import { boot } from 'quasar/wrappers';
import { setQuasarInstance } from 'src/utils/globalQ';
import { setRouterInstance } from 'src/utils/globalRouter';
import { databaseName } from 'src/vueLib/tables/members/MembersTable';
import { Logo } from 'src/vueLib/models/logo';

export default boot(({ app, router }) => {
  setRouterInstance(router); // store router for global access
  const $q = app.config.globalProperties.$q;
  setQuasarInstance($q);

  Logo.value = localStorage.getItem('icon') ?? Logo.value;
  databaseName.value = localStorage.getItem('databaseName') ?? databaseName.value;
  let primaryColor = localStorage.getItem('primaryColor');
  if (primaryColor == null || primaryColor === 'undefined' || primaryColor.trim() === '') {
    primaryColor = null;
  }
  let secondaryColor = localStorage.getItem('secondaryColor');
  if (secondaryColor == null || secondaryColor === 'undefined' || secondaryColor.trim() === '') {
    secondaryColor = null;
  }

  document.documentElement.style.setProperty('--q-primary', primaryColor ?? '#1976d2');
  document.documentElement.style.setProperty('--q-secondary', secondaryColor ?? '#26a69a');
});
