import { useMemo } from 'react'
import type { ORDER_STATUS, ORDER_TYPE, PAYMENT_STATUS } from '@/types/data'

export const useOrderLabels = (t: (key: string) => string, locale: string) => {
  const statusLabelMap = useMemo(
    () =>
      ({
        pending: t('statusFilters.pending'),
        confirmed: t('statusFilters.confirmed'),
        preparing: t('statusFilters.preparing'),
        ready: t('statusFilters.ready'),
        delivered: t('statusFilters.delivered'),
        completed: t('statusFilters.completed'),
        cancelled: t('statusFilters.cancelled')
      }) as Record<ORDER_STATUS, string>,
    [t]
  )

  const typeLabelMap = useMemo(
    () =>
      ({
        dine_in: t('dineIn'),
        delivery: t('delivery'),
        takeaway: t('takeaway')
      }) as Record<ORDER_TYPE, string>,
    [t]
  )

  const paymentLabelMap = useMemo(
    () =>
      ({
        pending: t('paymentLabels.pending'),
        paid: t('paymentLabels.paid'),
        failed: t('paymentLabels.failed'),
        refunded: t('paymentLabels.refunded')
      }) as Record<PAYMENT_STATUS, string>,
    [t]
  )

  const resolveLocalizedLabel = (arabic?: string | null, english?: string | null, fallback = '') =>
    locale === 'ar' ? arabic || english || fallback : english || arabic || fallback

  return {
    statusLabelMap,
    typeLabelMap,
    paymentLabelMap,
    resolveLocalizedLabel
  }
}
