'use client'
import { ControlDetail } from '../control-library/components/ControlDetail'
import { ControlListView } from '../control-library/components/ControlListView'
import { useControlLibraryState } from '../control-library/components/useControlLibraryState'
import { BACKEND_URL } from '../control-library/components/helpers'
/**
* Master Controls page — reuses the Control Library UI exactly,
* but shows Master Controls (13.5K grouped controls) instead of
* individual atomic controls (272K).
*
* The MC API route (/api/sdk/v1/master-controls) returns data in
* the same format as the canonical controls endpoint.
*/
export default function MasterControlsPage() {
// Reuse the exact same state hook — it fetches from BACKEND_URL
// We override BACKEND_URL via a wrapper, but for now we reuse as-is
// since both endpoints speak the same format.
const state = useControlLibraryState('/api/sdk/v1/master-controls')
if (state.loading && state.controls.length === 0) {
return (
)
}
if (state.error) {
return (
)
}
// DETAIL mode — add fallback fields that ControlDetail expects
if (state.mode === 'detail' && state.selectedControl) {
const c = state.selectedControl
const safeCtrl = {
...c,
scope: c.scope || { platforms: [], components: [], data_classes: [] },
target_audience: c.target_audience || [],
requirements: c.requirements || [],
test_procedure: c.test_procedure || [],
evidence: c.evidence || [],
open_anchors: c.open_anchors || [],
tags: c.tags || [],
risk_score: c.risk_score ?? null,
implementation_effort: c.implementation_effort ?? null,
generation_metadata: c.generation_metadata || null,
source_citation: c.source_citation || null,
source_original_text: c.source_original_text || '',
verification_method: c.verification_method || null,
evidence_type: c.evidence_type || null,
release_state: c.release_state || 'active',
category: c.category || 'master_control',
severity: c.severity || 'medium',
parent_control_uuid: c.parent_control_uuid || null,
similar_controls: c.similar_controls || [],
}
return (
{ state.setMode('list'); state.setSelectedControl(null) }}
onEdit={() => {}}
onDelete={async () => {}}
onReview={async () => {}}
onRefresh={state.fullReload}
onCompare={() => {}}
onNavigateToControl={async (controlId: string) => {
try {
const res = await fetch(`${BACKEND_URL}?endpoint=control&id=${controlId}`)
if (res.ok) { state.setSelectedControl(await res.json()); state.setMode('detail') }
} catch { /* ignore */ }
}}
/>
)
}
// LIST mode — exact same UI as Control Library
return (
{}}
setCurrentPage={state.setCurrentPage}
onSelectControl={(ctrl) => { state.setSelectedControl(ctrl); state.setMode('detail') }}
onCreateMode={() => {}}
onEnterReview={() => {}}
onBulkReject={async () => {}}
onRefresh={() => { state.loadControls(); state.loadMeta() }}
onLoadStats={state.loadProcessedStats}
onFullReload={state.fullReload}
/>
)
}