import {chatTags} from '@caj/components/chat/types';
import {type} from 'os';

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

export default interface LangFormat {
  details: LangDetails;
  curVersion: string;
  appName: string;
  appNameDesc: string;
  startHelper1: string;
  navigation: {
    home: {
      account: string;
      calendar: string;
      chat: string;
    };
  };
  info: string;
  error: string;
  success: string;
  chat: {
    tags: {
      names: {[key in chatTags]: string};
    };
  };
  account: {
    profile: {
      follower: string;
      following: string;
    };
    login: {
      title: string;
      wrongEmPw: string;
      failed: string;
      success: string;
    };
    registration: {
      registration: string;

      info: string;
      privacyPolicy: string;
      termsOfUse: string;
      stepOne: {
        title: string;
        success: string;
        addressExists: string;
        addressInvalid: string;
        noMailEntered: string;
        button: string;
      };
      stepTwo: {
        title: string;
        verification: string;
        resend: [string, string, string];
        noCodeEntered: string;
        resendError: {[key: number]: string};
        verificationError: {[key: number]: string};
        button: string;
        success: string;
      };
      stepFinal: {
        verification: string;
        userName: string;
        accountName: string;
        password: string;
        passwordRepeat: string;
        displayName: string;
        accountNameError: {[key: string]: string};
        userNameError: {[key: string]: string};
        passwordError: {[key: string]: string};
        passwordQuality: string;
        passwordQualityList: {[key: string]: string};
        noAllFieldsEntered: string;
        button: string;
        registerError: {[key: string]: 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(''));
 */
