<!doctype html>
<!-- Copyright (c) Microsoft Corporation.
 Licensed under the MIT License. -->

<html>
  <head>
    <meta charset="utf-8" />
    <title>TypeAgent Knowledge Panel</title>
    <link rel="stylesheet" href="../vendor/bootstrap/bootstrap.min.css" />
    <link
      href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css"
      rel="stylesheet"
    />
    <style>
      body {
        font-size: 0.875rem;
        background-color: #f8f9fa;
      }
      .knowledge-header {
        background: white;
        color: #333;
        padding: 1rem;
        margin: -0.5rem -0.5rem 1rem -0.5rem;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
        border-bottom: 1px solid #e9ecef;
      }
      .status-indicator {
        width: 8px;
        height: 8px;
        border-radius: 50%;
        display: inline-block;
        margin-right: 0.5rem;
      }
      .status-connected {
        background-color: #28a745;
      }
      .status-disconnected {
        background-color: #dc3545;
      }
      .status-indexing {
        background-color: #ffc107;
      }
      .knowledge-card {
        border: none;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
        margin-bottom: 1rem;
      }
      .entity-badge {
        font-size: 0.75rem;
        margin-right: 0.25rem;
      }
      .relationship-item {
        padding: 0.5rem;
        border-left: 3px solid #667eea;
        background-color: #f8f9fa;
        margin-bottom: 0.5rem;
      }
      .question-item {
        cursor: pointer;
        transition: background-color 0.2s;
      }
      .question-item:hover {
        background-color: #e9ecef;
      }
      .mode-description {
        font-size: 0.75rem;
        color: #6c757d;
        margin-top: 0.25rem;
      }

      .quality-indicator {
        border-radius: 12px;
        padding: 0.25rem 0.75rem;
        font-size: 0.75rem;
        font-weight: 500;
      }

      .quality-excellent {
        background-color: #d4edda;
        color: #155724;
        border: 1px solid #c3e6cb;
      }

      .quality-good {
        background-color: #d1ecf1;
        color: #0c5460;
        border: 1px solid #bee5eb;
      }

      .quality-basic {
        background-color: #fff3cd;
        color: #856404;
        border: 1px solid #ffeaa7;
      }

      .quality-poor {
        background-color: #f8d7da;
        color: #721c24;
        border: 1px solid #f5c6cb;
      }

      .ai-status-indicator {
        width: 6px;
        height: 6px;
        border-radius: 50%;
        display: inline-block;
        margin-right: 0.5rem;
      }

      .ai-available {
        background-color: #28a745;
      }

      .ai-unavailable {
        background-color: #dc3545;
      }

      .ai-checking {
        background-color: #ffc107;
        animation: pulse 1.5s infinite;
      }

      @keyframes pulse {
        0%,
        100% {
          opacity: 1;
        }
        50% {
          opacity: 0.5;
        }
      }

      .progress-container {
        margin: 1rem 0;
        padding: 1rem;
        background: #f8f9fa;
        border-radius: 6px;
        border: 1px solid #e9ecef;
      }

      .progress-label {
        font-size: 0.875rem;
        margin-bottom: 0.5rem;
        color: #495057;
      }

      .batch-progress {
        margin-bottom: 0.5rem;
      }

      .batch-stats {
        display: flex;
        justify-content: space-between;
        font-size: 0.75rem;
        color: #6c757d;
      }

      /* Enhanced button animations */
      .btn {
        transition: all 0.3s ease;
      }

      .btn-success {
        animation: pulse-success 0.6s ease-in-out;
      }

      .btn-danger {
        animation: pulse-error 0.6s ease-in-out;
      }

      .btn-warning {
        animation: pulse-warning 0.3s ease-in-out infinite alternate;
      }

      @keyframes pulse-success {
        0% {
          transform: scale(1);
        }
        50% {
          transform: scale(1.05);
          background-color: #28a745;
        }
        100% {
          transform: scale(1);
        }
      }

      @keyframes pulse-error {
        0% {
          transform: scale(1);
        }
        50% {
          transform: scale(1.05);
          background-color: #dc3545;
        }
        100% {
          transform: scale(1);
        }
      }

      @keyframes pulse-warning {
        0% {
          opacity: 0.8;
        }
        100% {
          opacity: 1;
        }
      }

      /* Enhanced notification styling */
      .alert.position-fixed {
        animation: slideInRight 0.4s ease-out;
      }

      .alert.position-fixed.show {
        animation: slideInRight 0.4s ease-out;
      }

      @keyframes slideInRight {
        from {
          opacity: 0;
          transform: translateX(100%);
        }
        to {
          opacity: 1;
          transform: translateX(0);
        }
      }

      /* Spinner animation for indexing state */
      .spinner-grow-sm {
        width: 0.75rem;
        height: 0.75rem;
      }
      .mode-description {
        font-size: 0.75rem;
        color: #6c757d;
        margin-top: 0.25rem;
      }

      .quality-indicator {
        border-radius: 12px;
        padding: 0.25rem 0.75rem;
        font-size: 0.75rem;
        font-weight: 500;
      }

      .quality-excellent {
        background-color: #d4edda;
        color: #155724;
        border: 1px solid #c3e6cb;
      }

      .quality-good {
        background-color: #d1ecf1;
        color: #0c5460;
        border: 1px solid #bee5eb;
      }

      .quality-basic {
        background-color: #fff3cd;
        color: #856404;
        border: 1px solid #ffeaa7;
      }

      .quality-poor {
        background-color: #f8d7da;
        color: #721c24;
        border: 1px solid #f5c6cb;
      }

      .ai-status-indicator {
        width: 6px;
        height: 6px;
        border-radius: 50%;
        display: inline-block;
        margin-right: 0.5rem;
      }

      .ai-available {
        background-color: #28a745;
      }

      .ai-unavailable {
        background-color: #dc3545;
      }

      .ai-checking {
        background-color: #ffc107;
        animation: pulse 1.5s infinite;
      }

      @keyframes pulse {
        0%,
        100% {
          opacity: 1;
        }
        50% {
          opacity: 0.5;
        }
      }

      .progress-container {
        margin: 1rem 0;
        padding: 1rem;
        background: #f8f9fa;
        border-radius: 6px;
        border: 1px solid #e9ecef;
      }

      .progress-label {
        font-size: 0.875rem;
        margin-bottom: 0.5rem;
        color: #495057;
      }

      .batch-progress {
        margin-bottom: 0.5rem;
      }

      .batch-stats {
        display: flex;
        justify-content: space-between;
        font-size: 0.75rem;
        color: #6c757d;
      }

      /* Enhanced button animations */
      .btn {
        transition: all 0.3s ease;
      }

      .btn-success {
        animation: pulse-success 0.6s ease-in-out;
      }

      .btn-danger {
        animation: pulse-error 0.6s ease-in-out;
      }

      .btn-warning {
        animation: pulse-warning 0.3s ease-in-out infinite alternate;
      }

      @keyframes pulse-success {
        0% {
          transform: scale(1);
        }
        50% {
          transform: scale(1.05);
          background-color: #28a745;
        }
        100% {
          transform: scale(1);
        }
      }

      @keyframes pulse-error {
        0% {
          transform: scale(1);
        }
        50% {
          transform: scale(1.05);
          background-color: #dc3545;
        }
        100% {
          transform: scale(1);
        }
      }

      @keyframes pulse-warning {
        0% {
          opacity: 0.8;
        }
        100% {
          opacity: 1;
        }
      }

      /* Enhanced notification styling */
      .alert.position-fixed {
        animation: slideInRight 0.4s ease-out;
      }

      .alert.position-fixed.show {
        animation: slideInRight 0.4s ease-out;
      }

      @keyframes slideInRight {
        from {
          opacity: 0;
          transform: translateX(100%);
        }
        to {
          opacity: 1;
          transform: translateX(0);
        }
      }

      /* Spinner animation for indexing state */
      .spinner-grow-sm {
        width: 0.75rem;
        height: 0.75rem;
      }

      /* Enhanced Question Styling */
      .question-category-card {
        background: rgba(255, 255, 255, 0.8);
        border-radius: 8px;
        padding: 1rem;
        border: 1px solid #e9ecef;
      }

      .category-header {
        border-bottom: 1px solid #e9ecef;
        padding-bottom: 0.5rem;
      }

      .enhanced-question-item {
        cursor: pointer;
        transition: all 0.2s ease;
        border: 1px solid #dee2e6 !important;
        background: #ffffff;
      }

      .enhanced-question-item:hover {
        border-color: #0d6efd !important;
        transform: translateY(-1px);
        box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1) !important;
      }

      .enhanced-question-item:active {
        transform: translateY(0);
      }

      .category-toggle {
        transition: all 0.2s ease;
      }

      .category-toggle:hover {
        transform: scale(1.1);
      }

      .progress {
        border-radius: 2px;
        background-color: #f1f3f4;
      }

      .progress-bar {
        transition: width 0.3s ease;
      }

      /* Enhanced Content Metrics Styling */
      .metric-section {
        border-left: 3px solid #e9ecef;
        padding-left: 1rem;
        margin-left: 0.5rem;
      }

      .metric-visual-container {
        background: rgba(248, 249, 250, 0.5);
        border-radius: 6px;
        padding: 0.75rem;
      }

      .metric-card {
        transition: all 0.2s ease;
        border: 1px solid #e9ecef;
      }

      .metric-card:hover {
        transform: translateY(-1px);
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
      }

      .reading-time-display {
        min-width: 80px;
        text-align: center;
      }

      .page-type-indicator {
        border: 1px solid #e9ecef;
      }

      .interactivity-display {
        border: 1px solid #e9ecef;
      }

      /* Related Content Styling */
      .related-content-item {
        cursor: pointer;
        transition: all 0.2s ease;
        border: 1px solid #e9ecef !important;
      }

      .related-content-item:hover {
        border-color: #0d6efd !important;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
        transform: translateY(-1px);
      }

      .related-section {
        margin-bottom: 1rem;
      }

      .explore-related {
        transition: all 0.2s ease;
      }

      .explore-related:hover {
        transform: scale(1.1);
      }

      .related-content-summary {
        border: 1px solid #e9ecef;
      }

      /* Extraction Mode Slider Styles */
      .extraction-mode-slider-container {
        position: relative;
        margin: 0.5rem 0 1rem 0;
      }

      .extraction-mode-slider {
        width: 100%;
        height: 6px;
        border-radius: 3px;
        background: #e9ecef;
        outline: none;
        appearance: none;
        cursor: pointer;
        position: relative;
        z-index: 2;
      }

      .extraction-mode-slider::-webkit-slider-thumb {
        appearance: none;
        width: 20px;
        height: 20px;
        border-radius: 50%;
        background: #667eea;
        cursor: pointer;
        border: 2px solid white;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
        transition: all 0.2s ease;
      }

      .extraction-mode-slider::-webkit-slider-thumb:hover {
        transform: scale(1.1);
        box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
      }

      .extraction-mode-slider::-moz-range-thumb {
        width: 20px;
        height: 20px;
        border-radius: 50%;
        background: #667eea;
        cursor: pointer;
        border: 2px solid white;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
        transition: all 0.2s ease;
      }

      .extraction-mode-slider::-moz-range-thumb:hover {
        transform: scale(1.1);
        box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
      }

      .slider-labels {
        display: flex;
        justify-content: space-between;
        margin-top: 0.5rem;
        position: relative;
      }

      .slider-label {
        font-size: 0.75rem;
        color: #6c757d;
        text-align: center;
        flex: 1;
        cursor: pointer;
        transition: color 0.2s ease;
        user-select: none;
      }

      .slider-label.active {
        color: #667eea;
        font-weight: 600;
      }

      .slider-ticks {
        position: absolute;
        top: 50%;
        left: 0;
        right: 0;
        height: 6px;
        display: flex;
        justify-content: space-between;
        align-items: center;
        transform: translateY(-50%);
        pointer-events: none;
        z-index: 1;
      }

      .slider-tick {
        width: 8px;
        height: 8px;
        background: #dee2e6;
        border-radius: 50%;
        border: 2px solid white;
        transition: background-color 0.2s ease;
      }

      .slider-tick.active {
        background: #667eea;
      }

      /* Basic mode color - green for fast/simple */
      .extraction-mode-slider[data-mode="basic"] {
        background: linear-gradient(
          to right,
          #28a745 0%,
          #28a745 20%,
          #e9ecef 20%,
          #e9ecef 100%
        );
      }

      .extraction-mode-slider[data-mode="basic"]::-webkit-slider-thumb {
        background: #28a745;
      }

      .extraction-mode-slider[data-mode="basic"]::-moz-range-thumb {
        background: #28a745;
      }

      /* Summary mode color - yellow for enhanced processing */
      .extraction-mode-slider[data-mode="summary"] {
        background: linear-gradient(
          to right,
          #28a745 0%,
          #28a745 20%,
          #ffc107 20%,
          #ffc107 40%,
          #e9ecef 40%,
          #e9ecef 100%
        );
      }

      .extraction-mode-slider[data-mode="summary"]::-webkit-slider-thumb {
        background: #ffc107;
      }

      .extraction-mode-slider[data-mode="summary"]::-moz-range-thumb {
        background: #ffc107;
      }

      /* Content mode color - blue for standard */
      .extraction-mode-slider[data-mode="content"] {
        background: linear-gradient(
          to right,
          #28a745 0%,
          #28a745 20%,
          #ffc107 20%,
          #ffc107 40%,
          #667eea 40%,
          #667eea 60%,
          #e9ecef 60%,
          #e9ecef 100%
        );
      }

      .extraction-mode-slider[data-mode="content"]::-webkit-slider-thumb {
        background: #667eea;
      }

      .extraction-mode-slider[data-mode="content"]::-moz-range-thumb {
        background: #667eea;
      }

      /* Actions mode color - orange for enhanced */
      .extraction-mode-slider[data-mode="actions"] {
        background: linear-gradient(
          to right,
          #28a745 0%,
          #28a745 20%,
          #ffc107 20%,
          #ffc107 40%,
          #667eea 40%,
          #667eea 60%,
          #fd7e14 60%,
          #fd7e14 80%,
          #e9ecef 80%,
          #e9ecef 100%
        );
      }

      .extraction-mode-slider[data-mode="actions"]::-webkit-slider-thumb {
        background: #fd7e14;
      }

      .extraction-mode-slider[data-mode="actions"]::-moz-range-thumb {
        background: #fd7e14;
      }

      /* Full mode color - red for maximum */
      .extraction-mode-slider[data-mode="full"] {
        background: linear-gradient(
          to right,
          #28a745 0%,
          #28a745 20%,
          #ffc107 20%,
          #ffc107 40%,
          #667eea 40%,
          #667eea 60%,
          #fd7e14 60%,
          #fd7e14 80%,
          #dc3545 80%,
          #dc3545 100%
        );
      }

      .extraction-mode-slider[data-mode="full"]::-webkit-slider-thumb {
        background: #dc3545;
      }

      .extraction-mode-slider[data-mode="full"]::-moz-range-thumb {
        background: #dc3545;
      }
    </style>
  </head>
  <body>
    <div class="container-fluid p-3">
      <!-- Header Section -->
      <div class="knowledge-header rounded">
        <div class="d-flex justify-content-between align-items-center">
          <div>
            <h4 class="mb-1"><i class="bi bi-brain"></i> Knowledge Panel</h4>
            <small id="connectionStatus">
              <span class="status-indicator status-connected"></span>
              Connected to TypeAgent
            </small>
          </div>
          <div class="auto-index-toggle">
            <div class="form-check form-switch">
              <input
                class="form-check-input"
                type="checkbox"
                id="autoIndexToggle"
              />
              <label class="form-check-label text-muted" for="autoIndexToggle">
                Auto-index
              </label>
            </div>
          </div>
        </div>
      </div>

      <!-- Current Page Section -->
      <div class="knowledge-card card">
        <div
          class="card-header d-flex justify-content-between align-items-center"
        >
          <h6 class="mb-0"><i class="bi bi-globe"></i> Current Page</h6>
          <div class="btn-group btn-group-sm">
            <button id="extractKnowledge" class="btn btn-primary">
              <i class="bi bi-search"></i> Extract
            </button>
            <button id="indexPage" class="btn btn-outline-primary">
              <i class="bi bi-plus-circle"></i> Index
            </button>
          </div>
        </div>
        <div class="card-body">
          <!-- Mode Selection -->
          <div class="mb-3">
            <label for="extractionMode" class="form-label text-muted">
              <i class="bi bi-gear"></i> Extraction Mode
            </label>
            <div class="extraction-mode-slider-container">
              <div class="slider-labels">
                <span class="slider-label" data-value="0">Basic</span>
                <span class="slider-label" data-value="1">Summary</span>
                <span class="slider-label" data-value="2">Content</span>
                <span class="slider-label" data-value="3">Macros</span>
                <span class="slider-label" data-value="4">Full</span>
              </div>

              <input
                type="range"
                id="extractionMode"
                class="extraction-mode-slider"
                min="0"
                max="4"
                value="2"
                step="1"
                data-mode="content"
              />

              <div class="slider-ticks">
                <span class="slider-tick" data-value="0"></span>
                <span class="slider-tick" data-value="1"></span>
                <span class="slider-tick" data-value="2"></span>
                <span class="slider-tick" data-value="3"></span>
                <span class="slider-tick" data-value="4"></span>
              </div>
            </div>
            <div class="form-text" id="modeDescription">
              AI-powered content analysis with entity and topic extraction
            </div>
          </div>

          <!-- AI Model Status -->
          <div id="aiModelStatus" class="mb-3 d-none">
            <div class="alert alert-warning alert-sm p-2 mb-0">
              <i class="bi bi-exclamation-triangle me-2"></i>
              <span id="aiStatusMessage"
                >Checking AI model availability...</span
              >
            </div>
          </div>

          <div id="currentPageInfo">
            <div class="text-center text-muted">
              <i class="bi bi-hourglass-split"></i>
              <p class="mb-0">Loading page information...</p>
            </div>
          </div>
        </div>
      </div>

      <!-- Knowledge Results Section -->
      <div id="knowledgeSection" class="d-none">
        <!-- Entities Card -->
        <div class="knowledge-card card">
          <div class="card-header">
            <h6 class="mb-0">
              <i class="bi bi-tags"></i> Entities
              <span id="entitiesCount" class="badge bg-secondary ms-2">0</span>
            </h6>
          </div>
          <div class="card-body">
            <div id="entitiesContainer">
              <div class="text-muted text-center">
                <i class="bi bi-info-circle"></i>
                No entities extracted yet
              </div>
            </div>
          </div>
        </div>

        <!-- Relationships Card -->
        <div class="knowledge-card card">
          <div class="card-header">
            <h6 class="mb-0">
              <i class="bi bi-diagram-3"></i> Relationships
              <span id="relationshipsCount" class="badge bg-secondary ms-2"
                >0</span
              >
            </h6>
          </div>
          <div class="card-body">
            <div id="relationshipsContainer">
              <div class="text-muted text-center">
                <i class="bi bi-info-circle"></i>
                No relationships found yet
              </div>
            </div>
          </div>
        </div>

        <!-- Key Topics Card -->
        <div class="knowledge-card card">
          <div class="card-header">
            <h6 class="mb-0"><i class="bi bi-bookmark"></i> Key Topics</h6>
          </div>
          <div class="card-body">
            <div id="topicsContainer">
              <div class="text-muted text-center">
                <i class="bi bi-info-circle"></i>
                No topics identified yet
              </div>
            </div>
          </div>
        </div>
      </div>

      <!-- Suggested Questions Section -->
      <div id="questionsSection" class="knowledge-card card d-none">
        <div class="card-header">
          <h6 class="mb-0">
            <i class="bi bi-question-circle"></i> Ask About This Page
          </h6>
        </div>
        <div class="card-body">
          <div id="suggestedQuestions" class="mb-3">
            <!-- Suggested questions will be populated here -->
          </div>

          <div class="input-group">
            <input
              type="text"
              id="knowledgeQuery"
              class="form-control form-control-sm"
              placeholder="What would you like to know?"
            />
            <button id="submitQuery" class="btn btn-outline-primary btn-sm">
              <i class="bi bi-send"></i>
            </button>
          </div>

          <div id="queryResults" class="mt-3">
            <!-- Query results will appear here -->
          </div>
        </div>
      </div>
    </div>

    <script src="../vendor/bootstrap/bootstrap.bundle.min.js"></script>
    <script src="pageKnowledge.js"></script>
  </body>
</html>
