import { Route, Switch } from 'react-router-dom'
import { DataShareServiceViz } from 'containers/Viz/Loadable'
import {
  DataShareServiceWidget 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, { useEffect } from 'react'
import { Dashboard } from '../Dashboard/Loadable'

export default function DataShareService() {
  useEffect(() => {
    window.localStorage.setItem('inDataService', 'dataShareService')
  }, [])
  return (
    <Project>
      <Switch>
        <Route
          path="/project/:projectId/dataShareService/portal/:portalId"
          component={Dashboard}
        />
        <Route
          path="/project/:projectId/dataShareService/display/:displayId"
          component={DataShareServiceViz}
        />
        <Route
          exact
          path="/project/:projectId/dataShareService/widget/:widgetId?"
          component={Workbench}
        />
        <Route
          exact
          path="/project/:projectId/dataShareService/view/:viewId?"
          component={ViewEditor}
        />
        <Route
          exact
          path="/project/:projectId/dataShareService/schedule/:scheduleId?"
          component={ScheduleEditor}
        />
        <Sidebar>
          <Switch>
            <AuthorizedRoute
              permission="vizPermission"
              path="/project/:projectId/dataShareService/vizs"
              component={DataShareServiceViz}
            />
            <AuthorizedRoute
              permission="widgetPermission"
              path="/project/:projectId/dataShareService/widgets"
              component={Widget}
            />
            <AuthorizedRoute
              exact
              permission="viewPermission"
              path="/project/:projectId/dataShareService/views"
              component={View}
            />
            <AuthorizedRoute
              permission="sourcePermission"
              path="/project/:projectId/dataShareService/sources"
              component={Source}
            />
            <AuthorizedRoute
              permission="schedulePermission"
              path="/project/:projectId/dataShareService/schedules"
              component={Schedule}
            />
          </Switch>
        </Sidebar>
      </Switch>
    </Project>
  )
}
