import { useStoreActions } from '@/store'
import { useEffect } from 'react'

const LoadAiPostsFromLocalStorage = () => {
  const setAiPosts = useStoreActions((actions) => actions.base.messages.setAiPosts)

  useEffect(() => {
    const saved = localStorage.getItem('AiPosts')
    if (saved) {
      try {
        const parsed = JSON.parse(saved)
        if (Array.isArray(parsed) && parsed.every((p) => 'role' in p && 'content' in p)) {
          setAiPosts(parsed)
        }
      } catch (err) {
        console.warn('aiPosts localStorage parse error', err)
      }
    }
  }, [])

  return null
}

export default LoadAiPostsFromLocalStorage
