"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var Popin_exports = {};
__export(Popin_exports, {
  default: () => Popin_default
});
module.exports = __toCommonJS(Popin_exports);
var import_react = __toESM(require("react"));
var import_react_dom = __toESM(require("react-dom"));
var import_styled_components = __toESM(require("styled-components"));
var import_CloseMedium = __toESM(require("@ledgerhq/icons-ui/reactLegacy/CloseMedium"));
var import_ArrowLeftMedium = __toESM(require("@ledgerhq/icons-ui/reactLegacy/ArrowLeftMedium"));
var import_styled = __toESM(require("../../styled"));
var import_Flex = __toESM(require("../../layout/Flex"));
var import_Button = __toESM(require("../../cta/Button"));
var import_TransitionInOut = __toESM(require("../../transitions/TransitionInOut"));
var import_TransitionScale = __toESM(require("../../transitions/TransitionScale"));
const ICON_SIZE = 20;
const Wrapper = (0, import_styled_components.default)(import_Flex.default).attrs((p) => ({
  flexDirection: "column",
  alignItems: "stretch",
  justifyContent: "space-between",
  height: p.height || `${p.theme.sizes.drawer.popin.max.height}px`,
  width: p.width || `${p.theme.sizes.drawer.popin.max.width}px`,
  minHeight: `${p.theme.sizes.drawer.popin.min.height}px`,
  minWidth: `${p.theme.sizes.drawer.popin.min.width}px`,
  maxHeight: `${p.theme.sizes.drawer.popin.max.height}px`,
  maxWidth: `${p.theme.sizes.drawer.popin.max.width}px`,
  zIndex: p.theme.zIndexes[8],
  p: p.p !== void 0 ? p.p : p.theme.space[10],
  rowGap: 6,
  backgroundColor: "background.main"
}))``;
const Overlay = (0, import_styled_components.default)(import_Flex.default).attrs((p) => ({
  justifyContent: "center",
  alignItems: "center",
  width: "100vw",
  height: "100vh",
  zIndex: p.theme.zIndexes[8],
  position: "fixed",
  top: 0,
  left: 0,
  backgroundColor: "constant.overlay"
}))``;
const Header = import_styled.default.section`
  display: grid;
  grid-template-columns: [icon] ${ICON_SIZE}px [title] 1fr [icon] ${ICON_SIZE}px;
  column-gap: 12px;
`;
const HeaderTitleContainer = (0, import_styled_components.default)(import_Flex.default).attrs(() => ({
  justifyContent: "center"
}))``;
const PopinBody = (0, import_styled.default)(import_Flex.default).attrs({
  as: "section",
  flexDirection: "column",
  flex: 1,
  overflow: "auto"
})``;
const PopinFooter = (0, import_styled.default)(import_Flex.default).attrs({ as: "section" })``;
const IconContainer = (0, import_styled_components.default)(import_Button.default.Unstyled)`
  display: flex;
  align-items: center;
`;
const PopinHeader = ({ children, onClose, onBack, ...props }) => /* @__PURE__ */ import_react.default.createElement(Header, { ...props }, /* @__PURE__ */ import_react.default.createElement(import_Flex.default, null, onBack ? /* @__PURE__ */ import_react.default.createElement(IconContainer, { onClick: onBack }, /* @__PURE__ */ import_react.default.createElement(import_ArrowLeftMedium.default, { size: ICON_SIZE, color: "neutral.c100" })) : null), /* @__PURE__ */ import_react.default.createElement(HeaderTitleContainer, null, children), /* @__PURE__ */ import_react.default.createElement(import_Flex.default, null, onClose ? /* @__PURE__ */ import_react.default.createElement(IconContainer, { onClick: onClose }, /* @__PURE__ */ import_react.default.createElement(import_CloseMedium.default, { size: ICON_SIZE, color: "neutral.c100" })) : null));
const Popin = ({ isOpen, children, width, height, ...props }) => /* @__PURE__ */ import_react.default.createElement(import_TransitionInOut.default, { in: isOpen, appear: true, mountOnEnter: true, unmountOnExit: true }, /* @__PURE__ */ import_react.default.createElement(Overlay, null, /* @__PURE__ */ import_react.default.createElement(import_TransitionScale.default, { in: isOpen, appear: true }, /* @__PURE__ */ import_react.default.createElement(Wrapper, { width, height, ...props }, children))));
const PopinWrapper = ({
  children,
  menuPortalTarget,
  ...popinProps
}) => {
  const $root = import_react.default.useMemo(
    () => menuPortalTarget === void 0 && typeof document !== "undefined" ? document.querySelector("body") : menuPortalTarget,
    [menuPortalTarget]
  );
  if (!$root) {
    return /* @__PURE__ */ import_react.default.createElement(Popin, { ...popinProps }, children);
  } else {
    return import_react_dom.default.createPortal(/* @__PURE__ */ import_react.default.createElement(Popin, { ...popinProps }, children), $root);
  }
};
PopinWrapper.Header = PopinHeader;
PopinWrapper.Body = PopinBody;
PopinWrapper.Footer = PopinFooter;
var Popin_default = PopinWrapper;
//# sourceMappingURL=index.js.map
