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
});
module.exports = __toCommonJS(Textarea_exports);
var import_react2 = require("react");
var import_clsx2 = __toESM(require("clsx"));

// 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]);
  console.log(timer);
  return { restartTimer, clearTimer, hasActiveTimer: !!timer };
}

// src/util/noop.ts
var noop = () => void 0;

// src/components/user-action/Label.tsx
var import_clsx = __toESM(require("clsx"));
var import_jsx_runtime = require("react/jsx-runtime");
var styleMapping = {
  labelSmall: "textstyle-label-sm",
  labelMedium: "textstyle-label-md",
  labelBig: "textstyle-label-lg"
};
var Label = ({
  children,
  name,
  labelType = "labelSmall",
  className,
  ...props
}) => {
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", { ...props, className: (0, import_clsx.default)(styleMapping[labelType], className), children: children ? children : name });
};

// src/components/user-action/Textarea.tsx
var import_jsx_runtime2 = require("react/jsx-runtime");
var Textarea = ({
  label,
  headline,
  id,
  resizable = false,
  onChange = noop,
  onChangeText = noop,
  disclaimer,
  onBlur = noop,
  onEditCompleted = noop,
  saveDelayOptions,
  defaultStyle = true,
  className,
  ...props
}) => {
  const [hasFocus, setHasFocus] = (0, import_react2.useState)(false);
  const { restartTimer, clearTimer } = useDelay(saveDelayOptions);
  const onEditCompletedWrapper = (text) => {
    onEditCompleted(text);
    clearTimer();
  };
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "w-full", children: [
    label && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
      Label,
      {
        ...label,
        htmlFor: id,
        className: (0, import_clsx2.default)("mb-1", label.className),
        labelType: label.labelType ?? "labelSmall"
      }
    ),
    /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
      "div",
      {
        className: `${(0, import_clsx2.default)(" bg-surface text-on-surface focus-within:border-primary relative", { "shadow border-2 hover:border-primary rounded-lg": defaultStyle })}`,
        children: [
          headline && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "mx-3 mt-3 block textstyle-label-md", children: headline }),
          /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
            "textarea",
            {
              id,
              className: (0, import_clsx2.default)("pt-0 px-3 border-transparent focus:border-transparent focus:ring-0 appearance-none border w-full leading-tight focus:outline-none", {
                "resize-none": !resizable,
                "h-32": defaultStyle,
                "mt-3": !headline
              }, className),
              onChange: (event) => {
                const value = event.target.value;
                restartTimer(() => {
                  onEditCompletedWrapper(value);
                });
                onChange(event);
                onChangeText(value);
              },
              onFocus: () => {
                setHasFocus(true);
              },
              onBlur: (event) => {
                onBlur(event);
                onEditCompletedWrapper(event.target.value);
                setHasFocus(false);
              },
              ...props
            }
          )
        ]
      }
    ),
    hasFocus && disclaimer && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("label", { className: "text-negative", children: disclaimer })
  ] });
};
var TextareaUncontrolled = ({
  value = "",
  onChangeText = noop,
  ...props
}) => {
  const [text, setText] = (0, import_react2.useState)(value);
  (0, import_react2.useEffect)(() => {
    setText(value);
  }, [value]);
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
    Textarea,
    {
      ...props,
      value: text,
      onChangeText: (text2) => {
        setText(text2);
        onChangeText(text2);
      }
    }
  );
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  Textarea,
  TextareaUncontrolled
});
//# sourceMappingURL=Textarea.js.map