"use strict";

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

var _path = _interopRequireDefault(require("path"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

/* eslint-disable class-methods-use-this */
const i18nDependencyCache = new WeakMap();
exports.i18nDependencyCache = i18nDependencyCache;

function getI18nDependency(webpack) {
  if (i18nDependencyCache.has(webpack)) {
    return i18nDependencyCache.get(webpack);
  }

  class I18nDependency extends webpack.Dependency {
    constructor({
      identifier,
      content
    }, context, identifierIndex) {
      super();
      this.identifier = identifier;
      this.identifierIndex = identifierIndex;
      this.content = content; // ## this.layer = layer;
      // ## this.supports = supports;
      // ## this.media = media;
      // ## this.sourceMap = sourceMap;

      this.context = context;
      this.assets = undefined;
      this.assetsInfo = undefined;
    }

    getResourceIdentifier() {
      return `i18n-module-${this.identifier}-${this.identifierIndex}`;
    }

    getModuleEvaluationSideEffectsState() {
      return webpack.ModuleGraphConnection.TRANSITIVE_ONLY;
    }

    serialize(context) {
      const {
        write
      } = context;
      write(this.identifier);
      write(this.content); // ## write(this.layer);
      // ## write(this.supports);
      // ## write(this.media);
      // ## write(this.sourceMap);

      write(this.context);
      write(this.identifierIndex);
      write(this.assets);
      write(this.assetsInfo);
      super.serialize(context);
    }

    deserialize(context) {
      super.deserialize(context);
    }

  }

  i18nDependencyCache.set(webpack, I18nDependency);
  webpack.util.serialization.register(I18nDependency, _path.default.resolve(__dirname, 'I18nDependency-new'), null, {
    serialize(instance, context) {
      instance.serialize(context);
    },

    deserialize(context) {
      const {
        read
      } = context;
      const dep = new I18nDependency({
        identifier: read(),
        content: read() // ## layer: read(),
        // ## supports: read(),
        // ## media: read(),
        // ## sourceMap: read()

      }, read(), read());
      const assets = read();
      const assetsInfo = read();
      dep.assets = assets;
      dep.assetsInfo = assetsInfo;
      dep.deserialize(context);
      return dep;
    }

  });
  return I18nDependency;
}