{"version":3,"file":"2SsV4dRH.js","sources":["../../../../composables/useInstrumentsConstants.ts","../../../../node_modules/nuxt/dist/app/compat/interval.js","../../../../composables/useInstrumentStateText.ts","../../../../composables/useInstrumentsProgress.ts"],"sourcesContent":["import { type Color } from '~/components/common/Badge.vue';\r\nimport { InstrumentState } from '~/models/instruments';\r\n\r\nexport function useInstrumentsConstants() {\r\n const icons = {\r\n barrel:\r\n '',\r\n bottle:\r\n '',\r\n car: '',\r\n coin: '',\r\n gem: '',\r\n generic:\r\n '',\r\n instrument:\r\n '',\r\n jewelry:\r\n '',\r\n medal:\r\n '',\r\n painting:\r\n '',\r\n sculpture:\r\n '',\r\n stamp:\r\n '',\r\n watch:\r\n '',\r\n wines:\r\n '',\r\n };\r\n const stateToColor: { [key in InstrumentState]: Color } = {\r\n [InstrumentState.InPreparation]: 'orange',\r\n [InstrumentState.BeingSubscribed]: 'green',\r\n [InstrumentState.Subscribed]: 'red',\r\n [InstrumentState.Hidden]: 'yellow',\r\n [InstrumentState.SubscriptionUnsuccessful]: 'gray',\r\n [InstrumentState.EvaluatingResults]: 'gray',\r\n [InstrumentState.Sold]: 'gray',\r\n [InstrumentState.PartlySold]: 'red-neon',\r\n };\r\n const stateToSubscriptionState = {\r\n [InstrumentState.InPreparation]: InstrumentState[InstrumentState.InPreparation],\r\n [InstrumentState.BeingSubscribed]: InstrumentState[InstrumentState.BeingSubscribed],\r\n [InstrumentState.Subscribed]: InstrumentState[InstrumentState.Subscribed],\r\n [InstrumentState.Hidden]: InstrumentState[InstrumentState.Hidden],\r\n [InstrumentState.SubscriptionUnsuccessful]:\r\n InstrumentState[InstrumentState.SubscriptionUnsuccessful],\r\n [InstrumentState.EvaluatingResults]: InstrumentState[InstrumentState.EvaluatingResults],\r\n [InstrumentState.Sold]: InstrumentState[InstrumentState.Subscribed],\r\n [InstrumentState.PartlySold]: InstrumentState[InstrumentState.Subscribed],\r\n };\r\n\r\n return {\r\n icons,\r\n stateToColor,\r\n stateToSubscriptionState,\r\n };\r\n}\r\n","import { createError } from \"../composables/error.js\";\nconst intervalError = \"[nuxt] `setInterval` should not be used on the server. Consider wrapping it with an `onNuxtReady`, `onBeforeMount` or `onMounted` lifecycle hook, or ensure you only call it in the browser by checking `import.meta.client`.\";\nexport const setInterval = import.meta.client ? window.setInterval : () => {\n if (import.meta.dev) {\n throw createError({\n statusCode: 500,\n message: intervalError\n });\n }\n console.error(intervalError);\n};\n","import { type Instrument, InstrumentState } from '~/models/instruments';\r\n\r\nexport function useInstrumentStateText(instrument: Readonly[>) {\r\n const { t, locale } = useI18n();\r\n const { differenceInSeconds, addHours, formatDuration, intervalToDuration } = useDateFns();\r\n\r\n const stateText = ref('');\r\n const showHiddenResultsUntil = ref(false);\r\n\r\n function createHiddenText() {\r\n const issueDate = new Date(instrument.value!.IssueDate);\r\n\r\n stateText.value = t('instrument-card.data.will-begin-subscription-at-date', {\r\n date: issueDate.toLocaleString(locale.value, {\r\n dateStyle: 'medium',\r\n }),\r\n });\r\n }\r\n\r\n function createHiddenUntilText() {\r\n const hiddenResultsUntil = new Date(instrument.value!.HiddenResultsUntil!);\r\n\r\n stateText.value = t('instrument-card.data.collecting-orders-until', {\r\n time: hiddenResultsUntil.toLocaleString(locale.value, {\r\n hour: 'numeric',\r\n minute: 'numeric',\r\n }),\r\n });\r\n }\r\n\r\n function createInPreparationText() {\r\n const issueDate = new Date(instrument.value!.IssueDate);\r\n\r\n stateText.value = t('instrument-card.data.will-begin-subscription-at-date-and-time', {\r\n date: issueDate.toLocaleString(locale.value, {\r\n dateStyle: 'medium',\r\n }),\r\n time: issueDate.toLocaleString(locale.value, {\r\n hour: 'numeric',\r\n minute: 'numeric',\r\n }),\r\n });\r\n }\r\n\r\n function createRemainingTimeText() {\r\n const endOfSubscription = addHours(\r\n new Date(instrument.value!.EndOfSubscription ?? Date.now()),\r\n 24,\r\n );\r\n const diff = differenceInSeconds(new Date(), endOfSubscription);\r\n if (diff >= 0) {\r\n stateText.value = t('instrument-card.data.subscription-ended');\r\n }\r\n\r\n let duration = intervalToDuration({\r\n start: new Date(),\r\n end: endOfSubscription,\r\n });\r\n duration = {\r\n months: duration.months ?? 0,\r\n days: duration.days ?? 0,\r\n hours: duration.hours ?? 0,\r\n minutes: duration.minutes ?? 0,\r\n seconds: duration.seconds ?? 0,\r\n };\r\n if (\r\n duration.months === 0 &&\r\n duration.days === 0 &&\r\n duration.hours === 0 &&\r\n duration.minutes === 0 &&\r\n duration.seconds! <= 0\r\n ) {\r\n stateText.value = t('instrument-card.data.subscription-ended');\r\n\r\n return;\r\n }\r\n\r\n if (duration.months === 0 && duration.days! < 1) {\r\n stateText.value = t('instrument-card.data.remains-less-than-day');\r\n\r\n return;\r\n }\r\n\r\n stateText.value = formatDuration(duration, {\r\n format: [...(duration.months !== 0 ? ['months'] : []), 'days'],\r\n locale: { code: locale.value },\r\n zero: true,\r\n });\r\n }\r\n\r\n function maybeStartRefreshTimer() {\r\n const issueDate = new Date(instrument.value!.IssueDate);\r\n const secondsDifference = differenceInSeconds(issueDate, new Date());\r\n\r\n // 6 hours in seconds\r\n if (secondsDifference > 0 && secondsDifference <= 60 * 60 * 6) {\r\n setInterval(() => {\r\n const secondsDifference = differenceInSeconds(issueDate, new Date());\r\n\r\n // between 0 and 10 seconds ellapsed from issueDate\r\n if (secondsDifference <= 0 && secondsDifference >= -10) {\r\n window.location.reload();\r\n }\r\n }, 10_000);\r\n }\r\n }\r\n\r\n watch(\r\n instrument,\r\n () => {\r\n if (!instrument.value) {\r\n return;\r\n }\r\n\r\n if (instrument.value.State === InstrumentState.Hidden) {\r\n createHiddenText();\r\n\r\n return;\r\n }\r\n\r\n if (\r\n instrument.value.HideResults &&\r\n instrument.value!.State !== InstrumentState.EvaluatingResults\r\n ) {\r\n showHiddenResultsUntil.value = true;\r\n createHiddenUntilText();\r\n\r\n return;\r\n }\r\n\r\n if (instrument.value.State === InstrumentState.InPreparation) {\r\n const hiddenResultsUntil = new Date(instrument.value.HiddenResultsUntil!);\r\n const diff = differenceInSeconds(new Date(), hiddenResultsUntil);\r\n\r\n if (diff <= -1 && diff >= -15 * 60) {\r\n showHiddenResultsUntil.value = true;\r\n createHiddenUntilText();\r\n\r\n return;\r\n }\r\n\r\n createInPreparationText();\r\n\r\n maybeStartRefreshTimer();\r\n }\r\n\r\n if (instrument.value.State === InstrumentState.BeingSubscribed) {\r\n createRemainingTimeText();\r\n }\r\n },\r\n { immediate: true },\r\n );\r\n\r\n return {\r\n stateText,\r\n showHiddenResultsUntil,\r\n };\r\n}\r\n","import { clamp } from '~/lib/number-formats';\r\nimport { type Instrument, InstrumentState } from '~/models/instruments';\r\n\r\nconst computeProgress = (instrument: Instrument | undefined) => {\r\n if (\r\n !instrument ||\r\n instrument.State === InstrumentState.InPreparation ||\r\n !instrument.FECurrentAmount ||\r\n !instrument.Amount ||\r\n instrument.HideResults\r\n ) {\r\n return 0;\r\n }\r\n\r\n return clamp(Math.floor((instrument.FECurrentAmount / instrument.Amount) * 100), 0, 100);\r\n};\r\n\r\nexport function useInstrumentsProgress(instrument: Readonly][>) {\r\n const progress = ref(computeProgress(instrument.value));\r\n\r\n watch(instrument, () => {\r\n progress.value = computeProgress(instrument.value);\r\n });\r\n\r\n return progress;\r\n}\r\n"],"names":["useInstrumentsConstants","icons","stateToColor","InstrumentState","stateToSubscriptionState","setInterval","useInstrumentStateText","instrument","locale","useI18n","differenceInSeconds","addHours","formatDuration","intervalToDuration","useDateFns","stateText","ref","showHiddenResultsUntil","createHiddenText","issueDate","createHiddenUntilText","hiddenResultsUntil","createInPreparationText","createRemainingTimeText","endOfSubscription","duration","maybeStartRefreshTimer","secondsDifference","watch","diff","computeProgress","clamp","useInstrumentsProgress","progress"],"mappings":"4FAGO,SAASA,GAA0B,CACxC,MAAMC,EAAQ,CACZ,OACE,ynGACF,OACE,oiCACF,IAAK,q+EACL,KAAM,oTACN,IAAK,ugBACL,QACE,kWACF,WACE,2+JACF,QACE,m/GACF,MACE,gsBACF,SACE,q1NACF,UACE,qmLAC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