@extends('layouts.app')

@section('content')
<div class="container">
    <div class="row justify-content-center">
        <div class="col-md-8">
            <div class="card">
                <div class="card-header">Indicador</div>

                <div class="card-body">
                    <form method="POST" action="{{ route('indicatorSave') }}">
                        @csrf

                        <input type="hidden" name="indicator_id" value="{{ $indicator->indicator_id ?? null }}" />

                        <div class="row mb-3">
                            <label for="indicator_category_id" class="col-md-4 col-form-label text-md-end">Categoria</label>

                            <div class="col-md-6">
                                @php
                                $selected = old('indicator_category_id') ?? $indicator->indicator_category_id ?? null;
                                @endphp
                                <select name="indicator_category_id" id="indicator_category_id" class="form-control  @error('indicator_category_id') is-invalid @enderror">
                                    <option value="">-- Seleccionar Categoria --</option>
                                    @foreach($indicatorCategories as $indicatorCategory)
                                    <option value="{{ $indicatorCategory->indicator_category_id }}" {{ $selected == $indicatorCategory->indicator_category_id ? 'selected' : '' }}>{{ $indicatorCategory->name }}</option>
                                    @endforeach
                                </select>

                                @error('indicator_category_id')
                                <span class="invalid-feedback" role="alert">
                                    <strong>{{ $message }}</strong>
                                </span>
                                @enderror
                            </div>
                        </div>

                        <div class="row mb-3">
                            <label for="unit_id" class="col-md-4 col-form-label text-md-end">Unidad</label>

                            <div class="col-md-6">
                                @php
                                $selected = old('unit_id') ?? $indicator->unit_id ?? null;
                                @endphp
                                <select name="unit_id" id="unit_id" class="form-control  @error('unit_id') is-invalid @enderror">
                                    <option value="">-- Seleccionar Unidad --</option>
                                    @foreach($units as $unit)
                                    <option value="{{ $unit->unit_id }}" {{ $selected == $unit->unit_id ? 'selected' : '' }}>{{ $unit->name }}</option>
                                    @endforeach
                                </select>

                                @error('unit_id')
                                <span class="invalid-feedback" role="alert">
                                    <strong>{{ $message }}</strong>
                                </span>
                                @enderror
                            </div>
                        </div>

                        <div class="row mb-3">
                            <label for="name" class="col-md-4 col-form-label text-md-end">Nombre</label>

                            <div class="col-md-6">
                                <input id="name" type="text" class="form-control @error('name') is-invalid @enderror" name="name" value="{{ old('name') ?? $indicator->name ?? null }} " required autocomplete="name">

                                @error('name')
                                <span class="invalid-feedback" role="alert">
                                    <strong>{{ $message }}</strong>
                                </span>
                                @enderror
                            </div>
                        </div>

                        <div class="row mb-3">
                            <label for="description" class="col-md-4 col-form-label text-md-end">Descripción</label>

                            <div class="col-md-6">
                                <input id="description" type="text" class="form-control @error('description') is-invalid @enderror" name="description" value="{{ old('description') ?? $indicator->description ?? null }} " required autocomplete="description">

                                @error('description')
                                <span class="invalid-feedback" role="alert">
                                    <strong>{{ $message }}</strong>
                                </span>
                                @enderror
                            </div>
                        </div>

                        <div class="row mb-3">
                            <label for="type" class="col-md-4 col-form-label text-md-end">Tipo</label>

                            <div class="col-md-6">
                                <input id="type" type="text" class="form-control @error('type') is-invalid @enderror" name="type" value="{{ old('type') ?? $indicator->type ?? null }} " required autocomplete="type">

                                @error('type')
                                <span class="invalid-feedback" role="alert">
                                    <strong>{{ $message }}</strong>
                                </span>
                                @enderror
                            </div>
                        </div>


                        <div class="row mb-0">
                            <div class="col-md-6 offset-md-4">
                                <button type="submit" class="btn btn-primary">
                                    Guardar
                                </button>
                                <a href="{{ route('indicators') }}">Cancel</a>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection