export interface DialogShowOptions {
  title: string
  content: string
  path: string
  image: string
}
export enum HonorDialogType {
  Badge = 'badge',
  Certificate = 'certificate',
}
export interface HonorDialogOptions {
  title?: string
  content?: string
  image?: string
  type?: HonorDialogType
  onLoad?: () => void
}
// export const HonorDialogSymbol: InjectionKey<{
//   show: (options: DialogShowOptions) => void
// }> = Symbol.for('HonorDialogContext')
export const HonorDialogSymbol = Symbol.for('HonorDialogContext')
// export const useHonorDialog = () => {
//   const honorDialog = inject(HonorDialogSymbol)
//   // if (!honorDialog) {
//   //   throw new Error('useHonorDialog must be used inside setup()')
//   // }
//   const show = computed(() => honorDialog?.show)
//   return {
//     show,
//   }
// }
export const useHonorDialog = () => {
  const dialogOption = ref({})
  // inject(HonorDialogSymbol, dialogOption)
  // const honorDialog = inject(HonorDialogSymbol)
  // console.log(honorDialog)
  provide(HonorDialogSymbol, dialogOption)
  // if (!honorDialog) {
  //   throw new Error('useHonorDialog must be used inside setup()')
  // }
  const show = (option: HonorDialogOptions) => {
    return new Promise((resolve, reject) => {
      const options = {
        ...option,
      }
      dialogOption.value = {
        ...options,
        ...{
          show: true,
          onConfirm: (res) => {
            resolve(res)
          },
          onCancel: (res) => {
            reject(res)
          },
        },
      }
    })
  }
  return {
    show,
  }
}
