import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
import { FormControl, Stack, Flex, HStack, FormLabel, Tooltip, FormErrorMessage, FormHelperText, Box } from '@chakra-ui/react';
import { QuestionOutlineIcon } from '@chakra-ui/icons';

var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
  for (var prop in b || (b = {}))
    if (__hasOwnProp.call(b, prop))
      __defNormalProp(a, prop, b[prop]);
  if (__getOwnPropSymbols)
    for (var prop of __getOwnPropSymbols(b)) {
      if (__propIsEnum.call(b, prop))
        __defNormalProp(a, prop, b[prop]);
    }
  return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
var __objRest = (source, exclude) => {
  var target = {};
  for (var prop in source)
    if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
      target[prop] = source[prop];
  if (source != null && __getOwnPropSymbols)
    for (var prop of __getOwnPropSymbols(source)) {
      if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
        target[prop] = source[prop];
    }
  return target;
};
function FormField(_a) {
  var _b = _a, {
    children,
    label,
    tooltip,
    description,
    footerDescription,
    isInvalid,
    helpText,
    errorText,
    _label,
    _help,
    _error,
    isRequired,
    showRequiredIndicator = true
  } = _b, props = __objRest(_b, [
    "children",
    "label",
    "tooltip",
    "description",
    "footerDescription",
    "isInvalid",
    "helpText",
    "errorText",
    "_label",
    "_help",
    "_error",
    "isRequired",
    "showRequiredIndicator"
  ]);
  var _a2, _b2;
  const isSwitch = ((_b2 = (_a2 = children == null ? void 0 : children.type) == null ? void 0 : _a2.render) == null ? void 0 : _b2.displayName) === "Switch";
  const descriptionComponent = description ? /* @__PURE__ */ jsx(Box, { fontSize: "sm", mb: "2", mt: "-1", children: description }) : null;
  const footerDescriptionComponent = footerDescription ? /* @__PURE__ */ jsx(Box, { fontSize: "sm", mb: "-1", mt: "3", children: footerDescription }) : null;
  return /* @__PURE__ */ jsxs(
    FormControl,
    __spreadProps(__spreadValues({
      isInvalid,
      isRequired: showRequiredIndicator ? isRequired : false,
      "aria-required": isRequired
    }, props), {
      children: [
        isSwitch ? /* @__PURE__ */ jsxs(Stack, { spacing: 1, children: [
          /* @__PURE__ */ jsxs(Flex, { alignItems: "center", gap: 3, children: [
            children,
            /* @__PURE__ */ jsxs(HStack, { children: [
              /* @__PURE__ */ jsx(FormLabel, __spreadProps(__spreadValues({}, _label), { mb: 0.25, mr: 0, children: label })),
              tooltip ? /* @__PURE__ */ jsx(Tooltip, { label: tooltip, children: /* @__PURE__ */ jsx(QuestionOutlineIcon, { boxSize: "3" }) }) : null
            ] })
          ] }),
          descriptionComponent
        ] }) : /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsxs(Stack, { spacing: 1, children: [
          /* @__PURE__ */ jsxs(HStack, { children: [
            /* @__PURE__ */ jsx(FormLabel, __spreadProps(__spreadValues({}, _label), { mb: 0.25, mr: 0, children: label })),
            tooltip ? /* @__PURE__ */ jsx(Tooltip, { label: tooltip, children: /* @__PURE__ */ jsx(QuestionOutlineIcon, { boxSize: "3" }) }) : null
          ] }),
          descriptionComponent,
          children,
          footerDescriptionComponent
        ] }) }),
        isInvalid ? /* @__PURE__ */ jsx(FormErrorMessage, __spreadProps(__spreadValues({}, _error), { children: errorText || `Field has an error` })) : helpText ? /* @__PURE__ */ jsx(FormHelperText, __spreadProps(__spreadValues({}, _help), { children: helpText })) : null
      ]
    })
  );
}

export { FormField as default };
//# sourceMappingURL=FormField.js.map
