import 'package:flutter/cupertino.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:keyboard/resource/assets.gen.dart';
import '../../../resource/colors.gen.dart';
import '../../../utils/widget_location_util.dart';

/// 键盘引导-引导覆盖弹窗
class KeyboardGuideOverlayDialog {
  static final _tag = "KeyboardGuideOverlayDialog";

  /// 显示
  /// [targetWidgetKey] 目标组件的key
  /// [onFinishCallback] 结束引导时回调
  static void show(
    GlobalKey targetWidgetKey, {
    required VoidCallback onCopyCallback,
    required VoidCallback onFinishCallback,
  }) {
    // 获取组件的位置信息
    var targetWidgetInfo = WidgetLocationUtil.getWidgetLocation(
      targetWidgetKey,
    );
    SmartDialog.show(
      tag: _tag,
      backType: SmartBackType.normal,
      clickMaskDismiss: true,
      maskColor: ColorName.black70,
      onDismiss: () {
        onFinishCallback();
      },
      builder: (_) {
        return SizedBox(
          width: double.infinity,
          height: double.infinity,
          child: Stack(
            children: [
              Positioned(
                left: targetWidgetInfo.position.dx,
                top: targetWidgetInfo.position.dy,
                child: GestureDetector(
                  onTap: () {
                    onCopyCallback();
                    SmartDialog.dismiss(tag: _tag);
                  },
                  child: Assets.images.iconKeyboardGuideOverlay1.image(
                    width: 320.w,
                  ),
                ),
              ),
            ],
          ),
        );
      },
    );
  }
}
