11/** @format */
22
3- import { computed , Injectable , signal } from "@angular/core" ;
3+ import { computed , inject , Injectable , signal } from "@angular/core" ;
44import { CourseLesson , Task } from "@domain/courses/courses.model" ;
55import { AsyncState , initial , isSuccess } from "@domain/shared/async-state" ;
6+ import { CourseDetailUIInfoService } from "./course-detail-ui-info.service" ;
67
78@Injectable ( )
89export class LessonUIInfoService {
10+ private readonly courseDetailUIInfoService = inject ( CourseDetailUIInfoService ) ;
911 readonly lesson$ = signal < AsyncState < CourseLesson > > ( initial ( ) ) ;
1012 readonly submitAnswer$ = signal < AsyncState < void > > ( initial ( ) ) ;
1113
@@ -16,6 +18,7 @@ export class LessonUIInfoService {
1618
1719 readonly isComplete = signal < boolean > ( false ) ;
1820 readonly currentTaskId = signal < number | null > ( null ) ;
21+ readonly activeTaskId = signal < number | null > ( null ) ;
1922
2023 /** Transition loading — управляется фасадом вручную (с setTimeout delay) */
2124 readonly loading = signal ( false ) ;
@@ -65,4 +68,25 @@ export class LessonUIInfoService {
6568 isDone ( task : Task ) : boolean {
6669 return task . isCompleted || this . completedTaskIds ( ) . has ( task . id ) ;
6770 }
71+
72+ readonly isViewingCompleted = computed ( ( ) => {
73+ const task = this . currentTask ( ) ;
74+ return task ? this . isDone ( task ) : false ;
75+ } ) ;
76+
77+ isClickable ( task : Task ) : boolean {
78+ return this . isDone ( task ) || task . id === this . activeTaskId ( ) ;
79+ }
80+
81+ readonly lessonOrder = computed < number | null > ( ( ) => {
82+ const lesson = this . lessonInfo ( ) ;
83+ const structure = this . courseDetailUIInfoService . courseStructure ( ) ;
84+ if ( ! lesson || ! structure ) return null ;
85+
86+ for ( const mod of structure . modules ) {
87+ const found = mod . lessons . find ( l => l . id === lesson . id ) ;
88+ if ( found ) return found . order ;
89+ }
90+ return null ;
91+ } ) ;
6892}
0 commit comments