import React from 'react'
import Download from 'kara-module-downloader'
import 'kara-module-downloader/lib/index.css'
import css from './frame.scss'
import KaraSearch from '../kara-search'
import './skins/default/skin.css'
import httpAgent from './httpAgent'
import {Tost,Scroll,Modal,Modals,Forward,PlainMessage,Tooltip} from  "karaui"
import "karaui/lib/index.css"
import './layout.css'

export default class Co extends React.Component {

  constructor(props) {
    super(props)
    this.state = {
      clientType: 'web',
      mainHeight: '100%',
      mainTop: '0',
    }
  }

  componentDidMount() {
    const {clientType} = this.state
    const frame = document.getElementById('app')
    frame.className = clientType
    if (clientType === 'web') {
      this.resize({target: window})
      window.addEventListener('resize', this.resize, false)
    }
  }

  resize = (e) => {
    const target = e.target
    const height = target.innerHeight
    const frame = document.getElementById('app')
    if (height >= 900) {
      frame.style.height = '900px'
      frame.style.marginTop = `${(height - 900) / 2}px`
    } else {
      frame.style.height = '100%'
      frame.style.marginTop = '0'
    }
  }

  render() {
    const {history, match} = this.props
    const {clientType, mainHeight, mainTop} = this.state

    const config = {
      history,
      match,
      language: 'zh',
      token: sessionStorage.token,
      apiRoot: 'https://xin-sandbox.asiainfo.com:16020/api',
      apiVersion: 'v1.0.0',
      user: {"accountId":"U3KM96QD6","accountName":"马子萌","accountStatus":"10","accountType":"Employee","address":"北京","autoIcon":"1","bgId":"30802","childAccountCount":0,"companyId":"101","companyName":"亚信中国","costCenter":"17309","costCenterName":"CIT TD","email":"mazm@asiainfo.com","gender":"M","headIcon":"https://xinbuluo.101test.com/personheadicon/U3KM96QD6_180131165707.png","mobile":"15311415404","nickName":"奥特蛋","officeAddr":"北京","org":"CIT TD WEB-BJ","orgName":"CIT TD WEB-BJ","parentAccountId":"UZBVDKC4J","parentStaffId":"231076","parentStaffName":"张春林","personId":"217414","regionId":"01","regionName":"北京","sbu":"亚信软件CIT","sbuId":"165","signature":"远离杠精，珍爱生命","staffAccount":"mazm","staffCode":"33559","staffId":"217414","staffName":"马子萌","staffType":"Employee","username":"mazm","welStatus":false},
      karaui:{Tost,Scroll,Modal,Modals,Forward,PlainMessage,Tooltip},
      httpAgent: httpAgent('https://xin-sandbox.asiainfo.com:16020/api','v1.0.0'),
      /*disableAuth: [
        'globalSearch.addressbook',
        'globalSearch.app',
        'globalSearch.tasks',
        'globalSearch.immessage',
        'globalSearch.imgroup',
        'globalSearch.imfile',
        'globalSearch.moments',
        'globalSearch.cms',
        'globalSearch.faq'
      ]*/
    }

    return (
      <div className="kf-body">
        <div className={`${css.frame} s-bg-page`}>
          <div className={`${css.top} kf-top`}>
            <KaraSearch config={config}/>
          </div>
          <div className={`${css.aside} s-bg-primary small kf-aside`}>
            <div className='kf-logo'>Logo</div>
            <div className="kf-user">
              user
            </div>
            <div className="kf-nav">
              nav<br/>
              nav<br/>
              nav<br/>
              nav<br/>
              nav<br/>
            </div>
          </div>
          <div className={css.body}>
            <Download apiRoot={'https://xin-sandbox.asiainfo.com:16020/api'} token={sessionStorage.token}/>
          </div>
        </div>
      </div>
    )
  }
}