{{-- resources/views/dashboard/job-descriptions/detail.blade.php - Single JD Detail View --}}
@extends('layouts.dashboard')

@section('content')
    <div class="w-full md:min-h-screen bg-gray-50 pt-[20px] pb-20">
        <div class="md:max-w-[80%] max-w-[90%] mx-auto px-6">

            {{-- Navigation Tabs --}}
            <x-job-descriptions.nav-tabs active="library" />

            {{-- Back Link --}}
            <a href="{{ route('dashboard.job-descriptions.index') }}"
               class="inline-flex items-center gap-2 text-sm text-gray-500 hover:text-gray-700 transition-colors mb-6">
                <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 19l-7-7m0 0l7-7m-7 7h18" />
                </svg>
                Back to Library
            </a>

            @php
                $jd = $jobDescription;
            @endphp

            {{-- Header --}}
            <div class="flex flex-col md:flex-row md:items-center justify-between gap-4 mb-8">
                <div class="flex items-center gap-3">
                    <h1 class="text-2xl font-bold text-gray-900">{{ $jd->job_title }}</h1>
                    @switch($jd->status)
                        @case('approved')
                            <span class="inline-flex items-center gap-1 px-3 py-1 rounded-full text-xs font-semibold bg-green-100 text-green-700 border border-green-200">
                                <svg class="w-3 h-3" fill="currentColor" viewBox="0 0 20 20"><path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z" clip-rule="evenodd" /></svg>
                                Approved
                            </span>
                            @break
                        @case('published')
                            <span class="inline-flex items-center gap-1 px-3 py-1 rounded-full text-xs font-semibold bg-blue-100 text-blue-700 border border-blue-200">
                                <svg class="w-3 h-3" fill="currentColor" viewBox="0 0 20 20"><path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z" clip-rule="evenodd" /></svg>
                                Published
                            </span>
                            @break
                        @case('unpublished')
                            <span class="inline-flex items-center gap-1 px-3 py-1 rounded-full text-xs font-semibold bg-orange-100 text-orange-700 border border-orange-200">
                                Unpublished
                            </span>
                            @break
                        @default
                            <span class="inline-flex items-center px-3 py-1 rounded-full text-xs font-semibold bg-gray-100 text-gray-600 border border-gray-200">Draft</span>
                    @endswitch
                </div>
                <div class="flex items-center gap-3">
                    <a href="{{ route('dashboard.job-descriptions.edit', $jd->id) }}"
                       class="inline-flex items-center gap-2 h-10 px-5 rounded-lg text-sm font-medium text-gray-700 bg-white border border-gray-200 hover:bg-gray-50 transition-colors">
                        <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z" />
                        </svg>
                        Edit
                    </a>
                    <button class="inline-flex items-center gap-2 h-10 px-5 rounded-lg text-sm font-medium text-gray-700 bg-white border border-gray-200 hover:bg-gray-50 transition-colors"
                            x-data="{ copied: false }"
                            @click="navigator.clipboard.writeText('{{ url('/job-descriptions/' . ($jd->job_id ?? 'JD-001') . '/' . \Illuminate\Support\Str::slug($jd->job_title)) }}'); copied = true; setTimeout(() => copied = false, 2000)">
                        <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8.684 13.342C8.886 12.938 9 12.482 9 12c0-.482-.114-.938-.316-1.342m0 2.684a3 3 0 110-2.684m0 2.684l6.632 3.316m-6.632-6l6.632-3.316m0 0a3 3 0 105.367-2.684 3 3 0 00-5.367 2.684zm0 9.316a3 3 0 105.368 2.684 3 3 0 00-5.368-2.684z" />
                        </svg>
                        <span x-text="copied ? 'Copied!' : 'Share'"></span>
                    </button>
                    <button class="inline-flex items-center gap-2 h-10 px-5 rounded-lg text-sm font-medium text-white bg-[#2F3D7E] hover:bg-[#1E2858] transition-colors">
                        <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4" />
                        </svg>
                        Export PDF
                    </button>
                </div>
            </div>

            {{-- Job ID --}}
            <p class="text-sm text-gray-500 mb-6">Job ID: {{ $jd->job_id }}</p>

            {{-- Info Cards --}}
            <div class="grid grid-cols-2 md:grid-cols-4 gap-4 mb-8">
                <div class="bg-white border border-gray-200 rounded-2xl p-5">
                    <div class="flex items-center gap-3 mb-2">
                        <div class="w-8 h-8 bg-blue-50 rounded-lg flex items-center justify-center">
                            <svg class="w-4 h-4 text-[#2F3D7E]" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 21V5a2 2 0 00-2-2H7a2 2 0 00-2 2v16m14 0h2m-2 0h-5m-9 0H3m2 0h5M9 7h1m-1 4h1m4-4h1m-1 4h1m-5 10v-5a1 1 0 011-1h2a1 1 0 011 1v5m-4 0h4" />
                            </svg>
                        </div>
                    </div>
                    <p class="text-xs text-gray-500">Department</p>
                    <p class="text-sm font-bold text-gray-900">{{ $jd->department }}</p>
                </div>
                <div class="bg-white border border-gray-200 rounded-2xl p-5">
                    <div class="flex items-center gap-3 mb-2">
                        <div class="w-8 h-8 bg-orange-50 rounded-lg flex items-center justify-center">
                            <svg class="w-4 h-4 text-orange-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 21V5a2 2 0 00-2-2H7a2 2 0 00-2 2v16m14 0h2m-2 0h-5m-9 0H3m2 0h5M9 7h1m-1 4h1m4-4h1m-1 4h1m-5 10v-5a1 1 0 011-1h2a1 1 0 011 1v5m-4 0h4" />
                            </svg>
                        </div>
                    </div>
                    <p class="text-xs text-gray-500">Level</p>
                    <p class="text-sm font-bold text-gray-900">{{ $jd->level }}</p>
                </div>
                <div class="bg-white border border-gray-200 rounded-2xl p-5">
                    <div class="flex items-center gap-3 mb-2">
                        <div class="w-8 h-8 bg-green-50 rounded-lg flex items-center justify-center">
                            <svg class="w-4 h-4 text-green-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17.657 16.657L13.414 20.9a1.998 1.998 0 01-2.827 0l-4.244-4.243a8 8 0 1111.314 0z" />
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 11a3 3 0 11-6 0 3 3 0 016 0z" />
                            </svg>
                        </div>
                    </div>
                    <p class="text-xs text-gray-500">Location</p>
                    <p class="text-sm font-bold text-gray-900">{{ $jd->location }}</p>
                </div>
                <div class="bg-white border border-gray-200 rounded-2xl p-5">
                    <div class="flex items-center gap-3 mb-2">
                        <div class="w-8 h-8 bg-yellow-50 rounded-lg flex items-center justify-center">
                            <svg class="w-4 h-4 text-yellow-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z" />
                            </svg>
                        </div>
                    </div>
                    <p class="text-xs text-gray-500">Type</p>
                    <p class="text-sm font-bold text-gray-900">{{ $jd->employment_type }}</p>
                </div>
            </div>

            {{-- Main Content --}}
            <div class="grid grid-cols-1 lg:grid-cols-3 gap-8">
                {{-- Left Column --}}
                <div class="lg:col-span-2 space-y-6">
                    {{-- Role Summary --}}
                    <div class="bg-white border border-gray-200 rounded-2xl p-6">
                        <h3 class="text-base font-bold text-gray-900 mb-3">Role Summary</h3>
                        <p class="text-sm text-gray-600 leading-relaxed">{{ $jd->role_summary }}</p>
                    </div>

                    {{-- Key Responsibilities --}}
                    <div class="bg-white border border-gray-200 rounded-2xl p-6">
                        <h3 class="text-base font-bold text-gray-900 mb-4">Key Responsibilities</h3>
                        <ul class="space-y-3">
                            @foreach($jd->responsibilities as $item)
                                <li class="flex items-start gap-2 text-sm text-gray-600">
                                    <span class="w-1.5 h-1.5 bg-gray-900 rounded-full mt-1.5 shrink-0"></span>
                                    {{ $item }}
                                </li>
                            @endforeach
                        </ul>
                    </div>

                    {{-- Required Skills --}}
                    <div class="bg-white border border-gray-200 rounded-2xl p-6">
                        <h3 class="text-base font-bold text-gray-900 mb-4">Required Skills</h3>
                        <ul class="space-y-3">
                            @foreach($jd->required_skills as $item)
                                <li class="flex items-start gap-2 text-sm text-gray-600">
                                    <svg class="w-4 h-4 text-green-500 mt-0.5 shrink-0" fill="currentColor" viewBox="0 0 20 20">
                                        <path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z" clip-rule="evenodd" />
                                    </svg>
                                    {{ $item }}
                                </li>
                            @endforeach
                        </ul>
                    </div>

                    {{-- Qualifications --}}
                    <div class="bg-white border border-gray-200 rounded-2xl p-6">
                        <h3 class="text-base font-bold text-gray-900 mb-4">Qualifications</h3>
                        <ul class="space-y-3">
                            @foreach($jd->qualifications as $item)
                                <li class="flex items-start gap-2 text-sm text-gray-600">
                                    <span class="w-1.5 h-1.5 bg-gray-900 rounded-full mt-1.5 shrink-0"></span>
                                    {{ $item }}
                                </li>
                            @endforeach
                        </ul>
                    </div>

                    {{-- Key Competencies --}}
                    <div class="bg-white border border-gray-200 rounded-2xl p-6">
                        <h3 class="text-base font-bold text-gray-900 mb-4">Key Competencies</h3>
                        <div class="flex flex-wrap gap-2">
                            @foreach($jd->competencies as $comp)
                                <span class="inline-flex items-center px-3 py-1.5 bg-gray-100 text-gray-700 rounded-full text-xs font-medium border border-gray-200">
                                    {{ $comp }}
                                </span>
                            @endforeach
                        </div>
                    </div>
                </div>

                {{-- Right Column --}}
                <div class="space-y-6">
                    {{-- Document Information --}}
                    <div class="bg-white border border-gray-200 rounded-2xl p-6">
                        <h3 class="text-base font-bold text-gray-900 mb-4">Document Information</h3>
                        <div class="space-y-4">
                            <div class="flex items-center gap-3">
                                <svg class="w-4 h-4 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z" />
                                </svg>
                                <div>
                                    <p class="text-xs text-gray-500">Created By</p>
                                    <p class="text-sm font-semibold text-gray-900">{{ $jd->created_by ?? 'Sarah Johnson' }}</p>
                                </div>
                            </div>
                            <hr class="border-gray-100">
                            <div class="flex items-center gap-3">
                                <svg class="w-4 h-4 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z" />
                                </svg>
                                <div>
                                    <p class="text-xs text-gray-500">Last Modified</p>
                                    <p class="text-sm font-semibold text-gray-900">{{ $jd->updated_at ?? now()->format('Y-m-d') }}</p>
                                </div>
                            </div>

                            @if($jd->status === 'approved' || $jd->status === 'published')
                                <hr class="border-gray-100">
                                <div class="flex items-center gap-3">
                                    <svg class="w-4 h-4 text-green-500" fill="currentColor" viewBox="0 0 20 20">
                                        <path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z" clip-rule="evenodd" />
                                    </svg>
                                    <div>
                                        <p class="text-xs text-gray-500">Approved By</p>
                                        <p class="text-sm font-semibold text-gray-900">{{ $jd->approved_by ?? 'David Martinez' }}</p>
                                    </div>
                                </div>
                                <div class="pl-7">
                                    <p class="text-xs text-gray-500">Approval Date</p>
                                    <p class="text-sm font-semibold text-gray-900">{{ $jd->approved_at ?? now()->format('Y-m-d') }}</p>
                                </div>
                            @endif
                        </div>
                    </div>

                    {{-- Quick Actions --}}
                    <div class="bg-white border border-gray-200 rounded-2xl p-6">
                        <h3 class="text-base font-bold text-gray-900 mb-4">Quick Actions</h3>
                        <div class="space-y-3">
                            <button class="w-full inline-flex items-center gap-3 px-4 py-3 rounded-lg text-sm font-medium text-gray-700 border border-gray-200 hover:bg-gray-50 transition-colors">
                                <svg class="w-4 h-4 text-gray-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4" />
                                </svg>
                                Export as DOCX
                            </button>
                            <button class="w-full inline-flex items-center gap-3 px-4 py-3 rounded-lg text-sm font-medium text-gray-700 border border-gray-200 hover:bg-gray-50 transition-colors"
                                    x-data="{ copied: false }"
                                    @click="navigator.clipboard.writeText('{{ url('/job-descriptions/' . ($jd->job_id ?? 'JD-001') . '/' . \Illuminate\Support\Str::slug($jd->job_title)) }}'); copied = true; setTimeout(() => copied = false, 2000)">
                                <svg class="w-4 h-4 text-gray-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8.684 13.342C8.886 12.938 9 12.482 9 12c0-.482-.114-.938-.316-1.342m0 2.684a3 3 0 110-2.684m0 2.684l6.632 3.316m-6.632-6l6.632-3.316m0 0a3 3 0 105.367-2.684 3 3 0 00-5.367 2.684zm0 9.316a3 3 0 105.368 2.684 3 3 0 00-5.368-2.684z" />
                                </svg>
                                <span x-text="copied ? 'Link Copied!' : 'Generate Share Link'"></span>
                            </button>
                        </div>
                    </div>

                    {{-- Next Steps (shown for drafts) --}}
                    @if($jd->status === 'draft')
                        <div class="bg-white border border-gray-200 rounded-2xl p-6">
                            <h3 class="text-base font-bold text-gray-900 mb-4">Next Steps</h3>
                            <form action="{{ route('dashboard.job-descriptions.submit-approval', $jd->id) }}" method="POST">
                                @csrf
                                <button type="submit"
                                        class="w-full inline-flex items-center justify-center h-11 px-6 rounded-lg font-medium text-white bg-[#2F3D7E] hover:bg-[#1E2858] transition-colors mb-2">
                                    Submit for Approval
                                </button>
                            </form>
                            <p class="text-xs text-gray-500 text-center">Complete editing before submitting</p>
                        </div>
                    @endif
                </div>
            </div>
        </div>
    </div>
@endsection
