<x-app-layout>
    <x-slot:heading>Record Harvest</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('harvest.store') }}" class="space-y-5">
                @csrf

                <div>
                    <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 }} ({{ $pond->pond_code }})
                            </option>
                        @endforeach
                    </select>
                    @error('pond_id') <p class="mt-1 text-xs text-red-500">{{ $message }}</p> @enderror
                </div>

                <div class="grid grid-cols-2 gap-4">
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-1">Harvest Date <span class="text-red-500">*</span></label>
                        <input type="date" name="harvest_date" value="{{ old('harvest_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">Harvest Type <span class="text-red-500">*</span></label>
                        <select name="harvest_type" class="w-full rounded-lg border-gray-200 text-sm focus:border-primary-500 focus:ring-primary-500">
                            @foreach($harvestTypes as $opt)
                                <option value="{{ $opt->value }}" @selected(old('harvest_type') === $opt->value)>{{ $opt->label }}</option>
                            @endforeach
                        </select>
                    </div>
                </div>

                <div class="grid grid-cols-2 gap-4">
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-1">Total Weight (kg) <span class="text-red-500">*</span></label>
                        <input type="number" name="total_weight_kg" value="{{ old('total_weight_kg') }}"
                               step="0.01" min="0.01"
                               class="w-full rounded-lg border-gray-200 text-sm focus:border-primary-500 focus:ring-primary-500">
                        @error('total_weight_kg') <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">Fish Harvested (count) <span class="text-red-500">*</span></label>
                        <input type="number" name="total_fish_harvested" value="{{ old('total_fish_harvested') }}"
                               min="1"
                               class="w-full rounded-lg border-gray-200 text-sm focus:border-primary-500 focus:ring-primary-500">
                    </div>
                </div>

                <div>
                    <label class="block text-sm font-medium text-gray-700 mb-1">Notes</label>
                    <textarea name="harvest_notes" rows="2"
                              class="w-full rounded-lg border-gray-200 text-sm focus:border-primary-500 focus:ring-primary-500">{{ old('harvest_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">
                        Record Harvest
                    </button>
                    <a href="{{ route('harvest.index') }}" class="text-sm text-gray-500 hover:text-gray-700">Cancel</a>
                </div>
            </form>
        </div>
    </div>
</x-app-layout>
