import 'package:flutter/material.dart';
import 'package:gz_video_player/video_control_bar_style.dart';
import 'package:gz_video_player/video_top_bar_style.dart';

class VideoTopBar extends AnimatedWidget {
  VideoTopBar({
    Key? key,
    required this.animation,
    VideoControlBarStyle? videoControlBarStyle,
    VideoTopBarStyle? videoTopBarStyle,
    this.onPop,
  })  : videoTopBarStyle = videoTopBarStyle ?? VideoTopBarStyle(),
        videoControlBarStyle = videoControlBarStyle ?? VideoControlBarStyle(),
        super(key: key, listenable: animation);

  final VideoTopBarStyle videoTopBarStyle;
  final VideoControlBarStyle videoControlBarStyle;
  final VoidCallback? onPop;
  final Animation<double> animation;

  @override
  Widget build(BuildContext context) {
    // final Animation<double> animation = listenable;
    if (videoTopBarStyle.customBar == null) {
      return Positioned(
        top: animation.value,
        left: 0,
        right: 0,
        // alignment: Alignment.topLeft,
        child: Container(
          margin: videoTopBarStyle.margin,
          padding: videoTopBarStyle.padding,
          height: videoTopBarStyle.height,
          decoration: BoxDecoration(
              gradient: LinearGradient(
                colors: [
                  videoControlBarStyle.barBackgroundColor,
                  Colors.transparent
                ],
                begin: Alignment.topCenter,
                end: Alignment.bottomCenter,
              )),
          child: Row(
            crossAxisAlignment: CrossAxisAlignment.center,
            children: <Widget>[
              /// 返回按钮
              GestureDetector(
                behavior: HitTestBehavior.translucent,
                onTap: onPop,
                child: videoTopBarStyle.popIcon,
              ),

              /// 中部控制栏
              Expanded(
                child: Row(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: videoTopBarStyle.contents,
                ),
              ),

              /// 右侧部控制栏
              Row(
                crossAxisAlignment: CrossAxisAlignment.center,
                children: videoTopBarStyle.actions,
              )
            ],
          ),
        ),
      );
    }
    else {
      return videoTopBarStyle.customBar!;
    }
  }
}
