import { ChangeDetectionStrategy, Component } from '@angular/core';
import { provideTranslocoScope, TranslocoDirective } from '@jsverse/transloco';
import { environment } from 'environments/environment';

/**
 * Terminal "signed out" page shown after a sign-out in authorization-code mode.
 *
 * Reachable at /signed-out — this route carries NO authentication guard so it is
 * always a safe landing place and can NEVER trigger a re-authentication loop (unlike
 * /auth/sign-in which is gated by noLocalAuthGuard and would immediately bounce the
 * user back to the hub if the hub cookie is still valid).
 *
 * This page is used as the `post_logout_redirect_uri` in the RP-initiated hub logout
 * flow. After the hub clears the `hub_session` cookie, it 302-redirects the browser
 * back to this URL, so the user lands here with both the local session and the hub
 * session fully terminated.
 *
 * The "Sign in again" link sends the user back to the hub launcher explicitly,
 * which is the only safe way to start a new authorize round-trip in this mode.
 */
@Component({
  selector: 'app-signed-out',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [TranslocoDirective],
  providers: [provideTranslocoScope('auth')],
  template: `
    <ng-container *transloco="let t; scope: 'auth'">
      <div class="flex min-h-svh flex-col items-center justify-center gap-4 p-6 text-center">
        <h1 class="text-2xl font-semibold">{{ t('auth.signedOut.Headline') }}</h1>
        <p class="text-muted-foreground max-w-sm text-sm">
          {{ t('auth.signedOut.Message') }}
        </p>
        <a
          class="bg-primary text-primary-foreground hover:bg-primary/90 inline-flex items-center rounded-md px-4 py-2 text-sm font-medium"
          [href]="hubLoginUrl"
        >
          {{ t('auth.signedOut.SignInButton') }}
        </a>
      </div>
    </ng-container>
  `,
})
export default class SignedOutComponent {
  /** Direct link to the hub launcher — triggers a fresh authorize round-trip. */
  readonly hubLoginUrl: string = `${environment.api.rest}/auth/login`;
}
