mitre-form-component 0.1.4 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -894,16 +894,183 @@ var Alert = ({
894
894
  );
895
895
  };
896
896
 
897
+ // src/components/Modal/index.tsx
898
+ import { useEffect as useEffect3, useRef } from "react";
899
+ import { HiX as HiX2 } from "react-icons/hi";
900
+
901
+ // src/components/Modal/styles.ts
902
+ import styled6, { css as css5, keyframes as keyframes2 } from "styled-components";
903
+ var fadeIn2 = keyframes2`
904
+ from { opacity: 0; }
905
+ to { opacity: 1; }
906
+ `;
907
+ var slideIn = keyframes2`
908
+ from { opacity: 0; transform: translateY(-20px) scale(0.96); }
909
+ to { opacity: 1; transform: translateY(0) scale(1); }
910
+ `;
911
+ var Overlay = styled6.div`
912
+ position: fixed;
913
+ inset: 0;
914
+ background: rgba(0, 0, 0, 0.55);
915
+ display: flex;
916
+ align-items: center;
917
+ justify-content: center;
918
+ z-index: 9999;
919
+ padding: 1rem;
920
+ animation: ${fadeIn2} 0.18s ease-out;
921
+ `;
922
+ var accentStyles = {
923
+ success: css5`
924
+ color: ${theme.colors.green2};
925
+ `,
926
+ error: css5`
927
+ color: ${theme.colors.red};
928
+ `
929
+ };
930
+ var Container = styled6.div`
931
+ position: relative;
932
+ background: ${theme.colors.white};
933
+ border-radius: 0.75rem;
934
+ box-shadow: ${theme.shadows.shadow500};
935
+ max-width: 420px;
936
+ width: 100%;
937
+ padding: 1.75rem 1.5rem 1.25rem;
938
+ font-family: ${theme.fonts.primary};
939
+ animation: ${slideIn} 0.22s ease-out;
940
+
941
+ &::before {
942
+ content: "";
943
+ display: block;
944
+ width: 56px;
945
+ height: 4px;
946
+ border-radius: 999px;
947
+ margin: 0 auto 1rem;
948
+ background: ${({ $type }) => $type === "success" ? theme.colors.green2 : theme.colors.red};
949
+ }
950
+
951
+ h2 {
952
+ margin: 0 0 0.5rem;
953
+ font-size: 1.25rem;
954
+ font-weight: 700;
955
+ text-align: center;
956
+ ${({ $type }) => accentStyles[$type]}
957
+ }
958
+
959
+ p {
960
+ margin: 0 0 1.5rem;
961
+ font-size: 0.95rem;
962
+ line-height: 1.45;
963
+ text-align: center;
964
+ color: ${theme.colors.black};
965
+ }
966
+ `;
967
+ var CloseButton = styled6.button`
968
+ position: absolute;
969
+ top: 0.5rem;
970
+ right: 0.5rem;
971
+ background: transparent;
972
+ border: none;
973
+ cursor: pointer;
974
+ color: ${theme.colors.gray550};
975
+ padding: 0.25rem;
976
+ display: inline-flex;
977
+ align-items: center;
978
+ justify-content: center;
979
+ border-radius: 999px;
980
+ transition: background 0.15s, color 0.15s;
981
+
982
+ &:hover {
983
+ background: ${theme.colors.gray300};
984
+ color: ${theme.colors.black};
985
+ }
986
+
987
+ svg {
988
+ width: 1.1rem;
989
+ height: 1.1rem;
990
+ }
991
+ `;
992
+ var PrimaryButton = styled6.button`
993
+ display: block;
994
+ width: 100%;
995
+ padding: 0.75rem 1rem;
996
+ border: none;
997
+ border-radius: 0.5rem;
998
+ background: ${({ $bgColor }) => $bgColor || theme.colors.yellow500};
999
+ color: ${({ $textColor }) => $textColor || theme.colors.black};
1000
+ font-family: ${theme.fonts.primary};
1001
+ font-size: 1rem;
1002
+ font-weight: 700;
1003
+ cursor: pointer;
1004
+ transition: filter 0.15s;
1005
+
1006
+ &:hover {
1007
+ filter: brightness(0.95);
1008
+ }
1009
+
1010
+ &:focus-visible {
1011
+ outline: 2px solid ${theme.colors.yellow400};
1012
+ outline-offset: 2px;
1013
+ }
1014
+ `;
1015
+
1016
+ // src/components/Modal/index.tsx
1017
+ import { jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
1018
+ var Modal = ({
1019
+ type,
1020
+ title,
1021
+ message,
1022
+ primaryButtonText,
1023
+ onPrimaryAction,
1024
+ onClose,
1025
+ primaryButtonBgColor,
1026
+ primaryButtonTextColor
1027
+ }) => {
1028
+ const primaryButtonRef = useRef(null);
1029
+ useEffect3(() => {
1030
+ primaryButtonRef.current?.focus();
1031
+ }, []);
1032
+ useEffect3(() => {
1033
+ const handleKey = (event) => {
1034
+ if (event.key === "Escape") {
1035
+ onClose();
1036
+ }
1037
+ };
1038
+ document.addEventListener("keydown", handleKey);
1039
+ return () => document.removeEventListener("keydown", handleKey);
1040
+ }, [onClose]);
1041
+ const handleOverlayClick = (event) => {
1042
+ if (event.target === event.currentTarget) {
1043
+ onClose();
1044
+ }
1045
+ };
1046
+ return /* @__PURE__ */ jsx4(Overlay, { onClick: handleOverlayClick, role: "dialog", "aria-modal": "true", "aria-label": title, children: /* @__PURE__ */ jsxs4(Container, { $type: type, children: [
1047
+ /* @__PURE__ */ jsx4(CloseButton, { onClick: onClose, "aria-label": "Fechar", children: /* @__PURE__ */ jsx4(HiX2, {}) }),
1048
+ /* @__PURE__ */ jsx4("h2", { children: title }),
1049
+ /* @__PURE__ */ jsx4("p", { children: message }),
1050
+ /* @__PURE__ */ jsx4(
1051
+ PrimaryButton,
1052
+ {
1053
+ ref: primaryButtonRef,
1054
+ onClick: onPrimaryAction,
1055
+ $bgColor: primaryButtonBgColor,
1056
+ $textColor: primaryButtonTextColor,
1057
+ type: "button",
1058
+ children: primaryButtonText
1059
+ }
1060
+ )
1061
+ ] }) });
1062
+ };
1063
+
897
1064
  // src/components/PhoneInput/index.tsx
898
1065
  import {
899
1066
  forwardRef as forwardRef2
900
1067
  } from "react";
901
1068
 
902
1069
  // src/components/PhoneInput/styles.ts
903
- import styled6, { css as css5 } from "styled-components";
1070
+ import styled7, { css as css6 } from "styled-components";
904
1071
  import { PhoneInput } from "react-international-phone";
905
1072
  import "react-international-phone/style.css";
906
- var FormLabel3 = styled6.label`
1073
+ var FormLabel3 = styled7.label`
907
1074
  font-family: ${theme.fonts.primary};
908
1075
  font-style: normal;
909
1076
  font-weight: 500;
@@ -913,7 +1080,7 @@ var FormLabel3 = styled6.label`
913
1080
  margin-bottom: 0.5rem;
914
1081
  text-align: left;
915
1082
  `;
916
- var StyledPhoneInput = styled6(PhoneInput)`
1083
+ var StyledPhoneInput = styled7(PhoneInput)`
917
1084
  width: 100%;
918
1085
  height: 3.125rem;
919
1086
  background: ${(props) => props.$backgroundColor || theme.colors.white};
@@ -1027,24 +1194,24 @@ var StyledPhoneInput = styled6(PhoneInput)`
1027
1194
  }
1028
1195
  }
1029
1196
  `;
1030
- var FormErrorMessage3 = styled6.small`
1197
+ var FormErrorMessage3 = styled7.small`
1031
1198
  font-size: 0.75rem;
1032
1199
  line-height: 1.125rem;
1033
1200
  color: ${theme.colors.red};
1034
1201
  margin-top: 0.25rem;
1035
1202
  display: block;
1036
1203
  `;
1037
- var FormControl3 = styled6.div.withConfig({
1204
+ var FormControl3 = styled7.div.withConfig({
1038
1205
  shouldForwardProp: (prop) => !["isInvalid"].includes(prop)
1039
1206
  })`
1040
1207
  ${FormLabel3} {
1041
- ${(props) => props.isInvalid && css5`
1208
+ ${(props) => props.isInvalid && css6`
1042
1209
  color: ${theme.colors.red};
1043
1210
  `};
1044
1211
  }
1045
1212
 
1046
1213
  ${StyledPhoneInput} {
1047
- ${(props) => props.isInvalid && css5`
1214
+ ${(props) => props.isInvalid && css6`
1048
1215
  border: 1px solid ${theme.colors.red};
1049
1216
 
1050
1217
  &:not(:focus)::placeholder {
@@ -1054,7 +1221,7 @@ var FormControl3 = styled6.div.withConfig({
1054
1221
  `};
1055
1222
 
1056
1223
  .react-international-phone-input-container {
1057
- ${(props) => props.isInvalid && css5`
1224
+ ${(props) => props.isInvalid && css6`
1058
1225
  border: 1px solid ${theme.colors.red};
1059
1226
 
1060
1227
  &:not(:focus)::placeholder {
@@ -1065,7 +1232,7 @@ var FormControl3 = styled6.div.withConfig({
1065
1232
  }
1066
1233
 
1067
1234
  .react-international-phone-country-selector-button {
1068
- ${(props) => props.isInvalid && css5`
1235
+ ${(props) => props.isInvalid && css6`
1069
1236
  border-right: 1px solid ${theme.colors.red};
1070
1237
  `};
1071
1238
  }
@@ -1073,7 +1240,7 @@ var FormControl3 = styled6.div.withConfig({
1073
1240
  `;
1074
1241
 
1075
1242
  // src/components/PhoneInput/index.tsx
1076
- import { jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
1243
+ import { jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
1077
1244
  var PhoneInputBase = ({
1078
1245
  id,
1079
1246
  label,
@@ -1088,9 +1255,9 @@ var PhoneInputBase = ({
1088
1255
  value,
1089
1256
  ...rest
1090
1257
  }, ref) => {
1091
- return /* @__PURE__ */ jsxs4(FormControl3, { isInvalid: !!error, children: [
1092
- !!label && /* @__PURE__ */ jsx4(FormLabel3, { htmlFor: id, $textColor: labelTextColor, children: label }),
1093
- /* @__PURE__ */ jsx4(
1258
+ return /* @__PURE__ */ jsxs5(FormControl3, { isInvalid: !!error, children: [
1259
+ !!label && /* @__PURE__ */ jsx5(FormLabel3, { htmlFor: id, $textColor: labelTextColor, children: label }),
1260
+ /* @__PURE__ */ jsx5(
1094
1261
  StyledPhoneInput,
1095
1262
  {
1096
1263
  ref,
@@ -1124,7 +1291,7 @@ var PhoneInputBase = ({
1124
1291
  $textColor: inputTextColor
1125
1292
  }
1126
1293
  ),
1127
- !!error && showErrorMessage && /* @__PURE__ */ jsx4(FormErrorMessage3, { "data-testid": "error-message", children: typeof error === "string" ? error : error?.message })
1294
+ !!error && showErrorMessage && /* @__PURE__ */ jsx5(FormErrorMessage3, { "data-testid": "error-message", children: typeof error === "string" ? error : error?.message })
1128
1295
  ] });
1129
1296
  };
1130
1297
  var PhoneInput2 = forwardRef2(PhoneInputBase);
@@ -1133,7 +1300,7 @@ var PhoneInput2 = forwardRef2(PhoneInputBase);
1133
1300
  import {
1134
1301
  forwardRef as forwardRef3
1135
1302
  } from "react";
1136
- import { jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
1303
+ import { jsx as jsx6, jsxs as jsxs6 } from "react/jsx-runtime";
1137
1304
  var ProductSelectBase = ({
1138
1305
  id,
1139
1306
  label,
@@ -1148,9 +1315,9 @@ var ProductSelectBase = ({
1148
1315
  placeholder = "Selecione um produto",
1149
1316
  ...rest
1150
1317
  }, ref) => {
1151
- return /* @__PURE__ */ jsxs5(FormControl, { isInvalid: !!error, children: [
1152
- !!label && /* @__PURE__ */ jsx5(FormLabel, { htmlFor: id, $textColor: labelTextColor, children: label }),
1153
- /* @__PURE__ */ jsxs5(
1318
+ return /* @__PURE__ */ jsxs6(FormControl, { isInvalid: !!error, children: [
1319
+ !!label && /* @__PURE__ */ jsx6(FormLabel, { htmlFor: id, $textColor: labelTextColor, children: label }),
1320
+ /* @__PURE__ */ jsxs6(
1154
1321
  Select,
1155
1322
  {
1156
1323
  id,
@@ -1162,18 +1329,37 @@ var ProductSelectBase = ({
1162
1329
  $textColor: textColor,
1163
1330
  ...rest,
1164
1331
  children: [
1165
- /* @__PURE__ */ jsx5("option", { value: "", disabled: true, children: placeholder }),
1166
- products.map((product) => /* @__PURE__ */ jsx5("option", { value: product.id, children: product.name }, product.id))
1332
+ /* @__PURE__ */ jsx6("option", { value: "", disabled: true, children: placeholder }),
1333
+ products.map((product) => /* @__PURE__ */ jsx6("option", { value: product.id, children: product.name }, product.id))
1167
1334
  ]
1168
1335
  }
1169
1336
  ),
1170
- !!error && showErrorMessage && /* @__PURE__ */ jsx5(FormErrorMessage, { "data-testid": "error-message", children: typeof error === "string" ? error : error.message })
1337
+ !!error && showErrorMessage && /* @__PURE__ */ jsx6(FormErrorMessage, { "data-testid": "error-message", children: typeof error === "string" ? error : error.message })
1171
1338
  ] });
1172
1339
  };
1173
1340
  var ProductSelect = forwardRef3(ProductSelectBase);
1174
1341
 
1342
+ // src/config/environments.ts
1343
+ var ENVIRONMENTS = {
1344
+ homol: {
1345
+ apiUrl: "https://leads-hml.mitrerealty.com.br/api-leads",
1346
+ apiToken: "TEFORElOR19NSVRSRTptZlFXZnhvUHdNbWVZY0FidkF0QWJ3Q2RFYWtKckJBOXg5cGNsOTBvS1V0N2ZsU0d4TEtNdEZZd3k0NFlEc0c3",
1347
+ whatsappPhone: "551148100601",
1348
+ chatUrl: "https://crm-hml.mitrerealty.com.br/wcc/UserLoginSubmit.do"
1349
+ },
1350
+ prod: {
1351
+ apiUrl: "https://leads.mitrerealty.com.br/api-leads",
1352
+ apiToken: "TEFORElOR19NSVRSRTptZlFXZnhvUHdNbWVZY0FidkF0QWJ3Q2RFYWtKckJBOXg5cGNsOTBvS1V0N2ZsU0d4TEtNdEZZd3k0NFlEc0c3",
1353
+ whatsappPhone: "551148100601",
1354
+ chatUrl: "https://crm.mitrerealty.com.br/wcc/UserLoginSubmit.do"
1355
+ }
1356
+ };
1357
+ var resolveEnvironment = (ambiente = "homol") => {
1358
+ return ENVIRONMENTS[ambiente] ?? null;
1359
+ };
1360
+
1175
1361
  // src/components/Form/index.tsx
1176
- import { Fragment, jsx as jsx6, jsxs as jsxs6 } from "react/jsx-runtime";
1362
+ import { Fragment, jsx as jsx7, jsxs as jsxs7 } from "react/jsx-runtime";
1177
1363
  var phoneUtil = PhoneNumberUtil.getInstance();
1178
1364
  var PreferenciaContato = /* @__PURE__ */ ((PreferenciaContato2) => {
1179
1365
  PreferenciaContato2["Whatsapp"] = "Whatsapp";
@@ -1181,6 +1367,40 @@ var PreferenciaContato = /* @__PURE__ */ ((PreferenciaContato2) => {
1181
1367
  PreferenciaContato2["Ligacao"] = "Liga\xE7\xE3o";
1182
1368
  return PreferenciaContato2;
1183
1369
  })(PreferenciaContato || {});
1370
+ var WHATSAPP_MESSAGE = "Ol\xE1! Tenho interesse e gostaria de mais informa\xE7\xF5es.";
1371
+ var WHATSAPP_TITLE = "Fale com um corretor por WhatsApp";
1372
+ var WHATSAPP_SUBTITLE = "Informe seus dados para contato.";
1373
+ var WHATSAPP_BUTTON_TEXT = "Entrar";
1374
+ var CHAT_TITLE = "Fale com um corretor por chat";
1375
+ var CHAT_SUBTITLE = "Informe seus dados para contato.";
1376
+ var CHAT_BUTTON_TEXT = "Entrar";
1377
+ var MODAL_ERROR_TITLE = "N\xE3o foi poss\xEDvel completar seu contato";
1378
+ var MODAL_ERROR_MESSAGE = "Por favor, tente novamente em alguns instantes.";
1379
+ var MODAL_ERROR_BUTTON_TEXT = "OK";
1380
+ var MODAL_SUCCESS_TITLE = "Cadastro realizado!";
1381
+ var MODAL_SUCCESS_MESSAGE_WHATSAPP = "Clique abaixo para continuar pelo WhatsApp.";
1382
+ var MODAL_SUCCESS_BUTTON_WHATSAPP = "Abrir WhatsApp";
1383
+ var MODAL_SUCCESS_MESSAGE_CHAT = "Clique abaixo para iniciar o atendimento.";
1384
+ var MODAL_SUCCESS_BUTTON_CHAT = "Iniciar atendimento";
1385
+ function buildWhatsappUrl(phone) {
1386
+ const digits = phone.replace(/\D/g, "");
1387
+ const text = encodeURIComponent(WHATSAPP_MESSAGE);
1388
+ return `https://api.whatsapp.com/send?phone=${digits}&text=${text}`;
1389
+ }
1390
+ function submitChatInNewTab(chatUrl, virtualObj) {
1391
+ const form = document.createElement("form");
1392
+ form.method = "POST";
1393
+ form.action = chatUrl;
1394
+ form.target = "_blank";
1395
+ const input = document.createElement("input");
1396
+ input.type = "hidden";
1397
+ input.name = "virtual_obj";
1398
+ input.value = JSON.stringify(virtualObj);
1399
+ form.appendChild(input);
1400
+ document.body.appendChild(form);
1401
+ form.submit();
1402
+ document.body.removeChild(form);
1403
+ }
1184
1404
  var isPhoneValid = (phone) => {
1185
1405
  try {
1186
1406
  return phoneUtil.isValidNumber(phoneUtil.parseAndKeepRawInput(phone));
@@ -1212,8 +1432,8 @@ var schemaWithProduct = yup.object().shape({
1212
1432
  var schema = yup.object().shape(baseSchema);
1213
1433
  var MitreFormComponent = React2.forwardRef(({
1214
1434
  products,
1215
- apiUrl,
1216
- apiToken,
1435
+ ambiente = "homol",
1436
+ canal = "form",
1217
1437
  showHeader = true,
1218
1438
  title = "Atendimento por mensagem",
1219
1439
  subtitle = "Informe seus dados e retornaremos a mensagem.",
@@ -1228,8 +1448,9 @@ var MitreFormComponent = React2.forwardRef(({
1228
1448
  inputPlaceholderColor = theme.colors.gray100,
1229
1449
  inputTextColor = theme.colors.black,
1230
1450
  showPreferenciaContato = false,
1231
- onSuccess,
1232
- onError
1451
+ idProdutoTerceiro,
1452
+ idEmpreendimento,
1453
+ naoCriarEvento
1233
1454
  }, ref) => {
1234
1455
  useMontserratFont();
1235
1456
  const [loading, setIsLoading] = useState3(false);
@@ -1237,6 +1458,7 @@ var MitreFormComponent = React2.forwardRef(({
1237
1458
  const [successMessage, setSuccessMessage] = useState3("");
1238
1459
  const [formKey, setFormKey] = useState3(0);
1239
1460
  const [selectedProductId, setSelectedProductId] = useState3(null);
1461
+ const [actionModal, setActionModal] = useState3(null);
1240
1462
  const validateProducts = () => {
1241
1463
  if (!products) {
1242
1464
  return "Lista de produtos n\xE3o foi fornecida";
@@ -1261,7 +1483,53 @@ var MitreFormComponent = React2.forwardRef(({
1261
1483
  }
1262
1484
  return null;
1263
1485
  };
1486
+ const env = resolveEnvironment(ambiente);
1487
+ const validateAmbienteConfig = () => {
1488
+ if (!env) {
1489
+ return `ambiente='${ambiente}' n\xE3o \xE9 reconhecido. Use 'homol' ou 'prod'.`;
1490
+ }
1491
+ if (!env.apiUrl || !env.apiToken) {
1492
+ return `Configura\xE7\xE3o interna do ambiente '${ambiente}' est\xE1 incompleta (apiUrl/apiToken).`;
1493
+ }
1494
+ return null;
1495
+ };
1496
+ const validateWhatsappConfig = () => {
1497
+ if (canal !== "whatsapp") return null;
1498
+ if (!env) return null;
1499
+ const raw = env.whatsappPhone?.trim() ?? "";
1500
+ if (!raw) {
1501
+ return `canal='whatsapp' exige whatsappPhone no ambiente '${ambiente}'.`;
1502
+ }
1503
+ const normalized = raw.startsWith("+") ? raw : `+${raw}`;
1504
+ if (!isPhoneValid(normalized)) {
1505
+ return `whatsappPhone do ambiente '${ambiente}' \xE9 inv\xE1lido (${JSON.stringify(env.whatsappPhone)}).`;
1506
+ }
1507
+ return null;
1508
+ };
1509
+ const validateChatConfig = () => {
1510
+ if (canal !== "chat") return null;
1511
+ if (!env) return null;
1512
+ const raw = env.chatUrl?.trim() ?? "";
1513
+ if (!raw) {
1514
+ return `canal='chat' exige chatUrl no ambiente '${ambiente}'.`;
1515
+ }
1516
+ try {
1517
+ const parsed = new URL(raw);
1518
+ if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
1519
+ return `chatUrl do ambiente '${ambiente}' precisa ter protocolo http(s) (recebido: ${JSON.stringify(env.chatUrl)}).`;
1520
+ }
1521
+ } catch {
1522
+ return `chatUrl do ambiente '${ambiente}' n\xE3o \xE9 URL absoluta v\xE1lida (recebido: ${JSON.stringify(env.chatUrl)}).`;
1523
+ }
1524
+ return null;
1525
+ };
1264
1526
  const productsValidationError = validateProducts();
1527
+ const ambienteConfigError = validateAmbienteConfig();
1528
+ const whatsappConfigError = validateWhatsappConfig();
1529
+ const chatConfigError = validateChatConfig();
1530
+ const effectiveShowPreferenciaContato = canal === "whatsapp" || canal === "chat" ? false : showPreferenciaContato;
1531
+ const effectiveTitle = canal === "whatsapp" ? WHATSAPP_TITLE : canal === "chat" ? CHAT_TITLE : title;
1532
+ const effectiveSubtitle = canal === "whatsapp" ? WHATSAPP_SUBTITLE : canal === "chat" ? CHAT_SUBTITLE : subtitle;
1265
1533
  const [utm, setUtm] = useState3({ utm_source: "direto", createdAt: (/* @__PURE__ */ new Date()).toISOString() });
1266
1534
  const formSchema = products && products.length > 1 ? schemaWithProduct : schema;
1267
1535
  const { control, register, handleSubmit, formState: { errors }, reset, clearErrors } = useForm({
@@ -1300,9 +1568,13 @@ var MitreFormComponent = React2.forwardRef(({
1300
1568
  const phoneValue = phone.inputValue;
1301
1569
  const phoneDigitsOnly = phoneValue?.replace(/\D/g, "") || "";
1302
1570
  const message = "Gostaria de mais informa\xE7\xF5es sobre o produto";
1571
+ setActionModal(null);
1303
1572
  try {
1304
1573
  setIsLoading(true);
1305
- if (!products || products.length === 0 || !apiToken) {
1574
+ if (!env) {
1575
+ throw new Error("Ambiente n\xE3o resolvido");
1576
+ }
1577
+ if (!products || products.length === 0) {
1306
1578
  throw new Error("Par\xE2metros obrigat\xF3rios n\xE3o informados");
1307
1579
  }
1308
1580
  let selectedProduct;
@@ -1318,6 +1590,8 @@ var MitreFormComponent = React2.forwardRef(({
1318
1590
  }
1319
1591
  selectedProduct = foundProduct;
1320
1592
  }
1593
+ const paginaAtual = typeof window !== "undefined" ? window.location.href : void 0;
1594
+ const naoCriarEventoEfetivo = canal !== "form" && (naoCriarEvento ?? true);
1321
1595
  const requestBody = {
1322
1596
  name,
1323
1597
  email,
@@ -1328,13 +1602,23 @@ var MitreFormComponent = React2.forwardRef(({
1328
1602
  utm_campaign: utm.utm_campaign,
1329
1603
  utm_medium: utm.utm_medium,
1330
1604
  utm_term: utm.utm_term,
1331
- ...showPreferenciaContato && preferencia_contato ? { preferencia_contato } : {}
1605
+ ...canal === "whatsapp" ? { preferencia_contato: "Whatsapp" /* Whatsapp */ } : effectiveShowPreferenciaContato && preferencia_contato ? { preferencia_contato } : {},
1606
+ ...canal !== "form" ? {
1607
+ canal,
1608
+ ...paginaAtual ? { pagina: paginaAtual } : {},
1609
+ // Paridade com atendimento.html legado: o mesmo <form id="chat-form">
1610
+ // era usado para chat e whatsapp, portanto is_chat=true ia em ambos.
1611
+ is_chat: true,
1612
+ ...idProdutoTerceiro !== void 0 ? { idProdutoTerceiro } : {},
1613
+ ...idEmpreendimento !== void 0 ? { idEmpreendimento } : {},
1614
+ ...naoCriarEventoEfetivo ? { naoCriarEvento: true } : {}
1615
+ } : {}
1332
1616
  };
1333
- const response = await fetch(`${apiUrl}/leads`, {
1617
+ const response = await fetch(`${env.apiUrl}/leads`, {
1334
1618
  method: "POST",
1335
1619
  headers: {
1336
1620
  "Content-Type": "application/json",
1337
- Authorization: `Basic ${apiToken}`
1621
+ Authorization: `Basic ${env.apiToken}`
1338
1622
  },
1339
1623
  body: JSON.stringify(requestBody)
1340
1624
  });
@@ -1343,26 +1627,61 @@ var MitreFormComponent = React2.forwardRef(({
1343
1627
  }
1344
1628
  const responseData = await response.json();
1345
1629
  const leadId = responseData.leadId || responseData.id || "";
1346
- setSuccessMessage("Mensagem enviada com sucesso!");
1347
1630
  resetForm();
1348
- onSuccess?.(requestBody, leadId);
1631
+ if (canal === "whatsapp") {
1632
+ setActionModal({
1633
+ kind: "success",
1634
+ canal: "whatsapp",
1635
+ targetUrl: buildWhatsappUrl(env.whatsappPhone)
1636
+ });
1637
+ } else if (canal === "chat") {
1638
+ const virtualObj = {
1639
+ ...requestBody,
1640
+ externalOriginId: leadId,
1641
+ ...paginaAtual ? { pagina: paginaAtual } : {},
1642
+ ...idProdutoTerceiro !== void 0 ? { idProdutoTerceiro } : {},
1643
+ ...idEmpreendimento !== void 0 ? { idEmpreendimento } : {},
1644
+ ...naoCriarEventoEfetivo ? { naoCriarEvento: true } : {}
1645
+ };
1646
+ setActionModal({
1647
+ kind: "success",
1648
+ canal: "chat",
1649
+ chatUrl: env.chatUrl,
1650
+ virtualObj
1651
+ });
1652
+ } else {
1653
+ setSuccessMessage("Mensagem enviada com sucesso!");
1654
+ }
1349
1655
  } catch (err) {
1350
- const error2 = err instanceof Error ? err : new Error("Erro desconhecido");
1351
- handleError(err);
1352
- onError?.(error2);
1656
+ if (canal === "whatsapp" || canal === "chat") {
1657
+ setActionModal({ kind: "error" });
1658
+ } else {
1659
+ handleError(err);
1660
+ }
1353
1661
  } finally {
1354
1662
  setIsLoading(false);
1355
1663
  }
1356
1664
  };
1357
- if (productsValidationError) {
1358
- console.error("Erro na valida\xE7\xE3o dos produtos:", productsValidationError);
1359
- return /* @__PURE__ */ jsx6(FormContainer, { $backgroundColor: backgroundColor, $innerPadding: innerPadding, ref, children: /* @__PURE__ */ jsxs6(HeaderContainer, { children: [
1360
- /* @__PURE__ */ jsx6(Title, { $textColor: textColor, children: "Erro no carregamento do formul\xE1rio!" }),
1361
- /* @__PURE__ */ jsx6(Subtitle, { $textColor: textColor, children: "N\xE3o foi poss\xEDvel carregar o formul\xE1rio. Tente novamente mais tarde." })
1665
+ if (productsValidationError || ambienteConfigError || whatsappConfigError || chatConfigError) {
1666
+ if (productsValidationError) {
1667
+ console.error("Erro na valida\xE7\xE3o dos produtos:", productsValidationError);
1668
+ }
1669
+ if (ambienteConfigError) {
1670
+ console.error("Erro na valida\xE7\xE3o do ambiente:", ambienteConfigError);
1671
+ }
1672
+ if (whatsappConfigError) {
1673
+ console.error("Erro na valida\xE7\xE3o do canal whatsapp:", whatsappConfigError);
1674
+ }
1675
+ if (chatConfigError) {
1676
+ console.error("Erro na valida\xE7\xE3o do canal chat:", chatConfigError);
1677
+ }
1678
+ return /* @__PURE__ */ jsx7(FormContainer, { $backgroundColor: backgroundColor, $innerPadding: innerPadding, ref, children: /* @__PURE__ */ jsxs7(HeaderContainer, { children: [
1679
+ /* @__PURE__ */ jsx7(Title, { $textColor: textColor, children: "Erro no carregamento do formul\xE1rio!" }),
1680
+ /* @__PURE__ */ jsx7(Subtitle, { $textColor: textColor, children: "N\xE3o foi poss\xEDvel carregar o formul\xE1rio. Tente novamente mais tarde." })
1362
1681
  ] }) });
1363
1682
  }
1364
- return /* @__PURE__ */ jsxs6(Fragment, { children: [
1365
- error && /* @__PURE__ */ jsx6(
1683
+ return /* @__PURE__ */ jsxs7(Fragment, { children: [
1684
+ error && /* @__PURE__ */ jsx7(
1366
1685
  Alert,
1367
1686
  {
1368
1687
  type: "error",
@@ -1372,7 +1691,7 @@ var MitreFormComponent = React2.forwardRef(({
1372
1691
  children: error.message
1373
1692
  }
1374
1693
  ),
1375
- successMessage && /* @__PURE__ */ jsx6(
1694
+ successMessage && /* @__PURE__ */ jsx7(
1376
1695
  Alert,
1377
1696
  {
1378
1697
  type: "success",
@@ -1382,13 +1701,58 @@ var MitreFormComponent = React2.forwardRef(({
1382
1701
  children: successMessage
1383
1702
  }
1384
1703
  ),
1385
- /* @__PURE__ */ jsxs6(FormContainer, { $backgroundColor: backgroundColor, $innerPadding: innerPadding, ref, children: [
1386
- showHeader && /* @__PURE__ */ jsxs6(HeaderContainer, { children: [
1387
- /* @__PURE__ */ jsx6(Title, { $textColor: textColor, children: title }),
1388
- /* @__PURE__ */ jsx6(Subtitle, { $textColor: textColor, children: subtitle })
1704
+ actionModal?.kind === "error" && /* @__PURE__ */ jsx7(
1705
+ Modal,
1706
+ {
1707
+ type: "error",
1708
+ title: MODAL_ERROR_TITLE,
1709
+ message: MODAL_ERROR_MESSAGE,
1710
+ primaryButtonText: MODAL_ERROR_BUTTON_TEXT,
1711
+ onPrimaryAction: () => setActionModal(null),
1712
+ onClose: () => setActionModal(null),
1713
+ primaryButtonBgColor: buttonBackgroundColor,
1714
+ primaryButtonTextColor: buttonTextColor
1715
+ }
1716
+ ),
1717
+ actionModal?.kind === "success" && actionModal.canal === "whatsapp" && /* @__PURE__ */ jsx7(
1718
+ Modal,
1719
+ {
1720
+ type: "success",
1721
+ title: MODAL_SUCCESS_TITLE,
1722
+ message: MODAL_SUCCESS_MESSAGE_WHATSAPP,
1723
+ primaryButtonText: MODAL_SUCCESS_BUTTON_WHATSAPP,
1724
+ onPrimaryAction: () => {
1725
+ window.open(actionModal.targetUrl, "_blank", "noopener,noreferrer");
1726
+ setActionModal(null);
1727
+ },
1728
+ onClose: () => setActionModal(null),
1729
+ primaryButtonBgColor: buttonBackgroundColor,
1730
+ primaryButtonTextColor: buttonTextColor
1731
+ }
1732
+ ),
1733
+ actionModal?.kind === "success" && actionModal.canal === "chat" && /* @__PURE__ */ jsx7(
1734
+ Modal,
1735
+ {
1736
+ type: "success",
1737
+ title: MODAL_SUCCESS_TITLE,
1738
+ message: MODAL_SUCCESS_MESSAGE_CHAT,
1739
+ primaryButtonText: MODAL_SUCCESS_BUTTON_CHAT,
1740
+ onPrimaryAction: () => {
1741
+ submitChatInNewTab(actionModal.chatUrl, actionModal.virtualObj);
1742
+ setActionModal(null);
1743
+ },
1744
+ onClose: () => setActionModal(null),
1745
+ primaryButtonBgColor: buttonBackgroundColor,
1746
+ primaryButtonTextColor: buttonTextColor
1747
+ }
1748
+ ),
1749
+ /* @__PURE__ */ jsxs7(FormContainer, { $backgroundColor: backgroundColor, $innerPadding: innerPadding, ref, children: [
1750
+ showHeader && /* @__PURE__ */ jsxs7(HeaderContainer, { children: [
1751
+ /* @__PURE__ */ jsx7(Title, { $textColor: textColor, children: effectiveTitle }),
1752
+ /* @__PURE__ */ jsx7(Subtitle, { $textColor: textColor, children: effectiveSubtitle })
1389
1753
  ] }),
1390
- /* @__PURE__ */ jsxs6(Form, { $textColor: textColor, onSubmit: handleSubmit(sendMessage), noValidate: true, children: [
1391
- products.length > 1 && /* @__PURE__ */ jsx6(
1754
+ /* @__PURE__ */ jsxs7(Form, { $textColor: textColor, onSubmit: handleSubmit(sendMessage), noValidate: true, children: [
1755
+ products.length > 1 && /* @__PURE__ */ jsx7(
1392
1756
  ProductSelect,
1393
1757
  {
1394
1758
  id: "productId",
@@ -1405,7 +1769,7 @@ var MitreFormComponent = React2.forwardRef(({
1405
1769
  textColor: inputTextColor
1406
1770
  }
1407
1771
  ),
1408
- /* @__PURE__ */ jsx6(
1772
+ /* @__PURE__ */ jsx7(
1409
1773
  Input2,
1410
1774
  {
1411
1775
  id: "name",
@@ -1423,7 +1787,7 @@ var MitreFormComponent = React2.forwardRef(({
1423
1787
  inputTextColor
1424
1788
  }
1425
1789
  ),
1426
- /* @__PURE__ */ jsx6(
1790
+ /* @__PURE__ */ jsx7(
1427
1791
  Input2,
1428
1792
  {
1429
1793
  id: "email",
@@ -1442,7 +1806,7 @@ var MitreFormComponent = React2.forwardRef(({
1442
1806
  inputTextColor
1443
1807
  }
1444
1808
  ),
1445
- /* @__PURE__ */ jsx6(
1809
+ /* @__PURE__ */ jsx7(
1446
1810
  Controller,
1447
1811
  {
1448
1812
  name: "phone",
@@ -1451,7 +1815,7 @@ var MitreFormComponent = React2.forwardRef(({
1451
1815
  shouldUnregister: true,
1452
1816
  render: ({ field }) => {
1453
1817
  const errorMsg = errors.phone?.inputValue?.message || errors.phone?.phone?.message || errors.phone?.message;
1454
- return /* @__PURE__ */ jsx6(
1818
+ return /* @__PURE__ */ jsx7(
1455
1819
  PhoneInput2,
1456
1820
  {
1457
1821
  id: "phone",
@@ -1474,9 +1838,9 @@ var MitreFormComponent = React2.forwardRef(({
1474
1838
  },
1475
1839
  formKey
1476
1840
  ),
1477
- showPreferenciaContato && /* @__PURE__ */ jsxs6(FormControl, { isInvalid: !!errors.preferencia_contato, children: [
1478
- /* @__PURE__ */ jsx6(FormLabel, { htmlFor: "preferencia_contato", $textColor: textColor, children: "Prefer\xEAncia de Contato" }),
1479
- /* @__PURE__ */ jsxs6(
1841
+ effectiveShowPreferenciaContato && /* @__PURE__ */ jsxs7(FormControl, { isInvalid: !!errors.preferencia_contato, children: [
1842
+ /* @__PURE__ */ jsx7(FormLabel, { htmlFor: "preferencia_contato", $textColor: textColor, children: "Prefer\xEAncia de Contato" }),
1843
+ /* @__PURE__ */ jsxs7(
1480
1844
  Select,
1481
1845
  {
1482
1846
  id: "preferencia_contato",
@@ -1487,19 +1851,19 @@ var MitreFormComponent = React2.forwardRef(({
1487
1851
  $focusBorderColor: inputFocusBorderColor,
1488
1852
  $textColor: inputTextColor,
1489
1853
  children: [
1490
- /* @__PURE__ */ jsx6("option", { value: "", disabled: true, children: "Selecione uma op\xE7\xE3o" }),
1491
- Object.values(PreferenciaContato).map((op) => /* @__PURE__ */ jsx6("option", { value: op, children: op }, op))
1854
+ /* @__PURE__ */ jsx7("option", { value: "", disabled: true, children: "Selecione uma op\xE7\xE3o" }),
1855
+ Object.values(PreferenciaContato).map((op) => /* @__PURE__ */ jsx7("option", { value: op, children: op }, op))
1492
1856
  ]
1493
1857
  }
1494
1858
  ),
1495
- errors.preferencia_contato && /* @__PURE__ */ jsx6(FormErrorMessage, { children: errors.preferencia_contato.message })
1859
+ errors.preferencia_contato && /* @__PURE__ */ jsx7(FormErrorMessage, { children: errors.preferencia_contato.message })
1496
1860
  ] }),
1497
- /* @__PURE__ */ jsx6("h6", { children: "* Campos de preenchimento obrigat\xF3rio." }),
1498
- /* @__PURE__ */ jsx6(ButtonContainer, { children: /* @__PURE__ */ jsx6(Button2, { bgColor: buttonBackgroundColor, color: buttonTextColor, type: "submit", isSubmitting: loading, children: "Enviar mensagem" }) }),
1499
- /* @__PURE__ */ jsxs6("p", { children: [
1861
+ /* @__PURE__ */ jsx7("h6", { children: "* Campos de preenchimento obrigat\xF3rio." }),
1862
+ /* @__PURE__ */ jsx7(ButtonContainer, { children: /* @__PURE__ */ jsx7(Button2, { bgColor: buttonBackgroundColor, color: buttonTextColor, type: "submit", isSubmitting: loading, children: canal === "whatsapp" ? WHATSAPP_BUTTON_TEXT : canal === "chat" ? CHAT_BUTTON_TEXT : "Enviar mensagem" }) }),
1863
+ /* @__PURE__ */ jsxs7("p", { children: [
1500
1864
  "A Mitre Realty respeita a sua privacidade e utiliza os seus dados pessoais para contat\xE1-lo por e-mail ou telefone aqui registrados. Para saber mais, acesse a nossa",
1501
1865
  " ",
1502
- /* @__PURE__ */ jsx6(
1866
+ /* @__PURE__ */ jsx7(
1503
1867
  "a",
1504
1868
  {
1505
1869
  href: "https://www.mitrerealty.com.br/politica-de-privacidade",