import React, { forwardRef } from "react";
import { omit } from "@ezez/utils";
import { Icon } from "../../icons/Icon.js";
import { Anchor, Badge, Button, StyledAction } from "./Action.styled.js";
const Action = forwardRef((props, ref) => {
    var _a;
    const { icon, label, css, ..._restProps } = props;
    const restProps = omit(_restProps, ["to", "Link", "href", "type"]);
    const maybeCss = css ? { css } : {};
    let iconElem = icon;
    if (typeof icon === "string") {
        iconElem = React.createElement(Icon, { name: icon });
    }
    const labelElem = label ? React.createElement("div", null, label) : null;
    const content = (React.createElement(React.Fragment, null,
        React.createElement(StyledAction, null,
            props.badge ? React.createElement(Badge, null, props.badge) : null,
            iconElem),
        labelElem));
    if ("to" in props) {
        if (!("Link" in props)) {
            throw new TypeError("`to` prop given without `Link` component");
        }
        return (React.createElement(props.Link, { href: props.to, ...restProps },
            React.createElement(Anchor, { ref: ref, className: props.className, ...maybeCss }, content)));
    }
    if ("href" in props) {
        return (React.createElement(Anchor, { ref: ref, href: props.href, className: props.className, ...restProps, ...maybeCss }, content));
    }
    return (React.createElement(Button, { ref: ref, onClick: props.onClick, className: props.className, ...maybeCss, type: (_a = props.type) !== null && _a !== void 0 ? _a : "button" }, content));
});
Action.displayName = "Action";
Action.toString = () => Button.toString();
const ActionCircleSelector = StyledAction.toString();
const ActionBadgeSelector = Badge.toString();
export { Action, ActionCircleSelector, ActionBadgeSelector };
//# sourceMappingURL=Action.js.map