import { Icon, TableHeaderCell, Dropdown, ActionableBox, Box } from "@contember/ui";
import { useMemo, createElement } from "react";
import { cycleOrderDirection } from "./DataGridOrderDirection.js";
import { jsxDEV, Fragment } from "react/jsx-dev-runtime";
var _jsxFileName = "/__w/interface/interface/packages/admin/src/components/bindingFacade/collections/DataGrid/base/DataGridHeaderCell.tsx";
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__ */ jsxDEV(Icon, {
      blueprintIcon: "filter",
      alignWithLowercase: true,
      style: {
        opacity: hasFilter ? "1" : "0.5"
      }
    }, void 0, false, {
      fileName: _jsxFileName,
      lineNumber: 51,
      columnNumber: 4
    }, this)
  }), [hasFilter]);
  return /* @__PURE__ */ jsxDEV(TableHeaderCell, {
    scope: "col",
    justification: headerJustification,
    shrunk,
    children: /* @__PURE__ */ jsxDEV("span", {
      style: {
        display: "flex",
        justifyContent: "flex-start",
        gap: ".25em"
      },
      children: [/* @__PURE__ */ jsxDEV("span", {
        onClick: (e) => setOrderBy(cycleOrderDirection(orderState?.direction ?? null), e.ctrlKey || e.metaKey),
        style: {
          cursor: "pointer"
        },
        children: [header, "\xA0", orderState && /* @__PURE__ */ jsxDEV(Fragment, {
          children: [{
            asc: ascOrderIcon ?? defaultAscIcon,
            desc: descOrderIcon ?? defaultDescIcon
          }[orderState.direction], orderState.index !== void 0 ? `(${orderState.index + 1})` : null]
        }, void 0, true)]
      }, void 0, true, {
        fileName: _jsxFileName,
        lineNumber: 64,
        columnNumber: 5
      }, this), filterRenderer && /* @__PURE__ */ jsxDEV(Dropdown, {
        buttonProps,
        renderContent: ({
          requestClose
        }) => /* @__PURE__ */ jsxDEV(ActionableBox, {
          onRemove: () => {
            setFilter(void 0);
            requestClose();
          },
          children: /* @__PURE__ */ jsxDEV(Box, {
            heading: /* @__PURE__ */ jsxDEV(Fragment, {
              children: ["Filter: ", header]
            }, void 0, true),
            children: createElement(filterRenderer, {
              filter: filterArtifact === void 0 ? emptyFilterArtifact : filterArtifact,
              setFilter,
              environment
            })
          }, void 0, false, {
            fileName: _jsxFileName,
            lineNumber: 86,
            columnNumber: 9
          }, this)
        }, void 0, false, {
          fileName: _jsxFileName,
          lineNumber: 80,
          columnNumber: 8
        }, this)
      }, void 0, false, {
        fileName: _jsxFileName,
        lineNumber: 77,
        columnNumber: 6
      }, this)]
    }, void 0, true, {
      fileName: _jsxFileName,
      lineNumber: 63,
      columnNumber: 4
    }, this)
  }, void 0, false, {
    fileName: _jsxFileName,
    lineNumber: 62,
    columnNumber: 3
  }, this);
}
const defaultAscIcon = /* @__PURE__ */ jsxDEV(Icon, {
  blueprintIcon: "caret-up",
  size: "small",
  alignWithLowercase: true
}, void 0, false, {
  fileName: _jsxFileName,
  lineNumber: 102,
  columnNumber: 24
}, void 0);
const defaultDescIcon = /* @__PURE__ */ jsxDEV(Icon, {
  blueprintIcon: "caret-down",
  size: "small",
  alignWithLowercase: true
}, void 0, false, {
  fileName: _jsxFileName,
  lineNumber: 103,
  columnNumber: 25
}, void 0);
export {
  DataGridHeaderCell
};
//# sourceMappingURL=DataGridHeaderCell.js.map
