<%= turbo_frame_tag :result do %>

<h1><%= t('views.user_menu.address_books') %></h1>

<div class="table-address-search-u" data-turbo="true">
  <%= form_with(url: {action: :index_sub}, id: :search_form, method: :get, data: {turbo: true, turbo_frame: :result}) do %>
    <%= select_tag('conditions[search_select]', options_for_select(
                   { t('activerecord.attributes.address_book.organization') => 'organization',
                     t('activerecord.attributes.address_book.name') => 'name',
                     t('activerecord.attributes.address_book.email') => 'email' },
                   params[:conditions][:search_select]),
                   include_blank: true) %>
              &nbsp;
    <%= text_field_tag 'conditions[search_text]', params[:conditions][:search_text], { size: 30 } %>
    <%= submit_tag(t('address_books.search_button'), id: 'search_form_submit') %>

    <span id="search_progress"></span>
    <div class="table-address-search-d">
      表示順序：
      <%= select_tag('conditions[sort_select_1]', options_for_select(
          { t('activerecord.attributes.address_book.organization') => 'organization',
            t('activerecord.attributes.address_book.name') => 'name',
            t('activerecord.attributes.address_book.email') => 'email' }, params[:conditions][:sort_select_1])) %>

      <%= select_tag('conditions[sort_select_2]', options_for_select(
          { t('views.sort.asc') => 'asc',
            t('views.sort.desc') => 'desc'},
          params[:conditions][:sort_select_2])) %>
      <%= hidden_field_tag "recipient_number", params[:recipient_number], id: :recipient_number %>
      <%= hidden_field_tag "page", params[:page], id: :page %>
      &nbsp;&nbsp;
      <%= label_tag 'conditions_organization_flg', '組織名を入れる：' %>
      <%#= hidden_field_tag('conditions[organization_flg]', false, id: "none_conditions_organization_flg") %>
      <%= check_box_tag 'conditions[organization_flg]', true, params[:conditions][:organization_flg], { id: 'conditions_organization_flg' } %>
    </div>
  <% end %>
</div>

<div id="result">
  <%= render "index_sub_result" %>
</div>

<script type="text/javascript">
(function() {
  // 検索ボタン押下時はページをリセット
  document.getElementById("search_form_submit").addEventListener('click', function(e) {
    if (e.isTrusted) {
      document.getElementById("page").value = "";
    }
  });
  // ソート
  document.querySelectorAll("#conditions_sort_select_1, #conditions_sort_select_2").forEach(function(el) {
    el.addEventListener('change', function() {
      document.getElementById("search_form_submit").click();
    });
  });
  // 組織名を入れるチェックボックス
  document.getElementById("conditions_organization_flg").addEventListener('change', function() {
    document.getElementById("search_form_submit").click();
  });
})();

function close_address_modal() {
  $.modal.close();
}

</script>
<% end %>
