function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _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(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
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(r) { if (Array.isArray(r)) return r; }
import { Radio } from 'antd';
import { timeUnitList, updateFrequencyList } from '../utils';
import React, { useEffect, useState } from 'react';
import './index.less';
import { BizCycleTime } from '@zgfe/business-lib';
var FusionFrequency = function FusionFrequency(props) {
  var _props$value, _props$value2;
  var classPrefix = 'fusion-frequency';
  var _useState = useState(((_props$value = props.value) === null || _props$value === void 0 ? void 0 : _props$value.type) || 1),
    _useState2 = _slicedToArray(_useState, 2),
    frequencyType = _useState2[0],
    setFrequencyType = _useState2[1];
  var _useState3 = useState((_props$value2 = props.value) === null || _props$value2 === void 0 ? void 0 : _props$value2.rule),
    _useState4 = _slicedToArray(_useState3, 2),
    frequencyTime = _useState4[0],
    setFrequencyTime = _useState4[1];
  useEffect(function () {
    props.onChange && props.onChange({
      type: frequencyType,
      rule: frequencyTime
    });
  }, [frequencyType, frequencyTime]);
  var onChange = function onChange(_ref) {
    var value = _ref.target.value;
    setFrequencyType(value);
  };
  var onChangeTime = function onChangeTime(data) {
    setFrequencyTime(data);
  };
  return /*#__PURE__*/React.createElement("div", {
    className: classPrefix
  }, /*#__PURE__*/React.createElement(Radio.Group, {
    value: frequencyType,
    onChange: onChange
  }, updateFrequencyList.map(function (item) {
    return /*#__PURE__*/React.createElement(Radio, {
      value: item.value,
      key: item.value
    }, item.label);
  })), frequencyType === 2 && (/*#__PURE__*/React.createElement("div", {
    className: "".concat(classPrefix, "-select")
  }, /*#__PURE__*/React.createElement(BizCycleTime, {
    value: frequencyTime,
    size: "middle",
    multiple: true,
    showHour: true,
    format: "HH",
    minTime: "Now",
    options: timeUnitList,
    onChange: onChangeTime
  }))));
};
export default FusionFrequency;