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;
    totalItems: number
    currentPage: number
    totalPages: number
}

export const BoartArticleListTable = ({
                                          items,
                                          params,
                                          onChange,
                                          totalItems,
                                          currentPage,
                                          totalPages
                                      }: BoartArticleListTableProps) => {

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

}