#include "../locale.h"
#include <locale.h>
#include <windows.h>

void print_res_str(HINSTANCE hLib, size_t id) {
  wchar_t buffer[256] = {0};
  if (LoadStringW(hLib, id, buffer, sizeof(buffer) / sizeof(wchar_t)))
    wprintf(L"%ls\n", buffer);
  else
    fprintf(stderr, "Error: Can't load string from dll\n");
}

int main() {
  setlocale(LC_ALL, "ukr");

  printf("Choose language to use\n");
  printf("\t1 - ua\n");
  printf("\t2 - en\n");
  printf("choice: ");

  int lang = getchar() - '0';

  HMODULE hLib = 0;

  if (lang == 1)
    hLib = LoadLibrary("locale-ua.dll");
  else if (lang == 2)
    hLib = LoadLibrary("locale-en.dll");
  else
    fprintf(stderr, "Error: No such language\n");

  if (!hLib) {
    fprintf(stderr, "Error: Can't load dll\n");
    return 1;
  }

  printf("Surname:\t");
  print_res_str(hLib, ID_SURNAME);

  printf("Faculty:\t");
  print_res_str(hLib, ID_FACULTY);

  printf("Group:\t\t");
  print_res_str(hLib, ID_GROUP);

  printf("Discipline:\t");
  print_res_str(hLib, ID_DISCIPLINE);

  FreeLibrary(hLib);
  return 0;
}
