@extends('layouts.admin')

@section('title', 'Template Pesan')

@section('content')
<div class="space-y-6">
    {{-- Header --}}
    <div class="flex flex-col sm:flex-row sm:items-center justify-between gap-3">
        <div>
            <h3 class="text-lg font-semibold text-gray-800">Template Pesan Notifikasi</h3>
            <p class="text-sm text-gray-500 mt-1">Kustomisasi isi pesan WhatsApp dan Email yang dikirim ke pelamar</p>
        </div>
    </div>

    {{-- Info --}}
    <div class="bg-blue-50 border border-blue-200 rounded-lg p-4">
        <div class="flex items-start space-x-3">
            <svg class="w-5 h-5 text-blue-500 mt-0.5 flex-shrink-0" fill="none" stroke="currentColor" stroke-width="1.5" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" d="M11.25 11.25l.041-.02a.75.75 0 011.063.852l-.708 2.836a.75.75 0 001.063.853l.041-.021M21 12a9 9 0 11-18 0 9 9 0 0118 0zm-9-3.75h.008v.008H12V8.25z"/></svg>
            <div class="text-sm text-blue-700">
                <p class="font-medium">Cara Penggunaan Variabel</p>
                <p class="mt-1">Gunakan variabel dalam kurung kurawal untuk data dinamis, contoh: <code class="bg-blue-100 px-1 rounded">{applicant_name}</code> akan diganti dengan nama pelamar.</p>
            </div>
        </div>
    </div>

    {{-- Templates List --}}
    <div class="space-y-4">
        @foreach($templates as $template)
        <div class="bg-white border border-gray-200 rounded-xl overflow-hidden">
            <div class="flex flex-col sm:flex-row sm:items-center justify-between px-6 py-4 bg-gray-50 border-b border-gray-200 gap-3">
                <div>
                    <h4 class="font-semibold text-gray-800">{{ $template->label }}</h4>
                    <p class="text-xs text-gray-500 mt-0.5">Tipe: <code class="bg-gray-200 px-1.5 py-0.5 rounded">{{ $template->type }}</code></p>
                </div>
                <div class="flex items-center space-x-2">
                    <a href="{{ route('admin.message-templates.edit', $template) }}"
                       class="inline-flex items-center px-3 py-1.5 bg-indigo-600 text-white text-sm font-medium rounded-lg hover:bg-indigo-700 transition">
                        <svg class="w-4 h-4 mr-1.5" fill="none" stroke="currentColor" stroke-width="1.5" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" d="M16.862 4.487l1.687-1.688a1.875 1.875 0 112.652 2.652L10.582 16.07a4.5 4.5 0 01-1.897 1.13L6 18l.8-2.685a4.5 4.5 0 011.13-1.897l8.932-8.931zm0 0L19.5 7.125M18 14v4.75A2.25 2.25 0 0115.75 21H5.25A2.25 2.25 0 013 18.75V8.25A2.25 2.25 0 015.25 6H10"/></svg>
                        Edit
                    </a>
                </div>
            </div>
            <div class="p-6 grid grid-cols-1 lg:grid-cols-2 gap-6">
                {{-- Email Preview --}}
                <div>
                    <div class="flex items-center space-x-2 mb-2">
                        <svg class="w-4 h-4 text-gray-500" fill="none" stroke="currentColor" stroke-width="1.5" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" d="M21.75 6.75v10.5a2.25 2.25 0 01-2.25 2.25h-15a2.25 2.25 0 01-2.25-2.25V6.75m19.5 0A2.25 2.25 0 0019.5 4.5h-15a2.25 2.25 0 00-2.25 2.25m19.5 0v.243a2.25 2.25 0 01-1.07 1.916l-7.5 4.615a2.25 2.25 0 01-2.36 0L3.32 8.91a2.25 2.25 0 01-1.07-1.916V6.75"/></svg>
                        <span class="text-sm font-medium text-gray-600">Email</span>
                    </div>
                    <div class="bg-gray-50 rounded-lg p-3">
                        <p class="text-xs text-gray-500 mb-1">Subject:</p>
                        <p class="text-sm font-medium text-gray-800 mb-2">{{ $template->email_subject }}</p>
                        <p class="text-xs text-gray-500 mb-1">Body:</p>
                        <div class="text-sm text-gray-700 prose prose-sm max-w-none">{!! Str::limit(strip_tags($template->email_body), 150) !!}</div>
                    </div>
                </div>
                {{-- WA Preview --}}
                <div>
                    <div class="flex items-center space-x-2 mb-2">
                        <svg class="w-4 h-4 text-green-500" fill="currentColor" viewBox="0 0 24 24"><path d="M17.472 14.382c-.297-.149-1.758-.867-2.03-.967-.273-.099-.471-.148-.67.15-.197.297-.767.966-.94 1.164-.173.199-.347.223-.644.075-.297-.15-1.255-.463-2.39-1.475-.883-.788-1.48-1.761-1.653-2.059-.173-.297-.018-.458.13-.606.134-.133.298-.347.446-.52.149-.174.198-.298.298-.497.099-.198.05-.371-.025-.52-.075-.149-.669-1.612-.916-2.207-.242-.579-.487-.5-.669-.51-.173-.008-.371-.01-.57-.01-.198 0-.52.074-.792.372-.272.297-1.04 1.016-1.04 2.479 0 1.462 1.065 2.875 1.213 3.074.149.198 2.096 3.2 5.077 4.487.709.306 1.262.489 1.694.625.712.227 1.36.195 1.871.118.571-.085 1.758-.719 2.006-1.413.248-.694.248-1.289.173-1.413-.074-.124-.272-.198-.57-.347z"/><path d="M12 0C5.373 0 0 5.373 0 12c0 2.625.846 5.059 2.284 7.034L.789 23.492a.75.75 0 00.917.918l4.462-1.494A11.945 11.945 0 0012 24c6.627 0 12-5.373 12-12S18.627 0 12 0zm0 22c-2.319 0-4.476-.668-6.305-1.812l-.44-.263-3.035 1.015 1.017-3.038-.27-.447A9.955 9.955 0 012 12C2 6.486 6.486 2 12 2s10 4.486 10 10-4.486 10-10 10z"/></svg>
                        <span class="text-sm font-medium text-gray-600">WhatsApp</span>
                    </div>
                    <div class="bg-green-50 rounded-lg p-3">
                        <p class="text-sm text-gray-700 whitespace-pre-line">{{ Str::limit($template->wa_body, 150) }}</p>
                    </div>
                </div>
            </div>
            {{-- Variables --}}
            @if($template->available_variables)
            <div class="px-6 pb-4">
                <p class="text-xs text-gray-500 mb-2">Variabel tersedia:</p>
                <div class="flex flex-wrap gap-1.5">
                    @foreach($template->available_variables as $var)
                    <span class="inline-flex items-center px-2 py-0.5 bg-indigo-50 text-indigo-700 text-xs rounded-full font-mono">{!! '{' . $var . '}' !!}</span>
                    @endforeach
                </div>
            </div>
            @endif
        </div>
        @endforeach
    </div>

</div>
@endsection
