@agrada_digital/pbm 0.0.40

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.mjs ADDED
@@ -0,0 +1,776 @@
1
+ // src/components/Header/index.tsx
2
+ import { jsx, jsxs } from "react/jsx-runtime";
3
+ function Header({ originalProductPrice }) {
4
+ return /* @__PURE__ */ jsxs(
5
+ "header",
6
+ {
7
+ className: "flex items-center justify-between w-full p-0.5 rounded-full bg-[#44c2c0]/30",
8
+ id: "header_pbm",
9
+ children: [
10
+ /* @__PURE__ */ jsx(
11
+ "span",
12
+ {
13
+ className: "py-1 px-6 rounded-full bg-[#44c2c0] shrink-0 text-white text-sm font-bold",
14
+ "data-testid": "test_id_header_price",
15
+ children: Number(originalProductPrice)?.toLocaleString("pt-BR", {
16
+ currency: "BRL",
17
+ currencyDisplay: "symbol",
18
+ currencySign: "standard",
19
+ style: "currency"
20
+ })
21
+ }
22
+ ),
23
+ /* @__PURE__ */ jsx("h1", { className: "text-center w-full text-[#339c9b] font-bold text-xs px-4 md:text-sm", children: "Benef\xEDcio de Laborat\xF3rio" })
24
+ ]
25
+ }
26
+ );
27
+ }
28
+ var Header_default = Header;
29
+
30
+ // src/components/UI/Container/index.tsx
31
+ import classNames from "classnames";
32
+ import { jsx as jsx2 } from "react/jsx-runtime";
33
+ function Container({
34
+ children,
35
+ variant
36
+ }) {
37
+ return /* @__PURE__ */ jsx2(
38
+ "main",
39
+ {
40
+ className: classNames({
41
+ "flex flex-col items-center justify-center min-w-[var(--min-container)] max-w-[var(--max-container)] w-full h-auto rounded-2xl p-4 bg-gray-100 gap-4": variant === "main",
42
+ "w-full h-auto relative": variant === "simple"
43
+ }),
44
+ "data-testid": "test_id_container",
45
+ "data-variant": variant,
46
+ id: "container_pbm",
47
+ children
48
+ }
49
+ );
50
+ }
51
+ var Container_default = Container;
52
+
53
+ // src/components/Footer/index.tsx
54
+ import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
55
+ function Footer({ industryLogo }) {
56
+ return /* @__PURE__ */ jsx3("footer", { className: "w-full h-auto relative", id: "footer_pbm", children: /* @__PURE__ */ jsxs2("section", { className: "flex items-center justify-center w-full h-auto gap-4", children: [
57
+ /* @__PURE__ */ jsxs2("section", { className: "w-4/5 h-auto", children: [
58
+ /* @__PURE__ */ jsx3("h3", { className: "text-start font-semibold text-sm", children: "Economize com o benef\xEDcio do laborat\xF3rio." }),
59
+ /* @__PURE__ */ jsx3("p", { className: "text-start font-normal text-sm", children: "Este produto tem pre\xE7o exclusivo para clientes cadastrados no programa." })
60
+ ] }),
61
+ industryLogo && /* @__PURE__ */ jsx3(
62
+ "img",
63
+ {
64
+ src: industryLogo,
65
+ alt: "parceiro",
66
+ className: "w-1/5 min-w-20 h-auto aspect-square",
67
+ loading: "eager",
68
+ id: "footer_industry_logo_pbm",
69
+ "data-testid": "footer_industry_logo_pbm"
70
+ }
71
+ )
72
+ ] }) });
73
+ }
74
+ var Footer_default = Footer;
75
+
76
+ // src/schema/validation-schema.ts
77
+ import { z } from "zod";
78
+ var validationSchema = z.strictObject({
79
+ securityNumber: z.string({
80
+ required_error: "CPF \xE9 obrigat\xF3rio."
81
+ }).refine((doc) => {
82
+ const replacedDoc = doc.replace(/\D/g, "");
83
+ return replacedDoc.length >= 11;
84
+ }, "CPF deve conter no m\xEDnimo 11 caracteres.").refine((doc) => {
85
+ const replacedDoc = doc.replace(/\D/g, "");
86
+ return !!Number(replacedDoc);
87
+ }, "CPF deve conter apenas n\xFAmeros.")
88
+ });
89
+
90
+ // src/utils/format.ts
91
+ var toFormat = (value) => {
92
+ const cleanedValue = value.replace(/\D/g, "");
93
+ if (cleanedValue.length <= 11) {
94
+ return cleanedValue.replace(/(\d{3})(\d)/, "$1.$2").replace(/(\d{3})(\d)/, "$1.$2").replace(/(\d{3})(\d{1,2})/, "$1-$2").replace(/(-\d{2})\d+?$/, "$1");
95
+ }
96
+ };
97
+
98
+ // src/components/Form/index.tsx
99
+ import classNames2 from "classnames";
100
+ import { zodResolver } from "@hookform/resolvers/zod";
101
+ import { useForm } from "react-hook-form";
102
+ import { ArrowRight } from "lucide-react";
103
+
104
+ // src/libs/zustand/usePBM.tsx
105
+ import { create, createStore } from "zustand";
106
+ var initialPBMState = {
107
+ securityNumber: "",
108
+ state: "isEmpty",
109
+ availableDiscountSelected: {
110
+ quantity: 0,
111
+ discount: {
112
+ unit: 0,
113
+ total: 0
114
+ },
115
+ totalPrice: 0
116
+ },
117
+ targetProduct: null,
118
+ campaign: "pbm_campaign"
119
+ };
120
+ var createPBMStore = (set) => ({
121
+ ...initialPBMState,
122
+ setSecurityNumber: (securityNumber) => set({ securityNumber }),
123
+ setState: (state) => set({ state }),
124
+ setTargetProduct: (targetProduct) => set({ targetProduct }),
125
+ setAvailableDiscountSelected: (availableDiscount) => set({ availableDiscountSelected: availableDiscount })
126
+ });
127
+ var usePBMStore = create(createPBMStore);
128
+ var pbmStore = createStore(createPBMStore);
129
+
130
+ // src/components/Form/index.tsx
131
+ import { jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
132
+ function Form({ setLoading }) {
133
+ const { setSecurityNumber, setState, securityNumber } = usePBMStore();
134
+ const {
135
+ handleSubmit,
136
+ register,
137
+ setValue,
138
+ formState: { errors }
139
+ } = useForm({
140
+ resolver: zodResolver(validationSchema),
141
+ defaultValues: {
142
+ securityNumber: securityNumber || ""
143
+ }
144
+ });
145
+ const onSubmitDefault = (values) => {
146
+ setLoading(true);
147
+ new Promise((resolve) => {
148
+ setTimeout(() => {
149
+ resolve({
150
+ securityNumber: values.securityNumber,
151
+ state: "isInvalid"
152
+ });
153
+ }, 2e3);
154
+ }).then((result) => {
155
+ const response = result;
156
+ setSecurityNumber(response.securityNumber);
157
+ setState(response.state);
158
+ }).finally(() => {
159
+ setLoading(false);
160
+ });
161
+ };
162
+ return /* @__PURE__ */ jsxs3(
163
+ "form",
164
+ {
165
+ onSubmit: handleSubmit(onSubmitDefault),
166
+ className: classNames2(
167
+ "w-full h-auto flex items-center justify-center mb-0 transition-all duration-150",
168
+ { "mb-4": errors.securityNumber }
169
+ ),
170
+ id: "form_security_number_pbm",
171
+ children: [
172
+ /* @__PURE__ */ jsxs3(
173
+ "label",
174
+ {
175
+ htmlFor: "cpf",
176
+ className: "w-4/5 h-auto flex items-start flex-col justify-center relative py-2",
177
+ id: "label_security_number_pbm",
178
+ children: [
179
+ /* @__PURE__ */ jsx4(
180
+ "input",
181
+ {
182
+ type: "text",
183
+ className: classNames2(
184
+ "w-full h-8 bg-[#44c2c0]/20 rounded-s-full text-sm font-semibold focus:outline focus:outline-[#339c9b] focus:bg-[#44c2c0]/30 text-zinc-600 placeholder:text-zinc-600 px-4 placeholder:text-sm placeholder:font-semibold",
185
+ { "outline outline-red-600": errors.securityNumber }
186
+ ),
187
+ placeholder: "Digite seu CPF aqui...",
188
+ required: true,
189
+ maxLength: 14,
190
+ ...register("securityNumber", {
191
+ onChange: (e) => {
192
+ const formatted = toFormat(e.target.value);
193
+ setValue("securityNumber", formatted, {
194
+ shouldValidate: true
195
+ });
196
+ }
197
+ }),
198
+ defaultValue: securityNumber || "",
199
+ id: "input_security_number_pbm"
200
+ }
201
+ ),
202
+ errors.securityNumber && /* @__PURE__ */ jsx4("span", { className: "text-red-400 text-xs font-semibold absolute -bottom-3 left-2 text-nowrap", children: errors.securityNumber.message })
203
+ ]
204
+ }
205
+ ),
206
+ /* @__PURE__ */ jsx4(
207
+ "button",
208
+ {
209
+ type: "submit",
210
+ className: "bg-gray-400 w-1/5 h-8 flex items-center justify-center rounded-e-full cursor-pointer",
211
+ id: "button_submit_security_number_pbm",
212
+ children: /* @__PURE__ */ jsx4(ArrowRight, { size: 24, color: "white", strokeWidth: 2 })
213
+ }
214
+ )
215
+ ]
216
+ }
217
+ );
218
+ }
219
+ var Form_default = Form;
220
+
221
+ // src/components/UI/Loading/index.tsx
222
+ import { jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
223
+ function Loading({ textColor }) {
224
+ return /* @__PURE__ */ jsxs4("main", { className: "flex items-center justify-center gap-4", id: "loading_pbm", children: [
225
+ /* @__PURE__ */ jsx5(
226
+ "div",
227
+ {
228
+ "data-testid": "test_id_spin",
229
+ className: "w-8 h-8 border-4 border-t-gray-700 border-gray-300 rounded-full animate-spin"
230
+ }
231
+ ),
232
+ /* @__PURE__ */ jsx5(
233
+ "p",
234
+ {
235
+ className: "text-sm font-semibold text-start text-zinc-900",
236
+ style: { color: textColor },
237
+ children: "Um momento... estamos verificando seus dados."
238
+ }
239
+ )
240
+ ] });
241
+ }
242
+ var Loading_default = Loading;
243
+
244
+ // src/components/UI/Button/index.tsx
245
+ import classNames3 from "classnames";
246
+ import { jsx as jsx6 } from "react/jsx-runtime";
247
+ function Button(props) {
248
+ return /* @__PURE__ */ jsx6(
249
+ "button",
250
+ {
251
+ ...props,
252
+ className: classNames3(
253
+ "w-3xs cursor-pointer h-10 rounded-full bg-blue-500 hover:bg-blue-400 text-white text-sm font-semibold transition-colors",
254
+ props.className
255
+ ),
256
+ children: props.children
257
+ }
258
+ );
259
+ }
260
+ var Button_default = Button;
261
+
262
+ // src/components/BenefitsTable/index.tsx
263
+ import { useState } from "react";
264
+
265
+ // src/mocks/benefits.ts
266
+ var BENEFITS_ITEMS = [
267
+ {
268
+ id: 1,
269
+ ean: "001",
270
+ authorizedQuantity: 1,
271
+ discountValue: 4800,
272
+ discountPercentual: 2400
273
+ },
274
+ {
275
+ id: 2,
276
+ ean: "002",
277
+ authorizedQuantity: 2,
278
+ discountValue: 4800,
279
+ discountPercentual: 2400
280
+ },
281
+ {
282
+ id: 3,
283
+ ean: "003",
284
+ authorizedQuantity: 3,
285
+ discountValue: 9400,
286
+ discountPercentual: 4700
287
+ }
288
+ ];
289
+
290
+ // src/components/UI/Title/index.tsx
291
+ import classNames4 from "classnames";
292
+ import { jsx as jsx7 } from "react/jsx-runtime";
293
+ function Title(props) {
294
+ return /* @__PURE__ */ jsx7(
295
+ "h2",
296
+ {
297
+ className: classNames4(
298
+ "text-start font-semibold text-sm text-zinc-900",
299
+ props.className
300
+ ),
301
+ style: { color: props.textColor, fontSize: props.textSize },
302
+ "data-testid": "test_id_title",
303
+ children: props.children
304
+ }
305
+ );
306
+ }
307
+ var Title_default = Title;
308
+
309
+ // src/components/BenefitsTable/Item.tsx
310
+ import { Badge, BadgeCheck } from "lucide-react";
311
+ import { useCallback, useEffect } from "react";
312
+ import { jsx as jsx8, jsxs as jsxs5 } from "react/jsx-runtime";
313
+ function Item({ data, onChange, checked, originalProductPrice }) {
314
+ const { setAvailableDiscountSelected, securityNumber } = usePBMStore();
315
+ const ID_INPUT = "unity_quantity_" + data.authorizedQuantity;
316
+ const decimalDiscount = data.discountPercentual / 1e4;
317
+ const unitDiscountValue = originalProductPrice * decimalDiscount;
318
+ const discountValue = unitDiscountValue * data.authorizedQuantity;
319
+ const totalPriceProductWithDiscountBenefit = originalProductPrice * data.authorizedQuantity - discountValue;
320
+ const updateStorageData = useCallback(() => {
321
+ if (checked) {
322
+ setAvailableDiscountSelected({
323
+ discount: {
324
+ total: discountValue,
325
+ unit: unitDiscountValue
326
+ },
327
+ quantity: data.authorizedQuantity,
328
+ totalPrice: totalPriceProductWithDiscountBenefit
329
+ });
330
+ }
331
+ }, [
332
+ checked,
333
+ data.authorizedQuantity,
334
+ setAvailableDiscountSelected,
335
+ discountValue,
336
+ totalPriceProductWithDiscountBenefit,
337
+ unitDiscountValue
338
+ ]);
339
+ useEffect(() => {
340
+ updateStorageData();
341
+ }, [updateStorageData]);
342
+ return /* @__PURE__ */ jsxs5(
343
+ "label",
344
+ {
345
+ htmlFor: ID_INPUT,
346
+ className: "w-full flex items-center justify-start bg-zinc-300/60 border border-zinc-400/50 px-4 py-2 hover:bg-zinc-300 transition-colors cursor-pointer rounded-full gap-1",
347
+ id: "label_benefits_" + ID_INPUT,
348
+ children: [
349
+ /* @__PURE__ */ jsx8(
350
+ "input",
351
+ {
352
+ type: "radio",
353
+ name: "benefits_discount",
354
+ id: ID_INPUT,
355
+ className: "hidden",
356
+ checked,
357
+ onChange,
358
+ disabled: !securityNumber
359
+ }
360
+ ),
361
+ !checked ? /* @__PURE__ */ jsx8(Badge, { color: "#9f9fa9", size: 20 }) : /* @__PURE__ */ jsx8(BadgeCheck, { color: "#32b316", size: 20 }),
362
+ /* @__PURE__ */ jsxs5("span", { className: "text-zinc-900 font-semibold text-sm", children: [
363
+ data.authorizedQuantity,
364
+ "un"
365
+ ] }),
366
+ /* @__PURE__ */ jsxs5("section", { className: "ml-auto relative", children: [
367
+ /* @__PURE__ */ jsxs5("span", { className: "absolute -top-4 text-emerald-900 py-0.5 font-semibold text-xs bg-[#32b316] px-2 w-auto text-nowrap rounded-2xl -right-4", children: [
368
+ discountValue.toLocaleString("pt-BR", {
369
+ currency: "BRL",
370
+ currencyDisplay: "symbol",
371
+ currencySign: "standard",
372
+ style: "currency"
373
+ }),
374
+ " ",
375
+ "OFF"
376
+ ] }),
377
+ /* @__PURE__ */ jsx8("strong", { className: "text-zinc-900 font-semibold text-sm text-center", children: totalPriceProductWithDiscountBenefit.toLocaleString("pt-BR", {
378
+ currency: "BRL",
379
+ currencyDisplay: "symbol",
380
+ currencySign: "standard",
381
+ style: "currency"
382
+ }) })
383
+ ] })
384
+ ]
385
+ }
386
+ );
387
+ }
388
+ var Item_default = Item;
389
+
390
+ // src/components/BenefitsTable/index.tsx
391
+ import { jsx as jsx9, jsxs as jsxs6 } from "react/jsx-runtime";
392
+ function BenefitsTable({
393
+ originalProductPrice
394
+ }) {
395
+ const { securityNumber, setState } = usePBMStore();
396
+ const [selectedDiscout, setSelectedDiscount] = useState(null);
397
+ return /* @__PURE__ */ jsxs6(
398
+ "section",
399
+ {
400
+ className: "flex items-start justify-center gap-4 w-full h-auto flex-col",
401
+ id: "benefits_table_pbm",
402
+ children: [
403
+ /* @__PURE__ */ jsx9(Title_default, { children: "Descontos dispon\xEDveis:" }),
404
+ /* @__PURE__ */ jsx9(
405
+ "form",
406
+ {
407
+ className: "flex flex-col items-center justify-start w-full gap-3",
408
+ id: "form_benefits_table_pbm",
409
+ children: BENEFITS_ITEMS.map((item, index) => {
410
+ const ID_INPUT = "unity_quantity_" + item.authorizedQuantity;
411
+ return /* @__PURE__ */ jsx9(
412
+ Item_default,
413
+ {
414
+ data: item,
415
+ checked: selectedDiscout === ID_INPUT,
416
+ onChange: () => setSelectedDiscount(ID_INPUT),
417
+ originalProductPrice
418
+ },
419
+ index
420
+ );
421
+ })
422
+ }
423
+ ),
424
+ !securityNumber && /* @__PURE__ */ jsxs6(
425
+ Button_default,
426
+ {
427
+ onClick: () => setState("isEmpty"),
428
+ 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",
429
+ children: [
430
+ "Aten\xE7\xE3o: n\xE3o \xE9 poss\xEDvel utilizar os benef\xEDcos sem realizar a consulta do cpf, por favor",
431
+ " ",
432
+ /* @__PURE__ */ jsx9("span", { className: "underline", children: "insira seu cpf para utilizar os benef\xEDcios" })
433
+ ]
434
+ }
435
+ ),
436
+ securityNumber && /* @__PURE__ */ jsx9(
437
+ Button_default,
438
+ {
439
+ onClick: () => setState("isEmpty"),
440
+ 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",
441
+ children: /* @__PURE__ */ jsx9("span", { className: "underline", children: "Deseja editar o cpf digitado?" })
442
+ }
443
+ )
444
+ ]
445
+ }
446
+ );
447
+ }
448
+ var BenefitsTable_default = BenefitsTable;
449
+
450
+ // src/components/UI/Text/index.tsx
451
+ import classNames5 from "classnames";
452
+ import { jsx as jsx10 } from "react/jsx-runtime";
453
+ function Text(props) {
454
+ return /* @__PURE__ */ jsx10(
455
+ "p",
456
+ {
457
+ className: classNames5(
458
+ "text-start font-normal text-sm text-zinc-900",
459
+ props.className
460
+ ),
461
+ style: { color: props.textColor, fontSize: props.textSize },
462
+ "data-testid": "test_id_text",
463
+ children: props.children
464
+ }
465
+ );
466
+ }
467
+ var Text_default = Text;
468
+
469
+ // src/components/Iframe/index.tsx
470
+ import classNames6 from "classnames";
471
+ import { TriangleAlert } from "lucide-react";
472
+ import { jsx as jsx11, jsxs as jsxs7 } from "react/jsx-runtime";
473
+ function Iframe({ url, title, openModal, setOpenModal }) {
474
+ return /* @__PURE__ */ jsxs7(
475
+ "main",
476
+ {
477
+ className: classNames6(
478
+ "fixed inset-0 flex items-center justify-center z-50 flex-col transition-all shadow",
479
+ {
480
+ "opacity-100 pointer-events-auto": openModal,
481
+ "opacity-0 pointer-events-none": !openModal
482
+ }
483
+ ),
484
+ "data-testid": "test_id_iframe",
485
+ children: [
486
+ /* @__PURE__ */ jsx11(
487
+ "div",
488
+ {
489
+ className: "bg-black/35 inset-0 absolute",
490
+ onClick: () => {
491
+ setOpenModal(false);
492
+ window.location.reload();
493
+ }
494
+ }
495
+ ),
496
+ /* @__PURE__ */ jsx11("section", { className: "w-4/5 h-auto bg-zinc-800 py-2 px-4 flex items-center justify-end rounded-ss-2xl rounded-se-2xl border-b-2 border-gray-100 z-10", children: /* @__PURE__ */ jsx11(
497
+ "button",
498
+ {
499
+ className: "shadow-2xl cursor-pointer text-white font-bold bg-red-500 w-auto h-auto px-8 py-2 rounded-full",
500
+ "aria-label": "Fechar o modal",
501
+ "data-testid": "test_id_buttonclose",
502
+ onClick: () => {
503
+ setOpenModal(false);
504
+ window.location.reload();
505
+ },
506
+ children: "Fechar"
507
+ }
508
+ ) }),
509
+ /* @__PURE__ */ jsx11(
510
+ "iframe",
511
+ {
512
+ src: url,
513
+ title,
514
+ width: "80%",
515
+ height: "80%",
516
+ allowFullScreen: true,
517
+ className: "z-10"
518
+ }
519
+ ),
520
+ /* @__PURE__ */ jsxs7("section", { className: "items-center justify-center flex flex-wrap gap-1 bg-zinc-800 z-10 w-4/5 py-2 px-4 rounded-ee-2xl rounded-es-2xl border-t-2 border-gray-100", children: [
521
+ /* @__PURE__ */ jsx11(TriangleAlert, { size: 20, className: "shrink-0 text-red-500 " }),
522
+ /* @__PURE__ */ jsxs7("p", { className: "text-start text-sm text-white", children: [
523
+ /* @__PURE__ */ jsx11("span", { className: "text-red-500 font-semibold text-base mr-1", children: "Aten\xE7\xE3o:" }),
524
+ "Ap\xF3s finalizar os termos de aceite, voc\xEA j\xE1 poder\xE1 fechar essa janela. Pode levar ",
525
+ /* @__PURE__ */ jsx11("strong", { children: "alguns minutos" }),
526
+ " para os seus dados serem aprovados."
527
+ ] })
528
+ ] })
529
+ ]
530
+ }
531
+ );
532
+ }
533
+ var Iframe_default = Iframe;
534
+
535
+ // src/components/SecurityNumberInvalid/index.tsx
536
+ import { useState as useState2 } from "react";
537
+ import { jsx as jsx12, jsxs as jsxs8 } from "react/jsx-runtime";
538
+ function SecurityNumberInvalid({ textColor }) {
539
+ const [openModal, setOpenModal] = useState2(false);
540
+ return /* @__PURE__ */ jsxs8(
541
+ "section",
542
+ {
543
+ "data-testid": "test_id_invalid",
544
+ className: "flex items-end justify-center gap-2 w-full h-auto flex-col border-y border-zinc-300 py-6",
545
+ id: "security_number_invalid_container_pbm",
546
+ children: [
547
+ /* @__PURE__ */ jsx12(Title_default, { className: "w-full", textColor, children: "CPF n\xE3o cadastrado!" }),
548
+ /* @__PURE__ */ jsx12(Text_default, { className: "w-full", textColor, children: "Por favor, conclua seu cadastro para habilitar os benef\xEDcios deste laborat\xF3rio." }),
549
+ /* @__PURE__ */ jsx12(
550
+ Button_default,
551
+ {
552
+ "data-testid": "test_id_openiframe",
553
+ onClick: () => setOpenModal(true),
554
+ id: "button_accept_terms_pbm",
555
+ children: "Aceitar os termos"
556
+ }
557
+ ),
558
+ /* @__PURE__ */ jsx12(
559
+ Iframe_default,
560
+ {
561
+ url: "https://termo.azurewebsites.net/",
562
+ title: "Aceitar termos PBM",
563
+ openModal,
564
+ setOpenModal
565
+ }
566
+ )
567
+ ]
568
+ }
569
+ );
570
+ }
571
+ var SecurityNumberInvalid_default = SecurityNumberInvalid;
572
+
573
+ // src/PBM.tsx
574
+ import { useCallback as useCallback2, useEffect as useEffect2, useState as useState3 } from "react";
575
+
576
+ // src/components/UI/Link/index.tsx
577
+ import classNames7 from "classnames";
578
+
579
+ // src/utils/getParams.ts
580
+ var getParams = (params) => {
581
+ if (params === void 0) return "";
582
+ return "?" + Object.keys(params).map((paramter) => paramter + "=" + params[paramter]).join("&");
583
+ };
584
+
585
+ // src/components/UI/Link/index.tsx
586
+ import { jsx as jsx13 } from "react/jsx-runtime";
587
+ function Link(props) {
588
+ return /* @__PURE__ */ jsx13(
589
+ "a",
590
+ {
591
+ ...props,
592
+ target: "_blank",
593
+ href: typeof props.href === "string" ? props.href : props.href.pathname + getParams(props.href.param),
594
+ className: classNames7(
595
+ "w-3xs cursor-pointer h-10 rounded-full bg-blue-500 hover:bg-blue-400 text-white text-sm font-semibold transition-colors flex items-center justify-center",
596
+ props.className
597
+ ),
598
+ "data-testid": "test_id_link",
599
+ children: props.children
600
+ }
601
+ );
602
+ }
603
+ var Link_default = Link;
604
+
605
+ // src/components/SecurityNumberRegitered/index.tsx
606
+ import { jsx as jsx14, jsxs as jsxs9 } from "react/jsx-runtime";
607
+ function SecurityNumberRegitered({ textColor }) {
608
+ return /* @__PURE__ */ jsxs9(
609
+ "section",
610
+ {
611
+ "data-testid": "test_id_registered",
612
+ className: "flex items-end justify-center gap-2 w-full h-auto flex-col border-y border-zinc-300 py-6",
613
+ id: "security_number_registered_container_pbm",
614
+ children: [
615
+ /* @__PURE__ */ jsx14(Title_default, { className: "w-full", textColor, children: "CPF n\xE3o habilitado no produto!" }),
616
+ /* @__PURE__ */ jsx14(Text_default, { className: "w-full", textColor, children: "Por favor, conclua seu cadastro para habilitar os benef\xEDcios deste laborat\xF3rio." }),
617
+ /* @__PURE__ */ jsx14(
618
+ Link_default,
619
+ {
620
+ href: {
621
+ pathname: "https://gip-pd-app.interplayers.com.br/idp-pd-app/adesao",
622
+ param: { guid: "f2aff249-51b4-49a4-b671-d6bee89da0f0" }
623
+ },
624
+ children: "Ativar CPF"
625
+ }
626
+ )
627
+ ]
628
+ }
629
+ );
630
+ }
631
+ var SecurityNumberRegitered_default = SecurityNumberRegitered;
632
+
633
+ // src/services/authorization.ts
634
+ import Cookies from "js-cookie";
635
+ var GetAuthorization = async ({ clientID }) => {
636
+ const API_URL = import.meta.env.VITE_API_URL;
637
+ const STORE_ID = import.meta.env.VITE_STORE_ID;
638
+ const STORE_NAME = import.meta.env.VITE_STORE_NAME;
639
+ if (!API_URL) {
640
+ throw new Error("API URL is not defined in environment variables");
641
+ }
642
+ if (!STORE_ID || !STORE_NAME) {
643
+ throw new Error("Store ID or Store Name is not defined in environment variables");
644
+ }
645
+ const response = await fetch(`${API_URL}/auth`, {
646
+ method: "POST",
647
+ headers: {
648
+ "Content-Type": "application/json"
649
+ },
650
+ body: JSON.stringify({
651
+ StoreID: STORE_ID,
652
+ StoreName: STORE_NAME,
653
+ ClientID: clientID
654
+ })
655
+ });
656
+ const dataResponse = await response.json();
657
+ if (!dataResponse.success) {
658
+ throw new Error(dataResponse.message || "Failed to fetch authorization");
659
+ }
660
+ Cookies.set("pbm-token", dataResponse.data.token, {
661
+ expires: parseInt(dataResponse.data.expiresIn, 10) / (60 * 60),
662
+ secure: true,
663
+ sameSite: "Strict"
664
+ });
665
+ Cookies.set("pbm-token-refresh", dataResponse.data.refreshToken, {
666
+ secure: true,
667
+ sameSite: "Strict"
668
+ });
669
+ return dataResponse;
670
+ };
671
+
672
+ // src/PBM.tsx
673
+ import { ArrowRight as ArrowRight2 } from "lucide-react";
674
+
675
+ // src/services/get-product-by-ean.ts
676
+ import Cookies2 from "js-cookie";
677
+ var GetProductByEAN = async ({ PRODUCT_EAN }) => {
678
+ const API_URL = import.meta.env.VITE_API_URL;
679
+ const AUTH_TOKEN = Cookies2.get("pbm-token");
680
+ if (!AUTH_TOKEN) {
681
+ throw new Error("Token is not defined in cookies or is expired");
682
+ }
683
+ const response = await fetch(`${API_URL}/core/products?ean=${PRODUCT_EAN}`, {
684
+ method: "GET",
685
+ headers: {
686
+ Authorization: `Bearer ${AUTH_TOKEN}`,
687
+ "Content-Type": "application/json"
688
+ }
689
+ });
690
+ const dataResponse = await response.json();
691
+ if (!dataResponse.success) {
692
+ throw new Error(dataResponse.message || "Failed to fetch authorization");
693
+ }
694
+ return dataResponse;
695
+ };
696
+
697
+ // src/libs/zustand/useTargetProduct.tsx
698
+ import { create as create2 } from "zustand";
699
+ var initialTargetProductState = {
700
+ targetProductInternal: null
701
+ };
702
+ var createPBMStore2 = (set) => ({
703
+ ...initialTargetProductState,
704
+ setTargetProductInternal: (targetProductInternal) => set({ targetProductInternal })
705
+ });
706
+ var useTargetProducts = create2(createPBMStore2);
707
+
708
+ // src/PBM.tsx
709
+ import { Fragment, jsx as jsx15, jsxs as jsxs10 } from "react/jsx-runtime";
710
+ function PBM({
711
+ originalProductPrice,
712
+ industryLogo,
713
+ clientID,
714
+ eanProduct
715
+ }) {
716
+ const [loading, setLoading] = useState3(false);
717
+ const { setState, state, setTargetProduct } = usePBMStore();
718
+ const { setTargetProductInternal } = useTargetProducts();
719
+ const handleGetProductByEAN = useCallback2(async () => {
720
+ try {
721
+ const response = await GetProductByEAN({ PRODUCT_EAN: eanProduct });
722
+ if (response.success) {
723
+ const productByEan = response.data.message.products[0];
724
+ setTargetProduct(productByEan);
725
+ setTargetProductInternal(productByEan);
726
+ }
727
+ } catch (error) {
728
+ console.error(error);
729
+ }
730
+ }, [eanProduct, setTargetProduct, setTargetProductInternal]);
731
+ const handleAuthorizationRequest = useCallback2(async () => {
732
+ try {
733
+ const response = await GetAuthorization({ clientID });
734
+ if (response.success && eanProduct) {
735
+ handleGetProductByEAN();
736
+ } else {
737
+ console.error("Authorization failed:", response.message);
738
+ }
739
+ } catch (error) {
740
+ console.error("Error fetching authorization:", error);
741
+ }
742
+ }, [clientID, handleGetProductByEAN, eanProduct]);
743
+ useEffect2(() => {
744
+ handleAuthorizationRequest();
745
+ }, [handleAuthorizationRequest]);
746
+ return /* @__PURE__ */ jsxs10(Container_default, { variant: "main", children: [
747
+ /* @__PURE__ */ jsx15(Header_default, { originalProductPrice: originalProductPrice || 0 }),
748
+ /* @__PURE__ */ jsxs10(Container_default, { variant: "simple", children: [
749
+ state === "isEmpty" && !loading && /* @__PURE__ */ jsxs10(Fragment, { children: [
750
+ /* @__PURE__ */ jsx15(Form_default, { setLoading }),
751
+ /* @__PURE__ */ jsxs10(
752
+ Button_default,
753
+ {
754
+ className: "bg-transparent p-0 pl-2 w-auto h-auto text-zinc-600 underline cursor-pointer hover:text-zinc-900 hover:bg-transparent flex items-center justify-start gap-1",
755
+ onClick: () => setState("isActivated"),
756
+ children: [
757
+ /* @__PURE__ */ jsx15("span", { children: "Consultar benef\xEDcios" }),
758
+ /* @__PURE__ */ jsx15(ArrowRight2, { size: 16 })
759
+ ]
760
+ }
761
+ )
762
+ ] }),
763
+ state === "isEmpty" && loading && /* @__PURE__ */ jsx15(Loading_default, {}),
764
+ state === "isInvalid" && !loading && /* @__PURE__ */ jsx15(SecurityNumberInvalid_default, {}),
765
+ state === "isRegistered" && !loading && /* @__PURE__ */ jsx15(SecurityNumberRegitered_default, {}),
766
+ state === "isActivated" && !loading && /* @__PURE__ */ jsx15(BenefitsTable_default, { originalProductPrice })
767
+ ] }),
768
+ /* @__PURE__ */ jsx15(Footer_default, { industryLogo })
769
+ ] });
770
+ }
771
+ var PBM_default = PBM;
772
+ export {
773
+ PBM_default as PBM,
774
+ usePBMStore
775
+ };
776
+ //# sourceMappingURL=index.mjs.map