import 'package:flutter/material.dart';
import 'package:get/get.dart';

import 'draggable_bottom_sheet_controller.dart';


class DraggableBottomSheet2 extends GetView<DraggableBottomSheetController> {
  final Color? backgroundColor;

  const DraggableBottomSheet2({super.key, this.backgroundColor = Colors.white});

  @override
  Widget build(BuildContext context) {
    WidgetsBinding.instance.addPostFrameCallback((_) {
      if (controller.isVisible.value && !controller.isVisible.value) {
        controller.show();
      }
    });

    return ObxValue((data) {
      return Stack(
        children: [
          Positioned.fill(
            child: GestureDetector(
              onTap: () {},
              child: Container(color: Colors.black54),
            ),
          ),
          // محتوای BottomSheet
          AnimatedPositioned(
            duration: Duration(milliseconds: 300),
            curve: Curves.easeOut,
            left: 0,
            right: 0,
            bottom: 0,
            child: GestureDetector(
              onVerticalDragUpdate: (details) {
                controller.updateHeight(details.primaryDelta);
              },
              child: Container(
                height: 350,
                decoration: BoxDecoration(
                  color: backgroundColor,
                  borderRadius: BorderRadius.vertical(top: Radius.circular(20)),
                  boxShadow: [
                    BoxShadow(
                      color: Colors.black.withValues(alpha: 0.1),
                      blurRadius: 10,
                    ),
                  ],
                ),
                child: Column(
                  children: [
                    GestureDetector(
                      onTap: () {},
                      child: Container(
                        padding: EdgeInsets.all(10),
                        child: Icon(Icons.drag_handle),
                      ),
                    ),
                    Expanded(
                      child: controller.items[data.value],
                    ),
                  ],
                ),
              ),
            ),
          ),
        ],
      );
    }, controller.currentIndex);
  }
}
