import {
  global
// } from '@declaration'
} from '../@declaration/_'

import { useStore } from './useStore'
export const pageTransit: global.PageTransitParams = {
  open: ( url ) => {
    window.open( url )
  },
  pushSync: ( url ) => {
    window.location.href = url
  },
  pushAsync: ( url ) => {
    if ( url.match( /https?:\/\// ) ) {
      pageTransit.pushSync( url )
      return
    }
    let navigate = useStore.get( 'navigate' )
    navigate( url )
  },
  push: ( url,newTab ) => {
    if ( newTab ) {
      pageTransit.open( url )
      return
    }
    pageTransit.pushAsync( url )
  },
  back: () => {
    let navigate = useStore.get( 'navigate' )
    navigate( -1 )
  },
}