import*as i18n from"../i18n/i18n.js";import*as UI from"../ui/ui.js";const UIStrings={audiocontext:"AudioContext",offlineaudiocontext:"`OfflineAudioContext`",state:"State",sampleRate:"Sample Rate",callbackBufferSize:"Callback Buffer Size",maxOutputChannels:"Max Output Channels",currentTime:"Current Time",callbackInterval:"Callback Interval",renderCapacity:"Render Capacity"},str_=i18n.i18n.registerUIStrings("web_audio/AudioContextContentBuilder.ts",UIStrings),i18nString=i18n.i18n.getLocalizedString.bind(void 0,str_);export class ContextDetailBuilder{constructor(t){this._fragment=document.createDocumentFragment(),this._container=document.createElement("div"),this._container.classList.add("context-detail-container"),this._fragment.appendChild(this._container),this._build(t)}_build(t){const e="realtime"===t.contextType?i18nString(UIStrings.audiocontext):i18nString(UIStrings.offlineaudiocontext);this._addTitle(e,t.contextId),this._addEntry(i18nString(UIStrings.state),t.contextState),this._addEntry(i18nString(UIStrings.sampleRate),t.sampleRate,"Hz"),"realtime"===t.contextType&&this._addEntry(i18nString(UIStrings.callbackBufferSize),t.callbackBufferSize,"frames"),this._addEntry(i18nString(UIStrings.maxOutputChannels),t.maxOutputChannelCount,"ch")}_addTitle(t,e){this._container.appendChild(UI.Fragment.html`
  <div class="context-detail-header">
  <div class="context-detail-title">${t}</div>
  <div class="context-detail-subtitle">${e}</div>
  </div>
  `)}_addEntry(t,e,n){const i=e+(n?` ${n}`:"");this._container.appendChild(UI.Fragment.html`
  <div class="context-detail-row">
  <div class="context-detail-row-entry">${t}</div>
  <div class="context-detail-row-value">${i}</div>
  </div>
  `)}getFragment(){return this._fragment}}export class ContextSummaryBuilder{constructor(t,e){const n=e.currentTime.toFixed(3),i=(1e3*e.callbackIntervalMean).toFixed(3),a=(1e3*Math.sqrt(e.callbackIntervalVariance)).toFixed(3),r=(100*e.renderCapacity).toFixed(3);this._fragment=document.createDocumentFragment(),this._fragment.appendChild(UI.Fragment.html`
  <div class="context-summary-container">
  <span>${i18nString(UIStrings.currentTime)}: ${n} s</span>
  <span>\u2758</span>
  <span>${i18nString(UIStrings.callbackInterval)}: μ = ${i} ms, σ = ${a} ms</span>
  <span>\u2758</span>
  <span>${i18nString(UIStrings.renderCapacity)}: ${r} %</span>
  </div>
  `)}getFragment(){return this._fragment}}