import React__default from 'react';

type VideoGridMetricMode = 'efficiency' | 'recent_flow' | 'recent_flow_wip_gated';
declare const normalizeVideoGridMetricMode: (value: unknown, assemblyEnabled?: boolean) => VideoGridMetricMode;
declare const isRecentFlowVideoGridMetricMode: (value: unknown, assemblyEnabled?: boolean) => boolean;
declare const isWipGatedVideoGridMetricMode: (value: unknown, assemblyEnabled?: boolean) => boolean;

type IdleReasonPaletteToken = 'red' | 'amber' | 'blue' | 'violet' | 'emerald' | 'cyan' | 'slate';
type IdleReasonIconToken = 'alert-triangle' | 'refresh-cw' | 'package' | 'clock' | 'user-x' | 'wrench' | 'activity' | 'clipboard-x' | 'help-circle';

/** One row of per-SKU workspace metrics. Backend computes; frontend renders. */
interface SkuBreakdownItem {
    /** UUID — `skus.id`. Stable identifier for selectors and threshold writes. */
    sku_id: string;
    /** Technical code — `skus.sku_id` (e.g. `IMT_BIG`). */
    sku_code: string;
    /** User-facing label — `skus.display_name`, falling back to `sku_code`. */
    sku_display_name?: string | null;
    sku_definition: string;
    is_dummy: boolean;
    total_output: number;
    target_output: number;
    avg_pph: number;
    pph_threshold: number;
    avg_cycle_time: number;
    ideal_cycle_time: number;
    efficiency: number;
    /** Active minutes the SKU was present in this shift; used for ranking. */
    active_minutes: number;
    intervals: Array<{
        start_time: string;
        end_time: string | null;
    }>;
}
/** Hourly-chart divider segment. Dummy excluded by backend. */
interface SkuSegmentItem {
    sku_id: string;
    sku_code: string;
    sku_display_name?: string | null;
    start_time: string;
    end_time: string | null;
    pph_threshold: number;
}
/** Per-SKU line-level breakdown (subset of workspace breakdown). */
interface LineSkuBreakdownItem {
    sku_id: string;
    sku_code: string;
    sku_display_name?: string | null;
    is_dummy: boolean;
    current_output: number;
    ideal_output: number;
    avg_efficiency: number;
    /**
     * Raw per-SKU target from `line_thresholds` (or the dummy-SKU fallback
     * via `update_line_metrics`'s LATERAL lookup when no per-SKU row exists).
     */
    line_threshold: number | null;
    /**
     * Active-time-weighted projection per-SKU (line-scope lift of
     * `pm.total_day_output_recalculated`, added by db migration v1_20).
     * Semantics:
     *   * Active SKU mid-shift: projected full-day output if it continues.
     *   * Finalized SKU: raw_target × active_fraction (realized share).
     * Per-SKU UIs should prefer this field for the displayed target so
     * efficiency reflects real SKU activity rather than the shared line
     * target. Null on rows written before v1_20 (not yet backfilled) and
     * on Nahar rows (quality_metrics path doesn't populate it).
     */
    line_threshold_recalculated?: number | null;
    /** Summed real-SKU `performance_metrics.total_day_output_recalculated`. */
    output_target_recalculated?: number | null;
    total_workspaces?: number;
    underperforming_workspaces?: number;
    underperforming_workspace_names?: string[];
    underperforming_workspace_uuids?: string[];
    output_array?: number[];
    output_hourly?: Record<string, any>;
    idle_time_hourly?: Record<string, any>;
    /**
     * Poorest-performing workspaces for THIS SKU specifically (sorted by
     * efficiency ascending, top 5). Excludes rows where the SKU had no
     * activity. Backend builds this from `workspace_metrics_by_sku[sku_id]`.
     * Absent on payloads from pre-Step-3 backends.
     */
    poorest_performing_workspaces?: PoorPerformingWorkspace[];
}
/** Currently-active SKU on a workspace (sourced from sku_presence end_time IS NULL). */
interface CurrentWorkspaceSKU {
    sku_uuid: string;
    sku_code: string;
    sku_display_name?: string | null;
    sku_definition: string;
    start_time: string;
    is_dummy: boolean;
}
interface LineInfo {
    line_id: string;
    line_name: string;
    company_id: string;
    company_name: string;
    factory_id: string;
    factory_name: string;
    shift_id: number;
    date: string;
    monitoring_mode?: 'output' | 'uptime';
    assembly?: boolean | null;
    recent_flow_window_minutes?: number;
    metrics: LineDetailedMetrics;
}
/**
 * Aggregated line metrics (legacy fields plus optional multi-SKU additions).
 *
 * The five SKU fields are populated only when `enable_sku_detection=true` AND
 * at least one real SKU row exists (decision #12). When absent, consumers
 * must fall back to the legacy aggregate fields.
 */
