"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.macroToItemArrayBase = exports.macroAirwayLabelMap = exports.macroDrugLabelMap = exports.macroLabelMap = void 0;

var _textFormat = require("./text-format");

/**
 * @type {{
 *   [K in MacroKey]: any
 * }}
 */
const macroLabelMap = {
  userRole: {
    label: 'Provider Role',
    format: role => ({
      both: 'Surgeon/Anesthesia Provider',
      sedationProvider: 'Anesthesia Provider',
      surgeon: 'Surgeon'
    })[role]
  },
  asaClassification: 'ASA Classification',
  surgeonName: 'Surgeon',
  sedationProviderName: 'Anesthesia Provider',
  pregnant: {
    label: 'Chance of Pregnancy',
    format: val => val === 'n' ? 'No' : 'Yes'
  },
  procedureNotes: 'Notes',
  preProcedureRiskAssessment: 'Pre-procedure risk assessment',
  dischargeScoreType: {
    label: _textFormat.spaceAndCapitalize,
    format: _textFormat.capitalize
  }
};
exports.macroLabelMap = macroLabelMap;
const macroDrugLabelMap = {
  dose: 'Typical First Dose',
  draw: 'First Draw'
};
exports.macroDrugLabelMap = macroDrugLabelMap;
const macroAirwayLabelMap = {
  preOx: 'Pre-oxygenation',
  inflated: 'Cuff inflated',
  deflated: 'Deflated before removal',
  placementCompDetail: 'Placement complications',
  removalComp: 'Removal complications',
  removalCompDetail: 'Removal details',
  peep: 'PEEP',
  preRemovalSpo2: 'Pre-removal SpO₂',
  postRemovalSpo2: 'Post-removal SpO₂'
};
exports.macroAirwayLabelMap = macroAirwayLabelMap;

const defaultFormat = val => {
  const type = typeof val;

  if (type === 'boolean') {
    return val ? 'Yes' : 'No';
  }

  return val;
};

const getLabel = (lookup, key) => {
  const match = lookup[key];
  const type = typeof (match && match.label);

  if (type === 'string') {
    return match.label;
  }

  if (type === 'function') {
    return match.label(key);
  }

  return match || (0, _textFormat.spaceAndCapitalize)(key);
};
/**
 * @param {any} object
 * @param {string} basePath
 * @param {{
 *   [id: string]:
 *     | string
 *     | {
 *         label: string
 *         format: (val: any) => string
 *       }
 * }} def
 * @returns {{ label: string; name: string; value: any; path: string }[]}
 */


const macroToItemArrayBase = (object, basePath, def) => {
  const toReturn = [];

  for (const key in object) {
    const match = def[key];
    const rawValue = object[key];
    toReturn.push({
      name: key,
      path: "".concat(basePath, ".").concat(key),
      value: match && match.format ? match.format(rawValue) : defaultFormat(rawValue),
      label: getLabel(def, key)
    });
  }

  return toReturn;
};

exports.macroToItemArrayBase = macroToItemArrayBase;