{% trans_default_domain 'lcshop' %}

{% macro total_order_product(totalProductOrdered, productFamily=false) %}
    {% for weekNumber, weekNumberQuantity in totalProductOrdered %}
        <span class="text-success"><i class="fa fa-calendar"></i> {{ weekNumber }}</span>
        <span class="text-info"><i class="fa fa-shopping-basket"></i>
            <strong>
                {{ weekNumberQuantity is null ? 0 : weekNumberQuantity}}
            </strong>
            </span>
        <br />
    {% endfor %}
{% endmacro total_order_product %}


{% macro total_order_product_family(totalProductOrdered, productFamily) %}
    {% for weekNumber, weekNumberQuantity in totalProductOrdered %}
        <span class="text-success"><i class="fa fa-calendar"></i> {{ weekNumber }}</span>
        <span class="text-info"><i class="fa fa-shopping-basket"></i>
            <strong>
                {{ weekNumberQuantity is null ? 0 : weekNumberQuantity}}
                {% if productFamily and productFamily.behaviorCountStock== constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_COUNT_STOCK_BY_MEASURE') %}
                    {{ productFamily.unit.unitReference }}
                {% endif %}
            </strong>
            </span>
        <br />
    {% endfor %}
{% endmacro total_order_product_family %}

{% macro product_field(colspan, field, field_name, field_display = false, display_suffix="",attr="") %}

    {% if field_display == false %}{% set field_display = field_name %}{% endif %}

    <td {{ attr|raw }} colspan="{{ colspan }}" class="{{ field_name }}">
        <div class="value" v-show="{{ field_name }}Inherited == false" @click="setFocusOnField('{{ field_name }}Inherited', keyForm)">
            <div v-if="{{ field_name }}">
                {% verbatim %}{{ {% endverbatim %}{{ field_display }} {% verbatim %}}}{% endverbatim %}{{ display_suffix }}
                {% if field_name == 'priceWithTax' %}
                    <br />
                    <span class="text-danger" v-show="productFamily.reductionActive">{% verbatim %}{{ finalPriceWithTaxAndReduction }}{% endverbatim %}€</span>
                {% endif %}
            </div>
            <div v-else class="inherited">
                {% verbatim %}{{ productFamily.{% endverbatim %}{{ field_display }} {% verbatim %}}}{% endverbatim %}{{ display_suffix }}
                {% if field_name == 'priceWithTax' %}
                    <br />
                    <span class="text-danger" v-show="productFamily.reductionActive">{% verbatim %}{{ finalPriceWithTaxAndReduction }}{% endverbatim %}€</span>
                {% endif %}

            </div>
        </div>
        <div v-show="{{ field_name }}Inherited == true">
            {{ form_widget(field, {'attr' : {'v-model' :  field_name , 'v-on:focusout': field_name~'Inherited = false', '@change' : field_name~'Updated', 'data-ref': field_name~'Inherited', ':data-y' : "keyForm" }}) }}
        </div>
        <button v-show="{{ field_name }}" v-on:click="{{ field_name }} = null; {{ field_name }}Inherited = false;"
                class="btn btn-empty-field" type="button"><i class="fa fa-undo"></i></button>
    </td>
{% endmacro %}

{% macro product_row(product, totalProductOrdered) %}

    <tr class="lc-draggable">
        <td>
            {% if product.vars.value is not null %}
                #{{ product.vars.value.id }}
            {% else %}
                #new
            {% endif %} <br/>
            {% verbatim %}{{keyForm}}{% endverbatim %}<i class="fa fa-fw fa-sort"></i></td>
        {{ _self.product_field(4, product.title, 'title') }}
        {{ _self.product_field(2, product.quantity, 'quantity') }}
        {{ _self.product_field(2, product.unit, 'unit', 'unitWording') }}
        {{ _self.product_field(3, product.buyingPriceByRefUnit, 'buyingPriceByRefUnit',false, '€', 'v-show="productFamily.behaviorPrice == \'' ~ constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_PRICE_BY_REFERENCE_UNIT') ~ '\'"') }}
        {{ _self.product_field(3, product.buyingPriceByRefUnitWithTax, 'buyingPriceByRefUnitWithTax',false, '€', 'v-show="productFamily.behaviorPrice == \'' ~ constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_PRICE_BY_REFERENCE_UNIT') ~ '\'"') }}
        {{ _self.product_field(3, product.buyingPrice, 'buyingPrice',false, '€', 'v-show="productFamily.behaviorPrice == \'' ~ constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_PRICE_BY_PIECE') ~ '\'"') }}
        {{ _self.product_field(3, product.buyingPriceWithTax, 'buyingPriceWithTax',false, '€', 'v-show="productFamily.behaviorPrice == \'' ~ constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_PRICE_BY_PIECE') ~ '\'"') }}

        <td class="buyingPrice" colspan="3" v-show="productFamily.behaviorPrice == '{{ constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_PRICE_BY_REFERENCE_UNIT') }}'">
            {% verbatim %}{{ finalBuyingPrice }}{% endverbatim %}€
        </td>

        {{ _self.product_field(3, product.multiplyingFactor, 'multiplyingFactor') }}
        {{ _self.product_field(3, product.priceByRefUnit, 'priceByRefUnit',false, '€', 'v-show="productFamily.behaviorPrice == \'' ~ constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_PRICE_BY_REFERENCE_UNIT') ~ '\'"') }}
        {{ _self.product_field(3, product.priceByRefUnitWithTax, 'priceByRefUnitWithTax',false, '€', 'v-show="productFamily.behaviorPrice == \'' ~ constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_PRICE_BY_REFERENCE_UNIT') ~ '\'"') }}


        <td class="price" colspan="3" v-show="productFamily.behaviorPrice == '{{ constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_PRICE_BY_REFERENCE_UNIT') }}'">
            {% verbatim %}{{ finalPrice }}{% endverbatim %}€
        </td>
        <td class="priceWithTax" colspan="3" v-show="productFamily.behaviorPrice == '{{ constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_PRICE_BY_REFERENCE_UNIT') }}'">
            {% verbatim %}{{ finalPriceWithTax }}{% endverbatim %}€
            <span class="text-danger" v-show="productFamily.reductionActive">{% verbatim %}{{ finalPriceWithTaxAndReduction }}{% endverbatim %}€</span>
        </td>

        {{ _self.product_field(3, product.price, 'price', false, '€', 'v-show="productFamily.behaviorPrice == \'' ~ constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_PRICE_BY_PIECE') ~ '\'"') }}
        {{ _self.product_field(3, product.priceWithTax, 'priceWithTax', false, '€', 'v-show="productFamily.behaviorPrice == \'' ~ constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_PRICE_BY_PIECE') ~ '\'"') }}

        <td colspan="2">
            <span v-if="productFamily.reductionActive" class="text-danger">
                {% verbatim %}{{ marginProfitWithReduction }}{% endverbatim %}€<br />
                {% verbatim %}{{ marginProfitPercentWithReduction }}{% endverbatim %}%
            </span>
            <span v-else>
                {% verbatim %}{{ marginProfit }}{% endverbatim %}€<br />
                {% verbatim %}{{ marginProfitPercent }}{% endverbatim %}%
            </span>
        </td>

        {{ _self.product_field(2, product.propertyExpirationDate, 'propertyExpirationDate','propertyExpirationDateValue', '', 'v-show="productFamily.behaviorExpirationDate== \'' ~ constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_EXPIRATION_DATE_BY_PRODUCT') ~ '\'"') }}

        {{ _self.product_field(2, product.availableQuantity, 'availableQuantity',false, '', 'v-show="productFamily.behaviorCountStock== \'' ~ constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_COUNT_STOCK_BY_PRODUCT') ~ '\'"') }}
        {{ _self.product_field(2, product.availableQuantityDefault, 'availableQuantityDefault',false, '', 'v-show="productFamily.behaviorCountStock== \'' ~ constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_COUNT_STOCK_BY_PRODUCT') ~ '\' && productFamily.behaviorStockWeek!= \'' ~ constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_STOCK_WEEK_NON_RENEWABLE') ~ '\'"') }}


        <td  colspan="2" v-show="productFamily.behaviorCountStock== '{{ constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_COUNT_STOCK_BY_PRODUCT') }}' || productFamily.behaviorCountStock== '{{ constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_COUNT_STOCK_BY_MEASURE') }}'">

            {{ _self.total_order_product(totalProductOrdered) }}

        </td>
        <td  colspan="3">
            <button type="button" class="btn-sm btn-info" @click="modalProductForm()">
                <i class="fa fa-edit"></i>
            </button>
            <button type="button" class="btn-sm btn-info" @click="changeStatus()">
                <i class="fa fa-check-square"></i>
            </button>
            <button type="button" class="btn-remove-product btn-sm btn-danger" @click="deleteProductForm()">
                <i class="fa fa-trash"></i>
            </button>
            {{ form_widget(product.position, {'attr' : {'class': "field-position", "v-model" : 'position'}}) }}
            {{ form_widget(product.status, {'attr' : {"v-model" : 'status'}}) }}


            <div class="modal fade show" :id="'modal-extends-product-'+keyForm">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <h4>{{ "group.ProductFamily.productsExtend"|trans }}</h4>
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                <span aria-hidden="true">×</span>
                            </button>
                        </div>
                        <div class="modal-body">
                            <div class="col">
                                {{ form_row(product.exportTitle) }}
                            </div>
                            <div class="col">
                                {{ form_row(product.exportNote) }}

                            </div>

                        </div>
                        <div class="modal-footer justify-content-between">
                            <button type="button" class="btn btn-info float-right" data-dismiss="modal">Ok</button>
                        </div>
                    </div>
                </div>
            </div>


        </td>
    </tr>
{% endmacro %}
