import {
	type AdminData,
	safeArray,
	safeRecord,
	textValue,
} from '../admin-data';
import type { DesignSystemViewModel } from './types';

export const buildDesignSystemViewModel = (
	data: AdminData
): DesignSystemViewModel => ( {
	applicationName: textValue(
		data.applicationName,
		"JJ's Post and Product Scheduler"
	),
	brandLogoFallbackUrl: textValue( data.brandLogoFallbackUrl ),
	brandLogoUrl: textValue( data.brandLogoUrl ),
	dateFormat: textValue( data.dateFormat ),
	timeFormat: textValue( data.timeFormat ),
	entitlementProfile: textValue( data.entitlementProfile ),
	notice: safeRecord( data.notice ),
	permissions: safeRecord( data.permissions ),
	actions: {
		adminPostUrl: textValue( data.adminPostUrl ),
		ajaxUrl: textValue( data.ajaxUrl ),
		nonce: textValue( data.nonce ),
		restUrl: textValue( data.restUrl ),
		restNonce: textValue( data.restNonce ),
	},
	navigation: safeArray( data.navigation ),
	dashboard: safeRecord( data.dashboardSummary ),
	calendar: safeArray( data.calendar ),
	launches: safeArray( data.launches ),
	runs: safeArray( data.runs ),
	recordings: safeArray( data.recordings ),
	targets: safeArray( data.targets ),
	recordableTargets: safeArray( data.recordableTargets ),
	fieldCatalog: safeArray( data.fieldCatalog ),
	supportedAreas: safeArray( data.supportedAreas ),
	notifications: safeArray( data.notifications ),
	notificationPreferences: safeRecord( data.notificationPreferences ),
	settingsState: safeRecord( data.settingsState ),
	system: safeArray( data.system ),
	adapters: safeArray( data.adapters ),
	featureDiagnostics: safeArray( data.featureDiagnostics ),
	ownershipCollisions: safeArray( data.ownershipCollisions ),
	schedulerDiagnostics: safeArray( data.schedulerDiagnostics ),
	scheduleDefaults: safeRecord( data.scheduleDefaults ),
	supportReportUrl: textValue( data.supportReportUrl ),
	approvalsActive: Boolean( data.approvalsActive ),
	futureSurfacesEnabled: Boolean( data.futureSurfacesEnabled ),
	source: data,
} );
