import 'package:flutter/material.dart';

class OrderConstant {
  // 用户的订单菜单栏
  static const List<dynamic> userOrderType = [
    {"name": "全部", "value": "USER_ALL"},
    {"name": "待付款", "value": "TO_PAY"},
    {"name": "待确认", "value": "USER_TO_SURE"},
    {"name": "待评价", "value": "TO_EVA"},
    {"name": "申诉", "value": "TO_APPEAL"}
  ];

  // 专家订单菜单栏
  static const List<dynamic> expertOrderType = [
    {"name": "全部", "value": "CHARGE_ALL"},
    {"name": "待报价", "value": "TO_OFFER"},
    {"name": "待打卡", "value": "TO_CLOCK"},
    {"name": "待确认", "value": "CHARGE_TO_SURE"},
    {"name": "待归档", "value": "TO_ARCHIVE"}
  ];

  // 问诊状态
  // showUserAppealInfo 是否显示申诉信息
  // showUserPaymentButton 是否显示立即付款按钮
  // showUserConfirmPunchButton 是否显示确认打卡按钮
  // showUserAppealButton 是否显示提出申诉按钮
  // showUserConfirmOrderButton 是否显示确认订单按钮
  // showUserEvaluationButton 是否显示评价按钮
  // showUserChooseExpertButton 是否显示重新选择专家按钮
  // showExpertQuoteButton 是否显示立即报价按钮
  // showExpertPunchButton 是否显示立即打卡按钮
  // showExpertConfirmOrderButton 是否显示专家确认按钮
  // showExpertArchiveButton 是否显示归档按钮
  static const List<dynamic> inquiryStatus = [
    {
      "id": 0,
      "name": "待付款",
      "desc": "待付款(创建订单)",
      "showUserAppealInfo": false,
      "showUserPaymentButton": true,
      "showUserConfirmPunchButton": false,
      "showUserAppealButton": false,
      "showUserConfirmOrderButton": false,
      "showUserEvaluationButton": false,
      "showUserChooseExpertButton": false,
      "showExpertQuoteButton": false,
      "showExpertPunchButton": false,
      "showExpertConfirmOrderButton": false,
      "showExpertArchiveButton": false
    },
    {
      "id": 1,
      "name": "待接单",
      "desc": "已付款(待接单)",
      "showUserAppealInfo": false,
      "showUserPaymentButton": false,
      "showUserConfirmPunchButton": false,
      "showUserAppealButton": false,
      "showUserConfirmOrderButton": false,
      "showUserEvaluationButton": false,
      "showUserChooseExpertButton": false,
      "showExpertQuoteButton": false,
      "showExpertPunchButton": false,
      "showExpertConfirmOrderButton": false,
      "showExpertArchiveButton": false
    },
    {
      "id": 2,
      "name": "已接单",
      "desc": "已接单",
      "showUserAppealInfo": false,
      "showUserPaymentButton": false,
      "showUserConfirmPunchButton": false,
      "showUserAppealButton": false,
      "showUserConfirmOrderButton": false,
      "showUserEvaluationButton": false,
      "showUserChooseExpertButton": false,
      "showExpertQuoteButton": false,
      "showExpertPunchButton": false,
      "showExpertConfirmOrderButton": true,
      "showExpertArchiveButton": false
    },
    {
      "id": 3,
      "name": "用户待确认",
      "desc": "用户待确认,专家确认完成",
      "showUserAppealInfo": false,
      "showUserPaymentButton": false,
      "showUserConfirmPunchButton": false,
      "showUserAppealButton": true,
      "showUserConfirmOrderButton": true,
      "showUserEvaluationButton": false,
      "showUserChooseExpertButton": false,
      "showExpertQuoteButton": false,
      "showExpertPunchButton": false,
      "showExpertConfirmOrderButton": false,
      "showExpertArchiveButton": false
    },
    {
      "id": 4,
      "name": "待评价",
      "desc": "用户确认完成,待评价",
      "showUserAppealInfo": false,
      "showUserPaymentButton": false,
      "showUserConfirmPunchButton": false,
      "showUserAppealButton": false,
      "showUserConfirmOrderButton": false,
      "showUserEvaluationButton": true,
      "showUserChooseExpertButton": false,
      "showExpertQuoteButton": false,
      "showExpertPunchButton": false,
      "showExpertConfirmOrderButton": false,
      "showExpertArchiveButton": false
    },
    {
      "id": 5,
      "name": "待归档",
      "desc": "待归档,已评价",
      "showUserAppealInfo": false,
      "showUserPaymentButton": false,
      "showUserConfirmPunchButton": false,
      "showUserAppealButton": false,
      "showUserConfirmOrderButton": false,
      "showUserEvaluationButton": false,
      "showUserChooseExpertButton": false,
      "showExpertQuoteButton": false,
      "showExpertPunchButton": false,
      "showExpertConfirmOrderButton": false,
      "showExpertArchiveButton": true
    },
    {
      "id": 6,
      "name": "已完成",
      "desc": "已完成",
      "showUserAppealInfo": false,
      "showUserPaymentButton": false,
      "showUserConfirmPunchButton": false,
      "showUserAppealButton": false,
      "showUserConfirmOrderButton": false,
      "showUserEvaluationButton": false,
      "showUserChooseExpertButton": false,
      "showExpertQuoteButton": false,
      "showExpertPunchButton": false,
      "showExpertConfirmOrderButton": false,
      "showExpertArchiveButton": false
    },
    {
      "id": 7,
      "name": "申诉中",
      "desc": "申诉中",
      "showUserAppealInfo": true,
      "showUserPaymentButton": false,
      "showUserConfirmPunchButton": false,
      "showUserAppealButton": false,
      "showUserConfirmOrderButton": false,
      "showUserEvaluationButton": false,
      "showUserChooseExpertButton": false,
      "showExpertQuoteButton": false,
      "showExpertPunchButton": false,
      "showExpertConfirmOrderButton": false,
      "showExpertArchiveButton": false
    },
    {
      "id": 8,
      "name": "拒绝接单",
      "desc": "拒绝接单",
      "showUserAppealInfo": true,
      "showUserPaymentButton": false,
      "showUserConfirmPunchButton": false,
      "showUserAppealButton": false,
      "showUserConfirmOrderButton": false,
      "showUserEvaluationButton": false,
      "showUserChooseExpertButton": true,
      "showExpertQuoteButton": false,
      "showExpertPunchButton": false,
      "showExpertConfirmOrderButton": false,
      "showExpertArchiveButton": false
    }
  ];

