// resources/js/plugins/primevue.js
import PrimeVue from 'primevue/config'
import ToastService from 'primevue/toastservice'
import Tooltip from 'primevue/tooltip'

import Button from 'primevue/button'
import Column from 'primevue/column'
import ConfirmationService from 'primevue/confirmationservice'
import ConfirmDialog from 'primevue/confirmdialog'
import DataTable from 'primevue/datatable'
import Dialog from 'primevue/dialog'
import InputText from 'primevue/inputtext'
import Paginator from 'primevue/paginator'
import Skeleton from 'primevue/skeleton'
import Toast from 'primevue/toast'

import Aura from '@primeuix/themes/aura'
import 'primeicons/primeicons.css'
import ToggleSwitch from 'primevue/toggleswitch'
// Prevent multiple registrations of PrimeVue plugin
let isPrimeVueRegistered = false

export default function registerPrimeVue(app) {
  if (isPrimeVueRegistered) return
  isPrimeVueRegistered = true
  app.use(PrimeVue, {
    theme: {
      preset: Aura,
      options: {
        // Match Vuetify theme (not OS prefers-color-scheme) so tables stay light in light mode
        darkModeSelector: '.v-theme--dark',
      },
    },
  });
  app.use(ToastService)
  app.use(ConfirmationService)

  app.directive('tooltip', Tooltip)

  app.component('Toast', Toast)
  app.component('Button', Button)
  app.component('InputText', InputText)
  app.component('DataTable', DataTable)
  app.component('Column', Column)
  app.component('Dialog', Dialog)
  app.component('Skeleton', Skeleton)
  app.component('Paginator', Paginator)
  app.component('ConfirmDialog', ConfirmDialog)
  app.component('ToggleSwitch', ToggleSwitch)
}
