%= render 'shared/turbo_modal_large', title: t('preferences') do %>
<% show_api = Docuseal.multitenant? || current_account.testing? || !current_account.linked_account_account %>
<% show_recipients = @template.submitters.to_a.length > 1 %>
<% options = [[t('general'), 'general']] %>
<% options << [t('recipients'), 'recipients'] if show_recipients %>
<% options << [t('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 %>
<%= render 'access' %>
<%= form_for @template, url: template_preferences_path(@template), method: :post, html: { autocomplete: 'off', class: 'mt-2' }, data: { close_on_submit: false } do |f| %>
<%= f.label :visibility, t('visibility'), class: 'label' %>
<%= f.select :visibility,
[[t('visibility_private'), Template::VISIBILITY_PRIVATE],
[t('visibility_public'), Template::VISIBILITY_PUBLIC]],
{}, class: 'base-select', data: { action: 'change->submit-form#submit' } %>
<% end %>
<%= form_for @template, url: template_preferences_path(@template), method: :post, html: { autocomplete: 'off', class: 'mt-2' }, data: { close_on_submit: false } do |f| %>
<%= f.fields_for :preferences, Struct.new(:bcc_completed).new(@template.preferences['bcc_completed']) do |ff| %>
<%= ff.label :bcc_completed, class: 'label' do %>
<%= t('completed_documents_notification_bcc_address') %>
<% end %>
<%= tag.input type: 'email', multiple: true, name: 'template[preferences][bcc_completed]', autocomplete: 'off', class: 'base-input', value: ff.object.bcc_completed, id: ff.field_id(:bcc_completed) %>
<% end %>
<% end %>
<%= form_for @template, url: template_preferences_path(@template), method: :post, html: { autocomplete: 'off', class: 'mb-5' }, data: { close_on_submit: false } do |f| %>
<%= f.fields_for :preferences, Struct.new(:default_expire_at_duration, :default_expire_at).new(@template.preferences['default_expire_at_duration'], @template.preferences['default_expire_at'] ? Time.zone.parse(@template.preferences['default_expire_at']).in_time_zone(current_account.timezone) : nil) do |ff| %>
<% end %>
<% end %>
<%= t('form_preferences') %>
<%= render 'templates_prefillable_fields/form', template: @template %>
<%= form_for @template, url: template_preferences_path(@template), method: :post, html: { autocomplete: 'off', class: 'mt-1' }, data: { close_on_submit: false } do |f| %>
<% configs = AccountConfigs.find_or_initialize_for_key(current_account, AccountConfig::SUBMITTER_COMPLETED_EMAIL_KEY).value %>
<%= f.fields_for :preferences, Struct.new(:completed_redirect_url, :completed_message, :require_phone_2fa, :require_email_2fa).new(@template.preferences['completed_redirect_url'].presence, Struct.new(:title, :body).new(*(@template.preferences['completed_message'] || {}).values_at('title', 'body')), @template.preferences['require_phone_2fa'] == true, @template.preferences['require_email_2fa'] == true) do |ff| %>
<%= ff.label :completed_redirect_url, t('redirect_on_completion_url'), class: 'label' %>
<%= ff.url_field :completed_redirect_url, required: false, class: 'base-input', dir: 'auto' %>
<%= ff.fields_for :completed_message, ff.object.completed_message do |fff| %>
<% end %>
<%= render 'templates_preferences/form_fields', ff: %>
<%= t('require_email_2fa_to_open') %>
<%= ff.check_box :require_email_2fa, { checked: ff.object.require_email_2fa == true, class: 'toggle' }, 'true', 'false' %>
<% end %>
<% end %>
<%= render 'templates_preferences/submitter_invitation_reminder_email_collapse' %>
<%= render 'templates_code_modal/preferences', class: 'pt-2' %>
<% if show_recipients %>
<%= form_for @template, url: template_share_link_path(@template), method: :post, html: { id: 'shared_link_form', autocomplete: 'off', class: 'w-full mt-1' }, data: { close_on_submit: false } do |f| %>
<%= render 'shared/clipboard_copy', icon: 'copy', text: start_form_url(slug: @template.slug), class: 'base-button', icon_class: 'w-6 h-6 text-white', copy_title: t('copy'), copied_title: t('copied') %>
<%= t('enable_shared_link') %>
<%= f.check_box :shared_link, { class: 'toggle' }, 'true', 'false' %>
<% end %>
<%= 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' }, data: { close_on_submit: false } do |f| %>
<%= f.hidden_field :template_id, value: @template.id %>
<%= t('share_template_with_test_mode') %>
<%= f.check_box :value, class: 'toggle', checked: @template.template_sharings.exists?(account_id: current_account.testing_accounts) %>
<% end %>
<% end %>
<% end %>
<% end %>