import 'package:flutter/cupertino.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';

import 'custom_direction_edit_view.dart';

/// 自定义预测方向的编辑弹窗
class CustomDirectionEditDialog {
  static const String _tag = "CustomDirectionEditDialog";

  /// 显示弹窗
  /// [onSaveCallback] 保存时回调
  static void show(OnSaveCallback onSaveCallback) {
    SmartDialog.show(
      tag: _tag,
      // 点击遮罩，不关闭弹窗
      clickMaskDismiss: false,
      // 内容居中显示
      alignment: Alignment.center,
      // 动画类型
      animationType: SmartAnimationType.fade,
      builder:
          (BuildContext context) => Container(
            margin: EdgeInsets.only(
              // 动态添加底部间距，避免软键盘弹起时，遮挡弹窗
              bottom: MediaQuery.of(context).viewInsets.bottom,
            ),
            // 高度，包裹内容
            child: IntrinsicHeight(
              child: Container(
                padding: EdgeInsets.symmetric(horizontal: 32.w),
                child: CustomDirectionEditView(
                  onSaveCallback: (String customDirection) {
                    onSaveCallback(customDirection);
                    SmartDialog.dismiss(tag: _tag);
                  },
                  onCloseCallback: () {
                    // 关闭弹窗
                    SmartDialog.dismiss(tag: _tag);
                  },
                ),
              ),
            ),
          ),
    );
  }
}
