<template>
  <va-card>
    <va-card-content>
      <va-button @click="showModal">FILE</va-button>
      <p>X: {{ channelStore.xAxisSelected.name }} Y: {{ channelStore.yAxisSelected.name }}</p>
      <va-list class="py-2" fit>
        <va-list-label> </va-list-label>
        <template v-for="(file, i) in selectedFiles" :key="'item' + file.id">
          <va-list-item>
            <va-list-item-section>
              <va-list-item-label>
                {{ file.name }}
              </va-list-item-label>
            </va-list-item-section>
          </va-list-item>

          <va-list-separator v-if="i < selectedFiles.length - 1" :key="'separator' + i" class="my-1" fit />
        </template>
      </va-list>
      <Suspense>
        <FileView ref="file_modal_ref"></FileView>
      </Suspense>
    </va-card-content>
  </va-card>
</template>

<script setup lang="ts">
  import { ref, reactive } from 'vue'
  import { useChannelStore } from '@/stores/data-analysis/channel'
  import { useFileViewStore } from '@/stores/data-analysis/file-view'
  import FileView from './FileView.vue'

  const channelStore = useChannelStore()
  const fileViewStore = useFileViewStore()
  const selectedFiles = reactive(fileViewStore.filesSelected)

  /* File Modal Handling */
  let file_modal_ref = ref<InstanceType<typeof FileView> | null>(null)
  const showModal = function () {
    file_modal_ref.value?.showModal()
  }

  defineExpose({ file_modal_ref, showModal })
</script>
