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/appointmentBooking/components/Guest/index.tsx
var Guest_exports = {};
__export(Guest_exports, {
  default: () => Guest_default
});
module.exports = __toCommonJS(Guest_exports);
var import_react = __toESM(require("react"));
var import_antd = require("antd");
var import_materials = require("@pisell/materials");
var import_utils = require("@pisell/utils");
var import_InformationOptionsModal = __toESM(require("./components/InformationOptionsModal"));
var import_context = require("../../context");
var import_hooks = require("../../hooks");
var import_utils2 = require("../../utils");
var import_index = require("./index.less");
var Guest = (0, import_react.forwardRef)((props, ref) => {
  const [openOption, setOpenOption] = (0, import_react.useState)(false);
  const [holderItem, setHolderItem] = (0, import_react.useState)(null);
  const { carts, appointmentBooking } = (0, import_context.useAppointmentBookingContext)();
  const { accountLists } = (0, import_hooks.useAppointmentBookingAccount)();
  const { nextStep } = (0, import_hooks.useAppointmentBookingStep)();
  (0, import_react.useImperativeHandle)(ref, () => ({
    next: () => {
      nextStep();
    }
  }));
  const lists = (0, import_react.useMemo)(() => {
    const _lists = (0, import_utils2.formatGuest)(accountLists, carts);
    return _lists;
  }, [accountLists, carts]);
  const options = [
    {
      key: "edit",
      label: /* @__PURE__ */ import_react.default.createElement("span", { className: "dropdown-menu-item" }, import_utils.locales.getText("pisell2.appointment.edit.service"))
    },
    {
      key: "remove",
      label: /* @__PURE__ */ import_react.default.createElement("span", { className: "dropdown-menu-item dropdown-menu-remove-item" }, import_utils.locales.getText("pisell2.event.remove"))
    }
  ];
  const handleClick = ({ key }, item) => {
    console.log(key, item, "wh978967");
    if (key === "edit") {
      appointmentBooking.setActiveAccount(item.id);
      appointmentBooking.back();
      return;
    }
    appointmentBooking.removeAccount(item.id);
  };
  const renderOptionButton = (item) => {
    console.log(item, options, "wh978776");
    let _options = [...options];
    if (!item.isGuest) {
      _options = _options.filter((option) => option.key !== "remove");
    }
    if ((0, import_utils.isMobile)()) {
      return /* @__PURE__ */ import_react.default.createElement(
        import_materials.Button,
        {
          size: "large",
          onClick: () => {
            setHolderItem(item);
            setOpenOption(true);
          }
        },
        import_utils.locales.getText("pisell2.event.option")
      );
    }
    return /* @__PURE__ */ import_react.default.createElement(
      import_antd.Dropdown,
      {
        menu: {
          items: _options,
          onClick: (e) => {
            setHolderItem(item);
            handleClick(e, item);
          }
        },
        placement: "bottomRight",
        overlayClassName: "appointment-guest-custom-dropdown-menu"
      },
      /* @__PURE__ */ import_react.default.createElement(import_materials.Button, null, import_utils.locales.getText("pisell2.event.option"))
    );
  };
  const handleAddGuest = () => {
    if (accountLists.length >= 6) {
      return (0, import_materials.PisellToast)({
        content: import_utils.locales.getText("pisell2.appointment.max.guest")
      });
    }
    const guest = {
      id: (0, import_utils.getUniqueId)(),
      username: `Guest${accountLists.length + 1}`,
      isGuest: true
    };
    appointmentBooking.addAccounts([guest]);
    appointmentBooking.setActiveAccount(guest.id);
    appointmentBooking.back();
  };
  return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement("div", { className: "appointment-guest-wrap" }, lists == null ? void 0 : lists.map((item) => {
    var _a;
    return /* @__PURE__ */ import_react.default.createElement(
      import_materials.PisellCard,
      {
        key: item.id,
        padding: 20,
        className: "information-card",
        isClickable: false
      },
      /* @__PURE__ */ import_react.default.createElement("div", { className: "information-header" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "information-left" }, /* @__PURE__ */ import_react.default.createElement(import_materials.PisellAvatar, { src: item.avatar, size: "md" }), /* @__PURE__ */ import_react.default.createElement("div", { className: "information-title" }, /* @__PURE__ */ import_react.default.createElement("span", null, item.name), /* @__PURE__ */ import_react.default.createElement("span", { className: "subtitle" }, `${import_utils.locales.getText(
        "pisell2.appointment.service.title"
      )((_a = item.children) == null ? void 0 : _a.length)}`))), renderOptionButton(item))
    );
  }), /* @__PURE__ */ import_react.default.createElement(
    import_materials.Button,
    {
      size: "large",
      style: { width: "max-content" },
      onClick: handleAddGuest,
      className: "appointment-guest-add-button"
    },
    /* @__PURE__ */ import_react.default.createElement(import_materials.Iconfont, { type: "pisell2-plus", style: { fontSize: "20px" } }),
    import_utils.locales.getText("pisell2.appointment.add.guest")
  )), openOption ? /* @__PURE__ */ import_react.default.createElement(
    import_InformationOptionsModal.default,
    {
      options,
      open: openOption,
      holderItem,
      onCancel: () => setOpenOption(false),
      onClick: (e) => {
        handleClick(e, holderItem);
        setOpenOption(false);
      }
    }
  ) : null);
});
var Guest_default = Guest;
