import 'package:cpt_community/components/comments_dialog.dart';
import 'package:cs_resources/theme/app_colors_theme.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:widgets/ext/ex_widget.dart';
import 'package:widgets/my_button.dart';
import 'package:widgets/my_load_image.dart';
import 'package:widgets/my_text_view.dart';

enum MyFollowingType {
  isFollowType,
  isFollowerType,
}

class MyFollowingListItem extends StatelessWidget {
  final MyFollowingType? itemType;
  bool? hasBottomDriver = true;
  Map<String, dynamic> itemObj;
  void Function(dynamic)? onClickAction;
  MyFollowingListItem({
    super.key,
    required this.itemObj,
    this.itemType = MyFollowingType.isFollowType,
    this.hasBottomDriver=true,
    this.onClickAction
  });

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        Container(
          margin: const EdgeInsets.only(left: 15,right: 15,top: 15,bottom: 15),
          child: Row(
            mainAxisSize: MainAxisSize.max,
            children: [
              Expanded(
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.start,
                  children: [
                    MyLoadImage(
                      'https://img1.baidu.com/it/u=2743394743,692629981&fm=253&fmt=auto&app=120&f=JPEG?w=800&h=800',
                      width: 65,
                      height: 65,
                      isCircle: true,
                    ),
                    MyTextView(
                      'Chin Lan',
                      fontSize: 17,
                      isFontMedium: true,
                      marginLeft: 17,
                    )
                  ],
                ).onTap((){
                  // onClickAction?.call(itemObj);
                }),
              ),
              // _buildIsFollowButton(context),
              HookConsumer(
                builder: (context, ref, child) {
                  final isFollow = useState(itemObj['isFollow']);
                  return (!isFollow.value)? MyButton(
                    text:'+Follow',
                    onPressed: (){
                      // todo 调用接口 然后更新状态
                      isFollow.value = !isFollow.value;
                    },
                    textColor: context.appColors.textWhite,
                    backgroundColor: context.appColors.textPrimary,
                    fontSize: 14,
                    fontWeight: FontWeight.w400,
                    minWidth: 67.5,
                    minHeight: 30.5,
                  ): const SizedBox.shrink();
                },
              )

            ],
          ),
        ),
        if(hasBottomDriver!)
          Container(
            height: 1,
            color: context.appColors.dividerDefault,
          )
      ],
    );
  }
}