import { E as compilerRuntimeExports, r as reactExports, a as r, j as jsxRuntimeExports } from "./vendor-react-DYNCg6N5.js";
import { aD as useViewportSize, ac as useClickOutside, at as Modal, q as Popover, h as ActionIcon } from "./vendor-mantine-h0WlM2Mj.js";
import { a8 as IconPlus } from "./vendor-icons-xWhXK_Ui.js";
var DeviceSize = /* @__PURE__ */ ((DeviceSize2) => {
  DeviceSize2["desktop"] = "Desktop";
  DeviceSize2["tablet"] = "Tablet";
  DeviceSize2["mobile"] = "Mobile";
  return DeviceSize2;
})(DeviceSize || {});
const getDeviceType = (width) => {
  if (width > 1200) return DeviceSize.desktop;
  if (width >= 769) return DeviceSize.tablet;
  return DeviceSize.mobile;
};
const useGetDeviceType = () => {
  const $ = compilerRuntimeExports.c(7);
  const {
    width
  } = useViewportSize();
  const [deviceType, setDeviceType] = reactExports.useState(_temp);
  let t0;
  let t1;
  if ($[0] !== width) {
    t0 = () => {
      if (width === 0) {
        return;
      }
      setDeviceType(getDeviceType(width));
    };
    t1 = [width];
    $[0] = width;
    $[1] = t0;
    $[2] = t1;
  } else {
    t0 = $[1];
    t1 = $[2];
  }
  reactExports.useEffect(t0, t1);
  const isMobile = deviceType === DeviceSize.mobile;
  const isTablet = deviceType === DeviceSize.tablet;
  const isDesktop = deviceType === DeviceSize.desktop;
  let t2;
  if ($[3] !== isDesktop || $[4] !== isMobile || $[5] !== isTablet) {
    t2 = {
      isMobile,
      isTablet,
      isDesktop
    };
    $[3] = isDesktop;
    $[4] = isMobile;
    $[5] = isTablet;
    $[6] = t2;
  } else {
    t2 = $[6];
  }
  return t2;
};
function _temp() {
  if (typeof window === "undefined") {
    return DeviceSize.desktop;
  }
  return getDeviceType(window.innerWidth);
}
const PopUpUI = (props) => {
  const $ = compilerRuntimeExports.c(39);
  const {
    isMobile
  } = useGetDeviceType();
  const [isOpen, setIsOpen] = r.useState(false);
  let t0;
  if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
    t0 = () => setIsOpen(true);
    $[0] = t0;
  } else {
    t0 = $[0];
  }
  const handleOpenPopUp = t0;
  let t1;
  if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
    t1 = () => setIsOpen(false);
    $[1] = t1;
  } else {
    t1 = $[1];
  }
  const handleClosePopUp = t1;
  const ref = useClickOutside(handleClosePopUp);
  const closeTimerRef = r.useRef(null);
  const {
    desktopPosition: t2,
    mobileSize: t3,
    withinPortal: t4,
    offset: t5,
    isHovered: t6,
    triggerWidth: t7
  } = props;
  const desktopPosition = t2 === void 0 ? "right-end" : t2;
  const mobileSize = t3 === void 0 ? "90%" : t3;
  const withinPortal = t4 === void 0 ? false : t4;
  let t8;
  if ($[2] !== t5) {
    t8 = t5 === void 0 ? {
      mainAxis: 10,
      crossAxis: 0
    } : t5;
    $[2] = t5;
    $[3] = t8;
  } else {
    t8 = $[3];
  }
  const offset = t8;
  const isHovered = t6 === void 0 ? false : t6;
  const triggerWidth = t7 === void 0 ? "fit-content" : t7;
  let t9;
  if ($[4] !== isHovered) {
    t9 = () => {
      if (!isHovered) {
        return;
      }
      if (closeTimerRef.current) {
        clearTimeout(closeTimerRef.current);
        closeTimerRef.current = null;
      }
      setIsOpen(true);
    };
    $[4] = isHovered;
    $[5] = t9;
  } else {
    t9 = $[5];
  }
  const handleMouseEnter = t9;
  let t10;
  if ($[6] !== isHovered) {
    t10 = () => {
      if (!isHovered) {
        return;
      }
      closeTimerRef.current = setTimeout(() => setIsOpen(false), 100);
    };
    $[6] = isHovered;
    $[7] = t10;
  } else {
    t10 = $[7];
  }
  const handleMouseLeave = t10;
  const [innerMobileSize, setMobileSize] = r.useState(mobileSize);
  let t11;
  if ($[8] !== isOpen) {
    t11 = {
      setMobileSize,
      isOpen,
      setIsOpen,
      handleOpenPopUp,
      handleClosePopUp
    };
    $[8] = isOpen;
    $[9] = t11;
  } else {
    t11 = $[9];
  }
  const propsToComponents = t11;
  let t12;
  if ($[10] !== props.children || $[11] !== propsToComponents) {
    t12 = typeof props.children === "function" ? props.children(propsToComponents) : props.children;
    $[10] = props.children;
    $[11] = propsToComponents;
    $[12] = t12;
  } else {
    t12 = $[12];
  }
  const children = t12;
  let triggerContent;
  if (props.trigger) {
    if (typeof props.trigger === "function") {
      const triggerName = props.trigger.name;
      if (triggerName && triggerName[0] === triggerName[0].toUpperCase()) {
        let t132;
        if ($[13] !== props.trigger || $[14] !== propsToComponents) {
          t132 = r.createElement(props.trigger, propsToComponents);
          $[13] = props.trigger;
          $[14] = propsToComponents;
          $[15] = t132;
        } else {
          t132 = $[15];
        }
        triggerContent = t132;
      } else {
        let t132;
        if ($[16] !== props.trigger || $[17] !== propsToComponents) {
          t132 = props.trigger(propsToComponents);
          $[16] = props.trigger;
          $[17] = propsToComponents;
          $[18] = t132;
        } else {
          t132 = $[18];
        }
        triggerContent = t132;
      }
    } else {
      triggerContent = props.trigger;
    }
  } else {
    let t132;
    if ($[19] === Symbol.for("react.memo_cache_sentinel")) {
      t132 = /* @__PURE__ */ jsxRuntimeExports.jsx(ActionIcon, { onClick: handleOpenPopUp, className: "singleAdd", children: /* @__PURE__ */ jsxRuntimeExports.jsx(IconPlus, { color: "rgba(51, 154, 240, 1)" }) });
      $[19] = t132;
    } else {
      t132 = $[19];
    }
    triggerContent = t132;
  }
  let t13;
  if ($[20] !== triggerWidth) {
    t13 = {
      display: "flex",
      width: triggerWidth
    };
    $[20] = triggerWidth;
    $[21] = t13;
  } else {
    t13 = $[21];
  }
  let t14;
  if ($[22] !== handleMouseEnter || $[23] !== handleMouseLeave || $[24] !== t13 || $[25] !== triggerContent) {
    t14 = /* @__PURE__ */ jsxRuntimeExports.jsx("div", { style: t13, onMouseEnter: handleMouseEnter, onMouseLeave: handleMouseLeave, children: triggerContent });
    $[22] = handleMouseEnter;
    $[23] = handleMouseLeave;
    $[24] = t13;
    $[25] = triggerContent;
    $[26] = t14;
  } else {
    t14 = $[26];
  }
  const triggerElement = t14;
  let t15;
  if ($[27] !== children || $[28] !== desktopPosition || $[29] !== handleMouseEnter || $[30] !== handleMouseLeave || $[31] !== innerMobileSize || $[32] !== isMobile || $[33] !== isOpen || $[34] !== offset || $[35] !== ref || $[36] !== triggerElement || $[37] !== withinPortal) {
    t15 = /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: isMobile ? /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
      triggerElement,
      /* @__PURE__ */ jsxRuntimeExports.jsxs(Modal.Root, { size: innerMobileSize, opened: isOpen, centered: true, onClose: handleClosePopUp, children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx(Modal.Overlay, {}),
        /* @__PURE__ */ jsxRuntimeExports.jsx(Modal.Content, { style: {
          overflow: "unset"
        }, children: /* @__PURE__ */ jsxRuntimeExports.jsx(Modal.Body, { style: {
          padding: 0
        }, children }) })
      ] })
    ] }) : /* @__PURE__ */ jsxRuntimeExports.jsxs(Popover, { withinPortal, opened: isOpen, position: desktopPosition, offset, shadow: "xs", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx(Popover.Target, { children: triggerElement }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(Popover.Dropdown, { style: {
        padding: 0
      }, ref, onMouseEnter: handleMouseEnter, onMouseLeave: handleMouseLeave, children })
    ] }) });
    $[27] = children;
    $[28] = desktopPosition;
    $[29] = handleMouseEnter;
    $[30] = handleMouseLeave;
    $[31] = innerMobileSize;
    $[32] = isMobile;
    $[33] = isOpen;
    $[34] = offset;
    $[35] = ref;
    $[36] = triggerElement;
    $[37] = withinPortal;
    $[38] = t15;
  } else {
    t15 = $[38];
  }
  return t15;
};
export {
  PopUpUI as P,
  useGetDeviceType as u
};
//# sourceMappingURL=index-DGrXxZ89.js.map
