"use strict";

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

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

var _itinerary = require("@opentripplanner/core-utils/lib/itinerary");

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

var _propTypes = _interopRequireDefault(require("prop-types"));

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

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; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

// FIXME: Some of these must be marked !important, otherwise the summary-block
// mode-block css class selectors will take precedence.
const Block = _styledComponents.default.div`
  background-color: ${props => getModeColor(props.mode)};
  height: 24px!important;
  margin: 0px!important;
  padding: 3px!important;
  width: 24px!important;
  :first-child {
    border-top-left-radius: 4px;
    border-bottom-left-radius: 4px;
  }
  :last-child {
    border-top-right-radius: 4px;
    border-bottom-right-radius: 4px;
  }
`;
const modeColors = {
  BICYCLE: '#E0C3E2',
  BUS: '#CAC3DF',
  CAR: '#E4CCCC',
  PARK: '#E4CCCC',
  RAIL: '#BDDAC0',
  WALK: '#DFC486'
};
const DEFAULT_COLOR = '#685C5C';

function getModeColor(mode) {
  if (!mode) return DEFAULT_COLOR;
  let color = modeColors[mode.toUpperCase()];
  if (typeof color === 'undefined') color = DEFAULT_COLOR;
  return color;
}

class ItinerarySummary extends _react.Component {
  render() {
    const {
      itinerary,
      LegIcon
    } = this.props;
    const blocks = [];
    itinerary.legs.forEach((leg, i) => {
      // Skip mid-itinerary walk transfer legs
      if (i > 0 && i < itinerary.legs.length - 1 && !leg.transitLeg && itinerary.legs[i - 1].transitLeg && itinerary.legs[i + 1].transitLeg) {
        return null;
      } // Add the mode icon


      let title = leg.mode;

      if (leg.transitLeg) {
        title = leg.routeShortName ? `${leg.routeShortName}${leg.routeLongName ? ` - ${leg.routeLongName}` : ''}` : leg.routeLongName;
      }

      const company = (0, _itinerary.getCompanyFromLeg)(leg);
      let iconStyle; // FIXME: hack for HOPR company logo, which must be offset a few pixels
      // to look good.

      if (company && company.toLowerCase() === 'hopr') {
        iconStyle = {
          marginTop: '-5px'
        };
      }

      blocks.push( /*#__PURE__*/_react.default.createElement(Block, {
        className: "summary-block mode-block",
        key: blocks.length,
        mode: leg.mode,
        title: title
      }, /*#__PURE__*/_react.default.createElement(LegIcon, {
        leg: leg,
        style: iconStyle
      })));
    });
    return /*#__PURE__*/_react.default.createElement("div", {
      className: "summary"
    }, blocks);
  }

}

exports.default = ItinerarySummary;

_defineProperty(ItinerarySummary, "propTypes", {
  itinerary: _propTypes.default.object,
  LegIcon: _propTypes.default.elementType.isRequired
});

module.exports = exports.default;

//# sourceMappingURL=itinerary-summary.js