import { Passthrough } from 'quill-component-library/dist/componentLibrary';

import { getParameterByName } from 'libs/getParameterByName';
import { createPreviewSession } from '../../../../actions/classroomSessions'

const previewEditionRoute = {
  path: ':lessonID/preview/:editionID',
  onEnter: (nextState, replaceWith) => {
    const classroomActivityId = createPreviewSession(nextState.params.editionID)
    const modalQSValue = getParameterByName('modal')
    const modalQS = modalQSValue ? `&modal=${modalQSValue}` : ''
    if (classroomActivityId) {
      document.location.href = `${document.location.origin + document.location.pathname}#/teach/class-lessons/${nextState.params.lessonID}?&classroom_activity_id=${classroomActivityId}${modalQS}`;
    }
  }
};

const previewRoute = {
  path: ':lessonID/preview',
  onEnter: (nextState, replaceWith) => {
    const classroomActivityId = createPreviewSession()
    const modalQSValue = getParameterByName('modal')
    const modalQS = modalQSValue ? `&modal=${modalQSValue}` : ''
    if (classroomActivityId) {
      document.location.href = `${document.location.origin + document.location.pathname}#/teach/class-lessons/${nextState.params.lessonID}?&classroom_activity_id=${classroomActivityId}${modalQS}`;
    }
  }
};

const markingLessonAsCompletedRoute = {
  path: ':lessonID/mark_lesson_as_completed',
  getComponent: (nextState, cb) => {
    System.import(/* webpackChunkName: "teach-classroom-lesson" */'components/classroomLessons/teach/markingLessonAsCompleted.tsx')
    .then((component) => {
      cb(null, component.default);
    });
  },
};

const teachRoute = {
  path: ':lessonID',
  getComponent: (nextState, cb) => {
    System.import(/* webpackChunkName: "teach-classroom-lesson" */'components/classroomLessons/teach/container.tsx')
    .then((component) => {
      cb(null, component.default);
    });
  },
};

const indexRoute = {
  component: Passthrough,
  onEnter: (nextState, replaceWith) => {
    const classroom_activity_id = getParameterByName('classroom_activity_id');
    const lessonID = getParameterByName('uid');
    if (lessonID) {
      document.location.href = `${document.location.origin + document.location.pathname}#/teach/class-lessons/${lessonID}?&classroom_activity_id=${classroom_activity_id}`;
    }
  },
};

const route = {
  path: 'class-lessons',
  indexRoute,
  childRoutes: [
    previewEditionRoute,
    markingLessonAsCompletedRoute,
    previewRoute,
    teachRoute
  ],
  component: Passthrough,
};

export default route;

@@ -337,32 +337,28 @@
 st classroom
-Activ
+Un
 it
-y
 Id = createP
@@ -530,32 +530,28 @@
 f (classroom
-Activ
+Un
 it
-y
 Id) %7B%0A      
@@ -690,32 +690,28 @@
 ?&classroom_
-activ
+un
 it
-y
 _id=$%7Bclassr
@@ -709,32 +709,28 @@
 =$%7Bclassroom
-Activ
+Un
 it
-y
 Id%7D$%7BmodalQS
@@ -859,24 +859,20 @@
 lassroom
-Activ
+Un
 it
-y
 Id = cre
@@ -1026,24 +1026,20 @@
 lassroom
-Activ
+Un
 it
-y
 Id) %7B%0A  
@@ -1182,32 +1182,28 @@
 ?&classroom_
-activ
+un
 it
-y
 _id=$%7Bclassr
@@ -1209,16 +1209,12 @@
 room
-Activ
+Un
 it
-y
 Id%7D$
@@ -1955,27 +1955,21 @@
 lassroom
-_activity_i
+UnitI
 d = getP
@@ -1994,24 +1994,20 @@
 assroom_
-activ
+un
 it
-y
 _id');%0A 
@@ -2206,24 +2206,20 @@
 assroom_
-activ
+un
 it
-y
 _id=$%7Bcl
@@ -2229,19 +2229,13 @@
 room
-_activity_i
+UnitI
 d%7D%60;

Update react router to use classroom unit id in lessons service