%= render 'shared/turbo_modal_large', title: 'Preferences', close_after_submit: false do %>
  <% show_api = Docuseal.multitenant? || current_account.testing? || !current_account.linked_account_account %>
  <% options = [%w[General general]] %>
  <% options << ['API and Embedding', 'api'] if show_api %>
  <% if options.size > 1 %>
    
      
        <% options.each_with_index do |(label, value), index| %>
          
            <%= radio_button_tag 'option', value, value == 'general', class: 'peer hidden', data: { action: 'change:toggle-visible#trigger' } %>
            
          
        <% end %>
      
    
  <% end %>
  
    <%= form_for @template, url: template_preferences_path(@template), method: :post, html: { autocomplete: 'off', class: 'mt-1' } do |f| %>
      
      <%= f.fields_for :preferences, Struct.new(:request_email_subject, :request_email_body).new(*(@template.preferences.values_at('request_email_subject', 'request_email_body').compact_blank.presence || AccountConfigs.find_or_initialize_for_key(current_account, AccountConfig::SUBMITTER_INVITATION_EMAIL_KEY).value.values_at('subject', 'body'))) do |ff| %>
        
          <%= ff.label :request_email_subject, 'Email subject', class: 'label' %>
          <%= ff.text_field :request_email_subject, required: true, class: 'base-input', dir: 'auto' %>
        
        
      <% end %>
      
    <% end %>
    <%= form_for @template, url: template_preferences_path(@template), method: :post, html: { autocomplete: 'off', class: 'mt-2' } do |f| %>
      
      <%= f.fields_for :preferences, Struct.new(:bcc_completed).new(@template.preferences['bcc_completed']) do |ff| %>
        
          <%= ff.label :bcc_completed, class: 'label' do %>
            
              
                Completed documents BCC address
              
            
          <% end %>
          <%= tag.input type: 'email', multiple: true, name: 'template[preferences][bcc_completed]', autocomplete: 'off', class: 'base-input', value: ff.object.bcc_completed %>
        
      <% end %>
      
    <% end %>
    <%= render 'templates_code_modal/preferences' %>
  
 
  <% if show_api %>
    
      
      
      <%= render 'templates_code_modal/placeholder' %>
      <%= render 'templates/embedding', template: @template %>
      <% if can?(:manage, TemplateSharing.new(template: @template)) %>
        <%= form_for '', url: template_sharings_testing_index_path, method: :post, html: { class: 'mt-1' } do |f| %>
          <%= f.hidden_field :template_id, value: @template.id %>
          
            
              Share template with Test Environment
            
            <%= f.check_box :value, class: 'toggle', checked: @template.template_sharings.exists?(account_id: current_account.testing_accounts), onchange: 'this.form.requestSubmit()' %>
          
        <% end %>
        
        
      <% end %>
    
 
  <% end %>
<% end %>