import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
import { useData } from "../data/index.js";
import { DISCORD_CLIENT_ID } from "../../../listen/auth/discord.js";
import { REDDIT_CLIENT_ID } from "../../../listen/auth/reddit.js";
import { AUTHSIGNAL_CHALLENGE_API_URL, AUTHSIGNAL_TENANT, AUTHSIGNAL_WEBAUTHN } from "../../../authentication/authsignal.js";
export const path = "/login";
export const anonymous = true;
const FORM_CLASS = `
mt-1
block
w-full
md:max-w-sm
rounded-md
border-gray-300
shadow-sm
focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50
disabled:bg-slate-300 disabled:cursor-not-allowed
`.trim();
const FORM_GROUP_CLASS = `block py-2`;
const { ALLOW_ANONYMOUS_USER } = process.env;
export function Login() {
    const { isUnauthenticated, url } = useData();
    if (!isUnauthenticated) {
        return _jsx("p", { children: "You're already logged in!" });
    }
    const state = new URL(url).searchParams.get("state");
    const params = new URLSearchParams();
    if (state) {
        params.set("state", state);
    }
    const stateUrlSuffix = state ? `?${state.toString()}` : "";
    const anonymousParams = new URLSearchParams(params);
    anonymousParams.set("redirect", "/home");
    return (_jsxs("div", { children: [_jsxs("form", { id: "login-authsignal", name: "login-authsignal", action: "/api/authentication/authsignal/redirect", method: "post", children: [AUTHSIGNAL_WEBAUTHN ? (_jsxs(_Fragment, { children: [_jsx("meta", { name: "authsignal-tenant-id", content: AUTHSIGNAL_TENANT }), _jsx("meta", { name: "authsignal-region", content: AUTHSIGNAL_CHALLENGE_API_URL }), _jsx("meta", { name: "authsignal-track-url", content: "/api/authentication/authsignal/track" })] })) : undefined, state ? _jsx("input", { type: "hidden", name: "state", value: state }) : undefined, _jsx("div", { className: "flex flex-col", children: _jsxs("label", { className: FORM_GROUP_CLASS, children: [_jsx("span", { className: "text-gray-700", children: "Email Address" }), _jsx("input", { className: FORM_CLASS, type: "email", name: "email", defaultValue: "", placeholder: "Email Address" })] }) }), _jsx("div", { id: "action-section", children: _jsx("button", { type: "submit", className: "bg-sky-500 hover:bg-sky-700 px-4 py-2.5 text-sm leading-5 rounded-md font-semibold text-white mr-2", children: "Continue with Email" }) })] }), (DISCORD_CLIENT_ID || REDDIT_CLIENT_ID || ALLOW_ANONYMOUS_USER) ? _jsxs("div", { children: [_jsx("br", {}), "OR", _jsx("br", {}), _jsx("br", {})] }) : undefined, DISCORD_CLIENT_ID ? (_jsxs(_Fragment, { children: [_jsx("a", { href: `/api/authentication/discord/redirect${stateUrlSuffix}`, className: "text-blue-600 hover:bg-white underline hover:underline-offset-2", children: "Continue with Discord" }), _jsx("br", {})] })) : undefined, REDDIT_CLIENT_ID ? (_jsxs(_Fragment, { children: [_jsx("a", { href: `/api/authentication/reddit/redirect${stateUrlSuffix}`, className: "text-blue-600 hover:bg-white underline hover:underline-offset-2", children: "Continue with Reddit" }), _jsx("br", {})] })) : undefined, ALLOW_ANONYMOUS_USER ? (_jsxs(_Fragment, { children: [_jsx("a", { href: `/api/authentication/anonymous?${anonymousParams.toString()}`, className: "text-blue-600 hover:bg-white underline hover:underline-offset-2", children: "Continue as Anonymous User" }), _jsx("br", {})] })) : undefined] }));
}
export const Component = Login;
//# sourceMappingURL=login.js.map