import type { KbxGridStatusMap, KbxStatusSemantic } from '@kbx/contracts'

export interface KbxResolvedGridStatus {
  rawValue: string
  label: string
  semantic: KbxStatusSemantic
  unknown: boolean
}

/** Domain raw value를 변경하지 않고 사용자 표시용 상태만 해석한다. */
export function resolveKbxGridStatus(map:KbxGridStatusMap|undefined,value:unknown):KbxResolvedGridStatus {
  const rawValue=value==null?'':String(value)
  const definition=map?.definitions.find(item=>item.value===rawValue)
  if(definition)return {rawValue,label:definition.label,semantic:definition.semantic,unknown:false}
  return {
    rawValue,
    label:`${map?.unknownLabel??'정의되지 않음'} · ${rawValue||'빈 값'}`,
    semantic:'warning',
    unknown:true,
  }
}
