'use client';

import Loader from '@/components/common/Loader';
import { party_requests } from '@/data/party/party.requests';
import useRequest from '@/hooks/useRequest';
import DashboardCreatePartyPage from '@/routes/private/parties-create/DashboardCreatePartyPage';
import { useParams } from 'next/navigation';
import React from 'react';

type Props = {};

const DashboardEditPartyPage = (props: Props) => {
    const params = useParams();
    const party_id = params.party_id as string;

    const getOneParty = useRequest(
        () => {
            return party_requests.find({ partyId: party_id });
        },
        {
            selectData(data) {
                return {
                    id: +party_id,
                    party_name: data.data.data.name,
                };
            },
        }
    );

    if (getOneParty.loading) {
        return <Loader p={8} size={96} />;
    }

    return (
        <>
            <DashboardCreatePartyPage initialValues={getOneParty.data!} />
        </>
    );
};

export default DashboardEditPartyPage;
