'use strict';

const jsxRuntime = require('react/jsx-runtime');
const config = require('./config.cjs');
const button = require('../../../../button.cjs');
const dropdownMenu = require('../../../../dropdown-menu.cjs');
const LucideIcons = require('lucide-react');
const React = require('react');

const EMPTY_OBJECT = {};
function ClassNameGroupControl({
  groupConfig,
  group,
  state,
  handleStateChange,
  handleGroupKeySelect,
  selectedKey
}) {
  const spreadProps = React.useMemo(
    () => "multiple" in groupConfig ? { multiple: groupConfig.multiple } : EMPTY_OBJECT,
    [groupConfig]
  );
  const handleChange = React.useCallback(
    (value) => handleStateChange(selectedKey, value),
    [handleStateChange, selectedKey]
  );
  const handleDropdownClick = React.useCallback(
    (key) => () => handleGroupKeySelect(group.label, key),
    [handleGroupKeySelect, group.label]
  );
  return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
    /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-xs font-medium text-muted-foreground", children: group.label }),
    /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-row", children: [
      /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(
        groupConfig.component,
        {
          ...groupConfig,
          ...spreadProps,
          hideLabel: true,
          value: state[selectedKey],
          onChange: handleChange
        }
      ) }),
      /* @__PURE__ */ jsxRuntime.jsxs(dropdownMenu.DropdownMenu, { children: [
        /* @__PURE__ */ jsxRuntime.jsx(dropdownMenu.DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(button.Button, { variant: "outline", size: "icon", className: "text-xs w-6 px-1 py-1", children: /* @__PURE__ */ jsxRuntime.jsx(LucideIcons.MoreVertical, { className: "!size-4" }) }) }),
        /* @__PURE__ */ jsxRuntime.jsx(dropdownMenu.DropdownMenuContent, { align: "end", children: group.keys.map((key) => /* @__PURE__ */ jsxRuntime.jsx(
          dropdownMenu.DropdownMenuItem,
          {
            onClick: handleDropdownClick(String(key)),
            className: selectedKey === String(key) ? "bg-secondary-foreground/10" : "",
            children: config.CONFIG[String(key)]?.label || String(key)
          },
          String(key)
        )) })
      ] })
    ] })
  ] });
}

exports.ClassNameGroupControl = ClassNameGroupControl;
