@extends('layouts.app')

@section('content')
<div class="container mt-4">
    <h4 class="mb-4">Edit Faculty Profile</h4>

    <form action="{{ route('faculty.profile.update') }}" method="POST" enctype="multipart/form-data" class="card shadow-sm p-4">
        @csrf
        @method('PUT')

        <div class="row">
            <div class="col-md-6 mb-3">
                <label class="form-label fw-semibold">Full Name</label>
                <input type="text" name="name" class="form-control" value="{{ old('name', $profile->name) }}" required>
            </div>

            <div class="col-md-6 mb-3">
                <label class="form-label fw-semibold">Email</label>
                <input type="email" name="email" class="form-control" value="{{ old('email', $profile->email) }}" required>
            </div>

            <div class="col-md-6 mb-3">
                <label class="form-label fw-semibold">Phone Number</label>
                <input type="text" name="phone_number" class="form-control" value="{{ old('phone_number', $profile->phone_number) }}">
            </div>

            <div class="col-md-6 mb-3">
                <label class="form-label fw-semibold">Employee ID</label>
                <input type="text" name="employee_id" class="form-control" value="{{ old('employee_id', $profile->employee_id) }}">
            </div>

            <div class="col-md-6 mb-3">
                <label class="form-label fw-semibold">Department</label>
                <input type="text" name="department_name" class="form-control" value="{{ old('department_name', $profile->department_name) }}">
            </div>

            <div class="col-md-6 mb-3">
                <label class="form-label fw-semibold">Programme</label>
                <input type="text" name="programme_name" class="form-control" value="{{ old('programme_name', $profile->programme_name) }}">
            </div>

            <div class="col-md-4 mb-3">
                <label class="form-label fw-semibold">Salutation</label>
                <input type="text" name="salutation" class="form-control" value="{{ old('salutation', $profile->salutation) }}">
            </div>

            <div class="col-md-4 mb-3">
                <label class="form-label fw-semibold">Designation</label>
                <input type="text" name="designation" class="form-control" value="{{ old('designation', $profile->designation) }}">
            </div>

            <div class="col-md-4 mb-3">
                <label class="form-label fw-semibold">Date of Joining</label>
                <input type="date" name="date_of_joining" class="form-control" value="{{ old('date_of_joining', $profile->date_of_joining?->format('Y-m-d')) }}">
            </div>

            <div class="col-md-6 mb-3">
                <label class="form-label fw-semibold">Google Scholar ID</label>
                <input type="text" class="form-control" id="google_scholar_id" name="google_scholar_id"
                       value="{{ old('google_scholar_id', $profile->google_scholar_id) }}">
            </div>

            <div class="col-md-6 mb-3">
                <label class="form-label fw-semibold">Vidhwan ID</label>
                <input type="text" class="form-control" id="vidhwan_id" name="vidhwan_id"
                       value="{{ old('vidhwan_id', $profile->vidhwan_id) }}">
            </div>

            <div class="col-md-6 mb-3">
                <label class="form-label fw-semibold">LinkedIn Profile</label>
                <input type="text" class="form-control" id="linkedin_id" name="linkedin_id"
                       value="{{ old('linkedin_id', $profile->linkedin_id) }}">
            </div>

            <div class="col-md-12 mb-3">
                <label class="form-label fw-semibold">Qualification</label>
                <textarea name="qualification" class="form-control" rows="2">{{ is_array($profile->qualification) ? implode(', ', $profile->qualification) : $profile->qualification }}</textarea>
                <small class="text-muted">Separate multiple qualifications with commas (e.g., B.Tech, M.Tech, Ph.D)</small>
            </div>

            <div class="col-md-12 mb-3">
                <label class="form-label fw-semibold">Address</label>
                <textarea name="address" class="form-control" rows="2">{{ old('address', $profile->address) }}</textarea>
            </div>

            <div class="col-md-6 mb-3">
                <label class="form-label fw-semibold">Profile Photo</label>
                <input type="file" name="profile_photo" class="form-control">

                @if ($profile->profile_photo_path)
                    <div class="mt-2">
                        <img src="{{ Storage::url($profile->profile_photo_path) }}" alt="Profile Photo" width="100" class="rounded shadow-sm">
                    </div>
                @endif
            </div>
        </div>

        <div class="text-end mt-3">
            <button type="submit" class="btn btn-primary">
                <i class="fa fa-save me-1"></i> Save Changes
            </button>
        </div>
    </form>
</div>
@endsection
