/**
 * Shoppr - E-commerce app starter Ionic 4(https://www.enappd.com)
 *
 * Copyright © 2018-present Enappd. All rights reserved.
 *
 * This source code is licensed as per the terms found in the
 * LICENSE.md file in the root directory of this source .
 *
 */ import { Component , OnInit , ViewChild } from '@angular/core' ; import { FunctionsService } from '../functions.service' ; import { DataService , Product , HomeTab } from '../data.service' ; import { IonSlides , MenuController , NavController , IonContent } from '@ionic/angular' ; @ Component ( { selector : 'app-productdetail' , templateUrl : './productdetail.page.html' , styleUrls : [ './productdetail.page.scss' ] , } ) export class ProductdetailPage implements OnInit { @ ViewChild ( 'Slides' ) slides : IonSlides ; @ ViewChild ( 'Content' ) content : IonContent ; @ ViewChild ( 'slider' ) slider : IonSlides ; index = 0 ; segment = '' ; slideOpts = { effect : 'flip' , zoom : false } ; data : Array < HomeTab > = [ ] ; product : Product ; constructor ( private menuCtrl , private fun , private dataService , private nav ) { this . product = dataService . current_product ; this . data = dataService . item_tab ; this . segment = this . data [ 0 ] . title ; } ngOnInit ( ) { } ionViewDidEnter ( ) { this . menuCtrl . enable ( false , 'start' ) ; this . menuCtrl . enable ( false , 'end' ) ; } async change ( ) { await this . slides . getActiveIndex ( ) . then ( d => this . index = d ) ; this . segment = this . data [ this . index ] . title ; this . drag ( ) ; } onReviewClick ( index ) { this . segment = this . data [ index ] . title ; this . index = index ; this . slides . slideTo ( index ) ; this . content . scrollToTop ( ) ; this . drag ( ) ; } goToCart ( ) { this . fun . navigate ( 'cart' , false ) ; } update ( i ) { this . slides . slideTo ( i ) ; } drag ( ) { let distanceToScroll = 0 ; for ( const index in this . data ) { if ( parseInt ( index ) < this . index ) { distanceToScroll = distanceToScroll + document . getElementById ( 'seg_' + index ) . offsetWidth + 24 ; } } document . getElementById ( 'dag' ) . scrollLeft = distanceToScroll ; } seg ( event ) { this . segment = event . detail . value ; } }