'use client'

import React, { useEffect } from 'react'
import { useSearchParams } from 'next/navigation'
import Dashboard from '../../../components/dashboard/Dashboard'
import useNavigationStore from '../../store/navigationStore'

const DashboardPage = () => {
  const searchParams = useSearchParams()
  const { currentObject, setCurrentObject } = useNavigationStore()
  
  const urlObjectId = searchParams.get('objectId')
  const urlObjectTitle = searchParams.get('objectTitle')
  useEffect(() => {
    if (urlObjectId && urlObjectTitle && (!currentObject.id || currentObject.id !== urlObjectId)) {
      setCurrentObject(urlObjectId, urlObjectTitle)
    }
  }, [urlObjectId, urlObjectTitle, currentObject.id, setCurrentObject])
  
  return <Dashboard />
}

export default DashboardPage