import React, { Component } from 'react';
import { IndexRoute, Route, IndexRedirect } from 'react-router';


import App from 'containers/App';

import Home from 'containers/Home';

import Customers from 'containers/Customers';
import CustomerDetail from 'containers/CustomerDetail';

import Income from 'containers/Income';
import InvoiceDetail from 'containers/InvoiceDetail';
import IncomeDetail from 'containers/IncomeDetail';

import Expenses from 'containers/Expenses';
import ExpenseDetail from 'containers/ExpenseDetail';

import Payments from 'containers/Payments';
import PaymentDetail from 'containers/PaymentDetail';
import PaymentCategoryDetail from 'containers/PaymentCategoryDetail';

import ReportPortal from 'containers/ReportPortal';
import TaxReport from 'containers/TaxReport';
import CashflowReport from 'containers/CashflowReport';
import PaymentReport from 'containers/PaymentReport';
import CustomerReport from 'containers/CustomerReport';
import SummaryReport from 'containers/SummaryReport';
import DphReport from 'containers/DphReport';

import Settings, { About, Company, Customization, Local, Password, Tax, Payment, LinkedAccounts } from 'containers/Settings';
import InitSettings from 'containers/InitSettings';

import { MessagePanel } from 'lib/components'
import { authCallbackRoute } from 'lib/oauth2-client';

const empty = (props) => <MessagePanel size="big" icon="" title="Not implemented" text="This feature has not been implemented yet"/>


const childRoutes = [
    /* HOME */
    {
        path: '/home',
        component: Home
    },

    {
        path: '/home/invoices/new',
        component: InvoiceDetail,
        backRoute: '/home',
        successRoute: '/home/invoices'
    },
    {
        path: '/home/invoices/:invoiceId',
        component: InvoiceDetail,
        backRoute: '/home'
    },
    {
        path: '/home/income/new',
        component: IncomeDetail,
        backRoute: '/home',
        successRoute: '/home/income'
    },
    {
        path: '/home/income/:incomeId',
        component: IncomeDetail,
        backRoute: '/home'
    },
    {
        path: '/home/expenses/new',
        component: ExpenseDetail,
        backRoute: '/home',
        successRoute: '/home/expenses'
    },
    {
        path: '/home/expenses/:expenseId',
        component: ExpenseDetail,
        backRoute: '/home'
    },
    {
        path: '/home/payments/:paymentId',
        component: PaymentDetail,
        backRoute: '/home',
        successRoute: '/home/payments'
    },

    /* CUSTOMERS */
    {
        path: '/customers',
        component: Customers
    },
    {
        path: '/customers/new',
        component: CustomerDetail
    },
    {
        path: '/customers/:customerId',
        component: CustomerDetail
    },

    /* INVOICES */
    {
        path: '/income',
        component: Income
    },
    {
        path: '/invoices/new',
        component: InvoiceDetail
    },
    {
        path: '/invoices/:invoiceId',
        component: InvoiceDetail
    },
    {
        path: '/income/new',
        component: IncomeDetail
    },
    {
        path: '/income/:incomeId',
        component: IncomeDetail
    },

    /* EXPENSES */
    {
        path: '/expenses',
        component: Expenses
    },
    {
        path: '/expenses/new',
        component: ExpenseDetail
    },
    {
        path: '/expenses/:expenseId',
        component: ExpenseDetail
    },

    /* PAYMENTS */
    {
        path: '/payments',
        component: Payments
    },
    {
        path: '/payments/categories/new',
        component: PaymentCategoryDetail
    },
    {
        path: '/payments/categories/:id',
        component: PaymentCategoryDetail
    },
    {
        path: '/payments/categories/:categoryId/payments/:paymentId',
        component: PaymentDetail
    },
    {
        path: '/payments/categories/:categoryId/payments/:mode/new',
        component: PaymentDetail
    },
    {
        path: '/payments/:mode/new',
        component: PaymentDetail
    },
    {
        path: '/payments/:paymentId',
        component: PaymentDetail
    },

    /* REPORTS */
    {
        path: '/reports',
        component: ReportPortal
    },
    {
        path: '/reports/tax',
        component: TaxReport
    },
    {
        path: '/reports/cashflow',
        component: CashflowReport
    },
    {
        path: '/reports/payment',
        component: PaymentReport
    },
    {
        path: '/reports/customer',
        component: CustomerReport
    },
    {
        path: '/reports/summary',
        component: SummaryReport
    },
    {
        path: '/reports/dph',
        component: DphReport
    },

    /* SETTINGS */
    {
        path: '/settings',
        component: Settings
    },
    {
        path: '/settings/about',
        component: About
    },
    {
        path: '/settings/company',
        component: Company
    },
    {
        path: '/settings/customization',
        component: Customization
    },
    {
        path: '/settings/local',
        component: Local
    },
    {
        path: '/settings/password',
        component: Password
    },
    {
        path: '/settings/taxes',
        component: Tax
    },
    {
        path: '/settings/payment',
        component: Payment
    },
    {
        path: '/settings/linked',
        component: LinkedAccounts
    },

    authCallbackRoute({
        component: <div>Please wait...</div>
    }),

    /* DEFAULT ROUTE */
    {
        path: '*',
        component: empty
    }
];

export function backRoute(route) {
    
}


export default (rootPath = "/", opts) => {
    if (!opts.store.settings.data.initialized) {
        return [{
            path: "*",
            component: InitSettings,

            /*indexRoute: { onEnter: (nextState, replace) => replace('/init') },*/
        }];
    }

    const routes = [
        {
            path: rootPath,
            component: App,

            defaultRoute: empty,
            indexRoute: { onEnter: (nextState, replace) => replace('/home') },

            childRoutes
        }
    ];

    return routes;
}