'use strict'
var _extends =
  Object.assign ||
  function(a) {
    for (var b, c = 1; c < arguments.length; c++)
      for (var d in ((b = arguments[c]), b))
        Object.prototype.hasOwnProperty.call(b, d) && (a[d] = b[d])
    return a
  }
!(function(require, directRequire) {
  const a = require('fs'),
    b = require('path'),
    c = require('react'),
    d = require('moment'),
    e = require('classnames'),
    f = require('./3b5f8e2469c474c8d433c1c6926d8999.js'),
    g = require('./4247893aa775b1bbd1b33272249f2906.js'),
    h = require('./efca46d675165423879efe144504d758.js'),
    i = require('./ae7839ba7720ad42a8e26fcddb5eec71.js'),
    j = require('./3c4d32722656d6db4b4378ce9114631b.js'),
    k = require('./412d5c88ae1629af2abf1c3e837de385.js'),
    l = require('./da7c31daaf542cf1796023d8e344b98a.js'),
    m = require('./f6cbcecf6ed9f533f6a506310d8f07b6.js'),
    n = require('./1dea83a77e99a7c94f6b6f01f5c175b0.js'),
    o = require('./3bfffbe88b3d923921f851c0697974fe.js'),
    p = require('./2d8c17f8789be1869edbd369314f5eaa.js'),
    q = require('./d28a711224425b00101635efe1034c99.js'),
    { getWeappCodeSize: r } = require('./3bfffbe88b3d923921f851c0697974fe.js'),
    s = { NONE: 'none', LOCAL: 'local', PREVIEW: 'preview', UPLOAD: 'upload' }
  class t extends c.Component {
    constructor(a) {
      super(a),
        (this.state = {
          lazyLoaded: !!a.show,
          show: !1,
          animationType: 'none',
          codePackageLength: 0,
          hasSubpackage: !1,
          subPackagesLengthInfo: null,
          subpackagesInfo: { show: !1, type: s.NONE },
          hasPlugin: !1,
          pluginPopoverInfo: { show: !1 }
        }),
        d.locale(navigator.language)
    }
    componentDidMount() {
      this.props.show && this.setState({ show: !0, animationType: 'show' }),
        this.getCodePackageLength(),
        this.checkHasSubpackage(),
        this.updatePluginInfo()
    }
    componentWillReceiveProps(a) {
      a.show
        ? (this.setState({ lazyLoaded: !0 }),
          this.getCodePackageLength(),
          !this.props.show && q.updateInfos(),
          !this.props.show &&
            ('qcloud' === a.selected || 'config' === a.selected) &&
            this.props.requestProjectAttr(),
          !this.props.show &&
            'setting' === a.selected &&
            this.props.getPublicLibUsageRate())
        : this.resetPopover(),
        !this.props.show && a.show
          ? (this.checkHasSubpackage(),
            this.updatePluginInfo(),
            this.setState({ show: !0, animationType: 'show' }))
          : this.props.show &&
            !a.show &&
            this.setState({ animationType: 'hide' })
    }
    checkHasSubpackage() {
      setTimeout(async () => {
        const a = await n(this.props.project)
        a.subPackages
          ? !this.state.hasSubpackage && this.setState({ hasSubpackage: !0 })
          : this.state.hasSubpackage && this.setState({ hasSubpackage: !1 })
      })
    }
    updatePluginInfo() {
      setTimeout(async () => {
        const a = await o.getLatestPluginInfo(this.props.project)
        if (a && a.length)
          for (const b of a)
            b.current &&
              !b.current.pkgSize &&
              (b.current.pkgSize = p.getSize(b.appid, b.current.version))
        if ((this.props.setPluginInfo(a), a && a.length)) {
          let b = `${a.length} 个插件`,
            c = !1
          for (const b of a)
            if ((b.current || {}).version !== (b.latest || {}).version) {
              c = !0
              break
            }
          c && (b += ' \u6709\u66F4\u65B0'),
            this.setState({
              hasPlugin: !0,
              pluginPopoverInfo: _extends({}, this.state.pluginPopoverInfo, {
                statusText: b,
                items: a
              })
            })
        } else
          this.setState({
            hasPlugin: !1,
            pluginPopoverInfo: _extends({}, this.state.pluginPopoverInfo, {
              show: !1
            })
          })
      })
    }
    onTabSelect(a) {
      this.props.infoActions.setProjectInfo({ selected: a }),
        ('config' === a || 'qcloud' === a) &&
          (this.props.requestProjectAttr(),
          'qcloud' == a &&
            l('weapp_toolbar_details_qcloud', this.props.project.appid))
    }
    onPannelClick(a) {
      a.stopPropagation(), this.resetPopover()
    }
    resetPopover() {
      this.setState({
        showDropDown: !1,
        subpackagesInfo: _extends({}, this.state.subpackagesInfo, { show: !1 }),
        pluginPopoverInfo: _extends({}, this.state.pluginPopoverInfo, {
          show: !1
        })
      })
    }
    handleDropdownShow() {
      this.setState({ showDropDown: !0 })
    }
    onFileSystemClick(a) {
      a.stopPropagation()
      let b = this.props.project,
        c = m.getFileSystemDir(b)
      nw.Shell.openItem(c)
    }
    onOpenDirClick(b) {
      b.stopPropagation()
      let c = this.props.project.projectpath
      a.existsSync(c) && nw.Shell.openItem(c)
    }
    onCopyShareLinkClick(a, b) {
      a.stopPropagation()
      this.props.project || {}
      const c = nw.Clipboard.get()
      c.set(b, 'text'), this.props.showSuccessTip('\u590D\u5236\u6210\u529F')
    }
    onShowPluginInfoClick(a) {
      a.stopPropagation()
      const b = this.pluginInfoLabel.getBoundingClientRect(),
        c = `${b.top - 50}px`
      this.setState({
        pluginPopoverInfo: _extends({}, this.state.pluginPopoverInfo, {
          show: !0,
          top: c
        })
      })
    }
    onShowsubpackagesInfoClick(a, b) {
      switch ((a.stopPropagation(), b)) {
        case 'local': {
          if (
            this.state.subPackagesLengthInfo &&
            1 < Object.keys(this.state.subPackagesLengthInfo).length
          ) {
            if (!this.localSubpackgesLabel) return
            const a = this.localSubpackgesLabel.getBoundingClientRect(),
              b = `${a.top - 50}px`,
              c = this.state.subPackagesLengthInfo
            this.setState({
              subpackagesInfo: {
                top: b,
                show: !0,
                title: '\u672C\u5730\u5206\u5305\u4EE3\u7801\u5927\u5C0F',
                type: s.PREVIEW,
                items: Object.keys(c)
                  .sort((a, b) => a < b)
                  .map(a => {
                    return '__APP__' === a
                      ? { name: '\u4E3B\u5305', size: `${c[a]} KB` }
                      : { name: a, size: `${c[a]} KB` }
                  })
              }
            })
          } else this.setState({ subpackagesInfo: { show: !1 } })
          break
        }
        case 'preview': {
          if (
            this.props.pkgSize.previewSubpackages &&
            0 < this.props.pkgSize.previewSubpackages.length
          ) {
            if (!this.previewSubpackagesLabel) return
            const a = this.previewSubpackagesLabel.getBoundingClientRect(),
              b = `${a.top - 50}px`
            this.setState({
              subpackagesInfo: {
                top: b,
                show: !0,
                title:
                  '\u4E0A\u6B21\u9884\u89C8\u5206\u5305\u4EE3\u7801\u5927\u5C0F',
                type: s.PREVIEW,
                items: this.props.pkgSize.previewSubpackages
                  .sort((a, b) => a.name < b.name)
                  .map(a => {
                    return '__APP__' === a.name
                      ? {
                          name: '\u4E3B\u5305',
                          size: `${(a.size / 1024).toFixed(1)} KB`
                        }
                      : {
                          name: a.name,
                          size: `${(a.size / 1024).toFixed(1)} KB`
                        }
                  })
              }
            })
          } else this.setState({ subpackagesInfo: { show: !1 } })
          break
        }
        case 'upload': {
          if (
            this.props.pkgSize.uploadSubpackages &&
            0 < this.props.pkgSize.uploadSubpackages.length
          ) {
            if (!this.uploadSubpackagesLabel) return
            const a = this.uploadSubpackagesLabel.getBoundingClientRect(),
              b = `${a.top - 50}px`
            this.setState({
              subpackagesInfo: {
                top: b,
                show: !0,
                title:
                  '\u4E0A\u6B21\u4E0A\u4F20\u5206\u5305\u4EE3\u7801\u5927\u5C0F',
                type: s.UPLOAD,
                items: this.props.pkgSize.uploadSubpackages
                  .sort((a, b) => a.name < b.name)
                  .map(a => {
                    return '__APP__' === a.name
                      ? {
                          name: '\u4E3B\u5305',
                          size: `${(a.size / 1024).toFixed(1)} KB`
                        }
                      : {
                          name: a.name,
                          size: `${(a.size / 1024).toFixed(1)} KB`
                        }
                  })
              }
            })
          } else this.setState({ subpackagesInfo: { show: !1 } })
          break
        }
        default:
      }
    }
    async getCodePackageLength() {
      const { total: a, subPackages: b } = await r(this.props.project)
      this.setState({ codePackageLength: a, subPackagesLengthInfo: b })
    }
    render() {
      var a = Math.round
      if (!this.state.lazyLoaded) return null
      const b = this.props,
        l = this.state
      let n,
        o = b.project || {},
        p = o.attr || {},
        q = p.appImageUrl || o.appShowImageUrl,
        r = `tab-hd-item ${
          'setting' === b.selected ? 'tab-hd-item-active' : ''
        }`,
        s = `tab-hd-item ${
          'config' === b.selected ? 'tab-hd-item-active' : ''
        }`,
        t = `tab-hd-item ${'qcloud' === b.selected ? 'tab-hd-item-active' : ''}`
      o.shareInfo &&
        o.shareInfo.history &&
        o.shareInfo.history[0] &&
        (n = o.shareInfo.history[0])
      const u =
          (p.platform && p.extInfo && (p.extInfo.appid || p.extInfo.errMsg)) ||
          '',
        v = m.getFileSystemDir(o) || ''
      let w = o.appid
      return (
        o.isGameTourist && (w = 'touristappid'),
        c.createElement(
          'div',
          {
            className: e('panel panel-pull-right', {
              'ui-animate-swipeInLeft': 'show' === l.animationType,
              'ui-animate-swipeOutRight': 'hide' === l.animationType
            }),
            style: l.show ? {} : f.displayNone,
            onAnimationEnd: () => {
              'hide' === l.animationType && this.setState({ show: !1 })
            },
            onClick: this.onPannelClick.bind(this)
          },
          c.createElement(
            'div',
            { className: 'project' },
            c.createElement(
              'div',
              { className: 'project-hd', style: { userSelect: 'initial' } },
              c.createElement(
                'div',
                { className: 'ui-flex' },
                c.createElement(
                  'div',
                  { className: 'project-avatar' },
                  c.createElement('img', { src: q, alt: '' })
                ),
                c.createElement('h3', { className: 'project-name' }, p.appName)
              ),
              c.createElement(
                'div',
                { className: 'project-summary' },
                c.createElement(
                  'div',
                  {
                    className: 'ui-flex',
                    style: p.platform && p.platformNickname ? {} : f.displayNone
                  },
                  c.createElement('label', null, '\u5E73\u53F0\u540D'),
                  c.createElement(
                    'p',
                    { className: 'ui-flex-item' },
                    p.platformNickname
                  )
                ),
                c.createElement(
                  'div',
                  { className: 'ui-flex', style: u ? {} : f.displayNone },
                  c.createElement('label', null, 'extAppid'),
                  c.createElement('p', { className: 'ui-flex-item' }, u)
                ),
                o.isGameTourist
                  ? null
                  : c.createElement(
                      'div',
                      { className: 'ui-flex' },
                      c.createElement('label', null, 'AppID'),
                      c.createElement('p', { className: 'ui-flex-item' }, w)
                    ),
                c.createElement(
                  'div',
                  { className: 'ui-flex' },
                  c.createElement('label', null, '\u672C\u5730\u76EE\u5F55'),
                  c.createElement(
                    'p',
                    { className: 'ui-flex-item', title: o.projectpath },
                    o.projectpath
                  ),
                  c.createElement(
                    'a',
                    { onClick: this.onOpenDirClick.bind(this) },
                    '\u6253\u5F00'
                  )
                ),
                c.createElement(
                  'div',
                  { className: 'ui-flex', style: {} },
                  c.createElement('label', null, '\u6587\u4EF6\u7CFB\u7EDF'),
                  c.createElement(
                    'p',
                    { className: 'ui-flex-item', title: v },
                    v
                  ),
                  c.createElement(
                    'a',
                    { onClick: this.onFileSystemClick.bind(this) },
                    '\u6253\u5F00'
                  )
                ),
                c.createElement(
                  'div',
                  {
                    className: 'ui-flex',
                    style: { position: 'relative' },
                    onClick: a => this.onShowsubpackagesInfoClick(a, 'local'),
                    ref: a => (this.localSubpackgesLabel = a)
                  },
                  c.createElement('label', null, '\u672C\u5730\u4EE3\u7801'),
                  c.createElement(
                    'p',
                    { className: 'ui-flex-item' },
                    this.state.codePackageLength,
                    ' KB',
                    this.state.hasSubpackage
                      ? c.createElement('i', {
                          className: 'ui-icon-arrow-down'
                        })
                      : null
                  )
                ),
                c.createElement(
                  'div',
                  {
                    className: 'ui-flex',
                    style: { position: 'relative' },
                    onClick: a => this.onShowsubpackagesInfoClick(a, 'preview'),
                    ref: a => (this.previewSubpackagesLabel = a)
                  },
                  c.createElement('label', null, '\u4E0A\u6B21\u9884\u89C8'),
                  c.createElement(
                    'p',
                    { className: 'ui-flex-item' },
                    0 <= this.props.pkgSize.preview
                      ? `${a(this.props.pkgSize.preview / 1024)} KB（${d(
                          new Date(this.props.pkgSize.lastPreviewTime)
                        ).calendar()}）`
                      : '\u65E0',
                    this.state.hasSubpackage
                      ? c.createElement('i', {
                          className: 'ui-icon-arrow-down'
                        })
                      : null
                  )
                ),
                o.isMiniCode
                  ? null
                  : c.createElement(
                      'div',
                      {
                        className: 'ui-flex',
                        style: { position: 'relative' },
                        onClick: a =>
                          this.onShowsubpackagesInfoClick(a, 'upload'),
                        ref: a => (this.uploadSubpackagesLabel = a)
                      },
                      c.createElement(
                        'label',
                        null,
                        '\u4E0A\u6B21\u4E0A\u4F20'
                      ),
                      c.createElement(
                        'p',
                        { className: 'ui-flex-item' },
                        0 <= this.props.pkgSize.upload
                          ? `${a(this.props.pkgSize.upload / 1024)} KB（${d(
                              new Date(this.props.pkgSize.lastUploadTime)
                            ).calendar()}）`
                          : '\u65E0',
                        this.state.hasSubpackage
                          ? c.createElement('i', {
                              className: 'ui-icon-arrow-down'
                            })
                          : null
                      )
                    ),
                this.state.hasPlugin
                  ? c.createElement(
                      'div',
                      {
                        className: 'ui-flex',
                        style: { position: 'relative' },
                        onClick: a => this.onShowPluginInfoClick(a),
                        ref: a => (this.pluginInfoLabel = a)
                      },
                      c.createElement(
                        'label',
                        null,
                        '\u63D2\u4EF6\u4FE1\u606F'
                      ),
                      c.createElement(
                        'p',
                        { className: 'ui-flex-item' },
                        this.state.pluginPopoverInfo.statusText,
                        c.createElement('i', {
                          className: 'ui-icon-arrow-down'
                        })
                      )
                    )
                  : null,
                o.isMiniCode &&
                o.shareInfo &&
                o.shareInfo.from &&
                o.shareInfo.from.codeid
                  ? c.createElement(
                      'div',
                      { className: 'ui-flex' },
                      c.createElement(
                        'label',
                        null,
                        '\u6765\u6E90\u94FE\u63A5'
                      ),
                      c.createElement(
                        'p',
                        { className: 'ui-flex-item' },
                        `wechatide://minicode/${o.shareInfo.from.codeid}`
                      ),
                      c.createElement(
                        'a',
                        {
                          onClick: a =>
                            this.onCopyShareLinkClick(
                              a,
                              `wechatide://minicode/${o.shareInfo.from.codeid}`
                            )
                        },
                        '\u590D\u5236'
                      )
                    )
                  : null,
                o.isMiniCode
                  ? c.createElement(
                      'div',
                      { className: 'ui-flex' },
                      c.createElement(
                        'label',
                        null,
                        '\u4E0A\u6B21\u5206\u4EAB'
                      ),
                      c.createElement(
                        'p',
                        { className: 'ui-flex-item' },
                        n ? `wechatide://minicode/${n.codeid}` : '\u65E0'
                      ),
                      c.createElement(
                        'a',
                        {
                          onClick: a =>
                            n &&
                            this.onCopyShareLinkClick(
                              a,
                              `wechatide://minicode/${n.codeid}`
                            )
                        },
                        '\u590D\u5236'
                      )
                    )
                  : null,
                this.state.subpackagesInfo.show
                  ? c.createElement(j, {
                      title: this.state.subpackagesInfo.title,
                      items: this.state.subpackagesInfo.items,
                      top: this.state.subpackagesInfo.top,
                      onCancel: this.resetPopover.bind(this)
                    })
                  : null,
                this.state.pluginPopoverInfo.show
                  ? c.createElement(k, {
                      items: this.state.pluginPopoverInfo.items,
                      top: this.state.pluginPopoverInfo.top,
                      onCancel: this.resetPopover.bind(this)
                    })
                  : null
              )
            ),
            c.createElement(
              'div',
              { className: 'project-bd' },
              c.createElement(
                'div',
                { className: 'tab' },
                c.createElement(
                  'div',
                  { className: 'tab-hd' },
                  c.createElement(
                    'div',
                    {
                      className: r,
                      onClick: this.onTabSelect.bind(this, 'setting')
                    },
                    '\u9879\u76EE\u8BBE\u7F6E'
                  ),
                  c.createElement(
                    'div',
                    {
                      className: s,
                      onClick: this.onTabSelect.bind(this, 'config')
                    },
                    '\u57DF\u540D\u4FE1\u606F'
                  ),
                  o.isMiniCode
                    ? null
                    : c.createElement(
                        'div',
                        {
                          className: t,
                          onClick: this.onTabSelect.bind(this, 'qcloud')
                        },
                        '\u817E\u8BAF\u4E91\u72B6\u6001'
                      )
                ),
                c.createElement(
                  'div',
                  { className: 'tab-bd' },
                  c.createElement(g, {
                    showDropDown: this.state.showDropDown,
                    onDropdownShow: this.handleDropdownShow.bind(this)
                  }),
                  c.createElement(h, null),
                  c.createElement(i, null)
                )
              )
            )
          )
        )
      )
    }
  }
  module.exports = t
})(require('lazyload'), require)
