import PrimeVue from 'primevue/config';
import ConfirmationService from 'primevue/confirmationservice';
import ToastService from 'primevue/toastservice';
import { createApp } from 'vue';
import App from './App.vue';
import router from './router';

import BlockViewer from '@/components/BlockViewer.vue';
import { definePreset } from '@primevue/themes';

import '@/assets/styles.scss';
import '@/assets/tailwind.css';
import Aura from '@primevue/themes/aura';
import axios from 'axios';

axios.defaults.baseURL = import.meta.env.VITE_BACKEND_URL; //'http://localhost:8082'
console.log(import.meta.env.VITE_BACKEND_URL);


import { createAuth } from '@websanova/vue-auth';
import driverAuthBearer from '@websanova/vue-auth/dist/drivers/auth/bearer.esm.js';
import driverHttpAxios from '@websanova/vue-auth/dist/drivers/http/axios.1.x.esm.js';
import driverRouterVueRouter from '@websanova/vue-auth/dist/drivers/router/vue-router.2.x.esm.js';


var auth = createAuth({
    plugins: {
        http: axios,
        router: router
    },
    drivers: {
        http: driverHttpAxios,
        auth: driverAuthBearer,
        router: driverRouterVueRouter
    },
    options:{
        notFoundRedirect: '/auth/login',
        authRedirect: '/auth/login',
        loginData: {url: '/api/auth/login', method: 'POST', redirect: '/'},
        logoutData: {url:'/api/auth/logout', redirect: '/auth/login'},
        fetchData: {url: '/api/auth/fetch-user', method: 'GET', enabled: true},
        refreshData: {url: '/api/auth/refresh-token', method: 'GET', enabled: true}
    }
});

const app = createApp(App);

app.use(router);
app.use(auth);

const MyPreset = definePreset(Aura, {
    semantic: {
        primary: {50: '#ecfeff', 100: '#cffafe', 200: '#a5f3fc', 300: '#67e8f9', 400: '#22d3ee', 500: '#06b6d4', 600: '#0891b2', 700: '#0e7490', 800: '#155e75', 900: '#164e63', 950: '#083344'  }
    }
});

app.use(PrimeVue, {
    theme: {
        preset: MyPreset,
        options: {
            prefix: 'p',
            darkModeSelector: '.app-dark'
        }
    }
});
app.use(ToastService);
app.use(ConfirmationService);

app.component('BlockViewer', BlockViewer);

app.mount('#app');
