All files / src/app/admin/dev-tools/plans page.tsx

0% Statements 0/204
100% Branches 0/0
0% Functions 0/1
0% Lines 0/204

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205                                                                                                                                                                                                                                                                                                                                                                                                                         
'use client';

import { useState, useEffect } from 'react';
import Link from 'next/link';
import type { PlanSummary } from '@/lib/dev-tools/types';
import { Icon } from '@/components/ui/icons';

export default function PlansViewerPage() {
  const [plans, setPlans] = useState<{ active: PlanSummary[]; archived: PlanSummary[] }>({ active: [], archived: [] });
  const [isLoading, setIsLoading] = useState(true);
  const [error, setError] = useState<string | null>(null);
  const [searchTerm, setSearchTerm] = useState('');
  const [showArchived, setShowArchived] = useState(false);

  useEffect(() => {
    const fetchPlans = async () => {
      try {
        const res = await fetch('/api/admin/dev-tools/docs/plans');
        if (!res.ok) throw new Error('Failed to fetch plans');
        const result = await res.json();
        // Handle both new wrapped format and legacy format
        const data = result.data ?? result;
        setPlans(data.plans);
      } catch (err) {
        setError(err instanceof Error ? err.message : 'Failed to load plans');
      } finally {
        setIsLoading(false);
      }
    };
    fetchPlans();
  }, []);

  const filterPlans = (planList: PlanSummary[]) => {
    if (!searchTerm) return planList;
    const term = searchTerm.toLowerCase();
    return planList.filter(plan =>
      plan.title.toLowerCase().includes(term) ||
      plan.slug.toLowerCase().includes(term)
    );
  };

  const filteredActive = filterPlans(plans.active);
  const filteredArchived = filterPlans(plans.archived);

  const getPriorityColor = (priority?: string) => {
    switch (priority?.toUpperCase()) {
      case 'HIGH': return 'bg-red-100 text-red-700';
      case 'MEDIUM': return 'bg-yellow-100 text-yellow-700';
      case 'LOW': return 'bg-green-100 text-green-700';
      default: return 'bg-gray-100 text-gray-700';
    }
  };

  const getComplexityColor = (complexity?: string) => {
    switch (complexity?.toUpperCase()) {
      case 'HIGH': return 'bg-purple-100 text-purple-700';
      case 'MEDIUM': case 'MEDIUM-HIGH': return 'bg-blue-100 text-blue-700';
      case 'LOW': return 'bg-teal-100 text-teal-700';
      default: return 'bg-gray-100 text-gray-700';
    }
  };

  if (isLoading) {
    return (
      <div className="max-w-[1170px] mx-auto px-4 sm:px-7.5 xl:px-0">
        <div className="animate-pulse">
          <div className="h-8 bg-gray-200 rounded w-48 mb-4"></div>
          <div className="space-y-4">
            {[1, 2, 3].map(i => (
              <div key={i} className="h-24 bg-gray-200 rounded"></div>
            ))}
          </div>
        </div>
      </div>
    );
  }

  if (error) {
    return (
      <div className="max-w-[1170px] mx-auto px-4 sm:px-7.5 xl:px-0">
        <div className="bg-red-50 border border-red-200 rounded-lg p-4 text-red-700">
          {error}
        </div>
      </div>
    );
  }

  return (
    <div className="max-w-[1170px] mx-auto px-4 sm:px-7.5 xl:px-0">
      {/* Breadcrumb */}
      <nav className="mb-4">
        <ol className="flex items-center gap-2 text-sm text-gray-600">
          <li><Link href="/admin/dev-tools" className="hover:text-blue">Developer Tools</Link></li>
          <li>/</li>
          <li className="text-dark font-medium">Plans</li>
        </ol>
      </nav>

      <div className="mb-8">
        <h1 className="text-2xl font-bold text-dark">Project Plans</h1>
        <p className="text-gray-600 mt-1">
          View development plans and roadmaps
        </p>
      </div>

      {/* Search and Filter */}
      <div className="bg-white rounded-lg shadow-sm border border-gray-200 p-4 mb-6">
        <div className="flex flex-wrap gap-4 items-center">
          <div className="flex-1 min-w-[200px]">
            <input
              type="text"
              value={searchTerm}
              onChange={(e) => setSearchTerm(e.target.value)}
              placeholder="Search plans..."
              className="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue focus:border-transparent"
            />
          </div>
          <div className="flex items-center gap-2">
            <span className="text-sm text-gray-600">
              {filteredActive.length} active, {filteredArchived.length} archived
            </span>
          </div>
        </div>
      </div>

      {/* Active Plans */}
      <div className="mb-8">
        <h2 className="text-lg font-semibold text-dark mb-4">Active Plans ({filteredActive.length})</h2>
        {filteredActive.length === 0 ? (
          <p className="text-gray-500">No active plans found</p>
        ) : (
          <div className="space-y-3">
            {filteredActive.map(plan => (
              <Link
                key={plan.slug}
                href={`/admin/dev-tools/plans/${plan.slug}`}
                className="block bg-white rounded-lg shadow-sm border border-gray-200 p-4 hover:shadow-md hover:border-blue transition-all"
              >
                <div className="flex items-start justify-between">
                  <div>
                    <h3 className="font-medium text-dark">{plan.title}</h3>
                    <p className="text-sm text-gray-500 mt-1">{plan.filename}</p>
                  </div>
                  <div className="flex items-center gap-2">
                    {plan.priority && (
                      <span className={`px-2 py-1 rounded text-xs font-medium ${getPriorityColor(plan.priority)}`}>
                        {plan.priority}
                      </span>
                    )}
                    {plan.complexity && (
                      <span className={`px-2 py-1 rounded text-xs font-medium ${getComplexityColor(plan.complexity)}`}>
                        {plan.complexity}
                      </span>
                    )}
                  </div>
                </div>
              </Link>
            ))}
          </div>
        )}
      </div>

      {/* Archived Plans */}
      <div>
        <button
          onClick={() => setShowArchived(!showArchived)}
          className="flex items-center gap-2 text-lg font-semibold text-dark mb-4 hover:text-blue transition-colors"
        >
          <Icon
            name="chevron-right"
            size={20}
            className={`transition-transform ${showArchived ? 'rotate-90' : ''}`}
          />
          Archived Plans ({filteredArchived.length})
        </button>
        {showArchived && (
          filteredArchived.length === 0 ? (
            <p className="text-gray-500">No archived plans found</p>
          ) : (
            <div className="space-y-3">
              {filteredArchived.map(plan => (
                <Link
                  key={plan.slug}
                  href={`/admin/dev-tools/plans/${plan.slug}`}
                  className="block bg-gray-50 rounded-lg border border-gray-200 p-4 hover:shadow-md hover:border-blue transition-all"
                >
                  <div className="flex items-start justify-between">
                    <div>
                      <h3 className="font-medium text-gray-700">{plan.title}</h3>
                      <p className="text-sm text-gray-500 mt-1">{plan.filename}</p>
                    </div>
                    <span className="px-2 py-1 bg-gray-200 text-gray-600 rounded text-xs font-medium">
                      Archived
                    </span>
                  </div>
                </Link>
              ))}
            </div>
          )
        )}
      </div>
    </div>
  );
}