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/shoppingCart/components/SelectHolderModal/index.tsx
var SelectHolderModal_exports = {};
__export(SelectHolderModal_exports, {
  default: () => SelectHolderModal_default
});
module.exports = __toCommonJS(SelectHolderModal_exports);
var import_react = __toESM(require("react"));
var import_materials = require("@pisell/materials");
var import_utils = require("@pisell/utils");
var import_utils2 = require("../../utils");
var import_antd = require("antd");
var import_index = require("./index.less");
var SelectPetModal = ({ onChange }, ref) => {
  const [open, setOpen] = (0, import_react.useState)(false);
  const [params, setParams] = (0, import_react.useState)(null);
  (0, import_react.useImperativeHandle)(ref, () => {
    return {
      open: ({ products, holders }) => {
        var _a;
        const _holders = holders == null ? void 0 : holders.filter((item) => item.key > 0);
        const service = (0, import_utils2.formatService)(products, (_a = _holders == null ? void 0 : _holders[0]) == null ? void 0 : _a.key);
        setParams({ service, holders: _holders });
        setOpen(true);
      }
    };
  });
  const handleChange = (e, index) => {
    const _lists = [...params == null ? void 0 : params.service];
    _lists[index].holder_id = e;
    console.log(e, index, _lists, "wh79876");
    setParams({ ...params, service: _lists });
  };
  const content = (0, import_react.useMemo)(() => {
    var _a;
    const services = (params == null ? void 0 : params.service) || [];
    const options = (_a = params == null ? void 0 : params.holders) == null ? void 0 : _a.map((item) => {
      return {
        value: item.key,
        label: item.main_field
      };
    });
    return /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-lowcode__booking-select-pet-content" }, services == null ? void 0 : services.map((item, index) => {
      var _a2;
      return /* @__PURE__ */ import_react.default.createElement(
        "div",
        {
          className: "pisell-lowcode__booking-select-pet-item",
          key: item._id
        },
        /* @__PURE__ */ import_react.default.createElement("span", null, " ", item.name),
        /* @__PURE__ */ import_react.default.createElement(
          import_antd.Select,
          {
            defaultValue: (_a2 = options[0]) == null ? void 0 : _a2.value,
            onChange: (e) => handleChange(e, index),
            options,
            popupMatchSelectWidth: false
          }
        )
      );
    }));
  }, [params == null ? void 0 : params.service, params == null ? void 0 : params.pets]);
  const handleCancel = () => {
    setOpen(false);
  };
  const handleOk = () => {
    const { service } = params;
    const holders = service == null ? void 0 : service.map((item) => {
      return {
        _id: item._id,
        holder_id: item.holder_id
      };
    });
    onChange(service, "update_holders", holders);
    handleCancel();
  };
  return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement(
    import_materials.PisellModal,
    {
      platform: "pc",
      open,
      bodyStyle: { padding: 0 },
      title: import_utils.locales.getText(
        "pisell2.text.shopping-cart.select.holder.modal.title"
      ),
      okText: import_utils.locales.getText("pisell2.text.shopping-cart.confirm"),
      cancelText: import_utils.locales.getText("pisell2.text.shopping-cart.cancel"),
      onCancel: handleCancel,
      onOk: handleOk,
      destroyOnClose: true,
      className: "pisell-lowcode__booking-select-pet-modal-wrap"
    },
    content
  ));
};
var SelectHolderModal_default = (0, import_react.forwardRef)(SelectPetModal);
