import 'dart:async';
import 'dart:ui';

import 'package:design/design.dart';
import 'package:example/pages/root/root_view.dart';
import 'package:example/pages/root/watermark.dart';
import 'package:get/get.dart';
import 'package:guru_utils/controller/base_controller.dart';
import 'package:guru_utils/controller/lifecycle_controller.dart';
import 'package:guru_utils/extensions/extensions.dart';
import 'package:guru_widgets/sliderbar/guru_slider_bar.dart';
import 'package:guru_widgets/overlay/guru_asset_controller.dart';
import 'package:guru_popup/guru_popup.dart';

import 'root_model.dart';

class RootController extends GuruAssetOverlayController {
  final GlobalKey key = GlobalKey();
  RootDesignSpec get designSpec => RootDesignSpec.get();
  final BehaviorSubject<int> focusPageSubject = BehaviorSubject.seeded(0);
  final BehaviorSubject<bool> showLabels = BehaviorSubject.seeded(false);
  final GuruSliderBarController sliderbarController = GuruSliderBarController(isAnimating: false);

  Stream<int> get observablePage => focusPageSubject.stream;

  Stream<bool> get observableShowLabels => showLabels.stream;

  void updatePageIndex(int page) {
    focusPageSubject.addEx(page);
  }

  void updateShowLabels() {
    final bool value = showLabels.value;
    showLabels.addEx(!value);
  }

  void showAssetsOverlay() {
    
  }

  void showWaterMarkOverlay(){
    final watermarkOverlay = Completer();
    final navigatorState = Navigator.of(Get.overlayContext!, rootNavigator: false);
    final overlayState = navigatorState.overlay!;

    final overlayEntry = OverlayEntry(
      builder: (BuildContext context) => const Material(
          child: WaterMarkWidget(packageName: 'guru.core.uiux.demo')));

    watermarkOverlay.future.then((params) {
      overlayEntry.remove();
    }).whenComplete(() {
      
    }).catchError((error) {
     
    });
    overlayState.insert(overlayEntry);

    Future.delayed(const Duration(milliseconds: 3000), () {
      watermarkOverlay.complete();
    });
  }

  @override
  void onReady() {
    super.onReady();
    sliderbarController.addListener(() {
      print(sliderbarController.data);
    });
  }

  @override
  void onClose() {
    // TODO: implement onClose
    super.onClose();
  }
}
