{% extends 'base.html' %}
{% from "macros.html" import render_field %}

{% block title %}Edit Specialist Magic Link{% endblock %}

{% block content_title %}Edit Specialist Magic Link{% endblock %}
{% block content_description %}Edit a Specialist Magic Link{% endblock %}

{% block content %}
    <form method="post">
        {{ form.hidden_tag() }}
        {% set disabled_fields = ['magic_link_code', 'chat_client_url', 'qr_code_url'] %}
        {% set exclude_fields = [] %}
        <!-- Render Static Fields -->
        {% for field in form.get_static_fields() %}
            {% if field.name == 'qr_code_url' and field.data %}
                <div class="form-group">
                    <label for="{{ field.id }}">{{ field.label.text }}</label>
                    <div style="max-width: 200px;">
                        <img src="{{ field.data }}" alt="QR Code" class="img-fluid">
                    </div>
                    <input type="hidden" name="{{ field.name }}" value="{{ field.data|e }}">
                </div>
            {% elif field.name == 'chat_client_url' %}
                <div class="form-group">
                    <label for="{{ field.id }}" class="form-label">{{ field.label.text }}</label>
                    <div class="input-group">
                        <input type="text" class="form-control" value="{{ field.data }}" id="{{ field.id }}" readonly>
                        <a href="{{ field.data }}" class="btn btn-primary" target="_blank">Open link</a>
                    </div>
                    <input type="hidden" name="{{ field.name }}" value="{{ field.data|e }}">
                </div>
            {% else %}
                {{ render_field(field, disabled_fields, exclude_fields) }}
            {% endif %}
        {% endfor %}
        <!-- Render Dynamic Fields -->
        {% for collection_name, fields in form.get_dynamic_fields().items() %}
            {% if fields|length > 0 %}
                <h4 class="mt-4">{{ collection_name }}</h4>
            {% endif %}
            {% for field in fields %}
                {{ render_field(field, disabled_fields, exclude_fields) }}
            {% endfor %}
        {% endfor %}
        <button type="submit" class="btn btn-primary">Save Specialist Magic Link</button>
    </form>
{% endblock %}

{% block content_footer %}

{% endblock %}