import { __assign, __rest } from "tslib";
import { Breadcrumb, Icon } from '@alicloud/console-components';
import classnames from 'classnames';
import React from 'react';
;
function mapBreadcrumbItem(item, index, push) {
    var link = item.link, name = item.name, disabled = item.disabled, className = item.className, rest = __rest(item, ["link", "name", "disabled", "className"]);
    var className_ = className ? classnames(className, "lp-breadcrumb-item") : "lp-breadcrumb-item";
    if (push && typeof push === 'function') {
        return (React.createElement(Breadcrumb.Item, __assign({ key: index, className: className_, onClick: function () {
                link && push(link);
            } }, rest), name));
    }
    else {
        return (React.createElement(Breadcrumb.Item, __assign({ key: index, link: link, className: className_ }, rest), name));
    }
}
var IotBreadcrumb = function (props) {
    var hasLine = props.hasLine, className = props.className, dataSource = props.dataSource, extra = props.extra, push = props.push, children = props.children, rest = __rest(props, ["hasLine", "className", "dataSource", "extra", "push", "children"]);
    var wrapperClass = classnames('lp-breadcrumb', {
        'lp-breadcrumb-line': hasLine
    });
    var breadcrumbClass = classnames(className, {
        'lp-breadcrumb-single': dataSource && dataSource.length === 1
    });
    return (React.createElement("div", { className: wrapperClass, style: props.style },
        React.createElement(Breadcrumb, __assign({ className: breadcrumbClass }, rest), children ?
            React.Children.map(children, function (child) {
                var className_ = child.props.className ? classnames(child.props.className, "lp-breadcrumb-item") : "lp-breadcrumb-item";
                return React.cloneElement(child, {
                    className: className_
                });
            })
            :
                dataSource && dataSource.map(function (item, index) {
                    return mapBreadcrumbItem(item, index, push);
                })),
        extra));
};
IotBreadcrumb.defaultProps = {
    separator: React.createElement(Icon, { size: "xs", type: "arrow-right" })
};
IotBreadcrumb.Item = Breadcrumb.Item;
export default IotBreadcrumb;
