import { _ as _extends } from '../extends-C4cduGrv.js';
import { _ as _defineProperty } from '../defineProperty-CEd-kZQW.js';
import { _ as _objectWithoutProperties } from '../objectWithoutProperties-TXwlfNxG.js';
import React__default from 'react';
import cx from 'classnames';
import PropTypes from 'prop-types';
import Stack from '../stack/index.js';
import Label from '../label/index.js';
import CKIcon from '../ck-icon/index.js';
import Text from '../text/index.js';
import '@reach/visually-hidden';
import '../ck-icon/assets/icon-map/index.js';
import '../icon/index.js';
import '@fortawesome/react-fontawesome';
import '../icon/icons.js';
import '../icon/library.js';
import '@fortawesome/fontawesome-svg-core';
import '@fortawesome/pro-solid-svg-icons';
import '@fortawesome/pro-light-svg-icons';
import '@fortawesome/free-brands-svg-icons';

var _excluded = ["state", "className", "disabled", "style", "resize", "info", "message", "label"];

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

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
var STATES = {
  "default": {
    inputClasses: "border border-gray-200 focus:outline-none focus:border-blue-500 focus:ring-0 hover:border-gray-300"
  },
  error: {
    inputClasses: "border-red-600 outline-red",
    icon: "alert-circle",
    iconColor: "text-red-600"
  },
  success: {
    inputClasses: "border-green-600 outline-green",
    icon: "check-circle",
    iconColor: "text-green-600"
  }
};
var Textarea = /*#__PURE__*/React__default.forwardRef(function (_ref, ref) {
  var _ref$state = _ref.state,
      state = _ref$state === void 0 ? "default" : _ref$state,
      className = _ref.className,
      _ref$disabled = _ref.disabled,
      disabled = _ref$disabled === void 0 ? false : _ref$disabled,
      style = _ref.style,
      _ref$resize = _ref.resize,
      resize = _ref$resize === void 0 ? "none" : _ref$resize,
      info = _ref.info,
      message = _ref.message,
      label = _ref.label,
      props = _objectWithoutProperties(_ref, _excluded);

  var stateName = typeof state === "string" ? state : (state === null || state === void 0 ? void 0 : state.name) || "default";
  var stateMessage = state === null || state === void 0 ? void 0 : state.message;
  className = cx({
    "bg-gray-50, select-none": disabled
  }, className, getResize(resize), "text-sm leading-5 px-3 py-2 w-full rounded", STATES[stateName].inputClasses);
  return /*#__PURE__*/React__default.createElement(Stack, {
    spacing: 2
  }, label && /*#__PURE__*/React__default.createElement("div", {
    className: "flex justify-between"
  }, /*#__PURE__*/React__default.createElement(Label, {
    htmlFor: props.id
  }, label), info && /*#__PURE__*/React__default.createElement(Text, {
    size: "sm",
    className: "text-gray-700 leading-5"
  }, info)), /*#__PURE__*/React__default.createElement("textarea", _extends({}, props, {
    id: props.id,
    ref: ref,
    style: _objectSpread(_objectSpread({}, style), {}, {
      transition: "border-color 0.3s",
      resize: resize
    }),
    className: className,
    disabled: disabled
  })), stateMessage && /*#__PURE__*/React__default.createElement("div", {
    className: "flex items-center gap-1"
  }, STATES[stateName].icon && /*#__PURE__*/React__default.createElement(CKIcon, {
    name: STATES[stateName].icon,
    className: STATES[stateName].iconColor
  }), /*#__PURE__*/React__default.createElement(Text, {
    size: "sm",
    className: "text-black"
  }, stateMessage)), message && /*#__PURE__*/React__default.createElement(Text, {
    size: "sm",
    className: "text-gray-700 leading-5"
  }, message));
});

function getResize(resize) {
  switch (resize) {
    case "none":
      return "resize-none";

    case "both":
      return "resize";

    case "vertical":
      return "resize-y";

    case "horizontal":
      return "resize-x";

    default:
      return "resize-none";
  }
}

Textarea.propTypes = {
  /**
   * State for the Textarea can be one of the following: "default", "error", or "success". It can also be an object with the following properties: `name` and `message`.
   */
  state: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
  className: PropTypes.string,
  id: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
  style: PropTypes.object,
  disabled: PropTypes.oneOfType([PropTypes.bool, PropTypes.func]),
  resize: PropTypes.string,
  rows: PropTypes.number,
  placeholder: PropTypes.string,
  onChange: PropTypes.func,
  value: PropTypes.string,

  /**
   * Text (or an element) placed below the textarea box on the left.
   */
  message: PropTypes.string,
  label: PropTypes.oneOfType([PropTypes.string, PropTypes.element]),

  /**
   * Text (or an element) placed on the right side of the label.
   */
  info: PropTypes.oneOfType([PropTypes.string, PropTypes.element])
};

export { Textarea as default };
