import { useDealPageContext } from "../../../contexts/DealPageContext.tsx";


const useShippingQrs = () => {
    const { selectedDeal: deal } = useDealPageContext();

    const basePdfUrl = `${import.meta.env.VITE_API_URL}/shipping/pdf`;

    const getPdf = (url: string) => {
        if (!deal) return;
        const pdfWindow = window.open(url);
        if (!pdfWindow) return;
        pdfWindow.print();
    };

    const onGetDealQrPdfClick = () => {
        getPdf(`${basePdfUrl}/deal/${deal?.id}`);
    };

    const onGetPalletsPdfClick = () => {
        getPdf(`${basePdfUrl}/pallets/${deal?.id}`);
    };

    const onGetBoxesPdfClick = () => {
        getPdf(`${basePdfUrl}/boxes/${deal?.id}`);
    };

    return {
        onGetDealQrPdfClick,
        onGetPalletsPdfClick,
        onGetBoxesPdfClick,
    };
};

export default useShippingQrs;
