"use strict";

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

class CssOrderControlPlugin {
  constructor(options) {
    this.options = {
      className: options.className
    };
  }

  apply(compiler) {
    // NOTE: we not using this, Reason currently this option is only need for EFC,
    // So it do not needed.
    const className = this.options.className;
    compiler.hooks.thisCompilation.tap({
      name: 'CssOrderControlPlugin',
      stage: 1,
      fn: compilation => {
        compilation.mainTemplate.hooks.requireEnsure.tap('CssOrderControlPlugin', source => {
          // const str = attributeSetTemplate(cssAttributes, 'linkTag');
          const replacedStr = source.replace('head.appendChild(linkTag);', `var referenceTag = document.getElementById('${className}');
                   head.insertBefore(linkTag, referenceTag);`); //   console.log({ s: source, r: replacedStr });

          return replacedStr;
        });
      }
    });
  }

}

exports.default = CssOrderControlPlugin;