import React from 'react'
import { Redirect } from 'wouter'
import Funding from '../pages/Funding/Funding.jsx'
import IndividualDiscounts from '../pages/LoyaltyPanel/IndividualDiscounts'
import PromoCodes from '../pages/LoyaltyPanel/PromoCodes'
import MachineLogs from '../pages/Logs/MachineLogs.jsx'
import CashUnits from '../pages/Maintenance/CashUnits'
import MachineStatus from '../pages/Maintenance/MachineStatus'
import Notifications from '../pages/Notifications/Notifications'
import CoinAtmRadar from '../pages/OperatorInfo/CoinATMRadar'
import ContactInfo from '../pages/OperatorInfo/ContactInfo'
import MachineScreens from '../pages/OperatorInfo/MachineScreens'
import ReceiptPrinting from '../pages/OperatorInfo/ReceiptPrinting'
import SMSNotices from '../pages/OperatorInfo/SMSNotices/SMSNotices'
import TermsConditions from '../pages/OperatorInfo/TermsConditions'
import ServerLogs from '../pages/Logs/ServerLogs.jsx'
import Services from '../pages/Services/Services'
import SessionManagement from '../pages/SessionManagement/SessionManagement'
import Transactions from '../pages/Transactions/Transactions'
import UserManagement from '../pages/UserManagement/UserManagement'
import WalletSettings from '../pages/Wallet/Wallet'

import Analytics from '../pages/Analytics'
import Blacklist from '../pages/Blacklist'
import Cashout from '../pages/Cashout'
import Commissions from '../pages/Commissions'
import { Customers, CustomerProfile } from '../pages/Customers'
import Locales from '../pages/Locales'
import Triggers from '../pages/Triggers'
import { namespaces } from '../utils/config'

import { ROLES } from './utils'

