import 'package:fis_common/event/event_type.dart';
import 'package:fis_i18n/i18n.dart';
import 'package:fis_jsonrpc/rpc.dart';
import 'package:fis_ui/base_define/page.dart';
import 'package:fis_ui/index.dart';
import 'package:flutter/material.dart';
import 'package:flyinsono/pages/remedical/consultation/widgets/report/entry_selection_mobile.dart';
import 'package:flyinsono/pages/remedical/vocabulary_entry/controller.dart';
import 'package:get/get.dart';

class EntryInfoMobilePage extends FStatefulWidget implements FPage {
  final int index;
  final ThesaurusDTO thesaurusDTO;
  @override
  final String pageName;
  EntryInfoMobilePage(
    this.index,
    this.thesaurusDTO, {
    this.pageName = "EntryInfoMobilePage",
  });

  @override
  FState<FStatefulWidget> createState() {
    return EntryInfoMobileState();
  }
}

class EntryInfoMobileState extends FState<EntryInfoMobilePage> {
  final controller = Get.find<VocabularyEntryController>();
  List<ThesaurusItemDTO> allThesaurusItem = [];
  FEventHandler<String> thesauruItemsChanged = new FEventHandler();
  @override
  void initState() {
    allThesaurusItem = controller.state.allThesaurusItem;
    super.initState();
  }

  @override
  FWidget build(BuildContext context) {
    return FScaffold(
      appBar: FAppBar.simple(
        title: widget.thesaurusDTO.thesaurusName,
        onBackClicked: () => Get.back(),
      ),
      body: FContainer(
        child: _buildEntryInfoMobileContentView(),
      ),
      bottomNavigationBar: FRow(),
    );
  }

  ///词条内容视图
  FWidget _buildEntryInfoMobileContentView() {
    final contentView = _buildEntryInfoTreeView();
    return FScaffold(
      appBar: FAppBar(
        backgroundColor: Colors.white,
        elevation: 0,
        automaticallyImplyLeading: false,
        foregroundColor: Colors.black,
        title: _buildSerchInput(),
        centerTitle: true,
      ),
      body: contentView,
    );
  }

  ///搜索输入框
  FWidget _buildSerchInput() {
    return FRow(
      children: [
        FBorderInput(
          focusNode: controller.searchFocusNode,
          controller: controller.serachInput,
          fillColor: Colors.white,
          hintSize: 16,
          contentSize: 16,
          maxLength: 50,
          borderColor: Color.fromARGB(255, 185, 184, 184),
          suffixIcon: FIconButton(
            name: "search",
            businessParent: this.widget,
            onPressed: () {
              controller.getEntrysByKeyWords();
              setState(() {
                allThesaurusItem = controller.state.allThesaurusItem;
                thesauruItemsChanged.emit(this, controller.state.keyWord);
              });
            },
            icon: FIcon(
              Icons.search,
              size: 18,
            ),
          ),
          height: 36,
          hintText: i18nBook.common.search.t,
          onChanged: (value) {
            controller.state.keyWord = value;
          },
        ),
      ],
    );
  }

  ///词条信息树形结构
  FWidget _buildEntryInfoTreeView() {
    return EntrySelectionPage(
      (des, conclusion) {},
      isUserCenter: true,
      thesaurus: allThesaurusItem,
      onThesaurusChange: thesauruItemsChanged,
      controller: controller,
    );
  }
}
