/**
 * Cover Section Builder
 *
 * Creates a styled cover page for proposals.
 * Consumer provides content only; styling is handled internally.
 */

import type { Page } from '../types'
import type { CoverConfig } from './types'

/**
 * Creates a cover page with company info, vertical, and solutions
 *
 * @param config - Content-only configuration
 * @returns Page object ready for PDFDocument.pages array
 */
export function coverSection(config: CoverConfig): Page {
  const {
    company,
    contact,
    vertical,
    solutions,
    date = new Date().toLocaleDateString('en-US', {
      year: 'numeric',
      month: 'long',
      day: 'numeric'
    }),
    logoSrc
  } = config

  // Build bottom left text - handle empty contact gracefully
  const preparedForText = contact && contact.trim()
    ? `Prepared for ${contact}`
    : 'Prepared for You'

  return {
    sections: [
      { type: 'text', content: company, variant: 'coverCompany' },
      { type: 'text', content: vertical, variant: 'coverVertical' },
      { type: 'text', content: solutions, variant: 'coverSolutions' }
    ],
    cover: {
      topLeft: logoSrc ? { src: logoSrc, width: 34 } : undefined,
      topRight: [{ type: 'text', content: 'AUTOMATION PROPOSAL', variant: 'caption' }],
      centerContent: true,
      bottomLeft: [{ type: 'text', content: preparedForText, variant: 'caption' }],
      bottomRight: [{ type: 'text', content: date, variant: 'caption' }]
    },
    footer: false
  }
}
