import { useStep } from "../../../../Sales/Step/index.js";
import { useCart } from "../../../../Sales/Cart/index.js";
import { useHolder } from "../../../../Sales/Holder/index.js";
import SelectHolderModal from "../SelectHolderModal.js";
import InformationOptionsModal from "../InformationOptionsModal/index.js";
import RemoveOptionConfirmModal from "../RemoveOptionConfirmModal.js";
import React, { useState } from "react";
import { Dropdown } from "antd";
import { isMobile, locales } from "@pisell/utils";
import { Button as Button$1, Iconfont, PisellAvatar, PisellCard } from "@pisell/materials";
import "./index.less";
//#region src/components/eventBooking/components/Provider/Information/index.tsx
const Information = () => {
	const { onHolderOpen, open } = useHolder();
	const { cartDataHolderList } = useCart();
	const { selectHolder, deleteHolderById } = useHolder();
	const { prevStep } = useStep();
	const [openOption, setOpenOption] = useState(false);
	const [holderItem, setHolderItem] = useState(null);
	const [removeOpen, setRemoveOpen] = useState(false);
	/**
	* @title: 选项
	* @description:
	* @return {*}
	* @Author: WangHan
	* @Date: 2025-01-19 10:44
	*/
	const options = [{
		key: "edit",
		label: /* @__PURE__ */ React.createElement("span", { className: "dropdown-menu-item" }, locales.getText("pisell2.event.edit.event"))
	}, {
		key: "remove",
		label: /* @__PURE__ */ React.createElement("span", { className: "dropdown-menu-item dropdown-menu-remove-item" }, locales.getText("pisell2.event.remove"))
	}];
	/**
	* @title: 点击item触发
	* @description:
	* @param {string} key
	* @return {*}
	* @Author: WangHan
	* @Date: 2025-01-18 16:14
	*/
	const handleClick = ({ key }, item) => {
		if (key === "edit") {
			selectHolder(item || holderItem, "createCartItem");
			prevStep();
			return;
		}
		setRemoveOpen(true);
	};
	/**
	* @title: 渲染options
	* @description:
	* @param {any} item
	* @return {*}
	* @Author: WangHan
	* @Date: 2025-01-19 11:44
	*/
	const renderOptionButton = (item) => {
		if (isMobile()) return /* @__PURE__ */ React.createElement(Button$1, {
			size: "large",
			onClick: () => {
				setHolderItem(item);
				setOpenOption(true);
			}
		}, locales.getText("pisell2.event.option"));
		return /* @__PURE__ */ React.createElement(Dropdown, {
			menu: {
				items: options,
				onClick: (e) => {
					setHolderItem(item);
					handleClick(e, item);
				}
			},
			placement: "bottomRight",
			overlayClassName: "provider-information-custom-dropdown-menu"
		}, /* @__PURE__ */ React.createElement(Button$1, null, locales.getText("pisell2.event.option")));
	};
	return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", {
		className: "provider-information-wrap",
		id: "information"
	}, /* @__PURE__ */ React.createElement("span", { className: "title" }, locales.getText("pisell2.event.confirm.information.tip")), cartDataHolderList === null || cartDataHolderList === void 0 ? void 0 : cartDataHolderList.map((item) => {
		var _item$children;
		return /* @__PURE__ */ React.createElement(PisellCard, {
			key: item.id,
			padding: 20,
			className: "information-card",
			isClickable: false
		}, /* @__PURE__ */ React.createElement("div", { className: "information-header" }, /* @__PURE__ */ React.createElement("div", { className: "information-left" }, /* @__PURE__ */ React.createElement(PisellAvatar, {
			src: item.avatar,
			size: "md"
		}), /* @__PURE__ */ React.createElement("div", { className: "information-title" }, /* @__PURE__ */ React.createElement("span", null, item.name), /* @__PURE__ */ React.createElement("span", { className: "subtitle" }, `${locales.getText("pisell2.event.title")((_item$children = item.children) === null || _item$children === void 0 ? void 0 : _item$children.length)}`))), renderOptionButton(item)), item.children.map((child) => {
			return /* @__PURE__ */ React.createElement("div", { className: "child-wrap" }, child.name);
		}));
	}), /* @__PURE__ */ React.createElement("span", { className: "add-tip" }, locales.getText("pisell2.event.confirm.information.other")), /* @__PURE__ */ React.createElement(Button$1, {
		size: "large",
		style: { width: "max-content" },
		onClick: () => {
			onHolderOpen();
		},
		className: "provider-information-add-button"
	}, /* @__PURE__ */ React.createElement(Iconfont, {
		type: "pisell2-plus",
		style: { fontSize: "20px" }
	}), locales.getText("pisell2.event.add.others"))), /* @__PURE__ */ React.createElement(SelectHolderModal, {
		open,
		type: "create"
	}), /* @__PURE__ */ React.createElement(InformationOptionsModal, {
		options,
		open: openOption,
		holderItem,
		onCancel: () => setOpenOption(false),
		onClick: handleClick
	}), /* @__PURE__ */ React.createElement(RemoveOptionConfirmModal, {
		removeOpen,
		onCancel: () => setRemoveOpen(false),
		onOk: () => {
			deleteHolderById(holderItem.id);
			setRemoveOpen(false);
			setOpenOption(false);
		}
	}));
};
//#endregion
export { Information as default };
