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

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

/*
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 _require = require("../utilities/convertColors"),
    flattenColorPalette = _require.flattenColorPalette,
    removeHash = _require.removeHash;

var opacity = require("./opacity");

var _require2 = require("./transform"),
    rotate = _require2.rotate;

var _require3 = require("./spacing"),
    spacing = _require3.spacing;

var colors = require("./colors");
/*
Gradient Directions:
Converts Rotations into Gradient Dirctions which can then be passed as background images.
*/


function setDirections(targetObj) {
  var newObj = {};
  Object.entries(targetObj).forEach(function (_ref) {
    var _ref2 = _slicedToArray(_ref, 2),
        key = _ref2[0],
        value = _ref2[1];

    var newClass = '';

    if (key < 0) {
      newClass = "-gradient-to".concat(key);
    } else {
      newClass = "gradient-to-".concat(key);
    }

    newObj[newClass] = "linear-gradient(".concat(value, ", var(--tw-gradient-stops))");
  });
  return newObj;
}

var gradientDirection = setDirections(rotate);
/*
Gradient Opacity:
Converts Opacity into Gradient Opacity.
*/

var gradientStopPosition = {
  "0": "0%",
  "5": "5%",
  "10": "10%",
  "15": "15%",
  "20": "20%",
  "25": "25%",
  "30": "30%",
  "35": "35%",
  "40": "40%",
  "45": "45%",
  "50": "50%",
  "55": "55%",
  "60": "60%",
  "65": "65%",
  "70": "70%",
  "75": "75%",
  "80": "80%",
  "85": "85%",
  "90": "90%",
  "95": "95%",
  "100": "100%"
};
/*
Gradient Opacity:
Converts Opacity into Gradient Opacity.
*/

var gradientOpacity = _objectSpread(_objectSpread({
  "0": "0"
}, opacity), {}, {
  "100": "1"
});

var backgroundSize = _objectSpread({
  'auto': 'auto',
  'cover': 'cover',
  'contain': 'contain',
  '25%': '25%',
  '50%': '50%',
  '75%': '75%',
  '100%': '100%',
  '150%': '150%',
  '200%': '200%',
  '300%': '300%',
  '1000%': '1000%'
}, spacing); // Generate background-image classes with colored circle svgs to be used with radio inputs.


var bgColors = flattenColorPalette(colors);
var bgCircle = {};

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

  return bgCircle["circle-".concat(key)] = "url(\"data:image/svg+xml,%3csvg viewBox='0 0 16 16' fill='%23".concat(removeHash(value), "' xmlns='http://www.w3.org/2000/svg'%3e%3ccircle cx='8' cy='8' r='3'/%3e%3c/svg%3e\")");
});

var bgCheck = {};

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

  return bgCheck["check-".concat(key)] = "url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23".concat(removeHash(value), "' d='M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z' /%3E%3C/svg%3E\")");
});
/*
Background Images:
Extends Tailwinds default background images with Q-CTRL spcific patterens and gradients.
*/


var backgroundImage = _objectSpread(_objectSpread(_objectSpread({
  'transparent-image': 'repeating-linear-gradient(45deg, currentColor 25%, transparent 25%, transparent 75%, currentColor 75%, currentColor),repeating-linear-gradient(45deg, currentColor 25%, transparent 25%, transparent 75%, currentColor 75%, currentColor)',
  'stripes': 'linear-gradient(45deg,currentColor 12.5%,transparent 12.5%,transparent 50%,currentColor 50%,currentColor 62.5%,transparent 62.5%,transparent 100%)',
  'gradient': 'linear-gradient(var(--tw-gradient-direction), var(--tw-gradient-stops))'
}, gradientDirection), bgCircle), bgCheck);

module.exports = {
  backgroundSize: backgroundSize,
  backgroundImage: backgroundImage,
  gradientStopPosition: gradientStopPosition,
  gradientOpacity: gradientOpacity
};