import 'package:flutter/material.dart';
import 'package:fis_theme/theme.dart';
import 'package:fis_ui/index.dart';

class FExpansionPanel extends FStatefulWidget {
  final String title;

  final FWidget body;

  FExpansionPanel({required this.title, required this.body});

  @override
  FState<FStatefulWidget> createState() {
    return FExpansionPanelState();
  }
}

class FExpansionPanelState extends FState<FExpansionPanel> {
  bool _isExpand = true;

  @override
  FWidget build(BuildContext context) {
    return FColumn(
      mainAxisAlignment: MainAxisAlignment.start,
      children: [
        FInkWell(
          onTap: () {
            setState(() {
              _isExpand = !_isExpand;
            });
          },
          child: FContainer(
            margin: EdgeInsets.symmetric(vertical: 5, horizontal: 5),
            decoration: BoxDecoration(
              borderRadius: BorderRadius.circular(4),
              color: FTheme.ins.colorScheme.secondary,
            ),
            child: FRow(
              children: [
                const FSizedBox(
                  width: 5,
                ),
                FIcon(
                  _isExpand ? Icons.arrow_circle_down : Icons.arrow_circle_up,
                  color: Colors.black54,
                ),
                const FSizedBox(
                  width: 10,
                ),
                FText(widget.title),
              ],
            ),
          ),
        ),
        if (_isExpand)
          FContainer(
            margin: EdgeInsets.symmetric(horizontal: 5),
            child: widget.body,
          ),
      ],
    );
  }
}
