defmodule SpazioSolazzoWeb.BookingCalendarLiveComponent do @moduledoc """ The calendar displayed in the space booking view. It allows users to select a date in a beautifully-styled calendar grid. """ use SpazioSolazzoWeb, :live_component alias SpazioSolazzo.CalendarExt def update(assigns, socket) do first_day = assigns[:first_day_of_month] || socket.assigns[:first_day_of_month] || Date.utc_today() |> Date.beginning_of_month() grid = CalendarExt.build_calendar_grid(first_day) {:ok, socket |> assign(assigns) |> assign(:first_day_of_month, first_day) |> assign(:grid, grid)} end def handle_event("prev-month", _, socket) do new_date = socket.assigns.first_day_of_month |> Date.shift(month: -1) |> Date.beginning_of_month() {:noreply, assign(socket, first_day_of_month: new_date, grid: CalendarExt.build_calendar_grid(new_date))} end def handle_event("next-month", _, socket) do new_date = socket.assigns.first_day_of_month |> Date.shift(month: 1) |> Date.beginning_of_month() {:noreply, assign(socket, first_day_of_month: new_date, grid: CalendarExt.build_calendar_grid(new_date))} end # --- Selection (Parent IS notified) --- def handle_event("select-date", %{"date" => date_str}, socket) do date = Date.from_iso8601!(date_str) send(self(), {:date_selected, date}) {:noreply, assign(socket, :selected_date, date)} end def render(assigns) do ~H"""