/**
 * Handles getting the current value.
 *
 * @param {boolean} simpleValue - Whether `simpleValue` is set.
 * @param {string|{label: string, value: string, metadata: Object<string, any>[]}} value - Current value.
 * @param {{label: string, value: string}[]} options - Options passed to the component.
 *
 * @returns Appropriate output for the given input combination.
 *
 * @preserve
 */
const getValue = (simpleValue, value, options) => {
  if (Array.isArray(value)) {
    if (simpleValue) {
      return value.map((value2) => options?.find(({ value: itemValue }) => itemValue === value2));
    }
    return value;
  }
  if (simpleValue) {
    return options?.find(({ value: itemValue }) => itemValue === value);
  }
  return value;
};
const moveArrayItem = (array, itemToMove, targetItem, position = "before") => {
  const result = [...array];
  const sourceIndex = result.indexOf(itemToMove);
  const targetIndex = result.indexOf(targetItem);
  if (sourceIndex === -1 || targetIndex === -1) {
    return result;
  }
  result.splice(sourceIndex, 1);
  let adjustedTargetIndex;
  if (position === "after") {
    adjustedTargetIndex = sourceIndex < targetIndex ? targetIndex : targetIndex + 1;
  } else if (position === "before") {
    adjustedTargetIndex = sourceIndex < targetIndex ? targetIndex - 1 : targetIndex;
  }
  result.splice(adjustedTargetIndex, 0, itemToMove);
  return result;
};
export {
  getValue,
  moveArrayItem
};
