'use strict'
!(function(require, directRequire) {
  const a = require('fs'),
    b = require('path'),
    c = require('react'),
    d = require('./875171e7b864aa58d026d4fa0999fbd1.js'),
    e = require('./92320c1386e6db6a6f2556736a9bc280.js'),
    f = require('./c4b43629b4de3d73a79d27fb0314f46a.js'),
    g = require('./25d0beb4120ce2acafb4e03b95444fda.js'),
    h = require('./d247c706e8ed1b6ec9de35f99448d8e8.js'),
    i = require('./d3976cc01aeebc5b09e11c4135b6bd8d.js'),
    j = require('./4152e7daed8b58a0b1bd0a083454e73f.js'),
    k = require('./6620a0cf7dad1b400d60f0fdae40f524.js'),
    l = require('./56c390e04c10e91a4aa2a2c19d9a885d.js'),
    m = require('./9e942ab5ae7ca9f57142dfe40a4b77e2.js'),
    n = require('./a3dbd8a227a46bf2bda5766bf515d780.js'),
    o = require('./e56b3f8f9a65ddb6e18ef417d763a1f6.js'),
    { connect: p } = require('react-redux'),
    q = a => {
      return {
        tree: a.cos.tree,
        currentPath: a.cos.currentPath,
        show: a.cos.show
      }
    },
    r = a => {
      return { cosActions: i.bindActionCreators(f, a) }
    }
  class s extends c.Component {
    constructor(a) {
      super(a),
        (this.state = {
          ignoreList: [],
          progressInfo: '',
          uploadShow: !1,
          uploadEnd: !1,
          detail: {}
        })
    }
    componentWillReceiveProps(a) {
      a.currentPath != this.props.currentPath &&
        (clearTimeout(this.getDetailTimer),
        (this.getDetailTimer = setTimeout(() => {
          this.getResourceDetail()
        })))
    }
    componentDidMount() {
      this.props.cosActions.setDir('/', !0)
    }
    componentWillUnmount() {
      clearTimeout(this.getDetailTimer),
        clearTimeout(this.checkTaskResultTimer),
        this.props.cosActions.closeCosManager()
    }
    getResourceDetail() {
      let a = this.props.tree[this.props.currentPath]
      if (a && !a.isDir && a.url) {
        let c = j.whiteFileExtName,
          d = b.extname(a.url || '').toLowerCase(),
          e = c[d]
        e
          ? this.setState({
              detail: {
                currentPath: this.props.currentPath,
                ext: d.replace(/^\./, '').toUpperCase(),
                type: e.type,
                name: e.name
              }
            })
          : j.getResourceDetail(this.props.currentPath, a.url).then(a => {
              a.currentPath == this.props.currentPath &&
                this.setState({ detail: a })
            })
      }
    }
    async onUpload(a, b = '/') {
      try {
        this.setState({ ignoreList: [] })
        let a = await j.getTaskId()
        if (a && 0 != a.taskId && 'uploading' == a.status)
          return void this.props.cosActions.showError(
            '\u5F53\u524D\u6709\u4E0A\u4F20\u4EFB\u52A1\u6B63\u5728\u8FDB\u884C\uFF0C\u8BF7\u7A0D\u5019\u91CD\u8BD5'
          )
        let c = await j.getUploadFiles(this.progressHandler.bind(this))
        if (c) {
          this.setState({ uploadShow: !0, uploadEnd: !1 }),
            this.progressHandler('progress', '\u6B63\u5728\u4E0A\u4F20......')
          let a = await j.upload(c, b)
          ;(this.startTs = Date.now()), this.checkTaskResult(a.taskId, b)
        }
      } catch (a) {
        this.setState({ uploadShow: !1, uploadEnd: !0 }),
          1003 == a.code
            ? this.props.cosActions.setConfirmInfo({
                show: !0,
                type: 'error',
                title: '\u63D0\u793A',
                content:
                  '\u672A\u5F00\u901A\u817E\u8BAF\u4E91 CDN \u670D\u52A1\uFF0C\u8BF7\u524D\u5F80\u5F00\u901A',
                showCancel: !0,
                showConfirm: !0,
                callback: a => {
                  a &&
                    g.jumpQCloudPage(
                      'https://www.qcloud.com/login/laAccessCallback'
                    )
                },
                confirmText: '\u524D\u5F80\u5F00\u901A'
              })
            : this.props.cosActions.showError(a.toString())
      }
    }
    progressHandler(a, b) {
      'ignore' == a
        ? this.setState({
            ignoreList: this.state.ignoreList.concat([
              `${b.file} 因 ${b.reason} 被忽略`
            ])
          })
        : 'zip' == a
          ? this.setState({
              progressInfo: `正在打包 ${b.file} 大小 ${b.length}B ......`
            })
          : 'progress' == a && this.setState({ progressInfo: b })
    }
    checkTaskResult(a, b) {
      j.getTaskResult(a)
        .then(({ status: c }) => {
          'uploading' == c
            ? (this.progressHandler(
                'progress',
                `正在处理，耗时${parseInt(
                  (Date.now() - this.startTs) / 1e3
                )}s ......`
              ),
              (this.checkTaskResultTimer = setTimeout(() => {
                this.checkTaskResult(a, b)
              }, 1e3)))
            : 'failed' == c
              ? (this.setState({ uploadEnd: !0 }),
                this.props.cosActions.showError(
                  '\u4E0A\u4F20\u5931\u8D25\uFF0C\u8BF7\u7A0D\u5019\u91CD\u8BD5'
                ))
              : 'complete' == c
                ? (this.setState({ uploadEnd: !0 }),
                  this.progressHandler('progress', `上传成功`),
                  this.props.cosActions.setDir(b, !0))
                : 'timeout' == c &&
                  (this.setState({ uploadEnd: !0 }),
                  this.props.cosActions.showError(
                    '\u4EFB\u52A1\u8D85\u65F6\uFF0C\u8BF7\u7A0D\u5019\u91CD\u8BD5'
                  ),
                  this.props.cosActions.setDir(b, !0))
        })
        .catch(a => {
          this.props.cosActions.showError(a.toString())
        })
    }
    renderInfo() {
      return c.createElement(
        'div',
        { className: 'intro' },
        c.createElement(
          'div',
          { className: 'intro-text-area' },
          c.createElement(
            'h4',
            { className: 'intro-title' },
            '\u6682\u672A\u4E0A\u4F20\u4EFB\u4F55\u7D20\u6750'
          )
        ),
        c.createElement(
          'div',
          { className: 'intro-desc-area' },
          c.createElement(
            'p',
            { className: 'intro-desc' },
            '1. \u652F\u6301\u7684\u6587\u4EF6\u7C7B\u578B png\u3001jpg\u3001jpeg\u3001bmp\u3001gif\u3001mp3\u3001mp4\u3001m4a\u3001ogg'
          ),
          c.createElement(
            'p',
            { className: 'intro-desc' },
            '2. \u5355\u4E2A\u6587\u4EF6\u6700\u5927\u9650\u5236 2 MB\uFF0C\u5355\u6B21\u4E0A\u4F20 zip \u5305\u6700\u5927\u9650\u5236 10 MB'
          )
        ),
        c.createElement(
          'div',
          { className: 'intro-button-area' },
          c.createElement(
            'button',
            {
              className: 'ui-button ui-button-primary',
              onClick: this.onUpload.bind(this)
            },
            '\u4E0A\u4F20\u7D20\u6750'
          )
        )
      )
    }
    onContainerClick() {
      this.props.cosActions.setContextMenu({ show: !1 })
    }
    onUploadClose() {
      this.setState({ uploadShow: !1 })
    }
    onCopyUrlClick() {
      let a = this.props.tree[this.props.currentPath] || {},
        b = nw.Clipboard.get()
      b.set(a.url, 'text')
    }
    renderMgr() {
      let a = this.props.tree[this.props.currentPath] || {},
        b = {},
        d = null
      return (
        this.state.detail &&
          this.state.detail.currentPath == this.props.currentPath &&
          ((b = this.state.detail),
          'img' == b.type
            ? (d = c.createElement('div', {
                className: 'file-mgr-detail-thumbnail',
                style: {
                  backgroundImage: `url('${a.url}')`,
                  backgroundPosition: 'center center',
                  backgroundRepeat: 'no-repeat',
                  backgroundSize: 'contain'
                }
              }))
            : 'audio' == b.type
              ? (d = c.createElement('audio', { src: a.url, controls: !0 }))
              : 'video' == b.type &&
                (d = c.createElement('video', { src: a.url, controls: !0 }))),
        c.createElement(
          'div',
          { className: 'file-mgr', style: { height: '100%' } },
          c.createElement(
            'div',
            { className: 'file-mgr-explore', style: { width: 250 } },
            c.createElement(
              'div',
              {
                className: 'file-mgr-toolbar',
                onClick: this.onUpload.bind(this)
              },
              c.createElement(
                'div',
                { className: 'file-mgr-toolbar-bd' },
                c.createElement(
                  'a',
                  { className: 'file-mgr-toolbar-item' },
                  c.createElement('i', { className: 'ui-icon-plus' }),
                  c.createElement(
                    'span',
                    { className: 'file-mgr-toolbar-name' },
                    '\u4E0A\u4F20\u6587\u4EF6'
                  )
                )
              )
            ),
            c.createElement(
              'div',
              { className: 'file-mgr-bd' },
              c.createElement(h, null)
            )
          ),
          c.createElement(
            'div',
            { className: 'file-mgr-preview', style: { userSelect: 'auto' } },
            c.createElement(
              'div',
              {
                className: 'file-mgr-detail',
                style: { display: a.url && !a.isDir ? '' : 'none' }
              },
              d,
              c.createElement(
                'p',
                { className: 'file-mgr-detail-name' },
                a.name
              ),
              c.createElement(
                'div',
                { className: 'file-mgr-detail-metas' },
                c.createElement(
                  'div',
                  { className: 'file-mgr-detail-meta' },
                  c.createElement('p', { className: 'file-mgr-detail-label' }),
                  c.createElement(
                    'p',
                    { className: 'file-mgr-detail-value file-mgr-detail-desc' },
                    b.ext,
                    ' ',
                    b.name,
                    ' \u2014 ',
                    1024 > a.size ? a.size : parseInt(a.size / 1024) + 'K',
                    'B'
                  )
                ),
                c.createElement(
                  'div',
                  { className: 'file-mgr-detail-meta' },
                  c.createElement(
                    'p',
                    { className: 'file-mgr-detail-label' },
                    '\u521B\u5EFA\u65F6\u95F4'
                  ),
                  c.createElement(
                    'p',
                    { className: 'file-mgr-detail-value' },
                    a.lastModified
                  )
                ),
                c.createElement(
                  'div',
                  { className: 'file-mgr-detail-meta' },
                  c.createElement(
                    'p',
                    { className: 'file-mgr-detail-label' },
                    'URL'
                  ),
                  c.createElement(
                    'p',
                    { className: 'file-mgr-detail-value' },
                    c.createElement('span', null, a.url),
                    c.createElement(
                      'a',
                      { onClick: this.onCopyUrlClick.bind(this) },
                      '\u590D\u5236'
                    )
                  )
                )
              )
            )
          )
        )
      )
    }
    render() {
      const a = this.props,
        b = this.state.ignoreList.map(a => {
          c.createElement('div', { key: a }, a)
        })
      let d = a.tree && 1 < Object.keys(a.tree).length
      return c.createElement(
        'div',
        {
          style: { height: '100%' },
          onClick: this.onContainerClick.bind(this)
        },
        c.createElement(m, null),
        c.createElement(n, {
          progress: this.state.progressInfo,
          tips: this.state.ignoreList,
          show: this.state.uploadShow,
          end: this.state.uploadEnd,
          onClose: this.onUploadClose.bind(this)
        }),
        c.createElement(o, null),
        d ? this.renderMgr() : this.renderInfo()
      )
    }
  }
  const t = p(q, r)(s)
  class u extends c.Component {
    constructor(a) {
      super(a)
    }
    onClose() {
      this.props.cosActions.closeCosManager()
    }
    componentWillUnmount() {
      this.props.cosActions.closeCosManager()
    }
    render() {
      return c.createElement(
        k,
        {
          title: '\u7D20\u6750\u7BA1\u7406',
          registryId: l.WINDOW_REGISTRY.MATERIAL,
          width: l.SIZE.MATERIAL.WIDTH,
          height: l.SIZE.MATERIAL.HEIGHT,
          resizable: !1,
          onWindowClose: this.onClose.bind(this),
          templateHTML: 'html/material.html',
          always_on_top: !0
        },
        c.createElement(t, null)
      )
    }
  }
  module.exports = p(q, r)(u)
})(require('lazyload'), require)
