@php
    /** @var string $tutorId */
@endphp
@extends('layouts.pmar.theme')

@section('title', env('APP_NAME') . ' :: Cadastrar Animal')

@section('content')

<div class="container">
    @include("errors.messageFlash")

    <h1 class="mb-4">Cadastrar Animal</h1>

    <form action="{{ route('paginas.castracao.animals.store', ['tutor_id' => $tutor->id]) }}" method="POST">
    

        @csrf
        <input type="hidden" name="tutor_id" value="{{ $tutor->id }}">

        <div class="mb-3">
            <label for="nome_animal" class="form-label">Nome do Animal</label>
            <input type="text" name="nome_animal" id="nome_animal" class="form-control" value="{{ old('nome_animal') }}" required>
        </div>

        <div class="mb-3">
            <label for="especie" class="form-label">Espécie</label>
            <select name="especie" id="especie" class="form-select" required>
                @foreach(App\Enums\Especie::cases() as $especie)
                <option value="{{ $especie->name }}" {{ old('especie') == $especie->name ? 'selected' : '' }}>
                    {{ $especie->value }}
                </option>
                @endforeach
            </select>
        </div>

        <div class="mb-3">
            <label for="raca_id" class="form-label">Raça</label>
            <select name="raca_id" id="raca_id" class="form-select" required>
                <option value="" disabled selected>Selecione uma raça</option>
                @foreach($racas as $raca)
                <option value="{{ $raca->id }}" {{ old('raca_id') == $raca->id ? 'selected' : '' }}>
                    {{ $raca->nome_raca }}
                </option>
                @endforeach
            </select>
        </div>

        <div class="mb-3">
            <label for="sexo" class="form-label">Sexo</label>
            <select name="sexo" id="sexo" class="form-select" required>
                @foreach(App\Enums\SexoAnimal::cases() as $sexo)
                <option value="{{ $sexo->name }}" {{ old('sexo') == $sexo->name ? 'selected' : '' }}>
                    {{ $sexo->value }}
                </option>
                @endforeach
            </select>
        </div>

        <div class="mb-3">
            <label for="tipo" class="form-label">Tipo</label>
            <select name="tipo" id="tipo" class="form-select" required>
                @foreach(App\Enums\TipoAnimal::cases() as $tipo)
                <option value="{{ $tipo->value }}">{{ $tipo->value }}</option>
                @endforeach
            </select>
        </div>

        <div class="mb-3">
            <label for="peso" class="form-label">Peso (kg)</label>
            <input type="number" step="0.01" name="peso" id="peso" class="form-control" value="{{ old('peso') }}">
        </div>

        <div class="mb-3">
            <label for="idade" class="form-label">Idade</label>
            <input type="number" name="idade" id="idade" class="form-control" value="{{ old('idade') }}">
        </div>

        <div class="mb-3">
            <label for="idade_em" class="form-label">Idade em</label>
            <select name="idade_em" id="idade_em" class="form-select">
                @foreach(App\Enums\IdadeEm::cases() as $idade)
                <option value="{{ $idade->name }}" {{ old('idade_em') == $idade->name ? 'selected' : '' }}>
                    {{ $idade->value }}
                </option>
                @endforeach
            </select>
        </div>
        <div class="mb-3">
            <label for="status" class="form-label text-bold">Status</label>
            <select class="form-control @error('status') is-invalid @enderror" name="status" id="status">
                @foreach(App\Enums\StatusEnum::cases() as $status)
                <option value="{{ $status->name }}" {{ old('status') === $status->name ? 'selected' : '' }}>
                    {{ $status->value }}
                </option>
                @endforeach
            </select>
            @error('status')
            <small class="text-danger text-bold">{{ $message }}</small>
            @enderror
        </div>

        <button type="submit" class="btn btn-primary">Salvar</button>
    </form>
</div>

@endsection
