import { defineComponent, ref, onMounted, computed, watch } from 'vue'

import { CImgText } from '../../../components/CImgText/index'
import { CCard } from '@/components/CCard'
import { CMyPage } from '@/components/CMyPage'
import { CTitleBanner } from '@/components/CTitleBanner'
import { CGridTableRec } from '@/components/CGridTableRec'

import { colmyelems } from '@src/store/Modules/fieldsTable'
import MixinMetaTags from '@/mixins/mixin-metatags'
import { tools } from '@store/Modules/tools'
import { shared_consts } from '@/common/shared_vuejs'
import { IMyPage } from 'model'
import { useGlobalStore } from '@store/globalStore'

export default defineComponent({
  name: 'editElems',
  setup() {

    const { setmeta } = MixinMetaTags()

    const globalStore = useGlobalStore()

    const arrPages = ref([] as any[])

    const pageSel = ref('')

    watch(() => pageSel.value, (newval: any, oldval) => {
      tools.setCookie('s_elems', newval)
    })

    const filtercustom = computed(() => [{ path: pageSel.value }] )

    function mounted() {

      arrPages.value = []
      arrPages.value.push({label: '[Vuoto]', path: ''})
      for (const page of globalStore.mypage) {

        const rec = {
          // @ts-ignore
          label: page.title,
          // @ts-ignore
          value: page.path
        }
        arrPages.value.push(rec)
      }



        // filtercustom.value = [{ userId: userStore.my._id }]
    }

    onMounted(mounted)

    pageSel.value = tools.getCookie('s_elems', '')

    return {
      colmyelems,
      setmeta,
      arrPages,
      pageSel,
      filtercustom,
    }
  },
  components: { CImgText, CCard, CMyPage, CTitleBanner, CGridTableRec }
})
