import Router from 'next/router';
import { NextApiResponse } from 'next';

interface RedictionOptions {
  res?: NextApiResponse;
  status?: number;
}

export default function redirectTo(destination: never, { res, status }: RedictionOptions = {}): void {
  if (res) {
    res.writeHead(status || 302, { Location: destination });
    //res.redirect(destination)
    res.end();
  } else {
    if (destination[0] === '/' && destination[1] !== '/') {
      Router.push(destination);
    } else {
      window.location = destination;
    }
  }
}
