'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var React = require('react');
var theme = require('@helpdice/theme');
var icons = require('@helpdice/icons');

function _arrayLikeToArray(r, a) {
  (null == a || a > r.length) && (a = r.length);
  for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
  return n;
}
function _arrayWithHoles(r) {
  if (Array.isArray(r)) return r;
}
function _createForOfIteratorHelper(r, e) {
  var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
  if (!t) {
    if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e) {
      t && (r = t);
      var n = 0,
        F = function () {};
      return {
        s: F,
        n: function () {
          return n >= r.length ? {
            done: true
          } : {
            done: false,
            value: r[n++]
          };
        },
        e: function (r) {
          throw r;
        },
        f: F
      };
    }
    throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  }
  var o,
    a = true,
    u = false;
  return {
    s: function () {
      t = t.call(r);
    },
    n: function () {
      var r = t.next();
      return a = r.done, r;
    },
    e: function (r) {
      u = true, o = r;
    },
    f: function () {
      try {
        a || null == t.return || t.return();
      } finally {
        if (u) throw o;
      }
    }
  };
}
function _defineProperty(e, r, t) {
  return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
    value: t,
    enumerable: true,
    configurable: true,
    writable: true
  }) : e[r] = t, e;
}
function _extends() {
  return _extends = Object.assign ? Object.assign.bind() : function (n) {
    for (var e = 1; e < arguments.length; e++) {
      var t = arguments[e];
      for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
    }
    return n;
  }, _extends.apply(null, arguments);
}
function _iterableToArrayLimit(r, l) {
  var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
  if (null != t) {
    var e,
      n,
      i,
      u,
      a = [],
      f = true,
      o = false;
    try {
      if (i = (t = t.call(r)).next, 0 === l) {
        if (Object(t) !== t) return;
        f = !1;
      } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
    } catch (r) {
      o = true, n = r;
    } finally {
      try {
        if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
      } finally {
        if (o) throw n;
      }
    }
    return a;
  }
}
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 ownKeys(e, r) {
  var t = Object.keys(e);
  if (Object.getOwnPropertySymbols) {
    var o = Object.getOwnPropertySymbols(e);
    r && (o = o.filter(function (r) {
      return Object.getOwnPropertyDescriptor(e, r).enumerable;
    })), t.push.apply(t, o);
  }
  return t;
}
function _objectSpread2(e) {
  for (var r = 1; r < arguments.length; r++) {
    var t = null != arguments[r] ? arguments[r] : {};
    r % 2 ? ownKeys(Object(t), true).forEach(function (r) {
      _defineProperty(e, r, t[r]);
    }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
      Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
    });
  }
  return e;
}
function _objectWithoutProperties(e, t) {
  if (null == e) return {};
  var o,
    r,
    i = _objectWithoutPropertiesLoose(e, t);
  if (Object.getOwnPropertySymbols) {
    var n = Object.getOwnPropertySymbols(e);
    for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
  }
  return i;
}
function _objectWithoutPropertiesLoose(r, e) {
  if (null == r) return {};
  var t = {};
  for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
    if (-1 !== e.indexOf(n)) continue;
    t[n] = r[n];
  }
  return t;
}
function _slicedToArray(r, e) {
  return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
}
function _toPrimitive(t, r) {
  if ("object" != typeof t || !t) return t;
  var e = t[Symbol.toPrimitive];
  if (void 0 !== e) {
    var i = e.call(t, r);
    if ("object" != typeof i) return i;
    throw new TypeError("@@toPrimitive must return a primitive value.");
  }
  return ("string" === r ? String : Number)(t);
}
function _toPropertyKey(t) {
  var i = _toPrimitive(t, "string");
  return "symbol" == typeof i ? i : i + "";
}
function _unsupportedIterableToArray(r, a) {
  if (r) {
    if ("string" == typeof r) return _arrayLikeToArray(r, a);
    var t = {}.toString.call(r).slice(8, -1);
    return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
  }
}

function getDefaultExportFromCjs (x) {
	return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
}

var index = {};

var hasRequiredIndex;

