/**
 * Automation Section Builder
 *
 * Creates a detail page for a single automation.
 * Consumer provides content only; styling is handled internally.
 */

import type { Page, ListItem } from '../types'
import type { AutomationConfig } from './types'

/**
 * Creates an automation detail page with metrics, workflow, and impact
 *
 * @param config - Content-only configuration
 * @returns Page object ready for PDFDocument.pages array
 */
export function automationSection(config: AutomationConfig): Page {
  const { title, howItWorks, workflow, impact, hoursPerWeek, annualSavings } = config

  // Convert workflow items to ListItem format
  const workflowItems: ListItem[] = workflow.map(item => {
    if (typeof item === 'string') {
      return item
    }
    return { text: item.text, highlight: item.highlight }
  })

  return {
    sections: [
      // Inline metrics without card container for compactness
      {
        type: 'columns',
        content: [
          {
            type: 'metric',
            value: String(hoursPerWeek),
            label: 'Projected Hours/Week Saved'
          },
          {
            type: 'metric',
            value: `$${annualSavings.toLocaleString()}`,
            label: 'Projected Annual Savings'
          }
        ]
      },
      { type: 'text', content: 'How It Works', variant: 'subtitle' },
      { type: 'text', content: howItWorks, variant: 'body' },
      { type: 'text', content: 'Workflow', variant: 'subtitle' },
      { type: 'list', ordered: true, items: workflowItems },
      { type: 'text', content: 'Expected Impact', variant: 'subtitle' },
      { type: 'list', items: impact }
    ],
    header: { subtitle: 'Automation', title, variant: 'accent' },
    footer: true
  }
}
