import {ReactNode, useEffect} from 'react';
import {createPortal} from "react-dom";

type PrintProps = {
    children: ReactNode
    unprint: () => void
}


/**
 * Wrapper components for all Print Components
 * opens the print browser window and prints the child compoment
 */

const Print = ({children, unprint}: PrintProps) => {

    useEffect(() => {

        setTimeout(() => {
            window.print()
            unprint()
        }, 150)

// eslint-disable-next-line react-hooks/exhaustive-deps
    }, [])


    return (
        createPortal(
            children
            , document.body)
    );
}

export default Print;
