"use strict";

import { TurboModuleRegistry } from 'react-native';
import ShikiEngine from '../NativeShikiEngine';
import { convertToOnigMatch } from './utils';
export function createNativeEngine(options = {}) {
  const {
    maxCacheSize = 1000
  } = options;
  if (!isNativeEngineAvailable()) {
    throw new Error('Native engine not available');
  }
  return {
    createScanner(patterns) {
      if (!Array.isArray(patterns) || patterns.some(p => typeof p !== 'string')) {
        throw new TypeError('Patterns must be an array of strings');
      }
      const scannerId = ShikiEngine.createScanner(patterns, maxCacheSize);
      if (typeof scannerId !== 'number') {
        throw new TypeError('Failed to create native scanner');
      }
      return {
        findNextMatchSync(string, startPosition) {
          if (startPosition < 0) throw new RangeError('Start position must be >= 0');
          const stringContent = typeof string === 'string' ? string : string.content;
          if (typeof stringContent !== 'string') throw new TypeError('Invalid input string');
          try {
            const result = ShikiEngine.findNextMatchSync(scannerId, stringContent, startPosition);
            return convertToOnigMatch(result);
          } catch (err) {
            if (__DEV__) console.error('Error in findNextMatchSync:', err);
            throw err;
          }
        },
        dispose() {
          try {
            ShikiEngine.destroyScanner(scannerId);
          } catch (err) {
            if (__DEV__) console.error('Error disposing scanner:', err);
          }
        }
      };
    },
    createString(s) {
      if (typeof s !== 'string') throw new TypeError('Input must be a string');
      return {
        content: s
      };
    }
  };
}
export function isNativeEngineAvailable() {
  try {
    return TurboModuleRegistry.getEnforcing('ShikiEngine') != null;
  } catch {
    return false;
  }
}
//# sourceMappingURL=index.js.map