import { jsx, jsxs } from "react/jsx-runtime";
import { Button } from "../Button/index.js";
/* empty css                  */
import Drawer from "../../node_modules/@mui/material/Drawer/Drawer.js";
function getSize(size) {
  switch (size) {
    case "medium":
      return "impact_drawer_container_medium";
    default:
      return "impact_drawer_container_large";
  }
}
function Panel({
  className,
  title,
  size,
  anchor = "right",
  open,
  setIsOpen,
  children,
  onClose,
  primaryButtonLabel,
  onPrimaryButtonClick,
  secondaryButtonLabel,
  onSecondaryButtonClick,
  primaryButtonProps,
  secondaryButtonProps,
  width,
  zIndex = 1500,
  ...args
}) {
  const toggleDrawer = (_anchor, isOpen) => (event, _reason) => {
    const e = event;
    if (e.type === "keydown" && (e.key === "Tab" || e.key === "Shift")) {
      return;
    }
    if (onClose) {
      onClose();
    }
    setIsOpen == null ? void 0 : setIsOpen(isOpen);
  };
  if (!secondaryButtonLabel && !primaryButtonLabel) {
    return /* @__PURE__ */ jsx(
      Drawer,
      {
        anchor,
        open,
        sx: {
          "& .MuiDrawer-paper": {
            zIndex: `${zIndex}`
          }
        },
        onClose: toggleDrawer(anchor, false),
        children: /* @__PURE__ */ jsxs(
          "div",
          {
            className: `impact_drawer_container ${getSize(size)} ${className}`,
            style: { width: `${width}px` },
            ...args,
            children: [
              /* @__PURE__ */ jsxs("div", { className: "impact_drawer_header", children: [
                /* @__PURE__ */ jsx("div", { className: "impact_drawer_heading", children: title }),
                /* @__PURE__ */ jsx(
                  "span",
                  {
                    "aria-label": "Close",
                    className: "close_icon",
                    "data-testid": "panel-close-button",
                    role: "button",
                    tabIndex: 0,
                    onClick: toggleDrawer(anchor, false),
                    onKeyDown: (e) => {
                      if (e.key === "Enter" || e.key === " ") toggleDrawer(anchor, false)(e);
                    }
                  }
                )
              ] }),
              /* @__PURE__ */ jsx("div", { className: "impact_drawer_body", style: { height: "calc(100% - 40px)" }, children })
            ]
          }
        )
      }
    );
  }
  return /* @__PURE__ */ jsx(
    Drawer,
    {
      anchor,
      open,
      sx: {
        "& .MuiDrawer-paper": {
          zIndex: `${zIndex}`
        }
      },
      onClose: toggleDrawer(anchor, false),
      children: /* @__PURE__ */ jsxs(
        "div",
        {
          className: `impact_drawer_container ${getSize(size)} ${className}`,
          style: { width: `${width}px` },
          ...args,
          children: [
            /* @__PURE__ */ jsxs("div", { className: "impact_drawer_header", children: [
              /* @__PURE__ */ jsx("div", { className: "impact_drawer_heading", children: title }),
              /* @__PURE__ */ jsx(
                "span",
                {
                  "aria-label": "Close",
                  className: "close_icon",
                  "data-testid": "panel-close-button",
                  role: "button",
                  tabIndex: 0,
                  onClick: toggleDrawer(anchor, false),
                  onKeyDown: (e) => {
                    if (e.key === "Enter" || e.key === " ") toggleDrawer(anchor, false)(e);
                  }
                }
              )
            ] }),
            /* @__PURE__ */ jsx("div", { className: "impact_drawer_body", children }),
            /* @__PURE__ */ jsxs("div", { className: "impact_drawer_footer", children: [
              secondaryButtonLabel && /* @__PURE__ */ jsx(Button, { variant: "url", onClick: onSecondaryButtonClick, ...secondaryButtonProps, children: secondaryButtonLabel }),
              primaryButtonLabel && /* @__PURE__ */ jsx(Button, { onClick: onPrimaryButtonClick, ...primaryButtonProps, children: primaryButtonLabel })
            ] })
          ]
        }
      )
    }
  );
}
export {
  Panel
};
