<%= render HeaderCompactComponent.new(title: "Storage") %>

<%= render MainCompactComponent.new do %>
  <section class="permissions">
    <p class="mb-8">
      The app on
      <%= link_to @client_id, "https://#{@client_id}", class: "ks-text-link" %>
      is asking for access to these folders:
    </p>

    <% if @root_access_requested %>
    <p class="scope text-lg">
      <span class="text-red-700">
        <%= render partial: "icons/alert-triangle",
              locals: { custom_class: "inline-block align-bottom mr-1.5" } %>
        All files and directories
      </span>
      <% if (@scopes & [":r"]).any? %>
        <span class="text-sm text-gray-500">(read only)</span>
      <% end %>
    </p>
    <% else %>
      <% @scopes.each do |scope| %>
      <p class="scope text-gray-600">
        <span class="text-lg">
          <%= render partial: "icons/folder",
            locals: { custom_class: "inline-block align-bottom mr-1.5" } %>
          <%= scope_name(scope) %>
        </span>
        <% if scope_permissions(scope) == "r" %>
          <span>(read only)</span>
        <% end %>
      </p>
      <% end %>
    <% end %>

    <%= form_with(url: rs_oauth_path, method: :post, data: { turbo: false }) do |f| %>
      <%= f.hidden_field :redirect_uri, value: @redirect_uri %>
      <%= f.hidden_field :scope, value: @scopes.join(" ") %>
      <%= f.hidden_field :user_id, value: @user.id %>
      <%= f.hidden_field :client_id, value: @client_id %>
      <%= f.hidden_field :state, value: @state %>
      <p class="mt-8 mb-6">
        <%= f.label :expire_at, "Permission expires:", class: "mr-1.5" %>
        <%= f.select :expire_at, options_for_select(@expire_at_dates) %>
      </p>
      <p class="text-sm text-gray-500">
        You can revoke access for this app at any time on your storage dashboard.
      </p>
      <p class="mt-8 flex flex-col sm:flex-row gap-3 sm:gap-2 sm:justify-items-stretch">
        <%= f.submit "Allow",
              class: "btn-md btn-blue w-full sm:order-last sm:grow",
              data: { disable_with: "Saving..." } %>
        <%= link_to "Deny", @denial_url, class: "btn-md btn-gray text-red-700 w-full sm:grow" %>
      </div>
    <% end %>
  </section>
<% end %>
