import {
  defineComponent, onBeforeMount, onBeforeUnmount, onMounted, ref, toRef, toRefs, watch, computed,
} from 'vue'

import { tools } from '@tools'
import { CMyFieldDb } from '@src/components/CMyFieldDb'
import { costanti } from '@costanti'
import { useGlobalStore } from '@store/globalStore'
import { useUserStore } from '@store/UserStore'
import { CGridTableRec } from '@src/components/CGridTableRec'
import type { IColGridTable} from 'model';
import { IMySkill, ISkill } from 'model'
import { toolsext } from '@store/Modules/toolsext'
import { fieldsTable } from '@store/Modules/fieldsTable'
import { shared_consts } from '@src/common/shared_vuejs'

export default defineComponent({
  name: 'CSkill',
  props: {
    table: {
      type: String,
      required: true,
    },
    title: {
      type: String,
      required: false,
      default: '',
    },
    defaultnewrec: {
      type: Function,
      required: false,
    },
    filtercustom: {
      type: Array,
      required: false,
      default: () => {
        return []
      }
    },
    visuinpage: {
      type: Boolean,
      required: false,
      default: false,
    },
    noaut: {
      type: Boolean,
      required: false,
      default: false,
    },
    username: {
      type: String,
      required: false,
      default: ''
    },
    groupname: {
      type: String,
      required: false,
      default: ''
    }
  },
  components: {
    CMyFieldDb, CGridTableRec,
  },
  setup(props, { attrs, slots, emit }) {
    const globalStore = useGlobalStore()
    const userStore = useUserStore()

    const table = ref(shared_consts.TABLES_MYSKILLS)

    const col = ref(<IColGridTable>{})

    const prop_colkey = ref('')
    const col_title = ref('')
    const col_footer = ref('')
    const col_tabfooter = ref('')

    function mounted() {

      let obj = tools.getParamsByTable(props.table)

      col.value = fieldsTable.getArrColsByTable(props.table)

      prop_colkey.value = obj.prop_colkey
      col_title.value = obj.col_title
      col_footer.value = obj.col_footer
      col_tabfooter.value = obj.col_tabfooter

    }

    onMounted(mounted)

    return {
      tools,
      costanti,
      fieldsTable,
      col,
      prop_colkey,
      col_title,
      col_footer,
      col_tabfooter,
    }
  },
})
