@hhgtech/hhg-components
Version:
Hello Health Group common components
761 lines (751 loc) • 42.6 kB
JavaScript
import { theme } from './miscTheme.js';
export { c as Constants } from './constants-c2780be8.js';
import './index-5e947517.js';
import 'date-fns/locale';
import './index-90813715.js';
import './Locale-f270bd9d.js';
import './constantsSite.js';
import './constantsDomainLocales.js';
import './constantsRiskScreener.js';
import './constantsIsProduction.js';
// ===== CART END =====
var apiTypes = /*#__PURE__*/Object.freeze({
__proto__: null
});
var dataTypes = /*#__PURE__*/Object.freeze({
__proto__: null
});
function isDefined(argument) {
return argument !== undefined && argument !== null;
}
const dataFormatter = {
formatAutoCompleteAddress: (address) => {
if (!address || !address.place_id)
return null;
return {
placeId: address.place_id,
description: address.description || '',
};
},
formatPrice: (price, locale) => {
const formattedPrice = typeof price === 'string' ? parseInt(price) : price;
return new Intl.NumberFormat(locale || 'vi-VN').format(formattedPrice);
},
formatHotSearchKeyword: (data) => {
return {
text: (data === null || data === void 0 ? void 0 : data.name) || '',
};
},
formatHelpfulUrl: (data) => {
return {
name: (data === null || data === void 0 ? void 0 : data.name) || '',
featuredImage: (data === null || data === void 0 ? void 0 : data.featured_image) || '',
url: (data === null || data === void 0 ? void 0 : data.url) || '',
};
},
formatCategory: function (data, parentId, parentFullSlug) {
var _a, _b, _c;
const currentFullSlug = parentFullSlug
? parentFullSlug + '/' + data.slug
: data.slug;
const children = ((_b = (_a = data === null || data === void 0 ? void 0 : data.children) === null || _a === void 0 ? void 0 : _a.map) === null || _b === void 0 ? void 0 : _b.call(_a, (childCategory) => {
return dataFormatter.formatCategory(childCategory, data.id, currentFullSlug);
})) || [];
return {
id: data === null || data === void 0 ? void 0 : data.id,
name: (data === null || data === void 0 ? void 0 : data.name) || '',
logo: (data === null || data === void 0 ? void 0 : data.logo) || '',
slug: (data === null || data === void 0 ? void 0 : data.slug) || '',
fullSlug: currentFullSlug || '',
children,
backgroundColor: data.color || theme.colors.teal50,
parentId: parentId || 0,
products: ((_c = data.products) === null || _c === void 0 ? void 0 : _c.map(dataFormatter.formatProduct)) || [],
};
},
formatFooterInfo: (data) => {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
const branches = ((_c = (_b = (_a = data === null || data === void 0 ? void 0 : data.branch) === null || _a === void 0 ? void 0 : _a.branch) === null || _b === void 0 ? void 0 : _b.map) === null || _c === void 0 ? void 0 : _c.call(_b, (branch) => {
return {
flag: branch.flag || '',
name: branch.name || '',
url: branch.url || '',
};
})) || [];
const verified = ((_f = (_e = (_d = data === null || data === void 0 ? void 0 : data.general) === null || _d === void 0 ? void 0 : _d.verified) === null || _e === void 0 ? void 0 : _e.map) === null || _f === void 0 ? void 0 : _f.call(_e, (verifiedItem) => {
return {
image: verifiedItem.image || '',
url: verifiedItem.url || '',
};
})) || [];
const menu = ((_h = (_g = data === null || data === void 0 ? void 0 : data.menu) === null || _g === void 0 ? void 0 : _g.map) === null || _h === void 0 ? void 0 : _h.call(_g, (menuItem) => {
var _a, _b;
return {
menu_title: menuItem.menu_title,
items: (_b = (_a = menuItem.items) === null || _a === void 0 ? void 0 : _a.map) === null || _b === void 0 ? void 0 : _b.call(_a, (item) => {
return {
title: item.title,
url: item.url,
};
}),
};
})) || [];
const socials = ((_l = (_k = (_j = data === null || data === void 0 ? void 0 : data.social) === null || _j === void 0 ? void 0 : _j.socials) === null || _k === void 0 ? void 0 : _k.map) === null || _l === void 0 ? void 0 : _l.call(_k, (social) => {
return {
icon: social.icon || '',
name: social.name || '',
url: social.url || '',
};
})) || [];
return {
branch: {
title: ((_m = data === null || data === void 0 ? void 0 : data.branch) === null || _m === void 0 ? void 0 : _m.title) || '',
branch: branches,
},
general: {
logo: (_p = (_o = data === null || data === void 0 ? void 0 : data.general) === null || _o === void 0 ? void 0 : _o.logo) !== null && _p !== void 0 ? _p : '',
content: (_r = (_q = data === null || data === void 0 ? void 0 : data.general) === null || _q === void 0 ? void 0 : _q.content) !== null && _r !== void 0 ? _r : '',
copyright: (_t = (_s = data === null || data === void 0 ? void 0 : data.general) === null || _s === void 0 ? void 0 : _s.copyright) !== null && _t !== void 0 ? _t : '',
verified,
},
menu,
social: {
title: ((_u = data === null || data === void 0 ? void 0 : data.social) === null || _u === void 0 ? void 0 : _u.title) || '',
socials,
},
};
},
formatNavigation: function (data) {
var _a, _b, _c, _d, _e, _f;
return {
hotSearchKeywords: ((_b = (_a = data === null || data === void 0 ? void 0 : data.hot_search_keywords) === null || _a === void 0 ? void 0 : _a.map) === null || _b === void 0 ? void 0 : _b.call(_a, dataFormatter.formatHotSearchKeyword)) || [],
helpfulUrls: ((_d = (_c = data === null || data === void 0 ? void 0 : data.helpful_urls) === null || _c === void 0 ? void 0 : _c.map) === null || _d === void 0 ? void 0 : _d.call(_c, dataFormatter.formatHelpfulUrl)) || [],
categories: ((_f = (_e = data === null || data === void 0 ? void 0 : data.categories) === null || _e === void 0 ? void 0 : _e.map) === null || _f === void 0 ? void 0 : _f.call(_e, (category) => dataFormatter.formatCategory(category))) || [],
footer: dataFormatter.formatFooterInfo(data === null || data === void 0 ? void 0 : data.footer),
storeId: (data === null || data === void 0 ? void 0 : data.store_id) || 0,
customerId: (data === null || data === void 0 ? void 0 : data.customer_id) || 0,
cartItemsQty: typeof (data === null || data === void 0 ? void 0 : data.cart_items_qty) === 'number' ? data.cart_items_qty : null,
};
},
// === ECOM TYPES FORMAT ===
formatPriceInfo: (priceInfoApi) => {
if (!priceInfoApi)
return null;
return {
final: priceInfoApi.final || 0,
regular: priceInfoApi.regular || 0,
discountPercent: priceInfoApi.discount_percent || 0,
};
},
formatProduct: function (productApi) {
var _a, _b, _c, _d;
if (!productApi)
return null;
const defaultPriceInfo = {
final: 0,
regular: 0,
discountPercent: 0,
};
return {
id: productApi.id || 0,
price: productApi.price
? dataFormatter.formatPriceInfo(productApi.price) || defaultPriceInfo
: defaultPriceInfo,
thumbnail: productApi.thumbnail || '',
name: productApi.name || '',
averageRating: Number((productApi.average_rating || 0).toFixed(2)),
reviewsCount: productApi.reviews_count || 0,
tag: productApi.tag || null,
sku: productApi.sku || '',
slug: productApi.slug || '',
images: productApi.images || [],
tags: productApi.tags || [],
unit: productApi.unit || '',
brand: productApi.brand
? {
name: productApi.brand.name || '',
image: productApi.brand.image || '',
slug: productApi.brand.slug || '',
productsCount: productApi.brand.products_count || 0,
}
: null,
description: productApi.description || '',
productPromotions: ((_b = (_a = productApi.product_promotions) === null || _a === void 0 ? void 0 : _a.map) === null || _b === void 0 ? void 0 : _b.call(_a, dataFormatter.formatProductPromotion).filter(isDefined)) || [],
categories: ((_d = (_c = productApi.categories) === null || _c === void 0 ? void 0 : _c.map) === null || _d === void 0 ? void 0 : _d.call(_c, (c) => dataFormatter.formatCategory(c)).filter(isDefined)) || [],
isInStock: (productApi === null || productApi === void 0 ? void 0 : productApi.is_in_stock) || false,
};
},
formatBanner: (bannerApi) => {
if (!bannerApi)
return null;
return {
name: bannerApi.name || '',
url: bannerApi.url || '',
featuredImage: bannerApi.featured_image || '',
alt: bannerApi.image_alt,
};
},
formatBlogPost: (blogPostApi) => {
var _a, _b;
if (!blogPostApi)
return null;
return {
title: blogPostApi.title || '',
image: blogPostApi.image || '',
link: blogPostApi.link || '',
postData: blogPostApi.post_data
? {
reviewed: blogPostApi.post_data.reviewed
? {
author: dataFormatter.formatBlogPostDataReviewedUser(blogPostApi.post_data.reviewed.author || undefined),
editor: dataFormatter.formatBlogPostDataReviewedUser(blogPostApi.post_data.reviewed.editor || undefined),
expert: dataFormatter.formatBlogPostDataReviewedUser(blogPostApi.post_data.reviewed.expert || undefined),
factCheck: dataFormatter.formatBlogPostDataReviewedUser(blogPostApi.post_data.reviewed.fact_check || undefined),
isAuthor: Boolean(blogPostApi.post_data.reviewed.is_author),
}
: null,
categories: blogPostApi.post_data.categories
? (_b = (_a = blogPostApi.post_data.categories).map) === null || _b === void 0 ? void 0 : _b.call(_a, (item) => ({
termId: item.term_id || 0,
name: item.name || '',
permalink: item.permalink || '',
textColor: item.text_color || '',
}))
: [],
postDate: blogPostApi.post_data.post_date || '',
postModified: blogPostApi.post_data.post_modified || '',
modifiedTime: blogPostApi.post_data.modified_time || '',
}
: null,
};
},
formatBlogPostDataReviewedUser: (blogPostDataReviewedUserApi) => {
if (!blogPostDataReviewedUserApi)
return null;
return {
id: blogPostDataReviewedUserApi.ID || 0,
userId: blogPostDataReviewedUserApi.user_id || 0,
formerRole: blogPostDataReviewedUserApi.former_role || '',
role: blogPostDataReviewedUserApi.role || '',
slug: blogPostDataReviewedUserApi.slug || '',
displayName: blogPostDataReviewedUserApi.display_name || '',
description: blogPostDataReviewedUserApi.description || '',
profileUrl: blogPostDataReviewedUserApi.profile_url || '',
avatar: blogPostDataReviewedUserApi.avatar || '',
avatarThumbnail: blogPostDataReviewedUserApi.avatar_thumbnail || '',
turnOffProfile: Boolean(blogPostDataReviewedUserApi.turn_off_profile),
};
},
formatBrand: function (brandApi) {
var _a, _b, _c, _d;
if (!brandApi)
return null;
return {
id: brandApi.id || 0,
image: brandApi.image || '',
position: brandApi.position || '',
isPopular: brandApi.is_popular || false,
summary: brandApi.summary || '',
name: brandApi.name || '',
slug: brandApi.slug || '',
description: brandApi.description || null,
banners: ((_b = (_a = brandApi.banners) === null || _a === void 0 ? void 0 : _a.map) === null || _b === void 0 ? void 0 : _b.call(_a, dataFormatter.formatBanner).filter(isDefined)) ||
[],
bestsellerProducts: ((_d = (_c = brandApi.bestseller_products) === null || _c === void 0 ? void 0 : _c.map) === null || _d === void 0 ? void 0 : _d.call(_c, dataFormatter.formatProduct).filter(isDefined)) || [],
};
},
formatHomePage: (homePageApi) => {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
if (!homePageApi)
return null;
return {
brands: homePageApi.brands
? (_b = (_a = homePageApi.brands).map) === null || _b === void 0 ? void 0 : _b.call(_a, dataFormatter.formatBrand).filter(isDefined)
: [],
hotDeals: homePageApi.hot_deals
? (_d = (_c = homePageApi.hot_deals).map) === null || _d === void 0 ? void 0 : _d.call(_c, dataFormatter.formatProduct).filter(isDefined)
: [],
newProducts: homePageApi.new_products
? (_f = (_e = homePageApi.new_products).map) === null || _f === void 0 ? void 0 : _f.call(_e, dataFormatter.formatProduct).filter(isDefined)
: [],
slideBanners: homePageApi.slide_banners
? (_h = (_g = homePageApi.slide_banners).map) === null || _h === void 0 ? void 0 : _h.call(_g, dataFormatter.formatBanner).filter(isDefined)
: [],
subBanners: homePageApi.sub_banners
? (_k = (_j = homePageApi.sub_banners).map) === null || _k === void 0 ? void 0 : _k.call(_j, dataFormatter.formatBanner).filter(isDefined)
: [],
footerBanners: homePageApi.footer_banners
? (_m = (_l = homePageApi.footer_banners).map) === null || _m === void 0 ? void 0 : _m.call(_l, dataFormatter.formatBanner).filter(isDefined)
: [],
blogPosts: homePageApi.blog_posts
? (_p = (_o = homePageApi.blog_posts).map) === null || _p === void 0 ? void 0 : _p.call(_o, dataFormatter.formatBlogPost).filter(isDefined)
: [],
popularCategories: homePageApi.popular_categories
? (_r = (_q = homePageApi.popular_categories).map) === null || _r === void 0 ? void 0 : _r.call(_q, (c) => dataFormatter.formatCategory(c)).filter(isDefined)
: [],
suggestProducts: homePageApi.suggest_products
? (_t = (_s = homePageApi.suggest_products).map) === null || _t === void 0 ? void 0 : _t.call(_s, (c) => dataFormatter.formatCategory(c)).filter(isDefined)
: [],
promotions: homePageApi.promotions
? (_v = (_u = homePageApi.promotions).map) === null || _v === void 0 ? void 0 : _v.call(_u, (c) => dataFormatter.formatPromotion(c)).filter(isDefined)
: [],
};
},
formatCategoryPage: function (categoryPageApi) {
var _a, _b, _c, _d;
if (!categoryPageApi)
return null;
return {
id: categoryPageApi.id || 0,
name: categoryPageApi.name || '',
slug: categoryPageApi.slug || '',
description: categoryPageApi.description || null,
banners: ((_b = (_a = categoryPageApi.banners) === null || _a === void 0 ? void 0 : _a.map) === null || _b === void 0 ? void 0 : _b.call(_a, dataFormatter.formatBanner).filter(isDefined)) || [],
bestsellerProducts: ((_d = (_c = categoryPageApi.bestseller_products) === null || _c === void 0 ? void 0 : _c.map) === null || _d === void 0 ? void 0 : _d.call(_c, dataFormatter.formatProduct).filter(isDefined)) || [],
};
},
formatBrandPage: function (brandPageApi) {
if (!brandPageApi)
return null;
return dataFormatter.formatBrand(brandPageApi);
},
formatPagination: (paginationApi) => {
if (!paginationApi)
return null;
return {
current: paginationApi.current || 0,
first: paginationApi.first || 0,
itemsPerPage: paginationApi.items_per_page || 0,
last: paginationApi.last || 0,
next: paginationApi.next || 0,
prev: paginationApi.prev || 0,
totalItems: paginationApi.total_items || 0,
};
},
formatProductDetailPage: function (productDetailPageApi) {
var _a, _b, _c, _d, _e, _f, _g, _h;
if (!productDetailPageApi)
return null;
return Object.assign(Object.assign({}, dataFormatter.formatProduct(productDetailPageApi)), { relatedProducts: ((_b = (_a = productDetailPageApi.related_products) === null || _a === void 0 ? void 0 : _a.map) === null || _b === void 0 ? void 0 : _b.call(_a, dataFormatter.formatProduct).filter(isDefined)) || [], bestsellerProducts: ((_d = (_c = productDetailPageApi.bestseller_products) === null || _c === void 0 ? void 0 : _c.map) === null || _d === void 0 ? void 0 : _d.call(_c, dataFormatter.formatProduct).filter(isDefined)) || [], viewedProducts: ((_f = (_e = productDetailPageApi.viewed_products) === null || _e === void 0 ? void 0 : _e.map) === null || _f === void 0 ? void 0 : _f.call(_e, dataFormatter.formatProduct).filter(isDefined)) || [], promotions: ((_h = (_g = productDetailPageApi.promotions) === null || _g === void 0 ? void 0 : _g.map) === null || _h === void 0 ? void 0 : _h.call(_g, dataFormatter.formatPromotion).filter(isDefined)) || [] });
},
formatProductReview: (productReview) => {
var _a, _b;
if (!productReview)
return null;
// TODO: avatar, images
return {
reviewId: productReview.review_id || '',
createdAt: productReview.created_at || '',
title: productReview.title || '',
detail: productReview.detail || '',
nickname: productReview.nick_name || '',
avatar: productReview.avatar || '',
ratingVotes: ((_b = (_a = productReview.rating_votes) === null || _a === void 0 ? void 0 : _a.map) === null || _b === void 0 ? void 0 : _b.call(_a, (vote) => {
return {
ratingCode: vote.rating_code || '',
value: Number(vote.value) || 0,
percent: Number(vote.percent) || 0,
};
})) || [],
images: productReview.images || [],
};
},
formatProductPromotion: (productPromotionApi) => {
if (!productPromotionApi)
return null;
return {
id: productPromotionApi.id || 0,
name: productPromotionApi.name || '',
thumbnail: productPromotionApi.thumbnail || '',
expirationDate: productPromotionApi.expiration_date || '',
};
},
formatPromotion: (promotionApi) => {
if (!promotionApi)
return null;
return {
id: promotionApi.id || 0,
name: promotionApi.name || '',
slug: promotionApi.slug || '',
thumbnail: promotionApi.thumbnail || '',
expiredDate: promotionApi.expired_date || '',
banners: promotionApi.banners || [],
points: 0,
description: promotionApi.description || '',
metaTitle: promotionApi.meta_title || '',
metaKeywords: promotionApi.meta_keywords || '',
metaDescription: promotionApi.meta_description || '',
};
},
formatCustomAttributes: (customAttributesApi, type) => {
var _a;
if (!(customAttributesApi === null || customAttributesApi === void 0 ? void 0 : customAttributesApi.length))
return '';
return (((_a = customAttributesApi === null || customAttributesApi === void 0 ? void 0 : customAttributesApi.find((item) => item.attribute_code === type)) === null || _a === void 0 ? void 0 : _a.value) || '');
},
formatAddress: (addressApi) => {
var _a, _b, _c, _d;
if (!addressApi)
return null;
return {
id: addressApi.id || 0,
fullName: addressApi.firstname || '',
telephone: addressApi.telephone || '',
province: {
value: (_a = addressApi.region) === null || _a === void 0 ? void 0 : _a.region_id,
label: (_b = addressApi.region) === null || _b === void 0 ? void 0 : _b.region,
} || null,
district: {
value: dataFormatter.formatCustomAttributes(addressApi.custom_attributes, 'district_id'),
label: dataFormatter.formatCustomAttributes(addressApi.custom_attributes, 'district'),
},
commune: {
value: dataFormatter.formatCustomAttributes(addressApi.custom_attributes, 'ward_id'),
label: dataFormatter.formatCustomAttributes(addressApi.custom_attributes, 'ward'),
},
street: ((_c = addressApi === null || addressApi === void 0 ? void 0 : addressApi.street) === null || _c === void 0 ? void 0 : _c.length) ? addressApi === null || addressApi === void 0 ? void 0 : addressApi.street[0] : '',
isDefault: (addressApi.default_billing && addressApi.default_shipping) || false,
fullAddress: ((_d = addressApi === null || addressApi === void 0 ? void 0 : addressApi.extension_attributes) === null || _d === void 0 ? void 0 : _d.full_address) || '',
};
},
formatProvince: (provinceApi) => {
if (!(provinceApi === null || provinceApi === void 0 ? void 0 : provinceApi.available_regions))
return [];
return provinceApi.available_regions.map((province) => ({
value: province.id || '',
label: province.name || '',
}));
},
formatDistrict: (districtApi) => {
if (!(districtApi === null || districtApi === void 0 ? void 0 : districtApi.districts))
return [];
return districtApi.districts.map((district) => ({
value: district.id || '',
label: district.name || '',
}));
},
formatCommune: (communeApi) => {
if (!(communeApi === null || communeApi === void 0 ? void 0 : communeApi.communes))
return [];
return communeApi.communes.map((commune) => ({
value: commune.id || '',
label: commune.name || '',
}));
},
formatOrder: (orderApi) => {
var _a, _b;
if (!orderApi)
return null;
return {
orderNumber: (orderApi === null || orderApi === void 0 ? void 0 : orderApi.order_number) || '',
shippingData: (orderApi === null || orderApi === void 0 ? void 0 : orderApi.shipping_data)
? {
shippingMethod: orderApi.shipping_data.shipping_method || '',
shippingDescription: orderApi.shipping_data.shipping_description || '',
shippingAddress: orderApi.shipping_data.shipping_address
? {
fullName: orderApi.shipping_data.shipping_address.firstname || '',
fullAddress: orderApi.shipping_data.shipping_address.full_address || '',
telephone: orderApi.shipping_data.shipping_address.telephone || '',
}
: null,
storeAddress: null,
}
: null,
orderedDate: (orderApi === null || orderApi === void 0 ? void 0 : orderApi.ordered_date) || '',
status: (orderApi === null || orderApi === void 0 ? void 0 : orderApi.status) || null,
totals: (orderApi === null || orderApi === void 0 ? void 0 : orderApi.totals)
? {
subtotal: orderApi.totals.subtotal || 0,
shippingAmount: orderApi.totals.shipping_amount || 0,
discountAmount: orderApi.totals.discount_amount || 0,
grandTotal: orderApi.totals.grand_total || 0,
}
: null,
products: ((_b = (_a = orderApi === null || orderApi === void 0 ? void 0 : orderApi.products) === null || _a === void 0 ? void 0 : _a.map) === null || _b === void 0 ? void 0 : _b.call(_a, (p) => ({
sku: p.sku || '',
name: p.name || '',
price: p.price || 0,
rowTotal: p.row_total || 0,
image: p.image || '',
qty: p.qty || 0,
}))) || [],
paymentMethod: (orderApi === null || orderApi === void 0 ? void 0 : orderApi.payment_method) || '',
};
},
formatStatistic: (statistic) => {
var _a, _b, _c, _d, _e;
if (!statistic)
return {};
return {
pending: Number((_a = statistic === null || statistic === void 0 ? void 0 : statistic.find((stt) => stt.status === 'pending')) === null || _a === void 0 ? void 0 : _a.amount) || 0,
processing: Number((_b = statistic === null || statistic === void 0 ? void 0 : statistic.find((stt) => stt.status === 'processing')) === null || _b === void 0 ? void 0 : _b.amount) || 0,
delivering: Number((_c = statistic === null || statistic === void 0 ? void 0 : statistic.find((stt) => stt.status === 'delivering')) === null || _c === void 0 ? void 0 : _c.amount) || 0,
complete: Number((_d = statistic === null || statistic === void 0 ? void 0 : statistic.find((stt) => stt.status === 'complete')) === null || _d === void 0 ? void 0 : _d.amount) || 0,
canceled: Number((_e = statistic === null || statistic === void 0 ? void 0 : statistic.find((stt) => stt.status === 'canceled')) === null || _e === void 0 ? void 0 : _e.amount) || 0,
};
},
formatCartItem: (cartItemApi) => {
var _a, _b, _c, _d, _e, _f, _g, _h;
if (!cartItemApi)
return null;
return {
itemId: cartItemApi.item_id || 0,
sku: cartItemApi.sku || '',
qty: cartItemApi.qty || 0,
name: cartItemApi.name || '',
price: cartItemApi.price || 0,
basePrice: ((_a = cartItemApi.extension_attributes) === null || _a === void 0 ? void 0 : _a.base_price) || 0,
productType: cartItemApi.product_type || '',
quoteId: cartItemApi.quote_id || '',
thumbnail: ((_b = cartItemApi.extension_attributes) === null || _b === void 0 ? void 0 : _b.thumbnail) || '',
rowTotal: ((_c = cartItemApi.extension_attributes) === null || _c === void 0 ? void 0 : _c.row_total) || 0,
promotions: (((_f = (_e = (_d = cartItemApi.extension_attributes) === null || _d === void 0 ? void 0 : _d.promotions) === null || _e === void 0 ? void 0 : _e.map) === null || _f === void 0 ? void 0 : _f.call(_e, dataFormatter.formatProductPromotion)) || []),
isInStock: ((_g = cartItemApi.extension_attributes) === null || _g === void 0 ? void 0 : _g.is_in_stock) || false,
urlProduct: ((_h = cartItemApi.extension_attributes) === null || _h === void 0 ? void 0 : _h.url_key) || '',
};
},
formatCartAddress: (cartAddressApi) => {
var _a;
if (!cartAddressApi)
return null;
return {
customerAddressId: (cartAddressApi === null || cartAddressApi === void 0 ? void 0 : cartAddressApi.customer_address_id) || 0,
id: cartAddressApi.id || 0,
region: cartAddressApi.region || '',
regionId: cartAddressApi.region_id || 0,
regionCode: cartAddressApi.region_code || '',
countryId: cartAddressApi.country_id || '',
street: cartAddressApi.street || [],
postcode: cartAddressApi.postcode || '',
city: cartAddressApi.city || '',
firstname: cartAddressApi.firstname || '',
lastname: cartAddressApi.lastname || '',
customerId: cartAddressApi.customer_id || 0,
email: cartAddressApi.email || '',
telephone: cartAddressApi.telephone || '',
sameAsBilling: cartAddressApi.same_as_billing || 0,
saveInAddressBook: cartAddressApi.save_in_address_book || 0,
fullAddress: ((_a = cartAddressApi.extension_attributes) === null || _a === void 0 ? void 0 : _a.full_address) || '',
};
},
formatEstimatedShipping: (estimatedShippingApi) => {
if (!estimatedShippingApi)
return null;
return {
carrierCode: estimatedShippingApi.carrier_code || '',
methodCode: estimatedShippingApi.method_code || '',
carrierTitle: estimatedShippingApi.carrier_title || '',
methodTitle: estimatedShippingApi.method_title || '',
amount: estimatedShippingApi.amount || 0,
baseAmount: estimatedShippingApi.base_amount || 0,
available: estimatedShippingApi.available || false,
errorMessage: estimatedShippingApi.error_message || '',
priceExclTax: estimatedShippingApi.price_excl_tax || 0,
priceInclTax: estimatedShippingApi.price_incl_tax || 0,
};
},
formatCartLoggedInCustomer: (cartLoggedInCustomerApi) => {
var _a, _b, _c;
if (!cartLoggedInCustomerApi)
return null;
return {
email: cartLoggedInCustomerApi.email || '',
firstname: cartLoggedInCustomerApi.firstname || '',
lastname: cartLoggedInCustomerApi.lastname || '',
id: cartLoggedInCustomerApi.id || 0,
groupId: cartLoggedInCustomerApi.group_id || 0,
createdAt: cartLoggedInCustomerApi.created_at || '',
updatedAt: cartLoggedInCustomerApi.updated_at || '',
createdIn: cartLoggedInCustomerApi.created_in || '',
storeId: cartLoggedInCustomerApi.store_id || 0,
websiteId: cartLoggedInCustomerApi.website_id || 0,
addresses: (((_b = (_a = cartLoggedInCustomerApi.addresses) === null || _a === void 0 ? void 0 : _a.map) === null || _b === void 0 ? void 0 : _b.call(_a, dataFormatter.formatCartAddress)) || []),
disableAutoGroupChange: cartLoggedInCustomerApi.disable_auto_group_change || 0,
isSubscribed: ((_c = cartLoggedInCustomerApi.extension_attributes) === null || _c === void 0 ? void 0 : _c.is_subscribed) || false,
};
},
formatCart: (cartApi) => {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
if (!cartApi)
return null;
return {
id: cartApi.id || 0,
createdAt: cartApi.created_at || '',
updatedAt: cartApi.updated_at || '',
isActive: cartApi.is_active || false,
isVirtual: cartApi.is_virtual || false,
items: (((_c = (_b = (_a = cartApi.items) === null || _a === void 0 ? void 0 : _a.map) === null || _b === void 0 ? void 0 : _b.call(_a, dataFormatter.formatCartItem)) === null || _c === void 0 ? void 0 : _c.sort((a, b) => Number(b === null || b === void 0 ? void 0 : b.isInStock) - Number(a === null || a === void 0 ? void 0 : a.isInStock))) ||
[]),
itemsCount: cartApi.items_count || 0,
itemsQty: cartApi.items_qty || 0,
customer: cartApi.customer
? dataFormatter.formatCartLoggedInCustomer(cartApi.customer)
: null,
billingAddress: cartApi.billing_address
? dataFormatter.formatCartAddress(cartApi.billing_address)
: null,
origOrderId: cartApi.orig_order_id || 0,
currency: {
globalCurrencyCode: ((_d = cartApi.currency) === null || _d === void 0 ? void 0 : _d.global_currency_code) || '',
baseCurrencyCode: ((_e = cartApi.currency) === null || _e === void 0 ? void 0 : _e.base_currency_code) || '',
storeCurrencyCode: ((_f = cartApi.currency) === null || _f === void 0 ? void 0 : _f.store_currency_code) || '',
quoteCurrencyCode: ((_g = cartApi.currency) === null || _g === void 0 ? void 0 : _g.quote_currency_code) || '',
storeToBaseRate: ((_h = cartApi.currency) === null || _h === void 0 ? void 0 : _h.store_to_base_rate) || 0,
storeToQuoteRate: ((_j = cartApi.currency) === null || _j === void 0 ? void 0 : _j.store_to_quote_rate) || 0,
baseToGlobalRate: ((_k = cartApi.currency) === null || _k === void 0 ? void 0 : _k.base_to_global_rate) || 0,
baseToQuoteRate: ((_l = cartApi.currency) === null || _l === void 0 ? void 0 : _l.base_to_quote_rate) || 0,
},
customerIsGuest: cartApi.customer_is_guest || false,
customerNoteNotify: cartApi.customer_note_notify || false,
customerTaxClassId: cartApi.customer_tax_class_id || 0,
storeId: cartApi.store_id || 0,
shippingAssignments: (_p = (_o = (_m = cartApi.extension_attributes) === null || _m === void 0 ? void 0 : _m.shipping_assignments) === null || _o === void 0 ? void 0 : _o.map) === null || _p === void 0 ? void 0 : _p.call(_o, (s) => {
var _a, _b, _c;
return ({
shipping: {
address: s.shipping.address
? dataFormatter.formatCartAddress(s.shipping.address)
: null,
method: ((_a = s.shipping) === null || _a === void 0 ? void 0 : _a.method) || '',
},
items: (((_c = (_b = s.items).map) === null || _c === void 0 ? void 0 : _c.call(_b, dataFormatter.formatCartItem)) ||
[]),
});
}),
};
},
formatCartTotal: (cartTotalApi) => {
var _a, _b, _c;
if (!cartTotalApi)
return null;
return {
grandTotal: cartTotalApi.grand_total || 0,
baseGrandTotal: cartTotalApi.base_grand_total || 0,
subtotal: cartTotalApi.subtotal || 0,
baseSubtotal: cartTotalApi.base_subtotal || 0,
discountAmount: cartTotalApi.discount_amount || 0,
baseDiscountAmount: cartTotalApi.base_discount_amount || 0,
subtotalWithDiscount: cartTotalApi.subtotal_with_discount || 0,
baseSubtotalWithDiscount: cartTotalApi.base_subtotal_with_discount || 0,
shippingAmount: cartTotalApi.shipping_amount || 0,
baseShippingAmount: cartTotalApi.base_shipping_amount || 0,
shippingDiscountAmount: cartTotalApi.shipping_discount_amount || 0,
baseShippingDiscountAmount: cartTotalApi.base_shipping_discount_amount || 0,
taxAmount: cartTotalApi.tax_amount || 0,
baseTaxAmount: cartTotalApi.base_tax_amount || 0,
weeeTaxAppliedAmount: cartTotalApi.weee_tax_applied_amount || 0,
shippingTaxAmount: cartTotalApi.shipping_tax_amount || 0,
baseShippingTaxAmount: cartTotalApi.base_shipping_tax_amount || 0,
subtotalInclTax: cartTotalApi.subtotal_incl_tax || 0,
shippingInclTax: cartTotalApi.shipping_incl_tax || 0,
baseShippingInclTax: cartTotalApi.base_shipping_incl_tax || 0,
baseCurrencyCode: cartTotalApi.base_currency_code || '',
quoteCurrencyCode: cartTotalApi.quote_currency_code || '',
itemsQty: cartTotalApi.items_qty || 0,
coupon: {
couponCode: cartTotalApi.coupon_code || '',
couponDescription: ((_a = cartTotalApi === null || cartTotalApi === void 0 ? void 0 : cartTotalApi.extension_attributes) === null || _a === void 0 ? void 0 : _a.coupon_description_text) || '',
},
items: ((_c = (_b = cartTotalApi.items) === null || _b === void 0 ? void 0 : _b.map) === null || _c === void 0 ? void 0 : _c.call(_b, (item) => ({
itemId: item.item_id || 0,
price: item.price || 0,
basePrice: item.base_price || 0,
qty: item.qty || 0,
rowTotal: item.row_total || 0,
baseRowTotal: item.base_row_total || 0,
rowTotalWithDiscount: item.row_total_with_discount || 0,
taxAmount: item.tax_amount || 0,
baseTaxAmount: item.base_tax_amount || 0,
taxPercent: item.tax_percent || 0,
discountAmount: item.discount_amount || 0,
baseDiscountAmount: item.base_discount_amount || 0,
discountPercent: item.discount_percent || 0,
priceInclTax: item.price_incl_tax || 0,
basePriceInclTax: item.base_price_incl_tax || 0,
rowTotalInclTax: item.row_total_incl_tax || 0,
baseRowTotalInclTax: item.base_row_total_incl_tax || 0,
options: item.options || '',
weeeTaxAppliedAmount: item.weee_tax_applied_amount || 0,
weeeTaxApplied: item.weee_tax_applied || 0,
name: item.name || '',
}))) || [],
totalSegments: cartTotalApi.total_segments || [],
};
},
formatPaymentMethod: (methods) => {
if (!methods)
return null;
return methods === null || methods === void 0 ? void 0 : methods.map((method) => ({
code: (method === null || method === void 0 ? void 0 : method.payment_code) || '',
title: (method === null || method === void 0 ? void 0 : method.payment_title) || '',
thumbnail: (method === null || method === void 0 ? void 0 : method.payment_thumbnail) || '',
}));
},
formatPaymentInformation: (paymentInformationApi) => {
var _a;
if (!paymentInformationApi)
return null;
return {
paymentMethods: dataFormatter.formatPaymentMethod((_a = paymentInformationApi === null || paymentInformationApi === void 0 ? void 0 : paymentInformationApi.extension_attributes) === null || _a === void 0 ? void 0 : _a.payment_detail_info) || [],
totals: dataFormatter.formatCartTotal(paymentInformationApi.totals),
};
},
formatOrderConfirmation: (orderConfirmationApi) => {
if (!orderConfirmationApi)
return null;
return {
isSuccess: orderConfirmationApi.is_success || false,
orderInfo: dataFormatter.formatOrder(orderConfirmationApi.order_info),
};
},
formatCoupons: (couponListApi) => {
var _a;
if (!((_a = couponListApi === null || couponListApi === void 0 ? void 0 : couponListApi.items) === null || _a === void 0 ? void 0 : _a.length))
return null;
return couponListApi.items.map((couponApi) => ({
code: (couponApi === null || couponApi === void 0 ? void 0 : couponApi.code) || '',
name: (couponApi === null || couponApi === void 0 ? void 0 : couponApi.name) || '',
thumbnail: (couponApi === null || couponApi === void 0 ? void 0 : couponApi.thumbnail) || '',
description: (couponApi === null || couponApi === void 0 ? void 0 : couponApi.expired_date) || '',
}));
},
formatShippings: (shippingsApi) => {
if (!shippingsApi)
return [];
return shippingsApi.map((shippingApi) => {
var _a;
return ({
carrierCode: shippingApi.carrier_code || '',
methodCode: shippingApi.method_code || '',
title: shippingApi.carrier_title || '',
description: shippingApi.method_title || '',
price: (shippingApi === null || shippingApi === void 0 ? void 0 : shippingApi.base_amount) || 0,
thumbnail: ((_a = shippingApi === null || shippingApi === void 0 ? void 0 : shippingApi.extension_attributes) === null || _a === void 0 ? void 0 : _a.thumbnail) || '',
});
});
},
};
var index = /*#__PURE__*/Object.freeze({
__proto__: null,
dataFormatter: dataFormatter
});
// You can include shared interfaces/types in a separate file
// and then use them in any component by importing them. For
// example, to import the interface below do:
//
var GenderLabel;
(function (GenderLabel) {
GenderLabel["MALE"] = "gender.male";
GenderLabel["FEMALE"] = "gender.female";
GenderLabel["OTHER"] = "gender.other";
})(GenderLabel || (GenderLabel = {}));
const DATE_FORMAT_API = 'yyyy-MM-dd';
const DATE_FORMAT = 'dd-MM-yyyy';
var types = /*#__PURE__*/Object.freeze({
__proto__: null,
get GenderLabel () { return GenderLabel; },
DATE_FORMAT_API: DATE_FORMAT_API,
DATE_FORMAT: DATE_FORMAT
});
export { apiTypes as ApiTypes, index as DataFormatter, dataTypes as DataTypes, types as Types };