"use strict";

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

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

var _coreUtils = _interopRequireDefault(require("@opentripplanner/core-utils"));

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

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

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

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

var uiActions = _interopRequireWildcard(require("../../actions/ui"));

var _map = _interopRequireDefault(require("../map/map"));

var _narrativeItineraries = _interopRequireDefault(require("../narrative/narrative-itineraries"));

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

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

var _container = _interopRequireDefault(require("./container"));

var _resultsError = _interopRequireDefault(require("./results-error"));

var _resultsHeader = _interopRequireDefault(require("./results-header"));

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

const StyledMobileContainer = (0, _styledComponents.default)(_container.default)`
  .options > .header {
    margin: 10px;
  }

  &.otp.mobile .mobile-narrative-container {
    bottom: 0;
    left: 0;
    overflow-y: auto;
    padding: 0;
    position: fixed;
    right: 0;
  }
`;
const ExpandMapButton = (0, _styledComponents.default)(_reactBootstrap.Button)`
  bottom: 10px;
  left: 10px;
  position: absolute;
  z-index: 999999;
`;
const NARRATIVE_SPLIT_TOP_PERCENT = 45; // Styles for the results map also include prop-independent styles copied from mobile.css.

const ResultsMap = _styledComponents.default.div`
  bottom: ${props => props.expanded ? '0' : `${100 - NARRATIVE_SPLIT_TOP_PERCENT}%`};
  display: ${props => props.visible ? 'inherit' : 'none'};
  left: 0;
  position: fixed;
  right: 0;
  top: 100px;
`;
const narrativeCss = (0, _styledComponents.css)`
  top: ${props => props.visible ? props.expanded ? '100px' : `${NARRATIVE_SPLIT_TOP_PERCENT}%` : '100%'};
  transition: top 300ms;
`;
const StyledResultsError = (0, _styledComponents.default)(_resultsError.default)`
  display: ${props => props.visible ? 'inherit' : 'none'};
  ${narrativeCss}
`;
const NarrativeContainer = _styledComponents.default.div`
  ${narrativeCss}
`;
const {
  ItineraryView
} = uiActions;
/**
 * This component renders the mobile view of itinerary results from batch routing,
 * and features a split view between the map and itinerary results or narratives.
 */

const BatchMobileResultsScreen = ({
  errors,
  itineraries,
  itineraryView,
  toggleBatchResultsMap
}) => {
  const hasErrorsAndNoResult = itineraries.length === 0 && errors.length > 0;
  const mapExpanded = itineraryView === ItineraryView.LEG_HIDDEN || itineraryView === ItineraryView.LIST_HIDDEN;
  const itineraryExpanded = itineraryView === ItineraryView.FULL;
  return /*#__PURE__*/_react.default.createElement(StyledMobileContainer, null, /*#__PURE__*/_react.default.createElement(_resultsHeader.default, null), /*#__PURE__*/_react.default.createElement(ResultsMap, {
    expanded: mapExpanded,
    visible: !itineraryExpanded
  }, /*#__PURE__*/_react.default.createElement(_map.default, null), /*#__PURE__*/_react.default.createElement(ExpandMapButton, {
    bsSize: "small",
    onClick: toggleBatchResultsMap
  }, /*#__PURE__*/_react.default.createElement(_icon.default, {
    name: mapExpanded ? 'list-ul' : 'arrows-alt'
  }), ' ', mapExpanded ? 'Show results' : 'Expand map')), hasErrorsAndNoResult ? /*#__PURE__*/_react.default.createElement(StyledResultsError, {
    error: errors[0],
    expanded: itineraryExpanded,
    visible: !mapExpanded
  }) : /*#__PURE__*/_react.default.createElement(NarrativeContainer, {
    className: "mobile-narrative-container",
    expanded: itineraryExpanded,
    visible: !mapExpanded
  }, /*#__PURE__*/_react.default.createElement(_narrativeItineraries.default, {
    containerStyle: {
      background: '#fff',
      display: 'flex',
      flexDirection: 'column',
      height: '100%',
      width: '100%'
    }
  })));
}; // connect to the redux store


const mapStateToProps = (state, ownProps) => {
  const activeSearch = (0, _state.getActiveSearch)(state);

  const urlParams = _coreUtils.default.query.getUrlParams();

  return {
    activeLeg: activeSearch ? activeSearch.activeLeg : null,
    errors: (0, _state.getResponsesWithErrors)(state),
    itineraries: (0, _state.getActiveItineraries)(state),
    itineraryView: urlParams.ui_itineraryView || ItineraryView.LIST
  };
};

const mapDispatchToProps = {
  toggleBatchResultsMap: uiActions.toggleBatchResultsMap
};

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

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

//# sourceMappingURL=batch-results-screen.js