import React from 'react';
import { Typography, Space } from 'antd';
import { LinkOutlined } from '@ant-design/icons';
import { handleUrlClick, formatUrlDisplay } from "../utils";
/**
 * PisellUrl 只读态视图组件
 * 
 * 职责：
 * - 渲染只读态 URL 链接展示
 * - 支持点击新窗口打开链接（安全性保障）
 * - 支持协议/路径隐藏
 * - 支持链接图标
 * 
 * @param props 组件 Props
 */
var ReadOnlyView = function ReadOnlyView(props) {
  var _props$value = props.value,
    value = _props$value === void 0 ? '' : _props$value,
    _props$enableLinkClic = props.enableLinkClick,
    enableLinkClick = _props$enableLinkClic === void 0 ? true : _props$enableLinkClic,
    _props$openInNewWindo = props.openInNewWindow,
    openInNewWindow = _props$openInNewWindo === void 0 ? true : _props$openInNewWindo,
    _props$showLinkIcon = props.showLinkIcon,
    showLinkIcon = _props$showLinkIcon === void 0 ? true : _props$showLinkIcon,
    _props$showProtocol = props.showProtocol,
    showProtocol = _props$showProtocol === void 0 ? false : _props$showProtocol,
    _props$showWww = props.showWww,
    showWww = _props$showWww === void 0 ? false : _props$showWww,
    _props$showPathname = props.showPathname,
    showPathname = _props$showPathname === void 0 ? true : _props$showPathname,
    _props$displayFormat = props.displayFormat,
    displayFormat = _props$displayFormat === void 0 ? 'full' : _props$displayFormat,
    customFormat = props.customFormat,
    _props$defaultProtoco = props.defaultProtocol,
    defaultProtocol = _props$defaultProtoco === void 0 ? 'https://' : _props$defaultProtoco,
    _props$fontSize = props.fontSize,
    fontSize = _props$fontSize === void 0 ? 16 : _props$fontSize,
    _props$fontWeight = props.fontWeight,
    fontWeight = _props$fontWeight === void 0 ? 500 : _props$fontWeight,
    _props$color = props.color,
    color = _props$color === void 0 ? '#101828' : _props$color,
    _props$linkColor = props.linkColor,
    linkColor = _props$linkColor === void 0 ? '#7F56DA' : _props$linkColor,
    onLinkClick = props.onLinkClick;

  // 格式化显示
  var displayUrl = formatUrlDisplay(value, {
    showProtocol: showProtocol,
    showWww: showWww,
    showPathname: showPathname,
    displayFormat: displayFormat,
    customFormat: customFormat
  });

  // 链接跳转处理
  var handleClick = function handleClick() {
    if (enableLinkClick && value) {
      onLinkClick === null || onLinkClick === void 0 || onLinkClick(value);
      handleUrlClick(value, openInNewWindow, defaultProtocol);
    }
  };
  var canClick = enableLinkClick && !!value;
  return /*#__PURE__*/React.createElement("div", {
    className: "pisell-url-read"
  }, /*#__PURE__*/React.createElement(Space, {
    size: "small"
  }, showLinkIcon && /*#__PURE__*/React.createElement(LinkOutlined, {
    style: {
      color: linkColor
    }
  }), canClick ? /*#__PURE__*/React.createElement(Typography.Link, {
    onClick: handleClick,
    style: {
      fontSize: fontSize,
      fontWeight: fontWeight,
      color: linkColor
    },
    "aria-label": props['aria-label'],
    "aria-describedby": props['aria-describedby']
  }, displayUrl) : /*#__PURE__*/React.createElement(Typography.Text, {
    style: {
      fontSize: fontSize,
      fontWeight: fontWeight,
      color: color
    },
    "aria-label": props['aria-label'],
    "aria-describedby": props['aria-describedby']
  }, displayUrl)));
};
export default ReadOnlyView;