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

type BoardArticleListTableProps = CheckableTableModel<BoardArticleListItem, BoardArticleSearchParams>;

export const BoardArticleListTable = ({
                                          items,
                                          params,
                                          onChange,
                                          check,
                                          pagination
                                      }: BoardArticleListTableProps) => {

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

}
