/*
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.
*/
const plugin = require("tailwindcss/plugin"); // Tokens


const colors = require("./tokens/colors");

const {
  fontFamilies,
  fontSizes,
  lineHeights,
  letterSpacing,
  textOrientations,
  writingModes,
  textShadow
} = require("./tokens/typography");

const spacing = require("./tokens/spacing");

const {
  minWidths,
  maxWidths,
  widths,
  minHeights,
  maxHeights,
  heights,
  aspectRatios,
  iconSizes,
  triangleSizes
} = require("./tokens/sizing");

const {
  durations,
  timingFunctions
} = require("./tokens/transition");

const {
  backgroundSize,
  backgroundImage,
  gradientOpacity,
  gradientStopPosition
} = require("./tokens/background");

const {
  rotate
} = require("./tokens/transform");

const opacity = require("./tokens/opacity");

const boxShadows = require("./tokens/boxShadow");

const {
  borderWidth,
  borderRadius
} = require("./tokens/border"); // Official Tailwind Plugins


const tailwindcssTypographyPlugin = require("@tailwindcss/typography");

const tailwindcssAspectRatioPlugin = require("@tailwindcss/aspect-ratio");

const tailwindcssLineClampPlugin = require("@tailwindcss/line-clamp"); // 3rd party plugins


const tailwindcssDebugScreensPlugin = require("tailwindcss-debug-screens"); //https://github.com/jorenvanhee/tailwindcss-debug-screens
// Plugins


const generalBase = require("./plugins/base/general");

const formsBase = require("./plugins/base/forms");

const typographyBase = require("./plugins/base/typography");

const markdownBase = require("./plugins/base/markdown");

const scrollbarsUtilities = require("./plugins/utilities/scrollbars");

const spacerUtilities = require("./plugins/utilities/spacers");

const iconUtilities = require("./plugins/utilities/icons");

const triangleUtilities = require("./plugins/utilities/triangles");

const maskUtilities = require("./plugins/utilities/mask");

const backgroundUtilities = require("./plugins/utilities/background");

const backgroundImageUtilities = require("./plugins/utilities/backgroundImage");

const gradientUtilities = require("./plugins/utilities/gradient");

const textOrientationUtilities = require("./plugins/utilities/textOrientation");

const textShadowUtilities = require("./plugins/utilities/textShadow");

const buttonComponents = require("./plugins/components/buttons");

const inputComponents = require("./plugins/components/input");

const inputGroupComponents = require("./plugins/components/inputGroup");

const radioButtonComponents = require("./plugins/components/radioButton"); // Variants


const {
  groupDisabledVariants
} = require("./plugins/variants/groupVariants");

const {
  errorVariants,
  groupErrorVariants,
  successVariants,
  groupSuccessVariants
} = require("./plugins/variants/stateVariants");

