 # * PI Stats?
 # * Industry stats - number of runs, not quantity of output (charges throw off the stats)
 
+SSO_HOST = 'https://login.eveonline.com'
+SSO_CALLBACK_URL = 'http://localhost:3000'
+SSO_CLIENT_ID = '67a0cc0f68d34e77b9751f8c75dd2e31'
+SSO_SECRET_KEY = 'hcw6vtxJPHyOuxddWCLP5sTpFILzoiuckk6mAqYc'
+
 React = require 'react'
-$ = require 'jquery'
+request = require 'request'
+http = require 'http'
 d3 = require 'd3'
 _ = require 'lodash'
+qs = require 'querystring'
 
 # polyfill for safari
 if not Intl

      year: 2014
    }
  componentDidMount: ->
    @loadData()
  loadData: ->
    if window.location.hash
      source = "#{window.location.hash.substring(1)}"
    else
      source = "null_pvp"
      source = _.sample samples
    $.get "./sampledata/#{source}.json", (data) =>
      stats = new CharacterStats(data)
      @setState {stats: stats, year: data.aggregateYear}
  render: ->
    if not @state.stats
      return dom.div null, "Loading..."

    facts = new CharacterFacts(@state.stats).getFacts()

    title = React.createElement(Title, {character: @state.character, year: @state.year})

    charInfoPanel = React.createElement(CharacterInfoPanel, {character: @state.character, facts: facts})

    travelJumpsPanel = React.createElement(TravelJumpsPanel, {stats: @state.stats})
    travelDistancePanel = React.createElement(TravelDistancePanel, {stats: @state.stats})

    distanceAnalogy = React.createElement(DistanceAnalogyPanel, {distance: @state.stats?.total 'travelDistanceWarped'})

    max = _.max [
      @state.stats?.combatKillsHighSec
      @state.stats?.combatKillsLowSec
      @state.stats?.combatKillsNullSec
      @state.stats?.combatKillsWormhole

      @state.stats?.combatDeathsHighSec
      @state.stats?.combatDeathsLowSec
      @state.stats?.combatDeathsNullSec
      @state.stats?.combatDeathsWormhole
    ]

    killsPanel = React.createElement(KillsPanel, {stats: @state.stats, max: max})
    deathsPanel = React.createElement(DeathsPanel, {stats: @state.stats, max: max})

    weaponUsagePanel = React.createElement(WeaponUsagePanel, {stats: @state.stats})
    damageTakenPanel = React.createElement(DamageTakenPanel, {stats: @state.stats})

    damageAnalogy = React.createElement(DamageAnalogyPanel, {damage: @state.stats?.totalDamageDealt})

    pvpModulesUsage = React.createElement(PvpModulesUsage, {stats: @state.stats})
    pvpModulesAgainst = React.createElement(PvpModulesAgainst, {stats: @state.stats})

    miscPvpStats = React.createElement(MiscPvpStats, {stats: @state.stats})

    selfRepPanel = React.createElement(SelfRepPanel, {stats: @state.stats})
    repsReceivedPanel = React.createElement(RepsReceivedPanel, {stats: @state.stats})
    repsGivenPanel = React.createElement(RepsGivenPanel, {stats: @state.stats})

    pveStats = React.createElement(PvePanel, {stats: @state.stats})

    miscModules = React.createElement(MiscModulePanel, {stats: @state.stats})

    industryJobs = React.createElement(IndustryJobsPanel, {stats: @state.stats})
    blueprints = React.createElement(IndustryBlueprintPanel, {stats: @state.stats})

    miningPanel = React.createElement(MiningPanel, {stats: @state.stats})

    iskPanel = React.createElement(ISKPanel, {stats: @state.stats})
    marketPanel = React.createElement(MarketPanel, {stats: @state.stats})

    contactsSelfPanel = React.createElement(ContactsPanel, {context: 'self', stats: @state.stats})
    contactsOtherPanel = React.createElement(ContactsPanel, {context: 'other', stats: @state.stats})

    socialMiscPanel = React.createElement(SocialMiscPanel, {stats: @state.stats})

    rawStatsList = React.createElement(RawStatsList, {stats: @state.stats})

    dom.div {className: 'container'},

      title

      charInfoPanel

      # Residence / Distance

      dom.div {className: 'row'},
        dom.div {className: 'col-md-6'}, travelJumpsPanel
        dom.div {className: 'col-md-6'}, travelDistancePanel

      dom.div {className: 'row'},
        dom.div {className: 'col-md-12'}, distanceAnalogy

      # PVP

      dom.div {className: 'row'},
        dom.div {className: 'col-md-6'}, killsPanel
        dom.div {className: 'col-md-6'}, deathsPanel

      dom.div {className: 'row'},
        dom.div {className: 'col-md-6'}, weaponUsagePanel
        dom.div {className: 'col-md-6'}, damageTakenPanel

      dom.div {className: 'row'},
        dom.div {className: 'col-md-12'}, damageAnalogy

      dom.div {className: 'row'},
        dom.div {className: 'col-md-6'}, pvpModulesUsage
        dom.div {className: 'col-md-6'}, pvpModulesAgainst

      dom.div {className: 'row'},
        dom.div {className: 'col-md-6'}, miscPvpStats

      dom.div {className: 'row'},
        dom.div {className: 'col-md-6'}, repsGivenPanel
        dom.div {className: 'col-md-6'}, repsReceivedPanel

      dom.div {className: 'row'},
        dom.div {className: 'col-md-12'}, selfRepPanel

      # PVE Stats

      dom.div {className: 'row'},
        dom.div {className: 'col-md-12'}, pveStats

      dom.div {className: 'row'},
        dom.div {className: 'col-md-12'}, miscModules

      # Industry
      dom.div {className: 'row'},
        dom.div {className: 'col-md-6'}, industryJobs
        dom.div {className: 'col-md-6'}, blueprints

      # Mining
      dom.div {className: 'row'},
        dom.div {className: 'col-md-6'}, miningPanel

      # Markets
      dom.div {className: 'row'},
        dom.div {className: 'col-md-6'}, iskPanel
        dom.div {className: 'col-md-6'}, marketPanel

      # Social
      dom.div {className: 'row'},
        dom.div {className: 'col-md-6'}, contactsSelfPanel
        dom.div {className: 'col-md-6'}, contactsOtherPanel

      dom.div {className: 'row'},
        dom.div {className: 'col-md-6'}, socialMiscPanel

      # Misc

      #rawStatsList
)

Title = React.createClass(

  displayName: 'CharacterStatsUI'
  getInitialState: ->
    return {
      ssoState: 'login'
      ssoCode: null
      stats: null
      character:
        name: 'Bellatroix'
