import 'package:flutter/material.dart';
import 'package:flutter_svga/flutter_svga.dart';
import 'package:tancent_vap/utils/constant.dart';
import 'package:tancent_vap/widgets/vap_view.dart';
import 'package:yumi/shared/tools/sc_gift_vap_svga_manager.dart';

class VapPlusSvgaPlayer extends StatefulWidget {
  final String tag;

  const VapPlusSvgaPlayer({super.key, required this.tag});

  @override
  State<VapPlusSvgaPlayer> createState() => _VapPlusSvgaPlayerState();
}

class _VapPlusSvgaPlayerState extends State<VapPlusSvgaPlayer>
    with TickerProviderStateMixin {
  late SVGAAnimationController _svgaController;

  @override
  void initState() {
    super.initState();
    _svgaController = SVGAAnimationController(vsync: this);
    if (widget.tag == "room_gift") {
      SCGiftVapSvgaManager().bindSvgaCtrl(_svgaController);
    }
  }

  @override
  void dispose() {
    SCGiftVapSvgaManager().dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Stack(
      children: [
        Positioned.fill(
          child: IgnorePointer(
            // VapView可以通过外层包Container(),设置宽高来限制弹出视频的宽高
            // VapView can set the width and height through the outer package Container() to limit the width and height of the pop-up video
            child: VapView(
              scaleType: ScaleType.centerCrop,
              onViewCreated: (controller) {
                if (widget.tag == "room_gift") {
                  SCGiftVapSvgaManager().bindVapCtrl(controller);
                  // VapManager().play("https://res.cloudinary.com/dkmchpua1/video/upload/v1737624783/vcg9co6yyfqsadgety1n.mp4");
                }
              },
            ),
          ),
        ),
        Positioned.fill(child: SVGAImage(_svgaController, fit: BoxFit.fill)),
      ],
    );
  }
}
