defmodule OutlookWeb.PublicComponents do
  @moduledoc """
    Provides components for showing and listing artikel and autoren.
  """
  use Phoenix.Component
  import OutlookWeb.ViewHelpers

  use OutlookWeb, :verified_routes

  alias Phoenix.LiveView.JS

  attr :autor, :any, required: true

  def autor(assigns) do
    ~H"""
    <a href={"/autoren/#{@autor.id}"}>
      <div class="p-4 my-2 border rounded-lg border-stone-400 text-stone-800 dark:text-stone-300 ">
        <div class="font-bold"><%= @autor.name %></div>
        <div class=""><%= @autor.description |> tidy_raw %></div>
      </div>
    </a>
    """
  end

  attr :artikel, :any, required: true
  attr :show_autor, :boolean, default: true

  def artikel(assigns) do
    ~H"""
    <.link navigate={~p"/artikel/#{@artikel}"}>
      <div class="my-2 px-2 rounded border-2 border-solid border-gray-300 dark:border-stone-800">
        <h4 class="font-bold  text-stone-800 dark:text-stone-300 py-2"><%= @artikel.title %></h4>
        <div :if={@show_autor}><small><%= @artikel.autor_name %></small></div>
        <div><small><%= @artikel.date |> Calendar.strftime("%d.%m.%Y") %></small></div>
        <div><%= @artikel.teaser |> tidy_raw %></div>
      </div>
    </.link>
    """
  end
end