  // 出诊状态
  static const List<dynamic> expeditionStatus = [
    {
      "id": 0,
      "name": "待接单",
      "desc": "待接单(创建订单)",
      "showUserAppealInfo": false,
      "showUserPaymentButton": false,
      "showUserConfirmPunchButton": false,
      "showUserAppealButton": false,
      "showUserConfirmOrderButton": false,
      "showUserEvaluationButton": false,
      "showUserChooseExpertButton": false,
      "showExpertQuoteButton": false,
      "showExpertPunchButton": false,
      "showExpertConfirmOrderButton": false,
      "showExpertArchiveButton": false
    },
    {
      "id": 1,
      "name": "待报价",
      "desc": "已接单(待报价)",
      "showUserAppealInfo": false,
      "showUserPaymentButton": false,
      "showUserConfirmPunchButton": false,
      "showUserAppealButton": false,
      "showUserConfirmOrderButton": false,
      "showUserEvaluationButton": false,
      "showUserChooseExpertButton": false,
      "showExpertQuoteButton": true,
      "showExpertPunchButton": false,
      "showExpertConfirmOrderButton": false,
      "showExpertArchiveButton": false
    },
    {
      "id": 2,
      "name": "用户待付款",
      "desc": "待付款(已报价)",
      "showUserAppealInfo": false,
      "showUserPaymentButton": true,
      "showUserConfirmPunchButton": false,
      "showUserAppealButton": false,
      "showUserConfirmOrderButton": false,
      "showUserEvaluationButton": false,
      "showUserChooseExpertButton": false,
      "showExpertQuoteButton": true,
      "showExpertPunchButton": false,
      "showExpertConfirmOrderButton": false,
      "showExpertArchiveButton": false
    },
    {
      "id": 3,
      "name": "已付款",
      "desc": "已付款（已付款, 专家待打卡，用户确认专家到场打卡，专家待确认）",
      "showUserAppealInfo": false,
      "showUserPaymentButton": false,
      "showUserConfirmPunchButton": true,
      "showUserAppealButton": false,
      "showUserConfirmOrderButton": false,
      "showUserEvaluationButton": false,
      "showUserChooseExpertButton": false,
      "showExpertQuoteButton": false,
      "showExpertPunchButton": true,
      "showExpertConfirmOrderButton": true,
      "showExpertArchiveButton": false
    },
    {
      "id": 4,
      "name": "用户待确认",
      "desc": "用户待确认,专家确认完成",
      "showUserAppealInfo": false,
      "showUserPaymentButton": false,
      "showUserConfirmPunchButton": false,
      "showUserAppealButton": true,
      "showUserConfirmOrderButton": true,
      "showUserEvaluationButton": false,
      "showUserChooseExpertButton": false,
      "showExpertQuoteButton": false,
      "showExpertPunchButton": false,
      "showExpertConfirmOrderButton": false,
      "showExpertArchiveButton": false
    },
    {
      "id": 5,
      "name": "用户确认完成",
      "desc": "用户确认完成,待评价",
      "showUserAppealInfo": false,
      "showUserPaymentButton": false,
      "showUserConfirmPunchButton": false,
      "showUserAppealButton": false,
      "showUserConfirmOrderButton": false,
      "showUserEvaluationButton": true,
      "showUserChooseExpertButton": false,
      "showExpertQuoteButton": false,
      "showExpertPunchButton": false,
      "showExpertConfirmOrderButton": false,
      "showExpertArchiveButton": false
    },
    {
      "id": 6,
      "name": "已完成",
      "desc": "已完成,已评价",
      "showUserAppealInfo": false,
      "showUserPaymentButton": false,
      "showUserConfirmPunchButton": false,
      "showUserAppealButton": false,
      "showUserConfirmOrderButton": false,
      "showUserEvaluationButton": false,
      "showUserChooseExpertButton": false,
      "showExpertQuoteButton": false,
      "showExpertPunchButton": false,
      "showExpertConfirmOrderButton": false,
      "showExpertArchiveButton": false
    },
    {
      "id": 7,
      "name": "申诉中",
      "desc": "申诉中",
      "showUserAppealInfo": true,
      "showUserPaymentButton": false,
      "showUserConfirmPunchButton": false,
      "showUserAppealButton": false,
      "showUserConfirmOrderButton": false,
      "showUserEvaluationButton": false,
      "showUserChooseExpertButton": false,
      "showExpertQuoteButton": false,
      "showExpertPunchButton": false,
      "showExpertConfirmOrderButton": false,
      "showExpertArchiveButton": false
    },
    {
      "id": 8,
      "name": "拒绝接单",
      "desc": "拒绝接单",
      "showUserAppealInfo": true,
      "showUserPaymentButton": false,
      "showUserConfirmPunchButton": false,
      "showUserAppealButton": false,
      "showUserConfirmOrderButton": false,
      "showUserEvaluationButton": false,
      "showUserChooseExpertButton": true,
      "showExpertQuoteButton": false,
      "showExpertPunchButton": false,
      "showExpertConfirmOrderButton": false,
      "showExpertArchiveButton": false
    }
  ];

