<!-- Search for member structures -->

<template>
  <LayoutContainer class="map-view">
    <!-- Header -->
    <v-row>
      <v-layout>
        <h2 style="flex: 1;">
          {{ $t("member_companies") }}
        </h2>
        <v-btn-toggle mandatory dense @change="viewChanged">
          <v-btn>
            {{ $t("map") }}
          </v-btn>
          <v-btn>
            {{ $t("list") }}
          </v-btn>
        </v-btn-toggle>
      </v-layout>
    </v-row>

    <v-row>
      <!-- Map Column (hidden in 'list-view' mode)-->
      <v-col v-show="mapview" cols="6">
        <UiMapStructures
          ref="map"
          :structures="filteredStructures"
          @boundsUpdated="mapBoundsFilterChanged"
        />
      </v-col>

      <!-- Results column -->
      <v-col :cols="mapview ? 6 : 12">
        <!-- Search form -->
        <v-row>
          <v-form method="get" class="mt-8 w100">
            <v-row>
              <v-col cols="6" class="py-2 px-1">
                <v-text-field
                  v-model="textFilter"
                  type="text"
                  outlined
                  clearable
                  append-icon="mdi-magnify"
                  :label="$t('what') + ' ?'"
                  @click:append="$emit('change', value)"
                />
              </v-col>

              <v-col cols="6" class="py-2 px-1">
                <UiSearchAddress
                  ref="addressSearch"
                  type="municipality"
                  @change="locationFilterChanged"
                />
              </v-col>
            </v-row>

            <v-row>
              <v-col v-if="listview" cols="2" class="py-2 px-1">
                <v-btn class="h100" @click="reinitializeFilters">
                  {{ $t('reinitialize') }}
                </v-btn>
              </v-col>
              <v-col :cols="listview ? 8 : 12">
                <v-row class="filters">
                  <v-col :cols="3" class="py-2 px-1">
                    <v-select
                      v-model="typeFilter"
                      :label="$t('type')"
                      :items="translatedPractices"
                      item-value="id"
                      item-text="label"
                      filled
                      @change="filtersUpdated"
                    />
                  </v-col>
                  <v-col :cols="3" class="py-2 px-1">
                    <v-select
                      v-model="departmentFilter"
                      :items="departments"
                      item-value="code"
                      item-text="label"
                      :label="$t('department')"
                      filled
                      @change="filtersUpdated"
                    />
                  </v-col>
                  <v-col :cols="3" class="py-2 px-1">
                    <v-select
                      v-model="federationFilter"
                      :items="federations"
                      item-value="id"
                      item-text="name"
                      :label="$t('federation')"
                      filled
                      @change="filtersUpdated"
                    />
                  </v-col>
                  <v-col :cols="3" class="py-2 px-1">
                    <v-select
                      v-model="distanceFilter"
                      :label="$t('distance')"
                      :items="[
                        {distance: 10, label: '10km'},
                        {distance: 30, label: '30km'},
                        {distance: 100, label: '100km'},
                        {distance: 200, label: '200km'}
                      ]"
                      item-value="distance"
                      item-text="label"
                      filled
                      @change="filtersUpdated"
                    />
                  </v-col>
                </v-row>
              </v-col>
              <v-col v-if="listview" cols="2" class="py-2 px-1 d-flex justify-end">
                <v-btn class="h100">
                  {{ $t('search') }}
                </v-btn>
              </v-col>
            </v-row>

            <v-row v-show="mapview" class="px-2 pt-2">
              <v-btn @click="reinitializeFilters">
                {{ $t('reinitialize') }}
              </v-btn>
              <v-spacer />
              <v-btn>{{ $t('search') }}</v-btn>
            </v-row>
          </v-form>
        </v-row>

        <!-- Results -->
        <v-data-iterator
          :items="filteredStructures"
          :page.sync="page"
          :items-per-page="itemsPerPage"
          sort-by="name"
          hide-default-footer
          :no-data-text="$t('no_results')"
          class="pt-4 mt-6"
        >
          <template #header>
            <i class="results-count">{{ totalRecords }} {{ $t('results') }}</i>
          </template>

          <template #default="props">
            <v-row justify="space-between" class="mt-1 mb-3">
              <v-col
                v-for="structure in props.items"
                :key="structure.name"
                cols="12"
                sm="12"
                :md="mapview ? 6 : 12"
                class="py-2 px-1"
              >
                <v-card
                  elevation="1"
                  outlined
                  :class="'structure-card pa-3 d-flex ' + (mapview ? 'flex-column' : 'flex-row align-items-center')"
                >
                  <div class="d-flex justify-center">
                    <v-img
                      :src="structure.logoId ? ('https://api.opentalent.fr/app.php/_internal/secure/files/' + structure.logoId) : '/images/default.jpg'"
                      alt="poster"
                      height="80px"
                      min-width="160px"
                      max-width="80%"
                      max-height="100%"
                      :contain="true"
                      style="margin: 12px;"
                    />
                  </div>

                  <div class="d-flex flex-column">
                    <v-chip-group v-if="structure.practices" active-class="primary--text">
                      <v-chip v-for="practice in structure.practices.split(',')" :key="practice" outlined small pill>
                        {{ $t(practice) }}
                      </v-chip>
                    </v-chip-group>

                    <v-card-title class="title">
                      {{ structure.name }}
                    </v-card-title>

                    <v-card-text class="infos">
                      <table>
                        <tr>
                          <td class="py-1 pr-2">
                            <font-awesome-icon class="icon" :icon="['fas', 'map-marker-alt']" />
                          </td>
                          <td class="py-1">
                            {{ [structure.streetAddress, structure.postalCode, structure.addressCity].join(" ") }}
                          </td>
                        </tr>
                        <tr>
                          <td class="py-1 pr-2">
                            <font-awesome-icon class="icon" :icon="['fas', 'project-diagram']" />
                          </td>
                          <td class="py-1">
                            {{ structure.n1Name }}
                          </td>
                        </tr>
                      </table>
                    </v-card-text>
                  </div>
                  <span class="flex-fill" />

                  <v-card-actions :class="listview ? 'align-self-end' : ''">
                    <v-btn class="see" :to="'/structures_adherentes/' + structure.id">
                      <span style="margin-right: 6px;">{{ $t("see_more") }}</span>
                      <font-awesome-icon :icon="['fa', 'caret-right']" />
                    </v-btn>
                  </v-card-actions>
                </v-card>
              </v-col>
            </v-row>
          </template>

          <template #footer>
            <v-pagination
              v-model="page"
              :length="pageCount"
              total-visible="9"
              color="#e4611b"
            />
          </template>
        </v-data-iterator>
      </v-col>
    </v-row>
  </LayoutContainer>
</template>

<script>
import departments from '@/enums/departments'
import practices from '@/enums/practices'

