"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.REGEXP_CONTENTHASH = void 0;
exports.getShortI18nAssets = getShortI18nAssets;
exports.hasContentHash = hasContentHash;

var _urlConcat = require("../../../utils/urlConcat");

// export const REGEXP_CHUNKHASH = /\[chunkhash(?::(\d+))?\]/gi;
// export const REGEXP_HASH = /\[hash(?::(\d+))?\]/gi;
// export const REGEXP_NAME = /\[name\]/gi;
// export const REGEXP_PLACEHOLDERS = /\[(name|id|chunkhash)\]/gi;
// TODO: want to choose file type for i18n load
const REGEXP_CONTENTHASH = /\[contenthash(?::(\d+))?\]/gi;
exports.REGEXP_CONTENTHASH = REGEXP_CONTENTHASH;

function hasContentHash(filenameTemplate) {
  return REGEXP_CONTENTHASH.test(filenameTemplate);
}

function getShortI18nAssets(chunks, i18nManifest, publicPathPrefix) {
  const i18nAssets = {};
  chunks.forEach(chunk => {
    const i18nFiles = i18nManifest[chunk.id];

    if (i18nFiles) {
      Object.keys(i18nFiles).forEach(locale => {
        if (!i18nAssets[locale]) {
          i18nAssets[locale] = [];
        }

        i18nAssets[locale].push((0, _urlConcat.urlConcat)(publicPathPrefix, i18nFiles[locale]));
      });
    }
  });
  return i18nAssets;
}