function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
import React, { forwardRef, useRef, useImperativeHandle, useEffect, useState } from 'react';
import getTitleByType from "./../utils/getTitleByType";
import Main from "./../Main";
import formatValue from "./formatValue";
import getActiveTab from "./getActiveTab";

// 内库使用-start
import DateUtil from "./../../../utils/DateUtil";
import TabBar from "./../../TabBar";
// 内库使用-end

/* 测试使用-start
import { DateUtil, TabBar } from 'seedsui-react'
测试使用-end */

// 日期多选
function MultipleMain(_ref, ref) {
  var _ref$visible = _ref.visible,
    visible = _ref$visible === void 0 ? true : _ref$visible,
    separator = _ref.separator,
    value = _ref.value,
    _ref$type = _ref.type,
    type = _ref$type === void 0 ? 'date' : _ref$type,
    allowClear = _ref.allowClear,
    min = _ref.min,
    max = _ref.max,
    hourStep = _ref.hourStep,
    minuteStep = _ref.minuteStep,
    _onChange = _ref.onChange;
  // 格式化数据
  var tabsRef = useRef(null);
  tabsRef.current = formatValue(value, type);
  var _useState = useState(null),
    _useState2 = _slicedToArray(_useState, 2),
    activeTab = _useState2[0],
    setActiveTab = _useState2[1];

  // Expose tools
  var mainRef = useRef(null);
  useImperativeHandle(ref, function () {
    return {
      mainDOM: mainRef.current,
      getMainDOM: function getMainDOM() {
        return mainRef.current;
      },
      // 获取标题
      getTitle: function getTitle() {
        return getTitleByType(type);
      },
      getValue: function getValue() {
        return tabsRef.current;
      }
    };
  });
  useEffect(function () {
    if (activeTab) return;
    setActiveTab(getActiveTab(tabsRef.current));
    // eslint-disable-next-line
  }, [value]);
  return /*#__PURE__*/React.createElement("div", {
    ref: mainRef,
    className: "picker-multiple-main"
  }, Array.isArray(tabsRef.current) && tabsRef.current.length ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(TabBar.Tabs, {
    className: "picker-tabs",
    separator: separator,
    descriptionPosition: "top",
    list: tabsRef.current,
    value: activeTab,
    onChange: setActiveTab
  }), tabsRef.current.map(function (tab, index) {
    // 主体内容(wrapper)是否显示
    var contentVisible = (tab === null || tab === void 0 ? void 0 : tab.id) === (activeTab === null || activeTab === void 0 ? void 0 : activeTab.id);
    if (!contentVisible) return null;
    return /*#__PURE__*/React.createElement(Main, {
      key: tab.id || index,
      value: tab.value,
      type: type,
      min: min,
      max: max,
      hourStep: hourStep,
      minuteStep: minuteStep,
      className: tab.disabled ? 'disabled' : '',
      onChange: function onChange(date) {
        tab.value = date;
        tab.name = DateUtil.format(tab.value, type);
        _onChange && _onChange(tabsRef.current);
      }
    });
  })) : null);
}
export default /*#__PURE__*/forwardRef(MultipleMain);