@agrada_digital/pbm 0.0.115 → 0.0.117

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
@@ -50,6 +50,7 @@ var initialPBMState = {
50
50
  grossPrice: 0
51
51
  },
52
52
  benefitsEnabled: true,
53
+ benefitsList: null,
53
54
  targetProduct: null,
54
55
  campaign: "pbm_campaign",
55
56
  isAuthenticatedShopper: false,
@@ -67,7 +68,8 @@ var createPBMStore = (set) => ({
67
68
  setIsAuthenticatedShopper: (isAuthenticatedShopper) => set({ isAuthenticatedShopper }),
68
69
  setCustomLoginUrl: (customLoginUrl) => set({ customLoginUrl }),
69
70
  setCardID: (cardID) => set({ cardID }),
70
- setBenefitsEnabled: (benefitsEnabled) => set({ benefitsEnabled })
71
+ setBenefitsEnabled: (benefitsEnabled) => set({ benefitsEnabled }),
72
+ setBenefitsList: (benefitsList) => set({ benefitsList })
71
73
  });
72
74
  var pbmStore = createStore(createPBMStore);
73
75
  function usePBMStore(selector) {
@@ -84,44 +86,6 @@ import { ArrowRight } from "lucide-react";
84
86
  import classNames2 from "classnames";
85
87
  import { Activity, useState } from "react";
86
88
 
87
- // src/services/lookup-customer.ts
88
- import Cookies from "js-cookie";
89
-
90
- // src/services/helper.ts
91
- var getEnv = (key) => {
92
- if (typeof import.meta !== "undefined") {
93
- return import.meta.env?.[key];
94
- }
95
- if (typeof process !== "undefined") {
96
- return process.env?.[key];
97
- }
98
- return void 0;
99
- };
100
-
101
- // src/services/lookup-customer.ts
102
- var LookupCustomer = async ({ DOCUMENT }) => {
103
- const API_URL = getEnv("VITE_API_URL");
104
- const AUTH_TOKEN = Cookies.get("pbm-token");
105
- if (!AUTH_TOKEN) {
106
- throw new Error("Token is not defined in cookies or is expired");
107
- }
108
- const response = await fetch(`${API_URL}/programregistration/${DOCUMENT}`, {
109
- method: "GET",
110
- headers: {
111
- Authorization: `Bearer ${AUTH_TOKEN}`,
112
- "Content-Type": "application/json"
113
- }
114
- });
115
- if (response.status === 404) {
116
- return {
117
- ...await response.json(),
118
- success: false
119
- };
120
- }
121
- const dataResponse = await response.json();
122
- return dataResponse;
123
- };
124
-
125
89
  // src/libs/zustand/useModal.tsx
126
90
  import { create } from "zustand";
127
91
  var initialModalState = {
@@ -144,58 +108,84 @@ var formatPhone = (value) => value.replace(/\D/g, "").slice(0, 11).replace(/^(\d
144
108
  var formatCEP = (value) => value.replace(/\D/g, "").slice(0, 8).replace(/^(\d{5})(\d{0,3})/, "$1-$2");
145
109
  var maskCPF = (value) => value.replace(/\D/g, "").replace(/(\d{3})(\d{3})(\d{3})(\d{2})/, "$1.$2.$3-$4");
146
110
  var formatPrice = (price) => Number(String(price).replace(",", "."));
111
+ var transformPrice = (price) => {
112
+ const priceString = String(price);
113
+ const cents = priceString.slice(-2);
114
+ const reais = priceString.slice(0, -2) || "0";
115
+ return Number(`${reais}.${cents}`);
116
+ };
117
+ var transformPorcent = (porcent) => {
118
+ const post = porcent.slice(-2);
119
+ const pre = porcent.slice(0, -2) || "0";
120
+ return Number(`${pre}.${post}`);
121
+ };
122
+ function priceToInteger(value) {
123
+ return value.replace(/[.,]/g, "");
124
+ }
147
125
  var formaters = {
148
126
  phone: (value) => formatPhone(value),
149
127
  cep: (value) => formatCEP(value),
150
128
  cpf: (value) => maskCPF(value),
151
- price: (price) => formatPrice(price)
129
+ priceToInteger: (value) => priceToInteger(value),
130
+ price: (price) => formatPrice(price),
131
+ transformPrice: (price) => transformPrice(price),
132
+ transformPorcent: (porcent) => transformPorcent(porcent)
152
133
  };
153
134
 
154
- // src/libs/zustand/usePBMForm.tsx
155
- import { create as create2 } from "zustand";
156
- var initialPBMFormState = {
157
- personalData: { name: "", phone: "", birthday: "", email: "" },
158
- address: {
159
- postalcode: "",
160
- number: "",
161
- complement: "",
162
- street: "",
163
- neighborhood: "",
164
- city: "",
165
- stateAddress: ""
166
- },
167
- genderResponsibility: { gender: "", patient: null },
168
- doctor: { typeCredential: "CRM", register: "", state: "", doctorName: "" },
169
- acceptances: {
170
- acceptPhone: false,
171
- acceptsSms: false,
172
- acceptsEmail: false,
173
- acceptsMail: false,
174
- acceptsPrivacyTermsLGPD: false
175
- },
176
- step: 0
135
+ // src/services/lookup-consumer.ts
136
+ import Cookies from "js-cookie";
137
+
138
+ // src/services/helper.ts
139
+ var getEnv = (key) => {
140
+ if (typeof import.meta !== "undefined") {
141
+ return import.meta.env?.[key];
142
+ }
143
+ if (typeof process !== "undefined") {
144
+ return process.env?.[key];
145
+ }
146
+ return void 0;
177
147
  };
178
- var usePBMFormStore = create2((set) => ({
179
- ...initialPBMFormState,
180
- setPersonalData: (data) => set((s) => ({ personalData: { ...s.personalData, ...data } })),
181
- setAddress: (data) => set((s) => ({ address: { ...s.address, ...data } })),
182
- setGenderResponsibility: (data) => set((s) => ({
183
- genderResponsibility: { ...s.genderResponsibility, ...data }
184
- })),
185
- setDoctor: (data) => set((s) => ({ doctor: { ...s.doctor, ...data } })),
186
- setAcceptances: (data) => set((s) => ({ acceptances: { ...s.acceptances, ...data } })),
187
- setStep: (step) => set({ step }),
188
- resetForm: () => set(initialPBMFormState)
189
- }));
190
- var usePBMForm = usePBMFormStore;
191
148
 
192
- // src/utils/mappingFormStep.ts
193
- var mappingFormStep = {
194
- "PersonalData": 0,
195
- "Address": 1,
196
- "GenderResponsibility": 2,
197
- "Doctor": 3,
198
- "Acceptances": 4
149
+ // src/services/lookup-consumer.ts
150
+ var LookupConsumer = async ({ product, consumer }) => {
151
+ const tenant_id = Cookies.get("tenant_id");
152
+ if (!tenant_id) {
153
+ throw new Error(`No configuration found for tenant: ${tenant_id}`);
154
+ }
155
+ if (!consumer || !consumer.holderId) {
156
+ throw new Error(`Consumer holderId information is required`);
157
+ }
158
+ if (!product) {
159
+ throw new Error(`Product information is required`);
160
+ }
161
+ try {
162
+ const response = await fetch(
163
+ `${getEnv("VITE_API_URL")}/api/lookup-consumer.ts`,
164
+ {
165
+ method: "POST",
166
+ headers: {
167
+ "Content-Type": "application/json",
168
+ "Accept": "application/json",
169
+ "Authorization": `Bearer ${Cookies.get("pbm-token")}`
170
+ },
171
+ body: JSON.stringify({
172
+ tenant_id,
173
+ product,
174
+ table_id: Cookies.get("current-table-id"),
175
+ local_hour: Cookies.get("current-local-hour"),
176
+ consumer
177
+ })
178
+ }
179
+ );
180
+ const data = await response.json();
181
+ if (!data.success) {
182
+ throw new Error("PBMLOG: Enable Discount Failed!");
183
+ }
184
+ return data;
185
+ } catch (error) {
186
+ console.error("Error during enable discount:", error);
187
+ return { success: false, error: "Authorization failed" };
188
+ }
199
189
  };
200
190
 
201
191
  // src/components/Form/index.tsx
@@ -204,7 +194,6 @@ function Form({ startTransition }) {
204
194
  const store = usePBMStore();
205
195
  const [showCardIDField, setShowCardIDField] = useState(false);
206
196
  const { setModal } = useModal();
207
- const { setStep } = usePBMForm();
208
197
  const {
209
198
  handleSubmit,
210
199
  register,
@@ -220,58 +209,12 @@ function Form({ startTransition }) {
220
209
  coupon: ""
221
210
  }
222
211
  });
223
- const CheckCustomerRegisterSteps = ({
224
- customer
225
- }) => {
226
- const data = customer.data;
227
- if (data.registration?.personal_data === null) {
228
- setStep(mappingFormStep["PersonalData"]);
229
- setModal({
230
- id: "CustomerNotRegistered",
231
- open: true
232
- });
233
- return;
234
- }
235
- if (data.registration?.address === null) {
236
- setStep(mappingFormStep["Address"]);
237
- setModal({
238
- id: "CustomerNotRegistered",
239
- open: true
240
- });
241
- return;
242
- }
243
- if (data.registration?.identity_responsibility === null) {
244
- setStep(mappingFormStep["GenderResponsibility"]);
245
- setModal({
246
- id: "CustomerNotRegistered",
247
- open: true
248
- });
249
- return;
250
- }
251
- if (data.registration?.medical_data === null) {
252
- setStep(mappingFormStep["Doctor"]);
253
- setModal({
254
- id: "CustomerNotRegistered",
255
- open: true
256
- });
257
- return;
258
- }
259
- if (data.registration?.lgpd === null) {
260
- setStep(mappingFormStep["Acceptances"]);
261
- setModal({
262
- id: "CustomerNotRegistered",
263
- open: true
264
- });
265
- return;
266
- }
267
- store.setState("isActivated");
268
- };
269
- const checkSecurityNumberBenefits = async (values) => {
212
+ const checkSecurityNumber = async (values) => {
270
213
  if (store.targetProduct === null) {
271
214
  console.error("PBMLOG: Product is not defined!");
272
215
  return;
273
216
  }
274
- if (!store.targetProduct.productId) {
217
+ if (!store.targetProduct.id) {
275
218
  console.error("PBMLOG: Product ID is not defined!");
276
219
  return;
277
220
  }
@@ -280,28 +223,11 @@ function Form({ startTransition }) {
280
223
  return;
281
224
  }
282
225
  store.setSecurityNumber(values.securityNumber.replace(/\D/g, ""));
283
- const customerIsRegistered = await LookupCustomer({
284
- DOCUMENT: values.securityNumber.replace(/\D/g, "")
226
+ const consumerHasDiscountEnabled = await LookupConsumer({
227
+ product: store.targetProduct,
228
+ consumer: { holderId: values.securityNumber.replace(/\D/g, "") }
285
229
  });
286
- if (customerIsRegistered.success) {
287
- if (!customerIsRegistered.data.requestId) {
288
- console.error(
289
- "PBMLOG: Request ID is not defined in lookup customer response"
290
- );
291
- return;
292
- }
293
- store.setRequestId(customerIsRegistered.data.requestId || "");
294
- CheckCustomerRegisterSteps({ customer: customerIsRegistered });
295
- return;
296
- }
297
- if (!customerIsRegistered.success) {
298
- if (!customerIsRegistered.requestId) {
299
- console.error(
300
- "PBMLOG: Request ID is not defined in lookup customer response for non registered customer"
301
- );
302
- return;
303
- }
304
- store.setRequestId(customerIsRegistered.requestId || "");
230
+ if (!consumerHasDiscountEnabled.success) {
305
231
  setModal({
306
232
  id: "CustomerNotRegistered",
307
233
  open: true
@@ -321,7 +247,7 @@ function Form({ startTransition }) {
321
247
  store.setCardID(values.coupon);
322
248
  }
323
249
  startTransition(async () => {
324
- await checkSecurityNumberBenefits(values);
250
+ await checkSecurityNumber(values);
325
251
  });
326
252
  };
327
253
  return /* @__PURE__ */ jsxs(Fragment, { children: [
@@ -337,7 +263,7 @@ function Form({ startTransition }) {
337
263
  /* @__PURE__ */ jsxs(
338
264
  "label",
339
265
  {
340
- htmlFor: "cpf",
266
+ htmlFor: "input_security_number_pbm",
341
267
  className: classNames2(
342
268
  "w-full h-auto flex items-start flex-col justify-center relative py-2 transition-all duration-100",
343
269
  {
@@ -389,7 +315,7 @@ function Form({ startTransition }) {
389
315
  /* @__PURE__ */ jsx2(Activity, { mode: showCardIDField ? "visible" : "hidden", children: /* @__PURE__ */ jsxs(
390
316
  "label",
391
317
  {
392
- htmlFor: "coupon",
318
+ htmlFor: "input_coupon_pbm",
393
319
  className: classNames2(
394
320
  "w-full h-auto flex items-start flex-col justify-center relative py-2",
395
321
  {
@@ -657,29 +583,46 @@ var Icons = {
657
583
  import { jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
658
584
  function Header({ originalProductPrice }) {
659
585
  const { targetProduct, benefitsEnabled, setBenefitsEnabled } = usePBMStore();
660
- const Price = targetProduct?.listPrice || originalProductPrice;
661
- const Discount = Price * ((targetProduct?.discountMax || 0) / 100);
586
+ const Price = formaters.transformPrice(
587
+ Number(targetProduct?.listPrice) || originalProductPrice
588
+ );
589
+ const DiscountValue = formaters.transformPrice(
590
+ Number(targetProduct?.discountValue) || 0
591
+ );
592
+ const DiscountPercentual = formaters.transformPorcent(
593
+ targetProduct?.discountMaxNewPatient || "0"
594
+ );
595
+ const DiscountPercentualValue = Price * DiscountPercentual / 100;
596
+ const DiscountApplied = Price - DiscountPercentualValue || Price - DiscountValue;
662
597
  return /* @__PURE__ */ jsxs3(
663
598
  "header",
664
599
  {
665
600
  className: "flex items-start justify-start flex-col gap-4 w-full p-0.5 rounded-xl mt-5",
666
601
  id: "header_pbm",
667
602
  children: [
668
- /* @__PURE__ */ jsxs3("label", { className: "flex items-center gap-2 cursor-pointer", children: [
669
- /* @__PURE__ */ jsx4(
670
- "input",
671
- {
672
- type: "checkbox",
673
- name: "option",
674
- className: "peer hidden",
675
- checked: benefitsEnabled,
676
- onChange: (e) => setBenefitsEnabled(e.target.checked)
677
- }
678
- ),
679
- /* @__PURE__ */ jsx4("div", { className: "w-5 h-5 border border-(--pbm-primary) rounded-full flex items-center justify-center transition-all duration-300 after:content-[''] after:w-2 after:h-2 after:rounded-full after:bg-(--pbm-primary) after:scale-0 after:transition-transform after:duration-200 peer-checked:after:scale-100" }),
680
- /* @__PURE__ */ jsx4("p", { className: "font-medium text-(--pbm-primary) select-none text-sm", children: "Desconto de Laborat\xF3rio" }),
681
- /* @__PURE__ */ jsx4(Icons.Pills, { size: 16, color: "var(--pbm-primary)" })
682
- ] }),
603
+ /* @__PURE__ */ jsxs3(
604
+ "label",
605
+ {
606
+ className: "flex items-center gap-2 cursor-pointer",
607
+ htmlFor: "enable_benefits_checkbox",
608
+ children: [
609
+ /* @__PURE__ */ jsx4(
610
+ "input",
611
+ {
612
+ id: "enable_benefits_checkbox",
613
+ type: "checkbox",
614
+ name: "option",
615
+ className: "peer hidden",
616
+ checked: benefitsEnabled,
617
+ onChange: (e) => setBenefitsEnabled(e.target.checked)
618
+ }
619
+ ),
620
+ /* @__PURE__ */ jsx4("div", { className: "w-5 h-5 border border-(--pbm-primary) rounded-full flex items-center justify-center transition-all duration-300 after:content-[''] after:w-2 after:h-2 after:rounded-full after:bg-(--pbm-primary) after:scale-0 after:transition-transform after:duration-200 peer-checked:after:scale-100" }),
621
+ /* @__PURE__ */ jsx4("p", { className: "font-medium text-(--pbm-primary) select-none text-sm", children: "Desconto de Laborat\xF3rio" }),
622
+ /* @__PURE__ */ jsx4(Icons.Pills, { size: 16, color: "var(--pbm-primary)" })
623
+ ]
624
+ }
625
+ ),
683
626
  /* @__PURE__ */ jsx4(
684
627
  "span",
685
628
  {
@@ -696,11 +639,11 @@ function Header({ originalProductPrice }) {
696
639
  }) }),
697
640
  /* @__PURE__ */ jsx4(Icons.ArrowDown, { size: 14, color: "var(--pbm-primary)" }),
698
641
  /* @__PURE__ */ jsxs3("span", { className: "font-semibold text-sm text-(--pbm-primary)", children: [
699
- (targetProduct?.discountMax || 0).toFixed(2),
642
+ DiscountPercentual.toFixed(2),
700
643
  "%"
701
644
  ] })
702
645
  ] }),
703
- /* @__PURE__ */ jsx4("span", { className: "text-lg text-zinc-700 font-bold", children: Number(Price - Discount)?.toLocaleString("pt-BR", {
646
+ /* @__PURE__ */ jsx4("span", { className: "text-lg text-zinc-700 font-bold", children: DiscountApplied?.toLocaleString("pt-BR", {
704
647
  currency: "BRL",
705
648
  currencyDisplay: "symbol",
706
649
  currencySign: "standard",
@@ -716,173 +659,20 @@ function Header({ originalProductPrice }) {
716
659
  }
717
660
  var Header_default = Header;
718
661
 
719
- // src/components/Iframe/index.tsx
720
- import classNames5 from "classnames";
721
- import { TriangleAlert, ExternalLink } from "lucide-react";
722
- import { useState as useState2, useEffect } from "react";
723
-
724
- // src/components/UI/Title/index.tsx
725
- import classNames3 from "classnames";
726
- import { jsx as jsx5 } from "react/jsx-runtime";
727
- function Title(props) {
728
- return /* @__PURE__ */ jsx5(
729
- "h2",
730
- {
731
- className: classNames3(
732
- "text-start font-semibold text-sm",
733
- props.className
734
- ),
735
- style: { color: props.textColor || "var(--pbm-text)", fontSize: props.textSize, textAlign: props.textAlign },
736
- "data-testid": "test_id_title",
737
- id: "title_pbm",
738
- children: props.children
739
- }
740
- );
741
- }
742
- var Title_default = Title;
743
-
744
- // src/components/UI/Text/index.tsx
745
- import classNames4 from "classnames";
746
- import { jsx as jsx6 } from "react/jsx-runtime";
747
- function Text(props) {
748
- return /* @__PURE__ */ jsx6(
749
- "p",
750
- {
751
- className: classNames4(
752
- "font-normal text-sm",
753
- props.textAlign && `text-${props.textAlign}`,
754
- props.className
755
- ),
756
- style: { color: props.textColor || "var(--pbm-text)", fontSize: props.textSize, textAlign: props.textAlign },
757
- "data-testid": "test_id_text",
758
- id: "text_pbm",
759
- children: props.children
760
- }
761
- );
762
- }
763
- var Text_default = Text;
764
-
765
- // src/components/Iframe/index.tsx
766
- import { jsx as jsx7, jsxs as jsxs4 } from "react/jsx-runtime";
767
- function Iframe() {
768
- const [showFallback, setShowFallback] = useState2(false);
769
- const { setState } = usePBMStore();
770
- const { resetModal, modal } = useModal();
771
- const isOpen = modal.open && modal.id === "iframe_pbm";
772
- useEffect(() => {
773
- if (isOpen) {
774
- setShowFallback(false);
775
- }
776
- }, [isOpen, modal.url]);
777
- const handleOpenInNewWindow = () => {
778
- if (modal.url) {
779
- window.open(modal.url, "_blank", "noopener,noreferrer");
780
- }
781
- };
782
- const handleClose = () => {
783
- setState("isEmpty");
784
- resetModal();
785
- };
786
- if (!modal.url) return;
787
- return /* @__PURE__ */ jsxs4(
788
- "main",
789
- {
790
- className: classNames5(
791
- "fixed inset-0 flex items-center justify-center z-50 flex-col transition-all duration-300 pt-[10%]",
792
- isOpen ? "opacity-100 pointer-events-auto" : "opacity-0 pointer-events-none"
793
- ),
794
- id: "iframe_pbm",
795
- children: [
796
- /* @__PURE__ */ jsx7(
797
- "div",
798
- {
799
- className: "bg-black/40 inset-0 absolute backdrop-blur-sm",
800
- onClick: handleClose
801
- }
802
- ),
803
- /* @__PURE__ */ jsxs4("section", { className: "w-[90%] md:w-4/5 gap-4 h-auto bg-zinc-900 py-3 px-6 flex items-center justify-end rounded-t-2xl border-b border-white/10 z-10 shadow-2xl", children: [
804
- /* @__PURE__ */ jsx7(
805
- Button_default,
806
- {
807
- onClick: handleClose,
808
- className: "bg-red-500 hover:bg-red-400 w-auto px-6 h-9 transition-all active:scale-95 shadow-lg text-xs md:text-sm",
809
- children: "Cancelar"
810
- }
811
- ),
812
- /* @__PURE__ */ jsx7(
813
- Button_default,
814
- {
815
- onClick: handleClose,
816
- className: "bg-blue-600 hover:bg-blue-500 w-auto px-6 h-9 transition-all active:scale-95 shadow-lg text-xs md:text-sm",
817
- children: "Finalizei o formul\xE1rio"
818
- }
819
- )
820
- ] }),
821
- /* @__PURE__ */ jsx7("div", { className: "w-[90%] md:w-4/5 h-[60vh] bg-zinc-900 z-10 overflow-hidden relative shadow-2xl", children: showFallback ? /* @__PURE__ */ jsxs4("div", { className: "absolute inset-0 flex flex-col items-center justify-center p-8 text-center bg-zinc-900", children: [
822
- /* @__PURE__ */ jsx7("div", { className: "bg-yellow-500/10 p-4 rounded-full mb-4 animate-pulse", children: /* @__PURE__ */ jsx7(TriangleAlert, { size: 48, className: "text-yellow-500" }) }),
823
- /* @__PURE__ */ jsx7(Title_default, { textColor: "white", textSize: "20px", textAlign: "center", className: "mb-2", children: "N\xE3o foi poss\xEDvel carregar o conte\xFAdo" }),
824
- /* @__PURE__ */ jsx7(Text_default, { textColor: "#a1a1aa", textAlign: "center", className: "mb-8 max-w-md", children: "Este conte\xFAdo n\xE3o permite exibi\xE7\xE3o integrada por seguran\xE7a. Clique no bot\xE3o abaixo para concluir em uma nova aba." }),
825
- /* @__PURE__ */ jsxs4(
826
- Button_default,
827
- {
828
- onClick: handleOpenInNewWindow,
829
- className: "flex items-center gap-2 w-auto px-8 h-12 shadow-xl shadow-emerald-500/20",
830
- children: [
831
- /* @__PURE__ */ jsx7(ExternalLink, { size: 18 }),
832
- "Abrir em nova janela"
833
- ]
834
- }
835
- )
836
- ] }) : /* @__PURE__ */ jsx7(
837
- "iframe",
838
- {
839
- src: modal.url,
840
- title: modal.label ?? "Conte\xFAdo PBM",
841
- className: "w-full h-full border-none bg-white animate-fade-in",
842
- allowFullScreen: true,
843
- onError: () => setShowFallback(true)
844
- }
845
- ) }),
846
- /* @__PURE__ */ jsxs4("section", { className: "w-[90%] md:w-4/5 flex flex-col md:flex-row items-center justify-between gap-3 bg-zinc-900 py-4 px-6 rounded-b-2xl border-t border-white/5 z-10 shadow-2xl", children: [
847
- /* @__PURE__ */ jsxs4("div", { className: "flex items-center gap-2", children: [
848
- /* @__PURE__ */ jsx7(TriangleAlert, { size: 18, className: "text-yellow-500 shrink-0" }),
849
- /* @__PURE__ */ jsxs4(Text_default, { textColor: "white", className: "text-[10px] md:text-xs", children: [
850
- /* @__PURE__ */ jsx7("span", { className: "text-yellow-500 font-bold mr-1", children: "Importante:" }),
851
- "Se a p\xE1gina n\xE3o carregar, tente abrir em tela cheia usando o bot\xE3o ao lado."
852
- ] })
853
- ] }),
854
- /* @__PURE__ */ jsxs4(
855
- "button",
856
- {
857
- onClick: handleOpenInNewWindow,
858
- className: "text-white/60 hover:text-white text-[11px] underline flex items-center gap-1 transition-colors cursor-pointer",
859
- children: [
860
- /* @__PURE__ */ jsx7(ExternalLink, { size: 14 }),
861
- " Abrir em nova aba"
862
- ]
863
- }
864
- )
865
- ] })
866
- ]
867
- }
868
- );
869
- }
870
- var Iframe_default = Iframe;
871
-
872
662
  // src/components/UI/Loading/index.tsx
873
- import { jsx as jsx8, jsxs as jsxs5 } from "react/jsx-runtime";
663
+ import { jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
874
664
  function Loading({ textColor }) {
875
- return /* @__PURE__ */ jsxs5("main", { className: "flex items-center justify-center gap-4", id: "loading_pbm", children: [
876
- /* @__PURE__ */ jsx8(
665
+ return /* @__PURE__ */ jsxs4("main", { className: "flex items-center justify-center gap-4", id: "loading_pbm", children: [
666
+ /* @__PURE__ */ jsx5(
877
667
  "div",
878
668
  {
879
669
  "data-testid": "test_id_spin",
880
- className: "w-8 h-8 border-4 border-gray-300 rounded-full animate-spin",
670
+ className: "w-8 h-8 border-4 shrink-0 border-gray-300 rounded-full animate-spin",
881
671
  style: { borderTopColor: "var(--pbm-secondary)" },
882
672
  id: "loading_spin"
883
673
  }
884
674
  ),
885
- /* @__PURE__ */ jsx8(
675
+ /* @__PURE__ */ jsx5(
886
676
  "p",
887
677
  {
888
678
  className: "text-sm font-semibold text-start",
@@ -896,17 +686,17 @@ function Loading({ textColor }) {
896
686
  var Loading_default = Loading;
897
687
 
898
688
  // src/components/UI/Container/index.tsx
899
- import classNames6 from "classnames";
900
- import { jsx as jsx9 } from "react/jsx-runtime";
689
+ import classNames3 from "classnames";
690
+ import { jsx as jsx6 } from "react/jsx-runtime";
901
691
  function Container({
902
692
  children,
903
693
  variant
904
694
  }) {
905
695
  const { benefitsEnabled } = usePBMStore();
906
- return /* @__PURE__ */ jsx9(
696
+ return /* @__PURE__ */ jsx6(
907
697
  "main",
908
698
  {
909
- className: classNames6({
699
+ className: classNames3({
910
700
  "border-3 border-(--pbm-border) overflow-hidden flex flex-col items-center justify-center min-w-(--min-container) max-w-(--max-container) w-full h-auto rounded-xl p-4 bg-white gap-4 relative": variant === "main",
911
701
  "w-full relative": variant === "simple",
912
702
  "h-0 overflow-hidden": !benefitsEnabled && variant === "simple"
@@ -920,83 +710,60 @@ function Container({
920
710
  }
921
711
  var Container_default = Container;
922
712
 
923
- // src/services/activate-customer.ts
924
- import Cookies2 from "js-cookie";
925
- var ActivateCustomer = async ({ document, requestId, products }) => {
926
- const API_URL = getEnv("VITE_API_URL");
927
- if (!API_URL) {
928
- throw new Error("API URL is not defined in environment variables");
929
- }
930
- const AUTH_TOKEN = Cookies2.get("pbm-token");
931
- if (!AUTH_TOKEN) {
932
- throw new Error("Token is not defined in cookies or is expired");
933
- }
934
- const response = await fetch(`${API_URL}/programregistration/activate`, {
935
- method: "POST",
936
- headers: {
937
- Authorization: `Bearer ${AUTH_TOKEN}`,
938
- "Content-Type": "application/json"
939
- },
940
- body: JSON.stringify({ document, requestId, products })
941
- });
942
- const dataResponse = await response.json();
943
- if (!dataResponse.success) {
944
- throw new Error(dataResponse.message || "Failed to fetch document validation");
945
- }
946
- return dataResponse;
947
- };
948
-
949
- // src/services/benefits-without-document.ts
950
- import Cookies3 from "js-cookie";
951
- var CheckBenefistWithoutDocument = async ({ products }) => {
952
- const API_URL = getEnv("VITE_API_URL");
953
- if (!API_URL) {
954
- throw new Error("API URL is not defined in environment variables");
955
- }
956
- const AUTH_TOKEN = Cookies3.get("pbm-token");
957
- if (!AUTH_TOKEN) {
958
- throw new Error("Token is not defined in cookies or is expired");
959
- }
960
- const response = await fetch(`${API_URL}/products/genericBenefit`, {
961
- method: "POST",
962
- headers: {
963
- Authorization: `Bearer ${AUTH_TOKEN}`,
964
- "Content-Type": "application/json"
965
- },
966
- body: JSON.stringify({ products })
967
- });
968
- const dataResponse = await response.json();
969
- if (!dataResponse.success) {
970
- throw new Error(dataResponse.message || "Failed to fetch benefits without document");
971
- }
972
- return dataResponse;
973
- };
713
+ // src/components/UI/Title/index.tsx
714
+ import classNames4 from "classnames";
715
+ import { jsx as jsx7 } from "react/jsx-runtime";
716
+ function Title(props) {
717
+ return /* @__PURE__ */ jsx7(
718
+ "h2",
719
+ {
720
+ className: classNames4(
721
+ "text-start font-semibold text-sm",
722
+ props.className
723
+ ),
724
+ style: { color: props.textColor || "var(--pbm-text)", fontSize: props.textSize, textAlign: props.textAlign },
725
+ "data-testid": "test_id_title",
726
+ id: "title_pbm",
727
+ children: props.children
728
+ }
729
+ );
730
+ }
731
+ var Title_default = Title;
974
732
 
975
733
  // src/components/BenefitsTable/index.tsx
976
- import { useEffect as useEffect3, useState as useState3, useTransition } from "react";
734
+ import { useState as useState2, useTransition } from "react";
977
735
 
978
736
  // src/components/BenefitsTable/Item.tsx
979
- import { useCallback, useEffect as useEffect2 } from "react";
980
- import classNames7 from "classnames";
981
- import { jsx as jsx10, jsxs as jsxs6 } from "react/jsx-runtime";
737
+ import { useCallback, useEffect } from "react";
738
+ import classNames5 from "classnames";
739
+ import { jsx as jsx8, jsxs as jsxs5 } from "react/jsx-runtime";
982
740
  function Item({ data, onChange, checked }) {
983
741
  const { setAvailableDiscountSelected, state, isAuthenticatedShopper } = usePBMStore();
984
742
  const { setModal } = useModal();
985
- const ID_INPUT = "unity_quantity_" + data.authorizedQuantity;
986
- const decimalDiscount = data.discountPercentual / 100;
987
- const unitDiscountValue = data.grossPrice * decimalDiscount;
988
- const discountValue = unitDiscountValue * data.authorizedQuantity;
989
- const totalPriceProductWithDiscountBenefit = data.grossPrice * data.authorizedQuantity - discountValue;
743
+ const ID_INPUT = data.id + "_" + data.authorizedQuantity;
744
+ const PricePerUnity = formaters.transformPrice(
745
+ Number(data?.grossPrice) || Number(data?.listPrice) || 0
746
+ );
747
+ const DiscountValuePerUnity = formaters.transformPrice(
748
+ Number(data?.discountValue) || 0
749
+ );
750
+ const DiscountPercentual = formaters.transformPorcent(
751
+ data?.discountPercentual || "0"
752
+ );
753
+ const TotalDiscountValue = DiscountValuePerUnity * data.authorizedQuantity;
754
+ const TotalPricePerQuantity = PricePerUnity * data.authorizedQuantity;
755
+ const DiscountPercentualValue = TotalPricePerQuantity * DiscountPercentual / 100;
756
+ const AppliedDiscount = TotalPricePerQuantity - DiscountPercentualValue || TotalPricePerQuantity - TotalDiscountValue;
990
757
  const updateStorageData = useCallback(() => {
991
758
  if (checked) {
992
759
  const roundToTwoDecimals = (value) => Math.round(value * 100) / 100;
993
760
  setAvailableDiscountSelected({
994
761
  discount: {
995
- total: roundToTwoDecimals(discountValue),
996
- unit: roundToTwoDecimals(unitDiscountValue)
762
+ total: roundToTwoDecimals(TotalDiscountValue),
763
+ unit: roundToTwoDecimals(DiscountValuePerUnity)
997
764
  },
998
765
  quantity: data.authorizedQuantity,
999
- totalPrice: roundToTwoDecimals(totalPriceProductWithDiscountBenefit),
766
+ totalPrice: roundToTwoDecimals(AppliedDiscount),
1000
767
  grossPrice: data.grossPrice
1001
768
  });
1002
769
  }
@@ -1005,11 +772,11 @@ function Item({ data, onChange, checked }) {
1005
772
  data.authorizedQuantity,
1006
773
  data.grossPrice,
1007
774
  setAvailableDiscountSelected,
1008
- discountValue,
1009
- totalPriceProductWithDiscountBenefit,
1010
- unitDiscountValue
775
+ TotalDiscountValue,
776
+ DiscountValuePerUnity,
777
+ AppliedDiscount
1011
778
  ]);
1012
- useEffect2(() => {
779
+ useEffect(() => {
1013
780
  updateStorageData();
1014
781
  }, [updateStorageData]);
1015
782
  const handleChange = () => {
@@ -1022,11 +789,11 @@ function Item({ data, onChange, checked }) {
1022
789
  }
1023
790
  onChange();
1024
791
  };
1025
- return /* @__PURE__ */ jsxs6(
792
+ return /* @__PURE__ */ jsxs5(
1026
793
  "label",
1027
794
  {
1028
795
  htmlFor: ID_INPUT,
1029
- className: classNames7(
796
+ className: classNames5(
1030
797
  "label_benefits w-full flex items-center justify-start bg-zinc-300/60 border border-zinc-400/50 px-4 py-2 transition-colors rounded-lg gap-1",
1031
798
  {
1032
799
  "cursor-not-allowed": state === "isPreview",
@@ -1040,7 +807,7 @@ function Item({ data, onChange, checked }) {
1040
807
  },
1041
808
  id: "label_benefits_" + ID_INPUT,
1042
809
  children: [
1043
- /* @__PURE__ */ jsx10(
810
+ /* @__PURE__ */ jsx8(
1044
811
  "input",
1045
812
  {
1046
813
  type: "radio",
@@ -1052,8 +819,8 @@ function Item({ data, onChange, checked }) {
1052
819
  disabled: state === "isPreview"
1053
820
  }
1054
821
  ),
1055
- /* @__PURE__ */ jsx10("span", { style: { color: "var(--pbm-primary)" }, children: !checked ? /* @__PURE__ */ jsx10(Icons.CheckOFF, { size: 20 }) : /* @__PURE__ */ jsx10(Icons.CheckON, { size: 20 }) }),
1056
- /* @__PURE__ */ jsxs6(
822
+ /* @__PURE__ */ jsx8("span", { style: { color: "var(--pbm-primary)" }, children: !checked ? /* @__PURE__ */ jsx8(Icons.CheckOFF, { size: 20 }) : /* @__PURE__ */ jsx8(Icons.CheckON, { size: 20 }) }),
823
+ /* @__PURE__ */ jsxs5(
1057
824
  "span",
1058
825
  {
1059
826
  className: "font-semibold text-sm",
@@ -1064,14 +831,14 @@ function Item({ data, onChange, checked }) {
1064
831
  ]
1065
832
  }
1066
833
  ),
1067
- /* @__PURE__ */ jsxs6("section", { className: "ml-auto relative gap-2 flex items-center-safe justify-end-safe", children: [
1068
- /* @__PURE__ */ jsxs6(
834
+ /* @__PURE__ */ jsxs5("section", { className: "ml-auto relative gap-2 flex items-center-safe justify-end-safe", children: [
835
+ /* @__PURE__ */ jsxs5(
1069
836
  "span",
1070
837
  {
1071
838
  className: "text-white -top-4 py-0.5 font-semibold text-xs px-2 w-auto text-nowrap rounded-2xl -right-3",
1072
839
  style: { backgroundColor: "var(--pbm-primary)" },
1073
840
  children: [
1074
- discountValue.toLocaleString("pt-BR", {
841
+ TotalDiscountValue.toLocaleString("pt-BR", {
1075
842
  currency: "BRL",
1076
843
  currencyDisplay: "symbol",
1077
844
  currencySign: "standard",
@@ -1082,12 +849,12 @@ function Item({ data, onChange, checked }) {
1082
849
  ]
1083
850
  }
1084
851
  ),
1085
- /* @__PURE__ */ jsx10(
852
+ /* @__PURE__ */ jsx8(
1086
853
  "strong",
1087
854
  {
1088
855
  className: "font-semibold text-sm text-center",
1089
856
  style: { color: "var(--pbm-text)" },
1090
- children: totalPriceProductWithDiscountBenefit.toLocaleString("pt-BR", {
857
+ children: AppliedDiscount.toLocaleString("pt-BR", {
1091
858
  currency: "BRL",
1092
859
  currencyDisplay: "symbol",
1093
860
  currencySign: "standard",
@@ -1102,104 +869,30 @@ function Item({ data, onChange, checked }) {
1102
869
  }
1103
870
  var Item_default = Item;
1104
871
 
872
+ // src/utils/approved-code.ts
873
+ var APPROVED_BENEFIT_CODE = "N000";
874
+
1105
875
  // src/components/BenefitsTable/index.tsx
1106
- import { Fragment as Fragment2, jsx as jsx11, jsxs as jsxs7 } from "react/jsx-runtime";
876
+ import { Fragment as Fragment2, jsx as jsx9, jsxs as jsxs6 } from "react/jsx-runtime";
1107
877
  function BenefitsTable() {
1108
- const [isPending, startTransition] = useTransition();
878
+ const [isPending] = useTransition();
1109
879
  const {
1110
- securityNumber,
880
+ // securityNumber,
1111
881
  setState,
1112
882
  state,
1113
- targetProduct,
883
+ // targetProduct,
1114
884
  customLoginUrl,
1115
885
  isAuthenticatedShopper,
1116
- requestId
886
+ // requestId,
887
+ benefitsList
1117
888
  } = usePBMStore();
1118
- const [selectedDiscout, setSelectedDiscount] = useState3(null);
1119
- const [benefitsItems, setBenefitsItems] = useState3();
1120
- useEffect3(() => {
1121
- if (!targetProduct?.productId) {
1122
- console.error("PBMLOG: Product ID is not defined on targetProduct");
1123
- return;
1124
- }
1125
- if (!targetProduct.ean) {
1126
- console.error("PBMLOG: EAN is not defined on targetProduct");
1127
- return;
1128
- }
1129
- if (!targetProduct.listPrice) {
1130
- console.error("PBMLOG: List Price is not defined on targetProduct");
1131
- return;
1132
- }
1133
- if (!targetProduct.price) {
1134
- console.error("PBMLOG: Price is not defined on targetProduct");
1135
- return;
1136
- }
1137
- const fetchDicountsWithoutDocument = async () => {
1138
- try {
1139
- const data = {
1140
- productId: Number(targetProduct.productId),
1141
- ean: targetProduct.ean,
1142
- requestedQuantity: 1,
1143
- listPrice: targetProduct.listPrice,
1144
- netPrice: targetProduct.price
1145
- };
1146
- const response = await CheckBenefistWithoutDocument({
1147
- products: [data]
1148
- });
1149
- if (response.success && response.data) {
1150
- setBenefitsItems(response.data);
1151
- } else {
1152
- setBenefitsItems(void 0);
1153
- }
1154
- } catch (error) {
1155
- setBenefitsItems(void 0);
1156
- console.error(error);
1157
- }
1158
- };
1159
- const fetchDiscountWithDocument = async () => {
1160
- if (!securityNumber) {
1161
- console.error("PBMLOG: Document is not defined");
1162
- return;
1163
- }
1164
- if (!requestId) {
1165
- console.error("PBMLOG: Request ID is not defined");
1166
- return;
1167
- }
1168
- try {
1169
- const data = {
1170
- productId: Number(targetProduct.productId),
1171
- ean: targetProduct.ean,
1172
- quantity: 1,
1173
- listPrice: targetProduct.listPrice
1174
- };
1175
- const response = await ActivateCustomer({
1176
- document: securityNumber,
1177
- requestId,
1178
- products: [data]
1179
- });
1180
- if (response.success && response.data) {
1181
- setBenefitsItems(response.data.product);
1182
- } else {
1183
- setBenefitsItems(void 0);
1184
- }
1185
- } catch (error) {
1186
- setBenefitsItems(void 0);
1187
- console.error(error);
1188
- }
1189
- };
1190
- startTransition(async () => {
1191
- if (state === "isActivated") {
1192
- await fetchDiscountWithDocument();
1193
- } else {
1194
- await fetchDicountsWithoutDocument();
1195
- }
1196
- });
1197
- }, []);
889
+ const [selectedDiscout, setSelectedDiscount] = useState2(null);
890
+ const [benefitsItems] = useState2(benefitsList);
1198
891
  if (isPending) {
1199
- return /* @__PURE__ */ jsx11(Loading_default, { textColor: "var(--pbm-text)" });
892
+ return /* @__PURE__ */ jsx9(Loading_default, { textColor: "var(--pbm-text)" });
1200
893
  }
1201
- if (benefitsItems?.length && benefitsItems[0]?.statusCode == null && state === "isActivated") {
1202
- return /* @__PURE__ */ jsx11("main", { className: "flex items-center justify-center gap-4", id: "loading_pbm", children: /* @__PURE__ */ jsx11(
894
+ if (benefitsItems?.length && benefitsItems[0]?.returnCode !== APPROVED_BENEFIT_CODE && state === "isActivated") {
895
+ return /* @__PURE__ */ jsx9("main", { className: "flex items-center justify-center gap-4", id: "loading_pbm", children: /* @__PURE__ */ jsx9(
1203
896
  "p",
1204
897
  {
1205
898
  className: "text-sm font-semibold text-start",
@@ -1209,21 +902,21 @@ function BenefitsTable() {
1209
902
  }
1210
903
  ) });
1211
904
  }
1212
- return /* @__PURE__ */ jsxs7(
905
+ return /* @__PURE__ */ jsxs6(
1213
906
  "section",
1214
907
  {
1215
908
  className: "flex items-start justify-center gap-4 w-full h-auto flex-col",
1216
909
  id: "benefits_table_pbm",
1217
910
  children: [
1218
- /* @__PURE__ */ jsx11(Title_default, { children: "Descontos dispon\xEDveis:" }),
1219
- /* @__PURE__ */ jsxs7(
911
+ /* @__PURE__ */ jsx9(Title_default, { children: "Descontos dispon\xEDveis:" }),
912
+ /* @__PURE__ */ jsxs6(
1220
913
  "form",
1221
914
  {
1222
915
  className: "flex flex-col items-center justify-start w-full gap-4.5",
1223
916
  id: "form_benefits_table_pbm",
1224
917
  onSubmit: (e) => e.preventDefault(),
1225
918
  children: [
1226
- !benefitsItems && /* @__PURE__ */ jsx11(
919
+ !benefitsItems && /* @__PURE__ */ jsx9(
1227
920
  "p",
1228
921
  {
1229
922
  className: "text-sm font-semibold text-start text-zinc-900",
@@ -1231,22 +924,22 @@ function BenefitsTable() {
1231
924
  children: "N\xE3o foi poss\xEDvel encontrar benef\xEDcios para esse produto."
1232
925
  }
1233
926
  ),
1234
- benefitsItems && benefitsItems.map((item, index) => {
1235
- const ID_INPUT = "unity_quantity_" + item.authorizedQuantity;
1236
- return /* @__PURE__ */ jsx11(
927
+ benefitsItems && benefitsItems.map((item) => {
928
+ const ID_INPUT = item.id + "_" + item.authorizedQuantity;
929
+ return /* @__PURE__ */ jsx9(
1237
930
  Item_default,
1238
931
  {
1239
932
  data: item,
1240
933
  checked: selectedDiscout === ID_INPUT,
1241
934
  onChange: () => setSelectedDiscount(ID_INPUT)
1242
935
  },
1243
- index
936
+ ID_INPUT
1244
937
  );
1245
938
  })
1246
939
  ]
1247
940
  }
1248
941
  ),
1249
- state === "isPreview" && /* @__PURE__ */ jsxs7(
942
+ state === "isPreview" && /* @__PURE__ */ jsxs6(
1250
943
  Button_default,
1251
944
  {
1252
945
  onClick: () => setState("isEmpty"),
@@ -1255,28 +948,28 @@ function BenefitsTable() {
1255
948
  children: [
1256
949
  "Aten\xE7\xE3o: N\xE3o \xE9 poss\xEDvel utilizar os benef\xEDcos sem realizar a consulta do CPF e o Login, por favor",
1257
950
  " ",
1258
- /* @__PURE__ */ jsx11("span", { className: "underline", children: "insira seu cpf para utilizar os benef\xEDcios" })
951
+ /* @__PURE__ */ jsx9("span", { className: "underline", children: "insira seu cpf para utilizar os benef\xEDcios" })
1259
952
  ]
1260
953
  }
1261
954
  ),
1262
- state === "isActivated" && /* @__PURE__ */ jsxs7(Fragment2, { children: [
1263
- !isAuthenticatedShopper && /* @__PURE__ */ jsx11(
955
+ state === "isActivated" && /* @__PURE__ */ jsxs6(Fragment2, { children: [
956
+ !isAuthenticatedShopper && /* @__PURE__ */ jsx9(
1264
957
  Button_default,
1265
958
  {
1266
959
  type: "button",
1267
960
  onClick: () => window.location.assign(customLoginUrl || "/login"),
1268
961
  className: "bg-transparent p-0 pl-2 w-auto h-auto text-zinc-600 cursor-pointer hover:text-zinc-900 hover:bg-transparent text-start",
1269
962
  id: "login",
1270
- children: /* @__PURE__ */ jsx11("span", { className: "underline", children: "Por favor, fa\xE7a o Login para aproveitar os benef\xEDcios!" })
963
+ children: /* @__PURE__ */ jsx9("span", { className: "underline", children: "Por favor, fa\xE7a o Login para aproveitar os benef\xEDcios!" })
1271
964
  }
1272
965
  ),
1273
- /* @__PURE__ */ jsx11(
966
+ /* @__PURE__ */ jsx9(
1274
967
  Button_default,
1275
968
  {
1276
969
  onClick: () => setState("isEmpty"),
1277
970
  className: "bg-transparent p-0 pl-2 w-auto h-auto text-zinc-600 cursor-pointer hover:text-zinc-900 hover:bg-transparent text-start",
1278
971
  id: "change_security_number",
1279
- children: /* @__PURE__ */ jsx11("span", { className: "underline", children: "Deseja editar o cpf digitado?" })
972
+ children: /* @__PURE__ */ jsx9("span", { className: "underline", children: "Deseja editar o cpf digitado?" })
1280
973
  }
1281
974
  )
1282
975
  ] })
@@ -1286,8 +979,29 @@ function BenefitsTable() {
1286
979
  }
1287
980
  var BenefitsTable_default = BenefitsTable;
1288
981
 
982
+ // src/components/UI/Text/index.tsx
983
+ import classNames6 from "classnames";
984
+ import { jsx as jsx10 } from "react/jsx-runtime";
985
+ function Text(props) {
986
+ return /* @__PURE__ */ jsx10(
987
+ "p",
988
+ {
989
+ className: classNames6(
990
+ "font-normal text-sm",
991
+ props.textAlign && `text-${props.textAlign}`,
992
+ props.className
993
+ ),
994
+ style: { color: props.textColor || "var(--pbm-text)", fontSize: props.textSize, textAlign: props.textAlign },
995
+ "data-testid": "test_id_text",
996
+ id: "text_pbm",
997
+ children: props.children
998
+ }
999
+ );
1000
+ }
1001
+ var Text_default = Text;
1002
+
1289
1003
  // src/components/SecurityNumberInvalid/index.tsx
1290
- import { jsx as jsx12, jsxs as jsxs8 } from "react/jsx-runtime";
1004
+ import { jsx as jsx11, jsxs as jsxs7 } from "react/jsx-runtime";
1291
1005
  function SecurityNumberInvalid({ textColor }) {
1292
1006
  const { urlAcceptTerms } = usePBMStore();
1293
1007
  const { setModal } = useModal();
@@ -1295,7 +1009,7 @@ function SecurityNumberInvalid({ textColor }) {
1295
1009
  if (!urlAcceptTerms) return;
1296
1010
  setModal({ open: true, id: "iframe_pbm", label: "Aceitar os termos", url: urlAcceptTerms });
1297
1011
  };
1298
- return /* @__PURE__ */ jsxs8(
1012
+ return /* @__PURE__ */ jsxs7(
1299
1013
  "section",
1300
1014
  {
1301
1015
  "data-testid": "test_id_invalid",
@@ -1303,13 +1017,13 @@ function SecurityNumberInvalid({ textColor }) {
1303
1017
  style: { borderColor: "color-mix(in srgb, var(--pbm-text), transparent 80%)" },
1304
1018
  id: "security_number_invalid_container_pbm",
1305
1019
  children: [
1306
- /* @__PURE__ */ jsx12(Title_default, { className: "w-full", textColor, children: "CPF n\xE3o cadastrado." }),
1307
- /* @__PURE__ */ jsxs8(Text_default, { className: "w-full", textColor, children: [
1020
+ /* @__PURE__ */ jsx11(Title_default, { className: "w-full", textColor, children: "CPF n\xE3o cadastrado." }),
1021
+ /* @__PURE__ */ jsxs7(Text_default, { className: "w-full", textColor, children: [
1308
1022
  "Conclua seu cadastro para habilitar o benef\xEDcio. ",
1309
- /* @__PURE__ */ jsx12("br", {}),
1023
+ /* @__PURE__ */ jsx11("br", {}),
1310
1024
  "Ao clicar em \u201CAceitar os termos\u201D, voc\xEA ir\xE1 para uma p\xE1gina externa. Aceite os termos e volte para continuar."
1311
1025
  ] }),
1312
- /* @__PURE__ */ jsx12(Button_default, { onClick: () => handleOpenModal(), style: { backgroundColor: "var(--pbm-primary)" }, children: "Aceitar os termos" })
1026
+ /* @__PURE__ */ jsx11(Button_default, { onClick: () => handleOpenModal(), style: { backgroundColor: "var(--pbm-primary)" }, children: "Aceitar os termos" })
1313
1027
  ]
1314
1028
  }
1315
1029
  );
@@ -1317,7 +1031,7 @@ function SecurityNumberInvalid({ textColor }) {
1317
1031
  var SecurityNumberInvalid_default = SecurityNumberInvalid;
1318
1032
 
1319
1033
  // src/components/SecurityNumberRegitered/index.tsx
1320
- import { jsx as jsx13, jsxs as jsxs9 } from "react/jsx-runtime";
1034
+ import { jsx as jsx12, jsxs as jsxs8 } from "react/jsx-runtime";
1321
1035
  function SecurityNumberRegitered({ textColor }) {
1322
1036
  const { urlRegisterIndustry } = usePBMStore();
1323
1037
  const { setModal } = useModal();
@@ -1325,7 +1039,7 @@ function SecurityNumberRegitered({ textColor }) {
1325
1039
  if (!urlRegisterIndustry) return;
1326
1040
  setModal({ open: true, id: "iframe_pbm", label: "Ativar CPF", url: urlRegisterIndustry });
1327
1041
  };
1328
- return /* @__PURE__ */ jsxs9(
1042
+ return /* @__PURE__ */ jsxs8(
1329
1043
  "section",
1330
1044
  {
1331
1045
  "data-testid": "test_id_registered",
@@ -1333,9 +1047,9 @@ function SecurityNumberRegitered({ textColor }) {
1333
1047
  style: { borderColor: "color-mix(in srgb, var(--pbm-text), transparent 80%)" },
1334
1048
  id: "security_number_registered_container_pbm",
1335
1049
  children: [
1336
- /* @__PURE__ */ jsx13(Title_default, { className: "w-full", textColor, children: "Ops, seu CPF ainda n\xE3o est\xE1 habilitado para este produto." }),
1337
- /* @__PURE__ */ jsx13(Text_default, { className: "w-full", textColor, children: "Para ativar o benef\xEDcio, clique em \u201CAtivar CPF\u201D e conclua a etapa na p\xE1gina externa. Depois, \xE9 s\xF3 voltar para continuar \u2014 vamos aguardar voc\xEA aqui." }),
1338
- /* @__PURE__ */ jsx13(Button_default, { onClick: () => handleOpenModal(), style: { backgroundColor: "var(--pbm-primary)" }, children: "Ativar CPF" })
1050
+ /* @__PURE__ */ jsx12(Title_default, { className: "w-full", textColor, children: "Ops, seu CPF ainda n\xE3o est\xE1 habilitado para este produto." }),
1051
+ /* @__PURE__ */ jsx12(Text_default, { className: "w-full", textColor, children: "Para ativar o benef\xEDcio, clique em \u201CAtivar CPF\u201D e conclua a etapa na p\xE1gina externa. Depois, \xE9 s\xF3 voltar para continuar \u2014 vamos aguardar voc\xEA aqui." }),
1052
+ /* @__PURE__ */ jsx12(Button_default, { onClick: () => handleOpenModal(), style: { backgroundColor: "var(--pbm-primary)" }, children: "Ativar CPF" })
1339
1053
  ]
1340
1054
  }
1341
1055
  );
@@ -1346,7 +1060,7 @@ var SecurityNumberRegitered_default = SecurityNumberRegitered;
1346
1060
  import { RefreshCw } from "lucide-react";
1347
1061
 
1348
1062
  // src/libs/zustand/useError.tsx
1349
- import { create as create3 } from "zustand";
1063
+ import { create as create2 } from "zustand";
1350
1064
  var initialErrorState = {
1351
1065
  ErrorMessage: "Erro ao aplicar o benef\xEDcio"
1352
1066
  };
@@ -1355,17 +1069,17 @@ var createErrorStore = (set) => ({
1355
1069
  setErrorMessage: (ErrorMessage) => set({ ErrorMessage }),
1356
1070
  resetErrorMessage: () => set({ ErrorMessage: initialErrorState.ErrorMessage })
1357
1071
  });
1358
- var useError = create3(createErrorStore);
1072
+ var useError = create2(createErrorStore);
1359
1073
 
1360
1074
  // src/components/Errors/ErrorToApplyBenefits.tsx
1361
- import { jsx as jsx14, jsxs as jsxs10 } from "react/jsx-runtime";
1075
+ import { jsx as jsx13, jsxs as jsxs9 } from "react/jsx-runtime";
1362
1076
  var ErrorToApplyBenefits = () => {
1363
1077
  const { ErrorMessage } = useError();
1364
1078
  const { setState } = usePBMStore();
1365
- return /* @__PURE__ */ jsxs10(Container_default, { variant: "main", children: [
1366
- /* @__PURE__ */ jsx14(Title_default, { children: "Erro ao Aplicar o Benef\xEDcio" }),
1367
- /* @__PURE__ */ jsx14(Text_default, { textAlign: "center", children: ErrorMessage }),
1368
- /* @__PURE__ */ jsxs10(
1079
+ return /* @__PURE__ */ jsxs9(Container_default, { variant: "main", children: [
1080
+ /* @__PURE__ */ jsx13(Title_default, { children: "Erro ao Aplicar o Benef\xEDcio" }),
1081
+ /* @__PURE__ */ jsx13(Text_default, { textAlign: "center", children: ErrorMessage }),
1082
+ /* @__PURE__ */ jsxs9(
1369
1083
  Button_default,
1370
1084
  {
1371
1085
  className: "bg-transparent p-0 pl-2 w-auto h-auto underline cursor-pointer hover:bg-transparent flex items-center justify-start gap-1",
@@ -1375,8 +1089,8 @@ var ErrorToApplyBenefits = () => {
1375
1089
  onClick: () => setState("isEmpty"),
1376
1090
  id: "check_benefits_button",
1377
1091
  children: [
1378
- /* @__PURE__ */ jsx14("span", { children: "Tentar novamente" }),
1379
- /* @__PURE__ */ jsx14(RefreshCw, { size: 16 })
1092
+ /* @__PURE__ */ jsx13("span", { children: "Tentar novamente" }),
1093
+ /* @__PURE__ */ jsx13(RefreshCw, { size: 16 })
1380
1094
  ]
1381
1095
  }
1382
1096
  )
@@ -1385,22 +1099,63 @@ var ErrorToApplyBenefits = () => {
1385
1099
  var ErrorToApplyBenefits_default = ErrorToApplyBenefits;
1386
1100
 
1387
1101
  // src/components/Modals/CustomerNotRegistered/index.tsx
1388
- import { useState as useState9 } from "react";
1389
- import classNames13 from "classnames";
1102
+ import { useState as useState8 } from "react";
1103
+
1104
+ // src/libs/zustand/usePBMForm.tsx
1105
+ import { create as create3 } from "zustand";
1106
+ var initialPBMFormState = {
1107
+ personalData: { name: "", phone: "", birthday: "", email: "" },
1108
+ address: {
1109
+ postalcode: "",
1110
+ number: "",
1111
+ complement: "",
1112
+ street: "",
1113
+ neighborhood: "",
1114
+ city: "",
1115
+ uf: "",
1116
+ stateAddress: ""
1117
+ },
1118
+ genderResponsibility: { gender: "", patient: null },
1119
+ doctor: { typeCredential: "CRM", register: "", state: "", doctorName: "" },
1120
+ acceptances: {
1121
+ acceptPhone: false,
1122
+ acceptsSms: false,
1123
+ acceptsEmail: false,
1124
+ acceptsMail: false,
1125
+ acceptsPrivacyTermsLGPD: false
1126
+ },
1127
+ step: 0
1128
+ };
1129
+ var usePBMFormStore = create3((set) => ({
1130
+ ...initialPBMFormState,
1131
+ setPersonalData: (data) => set((s) => ({ personalData: { ...s.personalData, ...data } })),
1132
+ setAddress: (data) => set((s) => ({ address: { ...s.address, ...data } })),
1133
+ setGenderResponsibility: (data) => set((s) => ({
1134
+ genderResponsibility: { ...s.genderResponsibility, ...data }
1135
+ })),
1136
+ setDoctor: (data) => set((s) => ({ doctor: { ...s.doctor, ...data } })),
1137
+ setAcceptances: (data) => set((s) => ({ acceptances: { ...s.acceptances, ...data } })),
1138
+ setStep: (step) => set({ step }),
1139
+ resetForm: () => set(initialPBMFormState)
1140
+ }));
1141
+ var usePBMForm = usePBMFormStore;
1142
+
1143
+ // src/components/Modals/CustomerNotRegistered/index.tsx
1144
+ import classNames12 from "classnames";
1390
1145
 
1391
1146
  // src/components/Modals/CustomerNotRegistered/StepPersonalDataForm.tsx
1392
- import { useState as useState4 } from "react";
1147
+ import { useState as useState3 } from "react";
1393
1148
 
1394
1149
  // src/components/Modals/CustomerNotRegistered/Shared/FieldWrapper.tsx
1395
- import { jsx as jsx15, jsxs as jsxs11 } from "react/jsx-runtime";
1150
+ import { jsx as jsx14, jsxs as jsxs10 } from "react/jsx-runtime";
1396
1151
  var FieldWrapper = ({
1397
1152
  label,
1398
1153
  error,
1399
1154
  children
1400
- }) => /* @__PURE__ */ jsxs11("div", { className: "flex flex-col gap-1", children: [
1401
- /* @__PURE__ */ jsx15("label", { className: "text-xs font-medium text-zinc-500 uppercase tracking-wide", children: label }),
1155
+ }) => /* @__PURE__ */ jsxs10("div", { className: "flex flex-col gap-1", children: [
1156
+ /* @__PURE__ */ jsx14("label", { className: "text-xs font-medium text-zinc-500 uppercase tracking-wide", children: label }),
1402
1157
  children,
1403
- error && /* @__PURE__ */ jsx15("span", { className: "text-xs text-red-500 mt-0.5", children: error })
1158
+ error && /* @__PURE__ */ jsx14("span", { className: "text-xs text-red-500 mt-0.5", children: error })
1404
1159
  ] });
1405
1160
  var FieldWrapper_default = FieldWrapper;
1406
1161
 
@@ -1409,8 +1164,8 @@ var disabledInputClass = "w-full rounded-lg border border-gray-200 bg-gray-100 p
1409
1164
  var DisabledInputClass_default = disabledInputClass;
1410
1165
 
1411
1166
  // src/components/Modals/CustomerNotRegistered/Shared/InputClass.ts
1412
- import classNames8 from "classnames";
1413
- var inputClass = (error) => classNames8(
1167
+ import classNames7 from "classnames";
1168
+ var inputClass = (error) => classNames7(
1414
1169
  "w-full rounded-lg border px-3 py-2.5 text-sm text-gray-800 outline-none transition-all",
1415
1170
  "focus:ring-2 focus:ring-blue-500/30 focus:border-blue-500",
1416
1171
  error ? "border-red-400 bg-red-50" : "border-gray-200 bg-gray-50 hover:border-gray-300"
@@ -1418,16 +1173,16 @@ var inputClass = (error) => classNames8(
1418
1173
  var InputClass_default = inputClass;
1419
1174
 
1420
1175
  // src/components/Modals/CustomerNotRegistered/Shared/StepActions.tsx
1421
- import classNames9 from "classnames";
1422
- import { jsx as jsx16, jsxs as jsxs12 } from "react/jsx-runtime";
1176
+ import classNames8 from "classnames";
1177
+ import { jsx as jsx15, jsxs as jsxs11 } from "react/jsx-runtime";
1423
1178
  var StepActions = ({
1424
1179
  onNext,
1425
1180
  onBack,
1426
1181
  loading,
1427
1182
  nextLabel = "Continuar",
1428
1183
  isLast = false
1429
- }) => /* @__PURE__ */ jsxs12("div", { className: "flex gap-2 mt-2 pt-4 border-t border-gray-100", children: [
1430
- onBack && /* @__PURE__ */ jsx16(
1184
+ }) => /* @__PURE__ */ jsxs11("div", { className: "flex gap-2 mt-2 pt-4 border-t border-gray-100", children: [
1185
+ onBack && /* @__PURE__ */ jsx15(
1431
1186
  "button",
1432
1187
  {
1433
1188
  type: "button",
@@ -1436,20 +1191,20 @@ var StepActions = ({
1436
1191
  children: "Voltar"
1437
1192
  }
1438
1193
  ),
1439
- /* @__PURE__ */ jsx16(
1194
+ /* @__PURE__ */ jsx15(
1440
1195
  "button",
1441
1196
  {
1442
1197
  type: "button",
1443
1198
  onClick: onNext,
1444
1199
  disabled: loading,
1445
- className: classNames9(
1200
+ className: classNames8(
1446
1201
  "flex-2 rounded-lg py-2.5 text-sm font-semibold text-white transition-all cursor-pointer",
1447
1202
  isLast ? "bg-emerald-600 hover:bg-emerald-500" : "bg-(--pbm-primary) hover:bg-(--pbm-primary)/60",
1448
1203
  loading && "opacity-60 cursor-not-allowed"
1449
1204
  ),
1450
- children: loading ? /* @__PURE__ */ jsxs12("span", { className: "flex items-center justify-center gap-2", children: [
1451
- /* @__PURE__ */ jsxs12("svg", { className: "h-4 w-4 animate-spin", viewBox: "0 0 24 24", fill: "none", children: [
1452
- /* @__PURE__ */ jsx16(
1205
+ children: loading ? /* @__PURE__ */ jsxs11("span", { className: "flex items-center justify-center gap-2", children: [
1206
+ /* @__PURE__ */ jsxs11("svg", { className: "h-4 w-4 animate-spin", viewBox: "0 0 24 24", fill: "none", children: [
1207
+ /* @__PURE__ */ jsx15(
1453
1208
  "circle",
1454
1209
  {
1455
1210
  className: "opacity-25",
@@ -1460,7 +1215,7 @@ var StepActions = ({
1460
1215
  strokeWidth: "4"
1461
1216
  }
1462
1217
  ),
1463
- /* @__PURE__ */ jsx16(
1218
+ /* @__PURE__ */ jsx15(
1464
1219
  "path",
1465
1220
  {
1466
1221
  className: "opacity-75",
@@ -1476,40 +1231,25 @@ var StepActions = ({
1476
1231
  ] });
1477
1232
  var StepActions_default = StepActions;
1478
1233
 
1479
- // src/services/set-personal-data-form.ts
1480
- import Cookies4 from "js-cookie";
1481
- var SetPersonalDataForm = async ({ document, requestId, personalData }) => {
1482
- const API_URL = getEnv("VITE_API_URL");
1483
- const AUTH_TOKEN = Cookies4.get("pbm-token");
1484
- if (!AUTH_TOKEN) {
1485
- throw new Error("Token is not defined in cookies or is expired");
1486
- }
1487
- const response = await fetch(`${API_URL}/programregistration/personalData`, {
1488
- method: "PUT",
1489
- headers: {
1490
- Authorization: `Bearer ${AUTH_TOKEN}`,
1491
- "Content-Type": "application/json"
1492
- },
1493
- body: JSON.stringify({ document, requestId, ...personalData })
1494
- });
1495
- const dataResponse = await response.json();
1496
- if (!dataResponse.success) {
1497
- throw new Error(dataResponse.message || "Failed to fetch authorization");
1498
- }
1499
- return dataResponse;
1234
+ // src/utils/mappingFormStep.ts
1235
+ var mappingFormStep = {
1236
+ "PersonalData": 0,
1237
+ "Address": 1,
1238
+ "GenderResponsibility": 2,
1239
+ "Doctor": 3,
1240
+ "Acceptances": 4
1500
1241
  };
1501
1242
 
1502
1243
  // src/components/Modals/CustomerNotRegistered/StepPersonalDataForm.tsx
1503
- import { jsx as jsx17, jsxs as jsxs13 } from "react/jsx-runtime";
1244
+ import { jsx as jsx16, jsxs as jsxs12 } from "react/jsx-runtime";
1504
1245
  var StepPersonalDataForm = ({
1505
1246
  securityNumber,
1506
1247
  onNext
1507
1248
  }) => {
1508
1249
  const { personalData, setPersonalData, setStep } = usePBMForm();
1509
1250
  const { setModal } = useModal();
1510
- const store = usePBMStore();
1511
- const [errors, setErrors] = useState4({});
1512
- const [loading, setLoading] = useState4(false);
1251
+ const [errors, setErrors] = useState3({});
1252
+ const [loading, setLoading] = useState3(false);
1513
1253
  const validate = () => {
1514
1254
  const e = {};
1515
1255
  if (!personalData.name.trim() || personalData.name.trim().split(" ").length < 2)
@@ -1526,15 +1266,6 @@ var StepPersonalDataForm = ({
1526
1266
  if (!validate()) return;
1527
1267
  setLoading(true);
1528
1268
  try {
1529
- const response = await SetPersonalDataForm({
1530
- document: securityNumber,
1531
- requestId: store.requestId,
1532
- personalData
1533
- });
1534
- if (!response.success) {
1535
- console.error("Failed to set personal data form:", response.message);
1536
- return;
1537
- }
1538
1269
  setStep(mappingFormStep["Address"]);
1539
1270
  onNext();
1540
1271
  } catch {
@@ -1543,9 +1274,9 @@ var StepPersonalDataForm = ({
1543
1274
  setLoading(false);
1544
1275
  }
1545
1276
  };
1546
- return /* @__PURE__ */ jsxs13("div", { className: "flex flex-col gap-4", children: [
1547
- /* @__PURE__ */ jsxs13(FieldWrapper_default, { label: "CPF", children: [
1548
- /* @__PURE__ */ jsx17(
1277
+ return /* @__PURE__ */ jsxs12("div", { className: "flex flex-col gap-4", children: [
1278
+ /* @__PURE__ */ jsxs12(FieldWrapper_default, { label: "CPF", children: [
1279
+ /* @__PURE__ */ jsx16(
1549
1280
  "input",
1550
1281
  {
1551
1282
  className: DisabledInputClass_default,
@@ -1554,7 +1285,7 @@ var StepPersonalDataForm = ({
1554
1285
  readOnly: true
1555
1286
  }
1556
1287
  ),
1557
- /* @__PURE__ */ jsx17("p", { className: "text-xs text-gray-400 mt-1", children: /* @__PURE__ */ jsx17(
1288
+ /* @__PURE__ */ jsx16("p", { className: "text-xs text-gray-400 mt-1", children: /* @__PURE__ */ jsx16(
1558
1289
  "button",
1559
1290
  {
1560
1291
  type: "button",
@@ -1564,7 +1295,7 @@ var StepPersonalDataForm = ({
1564
1295
  }
1565
1296
  ) })
1566
1297
  ] }),
1567
- /* @__PURE__ */ jsx17(FieldWrapper_default, { label: "Nome completo", error: errors.name, children: /* @__PURE__ */ jsx17(
1298
+ /* @__PURE__ */ jsx16(FieldWrapper_default, { label: "Nome completo", error: errors.name, children: /* @__PURE__ */ jsx16(
1568
1299
  "input",
1569
1300
  {
1570
1301
  className: InputClass_default(errors.name),
@@ -1576,8 +1307,8 @@ var StepPersonalDataForm = ({
1576
1307
  }
1577
1308
  }
1578
1309
  ) }),
1579
- /* @__PURE__ */ jsxs13("div", { className: "grid grid-cols-2 gap-3", children: [
1580
- /* @__PURE__ */ jsx17(FieldWrapper_default, { label: "Telefone", error: errors.phone, children: /* @__PURE__ */ jsx17(
1310
+ /* @__PURE__ */ jsxs12("div", { className: "grid grid-cols-2 gap-3", children: [
1311
+ /* @__PURE__ */ jsx16(FieldWrapper_default, { label: "Telefone", error: errors.phone, children: /* @__PURE__ */ jsx16(
1581
1312
  "input",
1582
1313
  {
1583
1314
  className: InputClass_default(errors.phone),
@@ -1589,7 +1320,7 @@ var StepPersonalDataForm = ({
1589
1320
  }
1590
1321
  }
1591
1322
  ) }),
1592
- /* @__PURE__ */ jsx17(FieldWrapper_default, { label: "Data de nascimento", error: errors.birthday, children: /* @__PURE__ */ jsx17(
1323
+ /* @__PURE__ */ jsx16(FieldWrapper_default, { label: "Data de nascimento", error: errors.birthday, children: /* @__PURE__ */ jsx16(
1593
1324
  "input",
1594
1325
  {
1595
1326
  type: "date",
@@ -1602,7 +1333,7 @@ var StepPersonalDataForm = ({
1602
1333
  }
1603
1334
  ) })
1604
1335
  ] }),
1605
- /* @__PURE__ */ jsx17(FieldWrapper_default, { label: "E-mail", error: errors.email, children: /* @__PURE__ */ jsx17(
1336
+ /* @__PURE__ */ jsx16(FieldWrapper_default, { label: "E-mail", error: errors.email, children: /* @__PURE__ */ jsx16(
1606
1337
  "input",
1607
1338
  {
1608
1339
  type: "email",
@@ -1615,89 +1346,53 @@ var StepPersonalDataForm = ({
1615
1346
  }
1616
1347
  }
1617
1348
  ) }),
1618
- /* @__PURE__ */ jsx17(StepActions_default, { onNext: handleSubmit, loading })
1349
+ /* @__PURE__ */ jsx16(StepActions_default, { onNext: handleSubmit, loading })
1619
1350
  ] });
1620
1351
  };
1621
1352
  var StepPersonalDataForm_default = StepPersonalDataForm;
1622
1353
 
1623
1354
  // src/components/Modals/CustomerNotRegistered/StepAddressForm.tsx
1624
- import { useCallback as useCallback2, useState as useState5 } from "react";
1355
+ import { useCallback as useCallback2, useState as useState4 } from "react";
1625
1356
 
1626
1357
  // src/services/lookup-postal-code.ts
1627
- import Cookies5 from "js-cookie";
1628
- var LookupPostalCode = async ({ POSTAL_CODE }) => {
1629
- const API_URL = getEnv("VITE_API_URL");
1630
- const AUTH_TOKEN = Cookies5.get("pbm-token");
1631
- if (!AUTH_TOKEN) {
1632
- throw new Error("Token is not defined in cookies or is expired");
1633
- }
1634
- const response = await fetch(`${API_URL}/programregistration/consulta-cep/${POSTAL_CODE}`, {
1635
- method: "GET",
1636
- headers: {
1637
- Authorization: `Bearer ${AUTH_TOKEN}`,
1638
- "Content-Type": "application/json"
1639
- }
1640
- });
1641
- const dataResponse = await response.json();
1642
- if (!dataResponse.success) {
1643
- throw new Error(dataResponse.message || "Failed to fetch authorization");
1644
- }
1645
- return dataResponse;
1646
- };
1647
-
1648
- // src/services/set-address-data-form.ts
1649
- import Cookies6 from "js-cookie";
1650
- var SetAddressDataForm = async ({ document, requestId, address }) => {
1651
- const API_URL = getEnv("VITE_API_URL");
1652
- const AUTH_TOKEN = Cookies6.get("pbm-token");
1653
- if (!AUTH_TOKEN) {
1654
- throw new Error("Token is not defined in cookies or is expired");
1655
- }
1656
- const response = await fetch(`${API_URL}/programregistration/address`, {
1657
- method: "PUT",
1658
- headers: {
1659
- Authorization: `Bearer ${AUTH_TOKEN}`,
1660
- "Content-Type": "application/json"
1661
- },
1662
- body: JSON.stringify({ document, requestId, ...address })
1663
- });
1664
- const dataResponse = await response.json();
1665
- if (!dataResponse.success) {
1666
- throw new Error(dataResponse.message || "Failed to fetch authorization");
1358
+ async function LookupPostalCode({ postal_code }) {
1359
+ const response = await fetch(`${getEnv("VITE_CORREIOS_API_URL")}/${postal_code}/json/`);
1360
+ if (!response.ok) {
1361
+ throw new Error("Erro ao consultar CEP");
1667
1362
  }
1668
- return dataResponse;
1669
- };
1363
+ const data = await response.json();
1364
+ return { ...data, success: true };
1365
+ }
1670
1366
 
1671
1367
  // src/components/Modals/CustomerNotRegistered/StepAddressForm.tsx
1672
- import { jsx as jsx18, jsxs as jsxs14 } from "react/jsx-runtime";
1368
+ import { jsx as jsx17, jsxs as jsxs13 } from "react/jsx-runtime";
1673
1369
  var StepAddressForm = ({
1674
- securityNumber,
1675
1370
  onNext,
1676
1371
  onBack
1677
1372
  }) => {
1678
1373
  const { address, setAddress, setStep } = usePBMForm();
1679
- const store = usePBMStore();
1680
- const [errors, setErrors] = useState5({});
1681
- const [loadingCep, setLoadingCep] = useState5(false);
1682
- const [loading, setLoading] = useState5(false);
1374
+ const [errors, setErrors] = useState4({});
1375
+ const [loadingCep, setLoadingCep] = useState4(false);
1376
+ const [loading, setLoading] = useState4(false);
1683
1377
  const fetchCEP = useCallback2(
1684
1378
  async (cep) => {
1685
1379
  const raw = cep.replace(/\D/g, "");
1686
1380
  if (raw.length !== 8) return;
1687
1381
  setLoadingCep(true);
1688
1382
  try {
1689
- const response = await LookupPostalCode({ POSTAL_CODE: raw });
1383
+ const response = await LookupPostalCode({ postal_code: raw });
1690
1384
  if (!response.success) {
1691
1385
  console.error("Failed to lookup postal code");
1692
1386
  return;
1693
1387
  }
1694
1388
  setAddress({
1695
- street: response.data.endereco,
1696
- neighborhood: response.data.bairro,
1697
- city: response.data.cidade,
1698
- stateAddress: response.data.estado,
1699
- postalcode: cep,
1700
- complement: response.data.complementoSugeridoViaCep || ""
1389
+ street: response.logradouro,
1390
+ neighborhood: response.bairro,
1391
+ uf: response.uf,
1392
+ city: response.localidade,
1393
+ stateAddress: response.estado,
1394
+ postalcode: response.cep,
1395
+ complement: response.complemento || ""
1701
1396
  });
1702
1397
  } catch {
1703
1398
  console.error("Failed to fetch address for CEP:", cep);
@@ -1719,19 +1414,6 @@ var StepAddressForm = ({
1719
1414
  if (!validate()) return;
1720
1415
  setLoading(true);
1721
1416
  try {
1722
- const response = await SetAddressDataForm({
1723
- document: securityNumber,
1724
- requestId: store.requestId,
1725
- address: {
1726
- postalcode: address.postalcode.replace(/\D/g, ""),
1727
- number: address.number,
1728
- complement: address.complement
1729
- }
1730
- });
1731
- if (!response.success) {
1732
- console.log("Failed to set address data form:", response.message);
1733
- return;
1734
- }
1735
1417
  setStep(mappingFormStep["GenderResponsibility"]);
1736
1418
  onNext();
1737
1419
  } catch {
@@ -1740,9 +1422,9 @@ var StepAddressForm = ({
1740
1422
  setLoading(false);
1741
1423
  }
1742
1424
  };
1743
- return /* @__PURE__ */ jsxs14("div", { className: "flex flex-col gap-4", children: [
1744
- /* @__PURE__ */ jsx18(FieldWrapper_default, { label: "CEP", error: errors.postalcode, children: /* @__PURE__ */ jsxs14("div", { className: "relative", children: [
1745
- /* @__PURE__ */ jsx18(
1425
+ return /* @__PURE__ */ jsxs13("div", { className: "flex flex-col gap-4", children: [
1426
+ /* @__PURE__ */ jsx17(FieldWrapper_default, { label: "CEP", error: errors.postalcode, children: /* @__PURE__ */ jsxs13("div", { className: "relative", children: [
1427
+ /* @__PURE__ */ jsx17(
1746
1428
  "input",
1747
1429
  {
1748
1430
  className: InputClass_default(errors.postalcode),
@@ -1760,14 +1442,14 @@ var StepAddressForm = ({
1760
1442
  }
1761
1443
  }
1762
1444
  ),
1763
- loadingCep && /* @__PURE__ */ jsx18("div", { className: "absolute right-3 top-1/2 -translate-y-1/2", children: /* @__PURE__ */ jsxs14(
1445
+ loadingCep && /* @__PURE__ */ jsx17("div", { className: "absolute right-3 top-1/2 -translate-y-1/2", children: /* @__PURE__ */ jsxs13(
1764
1446
  "svg",
1765
1447
  {
1766
1448
  className: "h-4 w-4 animate-spin text-blue-500",
1767
1449
  viewBox: "0 0 24 24",
1768
1450
  fill: "none",
1769
1451
  children: [
1770
- /* @__PURE__ */ jsx18(
1452
+ /* @__PURE__ */ jsx17(
1771
1453
  "circle",
1772
1454
  {
1773
1455
  className: "opacity-25",
@@ -1778,7 +1460,7 @@ var StepAddressForm = ({
1778
1460
  strokeWidth: "4"
1779
1461
  }
1780
1462
  ),
1781
- /* @__PURE__ */ jsx18(
1463
+ /* @__PURE__ */ jsx17(
1782
1464
  "path",
1783
1465
  {
1784
1466
  className: "opacity-75",
@@ -1790,8 +1472,8 @@ var StepAddressForm = ({
1790
1472
  }
1791
1473
  ) })
1792
1474
  ] }) }),
1793
- /* @__PURE__ */ jsxs14("div", { className: "grid grid-cols-2 gap-3", children: [
1794
- /* @__PURE__ */ jsx18(FieldWrapper_default, { label: "Rua", children: /* @__PURE__ */ jsx18(
1475
+ /* @__PURE__ */ jsxs13("div", { className: "grid grid-cols-2 gap-3", children: [
1476
+ /* @__PURE__ */ jsx17(FieldWrapper_default, { label: "Rua", children: /* @__PURE__ */ jsx17(
1795
1477
  "input",
1796
1478
  {
1797
1479
  className: DisabledInputClass_default,
@@ -1801,7 +1483,7 @@ var StepAddressForm = ({
1801
1483
  placeholder: "Preenchido pelo CEP"
1802
1484
  }
1803
1485
  ) }),
1804
- /* @__PURE__ */ jsx18(FieldWrapper_default, { label: "Bairro", children: /* @__PURE__ */ jsx18(
1486
+ /* @__PURE__ */ jsx17(FieldWrapper_default, { label: "Bairro", children: /* @__PURE__ */ jsx17(
1805
1487
  "input",
1806
1488
  {
1807
1489
  className: DisabledInputClass_default,
@@ -1812,8 +1494,8 @@ var StepAddressForm = ({
1812
1494
  }
1813
1495
  ) })
1814
1496
  ] }),
1815
- /* @__PURE__ */ jsxs14("div", { className: "grid grid-cols-2 gap-3", children: [
1816
- /* @__PURE__ */ jsx18(FieldWrapper_default, { label: "Cidade", children: /* @__PURE__ */ jsx18(
1497
+ /* @__PURE__ */ jsxs13("div", { className: "grid grid-cols-2 gap-3", children: [
1498
+ /* @__PURE__ */ jsx17(FieldWrapper_default, { label: "Cidade", children: /* @__PURE__ */ jsx17(
1817
1499
  "input",
1818
1500
  {
1819
1501
  className: DisabledInputClass_default,
@@ -1823,7 +1505,7 @@ var StepAddressForm = ({
1823
1505
  placeholder: "Preenchido pelo CEP"
1824
1506
  }
1825
1507
  ) }),
1826
- /* @__PURE__ */ jsx18(FieldWrapper_default, { label: "Estado", children: /* @__PURE__ */ jsx18(
1508
+ /* @__PURE__ */ jsx17(FieldWrapper_default, { label: "Estado", children: /* @__PURE__ */ jsx17(
1827
1509
  "input",
1828
1510
  {
1829
1511
  className: DisabledInputClass_default,
@@ -1834,8 +1516,8 @@ var StepAddressForm = ({
1834
1516
  }
1835
1517
  ) })
1836
1518
  ] }),
1837
- /* @__PURE__ */ jsxs14("div", { className: "grid grid-cols-2 gap-3", children: [
1838
- /* @__PURE__ */ jsx18(FieldWrapper_default, { label: "N\xFAmero", error: errors.number, children: /* @__PURE__ */ jsx18(
1519
+ /* @__PURE__ */ jsxs13("div", { className: "grid grid-cols-2 gap-3", children: [
1520
+ /* @__PURE__ */ jsx17(FieldWrapper_default, { label: "N\xFAmero", error: errors.number, children: /* @__PURE__ */ jsx17(
1839
1521
  "input",
1840
1522
  {
1841
1523
  className: InputClass_default(errors.number),
@@ -1847,7 +1529,7 @@ var StepAddressForm = ({
1847
1529
  }
1848
1530
  }
1849
1531
  ) }),
1850
- /* @__PURE__ */ jsx18(FieldWrapper_default, { label: "Complemento", children: /* @__PURE__ */ jsx18(
1532
+ /* @__PURE__ */ jsx17(FieldWrapper_default, { label: "Complemento", children: /* @__PURE__ */ jsx17(
1851
1533
  "input",
1852
1534
  {
1853
1535
  className: InputClass_default(),
@@ -1857,51 +1539,24 @@ var StepAddressForm = ({
1857
1539
  }
1858
1540
  ) })
1859
1541
  ] }),
1860
- /* @__PURE__ */ jsx18(StepActions_default, { onNext: handleSubmit, onBack, loading })
1542
+ /* @__PURE__ */ jsx17(StepActions_default, { onNext: handleSubmit, onBack, loading })
1861
1543
  ] });
1862
1544
  };
1863
1545
  var StepAddressForm_default = StepAddressForm;
1864
1546
 
1865
1547
  // src/components/Modals/CustomerNotRegistered/StepGenderForm.tsx
1866
- import classNames10 from "classnames";
1867
- import { useState as useState6 } from "react";
1868
-
1869
- // src/services/set-gender-responsability-data-form.ts
1870
- import Cookies7 from "js-cookie";
1871
- var SetGenderResponsabilityDataForm = async ({ document, requestId, identity_responsibility }) => {
1872
- const API_URL = getEnv("VITE_API_URL");
1873
- const AUTH_TOKEN = Cookies7.get("pbm-token");
1874
- if (!AUTH_TOKEN) {
1875
- throw new Error("Token is not defined in cookies or is expired");
1876
- }
1877
- const response = await fetch(`${API_URL}/programregistration/genderResponsibility`, {
1878
- method: "PUT",
1879
- headers: {
1880
- Authorization: `Bearer ${AUTH_TOKEN}`,
1881
- "Content-Type": "application/json"
1882
- },
1883
- body: JSON.stringify({ document, requestId, ...identity_responsibility })
1884
- });
1885
- const dataResponse = await response.json();
1886
- if (!dataResponse.success) {
1887
- throw new Error(dataResponse.message || "Failed to fetch authorization");
1888
- }
1889
- return dataResponse;
1890
- };
1891
-
1892
- // src/components/Modals/CustomerNotRegistered/StepGenderForm.tsx
1893
- import { jsx as jsx19, jsxs as jsxs15 } from "react/jsx-runtime";
1548
+ import classNames9 from "classnames";
1549
+ import { useState as useState5 } from "react";
1550
+ import { jsx as jsx18, jsxs as jsxs14 } from "react/jsx-runtime";
1894
1551
  var StepGenderForm = ({
1895
- securityNumber,
1896
1552
  onNext,
1897
1553
  onBack
1898
1554
  }) => {
1899
1555
  const { genderResponsibility, setGenderResponsibility, setStep } = usePBMForm();
1900
- const store = usePBMStore();
1901
- const [errors, setErrors] = useState6(
1556
+ const [errors, setErrors] = useState5(
1902
1557
  {}
1903
1558
  );
1904
- const [loading, setLoading] = useState6(false);
1559
+ const [loading, setLoading] = useState5(false);
1905
1560
  const validate = () => {
1906
1561
  const e = {};
1907
1562
  if (!genderResponsibility.gender) e.gender = "Selecione o g\xEAnero.";
@@ -1914,21 +1569,6 @@ var StepGenderForm = ({
1914
1569
  if (!validate()) return;
1915
1570
  setLoading(true);
1916
1571
  try {
1917
- const response = await SetGenderResponsabilityDataForm({
1918
- document: securityNumber,
1919
- requestId: store.requestId,
1920
- identity_responsibility: {
1921
- gender: genderResponsibility.gender,
1922
- patient: genderResponsibility.patient
1923
- }
1924
- });
1925
- if (!response.success) {
1926
- console.error(
1927
- "Failed to submit gender responsibility data:",
1928
- response.message
1929
- );
1930
- return;
1931
- }
1932
1572
  setStep(mappingFormStep["Doctor"]);
1933
1573
  onNext();
1934
1574
  } catch {
@@ -1944,10 +1584,10 @@ var StepGenderForm = ({
1944
1584
  { value: "F", label: "Feminino" },
1945
1585
  { value: "O", label: "Outro" }
1946
1586
  ];
1947
- return /* @__PURE__ */ jsxs15("div", { className: "flex flex-col gap-5", children: [
1948
- /* @__PURE__ */ jsxs15("div", { children: [
1949
- /* @__PURE__ */ jsx19("label", { className: "text-xs font-medium text-gray-500 uppercase tracking-wide block mb-2", children: "G\xEAnero" }),
1950
- /* @__PURE__ */ jsx19("div", { className: "flex gap-2", children: genderOptions.map((opt) => /* @__PURE__ */ jsx19(
1587
+ return /* @__PURE__ */ jsxs14("div", { className: "flex flex-col gap-5", children: [
1588
+ /* @__PURE__ */ jsxs14("div", { children: [
1589
+ /* @__PURE__ */ jsx18("label", { className: "text-xs font-medium text-gray-500 uppercase tracking-wide block mb-2", children: "G\xEAnero" }),
1590
+ /* @__PURE__ */ jsx18("div", { className: "flex gap-2", children: genderOptions.map((opt) => /* @__PURE__ */ jsx18(
1951
1591
  "button",
1952
1592
  {
1953
1593
  type: "button",
@@ -1955,22 +1595,22 @@ var StepGenderForm = ({
1955
1595
  setGenderResponsibility({ gender: opt.value });
1956
1596
  setErrors((p) => ({ ...p, gender: void 0 }));
1957
1597
  },
1958
- className: classNames10(
1959
- "flex-1 py-2.5 rounded-lg border text-sm font-medium transition-all",
1960
- genderResponsibility.gender === opt.value ? "border-blue-500 bg-blue-500 text-white" : "border-gray-200 bg-gray-50 text-gray-600 hover:border-blue-300"
1598
+ className: classNames9(
1599
+ "flex-1 py-2.5 cursor-pointer px-2.5 rounded-lg border text-sm font-medium transition-all",
1600
+ genderResponsibility.gender === opt.value ? "border-(--pbm-primary) bg-(--pbm-primary) text-white" : "border-gray-200 bg-gray-50 text-gray-600 hover:border-(--pbm-primary)"
1961
1601
  ),
1962
1602
  children: opt.label
1963
1603
  },
1964
1604
  opt.value
1965
1605
  )) }),
1966
- errors.gender && /* @__PURE__ */ jsx19("span", { className: "text-xs text-red-500 mt-1 block", children: errors.gender })
1606
+ errors.gender && /* @__PURE__ */ jsx18("span", { className: "text-xs text-red-500 mt-1 block", children: errors.gender })
1967
1607
  ] }),
1968
- /* @__PURE__ */ jsxs15("div", { children: [
1969
- /* @__PURE__ */ jsx19("label", { className: "text-xs font-medium text-gray-500 uppercase tracking-wide block mb-2", children: "Voc\xEA \xE9 o paciente?" }),
1970
- /* @__PURE__ */ jsx19("div", { className: "flex gap-2", children: [
1608
+ /* @__PURE__ */ jsxs14("div", { children: [
1609
+ /* @__PURE__ */ jsx18("label", { className: "text-xs font-medium text-gray-500 uppercase tracking-wide block mb-2", children: "Voc\xEA \xE9 o paciente?" }),
1610
+ /* @__PURE__ */ jsx18("div", { className: "flex gap-2", children: [
1971
1611
  { label: "Sim, sou o paciente", value: true },
1972
1612
  { label: "N\xE3o, sou respons\xE1vel", value: false }
1973
- ].map((opt) => /* @__PURE__ */ jsx19(
1613
+ ].map((opt) => /* @__PURE__ */ jsx18(
1974
1614
  "button",
1975
1615
  {
1976
1616
  type: "button",
@@ -1978,23 +1618,23 @@ var StepGenderForm = ({
1978
1618
  setGenderResponsibility({ patient: opt.value });
1979
1619
  setErrors((p) => ({ ...p, patient: void 0 }));
1980
1620
  },
1981
- className: classNames10(
1982
- "flex-1 py-2.5 rounded-lg border text-sm font-medium transition-all",
1983
- genderResponsibility.patient === opt.value ? "border-blue-500 bg-blue-500 text-white" : "border-gray-200 bg-gray-50 text-gray-600 hover:border-blue-300"
1621
+ className: classNames9(
1622
+ "flex-1 py-2.5 px-2.5 text-nowrap cursor-pointer rounded-lg border text-sm font-medium transition-all",
1623
+ genderResponsibility.patient === opt.value ? "border-(--pbm-primary) bg-(--pbm-primary) text-white" : "border-gray-200 bg-gray-50 text-gray-600 hover:border-(--pbm-primary)"
1984
1624
  ),
1985
1625
  children: opt.label
1986
1626
  },
1987
1627
  String(opt.value)
1988
1628
  )) }),
1989
- errors.patient && /* @__PURE__ */ jsx19("span", { className: "text-xs text-red-500 mt-1 block", children: errors.patient })
1629
+ errors.patient && /* @__PURE__ */ jsx18("span", { className: "text-xs text-red-500 mt-1 block", children: errors.patient })
1990
1630
  ] }),
1991
- /* @__PURE__ */ jsx19(StepActions_default, { onNext: handleSubmit, onBack, loading })
1631
+ /* @__PURE__ */ jsx18(StepActions_default, { onNext: handleSubmit, onBack, loading })
1992
1632
  ] });
1993
1633
  };
1994
1634
  var StepGenderForm_default = StepGenderForm;
1995
1635
 
1996
1636
  // src/components/Modals/CustomerNotRegistered/StepDoctorForm.tsx
1997
- import { useCallback as useCallback3, useState as useState7 } from "react";
1637
+ import { useState as useState6 } from "react";
1998
1638
 
1999
1639
  // src/utils/ufMapping.ts
2000
1640
  var BRAZILIAN_STATES = [
@@ -2027,91 +1667,15 @@ var BRAZILIAN_STATES = [
2027
1667
  "TO"
2028
1668
  ];
2029
1669
 
2030
- // src/services/set-doctor-data-form.ts
2031
- import Cookies8 from "js-cookie";
2032
- var SetDoctorDataForm = async ({ document, requestId, doctor }) => {
2033
- const API_URL = getEnv("VITE_API_URL");
2034
- const AUTH_TOKEN = Cookies8.get("pbm-token");
2035
- if (!AUTH_TOKEN) {
2036
- throw new Error("Token is not defined in cookies or is expired");
2037
- }
2038
- const response = await fetch(`${API_URL}/programregistration/doctorName`, {
2039
- method: "PUT",
2040
- headers: {
2041
- Authorization: `Bearer ${AUTH_TOKEN}`,
2042
- "Content-Type": "application/json"
2043
- },
2044
- body: JSON.stringify({ document, requestId, ...doctor })
2045
- });
2046
- const dataResponse = await response.json();
2047
- if (!dataResponse.success) {
2048
- throw new Error(dataResponse.message || "Failed to fetch authorization");
2049
- }
2050
- return dataResponse;
2051
- };
2052
-
2053
- // src/services/lookup-doctor.ts
2054
- import Cookies9 from "js-cookie";
2055
- var LookupDoctor = async ({ typeCredential, register, uf }) => {
2056
- const API_URL = getEnv("VITE_API_URL");
2057
- const AUTH_TOKEN = Cookies9.get("pbm-token");
2058
- if (!AUTH_TOKEN) {
2059
- throw new Error("Token is not defined in cookies or is expired");
2060
- }
2061
- const queryParams = new URLSearchParams({
2062
- tipoCredencial: typeCredential,
2063
- registro: register,
2064
- uf
2065
- });
2066
- const response = await fetch(`${API_URL}/doctors/consulta-profissional?${queryParams.toString()}`, {
2067
- method: "GET",
2068
- headers: {
2069
- Authorization: `Bearer ${AUTH_TOKEN}`,
2070
- "Content-Type": "application/json"
2071
- }
2072
- });
2073
- const dataResponse = await response.json();
2074
- if (!dataResponse.success) {
2075
- throw new Error(dataResponse.message || "Failed to fetch authorization");
2076
- }
2077
- return dataResponse;
2078
- };
2079
-
2080
1670
  // src/components/Modals/CustomerNotRegistered/StepDoctorForm.tsx
2081
- import { jsx as jsx20, jsxs as jsxs16 } from "react/jsx-runtime";
1671
+ import { jsx as jsx19, jsxs as jsxs15 } from "react/jsx-runtime";
2082
1672
  var StepDoctorForm = ({
2083
- securityNumber,
2084
1673
  onNext,
2085
1674
  onBack
2086
1675
  }) => {
2087
1676
  const { doctor, setDoctor, setStep } = usePBMForm();
2088
- const store = usePBMStore();
2089
- const [errors, setErrors] = useState7({});
2090
- const [loadingDoctor, setLoadingDoctor] = useState7(false);
2091
- const [loading, setLoading] = useState7(false);
2092
- const fetchDoctor = useCallback3(async () => {
2093
- if (!doctor.register || !doctor.state || !doctor.typeCredential) return;
2094
- setLoadingDoctor(true);
2095
- try {
2096
- const response = await LookupDoctor({
2097
- typeCredential: doctor.typeCredential,
2098
- register: doctor.register,
2099
- uf: doctor.state
2100
- });
2101
- if (!response.success) {
2102
- console.error("Failed to fetch doctor data:", response.message);
2103
- return;
2104
- }
2105
- const data = response.data;
2106
- if (data?.nomeProfissional) {
2107
- setDoctor({ doctorName: data.nomeProfissional });
2108
- }
2109
- } catch {
2110
- console.error("An error occurred while fetching doctor data.");
2111
- } finally {
2112
- setLoadingDoctor(false);
2113
- }
2114
- }, [doctor.register, doctor.state, doctor.typeCredential, setDoctor]);
1677
+ const [errors, setErrors] = useState6({});
1678
+ const [loading, setLoading] = useState6(false);
2115
1679
  const validate = () => {
2116
1680
  const e = {};
2117
1681
  if (!doctor.typeCredential)
@@ -2126,20 +1690,6 @@ var StepDoctorForm = ({
2126
1690
  if (!validate()) return;
2127
1691
  setLoading(true);
2128
1692
  try {
2129
- const response = await SetDoctorDataForm({
2130
- document: securityNumber,
2131
- requestId: store.requestId,
2132
- doctor: {
2133
- typeCredential: doctor.typeCredential,
2134
- register: doctor.register,
2135
- state: doctor.state,
2136
- doctorName: doctor.doctorName
2137
- }
2138
- });
2139
- if (!response.success) {
2140
- console.error("Failed to submit doctor data:", response.message);
2141
- return;
2142
- }
2143
1693
  setStep(mappingFormStep["Acceptances"]);
2144
1694
  onNext();
2145
1695
  } catch {
@@ -2148,9 +1698,9 @@ var StepDoctorForm = ({
2148
1698
  setLoading(false);
2149
1699
  }
2150
1700
  };
2151
- return /* @__PURE__ */ jsxs16("div", { className: "flex flex-col gap-4", children: [
2152
- /* @__PURE__ */ jsxs16("div", { className: "grid grid-cols-3 gap-3", children: [
2153
- /* @__PURE__ */ jsx20(FieldWrapper_default, { label: "Tipo credencial", error: errors.typeCredential, children: /* @__PURE__ */ jsxs16(
1701
+ return /* @__PURE__ */ jsxs15("div", { className: "flex flex-col gap-4", children: [
1702
+ /* @__PURE__ */ jsxs15("div", { className: "grid grid-cols-3 gap-3", children: [
1703
+ /* @__PURE__ */ jsx19(FieldWrapper_default, { label: "Tipo credencial", error: errors.typeCredential, children: /* @__PURE__ */ jsxs15(
2154
1704
  "select",
2155
1705
  {
2156
1706
  className: InputClass_default(errors.typeCredential),
@@ -2163,13 +1713,13 @@ var StepDoctorForm = ({
2163
1713
  }));
2164
1714
  },
2165
1715
  children: [
2166
- /* @__PURE__ */ jsx20("option", { value: "CRM", children: "CRM" }),
2167
- /* @__PURE__ */ jsx20("option", { value: "CRO", children: "CRO" }),
2168
- /* @__PURE__ */ jsx20("option", { value: "CRF", children: "CRF" })
1716
+ /* @__PURE__ */ jsx19("option", { value: "CRM", children: "CRM" }),
1717
+ /* @__PURE__ */ jsx19("option", { value: "CRO", children: "CRO" }),
1718
+ /* @__PURE__ */ jsx19("option", { value: "CRF", children: "CRF" })
2169
1719
  ]
2170
1720
  }
2171
1721
  ) }),
2172
- /* @__PURE__ */ jsx20(FieldWrapper_default, { label: "Estado (UF)", error: errors.state, children: /* @__PURE__ */ jsxs16(
1722
+ /* @__PURE__ */ jsx19(FieldWrapper_default, { label: "Estado (UF)", error: errors.state, children: /* @__PURE__ */ jsxs15(
2173
1723
  "select",
2174
1724
  {
2175
1725
  className: InputClass_default(errors.state),
@@ -2179,12 +1729,12 @@ var StepDoctorForm = ({
2179
1729
  setErrors((p) => ({ ...p, state: void 0 }));
2180
1730
  },
2181
1731
  children: [
2182
- /* @__PURE__ */ jsx20("option", { value: "", children: "UF" }),
2183
- BRAZILIAN_STATES.map((state) => /* @__PURE__ */ jsx20("option", { value: state, children: state }, state))
1732
+ /* @__PURE__ */ jsx19("option", { value: "", children: "UF" }),
1733
+ BRAZILIAN_STATES.map((state) => /* @__PURE__ */ jsx19("option", { value: state, children: state }, state))
2184
1734
  ]
2185
1735
  }
2186
1736
  ) }),
2187
- /* @__PURE__ */ jsx20(FieldWrapper_default, { label: "N\xBA registro", error: errors.register, children: /* @__PURE__ */ jsx20("div", { className: "relative", children: /* @__PURE__ */ jsx20(
1737
+ /* @__PURE__ */ jsx19(FieldWrapper_default, { label: "N\xBA registro", error: errors.register, children: /* @__PURE__ */ jsx19("div", { className: "relative", children: /* @__PURE__ */ jsx19(
2188
1738
  "input",
2189
1739
  {
2190
1740
  className: InputClass_default(errors.register),
@@ -2196,94 +1746,62 @@ var StepDoctorForm = ({
2196
1746
  ...p,
2197
1747
  register: void 0
2198
1748
  }));
2199
- },
2200
- onBlur: fetchDoctor
1749
+ }
2201
1750
  }
2202
1751
  ) }) })
2203
1752
  ] }),
2204
- /* @__PURE__ */ jsxs16(FieldWrapper_default, { label: "Nome do m\xE9dico", error: errors.doctorName, children: [
2205
- /* @__PURE__ */ jsxs16("div", { className: "relative", children: [
2206
- /* @__PURE__ */ jsx20(
2207
- "input",
2208
- {
2209
- className: InputClass_default(errors.doctorName),
2210
- placeholder: loadingDoctor ? "Buscando m\xE9dico..." : "Dr. Nome Completo",
2211
- value: doctor.doctorName,
2212
- onChange: (e) => {
2213
- setDoctor({ doctorName: e.target.value });
2214
- setErrors((p) => ({
2215
- ...p,
2216
- doctorName: void 0
2217
- }));
2218
- }
2219
- }
2220
- ),
2221
- loadingDoctor && /* @__PURE__ */ jsx20("div", { className: "absolute right-3 top-1/2 -translate-y-1/2", children: /* @__PURE__ */ jsxs16(
2222
- "svg",
2223
- {
2224
- className: "h-4 w-4 animate-spin text-blue-500",
2225
- viewBox: "0 0 24 24",
2226
- fill: "none",
2227
- children: [
2228
- /* @__PURE__ */ jsx20(
2229
- "circle",
2230
- {
2231
- className: "opacity-25",
2232
- cx: "12",
2233
- cy: "12",
2234
- r: "10",
2235
- stroke: "currentColor",
2236
- strokeWidth: "4"
2237
- }
2238
- ),
2239
- /* @__PURE__ */ jsx20(
2240
- "path",
2241
- {
2242
- className: "opacity-75",
2243
- fill: "currentColor",
2244
- d: "M4 12a8 8 0 018-8v8z"
2245
- }
2246
- )
2247
- ]
1753
+ /* @__PURE__ */ jsxs15(FieldWrapper_default, { label: "Nome do m\xE9dico", error: errors.doctorName, children: [
1754
+ /* @__PURE__ */ jsx19("div", { className: "relative", children: /* @__PURE__ */ jsx19(
1755
+ "input",
1756
+ {
1757
+ className: InputClass_default(errors.doctorName),
1758
+ placeholder: "Nome Completo do Profissional",
1759
+ value: doctor.doctorName,
1760
+ onChange: (e) => {
1761
+ setDoctor({ doctorName: e.target.value });
1762
+ setErrors((p) => ({
1763
+ ...p,
1764
+ doctorName: void 0
1765
+ }));
2248
1766
  }
2249
- ) })
2250
- ] }),
2251
- /* @__PURE__ */ jsx20("p", { className: "text-xs text-gray-400 mt-0.5", children: "Preenchido automaticamente ao informar registro + UF." })
1767
+ }
1768
+ ) }),
1769
+ /* @__PURE__ */ jsx19("p", { className: "text-xs text-gray-400 mt-0.5", children: "Preenchido automaticamente ao informar registro + UF." })
2252
1770
  ] }),
2253
- /* @__PURE__ */ jsx20(StepActions_default, { onNext: handleSubmit, onBack, loading })
1771
+ /* @__PURE__ */ jsx19(StepActions_default, { onNext: handleSubmit, onBack, loading })
2254
1772
  ] });
2255
1773
  };
2256
1774
  var StepDoctorForm_default = StepDoctorForm;
2257
1775
 
2258
1776
  // src/components/Modals/CustomerNotRegistered/StepAcceptancesForm.tsx
2259
- import { useState as useState8 } from "react";
1777
+ import { useState as useState7 } from "react";
2260
1778
 
2261
1779
  // src/components/Modals/CustomerNotRegistered/Shared/CheckRow.tsx
2262
- import classNames11 from "classnames";
2263
- import { jsx as jsx21, jsxs as jsxs17 } from "react/jsx-runtime";
1780
+ import classNames10 from "classnames";
1781
+ import { jsx as jsx20, jsxs as jsxs16 } from "react/jsx-runtime";
2264
1782
  var CheckRow = ({
2265
1783
  label,
2266
1784
  checked,
2267
1785
  onChange,
2268
1786
  required,
2269
1787
  error
2270
- }) => /* @__PURE__ */ jsxs17(
1788
+ }) => /* @__PURE__ */ jsxs16(
2271
1789
  "label",
2272
1790
  {
2273
- className: classNames11(
1791
+ className: classNames10(
2274
1792
  "flex items-start gap-3 cursor-pointer group p-3 rounded-lg border transition-all",
2275
1793
  checked ? "border-emerald-200 bg-emerald-50/60" : "border-zinc-100 hover:border-zinc-200 bg-zinc-50/40",
2276
1794
  error ? "border-red-300 bg-red-50/40" : ""
2277
1795
  ),
2278
1796
  children: [
2279
- /* @__PURE__ */ jsx21(
1797
+ /* @__PURE__ */ jsx20(
2280
1798
  "div",
2281
1799
  {
2282
- className: classNames11(
1800
+ className: classNames10(
2283
1801
  "mt-0.5 flex h-4 w-4 shrink-0 items-center justify-center rounded border transition-all",
2284
1802
  checked ? "border-(--pbm-primary) bg-(--pbm-primary)" : "border-zinc-300 bg-white"
2285
1803
  ),
2286
- children: checked && /* @__PURE__ */ jsx21("svg", { className: "h-2.5 w-2.5 text-white", viewBox: "0 0 10 8", fill: "none", children: /* @__PURE__ */ jsx21(
1804
+ children: checked && /* @__PURE__ */ jsx20("svg", { className: "h-2.5 w-2.5 text-white", viewBox: "0 0 10 8", fill: "none", children: /* @__PURE__ */ jsx20(
2287
1805
  "path",
2288
1806
  {
2289
1807
  d: "M1 4l3 3 5-6",
@@ -2295,11 +1813,11 @@ var CheckRow = ({
2295
1813
  ) })
2296
1814
  }
2297
1815
  ),
2298
- /* @__PURE__ */ jsxs17("span", { className: "text-sm text-zinc-700 leading-snug", children: [
1816
+ /* @__PURE__ */ jsxs16("span", { className: "text-sm text-zinc-700 leading-snug", children: [
2299
1817
  label,
2300
- required && /* @__PURE__ */ jsx21("span", { className: "text-red-400 ml-1", children: "*" })
1818
+ required && /* @__PURE__ */ jsx20("span", { className: "text-red-400 ml-1", children: "*" })
2301
1819
  ] }),
2302
- /* @__PURE__ */ jsx21(
1820
+ /* @__PURE__ */ jsx20(
2303
1821
  "input",
2304
1822
  {
2305
1823
  type: "checkbox",
@@ -2313,40 +1831,128 @@ var CheckRow = ({
2313
1831
  );
2314
1832
  var CheckRow_default = CheckRow;
2315
1833
 
2316
- // src/services/set-acceptances-data-form.ts
2317
- import Cookies10 from "js-cookie";
2318
- var SetAcceptancesDataForm = async ({ document, requestId, lgpd }) => {
2319
- const API_URL = getEnv("VITE_API_URL");
2320
- const AUTH_TOKEN = Cookies10.get("pbm-token");
2321
- if (!AUTH_TOKEN) {
2322
- throw new Error("Token is not defined in cookies or is expired");
1834
+ // src/services/enable-discount.ts
1835
+ import Cookies2 from "js-cookie";
1836
+ var EnableDiscount = async ({ product, consumer, healthProfessional }) => {
1837
+ const tenant_id = Cookies2.get("tenant_id");
1838
+ if (!tenant_id) {
1839
+ throw new Error(`No configuration found for tenant: ${tenant_id}`);
2323
1840
  }
2324
- const response = await fetch(`${API_URL}/programregistration/acceptances`, {
2325
- method: "PUT",
2326
- headers: {
2327
- Authorization: `Bearer ${AUTH_TOKEN}`,
2328
- "Content-Type": "application/json"
2329
- },
2330
- body: JSON.stringify({ document, requestId, ...lgpd })
2331
- });
2332
- const dataResponse = await response.json();
2333
- if (!dataResponse.success) {
2334
- throw new Error(dataResponse.message || "Failed to fetch authorization");
1841
+ if (!consumer) {
1842
+ throw new Error(`Consumer information is required`);
1843
+ }
1844
+ if (!healthProfessional) {
1845
+ throw new Error(`Health professional information is required`);
1846
+ }
1847
+ if (!product) {
1848
+ throw new Error(`Product information is required`);
1849
+ }
1850
+ try {
1851
+ const response = await fetch(
1852
+ `${getEnv("VITE_API_URL")}/api/discount.ts`,
1853
+ {
1854
+ method: "POST",
1855
+ headers: {
1856
+ "Content-Type": "application/json",
1857
+ "Accept": "application/json",
1858
+ "Authorization": `Bearer ${Cookies2.get("pbm-token")}`
1859
+ },
1860
+ body: JSON.stringify({
1861
+ tenant_id,
1862
+ product,
1863
+ table_id: Cookies2.get("current-table-id"),
1864
+ local_hour: Cookies2.get("current-local-hour"),
1865
+ consumer,
1866
+ healthProfessional
1867
+ })
1868
+ }
1869
+ );
1870
+ const data = await response.json();
1871
+ if (!data.success) {
1872
+ throw new Error("PBMLOG: Enable Discount Failed!");
1873
+ }
1874
+ Cookies2.set("current-central-number", data.product[0].centralNumber.toString(), {
1875
+ secure: true,
1876
+ sameSite: "Strict",
1877
+ expires: 1
1878
+ });
1879
+ Cookies2.set("current-term-code", data.product[0].activationFields.acceptLgpd.termCode.value.toString(), {
1880
+ secure: true,
1881
+ sameSite: "Strict",
1882
+ expires: 1
1883
+ });
1884
+ return data;
1885
+ } catch (error) {
1886
+ console.error("Error during enable discount:", error);
1887
+ return { success: false, error: "Authorization failed" };
1888
+ }
1889
+ };
1890
+
1891
+ // src/services/activate.ts
1892
+ import Cookies3 from "js-cookie";
1893
+ var Activate = async ({ product, consumer, healthProfessional }) => {
1894
+ const tenant_id = Cookies3.get("tenant_id");
1895
+ if (!tenant_id) {
1896
+ throw new Error(`No configuration found for tenant: ${tenant_id}`);
1897
+ }
1898
+ if (!consumer) {
1899
+ throw new Error(`Consumer information is required`);
1900
+ }
1901
+ if (!healthProfessional) {
1902
+ throw new Error(`Health professional information is required`);
1903
+ }
1904
+ if (!product) {
1905
+ throw new Error(`Product information is required`);
1906
+ }
1907
+ try {
1908
+ const response = await fetch(
1909
+ `${getEnv("VITE_API_URL")}/api/activate.ts`,
1910
+ {
1911
+ method: "POST",
1912
+ headers: {
1913
+ "Content-Type": "application/json",
1914
+ "Accept": "application/json",
1915
+ "Authorization": `Bearer ${Cookies3.get("pbm-token")}`
1916
+ },
1917
+ body: JSON.stringify({
1918
+ tenant_id,
1919
+ product,
1920
+ table_id: Cookies3.get("current-table-id"),
1921
+ local_hour: Cookies3.get("current-local-hour"),
1922
+ central_number: Cookies3.get("current-central-number"),
1923
+ consumer,
1924
+ healthProfessional,
1925
+ acceptLgpd: {
1926
+ evidenceType: "SITE",
1927
+ evidence: "VSTOSITE",
1928
+ termCode: Cookies3.get("current-term-code")
1929
+ }
1930
+ })
1931
+ }
1932
+ );
1933
+ const data = await response.json();
1934
+ if (!data.success) {
1935
+ throw new Error("PBMLOG: Activate Failed!");
1936
+ }
1937
+ return data;
1938
+ } catch (error) {
1939
+ console.error("Error during activate:", error);
1940
+ return { success: false, error: "Authorization failed" };
2335
1941
  }
2336
- return dataResponse;
2337
1942
  };
2338
1943
 
2339
1944
  // src/components/Modals/CustomerNotRegistered/StepAcceptancesForm.tsx
2340
- import { jsx as jsx22, jsxs as jsxs18 } from "react/jsx-runtime";
1945
+ import { jsx as jsx21, jsxs as jsxs17 } from "react/jsx-runtime";
2341
1946
  var StepAcceptancesForm = ({
2342
- securityNumber,
2343
1947
  onBack,
2344
- onDone
1948
+ onDone,
1949
+ securityNumber
2345
1950
  }) => {
2346
1951
  const { acceptances, setAcceptances } = usePBMForm();
2347
- const store = usePBMStore();
2348
- const [errors, setErrors] = useState8({});
2349
- const [loading, setLoading] = useState8(false);
1952
+ const { targetProduct, cardID } = usePBMStore();
1953
+ const [errors, setErrors] = useState7({});
1954
+ const [loading, setLoading] = useState7(false);
1955
+ const data = usePBMForm.getState();
2350
1956
  const validate = () => {
2351
1957
  const e = {};
2352
1958
  if (!acceptances.acceptsPrivacyTermsLGPD)
@@ -2354,24 +1960,65 @@ var StepAcceptancesForm = ({
2354
1960
  setErrors(e);
2355
1961
  return Object.keys(e).length === 0;
2356
1962
  };
1963
+ const activateConsumer = async (PAYLOAD) => {
1964
+ try {
1965
+ const response = await Activate(PAYLOAD);
1966
+ console.log("Activate response:", response);
1967
+ } catch (error) {
1968
+ console.error("Error during consumer activation:", error);
1969
+ }
1970
+ };
2357
1971
  const handleSubmit = async () => {
2358
1972
  if (!validate()) return;
2359
1973
  setLoading(true);
1974
+ if (!targetProduct) {
1975
+ console.error("No target product found in PBM store.");
1976
+ setLoading(false);
1977
+ return;
1978
+ }
1979
+ const phone = data.personalData.phone.replace(/\D/g, "");
1980
+ const ddd = phone.slice(0, 2);
1981
+ const cellphone = phone.slice(2);
1982
+ const PAYLOAD = {
1983
+ consumer: {
1984
+ holderId: securityNumber,
1985
+ cardId: cardID || "",
1986
+ name: data.personalData.name,
1987
+ email: data.personalData.email,
1988
+ birthdate: data.personalData.birthday,
1989
+ genre: data.genderResponsibility.gender,
1990
+ postalCode: data.address.postalcode.replace(/\D/g, ""),
1991
+ stateCode: data.address.uf || "",
1992
+ cityName: data.address.city || "",
1993
+ cityRegion: data.address.neighborhood || "",
1994
+ addressType: "casa",
1995
+ streetAddress: data.address.street || "",
1996
+ addressNumber: data.address.number || "",
1997
+ addressAdditionalInformation: data.address.complement || "",
1998
+ DDDcellPhone: ddd,
1999
+ cellphone,
2000
+ acceptInformativeMaterial: acceptances.acceptsMail ? "S" : "N",
2001
+ acceptMail: acceptances.acceptsMail ? "S" : "N",
2002
+ acceptEmail: acceptances.acceptsEmail ? "S" : "N",
2003
+ acceptCalls: acceptances.acceptPhone ? "S" : "N",
2004
+ acceptSMS: acceptances.acceptsSms ? "S" : "N",
2005
+ acceptTerm: acceptances.acceptsPrivacyTermsLGPD ? "S" : "N",
2006
+ acceptWhatsApp: "N"
2007
+ },
2008
+ healthProfessional: {
2009
+ id: data.doctor.register,
2010
+ stateCode: data.doctor.state,
2011
+ type: data.doctor.typeCredential,
2012
+ name: data.doctor.doctorName
2013
+ },
2014
+ product: targetProduct
2015
+ };
2360
2016
  try {
2361
- const response = await SetAcceptancesDataForm({
2362
- document: securityNumber,
2363
- requestId: store.requestId,
2364
- lgpd: {
2365
- acceptPhone: acceptances.acceptPhone,
2366
- acceptsSms: acceptances.acceptsSms,
2367
- acceptsEmail: acceptances.acceptsEmail,
2368
- acceptsMail: acceptances.acceptsMail,
2369
- acceptsPrivacyTermsLGPD: acceptances.acceptsPrivacyTermsLGPD
2370
- }
2371
- });
2372
- if (!response.success) {
2373
- console.error("Failed to submit acceptances data:", response.message);
2374
- return;
2017
+ const response = await EnableDiscount(PAYLOAD);
2018
+ if (response.success) {
2019
+ await activateConsumer(PAYLOAD);
2020
+ } else {
2021
+ console.error("Failed to enable discount:", response);
2375
2022
  }
2376
2023
  onDone();
2377
2024
  } catch {
@@ -2380,9 +2027,9 @@ var StepAcceptancesForm = ({
2380
2027
  setLoading(false);
2381
2028
  }
2382
2029
  };
2383
- return /* @__PURE__ */ jsxs18("div", { className: "flex flex-col gap-3", children: [
2384
- /* @__PURE__ */ jsx22("p", { className: "text-xs text-gray-500 mb-1", children: "Selecione como deseja receber comunica\xE7\xF5es:" }),
2385
- /* @__PURE__ */ jsx22(
2030
+ return /* @__PURE__ */ jsxs17("div", { className: "flex flex-col gap-3", children: [
2031
+ /* @__PURE__ */ jsx21("p", { className: "text-xs text-gray-500 mb-1", children: "Selecione como deseja receber comunica\xE7\xF5es:" }),
2032
+ /* @__PURE__ */ jsx21(
2386
2033
  CheckRow_default,
2387
2034
  {
2388
2035
  label: "Aceito receber contato por telefone",
@@ -2390,7 +2037,7 @@ var StepAcceptancesForm = ({
2390
2037
  onChange: (v) => setAcceptances({ acceptPhone: v })
2391
2038
  }
2392
2039
  ),
2393
- /* @__PURE__ */ jsx22(
2040
+ /* @__PURE__ */ jsx21(
2394
2041
  CheckRow_default,
2395
2042
  {
2396
2043
  label: "Aceito receber SMS",
@@ -2398,7 +2045,7 @@ var StepAcceptancesForm = ({
2398
2045
  onChange: (v) => setAcceptances({ acceptsSms: v })
2399
2046
  }
2400
2047
  ),
2401
- /* @__PURE__ */ jsx22(
2048
+ /* @__PURE__ */ jsx21(
2402
2049
  CheckRow_default,
2403
2050
  {
2404
2051
  label: "Aceito receber e-mails",
@@ -2406,7 +2053,7 @@ var StepAcceptancesForm = ({
2406
2053
  onChange: (v) => setAcceptances({ acceptsEmail: v })
2407
2054
  }
2408
2055
  ),
2409
- /* @__PURE__ */ jsx22(
2056
+ /* @__PURE__ */ jsx21(
2410
2057
  CheckRow_default,
2411
2058
  {
2412
2059
  label: "Aceito receber correspond\xEAncias por correio",
@@ -2414,8 +2061,8 @@ var StepAcceptancesForm = ({
2414
2061
  onChange: (v) => setAcceptances({ acceptsMail: v })
2415
2062
  }
2416
2063
  ),
2417
- /* @__PURE__ */ jsxs18("div", { className: "mt-1", children: [
2418
- /* @__PURE__ */ jsx22(
2064
+ /* @__PURE__ */ jsxs17("div", { className: "mt-1", children: [
2065
+ /* @__PURE__ */ jsx21(
2419
2066
  CheckRow_default,
2420
2067
  {
2421
2068
  label: "Li e aceito os Termos de Privacidade (LGPD)",
@@ -2428,9 +2075,9 @@ var StepAcceptancesForm = ({
2428
2075
  error: errors.lgpd
2429
2076
  }
2430
2077
  ),
2431
- errors.lgpd && /* @__PURE__ */ jsx22("span", { className: "text-xs text-red-500 mt-1 block pl-1", children: errors.lgpd })
2078
+ errors.lgpd && /* @__PURE__ */ jsx21("span", { className: "text-xs text-red-500 mt-1 block pl-1", children: errors.lgpd })
2432
2079
  ] }),
2433
- /* @__PURE__ */ jsx22(
2080
+ /* @__PURE__ */ jsx21(
2434
2081
  StepActions_default,
2435
2082
  {
2436
2083
  onNext: handleSubmit,
@@ -2445,8 +2092,8 @@ var StepAcceptancesForm = ({
2445
2092
  var StepAcceptancesForm_default = StepAcceptancesForm;
2446
2093
 
2447
2094
  // src/components/Modals/CustomerNotRegistered/Shared/StepProgress.tsx
2448
- import classNames12 from "classnames";
2449
- import { jsx as jsx23, jsxs as jsxs19 } from "react/jsx-runtime";
2095
+ import classNames11 from "classnames";
2096
+ import { jsx as jsx22, jsxs as jsxs18 } from "react/jsx-runtime";
2450
2097
  var STEP_LABELS = [
2451
2098
  "Dados Pessoais",
2452
2099
  "Endere\xE7o",
@@ -2454,23 +2101,23 @@ var STEP_LABELS = [
2454
2101
  "M\xE9dico",
2455
2102
  "Aceites"
2456
2103
  ];
2457
- var StepProgress = ({ current }) => /* @__PURE__ */ jsx23("div", { className: "flex items-center w-full justify-center mb-6", children: STEP_LABELS.map((label, i) => {
2104
+ var StepProgress = ({ current }) => /* @__PURE__ */ jsx22("div", { className: "flex items-center w-full justify-center mb-6", children: STEP_LABELS.map((label, i) => {
2458
2105
  const done = i < current;
2459
2106
  const active = i === current;
2460
- return /* @__PURE__ */ jsxs19(
2107
+ return /* @__PURE__ */ jsxs18(
2461
2108
  "div",
2462
2109
  {
2463
2110
  className: "flex items-center w-full min-w-0 justify-center relative",
2464
2111
  children: [
2465
- /* @__PURE__ */ jsxs19("div", { className: "flex flex-col items-center justify-center gap-1 shrink-0", children: [
2466
- /* @__PURE__ */ jsx23(
2112
+ /* @__PURE__ */ jsxs18("div", { className: "flex flex-col items-center justify-center gap-1 shrink-0 z-10", children: [
2113
+ /* @__PURE__ */ jsx22(
2467
2114
  "div",
2468
2115
  {
2469
- className: classNames12(
2116
+ className: classNames11(
2470
2117
  "flex h-7 w-7 items-center justify-center rounded-full text-xs font-semibold transition-all",
2471
2118
  done ? "bg-emerald-600 text-white" : active ? "bg-(--pbm-primary) text-white ring-4 ring-(--pbm-primary)/15" : "bg-zinc-100 text-zinc-400"
2472
2119
  ),
2473
- children: done ? /* @__PURE__ */ jsx23("svg", { className: "h-3.5 w-3.5", viewBox: "0 0 12 10", fill: "none", children: /* @__PURE__ */ jsx23(
2120
+ children: done ? /* @__PURE__ */ jsx22("svg", { className: "h-3.5 w-3.5", viewBox: "0 0 12 10", fill: "none", children: /* @__PURE__ */ jsx22(
2474
2121
  "path",
2475
2122
  {
2476
2123
  d: "M1 5l4 4 6-8",
@@ -2482,10 +2129,10 @@ var StepProgress = ({ current }) => /* @__PURE__ */ jsx23("div", { className: "f
2482
2129
  ) }) : i + 1
2483
2130
  }
2484
2131
  ),
2485
- /* @__PURE__ */ jsx23(
2132
+ /* @__PURE__ */ jsx22(
2486
2133
  "span",
2487
2134
  {
2488
- className: classNames12(
2135
+ className: classNames11(
2489
2136
  "text-[10px] font-medium whitespace-nowrap hidden sm:block",
2490
2137
  active ? "text-(--pbm-primary)" : done ? "text-emerald-600" : "text-zinc-400"
2491
2138
  ),
@@ -2493,11 +2140,11 @@ var StepProgress = ({ current }) => /* @__PURE__ */ jsx23("div", { className: "f
2493
2140
  }
2494
2141
  )
2495
2142
  ] }),
2496
- i < STEP_LABELS.length - 1 && /* @__PURE__ */ jsx23(
2143
+ i < STEP_LABELS.length - 1 && /* @__PURE__ */ jsx22(
2497
2144
  "div",
2498
2145
  {
2499
- className: classNames12(
2500
- "h-0.5 w-10 rounded transition-all absolute top-3.5 left-17",
2146
+ className: classNames11(
2147
+ "h-0.5 w-full rounded transition-all absolute top-3.5 left-10",
2501
2148
  "bg-zinc-200"
2502
2149
  )
2503
2150
  }
@@ -2510,9 +2157,9 @@ var StepProgress = ({ current }) => /* @__PURE__ */ jsx23("div", { className: "f
2510
2157
  var StepProgress_default = StepProgress;
2511
2158
 
2512
2159
  // src/components/Modals/CustomerNotRegistered/Shared/SuccessScreen.tsx
2513
- import { jsx as jsx24, jsxs as jsxs20 } from "react/jsx-runtime";
2514
- var SuccessScreen = ({ onClose }) => /* @__PURE__ */ jsxs20("div", { className: "flex flex-col items-center gap-4 py-4 text-center", children: [
2515
- /* @__PURE__ */ jsx24("div", { className: "flex h-16 w-16 items-center justify-center rounded-full bg-green-100", children: /* @__PURE__ */ jsx24("svg", { className: "h-8 w-8 text-green-500", viewBox: "0 0 24 24", fill: "none", children: /* @__PURE__ */ jsx24(
2160
+ import { jsx as jsx23, jsxs as jsxs19 } from "react/jsx-runtime";
2161
+ var SuccessScreen = ({ onClose }) => /* @__PURE__ */ jsxs19("div", { className: "flex flex-col items-center gap-4 py-4 text-center", children: [
2162
+ /* @__PURE__ */ jsx23("div", { className: "flex h-16 w-16 items-center justify-center rounded-full bg-green-100", children: /* @__PURE__ */ jsx23("svg", { className: "h-8 w-8 text-green-500", viewBox: "0 0 24 24", fill: "none", children: /* @__PURE__ */ jsx23(
2516
2163
  "path",
2517
2164
  {
2518
2165
  d: "M5 13l4 4L19 7",
@@ -2522,11 +2169,11 @@ var SuccessScreen = ({ onClose }) => /* @__PURE__ */ jsxs20("div", { className:
2522
2169
  strokeLinejoin: "round"
2523
2170
  }
2524
2171
  ) }) }),
2525
- /* @__PURE__ */ jsxs20("div", { children: [
2526
- /* @__PURE__ */ jsx24("h3", { className: "text-base font-semibold text-gray-800", children: "Cadastro conclu\xEDdo!" }),
2527
- /* @__PURE__ */ jsx24("p", { className: "text-sm text-zinc-500 mt-1", children: "Voc\xEA j\xE1 pode aproveitar os benef\xEDcios de farm\xE1cia." })
2172
+ /* @__PURE__ */ jsxs19("div", { children: [
2173
+ /* @__PURE__ */ jsx23("h3", { className: "text-base font-semibold text-gray-800", children: "Cadastro conclu\xEDdo!" }),
2174
+ /* @__PURE__ */ jsx23("p", { className: "text-sm text-zinc-500 mt-1", children: "Voc\xEA j\xE1 pode aproveitar os benef\xEDcios de farm\xE1cia." })
2528
2175
  ] }),
2529
- /* @__PURE__ */ jsx24(
2176
+ /* @__PURE__ */ jsx23(
2530
2177
  "button",
2531
2178
  {
2532
2179
  onClick: onClose,
@@ -2538,12 +2185,12 @@ var SuccessScreen = ({ onClose }) => /* @__PURE__ */ jsxs20("div", { className:
2538
2185
  var SuccessScreen_default = SuccessScreen;
2539
2186
 
2540
2187
  // src/components/Modals/CustomerNotRegistered/index.tsx
2541
- import { jsx as jsx25, jsxs as jsxs21 } from "react/jsx-runtime";
2188
+ import { jsx as jsx24, jsxs as jsxs20 } from "react/jsx-runtime";
2542
2189
  var CustomerNotRegistered = ({ ID }) => {
2543
2190
  const { modal, setModal } = useModal();
2544
2191
  const { securityNumber } = usePBMStore();
2545
2192
  const { resetForm, step, setStep } = usePBMForm();
2546
- const [done, setDone] = useState9(false);
2193
+ const [done, setDone] = useState8(false);
2547
2194
  const closeModal = () => {
2548
2195
  setModal({ id: "", open: false });
2549
2196
  setTimeout(() => {
@@ -2556,8 +2203,8 @@ var CustomerNotRegistered = ({ ID }) => {
2556
2203
  const back = () => setStep(step - 1);
2557
2204
  const rawSecurityNumber = securityNumber.replace(/\D/g, "");
2558
2205
  const stepComponents = [
2559
- /* @__PURE__ */ jsx25(StepPersonalDataForm_default, { securityNumber: rawSecurityNumber, onNext: next }),
2560
- /* @__PURE__ */ jsx25(
2206
+ /* @__PURE__ */ jsx24(StepPersonalDataForm_default, { securityNumber: rawSecurityNumber, onNext: next }),
2207
+ /* @__PURE__ */ jsx24(
2561
2208
  StepAddressForm_default,
2562
2209
  {
2563
2210
  securityNumber: rawSecurityNumber,
@@ -2565,7 +2212,7 @@ var CustomerNotRegistered = ({ ID }) => {
2565
2212
  onBack: back
2566
2213
  }
2567
2214
  ),
2568
- /* @__PURE__ */ jsx25(
2215
+ /* @__PURE__ */ jsx24(
2569
2216
  StepGenderForm_default,
2570
2217
  {
2571
2218
  securityNumber: rawSecurityNumber,
@@ -2573,7 +2220,7 @@ var CustomerNotRegistered = ({ ID }) => {
2573
2220
  onBack: back
2574
2221
  }
2575
2222
  ),
2576
- /* @__PURE__ */ jsx25(
2223
+ /* @__PURE__ */ jsx24(
2577
2224
  StepDoctorForm_default,
2578
2225
  {
2579
2226
  securityNumber: rawSecurityNumber,
@@ -2581,7 +2228,7 @@ var CustomerNotRegistered = ({ ID }) => {
2581
2228
  onBack: back
2582
2229
  }
2583
2230
  ),
2584
- /* @__PURE__ */ jsx25(
2231
+ /* @__PURE__ */ jsx24(
2585
2232
  StepAcceptancesForm_default,
2586
2233
  {
2587
2234
  securityNumber: rawSecurityNumber,
@@ -2590,10 +2237,10 @@ var CustomerNotRegistered = ({ ID }) => {
2590
2237
  }
2591
2238
  )
2592
2239
  ];
2593
- return /* @__PURE__ */ jsxs21(
2240
+ return /* @__PURE__ */ jsxs20(
2594
2241
  "main",
2595
2242
  {
2596
- className: classNames13(
2243
+ className: classNames12(
2597
2244
  "fixed inset-0 flex items-center justify-end z-50 flex-col transition-all shadow bg-black/40",
2598
2245
  {
2599
2246
  "opacity-100 pointer-events-auto": modal.id === ID && modal.open,
@@ -2601,16 +2248,16 @@ var CustomerNotRegistered = ({ ID }) => {
2601
2248
  }
2602
2249
  ),
2603
2250
  children: [
2604
- /* @__PURE__ */ jsx25("div", { className: "absolute inset-0", onClick: closeModal }),
2605
- /* @__PURE__ */ jsxs21("section", { className: "z-10 bg-white flex flex-col p-6 rounded-2xl w-full max-w-max mx-4 shadow-xl max-h-[90vh] overflow-y-auto", children: [
2606
- /* @__PURE__ */ jsxs21("div", { className: "flex items-center justify-between mb-4", children: [
2607
- /* @__PURE__ */ jsx25(Title_default, { textSize: "18px", textAlign: "start", children: done ? "Tudo pronto!" : "Benef\xEDcio de Farm\xE1cia" }),
2608
- /* @__PURE__ */ jsx25(
2251
+ /* @__PURE__ */ jsx24("div", { className: "absolute inset-0", onClick: closeModal }),
2252
+ /* @__PURE__ */ jsxs20("section", { className: "z-10 bg-white flex flex-col p-6 rounded-2xl w-full max-w-125 min-w-125 mx-4 shadow-xl max-h-[90vh] overflow-y-auto", children: [
2253
+ /* @__PURE__ */ jsxs20("div", { className: "flex items-center justify-between mb-4", children: [
2254
+ /* @__PURE__ */ jsx24(Title_default, { textSize: "18px", textAlign: "start", children: done ? "Tudo pronto!" : "Benef\xEDcio de Farm\xE1cia" }),
2255
+ /* @__PURE__ */ jsx24(
2609
2256
  "button",
2610
2257
  {
2611
2258
  onClick: closeModal,
2612
2259
  className: "flex h-7 w-7 cursor-pointer items-center justify-center rounded-full text-gray-400 hover:bg-gray-100 hover:text-gray-600 transition-all",
2613
- children: /* @__PURE__ */ jsx25("svg", { className: "h-4 w-4", viewBox: "0 0 14 14", fill: "none", children: /* @__PURE__ */ jsx25(
2260
+ children: /* @__PURE__ */ jsx24("svg", { className: "h-4 w-4", viewBox: "0 0 14 14", fill: "none", children: /* @__PURE__ */ jsx24(
2614
2261
  "path",
2615
2262
  {
2616
2263
  d: "M1 1l12 12M13 1L1 13",
@@ -2622,8 +2269,8 @@ var CustomerNotRegistered = ({ ID }) => {
2622
2269
  }
2623
2270
  )
2624
2271
  ] }),
2625
- !done && /* @__PURE__ */ jsx25(StepProgress_default, { current: step }),
2626
- done ? /* @__PURE__ */ jsx25(SuccessScreen_default, { onClose: closeModal }) : stepComponents[step]
2272
+ !done && /* @__PURE__ */ jsx24(StepProgress_default, { current: step }),
2273
+ done ? /* @__PURE__ */ jsx24(SuccessScreen_default, { onClose: closeModal }) : stepComponents[step]
2627
2274
  ] })
2628
2275
  ]
2629
2276
  }
@@ -2632,7 +2279,7 @@ var CustomerNotRegistered = ({ ID }) => {
2632
2279
  var CustomerNotRegistered_default = CustomerNotRegistered;
2633
2280
 
2634
2281
  // src/components/UI/Link/index.tsx
2635
- import classNames14 from "classnames";
2282
+ import classNames13 from "classnames";
2636
2283
 
2637
2284
  // src/utils/getParams.ts
2638
2285
  var getParams = (params) => {
@@ -2641,16 +2288,16 @@ var getParams = (params) => {
2641
2288
  };
2642
2289
 
2643
2290
  // src/components/UI/Link/index.tsx
2644
- import { jsx as jsx26 } from "react/jsx-runtime";
2291
+ import { jsx as jsx25 } from "react/jsx-runtime";
2645
2292
  function Link(props) {
2646
2293
  const { setState } = usePBMStore();
2647
- return /* @__PURE__ */ jsx26(
2294
+ return /* @__PURE__ */ jsx25(
2648
2295
  "a",
2649
2296
  {
2650
2297
  ...props,
2651
2298
  target: props.target || "_self",
2652
2299
  href: typeof props.href === "string" ? props.href : props.href.pathname + getParams(props.href.param),
2653
- className: classNames14(
2300
+ className: classNames13(
2654
2301
  "w-3xs cursor-pointer h-10 rounded-lg text-white text-sm font-semibold transition-colors flex items-center justify-center",
2655
2302
  props.className
2656
2303
  ),
@@ -2667,15 +2314,15 @@ function Link(props) {
2667
2314
  var Link_default = Link;
2668
2315
 
2669
2316
  // src/components/Modals/ShopperIsNotAuthenticated.tsx
2670
- import classNames15 from "classnames";
2671
- import { jsx as jsx27, jsxs as jsxs22 } from "react/jsx-runtime";
2317
+ import classNames14 from "classnames";
2318
+ import { jsx as jsx26, jsxs as jsxs21 } from "react/jsx-runtime";
2672
2319
  var ShopperIsNotAuthenticated = ({ ID }) => {
2673
2320
  const { customLoginUrl } = usePBMStore();
2674
2321
  const { modal, setModal } = useModal();
2675
- return /* @__PURE__ */ jsxs22(
2322
+ return /* @__PURE__ */ jsxs21(
2676
2323
  "main",
2677
2324
  {
2678
- className: classNames15(
2325
+ className: classNames14(
2679
2326
  "fixed inset-0 flex items-center justify-center z-50 flex-col transition-all shadow bg-black/40",
2680
2327
  {
2681
2328
  "opacity-100 pointer-events-auto": modal.id === ID && modal.open,
@@ -2683,15 +2330,15 @@ var ShopperIsNotAuthenticated = ({ ID }) => {
2683
2330
  }
2684
2331
  ),
2685
2332
  children: [
2686
- /* @__PURE__ */ jsx27(
2333
+ /* @__PURE__ */ jsx26(
2687
2334
  "div",
2688
2335
  {
2689
2336
  className: "absolute inset-0",
2690
2337
  onClick: () => setModal({ id: "", open: false })
2691
2338
  }
2692
2339
  ),
2693
- /* @__PURE__ */ jsxs22("section", { className: "z-10 bg-white gap-2 flex-col items-center-safe justify-center-safe p-8 rounded-xl", children: [
2694
- /* @__PURE__ */ jsx27(
2340
+ /* @__PURE__ */ jsxs21("section", { className: "z-10 bg-white gap-2 flex-col items-center-safe justify-center-safe p-8 rounded-xl", children: [
2341
+ /* @__PURE__ */ jsx26(
2695
2342
  Title_default,
2696
2343
  {
2697
2344
  textColor: "tomato",
@@ -2701,16 +2348,16 @@ var ShopperIsNotAuthenticated = ({ ID }) => {
2701
2348
  children: "Opa! Parece que voc\xEA n\xE3o est\xE1 Logado"
2702
2349
  }
2703
2350
  ),
2704
- /* @__PURE__ */ jsxs22(Text_default, { className: "mb-2", textAlign: "center", children: [
2351
+ /* @__PURE__ */ jsxs21(Text_default, { className: "mb-2", textAlign: "center", children: [
2705
2352
  "Para aproveitar os benef\xEDcios \xE9 necess\xE1rio realizar o",
2706
2353
  " ",
2707
- /* @__PURE__ */ jsx27("strong", { children: "Login" }),
2354
+ /* @__PURE__ */ jsx26("strong", { children: "Login" }),
2708
2355
  " ou ",
2709
- /* @__PURE__ */ jsx27("strong", { children: "Cadastro" }),
2356
+ /* @__PURE__ */ jsx26("strong", { children: "Cadastro" }),
2710
2357
  " no site!"
2711
2358
  ] }),
2712
- /* @__PURE__ */ jsxs22("section", { className: "flex items-center-safe justify-center-safe gap-4", children: [
2713
- /* @__PURE__ */ jsx27(
2359
+ /* @__PURE__ */ jsxs21("section", { className: "flex items-center-safe justify-center-safe gap-4", children: [
2360
+ /* @__PURE__ */ jsx26(
2714
2361
  Button_default,
2715
2362
  {
2716
2363
  className: "bg-gray-600 hover:bg-gray-500",
@@ -2718,7 +2365,7 @@ var ShopperIsNotAuthenticated = ({ ID }) => {
2718
2365
  children: "Seguir sem Benef\xEDcios"
2719
2366
  }
2720
2367
  ),
2721
- /* @__PURE__ */ jsx27(Link_default, { href: customLoginUrl || "/login", children: "Aproveitar Benef\xEDcios" })
2368
+ /* @__PURE__ */ jsx26(Link_default, { href: customLoginUrl || "/login", children: "Aproveitar Benef\xEDcios" })
2722
2369
  ] })
2723
2370
  ] })
2724
2371
  ]
@@ -2731,94 +2378,46 @@ var ShopperIsNotAuthenticated_default = ShopperIsNotAuthenticated;
2731
2378
  import Skeleton from "@mui/material/Skeleton";
2732
2379
 
2733
2380
  // src/hooks/useAppStartup.tsx
2734
- import { useEffect as useEffect4, useState as useState10 } from "react";
2735
-
2736
- // src/services/authorization.ts
2737
- import Cookies11 from "js-cookie";
2738
-
2739
- // src/services/clients-config.ts
2740
- var CLIENTS_CONFIG = {
2741
- santo_remedio: {
2742
- access_token: getEnv("VITE_KEYCLOAK_ACCESSTOKEN_SANTOREMEDIO") || ""
2743
- }
2744
- };
2381
+ import { useEffect as useEffect2, useState as useState9 } from "react";
2745
2382
 
2746
2383
  // src/services/authorization.ts
2384
+ import Cookies4 from "js-cookie";
2747
2385
  var GetAuthorization = async ({ tenant_id }) => {
2748
- const client = CLIENTS_CONFIG[tenant_id];
2749
- if (!client || !client.access_token) {
2386
+ if (!tenant_id) {
2750
2387
  throw new Error(`No configuration found for tenant: ${tenant_id}`);
2751
2388
  }
2752
- const response = await fetch(
2753
- `${getEnv("VITE_API_URL")}/auth`,
2754
- {
2755
- method: "POST",
2756
- headers: {
2757
- "Content-Type": "application/json",
2758
- "Accept": "application/json",
2759
- "Accept-Encoding": "gzip, deflate, br"
2760
- },
2761
- credentials: "include",
2762
- body: JSON.stringify({
2763
- accessToken: client.access_token
2764
- })
2765
- }
2766
- );
2767
- const data = await response.json();
2768
- if (!data.success) {
2769
- throw new Error("Authorization failed");
2770
- }
2771
- const SECONDS_IN_A_DAY = 86400;
2772
- Cookies11.set("pbm-token", data.data.access_token, {
2773
- secure: true,
2774
- sameSite: "Strict",
2775
- expires: data.data.expires_in / SECONDS_IN_A_DAY
2776
- });
2777
- return data;
2778
- };
2779
-
2780
- // src/services/get-product-by-ean.ts
2781
- import Cookies12 from "js-cookie";
2782
- var GetProductByEAN = async ({ PRODUCT_EAN }) => {
2783
- const API_URL = getEnv("VITE_API_URL");
2784
- const AUTH_TOKEN = Cookies12.get("pbm-token");
2785
- if (!AUTH_TOKEN) {
2786
- throw new Error("Token is not defined in cookies or is expired");
2787
- }
2788
- const response = await fetch(`${API_URL}/products/ean/${PRODUCT_EAN}`, {
2789
- method: "GET",
2790
- headers: {
2791
- Authorization: `Bearer ${AUTH_TOKEN}`,
2792
- "Content-Type": "application/json"
2793
- }
2794
- });
2795
- const dataResponse = await response.json();
2796
- if (!dataResponse.success) {
2797
- throw new Error(dataResponse.message || "Failed to fetch authorization");
2798
- }
2799
- return dataResponse;
2800
- };
2801
-
2802
- // src/services/get-list-products.ts
2803
- import Cookies13 from "js-cookie";
2804
- var GetProductsWithBenefits = async (eanProduct) => {
2805
- const API_URL = getEnv("VITE_API_URL");
2806
- const AUTH_TOKEN = Cookies13.get("pbm-token");
2807
- if (!AUTH_TOKEN) {
2808
- throw new Error("Token is not defined in cookies or is expired");
2809
- }
2810
- const response = await fetch(`${API_URL}/products/program-verification/${eanProduct}`, {
2811
- method: "GET",
2812
- headers: {
2813
- Authorization: `Bearer ${AUTH_TOKEN}`,
2814
- "Content-Type": "application/json"
2389
+ try {
2390
+ const response = await fetch(
2391
+ `${getEnv("VITE_API_URL")}/api/token.ts`,
2392
+ {
2393
+ method: "POST",
2394
+ headers: {
2395
+ "Content-Type": "application/json",
2396
+ "Accept": "application/json"
2397
+ },
2398
+ body: JSON.stringify({ tenant_id })
2399
+ }
2400
+ );
2401
+ const data = await response.json();
2402
+ if (!data.success) {
2403
+ throw new Error("PBMLOG: Authorization failed!");
2815
2404
  }
2816
- });
2817
- const dataResponse = await response.json();
2818
- if (!dataResponse.success) {
2819
- throw new Error(dataResponse.message || "Failed to fetch authorization");
2405
+ const SECONDS_IN_A_DAY = 86400;
2406
+ Cookies4.set("pbm-token", data.access_token, {
2407
+ secure: true,
2408
+ sameSite: "Strict",
2409
+ expires: data.expires_in / SECONDS_IN_A_DAY
2410
+ });
2411
+ Cookies4.set("tenant_id", tenant_id, {
2412
+ secure: true,
2413
+ sameSite: "Strict",
2414
+ expires: 7
2415
+ });
2416
+ return data;
2417
+ } catch (error) {
2418
+ console.error("Error during authorization:", error);
2419
+ return { success: false, error: "Authorization failed" };
2820
2420
  }
2821
- return dataResponse;
2822
2421
  };
2823
2422
 
2824
2423
  // src/libs/zustand/useTheme.tsx
@@ -2848,21 +2447,169 @@ function useTheme(selector) {
2848
2447
  );
2849
2448
  }
2850
2449
 
2450
+ // src/services/load-products-table.ts
2451
+ import Cookies5 from "js-cookie";
2452
+
2453
+ // src/utils/cleanupCacheTimestamp.ts
2454
+ var CLEANUP_HOUR = 2;
2455
+ var CLEANUP_MINUTE = 30;
2456
+ var cleanupCacheTimestamp = () => {
2457
+ const now = /* @__PURE__ */ new Date();
2458
+ const next = new Date(now);
2459
+ next.setHours(CLEANUP_HOUR, CLEANUP_MINUTE, 0, 0);
2460
+ if (next.getTime() <= now.getTime()) {
2461
+ next.setDate(next.getDate() + 1);
2462
+ }
2463
+ return next.getTime();
2464
+ };
2465
+
2466
+ // src/services/load-products-table.ts
2467
+ var memoryCache = /* @__PURE__ */ new Map();
2468
+ function getCacheKey(tenant_id) {
2469
+ return `load-products-table:${tenant_id}`;
2470
+ }
2471
+ function readCache(key) {
2472
+ const memEntry = memoryCache.get(key);
2473
+ if (memEntry && Date.now() < memEntry.expiresAt) {
2474
+ return memEntry.data;
2475
+ }
2476
+ try {
2477
+ const raw = localStorage.getItem(key);
2478
+ if (!raw) return null;
2479
+ const entry = JSON.parse(raw);
2480
+ if (Date.now() >= entry.expiresAt) {
2481
+ localStorage.removeItem(key);
2482
+ return null;
2483
+ }
2484
+ memoryCache.set(key, entry);
2485
+ return entry.data;
2486
+ } catch {
2487
+ return null;
2488
+ }
2489
+ }
2490
+ function writeCache(key, data) {
2491
+ const entry = { data, expiresAt: cleanupCacheTimestamp(), success: true };
2492
+ memoryCache.set(key, entry);
2493
+ localStorage.setItem(key, JSON.stringify(entry));
2494
+ }
2495
+ var LoadProductsTable = async ({ tenant_id }) => {
2496
+ if (!tenant_id) {
2497
+ throw new Error(`No configuration found for tenant: ${tenant_id}`);
2498
+ }
2499
+ const cacheKey = getCacheKey(tenant_id);
2500
+ const cached = readCache(cacheKey);
2501
+ if (cached) {
2502
+ const result2 = {
2503
+ data: cached,
2504
+ expiresAt: memoryCache.get(cacheKey).expiresAt,
2505
+ success: true
2506
+ };
2507
+ return result2;
2508
+ }
2509
+ const response = await fetch(
2510
+ `${getEnv("VITE_API_URL")}/api/load-tables.ts`,
2511
+ {
2512
+ method: "POST",
2513
+ headers: {
2514
+ "Content-Type": "application/json",
2515
+ "Accept": "application/json",
2516
+ "Authorization": `Bearer ${Cookies5.get("pbm-token")}`
2517
+ },
2518
+ body: JSON.stringify({ tenant_id })
2519
+ }
2520
+ );
2521
+ const data = await response.json();
2522
+ if (data.informativeText !== "Processamento aprovado") {
2523
+ throw new Error("PBMLOG: Load Products Table Failed!");
2524
+ }
2525
+ Cookies5.set("current-table-id", data.control.tableId, {
2526
+ secure: true,
2527
+ sameSite: "Strict",
2528
+ expires: 1
2529
+ });
2530
+ Cookies5.set("current-central-number", data.control.centralNumber.toString(), {
2531
+ secure: true,
2532
+ sameSite: "Strict",
2533
+ expires: 1
2534
+ });
2535
+ Cookies5.set("current-local-hour", data.local_hour, {
2536
+ secure: true,
2537
+ sameSite: "Strict",
2538
+ expires: 1
2539
+ });
2540
+ const formattedData = extractTableData(data.control.tableImage);
2541
+ writeCache(cacheKey, formattedData);
2542
+ const result = {
2543
+ data: formattedData,
2544
+ expiresAt: memoryCache.get(cacheKey).expiresAt,
2545
+ success: true
2546
+ };
2547
+ return result;
2548
+ };
2549
+ function extractTableData(tableImage) {
2550
+ const states = tableImage.map((s) => s.state);
2551
+ const cities = tableImage.flatMap((s) => s.cities.map((c) => c.city));
2552
+ const federalCodes = tableImage.flatMap((s) => s.cities.flatMap((c) => c.federalCodes.map((f) => f.federalCode)));
2553
+ const programNames = tableImage.flatMap((s) => s.cities.flatMap((c) => c.federalCodes.flatMap((f) => f.programNames.map((p) => p.programName))));
2554
+ const products = tableImage.flatMap((s) => s.cities.flatMap((c) => c.federalCodes.flatMap((f) => f.programNames.flatMap((p) => p.products.map((pr) => pr.ean)))));
2555
+ return { states, cities, federalCodes, programNames, products };
2556
+ }
2557
+
2558
+ // src/services/product.ts
2559
+ import Cookies6 from "js-cookie";
2560
+ var GetProduct = async ({ tenant_id, product }) => {
2561
+ if (!tenant_id) {
2562
+ throw new Error(`No configuration found for tenant: ${tenant_id}`);
2563
+ }
2564
+ if (!product) {
2565
+ throw new Error(`Product information is required`);
2566
+ }
2567
+ try {
2568
+ const response = await fetch(
2569
+ `${getEnv("VITE_API_URL")}/api/product.ts`,
2570
+ {
2571
+ method: "POST",
2572
+ headers: {
2573
+ "Content-Type": "application/json",
2574
+ "Accept": "application/json",
2575
+ "Authorization": `Bearer ${Cookies6.get("pbm-token")}`
2576
+ },
2577
+ body: JSON.stringify({
2578
+ tenant_id,
2579
+ product,
2580
+ table_id: Cookies6.get("current-table-id"),
2581
+ local_hour: Cookies6.get("current-local-hour")
2582
+ })
2583
+ }
2584
+ );
2585
+ const data = await response.json();
2586
+ if (!data.success) {
2587
+ throw new Error("PBMLOG: Get Product Failed!");
2588
+ }
2589
+ return data;
2590
+ } catch (error) {
2591
+ console.error("Error during get product:", error);
2592
+ return { success: false, error: "Get Product Failed" };
2593
+ }
2594
+ };
2595
+
2851
2596
  // src/hooks/useAppStartup.tsx
2852
2597
  var useAppStartup = (props) => {
2853
2598
  const {
2854
2599
  setTargetProduct,
2855
- targetProduct,
2600
+ setBenefitsList,
2856
2601
  setIsAuthenticatedShopper,
2857
2602
  setCustomLoginUrl
2858
2603
  } = usePBMStore();
2859
2604
  const { setTheme } = useTheme();
2860
- const [IsReady, setIsReady] = useState10(false);
2861
- const [IsValid, setIsValid] = useState10(false);
2862
- const [EanProductExist, setEanProductExist] = useState10(true);
2605
+ const [IsReady, setIsReady] = useState9(false);
2606
+ const [IsValid, setIsValid] = useState9(false);
2607
+ const [EanProductExist, setEanProductExist] = useState9(true);
2863
2608
  const fetchAuthorizationRequest = async () => {
2864
2609
  try {
2865
- const response = await GetAuthorization({ tenant_id: props.tenant_id });
2610
+ const response = await GetAuthorization({
2611
+ tenant_id: props.tenant_id
2612
+ });
2866
2613
  if (!response.success) {
2867
2614
  console.error("PBMLOG: Authorization failed!");
2868
2615
  }
@@ -2873,57 +2620,73 @@ var useAppStartup = (props) => {
2873
2620
  }
2874
2621
  };
2875
2622
  const fetchValidateProduct = async () => {
2876
- if (!props.ean_product) {
2877
- console.error("PBMLOG: Ean is not defined.");
2623
+ if (!props.target_product) {
2624
+ console.error("PBMLOG: Target product is not defined.");
2878
2625
  setEanProductExist(false);
2879
2626
  return false;
2880
2627
  }
2881
2628
  try {
2882
- const response = await GetProductsWithBenefits(props.ean_product);
2883
- if (response.success) {
2884
- const data = response.data;
2885
- const hasProductInList = data.ean == props.ean_product && data.showModule;
2886
- setIsValid(hasProductInList);
2887
- return hasProductInList;
2629
+ const response = await LoadProductsTable({ tenant_id: props.tenant_id });
2630
+ if (!response.success) {
2631
+ console.error("PBMLOG: Product validation failed!");
2632
+ return false;
2633
+ }
2634
+ if (response.data.products.includes(props.target_product.ean.toString())) {
2635
+ setEanProductExist(true);
2636
+ return true;
2888
2637
  }
2638
+ return false;
2889
2639
  } catch (error) {
2890
- console.error(error);
2640
+ console.error("Error fetching product validation:", error);
2641
+ setEanProductExist(false);
2891
2642
  }
2892
2643
  return false;
2893
2644
  };
2894
- const fetchProductByEan = async () => {
2645
+ const fetchProductHasEnableDiscount = async () => {
2895
2646
  try {
2896
- if (!props.ean_product) {
2897
- console.error("PBMLOG: Ean is not defined.");
2647
+ if (!props.target_product) {
2648
+ console.error("PBMLOG: Target product is not defined.");
2898
2649
  setEanProductExist(false);
2899
- return;
2650
+ return false;
2900
2651
  }
2901
- const response = await GetProductByEAN({
2902
- PRODUCT_EAN: props.ean_product
2652
+ const response = await GetProduct({
2653
+ tenant_id: props.tenant_id,
2654
+ product: props.target_product
2903
2655
  });
2904
- if (response.success && response.data) {
2905
- setEanProductExist(true);
2906
- const { pbm, sku: _sku, ...targetProductNewData } = response.data;
2907
- setTargetProduct({
2908
- ...targetProduct,
2909
- ...targetProductNewData,
2910
- productId: Number(targetProductNewData.productId),
2911
- informativeMessage: pbm.informativeMessage ?? "",
2912
- discountMax: pbm.discountMax ?? 0,
2913
- industryLogo: pbm.imageLink ?? void 0,
2914
- ean: props.ean_product
2915
- });
2916
- setIsAuthenticatedShopper(props.is_authenticated_shopper);
2917
- setCustomLoginUrl(props.custom_login_url);
2918
- } else {
2656
+ if (!response.success) {
2657
+ console.error("PBMLOG: Product discount check failed!");
2919
2658
  setEanProductExist(false);
2659
+ return false;
2920
2660
  }
2661
+ if (!response.product || response.product.length === 0) {
2662
+ console.error("PBMLOG: Product not found in discount check!");
2663
+ setEanProductExist(false);
2664
+ return false;
2665
+ }
2666
+ setTargetProduct({
2667
+ ...response.product[0],
2668
+ requestedQuantity: "1",
2669
+ listPrice: formaters.priceToInteger(props.target_product.listPrice),
2670
+ netPrice: formaters.priceToInteger(props.target_product.netPrice)
2671
+ });
2672
+ setBenefitsList(
2673
+ response.product.map((prod) => ({
2674
+ ...prod,
2675
+ listPrice: props.target_product.listPrice,
2676
+ netPrice: props.target_product.netPrice
2677
+ }))
2678
+ );
2679
+ setIsAuthenticatedShopper(props.is_authenticated_shopper);
2680
+ setCustomLoginUrl(props.custom_login_url);
2681
+ setEanProductExist(true);
2682
+ return true;
2921
2683
  } catch (error) {
2922
2684
  console.error(error);
2923
2685
  setEanProductExist(false);
2686
+ return false;
2924
2687
  }
2925
2688
  };
2926
- useEffect4(() => {
2689
+ useEffect2(() => {
2927
2690
  let isMounted = true;
2928
2691
  const startup = async () => {
2929
2692
  if (props.theme) {
@@ -2931,9 +2694,13 @@ var useAppStartup = (props) => {
2931
2694
  }
2932
2695
  const isAuthorized = await fetchAuthorizationRequest();
2933
2696
  if (!isAuthorized || !isMounted) return;
2934
- const isValidProduct = await fetchValidateProduct();
2697
+ const isValidProduct = await Promise.all(
2698
+ [fetchValidateProduct(), fetchProductHasEnableDiscount()].filter(
2699
+ Boolean
2700
+ )
2701
+ ).then((results) => results.every(Boolean));
2702
+ setIsValid(isValidProduct);
2935
2703
  if (!isValidProduct || !isMounted) return;
2936
- await fetchProductByEan();
2937
2704
  if (isMounted) {
2938
2705
  setIsReady(true);
2939
2706
  }
@@ -2942,14 +2709,14 @@ var useAppStartup = (props) => {
2942
2709
  return () => {
2943
2710
  isMounted = false;
2944
2711
  };
2945
- }, [props.ean_product, props.tenant_id]);
2712
+ }, [props.tenant_id]);
2946
2713
  return { IsReady, IsValid, EanProductExist };
2947
2714
  };
2948
2715
  var useAppStartup_default = useAppStartup;
2949
2716
 
2950
2717
  // src/PBM.tsx
2951
2718
  import { useTransition as useTransition2 } from "react";
2952
- import { Fragment as Fragment3, jsx as jsx28, jsxs as jsxs23 } from "react/jsx-runtime";
2719
+ import { Fragment as Fragment3, jsx as jsx27, jsxs as jsxs22 } from "react/jsx-runtime";
2953
2720
  function PBM(props) {
2954
2721
  const { state } = usePBMStore();
2955
2722
  const { IsReady, EanProductExist, IsValid } = useAppStartup_default(props);
@@ -2959,7 +2726,7 @@ function PBM(props) {
2959
2726
  const formatedProductPrice = formaters.price(props.original_product_price);
2960
2727
  if (!IsValid) return;
2961
2728
  if (!IsReady) {
2962
- return /* @__PURE__ */ jsx28(
2729
+ return /* @__PURE__ */ jsx27(
2963
2730
  Skeleton,
2964
2731
  {
2965
2732
  variant: "rectangular",
@@ -2973,9 +2740,9 @@ function PBM(props) {
2973
2740
  setErrorMessage(
2974
2741
  "O produto n\xE3o foi encontrado no sistema. Por favor, tente novamente mais tarde ou contate o suporte."
2975
2742
  );
2976
- return /* @__PURE__ */ jsx28("div", { id: "pbm-library-root", children: /* @__PURE__ */ jsx28(ErrorToApplyBenefits_default, {}) });
2743
+ return /* @__PURE__ */ jsx27("div", { id: "pbm-library-root", children: /* @__PURE__ */ jsx27(ErrorToApplyBenefits_default, {}) });
2977
2744
  }
2978
- return /* @__PURE__ */ jsxs23(
2745
+ return /* @__PURE__ */ jsxs22(
2979
2746
  "div",
2980
2747
  {
2981
2748
  id: "pbm-library-root",
@@ -2991,19 +2758,18 @@ function PBM(props) {
2991
2758
  "--pbm-input-background": theme.inputBackgroundColor
2992
2759
  },
2993
2760
  children: [
2994
- /* @__PURE__ */ jsxs23(Container_default, { variant: "main", children: [
2995
- /* @__PURE__ */ jsx28(Header_default, { originalProductPrice: formatedProductPrice || 0 }),
2996
- /* @__PURE__ */ jsx28(Container_default, { variant: "simple", children: isPending ? /* @__PURE__ */ jsx28(Loading_default, {}) : /* @__PURE__ */ jsxs23(Fragment3, { children: [
2997
- state === "isEmpty" && /* @__PURE__ */ jsx28(Form_default, { startTransition }),
2998
- state === "isInvalid" && /* @__PURE__ */ jsx28(SecurityNumberInvalid_default, {}),
2999
- state === "isRegistered" && /* @__PURE__ */ jsx28(SecurityNumberRegitered_default, {}),
3000
- (state === "isActivated" || state === "isPreview") && /* @__PURE__ */ jsx28(BenefitsTable_default, {}),
3001
- state === "isError" && /* @__PURE__ */ jsx28(ErrorToApplyBenefits_default, {})
2761
+ /* @__PURE__ */ jsxs22(Container_default, { variant: "main", children: [
2762
+ /* @__PURE__ */ jsx27(Header_default, { originalProductPrice: formatedProductPrice || 0 }),
2763
+ /* @__PURE__ */ jsx27(Container_default, { variant: "simple", children: isPending ? /* @__PURE__ */ jsx27(Loading_default, {}) : /* @__PURE__ */ jsxs22(Fragment3, { children: [
2764
+ state === "isEmpty" && /* @__PURE__ */ jsx27(Form_default, { startTransition }),
2765
+ state === "isInvalid" && /* @__PURE__ */ jsx27(SecurityNumberInvalid_default, {}),
2766
+ state === "isRegistered" && /* @__PURE__ */ jsx27(SecurityNumberRegitered_default, {}),
2767
+ (state === "isActivated" || state === "isPreview") && /* @__PURE__ */ jsx27(BenefitsTable_default, {}),
2768
+ state === "isError" && /* @__PURE__ */ jsx27(ErrorToApplyBenefits_default, {})
3002
2769
  ] }) })
3003
2770
  ] }),
3004
- /* @__PURE__ */ jsx28(ShopperIsNotAuthenticated_default, { ID: "ShopperIsNotAuthenticated" }),
3005
- /* @__PURE__ */ jsx28(CustomerNotRegistered_default, { ID: "CustomerNotRegistered" }),
3006
- /* @__PURE__ */ jsx28(Iframe_default, {})
2771
+ /* @__PURE__ */ jsx27(ShopperIsNotAuthenticated_default, { ID: "ShopperIsNotAuthenticated" }),
2772
+ /* @__PURE__ */ jsx27(CustomerNotRegistered_default, { ID: "CustomerNotRegistered" })
3007
2773
  ]
3008
2774
  }
3009
2775
  );