"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __getProtoOf = Object.getPrototypeOf;
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;
};
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/molecules/dynamic-field.tsx
var dynamic_field_exports = {};
__export(dynamic_field_exports, {
  DynamicFormField: () => DynamicFormField
});
module.exports = __toCommonJS(dynamic_field_exports);

// src/context/dynamic-form-context.tsx
var import_react4 = require("react");

// src/molecules/form/form.tsx
var RadixForm = __toESM(require("@radix-ui/react-form"), 1);
var import_react3 = require("react");

// src/atoms/heading.tsx
var import_themes = require("@radix-ui/themes");
var import_react = require("react");

// src/utils/map-with-responsive.ts
var mapWithResponsive = (args) => {
  const { value, mapFn } = args;
  if (typeof value === "string") {
    return mapFn(value);
  }
  ;
  if (typeof value === "object") {
    const newObj = {};
    let key;
    for (key in value) {
      newObj[key] = mapFn(value[key]);
    }
    return newObj;
  }
  return value;
};

// src/atoms/heading.tsx
var import_themes2 = require("@radix-ui/themes");
var import_jsx_runtime = require("react/jsx-runtime");
var mapVariant = (variant) => {
  switch (variant) {
    case "heading1":
      return "7";
    case "heading2":
      return "6";
    case "heading3":
      return "5";
    case "heading4":
      return "4";
    case "heading5":
      return "3";
    default:
      return void 0;
  }
};
function Heading2(props) {
  const _a = props, { size, children, variant } = _a, rest = __objRest(_a, ["size", "children", "variant"]);
  const radixSize = (0, import_react.useMemo)(() => {
    return variant ? mapWithResponsive({
      value: variant,
      mapFn: mapVariant
    }) : size;
  }, [size, variant]);
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_themes.Heading, __spreadProps(__spreadValues({}, rest), { size: radixSize, children }));
}

// src/atoms/typo.tsx
var import_themes3 = require("@radix-ui/themes");
var import_react2 = require("react");
var import_jsx_runtime2 = require("react/jsx-runtime");
var Typo = (0, import_react2.forwardRef)(
  (props, ref) => {
    const _a = props, { size, variant, children } = _a, rest = __objRest(_a, ["size", "variant", "children"]);
    const radixSize = (0, import_react2.useMemo)(() => {
      if (size !== void 0) return size;
      if (variant === void 0) return "2";
      return mapWithResponsive({
        value: variant,
        mapFn: (variantValue) => {
          switch (variantValue) {
            case "caption":
              return "1";
            case "subtitle":
              return "3";
            case "body":
            default:
              return "2";
          }
        }
      });
    }, [size, variant]);
    return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_themes3.Text, __spreadProps(__spreadValues({}, rest), { ref, size: radixSize, children }));
  }
);
Typo.displayName = "Typo";

// src/molecules/form/form.tsx
var import_jsx_runtime3 = require("react/jsx-runtime");
var Root2 = (0, import_react3.forwardRef)(
  (_a, ref) => {
    var _b = _a, { children, className } = _b, rest = __objRest(_b, ["children", "className"]);
    return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
      RadixForm.Root,
      __spreadProps(__spreadValues({}, rest), {
        className: `FormRoot ${className || ""}`,
        ref,
        children
      })
    );
  }
);
Root2.displayName = "FORM_ROOT";
var FieldContext = (0, import_react3.createContext)({
  name: ""
});
var Field2 = (0, import_react3.forwardRef)(
  (_a, ref) => {
    var _b = _a, { children, className } = _b, rest = __objRest(_b, ["children", "className"]);
    return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
      RadixForm.Field,
      __spreadProps(__spreadValues({}, rest), {
        className: `FormField ${className || ""}`,
        ref,
        children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(FieldContext.Provider, { value: rest, children })
      })
    );
  }
);
Field2.displayName = "FORM_FIELD";
function HeadingLabel(props) {
  return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Heading2, __spreadProps(__spreadValues({ variant: "heading5" }, props), { children: props.children }));
}
function CaptionLabel(props) {
  return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Typo, __spreadProps(__spreadValues({ color: "gray", variant: "caption" }, props), { children: props.children }));
}
var Label2 = (0, import_react3.forwardRef)(
  (_a, ref) => {
    var _b = _a, { children, className, variant } = _b, rest = __objRest(_b, ["children", "className", "variant"]);
    const Comp = (0, import_react3.useMemo)(() => {
      switch (variant) {
        case "title":
          return HeadingLabel;
        case "caption":
          return CaptionLabel;
        case "body":
        default:
          return Typo;
      }
    }, [variant]);
    const fieldProps = (0, import_react3.useContext)(FieldContext);
    return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
      RadixForm.Label,
      __spreadProps(__spreadValues({}, rest), {
        asChild: true,
        className: `FormLabel ${className || ""}`,
        ref,
        children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Comp, { children: [
          children,
          fieldProps.required ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Typo, { as: "span", color: "tomato", children: ` *` }) : null
        ] })
      })
    );
  }
);
Label2.displayName = "FORM_Label";
var Message2 = (0, import_react3.forwardRef)(
  (_a, ref) => {
    var _b = _a, { children, className } = _b, rest = __objRest(_b, ["children", "className"]);
    return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
      RadixForm.Message,
      __spreadProps(__spreadValues({}, rest), {
        asChild: true,
        className: `FormMessage ${className || ""}`,
        ref,
        children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Typo, { color: "red", children })
      })
    );
  }
);
Message2.displayName = "FORM_Message";
var Control2 = (0, import_react3.forwardRef)(
  (_a, ref) => {
    var _b = _a, { className } = _b, rest = __objRest(_b, ["className"]);
    const fieldProps = (0, import_react3.useContext)(FieldContext);
    return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
      RadixForm.Control,
      __spreadProps(__spreadValues({}, rest), {
        className: `FormControl ${className || ""}`,
        ref,
        required: fieldProps.required
      })
    );
  }
);
Control2.displayName = "FORM_Control";

