@extends('layouts.app')

@section('content')
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
    <div class="bg-white overflow-hidden shadow sm:rounded-lg">
        <div class="px-4 py-5 sm:px-6">
            <h3 class="text-lg leading-6 font-medium text-gray-900">
                Submit Industrial Visit Details
            </h3>
            <p class="mt-1 max-w-2xl text-sm text-gray-500">
                Fill in the details of the industrial visit you organised.
            </p>
        </div>
        <div class="border-t border-gray-200">
            <form method="POST" action="{{ route('faculty.IvOrganisedFormResponse') }}" enctype="multipart/form-data">
                @csrf
                <div class="px-4 py-5 sm:px-6">
                    <div class="space-y-6">

                        <!-- Company Name -->
                        <div>
                            <label for="company_name" class="block text-sm font-medium text-gray-700">Name of the Company/Field/Institute</label>
                            <input type="text" name="company_name" id="company_name" class="block w-full mt-1 border-gray-300 rounded-md shadow-sm focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm" required>
                        </div>

                        <!-- Company Address -->
                        <div>
                            <label for="company_address" class="block text-sm font-medium text-gray-700">Address of the Company/Field/Institute</label>
                            <input type="text" name="company_address" id="company_address" class="block w-full mt-1 border-gray-300 rounded-md shadow-sm focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm" required>
                        </div>

                        <!-- Resource Person Details -->
                        <div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
                            <div>
                                <label for="resource_person_name" class="block text-sm font-medium text-gray-700">Resource Person Name</label>
                                <input type="text" name="resource_person_name" id="resource_person_name" class="block w-full mt-1 border-gray-300 rounded-md shadow-sm focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm" required>
                            </div>
                            <div>
                                <label for="resource_person_contact_details" class="block text-sm font-medium text-gray-700">Resource Person Contact Details</label>
                                <input type="text" name="resource_person_contact_details" id="resource_person_contact_details" class="block w-full mt-1 border-gray-300 rounded-md shadow-sm focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm" required>
                            </div>
                        </div>

                        <!-- Target Audience and Student Year -->
                        <div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
                            <div>
                                <label for="target_audience" class="block text-sm font-medium text-gray-700">Target Audience</label>
                                <select name="target_audience" id="target_audience" class="block w-full mt-1 border-gray-300 rounded-md shadow-sm focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm" required onchange="toggleStudentYear()">
                                    <option value="">Select</option>
                                    <option value="faculty">Faculty</option>
                                    <option value="student">Student</option>
                                    <option value="both">Both</option>
                                </select>
                            </div>
                            <div id="student_year_container" class="hidden">
                                <label for="student_year" class="block text-sm font-medium text-gray-700">Year of Study</label>
                                <input type="text" name="student_year" id="student_year" class="block w-full mt-1 border-gray-300 rounded-md shadow-sm focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm">
                            </div>
                        </div>

                        <!-- Number of Participants -->
                        <div>
                            <label for="number_of_participants" class="block text-sm font-medium text-gray-700">Number of Participants</label>
                            <input type="number" name="number_of_participants" id="number_of_participants" class="block w-full mt-1 border-gray-300 rounded-md shadow-sm focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm" required>
                        </div>

                        <!-- Department and Faculty Name -->
                        <div class="grid grid-cols-2 sm:grid-cols-2 gap-4">
                            <div>
                                <label for="department" class="block text-sm font-medium text-gray-700">Department</label>
                                <input type="text" name="department" id="department" value="{{ auth()->user()->department->name }}" class="block w-full mt-1 border-gray-300 rounded-md shadow-sm focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm bg-gray-100" disabled>
                                <input type="hidden" name="department_id" value="{{ auth()->user()->department_id }}">
                            </div>
                            <div>
                                <label for="faculty_name" class="block text-sm font-medium text-gray-700">Faculty Name</label>
                                <input type="text" name="faculty_name" id="faculty_name" value="{{ auth()->user()->name }}" class="block w-full mt-1 border-gray-300 rounded-md shadow-sm focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm bg-gray-100" disabled>
                                <input type="hidden" name="faculty_id" value="{{ auth()->user()->id }}">
                            </div>
                        </div>

                        <!-- Start Date/Time, End Date/Time -->
                        <div class="grid grid-cols-2 gap-4">
                            <div>
                                <label for="start_date" class="block text-sm font-medium text-gray-700">Start Date</label>
                                <input type="date" name="start_date" id="start_date" class="block w-full mt-1 border-gray-300 rounded-md shadow-sm focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm" required>
                            </div>
                            <div>
                                <label for="start_time" class="block text-sm font-medium text-gray-700">Start Time</label>
                                <input type="time" name="start_time" id="start_time" class="block w-full mt-1 border-gray-300 rounded-md shadow-sm focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm" required>
                            </div>
                            <div>
                                <label for="end_date" class="block text-sm font-medium text-gray-700">End Date</label>
                                <input type="date" name="end_date" id="end_date" class="block w-full mt-1 border-gray-300 rounded-md shadow-sm focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm" required>
                            </div>
                            <div>
                                <label for="end_time" class="block text-sm font-medium text-gray-700">End Time</label>
                                <input type="time" name="end_time" id="end_time" class="block w-full mt-1 border-gray-300 rounded-md shadow-sm focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm" required>
                            </div>
                        </div>

                        <!-- Objective -->
                        <div>
                            <label for="objective" class="block text-sm font-medium text-gray-700">Objective of Industrial Visit</label>
                            <textarea name="objective" id="objective" rows="3" class="block w-full mt-1 border-gray-300 rounded-md shadow-sm focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm" required></textarea>
                        </div>

                        <!-- Outcomes -->
                        <div>
                            <label for="outcomes" class="block text-sm font-medium text-gray-700">Outcomes of Industrial Visit</label>
                            <textarea name="outcomes" id="outcomes" rows="3" class="block w-full mt-1 border-gray-300 rounded-md shadow-sm focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm" required></textarea>
                        </div>

                        <!-- Proof Document -->
                        <div>
                            <label for="proof" class="block text-sm font-medium text-gray-700">Upload Proof/Document</label>
                            <input type="file" name="proof" id="proof" class="block w-full mt-1 border-gray-300 rounded-md shadow-sm focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm" accept=".jpg,.jpeg,.png,.pdf,.doc,.docx,.zip">
                            <p class="mt-1 text-xs text-gray-500">Accepted formats: JPG, JPEG, PNG, PDF, DOC, DOCX, ZIP</p>
                        </div>
                    </div>
                </div>

                <!-- Submit Button -->
                <div class="px-4 py-3 sm:px-6 text-center mt-4">
                    <button type="submit" class="inline-flex justify-center py-2 px-4 border border-transparent text-sm font-medium rounded-md text-white bg-black">
                        Submit Industrial Visit
                    </button>
                </div>
            </form>
        </div>
    </div>
</div>

<script>
    function toggleStudentYear() {
        const targetAudience = document.getElementById('target_audience').value;
        const studentYearContainer = document.getElementById('student_year_container');
        const studentYearField = document.getElementById('student_year');
        
        if (targetAudience === 'faculty') {
            studentYearContainer.classList.add('hidden');
            studentYearField.required = false;
            studentYearField.value = '';
        } else {
            studentYearContainer.classList.remove('hidden');
            studentYearField.required = true;
        }
    }
    
    // Initialize on page load
    document.addEventListener('DOMContentLoaded', function() {
        toggleStudentYear();
    });
</script>
@endsection