'use strict';

var tslib_es6 = require('./tslib.es6-cjs.js');
var React = require('react');
var Button = require('./Button-cjs.js');
var useRenderElement = require('./useRenderElement-cjs.js');

function assignRef(ref, instance) {
    if (!ref) {
        return;
    }
    if (typeof ref === "function") {
        ref(instance);
        return;
    }
    ref.current = instance;
}
function mergeRefs(...refs) {
    return (instance) => {
        refs.forEach(ref => {
            assignRef(ref, instance);
        });
    };
}
function getElementRef(element) {
    return element.ref;
}
function normalizeBaseUiButtonProps(props) {
    const rest = tslib_es6.__rest(props, ["type"]);
    return rest;
}
function isAtlantisButtonRenderTarget(element) {
    return React.isValidElement(element) && element.type === Button.Button;
}
function renderAtlantisButtonTarget(element) {
    return function renderButtonTarget(props) {
        const mergedProps = useRenderElement.mergeProps(normalizeBaseUiButtonProps(props), element.props);
        return (React.createElement(Button.Button, Object.assign({}, mergedProps, { ref: mergeRefs(props.ref, getElementRef(element)), key: element.key })));
    };
}
function stripNativeTypeFromButtonRenderTarget(element) {
    const nativeType = element.props.type;
    if (nativeType !== "button" &&
        nativeType !== "submit" &&
        nativeType !== "reset") {
        return element;
    }
    return React.cloneElement(element, {
        type: undefined,
    });
}

exports.isAtlantisButtonRenderTarget = isAtlantisButtonRenderTarget;
exports.normalizeBaseUiButtonProps = normalizeBaseUiButtonProps;
exports.renderAtlantisButtonTarget = renderAtlantisButtonTarget;
exports.stripNativeTypeFromButtonRenderTarget = stripNativeTypeFromButtonRenderTarget;
