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

{% block title %}Регистрация нового пользователя{% endblock %}

{% block content %}
<div class="card">
    <div class="card-header text-center">
        <h3>Регистрация магазина</h3>
        <p>Заполните форму для создания заявки</p>
    </div>
    <div class="card-body">
        <form method="post" novalidate>
            {% csrf_token %}

            <!-- Название магазина -->
            <div class="mb-2">
                <label for="{{ form.shop_name.id_for_label }}" class="form-label">
                    {{ form.shop_name.label }}
                    <span class="text-danger">*</span>
                </label>
                {{ form.shop_name }}
                {% if form.shop_name.errors %}
                    <div class="text-danger small mt-1">
                        {{ form.shop_name.errors.0 }}
                    </div>
                {% endif %}
            </div>

            <!-- Поддомен -->
            <div class="mb-2">
                <label for="{{ form.schema_name.id_for_label }}" class="form-label">
                    {{ form.schema_name.label }}
                    <span class="text-danger">*</span>
                </label>
                <div class="input-group">
                    {{ form.schema_name }}
                    <span class="input-group-text">.flowers</span>
                </div>
                {% if form.schema_name.errors %}
                    <div class="text-danger small mt-1">
                        {{ form.schema_name.errors.0 }}
                    </div>
                {% endif %}
            </div>

            <!-- Имя и Телефон в две колонки -->
            <div class="row mb-2">
                <div class="col-md-6">
                    <label for="{{ form.owner_name.id_for_label }}" class="form-label">
                        {{ form.owner_name.label }}
                        <span class="text-danger">*</span>
                    </label>
                    {{ form.owner_name }}
                    {% if form.owner_name.errors %}
                        <div class="text-danger small mt-1">
                            {{ form.owner_name.errors.0 }}
                        </div>
                    {% endif %}
                </div>
                <div class="col-md-6">
                    <label for="{{ form.phone.id_for_label }}" class="form-label">
                        {{ form.phone.label }}
                        <span class="text-danger">*</span>
                    </label>
                    {{ form.phone }}
                    {% if form.phone.errors %}
                        <div class="text-danger small mt-1">
                            {{ form.phone.errors.0 }}
                        </div>
                    {% endif %}
                </div>
            </div>

            <!-- Email -->
            <div class="mb-3">
                <label for="{{ form.owner_email.id_for_label }}" class="form-label">
                    {{ form.owner_email.label }}
                    <span class="text-danger">*</span>
                </label>
                {{ form.owner_email }}
                {% if form.owner_email.errors %}
                    <div class="text-danger small mt-1">
                        {{ form.owner_email.errors.0 }}
                    </div>
                {% endif %}
                {% if form.owner_email.help_text %}
                    <div class="form-text">{{ form.owner_email.help_text }}</div>
                {% endif %}
            </div>

            <!-- Кнопка отправки -->
            <div class="d-grid">
                <button type="submit" class="btn btn-primary">
                    Отправить заявку
                </button>
            </div>

            <div class="text-center mt-2">
                <small class="text-muted">
                    Заявка будет проверена в течение 24 часов
                </small>
            </div>
        </form>
    </div>
</div>
{% endblock %}

{% block extra_js %}
<script>
    // Автоматическое преобразование поддомена в lowercase
    document.addEventListener('DOMContentLoaded', function() {
        const schemaNameInput = document.getElementById('{{ form.schema_name.id_for_label }}');
        if (schemaNameInput) {
            schemaNameInput.addEventListener('input', function() {
                this.value = this.value.toLowerCase();
            });
        }
    });
</script>
{% endblock %}
