"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.PunctuationMixin = PunctuationMixin;
var _wasmLoader = require("../wasmLoader.js");
var _mixinUtils = require("./mixinUtils.js");
function PunctuationMixin(Base) {
  return class extends Base {
    punctuation = null;
    async initPunctuation(config) {
      try {
        await (0, _wasmLoader.loadCombinedWasm)();
        if (!window.SherpaOnnx.Punctuation) {
          return {
            success: false,
            error: 'Punctuation module not loaded'
          };
        }
        const debug = config?.debug ? 1 : 0;
        const numThreads = 1; // WASM is single-threaded

        console.log(`[Punctuation] Loading model (threads=${numThreads}, debug=${debug})...`);
        // Web-only: config.modelDir is set to '/wasm/punctuation' by ModelManagement
        // (createWebPunctuationModelState in constants.ts), pointing to model files
        // pre-served by download-web-models.sh. Native Punctuation uses the TurboModule.
        const modelDir = config?.modelDir || '/wasm/punctuation';
        const fetchBase = config?.modelBaseUrl || modelDir;
        const loadedModel = await (0, _mixinUtils.withDownloadProgress)(config?.onProgress, () => window.SherpaOnnx.Punctuation.loadModel({
          cnnBilstm: `${fetchBase}/model.onnx`,
          bpeVocab: `${fetchBase}/bpe.vocab`,
          modelDir,
          debug
        }));
        this.punctuation = window.SherpaOnnx.Punctuation.createPunctuation(loadedModel, {
          numThreads,
          debug
        });
        console.log('[Punctuation] Initialized successfully');
        return {
          success: true
        };
      } catch (error) {
        console.error('[Punctuation] initPunctuation failed:', error);
        return {
          success: false,
          error: error.message
        };
      }
    }
    async addPunctuation(text) {
      if (!this.punctuation) {
        return {
          success: false,
          text: '',
          durationMs: 0,
          error: 'Punctuation not initialized'
        };
      }
      try {
        const startMs = performance.now();
        const result = this.punctuation.addPunct(text);
        const durationMs = performance.now() - startMs;
        return {
          success: true,
          text: result,
          durationMs
        };
      } catch (error) {
        return {
          success: false,
          text: '',
          durationMs: 0,
          error: error.message
        };
      }
    }
    async releasePunctuation() {
      if (this.punctuation) {
        try {
          this.punctuation.free();
        } catch (_) {
          console.error('[Punctuation] releasePunctuation failed:', _);
        }
        this.punctuation = null;
      }
      return {
        released: true
      };
    }
  };
}
//# sourceMappingURL=punctuation.js.map