"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.LocaleChunkAssetsStore = void 0;
exports.getLocaleChunkAssetsStore = getLocaleChunkAssetsStore;
exports.setLocaleChunkAssetsStore = setLocaleChunkAssetsStore;

var _ModulesI18nKeysStore = require("./ModulesI18nKeysStore");

class LocaleChunkAssetsStore extends _ModulesI18nKeysStore.ModulesI18nKeysStore {
  constructor() {
    super();
    this.data = {};
  }

  clear() {
    this.data = {};
  }

  storeData(chunkId, locale, data) {
    if (!this.data[chunkId]) {
      this.data[chunkId] = {};
    }

    const chunkBasedData = this.data[chunkId];
    chunkBasedData[locale] = { ...(chunkBasedData[locale] || {}),
      ...data
    };
  }

  getChunkIdsWhichHasI18n() {
    return Object.keys(this.data);
  }

  forEachChunkId(cb) {
    // Object.keys(localeChunkAssestMap).forEach
    this.getChunkIdsWhichHasI18n().forEach(cb);
  }

  isChunkHasI18n(chunkId) {
    if (typeof chunkId === 'object') {
      return super.isChunkHasI18n(chunkId);
    }

    return !!this.data[chunkId];
  }

  getDate(chunkId, locale) {
    return this.data[chunkId]?.[locale];
  }

  getContent(chunkId, locale) {
    return this.data[chunkId]?.[locale]?.content;
  }

  getContentHash(chunkId, locale) {
    return this.data[chunkId]?.[locale]?.contentHash;
  }

}

exports.LocaleChunkAssetsStore = LocaleChunkAssetsStore;
const storeCache = new WeakMap();

function getLocaleChunkAssetsStore(compilation) {
  return storeCache.get(compilation);
}

function setLocaleChunkAssetsStore(compilation, store) {
  return storeCache.set(compilation, store);
}