{"version":3,"file":"product-2df0c4c0.js","sources":["../../client/packages/utils/src/normalizers/product.ts"],"sourcesContent":["import type {\n Product,\n ProductAttribute,\n NormalizedProductAttribute, \n ProductStockTag,\n ProductListItem,\n} from \"@songfinch/types/types\";\n\nimport {isNumber} from \"../validators\";\n\nexport const normalizeProductAttribute = (productAttributes: ProductAttribute[]): NormalizedProductAttribute | undefined => {\n if (!productAttributes) return undefined;\n const normalizedProductAttributes: NormalizedProductAttribute = {};\n\n productAttributes.forEach((productAttribute) => {\n const attributeKey = productAttribute.description.toLowerCase();\n normalizedProductAttributes[attributeKey] = {\n title: productAttribute.description,\n values: productAttribute.product_options_attributes.map(attributeValue => {\n if (productAttribute.select_type === \"color\") {\n return {\n key: attributeValue.description,\n value: attributeValue.description,\n color: attributeValue.hex_color,\n };\n } else {\n return {\n key: attributeValue.description,\n value: attributeValue.description,\n image: attributeValue.image,\n };\n }\n\n }),\n type: productAttribute.select_type || \"select\"\n };\n });\n\n return normalizedProductAttributes;\n};\n\nexport const normalizeProductOutOfStock = (inStock: number | null | undefined): boolean => {\n if (!isNumber(inStock) || inStock !== 0) return false;\n return true;\n};\n\nexport const normalizeProductStockTag = (product: Product | ProductListItem): ProductStockTag | undefined => {\n if (!product.tracks_inventory) return undefined;\n const stock = product.in_stock;\n if (!isNumber(stock) || stock >= 10) return undefined;\n if (normalizeProductOutOfStock(stock)) return {label: \"Out of Stock\", tagColor: \"black-20\"};\n if (stock === 1) return {label: \"Last One\", tagColor: \"blue\"};\n if (stock < 5) return {label: \"Only a Few Left\", tagColor: \"blue\"};\n return {label: \"Running Low\", tagColor: \"blue\"};\n};"],"names":["normalizeProductAttribute","productAttributes","normalizedProductAttributes","productAttribute","attributeKey","attributeValue","normalizeProductOutOfStock","inStock","isNumber","normalizeProductStockTag","product","stock"],"mappings":"4oBAUa,MAAAA,EAA6BC,GAAkF,CACxH,GAAI,CAACA,EAA0B,OAC/B,MAAMC,EAA0D,CAAA,EAE9C,OAAAD,EAAA,QAASE,GAAqB,CACtC,MAAAC,EAAeD,EAAiB,YAAY,YAAY,EAC9DD,EAA4BE,CAAY,EAAI,CACxC,MAAOD,EAAiB,YACxB,OAAQA,EAAiB,2BAA2B,IAAsBE,GAClEF,EAAiB,cAAgB,QAC1B,CACH,IAAKE,EAAe,YACpB,MAAOA,EAAe,YACtB,MAAOA,EAAe,SAAA,EAGnB,CACH,IAAKA,EAAe,YACpB,MAAOA,EAAe,YACtB,MAAOA,EAAe,KAAA,CAIjC,EACD,KAAMF,EAAiB,aAAe,QAAA,CAC1C,CACH,EAEMD,CACX,EAEaI,EAA8BC,GACnC,GAACC,EAASD,CAAO,GAAKA,IAAY,GAI7BE,EAA4BC,GAAoE,CACzG,GAAI,CAACA,EAAQ,iBAAyB,OACtC,MAAMC,EAAQD,EAAQ,SACtB,GAAI,GAACF,EAASG,CAAK,GAAKA,GAAS,IACjC,OAAIL,EAA2BK,CAAK,EAAU,CAAC,MAAO,eAAgB,SAAU,UAAU,EACtFA,IAAU,EAAU,CAAC,MAAO,WAAY,SAAU,MAAM,EACxDA,EAAQ,EAAU,CAAC,MAAO,kBAAmB,SAAU,MAAM,EAC1D,CAAC,MAAO,cAAe,SAAU,MAAM,CAClD"}