    {% extends "base.html" %}
{% load i18n %}
{% load static %}
{% load custom_filters %}

{% block content %}
<style>
    .color-option {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        margin: 10px;
        padding: 10px;
        border: 1px solid #ddd;
        border-radius: 8px;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
        transition: all 0.3s ease-in-out;
        cursor: pointer;
    }

    .color-option.selected {
        border: 1px solid #1c1b1b;
        box-shadow: 0 4px 8px rgba(0, 123, 255, 0.2);
        transform: translateY(-3px);
    }

    .color-box {
        width: 50px;
        height: 50px;
        border-radius: 50%;
        border: 1px solid #ccc;
        margin-bottom: 8px;
    }

    .color-option:hover {
        box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
        transform: translateY(-3px);
    }

    .color-box {
        display: flex;
        width: 150px;
        height: 32px;
        border-radius: 5px;
        border: 1px solid #ccc;
        margin-bottom: 8px;
    }

    .form-title {
        font-size: 1.5rem;
        font-weight: bold;
        text-align: center;
        margin-bottom: 20px;
    }

    .btn-group {
        margin-top: 20px;
        text-align: center;
    }

    .btn-group button {
        margin: 0 5px;
    }
</style>

<div class="container mt-3">
<form method="post">
        {% csrf_token %}
        <div class="d-flex flex-column min-vh-100">
            <div class="d-flex flex-column flex-sm-grow-1 ms-sm-14 p-4">
                <main class="d-grid gap-4 p-1">
{% if car.colors.exists %}
    <p class="text-center mb-4">{% trans 'Update Color' %}</p>
{% else %}
<div class="form-title">
        <p>{% trans 'Add Color for' %} {{ car.id_car_make.get_local_name }} {{ car.id_car_model.get_local_name }}</p>
    </div>
                    <!-- Color Type Selection -->
                    <div class="row g-4 justify-content-center">
                        <div class="col-lg-6 col-xl-4">
                            <div class="card p-3">
                                <label class="form-label">{% trans 'Color Type' %}</label>
                                {{ form.color_type }}
                            </div>
                        </div>
                    </div>
                {% endif %}
                    <!-- Color Options -->
                    <div class="row g-4">
                        {% for choice in form.color.field.choices %}
                        <div class="col-lg-3 col-xl-3 text-center">
                            <label class="color-option" id="color-option-{{ forloop.counter }}">
                                <input type="radio" name="color" value="{{ choice.0 }}"
                                       {% if choice.0 == form.color.value %}checked{% endif %}
                                       style="display: none;"
                                       onchange="highlightSelectedColor({{ forloop.counter }})">
                                <div class="color-box" style="background-color: rgb({{ choice.0 }});"></div>
                                <span><small class="fw-lighter">{{ choice.1 }}</small></span>
                            </label>
                        </div>
                        {% endfor %}
                    </div>
                    <!-- Save and Cancel Buttons -->
                    <div class="btn-group">
                        <button type="submit" class="btn btn-sm btn-success">{% trans "Save" %}</button>
                        <a href="{{request.META.HTTP_REFERER}}" class="btn btn-sm btn-danger">{% trans "Cancel" %}</a>
                    </div>
                </main>
            </div>
        </div>
    </form>
</div>
    <script>
    function highlightSelectedColor(selectedId) {
        document.querySelectorAll('.color-option').forEach(option => {
            option.classList.remove('selected');
        });

        const selectedOption = document.getElementById(`color-option-${selectedId}`);
        selectedOption.classList.add('selected');
    }

    document.addEventListener('DOMContentLoaded', function () {
        const checkedInput = document.querySelector('input[name="color"]:checked');
        if (checkedInput) {
            const parentLabel = checkedInput.closest('.color-option');
            parentLabel.classList.add('selected');
            document.getElementById()
        }
    });
</script>
{% endblock content %}