"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports["default"] = void 0;
exports.uuid = uuid;
var _datePicker = _interopRequireDefault(require("antd/lib/date-picker"));
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
var React = _interopRequireWildcard(require("react"));
var _moment = _interopRequireDefault(require("moment"));
var _localHelper = require("./localHelper");
require("./index.less");
var _excluded = ["DatePickerType", "allowClear", "autoFocus", "bordered", "dateRender", "disabled", "disabledDate", "placement", "size", "defaultValue", "format", "showTime", "showNow", "showToday", "renderExtraFooter", "flag", "wholeStyle", "style"];
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
var antDatePicker = function antDatePicker(_ref) {
  var DatePickerType = _ref.DatePickerType,
    allowClear = _ref.allowClear,
    autoFocus = _ref.autoFocus,
    bordered = _ref.bordered,
    dateRender = _ref.dateRender,
    disabled = _ref.disabled,
    disabledDate = _ref.disabledDate,
    placement = _ref.placement,
    size = _ref.size,
    defaultValue = _ref.defaultValue,
    format = _ref.format,
    showTime = _ref.showTime,
    showNow = _ref.showNow,
    showToday = _ref.showToday,
    _renderExtraFooter = _ref.renderExtraFooter,
    flag = _ref.flag,
    wholeStyle = _ref.wholeStyle,
    style = _ref.style,
    otherProps = (0, _objectWithoutPropertiesLoose2["default"])(_ref, _excluded);
  var yangshi = (0, _extends2["default"])({}, style);
  var _style = style || {};
  var newstyle = JSON.stringify(_style);
  var _otherProps = otherProps || {};
  // _otherProps.style = _style;

  _otherProps.style = (0, _extends2["default"])({}, _style);
  var arrObj = Object.keys(_otherProps.style);
  if (arrObj.length > 0) {
    for (var k in _otherProps.style) {
      if (k == 'paddingRight' || k == 'paddingLeft' || k == 'paddingTop' || k == 'paddingBottom' || k == 'marginRight' || k == 'marginLeft' || k == 'marginTop' || k == 'marginBottom') {
        _otherProps.style[k] = '0px';
      }
      if (k == 'width' || k == 'height') {
        _otherProps.style[k] = '100%';
      }
    }
  }
  var _useState = (0, React.useState)(''),
    ID = _useState[0],
    setID = _useState[1];
  var _useState2 = (0, React.useState)(false),
    ifOpen = _useState2[0],
    setIfOpen = _useState2[1];
  (0, React.useEffect)(function () {
    setID("antDatePicker_" + uuid());
  }, []);
  (0, React.useEffect)(function () {
    ChangeSize();
  }, [ID, _otherProps]);
  var ChangeSize = function ChangeSize() {
    setTimeout(function () {
      if (ID) {
        var elemsMax = document.getElementById(ID) || document;
        newstyle = JSON.parse(newstyle);
        elemsMax.style.paddingRight = newstyle.paddingRight ? newstyle.paddingRight : 0;
        elemsMax.style.paddingLeft = newstyle.paddingLeft ? newstyle.paddingLeft : 0;
        elemsMax.style.paddingTop = newstyle.paddingTop ? newstyle.paddingTop : 0;
        elemsMax.style.paddingBottom = newstyle.paddingBottom ? newstyle.paddingBottom : 0;
        elemsMax.style.marginRight = newstyle.marginRight ? newstyle.marginRight : 0;
        elemsMax.style.marginLeft = newstyle.marginLeft ? newstyle.marginLeft : 0;
        elemsMax.style.marginTop = newstyle.marginTop ? newstyle.marginTop : 0;
        elemsMax.style.marginBottom = newstyle.marginBottom ? newstyle.marginBottom : 0;
      }
    }, 0);
  };
  (0, React.useEffect)(function () {
    if (ID) {
      document.getElementById(ID).style.setProperty('--pickerColor', style !== null && style !== void 0 && style.color ? style === null || style === void 0 ? void 0 : style.color : '#DCDCDC');
      document.getElementById(ID).style.setProperty('--pickerInputFontWeight', style !== null && style !== void 0 && style.fontWeight ? style === null || style === void 0 ? void 0 : style.fontWeight : '400');
      document.getElementById(ID).style.setProperty('--pickerInputFontSize', style !== null && style !== void 0 && style.fontSize ? (style === null || style === void 0 ? void 0 : style.fontSize) + 'px' : '14px');
    }
  });
  (0, React.useEffect)(function () {
    if (ID && document.getElementsByClassName(ID)) {
      document.getElementsByClassName(ID)[0].style.setProperty('--xzPickerColor', wholeStyle.boxStyle.pitchOnStyle.color);
      document.getElementsByClassName(ID)[0].style.setProperty('--xzPickerFontSize', wholeStyle.boxStyle.pitchOnStyle.size + 'px');
      document.getElementsByClassName(ID)[0].style.setProperty('--xzPickerBackground', wholeStyle.boxStyle.pitchOnStyle.backgroundColor);
      document.getElementsByClassName(ID)[0].style.setProperty('--ydPickerColor', wholeStyle.boxStyle.mouseStyle.color);
      document.getElementsByClassName(ID)[0].style.setProperty('--ydPickerFontSize', wholeStyle.boxStyle.mouseStyle.size + 'px');
      document.getElementsByClassName(ID)[0].style.setProperty('--ydPickerBackground', wholeStyle.boxStyle.mouseStyle.backgroundColor);
      document.getElementsByClassName(ID)[0].style.setProperty('--bjPickerColor', wholeStyle.toubuStyle.morenStyle.color);
      document.getElementsByClassName(ID)[0].style.setProperty('--bjPickerFontSize', wholeStyle.toubuStyle.morenStyle.size + 'px');
      document.getElementsByClassName(ID)[0].style.setProperty('--bjPickerBorderBottom', wholeStyle.toubuStyle.morenStyle.borderBottomColor);
      document.getElementsByClassName(ID)[0].style.setProperty('--bjPickerBacColor', wholeStyle.toubuStyle.morenStyle.backgroundColor);
      document.getElementsByClassName(ID)[0].style.setProperty('--bjPickerIconFontSize', wholeStyle.toubuStyle.arrowsStyle.size);
      document.getElementsByClassName(ID)[0].style.setProperty('--bjPickerIconColor', wholeStyle.toubuStyle.arrowsStyle.color);
      document.getElementsByClassName(ID)[0].style.setProperty('--bjPickerIconHoverFontSize', wholeStyle.toubuStyle.arrowsHoverStyle.size);
      document.getElementsByClassName(ID)[0].style.setProperty('--bjPickerIconHoverColor', wholeStyle.toubuStyle.arrowsHoverStyle.color);
      document.getElementsByClassName(ID)[0].style.setProperty('--bjboxIconBackgroundcolor', wholeStyle.boxStyle.morenStyle.backgroundColor);
    }
  }, [ifOpen]);
  var onOpenChange = function onOpenChange(open) {
    setIfOpen(open);
  };
  // || k == 'width' || k == 'height'

  var date = function date() {
    return /*#__PURE__*/React.createElement(_datePicker["default"], (0, _extends2["default"])({
      style: style,
      popupClassName: ID,
      onOpenChange: onOpenChange,
      open: ifOpen
      // className={flag ? "isflag" : ""}
      ,
      locale: _localHelper.LocalFormat.getDefinedChineseLocal(),
      inputReadOnly: true,
      allowClear: allowClear,
      autoFocus: autoFocus,
      bordered: !bordered,
      dateRender: dateRender,
      disabled: disabled,
      disabledDate: disabledDate,
      placement: placement,
      size: size,
      defaultValue: (0, _moment["default"])(defaultValue, format),
      value: defaultValue ? (0, _moment["default"])(defaultValue, format) : null,
      format: format,
      showTime: showTime,
      showNow: showNow,
      showToday: showToday,
      renderExtraFooter: function renderExtraFooter() {
        return _renderExtraFooter;
      }
    }, _otherProps));
  };
  // const week = () => {
  //   return (
  //     <DatePicker
  //       style={style}
  //       // className={flag ? "isflag" : ""}
  //       picker="week"
  //       placeholder='请选择周'
  //       inputReadOnly={true}
  //       allowClear={allowClear}
  //       autoFocus={autoFocus}
  //       bordered={!bordered}
  //       dateRender={dateRender}
  //       disabled={disabled}
  //       disabledDate={disabledDate}
  //       placement={placement}
  //       size={size}
  //       defaultValue={moment(defaultValue, 'YYYY-wo')}
  //       value={defaultValue ? moment(defaultValue, 'YYYY-wo') : null}
  //       {..._otherProps} />
  //   );
  // };
  var month = function month() {
    return /*#__PURE__*/React.createElement(_datePicker["default"], (0, _extends2["default"])({
      style: style,
      popupClassName: ID,
      onOpenChange: onOpenChange,
      open: ifOpen
      // className={flag ? "isflag" : ""}
      ,
      picker: "month",
      inputReadOnly: true,
      locale: _localHelper.LocalFormat.getDefinedChineseLocal(),
      allowClear: allowClear,
      autoFocus: autoFocus,
      bordered: !bordered,
      dateRender: dateRender,
      disabled: disabled,
      disabledDate: disabledDate,
      placement: placement,
      size: size,
      defaultValue: (0, _moment["default"])(defaultValue, 'YYYY-MM'),
      value: defaultValue ? (0, _moment["default"])(defaultValue, 'YYYY-MM') : null,
      renderExtraFooter: function renderExtraFooter() {
        return _renderExtraFooter;
      }
    }, _otherProps));
  };
  var quarter = function quarter() {
    return /*#__PURE__*/React.createElement(_datePicker["default"], (0, _extends2["default"])({
      style: style,
      popupClassName: ID,
      onOpenChange: onOpenChange,
      open: ifOpen
      // className={flag ? "isflag" : ""}
      ,
      picker: "quarter",
      inputReadOnly: true,
      locale: _localHelper.LocalFormat.getDefinedChineseLocal(),
      allowClear: allowClear,
      autoFocus: autoFocus,
      bordered: !bordered,
      dateRender: dateRender,
      disabled: disabled,
      disabledDate: disabledDate,
      placement: placement,
      size: size,
      defaultValue: (0, _moment["default"])(defaultValue, 'YYYY-\QQ'),
      value: defaultValue ? (0, _moment["default"])(defaultValue, 'YYYY-\QQ') : null,
      renderExtraFooter: function renderExtraFooter() {
        return _renderExtraFooter;
      }
    }, _otherProps));
  };
  var year = function year() {
    return /*#__PURE__*/React.createElement(_datePicker["default"], (0, _extends2["default"])({
      style: style,
      popupClassName: ID,
      onOpenChange: onOpenChange,
      open: ifOpen
      // className={flag ? "isflag" : ""}
      ,
      picker: "year",
      inputReadOnly: true,
      locale: _localHelper.LocalFormat.getDefinedChineseLocal(),
      allowClear: allowClear,
      autoFocus: autoFocus,
      bordered: !bordered,
      dateRender: dateRender,
      disabled: disabled,
      disabledDate: disabledDate,
      placement: placement,
      size: size,
      defaultValue: (0, _moment["default"])(defaultValue, 'YYYY'),
      value: defaultValue ? (0, _moment["default"])(defaultValue, 'YYYY') : null,
      renderExtraFooter: function renderExtraFooter() {
        return _renderExtraFooter;
      }
    }, _otherProps));
  };
  return /*#__PURE__*/React.createElement("div", {
    className: "antDatePicker",
    id: ID,
    style: {
      width: yangshi && yangshi.width ? yangshi.width : '',
      height: yangshi && yangshi.height ? yangshi.height : '',
      display: flag ? 'none' : 'inline-block'
    }
  }, function () {
    switch (DatePickerType) {
      case '日期':
        return date();
        break;
      // case '周':
      //   return week()
      //   break
      case '月份':
        return month();
        break;
      case '季度':
        return quarter();
        break;
      case '年份':
        return year();
        break;
      default:
        return false;
    }
  }());
};
antDatePicker.displayName = 'antDatePicker';
var _default = antDatePicker;
exports["default"] = _default;
function uuid() {
  return (Math.random() * 1e6 >> 0).toString(36);
}