function requireIndex () {
	if (hasRequiredIndex) return index;
	hasRequiredIndex = 1;
	var React$1 = React;

	function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

	var React__default = /*#__PURE__*/_interopDefaultLegacy(React$1);

	/*
	Based on Glamor's sheet
	https://github.com/threepointone/glamor/blob/667b480d31b3721a905021b26e1290ce92ca2879/src/sheet.js
	*/ function _defineProperties(target, props) {
	    for(var i = 0; i < props.length; i++){
	        var descriptor = props[i];
	        descriptor.enumerable = descriptor.enumerable || false;
	        descriptor.configurable = true;
	        if ("value" in descriptor) descriptor.writable = true;
	        Object.defineProperty(target, descriptor.key, descriptor);
	    }
	}
	function _createClass(Constructor, protoProps, staticProps) {
	    if (protoProps) _defineProperties(Constructor.prototype, protoProps);
	    return Constructor;
	}
	var isProd = typeof process !== "undefined" && process.env && process.env.NODE_ENV === "production";
	var isString = function(o) {
	    return Object.prototype.toString.call(o) === "[object String]";
	};
	var StyleSheet = /*#__PURE__*/ function() {
	    function StyleSheet(param) {
	        var ref = param === void 0 ? {} : param, _name = ref.name, name = _name === void 0 ? "stylesheet" : _name, _optimizeForSpeed = ref.optimizeForSpeed, optimizeForSpeed = _optimizeForSpeed === void 0 ? isProd : _optimizeForSpeed;
	        invariant$1(isString(name), "`name` must be a string");
	        this._name = name;
	        this._deletedRulePlaceholder = "#" + name + "-deleted-rule____{}";
	        invariant$1(typeof optimizeForSpeed === "boolean", "`optimizeForSpeed` must be a boolean");
	        this._optimizeForSpeed = optimizeForSpeed;
	        this._serverSheet = undefined;
	        this._tags = [];
	        this._injected = false;
	        this._rulesCount = 0;
	        var node = typeof window !== "undefined" && document.querySelector('meta[property="csp-nonce"]');
	        this._nonce = node ? node.getAttribute("content") : null;
	    }
	    var _proto = StyleSheet.prototype;
	    _proto.setOptimizeForSpeed = function setOptimizeForSpeed(bool) {
	        invariant$1(typeof bool === "boolean", "`setOptimizeForSpeed` accepts a boolean");
	        invariant$1(this._rulesCount === 0, "optimizeForSpeed cannot be when rules have already been inserted");
	        this.flush();
	        this._optimizeForSpeed = bool;
	        this.inject();
	    };
	    _proto.isOptimizeForSpeed = function isOptimizeForSpeed() {
	        return this._optimizeForSpeed;
	    };
	    _proto.inject = function inject() {
	        var _this = this;
	        invariant$1(!this._injected, "sheet already injected");
	        this._injected = true;
	        if (typeof window !== "undefined" && this._optimizeForSpeed) {
	            this._tags[0] = this.makeStyleTag(this._name);
	            this._optimizeForSpeed = "insertRule" in this.getSheet();
	            if (!this._optimizeForSpeed) {
	                if (!isProd) {
	                    console.warn("StyleSheet: optimizeForSpeed mode not supported falling back to standard mode.");
	                }
	                this.flush();
	                this._injected = true;
	            }
	            return;
	        }
	        this._serverSheet = {
	            cssRules: [],
	            insertRule: function(rule, index) {
	                if (typeof index === "number") {
	                    _this._serverSheet.cssRules[index] = {
	                        cssText: rule
	                    };
	                } else {
	                    _this._serverSheet.cssRules.push({
	                        cssText: rule
	                    });
	                }
	                return index;
	            },
	            deleteRule: function(index) {
	                _this._serverSheet.cssRules[index] = null;
	            }
	        };
	    };
	    _proto.getSheetForTag = function getSheetForTag(tag) {
	        if (tag.sheet) {
	            return tag.sheet;
	        }
	        // this weirdness brought to you by firefox
	        for(var i = 0; i < document.styleSheets.length; i++){
	            if (document.styleSheets[i].ownerNode === tag) {
	                return document.styleSheets[i];
	            }
	        }
	    };
	    _proto.getSheet = function getSheet() {
	        return this.getSheetForTag(this._tags[this._tags.length - 1]);
	    };
	    _proto.insertRule = function insertRule(rule, index) {
	        invariant$1(isString(rule), "`insertRule` accepts only strings");
	        if (typeof window === "undefined") {
	            if (typeof index !== "number") {
	                index = this._serverSheet.cssRules.length;
	            }
	            this._serverSheet.insertRule(rule, index);
	            return this._rulesCount++;
	        }
	        if (this._optimizeForSpeed) {
	            var sheet = this.getSheet();
	            if (typeof index !== "number") {
	                index = sheet.cssRules.length;
	            }
	            // this weirdness for perf, and chrome's weird bug
	            // https://stackoverflow.com/questions/20007992/chrome-suddenly-stopped-accepting-insertrule
	            try {
	                sheet.insertRule(rule, index);
	            } catch (error) {
	                if (!isProd) {
	                    console.warn("StyleSheet: illegal rule: \n\n" + rule + "\n\nSee https://stackoverflow.com/q/20007992 for more info");
	                }
	                return -1;
	            }
	        } else {
	            var insertionPoint = this._tags[index];
	            this._tags.push(this.makeStyleTag(this._name, rule, insertionPoint));
	        }
	        return this._rulesCount++;
	    };
	    _proto.replaceRule = function replaceRule(index, rule) {
	        if (this._optimizeForSpeed || typeof window === "undefined") {
	            var sheet = typeof window !== "undefined" ? this.getSheet() : this._serverSheet;
	            if (!rule.trim()) {
	                rule = this._deletedRulePlaceholder;
	            }
	            if (!sheet.cssRules[index]) {
	                // @TBD Should we throw an error?
	                return index;
	            }
	            sheet.deleteRule(index);
	            try {
	                sheet.insertRule(rule, index);
	            } catch (error) {
	                if (!isProd) {
	                    console.warn("StyleSheet: illegal rule: \n\n" + rule + "\n\nSee https://stackoverflow.com/q/20007992 for more info");
	                }
	                // In order to preserve the indices we insert a deleteRulePlaceholder
	                sheet.insertRule(this._deletedRulePlaceholder, index);
	            }
	        } else {
	            var tag = this._tags[index];
	            invariant$1(tag, "old rule at index `" + index + "` not found");
	            tag.textContent = rule;
	        }
	        return index;
	    };
	    _proto.deleteRule = function deleteRule(index) {
	        if (typeof window === "undefined") {
	            this._serverSheet.deleteRule(index);
	            return;
	        }
	        if (this._optimizeForSpeed) {
	            this.replaceRule(index, "");
	        } else {
	            var tag = this._tags[index];
	            invariant$1(tag, "rule at index `" + index + "` not found");
	            tag.parentNode.removeChild(tag);
	            this._tags[index] = null;
	        }
	    };
	    _proto.flush = function flush() {
	        this._injected = false;
	        this._rulesCount = 0;
	        if (typeof window !== "undefined") {
	            this._tags.forEach(function(tag) {
	                return tag && tag.parentNode.removeChild(tag);
	            });
	            this._tags = [];
	        } else {
	            // simpler on server
	            this._serverSheet.cssRules = [];
	        }
	    };
	    _proto.cssRules = function cssRules() {
	        var _this = this;
	        if (typeof window === "undefined") {
	            return this._serverSheet.cssRules;
	        }
	        return this._tags.reduce(function(rules, tag) {
	            if (tag) {
	                rules = rules.concat(Array.prototype.map.call(_this.getSheetForTag(tag).cssRules, function(rule) {
	                    return rule.cssText === _this._deletedRulePlaceholder ? null : rule;
	                }));
	            } else {
	                rules.push(null);
	            }
	            return rules;
	        }, []);
	    };
	    _proto.makeStyleTag = function makeStyleTag(name, cssString, relativeToTag) {
	        if (cssString) {
	            invariant$1(isString(cssString), "makeStyleTag accepts only strings as second parameter");
	        }
	        var tag = document.createElement("style");
	        if (this._nonce) tag.setAttribute("nonce", this._nonce);
	        tag.type = "text/css";
	        tag.setAttribute("data-" + name, "");
	        if (cssString) {
	            tag.appendChild(document.createTextNode(cssString));
	        }
	        var head = document.head || document.getElementsByTagName("head")[0];
	        if (relativeToTag) {
	            head.insertBefore(tag, relativeToTag);
	        } else {
	            head.appendChild(tag);
	        }
	        return tag;
	    };
	    _createClass(StyleSheet, [
	        {
	            key: "length",
	            get: function get() {
	                return this._rulesCount;
	            }
	        }
	    ]);
	    return StyleSheet;
	}();
	function invariant$1(condition, message) {
	    if (!condition) {
	        throw new Error("StyleSheet: " + message + ".");
	    }
	}

	function hash(str) {
	    var _$hash = 5381, i = str.length;
	    while(i){
	        _$hash = _$hash * 33 ^ str.charCodeAt(--i);
	    }
	    /* JavaScript does bitwise operations (like XOR, above) on 32-bit signed
	   * integers. Since we want the results to be always positive, convert the
	   * signed int to an unsigned by doing an unsigned bitshift. */ return _$hash >>> 0;
	}
	var stringHash = hash;

	var sanitize = function(rule) {
	    return rule.replace(/\/style/gi, "\\/style");
	};
	var cache = {};
	/**
	 * computeId
	 *
	 * Compute and memoize a jsx id from a basedId and optionally props.
	 */ function computeId(baseId, props) {
	    if (!props) {
	        return "jsx-" + baseId;
	    }
	    var propsToString = String(props);
	    var key = baseId + propsToString;
	    if (!cache[key]) {
	        cache[key] = "jsx-" + stringHash(baseId + "-" + propsToString);
	    }
	    return cache[key];
	}
	/**
	 * computeSelector
	 *
	 * Compute and memoize dynamic selectors.
	 */ function computeSelector(id, css) {
	    var selectoPlaceholderRegexp = /__jsx-style-dynamic-selector/g;
	    // Sanitize SSR-ed CSS.
	    // Client side code doesn't need to be sanitized since we use
	    // document.createTextNode (dev) and the CSSOM api sheet.insertRule (prod).
	    if (typeof window === "undefined") {
	        css = sanitize(css);
	    }
	    var idcss = id + css;
	    if (!cache[idcss]) {
	        cache[idcss] = css.replace(selectoPlaceholderRegexp, id);
	    }
	    return cache[idcss];
	}

	function mapRulesToStyle(cssRules, options) {
	    if (options === void 0) options = {};
	    return cssRules.map(function(args) {
	        var id = args[0];
	        var css = args[1];
	        return /*#__PURE__*/ React__default["default"].createElement("style", {
	            id: "__" + id,
	            // Avoid warnings upon render with a key
	            key: "__" + id,
	            nonce: options.nonce ? options.nonce : undefined,
	            dangerouslySetInnerHTML: {
	                __html: css
	            }
	        });
	    });
	}
	var StyleSheetRegistry = /*#__PURE__*/ function() {
	    function StyleSheetRegistry(param) {
	        var ref = param === void 0 ? {} : param, _styleSheet = ref.styleSheet, styleSheet = _styleSheet === void 0 ? null : _styleSheet, _optimizeForSpeed = ref.optimizeForSpeed, optimizeForSpeed = _optimizeForSpeed === void 0 ? false : _optimizeForSpeed;
	        this._sheet = styleSheet || new StyleSheet({
	            name: "styled-jsx",
	            optimizeForSpeed: optimizeForSpeed
	        });
	        this._sheet.inject();
	        if (styleSheet && typeof optimizeForSpeed === "boolean") {
	            this._sheet.setOptimizeForSpeed(optimizeForSpeed);
	            this._optimizeForSpeed = this._sheet.isOptimizeForSpeed();
	        }
	        this._fromServer = undefined;
	        this._indices = {};
	        this._instancesCounts = {};
	    }
	    var _proto = StyleSheetRegistry.prototype;
	    _proto.add = function add(props) {
	        var _this = this;
	        if (undefined === this._optimizeForSpeed) {
	            this._optimizeForSpeed = Array.isArray(props.children);
	            this._sheet.setOptimizeForSpeed(this._optimizeForSpeed);
	            this._optimizeForSpeed = this._sheet.isOptimizeForSpeed();
	        }
	        if (typeof window !== "undefined" && !this._fromServer) {
	            this._fromServer = this.selectFromServer();
	            this._instancesCounts = Object.keys(this._fromServer).reduce(function(acc, tagName) {
	                acc[tagName] = 0;
	                return acc;
	            }, {});
	        }
	        var ref = this.getIdAndRules(props), styleId = ref.styleId, rules = ref.rules;
	        // Deduping: just increase the instances count.
	        if (styleId in this._instancesCounts) {
	            this._instancesCounts[styleId] += 1;
	            return;
	        }
	        var indices = rules.map(function(rule) {
	            return _this._sheet.insertRule(rule);
	        })// Filter out invalid rules
	        .filter(function(index) {
	            return index !== -1;
	        });
	        this._indices[styleId] = indices;
	        this._instancesCounts[styleId] = 1;
	    };
	    _proto.remove = function remove(props) {
	        var _this = this;
	        var styleId = this.getIdAndRules(props).styleId;
	        invariant(styleId in this._instancesCounts, "styleId: `" + styleId + "` not found");
	        this._instancesCounts[styleId] -= 1;
	        if (this._instancesCounts[styleId] < 1) {
	            var tagFromServer = this._fromServer && this._fromServer[styleId];
	            if (tagFromServer) {
	                tagFromServer.parentNode.removeChild(tagFromServer);
	                delete this._fromServer[styleId];
	            } else {
	                this._indices[styleId].forEach(function(index) {
	                    return _this._sheet.deleteRule(index);
	                });
	                delete this._indices[styleId];
	            }
	            delete this._instancesCounts[styleId];
	        }
	    };
	    _proto.update = function update(props, nextProps) {
	        this.add(nextProps);
	        this.remove(props);
	    };
	    _proto.flush = function flush() {
	        this._sheet.flush();
	        this._sheet.inject();
	        this._fromServer = undefined;
	        this._indices = {};
	        this._instancesCounts = {};
	    };
	    _proto.cssRules = function cssRules() {
	        var _this = this;
	        var fromServer = this._fromServer ? Object.keys(this._fromServer).map(function(styleId) {
	            return [
	                styleId,
	                _this._fromServer[styleId]
	            ];
	        }) : [];
	        var cssRules = this._sheet.cssRules();
	        return fromServer.concat(Object.keys(this._indices).map(function(styleId) {
	            return [
	                styleId,
	                _this._indices[styleId].map(function(index) {
	                    return cssRules[index].cssText;
	                }).join(_this._optimizeForSpeed ? "" : "\n")
	            ];
	        })// filter out empty rules
	        .filter(function(rule) {
	            return Boolean(rule[1]);
	        }));
	    };
	    _proto.styles = function styles(options) {
	        return mapRulesToStyle(this.cssRules(), options);
	    };
	    _proto.getIdAndRules = function getIdAndRules(props) {
	        var css = props.children, dynamic = props.dynamic, id = props.id;
	        if (dynamic) {
	            var styleId = computeId(id, dynamic);
	            return {
	                styleId: styleId,
	                rules: Array.isArray(css) ? css.map(function(rule) {
	                    return computeSelector(styleId, rule);
	                }) : [
	                    computeSelector(styleId, css)
	                ]
	            };
	        }
	        return {
	            styleId: computeId(id),
	            rules: Array.isArray(css) ? css : [
	                css
	            ]
	        };
	    };
	    /**
	   * selectFromServer
	   *
	   * Collects style tags from the document with id __jsx-XXX
	   */ _proto.selectFromServer = function selectFromServer() {
	        var elements = Array.prototype.slice.call(document.querySelectorAll('[id^="__jsx-"]'));
	        return elements.reduce(function(acc, element) {
	            var id = element.id.slice(2);
	            acc[id] = element;
	            return acc;
	        }, {});
	    };
	    return StyleSheetRegistry;
	}();
	function invariant(condition, message) {
	    if (!condition) {
	        throw new Error("StyleSheetRegistry: " + message + ".");
	    }
	}
	var StyleSheetContext = /*#__PURE__*/ React$1.createContext(null);
	StyleSheetContext.displayName = "StyleSheetContext";
	function createStyleRegistry() {
	    return new StyleSheetRegistry();
	}
	function StyleRegistry(param) {
	    var configuredRegistry = param.registry, children = param.children;
	    var rootRegistry = React$1.useContext(StyleSheetContext);
	    var ref = React$1.useState(function() {
	        return rootRegistry || configuredRegistry || createStyleRegistry();
	    }), registry = ref[0];
	    return /*#__PURE__*/ React__default["default"].createElement(StyleSheetContext.Provider, {
	        value: registry
	    }, children);
	}
	function useStyleRegistry() {
	    return React$1.useContext(StyleSheetContext);
	}

	// Opt-into the new `useInsertionEffect` API in React 18, fallback to `useLayoutEffect`.
	// https://github.com/reactwg/react-18/discussions/110
	var useInsertionEffect = React__default["default"].useInsertionEffect || React$1.useLayoutEffect;
	var defaultRegistry = typeof window !== "undefined" ? createStyleRegistry() : undefined;
	function JSXStyle(props) {
	    var registry = defaultRegistry ? defaultRegistry : useStyleRegistry();
	    var insertionEffectCalled = React$1.useRef(false);
	    // `registry` might not exist while server-side rendering
	    if (!registry) {
	        return null;
	    }
	    if (typeof window === "undefined") {
	        registry.add(props);
	        return null;
	    }
	    useInsertionEffect(function() {
	        // ReactDOM removes all DOM during hydration in certain cases
	        if (!document.head) {
	            return;
	        }
	        registry.add(props);
	        insertionEffectCalled.current = true;
	        return function() {
	            insertionEffectCalled.current = false;
	            registry.remove(props);
	        };
	    }, [
	        props.id,
	        String(props.dynamic)
	    ]);
	    React$1.useLayoutEffect(function() {
	        if (!document.head || insertionEffectCalled.current) {
	            return;
	        }
	        registry.add(props);
	        return function() {
	            registry.remove(props);
	        };
	    // props.children can be string[], will be striped since id is identical
	    }, [
	        props.id,
	        String(props.dynamic)
	    ]);
	    return null;
	}
	JSXStyle.dynamic = function(info) {
	    return info.map(function(tagInfo) {
	        var baseId = tagInfo[0];
	        var props = tagInfo[1];
	        return computeId(baseId, props);
	    }).join(" ");
	};

	index.StyleRegistry = StyleRegistry;
	index.createStyleRegistry = createStyleRegistry;
	index.style = JSXStyle;
	index.useStyleRegistry = useStyleRegistry;
	return index;
}

var style;
var hasRequiredStyle;

function requireStyle () {
	if (hasRequiredStyle) return style;
	hasRequiredStyle = 1;
	style = requireIndex().style;
	return style;
}

var styleExports = requireStyle();
var _JSXStyle = /*@__PURE__*/getDefaultExportFromCjs(styleExports);

