@cnc-ti/layout-basic 8.6.0 → 8.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -31,6 +31,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
31
31
  // src/index.ts
32
32
  var src_exports = {};
33
33
  __export(src_exports, {
34
+ AlertaItem: () => AlertaItem,
35
+ Alertas: () => Alertas,
34
36
  AplicationsHeader: () => AplicationsHeader,
35
37
  AppsMenu: () => AppsMenu,
36
38
  Avatar: () => Avatar,
@@ -98,10 +100,12 @@ __export(src_exports, {
98
100
  DropdownMenuSubTrigger: () => DropdownMenuSubTrigger,
99
101
  DropdownMenuTrigger: () => DropdownMenuTrigger,
100
102
  EmptyState: () => EmptyState,
103
+ ErroAlertas: () => ErroAlertas,
101
104
  ErroNotificacoes: () => ErroNotificacoes,
102
105
  FileList: () => FileList,
103
106
  FileUpload: () => FileUpload,
104
107
  Filter: () => Filter,
108
+ FormularioAlerta: () => FormularioAlerta,
105
109
  Header: () => Header,
106
110
  HeaderContainer: () => HeaderContainer,
107
111
  HeaderNotifications: () => HeaderNotifications,
@@ -154,14 +158,17 @@ __export(src_exports, {
154
158
  URL_PADRAO_NOTIFICACOES: () => URL_PADRAO_NOTIFICACOES,
155
159
  availableApps: () => availableApps,
156
160
  buildMonthDays: () => buildMonthDays,
161
+ buscarAlertas: () => buscarAlertas,
157
162
  buttonVariants: () => buttonVariants,
158
163
  formatDayAriaLabel: () => formatDayAriaLabel,
159
164
  formatFileSize: () => formatFileSize,
160
165
  formatMonthYear: () => formatMonthYear,
161
166
  isSameDay: () => isSameDay,
162
167
  isToday: () => isToday,
168
+ normalizarBaseUrl: () => normalizarBaseUrl,
163
169
  toDateKey: () => toDateKey,
164
170
  toLocalNoon: () => toLocalNoon,
171
+ usarAlertas: () => usarAlertas,
165
172
  useDrawer: () => useDrawer,
166
173
  validateFiles: () => validateFiles
167
174
  });
@@ -320,6 +327,20 @@ var Bell = createLucideIcon("Bell", [
320
327
  ["path", { d: "M10.3 21a1.94 1.94 0 0 0 3.4 0", key: "qgo35s" }]
321
328
  ]);
322
329
 
330
+ // ../../node_modules/lucide-react/dist/esm/icons/calendar-days.js
331
+ var CalendarDays = createLucideIcon("CalendarDays", [
332
+ ["path", { d: "M8 2v4", key: "1cmpym" }],
333
+ ["path", { d: "M16 2v4", key: "4m81vk" }],
334
+ ["rect", { width: "18", height: "18", x: "3", y: "4", rx: "2", key: "1hopcy" }],
335
+ ["path", { d: "M3 10h18", key: "8toen8" }],
336
+ ["path", { d: "M8 14h.01", key: "6423bh" }],
337
+ ["path", { d: "M12 14h.01", key: "1etili" }],
338
+ ["path", { d: "M16 14h.01", key: "1gbofw" }],
339
+ ["path", { d: "M8 18h.01", key: "lrp35t" }],
340
+ ["path", { d: "M12 18h.01", key: "mhygvu" }],
341
+ ["path", { d: "M16 18h.01", key: "kzsmim" }]
342
+ ]);
343
+
323
344
  // ../../node_modules/lucide-react/dist/esm/icons/check.js
324
345
  var Check = createLucideIcon("Check", [["path", { d: "M20 6 9 17l-5-5", key: "1gmf2c" }]]);
325
346
 
@@ -434,6 +455,18 @@ var Paperclip = createLucideIcon("Paperclip", [
434
455
  ]
435
456
  ]);
436
457
 
458
+ // ../../node_modules/lucide-react/dist/esm/icons/pencil.js
459
+ var Pencil = createLucideIcon("Pencil", [
460
+ [
461
+ "path",
462
+ {
463
+ d: "M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",
464
+ key: "1a8usu"
465
+ }
466
+ ],
467
+ ["path", { d: "m15 5 4 4", key: "1mk7zo" }]
468
+ ]);
469
+
437
470
  // ../../node_modules/lucide-react/dist/esm/icons/plus.js
438
471
  var Plus = createLucideIcon("Plus", [
439
472
  ["path", { d: "M5 12h14", key: "1ays0h" }],
@@ -6940,8 +6973,757 @@ function HeaderNotifications(props) {
6940
6973
  ] })
6941
6974
  ] });
6942
6975
  }
