{% extends "base.html" %} {% block title %} 插件列表 - Amrita Dashboard{%
endblock %} {% block extra_css %}
<style>
  /* 移除了与base.css重复的大量样式，仅保留插件页面特有的样式 */

  body {
    overflow-x: hidden;
  }

  .plugins-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid #eee;
    margin-bottom: 10px;
  }
  
  body.dark-mode .plugins-header {
    border-bottom: 1px solid var(--dark-border-color);
  }
  
  body.dark-mode .page-title {
    color: var(--accent-color);
  }
  
  body.dark-mode .action-btn {
    background: var(--accent-color);
  }
  
  body.dark-mode .action-btn:hover {
    background: #8a2be2;
  }
  
  body.dark-mode .action-btn.secondary {
    background: #5a6268;
    color: var(--dark-text-color);
  }
  
  body.dark-mode .action-btn.secondary:hover {
    background: #495057;
  }
  
  body.dark-mode .plugin-card {
    background: var(--dark-card-bg);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    border: 1px solid var(--dark-border-color);
  }
  
  body.dark-mode .search-icon {
    color: #aaa;
  }
  
  body.dark-mode .filter-label {
    color: #ddd;
  }
  
  body.dark-mode .filter-select {
    border: 1px solid var(--dark-border-color);
    background: var(--dark-card-bg);
    color: var(--dark-text-color);
  }
  
  body.dark-mode .search-input {
    border: 1px solid var(--dark-border-color);
    background: var(--dark-card-bg);
    color: var(--dark-text-color);
  }
  
  body.dark-mode .plugin-tag {
    background: #333;
    color: #ccc;
  }

  body.dark-mode .plugin-meta {
    color: #aaa;
  }
  
  body.dark-mode .plugin-description {
    color: #bbb;
  }
  
  body.dark-mode .plugin-version {
    background: rgba(41, 128, 185, 0.2);
    color: var(--accent-color);
  }
  
  body.dark-mode .plugin-name {
    color: var(--accent-color);
  }
  
  body.dark-mode .plugin-card:hover {
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5);
  }
  
  body.dark-mode .slider {
    background-color: #555;
  }
  
  body.dark-mode input:checked + .slider {
    background-color: var(--accent-color);
  }
  
  body.dark-mode .plugin-action-btn:hover {
    background: var(--dark-sidebar-hover);
    color: var(--accent-color);
  }
  
  body.dark-mode .plugin-action-btn {
    color: #aaa;
  }
  
  body.dark-mode .no-plugins {
    color: #aaa;
  }
  
  body.dark-mode .no-plugins i {
    color: #555;
  }
  
  .page-title {
    font-size: 24px;
    font-weight: 600;
    color: var(--primary-color);
  }

  .actions-container {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
    margin-top: 5px;
  }

  .action-btn {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 8px 15px;
    border-radius: 5px;
    cursor: pointer;
    display: flex;
    align-items: center;
    transition: background 0.3s;
  }

  .action-btn:hover {
    background: var(--accent-color);
  }

  .action-btn i {
    margin-right: 5px;
  }

  .action-btn.secondary {
    background: #6c757d;
  }

  .action-btn.secondary:hover {
    background: #5a6268;
  }

  .filter-container {
    display: flex;
    gap: 15px;
    margin-bottom: 20px;
    flex-wrap: wrap;
    margin-top: 10px;
  }

  .filter-group {
    display: flex;
    align-items: center;
    gap: 8px;
  }

  .filter-label {
    font-weight: 500;
    color: #555;
  }

  .filter-select {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 5px;
    background: white;
    min-width: 150px;
  }

  .search-box {
    position: relative;
    flex-grow: 1;
    max-width: 300px;
  }

  .search-input {
    width: 100%;
    padding: 8px 12px 8px 35px;
    border: 1px solid #ddd;
    border-radius: 5px;
  }

  .search-icon {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: #777;
  }

  .plugins-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
  }

  .plugin-card {
    background: white;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    padding: 20px;
    transition: transform 0.3s, box-shadow 0.3s;
    position: relative;
    overflow: hidden;
  }

  .plugin-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
  }

  .plugin-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 15px;
  }

  .plugin-name {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-color);
    margin-bottom: 5px;
  }

  .plugin-badge {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
    margin-left: 8px;
  }

  .badge-local {
    background: rgba(46, 204, 113, 0.1);
    color: #2ecc71;
  }

  .badge-remote {
    background: rgba(52, 152, 219, 0.1);
    color: #3498db;
  }

  .plugin-version {
    color: #777;
    font-size: 14px;
  }

  .plugin-type {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
    background: rgba(43, 76, 226, 0.1);
    color: var(--primary-color);
  }

  .plugin-description {
    color: #555;
    margin: 15px 0;
    line-height: 1.5;
    font-size: 14px;
  }

  .plugin-homepage {
    margin-bottom: 15px;
  }

  .homepage-link {
    color: var(--primary-color);
    text-decoration: none;
    font-size: 14px;
    display: flex;
    align-items: center;
  }

  .homepage-link:hover {
    text-decoration: underline;
  }

  .homepage-link i {
    margin-right: 5px;
  }

  .plugin-actions {
    display: flex;
    gap: 10px;
    margin-top: 15px;
    border-top: 1px solid #f0f0f0;
    padding-top: 15px;
  }

  .plugin-btn {
    flex: 1;
    padding: 8px 12px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
  }

  .plugin-btn i {
    margin-right: 5px;
  }

  .btn-enable {
    background: #2ecc71;
    color: white;
  }

  .btn-enable:hover {
    background: #27ae60;
  }

  .btn-disable {
    background: #e74c3c;
    color: white;
  }

  .btn-disable:hover {
    background: #c0392b;
  }

  .btn-configure {
    background: #f39c12;
    color: white;
  }

  .btn-configure:hover {
    background: #d35400;
  }

  .btn-reload {
    background: #3498db;
    color: white;
  }

  .btn-reload:hover {
    background: #2980b9;
  }

  .empty-state {
    text-align: center;
    padding: 40px 20px;
    background: white;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
  }

  .empty-icon {
    font-size: 48px;
    color: #ddd;
    margin-bottom: 15px;
  }

  .empty-text {
    color: #777;
    margin-bottom: 20px;
  }

  @media (max-width: 768px) {
    .plugins-header {
      flex-direction: column;
      align-items: flex-start;
      gap: 15px;
      margin-bottom: 10px;
    }

    .actions-container {
      width: 100%;
      justify-content: space-between;
    }

    .plugins-grid {
      grid-template-columns: 1fr;
    }

    .plugin-actions {
      flex-direction: column;
    }

    .plugin-btn {
      width: 100%;
    }
  }

  @media (max-width: 480px) {
    .filter-container {
      flex-direction: column;
      align-items: flex-start;
    }

    .search-box {
      max-width: 100%;
    }
  }
