import * as tslib_1 from "tslib";
import React, { Component, PropTypes } from "react";
import { EVENTS, Router } from "../Router";
export class Link extends Component {
    constructor() {
        super(...arguments);
        this.listener = () => {
            this.setState({});
        };
    }
    render() {
        const props = tslib_1.__assign({}, this.props);
        delete props.to;
        delete props.params;
        delete props.query;
        const url = this.context.router.buildUrl(this.props.to, this.props.params, this.props.query);
        const navigate = (e) => {
            e.preventDefault();
            this.context.router.navigate(this.props.to, this.props.params, this.props.query);
        };
        return (<a href={url} onClick={navigate} {...props}>
				{this.props.children}
			</a>);
    }
    /**
     * @returns {null}
     */
    componentDidMount() {
        this.context.router.subscribe(EVENTS.ROUTE_MATCHED, this.listener);
        return null;
    }
    /**
     * @returns {null}
     */
    componentWillUnmount() {
        this.context.router.unsubscribe(EVENTS.ROUTE_MATCHED, this.listener);
        return null;
    }
}
/**
 * @type {{router: React.Requireable<any>}}
 */
Link.contextTypes = { router: PropTypes.instanceOf(Router) };