var InputLabel = function InputLabel(_ref) {
  var children = _ref.children,
    isRight = _ref.isRight;
  var theme$1 = theme.useTheme();
  return /*#__PURE__*/React.createElement("span", {
    className: _JSXStyle.dynamic([["3089782703", [theme$1.layout.gapHalf, theme$1.palette.accents_4, theme$1.palette.accents_1, theme$1.layout.radius, theme$1.layout.radius, theme$1.palette.border, theme$1.palette.border, theme$1.palette.border, theme$1.layout.radius, theme$1.layout.radius, theme$1.palette.border]]]) + " " + ((isRight ? 'right' : '') || "")
  }, children, /*#__PURE__*/React.createElement(_JSXStyle, {
    id: "3089782703",
    dynamic: [theme$1.layout.gapHalf, theme$1.palette.accents_4, theme$1.palette.accents_1, theme$1.layout.radius, theme$1.layout.radius, theme$1.palette.border, theme$1.palette.border, theme$1.palette.border, theme$1.layout.radius, theme$1.layout.radius, theme$1.palette.border]
  }, "span.__jsx-style-dynamic-selector{display:-webkit-inline-box;display:-webkit-inline-flex;display:-ms-inline-flexbox;display:inline-flex;width:initial;height:100%;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;pointer-events:none;margin:0;padding:0 ".concat(theme$1.layout.gapHalf, ";color:").concat(theme$1.palette.accents_4, ";background-color:").concat(theme$1.palette.accents_1, ";border-top-left-radius:").concat(theme$1.layout.radius, ";border-bottom-left-radius:").concat(theme$1.layout.radius, ";border-top:1px solid ").concat(theme$1.palette.border, ";border-left:1px solid ").concat(theme$1.palette.border, ";border-bottom:1px solid ").concat(theme$1.palette.border, ";font-size:inherit;line-height:1;}span.right.__jsx-style-dynamic-selector{border-top-left-radius:0;border-bottom-left-radius:0;border-top-right-radius:").concat(theme$1.layout.radius, ";border-bottom-right-radius:").concat(theme$1.layout.radius, ";border-left:0;border-right:1px solid ").concat(theme$1.palette.border, ";}")));
};
var MemoInputLabel = /*#__PURE__*/React.memo(InputLabel);

var InputBlockLabelComponent = function InputBlockLabelComponent(_ref) {
  var children = _ref.children;
  var theme$1 = theme.useTheme();
  return /*#__PURE__*/React.createElement("label", {
    className: _JSXStyle.dynamic([["1278828862", [theme$1.palette.accents_6]]])
  }, children, /*#__PURE__*/React.createElement(_JSXStyle, {
    id: "1278828862",
    dynamic: [theme$1.palette.accents_6]
  }, "label.__jsx-style-dynamic-selector{display:block;font-weight:normal;color:".concat(theme$1.palette.accents_6, ";padding:0 0 0 1px;margin-bottom:0.5em;font-size:1em;line-height:1.5;}label.__jsx-style-dynamic-selector>*:first-child{margin-top:0;}label.__jsx-style-dynamic-selector>*:last-child{margin-bottom:0;}")));
};
InputBlockLabelComponent.displayName = 'InputBlockLabel';
var InputBlockLabel = /*#__PURE__*/React.memo(InputBlockLabelComponent);

var InputIconComponent = function InputIconComponent(_ref) {
  var icon = _ref.icon,
    _ref$clickable = _ref.clickable,
    clickable = _ref$clickable === void 0 ? false : _ref$clickable,
    onClick = _ref.onClick;
  return /*#__PURE__*/React.createElement("span", {
    onClick: onClick,
    className: _JSXStyle.dynamic([["4247656379", [clickable ? 'pointer' : 'default', clickable ? 'auto' : 'none']]]) + " " + "input-icon"
  }, icon, /*#__PURE__*/React.createElement(_JSXStyle, {
    id: "4247656379",
    dynamic: [clickable ? 'pointer' : 'default', clickable ? 'auto' : 'none']
  }, ".input-icon.__jsx-style-dynamic-selector{box-sizing:border-box;display:-webkit-inline-box;display:-webkit-inline-flex;display:-ms-inline-flexbox;display:inline-flex;width:calc(var(--input-height) - 2px);-webkit-flex-shrink:0;-ms-flex-negative:0;flex-shrink:0;height:100%;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-box-pack:center;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;margin:0;padding:0;line-height:1;position:relative;cursor:".concat(clickable ? 'pointer' : 'default', ";pointer-events:").concat(clickable ? 'auto' : 'none', ";}.input-icon.__jsx-style-dynamic-selector svg{width:calc(var(--input-height) - 2px);height:calc(var(--input-height) - 2px);-webkit-transform:scale(0.44);-ms-transform:scale(0.44);transform:scale(0.44);}")));
};
InputIconComponent.displayName = 'InputIcon';
var InputIcon = /*#__PURE__*/React.memo(InputIconComponent);

var InputIconClear = function InputIconClear(_ref) {
  var onClick = _ref.onClick,
    disabled = _ref.disabled,
    visible = _ref.visible;
  var theme$1 = theme.useTheme();
  var classes = theme.useClasses('clear-icon', {
    visible: visible
  });
  var clickHandler = function clickHandler(event) {
    event.preventDefault();
    event.stopPropagation();
    event.nativeEvent.stopImmediatePropagation();
    onClick && onClick(event);
  };
  return /*#__PURE__*/React.createElement("div", {
    onClick: clickHandler,
    className: _JSXStyle.dynamic([["1567030211", [disabled ? 'not-allowed' : 'pointer', theme$1.palette.accents_3, disabled ? theme$1.palette.accents_3 : theme$1.palette.foreground]]]) + " " + (classes || "")
  }, /*#__PURE__*/React.createElement("svg", {
    viewBox: "0 0 24 24",
    stroke: "currentColor",
    strokeWidth: "1.5",
    strokeLinecap: "round",
    strokeLinejoin: "round",
    fill: "none",
    shapeRendering: "geometricPrecision",
    className: _JSXStyle.dynamic([["1567030211", [disabled ? 'not-allowed' : 'pointer', theme$1.palette.accents_3, disabled ? theme$1.palette.accents_3 : theme$1.palette.foreground]]])
  }, /*#__PURE__*/React.createElement("path", {
    d: "M18 6L6 18",
    className: _JSXStyle.dynamic([["1567030211", [disabled ? 'not-allowed' : 'pointer', theme$1.palette.accents_3, disabled ? theme$1.palette.accents_3 : theme$1.palette.foreground]]])
  }), /*#__PURE__*/React.createElement("path", {
    d: "M6 6l12 12",
    className: _JSXStyle.dynamic([["1567030211", [disabled ? 'not-allowed' : 'pointer', theme$1.palette.accents_3, disabled ? theme$1.palette.accents_3 : theme$1.palette.foreground]]])
  })), /*#__PURE__*/React.createElement(_JSXStyle, {
    id: "1567030211",
    dynamic: [disabled ? 'not-allowed' : 'pointer', theme$1.palette.accents_3, disabled ? theme$1.palette.accents_3 : theme$1.palette.foreground]
  }, ".clear-icon.__jsx-style-dynamic-selector{box-sizing:border-box;display:-webkit-inline-box;display:-webkit-inline-flex;display:-ms-inline-flexbox;display:inline-flex;width:calc(var(--input-height) - 2px);-webkit-flex-shrink:0;-ms-flex-negative:0;flex-shrink:0;height:100%;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-box-pack:center;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;cursor:".concat(disabled ? 'not-allowed' : 'pointer', ";-webkit-transition:color 150ms ease 0s;transition:color 150ms ease 0s;margin:0;padding:0;color:").concat(theme$1.palette.accents_3, ";visibility:hidden;opacity:0;}.visible.__jsx-style-dynamic-selector{visibility:visible;opacity:1;}.clear-icon.__jsx-style-dynamic-selector:hover{color:").concat(disabled ? theme$1.palette.accents_3 : theme$1.palette.foreground, ";}svg.__jsx-style-dynamic-selector{color:currentColor;width:calc(var(--input-height) - 2px);height:calc(var(--input-height) - 2px);-webkit-transform:scale(0.44);-ms-transform:scale(0.44);transform:scale(0.44);}")));
};
var MemoInputIconClear = /*#__PURE__*/React.memo(InputIconClear);

var getColors = function getColors(palette, status) {
  var colors = {
    "default": {
      color: palette.foreground,
      borderColor: palette.border,
      hoverBorder: palette.accents_5
    },
    secondary: {
      color: palette.foreground,
      borderColor: palette.secondary,
      hoverBorder: palette.secondary
    },
    success: {
      color: palette.foreground,
      borderColor: palette.successLight,
      hoverBorder: palette.success
    },
    warning: {
      color: palette.foreground,
      borderColor: palette.warningLight,
      hoverBorder: palette.warning
    },
    error: {
      color: palette.error,
      borderColor: palette.error,
      hoverBorder: palette.errorDark
    }
  };
  if (!status) return colors["default"];
  return colors[status];
};

/* "use client" */

var ScalePropKeys = ['width', 'height', 'padding', 'margin', 'w', 'h', 'paddingLeft', 'paddingRight', 'paddingTop', 'paddingBottom', 'pl', 'pr', 'pt', 'pb', 'marginLeft', 'marginRight', 'marginTop', 'marginBottom', 'ml', 'mr', 'mt', 'mb', 'px', 'py', 'mx', 'my', 'font', 'unit', 'scale'];
var defaultDynamicLayoutPipe = function defaultDynamicLayoutPipe(scale1x) {
  return "".concat(scale1x);
};
var defaultContext$1 = {
  getScaleProps: function getScaleProps() {
    return undefined;
  },
  getAllScaleProps: function getAllScaleProps() {
    return {};
  },
  SCALES: {
    pl: defaultDynamicLayoutPipe,
    pr: defaultDynamicLayoutPipe,
    pb: defaultDynamicLayoutPipe,
    pt: defaultDynamicLayoutPipe,
    px: defaultDynamicLayoutPipe,
    py: defaultDynamicLayoutPipe,
    mb: defaultDynamicLayoutPipe,
    ml: defaultDynamicLayoutPipe,
    mr: defaultDynamicLayoutPipe,
    mt: defaultDynamicLayoutPipe,
    mx: defaultDynamicLayoutPipe,
    my: defaultDynamicLayoutPipe,
    width: defaultDynamicLayoutPipe,
    height: defaultDynamicLayoutPipe,
    font: defaultDynamicLayoutPipe
  },
  unit: '16px'
};
var ScaleContext = /*#__PURE__*/React.createContext(defaultContext$1);
var useScale = function useScale() {
  return React.useContext(ScaleContext);
};

/* "use client" */

var pickChild = function pickChild(children, targetChild) {
  var target = [];
  var withoutTargetChildren = React.Children.map(children, function (item) {
    if (! /*#__PURE__*/React.isValidElement(item)) return item;
    if (item.type === targetChild) {
      target.push(item);
      return null;
    }
    return item;
  });
  var targetChildren = target.length >= 0 ? target : undefined;
  return [withoutTargetChildren, targetChildren];
};
var isCSSNumberValue = function isCSSNumberValue(value) {
  return value !== undefined && !Number.isNaN(+value);
};

var generateGetScaleProps = function generateGetScaleProps(props) {
  var getScaleProps = function getScaleProps(keyOrKeys) {
    if (!Array.isArray(keyOrKeys)) return props[keyOrKeys];
    var value = undefined;
    var _iterator = _createForOfIteratorHelper(keyOrKeys),
      _step;
    try {
      for (_iterator.s(); !(_step = _iterator.n()).done;) {
        var key = _step.value;
        var currentValue = props[key];
        if (typeof currentValue !== 'undefined') {
          value = currentValue;
        }
      }
    } catch (err) {
      _iterator.e(err);
    } finally {
      _iterator.f();
    }
    return value;
  };
  return getScaleProps;
};
var generateGetAllScaleProps = function generateGetAllScaleProps(props) {
  var getAllScaleProps = function getAllScaleProps() {
    var scaleProps = {};
    var _iterator2 = _createForOfIteratorHelper(ScalePropKeys),
      _step2;
    try {
      for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
        var key = _step2.value;
        var value = props[key];
        if (typeof value !== 'undefined') {
          scaleProps[key] = value;
        }
      }
    } catch (err) {
      _iterator2.e(err);
    } finally {
      _iterator2.f();
    }
    return scaleProps;
  };
  return getAllScaleProps;
};

