@extends('layouts.app')

@section('content')
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-6">
    <div class="bg-white overflow-hidden shadow sm:rounded-lg">
        <div class="px-4 py-5 sm:px-6">
            <h3 class="text-xl leading-6 font-semibold text-gray-900">
                Edit Patents/Copyrights 
            </h3>
        </div>

        <div class="px-4 py-5 sm:p-6">
            @if ($errors->any())
            <div class="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded mb-4">
                <ul>
                    @foreach ($errors->all() as $error)
                    <li>{{ $error }}</li>
                    @endforeach
                </ul>
            </div>
            @endif

            <form action="{{ request()->is('admin/*') ? route('admin.Patents.update', $patent->id) : (request()->is('coordinator/*') ? route('coordinator.Patents.update', $patent->id) : route('faculty.Patents.update', $patent->id)) }}" method="POST" enctype="multipart/form-data">
                @csrf
                @method('PUT')
                <div class="space-y-6">
                    <!-- title Information -->
                    <div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
                        <div>
                            <label for="title" class="block text-sm font-medium text-gray-700">Title</label>
                            <input type="text" name="title" id="title" value="{{ old('title', $patent->title) }}" class="mt-1 focus:ring-indigo-500 focus:border-indigo-500 block w-full shadow-sm sm:text-sm border-gray-300 rounded-md" required>
                        </div>
                        <!-- investigator -->
                        <div>
                            <label for="investigator" class="block text-sm font-medium text-gray-700">Investigator</label>
                            <input type="text" name="investigator" id="investigator" value="{{ old('investigator', $patent->investigator) }}" class="mt-1 focus:ring-indigo-500 focus:border-indigo-500 block w-full shadow-sm sm:text-sm border-gray-300 rounded-md" required>
                        </div>
                    </div>

                    <div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
                        <div>
                            <label for="application_no" class="block text-sm font-medium text-gray-700">Application No</label>
                            <input type="text" name="application_no" id="application_no" value="{{ old('application_no', $patent->application_no) }}" class="mt-1 focus:ring-indigo-500 focus:border-indigo-500 block w-full shadow-sm sm:text-sm border-gray-300 rounded-md" required>
                        </div>
                        <!-- investigator -->
                        <div>
                            <label for="type" class="block text-sm font-medium text-gray-700">Type</label>
                            <input type="text" name="type" id="type" value="{{ old('type', $patent->type) }}" class="mt-1 focus:ring-indigo-500 focus:border-indigo-500 block w-full shadow-sm sm:text-sm border-gray-300 rounded-md" required>
                        </div>
                    </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="{{ $patent->department->name ?? 'Unknown' }}" class="mt-1 focus:ring-indigo-500 focus:border-indigo-500 block w-full shadow-sm sm:text-sm border-gray-300 rounded-md bg-gray-100" disabled>
                        </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="{{ $patent->user->name ?? 'Unknown' }}" class="mt-1 focus:ring-indigo-500 focus:border-indigo-500 block w-full shadow-sm sm:text-sm border-gray-300 rounded-md bg-gray-100" disabled>
                        </div>
                    </div>

                    <div class="grid grid-cols-2 gap-4">
                        <div>
                            <label for="date_of_submission" class="block text-sm font-medium text-gray-700">Start Date</label>
                            <input type="date" name="date_of_submission" id="date_of_submission" value="{{ old('date_of_submission', \Carbon\Carbon::parse($patent->date_of_submission)->format('Y-m-d')) }}" class="mt-1 focus:ring-indigo-500 focus:border-indigo-500 block w-full shadow-sm sm:text-sm border-gray-300 rounded-md" required onchange="calculateDays()">
                        </div>
                        <div>
                            <label for="date_of_filling" class="block text-sm font-medium text-gray-700">End Date</label>
                            <input type="date" name="date_of_filling" id="date_of_filling" value="{{ old('date_of_filling', \Carbon\Carbon::parse($patent->date_of_filling)->format('Y-m-d')) }}" class="mt-1 focus:ring-indigo-500 focus:border-indigo-500 block w-full shadow-sm sm:text-sm border-gray-300 rounded-md" required onchange="calculateDays()">
                        </div>
                        <div>
                            <label for="status" class="block text-sm font-medium text-gray-700">Number of Days</label>
                            <input type="text" name="status" id="status" value="{{ old('status', $patent->status) }}" class="mt-1 focus:ring-indigo-500 focus:border-indigo-500 block w-full shadow-sm sm:text-sm border-gray-300 rounded-md bg-gray-100">
                        </div>
                    </div>

                    <!-- Proof File -->
                    <div>
                        <label for="proof" class="block text-sm font-medium text-gray-700">Upload Proof</label>
                        @if ($patent->proof)
                        <div class="mb-2">
                            <span class="text-sm text-gray-600">Current file:</span>
                            <a href="{{ asset('storage/' . $patent->proof) }}" target="_blank" class="ml-2 text-blue-600 hover:text-blue-800">View</a>
                        </div>
                        @endif
                        <input type="file" name="proof" id="proof" class="mt-1 block w-full text-sm text-gray-500
                            file:mr-4 file:py-2 file:px-4
                            file:rounded-full file:border-0
                            file:text-sm file:font-semibold
                            file:bg-blue-50 file:text-blue-700
                            hover:file:bg-blue-100">
                        <p class="mt-1 text-xs text-gray-500">Accepted formats: JPG, JPEG, PNG, PDF, DOC, DOCX, ZIP</p>
                    </div>
                </div>

                <!-- Submit Button -->
                <div class="mt-6 flex items-center justify-end">
                    <a href="{{ request()->is('admin/*') ? route('admin.PatentsResponses') : (request()->is('coordinator/*') ? route('coordinator.PatentsResponses') : route('faculty.PatentsResponses')) }}" class="bg-gray-200 py-2 px-4 border border-gray-300 rounded-md shadow-sm text-sm font-medium text-gray-700 hover:bg-gray-300 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-gray-500 mr-3">
                        Cancel
                    </a>
                    <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">
                        Update
                    </button>
                </div>
            </form>
        </div>
    </div>
</div>

@endsection