import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:ongbut_ntmanh/app/module/lession/widgets/play_video.dart';

import '../bloc/lesson_bloc.dart';
import '../model/lesson_model.dart';

class LessionWidget extends StatelessWidget {
  String lessonID;
  LessonModel? lessonModel;
  String pl = 'Playlist video';
   LessionWidget( this.lessonID, {Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    BlocProvider.of<LessonBloc>(context).add(
        RequestLesson(context: context));
    return
      // Container(child: Text(lessonID.toString()),);
      SingleChildScrollView(
        child: Column(
          mainAxisSize: MainAxisSize.max,
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            Padding(
              padding: const EdgeInsets.fromLTRB(10, 10, 0, 0),
              child: Row(
                children: [
                  const Text('Thong Tin chi tiet',style: TextStyle(fontWeight: FontWeight.bold,fontSize: 15),),
                  const SizedBox(width: 100),
                  TextButton(
                      child: Text('Nhan xet ve khoa hoc'),
                      onPressed: () {
                        print('Pressed');
                      }
                  )
                ],
              ),
            ),
            BlocConsumer<LessonBloc, LessonState>(
            listener: (context, state) async {},
            builder: (context, state) {
              return
                BlocBuilder<LessonBloc, LessonState>(
                    builder: (context, state) {
                      if(state is LessonInitial){
                        return const Text('LessonInitial');
                      }
                      if(state is LessonFailed){
                        //const CircularProgressIndicator();
                        return const Text('LessonFailed');
                      }
                      if(state is LessonLoading){
                        return const CircularProgressIndicator();
                      }
                      if(state is LessonSuccess){
                        return
                          // const Text('LessonSuccess');
                        ListView.builder(
                            shrinkWrap: true,
                            itemCount: state.lessonModel.data!.length,
                            itemBuilder: (context, index){
                              return
                                Column(children: [
                                  Text(state.lessonModel.data![index].title!=null?state.lessonModel.data![index].title!:'khong co du lieu'),
                                  //Text(state.lessonModel.data![index].playlist![0]!=null?state.lessonModel.data![index].playlist![0].link!:'....'),
                                  TextButton(
                                      onPressed: (){
                                         // PlayVideoPage();
                                        return Center(child: Text('12121'));
                                      },
                                      child:
                                      Text(state.lessonModel.data![index].title == pl ?state.lessonModel.data![index].playlist![0].link!:'...'),
                                      // Text(state.lessonModel.data![index].playlist![0]!=null?state.lessonModel.data![index].playlist![0].link!:'....'),
                                  ),
                                ],);

                            }
                        );
                      }
                      return const Text('NewFailed');
                    }
                );
            }
        ),
          ],
        ),
      );
  }
}
