import { importFromClient, listSpacesWithArtifactIds } from '../../../../../lib/dashboard-spaces.js';

export async function POST(request) {
  try {
    const body = await request.json().catch(() => ({}));
    const result = importFromClient({
      spaces: body?.spaces,
      active_space_id: body?.active_space_id,
    });
    if (!result) {
      return Response.json({ imported: false, ...listSpacesWithArtifactIds() });
    }
    return Response.json({ imported: true, ...result });
  } catch (err) {
    return Response.json({ error: err?.message || String(err) }, { status: 400 });
  }
}
