import type { KviewTableCellInput } from '@kview/ui-data/vue';

export interface DashboardFilterOption {
    value: string;
    label: string;
}

export interface DashboardFilters {
    gp_id: string[];
    fund_id: string[];
    investor_id: string[];
    as_of_date: string;
    include_fees_in_multiples: boolean;
    amount_scaling: string;
    overview_period: string;
    dashboard_view: string;
}

export interface DashboardFilterOptions {
    gps: DashboardFilterOption[];
    funds: DashboardFilterOption[];
    investors: DashboardFilterOption[];
    amountScaling: DashboardFilterOption[];
}

export interface DashboardContext {
    targetCurrency: string;
    currencyLabel: string;
    unitLabel: string;
    asOfDateLabel: string;
    amountScaling: string;
    includeFeesInMultiples: boolean;
}

export interface DashboardTab {
    id: string;
    label: string;
    icon: string;
    switcherLabel: string;
    description: string;
}

export interface DashboardKpi {
    label: string;
    value: string;
    icon?: string | null;
    meta?: string | null;
    trendValue?: string | null;
    trendLabel?: string | null;
    trendDirection?: 'up' | 'down' | 'neutral';
}

export interface DashboardTopPerformer {
    rank: number;
    name: string;
    category: string;
    initial: string;
    href: string | null;
    return: string;
    variant: 'positive' | 'negative';
}

export interface DashboardChartPoint {
    label: string;
    nav: number | null;
    benchmark: number | null;
}

export interface DashboardOverview {
    greeting: string;
    periodLabel: string;
    selectedPeriod: string;
    periodItems: DashboardFilterOption[];
    kpis: DashboardKpi[];
    chart: {
        points: DashboardChartPoint[];
        navLabel: string;
        benchmarkLabel: string;
        valueLabel: string;
        unit: string;
        decimals: number;
        width: number;
        height: number;
    };
    topPerformers: DashboardTopPerformer[];
    exportUrl: string;
}

export interface DashboardLinkCell {
    label: string;
    href: string | null;
}

export type DashboardCellRecord = Record<string, KviewTableCellInput>;

export type DashboardPeriodCellRecord = Record<string, string>;

export interface DashboardRow {
    id: string;
    href: string;
    investor: DashboardLinkCell;
    fund: DashboardLinkCell;
    cells: DashboardCellRecord;
}

export interface DashboardGroup {
    id: string;
    label: string;
    rows: DashboardRow[];
    subtotal: DashboardCellRecord;
}

export interface DashboardGroupedTabPayload {
    groups: DashboardGroup[];
    unitLabel: string;
    footnote?: string;
}

export interface DashboardPeriodRow {
    label: string;
    cells: DashboardPeriodCellRecord;
}

export interface DashboardPeriodGroup {
    id: string;
    label: string;
    periods: DashboardPeriodRow[];
}

export interface DashboardYearlyPayload {
    groups: DashboardPeriodGroup[];
    unitLabel: string;
    footnote?: string;
}

export type DashboardChartValueFormat = 'amount' | 'ratio' | 'percent' | 'number';

export interface DashboardChartDatasetPayload {
    id: string;
    label: string;
    kind?: 'line' | 'bar';
    axis?: 'primary' | 'secondary';
    valueFormat?: DashboardChartValueFormat;
    emphasize?: boolean;
    color?: string;
    values: Array<number | null>;
}

export interface DashboardComboChart {
    labels: string[];
    datasets: DashboardChartDatasetPayload[];
    primaryAxisLabel: string;
    secondaryAxisLabel?: string;
    ariaLabel: string;
}

export interface DashboardQuarterlyGroup extends DashboardPeriodGroup {
    comboChart: DashboardComboChart | null;
    netInvestmentChart: DashboardComboChart | null;
}

export interface DashboardQuarterlyMeta {
    url: string;
    hasInvestments: boolean;
}

export interface DashboardQuarterlyPayload {
    groups: DashboardQuarterlyGroup[];
    unitLabel: string;
    footnote: string;
}

export interface DashboardSectionUrls {
    commitment: string;
    'call-distrib-nav': string;
    'irr-calculation': string;
    'yearly-performance': string;
}

export interface DashboardPageProps {
    filters: DashboardFilters;
    filterOptions: DashboardFilterOptions;
    context: DashboardContext;
    tabs: DashboardTab[];
    overview: DashboardOverview;
    commitment: DashboardGroupedTabPayload | null;
    callDistribNav: DashboardGroupedTabPayload | null;
    irr: DashboardGroupedTabPayload | null;
    yearly: DashboardYearlyPayload | null;
    sectionUrls: DashboardSectionUrls;
    quarterly: DashboardQuarterlyMeta;
}
