import { useSelect } from '@wordpress/data'

export default function useParentBlockName(
  clientId: string
): string | undefined {
  return useSelect(
    (select) => {
      const parentClientId = (select('core/block-editor') as any)
        .getBlockParents(clientId, true)
        .at(0)
      return (select('core/block-editor') as any).getBlock(parentClientId)?.name
    },
    [clientId]
  )
}
