<div class="row spbrow">
    <div class="col-xs-12" ng-if="!infosSpancAreSet">
        <div class="alert alert-danger">
            Veuillez renseigner les informations du SPANC
        </div>
    </div>
</div>

<div class="row spbrow spanc_Info">
    <div class="col-xs-12">
        <div class="col-xs-6">
            <h3> Informations du SPANC </h3>
        </div>
    </div>
    
    <div class="col-xs-8">

        <div class="row spbrow">
            <div class="col-xs-12">
                <label> Nom </label>
                <input type="text" class="form-control" ng-model="infosSpanc.nom"/>
            </div>
            <div class="col-xs-12">
                <label> SIRET </label>
                <input type="text" class="form-control" ng-model="infosSpanc.siret"/>
            </div>
        </div>
    </div>
    <div class="col-xs-4">
        <label> Logo ( <100kb )</label>&nbsp;
        <div ng-if="infosSpanc.logo" class="btn btn-default btn-xs" ng-click="removeLogo();infosSpanc.logo=false"><i
                class="fa fa-times"></i></div>
        <label class="custom-file-upload btn btn-xs btn-default  ">
            <input type="file"
                   style="display: none;"
                   onclick="this.value = null"
                   onchange="angular.element(this).scope().uploadSpancLogo(this)"/>
            Choisir une image
        </label>
        <div class="clearfix">
            <div class="previewSpancLogo">
                <div ng-if="infosSpanc.logo">
                    <img ng-src="{{infosSpanc.logo}}"/>
                </div>

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

</div>
<div>
    <anc-adresse res="infosSpanc"
                 show-contact="true"
                 show-title="true"></anc-adresse>
</div>
<div class="row">
    <div class="col-xs-12">
        <hr/>
        <h3>Agents du SPANC</h3>
    </div>

    <div class="col-xs-12">
        La liste des agents du SPANC est gérable depuis
        <a ng-click="goToListeUtilisateurs()" ng-if="xgos.isadmin" >
            <i class="fa fa-plug"></i> la liste principale des utilisateurs du portail.
        </a>

    </div>
</div>
<hr/>
<div class="row spbrow">
    <div class="col-xs-6">

        <h3 style="margin-top: 0;">
            Communautés de communes
            <span class="label label-default" style="font-size: 13px;">
                {{listeDesCC.length}}
            </span>
        </h3>
    </div>
    <div class="col-xs-6">
        <button class="btn btn-default pull-right" type="button" ng-click="openNouvelleCCDialog()">Ajouter une communauté de communes
        </button>
    </div>
</div>
<div class="row">
    <div class="col-xs-12">
        <div style="max-height: 500px; overflow: auto;">
            <table class="table table-bordered table-stripped">
                <tr>

                    <th>Nom</th>
                    <th>Commune</th>
                    <th>Code postal</th>
                    <th>Téléphone</th>
                    <th>Email</th>
                    <th>Actions</th>
                </tr>
                <tr ng-show="listeDesVilles.length">
                    <th> <input type="text" class="form-control" ng-model="ccfilter.value"></th>
                    <th> <input type="text" class="form-control" ng-model="ccfilter.ville"></th>
                    <th> <input type="text" class="form-control" ng-model="ccfilter.adresse_cp"></th>
                    <th> <input type="text" class="form-control" ng-model="ccfilter.num_tel"></th>
                    <th> <input type="text" class="form-control" ng-model="ccfilter.email"></th>
                    <th> <div class="btn btn-xs btn-default"
                              ng-click ="setDefaultCCFilter()">
                        <i class="fa fa-times"></i> Annuler les filtres </div>
                    </th>
                </tr>
                <tr ng-repeat="v in filteredListeCC = (listeDesCC | orderBy : 'value' | filter:ccfilter) track by $index  ">
                    <td align="center">
                         {{v.value}} 
                    </td>
                    <td align="center">
                        {{ v.adresse_ville }}
                    </td>
                    <td align="center">
                        {{v.adresse_cp}}
                    </td> 
                    <td align="center">
                        {{ v.num_tel }}
                    </td>
                    <td align="center">
                        {{ v.email }}
                    </td>
                    <td align="center">
                        <div class="btn btn-default btn-xs"
                             ng-click="openNouvelleCCDialog(v,$index,true)">
                            <i class="fa fa-edit"></i>
                        </div>
                        <div class="btn btn-danger btn-xs"
                             ng-click="supprimer_CC_spanc(v)">
                            <i class="fa fa-times"></i>
                        </div>
                    </td>
                </tr>
            </table>
        </div>

    </div>
</div>
<hr/>
<div class="row spbrow">
    <div class="col-xs-6">

        <h3 style="margin-top: 0;">
            Communes
            <span class="label label-default" style="font-size: 13px;">
                {{ (listeDesVilles | filter: {'gere_spanc':true }).length }} / {{listeDesVilles.length}}
            </span>
        </h3>
    </div>
    <div class="col-xs-6">
        <button class="btn btn-default pull-right" type="button" ng-click="openNouvelleVilleDialog()">
            Ajouter une commune
        </button>
        <label class="custom-file-upload btn btn-default pull-right">
            <input type="file" style="display: none;" accept=".csv"
                   onchange="angular.element(this).scope().loadCsvFile(this)" />
            <translate>common.import_csv</translate>
        </label>
    </div>
