import 'package:flutter/material.dart';
import 'package:bookatanker/common/settings.dart';
import 'package:intl/intl.dart';

class PendingSuppliersModel {
  String supplier_name = '';
  String status='';
  String supplier_address='';
  String supplier_phone_number='';
  String supplier_id='';
  Color text_color=Colors.black;
  double lat=0;
  double lng=0;
  var timestamp;
  bool sendReminder=false;

  PendingSuppliersModel();

  factory PendingSuppliersModel.fromJson(Map<String, dynamic> json){
    PendingSuppliersModel rtvm = new PendingSuppliersModel();

    rtvm.supplier_name = json['suppliername'] ?? '';
    rtvm.status = json['status'] ?? '';
    rtvm.supplier_address = json['profile']['office_address'] ?? '';
    rtvm.supplier_phone_number = json['phone'] ?? '';
    rtvm.supplier_id = json['supplierId'] ?? '';
    rtvm.lat = json['latitude'] ?? 0;
    rtvm.lng = json['longitude'] ?? 0;
    rtvm.timestamp = json['timestamp'] ?? '';



    final DateTime now = DateTime.now();

    //var date = '2021-01-26T03:17:00.000000Z';
    DateTime parseDate = new DateFormat("dd-MM-yyyy HH:mm:ss").parse(rtvm.timestamp);
    /*var inputDate = DateTime.parse(parseDate.toString());
    var outputFormat = DateFormat('MM/dd/yyyy hh:mm a');
    var outputDate = outputFormat.format(inputDate);
    print(outputDate);*/
    var diff = now.difference(parseDate).inHours;

    if(diff>=5){
      rtvm.sendReminder=true;
    }
    else{
      rtvm.sendReminder=false;
    }


    if(rtvm.status.toString().toLowerCase()=='pending'){
      rtvm.text_color=Colors.yellow;
    }
    else if(rtvm.status.toString().toLowerCase()=='accepted'){
      rtvm.text_color=Colors.green;
    }
    else if(rtvm.status.toString().toLowerCase()=='rejected'){
      rtvm.text_color=Colors.red;
    }
    else{
      rtvm.status='Connect?';
      rtvm.text_color=primaryColor;
    }




    return rtvm;
  }

}