'use strict'
!(function(require, directRequire) {
  var a = Math.max
  const b = require('react'),
    c = require('./3b5f8e2469c474c8d433c1c6926d8999.js'),
    {
      enterBackground: d,
      enterForeground: e
    } = require('./a3959bb900db9f65ed2e9c5dfa6977b7.js'),
    {
      weappStoreFileReqular: f,
      weappTmpFileReqular: g,
      weappUsrFileReqular: h
    } = require('./6242f55dbdfe53c2f07b7a51568311f2.js')
  class i extends b.Component {
    constructor(a) {
      super(a),
        (this.state = {
          translateX: 0,
          lazyLoaded: !1,
          backgroundImageUrls: (a.urls || []).map(() => '')
        })
    }
    componentWillReceiveProps(b) {
      if (b.show != this.props.show)
        if (b.show) {
          d('previewImage')
          let c = b.current,
            e = b.urls || []
          ;(c = e.indexOf(c)),
            (c = a(c, 0)),
            this.setState({
              translateX: -c * b.width,
              lazyLoaded: !0,
              backgroundImageUrls: e.map(() => '')
            }),
            setTimeout(() => this.loadImages(e))
        } else e('previewImage')
    }
    loadImages(a) {
      for (let b, c = 0, d = a.length; c < d; c++) {
        ;(b = a[c]),
          'string' == typeof b && 0 <= b.indexOf('wxfile://')
            ? (b = b.replace('wxfile://', 'http://wxfile.open.weixin.qq.com/'))
            : (f.test(b) || g.test(b) || h.test(b)) &&
              (b = b.replace(
                /^https?:\/\//,
                `$&127.0.0.1:${global.proxyPort}/`
              ))
        const d = () => {
            e.removeEventListener('load', d)
            const a = [...this.state.backgroundImageUrls]
            a.splice(c, 1, b), this.setState({ backgroundImageUrls: a })
          },
          e = document.createElement('img')
        e.addEventListener('load', d), e.setAttribute('src', b)
      }
    }
    hide() {
      this.props.hidePreviewImage()
    }
    onMouseDown(a) {
      ;(this.startX = a.pageX),
        (this.touch = !0),
        (this.lastTranslateX = this.state.translateX)
    }
    onMouseMove(b) {
      if (!this.touch) return
      let c = b.pageX - this.startX + this.lastTranslateX
      ;(c = Math.min(0, c)),
        (c = a((1 - this.props.urls.length) * this.props.width, c)),
        this.setState({ translateX: c }),
        (this.moved = !0)
    }
    onMouseUp() {
      ;(this.startX = 0),
        (this.touch = !1),
        this.setState({
          translateX:
            parseInt(this.state.translateX / this.props.width - 0.5) *
            this.props.width
        }),
        setTimeout(() => {
          this.moved = !1
        })
    }
    onMouseEnter() {}
    onClick() {
      this.moved || this.hide()
    }
    render() {
      if (!this.state.lazyLoaded) return null
      let a = this.props,
        c = {
          display: a.show ? 'block' : 'none',
          transition: 'all linear 0.3s',
          width: `${100 * a.urls.length}%`,
          transform: `translate(${this.state.translateX}px,0)`
        },
        d = a.urls.map((c, d) => {
          let e = this.state.backgroundImageUrls[d]
          return b.createElement(
            'span',
            {
              key: d,
              className: 'weui-gallery__img',
              style: {
                backgroundImage: `url('${e}')`,
                width: a.width,
                left: d * a.width
              }
            },
            '' === e
              ? b.createElement(
                  'div',
                  { className: 'weui-gallery__loading' },
                  b.createElement('i', {
                    className: 'weui-loading weui-icon_toast'
                  })
                )
              : null
          )
        })
      return b.createElement(
        'div',
        {
          className: 'weui-gallery',
          style: c,
          onClick: this.onClick.bind(this),
          onMouseDown: this.onMouseDown.bind(this),
          onMouseMove: this.onMouseMove.bind(this),
          onMouseUp: this.onMouseUp.bind(this),
          onMouseLeave: this.onMouseUp.bind(this),
          onMouseEnter: this.onMouseEnter.bind(this)
        },
        d
      )
    }
  }
  module.exports = i
})(require('lazyload'), require)
