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