"use strict";

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

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

var _locationIcon = _interopRequireDefault(require("@opentripplanner/location-icon"));

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

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

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

var _reactRedux = require("react-redux");

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

var _state = require("../../util/state");

var _editSearchButton = _interopRequireDefault(require("./edit-search-button"));

var _navigationBar = _interopRequireDefault(require("./navigation-bar"));

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 _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

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

const LocationContainer = _styledComponents.default.div`
  font-weight: 300;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
`;
const LocationSummaryContainer = _styledComponents.default.div`
  height: 50px;
  left: 0;
  padding-right: 10px;
  position: fixed;
  right: 0;
  top: 50px;
`;
const LocationsSummaryColFromTo = (0, _styledComponents.default)(_reactBootstrap.Col)`
  font-size: 1.1em;
  line-height: 1.2em;
`;
const LocationsSummaryRow = (0, _styledComponents.default)(_reactBootstrap.Row)`
  padding: 4px 8px;
`;
const StyledLocationIcon = (0, _styledComponents.default)(_locationIcon.default)`
  margin: 3px;
`;
/**
 * This component renders the results header and an error message
 * if no itinerary was found.
 */

class ResultsHeader extends _react.Component {
  render() {
    const {
      errors,
      query,
      resultCount
    } = this.props;
    const hasNoResult = resultCount === 0 && errors.length > 0;
    const headerText = hasNoResult ? 'No Trip Found' : resultCount ? `We Found ${resultCount} Option${resultCount > 1 ? 's' : ''}` : 'Waiting...';
    return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_navigationBar.default, {
      headerText: headerText
    }), /*#__PURE__*/_react.default.createElement(LocationSummaryContainer, null, /*#__PURE__*/_react.default.createElement(LocationsSummaryRow, {
      className: "locations-summary"
    }, /*#__PURE__*/_react.default.createElement(LocationsSummaryColFromTo, {
      sm: 11,
      xs: 8
    }, /*#__PURE__*/_react.default.createElement(LocationContainer, null, /*#__PURE__*/_react.default.createElement(StyledLocationIcon, {
      type: "from"
    }), " ", query.from ? query.from.name : ''), /*#__PURE__*/_react.default.createElement(LocationContainer, {
      style: {
        marginTop: 2
      }
    }, /*#__PURE__*/_react.default.createElement(StyledLocationIcon, {
      type: "to"
    }), " ", query.to ? query.to.name : '')), /*#__PURE__*/_react.default.createElement(_reactBootstrap.Col, {
      sm: 1,
      xs: 4
    }, /*#__PURE__*/_react.default.createElement(_editSearchButton.default, {
      className: "edit-search-button pull-right"
    }, "Edit")))));
  }

} // connect to the redux store


_defineProperty(ResultsHeader, "propTypes", {
  errors: _propTypes.default.array,
  query: _propTypes.default.object,
  resultCount: _propTypes.default.number
});

const mapStateToProps = (state, ownProps) => {
  const activeSearch = (0, _state.getActiveSearch)(state);
  const {
    useRealtime
  } = state.otp;
  const response = !activeSearch ? null : useRealtime ? activeSearch.response : activeSearch.nonRealtimeResponse;
  const itineraries = (0, _state.getActiveItineraries)(state);
  return {
    errors: (0, _state.getResponsesWithErrors)(state),
    query: state.otp.currentQuery,
    resultCount: response ? itineraries.length : null
  };
};

var _default = (0, _reactRedux.connect)(mapStateToProps)(ResultsHeader);

exports.default = _default;
module.exports = exports.default;

//# sourceMappingURL=results-header.js