interface LineDetailedMetrics {
    avg_efficiency: number;
    avg_cycle_time: number;
    current_output: number;
    ideal_output: number;
    total_workspaces: number;
    underperforming_workspaces: number;
    underperforming_workspace_names: string[];
    underperforming_workspace_uuids: string[];
    output_array: number[];
    output_hourly?: Record<string, number[]>;
    hourly_target_output?: Array<number | null> | null;
    hourly_target_output_by_sku?: Record<string, Array<number | null> | null>;
    line_threshold: number;
    /** Summed real-SKU `performance_metrics.total_day_output_recalculated`. */
    output_target_recalculated?: number | null;
    threshold_pph?: number;
    shift_start?: string;
    shift_end?: string;
    last_updated?: string;
    poorest_performing_workspaces?: PoorPerformingWorkspace[];
    avg_idle_time_seconds?: number;
    idle_time_hourly?: Record<string, any> | null;
    /** True iff `enable_sku_detection=true` AND `real_sku_count >= 1`. */
    sku_aware?: boolean;
    /** Distinct count of non-dummy SKU rows for this (line, date, shift). */
    real_sku_count?: number;
    /** Per-SKU breakdown for the Line Detail selector. Includes dummy with `is_dummy=true`. */
    sku_breakdown?: LineSkuBreakdownItem[];
    /** Hourly-chart divider segments (dummy excluded). */
    sku_segments?: SkuSegmentItem[];
}
interface PoorPerformingWorkspace {
    workspace_name: string;
    efficiency: number;
    action_count: number;
    action_threshold: number;
}
interface VideoGridStatusBadge {
    kind: 'idle_reason' | 'no_plan';
    label: string | null;
    display_name: string;
    palette_token: IdleReasonPaletteToken;
    icon_token: IdleReasonIconToken;
    is_known?: boolean;
    title?: string;
    anchor_minute?: number;
    reason_minute?: number;
    shift_elapsed_fraction?: number;
}
interface WorkspaceMetrics {
    company_id: string;
    line_id: string;
    shift_id: number;
    date: string;
    workspace_uuid: string | null;
    workspace_name: string;
    action_count: number;
    pph: number;
    pph_threshold?: number;
    performance_score: 0 | 1 | 2;
    avg_cycle_time: number;
    ideal_cycle_time?: number;
    trend: 0 | 1 | 2;
    predicted_output: number;
    efficiency: number;
    action_threshold: number;
    displayName?: string;
    monitoring_mode?: 'output' | 'uptime';
    idle_time?: number;
    idle_time_hourly?: Record<string, any> | null;
    idle_reason_hourly?: Record<string, any> | null;
    shift_start?: string;
    shift_end?: string;
    assembly_enabled?: boolean;
    video_grid_metric_mode?: VideoGridMetricMode;
    action_type?: 'assembly' | 'output' | null;
    action_family?: 'assembly' | 'output' | 'other' | null;
    action_display_name?: string | null;
    factory_area_id?: string | null;
    factory_area_key?: string | null;
    factory_area_name?: string | null;
    factory_area_enabled?: boolean | null;
    leaderboard_metric_kind?: 'efficiency' | 'cycle_time' | 'recent_flow_shift_average';
    leaderboard_value?: number | null;
    avg_recent_flow?: number | null;
    recent_flow_mode?: 'computed' | 'hold' | 'unavailable';
    recent_flow_percent?: number | null;
    recent_flow_hourly?: Record<string, unknown> | null;
    recent_flow_actual_rate_pph?: number | null;
    recent_flow_healthy_rate_pph?: number | null;
    recent_flow_window_minutes?: number | null;
    recent_flow_effective_end_at?: string | null;
    recent_flow_computed_at?: string | null;
    recent_flow_forced_zero_after_shift?: boolean | null;
    video_grid_green_streak_active?: boolean | null;
    video_grid_green_streak_minutes?: number | null;
    video_grid_green_streak_anchor_at?: string | null;
    video_grid_green_streak_started_at?: string | null;
    video_grid_green_streak_observed_at?: string | null;
    scheduled_break_active?: boolean;
    incoming_wip_current?: number | null;
    incoming_wip_effective_at?: string | null;
    incoming_wip_buffer_name?: string | null;
    video_grid_badges?: VideoGridStatusBadge[];
    /**
     * When present, controls whether the UI should show the exclamation indicator for this workstation.
     * - Flow-configured lines: true only when a WIP alert is active for a buffer that outputs to this workstation.
     * - Non-flow lines: true when efficiency is critically low (legacy behavior).
     */
    show_exclamation?: boolean;
}
interface WorkspaceDetailedMetrics {
    line_id: string;
    line_name: string;
    line_assembly_enabled?: boolean;
    workspace_name: string;
    workspace_display_name?: string | null;
    workspace_id: string;
    company_id: string;
    company_name: string;
    date: string;
    shift_id: number;
    action_name: string;
    action_type?: 'assembly' | 'output' | null;
    action_family?: 'assembly' | 'output' | 'other' | null;
    action_display_name?: string | null;
    monitoring_mode?: 'output' | 'uptime';
    shift_start: string;
    shift_end: string;
    shift_type: string;
    pph_threshold: number;
    target_output: number;
    avg_pph: number;
    avg_cycle_time: number;
    ideal_cycle_time: number;
    avg_efficiency: number;
    total_actions: number;
    hourly_action_counts: number[];
    hourly_target_output?: Array<number | null> | null;
    hourly_cycle_times?: number[];
    cycle_completion_clip_count?: number | null;
    cycle_time_data_status?: 'available' | 'missing_clips' | null;
    cycle_time_timezone?: string | null;
    workspace_rank: number;
    total_workspaces: number;
    ideal_output_until_now: number;
    output_difference: number;
    idle_time?: number;
    idle_time_hourly?: Record<string, string[]>;
    compliance_efficiency?: number;
    sop_check?: Record<string, number>;
    /** True iff `enable_sku_detection=true` AND `real_sku_count >= 1`. */
    sku_aware?: boolean;
    /**
     * True when only dummy rows exist for this workspace/shift. Default `true`
     * for legacy lines so the SKU UI is hidden by default. Backend authoritative.
     */
    is_dummy_only?: boolean;
    /** Distinct count of non-dummy SKU rows for this (workspace, date, shift). */
    real_sku_count?: number;
    /** Per-SKU workspace breakdown ordered by `active_minutes desc, total_output desc`. */
    sku_breakdown?: SkuBreakdownItem[];
    /** Hourly-chart divider segments (dummy excluded). */
    sku_segments?: SkuSegmentItem[];
}
type LineSignalSource = 'recent_flow' | 'efficiency';
type KpiSignalSource = LineSignalSource | 'mixed';
type KpiSignalMode = 'computed' | 'unavailable';
interface LineSignal {
    source: LineSignalSource;
    percent: number | null;
    weight?: number | null;
    mode?: KpiSignalMode;
    reason?: string | null;
    aggregate_eligible?: boolean | null;
    aggregate_reason?: string | null;
    aggregate_threshold_percent?: number | null;
    effective_end_at?: string | null;
    computed_at?: string | null;
}
interface KpiSignal {
    source: KpiSignalSource;
    percent: number | null;
    weight?: number | null;
    mode?: KpiSignalMode;
    reason?: string | null;
    aggregateEligible?: boolean | null;
    aggregateReason?: string | null;
    aggregateThresholdPercent?: number | null;
    effectiveEndAt?: string | null;
    computedAt?: string | null;
}
interface DashboardKPIs {
    underperformingWorkers: {
        current: number;
        total: number;
        change: number;
    };
    efficiency: {
        value: number;
        change: number;
    };
    outputProgress: {
        current: number;
        target: number;
        change: number;
        idealOutput: number;
    };
    qualityCompliance: {
        value: number;
        change: number;
    };
    avgCycleTime: {
        value: number;
        change: number;
    };
    lineSignal?: KpiSignal | null;
}
interface LineIssueResolutionSummary {
    mean_resolution_seconds: number | null;
    median_resolution_seconds: number | null;
    resolved_issue_count: number;
    open_issue_count: number;
    oldest_open_issue_age_seconds: number | null;
    total_issue_seconds: number;
}
interface ValueDelta {
    current: number | null;
    previous: number | null;
}
interface PercentageDelta extends ValueDelta {
    delta_pp: number | null;
}
interface CountDelta extends ValueDelta {
    delta_count: number | null;
}
interface DurationDelta extends ValueDelta {
    delta_seconds: number | null;
}
interface KpiTrend {
    efficiency: PercentageDelta;
    outputProgress: PercentageDelta;
    underperformingWorkers: CountDelta;
    avgCycleTime: DurationDelta;
}
interface MonthlyTrendSummary {
    avg_efficiency?: PercentageDelta;
    avg_daily_output?: PercentageDelta;
    avg_cycle_time?: DurationDelta;
    avg_idle_time?: DurationDelta;
    avg_daily_stoppages?: CountDelta;
}

