% has_archived = can?(:manage, :countless) || current_account.templates.where.not(archived_at: nil).exists? %>
<% show_dropzone = params[:q].blank? && @pagy.pages == 1 && ((@template_folders.size < 10 && @templates.size.zero?) || (@template_folders.size < 7 && @templates.size < 4) || (@template_folders.size < 4 && @templates.size < 7)) %>
<% if Docuseal.demo? %><%= render 'shared/demo_alert' %><% end %>
  <%= form_for '', url: '', id: form_id = SecureRandom.uuid, method: :post, class: 'hidden', data: { target: 'dashboard-dropzone.form' }, html: { enctype: 'multipart/form-data' } do %>
    
    
    
  <% end %>
  
    <% unless show_dropzone %>
      <%= render 'templates/dashboard_dropzone', style: 'height: 114px' %>
    <% end %>
    
      <% if has_archived || @pagy.count.nil? || @pagy.count > 0 || @template_folders.present? %>
        
          <%= render 'dashboard/toggle_view', selected: 'templates' %>
        
      <% end %>
      
        <%= t('document_templates_html') %>
      
    
      <% if params[:q].present? || @pagy.pages > 1 || @template_folders.present? %>
        <%= render 'shared/search_input' %>
      <% end %>
      <% if can?(:create, ::Template) %>
        
          <%= render 'templates/upload_button' %>
        
        <%= link_to new_template_path, class: 'white-button !border gap-2', data: { turbo_frame: :modal } do %>
          <%= svg_icon('plus', class: 'w-6 h-6 stroke-2') %>
          <%= t('create') %>
        <% end %>
      <% end %>
    
  
      <%= render partial: 'template_folders/folder', collection: @template_folders, as: :folder %>
    
  <% end %>
  <% if @templates.present? %>
    
      <%= render partial: 'templates/template', collection: @templates %>
      <% if show_dropzone && (current_user.created_at > 2.weeks.ago || params[:tour] == 'true') && current_user == true_user %>
        <% user_config = current_user.user_configs.find_or_initialize_by(key: UserConfig::SHOW_APP_TOUR) %>
        <% if user_config.new_record? || user_config.value || params[:tour] == 'true' %>
          
            
            <% if user_config.new_record? && !params.key?(:tour) %>
              
                
                  <%= t('welcome_to_docuseal') %>
                
                
                  <%= t('start_a_quick_tour_to_learn_how_to_create_an_send_your_first_document') %>
                
                
                  <%= button_to button_title(title: t('skip'), icon_disabled: svg_icon('loader', class: 'w-4 h-4 animate-spin')), user_configs_path, params: { user_config: { key: UserConfig::SHOW_APP_TOUR, value: false } }, class: 'btn btn-sm btn-outline w-full', form_class: 'flex-1', method: :post, form: { onsubmit: 'window.app_tour.parentNode.remove()' } %>
                  <%= button_to t('start_tour'), user_configs_path, params: { user_config: { key: UserConfig::SHOW_APP_TOUR, value: true } }, class: 'btn btn-sm btn-warning  w-full', form_class: 'flex-1', method: :post, form: { onsubmit: 'window.app_tour.start()' } %>
                
               
            <% end %>
          
 
        <% end %>
      <% end %>
    
      <%= view_archived_html %>
    
  <% end %>
<% elsif params[:q].present? %>
  
    
      <%= t('templates_not_found') %>
    
   
<% end %>
<%= render 'shared/review_form' %>