@extends('layouts.admin')

@section('title', 'Editar Campanha')

@section('content')
<div class="max-w-2xl mx-auto">
    <div class="mb-8">
        <span class="w-8 h-[2px] bg-brand block mb-2"></span>
        <h1 class="text-3xl font-bold italic tracking-tighter uppercase text-brand">Editar Campanha</h1>
        <p class="text-slate-500 font-medium text-sm">A editar: <span class="font-bold text-brand">{{ $campaign->name }}</span></p>
    </div>

    <form action="{{ route('admin.campaigns.update', $campaign) }}" method="POST" enctype="multipart/form-data" class="bg-white border border-slate-100 rounded-2xl p-8 shadow-sm space-y-6">
        @csrf
        @method('PUT')

        <div class="space-y-2">
            <label class="text-[10px] font-bold uppercase tracking-widest text-slate-400">Nome</label>
            <input type="text" name="name" value="{{ old('name', $campaign->name) }}" class="w-full px-4 py-3 rounded-xl border border-slate-200 focus:border-brand focus:ring-1 focus:ring-brand outline-none text-sm font-medium transition @error('name') border-red-300 @enderror" placeholder="Nome da campanha">
            @error('name') <p class="text-[10px] font-bold text-red-500 mt-1">{{ $message }}</p> @enderror
        </div>

        <div class="space-y-2">
            <label class="text-[10px] font-bold uppercase tracking-widest text-slate-400">Slug</label>
            <input type="text" name="slug" value="{{ old('slug', $campaign->slug) }}" class="w-full px-4 py-3 rounded-xl border border-slate-200 focus:border-brand focus:ring-1 focus:ring-brand outline-none text-sm font-medium transition @error('slug') border-red-300 @enderror" placeholder="slug-da-campanha">
            <p class="text-[9px] text-slate-400 font-medium">Deixar vazio para gerar automaticamente</p>
            @error('slug') <p class="text-[10px] font-bold text-red-500 mt-1">{{ $message }}</p> @enderror
        </div>

        <div class="space-y-2">
            <label class="text-[10px] font-bold uppercase tracking-widest text-slate-400">Objetivo</label>
            <textarea name="objective" rows="4" class="w-full px-4 py-3 rounded-xl border border-slate-200 focus:border-brand focus:ring-1 focus:ring-brand outline-none text-sm font-medium transition @error('objective') border-red-300 @enderror" placeholder="Objetivo da campanha">{{ old('objective', $campaign->objective) }}</textarea>
            @error('objective') <p class="text-[10px] font-bold text-red-500 mt-1">{{ $message }}</p> @enderror
        </div>

        <div class="space-y-2">
            <label class="text-[10px] font-bold uppercase tracking-widest text-slate-400">Imagem</label>
            @if($campaign->image)
            <div class="mb-3">
                <img src="{{ asset('storage/' . $campaign->image) }}" class="w-40 h-24 rounded-xl object-cover border border-slate-100">
            </div>
            @endif
            <input type="file" name="image" class="w-full px-4 py-3 rounded-xl border border-slate-200 focus:border-brand focus:ring-1 focus:ring-brand outline-none text-sm font-medium transition file:mr-3 file:py-2 file:px-4 file:rounded-xl file:border-0 file:bg-brand/5 file:text-brand file:text-xs file:font-bold hover:file:bg-brand/10 @error('image') border-red-300 @enderror">
            @error('image') <p class="text-[10px] font-bold text-red-500 mt-1">{{ $message }}</p> @enderror
        </div>

        <div class="space-y-2">
            <label class="text-[10px] font-bold uppercase tracking-widest text-slate-400">Estado</label>
            <select name="status" class="w-full px-4 py-3 rounded-xl border border-slate-200 focus:border-brand focus:ring-1 focus:ring-brand outline-none text-sm font-medium transition bg-white @error('status') border-red-300 @enderror">
                <option value="draft" {{ old('status', $campaign->status->value) === 'draft' ? 'selected' : '' }}>Rascunho</option>
                <option value="published" {{ old('status', $campaign->status->value) === 'published' ? 'selected' : '' }}>Publicado</option>
                <option value="archived" {{ old('status', $campaign->status->value) === 'archived' ? 'selected' : '' }}>Arquivado</option>
            </select>
            @error('status') <p class="text-[10px] font-bold text-red-500 mt-1">{{ $message }}</p> @enderror
        </div>

        <div class="grid grid-cols-2 gap-4">
            <div class="space-y-2">
                <label class="text-[10px] font-bold uppercase tracking-widest text-slate-400">Início</label>
                <input type="date" name="starts_at" value="{{ old('starts_at', $campaign->starts_at ? $campaign->starts_at->format('Y-m-d') : '') }}" class="w-full px-4 py-3 rounded-xl border border-slate-200 focus:border-brand focus:ring-1 focus:ring-brand outline-none text-sm font-medium transition @error('starts_at') border-red-300 @enderror">
                @error('starts_at') <p class="text-[10px] font-bold text-red-500 mt-1">{{ $message }}</p> @enderror
            </div>
            <div class="space-y-2">
                <label class="text-[10px] font-bold uppercase tracking-widest text-slate-400">Fim</label>
                <input type="date" name="ends_at" value="{{ old('ends_at', $campaign->ends_at ? $campaign->ends_at->format('Y-m-d') : '') }}" class="w-full px-4 py-3 rounded-xl border border-slate-200 focus:border-brand focus:ring-1 focus:ring-brand outline-none text-sm font-medium transition @error('ends_at') border-red-300 @enderror">
                @error('ends_at') <p class="text-[10px] font-bold text-red-500 mt-1">{{ $message }}</p> @enderror
            </div>
        </div>

        <div class="flex items-center gap-3">
            <input type="checkbox" name="is_pinned" value="1" {{ old('is_pinned', $campaign->is_pinned) ? 'checked' : '' }} class="w-4 h-4 rounded border-slate-300 text-brand focus:ring-brand">
            <label class="text-xs font-bold text-slate-600">Campanha fixa (pinned)</label>
        </div>

        <div class="flex items-center gap-4 pt-4 border-t border-slate-100">
            <button type="submit" class="px-8 py-3 bg-brand hover:bg-brand-700 text-white font-bold text-xs uppercase tracking-widest rounded-xl transition-all shadow-md hover:shadow-lg">Atualizar Campanha</button>
            <a href="{{ route('admin.campaigns.index') }}" class="text-slate-400 hover:text-slate-600 text-xs font-bold uppercase tracking-widest transition">Cancelar</a>
        </div>
    </form>
</div>
@endsection