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/components/booking/info2/service/editService/Capacity/index.tsx
var Capacity_exports = {};
__export(Capacity_exports, {
  default: () => Capacity_default
});
module.exports = __toCommonJS(Capacity_exports);
var import_react = __toESM(require("react"));
var import_antd = require("antd");
var import_index = require("./index.less");
var getName = (name, locale) => {
  return name[locale] || name["original"] || name["en"] || "";
};
var getSelectOptions = (min, max) => {
  let arr = [];
  for (let i = min; i <= max; i++) {
    arr.push({ label: `${i}`, value: i });
  }
  return arr;
};
var Capacity = ({ state, cacheItem, value, onChange }, ref) => {
  var _a;
  const data = (_a = cacheItem == null ? void 0 : cacheItem._data) == null ? void 0 : _a.capacitys;
  const _value = (0, import_react.useMemo)(() => {
    return value || [];
  }, [value]);
  const _onChange = (val, index) => {
    let _val = [..._value];
    _val = _val.map((item) => {
      if (item.id === index) {
        return { ...item, value: val };
      }
      return item;
    });
    console.log(_val);
    onChange == null ? void 0 : onChange(_val);
  };
  if ((data == null ? void 0 : data.type) !== "custom") {
    return null;
  }
  return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, data.custom.map((item) => {
    var _a2;
    return /* @__PURE__ */ import_react.default.createElement(import_antd.Col, { span: 24, key: item.id }, /* @__PURE__ */ import_react.default.createElement(import_antd.Form.Item, { label: getName(item.name, state.locale), required: true }, /* @__PURE__ */ import_react.default.createElement(
      import_antd.Select,
      {
        size: "large",
        className: "capacity-select",
        onChange: (e) => {
          _onChange(e, item.id);
        },
        showSearch: !state.isTerminal,
        value: (_a2 = _value.find((d) => d.id === item.id)) == null ? void 0 : _a2.value,
        options: getSelectOptions(item.min, item.max),
        onSearch: (e) => {
          if (!e) {
            return;
          }
          const num = Number(e);
          if (isNaN(num)) {
            return;
          }
          if (num >= item.min && num <= item.max) {
            _onChange(num, item.id);
          }
        }
      }
    )));
  }));
};
var Capacity_default = (0, import_react.forwardRef)(Capacity);
