import { jsxs, jsx } from "react/jsx-runtime";
import { useState } from "react";
import FormControlLabel from "../../node_modules/@mui/material/FormControlLabel/FormControlLabel.js";
import Checkbox from "../../node_modules/@mui/material/Checkbox/Checkbox.js";
import KeyboardArrowDown from "../../node_modules/@mui/icons-material/esm/KeyboardArrowDown.js";
import Menu from "../../node_modules/@mui/material/Menu/Menu.js";
import MenuItem from "../../node_modules/@mui/material/MenuItem/MenuItem.js";
function WithDropDown({
  defaultChecked,
  checked,
  onChange,
  isRequired = false,
  isDisabled = false,
  label,
  dropDownData,
  onDropDownCheckBoxClick,
  ...args
}) {
  const [anchorEl, setAnchorEl] = useState(null);
  const [selected, setSelected] = useState(null);
  const isOpen = Boolean(anchorEl);
  const onClose = () => {
    setAnchorEl(null);
  };
  const handleClick = (event) => {
    setAnchorEl(event.currentTarget);
    onDropDownCheckBoxClick == null ? void 0 : onDropDownCheckBoxClick(event);
  };
  const isChecked = checked ?? defaultChecked;
  return /* @__PURE__ */ jsxs("div", { className: "impact-form-checkbox", children: [
    /* @__PURE__ */ jsxs(
      "div",
      {
        "aria-expanded": isOpen,
        "aria-haspopup": "true",
        role: "button",
        style: { display: "flex", alignItems: "center" },
        tabIndex: 0,
        onClick: handleClick,
        onKeyDown: (e) => {
          if (e.key === "Enter" || e.key === " ") {
            handleClick(e);
          }
        },
        children: [
          /* @__PURE__ */ jsx(
            FormControlLabel,
            {
              className: `impact-form-checkbox-container ${isChecked ? "checked" : ""}`,
              control: /* @__PURE__ */ jsx(
                Checkbox,
                {
                  ...args,
                  disableRipple: true,
                  checked,
                  className: "impact-checkbox-container default-variant",
                  defaultChecked,
                  disabled: isDisabled,
                  onChange
                }
              ),
              disabled: isDisabled,
              label,
              required: isRequired
            }
          ),
          /* @__PURE__ */ jsx(KeyboardArrowDown, { className: `impact-arrow-button ${isOpen ? "up" : "down"}` })
        ]
      }
    ),
    /* @__PURE__ */ jsx(
      Menu,
      {
        anchorEl,
        className: "ia-styles ia-checkbox-menu",
        id: "checkbox-menu",
        MenuListProps: {
          "aria-labelledby": "checkbox-button"
        },
        open: isOpen,
        onClose,
        children: dropDownData.map((opt) => /* @__PURE__ */ jsx(
          MenuItem,
          {
            disableRipple: true,
            disableTouchRipple: true,
            disabled: opt.disabled,
            selected: selected === opt.value,
            onClick: () => {
              var _a;
              setSelected((prev) => prev === opt.value ? null : opt.value);
              (_a = opt.onClick) == null ? void 0 : _a.call(opt);
              onClose();
            },
            children: opt.label
          },
          opt.value
        ))
      }
    )
  ] });
}
export {
  WithDropDown as default
};
