@aglyn/plugins-commerce 1.31.0 → 1.32.0

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.
Files changed (118) hide show
  1. package/README.md +4 -0
  2. package/package.json +13 -13
  3. package/src/lib/components/cart.js +35 -15
  4. package/src/lib/components/cart.js.map +1 -1
  5. package/src/lib/components/commerce-console-page.js +6 -0
  6. package/src/lib/components/commerce-console-page.js.map +1 -1
  7. package/src/lib/components/console/currencies-card.component.d.ts +21 -0
  8. package/src/lib/components/console/currencies-card.component.js +408 -0
  9. package/src/lib/components/console/currencies-card.component.js.map +1 -0
  10. package/src/lib/components/console/product-add-ons-fields.component.d.ts +13 -0
  11. package/src/lib/components/console/product-add-ons-fields.component.js +74 -2
  12. package/src/lib/components/console/product-add-ons-fields.component.js.map +1 -1
  13. package/src/lib/components/console/product-editor-dialog.component.js +42 -1
  14. package/src/lib/components/console/product-editor-dialog.component.js.map +1 -1
  15. package/src/lib/components/console/product-fixed-prices-fields.component.d.ts +25 -0
  16. package/src/lib/components/console/product-fixed-prices-fields.component.js +112 -0
  17. package/src/lib/components/console/product-fixed-prices-fields.component.js.map +1 -0
  18. package/src/lib/components/console/reservations-card.component.js +32 -15
  19. package/src/lib/components/console/reservations-card.component.js.map +1 -1
  20. package/src/lib/components/console/shipping-settings-card.component.js +100 -1
  21. package/src/lib/components/console/shipping-settings-card.component.js.map +1 -1
  22. package/src/lib/components/console/store-settings-card.component.js +1 -1
  23. package/src/lib/components/console/store-settings-card.component.js.map +1 -1
  24. package/src/lib/components/console/use-currency-setup.d.ts +20 -0
  25. package/src/lib/components/console/use-currency-setup.js +61 -0
  26. package/src/lib/components/console/use-currency-setup.js.map +1 -0
  27. package/src/lib/components/currency-selector.d.ts +36 -0
  28. package/src/lib/components/currency-selector.js +157 -0
  29. package/src/lib/components/currency-selector.js.map +1 -0
  30. package/src/lib/components/product-add-ons.d.ts +9 -1
  31. package/src/lib/components/product-add-ons.js +8 -4
  32. package/src/lib/components/product-add-ons.js.map +1 -1
  33. package/src/lib/components/product-choice-cards.d.ts +13 -1
  34. package/src/lib/components/product-choice-cards.js +5 -4
  35. package/src/lib/components/product-choice-cards.js.map +1 -1
  36. package/src/lib/components/product-detail.d.ts +8 -0
  37. package/src/lib/components/product-detail.js +38 -11
  38. package/src/lib/components/product-detail.js.map +1 -1
  39. package/src/lib/components/product-grid.d.ts +2 -0
  40. package/src/lib/components/product-grid.js +22 -9
  41. package/src/lib/components/product-grid.js.map +1 -1
  42. package/src/lib/components/related-products.js +6 -2
  43. package/src/lib/components/related-products.js.map +1 -1
  44. package/src/lib/components/shopper-currency.d.ts +108 -0
  45. package/src/lib/components/shopper-currency.js +262 -0
  46. package/src/lib/components/shopper-currency.js.map +1 -0
  47. package/src/lib/components/wishlist.js +7 -1
  48. package/src/lib/components/wishlist.js.map +1 -1
  49. package/src/lib/declarations.server.js +39 -0
  50. package/src/lib/declarations.server.js.map +1 -1
  51. package/src/lib/model/commerce-currency-setup.d.ts +79 -0
  52. package/src/lib/model/commerce-currency-setup.js +124 -0
  53. package/src/lib/model/commerce-currency-setup.js.map +1 -0
  54. package/src/lib/model/commerce-currency.d.ts +215 -0
  55. package/src/lib/model/commerce-currency.js +511 -0
  56. package/src/lib/model/commerce-currency.js.map +1 -0
  57. package/src/lib/model/commerce-orders.d.ts +17 -0
  58. package/src/lib/model/commerce-orders.js +10 -5
  59. package/src/lib/model/commerce-orders.js.map +1 -1
  60. package/src/lib/model/commerce-record-routes.js +26 -1
  61. package/src/lib/model/commerce-record-routes.js.map +1 -1
  62. package/src/lib/model/commerce-reservations.d.ts +6 -0
  63. package/src/lib/model/commerce-reservations.js.map +1 -1
  64. package/src/lib/model/commerce-shipping.d.ts +22 -1
  65. package/src/lib/model/commerce-shipping.js +31 -2
  66. package/src/lib/model/commerce-shipping.js.map +1 -1
  67. package/src/lib/model/commerce.d.ts +6 -0
  68. package/src/lib/model/commerce.js.map +1 -1
  69. package/src/lib/model/index.d.ts +2 -0
  70. package/src/lib/model/index.js +2 -0
  71. package/src/lib/model/index.js.map +1 -1
  72. package/src/lib/model/order-figures.js +9 -2
  73. package/src/lib/model/order-figures.js.map +1 -1
  74. package/src/lib/model/product-modifiers.d.ts +5 -0
  75. package/src/lib/model/product-modifiers.js.map +1 -1
  76. package/src/lib/server/billing-webhook.js +37 -24
  77. package/src/lib/server/billing-webhook.js.map +1 -1
  78. package/src/lib/server/cart-checkout.js +67 -11
  79. package/src/lib/server/cart-checkout.js.map +1 -1
  80. package/src/lib/server/cart.d.ts +12 -0
  81. package/src/lib/server/cart.js +50 -4
  82. package/src/lib/server/cart.js.map +1 -1
  83. package/src/lib/server/catalog.d.ts +5 -0
  84. package/src/lib/server/catalog.js +7 -0
  85. package/src/lib/server/catalog.js.map +1 -1
  86. package/src/lib/server/checkout.js +48 -12
  87. package/src/lib/server/checkout.js.map +1 -1
  88. package/src/lib/server/currency.d.ts +93 -0
  89. package/src/lib/server/currency.js +182 -0
  90. package/src/lib/server/currency.js.map +1 -0
  91. package/src/lib/server/order-notifications.js +4 -2
  92. package/src/lib/server/order-notifications.js.map +1 -1
  93. package/src/lib/server/product.d.ts +9 -0
  94. package/src/lib/server/product.js +12 -0
  95. package/src/lib/server/product.js.map +1 -1
  96. package/src/lib/server/refund.js +3 -3
  97. package/src/lib/server/refund.js.map +1 -1
  98. package/src/lib/server/site-chat-tools.d.ts +22 -0
  99. package/src/lib/server/site-chat-tools.js +369 -0
  100. package/src/lib/server/site-chat-tools.js.map +1 -0
  101. package/src/lib/server/site-chat-visitor.d.ts +24 -0
  102. package/src/lib/server/site-chat-visitor.js +39 -0
  103. package/src/lib/server/site-chat-visitor.js.map +1 -0
  104. package/src/lib/server/site-offers.d.ts +31 -0
  105. package/src/lib/server/site-offers.js +91 -0
  106. package/src/lib/server/site-offers.js.map +1 -0
  107. package/src/lib/server/stays-site-search.d.ts +20 -0
  108. package/src/lib/server/stays-site-search.js +78 -0
  109. package/src/lib/server/stays-site-search.js.map +1 -0
  110. package/src/lib/server.js +20 -0
  111. package/src/lib/server.js.map +1 -1
  112. package/src/lib/site-chat-tool-definitions.d.ts +26 -0
  113. package/src/lib/site-chat-tool-definitions.js +141 -0
  114. package/src/lib/site-chat-tool-definitions.js.map +1 -0
  115. package/src/lib/site.js +8 -0
  116. package/src/lib/site.js.map +1 -1
  117. package/src/lib/subprocessors.js +7 -0
  118. package/src/lib/subprocessors.js.map +1 -1
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../../libs/plugins/commerce/src/lib/components/console/currencies-card.component.tsx"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n'use client'\n\nimport { CardDisplay } from '@aglyn/shared-ui-jsx'\nimport { useSnackbar } from '@aglyn/shared-ui-snackstack'\nimport {\n Box,\n Button,\n Divider,\n FormControlLabel,\n IconButton,\n MenuItem,\n Stack,\n Switch,\n TextField,\n Typography,\n} from '@mui/material'\nimport { doc } from 'firebase/firestore'\nimport { useCallback, useState } from 'react'\nimport { pluginDocsHelp } from '@aglyn/aglyn'\nimport {\n useFirestore,\n useFirestoreDoc,\n useUser,\n writeGuardedBySeed,\n} from '@aglyn/tenant-feature-instance'\nimport { writeSiteWideChange } from '@aglyn/tenant-feature-instance/hooks/helpers/site-wide-change'\nimport {\n heldSaveLabel,\n isSeedChecking,\n seedCheckingText,\n useHeldSave,\n useSeedEdits,\n} from '@aglyn/tenant-feature-instance/hooks/use-seed-edits'\nimport * as CommerceModel from '../../model'\nimport { useCurrencySetup } from './use-currency-setup'\n\nexport interface CurrenciesCardProps {\n hostId: string\n}\n\n/** The price each currency's preview converts: 250 of the store currency. */\nconst SAMPLE_MAJOR = 250\n\n\n/**\n * Currencies (AGL-4248), beside Store settings: which other currencies the\n * store sells in, the rate each converts at (daily, or a manual one), its\n * price adjustment and rounding (off until turned on, as on Shopify), whether\n * its prices include tax, and whether shoppers get their own currency from\n * where they browse. Stored on `hosts/{hostId}/settings/store` under\n * `currencies`; the storefront and checkout read it through\n * `GET commerce/currency`.\n *\n * Same write guard as Store settings (AGL-1358): `currencies.currencies` is\n * an array, and a merge replaces an array wholesale, so a save from a seed\n * the server never confirmed would put a stale list back.\n */\nexport function CurrenciesCard(props: CurrenciesCardProps) {\n const { hostId } = props\n const firestore = useFirestore()\n const { data: user } = useUser()\n const { enqueueSnackbar } = useSnackbar()\n const {\n data: store,\n status: storeStatus,\n fromCache: storeFromCache,\n listen: storeListen,\n } = useFirestoreDoc<any>(\n () => doc(firestore, 'hosts', hostId, 'settings', 'store'),\n [firestore, hostId],\n )\n const base = CommerceModel.storeBaseCurrency(store)\n const saved = (store?.currencies ?? {}) as CommerceModel.StoreCurrencySettings\n const form = useSeedEdits<CommerceModel.StoreCurrencySettings>({\n enabled: saved.enabled === true,\n currencies: saved.currencies ?? [],\n autoDetect: saved.autoDetect !== false,\n })\n const current = form.values\n const list = current.currencies ?? []\n const checking = isSeedChecking({\n fromCache: storeFromCache,\n unreadable: storeStatus === 'error',\n })\n const { rates } = useCurrencySetup(hostId)\n const [adding, setAdding] = useState('')\n\n const setEntry = (index: number, patch: Partial<CommerceModel.StoreCurrency> | null) => {\n const next = [...list]\n if (patch === null) next.splice(index, 1)\n else next[index] = { ...next[index], ...patch }\n form.edit({ currencies: next })\n }\n // A whole entry, for a field whose clearing removes a key.\n const replaceEntry = (index: number, entry: CommerceModel.StoreCurrency) =>\n form.edit({ currencies: list.map((was, at) => (at === index ? entry : was)) })\n const addCurrency = (code: string) => {\n if (!code) return\n form.edit({ currencies: [...list, CommerceModel.newStoreCurrency(code)] })\n setAdding('')\n }\n const addable = CommerceModel.addableCurrencies(\n base,\n list.map((entry) => entry.code),\n )\n\n const handleSave = useCallback(async () => {\n const written = form.edits\n const verdict = await writeGuardedBySeed(\n {\n subject: 'currencies',\n unreadable: storeStatus === 'error',\n fromCache: storeFromCache,\n listen: storeListen,\n },\n async () => {\n // Prices on the live store change with no publish step, so the save\n // carries the site's cache drop with it, as Store settings does.\n await writeSiteWideChange({\n firestore,\n user,\n hostId,\n write: (batch) =>\n batch.set(\n doc(firestore, 'hosts', hostId, 'settings', 'store'),\n {\n currencies: {\n enabled: current.enabled === true,\n currencies: (current.currencies ?? []).map((entry) => ({\n code: entry.code,\n rounding: entry.rounding ?? 'none',\n bufferPct: CommerceModel.clampAdjustmentInput(String(entry.bufferPct ?? 0)),\n // Blank is the daily rate: the key is left off, never null.\n ...(entry.manualRate && entry.manualRate > 0 ? { manualRate: entry.manualRate } : {}),\n pricesIncludeTax: entry.pricesIncludeTax === true,\n })),\n autoDetect: current.autoDetect !== false,\n },\n },\n { merge: true },\n ),\n })\n },\n )\n if (!verdict.ok) {\n return void enqueueSnackbar(verdict.message, { variant: 'warning', persist: false })\n }\n form.settle(written)\n enqueueSnackbar('Currencies saved', { variant: 'success', persist: false })\n }, [current, form, firestore, hostId, user, enqueueSnackbar, storeStatus, storeFromCache, storeListen])\n const held = useHeldSave(handleSave, {\n checking,\n subject: 'currencies',\n onRefused: (message) => enqueueSnackbar(message, { variant: 'warning', persist: false }),\n })\n\n const sampleMinor = CommerceModel.majorToMinor(SAMPLE_MAJOR, base)\n\n return (\n <CardDisplay\n header={'Currencies'}\n help={pluginDocsHelp('currencies')}\n contentGutterX\n contentGutterY\n >\n <Stack spacing={1.5}>\n <FormControlLabel\n control={\n <Switch\n size=\"small\"\n checked={current.enabled === true}\n onChange={(event) => form.edit({ enabled: event.target.checked })}\n />\n }\n label=\"Sell in other currencies\"\n />\n <Typography variant=\"caption\" color=\"text.secondary\">\n {`Shoppers see and pay prices in their own currency. Stripe converts each payment and ` +\n `pays you in ${base}, less its conversion fee.`}\n </Typography>\n {current.enabled ? (\n <>\n <Typography variant=\"body2\" color=\"text.secondary\" data-testid=\"currency-rates-updated\">\n {rates?.asOfMs\n ? `Rates updated ${CommerceModel.ratesAsOfLabel(rates)} (European Central Bank, daily)`\n : 'Daily rates are not in yet: a currency without a manual rate sells in ' + base + ' until they are.'}\n </Typography>\n {list.map((entry, index) => (\n <Box key={entry.code}>\n <Divider sx={{ mb: 1.5 }} />\n <Stack spacing={1}>\n <Stack direction=\"row\" spacing={1} sx={{ alignItems: 'center' }}>\n <Typography variant=\"subtitle2\" sx={{ flex: 1 }}>\n {CommerceModel.currencyOptionLabel(entry.code)}\n </Typography>\n <IconButton\n size=\"small\"\n aria-label={`Remove ${entry.code}`}\n onClick={() => setEntry(index, null)}\n >\n {'✕'}\n </IconButton>\n </Stack>\n <Typography variant=\"body2\" color=\"text.secondary\" data-testid={`currency-rate-${entry.code}`}>\n {CommerceModel.currencyRateLabel(rates, base, entry)}\n </Typography>\n <Stack direction={{ xs: 'column', sm: 'row' }} spacing={1}>\n <TextField\n label={`Manual exchange rate (${entry.code})`}\n // Kept as typed until the field is left (as below).\n defaultValue={entry.manualRate ? String(entry.manualRate) : ''}\n placeholder=\"Daily rate\"\n onBlur={(event) => {\n const manualRate = CommerceModel.parseManualRateInput(event.target.value)\n const next = { ...entry }\n if (manualRate) next.manualRate = manualRate\n else delete next.manualRate\n replaceEntry(index, next)\n }}\n size=\"small\"\n sx={{ minWidth: 220 }}\n helperText={`${base} 1 = ${entry.code} this much. Blank uses the ${CommerceModel.dailyRateLabel(\n rates,\n base,\n entry.code,\n ).replace(/^Daily rate/, 'daily rate')}`}\n slotProps={{ htmlInput: { inputMode: 'decimal' } }}\n />\n <TextField\n label={`Price adjustment (%) (${entry.code})`}\n // Kept as typed until the field is left, so \"2.5\" can\n // be typed through \"2.\" without the dot being eaten.\n defaultValue={entry.bufferPct ? String(entry.bufferPct) : ''}\n placeholder=\"0\"\n onBlur={(event) =>\n setEntry(index, { bufferPct: CommerceModel.clampAdjustmentInput(event.target.value) })\n }\n size=\"small\"\n sx={{ minWidth: 220 }}\n helperText={\n '-90 to +100. Stripe’s currency conversion fee (about 1–2%) comes out of your ' +\n 'payout unless you raise prices here.'\n }\n slotProps={{ htmlInput: { inputMode: 'decimal' } }}\n />\n </Stack>\n <Stack direction={{ xs: 'column', sm: 'row' }} spacing={1} sx={{ alignItems: { sm: 'center' } }}>\n <FormControlLabel\n control={\n <Switch\n size=\"small\"\n checked={(entry.rounding ?? 'none') !== 'none'}\n onChange={(event) =>\n setEntry(index, { rounding: event.target.checked ? '99' : 'none' })\n }\n />\n }\n label={`Round converted prices (${entry.code})`}\n />\n {(entry.rounding ?? 'none') !== 'none' ? (\n <TextField\n label={`Round up to (${entry.code})`}\n value={entry.rounding}\n onChange={(event) =>\n setEntry(index, { rounding: event.target.value as CommerceModel.CurrencyRounding })\n }\n size=\"small\"\n select\n sx={{ minWidth: 220 }}\n >\n {CommerceModel.CURRENCY_ROUNDING_ENDINGS.map((value) => (\n <MenuItem key={value} value={value}>\n {CommerceModel.CURRENCY_ROUNDING_LABELS[value]}\n </MenuItem>\n ))}\n </TextField>\n ) : null}\n </Stack>\n <FormControlLabel\n control={\n <Switch\n size=\"small\"\n checked={entry.pricesIncludeTax === true}\n onChange={(event) => setEntry(index, { pricesIncludeTax: event.target.checked })}\n />\n }\n label={`Prices in ${entry.code} include tax`}\n />\n <Typography variant=\"caption\" color=\"text.secondary\">\n {'For shoppers who expect VAT or GST in the price. Tax is worked out by Stripe Tax, ' +\n 'so it needs a Stripe Tax registration in each country that pays in this currency.'}\n </Typography>\n <Typography variant=\"body2\" data-testid={`currency-preview-${entry.code}`}>\n {CommerceModel.currencyPreviewText(sampleMinor, base, entry, rates)}\n </Typography>\n </Stack>\n </Box>\n ))}\n <Divider />\n <TextField\n label=\"Add a currency\"\n value={adding}\n onChange={(event) => addCurrency(event.target.value)}\n size=\"small\"\n select\n sx={{ maxWidth: 320 }}\n disabled={!addable.length}\n >\n {addable.map((code) => (\n <MenuItem key={code} value={code}>\n {CommerceModel.currencyOptionLabel(code)}\n </MenuItem>\n ))}\n </TextField>\n <FormControlLabel\n control={\n <Switch\n size=\"small\"\n checked={current.autoDetect !== false}\n onChange={(event) => form.edit({ autoDetect: event.target.checked })}\n />\n }\n label=\"Show each shopper prices in their own currency, picked from where they are browsing\"\n />\n <Typography variant=\"caption\" color=\"text.secondary\">\n {'Shoppers can always switch with the Currency selector element; add it to your header ' +\n 'or footer in the Besigner. Rates are the European Central Bank’s, updated daily. Set a ' +\n 'fixed price in a currency on a product, add-on or shipping rate to skip conversion.'}\n </Typography>\n </>\n ) : null}\n <Button\n variant=\"contained\"\n color=\"primary\"\n size=\"small\"\n disabled={!form.dirty || held.saving}\n onClick={held.press}\n sx={{ alignSelf: 'flex-start' }}\n >\n {heldSaveLabel(held, 'Save currencies')}\n </Button>\n {form.dirty && checking ? (\n <Typography variant=\"body2\" color=\"text.secondary\" role=\"status\">\n {seedCheckingText('currencies')}\n </Typography>\n ) : null}\n </Stack>\n </CardDisplay>\n )\n}\nCurrenciesCard.displayName = 'CurrenciesCard'\n\nexport default CurrenciesCard\n"],"names":["CardDisplay","useSnackbar","Box","Button","Divider","FormControlLabel","IconButton","MenuItem","Stack","Switch","TextField","Typography","doc","useCallback","useState","pluginDocsHelp","useFirestore","useFirestoreDoc","useUser","writeGuardedBySeed","writeSiteWideChange","heldSaveLabel","isSeedChecking","seedCheckingText","useHeldSave","useSeedEdits","CommerceModel","useCurrencySetup","SAMPLE_MAJOR","CurrenciesCard","props","saved","current","hostId","firestore","data","user","enqueueSnackbar","store","status","storeStatus","fromCache","storeFromCache","listen","storeListen","base","storeBaseCurrency","currencies","form","enabled","autoDetect","values","list","checking","unreadable","rates","adding","setAdding","setEntry","index","patch","next","splice","edit","replaceEntry","entry","map","was","at","addCurrency","code","newStoreCurrency","addable","addableCurrencies","handleSave","written","edits","verdict","subject","write","batch","set","rounding","bufferPct","clampAdjustmentInput","String","manualRate","pricesIncludeTax","merge","ok","message","variant","persist","settle","held","onRefused","sampleMinor","majorToMinor","header","help","contentGutterX","contentGutterY","spacing","control","size","checked","onChange","event","target","label","color","data-testid","asOfMs","ratesAsOfLabel","sx","mb","direction","alignItems","flex","currencyOptionLabel","aria-label","onClick","currencyRateLabel","xs","sm","defaultValue","placeholder","onBlur","parseManualRateInput","value","minWidth","helperText","dailyRateLabel","replace","slotProps","htmlInput","inputMode","select","CURRENCY_ROUNDING_ENDINGS","CURRENCY_ROUNDING_LABELS","currencyPreviewText","maxWidth","disabled","length","dirty","saving","press","alignSelf","role","displayName"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;;AAEA,SAASA,WAAW,QAAQ,uBAAsB;AAClD,SAASC,WAAW,QAAQ,8BAA6B;AACzD,SACEC,GAAG,EACHC,MAAM,EACNC,OAAO,EACPC,gBAAgB,EAChBC,UAAU,EACVC,QAAQ,EACRC,KAAK,EACLC,MAAM,EACNC,SAAS,EACTC,UAAU,QACL,gBAAe;AACtB,SAASC,GAAG,QAAQ,qBAAoB;AACxC,SAASC,WAAW,EAAEC,QAAQ,QAAQ,QAAO;AAC7C,SAASC,cAAc,QAAQ,eAAc;AAC7C,SACEC,YAAY,EACZC,eAAe,EACfC,OAAO,EACPC,kBAAkB,QACb,iCAAgC;AACvC,SAASC,mBAAmB,QAAQ,gEAA+D;AACnG,SACEC,aAAa,EACbC,cAAc,EACdC,gBAAgB,EAChBC,WAAW,EACXC,YAAY,QACP,sDAAqD;AAC5D,YAAYC,mBAAmB,uBAAa;AAC5C,SAASC,gBAAgB,QAAQ,0BAAsB;AAMvD,2EAA2E,GAC3E,MAAMC,eAAe;AAGrB;;;;;;;;;;;;CAYC,GACD,OAAO,SAASC,eAAeC,KAA0B;cAkBzCC,mBAIDC;IArBb,MAAM,EAAEC,MAAM,EAAE,GAAGH;IACnB,MAAMI,YAAYlB;IAClB,MAAM,EAAEmB,MAAMC,IA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tEI,OAAM;;sCAER,KAAClG;4BAAWgF,SAAQ;4BAAUmB,OAAM;sCACjC,0FACC,4FACA;;;qBAGJ;8BACJ,KAAC3G;oBACCwF,SAAQ;oBACRmB,OAAM;oBACNN,MAAK;oBACLsC,UAAU,CAAC9F,KAAKgG,KAAK,IAAIlD,KAAKmD,MAAM;oBACpCxB,SAAS3B,KAAKoD,KAAK;oBACnBhC,IAAI;wBAAEiC,WAAW;oBAAa;8BAE7B9H,cAAcyE,MAAM;;gBAEtB9C,KAAKgG,KAAK,IAAI3F,yBACb,KAAC1C;oBAAWgF,SAAQ;oBAAQmB,OAAM;oBAAiBsC,MAAK;8BACrD7H,iBAAiB;qBAElB;;;;AAIZ;AACAM,eAAewH,WAAW,GAAG;AAE7B,eAAexH,eAAc"}
@@ -1,5 +1,6 @@
1
1
  import * as CommerceModel from '../../model';
2
2
  import { type ProductMediaPick } from './product-builder-fields.component';
3
+ import type { ConsoleCurrencySetup } from './use-currency-setup';
3
4
  type Patch = Partial<CommerceModel.HostProduct>;
4
5
  export interface ProductAddOnsFieldsProps {
5
6
  modifierGroups: readonly CommerceModel.ProductModifierGroup[];
@@ -10,6 +11,11 @@ export interface ProductAddOnsFieldsProps {
10
11
  update: (patch: Patch) => void;
11
12
  /** Opens the media browser for a choice's picture (AGL-4205); without it, no picture is chosen. */
12
13
  pick?: ProductMediaPick;
14
+ /**
15
+ * The store's other currencies (AGL-4248): with any, each choice may carry
16
+ * a fixed amount in them. Without, nothing currency-related is drawn.
17
+ */
18
+ currencies?: ConsoleCurrencySetup;
13
19
  }
14
20
  /**
15
21
  * What a choice's per-variant prices are called (AGL-4100): by the one
@@ -36,6 +42,13 @@ export declare function withWriteInName(group: CommerceModel.ProductModifierGrou
36
42
  * which refuses one).
37
43
  */
38
44
  export declare function withVariantPrice(option: CommerceModel.ProductModifierOption, variantId: string, raw: string): CommerceModel.ProductModifierOption;
45
+ /**
46
+ * A choice's fixed amount in another currency (AGL-4248), set or cleared, in
47
+ * minor units of that currency. A cleared amount converts again; with none
48
+ * left the field is dropped, never stored as `undefined`. Something that is
49
+ * not a price changes nothing.
50
+ */
51
+ export declare function withCurrencyPrice(option: CommerceModel.ProductModifierOption, code: string, raw: string): CommerceModel.ProductModifierOption;
39
52
  /**
40
53
  * A choice with its card changed (AGL-4205): its picture, its note, or what
41
54
  * it includes as a combo, typed one item per line. A cleared field is
@@ -107,6 +107,22 @@ function newId(prefix) {
107
107
  priceCentsByVariant: next
108
108
  }) : rest;
109
109
  }
110
+ /**
111
+ * A choice's fixed amount in another currency (AGL-4248), set or cleared, in
112
+ * minor units of that currency. A cleared amount converts again; with none
113
+ * left the field is dropped, never stored as `undefined`. Something that is
114
+ * not a price changes nothing.
115
+ */ export function withCurrencyPrice(option, code, raw) {
116
+ const major = CommerceModel.parseMajorInput(raw);
117
+ if (major === null) return option;
118
+ const { fixedPriceCents } = option, rest = _object_without_properties_loose(option, [
119
+ "fixedPriceCents"
120
+ ]);
121
+ const next = CommerceModel.withCurrencyAmount(fixedPriceCents, code, major === undefined ? undefined : CommerceModel.majorToMinor(major, code));
122
+ return next ? _extends({}, rest, {
123
+ fixedPriceCents: next
124
+ }) : rest;
125
+ }
110
126
  /**
111
127
  * A choice with its card changed (AGL-4205): its picture, its note, or what
112
128
  * it includes as a combo, typed one item per line. A cleared field is
@@ -288,9 +304,12 @@ function newId(prefix) {
288
304
  * the product, so editing it takes exactly what editing the product takes.
289
305
  * Memoized on its own props like every section of this editor (AGL-3423).
290
306
  */ export const ProductAddOnsFields = /*#__PURE__*/ memo(function ProductAddOnsFields(props) {
291
- const { modifierGroups, options, variants, update, pick } = props;
307
+ var _ref;
308
+ const { modifierGroups, options, variants, update, pick, currencies } = props;
292
309
  const helpId = useId();
293
310
  const [pricedByVariant, setPricedByVariant] = useState({});
311
+ const [inCurrenciesOpen, setInCurrenciesOpen] = useState({});
312
+ const others = (_ref = currencies == null ? void 0 : currencies.others) != null ? _ref : [];
294
313
  const [cardOpen, setCardOpen] = useState({});
295
314
  const setGroups = useCallback((groups)=>update({
296
315
  modifierGroups: groups
@@ -425,12 +444,13 @@ function newId(prefix) {
425
444
  children: group.nameOnOrder === true ? `The order says “${group.name || 'Size'}: ${((_group_options_ = group.options[0]) == null ? void 0 : _group_options_.name) || 'M'}”.` : `The order says “${((_group_options_1 = group.options[0]) == null ? void 0 : _group_options_1.name) || 'M'}”. Turn this on when a choice ` + 'doesn’t say what it is on its own, like a size.'
426
445
  }),
427
446
  group.options.map((option, optionIndex)=>{
428
- var _pricedByVariant_optionKey, _option_priceCentsByVariant, _cardOpen_optionKey, _option_note;
447
+ var _pricedByVariant_optionKey, _option_priceCentsByVariant, _cardOpen_optionKey, _inCurrenciesOpen_optionKey, _option_fixedPriceCents, _option_note;
429
448
  var _option_includes;
430
449
  const optionKey = `${group.id}:${option.id}`;
431
450
  const byVariantOpen = (_pricedByVariant_optionKey = pricedByVariant[optionKey]) != null ? _pricedByVariant_optionKey : Object.keys((_option_priceCentsByVariant = option.priceCentsByVariant) != null ? _option_priceCentsByVariant : {}).length > 0;
432
451
  const hasCard = Boolean(option.imageUrl || option.note || ((_option_includes = option.includes) == null ? void 0 : _option_includes.length));
433
452
  const cardShown = (_cardOpen_optionKey = cardOpen[optionKey]) != null ? _cardOpen_optionKey : hasCard;
453
+ const currenciesShown = (_inCurrenciesOpen_optionKey = inCurrenciesOpen[optionKey]) != null ? _inCurrenciesOpen_optionKey : Object.keys((_option_fixedPriceCents = option.fixedPriceCents) != null ? _option_fixedPriceCents : {}).length > 0;
434
454
  const choiceLabel = option.name || 'this choice';
435
455
  return /*#__PURE__*/ _jsxs(Box, {
436
456
  children: [
@@ -480,6 +500,14 @@ function newId(prefix) {
480
500
  })),
481
501
  children: byLabel
482
502
  }) : null,
503
+ others.length ? /*#__PURE__*/ _jsx(Button, {
504
+ size: "small",
505
+ "aria-expanded": currenciesShown,
506
+ onClick: ()=>setInCurrenciesOpen((open)=>_extends({}, open, {
507
+ [optionKey]: !currenciesShown
508
+ })),
509
+ children: 'Other currencies'
510
+ }) : null,
483
511
  /*#__PURE__*/ _jsx(Button, {
484
512
  size: "small",
485
513
  "aria-expanded": cardShown,
@@ -541,6 +569,50 @@ function newId(prefix) {
541
569
  ]
542
570
  })
543
571
  }) : null,
572
+ others.length && currencies ? /*#__PURE__*/ _jsx(Collapse, {
573
+ in: currenciesShown,
574
+ unmountOnExit: true,
575
+ children: /*#__PURE__*/ _jsxs(Stack, {
576
+ spacing: 1,
577
+ sx: {
578
+ pl: 2,
579
+ pt: 1.5
580
+ },
581
+ children: [
582
+ /*#__PURE__*/ _jsx(Typography, {
583
+ variant: "caption",
584
+ color: "text.secondary",
585
+ children: `What “${choiceLabel}” adds in each currency. Leave one blank to convert ` + 'the price above at the day’s rate.'
586
+ }),
587
+ /*#__PURE__*/ _jsx(Box, {
588
+ sx: {
589
+ display: 'grid',
590
+ gridTemplateColumns: {
591
+ xs: '1fr',
592
+ sm: 'repeat(3, minmax(0, 1fr))'
593
+ },
594
+ gap: 1
595
+ },
596
+ children: others.map((entry)=>{
597
+ var _option_priceCents;
598
+ var _option_fixedPriceCents;
599
+ return /*#__PURE__*/ _jsx(TextField, {
600
+ label: `Adds (${entry.code})`,
601
+ size: "small",
602
+ defaultValue: CommerceModel.minorToInput((_option_fixedPriceCents = option.fixedPriceCents) == null ? void 0 : _option_fixedPriceCents[entry.code], entry.code),
603
+ placeholder: CommerceModel.minorToInput(CommerceModel.amountMinorIn((_option_priceCents = option.priceCents) != null ? _option_priceCents : 0, currencies.base, entry, currencies.rates), entry.code),
604
+ onBlur: (event)=>replaceOption(groupIndex, optionIndex, withCurrencyPrice(modifierGroups[groupIndex].options[optionIndex], entry.code, event.target.value)),
605
+ slotProps: {
606
+ htmlInput: {
607
+ inputMode: 'decimal'
608
+ }
609
+ }
610
+ }, entry.code);
611
+ })
612
+ })
613
+ ]
614
+ })
615
+ }) : null,
544
616
  /*#__PURE__*/ _jsx(Collapse, {
545
617
  in: cardShown,
546
618
  unmountOnExit: true,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../../libs/plugins/commerce/src/lib/components/console/product-add-ons-fields.component.tsx"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n'use client'\n\nimport {\n Box,\n Button,\n Collapse,\n FormControlLabel,\n IconButton,\n Stack,\n Switch,\n TextField,\n Typography,\n} from '@mui/material'\nimport { memo, useCallback, useId, useState } from 'react'\nimport * as CommerceModel from '../../model'\nimport { PRODUCT_CHOICE_NOTE_MAX, PRODUCT_COMBO_ITEM_MAX, PRODUCT_COMBO_MAX_ITEMS } from '../../model/product-card-rules'\nimport { CardPictureField, type ProductMediaPick } from './product-builder-fields.component'\n\ntype Patch = Partial<CommerceModel.HostProduct>\n\nexport interface ProductAddOnsFieldsProps {\n modifierGroups: readonly CommerceModel.ProductModifierGroup[]\n /** The product's options, to name what a choice is priced by. */\n options: readonly CommerceModel.ProductOption[]\n /** The product's variants, each of which a choice may be priced on. */\n variants: readonly Pick<CommerceModel.ProductVariant, 'id' | 'options'>[]\n update: (patch: Patch) => void\n /** Opens the media browser for a choice's picture (AGL-4205); without it, no picture is chosen. */\n pick?: ProductMediaPick\n}\n\nfunction newId(prefix: string): string {\n return `${prefix}${Math.random().toString(36).slice(2, 10)}`\n}\n\n/** Dollars as typed, to whole cents; blank is free. */\nfunction centsFromDollars(value: string): number {\n const number = Math.round(Number(String(value).replace(/[^0-9.]/g, '')) * 100)\n return Number.isFinite(number) && number > 0 ? number : 0\n}\n\n/** Cents as the price field shows them; blank for free. */\nfunction dollarsFromCents(cents: number | undefined): string {\n return cents ? (cents / 100).toFixed(2) : ''\n}\n\n/**\n * What a choice's per-variant prices are called (AGL-4100): by the one\n * option a product varies by (\"Price by size\"), else by variant.\n */\nexport function priceByLabel(options: readonly Pick<CommerceModel.ProductOption, 'name'>[]): string {\n const named = options.filter((option) => option.name?.trim())\n return named.length === 1 ? `Price by ${named[0].name.trim().toLowerCase()}` : 'Price by variant'\n}\n\n/** A new group, as the console makes it from now on: shown on the website (AGL-4100). */\nexport function newAddOnGroup(): CommerceModel.ProductModifierGroup {\n return {\n id: newId('g'),\n name: '',\n min: 0,\n max: 1,\n online: true,\n options: [{ id: newId('o'), name: '', priceCents: 0 }],\n }\n}\n\n/**\n * A new write-in (write-ins): one field the shopper types into,\n * such as a name to print or an engraving. Required, shown on the website,\n * free until the merchant sets what it adds.\n */\nexport function newWriteInGroup(): CommerceModel.ProductModifierGroup {\n return {\n id: newId('g'),\n name: '',\n kind: 'text',\n min: 1,\n max: 1,\n maxLength: CommerceModel.DEFAULT_WRITE_IN_LENGTH,\n online: true,\n options: [{ id: newId('o'), name: '', priceCents: 0 }],\n }\n}\n\n/**\n * A write-in renamed: its one option carries the same name, so every reader\n * that names a pick by its option names the field.\n */\nexport function withWriteInName(\n group: CommerceModel.ProductModifierGroup,\n name: string,\n): Partial<CommerceModel.ProductModifierGroup> {\n return { name, options: group.options.map((option, at) => (at === 0 ? { ...option, name } : option)) }\n}\n\n/**\n * A choice's prices by variant with one variant's price set or cleared. A\n * cleared price follows the choice's own; with none left the field is\n * dropped, never stored as `undefined` (the save is a client-direct write,\n * which refuses one).\n */\nexport function withVariantPrice(\n option: CommerceModel.ProductModifierOption,\n variantId: string,\n raw: string,\n): CommerceModel.ProductModifierOption {\n const { priceCentsByVariant, ...rest } = option\n const next = { ...(priceCentsByVariant ?? {}) }\n if (raw.trim() === '') delete next[variantId]\n else next[variantId] = centsFromDollars(raw)\n return Object.keys(next).length ? { ...rest, priceCentsByVariant: next } : rest\n}\n\n/**\n * A choice with its card changed (AGL-4205): its picture, its note, or what\n * it includes as a combo, typed one item per line. A cleared field is\n * dropped, never stored as `undefined`.\n */\nexport function withChoiceCard(\n option: CommerceModel.ProductModifierOption,\n patch: { imageUrl?: string | null; note?: string | null; includes?: string | null },\n): CommerceModel.ProductModifierOption {\n const next: CommerceModel.ProductModifierOption = { ...option }\n if ('imageUrl' in patch) {\n const url = String(patch.imageUrl ?? '').trim()\n if (url) next.imageUrl = url\n else delete next.imageUrl\n }\n if ('note' in patch) {\n const note = String(patch.note ?? '').trim().slice(0, PRODUCT_CHOICE_NOTE_MAX)\n if (note) next.note = note\n else delete next.note\n }\n if ('includes' in patch) {\n const items = String(patch.includes ?? '')\n .split('\\n')\n .map((item) => item.trim().slice(0, PRODUCT_COMBO_ITEM_MAX))\n .filter(Boolean)\n .slice(0, PRODUCT_COMBO_MAX_ITEMS)\n if (items.length) next.includes = items\n else delete next.includes\n }\n return next\n}\n\ninterface WriteInFieldsProps {\n group: CommerceModel.ProductModifierGroup\n edit: (patch: Partial<CommerceModel.ProductModifierGroup>) => void\n remove: () => void\n}\n\n/**\n * One write-in in the editor (write-ins): what the field is\n * called, how long an answer can be, what a filled one adds, the note under\n * it, and whether it is required, numbers only and asked on the website.\n */\nfunction WriteInFields(props: WriteInFieldsProps) {\n const { group, edit, remove } = props\n const option = group.options[0]\n const editOption = (next: CommerceModel.ProductModifierOption) =>\n edit({ options: group.options.map((entry, at) => (at === 0 ? next : entry)) })\n const example = `${group.name || 'Engraving'}: ${group.digitsOnly ? '27' : 'For Sam'}`\n return (\n <Stack spacing={1.5}>\n <Typography variant=\"overline\" color=\"text.secondary\">\n {'Write-in'}\n </Typography>\n <Stack direction=\"row\" spacing={1} sx={{ alignItems: 'flex-start', flexWrap: 'wrap', rowGap: 1 }}>\n <TextField\n label=\"Field name\"\n size=\"small\"\n value={group.name}\n placeholder=\"Engraving\"\n onChange={(event) => edit(withWriteInName(group, event.target.value))}\n sx={{ flex: 1, minWidth: (theme) => theme.spacing(20) }}\n />\n <TextField\n label=\"Longest answer\"\n size=\"small\"\n value={group.maxLength ?? CommerceModel.DEFAULT_WRITE_IN_LENGTH}\n onChange={(event) =>\n edit({\n maxLength: Math.min(\n CommerceModel.MAX_WRITE_IN_LENGTH,\n Math.max(1, Math.round(Number(event.target.value) || 1)),\n ),\n })\n }\n helperText=\"Characters\"\n sx={{ width: (theme) => theme.spacing(15) }}\n slotProps={{ htmlInput: { inputMode: 'numeric' } }}\n />\n <TextField\n label=\"Adds ($)\"\n size=\"small\"\n defaultValue={dollarsFromCents(option?.priceCents)}\n placeholder=\"0.00\"\n onBlur={(event) => option && editOption({ ...option, priceCents: centsFromDollars(event.target.value) })}\n helperText=\"When filled in\"\n sx={{ width: (theme) => theme.spacing(15) }}\n slotProps={{ htmlInput: { inputMode: 'decimal' } }}\n />\n <Button color=\"error\" onClick={remove}>\n {'Remove write-in'}\n </Button>\n </Stack>\n <TextField\n label=\"Note\"\n size=\"small\"\n defaultValue={option?.note ?? ''}\n placeholder=\"Exactly as it should read\"\n onBlur={(event) => option && editOption(withChoiceCard(option, { note: event.target.value }))}\n helperText=\"Shown under the field on the product’s page.\"\n slotProps={{ htmlInput: { maxLength: PRODUCT_CHOICE_NOTE_MAX } }}\n />\n <Stack direction=\"row\" spacing={2} sx={{ flexWrap: 'wrap', rowGap: 0.5 }}>\n <FormControlLabel\n control={<Switch checked={group.min > 0} onChange={(event) => edit({ min: event.target.checked ? 1 : 0 })} />}\n label=\"Required\"\n />\n <FormControlLabel\n control={\n <Switch checked={group.digitsOnly === true} onChange={(event) => edit({ digitsOnly: event.target.checked })} />\n }\n label=\"Numbers only\"\n />\n <FormControlLabel\n control={<Switch checked={group.online === true} onChange={(event) => edit({ online: event.target.checked })} />}\n label=\"Show on the website\"\n />\n </Stack>\n <Typography variant=\"caption\" color=\"text.secondary\">\n {`The answer goes on the order, the receipt and your order emails, like “${example}”.` +\n (group.online === true ? '' : ' Asked at the register only.')}\n </Typography>\n </Stack>\n )\n}\n\n/**\n * The product's add-ons (AGL-4100, from the register's modifiers of\n * AGL-3607): choices added to the item that are not stocked variants — walls\n * and printing on a canopy, a milk in a latte — each free or adding to the\n * price, and able to cost more on one variant than another. A group with a\n * minimum of 1 or more must be answered before the item is added. Each group\n * says whether the website's product page offers it; the register always\n * does.\n *\n * Offered on every store, with or without the point of sale, and saved with\n * the product, so editing it takes exactly what editing the product takes.\n * Memoized on its own props like every section of this editor (AGL-3423).\n */\nexport const ProductAddOnsFields = memo(function ProductAddOnsFields(\n props: ProductAddOnsFieldsProps,\n) {\n const { modifierGroups, options, variants, update, pick } = props\n const helpId = useId()\n const [pricedByVariant, setPricedByVariant] = useState<Record<string, boolean>>({})\n const [cardOpen, setCardOpen] = useState<Record<string, boolean>>({})\n const setGroups = useCallback(\n (groups: CommerceModel.ProductModifierGroup[]) => update({ modifierGroups: groups }),\n [update],\n )\n const editGroup = (index: number, patch: Partial<CommerceModel.ProductModifierGroup>) =>\n setGroups(modifierGroups.map((group, at) => (at === index ? { ...group, ...patch } : group)))\n const replaceOption = (\n groupIndex: number,\n optionIndex: number,\n next: CommerceModel.ProductModifierOption,\n ) => {\n const group = modifierGroups[groupIndex]\n editGroup(groupIndex, {\n options: group.options.map((option, at) => (at === optionIndex ? next : option)),\n })\n }\n const editOption = (\n groupIndex: number,\n optionIndex: number,\n patch: Partial<CommerceModel.ProductModifierOption>,\n ) => replaceOption(groupIndex, optionIndex, { ...modifierGroups[groupIndex].options[optionIndex], ...patch })\n const problem = CommerceModel.modifierGroupsProblem(modifierGroups)\n const variesByVariant = variants.length > 1\n const byLabel = priceByLabel(options)\n\n return (\n <Stack spacing={2}>\n <Typography id={helpId} variant=\"body2\" color=\"text.secondary\">\n {'Add-ons are choices added to the item that don’t need their own stock, such as walls or ' +\n 'printing on a canopy, or a milk in a latte. Each can be free or add to the price, and can ' +\n 'cost more on a larger size. Show a group on the website to offer it on the product’s page; ' +\n 'the register offers every group. A write-in asks the customer to type an answer, such as ' +\n 'a name to print, an engraving or a cake message, and puts it on the order.'}\n </Typography>\n {modifierGroups.map((group, groupIndex) => (\n <Box\n key={group.id}\n role=\"group\"\n aria-label={group.name || 'Add-on group'}\n sx={{ border: 1, borderColor: 'divider', borderRadius: 1, p: 2 }}\n >\n {CommerceModel.modifierGroupIsWriteIn(group) ? (\n <WriteInFields\n group={group}\n edit={(patch) => editGroup(groupIndex, patch)}\n remove={() => setGroups(modifierGroups.filter((_group, at) => at !== groupIndex))}\n />\n ) : (\n <Stack spacing={1.5}>\n <Stack direction=\"row\" spacing={1} sx={{ alignItems: 'flex-start', flexWrap: 'wrap', rowGap: 1 }}>\n <TextField\n label=\"Group name\"\n size=\"small\"\n value={group.name}\n onChange={(event) => editGroup(groupIndex, { name: event.target.value })}\n sx={{ flex: 1, minWidth: (theme) => theme.spacing(20) }}\n />\n <TextField\n label=\"At least\"\n size=\"small\"\n value={group.min}\n onChange={(event) =>\n editGroup(groupIndex, { min: Math.max(0, Math.round(Number(event.target.value) || 0)) })\n }\n helperText={group.min > 0 ? 'Required' : 'Optional'}\n sx={{ width: (theme) => theme.spacing(12) }}\n slotProps={{ htmlInput: { inputMode: 'numeric' } }}\n />\n <TextField\n label=\"At most\"\n size=\"small\"\n value={group.max}\n onChange={(event) =>\n editGroup(groupIndex, { max: Math.max(1, Math.round(Number(event.target.value) || 1)) })\n }\n sx={{ width: (theme) => theme.spacing(12) }}\n slotProps={{ htmlInput: { inputMode: 'numeric' } }}\n />\n <Button\n color=\"error\"\n onClick={() => setGroups(modifierGroups.filter((_group, at) => at !== groupIndex))}\n >\n {'Remove group'}\n </Button>\n </Stack>\n <FormControlLabel\n control={\n <Switch\n checked={group.online === true}\n onChange={(event) => editGroup(groupIndex, { online: event.target.checked })}\n />\n }\n label=\"Show on the website\"\n />\n <Typography variant=\"caption\" color=\"text.secondary\">\n {group.online === true\n ? 'Offered on the product’s page and at the register.'\n : 'Offered at the register only.'}\n </Typography>\n <FormControlLabel\n control={\n <Switch\n checked={group.nameOnOrder === true}\n onChange={(event) => editGroup(groupIndex, { nameOnOrder: event.target.checked })}\n />\n }\n label=\"Name the group on the order\"\n />\n <Typography variant=\"caption\" color=\"text.secondary\">\n {group.nameOnOrder === true\n ? `The order says “${group.name || 'Size'}: ${group.options[0]?.name || 'M'}”.`\n : `The order says “${group.options[0]?.name || 'M'}”. Turn this on when a choice ` +\n 'doesn’t say what it is on its own, like a size.'}\n </Typography>\n {group.options.map((option, optionIndex) => {\n const optionKey = `${group.id}:${option.id}`\n const byVariantOpen =\n pricedByVariant[optionKey] ?? Object.keys(option.priceCentsByVariant ?? {}).length > 0\n const hasCard = Boolean(option.imageUrl || option.note || option.includes?.length)\n const cardShown = cardOpen[optionKey] ?? hasCard\n const choiceLabel = option.name || 'this choice'\n return (\n <Box key={option.id}>\n <Stack direction=\"row\" spacing={1} sx={{ alignItems: 'center', flexWrap: 'wrap', rowGap: 1 }}>\n <TextField\n label=\"Choice\"\n size=\"small\"\n value={option.name}\n onChange={(event) => editOption(groupIndex, optionIndex, { name: event.target.value })}\n sx={{ flex: 1, minWidth: (theme) => theme.spacing(20) }}\n />\n <TextField\n label=\"Adds ($)\"\n size=\"small\"\n defaultValue={dollarsFromCents(option.priceCents)}\n placeholder=\"0.00\"\n onBlur={(event) =>\n editOption(groupIndex, optionIndex, { priceCents: centsFromDollars(event.target.value) })\n }\n sx={{ width: (theme) => theme.spacing(15) }}\n slotProps={{ htmlInput: { inputMode: 'decimal' } }}\n />\n {variesByVariant ? (\n <Button\n size=\"small\"\n aria-expanded={byVariantOpen}\n onClick={() =>\n setPricedByVariant((open) => ({ ...open, [optionKey]: !byVariantOpen }))\n }\n >\n {byLabel}\n </Button>\n ) : null}\n <Button\n size=\"small\"\n aria-expanded={cardShown}\n onClick={() => setCardOpen((open) => ({ ...open, [optionKey]: !cardShown }))}\n >\n {'Picture & combo'}\n </Button>\n <IconButton\n aria-label={`Remove ${option.name || 'choice'}`}\n onClick={() =>\n editGroup(groupIndex, {\n options: group.options.filter((_option, at) => at !== optionIndex),\n max: Math.max(1, Math.min(group.max, group.options.length - 1)),\n })\n }\n >\n {'✕'}\n </IconButton>\n </Stack>\n {variesByVariant ? (\n <Collapse in={byVariantOpen} unmountOnExit>\n <Stack spacing={1} sx={{ pl: 2, pt: 1.5 }}>\n <Typography variant=\"caption\" color=\"text.secondary\">\n {`What “${option.name || 'this choice'}” adds on each. Leave one blank to use ` +\n 'the price above.'}\n </Typography>\n <Box\n sx={{\n display: 'grid',\n gridTemplateColumns: { xs: '1fr', sm: 'repeat(2, minmax(0, 1fr))' },\n gap: 1,\n }}\n >\n {variants.map((variant) => (\n <TextField\n key={variant.id}\n label={CommerceModel.variantPriceLabel(variant)}\n size=\"small\"\n defaultValue={dollarsFromCents(option.priceCentsByVariant?.[variant.id])}\n placeholder={dollarsFromCents(option.priceCents) || '0.00'}\n onBlur={(event) =>\n replaceOption(\n groupIndex,\n optionIndex,\n withVariantPrice(\n modifierGroups[groupIndex].options[optionIndex],\n variant.id,\n event.target.value,\n ),\n )\n }\n slotProps={{ htmlInput: { inputMode: 'decimal' } }}\n />\n ))}\n </Box>\n </Stack>\n </Collapse>\n ) : null}\n <Collapse in={cardShown} unmountOnExit>\n <Stack spacing={1} sx={{ pl: 2, pt: 1.5 }}>\n <Typography variant=\"caption\" color=\"text.secondary\">\n {`What “${choiceLabel}” shows on its picture card. List what it includes to make it ` +\n 'a combo: shoppers can open the list on its card.'}\n </Typography>\n <CardPictureField\n imageUrl={option.imageUrl}\n label={choiceLabel}\n pick={pick}\n onChange={(imageUrl) =>\n replaceOption(\n groupIndex,\n optionIndex,\n withChoiceCard(modifierGroups[groupIndex].options[optionIndex], { imageUrl }),\n )\n }\n />\n <TextField\n label=\"Note\"\n size=\"small\"\n defaultValue={option.note ?? ''}\n placeholder=\"Blocks wind on one side\"\n onBlur={(event) =>\n replaceOption(\n groupIndex,\n optionIndex,\n withChoiceCard(modifierGroups[groupIndex].options[optionIndex], {\n note: event.target.value,\n }),\n )\n }\n slotProps={{ htmlInput: { maxLength: PRODUCT_CHOICE_NOTE_MAX } }}\n />\n <TextField\n label=\"Combo: what it includes\"\n size=\"small\"\n multiline\n minRows={2}\n defaultValue={Array.isArray(option.includes) ? option.includes.join('\\n') : ''}\n placeholder={'Full wall ×2\\nSteel weights ×4\\nRoller bag'}\n helperText={`One item per line, up to ${PRODUCT_COMBO_MAX_ITEMS}. Leave it empty for a single choice.`}\n onBlur={(event) =>\n replaceOption(\n groupIndex,\n optionIndex,\n withChoiceCard(modifierGroups[groupIndex].options[optionIndex], {\n includes: event.target.value,\n }),\n )\n }\n />\n </Stack>\n </Collapse>\n </Box>\n )\n })}\n <Box>\n <Button\n onClick={() =>\n editGroup(groupIndex, {\n options: [...group.options, { id: newId('o'), name: '', priceCents: 0 }],\n })\n }\n disabled={group.options.length >= CommerceModel.POS_MAX_MODIFIER_OPTIONS}\n >\n {'Add choice'}\n </Button>\n </Box>\n </Stack>\n )}\n </Box>\n ))}\n <Box>\n <Stack direction=\"row\" spacing={1} sx={{ flexWrap: 'wrap', rowGap: 1 }}>\n <Button\n variant=\"outlined\"\n aria-describedby={helpId}\n onClick={() => setGroups([...modifierGroups, newAddOnGroup()])}\n disabled={modifierGroups.length >= CommerceModel.POS_MAX_MODIFIER_GROUPS}\n >\n {'New add-on group'}\n </Button>\n <Button\n variant=\"outlined\"\n aria-describedby={helpId}\n onClick={() => setGroups([...modifierGroups, newWriteInGroup()])}\n disabled={modifierGroups.length >= CommerceModel.POS_MAX_MODIFIER_GROUPS}\n >\n {'New write-in'}\n </Button>\n </Stack>\n </Box>\n {problem && modifierGroups.length ? (\n <Typography variant=\"body2\" color=\"warning.main\">\n {problem}\n </Typography>\n ) : null}\n </Stack>\n )\n})\n"],"names":["Box","Button","Collapse","FormControlLabel","IconButton","Stack","Switch","TextField","Typography","memo","useCallback","useId","useState","CommerceModel","PRODUCT_CHOICE_NOTE_MAX","PRODUCT_COMBO_ITEM_MAX","PRODUCT_COMBO_MAX_ITEMS","CardPictureField","newId","prefix","Math","random","toString","slice","centsFromDollars","value","number","round","Number","String","replace","isFinite","dollarsFromCents","cents","toFixed","priceByLabel","options","named","filter","option","name","trim","length","toLowerCase","newAddOnGroup","id","min","max","online","priceCents","newWriteInGroup","kind","maxLength","DEFAULT_WRITE_IN_LENGTH","withWriteInName","group","map","at","withVariantPrice","variantId","raw","priceCentsByVariant","rest","next","Object","keys","withChoiceCard","patch","url","imageUrl","note","items","includes","split","item","Boolean","WriteInFields","props","edit","remove","editOption","entry","example","digitsOnly","spacing","variant","color","direction","sx","alignItems","flexWrap","rowGap","label","size","placeholder","onChange","event","target","flex","minWidth","theme","MAX_WRITE_IN_LENGTH","helperText","width","slotProps","htmlInput","inputMode","defaultValue","onBlur","onClick","control","checked","ProductAddOnsFields","modifierGroups","variants","update","pick","helpId","pricedByVariant","setPricedByVariant","cardOpen","setCardOpen","setGroups","groups","editGroup","index","replaceOption","groupIndex","optionIndex","problem","modifierGroupsProblem","variesByVariant","byLabel","role","aria-label","border","borderColor","borderRadius","p","modifierGroupIsWriteIn","_group","nameOnOrder","optionKey","byVariantOpen","hasCard","cardShown","choiceLabel","aria-expanded","open","_option","in","unmountOnExit","pl","pt","display","gridTemplateColumns","xs","sm","gap","variantPriceLabel","multiline","minRows","Array","isArray","join","disabled","POS_MAX_MODIFIER_OPTIONS","aria-describedby","POS_MAX_MODIFIER_GROUPS"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;;;AAEA,SACEA,GAAG,EACHC,MAAM,EACNC,QAAQ,EACRC,gBAAgB,EAChBC,UAAU,EACVC,KAAK,EACLC,MAAM,EACNC,SAAS,EACTC,UAAU,QACL,gBAAe;AACtB,SAASC,IAAI,EAAEC,WAAW,EAAEC,KAAK,EAAEC,QAAQ,QAAQ,QAAO;AAC1D,YAAYC,mBAAmB,uBAAa;AAC5C,SAASC,uBAAuB,EAAEC,sBAAsB,EAAEC,uBAAuB,QAAQ,oCAAgC;AACzH,SAASC,gBAAgB,QAA+B,wCAAoC;AAe5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BAAwB;8CAEvE;;;;;mBAjPF/G,MAAMV,EAAE;;0BAwPjB,KAAC7C;0BACC,cAAA,MAACK;oBAAMkF,WAAU;oBAAMH,SAAS;oBAAGI,IAAI;wBAAEE,UAAU;wBAAQC,QAAQ;oBAAE;;sCACnE,KAAC1F;4BACCoF,SAAQ;4BACRkF,oBAAkBlD;4BAClBR,SAAS,IAAMa,UAAU;uCAAIT;oCAAgBrE;iCAAgB;4BAC7DyH,UAAUpD,eAAevE,MAAM,IAAI7B,cAAc2J,uBAAuB;sCAEvE;;sCAEH,KAACvK;4BACCoF,SAAQ;4BACRkF,oBAAkBlD;4BAClBR,SAAS,IAAMa,UAAU;uCAAIT;oCAAgB/D;iCAAkB;4BAC/DmH,UAAUpD,eAAevE,MAAM,IAAI7B,cAAc2J,uBAAuB;sCAEvE;;;;;YAINvC,WAAWhB,eAAevE,MAAM,iBAC/B,KAAClC;gBAAW6E,SAAQ;gBAAQC,OAAM;0BAC/B2C;iBAED;;;AAGV,GAAE"}
1
+ {"version":3,"sources":["../../../../../../../../libs/plugins/commerce/src/lib/components/console/product-add-ons-fields.component.tsx"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n'use client'\n\nimport {\n Box,\n Button,\n Collapse,\n FormControlLabel,\n IconButton,\n Stack,\n Switch,\n TextField,\n Typography,\n} from '@mui/material'\nimport { memo, useCallback, useId, useState } from 'react'\nimport * as CommerceModel from '../../model'\nimport { PRODUCT_CHOICE_NOTE_MAX, PRODUCT_COMBO_ITEM_MAX, PRODUCT_COMBO_MAX_ITEMS } from '../../model/product-card-rules'\nimport { CardPictureField, type ProductMediaPick } from './product-builder-fields.component'\nimport type { ConsoleCurrencySetup } from './use-currency-setup'\n\ntype Patch = Partial<CommerceModel.HostProduct>\n\nexport interface ProductAddOnsFieldsProps {\n modifierGroups: readonly CommerceModel.ProductModifierGroup[]\n /** The product's options, to name what a choice is priced by. */\n options: readonly CommerceModel.ProductOption[]\n /** The product's variants, each of which a choice may be priced on. */\n variants: readonly Pick<CommerceModel.ProductVariant, 'id' | 'options'>[]\n update: (patch: Patch) => void\n /** Opens the media browser for a choice's picture (AGL-4205); without it, no picture is chosen. */\n pick?: ProductMediaPick\n /**\n * The store's other currencies (AGL-4248): with any, each choice may carry\n * a fixed amount in them. Without, nothing currency-related is drawn.\n */\n currencies?: ConsoleCurrencySetup\n}\n\nfunction newId(prefix: string): string {\n return `${prefix}${Math.random().toString(36).slice(2, 10)}`\n}\n\n/** Dollars as typed, to whole cents; blank is free. */\nfunction centsFromDollars(value: string): number {\n const number = Math.round(Number(String(value).replace(/[^0-9.]/g, '')) * 100)\n return Number.isFinite(number) && number > 0 ? number : 0\n}\n\n/** Cents as the price field shows them; blank for free. */\nfunction dollarsFromCents(cents: number | undefined): string {\n return cents ? (cents / 100).toFixed(2) : ''\n}\n\n/**\n * What a choice's per-variant prices are called (AGL-4100): by the one\n * option a product varies by (\"Price by size\"), else by variant.\n */\nexport function priceByLabel(options: readonly Pick<CommerceModel.ProductOption, 'name'>[]): string {\n const named = options.filter((option) => option.name?.trim())\n return named.length === 1 ? `Price by ${named[0].name.trim().toLowerCase()}` : 'Price by variant'\n}\n\n/** A new group, as the console makes it from now on: shown on the website (AGL-4100). */\nexport function newAddOnGroup(): CommerceModel.ProductModifierGroup {\n return {\n id: newId('g'),\n name: '',\n min: 0,\n max: 1,\n online: true,\n options: [{ id: newId('o'), name: '', priceCents: 0 }],\n }\n}\n\n/**\n * A new write-in (write-ins): one field the shopper types into,\n * such as a name to print or an engraving. Required, shown on the website,\n * free until the merchant sets what it adds.\n */\nexport function newWriteInGroup(): CommerceModel.ProductModifierGroup {\n return {\n id: newId('g'),\n name: '',\n kind: 'text',\n min: 1,\n max: 1,\n maxLength: CommerceModel.DEFAULT_WRITE_IN_LENGTH,\n online: true,\n options: [{ id: newId('o'), name: '', priceCents: 0 }],\n }\n}\n\n/**\n * A write-in renamed: its one option carries the same name, so every reader\n * that names a pick by its option names the field.\n */\nexport function withWriteInName(\n group: CommerceModel.ProductModifierGroup,\n name: string,\n): Partial<CommerceModel.ProductModifierGroup> {\n return { name, options: group.options.map((option, at) => (at === 0 ? { ...option, name } : option)) }\n}\n\n/**\n * A choice's prices by variant with one variant's price set or cleared. A\n * cleared price follows the choice's own; with none left the field is\n * dropped, never stored as `undefined` (the save is a client-direct write,\n * which refuses one).\n */\nexport function withVariantPrice(\n option: CommerceModel.ProductModifierOption,\n variantId: string,\n raw: string,\n): CommerceModel.ProductModifierOption {\n const { priceCentsByVariant, ...rest } = option\n const next = { ...(priceCentsByVariant ?? {}) }\n if (raw.trim() === '') delete next[variantId]\n else next[variantId] = centsFromDollars(raw)\n return Object.keys(next).length ? { ...rest, priceCentsByVariant: next } : rest\n}\n\n/**\n * A choice's fixed amount in another currency (AGL-4248), set or cleared, in\n * minor units of that currency. A cleared amount converts again; with none\n * left the field is dropped, never stored as `undefined`. Something that is\n * not a price changes nothing.\n */\nexport function withCurrencyPrice(\n option: CommerceModel.ProductModifierOption,\n code: string,\n raw: string,\n): CommerceModel.ProductModifierOption {\n const major = CommerceModel.parseMajorInput(raw)\n if (major === null) return option\n const { fixedPriceCents, ...rest } = option\n const next = CommerceModel.withCurrencyAmount(\n fixedPriceCents,\n code,\n major === undefined ? undefined : CommerceModel.majorToMinor(major, code),\n )\n return next ? { ...rest, fixedPriceCents: next } : rest\n}\n\n/**\n * A choice with its card changed (AGL-4205): its picture, its note, or what\n * it includes as a combo, typed one item per line. A cleared field is\n * dropped, never stored as `undefined`.\n */\nexport function withChoiceCard(\n option: CommerceModel.ProductModifierOption,\n patch: { imageUrl?: string | null; note?: string | null; includes?: string | null },\n): CommerceModel.ProductModifierOption {\n const next: CommerceModel.ProductModifierOption = { ...option }\n if ('imageUrl' in patch) {\n const url = String(patch.imageUrl ?? '').trim()\n if (url) next.imageUrl = url\n else delete next.imageUrl\n }\n if ('note' in patch) {\n const note = String(patch.note ?? '').trim().slice(0, PRODUCT_CHOICE_NOTE_MAX)\n if (note) next.note = note\n else delete next.note\n }\n if ('includes' in patch) {\n const items = String(patch.includes ?? '')\n .split('\\n')\n .map((item) => item.trim().slice(0, PRODUCT_COMBO_ITEM_MAX))\n .filter(Boolean)\n .slice(0, PRODUCT_COMBO_MAX_ITEMS)\n if (items.length) next.includes = items\n else delete next.includes\n }\n return next\n}\n\ninterface WriteInFieldsProps {\n group: CommerceModel.ProductModifierGroup\n edit: (patch: Partial<CommerceModel.ProductModifierGroup>) => void\n remove: () => void\n}\n\n/**\n * One write-in in the editor (write-ins): what the field is\n * called, how long an answer can be, what a filled one adds, the note under\n * it, and whether it is required, numbers only and asked on the website.\n */\nfunction WriteInFields(props: WriteInFieldsProps) {\n const { group, edit, remove } = props\n const option = group.options[0]\n const editOption = (next: CommerceModel.ProductModifierOption) =>\n edit({ options: group.options.map((entry, at) => (at === 0 ? next : entry)) })\n const example = `${group.name || 'Engraving'}: ${group.digitsOnly ? '27' : 'For Sam'}`\n return (\n <Stack spacing={1.5}>\n <Typography variant=\"overline\" color=\"text.secondary\">\n {'Write-in'}\n </Typography>\n <Stack direction=\"row\" spacing={1} sx={{ alignItems: 'flex-start', flexWrap: 'wrap', rowGap: 1 }}>\n <TextField\n label=\"Field name\"\n size=\"small\"\n value={group.name}\n placeholder=\"Engraving\"\n onChange={(event) => edit(withWriteInName(group, event.target.value))}\n sx={{ flex: 1, minWidth: (theme) => theme.spacing(20) }}\n />\n <TextField\n label=\"Longest answer\"\n size=\"small\"\n value={group.maxLength ?? CommerceModel.DEFAULT_WRITE_IN_LENGTH}\n onChange={(event) =>\n edit({\n maxLength: Math.min(\n CommerceModel.MAX_WRITE_IN_LENGTH,\n Math.max(1, Math.round(Number(event.target.value) || 1)),\n ),\n })\n }\n helperText=\"Characters\"\n sx={{ width: (theme) => theme.spacing(15) }}\n slotProps={{ htmlInput: { inputMode: 'numeric' } }}\n />\n <TextField\n label=\"Adds ($)\"\n size=\"small\"\n defaultValue={dollarsFromCents(option?.priceCents)}\n placeholder=\"0.00\"\n onBlur={(event) => option && editOption({ ...option, priceCents: centsFromDollars(event.target.value) })}\n helperText=\"When filled in\"\n sx={{ width: (theme) => theme.spacing(15) }}\n slotProps={{ htmlInput: { inputMode: 'decimal' } }}\n />\n <Button color=\"error\" onClick={remove}>\n {'Remove write-in'}\n </Button>\n </Stack>\n <TextField\n label=\"Note\"\n size=\"small\"\n defaultValue={option?.note ?? ''}\n placeholder=\"Exactly as it should read\"\n onBlur={(event) => option && editOption(withChoiceCard(option, { note: event.target.value }))}\n helperText=\"Shown under the field on the product’s page.\"\n slotProps={{ htmlInput: { maxLength: PRODUCT_CHOICE_NOTE_MAX } }}\n />\n <Stack direction=\"row\" spacing={2} sx={{ flexWrap: 'wrap', rowGap: 0.5 }}>\n <FormControlLabel\n control={<Switch checked={group.min > 0} onChange={(event) => edit({ min: event.target.checked ? 1 : 0 })} />}\n label=\"Required\"\n />\n <FormControlLabel\n control={\n <Switch checked={group.digitsOnly === true} onChange={(event) => edit({ digitsOnly: event.target.checked })} />\n }\n label=\"Numbers only\"\n />\n <FormControlLabel\n control={<Switch checked={group.online === true} onChange={(event) => edit({ online: event.target.checked })} />}\n label=\"Show on the website\"\n />\n </Stack>\n <Typography variant=\"caption\" color=\"text.secondary\">\n {`The answer goes on the order, the receipt and your order emails, like “${example}”.` +\n (group.online === true ? '' : ' Asked at the register only.')}\n </Typography>\n </Stack>\n )\n}\n\n/**\n * The product's add-ons (AGL-4100, from the register's modifiers of\n * AGL-3607): choices added to the item that are not stocked variants — walls\n * and printing on a canopy, a milk in a latte — each free or adding to the\n * price, and able to cost more on one variant than another. A group with a\n * minimum of 1 or more must be answered before the item is added. Each group\n * says whether the website's product page offers it; the register always\n * does.\n *\n * Offered on every store, with or without the point of sale, and saved with\n * the product, so editing it takes exactly what editing the product takes.\n * Memoized on its own props like every section of this editor (AGL-3423).\n */\nexport const ProductAddOnsFields = memo(function ProductAddOnsFields(\n props: ProductAddOnsFieldsProps,\n) {\n const { modifierGroups, options, variants, update, pick, currencies } = props\n const helpId = useId()\n const [pricedByVariant, setPricedByVariant] = useState<Record<string, boolean>>({})\n const [inCurrenciesOpen, setInCurrenciesOpen] = useState<Record<string, boolean>>({})\n const others = currencies?.others ?? []\n const [cardOpen, setCardOpen] = useState<Record<string, boolean>>({})\n const setGroups = useCallback(\n (groups: CommerceModel.ProductModifierGroup[]) => update({ modifierGroups: groups }),\n [update],\n )\n const editGroup = (index: number, patch: Partial<CommerceModel.ProductModifierGroup>) =>\n setGroups(modifierGroups.map((group, at) => (at === index ? { ...group, ...patch } : group)))\n const replaceOption = (\n groupIndex: number,\n optionIndex: number,\n next: CommerceModel.ProductModifierOption,\n ) => {\n const group = modifierGroups[groupIndex]\n editGroup(groupIndex, {\n options: group.options.map((option, at) => (at === optionIndex ? next : option)),\n })\n }\n const editOption = (\n groupIndex: number,\n optionIndex: number,\n patch: Partial<CommerceModel.ProductModifierOption>,\n ) => replaceOption(groupIndex, optionIndex, { ...modifierGroups[groupIndex].options[optionIndex], ...patch })\n const problem = CommerceModel.modifierGroupsProblem(modifierGroups)\n const variesByVariant = variants.length > 1\n const byLabel = priceByLabel(options)\n\n return (\n <Stack spacing={2}>\n <Typography id={helpId} variant=\"body2\" color=\"text.secondary\">\n {'Add-ons are choices added to the item that don’t need their own stock, such as walls or ' +\n 'printing on a canopy, or a milk in a latte. Each can be free or add to the price, and can ' +\n 'cost more on a larger size. Show a group on the website to offer it on the product’s page; ' +\n 'the register offers every group. A write-in asks the customer to type an answer, such as ' +\n 'a name to print, an engraving or a cake message, and puts it on the order.'}\n </Typography>\n {modifierGroups.map((group, groupIndex) => (\n <Box\n key={group.id}\n role=\"group\"\n aria-label={group.name || 'Add-on group'}\n sx={{ border: 1, borderColor: 'divider', borderRadius: 1, p: 2 }}\n >\n {CommerceModel.modifierGroupIsWriteIn(group) ? (\n <WriteInFields\n group={group}\n edit={(patch) => editGroup(groupIndex, patch)}\n remove={() => setGroups(modifierGroups.filter((_group, at) => at !== groupIndex))}\n />\n ) : (\n <Stack spacing={1.5}>\n <Stack direction=\"row\" spacing={1} sx={{ alignItems: 'flex-start', flexWrap: 'wrap', rowGap: 1 }}>\n <TextField\n label=\"Group name\"\n size=\"small\"\n value={group.name}\n onChange={(event) => editGroup(groupIndex, { name: event.target.value })}\n sx={{ flex: 1, minWidth: (theme) => theme.spacing(20) }}\n />\n <TextField\n label=\"At least\"\n size=\"small\"\n value={group.min}\n onChange={(event) =>\n editGroup(groupIndex, { min: Math.max(0, Math.round(Number(event.target.value) || 0)) })\n }\n helperText={group.min > 0 ? 'Required' : 'Optional'}\n sx={{ width: (theme) => theme.spacing(12) }}\n slotProps={{ htmlInput: { inputMode: 'numeric' } }}\n />\n <TextField\n label=\"At most\"\n size=\"small\"\n value={group.max}\n onChange={(event) =>\n editGroup(groupIndex, { max: Math.max(1, Math.round(Number(event.target.value) || 1)) })\n }\n sx={{ width: (theme) => theme.spacing(12) }}\n slotProps={{ htmlInput: { inputMode: 'numeric' } }}\n />\n <Button\n color=\"error\"\n onClick={() => setGroups(modifierGroups.filter((_group, at) => at !== groupIndex))}\n >\n {'Remove group'}\n </Button>\n </Stack>\n <FormControlLabel\n control={\n <Switch\n checked={group.online === true}\n onChange={(event) => editGroup(groupIndex, { online: event.target.checked })}\n />\n }\n label=\"Show on the website\"\n />\n <Typography variant=\"caption\" color=\"text.secondary\">\n {group.online === true\n ? 'Offered on the product’s page and at the register.'\n : 'Offered at the register only.'}\n </Typography>\n <FormControlLabel\n control={\n <Switch\n checked={group.nameOnOrder === true}\n onChange={(event) => editGroup(groupIndex, { nameOnOrder: event.target.checked })}\n />\n }\n label=\"Name the group on the order\"\n />\n <Typography variant=\"caption\" color=\"text.secondary\">\n {group.nameOnOrder === true\n ? `The order says “${group.name || 'Size'}: ${group.options[0]?.name || 'M'}”.`\n : `The order says “${group.options[0]?.name || 'M'}”. Turn this on when a choice ` +\n 'doesn’t say what it is on its own, like a size.'}\n </Typography>\n {group.options.map((option, optionIndex) => {\n const optionKey = `${group.id}:${option.id}`\n const byVariantOpen =\n pricedByVariant[optionKey] ?? Object.keys(option.priceCentsByVariant ?? {}).length > 0\n const hasCard = Boolean(option.imageUrl || option.note || option.includes?.length)\n const cardShown = cardOpen[optionKey] ?? hasCard\n const currenciesShown =\n inCurrenciesOpen[optionKey] ?? Object.keys(option.fixedPriceCents ?? {}).length > 0\n const choiceLabel = option.name || 'this choice'\n return (\n <Box key={option.id}>\n <Stack direction=\"row\" spacing={1} sx={{ alignItems: 'center', flexWrap: 'wrap', rowGap: 1 }}>\n <TextField\n label=\"Choice\"\n size=\"small\"\n value={option.name}\n onChange={(event) => editOption(groupIndex, optionIndex, { name: event.target.value })}\n sx={{ flex: 1, minWidth: (theme) => theme.spacing(20) }}\n />\n <TextField\n label=\"Adds ($)\"\n size=\"small\"\n defaultValue={dollarsFromCents(option.priceCents)}\n placeholder=\"0.00\"\n onBlur={(event) =>\n editOption(groupIndex, optionIndex, { priceCents: centsFromDollars(event.target.value) })\n }\n sx={{ width: (theme) => theme.spacing(15) }}\n slotProps={{ htmlInput: { inputMode: 'decimal' } }}\n />\n {variesByVariant ? (\n <Button\n size=\"small\"\n aria-expanded={byVariantOpen}\n onClick={() =>\n setPricedByVariant((open) => ({ ...open, [optionKey]: !byVariantOpen }))\n }\n >\n {byLabel}\n </Button>\n ) : null}\n {others.length ? (\n <Button\n size=\"small\"\n aria-expanded={currenciesShown}\n onClick={() =>\n setInCurrenciesOpen((open) => ({ ...open, [optionKey]: !currenciesShown }))\n }\n >\n {'Other currencies'}\n </Button>\n ) : null}\n <Button\n size=\"small\"\n aria-expanded={cardShown}\n onClick={() => setCardOpen((open) => ({ ...open, [optionKey]: !cardShown }))}\n >\n {'Picture & combo'}\n </Button>\n <IconButton\n aria-label={`Remove ${option.name || 'choice'}`}\n onClick={() =>\n editGroup(groupIndex, {\n options: group.options.filter((_option, at) => at !== optionIndex),\n max: Math.max(1, Math.min(group.max, group.options.length - 1)),\n })\n }\n >\n {'✕'}\n </IconButton>\n </Stack>\n {variesByVariant ? (\n <Collapse in={byVariantOpen} unmountOnExit>\n <Stack spacing={1} sx={{ pl: 2, pt: 1.5 }}>\n <Typography variant=\"caption\" color=\"text.secondary\">\n {`What “${option.name || 'this choice'}” adds on each. Leave one blank to use ` +\n 'the price above.'}\n </Typography>\n <Box\n sx={{\n display: 'grid',\n gridTemplateColumns: { xs: '1fr', sm: 'repeat(2, minmax(0, 1fr))' },\n gap: 1,\n }}\n >\n {variants.map((variant) => (\n <TextField\n key={variant.id}\n label={CommerceModel.variantPriceLabel(variant)}\n size=\"small\"\n defaultValue={dollarsFromCents(option.priceCentsByVariant?.[variant.id])}\n placeholder={dollarsFromCents(option.priceCents) || '0.00'}\n onBlur={(event) =>\n replaceOption(\n groupIndex,\n optionIndex,\n withVariantPrice(\n modifierGroups[groupIndex].options[optionIndex],\n variant.id,\n event.target.value,\n ),\n )\n }\n slotProps={{ htmlInput: { inputMode: 'decimal' } }}\n />\n ))}\n </Box>\n </Stack>\n </Collapse>\n ) : null}\n {others.length && currencies ? (\n <Collapse in={currenciesShown} unmountOnExit>\n <Stack spacing={1} sx={{ pl: 2, pt: 1.5 }}>\n <Typography variant=\"caption\" color=\"text.secondary\">\n {`What “${choiceLabel}” adds in each currency. Leave one blank to convert ` +\n 'the price above at the day’s rate.'}\n </Typography>\n <Box\n sx={{\n display: 'grid',\n gridTemplateColumns: { xs: '1fr', sm: 'repeat(3, minmax(0, 1fr))' },\n gap: 1,\n }}\n >\n {others.map((entry) => (\n <TextField\n key={entry.code}\n label={`Adds (${entry.code})`}\n size=\"small\"\n defaultValue={CommerceModel.minorToInput(\n option.fixedPriceCents?.[entry.code],\n entry.code,\n )}\n placeholder={CommerceModel.minorToInput(\n CommerceModel.amountMinorIn(\n option.priceCents ?? 0,\n currencies.base,\n entry,\n currencies.rates,\n ),\n entry.code,\n )}\n onBlur={(event) =>\n replaceOption(\n groupIndex,\n optionIndex,\n withCurrencyPrice(\n modifierGroups[groupIndex].options[optionIndex],\n entry.code,\n event.target.value,\n ),\n )\n }\n slotProps={{ htmlInput: { inputMode: 'decimal' } }}\n />\n ))}\n </Box>\n </Stack>\n </Collapse>\n ) : null}\n <Collapse in={cardShown} unmountOnExit>\n <Stack spacing={1} sx={{ pl: 2, pt: 1.5 }}>\n <Typography variant=\"caption\" color=\"text.secondary\">\n {`What “${choiceLabel}” shows on its picture card. List what it includes to make it ` +\n 'a combo: shoppers can open the list on its card.'}\n </Typography>\n <CardPictureField\n imageUrl={option.imageUrl}\n label={choiceLabel}\n pick={pick}\n onChange={(imageUrl) =>\n replaceOption(\n groupIndex,\n optionIndex,\n withChoiceCard(modifierGroups[groupIndex].options[optionIndex], { imageUrl }),\n )\n }\n />\n <TextField\n label=\"Note\"\n size=\"small\"\n defaultValue={option.note ?? ''}\n placeholder=\"Blocks wind on one side\"\n onBlur={(event) =>\n replaceOption(\n groupIndex,\n optionIndex,\n withChoiceCard(modifierGroups[groupIndex].options[optionIndex], {\n note: event.target.value,\n }),\n )\n }\n slotProps={{ htmlInput: { maxLength: PRODUCT_CHOICE_NOTE_MAX } }}\n />\n <TextField\n label=\"Combo: what it includes\"\n size=\"small\"\n multiline\n minRows={2}\n defaultValue={Array.isArray(option.includes) ? option.includes.join('\\n') : ''}\n placeholder={'Full wall ×2\\nSteel weights ×4\\nRoller bag'}\n helperText={`One item per line, up to ${PRODUCT_COMBO_MAX_ITEMS}. Leave it empty for a single choice.`}\n onBlur={(event) =>\n replaceOption(\n groupIndex,\n optionIndex,\n withChoiceCard(modifierGroups[groupIndex].options[optionIndex], {\n includes: event.target.value,\n }),\n )\n }\n />\n </Stack>\n </Collapse>\n </Box>\n )\n })}\n <Box>\n <Button\n onClick={() =>\n editGroup(groupIndex, {\n options: [...group.options, { id: newId('o'), name: '', priceCents: 0 }],\n })\n }\n disabled={group.options.length >= CommerceModel.POS_MAX_MODIFIER_OPTIONS}\n >\n {'Add choice'}\n </Button>\n </Box>\n </Stack>\n )}\n </Box>\n ))}\n <Box>\n <Stack direction=\"row\" spacing={1} sx={{ flexWrap: 'wrap', rowGap: 1 }}>\n <Button\n variant=\"outlined\"\n aria-describedby={helpId}\n onClick={() => setGroups([...modifierGroups, newAddOnGroup()])}\n disabled={modifierGroups.length >= CommerceModel.POS_MAX_MODIFIER_GROUPS}\n >\n {'New add-on group'}\n </Button>\n <Button\n variant=\"outlined\"\n aria-describedby={helpId}\n onClick={() => setGroups([...modifierGroups, newWriteInGroup()])}\n disabled={modifierGroups.length >= CommerceModel.POS_MAX_MODIFIER_GROUPS}\n >\n {'New write-in'}\n </Button>\n </Stack>\n </Box>\n {problem && modifierGroups.length ? (\n <Typography variant=\"body2\" color=\"warning.main\">\n {problem}\n </Typography>\n ) : null}\n </Stack>\n )\n})\n"],"names":["Box","Button","Collapse","FormControlLabel","IconButton","Stack","Switch","TextField","Typography","memo","useCallback","useId","useState","CommerceModel","PRODUCT_CHOICE_NOTE_MAX","PRODUCT_COMBO_ITEM_MAX","PRODUCT_COMBO_MAX_ITEMS","CardPictureField","newId","prefix","Math","random","toString","slice","centsFromDollars","value","number","round","Number","String","replace","isFinite","dollarsFromCents","cents","toFixed","priceByLabel","options","named","filter","option","name","trim","length","toLowerCase","newAddOnGroup","id","min","max","online","priceCents","newWriteInGroup","kind","maxLength","DEFAULT_WRITE_IN_LENGTH","withWriteInName","group","map","at","withVariantPrice","variantId","raw","priceCentsByVariant","rest","next","Object","keys","withCurrencyPrice","code","major","parseMajorInput","fixedPriceCents","withCurrencyAmount","undefined","majorToMinor","withChoiceCard","patch","url","imageUrl","note","items","includes","split","item","Boolean","WriteInFields","props","edit","remove","editOption","entry","example","digitsOnly","spacing","variant","color","direction","sx","alignItems","flexWrap","rowGap","label","size","placeholder","onChange","event","target","flex","minWidth","theme","MAX_WRITE_IN_LENGTH","helperText","width","slotProps","htmlInput","inputMode","defaultValue","onBlur","onClick","control","checked","ProductAddOnsFields","modifierGroups","variants","update","pick","currencies","helpId","pricedByVariant","setPricedByVariant","inCurrenciesOpen","setInCurrenciesOpen","others","cardOpen","setCardOpen","setGroups","groups","editGroup","index","replaceOption","groupIndex","optionIndex","problem","modifierGroupsProblem","variesByVariant","byLabel","role","aria-label","border","borderColor","borderRadius","p","modifierGroupIsWriteIn","_group","nameOnOrder","optionKey","byVariantOpen","hasCard","cardShown","currenciesShown","choiceLabel","aria-expanded","open","_option","in","unmountOnExit","pl","pt","display","gridTemplateColumns","xs","sm","gap","variantPriceLabel","minorToInput","amountMinorIn","base","rates","multiline","minRows","Array","isArray","join","disabled","POS_MAX_MODIFIER_OPTIONS","aria-describedby","POS_MAX_MODIFIER_GROUPS"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;;;AAEA,SACEA,GAAG,EACHC,MAAM,EACNC,QAAQ,EACRC,gBAAgB,EAChBC,UAAU,EACVC,KAAK,EACLC,MAAM,EACNC,SAAS,EACTC,UAAU,QACL,gBAAe;AACtB,SAASC,IAAI,EAAEC,WAAW,EAAEC,KAAK,EAAEC,QAAQ,QAAQ,QAAO;AAC1D,YAAYC,mBAAmB,uBAAa;AAC5C,SAASC,uBAAuB,EAAEC,sBAAsB,EAAEC,uBAAuB,QAAQ,oCAAgC;AACzH,SAASC,gBAAgB,QAA+B,wCAAoC;AAqB5F,SAASC,MAAMC,MAAc;IAC3B,OAAO,GAAGA,SAASC,KAAKC,MAAM,GAAGC,QAAQ,CAAC,IAAIC,KAAK,CAAC,GAAG,KAAK;AAC9D;AAEA,qDAAqD,GACrD,SAASC,iBAAiBC,KAAa;IACrC,MAAMC,SAASN,KAAKO,KAAK,CAACC,OAAOC,OAAOJ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;wDACbQ,YAAY,CAAC,yBAAyB,EAAE9F,wBAAwB,qCAAqC,CAAC;wDACtGoG,QAAQ,CAACZ,QACPkC,cACEC,YACAC,aACAlE,eAAe+C,cAAc,CAACkB,WAAW,CAACvG,OAAO,CAACwG,YAAY,EAAE;gEAC9D5D,UAAUwB,MAAMC,MAAM,CAAChF,KAAK;4DAC9B;;;;;;mCAtMFc,OAAOM,EAAE;4BA8MvB;0CACA,KAAC7C;0CACC,cAAA,KAACC;oCACCoH,SAAS,IACPmB,UAAUG,YAAY;4CACpBvG,SAAS;mDAAImB,MAAMnB,OAAO;gDAAE;oDAAES,IAAI3B,MAAM;oDAAMsB,MAAM;oDAAIS,YAAY;gDAAE;6CAAE;wCAC1E;oCAEFqI,UAAU/H,MAAMnB,OAAO,CAACM,MAAM,IAAI7B,cAAc0K,wBAAwB;8CAEvE;;;;;mBAhTFhI,MAAMV,EAAE;;0BAuTjB,KAAC7C;0BACC,cAAA,MAACK;oBAAM0F,WAAU;oBAAMH,SAAS;oBAAGI,IAAI;wBAAEE,UAAU;wBAAQC,QAAQ;oBAAE;;sCACnE,KAAClG;4BACC4F,SAAQ;4BACR2F,oBAAkB1D;4BAClBT,SAAS,IAAMiB,UAAU;uCAAIb;oCAAgB7E;iCAAgB;4BAC7D0I,UAAU7D,eAAe/E,MAAM,IAAI7B,cAAc4K,uBAAuB;sCAEvE;;sCAEH,KAACxL;4BACC4F,SAAQ;4BACR2F,oBAAkB1D;4BAClBT,SAAS,IAAMiB,UAAU;uCAAIb;oCAAgBvE;iCAAkB;4BAC/DoI,UAAU7D,eAAe/E,MAAM,IAAI7B,cAAc4K,uBAAuB;sCAEvE;;;;;YAIN5C,WAAWpB,eAAe/E,MAAM,iBAC/B,KAAClC;gBAAWqF,SAAQ;gBAAQC,OAAM;0BAC/B+C;iBAED;;;AAGV,GAAE"}
@@ -44,6 +44,8 @@ import { MembersVideosField, PaidDownloadAddButton, PaidMediaProtection } from "
44
44
  import { ProductCheckInFields } from "./product-check-in-fields.component.js";
45
45
  import { ProductRegisterFields, ProductSellOnlineField } from "./product-register-fields.component.js";
46
46
  import { ProductAddOnsFields } from "./product-add-ons-fields.component.js";
47
+ import { ProductFixedPricesFields } from "./product-fixed-prices-fields.component.js";
48
+ import { useCurrencySetup } from "./use-currency-setup.js";
47
49
  import { ProductBuilderFields } from "./product-builder-fields.component.js";
48
50
  import { ProductKioskOfferField } from "./product-kiosk-offer-field.component.js";
49
51
  /**
@@ -1510,6 +1512,29 @@ const MemoPaidDownloadAddButton = /*#__PURE__*/ memo(PaidDownloadAddButton);
1510
1512
  }), [
1511
1513
  update
1512
1514
  ]);
1515
+ /*
1516
+ * The store's other currencies (AGL-4248), read once the dialog is open:
1517
+ * a closed editor costs nothing (see the pickers above).
1518
+ */ const currencySetup = useCurrencySetup(hostId, open);
1519
+ const handleFixedPrice = useCallback((index, code, raw)=>update((at)=>{
1520
+ const variants = [
1521
+ ...at.variants
1522
+ ];
1523
+ const major = CommerceModel.parseMajorInput(raw);
1524
+ if (major === null || !variants[index]) return {};
1525
+ const fixedPrices = CommerceModel.withCurrencyAmount(variants[index].fixedPrices, code, major);
1526
+ const next = _extends({}, variants[index]);
1527
+ // A cleared price converts again; an emptied map is dropped, never
1528
+ // stored as `undefined` (the client-direct `setDoc` refuses one).
1529
+ if (fixedPrices) next.fixedPrices = fixedPrices;
1530
+ else delete next.fixedPrices;
1531
+ variants[index] = next;
1532
+ return {
1533
+ variants
1534
+ };
1535
+ }), [
1536
+ update
1537
+ ]);
1513
1538
  const handleSave = useCallback(async ()=>{
1514
1539
  if (!current.name.trim() || error) return;
1515
1540
  /*
@@ -1735,6 +1760,21 @@ const MemoPaidDownloadAddButton = /*#__PURE__*/ memo(PaidDownloadAddButton);
1735
1760
  severity: "warning",
1736
1761
  children: PRODUCT_PRICE_EMPTY_NOTICE
1737
1762
  }) : null,
1763
+ currencySetup.others.length ? /*#__PURE__*/ _jsxs(_Fragment, {
1764
+ children: [
1765
+ /*#__PURE__*/ _jsx(Divider, {
1766
+ textAlign: "left",
1767
+ children: 'Prices in other currencies'
1768
+ }),
1769
+ /*#__PURE__*/ _jsx(ProductFixedPricesFields, {
1770
+ variants: current.variants,
1771
+ base: currencySetup.base,
1772
+ currencies: currencySetup.others,
1773
+ rates: currencySetup.rates,
1774
+ onPrice: handleFixedPrice
1775
+ })
1776
+ ]
1777
+ }) : null,
1738
1778
  /*#__PURE__*/ _jsx(Typography, {
1739
1779
  variant: "caption",
1740
1780
  color: "text.secondary",
@@ -1781,7 +1821,8 @@ const MemoPaidDownloadAddButton = /*#__PURE__*/ memo(PaidDownloadAddButton);
1781
1821
  options: (_current_options2 = current.options) != null ? _current_options2 : NO_OPTIONS,
1782
1822
  variants: current.variants,
1783
1823
  update: update,
1784
- pick: pick
1824
+ pick: pick,
1825
+ currencies: currencySetup
1785
1826
  }),
1786
1827
  /*#__PURE__*/ _jsx(Divider, {
1787
1828
  textAlign: "left",