import { findExamples } from '@looker/sdk-codegen';
import { theme } from '@looker/components';
export var PER_PAGE_COUNT = 10;
export var EMPTY_STRING = '';
export var exampleColumns = [{
  id: 'filename',
  title: 'Filename',
  type: 'string',
  size: 30
}, {
  id: 'language',
  title: 'Language',
  type: 'string',
  size: 20
}, {
  id: 'description',
  title: 'Description',
  type: 'string',
  size: 40
}, {
  id: 'line',
  title: 'Line',
  type: 'number',
  size: 20
}];
export function getFileNameFromPath(path) {
  var lastForwardSlash = path.lastIndexOf('/');
  return lastForwardSlash === -1 ? path : path.slice(lastForwardSlash + 1, path.indexOf(' '));
}
export function prepareExampleDataTable(languages, examples, operationId, currentPage) {
  var tableExamples = languages.reduce(function (result, language) {
    var languageExamples = findExamples(examples, language, operationId);
    return [...result, ...languageExamples.map(exampleLink => {
      return {
        filename: getFileNameFromPath(exampleLink.tooltip),
        line: exampleLink.lineNumber,
        language: language.toLowerCase(),
        permalink: exampleLink.permalink,
        description: exampleLink.description
      };
    })];
  }, []);
  var pageExamples = tableExamples.filter((example, index) => example && index + 1 > (currentPage - 1) * PER_PAGE_COUNT && index + 1 <= currentPage * PER_PAGE_COUNT);
  var pageLimit = Math.ceil(tableExamples.length / PER_PAGE_COUNT);
  var paginate = tableExamples.length > PER_PAGE_COUNT;

  if (tableExamples.length > PER_PAGE_COUNT) {
    while (pageExamples.length !== PER_PAGE_COUNT) {
      pageExamples.push({
        filename: EMPTY_STRING,
        line: EMPTY_STRING,
        language: EMPTY_STRING,
        permalink: pageExamples.length.toString(),
        description: EMPTY_STRING
      });
    }
  }

  return {
    pageExamples,
    pageLimit,
    paginate
  };
}
export function getTableItemBottomBorder(hide) {
  return hide ? 'none' : "solid 1px ".concat(theme.colors.ui2);
}
export function sortLanguagesByPreference(languages, sdkLanguage) {
  languages.some((item, idx) => item === sdkLanguage && languages.unshift(languages.splice(idx, 1)[0]));
  return languages;
}
//# sourceMappingURL=utils.js.map