import { CMyCircuits } from '@/components/CMyCircuits'
import { CFinder } from '@/components/CFinder'
import { CGridTableRec } from '@/components/CGridTableRec'
import { CNotifAtTop } from '@/components/CNotifAtTop'
import { tools } from '@store/Modules/tools'
import { toolsext } from '@store/Modules/toolsext'
import { computed, defineComponent, onMounted, ref, watch } from 'vue'
import { useUserStore } from '@store/UserStore'
import { useRoute, useRouter } from 'vue-router'
import { useGlobalStore } from '@store/globalStore'
import { useI18n } from '@/boot/i18n'
import { colmyUserCircuit } from '@store/Modules/fieldsTable'
import { costanti } from '@costanti'
import { shared_consts } from '@/common/shared_vuejs'

export default defineComponent({
  name: 'mycircuits',
  components: { CMyCircuits, CGridTableRec, CFinder, CNotifAtTop },
  props: {},
  setup() {
    const userStore = useUserStore()
    const globalStore = useGlobalStore()
    const { t } = useI18n()

    const filter = ref(costanti.MY_CIRCUITS)

    const isfinishLoading = computed(() => globalStore.finishLoading)

    function mounted() {

      if (userStore.my.profile.mycircuits.length <= 0) {
        filter.value = costanti.FIND_CIRCUIT
      }
      // const filt_loaded = tools.getCookie(tools.COOK_SEARCH + tools.CIRCUIT_SEARCH, costanti.FIND_CIRCUIT, true)
      // console.log('filt_loaded', filt_loaded)
      // filter.value = filt_loaded ? filt_loaded : costanti.FIND_CIRCUIT
    }

    watch(() => filter.value, (newval: any, oldval) => {
      tools.setCookie(tools.COOK_SEARCH + tools.CIRCUIT_SEARCH, newval)

    })
    onMounted(mounted)

    return {
      filter,
      costanti,
      shared_consts,
      colmyUserCircuit,
      toolsext,
      isfinishLoading,
      tools,
    }
  }
})