// src/context/dynamic-form-context.tsx
var import_jsx_runtime4 = require("react/jsx-runtime");
var DynamicFormContext = (0, import_react4.createContext)(null);
function useDynamicForm() {
  const context = (0, import_react4.useContext)(DynamicFormContext);
  if (!context) {
    throw new Error("useDynamicForm must be used within a DynamicFormProvider");
  }
  return context;
}

// src/atoms/text-field.tsx
var import_themes4 = require("@radix-ui/themes");
var import_react5 = require("react");
var import_jsx_runtime5 = require("react/jsx-runtime");
var Root3 = (0, import_react5.forwardRef)((props, ref) => {
  const _a = props, { error, style, className } = _a, rest = __objRest(_a, ["error", "style", "className"]);
  const fieldStyle = (0, import_react5.useMemo)(() => {
    if (!error) return style;
    const errorStyle = {
      boxShadow: "inset 0 0 0 var(--text-field-border-width) var(--error-11)"
    };
    return __spreadValues(__spreadValues({}, style || {}), errorStyle);
  }, [error, style]);
  const classNameStr = error ? `error ${className}` : className;
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
    import_themes4.TextField.Root,
    __spreadValues({
      className: classNameStr,
      ref,
      style: fieldStyle
    }, rest)
  );
});
Root3.displayName = "TextField.Root";
var TextField = { Root: Root3, Slot: import_themes4.TextField.Slot };

// src/atoms/text-area.tsx
var import_themes5 = require("@radix-ui/themes");
var import_react6 = require("react");
var import_jsx_runtime6 = require("react/jsx-runtime");
var TextArea = (0, import_react6.forwardRef)(
  (props, ref) => {
    const _a = props, { error, style, className } = _a, rest = __objRest(_a, ["error", "style", "className"]);
    const fieldStyle = (0, import_react6.useMemo)(() => {
      if (!error) return style;
      const errorStyle = {
        boxShadow: "inset 0 0 0 var(--text-area-border-width) var(--error-11)"
      };
      return __spreadValues(__spreadValues({}, style || {}), errorStyle);
    }, [error, style]);
    const classNameStr = error ? `error ${className}` : className;
    return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
      import_themes5.TextArea,
      __spreadProps(__spreadValues({}, rest), {
        className: classNameStr,
        ref,
        style: fieldStyle
      })
    );
  }
);
TextArea.displayName = "TextArea";

// src/atoms/select.tsx
var import_themes6 = require("@radix-ui/themes");
var import_react7 = require("react");
var import_jsx_runtime7 = require("react/jsx-runtime");
var SelectContext = (0, import_react7.createContext)({
  error: false
});
var Content = (0, import_react7.forwardRef)((props, ref) => {
  const _a = props, { className, isNavigation } = _a, rest = __objRest(_a, ["className", "isNavigation"]);
  const { error } = (0, import_react7.useContext)(SelectContext);
  const cls = (0, import_react7.useMemo)(() => {
    const etc = isNavigation ? "nav-select" : "";
    const errorCls = error ? "tipp-error" : "";
    return [etc, errorCls, className].join(" ");
  }, [className, error, isNavigation]);
  return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
    import_themes6.Select.Content,
    __spreadProps(__spreadValues({
      position: "popper"
    }, rest), {
      className: cls,
      ref
    })
  );
});
Content.displayName = "Select.Content";
var Trigger = (0, import_react7.forwardRef)(
  (props, ref) => {
    const _a = props, { className } = _a, rest = __objRest(_a, ["className"]);
    const { error } = (0, import_react7.useContext)(SelectContext);
    const cls = (0, import_react7.useMemo)(() => {
      const errorCls = error ? "error" : "";
      return [errorCls, className].join(" ");
    }, [className, error]);
    return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_themes6.Select.Trigger, __spreadProps(__spreadValues({}, rest), { className: cls, ref }));
  }
);
Trigger.displayName = "Select.Trigger";
function Root4(props) {
  const _a = props, { error } = _a, rest = __objRest(_a, ["error"]);
  return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(SelectContext.Provider, { value: { error }, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_themes6.Select.Root, __spreadValues({}, rest)) });
}
Root4.displayName = "Select.Root";
var Select = __spreadProps(__spreadValues({}, import_themes6.Select), {
  Root: Root4,
  Trigger,
  Content
});

