"use strict";

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

var _postcss = _interopRequireDefault(require("postcss"));

var corePlugins = _interopRequireWildcard(require("../plugins"));

var _buildMediaQuery = _interopRequireDefault(require("../util/buildMediaQuery"));

var _prefixSelector = _interopRequireDefault(require("../util/prefixSelector"));

var _pluginUtils = require("../util/pluginUtils");

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

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

var _default = {
  pseudoClassVariants: function ({
    config,
    addVariant
  }) {
    let pseudoVariants = [['first', 'first-child'], ['last', 'last-child'], ['odd', 'nth-child(odd)'], ['even', 'nth-child(even)'], 'visited', 'checked', 'focus-within', 'hover', 'focus', 'focus-visible', 'active', 'disabled'];

    for (let variant of pseudoVariants) {
      let [variantName, state] = Array.isArray(variant) ? variant : [variant, variant];
      addVariant(variantName, (0, _pluginUtils.transformAllClasses)((className, {
        withPseudo
      }) => {
        return withPseudo(`${variantName}${config('separator')}${className}`, state);
      }));
    }

    for (let variant of pseudoVariants) {
      let [variantName, state] = Array.isArray(variant) ? variant : [variant, variant];
      let groupVariantName = `group-${variantName}`;
      addVariant(groupVariantName, (0, _pluginUtils.transformAllSelectors)(selector => {
        let variantSelector = (0, _pluginUtils.updateAllClasses)(selector, className => {
          return `${groupVariantName}${config('separator')}${className}`;
        });

        if (variantSelector === selector) {
          return null;
        }

        let groupSelector = (0, _prefixSelector.default)(config('prefix'), `.group${config('separator')}${state}`);
        return `${groupSelector} ${variantSelector}`;
      }));
    }
  },
  directionVariants: function ({
    config,
    addVariant
  }) {
    addVariant('ltr', (0, _pluginUtils.transformAllSelectors)(selector => `[dir="ltr"] ${(0, _pluginUtils.updateAllClasses)(selector, className => `ltr${config('separator')}${className}`)}`));
    addVariant('rtl', (0, _pluginUtils.transformAllSelectors)(selector => `[dir="rtl"] ${(0, _pluginUtils.updateAllClasses)(selector, className => `rtl${config('separator')}${className}`)}`));
  },
  reducedMotionVariants: function ({
    config,
    addVariant
  }) {
    addVariant('motion-safe', (0, _pluginUtils.transformLastClasses)(className => {
      return `motion-safe${config('separator')}${className}`;
    }, () => _postcss.default.atRule({
      name: 'media',
      params: '(prefers-reduced-motion: no-preference)'
    })));
    addVariant('motion-reduce', (0, _pluginUtils.transformLastClasses)(className => {
      return `motion-reduce${config('separator')}${className}`;
    }, () => _postcss.default.atRule({
      name: 'media',
      params: '(prefers-reduced-motion: reduce)'
    })));
  },
  darkVariants: function ({
    config,
    addVariant
  }) {
    if (config('darkMode') === 'class') {
      addVariant('dark', (0, _pluginUtils.transformAllSelectors)(selector => {
        let variantSelector = (0, _pluginUtils.updateLastClasses)(selector, className => {
          return `dark${config('separator')}${className}`;
        });

        if (variantSelector === selector) {
          return null;
        }

        let darkSelector = (0, _prefixSelector.default)(config('prefix'), `.dark`);
        return `${darkSelector} ${variantSelector}`;
      }));
    } else if (config('darkMode') === 'media') {
      addVariant('dark', (0, _pluginUtils.transformLastClasses)(className => {
        return `dark${config('separator')}${className}`;
      }, () => _postcss.default.atRule({
        name: 'media',
        params: '(prefers-color-scheme: dark)'
      })));
    }
  },
  screenVariants: function ({
    config,
    theme,
    addVariant
  }) {
    for (let screen in theme('screens')) {
      let size = theme('screens')[screen];
      let query = (0, _buildMediaQuery.default)(size);
      addVariant(screen, (0, _pluginUtils.transformLastClasses)(className => {
        return `${screen}${config('separator')}${className}`;
      }, () => _postcss.default.atRule({
        name: 'media',
        params: query
      })));
    }
  },
  ...Object.fromEntries(Object.entries(corePlugins).map(([pluginName, plugin]) => {
    return [pluginName, plugin()];
  }))
};
exports.default = _default;