import { useEffect, useState } from 'react';
import { PATHS } from '@/shared/constants/paths';
import { useNavigate } from '@/shared/lib/hooks/use-navigate';
import { HeaderType } from '@/entities/common/model/types';
import {
    useSetHeaderTitle,
    useSetHeaderType,
    useSetFooterMode,
    useSetOnBack
} from '@/widgets/sub-layout/use-sub-layout';
import { AdditionalServiceCategory, DetailInfo, DetailResponse, ExtensionAccountHolderAuthDetailParams, TitleInfo } from '@/entities/additional-service/model/types';
import { TitleInfoWrap } from '@/entities/additional-service/ui/info-wrap/title-info-wrap';
import { useLocation } from 'react-router';
import { DetailInfoWrap } from '@/entities/additional-service/ui/info-wrap/detail-info-wrap';
import { useExtensionAccountHolderAuthDetailMutation } from '@/entities/additional-service/api/account-holder-auth/use-extension-account-holder-auth-deatil-mutation';

export const AccountHolderAuthDetailPage = () => {
    const { navigate } = useNavigate();
    const location = useLocation();

    const { mid, tid } = location.state || {};

    const [titleInfo, setTitleInfo] = useState<TitleInfo>();
    const [detailInfo, setDetailInfo] = useState<DetailInfo>();

    useSetHeaderTitle('계좌점유인증 상세');
    useSetHeaderType(HeaderType.LeftArrow);
    useSetFooterMode(false);
    useSetOnBack(() => {
        navigate(PATHS.additionalService.accountHolderAuth.list);
    });

    const { mutateAsync: accountHolderAuthDetail } = useExtensionAccountHolderAuthDetailMutation();

    const callDetail = () => {
        let accountHolderAuthDetailParams: ExtensionAccountHolderAuthDetailParams = {
            mid: mid,
            tid: tid
        }
        accountHolderAuthDetail(accountHolderAuthDetailParams).then((rs: DetailResponse) => {
            console.log("Detail Info: ", rs)
            setTitleInfo(rs.titleInfo);
            setDetailInfo(rs.detailInfo);
        });
    };
    useEffect(() => {
        callDetail();
    }, []);
    return (
        <>
            <main>
                <div className="tab-content">
                    <div className="tab-pane sub active">
                        <div className="pay-top">
                            <TitleInfoWrap
                                additionalServiceCategory={AdditionalServiceCategory.AccountHolderAuth}
                                titleInfo={titleInfo}
                            ></TitleInfoWrap>
                        </div>
                        <div className="pay-detail">
                            <div className="detail-divider"></div>
                            <DetailInfoWrap
                                additionalServiceCategory={AdditionalServiceCategory.AccountHolderAuth}
                                detailInfo={detailInfo}
                            ></DetailInfoWrap>
                        </div>
                    </div>
                </div>
            </main >
        </>
    )
}