{% extends "base.html" %}
{% block content %}
 
<div class="content-cloak">
  <form id="form_search" class="form-inline" style="text-align:left">
    <div class="container-fluid">
      <div class="row show-grid">
        <span class="col-md-4">
          <select id="order" name="order" class="form-control form-control-sm">
            <option value="desc">최근순</option>
            <option value="asc">오래된순</option>
          </select>
          <select id="option" name="option" class="form-control form-control-sm">
            <option value="all">전체</option>
            <option value="completed">완료</option>
          </select>
        </span>
        <span class="col-md-8">
          <input id="search_word" name="search_word" class="form-control form-control-sm w-75" type="text" placeholder="" aria-label="Search">
          <button id="search" class="btn btn-sm btn-outline-success">검색</button>
          <button id="reset_btn" class="btn btn-sm btn-outline-success">리셋</button>
        </span>
      </div>
    </div>
  </form>
  <div id='page1'></div>
  {{ macros.m_hr_head_top() }}
  {{ macros.m_row_start('0') }}
  {{ macros.m_col(2,  macros.m_strong('Poster')) }}
  {{ macros.m_col(10,  macros.m_strong('Info')) }}
  {{ macros.m_row_end() }}
  {{ macros.m_hr_head_bottom() }}
  <div id="list_div"></div>
  <div id='page2'></div>
</div>

<script type="text/javascript">
var package_name = "{{arg['package_name']}}";
var sub = "{{arg['sub']}}";
var current_data = null;

$(document).ready(function(){
  global_sub_request_search('1');
});

$("#search").click(function(e) {
  e.preventDefault();
  global_sub_request_search('1');
});

$("body").on('click', '#page', function(e){
  e.preventDefault();
  global_sub_request_search($(this).data('page'));
});

$("#reset_btn").click(function(e) {
  e.preventDefault();
  document.getElementById("order").value = 'desc';
  document.getElementById("option").value = 'all';
  document.getElementById("search_word").value = '';
  global_sub_request_search('1')
});


$("body").on('click', '#json_btn', function(e){
  e.preventDefault();
  var id = $(this).data('id');
  for (i in current_data.list) {
    if (current_data.list[i].id == id) {
      m_modal(current_data.list[i])
    }
  }
});

$("body").on('click', '#self_search_btn', function(e){
  e.preventDefault();
  var search_word = $(this).data('title');
  document.getElementById("search_word").value = search_word;
  global_sub_request_search('1')
});

$("body").on('click', '#remove_btn', function(e) {
  e.preventDefault();
  id = $(this).data('id');
  $.ajax({
    url: '/'+package_name+'/ajax/'+sub+ '/db_remove',
    type: "POST", 
    cache: false,
    data: {id:id},
    dataType: "json",
    success: function (data) {
      if (data) {
        $.notify('<strong>삭제되었습니다.</strong>', {
          type: 'success'
        });
        global_sub_request_search(current_data.paging.current_page, false)
      } else {
        $.notify('<strong>삭제 실패</strong>', {
          type: 'warning'
        });
      }
    }
  });
});

$("body").on('click', '#request_btn', function(e){
  e.preventDefault();
  var content_code = $(this).data('content_code');
  $(location).attr('href', '/' + package_name + '/' + sub + '/request?content_code=' + content_code)
});



function make_list(data) {
  //console.log(data)
  str = '';
  for (i in data) {
    //console.log(data[i])
    str += m_row_start();
    str += m_col(1, data[i].id);
    tmp = (data[i].status == 'completed') ? '완료' : '미완료';
    str += m_col(1, tmp);
    tmp = data[i].created_time + '(추가)';
    if (data[i].completed_time != null)
      tmp += data[i].completed_time + '(완료)';
    str += m_col(3, tmp)
    tmp = data[i].savepath + '<br>' + data[i].filename + '<br><br>';
    tmp2 = m_button('json_btn', 'JSON', [{'key':'id', 'value':data[i].id}]);
    tmp2 += m_button('request_btn', '작품 검색', [{'key':'content_code', 'value':data[i].content_code}]);
    tmp2 += m_button('self_search_btn', '목록 검색', [{'key':'title', 'value':data[i].title}]);
    tmp2 += m_button('remove_btn', '삭제', [{'key':'id', 'value':data[i].id}]);
    tmp += m_button_group(tmp2)
    str += m_col(7, tmp)
    str += m_row_end();
    if (i != data.length -1) str += m_hr();
  }
  document.getElementById("list_div").innerHTML = str;
}




