import { isPopout } from 'utils/popouts';

/**
 * standardWidgetAction
 * Creates a standard widget action to be dispatched. Should be used as the payload
 * of a standardAction.
 * Contains the widgetId of the widget this originates from.
 * A payload can also be optionally set and is spread into the returned Object.
 *
 * @name standardWidgetAction
 * @function
 * @param {int (or whatever type we are using for ids)} widgetId The id of the widget this action is for
 * @param {Object} payload The payload of the action. Is flattened into the returned object
 * @returns {Object} An object to be dispatched for widget actions
 */
export function standardWidgetAction(widgetId, payload = {}) {
  const standWidAct = {
    widgetId,
    isPopout: isPopout(),
  };
  // Payload is spread into the returned object so we don't have too look too
  // deep to get the data we want
  return Object.assign({}, payload, standWidAct);
}

export const ADD_WIDGET_CALENDAR = 'ADD_WIDGET_CALENDAR';
export function addWidgetCalendar(calendar = null) {
  return {
    type: ADD_WIDGET_CALENDAR,
    calendar
  };
}

export const ADD_WIDGET_NEWSFEED = 'ADD_WIDGET_NEWSFEED';
export function addWidgetNewsfeed(filters = null) {
  return {
    type: ADD_WIDGET_NEWSFEED,
    filters
  };
}

export const ADD_WIDGET_SECURITY = 'ADD_WIDGET_SECURITY';
export function addWidgetSecurity(symbol = null) {
  return {
    type: ADD_WIDGET_SECURITY,
    symbol
  };
}

export const ADD_WIDGET_WATCHLIST = 'ADD_WIDGET_WATCHLIST';
export function addWidgetWatchlist() {
  return {
    type: ADD_WIDGET_WATCHLIST
  };
}
