'use client' import { useState } from 'react' import Link from 'next/link' import { useRouter } from 'next/navigation' import { useTranslations } from 'next-intl' import { createClient } from '@/lib/supabase/client' import { AttnLine } from '@/components/ui/attn-line' import { Card, CardContent } from '@/components/ui/card' import { Badge } from '@/components/ui/badge' import { useCapability, useCompany } from '@/contexts/CompanyContext' import { CAPABILITY } from '@/lib/entitlements/keys' import NewUserChecklist from '@/components/onboarding/NewUserChecklist' import AttGoraSection from '@/components/dashboard/AttGoraSection' import ResumePane from '@/components/dashboard/ResumePane' import BackupHealthBanner from '@/components/dashboard/BackupHealthBanner' import { SkatteverketPromoCard } from '@/components/dashboard/SkatteverketPromoCard' import { ArrowRight } from 'lucide-react' import type { InitialSetupState, OnboardingProgress } from '@/types' import type { SuggestedMatch, WorklistCounts } from '@/lib/worklist/types' import type { ResumeItem } from '@/lib/worklist/resume' interface DashboardContentProps { companyId: string /** Signed-in user's first name for the greeting; null falls back to a * nameless greeting. */ userFirstName?: string | null /** Expiring PSD2 consents (dashboard-only worklist extra). */ expiringBankConnections?: { id: string; bank_name: string; days_left: number }[] /** Unified pending-work counts from lib/worklist: same source as the sidebar badges. */ worklist: WorklistCounts /** High-confidence transaction↔invoice matches for inline one-click confirm. */ suggestedMatches: SuggestedMatch[] /** In-progress work for the Fortsätt pane (lib/worklist/resume). */ resumeItems: ResumeItem[] /** * True when this account looks bookkeeping-empty while a same-orgnr * company with real bookkeeping exists in another account (#1231): the * user probably signed in with the wrong login (stale BankID account). */ otherAccountHint?: boolean onboardingProgress?: OnboardingProgress initialSetup: InitialSetupState /** * False until the company has a verified agent_profile. When false the hero * slot shows a build-assistant prompt instead of the next-best-action card, * so existing/migrated users are nudged to build the assistant without a * full-screen onboarding takeover. */ agentBuilt?: boolean } /** * Hem (concept scene 14): greeting, then the two panes side by side: * Att göra (obligations, lib/worklist) and Fortsätt (in-progress work, * lib/worklist/resume). KPI tiles, revenue/expense cards and the deadline/tax * widgets left the page (founder direction, dev_docs/last_session_resume.md * §8): the numbers live at /kpi and /reports, deadlines render as Bevaka rows. */ export default function DashboardContent({ companyId, userFirstName, expiringBankConnections, worklist, suggestedMatches, resumeItems, otherAccountHint = false, onboardingProgress, initialSetup, agentBuilt = true, }: DashboardContentProps) { const t = useTranslations('dashboard') const hasAi = useCapability(CAPABILITY.ai) const { company } = useCompany() const router = useRouter() // Wrong-account hint action: sign out so the user can come back in with // their other login (email+password). Same flow as SandboxBanner. async function handleSwitchAccount() { const supabase = createClient() await supabase.auth.signOut() router.push('/login') } // Time-of-day greeting (concept: "God morgon, Jakob."). Client-side clock // on purpose (the user's local morning, not the server's), captured once // so render stays pure. const [greetingNow] = useState(() => new Date()) const hour = greetingNow.getHours() const greeting = hour < 10 ? t('greeting_morning') : hour < 17 ? t('greeting_day') : t('greeting_evening') const dateLine = new Intl.DateTimeFormat('sv-SE', { weekday: 'long', day: 'numeric', month: 'long', }).format(greetingNow) return (
{dateLine} {company?.name ? ` · ${company.name}` : ''}
{otherAccountHint && (Bygg din bokföringsassistent
{hasAi ? 'Några frågor om din verksamhet kalibrerar en assistent som föreslår bokföring åt dig.' : 'Ingår i abonnemanget: en assistent som föreslår bokföring åt dig.'}