const require_runtime = require("../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_useEngineContext = require("../../hooks/useEngineContext.js");
const require_index = require("./components/Avatar/index.js");
const require_index$1 = require("./components/SwipeAction/index.js");
const require_index$2 = require("../contactInfoModal/index.js");
const require_locales = require("./locales.js");
let react = require("react");
react = require_runtime.__toESM(react);
let _pisell_utils = require("@pisell/utils");
let _pisell_materials = require("@pisell/materials");
require("./index.less");
//#region src/plus/contactInfo/index.tsx
const PREFIX = "pisell-plus-contact-info";
const ContactInfo = (props) => {
	var _context$appHelper$ut, _props$style2;
	console.log("props>>>>>>>>>", props);
	const { dataSource, defaultName, placeholder, direction = "horizontal", isShowDelete, isShowAvatar, isShowPhone, isShowEmail, horizontalGap, verticalGap, onSave, onDelete, onCancel } = props;
	const context = require_useEngineContext.default();
	_pisell_utils.locales.init(require_locales.default, ((_context$appHelper$ut = context.appHelper.utils) === null || _context$appHelper$ut === void 0 || (_context$appHelper$ut = _context$appHelper$ut.storage) === null || _context$appHelper$ut === void 0 ? void 0 : _context$appHelper$ut.get("umi_locale")) || "en");
	const [modalVisible, setModalVisible] = (0, react.useState)(false);
	const isHorizontal = (0, react.useMemo)(() => {
		return direction === "horizontal";
	}, [direction]);
	const displayName = (0, react.useMemo)(() => {
		const { first_name, last_name } = dataSource || {};
		if (!first_name && !last_name) return defaultName || "";
		return `${first_name || ""} ${last_name || ""}`;
	}, [dataSource, defaultName]);
	const displayPhone = (0, react.useMemo)(() => {
		const { country_calling_code, phone } = (dataSource === null || dataSource === void 0 ? void 0 : dataSource.phone) || {};
		if (!country_calling_code || !phone) return "";
		return `${((country_calling_code === null || country_calling_code === void 0 ? void 0 : country_calling_code.startsWith("+")) ? country_calling_code : `+${country_calling_code}`) || ""} ${phone || ""}`;
	}, [dataSource === null || dataSource === void 0 ? void 0 : dataSource.phone]);
	const isEmpty = (0, react.useMemo)(() => {
		var _dataSource$phone;
		return !(dataSource === null || dataSource === void 0 ? void 0 : dataSource.first_name) && !(dataSource === null || dataSource === void 0 ? void 0 : dataSource.last_name) && !(dataSource === null || dataSource === void 0 || (_dataSource$phone = dataSource.phone) === null || _dataSource$phone === void 0 ? void 0 : _dataSource$phone.phone) && !(dataSource === null || dataSource === void 0 ? void 0 : dataSource.email);
	}, [dataSource]);
	const handleClick = () => {
		console.log("handleClick");
		setModalVisible(true);
	};
	const _rightActions = (0, react.useMemo)(() => {
		return [{
			key: "delete",
			text: /* @__PURE__ */ react.default.createElement("div", { style: {
				display: "flex",
				justifyContent: "center",
				alignItems: "center",
				color: "white",
				cursor: "pointer",
				padding: "10px 0px",
				borderRadius: "8px"
			} }, /* @__PURE__ */ react.default.createElement(_pisell_materials.Iconfont, {
				type: "pisell2-trash-01",
				style: {
					fontSize: 20,
					marginRight: 4
				}
			}), /* @__PURE__ */ react.default.createElement("span", { style: {
				fontSize: 12,
				fontWeight: 500
			} }, _pisell_utils.locales.getText("pisell2.text.contact-info.actions.delete"))),
			color: "danger",
			onClick: (e) => {
				e.preventDefault();
				e.stopPropagation();
				onDelete === null || onDelete === void 0 || onDelete();
			}
		}];
	}, [dataSource, onDelete]);
	const renderContent = () => {
		var _props$style;
		return /* @__PURE__ */ react.default.createElement("div", {
			className: `${PREFIX}__${direction}`,
			style: {
				gap: verticalGap,
				padding: (props === null || props === void 0 || (_props$style = props.style) === null || _props$style === void 0 ? void 0 : _props$style.padding) || "8px"
			}
		}, isHorizontal ? /* @__PURE__ */ react.default.createElement(react.default.Fragment, null, /* @__PURE__ */ react.default.createElement("div", {
			className: `${PREFIX}__horizontal-left`,
			style: { gap: horizontalGap }
		}, isShowAvatar && /* @__PURE__ */ react.default.createElement(require_index.default, {
			config: props.avatar,
			name: displayName,
			cover: ""
		}), /* @__PURE__ */ react.default.createElement("div", {
			className: `${PREFIX}__horizontal-left-content`,
			style: { gap: verticalGap }
		}, isEmpty ? /* @__PURE__ */ react.default.createElement("div", { className: `${PREFIX}__empty-description` }, placeholder || _pisell_utils.locales.getText("pisell2.text.contact-info.placeholder")) : /* @__PURE__ */ react.default.createElement(react.default.Fragment, null, /* @__PURE__ */ react.default.createElement("div", { className: `${PREFIX}__name-horizontal-container` }, /* @__PURE__ */ react.default.createElement("span", {
			className: `${PREFIX}__name-horizontal`,
			style: props.nameStyle
		}, displayName), isShowPhone && displayPhone && /* @__PURE__ */ react.default.createElement("span", {
			className: `pisell-plus-contact-info__phone-horizontal`,
			style: props.textStyle
		}, "(", displayPhone, ")")), isShowEmail && (dataSource === null || dataSource === void 0 ? void 0 : dataSource.email) && /* @__PURE__ */ react.default.createElement("div", {
			className: `pisell-plus-contact-info__text`,
			style: props.textStyle
		}, dataSource === null || dataSource === void 0 ? void 0 : dataSource.email)))), /* @__PURE__ */ react.default.createElement("div", { className: `${PREFIX}__horizontal-right` }, /* @__PURE__ */ react.default.createElement(_pisell_materials.Iconfont, {
			type: isEmpty ? "pisell2-plus-circle" : "pisell2-edit-05",
			className: `${PREFIX}__horizontal-right-icon`
		}))) : /* @__PURE__ */ react.default.createElement(react.default.Fragment, null, isShowAvatar && /* @__PURE__ */ react.default.createElement(require_index.default, {
			config: props.avatar,
			name: "hhhhh",
			cover: ""
		}), isEmpty ? /* @__PURE__ */ react.default.createElement("div", { className: `${PREFIX}__empty-description` }, placeholder || _pisell_utils.locales.getText("pisell2.text.contact-info.placeholder")) : /* @__PURE__ */ react.default.createElement(react.default.Fragment, null, /* @__PURE__ */ react.default.createElement("div", {
			className: `${PREFIX}__name`,
			style: props.nameStyle
		}, displayName), isShowPhone && displayPhone && /* @__PURE__ */ react.default.createElement("div", {
			className: `pisell-plus-contact-info__text`,
			style: props.textStyle
		}, displayPhone), isShowEmail && (dataSource === null || dataSource === void 0 ? void 0 : dataSource.email) && /* @__PURE__ */ react.default.createElement("div", {
			className: `pisell-plus-contact-info__text`,
			style: props.textStyle
		}, dataSource === null || dataSource === void 0 ? void 0 : dataSource.email))));
	};
	return /* @__PURE__ */ react.default.createElement(react.default.Fragment, null, /* @__PURE__ */ react.default.createElement("div", {
		className: `${PREFIX}`,
		style: require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, props.style || {}), {}, { padding: 0 }),
		onClick: handleClick
	}, isShowDelete && !isEmpty ? /* @__PURE__ */ react.default.createElement(require_index$1.SwipeAction, {
		closeOnAction: false,
		rightActions: _rightActions,
		style: { borderRadius: (props === null || props === void 0 || (_props$style2 = props.style) === null || _props$style2 === void 0 ? void 0 : _props$style2.borderRadius) || 0 }
	}, renderContent()) : renderContent()), /* @__PURE__ */ react.default.createElement(require_index$2.default, {
		open: modalVisible,
		dataSource,
		isShowDelete,
		onCancel: () => {
			setModalVisible(false);
			onCancel === null || onCancel === void 0 || onCancel();
		},
		onSave: (value) => {
			setModalVisible(false);
			onSave === null || onSave === void 0 || onSave(value);
		},
		onDelete: () => {
			setModalVisible(false);
			onDelete === null || onDelete === void 0 || onDelete();
		}
	}));
};
//#endregion
exports.PREFIX = PREFIX;
exports.default = ContactInfo;
