<script>
import {computed} from 'vue'
import {mapGetters, mapMutations, mapActions, useStore} from "vuex";
import {useRoute} from 'vue-router'
import Datepicker from "@molecules/VDatepicker/VDatepicker.vue"
import Spinner from "@molecules/VSpinner/VSpinner.vue"
import Tabulator from "@molecules/VTabulator/VTabulator.vue"
import PackChart from './Chart/Chart.vue'
import VueMultiselect from 'vue-multiselect'
import moment from 'moment'

export default {
  name: 'PacksPage',
  components: {
    Datepicker,
    VueMultiselect,
    Tabulator,
    PackChart,
    Spinner
  },
  provide() {
    return {
      defaultDate: computed(() => this.setPickerFormat(this.packsSettings.dates.selectedDate)),
    }
  },
  setup() {
    const store = useStore()
    const route = useRoute()
    const path = computed(() => route.path)
    const query = computed(() => route.query)
    
    console.log('path', path)
    console.log('query', query)
    store.commit('packs/setIsLoading', true)
    store.dispatch('packs/uploadData', {path: path.value, query: query.value})

  },
  data() {
    return {
      columnSelector: false,
      displayView: 'table',
    }
  },
  computed: {
    ...mapGetters('packs', ['selectedPacksGroup', 'selectedPack', 'tableData', 'packsSettings', 'columnsSelect', 'selectedColumnsSelect', 'isLoading']),
    curerentTableData () {
      const pagination = {...this.packsSettings.pagination, updatePagination: this.updatePagination}
      return {
        ...this.tableData, pagination 
      }
    },
  },
  unmounted() {
    const store = useStore()
    store.dispatch('packs/resetStore')
  },
  methods: {
    ...mapActions('packs', ['uploadData', 'updatePagination', 'updatePackSettings', 'updateSelects']),
    ...mapMutations('packs', ['setSelectedPack']),
    updateSelectedPack:  function(value) {
      this.setSelectedPack(value)
    },
    setPackSettings: function(value, key) {
      console.log('value', value)
      console.log('key', key)
      switch (key) {
      case 'date':
        this.updatePackSettings({dates: {...this.packsSettings.dates, selectedDate: value}})
        break
      case 'imei':
        this.updatePackSettings({imei: value})
        break
      case 'selectedPack':
        this.updatePackSettings({selectedPack: value})
        break
      }
    },
    setDate: function(value) {
      console.log('value', value)
      this.updatePackSettings({dates: {...this.packsSettings.dates, selectedDate: value}})
    },
    setImei: function(e) {
      console.log('value', e.target.value)
      this.updatePackSettings({imei: e.target.value})
    },
    setPack: function(value) {
      console.log('value', value)
      this.updatePackSettings({selectedPack: value})
    },
    fetchPack: function(params) {
      console.log('params', params)
      if (params.imei && params.dates.selectedDate && params.selectedPack) {
        const path = this.$route.path
        const query = this.$route.query
        const dateUrl = moment(params.dates.selectedDate).format('YYYY-MM-DD')
        console.log('params.selectedPack', params.selectedPack)
        const queryUrl = {...query, date: dateUrl, imei: params.imei, pack: params.selectedPack.name} 
        this.$router.push({ path: path, query: queryUrl})
        const currentQuery = {...queryUrl, date: params.dates.selectedDate}
        this.uploadData({path: path, query: currentQuery})
      }
    },
    setPickerFormat: (date) => {
      console.log('moment(date)', moment(date).format('DD.MM.YYYY'))
      if (!date) return null
      return moment(date).format('DD.MM.YYYY')
    },
    setOpenColumnSelect: function() {
      return this.columnSelector = !this.columnSelector
    },
    toggleDisplayView: function() {
      this.displayView = this.displayView === 'chart' ? 'table' : 'chart'
    },
    addedOption: function(value) {
      console.log('value', value)
      this.updateSelects({key: 'added', select: value})
    },
    removedOption: function(value) {
      this.updateSelects({key: 'removed', select: value})
    },
    
  }
}

