/*
 * @Author: XianKaiQun
 * @Date: 2020-08-14 15:35:20
 * @LastEditors  : WuWei
 * @LastEditTime : 2023-05-18 09:25:52
 * @Description: 
 */

import 'package:flutter/material.dart';
import 'package:wisdom_cli/wisdom_cli.dart';

class WisBottomModalLayout extends StatelessWidget {
  WisBottomModalLayout({
    Key? key,
    this.plain = true,
    this.bodyConstraints = const BoxConstraints(maxHeight: 350, minHeight: 250),
    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 String? title;
  final void Function(BuildContext)? onConfirm;
  final void Function(BuildContext)? onCancel;
  final Widget? body;

  @override
  Widget build(BuildContext context) {
    return SafeArea(
      child: Column(
        mainAxisSize: MainAxisSize.min,
        crossAxisAlignment: CrossAxisAlignment.stretch,
        children: <Widget>[
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: <Widget>[
              Wisdom(
                width: 100,
                alignment: Alignment.centerLeft,
                child: !plain
                    ? TextButton(
                        child: Text(cancelText ?? ''),
                        style: TextButton.styleFrom(
                            foregroundColor: Theme.of(context).hintColor),
                        onPressed:
                            onCancel != null ? () => onCancel!(context) : null,
                      )
                    : null,
              ),
              Text(
                title ?? '',
                textAlign: TextAlign.center,
                maxLines: 1,
                style: TextStyle(
                  fontWeight: FontWeight.bold,
                  fontSize: 16,
                ),
              ).asExpanded(),
              Wisdom(
                width: 100,
                alignment: Alignment.centerRight,
                child: !plain
                    ? TextButton(
                        child: Text(confirmText ?? ''),
                        onPressed:
                            onCancel != null ? () => onConfirm!(context) : null,
                      )
                    : CloseButton(
                        onPressed:
                            onCancel != null ? () => onCancel!(context) : null,
                      ),
              ),
            ],
          ),
          Divider(height: 1),
          ConstrainedBox(
            constraints: bodyConstraints,
            child: body,
          ),
        ],
      ),
    );
  }
}
