import { inject } from '@angular/core';
import { CanDeactivateFn } from '@angular/router';
import { AdminCategoriesFacade } from '../facade/admin-categories.facade';
import { AdminCategoryEditorPageComponent } from '../pages/admin-category-editor-page.component';
import { TranslateService } from '../../../../i18n/translate.service';

export const adminCategoryDirtyGuard: CanDeactivateFn<AdminCategoryEditorPageComponent> = () => {
  const facade = inject(AdminCategoriesFacade);
  if (!facade.dirty()) {
    return true;
  }
  const translate = inject(TranslateService);
  return window.confirm(translate.t('adminCategories.confirmLeaveUnsaved'));
};
