import 'package:dotted_border/dotted_border.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:keyboard/resource/colors.gen.dart';

import '../../../../resource/assets.gen.dart';
import '../../../../resource/string.gen.dart';
import '../../../../utils/string_format_util.dart';

/// 点击添加回调
typedef OnClickAddCallback = void Function();

/// 添加上传项组件
class UploadAddWidget extends StatelessWidget {
  /// 还可以上传多少个文件
  final int residueCount;

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

  const UploadAddWidget({
    super.key,
    required this.residueCount,
    this.onClickAddCallback,
  });

  @override
  Widget build(BuildContext context) {
    return Container(
      alignment: Alignment.center,
      child: GestureDetector(
        onTap: onClickAddCallback,
        child: DottedBorder(
          // 虚线颜色
          color: ColorName.uploadAddDottedBorder,
          // 线条宽度
          strokeWidth: 1.0.w,
          // 圆角矩形，要使用 RRect 类型，才能有效
          borderType: BorderType.RRect,
          // 圆角半径
          radius: Radius.circular(12.r),
          child: SizedBox(
            // 宽度和高度，都撑满父组件
            width: double.maxFinite,
            height: double.maxFinite,
            child: Column(
              // 文字和图标都居中
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                // 上传图标
                Assets.images.iconUploadAddSymbol.image(
                  width: 23.w,
                  height: 23.w,
                ),
                // 还可以上传多少个文件
                Text(
                  StringFormatUtil.formatStr(
                    StringName.intimacyAnalyseUploadLimitTip,
                    residueCount.toString(),
                  ),
                  style: TextStyle(
                    color: ColorName.uploadAddText,
                    fontSize: 12.sp,
                    fontWeight: FontWeight.w400,
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}
