// src/router/router.js
import { createBrowserRouter, Navigate } from "react-router";
import ProtectedRoute from "../components/auth/ProtectedRoute.jsx";
import MainLayout from "../layout/MainLayout.jsx";
import AuthLayout from "../layout/AuthLayout.jsx";
import Register from "../pages/Register.jsx";
import Login from "../pages/login.jsx";
import Dashboard from "../pages/Dashboard.jsx";
import Upload from "../pages/Upload.jsx";
import MyFile from "../pages/MyFile.jsx";
import Trash from "../pages/Trash.jsx";
import Folder from "../pages/Folder.jsx";
import Space from "../pages/Space.jsx";
import Star from "../pages/Star.jsx";
import MyTicket from "../pages/MyTicket.jsx";
import NewTicket from "../pages/NewTicket.jsx";
import MyAccount from "../pages/MyAccount.jsx";
import Ftp from "../pages/Ftp.jsx";
import Plans from "../pages/Plans.jsx";
import Invoices from "../pages/Invoices.jsx";
import ChangePassword from "../pages/TwoStep.jsx";
import Wallet from "../pages/Wallet.jsx";
import Notif from "../pages/Notif.jsx";
import ForgotPassword from "../pages/ForgotPassword.jsx";
import Payment from "../pages/Payment.jsx";
import Landing from "../pages/Landing.jsx";
import Empty from "../pages/Empty.jsx";
import Domains from "../pages/Domains.jsx";
import ShareExpired from "../pages/ShareExpired.jsx";
import Logini from "../pages/Login-Num.jsx";

export const router = createBrowserRouter([
  {
    path: "/",
    element: <Landing />,
  },

  {
    path: "/auth/",
    element: <AuthLayout />,
    children: [
      { index: true, element: <Navigate to="/auth/login" replace /> },
      { path: "login", element: <Logini /> },
      { path: "forget-password", element: <ForgotPassword /> },
      { path: "register", element: <Register /> },
      { path: "login-username", element: <Login /> },
      { path: "shareexpired", element: <ShareExpired /> },
      { path: "payment", element: <Payment /> },
      { path: "payment/:status", element: <Payment /> },

      // ✅ اگر داخل /auth/... چیزی اشتباه زد، بره لندینگ
      { path: "*", element: <Navigate to="/" replace /> },
    ],
  },

  {
    path: "/",
    element: (
      <ProtectedRoute>
        <MainLayout />
      </ProtectedRoute>
    ),
    children: [
      { path: "home", element: <Dashboard /> },
      { path: "myfile", element: <MyFile /> },
      { path: "myfolder", element: <Folder /> },
      { path: "star", element: <Star /> },
      { path: "trash", element: <Trash /> },
      { path: "upload", element: <Upload /> },
      { path: "space", element: <Space /> },
      { path: "ftp", element: <Ftp /> },
      { path: "upgrade", element: <Plans /> },
      { path: "mywallet", element: <Wallet /> },
      { path: "receipt", element: <Invoices /> },
      { path: "newticket", element: <NewTicket /> },
      { path: "myticket", element: <MyTicket /> },
      { path: "mynotification", element: <Notif /> },
      { path: "myaccount", element: <MyAccount /> },
      { path: "domain", element: <Domains /> },
      { path: "twostep", element: <ChangePassword /> },
      { path: "empty", element: <Empty /> },

      // ✅ اگر کاربر لاگین بود و مسیر اشتباه زد، بره لندینگ
      { path: "*", element: <Navigate to="/home" replace /> },
    ],
  },

  // ✅ مهم‌ترین: هر مسیر ناشناخته‌ی کلی (مثلاً /aaaa) -> لندینگ
  { path: "*", element: <Navigate to="/" replace /> },
]);
