import { getSubscriptions } from '~/apis/common/get-subscriptions'
import { FormSubscribePlanPage } from '~/pages/form-subscriptions-plan'

import type { Route } from './+types/_admin.lg-admin._dashboard.subscribe-plan.update.$id'

export const loader = async ({ params }: Route.LoaderArgs) => {
  const { data: subscribePlansData } = await getSubscriptions()
  const subscribePlanData = subscribePlansData.find(
    (subscribePlan) => subscribePlan.id === params.id,
  )
  return { subscribePlanData }
}

const DashboardSubscribePlanUpdateLayout = ({
  loaderData,
}: Route.ComponentProps) => {
  const { subscribePlanData } = loaderData || {}
  return <FormSubscribePlanPage subscribePlanData={subscribePlanData} />
}
export default DashboardSubscribePlanUpdateLayout
