@extends('layouts.app')

@section('title', 'Referral progress')
@section('heading', 'Referral progress')

@section('content')
    @include('recruitment.top-submenu')

    <x-card class="mb-4">
        <div class="flex flex-wrap items-start justify-between gap-4">
            <div>
                <p class="text-xs font-semibold uppercase tracking-wider text-slate-400">Your referral</p>
                <h2 class="mt-1 text-xl font-semibold text-slate-900">{{ $applicant->name }}</h2>
                <p class="mt-1 text-sm text-slate-600">{{ $applicant->jobPosting?->title ?? 'Open role' }}</p>
                <p class="mt-1 text-xs text-slate-500">Submitted {{ $applicant->applied_at?->format('l, d M Y') ?? $applicant->created_at?->format('l, d M Y') }}</p>
            </div>
            @if($applicant->resume_path)
                <a href="{{ route('applicants.resume.download', $applicant) }}" class="inline-flex items-center rounded-lg border border-slate-200 px-3 py-2 text-sm font-medium text-slate-700 hover:bg-slate-50">
                    Download resume
                </a>
            @endif
        </div>

        <div class="mt-6 rounded-xl border border-slate-200 bg-slate-50/60 p-4">
            @include('recruitment.partials.progress-stepper', ['progress' => $progress, 'showPercent' => true])
        </div>
    </x-card>

    @if($timeline->isNotEmpty())
        <x-card class="mb-4">
            <h3 class="text-sm font-semibold text-slate-900">Updates</h3>
            <ul class="mt-4 space-y-4">
                @foreach($timeline as $event)
                    <li class="border-l-2 border-primary/30 pl-4">
                        <p class="text-sm font-medium text-slate-800">{{ app(\App\Services\Recruitment\ReferralProgressService::class)->staffLabel($event->to_stage) }}</p>
                        @if($event->note_referrer)
                            <p class="mt-1 text-sm text-slate-600">{{ $event->note_referrer }}</p>
                        @endif
                        <p class="mt-1 text-xs text-slate-500">{{ $event->created_at?->format('d M Y, H:i') }}</p>
                    </li>
                @endforeach
            </ul>
        </x-card>
    @endif

    <div class="flex flex-wrap gap-2">
        <a href="{{ route('recruitment.my-referrals') }}" class="rounded-lg bg-slate-100 px-4 py-2 text-sm font-medium text-slate-700">Back to my referrals</a>
        @if($applicant->job_posting_id && app(\App\Services\Recruitment\RecruitmentNavService::class)->canRefer(auth()->user()))
            <a href="{{ route('applicants.refer', ['job_posting_id' => $applicant->job_posting_id]) }}" class="rounded-lg bg-primary px-4 py-2 text-sm font-medium text-white">Refer another for this role</a>
        @endif
    </div>
@endsection
