import { useMemo, createElement, Fragment } from "react";
import { Icon, TableHeaderCell, Dropdown, ActionableBox, Box } from "@contember/ui";
import { cycleOrderDirection } from "./DataGridOrderDirection.js";
function DataGridHeaderCell({
  ascOrderIcon,
  descOrderIcon,
  emptyFilterArtifact,
  environment,
  filterArtifact,
  filterRenderer,
  hasFilter,
  header,
  headerJustification,
  orderState,
  setFilter,
  setOrderBy,
  shrunk
}) {
  const buttonProps = useMemo(() => ({
    intent: hasFilter ? "primary" : "default",
    distinction: "seamless",
    size: "small",
    children: /* @__PURE__ */ createElement(Icon, {
      blueprintIcon: "filter",
      alignWithLowercase: true,
      style: {
        opacity: hasFilter ? "1" : "0.5"
      }
    })
  }), [hasFilter]);
  return /* @__PURE__ */ createElement(TableHeaderCell, {
    scope: "col",
    justification: headerJustification,
    shrunk
  }, /* @__PURE__ */ createElement("span", {
    style: { display: "flex", justifyContent: "flex-start", gap: ".25em" }
  }, /* @__PURE__ */ createElement("span", {
    onClick: (e) => setOrderBy(cycleOrderDirection(orderState?.direction ?? null), e.ctrlKey || e.metaKey),
    style: { cursor: "pointer" }
  }, header, "\xA0", orderState && /* @__PURE__ */ createElement(Fragment, null, {
    asc: ascOrderIcon ?? defaultAscIcon,
    desc: descOrderIcon ?? defaultDescIcon
  }[orderState.direction], orderState.index !== void 0 ? `(${orderState.index + 1})` : null)), filterRenderer && /* @__PURE__ */ createElement(Dropdown, {
    buttonProps,
    renderContent: ({ requestClose }) => /* @__PURE__ */ createElement(ActionableBox, {
      onRemove: () => {
        setFilter(void 0);
        requestClose();
      }
    }, /* @__PURE__ */ createElement(Box, {
      heading: /* @__PURE__ */ createElement(Fragment, null, "Filter: ", header)
    }, createElement(filterRenderer, {
      filter: filterArtifact === void 0 ? emptyFilterArtifact : filterArtifact,
      setFilter,
      environment
    })))
  })));
}
const defaultAscIcon = /* @__PURE__ */ createElement(Icon, {
  blueprintIcon: "caret-up",
  size: "small",
  alignWithLowercase: true
});
const defaultDescIcon = /* @__PURE__ */ createElement(Icon, {
  blueprintIcon: "caret-down",
  size: "small",
  alignWithLowercase: true
});
export { DataGridHeaderCell };
//# sourceMappingURL=DataGridHeaderCell.js.map
