import 'package:fis_jsonrpc/rpc.dart';
import 'package:flutter/material.dart';
import 'package:flyinsono/pages/remedical/consultation/widgets/report/report_entry_selection.dart';
import 'package:get/get.dart';
import 'package:fis_i18n/i18n.dart';
import 'package:fis_ui/index.dart';

class EntrySelectionDialog extends StatelessWidget {
  const EntrySelectionDialog({
    Key? key,
    required this.items,
  }) : super(key: key);

  final List<ThesaurusItemDTO> items;

  @override
  Widget build(BuildContext context) {
    return FSimpleDialog(
      isUseColumnLayout: true,
      contentPadding: const EdgeInsets.fromLTRB(5, 5, 5, 5),
      insetPadding: EdgeInsets.symmetric(horizontal: 20, vertical: 40),
      okString: i18nBook.common.confirm.t,
      cancelString: i18nBook.common.cancel.t,
      children: [
        _buildTitle(),
        Expanded(child: _buildCards()),
      ],
    );
  }

  Widget _buildCards() {
    return Container(
      width: Get.width,
      height: Get.height,
      child: ListView.builder(
        itemCount: items.length,
        itemBuilder: (context, index) {
          return _buildCard(items[index]);
        },
      ),
    );
  }

  Widget _buildTitle() {
    return Padding(
      padding: const EdgeInsets.only(left: 5, right: 5),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Text(
            i18nBook.remedical.selectWord.t,
            style: TextStyle(fontSize: 20),
          ),
          IconButton(onPressed: () => Get.back(), icon: Icon(Icons.close))
        ],
      ),
    );
  }

  Widget _buildCard(ThesaurusItemDTO item) {
    return InkWell(
      onTap: () {
        Get.back<EntrySelectResult>(
            result: EntrySelectResult(
          description: item.thesaurusItemDescription ?? "",
          conclusion: item.thesaurusItemConclusion ?? "",
        ));
      },
      child: Container(
        decoration: BoxDecoration(
            borderRadius: BorderRadius.all(Radius.circular(5)),
            border: Border.all(color: Colors.black38)),
        padding: EdgeInsets.all(5),
        margin: EdgeInsets.all(5),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Text(
              i18nBook.remedical.description.t,
              style: TextStyle(fontWeight: FontWeight.bold, fontSize: 13),
            ),
            Text(
              item.thesaurusItemDescription ?? "",
              style: TextStyle(fontSize: 12),
            ),
            SizedBox(
              height: 5,
            ),
            Text(
              i18nBook.remedical.summary.t,
              style: TextStyle(fontWeight: FontWeight.bold, fontSize: 13),
            ),
            Text(
              item.thesaurusItemConclusion ?? "",
              style: TextStyle(fontSize: 12),
            ),
          ],
        ),
      ),
    );
  }
}
