UNPKG

@hhgtech/hhg-components

Version:
247 lines (241 loc) • 10.4 kB
'use strict'; var constants$1 = require('./constants-961f54ac.js'); require('./index-ec32050c.js'); var index = require('./index-0a047edc.js'); var formatString = require('string-format'); var constants = require('./constants-b53fd629.js'); var constantsDomainLocales = require('./constantsDomainLocales.js'); function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; } var formatString__default = /*#__PURE__*/_interopDefault(formatString); const formatSponsor = (sponsor) => { if (!sponsor) return {}; return { title: sponsor.title, logo: sponsor.logo, link: sponsor.link, }; }; const formatReviewedCategory = (data) => { return { postTitle: data.post_title, permalink: data.permalink, }; }; const formatFaqsCategory = (data) => { return { title: data.title, content: data.content, }; }; const formatCategory = (category) => { var _a, _b; if (!category) return {}; return { termId: category.term_id || null, sponsor: category.sponsor ? formatSponsor(category.sponsor) : null, isSponsored: category.is_sponsored || null, categoryName: category.cat_name || category.name || null, name: category.name || null, iconUrl: category.icon || '', slugName: category.category_nicename || null, description: category.description || null, featureImage: category.thumbnail || category.image || null, displayName: category.name || null, parent: category.parent || null, permalink: category.permalink || null, slug: category.slug || null, childCates: ((_a = category.child_cates) === null || _a === void 0 ? void 0 : _a.map((childCate) => { return formatCategory(childCate); })) || [], thumnailColor: category.thumnail_color || ['#FFEAF1', '#E0E9FB', '#FFF9EB', '#F2FCF7', '#F3F3F3'][(Math.random() * 5) | 0], colorFeatureImage: category.color_feature_image || null, imageColor: category.image_color || null, textColor: category.text_color || null, catParent: ((_b = category.cat_parent) === null || _b === void 0 ? void 0 : _b.name) ? { name: category.cat_parent.name, permalink: category.cat_parent.permalink, } : {}, metaTag: category.meta_tag || '', reviewedBy: category.reviewed_by ? formatReviewedCategory(category.reviewed_by) : null, reviewedDate: category.reviewed_date || '', faqs: category.faqs ? category.faqs.map((faq) => formatFaqsCategory(faq)) : null, customizedUrl: category.customized_url || null, }; }; const formatHealthTool = (healthTool) => { var _a, _b; if (!healthTool) return {}; const isBot = (_a = healthTool.link) === null || _a === void 0 ? void 0 : _a.includes('/bot/'); const hasFilPrefix = (_b = healthTool.link) === null || _b === void 0 ? void 0 : _b.startsWith('/fil/'); const link = healthTool.link ? healthTool.link.startsWith('http') ? healthTool.link : isBot ? healthTool.link : hasFilPrefix ? healthTool.link .replace('/health-tools/', '/') .replace('/fil/', '/fil/health-tools/') : `/health-tools${healthTool.link.replace('/health-tools/', '/')}` : undefined; return { icon: healthTool.icon, link, subtitle: healthTool.subtitle, title: healthTool.title, isMobileAppTool: !!(healthTool === null || healthTool === void 0 ? void 0 : healthTool.is_mobile_app_tool), }; }; const formatSpecialties = (specialties) => { var _a, _b, _c, _d, _e; if (!specialties || !(specialties === null || specialties === void 0 ? void 0 : specialties.object_id)) return {}; return { thumbnail: ((_a = specialties === null || specialties === void 0 ? void 0 : specialties.object_id) === null || _a === void 0 ? void 0 : _a.logo) || '', link: ((_b = specialties === null || specialties === void 0 ? void 0 : specialties.object_id) === null || _b === void 0 ? void 0 : _b.slug) || '', subtitle: ((_c = specialties.object_id) === null || _c === void 0 ? void 0 : _c.name) || '', name: ((_d = specialties.object_id) === null || _d === void 0 ? void 0 : _d.name) || '', slug: ((_e = specialties.object_id) === null || _e === void 0 ? void 0 : _e.slug) || '', }; }; const formatHospital = (hospital) => { var _a, _b, _c, _d, _e; if (!hospital || !(hospital === null || hospital === void 0 ? void 0 : hospital.object_id)) return {}; return { id: (_a = hospital.object_id) === null || _a === void 0 ? void 0 : _a.id, name: ((_b = hospital.object_id) === null || _b === void 0 ? void 0 : _b.name) || '', logo: ((_c = hospital === null || hospital === void 0 ? void 0 : hospital.object_id) === null || _c === void 0 ? void 0 : _c.logo) || '', description: ((_d = hospital.object_id) === null || _d === void 0 ? void 0 : _d.description) || '', slug: ((_e = hospital.object_id) === null || _e === void 0 ? void 0 : _e.slug) || '', }; }; const getTogetherUserPostsApiPath = (locale, isMarryBaby, apiDomain, params) => { const apiUrl = apiDomain || `https://together.hellohealthgroup.com/`; return (apiUrl + 'api/v1/' + formatString__default["default"](constants.TOGETHER_PATHS.GET_USER_POSTS, Object.assign(Object.assign({}, params), { websiteUrl: isMarryBaby ? 'https://marrybaby.vn' : `https://${constantsDomainLocales.domainLocales[locale]}` }))); }; const getCareSearchUrl = ({ type, specialtySlug, locale, }) => { var _a, _b; return `${(_a = constants$1.LOCALIZED_SLUGS[locale]) === null || _a === void 0 ? void 0 : _a.ALL}/${((_b = constants$1.LOCALIZED_SLUGS[locale]) === null || _b === void 0 ? void 0 : _b[type]) || 'doctor'}/${specialtySlug !== null && specialtySlug !== void 0 ? specialtySlug : ''}`; }; const formatSpotlightsList = (spotlight) => { if (!spotlight) return {}; return { id: spotlight.ID, name: spotlight.name, permalink: spotlight.permalink, image: (spotlight === null || spotlight === void 0 ? void 0 : spotlight.small_banner) || (spotlight === null || spotlight === void 0 ? void 0 : spotlight.image) || '', imageMedium: (spotlight === null || spotlight === void 0 ? void 0 : spotlight.image_medium) || null, imageThumbnail: (spotlight === null || spotlight === void 0 ? void 0 : spotlight.image_thumbnail) || null, startDate: spotlight === null || spotlight === void 0 ? void 0 : spotlight.start_date, endDate: spotlight === null || spotlight === void 0 ? void 0 : spotlight.end_date, buttonDisplay: spotlight.button_display || null, }; }; const checkAvailableSpotlight = (spotlight) => { const today = new Date(); if (spotlight === null || spotlight === void 0 ? void 0 : spotlight.startDate) { const startDate = new Date(spotlight.startDate); if (today.getTime() < startDate.getTime()) return false; } if (spotlight === null || spotlight === void 0 ? void 0 : spotlight.endDate) { const endDate = new Date(spotlight.endDate); if (today.getTime() > endDate.getTime()) return false; } return true; }; const formatVideoItem = (data) => { if (typeof data === 'undefined' || !data) return null; return { id: data.ID || '', videoId: data.video_id || '', url: data.video_url || '', title: data.video_title || '', type: data.type || index.VideoType.VIDEO, totalView: data.total_view || 0, description: data.description || '', createTime: data.create_time || '', duration: data.duration || 0, image: data.image || '', imageMedium: data.image_medium || '', imageThumbnail: data.image_thumbnail || '', active: false, articleLink: data.article_link || '', }; }; function hexToRgb(hex, returnObj = false) { let alpha = false, h = hex.slice(hex.startsWith('#') ? 1 : 0); if (h.length === 3) h = [...h].map((x) => x + x).join(''); else if (h.length === 8) alpha = true; h = parseInt(h, 16); const obj = { r: h >>> (alpha ? 24 : 16), g: (h & (alpha ? 0x00ff0000 : 0x00ff00)) >>> (alpha ? 16 : 8), b: (h & (alpha ? 0x0000ff00 : 0x0000ff)) >>> (alpha ? 8 : 0), }; return returnObj ? obj : 'rgb' + (alpha ? 'a' : '') + '(' + obj.r + ', ' + obj.g + ', ' + obj.b + (alpha ? `, ${h & 0x000000ff}` : '') + ')'; } function rgbToHsb(r, g, b) { r /= 255; g /= 255; b /= 255; const v = Math.max(r, g, b), n = v - Math.min(r, g, b); const h = n === 0 ? 0 : n && v === r ? (g - b) / n : v === g ? 2 + (b - r) / n : 4 + (r - g) / n; return [60 * (h < 0 ? h + 6 : h), v && (n / v) * 100, v * 100]; } function hsbToRgb(h, s, b) { s /= 100; b /= 100; const k = (n) => (n + h / 60) % 6; const f = (n) => b * (1 - s * Math.max(0, Math.min(k(n), 4 - k(n), 1))); return [255 * f(5), 255 * f(3), 255 * f(1)]; } exports.checkAvailableSpotlight = checkAvailableSpotlight; exports.formatCategory = formatCategory; exports.formatHealthTool = formatHealthTool; exports.formatHospital = formatHospital; exports.formatSpecialties = formatSpecialties; exports.formatSpotlightsList = formatSpotlightsList; exports.formatVideoItem = formatVideoItem; exports.getCareSearchUrl = getCareSearchUrl; exports.getTogetherUserPostsApiPath = getTogetherUserPostsApiPath; exports.hexToRgb = hexToRgb; exports.hsbToRgb = hsbToRgb; exports.rgbToHsb = rgbToHsb;