import { defineComponent, onMounted, PropType, ref, watch } from 'vue'
import { tools } from '@src/store/Modules/tools'

import { date, useQuasar } from 'quasar'
import { useI18n } from 'vue-i18n'
import { CCurrencyValue } from '@src/components/CCurrencyValue'
import { CMyFieldDb } from '@src/components/CMyFieldDb'


import { costanti } from '@costanti'

export default defineComponent({
  name: 'CCurrencyV2',
  components: { CCurrencyValue, CMyFieldDb },
  emits: ['save'],
  props: {
    small: {
      type: Boolean,
      default: false,
    },
    label: {
      type: String,
      required: false,
      default: '',
    },
    tips: {
      type: String,
      required: false,
      default: '',
    },
    readonly: {
      type: Boolean,
      required: false,
      default: false,
    },
    symbol: {
      type: String,
      required: true,
    },
    color: {
      type: String,
      required: false,
      default: '',
    },
    color_border: {
      type: String,
      required: false,
      default: '',
    },
    icon: {
      type: String,
      required: false,
      default: '',
    },
    modelValue: {
      type: [String, Number],
      required: true,
      default: '',
    },
    valueextra: {
      type: String,
      required: false,
      default: '',
    },
    paramTypeAccount: {
      type: Number,
      required: false,
      default: 0,
    },
    myrecparam: {
      type: Object,
      required: false,
      default: null,
    },
    admin: {
      type: Boolean,
      required: false,
      default: false,
    },
  },
  setup(props, { emit }) {
    const $q = useQuasar()
    const { t } = useI18n()

    const changeParamValue = ref(false)

    const showingtooltip = ref(false)

    const myvalue = ref(<any>null)

    function created() {
      // created
      myvalue.value = props.modelValue
    }

    function changedParamValue(value: boolean) {
      changeParamValue.value = value
    }

    function save(value: any) {

      // ricarico
      emit('save', value)

      myvalue.value = value

    }

    onMounted(created)

    return {
      showingtooltip,
      t,
      tools,
      changeParamValue,
      changedParamValue,
      costanti,
      save,
      myvalue,
    }
  },
})