var _excluded$5 = ["children"];
var reduceScaleCoefficient = function reduceScaleCoefficient(scale) {
  if (scale === 1) return scale;
  var diff = Math.abs((scale - 1) / 2);
  return scale > 1 ? 1 + diff : 1 - diff;
};
var withScale = function withScale(Render) {
  var ScaleFC = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
    var _ref2, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8, _ref9, _ref0, _ref1, _ref10, _ref11, _ref12, _ref13, _ref14, _ref15, _ref16, _ref17, _ref18, _ref19, _ref20, _ref21, _ref22, _ref23, _ref24, _ref25, _ref26, _ref27, _ref28, _ref29, _ref30, _ref31;
    var children = _ref.children,
      props = _objectWithoutProperties(_ref, _excluded$5);
    var _useTheme = theme.useTheme(),
      layout = _useTheme.layout;
    var paddingLeft = props.paddingLeft,
      pl = props.pl,
      paddingRight = props.paddingRight,
      pr = props.pr,
      paddingTop = props.paddingTop,
      pt = props.pt,
      paddingBottom = props.paddingBottom,
      pb = props.pb,
      marginTop = props.marginTop,
      mt = props.mt,
      marginRight = props.marginRight,
      mr = props.mr,
      marginBottom = props.marginBottom,
      mb = props.mb,
      marginLeft = props.marginLeft,
      ml = props.ml,
      px = props.px,
      py = props.py,
      mx = props.mx,
      my = props.my,
      width = props.width,
      height = props.height,
      font = props.font,
      w = props.w,
      h = props.h,
      margin = props.margin,
      padding = props.padding,
      _props$unit = props.unit,
      unit = _props$unit === void 0 ? layout.unit : _props$unit,
      _props$scale = props.scale,
      scale = _props$scale === void 0 ? 1 : _props$scale;
    var makeScaleHandler = function makeScaleHandler(attrValue) {
      return function (scale1x, defaultValue) {
        // 0 means disable scale and the default value is 0
        if (scale1x === 0) {
          scale1x = 1;
          defaultValue = defaultValue || 0;
        }
        var factor = reduceScaleCoefficient(scale) * scale1x;
        if (typeof attrValue === 'undefined') {
          if (typeof defaultValue !== 'undefined') return "".concat(defaultValue);
          return "calc(".concat(factor, " * ").concat(unit, ")");
        }
        if (!isCSSNumberValue(attrValue)) return "".concat(attrValue);
        var customFactor = factor * Number(attrValue);
        return "calc(".concat(customFactor, " * ").concat(unit, ")");
      };
    };
    var value = {
      unit: unit,
      SCALES: {
        pt: makeScaleHandler((_ref2 = (_ref3 = paddingTop !== null && paddingTop !== void 0 ? paddingTop : pt) !== null && _ref3 !== void 0 ? _ref3 : py) !== null && _ref2 !== void 0 ? _ref2 : padding),
        pr: makeScaleHandler((_ref4 = (_ref5 = paddingRight !== null && paddingRight !== void 0 ? paddingRight : pr) !== null && _ref5 !== void 0 ? _ref5 : px) !== null && _ref4 !== void 0 ? _ref4 : padding),
        pb: makeScaleHandler((_ref6 = (_ref7 = paddingBottom !== null && paddingBottom !== void 0 ? paddingBottom : pb) !== null && _ref7 !== void 0 ? _ref7 : py) !== null && _ref6 !== void 0 ? _ref6 : padding),
        pl: makeScaleHandler((_ref8 = (_ref9 = paddingLeft !== null && paddingLeft !== void 0 ? paddingLeft : pl) !== null && _ref9 !== void 0 ? _ref9 : px) !== null && _ref8 !== void 0 ? _ref8 : padding),
        px: makeScaleHandler((_ref0 = (_ref1 = (_ref10 = (_ref11 = px !== null && px !== void 0 ? px : paddingLeft) !== null && _ref11 !== void 0 ? _ref11 : paddingRight) !== null && _ref10 !== void 0 ? _ref10 : pl) !== null && _ref1 !== void 0 ? _ref1 : pr) !== null && _ref0 !== void 0 ? _ref0 : padding),
        py: makeScaleHandler((_ref12 = (_ref13 = (_ref14 = (_ref15 = py !== null && py !== void 0 ? py : paddingTop) !== null && _ref15 !== void 0 ? _ref15 : paddingBottom) !== null && _ref14 !== void 0 ? _ref14 : pt) !== null && _ref13 !== void 0 ? _ref13 : pb) !== null && _ref12 !== void 0 ? _ref12 : padding),
        mt: makeScaleHandler((_ref16 = (_ref17 = marginTop !== null && marginTop !== void 0 ? marginTop : mt) !== null && _ref17 !== void 0 ? _ref17 : my) !== null && _ref16 !== void 0 ? _ref16 : margin),
        mr: makeScaleHandler((_ref18 = (_ref19 = marginRight !== null && marginRight !== void 0 ? marginRight : mr) !== null && _ref19 !== void 0 ? _ref19 : mx) !== null && _ref18 !== void 0 ? _ref18 : margin),
        mb: makeScaleHandler((_ref20 = (_ref21 = marginBottom !== null && marginBottom !== void 0 ? marginBottom : mb) !== null && _ref21 !== void 0 ? _ref21 : my) !== null && _ref20 !== void 0 ? _ref20 : margin),
        ml: makeScaleHandler((_ref22 = (_ref23 = marginLeft !== null && marginLeft !== void 0 ? marginLeft : ml) !== null && _ref23 !== void 0 ? _ref23 : mx) !== null && _ref22 !== void 0 ? _ref22 : margin),
        mx: makeScaleHandler((_ref24 = (_ref25 = (_ref26 = (_ref27 = mx !== null && mx !== void 0 ? mx : marginLeft) !== null && _ref27 !== void 0 ? _ref27 : marginRight) !== null && _ref26 !== void 0 ? _ref26 : ml) !== null && _ref25 !== void 0 ? _ref25 : mr) !== null && _ref24 !== void 0 ? _ref24 : margin),
        my: makeScaleHandler((_ref28 = (_ref29 = (_ref30 = (_ref31 = my !== null && my !== void 0 ? my : marginTop) !== null && _ref31 !== void 0 ? _ref31 : marginBottom) !== null && _ref30 !== void 0 ? _ref30 : mt) !== null && _ref29 !== void 0 ? _ref29 : mb) !== null && _ref28 !== void 0 ? _ref28 : margin),
        width: makeScaleHandler(width !== null && width !== void 0 ? width : w),
        height: makeScaleHandler(height !== null && height !== void 0 ? height : h),
        font: makeScaleHandler(font)
      },
      getScaleProps: generateGetScaleProps(props),
      getAllScaleProps: generateGetAllScaleProps(props)
    };
    return /*#__PURE__*/React.createElement(ScaleContext.Provider, {
      value: value
    }, /*#__PURE__*/React.createElement(Render, _extends({}, props, {
      ref: ref
    }), children));
  });
  ScaleFC.displayName = "Scale".concat(Render.displayName || 'Wrapper');
  return ScaleFC;
};

