{# When a form has a 'type' attribute with a value of 'product' the below elements are inserted  #}
{% if form.price %}
{% set startingprice = form.price.lowest or 0 %}
{%- if form.qty -%}
    <label for="qty" class="form-label">Quantity</label>
    <input type="text" name="item.qty" class="item.qty" value="1" />
    {%- else -%}
    <input type="hidden" name="item.qty" class="item.qty" value="1" />
 {%- endif -%}
 <div id="form-submit-btn">
    {##}
    <button type="submit" class="hyper btn addToCart"
        data-text="{% if form.button %}{{form.button}}{% else %}Add to Cart{% endif %}">
    {% if form.button %} {{form.button}}{% else %}Add to Cart{% endif %} ${{ startingprice|babelmoney() }}</button>
    {##}
</div>
<input class="price" type="hidden" name="item.price" value="{{ startingprice }}">
<input type="hidden" name="item.base_price" value="{{ startingprice|babelmoney() }}">

<!-- <input type="hidden" name="item.tax" value="2"> -->
<input type="hidden" name="item.name" value="{{ data.title}}">
<input type="hidden" name="item.type" value="{{ form.type }}">
<input type="hidden" name="item.sku" value="{{form.id or form.sku or data.title[:6] }}">
<input type="hidden" name="item.currency" value="{{ form.currency or 'USD' }}">
<input type="hidden" name="item.url" value="{{data.url}}">
<input type="hidden" name="item.image" value="{{ form.image or data.featuredimage }}">
<input type="hidden" name="item.description" value="{{form.description}}">
<input type="hidden" name="item.weight" value="{%- if form.weight -%}{{form.weight}}{%- else -%}0{%- endif -%}">
{% pull 'js' %}
<!--PRODUCT JS-->
<script type="text/javascript" id="hypercart-btn">
var {{ formId }}_btn;
window.addEventListener('DOMContentLoaded', function() {
    {{ formId }}_btn = IHyperCart.createAddToCartBtn({
            source: document.getElementById('{{formId}}'),
            // onChange: (f)=> console.log('changed', f),
            onSubmit: (form)=> IHyperCart.addItem(form.data.item)
    });
});
</script>
<!--PRODUCT JS-->
{% endpull %}
{% endif %}
