function createMobileIssueDetailNavigation(options) {
  const buttons = options.buttons || {};
  const targets = options.targets || {};
  const listeners = new Map();
  const prefersReducedMotion = options.prefersReducedMotion || (() => false);
  const targetNames = new Map(Object.entries(targets).map(([name, target]) => [target, name]));
  let observer = null;

  function select(name) {
    Object.entries(buttons).forEach(([key, button]) => {
      if (!button) return;
      if (key === name) button.setAttribute('aria-current', 'location');
      else button.removeAttribute('aria-current');
    });
  }

  function navigate(name, navigationOptions = {}) {
    const target = targets[name];
    if (!target) return false;
    const prepare = options.beforeNavigate && options.beforeNavigate[name];
    if (prepare) prepare(target);
    if (name === 'actions' && options.planning) options.planning.open = true;
    target.scrollIntoView({
      block: 'start',
      behavior: prefersReducedMotion() ? 'auto' : 'smooth',
    });
    if (name === 'reply' && navigationOptions.focus !== false) target.focus();
    select(name);
    return true;
  }

  return {
    start() {
      Object.entries(buttons).forEach(([name, button]) => {
        if (!button || listeners.has(button)) return;
        const listener = event => {
          event.preventDefault();
          navigate(name);
          if (options.onSectionChange) options.onSectionChange(name, { replace:false });
        };
        listeners.set(button, listener);
        button.addEventListener('click', listener);
      });
      select('overview');
      const observe = options.observe || ((handler, observedTargets) => {
        if (typeof IntersectionObserver === 'undefined') return null;
        const instance = new IntersectionObserver(handler, {
          root: options.root || null,
          rootMargin: '-20% 0px -60% 0px',
          threshold: [0, 0.25, 0.5, 0.75, 1],
        });
        observedTargets.forEach(target => instance.observe(target));
        return instance;
      });
      observer = observe(entries => {
        const visible = entries
          .filter(entry => entry.isIntersecting && targetNames.has(entry.target))
          .sort((left, right) => right.intersectionRatio - left.intersectionRatio)[0];
        if (visible) {
          const name = targetNames.get(visible.target);
          select(name);
          if (options.onSectionChange) options.onSectionChange(name, { replace:true });
        }
      }, Array.from(targetNames.keys()).filter(Boolean));
    },
    stop() {
      listeners.forEach((listener, button) => button.removeEventListener('click', listener));
      listeners.clear();
      if (observer) observer.disconnect();
      observer = null;
    },
    navigate,
    select,
  };
}

if (typeof module !== 'undefined') module.exports = createMobileIssueDetailNavigation;
