import type { ProductVariationSelection } from '../services/productVariationService'
import { createId } from './id'

export interface StoreItemDraftRow {
  id: string
  storeItemId?: string
  selections: Record<string, string>
  price: string
  stock: string
}

export function getVariationOptions(variation: ProductVariationSelection) {
  if (variation.selectedOptionIds.length > 0) {
    return variation.options.filter((option) =>
      variation.selectedOptionIds.includes(option.id),
    )
  }
  return variation.options
}

export function createEmptyStoreItemRow(): StoreItemDraftRow {
  return {
    id: createId(),
    selections: {},
    price: '',
    stock: '1',
  }
}
