import { jsx } from 'react/jsx-runtime';
import React__default from 'react';
import RcDropdown from 'rc-dropdown';
import { a as $rcPrefixCls, $ as $prefixCls } from './constant-66aa48a1.js';
import { g as getNearestOverflowAncestor, u as usePopupContainer } from './usePopupContainer-87febeb9.js';
import clsx from 'clsx';
import dayjs from 'dayjs';
import { UUID } from '@iam-com/lib';
import { s as styleInject } from './style-inject.es-300983ab.js';

function getPlaceholder(picker, locale, customizePlaceholder) {
  if (customizePlaceholder !== undefined) {
    return customizePlaceholder;
  }
  if (picker === 'year' && locale.lang.yearPlaceholder) {
    return locale.lang.yearPlaceholder;
  }
  if (picker === 'quarter' && locale.lang.quarterPlaceholder) {
    return locale.lang.quarterPlaceholder;
  }
  if (picker === 'month' && locale.lang.monthPlaceholder) {
    return locale.lang.monthPlaceholder;
  }
  if (picker === 'week' && locale.lang.weekPlaceholder) {
    return locale.lang.weekPlaceholder;
  }
  if (picker === 'time' && locale.timePickerLocale.placeholder) {
    return locale.timePickerLocale.placeholder;
  }
  return locale.lang.placeholder;
}
function getRangePlaceholder(picker, locale, customizePlaceholder) {
  if (customizePlaceholder !== undefined) {
    return customizePlaceholder;
  }
  if (picker === 'year' && locale.lang.yearPlaceholder) {
    return locale.lang.rangeYearPlaceholder;
  }
  if (picker === 'month' && locale.lang.monthPlaceholder) {
    return locale.lang.rangeMonthPlaceholder;
  }
  if (picker === 'week' && locale.lang.weekPlaceholder) {
    return locale.lang.rangeWeekPlaceholder;
  }
  if (picker === 'time' && locale.timePickerLocale.placeholder) {
    return locale.timePickerLocale.rangePlaceholder;
  }
  return locale.lang.rangePlaceholder;
}
function toArray(list) {
  if (!list) {
    return [];
  }
  return Array.isArray(list) ? list : [list];
}
function getTimeProps(props) {
  var format = props.format,
    picker = props.picker,
    showHour = props.showHour,
    showMinute = props.showMinute,
    showSecond = props.showSecond,
    use12Hours = props.use12Hours;
  var firstFormat = toArray(format)[0];
  var showTimeObj = Object.assign({}, props);
  if (firstFormat && typeof firstFormat === 'string') {
    if (!firstFormat.includes('s') && showSecond === undefined) {
      showTimeObj.showSecond = false;
    }
    if (!firstFormat.includes('m') && showMinute === undefined) {
      showTimeObj.showMinute = false;
    }
    if (!firstFormat.includes('H') && !firstFormat.includes('h') && showHour === undefined) {
      showTimeObj.showHour = false;
    }
    if ((firstFormat.includes('a') || firstFormat.includes('A')) && use12Hours === undefined) {
      showTimeObj.use12Hours = true;
    }
  }
  if (picker === 'time') {
    return showTimeObj;
  }
  if (typeof firstFormat === 'function') {
    delete showTimeObj.format;
  }
  return {
    showTime: showTimeObj
  };
}
function formatPickerValue(value, format) {
  if (typeof value === 'string') {
    if (value === '') return null;
    if (format) {
      if (dayjs(value, format).isValid()) return dayjs(value, format);
    } else {
      if (dayjs(value).isValid()) return dayjs(value);
    }
    return null;
  }
  return value;
}
function mergedLocale(locale, defaultLocale) {
  var lang = Object.assign(Object.assign({}, defaultLocale === null || defaultLocale === void 0 ? void 0 : defaultLocale.lang), (locale === null || locale === void 0 ? void 0 : locale.lang) || {});
  var timePickerLocale = Object.assign(Object.assign({}, defaultLocale === null || defaultLocale === void 0 ? void 0 : defaultLocale.timePickerLocale), (locale === null || locale === void 0 ? void 0 : locale.timeLang) || {});
  return {
    lang: lang,
    timePickerLocale: timePickerLocale
  };
}
//最近的绝对定位滚动元素
function getNearestAbsoluteAncestor(node, pos) {
  var _a;
  var parentNode = node.parentNode;
  var nodeName = ((_a = parentNode === null || parentNode === void 0 ? void 0 : parentNode.nodeName) === null || _a === void 0 ? void 0 : _a.toLowerCase()) || '';
  if (['html', 'body', '#document'].includes(nodeName)) {
    return null;
  }
  if (parentNode instanceof window.HTMLElement) {
    var _window$getComputedSt = window.getComputedStyle(parentNode),
      position = _window$getComputedSt.position;
    if (new RegExp(pos).test(position)) return parentNode;
  }
  return getNearestAbsoluteAncestor(parentNode, pos);
}
//下拉弹出框关闭时，隔离dom污染
function isolationPopupPollution(open, uniqueCls) {
  var popupDom = document.getElementsByClassName("".concat(uniqueCls))[0];
  if (!popupDom) return;
  var position = open ? 'fixed' : 'absolute';
  var nearestDom = getNearestAbsoluteAncestor(popupDom, position);
  if (!nearestDom) return;
  if (!open) {
    //关闭弹框
    nearestDom.style.position = 'fixed';
    nearestDom.style.left = '-9999px';
    nearestDom.style.top = '-9999px';
  } else {
    //打开弹框
    nearestDom.style.position = 'absolute';
    nearestDom.style.left = '0';
    nearestDom.style.top = '0';
  }
}
//浮层渲染容器
function getPopupContainer(triggerNode, customizeContainer, that) {
  var _a, _b;
  var container;
  if (!customizeContainer) {
    var rootNode = that.wrapRef.current;
    if (rootNode) {
      container = getNearestOverflowAncestor(rootNode);
      var scrollHeight = container.scrollHeight;
      var clientHeight = container.clientHeight;
      if (scrollHeight <= clientHeight) {
        container = document.body;
      }
    } else {
      container = document.body;
    }
    var nodeName = (_a = container.nodeName) === null || _a === void 0 ? void 0 : _a.toLowerCase();
    if (nodeName !== 'body') {
      if (((_b = window.getComputedStyle(container)) === null || _b === void 0 ? void 0 : _b.position) === 'static') {
        container.style.position = 'relative';
      }
    }
    that.popupRecord = container;
  } else {
    container = customizeContainer(triggerNode) || document.body;
  }
  return container;
}

