{"size": 2003, "ext": "js", "max_stars_repo_path": "src/functions/getOptionInfo.js", "max_stars_repo_name": "weterynarzfred/options", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/functions/getOptionInfo.js", "max_issues_repo_name": "weterynarzfred/options", "max_issues_repo_issues_event_min_datetime": "2021-09-03T01:40:02.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-15T08:26:10.000Z", "max_forks_repo_path": "src/functions/getOptionInfo.js", "max_forks_repo_name": "weterynarzfred/options", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 2, "max_forks_count": null, "avg_line_length": 32.3064516129, "max_line_length": 86, "alphanum_fraction": 0.6674987519}
import getControlType from './getControlType';
import getSubptions from './getSubptions';
import getDepth from './getDepth';
import isOptionDisabled from './isOptionDisabled';

export default function getOptionInfo(option, options) {
  if (option.path === undefined) return { suboptions: options };
  const optionInfo = {
    controlType: getControlType(option),
    suboptions: getSubptions(option, options),
    depth: getDepth(option, options),
  };
  optionInfo.isOpenable = Object.keys(optionInfo.suboptions).length > 0;
  optionInfo.image = option.image;
  optionInfo.imageCy = option.imageCy;
  optionInfo.imageCx = option.imageCx;
  optionInfo.getStastsFrom = option;

  // when controlType === select
  optionInfo.isSelectableSuboption = option.type === 'option' &&
    option.min === 0 &&
    !option.disableUseAsSelect &&
    option.max === 1;

  if (optionInfo.controlType === 'select') {
    optionInfo.selectableSuboptions = [];
    for (const slug in optionInfo.suboptions) {
      const suboption = optionInfo.suboptions[slug];
      if (
        suboption.type === 'option' &&
        suboption.max === 1 &&
        suboption.min === 0 &&
        !suboption.disableUseAsSelect &&
        (
          !isOptionDisabled(suboption, options) ||
          suboption.showWhenDisabled
        )
      ) {
        optionInfo.selectableSuboptions.push(suboption);
        if (suboption.selected) {
          optionInfo.selectedSuboptionId = optionInfo.selectableSuboptions.length - 1;
        }
      }
    }
    if (optionInfo.selectableSuboptions.length <= 1) {
      optionInfo.controlType = false;
    }

    const selected = optionInfo.selectableSuboptions[optionInfo.selectedSuboptionId];
    if (selected !== undefined) {
      optionInfo.getStastsFrom = selected;
      if (!option.dontUseImageOfSelected) {
        optionInfo.image = selected.image;
        optionInfo.imageCy = selected.imageCy;
        optionInfo.imageCx = selected.imageCx;
      }
    }
  }

  return optionInfo;
}
