<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{% if success %}Authentication Successful{% else %}Authentication Failed{% endif %} - Rise</title>
    <link rel="icon" type="image/x-icon" href="/assets/favicon.ico">
    <link rel="icon" type="image/png" sizes="16x16" href="/assets/favicon-16x16.png">
    <link rel="icon" type="image/png" sizes="32x32" href="/assets/favicon-32x32.png">
    <style>
        :root {
            --bg: #111111;
            --panel: #141414;
            --line: #3a3a3a;
            --text: #ececec;
            --muted: #b8b8b8;
            --ok: #b7ffce;
            --bad: #ffc0c0;
        }
        * { box-sizing: border-box; }
        body {
            margin: 0;
            min-height: 100vh;
            font-family: "IBM Plex Mono", ui-monospace, monospace;
            color: var(--text);
            background: radial-gradient(circle at 0 0, #202020 0%, #101010 40%), var(--bg);
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 1rem;
        }
        .card {
            width: 100%;
            max-width: 48rem;
            background: var(--panel);
            border: 1px solid var(--line);
            padding: 1.2rem;
            text-align: center;
        }
        .logo {
            width: 2rem;
            height: 2rem;
            margin: 0 auto 0.75rem;
            background-color: currentColor;
            mask-size: contain;
            mask-repeat: no-repeat;
            mask-position: center;
            -webkit-mask-size: contain;
            -webkit-mask-repeat: no-repeat;
            -webkit-mask-position: center;
            mask-image: url(/assets/logo.svg);
            -webkit-mask-image: url(/assets/logo.svg);
        }
        .state-ok { color: var(--ok); font-size: 2rem; margin-bottom: 0.5rem; }
        .state-bad { color: var(--bad); font-size: 2rem; margin-bottom: 0.5rem; }
        h2 { margin: 0 0 0.8rem; font-size: 1.2rem; }
        p { color: var(--muted); }
        .mono-code {
            color: var(--text);
            background: #1a1a1a;
            border: 1px solid var(--line);
            padding: 0.1rem 0.35rem;
        }
        .progress {
            width: 100%;
            background: #1a1a1a;
            border: 1px solid var(--line);
            height: 8px;
            margin: 1rem 0;
        }
        .progress > div {
            background: #d6d6d6;
            height: 100%;
            width: 0%;
            transition: width 1000ms;
        }
        .btn {
            display: inline-block;
            border: 1px solid var(--line);
            background: #1a1a1a;
            color: var(--text);
            text-decoration: none;
            padding: 0.55rem 0.75rem;
        }
        .subtle-link {
            color: #888888;
            text-decoration: underline;
        }
        .subtle-link:hover {
            color: #aaaaaa;
        }
        .errbox {
            border: 1px solid #7d4b4b;
            color: var(--bad);
            background: #1a1212;
            padding: 0.6rem;
            margin: 0.9rem 0;
        }
    </style>
</head>
<body>
    <div class="card">
            {% if success %}
            <div>
                <div class="logo" aria-hidden="true"></div>
                <div class="state-ok">[ok]</div>
                <h2>Authentication Successful</h2>

                <p>
                    Signing you in to project
                    <strong class="mono-code">{{ project_name }}</strong>...
                </p>

                <div class="progress">
                    <div id="progress-bar"></div>
                </div>

                <p>
                    <small>You will be redirected shortly. <a href="{{ redirect_url }}" class="subtle-link">Click here if not redirected automatically</a></small>
                </p>
            </div>

            <script>
                const redirectUrl = {{ redirect_url | json_encode() }};
                const progressBar = document.getElementById('progress-bar');

                // Start progress bar animation
                setTimeout(() => progressBar.style.width = '100%', 100);

                // Redirect after 1 second to ensure cookie is set
                setTimeout(() => {
                    window.location.href = redirectUrl;
                }, 1000);
            </script>
            {% else %}
            <div>
                <div class="logo" aria-hidden="true"></div>
                <div class="state-bad">[error]</div>
                <h2>Authentication Failed</h2>

                <p>
                    Failed to authenticate for project
                    <strong class="mono-code">{{ project_name }}</strong>.
                </p>

                {% if error_message %}
                <p class="errbox">
                    {{ error_message }}
                </p>
                {% endif %}

                <a href="/api/v1/auth/signin?project={{ project_name }}{% if redirect_url %}&redirect={{ redirect_url | urlencode }}{% endif %}"
                   class="btn">
                    Try Again
                </a>
            </div>
            {% endif %}
    </div>
</body>
</html>
