'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('react'),
    b = require('prop-types'),
    c = require('./NavigationBarConnected.js'),
    d = require('./TabBar.js'),
    e = require('./WebviewConnected.js'),
    f = require('./HtmlWebviewConnected.js'),
    g = require('./PreviewImageConnected.js'),
    h = require('./PaymentConnected.js'),
    i = require('./ff946754202ecf377034d29daac7c8d9.js'),
    j = require('./ToastConnected.js'),
    k = require('./ModalConnected.js'),
    l = require('./ActionSheetConnected.js'),
    m = require('./e12e47cfa49959a6d49ea1936dc19380.js'),
    n = require('./10279410b7cf7ea9409d42a7eb37225c.js'),
    o = require('./b6dd6ba0b853899c69527eaf93a58f7b.js'),
    p = require('./413e1df0d2a135fa20cefc4c23f8e8e1.js'),
    q = require('./d03a90fbd796428c64e8c47eef5f4e71.js'),
    r = require('./8e7fed729e9f11f30d63365586719bf0.js'),
    s = require('./504ae46dc4a72502ee836b22913fbe81.js'),
    t = require('./9a1630c7db7597f338c9319bfc8571c5.js'),
    u = require('./a1b9e6fb17fda6e4b961ef97ab1371f8.js'),
    v = require('./6fc2d18cec70b19ca4d1e2defbdf43cd.js'),
    w = require('./logger.js'),
    x = require('./3bfffbe88b3d923921f851c0697974fe.js'),
    y = require('./1dea83a77e99a7c94f6b6f01f5c175b0.js'),
    z = require('./1ca0b7713664710bff99ca9c6d29c43c.js'),
    A = require('./3b5f8e2469c474c8d433c1c6926d8999.js'),
    B = require('./84eac15ddafa077aa832c98b6c2290bd.js'),
    C = require('./f094f1d16fffcac4d74949e4fc6b09ac.js'),
    D = require('./ea653f45dc25181ca4f1b108175009b7.js'),
    E = require('./dc4889188702c881b1432b490a2a4850.js'),
    F = require('./03f56b6c971ec6f7813234d685a2fa8c.js'),
    G = require('classnames'),
    H = require('./d3fc1d4b6cfd440a6300e62456252a06.js'),
    I = require('./137588fc97010af6b33c2be1d533447b.js'),
    J = require('./b6a2a0af8ea41ee5132948d45a0a6677.js'),
    K = require('./a03c8e76d4fe0178cd6a28a2fbc16ddd.js'),
    L = require('./195285e5284f78e12cb71042e95b9566.js'),
    M = require('./245e991bfa34036d0454bd1d61b4a3b2.js'),
    N = require('./b86cb96a5caed2b5ae72ef2e6a5d13ef.js'),
    O = require('./0cecfd7c413f06c788a4d6b7972cdf96.js'),
    P = require('./e452f0d072800b8203d233682d37d71a.js')
  class Q extends a.Component {
    constructor(a) {
      super(a),
        (this.onResizeStop = (a, b) => {
          this.props.windowActions.setSimulator({ width: b })
        }),
        (this.state = { simulatorStyle: {} })
    }
    componentDidMount() {
      this.props.isPopup
        ? this.adjustWindowSize()
        : this.props.appLaunched && this.props.simulatorActions.compile(),
        chrome.fontSettings.setMinimumFontSize({ pixelSize: 1 }),
        global.online &&
          setTimeout(() => {
            global.Win.resizeBy(5, 5)
          }, 1e3)
    }
    componentWillUnmount() {}
    componentWillReceiveProps(a) {
      a.vibrate != this.props.vibrate &&
        ('short' == a.vibrate
          ? this.vibrateAnimation(1)
          : 'long' == a.vibrate && this.vibrateAnimation(3)),
        this.props.isPopup &&
          (a.screenWidth !== this.props.screenWidth ||
            a.screenHeight !== this.props.screenHeight) &&
          this.adjustWindowSize()
    }
    getChildContext() {
      return {
        isPopup: this.props.isPopup,
        window: this.props.win ? this.props.win : null
      }
    }
    async vibrateAnimation(a) {
      if (0 >= a) return void this.props.simulatorActions.setVibrate('none')
      var b = [
        `translate(1%,5px) scale(${this.props.deviceScale})`,
        `translate(-1%,5px) scale(${this.props.deviceScale})`
      ]
      const c = async a => {
        return 0 >= a.length
          ? void this.setState({ simulatorStyle: {} })
          : (this.setState({
              simulatorStyle: {
                transition: 'all linear 0.05s',
                transform: a[0]
              }
            }),
            a.splice(0, 1),
            new Promise((b, d) => {
              setTimeout(() => {
                c(a)
                  .then(() => {
                    b()
                  })
                  .catch(a => {
                    d(a)
                  })
              }, 50)
            }))
      }
      await c(b), await this.vibrateAnimation(--a)
    }
    reLaunch() {}
    adjustWindowSize() {
      setTimeout(() => {
        const a = this.props.win
        if (a) {
          let b = this.props.screenWidth
          isMac || (b -= 10), (a.width = b)
          let c = this.props.screenHeight
          const d = document.getElementsByClassName('simulator-toolbar')
          ;(c += d[0] ? d[0].offsetHeight : 27),
            isMac || (c -= 10),
            (a.height = c)
        }
      })
    }
    getOptionsComponents() {
      let b = this.props,
        c = []
      return (
        b.switch.selectorPickerShow &&
          c.push(a.createElement(q, { key: 'selectorpicker' })),
        b.switch.datePickerShow &&
          c.push(a.createElement(n, { key: 'datepicker' })),
        b.switch.timePickerShow &&
          c.push(a.createElement(o, { key: 'timepicker' })),
        b.switch.multiPickerShow &&
          c.push(a.createElement(p, { key: 'multipicker' })),
        b.switch.paymentShow && c.push(a.createElement(h, { key: 'payment' })),
        b.switch.confirmShow && c.push(a.createElement(u, { key: 'confirm' })),
        b.switch.authorizeShow &&
          c.push(a.createElement(B, { key: 'authorize' })),
        c
      )
    }
    getWindowComponents() {
      let b = this.props,
        c = []
      return (
        b.window.groupShow && c.push(a.createElement(s, { key: 'grouplist' })),
        b.window.settingShow && c.push(a.createElement(t, { key: 'setting' })),
        b.window.addCardShow && c.push(a.createElement(E, { key: 'addcard' })),
        b.window.viewCardShow &&
          c.push(a.createElement(F, { key: 'viewcard' })),
        b.window.h5AddCardShow &&
          c.push(a.createElement(N, { key: 'h5addcard' })),
        b.window.h5ViewCardShow &&
          c.push(a.createElement(O, { key: 'h5viewcard' })),
        b.window.h5ChooseCardShow &&
          c.push(a.createElement(P, { key: 'h5choosecard' })),
        b.window.locationShow &&
          c.push(a.createElement(C, { key: 'location' })),
        b.window.addPhoneContactShow &&
          c.push(a.createElement(J, { key: 'addPhoneContact' })),
        b.window.chooseAddressShow &&
          c.push(a.createElement(K, { key: 'chooseAddress' })),
        b.window.chooseInvoiceTitleShow &&
          c.push(a.createElement(L, { key: 'chooseInvoiceTitle' })),
        c
      )
    }
    render() {
      let b,
        h,
        i = this.props,
        n = { width: i.width },
        o = G('simulator-container', { 'ui-invisible': !i.show }),
        p = []
      const q =
        this.props.enableFullScreen ||
        (this.props.libVersion &&
          170 <= parseInt(this.props.libVersion.replace(/\./g, '')) &&
          'custom' === this.props.navigationStyle)
      for (let c in (q
        ? ((b = i.screenHeight), (h = 0))
        : ((b = i.screenHeight - i.navigationbarHeight - i.statusbarHeight),
          (h = i.navigationbarHeight + i.statusbarHeight)),
      i.webviewInfos)) {
        let d = i.webviewInfos[c],
          f = b,
          g = h
        i.tabbarShow &&
          -1 != d.tabbarIndex &&
          ('top' == i.tabbarPosition
            ? ((f -= i.tabbarHeight), (g += i.tabbarHeight))
            : (f -= i.tabbarHeight)),
          p.push(
            a.createElement(e, {
              key: c,
              show: i.currentWebviewID == c,
              info: d,
              top: g,
              height: f
            })
          )
      }
      let s = a.createElement(c, null)
      if (i.anyHtmlWebviewInfo) {
        const d = i.anyHtmlWebviewInfo
        p.push(
          a.createElement(f, {
            webviewID: d.webviewID,
            nosupport: !0,
            url: d.url || '',
            cangoback: !0,
            width: i.screenWidth,
            height: b,
            left: 0,
            top: h
          })
        ),
          (s = a.createElement(c, {
            showLeftBtn: !0,
            onLeftBtnClick: () => {
              i.simulatorActions.setAnyHtmlWebview()
            }
          }))
      }
      i.standbyWebview &&
        p.push(
          a.createElement(e, {
            key: i.standbyWebview.id,
            show: !1,
            info: i.standbyWebview,
            top: h,
            height: b,
            type: 'standby'
          })
        ),
        0 >= p.length &&
          p.push(
            a.createElement(e, {
              key: -1,
              show: !0,
              info: {},
              top: h,
              height: b,
              type: 'tip'
            })
          )
      let t
      return (
        global.onlySimulator
          ? ((t = _extends(
              {
                top: 0,
                left: 0,
                width: i.screenWidth,
                height: i.screenHeight,
                transform: `scale(${i.deviceScale})`,
                transformOrigin: '50% 0'
              },
              this.state.simulatorStyle
            )),
            global.Win.width !== t.width && (global.Win.width = t.width),
            global.Win.height !== t.height &&
              (global.Win.height =
                t.height + ('darwin' === process.platform ? 0 : 26)))
          : (t = _extends(
              {
                width: i.screenWidth,
                height: i.screenHeight,
                transform: `scale(${i.deviceScale})`,
                transformOrigin: '50% 0',
                marginLeft: -i.screenWidth / 2
              },
              this.state.simulatorStyle
            )),
        this.props.isPopup
          ? ((t.top = '0'),
            (t.left = 'inherit'),
            (t.marginLeft = 'inherit'),
            a.createElement(
              'div',
              { style: { width: '100%', height: '100%' }, className: o },
              a.createElement(z, null),
              a.createElement(
                'div',
                { className: 'simulator-shell' },
                a.createElement(
                  'div',
                  { className: 'simulator', style: t },
                  a.createElement(H, null),
                  a.createElement(M, null),
                  s,
                  p,
                  a.createElement(d, null),
                  a.createElement(g, null),
                  a.createElement(j, null),
                  a.createElement(k, null),
                  a.createElement(l, null),
                  a.createElement(m, null),
                  this.getOptionsComponents(),
                  a.createElement(r, null)
                ),
                this.getWindowComponents()
              ),
              a.createElement(I, null)
            ))
          : a.createElement(
              D,
              {
                width: i.width,
                height: '100%',
                className: o,
                style: { minWidth: i.shellMinWidth },
                leftResizable: i.workbenchShow && 'right' === i.position,
                rightResizable: i.workbenchShow && 'left' === i.position,
                onResizeStop: this.onResizeStop
              },
              a.createElement(z, null),
              a.createElement(
                'div',
                { className: 'simulator-shell' },
                a.createElement(
                  'div',
                  { className: 'simulator', style: t },
                  a.createElement(H, null),
                  a.createElement(M, null),
                  s,
                  p,
                  a.createElement(d, null),
                  a.createElement(g, null),
                  a.createElement(j, null),
                  a.createElement(k, null),
                  a.createElement(l, null),
                  a.createElement(m, null),
                  this.getOptionsComponents(),
                  a.createElement(r, null)
                ),
                this.getWindowComponents()
              ),
              a.createElement(v, null),
              a.createElement(I, null),
              a.createElement('div', {
                className: 'ui-divider-vertical',
                style: { pointerEvents: 'none' }
              })
            )
      )
    }
  }
  ;(Q.childContextTypes = { isPopup: b.bool, window: b.object }),
    (module.exports = Q)
})(require('lazyload'), require)
