@extends('layouts.app')

@section('content')
<div class="bg-body-light">
    <div class="content content-full">
        <div class="d-flex flex-column flex-sm-row justify-content-sm-between align-items-sm-center py-2">
            <div class="flex-grow-1">
                <h1 class="h3 fw-bold mb-2">
                    <i class="fa fa-user-edit text-warning me-2"></i>Editar {{ $tipo === 'vendedores' ? 'Vendedor' : 'Cobrador' }}
                </h1>
                <h2 class="fs-base lh-base fw-medium text-muted mb-0">
                    Actualizando registro <span class="nav-main-link-badge badge bg-warning text-dark">#{{ $registro->id }}</span>
                </h2>
            </div>
            <div class="flex-shrink-0 mt-3 mt-sm-0 ms-sm-3">
                <a href="{{ route('cobradores-vendedores.show', ['id' => $registro->id, 'tipo' => $tipo]) }}" class="btn btn-alt-secondary">
                    <i class="fa fa-arrow-left me-1"></i> Cancelar y volver
                </a>
            </div>
        </div>
    </div>
</div>

<div class="content">
    <div class="row justify-content-center">
        <div class="col-md-10 col-lg-8">
            {{-- Errores de Validación --}}
            @if($errors->any())
                <div class="alert alert-danger d-flex align-items-center mb-4" role="alert">
                    <div class="flex-shrink-0">
                        <i class="fa fa-fw fa-times-circle"></i>
                    </div>
                    <div class="flex-grow-1 ms-3">
                        <p class="mb-0 fw-semibold">Por favor, revise los siguientes errores:</p>
                        <ul class="mb-0 fs-sm">
                            @foreach($errors->all() as $e) <li>{{ $e }}</li> @endforeach
                        </ul>
                    </div>
                </div>
            @endif

            <div class="block block-rounded block-bordered">
                <div class="block-header block-header-default">
                    <h3 class="block-title">Formulario de Modificación</h3>
                    <div class="block-options">
                        <span class="nav-main-link-badge badge bg-primary-light text-primary">
                            <i class="fa fa-clock me-1"></i> Editando ahora
                        </span>
                    </div>
                </div>
                <div class="block-content block-content-full">
                    <form method="POST" action="{{ route('cobradores-vendedores.update', ['id' => $registro->id, 'tipo' => $tipo]) }}">
                        @csrf @method('PUT')
                        <input type="hidden" name="tipo" value="{{ $tipo }}">

                        {{-- Metadata del Registro --}}
                        <div class="row mb-4 bg-body-light p-3 rounded-3 mx-0">
                            <div class="col-sm-6 mb-2 mb-sm-0">
                                <label class="form-label fs-xs text-uppercase text-muted fw-bold">Código de Sistema</label>
                                <div class="input-group">
                                    <span class="input-group-text bg-white border-0"><i class="fa fa-lock text-muted"></i></span>
                                    <input type="text" class="form-control form-control-alt fw-bold border-0" 
                                           value="{{ $registro->id }}" readonly>
                                </div>
                            </div>
                            <div class="col-sm-6">
                                <label class="form-label fs-xs text-uppercase text-muted fw-bold" for="fecha">Fecha de Ingreso</label>
                                <div class="input-group">
                                    <span class="input-group-text bg-white border-0"><i class="fa fa-calendar-alt text-muted"></i></span>
                                    <input type="text" class="form-control form-control-alt border-0"
                                           name="fecha" id="fecha"
                                           value="{{ old('fecha', \App\Helpers\FechaHelper::bdToLocal($registro->fecha)) }}"
                                           maxlength="10" placeholder="dd/mm/aaaa">
                                </div>
                            </div>
                        </div>

                        {{-- Inclusión del formulario base --}}
                        @include('cobradores_vendedores._form', ['registro' => $registro])

                        <div class="block-content block-content-full block-content-sm bg-body-light mx-n4 mb-n4 mt-4 text-end">
                            <a href="{{ route('cobradores-vendedores.show', ['id' => $registro->id, 'tipo' => $tipo]) }}" 
                               class="btn btn-alt-secondary">
                                Descartar Cambios
                            </a>
                            <button type="submit" class="btn btn-warning px-4" onclick="return confirm('¿Confirmar la actualización de datos?')">
                                <i class="fa fa-save me-1"></i> Guardar Cambios
                            </button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection