import {ShareParams, ShareResponse} from '@shopify/shop-minis-platform/actions'

import {useHandleAction} from '../../internal/useHandleAction'
import {useShopActions} from '../../internal/useShopActions'

interface UseShareReturns {
  /**
   * Closes the Mini viewer.
   */
  share: (params: ShareParams) => Promise<ShareResponse>
}

export const useShare = (): UseShareReturns => {
  const {share} = useShopActions()

  return {
    share: useHandleAction(share),
  }
}
