"use strict";
var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
var __read = (this && this.__read) || function (o, n) {
    var m = typeof Symbol === "function" && o[Symbol.iterator];
    if (!m) return o;
    var i = m.call(o), r, ar = [], e;
    try {
        while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
    }
    catch (error) { e = { error: error }; }
    finally {
        try {
            if (r && !r.done && (m = i["return"])) m.call(i);
        }
        finally { if (e) throw e.error; }
    }
    return ar;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var jsx_runtime_1 = require("react/jsx-runtime");
var antd_1 = require("antd");
var icon_1 = require("@cocalc/frontend/components/icon");
var react_1 = require("react");
var site_name_1 = __importDefault(require("components/share/site-name"));
var A_1 = __importDefault(require("components/misc/A"));
var misc_1 = require("@cocalc/util/misc");
function IFrame(_a) {
    var src0 = _a.src, appURL = _a.appURL, path = _a.path, style = _a.style, fullscreen0 = _a.fullscreen;
    var _b = __read((0, react_1.useState)(!!fullscreen0), 2), fullscreen = _b[0], setFullscreen = _b[1];
    var _c = __read((0, react_1.useState)(0), 2), reload = _c[0], setReload = _c[1];
    var iframeRef = (0, react_1.useRef)(null);
    var url = new URL("http://example.com" + src0);
    url.search += (url.search ? "&" : "") + "reload=".concat(reload);
    var src = url.pathname + url.search + url.hash;
    return ((0, jsx_runtime_1.jsxs)("div", __assign({ style: fullscreen
            ? {
                position: "fixed",
                top: 0,
                left: 0,
                width: "100vw",
                height: "100vh",
                zIndex: 1000,
                background: "white",
            }
            : __assign({ padding: "5px 15px", height: "70vh", border: "1px solid #ddd", borderRadius: "5px", boxShadow: "5px 5px 5px #eee", display: "flex", flexDirection: "column" }, style) }, { children: [(0, jsx_runtime_1.jsx)("div", { children: (0, jsx_runtime_1.jsxs)("div", __assign({ style: { display: "flex" } }, { children: [(0, jsx_runtime_1.jsx)(antd_1.Button, __assign({ title: "Reload this", size: "small", type: "text", onClick: function () {
                                setReload(reload + 1);
                                //iframeRef.current?.contentWindow.location.reload();
                            } }, { children: (0, jsx_runtime_1.jsx)(icon_1.Icon, { name: "reload" }) })), (0, jsx_runtime_1.jsx)("div", __assign({ style: {
                                flex: 1,
                                textAlign: "center",
                                paddingTop: "2.5px",
                                paddingLeft: fullscreen ? "15px" : undefined,
                            } }, { children: appURL && ((0, jsx_runtime_1.jsx)(antd_1.Popover, __assign({ title: "Open in the App", content: (0, jsx_runtime_1.jsxs)("div", __assign({ style: { maxWidth: "350px" } }, { children: ["Open ", path, " in the ", (0, jsx_runtime_1.jsx)(site_name_1.default, {}), " app for more options and to see your other files..."] })) }, { children: (0, jsx_runtime_1.jsxs)(A_1.default, __assign({ href: appURL, external: true }, { children: [(0, jsx_runtime_1.jsx)(icon_1.Icon, { name: "external-link", style: { marginRight: "5px" } }), path ? (0, misc_1.trunc_middle)(path, 50) : ""] })) }))) })), (0, jsx_runtime_1.jsx)(antd_1.Button, __assign({ size: "small", type: "text", title: "Full screen", onClick: function () {
                                if (!fullscreen) {
                                    document.documentElement.requestFullscreen();
                                }
                                else {
                                    if (document.fullscreenElement) {
                                        document.exitFullscreen();
                                    }
                                }
                                setFullscreen(!fullscreen);
                            } }, { children: (0, jsx_runtime_1.jsx)(icon_1.Icon, { name: fullscreen ? "compress" : "expand" }) }))] })) }), (0, jsx_runtime_1.jsx)("hr", { style: { width: "100%" } }), (0, jsx_runtime_1.jsx)("iframe", { ref: iframeRef, src: src, width: "100%", height: "100%", frameBorder: "0" })] })));
}
exports.default = IFrame;
//# sourceMappingURL=iframe.js.map