"use strict";

require("core-js/modules/web.dom.iterable");

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

var _react = _interopRequireWildcard(require("react"));

var _reactBootstrap = require("react-bootstrap");

var _styledComponents = _interopRequireDefault(require("styled-components"));

var _contexts = require("../../util/contexts");

var _icon = _interopRequireDefault(require("../util/icon"));

var _batchStyled = require("./batch-styled");

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

function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

const MODE_OPTIONS = [{
  label: 'Transit',
  mode: 'TRANSIT'
}, {
  label: 'Walking',
  mode: 'WALK'
}, {
  label: 'Drive',
  mode: 'CAR'
}, {
  label: 'Bicycle',
  mode: 'BICYCLE'
}, {
  icon: 'mobile',
  label: 'Rental options',
  mode: 'RENT' // TODO: include HAIL?

}];
exports.MODE_OPTIONS = MODE_OPTIONS;

const ModeButtons = ({
  className,
  onClick,
  selectedModes = []
}) => {
  return MODE_OPTIONS.map((item, index) => /*#__PURE__*/_react.default.createElement(StyledModeButton, {
    className: className,
    item: item,
    key: item.mode,
    onClick: onClick,
    selected: selectedModes.indexOf(item.mode) !== -1
  }));
};

const CheckMarkIcon = (0, _styledComponents.default)(_icon.default)`
  position: absolute;
  bottom: 2px;
  right: 2px;
  color: green;
`;

const ModeButton = ({
  className,
  item,
  onClick,
  selected
}) => {
  const {
    ModeIcon
  } = (0, _react.useContext)(_contexts.ComponentContext);
  const {
    icon,
    label,
    mode
  } = item;
  return /*#__PURE__*/_react.default.createElement(_reactBootstrap.OverlayTrigger, {
    overlay: /*#__PURE__*/_react.default.createElement(_reactBootstrap.Tooltip, {
      id: mode
    }, label),
    placement: "bottom"
  }, /*#__PURE__*/_react.default.createElement("button", {
    className: className,
    onClick: () => onClick(mode)
  }, icon ? /*#__PURE__*/_react.default.createElement(_icon.default, {
    className: "fa-2x",
    type: icon
  }) : /*#__PURE__*/_react.default.createElement(ModeIcon, {
    height: 25,
    mode: mode
  }), selected && /*#__PURE__*/_react.default.createElement(CheckMarkIcon, {
    type: "check"
  })));
};

const StyledModeButton = (0, _styledComponents.default)(ModeButton)`
  ${_batchStyled.buttonCss}
  &.flex {
    flex-grow: 1;
    margin-right: 5px;
  }
  &.straight-corners {
    border-radius: 0px;
  }
  border: 0px;
  position: relative;
`;
exports.StyledModeButton = StyledModeButton;
var _default = ModeButtons;
exports.default = _default;

//# sourceMappingURL=mode-buttons.js