import 'dart:ui';

import 'package:electronic_assistant/utils/expand.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';

void showPressTouchPopup(
    Offset offset, Alignment alignment, List<Widget> childWidget,
    {String? tag, BuildContext? bindWidget}) {
  SmartDialog.showAttach(
    targetContext: null,
    targetBuilder: (_, __) => offset,
    animationType: SmartAnimationType.fade,
    clickMaskDismiss: true,
    alignment: alignment,
    bindWidget: bindWidget,
    tag: tag,
    maskColor: Colors.transparent,
    builder: (_) {
      return IntrinsicWidth(
        child: Container(
          constraints: BoxConstraints(
            minWidth: 128.w,
          ),
          decoration: BoxDecoration(
            color: Colors.white,
            border: Border.all(color: '#D8D8D8'.toColor(), width: 1), // 边框
            borderRadius: BorderRadius.circular(8), // 圆角
            boxShadow: [
              BoxShadow(
                color: Colors.black.withOpacity(0.1), // 阴影颜色
                spreadRadius: 2, // 阴影扩散半径
                blurRadius: 6, // 阴影模糊半径
                offset: const Offset(0, 3), // 阴影偏移量
              ),
            ],
          ),
          child: Column(
            children: childWidget,
          ),
        ),
      );
    },
  );
}

void showViewTargetPopup(BuildContext context, Alignment alignment,
    List<Widget> childWidget,
    {Offset? offset}) {
  SmartDialog.showAttach(
    targetContext: context,
    targetBuilder: (targetOffset, targetSize) {
      return Offset(targetOffset.dx + (offset != null ? offset.dx : 0),
          targetOffset.dy + (offset != null ? offset.dy : 0));
    },
    alignment: alignment,
    animationType: SmartAnimationType.fade,
    clickMaskDismiss: true,
    maskColor: Colors.transparent,
    bindPage: true,
    builder: (_) => IntrinsicWidth(
      child: Container(
        constraints: BoxConstraints(
          minWidth: 128.w,
        ),
        decoration: BoxDecoration(
          color: Colors.white,
          border: Border.all(color: '#D8D8D8'.toColor(), width: 1), // 边框
          borderRadius: BorderRadius.circular(8), // 圆角
          boxShadow: [
            BoxShadow(
              color: Colors.black.withOpacity(0.1), // 阴影颜色
              spreadRadius: 2, // 阴影扩散半径
              blurRadius: 6, // 阴影模糊半径
              offset: const Offset(0, 3), // 阴影偏移量
            ),
          ],
        ),
        child: Column(
          children: childWidget,
        ),
      ),
    ),
  );
}