6976
+
6977
+ // src/alertas/alertas.tsx
6978
+ var React32 = __toESM(require("react"));
6979
+
6980
+ // src/alertas/formulario-alerta.tsx
6981
+ var React30 = __toESM(require("react"));
6982
+
6983
+ // src/alertas/date-utils.ts
6984
+ function obterHojeDataHoraIsoLocal() {
6985
+ const hoje = /* @__PURE__ */ new Date();
6986
+ const ano = hoje.getFullYear();
6987
+ const mes = String(hoje.getMonth() + 1).padStart(2, "0");
6988
+ const dia = String(hoje.getDate()).padStart(2, "0");
6989
+ const horas = String(hoje.getHours()).padStart(2, "0");
6990
+ const minutos = String(hoje.getMinutes()).padStart(2, "0");
6991
+ return `${ano}-${mes}-${dia}T${horas}:${minutos}`;
6992
+ }
6993
+ function datetimeLocalParaIsoComOffset(valorInput) {
6994
+ if (!valorInput) return valorInput;
6995
+ const data = new Date(valorInput);
6996
+ if (isNaN(data.getTime())) return valorInput;
6997
+ const offsetMinutos = data.getTimezoneOffset();
6998
+ const sinal = offsetMinutos <= 0 ? "+" : "-";
6999
+ const absOffset = Math.abs(offsetMinutos);
7000
+ const offsetHoras = String(Math.floor(absOffset / 60)).padStart(2, "0");
7001
+ const offsetMins = String(absOffset % 60).padStart(2, "0");
7002
+ const ano = data.getFullYear();
7003
+ const mes = String(data.getMonth() + 1).padStart(2, "0");
7004
+ const dia = String(data.getDate()).padStart(2, "0");
7005
+ const horas = String(data.getHours()).padStart(2, "0");
7006
+ const minutos = String(data.getMinutes()).padStart(2, "0");
7007
+ return `${ano}-${mes}-${dia}T${horas}:${minutos}:00${sinal}${offsetHoras}:${offsetMins}`;
7008
+ }
7009
+ function formatarDataParaExibicao(iso) {
7010
+ if (!iso) return "";
7011
+ const dataObj = new Date(iso);
7012
+ if (isNaN(dataObj.getTime())) return "";
7013
+ const dia = String(dataObj.getDate()).padStart(2, "0");
7014
+ const mes = String(dataObj.getMonth() + 1).padStart(2, "0");
7015
+ const ano = dataObj.getFullYear();
7016
+ const horas = String(dataObj.getHours()).padStart(2, "0");
7017
+ const minutos = String(dataObj.getMinutes()).padStart(2, "0");
7018
+ return `${dia}/${mes}/${ano} \xE0s ${horas}:${minutos}`;
7019
+ }
7020
+
7021
+ // src/alertas/formulario-alerta.tsx
7022
+ var import_jsx_runtime43 = require("react/jsx-runtime");
7023
+ var FORM_VAZIO = {
7024
+ titulo: "",
7025
+ dataReferencia: "",
7026
+ lembrarNoDia: true,
7027
+ diasAntes: "",
7028
+ alertasDiasAntes: [],
7029
+ novoAlertaDiasAntes: "",
7030
+ mensagem: "",
7031
+ enviarEmail: false
7032
+ };
7033
+ function normalizarAlertasDiasAntes(values) {
7034
+ const alertas = [...values.alertasDiasAntes];
7035
+ if (values.novoAlertaDiasAntes.trim()) {
7036
+ alertas.push(values.novoAlertaDiasAntes.trim());
7037
+ }
7038
+ return Array.from(new Set(alertas.map(Number))).sort((a, b) => a - b);
7039
+ }
7040
+ function construirPayload(values) {
7041
+ const alertasNumericos = normalizarAlertasDiasAntes(values);
7042
+ const diasAntes = alertasNumericos.length ? Math.max(...alertasNumericos) : values.diasAntes.trim() ? Number(values.diasAntes) : 0;
7043
+ return {
7044
+ titulo: values.titulo.trim(),
7045
+ dataReferencia: datetimeLocalParaIsoComOffset(values.dataReferencia),
7046
+ lembrarNoDia: values.lembrarNoDia,
7047
+ diasAntes,
7048
+ alertasDiasAntes: alertasNumericos,
7049
+ mensagem: values.mensagem.trim() || void 0,
7050
+ enviarEmail: values.enviarEmail
7051
+ };
7052
+ }
7053
+ function preencherFormDoAlerta(alerta) {
7054
+ const alertasDiasAntes = alerta.alertasDiasAntes && alerta.alertasDiasAntes.length > 0 ? alerta.alertasDiasAntes.map(String) : alerta.diasAntes > 0 ? [String(alerta.diasAntes)] : [];
7055
+ const dataObj = new Date(alerta.dataReferencia);
7056
+ const formatada = isNaN(dataObj.getTime()) ? "" : (() => {
7057
+ const ano = dataObj.getFullYear();
7058
+ const mes = String(dataObj.getMonth() + 1).padStart(2, "0");
7059
+ const dia = String(dataObj.getDate()).padStart(2, "0");
7060
+ const horas = String(dataObj.getHours()).padStart(2, "0");
7061
+ const minutos = String(dataObj.getMinutes()).padStart(2, "0");
7062
+ return `${ano}-${mes}-${dia}T${horas}:${minutos}`;
7063
+ })();
7064
+ return {
7065
+ titulo: alerta.titulo,
7066
+ dataReferencia: formatada,
7067
+ lembrarNoDia: alerta.lembrarNoDia ?? alerta.diasAntes === 0,
7068
+ diasAntes: alerta.diasAntes ? String(alerta.diasAntes) : "",
7069
+ alertasDiasAntes,
7070
+ novoAlertaDiasAntes: "",
7071
+ mensagem: alerta.mensagem ?? "",
7072
+ enviarEmail: alerta.enviarEmail ?? false
7073
+ };
7074
+ }
7075
+ function validarForm(values) {
7076
+ if (!values.titulo.trim()) return "Informe o titulo do alerta";
7077
+ if (!values.dataReferencia) return "Informe a data do alerta";
7078
+ if (new Date(values.dataReferencia) < /* @__PURE__ */ new Date()) {
7079
+ return "Informe uma data e hora igual ou posterior ao momento atual";
7080
+ }
7081
+ if (values.diasAntes.trim() && values.diasAntes !== "0") {
7082
+ const diasAntes = Number(values.diasAntes);
7083
+ if (!Number.isInteger(diasAntes) || diasAntes < 0) {
7084
+ return "Informe uma quantidade de dias maior ou igual a zero";
7085
+ }
7086
+ }
7087
+ if (values.novoAlertaDiasAntes.trim()) {
7088
+ const novoAlerta = Number(values.novoAlertaDiasAntes);
7089
+ if (!Number.isInteger(novoAlerta) || novoAlerta <= 0) {
7090
+ return "Informe uma quantidade de dias maior que zero";
7091
+ }
7092
+ }
7093
+ return "";
7094
+ }
7095
+ function OpcaoAlerta({ checked, label, onChange }) {
7096
+ return /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)("label", { className: "alerta-opcao", children: [
7097
+ /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
7098
+ "input",
7099
+ {
7100
+ type: "checkbox",
7101
+ checked,
7102
+ onChange: (e) => onChange(e.target.checked),
7103
+ className: "alerta-checkbox"
7104
+ }
7105
+ ),
7106
+ label
7107
+ ] });
7108
+ }
7109
+ function FormularioAlerta({
7110
+ alertaEmEdicao,
7111
+ isSaving = false,
7112
+ onSalvar,
7113
+ onCancelar
7114
+ }) {
7115
+ const [values, setValues] = React30.useState(
7116
+ () => alertaEmEdicao ? preencherFormDoAlerta(alertaEmEdicao) : FORM_VAZIO
7117
+ );
7118
+ const [erro, setErro] = React30.useState("");
7119
+ const [hojeDataHoraIso, setHojeDataHoraIso] = React30.useState("");
7120
+ React30.useEffect(() => {
7121
+ setHojeDataHoraIso(obterHojeDataHoraIsoLocal());
7122
+ }, []);
7123
+ React30.useEffect(() => {
7124
+ setValues(alertaEmEdicao ? preencherFormDoAlerta(alertaEmEdicao) : FORM_VAZIO);
7125
+ setErro("");
7126
+ }, [alertaEmEdicao]);
7127
+ const setField = (campo, valor) => {
7128
+ setErro("");
7129
+ setValues((prev) => ({ ...prev, [campo]: valor }));
7130
+ };
7131
+ const toggleLembrarNoDia = (checked) => {
7132
+ setErro("");
7133
+ setValues((prev) => ({ ...prev, lembrarNoDia: checked }));
7134
+ };
7135
+ const toggleAlertaDiasAntes = (dias, checked) => {
7136
+ setErro("");
7137
+ setValues((prev) => {
7138
+ const valor = String(dias);
7139
+ const alertas = new Set(prev.alertasDiasAntes);
7140
+ if (checked) alertas.add(valor);
7141
+ else alertas.delete(valor);
7142
+ const alertasDiasAntes = Array.from(alertas).sort(
7143
+ (a, b) => Number(a) - Number(b)
7144
+ );
7145
+ return {
7146
+ ...prev,
7147
+ alertasDiasAntes,
7148
+ diasAntes: alertasDiasAntes.length > 0 ? String(Math.max(...alertasDiasAntes.map(Number))) : ""
7149
+ };
7150
+ });
7151
+ };
7152
+ const adicionarAlertaDiasAntes = () => {
7153
+ const valor = values.novoAlertaDiasAntes.trim();
7154
+ const dias = Number(valor);
7155
+ if (!Number.isInteger(dias) || dias <= 0) {
7156
+ setErro("Informe uma quantidade de dias maior que zero");
7157
+ return;
7158
+ }
7159
+ setErro("");
7160
+ setValues((prev) => {
7161
+ const alertas = new Set(prev.alertasDiasAntes);
7162
+ alertas.add(String(dias));
7163
+ const alertasDiasAntes = Array.from(alertas).sort(
7164
+ (a, b) => Number(a) - Number(b)
7165
+ );
7166
+ return {
7167
+ ...prev,
7168
+ diasAntes: String(Math.max(...alertasDiasAntes.map(Number))),
7169
+ novoAlertaDiasAntes: "",
7170
+ alertasDiasAntes
7171
+ };
7172
+ });
7173
+ };
7174
+ const removerAlertaDiasAntes = (valor) => {
7175
+ setValues((prev) => {
7176
+ const alertasDiasAntes = prev.alertasDiasAntes.filter((item) => item !== valor);
7177
+ return {
7178
+ ...prev,
7179
+ alertasDiasAntes,
7180
+ diasAntes: alertasDiasAntes.length > 0 ? String(Math.max(...alertasDiasAntes.map(Number))) : ""
7181
+ };
7182
+ });
7183
+ };
7184
+ const handleSalvar = () => {
7185
+ const mensagemErro = validarForm(values);
7186
+ if (mensagemErro) {
7187
+ setErro(mensagemErro);
7188
+ return;
7189
+ }
7190
+ onSalvar(construirPayload(values));
7191
+ };
7192
+ const alertasPersonalizados = values.alertasDiasAntes.filter(
7193
+ (d) => !["2", "7", "15", "30"].includes(d)
7194
+ );
7195
+ return /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)("section", { className: "alerta-form-section", children: [
7196
+ /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("div", { className: "alerta-form-header", children: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("h2", { className: "alerta-form-titulo", children: alertaEmEdicao ? "Editar alerta" : "Novo alerta" }) }),
7197
+ /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)("div", { className: "alerta-form-grid", children: [
7198
+ /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)("div", { className: "alerta-campo", children: [
7199
+ /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)("label", { htmlFor: "alerta-titulo", className: "alerta-label", children: [
7200
+ "Titulo ",
7201
+ /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("span", { className: "alerta-obrigatorio", children: "*" })
7202
+ ] }),
7203
+ /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
7204
+ "input",
7205
+ {
7206
+ id: "alerta-titulo",
7207
+ type: "text",
7208
+ value: values.titulo,
7209
+ onChange: (e) => setField("titulo", e.target.value),
7210
+ placeholder: "Informe o titulo do alerta",
7211
+ className: "alerta-input"
7212
+ }
7213
+ )
7214
+ ] }),
7215
+ /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)("div", { className: "alerta-campo alerta-campo--data", children: [
7216
+ /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)("label", { htmlFor: "alerta-data", className: "alerta-label", children: [
7217
+ "Data e Hora ",
7218
+ /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("span", { className: "alerta-obrigatorio", children: "*" })
7219
+ ] }),
7220
+ /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
7221
+ "input",
7222
+ {
7223
+ id: "alerta-data",
7224
+ type: "datetime-local",
7225
+ min: hojeDataHoraIso,
7226
+ value: values.dataReferencia,
7227
+ onChange: (e) => setField("dataReferencia", e.target.value),
7228
+ className: "alerta-input alerta-input--sm"
7229
+ }
7230
+ )
7231
+ ] }),
7232
+ /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)("div", { className: "alerta-campo", children: [
7233
+ /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("span", { className: "alerta-label", children: "Notifica\xE7\xF5es" }),
7234
+ /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)("div", { className: "alerta-notif-container", children: [
7235
+ /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)("div", { className: "alerta-notif-col", children: [
7236
+ /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
7237
+ OpcaoAlerta,
7238
+ {
7239
+ checked: values.lembrarNoDia,
7240
+ label: "Alertar no dia",
7241
+ onChange: toggleLembrarNoDia
7242
+ }
7243
+ ),
7244
+ /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
7245
+ OpcaoAlerta,
7246
+ {
7247
+ checked: values.alertasDiasAntes.includes("2"),
7248
+ label: "2 dias antes",
7249
+ onChange: (c) => toggleAlertaDiasAntes(2, c)
7250
+ }
7251
+ ),
7252
+ /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
7253
+ OpcaoAlerta,
7254
+ {
7255
+ checked: values.alertasDiasAntes.includes("7"),
7256
+ label: "1 semana antes",
7257
+ onChange: (c) => toggleAlertaDiasAntes(7, c)
7258
+ }
7259
+ )
7260
+ ] }),
7261
+ /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)("div", { className: "alerta-notif-col", children: [
7262
+ /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
7263
+ OpcaoAlerta,
7264
+ {
7265
+ checked: values.alertasDiasAntes.includes("15"),
7266
+ label: "15 dias antes",
7267
+ onChange: (c) => toggleAlertaDiasAntes(15, c)
7268
+ }
7269
+ ),
7270
+ /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
7271
+ OpcaoAlerta,
7272
+ {
7273
+ checked: values.alertasDiasAntes.includes("30"),
7274
+ label: "1 m\xEAs antes",
7275
+ onChange: (c) => toggleAlertaDiasAntes(30, c)
7276
+ }
7277
+ ),
7278
+ /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)("div", { className: "alerta-notif-personalizado", children: [
7279
+ /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
7280
+ "input",
7281
+ {
7282
+ id: "alerta-dias",
7283
+ type: "number",
7284
+ min: 1,
7285
+ step: 1,
7286
+ value: values.novoAlertaDiasAntes,
7287
+ onChange: (e) => setField("novoAlertaDiasAntes", e.target.value),
7288
+ onKeyDown: (e) => {
7289
+ if (e.key === "Enter") {
7290
+ e.preventDefault();
7291
+ adicionarAlertaDiasAntes();
7292
+ }
7293
+ },
7294
+ placeholder: "Dias",
7295
+ className: "alerta-input alerta-input--dias"
7296
+ }
7297
+ ),
7298
+ /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(
7299
+ "button",
7300
+ {
7301
+ type: "button",
7302
+ onClick: adicionarAlertaDiasAntes,
7303
+ className: "alerta-btn alerta-btn--outline",
7304
+ children: [
7305
+ /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(Plus, { size: 16 }),
7306
+ "Adicionar"
7307
+ ]
7308
+ }
7309
+ )
7310
+ ] })
7311
+ ] }),
7312
+ alertasPersonalizados.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("div", { className: "alerta-tags", children: alertasPersonalizados.map((dias) => /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)("span", { className: "alerta-tag", children: [
7313
+ dias,
7314
+ " dia",
7315
+ Number(dias) > 1 ? "s" : "",
7316
+ " antes",
7317
+ /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
7318
+ "button",
7319
+ {
7320
+ type: "button",
7321
+ onClick: () => removerAlertaDiasAntes(dias),
7322
+ "aria-label": `Remover alerta de ${dias} dias antes`,
7323
+ className: "alerta-tag-remover",
7324
+ children: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(X, { size: 14 })
7325
+ }
7326
+ )
7327
+ ] }, dias)) })
7328
+ ] })
7329
+ ] }),
7330
+ /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)("div", { className: "alerta-campo", children: [
7331
+ /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("label", { htmlFor: "alerta-mensagem", className: "alerta-label", children: "Mensagem" }),
7332
+ /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
7333
+ "textarea",
7334
+ {
7335
+ id: "alerta-mensagem",
7336
+ value: values.mensagem,
7337
+ onChange: (e) => setField("mensagem", e.target.value),
7338
+ placeholder: "Informe a mensagem do alerta",
7339
+ rows: 3,
7340
+ className: "alerta-textarea"
7341
+ }
7342
+ )
7343
+ ] }),
7344
+ /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("div", { className: "alerta-campo", children: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
7345
+ OpcaoAlerta,
7346
+ {
7347
+ checked: values.enviarEmail,
7348
+ label: "Enviar tamb\xE9m por e-mail",
7349
+ onChange: (checked) => setField("enviarEmail", checked)
7350
+ }
7351
+ ) }),
7352
+ erro && /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("div", { className: "alerta-erro", children: erro }),
7353
+ /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)("div", { className: "alerta-form-acoes", children: [
7354
+ /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
7355
+ "button",
7356
+ {
7357
+ type: "button",
7358
+ onClick: onCancelar,
7359
+ className: "alerta-btn alerta-btn--secundario",
7360
+ children: "Cancelar"
7361
+ }
7362
+ ),
7363
+ /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)(
7364
+ "button",
7365
+ {
7366
+ type: "button",
7367
+ onClick: handleSalvar,
7368
+ disabled: isSaving,
7369
+ className: "alerta-btn alerta-btn--primario",
7370
+ children: [
7371
+ /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(Plus, { size: 16 }),
7372
+ isSaving ? "Salvando..." : alertaEmEdicao ? "Atualizar alerta" : "Adicionar alerta"
7373
+ ]
7374
+ }
7375
+ )
7376
+ ] })
7377
+ ] })
7378
+ ] });
7379
+ }
7380
+
7381
+ // src/alertas/alerta-item.tsx
7382
+ var import_jsx_runtime44 = require("react/jsx-runtime");
7383
+ function AlertaItem({
7384
+ alerta,
7385
+ disabled = false,
7386
+ selecionado = false,
7387
+ onEditar,
7388
+ onConcluir,
7389
+ onExcluir
7390
+ }) {
7391
+ const concluido = alerta.status === "CONCLUIDO";
7392
+ const cancelado = alerta.status === "CANCELADO";
7393
+ const podeAlterar = !concluido && !cancelado;
7394
+ const statusLabel = concluido ? "Concluido" : cancelado ? "Cancelado" : "Pendente";
7395
+ const descricaoAlertas = [
7396
+ alerta.lembrarNoDia ?? alerta.diasAntes === 0 ? "no dia" : null,
7397
+ ...alerta.alertasDiasAntes && alerta.alertasDiasAntes.length > 0 ? alerta.alertasDiasAntes.map(
7398
+ (dias) => `${dias} dia${dias > 1 ? "s" : ""} antes`
7399
+ ) : alerta.diasAntes > 0 ? [`${alerta.diasAntes} dia${alerta.diasAntes > 1 ? "s" : ""} antes`] : []
7400
+ ].filter(Boolean).join(", ");
7401
+ return /* @__PURE__ */ (0, import_jsx_runtime44.jsx)(
7402
+ "article",
7403
+ {
7404
+ className: [
7405
+ "alerta-item",
7406
+ selecionado ? "alerta-item--selecionado" : "",
7407
+ concluido ? "alerta-item--concluido" : "",
7408
+ cancelado ? "alerta-item--cancelado" : ""
7409
+ ].filter(Boolean).join(" "),
7410
+ children: /* @__PURE__ */ (0, import_jsx_runtime44.jsxs)("div", { className: "alerta-item-corpo", children: [
7411
+ /* @__PURE__ */ (0, import_jsx_runtime44.jsxs)("div", { className: "alerta-item-info", children: [
7412
+ /* @__PURE__ */ (0, import_jsx_runtime44.jsxs)("div", { className: "alerta-item-topo", children: [
7413
+ /* @__PURE__ */ (0, import_jsx_runtime44.jsx)("h3", { className: "alerta-item-titulo", children: alerta.titulo }),
7414
+ /* @__PURE__ */ (0, import_jsx_runtime44.jsx)("span", { className: `alerta-status alerta-status--${statusLabel.toLowerCase()}`, children: statusLabel })
7415
+ ] }),
7416
+ alerta.mensagem && /* @__PURE__ */ (0, import_jsx_runtime44.jsx)("p", { className: "alerta-item-mensagem", children: alerta.mensagem }),
7417
+ /* @__PURE__ */ (0, import_jsx_runtime44.jsxs)("div", { className: "alerta-item-meta", children: [
7418
+ /* @__PURE__ */ (0, import_jsx_runtime44.jsxs)("span", { className: "alerta-item-meta-linha", children: [
7419
+ /* @__PURE__ */ (0, import_jsx_runtime44.jsx)(CalendarDays, { size: 14 }),
7420
+ "Data ",
7421
+ formatarDataParaExibicao(alerta.dataReferencia)
7422
+ ] }),
7423
+ /* @__PURE__ */ (0, import_jsx_runtime44.jsxs)("span", { className: "alerta-item-meta-linha", children: [
7424
+ /* @__PURE__ */ (0, import_jsx_runtime44.jsx)(Bell, { size: 14 }),
7425
+ "Notifica\xE7\xF5es: ",
7426
+ descricaoAlertas || "\u2014"
7427
+ ] }),
7428
+ alerta.enviarEmail && /* @__PURE__ */ (0, import_jsx_runtime44.jsxs)("span", { className: "alerta-item-meta-linha alerta-item-email-ativo", children: [
7429
+ /* @__PURE__ */ (0, import_jsx_runtime44.jsx)("span", { className: "alerta-dot" }),
7430
+ "Notifica\xE7\xE3o por e-mail ativa"
7431
+ ] }),
7432
+ cancelado && alerta.motivoCancelamento && /* @__PURE__ */ (0, import_jsx_runtime44.jsxs)("span", { className: "alerta-item-meta-linha", children: [
7433
+ /* @__PURE__ */ (0, import_jsx_runtime44.jsx)(X, { size: 14 }),
7434
+ "Cancelado automaticamente: ",
7435
+ alerta.motivoCancelamento
7436
+ ] })
7437
+ ] })
7438
+ ] }),
7439
+ /* @__PURE__ */ (0, import_jsx_runtime44.jsxs)("div", { className: "alerta-item-acoes", children: [
7440
+ /* @__PURE__ */ (0, import_jsx_runtime44.jsx)(
7441
+ "button",
7442
+ {
7443
+ type: "button",
7444
+ onClick: onEditar,
7445
+ disabled: disabled || !podeAlterar,
7446
+ title: "Editar alerta",
7447
+ className: "alerta-btn-icone",
7448
+ children: /* @__PURE__ */ (0, import_jsx_runtime44.jsx)(Pencil, { size: 16 })
7449
+ }
7450
+ ),
7451
+ podeAlterar && /* @__PURE__ */ (0, import_jsx_runtime44.jsx)(
7452
+ "button",
7453
+ {
7454
+ type: "button",
7455
+ onClick: onConcluir,
7456
+ disabled,
7457
+ title: "Concluir alerta",
7458
+ className: "alerta-btn-icone alerta-btn-icone--sucesso",
7459
+ children: /* @__PURE__ */ (0, import_jsx_runtime44.jsx)(Check, { size: 16 })
7460
+ }
7461
+ ),
7462
+ /* @__PURE__ */ (0, import_jsx_runtime44.jsx)(
7463
+ "button",
7464
+ {
7465
+ type: "button",
7466
+ onClick: onExcluir,
7467
+ disabled,
7468
+ title: "Excluir alerta",
7469
+ className: "alerta-btn-icone alerta-btn-icone--perigo",
7470
+ children: /* @__PURE__ */ (0, import_jsx_runtime44.jsx)(Trash2, { size: 16 })
7471
+ }
7472
+ )
7473
+ ] })
7474
+ ] })
7475
+ }
7476
+ );
7477
+ }
7478
+
7479
+ // src/alertas/usar-alertas.ts
7480
+ var React31 = __toESM(require("react"));
7481
+
7482
+ // src/alertas/cliente.ts
7483
+ var ErroAlertas = class _ErroAlertas extends Error {
7484
+ status;
7485
+ constructor(mensagem, status) {
7486
+ super(mensagem);
7487
+ this.name = "ErroAlertas";
7488
+ this.status = status;
7489
+ Object.setPrototypeOf(this, _ErroAlertas.prototype);
7490
+ }
7491
+ };
7492
+ async function buscarAlertas({
7493
+ baseUrl,
7494
+ sistema,
7495
+ email,
7496
+ fetchFn = fetch,
7497
+ signal,
7498
+ eventoId
7499
+ }) {
7500
+ const params = new URLSearchParams({ sistema, email });
7501
+ if (eventoId !== void 0) params.set("eventoId", String(eventoId));
7502
+ const url = `${normalizarBaseUrl(baseUrl)}/notificacoes?${params.toString()}`;
7503
+ const resposta = await fetchFn(url, {
7504
+ method: "GET",
7505
+ headers: { Accept: "application/json" },
7506
+ signal
7507
+ });
7508
+ if (!resposta.ok) {
7509
+ throw new ErroAlertas(`Falha ao buscar alertas`, resposta.status);
7510
+ }
7511
+ return await resposta.json();
7512
+ }
7513
+
7514
+ // src/alertas/usar-alertas.ts
7515
+ function foiAbortado2(erro) {
7516
+ return erro?.name === "AbortError";
7517
+ }
7518
+ function usarAlertas({
7519
+ baseUrl,
7520
+ sistema,
7521
+ email,
7522
+ fetchFn,
7523
+ eventoId,
7524
+ habilitado = true,
7525
+ onErro
7526
+ }) {
7527
+ const [alertas, setAlertas] = React31.useState([]);
7528
+ const [carregando, setCarregando] = React31.useState(habilitado);
7529
+ const controladorRef = React31.useRef(null);
7530
+ const jaCarregouRef = React31.useRef(false);
7531
+ const onErroRef = React31.useRef(onErro);
7532
+ const fetchFnRef = React31.useRef(fetchFn);
7533
+ React31.useEffect(() => {
7534
+ onErroRef.current = onErro;
7535
+ }, [onErro]);
7536
+ React31.useEffect(() => {
7537
+ fetchFnRef.current = fetchFn;
7538
+ }, [fetchFn]);
7539
+ const pronto = baseUrl !== void 0 && sistema !== void 0 && email !== void 0;
7540
+ const atualizar = React31.useCallback(() => {
7541
+ if (!habilitado || !pronto) return;
7542
+ controladorRef.current?.abort();
7543
+ const controlador = new AbortController();
7544
+ controladorRef.current = controlador;
7545
+ void (async () => {
7546
+ try {
7547
+ const lista = await buscarAlertas({
7548
+ baseUrl,
7549
+ sistema,
7550
+ email,
7551
+ fetchFn: fetchFnRef.current,
7552
+ eventoId,
7553
+ signal: controlador.signal
7554
+ });
7555
+ if (controlador.signal.aborted) return;
7556
+ setAlertas(lista);
7557
+ } catch (erro) {
7558
+ if (controlador.signal.aborted || foiAbortado2(erro)) return;
7559
+ onErroRef.current?.(erro);
7560
+ } finally {
7561
+ if (!controlador.signal.aborted) {
7562
+ jaCarregouRef.current = true;
7563
+ setCarregando(false);
7564
+ }
7565
+ }
7566
+ })();
7567
+ }, [baseUrl, sistema, email, eventoId, habilitado, pronto]);
7568
+ React31.useEffect(() => {
7569
+ if (!habilitado || !pronto) {
7570
+ setCarregando(false);
7571
+ return;
7572
+ }
7573
+ if (!jaCarregouRef.current) setCarregando(true);
7574
+ atualizar();
7575
+ return () => controladorRef.current?.abort();
7576
+ }, [atualizar, habilitado, pronto]);
7577
+ return {
7578
+ alertas,
7579
+ carregando,
7580
+ atualizar
7581
+ };
7582
+ }
7583
+
7584
+ // src/alertas/alertas.tsx
7585
+ var import_jsx_runtime45 = require("react/jsx-runtime");
7586
+ function Alertas({
7587
+ alertas: alertasProps = [],
7588
+ isLoading = false,
7589
+ isSaving = false,
7590
+ isRemovendo = false,
7591
+ podeCriar = true,
7592
+ onCriar,
7593
+ onAtualizar,
7594
+ onConcluir,
7595
+ onExcluir,
7596
+ baseUrl = URL_PADRAO_NOTIFICACOES,
7597
+ sistema,
7598
+ email,
7599
+ fetchFn,
7600
+ eventoId,
7601
+ onErro
7602
+ }) {
7603
+ const [formAberto, setFormAberto] = React32.useState(false);
7604
+ const [alertaEmEdicao, setAlertaEmEdicao] = React32.useState(null);
7605
+ const [salvandoLocal, setSalvandoLocal] = React32.useState(false);
7606
+ const [removendoLocal, setRemovendoLocal] = React32.useState(false);
7607
+ const conectado = Boolean(sistema && email);
7608
+ const remoto = usarAlertas({
7609
+ baseUrl,
7610
+ sistema,
7611
+ email,
7612
+ fetchFn,
7613
+ eventoId,
7614
+ habilitado: conectado,
7615
+ onErro
7616
+ });
7617
+ const alertas = conectado ? remoto.alertas : alertasProps;
7618
+ const carregando = conectado ? remoto.carregando : isLoading;
7619
+ const salvando = salvandoLocal || isSaving;
7620
+ const removendo = removendoLocal || isRemovendo;
7621
+ const resetForm = () => {
7622
+ setFormAberto(false);
7623
+ setAlertaEmEdicao(null);
7624
+ };
7625
+ const abrirNovoAlerta = () => {
7626
+ setAlertaEmEdicao(null);
7627
+ setFormAberto(true);
7628
+ };
7629
+ const abrirEdicao = (alerta) => {
7630
+ setAlertaEmEdicao(alerta);
7631
+ setFormAberto(true);
7632
+ };
7633
+ const handleSalvar = async (payload) => {
7634
+ setSalvandoLocal(true);
7635
+ try {
7636
+ if (alertaEmEdicao) {
7637
+ await onAtualizar?.(alertaEmEdicao.id, payload);
7638
+ } else {
7639
+ await onCriar?.(payload);
7640
+ }
7641
+ if (conectado) remoto.atualizar();
7642
+ resetForm();
7643
+ } catch (err) {
7644
+ console.error("Erro ao salvar alerta:", err);
7645
+ onErro?.(err);
7646
+ } finally {
7647
+ setSalvandoLocal(false);
7648
+ }
7649
+ };
7650
+ const handleConcluir = async (alertaId) => {
7651
+ setRemovendoLocal(true);
7652
+ try {
7653
+ await onConcluir?.(alertaId);
7654
+ if (conectado) remoto.atualizar();
7655
+ } catch (err) {
7656
+ console.error("Erro ao concluir alerta:", err);
7657
+ onErro?.(err);
7658
+ } finally {
7659
+ setRemovendoLocal(false);
7660
+ }
7661
+ };
7662
+ const handleExcluir = (alerta) => {
7663
+ if (!window.confirm(`Tem certeza que deseja excluir o alerta "${alerta.titulo}"?`)) return;
7664
+ void (async () => {
7665
+ setRemovendoLocal(true);
7666
+ try {
7667
+ await onExcluir?.(alerta);
7668
+ if (conectado) remoto.atualizar();
7669
+ } catch (err) {
7670
+ console.error("Erro ao excluir alerta:", err);
7671
+ onErro?.(err);
7672
+ } finally {
7673
+ setRemovendoLocal(false);
7674
+ }
7675
+ })();
7676
+ };
7677
+ return /* @__PURE__ */ (0, import_jsx_runtime45.jsxs)("div", { className: "alertas-container", children: [
7678
+ !formAberto && podeCriar && /* @__PURE__ */ (0, import_jsx_runtime45.jsx)("div", { className: "alertas-nova-acao", children: /* @__PURE__ */ (0, import_jsx_runtime45.jsxs)(
7679
+ "button",
7680
+ {
7681
+ type: "button",
7682
+ onClick: abrirNovoAlerta,
7683
+ className: "alerta-btn alerta-btn--primario",
7684
+ children: [
7685
+ /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(Plus, { size: 16 }),
7686
+ "Novo alerta"
7687
+ ]
7688
+ }
7689
+ ) }),
7690
+ formAberto && /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(
7691
+ FormularioAlerta,
7692
+ {
7693
+ alertaEmEdicao,
7694
+ isSaving: salvando,
7695
+ onSalvar: handleSalvar,
7696
+ onCancelar: resetForm
7697
+ }
7698
+ ),
7699
+ /* @__PURE__ */ (0, import_jsx_runtime45.jsxs)("section", { className: "alertas-lista-section", children: [
7700
+ /* @__PURE__ */ (0, import_jsx_runtime45.jsx)("div", { className: "alertas-lista-header", children: /* @__PURE__ */ (0, import_jsx_runtime45.jsxs)("h2", { className: "alertas-lista-titulo", children: [
7701
+ "Alertas cadastrados (",
7702
+ alertas.length,
7703
+ ")"
7704
+ ] }) }),
7705
+ carregando ? /* @__PURE__ */ (0, import_jsx_runtime45.jsx)("div", { className: "alertas-estado", children: "Carregando alertas..." }) : alertas.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime45.jsxs)("div", { className: "alertas-vazio", children: [
7706
+ /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(Bell, { size: 32, className: "alertas-vazio-icone" }),
7707
+ /* @__PURE__ */ (0, import_jsx_runtime45.jsx)("p", { className: "alertas-vazio-texto", children: "Nenhum alerta cadastrado." })
7708
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime45.jsx)("div", { className: "alertas-lista", children: alertas.map((alerta) => /* @__PURE__ */ (0, import_jsx_runtime45.jsx)(
7709
+ AlertaItem,
7710
+ {
7711
+ alerta,
7712
+ disabled: removendo,
7713
+ selecionado: alertaEmEdicao?.id === alerta.id,
7714
+ onEditar: () => abrirEdicao(alerta),
7715
+ onConcluir: () => handleConcluir(alerta.id),
7716
+ onExcluir: () => handleExcluir(alerta)
7717
+ },
7718
+ alerta.id
7719
+ )) })
7720
+ ] })
7721
+ ] });
7722
+ }
6943
7723
  // Annotate the CommonJS export names for ESM import in node:
6944
7724
  0 && (module.exports = {
7725
+ AlertaItem,
7726
+ Alertas,
6945
7727
  AplicationsHeader,
6946
7728
  AppsMenu,
6947
7729
  Avatar,
@@ -7009,10 +7791,12 @@ function HeaderNotifications(props) {
7009
7791
  DropdownMenuSubTrigger,
7010
7792
  DropdownMenuTrigger,
7011
7793
  EmptyState,
7794
+ ErroAlertas,
7012
7795
  ErroNotificacoes,
7013
7796
  FileList,
7014
7797
  FileUpload,
7015
7798
  Filter,
7799
+ FormularioAlerta,
7016
7800
  Header,
7017
7801
  HeaderContainer,
7018
7802
  HeaderNotifications,
@@ -7065,14 +7849,17 @@ function HeaderNotifications(props) {
7065
7849
  URL_PADRAO_NOTIFICACOES,
7066
7850
  availableApps,
7067
7851
  buildMonthDays,
7852
+ buscarAlertas,
7068
7853
  buttonVariants,
7069
7854
  formatDayAriaLabel,
7070
7855
  formatFileSize,
7071
7856
  formatMonthYear,
7072
7857
  isSameDay,
7073
7858
  isToday,
7859
+ normalizarBaseUrl,
7074
7860
  toDateKey,
7075
7861
  toLocalNoon,
7862
+ usarAlertas,
7076
7863
  useDrawer,
7077
7864
  validateFiles
7078
7865
  });
@@ -7134,6 +7921,14 @@ lucide-react/dist/esm/icons/bell.js:
7134
7921
  * See the LICENSE file in the root directory of this source tree.
7135
7922
  *)
7136
7923
 
7924
+ lucide-react/dist/esm/icons/calendar-days.js:
7925
+ (**
7926
+ * @license lucide-react v0.453.0 - ISC
7927
+ *
7928
+ * This source code is licensed under the ISC license.
7929
+ * See the LICENSE file in the root directory of this source tree.
7930
+ *)
7931
+
7137
7932
  lucide-react/dist/esm/icons/check.js:
7138
7933
  (**
7139
7934
  * @license lucide-react v0.453.0 - ISC
@@ -7270,6 +8065,14 @@ lucide-react/dist/esm/icons/paperclip.js:
7270
8065
  * See the LICENSE file in the root directory of this source tree.
7271
8066
  *)
7272
8067
 
8068
+ lucide-react/dist/esm/icons/pencil.js:
8069
+ (**
8070
+ * @license lucide-react v0.453.0 - ISC
8071
+ *
8072
+ * This source code is licensed under the ISC license.
8073
+ * See the LICENSE file in the root directory of this source tree.
8074
+ *)
8075
+
7273
8076
  lucide-react/dist/esm/icons/plus.js:
7274
8077
  (**
7275
8078
  * @license lucide-react v0.453.0 - ISC