var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/plus/saasAttendance/settings/PermissonTab.tsx
var PermissonTab_exports = {};
__export(PermissonTab_exports, {
  default: () => PermissonTab_default
});
module.exports = __toCommonJS(PermissonTab_exports);
var import_react = __toESM(require("react"));
var import_antd = require("antd");
var import_utils = require("@pisell/utils");
var PermissionField = (props) => {
  var _a;
  (0, import_react.useEffect)(() => {
    var _a2, _b;
    if (typeof ((_a2 = props.value) == null ? void 0 : _a2.member_data_view_range) === "undefined") {
      (_b = props.onChange) == null ? void 0 : _b.call(props, {
        ...props.value || {},
        member_data_view_range: ["this_week"]
      });
    }
  }, []);
  const options = [
    {
      label: import_utils.locales.getText(
        "pisell2.attendance.group-settings.basic-info.permission.this-week.recommended"
      ),
      value: "this_week"
    },
    {
      label: import_utils.locales.getText(
        "pisell2.attendance.group-settings.basic-info.permission.last-week"
      ),
      value: "last_week"
    },
    {
      label: import_utils.locales.getText(
        "pisell2.attendance.group-settings.basic-info.permission.this-month"
      ),
      value: "this_month"
    }
  ];
  const value = (_a = props.value) == null ? void 0 : _a.member_data_view_range;
  const isLimited = Array.isArray(value) && value.length > 0;
  return /* @__PURE__ */ import_react.default.createElement("div", null, /* @__PURE__ */ import_react.default.createElement(
    import_antd.Radio.Group,
    {
      value: isLimited ? "limited" : "unlimited",
      onChange: (e) => {
        var _a2, _b;
        const nextMode = e.target.value;
        if (nextMode === "limited") {
          const next = Array.isArray(value) && value.length > 0 ? value : ["this_week"];
          (_a2 = props.onChange) == null ? void 0 : _a2.call(props, {
            ...props.value || {},
            member_data_view_range: next
          });
        } else {
          (_b = props.onChange) == null ? void 0 : _b.call(props, {
            ...props.value || {},
            member_data_view_range: []
          });
        }
      },
      style: { marginBottom: 8 }
    },
    /* @__PURE__ */ import_react.default.createElement(import_antd.Radio, { value: "limited" }, import_utils.locales.getText(
      "pisell2.attendance.group-settings.basic-info.permission.limited"
    )),
    /* @__PURE__ */ import_react.default.createElement(import_antd.Radio, { value: "unlimited" }, import_utils.locales.getText(
      "pisell2.attendance.group-settings.basic-info.permission.unlimited"
    ))
  ), isLimited && /* @__PURE__ */ import_react.default.createElement(
    import_antd.Select,
    {
      mode: "multiple",
      allowClear: true,
      value,
      options,
      onChange: (next) => {
        var _a2;
        (_a2 = props.onChange) == null ? void 0 : _a2.call(props, {
          ...props.value || {},
          member_data_view_range: next.length > 0 ? next : []
        });
      }
    }
  ));
};
var PermissonTab = (props) => {
  return /* @__PURE__ */ import_react.default.createElement("div", { className: "saas-attendance-group-settings__panel", id: props.id }, /* @__PURE__ */ import_react.default.createElement(
    import_antd.Form.Item,
    {
      label: import_utils.locales.getText(
        "pisell2.attendance.group-settings.data-permission.employee-data-view-range"
      ),
      name: "permission"
    },
    /* @__PURE__ */ import_react.default.createElement(PermissionField, null)
  ));
};
var PermissonTab_default = PermissonTab;
