@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">
          Modificar Distrito
        </h1>
        <h2 class="fs-base lh-base fw-medium text-muted mb-0">
          Actualizando la configuración del registro <span class="text-warning fw-bold">#{{ $distrito->id }}</span>.
        </h2>
      </div>
      <nav class="flex-shrink-0 mt-3 mt-sm-0 ms-sm-3" aria-label="breadcrumb">
        <ol class="breadcrumb breadcrumb-alt">
          <li class="breadcrumb-item">
            <a class="link-fx" href="{{ route('distritos.index') }}">Distritos</a>
          </li>
          <li class="breadcrumb-item" aria-current="page">
            Modificar
          </li>
        </ol>
      </nav>
    </div>
  </div>
</div>
<div class="content">
  <div class="row justify-content-center">
    <div class="col-md-10 col-lg-8">
      
      <div class="block block-rounded">
        <div class="block-header block-header-default">
          <h3 class="block-title">
            <i class="fa fa-pencil-alt me-1 text-warning"></i> Editar Parámetros
          </h3>
          <div class="block-options">
            <button type="button" class="btn-block-option" data-toggle="block-option" data-action="state_toggle" data-action-mode="demo">
              <i class="si si-refresh"></i>
            </button>
          </div>
        </div>
        <div class="block-content">
          {{-- Alertas de validación --}}
          @if($errors->any())
            <div class="alert alert-danger alert-dismissible" role="alert">
              <p class="mb-1 fs-sm fw-bold">Hubo algunos problemas con su entrada:</p>
              <ul class="mb-0 fs-sm">
                @foreach($errors->all() as $e) <li>{{ $e }}</li> @endforeach
              </ul>
              <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
            </div>
          @endif

          <form method="POST" action="{{ route('distritos.update', $distrito->id) }}">
            @csrf 
            @method('PUT')

            <div class="row push">
              <div class="col-12">
                {{-- Se incluye el formulario parcial --}}
                @include('distritos._form', ['distrito' => $distrito])
              </div>
            </div>

            <div class="block-content block-content-full block-content-sm bg-body-light text-end rounded-bottom mb-4">
              <a href="{{ route('distritos.show', $distrito->id) }}" class="btn btn-alt-secondary me-1">
                <i class="fa fa-times me-1"></i> Cancelar
              </a>
              <button type="submit" class="btn btn-alt-warning"
                      onclick="return confirm('¿Está seguro de guardar los cambios?')">
                <i class="fa fa-save me-1"></i> Actualizar Cambios
              </button>
            </div>
          </form>
        </div>
      </div>
      <div class="alert alert-warning d-flex align-items-center" role="alert">
        <div class="flex-shrink-0">
          <i class="fa fa-fw fa-exclamation-circle fa-2x opacity-50"></i>
        </div>
        <div class="flex-grow-1 ms-3">
          <p class="mb-0 fs-sm">
            Tenga en cuenta que los cambios en los <strong>precios y porcentajes</strong> afectarán a los nuevos cálculos realizados a partir de este momento.
          </p>
        </div>
      </div>

    </div>
  </div>
</div>
@endsection