All files / web/src/app/vision-training/train/components/data-panel DataPanelHeader.tsx

0% Statements 0/179
0% Branches 0/1
0% Functions 0/1
0% Lines 0/179

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180                                                                                                                                                                                                                                                                                                                                                                       
'use client'

import { css } from '../../../../../../styled-system/css'
import type { ModelType } from '../wizard/types'
import type { SyncStatus, SyncProgress } from './types'
import { SyncHistoryIndicator } from '../SyncHistoryIndicator'

export interface DataPanelHeaderProps {
  /** Model type */
  modelType: ModelType
  /** Total item count */
  totalCount: number
  /** Data quality label */
  dataQuality: string
  /** Sync status (optional) */
  syncStatus?: SyncStatus | null
  /** Sync progress (optional) */
  syncProgress?: SyncProgress
  /** Handler to start sync */
  onStartSync?: () => void
  /** Handler to cancel sync */
  onCancelSync?: () => void
  /** Trigger for sync history refresh */
  syncHistoryRefreshTrigger?: number
}

const MODEL_CONFIG = {
  'boundary-detector': {
    icon: '🎯',
    title: 'Boundary Training Data',
    itemLabel: 'frames',
  },
  'column-classifier': {
    icon: '🔢',
    title: 'Column Classifier Data',
    itemLabel: 'images',
  },
} as const

/**
 * Shared header component for data panels.
 * Shows model info, count, quality, and optional sync controls.
 */
export function DataPanelHeader({
  modelType,
  totalCount,
  dataQuality,
  syncStatus,
  syncProgress,
  onStartSync,
  onCancelSync,
  syncHistoryRefreshTrigger = 0,
}: DataPanelHeaderProps) {
  const config = MODEL_CONFIG[modelType]
  const isSyncing = syncProgress?.phase === 'connecting' || syncProgress?.phase === 'syncing'
  const hasNewOnRemote = (syncStatus?.newOnRemote ?? 0) > 0

  return (
    <div
      data-element="data-panel-header"
      className={css({
        display: 'flex',
        alignItems: 'center',
        justifyContent: 'space-between',
        px: { base: 3, lg: 5 },
        py: 3,
        borderBottom: '1px solid',
        borderColor: 'gray.800',
        bg: 'gray.850',
      })}
    >
      {/* Title group */}
      <div
        data-element="header-title-group"
        className={css({ display: 'flex', alignItems: 'center', gap: 3 })}
      >
        <span data-element="header-icon" className={css({ fontSize: 'xl' })}>
          {config.icon}
        </span>
        <div data-element="header-text">
          <h2
            data-element="header-title"
            className={css({
              fontSize: 'lg',
              fontWeight: 'bold',
              color: 'gray.100',
            })}
          >
            {config.title}
          </h2>
          <div
            data-element="header-subtitle"
            className={css({ fontSize: 'sm', color: 'gray.500' })}
          >
            {totalCount.toLocaleString()} {config.itemLabel} • {dataQuality} quality
          </div>
        </div>
      </div>

      {/* Actions */}
      <div
        data-element="header-actions"
        className={css({ display: 'flex', alignItems: 'center', gap: 3 })}
      >
        {/* Sync history indicator */}
        {syncStatus?.available && (
          <SyncHistoryIndicator modelType={modelType} refreshTrigger={syncHistoryRefreshTrigger} />
        )}

        {/* Sync button */}
        {syncStatus?.available && onStartSync && onCancelSync && (
          <button
            type="button"
            data-action="sync"
            data-status={isSyncing ? 'syncing' : hasNewOnRemote ? 'has-new' : 'in-sync'}
            onClick={isSyncing ? onCancelSync : onStartSync}
            disabled={!hasNewOnRemote && !isSyncing}
            className={css({
              display: 'flex',
              alignItems: 'center',
              gap: 2,
              px: 3,
              py: 2,
              bg: isSyncing ? 'blue.800' : hasNewOnRemote ? 'blue.600' : 'gray.700',
              color: hasNewOnRemote || isSyncing ? 'white' : 'gray.500',
              borderRadius: 'lg',
              border: 'none',
              cursor: hasNewOnRemote || isSyncing ? 'pointer' : 'not-allowed',
              fontSize: 'sm',
              fontWeight: 'medium',
              _hover: hasNewOnRemote ? { bg: 'blue.500' } : {},
            })}
          >
            {isSyncing ? (
              <>
                <span
                  className={css({
                    animation: 'spin 1s linear infinite',
                  })}
                >
                  🔄
                </span>
                <span
                  className={css({
                    display: { base: 'none', md: 'inline' },
                  })}
                >
                  {syncProgress?.message}
                </span>
              </>
            ) : hasNewOnRemote ? (
              <>
                <span>☁️</span>
                <span
                  className={css({
                    display: { base: 'none', md: 'inline' },
                  })}
                >
                  Sync {syncStatus.newOnRemote} new
                </span>
              </>
            ) : (
              <>
                <span>✓</span>
                <span
                  className={css({
                    display: { base: 'none', md: 'inline' },
                  })}
                >
                  In sync
                </span>
              </>
            )}
          </button>
        )}
      </div>
    </div>
  )
}