import { Injectable } from '@angular/core';
import {SessionDataProviderService} from "./session-data-provider.service";
import {AlertController, LoadingController} from "@ionic/angular";
import {WrenchService} from "../services/wrench.service";

@Injectable({
  providedIn: 'root'
})
export class UsersoffersDataService {

  constructor(public sessionDataProviderService: SessionDataProviderService,
              private alertController:AlertController,
              private wrenchService: WrenchService,
              private loadingCtrl: LoadingController) { }

  session_image_server:string='';
  curr_session:string='';
  //
  usrData: {
    action:number, member_id: number, uid: string,
    sessionid: string,
    limit:20,
    page:1, offset:number
  };
  total_offers:number = 0;
  myOffersTotalData:any;
  myOffersData: [];
  async getMyOffersData(){
    this.usrData = {action:15010,
      member_id: this.sessionDataProviderService.member_id,
      uid: this.sessionDataProviderService.member_uid,
      sessionid: this.sessionDataProviderService.session ,
      limit:20, page:1,offset: 0}

    this.curr_session =  this.sessionDataProviderService.session;
    this.wrenchService.getMyOffers(this.usrData).subscribe(
        myOffersTotalData => {
          this.myOffersTotalData = myOffersTotalData;
          this.session_image_server = this.myOffersTotalData.session_image_server;
          //console.log("myOffersTotalData  RETURN->", this.myOffersTotalData);
          this.myOffersData = this.myOffersTotalData.result_list;
          //console.log("myOffersData RETURN DATA->", this.myOffersData);
          this.total_offers =  this.myOffersData?.length;
        }
    );

  }
}
