import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import '../../playvideo/page/play_video.dart';
import '../bloc/lesson_bloc.dart';
import '../model/lesson_model.dart';

class LessionWidget extends StatelessWidget {
String lessonID;
   LessionWidget({Key? key,  required  this.lessonID}) : super(key: key);
  LessonModel? lessonModel;

  @override
  Widget build(BuildContext context) {
    BlocProvider.of<LessonBloc>(context).add(
        RequestLesson(context: context, lessonID: lessonID));
    return
      BlocBuilder<LessonBloc, LessonState>(
          builder: (context, state) {
            if(state is LessonInitial){
              return const CircularProgressIndicator();
            }
            if(state is LessonFailed){
              return const Text('LessonFailed');
            }
            if(state is LessonLoading){
              return const CircularProgressIndicator();
            }
            if(state is LessonSuccess){
              return
                PlayVideoPage(link: state.lessonModel.data!.length>3?state.lessonModel.data![3].playlist![0].link!:'ES1NU-uwX-Q');
              // state.lessonModel.data!.length>3?PlayVideoPage(link: state.lessonModel.data![3].playlist![0].link!):const Text('Xin Loi khong co Video');
            }
            return const Text('NewFailed');
          }
      );
  }
}


