{"size": 1430, "ext": "js", "max_stars_repo_path": "helpers.js", "max_stars_repo_name": "Waitroom/react-native-typeform-embed", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "helpers.js", "max_issues_repo_name": "Waitroom/react-native-typeform-embed", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "helpers.js", "max_forks_repo_name": "Waitroom/react-native-typeform-embed", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 28.6, "max_line_length": 118, "alphanum_fraction": 0.6727272727}
const embedTypes = {
  widget: 'embed-widget',
  popup: 'popup-blank',
  slider: 'popup-drawer',
  popover: 'popup-popover',
  'side-tab': 'popup-side-panel',
};

const getEmbedOptions = (props) => {
  const embedOptions = [
    'typeform-medium=embed-sdk',
    'typeform-medium-version=next',
  ];

  const embedType = embedTypes[props.type];
  if (!embedType) return null;
  embedOptions.push(`typeform-embed=${embedType}`);

  if (props.source) {
    embedOptions.push(`typeform-source=${props.source}`);
  }

  if (props.enableSandbox) {
    embedOptions.push(
      'disable-tracking=true&__dangerous-disable-submissions=true'
    );
  }

  embedOptions.push(`embed-hide-headers=${props.hideHeader}`);
  embedOptions.push(`embed-hide-footer=${props.hideFooter}`);

  // TODO: Add embed-opacity, disable-tracking, disable-auto-focus, share-ga-instance, force-touch, add-placeholder-ws

  return embedOptions;
};

export const getTypeformUrl = (props) => {
  const baseUrl = `https://form.typeform.com/to/${props.id}`;
  const embedOptions = getEmbedOptions(props);
  const embedOptionsStr = embedOptions ? `?${embedOptions.join('&')}` : '';
  const hiddenFields = Object.entries(props.hidden).map(
    ([key, value]) => `${key}=${value}`
  );
  const hiddenFieldsStr = hiddenFields.length
    ? `#${hiddenFields.join('&')}`
    : '';
  const url = `${baseUrl}${embedOptionsStr}${hiddenFieldsStr}`;
  return encodeURI(url);
};
