<% content_for(:html_title, "#{@template.name} | DocuSeal") %>
<% I18n.with_locale(@template.account.locale) do %>
  <% content_for(:html_description, t('account_name_has_invited_you_to_fill_and_sign_documents_online_effortlessly_with_a_secure_fast_and_user_friendly_digital_document_signing_solution', account_name: @template.account.name)) %>
<% end %>
<main class="max-w-md mx-auto px-2 mt-12 mb-4">
  <div class="space-y-6 mx-auto">
    <div class="space-y-6">
      <div class="flex items-center justify-center">
        <%= render 'start_form/banner' %>
      </div>
      <div class="flex items-center bg-base-200 rounded-xl p-4 mb-4">
        <div class="flex items-center">
          <div class="mr-3">
            <%= svg_icon('writing_sign', class: 'w-10 h-10') %>
          </div>
          <div>
            <p class="text-lg font-bold mb-1"><%= @template.name %></p>
            <p dir="auto" class="text-sm"><%= t('invited_by_html', name: @template.account.name) %></p>
          </div>
        </div>
      </div>
    </div>
    <div>
      <%= t('we_sent_a_one_time_verification_code_to_your_email_address_please_enter_the_code_below_to_continue') %>
    </div>
    <%= form_for '', url: start_form_path(@template.slug), method: :put, html: { class: 'space-y-4', id: 'code_form' } do |f| %>
      <div dir="auto" class="form-control !mt-0">
        <%= f.hidden_field 'resubmit', value: params[:resubmit] %>
        <%= f.hidden_field 'submitter[name]', value: params[:name] || @submitter&.name %>
        <%= f.hidden_field 'submitter[email]', value: params[:email] || @submitter&.email %>
        <%= f.hidden_field 'submitter[phone]', value: params[:phone] || @submitter&.phone %>
        <%= f.text_field :one_time_code, required: true, class: 'base-input text-center', placeholder: 'XXX-XXX' %>
        <div class="flex justify-between items-center mt-1">
          <span>
            <% if flash[:alert] %>
              <span class="text-red-500">
                <%= flash[:alert] %>
              </span>
            <% elsif flash[:notice] %>
              <%= flash[:notice] %>
            <% end %>
          </span>
          <span>
            <label for="resend_code" id="resend_label" class="link"><%= t(:re_send_code) %></label>
          </span>
        </div>
      </div>
      <toggle-submit dir="auto" class="form-control">
        <%= f.button button_title(title: t('submit')), class: 'base-button' %>
      </toggle-submit>
    <% end %>
    <%= button_to t(:re_send_email), start_form_email_2fa_send_index_path, params: { slug: @template.slug, resend: true, submitter: { name: params[:name] || @submitter&.name, email: params[:email] || @submitter&.email, phone: params[:phone] || @submitter&.phone } }.compact, method: :post, id: 'resend_code', class: 'hidden' %>
  </div>
</main>
