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 {
		selectedItems,
		showBulk,
		checkState,
		selectItems,
		selectAllItems,
		totalItems,
		isScrolling,
		sortItems,
		filterItems,
		sortedListStatus,
		filterValues,
		setHoverCheck,
		featuredCategory,
		bulkActions,
		siteID,
		isLoading,
	} = props;

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

interface IProps {
	showBulk: boolean;
	checkState: Record<string, boolean>;
	selectItems: () => void;
	selectAllItems: () => void;
	totalItems: number;
	isScrolling: boolean;
	featuredCategory?: { value: string; label: string };
	bulkActions: { icon: string; text: string; action: () => void }[];
	sortItems: (orderPointer: IQueryValue[], isAscending: boolean) => void;
	sortedListStatus: { isAscending: boolean; sortedByTitle: boolean; sortedByDate: boolean };
	filterValues: Record<string, IQueryValue[]>;
	siteID: number | null;
	filterItems: (filterPointer: string, filtersSelected: IQueryValue[]) => void;
	setHoverCheck: (state: boolean) => void;
	selectedItems: IBulkSelectedItems;
	isLoading: boolean;
}

export default BulkHeader;
