export function useGrateWizard() {
  const appConfig = useAppConfig()
  const { url, popup } = appConfig.gratewizard as { url: string; popup: { width: number; height: number } }

  function launch(e?: Event) {
    const left = Math.round((window.screen.width - popup.width) / 2)
    const top = Math.round((window.screen.height - popup.height) / 2)
    const win = window.open(
      url,
      'grateWizard',
      `width=${popup.width},height=${popup.height},left=${left},top=${top},scrollbars=yes,resizable=yes`,
    )
    if (win) e?.preventDefault()
  }

  return { url, launch }
}
