"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/utils/StateMachines.ts
var StateMachines_exports = {};
__export(StateMachines_exports, {
  getUniqueStateIds: () => getUniqueStateIds
});
module.exports = __toCommonJS(StateMachines_exports);

// src/utils/uuid.ts
function uuidv4() {
  return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
    const r = Math.random() * 16 | 0, v = c == "x" ? r : r & 3 | 8;
    return v.toString(16);
  });
}

// src/utils/StateMachines.ts
function getUniqueStateIds(inputArray, parent) {
  let statesArray = [...inputArray];
  if (statesArray[0]?.id.indexOf("|") >= 0) {
    return statesArray;
  }
  statesArray = statesArray.map((state, index, original) => {
    switch (state.id) {
      // these states only hve one occurance in all machines
      case "success":
      case "failure":
      case "pause":
        break;
      default:
        state.id = `${state.id}|${uuidv4()}`;
        if (parent) {
          state.parentId = parent.id;
        }
        break;
    }
    return state;
  });
  statesArray = statesArray.map((state, index) => {
    switch (state.id) {
      // these states only hve one occurance in all machines
      case "success":
      case "failure":
      case "pause":
        break;
      default:
        const futureStates = statesArray.slice(index + 1);
        state.transitions = state.transitions?.map((stateTranistion) => {
          const targetState = futureStates.find((futureState) => futureState.id.indexOf(stateTranistion.target) >= 0);
          stateTranistion.target = targetState ? targetState.id : stateTranistion.target;
          return stateTranistion;
        });
        if (state.onDone) {
          if (state.onDone instanceof Array) {
            state.onDone = state.onDone[0].target;
          }
          if (state.onDone instanceof Object) {
            state.onDone = state.onDone.target;
          }
          const targetState = futureStates.find((futureState) => futureState.id.indexOf(state.onDone) >= 0);
          state.onDone = targetState ? targetState.id : state.onDone;
        }
        if (state.states) {
          getUniqueStateIds(state.states, state);
        }
        break;
    }
    return state;
  });
  return statesArray;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  getUniqueStateIds
});
