"use strict";

function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }

function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }

function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }

function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }

function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }

function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

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

function cleanRem(rem) {
  return parseFloat(rem.replace("rem", ""));
}

function createRem(rem) {
  return "".concat(rem, "rem");
} // Components


module.exports = function (_ref) {
  var addComponents = _ref.addComponents,
      theme = _ref.theme;
  var colors = flattenColorPalette(theme("colors"));
  var colorDanger = colors.danger;
  var inputGroup = {
    ".input-group": {
      position: "relative",
      display: "flex",
      "&.icon-left, &.icon-right": {
        svg: {
          position: "absolute",
          top: "50%",
          transform: "translateY(-50%)"
        }
      },
      "&.input-group-danger": {
        input: {
          borderColor: colorDanger
        },
        svg: {
          color: colorDanger
        }
      },
      "&.input-group-disabled": {
        input: {
          backgroundColor: theme("colors.gray.0"),
          borderColor: theme("colors.gray.DEFAULT"),
          color: theme("colors.gray.300")
        },
        svg: {
          color: theme("colors.gray.300")
        }
      }
    }
  };
  var paddingXs = theme("borderSquash.xs");

  var _paddingXs$split = paddingXs.split(" "),
      _paddingXs$split2 = _slicedToArray(_paddingXs$split, 2),
      _paddingXsY = _paddingXs$split2[0],
      paddingXsX = _paddingXs$split2[1];

  var paddingSm = theme("borderSquash.sm");

  var _paddingSm$split = paddingSm.split(" "),
      _paddingSm$split2 = _slicedToArray(_paddingSm$split, 2),
      _paddingSmY = _paddingSm$split2[0],
      paddingSmX = _paddingSm$split2[1];

  var paddingMd = theme("borderSquash.md");

  var _paddingMd$split = paddingMd.split(" "),
      _paddingMd$split2 = _slicedToArray(_paddingMd$split, 2),
      _paddingMdY = _paddingMd$split2[0],
      paddingMdX = _paddingMd$split2[1];

  var paddingLg = theme("borderSquash.lg");

  var _paddingLg$split = paddingLg.split(" "),
      _paddingLg$split2 = _slicedToArray(_paddingLg$split, 2),
      _paddingLgY = _paddingLg$split2[0],
      paddingLgX = _paddingLg$split2[1];

  var paddingXl = theme("borderSquash.xl");

  var _paddingXl$split = paddingXl.split(" "),
      _paddingXl$split2 = _slicedToArray(_paddingXl$split, 2),
      _paddingXlY = _paddingXl$split2[0],
      paddingXlX = _paddingXl$split2[1];

  var inputGroupSizes = {
    ".input-group-xs": {
      input: {
        padding: paddingXs,
        fontSize: theme("fontSize.2xs"),
        lineHeight: theme("lineHeight.4"),
        borderRadius: theme("borderRadius.xs"),
        "&::placeholder": {
          lineHeight: theme("lineHeight.4"),
          fontSize: theme("fontSize.2xs")
        }
      },
      "&.icon-left": {
        input: {
          paddingLeft: createRem(cleanRem(paddingXsX) + cleanRem(theme("iconSize.2xs")) + cleanRem(theme("inline.sm")))
        },
        "svg:first-of-type": {
          left: paddingXsX
        }
      },
      "&.icon-right": {
        input: {
          paddingRight: createRem(cleanRem(paddingXsX) + cleanRem(theme("iconSize.2xs")) + cleanRem(theme("inline.sm")))
        },
        "svg:last-of-type": {
          right: paddingXsX
        }
      },
      svg: {
        width: theme("iconSize.2xs"),
        height: theme("iconSize.2xs")
      }
    },
    ".input-group-sm": {
      input: {
        padding: paddingSm,
        fontSize: theme("fontSize.xs"),
        lineHeight: theme("lineHeight.5"),
        borderRadius: theme("borderRadius.xs"),
        "&::placeholder": {
          fontSize: theme("fontSize.xs"),
          lineHeight: theme("lineHeight.5")
        }
      },
      "&.icon-left": {
        input: {
          paddingLeft: createRem(cleanRem(paddingSmX) + cleanRem(theme("iconSize.sm")) + cleanRem(theme("inline.sm")))
        },
        "svg:first-of-type": {
          left: paddingSmX
        }
      },
      "&.icon-right": {
        input: {
          paddingRight: createRem(cleanRem(paddingSmX) + cleanRem(theme("iconSize.sm")) + cleanRem(theme("inline.sm")))
        },
        "svg:last-of-type": {
          right: paddingSmX
        }
      },
      svg: {
        width: theme("iconSize.sm"),
        height: theme("iconSize.sm")
      }
    },
    ".input-group-md": {
      input: {
        padding: paddingMd,
        fontSize: theme("fontSize.base"),
        lineHeight: theme("lineHeight.6"),
        borderRadius: theme("borderRadius.sm"),
        "&::placeholder": {
          fontSize: theme("fontSize.base"),
          lineHeight: theme("lineHeight.6")
        }
      },
      "&.icon-left": {
        input: {
          paddingLeft: createRem(cleanRem(paddingMdX) + cleanRem(theme("iconSize.md")) + cleanRem(theme("inline.sm")))
        },
        "svg:first-of-type": {
          left: paddingMdX
        }
      },
      "&.icon-right": {
        input: {
          paddingRight: createRem(cleanRem(paddingMdX) + cleanRem(theme("iconSize.md")) + cleanRem(theme("inline.sm")))
        },
        "svg:last-of-type": {
          right: paddingMdX
        }
      },
      svg: {
        width: theme("iconSize.md"),
        height: theme("iconSize.md")
      }
    },
    ".input-group-lg": {
      input: {
        padding: paddingLg,
        fontSize: theme("fontSize.base"),
        lineHeight: theme("lineHeight.6"),
        borderRadius: theme("borderRadius.DEFAULT"),
        "&::placeholder": {
          fontSize: theme("fontSize.base"),
          lineHeight: theme("lineHeight.6")
        }
      },
      "&.icon-left": {
        input: {
          paddingLeft: createRem(cleanRem(paddingLgX) + cleanRem(theme("iconSize.md")) + cleanRem(theme("inline.md")))
        },
        "svg:first-of-type": {
          left: paddingLgX
        }
      },
      "&.icon-right": {
        input: {
          paddingRight: createRem(cleanRem(paddingLgX) + cleanRem(theme("iconSize.md")) + cleanRem(theme("inline.md")))
        },
        "svg:last-of-type": {
          right: paddingLgX
        }
      },
      svg: {
        width: theme("iconSize.md"),
        height: theme("iconSize.md")
      }
    },
    ".input-group-xl": {
      input: {
        padding: paddingXl,
        fontSize: theme("fontSize.lg"),
        lineHeight: theme("lineHeight.8"),
        borderRadius: theme("borderRadius.md"),
        "&::placeholder": {
          fontSize: theme("fontSize.lg"),
          lineHeight: theme("lineHeight.8")
        }
      },
      "&.icon-left": {
        input: {
          paddingLeft: createRem(cleanRem(paddingXlX) + cleanRem(theme("iconSize.lg")) + cleanRem(theme("inline.md")))
        },
        "svg:first-of-type": {
          left: paddingXlX
        }
      },
      "&.icon-right": {
        input: {
          paddingRight: createRem(cleanRem(paddingXlX) + cleanRem(theme("iconSize.lg")) + cleanRem(theme("inline.md")))
        },
        "svg:last-of-type": {
          right: paddingXlX
        }
      },
      svg: {
        width: theme("iconSize.lg"),
        height: theme("iconSize.lg")
      }
    }
  };
  addComponents([inputGroup, inputGroupSizes], {
    variants: ["responsive"]
  });
};