import { IDocumentGetInitialProps } from './types';
import * as bowser from 'bowser';
const glamor = require('glamor/server');

export { IDocumentGetInitialProps };
export { React, fastClick } from '../common';
export * from '../components';

/**
 * Server renders the Glamor CSS.
 */
export function renderCss(args: IDocumentGetInitialProps) {
  const page = args.renderPage();
  const styles = glamor.renderStatic(() => page.html);
  return { ...page, ...styles };
}

/**
 * Retrieves browser information.
 */
export function browser(args: IDocumentGetInitialProps) {
  const userAgent = args.req.headers['user-agent'] as string;
  return bowser._detect(userAgent);
}

/**
 * Determines if the app is running in dev mode.
 */
export function isDev(args: IDocumentGetInitialProps) {
  const { req } = args;
  const host = req.headers && req.headers.host && req.headers.host;
  return host && host.startsWith('localhost');
}
