@extends('layouts.app')

@section('title', 'Templates de documento')
@section('page-title', 'Templates — Document Studio')

@section('content')
    @include('partials.flash')

    <div class="mb-6 flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">
        <p class="text-sm text-slate-600">Modelos reutilizáveis para propostas, contratos e demais documentos.</p>
        <a href="{{ route('documents.templates.create') }}" class="rounded-lg bg-emerald-600 px-4 py-2 text-sm font-semibold text-white hover:bg-emerald-700">Novo template</a>
    </div>

    <div class="space-y-3">
        @forelse ($templates as $t)
            <article class="rounded-xl border border-slate-200 bg-white p-4 shadow-sm">
                <div class="flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between">
                    <div>
                        <h2 class="font-medium">{{ $t->name }}</h2>
                        <p class="text-xs text-slate-500">
                            {{ $t->document_type->label() }}
                            @if ($t->is_default) · padrão @endif
                            @if ($t->is_system) · sistema @endif
                        </p>
                    </div>
                    <a href="{{ route('documents.templates.edit', $t) }}" class="text-sm font-medium text-emerald-700">Editar</a>
                </div>
                <div class="mt-3 max-h-40 overflow-auto rounded border border-slate-100 bg-slate-50 p-3 text-xs prose prose-sm max-w-none">
                    {!! $t->body_html !!}
                </div>
            </article>
        @empty
            <p class="rounded-xl border border-slate-200 bg-white px-4 py-8 text-center text-sm text-slate-500">Nenhum template ainda.</p>
        @endforelse
    </div>
@endsection
