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

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

interface UseShareReturns {
  /**
   * Generic Social Share
   */
  share: (params: ShareParams) => Promise<ShareResponse>
  /**
   * Social Share for a single social medium
   */
  shareSingle: (params: ShareSingleParams) => Promise<ShareSingleResponse>
}

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

  return {
    share: useHandleAction(share),
    shareSingle: useHandleAction(shareSingle),
  }
}
