<script>
import { router, page } from "@inertiajs/svelte";
import Logo from "../../components/Logo.svelte";
// scopes: [{name, description?}]; description is shown only when the server provides it.
let { client, scopes = [], request_id } = $props();
const user = $derived($page.props.auth?.user);
let busy = $state("");
const decide = (decision) => {
busy = decision;
router.post("/oauth/authorize", { decision, request_id }, { onFinish: () => (busy = "") });
};
</script>
<svelte:head><title>Authorize {client?.name}</title></svelte:head>
<div class="auth">
<div class="card auth-card">
<Logo class="brand-mark" />
<h1>Authorize {client?.name}</h1>
<p class="lede"><strong>{client?.name}</strong> wants to access your account{#if user} as <strong>{user.name || user.email}</strong>{/if}.</p>
{#if scopes.length}
<ul class="scopes" aria-label="Requested permissions">
{#each scopes as s (s.name)}
<li><code>{s.name}</code>{#if s.description}<span>{s.description}</span>{/if}</li>
{/each}
</ul>
{:else}
<p class="lede">No specific permissions requested.</p>
{/if}
<div class="consent-actions">
<button type="button" class="btn" disabled={!!busy} onclick={() => decide("deny")}>Deny</button>
<button type="button" class="btn btn-primary" disabled={!!busy} onclick={() => decide("allow")}>
{#if busy === "allow"}<span class="spin" aria-hidden="true"></span>{/if}Allow
</button>
</div>
<p class="auth-alt">You will be sent back to the app after you choose. Only allow apps you trust.</p>
</div>
</div>