import { createBrowserRouter } from "react-router";

import Root from "@/root";
import { Home } from "@/pages/Home";
import { Forms } from "@/pages/Forms";
import Dashboard from "@/pages/Dashboard";
import Productors from "@/pages/Productors";
import Products from "@/pages/Products";
import Users from "@/pages/Users";
import Shipments from "./pages/Shipments";
import { Contract } from "./pages/Contract";
import { NotFound } from "./pages/NotFound";
import Contracts from "./pages/Contracts";
import { Help } from "./pages/Help";
import { Login } from "./pages/Login";
import { ProtectedRoute } from "./services/auth/ProtectedRoute";

export const router = createBrowserRouter([
    {
        path: "/",
        Component: Root,
        errorElement: <NotFound />,
        children: [
            { index: true, Component: Home },
            { path: "/forms", Component: Forms },
            {
                element: <ProtectedRoute />,
                children: [
                    {
                        path: "/dashboard",
                        Component: Dashboard,
                        children: [
                            { path: "help", Component: Help },
                            { path: "productors", Component: Productors },
                            { path: "productors/create", Component: Productors },
                            { path: "productors/:id/edit", Component: Productors },
                            { path: "products", Component: Products },
                            { path: "products/create", Component: Products },
                            { path: "products/:id/edit", Component: Products },
                            { path: "contracts", Component: Contracts },
                            { path: "contracts/download", Component: Contracts },
                            { path: "contracts/export", Component: Contracts },
                            { path: "users", Component: Users },
                            { path: "users/create", Component: Users },
                            { path: "users/:id/edit", Component: Users },
                            { path: "forms", Component: Forms },
                            { path: "forms/:id/edit", Component: Forms },
                            { path: "forms/:id/delete", Component: Forms },
                            { path: "forms/create", Component: Forms },
                            { path: "shipments", Component: Shipments },
                            { path: "shipments/:id/edit", Component: Shipments },
                            { path: "shipments/create", Component: Shipments },
                        ],
                    },
                ],
            },
            { path: "/form/:id", Component: Contract },
            { path: "/auth/login", Component: Login },
        ],
    },
]);
