/** Arabic / Persian script ranges (including presentation forms). */
const RTL_SCRIPT_RE =
  /[\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\uFB50-\uFDFF\uFE70-\uFEFF]/

export function isRtlScript(text: string | null | undefined): boolean {
  if (!text) return false
  return RTL_SCRIPT_RE.test(text)
}

export type TextLocaleAttrs = {
  lang: 'fa' | 'en'
  dir: 'rtl' | 'ltr'
  className: string | undefined
}

/** Font + direction attrs for mixed FA/EN content fields. */
export function textLocaleAttrs(text: string | null | undefined): TextLocaleAttrs {
  if (isRtlScript(text)) {
    return { lang: 'fa', dir: 'rtl', className: 'faText' }
  }
  return { lang: 'en', dir: 'ltr', className: undefined }
}
