@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">
          Detalle del Distrito
        </h1>
        <h2 class="fs-base lh-base fw-medium text-muted mb-0">
          Visualización de parámetros y costos configurados para {{ $distrito->nombre }}.
        </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">
            Vista Detallada
          </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-map-marker-alt me-1 text-muted"></i> Información General
          </h3>
          <div class="block-options">
            <span class="badge bg-primary px-3 py-2">Código #{{ $distrito->id }}</span>
          </div>
        </div>
        <div class="block-content">
          <div class="row items-push">
            <div class="col-md-6">
              <address class="fs-sm">
                <div class="fw-bold text-uppercase mb-2 text-primary border-bottom pb-1">Identificación</div>
                <div class="mb-3">
                  <span class="fw-semibold d-block">Nombre completo:</span>
                  <span class="text-muted">{{ $distrito->nombre }}</span>
                </div>
                <div class="mb-3">
                  <span class="fw-semibold d-block">Nombre corto:</span>
                  <span class="text-muted">{{ $distrito->nomcorto ?: '—' }}</span>
                </div>
                <div class="mb-0">
                  <span class="fw-semibold d-block">Urbanización asociada:</span>
                  @if($distrito->urbanizacion)
                    <span class="badge bg-info-light text-info">
                      <i class="fa fa-building me-1"></i> {{ $distrito->urbanizacion->nombre }}
                    </span>
                  @else
                    <span class="text-muted italic">No asignada</span>
                  @endif
                </div>
              </address>
            </div>

            <div class="col-md-6">
              <div class="fw-bold text-uppercase mb-2 text-primary border-bottom pb-1">Tasas y Costos</div>
              <ul class="list-unstyled fs-sm">
                <li class="d-flex justify-content-between mb-2">
                  <span class="fw-semibold"><i class="fa fa-road me-2 text-muted"></i> Precio Calle:</span>
                  <span class="text-dark fw-bold">{{ number_format($distrito->Calle, 2) }}</span>
                </li>
                <li class="d-flex justify-content-between mb-2">
                  <span class="fw-semibold"><i class="fa fa-car-side me-2 text-muted"></i> Precio Avenida:</span>
                  <span class="text-dark fw-bold">{{ number_format($distrito->Avenida, 2) }}</span>
                </li>
                <li class="d-flex justify-content-between mb-2">
                  <span class="fw-semibold"><i class="fa fa-leaf me-2 text-muted"></i> Precio Área Verde:</span>
                  <span class="text-dark fw-bold">{{ number_format($distrito->AreaVerde, 2) }}</span>
                </li>
                <li class="d-flex justify-content-between pt-2 border-top">
                  <span class="fw-semibold"><i class="fa fa-percentage me-2 text-muted"></i> Porcentaje de Costo:</span>
                  <span class="badge bg-warning-light text-warning fw-bold">{{ $distrito->Costporc }}%</span>
                </li>
              </ul>
            </div>
          </div>
        </div>

        <div class="block-content block-content-full block-content-sm bg-body-light rounded-bottom">
          <div class="row g-sm">
            <div class="col-6">
              <a href="{{ route('distritos.index') }}" class="btn btn-alt-secondary">
                <i class="fa fa-arrow-left me-1"></i> Volver al listado
              </a>
            </div>
            <div class="col-6 text-end">
              @if(auth()->user()->tipo == 1)
                <div class="btn-group" role="group">
                  <a href="{{ route('distritos.edit', $distrito->id) }}" class="btn btn-alt-warning">
                    <i class="fa fa-pencil-alt me-1"></i> Modificar
                  </a>
                  <button type="button" class="btn btn-alt-danger" onclick="confirmDelete()">
                    <i class="fa fa-trash me-1"></i> Eliminar
                  </button>
                </div>
                
                <form id="delete-form" method="POST" action="{{ route('distritos.destroy', $distrito->id) }}" style="display:none;">
                  @csrf @method('DELETE')
                </form>
              @endif
            </div>
          </div>
        </div>
      </div>
      </div>
  </div>
</div>
@endsection

@push('scripts')
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<script>
  function confirmDelete() {
    Swal.fire({
      title: '¿Está seguro?',
      text: "Esta acción eliminará permanentemente el distrito {{ $distrito->nombre }}.",
      icon: 'warning',
      showCancelButton: true,
      confirmButtonColor: '#d33',
      cancelButtonColor: '#6c757d',
      confirmButtonText: 'Sí, eliminar',
      cancelButtonText: 'Cancelar'
    }).then((result) => {
      if (result.isConfirmed) {
        document.getElementById('delete-form').submit();
      }
    })
  }
</script>
@endpush