<x-app-layout>
    <x-slot name="header">
        <div class="flex justify-between items-center">
            <h2 class="font-semibold text-xl text-gray-800 leading-tight">
                {{ __('Inquiry Details') }}
            </h2>
            <a href="{{ $inquiry->type === 'career' ? route('inquiries.careers') : route('inquiries.index') }}" class="text-gray-600 hover:text-gray-800">
                ← {{ $inquiry->type === 'career' ? 'Back to Career Applications' : 'Back to Inquiries' }}
            </a>
        </div>
    </x-slot>

    <div class="py-12">
        <div class="max-w-4xl mx-auto sm:px-6 lg:px-8">

            @if(session('success'))
                <div class="bg-green-100 border border-green-400 text-green-700 px-4 py-3 rounded relative mb-4">
                    {{ session('success') }}
                </div>
            @endif

            <div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
                <div class="p-6 text-gray-900">
                    <!-- Header with status and type -->
                    <div class="flex justify-between items-start mb-6 pb-6 border-b">
                        <div>
                            <h1 class="text-2xl font-bold text-gray-800">{{ $inquiry->subject }}</h1>
                            <p class="text-gray-500 mt-1">Received on {{ $inquiry->created_at->format('M d, Y \a\t g:i A') }}</p>
                        </div>
                        <div class="flex gap-2">
                            <span class="px-3 py-1 text-sm font-semibold rounded-full
                                {{ $inquiry->type === 'contact' ? 'bg-blue-100 text-blue-800' : '' }}
                                {{ $inquiry->type === 'quote' ? 'bg-green-100 text-green-800' : '' }}
                                {{ $inquiry->type === 'product' ? 'bg-purple-100 text-purple-800' : '' }}
                                {{ $inquiry->type === 'career' ? 'bg-orange-100 text-orange-800' : '' }}
                            ">
                                {{ ucfirst($inquiry->type) }}
                            </span>
                            <span class="px-3 py-1 text-sm font-semibold rounded-full {{ $inquiry->status === 'unread' ? 'bg-yellow-100 text-yellow-800' : 'bg-green-100 text-green-800' }}">
                                {{ ucfirst($inquiry->status) }}
                            </span>
                        </div>
                    </div>

                    <!-- Contact Information -->
                    <div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-6">
                        <div>
                            <label class="block text-xs uppercase text-gray-500 font-semibold mb-1">Name</label>
                            <p class="text-gray-800 font-medium">{{ $inquiry->name }}</p>
                        </div>
                        <div>
                            <label class="block text-xs uppercase text-gray-500 font-semibold mb-1">Email</label>
                            <p class="text-gray-800">
                                <a href="mailto:{{ $inquiry->email }}" class="text-blue-600 hover:underline">{{ $inquiry->email }}</a>
                            </p>
                        </div>
                        @if($inquiry->phone)
                        <div>
                            <label class="block text-xs uppercase text-gray-500 font-semibold mb-1">Phone</label>
                            <p class="text-gray-800">
                                <a href="tel:{{ $inquiry->phone }}" class="text-blue-600 hover:underline">{{ $inquiry->phone }}</a>
                            </p>
                        </div>
                        @endif
                        @if($inquiry->quantity)
                        <div>
                            <label class="block text-xs uppercase text-gray-500 font-semibold mb-1">Quantity</label>
                            <p class="text-gray-800 font-medium">{{ $inquiry->quantity }}</p>
                        </div>
                        @endif
                    </div>

                    <!-- Message -->
                    <div class="mb-6 pb-6 border-b">
                        <label class="block text-xs uppercase text-gray-500 font-semibold mb-2">Message</label>
                        <div class="bg-gray-50 p-4 rounded-lg text-gray-800 whitespace-pre-wrap">
                            {{ $inquiry->message }}
                        </div>
                    </div>

                    @if($inquiry->file_path)
                    <!-- Attachment -->
                    <div class="mb-6 pb-6 border-b">
                        <label class="block text-xs uppercase text-gray-500 font-semibold mb-2">Attachment (Resume/CV)</label>
                        <a href="{{ Storage::url($inquiry->file_path) }}" target="_blank" class="inline-flex items-center px-4 py-2 bg-indigo-50 border border-indigo-200 rounded-md font-semibold text-xs text-indigo-700 uppercase tracking-widest hover:bg-indigo-100 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2 transition ease-in-out duration-150">
                            Download Attachment
                        </a>
                    </div>
                    @endif

                    <!-- Actions -->
                    <div class="flex gap-2">
                        @if($inquiry->status === 'unread')
                            <form action="{{ route('inquiries.mark-read', $inquiry) }}" method="POST" class="inline">
                                @csrf
                                @method('PATCH')
                                <button type="submit" class="bg-blue-600 text-white px-4 py-2 rounded-md hover:bg-blue-700">
                                    Mark as Read
                                </button>
                            </form>
                        @else
                            <form action="{{ route('inquiries.mark-unread', $inquiry) }}" method="POST" class="inline">
                                @csrf
                                @method('PATCH')
                                <button type="submit" class="bg-gray-600 text-white px-4 py-2 rounded-md hover:bg-gray-700">
                                    Mark as Unread
                                </button>
                            </form>
                        @endif

                        <form action="{{ route('inquiries.destroy', $inquiry) }}" method="POST" onsubmit="return confirm('Are you sure?');" class="inline">
                            @csrf
                            @method('DELETE')
                            <button type="submit" class="bg-red-600 text-white px-4 py-2 rounded-md hover:bg-red-700">
                                Delete
                            </button>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</x-app-layout>