const getLamassuRoutes = () => [
  {
    key: 'transactions',
    label: 'Transactions',
    route: '/transactions',
    allowedRoles: [ROLES.USER, ROLES.SUPERUSER],
    component: Transactions,
  },
  {
    key: 'maintenance',
    label: 'Maintenance',
    route: '/maintenance',
    allowedRoles: [ROLES.USER, ROLES.SUPERUSER],
    get component() {
      return () => <Redirect to={this.children[0].route} />
    },
    children: [
      {
        key: 'cash_units',
        label: 'Cash units',
        route: '/maintenance/cash-units',
        allowedRoles: [ROLES.USER, ROLES.SUPERUSER],
        component: CashUnits,
      },
      {
        key: 'funding',
        label: 'Funding',
        route: '/maintenance/funding',
        allowedRoles: [ROLES.USER, ROLES.SUPERUSER],
        component: Funding,
      },
      {
        key: 'logs',
        label: 'Machine logs',
        route: '/maintenance/logs',
        allowedRoles: [ROLES.USER, ROLES.SUPERUSER],
        component: MachineLogs,
      },
      {
        key: 'machine-status',
        label: 'Machine status',
        route: '/maintenance/machine-status',
        allowedRoles: [ROLES.USER, ROLES.SUPERUSER],
        component: MachineStatus,
      },
      {
        key: 'server-logs',
        label: 'Server',
        route: '/maintenance/server-logs',
        allowedRoles: [ROLES.USER, ROLES.SUPERUSER],
        component: ServerLogs,
      },
    ],
  },
  {
    key: 'analytics',
    label: 'Analytics',
    route: '/analytics',
    allowedRoles: [ROLES.USER, ROLES.SUPERUSER],
    component: Analytics,
  },
  {
    key: 'settings',
    label: 'Settings',
    route: '/settings',
    allowedRoles: [ROLES.USER, ROLES.SUPERUSER],
    get component() {
      return () => <Redirect to={this.children[0].route} />
    },
    children: [
      {
        key: namespaces.COMMISSIONS,
        label: 'Commissions',
        route: '/settings/commissions',
        allowedRoles: [ROLES.USER, ROLES.SUPERUSER],
        component: Commissions,
      },
      {
        key: namespaces.LOCALE,
        label: 'Locales',
        route: '/settings/locale',
        allowedRoles: [ROLES.USER, ROLES.SUPERUSER],
        component: Locales,
      },
      {
        key: namespaces.CASH_OUT,
        label: 'Cash-out',
        route: '/settings/cash-out',
        allowedRoles: [ROLES.USER, ROLES.SUPERUSER],
        component: Cashout,
      },
      {
        key: namespaces.NOTIFICATIONS,
        label: 'Notifications',
        route: '/settings/notifications',
        allowedRoles: [ROLES.USER, ROLES.SUPERUSER],
        component: Notifications,
      },
      {
        key: 'services',
        label: 'Third-party services',
        route: '/settings/3rd-party-services',
        allowedRoles: [ROLES.USER, ROLES.SUPERUSER],
        component: Services,
      },
      {
        key: namespaces.WALLETS,
        label: 'Wallet',
        route: '/settings/wallet-settings',
        allowedRoles: [ROLES.USER, ROLES.SUPERUSER],
        component: WalletSettings,
      },
      {
        key: namespaces.OPERATOR_INFO,
        label: 'Operator info',
        route: '/settings/operator-info',
        title: 'Operator information',
        allowedRoles: [ROLES.USER, ROLES.SUPERUSER],
        get component() {
          return () => (
            <Redirect
              to={this.children[0].route}
              state={{ prev: this.state?.prev }}
            />
          )
        },
        children: [
          {
            key: 'contact-info',
            label: 'Contact information',
            route: '/settings/operator-info/contact-info',
            allowedRoles: [ROLES.USER, ROLES.SUPERUSER],
            component: ContactInfo,
          },
          {
            key: 'receipt-printing',
            label: 'Receipt',
            route: '/settings/operator-info/receipt-printing',
            allowedRoles: [ROLES.USER, ROLES.SUPERUSER],
            component: ReceiptPrinting,
          },
          {
            key: 'sms-notices',
            label: 'SMS notices',
            route: '/settings/operator-info/sms-notices',
            allowedRoles: [ROLES.USER, ROLES.SUPERUSER],
            component: SMSNotices,
          },
          {
            key: 'coin-atm-radar',
            label: 'Coin ATM Radar',
            route: '/settings/operator-info/coin-atm-radar',
            allowedRoles: [ROLES.USER, ROLES.SUPERUSER],
            component: CoinAtmRadar,
          },
          {
            key: 'terms-conditions',
            label: 'Terms & Conditions',
            route: '/settings/operator-info/terms-conditions',
            allowedRoles: [ROLES.USER, ROLES.SUPERUSER],
            component: TermsConditions,
          },
          {
            key: 'machine-screens',
            label: 'Machine screens',
            route: '/settings/operator-info/machine-screens',
            allowedRoles: [ROLES.USER, ROLES.SUPERUSER],
            component: MachineScreens,
          },
        ],
      },
    ],
  },
  {
    key: 'compliance',
    label: 'Compliance',
    route: '/compliance',
    allowedRoles: [ROLES.USER, ROLES.SUPERUSER],
    get component() {
      return () => <Redirect to={this.children[0].route} />
    },
    children: [
      {
        key: 'triggers',
        label: 'Triggers',
        route: '/compliance/triggers',
        allowedRoles: [ROLES.USER, ROLES.SUPERUSER],
        component: Triggers,
      },
      {
        key: 'customers',
        label: 'Customers',
        route: '/compliance/customers',
        allowedRoles: [ROLES.USER, ROLES.SUPERUSER],
        component: Customers,
      },
      {
        key: 'blacklist',
        label: 'Blacklist',
        route: '/compliance/blacklist',
        allowedRoles: [ROLES.USER, ROLES.SUPERUSER],
        component: Blacklist,
      },
      {
        key: 'loyalty',
        label: 'Loyalty',
        route: '/compliance/loyalty',
        title: 'Loyalty panel',
        allowedRoles: [ROLES.USER, ROLES.SUPERUSER],
        get component() {
          return () => (
            <Redirect
              to={this.children[0].route}
              state={{ prev: this.state?.prev }}
            />
          )
        },
        children: [
          {
            key: 'individual-discounts',
            label: 'Individual discounts',
            route: '/compliance/loyalty/individual-discounts',
            allowedRoles: [ROLES.USER, ROLES.SUPERUSER],
            component: IndividualDiscounts,
          },
          {
            key: 'promo-codes',
            label: 'Promo codes',
            route: '/compliance/loyalty/codes',
            allowedRoles: [ROLES.USER, ROLES.SUPERUSER],
            component: PromoCodes,
          },
        ],
      },
      {
        key: 'customer',
        route: '/compliance/customer/:id',
        allowedRoles: [ROLES.USER, ROLES.SUPERUSER],
        component: CustomerProfile,
      },
    ],
  },
  {
    key: 'system',
    label: 'System',
    route: '/system',
    allowedRoles: [ROLES.SUPERUSER],
    get component() {
      return () => <Redirect to={this.children[0].route} />
    },
    children: [
      {
        key: 'user-management',
        label: 'User management',
        route: '/system/user-management',
        allowedRoles: [ROLES.SUPERUSER],
        component: UserManagement,
      },
      {
        key: 'session-management',
        label: 'Session management',
        route: '/system/session-management',
        allowedRoles: [ROLES.SUPERUSER],
        component: SessionManagement,
      },
    ],
  },
]

export default getLamassuRoutes
