'use client'

import { useEffect } from 'react'

/**
 * Sets document direction (RTL/LTR) on mount based on saved language.
 * Runs before paint to prevent visual flash.
 */
export function DirectionInitializer() {
  useEffect(() => {
    try {
      const lang = localStorage.getItem('user-language')
      if (lang === 'fa' || lang === 'ar') {
        document.documentElement.dir = 'rtl'
        document.documentElement.lang = lang
      } else {
        document.documentElement.dir = 'ltr'
      }
    } catch {}
  }, [])

  return null
}
