import { defineComponent, onMounted, ref, computed, watch } from 'vue'
import { tools } from '@store/Modules/tools'
import { useUserStore } from '@store/UserStore'
import { useI18n } from 'vue-i18n'
import { toolsext } from '@store/Modules/toolsext'
import { costanti } from '@costanti'

import { shared_consts } from '@src/common/shared_vuejs'

export default defineComponent({
  name: 'CMyDialog',
  emits: ['update:modelValue'],
  props: {
    modelValue: {
      type: Boolean,
      required: true,
    },
    title: {
      type: String,
      required: false,
      default: '',
    },
    class: {
      type: String,
      required: false,
      default: '',
    },
  },
  setup(props, { emit }) {
    const userStore = useUserStore()
    const { t } = useI18n();

    const internalModel = ref(props.modelValue)

    watch(
      () => props.modelValue,
      (newVal) => {
        internalModel.value = newVal
      }
    )

    watch(internalModel, (newVal) => {
      emit('update:modelValue', newVal)
    })

    function mounted() {

      // ...
    }


    onMounted(mounted)

    return {
      userStore,
      costanti,
      tools,
      toolsext,
      shared_consts,
      t,
      internalModel,
    }
  }
})
