@anoki/fse-ui
Version:
FSE UI components library
186 lines (185 loc) • 5.34 kB
JavaScript
import { j as n } from "./index.es244.js";
import './components/ui/CardOpeningHours/CardOpeningHours.css';/* empty css */
import { clsx as ee } from "./index.es246.js";
import { useState as i, useCallback as h, useMemo as te, useEffect as se } from "react";
import U from "./index.es225.js";
import "./index.es3.js";
import { Col as $ } from "./index.es10.js";
import { Row as j } from "./index.es9.js";
const me = ({
title: q = "Orari di apertura",
titleTag: z = "h1",
openingHours: x,
weekDaysMap: C,
openLabel: a = "Aperto",
todayLabel: B = "Oggi",
closeLabel: u = "Chiuso",
open24Label: l = "24 ore su 24",
opensSoonLabel: T = "Apre tra poco",
opensAtLabel: N = "Apre alle",
opensTomorrowLabel: I = "Apre domani",
opensOnLabel: D = "Apre",
atLabel: k = "alle",
closesAtLabel: H = "Chiude alle"
}) => {
const [G, J] = i(null), [A, P] = i(""), [Q, m] = i(""), [V, S] = i(""), [W, w] = i(!1), [X, f] = i(!1), [Y, c] = i(""), d = Object.values(C), p = Object.keys(C), Z = () => U.now().toFormat("HH:mm"), v = (t) => {
const [e, s] = t.split(":").map(Number);
return e * 60 + s;
}, F = h(
(t) => t.from === "00:00" && t.to === "00:00",
[]
), y = h(
(t) => t.some(F),
[F]
), _ = (t, e) => {
for (const { from: s, to: r } of t)
if (e >= s && e <= r)
return { open: !0, closingTime: r };
return { open: !1, closingTime: "" };
}, b = (t, e) => {
for (const { from: s } of t)
if (s > e)
return s;
return "";
}, M = h(
(t, e) => {
if (!t) return !1;
const s = v(t), r = v(e), o = s - r;
return o > 0 && o <= 60;
},
[]
), K = h(
(t) => {
for (let e = 1; e <= 7; e++) {
const s = (t + e) % 7, r = p[s], o = x[r];
if (o && o.length > 0)
return {
dayName: d[s].toLowerCase(),
isTomorrow: e === 1
};
}
return null;
},
[p, x, d]
), E = te(() => (t) => t.length === 0 ? u : y(t) ? `${a} ${l}` : t.map(({ from: e, to: s }) => `${e} - ${s}`).join(" | "), [u, y, l, a]);
return se(() => {
const e = U.now().weekday - 1;
J(e), P(d[e] || "");
const s = p[e], r = x[s];
if (!r)
return;
const o = Z();
if (y(r)) {
m(a), c(` | ${l}`), w(!0), f(!1), S(`${a} ${l}`);
return;
}
const { open: L, closingTime: R } = _(r, o);
if (L)
m(a), c(
R ? ` | ${H} ${R}` : ""
), w(!0), f(!1);
else {
const g = b(r, o);
if (w(!1), g)
M(g, o) ? (m(T), c(` | ${k} ${g}`), f(!0)) : (m(u), c(` | ${N} ${g}`), f(!1));
else {
m(u), f(!1);
const O = K(e);
c(
O ? O.isTomorrow ? ` | ${I}` : ` | ${D} ${O.dayName}` : ""
);
}
}
S(E(r));
}, [
k,
M,
u,
H,
E,
K,
y,
l,
a,
x,
N,
D,
T,
I,
d,
p
]), /* @__PURE__ */ n.jsxs(
$,
{
fs: "6",
fw: "semibold",
className: "ui-card-opening rounded shadow text-slate-28",
children: [
/* @__PURE__ */ n.jsxs($, { as: "header", className: "ui-card-header", children: [
/* @__PURE__ */ n.jsx(z, { className: "text-slate-20 fw-semibold fs-4", children: q }),
/* @__PURE__ */ n.jsxs(
j,
{
justifyContent: "space-between",
alignItems: "center",
style: { backgroundColor: "#F7F2FC" },
py: "x16",
px: "x24",
fw: "bold",
fs: "6",
className: "rounded",
children: [
/* @__PURE__ */ n.jsxs("p", { className: "text-slate-28", children: [
B,
", ",
A
] }),
/* @__PURE__ */ n.jsxs("p", { children: [
/* @__PURE__ */ n.jsx(
"span",
{
className: W ? "text-success" : X ? "text-warning" : "text-error",
children: Q
}
),
/* @__PURE__ */ n.jsx("span", { className: "fw-regular text-grey-black", children: Y })
] })
]
}
)
] }),
/* @__PURE__ */ n.jsxs($, { as: "main", pt: "x32", gap: "x24", children: [
/* @__PURE__ */ n.jsx(j, { justifyContent: "space-around", className: "ui-weekdays-container", children: d.map((t, e) => /* @__PURE__ */ n.jsx(
j,
{
justifyContent: "center",
alignItems: "center",
className: ee(
G === e ? "active-day text-primary" : "",
"flex-1"
),
children: t.charAt(0).toUpperCase()
},
e
)) }),
/* @__PURE__ */ n.jsxs(
j,
{
justifyContent: "space-between",
alignItems: "center",
fw: "regular",
children: [
/* @__PURE__ */ n.jsx("p", { children: A }),
/* @__PURE__ */ n.jsx("p", { children: V })
]
}
)
] })
]
}
);
};
export {
me as CardOpeningHours
};
//# sourceMappingURL=index.es36.js.map