import {type} from 'os';

interface LangDetails {
  langCode: string;
  langName: string;
}

export default interface LangFormat {
  details: LangDetails;
  curVersion: string;
  appName: string;
  startHelper1: string;
}

interface LangPlaceholderKeys {
  version?: number;
  appName?: string;
}

export function placeholder(text: string, data: LangPlaceholderKeys): string {
  let out = text;

  for (const key in data) {
    const rawValue = data[key as keyof LangPlaceholderKeys];

    let _value: any =
      typeof rawValue === 'number' ? rawValue.toString() : rawValue;

    if (typeof rawValue === 'undefined') _value = 'undefined';
    let value: string = _value;

    out = out.replaceAll('${' + key + '}', value);
  }

  return out;
}

/*
var str = 'Good ${timeOfTheDay}, ${name}. I am from ${city}, ${age} years old';

var parts = str.split(/(\$\{\w+?})/g).map(function(v) {
  var replaced = v.replace(/\$\{(\w+?)}/g, '$1');
  return content[replaced] || v;
});

console.log(parts.join(''));
 */
