defmodule LocalspotWeb.BusinessLive.Show do use LocalspotWeb, :live_view alias Localspot.Businesses @impl true def mount(%{"slug" => slug}, _session, socket) do case Businesses.get_business_by_slug(slug) do nil -> {:ok, socket |> put_flash(:error, "Business not found") |> push_navigate(to: ~p"/businesses")} business -> {:ok, socket |> assign(:page_title, business.name) |> assign(:business, business) |> assign(:is_open, Businesses.currently_open?(business.hours))} end end @impl true def render(assigns) do ~H"""
<%!-- Back link --%> <.link navigate={~p"/businesses"} class="btn btn-ghost btn-sm mb-4"> <.icon name="hero-arrow-left" class="w-4 h-4" /> Back to Directory <%!-- Photo gallery --%> <%!-- Business header --%>

{@business.name} Locally Owned

<.link navigate={~p"/categories/#{@business.category.slug}"} class="text-base-content/60 hover:underline" > {@business.category.name}
{if @is_open, do: "Open Now", else: "Closed"}
<%!-- Description --%>

{@business.description}

<%!-- Local ownership info --%>
<.icon name="hero-check-badge" class="w-6 h-6" />

Locally Owned Business

This business has confirmed they are locally owned and operated, not a chain or franchise.

<%!-- Contact info --%>

Contact Information

<.icon name="hero-map-pin" class="w-5 h-5 mt-0.5 text-primary" />

{@business.street_address}

{@business.city}, {@business.state} {@business.zip_code}

<.icon name="hero-phone" class="w-5 h-5 text-primary" /> {Businesses.format_phone(@business.phone)}
<.icon name="hero-envelope" class="w-5 h-5 text-primary" /> {@business.email}
<.icon name="hero-globe-alt" class="w-5 h-5 text-primary" /> Visit Website <.icon name="hero-arrow-top-right-on-square" class="w-4 h-4 inline" />
<%!-- Hours --%>

Business Hours

<%= if @business.hours == [] do %>

Hours not available

<% else %>
{Businesses.day_name(hour.day_of_week)} Closed {format_time(hour.opens_at)} - {format_time(hour.closes_at)}
<% end %>
""" end defp format_time(time) do Calendar.strftime(time, "%I:%M %p") end end