@neowhale/storefront 0.2.21 → 0.2.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3147,13 +3147,24 @@ function buildDefaultSections(data) {
3147
3147
  config: { align: "center" }
3148
3148
  });
3149
3149
  }
3150
+ const totalMg = toNum(cf?.total_mg_per_package ?? cf?.total_mg);
3151
+ const mgPerPiece = toNum(cf?.mg_per_piece);
3152
+ const piecesPerPkg = toNum(cf?.pieces_per_package);
3153
+ const isEdible = totalMg != null || mgPerPiece != null || piecesPerPkg != null;
3150
3154
  const thca = toNum(cf?.thca_percentage);
3151
3155
  const thc = toNum(cf?.d9_percentage);
3152
3156
  const cbd = toNum(cf?.cbd_total);
3153
3157
  const stats = [];
3154
- if (thca != null) stats.push({ label: "THCa", value: `${thca.toFixed(thca >= 1 ? 1 : 2)}%` });
3155
- if (thc != null) stats.push({ label: "\u03949 THC", value: `${thc.toFixed(thc >= 1 ? 1 : 2)}%` });
3156
- if (cbd != null) stats.push({ label: "CBD", value: `${cbd.toFixed(cbd >= 1 ? 1 : 2)}%` });
3158
+ if (isEdible) {
3159
+ if (totalMg != null) stats.push({ label: "Total MG", value: `${fmtMg(totalMg)}` });
3160
+ if (mgPerPiece != null) stats.push({ label: "Per Piece", value: `${fmtMg(mgPerPiece)}mg` });
3161
+ if (piecesPerPkg != null) stats.push({ label: "Pieces", value: `${piecesPerPkg}` });
3162
+ if (thc != null) stats.push({ label: "\u03949 THC", value: `${thc.toFixed(thc >= 1 ? 1 : 2)}%` });
3163
+ } else {
3164
+ if (thca != null) stats.push({ label: "THCa", value: `${thca.toFixed(thca >= 1 ? 1 : 2)}%` });
3165
+ if (thc != null) stats.push({ label: "\u03949 THC", value: `${thc.toFixed(thc >= 1 ? 1 : 2)}%` });
3166
+ if (cbd != null) stats.push({ label: "CBD", value: `${cbd.toFixed(cbd >= 1 ? 1 : 2)}%` });
3167
+ }
3157
3168
  if (stats.length > 0) {
3158
3169
  sections.push({
3159
3170
  id: "auto-stats",
@@ -3162,6 +3173,24 @@ function buildDefaultSections(data) {
3162
3173
  content: { stats }
3163
3174
  });
3164
3175
  }
3176
+ if (isEdible) {
3177
+ const servingDetails = [];
3178
+ const servingSize = toStr(cf?.serving_size);
3179
+ const ingredients = toStr(cf?.ingredients);
3180
+ const allergens = toStr(cf?.allergens);
3181
+ if (servingSize) servingDetails.push({ label: "Serving Size", value: servingSize });
3182
+ if (ingredients) servingDetails.push({ label: "Ingredients", value: ingredients });
3183
+ if (allergens) servingDetails.push({ label: "Allergens", value: allergens });
3184
+ if (servingDetails.length > 0) {
3185
+ sections.push({
3186
+ id: "auto-serving",
3187
+ type: "stats",
3188
+ order: order++,
3189
+ content: { stats: servingDetails },
3190
+ config: { layout: "list" }
3191
+ });
3192
+ }
3193
+ }
3165
3194
  const profileDetails = [];
3166
3195
  const genetics = toStr(cf?.genetics);
3167
3196
  const terpenes = toStr(cf?.terpenes);
@@ -3233,6 +3262,9 @@ function toNum(v) {
3233
3262
  const n = Number(v);
3234
3263
  return Number.isFinite(n) ? n : null;
3235
3264
  }
3265
+ function fmtMg(mg) {
3266
+ return mg === Math.floor(mg) ? `${mg}mg` : `${mg.toFixed(1)}mg`;
3267
+ }
3236
3268
  function toStr(v) {
3237
3269
  if (v == null || v === "") return null;
3238
3270
  return String(v);