var css_248z = "@charset \"UTF-8\";\n/**\n* @author Hanz\n* @date 2022/5/27 上午9:58\n* @description\n*/\n/**\n* @author Hanz\n* @date 2021/10/20 下午2:08\n* @description color\n*/\n.paraui-v3-dropdown {\n  position: absolute;\n  left: -9999px;\n  top: -9999px;\n  z-index: 1500;\n  display: block;\n  font-family: -apple-system, BlinkMacSystemFont, Helvetica Neue, PingFang SC, Microsoft YaHei, Source Han Sans SC, Noto Sans CJK SC, WenQuanYi Micro Hei, sans-serif;\n  font-size: 14px;\n  font-weight: 400;\n  line-height: 1.5715;\n  background-color: rgb(255, 255, 255);\n  box-shadow: 0px 2px 8px 0px rgba(171, 176, 185, 0.4);\n  border-radius: 4px;\n}\n.paraui-v3-dropdown.component-dropdown-hidden {\n  display: none;\n}\n.paraui-v3-dropdown .component-dropdown-arrow {\n  position: absolute;\n  border-width: 4px;\n  border-color: transparent;\n  box-shadow: 0px 2px 8px 0px rgba(171, 176, 185, 0.4);\n  border-style: solid;\n  transform: rotate(45deg);\n}\n.paraui-v3-dropdown.component-dropdown-show-arrow.component-dropdown-placement-top, .paraui-v3-dropdown.component-dropdown-show-arrow.component-dropdown-placement-topLeft, .paraui-v3-dropdown.component-dropdown-show-arrow.component-dropdown-placement-topRight {\n  padding-bottom: 6px;\n}\n.paraui-v3-dropdown.component-dropdown-show-arrow.component-dropdown-placement-bottom, .paraui-v3-dropdown.component-dropdown-show-arrow.component-dropdown-placement-bottomLeft, .paraui-v3-dropdown.component-dropdown-show-arrow.component-dropdown-placement-bottomRight {\n  padding-top: 6px;\n}\n.paraui-v3-dropdown.component-dropdown-placement-top .component-dropdown-arrow, .paraui-v3-dropdown.component-dropdown-placement-topLeft .component-dropdown-arrow, .paraui-v3-dropdown.component-dropdown-placement-topRight .component-dropdown-arrow {\n  bottom: 4px;\n  border-top-color: rgb(255, 255, 255);\n}\n.paraui-v3-dropdown.component-dropdown-placement-top .component-dropdown-arrow {\n  left: 50%;\n}\n.paraui-v3-dropdown.component-dropdown-placement-topLeft .component-dropdown-arrow {\n  left: 15%;\n}\n.paraui-v3-dropdown.component-dropdown-placement-topRight .component-dropdown-arrow {\n  right: 15%;\n}\n.paraui-v3-dropdown.component-dropdown-placement-bottom .component-dropdown-arrow, .paraui-v3-dropdown.component-dropdown-placement-bottomLeft .component-dropdown-arrow, .paraui-v3-dropdown.component-dropdown-placement-bottomRight .component-dropdown-arrow {\n  top: 4px;\n  border-bottom-color: rgb(255, 255, 255);\n}\n.paraui-v3-dropdown.component-dropdown-placement-bottom .component-dropdown-arrow {\n  left: 50%;\n}\n.paraui-v3-dropdown.component-dropdown-placement-bottomLeft .component-dropdown-arrow {\n  left: 15%;\n}\n.paraui-v3-dropdown.component-dropdown-placement-bottomRight .component-dropdown-arrow {\n  right: 15%;\n}\n\n.component-dropdown-slide-up-enter,\n.component-dropdown-slide-up-appear {\n  animation-duration: 0.3s;\n  animation-fill-mode: both;\n  transform-origin: 0 0;\n  display: block !important;\n  opacity: 0;\n  animation-timing-function: cubic-bezier(0.08, 0.82, 0.17, 1);\n  animation-play-state: paused;\n}\n\n.component-dropdown-slide-up-leave {\n  animation-duration: 0.3s;\n  animation-fill-mode: both;\n  transform-origin: 0 0;\n  display: block !important;\n  opacity: 1;\n  animation-timing-function: cubic-bezier(0.6, 0.04, 0.98, 0.34);\n  animation-play-state: paused;\n}\n\n.component-dropdown-slide-up-enter.component-dropdown-slide-up-enter-active.component-dropdown-placement-bottomLeft,\n.component-dropdown-slide-up-appear.component-dropdown-slide-up-appear-active.component-dropdown-placement-bottomLeft,\n.component-dropdown-slide-up-enter.component-dropdown-slide-up-enter-active.component-dropdown-placement-bottomCenter,\n.component-dropdown-slide-up-appear.component-dropdown-slide-up-appear-active.component-dropdown-placement-bottomCenter,\n.component-dropdown-slide-up-enter.component-dropdown-slide-up-enter-active.component-dropdown-placement-bottomRight,\n.component-dropdown-slide-up-appear.component-dropdown-slide-up-appear-active.component-dropdown-placement-bottomRight {\n  animation-name: componentDropdownSlideUpIn;\n  animation-play-state: running;\n}\n\n.component-dropdown-slide-up-enter.component-dropdown-slide-up-enter-active.component-dropdown-placement-topLeft,\n.component-dropdown-slide-up-appear.component-dropdown-slide-up-appear-active.component-dropdown-placement-topLeft,\n.component-dropdown-slide-up-enter.component-dropdown-slide-up-enter-active.component-dropdown-placement-topCenter,\n.component-dropdown-slide-up-appear.component-dropdown-slide-up-appear-active.component-dropdown-placement-topCenter,\n.component-dropdown-slide-up-enter.component-dropdown-slide-up-enter-active.component-dropdown-placement-topRight,\n.component-dropdown-slide-up-appear.component-dropdown-slide-up-appear-active.component-dropdown-placement-topRight {\n  animation-name: componentDropdownSlideDownIn;\n  animation-play-state: running;\n}\n\n.component-dropdown-slide-up-leave.component-dropdown-slide-up-leave-active.component-dropdown-placement-bottomLeft,\n.component-dropdown-slide-up-leave.component-dropdown-slide-up-leave-active.component-dropdown-placement-bottomCenter,\n.component-dropdown-slide-up-leave.component-dropdown-slide-up-leave-active.component-dropdown-placement-bottomRight {\n  animation-name: componentDropdownSlideUpOut;\n  animation-play-state: running;\n}\n\n.component-dropdown-slide-up-leave.component-dropdown-slide-up-leave-active.component-dropdown-placement-topLeft,\n.component-dropdown-slide-up-leave.component-dropdown-slide-up-leave-active.component-dropdown-placement-topCenter,\n.component-dropdown-slide-up-leave.component-dropdown-slide-up-leave-active.component-dropdown-placement-topRight {\n  animation-name: componentDropdownSlideDownOut;\n  animation-play-state: running;\n}\n\n@keyframes componentDropdownSlideUpIn {\n  0% {\n    opacity: 0;\n    transform-origin: 0% 0%;\n    transform: scaleY(0);\n  }\n  100% {\n    opacity: 1;\n    transform-origin: 0% 0%;\n    transform: scaleY(1);\n  }\n}\n@keyframes componentDropdownSlideUpOut {\n  0% {\n    opacity: 1;\n    transform-origin: 0% 0%;\n    transform: scaleY(1);\n  }\n  100% {\n    opacity: 0;\n    transform-origin: 0% 0%;\n    transform: scaleY(0);\n  }\n}\n@keyframes componentDropdownSlideDownIn {\n  0% {\n    opacity: 0;\n    transform-origin: 0% 100%;\n    transform: scaleY(0);\n  }\n  100% {\n    opacity: 1;\n    transform-origin: 0% 100%;\n    transform: scaleY(1);\n  }\n}\n@keyframes componentDropdownSlideDownOut {\n  0% {\n    opacity: 1;\n    transform-origin: 0% 100%;\n    transform: scaleY(1);\n  }\n  100% {\n    opacity: 0;\n    transform-origin: 0% 100%;\n    transform: scaleY(0);\n  }\n}";
styleInject(css_248z);

