import "antd-mobile/es/toast/style";
import _Toast from "antd-mobile/es/toast";

function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }

function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }

function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }

function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }

function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

import React, { Component, PureComponent } from 'react';

/* babel-plugin-inline-import '../assets/up-arrow.png' */
var UpArrowPng = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAAM1BMVEUAAACZmZmYmJigoKCXl5eYmJiYmJiYmJiYmJiXl5eYmJiYmJiampqXl5ecnJyqqqqXl5eVv79FAAAAEHRSTlMAiXcV04FX1MTltZ9JOywJt9JosgAAAFlJREFUOMvtyksOgCAMRdEqisVv979aWxi8REgdqol3eg+9sGP3fxhkvPmiwv0mnD8twhCNHzrpI0T9SQFB1D+DtmD7BWQRr2Bm/QWYSAAIwPrB02BNG32vE/lgA/nJAnnvAAAAAElFTkSuQmCC";
import UnitHeader from './UnitHeader';
import UnitLeft from './UnitLeft';
import UnitWithoutHour from './UnitBodyWithoutHour';
import UnitWithHour from './UnitBodyWithHour';
import ConfirmBottom from './ConfirmBottom';
var now = new Date();

var Main =
/*#__PURE__*/
function (_ref) {
  _inherits(Main, _ref);

  function Main() {
    var _getPrototypeOf2;

    var _this;

    _classCallCheck(this, Main);

    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    _this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(Main)).call.apply(_getPrototypeOf2, [this].concat(args)));

    _defineProperty(_assertThisInitialized(_this), "state", {
      ruleDate: new Date().getTime(),
      // 当前时间
      dataDetail: {},
      // 接口返回的数据
      rentalDate: '',
      // 点下一步 需要知道所选的日期
      calendarShow: false,
      // 是否显示日历
      tabsBarHeight: 80,
      // 默认topbarHeight
      loadingData: false,
      headerContent: [{
        // 头部
        title: '星期日'
      }, {
        title: '星期一'
      }, {
        title: '星期二'
      }, {
        title: '星期三'
      }, {
        title: '星期四'
      }, {
        title: '星期五'
      }, {
        title: '星期六'
      }],
      bottomState: {
        // 底部的state，让UnitWithoutHour组件修改
        price: '',
        originalPrice: '',
        counts: '',
        rentalDate: '',
        // 点下一步 需要知道所选的日期
        rulesId: [] // 选中的格子id数组

      },
      navContent: [],
      // 时间轴数据
      bodyArray: [] // 表格主题数据

    });

    _defineProperty(_assertThisInitialized(_this), "onCancel", function () {
      _this.setState({
        calendarShow: false
      });
    });

    _defineProperty(_assertThisInitialized(_this), "onConfirm", function (Date) {
      var self = _assertThisInitialized(_this);

      _Toast.loading('加载中', 10);

      self.getData({
        ruleDate: Date.getTime()
      }, function (state) {
        self.setState(_objectSpread({}, state, {
          calendarShow: false
        }), function () {
          _Toast.hide();
        });
      });
    });

    return _this;
  }

  _createClass(Main, [{
    key: "componentDidMount",
    value: function componentDidMount() {
      this.initComponent(this.props);
    }
  }, {
    key: "componentWillReceiveProps",
    value: function componentWillReceiveProps(nextProps) {
      this.initComponent(nextProps);
    }
  }, {
    key: "initComponent",
    value: function initComponent(_ref2) {
      var _this2 = this;

      var _ref2$headerContent = _ref2.headerContent,
          headerContent = _ref2$headerContent === void 0 ? [] : _ref2$headerContent,
          _ref2$dataDetail = _ref2.dataDetail,
          dataDetail = _ref2$dataDetail === void 0 ? {} : _ref2$dataDetail,
          _ref2$navContent = _ref2.navContent,
          navContent = _ref2$navContent === void 0 ? [] : _ref2$navContent,
          _ref2$ruleDate = _ref2.ruleDate,
          ruleDate = _ref2$ruleDate === void 0 ? '' : _ref2$ruleDate,
          _ref2$bodyArray = _ref2.bodyArray,
          bodyArray = _ref2$bodyArray === void 0 ? [] : _ref2$bodyArray;
      this.setState({
        headerContent: headerContent,
        bodyArray: bodyArray,
        dataDetail: dataDetail,
        navContent: navContent,
        ruleDate: ruleDate
      }, function () {
        _this2.setState({
          pullDownShow: true
        });
      });
    }
  }, {
    key: "getData",
    value: function getData(data, callback, concatFlag) {
      this.props.getUnitData(data, callback, concatFlag);
    }
  }, {
    key: "render",
    value: function render() {
      var _this3 = this;

      var windowHeight = window.innerHeight;
      var _this$props = this.props,
          history = _this$props.history,
          concatFlag = _this$props.concatFlag,
          _this$props$halfDayTi = _this$props.halfDayTimeIntervals,
          halfDayTimeIntervals = _this$props$halfDayTi === void 0 ? [] : _this$props$halfDayTi;
      var _window$$$RESOURCECON = window.$$RESOURCECONTEXT,
          multiUnit = _window$$$RESOURCECON.multiUnit,
          autoAssign = _window$$$RESOURCECON.autoAssign,
          notice = _window$$$RESOURCECON.notice,
          rentalType = _window$$$RESOURCECON.rentalType,
          Spin = _window$$$RESOURCECON.Spin,
          Calendar = _window$$$RESOURCECON.Calendar;
      var _this$state = this.state,
          pullDownShow = _this$state.pullDownShow,
          calendarShow = _this$state.calendarShow,
          headerContent = _this$state.headerContent,
          rentalDate = _this$state.rentalDate,
          navContent = _this$state.navContent,
          bodyArray = _this$state.bodyArray,
          bottomState = _this$state.bottomState,
          dataDetail = _this$state.dataDetail,
          ruleDate = _this$state.ruleDate,
          loadingData = _this$state.loadingData;
      var bottomHeight = 110;
      var detailBodyCls = '';

      if (String(rentalType) === '1' || String(rentalType) === '3') {
        detailBodyCls = "halfDay".concat(halfDayTimeIntervals.length);
      } else if (String(rentalType) === '5') {
        detailBodyCls = 'perWeekUnit';
      }

      if (String(multiUnit) === '1' && String(autoAssign) === '0') {
        bottomHeight += 45;
      }

      if (String(notice) && String(notice) !== 'undefined') {
        bottomHeight += 30; // 有提示
      }

      return React.createElement("div", {
        className: "parameter",
        style: {
          height: "".concat(windowHeight, "px")
        }
      }, React.createElement("section", {
        style: {
          overflow: 'hidden'
        },
        className: "parameter-detail fn-mt",
        id: "unit-scroll"
      }, headerContent.length > 0 && React.createElement(UnitHeader, {
        autoAssign: autoAssign,
        rentalType: rentalType,
        ruleDate: ruleDate,
        setParentState: function setParentState(state) {
          return _this3.setState(state);
        },
        headerContent: headerContent
      }), React.createElement(Spin, {
        spinning: loadingData
      }, React.createElement("div", {
        style: {
          height: "".concat(windowHeight - bottomHeight * window.devicePixelRatio, "px")
        },
        className: "detail detail-body nav-bar ".concat(detailBodyCls),
        id: "detail"
      }, React.createElement("div", {
        style: {
          backgroundColor: 'white'
        }
      }, React.createElement("div", {
        id: "pull-down-refresh",
        className: "pull-down-refresh"
      }, String(rentalType) === '0' && String(autoAssign) === '0' ? '' : pullDownShow && React.createElement("span", null, React.createElement("span", {
        id: "pull-down-icon"
      }, React.createElement("img", {
        alt: "",
        src: UpArrowPng
      })), React.createElement("span", {
        id: "pull-down-text"
      }, "\u4E0B\u62C9\u52A0\u8F7D\u66F4\u591A"))), navContent.length > 0 && React.createElement(UnitLeft, {
        halfDayTimeIntervals: halfDayTimeIntervals,
        navContent: navContent
      }), String(rentalType) !== '0' && bodyArray.length > 0 && headerContent.length > 0 && React.createElement(UnitWithoutHour, {
        getData: function getData(data, callback, concatFlag1) {
          return _this3.getData(data, callback, concatFlag1);
        },
        dataDetail: dataDetail,
        navContent: navContent,
        headerContent: headerContent,
        bodyArray: bodyArray,
        ruleDate: ruleDate,
        concatFlag: concatFlag,
        halfDayTimeIntervals: halfDayTimeIntervals,
        setParentState: function setParentState(state) {
          return _this3.setState(state);
        }
      }), String(rentalType) === '0' && bodyArray.length > 0 && headerContent.length > 0 && React.createElement(UnitWithHour, {
        getData: function getData(data, callback) {
          return _this3.getData(data, callback);
        },
        dataDetail: dataDetail,
        headerContent: headerContent,
        bodyArray: bodyArray,
        ruleDate: ruleDate,
        setParentState: function setParentState(state) {
          return _this3.setState(state);
        }
      }), React.createElement("div", {
        id: "pull-up-refresh",
        className: "pull-up-refresh"
      }, String(rentalType) === '0' && String(autoAssign) === '0' ? '' : pullDownShow && React.createElement("span", null, React.createElement("span", {
        id: "pull-up-icon"
      }, React.createElement("img", {
        alt: "",
        src: UpArrowPng
      })), React.createElement("span", {
        id: "pull-up-text"
      }, "\u4E0A\u62C9\u52A0\u8F7D\u66F4\u591A"))))))), React.createElement(ConfirmBottom, _extends({
        history: history,
        rentalDate: rentalDate || ruleDate,
        dataDetail: dataDetail
      }, bottomState)), React.createElement("div", null, React.createElement(Calendar // locale={zhCN}
      , {
        visible: calendarShow,
        onCancel: this.onCancel,
        onConfirm: this.onConfirm,
        defaultDate: now,
        rowSize: "xl",
        type: "one",
        minDate: new Date(+now)
      })));
    }
  }]);

  return Main;
}(PureComponent || Component);

export default Main;