

















(function () {
  'use strict';

  function PrepBar(opts) {
    opts = opts || {};
    var banner = (opts.variant === 'banner');
    this.wrap = document.createElement('div');
    





    this.wrap.style.cssText = banner
      ? 'display:none; min-width:300px; max-width:min(420px, 60vw); ' +
        'background:rgba(20,22,26,.96); border:1px solid #4da3ff; border-radius:6px; ' +
        'padding:8px 12px; box-shadow:0 4px 14px rgba(0,0,0,.45); pointer-events:none;'
      : 'margin-top:3px; display:none;';
    var line = document.createElement('div');
    line.style.cssText = 'color:#8ab4f8; display:flex; gap:8px; ' +
      (banner ? 'font-size:12px;' : 'font-size:10px;');
    this.whatEl = document.createElement('span');
    this.whatEl.style.cssText = 'flex:1 1 auto; overflow:hidden; ' +
      'text-overflow:ellipsis; white-space:nowrap;';
    this.leftEl = document.createElement('span');
    this.leftEl.style.cssText = 'flex:0 0 auto; font-variant-numeric:tabular-nums;';
    line.appendChild(this.whatEl);
    line.appendChild(this.leftEl);
    this.wrap.appendChild(line);
    var rail = document.createElement('div');
    rail.style.cssText = 'border-radius:2px; background:#2b3138; overflow:hidden;' +
      (banner ? 'height:4px; margin-top:6px;' : 'height:3px; margin-top:2px;');
    this.barEl = document.createElement('div');
    this.barEl.style.cssText = 'height:100%; width:0%; background:#4da3ff; ' +
      'transition:width .12s linear;';
    rail.appendChild(this.barEl);
    this.wrap.appendChild(rail);
    this._mode = null;      
    this._what = '';
    this._t0 = 0;
    this._eta = 0;
    this._k = 0;
  }

  


  PrepBar.prototype.el = function () { return this.wrap; };

  PrepBar.prototype.active = function () { return this._mode !== null; };

  

  PrepBar.prototype.setEta = function (what, etaS) {
    var eta = Math.max(0, Number(etaS) || 0);
    
    if (!(this._mode === 'eta' && this._what === what && this._eta === eta)) {
      this._t0 = performance.now();
    }
    this._mode = 'eta';
    this._what = what;
    this._eta = eta;
    this._paint();
  };

  

  PrepBar.prototype.setFraction = function (what, k) {
    this._mode = 'frac';
    this._what = what;
    this._k = Math.max(0, Math.min(1, Number(k) || 0));
    this._paint();
  };

  PrepBar.prototype.clear = function () {
    this._mode = null;
    this._what = '';
    this._eta = 0;
    this._t0 = 0;
    this._k = 0;
    this.wrap.style.display = 'none';
  };

  
  PrepBar.prototype.tick = function () {
    if (this._mode === 'eta') this._paint();
  };

  PrepBar.prototype._paint = function () {
    if (this._mode === null) { this.wrap.style.display = 'none'; return; }
    this.wrap.style.display = '';
    this.whatEl.textContent = this._what;
    if (this._mode === 'frac') {
      this.barEl.style.width = (this._k * 100).toFixed(1) + '%';
      this.leftEl.textContent = '';
      return;
    }
    if (!this._eta || !this._t0) {
      this.barEl.style.width = '0%';
      this.leftEl.textContent = '';
      return;
    }
    var done = (performance.now() - this._t0) / 1000;
    var k = Math.max(0, Math.min(0.99, done / this._eta));   
    this.barEl.style.width = (k * 100).toFixed(1) + '%';
    this.leftEl.textContent = VizI18n.tr('viz_teach_goto_left', '还剩 {n}s')
      .replace('{n}', Math.max(0, this._eta - done).toFixed(1));
  };

  window.PrepBar = PrepBar;
})();
