import { ChangeDetectionStrategy, Component, EventEmitter, Input, Output, } from '@angular/core'; import { CatalogShippingInfoResponseInterface, DropdownBoxOptionsInterface, PriceDefinitionInterface, } from './../../models/index'; @Component({ changeDetection: ChangeDetectionStrategy.OnPush, selector: 'product-shipping-locations-and-prices-content-component', styleUrls: [ './product-shipping-locations-and-prices-content.component.scss', ], templateUrl: './product-shipping-locations-and-prices-content.component.template.pug', }) export class ProductShippingLocationsAndPricesContentComponent { @Input() public title: string = 'Shipping Locations & Prices'; @Input() public intro: string = 'With Prodigi you only need to set up one product to' + ' sell worldwide. We do this by grouping similar brands to ensure' + ' your customers get the best products and the quickest shipping' + ' times but we also give you the power to customise what brands are' + ' sent where.'; @Input() public carrierColumnLabel: string = 'Carrier'; @Input() public serviceColumnLabel: string = 'Service'; @Input() public shippingCostColumnLabel: string = 'Shipping cost'; @Input() public additionalItemsColumnLabel: string = 'Additional items'; @Input() public deliveryTimesColumnLabel: string = 'Delivery times'; @Input() public manufacturingTimeColumnLabel: string = 'Manufacturing time'; @Input() public currency: string = 'GBP'; @Input() public trackedText: string = 'Tracked'; @Input() public shippingCountries: Map; @Input() public shippingTemplates: Map; @Input() public shippingInfo: CatalogShippingInfoResponseInterface[]; @Output() public onChangeShippingTemplate = new EventEmitter(); @Output() public onChangeShippingCountry = new EventEmitter(); public get showContent() { return Boolean( (this.shippingCountries && this.shippingCountries.size > 0) && (this.shippingTemplates && this.shippingTemplates.size > 0), ); } public get shippingTemplatesAsOptions(): DropdownBoxOptionsInterface[] { return Array.from(this.shippingTemplates) .map(([label]) => ({ label, value: label, })); } public get shippingTemplatesOptionsSelectedValue(): string { const selectedValue = Array.from(this.shippingTemplates).find(([, value]) => ( value === true )); return selectedValue && selectedValue[0]; } public get shippingCountriesAsOptions(): DropdownBoxOptionsInterface[] { return Array.from(this.shippingCountries) .map(([label]) => ({ label, value: label, })); } public get shippingCountriesOptionsSelectedValue(): string { const selectedValue = Array.from(this.shippingCountries).find(([, value]) => ( value === true )); return selectedValue && selectedValue[0]; } public getCarrierMethod({ carrierMethod, tracked, }: CatalogShippingInfoResponseInterface) { const trackedText = tracked && !carrierMethod.includes(this.trackedText) ? ` ${this.trackedText}` : ''; return `${carrierMethod}${trackedText}`; } public getCostForCurrentCurrency( costsByCurrency: PriceDefinitionInterface[], ) { const price = costsByCurrency.find( (cost) => cost.currency === this.currency, ); return price && price.value; } public changeSelectedTemplate(templateId: string) { this.onChangeShippingTemplate.emit(templateId); } public changeSelectedCountry(country: string) { this.onChangeShippingCountry.emit(country); } public hasManufacturingTime() { return this.shippingInfo .some((info) => Boolean(info.manufacturingTime)); } }