import { Component, OnInit } from '@angular/core'; import { CommonService } from 'src/app/hmg-common/services/common/common.service'; import { TranslatorService } from 'src/app/hmg-common/services/translator/translator.service'; import { OfferDiscountService } from '../services/service'; import { SocialSharing } from '@ionic-native/social-sharing/ngx'; @Component({ selector: 'app-offer-details', templateUrl: './offer-details.component.html', styleUrls: ['./offer-details.component.scss'], }) export class OfferDetailsComponent implements OnInit { public details: any; public direction: String; public related: any; constructor(public ts: TranslatorService, private socialSharing: SocialSharing, public cs: CommonService, public offersService: OfferDiscountService) { } ngOnInit() { this.direction = TranslatorService.getCurrentDirection(); this.details = this.cs.sharedService.getSharedData(OfferDiscountService.selected_offers, false); this.related = this.cs.sharedService.getSharedData(OfferDiscountService.related_offers, false); } checkDate(date) { return new Date(date) >= new Date() } getDotted(temp) { temp = this.stripHtml(temp); return temp.substring(0, 100) + " ..."; } stripHtml(html) { var temporalDivElement = document.createElement("div"); temporalDivElement.innerHTML = html; return temporalDivElement.textContent || temporalDivElement.innerText || ""; } share() { console.log(this.details); const offerMessage = this.direction === 'ltr' ? this.details.Description : this.details.Description_AR; const offerSubject = this.direction === 'ltr' ? this.details.Title : this.details.Title_AR; const options = { message: this.stripHtml(offerMessage), subject: this.stripHtml(offerSubject), files: [this.details.Banner_Image] } this.socialSharing.shareWithOptions(options).then((result) => { console.log(result); }) } openRelated(item) { this.cs.sharedService.setSharedData(item, OfferDiscountService.selected_offers); this.cs.back(); setTimeout(() => { this.cs.navigateForward('/offersdiscount/offer-details'); }, 200); } openLocation() { this.cs.navigateForward('/offersdiscount/location'); } getLocation() { this.cs.startLoading(); this.offersService.getOfferLocation({ OfferId: this.details.rowID }, () => { }, this.ts.trPK('general', 'retry')).subscribe((result) => { this.cs.stopLoading(); result = JSON.parse(result.Mohemm_ITG_ResponseItem).result.data; this.cs.sharedService.setSharedData(result, OfferDiscountService.selected_offers); this.openLocation(); }) } }