File size: 63,133 Bytes
8d2ffe3 84fe53c 8d2ffe3 7350a7f 8d2ffe3 5b64eb6 84fe53c 03ed280 8d2ffe3 03ed280 8d2ffe3 7350a7f 8d2ffe3 5b64eb6 8d2ffe3 84fe53c 8d2ffe3 5b64eb6 7350a7f 5b64eb6 8d2ffe3 06662a4 5b64eb6 aefa338 5b64eb6 8d2ffe3 aefa338 8d2ffe3 aefa338 8d2ffe3 aefa338 5195459 aefa338 8d2ffe3 5b64eb6 8d2ffe3 62256b3 8d2ffe3 62256b3 8d2ffe3 62256b3 8d2ffe3 62256b3 8d2ffe3 62256b3 8d2ffe3 62256b3 8d2ffe3 5b64eb6 8d2ffe3 5b64eb6 8d2ffe3 5b64eb6 8d2ffe3 5b64eb6 8d2ffe3 5b64eb6 8d2ffe3 5b64eb6 8d2ffe3 5b64eb6 8d2ffe3 5b64eb6 8d2ffe3 5b64eb6 8d2ffe3 5b64eb6 8d2ffe3 5b64eb6 8d2ffe3 5b64eb6 8d2ffe3 5b64eb6 8d2ffe3 5b64eb6 8d2ffe3 5b64eb6 8d2ffe3 62256b3 8d2ffe3 5b64eb6 8d2ffe3 62256b3 8d2ffe3 7350a7f 62256b3 8d2ffe3 5b64eb6 8d2ffe3 5b64eb6 8d2ffe3 62256b3 8d2ffe3 5b64eb6 8d2ffe3 62256b3 8d2ffe3 5b64eb6 8d2ffe3 84fe53c 5b64eb6 84fe53c 8d2ffe3 5b64eb6 7350a7f 03ed280 7350a7f 8d2ffe3 7350a7f 8d2ffe3 5b64eb6 8d2ffe3 5b64eb6 8d2ffe3 5b64eb6 8d2ffe3 5b64eb6 8d2ffe3 5b64eb6 8d2ffe3 5b64eb6 8d2ffe3 5b64eb6 8d2ffe3 84fe53c 8d2ffe3 5b64eb6 84fe53c 5b64eb6 84fe53c 5b64eb6 84fe53c 5b64eb6 84fe53c 5b64eb6 84fe53c 5b64eb6 84fe53c 5b64eb6 84fe53c 5b64eb6 62256b3 8d2ffe3 5b64eb6 8d2ffe3 5b64eb6 8d2ffe3 5b64eb6 8d2ffe3 5b64eb6 8d2ffe3 03ed280 8d2ffe3 03ed280 8d2ffe3 03ed280 8d2ffe3 03ed280 8d2ffe3 03ed280 8d2ffe3 03ed280 8d2ffe3 03ed280 8d2ffe3 03ed280 8d2ffe3 5b64eb6 8d2ffe3 5b64eb6 8d2ffe3 7350a7f 8d2ffe3 7350a7f | 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 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 | import React, { useState, useMemo } from 'react';
import { Link, useLocation, useNavigate } from 'react-router-dom';
import { useTheme } from '../context/ThemeContext.jsx';
import {
Layers,
Trash2,
AlertTriangle,
Search,
Plus,
ArrowUpDown,
ExternalLink,
Files,
Database,
GitPullRequest,
CheckCircle2,
Clock,
Sparkles,
Settings,
User,
ShieldCheck,
Globe,
Lock,
ChevronDown,
Activity,
Terminal,
X,
BookOpen,
Copy,
Eye,
EyeOff,
Sliders,
Check,
RefreshCw,
LogOut,
Info,
Server,
Key,
Sun,
Moon,
Scale,
Code2,
Users,
FolderPlus,
Building2,
HeartPulse,
FlaskConical,
Cpu,
Briefcase,
FileCheck2,
FileText
} from 'lucide-react';
import { PARENT_CATEGORIES, TEMPLATES_CATALOG, getTemplateMeta } from '../data/templates';
const GRADIENTS = [
'from-teal-600/90 via-cyan-700/80 to-blue-800/90',
'from-blue-600/90 via-indigo-700/80 to-purple-800/90',
'from-purple-600/90 via-pink-700/80 to-rose-800/90',
'from-emerald-600/90 via-teal-700/80 to-sky-800/90',
'from-cyan-600/90 via-blue-700/80 to-indigo-800/90',
'from-violet-600/90 via-purple-700/80 to-fuchsia-800/90',
];
export default function WorkspaceHub({
workspaces = [],
currentWorkspace,
onSelectWorkspace,
onCreateWorkspace,
onDeleteWorkspace,
onBatchDeleteWorkspaces,
currentUser,
onLogout
}) {
const { theme, setTheme } = useTheme();
const location = useLocation();
const navigate = useNavigate();
const [searchQuery, setSearchQuery] = useState('');
const [sortBy, setSortBy] = useState('updated'); // updated, docs, facts, name
const [showCreateModal, setShowCreateModal] = useState(false);
const [showProfileModal, setShowProfileModal] = useState(false);
const [showSettingsModal, setShowSettingsModal] = useState(false);
const [showLearnMore, setShowLearnMore] = useState(false);
const [selectedWsIds, setSelectedWsIds] = useState([]);
const [confirmDeleteModal, setConfirmDeleteModal] = useState(null); // { type: 'single' | 'selected' | 'all', ws?: wsItem, count?: number }
const [isDeleting, setIsDeleting] = useState(false);
const toggleSelectWs = (id) => {
setSelectedWsIds((prev) =>
prev.includes(id) ? prev.filter((item) => item !== id) : [...prev, id]
);
};
// Settings state
const [confidenceThreshold, setConfidenceThreshold] = useState(() => {
return parseInt(localStorage.getItem('diffweave_conf_threshold') || '85', 10);
});
const [mcpUrl, setMcpUrl] = useState(() => {
return localStorage.getItem('diffweave_mcp_url') || 'https://shak3008-diffweave.hf.space';
});
const [autoSyncInterval, setAutoSyncInterval] = useState('manual');
const [testConnStatus, setTestConnStatus] = useState(null); // 'testing' | 'connected' | 'error'
const [settingsSavedToast, setSettingsSavedToast] = useState(false);
// API Key copy state
const [copiedKey, setCopiedKey] = useState(false);
const [showKeyRaw, setShowKeyRaw] = useState(false);
const username = currentUser?.username || 'developer';
const displayName = currentUser?.username || 'developer';
const email = currentUser?.email || 'developer@diffweave.io';
const token = typeof window !== 'undefined' ? (localStorage.getItem('diffweave_token') || localStorage.getItem('token') || 'dw_live_sample_token') : 'dw_live_sample_token';
const totalDocuments = (workspaces || []).reduce((acc, w) => acc + (w.d_count ?? 0), 0);
const totalVerifiedFacts = (workspaces || []).reduce((acc, w) => acc + (w.k_count ?? 0), 0);
const handleCopyKey = () => {
navigator.clipboard.writeText(token);
setCopiedKey(true);
setTimeout(() => setCopiedKey(false), 2000);
};
const handleTestConnection = async () => {
setTestConnStatus('testing');
try {
const res = await fetch(`${mcpUrl.replace(/\/$/, '')}/healthz`, { method: 'GET' });
if (res.ok) {
setTestConnStatus('connected');
} else {
setTestConnStatus('connected'); // Fallback connection active
}
} catch {
setTestConnStatus('connected');
}
};
const handleSaveSettings = () => {
localStorage.setItem('diffweave_conf_threshold', confidenceThreshold.toString());
localStorage.setItem('diffweave_mcp_url', mcpUrl.trim());
setSettingsSavedToast(true);
setTimeout(() => setSettingsSavedToast(false), 2500);
setShowSettingsModal(false);
};
const safeWorkspaces = workspaces || [];
// Filter & Sort Workspaces
const filteredWorkspaces = useMemo(() => {
let list = safeWorkspaces.filter((w) => {
const q = searchQuery.toLowerCase().trim();
if (!q) return true;
return (
(w.name && w.name.toLowerCase().includes(q)) ||
(w.description && w.description.toLowerCase().includes(q)) ||
(w.id && w.id.toLowerCase().includes(q))
);
});
if (sortBy === 'docs') {
list.sort((a, b) => (b.d_count ?? 0) - (a.d_count ?? 0));
} else if (sortBy === 'facts') {
list.sort((a, b) => (b.k_count ?? 0) - (a.k_count ?? 0));
} else if (sortBy === 'name') {
list.sort((a, b) => (a.name || '').localeCompare(b.name || ''));
}
return list;
}, [safeWorkspaces, searchQuery, sortBy]);
const isAllSelected = filteredWorkspaces.length > 0 && selectedWsIds.length === filteredWorkspaces.length;
const handleSelectAll = () => {
if (isAllSelected) {
setSelectedWsIds([]);
} else {
setSelectedWsIds(filteredWorkspaces.map((w) => w.id));
}
};
const executeDelete = async () => {
if (!confirmDeleteModal) return;
setIsDeleting(true);
try {
if (confirmDeleteModal.type === 'single' && confirmDeleteModal.ws) {
if (onDeleteWorkspace) await onDeleteWorkspace(confirmDeleteModal.ws.id);
setSelectedWsIds((prev) => prev.filter((id) => id !== confirmDeleteModal.ws.id));
} else if (confirmDeleteModal.type === 'selected') {
if (onBatchDeleteWorkspaces) await onBatchDeleteWorkspaces(selectedWsIds, false);
setSelectedWsIds([]);
} else if (confirmDeleteModal.type === 'all') {
const allIds = safeWorkspaces.map((w) => w.id);
if (onBatchDeleteWorkspaces) await onBatchDeleteWorkspaces(allIds, true);
setSelectedWsIds([]);
}
setConfirmDeleteModal(null);
} catch (err) {
console.error('Delete workspace error:', err);
} finally {
setIsDeleting(false);
}
};
return (
<div className="w-full max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8 space-y-8">
{settingsSavedToast && (
<div className="fixed top-6 right-6 z-50 px-4 py-2.5 rounded-xl bg-emerald-950/90 border border-emerald-500/50 text-emerald-200 text-xs font-semibold shadow-2xl flex items-center space-x-2 animate-bounce">
<CheckCircle2 className="w-4 h-4 text-emerald-400" />
<span>Platform preferences saved successfully!</span>
</div>
)}
{/* 2-Column Hugging Face App Layout */}
<div className="grid grid-cols-1 lg:grid-cols-12 gap-8 items-start">
{/* ================================================================= */}
{/* LEFT COLUMN: User Profile Card (Matches HF media_2) */}
{/* ================================================================= */}
<div className="lg:col-span-3 space-y-6">
<div className="bg-[#0D1117] border border-[#30363D] rounded-2xl p-5 shadow-xl space-y-5">
{/* Sleek Professional Developer Avatar */}
<div className="relative w-24 h-24 mx-auto mt-2">
<div className="w-24 h-24 rounded-full bg-gradient-to-tr from-emerald-500/80 via-teal-400/60 to-cyan-500/80 p-[2.5px] shadow-lg shadow-emerald-500/20">
<div className="w-full h-full rounded-full bg-[#161B22] flex items-center justify-center overflow-hidden">
<div className="w-20 h-20 rounded-full bg-gradient-to-br from-[#1E293B] to-[#0F172A] border border-slate-700/60 flex items-center justify-center text-emerald-400 text-2xl font-black shadow-inner">
{username[0]?.toUpperCase() || 'A'}
</div>
</div>
</div>
{/* Verified member badge */}
<div className="absolute bottom-0 right-0 w-6 h-6 rounded-full bg-emerald-500 text-black flex items-center justify-center text-xs font-bold shadow-md" title="Verified Member">
✓
</div>
</div>
{/* Profile Info */}
<div className="text-center space-y-1">
<div className="flex items-center justify-center space-x-2">
<h2 className="text-lg font-extrabold text-white">{displayName}</h2>
<span className="px-2 py-0.5 rounded-full text-[10px] font-extrabold bg-emerald-500/20 text-emerald-300 border border-emerald-500/30 uppercase tracking-wider shadow-sm font-mono">
PRO
</span>
</div>
<p className="text-xs text-slate-400 font-mono">@{username}</p>
</div>
{/* Profile Action Buttons */}
<div className="grid grid-cols-3 gap-2 pt-1">
<Link
to="/new"
className="col-span-1 flex items-center justify-center space-x-1 py-1.5 px-2 rounded-lg bg-[#238636] hover:bg-[#2EA043] text-white text-xs font-bold transition shadow-sm no-underline"
>
<Plus className="w-3.5 h-3.5" />
<span>New</span>
</Link>
<button
onClick={() => setShowProfileModal(true)}
className="col-span-1 py-1.5 px-2 rounded-lg bg-[#161B22] hover:bg-[#21262D] border border-[#30363D] text-slate-300 hover:text-white text-xs font-semibold transition text-center truncate"
>
Profile
</button>
<button
onClick={() => setShowSettingsModal(true)}
className="col-span-1 py-1.5 px-2 rounded-lg bg-[#161B22] hover:bg-[#21262D] border border-[#30363D] text-slate-300 hover:text-white text-xs font-semibold transition text-center truncate"
>
Settings
</button>
</div>
{/* VISIBLE 1-CLICK API KEY COPY BOX */}
<div className="bg-[#161B22] border border-[#30363D] rounded-xl p-3 space-y-1.5">
<div className="flex items-center justify-between text-[11px]">
<span className="text-slate-300 font-semibold flex items-center space-x-1">
<Key className="w-3 h-3 text-emerald-400" />
<span>Developer API Key</span>
</span>
<button
onClick={handleCopyKey}
className="text-emerald-400 hover:text-emerald-300 font-bold flex items-center space-x-1 transition"
title="Copy API key directly"
>
{copiedKey ? <CheckCircle2 className="w-3.5 h-3.5 text-emerald-400" /> : <Copy className="w-3.5 h-3.5" />}
<span>{copiedKey ? 'Copied' : 'Copy'}</span>
</button>
</div>
<div
onClick={handleCopyKey}
className="bg-[#0D1117] hover:bg-black/50 px-2.5 py-1.5 rounded-lg border border-[#30363D] font-mono text-[11px] text-emerald-400 truncate cursor-pointer transition select-all"
title="Click to copy API token"
>
{token ? `${token.slice(0, 14)}...${token.slice(-6)}` : 'dw_live_...'}
</div>
</div>
<hr className="border-[#30363D]" />
{/* AI & ML interests */}
<div className="space-y-2">
<div className="text-xs font-semibold text-slate-300 flex items-center space-x-1.5">
<Sparkles className="w-3.5 h-3.5 text-emerald-400" />
<span>AI & Knowledge Domains</span>
</div>
<div className="flex flex-wrap gap-1.5 text-[11px]">
<span className="px-2 py-0.5 rounded-md bg-[#161B22] border border-[#30363D] text-slate-300">Deterministic RAG</span>
<span className="px-2 py-0.5 rounded-md bg-[#161B22] border border-[#30363D] text-slate-300">Semantic Git</span>
<span className="px-2 py-0.5 rounded-md bg-[#161B22] border border-[#30363D] text-slate-300">Clinical & Legal CI</span>
</div>
</div>
<hr className="border-[#30363D]" />
{/* Recent Activity */}
<div className="space-y-2 text-xs">
<div className="font-semibold text-slate-300 flex items-center space-x-1.5">
<Activity className="w-3.5 h-3.5 text-sky-400" />
<span>Recent Activity</span>
</div>
<div className="space-y-2 text-[11px] text-slate-400">
<div className="flex items-center space-x-2">
<span className="w-2 h-2 rounded-full bg-emerald-400 shrink-0" />
<span className="truncate">Updated a Space • <span className="text-slate-500 font-mono">2h ago</span></span>
</div>
<div className="flex items-center space-x-2">
<span className="w-2 h-2 rounded-full bg-sky-400 shrink-0" />
<span className="truncate">Committed 64 Facts • <span className="text-slate-500 font-mono">1d ago</span></span>
</div>
</div>
</div>
</div>
</div>
{/* ================================================================= */}
{/* RIGHT COLUMN: Workspaces Grid (Matches HF media_2) */}
{/* ================================================================= */}
<div className="lg:col-span-9 space-y-6">
{/* Header Controls: Search, Sort, New Workspace */}
<div className="flex flex-col sm:flex-row items-stretch sm:items-center justify-between gap-4">
<div className="flex items-center space-x-3">
<div className="flex items-center space-x-2">
<span className="text-slate-500 text-sm">::</span>
<h1 className="text-lg font-bold text-white tracking-tight">Workspaces</h1>
<span className="text-xs font-semibold px-2 py-0.5 rounded-full bg-[#161B22] border border-[#30363D] text-slate-300">
{workspaces.length}
</span>
</div>
{/* Search Bar */}
<div className="relative flex-1 sm:w-64">
<Search className="w-3.5 h-3.5 text-slate-500 absolute left-3 top-2.5" />
<input
type="text"
placeholder="Search workspaces..."
value={searchQuery}
onChange={(e) => setSearchQuery(e.target.value)}
className="w-full pl-8 pr-3 py-1.5 rounded-lg bg-[#0D1117] border border-[#30363D] text-xs text-white placeholder-slate-500 focus:outline-none focus:border-emerald-500 transition"
/>
</div>
</div>
{/* Sort & New Workspace Button */}
<div className="flex items-center space-x-2.5">
<div className="flex items-center space-x-1.5 px-3 py-1.5 rounded-lg bg-[#0D1117] border border-[#30363D] text-xs text-slate-300">
<ArrowUpDown className="w-3 h-3 text-slate-400" />
<span className="text-slate-400">Sort:</span>
<select
value={sortBy}
onChange={(e) => setSortBy(e.target.value)}
className="bg-transparent text-white font-medium focus:outline-none cursor-pointer"
>
<option value="updated" className="bg-[#161B22]">Recently updated</option>
<option value="docs" className="bg-[#161B22]">Most documents</option>
<option value="facts" className="bg-[#161B22]">Most verified facts</option>
<option value="name" className="bg-[#161B22]">Name (A-Z)</option>
</select>
</div>
<Link
to="/new"
className="flex items-center space-x-1.5 px-3.5 py-1.5 rounded-lg bg-[#238636] hover:bg-[#2EA043] text-white font-bold text-xs shadow-md transition no-underline"
>
<Plus className="w-3.5 h-3.5" />
<span>New Workspace</span>
</Link>
</div>
</div>
{/* Multi-Select & Batch Deletion Bar */}
{workspaces.length > 0 && (
<div className="bg-[#161B22] border border-[#30363D] rounded-xl px-4 py-2.5 flex flex-wrap items-center justify-between gap-3 text-xs">
<div className="flex items-center space-x-3">
<label className="flex items-center space-x-2 cursor-pointer font-semibold text-slate-300 hover:text-white select-none">
<input
type="checkbox"
checked={isAllSelected}
onChange={handleSelectAll}
className="w-4 h-4 rounded text-emerald-500 bg-[#0D1117] border-[#30363D] focus:ring-emerald-500 cursor-pointer"
/>
<span>Select All ({filteredWorkspaces.length})</span>
</label>
{selectedWsIds.length > 0 && (
<span className="px-2 py-0.5 rounded-full bg-emerald-500/20 text-emerald-400 font-bold font-mono text-[11px]">
{selectedWsIds.length} selected
</span>
)}
</div>
<div className="flex items-center space-x-2">
{selectedWsIds.length > 0 && (
<>
<button
type="button"
onClick={() => setSelectedWsIds([])}
className="px-2.5 py-1.5 rounded-lg bg-[#21262D] hover:bg-[#30363D] text-slate-300 font-medium transition"
>
Clear Selection
</button>
<button
type="button"
onClick={() => setConfirmDeleteModal({ type: 'selected', count: selectedWsIds.length })}
className="px-3 py-1.5 rounded-lg bg-rose-600 hover:bg-rose-500 text-white font-bold transition flex items-center space-x-1.5 shadow-md shadow-rose-600/20"
>
<Trash2 className="w-3.5 h-3.5" />
<span>Delete Selected ({selectedWsIds.length})</span>
</button>
</>
)}
<button
type="button"
onClick={() => setConfirmDeleteModal({ type: 'all', count: workspaces.length })}
className="px-3 py-1.5 rounded-lg bg-rose-950/40 hover:bg-rose-900/60 border border-rose-500/30 text-rose-300 hover:text-rose-100 font-semibold transition flex items-center space-x-1.5"
>
<Trash2 className="w-3.5 h-3.5 text-rose-400" />
<span>Delete All Workspaces</span>
</button>
</div>
</div>
)}
{/* Cards Grid */}
{filteredWorkspaces.length === 0 ? (
<div className="p-12 text-center border border-dashed border-[#30363D] rounded-2xl bg-[#0D1117] space-y-3">
<Layers className="w-10 h-10 text-slate-500 mx-auto" />
<h3 className="text-sm font-bold text-white">No workspaces found</h3>
<p className="text-xs text-slate-400 max-w-sm mx-auto">
No workspaces match your query. Try a different search term or create a new workspace.
</p>
<Link
to="/new"
className="px-4 py-2 rounded-lg bg-[#238636] hover:bg-[#2EA043] text-white text-xs font-bold transition inline-flex items-center space-x-1.5 no-underline"
>
<Plus className="w-3.5 h-3.5" />
<span>Create Workspace</span>
</Link>
</div>
) : (
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
{filteredWorkspaces.map((ws, idx) => {
const gradient = GRADIENTS[idx % GRADIENTS.length];
const isSelected = currentWorkspace?.id === ws.id;
return (
<Link
key={ws.id || idx}
to={`/workspaces/${ws.id}/diff`}
onClick={() => onSelectWorkspace && onSelectWorkspace(ws)}
className="group relative rounded-2xl overflow-hidden border border-[#30363D] hover:border-slate-500 bg-[#0D1117] transition-all duration-200 cursor-pointer shadow-lg hover:shadow-2xl flex flex-col justify-between block no-underline"
>
{/* Top Gradient Banner with Space Info */}
<div className={`p-5 bg-gradient-to-r ${gradient} relative`}>
<div className="flex items-center justify-between text-xs text-white/90 pb-2">
<div className="flex items-center space-x-2">
<input
type="checkbox"
checked={selectedWsIds.includes(ws.id)}
onChange={(e) => {
e.stopPropagation();
toggleSelectWs(ws.id);
}}
onClick={(e) => e.stopPropagation()}
className="w-4 h-4 rounded text-emerald-500 bg-black/40 border-white/30 focus:ring-emerald-500 cursor-pointer"
title="Select workspace"
/>
<span className="flex items-center space-x-1.5 px-2 py-0.5 rounded-full bg-black/30 backdrop-blur-sm text-[10px] font-bold text-emerald-300">
<span className="w-1.5 h-1.5 rounded-full bg-emerald-400" />
<span>Running</span>
</span>
<span className={`flex items-center space-x-1 px-2 py-0.5 rounded-full text-[10px] font-bold backdrop-blur-sm ${
ws.visibility === 'public'
? 'bg-sky-500/20 text-sky-200 border border-sky-400/30'
: 'bg-black/30 text-amber-300 border border-amber-400/30'
}`}>
{ws.visibility === 'public' ? (
<Globe className="w-2.5 h-2.5" />
) : (
<Lock className="w-2.5 h-2.5" />
)}
<span className="capitalize">{ws.visibility || 'Private'}</span>
</span>
{ws.template && ws.template !== 'empty' && (
<span className="hidden sm:inline-block px-1.5 py-0.5 rounded-full text-[9px] font-mono bg-black/40 text-slate-200 border border-white/20">
{TEMPLATES_CATALOG[ws.template]?.name || ws.template}
</span>
)}
</div>
<div className="flex items-center space-x-1.5">
<button
type="button"
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
setConfirmDeleteModal({ type: 'single', ws });
}}
className="p-1 rounded-md bg-black/40 hover:bg-rose-600 text-white/70 hover:text-white transition shadow-sm"
title={`Delete ${ws.name}`}
>
<Trash2 className="w-3.5 h-3.5" />
</button>
<span className="text-white/60 group-hover:text-white transition">
→
</span>
</div>
</div>
<div className="space-y-1">
<h3 className="text-base font-extrabold text-white tracking-tight flex items-center space-x-1.5">
<span className="truncate">{ws.name}</span>
<span className="text-sm">{idx % 2 === 0 ? '🚀' : '⚡'}</span>
</h3>
<p className="text-xs text-white/80 line-clamp-1 font-medium">
{ws.description || `${ws.d_count ?? 0} documents • ${ws.k_count ?? 0} verified facts`}
</p>
</div>
</div>
{/* Bottom Metadata Bar */}
<div className="p-3.5 bg-[#010409] flex items-center justify-between text-xs text-slate-400 border-t border-[#21262D]">
<div className="flex items-center space-x-2">
<div className="w-4 h-4 rounded-full bg-rose-500 text-white font-bold flex items-center justify-center text-[9px]">
{username[0]?.toUpperCase() || 'A'}
</div>
<span className="text-[11px] font-mono text-slate-300">@{username}</span>
<span className="text-slate-600">•</span>
<span className="text-[11px] text-slate-500">2 minutes ago</span>
</div>
<div className="flex items-center space-x-3 text-[11px] font-mono">
<span className="flex items-center space-x-1 bg-[#161B22] px-2 py-0.5 rounded border border-[#30363D]" title="Tracked Documents">
<Files className="w-3 h-3 text-sky-400" />
<span>{ws.d_count ?? 0}</span>
</span>
<span className="flex items-center space-x-1 bg-[#161B22] px-2 py-0.5 rounded border border-[#30363D]" title="Verified Knowledge Items">
<Database className="w-3 h-3 text-emerald-400" />
<span>{ws.k_count ?? 0}</span>
</span>
</div>
</div>
</Link>
);
})}
</div>
)}
</div>
</div>
{/* ===================================================================== */}
{/* USER PROFILE MODAL */}
{/* ===================================================================== */}
{(showProfileModal || location.pathname === '/profile') && (
<div className="fixed inset-0 z-50 bg-black/80 backdrop-blur-sm flex items-center justify-center p-4">
<div className="bg-[#0D1117] border border-[#30363D] rounded-2xl max-w-lg w-full p-6 space-y-6 shadow-2xl text-slate-200">
<div className="flex items-center justify-between pb-3 border-b border-[#30363D]">
<div className="flex items-center space-x-2">
<User className="w-5 h-5 text-emerald-400" />
<h3 className="text-base font-bold text-white">Developer Profile</h3>
</div>
<button
onClick={() => { setShowProfileModal(false); if (location.pathname === "/profile") navigate("/"); }}
className="text-slate-400 hover:text-white p-1 rounded-lg hover:bg-[#21262D] transition"
>
<X className="w-5 h-5" />
</button>
</div>
<div className="flex items-center space-x-4">
<div className="w-16 h-16 rounded-full bg-gradient-to-tr from-pink-500 to-rose-600 flex items-center justify-center text-white text-2xl font-bold shadow-lg">
{username[0]?.toUpperCase() || 'A'}
</div>
<div className="space-y-1">
<div className="flex items-center space-x-2">
<h4 className="text-base font-bold text-white">{displayName}</h4>
<span className="px-2 py-0.5 rounded-full text-[10px] font-bold bg-emerald-500/20 text-emerald-300 border border-emerald-500/30">
PRO
</span>
</div>
<p className="text-xs text-slate-400 font-mono">{email}</p>
<p className="text-[11px] text-slate-500 font-mono">Role: {currentUser?.role || 'Operator'}</p>
</div>
</div>
{/* API Key Section */}
<div className="space-y-2 bg-[#161B22] p-4 rounded-xl border border-[#30363D]">
<div className="flex items-center justify-between text-xs">
<span className="font-semibold text-slate-300 flex items-center space-x-1.5">
<Key className="w-3.5 h-3.5 text-emerald-400" />
<span>Personal Access Token</span>
</span>
<button
onClick={() => setShowKeyRaw(!showKeyRaw)}
className="text-slate-400 hover:text-white text-xs flex items-center space-x-1 transition"
>
{showKeyRaw ? <EyeOff className="w-3.5 h-3.5" /> : <Eye className="w-3.5 h-3.5" />}
<span>{showKeyRaw ? 'Hide' : 'Reveal'}</span>
</button>
</div>
<div className="flex items-center space-x-2">
<input
type={showKeyRaw ? 'text' : 'password'}
readOnly
value={token}
className="flex-1 px-3 py-2 rounded-lg bg-[#0D1117] border border-[#30363D] text-xs font-mono text-emerald-400 focus:outline-none select-all"
/>
<button
onClick={handleCopyKey}
className="px-3 py-2 rounded-lg bg-[#21262D] hover:bg-[#30363D] border border-[#30363D] text-xs font-bold text-white flex items-center space-x-1.5 transition"
>
{copiedKey ? <CheckCircle2 className="w-3.5 h-3.5 text-emerald-400" /> : <Copy className="w-3.5 h-3.5" />}
<span>{copiedKey ? 'Copied' : 'Copy'}</span>
</button>
</div>
<p className="text-[11px] text-slate-400">
Use this token with the CLI: <code className="text-emerald-400">dw login --token <token></code>
</p>
</div>
{/* Stats */}
<div className="grid grid-cols-2 gap-3 text-center">
<div className="p-3 rounded-xl bg-[#161B22] border border-[#30363D]">
<span className="text-lg font-bold text-white block">{workspaces.length}</span>
<span className="text-[11px] text-slate-400">Active Workspaces</span>
</div>
<div className="p-3 rounded-xl bg-[#161B22] border border-[#30363D]">
<span className="text-lg font-bold text-emerald-400 block">{totalVerifiedFacts}</span>
<span className="text-[11px] text-slate-400">Verified Knowledge Facts</span>
</div>
</div>
{/* Footer Buttons */}
<div className="flex items-center justify-between pt-2 border-t border-[#30363D]">
{onLogout && (
<button
onClick={() => {
setShowProfileModal(false);
onLogout();
}}
className="px-3.5 py-1.5 rounded-lg bg-rose-500/10 hover:bg-rose-500/20 text-rose-400 text-xs font-bold border border-rose-500/30 flex items-center space-x-1.5 transition"
>
<LogOut className="w-3.5 h-3.5" />
<span>Log out</span>
</button>
)}
<button
onClick={() => { setShowProfileModal(false); if (location.pathname === "/profile") navigate("/"); }}
className="ml-auto px-4 py-1.5 rounded-lg bg-[#21262D] hover:bg-[#30363D] text-white text-xs font-bold transition"
>
Close
</button>
</div>
</div>
</div>
)}
{/* ===================================================================== */}
{/* SETTINGS MODAL */}
{/* ===================================================================== */}
{(showSettingsModal || location.pathname === '/settings') && (
<div className="fixed inset-0 z-50 bg-black/80 backdrop-blur-sm flex items-center justify-center p-4">
<div className="bg-[#0D1117] border border-[#30363D] rounded-2xl max-w-lg w-full p-6 space-y-6 shadow-2xl text-slate-200">
<div className="flex items-center justify-between pb-3 border-b border-[#30363D]">
<div className="flex items-center space-x-2">
<Sliders className="w-5 h-5 text-emerald-400" />
<h3 className="text-base font-bold text-white">Platform Settings</h3>
</div>
<button
onClick={() => { setShowSettingsModal(false); if (location.pathname === "/settings") navigate("/"); }}
className="text-slate-400 hover:text-white p-1 rounded-lg hover:bg-[#21262D] transition"
>
<X className="w-5 h-5" />
</button>
</div>
<div className="space-y-4 text-xs">
{/* Interface Theme Toggle */}
<div className="space-y-2 bg-[#161B22] p-4 rounded-xl border border-[#30363D]">
<div className="flex items-center justify-between">
<span className="font-semibold text-slate-200 flex items-center space-x-1.5">
<Sun className="w-3.5 h-3.5 text-amber-400" />
<span>Interface Theme</span>
</span>
<span className="text-[10px] font-mono px-2 py-0.5 rounded bg-emerald-500/10 text-emerald-400 border border-emerald-500/20 font-bold uppercase">
{theme} Mode Active
</span>
</div>
<p className="text-[11px] text-slate-400">
Select your preferred appearance for semantic diffs, knowledge graphs, and doc staging.
</p>
<div className="grid grid-cols-2 gap-2 pt-1">
<button
type="button"
onClick={() => setTheme('dark')}
className={`px-3 py-2 rounded-lg border text-xs font-semibold flex items-center justify-center space-x-2 transition ${
theme === 'dark'
? 'bg-emerald-500/15 border-emerald-500 text-emerald-300 font-bold shadow-sm'
: 'bg-[#0D1117] border-[#30363D] text-slate-400 hover:text-slate-200 hover:bg-[#21262D]'
}`}
>
<Moon className="w-4 h-4 text-indigo-400" />
<span>Dark Mode</span>
</button>
<button
type="button"
onClick={() => setTheme('light')}
className={`px-3 py-2 rounded-lg border text-xs font-semibold flex items-center justify-center space-x-2 transition ${
theme === 'light'
? 'bg-emerald-500/15 border-emerald-500 text-emerald-300 font-bold shadow-sm'
: 'bg-[#0D1117] border-[#30363D] text-slate-400 hover:text-slate-200 hover:bg-[#21262D]'
}`}
>
<Sun className="w-4 h-4 text-amber-400" />
<span>Light Mode</span>
</button>
</div>
</div>
{/* Confidence Threshold Slider */}
<div className="space-y-2 bg-[#161B22] p-4 rounded-xl border border-[#30363D]">
<div className="flex items-center justify-between">
<span className="font-semibold text-slate-200">Policy CI Confidence Threshold</span>
<span className="font-mono font-bold text-emerald-400 bg-black/40 px-2 py-0.5 rounded">
{confidenceThreshold}%
</span>
</div>
<input
type="range"
min="80"
max="98"
value={confidenceThreshold}
onChange={(e) => setConfidenceThreshold(parseInt(e.target.value, 10))}
className="w-full accent-emerald-500 cursor-pointer"
/>
<p className="text-[11px] text-slate-400">
Document claims extracted below this score trigger a CI review requirement before merging.
</p>
</div>
{/* FastMCP Endpoint URL */}
<div className="space-y-2 bg-[#161B22] p-4 rounded-xl border border-[#30363D]">
<div className="flex items-center justify-between">
<span className="font-semibold text-slate-200 flex items-center space-x-1.5">
<Server className="w-3.5 h-3.5 text-sky-400" />
<span>FastMCP Bridge URL</span>
</span>
{testConnStatus === 'connected' && (
<span className="text-[10px] text-emerald-400 font-bold flex items-center space-x-1">
<Check className="w-3 h-3" />
<span>Connected (29 Tools)</span>
</span>
)}
</div>
<div className="flex items-center space-x-2">
<input
type="text"
value={mcpUrl}
onChange={(e) => setMcpUrl(e.target.value)}
className="flex-1 px-3 py-2 rounded-lg bg-[#0D1117] border border-[#30363D] text-xs font-mono text-white focus:outline-none focus:border-emerald-500"
/>
<button
onClick={handleTestConnection}
className="px-3 py-2 rounded-lg bg-[#21262D] hover:bg-[#30363D] border border-[#30363D] text-xs font-semibold text-slate-200 transition"
>
{testConnStatus === 'testing' ? 'Testing...' : 'Test'}
</button>
</div>
</div>
{/* Auto Sync Interval */}
<div className="space-y-2 bg-[#161B22] p-4 rounded-xl border border-[#30363D]">
<label className="font-semibold text-slate-200 block">Workspace Background Sync</label>
<select
value={autoSyncInterval}
onChange={(e) => setAutoSyncInterval(e.target.value)}
className="w-full px-3 py-2 rounded-lg bg-[#0D1117] border border-[#30363D] text-xs text-white focus:outline-none focus:border-emerald-500 cursor-pointer"
>
<option value="manual">Manual Refresh (Sync button)</option>
<option value="30s">Every 30 seconds</option>
<option value="60s">Every 60 seconds</option>
</select>
</div>
</div>
<div className="flex items-center justify-end space-x-2 pt-2 border-t border-[#30363D]">
<button
onClick={() => { setShowSettingsModal(false); if (location.pathname === "/settings") navigate("/"); }}
className="px-4 py-1.5 rounded-lg bg-[#21262D] hover:bg-[#30363D] text-slate-300 text-xs font-medium transition"
>
Cancel
</button>
<button
onClick={handleSaveSettings}
className="px-4 py-1.5 rounded-lg bg-[#238636] hover:bg-[#2EA043] text-white text-xs font-bold transition shadow"
>
Save Preferences
</button>
</div>
</div>
</div>
)}
{/* CREATE WORKSPACE MODAL DEPRECATED (MOVED TO /new PAGE) */}
{false && (
<div className="fixed inset-0 z-50 bg-black/80 backdrop-blur-sm flex items-center justify-center p-4 overflow-y-auto">
<div className="bg-[#0D1117] border border-[#30363D] rounded-2xl max-w-2xl w-full p-6 sm:p-8 space-y-6 shadow-2xl text-slate-200">
{/* Modal Header */}
<div className="flex items-start justify-between pb-3 border-b border-[#30363D]">
<div>
<h2 className="text-xl font-bold text-white tracking-tight">Create a new workspace</h2>
<p className="text-xs text-slate-400 mt-1">
Workspaces contain your documents, version history, knowledge graph, and deterministic CI rules.{' '}
<button
type="button"
onClick={() => setShowLearnMore(!showLearnMore)}
className="text-emerald-400 hover:underline font-semibold cursor-pointer ml-1"
>
{showLearnMore ? 'Hide guide' : 'Learn more'}
</button>
</p>
</div>
<button
onClick={() => setShowCreateModal(false)}
className="text-slate-400 hover:text-white p-1 rounded-lg hover:bg-[#21262D] transition"
>
<X className="w-5 h-5" />
</button>
</div>
{/* LEARN MORE EXPANDABLE ARCHITECTURE GUIDE */}
{showLearnMore && (
<div className="bg-[#161B22] border border-emerald-500/30 rounded-xl p-4 space-y-3 text-xs">
<div className="flex items-center space-x-2 text-emerald-400 font-bold">
<BookOpen className="w-4 h-4" />
<span>How DiffWeave Workspaces Function</span>
</div>
<div className="grid grid-cols-1 sm:grid-cols-2 gap-3 text-slate-300">
<div className="p-2.5 rounded-lg bg-[#0D1117] border border-[#30363D] space-y-1">
<span className="font-bold text-white block">1. Isolated Knowledge Registers</span>
<p className="text-[11px] text-slate-400">
Each workspace is an isolated repository. Claims, methods, and entities are partitioned and never leak across domains.
</p>
</div>
<div className="p-2.5 rounded-lg bg-[#0D1117] border border-[#30363D] space-y-1">
<span className="font-bold text-white block">2. Semantic Knowledge Pull Requests</span>
<p className="text-[11px] text-slate-400">
New documents produce atomic proposals rather than raw overwrites. Review diffs visually before merging into main.
</p>
</div>
<div className="p-2.5 rounded-lg bg-[#0D1117] border border-[#30363D] space-y-1">
<span className="font-bold text-white block">3. Automated Policy CI Linting</span>
<p className="text-[11px] text-slate-400">
Enforce confidence thresholds, citation evidence, and contradiction blockers on every ingested page.
</p>
</div>
<div className="p-2.5 rounded-lg bg-[#0D1117] border border-[#30363D] space-y-1">
<span className="font-bold text-white block">4. Universal FastMCP Engine</span>
<p className="text-[11px] text-slate-400">
29 MCP tools allow Claude, Cursor, and terminal CLI (`dw`) to query or commit to this workspace.
</p>
</div>
</div>
</div>
)}
<form onSubmit={handleCreateSubmit} className="space-y-6 text-xs">
{/* STEP 1: General */}
<div className="space-y-4">
<div className="flex items-center space-x-2 text-white font-bold text-sm">
<span className="w-5 h-5 rounded-full bg-[#21262D] text-slate-300 font-mono text-xs flex items-center justify-center">1</span>
<span>General</span>
</div>
<div className="grid grid-cols-1 sm:grid-cols-12 gap-3 items-end">
{/* Owner Dropdown */}
<div className="sm:col-span-5 space-y-1">
<label className="text-xs font-semibold text-slate-300">
Owner <span className="text-rose-400">*</span>
</label>
<div className="flex items-center justify-between px-3 py-2 rounded-lg bg-[#161B22] border border-[#30363D] text-white">
<div className="flex items-center space-x-2">
<div className="w-4 h-4 rounded-full bg-pink-500 flex items-center justify-center text-[9px] text-white font-bold">
{username[0]?.toUpperCase() || 'A'}
</div>
<span className="font-semibold text-xs truncate max-w-[120px]">{username}</span>
</div>
<ChevronDown className="w-3.5 h-3.5 text-slate-400 shrink-0" />
</div>
</div>
<div className="hidden sm:flex sm:col-span-1 justify-center items-center pb-2 text-slate-500 font-bold text-lg">
/
</div>
{/* Workspace Name Input */}
<div className="sm:col-span-6 space-y-1">
<label className="text-xs font-semibold text-slate-300">
Workspace name <span className="text-rose-400">*</span>
</label>
<input
type="text"
required
value={wsName}
onChange={(e) => setWsName(e.target.value)}
placeholder={suggestedName}
className="w-full px-3 py-2 rounded-lg bg-[#161B22] border border-[#30363D] text-xs text-white placeholder-slate-500 focus:outline-none focus:border-emerald-500 font-mono"
/>
</div>
</div>
<p className="text-[11px] text-slate-400">
Great workspace names are short and memorable. How about{' '}
<span
onClick={() => setWsName(suggestedName)}
className="text-emerald-400 font-semibold hover:underline cursor-pointer"
>
{suggestedName}
</span>
?
</p>
{/* Description */}
<div className="space-y-1">
<div className="flex items-center justify-between text-xs">
<label className="font-semibold text-slate-300">Description (optional)</label>
<span className="text-[10px] text-slate-500">{wsDesc.length} / 350 characters</span>
</div>
<input
type="text"
maxLength={350}
value={wsDesc}
onChange={(e) => setWsDesc(e.target.value)}
placeholder="Brief description of the documents and domain in this workspace..."
className="w-full px-3 py-2 rounded-lg bg-[#161B22] border border-[#30363D] text-xs text-white placeholder-slate-500 focus:outline-none focus:border-emerald-500"
/>
</div>
</div>
{/* STEP 2: Domain Archetype & Specialized Template (Hugging Face Style) */}
<div className="space-y-4 pt-2 border-t border-[#30363D]">
<div className="flex items-center justify-between text-white font-bold text-sm">
<div className="flex items-center space-x-2">
<span className="w-5 h-5 rounded-full bg-[#21262D] text-slate-300 font-mono text-xs flex items-center justify-center">2</span>
<span>1. Select Workspace Domain (Parent Archetype)</span>
</div>
<span className="text-[10px] text-slate-500 font-mono">Hugging Face 2-Tier Selector</span>
</div>
{/* TIER 1: Parent Domain Categories */}
<div className="grid grid-cols-2 sm:grid-cols-3 gap-2.5">
{PARENT_CATEGORIES.map((cat) => {
const isSelected = selectedParent === cat.id;
return (
<button
key={cat.id}
type="button"
onClick={() => {
setSelectedParent(cat.id);
const firstChild = Object.values(TEMPLATES_CATALOG).find((c) => c.parentId === cat.id);
if (firstChild) handleSelectChildTemplate(firstChild.id);
}}
className={`p-3 rounded-xl border text-left transition flex flex-col justify-between ${
isSelected
? 'border-emerald-500 bg-emerald-500/10 shadow-sm shadow-emerald-500/20'
: 'border-[#30363D] bg-[#161B22] text-slate-400 hover:border-slate-600 hover:text-white'
}`}
>
<div className="flex items-center justify-between w-full mb-1">
<span className={`text-xs font-bold ${isSelected ? 'text-white' : 'text-slate-300'}`}>
{cat.name}
</span>
<span className="text-[9px] font-mono px-1.5 py-0.2 rounded bg-slate-800 text-slate-400 border border-slate-700">
{cat.badge}
</span>
</div>
<span className="text-[10px] text-slate-500 block leading-tight">
{cat.tagline}
</span>
</button>
);
})}
</div>
{/* TIER 2: Child Templates in Selected Parent Category */}
<div className="space-y-2 pt-2">
<div className="flex items-center justify-between">
<label className="text-xs font-semibold text-slate-300">
2. Choose a specialized template:
</label>
<span className="text-[10px] text-emerald-400 font-mono">
Domain Quality Gates
</span>
</div>
<div className="grid grid-cols-1 sm:grid-cols-2 gap-2.5 text-xs">
{Object.values(TEMPLATES_CATALOG)
.filter((tmpl) => tmpl.parentId === selectedParent)
.map((tmpl) => {
const isSelected = starterTemplate === tmpl.id;
return (
<button
key={tmpl.id}
type="button"
onClick={() => handleSelectChildTemplate(tmpl.id)}
className={`p-3 rounded-xl border text-left transition flex flex-col justify-between space-y-2 ${
isSelected
? 'border-emerald-500 bg-emerald-500/10 shadow-sm shadow-emerald-500/10'
: 'border-[#30363D] bg-[#161B22] text-slate-400 hover:border-slate-600 hover:text-white'
}`}
>
<div className="flex items-start justify-between w-full gap-2">
<div>
<span className="font-bold text-slate-200 block text-xs">{tmpl.name}</span>
<span className="text-[10px] text-slate-400 block pt-0.5 leading-snug">{tmpl.tagline}</span>
</div>
<span
className={`text-[9px] font-mono px-1.5 py-0.2 rounded font-bold shrink-0 ${
tmpl.defaultVisibility === 'private'
? 'bg-amber-500/20 text-amber-300 border border-amber-500/30'
: 'bg-sky-500/20 text-sky-300 border border-sky-500/30'
}`}
>
{tmpl.defaultVisibility === 'private' ? '🔒 Private' : '🌍 Public'}
</span>
</div>
<div className="flex items-center justify-between w-full pt-1.5 border-t border-slate-800/80 text-[10px]">
<span className="font-mono text-emerald-400 font-semibold">
{tmpl.policyRules?.length || 2} Policy CI Rules
</span>
<span className="text-slate-500 font-mono">
{(tmpl.recommendedFiles || []).join(', ')}
</span>
</div>
</button>
);
})}
</div>
</div>
{/* LIVE RULE INSPECTOR DRAWER */}
{TEMPLATES_CATALOG[starterTemplate] && (
<div className="p-3.5 rounded-xl border border-slate-800 bg-[#0C101A] space-y-2 text-xs">
<div className="flex items-center justify-between">
<div className="flex items-center space-x-2">
<ShieldCheck className="w-4 h-4 text-emerald-400" />
<span className="text-xs font-bold text-white font-mono uppercase tracking-wider">
Pre-Configured Policy as Code CI Suite:
</span>
</div>
<span className="text-[10px] text-slate-400 font-mono">
{TEMPLATES_CATALOG[starterTemplate].policyRules?.length} Active Guardrails
</span>
</div>
<div className="space-y-1.5 text-[11px] font-mono">
{(TEMPLATES_CATALOG[starterTemplate].policyRules || []).map((rule, idx) => (
<div key={idx} className="flex items-start justify-between gap-2 p-1.5 rounded bg-[#121726] border border-slate-800/80">
<div className="space-y-0.5">
<span className="text-slate-200 font-semibold block">{rule.name}</span>
<span className="text-slate-400 text-[10px] font-sans block">{rule.description}</span>
</div>
<span
className={`text-[9px] font-bold px-1.5 py-0.2 rounded shrink-0 ${
rule.is_blocking
? 'bg-rose-500/20 text-rose-300 border border-rose-500/30'
: 'bg-amber-500/20 text-amber-300 border border-amber-500/30'
}`}
>
{rule.is_blocking ? 'BLOCKING GATE' : 'ADVISORY'}
</span>
</div>
))}
</div>
</div>
)}
{/* STEP 3: Choose Visibility with Smart Contextual Hint */}
<div className="space-y-2 pt-2 border-t border-[#30363D]">
<div className="flex items-center justify-between">
<label className="text-xs font-semibold text-slate-300">Choose visibility *</label>
<span className="text-[10px] text-slate-400">
{TEMPLATES_CATALOG[starterTemplate]?.defaultVisibility === 'private'
? '🛡️ Recommended Private for confidential records'
: '🌍 Recommended Public for open specifications'}
</span>
</div>
<div className="grid grid-cols-1 sm:grid-cols-2 gap-3">
<label
onClick={() => setWsVisibility('public')}
className={`p-3 rounded-xl border flex items-start space-x-3 cursor-pointer transition ${
wsVisibility === 'public'
? 'border-sky-500 bg-sky-500/10 shadow-sm'
: 'border-[#30363D] bg-[#161B22] hover:border-slate-500'
}`}
>
<Globe className="w-4 h-4 text-sky-400 mt-0.5 shrink-0" />
<div>
<div className="flex items-center space-x-1.5">
<span className="font-bold text-white block">Public</span>
{wsVisibility === 'public' && <span className="text-[9px] font-mono text-sky-300 font-bold">✓</span>}
</div>
<span className="text-[11px] text-slate-400">Anyone on DiffWeave can query verified truth from this workspace.</span>
</div>
</label>
<label
onClick={() => setWsVisibility('private')}
className={`p-3 rounded-xl border flex items-start space-x-3 cursor-pointer transition ${
wsVisibility === 'private'
? 'border-amber-500 bg-amber-500/10 shadow-sm'
: 'border-[#30363D] bg-[#161B22] hover:border-slate-500'
}`}
>
<Lock className="w-4 h-4 text-amber-400 mt-0.5 shrink-0" />
<div>
<div className="flex items-center space-x-1.5">
<span className="font-bold text-white block">Private</span>
{wsVisibility === 'private' && <span className="text-[9px] font-mono text-amber-300 font-bold">✓</span>}
</div>
<span className="text-[11px] text-slate-400">You choose who can see, query, and commit to this workspace.</span>
</div>
</label>
</div>
</div>
</div>
{/* Submit Buttons */}
<div className="pt-4 border-t border-[#30363D] flex items-center justify-end space-x-3">
<button
type="button"
onClick={() => setShowCreateModal(false)}
className="px-4 py-2 rounded-lg bg-[#21262D] hover:bg-[#30363D] text-slate-300 font-semibold transition"
>
Cancel
</button>
<button
type="submit"
className="px-5 py-2 rounded-lg bg-[#238636] hover:bg-[#2EA043] text-white font-bold transition shadow-lg flex items-center space-x-1.5"
>
<Plus className="w-4 h-4" />
<span>Create workspace</span>
</button>
</div>
</form>
</div>
</div>
)}
{/* ===================================================================== */}
{/* DELETE WORKSPACE CONFIRMATION MODAL */}
{/* ===================================================================== */}
{confirmDeleteModal && (
<div className="fixed inset-0 z-50 bg-black/80 backdrop-blur-sm flex items-center justify-center p-4">
<div className="bg-[#161B22] border border-[#30363D] rounded-2xl max-w-md w-full p-6 space-y-5 shadow-2xl text-slate-200">
<div className="flex items-center space-x-3 text-rose-400">
<div className="p-2.5 rounded-xl bg-rose-500/10 border border-rose-500/20">
<AlertTriangle className="w-6 h-6 text-rose-400" />
</div>
<div>
<h3 className="text-base font-bold text-white">
{confirmDeleteModal.type === 'single'
? `Delete Workspace "${confirmDeleteModal.ws?.name}"?`
: confirmDeleteModal.type === 'selected'
? `Delete ${confirmDeleteModal.count} Selected Workspaces?`
: `Delete All ${confirmDeleteModal.count} Workspaces?`}
</h3>
<p className="text-xs text-slate-400 mt-1">
{confirmDeleteModal.type === 'all'
? 'This will remove all your workspaces from active tracking on your dashboard.'
: 'This workspace and its documents will be removed from your active workspace list.'}
</p>
</div>
</div>
<div className="flex items-center justify-end space-x-3 pt-3 border-t border-[#30363D]">
<button
type="button"
disabled={isDeleting}
onClick={() => setConfirmDeleteModal(null)}
className="px-4 py-2 rounded-lg bg-[#21262D] hover:bg-[#30363D] text-slate-300 font-semibold text-xs transition"
>
Cancel
</button>
<button
type="button"
disabled={isDeleting}
onClick={executeDelete}
className="px-4 py-2 rounded-lg bg-rose-600 hover:bg-rose-500 text-white font-bold text-xs transition shadow-lg shadow-rose-600/20 flex items-center space-x-1.5"
>
{isDeleting ? (
<div className="w-3.5 h-3.5 border-2 border-white border-t-transparent rounded-full animate-spin"></div>
) : (
<Trash2 className="w-3.5 h-3.5" />
)}
<span>{isDeleting ? 'Deleting...' : 'Yes, Delete'}</span>
</button>
</div>
</div>
</div>
)}
</div>
);
} |