import {Component, OnInit, ViewChild} from '@angular/core';
import {NavController} from "@ionic/angular";
import {Router} from "@angular/router";
import {SessionDataProviderService} from "../../store/session-data-provider.service";
import {WrenchService} from "../../services/wrench.service";

@Component({
  selector: 'app-jobactive',
  templateUrl: './jobactive.page.html',
  styleUrls: ['./jobactive.page.scss'],
})
export class JobactivePage implements OnInit {
  @ViewChild('yourmessage') yourmessage;

  jobData: any;
  tabs = 'activities';
  item_banner:string = 'default.jpg';
  session_image_server:string='';
  curr_session:string='';

  constructor(
      private navctr: NavController,
      private router: Router,
      public sessionDataProviderService: SessionDataProviderService,
      private wrenchService: WrenchService
  ) {
    this.jobData  =  this.router.getCurrentNavigation().extras.state;
    this.item_banner = this.jobData.banner;
  }


  ngOnInit() {
    this.curr_session =  this.sessionDataProviderService.session;
    //this.activeJobMsgList();
  }

  onBack() {
    this.navctr.back();
  }

  // contrData: {
  //   action:number,
  //   member_id: number,
  //   uid: string,
  //   sessionid: string,
  //   limit:20,
  //   contract:string,
  //   offset: 0
  // };
  // msgListTotalData:any;
  // msgListData: [];
  // activeJobMsgList(){
  //   this.contrData = {
  //     action:14011,
  //     member_id: this.sessionDataProviderService.member_id,
  //     uid: this.sessionDataProviderService.member_uid,
  //     sessionid: this.sessionDataProviderService.session ,
  //     limit:20,
  //     contract: this.jobData.contract,
  //     offset: 0}
  //
  //   this.wrenchService.activeJobMsgList(this.contrData).subscribe(
  //       msgListTotalData => {
  //         this.msgListTotalData = msgListTotalData;
  //         // console.log("REFER  RETURN->", this.referTotalData);
  //         this.msgListData = this.msgListTotalData.result_list;
  //         console.log("REFER RETURN DATA->", this.msgListData);
  //       }
  //   );
  //
  // }

  reqData: {
    action:number, member_id: number, uid: string, sessionid: string, msg_type:string,
    contract:string,
    message:string
  };

  interest_status:string = "";
  interest_msg_status:string = "";

  msgReqResult:any;
  sendActiveJobMessage(){
    if (this.yourmessage.length < 5){
      alert("Enter Message to send");
      return;
    }

    this.reqData = {action:14010,
      member_id: this.sessionDataProviderService.member_id,
      uid: this.sessionDataProviderService.member_uid,
      sessionid: this.sessionDataProviderService.session ,
      msg_type: "TEXT",
      contract:this.jobData.contract,
      message: this.yourmessage
    }

    this.wrenchService.sendTaskMessage(this.reqData).subscribe(
        reqResult => {
          this.msgReqResult = reqResult;
          console.log("msgReqResult  RETURN->", this.msgReqResult);
          this.interest_msg_status =  this.msgReqResult?.status;
         // this.activeJobMsgList();
        }
    );
  }

}
