import {useParams} from "react-router-dom";
import {PageHeader} from "../../../component/PageHeader.tsx";
import {useLoadingToast} from "../../../hook/useLoadingToast.ts";
import {ActionButtonFormGroup} from "../../../component/button/ActionButtonFormGroup.tsx";
import {BoardFormTable} from "../components/master/BoardFormTable.tsx";
import {useBoardForm} from "../hook/page/useBoardForm.ts";

export const BoardFormPage = () => {
    const {bbsId = ''} = useParams();
    const {
        mode,
        title,
        breadcrumb,
        form,
        typeList,
        isLoading,
        error,
        isPending,
        handleChange,
        handleCreate,
        handleUpdate,
        handleDelete,
        handleList,
    } = useBoardForm(bbsId);

    useLoadingToast({
        isLoading,
        error,
        successMessage: '데이터 조회가 완료되었습니다.'
    });

    return (
        <>
            <PageHeader title={title} breadcrumb={breadcrumb} homeUrl="#"/>
            <BoardFormTable
                form={form}
                typeList={typeList}
                onChange={handleChange}
            />
            <ActionButtonFormGroup
                mode={mode}
                disabled={isPending}
                onDelete={handleDelete}
                onCreate={handleCreate}
                onUpdate={handleUpdate}
                onList={handleList}
            />
        </>
    );
};
