import 'package:fcs/helpers/theme.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

import 'callbacks.dart';

class FcsExpansionTile extends StatefulWidget {
  final ValueChanged<bool> onExpansionChanged;
  final CallBack onEditPress;
  final List<Widget> children;
  final Widget title;
  final bool isEdit;
  const FcsExpansionTile(
      {this.onExpansionChanged,
      this.children,
      this.title,
      this.isEdit = false,
      this.onEditPress});
  @override
  _FcsExpansionTileState createState() => _FcsExpansionTileState();
}

class _FcsExpansionTileState extends State<FcsExpansionTile> {
  bool expanded;
  @override
  void initState() {
    this.expanded = false;
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Theme(
      data: ThemeData(
          accentColor: primaryColor, dividerColor: Colors.transparent),
      child: ExpansionTile(
        onExpansionChanged: (value) {
          setState(() {
            expanded = value;
          });
          if (widget.onExpansionChanged != null)
            widget.onExpansionChanged(value);
        },
        title: widget.title,
        children: widget.children,
        trailing: widget.isEdit
            ? IconButton(
                padding: EdgeInsets.all(0),
                iconSize: 20,
                onPressed: () =>
                    widget.onEditPress != null ? widget.onEditPress() : {},
                icon: Icon(
                  Icons.edit,
                  color: primaryColor,
                ))
            : AnimatedSwitcher(
                child: expanded
                    ? Icon(
                        Icons.remove,
                        color: primaryColor,
                      )
                    : Icon(
                        Icons.add,
                        color: primaryColor,
                      ),
                duration: Duration(seconds: 2)),
        childrenPadding: EdgeInsets.all(18),
      ),
    );
  }
}