interface Workspace {
    id: string;
    line_id: string;
    workspace_id: string;
    action_id: string;
    action_type?: 'assembly' | 'output';
    action_display_name?: string | null;
    action_pph_threshold: number | null;
    action_cycle_time: number | null;
    action_total_day_output: number | null;
    enable: boolean;
}
interface WorkspaceCropRect {
    x: number;
    y: number;
    width: number;
    height: number;
}
interface WorkspaceVideoStream {
    workspace_id: string;
    camera_uuid: string;
    stream_camera_uuid: string;
    hls_url: string;
    crop?: WorkspaceCropRect | null;
}
interface WorkspaceCameraIpInfo {
    workspace_id: string;
    camera_ip: string | null;
    source_camera_uuid: string | null;
    effective_camera_uuid: string | null;
    resolution_mode: 'direct' | 'redirect' | null;
}
interface ActionThreshold {
    line_id: string;
    shift_id: number;
    action_id: string;
    workspace_id: string;
    date: string;
    pph_threshold: number;
    ideal_cycle_time: number;
    total_day_output: number;
    action_name: string | null;
    action_family?: 'assembly' | 'output' | 'other' | null;
    display_name?: string | null;
    updated_by: string;
    sku_id?: string;
    created_at?: string;
    last_updated?: string;
}
interface WorkspaceActionUpdate {
    id: string;
    action_id: string;
}
interface LineThreshold {
    factory_id: string;
    line_id: string;
    date: string;
    shift_id: number;
    product_code: string;
    threshold_day_output: number;
    threshold_pph: number;
    sku_id?: string;
}
interface ShiftConfiguration {
    id?: string;
    lineId: string;
    dayShift: {
        startTime: string;
        endTime: string;
        breaks: {
            startTime: string;
            endTime: string;
            duration: number;
        }[];
    };
    nightShift: {
        startTime: string;
        endTime: string;
        breaks: {
            startTime: string;
            endTime: string;
            duration: number;
        }[];
    };
    date: string;
    updatedBy: string;
}
interface ShiftConfigurationRecord {
    id: string;
    line_id: string;
    day_shift: object;
    night_shift: object;
    date: string;
    updated_by: string;
    created_at: string;
    last_updated: string;
}

