"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.AppointmentStatus = void 0;

var _preact = require("preact");

var _classnames = _interopRequireDefault(require("classnames"));

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

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

/**
 * @typedef {  | 'proposed'
 *   | 'pending'
 *   | 'booked'
 *   | 'arrived'
 *   | 'fulfilled'
 *   | 'cancelled'
 *   | 'noshow'
 *   | 'entered-in-error'
 *   | 'checked-in'
 *   | 'waitlist'} AppointmentStatus
 */

/**
 * @param {AppointmentStatus} status
 * @returns {string}
 */
const getClasses = status => {
  if (status === 'booked') {
    return 'bg-lightest-blue';
  }

  if (status === 'arrived') {
    return 'bg-orange white';
  }

  if (status === 'fulfilled') {
    return 'bg-green';
  }

  if (status === 'checked-in' || status === 'pending' || status === 'proposed') {
    return 'bg-yellow';
  }

  if (status === 'entered-in-error' || status === 'noshow' || status === 'cancelled') {
    return 'bg-red white';
  }

  return 'bg-orange white';
};
/**
 * Small wrapped component for showing a color-coded FHIR appointment status.
 *
 * @typedef {import('preact').FunctionComponent} Appointment
 * @param {{
 *   status: AppointmentStatus
 *   className?: string
 *   children?: any
 * }} Props
 */


const AppointmentStatus = (_ref) => {
  let {
    status,
    className,
    children
  } = _ref,
      rest = _objectWithoutProperties(_ref, ["status", "className", "children"]);

  return (0, _preact.h)("span", _extends({
    className: (0, _classnames.default)('pa1 br2 fw4 f5', getClasses(status), className)
  }, rest), children || (0, _textFormat.deSlug)(status));
};

exports.AppointmentStatus = AppointmentStatus;