import {useAuthorRoleListPage} from "../hook/page/useAuthorRoleListPage.ts";
import {useSearchParams} from "react-router-dom";
import {PageHeader} from "../../../component/PageHeader.tsx";
import {ListSearchForm} from "../../../component/ListSearchForm.tsx";
import {Pagination} from "../../../component/pagination/Pagination.tsx";
import {AuthorRoleListTable} from "../components/author/role/AuthorRoleListTable.tsx";
import {useLoadingToast} from "../../../hook/useLoadingToast.ts";

export const AuthorRoleListPage = () => {
    const [urlParams] = useSearchParams();
    const authorCode = urlParams.get("authorCode") || "";
    const authorNm = urlParams.get("authorNm") || "";
    const {
        header,
        status,
        search,
        table,
        pagination,
    } = useAuthorRoleListPage(authorCode);

    useLoadingToast(status);

    return (
        <>
            <PageHeader {...header}/>
            <ListSearchForm
                {...search}
                totalLabel={`(${authorCode}:${authorNm}) 총 건수`}
            />
            <AuthorRoleListTable {...table}/>
            <Pagination {...pagination}/>
        </>
    );
}