var _excluded$4 = ["label", "labelRight", "color", "error", "type", "icon", "iconRight", "iconClickable", "onIconClick", "initialValue", "onChange", "readOnly", "value", "onClearClick", "clearable", "className", "onBlur", "onFocus", "autoComplete", "placeholder", "children", "disabled", "fullWidth"];
var simulateChangeEvent = function simulateChangeEvent(el, event) {
  return _objectSpread2(_objectSpread2({}, event), {}, {
    target: el,
    currentTarget: el
  });
};
var InputComponent = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
  var label = _ref.label,
    labelRight = _ref.labelRight,
    _ref$color = _ref.color,
    _color = _ref$color === void 0 ? 'default' : _ref$color,
    error = _ref.error,
    _ref$type = _ref.type,
    type = _ref$type === void 0 ? 'text' : _ref$type,
    icon = _ref.icon,
    iconRight = _ref.iconRight,
    _ref$iconClickable = _ref.iconClickable,
    iconClickable = _ref$iconClickable === void 0 ? false : _ref$iconClickable,
    onIconClick = _ref.onIconClick,
    _ref$initialValue = _ref.initialValue,
    initialValue = _ref$initialValue === void 0 ? '' : _ref$initialValue,
    onChange = _ref.onChange,
    _ref$readOnly = _ref.readOnly,
    readOnly = _ref$readOnly === void 0 ? false : _ref$readOnly,
    value = _ref.value,
    onClearClick = _ref.onClearClick,
    _ref$clearable = _ref.clearable,
    clearable = _ref$clearable === void 0 ? false : _ref$clearable,
    _ref$className = _ref.className,
    className = _ref$className === void 0 ? '' : _ref$className,
    onBlur = _ref.onBlur,
    onFocus = _ref.onFocus,
    _ref$autoComplete = _ref.autoComplete,
    autoComplete = _ref$autoComplete === void 0 ? 'off' : _ref$autoComplete,
    _ref$placeholder = _ref.placeholder,
    placeholder = _ref$placeholder === void 0 ? '' : _ref$placeholder,
    children = _ref.children,
    _ref$disabled = _ref.disabled,
    disabled = _ref$disabled === void 0 ? false : _ref$disabled,
    _ref$fullWidth = _ref.fullWidth,
    fullWidth = _ref$fullWidth === void 0 ? false : _ref$fullWidth,
    props = _objectWithoutProperties(_ref, _excluded$4);
  var theme$1 = theme.useTheme();
  var _useScale = useScale(),
    SCALES = _useScale.SCALES;
  var inputRef = React.useRef(null);
  React.useImperativeHandle(ref, function () {
    return inputRef.current;
  }); // Changed with !

  var _useState = React.useState(initialValue),
    _useState2 = _slicedToArray(_useState, 2),
    selfValue = _useState2[0],
    setSelfValue = _useState2[1];
  var _useState3 = React.useState(false),
    _useState4 = _slicedToArray(_useState3, 2),
    hover = _useState4[0],
    setHover = _useState4[1];
  var isControlledComponent = React.useMemo(function () {
    return value !== undefined;
  }, [value]);
  var labelClasses = React.useMemo(function () {
    return labelRight ? 'right-label' : label ? 'left-label' : '';
  }, [label, labelRight]);
  var iconClasses = React.useMemo(function () {
    return iconRight ? 'right-icon' : icon ? 'left-icon' : '';
  }, [icon, iconRight]);
  var _useMemo = React.useMemo(function () {
      return getColors(theme$1.palette, _color);
    }, [theme$1.palette, type]),
    color = _useMemo.color,
    borderColor = _useMemo.borderColor,
    hoverBorder = _useMemo.hoverBorder;
  var changeHandler = function changeHandler(event) {
    if (disabled || readOnly) return;
    setSelfValue(event.target.value);
    onChange && onChange(event);
  };
  var clearHandler = function clearHandler(event) {
    setSelfValue('');
    onClearClick && onClearClick(event);
    /* istanbul ignore next */
    if (!inputRef.current) return;
    var changeEvent = simulateChangeEvent(inputRef.current, event);
    changeEvent.target.value = '';
    onChange && onChange(changeEvent);
    inputRef.current.focus();
  };
  var focusHandler = function focusHandler(e) {
    setHover(true);
    onFocus && onFocus(e);
  };
  var blurHandler = function blurHandler(e) {
    setHover(false);
    onBlur && onBlur(e);
  };
  var iconClickHandler = function iconClickHandler(e) {
    if (disabled) return;
    onIconClick && onIconClick(e);
  };
  var iconProps = React.useMemo(function () {
    return {
      clickable: iconClickable,
      onClick: iconClickHandler
    };
  }, [iconClickable, iconClickHandler]);
  React.useEffect(function () {
    if (isControlledComponent) {
      setSelfValue(value);
    }
  });
  var controlledValue = isControlledComponent ? {
    value: selfValue
  } : {
    defaultValue: initialValue
  };
  var inputProps = _objectSpread2(_objectSpread2({}, props), controlledValue);
  var defaultWidth = fullWidth ? '100%' : 'initial';
  return /*#__PURE__*/React.createElement("div", {
    className: _JSXStyle.dynamic([["3279091727", [SCALES.height(2.25), SCALES.font(0.875), SCALES.width(1, defaultWidth), SCALES.pt(0), SCALES.pr(0), SCALES.pb(0), SCALES.pl(0), SCALES.mt(0), SCALES.mr(0), SCALES.mb(0), SCALES.ml(0), SCALES.width(1, defaultWidth), theme$1.layout.radius, borderColor, theme$1.palette.accents_1, theme$1.palette.accents_2, hoverBorder, SCALES.font(0.875), color, theme$1.palette.accents_3, theme$1.palette.background, color]]]) + " " + "with-label"
  }, children && /*#__PURE__*/React.createElement(InputBlockLabel, null, children), /*#__PURE__*/React.createElement("div", {
    className: _JSXStyle.dynamic([["3279091727", [SCALES.height(2.25), SCALES.font(0.875), SCALES.width(1, defaultWidth), SCALES.pt(0), SCALES.pr(0), SCALES.pb(0), SCALES.pl(0), SCALES.mt(0), SCALES.mr(0), SCALES.mb(0), SCALES.ml(0), SCALES.width(1, defaultWidth), theme$1.layout.radius, borderColor, theme$1.palette.accents_1, theme$1.palette.accents_2, hoverBorder, SCALES.font(0.875), color, theme$1.palette.accents_3, theme$1.palette.background, color]]]) + " " + (theme.useClasses('input-container', className) || "")
  }, label && /*#__PURE__*/React.createElement(MemoInputLabel, null, label), /*#__PURE__*/React.createElement("div", {
    className: _JSXStyle.dynamic([["3279091727", [SCALES.height(2.25), SCALES.font(0.875), SCALES.width(1, defaultWidth), SCALES.pt(0), SCALES.pr(0), SCALES.pb(0), SCALES.pl(0), SCALES.mt(0), SCALES.mr(0), SCALES.mb(0), SCALES.ml(0), SCALES.width(1, defaultWidth), theme$1.layout.radius, borderColor, theme$1.palette.accents_1, theme$1.palette.accents_2, hoverBorder, SCALES.font(0.875), color, theme$1.palette.accents_3, theme$1.palette.background, color]]]) + " " + (theme.useClasses('input-wrapper', {
      hover: hover,
      disabled: disabled
    }, labelClasses) || "")
  }, icon && /*#__PURE__*/React.createElement(InputIcon, _extends({
    icon: icon
  }, iconProps)), /*#__PURE__*/React.createElement("input", _extends({
    type: type,
    ref: inputRef,
    placeholder: placeholder,
    disabled: disabled,
    readOnly: readOnly,
    onFocus: focusHandler,
    onBlur: blurHandler,
    onChange: changeHandler,
    autoComplete: autoComplete
  }, inputProps, {
    className: _JSXStyle.dynamic([["3279091727", [SCALES.height(2.25), SCALES.font(0.875), SCALES.width(1, defaultWidth), SCALES.pt(0), SCALES.pr(0), SCALES.pb(0), SCALES.pl(0), SCALES.mt(0), SCALES.mr(0), SCALES.mb(0), SCALES.ml(0), SCALES.width(1, defaultWidth), theme$1.layout.radius, borderColor, theme$1.palette.accents_1, theme$1.palette.accents_2, hoverBorder, SCALES.font(0.875), color, theme$1.palette.accents_3, theme$1.palette.background, color]]]) + " " + (inputProps && inputProps.className != null && inputProps.className || theme.useClasses({
      disabled: disabled
    }, iconClasses) || "")
  })), clearable && /*#__PURE__*/React.createElement(MemoInputIconClear, {
    visible: Boolean(inputRef.current && inputRef.current.value !== ''),
    disabled: disabled || readOnly,
    onClick: clearHandler
  }), iconRight && /*#__PURE__*/React.createElement(InputIcon, _extends({
    icon: iconRight
  }, iconProps))), labelRight && /*#__PURE__*/React.createElement(MemoInputLabel, {
    isRight: true
  }, labelRight), /*#__PURE__*/React.createElement("br", {
    className: _JSXStyle.dynamic([["3279091727", [SCALES.height(2.25), SCALES.font(0.875), SCALES.width(1, defaultWidth), SCALES.pt(0), SCALES.pr(0), SCALES.pb(0), SCALES.pl(0), SCALES.mt(0), SCALES.mr(0), SCALES.mb(0), SCALES.ml(0), SCALES.width(1, defaultWidth), theme$1.layout.radius, borderColor, theme$1.palette.accents_1, theme$1.palette.accents_2, hoverBorder, SCALES.font(0.875), color, theme$1.palette.accents_3, theme$1.palette.background, color]]])
  })), error && /*#__PURE__*/React.createElement("p", {
    style: {
      marginTop: 0.4,
      marginRight: 0,
      marginLeft: 0,
      marginBottom: '0.4rem',
      textAlign: 'left'
    },
    className: _JSXStyle.dynamic([["3279091727", [SCALES.height(2.25), SCALES.font(0.875), SCALES.width(1, defaultWidth), SCALES.pt(0), SCALES.pr(0), SCALES.pb(0), SCALES.pl(0), SCALES.mt(0), SCALES.mr(0), SCALES.mb(0), SCALES.ml(0), SCALES.width(1, defaultWidth), theme$1.layout.radius, borderColor, theme$1.palette.accents_1, theme$1.palette.accents_2, hoverBorder, SCALES.font(0.875), color, theme$1.palette.accents_3, theme$1.palette.background, color]]]) + " " + "input-error"
  }, error), /*#__PURE__*/React.createElement(_JSXStyle, {
    id: "3279091727",
    dynamic: [SCALES.height(2.25), SCALES.font(0.875), SCALES.width(1, defaultWidth), SCALES.pt(0), SCALES.pr(0), SCALES.pb(0), SCALES.pl(0), SCALES.mt(0), SCALES.mr(0), SCALES.mb(0), SCALES.ml(0), SCALES.width(1, defaultWidth), theme$1.layout.radius, borderColor, theme$1.palette.accents_1, theme$1.palette.accents_2, hoverBorder, SCALES.font(0.875), color, theme$1.palette.accents_3, theme$1.palette.background, color]
  }, ".with-label.__jsx-style-dynamic-selector{display:inline-block;box-sizing:border-box;-webkit-box-align:center;--input-height:".concat(SCALES.height(2.25), ";font-size:").concat(SCALES.font(0.875), ";width:").concat(SCALES.width(1, defaultWidth), ";padding:").concat(SCALES.pt(0), " ").concat(SCALES.pr(0), " ").concat(SCALES.pb(0), " ").concat(SCALES.pl(0), ";margin:").concat(SCALES.mt(0), " ").concat(SCALES.mr(0), " ").concat(SCALES.mb(0), " ").concat(SCALES.ml(0), ";}.input-error.__jsx-style-dynamic-selector{color:#aa4a44;}.input-container.__jsx-style-dynamic-selector{display:-webkit-inline-box;display:-webkit-inline-flex;display:-ms-inline-flexbox;display:inline-flex;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;width:").concat(SCALES.width(1, defaultWidth), ";height:var(--input-height);}.input-wrapper.__jsx-style-dynamic-selector{display:-webkit-inline-box;display:-webkit-inline-flex;display:-ms-inline-flexbox;display:inline-flex;vertical-align:middle;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;height:100%;-webkit-flex:1;-ms-flex:1;flex:1;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;border-radius:").concat(theme$1.layout.radius, ";border:1px solid ").concat(borderColor, ";-webkit-transition:border 0.2s ease 0s,color 0.2s ease 0s;transition:border 0.2s ease 0s,color 0.2s ease 0s;}.input-wrapper.left-label.__jsx-style-dynamic-selector{border-top-left-radius:0;border-bottom-left-radius:0;}.input-wrapper.right-label.__jsx-style-dynamic-selector{border-top-right-radius:0;border-bottom-right-radius:0;}.input-wrapper.disabled.__jsx-style-dynamic-selector{background-color:").concat(theme$1.palette.accents_1, ";border-color:").concat(theme$1.palette.accents_2, ";cursor:not-allowed;}input.disabled.__jsx-style-dynamic-selector{cursor:not-allowed;}.input-wrapper.hover.__jsx-style-dynamic-selector{border-color:").concat(hoverBorder, ";}input.__jsx-style-dynamic-selector{margin:0.25em 0.625em;padding:0;box-shadow:none;font-size:").concat(SCALES.font(0.875), ";background-color:transparent;border:none;color:").concat(color, ";outline:none;border-radius:0;width:100%;min-width:0;-webkit-appearance:none;}input.left-icon.__jsx-style-dynamic-selector{margin-left:0;}input.right-icon.__jsx-style-dynamic-selector{margin-right:0;}.__jsx-style-dynamic-selector::-webkit-input-placeholder,.__jsx-style-dynamic-selector::-moz-placeholder,.__jsx-style-dynamic-selector:-ms-input-placeholder,.__jsx-style-dynamic-selector::-webkit-input-placeholder{color:").concat(theme$1.palette.accents_3, ";}.__jsx-style-dynamic-selector::-moz-placeholder,.__jsx-style-dynamic-selector::-moz-placeholder,.__jsx-style-dynamic-selector:-ms-input-placeholder,.__jsx-style-dynamic-selector::-webkit-input-placeholder{color:").concat(theme$1.palette.accents_3, ";}.__jsx-style-dynamic-selector:-ms-input-placeholder,.__jsx-style-dynamic-selector::-moz-placeholder,.__jsx-style-dynamic-selector:-ms-input-placeholder,.__jsx-style-dynamic-selector::-webkit-input-placeholder{color:").concat(theme$1.palette.accents_3, ";}.__jsx-style-dynamic-selector::placeholder,.__jsx-style-dynamic-selector::-moz-placeholder,.__jsx-style-dynamic-selector:-ms-input-placeholder,.__jsx-style-dynamic-selector::-webkit-input-placeholder{color:").concat(theme$1.palette.accents_3, ";}.__jsx-style-dynamic-selector::-ms-reveal{display:none !important;}input.__jsx-style-dynamic-selector:-webkit-autofill,input.__jsx-style-dynamic-selector:-webkit-autofill.__jsx-style-dynamic-selector:hover,input.__jsx-style-dynamic-selector:-webkit-autofill.__jsx-style-dynamic-selector:active,input.__jsx-style-dynamic-selector:-webkit-autofill.__jsx-style-dynamic-selector:focus{-webkit-box-shadow:0 0 0 30px ").concat(theme$1.palette.background, " inset !important;-webkit-text-fill-color:").concat(color, " !important;}")));
});
InputComponent.displayName = 'Input';
var Input = withScale(InputComponent);

var tuple = function tuple() {
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
    args[_key] = arguments[_key];
  }
  return args;
};
tuple('default', 'secondary', 'success', 'warning', 'error', 'abort', 'secondary-light', 'success-light', 'warning-light', 'error-light');
tuple('default', 'secondary', 'success', 'warning', 'error');
tuple('default', 'secondary', 'success', 'warning', 'error', 'dark', 'lite');
tuple('default', 'secondary', 'success', 'warning', 'error', 'dark', 'lite', 'alert', 'purple', 'violet', 'cyan');
tuple('default', 'silent', 'prevent');
tuple('hover', 'click');
tuple('top', 'topStart', 'topEnd', 'left', 'leftStart', 'leftEnd', 'bottom', 'bottomStart', 'bottomEnd', 'right', 'rightStart', 'rightEnd');
tuple('start', 'center', 'end', 'left', 'right');

