@extends('layouts.app')

@section('title', isset($operationDetails) ? 'Edit Operation Details' : 'Add 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 items-center justify-between">
                <div>
                    <h1 class="text-3xl font-bold text-gray-800">
                        {{ isset($operationDetails) ? 'Edit Operation Details' : 'Add Operation Details' }}
                    </h1>
                    <p class="text-gray-600">Step 3: Provide information about your fishing operations</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 ($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

        <!-- Form -->
        <div class="bg-white rounded-lg shadow-md p-8">
            @if(isset($operationDetails))
                <form method="POST" action="{{ route('applicant.operation.update', $operationDetails->id) }}" enctype="multipart/form-data">
                    @method('PUT')
            @else
                <form method="POST" action="{{ route('applicant.operation.store') }}" enctype="multipart/form-data">
            @endif
                @csrf
                
                <div class="space-y-6">
                    <!-- Supplying Companies -->
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-1">Supplying Companies</label>
                        <textarea name="supplying_companies" rows="3"
                            placeholder="List the companies you supply to"
                            class="w-full px-4 py-2 border rounded-lg focus:ring-2 focus:ring-indigo-500">{{ isset($operationDetails) ? $operationDetails->supplying_companies : old('supplying_companies') }}</textarea>
                        <p class="text-xs text-gray-500 mt-1">Optional: Name the companies or buyers you supply fish to</p>
                    </div>

                    <!-- Harvest Islands -->
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-1">Harvest Islands</label>
                        <textarea name="harvest_islands" rows="3"
                            placeholder="e.g., Malé Atoll, Ari Atoll"
                            class="w-full px-4 py-2 border rounded-lg focus:ring-2 focus:ring-indigo-500">{{ isset($operationDetails) ? $operationDetails->harvest_islands : old('harvest_islands') }}</textarea>
                        <p class="text-xs text-gray-500 mt-1">Optional: List the islands/atolls where you harvest fish</p>
                    </div>

                    <!-- Target Species -->
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-1">Target Species</label>
                        <textarea name="target_species" rows="3"
                            placeholder="e.g., Skipjack tuna, Yellowfin tuna, Grouper"
                            class="w-full px-4 py-2 border rounded-lg focus:ring-2 focus:ring-indigo-500">{{ isset($operationDetails) ? $operationDetails->target_species : old('target_species') }}</textarea>
                        <p class="text-xs text-gray-500 mt-1">Optional: List the fish species you target</p>
                    </div>

                    <!-- Fishing Grounds -->
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-1">Fishing Grounds</label>
                        <textarea name="fishing_grounds" rows="3"
                            placeholder="Describe the areas where you fish"
                            class="w-full px-4 py-2 border rounded-lg focus:ring-2 focus:ring-indigo-500">{{ isset($operationDetails) ? $operationDetails->fishing_grounds : old('fishing_grounds') }}</textarea>
                        <p class="text-xs text-gray-500 mt-1">Optional: Describe the fishing areas/grounds</p>
                    </div>

                    <!-- Fishing Gears & Methods -->
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-1">Fishing Gears & Methods</label>
                        <textarea name="fishing_gears_methods" rows="3"
                            placeholder="e.g., Pole and line, Longline, Handline"
                            class="w-full px-4 py-2 border rounded-lg focus:ring-2 focus:ring-indigo-500">{{ isset($operationDetails) ? $operationDetails->fishing_gears_methods : old('fishing_gears_methods') }}</textarea>
                        <p class="text-xs text-gray-500 mt-1">Optional: Describe the fishing methods and gear you use</p>
                    </div>

                    <!-- Processing Methods -->
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-1">Processing Methods</label>
                        <textarea name="processing_methods" rows="3"
                            placeholder="e.g., Fresh storage, Freezing, Smoking, Drying"
                            class="w-full px-4 py-2 border rounded-lg focus:ring-2 focus:ring-indigo-500">{{ isset($operationDetails) ? $operationDetails->processing_methods : old('processing_methods') }}</textarea>
                        <p class="text-xs text-gray-500 mt-1">Optional: Describe how you process/store the fish</p>
                    </div>

                    <!-- Number of Fishing Days -->
                    <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" min="0"
                            value="{{ isset($operationDetails) ? $operationDetails->number_of_fishing_days : old('number_of_fishing_days') }}"
                            placeholder="e.g., 250"
                            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">Optional: Average number of days you fish per year</p>
                    </div>

                    <!-- Business Plan Upload -->
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-1">Business Plan</label>
                        <input type="file" name="business_plan_path" accept="image/*,.pdf"
                            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">Optional: Upload your business plan (PDF or Image, max 5MB)</p>
                        
                        @if(isset($operationDetails) && $operationDetails->business_plan_path)
                            <div class="mt-2 p-2 bg-green-50 border border-green-200 rounded">
                                <p class="text-sm text-green-700">
                                    ✓ Current file: 
                                    <a href="{{ Storage::url($operationDetails->business_plan_path) }}" 
                                       target="_blank" 
                                       class="underline hover:text-green-900">
                                        View Document
                                    </a>
                                </p>
                            </div>
                        @endif
                    </div>

                    <!-- Submit Button -->
                    <div class="pt-4 border-t">
                        <button type="submit" 
                                class="w-full bg-indigo-600 text-white px-6 py-3 rounded-lg hover:bg-indigo-700 font-semibold text-lg">
                            {{ isset($operationDetails) ? 'Update Operation Details' : 'Save & Continue to Vessel Details →' }}
                        </button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
@endsection