import 'package:Capsule/components/custom_circle_avatar.dart';
import 'package:Capsule/models/friends.dart';
import 'package:flutter/material.dart';

class ConversationAddFriendItem extends StatefulWidget{
  final Friend friend;
  final ValueChanged<bool> isSelected;
  const ConversationAddFriendItem({
    Key? key,
    required this.friend,
    required this.isSelected,
  }) : super(key: key);

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

class _ConversationAddFriendItemState extends State<ConversationAddFriendItem> {
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
        behavior: HitTestBehavior.opaque,
        onTap: () async {
          setState(() {
            widget.friend.selected = !(widget.friend.selected ?? false);
            widget.isSelected(widget.friend.selected ?? false);
          });
        },
        child: Container(
           padding: const EdgeInsets.only(left: 16,right: 16,top: 10,bottom: 10),
           child: Row(
               children: <Widget>[
                 Expanded(
                     child: Row(
                         children: <Widget>[
                           CustomCircleAvatar(
                               initials: widget.friend.username[0].toUpperCase(),
                           ),
                           const SizedBox(width: 16),
                           Expanded(
                               child: Align(
                                   alignment: Alignment.centerLeft,
                                   child: Container(
                                       color: Colors.transparent,
                                       child: Column(
                                           crossAxisAlignment: CrossAxisAlignment.start,
                                           children: <Widget>[
                                             Text(
                                                 widget.friend.username,
                                                 style: const TextStyle(
                                                     fontSize: 16
                                                 )
                                             ),
                                           ],
                                       ),
                                   ),
                               ),
                           ),
                           (widget.friend.selected ?? false)
                               ? Align(
                                   alignment: Alignment.centerRight,
                                   child: Icon(
                                       Icons.check_circle,
                                       color: Theme.of(context).colorScheme.primary,
                                       size: 36,
                                   ),
                               )
                               : Padding(
                                   padding: const EdgeInsets.only(right: 3),
                                   child: Container(
                                       width: 30,
                                       height: 30,
                                       decoration: BoxDecoration(
                                           border: Border.all(
                                               color: Theme.of(context).colorScheme.primary,
                                               width: 2,
                                           ),
                                           borderRadius: const BorderRadius.all(Radius.circular(100))
                                       ),
                                   )
                               ),
                        ],
                      ),
                  ),
              ],
          ),
      ),
    );
  }
}
