/*!
 * Copyright (c) Microsoft. All rights reserved.
 * Licensed under the MIT license. See LICENSE file in the project.
 */ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import styled from '@essex/styled-components';
import { memo, useMemo } from 'react';
import { HEIGHT } from './ArqueroTableHeader.constants.js';
import { useColorDefaults, useColumnCounts, useRowCounts } from './hooks/index.js';
import { TableName } from './TableName.js';
export const ArqueroTableHeader = /*#__PURE__*/ memo(function ArqueroTableHeader({ table , name , showRowCount =true , showColumnCount =true , commandBar , farCommandBar , visibleColumns , onRenameTable , background , color ,  }) {
    const { background: bg , color: clr  } = useColorDefaults({
        color,
        background
    });
    const groupCount = useMemo(()=>{
        return table.isGrouped() ? table.groups().size : 0;
    }, [
        table
    ]);
    const columnCounts = useColumnCounts(table, visibleColumns);
    const rowCounts = useRowCounts(table);
    return /*#__PURE__*/ _jsxs(Header, {
        background: bg,
        color: clr,
        children: [
            /*#__PURE__*/ _jsx(Left, {
                children: commandBar
            }),
            /*#__PURE__*/ _jsxs(Middle, {
                hasFarCommandBar: !!farCommandBar,
                children: [
                    name ? /*#__PURE__*/ _jsx(TableName, {
                        onRenameTable: onRenameTable,
                        name: name,
                        color: clr
                    }) : null,
                    showRowCount === true ? /*#__PURE__*/ _jsx(H3, {
                        children: `${rowCounts.visible} row${rowCounts.visible !== 1 ? 's' : ''}${rowCounts.hidden > 0 ? ` (${rowCounts.hidden} filtered)` : ''}`
                    }) : null,
                    showColumnCount === true ? /*#__PURE__*/ _jsx(H3, {
                        children: `${columnCounts.visible} col${columnCounts.visible !== 1 ? 's' : ''}${columnCounts.hidden > 0 ? ` (${columnCounts.hidden} hidden)` : ''}`
                    }) : null,
                    groupCount ? /*#__PURE__*/ _jsxs(H3, {
                        children: [
                            groupCount,
                            " groups"
                        ]
                    }) : null
                ]
            }),
            farCommandBar && /*#__PURE__*/ _jsx(Right, {
                children: farCommandBar
            })
        ]
    });
});
const Header = styled.div`
	height: ${HEIGHT}px;
	width: 100%;
	padding: 0 8px 0 0;
	background-color: ${({ background  })=>background};
	color: ${({ color  })=>color};
	position: relative;
	box-sizing: border-box;
	display: flex;
	align-items: center;
	justify-content: space-between;
`;
const H3 = styled.h3`
	font-weight: normal;
	font-size: 0.8em;
`;
const Left = styled.div`
	flex: 1;
	display: flex;
	justify-content: flex-start;
`;
const Middle = styled.div`
	flex: 2;
	display: flex;
	justify-content: ${({ hasFarCommandBar  })=>hasFarCommandBar ? 'center' : 'end'};
	align-items: center;
	gap: 8px;
`;
const Right = styled.div`
	flex: 1;
	display: flex;
	justify-content: flex-end;
`;
