import _extends from "@babel/runtime/helpers/extends";
import _DatePicker from "antd/es/date-picker";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
var _excluded = ["DatePickerType", "allowClear", "autoFocus", "bordered", "dateRender", "disabled", "disabledDate", "placement", "size", "defaultValue", "format", "showTime", "showNow", "showToday", "renderExtraFooter", "flag", "style"];
/* eslint-disable @typescript-eslint/no-shadow */

import * as React from 'react';
import { useState, useEffect } from 'react';
import moment from 'moment';
import { LocalFormat } from "./localHelper";
import "./index.less";
var antDatePickerScope = function antDatePickerScope(_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,
    style = _ref.style,
    otherProps = _objectWithoutPropertiesLoose(_ref, _excluded);
  var RangePicker = _DatePicker.RangePicker;
  var yangshi = _extends({}, style);
  var _style = style || {};
  var newstyle = JSON.stringify(_style);
  var _otherProps = otherProps || {};
  // _otherProps.style = _style;
  _otherProps.style = _extends({}, _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 = useState(''),
    ID = _useState[0],
    setID = _useState[1];
  useEffect(function () {
    setID("antDatePicker_" + uuid());
  }, []);
  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);
  };
  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');
    }
  });
  var date = function date() {
    return /*#__PURE__*/React.createElement(RangePicker, _extends({
      className: flag ? "isflag" : "",
      locale: LocalFormat.getDefinedChineseLocal(),
      inputReadOnly: true,
      allowClear: allowClear,
      autoFocus: autoFocus,
      bordered: !bordered,
      dateRender: dateRender,
      disabled: disabled,
      disabledDate: disabledDate,
      size: size,
      defaultValue: [moment(defaultValue[0], format), moment(defaultValue[1], format)],
      value: defaultValue ? [moment(defaultValue[0], format), moment(defaultValue[1], format)] : null,
      format: format,
      showTime: showTime,
      showNow: showNow,
      renderExtraFooter: function renderExtraFooter() {
        return _renderExtraFooter;
      }
    }, _otherProps));
  };
  // const week = () => {
  //   return (
  //     <RangePicker
  //       picker="week"
  //       className={flag ? "isflag" : ""}
  //       locale={LocalFormat.getDefinedChineseLocal()}
  //       inputReadOnly={true}
  //       allowClear={allowClear}
  //       autoFocus={autoFocus}
  //       bordered={!bordered}
  //       dateRender={dateRender}
  //       disabled={disabled}
  //       disabledDate={disabledDate}
  //       placement={placement}
  //       size={size}
  //       allowEmpty={[true, false]}
  //       defaultValue={[moment(defaultValue[0], 'YYYY-wo'), moment(defaultValue[1], 'YYYY-wo')]}
  //       value={defaultValue ? [moment(defaultValue[0], 'YYYY-wo'), moment(defaultValue[1], 'YYYY-wo')] : null}
  //       {..._otherProps} />
  //   );
  // };
  var month = function month() {
    return /*#__PURE__*/React.createElement(RangePicker, _extends({
      picker: "month",
      className: flag ? "isflag" : "",
      locale: LocalFormat.getDefinedChineseLocal(),
      inputReadOnly: true,
      allowClear: allowClear,
      autoFocus: autoFocus,
      bordered: !bordered,
      dateRender: dateRender,
      disabled: disabled,
      disabledDate: disabledDate,
      placement: placement,
      size: size,
      defaultValue: [moment(defaultValue[0], 'YYYY-MM'), moment(defaultValue[1], 'YYYY-MM')],
      value: defaultValue ? [moment(defaultValue[0], 'YYYY-MM'), moment(defaultValue[1], 'YYYY-MM')] : null
      // format={format}
      ,
      renderExtraFooter: function renderExtraFooter() {
        return _renderExtraFooter;
      }
    }, _otherProps));
  };
  var quarter = function quarter() {
    return /*#__PURE__*/React.createElement(RangePicker, _extends({
      picker: "quarter",
      className: flag ? "isflag" : "",
      locale: LocalFormat.getDefinedChineseLocal(),
      inputReadOnly: true,
      allowClear: allowClear,
      autoFocus: autoFocus,
      bordered: !bordered,
      dateRender: dateRender,
      disabled: disabled,
      disabledDate: disabledDate,
      placement: placement,
      size: size,
      defaultValue: [moment(defaultValue[0], 'YYYY-\QQ'), moment(defaultValue[1], 'YYYY-\QQ')],
      value: defaultValue ? [moment(defaultValue[0], 'YYYY-\QQ'), moment(defaultValue[1], 'YYYY-\QQ')] : null
      // format={format}
      ,
      renderExtraFooter: function renderExtraFooter() {
        return _renderExtraFooter;
      }
    }, _otherProps));
  };
  var year = function year() {
    return /*#__PURE__*/React.createElement(RangePicker, _extends({
      inputReadOnly: true,
      picker: "year",
      className: flag ? "isflag" : "",
      locale: LocalFormat.getDefinedChineseLocal(),
      allowClear: allowClear,
      autoFocus: autoFocus,
      bordered: !bordered,
      dateRender: dateRender,
      disabled: disabled,
      disabledDate: disabledDate,
      placement: placement,
      size: size,
      defaultValue: [moment(defaultValue[0], 'YYYY'), moment(defaultValue[1], 'YYYY')],
      value: defaultValue ? [moment(defaultValue[0], 'YYYY'), moment(defaultValue[1], 'YYYY')] : null
      // format={format}
      ,
      renderExtraFooter: function renderExtraFooter() {
        return _renderExtraFooter;
      }
    }, _otherProps));
  };
  return /*#__PURE__*/React.createElement("div", {
    className: "antDatePickerScope",
    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;
    }
  }());
};
antDatePickerScope.displayName = 'antDatePickerScope';
export default antDatePickerScope;
export function uuid() {
  return (Math.random() * 1e6 >> 0).toString(36);
}