export type TWorkspaceView = 'inbox' | 'compose' | 'sign' | 'audit' | 'developers' | 'templates' | 'team' | 'settings'; export type TRecipientRole = 'signer' | 'copy' | 'updates'; export interface IAppDocumentRow { id: string; title: string; status: 'awaiting' | 'signed' | 'draft' | 'declined'; recipients: Array<{ name: string; initials: string; signed: boolean }>; updated: string; sender: string; pages: number; deadline?: string; } export interface IAppRecipient { id: number; name: string; email: string; color: string; order: number; role: TRecipientRole; } export interface IAppFieldPlacement { id: string; type: 'signature' | 'date' | 'text' | 'initials' | 'check'; x: number; y: number; w: number; h: number; page: number; recipient: number; label: string; } export const workspaceViews: TWorkspaceView[] = ['inbox', 'compose', 'sign', 'audit', 'developers', 'templates', 'team', 'settings']; export const appDocuments: IAppDocumentRow[] = [ { id: 'app_doc_001', title: 'Platform Services Agreement - App-owned data', status: 'awaiting', recipients: [{ name: 'Sarah Chen', initials: 'SC', signed: true }, { name: 'David Park', initials: 'DP', signed: false }], updated: 'just now', sender: 'App Service', pages: 14, deadline: 'May 5' }, { id: 'app_doc_002', title: 'Security Addendum - Catalog Integration', status: 'draft', recipients: [{ name: 'Philipp K.', initials: 'PK', signed: false }], updated: '12 min ago', sender: 'App Service', pages: 5 }, { id: 'app_doc_003', title: 'Completed Vendor NDA - Signed from App', status: 'signed', recipients: [{ name: 'Lila Brooks', initials: 'LB', signed: true }, { name: 'Philipp K.', initials: 'PK', signed: true }], updated: '1h ago', sender: 'App Service', pages: 3 }, ]; export let appRecipients: IAppRecipient[] = [ { id: 0, name: 'Sarah Chen', email: 'sarah@acme.com', color: '#60a5fa', order: 1, role: 'signer' }, { id: 1, name: 'David Park', email: 'd.park@acme.com', color: '#fbbf24', order: 2, role: 'signer' }, { id: 2, name: 'Philipp K.', email: 'philipp@lossless.com', color: '#3b82f6', order: 3, role: 'updates' }, ]; const defaultFields: IAppFieldPlacement[] = [ { id: 'app_f1', type: 'signature', x: 60, y: 580, w: 200, h: 50, page: 1, recipient: 0, label: 'Signature' }, { id: 'app_f2', type: 'date', x: 320, y: 580, w: 120, h: 30, page: 1, recipient: 0, label: 'Date' }, { id: 'app_f3', type: 'text', x: 60, y: 460, w: 280, h: 30, page: 1, recipient: 1, label: 'Full legal name' }, { id: 'app_f4', type: 'signature', x: 60, y: 700, w: 200, h: 50, page: 1, recipient: 1, label: 'Counter-signature' }, ]; const appFieldsByDocument: Record = Object.fromEntries( appDocuments.map((document) => [document.id, defaultFields.map((field) => ({ ...field, id: `${document.id}_${field.id}` }))]) ); export const isWorkspaceView = (view: string): view is TWorkspaceView => workspaceViews.includes(view as TWorkspaceView); export const routeFromLocation = (): { view: TWorkspaceView; documentId: string } => { const [view = '', documentId = ''] = globalThis.location.hash.replace(/^#/, '').split(':'); return { view: isWorkspaceView(view) ? view : 'inbox', documentId }; }; export const hashForRoute = (view: TWorkspaceView, documentId = ''): string => { return documentId && (view === 'compose' || view === 'sign' || view === 'audit') ? `#${view}:${documentId}` : `#${view}`; }; export const documentIdOrDefault = (documentId: string): string => { return appDocuments.some((document) => document.id === documentId) ? documentId : appDocuments[0].id; }; export const fieldsForDocument = (documentId: string): IAppFieldPlacement[] => { return appFieldsByDocument[documentId] || []; }; export const setFieldsForDocument = (documentId: string, fields: IAppFieldPlacement[]) => { appFieldsByDocument[documentId] = fields; }; export const setAppRecipients = (recipients: IAppRecipient[]) => { appRecipients = recipients; };