function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _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(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
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(arr) { if (Array.isArray(arr)) return arr; }
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); }
import React, { useMemo } from 'react';
import { Form, Select } from 'antd';
import { useRequest } from 'ahooks';
import { Icon, BaseTranslation } from '@pisell/materials';
import { locales } from '@pisell/utils';
import useEngineContext from "../../../hooks/useEngineContext";
import { MembersField } from "./components";
import { getTimezoneList } from "./serve";
var BasicInfoTab = function BasicInfoTab(props) {
  var _engineContext$appHel;
  var engineContext = useEngineContext();
  var _ref = (engineContext === null || engineContext === void 0 || (_engineContext$appHel = engineContext.appHelper) === null || _engineContext$appHel === void 0 ? void 0 : _engineContext$appHel.utils) || {},
    translation = _ref.translation;
  var _useRequest = useRequest(getTimezoneList, {
      defaultParams: [{
        pageSize: 499
      }]
    }),
    data = _useRequest.data;
  var timeZoneOptions = useMemo(function () {
    var _data$data;
    return (data === null || data === void 0 || (_data$data = data.data) === null || _data$data === void 0 ? void 0 : _data$data.map(function (item) {
      return {
        label: translation(item.name),
        value: item.code
      };
    })) || [];
  }, [data]);
  return /*#__PURE__*/React.createElement("div", {
    className: "saas-attendance-group-settings__panel",
    id: props.id
  }, /*#__PURE__*/React.createElement(Form.Item, {
    label: locales.getText('pisell2.attendance.group-settings.basic-info.label.name'),
    name: "name",
    rules: [{
      required: true
    }, {
      validator: function validator(_, value) {
        var hasVal = false;
        if (value && _typeof(value) === 'object') {
          Object.entries(value).forEach(function (_ref2) {
            var _ref3 = _slicedToArray(_ref2, 2),
              key = _ref3[0],
              val = _ref3[1];
            if (val) {
              hasVal = true;
            }
          });
        }
        if (!hasVal) {
          return Promise.reject(locales.getText('pisell2.attendance.group-settings.basic-info.name-required'));
        }
        return Promise.resolve();
      }
    }],
    extra: locales.getText('pisell2.attendance.group-settings.basic-info.name-max-length')(50)
  }, /*#__PURE__*/React.createElement(BaseTranslation, {
    maxLength: 50,
    placeholder: locales.getText('pisell2.attendance.group-settings.basic-info.name-tip')
  })), /*#__PURE__*/React.createElement(Form.Item, {
    label: locales.getText('pisell2.attendance.group-settings.basic-info.label.time-zone'),
    name: "timezone",
    rules: [{
      required: true
    }],
    required: true,
    extra: /*#__PURE__*/React.createElement("div", {
      style: {
        color: '#ea580c'
      }
    }, /*#__PURE__*/React.createElement(Icon, {
      type: "pisell2-alert-triangle",
      size: 14,
      style: {
        marginRight: 4
      }
    }), locales.getText('pisell2.attendance.group-settings.basic-info.time-zone-tip'))
  }, /*#__PURE__*/React.createElement(Select, {
    disabled: true,
    options: timeZoneOptions
  })), /*#__PURE__*/React.createElement(Form.Item, {
    label: locales.getText('pisell2.attendance.group-settings.basic-info.label.members'),
    name: "member_ids",
    rules: [{
      required: true
    }]
  }, /*#__PURE__*/React.createElement(MembersField, null)));
};
export default BasicInfoTab;