{% set form = guest.formbuilder_get({ "id": order.form_id }) %}
{% set config = order.config %}
<form method="post" action="{{ 'order/update_config'|api_url }}" {{ fb_api_form({message: 'Order Updated'|trans}) }}>
    <input type="hidden" name="config[form_id]" value="{{ config.form_id }}"/>
    <input type="hidden" name="config[id]" value="{{ config.id }}"/>
    <input type="hidden" name="config[product_id]" value="{{ form.product_id }}"/>
    <input type="hidden" name="config[type]" value="{{ config.type }}"/>
    <input type="hidden" name="config[quantity]" value="{{ config.quantity }}"/>
    <input type="hidden" name="config[price]" value="{{ config.price }}"/>
    <input type="hidden" name="config[setup_price]" value="{{ config.setup_price }}"/>
    <input type="hidden" name="config[discount]" value="{{ config.discount }}"/>
    <input type="hidden" name="config[discount_price]" value="{{ config.discount_price }}"/>
    <input type="hidden" name="config[discount_setup]" value="{{ config.discount_setup }}"/>
    <input type="hidden" name="config[total]" value="{{ config.total }}"/>
    <input type="hidden" name="id" value="{{ order.id }}"/>

    <div class="card-body">
        <div class="mb-3">
            <h3 class="card-title mb-1">{{ form.title }}</h3>
            <p class="text-secondary mb-0">{{ 'Update the values captured by this form for the current order.'|trans }}</p>
        </div>
        <div class="row g-4">
            <div class="col-12">
                {% for field in form.fields %}
                    <div class="border-bottom pb-4 mb-4">
                        <div class="row g-3">
                            <div class="col-lg-4">
                                {% if field.hide_label != 1 %}
                                    <label class="form-label {% if field.required == 1 %}required{% endif %}" for="{{ field.name }}">{{ field.label }}</label>
                                {% endif %}
                            </div>
                            <div class="col-lg-8">
                            {% if field.type == "text" %}
                                <div class="input-group">
                                    {% if field.prefix %}
                                        <span class="input-group-text">{{ field.prefix }}</span>
                                    {% endif %}
                                    <input class="form-control readonly" type="text"
                                           name="config[{{ field.name }}]" id="{{ field.name }}"
                                           value="{{ (order.config[field.name]) }}"
                                           {% if field.required %}required="required"{% endif %}
                                        {% if field.readonly %}readonly="readonly"{% endif %}>
                                    {% if field.suffix %}
                                        <span class="input-group-text">{{ field.suffix }}</span>
                                    {% endif %}
                                </div>
                            {% elseif field.type == "url" %}
                                <input class="form-control" type="url" name="config[{{ field.name }}]" id="{{ field.name }}"
                                       value="{{ order.config[field.name] }}"
                                       {% if field.required %}required="required"{% endif %}
                                       {% if field.readonly %}readonly="readonly"{% endif %}
                                       placeholder="https://example.com">
                            {% elseif field.type == "select" %}
                                <select id="{{ field.name }}" class="form-select" name="config[{{ field.name }}]"
                                        required="required">
                                    {% for k,v in field.options %}
                                        <option value="{{ v }}"
                                                {% if v == order.config.(field.name) %}selected="selected"{% endif %}>{{ k }}</option>
                                    {% endfor %}
                                </select>

                            {% elseif field.type == "checkbox" %}
                                {% for k,v in field.options %}
                                    <label class="form-check form-check-inline">
                                        <input id="{{ field.name }}" class="form-check-input" type="checkbox"
                                               name="config[{{ field.name }}][]"
                                               value="{{ v }}"
                                               {% if v in config[field.name] %}checked="checked" {% endif %}>
                                        <span class="form-check-label">{{ k }}</span>
                                    </label>
                                {% endfor %}

                            {% elseif field.type == "radio" %}
                                {% for k,v in field.options %}
                                    <label class="form-check form-check-inline">
                                        <input id="{{ field.name }}" class="form-check-input" type="radio"
                                               name="config[{{ field.name }}]" value="{{ v }}"
                                               {% if order.config.(field.name) == v %}checked{% endif %}>
                                        <span class="form-check-label">{{ k }}</span>
                                    </label>
                                {% endfor %}

                            {% elseif field.type == "textarea" %}
                                {% set textarea_width = field.options.width|default(null) %}
                                {% set textarea_height = field.options.height|default(null) %}
                                <textarea class="form-control"
                                          name="config[{{ field.name }}]"
                                          id="{{ field.name }}"
                                          {% if textarea_width or textarea_height %}
                                              style="{% if textarea_width %}width: min(100%, {{ textarea_width }}px);{% endif %}{% if textarea_height %}height: {{ textarea_height }}px; min-height: {{ textarea_height }}px;{% endif %}"
                                          {% endif %}
                                          {% if field.required==1 %}required="required"{% endif %}
                                    {% if field.readonly==1 %}readonly="readonly"{% endif %}>{{ order.config.(field.name) }}</textarea>
                            {% endif %}
                            </div>
                        </div>
                    </div>
                {% endfor %}
            </div>
        </div>
    </div>
    <div class="card-footer text-end">
        <button type="submit" class="btn btn-primary pull-right">{{ 'Update'|trans }}</button>
    </div>
</form>
