import ErrorTip from "../ErrorTip/index.js";
import { mock } from "../../mock.js";
import React, { useEffect, useState } from "react";
import { isMobile, locales } from "@pisell/utils";
import { PisellAvatar, PisellCard, PisellCustomCheckboxGroup, PisellModal } from "@pisell/materials";
import "./index.less";
//#region src/components/eventBooking/components/selectHolder/index.tsx
const PisellSelectHolder = ({ open = false, onCancel, onOk, onClick, onAdd, options = mock.holder || [], value, title, okText, showCancel, disabled, errorTipText }) => {
	const [errorTip, setErrorTip] = useState();
	useEffect(() => {
		if (open && !disabled) setErrorTip("");
	}, [open, disabled]);
	/**
	* @title: 渲染卡片
	* @description:
	* @param {any} item
	* @return {*}
	* @Author: WangHan
	* @Date: 2025-01-13 12:19
	*/
	const renderCard = (item) => {
		return /* @__PURE__ */ React.createElement(PisellCard, {
			key: item.id,
			padding: 20,
			selected: value == item.id
		}, /* @__PURE__ */ React.createElement("div", { className: "select-holder-card" }, /* @__PURE__ */ React.createElement(PisellAvatar, {
			src: item.avatar,
			size: "xxl"
		}), /* @__PURE__ */ React.createElement("span", { className: "select-holder-name" }, item.name)));
	};
	/**
	* @title: 渲染添加项
	* @description:
	* @return {*}
	* @Author: WangHan
	* @Date: 2025-01-13 12:04
	*/
	const renderAddItem = () => {
		return /* @__PURE__ */ React.createElement(PisellCard, { padding: 20 }, /* @__PURE__ */ React.createElement("div", { className: `select-holder-card select-holder-add-card` }, /* @__PURE__ */ React.createElement(PisellAvatar, {
			size: "xxl",
			className: "select-holder-card-avatar"
		}), /* @__PURE__ */ React.createElement("span", { className: "select-holder-name" }, locales.getText("pisell2.event.create"))));
	};
	return /* @__PURE__ */ React.createElement(PisellModal, {
		open,
		title: isMobile() ? "" : title,
		platform: isMobile() ? "h5" : "pc",
		okText,
		cancelVisible: false,
		closable: showCancel,
		onCancel,
		onOk: (e) => {
			if (disabled) return setErrorTip(errorTipText);
			onOk && onOk(e);
		},
		bodyStyle: { padding: isMobile() ? "0 16px 16px" : 20 },
		mobileModalHeight: "auto",
		destroyOnClose: true,
		className: `select-holder-modal ${isMobile() ? "select-holder-modal-mobile" : ""}`,
		headerDivider: false
	}, isMobile() ? /* @__PURE__ */ React.createElement("div", { className: "select-holder-modal-title" }, title) : null, errorTip ? /* @__PURE__ */ React.createElement(ErrorTip, { text: errorTip }) : null, /* @__PURE__ */ React.createElement(PisellCustomCheckboxGroup, {
		dataSource: options,
		renderItem: renderCard,
		renderAddItem,
		columns: isMobile() ? 2 : 3,
		horizontalGap: 16,
		verticalGap: 16,
		allowAdd: true,
		onClick: (e) => onClick && onClick(e)
	}));
};
//#endregion
export { PisellSelectHolder as default };
