"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.RefreshBoxComponent = void 0;
var _button = _interopRequireDefault(require("@alifd/next/lib/button"));
var _icon = _interopRequireDefault(require("@alifd/next/lib/icon"));
var _numberPicker = _interopRequireDefault(require("@alifd/next/lib/number-picker"));
var _select = _interopRequireDefault(require("@alifd/next/lib/select"));
var _react = _interopRequireWildcard(require("react"));
var _boxSlotComponent = _interopRequireDefault(require("../../_components/boxSlotComponent"));
require("../index.less");
var _behaviorService = require("../../../_utils/behaviorService");
var _utils = require("../../../_utils/utils");
var _locale = require("../../../../src/locale");
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
var RefreshBoxComponent = exports.RefreshBoxComponent = function RefreshBoxComponent(props) {
  var onChange = props.onChange,
    value = props.value;
  var behaviorService = new _behaviorService.BehaviorService();
  var _useState = (0, _react.useState)(value || []),
    refreshList = _useState[0],
    setRefreshList = _useState[1];
  var _useState2 = (0, _react.useState)([]),
    refreshOptions = _useState2[0],
    setRefreshOptions = _useState2[1];
  (0, _react.useEffect)(function () {
    var data = behaviorService.getRefreshList();
    setRefreshOptions(data);
  }, []);
  function changeRefreshList(item, index) {
    refreshList[index] = item;
    setRefreshList([].concat(refreshList));
  }
  function removeRefreshList(index) {
    refreshList.splice(index, 1);
    setRefreshList([].concat(refreshList));
  }
  function addRefreshList() {
    var newObj = {
      id: (0, _utils.uuid)(),
      refreshId: "",
      delayTime: 0
    };
    refreshList.push(newObj);
    setRefreshList([].concat(refreshList));
  }
  (0, _react.useEffect)(function () {
    onChange(refreshList);
  }, [refreshList]);
  return /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement("div", {
    className: "refreshListBox"
  }, refreshList.map(function (item, index) {
    return /*#__PURE__*/_react["default"].createElement("div", {
      key: item.id,
      className: "refreshItem"
    }, /*#__PURE__*/_react["default"].createElement("div", {
      style: {
        flex: 1
      }
    }, /*#__PURE__*/_react["default"].createElement(_boxSlotComponent["default"], {
      title: (0, _locale.t)("setter.refreshUrl")
    }, /*#__PURE__*/_react["default"].createElement(_select["default"], {
      className: "itemOne_select",
      style: {
        width: 100 + "%",
        minWidth: 0
      },
      placeholder: (0, _locale.t)("setter.selectPlaceHolder"),
      notFoundContent: (0, _locale.t)('setter.notFoundContent'),
      dataSource: refreshOptions,
      value: item.refreshId,
      onChange: function onChange(v) {
        item.refreshId = v;
        changeRefreshList(item, index);
      }
    })), /*#__PURE__*/_react["default"].createElement(_boxSlotComponent["default"], {
      title: (0, _locale.t)("setter.delayRefresh")
    }, /*#__PURE__*/_react["default"].createElement("div", {
      className: "refreshDelayBox"
    }, /*#__PURE__*/_react["default"].createElement(_numberPicker["default"], {
      style: {
        width: 100 + "%"
      },
      min: 0,
      step: 1,
      size: "small",
      hasTrigger: false,
      innerAfter: /*#__PURE__*/_react["default"].createElement("span", {
        style: {
          marginRight: "10px",
          fontSize: "18px"
        }
      }, "ms"),
      placeholder: (0, _locale.t)("setter.selectPlaceHolder"),
      value: item.delayTime,
      onChange: function onChange(v) {
        item.delayTime = v;
        changeRefreshList(item, index);
      }
    })))), /*#__PURE__*/_react["default"].createElement("div", {
      className: "refreshDBtn"
    }, /*#__PURE__*/_react["default"].createElement(_icon["default"], {
      style: {
        cursor: "pointer"
      },
      type: "ashbin",
      onClick: function onClick() {
        removeRefreshList(index);
      }
    })));
  })), /*#__PURE__*/_react["default"].createElement("div", {
    className: "sub_btn"
  }, /*#__PURE__*/_react["default"].createElement(_button["default"], {
    text: true,
    type: "primary",
    onClick: function onClick() {
      addRefreshList();
    }
  }, /*#__PURE__*/_react["default"].createElement("span", null, (0, _locale.t)("setter.addData")))));
};