import type {ContentListItem} from "../type/content.types.ts";
import type {SearchParams} from "../../../../type/searchParams.ts";
import {CheckBox} from "../../../component/checkbox/CheckBox.tsx";
import {getTableRowNumber} from "../../../component/table/getTableRowNumber.ts";

interface ContentListTableRowProps {
    item: ContentListItem
    index: number;
    searchParams: SearchParams;
    totalItems: number
    currentPage: number
    checked: boolean
    onCheck: (id: string, checked: boolean) => void
    onDetail: (cntId: string, cntDtId: string) => void
    onPreview: (cntId: string, cntDtId: string) => void
}

export const ContentListTableRow = (
    {
        item,
        index,
        searchParams,
        totalItems,
        currentPage,
        checked,
        onCheck,
        onDetail,
        onPreview
    }: ContentListTableRowProps
) => {

    const rowNumber = getTableRowNumber({
        searchParams,
        totalItems,
        currentPage,
        index
    })

    const cntId = item.cntId;
    const cntDtId = item.cntDtId;

    return (
        <tr>
            <td>
                <CheckBox id={`contentCheckList_${cntId}`}
                          name={'checkList'}
                          value={cntId}
                          checked={checked}
                          onChange={(nextChecked => onCheck(cntId, nextChecked))}/>
            </td>
            <td>
                {rowNumber}
            </td>

            <td>
                <button onClick={() => onDetail(cntId, cntDtId)}>
                    {item.cntName}
                </button>
            </td>
            <td>
                {item.menuNm}
            </td>
            <td>
                {item.registerId}
            </td>
            <td>
                {item.registPnttm}
            </td>
            <td>
                <button className={"btn line primary small"} onClick={() => onPreview(cntId, cntDtId)}>
                    미리보기
                </button>
            </td>
        </tr>
    )
}
