<%= page_title "Templates" %>

<div class="flex items-center justify-between mb-6">
  <div>
    <h1 class="text-h2 text-neutral-900">All Templates</h1>
    <p class="text-body text-neutral-700 mt-1">Manage screen templates</p>
  </div>
  <div class="flex space-x-3">
    <% if policy(::Template.new).new? %>
      <%= link_to new_template_path, class: "btn-primary btn-md whitespace-nowrap" do %>
        <%= heroicon('plus', class: 'w-4 h-4 mr-2') %>
        New Template
      <% end %>
    <% end %>
  </div>
</div>

<div id="templates" class="flex flex-wrap gap-4 my-4">
  <% @templates.each do |template| %>
    <%= link_to template, class: "block" do %>
    <div class="block w-96 h-full pb-4 border-2 text-center bg-white">
      <div class="m-auto mt-2 p-2">
        <% if template.image.attached? %>
          <%= image_tag template.image %>
        <% else %>
          <i>No Image</i>
        <% end %>
      </div>
      <div class="text-lg font-medium"><%= template.name %></div>
    </div>
    <% end %>
  <% end %>
</div>