import 'package:cs_resources/theme/app_colors_theme.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:shared/utils/color_utils.dart';
import 'package:shared/utils/log_utils.dart';
import 'package:widgets/utils/dark_theme_util.dart';

import '../../../components/garage_card.dart';
import 'my_posts_sale_rent_item_vm.dart';

class MyPostsSaleRentItem extends HookConsumerWidget {
  MyPostsSaleRentItem({Key? key, required this.item, required this.garageSaleType}) : super(key: key);

  String garageSaleType = 'forSale';
  final Map<String, dynamic> item;

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    final vm = ref.read(myPostsSaleRentItemVmProvider.notifier);
    return SizedBox(
      width: double.infinity,
      child: Container(
        decoration: BoxDecoration(
          color: context.appColors.whiteBG,
          borderRadius: BorderRadius.circular(8),
          boxShadow: [
            BoxShadow(
              color: DarkThemeUtil.multiColors(context, ColorUtils.string2Color('#E5E5E5'), darkColor: Colors.transparent)?? Colors.transparent,
              offset: const Offset(0, 2),
              blurRadius: 8,
            ),
          ],
        ),
        child: Column(
            mainAxisAlignment: MainAxisAlignment.start,
            crossAxisAlignment: CrossAxisAlignment.start,
            mainAxisSize: MainAxisSize.max,
            children: [
              Expanded(
                child: GarageCard(
                    key: UniqueKey(),
                    useType: GarageCardUseType.myPostsForRent,
                    itemObj: item,
                    onClickColleciotn: (dynamic collectionValue) async {
                      Log.d("my_posts_sale_rent_item 点击了喜欢按钮  --${item['id']}-$collectionValue");
                      bool asyncResult = await vm.handlerGarageClickLike(item['id'], collectionValue);
                      if(asyncResult){
                        return true;
                      }else {
                        return false;
                      }
                    }
                ),
              ),
            ]
        ),
      ),
    );
  }
}