import React from "react";
import { connect } from "redux-bundler-react";

const FavoritesToggle = (props) => {
  const { doToggleLayerFavoritesAdd, layer } = props;
  const btnTxt = layer.favorite
    ? "REMOVE FROM FAVORITE LAYERS"
    : "ADD TO FAVORITE LAYERS";
  if (!layer.id) {
    return null;
  } else {
    return (
      <div>
        <button
          onClick={() => {
            doToggleLayerFavoritesAdd(layer, !layer.favorite);
          }}
          type="button"
          className="cm-btn cm-btn-xs cm-btn-default"
          title={btnTxt}
        >
          {btnTxt}
        </button>
      </div>
    );
  }
};
export default connect("doToggleLayerFavoritesAdd", FavoritesToggle);
