export interface EmailTemplate {
  id: string
  template_type: string
  name: string
  description: string | null
  category: string
  is_active: boolean
  sort_order: number
  variables: string[]
  latest_version?: TemplateVersion | null
  created_at: string | null
  updated_at: string | null
}

export interface TemplateVersion {
  id: string
  template_id: string
  version: string
  language: string
  subject: string
  body_html: string
  body_text: string | null
  status: string
  submitted_at: string | null
  published_at: string | null
  created_at: string | null
}

export interface TemplateType {
  type: string
  name: string
  category: string
  variables: string[]
}

export interface SendLog {
  id: string
  template_type: string
  recipient: string
  subject: string
  status: string
  sent_at: string | null
}

export interface TemplateApproval {
  id: string
  version_id: string
  action: string // submitted, approved, rejected
  actor_id: string
  actor_name?: string
  comment?: string
  created_at: string
}

export interface Settings {
  sender_name: string
  sender_email: string
  reply_to: string | null
  logo_url: string | null
  primary_color: string
  secondary_color: string
  footer_text: string
  company_name: string | null
  company_address: string | null
}

export type TabId = 'templates' | 'editor' | 'settings' | 'logs'

export const API_BASE = '/api/sdk/v1/compliance/email-templates'

export function getHeaders(): HeadersInit {
  if (typeof window === 'undefined') return { 'Content-Type': 'application/json' }
  return {
    'Content-Type': 'application/json',
    'X-Tenant-ID': localStorage.getItem('bp_tenant_id') || '9282a473-5c95-4b3a-bf78-0ecc0ec71d3e',
    'X-User-ID': localStorage.getItem('bp_user_id') || '',
  }
}

export const CATEGORIES: Record<string, { label: string; color: string; bgColor: string }> = {
  general: { label: 'Allgemein', color: 'text-gray-700', bgColor: 'bg-gray-100' },
  dsr: { label: 'Betroffenenrechte', color: 'text-blue-700', bgColor: 'bg-blue-100' },
  consent: { label: 'Einwilligung', color: 'text-green-700', bgColor: 'bg-green-100' },
  breach: { label: 'Datenpanne', color: 'text-red-700', bgColor: 'bg-red-100' },
  vendor: { label: 'Dienstleister', color: 'text-purple-700', bgColor: 'bg-purple-100' },
  training: { label: 'Schulung', color: 'text-orange-700', bgColor: 'bg-orange-100' },
}

export const STATUS_BADGE: Record<string, { label: string; color: string }> = {
  draft: { label: 'Entwurf', color: 'bg-gray-100 text-gray-700' },
  review: { label: 'Pruefung', color: 'bg-yellow-100 text-yellow-700' },
  approved: { label: 'Genehmigt', color: 'bg-blue-100 text-blue-700' },
  published: { label: 'Publiziert', color: 'bg-green-100 text-green-700' },
}
