"use strict";

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

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

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

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

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

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

var _connectedLinks = require("../../form/connected-links");

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

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 FIELD_HEIGHT_PX = '60px';
const Container = _styledComponents.default.div`
  align-items: stretch;
  display: flex;
  height: ${FIELD_HEIGHT_PX};
  margin-bottom: 10px;
`;
const PlaceButton = (0, _styledComponents.default)(_reactBootstrap.Button)`
  align-items: center;
  display: flex;
  flex: 1 0 0;
  overflow: hidden;
  text-align: left;
  width: inherit;
`;
const GreyIcon = (0, _styledComponents.default)(_icon.default)`
  color: #888;
  margin-right: 10px;
`;
const PlaceContent = _styledComponents.default.span`
  display: inline-block;

  & * {
    color: #888;
    display: block;
  }

  & *:first-child {
    color: inherit;
  }
`;
const deleteCss = (0, _styledComponents.css)`
  margin-left: 4px;
  width: ${FIELD_HEIGHT_PX};
`;
const DeleteButton = (0, _styledComponents.default)(_reactBootstrap.Button)`
  ${deleteCss}
`;
const DeletePlaceholder = _styledComponents.default.span`
  ${deleteCss}
`;
const MESSAGES = {
  DELETE: 'Delete this place',
  EDIT: 'Edit this place'
};
/**
 * Renders a clickable button for editing a user's favorite place,
 * and lets the user delete the place.
 */

const FavoritePlaceRow = ({
  isFixed,
  onDelete,
  path,
  place
}) => {
  if (place) {
    const {
      address,
      icon,
      name,
      type
    } = place;
    return /*#__PURE__*/_react.default.createElement(Container, null, /*#__PURE__*/_react.default.createElement(_connectedLinks.LinkContainerWithQuery, {
      to: path
    }, /*#__PURE__*/_react.default.createElement(PlaceButton, {
      "aria-label": MESSAGES.EDIT,
      title: MESSAGES.EDIT
    }, /*#__PURE__*/_react.default.createElement(GreyIcon, {
      name: icon,
      size: "2x"
    }), /*#__PURE__*/_react.default.createElement(PlaceContent, null, name && /*#__PURE__*/_react.default.createElement("span", null, name), /*#__PURE__*/_react.default.createElement("span", null, address || `Set your ${type} address`)))), !isFixed || address ? /*#__PURE__*/_react.default.createElement(DeleteButton, {
      "aria-label": MESSAGES.DELETE,
      onClick: onDelete,
      title: MESSAGES.DELETE
    }, /*#__PURE__*/_react.default.createElement(GreyIcon, {
      name: "trash-o",
      size: "2x"
    })) : /*#__PURE__*/_react.default.createElement(DeletePlaceholder, null));
  } else {
    // If no place is passed, render the Add place button instead.
    return /*#__PURE__*/_react.default.createElement(Container, null, /*#__PURE__*/_react.default.createElement(_connectedLinks.LinkContainerWithQuery, {
      to: path
    }, /*#__PURE__*/_react.default.createElement(PlaceButton, null, /*#__PURE__*/_react.default.createElement(GreyIcon, {
      name: "plus",
      size: "2x"
    }), "Add another place")), /*#__PURE__*/_react.default.createElement(DeletePlaceholder, null));
  }
};

FavoritePlaceRow.propTypes = {
  /** Whether the place is fixed (e.g. 'Home', 'Work' are fixed.) */
  isFixed: _propTypes.default.bool,

  /** Called when the delete button is clicked. */
  onDelete: _propTypes.default.func,

  /** The path to navigate to on click. */
  path: _propTypes.default.string.isRequired,

  /** The place to render. */
  place: _propTypes.default.shape({
    address: _propTypes.default.string,
    icon: _propTypes.default.string.isRequired,
    name: _propTypes.default.string,
    type: _propTypes.default.string.isRequired
  })
};
var _default = FavoritePlaceRow;
exports.default = _default;
module.exports = exports.default;

//# sourceMappingURL=favorite-place-row.js