import 'package:fis_i18n/i18n.dart';
import 'package:fis_theme/theme.dart';
import 'package:fis_ui/index.dart';
import 'package:flutter/material.dart';
import 'package:flyinsono/architecture/define.dart';

class FBottomSheet {
//显示底部弹框的功能
  static void showBottomSheet(
    BuildContext _context,
    FWidget bottomBody,
    Function callback,
  ) {
    //用于在底部打开弹框的效果
    showModalBottomSheet(
      builder: (BuildContext context) {
        //构建弹框中的内容
        return buildBottomSheetWidget(
          context,
          bottomBody,
          callback,
        );
      },
      context: _context,
    );
  }

  static FWidget buildBottomSheetWidget(
      BuildContext context, FWidget bottomBody, Function callback,
      [bool? isClose = true]) {
    return FGestureDetector(
      name: "ConfirmApplication.BottomSheetWidget",
      businessParent: FVirtualPageWidget("ConfirmApplication"),
      onTap: () {
        FocusScope.of(context).requestFocus(FocusNode());
      },
      child: FContainer(
        child: FColumn(
          children: [
            FContainer(
              decoration: BoxDecoration(
                border: Border(
                  bottom: BorderSide(
                    color: Color.fromRGBO(211, 211, 211, 0.3),
                  ),
                ),
              ),
              child: FRow(
                mainAxisSize: MainAxisSize.max,
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  _buildConfirmOrCancelInkWell(
                    title: i18nBook.common.cancel.t,
                    onTap: () {
                      Navigator.of(context).pop();
                    },
                  ),
                  _buildConfirmOrCancelInkWell(
                    title: i18nBook.common.confirm.t,
                    onTap: () {
                      callback.call();
                    },
                    textColor: FTheme.ins.colorScheme.primary,
                  ),
                ],
              ),
            ),
            FExpanded(
              child: bottomBody,
            ),
          ],
        ),
      ),
    );
  }

  static FWidget _buildConfirmOrCancelInkWell({
    Color? textColor,
    required String title,
    required Function onTap,
  }) {
    return FInkWell(
      child: FContainer(
        padding: EdgeInsets.all(15),
        child: FText(
          title,
          style: TextStyle(
            color: textColor,
          ),
        ),
      ),
      onTap: () => onTap.call(),
    );
  }
}
