<div class="mb-6 flex gap-3 flex-row items-center justify-between">
  <div class="flex gap-3 items-center">
    <.link href={~p"/sources"}>
      <.icon name="hero-arrow-left" class="w-10 h-10 hover:dark:text-white" />
    </.link>
    <h2 class="text-title-md2 font-bold text-black dark:text-white ml-4">
      <%= @source.custom_name %>
    </h2>
  </div>

  <nav>
    <.link href={~p"/sources/#{@source}/edit"}>
      <.button color="bg-primary" rounding="rounded-lg">
        <.icon name="hero-pencil-square" class="mr-2" /> Edit <span class="hidden sm:inline pl-1">Source</span>
      </.button>
    </.link>
  </nav>
</div>
<div class="rounded-sm border border-stroke bg-white px-5 py-5 shadow-default dark:border-strokedark dark:bg-boxdark sm:px-7.5">
  <div class="max-w-full">
    <.tabbed_layout>
      <:tab_append>
        <.actions_dropdown source={@source} conn={@conn} />
      </:tab_append>

      <:tab title="Source">
        <div class="flex flex-col gap-10 text-white">
          <h3 class="font-bold text-xl mt-6">Raw Attributes</h3>
          <section>
            <strong>Media Profile:</strong>
            <.subtle_link href={~p"/media_profiles/#{@source.media_profile_id}"}>
              <%= @source.media_profile.name %>
            </.subtle_link>
          </section>

          <.list_items_from_map map={Map.from_struct(@source)} />
        </div>
      </:tab>
      <:tab title="Pending Media">
        <%= live_render(
          @conn,
          Pinchflat.Sources.MediaItemTableLive,
          session: %{"source_id" => @source.id, "media_state" => "pending"}
        ) %>
      </:tab>
      <:tab title="Downloaded Media">
        <%= live_render(
          @conn,
          Pinchflat.Sources.MediaItemTableLive,
          session: %{"source_id" => @source.id, "media_state" => "downloaded"}
        ) %>
      </:tab>
      <:tab title="Pending Tasks">
        <%= if match?([_|_], @pending_tasks) do %>
          <.table rows={@pending_tasks} table_class="text-black dark:text-white">
            <:col :let={task} label="Worker">
              <%= task.job.worker %>
            </:col>
            <:col :let={task} label="State">
              <%= task.job.state %>
            </:col>
            <:col :let={task} label="Scheduled At">
              <%= Calendar.strftime(task.job.scheduled_at, "%y-%m-%d %I:%M:%S %p %Z") %>
            </:col>
          </.table>
        <% else %>
          <p>Nothing Here!</p>
        <% end %>
      </:tab>
    </.tabbed_layout>
  </div>
</div>
