import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:rasadyar_core/core.dart';
import 'draggable_bottom_sheet.dart';

/*class DraggableBottomSheetController extends GetxController {
  final RxList<DraggableBottomSheet> bottomSheets =
      <DraggableBottomSheet>[].obs;

  // Observable variables
  final RxBool isVisible = false.obs;
  final RxDouble currentHeight = 200.0.obs;

  // Configuration values
  final double initialHeight;
  final double minHeight;
  final double maxHeight;

  DraggableBottomSheetController({
    bool initialVisibility = false,
    this.initialHeight = 200,
    this.minHeight = 0,
    this.maxHeight = 700,
  }) {
    isVisible.value = initialVisibility;
    currentHeight.value = initialHeight;
  }

  // Show the bottom sheet
  void show() {
    if (!isVisible.value) {
      isVisible.value = true;
      currentHeight.value = initialHeight;
    }
  }

  // Hide the bottom sheet
  void hide() {
    if (isVisible.value) {
      isVisible.value = false;
    }
  }

  // Toggle visibility
  void toggle() {
    isVisible.value = !isVisible.value;
    if (isVisible.value) {
      currentHeight.value = initialHeight;
    }
  }

  // Set a specific height for the bottom sheet
  void setHeight(double height) {
    final clampedHeight = height.clamp(minHeight, maxHeight);
    if (currentHeight.value != clampedHeight) {
      currentHeight.value = clampedHeight;
    }
  }

  void updateHeight(double? delta) {
    if (delta == null) return;
    final newHeight = (currentHeight.value - delta).clamp(minHeight, maxHeight);

    if (newHeight <= minHeight) {
      toggle();
    } else {
      currentHeight.value = newHeight;
    }
  }

  // Expand to maximum height
  void expandFully() {
    currentHeight.value = maxHeight;
    isVisible.value = true;
  }

  // Collapse to minimum height
  void collapse() {
    currentHeight.value = minHeight;
  }

  void addBottomSheet({
    required Widget child,
    required double initHeight,
    required double maxHeight,
    required double minHeight,
  }) {
    final controller = DraggableBottomSheetController(
      initialVisibility: true,
      initialHeight: initHeight,
      minHeight: minHeight,
      maxHeight: maxHeight,
    );

    final bottomSheet = DraggableBottomSheet(
      controller: controller,
      backgroundColor: AppColor.lightGreyLightActive,
      child: child,
    );
    if (bottomSheets.isNotEmpty) {
      bottomSheets.removeLast();
    }

    bottomSheets.add(bottomSheet);
  }

  void removeLastBottomSheet() {
    if (bottomSheets.isNotEmpty) {
      bottomSheets.last.controller?.hide();
      Future.delayed(Duration(milliseconds: 200), () {
        bottomSheets.removeLast();
        if(bottomSheets.isNotEmpty){
          bottomSheets.last.controller?.show();
        }

      });
    }
  }
 bool get handleBack{
  if (bottomSheets.isNotEmpty) {
  removeLastBottomSheet();
  return true;
  }
  return false;
  }

}*/

class DraggableBottomSheetController extends GetxController {
  final RxBool isVisible = false.obs;
  final RxDouble currentHeight = 200.0.obs;
  RxList<Widget> items = <Widget>[].obs;
  RxInt currentIndex = 0.obs;
  late double initialHeight;
  late double minHeight;
  late double maxHeight;

  DraggableBottomSheetController({
    this.initialHeight = 200,
    this.minHeight = 100,
    this.maxHeight = 700,
  }) {
    currentHeight.value = initialHeight;
  }

  void show() => isVisible.value = true;

  void hide() => isVisible.value = false;

  void toggle() => isVisible.value = !isVisible.value;

  void updateHeight(double? delta) {
    if (delta == null) return;
    final newHeight = (currentHeight.value - delta).clamp(minHeight, maxHeight);
    if (newHeight <= minHeight) {
      hide();
    } else {
      currentHeight.value = newHeight;
    }
  }


}
