import type {BoardListItem} from "../type/board.types.ts";
import type {SearchParams} from "../../../../type/searchParams.ts";
import {EmptyRow} from "../../../component/EmptyRow.tsx";
import {BoardListTableHeader} from "./BoardListTableHeader.tsx";
import {BoardListTableRow} from "./BoardListTableRow.tsx";

interface BoardListTableProps {
    items: BoardListItem[]
    params: SearchParams
    onChange: (params: SearchParams) => void
    totalCount: number
    currentPage: number
    recordPerPage: number
}

export function BoardListTable({items, params, onChange, totalCount, currentPage, recordPerPage}: BoardListTableProps) {
    if (!items.length) {
        return <EmptyRow colSpan={9}/>
    }

    return (
        <div className="table table_type_cols">
            <table>
                <BoardListTableHeader params={params} onChange={onChange}/>
                <tbody>
                {items.map((item, index) => (
                    <BoardListTableRow
                        key={item.bbsId}
                        item={item}
                        index={index}
                        searchParams={params}
                        totalCount={totalCount}
                        currentPage={currentPage}
                        recordPerPage={recordPerPage}
                    />
                ))}
                </tbody>
            </table>
        </div>
    )
}
