import 'dart:math';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:worker_client/widgets/MyCard/entities/ItemColor.dart';

class Jianbian extends StatelessWidget {
  Jianbian({Key? key, this.type, required this.status, this.value, this.ptop})
      : super(key: key);

  final String? type;
  final dynamic status;
  final dynamic? value;
  final double? ptop;

  List<ItemColor> colors = [
    ItemColor(const Color(0xFFC7C7C7), const Color(0xFF8F8F8F),
        const Color(0xFFC0C0C0)),
    ItemColor(const Color(0xFFFFC937), const Color(0xFFFFAB8C),
        const Color(0xFFFF703B)),
    ItemColor(const Color(0xFF06B03B), const Color(0xFF00AE39),
        const Color(0xFFA0E067)),
  ];

  String Title() {
    return type == 'machinery'
        ? (status == 0
            ? '维修中'
            : (value == null || value == 3)
                ? '空闲中'
                : '使用中')
        : (status == 0
            ? '待作业'
            : status == 1 || status == 2
                ? '进行中'
                : status == 3
                    ? '已完成'
                    : '');
  }

  ItemColor CurrentColor() {
    return type == 'machinery'
        //是农机列表卡片？？要改
        ? (status == 0
            ? colors[0]
            : (value == null || value == 3)
                ? colors[1]
                : colors[2])
        : (status == 0
            ? colors[1]
            : status == 1 || status == 2
                ? colors[2]
                : status == 3
                    ? colors[0]
                    : colors[0]);
  }

  @override
  Widget build(BuildContext context) {
    return Positioned(
      top: ptop == null ? -61.w : ptop! - 61.w,
      left: -67.w,
      child: Transform.rotate(
        angle: pi / 6,
        child: Container(
          width: 112.5.w,
          height: 108.5.w,
          decoration: BoxDecoration(
            borderRadius: BorderRadius.all(Radius.circular(68.5.w)),
            border: Border.all(
                width: 1.w,
                color: CurrentColor().borderColor,
                style: BorderStyle.solid),
            gradient: LinearGradient(
              colors: [
                CurrentColor().rightColor,
                CurrentColor().leftColor,
              ],
            ),
          ),
          child: Transform.rotate(
            angle: -pi / 2.3,
            child: Transform.translate(
              offset: Offset(38.w, 85.w),
              child: Text(
                Title(),
                style: TextStyle(
                    fontSize: 14.sp,
                    fontWeight: FontWeight.bold,
                    color: const Color(0xffffffff)),
              ),
            ),
          ),
        ),
      ),
    );
  }
}
