// Operação Brasil — cadastro simples, nativo e compatível com autopreenchimento. const { SectionHeading: FmSH, Field: FmField, Select: FmSelect, Button: FmButton, LegalNote: FmLegal, DogTag: FmDogTag, StoreOption: FmStore } = window.OperaOBrasilDesignSystem_ac060f; const STORES = [ { id: "cac", name: "CAC Armas", region: "GO" }, { id: "big", name: "Big Boar", region: "DF" }, { id: "canil", name: "Canil do Caçador", region: "MG" }, ]; const UFS = [ ["AC","Acre"],["AL","Alagoas"],["AP","Amapá"],["AM","Amazonas"],["BA","Bahia"],["CE","Ceará"], ["DF","Distrito Federal"],["ES","Espírito Santo"],["GO","Goiás"],["MA","Maranhão"],["MT","Mato Grosso"], ["MS","Mato Grosso do Sul"],["MG","Minas Gerais"],["PA","Pará"],["PB","Paraíba"],["PR","Paraná"], ["PE","Pernambuco"],["PI","Piauí"],["RJ","Rio de Janeiro"],["RN","Rio Grande do Norte"],["RS","Rio Grande do Sul"], ["RO","Rondônia"],["RR","Roraima"],["SC","Santa Catarina"],["SP","São Paulo"],["SE","Sergipe"],["TO","Tocantins"], ].map(([value, name]) => ({ value, label: `${name} · ${value}` })); const FORM_PRODUCTS = [ { value: "nao-sei", label: "Ainda não sei — quero orientação" }, { value: "g2c-cafo", label: "G2C CAFO Black" }, { value: "gx4-grafeno", label: "GX4 Carry Grafeno" }, { value: "gx4-tungstenio", label: "GX4 Carry Tungstênio" }, { value: "g3-tungstenio", label: "G3 Tungstênio" }, { value: "g3-toro", label: "G3 T.O.R.O." }, ]; const PRODUCT_DESTINATIONS = { cac: { "nao-sei": "https://cacarmas.com.br/categoria-produto/operacao-brasil/", "g2c-cafo": "https://cacarmas.com.br/produto/pistola-taurus-g2c-calibre-38-tpc-cafo-black/", "gx4-grafeno": "https://cacarmas.com.br/produto/pistola-taurus-gx4-carry-calibre-38-tpc-graphene/", "gx4-tungstenio": "https://cacarmas.com.br/produto/pistola-taurus-gx4-carry-calibre-38-tpc-tungstenio/", "g3-tungstenio": "https://cacarmas.com.br/produto/pistola-taurus-g3-toro-calibre-38-tpc-tungstenio/", "g3-toro": "https://cacarmas.com.br/produto/pistola-taurus-g3-toro-calibre-38-tpc-oxidado-fosco/", }, big: { "nao-sei": "https://bigboar.com.br/categoria-produto/operacao-brasil/", "g2c-cafo": "https://bigboar.com.br/produto/pistola-taurus-g2c-cafo-black-38-tpc-bigboar/", "gx4-grafeno": "https://bigboar.com.br/produto/pistola-taurus-gx4-carry-graphene-38-tpc-bigboar/", "gx4-tungstenio": "https://bigboar.com.br/produto/pistola-taurus-gx4-carry-tungstenio-38-tpc-bigboar/", "g3-tungstenio": "https://bigboar.com.br/produto/pistola-taurus-g3-tungstenio-38-tpc-toro-bigboar/", "g3-toro": "https://bigboar.com.br/produto/pistola-taurus-g3-tenox-38-tpc-toro-bigboar/", }, }; const SUBMIT_TIMEOUT_MS = 15000; const OPERATION_COPY_EMAIL = "suporte@kivodigital.com.br"; const STORE_RECIPIENTS = { cac: "socialmedia.cacarmas@gmail.com", big: "bigboarvendas@gmail.com", canil: "acbcbrasil@gmail.com", }; const BIG_BOAR_WHATSAPP_NUMBER = "5561996478620"; const CANIL_DO_CACADOR_WHATSAPP_NUMBER = "5534992484444"; function formEndpointFor() { return `https://formsubmit.co/ajax/${OPERATION_COPY_EMAIL}`; } function FormSection() { const storeOrder = ["big", "cac", "canil"]; const [store, setStore] = React.useState("big"); const [product, setProduct] = React.useState("nao-sei"); const [sent, setSent] = React.useState(false); const [sending, setSending] = React.useState(false); const [error, setError] = React.useState(""); const [sentStore, setSentStore] = React.useState(null); const [redirectUrl, setRedirectUrl] = React.useState(""); const [redirectLabel, setRedirectLabel] = React.useState(""); const [whatsAppUrl, setWhatsAppUrl] = React.useState(""); const [showBigBoarModal, setShowBigBoarModal] = React.useState(false); const [popupBlocked, setPopupBlocked] = React.useState(false); const modalRef = React.useRef(null); const returnFocusRef = React.useRef(null); const selected = STORES.find((item) => item.id === store); const currentProduct = FORM_PRODUCTS.find((item) => item.value === product) || FORM_PRODUCTS[0]; const orderedStores = storeOrder.map((storeId) => STORES.find((item) => item.id === storeId)); const handleSubmit = async (event) => { event.preventDefault(); const form = event.currentTarget; if (!form.reportValidity()) return; setSending(true); setError(""); const fields = new FormData(form); const productId = fields.get("product-interest") || "nao-sei"; const selectedProduct = FORM_PRODUCTS.find((item) => item.value === productId) || FORM_PRODUCTS[0]; const destination = PRODUCT_DESTINATIONS[selected.id]?.[productId] || PRODUCT_DESTINATIONS[selected.id]?.["nao-sei"] || ""; const payload = { Nome: fields.get("name"), WhatsApp: fields.get("tel"), Estado: fields.get("address-level1"), "Produto de interesse": selectedProduct.label, "Loja escolhida": `${selected.name} — ${selected.region}`, "Página de destino": destination || "Atendimento direto pela loja", Origem: "Landing page Operação Brasil", _subject: `Novo cadastro Operação Brasil — ${selected.name} — ${selected.region}`, _template: "table", _captcha: "false", _honey: fields.get("_honey") || "", _cc: STORE_RECIPIENTS[selected.id] || "", }; const controller = new AbortController(); const timeoutId = window.setTimeout(() => controller.abort(), SUBMIT_TIMEOUT_MS); try { const response = await fetch(formEndpointFor(), { method: "POST", headers: { "Content-Type": "application/json", Accept: "application/json" }, body: JSON.stringify(payload), signal: controller.signal, }); const result = await response.json().catch(() => ({})); if (!response.ok || result.success === false || result.success === "false") { const serverError = new Error(result.message || "Não foi possível confirmar o cadastro."); serverError.isServerResponse = true; throw serverError; } setSentStore(selected); setRedirectUrl(destination); setRedirectLabel(selectedProduct.value === "nao-sei" ? "catálogo" : selectedProduct.label); setSent(true); form.reset(); if (selected.id === "big") { const whatsAppMessage = [ `Olá, equipe Big Boar! Meu nome é ${fields.get("name")}.`, `Vim pela Operação Brasil e tenho interesse em ${selectedProduct.label}.`, "Gostaria de falar com a equipe antes de continuar pelo site.", ].join(" "); setWhatsAppUrl(`https://wa.me/${BIG_BOAR_WHATSAPP_NUMBER}?text=${encodeURIComponent(whatsAppMessage)}`); returnFocusRef.current = document.activeElement; setPopupBlocked(false); setShowBigBoarModal(true); } else if (selected.id === "canil") { const whatsAppMessage = [ `Olá, equipe do Canil do Caçador! Meu nome é ${fields.get("name")}.`, `Vim pela Operação Brasil e tenho interesse em ${selectedProduct.label}.`, "Acabei de enviar meu cadastro e gostaria de continuar o atendimento pelo WhatsApp.", ].join(" "); setWhatsAppUrl(`https://wa.me/${CANIL_DO_CACADOR_WHATSAPP_NUMBER}?text=${encodeURIComponent(whatsAppMessage)}`); } else if (destination) { window.location.assign(destination); } } catch (submitError) { setError(submitError?.name === "AbortError" ? "A confirmação demorou mais que o esperado. Tente novamente." : submitError?.isServerResponse ? submitError.message : "Não foi possível enviar agora. Verifique sua conexão e tente novamente."); } finally { window.clearTimeout(timeoutId); setSending(false); } }; React.useEffect(() => { window.dispatchEvent(new CustomEvent("operation-progress", { detail: { complete: sent } })); }, [sent]); React.useEffect(() => { if (!showBigBoarModal) return undefined; const modal = modalRef.current; const focusableSelector = 'a[href], button:not([disabled]), [tabindex]:not([tabindex="-1"])'; const focusable = () => Array.from(modal?.querySelectorAll(focusableSelector) || []); focusable()[0]?.focus(); const handleKeyDown = (event) => { if (event.key === "Escape") { event.preventDefault(); setShowBigBoarModal(false); return; } if (event.key !== "Tab") return; const items = focusable(); if (!items.length) return; const first = items[0]; const last = items[items.length - 1]; if (event.shiftKey && document.activeElement === first) { event.preventDefault(); last.focus(); } else if (!event.shiftKey && document.activeElement === last) { event.preventDefault(); first.focus(); } }; document.addEventListener("keydown", handleKeyDown); const previousOverflow = document.body.style.overflow; document.body.style.overflow = "hidden"; return () => { document.removeEventListener("keydown", handleKeyDown); document.body.style.overflow = previousOverflow; returnFocusRef.current?.focus?.(); }; }, [showBigBoarModal]); const openBigBoarWhatsApp = () => { const whatsAppWindow = window.open("", "_blank"); if (!whatsAppWindow) { setPopupBlocked(true); return; } whatsAppWindow.opener = null; whatsAppWindow.location.replace(whatsAppUrl); setPopupBlocked(false); }; return (
); } window.FormSection = FormSection;