interface EfficiencyLegendUpdate {
    green_min: number;
    green_max: number;
    yellow_min: number;
    yellow_max: number;
    red_min: number;
    red_max: number;
    critical_threshold: number;
}

type SnapshotVideoStatus = {
    expectedVideoCount: number;
    readyVideoCount: number;
    status: 'loading' | 'ready' | 'no_videos';
    updatedAt: string;
};
declare global {
    interface Window {
        __OPTIFYE_SNAPSHOT_READY__?: boolean;
        __OPTIFYE_SNAPSHOT_VIDEO_STATUS__?: SnapshotVideoStatus;
    }
}
interface RecentFlowSnapshotGridProps {
    workspaces: WorkspaceMetrics[];
    videoStreamsByWorkspaceId: Record<string, WorkspaceVideoStream>;
    legend?: EfficiencyLegendUpdate | null;
    className?: string;
}
declare const RecentFlowSnapshotGrid: React__default.FC<RecentFlowSnapshotGridProps>;

export { type ActionThreshold as A, RecentFlowSnapshotGrid as B, type CurrentWorkspaceSKU as C, type DashboardKPIs as D, type EfficiencyLegendUpdate as E, type KpiTrend as K, type LineSignal as L, type MonthlyTrendSummary as M, type PoorPerformingWorkspace as P, type RecentFlowSnapshotGridProps as R, type SkuBreakdownItem as S, type VideoGridMetricMode as V, type WorkspaceMetrics as W, type LineInfo as a, type WorkspaceDetailedMetrics as b, type SkuSegmentItem as c, type LineSkuBreakdownItem as d, type WorkspaceVideoStream as e, type Workspace as f, type WorkspaceCameraIpInfo as g, type WorkspaceActionUpdate as h, type ShiftConfiguration as i, type KpiSignal as j, type LineIssueResolutionSummary as k, type LineDetailedMetrics as l, type VideoGridStatusBadge as m, type LineSignalSource as n, type KpiSignalSource as o, type KpiSignalMode as p, type ValueDelta as q, type PercentageDelta as r, type CountDelta as s, type DurationDelta as t, type WorkspaceCropRect as u, type LineThreshold as v, type ShiftConfigurationRecord as w, normalizeVideoGridMetricMode as x, isRecentFlowVideoGridMetricMode as y, isWipGatedVideoGridMetricMode as z };
