import { Route, Switch } from 'react-router-dom'
import { DataManagerViz as Viz } from 'containers/Viz/Loadable'
import { DataManagerWidget as Widget, Workbench } from 'containers/Widget/Loadable'
import { Sidebar } from './Loadable'
import AuthorizedRoute from 'containers/Main/AuthorizedRoute'
import { View, ViewEditor } from 'containers/View/Loadable'
import { Source } from 'containers/Source/Loadable'
import { Schedule, ScheduleEditor } from 'containers/Schedule/Loadable'
import { Project } from 'containers/Projects/Loadable'
import React from 'react'
import { Dashboard } from '../Dashboard/Loadable'

export default function DataManager() {
  return (
    <Project>
      <Switch>
        <Route
          path='/project/:projectId/dataManager/portal/:portalId'
          component={Dashboard}
        />
        <Route
          path='/project/:projectId/dataManager/display/:displayId'
          component={Viz}
        />
        <Route
          exact
          path='/project/:projectId/dataManager/widget/:widgetId?'
          component={Workbench}
        />
        <Route
          exact
          path='/project/:projectId/dataManager/view/:viewId?'
          component={ViewEditor}
        />
        <Route
          exact
          path='/project/:projectId/dataManager/schedule/:scheduleId?'
          component={ScheduleEditor}
        />
        <Sidebar>
          <Switch>
            <AuthorizedRoute
              permission='vizPermission'
              path='/project/:projectId/dataManager/vizs'
              component={Viz}
            />
            <AuthorizedRoute
              permission='widgetPermission'
              path='/project/:projectId/dataManager/widgets'
              component={Widget}
            />
            <AuthorizedRoute
              exact
              permission='viewPermission'
              path='/project/:projectId/dataManager/views'
              component={View}
            />
            <AuthorizedRoute
              permission='sourcePermission'
              path='/project/:projectId/dataManager/sources'
              component={Source}
            />
            <AuthorizedRoute
              permission='schedulePermission'
              path='/project/:projectId/dataManager/schedules'
              component={Schedule}
            />
          </Switch>
        </Sidebar>
      </Switch>
    </Project>
  )
}
