'use strict';

var jsxRuntime = require('../../../node_modules/.pnpm/react@18.2.0/node_modules/react/jsx-runtime.cjs');
var flex = require('../../flex/flex.cjs');
var dataTable_module = require('../data-table.module.css.cjs');
var button = require('../../button/button.cjs');
var popover = require('../../popover/popover.cjs');
var reactIcons_esm = require('../../../node_modules/.pnpm/@radix-ui_react-icons@1.3.0_react@18.2.0/node_modules/@radix-ui/react-icons/dist/react-icons.esm.cjs');
var useDataTable = require('../hooks/useDataTable.cjs');
var index = require('../utils/index.cjs');
var ordering = require('./ordering.cjs');
var grouping = require('./grouping.cjs');
var displayProperties = require('./display-properties.cjs');

function DisplaySettings() {
    const { table, updateTableQuery, tableQuery, defaultSort, onDisplaySettingsReset, } = useDataTable.useDataTable();
    const columns = table?.getAllColumns();
    const sortableColumns = columns
        ?.filter((col) => col.columnDef.enableSorting)
        ?.map((column) => {
        const id = column.id;
        return {
            label: column.columnDef.header || id,
            id: id,
        };
    });
    function onSortChange(columnId, order) {
        updateTableQuery((query) => {
            return {
                ...query,
                sort: [{ name: columnId, order }],
            };
        });
    }
    function onGroupChange(columnId, order) {
        updateTableQuery((query) => {
            return {
                ...query,
                group_by: [columnId],
                __group_by_sort: order,
            };
        });
    }
    function onReset() {
        onDisplaySettingsReset();
    }
    return (jsxRuntime.jsxRuntimeExports.jsxs(popover.Popover, { children: [jsxRuntime.jsxRuntimeExports.jsx(popover.Popover.Trigger, { asChild: true, children: jsxRuntime.jsxRuntimeExports.jsx(button.Button, { variant: "outline", color: "neutral", size: "small", leadingIcon: jsxRuntime.jsxRuntimeExports.jsx(reactIcons_esm.MixerHorizontalIcon, {}), children: "Display" }) }), jsxRuntime.jsxRuntimeExports.jsx(popover.Popover.Content, { className: dataTable_module.default["display-popover-content"], align: "end", children: jsxRuntime.jsxRuntimeExports.jsxs(flex.Flex, { direction: "column", children: [jsxRuntime.jsxRuntimeExports.jsxs(flex.Flex, { direction: "column", className: dataTable_module.default["display-popover-properties-container"], gap: 5, children: [jsxRuntime.jsxRuntimeExports.jsx(ordering.Ordering, { columnList: sortableColumns, onChange: onSortChange, value: tableQuery?.sort?.[0] || defaultSort }), jsxRuntime.jsxRuntimeExports.jsx(grouping.Grouping, { columns: columns, onChange: onGroupChange, value: tableQuery?.group_by?.[0] || index.defaultGroupOption.id })] }), jsxRuntime.jsxRuntimeExports.jsx(flex.Flex, { className: dataTable_module.default["display-popover-properties-container"], children: jsxRuntime.jsxRuntimeExports.jsx(displayProperties.DisplayProperties, { columns: columns }) }), jsxRuntime.jsxRuntimeExports.jsx(flex.Flex, { justify: "end", className: dataTable_module.default["display-popover-reset-container"], children: jsxRuntime.jsxRuntimeExports.jsx(button.Button, { variant: "text", onClick: onReset, children: "Reset to default" }) })] }) })] }));
}

exports.DisplaySettings = DisplaySettings;
//# sourceMappingURL=display-settings.cjs.map
