// TODO: this needs to be refactored to a better location const brandNames = { botox: 'BOTOX®', juvederm: 'JUVÉDERM®', cool_sculpting: 'CoolSculpting® and CoolSculpting® Elite', cool_tone: 'CoolTone®', diamond_glow: 'DiamondGlow®', kybella: 'KYBELLA®', latisse: 'LATISSE®', natrelle: 'Natrelle®', skin_medica: 'SkinMedica®', }; const ImportantSafetyInformationMachine = Machine( { id: 'isi-builder', initial: 'start', context: { brands: [''], codeIds: [], }, states: { start: { on: { '': [ { target: 'containsBotox', cond: 'containsBotox' }, { target: 'singleSafetyAndPrescribingInfo', cond: 'hasKybellaOrLatisse', actions: 'setSingleSafetyInformationOnly', }, { target: 'importantSafetyInformationOnly', actions: 'setImportantSafetyInformationOnly', }, ], }, }, containsBotox: { on: { '': [ { target: 'botoxOnly', cond: 'hasOnlyOneCondition', actions: 'setBotoxOnly', }, { target: 'botoxSafetyAndPrescribingInfo', cond: 'hasKybellaOrLatisse', actions: ['setBotoxOnly', 'setSafetyAndPrescribingInfo'], }, { target: 'botoxOnlyImportantSafetyInformationOnly', actions: ['setBotoxOnly', 'setImportantSafetyInformationOnly'], }, ], }, }, singleSafetyAndPrescribingInfo: {}, importantSafetyInformationOnly: {}, doesNotContainBotox: {}, hasOnlyOneCondition: {}, botoxOnly: {}, botoxSafetyAndPrescribingInfo: {}, botoxOnlyImportantSafetyInformationOnly: {}, }, }, { actions: { setBotoxOnly: assign({ codeIds: (context) => { return [...context.codeIds, 'BotoxOnly']; }, }), setImportantSafetyInformationOnly: assign({ codeIds: (context) => [ ...context.codeIds, 'ImportantSafetyInformationOnly', ], }), setSingleSafetyInformationOnly: assign({ codeIds: (context) => [ ...context.codeIds, 'SingleSafetyAndPrescribingInfo', ], }), setSafetyAndPrescribingInfo: assign({ codeIds: (context) => { return [...context.codeIds, 'SafetyAndPrescribingInfo']; }, }), }, guards: { doesNotContainBotox: (context) => !context.brands.includes(brandNames.botox), containsBotox: (context) => context.brands.includes(brandNames.botox), hasOnlyOneCondition: (context) => context.brands.length === 1, hasKybellaOrLatisse: (context) => { return context.brands.some( (brand) => brand === brandNames.kybella || brand === brandNames.latisse ); }, }, } );