import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { AnimatedLoader, ConnectSidebar, HomeScreen, } from "@powerhousedao/design-system";
import { useEffect, useState } from "react";
import { getBasePath } from "../utils/browser.js";
const LOADER_DELAY = 250;
const Loader = ({ delay = LOADER_DELAY }) => {
    const isSSR = typeof window === "undefined";
    const showInitialLoader = typeof document !== "undefined" &&
        document.body.getAttribute("data-show-loader") === "true";
    const [showLoading, setShowLoading] = useState(!delay || showInitialLoader);
    useEffect(() => {
        const id = setTimeout(() => {
            setShowLoading(true);
        }, delay);
        return () => clearTimeout(id);
    }, []);
    return (_jsxs("div", { className: `skeleton-loader absolute inset-0 z-10 flex items-center justify-center ${showLoading ? "" : "hidden"}`, children: [_jsx("div", { className: "animate-pulse overflow-hidden rounded-full shadow-lg", children: _jsx(AnimatedLoader, {}) }), isSSR ? (_jsx("script", { dangerouslySetInnerHTML: {
                    __html: `setTimeout(() => {
                        document.querySelector('.skeleton-loader')?.classList.remove('hidden');
                        document.body.setAttribute('data-show-loader', 'true');
                    }, ${delay})`,
                } })) : null] }));
};
export const AppSkeleton = () => {
    const isSSR = typeof window === "undefined";
    const isHomeScreen = !isSSR && window.location.pathname === getBasePath();
    return (_jsxs("div", { className: "flex h-screen", children: [_jsx(ConnectSidebar, { className: "animate-pulse", onLogin: undefined, onDisconnect: undefined, onClickSettings: undefined, address: undefined }), _jsx(HomeScreen, { containerClassName: isSSR || !isHomeScreen ? "hidden home-screen" : undefined, children: null }), isSSR ? (_jsx("script", { dangerouslySetInnerHTML: {
                    __html: `
                    const baseEl = document.querySelector('base');
                    const href = baseEl?.getAttribute('href');
                    const basePath = href || '/';
                    if (window.location.pathname === basePath) {
                        document.querySelector('.home-screen')?.classList.remove('hidden')
                    }`,
                } })) : null, _jsx(Loader, {})] }));
};
export default AppSkeleton;
//# sourceMappingURL=app-skeleton.js.map