
import VBase from './vbase.js'

export default async ($mod) => {
  // Load i18n
  try {
    const langs = await (await fetch($mod.scoped + '/langs.json')).json()
    $mod.$i18n.load(langs)
  } catch (e) {
    console.error('Failed to load langs.json', e)
  }
  if (!$mod.$auth) {
    // Initialize VBase Service
    $mod.users = {}
    const vbase = new VBase('vb', $mod.scoped, null, $mod.users); // Relative path
    $mod.$auth = vbase;
  }
  $mod.$axios.interceptors.response.use(function(response) {
    return response?.data
  }, function(error) {
    let data = error.response ? error.response.data : error.response
    return Promise.reject(data?.message || data);
  });

}