//dropdown偏移量
var getDropdownOffset = function getDropdownOffset(place) {
  var _a, _b;
  var offsetMap = {
    top: {
      offset: [0, -8]
    },
    topLeft: {
      offset: [0, -8]
    },
    topRight: {
      offset: [0, -8]
    },
    bottom: {
      offset: [0, 8]
    },
    bottomRight: {
      offset: [0, 8]
    },
    bottomLeft: {
      offset: [0, 8]
    }
  };
  return (_b = (_a = offsetMap[place]) === null || _a === void 0 ? void 0 : _a.offset) !== null && _b !== void 0 ? _b : [0, 0];
};
//dropdown
var Dropdown = function Dropdown(props) {
  var wrapRef = React__default.useRef();
  var getPopupContainer = usePopupContainer(wrapRef, props.getPopupContainer);
  var uuidRef = React__default.useRef(UUID());
  //visible change
  var handleVisibleChange = function handleVisibleChange(visible) {
    var _a;
    (_a = props.onVisibleChange) === null || _a === void 0 ? void 0 : _a.call(props, visible);
    if (props.isolationPopupOnHide) {
      //关闭时隔离dom污染
      isolationPopupPollution(visible, uuidRef.current);
    }
  };
  return jsx(RcDropdown, Object.assign({}, props, {
    prefixCls: "".concat($rcPrefixCls, "-dropdown"),
    overlayClassName: clsx("".concat($prefixCls, "-dropdown"), props.overlayClassName, uuidRef.current),
    animation: "slide-up",
    align: {
      offset: getDropdownOffset(props.placement)
    },
    getPopupContainer: getPopupContainer,
    ref: wrapRef,
    onVisibleChange: handleVisibleChange
  }, {
    children: props.children
  }));
};
Dropdown.defaultProps = {
  mouseEnterDelay: 0.15,
  mouseLeaveDelay: 0.1,
  trigger: ['hover'],
  placement: 'bottomRight',
  isolationPopupOnHide: false
};

export { Dropdown as D, getPlaceholder as a, getPopupContainer as b, getRangePlaceholder as c, formatPickerValue as f, getTimeProps as g, isolationPopupPollution as i, mergedLocale as m };
