import { useCardPageContext } from "../../../../../pages/CardsPage/contexts/CardPageContext.tsx";


const useShippingQrs = () => {
    const { selectedCard: card } = useCardPageContext();

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

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

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

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

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

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

export default useShippingQrs;
