const require_runtime = require("../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_PisellEntityCard = require("../pisellEntityCard/PisellEntityCard.js");
const require_ContactFormModal = require("./components/ContactFormModal.js");
const require_locales = require("./locales.js");
let react = require("react");
react = require_runtime.__toESM(react);
let _pisell_utils = require("@pisell/utils");
let _ant_design_icons = require("@ant-design/icons");
require("./PisellContactBrief.less");
//#region src/components/PisellContactBrief/PisellContactBrief.tsx
/** 初始化多语言（合并到全局 locales），确保 getText 能取到本组件文案 */
function ensureLocales() {
	try {
		var _getLocale, _getLocale2;
		const current = (_getLocale = (_getLocale2 = _pisell_utils.locales.getLocale) === null || _getLocale2 === void 0 ? void 0 : _getLocale2.call(_pisell_utils.locales)) !== null && _getLocale !== void 0 ? _getLocale : "en";
		const locale = current === "zh-TW" ? "zh-HK" : current;
		_pisell_utils.locales.init(require_locales.default, locale);
	} catch (_unused) {}
}
/**
* PisellContactBrief 联系人简要卡片
* 基于 PisellEntityCard 展示姓名、电话、邮箱及扩展字段，右侧编辑图标调起编辑弹窗
*/
function PisellContactBrief({ name, phone, email, avatar, extraData = {}, extraFields = [], onSubmit, onDelete, swipeToDelete = false, layout = "horizontal", showAvatar = true, showPhone = true, showEmail = true, primaryLineClamp, secondaryLineClamp, className, style, hoverStyle, activeStyle, disabledStyle, clickable = true, disabled = false, onClick }) {
	const [editModalVisible, setEditModalVisible] = (0, react.useState)(false);
	(0, react.useEffect)(() => {
		ensureLocales();
	}, []);
	const media = (0, react.useMemo)(() => {
		if (!showAvatar) return void 0;
		return {
			type: "avatar",
			src: avatar,
			alt: name,
			size: 32,
			shape: "circle"
		};
	}, [
		showAvatar,
		avatar,
		name
	]);
	const secondaryTexts = (0, react.useMemo)(() => {
		const list = [];
		if (showEmail && email) list.push({ text: email });
		extraFields.forEach((f) => {
			const v = extraData[f.key];
			if (v) list.push({ text: v });
		});
		return list;
	}, [
		showEmail,
		email,
		extraFields,
		extraData
	]);
	const editAction = (0, react.useMemo)(() => ({
		type: "icon",
		icon: /* @__PURE__ */ react.default.createElement(_ant_design_icons.EditOutlined, { className: "pisell-contact-brief-action-edit" }),
		onClick: () => {
			setEditModalVisible(true);
		}
	}), []);
	const initialEditValues = (0, react.useMemo)(() => require_objectSpread2._objectSpread2({
		name,
		phone,
		email
	}, extraData), [
		name,
		phone,
		email,
		extraData
	]);
	const handleEditSubmit = (0, react.useCallback)((values) => {
		onSubmit === null || onSubmit === void 0 || onSubmit(values);
		setEditModalVisible(false);
	}, [onSubmit]);
	return /* @__PURE__ */ react.default.createElement(react.default.Fragment, null, /* @__PURE__ */ react.default.createElement("div", { className: "pisell-contact-brief-wrap" }, /* @__PURE__ */ react.default.createElement(require_PisellEntityCard.PisellEntityCard, {
		className,
		style,
		hoverStyle,
		activeStyle,
		disabledStyle,
		clickable,
		disabled,
		onClick,
		media,
		primaryText: name,
		subtitleText: showPhone && phone ? phone : void 0,
		secondaryTexts,
		showMedia: showAvatar,
		showPrimaryText: true,
		showSubtitle: showPhone,
		showSecondaryText: true,
		showTags: false,
		showActions: true,
		actions: [editAction],
		density: "B2",
		layout,
		width: "content",
		swipeToDelete,
		onDelete,
		primaryLineClamp,
		secondaryLineClamp
	})), /* @__PURE__ */ react.default.createElement(require_ContactFormModal.ContactFormModal, {
		visible: editModalVisible,
		onCancel: () => setEditModalVisible(false),
		onSubmit: handleEditSubmit,
		mode: "edit",
		initialValues: initialEditValues,
		extraFields
	}));
}
/**
* 新建联系人入口按钮
* 展示「Add Contact」+ 占位头像 + plus 图标，点击打开新建弹窗
*/
function PisellContactBriefCreateButton({ extraFields = [], onCreate, onClick: onClickProp, className, style }) {
	const [createModalVisible, setCreateModalVisible] = (0, react.useState)(false);
	(0, react.useEffect)(() => {
		ensureLocales();
	}, []);
	const handleClick = (0, react.useCallback)((e) => {
		if (onClickProp) {
			onClickProp(e);
			return;
		}
		setCreateModalVisible(true);
	}, [onClickProp]);
	const handleCreateSubmit = (0, react.useCallback)((values) => {
		onCreate === null || onCreate === void 0 || onCreate(values);
		setCreateModalVisible(false);
	}, [onCreate]);
	const addContactText = _pisell_utils.locales.getText("pisell.contact.brief.addContact");
	return /* @__PURE__ */ react.default.createElement(react.default.Fragment, null, /* @__PURE__ */ react.default.createElement("div", {
		role: "button",
		tabIndex: 0,
		className: `pisell-contact-brief-create-btn ${className !== null && className !== void 0 ? className : ""}`.trim(),
		style,
		onClick: handleClick,
		onKeyDown: (e) => {
			if (e.key === "Enter" || e.key === " ") {
				e.preventDefault();
				handleClick(e);
			}
		}
	}, /* @__PURE__ */ react.default.createElement("span", { className: "pisell-contact-brief-create-btn-avatar" }, /* @__PURE__ */ react.default.createElement("span", { className: "pisell-contact-brief-create-btn-avatar-inner" })), /* @__PURE__ */ react.default.createElement("span", { className: "pisell-contact-brief-create-btn-text" }, addContactText), /* @__PURE__ */ react.default.createElement(_ant_design_icons.PlusCircleOutlined, { className: "pisell-contact-brief-create-btn-icon" })), /* @__PURE__ */ react.default.createElement(require_ContactFormModal.ContactFormModal, {
		visible: createModalVisible,
		onCancel: () => setCreateModalVisible(false),
		onSubmit: handleCreateSubmit,
		mode: "create",
		extraFields
	}));
}
PisellContactBrief.CreateButton = PisellContactBriefCreateButton;
//#endregion
exports.PisellContactBrief = PisellContactBrief;