// src/atoms/check-box-group.tsx
var import_themes7 = require("@radix-ui/themes");
var import_react8 = require("react");
var import_jsx_runtime8 = require("react/jsx-runtime");
var Root5 = (0, import_react8.forwardRef)((props, ref) => {
  const _a = props, { children, size = "medium" } = _a, rest = __objRest(_a, ["children", "size"]);
  const groupSize = (0, import_react8.useMemo)(() => {
    switch (size) {
      case "small":
        return "1";
      case "large":
        return "3";
      case "medium":
      default:
        return "2";
    }
  }, [size]);
  return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_themes7.CheckboxGroup.Root, __spreadProps(__spreadValues({}, rest), { ref, size: groupSize, children }));
});
Root5.displayName = "CheckboxGroup.Root";
var CheckboxGroup = {
  Root: Root5,
  Item: import_themes7.CheckboxGroup.Item
};

// src/atoms/radio-group.tsx
var import_themes8 = require("@radix-ui/themes");

// src/atoms/check-box.tsx
var import_themes9 = require("@radix-ui/themes");
var import_react9 = require("react");
var import_jsx_runtime9 = require("react/jsx-runtime");
var Checkbox = (0, import_react9.forwardRef)(
  (props, ref) => {
    const _a = props, { size = "medium" } = _a, rest = __objRest(_a, ["size"]);
    const radixSize = (0, import_react9.useMemo)(() => {
      switch (size) {
        case "small":
          return "1";
        case "medium":
          return "2";
        case "large":
          return "3";
      }
    }, [size]);
    return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_themes9.Checkbox, __spreadProps(__spreadValues({}, rest), { ref, size: radixSize }));
  }
);
Checkbox.displayName = "Checkbox";

// src/molecules/dynamic-field.tsx
var import_jsx_runtime10 = require("react/jsx-runtime");
function DynamicFormField({
  field
}) {
  const {
    getFieldValue,
    getFieldError,
    getFieldTouched,
    setFieldValue,
    handleChange,
    handleBlur
  } = useDynamicForm();
  const { name, type } = field;
  const value = getFieldValue(name);
  const error = getFieldError(name);
  const touched = getFieldTouched(name);
  const hasError = Boolean(error && touched);
  const commonProps = {
    name,
    value: String(value || ""),
    onChange: handleChange,
    onBlur: handleBlur,
    error: hasError
  };
  switch (type) {
    case "short_text":
    case "email":
      return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
        TextField.Root,
        __spreadProps(__spreadValues({}, commonProps), {
          placeholder: field.placeholder,
          type: type === "short_text" ? "text" : type
        })
      );
    case "number":
      return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
        TextField.Root,
        __spreadProps(__spreadValues({}, commonProps), {
          inputMode: "numeric",
          pattern: "[0-9]*",
          placeholder: field.placeholder,
          type: "number"
        })
      );
    case "long_text":
      return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(TextArea, __spreadProps(__spreadValues({}, commonProps), { placeholder: field.placeholder, rows: 4 }));
    case "dropdown":
      return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
        Select.Root,
        {
          onValueChange: (newValue) => {
            void setFieldValue(name, newValue);
          },
          value,
          children: [
            /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(Select.Trigger, { placeholder: field.placeholder }),
            /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(Select.Content, { children: field.options.map((option) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(Select.Item, { value: String(option.value), children: option.label }, option.value)) })
          ]
        }
      );
    case "choice":
      return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
        import_themes8.RadioGroup.Root,
        {
          onValueChange: (newValue) => {
            void setFieldValue(name, newValue);
          },
          orientation: field.orientation,
          value: String(value || ""),
          children: field.options.map((option) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_themes8.RadioGroup.Item, { value: String(option.value), children: option.label }, option.value))
        }
      );
    case "choices":
      return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
        CheckboxGroup.Root,
        {
          onValueChange: (newValue) => {
            void setFieldValue(name, newValue);
          },
          orientation: field.orientation,
          value: Array.isArray(value) ? value.map(String) : [],
          children: field.options.map((option) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(CheckboxGroup.Item, { value: String(option.value), children: option.label }, option.value))
        }
      );
    case "yes_no":
      return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { style: { display: "flex", alignItems: "flex-start", gap: "8px" }, children: [
        /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
          Checkbox,
          {
            checked: Boolean(value),
            onCheckedChange: (checked) => {
              void setFieldValue(name, checked);
            }
          }
        ),
        field.description ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { style: { fontSize: "14px", color: "#666", lineHeight: "1.4" }, children: field.description }) : null
      ] });
    default:
      return null;
  }
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  DynamicFormField
});
//# sourceMappingURL=dynamic-field.cjs.map