import { useNewsletterStore } from "@/stores/admin/newsletter";
import { useNewsletterDatesStore } from "@/stores/admin/newsletterDates";
import { useNewsletterRecipientsStore } from "@/stores/admin/newsletterRecipients";
import { useNewsletterPrintoutStore } from "../stores/admin/newsletterPrintout";

export async function setNewsletterId(to: any, from: any, next: any) {
  const newsletter = useNewsletterStore();
  newsletter.activeNewsletter = to.params?.newsletterId ?? null;

  useNewsletterDatesStore().$reset();
  useNewsletterRecipientsStore().$reset();
  useNewsletterPrintoutStore().unsubscribePdfPrintingProgress();
  useNewsletterPrintoutStore().unsubscribeMailSendingProgress();
  useNewsletterPrintoutStore().$reset();

  next();
}

export async function resetNewsletterStores(to: any, from: any, next: any) {
  const newsletter = useNewsletterStore();
  newsletter.activeNewsletter = null;
  newsletter.activeNewsletterObj = null;

  useNewsletterDatesStore().$reset();
  useNewsletterRecipientsStore().$reset();
  useNewsletterPrintoutStore().unsubscribePdfPrintingProgress();
  useNewsletterPrintoutStore().unsubscribeMailSendingProgress();
  useNewsletterPrintoutStore().$reset();

  next();
}
