import 'package:fis_ui/index.dart';
import 'package:flutter/cupertino.dart';
import 'package:flyinsono/pages/remedical/vocabulary_entry/controller.dart';
import 'package:flyinsono/pages/remedical/vocabulary_entry/widgets/widgets.dart';
import 'package:get/get.dart';

class VocabularyEntryMobilePage extends StatefulWidget implements FWidget {
  @override
  State<StatefulWidget> createState() {
    return VocabularyEntryMobileState();
  }
}

class VocabularyEntryMobileState extends State<VocabularyEntryMobilePage> {
  final controller = Get.find<VocabularyEntryController>();

  @override 
  void initState() {
    controller.onLoaded.addListener((sender, e) {
      setState(() {});
    });
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    final extrys = controller.state.entryInfos;
    if (extrys.isEmpty) {
      return FSizedBox();
    } else {
      return FContainer(
        margin: EdgeInsets.symmetric(vertical: 20),
        child: extrys.isEmpty
            ? FSizedBox()
            : FListView.builder(
                shrinkWrap: true,
                itemCount: extrys.length,
                controller: controller.entryCardController,
                itemBuilder: (context, index) {
                  final thesaurusInfo = extrys[index];
                  return EntryCard(
                    index: index,
                    thesaurusInfo: thesaurusInfo,
                  );
                },
              ),
      );
    }
  }
}
