<?php
// app/views/pages/index.php

$toolbarLeftHtml = '';
$toolbarRightHtml = '';
$showQueueSummary = true;
?>
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title data-i18n="app.title"><?php echo htmlspecialchars($t('app.title', 'scMedia'), ENT_QUOTES); ?></title>
  <link rel="stylesheet" href="/assets/css/common.css">
  <link rel="stylesheet" href="/assets/css/style.css">
</head>
<body>
  <?php
  require __DIR__ . '/../partials/header.php';
  ?>

  <!-- ================= MAIN GRID ================= -->
  <main class="main">
    <div class="media-tabs" id="media-tabs">
      <button class="tab active" data-tab="movies" data-i18n="media.tabs.movies"><?php echo htmlspecialchars($t('media.tabs.movies', 'Movies'), ENT_QUOTES); ?></button>
      <button class="tab" data-tab="series" data-i18n="media.tabs.series"><?php echo htmlspecialchars($t('media.tabs.series', 'Series'), ENT_QUOTES); ?></button>
      <button class="tab" data-tab="sources" data-i18n="media.tabs.sources"><?php echo htmlspecialchars($t('media.tabs.sources', 'Sources'), ENT_QUOTES); ?></button>
    </div>
    <?php
    $id = 'grid';
    $tableClass = 'grid data-table';
    $wrapClass = 'media-table';
    $headers = [
      ['label' => '', 'i18n' => '', 'key' => '', 'filter' => null],
      ['label' => $t('grid.type', 'Type'), 'i18n' => 'grid.type', 'key' => 'type', 'filter' => ['type' => 'text', 'ops' => ['like','eq']]],
      ['label' => $t('grid.name', 'Name'), 'i18n' => 'grid.name', 'sort' => 'name', 'key' => 'name', 'filter' => ['type' => 'text', 'ops' => ['like','eq','empty']]],
      ['label' => $t('grid.year', 'Year'), 'i18n' => 'grid.year', 'key' => 'year', 'filter' => ['type' => 'number', 'ops' => ['eq','between','gt','lt']]],
      ['label' => $t('grid.status', 'Status'), 'i18n' => 'grid.status', 'key' => 'status', 'filter' => ['type' => 'text', 'ops' => ['like','eq']]],
      ['label' => $t('grid.issues', 'Issues'), 'i18n' => 'grid.issues', 'key' => 'issues', 'filter' => ['type' => 'text', 'ops' => ['like','eq','empty']]],
    ];
    $attrs = ['data-table' => 'media'];
    require __DIR__ . '/../partials/table.php';
    ?>
    <?php
    $id = 'sources-grid';
    $tableClass = 'grid data-table';
    $wrapClass = 'media-table is-hidden';
    $headers = [
      ['label' => $t('sources.source', 'Source'), 'i18n' => 'sources.source', 'key' => 'source', 'filter' => ['type' => 'select', 'control' => 'select', 'options' => [
        ['value' => 'transmission', 'label' => 'Transmission'],
      ]]],
      ['label' => $t('sources.type', 'Type'), 'i18n' => 'sources.type', 'key' => 'type', 'filter' => ['type' => 'select', 'control' => 'select', 'options' => [
        ['value' => 'folder', 'label' => $t('sources.type.folder', 'Folder'), 'i18n' => 'sources.type.folder'],
        ['value' => 'file', 'label' => $t('sources.type.file', 'File'), 'i18n' => 'sources.type.file'],
      ]]],
      ['label' => $t('sources.name', 'Name'), 'i18n' => 'sources.name', 'sort' => 'name', 'key' => 'name', 'filter' => ['type' => 'text', 'ops' => ['like','eq','empty']]],
      ['label' => $t('sources.size', 'Size'), 'i18n' => 'sources.size', 'sort' => 'size', 'class' => 'align-right', 'key' => 'size', 'filter' => null],
      ['label' => $t('sources.status', 'Status'), 'i18n' => 'sources.status', 'sort' => 'status', 'class' => 'align-center', 'key' => 'status', 'filter' => ['type' => 'select', 'control' => 'select', 'options' => [
        ['value' => 'checking', 'label' => 'checking', 'i18n' => 'sources.status.checking'],
        ['value' => 'queued', 'label' => 'queued', 'i18n' => 'sources.status.queued'],
        ['value' => 'downloading', 'label' => $t('sources.status.downloading', 'downloading'), 'i18n' => 'sources.status.downloading'],
        ['value' => 'seeding', 'label' => $t('sources.status.seeding', 'seeding'), 'i18n' => 'sources.status.seeding'],
        ['value' => 'stopped', 'label' => $t('sources.status.stopped', 'stopped'), 'i18n' => 'sources.status.stopped'],
        ['value' => 'completed', 'label' => $t('sources.status.completed', 'completed'), 'i18n' => 'sources.status.completed'],
        ['value' => 'unknown', 'label' => $t('sources.status.unknown', 'unknown'), 'i18n' => 'sources.status.unknown'],
      ]]],
      ['label' => $t('sources.progress', 'Progress'), 'i18n' => 'sources.progress', 'class' => 'align-right', 'key' => 'progress', 'filter' => null],
    ];
    $attrs = ['data-table' => 'sources', 'data-view-config' => '1'];
    require __DIR__ . '/../partials/table.php';
    ?>
  </main>

  <!-- ================= JOB DIALOG ================= -->
  <dialog id="dlg-job">
    <form method="dialog" class="dialog">
      <h3 data-i18n="job.title"><?php echo htmlspecialchars($t('job.title', 'Job'), ENT_QUOTES); ?></h3>
      <div id="job-status"></div>
      <progress id="job-progress" value="0" max="100"></progress>
      <pre id="job-log" class="mono"></pre>
      <menu class="menu">
        <button id="btnJobCancel" type="button" class="btn" data-i18n="common.cancel"><?php echo htmlspecialchars($t('common.cancel', 'Cancel'), ENT_QUOTES); ?></button>
        <button value="cancel" data-i18n="common.close"><?php echo htmlspecialchars($t('common.close', 'Close'), ENT_QUOTES); ?></button>
      </menu>
    </form>
  </dialog>

  <dialog id="dlg-source" data-source-dialog>
    <form method="dialog" class="dialog">
      <div class="dialog-head">
        <h3 id="sourceTitle" data-i18n="sources.detail.title"><?php echo htmlspecialchars($t('sources.detail.title', 'Source detail'), ENT_QUOTES); ?></h3>
        <button type="button" class="btn" id="btnSourceClose" data-i18n="common.close"><?php echo htmlspecialchars($t('common.close', 'Close'), ENT_QUOTES); ?></button>
      </div>
      <div id="sourceMeta" class="source-meta"></div>
      <div id="sourceFields" class="source-fields"></div>
      <details id="sourceRawWrap" class="source-raw">
        <summary data-i18n="sources.detail.raw"><?php echo htmlspecialchars($t('sources.detail.raw', 'Raw data'), ENT_QUOTES); ?></summary>
        <pre id="sourceRaw" class="mono"></pre>
      </details>
      <menu class="menu">
        <button id="btnSourceApprove" type="button" class="btn primary" data-i18n="sources.detail.approve"><?php echo htmlspecialchars($t('sources.detail.approve', 'Approve'), ENT_QUOTES); ?></button>
        <button value="cancel" data-i18n="common.close"><?php echo htmlspecialchars($t('common.close', 'Close'), ENT_QUOTES); ?></button>
      </menu>
    </form>
  </dialog>

  <dialog id="dlg-table-view">
    <form method="dialog" class="dialog table-view-dialog">
      <h3>Table view</h3>
      <div class="table-view-body">
        <table class="table table-view-table">
          <thead>
            <tr>
              <th>On</th>
              <th>Column</th>
              <th>Width</th>
              <th>Header align</th>
              <th>Cell align</th>
              <th>Order</th>
            </tr>
          </thead>
          <tbody data-table-view-body></tbody>
        </table>
      </div>
      <menu class="menu">
        <button type="button" class="btn" data-table-view-reset>Reset</button>
        <button type="button" class="btn primary" data-table-view-apply>Apply</button>
        <button value="cancel" class="btn">Close</button>
      </menu>
    </form>
  </dialog>

  <!-- ================= DRY RUN DIALOG ================= -->
  <dialog id="dlg-dry-run">
    <form method="dialog" class="dialog">
      <h3 data-i18n="media.dry_run.title"><?php echo htmlspecialchars($t('media.dry_run.title', 'Dry run'), ENT_QUOTES); ?></h3>
      <pre id="dry-run-log" class="mono"></pre>
      <menu class="menu">
        <button value="cancel" data-i18n="common.close"><?php echo htmlspecialchars($t('common.close', 'Close'), ENT_QUOTES); ?></button>
      </menu>
    </form>
  </dialog>

  <script>
    window.I18N = <?php echo json_encode($dict, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); ?>;
    window.APP_LANG = <?php echo json_encode($lang, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); ?>;
    window.DEBUG_TOOLS_ENABLED = <?php echo !empty($debugToolsEnabled) ? 'true' : 'false'; ?>;
  </script>
  <script src="/assets/js/app-config.js"></script>
  <script src="/assets/js/table.js"></script>
  <script src="/assets/js/ui.js"></script>
  <script src="/assets/js/api.js"></script>
  <script src="/assets/js/prefs.js"></script>
  <script src="/assets/js/auth.js"></script>
  <script src="/assets/js/sse.js"></script>
  <script src="/assets/js/http.js"></script>
  <script src="/assets/js/app.js"></script>
</body>
</html>
