<% content_for :title, "Exports" %>

<div class="w-full my-5">
  <div class="flex justify-center">
    <h1 class="font-bold text-4xl">Exports</h1>
  </div>

  <div id="exports" class="min-w-full">
    <% if @exports.empty? %>
      <div class="hero min-h-80 bg-base-200">
        <div class="hero-content text-center">
          <div class="max-w-md">
            <h1 class="text-5xl font-bold">Hello there!</h1>
            <p class="py-6">
              Here you'll find your exports, created on <%= link_to 'Points', points_url, class: 'link' %> page. But now there are none.
            </p>
          </div>
        </div>
      </div>
    <% else %>
      <div class="flex justify-center my-5">
        <div class='flex'>
          <%= paginate @exports %>
        </div>
      </div>
      <div class="overflow-x-auto">
        <table class="table overflow-x-auto">
          <thead>
            <tr>
              <th>Name</th>
              <th>File size</th>
              <th>Created at</th>
              <th>Status</th>
              <th>Actions</th>
            </tr>
          </thead>
          <tbody>
            <% @exports.each do |export| %>
              <tr>
                <td><%= export.name %></td>
                <td><%= number_to_human_size(export.file&.byte_size) || 'N/A' %></td>
                <td><%= human_datetime(export.created_at) %></td>
                <td><%= export.status %></td>
                <td class="whitespace-nowrap">
                  <% if export.completed? %>
                    <% if export.file.present? %>
                      <%= link_to 'Download', rails_blob_path(export.file, disposition: 'attachment'), class: "px-4 py-2 bg-blue-500 text-white rounded-md", download: export.name %>
                    <% else %>
                      <%= link_to 'Download', export.url, class: "px-4 py-2 bg-blue-500 text-white rounded-md", download: export.name %>
                    <% end %>
                  <% end %>
                  <%= link_to 'Delete', export, data: { turbo_confirm: "Are you sure?", turbo_method: :delete }, method: :delete, class: "px-4 py-2 bg-red-500 text-white rounded-md" %>
                </td>
              </tr>
            <% end %>
          </tbody>
        </table>
      </div>
    <% end %>
  </div>
</div>
