"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const getComponent_1 = require("../../getComponent");
const react_1 = tslib_1.__importDefault(require("react"));
const TouchableItem_1 = tslib_1.__importDefault(require("../HeaderBackButton/TouchableItem"));
/**
 * 🔗 Link
 */
class Link extends react_1.default.PureComponent {
    handlePress(event, navigation) {
        const { routeName, path, params, replace } = this.props;
        if (!event.defaultPrevented) {
            event.preventDefault();
            const fn = (replace === true) ? navigation.replace : navigation.push;
            if (typeof routeName === 'string') {
                fn(routeName, params);
            }
            else if (typeof path === 'string') {
                fn({ path }, params);
            }
        }
    }
    render() {
        const _a = this.props, { component: Component, routeName, path, params, onPress, replace } = _a, rest = tslib_1.__rest(_a, ["component", "routeName", "path", "params", "onPress", "replace"]);
        return Component ? (react_1.default.createElement(getComponent_1.NavigationActions, null, (navigation) => {
            const href = path ? path : '';
            const onPressDefault = (e) => this.handlePress(e, navigation);
            return (react_1.default.createElement(Component, Object.assign({}, rest, { href: href, onPress: onPress || onPressDefault })));
        })) : null;
    }
}
Link.defaultProps = {
    component: TouchableItem_1.default,
    replace: false,
};
exports.Link = Link;
