"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }"use client";












var _chunkQAQ7AROScjs = require('./chunk-QAQ7AROS.cjs');



var _chunkQLWBBCI5cjs = require('./chunk-QLWBBCI5.cjs');


var _chunk6JINAOI7cjs = require('./chunk-6JINAOI7.cjs');


var _chunkJMU4RU5Jcjs = require('./chunk-JMU4RU5J.cjs');


var _chunkN5UOJC3Vcjs = require('./chunk-N5UOJC3V.cjs');

// src/components/contact/contact-form.tsx
var _react = require('react');
var _reacthookform = require('react-hook-form');
var _zod = require('@hookform/resolvers/zod');

// src/schemas/contact-schema.ts
var _zod3 = require('zod');
var companySizeOptions = [
  "1-10",
  "11-50",
  "51-200",
  "201-500",
  "501-1000",
  "1001+"
];
var referralSourceOptions = [
  "Google",
  "LinkedIn",
  "Twitter/X",
  "Reddit",
  "Friend / Colleague",
  "Other"
];
var defaultHelpCategoryOptions = [
  "Open-Source Alternatives",
  "Vendor Cost Reduction",
  "MSP Best Practices",
  "Partnerships",
  "Press",
  "Other"
];
var LinkedInUrlSchema = _zod3.z.string().url({ message: "Please enter a valid LinkedIn URL" }).refine(
  (url) => {
    try {
      const host = new URL(url).hostname.toLowerCase();
      return host === "linkedin.com" || host.endsWith(".linkedin.com");
    } catch (e) {
      return false;
    }
  },
  {
    message: "Please enter a valid LinkedIn profile URL"
  }
).optional().or(_zod3.z.literal(""));
var ContactBaseSchema = _zod3.z.object({
  name: _zod3.z.string().min(2, { message: "Name must be at least 2 characters" }).max(255, { message: "Name is too long" }),
  email: _zod3.z.string().email({ message: "Please enter a valid email address" }).max(255),
  linkedin_url: LinkedInUrlSchema,
  helpCategory: _zod3.z.string().min(1, { message: "Please select what we can help you with" }).max(255, { message: "Help category is too long" }),
  message: _zod3.z.string().min(10, { message: "Message must be at least 10 characters" }).max(5e3, { message: "Message is too long (5,000 character limit)" }),
  rdt_cid: _zod3.z.string().optional()
});
var ContactSchema = ContactBaseSchema.extend({
  companySize: _zod3.z.string().optional().refine((val) => !val || companySizeOptions.includes(val), {
    message: "Please select a valid company size"
  }),
  referralSource: _zod3.z.string().optional().refine((val) => !val || referralSourceOptions.includes(val), {
    message: "Please select a valid referral source"
  })
});