var _excluded$3 = ["type", "disabled", "readOnly", "onFocus", "onBlur", "className", "initialValue", "onChange", "value", "placeholder", "resize"];
tuple('none', 'both', 'horizontal', 'vertical', 'initial', 'inherit');
var TextareaComponent = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
  var _ref$type = _ref.type,
    type = _ref$type === void 0 ? 'default' : _ref$type,
    _ref$disabled = _ref.disabled,
    disabled = _ref$disabled === void 0 ? false : _ref$disabled,
    _ref$readOnly = _ref.readOnly,
    readOnly = _ref$readOnly === void 0 ? false : _ref$readOnly,
    onFocus = _ref.onFocus,
    onBlur = _ref.onBlur,
    _ref$className = _ref.className,
    className = _ref$className === void 0 ? '' : _ref$className,
    _ref$initialValue = _ref.initialValue,
    initialValue = _ref$initialValue === void 0 ? '' : _ref$initialValue,
    onChange = _ref.onChange,
    value = _ref.value,
    placeholder = _ref.placeholder,
    _ref$resize = _ref.resize,
    resize = _ref$resize === void 0 ? 'none' : _ref$resize,
    props = _objectWithoutProperties(_ref, _excluded$3);
  var theme$1 = theme.useTheme();
  var _useScale = useScale(),
    SCALES = _useScale.SCALES;
  var textareaRef = React.useRef(null);
  React.useImperativeHandle(ref, function () {
    return textareaRef.current;
  }); // added not null
  var isControlledComponent = React.useMemo(function () {
    return value !== undefined;
  }, [value]);
  var _useState = React.useState(initialValue),
    _useState2 = _slicedToArray(_useState, 2),
    selfValue = _useState2[0],
    setSelfValue = _useState2[1];
  var _useState3 = React.useState(false),
    _useState4 = _slicedToArray(_useState3, 2),
    hover = _useState4[0],
    setHover = _useState4[1];
  var _useMemo = React.useMemo(function () {
      return getColors(theme$1.palette, type);
    }, [theme$1.palette, type]),
    color = _useMemo.color,
    borderColor = _useMemo.borderColor,
    hoverBorder = _useMemo.hoverBorder;
  var classes = theme.useClasses('wrapper', {
    hover: hover,
    disabled: disabled
  }, className);
  var changeHandler = function changeHandler(event) {
    if (disabled || readOnly) return;
    setSelfValue(event.target.value);
    onChange && onChange(event);
  };
  var focusHandler = function focusHandler(e) {
    setHover(true);
    onFocus && onFocus(e);
  };
  var blurHandler = function blurHandler(e) {
    setHover(false);
    onBlur && onBlur(e);
  };
  React.useEffect(function () {
    if (isControlledComponent) {
      setSelfValue(value);
    }
  });
  var controlledValue = isControlledComponent ? {
    value: selfValue
  } : {
    defaultValue: initialValue
  };
  var textareaProps = _objectSpread2(_objectSpread2({}, props), controlledValue);
  return /*#__PURE__*/React.createElement("div", {
    className: _JSXStyle.dynamic([["12276481", [theme$1.layout.radius, borderColor, color, SCALES.font(0.875), SCALES.height(1, 'auto'), SCALES.width(1, 'initial'), SCALES.mt(0), SCALES.mr(0), SCALES.mb(0), SCALES.ml(0), hoverBorder, theme$1.palette.accents_1, theme$1.palette.accents_2, theme$1.font.sans, SCALES.pt(0.5), SCALES.pr(0.5), SCALES.pb(0.5), SCALES.pl(0.5), resize, theme$1.palette.background]]]) + " " + (classes || "")
  }, /*#__PURE__*/React.createElement("textarea", _extends({
    ref: textareaRef,
    disabled: disabled,
    placeholder: placeholder,
    readOnly: readOnly,
    onFocus: focusHandler,
    onBlur: blurHandler,
    onChange: changeHandler
  }, textareaProps, {
    className: _JSXStyle.dynamic([["12276481", [theme$1.layout.radius, borderColor, color, SCALES.font(0.875), SCALES.height(1, 'auto'), SCALES.width(1, 'initial'), SCALES.mt(0), SCALES.mr(0), SCALES.mb(0), SCALES.ml(0), hoverBorder, theme$1.palette.accents_1, theme$1.palette.accents_2, theme$1.font.sans, SCALES.pt(0.5), SCALES.pr(0.5), SCALES.pb(0.5), SCALES.pl(0.5), resize, theme$1.palette.background]]]) + " " + (textareaProps && textareaProps.className != null && textareaProps.className || "")
  })), /*#__PURE__*/React.createElement(_JSXStyle, {
    id: "12276481",
    dynamic: [theme$1.layout.radius, borderColor, color, SCALES.font(0.875), SCALES.height(1, 'auto'), SCALES.width(1, 'initial'), SCALES.mt(0), SCALES.mr(0), SCALES.mb(0), SCALES.ml(0), hoverBorder, theme$1.palette.accents_1, theme$1.palette.accents_2, theme$1.font.sans, SCALES.pt(0.5), SCALES.pr(0.5), SCALES.pb(0.5), SCALES.pl(0.5), resize, theme$1.palette.background]
  }, ".wrapper.__jsx-style-dynamic-selector{display:-webkit-inline-box;display:-webkit-inline-flex;display:-ms-inline-flexbox;display:inline-flex;box-sizing:border-box;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;border-radius:".concat(theme$1.layout.radius, ";border:1px solid ").concat(borderColor, ";color:").concat(color, ";-webkit-transition:border 0.2s ease 0s,color 0.2s ease 0s;transition:border 0.2s ease 0s,color 0.2s ease 0s;min-width:12.5rem;max-width:95vw;--textarea-font-size:").concat(SCALES.font(0.875), ";--textarea-height:").concat(SCALES.height(1, 'auto'), ";width:").concat(SCALES.width(1, 'initial'), ";height:var(--textarea-height);margin:").concat(SCALES.mt(0), " ").concat(SCALES.mr(0), " ").concat(SCALES.mb(0), " ").concat(SCALES.ml(0), ";}.wrapper.hover.__jsx-style-dynamic-selector{border-color:").concat(hoverBorder, ";}.wrapper.disabled.__jsx-style-dynamic-selector{background-color:").concat(theme$1.palette.accents_1, ";border-color:").concat(theme$1.palette.accents_2, ";cursor:not-allowed;}textarea.__jsx-style-dynamic-selector{background-color:transparent;box-shadow:none;display:block;font-family:").concat(theme$1.font.sans, ";font-size:var(--textarea-font-size);width:100%;height:var(--textarea-height);border:none;outline:none;padding:").concat(SCALES.pt(0.5), " ").concat(SCALES.pr(0.5), " ").concat(SCALES.pb(0.5), " ").concat(SCALES.pl(0.5), ";resize:").concat(resize, ";}.disabled.__jsx-style-dynamic-selector>textarea.__jsx-style-dynamic-selector{cursor:not-allowed;}textarea.__jsx-style-dynamic-selector:-webkit-autofill,textarea.__jsx-style-dynamic-selector:-webkit-autofill.__jsx-style-dynamic-selector:hover,textarea.__jsx-style-dynamic-selector:-webkit-autofill.__jsx-style-dynamic-selector:active,textarea.__jsx-style-dynamic-selector:-webkit-autofill.__jsx-style-dynamic-selector:focus{-webkit-box-shadow:0 0 0 30px ").concat(theme$1.palette.background, " inset !important;}")));
});
TextareaComponent.displayName = 'Textarea';
var Textarea = withScale(TextareaComponent);

var PasswordIcon = function PasswordIcon(_ref) {
  var visible = _ref.visible;
  return /*#__PURE__*/React.createElement("svg", {
    viewBox: "0 0 24 24",
    stroke: "currentColor",
    strokeWidth: "1.5",
    strokeLinecap: "round",
    strokeLinejoin: "round",
    fill: "none",
    shapeRendering: "geometricPrecision",
    style: {
      color: 'currentColor'
    }
  }, !visible ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("path", {
    d: "M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"
  }), /*#__PURE__*/React.createElement("circle", {
    cx: "12",
    cy: "12",
    r: "3"
  })) : /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("path", {
    d: "M17.94 17.94A10.07 10.07 0 0112 20c-7 0-11-8-11-8a18.45 18.45 0 015.06-5.94M9.9 4.24A9.12 9.12 0 0112 4c7 0 11 8 11 8a18.5 18.5 0 01-2.16 3.19m-6.72-1.07a3 3 0 11-4.24-4.24"
  }), /*#__PURE__*/React.createElement("path", {
    d: "M1 1l22 22"
  })));
};
var MemoPasswordIcon = /*#__PURE__*/React.memo(PasswordIcon);

var _excluded$2 = ["hideToggle", "children"];
var InputPasswordComponent = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
  var hideToggle = _ref.hideToggle,
    children = _ref.children,
    props = _objectWithoutProperties(_ref, _excluded$2);
  var _useScale = useScale(),
    getAllScaleProps = _useScale.getAllScaleProps;
  var inputRef = React.useRef(null);
  var _useState = React.useState(false),
    _useState2 = _slicedToArray(_useState, 2),
    visible = _useState2[0],
    setVisible = _useState2[1];
  React.useImperativeHandle(ref, function () {
    return inputRef.current;
  }); // Changed with !

  var iconClickHandler = function iconClickHandler() {
    setVisible(function (v) {
      return !v;
    });
    /* istanbul ignore next */
    if (inputRef && inputRef.current) {
      inputRef.current.focus();
    }
  };
  var inputProps = React.useMemo(function () {
    return _objectSpread2(_objectSpread2({}, props), {}, {
      ref: inputRef,
      iconClickable: true,
      onIconClick: iconClickHandler,
      type: visible ? 'text' : 'password'
    });
  }, [props, iconClickHandler, visible, inputRef]);
  var icon = React.useMemo(function () {
    if (hideToggle) return null;
    return /*#__PURE__*/React.createElement(MemoPasswordIcon, {
      visible: visible
    });
  }, [hideToggle, visible]);
  return /*#__PURE__*/React.createElement(Input, _extends({
    iconRight: icon
  }, getAllScaleProps(), inputProps), children);
});
InputPasswordComponent.displayName = 'InputPassword';
var InputPassword = withScale(InputPasswordComponent);

/* "use client" */
Input.Textarea = Textarea;
Input.Password = InputPassword;

/* "use client" */

var defaultContext = {
  visible: false
};
var AutoCompleteContext = /*#__PURE__*/React.createContext(defaultContext);
var useAutoCompleteContext = function useAutoCompleteContext() {
  return React.useContext(AutoCompleteContext);
};

// interface Props 

