<!-- web/templates/web/service_detail.html -->
{% extends 'web/base.html' %}
{% load static %}
{% block title %}Услуга - {{ service.name }}{% endblock %}

{% block content %}

<div class="container py-4 py-xl-5">
    <div class="row gy-4 gy-md-0">
        <div class="col-md-6">
            <div class="p-xl-5 m-xl-5"><img class="rounded img-fluid w-100 fit-cover" style="min-height: 300px;" src="{{ service.image.url }}" /></div>
        </div>
        <div class="col-md-6 d-md-flex align-items-md-center">
            <div style="max-width: 350px;">
                <h2 class="text-uppercase fw-bold">{{ service.name }}<br /></h2>
                <p class="my-3">{{ service.description }}</p>
                <a class="btn btn-primary btn-lg me-2" role="button" href="#" data-bs-toggle="modal" data-bs-target="#orderModal">Order Service</a>
            </div>
        </div>
    </div>
</div>

{% include "web/modal_order_form.html" %}
<div class="container py-4">
    <div class="row-cols-auto">
        <div class="col-md-8 col-xl-6 text-center mx-auto">
            <h2>Проекты</h2>
            <p>Список проектов, связанных с данной услугой:</p>
        </div>
    </div>
    <div class="row gy-4 row-cols-1 row-cols-sm-2 row-cols-lg-3">
        {% for project in service.projects.all %}
        <div class="col">
            <div class="card project-card">
                <div class="card-body">
                    <h5 class="card-title">{{ project.name }}</h5>
                    <p class="card-text small-text">{{ project.description }}</p>
                    <p class="card-text small-text"><strong>Сообщение заказчика:</strong> {{ project.order.message }}</p>
                    <p class="card-text small-text"><strong>Дата завершения:</strong> {{ project.completion_date }}</p>
                    <p class="card-text small-text"><strong>Статус:</strong> {{ project.get_status_display }}</p>
                </div>
            </div>
        </div>
        {% endfor %}
    </div>
</div>

<div class="container py-4">
    <div class="row-cols-auto">
        <div class="col-md-8 col-xl-6 text-center mx-auto">
            <h2>Отзывы</h2>
            <p>Наших любимых клиентов. Спасибо, что Вы с нами!</p>
        </div>
    </div>

    <div class="row gy-4 row-cols-1 row-cols-sm-2 row-cols-lg-3">
        {% for review in reviews %}
        <div class="col">
            <div class="card review-card">
                <div class="card-body">
                    <p class="card-text small-text">{{ review.comment }}</p>
                    <div class="d-flex">
                        {% if review.client.image %}
                            <img class="rounded-circle flex-shrink-0 me-3 fit-cover" width="50" height="50" src="{{ review.client.image.url }}" />
                        {% else %}
                            <img class="rounded-circle flex-shrink-0 me-3 fit-cover" width="50" height="50" src="https://cdn.bootstrapstudio.io/placeholders/1400x800.png" />
                        {% endif %}
                        <div>
                            <p class="fw-bold text-primary mb-0 small-text">{{ review.client.first_name }} {{ review.client.last_name }}</p>
                            <p class="text-muted mb-0 small-text">Оценка: {{ review.rating }} из 5</p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        {% endfor %}
    </div>
</div>

<script>
    // JavaScript для дополнительной проверки формы
    document.getElementById('orderForm').addEventListener('submit', function (event) {
        let phoneInput = document.getElementById('client_phone');
        let phonePattern = /^\+?[0-9\s\-]{7,15}$/;
    
        if (!phonePattern.test(phoneInput.value)) {
            alert('Введите правильный номер телефона.');
            event.preventDefault(); // Останавливаем отправку формы
        }
    });
</script>

{% endblock %}