import { useState } from "preact/hooks";
import { useTranslation } from "react-i18next";
import { Link } from "preact-router";
import { RiPictureInPictureExitFill, RiFullscreenFill } from "react-icons/ri";
import { IoCodeSlashSharp,IoChevronBackSharp,IoChevronForwardSharp, IoReloadSharp } from "react-icons/io5";
import { FaXmark } from "react-icons/fa6";
interface ProxyFrame extends HTMLElement {
contentWindow: any;
contentDocument: any;
}
export function IframeHeader(props: { url: string }) {
const { t } = useTranslation();
const [showPopout, setShowPopout] = useState(false);
const [showFullScreen, setFullScreen] = useState(false);
if (showPopout) {
window.location.replace(props.url);
}
if (showFullScreen) {
document.getElementById("iframe").requestFullscreen();
setFullScreen(false);
}
return (
{" "}
{t("header.title")}{" "}
{
const proxyFrame: ProxyFrame | null = document.getElementById("iframe") as ProxyFrame;
proxyFrame.contentWindow.history.back();
}}
/>
{
const proxyFrame: ProxyFrame | null = document.getElementById("iframe") as ProxyFrame;
proxyFrame.contentWindow.location.reload();
}}
/>
{
const proxyFrame: ProxyFrame | null = document.getElementById("iframe") as ProxyFrame;
proxyFrame.contentWindow.history.forward();
}}
/>
{
const proxyFrame: ProxyFrame | null = document.getElementById(
"iframe"
) as ProxyFrame;
if (!proxyFrame) return;
const proxyWindow = proxyFrame.contentWindow;
const proxyDocument = proxyFrame.contentDocument;
if (!proxyWindow || !proxyDocument) return;
if (proxyWindow.eruda?._isInit) {
proxyWindow.eruda.destroy();
} else {
let script = proxyDocument.createElement("script");
script.src = "https://cdn.jsdelivr.net/npm/eruda";
script.onload = function () {
if (!proxyWindow) return;
proxyWindow.eruda.init();
proxyWindow.eruda.show();
};
proxyDocument.head.appendChild(script);
}
}}
/>
setShowPopout(true)}
/>
setFullScreen(true)}
/>
);
}