var _excluded = ["value", "allowClear", "onChange", "rangeId", "ranges"];
function _extends() { _extends = Object.assign ? Object.assign.bind() : 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 _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
import React, { forwardRef, useRef, useImperativeHandle } from 'react';
import getSelectorOptions from "./../getSelectorOptions";

// 内库使用-start
import Selector from "./../../../Selector";
// 内库使用-end

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

// 日期快捷选择
function RangeMain(_ref, ref) {
  var value = _ref.value,
    allowClear = _ref.allowClear,
    _onChange = _ref.onChange,
    rangeId = _ref.rangeId,
    ranges = _ref.ranges,
    props = _objectWithoutProperties(_ref, _excluded);
  var rootRef = useRef(null);
  useImperativeHandle(ref, function () {
    return {
      rootDOM: rootRef.current,
      getRootDOM: function getRootDOM() {
        return rootRef.current;
      }
    };
  });
  return /*#__PURE__*/React.createElement("div", _extends({}, props, {
    className: "datepicker-rangemain-selector".concat(props.className ? ' ' + props.className : ''),
    ref: rootRef
  }), /*#__PURE__*/React.createElement(Selector, {
    columns: 5,
    allowClear: allowClear,
    value: [{
      id: rangeId
    }]
    // 过滤自定义配置
    ,
    list: getSelectorOptions(ranges, function (item) {
      if (!Array.isArray(item === null || item === void 0 ? void 0 : item.value) || !(item !== null && item !== void 0 && item.value.length)) {
        return false;
      }
      return true;
    }),
    onChange: function onChange(newRange) {
      var _newRange$;
      var newRangeId = (newRange === null || newRange === void 0 || (_newRange$ = newRange[0]) === null || _newRange$ === void 0 ? void 0 : _newRange$.id) || '';
      var newValue = newRangeId && Array.isArray(ranges[newRangeId]) && ranges[newRangeId].length === 2 ? ranges[newRangeId] : value;
      _onChange && _onChange(newValue, {
        rangeId: newRangeId
      });
    }
  }));
}
export default /*#__PURE__*/forwardRef(RangeMain);