text: "use strict";
  Object.defineProperty(exports, "__esModule", { value: true });
  const fs = require("fs");
  const path = require("path");
  const converter_common_1 = require("./converter.common");
  const resource_android_1 = require("../resource.android");
  class ConverterAndroid extends converter_common_1.ConverterCommon {
      constructor(dataProvider, androidResourcesMigrationService, logger, platformData, projectData) {
          super(dataProvider, logger, platformData, projectData);
          if (androidResourcesMigrationService.hasMigrated(projectData.appResourcesDirectoryPath)) {
              this.appResourcesDirectoryPath = path.join(this.appResourcesDirectoryPath, "src", "main", "res");
          }
      }
      cleanObsoleteResourcesFiles(resourcesDirectory, languages) {
          fs.readdirSync(resourcesDirectory).filter(fileName => {
              const match = /^values-(.+)$/.exec(fileName);
              return match && !languages.has(match[1].replace(/^(.+?)-r(.+?)$/, "$1-$2"));
          }).map(fileName => {
              return path.join(resourcesDirectory, fileName);
          }).filter(filePath => {
              return fs.statSync(filePath).isDirectory();
          }).forEach(lngResourcesDir => {
              const resourceFilePath = path.join(lngResourcesDir, "strings.xml");
              this.removeFileIfExists(resourceFilePath);
              this.removeDirectoryIfEmpty(lngResourcesDir);
          });
          return this;
      }
      createLanguageResourcesFiles(language, isDefaultLanguage, i18nEntries) {
          const languageResourcesDir = path.join(this.appResourcesDirectoryPath, `values${isDefaultLanguage ? "" : `-${language.replace(/^(.+?)-(.+?)$/, "$1-r$2")}`}`);
          this.createDirectoryIfNeeded(languageResourcesDir);
          let strings = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<resources>\n";
          this.encodeI18nEntries(i18nEntries).forEach((encodedValue, encodedKey) => {
              strings += `  <string name="${encodedKey}">${encodedValue}</string>\n`;
          });
          strings += "</resources>\n";
          const resourceFilePath = path.join(languageResourcesDir, "strings.xml");
          this.writeFileSyncIfNeeded(resourceFilePath, strings);
          return this;
      }
      encodeI18nEntries(i18nEntries) {
          const encodedI18nEntries = new Map();
          i18nEntries.forEach((value, key) => {
              const encodedKey = resource_android_1.encodeKey(key);
              const encodedValue = resource_android_1.encodeValue(value);
              encodedI18nEntries.set(encodedKey, encodedValue);
              if (key === "app.name") {
                  encodedI18nEntries.set("app_name", encodedValue);
                  encodedI18nEntries.set("title_activity_kimera", encodedValue);
              }
          });
          return encodedI18nEntries;
      }
  }
  exports.ConverterAndroid = ConverterAndroid;
  