import React__default, { useState, useMemo, useEffect, useCallback } from 'react';
import moment from 'moment';
import { DatePicker } from 'antd';
import Title from '../Title/index.js';
import IconFont from '../IconFont/index.js';
import { LMConfig } from '@zenview/micro-basic-library';
import '../BetweenBox/index.js';
import '../_rollupPluginBabelHelpers-736b301a.js';
import '@zenview/micro-utils';

function RangePicker({
  className = '',
  title,
  icon,
  download,
  onChange,
  value,
  showTime,
  format = 'YYYY.MM.DD HH:mm:ss',
  dropdownClassName,
  showFastSet,
  defaultDay,
  getContainer
}) {
  const [_value, setValue] = useState(value);
  const rangesarr = useMemo(() => {
    if (download) {
      return {
        '3天': [moment(new Date()).subtract(3, 'd'), moment()],
        '7天': [moment(new Date()).subtract(7, 'd'), moment()]
      };
    } else {
      return {
        '3天': [moment(new Date()).subtract(3, 'd'), moment()],
        '7天': [moment(new Date()).subtract(7, 'd'), moment()],
        '15天': [moment(new Date()).subtract(15, 'd'), moment()]
      };
    }
  }, [download]);
  useEffect(() => setValue(value), [value]);
  const fastSetTime = useCallback(type => {
    const dates = [moment().subtract(type, 'day'), moment()];
    setValue(() => dates);
    onChange(dates);
  }, [onChange]);
  const onPickChange = useCallback(dates => {
    onChange && onChange(dates);
    setValue(dates);
  }, [onChange]);
  return /*#__PURE__*/React__default.createElement("div", {
    className: `lm-filter-range-picker-wrapper ${className}`
  }, title && /*#__PURE__*/React__default.createElement(Title, {
    icon: icon,
    title: title,
    className: ""
  }, Array.isArray(_value) && !_value[0] && !_value[1] && title && /*#__PURE__*/React__default.createElement("div", {
    style: {
      fontSize: 12,
      color: 'var(--text-light)'
    }
  }, /*#__PURE__*/React__default.createElement(IconFont, {
    type: "icon-S_Photo_AlarmOpen",
    style: {
      paddingRight: 4,
      fontSize: 14
    }
  }), "\u9ED8\u8BA4\u67E5\u8BE2\u8FD1", defaultDay || LMConfig.BSConfig.dataRetention, "\u5929")), showFastSet && /*#__PURE__*/React__default.createElement("div", {
    className: "fast-set-wrapper"
  }, /*#__PURE__*/React__default.createElement("span", {
    onClick: () => fastSetTime(1)
  }, "\u8FD1\u4E00\u5929"), /*#__PURE__*/React__default.createElement("span", {
    onClick: () => fastSetTime(3)
  }, "\u8FD1\u4E09\u5929"), /*#__PURE__*/React__default.createElement("span", {
    onClick: () => fastSetTime(7)
  }, "\u8FD1\u4E03\u5929"), /*#__PURE__*/React__default.createElement("span", {
    onClick: () => fastSetTime(30)
  }, "\u8FD1\u4E00\u6708")), /*#__PURE__*/React__default.createElement(DatePicker.RangePicker, {
    showTime: showTime,
    format: format,
    value: _value,
    dropdownClassName: `lm-range-picke-drop ${dropdownClassName}`,
    onChange: onPickChange,
    getPopupContainer: () => {
      return getContainer && getContainer() || document.body;
    },
    ranges: rangesarr
  }));
}

export { RangePicker as default };
//# sourceMappingURL=index.js.map