</div>
<div class="row spbrow" style="display:none;">
    <div class="col-xs-12">
        <input type="checkbox" ng-model="infosSpanc.allowExtraCity" disabled> Autoriser la saisie d'autres communes
    </div>  
    </div>  
</div>


<div class="row">
    <div class="col-xs-12">
        <div style="max-height: 500px; overflow: auto;">
            <table class="table table-bordered table-stripped">
                <tr>
                    <th>Gérée par le SPANC</th>
                    <th>Régie / DSP</th>
                    <th ng-click="sortBy('value',villesOrderBy)" style="cursor: pointer">
                        Nom
                        <span class="fa fa-sort-alpha-asc" ng-if="villesOrderBy.field === 'value' && !villesOrderBy.reverse"></span>
                        <span class="fa fa-sort-alpha-desc" ng-if="villesOrderBy.field === 'value' && villesOrderBy.reverse"></span>
                    </th>
                    <th ng-click="sortBy('cp[0]',villesOrderBy)" style="cursor: pointer">
                        Codes postaux
                        <span class="fa fa-sort-alpha-asc" ng-if="villesOrderBy.field === 'cp[0]' && !villesOrderBy.reverse"></span>
                        <span class="fa fa-sort-alpha-desc" ng-if="villesOrderBy.field === 'cp[0]' && villesOrderBy.reverse"></span>
                    </th>
                    <th ng-click="sortBy('insee',villesOrderBy)" style="cursor: pointer">
                        Code INSEE
                        <span class="fa fa-sort-alpha-asc" ng-if="villesOrderBy.field === 'insee' && !villesOrderBy.reverse"></span>
                        <span class="fa fa-sort-alpha-desc" ng-if="villesOrderBy.field === 'insee' && villesOrderBy.reverse"></span>
                    </th>
                    <th ng-click="sortBy('pays',villesOrderBy)" style="cursor: pointer">
                        Pays
                        <span class="fa fa-sort-alpha-asc" ng-if="villesOrderBy.field === 'pays' && !villesOrderBy.reverse"></span>
                        <span class="fa fa-sort-alpha-desc" ng-if="villesOrderBy.field === 'pays' && villesOrderBy.reverse"></span>
                    </th>
                    <th>Maire</th>
                    <th>Actions</th>
                </tr>
                <tr ng-show="listeDesVilles.length">
                    <th>
                        <select class="form-control"
                                ng-options="o.k as o.v for o in gestionSpancOptions"
                                ng-model="villesfilter.gere_spanc"
                                ng-change="setGereSpancFilter()">
                        </select>
                    </th>
                    <th>
                        <select class="form-control"
                                ng-model="villesfilter.dsp_regie"
                                ng-options="item.id as item.title for item in select_dsp_regie">
                        </select>
                    </th>
                    <th> <input type="text" class="form-control" ng-model="villesfilter.value"></th>
                    <th> <input type="text" class="form-control" ng-model="villesfilter.cp[0]"></th>
                    <th> <input type="text" class="form-control" ng-model="villesfilter.insee"></th>
                    <th> <input type="text" class="form-control" ng-model="villesfilter.pays"></th>
                    <th> <input type="text" class="form-control" ng-model="villesfilter.maire.nom"></th>
                    <th> <div class="btn btn-xs btn-default"
                              ng-click ="setDefaultVillesFilter()">
                        <i class="fa fa-times"></i> Annuler les filtres </div>
                    </th>
                </tr>
                <tr ng-repeat="v in filteredListeVilles = (listeDesVilles | orderBy : villesOrderBy.field : villesOrderBy.reverse | filter:villesfilter) track by $index  ">
                    <td align="center">
                        <input type="checkbox" ng-model="v.gere_spanc" ng-click="setGereSpanc(v)"/>
                    </td>
                    <td align="center" ng-bind-html='getDspOrRegie(v)'>
                       
                    </td>
                    <td>
                         {{v.value}} 
                    </td>
                    <td align="center">
                        <div class="col-xs-12" ng-repeat="x in v.cp track by $index">
                            {{x}}
                        </div>
                    </td> 
                    <td align="center">
                        {{ v.insee }}
                    </td>
                    <td align="center">
                        {{v.pays}}
                    </td>
                    <td align="center">
                        {{v.maire.civilite}}  {{v.maire.nom}}  {{v.maire.prenom}}
                    </td>
                    <td align="center">
                        <div class="btn btn-default btn-xs"
                             ng-click="openNouvelleVilleDialog(v,$index,true)">
                            <i class="fa fa-edit"></i>
                        </div>
                        <div class="btn btn-danger btn-xs"
                             ng-click="supprimer_ville_spanc(v)">
                            <i class="fa fa-times"></i>
                        </div>
                    </td>
                </tr>
            </table>
        </div>
    </div>
</div>

<div class="row spbrow" style="display:none;">
    <div class="col-xs-12">
        <input type="checkbox" ng-model="infosSpanc.allowExtraCity" disabled> Autoriser la saisie d'autres communes
    </div>  
</div>
<div class="row">
    <div class="col-xs-12 panelSaveAdminBot">
        <div class="btn btn-primary pull-right" ng-click="enregistrerInfoSpanc()">
            Enregistrer la configuration des informations relatives au SPANC
        </div>
    </div>
</div>



