{"version":3,"file":"useSteps.mjs","sources":["../../../lib/data-provider-interface/utils/useSteps.js"],"sourcesContent":["import { reactive, toRef, ref, watch } from 'vue'\nimport { getNode, createMessage } from '@formkit/core'\n\nexport default function useSteps () {\n  const activeStep = ref('')\n  const steps = reactive({})\n  const visitedSteps = ref([]) // track visited steps\n\n  // Watch our activeStep and store visited steps\n  watch(activeStep, (newStep, oldStep) => {\n    if (oldStep && !visitedSteps.value.includes(oldStep)) {\n      visitedSteps.value.push(oldStep)\n    }\n\n    // Trigger showing validation on fields if a group has been visited\n    visitedSteps.value.forEach((step) => {\n      const node = getNode(step)\n\n      if (node === undefined) return;\n\n      // the node.walk() method walks through all the descendants of the current node\n      // and executes the provided function.\n      node.walk((n) => {\n        n.store.set(\n          createMessage({\n            key: 'submitted',\n            value: true,\n            visible: false\n          })\n        )\n      })\n    })\n  });\n\n  const stepPlugin = (node) => {\n    if (node.props.type == \"group\") {\n      // builds an object of the top-level groups\n      steps[node.name] = steps[node.name] || { }\n\n      node.on('created', () => {\n        // use 'on created' to ensure context object is available\n        const state = toRef(node.context.state, 'valid')\n        steps[node.name].valid = state;\n      })\n\n      // Store or update the count of blocking validation messages.\n      // FormKit emits the \"count:blocking\" event (with the count) each time\n      // the count changes.\n      node.on('count:blocking', ({ payload: count }) => {\n        steps[node.name].blockingCount = count\n      })\n\n      // Store or update the count of backend error messages.\n      node.on('count:errors', ({ payload: count }) => {\n        steps[node.name].errorCount = count\n      })\n\n      // set the active tab to the 1st tab\n      if (activeStep.value === '') {\n        activeStep.value = node.name\n      }\n\n      // Stop plugin inheritance to descendant nodes\n      return false\n    }\n    \n  }\n\n  return { visitedSteps, activeStep, steps, stepPlugin }\n}"],"names":["useSteps","activeStep","ref","steps","reactive","visitedSteps","watch","newStep","oldStep","step","node","getNode","n","createMessage","state","toRef","count"],"mappings":";;AAGe,SAASA,IAAY;AAClC,QAAMC,IAAaC,EAAI,EAAE,GACnBC,IAAQC,EAAS,EAAE,GACnBC,IAAeH,EA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