<% 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="text-center w-full space-y-6">
        <%= render 'banner' %>
        <% unless @template.archived_at? %>
          <p class="text-xl font-semibold text-center"><%= t('you_have_been_invited_to_submit_a_form') %></p>
        <% end %>
      </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>
            <% if @template.archived_at? %>
              <p dir="auto" class="text-sm"><%= t('form_has_been_deleted_by_html', name: @template.account.name) %></p>
            <% else %>
              <p dir="auto" class="text-sm"><%= t('invited_by_html', name: @template.account.name) %></p>
            <% end %>
          </div>
        </div>
      </div>
    </div>
    <% if !@template.archived_at? && !@template.account.archived_at? %>
      <%= form_for @submitter, url: start_form_path(@template.slug), data: { turbo_frame: :_top }, method: :put, html: { class: 'space-y-4' } do |f| %>
        <% if @error_message %>
          <div class="alert items-start bg-base-100 border border-red-400 text-red-400">
            <%= svg_icon('info_circle', class: 'stroke-current shrink-0 h-6 w-6 mt-1') %>
            <div class="text-sm"><%= @error_message %></div>
          </div>
        <% end %>
        <% link_form_fields = @template.preferences.fetch('link_form_fields', ['email']) %>
        <% multiple_fields = link_form_fields.size > 1 %>
        <% if link_form_fields.include?('name') %>
          <div dir="auto" class="form-control !mt-0">
            <%= f.label :name, t('name'), class: 'label' %>
            <%= f.text_field :name, value: current_user&.full_name || params[:name] || @submitter.name, required: true, class: 'base-input', placeholder: t(multiple_fields ? 'provide_your_name' : 'provide_your_name_to_start') %>
          </div>
        <% end %>
        <% if link_form_fields.include?('email') %>
          <div dir="auto" class="form-control !mt-0">
            <%= f.label :email, t('email'), class: 'label' %>
            <%= f.email_field :email, value: current_user&.email || params[:email] || @submitter.email, required: true, class: 'base-input', placeholder: t(multiple_fields ? 'provide_your_email' : 'provide_your_email_to_start') %>
          </div>
        <% end %>
        <% if link_form_fields.include?('phone') %>
          <div dir="auto" class="form-control !mt-0">
            <%= f.label :phone, t('phone'), class: 'label' %>
            <%= f.telephone_field :phone, value: params[:phone] || @submitter.phone, pattern: '^\+[0-9\s\-]+$', required: true, title: t('use_international_format_1xxx_'), class: 'base-input w-full', placeholder: t(multiple_fields ? 'provide_your_phone_in_international_format' : 'provide_your_phone_in_international_format_to_start') %>
          </div>
        <% end %>
        <toggle-submit dir="auto" class="form-control">
          <%= f.button button_title(title: t('start'), disabled_with: t('starting')), class: 'base-button' %>
        </toggle-submit>
      <% end %>
    <% end %>
  </div>
  <div class="mt-4">
    <%= render 'shared/attribution', link_path: '/start', account: @template.account %>
    <%= render 'start_form/policy', account: @template.account %>
  </div>
</main>
