/**
 * Internationalization utilities for WooNooW Admin SPA
 * Uses WordPress i18n functions via wp.i18n
 */

// WordPress i18n is loaded globally
declare const wp: {
  i18n: {
    __: (text: string, domain: string) => string;
    _x: (text: string, context: string, domain: string) => string;
    _n: (single: string, plural: string, number: number, domain: string) => string;
    sprintf: (format: string, ...args: any[]) => string;
  };
};

const TEXT_DOMAIN = 'woonoow';

/**
 * Translate a string
 */
export function __(text: string): string {
  if (typeof wp !== 'undefined' && wp.i18n && wp.i18n.__) {
    return wp.i18n.__(text, TEXT_DOMAIN);
  }
  return text; // Fallback to original text
}

/**
 * Translate a string with context
 */
export function _x(text: string, context: string): string {
  if (typeof wp !== 'undefined' && wp.i18n && wp.i18n._x) {
    return wp.i18n._x(text, context, TEXT_DOMAIN);
  }
  return text;
}

/**
 * Translate plural forms
 */
export function _n(single: string, plural: string, number: number): string {
  if (typeof wp !== 'undefined' && wp.i18n && wp.i18n._n) {
    return wp.i18n._n(single, plural, number, TEXT_DOMAIN);
  }
  return number === 1 ? single : plural;
}

/**
 * sprintf-style formatting
 */
export function sprintf(format: string, ...args: any[]): string {
  if (typeof wp !== 'undefined' && wp.i18n && wp.i18n.sprintf) {
    return wp.i18n.sprintf(format, ...args);
  }
  // Simple fallback
  return format.replace(/%s/g, () => String(args.shift() || ''));
}