export default {
  data () {
    return {
      structures: [
        {
          id: '5854',
          name: 'CMF Rhône-Alpes',
          logoId: '13038',
          principalType: 'REGIONAL_FEDERATION',
          website: 'https://fmra.opentalent.fr',
          latitude: '45.527896881103516',
          longitude: '5.741861820220947',
          streetAddress: 'Mairie de la Bridoire 510 route du Lac',
          postalCode: '73520',
          addressCity: 'LA BRIDOIRE',
          country: null,
          practices: null,
          n1Id: '12097',
          n1Name: 'CONFÉDÉRATION MUSICALE DE FRANCE',
          n2Id: null,
          n3Id: null,
          n4Id: null,
          n5Id: null,
          parents: '12097'
        },
        {
          id: '2289',
          name: 'Union des Fédérations Musicales de Haute-Savoie',
          logoId: '13039',
          principalType: 'DEPARTEMENTAL_FEDERATION',
          website: 'https://ufm74.opentalent.fr',
          latitude: '46.381401062012',
          longitude: '6.5108823776245',
          streetAddress: '13 avenue Jules Ferry',
          postalCode: '74200',
          addressCity: 'THONON-LES-BAINS',
          country: null,
          practices: null,
          n1Id: '5854',
          n1Name: 'CMF Rhône-Alpes',
          n2Id: '12097',
          n3Id: null,
          n4Id: null,
          n5Id: null,
          parents: '5854,12097'
        },
        {
          id: '1374',
          name: 'Fédération des Musiques du Faucigny',
          logoId: '13040',
          principalType: 'LOCAL_FEDERATION',
          website: 'https://fmfaucigny.opentalent.fr',
          latitude: '46.06029510498',
          longitude: '6.5806193351746',
          streetAddress: 'MAIRIE DE CLUSES HOTEL DE VILLE',
          postalCode: '74300',
          addressCity: 'Cluses',
          country: null,
          practices: null,
          n1Id: '2289',
          n1Name: 'Union des Fédérations Musicales de Haute-Savoie',
          n2Id: '5854',
          n3Id: '12097',
          n4Id: null,
          n5Id: null,
          parents: '2289,5854,12097'
        },
        {
          id: '1893',
          name: 'Fédération Musicale du Chablais',
          logoId: '13041',
          principalType: 'LOCAL_FEDERATION',
          website: 'https://fmchablais.opentalent.fr',
          latitude: '46.37556457519531',
          longitude: '6.527181148529053',
          streetAddress: 'Batiment Ivomar ZAC du Larry',
          postalCode: '74200',
          addressCity: 'MARIN',
          country: 'France',
          practices: null,
          n1Id: '2289',
          n1Name: 'Union des Fédérations Musicales de Haute-Savoie',
          n2Id: '5854',
          n3Id: '12097',
          n4Id: null,
          n5Id: null,
          parents: '2289,5854,12097'
        },
        {
          id: '1849',
          name: 'Fédération musicale du Genevois',
          logoId: '13042',
          principalType: 'LOCAL_FEDERATION',
          website: 'https://fmgenevois.opentalent.fr',
          latitude: '45.747020721436',
          longitude: '6.2935471534729',
          streetAddress: '8 rue Sainte Catherine',
          postalCode: '74600',
          addressCity: 'ANNECY',
          country: 'France',
          practices: null,
          n1Id: '2289',
          n1Name: 'Union des Fédérations Musicales de Haute-Savoie',
          n2Id: '5854',
          n3Id: '12097',
          n4Id: null,
          n5Id: null,
          parents: '2289,5854,12097'
        },
        {
          id: '498',
          name: "Orchestre d'Harmonie de Cluses",
          logoId: '13043',
          principalType: 'ARTISTIC_PRACTICE_ONLY',
          website: 'https://ohcluses.opentalent.fr',
          latitude: '46.06039',
          longitude: '6.580582',
          streetAddress: '16 B rue du Pré Bénévix Place Claude Anthoine Salle André Favre',
          postalCode: '74300',
          addressCity: 'CLUSES',
          country: 'France',
          practices: 'HARMONY_ORCHESTRA',
          n1Id: '1374',
          n1Name: 'Fédération des Musiques du Faucigny',
          n2Id: '2289',
          n3Id: '5854',
          n4Id: '12097',
          n5Id: null,
          parents: '1374,2289,5854,12097'
        },
        {
          id: '541',
          name: "Musique Municipale de Passy 'Echo de Warens'",
          logoId: '13044',
          principalType: 'ARTISTIC_PRACTICE_ONLY',
          website: 'https://musique-passy.opentalent.fr',
          latitude: '45.92109680175781',
          longitude: '6.695181846618652',
          streetAddress: "14 Chemin de l'île",
          postalCode: '74190',
          addressCity: 'PASSY',
          country: null,
          practices: 'HARMONY_ORCHESTRA',
          n1Id: '1374',
          n1Name: 'Fédération des Musiques du Faucigny',
          n2Id: '2289',
          n3Id: '5854',
          n4Id: '12097',
          n5Id: null,
          parents: '1374,2289,5854,12097'
        },
        {
          id: '584',
          name: "Harmonie d'Evian",
          logoId: null,
          principalType: 'ARTISTIC_PRACTICE_ONLY',
          website: 'https://orchestre-harmonie-evian.opentalent.fr',
          latitude: '46.39456558227539',
          longitude: '6.582443714141846',
          streetAddress: '1 nouvelle route du stade',
          postalCode: '74500',
          addressCity: 'EVIAN',
          country: 'France',
          practices: 'HARMONY_ORCHESTRA',
          n1Id: '1893',
          n1Name: 'Fédération Musicale du Chablais',
          n2Id: '2289',
          n3Id: '5854',
          n4Id: '12097',
          n5Id: null,
          parents: '1893,2289,5854,12097'
        },
        {
          id: '885',
          name: 'Harmonie Municipale de Machilly / Saint-Cergues',
          logoId: null,
          principalType: 'ARTISTIC_PRACTICE_ONLY',
          website: 'https://harmonie-machilly-saint-cergues.opentalent.fr',
          latitude: '46.25160217285156',
          longitude: '6.331543922424316',
          streetAddress: '290 route des Voirons',
          postalCode: '74140',
          addressCity: 'MACHILLY',
          country: 'France',
          practices: 'HARMONY_ORCHESTRA',
          n1Id: '1893',
          n1Name: 'Fédération Musicale du Chablais',
          n2Id: '2289',
          n3Id: '5854',
          n4Id: '12097',
          n5Id: null,
          parents: '1893,2289,5854,12097'
        },
        {
          id: '842',
          name: "Orchestre d'harmonie de La Clusaz",
          logoId: '13045',
          principalType: 'ARTISTIC_PRACTICE_ONLY',
          website: 'https://echo-des-aravis.opentalent.fr',
          latitude: '45.90581130981445',
          longitude: '6.421348571777344',
          streetAddress: 'Espace Musique 41, Salon des Dames',
          postalCode: '74220',
          addressCity: 'LA CLUSAZ',
          country: 'France',
          practices: 'HARMONY_ORCHESTRA',
          n1Id: '1849',
          n1Name: 'Fédération musicale du Genevois',
          n2Id: '2289',
          n3Id: '5854',
          n4Id: '12097',
          n5Id: null,
          parents: '1849,2289,5854,12097'
        },
        {
          id: '928',
          name: "Orchestre d'Harmonie de Sevrier",
          logoId: '13046',
          principalType: 'ARTISTIC_PRACTICE_ONLY',
          website: 'https://ohsevrier.opentalent.fr',
          latitude: '45.863983154297',
          longitude: '6.1415858268738',
          streetAddress: '8 rue Sainte Catherine',
          postalCode: '74600',
          addressCity: 'ANNECY',
          country: 'France',
          practices: 'HARMONY_ORCHESTRA',
          n1Id: '1849',
          n1Name: 'Fédération musicale du Genevois',
          n2Id: '2289',
          n3Id: '5854',
          n4Id: '12097',
          n5Id: null,
          parents: '1849,2289,5854,12097'
        },
        {
          id: '977',
          name: 'Association démonstration avec titre',
          logoId: '13047',
          principalType: 'ARTISTIC_PRACTICE_ONLY',
          website: 'https://demo.opentalent.fr',
          latitude: '43.05202865600586',
          longitude: '2.2192111015319824',
          streetAddress: '17, rue de la Mairie',
          postalCode: '11300',
          addressCity: 'LIMOUX',
          country: null,
          practices: null,
          n1Id: '93931',
          n1Name: 'Opentalent Manager',
          n2Id: null,
          n3Id: null,
          n4Id: null,
          n5Id: null,
          parents: '93931'
        },
        {
          id: '1065',
          name: "Orchestre d'Harmonie Municipal de Marignier",
          logoId: '13048',
          principalType: 'ARTISTIC_PRACTICE_ONLY',
          website: 'https://ohm-marignier.opentalent.fr',
          latitude: '46.0908203125',
          longitude: '6.500844955444336',
          streetAddress: 'SALLE JEAN BALLALOUD 17 RUE DU PATRONAGE',
          postalCode: '74970',
          addressCity: 'MARIGNIER',
          country: 'France',
          practices: 'HARMONY_ORCHESTRA',
          n1Id: '1374',
          n1Name: 'Fédération des Musiques du Faucigny',
          n2Id: '2289',
          n3Id: '5854',
          n4Id: '12097',
          n5Id: null,
          parents: '1374,2289,5854,12097'
        },
        {
          id: '1199',
          name: 'Harmonie Municipale de Samoëns',
          logoId: '13049',
          principalType: 'ARTISTIC_PRACTICE_EDUCATION',
          website: 'https://hm-samoens.opentalent.fr',
          latitude: '46.084044',
          longitude: '6.728173',
          streetAddress: 'C/ Sarah GUILLOT 200 route de Mathonex La Combe',
          postalCode: '74340',
          addressCity: 'SAMOENS',
          country: 'France',
          practices: 'HARMONY_ORCHESTRA',
          n1Id: '1374',
          n1Name: 'Fédération des Musiques du Faucigny',
          n2Id: '2289',
          n3Id: '5854',
          n4Id: '12097',
          n5Id: null,
          parents: '1374,2289,5854,12097'
        },
        {
          id: '1462',
          name: "L'Echo du Lac Bénit",
          logoId: '151967',
          principalType: 'ARTISTIC_PRACTICE_EDUCATION',
          website: 'https://musique-mtsaxonnex.opentalent.fr',
          latitude: '46.0538444519043',
          longitude: '6.484353542327881',
          streetAddress: "Mairie route de l'église",
          postalCode: '74130',
          addressCity: 'MONT-SAXONNEX',
          country: 'France',
          practices: 'HARMONY_ORCHESTRA',
          n1Id: '1374',
          n1Name: 'Fédération des Musiques du Faucigny',
          n2Id: '2289',
          n3Id: '5854',
          n4Id: '12097',
          n5Id: null,
          parents: '1374,2289,5854,12097'
        },
        {
          id: '1548',
          name: "Orchestre d'Harmonie de Chamonix Mont-Blanc",
          logoId: '13051',
          principalType: 'ARTISTIC_PRACTICE_ONLY',
          website: 'https://chamonixmusique.opentalent.fr',
          latitude: '45.9780387878418',
          longitude: '6.922300338745117',
          streetAddress: '242.LE PLAGNOLET',
          postalCode: '74400',
          addressCity: 'CHAMONIX MONT-BLANC',
          country: 'France',
          practices: 'HARMONY_ORCHESTRA',
          n1Id: '1374',
          n1Name: 'Fédération des Musiques du Faucigny',
          n2Id: '2289',
          n3Id: '5854',
          n4Id: '12097',
          n5Id: null,
          parents: '1374,2289,5854,12097'
        },
        {
          id: '1505',
          name: 'Harmonie Municipale de Saint-Jeoire',
          logoId: '13052',
          principalType: 'ARTISTIC_PRACTICE_ONLY',
          website: 'https://harmonie-saint-jeoire.opentalent.fr',
          latitude: '46.137715',
          longitude: '6.457955',
          streetAddress: 'Mairie 156 rue du Fauçigny',
          postalCode: '74490',
          addressCity: 'SAINT-JEOIRE EN FAUCIGNY',
          country: null,
          practices: 'HARMONY_ORCHESTRA',
          n1Id: '1374',
          n1Name: 'Fédération des Musiques du Faucigny',
          n2Id: '2289',
          n3Id: '5854',
          n4Id: '12097',
          n5Id: null,
          parents: '1374,2289,5854,12097'
        },
        {
          id: '1591',
          name: "Harmonie municipale des Houches l' écho des glaciers",
          logoId: '13053',
          principalType: 'ARTISTIC_PRACTICE_ONLY',
          website: 'https://musique-leshouches.opentalent.fr',
          latitude: '45.89430618286133',
          longitude: '6.803390026092529',
          streetAddress: '72 rte de la griaz',
          postalCode: '74310',
          addressCity: 'LES HOUCHES',
          country: null,
          practices: 'HARMONY_ORCHESTRA',
          n1Id: '1374',
          n1Name: 'Fédération des Musiques du Faucigny',
          n2Id: '2289',
          n3Id: '5854',
          n4Id: '12097',
          n5Id: null,
          parents: '1374,2289,5854,12097'
        },
        {
          id: '1634',
          name: 'Harmonie Municipale de Saint Gervais',
          logoId: null,
          principalType: 'ARTISTIC_PRACTICE_ONLY',
          website: 'https://harmonie-stgervais74.opentalent.fr',
          latitude: '45.89208984375',
          longitude: '6.711752414703369',
          streetAddress: "Mairie de Saint Gervais 50 Avenue du Mont d'Arbois",
          postalCode: '74170',
          addressCity: 'SAINT GERVAIS',
          country: null,
          practices: 'HARMONY_ORCHESTRA',
          n1Id: '1374',
          n1Name: 'Fédération des Musiques du Faucigny',
          n2Id: '2289',
          n3Id: '5854',
          n4Id: '12097',
          n5Id: null,
          parents: '1374,2289,5854,12097'
        },
        {
          id: '1677',
          name: "Orchestre d'harmonie   Megève",
          logoId: '170018',
          principalType: 'ARTISTIC_PRACTICE_EDUCATION',
          website: 'https://ohmegeve.opentalent.fr',
          latitude: '45.856876373291',
          longitude: '6.6177501678467',
          streetAddress: 'Maison des frères 23 quai du Glapet',
          postalCode: '74120',
          addressCity: 'MEGEVE',
          country: 'France',
          practices: 'HARMONY_ORCHESTRA',
          n1Id: '1374',
          n1Name: 'Fédération des Musiques du Faucigny',
          n2Id: '2289',
          n3Id: '5854',
          n4Id: '12097',
          n5Id: null,
          parents: '1374,2289,5854,12097'
        },
        {
          id: '1720',
          name: 'Harmonie de Mieussy',
          logoId: '13054',
          principalType: 'ARTISTIC_PRACTICE_ONLY',
          website: 'https://harmoniemieussy.opentalent.fr',
          latitude: '46.133934020996094',
          longitude: '6.5243239402771',
          streetAddress: 'Chef-Lieu Mairie',
          postalCode: '74440',
          addressCity: 'MIEUSSY',
          country: null,
          practices: 'HARMONY_ORCHESTRA',
          n1Id: '1374',
          n1Name: 'Fédération des Musiques du Faucigny',
          n2Id: '2289',
          n3Id: '5854',
          n4Id: '12097',
          n5Id: null,
          parents: '1374,2289,5854,12097'
        },
        {
          id: '1763',
          name: 'Harmonie Municipale Reignier-Esery',
          logoId: '13055',
          principalType: 'ARTISTIC_PRACTICE_ONLY',
          website: 'https://harmonie-reignier.opentalent.fr',
          latitude: '46.13705062866211',
          longitude: '6.2681145668029785',
          streetAddress: '197 Grande Rue Mairie de Reignier',
          postalCode: '74930',
          addressCity: 'REIGNIER',
          country: 'France',
          practices: 'HARMONY_ORCHESTRA',
          n1Id: '1374',
          n1Name: 'Fédération des Musiques du Faucigny',
          n2Id: '2289',
          n3Id: '5854',
          n4Id: '12097',
          n5Id: null,
          parents: '1374,2289,5854,12097'
        },
        {
          id: '1806',
          name: "Estudiantina d'Annecy",
          logoId: null,
          principalType: 'ARTISTIC_PRACTICE_ONLY',
          website: 'https://estudiantina-annecy.opentalent.fr',
          latitude: '45.89717102050781',
          longitude: '6.125161170959473',
          streetAddress: '5, allée du Tertre Chateauvieux',
          postalCode: '74600',
          addressCity: 'SEYNOD',
          country: 'France',
          practices: 'PLUCKED_ORCHESTRA',
          n1Id: '1849',
          n1Name: 'Fédération musicale du Genevois',
          n2Id: '2289',
          n3Id: '5854',
          n4Id: '12097',
          n5Id: null,
          parents: '1849,2289,5854,12097'
        },
        {
          id: '1938',
          name: 'HARMONIE MUNICIPALE DE SALLANCHES',
          logoId: '13056',
          principalType: 'ARTISTIC_PRACTICE_ONLY',
          website: 'https://sallanchesharmonie.opentalent.fr',
          latitude: '45.93632125854492',
          longitude: '6.629683494567871',
          streetAddress: 'quai de l hotel de ville mairie',
          postalCode: '74700',
          addressCity: 'SALLANCHES',
          country: 'France',
          practices: 'HARMONY_ORCHESTRA',
          n1Id: '1374',
          n1Name: 'Fédération des Musiques du Faucigny',
          n2Id: '2289',
          n3Id: '5854',
          n4Id: '12097',
          n5Id: null,
          parents: '1374,2289,5854,12097'
        },
        {
          id: '1981',
          name: 'Ecole de Musique des Aravis',
          logoId: null,
          principalType: 'ARTISTIC_PRACTICE_EDUCATION',
          website: 'https://aravismusique.opentalent.fr',
          latitude: '45.90442657470703',
          longitude: '6.42335319519043',
          streetAddress: '41, Salon des Dames Espace Musique',
          postalCode: '74220',
          addressCity: 'LA CLUSAZ',
          country: 'France',
          practices: 'ORCHESTRA_CLASS',
          n1Id: '1849',
          n1Name: 'Fédération musicale du Genevois',
          n2Id: '2289',
          n3Id: '5854',
          n4Id: '12097',
          n5Id: null,
          parents: '1849,2289,5854,12097'
        },
        {
          id: '2024',
          name: "Harmonie Municipale d'Arâches La Frasse",
          logoId: '13057',
          principalType: 'ARTISTIC_PRACTICE_ONLY',
          website: 'https://harmonie-araches-lafrasse.opentalent.fr',
          latitude: '46.02651596069336',
          longitude: '6.636077880859375',
          streetAddress: '213 route des cyclamens',
          postalCode: '74300',
          addressCity: 'Arâches-la-Frasse',
          country: 'France',
          practices: 'HARMONY_ORCHESTRA',
          n1Id: '1374',
          n1Name: 'Fédération des Musiques du Faucigny',
          n2Id: '2289',
          n3Id: '5854',
          n4Id: '12097',
          n5Id: null,
          parents: '1374,2289,5854,12097'
        },
        {
          id: '2072',
          name: 'Harmonie Municipale de Marnaz',
          logoId: '13058',
          principalType: 'ARTISTIC_PRACTICE_EDUCATION',
          website: 'https://harmoniedemarnaz.opentalent.fr',
          latitude: '46.060596466064',
          longitude: '6.5268602371216',
          streetAddress: '65, rue Antoine de Saint Exupéry',
          postalCode: '74460',
          addressCity: 'MARNAZ',
          country: 'France',
          practices: 'HARMONY_ORCHESTRA',
          n1Id: '1374',
          n1Name: 'Fédération des Musiques du Faucigny',
          n2Id: '2289',
          n3Id: '5854',
          n4Id: '12097',
          n5Id: null,
          parents: '1374,2289,5854,12097'
        },
        {
          id: '2160',
          name: "Harmonie L' Echo des deux Vallées",
          logoId: '13059',
          principalType: 'ARTISTIC_PRACTICE_ONLY',
          website: 'https://musique-chatillon.opentalent.fr',
          latitude: '46.08719253540039',
          longitude: '6.583064556121826',
          streetAddress: '15, place de la mairie',
          postalCode: '74300',
          addressCity: 'CHATILLON sur CLUSES',
          country: 'France',
          practices: 'HARMONY_ORCHESTRA',
          n1Id: '1374',
          n1Name: 'Fédération des Musiques du Faucigny',
          n2Id: '2289',
          n3Id: '5854',
          n4Id: '12097',
          n5Id: null,
          parents: '1374,2289,5854,12097'
        },
        {
          id: '2117',
          name: "Harmonie l'Espérance",
          logoId: '13060',
          principalType: 'ARTISTIC_PRACTICE_EDUCATION',
          website: 'https://esperance-vlg.opentalent.fr',
          latitude: '46.2016149',
          longitude: '6.2471439',
          streetAddress: "1 rue de l'Esperance",
          postalCode: '74100',
          addressCity: 'Ville-la-Grand',
          country: 'France',
          practices: null,
          n1Id: '1374',
          n1Name: 'Fédération des Musiques du Faucigny',
          n2Id: '2289',
          n3Id: '5854',
          n4Id: '12097',
          n5Id: null,
          parents: '1374,2289,5854,12097'
        },
        {
          id: '2245',
          name: "Orchestre d'Harmonie du Grand-Bornand",
          logoId: '13061',
          principalType: 'ARTISTIC_PRACTICE_ONLY',
          website: 'https://grandbo.opentalent.fr',
          latitude: '45.942027',
          longitude: '6.426699',
          streetAddress: 'Chalet Marie Liesse 170 route de la Patinoire',
          postalCode: '74450',
          addressCity: 'LE GRAND-BORNAND',
          country: 'France',
          practices: 'HARMONY_ORCHESTRA',
          n1Id: '1849',
          n1Name: 'Fédération musicale du Genevois',
          n2Id: '2289',
          n3Id: '5854',
          n4Id: '12097',
          n5Id: null,
          parents: '1849,2289,5854,12097'
        },
        {
          id: '2338',
          name: 'Echo de la Tournette',
          logoId: null,
          principalType: 'ARTISTIC_PRACTICE_EDUCATION',
          website: 'https://harmoniedethones.opentalent.fr',
          latitude: '45.88652038574219',
          longitude: '6.3144145011901855',
          streetAddress: '2 ter rue du Fier',
          postalCode: '74230',
          addressCity: 'THÔNES',
          country: 'France',
          practices: 'HARMONY_ORCHESTRA',
          n1Id: '1849',
          n1Name: 'Fédération musicale du Genevois',
          n2Id: '2289',
          n3Id: '5854',
          n4Id: '12097',
          n5Id: null,
          parents: '1849,2289,5854,12097'
        },
        {
          id: '2382',
          name: 'Le Choeur du Brevon',
          logoId: null,
          principalType: 'ARTISTIC_PRACTICE_ONLY',
          website: 'https://choeur-du-brevon.opentalent.fr',
          latitude: '46.232735',
          longitude: '6.535429',
          streetAddress: 'Les Chevriers 1200 rte du Brevon',
          postalCode: '74470',
          addressCity: 'LULLIN',
          country: 'France',
          practices: 'MIXED_CHORUS',
          n1Id: '1893',
          n1Name: 'Fédération Musicale du Chablais',
          n2Id: '2289',
          n3Id: '5854',
          n4Id: '12097',
          n5Id: null,
          parents: '1893,2289,5854,12097'
        },
        {
          id: '2541',
          name: 'Echos du Chéran',
          logoId: '13062',
          principalType: 'ARTISTIC_PRACTICE_ONLY',
          website: 'https://echosducheran.opentalent.fr',
          latitude: '45.816383361816406',
          longitude: '6.023940086364746',
          streetAddress: '34 Chemin des Moulins Maison des Associations',
          postalCode: '74540',
          addressCity: 'Alby-sur-Chéran',
          country: 'France',
          practices: 'HARMONY_ORCHESTRA',
          n1Id: '1849',
          n1Name: 'Fédération musicale du Genevois',
          n2Id: '2289',
          n3Id: '5854',
          n4Id: '12097',
          n5Id: null,
          parents: '1849,2289,5854,12097'
        },
        {
          id: '2587',
          name: "Orchestre d'Harmonie Municipal de Fillinges",
          logoId: '13063',
          principalType: 'ARTISTIC_PRACTICE_ONLY',
          website: 'https://ohfillinges.opentalent.fr',
          latitude: '46.15928268432617',
          longitude: '6.3435163497924805',
          streetAddress: '857 route du chef-lieu',
          postalCode: '74250',
          addressCity: 'FILLINGES',
          country: null,
          practices: 'HARMONY_ORCHESTRA',
          n1Id: '1893',
          n1Name: 'Fédération Musicale du Chablais',
          n2Id: '2289',
          n3Id: '5854',
          n4Id: '12097',
          n5Id: null,
          parents: '1893,2289,5854,12097'
        },
        {
          id: '2632',
          name: 'Musique Echo de Gavot',
          logoId: null,
          principalType: 'ARTISTIC_PRACTICE_EDUCATION',
          website: 'https://echodegavot.opentalent.fr',
          latitude: '46.37945556640625',
          longitude: '6.630401134490967',
          streetAddress: 'Bâtiment Communal Chef Lieu',
          postalCode: '74500',
          addressCity: 'SAINT PAUL EN CHABLAIS',
          country: 'France',
          practices: 'HARMONY_ORCHESTRA',
          n1Id: '1893',
          n1Name: 'Fédération Musicale du Chablais',
          n2Id: '2289',
          n3Id: '5854',
          n4Id: '12097',
          n5Id: null,
          parents: '1893,2289,5854,12097'
        },
        {
          id: '2678',
          name: 'ÉCOLE DES ARTS VIVANTS DE FAVERGES-SEYTHENEX',
          logoId: '339356',
          principalType: 'ARTISTIC_PRACTICE_EDUCATION',
          website: 'https://musique-faverges.opentalent.fr',
          latitude: '48.670036315918',
          longitude: '8.2316989898682',
          streetAddress: 'Place Bühlertal Centre musical Robert Stäubli',
          postalCode: '74210',
          addressCity: 'FAVERGES-SEYTHENEX',
          country: 'France',
          practices: 'EDUCATION',
          n1Id: '1849',
          n1Name: 'Fédération musicale du Genevois',
          n2Id: '2289',
          n3Id: '5854',
          n4Id: '12097',
          n5Id: null,
          parents: '1849,2289,5854,12097'
        },
        {
          id: '2762',
          name: "Orchestre d'Harmonie Cruseilles-Le Châble",
          logoId: '13065',
          principalType: 'ARTISTIC_PRACTICE_ONLY',
          website: 'https://ohcc.opentalent.fr',
          latitude: '46.03376007080078',
          longitude: '6.106630802154541',
          streetAddress: "Centre de Secours 141 route d'Annecy",
          postalCode: '74350',
          addressCity: 'CRUSEILLES',
          country: 'France',
          practices: 'HARMONY_ORCHESTRA',
          n1Id: '1374',
          n1Name: 'Fédération des Musiques du Faucigny',
          n2Id: '2289',
          n3Id: '5854',
          n4Id: '12097',
          n5Id: null,
          parents: '1374,2289,5854,12097'
        },
        {
          id: '2808',
          name: 'Harmonie Intercommunale de Bonneville - Ayze - Vougy',
          logoId: '159185',
          principalType: 'ARTISTIC_PRACTICE_EDUCATION',
          website: 'https://harmonie-bonneville.opentalent.fr',
          latitude: '0',
          longitude: '0',
          streetAddress: null,
          postalCode: '74130',
          addressCity: 'Bonneville',
          country: null,
          practices: 'EDUCATION,HARMONY_ORCHESTRA,ORCHESTRA_CLASS',
          n1Id: '1374',
          n1Name: 'Fédération des Musiques du Faucigny',
          n2Id: '2289',
          n3Id: '5854',
          n4Id: '12097',
          n5Id: null,
          parents: '1374,2289,5854,12097'
        },
        {
          id: '2854',
          name: 'Harmonie municipale du fer à cheval',
          logoId: null,
          principalType: 'ARTISTIC_PRACTICE_EDUCATION',
          website: 'https://fanfareduferacheval.opentalent.fr',
          latitude: '46.070793151855',
          longitude: '6.8110952377319',
          streetAddress: '104 Route de Nambride',
          postalCode: '74740',
          addressCity: 'SIXT-FER-A-CHEVAL',
          country: 'France',
          practices: 'HARMONY_ORCHESTRA',
          n1Id: '1374',
          n1Name: 'Fédération des Musiques du Faucigny',
          n2Id: '2289',
          n3Id: '5854',
          n4Id: '12097',
          n5Id: null,
          parents: '1374,2289,5854,12097'
        },
        {
          id: '2992',
          name: 'Esperance Douvainoise',
          logoId: '48398',
          principalType: 'ARTISTIC_PRACTICE_EDUCATION',
          website: 'https://esperance-douvainoise.opentalent.fr',
          latitude: '46.303418874294',
          longitude: '6.3039148207627',
          streetAddress: 'Avenue du Stade Espace Associatif et Culturel',
          postalCode: '74140',
          addressCity: 'Douvaine',
          country: 'France',
          practices: 'EDUCATION,HARMONY_ORCHESTRA,ORCHESTRA_CLASS',
          n1Id: '1893',
          n1Name: 'Fédération Musicale du Chablais',
          n2Id: '2289',
          n3Id: '5854',
          n4Id: '12097',
          n5Id: null,
          parents: '1893,2289,5854,12097'
        },
        {
          id: '3038',
          name: "Orchestre d'Harmonie de Rumilly",
          logoId: '13068',
          principalType: 'ARTISTIC_PRACTICE_ONLY',
          website: 'https://harmonierumilly74.opentalent.fr',
          latitude: '45.86713790893555',
          longitude: '5.942357063293457',
          streetAddress: "rue de l'annexion Maison des Associations",
          postalCode: '74150',
          addressCity: 'RUMILLY',
          country: null,
          practices: 'HARMONY_ORCHESTRA',
          n1Id: '1849',
          n1Name: 'Fédération musicale du Genevois',
          n2Id: '2289',
          n3Id: '5854',
          n4Id: '12097',
          n5Id: null,
          parents: '1849,2289,5854,12097'
        },
        {
          id: '3084',
          name: 'Ecole de Musique du Pays de Cruseilles',
          logoId: '13069',
          principalType: 'ARTISTIC_EDUCATION_ONLY',
          website: 'https://ecole-musique-cruseilles.opentalent.fr',
          latitude: '46.03089904785156',
          longitude: '6.105513572692871',
          streetAddress: "141 route d'Annecy",
          postalCode: '74350',
          addressCity: 'CRUSEILLES',
          country: null,
          practices: 'EDUCATION',
          n1Id: '1849',
          n1Name: 'Fédération musicale du Genevois',
          n2Id: '2289',
          n3Id: '5854',
          n4Id: '12097',
          n5Id: null,
          parents: '1849,2289,5854,12097'
        },
        {
          id: '3138',
          name: 'Association musicale de Vétraz-Monthoux VETRAZ MUSIQUE',
          logoId: null,
          principalType: 'ARTISTIC_PRACTICE_EDUCATION',
          website: 'https://vetrazmusique.opentalent.fr',
          latitude: '46.186485290527344',
          longitude: '6.270125389099121',
          streetAddress: '7, Chemin des Clus',
          postalCode: '74100',
          addressCity: 'Vétraz-Monthoux',
          country: 'France',
          practices: 'EDUCATION,HARMONY_ORCHESTRA',
          n1Id: '1374',
          n1Name: 'Fédération des Musiques du Faucigny',
          n2Id: '2289',
          n3Id: '5854',
          n4Id: '12097',
          n5Id: null,
          parents: '1374,2289,5854,12097'
        },
        {
          id: '3186',
          name: "L'écho du Semnoz",
          logoId: null,
          principalType: 'ARTISTIC_PRACTICE_ONLY',
          website: 'https://harmoniedegruffy.opentalent.fr',
          latitude: '45.78824234008789',
          longitude: '6.054960250854492',
          streetAddress: 'ENTREVES',
          postalCode: '73340',
          addressCity: 'BELLECOMBE-EN-BAUGES',
          country: 'France',
          practices: 'HARMONY_ORCHESTRA',
          n1Id: '1849',
          n1Name: 'Fédération musicale du Genevois',
          n2Id: '2289',
          n3Id: '5854',
          n4Id: '12097',
          n5Id: null,
          parents: '1849,2289,5854,12097'
        },
        {
          id: '3232',
          name: 'Centre de Pratique Musicale du Lac',
          logoId: '13070',
          principalType: 'ARTISTIC_PRACTICE_EDUCATION',
          website: 'https://cpml.opentalent.fr',
          latitude: '45.83303451538086',
          longitude: '6.165421962738037',
          streetAddress: '72, Route de Tavan',
          postalCode: '74410',
          addressCity: 'SAINT-JORIOZ',
          country: 'France',
          practices: 'EDUCATION',
          n1Id: '1849',
          n1Name: 'Fédération musicale du Genevois',
          n2Id: '2289',
          n3Id: '5854',
          n4Id: '12097',
          n5Id: null,
          parents: '1849,2289,5854,12097'
        },
        {
          id: '3278',
          name: 'Harmonie de Saint-Sigismond',
          logoId: null,
          principalType: 'ARTISTIC_PRACTICE_ONLY',
          website: 'https://musique-saintsigismond.opentalent.fr',
          latitude: '46.07004928588867',
          longitude: '6.620676040649414',
          streetAddress: '685 les alluaz',
          postalCode: '74300',
          addressCity: 'SAINT-SIGISMOND',
          country: 'France',
          practices: 'HARMONY_ORCHESTRA',
          n1Id: '1374',
          n1Name: 'Fédération des Musiques du Faucigny',
          n2Id: '2289',
          n3Id: '5854',
          n4Id: '12097',
          n5Id: null,
          parents: '1374,2289,5854,12097'
        },
        {
          id: '3324',
          name: 'La Voix du Léman',
          logoId: '39926',
          principalType: 'ARTISTIC_PRACTICE_ONLY',
          website: 'https://ohlavoixduleman.opentalent.fr',
          latitude: '46.3897089',
          longitude: '6.5359195999999',
          streetAddress: 'Place du 8 mai 1945',
          postalCode: '74500',
          addressCity: 'PUBLIER',
          country: 'France',
          practices: 'HARMONY_ORCHESTRA',
          n1Id: '1893',
          n1Name: 'Fédération Musicale du Chablais',
          n2Id: '2289',
          n3Id: '5854',
          n4Id: '12097',
          n5Id: null,
          parents: '1893,2289,5854,12097'
        },
        {
          id: '3370',
          name: 'Ecole de musique ABC',
          logoId: null,
          principalType: 'ARTISTIC_PRACTICE_EDUCATION',
          website: 'https://ecoledemusiqueabc.opentalent.fr',
          latitude: '46.13518142700195',
          longitude: '6.132789611816406',
          streetAddress: "34 place de l'église",
          postalCode: '74160',
          addressCity: 'ARCHAMPS',
          country: 'France',
          practices: 'EDUCATION,ORCHESTRA_CLASS',
          n1Id: '1849',
          n1Name: 'Fédération musicale du Genevois',
          n2Id: '2289',
          n3Id: '5854',
          n4Id: '12097',
          n5Id: null,
          parents: '1849,2289,5854,12097'
        },
        {
          id: '3416',
          name: 'ASSOCIATION MUSICALE DE SAINT APOLLINAIRE',
          logoId: '13072',
          principalType: 'ARTISTIC_PRACTICE_EDUCATION',
          website: 'https://amsa.opentalent.fr',
          latitude: '47.33273390238',
          longitude: '5.082311455542',
          streetAddress: '129 RUE SAINT JEAN MAISON DES ASSOCIATIONS',
          postalCode: '21850',
          addressCity: 'SAINT-APOLLINAIRE',
          country: 'France',
          practices: 'EDUCATION',
          n1Id: '8522',
          n1Name: "CMF Côte d'Or",
          n2Id: '8565',
          n3Id: '12097',
          n4Id: null,
          n5Id: null,
          parents: '8522,8565,12097'
        },
        {
          id: '3506',
          name: "Orchestre d'Harmonie Municipale de SCIONZIER (OHMS)",
          logoId: '307099',
          principalType: 'ARTISTIC_PRACTICE_ONLY',
          website: 'https://harmonie-scionzier.opentalent.fr',
          latitude: '46.0593998',
          longitude: '6.5524099',
          streetAddress: null,
          postalCode: '74950',
          addressCity: 'SCIONZIER',
          country: 'France',
          practices: 'HARMONY_ORCHESTRA',
          n1Id: '1374',
          n1Name: 'Fédération des Musiques du Faucigny',
          n2Id: '2289',
          n3Id: '5854',
          n4Id: '12097',
          n5Id: null,
          parents: '1374,2289,5854,12097'
        },
        {
          id: '10733',
          name: "Fédération des sociétés de musique d'Alsace",
          logoId: '13074',
          principalType: 'REGIONAL_FEDERATION',
          website: 'https://fsma.opentalent.fr',
          latitude: '48.5789133',
          longitude: '7.7540132',
          streetAddress: 'Maison des associations 1a Place des Orphelins',
          postalCode: '67000',
          addressCity: 'STRASBOURG',
          country: null,
          practices: null,
          n1Id: '12097',
          n1Name: 'CONFÉDÉRATION MUSICALE DE FRANCE',
          n2Id: null,
          n3Id: null,
          n4Id: null,
          n5Id: null,
          parents: '12097'
        },
        {
          id: '37321',
          name: "Association des Sociétés Chorales d'Alsace",
          logoId: null,
          principalType: 'DEPARTEMENTAL_FEDERATION',
          website: 'https://asca.opentalent.fr',
          latitude: '47.74827575683594',
          longitude: '7.346599578857422',
          streetAddress: 'c/o Sylvie Maurice 14 rue de Chalampé',
          postalCode: '68100',
          addressCity: 'Mulhouse',
          country: null,
          practices: null,
          n1Id: '12097',
          n1Name: 'CONFÉDÉRATION MUSICALE DE FRANCE',
          n2Id: null,
          n3Id: null,
          n4Id: null,
          n5Id: null,
          parents: '12097'
        },
        {
          id: '37386',
          name: 'Union Départementale des Musiques du Bas Rhin',
          logoId: null,
          principalType: 'DEPARTEMENTAL_FEDERATION',
          website: 'https://udmbr.opentalent.fr',
          latitude: '48.8292077',
          longitude: '7.6580206',
          streetAddress: '6 rue des Roses',
          postalCode: '67350',
          addressCity: 'DAUENDORF',
          country: null,
          practices: null,
          n1Id: '10733',
          n1Name: "Fédération des sociétés de musique d'Alsace",
          n2Id: '12097',
          n3Id: null,
          n4Id: null,
          n5Id: null,
          parents: '10733,12097'
        },
        {
          id: '37418',
          name: 'CMF  HAUTE-ALSACE',
          logoId: '359019',
          principalType: 'DEPARTEMENTAL_FEDERATION',
          website: 'https://udsmhr.opentalent.fr',
          latitude: '47.776653289795',
          longitude: '7.3691039085388',
          streetAddress: '9 rue de Saint-Louis',
          postalCode: '68390',
          addressCity: 'SAUSHEIM',
          country: 'France',
          practices: null,
          n1Id: '10733',
          n1Name: "Fédération des sociétés de musique d'Alsace",
          n2Id: '12097',
          n3Id: null,
          n4Id: null,
          n5Id: null,
          parents: '10733,12097'
        },
        {
          id: '11815',
          name: "CMF-Aquitaine Fédération Musicale d'Aquitaine",
          logoId: null,
          principalType: 'REGIONAL_FEDERATION',
          website: 'https://fmaquitaine.opentalent.fr',
          latitude: '44.9259247',
          longitude: '-0.49066590000007',
          streetAddress: '18 Place de la Victoire Hotel de ville',
          postalCode: '33440',
          addressCity: 'Ambarès-et-Lagrave',
          country: null,
          practices: null,
          n1Id: '12097',
          n1Name: 'CONFÉDÉRATION MUSICALE DE FRANCE',
          n2Id: null,
          n3Id: null,
          n4Id: null,
          n5Id: null,
          parents: '12097'
        },
        {
          id: '37450',
          name: 'Union des Sociétés Musicales de la Dordogne',
          logoId: null,
          principalType: 'DEPARTEMENTAL_FEDERATION',
          website: 'https://udmd.opentalent.fr',
          latitude: '45.41175842285156',
          longitude: '0.9117730259895325',
          streetAddress: '15 rue Albert Bonneau',
          postalCode: '24800',
          addressCity: 'THIVIERS',
          country: 'France',
          practices: null,
          n1Id: '11815',
          n1Name: "CMF-Aquitaine Fédération Musicale d'Aquitaine",
          n2Id: '12097',
          n3Id: null,
          n4Id: null,
          n5Id: null,
          parents: '11815,12097'
        },
        {
          id: '23917',
          name: 'CMF GIRONDE',
          logoId: '39568',
          principalType: 'DEPARTEMENTAL_FEDERATION',
          website: 'https://udam33.opentalent.fr',
          latitude: '44.9269344',
          longitude: '-0.4900999',
          streetAddress: 'CMF GIRONDE Hôtel de Ville 18, place de la Victoire',
          postalCode: '33440',
          addressCity: 'AMBARES et LAGRAVE',
          country: null,
          practices: null,
          n1Id: '11815',
          n1Name: "CMF-Aquitaine Fédération Musicale d'Aquitaine",
          n2Id: '12097',
          n3Id: null,
          n4Id: null,
          n5Id: null,
          parents: '11815,12097'
        },
        {
          id: '37482',
          name: 'Union des Sociétés Musicales de Lot et Garonne',
          logoId: null,
          principalType: 'DEPARTEMENTAL_FEDERATION',
          website: 'https://usmlg.opentalent.fr',
          latitude: '44.197147369384766',
          longitude: '0.6396999955177307',
          streetAddress: '1944 Route de Pécau',
          postalCode: '47240',
          addressCity: 'BON-ENCONTRE',
          country: null,
          practices: null,
          n1Id: '11815',
          n1Name: "CMF-Aquitaine Fédération Musicale d'Aquitaine",
          n2Id: '12097',
          n3Id: null,
          n4Id: null,
          n5Id: null,
          parents: '11815,12097'
        },
        {
          id: '37498',
          name: 'Confédération musicale de France en Pyrénées Atlantiques',
          logoId: '13078',
          principalType: 'DEPARTEMENTAL_FEDERATION',
          website: 'https://udmpa.opentalent.fr',
          latitude: '43.48881912231445',
          longitude: '-0.7686976790428162',
          streetAddress: '',
          postalCode: '',
          addressCity: '',
          country: 'France',
          practices: null,
          n1Id: '11815',
          n1Name: "CMF-Aquitaine Fédération Musicale d'Aquitaine",
          n2Id: '12097',
          n3Id: null,
          n4Id: null,
          n5Id: null,
          parents: '11815,12097'
        },
        {
          id: '37514',
          name: "Fédération Musicale d'Auvergne",
          logoId: '13079',
          principalType: 'REGIONAL_FEDERATION',
          website: 'https://fma.opentalent.fr',
          latitude: '45.28485107421875',
          longitude: '3.3902878761291504',
          streetAddress: 'BP 114',
          postalCode: '43103',
          addressCity: 'BRIOUDE cedex 03',
          country: 'France',
          practices: null,
          n1Id: '12097',
          n1Name: 'CONFÉDÉRATION MUSICALE DE FRANCE',
          n2Id: null,
          n3Id: null,
          n4Id: null,
          n5Id: null,
          parents: '12097'
        },
        {
          id: '37530',
          name: "Union Départementale des Sociétés Musicales de l'Allier",
          logoId: '13080',
          principalType: 'DEPARTEMENTAL_FEDERATION',
          website: 'https://udsma.opentalent.fr',
          latitude: '46.102451324463',
          longitude: '3.1950829029083',
          streetAddress: '18, rue Croix des Rameaux',
          postalCode: '03800',
          addressCity: 'Gannat',
          country: null,
          practices: null,
          n1Id: '37514',
          n1Name: "Fédération Musicale d'Auvergne",
          n2Id: '12097',
          n3Id: null,
          n4Id: null,
          n5Id: null,
          parents: '37514,12097'
        },
        {
          id: '37546',
          name: 'Union Départementale des Sociétés Musicales du Cantal',
          logoId: null,
          principalType: 'DEPARTEMENTAL_FEDERATION',
          website: 'https://udsm.opentalent.fr',
          latitude: '44.925296783447266',
          longitude: '2.4423909187316895',
          streetAddress: 'Centre Pierre Mendès France 37 rue des Carmes',
          postalCode: '15000',
          addressCity: 'Aurillac',
          country: null,
          practices: null,
          n1Id: '37514',
          n1Name: "Fédération Musicale d'Auvergne",
          n2Id: '12097',
          n3Id: null,
          n4Id: null,
          n5Id: null,
          parents: '37514,12097'
        },
        {
          id: '37578',
          name: 'Union Départementale des Sociétés Musicales du Puy de Dôme',
          logoId: null,
          principalType: 'DEPARTEMENTAL_FEDERATION',
          website: 'https://udsm63.opentalent.fr',
          latitude: '45.796936035156',
          longitude: '3.2485909461975',
          streetAddress: 'BP69 7 av Roger Prat',
          postalCode: '63430',
          addressCity: 'Pont du Chateau',
          country: null,
          practices: null,
          n1Id: '37514',
          n1Name: "Fédération Musicale d'Auvergne",
          n2Id: '12097',
          n3Id: null,
          n4Id: null,
          n5Id: null,
          parents: '37514,12097'
        },
        {
          id: '10776',
          name: 'Fédération Musicale de Basse-Normandie',
          logoId: null,
          principalType: 'REGIONAL_FEDERATION',
          website: 'https://fmbn.opentalent.fr',
          latitude: '49.193336486816',
          longitude: '-0.40285688638687',
          streetAddress: "Michel Morin 8 rue d'auvergne",
          postalCode: '14000',
          addressCity: 'CAEN',
          country: null,
          practices: null,
          n1Id: '12097',
          n1Name: 'CONFÉDÉRATION MUSICALE DE FRANCE',
          n2Id: null,
          n3Id: null,
          n4Id: null,
          n5Id: null,
          parents: '12097'
        },
        {
          id: '8565',
          name: 'CMF Bourgogne',
          logoId: '13082',
          principalType: 'REGIONAL_FEDERATION',
          website: 'https://frsmb.opentalent.fr',
          latitude: '47.32759475708008',
          longitude: '4.82658052444458',
          streetAddress: '1 RUE DE LA PETITE FIN',
          postalCode: '21410',
          addressCity: 'Ancey',
          country: 'France',
          practices: null,
          n1Id: '12097',
          n1Name: 'CONFÉDÉRATION MUSICALE DE FRANCE',
          n2Id: null,
          n3Id: null,
          n4Id: null,
          n5Id: null,
          parents: '12097'
        },
        {
          id: '8522',
          name: "CMF Côte d'Or",
          logoId: '13083',
          principalType: 'DEPARTEMENTAL_FEDERATION',
          website: 'https://cmf21.opentalent.fr',
          latitude: '47.289310455322',
          longitude: '5.0091304779053',
          streetAddress: "L'entrepôt, boite J4/16 40 rue de Longvic",
          postalCode: '21300',
          addressCity: 'Chenôve',
          country: 'France',
          practices: null,
          n1Id: '8565',
          n1Name: 'CMF Bourgogne',
          n2Id: '12097',
          n3Id: null,
          n4Id: null,
          n5Id: null,
          parents: '8565,12097'
        },
        {
          id: '19449',
          name: 'CONFEDERATION MUSICALE DE LA NIEVRE CMF Nièvre',
          logoId: '13084',
          principalType: 'DEPARTEMENTAL_FEDERATION',
          website: 'https://udsmn.opentalent.fr',
          latitude: '47.06442642211914',
          longitude: '3.2113540172576904',
          streetAddress: '435 Rue des Ouches',
          postalCode: '58130',
          addressCity: 'Urzy',
          country: null,
          practices: null,
          n1Id: '8565',
          n1Name: 'CMF Bourgogne',
          n2Id: '12097',
          n3Id: null,
          n4Id: null,
          n5Id: null,
          parents: '8565,12097'
        },
        {
          id: '19433',
          name: 'FMSL - CMF Saône et Loire',
          logoId: '13085',
          principalType: 'DEPARTEMENTAL_FEDERATION',
          website: 'https://fmsl.opentalent.fr',
          latitude: '46.78220748901367',
          longitude: '4.855426788330078',
          streetAddress: '30 rue Saint Georges',
          postalCode: '71100',
          addressCity: 'CHALON-SUR-SAÔNE',
          country: null,
          practices: null,
          n1Id: '8565',
          n1Name: 'CMF Bourgogne',
          n2Id: '12097',
          n3Id: null,
          n4Id: null,
          n5Id: null,
          parents: '8565,12097'
        },
        {
          id: '19211',
          name: "Fédération Musicale de l'Yonne",
          logoId: '13086',
          principalType: 'DEPARTEMENTAL_FEDERATION',
          website: 'https://fmy.opentalent.fr',
          latitude: '47.73518371582',
          longitude: '3.2917716503143',
          streetAddress: '11 ue de la taille  les Breandes',
          postalCode: '89000',
          addressCity: 'PERRIGNY',
          country: null,
          practices: null,
          n1Id: '8565',
          n1Name: 'CMF Bourgogne',
          n2Id: '12097',
          n3Id: null,
          n4Id: null,
          n5Id: null,
          parents: '8565,12097'
        },
        {
          id: '10819',
          name: 'CMF Bretagne',
          logoId: null,
          principalType: 'REGIONAL_FEDERATION',
          website: 'https://federationmusicalebretagne.opentalent.fr',
          latitude: '48.03236389160156',
          longitude: '-3.4900450706481934',
          streetAddress: 'Pont Tanguy Domaine de la Flûte Enchantée',
          postalCode: '56320',
          addressCity: 'Le Faouët',
          country: null,
          practices: null,
          n1Id: '12097',
          n1Name: 'CONFÉDÉRATION MUSICALE DE FRANCE',
          n2Id: null,
          n3Id: null,
          n4Id: null,
          n5Id: null,
          parents: '12097'
        },
        {
          id: '37594',
          name: "Fédération musicale de Côtes d'Armor",
          logoId: null,
          principalType: 'DEPARTEMENTAL_FEDERATION',
          website: 'https://fepem.opentalent.fr',
          latitude: '48.51417922973633',
          longitude: '-2.7658350467681885',
          streetAddress: 'Pont Tanguy Domaine de la Flûte Enchantée',
          postalCode: '56320',
          addressCity: 'LE FAOUËT',
          country: 'France',
          practices: null,
          n1Id: '10819',
          n1Name: 'CMF Bretagne',
          n2Id: '12097',
          n3Id: null,
          n4Id: null,
          n5Id: null,
          parents: '10819,12097'
        },
        {
          id: '37610',
          name: 'Fédération Musicale de Finistère',
          logoId: null,
          principalType: 'DEPARTEMENTAL_FEDERATION',
          website: 'https://fmf.opentalent.fr',
          latitude: '48.428123474121094',
          longitude: '-4.503469944000244',
          streetAddress: 'Pont Tanguy Domaine de la Flûte Enchantée',
          postalCode: '56320',
          addressCity: 'LE FAOUËT',
          country: null,
          practices: null,
          n1Id: '10819',
          n1Name: 'CMF Bretagne',
          n2Id: '12097',
          n3Id: null,
          n4Id: null,
          n5Id: null,
          parents: '10819,12097'
        },
        {
          id: '37626',
          name: 'Fédération des structures musicales en Ille et Vilaine',
          logoId: '13087',
          principalType: 'DEPARTEMENTAL_FEDERATION',
          website: 'https://fsm35.opentalent.fr',
          latitude: '47.96603775024414',
          longitude: '-1.7967469692230225',
          streetAddress: 'Pont Tanguy',
          postalCode: '56320',
          addressCity: 'LE FAOUËT',
          country: null,
          practices: null,
          n1Id: '10819',
          n1Name: 'CMF Bretagne',
          n2Id: '12097',
          n3Id: null,
          n4Id: null,
          n5Id: null,
          parents: '10819,12097'
        },
        {
          id: '37642',
          name: 'Fédération musicale du Morbihan',
          logoId: null,
          principalType: 'DEPARTEMENTAL_FEDERATION',
          website: 'https://fepem56.opentalent.fr',
          latitude: '47.66520309448242',
          longitude: '-2.7524585723876953',
          streetAddress: 'Pont Tanguy',
          postalCode: '56320',
          addressCity: 'LE FAOUËT',
          country: 'France',
          practices: null,
          n1Id: '10819',
          n1Name: 'CMF Bretagne',
          n2Id: '12097',
          n3Id: null,
          n4Id: null,
          n5Id: null,
          parents: '10819,12097'
        },
        {
          id: '37353',
          name: 'CMF Centre Val de Loire',
          logoId: '36480',
          principalType: 'REGIONAL_FEDERATION',
          website: 'https://cmfcentrevaldeloire.opentalent.fr',
          latitude: '47.7174905',
          longitude: '1.9435408',
          streetAddress: '9 Rue Aristide Briand',
          postalCode: '45240',
          addressCity: 'LA FERTE ST AUBIN',
          country: 'France',
          practices: null,
          n1Id: '12097',
          n1Name: 'CONFÉDÉRATION MUSICALE DE FRANCE',
          n2Id: null,
          n3Id: null,
          n4Id: null,
          n5Id: null,
          parents: '12097'
        }],
      page: 1,
      itemsPerPage: 8,
      mapview: true,
      departments,
      practices,
      textFilter: '',
      locationFilter: null,
      typeFilter: null,
      departmentFilter: null,
      federationFilter: null,
      distanceFilter: null,
      mapBoundsFilter: null
    }
  },
  computed: {
    filteredStructures () {
      return this.structures.filter((s) => { return this.matchFilters(s) })
    },
    totalRecords () {
      return this.filteredStructures.length
    },
    pageCount () {
      return Math.floor(this.totalRecords / this.itemsPerPage) + 1
    },
    listview () {
      return !this.mapview
    },
    translatedPractices () {
      const tPractices = []
      for (const practice of this.practices) {
        tPractices.push({ id: practice.id, label: this.$t(practice.id) })
      }
      return tPractices
    },
    federations () {
      const federations = []
      for (const s of this.structures) {
        const f = { id: s.n1Id, name: s.n1Name }
        if (!federations.includes(f)) {
          federations.push(f)
        }
      }
      return federations
    }
  },
  methods: {
    viewChanged (e) {
      this.mapview = (e === 0)
    },
    textFilterChanged (newVal) {
      this.textFilter = newVal
      this.filtersUpdated()
    },
    locationFilterChanged (newVal) {
      this.locationFilter = newVal
      if (this.distanceFilter === null) {
        this.distanceFilter = 10
      }
      this.filtersUpdated()
    },
    filtersUpdated () {
      this.fitMapToResults()
    },
    fitMapToResults () {
      this.$refs.map.zoomOnResults()
    },
    mapBoundsFilterChanged (newBounds) {
      this.mapBoundsFilter = newBounds
    },
    reinitializeFilters () {
      this.textFilter = null
      this.locationFilter = null
      this.typeFilter = null
      this.departmentFilter = null
      this.federationFilter = null
      this.distanceFilter = null
      this.mapBoundsFilter = null
      this.$refs.addressSearch.clear()
      this.$refs.map.resetBounds()
    },
    toRad (val) {
      // Converts numeric degrees to radians
      return val * Math.PI / 180
    },
    sphericDistance (lat1, lon1, lat2, lon2) {
      // This function takes in latitude and longitude of two location and returns the distance between them as the crow flies (in km)
      const R = 6371 // km
      const dLat = this.toRad(lat2 - lat1)
      const dLon = this.toRad(lon2 - lon1)
      lat1 = this.toRad(lat1)
      lat2 = this.toRad(lat2)

      const a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
        Math.sin(dLon / 2) * Math.sin(dLon / 2) * Math.cos(lat1) * Math.cos(lat2)
      const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a))
      return R * c
    },
    matchFilters (structure) {
      // Filter by name
      if (this.textFilter && !structure.name.toLowerCase().includes(this.textFilter.toLowerCase())) {
        return false
      }

      // filter by geographical position
      if (this.locationFilter) {
        if (!structure.latitude || !structure.longitude) {
          return false
        }

        let radius = Number(this.distanceFilter) ?? 0

        // radius is always increased by 10km to approximate the city radius
        radius += 10

        if (this.sphericDistance(
          this.locationFilter.latitude,
          this.locationFilter.longitude,
          Number.parseFloat(structure.latitude),
          Number.parseFloat(structure.longitude)) > radius
        ) {
          return false
        }
      }

      // filter by practice
      if (this.typeFilter && (!structure.practices || !structure.practices.split(',').includes(this.typeFilter))) {
        return false
      }

      // filter by department
      if (this.departmentFilter && !structure.postalCode.startsWith(this.departmentFilter)) {
        return false
      }

      // filter by federation
      if (this.federationFilter && !structure.parents.includes(Number(this.federationFilter))) {
        return false
      }

      // filter by map bounds
      if (this.mapBoundsFilter !== null) {
        if (structure.longitude < this.mapBoundsFilter.getSouthWest().lng ||
          structure.latitude < this.mapBoundsFilter.getSouthWest().lat ||
          structure.longitude > this.mapBoundsFilter.getNorthEast().lng ||
          structure.latitude > this.mapBoundsFilter.getNorthEast().lat
        ) {
          return false
        }
      }
      return true
    }
  }
}
</script>

<style scoped lang="scss">
  @import 'assets/style/variables.scss';

  h2 {
    color: $theme;
  }

  .structure-card {
    height: 100%;
  }

  .infos .col {
    padding: 6px 12px;
  }

  .title {
    word-break: normal;
    color: $theme;
    font-size: 18px;
    font-weight: 500;
    line-height: 1.6rem;
  }

  .icon {
    color: $theme;
  }

  .results-count {
    font-size: .8em;
    color: #666;
  }
</style>
