export function slugifyIfMissing({
  data,
  operation,
}: {
  data?: { title?: string; slug?: string };
  operation?: string;
}) {
  if (!data) return data;
  if (operation !== "create") return data;
  if (data.slug) return data;
  if (!data.title) return data;

  data.slug = data.title
    .toLowerCase()
    .replace(/[^a-z0-9]+/g, "-")
    .replace(/^-+|-+$/g, "");

  return data;
}
