function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
import React from 'react';
import { Typography, Button, Space } from 'antd';
import { PhoneOutlined } from '@ant-design/icons';
import { formatPhone, maskPhone } from "../utils";
/**
 * PisellPhone 只读态视图组件
 * 
 * 负责渲染只读态的电话号码展示和拨号功能
 * 
 * 功能：
 * - 格式化或脱敏显示
 * - 显示国旗图标（可选）
 * - 移动端可点击拨号（tel: 协议）
 * - 拨号图标（可选）
 * 
 * @param props 组件 Props
 */
var ReadOnlyView = function ReadOnlyView(props) {
  var _props$fontSize, _props$fontWeight;
  var isMobile = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent);
  var countryCode = props.countryCode || '+86';

  // 格式化或脱敏显示
  var 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);
  }

  // 拨号处理
  var handleDial = function handleDial() {
    if (props.enableDial !== false && isMobile) {
      var _props$onDial;
      var cleaned = (props.value || '').replace(/\D/g, '');
      var fullNumber = countryCode + cleaned;
      (_props$onDial = props.onDial) === null || _props$onDial === void 0 || _props$onDial.call(props, fullNumber);
      window.location.href = "tel:".concat(fullNumber);
    }
  };
  var canDial = props.enableDial !== false && isMobile;
  var textColor = canDial ? '#7F56DA' : props.color || '#101828';
  var textFontSize = (_props$fontSize = props.fontSize) !== null && _props$fontSize !== void 0 ? _props$fontSize : 16;
  var textFontWeight = (_props$fontWeight = props.fontWeight) !== null && _props$fontWeight !== void 0 ? _props$fontWeight : 500;
  return /*#__PURE__*/React.createElement("div", {
    className: "pisell-phone-read ".concat(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 : undefined,
    style: _objectSpread({
      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
  })));
};
export default ReadOnlyView;