import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";

/*
Copyright 2021 Q-CTRL. All rights reserved.

Licensed under the Q-CTRL Terms of service (the "License"). Unauthorized
copying or use of this file, via any medium, is strictly prohibited.
Proprietary and confidential. You may not use this file except in compliance
with the License. You may obtain a copy of the License at

     https://q-ctrl.com/terms

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS. See the
License for the specific language.
*/
var _ = require("lodash");

var plugin = require("tailwindcss/plugin");

var _require = require("../../utilities/convertColors"),
    flattenColorPalette = _require.flattenColorPalette,
    getRGB = _require.getRGB; // Text orientation & writing mode


module.exports = function (_ref) {
  var addBase = _ref.addBase,
      addUtilities = _ref.addUtilities,
      theme = _ref.theme,
      e = _ref.e,
      variants = _ref.variants,
      target = _ref.target;
  var colors = flattenColorPalette(theme('colors')); //   gradient stop colors

  var fromStartColor = getRGB(colors.secondary);
  var viaStartColor = getRGB(colors.magenta);
  var toStartColor = getRGB(colors.primary); // Set CSS Varaiables

  var rootStyles = {
    ":root": {
      "--tw-gradient-direction": "0deg",
      "--tw-gradient-from-stop": "0%",
      "--tw-gradient-via-stop": "50%",
      "--tw-gradient-to-stop": "100%",
      "--tw-gradient-from-opacity": "1",
      "--tw-gradient-via-opacity": "1",
      "--tw-gradient-to-opacity": "1",
      "--tw-gradient-from": "rgba(".concat(fromStartColor, ", var(--tw-gradient-from-opacity))"),
      "--tw-gradient-via": "rgba(".concat(viaStartColor, ", var(--tw-gradient-via-opacity))"),
      "--tw-gradient-to": "rgba(".concat(toStartColor, ", var(--tw-gradient-to-opacity))"),
      "--tw-gradient-stops": "var(--tw-gradient-from) var(--tw-gradient-from-stop), var(--tw-gradient-to, rgba(".concat(fromStartColor, ", 0)) var(--tw-gradient-to-stop)")
    }
  }; // Gradient stop positions
  // Uses same values as opacity but as percentage not decimal.

  var fromStop = _.map(theme("gradientStopPosition"), function (value, key) {
    return _defineProperty({}, ".".concat(e("from-stop-".concat(key))), {
      "--tw-gradient-from-stop": "".concat(value)
    });
  });

  var viaStop = _.map(theme("gradientStopPosition"), function (value, key) {
    return _defineProperty({}, ".".concat(e("via-stop-".concat(key))), {
      "--tw-gradient-via-stop": "".concat(value)
    });
  });

  var toStop = _.map(theme("gradientStopPosition"), function (value, key) {
    return _defineProperty({}, ".".concat(e("to-stop-".concat(key))), {
      "--tw-gradient-to-stop": "".concat(value)
    });
  }); // Opacity


  var fromOpacity = _.map(theme("gradientOpacity"), function (value, key) {
    return _defineProperty({}, ".".concat(e("from-opacity-".concat(key))), {
      "--tw-gradient-from-opacity": "".concat(value)
    });
  });

  var viaOpacity = _.map(theme("gradientOpacity"), function (value, key) {
    return _defineProperty({}, ".".concat(e("via-opacity-".concat(key))), {
      "--tw-gradient-via-opacity": "".concat(value)
    });
  });

  var toOpacity = _.map(theme("gradientOpacity"), function (value, key) {
    return _defineProperty({}, ".".concat(e("to-opacity-".concat(key))), {
      "--tw-gradient-to-opacity": "".concat(value)
    });
  }); // Colors
  // Fine control over the stop color and it's opacity


  var fromColor = _.map(colors, function (value, key) {
    if (value == 'currentColor') {
      return null;
    }

    var color = getRGB(value);
    return _defineProperty({}, ".".concat(e("from-".concat(key))), {
      "--tw-gradient-from": "rgba(".concat(color, ", var(--tw-gradient-from-opacity))"),
      "--tw-gradient-stops": "var(--tw-gradient-from) var(--tw-gradient-from-stop), var(--tw-gradient-to, rgba(".concat(color, ", 0)) var(--tw-gradient-to-stop)")
    });
  });

  var viaColor = _.map(colors, function (value, key) {
    if (value == 'currentColor') {
      return null;
    }

    var color = getRGB(value);
    return _defineProperty({}, ".".concat(e("via-".concat(key))), {
      "--tw-gradient-via": "rgba(".concat(color, ", var(--tw-gradient-via-opacity))"),
      "--tw-gradient-stops": "var(--tw-gradient-from) var(--tw-gradient-from-stop), var(--tw-gradient-via) var(--tw-gradient-via-stop), var(--tw-gradient-to, rgba(".concat(color, ", 0)) var(--tw-gradient-to-stop)")
    });
  });

  var toColor = _.map(colors, function (value, key) {
    if (value == 'currentColor') {
      return null;
    }

    var color = getRGB(value);
    return _defineProperty({}, ".".concat(e("to-".concat(key))), {
      "--tw-gradient-to": "rgba(".concat(color, ", var(--tw-gradient-to-opacity))")
    });
  });

  addBase([rootStyles]);
  addUtilities([fromStop, viaStop, toStop, fromOpacity, viaOpacity, toOpacity, fromColor, viaColor, toColor], variants("gradientColorStops"));
};