import { _objectSpread2 } from "../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import { formatPhone, maskPhone } from "../utils/phoneFormatter.js";
import React from "react";
import { Button, Space, Typography } from "antd";
import { PhoneOutlined } from "@ant-design/icons";
//#region src/components/pisellPhone/components/ReadOnlyView.tsx
/**
* PisellPhone 只读态视图组件
* 
* 负责渲染只读态的电话号码展示和拨号功能
* 
* 功能：
* - 格式化或脱敏显示
* - 显示国旗图标（可选）
* - 移动端可点击拨号（tel: 协议）
* - 拨号图标（可选）
* 
* @param props 组件 Props
*/
const ReadOnlyView = (props) => {
	var _props$fontSize, _props$fontWeight;
	const isMobile = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent);
	const countryCode = props.countryCode || "+86";
	let displayValue;
	if (props.enableMasking) if (props.maskPattern === "custom" && props.customMask) displayValue = props.customMask(props.value || "");
	else displayValue = maskPhone(props.value || "", props.maskPattern);
	else displayValue = formatPhone(props.value || "", countryCode);
	const handleDial = () => {
		if (props.enableDial !== false && isMobile) {
			var _props$onDial;
			const fullNumber = countryCode + (props.value || "").replace(/\D/g, "");
			(_props$onDial = props.onDial) === null || _props$onDial === void 0 || _props$onDial.call(props, fullNumber);
			window.location.href = `tel:${fullNumber}`;
		}
	};
	const canDial = props.enableDial !== false && isMobile;
	const textColor = canDial ? "#7F56DA" : props.color || "#101828";
	const textFontSize = (_props$fontSize = props.fontSize) !== null && _props$fontSize !== void 0 ? _props$fontSize : 16;
	const textFontWeight = (_props$fontWeight = props.fontWeight) !== null && _props$fontWeight !== void 0 ? _props$fontWeight : 500;
	return /* @__PURE__ */ React.createElement("div", { className: `pisell-phone-read ${props.className || ""}` }, /* @__PURE__ */ React.createElement(Space, { size: "small" }, props.showFlag !== false && /* @__PURE__ */ React.createElement("span", {
		className: "pisell-phone-country-code",
		style: {
			fontSize: textFontSize,
			fontWeight: textFontWeight,
			color: textColor
		}
	}, countryCode), /* @__PURE__ */ React.createElement(Typography.Text, {
		className: canDial ? "pisell-phone-clickable" : "",
		onClick: canDial ? handleDial : void 0,
		style: _objectSpread2({
			fontSize: textFontSize,
			fontWeight: textFontWeight,
			color: textColor,
			cursor: canDial ? "pointer" : "default",
			textDecoration: canDial ? "underline" : "none"
		}, props.style)
	}, displayValue), props.showDialIcon && canDial && /* @__PURE__ */ React.createElement(Button, {
		type: "link",
		size: "small",
		icon: /* @__PURE__ */ React.createElement(PhoneOutlined, null),
		onClick: handleDial
	})));
};
//#endregion
export { ReadOnlyView as default };
