import {requireEnglishSurface} from './document-localization.js'; // @requirements REQ-EU-NOTICE REQ-US-CA-CHOICES REQ-US-VA-RIGHTS // @requirements REQ-PRODUCT-RIGHTS-CENTER REQ-PRODUCT-MOBILE REQ-PRODUCT-A11Y import {isSafeLink,toPublicConfig} from './config.js'; import {escapeHtml,renderLegalLinks} from './documents.js'; import type {ValidationOptions} from './types.js'; export type RightsCenterRenderOptions=ValidationOptions&{idPrefix?:string;headingLevel?:1|2|3|4|5}; /** Script-free entry points. Following a link never means a request was submitted or fulfilled. */ export function renderRightsCenter(input:unknown,options:RightsCenterRenderOptions={}):string { const mode=options.mode??'production';const config=toPublicConfig(input,{...options,mode}),center=config.rightsCenter;requireEnglishSurface(config,'Privacy request center');if(!center)throw new Error('Declare a rights center before rendering it.'); const id=options.idPrefix??'nb-rights';if(!/^[a-z][a-z0-9-]{0,79}$/u.test(id)||options.headingLevel!==undefined&&![1,2,3,4,5].includes(options.headingLevel))throw new Error('Use a unique lowercase ID prefix and a heading level from 1 to 5.'); const heading='h'+(options.headingLevel??2),sub='h'+((options.headingLevel??2)+1),e=escapeHtml; return `

${e(config.site.name)} · Your information

<${heading} id="${id}-title">${e(center.title)}

${e(center.intro)}

${center.reviewStatus==='draft'?'

Draft rights information — for review.

':''}
${center.actions.map((action,index)=>`
<${sub} id="${id}-${action.id}-title">${e(action.title)}

${e(action.description)}

${e(action.scope)}

${e(action.link.label)}
`).join('')}
<${sub} id="${id}-next">What happens next
    ${center.nextSteps.map(step=>`
  1. ${e(step)}
  2. `).join('')}
`; } /** Supporting navigation page, separate from the three immutable legal-document kinds. */ export function renderRightsPage(input:unknown,options:ValidationOptions&{stylesheetUrl?:string}={}):string { const mode=options.mode??'production';const config=toPublicConfig(input,{...options,mode}),center=config.rightsCenter;requireEnglishSurface(config,'Privacy request center');if(!center)throw new Error('Declare a rights center before rendering it.'); const stylesheet=options.stylesheetUrl;if(stylesheet!==undefined&&!isSafeLink(stylesheet))throw new Error('Unsafe stylesheet URL.');const e=escapeHtml; return `${e(center.title)} · ${e(config.site.name)}${stylesheet?``:''}Skip to content
${e(config.site.name)}Privacy requests
${renderRightsCenter(config,{...options,mode,headingLevel:1})}
`; }