var __assign = this && this.__assign || function () {
  __assign = Object.assign || function (t) {
    for (var s, i = 1, n = arguments.length; i < n; i++) {
      s = arguments[i];

      for (var p in s) {
        if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
      }
    }

    return t;
  };

  return __assign.apply(this, arguments);
};

import PickerButton from "../PickerButton";
import PickerTag from "../PickerTag";
import generateSinglePicker from "./generateSinglePicker";
import generateRangePicker from "./generateRangePicker";
export var PickerComponents = function PickerComponents(btnProps) {
  return {
    button: function button(props) {
      // 单独处理的事件
      var onClick = props.onClick;

      var _onClick = function _onClick(e) {
        var _a;

        onClick === null || onClick === void 0 ? void 0 : onClick(e);
        (_a = btnProps === null || btnProps === void 0 ? void 0 : btnProps.onClick) === null || _a === void 0 ? void 0 : _a.call(btnProps, e);
      };

      return PickerButton(__assign(__assign(__assign({}, props), btnProps), {
        onClick: _onClick
      }));
    },
    rangeItem: PickerTag
  };
};

function toArray(list) {
  if (!list) {
    return [];
  }

  return Array.isArray(list) ? list : [list];
} // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types


export function getTimeProps(props) {
  var format = props.format,
      picker = props.picker,
      showHour = props.showHour,
      showMinute = props.showMinute,
      showSecond = props.showSecond,
      use12Hours = props.use12Hours;
  var firstFormat = toArray(format)[0]; // eslint-disable-next-line @typescript-eslint/no-explicit-any

  var showTimeObj = __assign({}, props);

  if (firstFormat) {
    if (!firstFormat.includes('s') && showSecond === undefined) {
      showTimeObj.showSecond = false;
    }

    if (!firstFormat.includes('m') && showMinute === undefined) {
      showTimeObj.showMinute = false;
    }

    if (!firstFormat.includes('H') && !firstFormat.includes('h') && showHour === undefined) {
      showTimeObj.showHour = false;
    }

    if ((firstFormat.includes('a') || firstFormat.includes('A')) && use12Hours === undefined) {
      showTimeObj.use12Hours = true;
    }
  }

  if (picker === 'time') {
    return showTimeObj;
  }

  return {
    showTime: showTimeObj
  };
}

function generatePicker(generateConfig) {
  // =========================== Picker ===========================
  var _a = generateSinglePicker(generateConfig),
      DatePicker = _a.DatePicker,
      WeekPicker = _a.WeekPicker,
      MonthPicker = _a.MonthPicker,
      YearPicker = _a.YearPicker,
      TimePicker = _a.TimePicker; // ======================== Range Picker ========================


  var RangePicker = generateRangePicker(generateConfig);
  var MergedDatePicker = DatePicker;
  MergedDatePicker.WeekPicker = WeekPicker;
  MergedDatePicker.MonthPicker = MonthPicker;
  MergedDatePicker.YearPicker = YearPicker;
  MergedDatePicker.RangePicker = RangePicker;
  MergedDatePicker.TimePicker = TimePicker;
  return MergedDatePicker;
}

export default generatePicker;