var AutoCompleteItemComponent = function AutoCompleteItemComponent(_ref) {
  var identValue = _ref.value,
    children = _ref.children,
    isLabelOnly = _ref.isLabelOnly;
  var theme$1 = theme.useTheme();
  var _useScale = useScale(),
    SCALES = _useScale.SCALES;
  var _useAutoCompleteConte = useAutoCompleteContext(),
    value = _useAutoCompleteConte.value,
    updateValue = _useAutoCompleteConte.updateValue,
    updateVisible = _useAutoCompleteConte.updateVisible;
  var selectHandler = function selectHandler() {
    updateValue && updateValue(identValue);
    updateVisible && updateVisible(false);
  };
  var isActive = React.useMemo(function () {
    return value === identValue;
  }, [identValue, value]);
  var classes = theme.useClasses('item', {
    active: isActive
  });
  return /*#__PURE__*/React.createElement("div", {
    onClick: selectHandler,
    className: _JSXStyle.dynamic([["2003094915", [theme$1.palette.background, theme$1.palette.foreground, SCALES.font(0.875), SCALES.width(1, 'auto'), isLabelOnly ? SCALES.height(2.5) : SCALES.height(1, 'auto'), SCALES.pt(0), SCALES.pr(0.75), SCALES.pb(0), SCALES.pl(0.75), SCALES.mt(0), SCALES.mr(0), SCALES.mb(0), SCALES.ml(0), theme$1.layout.radius, theme$1.layout.radius, theme$1.layout.radius, theme$1.layout.radius, theme$1.palette.accents_1, theme$1.palette.accents_1, theme$1.palette.success]]]) + " " + (classes || "")
  }, isLabelOnly ? /*#__PURE__*/React.createElement(theme.Ellipsis, {
    height: SCALES.height(2)
  }, children) : children, /*#__PURE__*/React.createElement(_JSXStyle, {
    id: "2003094915",
    dynamic: [theme$1.palette.background, theme$1.palette.foreground, SCALES.font(0.875), SCALES.width(1, 'auto'), isLabelOnly ? SCALES.height(2.5) : SCALES.height(1, 'auto'), SCALES.pt(0), SCALES.pr(0.75), SCALES.pb(0), SCALES.pl(0.75), SCALES.mt(0), SCALES.mr(0), SCALES.mb(0), SCALES.ml(0), theme$1.layout.radius, theme$1.layout.radius, theme$1.layout.radius, theme$1.layout.radius, theme$1.palette.accents_1, theme$1.palette.accents_1, theme$1.palette.success]
  }, ".item.__jsx-style-dynamic-selector{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-box-pack:start;-webkit-justify-content:flex-start;-ms-flex-pack:start;justify-content:flex-start;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;font-weight:normal;white-space:pre;background-color:".concat(theme$1.palette.background, ";color:").concat(theme$1.palette.foreground, ";-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;border:0;cursor:pointer;-webkit-transition:background 0.2s ease 0s,border-color 0.2s ease 0s;transition:background 0.2s ease 0s,border-color 0.2s ease 0s;font-size:").concat(SCALES.font(0.875), ";width:").concat(SCALES.width(1, 'auto'), ";height:").concat(isLabelOnly ? SCALES.height(2.5) : SCALES.height(1, 'auto'), ";padding:").concat(SCALES.pt(0), " ").concat(SCALES.pr(0.75), " ").concat(SCALES.pb(0), " ").concat(SCALES.pl(0.75), ";margin:").concat(SCALES.mt(0), " ").concat(SCALES.mr(0), " ").concat(SCALES.mb(0), " ").concat(SCALES.ml(0), ";}.item.__jsx-style-dynamic-selector:first-of-type{border-top-left-radius:").concat(theme$1.layout.radius, ";border-top-right-radius:").concat(theme$1.layout.radius, ";}.item.__jsx-style-dynamic-selector:last-of-type{border-bottom-left-radius:").concat(theme$1.layout.radius, ";border-bottom-right-radius:").concat(theme$1.layout.radius, ";}.item.__jsx-style-dynamic-selector:hover{background-color:").concat(theme$1.palette.accents_1, ";}.item.active.__jsx-style-dynamic-selector{background-color:").concat(theme$1.palette.accents_1, ";color:").concat(theme$1.palette.success, ";}")));
};
AutoCompleteItemComponent.displayName = 'AutoCompleteItem';

var AutoCompleteDropdown = function AutoCompleteDropdown(_ref) {
  var children = _ref.children,
    visible = _ref.visible,
    _ref$className = _ref.className,
    className = _ref$className === void 0 ? '' : _ref$className,
    _ref$dropdownStyle = _ref.dropdownStyle,
    dropdownStyle = _ref$dropdownStyle === void 0 ? {} : _ref$dropdownStyle,
    disableMatchWidth = _ref.disableMatchWidth,
    getPopupContainer = _ref.getPopupContainer;
  var theme$1 = theme.useTheme();
  var _useAutoCompleteConte = useAutoCompleteContext(),
    ref = _useAutoCompleteConte.ref;
  var isEmpty = React.useMemo(function () {
    return !visible || React.Children.count(children) === 0;
  }, [children, visible]);
  var classes = theme.useClasses('auto-complete-dropdown', className);
  var clickHandler = function clickHandler(event) {
    event.preventDefault();
    event.stopPropagation();
    event.nativeEvent.stopImmediatePropagation();
  };
  return /*#__PURE__*/React.createElement(theme.Dropdown, {
    parent: ref,
    visible: visible,
    disableMatchWidth: disableMatchWidth,
    getPopupContainer: getPopupContainer
  }, /*#__PURE__*/React.createElement("div", {
    style: dropdownStyle,
    onClick: clickHandler,
    className: _JSXStyle.dynamic([["155200262", [theme$1.layout.radius, isEmpty ? 'none' : theme$1.expressiveness.shadowLarge, theme$1.palette.background]]]) + " " + (classes || "")
  }, children, /*#__PURE__*/React.createElement(_JSXStyle, {
    id: "155200262",
    dynamic: [theme$1.layout.radius, isEmpty ? 'none' : theme$1.expressiveness.shadowLarge, theme$1.palette.background]
  }, ".auto-complete-dropdown.__jsx-style-dynamic-selector{border-radius:".concat(theme$1.layout.radius, ";box-shadow:").concat(isEmpty ? 'none' : theme$1.expressiveness.shadowLarge, ";background-color:").concat(theme$1.palette.background, ";overflow-y:auto;max-height:15rem;overflow-anchor:none;}"))));
};
AutoCompleteDropdown.displayName = 'AutoCompleteDropdown';

// interface Props {
//   className?: string
// }

var AutoCompleteSearchComponent = function AutoCompleteSearchComponent(_ref) {
  var children = _ref.children,
    className = _ref.className;
  var theme$1 = theme.useTheme();
  var _useScale = useScale(),
    SCALES = _useScale.SCALES;
  return /*#__PURE__*/React.createElement("div", {
    className: _JSXStyle.dynamic([["2266351824", [theme$1.layout.gapHalf, theme$1.palette.background, theme$1.palette.accents_5, theme$1.layout.radius, SCALES.font(0.875), SCALES.width(1, 'auto'), SCALES.height(1, 'auto'), SCALES.pt(0.875), SCALES.pr(0.875), SCALES.pb(0.875), SCALES.pl(0.875), SCALES.mt(0), SCALES.mr(0), SCALES.mb(0), SCALES.ml(0)]]]) + " " + (className || "")
  }, children, /*#__PURE__*/React.createElement(_JSXStyle, {
    id: "2266351824",
    dynamic: [theme$1.layout.gapHalf, theme$1.palette.background, theme$1.palette.accents_5, theme$1.layout.radius, SCALES.font(0.875), SCALES.width(1, 'auto'), SCALES.height(1, 'auto'), SCALES.pt(0.875), SCALES.pr(0.875), SCALES.pb(0.875), SCALES.pl(0.875), SCALES.mt(0), SCALES.mr(0), SCALES.mb(0), SCALES.ml(0)]
  }, "div.__jsx-style-dynamic-selector{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-box-pack:center;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;text-align:center;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;font-weight:normal;white-space:pre;padding:".concat(theme$1.layout.gapHalf, ";line-height:1;background-color:").concat(theme$1.palette.background, ";color:").concat(theme$1.palette.accents_5, ";-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;border:0;border-radius:").concat(theme$1.layout.radius, ";font-size:").concat(SCALES.font(0.875), ";width:").concat(SCALES.width(1, 'auto'), ";height:").concat(SCALES.height(1, 'auto'), ";padding:").concat(SCALES.pt(0.875), " ").concat(SCALES.pr(0.875), " ").concat(SCALES.pb(0.875), " ").concat(SCALES.pl(0.875), ";margin:").concat(SCALES.mt(0), " ").concat(SCALES.mr(0), " ").concat(SCALES.mb(0), " ").concat(SCALES.ml(0), ";}")));
};
AutoCompleteSearchComponent.displayName = 'AutoCompleteSearch';
var AutoCompleteSearch = withScale(AutoCompleteSearchComponent);

var AutoCompleteEmpty = function AutoCompleteEmpty(_ref) {
  var children = _ref.children,
    _ref$hidden = _ref.hidden,
    hidden = _ref$hidden === void 0 ? false : _ref$hidden,
    _ref$className = _ref.className,
    className = _ref$className === void 0 ? '' : _ref$className;
  if (hidden) return null;
  return /*#__PURE__*/React.createElement(AutoCompleteSearch, {
    className: className
  }, children);
};
AutoCompleteEmpty.displayName = 'AutoCompleteEmpty';

var _excluded$1 = ["children", "type", "color", "className", "spaceRatio"];
var getIconBgColor = function getIconBgColor(type, palette, color) {
  var colors = {
    "default": palette.accents_6,
    secondary: palette.secondary,
    success: palette.success,
    warning: palette.warning,
    error: palette.error
  };
  return color ? color : colors[type];
};
var LoadingComponent = function LoadingComponent(_ref) {
  var children = _ref.children,
    _ref$type = _ref.type,
    type = _ref$type === void 0 ? 'default' : _ref$type,
    color = _ref.color,
    _ref$className = _ref.className,
    className = _ref$className === void 0 ? '' : _ref$className,
    _ref$spaceRatio = _ref.spaceRatio,
    spaceRatio = _ref$spaceRatio === void 0 ? 1 : _ref$spaceRatio,
    props = _objectWithoutProperties(_ref, _excluded$1);
  var theme$1 = theme.useTheme();
  var _useScale = useScale(),
    SCALES = _useScale.SCALES;
  var classes = theme.useClasses('loading-container', className);
  var bgColor = React.useMemo(function () {
    return getIconBgColor(type, theme$1.palette, color);
  }, [type, theme$1.palette, color]);
  return /*#__PURE__*/React.createElement("div", _extends({}, props, {
    className: _JSXStyle.dynamic([["2201634259", [SCALES.font(1), SCALES.width(1, '100%'), SCALES.height(1, '100%'), SCALES.pt(0), SCALES.pr(0), SCALES.pb(0), SCALES.pl(0), SCALES.mt(0), SCALES.mr(0), SCALES.mb(0), SCALES.ml(0), theme$1.palette.accents_5, bgColor, spaceRatio]]]) + " " + (props && props.className != null && props.className || classes || "")
  }), /*#__PURE__*/React.createElement("span", {
    className: _JSXStyle.dynamic([["2201634259", [SCALES.font(1), SCALES.width(1, '100%'), SCALES.height(1, '100%'), SCALES.pt(0), SCALES.pr(0), SCALES.pb(0), SCALES.pl(0), SCALES.mt(0), SCALES.mr(0), SCALES.mb(0), SCALES.ml(0), theme$1.palette.accents_5, bgColor, spaceRatio]]]) + " " + "loading"
  }, children && /*#__PURE__*/React.createElement("label", {
    className: _JSXStyle.dynamic([["2201634259", [SCALES.font(1), SCALES.width(1, '100%'), SCALES.height(1, '100%'), SCALES.pt(0), SCALES.pr(0), SCALES.pb(0), SCALES.pl(0), SCALES.mt(0), SCALES.mr(0), SCALES.mb(0), SCALES.ml(0), theme$1.palette.accents_5, bgColor, spaceRatio]]])
  }, children), /*#__PURE__*/React.createElement("i", {
    className: _JSXStyle.dynamic([["2201634259", [SCALES.font(1), SCALES.width(1, '100%'), SCALES.height(1, '100%'), SCALES.pt(0), SCALES.pr(0), SCALES.pb(0), SCALES.pl(0), SCALES.mt(0), SCALES.mr(0), SCALES.mb(0), SCALES.ml(0), theme$1.palette.accents_5, bgColor, spaceRatio]]])
  }), /*#__PURE__*/React.createElement("i", {
    className: _JSXStyle.dynamic([["2201634259", [SCALES.font(1), SCALES.width(1, '100%'), SCALES.height(1, '100%'), SCALES.pt(0), SCALES.pr(0), SCALES.pb(0), SCALES.pl(0), SCALES.mt(0), SCALES.mr(0), SCALES.mb(0), SCALES.ml(0), theme$1.palette.accents_5, bgColor, spaceRatio]]])
  }), /*#__PURE__*/React.createElement("i", {
    className: _JSXStyle.dynamic([["2201634259", [SCALES.font(1), SCALES.width(1, '100%'), SCALES.height(1, '100%'), SCALES.pt(0), SCALES.pr(0), SCALES.pb(0), SCALES.pl(0), SCALES.mt(0), SCALES.mr(0), SCALES.mb(0), SCALES.ml(0), theme$1.palette.accents_5, bgColor, spaceRatio]]])
  })), /*#__PURE__*/React.createElement(_JSXStyle, {
    id: "2201634259",
    dynamic: [SCALES.font(1), SCALES.width(1, '100%'), SCALES.height(1, '100%'), SCALES.pt(0), SCALES.pr(0), SCALES.pb(0), SCALES.pl(0), SCALES.mt(0), SCALES.mr(0), SCALES.mb(0), SCALES.ml(0), theme$1.palette.accents_5, bgColor, spaceRatio]
  }, ".loading-container.__jsx-style-dynamic-selector{display:-webkit-inline-box;display:-webkit-inline-flex;display:-ms-inline-flexbox;display:inline-flex;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;position:relative;font-size:".concat(SCALES.font(1), ";width:").concat(SCALES.width(1, '100%'), ";height:").concat(SCALES.height(1, '100%'), ";min-height:1em;padding:").concat(SCALES.pt(0), " ").concat(SCALES.pr(0), " ").concat(SCALES.pb(0), " ").concat(SCALES.pl(0), ";margin:").concat(SCALES.mt(0), " ").concat(SCALES.mr(0), " ").concat(SCALES.mb(0), " ").concat(SCALES.ml(0), ";}label.__jsx-style-dynamic-selector{margin-right:0.5em;color:").concat(theme$1.palette.accents_5, ";line-height:1;}label.__jsx-style-dynamic-selector *{margin:0;}.loading.__jsx-style-dynamic-selector{position:absolute;top:50%;left:50%;width:100%;height:100%;-webkit-transform:translate(-50%,-50%);-ms-transform:translate(-50%,-50%);transform:translate(-50%,-50%);display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-box-pack:center;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;background-color:transparent;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;}i.__jsx-style-dynamic-selector{width:0.25em;height:0.25em;border-radius:50%;background-color:").concat(bgColor, ";margin:0 calc(0.25em / 2 * ").concat(spaceRatio, ");display:inline-block;-webkit-animation:loading-blink-__jsx-style-dynamic-selector 1.4s infinite both;animation:loading-blink-__jsx-style-dynamic-selector 1.4s infinite both;}i.__jsx-style-dynamic-selector:nth-child(2){-webkit-animation-delay:0.2s;animation-delay:0.2s;}i.__jsx-style-dynamic-selector:nth-child(3){-webkit-animation-delay:0.4s;animation-delay:0.4s;}@-webkit-keyframes loading-blink-__jsx-style-dynamic-selector{0%{opacity:0.2;}20%{opacity:1;}100%{opacity:0.2;}}@keyframes loading-blink-__jsx-style-dynamic-selector{0%{opacity:0.2;}20%{opacity:1;}100%{opacity:0.2;}}")));
};
LoadingComponent.displayName = 'Loading';
var Loading = withScale(LoadingComponent);

