"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const Enum = require("./Enum.js");
const Utility = require("./Utility.js");
const Tokenizer = require("./Tokenizer.js");
const Serializer = require("./Serializer.js");
const Prefixer = require("./Prefixer.js");
function middleware(collection) {
  var length = Utility.sizeof(collection);
  return function(element, index, children, callback) {
    var output = "";
    for (var i = 0; i < length; i++)
      output += collection[i](element, index, children, callback) || "";
    return output;
  };
}
function rulesheet(callback) {
  return function(element) {
    if (!element.root) {
      if (element = element.return)
        callback(element);
    }
  };
}
function prefixer(element, index, children, callback) {
  if (element.length > -1) {
    if (!element.return)
      switch (element.type) {
        case Enum.DECLARATION:
          element.return = Prefixer.prefix(element.value, element.length);
          break;
        case Enum.KEYFRAMES:
          return Serializer.serialize([Tokenizer.copy(element, { value: Utility.replace(element.value, "@", "@" + Enum.WEBKIT) })], callback);
        case Enum.RULESET:
          if (element.length)
            return Utility.combine(element.props, function(value) {
              switch (Utility.match(value, /(::plac\w+|:read-\w+)/)) {
                case ":read-only":
                case ":read-write":
                  return Serializer.serialize([Tokenizer.copy(element, { props: [Utility.replace(value, /:(read-\w+)/, ":" + Enum.MOZ + "$1")] })], callback);
                case "::placeholder":
                  return Serializer.serialize([
                    Tokenizer.copy(element, { props: [Utility.replace(value, /:(plac\w+)/, ":" + Enum.WEBKIT + "input-$1")] }),
                    Tokenizer.copy(element, { props: [Utility.replace(value, /:(plac\w+)/, ":" + Enum.MOZ + "$1")] }),
                    Tokenizer.copy(element, { props: [Utility.replace(value, /:(plac\w+)/, Enum.MS + "input-$1")] })
                  ], callback);
              }
              return "";
            });
      }
  }
}
exports.middleware = middleware;
exports.prefixer = prefixer;
exports.rulesheet = rulesheet;
//# sourceMappingURL=Middleware.js.map
