<h2><%= t('users.notifications.title') %></h2>

<%= form_with(model: @user, url: update_notification_settings_user_path(@user), method: :PATCH, data: { turbo: true }) do |f| %>

  <p><%= t('users.notifications.intro', site_name:) %></p>

  <% if @user.any_email_notifications? %>
    <%= f.submit t('users.notifications.unsubscribe_email'), formaction: unsubscribe_email_user_path(@user) %>
  <% end %>

  <% if @user.subscribed_to_anything? %>
    <%= f.submit t('users.notifications.unsubscribe_all'), formaction: unsubscribe_all_user_path(@user) %>
  <% end %>

  <hr>

  <div class="form-control">
    <h3><%= t('users.notifications.discussion_defaults.title') %></h3>

    <p><%= t('users.notifications.discussion_defaults.intro') %></p>

    <% if @user.discussion_subscriptions.any? %>
      <div class="form-control">
        <%= check_box_tag :unsubscribe_all_discussions, '1' %>
        <%= label_tag :unsubscribe_all_discussions, it('users.notifications.current_discussion_subscriptions', count: @user.discussion_subscriptions.count, discussions_link: discussions_path(me: 'subscribed')), class: 'radio-label' %>
      </div>
    <% end %>

    <%= label_tag t('users.notifications.discussion_defaults.discussion_subscription_defaults.overall_label') %>
    <div class="form-control">
      <div>
        <%= f.check_box :subscribe_on_discussion %>
        <%= f.label :subscribe_on_discussion, t('users.notifications.discussion_defaults.discussion_subscription_defaults.start'), class: 'radio-label' %>
      </div>
      <div>
        <%= f.check_box :subscribe_on_comment %>
        <%= f.label :subscribe_on_comment, t('users.notifications.discussion_defaults.discussion_subscription_defaults.comment'), class: 'radio-label' %>
      </div>
      <div>
        <%= f.check_box :subscribe_on_script_discussion %>
        <%= f.label :subscribe_on_script_discussion, t('users.notifications.discussion_defaults.discussion_subscription_defaults.script'), class: 'radio-label' %>
      </div>
    </div>

    <%= label_tag t('users.notifications.discussion_defaults.subscribed_discussion_notification') %>
    <%= render partial: 'notification_setting_checkboxes', locals: { current_settings: @notification_settings, notification_type: Notification::NOTIFICATION_TYPE_NEW_COMMENT } %>

    <%= label_tag t('users.notifications.discussion_defaults.mention') %>
    <%= render partial: 'notification_setting_checkboxes', locals: { current_settings: @notification_settings, notification_type: Notification::NOTIFICATION_TYPE_MENTION } %>
  </div>

  <hr>

  <div class="form-control">
    <h3><%= t('users.notifications.conversation_defaults.title') %></h3>

    <p><%= t('users.notifications.conversation_defaults.intro') %></p>

    <% if @user.conversation_subscriptions.any? %>
      <div class="form-control">
        <%= check_box_tag :unsubscribe_all_conversations, '1' %>
        <%= label_tag :unsubscribe_all_conversations, it('users.notifications.current_conversation_subscriptions', count: @user.conversation_subscriptions.count), class: 'radio-label' %>
      </div>
    <% end %>

    <%= label_tag t('users.notifications.conversation_defaults.new_conversation_subscription.overall_label') %>
    <div class="form-control">
      <div>
        <%= f.check_box :subscribe_on_conversation_starter %>
        <%= f.label :subscribe_on_conversation_starter, t('users.notifications.conversation_defaults.new_conversation_subscription.self'), class: 'radio-label' %>
      </div>
      <div>
        <%= f.check_box :subscribe_on_conversation_receiver %>
        <%= f.label :subscribe_on_conversation_receiver, t('users.notifications.conversation_defaults.new_conversation_subscription.other'), class: 'radio-label' %>
      </div>
    </div>

    <%= label_tag t('users.notifications.conversation_defaults.new_conversation_notification') %>
    <%= render partial: 'notification_setting_checkboxes', locals: { current_settings: @notification_settings, notification_type: Notification::NOTIFICATION_TYPE_NEW_CONVERSATION } %>

    <%= label_tag t('users.notifications.conversation_defaults.new_message_notification') %>
    <%= render partial: 'notification_setting_checkboxes', locals: { current_settings: @notification_settings, notification_type: Notification::NOTIFICATION_TYPE_NEW_MESSAGE } %>
  </div>

  <hr>

  <div class="form-control">
    <h3><%= t('users.notifications.report_defaults.title') %></h3>

    <p><%= t('users.notifications.report_defaults.intro', site_name:) %></p>

    <%= label_tag t('users.notifications.report_defaults.as_reporter') %>
    <%= render partial: 'notification_setting_checkboxes', locals: { current_settings: @notification_settings, notification_type: Notification::NOTIFICATION_TYPE_REPORT_RESOLVED_REPORTER } %>

    <%= label_tag t('users.notifications.report_defaults.as_reported_filed') %>
    <%= render partial: 'notification_setting_checkboxes', locals: { current_settings: @notification_settings, notification_type: Notification::NOTIFICATION_TYPE_REPORT_FILED_REPORTED } %>

    <%= label_tag t('users.notifications.report_defaults.as_reported_resolved') %>
    <%= render partial: 'notification_setting_checkboxes', locals: { current_settings: @notification_settings, notification_type: Notification::NOTIFICATION_TYPE_REPORT_RESOLVED_REPORTED } %>
  </div>

  <hr>

  <div class="form-control">
    <h3><%= t('users.notifications.script.title') %></h3>

    <p><%= t('users.notifications.script.intro', site_name:) %></p>

    <%= label_tag t('users.notifications.script.consecutive_bad_ratings') %>
    <%= render partial: 'notification_setting_checkboxes', locals: { current_settings: @notification_settings, notification_type: Notification::NOTIFICATION_TYPE_CONSECUTIVE_BAD_RATINGS } %>
  </div>

  <hr>

  <div>
    <%= f.submit t('users.notifications.save_button') %>
  </div>
<% end %>
