import 'package:fis_ui/index.dart';
import 'package:flutter/material.dart';
import 'package:flyinsono/pages/remote_controller/widgets/remote_controller_parameters/remote_controller_parameters_styles.dart';

class FExpandableContainer extends StatefulWidget implements FWidget {
  final Widget child;
  final String headerTitle;
  FExpandableContainer({required this.headerTitle, required this.child});

  @override
  _FExpandableContainerState createState() => _FExpandableContainerState();
}

class _FExpandableContainerState extends State<FExpandableContainer> {
  bool isExpanded = true;

  @override
  Widget build(BuildContext context) {
    return Theme(
      data: ThemeData(
        brightness: Brightness.dark,
      ),
      child: ExpansionPanelList(
        expandedHeaderPadding: EdgeInsets.symmetric(vertical: 5),
        expansionCallback: (int index, bool isExpanded) {
          setState(() {
            this.isExpanded = !this.isExpanded;
          });
        },
        children: [
          ExpansionPanel(
            backgroundColor: TuningParametersStyles.backgroundColor,
            canTapOnHeader: true,
            headerBuilder: (BuildContext context, bool isExpanded) {
              return Container(
                alignment: Alignment.centerLeft,
                padding: EdgeInsets.symmetric(horizontal: 16),
                height: 30,
                child: Text(
                  widget.headerTitle,
                  style: TextStyle(
                    fontWeight: FontWeight.bold,
                    fontSize: 16,
                    color: Colors.white,
                  ),
                ),
              );
            },
            body: widget.child,
            isExpanded: isExpanded,
          ),
        ],
      ),
    );
  }
}
