import 'package:flutter/material.dart';
import 'package:syncrow_web/common/widgets/custom_expansion_tile.dart';

class SpaceTile extends StatefulWidget {
  final String title;
  final bool isSelected;
  final bool initiallyExpanded;
  final ValueChanged<bool> onExpansionChanged;
  final List<Widget>? children;
  final void Function() onItemSelected;

  const SpaceTile({
    super.key,
    required this.title,
    required this.initiallyExpanded,
    required this.onExpansionChanged,
    required this.onItemSelected,
    required this.isSelected,
    this.children,
  });

  @override
  State<SpaceTile> createState() => _SpaceTileState();
}

class _SpaceTileState extends State<SpaceTile> {
  late bool _isExpanded;

  @override
  void initState() {
    super.initState();
    _isExpanded = widget.initiallyExpanded;
  }

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.only(left: 8.0, right: 8.0, top: 8.0),
      child: CustomExpansionTile(
        isSelected: widget.isSelected,
        title: widget.title,
        initiallyExpanded: _isExpanded,
        onItemSelected: widget.onItemSelected,
        onExpansionChanged: (bool expanded) {
          setState(() {
            _isExpanded = expanded;
          });
          widget.onExpansionChanged(expanded);
        },
        children: widget.children ?? [],
      ),
    );
  }
}
