{% extends "common/base.html" %}

{% block title %}Profile - DocuPulse{% endblock %}

{% block content %}
<div class="container mx-auto px-4 py-6">
    <div class="max-w-3xl mx-auto">
        <form method="POST" enctype="multipart/form-data" class="bg-white rounded-lg shadow overflow-hidden">
            <input type="hidden" name="csrf_token" value="{{ csrf_token }}">
            <!-- Profile Picture Section -->
            <div class="p-4 border-b border-gray-200">
                <div class="flex flex-col items-center">
                    <div class="relative group flex flex-col items-center">
                        <label for="profile_picture" class="cursor-pointer">
                            <img id="avatarPreview" src="{{ url_for('profile_pic', filename=current_user.profile_picture) if current_user.profile_picture else url_for('static', filename='default-avatar.png') }}" alt="Profile Picture" class="w-32 h-32 rounded-full object-cover border-4 border-gray-200 mb-0 transition duration-200 group-hover:opacity-80 group-hover:ring-4 group-hover:ring-primary-200 shadow-sm">
                            <input id="profile_picture" type="file" name="profile_picture" accept="image/*" class="hidden" onchange="previewAvatar(event)" />
                        </label>
                        {% if current_user.profile_picture %}
                        <button type="submit" name="remove_picture" value="1" class="mt-2 text-xs px-3 py-1 rounded bg-red-100 text-red-700 border border-red-200 hover:bg-red-200 transition">Remove Picture</button>
                        {% endif %}
                    </div>
                </div>
            </div>

            <!-- Personal Information Section -->
            <div class="p-4 border-b border-gray-200">
                <h2 class="text-lg font-medium text-gray-900 mb-3">Personal Information</h2>
                <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-1">First Name</label>
                        <input type="text" name="first_name" value="{{ current_user.username }}" 
                               class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500">
                    </div>
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-1">Last Name</label>
                        <input type="text" name="last_name" value="{{ current_user.last_name }}"
                               class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500">
                    </div>
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-1">Email</label>
                        <input type="email" name="email" value="{{ current_user.email }}"
                               class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500">
                    </div>
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-1">Phone</label>
                        <input type="tel" name="phone" value="{{ current_user.phone or '' }}"
                               class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500">
                    </div>
                </div>
            </div>

            <!-- Professional Information Section -->
            <div class="p-4 border-b border-gray-200">
                <h2 class="text-lg font-medium text-gray-900 mb-3">Professional Information</h2>
                <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-1">Company</label>
                        <input type="text" name="company" value="{{ current_user.company or '' }}"
                               class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500">
                    </div>
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-1">Position</label>
                        <input type="text" name="position" value="{{ current_user.position or '' }}"
                               class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500">
                    </div>
                </div>
                <div class="mt-4">
                    <label class="block text-sm font-medium text-gray-700 mb-1">Notes</label>
                    <textarea name="notes" rows="4"
                              class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500">{{ current_user.notes or '' }}</textarea>
                </div>
            </div>

            <!-- Password Change Section -->
            <div class="p-4 border-b border-gray-200">
                <h2 class="text-lg font-medium text-gray-900 mb-3">Change Password</h2>
                <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-1">New Password</label>
                        <input type="password" name="new_password"
                               class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500">
                    </div>
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-1">Confirm New Password</label>
                        <input type="password" name="confirm_password"
                               class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500">
                    </div>
                </div>
            </div>

            <!-- Submit Button -->
            <div class="p-4 bg-gray-50">
                <div class="flex justify-end">
                    <button type="submit"
                            class="text-white px-6 py-2 rounded-lg transition duration-200"
                            style="background-color: var(--primary-color); border: 1px solid var(--primary-color);"
                            onmouseover="this.style.backgroundColor='var(--primary-light)'"
                            onmouseout="this.style.backgroundColor='var(--primary-color)'">
                        Save Changes
                    </button>
                </div>
            </div>
        </form>
    </div>
</div>

{% block extra_js %}
<script src="{{ url_for('static', filename='js/avatar-preview.js') }}?v={{ 'js/avatar-preview.js'|asset_version }}"></script>
{% endblock %}
{% endblock %} 