function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
var _excluded = ["visible", "separator", "value", "type", "min", "max", "hourStep", "minuteStep", "disabledStart", "disabledEnd", "allowClear", "onChange", "rangeId", "ranges", "titles", "portal", "selectorProps", "datePickerModalProps"];
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 ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
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, { useRef, forwardRef, useImperativeHandle } from 'react';
import getTitleByType from "./../utils/getTitleByType";
import updateRangeValue from "./updateRangeValue";
import SelectorMain from "./SelectorMain";
import getDefaultRanges from "./getDefaultRanges";
import PickerMain from "./PickerMain";

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

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

// 日期快捷选择
function RangeMain(_ref, ref) {
  var _titles, _titles2;
  var visible = _ref.visible,
    separator = _ref.separator,
    value = _ref.value,
    _ref$type = _ref.type,
    type = _ref$type === void 0 ? 'date' : _ref$type,
    min = _ref.min,
    max = _ref.max,
    hourStep = _ref.hourStep,
    minuteStep = _ref.minuteStep,
    disabledStart = _ref.disabledStart,
    disabledEnd = _ref.disabledEnd,
    allowClear = _ref.allowClear,
    onChange = _ref.onChange,
    rangeId = _ref.rangeId,
    ranges = _ref.ranges,
    titles = _ref.titles,
    portal = _ref.portal,
    selectorProps = _ref.selectorProps,
    datePickerModalProps = _ref.datePickerModalProps,
    props = _objectWithoutProperties(_ref, _excluded);
  // 默认分割符
  if (separator === undefined) {
    // eslint-disable-next-line
    separator = LocaleUtil.locale('至', 'SeedsUI_to');
  }
  // 默认标题
  if (titles === undefined) {
    // eslint-disable-next-line
    titles = {
      selector: LocaleUtil.locale('快捷选择', 'SeedsUI_date_range_selector_title'),
      custom: LocaleUtil.locale('自定义', 'SeedsUI_custom')
    };
  }
  var selectorRef = useRef(null);
  var rangeMainRef = useRef(null);
  if (ranges === undefined) {
    // eslint-disable-next-line
    ranges = getDefaultRanges();
  }

  // 判断有没有快捷选择
  var hasSelector = false;
  if (ranges) {
    for (var key in ranges) {
      if (Array.isArray(ranges[key])) {
        hasSelector = true;
      }
    }
  }
  useImperativeHandle(ref, function () {
    return _objectSpread(_objectSpread({}, rangeMainRef.current), {}, {
      getTitle: function getTitle() {
        return getTitleByType(type);
      }
    });
  });

  // unify onChange
  function handleChange(newValue) {
    var _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
      rangeId = _ref2.rangeId;
    onChange && onChange(updateRangeValue(newValue, type), {
      rangeId: rangeId || null,
      ranges: ranges
    });
  }
  return /*#__PURE__*/React.createElement(React.Fragment, null, hasSelector && typeof ((_titles = titles) === null || _titles === void 0 ? void 0 : _titles.selector) === 'string' ? /*#__PURE__*/React.createElement("p", {
    className: "datepicker-rangemain-selector-title selector"
  }, titles.selector) : null, hasSelector && /*#__PURE__*/React.createElement(SelectorMain, _extends({
    ref: selectorRef,
    value: value,
    allowClear: allowClear,
    onChange: handleChange,
    rangeId: rangeId,
    ranges: ranges
  }, selectorProps || {})), hasSelector && typeof ((_titles2 = titles) === null || _titles2 === void 0 ? void 0 : _titles2.custom) === 'string' ? /*#__PURE__*/React.createElement("p", {
    className: "datepicker-rangemain-selector-title custom"
  }, titles.custom) : null, /*#__PURE__*/React.createElement(PickerMain, _extends({
    ref: rangeMainRef,
    portal: portal,
    separator: separator,
    type: type,
    min: min,
    max: max,
    hourStep: hourStep,
    minuteStep: minuteStep,
    disabledStart: disabledStart,
    disabledEnd: disabledEnd,
    allowClear: allowClear,
    value: value,
    onChange: handleChange
  }, props)));
}
export default /*#__PURE__*/forwardRef(RangeMain);