<script type="text/html" id="lps_ui">

    <td colspan="3">

        {loop type="lps_area" name="area-loop" id={$area_id}}
            {assign var=livraison value=$PRICE}
            {assign var=minimum value=$MINIMUM_AMOUNT}
        {/loop}

        {if {cart attr='total_taxed_price_without_discount'} < $minimum}
        <div class="row">
            <div class="alert alert-danger">{intl l="Message info minimum de commande" d="livraisonparsecteurs" montant=$minimum}</div>
        </div>
        {/if}

        <div class="row">
            <div class="col-sm-4">
                {form name="thelia.order.delivery"}
                {form_field field='delivery-module'}
                <label for="delivery-method_{$module_id}">
                    <input type="radio" delivery-mode="lps" name="{$name}" id="delivery-method_{$module_id}" value="{$module_id}">
                    <strong>{intl l="Module name" d="livraisonparsecteurs"}</strong>
                    <br>
                </label>
                {/form_field}
                {/form}
            </div>
            <div class="col-sm-4">
                <div class="price text-right">
                    {loop type="lps_area" name="area-price" id={$area_id}}
                        {format_money number=$livraison symbol={currency attr='symbol'}}
                    {/loop}
                </div>
            </div>
        </div>

        <div class="row">
            <div class="col-md-12">
                <div id="select-delivery-day">
                {form name="thelia.order.delivery"}
                    <div class="table-responsive">
                        <table class="table table-striped table-condensed">
                            <thead>
                                <th style="text-align: center">{intl l='Next delivery day' d='livraisonparsecteurs'}</th>
                                <th style="text-align: center">{intl l='Schedule' d='livraisonparsecteurs'}</th>
                                <th style="text-align: center">{intl l='Choose this day' d='livraisonparsecteurs'}</th>
                            </thead>
                            <tbody>
                            {loop type="lps_area_schedule" name="area-schedule" area_id={$area_id}}
                                <tr>
                                    <td style="padding:10px; text-align: center">{$DAY_LABEL} {$CALCULATED_DAY}</td>
                                    <td style="padding:10px; text-align: center">{format_date date=$BEGIN format="H\hi"} à {format_date date=$END format="H\hi"}</td>
                                    <td style="padding:10px; text-align: center"><input type="radio" name="lps-choosen-day" value="{$ID}"{if {cart attr='total_taxed_price_without_discount'} < $minimum} disabled{/if} /></td>
                                </tr>
                            {/loop}
                            </tbody>
                        </table>
                    </div>
                {/form}
                </div>
            </div>
        </div>
    </td>

</script>


<script>

    // Masquer par défaut les options du mode LPS
    $(document).ready(function(){
        $("#delivery-module-38").html($('#lps_ui').html());
        $('#select-delivery-day').slideUp('fast');
    });

    // Gestion du pliage/dépliage du mode LPS
    $('input[type=radio]').click(function() {
        if ($('[delivery-mode=lps]').is(':checked')) {
            $('#select-delivery-day').slideDown('fast');
        } else {
            $('#select-delivery-day').slideUp('fast');
        }
    });

    //
    $("#form-cart-delivery").off('submit').submit(function(ev) {
        if ($('[delivery-mode=lps]').is(':checked')
            &&
            $('input[name=lps-choosen-day]:checked').length === 0) {
            alert("{intl l='Please select a delivery day' d='livraisonparsecteurs' js=1}");
            ev.preventDefault();
        }
    });


</script>
