if (typeof y > "u")
  var y = window;
var k = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof y < "u" ? y : typeof self < "u" ? self : {};
function I(e) {
  return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
}
function E(e) {
  if (e.__esModule)
    return e;
  var t = e.default;
  if (typeof t == "function") {
    var c = function s() {
      return this instanceof s ? Reflect.construct(t, arguments, this.constructor) : t.apply(this, arguments);
    };
    c.prototype = t.prototype;
  } else
    c = {};
  return Object.defineProperty(c, "__esModule", { value: !0 }), Object.keys(e).forEach(function(s) {
    var o = Object.getOwnPropertyDescriptor(e, s);
    Object.defineProperty(c, s, o.get ? o : {
      enumerable: !0,
      get: function() {
        return e[s];
      }
    });
  }), c;
}
/*! js-cookie v3.0.5 | MIT */
function g(e) {
  for (var t = 1; t < arguments.length; t++) {
    var c = arguments[t];
    for (var s in c)
      e[s] = c[s];
  }
  return e;
}
var R = {
  read: function(e) {
    return e[0] === '"' && (e = e.slice(1, -1)), e.replace(/(%[\dA-F]{2})+/gi, decodeURIComponent);
  },
  write: function(e) {
    return encodeURIComponent(e).replace(
      /%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,
      decodeURIComponent
    );
  }
};
function C(e, t) {
  function c(o, r, n) {
    if (!(typeof document > "u")) {
      n = g({}, t, n), typeof n.expires == "number" && (n.expires = new Date(Date.now() + n.expires * 864e5)), n.expires && (n.expires = n.expires.toUTCString()), o = encodeURIComponent(o).replace(/%(2[346B]|5E|60|7C)/g, decodeURIComponent).replace(/[()]/g, escape);
      var u = "";
      for (var f in n)
        n[f] && (u += "; " + f, n[f] !== !0 && (u += "=" + n[f].split(";")[0]));
      return document.cookie = o + "=" + e.write(r, o) + u;
    }
  }
  function s(o) {
    if (!(typeof document > "u" || arguments.length && !o)) {
      for (var r = document.cookie ? document.cookie.split("; ") : [], n = {}, u = 0; u < r.length; u++) {
        var f = r[u].split("="), l = f.slice(1).join("=");
        try {
          var i = decodeURIComponent(f[0]);
          if (n[i] = e.read(l, i), o === i)
            break;
        } catch {
        }
      }
      return o ? n[o] : n;
    }
  }
  return Object.create(
    {
      set: c,
      get: s,
      remove: function(o, r) {
        c(
          o,
          "",
          g({}, r, {
            expires: -1
          })
        );
      },
      withAttributes: function(o) {
        return C(this.converter, g({}, this.attributes, o));
      },
      withConverter: function(o) {
        return C(g({}, this.converter, o), this.attributes);
      }
    },
    {
      attributes: { value: Object.freeze(t) },
      converter: { value: Object.freeze(e) }
    }
  );
}
var M = C(R, { path: "/" });
const j = (e) => {
  var o, r, n;
  const t = (o = window == null ? void 0 : window.location) == null ? void 0 : o.hostname, c = (r = window == null ? void 0 : window.location) != null && r.port ? `:${window.location.port}` : "";
  return `${(n = window == null ? void 0 : window.location) == null ? void 0 : n.protocol}//${t}${c}${e}`;
}, W = j;
function z(e) {
  if (e) {
    const t = Math.trunc(e * 10) / 10;
    return t % 1 === 0 ? Math.trunc(t) : t;
  }
  return 0;
}
function U(e) {
  var c;
  const t = e == null ? void 0 : e.Reference;
  if (t) {
    const s = Object.values(e["Word Phonetic Evaluation"]), o = (c = t == null ? void 0 : t.split(/\s+/)) == null ? void 0 : c.map((n, u) => {
      var i;
      const f = s[u], l = f["Word Score"];
      return (n == null ? void 0 : n.toLowerCase()) === ((i = f.Word) == null ? void 0 : i.toLowerCase()) ? { text: n, highlight: l <= 45 } : { text: n };
    });
    let r = "<p>";
    return o == null || o.forEach((n) => {
      n != null && n.highlight ? r += `<span>${n == null ? void 0 : n.text}</span> ` : r += `${n == null ? void 0 : n.text} `;
    }), r = (r == null ? void 0 : r.trim()) + "</p>", r;
  }
  return "";
}
const b = (e, t = {}) => {
  if (e) {
    const c = [];
    return e != null && e.relevance && c.push({ value: "relevance", label: "Relevance" }), e != null && e.speech_analysis && c.push({ value: "speech", label: "Speech analysis" }), e != null && e.grammar && c.push({ value: "grammar", label: "Grammar" }), { options: c, data: { ...e, ...t } };
  }
  return null;
}, D = (e) => {
  var s;
  if (!e)
    return [];
  const t = (s = e == null ? void 0 : e.data) == null ? void 0 : s.speech_analysis;
  return t == null ? void 0 : t.map((o) => {
    var n;
    const r = (n = Object.values(o == null ? void 0 : o.attempt_data)) == null ? void 0 : n[0];
    return {
      data: r,
      audioText: o != null && o.model_data ? U(o == null ? void 0 : o.model_data) : void 0,
      setupAnalysis: o != null && o.model_data ? b(
        { speech_analysis: [{ model_data: o == null ? void 0 : o.model_data }] },
        { audio: r == null ? void 0 : r.recording }
      ) : void 0
    };
  });
}, O = (e) => {
  var o;
  if (!e)
    return [];
  const t = (o = e == null ? void 0 : e.data) == null ? void 0 : o.speech_analysis, c = (r) => {
    var f;
    if (!r)
      return;
    const n = (f = e == null ? void 0 : e.data) == null ? void 0 : f.grammar;
    if (!n || (n == null ? void 0 : n.length) === 0)
      return;
    const u = n == null ? void 0 : n.find(
      (l) => {
        var i, d;
        return ((d = (i = l == null ? void 0 : l.attempt_data) == null ? void 0 : i.recording) == null ? void 0 : d.id) === r;
      }
    );
    return [{ model_data: u == null ? void 0 : u.model_data }];
  };
  return t == null ? void 0 : t.map((r) => {
    var u;
    const n = r == null ? void 0 : r.attempt_data;
    return {
      data: n,
      audioText: r != null && r.model_data ? U(r == null ? void 0 : r.model_data) : void 0,
      setupAnalysis: r != null && r.model_data ? b(
        {
          speech_analysis: [{ model_data: r == null ? void 0 : r.model_data }],
          grammar: c((u = n == null ? void 0 : n.recording) == null ? void 0 : u.id)
        },
        { audio: (n == null ? void 0 : n.recording) || n, student_text: n == null ? void 0 : n.text }
      ) : void 0
    };
  });
}, B = () => ({ setupAnalysis: b, getResponse: U, getDialogueByModal: D, getQuizByModal: O }), F = B;
function v(e, t, c) {
  for (let s = 0; s < c.length; s++)
    e.setUint8(t + s, c.charCodeAt(s));
}
function S(e) {
  const t = e.numberOfChannels, c = e.sampleRate, s = 1, o = 16, r = o / 8, n = t * r, u = c * n, f = [];
  for (let p = 0; p < t; p++)
    f.push(e.getChannelData(p));
  const l = f[0].length, i = l * t * r, d = new Int16Array(l * t);
  let x = 0;
  for (let p = 0; p < l; p++)
    for (let w = 0; w < t; w++) {
      let h = f[w][p];
      h = Math.max(-1, Math.min(1, h)), d[x++] = h < 0 ? h * 32768 : h * 32767;
    }
  const A = new ArrayBuffer(44 + i), a = new DataView(A);
  return v(a, 0, "RIFF"), a.setUint32(4, 36 + i, !0), v(a, 8, "WAVE"), v(a, 12, "fmt "), a.setUint32(16, 16, !0), a.setUint16(20, s, !0), a.setUint16(22, t, !0), a.setUint32(24, c, !0), a.setUint32(28, u, !0), a.setUint16(32, n, !0), a.setUint16(34, o, !0), v(a, 36, "data"), a.setUint32(40, i, !0), new Int16Array(A, 44).set(d), new Blob([a], { type: "audio/wav" });
}
async function P(e) {
  if (!e || e.size === 0)
    throw new Error("Input blob is empty or null. Cannot convert to WAV.");
  let t;
  try {
    t = new (window.AudioContext || window.webkitAudioContext)();
    const c = await e.arrayBuffer(), s = await t.decodeAudioData(c);
    return S(s);
  } catch (c) {
    throw console.error("Error during blob to WAV conversion:", c), new Error(`Failed to convert blob to WAV: ${c.message}`);
  } finally {
    t && t.state !== "closed" && await t.close();
  }
}
function T(e) {
  const c = document.cookie.split("; ");
  for (const s of c) {
    const [o, r] = s.split("=");
    if (o === e)
      return decodeURIComponent(r);
  }
  return null;
}
const $ = (e) => {
  const t = Math.floor(e), c = Math.floor(t / 60), s = (t % 60).toString().padStart(2, "0");
  return `${c}:${s} min`;
}, V = $;
export {
  M as a,
  E as b,
  k as c,
  T as d,
  V as e,
  z as f,
  I as g,
  P as h,
  W as r,
  F as u
};
//# sourceMappingURL=formatDuration.-4b39a981.js.map
