<%
  define_admin_breadcrumbs do
    add_admin_breadcrumb('广告栏')
  end
%>

<div class="card mb-5 adverts-card">
  <div class="card-header d-flex justify-content-between align-items-center">
    <span class="flex-1">广告栏</span>
    <%= javascript_void_link '添加', class: 'btn btn-primary btn-sm add-btn', data: { toggle: 'modal', target: '.admin-add-weapp-advert-modal' } %>
  </div>
  <div class="card-body row" id="adverts-container">
    <% @adverts.each_with_index do |advert, index| %>
      <div class="col-12 advert-item advert-item-<%= advert.id %>" data-id="<%= advert.id %>">
        <div class="border rounded relative p-3 mb-3 drag row align-items-center <%= advert.online? ? '' : 'not_active' %>">
          <div class="col-2 col-md-1 advert-item-no"><%= index + 1 %></div>
          <div class="col-10 col-md-3 advert-item-img" data-source-id="<%= advert.id %>" data-source-type="WeappSettings::Advert" data-toggle="modal" data-target=".admin-upload-file-modal">
            <img src="<%= Util::FileManage.exists?(advert) ? Util::FileManage.source_disk_file_url(advert) : '' %>" data-toggle="tooltip" data-title="重新上传"/>
          </div>
          <div class="col-10 col-md-7">
            <div class="input-group">
              <input type="text" value="<%= advert.link %>" class="form-control link-input" placeholder="请输入跳转地址">
              <div class="input-group-prepend">
                <button class="input-group-text save-data-btn" data-id="<%= advert.id %>">保存</button>
              </div>
            </div>
          </div>
          <div class="col-2 col-md-1 operate-box">
            <%= check_box_tag(:online, 1, advert.online?, id: nil, class: 'online-check-box', data: { id: advert.id, toggle: 'tooltip', title: '首页展示' }) %>
            <%= delete_link '删除', admins_weapp_advert_path(advert, element: ".advert-item-#{advert.id}", not_refresh: true), class: 'delete-btn' do %>
              <i class="fa fa-trash-o" data-id="<%= advert.id %>"></i>
            <% end %>
          </div>
        </div>
      </div>
    <% end %>
  </div>
</div>


<%= render partial: 'admins/weapp_adverts/shared/add_weapp_advert_modal' %>
<%= render partial: 'admins/shared/modal/upload_file_modal' %>