{"version":3,"file":"FinderStore.js","names":["BaseStore","a","default","execute","initialData","currentStep","activeStep","totalSteps","oldStep","completedStep","lastCompletedStep","answers","isValid","isReset","isShowLanding","areDependenciesUpdated","isSubmitFlow","dependencies","finderStore","goTo","state","newStep","Object","assign","saveAnswer","newState","dependentSection","index","filter","answer","push","runNextSection","questionStep","question","lastDependentStep","length","includes","reset","setDependencies","dependentAnswers","reduce","acc","section","concat","map","some"],"sources":["stores/FinderStore.js"],"sourcesContent":["/* eslint-disable require-jsdoc */\nimport BaseStore from 'stores/BaseStore';\n\nconst initialData = {\n currentStep: 0, // Step where the user is\n activeStep: 0, // Step that is currently active\n totalSteps: 0, // Total number of steps\n oldStep: null, // last step where the user was on\n completedStep: null, // Step completed\n lastCompletedStep: -1, // Last completed step\n answers: [], // List of answers for each step - Answer object { name, value }\n isValid: false, // true when all steps are good\n isReset: false, // true when view is reset\n isShowLanding: true, // show the landing step\n areDependenciesUpdated: false, // true when dependencies were updated\n isSubmitFlow: true, // true if store is updated during the submit flow\n dependencies: [], // Finder answers and dependencies\n};\n\nconst finderStore = new BaseStore(initialData, {\n goTo: (state, newStep) => (\n Object.assign({}, state, {\n oldStep: state.currentStep,\n currentStep: newStep,\n completedStep: state.completedStep,\n isReset: false,\n isSubmitFlow: false,\n isShowLanding: false, // hide landing page if go to some step\n })\n ),\n saveAnswer: (state, newState) => {\n let { answers } = state;\n const dependentSection = state.dependencies[newState.index] ? state.dependencies[newState.index].dependentSection : false;\n\n if (newState && dependentSection) {\n // remove all answers with bigger index then current dependent one\n answers = state.answers.filter(answer => answer.index < newState.index);\n answers.push(newState);\n } else {\n // replace answers with current index\n answers[newState.index] = newState;\n }\n\n const isSubmitFlow = newState.isSubmitFlow === true;\n const runNextSection = newState.runNextSection || false;\n const oldStep = newState.index;\n const currentStep = newState.index + (runNextSection ? 1 : 0);\n const activeStep = currentStep;\n const completedStep = newState.index;\n const questionStep = newState.question;\n const lastDependentStep = dependentSection ? newState.index : state.lastDependentStep;\n const lastCompletedStep = runNextSection ? newState.index : state.lastCompletedStep;\n\n return Object.assign({}, state, {\n isSubmitFlow,\n answers,\n oldStep,\n currentStep,\n activeStep,\n completedStep,\n lastCompletedStep,\n lastDependentStep,\n questionStep,\n isReset: false,\n areDependenciesUpdated: false,\n\n get isValid() {\n return answers.length === state.totalSteps && !answers.includes(undefined);\n },\n });\n },\n reset: (state, newState) => (\n Object.assign({}, state, initialData, {\n oldStep: 0,\n totalSteps: state.totalSteps,\n isReset: true,\n isShowLanding: newState.isShowLanding,\n lastCompletedStep: -1,\n answers: [],\n })\n ),\n setDependencies: (state, newState) => {\n if (newState.dependencies) {\n state.dependencies[newState.dependencies.index] = newState.dependencies;\n }\n\n const dependentAnswers = state.dependencies.reduce((acc, section) => acc.concat(section.dependentAnswers), []);\n const isSubmitFlow = newState.isSubmitFlow === true;\n\n return Object.assign({}, state, {\n isSubmitFlow,\n isReset: false,\n areDependenciesUpdated: true,\n dependencies: state.dependencies.map(section => Object.assign({}, section, {\n dependentSection: section.answers.some(answer => dependentAnswers.includes(answer)),\n })),\n });\n },\n\n});\n\nexport default finderStore;\n"],"mappings":"iHACOA,CAAS,CAAAC,CAAA,CAAAC,OAAA,GAAAC,OAAA,SAAAA,CAAA,EAEVC,CAAW,CAAG,CAChBC,WAAW,CAAE,CAAC,CACdC,UAAU,CAAE,CAAC,CACbC,UAAU,CAAE,CAAC,CACbC,OAAO,CAAE,IAAI,CACbC,aAAa,CAAE,IAAI,CACnBC,iBAAiB,CAAE,CAAC,CAAC,CACrBC,OAAO,CAAE,EAAE,CACXC,OAAO,GAAO,CACdC,OAAO,GAAO,CACdC,aAAa,GAAM,CACnBC,sBAAsB,GAAO,CAC7BC,YAAY,GAAM,CAClBC,YAAY,CAAE,EAClB,CAAC,CAEKC,CAAW,CAAG,GAAI,CAAAlB,CAAS,CAACI,CAAW,CAAE,CAC3Ce,IAAI,CAAEA,CAACC,CAAK,CAAEC,CAAO,GACjBC,MAAM,CAACC,MAAM,CAAC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