import 'package:flyinsono/lab/pages/lab_image/widgets/image_data_player/widgets/lab_vid_player.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'index.dart';

class ImageDataPlayer extends GetView<ImageDataPlayerController> {
  const ImageDataPlayer({
    Key? key,
    required this.initController,
    required this.tabHashCode,
  }) : super(key: key);

  @override
  String? get tag => tabHashCode;

  final String tabHashCode;

  final ImageDataPlayerController initController;

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(
        color: Colors.black,
        borderRadius: BorderRadius.circular(5),
      ),
      child: GetBuilder<ImageDataPlayerController>(
        init: initController,
        tag: tabHashCode,
        id: ImageDataPlayerController.imageDataPlayerId,
        builder: (context) {
          return Stack(
            children: [
              // if (controller.showPreviewImage)
              //   SizedBox.expand(
              //     child: Image.network(
              //       controller.previewImageUrl,
              //       fit: BoxFit.contain,
              //       errorBuilder: (context, error, stackTrace) {
              //         return LabCenterLoading();
              //       },
              //     ),
              //   ),
              if (controller.playerAvailable) ...[
                Center(
                  child: AspectRatio(
                    aspectRatio: controller.currentFrameAspectRatio,
                    child: RepaintBoundary(
                      key: controller.playerKey,
                      child: LabVidPlayer(controller.playerController!),
                    ),
                  ),
                ),
                if (controller.isURMVideoVid && controller.isShowTime)
                  GetBuilder<ImageDataPlayerController>(
                    tag: tabHashCode,
                    id: ImageDataPlayerController.currentTimeId,
                    builder: (_) {
                      return Align(
                        alignment: Alignment.bottomCenter,
                        child: Text(
                          controller.currentTimeString,
                          style: TextStyle(
                            color: Colors.yellow,
                          ),
                        ),
                      );
                    },
                  )
              ],
            ],
          );
        },
      ),
    );
  }
}
