{"size": 1619, "ext": "js", "max_stars_repo_path": "src/lib/mediaUtil.js", "max_stars_repo_name": "Yunicorn228/web-tools", "max_stars_repo_stars_event_min_datetime": "2017-06-12T15:53:14.000Z", "max_stars_repo_stars_event_max_datetime": "2020-08-31T15:23:38.000Z", "max_issues_repo_path": "src/lib/mediaUtil.js", "max_issues_repo_name": "Yunicorn228/web-tools", "max_issues_repo_issues_event_min_datetime": "2017-05-04T17:14:15.000Z", "max_issues_repo_issues_event_max_datetime": "2020-09-28T18:32:00.000Z", "max_forks_repo_path": "src/lib/mediaUtil.js", "max_forks_repo_name": "Yunicorn228/web-tools", "max_forks_repo_forks_event_min_datetime": "2017-10-10T20:07:07.000Z", "max_forks_repo_forks_event_max_datetime": "2020-08-30T14:03:06.000Z"}
{"max_stars_count": 32, "max_issues_count": 1316, "max_forks_count": 20, "avg_line_length": 37.6511627907, "max_line_length": 119, "alphanum_fraction": 0.7047560222}
export const VIEW_ALL_STORIES = 'VIEW_ALL_STORIES';
export const VIEW_REGULARLY_COLLECTED = 'VIEW_REGULARLY_COLLECTED';
export const ALL_MEDIA = -1;
// TODO replace these with explorer PICK_ vars
export const MEDIAPICKER_SOURCES_COLLECTIONS_QUERY_SETTING = 1;
export const MEDIAPICKER_FEATURED_QUERY_SETTING = 0;

/* this is set up to match the expected params within the metadataCheckboxFieldArray */
export function importTagsFromCustomSearches(tagsObj, lookupReadableMetadataName) {
  if (tagsObj) {
    const updatedTagsObj = {};
    Object.keys(tagsObj).forEach((m) => { // for each tag
      const vals = Object.values(tagsObj[m]);
      if (vals && vals.length > 0) {
        const readableName = lookupReadableMetadataName(parseInt(m, 10));
        updatedTagsObj[readableName] = Object.values(tagsObj[m]).map(a => ({
          name: readableName,
          tags_id: a,
          tag_sets_id: parseInt(m, 10),
          label: 'Pub Country',
          tag_set_label: 'Pub Country',
          tag_set_name: 'pub_country',
          selected: true,
          value: true,
        }));
      }
    });
    return updatedTagsObj;
  }
  return [];
}

export function decodeQueryParamString(queryString, lookupReadableMetadataName) {
  const queriesFromUrl = queryString; // tags and searchstr
  if (queryString.query && queryString.query.search) {
    queriesFromUrl.mediaKeyword = queryString.query.search;
  }
  if (queryString.query && queryString.query.tags) {
    queriesFromUrl.tags = importTagsFromCustomSearches(JSON.parse(queryString.query.tags), lookupReadableMetadataName);
  }
  return queriesFromUrl;
}
