<div class="DigitalSignage4_card DigitalSignage4_wp_card ds_auto">

    <div style="display: flex;align-items: center;margin:0">

        <img style="height: 61px; widows: 40" src="{$BatchUrl}" alt=""/>
        <h2 style="margin: 0 1em;">{$t::getTraduction( "traitement_lot_titre")}</h2>

    </div>

    <br><br>

    <h3>{$t::getTraduction( "Comment_ca_marche")}</h3>
    <p>{$t::getTraduction( "traitement_lot_description")}</p>

    <div class="wrapper_table">

        <div class="table" id="traitement_lot_rendu">
			
            <div class="row header">

                <div class="cell" style="width: calc(80px + 5em);">
                </div>


                <div class="cell">
                    {$t::getTraduction( "Nom")}
                </div>

                <div class="cell">
                    {$t::getTraduction( "Video_cree")}
                </div>

                <div class="cell">
                    {$t::getTraduction( "Etat")}
                </div>

                <div class="cell">
                    {$t::getTraduction( "Playlist")}
                </div>

                <div class="cell">
                    {$t::getTraduction( "Gabarit")}
                </div>

            </div>

            {foreach from=$traitement_par_lots item=traitement_par_lot}
                <div class="row" id="row_{$traitement_par_lot->getId()}">


                    <div class="cell" data-title="" style="display: flex; width: calc(80px + 5em);">

                        <button style="padding: .55em; border-radius: 2em;background-color: #25b9d7; border: none " class="btn DigitalSignage4_button btn-primary"  onclick="location.href=location.href+'&traitement_par_lotVue=add&lot_id={$traitement_par_lot->getId()}'">
                                <span class="DigitalSignage4_material-icons">
                                    edit
                                </span>
                        </button>

                        <button style="padding: .55em; border-radius: 2em; background-color: #e07281; border: none; margin-left: 1em !important;" onclick="saveIdDeleteLot({$traitement_par_lot->getId()})" class="btn DigitalSignage4_button btn-primary" data-toggle="modal" data-target="#ModalLot">
                                <span class="DigitalSignage4_material-icons">
                                    delete
                                </span>
                        </button>
						

                    </div>


                    <div class="cell" data-title="{$t::getTraduction( "Nom")}">
                        {$traitement_par_lot->getName()}
                    </div>


                    <div class="cell" data-title="{$t::getTraduction( "Video_cree")}">
                        {if $traitement_par_lot->getCreated()}
                            {$traitement_par_lot->getCreated()}
                        {else}
                            0
                        {/if}

                    </div>

                    <div class="cell" data-title="{$t::getTraduction( "Active")}">

						{$t::getTraduction( $traitement_par_lot->getEtat())}

                    </div>

                    <div class="cell" data-title="{$t::getTraduction( "Playlist")}">

                        {if $traitement_par_lot->getPlaylist()}
                            <a href="{$playlistBaseUrl}&playlistVue=update&id_playlist={$traitement_par_lot->getPlaylist()->get_id()}">{$traitement_par_lot->getPlaylist()->get_title()} </a>
                        {/if}

                    </div>

                    <div class="cell" data-title="{$t::getTraduction( "Gabarit")}">
                        {$traitement_par_lot->getGabarit()->getNom()}
                    </div>



                </div>
            {/foreach}
			

        </div>

        <div class="DigitalSignage4_material-icons add_playlist DigitalSignage4_click" onClick="location.href=location.href+'&traitement_par_lotVue=add'">
            control_point
        </div>


        <div class="modal fade" id="ModalLot" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
             aria-hidden="true">
            <div class="modal-dialog" role="document">
                <div class="modal-content">

                    <div class="modal-body">
                        <p>Voulez-vous vraiment supprimer ce lot ?</p>
                    </div>

                    <div class="modal-footer">
                        <button type="button" class="btn btn-secondary"
                                data-dismiss="modal">{$t::getTraduction( "Non")}</button>

                        <button onclick="deletelot();" type="button" data-dismiss="modal"
                                class="btn btn-primary">{$t::getTraduction( "Oui")}</button>
                    </div>

                </div>
            </div>
        </div>

        <script>

            var id_auto = -1;
			
			updateLot();
					
			function updateLot(){
				let form = new FormData();
				form.append("request", "rendu_Lot");

				let xhr = new XMLHttpRequest();

				xhr.open('POST', '', true);

				xhr.onload = function () {
					
					var rendu_lot = document.getElementById("traitement_lot_rendu");
					
					let response = this.responseText;
					//if (isJson(response)) {
						response = JSON.parse(response);
						rendu_lot.innerHTML=response['html'];
						if (response['stop_refresh']) {
							//plus de refresh
						} else {
							setTimeout(
								() => {
									updateLot()
								},
								10_000
							);
						}
					//}
					
					
					
				};
				
								
				xhr.onerror = function () {
					setTimeout(
						() => {
							updateLot()
						},
						10_000
					);
				}

				xhr.send(form);
			}

            function deletelot() {

				
				let form = new FormData();

                form.append("id", id_auto);
                form.append("request", "deleteLot");

                var xhr = new XMLHttpRequest();
                xhr.open('POST', '', true);
                xhr.onload = function () {
                    // do something to response

                    //console.log(this.responseText);
                 
                    if (this.responseText === "ok") {
                        //DigitalSignage4_showSuccessMessage("{$t::getTraduction( "Auto_delete")}");
                        element = document.getElementById('row_' + id_auto);
                        element.parentElement.removeChild(element);
                    } else {
                        DigitalSignage4_showErrorMessage(this.responseText);
                    }

                };

                xhr.send(form);
				

            }

            function saveIdDeleteLot(id) {
                id_auto = id;
            }




        </script>

    </div>

</div>
