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

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