<!DOCTYPE html>
<html>
    <head>
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no" />

        <script type="module" src="/node_modules/@finos/perspective-viewer/dist/cdn/perspective-viewer.js"></script>
        <script type="module" src="/node_modules/@finos/perspective-viewer-datagrid/dist/cdn/perspective-viewer-datagrid.js"></script>
        <script type="module" src="/node_modules/@finos/perspective-viewer-d3fc/dist/cdn/perspective-viewer-d3fc.js"></script>

        <link rel="stylesheet" crossorigin="anonymous" href="/node_modules/@finos/perspective-viewer/dist/css/themes.css" />

        <style>
            perspective-viewer {
                position: absolute;
                top: 0;
                left: 0;
                right: 0;
                bottom: 0;
            }
        </style>
    </head>

    <body>
        <perspective-viewer id="viewer" ,> </perspective-viewer>

        <script type="module">
            import perspective from "/node_modules/@finos/perspective/dist/cdn/perspective.js";
            window.addEventListener("DOMContentLoaded", async function () {
                setTimeout(async () => {
                    await customElements.whenDefined("perspective-viewer");                    
                    const viewer = document.getElementById("viewer");
                    let ws = "ws"
                    if (location.protocol === 'https:'){ ws = "wss"; }
                    const ws_path = "/websocket{{'' if is_new_api else '_readonly' if not editable else '_editable'}}";
                    const websocket = await perspective.websocket(ws + "://" + location.host + ws_path);
                    const table = await websocket.open_table("{{table_name}}");
                    viewer.load(table);
                    viewer.toggleConfig();
                }, 1000);
            });
        </script>
    </body>
</html>
