@extends('layouts.app')
@section('title', 'Email Templates')
@section('content')
    <x-page-head title="Email Templates" subtitle="Customize automated and manual message templates">
        <x-slot:actions>
            <a href="{{ route('communication.emails.index') }}" class="btn btn-outline">Email Center</a>
            <a href="{{ route('communication.email-templates.create') }}" class="btn btn-primary">New Template</a>
        </x-slot:actions>
    </x-page-head>

    <x-panel>
        <div class="table-wrap">
            <table>
                <thead><tr><th>Name</th><th>Category</th><th>Subject</th><th>Default</th><th>Active</th><th></th></tr></thead>
                <tbody>
                    @foreach ($templates as $template)
                        <tr>
                            <td>{{ $template->name }}</td>
                            <td>{{ $template->category }}</td>
                            <td>{{ str($template->subject)->limit(50) }}</td>
                            <td>@if($template->is_default)<x-badge variant="blue">Default</x-badge>@endif</td>
                            <td><x-badge :variant="$template->is_active ? 'green' : 'gray'">{{ $template->is_active ? 'Active' : 'Inactive' }}</x-badge></td>
                            <td style="display:flex; gap:6px; flex-wrap:wrap;">
                                <a href="{{ route('communication.email-templates.edit', $template) }}" class="btn btn-ghost btn-sm">Edit</a>
                                <form method="POST" action="{{ route('communication.email-templates.duplicate', $template) }}">@csrf<button class="btn btn-outline btn-sm">Duplicate</button></form>
                                @unless($template->is_system)
                                    <form method="POST" action="{{ route('communication.email-templates.destroy', $template) }}" onsubmit="return confirm('Delete this template?')">@csrf @method('DELETE')<button class="btn btn-danger btn-sm">Delete</button></form>
                                @endunless
                            </td>
                        </tr>
                    @endforeach
                </tbody>
            </table>
        </div>
        <p style="margin-top:16px; color:var(--text2); font-size:13px;">Placeholders: @{{business_name}}, @{{client_name}}, @{{invoice_number}}, @{{total_amount}}, @{{custom_message}}, and more.</p>
    </x-panel>
@endsection
