(async () => { // カレンダーは NIHO の部品に任せ、上の告知と下のボタンだけを描く。 const el = (tag, className, ...children) => { const node = document.createElement(tag); if (className) node.className = className; node.append(...children); return node; }; // 押せる要素には、名前(data-on-tap)と読み上げの名前(aria-label・120 字まで)が要る。 const tap = (node, name, label, data) => { node.setAttribute("data-on-tap", name); node.setAttribute("aria-label", label.slice(0, 120)); for (const [key, value] of Object.entries(data || {})) node.dataset[key] = value; return node; }; const dayOf = (instant) => Number(instant.slice(5, 7)) + "/" + Number(instant.slice(8, 10)); // 申込の状態。参加している → 満席 → 受付終了 → 残りの席 の順に見る。 const stateOf = (event, text) => event.joined ? text.joined : event.registration === "FULL" ? text.full : event.registration === "CLOSED" ? text.closed : event.seats ? text.left(event.seats.left) : ""; const join = (...parts) => parts.filter((part) => part !== "").join(" "); const yen = (amount) => "¥" + String(amount).replace(/\B(?=(\d{3})+$)/g, ","); const feeOf = (event, text) => event.fee === null ? "" : event.fee === 0 ? text.free : yen(event.fee); const TEXT = { ja: { next: "つぎの", empty: "これからの予定はありません", book: "場所をとる", home: "リビングへ戻る", free: "無料", joined: "参加します", full: "満席", closed: "受付終了", left: (count) => "あと" + count + "席" }, en: { next: "Next ", empty: "Nothing coming up", book: "Book a space", home: "Back to the living room", free: "Free", joined: "Joined", full: "Full", closed: "Closed", left: (count) => count + " left" }, }; const style = document.createElement("style"); style.textContent = [ ".notice{margin:12px 16px;padding:16px;border-radius:12px;background:#2f5d50;color:#ffffff}", ".kicker{font-size:13px;font-weight:700}", ".title{max-height:2.8em;margin:4px 0 0;overflow:hidden;font-size:20px;font-weight:800;line-height:1.4;overflow-wrap:anywhere}", ".meta{margin:6px 0 0;font-size:14px;overflow-wrap:anywhere}", ".empty{margin:12px 16px;padding:16px;border-radius:12px;background:#eef3ec;color:#2b3a33;font-size:15px}", ".foot{display:grid;gap:8px;padding:12px 16px 20px}", ".main{min-height:48px;padding:12px;border-radius:12px;background:#2f5d50;color:#ffffff;font-size:16px;font-weight:700;text-align:center}", ".sub{min-height:48px;padding:12px;border:1px solid #9aa89f;border-radius:12px;color:#2b3a33;font-size:15px;font-weight:700;text-align:center}", ].join(""); document.head.append(style); const draw = () => { const view = niho.surface.get(); const text = TEXT[view.language] || TEXT.ja; const next = view.events.find((event) => event.endAt.slice(0, 10) >= view.today); const when = next ? dayOf(next.startAt) + " " + next.startAt.slice(11, 16) : ""; document.getElementById("before").replaceChildren(next ? tap(el("section", "notice", el("div", "kicker", text.next + view.labels.event), el("h2", "title", next.title), el("p", "meta", join(when, next.places.slice(0, 3).join("・"))), el("p", "meta", join(feeOf(next, text), stateOf(next, text)))), "open", when + " " + next.title, { ref: next.ref }) : el("section", "empty", text.empty)); const foot = el("section", "foot"); // 予定を作れない人には、作るボタンを出さない(押しても何も起きないため)。 if (view.viewer.canBook) foot.append(tap(el("div", "main", text.book), "book", text.book)); foot.append(tap(el("div", "sub", text.home), "home", text.home)); document.getElementById("after").replaceChildren(foot); }; draw(); niho.surface.onChange(draw); niho.ui.onTap("open", ({ data }) => niho.actions.request({ type: "openBooking", ref: data["data-ref"] })); niho.ui.onTap("book", () => niho.actions.request({ type: "startBooking", date: niho.surface.get().today })); niho.ui.onTap("home", () => niho.actions.request({ type: "openSurface", surface: "HOME" })); await niho.ready(); })();