import { jsx, jsxs } from "react/jsx-runtime";
import { FilterPanelHeader } from "./FilterPanelHeader.js";
import { PanelFooter } from "./PanelFooter.js";
import { PanelSidebar } from "./PanelSidebar.js";
/* empty css                        */
import Drawer from "../../node_modules/@mui/material/Drawer/Drawer.js";
function getSizeClass(size) {
  switch (size) {
    case "medium":
      return "impact_drawer_filter_container_medium";
    default:
      return "impact_drawer_filter_container_large";
  }
}
function FilterPanel({
  className,
  title,
  size = "large",
  anchor = "right",
  isOpen,
  setIsOpen,
  active,
  setActive,
  filters,
  handleClose,
  primaryButtonLabel,
  onPrimaryButtonClick,
  secondaryButtonLabel,
  onSecondaryButtonClick,
  tertiaryButtonLabel,
  onTertiaryButtonClick,
  quaternaryButtonLabel,
  onQuaternaryButtonClick,
  primaryButtonProps,
  secondaryButtonProps,
  tertiaryButtonProps,
  quaternaryButtonProps,
  alwaysRender = false,
  "data-testid": dataTestId,
  ...drawerProps
}) {
  var _a;
  const handleToggleDrawer = (_event) => {
    if (_event.type === "keydown" && (_event.key === "Tab" || _event.key === "Shift")) {
      return;
    }
    if (handleClose) {
      handleClose();
    } else {
      setIsOpen == null ? void 0 : setIsOpen(!isOpen);
    }
  };
  const closeHandler = () => {
    handleToggleDrawer({});
  };
  const hasFooter = primaryButtonLabel != null || secondaryButtonLabel != null || tertiaryButtonLabel != null || quaternaryButtonLabel != null;
  const activeItems = filters.filter((item) => item.value === active);
  const activeContent = (_a = activeItems[0]) == null ? void 0 : _a.children;
  const containerClass = ["impact_drawer_filter_container", getSizeClass(size), className ?? ""].filter(Boolean).join(" ");
  const bodyClass = hasFooter ? "impact_drawer_filter_body" : "impact_drawer_filter_body impact_drawer_filter_footer_no_buttons";
  if (!hasFooter) {
    return /* @__PURE__ */ jsx(Drawer, { anchor, open: isOpen, onClose: handleToggleDrawer, ...drawerProps, children: /* @__PURE__ */ jsxs("div", { className: containerClass, "data-testid": dataTestId, children: [
      /* @__PURE__ */ jsx(FilterPanelHeader, { title, toggleDrawer: closeHandler }),
      /* @__PURE__ */ jsxs("div", { className: "impact-drawer-filter-main-container", children: [
        /* @__PURE__ */ jsx(PanelSidebar, { active, filters, setActive }),
        /* @__PURE__ */ jsx("div", { className: "impact_drawer_filter_container_right_panel", children: /* @__PURE__ */ jsx("div", { className: bodyClass, children: activeContent }) })
      ] })
    ] }) });
  }
  return /* @__PURE__ */ jsx(Drawer, { anchor, open: isOpen, onClose: handleToggleDrawer, ...drawerProps, children: /* @__PURE__ */ jsxs("div", { className: containerClass, "data-testid": dataTestId, children: [
    /* @__PURE__ */ jsx(FilterPanelHeader, { title, toggleDrawer: closeHandler }),
    /* @__PURE__ */ jsxs("div", { className: "impact-drawer-filter-main-container", children: [
      /* @__PURE__ */ jsx(PanelSidebar, { active, filters, setActive }),
      /* @__PURE__ */ jsxs("div", { className: "impact_drawer_filter_container_right_panel", children: [
        alwaysRender ? filters.map((item) => /* @__PURE__ */ jsx(
          "div",
          {
            className: "impact_drawer_filter_body",
            style: {
              display: item.value === active ? "block" : "none"
            },
            children: item.children
          },
          item.id ?? item.value
        )) : /* @__PURE__ */ jsx("div", { className: "impact_drawer_filter_body", children: activeContent }),
        /* @__PURE__ */ jsx(
          PanelFooter,
          {
            primaryButtonLabel,
            primaryButtonProps,
            quaternaryButtonLabel,
            quaternaryButtonProps,
            secondaryButtonLabel,
            secondaryButtonProps,
            tertiaryButtonLabel,
            tertiaryButtonProps,
            onPrimaryButtonClick,
            onQuaternaryButtonClick,
            onSecondaryButtonClick,
            onTertiaryButtonClick
          }
        )
      ] })
    ] })
  ] }) });
}
FilterPanel.displayName = "FilterPanel";
export {
  FilterPanel,
  FilterPanelHeader,
  PanelFooter,
  PanelSidebar
};
