'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var hooks = require('preact/hooks');

function useNavigationCurrentEntry() {
  const [entry, update] = hooks.useReducer(() => navigation.currentEntry, navigation.currentEntry);
  hooks.useEffect(() => {
    if (!navigation || !navigation.currentEntry || !navigation.removeEventListener || !navigation.addEventListener) {
      throw new Error('useNavigationCurrentEntry must be used in an extension with the customer-account.page.render or customer-account.order.page.render target only');
    }
    navigation.addEventListener('currententrychange', update);
    return () => navigation.removeEventListener('currententrychange', update);
  }, [navigation]);
  return entry;
}

exports.useNavigationCurrentEntry = useNavigationCurrentEntry;
