const require_runtime = require("../../../../_virtual/_rolldown/runtime.js");
const require_utils = require("../../utils.js");
const require_context = require("../../context.js");
const require_hooks = require("../../hooks.js");
const require_index = require("./components/InformationOptionsModal/index.js");
let react = require("react");
react = require_runtime.__toESM(react);
let antd = require("antd");
let _pisell_utils = require("@pisell/utils");
let _pisell_materials = require("@pisell/materials");
require("./index.less");
//#region src/components/appointmentBooking/components/Guest/index.tsx
const Guest = (0, react.forwardRef)((props, ref) => {
	const [openOption, setOpenOption] = (0, react.useState)(false);
	const [holderItem, setHolderItem] = (0, react.useState)(null);
	const { carts, appointmentBooking } = require_context.useAppointmentBookingContext();
	const { accountLists } = require_hooks.useAppointmentBookingAccount();
	const { nextStep } = require_hooks.useAppointmentBookingStep();
	const { isMobile } = require_hooks.useConfig();
	(0, react.useImperativeHandle)(ref, () => ({ next: () => {
		nextStep();
	} }));
	const lists = (0, react.useMemo)(() => {
		return require_utils.formatGuest(accountLists, carts);
	}, [accountLists, carts]);
	/**
	* @title: 选项
	* @description:
	* @return {*}
	* @Author: WangHan
	* @Date: 2025-01-19 10:44
	*/
	const options = [{
		key: "edit",
		label: /* @__PURE__ */ react.default.createElement("span", { className: "dropdown-menu-item" }, _pisell_utils.locales.getText("pisell2.appointment.edit.service"))
	}, {
		key: "remove",
		label: /* @__PURE__ */ react.default.createElement("span", { className: "dropdown-menu-item dropdown-menu-remove-item" }, _pisell_utils.locales.getText("pisell2.event.remove"))
	}];
	/**
	* @title: 点击item触发
	* @description:
	* @param {string} key
	* @return {*}
	* @Author: WangHan
	* @Date: 2025-01-18 16:14
	*/
	const handleClick = ({ key }, item) => {
		console.log(key, item, "wh978967");
		if (key === "edit") {
			appointmentBooking.setActiveAccount(item.id);
			appointmentBooking.back();
			return;
		}
		appointmentBooking.removeAccount(item.id);
	};
	/**
	* @title: 渲染options
	* @description:
	* @param {any} item
	* @return {*}
	* @Author: WangHan
	* @Date: 2025-01-19 11:44
	*/
	const renderOptionButton = (item) => {
		console.log(item, options, "wh978776");
		let _options = [...options];
		if (!item.isGuest) _options = _options.filter((option) => option.key !== "remove");
		if (isMobile) return /* @__PURE__ */ react.default.createElement(_pisell_materials.Button, {
			size: "large",
			onClick: () => {
				setHolderItem(item);
				setOpenOption(true);
			}
		}, _pisell_utils.locales.getText("pisell2.event.option"));
		return /* @__PURE__ */ react.default.createElement(antd.Dropdown, {
			menu: {
				items: _options,
				onClick: (e) => {
					setHolderItem(item);
					handleClick(e, item);
				}
			},
			placement: "bottomRight",
			overlayClassName: "appointment-guest-custom-dropdown-menu"
		}, /* @__PURE__ */ react.default.createElement(_pisell_materials.Button, null, _pisell_utils.locales.getText("pisell2.event.option")));
	};
	const handleAddGuest = () => {
		if (accountLists.length >= 6) return (0, _pisell_materials.PisellToast)({ content: _pisell_utils.locales.getText("pisell2.appointment.max.guest") });
		const guest = {
			id: (0, _pisell_utils.getUniqueId)(),
			username: `Guest${accountLists.length + 1}`,
			isGuest: true
		};
		appointmentBooking.addAccounts([guest]);
		appointmentBooking.setActiveAccount(guest.id);
		appointmentBooking.back();
	};
	return /* @__PURE__ */ react.default.createElement(react.default.Fragment, null, /* @__PURE__ */ react.default.createElement("div", { className: "appointment-guest-wrap" }, lists === null || lists === void 0 ? void 0 : lists.map((item) => {
		var _item$children;
		return /* @__PURE__ */ react.default.createElement(_pisell_materials.PisellCard, {
			key: item.id,
			padding: 20,
			className: "information-card",
			isClickable: false
		}, /* @__PURE__ */ react.default.createElement("div", { className: "information-header" }, /* @__PURE__ */ react.default.createElement("div", { className: "information-left" }, /* @__PURE__ */ react.default.createElement(_pisell_materials.PisellAvatar, {
			src: item.avatar,
			size: "md"
		}), /* @__PURE__ */ react.default.createElement("div", { className: "information-title" }, /* @__PURE__ */ react.default.createElement("span", null, item.name), /* @__PURE__ */ react.default.createElement("span", { className: "subtitle" }, `${_pisell_utils.locales.getText("pisell2.appointment.service.title")((_item$children = item.children) === null || _item$children === void 0 ? void 0 : _item$children.length)}`))), renderOptionButton(item)));
	}), /* @__PURE__ */ react.default.createElement(_pisell_materials.Button, {
		size: "large",
		style: { width: "max-content" },
		onClick: handleAddGuest,
		className: "appointment-guest-add-button"
	}, /* @__PURE__ */ react.default.createElement(_pisell_materials.Iconfont, {
		type: "pisell2-plus",
		style: { fontSize: "20px" }
	}), _pisell_utils.locales.getText("pisell2.appointment.add.guest"))), openOption ? /* @__PURE__ */ react.default.createElement(require_index.default, {
		options,
		open: openOption,
		holderItem,
		onCancel: () => setOpenOption(false),
		onClick: (e) => {
			handleClick(e, holderItem);
			setOpenOption(false);
		}
	}) : null);
});
//#endregion
exports.default = Guest;
