import { useEffect, useState } from 'react';
import { PATHS } from '@/shared/constants/paths';
import { useNavigate } from '@/shared/lib/hooks/use-navigate';
import { PaymentTab } from '@/entities/payment/ui/payment-tab';
import { DataNotificationWrap } from '@/entities/payment/ui/data-notification-wrap';
import { PaymentNonCardResponse, PaymentNotificationDataResponse, PaymentTabKeys } from '@/entities/payment/model/types';
import { usePaymentNotificationDataMutation } from '@/entities/payment/api/use-payment-notification-data-mutation';
import { HeaderType } from '@/entities/common/model/types';
import { 
	useSetHeaderTitle,
	useSetHeaderType,
	useSetFooterMode,
  useSetOnBack
} from '@/widgets/sub-layout/use-sub-layout';

export const DataNotificationPage = () => {
  const { navigate } = useNavigate();

  const { mutateAsync: paymentNotificationData } = usePaymentNotificationDataMutation();
    
  const [activeTab, setActiveTab] = useState<PaymentTabKeys>(PaymentTabKeys.DataNotification);
  const [mid, setMid] = useState<string>('nictest00g');
  const [gid, setGid] = useState<string>('nictest00g');
  const [paymentNotificationDataResult, setPaymentNotificationDataResult] = useState<PaymentNotificationDataResponse>();

  useSetHeaderTitle('결제 관리');
  useSetHeaderType(HeaderType.LeftArrow);
  useSetFooterMode(true);
  useSetOnBack(() => {
    navigate(PATHS.home);
  });

  const callPaymentNotificationData = () => {
    let params = {
      mid: mid,
      gid: gid
    };
    
    paymentNotificationData(params).then((rs) => {
      console.log(rs);
      setPaymentNotificationDataResult(rs);
    });
  };

  useEffect(() => {
    callPaymentNotificationData();
  }, []);

  return (
    <>
      <main>
        <div className="tab-content">
          <div className="tab-pane pt-46 active">
            <PaymentTab activeTab={ activeTab }></PaymentTab>
            <DataNotificationWrap
              paymentNotificationData={ paymentNotificationDataResult }
            ></DataNotificationWrap>
          </div>
        </div>
      </main>
    </>
  );
};