import type { PropType} from 'vue';
import { defineComponent, onMounted, ref, watch } from 'vue'
import { useUserStore } from '@store/UserStore'
import type { ICircuit, IMovQuery, IUserFields} from 'model';
import { IImgGallery, IUserProfile } from 'model'
import { costanti } from '@costanti'
import { shared_consts } from '@src/common/shared_vuejs'
import { tools } from '@tools'
import { useQuasar } from 'quasar'
import { CSendCoins } from '@src/components/CSendCoins'
import { CSaldo } from '@src/components/CSaldo'
import { CUserInfoAccount } from '@src/components/CUserInfoAccount'
import { useI18n } from 'vue-i18n'
import { useRoute, useRouter } from 'vue-router'
import { useCircuitStore } from '@store/CircuitStore'

export default defineComponent({
  name: 'CMyImgUser',
  components: { CSendCoins, CSaldo, CUserInfoAccount },
  emits: ['setCmd', 'showInnerDialog'],
  props: {
    mycontact: {
      type: Object as PropType<IUserFields | null>,
      required: false,
      default: null,
    },
    mov: {
      type: Object as PropType<IMovQuery | null>,
      required: false,
      default: null,
    },
    from: {
      type: Boolean,
      required: false,
      default: false,
    },
    myusername: {
      type: String,
      required: false,
      default: null,
    },
    groupname: {
      type: String,
      required: false,
      default: '',
    },
  },

  setup(props, { emit }) {

    const userStore = useUserStore()
    const $q = useQuasar()
    const { t } = useI18n()
    const $router = useRouter()
    const $route = useRoute()

    const showsendCoinTo = ref(false)

    const showAccountInfo = ref(false)

    const contact = ref(<IUserFields | null>null)
    const circuit = ref(<ICircuit | null | undefined>null)

    watch(() => props.mycontact, (newval, oldval) => {
      mounted()
    })

    function mounted() {
      if (props.mycontact) {
        contact.value = props.mycontact
      }
    }

    function getImgUser(profile: IUserFields) {
      return userStore.getImgByProfile(profile)
    }

    function getImgUserMov(tipoconto: number, from: boolean) {
      return userStore.getImgByMov(props.mov!, tipoconto, from, true)
    }

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

    onMounted(mounted)

    return {
      contact,
      costanti,
      getImgUser,
      getImgUserMov,
      naviga,
      shared_consts,
      userStore,
      tools,
      circuit,
      showAccountInfo,
      showsendCoinTo,
    }
  },
})