var _excluded = ["options", "initialValue", "onSelect", "onSearch", "onChange", "searching", "children", "type", "color", "value", "clearable", "disabled", "dropdownClassName", "dropdownStyle", "disableMatchWidth", "disableFreeSolo", "getPopupContainer"];
var childrenToOptionsNode = function childrenToOptionsNode(options) {
  return options.map(function (item, index) {
    var key = "auto-complete-item-".concat(index);
    if (/*#__PURE__*/React.isValidElement(item)) return /*#__PURE__*/React.cloneElement(item, {
      key: key
    });
    var validItem = item;
    return /*#__PURE__*/React.createElement(AutoCompleteItemComponent, {
      key: key,
      value: validItem.value,
      isLabelOnly: true
    }, validItem.label);
  });
};

// When the search is not set, the "clearable" icon can be displayed in the original location.
// When the search is seted, at least one element should exist to avoid re-render.
var getSearchIcon = function getSearchIcon(searching) {
  var scale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
  if (searching === undefined) return null;
  return searching ? /*#__PURE__*/React.createElement(Loading, {
    scale: +scale / 2
  }) : /*#__PURE__*/React.createElement(icons.ArrowRight, null);
};
var AutoCompleteComponent = /*#__PURE__*/React.forwardRef(function (_ref, userRef) {
  var _ref$options = _ref.options,
    options = _ref$options === void 0 ? [] : _ref$options,
    _ref$initialValue = _ref.initialValue,
    customInitialValue = _ref$initialValue === void 0 ? '' : _ref$initialValue,
    onSelect = _ref.onSelect,
    onSearch = _ref.onSearch,
    onChange = _ref.onChange,
    searching = _ref.searching,
    children = _ref.children,
    type = _ref.type,
    color = _ref.color,
    value = _ref.value,
    _ref$clearable = _ref.clearable,
    clearable = _ref$clearable === void 0 ? false : _ref$clearable,
    _ref$disabled = _ref.disabled,
    disabled = _ref$disabled === void 0 ? false : _ref$disabled,
    dropdownClassName = _ref.dropdownClassName,
    dropdownStyle = _ref.dropdownStyle,
    _ref$disableMatchWidt = _ref.disableMatchWidth,
    disableMatchWidth = _ref$disableMatchWidt === void 0 ? false : _ref$disableMatchWidt,
    _ref$disableFreeSolo = _ref.disableFreeSolo,
    disableFreeSolo = _ref$disableFreeSolo === void 0 ? false : _ref$disableFreeSolo,
    getPopupContainer = _ref.getPopupContainer,
    props = _objectWithoutProperties(_ref, _excluded);
  var resetTimer = React.useRef(0); // DEFAULT Value 0
  var _useScale = useScale(),
    SCALES = _useScale.SCALES,
    getScaleProps = _useScale.getScaleProps;
  var ref = React.useRef(null);
  var inputRef = React.useRef(null);
  var _useCurrentState = theme.useCurrentState(customInitialValue),
    _useCurrentState2 = _slicedToArray(_useCurrentState, 3),
    state = _useCurrentState2[0],
    setState = _useCurrentState2[1],
    stateRef = _useCurrentState2[2];
  var _useState = React.useState(customInitialValue),
    _useState2 = _slicedToArray(_useState, 2),
    selectVal = _useState2[0],
    setSelectVal = _useState2[1];
  var _useState3 = React.useState(false),
    _useState4 = _slicedToArray(_useState3, 2),
    visible = _useState4[0],
    setVisible = _useState4[1];
  React.useImperativeHandle(userRef, function () {
    return inputRef.current;
  }); // Chnaged using !

  var _pickChild = pickChild(children, AutoCompleteSearch),
    _pickChild2 = _slicedToArray(_pickChild, 2),
    searchChild = _pickChild2[1];
  var _pickChild3 = pickChild(children, AutoCompleteEmpty),
    _pickChild4 = _slicedToArray(_pickChild3, 2),
    emptyChild = _pickChild4[1];
  var autoCompleteItems = React.useMemo(function () {
    var hasSearchChild = searchChild && React.Children.count(searchChild) > 0;
    var hasEmptyChild = emptyChild && React.Children.count(emptyChild) > 0;
    if (searching) {
      return hasSearchChild ? searchChild : /*#__PURE__*/React.createElement(AutoCompleteSearch, null, "Searching...");
    }
    if (options.length === 0) {
      if (state === '') return null;
      return hasEmptyChild ? emptyChild : /*#__PURE__*/React.createElement(AutoCompleteEmpty, null, "No Options");
    }
    return childrenToOptionsNode(options);
  }, [searching, options]);
  var showClearIcon = React.useMemo(function () {
    return clearable && searching === undefined;
  }, [clearable, searching]);
  var updateValue = function updateValue(val) {
    if (disabled) return;
    setSelectVal(val);
    onSelect && onSelect(val);
    setState(val);
    inputRef.current && inputRef.current.focus();
  };
  var updateVisible = function updateVisible(next) {
    return setVisible(next);
  };
  var onInputChange = function onInputChange(event) {
    setVisible(true);
    onSearch && onSearch(event.target.value);
    setState(event.target.value);
  };
  var resetInputValue = function resetInputValue() {
    if (!disableFreeSolo) return;
    if (!state || state === '') return;
    if (state !== selectVal) {
      setState(selectVal);
    }
  };
  React.useEffect(function () {
    onChange && onChange(state);
  }, [state]);
  React.useEffect(function () {
    if (value === undefined) return;
    var option = options.find(function (opt) {
      return opt.value === value;
    });
    if (option) {
      setState(option.label);
    }
  }, [value]);
  var initialValue = React.useMemo(function () {
    return {
      ref: ref,
      value: state,
      updateValue: updateValue,
      visible: visible,
      updateVisible: updateVisible
    };
  }, [state, visible]);
  var toggleFocusHandler = function toggleFocusHandler(next) {
    clearTimeout(resetTimer.current);
    setVisible(next);
    if (next) {
      onSearch && onSearch(stateRef.current);
    } else {
      resetTimer.current = window.setTimeout(function () {
        resetInputValue();
        clearTimeout(resetTimer.current);
      }, 100);
    }
  };
  var inputProps = _objectSpread2(_objectSpread2({}, props), {}, {
    disabled: disabled,
    value: state
  });
  return /*#__PURE__*/React.createElement(AutoCompleteContext.Provider, {
    value: initialValue
  }, /*#__PURE__*/React.createElement("div", {
    ref: ref,
    className: _JSXStyle.dynamic([["2878925540", [SCALES.width(1, 'max-content'), SCALES.height(1, 'auto'), SCALES.pt(0), SCALES.pr(0), SCALES.pb(0), SCALES.pl(0), SCALES.mt(0), SCALES.mr(0), SCALES.mb(0), SCALES.ml(0)]]]) + " " + "auto-complete"
  }, /*#__PURE__*/React.createElement(Input, _extends({
    fullWidth: true,
    ref: inputRef,
    type: type,
    color: color,
    onChange: onInputChange,
    onFocus: function onFocus() {
      return toggleFocusHandler(true);
    },
    onBlur: function onBlur() {
      return toggleFocusHandler(false);
    },
    clearable: showClearIcon,
    width: SCALES.width(1, 'initial'),
    height: SCALES.height(2.25),
    iconRight: getSearchIcon(searching, getScaleProps('scale'))
  }, inputProps)), /*#__PURE__*/React.createElement(AutoCompleteDropdown, {
    visible: visible,
    disableMatchWidth: disableMatchWidth,
    className: dropdownClassName,
    dropdownStyle: dropdownStyle,
    getPopupContainer: getPopupContainer
  }, autoCompleteItems), /*#__PURE__*/React.createElement(_JSXStyle, {
    id: "2878925540",
    dynamic: [SCALES.width(1, 'max-content'), SCALES.height(1, 'auto'), SCALES.pt(0), SCALES.pr(0), SCALES.pb(0), SCALES.pl(0), SCALES.mt(0), SCALES.mr(0), SCALES.mb(0), SCALES.ml(0)]
  }, ".auto-complete.__jsx-style-dynamic-selector{width:".concat(SCALES.width(1, 'max-content'), ";height:").concat(SCALES.height(1, 'auto'), ";padding:").concat(SCALES.pt(0), " ").concat(SCALES.pr(0), " ").concat(SCALES.pb(0), " ").concat(SCALES.pl(0), ";margin:").concat(SCALES.mt(0), " ").concat(SCALES.mr(0), " ").concat(SCALES.mb(0), " ").concat(SCALES.ml(0), ";}.auto-complete.__jsx-style-dynamic-selector .loading{width:-webkit-max-content;width:-moz-max-content;width:max-content;}"))));
});
AutoCompleteComponent.displayName = 'AutoComplete';
var AutoComplete = withScale(AutoCompleteComponent);

/* "use client" */
AutoComplete.Item = AutoCompleteItemComponent;
AutoComplete.Option = AutoCompleteItemComponent;
AutoComplete.Searching = AutoCompleteSearch;
AutoComplete.Empty = AutoCompleteEmpty;

exports.default = AutoComplete;
