var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/components/user-action/Textarea.tsx
var Textarea_exports = {};
__export(Textarea_exports, {
  Textarea: () => Textarea,
  TextareaUncontrolled: () => TextareaUncontrolled,
  TextareaWithHeadline: () => TextareaWithHeadline
});
module.exports = __toCommonJS(Textarea_exports);
var import_react3 = require("react");
var import_clsx2 = __toESM(require("clsx"), 1);

// src/components/user-action/Label.tsx
var import_clsx = __toESM(require("clsx"), 1);
var import_jsx_runtime = require("react/jsx-runtime");
var styleMapping = {
  md: "typography-label-md color-label-text",
  lg: "typography-label-lg color-label-text"
};
var Label = ({
  children,
  size = "md",
  className,
  ...props
}) => {
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", { ...props, className: (0, import_clsx.default)(styleMapping[size], className), children });
};

// src/hooks/useDelay.ts
var import_react = require("react");
var defaultOptions = {
  delay: 3e3,
  disabled: false
};
function useDelay(options) {
  const [timer, setTimer] = (0, import_react.useState)(void 0);
  const { delay, disabled } = {
    ...defaultOptions,
    ...options
  };
  const clearTimer = () => {
    clearTimeout(timer);
    setTimer(void 0);
  };
  const restartTimer = (onDelayFinish) => {
    if (disabled) {
      return;
    }
    clearTimeout(timer);
    setTimer(setTimeout(() => {
      onDelayFinish();
      setTimer(void 0);
    }, delay));
  };
  (0, import_react.useEffect)(() => {
    return () => {
      clearTimeout(timer);
    };
  }, [timer]);
  (0, import_react.useEffect)(() => {
    if (disabled) {
      clearTimeout(timer);
      setTimer(void 0);
    }
  }, [disabled, timer]);
  return { restartTimer, clearTimer, hasActiveTimer: !!timer };
}

// src/hooks/useOverwritableState.ts
var import_react2 = require("react");

// src/utils/resolveSetState.ts
function resolveSetState(action, prev) {
  return typeof action === "function" ? action(prev) : action;
}

// src/hooks/useOverwritableState.ts
var useOverwritableState = (initialValue, onChange) => {
  const [state, setState] = (0, import_react2.useState)(initialValue);
  (0, import_react2.useEffect)(() => {
    setState(initialValue);
  }, [initialValue]);
  const onChangeWrapper = (action) => {
    const resolved = resolveSetState(action, state);
    setState(resolved);
    onChange?.(state);
  };
  return [state, onChangeWrapper];
};

// src/components/user-action/Textarea.tsx
var import_jsx_runtime2 = require("react/jsx-runtime");
var Textarea = (0, import_react3.forwardRef)(function Textarea2({
  id,
  onChange,
  onChangeText,
  onBlur,
  onEditCompleted,
  saveDelayOptions,
  defaultStyle = true,
  invalid = false,
  disabled = false,
  className,
  ...props
}, ref) {
  const { restartTimer, clearTimer } = useDelay(saveDelayOptions);
  const onEditCompletedWrapper = (text) => {
    onEditCompleted?.(text);
    clearTimer();
  };
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
    "textarea",
    {
      ref,
      id,
      className: (0, import_clsx2.default)(
        "resize-none w-full h-32 overflow-y-scroll",
        "py-2 px-3 rounded-md border-2 border-transparent focus-style-none",
        {
          "bg-input-background text-input-text hover:border-primary focus:border-primary": !disabled && !invalid,
          "bg-negative/20 text-negative hover:border-negative focus-visible:border-negative": invalid && !disabled && defaultStyle,
          "text-disabled bg-disabled-background border-disabled-border": disabled && defaultStyle
        },
        className
      ),
      onChange: (event) => {
        const value = event.target.value;
        restartTimer(() => {
          onEditCompletedWrapper(value);
        });
        onChange?.(event);
        onChangeText?.(value);
      },
      onBlur: (event) => {
        onBlur?.(event);
        onEditCompletedWrapper(event.target.value);
      },
      disabled,
      ...props
    }
  );
});
var TextareaUncontrolled = ({
  value,
  onChangeText,
  ...props
}) => {
  const [text, setText] = useOverwritableState(value, onChangeText);
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
    Textarea,
    {
      ...props,
      value: text,
      onChangeText: setText
    }
  );
};
var TextareaWithHeadline = ({
  id,
  headline,
  headlineProps,
  disabled,
  className,
  containerClassName,
  ...props
}) => {
  const genId = (0, import_react3.useId)();
  const usedId = id ?? genId;
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
    "div",
    {
      className: (0, import_clsx2.default)(
        "group flex-col-3 border-2 rounded-lg",
        {
          "bg-input-background text-input-text hover:border-primary focus-within:border-primary": !disabled,
          "border-disabled-border bg-disabled-background cursor-not-allowed": disabled
        },
        containerClassName
      ),
      children: [
        headline && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Label, { size: "md", ...headlineProps, htmlFor: usedId, children: headline }),
        /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
          Textarea,
          {
            ...props,
            id: usedId,
            className: (0, import_clsx2.default)(
              "border-transparent focus:ring-0 focus-visible:ring-0 resize-none h-32",
              className
            ),
            defaultStyle: false
          }
        )
      ]
    }
  );
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  Textarea,
  TextareaUncontrolled,
  TextareaWithHeadline
});
//# sourceMappingURL=Textarea.cjs.map