import { BulkSelectionOptions } from "@ax/components";
import { itemLabel } from "@ax/constants";
import type { IBulkSelectedItems } from "@ax/hooks";
import type { IQueryValue } from "@ax/types";

import TableHeader from "./TableHeader";

const BulkHeader = (props: IProps): JSX.Element => {
	const {
		showBulk,
		checkState,
		selectItems,
		selectAllItems,
		totalItems,
		isScrolling,
		bulkActions,
		filterItems,
		filterValues,
		setHoverCheck,
		selectedItems,
		isLoading,
	} = props;

	return showBulk ? (
		<BulkSelectionOptions
			checkState={checkState}
			actions={bulkActions}
			selectItems={selectItems}
			totalItems={totalItems}
			selectedItems={selectedItems}
			isLoading={isLoading}
			itemLabel={itemLabel.CATEGORY}
		/>
	) : (
		<TableHeader
			totalItems={totalItems}
			selectAllItems={selectAllItems}
			isScrolling={isScrolling}
			filterItems={filterItems}
			filterValues={filterValues}
			setHoverCheck={setHoverCheck}
			checkState={checkState}
		/>
	);
};

interface IProps {
	showBulk: boolean;
	checkState: Record<string, boolean>;
	selectItems: () => void;
	selectAllItems: () => void;
	totalItems: number;
	isScrolling: boolean;
	bulkActions: { icon: string; text: string; action: () => void }[];
	filterValues: Record<string, IQueryValue[]>;
	filterItems: (filterPointer: string, filtersSelected: IQueryValue[]) => void;
	setHoverCheck: (state: boolean) => void;
	selectedItems: IBulkSelectedItems;
	isLoading: boolean;
}

export default BulkHeader;
