import { useEffect, useState } from 'react';
import { useLocation } from 'react-router';
import { PATHS } from '@/shared/constants/paths';
import { useNavigate } from '@/shared/lib/hooks/use-navigate';
import { useBillingDetailMutation } from '@/entities/transaction/api/use-billing-detail-mutation';
import { BillingInfoWrap } from '@/entities/transaction/ui/info-wrap/billing-info-wrap';
import { HeaderType } from '@/entities/common/model/types';
import { 
  TransactionCategory,
  BillingDetailParams,
  BillingDetailResponse,
  BillingInfo
} from '@/entities/transaction/model/types';
import {
  useSetOnBack, 
  useSetHeaderTitle,
  useSetHeaderType,
  useSetFooterMode
} from '@/widgets/sub-layout/use-sub-layout';
import { NumericFormat } from 'react-number-format';

export const BillingDetailPage = () => {
  const { navigate } = useNavigate();
  const location = useLocation();
    
  const [billingInfo, setBillingInfo] = useState<BillingInfo>();
  
  useSetHeaderTitle('빌링 상세');
  useSetHeaderType(HeaderType.RightClose);
  useSetOnBack(() => {
    navigate(PATHS.transaction.billing.list);
  });
  useSetFooterMode(false);

  const { mutateAsync: billingDetail } = useBillingDetailMutation();
    
  const callDetail = () => {
    let billingDetailParams: BillingDetailParams = {
      billKey: location?.state.billKey
    };
    billingDetail(billingDetailParams).then((rs: BillingDetailResponse) => {
      setBillingInfo(rs);
    });
  };
  useEffect(() => {
    callDetail();
  }, []);
  
  return (
    <>
      <main>
        <div className="tab-content">
          <div className="tab-pane sub active">
            <div className="option-list">
              <div className="txn-detail">
                <div className="txn-num-group">
                  <div className="txn-amount">
                    <div className="value">
                      <NumericFormat
                        value={ 100000000 } 
                        thousandSeparator
                        displayType="text"
                      ></NumericFormat>
                      <span className="unit">원</span>
                    </div>
                    <div className="txn-mid">
                      <span className="value">{ 'nitnitni' }</span>
                    </div>
                  </div>

                </div>
                <div className="txn-divider"></div>
                <BillingInfoWrap
                  billingInfo={ billingInfo }
                ></BillingInfoWrap>
              </div>
            </div>
          </div>
        </div>
      </main>
    </>
  );
};