// @ts-check
const browserSync = require("browser-sync").create("AcantoWorkflow");

function browserSyncStart() {
  const { getServerPort } = require("../webpack/helpers");
  const port = getServerPort();

  const browserSyncOptions = {
    port: port,
    open: false, // "local", // TODO: arg option minimist
    logLevel: "info", // 'silent'
    notify: false,
    stream: true,
    injectChanges: true,
    online: false,
    reloadDebounce: 300,
    proxy: {
      target: process.env.APP_URL,
    },
  };

  if (process.env.DEV_BROWSERSYNC_HOST) {
    browserSyncOptions.host = process.env.DEV_BROWSERSYNC_HOST;
  }

  // @see https://www.browsersync.io/docs/options
  // @ts-ignore
  browserSync.init({ ...browserSyncOptions });
}

module.exports = {
  browserSync,
  browserSyncStart,
};
