'use strict'
!(function(require, directRequire) {
  const a = require('react'),
    b = require('./3b5f8e2469c474c8d433c1c6926d8999.js'),
    c = require('./59394b696f4be6762ad2b2bf3e1575a7.js')
  class d extends a.Component {
    constructor(a) {
      super(a)
      let b = new Date()
      ;(this.state = {
        yearCurrent: b.getFullYear() - 1900,
        monthCurrent: b.getMonth(),
        dayCurrent: b.getDate() - 1
      }),
        (this.range = {}),
        (this.yearArray = [])
      for (let b = 1900; 2100 >= b; b++) this.yearArray.push(`${b}年`)
      this.monthArray = []
      for (let b = 1; 13 > b; b++)
        this.monthArray.push(9 < b ? `${b}月` : `0${b}月`)
      this.dayArray = []
      for (let b = 1; 32 > b; b++)
        this.dayArray.push(9 < b ? `${b}日` : `0${b}日`)
    }
    componentDidMount() {
      ;(this.range = {}),
        this.setRange('start', this.props.start || '1900-01-01'),
        this.setRange('end', this.props.end || '2100-01-01'),
        this.setCurrent(this.props.current)
    }
    componentWillReceiveProps(a) {
      var b = Math.min,
        c = Math.max
      if (a.show) {
        if (a.current != this.props.current) {
          let d = a.current || ''
          d = a.current.split('-')
          let e = parseInt(d[0]) - 1900,
            f = parseInt(d[1]) - 1,
            g = parseInt(d[2]) - 1,
            h = new Date()
          this.setState({
            yearCurrent: isNaN(e) ? h.getFullYear() - 1900 : b(c(e, 0), 2100),
            monthCurrent: isNaN(f) ? h.getMonth() : b(c(f, 0), 11),
            dayCurrent: isNaN(g) ? h.getDate() - 1 : b(c(g, 0), 30)
          })
        }
        a.start != this.props.start &&
          this.setRange('start', a.start || '1900-01-01'),
          a.end != this.props.end && this.setRange('end', a.end || '2100-01-01')
      }
    }
    validDate(a, b, c) {
      let d = new Date(`${a + 1900}-${b + 1}-${c + 1}`),
        e = d.getDate() - 1
      return (
        this.state.dayCurrent != e &&
          (this.setState({ dayCurrent: e }), this.refs.dayPicker.setCurrent(e)),
        d
      )
    }
    setRange(a, b) {
      if (b) {
        let c = new Date(b)
        'Invalid Date' != c && (this.range[a] = c.getTime())
      }
    }
    setCurrent(a) {
      if (!a) return
      let b = new Date(a + '')
      'Invalid Date' == b &&
        ((b = new Date()),
        b.getTime() < this.range.start
          ? (b = new Date(this.range.start))
          : b.getTime() > this.range.end && (b = new Date(this.range.end))),
        this.setState({
          yearCurrent: b.getFullYear() - 1900,
          monthCurrent: b.getMonth(),
          dayCurrent: b.getDate() - 1
        })
    }
    onYearSelect(a) {
      let b = a,
        c = this.validDate(b, this.state.monthCurrent, this.state.dayCurrent)
      if (c.getTime() < this.range.start) {
        let a = new Date(this.range.start)
        ;(b = a.getFullYear() - 1900),
          this.refs.yearPicker.setCurrent(b),
          this.refs.monthPicker.setCurrent(a.getMonth()),
          this.refs.dayPicker.setCurrent(a.getDate() - 1)
      } else if (c.getTime() > this.range.end) {
        let a = new Date(this.range.end)
        ;(b = a.getFullYear() - 1900),
          this.refs.yearPicker.setCurrent(b),
          this.refs.monthPicker.setCurrent(a.getMonth()),
          this.refs.dayPicker.setCurrent(a.getDate() - 1)
      }
      this.setState({ yearCurrent: b })
    }
    onMonthSelect(a) {
      let b = a,
        c = this.validDate(this.state.yearCurrent, b, this.state.dayCurrent)
      if (c.getTime() < this.range.start) {
        let a = new Date(this.range.start)
        ;(b = a.getMonth()),
          this.refs.monthPicker.setCurrent(b),
          this.refs.dayPicker.setCurrent(a.getDate() - 1)
      } else if (c.getTime() > this.range.end) {
        let a = new Date(this.range.end)
        ;(b = a.getMonth()),
          this.refs.monthPicker.setCurrent(b),
          this.refs.dayPicker.setCurrent(a.getDate() - 1)
      }
      this.setState({ monthCurrent: b })
    }
    onDaySelect(a) {
      let b = a,
        c = this.validDate(this.state.yearCurrent, this.state.monthCurrent, b)
      ;(b = c.getDate() - 1),
        c.getTime() < this.range.start
          ? ((b = new Date(this.range.start).getDate() - 1),
            this.refs.dayPicker.setCurrent(b))
          : c.getTime() > this.range.end &&
            ((b = new Date(this.range.end).getDate() - 1),
            this.refs.dayPicker.setCurrent(b)),
        this.setState({ dayCurrent: b })
    }
    getValue() {
      let a = this.state.yearCurrent + 1900
      if ('month' === this.props.fields) {
        let b = this.state.monthCurrent + 1
        ;(b = 9 < b ? b : '0' + b), (a = a + '-' + b)
      } else if ('day' === this.props.fields) {
        let b = this.state.monthCurrent + 1
        b = 9 < b ? b : '0' + b
        let c = this.state.dayCurrent + 1
        ;(c = 9 < c ? c : '0' + c), (a = a + '-' + b + '-' + c)
      }
      return a
    }
    hide() {
      this.props.hidePicker({
        callbackID: this.props.callbackID,
        webviewID: this.props.webviewID,
        res: { errMsg: 'showDatePickerView:cancel' }
      })
    }
    confirm() {
      this.props.hidePicker({
        callbackID: this.props.callbackID,
        webviewID: this.props.webviewID,
        res: { errMsg: 'showDatePickerView:ok', value: this.getValue() }
      })
    }
    render() {
      let d = this.props
      return a.createElement(
        'div',
        { style: d.show ? {} : b.displayNone },
        a.createElement('div', {
          className: 'weui-mask weui-animate-fade-in',
          onClick: this.hide.bind(this)
        }),
        a.createElement(
          'div',
          { className: 'weui-picker weui-animate-slide-up' },
          a.createElement(
            'div',
            { className: 'weui-picker__hd' },
            a.createElement(
              'a',
              {
                className: 'weui-picker__action',
                onClick: this.hide.bind(this)
              },
              '\u53D6\u6D88'
            ),
            a.createElement(
              'a',
              {
                className: 'weui-picker__action',
                onClick: this.confirm.bind(this)
              },
              '\u786E\u5B9A'
            )
          ),
          a.createElement(
            'div',
            { className: 'weui-picker__bd' },
            a.createElement(c, {
              ref: 'yearPicker',
              array: this.yearArray,
              current: this.state.yearCurrent,
              onPickerSelect: this.onYearSelect.bind(this)
            }),
            a.createElement(c, {
              ref: 'monthPicker',
              hidden: 'year' == d.fields,
              array: this.monthArray,
              current: this.state.monthCurrent,
              onPickerSelect: this.onMonthSelect.bind(this)
            }),
            a.createElement(c, {
              ref: 'dayPicker',
              hidden: 'day' != d.fields,
              array: this.dayArray,
              current: this.state.dayCurrent,
              onPickerSelect: this.onDaySelect.bind(this)
            })
          )
        )
      )
    }
  }
  module.exports = d
})(require('lazyload'), require)
