import type {BoardArticleListItem, BoardArticleSearchParams} from "../../type/board.types.ts";
import {EmptyRow} from "../../../../component/EmptyRow.tsx";
import {BoardArticleListTableHeader} from "./BoardArticleListTableHeader.tsx";
import {BoardArticleListTableRow} from "./BoardArticleListTableRow.tsx";

type BoartArticleListTableProps = {

    items: BoardArticleListItem[];
    params: BoardArticleSearchParams;
    onChange: (params: BoardArticleSearchParams) => void;
    isAllChecked: boolean;
    isPartiallyChecked: boolean;
    isChecked: (id: string) => boolean;
    onCheck: (id: string, checked: boolean) => void;
    onCheckAll: (checked: boolean) => void;
    totalItems: number
    currentPage: number
    totalPages: number
}

export const BoartArticleListTable = ({
                                          items,
                                          params,
                                          onChange,
                                          isAllChecked,
                                          isPartiallyChecked,
                                          isChecked,
                                          onCheck,
                                          onCheckAll,
                                          totalItems,
                                          currentPage,
                                          totalPages
                                      }: BoartArticleListTableProps) => {

    return (
        <div className={"table table_type_cols"}>
            <table>
                <BoardArticleListTableHeader
                    params={params}
                    onChange={onChange}
                    checked={isAllChecked}
                    indeterminate={isPartiallyChecked}
                    onCheckAll={onCheckAll}
                />
                <tbody>
                {items.length > 0 ?
                        items.map((item, index) => (
                            <BoardArticleListTableRow
                                key={item.nttId}
                                item={item}
                                index={index}
                                searchParams={params}
                                totalItems={totalItems}
                                currentPage={currentPage}
                                totalPages={totalPages}
                                checked={isChecked(item.nttId)}
                                onCheck={onCheck}
                            />
                        )) :
                    (<EmptyRow colSpan={8}/>)
                }
                </tbody>
            </table>
        </div>
    )

}
