@extends('admin.layouts.app')
@section('title', isset($testimonio) ? 'Editar Testimonio' : 'Nuevo Testimonio')
@section('icon', 'people-fill')
@section('page-title', isset($testimonio) ? 'Editar Testimonio' : 'Nuevo Testimonio')

@section('content')
<div class="page-header">
    <div class="page-header-left">
        <h1><i class="bi bi-people-fill"></i> {{ isset($testimonio) ? 'Editar' : 'Nuevo' }} Testimonio</h1>
    </div>
    <a href="{{ route('admin.testimonios.index') }}" class="btn btn-secondary"><i class="bi bi-arrow-left"></i> Volver</a>
</div>
<div class="card"><div class="card-body">
    <form action="{{ isset($testimonio) ? route('admin.testimonios.update', $testimonio) : route('admin.testimonios.store') }}" method="POST" enctype="multipart/form-data">
        @csrf @if(isset($testimonio)) @method('PUT') @endif
        <div class="form-row">
            <div class="form-group">
                <label class="form-label">Nombre Completo <span class="required">*</span></label>
                <input type="text" name="nombre" class="form-control" value="{{ old('nombre', $testimonio->nombre ?? '') }}" required>
            </div>
            <div class="form-group">
                <label class="form-label">Cargo</label>
                <input type="text" name="cargo" class="form-control" value="{{ old('cargo', $testimonio->cargo ?? '') }}" placeholder="Director, Gerente...">
            </div>
        </div>
        <div class="form-row">
            <div class="form-group">
                <label class="form-label">Empresa / Institución</label>
                <input type="text" name="empresa" class="form-control" value="{{ old('empresa', $testimonio->empresa ?? '') }}">
            </div>
            <div class="form-group">
                <label class="form-label">Estrellas (1-5)</label>
                <select name="estrellas" class="form-control">
                    @for($i=5;$i>=1;$i--)
                    <option value="{{ $i }}" {{ old('estrellas', $testimonio->estrellas ?? 5) == $i ? 'selected' : '' }}>{{ str_repeat('⭐', $i) }} ({{ $i }})</option>
                    @endfor
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="form-label">Mensaje / Testimonio <span class="required">*</span></label>
            <textarea name="mensaje" class="form-control" rows="4" required>{{ old('mensaje', $testimonio->mensaje ?? '') }}</textarea>
        </div>
        <div class="form-row">
            <div class="form-group">
                <label class="form-label">Avatar / Foto</label>
                @if(isset($testimonio) && $testimonio->avatar)<img src="{{ asset('storage/'.$testimonio->avatar) }}" style="width:60px;height:60px;border-radius:50%;object-fit:cover;display:block;margin-bottom:.5rem;">@endif
                <input type="file" name="avatar" class="form-control" accept="image/*">
            </div>
            <div class="form-group">
                <label class="form-label">Orden</label>
                <input type="number" name="orden" class="form-control" value="{{ old('orden', $testimonio->orden ?? 0) }}" min="0">
                <div style="margin-top:1rem;"><label class="form-check"><input type="checkbox" name="activo" value="1" {{ old('activo', $testimonio->activo ?? true) ? 'checked' : '' }}> Activo</label></div>
            </div>
        </div>
        <div style="display:flex;gap:1rem;justify-content:flex-end;">
            <a href="{{ route('admin.testimonios.index') }}" class="btn btn-secondary">Cancelar</a>
            <button type="submit" class="btn btn-primary"><i class="bi bi-save-fill"></i> {{ isset($testimonio) ? 'Actualizar' : 'Guardar' }}</button>
        </div>
    </form>
</div></div>
@endsection
