/**
 * Acceptance Section Builder
 *
 * Creates a dedicated signature/acceptance page for proposals.
 * This page contains minimal terms and signature fields placement area.
 *
 * Pattern: Content-only configuration, styling handled by theme system.
 *
 * @example
 * ```typescript
 * import { acceptanceSection } from '@repo/core/pdf/sections'
 *
 * const page = acceptanceSection({
 *   companyName: 'Acme Corp',
 *   contactName: 'John Smith',
 *   tier: 'tier2',
 *   initialFee: 5000,
 *   monthlyFee: 2500  // optional
 * })
 * ```
 */

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

/**
 * Configuration for acceptance section
 */
export interface AcceptanceSectionConfig {
  /** Company name for personalization */
  companyName: string
  /** Contact name for personalization */
  contactName: string
  /** Service tier being proposed */
  tier: 'tier1' | 'tier2' | 'tier3' | 'custom'
  /** Initial fee amount in dollars (one-time implementation fee) */
  initialFee: number
  /** Monthly fee amount in dollars (optional, for ongoing support) */
  monthlyFee?: number
  /** Name of the service provider issuing the proposal (e.g. "Elevasis") */
  providerName: string
}

/**
 * Build acceptance page with simplified terms and signature area
 *
 * Creates a dedicated page at the end of the proposal with:
 * - Pricing summary
 * - Key terms (audit timeline, training, support, guarantee)
 * - Acceptance statement
 * - Space for electronic signature fields (added by SignatureAPI)
 *
 * @param config - Acceptance section configuration
 * @returns Page structure for terms and acceptance
 */
export function acceptanceSection(config: AcceptanceSectionConfig): Page {
  const { companyName, contactName, tier, initialFee, monthlyFee, providerName } = config

  const tierDescriptions = {
    tier1: 'Standard Implementation',
    tier2: 'Professional Implementation',
    tier3: 'Enterprise Implementation',
    custom: 'Custom Implementation'
  }

  // Build simplified terms list
  const terms: string[] = [
    `Initial fee: $${initialFee.toLocaleString()} (${tierDescriptions[tier]})`,
    ...(monthlyFee ? [`Monthly fee: $${monthlyFee.toLocaleString()}/month`] : []),
    'Detailed audit begins within 5 business days of payment',
    'Training materials provided',
    ...(monthlyFee ? ['Ongoing maintenance, support, and optimization included'] : []),
    'Payment link provided via email after signing',
    '60-day money-back guarantee'
  ]

  return {
    header: { title: 'Agreement & Terms', variant: 'accent' },
    footer: true,
    sections: [
      {
        type: 'card',
        content: [
          {
            type: 'list',
            ordered: false,
            items: terms
          }
        ]
      },
      {
        type: 'text',
        content: `By signing below, ${contactName} of ${companyName} authorizes ${providerName} to proceed.`,
        variant: 'body'
      },
      {
        type: 'card',
        title: 'Signature',
        variant: 'light',
        content: [
          {
            type: 'text',
            content: 'Electronic signature will be captured below via SignatureAPI',
            variant: 'caption'
          },
          {
            type: 'text',
            content: '\n\n\n\n\n',
            variant: 'body'
          }
        ]
      }
    ]
  }
}
