"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.isI18nFile = void 0;
exports.nameTemplates = nameTemplates;

var _modeUtils = require("./modeUtils");

// nameTemplate.js
// NOTE: these below code can be done in js,
//   we did copy paste in order to avoid unnecessary confusion
// NOTE: array[0] is dev mode file templates and array[1] is prod mode file templates 
const templates = {
  html: ['index.html', 'index.[contenthash].html'],
  js: ['js/[name].js', 'js/[name].[contenthash].js'],
  chunkjs: ['js-chunks/[name].js', 'js-chunks/[name].[contenthash].js'],
  i18njs: ['i18n-chunks/[locale]/[name].i18n.js', 'i18n-chunks/[locale]/[name].[chunkhash].i18n.js'],
  i18nchunkjs: ['i18n-chunks/[locale]/[name].i18n.js', // 'i18n-chunks/[locale]/[name].[chunkhash].i18n.js'
  'i18n-chunks/[locale]/[name].[contenthash].i18n.js'],
  i18nmanifest: ['i18n-manifest.json', 'i18n-manifest.json'],
  workerjs: ['js/[name].js', 'js/[name].[contenthash].js'],
  css: ['css/[name].css', 'css/[name].[contenthash].css'],

  /**
   * NOTE: when you change (cssdir) this line it  will have affect on Below files will be affected
   *   custom_plugins/RtlSplitPlugin/*
   *   pluginConfigs/configMiniCSSExtractPlugin.js
   *   pluginConfigs/configRtlCssPlugin.js
   *  */
  cssdir: ['css/[name].[dir].css', 'css/[name].[contenthash].[dir].css'],
  image: ['images/[name][ext]', 'images/[name].[contenthash][ext]'],
  font: ['fonts/[name][ext]', 'fonts/[name].[contenthash][ext]'],
  svg: ['fonts/[name][ext]', 'fonts/[name].[contenthash][ext]'],
  audio: ['fonts/[name][ext]', 'fonts/[name].[contenthash][ext]'],
  video: ['videos/[name][ext]', 'videos/[name].[contenthash][ext]']
};

function createNameTemplate(name, useHash) {
  // const ext = `${useHash ? '.[hash:20]' : ''}[ext]`;
  return useHash ? name[1] : name[0];
}

function nameTemplates(type, options) {
  const {
    enableChunkHash,
    mode
  } = options;
  const tname = templates[type];

  if (!tname) {
    throw Error(`specified type not valid Type: ${type}`);
  }

  let useHash = (0, _modeUtils.isProductionMode)(mode) || enableChunkHash;

  if ((0, _modeUtils.isDevelopmentMode)(mode) && type === 'html') {
    useHash = false;
  }

  return createNameTemplate(tname, useHash);
} // export function cssDirNameTemplate(dir, options) {
//   return nameTemplates('cssdir', options).replace(/\[dir\]/g, dir);
// }


const isI18nFile = url => url.endsWith('.i18n.js');

exports.isI18nFile = isI18nFile;