import type { PropType } from 'vue';
import { defineComponent, onMounted, ref, watch } from 'vue'
import { useCircuitStore } from '@store/CircuitStore'
import { useGlobalStore } from '@store/globalStore'
import { useUserStore } from '@store/UserStore'
import { IImgGallery, IUserFields, IUserProfile } from 'model'
import { costanti } from '@costanti'
import { shared_consts } from '@src/common/shared_vuejs'
import { fieldsTable } from '@store/Modules/fieldsTable'
import { tools } from '@tools'
import { toolsext } from '@store/Modules/toolsext'
import { useQuasar } from 'quasar'
import { useI18n } from 'vue-i18n'
import { CMyCardPopup } from '@src/components/CMyCardPopup'
import { CCurrencyValue } from '@src/components/CCurrencyValue'
import { useRouter } from 'vue-router'
// import { useRouter } from 'vue-router'

export default defineComponent({
  name: 'CMyRecCircuitCard',
  components: { CMyCardPopup, CCurrencyValue },
  emits: ['setCmd', 'cmdext'],
  props: {
    table: {
      type: String,
      required: true,
    },
    prop_myrec: {
      type: Object as PropType<any>,
      required: false,
      default: null,
    },
  },

  setup(props, { emit }) {

    const userStore = useUserStore()
    const circuitStore = useCircuitStore()
    const globalStore = useGlobalStore()
    // const $q = useQuasar()
    const { t } = useI18n()
    // const $router = useRouter()

    const circuit = ref(<any>null)

    const showingtooltip = ref(false)

    const $router = useRouter()

    watch(() => props.prop_myrec, (newval, oldval) => {

      mounted()
    })

    function mounted() {
      if (props.prop_myrec) {
        circuit.value = props.prop_myrec
      }
    }

    function setCmd($q: any, cmd: number, myusername: string, value: any, groupname: string) {
      emit('setCmd', $q, cmd, myusername, value, groupname)
    }

    function cmdExt(cmd: any, val1: any, val2: any) {
      emit('cmdext', cmd, val1, val2)
    }

    function naviga(path: string) {
      $router.push(path)
    }

    onMounted(mounted)

    return {
      t,
      circuit,
      costanti,
      naviga,
      setCmd,
      shared_consts,
      userStore,
      tools,
      toolsext,
      fieldsTable,
      cmdExt,
      globalStore,
      circuitStore,
      showingtooltip,
    }
  },
})
