import { getNewsBySlug } from '~/apis/common/get-news-by-slug'
import { handleCookie } from '~/libs/cookies'
import { FormContentsPage } from '~/pages/form-contents'

import type { Route } from './+types/_admin.lg-admin._dashboard.contents.update.$slug'

export const loader = async ({ request }: Route.LoaderArgs) => {
  const { staffToken } = await handleCookie(request)
  const { data: newsData } = await getNewsBySlug({
    accessToken: staffToken,
    slug: request.url.split('/').pop() ?? '',
  })
  return { newsData }
}

const DashboardContentUpdateLayout = ({ loaderData }: Route.ComponentProps) => {
  const newsData = loaderData.newsData
  return <FormContentsPage newsData={newsData} />
}
export default DashboardContentUpdateLayout