</script>    
<style>
    /* Navigation Menu Override */
    ul.nav.nav-pills.bg-light {
        background-color: rgba(30, 41, 59, 0.6) !important;
        backdrop-filter: blur(10px);
        border: 1px solid rgba(255, 255, 255, 0.08);
        border-radius: 50rem !important;
        padding: 6px !important;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2) !important;
        display: inline-flex !important;
        flex-wrap: wrap;
        justify-content: center;
        width: auto !important;
        margin-bottom: 20px;
    }

    ul.nav.nav-pills .nav-item {
        margin: 0 2px;
    }

    ul.nav.nav-pills .nav-link {
        border-radius: 50rem !important;
        padding: 8px 20px !important;
        color: #94a3b8 !important;
        font-weight: 600;
        transition: all 0.3s ease;
    }

    ul.nav.nav-pills .nav-link:hover {
        background-color: rgba(255, 255, 255, 0.1);
        color: #fff !important;
        transform: translateY(-1px);
    }

    ul.nav.nav-pills .nav-link.active {
        background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%) !important;
        color: #fff !important;
        box-shadow: 0 4px 12px rgba(37, 99, 235, 0.4);
    }
</style>

<style>
    /* Smooth Load Transition */
    .content-cloak, 
    #menu_module_div, 
    #menu_page_div {
        opacity: 0;
        transition: opacity 0.5s ease-out;
    }
    
    /* Staggered Delays for Natural Top-Down Flow */
    #menu_module_div.visible {
        opacity: 1;
        transition-delay: 0ms;
    }

    #menu_page_div.visible {
        opacity: 1;
        transition-delay: 150ms;
    }

    .content-cloak.visible {
        opacity: 1;
        transition-delay: 300ms;
    }
    
    /* Navigation Menu Override (Top Sub-menu) */
    ul.nav.nav-pills.bg-light {
        background-color: rgba(30, 41, 59, 0.6) !important;
        backdrop-filter: blur(10px);
        border: 1px solid rgba(255, 255, 255, 0.08);
        border-radius: 50rem !important;
        padding: 6px !important;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2) !important;
        display: inline-flex !important;
        flex-wrap: wrap;
        justify-content: center;
        width: auto !important;
        margin-bottom: 20px;
    }

    ul.nav.nav-pills .nav-item { margin: 0 2px; }
    ul.nav.nav-pills .nav-link {
        border-radius: 50rem !important;
        padding: 8px 20px !important;
        color: #94a3b8 !important;
        font-weight: 600;
        transition: all 0.3s ease;
    }
    ul.nav.nav-pills .nav-link:hover {
        background-color: rgba(255, 255, 255, 0.1);
        color: #fff !important;
        transform: translateY(-1px);
    }
    ul.nav.nav-pills .nav-link.active {
        background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%) !important;
        color: #fff !important;
        box-shadow: 0 4px 12px rgba(37, 99, 235, 0.4);
    }
</style>

<script type="text/javascript">
$(document).ready(function(){
  // Smooth Load Trigger
  setTimeout(function() {
      $('.content-cloak, #menu_module_div, #menu_page_div').addClass('visible');
  }, 100);
});
</script>
<style>
/* Mobile Margin Fix */
@media (max-width: 768px) {
    body { overflow-x: hidden !important; padding: 0 !important; margin: 0 !important; }
    .container, .container-fluid, .row, form, #program_list, #program_auto_form, #episode_list, .queue-container, #yommi_wrapper, #main_container {
        width: 100% !important; max-width: 100% !important;
        padding-left: 4px !important; padding-right: 4px !important;
        margin-left: 0 !important; margin-right: 0 !important;
        box-sizing: border-box !important;
    }
    .form-group, .form-inline, [class*="col-"] {
        flex: 0 0 100% !important; max-width: 100% !important; width: 100% !important;
        padding-left: 0 !important; padding-right: 0 !important;
    }
    .row { margin-left: 0 !important; margin-right: 0 !important; }
    .card, .card.p-4, .card.p-lg-5, .card.border-light {
         width: calc(100% - 8px) !important; max-width: 100% !important;
         padding: 8px !important; margin: 4px !important;
         border-radius: 12px !important; box-sizing: border-box !important;
    }
    .badge {
        white-space: normal !important; text-align: left !important;
        line-height: 1.4 !important; height: auto !important; display: inline-block !important;
    }
}
</style>
{% endblock %}