import { Icon, Dropdown, Box, Table, TableRow, TableHeaderCell, TableCell, Button, ButtonGroup } from "@contember/ui";
import { useMemo, Fragment as Fragment$1, createElement } from "react";
import { jsxDEV, Fragment } from "react/jsx-dev-runtime";
import { EmptyMessage } from "../../helpers/EmptyMessage.js";
var _jsxFileName = "/__w/interface/interface/packages/admin/src/components/bindingFacade/collections/DataGrid/base/DataGridFullFilters.tsx";
function DataGridFullFilters({
  desiredState,
  environment,
  formatMessage,
  setFilter
}) {
  const remainingColumns = Array.from(desiredState.columns).filter(([key, column]) => column.enableFiltering !== false && !(key in desiredState.filterArtifacts));
  const hasAnyFilters = Object.keys(desiredState.filterArtifacts).length > 0;
  const columnFilteringButtonProps = useMemo(() => ({
    intent: hasAnyFilters ? "primary" : "default",
    distinction: "seamless",
    children: /* @__PURE__ */ jsxDEV(Fragment, {
      children: [/* @__PURE__ */ jsxDEV(Icon, {
        blueprintIcon: "filter",
        alignWithLowercase: true,
        style: {
          marginRight: "0.2em",
          opacity: hasAnyFilters ? "1" : "0.8"
        }
      }, void 0, false, {
        fileName: _jsxFileName,
        lineNumber: 38,
        columnNumber: 5
      }, this), formatMessage("dataGrid.columnFiltering.showMenuButton.text")]
    }, void 0, true)
  }), [formatMessage, hasAnyFilters]);
  const filterButtonBrops = useMemo(() => ({
    distinction: "seamless",
    flow: "block",
    style: {
      marginTop: hasAnyFilters ? "1em" : 0
    },
    children: /* @__PURE__ */ jsxDEV(Fragment, {
      children: [/* @__PURE__ */ jsxDEV(Icon, {
        alignWithLowercase: true,
        blueprintIcon: "add",
        style: {
          marginRight: "0.2em"
        }
      }, void 0, false, {
        fileName: _jsxFileName,
        lineNumber: 57,
        columnNumber: 5
      }, this), formatMessage("dataGrid.columnFiltering.addFilterButton.text")]
    }, void 0, true)
  }), [formatMessage, hasAnyFilters]);
  return /* @__PURE__ */ jsxDEV(Dropdown, {
    alignment: "end",
    buttonProps: columnFilteringButtonProps,
    renderContent: ({
      update: updateOuterDropdown
    }) => /* @__PURE__ */ jsxDEV(Box, {
      heading: formatMessage("dataGrid.columnFiltering.heading"),
      children: [hasAnyFilters || /* @__PURE__ */ jsxDEV(EmptyMessage, {
        children: formatMessage("dataGrid.columnFiltering.emptyMessage.text")
      }, void 0, false, {
        fileName: _jsxFileName,
        lineNumber: 69,
        columnNumber: 24
      }, this), hasAnyFilters && /* @__PURE__ */ jsxDEV(Table, {
        tableHead: /* @__PURE__ */ jsxDEV(TableRow, {
          children: [/* @__PURE__ */ jsxDEV(TableHeaderCell, {
            scope: "col",
            justification: "justifyStart",
            shrunk: true,
            children: formatMessage("dataGrid.columnFiltering.columnColumn.text")
          }, void 0, false, {
            fileName: _jsxFileName,
            lineNumber: 74,
            columnNumber: 10
          }, this), /* @__PURE__ */ jsxDEV(TableHeaderCell, {
            scope: "col",
            justification: "justifyStart",
            children: formatMessage("dataGrid.columnFiltering.filterColumn.text")
          }, void 0, false, {
            fileName: _jsxFileName,
            lineNumber: 77,
            columnNumber: 10
          }, this), /* @__PURE__ */ jsxDEV(TableHeaderCell, {
            scope: "col",
            shrunk: true,
            children: "\xA0"
          }, void 0, false, {
            fileName: _jsxFileName,
            lineNumber: 80,
            columnNumber: 10
          }, this)]
        }, void 0, true, {
          fileName: _jsxFileName,
          lineNumber: 73,
          columnNumber: 9
        }, this),
        children: Array.from(Object.entries(desiredState.filterArtifacts), ([key, filterArtifact]) => {
          const column = desiredState.columns.get(key);
          const filterRenderer = column.enableFiltering !== false ? column.filterRenderer : void 0;
          if (!filterRenderer) {
            return /* @__PURE__ */ jsxDEV(Fragment$1, {}, key, false, {
              fileName: _jsxFileName,
              lineNumber: 91,
              columnNumber: 17
            }, this);
          }
          return /* @__PURE__ */ jsxDEV(TableRow, {
            children: [/* @__PURE__ */ jsxDEV(TableCell, {
              justification: "justifyStart",
              children: column.header
            }, void 0, false, {
              fileName: _jsxFileName,
              lineNumber: 96,
              columnNumber: 11
            }, this), /* @__PURE__ */ jsxDEV(TableCell, {
              children: createElement(filterRenderer, {
                filter: filterArtifact,
                setFilter: (newArtifact) => setFilter(key, newArtifact),
                environment
              })
            }, void 0, false, {
              fileName: _jsxFileName,
              lineNumber: 97,
              columnNumber: 11
            }, this), /* @__PURE__ */ jsxDEV(TableCell, {
              shrunk: true,
              justification: "justifyEnd",
              children: /* @__PURE__ */ jsxDEV(Button, {
                onClick: () => {
                  updateOuterDropdown();
                  setFilter(key, void 0);
                },
                distinction: "seamless",
                size: "small",
                bland: true,
                children: /* @__PURE__ */ jsxDEV(Icon, {
                  blueprintIcon: "trash",
                  size: "small"
                }, void 0, false, {
                  fileName: _jsxFileName,
                  lineNumber: 114,
                  columnNumber: 13
                }, this)
              }, void 0, false, {
                fileName: _jsxFileName,
                lineNumber: 105,
                columnNumber: 12
              }, this)
            }, void 0, false, {
              fileName: _jsxFileName,
              lineNumber: 104,
              columnNumber: 11
            }, this)]
          }, key, true, {
            fileName: _jsxFileName,
            lineNumber: 95,
            columnNumber: 10
          }, this);
        })
      }, void 0, false, {
        fileName: _jsxFileName,
        lineNumber: 71,
        columnNumber: 7
      }, this), !!remainingColumns.length && /* @__PURE__ */ jsxDEV(Dropdown, {
        alignment: "center",
        buttonProps: filterButtonBrops,
        children: ({
          requestClose
        }) => /* @__PURE__ */ jsxDEV(ButtonGroup, {
          orientation: "vertical",
          children: remainingColumns.map(([key, column]) => /* @__PURE__ */ jsxDEV(Button, {
            distinction: "seamless",
            flow: "generousBlock",
            justification: "justifyStart",
            onClick: () => {
              requestClose();
              updateOuterDropdown();
              if (column.enableFiltering === false) {
                return;
              }
              setFilter(key, column.emptyFilter);
            },
            children: column.header
          }, key, false, {
            fileName: _jsxFileName,
            lineNumber: 130,
            columnNumber: 11
          }, this))
        }, void 0, false, {
          fileName: _jsxFileName,
          lineNumber: 128,
          columnNumber: 9
        }, this)
      }, void 0, false, {
        fileName: _jsxFileName,
        lineNumber: 123,
        columnNumber: 7
      }, this)]
    }, void 0, true, {
      fileName: _jsxFileName,
      lineNumber: 68,
      columnNumber: 5
    }, this)
  }, void 0, false, {
    fileName: _jsxFileName,
    lineNumber: 64,
    columnNumber: 3
  }, this);
}
export {
  DataGridFullFilters
};
//# sourceMappingURL=DataGridFullFilters.js.map