module.exports = plugin(options => {
  tailwindcssTypographyPlugin(options);
  tailwindcssAspectRatioPlugin.handler(options);
  tailwindcssLineClampPlugin.handler(options);
  generalBase(options);
  formsBase(options);
  typographyBase(options);
  markdownBase(options);
  scrollbarsUtilities(options);
  spacerUtilities(options);
  iconUtilities(options);
  triangleUtilities(options);
  maskUtilities(options);
  backgroundUtilities(options);
  backgroundImageUtilities(options);
  gradientUtilities(options);
  textOrientationUtilities(options);
  textShadowUtilities.handler(options);
  buttonComponents(options);
  inputComponents(options);
  inputGroupComponents(options);
  radioButtonComponents(options);
  groupDisabledVariants.handler(options);
  errorVariants.handler(options);
  groupErrorVariants.handler(options);
  successVariants.handler(options);
  groupSuccessVariants.handler(options);
  tailwindcssDebugScreensPlugin(options);
}, {
  darkMode: "class",
  theme: {
    colors,
    ...spacing,
    borderColor: theme => ({ ...theme("colors"),
      DEFAULT: theme("colors.gray.300", "currentColor")
    }),
    borderWidth,
    borderRadius,
    ringOpacity: opacity,
    boxShadow: boxShadows,
    fontFamily: fontFamilies,
    fontSize: fontSizes,
    letterSpacing,
    textOrientation: textOrientations,
    textShadow,
    writingMode: writingModes,
    iconSize: iconSizes,
    triangleSize: triangleSizes,
    // aspectRatio: aspectRatios,
    extend: {
      screens: {
        sm: "640px",
        md: "768px",
        lg: "1024px",
        xl: "1280px"
      },
      margin: {
        "1/4": "25%",
        "1/2": "50%",
        "3/4": "75%",
        full: "100%"
      },
      padding: {
        "1/4": "25%",
        "1/2": "50%",
        "3/4": "75%",
        full: "100%"
      },
      minHeight: minHeights,
      maxHeight: maxHeights,
      minWidth: minWidths,
      maxWidth: maxWidths,
      height: heights,
      width: widths,
      lineHeight: lineHeights,
      lineClamp: {
        1: "1",
        2: "2",
        3: "3",
        4: "4",
        5: "5",
        6: "6",
        7: "7",
        8: "8",
        9: "9",
        10: "10"
      },
      listStyleType: {
        asterix: '"*"',
        circle: "circle",
        "decimal-leading-zero": "decimal-leading-zero",
        "lower-latin": "lower-latin",
        "lower-roman": "lower-roman",
        "upper-latin": "upper-latin",
        "upper-roman": "upper-roman"
      },
      gridTemplateColumns: {
        16: "repeat(16, minmax(0, 1fr))",
        24: "repeat(24, minmax(0, 1fr))"
      },
      backgroundSize,
      backgroundImage,
      gradientStopPosition,
      gradientOpacity,
      opacity,
      rotate,
      transitionDuration: durations,
      transitionDelay: durations,
      transitionTimingFunction: timingFunctions,
      aspectRatio: {
        1: '1',
        2: '2',
        3: '3',
        4: '4',
        5: '5',
        6: '6',
        7: '7',
        8: '8',
        9: '9',
        10: '10',
        11: '11',
        12: '12',
        13: '13',
        14: '14',
        15: '15',
        16: '16'
      }
    }
  },
  variants: {
    backgroundClip: ["responsive"],
    backgroundColor: ["responsive", "odd", "even", "first", "last", "hover", "focus", "active", "disabled", "focus-within", "group-focus", "group-hover", "group-disabled", "checked"],
    backgroundOpacity: ["responsive", "odd", "even", "first", "last", "hover", "focus", "active", "disabled", "focus-within", "group-focus", "group-hover"],
    backgroundSize: ["responsive", "hover", "focus", "group-hover"],
    backgroundImage: ["responsive", "hover", "focus", "active", "disabled", "focus-within", "group-focus", "group-hover", "checked"],
    gradientColorStops: ["responsive", "hover", "focus", "group-hover"],
    borderColor: ["responsive", "odd", "even", "first", "last", "hover", "focus", "active", "disabled", "focus-within", "group-focus", "group-hover", "group-disabled"],
    borderOpacity: ["responsive", "odd", "even", "first", "last", "hover", "focus", "active", "disabled", "focus-within", "group-focus", "group-hover"],
    triangleSize: ["responsive", "hover"],
    textColor: ["responsive", "odd", "even", "first", "last", "hover", "focus", "active", "disabled", "focus-within", "group-focus", "group-hover", "group-disabled", "visited"],
    textOpacity: ["responsive", "odd", "even", "first", "last", "hover", "focus", "active", "disabled", "focus-within", "group-focus", "group-hover"],
    textShadow: ["responsive", "hover", "focus", "disabled", "focus-within", "group-focus", "group-hover"],
    textOrientation: ["responsive"],
    lineClamp: ["responsive", "hover"],
    opacity: ["responsive", "hover", "focus", "disabled", "focus-within", "group-focus", "group-hover"],
    boxShadow: ["responsive", "hover", "focus", "disabled", "focus-within", "group-focus", "group-hover"],
    mask: ["responsive", "hover"],
    transform: ["responsive"],
    scale: ["responsive", "hover", "focus", "group-hover"],
    rotate: ["responsive", "hover", "focus", "group-hover"],
    translate: ["responsive", "hover", "focus", "group-hover"],
    skew: ["responsive", "hover", "focus", "group-hover"],
    mixBlendMode: ["responsive", "hover", "group-hover"],
    backgroundBlendMode: ["responsive", "hover", "group-hover"],
    isolation: ["responsive", "hover", "group-hover"],
    margin: ["responsive"],
    padding: ["responsive"],
    spacers: ["responsive"],
    position: ["responsive"],
    inset: ["responsive", "hover", "group-hover"],
    width: ["responsive"],
    iconSize: ["responsive"],
    zIndex: ["responsive", "hover", "group-hover"],
    wordBreak: ["responsive", "group-hover"],
    textOverflow: ["responsive", "group-hover"],
    aspectRatio: ["responsive", "hover"]
  },
  corePlugins: {
    gradientColorStops: false,
    backgroundImage: false
  }
});