<script>
import { createAccountsStore, createContactsStore } from '@pitcher/core'
import { defineComponent } from '@vue/composition-api'

export default defineComponent({
  name: 'PAccountsContactsProvider',
  props: {
    // eslint-disable-next-line vue/no-unused-properties
    selectColumns: { type: Array, required: true },
    // eslint-disable-next-line vue/no-unused-properties
    searchFields: { type: Array, required: true },
    // eslint-disable-next-line vue/no-unused-properties
    defaultSortBy: { type: String, required: true },
    // eslint-disable-next-line vue/no-unused-properties
    defaultItemsPerPage: { type: Number, default: 50 },
    type: {
      type: String,
      required: true,
      validator: (v) => {
        if (!['account', 'contact'].includes(v)) {
          console.error(`[Vue warn]: Validation error PAccountContactsTable!`)
          console.error(`[Vue warn]: accepted type values: contact | account`)

          return false
        }

        return true
      },
    },
    // eslint-disable-next-line vue/no-unused-properties
    accountId: {
      type: String,
      required: false,
    },
  },
  setup(props) {
    props.type === 'contact' ? createContactsStore(props) : createAccountsStore(props)
    // watch(
    //   () => props,
    //   () => {
    //     props.type === 'contact' ? createAccountsStore(props) : createContactsStore(props)
    //   },
    //   { deep: true, immediate: true }
    // )
  },
  render() {
    return this.$slots.default
  },
})
</script>
