'use client';

import React from 'react';
import Link from 'next/link';
import { BrandArtwork } from '../landing/BrandArtwork';
import { Icon } from '../ui/Icon';

function BrandLockup({ onNavy = false }: { onNavy?: boolean }) {
  return (
    <Link href="/" className="inline-flex items-center gap-2.5">
      <span className="grid h-9 w-9 place-items-center rounded-[11px] bg-gradient-to-br from-[#ff6b4a] to-[#b31800] text-base font-extrabold text-white shadow-[0_8px_20px_-6px_rgba(201,28,0,0.55)]">T</span>
      <span className={`text-[15px] font-bold tracking-[-0.01em] ${onNavy ? 'text-white' : 'text-ink'}`}>TechCMantix</span>
    </Link>
  );
}

/**
 * Shared split-screen layout for sign-in, password and invitation screens: a navy
 * brand panel with illustration on the left and the form centred on white on the
 * right, fitted to the viewport on desktop and collapsing to one column on mobile.
 */
export function AuthCard({ title, subtitle, children }: { title: string; subtitle?: React.ReactNode; children: React.ReactNode }) {
  return (
    <div className="min-h-screen bg-white lg:grid lg:h-screen lg:min-h-[640px] lg:grid-cols-[1.1fr_1fr]">
      <aside className="tcx-navy-band relative hidden overflow-hidden lg:flex lg:flex-col lg:p-12 xl:p-14">
        <div className="tcx-grid-lines pointer-events-none absolute inset-0" />
        <div className="pointer-events-none absolute -top-32 -right-24 h-96 w-96 rounded-full bg-[#ff6b4a]/15 blur-3xl" />
        <div className="pointer-events-none absolute -bottom-40 -left-24 h-96 w-96 rounded-full bg-[#5856d6]/15 blur-3xl" />

        <div className="relative">
          <BrandLockup onNavy />
        </div>

        <div className="relative flex min-h-0 flex-1 items-center justify-center py-8">
          <div className="w-full max-w-[min(520px,54vh)]">
            <BrandArtwork variant="minimal" />
          </div>
        </div>

        <div className="relative max-w-md">
          <p className="m-0 text-[32px] leading-[1.12] font-bold tracking-[-0.035em] text-white xl:text-[38px]">
            Pick up right where your <span className="text-[#ff7a5c]">team left off.</span>
          </p>
          <p className="mt-3 mb-0 text-[15px] leading-relaxed text-slate-400">Priorities, conversations and progress in one secure workspace.</p>
        </div>
      </aside>

      <div className="flex min-h-screen flex-col px-6 py-6 sm:px-10 lg:h-screen lg:min-h-0 lg:overflow-y-auto lg:px-14 lg:py-8">
        <div className="flex items-center justify-between">
          <span className="lg:invisible">
            <BrandLockup />
          </span>
          <Link href="/" className="inline-flex items-center gap-1 text-[13px] font-medium text-muted transition-colors hover:text-ink">
            <Icon name="chevronLeft" size={14} />
            Back to home
          </Link>
        </div>

        <main className="tcx-hero-enter flex flex-1 items-center justify-center py-10 lg:py-4">
          <div className="w-full max-w-[400px]">
            <span className="block h-1 w-10 rounded-full bg-primary" />
            <h1 className="mt-6 mb-0 text-[28px] leading-tight font-bold tracking-[-0.03em] text-ink sm:text-[32px]">{title}</h1>
            {subtitle ? <p className="mt-2.5 mb-0 text-[15px] leading-relaxed text-muted">{subtitle}</p> : null}
            <div className="mt-8">{children}</div>
          </div>
        </main>

        <p className="m-0 flex flex-wrap items-center justify-center gap-x-2 gap-y-1 text-center text-[12.5px] text-muted">
          <span>© 2026 TechCMantix</span>
          <span aria-hidden="true" className="hidden sm:inline">
            ·
          </span>
          <span className="inline-flex items-center gap-1.5">
            <Icon name="shield" size={13} />
            Secure, invitation-only workspace
          </span>
        </p>
      </div>
    </div>
  );
}
