import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
import { Alert, Button } from "antd";
import { useActions, useAppState } from "../overmind";
const maybeWithEnv = (v, env) => (env != "prod" ? v : `${v}-${env}`);
export const NewsafeAuth = ({ children, redirectPath, redirectUrl }) => {
    const state = useAppState();
    const actions = useActions();
    const hostname = state.config.settings.newsafe.currentHost || state.config.settings.app.currentHost;
    const params = {
        requestor: state.config.settings.newcoin.daoDomain,
        referer: hostname,
        redirectUrl: redirectUrl || redirectPath || `https://${hostname}`,
    };
    const { stage, env } = state.config.env;
    const newstackConsoleUrl = maybeWithEnv("https://console", env) + ".newstack.dev";
    const isConfigured = params.requestor && stage;
    return (_jsx(_Fragment, { children: children || (_jsxs(_Fragment, { children: [isConfigured && _jsx("h1", { className: "text-center", children: `Welcome to ${state.config.settings.app.name}` }), _jsxs("h2", { className: "text-center", children: ["This application is using NEWSAFE", _jsx("br", {}), "the decentralized identity and access management service."] }), _jsx("br", {}), isConfigured ? (_jsxs(_Fragment, { children: [_jsx("h2", { className: "text-center", children: "Please sign in using your account at auth.newsafe.org" }), _jsx("div", { className: "text-center", children: _jsx(Button, { style: { fontSize: 30, height: 60, marginTop: 60 }, onClick: () => actions.newsafe.navigateToNewsafeAuthUrl(), children: "Sign In" }) })] })) : (_jsx("div", { className: "text-center", style: { maxWidth: 800 }, children: _jsx(Alert, { message: _jsxs(_Fragment, { children: ["This application had not been configured correctly.", _jsx("br", {}), _jsx("br", {}), "If you are the developer of the app:", _jsx("br", {}), _jsx("br", {}), "For more details check ", _jsx("a", { href: "https://newstack.dev/instructions", children: "newstack.dev/instructions" }), _jsx("br", {}), _jsxs("ul", { children: [_jsxs("li", { children: ["Have you created your app entry yet? If not create it at\u00A0", _jsx("a", { href: newstackConsoleUrl, children: newstackConsoleUrl }), "\u00A0. It only takes a few minutes.", _jsx("br", {}), _jsx("br", {})] }), _jsxs("li", { children: ["Got an app created? You are likely missing just a tiny bit of config. Please follow the instructions at\u00A0", _jsx("a", { href: `${newstackConsoleUrl}/instructions`, children: newstackConsoleUrl }), "\u00A0.", _jsx("br", {}), _jsx("br", {})] })] })] }), type: "error" }) }))] })) }));
};
//# sourceMappingURL=NewsafeAuth.js.map