{% import '@LcShop/backend/default/block/macros.html.twig' as macros %}
{% import '@LcShop/backend/productfamily/macros.html.twig' as product_family_macros %}
{% trans_default_domain 'lcshop' %}

{#{% import _self as formMacros %}#}
<div class="row">
    {{ macros.startCard(12, 'ProductFamily.products', 'light', true) }}

    <table class="table datagrid sortable lc-sortable-products  products-collection-table"
           :data-index="formProducts.length"
           data-prototype="{{ product_family_macros.product_row(form.products.vars.prototype)|e('html_attr') }}">
        <thead>
        <tr>
            <th>
            </th>
            <th colspan="4" class="string">
                Titre
            </th>
            <th colspan="2" class="string ">
                Quantité
            </th>
            <th colspan="2" class="quantity">
                Unité
            </th>
            <th v-show="getBehaviorPrice() == '{{ constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_PRICE_BY_REFERENCE_UNIT') }}'"
                colspan="3" class="buyingPriceByRefUnit ">
                PA HT / ${ getUnitReference() }
            </th>
            <th v-show="getBehaviorPrice() == '{{ constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_PRICE_BY_REFERENCE_UNIT') }}'"
                colspan="3" class="priceByRefUnit">
                PA TTC / ${ getUnitReference() }
            </th>

            <th colspan="3" class="price main-info">
                PA HT
            </th>
            <th colspan="3" class="price"
                v-show="getBehaviorPrice() =='{{ constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_PRICE_BY_PIECE') }}'">
                PA TTC
            </th>
            <th colspan="3" class="main-info">
                Coef
            </th>


            <th v-show="getBehaviorPrice() == '{{ constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_PRICE_BY_REFERENCE_UNIT') }}'"
                colspan="3" class="">
                PV HT / ${ getUnitReference() }
            </th>
            <th v-show="getBehaviorPrice() == '{{ constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_PRICE_BY_REFERENCE_UNIT') }}'"
                colspan="3" class="price">
                PV TTC / ${ getUnitReference() }
            </th>

            <th colspan="3" class="price">
               {# v-show="getBehaviorPrice() =='{{ constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_PRICE_BY_PIECE') }}'">#}
                PV HT
            </th>
            <th colspan="3" class="price main-info">
                PV TTC
            </th>
            <th colspan="2">
                Marge HT
            </th>

            <th colspan="2" class=""
                v-show="behaviorExpirationDate== '{{ constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_EXPIRATION_DATE_BY_PRODUCT') }}'">
                <span style="text-transform: uppercase"> ${typeExpirationDate}</span>
            </th>
            <th colspan="2"
                v-show="behaviorCountStock== '{{ constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_COUNT_STOCK_BY_PRODUCT') }}'">
                Stock
            </th>
            <th colspan="2"
                v-show="behaviorCountStock== '{{ constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_COUNT_STOCK_BY_PRODUCT') }}' && behaviorStockWeek!= '{{ constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_STOCK_WEEK_NON_RENEWABLE') }}'">
                Stock par défaut
            </th>
            <th colspan="2"
                v-show="behaviorCountStock== '{{ constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_COUNT_STOCK_BY_PRODUCT') }}' || behaviorCountStock== '{{ constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_COUNT_STOCK_BY_MEASURE') }}'">
                Semaine / Commandés
            </th>

            <th colspan="3" class="">
                Action
            </th>
        </tr>
        </thead>
        <tbody class="products-collection">

        <template>
            <product-form v-for="(formProduct, name, index) in formProducts" v-bind:key="name"
                          :key-form="name" ref="productForm" v-bind:product-family="productFamily"
                          :template="formProduct"></product-form>
        </template>
        </tbody>
        <tfoot>
        <th>
            Rappel
        </th>
        <th colspan="4" class="string">
            ${title}
        </th>
        <th colspan="2" class="string ">
            ${productFamily.quantity}
        </th>
        <th colspan="2" class="quantity">
            ${productFamily.unitWording}
        </th>
        <th v-show="getBehaviorPrice() == '{{ constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_PRICE_BY_REFERENCE_UNIT') }}'"
            colspan="3" class="buyingPriceByRefUnit">
            ${productFamily.buyingPriceByRefUnit}
        </th>
        <th v-show="getBehaviorPrice() == '{{ constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_PRICE_BY_REFERENCE_UNIT') }}'"
            colspan="3" class="priceByRefUnit">
            ${productFamily.buyingPriceByRefUnitWithTax}
        </th>

        <th colspan="3" class="price main-info">
            ${productFamily.buyingPrice}
        </th>
        <th colspan="3" class="price"
            v-show="getBehaviorPrice() =='{{ constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_PRICE_BY_PIECE') }}'">
            ${productFamily.buyingPriceWithTax}
        </th>
        <th colspan="3" class="main-info">
            ${productFamily.multiplyingFactor}
        </th>


        <th v-show="getBehaviorPrice() == '{{ constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_PRICE_BY_REFERENCE_UNIT') }}'"
            colspan="3" class="">
            ${productFamily.priceByRefUnit}
        </th>
        <th v-show="getBehaviorPrice() == '{{ constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_PRICE_BY_REFERENCE_UNIT') }}'"
            colspan="3" class="price">
            ${productFamily.priceByRefUnitWithTax}
        </th>

        <th colspan="3" class="price">
           {# v-show="getBehaviorPrice() =='{{ constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_PRICE_BY_PIECE') }}'">#}
            ${productFamily.price}
        </th>
        <th colspan="3" class="price main-info">
            ${productFamily.priceWithTax}
        </th>
        <th colspan="2" class="price">
            ${productFamily.marginProfit}€<br/>
            ${productFamily.marginProfitPercent}%
        </td>

        <th colspan="2" class=""
            v-show="behaviorExpirationDate== '{{ constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_EXPIRATION_DATE_BY_PRODUCT') }}'">
            ${propertyExpirationDate}
        </th>

        <th colspan="2"
            v-show="behaviorCountStock== '{{ constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_COUNT_STOCK_BY_PRODUCT') }}'">
        </th>
        <th colspan="2"
            v-show="behaviorCountStock== '{{ constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_COUNT_STOCK_BY_PRODUCT') }}'  && behaviorStockWeek!= '{{ constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_STOCK_WEEK_NON_RENEWABLE') }}'">
        </th>
        <th colspan="2"
            v-show="behaviorCountStock== '{{ constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_COUNT_STOCK_BY_PRODUCT') }}' || behaviorCountStock== '{{ constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_COUNT_STOCK_BY_MEASURE') }}'">
        </th>

        <th colspan="3" class="">

        </th>
        </tfoot>
    </table>

    <button type="button" class="add_tag_link btn-add-product btn btn-default" @click="addProductForm"><span
                class="fa fa-plus"></span> Ajouter une déclinaison
    </button>
    <p>
        <strong>Aide à l'utilisation - Raccourci clavier</strong>
    <ul>
        <li><strong>TAB</strong> : Champ suivant</li>
        <li><strong>SHIFT + TAB</strong> : Champ précédent</li>
        <li><strong>FLÈCHE BAS</strong> : Déclinaison suivante</li>
        <li><strong>FLÈCHE HAUT</strong> : Déclinaison précédente</li>
        <li><strong>SHIFT + [+]</strong> : Ajout d'une nouvelle déclinaison</li>
    </ul>
    </p>

    <div class="clearfix"></div>

    {{ macros.endCard() }}
</div>
{% do form.products.setRendered %}
<script>
    window.productForm = new Array();
    window.formProductTemplate = new Array();

    {% for keyForm,i in sortableProductsField %}
    {% set product = form.products[i] %}

    window.productForm[{{ keyForm }}] = {
        {% if product.vars.value.status is defined %}status: parseInt({{ product.vars.value.status }}),{% endif %}
        {% if product.vars.value.position %}position: "{{ product.vars.value.position }}",{% endif %}
        {% if product.vars.value.title %}title: "{{ product.vars.value.title }}",{% endif %}
        {% if product.vars.value.quantity %}quantity: "{{ product.vars.value.quantity }}",{% endif %}
        {% if product.vars.value.unit %}unit: {{ product.vars.value.unit.id }},{% endif %}
        {% if product.vars.value.buyingPrice %}buyingPrice: parseFloat({{ product.vars.value.buyingPrice }}).toFixed(3),{% endif %}
        {% if product.vars.value.buyingPriceByRefUnit %}buyingPriceByRefUnit: parseFloat({{ product.vars.value.buyingPriceByRefUnit }}).toFixed(3),{% endif %}
        {% if product.vars.value.price %}price: parseFloat({{ product.vars.value.price }}).toFixed(3),{% endif %}
        {% if product.vars.value.priceByRefUnit %}priceByRefUnit: parseFloat({{ product.vars.value.priceByRefUnit }}).toFixed(3),{% endif %}
        {% if product.vars.value.availableQuantity %}availableQuantity: parseInt({{ product.vars.value.availableQuantity }}),{% endif %}
        {% if product.vars.value.availableQuantityDefault %}availableQuantityDefault: parseInt({{ product.vars.value.availableQuantityDefault }}),{% endif %}
        {% if product.vars.value.propertyExpirationDate %}propertyExpirationDate: "{{ product.vars.value.propertyExpirationDate }}",{% endif %}
        {#{% if product.vars.value.expirationDate %}expirationDate: "{{ product.vars.value.expirationDate|date('d/m/Y') }}"{% endif %}#}
    };
    window.formProductTemplate[{{ keyForm }}] = '{{ product_family_macros.product_row(product, totalProductOrdered[product.vars.value.id])|replace({"\n":' ', "\r":' ', "'" : "\\'"})|raw }}';
    {% endfor %}

</script>

