import 'dart:math';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:worker_client/models/entities/Job.dart';
import 'package:worker_client/widgets/Jianbian/index.dart';
import 'package:worker_client/widgets/MyButton/index.dart';
import 'package:worker_client/widgets/MyCard/entities/ItemColor.dart';
import 'package:worker_client/widgets/MyCard/widgets/CardCell.dart';

class MyCard extends StatelessWidget {
  final dynamic item;
  final String? type;
  final String? value;
  final String buttomText;
  final bool job;
  final bool detail;
  final GestureTapCallback onClick;
  final GestureTapCallback? goDetail;
  const MyCard(
      {Key? key,
      required this.item,
      this.type,
      this.value,
      required this.job,
      required this.detail,
      required this.onClick,
      required this.buttomText,
      this.goDetail})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.fromLTRB(0, 7.5.w, 0, 7.5.w),
      clipBehavior: Clip.hardEdge,
      width: 345.w,
      decoration: BoxDecoration(
        color: Colors.white,
        boxShadow: [
          BoxShadow(
              color: const Color(0x24000000),
              offset: const Offset(0, 0),
              blurRadius: 22.w)
        ],
        borderRadius: BorderRadius.all(Radius.circular(20.w)),
      ),
      child: Stack(
        children: [
          Jianbian(status: job?item.status:item.workStatus),
          Container(
            padding: EdgeInsets.all(20.w),
            child: Column(
              children: [
                Container(
                  padding: EdgeInsets.fromLTRB(19.w, 9.w, 0, 9.w),
                  child: Row(
                    children: [
                      SizedBox(
                        width: 70,
                        child: Text(
                          '需求时间',
                          style: TextStyle(
                              fontSize: 17.sp,
                              color: const Color(0xFF606060),
                              fontWeight: FontWeight.bold,
                              letterSpacing: 2),
                        ),
                      ),
                      Text(
                        '：',
                        style: TextStyle(
                          fontSize: 17.sp,
                          color: const Color(0xFF606060),
                          fontWeight: FontWeight.bold,
                        ),
                      ),
                      Expanded(
                        flex: 1,
                        child: Text(
                          item.appointmentDate != null
                              ? item.appointmentDate.toString().substring(0, 10)
                              : '',
                          style: TextStyle(
                              fontSize: 17.sp,
                              color: Color(0xFF101010),
                              fontWeight: FontWeight.bold),
                        ),
                      ),
                      Visibility(
                        child: GestureDetector(
                          onTap: goDetail,
                          child: Container(
                            margin: EdgeInsets.fromLTRB(0, 0, 7.5.w, 0),
                            child: Text(
                              '详情>>',
                              style: TextStyle(
                                  fontSize: 17.sp,
                                  fontWeight: FontWeight.bold,
                                  color: Color(0xFF606060)),
                            ),
                          ),
                        ),
                        visible: job && !detail,
                      )
                    ],
                  ),
                ),
                Divider(
                  color: Color(0xE5000000),
                  height: 30.h,
                  thickness: 0.5.w,
                ),
                CardCell(
                    lable: '订单号', content: item.orderNo.toString(), size: 8.6),
                Visibility(
                  child: CardCell(
                      lable: '农机名称',
                      content: item.machineryName.toString(),
                      size: 2),
                  visible: job,
                ),
                Visibility(
                  child: CardCell(
                      lable: '农机类型',
                      content:
                          (item is Job ? item.machineryTypeName : item.typeName)
                              .toString(),
                      size: 2),
                  visible: !job,
                ),
                CardCell(
                    lable: '下单人',
                    content: (item.personName ?? ' ').toString(),
                    size: 8.6),
                CardCell(
                    lable: '手机号', content: item.phone.toString(), size: 8.6),
                CardCell(
                    lable: '订单时间',
                    content: item.createDate != null
                        ? item.createDate.toString().substring(0, 10)
                        : '',
                    size: 2),
                Visibility(
                    child: CardCell(
                        lable: '服务地址',
                        content: item.address.toString(),
                        size: 2),
                    visible: detail),
                Visibility(
                    child: CardCell(
                        lable: '作业时间',
                        content:  item is Job ? item.startDate.toString() : '' +
                            (item is Job ? (item?.endDate != null
                            ? '\n' + item.endDate.toString()
                            : '') : ''),
                        size: 2),
                    visible: job),
                CardCell(
                    lable: '订单费用',
                    content: ((item.charges ?? 0) / 100).toString(),
                    size: 2),
                Visibility(
                  visible: job && item.status != 3,
                  child: MyButton(
                      text: buttomText,
                      type: item.status ?? 0,
                      disable: false,
                      onClick: onClick),
                ),
                Visibility(
                  child: Divider(
                    color: Color(0xE5000000),
                    height: 30.h,
                    thickness: 0.5.w,
                  ),
                  visible: !job && !detail,
                ),
                Visibility(
                  child: GestureDetector(
                    onTap: goDetail,
                    child: Container(
                      alignment: Alignment.center,
                      width: 345.w,
                      padding: EdgeInsets.fromLTRB(0, 12.5.h, 0, 0),
                      child: const Text(
                        '详情>>',
                        style: TextStyle(
                          fontWeight: FontWeight.bold,
                          color: Color(0xFF606060),
                        ),
                      ),
                    ),
                  ),
                  visible: !job && !detail,
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}
