import firefoxPrintFix from "@insite/client-framework/Common/Utilities/printFirefox";

const openPrintDialog = () => {
    const firefoxPrintCallback = firefoxPrintFix();
    if (document.queryCommandSupported("print") && !iOS()) {
        document.execCommand("print", false);
    } else {
        window.print();
    }
    firefoxPrintCallback();
};

const iOS = () => {
    return (
        ["iPad Simulator", "iPhone Simulator", "iPod Simulator", "iPad", "iPhone", "iPod"].includes(
            navigator.platform,
        ) ||
        // iPad on iOS 13 detection
        (navigator.userAgent.includes("Mac") && "ontouchend" in document)
    );
};

export default openPrintDialog;
