import copy from 'copy-to-clipboard';
import ContentCopyIcon from 'mdi-react/ContentCopyIcon';
import * as React from 'react';
import { Tooltip } from '../../components/tooltip/Tooltip';
import { eventLogger } from '../../tracking/eventLogger';
/**
 * A repository header action that copies the current page's URL to the clipboard.
 */
export class CopyLinkAction extends React.PureComponent {
    constructor() {
        super(...arguments);
        this.state = { copied: false };
        this.onClick = event => {
            event.preventDefault();
            eventLogger.log('ShareButtonClicked');
            const loc = this.props.location;
            const shareLink = new URL(loc.pathname + loc.search + loc.hash, window.location.href);
            shareLink.searchParams.set('utm_source', 'share');
            copy(shareLink.href);
            this.setState({ copied: true });
            setTimeout(() => {
                this.setState({ copied: false });
            }, 1000);
        };
    }
    componentDidUpdate(prevProps, prevState) {
        if (prevState.copied !== this.state.copied) {
            Tooltip.forceUpdate();
        }
    }
    render() {
        return (React.createElement("button", { className: "copy-link-action btn btn-link btn-link-sm", "data-tooltip": this.state.copied ? 'Copied!' : 'Copy link to clipboard', onClick: this.onClick },
            React.createElement(ContentCopyIcon, { className: "icon-inline" })));
    }
}
//# sourceMappingURL=CopyLinkAction.js.map