/*
 * @Author: XianKaiQun
 * @Date: 2020-09-08 16:48:28
 * @LastEditors: XianKaiQun
 * @LastEditTime: 2020-10-27 11:06:38
 * @Description: 
 */
import 'package:flutter/material.dart';
import 'package:wisdom_cli/wisdom_cli.dart';

///确认弹窗的基本视图样式
class WModal extends StatelessWidget {
  const WModal({
    Key? key,
    this.header,
    this.content,
    this.iconTheme,
    this.headerStyle,
    this.bodyStyle,
    this.buttonTheme,
    this.footers,
  }) : super(key: key);
  final Widget? header;
  final Widget? content;
  final IconThemeData? iconTheme;
  final TextStyle? headerStyle;
  final TextStyle? bodyStyle;
  final ButtonThemeData? buttonTheme;
  final List<Widget>? footers;

  @override
  Widget build(BuildContext context) {
    final style = WTheme.of(context);
    final colorScheme = style.colorScheme;

    Widget? headerWidget = header;
    if (headerWidget != null) {
      headerWidget = DefaultTextStyle(
        style: TextStyle(
          fontSize: 18.pt,
          fontWeight: FontWeight.bold,
          color: colorScheme.text,
        ).merge(headerStyle),
        child: headerWidget,
      );
      headerWidget = IconTheme(
        data: IconTheme.of(context).copyWith(size: 18.pt).merge(iconTheme),
        child: headerWidget,
      );
    }

    Widget? contentWidget = content;
    if (contentWidget != null) {
      contentWidget = DefaultTextStyle(
        textAlign: TextAlign.center,
        style: TextStyle(
          fontSize: 16.pt,
          color: colorScheme.text,
        ).merge(headerStyle),
        child: contentWidget,
      );
      contentWidget = ConstrainedBox(
        constraints: BoxConstraints(
          minHeight: 30.pt,
        ),
        child: contentWidget,
      );
    }

    Widget footerWidget = Row(
      mainAxisAlignment: MainAxisAlignment.spaceEvenly,
      children: footers!,
    );

    return Container(
      alignment: Alignment.center,
      color: Colors.black26,
      child: Material(
        color: Colors.white,
        borderRadius: BorderRadius.circular(20.pt),
        child: ButtonTheme.fromButtonThemeData(
          data: ButtonThemeData(
            height: 44.pt,
            textTheme: ButtonTextTheme.primary,
          ),
          child: Container(
            padding: EdgeInsets.all(20.pt),
            constraints: BoxConstraints(
              minWidth: 305.pt,
              maxWidth: 305.pt,
              minHeight: 150.pt,
              maxHeight: 400.pt,
            ),
            child: Column(
              mainAxisSize: MainAxisSize.min,
              children: [
                if (headerWidget != null) ...[
                  headerWidget,
                  SizedBox(height: 25.pt),
                ],
                if (contentWidget != null) ...[
                  contentWidget,
                  SizedBox(height: 25.pt),
                ],
                footerWidget,
              ],
            ),
          ),
        ),
      ),
    );
  }
}
