import type {SearchParams} from "../../../../../type/searchParams.ts";
import {CheckBox} from "../../../../component/checkbox/CheckBox.tsx";
import {useTableSort} from "../../../../hook/useTableSort.ts";
import {SortableHeaderCell} from "../../../../component/table/SortableHeaderCell.tsx";

interface BoardListTableHeaderProps {
    params: SearchParams;
    onChange: (params: SearchParams) => void
    checked: boolean
    indeterminate: boolean
    onCheckAll: (checked: boolean) => void
}

export function BoardListTableHeader({
                                         params,
                                         onChange,
                                         checked,
                                         indeterminate,
                                         onCheckAll
                                     }: BoardListTableHeaderProps) {
    const {handleSort, getSortIcon, isSorted} = useTableSort(params, onChange);

    return (
        <>
            <colgroup>
                <col style={{width: '40px'}}/>
                <col style={{width: '6%'}}/>
                <col style={{width: '18%'}}/>
                <col style={{width: '18%'}}/>
                <col style={{width: '10%'}}/>
                <col style={{width: '10%'}}/>
                <col style={{width: '10%'}}/>
                <col style={{width: '6%'}}/>
                <col style={{width: '20%'}}/>
            </colgroup>

            <thead>
            <tr>
                <th>
                    <CheckBox
                        id="boardCheckAll"
                        name="checkAll"
                        checked={checked}
                        indeterminate={indeterminate}
                        onChange={onCheckAll}
                    />
                </th>
                <th>번호</th>
                <SortableHeaderCell
                    field="BBS_NM"
                    active={isSorted('BBS_NM')}
                    icon={getSortIcon('BBS_NM')}
                    onSort={handleSort}
                >
                    게시판명
                </SortableHeaderCell>
                <SortableHeaderCell
                    field="MENU_NM"
                    active={isSorted('MENU_NM')}
                    icon={getSortIcon('MENU_NM')}
                    onSort={handleSort}
                >
                    연결 메뉴
                </SortableHeaderCell>
                <SortableHeaderCell
                    field="TOTCNT"
                    active={isSorted('TOTCNT')}
                    icon={getSortIcon('TOTCNT')}
                    onSort={handleSort}
                >
                    댓글 / 글수
                </SortableHeaderCell>
                <SortableHeaderCell
                    field="BBS_TY_CODE_NM"
                    active={isSorted('BBS_TY_CODE_NM')}
                    icon={getSortIcon('BBS_TY_CODE_NM')}
                    onSort={handleSort}
                >
                    게시판유형
                </SortableHeaderCell>
                <SortableHeaderCell
                    field="FRST_REGIST_PNTTM"
                    active={isSorted('FRST_REGIST_PNTTM')}
                    icon={getSortIcon('FRST_REGIST_PNTTM')}
                    onSort={handleSort}
                >
                    생성일
                </SortableHeaderCell>
                <SortableHeaderCell
                    field="USE_AT"
                    active={isSorted('USE_AT')}
                    icon={getSortIcon('USE_AT')}
                    onSort={handleSort}
                >
                    사용여부
                </SortableHeaderCell>
                <th>게시판 관리</th>
            </tr>
            </thead>
        </>
    )
}
