import { mainSelectorOptions, checkboxOptions } from './optionsValue';

function buildMainSelectorOption(key, label) {
  const objLabel = label || mainSelectorOptions[key].label;
  return { ...mainSelectorOptions[key], label: objLabel };
}

export function buildMainSelectorOptions({ optionValues }) {
  const visibleOptions = Object.keys(optionValues)
    .filter(key => optionValues[key].visible)
    .map(key => buildMainSelectorOption(key, optionValues[key].label));

  const first = visibleOptions
    .filter(option => option.first);

  const last = visibleOptions
    .filter(option => !option.first);

  return {
    first,
    last,
    custom: optionValues.customOptions,
  };
}

export function buildFilterItem(entityType) {
  return kd.FilterItem(entityType, 'KdId', entityType, null);
}

export function getCheckboxData(type, value) {
  const { data } = checkboxOptions[type].find(
    option => option.value === value,
  );

  return data;
}
