import 'package:flutter/cupertino.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import '../../../../data/bean/upload_info.dart';
import '../../../../resource/assets.gen.dart';
import '../../../../resource/colors.gen.dart';
import '../../../../utils/step_card_util.dart';
import '../../../../utils/upload/upload_scene_type.dart';
import '../../intimacy_analyse_upload/widget/upload_add_widget.dart';
import '../../intimacy_analyse_upload/widget/upload_item_widget.dart';
import '../../intimacy_analyse_upload/widget/upload_nine_grid.dart';
import '../step_card.dart';

/// 上传步骤卡片
class UploadStepCard extends StatelessWidget {
  /// 上传场景类型
  final UploadSceneType sceneType;

  /// 图片资源列表
  final List<UploadInfo> imageUploadInfoList;

  /// 顶部标题区域的组件
  final Widget? topTitleWidget;

  /// 底部的子组件，可以没有
  final Widget? bottomChild;

  /// 点击上传按钮的回调
  final OnClickAddCallback? onClickAddCallback;

  /// 点击删除时回调
  final OnClickDeleteCallback? onClickDeleteCallback;

  const UploadStepCard({
    super.key,
    required this.sceneType,
    required this.imageUploadInfoList,
    this.topTitleWidget,
    this.bottomChild,
    this.onClickAddCallback,
    this.onClickDeleteCallback,
  });

  @override
  Widget build(BuildContext context) {
    Mode mode = Mode.edit;
    return StepCard(
      // 背景图片
      bgImageProvider: StepCardUtil.getCardBgImageProvider(
        itemCount: imageUploadInfoList.length,
        sceneType: sceneType,
        mode: mode,
      ),
      // 顶部的标题
      topTitleWidget: topTitleWidget,
      // 顶部的图标
      topIconWidget: Assets.images.iconIntimacyAnalyseUploadTop.image(
        height: 63.h,
        width: 103.w,
      ),
      // 顶部图标的位置
      topIconWidgetLocation: StepCardUtil.calculateTopIconWidgetLocation(
        itemCount: imageUploadInfoList.length,
        sceneType: sceneType,
        mode: mode,
      ),
      contentWidget: Column(
        children: [
          SizedBox(height: 14.h),
          // 图片九宫格
          Container(
            margin: EdgeInsets.only(left: 12.w, right: 12.w),
            padding: EdgeInsets.only(
              left: 12.w,
              top: 12.h,
              right: 12.w,
              bottom: 12.h,
            ),
            decoration: BoxDecoration(
              color: ColorName.white,
              borderRadius: BorderRadius.circular(16.r),
            ),
            // 图片九宫格
            child: UploadNineGrid(
              mode: mode,
              imageUploadInfoList: imageUploadInfoList,
              spacing: 8.0,
              onClickAddCallback: onClickAddCallback,
              onClickDeleteCallback: onClickDeleteCallback,
            ),
          ),
          SizedBox(height: 10.h),
          // 当前的亲密关系
          bottomChild ?? SizedBox(),
        ],
      ),
    );
  }
}
