<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Update Tutor Profile</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <style>
        body { font-family: Arial, sans-serif; background: #f4f4f9; margin: 0; padding: 0; }
        .container { max-width: 800px; margin: 40px auto; background: #fff; padding: 30px; border-radius: 8px; box-shadow: 0 0 15px rgba(0,0,0,0.1); }
        h2 { text-align: center; margin-bottom: 25px; color: #333; }
        .form-group { margin-bottom: 20px; }
        label { font-weight: bold; display: block; margin-bottom: 8px; }
        input[type="text"], input[type="number"], select, textarea { width: 100%; padding: 10px; border: 1px solid #ccc; border-radius: 5px; box-sizing: border-box; }
        select[multiple] { height: 120px; }
        button { padding: 12px 25px; background-color: #007bff; border: none; border-radius: 5px; color: #fff; cursor: pointer; font-size: 16px; }
        button:hover { background-color: #0056b3; }
        .alert { padding: 12px 20px; border-radius: 5px; margin-bottom: 20px; }
        .alert-success { background-color: #d4edda; color: #155724; }
        .alert-danger { background-color: #f8d7da; color: #721c24; }
        .text-muted { font-size: 13px; color: #6c757d; }
        a { color: #007bff; text-decoration: none; }
        a:hover { text-decoration: underline; }
    </style>
</head>
<body>

<div class="container">
    <h2>Update Profile Information</h2>

    @if(session('success'))
        <div class="alert alert-success">{{ session('success') }}</div>
    @endif

    @if($errors->any())
        <div class="alert alert-danger">
            <ul>
                @foreach($errors->all() as $error) <li>{{ $error }}</li> @endforeach
            </ul>
        </div>
    @endif

    <form action="{{ route('tutor.account.information.update') }}" method="POST" enctype="multipart/form-data">
        @csrf

        <div class="form-group">
            <label for="hourly_rate">Hourly Rate</label>
            <input type="number" step="0.01" name="hourly_rate" id="hourly_rate" 
                   value="{{ old('hourly_rate', auth()->user()->tutor_hourly_rate) }}" required>
        </div>

        <div class="form-group">
            <label for="headline">Headline</label>
            <input type="text" name="headline" id="headline" 
                   value="{{ old('headline', auth()->user()->headline) }}" required>
        </div>

        <div class="form-group">
            <label for="introduction">Introduction</label>
            <textarea name="introduction" id="introduction" rows="4" required>{{ old('introduction', auth()->user()->introduction) }}</textarea>
        </div>

        <div class="form-group">
            <label for="qualification">Qualification</label>
            <input type="text" name="qualification" id="qualification" 
                   value="{{ old('qualification', auth()->user()->qualification) }}" required>
        </div>

        <div class="form-group">
            <label>Subjects</label>
            <select name="subjects[]" multiple required>
                @foreach($subjects as $subject)
                    <option value="{{ $subject->id }}" 
                        @if(in_array($subject->id, $tutorSubject->pluck('subject_id')->toArray())) selected @endif>
                        {{ $subject->subject_name }}
                    </option>
                @endforeach
            </select>
        </div>

        <div class="form-group">
            <label>Level of Teaching</label>
            <select name="level_of_teaching[]" multiple required>
                @php
                    
                    $tutorLevels = auth()->user()->tutorLevels()->pluck('level_id')->toArray() ?? [];
                @endphp
                @foreach($levels as $key => $level)
                    <option value="{{ $level->id }}" @if(in_array($key, $tutorLevels)) selected @endif>{{ $level->level_name }}</option>
                @endforeach
            </select>
        </div>

        <div class="form-group">
            <label>Languages</label>
            <select name="languages[]" multiple required>
                @foreach($languages as $language)
                    <option value="{{ $language->id }}" 
                        @if(in_array($language->id, $tutorLanguages->pluck('language_id')->toArray())) selected @endif>
                        {{ $language->language_name }}
                    </option>
                @endforeach
            </select>
        </div>

        <div class="form-group">
            <label>Certificates</label>
            <input type="file" name="certificates[]" multiple>
            <small class="text-muted">Upload multiple certificates. Existing certificates will be replaced.</small>
            <div style="margin-top: 10px;">
                @foreach(auth()->user()->certificates as $certificate)
                    <a href="{{ asset($certificate->document) }}" target="_blank">{{ basename($certificate->document) }}</a><br>
                @endforeach
            </div>
        </div>

        <div class="form-group">
            <button type="submit">Update Profile</button>
        </div>
    </form>
</div>

</body>
</html>
