import { stringifyOperations } from '../utils';

const render = {};

/**
 * ### Render
 *
 * @module render
 */
export default (state) => {
  /**
   * Get URL for rendering an image.
   *
   * ```js
   * rokka.render.getUrl('myorg', 'c421f4e8cefe0fd3aab22832f51e85bacda0a47a', 'png', 'mystack')
   * ```
   *
   * @param  {string}       organization name
   * @param  {string}       hash         image hash
   * @param  {string}       format       image format: `jpg`, `png` or `gif`
   * @param  {string|array} mixed        stack operation name or array of stack operation objects
   * @return {string}
   */
  render.getUrl = (organization, hash, format, mixed) => {
    const host = state.renderHost.replace('{organization}', organization);
    const mixedParam = Array.isArray(mixed)
      ? stringifyOperations(mixed) // array of operations
      : mixed; // stack name
    const stack = mixedParam ? `${mixedParam}` : 'original';

    return `${host}/${stack}/${hash}.${format}`;
  };

  return {
    render
  };
};

@@ -789,16 +789,27 @@
       ? 
+%60dynamic/$%7B
 stringif
@@ -826,16 +826,18 @@
 s(mixed)
+%7D%60
  // arra

fix render.getUrl with dynamic stack operations