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;
  var colors = flattenColorPalette(theme('colors'));
  var rootStyles = {
    ":root": {
      "--triangle-background-color": theme("colors.white"),
      "--triangle-opacity": "1",
      "--triangle-size": theme('triangleSize.md'),
      "--triangle-size-sm": "calc( var(--triangle-size) * 0.75)",
      "--triangle-size-xs": "calc( var(--triangle-size) * 0.66)"
    },
    ".triangle, [class*='triangle-']": {
      display: "inline-block",
      width: 0,
      height: 0,
      borderStyle: "solid",
      borderWidth: "0 var(--triangle-size-xs) var(--triangle-size-sm) var(--triangle-size-xs)",
      borderColor: "transparent transparent var(--triangle-background-color) transparent"
    }
  };
  var triangleDirectionUtilities = {
    ".triangle-t": {
      borderWidth: "0 var(--triangle-size-xs) var(--triangle-size-sm) var(--triangle-size-xs)",
      borderColor: "transparent transparent var(--triangle-background-color) transparent"
    },
    ".triangle-r": {
      borderWidth: "var(--triangle-size-xs) 0 var(--triangle-size-xs) var(--triangle-size-sm)",
      borderColor: "transparent transparent transparent var(--triangle-background-color)"
    },
    ".triangle-b": {
      borderWidth: "var(--triangle-size-sm) var(--triangle-size-xs) 0 var(--triangle-size-xs)",
      borderColor: "var(--triangle-background-color) transparent transparent transparent"
    },
    ".triangle-l": {
      borderWidth: "var(--triangle-size-xs) var(--triangle-size-sm) var(--triangle-size-xs) 0",
      borderColor: "transparent var(--triangle-background-color) transparent transparent"
    },
    ".triangle-tr": {
      borderWidth: "0 var(--triangle-size) var(--triangle-size) 0",
      borderColor: "transparent var(--triangle-background-color) transparent transparent"
    },
    ".triangle-br": {
      borderWidth: "0 0 var(--triangle-size) var(--triangle-size)",
      borderColor: "transparent transparent var(--triangle-background-color) transparent"
    },
    ".triangle-bl": {
      borderWidth: "var(--triangle-size) 0 0 var(--triangle-size)",
      borderColor: "transparent transparent transparent var(--triangle-background-color)"
    },
    ".triangle-tl": {
      borderWidth: "var(--triangle-size) var(--triangle-size) 0 0",
      borderColor: "var(--triangle-background-color) transparent transparent transparent"
    }
  };

  var triangleSizeUtilities = _.map(theme("triangleSize"), function (val, key) {
    return _defineProperty({}, ".".concat(e("triangle-".concat(key))), {
      "--triangle-size": "".concat(val),
      "--triangle-size-sm": "calc( var(--triangle-size) * 0.75)",
      "--triangle-size-xs": "calc( var(--triangle-size) * 0.66)"
    });
  });

  var triangleColorUtilities = _.map(colors, function (value, key) {
    if (key === 'current' || key === 'transparent') {
      return _defineProperty({}, ".".concat(e("triangle-".concat(key))), {
        '--triangle-background-color': "".concat(value)
      });
    }

    return _defineProperty({}, ".".concat(e("triangle-".concat(key))), {
      '--triangle-background-color': "rgba(".concat(getRGB(value), ", var(--triangle-opacity))")
    });
  });

  var triangleOpacityUtilities = _.map(theme("opacity"), function (value, key) {
    return _defineProperty({}, ".".concat(e("triangle-opacity-".concat(key))), {
      '--triangle-opacity': "".concat(value)
    });
  });

  addBase([rootStyles]);
  addUtilities([triangleDirectionUtilities, triangleSizeUtilities, triangleColorUtilities, triangleOpacityUtilities], variants('triangleSize'));
};