@extends('layouts.app')

@section('title', 'Edit Operation Details')

@section('content')
<div class="min-h-screen bg-gray-50 p-6">
    <div class="max-w-4xl mx-auto">
        <!-- Header -->
        <div class="bg-white rounded-lg shadow-md p-6 mb-6">
            <div class="flex justify-between items-center">
                <div>
                    <h1 class="text-3xl font-bold text-gray-800">Edit Operation Details</h1>
                    <p class="text-gray-600">Update your operation information</p>
                </div>
                <a href="{{ route('applicant.dashboard') }}" 
                   class="bg-gray-600 text-white px-4 py-2 rounded-lg hover:bg-gray-700">
                    ← Back to Dashboard
                </a>
            </div>
        </div>

        @if (session('success'))
            <div class="bg-green-100 border border-green-400 text-green-700 px-4 py-3 rounded mb-4">
                {{ session('success') }}
            </div>
        @endif

        @if (session('error'))
            <div class="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded mb-4">
                {{ session('error') }}
            </div>
        @endif

        @if ($errors->any())
            <div class="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded mb-4">
                <ul class="list-disc list-inside">
                    @foreach ($errors->all() as $error)
                        <li>{{ $error }}</li>
                    @endforeach
                </ul>
            </div>
        @endif

        <!-- Edit Form -->
        <div class="bg-white rounded-lg shadow-md p-8">
            <form method="POST" action="{{ route('applicant.operation.update', $operationDetails->id) }}" enctype="multipart/form-data" class="space-y-4">
                @csrf
                @method('PUT')
                
                <div>
                    <label class="block text-sm font-medium text-gray-700 mb-1">Supplying Companies *</label>
                    <textarea name="supplying_companies" rows="3" required
                        placeholder="List the companies you supply to"
                        class="w-full px-4 py-2 border rounded-lg focus:ring-2 focus:ring-indigo-500">{{ old('supplying_companies', $operationDetails->supplying_companies) }}</textarea>
                    <p class="text-xs text-gray-500 mt-1">Enter names of companies or buyers you supply fish to</p>
                </div>
                
                <div>
                    <label class="block text-sm font-medium text-gray-700 mb-1">Harvest Islands *</label>
                    <textarea name="harvest_islands" rows="2" required
                        placeholder="e.g., North Malé Atoll, Ari Atoll, Baa Atoll"
                        class="w-full px-4 py-2 border rounded-lg focus:ring-2 focus:ring-indigo-500">{{ old('harvest_islands', $operationDetails->harvest_islands) }}</textarea>
                    <p class="text-xs text-gray-500 mt-1">List the islands or atolls where you harvest</p>
                </div>
                
                <div>
                    <label class="block text-sm font-medium text-gray-700 mb-1">Target Species *</label>
                    <textarea name="target_species" rows="2" required
                        placeholder="e.g., Skipjack Tuna, Yellowfin Tuna, Reef Fish"
                        class="w-full px-4 py-2 border rounded-lg focus:ring-2 focus:ring-indigo-500">{{ old('target_species', $operationDetails->target_species) }}</textarea>
                    <p class="text-xs text-gray-500 mt-1">List the main fish species you target</p>
                </div>
                
                <div>
                    <label class="block text-sm font-medium text-gray-700 mb-1">Fishing Grounds *</label>
                    <textarea name="fishing_grounds" rows="3" required
                        placeholder="Describe the areas where you conduct fishing operations"
                        class="w-full px-4 py-2 border rounded-lg focus:ring-2 focus:ring-indigo-500">{{ old('fishing_grounds', $operationDetails->fishing_grounds) }}</textarea>
                    <p class="text-xs text-gray-500 mt-1">Specify the geographical areas of your fishing operations</p>
                </div>
                
                <div>
                    <label class="block text-sm font-medium text-gray-700 mb-1">Fishing Gears & Methods *</label>
                    <textarea name="fishing_gears_methods" rows="3" required
                        placeholder="e.g., Pole and Line, Longlining, Hand Line, etc."
                        class="w-full px-4 py-2 border rounded-lg focus:ring-2 focus:ring-indigo-500">{{ old('fishing_gears_methods', $operationDetails->fishing_gears_methods) }}</textarea>
                    <p class="text-xs text-gray-500 mt-1">Describe the fishing gears and methods you use</p>
                </div>
                
                <div>
                    <label class="block text-sm font-medium text-gray-700 mb-1">Processing Methods *</label>
                    <textarea name="processing_methods" rows="3" required
                        placeholder="e.g., Fresh, Frozen, Dried, Smoked, Canned"
                        class="w-full px-4 py-2 border rounded-lg focus:ring-2 focus:ring-indigo-500">{{ old('processing_methods', $operationDetails->processing_methods) }}</textarea>
                    <p class="text-xs text-gray-500 mt-1">Describe how you process the fish after harvest</p>
                </div>
                
                <div>
                    <label class="block text-sm font-medium text-gray-700 mb-1">Number of Fishing Days (per year) *</label>
                    <input type="number" name="number_of_fishing_days" required min="1" max="365"
                        value="{{ old('number_of_fishing_days', $operationDetails->number_of_fishing_days) }}"
                        placeholder="e.g., 200"
                        class="w-full px-4 py-2 border rounded-lg focus:ring-2 focus:ring-indigo-500">
                    <p class="text-xs text-gray-500 mt-1">Estimated number of days spent fishing per year</p>
                </div>
                
                <!-- Business Plan Document -->
                <div class="border-t pt-4 mt-6">
                    <h3 class="text-lg font-semibold text-gray-800 mb-4">Update Business Plan (Optional)</h3>
                    <p class="text-sm text-gray-600 mb-4">Leave blank to keep existing document. Upload new file only if you need to replace it.</p>
                    
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-1">Business Plan Document</label>
                        @if($operationDetails->business_plan_path)
                            <p class="text-xs text-green-600 mb-2">✓ Current file: {{ basename($operationDetails->business_plan_path) }}</p>
                        @endif
                        <input type="file" name="business_plan_path" accept="image/*,.pdf,.doc,.docx"
                            class="w-full px-4 py-2 border rounded-lg focus:ring-2 focus:ring-indigo-500">
                        <p class="text-xs text-gray-500 mt-1">Upload your business plan (PDF, DOC, DOCX, or image)</p>
                    </div>
                </div>

                <div class="flex gap-4 pt-4">
                    <a href="{{ route('applicant.dashboard') }}"
                       class="flex-1 text-center bg-gray-200 text-gray-800 px-6 py-3 rounded-lg hover:bg-gray-300 font-semibold text-lg">
                        Cancel
                    </a>
                    <button type="submit" 
                            class="flex-1 bg-indigo-600 text-white px-6 py-3 rounded-lg hover:bg-indigo-700 font-semibold text-lg">
                        Update Operation Details
                    </button>
                </div>
            </form>
        </div>
    </div>
</div>
@endsection