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); }
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); }
import React, { useEffect } from 'react';
import { Form, Select, Radio } from 'antd';
import { locales } from '@pisell/utils';
var PermissionField = function PermissionField(props) {
  var _props$value2;
  useEffect(function () {
    var _props$value;
    if (typeof ((_props$value = props.value) === null || _props$value === void 0 ? void 0 : _props$value.member_data_view_range) === 'undefined') {
      var _props$onChange;
      (_props$onChange = props.onChange) === null || _props$onChange === void 0 || _props$onChange.call(props, _objectSpread(_objectSpread({}, props.value || {}), {}, {
        member_data_view_range: ['this_week']
      }));
    }
  }, []);
  var options = [{
    label: locales.getText('pisell2.attendance.group-settings.basic-info.permission.this-week.recommended'),
    value: 'this_week'
  }, {
    label: locales.getText('pisell2.attendance.group-settings.basic-info.permission.last-week'),
    value: 'last_week'
  }, {
    label: locales.getText('pisell2.attendance.group-settings.basic-info.permission.this-month'),
    value: 'this_month'
  }];
  var value = (_props$value2 = props.value) === null || _props$value2 === void 0 ? void 0 : _props$value2.member_data_view_range;
  var isLimited = Array.isArray(value) && value.length > 0;
  return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(Radio.Group, {
    value: isLimited ? 'limited' : 'unlimited',
    onChange: function onChange(e) {
      var nextMode = e.target.value;
      if (nextMode === 'limited') {
        var _props$onChange2;
        var next = Array.isArray(value) && value.length > 0 ? value : ['this_week'];
        (_props$onChange2 = props.onChange) === null || _props$onChange2 === void 0 || _props$onChange2.call(props, _objectSpread(_objectSpread({}, props.value || {}), {}, {
          member_data_view_range: next
        }));
      } else {
        var _props$onChange3;
        (_props$onChange3 = props.onChange) === null || _props$onChange3 === void 0 || _props$onChange3.call(props, _objectSpread(_objectSpread({}, props.value || {}), {}, {
          member_data_view_range: []
        }));
      }
    },
    style: {
      marginBottom: 8
    }
  }, /*#__PURE__*/React.createElement(Radio, {
    value: "limited"
  }, locales.getText('pisell2.attendance.group-settings.basic-info.permission.limited')), /*#__PURE__*/React.createElement(Radio, {
    value: "unlimited"
  }, locales.getText('pisell2.attendance.group-settings.basic-info.permission.unlimited'))), isLimited && /*#__PURE__*/React.createElement(Select, {
    mode: "multiple",
    allowClear: true,
    value: value,
    options: options,
    onChange: function onChange(next) {
      var _props$onChange4;
      (_props$onChange4 = props.onChange) === null || _props$onChange4 === void 0 || _props$onChange4.call(props, _objectSpread(_objectSpread({}, props.value || {}), {}, {
        member_data_view_range: next.length > 0 ? next : []
      }));
    }
  }));
};
var PermissonTab = function PermissonTab(props) {
  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.data-permission.employee-data-view-range'),
    name: "permission"
  }, /*#__PURE__*/React.createElement(PermissionField, null)));
};
export default PermissonTab;