{% extends "base.html" %}

{% block extra_head %}
<style>
  body {
    padding-bottom: calc(96px + env(safe-area-inset-bottom)) !important;
  }
  .mode-tabs {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 2px;
  }
  .mode-tabs::-webkit-scrollbar {
    display: none;
  }
  .mode-tab {
    border: 1px solid rgba(148, 163, 184, 0.25);
    background: rgba(255, 255, 255, 0.86);
    color: #334155;
    border-radius: 999px;
    padding: 7px 12px;
    font-size: 12px;
    white-space: nowrap;
  }
  [data-theme="dark"] .mode-tab {
    background: rgba(30, 41, 59, 0.8);
    color: #cbd5e1;
    border-color: rgba(148, 163, 184, 0.2);
  }
  .mode-tab.is-active {
    background: rgba(15, 23, 42, 0.92);
    color: #fff;
    border-color: rgba(15, 23, 42, 0.92);
  }
  [data-theme="dark"] .mode-tab.is-active {
    background: rgba(248, 250, 252, 0.95);
    color: #0f172a;
    border-color: rgba(248, 250, 252, 0.95);
  }
  .collection-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 2px 2px 4px;
  }
  .collection-nav-back {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: #475569;
    text-decoration: none;
    padding: 6px 8px;
    border-radius: 999px;
    border: 1px solid rgba(148, 163, 184, 0.25);
    background: rgba(255, 255, 255, 0.82);
  }
  .collection-nav-back svg {
    width: 14px;
    height: 14px;
  }
  .collection-nav-title {
    flex: 1;
    min-width: 0;
    text-align: right;
    font-size: 14px;
    font-weight: 700;
    color: #0f172a;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  [data-theme="dark"] .collection-nav-back {
    color: #cbd5e1;
    border-color: rgba(148, 163, 184, 0.2);
    background: rgba(30, 41, 59, 0.8);
  }
  [data-theme="dark"] .collection-nav-title {
    color: #f8fafc;
  }

  .masonry-grid {
    --wf-gap: 8px;
    display: flex;
    align-items: flex-start;
    gap: var(--wf-gap);
  }
  @media (min-width: 768px) {
    .masonry-grid { --wf-gap: 10px; }
  }
  .waterfall-col {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: var(--wf-gap);
  }
  .media-tile {
    border-radius: 12px;
    overflow: hidden;
    position: relative;
    background: #0b0f15;
    cursor: pointer;
  }
  .media-tile img {
    width: 100%;
    height: auto;
    display: block;
  }
  .media-tile video {
    width: 100%;
    height: auto;
    display: block;
    object-fit: cover;
    background: #000;
  }
  .tile-video-badge {
    position: absolute;
    right: 8px;
    bottom: 8px;
    width: 24px;
    height: 24px;
    border-radius: 999px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.52);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.28);
    pointer-events: none;
  }
  .library-loading {
    text-align: center;
    color: #64748b;
    font-size: 12px;
    padding: 16px 0 8px;
  }

  /* Quick Flow Viewer */
  #quick-view {
    position: fixed;
    inset: 0;
    z-index: 260;
    background: #000;
    display: none;
    overflow: hidden;
    touch-action: none;
  }
  #quick-view.active {
    display: block;
  }
  #quick-feed-layer {
    position: absolute;
    inset: 0;
  }
  .quick-media {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: none;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #000;
    z-index: 1;
    opacity: 0;
    transition: opacity 0.18s ease;
  }
  .quick-media.active {
    display: block;
    opacity: 1;
  }
  #quick-overlay {
    position: absolute;
    inset: 0;
    z-index: 10;
  }
  #quick-close-top {
    position: absolute;
    top: calc(12px + env(safe-area-inset-top));
    right: 12px;
    width: 42px;
    height: 42px;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.28);
    background: rgba(0, 0, 0, 0.5);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 40;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    transition: transform 0.15s ease, background 0.15s ease;
  }
  #quick-close-top:active {
    transform: scale(0.94);
    background: rgba(0, 0, 0, 0.66);
  }
  #quick-close-top svg {
    width: 18px;
    height: 18px;
  }
  .quick-counter {
    position: absolute;
    top: calc(14px + env(safe-area-inset-top));
    left: 12px;
    font-size: 12px;
    color: rgba(255, 255, 255, 0.94);
    background: rgba(0, 0, 0, 0.42);
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 999px;
    padding: 4px 10px;
    z-index: 30;
  }
  #quick-controls {
    position: absolute;
    left: 12px;
    right: 12px;
    bottom: calc(92px + env(safe-area-inset-bottom));
    height: 20px;
    display: flex;
    align-items: center;
    gap: 8px;
    z-index: 30;
    transition: opacity 0.2s ease, transform 0.2s ease;
  }
  #quick-controls.is-hidden {
    display: none;
  }
  .quick-time {
    color: rgba(255, 255, 255, 0.9);
    font-size: 11px;
    font-variant-numeric: tabular-nums;
    width: 38px;
    text-align: center;
  }
  .quick-progress-wrap {
    position: relative;
    flex: 1;
    height: 100%;
    display: flex;
    align-items: center;
  }
  #quick-progress {
    -webkit-appearance: none;
    position: absolute;
    width: 100%;
    height: 100%;
    opacity: 0;
    z-index: 2;
    cursor: pointer;
    margin: 0;
  }
  #quick-progress:disabled {
    cursor: default;
  }
  .quick-progress-track {
    position: absolute;
    left: 0;
    right: 0;
    height: 4px;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.2);
  }
  .quick-progress-fill {
    position: absolute;
    left: 0;
    height: 4px;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.95);
    width: 0%;
  }
  .quick-actions {
    position: absolute;
    right: 14px;
    bottom: calc(130px + env(safe-area-inset-bottom));
    display: flex;
    flex-direction: column;
    gap: 12px;
    z-index: 35;
    transition: opacity 0.2s ease, transform 0.2s ease;
  }
  .quick-btn {
    width: 46px;
    height: 46px;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.24);
    background: rgba(0, 0, 0, 0.5);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease;
    position: relative;
  }
  .quick-btn:active {
    transform: scale(0.92);
  }
  .quick-btn svg {
    width: 20px;
    height: 20px;
  }
  .quick-btn.is-favorited {
    background: rgba(239, 68, 68, 0.92);
    border-color: rgba(239, 68, 68, 0.96);
  }
  .quick-btn.is-active {
    background: rgba(255, 255, 255, 0.24);
    border-color: rgba(255, 255, 255, 0.78);
  }
  .quick-btn.is-hidden {
    display: none;
  }
  .quick-btn .collection-count {
    position: absolute;
    top: -6px;
    right: -6px;
    min-width: 18px;
    height: 18px;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.35);
    background: rgba(15, 23, 42, 0.9);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    line-height: 1;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
  }
  .quick-btn.has-collection {
    background: rgba(255, 255, 255, 0.24);
    border-color: rgba(255, 255, 255, 0.78);
  }
  .quick-btn.has-collection .collection-count {
    display: inline-flex;
  }
  #quick-speed {
    font-size: 14px;
    font-weight: 700;
    font-family: system-ui, -apple-system, sans-serif;
  }
  .quick-image-tool-wrap {
    position: relative;
  }
  .quick-zoom-options {
    position: absolute;
    right: 58px;
    bottom: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
    opacity: 0;
    pointer-events: none;
    transform: translateX(8px);
    transition: all 0.2s ease;
  }
  .quick-zoom-options.show {
    opacity: 1;
    pointer-events: auto;
    transform: translateX(0);
  }
  .quick-zoom-btn {
    width: 44px;
    height: 44px;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.16);
    background: rgba(0, 0, 0, 0.62);
    color: rgba(255, 255, 255, 0.75);
    font-size: 11px;
    font-weight: 700;
  }
  .quick-zoom-btn.active {
    background: rgba(255, 255, 255, 0.22);
    color: #fff;
    border-color: rgba(255, 255, 255, 0.78);
  }
  .quick-caption-panel {
    position: absolute;
    left: 16px;
    bottom: calc(114px + env(safe-area-inset-bottom));
    max-width: min(72vw, 420px);
    padding: 14px 16px;
    border-radius: 14px;
    background: rgba(0, 0, 0, 0.55);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: #fff;
    z-index: 32;
    display: flex;
    flex-direction: column;
    gap: 8px;
    backdrop-filter: blur(10px);
  }
  .quick-caption-panel.is-hidden {
    display: none;
  }
  .quick-caption-title {
    font-size: 14px;
    line-height: 1.4;
    font-weight: 600;
  }
  .quick-caption-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
  }
  .quick-caption-tag {
    display: inline-flex;
    align-items: center;
    padding: 4px 8px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.15);
    font-size: 11px;
    color: rgba(255, 255, 255, 0.86);
  }
  #quick-caption.is-loading::after {
    content: '';
    position: absolute;
    inset: 7px;
    border-radius: 999px;
    border: 1.5px solid rgba(255, 255, 255, 0.7);
    border-top-color: transparent;
    animation: quick-caption-spin 0.9s linear infinite;
  }
  #quick-caption {
    position: relative;
  }
  #quick-caption.is-loading i {
    opacity: 0.35;
  }
  #quick-caption.is-error::after {
    content: '';
    position: absolute;
    inset: 7px;
    border-radius: 999px;
    border: 1.5px solid rgba(248, 113, 113, 0.9);
  }
  @keyframes quick-caption-spin {
    to { transform: rotate(360deg); }
  }
  .quick-magnifier {
    position: absolute;
    width: 220px;
    height: 220px;
    border-radius: 50%;
    border: 3px solid rgba(255, 255, 255, 0.9);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
    background-repeat: no-repeat;
    background-color: #000;
    cursor: grab;
    z-index: 45;
    display: none;
    transform: translate(-50%, -50%) scale(0);
    transition: transform 0.2s ease, width 0.2s ease, height 0.2s ease;
  }
  .quick-magnifier.quick-magnifier-large {
    width: 300px;
    height: 300px;
  }
  .quick-magnifier.active {
    display: block;
    transform: translate(-50%, -50%) scale(1);
  }
  #quick-play-status {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(1);
    width: 78px;
    height: 78px;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.46);
    border: 1px solid rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    z-index: 28;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.16s ease, transform 0.16s ease;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
  }
  #quick-play-status.visible {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.08);
  }
  #quick-play-status svg {
    width: 38px;
    height: 38px;
    fill: currentColor;
    stroke: none;
  }
  .quick-mag-badge {
    position: absolute;
    left: 50%;
    bottom: 10px;
    transform: translateX(-50%);
    border-radius: 10px;
    padding: 2px 6px;
    font-size: 10px;
    color: #fff;
    background: rgba(0, 0, 0, 0.55);
  }
  #quick-view.immersive .quick-actions,
  #quick-view.immersive #quick-controls,
  #quick-view.immersive .quick-counter,
  #quick-view.immersive .quick-caption-panel {
    opacity: 0;
    pointer-events: none;
    transform: translateY(10px);
  }

  .quick-collection-modal {
    position: fixed;
    inset: 0;
    z-index: 280;
    background: rgba(15, 23, 42, 0.56);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s;
  }
  .quick-collection-modal.active {
    opacity: 1;
    pointer-events: auto;
  }
  .quick-collection-card {
    width: min(440px, 100%);
    border-radius: 14px;
    border: 1px solid rgba(148, 163, 184, 0.28);
    background: rgba(255, 255, 255, 0.98);
    color: #0f172a;
    box-shadow: 0 24px 80px rgba(15, 23, 42, 0.3);
    padding: 12px;
    transform: translateY(20px);
    transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
  }
  .quick-collection-modal.active .quick-collection-card {
    transform: translateY(0);
  }
  [data-theme="dark"] .quick-collection-card {
    background: rgba(15, 23, 42, 0.98);
    border-color: rgba(148, 163, 184, 0.2);
    color: #f8fafc;
  }
  .quick-collection-header {
    margin-bottom: 10px;
  }
  .quick-collection-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
  .quick-collection-header h3 {
    font-size: 14px;
    font-weight: 700;
  }
  .quick-collection-meta {
    margin-top: 4px;
    font-size: 11px;
    color: #64748b;
  }
  [data-theme="dark"] .quick-collection-meta {
    color: #94a3b8;
  }
  .quick-collection-close {
    width: 30px;
    height: 30px;
    border-radius: 999px;
    border: 1px solid rgba(148, 163, 184, 0.28);
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .quick-collection-close svg {
    width: 15px;
    height: 15px;
  }
  .quick-collection-create {
    display: flex;
    gap: 8px;
    margin-top: 10px;
  }
  .quick-collection-create input {
    flex: 1;
    min-width: 0;
    border-radius: 10px;
    border: 1px solid rgba(148, 163, 184, 0.32);
    background: rgba(248, 250, 252, 0.86);
    color: #0f172a;
    font-size: 13px;
    padding: 8px 10px;
  }
  [data-theme="dark"] .quick-collection-create input {
    background: rgba(15, 23, 42, 0.82);
    color: #f1f5f9;
    border-color: rgba(148, 163, 184, 0.2);
  }
  .quick-collection-create button {
    border-radius: 10px;
    border: 1px solid rgba(148, 163, 184, 0.3);
    background: rgba(15, 23, 42, 0.9);
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    padding: 8px 12px;
  }
  [data-theme="dark"] .quick-collection-create button {
    background: rgba(226, 232, 240, 0.94);
    color: #0f172a;
  }
  .quick-collection-list {
    max-height: min(44vh, 320px);
    overflow: auto;
    border: 1px solid rgba(148, 163, 184, 0.24);
    border-radius: 10px;
    padding: 4px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    background: rgba(248, 250, 252, 0.78);
  }
  [data-theme="dark"] .quick-collection-list {
    background: rgba(15, 23, 42, 0.76);
    border-color: rgba(148, 163, 184, 0.2);
  }
  .quick-collection-item {
    border-radius: 8px;
    padding: 8px 10px;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    border: 1px solid transparent;
  }
  .quick-collection-item:hover {
    background: rgba(148, 163, 184, 0.12);
  }
  .quick-collection-item.is-pending {
    opacity: 0.6;
    pointer-events: none;
  }
  .quick-collection-item.is-selected {
    background: rgba(99, 102, 241, 0.07);
  }
  .quick-collection-item input[type="checkbox"] {
    position: absolute; opacity: 0; width: 0; height: 0;
  }
  .quick-collection-item span.coll-name {
    flex: 1;
    min-width: 0;
    font-size: 13px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .quick-collection-item .coll-icon {
    width: 28px; height: 28px;
    border-radius: 6px;
    background: rgba(148, 163, 184, 0.12);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; color: #64748b;
  }
  .quick-collection-item .coll-check {
    width: 20px; height: 20px;
    border-radius: 50%;
    border: 1.5px solid rgba(148, 163, 184, 0.45);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s, border-color 0.15s;
  }
  .quick-collection-item .coll-check svg { display: none; color: white; }
  .quick-collection-item.is-selected .coll-check {
    background: #6366f1;
    border-color: #6366f1;
  }
  .quick-collection-item.is-selected .coll-check svg { display: block; }
  .quick-collection-empty {
    text-align: center;
    font-size: 12px;
    color: #64748b;
    padding: 14px 8px;
  }
  [data-theme="dark"] .quick-collection-empty {
    color: #94a3b8;
  }
  .coll-drag-handle {
    width: 36px; height: 4px;
    border-radius: 2px;
    background: rgba(148, 163, 184, 0.35);
    margin: 12px auto 16px;
    display: none;
  }
  @media (max-width: 540px) {
    .quick-collection-modal {
      align-items: flex-end;
      padding: 0;
    }
    .quick-collection-card {
      width: 100%;
      border-radius: 20px 20px 0 0;
      transform: translateY(100%);
      padding: 0 12px 24px;
    }
    .quick-collection-modal.active .quick-collection-card {
      transform: translateY(0);
    }
    .coll-drag-handle { display: block; }
  }
</style>
{% endblock %}

{% block content %}
<main class="container mx-auto px-2 pt-2 pb-1 md:px-3">
  {% if scope == 'all' %}
  <section class="mb-2">
    <div class="mode-tabs" id="mode-tabs">
      <button type="button" class="mode-tab" data-mode="all">全部</button>
      <button type="button" class="mode-tab" data-mode="image_random">图片随机</button>
      <button type="button" class="mode-tab" data-mode="video_latest">视频最新</button>
      <button type="button" class="mode-tab" data-mode="big_files">大文件</button>
    </div>
  </section>
  {% elif scope == 'favorite' %}
  <section class="mb-2">
    <div class="mode-tabs">
      <a class="mode-tab is-active" href="/favorite">收藏媒体</a>
      <a class="mode-tab" href="/collections">我的集合</a>
    </div>
  </section>
  {% elif scope == 'collection' %}
  <section class="mb-2">
    <div class="collection-nav">
      <a class="collection-nav-back" href="/collections">
        <i data-feather="arrow-left"></i>
        <span>我的集合</span>
      </a>
      <div class="collection-nav-title">{{ collection_name }}</div>
    </div>
  </section>
  {% endif %}

  <section id="library-grid" class="masonry-grid"></section>
  <div id="library-loading" class="library-loading">正在加载...</div>
  <div id="library-sentinel" style="height: 1px;"></div>
</main>

<div id="quick-view" aria-hidden="true">
  <div id="quick-feed-layer">
    <video id="quick-video" class="quick-media" playsinline preload="metadata"></video>
    <img id="quick-image" class="quick-media" alt="" />
    <div id="quick-overlay"></div>
    <div id="quick-play-status" aria-hidden="true">
      <svg id="quick-play-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><polygon points="5 3 19 12 5 21 5 3"></polygon></svg>
    </div>
  </div>

  <button id="quick-close-top" type="button" title="关闭">
    <i data-feather="x"></i>
  </button>
  <div class="quick-counter" id="quick-counter">1 / 1</div>

  <div id="quick-controls" class="is-hidden">
    <span class="quick-time" id="quick-time-current">00:00</span>
    <div class="quick-progress-wrap">
      <input type="range" id="quick-progress" min="0" max="100" step="0.1" value="0" />
      <div class="quick-progress-track"></div>
      <div class="quick-progress-fill" id="quick-progress-fill"></div>
    </div>
    <span class="quick-time" id="quick-time-total">00:00</span>
  </div>

  <div class="quick-actions">
    <button id="quick-speed" class="quick-btn" type="button" title="倍速">1x</button>
    <button id="quick-caption" class="quick-btn" type="button" title="生成标题" hidden>
      <i data-feather="zap"></i>
    </button>

    <div class="quick-image-tool-wrap" id="quick-magnifier-tool-wrap" hidden>
      <div class="quick-zoom-options" id="quick-zoom-options">
        <button type="button" class="quick-zoom-btn active" data-level="2.5">2.5x</button>
        <button type="button" class="quick-zoom-btn" data-level="5">5x</button>
      </div>
      <button id="quick-magnifier-toggle" class="quick-btn" type="button" title="放大镜">
        <i data-feather="search"></i>
      </button>
    </div>

    <button id="quick-favorite" class="quick-btn" type="button" title="收藏">
      <i data-feather="heart"></i>
    </button>
    <button id="quick-collection" class="quick-btn" type="button" title="加入集合">
      <i data-feather="bookmark"></i>
      <span class="collection-count" id="quick-collection-count">0</span>
    </button>
    <button id="quick-set-cover" class="quick-btn is-hidden" type="button" title="设为集合封面">
      <i data-feather="image"></i>
    </button>
    <a id="quick-source" class="quick-btn is-hidden" href="#" target="_blank" rel="noopener noreferrer" title="查看来源">
      <i data-feather="external-link"></i>
    </a>
    <a id="quick-detail" class="quick-btn" href="#" title="查看详情">
      <i data-feather="info"></i>
    </a>
  </div>

  <div class="quick-caption-panel is-hidden" id="quick-caption-panel">
    <div class="quick-caption-title" id="quick-caption-title"></div>
    <div class="quick-caption-tags" id="quick-caption-tags"></div>
  </div>

  <div class="quick-magnifier" id="quick-magnifier">
    <div class="quick-mag-badge" id="quick-mag-badge">2.5x</div>
  </div>
</div>

<div id="quick-collection-modal" class="quick-collection-modal" aria-hidden="true">
  <div class="quick-collection-card">
    <div class="coll-drag-handle"></div>
    <div class="quick-collection-header">
      <div class="quick-collection-title-row">
        <h3>加入集合</h3>
        <button id="quick-collection-close" type="button" class="quick-collection-close">
          <i data-feather="x"></i>
        </button>
      </div>
      <div id="quick-collection-meta" class="quick-collection-meta">当前未加入任何集合</div>
    </div>
    <div id="quick-collection-list" class="quick-collection-list"></div>
    <div class="quick-collection-create">
      <input id="quick-collection-name" type="text" maxlength="80" placeholder="新建集合名称" />
      <button id="quick-collection-create-btn" type="button">新建</button>
    </div>
  </div>
</div>
{% endblock %}

{% block extra_body %}
<script src="{{ url_for('static', filename='flow_ui_shared.js') }}"></script>
<script src="{{ url_for('static', filename='flow_state_controller.js') }}"></script>
<script src="{{ url_for('static', filename='flow_session.js') }}"></script>
<script src="{{ url_for('static', filename='flow_actions_shared.js') }}"></script>
<script src="{{ url_for('static', filename='flow_media_actions_controller.js') }}"></script>
<script src="{{ url_for('static', filename='hammer.min.js') }}"></script>
<script>
  window.__TIKLOCAL_LIBRARY_BOOT__ = {
    scope: {{ scope | tojson }},
    collectionId: {{ collection_id | tojson }},
    pageSize: {{ page_size }},
    initialItems: {{ initial_items | tojson }},
    initialHasMore: {{ 'true' if initial_has_more else 'false' }},
    initialNextOffset: {{ initial_next_offset }},
    initialMode: {{ active_mode | tojson }},
    initialSeed: {{ mode_seed | tojson }},
    minMb: {{ min_mb }},
    emptyMessage: {{ empty_message | tojson }},
  };
</script>
<script src="{{ url_for('static', filename='library_page_controller.js') }}"></script>
{% endblock %}
