import { __spreadArray } from 'tslib';
import { KTP_SEPARATOR, KTP_PREFIX, DATAKTP_TARGET, DATAKTP_EXECUTE_TARGET, KTP_LAYER_ID } from './KeytipConstants.js';
import { addElementAtIndex } from '@uifabric-vue/utilities';

function sequencesToID(keySequences) {
  return keySequences.reduce(function(prevValue, keySequence) {
    return prevValue + KTP_SEPARATOR + keySequence.split("").join(KTP_SEPARATOR);
  }, KTP_PREFIX);
}
function mergeOverflows(keySequences, overflowKeySequences) {
  var overflowSequenceLen = overflowKeySequences.length;
  var overflowSequence = __spreadArray([], overflowKeySequences, true).pop();
  var newKeySequences = __spreadArray([], keySequences, true);
  return addElementAtIndex(newKeySequences, overflowSequenceLen - 1, overflowSequence);
}
function ktpTargetFromSequences(keySequences) {
  return "[" + DATAKTP_TARGET + '="' + sequencesToID(keySequences) + '"]';
}
function ktpTargetFromId(keytipId) {
  return "[" + DATAKTP_EXECUTE_TARGET + '="' + keytipId + '"]';
}
function getAriaDescribedBy(keySequences) {
  var describedby = " " + KTP_LAYER_ID;
  if (!keySequences.length) {
    return describedby;
  }
  return describedby + " " + sequencesToID(keySequences);
}

export { getAriaDescribedBy, ktpTargetFromId, ktpTargetFromSequences, mergeOverflows, sequencesToID };
