import React from 'react';
import { connect } from 'redux-bundler-react';
import { SidebarButton } from '../../application-controls/index';
import PermalinkModal from './permalink-modal';

class PermalinkButton extends React.Component {
  constructor(props){
    super(props);
    this.handleClick = this.handleClick.bind(this);
  }

  handleClick(){
    const { doConstructPermalinkParams, doModalOpen } = this.props;
    doConstructPermalinkParams();
    doModalOpen( {
      children: [ PermalinkModal ],
      options: {}, 
      openedBy: 'Permalink'
    });
  }

  render() {
    return (
      <SidebarButton
        iconClass="ms ms-link"
        label="Show Permalink"
        title="Show Permalink"
        onClick={ this.handleClick }
      />
    );
  }
}

export default connect(
  'doConstructPermalinkParams',
  'doModalOpen',
  PermalinkButton
);
