// ========== TYPES FOR MULTILEVEL SUPPLIES TABLE ==========
// Модульные типы для V1 товарных поставок (legacy)

// Основные интерфейсы из GraphQL
export interface SupplyOrderFromGraphQL {
  id: string
  organizationId: string
  partnerId: string
  partner: {
    id: string
    name?: string
    fullName?: string
    inn: string
    address?: string
    market?: string
    phones?: Array<{ value: string }>
    emails?: Array<{ value: string }>
    type: string
  }
  deliveryDate: string
  status: string
  totalAmount: number
  totalItems: number
  fulfillmentCenterId?: string
  fulfillmentCenter?: {
    id: string
    name?: string
    fullName?: string
    address?: string
  }
  logisticsPartnerId?: string
  logisticsPartner?: {
    id: string
    name?: string
    fullName?: string
  }
  packagesCount?: number
  volume?: number
  responsibleEmployee?: string
  employee?: {
    id: string
    firstName: string
    lastName: string
    position: string
    department?: string
  }
  notes?: string
  routes: Array<{
    id: string
    logisticsId?: string
    fromLocation: string
    toLocation: string
    fromAddress?: string
    toAddress?: string
    price?: number
    status?: string
    createdDate: string
    logistics?: {
      id: string
      fromLocation: string
      toLocation: string
      priceUnder1m3: number
      priceOver1m3: number
      description?: string
    }
  }>
  items: Array<{
    id: string
    quantity: number
    price: number
    totalPrice: number
    product: {
      id: string
      name: string
      article?: string
      description?: string
      price: number
      category?: { name: string }
      sizes?: Array<{ id: string; name: string; quantity: number }>
    }
    productId: string
    recipe?: {
      services?: Array<{
        id: string
        name: string
        price: number
      }>
      fulfillmentConsumables?: Array<{
        id: string
        name: string
        price: number
      }>
      sellerConsumables?: Array<{
        id: string
        name: string
        price: number
      }>
      marketplaceCardId?: string
    }
  }>
  createdAt: string
  updatedAt: string
}

// Props для основного компонента
export interface MultiLevelSuppliesTableProps {
  supplies?: SupplyOrderFromGraphQL[]
  loading?: boolean
  userRole?: 'SELLER' | 'WHOLESALE' | 'FULFILLMENT' | 'LOGIST'
  activeTab?: string
  onSupplyAction?: (supplyId: string, action: string) => void
  onVolumeChange?: (supplyId: string, volume: number | null) => void
  onPackagesChange?: (supplyId: string, packagesCount: number | null) => void
  onUpdateComplete?: (supplyId: string, field: 'volume' | 'packages') => void
}

// Состояние для управления раскрытием элементов
export interface ExpandedState {
  supplies: Set<string>
  routes: Set<string>
  suppliers: Set<string>
  products: Set<string>
}

// Локальные значения инпутов
export interface InputValues {
  [key: string]: {
    volume: string
    packages: string
  }
}

// Состояние контекстного меню
export interface ContextMenuState {
  isOpen: boolean
  position: { x: number; y: number }
  supplyId: string | null
}

// Props для блок-компонентов
export interface TableHeaderBlockProps {
  userRole: 'SELLER' | 'WHOLESALE' | 'FULFILLMENT' | 'LOGIST'
}

export interface SupplyRowBlockProps {
  supply: SupplyOrderFromGraphQL
  index: number
  userRole: 'SELLER' | 'WHOLESALE' | 'FULFILLMENT' | 'LOGIST'
  isExpanded: boolean
  inputValues: {
    volume: string
    packages: string
  }
  pendingUpdates: Set<string>
  onToggleExpansion: (supplyId: string) => void
  onVolumeChange: (value: string) => void
  onPackagesChange: (value: string) => void
  onVolumeBlur: () => void
  onPackagesBlur: () => void
  onSupplyAction?: (supplyId: string, action: string) => void
  onRightClick: (e: React.MouseEvent, supplyId: string) => void
}

export interface RouteRowBlockProps {
  route: SupplyOrderFromGraphQL['routes'][0]
  supplyIndex: number
  routeIndex: number
  userRole: 'SELLER' | 'WHOLESALE' | 'FULFILLMENT' | 'LOGIST'
  isExpanded: boolean
  onToggleExpansion: (routeId: string) => void
}

export interface ProductRowBlockProps {
  item: SupplyOrderFromGraphQL['items'][0]
  supplyIndex: number
  itemIndex: number
  userRole: 'SELLER' | 'WHOLESALE' | 'FULFILLMENT' | 'LOGIST'
  isExpanded: boolean
  onToggleExpansion: (productId: string) => void
}

export interface ActionButtonsProps {
  supplyId: string
  onSupplyAction?: (supplyId: string, action: string) => void
}

export interface StatusBadgeProps {
  status: string
}

export interface ContextMenuProps {
  isOpen: boolean
  position: { x: number; y: number }
  onClose: () => void
  onCancel: () => void
}

export interface CancelConfirmDialogProps {
  isOpen: boolean
  onClose: () => void
  onConfirm: () => void
  supplyId: string | null
}

// Простые компоненты таблицы (переиспользуемые типы)
export interface TableComponentProps {
  children: React.ReactNode
  className?: string
  [key: string]: unknown
}