</style>
{% endblock %} {% block content %}
<div class="plugins-header">
  <h1 class="page-title">插件管理</h1>
  <div class="actions-container">
    <button class="action-btn" onclick="refreshPlugins()">
      <i class="fas fa-sync-alt"></i> 刷新列表
    </button>
  </div>
</div>
<div class="filter-container">
  <div class="filter-group">
    <span class="filter-label">类型:</span>
    <select class="filter-select" id="type-filter" onchange="filterPlugins()">
      <option value="all">全部类型</option>
      {% for type in plugin_types %}
      <option value="{{ type }}">{{ type }}</option>
      {% endfor %}
    </select>
  </div>
  <div class="filter-group">
    <span class="filter-label">来源:</span>
    <select class="filter-select" id="source-filter" onchange="filterPlugins()">
      <option value="all">全部来源</option>
      <option value="local">本地插件</option>
      <option value="remote">Pypi插件</option>
    </select>
  </div>
  <div class="search-box">
    <i class="fas fa-search search-icon"></i>
    <input
      type="text"
      class="search-input"
      id="plugin-search"
      placeholder="搜索插件..."
      onkeyup="filterPlugins()"
    />
  </div>
</div>
<div class="plugins-grid" id="plugins-container">
  {% for plugin in plugins %}
  <div
    class="plugin-card"
    data-type="{{ plugin.type }}"
    data-source="{{ 'local' if plugin.is_local else 'remote' }}"
    data-name="{{ plugin.name|lower }}"
  >
    <div class="plugin-header">
      <div>
        <h3 class="plugin-name">
          {{ plugin.name }}
          <span
            class="plugin-badge {{ 'badge-local' if plugin.is_local else 'badge-remote' }}"
          >
            {{ '本地' if plugin.is_local else 'Pypi' }}
          </span>
        </h3>
        <div class="plugin-version">版本: {{ plugin.version }}</div>
      </div>
      <span class="plugin-type">{{ plugin.type }}</span>
    </div>
    <p class="plugin-description">{{ plugin.description }}</p>
    {% if plugin.homepage %}
    <div class="plugin-homepage">
      <a href="{{ plugin.homepage }}" class="homepage-link" target="_blank">
        <i class="fas fa-external-link-alt"></i> 插件主页
      </a>
    </div>
    {% endif %}
  </div>
  {% else %}
  <div class="empty-state">
    <div class="empty-icon">
      <i class="fas fa-plug"></i>
    </div>
    <p class="empty-text">未找到任何插件</p>
  </div>
  {% endfor %}
</div>
{% endblock %} {% block scripts %}
<script>
  function filterPlugins() {
    const typeFilter = document.getElementById("type-filter").value;
    const sourceFilter = document.getElementById("source-filter").value;
    const searchQuery = document
      .getElementById("plugin-search")
      .value.toLowerCase();

    const pluginCards = document.querySelectorAll(".plugin-card");

    pluginCards.forEach((card) => {
      const pluginType = card.getAttribute("data-type");
      const pluginSource = card.getAttribute("data-source");
      const pluginName = card.getAttribute("data-name");

      const typeMatch = typeFilter === "all" || pluginType === typeFilter;
      const sourceMatch =
        sourceFilter === "all" || pluginSource === sourceFilter;
      const searchMatch =
        pluginName.includes(searchQuery) ||
        card
          .querySelector(".plugin-description")
          .textContent.toLowerCase()
          .includes(searchQuery);

      if (typeMatch && sourceMatch && searchMatch) {
        card.style.display = "block";
      } else {
        card.style.display = "none";
      }
    });

    const visibleCards = Array.from(pluginCards).filter(
      (card) => card.style.display !== "none"
    );
    const emptyState = document.querySelector(".empty-state");

    if (visibleCards.length === 0 && emptyState) {
      emptyState.style.display = "block";
    } else if (emptyState) {
      emptyState.style.display = "none";
    }
  }

  async function refreshPlugins() {
    try {
      Swal.fire({
        title: "刷新中...",
        text: "正在获取最新插件信息",
        allowOutsideClick: false,
        didOpen: () => {
          Swal.showLoading();
        },
      });

      const response = await fetch("/api/plugins/list");

      if (response.ok) {
        location.reload();
      } else {
        throw new Error("服务器返回错误状态");
      }
    } catch (error) {
      console.error("刷新插件列表失败:", error);
      Swal.close();
      Swal.fire({
        title: "刷新失败",
        text: "无法获取插件列表，请检查网络连接",
        icon: "error",
        timer: 2000,
      });
    }
  }

  document.addEventListener("DOMContentLoaded", function () {});
</script>
{% endblock %}
