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 { Modal, Drawer, Dropdown } from 'antd';
import { CloseOutlined } from '@ant-design/icons';
import { getText } from "../../../locales";

/**
 * LookupResultHost 组件
 * 结果承载层：根据展示类型渲染不同的容器
 */
export var LookupResultHost = function LookupResultHost(props) {
  var displayType = props.displayType,
    visible = props.visible,
    onClose = props.onClose,
    children = props.children,
    _props$modalWidth = props.modalWidth,
    modalWidth = _props$modalWidth === void 0 ? 834 : _props$modalWidth,
    modalStyle = props.modalStyle,
    getContainer = props.getContainer,
    _props$drawerWidth = props.drawerWidth,
    drawerWidth = _props$drawerWidth === void 0 ? 378 : _props$drawerWidth,
    _props$drawerPlacemen = props.drawerPlacement,
    drawerPlacement = _props$drawerPlacemen === void 0 ? 'right' : _props$drawerPlacemen,
    popupWidth = props.popupWidth,
    containerStyle = props.containerStyle,
    containerClassName = props.containerClassName,
    _props$mask = props.mask,
    mask = _props$mask === void 0 ? false : _props$mask,
    _props$maskClosable = props.maskClosable,
    maskClosable = _props$maskClosable === void 0 ? true : _props$maskClosable,
    zIndex = props.zIndex,
    onAfterOpen = props.onAfterOpen;

  /**
   * 渲染 Inline 模式
   */
  var renderInline = function renderInline() {
    if (!visible) return null;

    // 如果没有内容，不显示空容器
    if (!children) return null;
    return /*#__PURE__*/React.createElement("div", {
      className: "pisell-lookup-result-inline ".concat(containerClassName || ''),
      style: containerStyle
    }, children);
  };

  /**
   * 渲染 Popup 模式
   */
  var renderPopup = function renderPopup() {
    // 如果没有内容，不显示
    if (!visible || !children) return null;
    return /*#__PURE__*/React.createElement(Dropdown, {
      open: visible,
      onOpenChange: function onOpenChange(open) {
        if (!open) onClose();
      },
      dropdownRender: function dropdownRender() {
        return /*#__PURE__*/React.createElement("div", {
          className: "pisell-lookup-result-popup ".concat(containerClassName || ''),
          style: _objectSpread({
            width: popupWidth,
            background: '#fff',
            borderRadius: 8,
            boxShadow: '0 2px 8px rgba(0, 0, 0, 0.15)'
          }, containerStyle)
        }, children);
      },
      trigger: ['click']
    }, /*#__PURE__*/React.createElement("div", null));
  };

  /**
   * 渲染 Modal 模式
   */
  var renderModal = function renderModal() {
    // 如果没有遮罩层，点击背后内容不应该关闭 Modal
    var effectiveMaskClosable = mask ? maskClosable : false;

    // 检测是否使用自定义挂载点
    var hasCustomContainer = getContainer !== undefined;

    // 如果没有遮罩层，添加特殊类名以支持点击穿透
    var modalClassName = ['pisell-lookup-modal-container', !mask ? 'pisell-lookup-modal-no-mask' : '', containerClassName || ''].filter(Boolean).join(' ');

    // wrapClassName 用于控制 modal-wrap
    // 只要使用了自定义挂载点，就应用特殊样式
    var wrapClassName = hasCustomContainer ? 'pisell-lookup-modal-custom-container' : '';
    return /*#__PURE__*/React.createElement(Modal, {
      open: visible,
      onCancel: onClose,
      footer: null,
      width: modalWidth,
      style: _objectSpread({
        top: 0
      }, modalStyle),
      getContainer: getContainer,
      mask: mask,
      maskClosable: effectiveMaskClosable,
      zIndex: zIndex,
      className: modalClassName,
      wrapClassName: wrapClassName,
      closeIcon: null,
      destroyOnClose: true,
      title: null,
      afterOpenChange: function afterOpenChange(open) {
        if (open && onAfterOpen) {
          onAfterOpen();
        }
      }
    }, /*#__PURE__*/React.createElement("div", {
      className: "pisell-lookup-modal-wrapper",
      style: containerStyle
    }, children));
  };

  /**
   * 渲染 Drawer 模式
   */
  var renderDrawer = function renderDrawer() {
    // 如果没有遮罩层，点击背后内容不应该关闭 Drawer
    var effectiveMaskClosable = mask ? maskClosable : false;

    // 如果没有遮罩层，添加特殊类名以支持点击穿透
    var drawerClassName = "pisell-lookup-drawer-container ".concat(!mask ? 'pisell-lookup-drawer-no-mask' : '', " ").concat(containerClassName || '');
    return /*#__PURE__*/React.createElement(Drawer, {
      open: visible,
      onClose: onClose,
      width: drawerWidth,
      placement: drawerPlacement,
      mask: mask,
      maskClosable: effectiveMaskClosable,
      zIndex: zIndex,
      className: drawerClassName,
      closeIcon: /*#__PURE__*/React.createElement(CloseOutlined, null),
      destroyOnClose: true,
      title: getText('pisell-lookup-confirm-button-text'),
      afterOpenChange: function afterOpenChange(open) {
        if (open && onAfterOpen) {
          onAfterOpen();
        }
      }
    }, /*#__PURE__*/React.createElement("div", {
      className: "pisell-lookup-drawer-content",
      style: containerStyle
    }, children));
  };

  /**
   * 渲染 Detached 模式
   */
  var renderDetached = function renderDetached() {
    if (!visible) return null;

    // 如果没有内容，不显示空容器
    if (!children) return null;
    return /*#__PURE__*/React.createElement("div", {
      className: "pisell-lookup-result-detached ".concat(containerClassName || ''),
      style: containerStyle
    }, children);
  };

  // 根据展示类型渲染
  switch (displayType) {
    case 'inline':
      return renderInline();
    case 'popup':
      return renderPopup();
    case 'modal':
      return renderModal();
    case 'drawer':
      return renderDrawer();
    case 'detached':
      return renderDetached();
    default:
      return renderInline();
  }
};
LookupResultHost.displayName = 'LookupResultHost';