<x-app-layout>
    <x-slot:heading>Log Mortality</x-slot:heading>

    <div class="max-w-xl">
        <div class="rounded-xl border border-gray-100 bg-white p-6 shadow-sm">
            <form method="POST" action="{{ route('health.mortality.store') }}" class="space-y-5">
                @csrf

                <div class="grid grid-cols-2 gap-4">
                    <div class="col-span-2">
                        <label class="block text-sm font-medium text-gray-700 mb-1">Pond <span class="text-red-500">*</span></label>
                        <select name="pond_id" class="w-full rounded-lg border-gray-200 text-sm focus:border-primary-500 focus:ring-primary-500">
                            <option value="">Select pond…</option>
                            @foreach($ponds as $pond)
                                <option value="{{ $pond->id }}" @selected($selectedPondId == $pond->id)>{{ $pond->name }}</option>
                            @endforeach
                        </select>
                        @error('pond_id') <p class="mt-1 text-xs text-red-500">{{ $message }}</p> @enderror
                    </div>
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-1">Date <span class="text-red-500">*</span></label>
                        <input type="date" name="log_date" value="{{ old('log_date', today()->toDateString()) }}"
                               max="{{ today()->toDateString() }}"
                               class="w-full rounded-lg border-gray-200 text-sm focus:border-primary-500 focus:ring-primary-500">
                    </div>
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-1">Dead Count <span class="text-red-500">*</span></label>
                        <input type="number" name="dead_count" value="{{ old('dead_count') }}" min="1"
                               class="w-full rounded-lg border-gray-200 text-sm focus:border-primary-500 focus:ring-primary-500">
                        @error('dead_count') <p class="mt-1 text-xs text-red-500">{{ $message }}</p> @enderror
                    </div>
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-1">Est. Avg Weight (g)</label>
                        <input type="number" name="estimated_avg_weight_g" value="{{ old('estimated_avg_weight_g') }}"
                               step="0.1" min="0.1"
                               class="w-full rounded-lg border-gray-200 text-sm focus:border-primary-500 focus:ring-primary-500">
                    </div>
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-1">Probable Cause</label>
                        <select name="probable_cause" class="w-full rounded-lg border-gray-200 text-sm focus:border-primary-500 focus:ring-primary-500">
                            <option value="">— Select —</option>
                            @foreach($probableCauses as $opt)
                                <option value="{{ $opt->value }}" @selected(old('probable_cause') === $opt->value)>{{ $opt->label }}</option>
                            @endforeach
                        </select>
                    </div>
                </div>

                <div>
                    <label class="block text-sm font-medium text-gray-700 mb-1">Symptoms Observed</label>
                    <textarea name="symptoms_observed" rows="2"
                              class="w-full rounded-lg border-gray-200 text-sm focus:border-primary-500 focus:ring-primary-500"
                              placeholder="e.g. Lesions, erratic swimming, white patches…">{{ old('symptoms_observed') }}</textarea>
                </div>

                <div>
                    <label class="block text-sm font-medium text-gray-700 mb-1">Notes</label>
                    <textarea name="notes" rows="2"
                              class="w-full rounded-lg border-gray-200 text-sm focus:border-primary-500 focus:ring-primary-500">{{ old('notes') }}</textarea>
                </div>

                <div class="flex items-center gap-3 border-t border-gray-100 pt-4">
                    <button type="submit"
                            class="inline-flex items-center gap-2 rounded-lg bg-primary-600 px-5 py-2 text-sm font-semibold text-white hover:bg-primary-700">
                        Log Mortality
                    </button>
                    <a href="{{ route('health.index') }}" class="text-sm text-gray-500 hover:text-gray-700">Cancel</a>
                </div>
            </form>
        </div>
    </div>
</x-app-layout>
