import { ViewportScroller } from '@angular/common';
import { inject } from '@angular/core';
import { Router } from '@angular/router';
import { injectStorage, SessionStorageProvider } from '@isa/core/storage';

/**
 * Stores the current scroll position in session storage.
 * Uses the current router URL as the key.
 */
export async function storeScrollPosition() {
  const router = inject(Router);
  const viewportScroller = inject(ViewportScroller);
  const sessionStorage = injectStorage(SessionStorageProvider);

  const url = router.url;
  sessionStorage.set(url, viewportScroller.getScrollPosition());
}