  // 通过id和类型获取状态名称
  // dataTable 1问诊，2出诊
  static String getStatusName(statuz, dataTable,
      {int arrivedFlag = 0, String userType = 'USER'}) {
    List statusList;
    if(statuz == 8){
      return "已拒绝";
    }
    if (dataTable == 1) {
      if (userType == "USER" && (statuz == 5 || statuz == 6)) {
        return "已完成";
      }
      statusList = inquiryStatus;
    } else if (dataTable == 2) {
      statusList = expeditionStatus;
      if (statuz == 3) {
        return arrivedFlag == 0 ? "待打卡" : "已打卡";
      }
    }
    for (var i = 0; i < statusList.length; i++) {
      if (statusList[i]['id'] == statuz) {
        return statusList[i]['name'];
      }
    }
    return '';
  }

  // 通过id、类型和按钮关键字，判断内容是否显示
  static bool isShow(statuz, dataTable, type, {int arrivedFlag}) {
    List statusList;
    if (dataTable == 1) {
      statusList = inquiryStatus;
    } else if (dataTable == 2) {
      statusList = expeditionStatus;
    }
    for (var i = 0; i < statusList.length; i++) {
      if (statusList[i]['id'] == statuz && statusList[i][type]) {
        if (type == 'showUserConfirmPunchButton') {
          // 如果专家没有打卡，用户可以协助打卡
          if (arrivedFlag == 0 || arrivedFlag == 1) {
            return false;
          }else {
            return true;
          }
        }
        if (type == 'showExpertConfirmOrderButton'&& dataTable == 2) {
          // 如果专家已经打卡，才能专家确认
          if (arrivedFlag != 1) {
            return false;
          }else {
            return true;
          }
        }

        return true;
      }
    }
    return false;
  }
}
