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/info/pet/ChangePetModal/index.tsx
var ChangePetModal_exports = {};
__export(ChangePetModal_exports, {
  default: () => ChangePetModal_default
});
module.exports = __toCommonJS(ChangePetModal_exports);
var import_react = __toESM(require("react"));
var import_utils = require("@pisell/utils");
var import_materials = require("@pisell/materials");
var import_status = require("../../service2/status");
var import_index = require("./index.less");
var ChangePetModal = (props, ref) => {
  const [open, setOpen] = (0, import_react.useState)(false);
  const [params, setParams] = (0, import_react.useState)({});
  (0, import_react.useImperativeHandle)(ref, () => ({
    open: (e) => {
      setParams(e);
      setOpen(true);
    }
  }));
  const handleProduct = (type) => {
    const { ids, service, dispatch, setGlobalState, state, source } = params;
    let _service = [...service || []];
    if (source === "changeClient") {
      if (type === "ok") {
        _service = _service == null ? void 0 : _service.filter(
          (item) => !import_status.appointmentTypes.includes(item.extension_type)
        );
      } else {
        _service = [];
      }
    } else {
      if (type === "ok") {
        _service = _service == null ? void 0 : _service.map((item) => {
          if (ids == null ? void 0 : ids.includes(item._extend.holder_id)) {
            return {
              ...item,
              _extend: {
                ...item._extend || {},
                holder_id: 0
              }
            };
          }
          return item;
        });
        _service = _service.filter(
          (item) => {
            var _a;
            return !(((_a = item == null ? void 0 : item._extend) == null ? void 0 : _a.holder_id) === 0 && import_status.appointmentTypes.includes(item.extension_type));
          }
        );
      } else {
        _service = _service.filter(
          (item) => !ids.includes(item._extend.holder_id)
        );
      }
    }
    if (dispatch) {
      dispatch({
        type: "setService",
        payload: {
          value: [..._service],
          edit: true
        }
      });
    } else {
      setGlobalState({
        service: {
          ...state.service,
          edit: true,
          value: [..._service]
        }
      });
    }
    setOpen(false);
  };
  return /* @__PURE__ */ import_react.default.createElement(
    import_materials.PisellModal.Information,
    {
      open,
      platform: "pc",
      width: 432,
      title: import_utils.locales.getText("pisell2.text.change.pet.title"),
      describe: /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell2-change-pet-modal-content" }, /* @__PURE__ */ import_react.default.createElement("span", null, import_utils.locales.getText("pisell2.text.change.pet.content")), /* @__PURE__ */ import_react.default.createElement("span", null, import_utils.locales.getText("pisell2.text.change.pet.content1"))),
      cancelText: import_utils.locales.getText("pisell2.text.change.pet.cancel"),
      okText: import_utils.locales.getText("pisell2.text.change.pet.confirm"),
      closable: true,
      onOk: () => handleProduct("ok"),
      onCancel: () => handleProduct("cancel")
    }
  );
};
var ChangePetModal_default = (0, import_react.forwardRef)(ChangePetModal);
