import {createRouter, createWebHistory} from 'vue-router';
import CategoriesList from '@/components/settings/categories/CategoriesList.vue';
import CreateCategoryModal from "@/components/settings/categories/CreateCategoryModal.vue";
import CategoryListItem from "@/components/settings/categories/CategoryListItem.vue"; // Импортируем новый компонент
import BudgetList from "../components/budgets/BudgetList.vue";
import BudgetView from "@/components/budgets/BudgetView.vue";
import BudgetView2 from "@/components/budgets/BudgetView2.vue";
import SettingsView from "@/components/settings/SettingsView.vue";
import RecurrentList from "@/components/settings/recurrent/RecurrentList.vue";
import TransactionList from "@/components/transactions/TransactionList.vue";
import LoginView from "@/components/auth/LoginView.vue";
import RegisterView from "@/components/auth/RegisterView.vue";
import AnalyticsView from "@/components/analytics/AnalyticsView.vue";
import BudgetViewboth from "@/components/budgets/BudgetViewboth.vue";
import SpacesList from "@/components/spaces/SpacesList.vue";
import SpaceInventationView from "@/components/spaces/SpaceInventationView.vue";
import About from "@/components/faq/About.vue";

const routes = [
    {path: '/login', component: LoginView},
    {path: '/register', component: RegisterView},
    {path: '/', name: 'Aboutmain', component: About, meta: {requiresAuth: true}},
    {path: '/about', name: 'About', component: About, meta: {requiresAuth: true}},
    {path: '/analytics', name: 'Analytics', component: AnalyticsView, meta: {requiresAuth: true}},
    {path: '/spaces', name: 'Spaces', component: SpacesList, meta: {requiresAuth: true}},
    {path: '/spaces/invite/:code', name: 'Space Invite View', component: SpaceInventationView, meta: {requiresAuth: true}},
    {path: '/budgets', name: 'Budgets', component: BudgetList, meta: {requiresAuth: true}},
    {path: '/budgets/:id', name: 'BudgetView', component: BudgetViewboth, meta: {requiresAuth: true}},
    {path: '/budgets-new/:id', name: 'BudgetView New', component: BudgetView2, meta: {requiresAuth: true}},
    {path: '/transactions/:mode*', name: 'Transaction List', component: TransactionList, meta: {requiresAuth: true}},
    // {path: '/transactions/create', name: 'Transaction List', component: TransactionList},
    {path: '/settings/', name: 'Settings', component: SettingsView, meta: {requiresAuth: true}},
    {path: '/settings/categories', name: 'Categories', component: CategoriesList, meta: {requiresAuth: true}},
    {
        path: '/settings/recurrents',
        name: 'Recurrent operations list',
        component: RecurrentList,
        meta: {requiresAuth: true}
    },
    {
        path: '/settings/categories/create',
        name: "Categories Creation",
        component: CreateCategoryModal,
        meta: {requiresAuth: true}
    },// Добавляем новый маршрут
    {
        path: '/settings/categories/one',
        name: "Categories Creation",
        component: CategoryListItem,
        meta: {requiresAuth: true}
    }// Добавляем новый маршрут
];

const router = createRouter({
    history: createWebHistory(),
    routes,
});

router.beforeEach((to, from, next) => {
    const token = localStorage.getItem('token');
    if (to.meta.requiresAuth && !token) {
        // const router = useRoute()
        next('/login?back=' + to.fullPath);
    } else {
        next();
    }
});
export default router;