// src/components/contact/contact-form.tsx
var _jsxruntime = require('react/jsx-runtime');
function ContactForm({
  userId,
  helpCategoryOptions = defaultHelpCategoryOptions,
  rdtCid,
  onSubmitSuccess,
  prefilledReason,
  prefilledMessage,
  hideFields = [],
  defaultValues: defaultValuesProp,
  onCustomSubmit,
  extraTopField,
  attachmentsEnabled = false,
  title = "Hit Us Up",
  subtitle,
  footerText = "We typically respond within 24 hours. We respect your privacy \u2013 no spam, ever.",
  noBorder = false,
  noPadding = false,
  buttonVariant = "accent",
  buttonClassName = "",
  submitLabel = "Send Message",
  submitSuccessLabel = "Message Sent!",
  successRedirectUrl = "/blog#community",
  successToastMessage = "Redirecting you to join our community..."
} = {}) {
  const attachments = _chunkQAQ7AROScjs.useChatAttachments.call(void 0, );
  const builtInSubmission = _chunkQLWBBCI5cjs.useContactSubmission.call(void 0, {
    userId,
    successRedirectUrl,
    successToastMessage
  });
  const [customSubmitting, setCustomSubmitting] = _react.useState.call(void 0, false);
  const { honeypotInputProps, getSignals, resetSignals } = _chunkQLWBBCI5cjs.useHumanitySignals.call(void 0, );
  const isSubmitting = onCustomSubmit ? customSubmitting : builtInSubmission.isSubmitting;
  const isSuccess = onCustomSubmit ? false : builtInSubmission.isSuccess;
  const {
    register,
    handleSubmit,
    control,
    formState: { errors },
    reset
  } = _reacthookform.useForm.call(void 0, {
    resolver: _zod.zodResolver.call(void 0, ContactSchema),
    defaultValues: {
      ...prefilledReason && { helpCategory: prefilledReason },
      ...prefilledMessage && { message: prefilledMessage },
      // Caller-supplied defaults win over the legacy `prefilled*` props
      // (they're the authoritative seed for hidden fields).
      ...defaultValuesProp
    }
  });
  const handleFormSubmit = async (data) => {
    if (isSubmitting) return;
    if (attachmentsEnabled && attachments.hasInflightUploads) return;
    try {
      const payload = { ...data, ...rdtCid && { rdt_cid: rdtCid }, ...getSignals() };
      const readyAttachments = attachmentsEnabled ? attachments.readyAttachments : [];
      if (onCustomSubmit) {
        setCustomSubmitting(true);
        try {
          await onCustomSubmit(payload, readyAttachments);
        } finally {
          setCustomSubmitting(false);
        }
      } else {
        await builtInSubmission.submit(payload);
      }
      _optionalChain([onSubmitSuccess, 'optionalCall', _ => _()]);
      reset();
      resetSignals();
      if (attachmentsEnabled) attachments.clear();
    } catch (e2) {
    }
  };
  const showName = !hideFields.includes("name");
  const showEmail = !hideFields.includes("email");
  const showNameEmailRow = showName || showEmail;
  const showCompanySize = !hideFields.includes("companySize");
  const showReferralSource = !hideFields.includes("referralSource");
  const showHelpCategory = !hideFields.includes("helpCategory");
  const showMessage = !hideFields.includes("message");
  return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, 
    "div",
    {
      className: `h-full flex flex-col ${!noBorder ? "border border-ods-border rounded-2xl md:rounded-3xl" : ""} ${!noPadding ? "p-6 md:p-8 lg:p-10" : ""}`,
      children: [
        (title || subtitle) && /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "mb-6 md:mb-8", children: [
          title && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "h2", { className: `${_chunkJMU4RU5Jcjs.SECTION_HEADING_CLASS} mb-3 md:mb-4`, children: title }),
          subtitle && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "p", { className: "font-['DM_Sans'] font-medium text-[16px] md:text-[18px] leading-[24px] text-ods-text-primary", children: subtitle })
        ] }),
        /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, 
          "form",
          {
            onSubmit: handleSubmit(handleFormSubmit, (validationErrors) => {
              console.warn(
                "[ContactForm] submit blocked by validation:",
                Object.fromEntries(
                  Object.entries(validationErrors).map(([k, v]) => [k, _nullishCoalesce(_optionalChain([v, 'optionalAccess', _2 => _2.message]), () => ( v))])
                )
              );
            }),
            className: "flex flex-col flex-grow space-y-4 md:space-y-6",
            children: [
              !showName && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "input", { type: "hidden", ...register("name") }),
              !showEmail && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "input", { type: "hidden", ...register("email") }),
              !showHelpCategory && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "input", { type: "hidden", ...register("helpCategory") }),
              !showMessage && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "input", { type: "hidden", ...register("message") }),
              /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkQAQ7AROScjs.HoneypotField, { ...honeypotInputProps }),
              extraTopField,
              showNameEmailRow && /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4 md:gap-6", children: [
                showName && /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex flex-col", children: [
                  /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkQAQ7AROScjs.Label, { htmlFor: "name", children: [
                    "Your Name",
                    /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "text-ods-accent", children: "*" })
                  ] }),
                  /* @__PURE__ */ _jsxruntime.jsx.call(void 0, 
                    _chunk6JINAOI7cjs.Input,
                    {
                      id: "name",
                      type: "text",
                      ...register("name"),
                      placeholder: "Jane Doe",
                      "aria-invalid": !!errors.name,
                      "aria-describedby": "name-error",
                      className: "bg-ods-card border-ods-border text-ods-text-primary placeholder-ods-text-secondary px-3 h-12"
                    }
                  ),
                  errors.name && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { id: "name-error", className: "text-ods-error text-xs font-['DM_Sans'] mt-1", children: errors.name.message })
                ] }),
                showEmail && /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex flex-col", children: [
                  /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkQAQ7AROScjs.Label, { htmlFor: "email", children: [
                    "Email",
                    /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "text-ods-accent", children: "*" })
                  ] }),
                  /* @__PURE__ */ _jsxruntime.jsx.call(void 0, 
                    _chunk6JINAOI7cjs.Input,
                    {
                      id: "email",
                      type: "email",
                      ...register("email"),
                      placeholder: "jane@company.com",
                      "aria-invalid": !!errors.email,
                      "aria-describedby": "email-error",
                      className: "bg-ods-card border-ods-border text-ods-text-primary placeholder-ods-text-secondary px-3 h-12"
                    }
                  ),
                  errors.email && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { id: "email-error", className: "text-ods-error text-xs font-['DM_Sans'] mt-1", children: errors.email.message })
                ] })
              ] }),
              (showCompanySize || showReferralSource) && /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4 md:gap-6", children: [
                showCompanySize && /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex flex-col", children: [
                  /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkQAQ7AROScjs.Label, { htmlFor: "companySize", children: "Company Size" }),
                  /* @__PURE__ */ _jsxruntime.jsx.call(void 0, 
                    _reacthookform.Controller,
                    {
                      control,
                      name: "companySize",
                      render: ({ field }) => /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkQAQ7AROScjs.Select, { onValueChange: field.onChange, defaultValue: field.value, children: [
                        /* @__PURE__ */ _jsxruntime.jsx.call(void 0, 
                          _chunkQAQ7AROScjs.SelectTrigger,
                          {
                            id: "companySize",
                            "aria-label": "Company Size",
                            className: "bg-ods-card border-ods-border text-ods-text-primary h-12 px-3",
                            children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkQAQ7AROScjs.SelectValue, { placeholder: "Select company size" })
                          }
                        ),
                        /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkQAQ7AROScjs.SelectContent, { children: companySizeOptions.map((opt) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkQAQ7AROScjs.SelectItem, { value: opt, children: opt }, opt)) })
                      ] })
                    }
                  ),
                  errors.companySize && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { id: "companySize-error", className: "text-ods-error text-xs font-['DM_Sans'] mt-1", children: errors.companySize.message })
                ] }),
                showReferralSource && /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex flex-col", children: [
                  /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkQAQ7AROScjs.Label, { htmlFor: "referralSource", children: "How did you hear about us?" }),
                  /* @__PURE__ */ _jsxruntime.jsx.call(void 0, 
                    _reacthookform.Controller,
                    {
                      control,
                      name: "referralSource",
                      render: ({ field }) => /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkQAQ7AROScjs.Select, { onValueChange: field.onChange, defaultValue: field.value, children: [
                        /* @__PURE__ */ _jsxruntime.jsx.call(void 0, 
                          _chunkQAQ7AROScjs.SelectTrigger,
                          {
                            id: "referralSource",
                            "aria-label": "Referral Source",
                            className: "bg-ods-card border-ods-border text-ods-text-primary h-12 px-3",
                            children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkQAQ7AROScjs.SelectValue, { placeholder: "Select an option" })
                          }
                        ),
                        /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkQAQ7AROScjs.SelectContent, { children: referralSourceOptions.map((opt) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkQAQ7AROScjs.SelectItem, { value: opt, children: opt }, opt)) })
                      ] })
                    }
                  ),
                  errors.referralSource && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { id: "referralSource-error", className: "text-ods-error text-xs font-['DM_Sans'] mt-1", children: errors.referralSource.message })
                ] })
              ] }),
              showHelpCategory && /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex flex-col", children: [
                /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkQAQ7AROScjs.Label, { htmlFor: "helpCategory", children: [
                  "Choose your main interest",
                  /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "text-ods-accent", children: "*" })
                ] }),
                /* @__PURE__ */ _jsxruntime.jsx.call(void 0, 
                  _reacthookform.Controller,
                  {
                    control,
                    name: "helpCategory",
                    render: ({ field }) => /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkQAQ7AROScjs.Select, { onValueChange: field.onChange, defaultValue: field.value, children: [
                      /* @__PURE__ */ _jsxruntime.jsx.call(void 0, 
                        _chunkQAQ7AROScjs.SelectTrigger,
                        {
                          id: "helpCategory",
                          "aria-label": "Help Category",
                          className: "bg-ods-card border-ods-border text-ods-text-primary h-12 px-3",
                          children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkQAQ7AROScjs.SelectValue, { placeholder: "Choose your main interest" })
                        }
                      ),
                      /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkQAQ7AROScjs.SelectContent, { children: helpCategoryOptions.map((opt) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkQAQ7AROScjs.SelectItem, { value: opt, children: opt }, opt)) })
                    ] })
                  }
                ),
                errors.helpCategory && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { id: "helpCategory-error", className: "text-ods-error text-xs font-['DM_Sans'] mt-1", children: errors.helpCategory.message })
              ] }),
              showMessage && /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex flex-col flex-grow", children: [
                /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkQAQ7AROScjs.Label, { htmlFor: "message", children: [
                  "Your Message",
                  /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "text-ods-accent", children: "*" })
                ] }),
                /* @__PURE__ */ _jsxruntime.jsx.call(void 0, 
                  _chunkQAQ7AROScjs.Textarea,
                  {
                    id: "message",
                    ...register("message"),
                    placeholder: "Share your current challenges or questions about open-source alternatives...",
                    "aria-invalid": !!errors.message,
                    "aria-describedby": "message-error",
                    className: "bg-ods-card border-ods-border text-ods-text-primary placeholder-ods-text-secondary h-full flex-grow"
                  }
                ),
                errors.message && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { id: "message-error", className: "text-ods-error text-xs font-['DM_Sans'] mt-1", children: errors.message.message })
              ] }),
              attachmentsEnabled && /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex flex-col gap-2", children: [
                /* @__PURE__ */ _jsxruntime.jsx.call(void 0, 
                  _chunkQAQ7AROScjs.ChatAttachmentChipStrip,
                  {
                    attachments: attachments.attachments,
                    onRemove: attachments.removeAttachment,
                    disabled: isSubmitting
                  }
                ),
                /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex items-center gap-2", children: [
                  /* @__PURE__ */ _jsxruntime.jsx.call(void 0, 
                    _chunkQAQ7AROScjs.ChatAttachmentAddButton,
                    {
                      attachmentsEnabled: true,
                      attachmentsCount: attachments.attachments.length,
                      onAddFiles: attachments.addFiles,
                      disabled: isSubmitting
                    }
                  ),
                  /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "text-xs text-ods-text-secondary", children: "Attach files (optional)" })
                ] })
              ] }),
              /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex flex-col md:flex-row gap-4 md:gap-6 items-center justify-end w-full pt-2 mt-auto", children: [
                footerText && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "p", { className: "font-['DM_Sans'] text-ods-text-secondary text-xs md:text-sm leading-relaxed text-center md:text-left", children: footerText }),
                /* @__PURE__ */ _jsxruntime.jsx.call(void 0, 
                  _chunkN5UOJC3Vcjs.Button,
                  {
                    type: "submit",
                    loading: isSubmitting,
                    disabled: isSubmitting || isSuccess || attachmentsEnabled && attachments.hasInflightUploads,
                    variant: buttonVariant,
                    className: `w-full md:w-auto ${buttonClassName}`,
                    children: isSuccess ? submitSuccessLabel : submitLabel
                  }
                )
              ] })
            ]
          }
        )
      ]
    }
  );
}



exports.ContactForm = ContactForm;
//# sourceMappingURL=chunk-Q52JZP3P.cjs.map