"use strict";

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

var _fs = require("fs");

var _postcssRtl = _interopRequireDefault(require("postcss-rtl"));

var _SelectorReplace = _interopRequireDefault(require("./custom_postcss_plugins/SelectorReplace"));

var _ValueReplacer = _interopRequireDefault(require("./custom_postcss_plugins/ValueReplacer"));

var _HoverActivePlugin = _interopRequireDefault(require("./custom_postcss_plugins/HoverActivePlugin"));

var _VariableModificationPlugin = _interopRequireDefault(require("./custom_postcss_plugins/VariableModificationPlugin"));

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

/* eslint-disable no-use-before-define */
function getSpecificPostCssPlugin(pluginOption) {
  return postcssPluginMapper[pluginOption.pluginName]?.(pluginOption);
} // eslint-disable-next-line no-unused-vars


function configPostCssRtl(pluginOption) {
  return (0, _postcssRtl.default)({
    addPrefixToSelector: function addPrefixToSelector(selector, prefix) {
      if (prefix === '[dir]') {
        return selector;
      }

      return `${prefix} ${selector}`; // Make selectors like [dir=rtl] > .selector
    }
  });
} // NOTE: we have keeping array because we need to maintain order (Just In Cases For Future)


const supportedPluginsOptionNames = ['rtl', 'valueReplacer', 'selectorReplace', 'hoverActive', 'cssVariableReplacement'];
exports.supportedPluginsOptionNames = supportedPluginsOptionNames;
const postcssPluginMapper = {
  rtl: configPostCssRtl,
  selectorReplace: pluginOption => (0, _SelectorReplace.default)(pluginOption),
  valueReplacer: pluginOption => (0, _ValueReplacer.default)(pluginOption.config),
  hoverActive: pluginOption => (0, _HoverActivePlugin.default)(pluginOption),
  cssVariableReplacement: configCssVariableReplacement
};

function configCssVariableReplacement(pluginOption) {
  const {
    configFile
  } = pluginOption;
  return configFile && (0, _fs.existsSync)(configFile) && (0, _VariableModificationPlugin.default)(pluginOption);
}