</script>


<template>
  <div class="grid grid-cols-12 gap-6 col-span-12 h-full">
    {{ 
      // console.log('tableData', tableData)
      console.log('packsSettings', packsSettings)
    }}
    <div class="rounded-md bg-light px-4 pt-4 pb-6 gap-2 shadow lg:col-span-4 xl:col-span-3 2xl:col-span-2 col-span-12">
      <h1 class="font-medium leading-tight text-xl mb-4 text-slate-600">
        Первый пакет
      </h1>
      <div class="grid gap-3 mb-3 ">
        <div class="grid grid-cols-1">
          <label
            for="date"
            class="block mb-2 text-sm font-medium text-gray-900 dark:text-gray-300"
          >
            Дата
          </label>
          <Datepicker
            id="date"
            :onchange="setDate"
          />
        </div>
        <div phx-feedback-for="imei">
          <label
            for="selectedImei"
            class="block text-sm leading-6 text-zinc-800 dark:text-white"
          >
            imei
          </label>
          <input
            id="selectedImei"
            type="text"
            name="imei"
            :value="packsSettings.imei"
            class="block w-full rounded-lg border-zinc-300 py-[1px] px-[11px] text-zinc-900 focus:outline-none focus:ring-4 text-sm sm:leading-6 phx-no-feedback:border-zinc-300 phx-no-feedback:focus:border-zinc-400 phx-no-feedback:focus:ring-zinc-800/5 border-zinc-300 focus:border-zinc-400 focus:ring-zinc-800/5 "
            placeholder="imei"
            required=""
            @change="setImei"
          >
        </div>
        <div>
          <label
            for="selectedPack"
            class="block mb-2 text-sm font-medium text-gray-900 dark:text-gray-400"
          >Выбрать пакет</label>
          <div
            id="selected_settings_name_wrapper"
            class="w-full"
          >
            <div
              id="packsOptions"
              class="col-span-12 sm:col-span-6 lg:col-span-3 rounded-lg"
            >
              <VueMultiselect
                v-model="packsSettings.selectedPack"
                name="selectedPack"
                label="name"
                track-by="name"
                :options="packsSettings.selectedPackGroup"
                :placeholder="packsSettings.selectedPack?.name"
                :showLabels="false"
                @update:model-value="setPack"
              />
            </div>
          </div>
        </div>
      </div>
      <div class="grid gap-3 grid-cols-4">
        <input
          type="submit"
          class="col-span-4 lg:col-span-4 cursor-pointer text-white bg-primary hover:brightness-90 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-ssm w-full sm:w-auto px-5 py-1 text-center  dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800 transition_up"
          value="Выгрузить"
          @click="fetchPack(packsSettings)"
        >
        <div
          phx-click="load_pack_settings"
          class="cursor-pointer col-span-4 xl:col-span-4 bg-transparent hover:bg-primary text-primary font-semibold hover:text-white py-1 text-ssm px-4 border border-primary hover:border-transparent rounded-lg text-center transition_up"
        >
          Настройки
        </div>
        <div
          class="cursor-pointer col-span-4 lg:col-span-4 bg-transparent hover:bg-primary text-primary font-semibold hover:text-white py-1 text-ssm px-4 border border-primary hover:border-transparent rounded-lg text-center transition_up"
          phx-click="[[&quot;show&quot;,{&quot;display&quot;:null,&quot;time&quot;:200,&quot;to&quot;:&quot;#select_machines_modal&quot;,&quot;transition&quot;:[[],[],[]]}],[&quot;show&quot;,{&quot;display&quot;:null,&quot;time&quot;:200,&quot;to&quot;:&quot;#machines_modal_loader&quot;,&quot;transition&quot;:[[],[],[]]}],[&quot;push&quot;,{&quot;event&quot;:&quot;load_machines_table&quot;,&quot;value&quot;:{&quot;mode&quot;:&quot;page&quot;}}]]"
        >
          Выбрать машину
        </div>
        <div
          id="question"
          class="cursor-pointer col-span-4 xl:col-span-4 bg-transparent hover:bg-primary text-primary font-semibold hover:text-white py-1 text-ssm px-4 border border-primary hover:border-transparent rounded-lg text-center transition_up"
          phx-hook="InfoModal"
        >
          <i class="ri-question-mark" />
        </div>
      </div>
    </div>
    <div
      id="packageDisplay"
      class="relative lg:col-span-8 xl:col-span-9 2xl:col-span-10 col-span-12 bg-light shadow"
    >
      <div
        v-if="!isLoading && curerentTableData.dataSource"
        id="tableButtons"
        class="w-full"
      >
        <div class="w-full flex justify-end">
          <div class="flex gap-3 pt-4 pb-2 pr-4">
            <div class="">
              <button
                type="button"
                class="flex items-center transition-all justify-center py-2 px-3 bg-light text-sm font-medium text-slate-700 focus:outline-none rounded-lg border border-dashed border-slate-400 hover:text-blue-800 hover:border-blue-900 hover:shadow focus:z-10 focus:ring-4 focus:ring-gray-200 dark:focus:ring-gray-700 dark:bg-gray-800 dark:text-gray-400 dark:border-gray-600 dark:hover:text-white dark:hover:bg-gray-700"
                @click="setOpenColumnSelect"
              >
                <i class="ri-settings-3-line" />
              </button>
            </div>
            <div
              id="graphic_btn_inactive"
              class=""
            >
              <button
                type="button"
                class="flex items-center transition-all justify-center py-2 px-3 bg-light text-sm font-medium text-slate-700 focus:outline-none rounded-lg border border-dashed border-slate-400 hover:text-blue-800 hover:border-blue-900 hover:shadow focus:z-10 focus:ring-4 focus:ring-gray-200 dark:focus:ring-gray-700 dark:bg-gray-800 dark:text-gray-400 dark:border-gray-600 dark:hover:text-white dark:hover:bg-gray-700"
                phx-click="[[&quot;toggle&quot;,{&quot;display&quot;:null,&quot;ins&quot;:[[],[],[]],&quot;outs&quot;:[[],[],[]],&quot;time&quot;:200,&quot;to&quot;:&quot;#graphic_btn_inactive&quot;}],[&quot;toggle&quot;,{&quot;display&quot;:null,&quot;ins&quot;:[[],[],[]],&quot;outs&quot;:[[],[],[]],&quot;time&quot;:200,&quot;to&quot;:&quot;#graphic_btn_active&quot;}],[&quot;toggle&quot;,{&quot;display&quot;:null,&quot;ins&quot;:[[],[],[]],&quot;outs&quot;:[[],[],[]],&quot;time&quot;:200,&quot;to&quot;:&quot;#pack_table_warapper&quot;}],[&quot;toggle&quot;,{&quot;display&quot;:null,&quot;ins&quot;:[[],[],[]],&quot;outs&quot;:[[],[],[]],&quot;time&quot;:200,&quot;to&quot;:&quot;#pack_graphic_wrapper&quot;}],[&quot;push&quot;,{&quot;event&quot;:&quot;toggle_display_data&quot;}]]"
                @click="toggleDisplayView"
              >
                <i class="ri-bar-chart-grouped-line" />
              </button>
            </div>
            <div
              id="graphic_btn_active"
              class="hidden"
            >
              <button
                type="button"
                class="flex items-center transition-all justify-center py-2 px-3 bg-blue-200 text-sm font-medium text-blue-700 focus:outline-none rounded-lg border border-dashed border-blue-500 hover:text-blue-800 hover:border-blue-900 hover:shadow focus:z-10 focus:ring-4 focus:ring-gray-200 dark:focus:ring-gray-700 dark:bg-gray-800 dark:text-gray-400 dark:border-gray-600 dark:hover:text-white dark:hover:bg-gray-700"
                phx-click="[[&quot;toggle&quot;,{&quot;display&quot;:null,&quot;ins&quot;:[[],[],[]],&quot;outs&quot;:[[],[],[]],&quot;time&quot;:200,&quot;to&quot;:&quot;#graphic_btn_inactive&quot;}],[&quot;toggle&quot;,{&quot;display&quot;:null,&quot;ins&quot;:[[],[],[]],&quot;outs&quot;:[[],[],[]],&quot;time&quot;:200,&quot;to&quot;:&quot;#graphic_btn_active&quot;}],[&quot;toggle&quot;,{&quot;display&quot;:null,&quot;ins&quot;:[[],[],[]],&quot;outs&quot;:[[],[],[]],&quot;time&quot;:200,&quot;to&quot;:&quot;#pack_table_warapper&quot;}],[&quot;toggle&quot;,{&quot;display&quot;:null,&quot;ins&quot;:[[],[],[]],&quot;outs&quot;:[[],[],[]],&quot;time&quot;:200,&quot;to&quot;:&quot;#pack_graphic_wrapper&quot;}],[&quot;push&quot;,{&quot;event&quot;:&quot;toggle_display_data&quot;}]]"
              >
                <i class="ri-bar-chart-grouped-line" />
              </button>
            </div>
            <div
              id="excel_btn"
              phx-click="download_csv"
              style=""
              class="flex items-center justify-center transition-all justify-center py-2 px-3 bg-light text-sm font-medium text-slate-700 focus:outline-none rounded-lg border border-dashed border-slate-400 hover:text-blue-800 hover:border-blue-900 hover:shadow focus:z-10 focus:ring-4 focus:ring-gray-200 dark:focus:ring-gray-700 dark:bg-gray-800 dark:text-gray-400 dark:border-gray-600 dark:hover:text-white dark:hover:bg-gray-700 cursor-pointer"
            >
              <i class="ri-file-excel-line" />
            </div>
            <div
              id="excel_loader"
              style="display: none"
              class="flex items-center justify-center transition-all justify-center py-2 px-3 bg-light text-sm font-medium text-slate-700 focus:outline-none rounded-lg border border-dashed border-slate-400 hover:text-blue-800 hover:border-blue-900 hover:shadow focus:z-10 focus:ring-4 focus:ring-gray-200 dark:focus:ring-gray-700 dark:bg-gray-800 dark:text-gray-400 dark:border-gray-600 dark:hover:text-white dark:hover:bg-gray-700 "
            >
              <svg
                aria-hidden="true"
                class="w-4 h-4 text-gray-300 animate-spin dark:text-gray-400 fill-slate-700"
                viewBox="0 0 100 101"
                fill="none"
                xmlns="http://www.w3.org/2000/svg"
              >
                <path
                  d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z"
                  fill="currentColor"
                />
                <path
                  d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z"
                  fill="currentFill"
                />
              </svg>
            </div>
          </div>
        </div>
      </div>
      <div
        v-if="columnSelector"
        id="colums_select_wrapper"
        class="w-full"
      >
        <VueMultiselect
          v-model="selectedColumnsSelect"
          name="selectedPack"
          label="name"
          track-by="name"
          :options="columnsSelect"
          :placeholder="null"
          :showLabels="false"
          :multiple="true"
          :group-select="true"
          @select="addedOption"
          @remove="removedOption"
        />
      </div>
      <div
        v-if="displayView === 'table'"
        id="packTableWarapper"
      >
        {{ console.log('getters.isLoading', isLoading) }}
        <div
          id="reportPacks"
          class="tab-pane active text-center min-h-[300px] rounded-md "
        >
          <Tabulator
            v-if="!isLoading && curerentTableData.dataSource"
            v-bind="curerentTableData"
          />
          <span
            v-if="!isLoading && !curerentTableData.dataSource"
            class="absolute flex w-full justify-center items-center mt-2"
          > Выберите пакет и нажмите выгрузить</span>
          <div
            v-if="isLoading && !curerentTableData.dataSource"
            id="packLoader"
            class="absolute flex w-full h-full justify-center items-center bg-slate-50"
          >
            <Spinner />
          </div>
        </div>
      </div>
      <PackChart
        :displayView="displayView"
        :curerentTableData="curerentTableData"
      />
    </div>
    <div>
      <button
        type="button"
        class="hidden"
        phx-click="[[&quot;toggle&quot;,{&quot;display&quot;:null,&quot;ins&quot;:[[],[],[]],&quot;outs&quot;:[[],[],[]],&quot;time&quot;:200,&quot;to&quot;:&quot;#period_table_modal&quot;}]]"
      />
      <div
        id="period_table_modal"
        class="fixed z-[10000] inset-0 hidden"
        phx-remove="[[&quot;transition&quot;,{&quot;time&quot;:200,&quot;to&quot;:null,&quot;transition&quot;:[[&quot;fade-out&quot;],[],[]]}]]"
      >
        <!-- VModal container -->
        <div class="h-screen flex items-center justify-center p-4">
          <!-- Overlay -->
          <div
            class="absolute z-0 inset-0 bg-gray-500 opacity-75"
            aria-hidden="true"
          />
          <!-- VModal box -->
          <div
            class="relative max-h-full overflow-y-auto bg-white rounded-lg shadow-xl "
            role="dialog"
            aria-modal="true"
            tabindex="0"
            autofocus=""
            phx-window-keydown="[[&quot;hide&quot;,{&quot;time&quot;:200,&quot;to&quot;:&quot;#period_table_modal&quot;,&quot;transition&quot;:[[&quot;ease-in&quot;,&quot;duration-200&quot;],[&quot;opacity-100&quot;],[&quot;opacity-0&quot;]]}],[&quot;dispatch&quot;,{&quot;event&quot;:&quot;click&quot;,&quot;to&quot;:&quot;#period_table_modal-return&quot;}]]"
            phx-key="escape"
          >
            <button
              type="button"
              class="absolute top-2 right-2 text-gray-400 flex space-x-1 items-center"
              aria_label="close modal"
              phx-click="[[&quot;hide&quot;,{&quot;time&quot;:200,&quot;to&quot;:&quot;#period_table_modal&quot;,&quot;transition&quot;:[[&quot;ease-in&quot;,&quot;duration-200&quot;],[&quot;opacity-100&quot;],[&quot;opacity-0&quot;]]}],[&quot;dispatch&quot;,{&quot;event&quot;:&quot;click&quot;,&quot;to&quot;:&quot;#period_table_modal-return&quot;}]]"
            >
              <span class="text-sm">(esc)</span>
              <i class="ri ri-close-line text-2xl" />
            </button>

            <div class="min-w-[350px] min-h-[400px] py">
              <div class=" p-4 font-bold" />

              <div
                id="pack-settings-editor"
                phx-hook="PackSettingsEditor"
              />
            </div>
          </div>
        </div>
      </div>
    </div>
    <div
      id="ignore:31QzedwP"
      phx-update="ignore"
    >
      <div>
        <button
          type="button"
          class="hidden"
          phx-click="[[&quot;toggle&quot;,{&quot;display&quot;:null,&quot;ins&quot;:[[],[],[]],&quot;outs&quot;:[[],[],[]],&quot;time&quot;:200,&quot;to&quot;:&quot;#select_machines_modal&quot;}]]"
        />
        <div
          id="select_machines_modal"
          class="fixed z-[10000] inset-0 hidden"
          phx-remove="[[&quot;transition&quot;,{&quot;time&quot;:200,&quot;to&quot;:null,&quot;transition&quot;:[[&quot;fade-out&quot;],[],[]]}]]"
        >
          <!-- VModal container -->
          <div class="h-screen flex items-center justify-center p-4">
            <!-- Overlay -->
            <div
              class="absolute z-0 inset-0 bg-gray-500 opacity-75"
              aria-hidden="true"
            />
            <!-- VModal box -->
            <div
              class="relative max-h-full overflow-y-auto bg-white rounded-lg shadow-xl "
              role="dialog"
              aria-modal="true"
              tabindex="0"
              autofocus=""
              phx-window-keydown="[[&quot;hide&quot;,{&quot;time&quot;:200,&quot;to&quot;:&quot;#select_machines_modal&quot;,&quot;transition&quot;:[[&quot;ease-in&quot;,&quot;duration-200&quot;],[&quot;opacity-100&quot;],[&quot;opacity-0&quot;]]}],[&quot;dispatch&quot;,{&quot;event&quot;:&quot;click&quot;,&quot;to&quot;:&quot;#select_machines_modal-return&quot;}]]"
              phx-key="escape"
            >
              <button
                type="button"
                class="absolute top-2 right-2 text-gray-400 flex space-x-1 items-center"
                aria_label="close modal"
                phx-click="[[&quot;hide&quot;,{&quot;time&quot;:200,&quot;to&quot;:&quot;#select_machines_modal&quot;,&quot;transition&quot;:[[&quot;ease-in&quot;,&quot;duration-200&quot;],[&quot;opacity-100&quot;],[&quot;opacity-0&quot;]]}],[&quot;dispatch&quot;,{&quot;event&quot;:&quot;click&quot;,&quot;to&quot;:&quot;#select_machines_modal-return&quot;}]]"
              >
                <span class="text-sm">(esc)</span>
                <i class="ri ri-close-line text-2xl" />
              </button>

              <div class="min-w-[350px] min-h-[400px] py">
                <div class=" p-4 font-bold" />

                <div class="w-[95vw] h-[95vh] flex flex-col gap-8 p-5">
                  <div id="machines_modal_loader">
                    <div
                      style=""
                      class="h-full absolute inset-0 flex flex-row items-center grow transition items-center justify-center appear_from_opacity-3 z-30 rounded p-2"
                    >
                      <div class="flex flex-row items-center grow transition items-center justify-center rounded shadow bg-white h-full">
                        <div
                          type-node="loader"
                          class="flex gap-3 items-center justify-center "
                        >
                          <span class="text-slate-600 text-md font-medium">Загрузка</span>
                          <div role="status">
                            <svg
                              aria-hidden="true"
                              class="mr-2 w-6 h-6 text-gray-300 animate-spin dark:text-gray-400 fill-slate-700"
                              viewBox="0 0 100 101"
                              fill="none"
                              xmlns="http://www.w3.org/2000/svg"
                            >
                              <path
                                d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z"
                                fill="currentColor"
                              />
                              <path
                                d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z"
                                fill="currentFill"
                              />
                            </svg>
                          </div>
                        </div>
                      </div>
                    </div>
                  </div>
                  <div
                    id="select_machines"
                    no-init="true"
                    phx-hook="MakeTabulator"
                  />
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div>
      <button
        type="button"
        class="hidden"
        phx-click="[[&quot;toggle&quot;,{&quot;display&quot;:null,&quot;ins&quot;:[[],[],[]],&quot;outs&quot;:[[],[],[]],&quot;time&quot;:200,&quot;to&quot;:&quot;#map_modal&quot;}]]"
      />
      <div
        id="map_modal"
        class="fixed z-[10000] inset-0 hidden"
        phx-remove="[[&quot;transition&quot;,{&quot;time&quot;:200,&quot;to&quot;:null,&quot;transition&quot;:[[&quot;fade-out&quot;],[],[]]}]]"
      >
        <!-- VModal container -->
        <div class="h-screen flex items-center justify-center p-4">
          <!-- Overlay -->
          <div
            class="absolute z-0 inset-0 bg-gray-500 opacity-75"
            aria-hidden="true"
          />
          <!-- VModal box -->
          <div
            class="relative max-h-full overflow-y-auto bg-white rounded-lg shadow-xl "
            role="dialog"
            aria-modal="true"
            tabindex="0"
            autofocus=""
            phx-window-keydown="[[&quot;hide&quot;,{&quot;time&quot;:200,&quot;to&quot;:&quot;#map_modal&quot;,&quot;transition&quot;:[[&quot;ease-in&quot;,&quot;duration-200&quot;],[&quot;opacity-100&quot;],[&quot;opacity-0&quot;]]}],[&quot;dispatch&quot;,{&quot;event&quot;:&quot;click&quot;,&quot;to&quot;:&quot;#map_modal-return&quot;}]]"
            phx-click-away="[[&quot;hide&quot;,{&quot;time&quot;:200,&quot;to&quot;:&quot;#map_modal&quot;,&quot;transition&quot;:[[&quot;ease-in&quot;,&quot;duration-200&quot;],[&quot;opacity-100&quot;],[&quot;opacity-0&quot;]]}],[&quot;dispatch&quot;,{&quot;event&quot;:&quot;click&quot;,&quot;to&quot;:&quot;#map_modal-return&quot;}]]"
            phx-key="escape"
          >
            <button
              type="button"
              class="absolute top-2 right-2 text-gray-400 flex space-x-1 items-center"
              aria_label="close modal"
              phx-click="[[&quot;hide&quot;,{&quot;time&quot;:200,&quot;to&quot;:&quot;#map_modal&quot;,&quot;transition&quot;:[[&quot;ease-in&quot;,&quot;duration-200&quot;],[&quot;opacity-100&quot;],[&quot;opacity-0&quot;]]}],[&quot;dispatch&quot;,{&quot;event&quot;:&quot;click&quot;,&quot;to&quot;:&quot;#map_modal-return&quot;}]]"
            >
              <span class="text-sm">(esc)</span>
              <i class="ri ri-close-line text-2xl" />
            </button>

            <div class="min-w-[350px] min-h-[400px] py">
              <div class="border-b p-4 font-bold">
                Карта
              </div>

              <div
                id="ignore:7"
                phx-update="ignore"
                class="w-[95vw] h-[85vh] m-auto relative"
              >
                <div id="map_loader">
                  <div
                    style="padding: 0"
                    class="h-full absolute inset-0 flex flex-row items-center grow transition items-center justify-center appear_from_opacity-3 z-30 rounded p-2"
                  >
                    <div class="flex flex-row items-center grow transition items-center justify-center rounded shadow bg-white h-full">
                      <div
                        type-node="loader"
                        class="flex gap-3 items-center justify-center "
                      >
                        <span class="text-slate-600 text-md font-medium">Загрузка</span>
                        <div role="status">
                          <svg
                            aria-hidden="true"
                            class="mr-2 w-6 h-6 text-gray-300 animate-spin dark:text-gray-400 fill-slate-700"
                            viewBox="0 0 100 101"
                            fill="none"
                            xmlns="http://www.w3.org/2000/svg"
                          >
                            <path
                              d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z"
                              fill="currentColor"
                            />
                            <path
                              d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z"
                              fill="currentFill"
                            />
                          </svg>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
                <div
                  id="map_show"
                  phx-hook="CoordsMap"
                  style="width: 95vw; height: 82vh;"
                />
                <div
                  id="popup"
                  class="ol-popup hidden transition-all"
                >
                  <a
                    id="popup-closer"
                    href="#"
                    class="ol-popup-closer hover:no-underline top-2 right-2 "
                  >
                    <i class="ri-close-fill" />
                  </a>
                  <div id="popup-content" />
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<style src="vue-multiselect/dist/vue-multiselect.css"></style>