%= turbo_frame_tag "modal" do %>
<% security_questions = Array(@challenge[:security_questions]) %>
<% token_methods = Array(@challenge[:token_methods]) %>
<% safe_captcha_image = @challenge[:captcha_image].to_s.split(%r{[^A-Za-z0-9+/=\s]}, 2).first.to_s.gsub(/\s+/, "") %>
<%= render DS::Dialog.new do |dialog| %>
<% dialog.with_header(title: t(".title")) %>
<% dialog.with_body do %>
<% if security_questions.any? %>
<%= form_with url: submit_mfa_sophtron_item_path(@sophtron_item), method: :post, class: "space-y-3", data: { turbo_frame: "modal" } do %>
<%= hidden_field_tag :mfa_type, "security_answer" %>
<%= hidden_field_tag :accountable_type, @accountable_type %>
<%= hidden_field_tag :account_id, @account_id %>
<%= hidden_field_tag :return_to, @return_to %>
<% security_questions.each_with_index do |question, index| %>
<% answer_field_id = "security_answer_#{index}" %>
<% end %>
<%= render DS::Button.new(text: t(".submit"), type: "submit") %>
<% end %>
<% elsif token_methods.any? %>
<% token_methods.each do |method| %>
<%= form_with url: submit_mfa_sophtron_item_path(@sophtron_item), method: :post, data: { turbo_frame: "modal" } do %>
<%= hidden_field_tag :mfa_type, "token_choice" %>
<%= hidden_field_tag :token_choice, method %>
<%= hidden_field_tag :accountable_type, @accountable_type %>
<%= hidden_field_tag :account_id, @account_id %>
<%= hidden_field_tag :return_to, @return_to %>
<%= button_tag type: "submit", class: "w-full rounded-lg border border-primary bg-container-inset p-3 text-left text-sm text-primary transition-colors hover:bg-container-inset-hover" do %>
<%= method %>
<% end %>
<% end %>
<% end %>
<% elsif @challenge[:token_sent] %>
<%= form_with url: submit_mfa_sophtron_item_path(@sophtron_item), method: :post, class: "space-y-3", data: { turbo_frame: "modal" } do %>
<%= hidden_field_tag :mfa_type, "token_input" %>
<%= hidden_field_tag :accountable_type, @accountable_type %>
<%= hidden_field_tag :account_id, @account_id %>
<%= hidden_field_tag :return_to, @return_to %>
<%= render DS::Button.new(text: t(".submit"), type: "submit") %>
<% end %>
<% elsif @challenge[:token_read].present? %>
<%= @challenge[:token_read] %>
<%= form_with url: submit_mfa_sophtron_item_path(@sophtron_item), method: :post, data: { turbo_frame: "modal" } do %>
<%= hidden_field_tag :mfa_type, "verify_phone" %>
<%= hidden_field_tag :accountable_type, @accountable_type %>
<%= hidden_field_tag :account_id, @account_id %>
<%= hidden_field_tag :return_to, @return_to %>
<%= render DS::Button.new(text: t(".phone_confirmed"), type: "submit") %>
<% end %>
<% elsif safe_captcha_image.present? %>
<%= form_with url: submit_mfa_sophtron_item_path(@sophtron_item), method: :post, class: "space-y-3", data: { turbo_frame: "modal" } do %>
<%= hidden_field_tag :mfa_type, "captcha" %>
<%= hidden_field_tag :accountable_type, @accountable_type %>
<%= hidden_field_tag :account_id, @account_id %>
<%= hidden_field_tag :return_to, @return_to %>
<%= image_tag "data:image/png;base64,#{safe_captcha_image}", alt: t(".captcha_alt"), class: "max-w-full rounded-md" %>
<%= render DS::Button.new(text: t(".submit"), type: "submit") %>
<% end %>
<% end %>
<% end %>
<% end %>
<% end %>