/*
 * @Author       : WuWei
 * @LastEditors  : WuWei
 * @Date         : 2022-11-02 10:26:39
 * @LastEditTime : 2023-10-26 19:18:54
 * @Description  : Do not edit
 */

import 'package:flutter/material.dart';
import 'package:wisdom_cli/src/assets.gen.dart';
import 'package:wisdom_cli/wisdom_cli.dart';

///弹出层构造Widget
class WBottomModal extends StatelessWidget {
  WBottomModal({
    Key? key,
    this.plain = true,
    this.bodyConstraints = const BoxConstraints(
      maxHeight: 500,
      minHeight: 400,
    ),
    this.confirmText = '确定',
    this.cancelText = '取消',
    this.title,
    this.onConfirm,
    this.onCancel,
    this.body,
  }) : super(key: key);
  final bool plain;
  final BoxConstraints bodyConstraints;
  final String? confirmText;
  final String? cancelText;
  final Widget? title;
  final void Function(BuildContext)? onConfirm;
  final void Function(BuildContext)? onCancel;
  final Widget? body;

  @override
  Widget build(BuildContext context) {
    final colorScheme = WTheme.of(context).colorScheme;
    return Container(
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.only(
          topLeft: Radius.circular(20.pt),
          topRight: Radius.circular(20.pt),
        ),
      ),
      child: SafeArea(
        child: Column(
          mainAxisSize: MainAxisSize.min,
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: <Widget>[
            Wisdom.row(
              minHeight: 54.pt,
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: <Widget>[
                if (onCancel != null) ...[
                  Wisdom(
                    width: 100.pt,
                    alignment: Alignment.centerLeft,
                    child: !plain
                        ? TextButton(
                            style: TextButton.styleFrom(
                              foregroundColor: Theme.of(context).hintColor,
                            ),
                            child: WisText(cancelText ?? ''),
                            // textColor:
                            onPressed: () => onCancel!(context),
                          ).asPaddingOnly(right: 20.pt)
                        : null,
                  ),
                ] else ...[
                  SizedBox(
                    width: 100.pt,
                  ),
                ],
                DefaultTextStyle(
                  maxLines: 1,
                  // textAlign: onCancel != null ? TextAlign.center : TextAlign.left,
                  textAlign: TextAlign.center,
                  style: DefaultTextStyle.of(context).style.copyWith(
                        fontWeight: FontWeight.bold,
                        fontSize: 16.pt,
                      ),
                  child: Wisdom(
                    padding: EdgeInsets.symmetric(horizontal: 15.pt),
                    child: title,
                  ).asExpanded(),
                ),
                Wisdom(
                  width: 100.pt,
                  alignment: Alignment.centerRight,
                  child: !plain
                      ? TextButton(
                          child: WisText(
                            confirmText ?? '',
                            color: colorScheme.primary,
                          ),
                          onPressed: onConfirm != null
                              ? () => onConfirm!(context)
                              : null,
                        ).asPaddingOnly(left: 20.pt)
                      : Wisdom(
                          onTap: () => {
                            Navigator.pop(context),
                            onCancel != null ? () => onCancel!(context) : null,
                          },
                          padding: EdgeInsets.only(right: 15.pt),
                          child: Image(
                            image: AssetList.$guanbi_png_image,
                            height: 14.pt,
                            width: 14.pt,
                          ),
                        ),
                ),
              ],
            ),
            Container(
              height: MediaQuery.of(context).size.height * 0.62,
              child: body,
            ),
          ],
        ),
      ),
    );
  }
}
