{% if guest.extension_is_on({ "mod": "formbuilder" }) %}
    {% set form = guest.formbuilder_get({ "id": product.form_id }) %}
    <div class="card mb-3 mt-3">
    {% if form.style.show_title != "0" %}
        <div class="card-header">
            <legend>{{ form.name }}</legend>
        </div>
    {% endif %}

    <div class="card-body">
        <fieldset>
            {% for field in form.fields %}
                {% if form.style.type == 'horizontal' %}
                    <div class="mb-3 row">
                        {% if field.hide_label != 1 %}
                            <label class="col-sm-2 col-form-label" for="{{ field.name }}">{{ field.label }}</label>
                        {% endif %}
                        {% if field.description %}<div class="col-sm-2 col-form-label form-text mt-0">{{ field.description | markdown_to_html }}</div>{% endif %}
                        <div class="col-sm-10">
                {% else %}
                    {% if field.hide_label != 1 %}
                        <label class="form-label" for="{{ field.name }}">{{ field.label }}</label>
                    {% endif %}
                    {% if field.description %}<div class="form-text mt-0 mb-2">{{ field.description | markdown_to_html }}</div>{% endif %}
                {% endif %}

                {% if field.type == "text" %}
                    {% if field.prefix is not empty or field.suffix is not empty %}
                        <div class="input-group">
                            {% if field.prefix is not empty %}<span class="input-group-text">{{ field.prefix }}</span>{% endif %}
                            <input type="text" class="form-control" name="{{ field.name }}" value="{{ field.default_value }}"
                                {% if field.required==1 %}required="required"{% endif %}
                                {% if field.readonly==1 %}readonly="readonly"{% endif %}
                            />
                            {% if field.suffix is not empty %}<span class="input-group-text">{{ field.suffix }}</span>{% endif %}
                        </div>
                    {% else %}
                        <input type="text" class="form-control" name="{{ field.name }}" value="{{ field.default_value }}"
                            {% if field.required==1 %}required="required"{% endif %}
                            {% if field.readonly==1 %}readonly="readonly"{% endif %}
                        />
                    {% endif %}

                {% elseif field.type == "url" %}
                    <input type="url" class="form-control" name="{{ field.name }}" value="{{ field.default_value }}"
                        {% if field.required==1 %}required="required"{% endif %}
                        {% if field.readonly==1 %}readonly="readonly"{% endif %}
                        placeholder="https://example.com"
                    />

                {% elseif field.type == "select" %}
                    <select class="form-select" name="{{ field.name }}" required="required">
                        {% for k,v in field.options %}
                            <option value="{{v}}" {% if v == field.default_value %}selected="selected"{% endif %}>{{ k }}</option>
                        {% endfor %}
                    </select>

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

                {% elseif field.type == "radio" %}
                    {% for k,v in field.options %}
                        <div class="form-check">
                            <input class="form-check-input" type="radio" name="{{ field.name }}" value="{{ v }}"
                                {% if field.default_value == v %}checked{% endif %}
                                {% if field.required==1 %}required="required"{% endif %}
                                {% if field.readonly==1 %}readonly="readonly"{% endif %}
                            />
                            <label class="form-check-label">{{k}}</label>
                        </div>
                    {% 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" id="{{ field.name }}" name="{{ 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 %}
                    >{{field.default_value}}</textarea>
                {% endif %}

                {% if form.style.type == 'horizontal' %}
                        </div>
                    </div>
                {% endif %}
            {% endfor %}
        </fieldset>
        <input type="hidden" name="form_id" value="{{ form.id }}" />
        <input type="hidden" name="id" value="{{ product.id }}" />
    </div>
    </div>
{% endif %}
