"use client";
'use strict';

var classVarianceAuthority = require('class-variance-authority');
var clsx = require('clsx');
var tailwindMerge = require('tailwind-merge');
var jsxRuntime = require('react/jsx-runtime');
var checkbox = require('@base-ui/react/checkbox');
var lucideReact = require('lucide-react');

var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
  for (var prop in b || (b = {}))
    if (__hasOwnProp.call(b, prop))
      __defNormalProp(a, prop, b[prop]);
  if (__getOwnPropSymbols)
    for (var prop of __getOwnPropSymbols(b)) {
      if (__propIsEnum.call(b, prop))
        __defNormalProp(a, prop, b[prop]);
    }
  return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
var __objRest = (source, exclude) => {
  var target = {};
  for (var prop in source)
    if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
      target[prop] = source[prop];
  if (source != null && __getOwnPropSymbols)
    for (var prop of __getOwnPropSymbols(source)) {
      if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
        target[prop] = source[prop];
    }
  return target;
};
function cn(...inputs) {
  return tailwindMerge.twMerge(clsx.clsx(inputs));
}
var TABLE_SORT_INACTIVE_FILL = "fill-[color:var(--theme-text-inactive)]";
var SORT_INACTIVE_TOP = "M12.4207 3.10686C12.5531 3.16564 12.6718 3.25153 12.769 3.35899L17.769 9.35899C17.891 9.50504 17.9687 9.68286 17.9932 9.87156C18.0176 10.0603 17.9877 10.252 17.907 10.4243C17.8262 10.5966 17.698 10.7423 17.5373 10.8443C17.3767 10.9463 17.1903 11.0003 17 11H7C6.80971 11.0003 6.6233 10.9463 6.46265 10.8443C6.302 10.7423 6.17377 10.5966 6.09303 10.4243C6.01229 10.252 5.98238 10.0603 6.00682 9.87156C6.03126 9.68286 6.10903 9.50504 6.231 9.35899L11.231 3.35899C11.3282 3.25153 11.4469 3.16564 11.5793 3.10686C11.7118 3.04807 11.8551 3.0177 12 3.0177C12.1449 3.0177 12.2882 3.04807 12.4207 3.10686Z";
var SORT_INACTIVE_BOTTOM = "M7 13H17C17.1903 12.9997 17.3767 13.0537 17.5373 13.1557C17.698 13.2577 17.8262 13.4034 17.907 13.5757C17.9877 13.748 18.0176 13.9397 17.9932 14.1284C17.9687 14.3171 17.891 14.4949 17.769 14.641L12.769 20.641C12.6752 20.7539 12.5576 20.8447 12.4247 20.9071C12.2918 20.9694 12.1468 21.0017 12 21.0017C11.8532 21.0017 11.7082 20.9694 11.5753 20.9071C11.4424 20.8447 11.3248 20.7539 11.231 20.641L6.231 14.641C6.10903 14.4949 6.03126 14.3171 6.00682 14.1284C5.98238 13.9397 6.01229 13.748 6.09303 13.5757C6.17377 13.4034 6.302 13.2577 6.46265 13.1557C6.6233 13.0537 6.80971 12.9997 7 13Z";
var SORT_ASCENDING_ACTIVE = "M12.4207 3.10686C12.5531 3.16564 12.6718 3.25153 12.769 3.35899L17.769 9.35899C17.891 9.50504 17.9687 9.68286 17.9932 9.87156C18.0176 10.0603 17.9877 10.252 17.907 10.4243C17.8262 10.5966 17.698 10.7423 17.5373 10.8443C17.3767 10.9463 17.1903 11.0003 17 11H7C6.80971 11.0003 6.6233 10.9463 6.46265 10.8443C6.302 10.7423 6.17377 10.5966 6.09303 10.4243C6.01229 10.252 5.98238 10.0603 6.00682 9.87156C6.03126 9.68286 6.10903 9.50504 6.231 9.35899L11.231 3.35899C11.3282 3.25153 11.4469 3.16564 11.5793 3.10686C11.7118 3.04807 11.8551 3.0177 12 3.0177C12.1449 3.0177 12.2882 3.04807 12.4207 3.10686Z";
var SORT_DESCENDING_ACTIVE = "M11.5793 20.9126C11.4469 20.8538 11.3282 20.7679 11.231 20.6604L6.23101 14.6604C6.10904 14.5144 6.03126 14.3366 6.00683 14.1478C5.98239 13.9591 6.0123 13.7674 6.09304 13.5951C6.17378 13.4228 6.30201 13.2771 6.46266 13.1751C6.62331 13.0732 6.80972 13.0191 7 13.0194L17 13.0194C17.1903 13.0191 17.3767 13.0732 17.5373 13.1751C17.698 13.2771 17.8262 13.4228 17.907 13.5951C17.9877 13.7674 18.0176 13.9591 17.9932 14.1478C17.9687 14.3366 17.891 14.5144 17.769 14.6604L12.769 20.6604C12.6718 20.7679 12.5531 20.8538 12.4207 20.9126C12.2882 20.9713 12.1449 21.0017 12 21.0017C11.8551 21.0017 11.7118 20.9713 11.5793 20.9126Z";
function TableSortIconShell(_a) {
  var _b = _a, {
    className,
    children
  } = _b, props = __objRest(_b, [
    "className",
    "children"
  ]);
  return /* @__PURE__ */ jsxRuntime.jsx(
    "svg",
    __spreadProps(__spreadValues({
      viewBox: "0 0 24 24",
      fill: "none",
      xmlns: "http://www.w3.org/2000/svg",
      className: cn("size-4 shrink-0", className),
      "aria-hidden": true
    }, props), {
      children
    })
  );
}
function TableSortInactiveIcon(props) {
  return /* @__PURE__ */ jsxRuntime.jsxs(TableSortIconShell, __spreadProps(__spreadValues({}, props), { children: [
    /* @__PURE__ */ jsxRuntime.jsx("path", { d: SORT_INACTIVE_TOP, className: TABLE_SORT_INACTIVE_FILL }),
    /* @__PURE__ */ jsxRuntime.jsx("path", { d: SORT_INACTIVE_BOTTOM, className: TABLE_SORT_INACTIVE_FILL })
  ] }));
}
function TableSortAscendingIcon(props) {
  return /* @__PURE__ */ jsxRuntime.jsxs(TableSortIconShell, __spreadProps(__spreadValues({}, props), { children: [
    /* @__PURE__ */ jsxRuntime.jsx("path", { d: SORT_INACTIVE_BOTTOM, className: TABLE_SORT_INACTIVE_FILL }),
    /* @__PURE__ */ jsxRuntime.jsx("path", { d: SORT_ASCENDING_ACTIVE, className: "fill-primary" })
  ] }));
}
function TableSortDescendingIcon(props) {
  return /* @__PURE__ */ jsxRuntime.jsxs(TableSortIconShell, __spreadProps(__spreadValues({}, props), { children: [
    /* @__PURE__ */ jsxRuntime.jsx("path", { d: SORT_INACTIVE_TOP, className: TABLE_SORT_INACTIVE_FILL }),
    /* @__PURE__ */ jsxRuntime.jsx("path", { d: SORT_DESCENDING_ACTIVE, className: "fill-primary" })
  ] }));
}
function TableSortIndicatorIcon({
  state,
  className
}) {
  if (state === "asc") {
    return /* @__PURE__ */ jsxRuntime.jsx(TableSortAscendingIcon, { className });
  }
  if (state === "desc") {
    return /* @__PURE__ */ jsxRuntime.jsx(TableSortDescendingIcon, { className });
  }
  return /* @__PURE__ */ jsxRuntime.jsx(TableSortInactiveIcon, { className });
}
function Checkbox(_a) {
  var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
  return /* @__PURE__ */ jsxRuntime.jsx(
    checkbox.Checkbox.Root,
    __spreadProps(__spreadValues({
      "data-slot": "checkbox",
      className: cn(
        "group/checkbox relative inline-flex size-6 shrink-0 cursor-pointer items-center justify-center outline-none touch-manipulation",
        "focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-50",
        className
      )
    }, props), {
      children: /* @__PURE__ */ jsxRuntime.jsx(
        "span",
        {
          "aria-hidden": true,
          className: cn(
            "relative flex size-4 shrink-0 items-center justify-center overflow-hidden rounded-[4px] border border-input bg-background transition-colors outline-none",
            "dark:bg-input/30",
            "group-focus-visible/checkbox:ring-4 group-focus-visible/checkbox:ring-ring/50 group-focus-visible/checkbox:ring-offset-1 group-focus-visible/checkbox:ring-offset-background",
            "group-focus-visible/checkbox:border-ring",
            "group-disabled/checkbox:cursor-not-allowed group-disabled/checkbox:opacity-50",
            "group-aria-invalid/checkbox:border-destructive group-aria-invalid/checkbox:ring-3 group-aria-invalid/checkbox:ring-destructive/20",
            "group-aria-invalid/checkbox:group-data-checked/checkbox:border-primary",
            "dark:group-aria-invalid/checkbox:border-destructive/50 dark:group-aria-invalid/checkbox:ring-destructive/40",
            "group-data-unchecked/checkbox:group-hover/checkbox:border-input-hover group-data-unchecked/checkbox:group-hover/checkbox:bg-accent/50",
            "dark:group-data-unchecked/checkbox:group-hover/checkbox:border-input-hover dark:group-data-unchecked/checkbox:group-hover/checkbox:bg-accent/30",
            "group-disabled/checkbox:group-hover/checkbox:border-input group-disabled/checkbox:group-hover/checkbox:bg-transparent",
            "group-data-checked/checkbox:border-primary group-data-checked/checkbox:bg-primary group-data-checked/checkbox:text-primary-foreground",
            "group-data-checked/checkbox:group-hover/checkbox:border-[var(--primary-hover)] group-data-checked/checkbox:group-hover/checkbox:bg-[var(--primary-hover)]",
            "dark:group-data-checked/checkbox:bg-primary",
            "group-data-indeterminate/checkbox:border-primary group-data-indeterminate/checkbox:bg-primary group-data-indeterminate/checkbox:text-primary-foreground",
            "group-data-indeterminate/checkbox:group-hover/checkbox:border-[var(--primary-hover)] group-data-indeterminate/checkbox:group-hover/checkbox:bg-[var(--primary-hover)]",
            "dark:group-data-indeterminate/checkbox:bg-primary"
          ),
          children: /* @__PURE__ */ jsxRuntime.jsx(
            checkbox.Checkbox.Indicator,
            {
              "data-slot": "checkbox-indicator",
              keepMounted: true,
              className: "absolute inset-0 flex items-center justify-center leading-none text-current transition-none",
              render: (indicatorProps, state) => /* @__PURE__ */ jsxRuntime.jsx(
                "span",
                __spreadProps(__spreadValues({}, indicatorProps), {
                  className: cn(
                    indicatorProps.className,
                    "flex size-full items-center justify-center"
                  ),
                  children: state.indeterminate ? /* @__PURE__ */ jsxRuntime.jsx(
                    lucideReact.MinusIcon,
                    {
                      className: "block size-2.5",
                      strokeWidth: 2.25,
                      "aria-hidden": true
                    }
                  ) : state.checked ? /* @__PURE__ */ jsxRuntime.jsx(
                    lucideReact.CheckIcon,
                    {
                      className: "block size-2.5",
                      strokeWidth: 2.25,
                      "aria-hidden": true
                    }
                  ) : null
                })
              )
            }
          )
        }
      )
    })
  );
}
var tableHeaderCellVariants = classVarianceAuthority.cva(
  "flex items-center min-h-8 min-w-9 rounded-[var(--radius-xs,4px)]",
  {
    variants: {
      variant: {
        label: "cursor-default gap-4 px-3",
        checkbox: "justify-center",
        icon: "justify-center",
        empty: ""
      }
    },
    defaultVariants: {
      variant: "label"
    }
  }
);
function TableHeaderCell(_a) {
  var _b = _a, {
    className,
    variant = "label",
    label,
    leadIcon,
    tailIcon,
    sortable = false,
    sortState = "inactive",
    onSort,
    checked,
    indeterminate,
    onCheckedChange
  } = _b, props = __objRest(_b, [
    "className",
    "variant",
    "label",
    "leadIcon",
    "tailIcon",
    "sortable",
    "sortState",
    "onSort",
    "checked",
    "indeterminate",
    "onCheckedChange"
  ]);
  if (variant === "empty") {
    return /* @__PURE__ */ jsxRuntime.jsx(
      "div",
      __spreadValues({
        "data-slot": "table-header-cell",
        className: cn("h-8 min-h-8 min-w-9", className)
      }, props)
    );
  }
  if (variant === "checkbox") {
    return /* @__PURE__ */ jsxRuntime.jsx(
      "div",
      __spreadProps(__spreadValues({
        "data-slot": "table-header-cell",
        className: cn(tableHeaderCellVariants({ variant }), className)
      }, props), {
        children: /* @__PURE__ */ jsxRuntime.jsx(
          Checkbox,
          {
            checked,
            indeterminate,
            onCheckedChange: (val) => onCheckedChange == null ? void 0 : onCheckedChange(val),
            "aria-label": "Select all"
          }
        )
      })
    );
  }
  if (variant === "icon") {
    return /* @__PURE__ */ jsxRuntime.jsx(
      "div",
      __spreadProps(__spreadValues({
        "data-slot": "table-header-cell",
        className: cn(tableHeaderCellVariants({ variant }), className)
      }, props), {
        children: leadIcon && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "flex size-4 shrink-0 items-center justify-center text-muted-foreground", children: leadIcon })
      })
    );
  }
  const sortGlyph = sortable && !tailIcon ? /* @__PURE__ */ jsxRuntime.jsx(TableSortIndicatorIcon, { state: sortState }) : tailIcon;
  const sortControl = sortable && sortGlyph && !tailIcon ? /* @__PURE__ */ jsxRuntime.jsx(
    "button",
    {
      type: "button",
      className: cn(
        "inline-flex size-6 shrink-0 cursor-pointer items-center justify-center rounded-[var(--radius-xs,4px)] border-0 bg-transparent p-0 outline-none transition-colors hover:bg-muted/50 focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background",
        sortState !== "inactive" ? "text-primary" : "text-[color:var(--theme-text-inactive)]"
      ),
      "aria-label": label ? `Sort by ${label}` : "Sort column",
      onClick: (e) => {
        e.stopPropagation();
        onSort == null ? void 0 : onSort();
      },
      children: sortGlyph
    }
  ) : sortGlyph ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "flex size-4 shrink-0 items-center justify-center text-muted-foreground [&>svg]:size-4", children: sortGlyph }) : null;
  return /* @__PURE__ */ jsxRuntime.jsxs(
    "div",
    __spreadProps(__spreadValues({
      "data-slot": "table-header-cell",
      className: cn(
        tableHeaderCellVariants({ variant }),
        sortable && "select-none",
        className
      )
    }, props), {
      children: [
        leadIcon && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "flex size-4 shrink-0 items-center justify-center text-muted-foreground [&>svg]:size-4", children: leadIcon }),
        /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex min-h-px min-w-0 flex-1 items-center gap-[var(--spacing-4)]", children: [
          /* @__PURE__ */ jsxRuntime.jsx("span", { className: "min-w-0 cursor-default truncate text-sm font-medium leading-5 text-foreground", children: label }),
          sortControl
        ] })
      ]
    })
  );
}

exports.TableHeaderCell = TableHeaderCell;
exports.tableHeaderCellVariants = tableHeaderCellVariants;
//# sourceMappingURL=table-header-cell.cjs.map
//# sourceMappingURL=table-header-cell.cjs.map