import type {
  PropType} from 'vue';
import {
  computed,
  defineComponent, onBeforeMount, onBeforeUnmount, onMounted, ref, toRef, toRefs, watch,
} from 'vue'

import { tools } from '@tools'
import type { IOptQueryGM } from '@src/model';
import { IOptCatalogo, IMyScheda, IProduct, ISchedaSingola, IText } from '@src/model'

import { useProducts } from '@store/Products'
import { useGlobalStore } from '@src/store/globalStore'

import { costanti } from '@costanti'

export default defineComponent({
  name: 'CViewTable',
  props: {
    options: {
      type: Object as PropType<IOptQueryGM>,
      required: true,
    },
  },

  setup(props, { attrs, slots, emit }) {

    const globalStore = useGlobalStore()

    const risultatoHTML = ref('')
    const tabella = ref('')

    const loading = ref(false)

    async function mounted() {
      if (props.options) {
        loading.value = true
        await getTabellaDaGM()
        loading.value = false
      }
    }

    async function getTabellaDaGM() {
      tabella.value = props.options.nameTable
      risultatoHTML.value = ''
      risultatoHTML.value = await globalStore.getGM_Tabella(props.options)
    }


    onMounted(mounted)
    return {
      tools,
      globalStore,
      costanti,
      getTabellaDaGM,
      risultatoHTML,
      tabella,
      loading,
    }
  },
})
