"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ListItemInnerContainerClassNameSelector = exports.Item = void 0;
const react_1 = __importStar(require("react"));
const fnWithProps_1 = require("../../../types/fnWithProps");
const useRipple_1 = require("../../../utils/useRipple");
const Icon_1 = require("../../icons/Icon");
const Item_styled_1 = require("./Item.styled");
const Label_1 = require("./Label");
const Value_1 = require("./Value");
const icon = react_1.default.createElement(Item_styled_1.StyledIcon, { name: Icon_1.ICON.forward });
const noIcon = react_1.default.createElement(Item_styled_1.StyledNoIcon, null);
const ListItemInnerContainerClassNameSelector = Item_styled_1.StyledInnerContainer.toString();
exports.ListItemInnerContainerClassNameSelector = ListItemInnerContainerClassNameSelector;
const ItemBase = (0, react_1.forwardRef)((_a, ref) => {
    var _b, _c;
    var { href, to, onClick, Link, ratio } = _a, props = __rest(_a, ["href", "to", "onClick", "Link", "ratio"]);
    const innerRef = (0, react_1.useRef)(null);
    const ripple = (0, useRipple_1.useRipple)({ ref: innerRef });
    const r = ratio ? ratio.split("/") : [];
    const pre = typeof props.selected === "boolean"
        ? react_1.default.createElement(Label_1.Label, null, props.selected ? icon : noIcon)
        : null;
    const ren = !r.length
        ? props.children
        : (_b = react_1.default.Children.map(props.children, (child, index) => {
            var _a;
            if (!child || typeof child !== "object" || !("type" in child)) {
                return child;
            }
            const flex = (_a = r[index]) !== null && _a !== void 0 ? _a : undefined;
            if (flex === undefined) {
                return child;
            }
            return react_1.default.cloneElement(child, {
                style: { flex },
                css: { flex },
            });
        })) !== null && _b !== void 0 ? _b : [];
    const interactive = Boolean((_c = onClick !== null && onClick !== void 0 ? onClick : href) !== null && _c !== void 0 ? _c : to);
    const rippleProps = interactive
        ? { onPointerDown: ripple.onPointerDown, onKeyDown: ripple.onKeyDown }
        : {};
    if (to) {
        if (!Link) {
            throw new TypeError("`to` prop given without `Link` component");
        }
        return (react_1.default.createElement(Item_styled_1.StyledItem, Object.assign({}, props, { ref: ref }),
            react_1.default.createElement(Link, { href: to },
                react_1.default.createElement(Item_styled_1.StyledInnerContainer, Object.assign({ as: "a", href: to, ref: innerRef }, rippleProps),
                    pre,
                    ren,
                    ripple.ripples))));
    }
    if (href) {
        return (react_1.default.createElement(Item_styled_1.StyledItem, Object.assign({}, props, { ref: ref }),
            react_1.default.createElement(Item_styled_1.StyledInnerContainer, Object.assign({ as: "a", href: href, onClick: onClick, ref: innerRef }, rippleProps),
                pre,
                ren,
                ripple.ripples)));
    }
    if (onClick) {
        return (react_1.default.createElement(Item_styled_1.StyledItem, Object.assign({}, props, { ref: ref }),
            react_1.default.createElement(Item_styled_1.StyledInnerContainer, Object.assign({ as: "button", onClick: onClick, ref: innerRef }, rippleProps),
                pre,
                ren,
                ripple.ripples)));
    }
    return react_1.default.createElement(Item_styled_1.StyledItem, Object.assign({}, props, { ref: ref }),
        react_1.default.createElement(Item_styled_1.StyledInnerContainer, null,
            pre,
            ren));
});
ItemBase.displayName = "List.Item";
const Item = (0, fnWithProps_1.fnWithProps)(ItemBase, {
    Label: Label_1.Label,
    Value: Value_1.Value,
});
exports.Item = Item;
Item.toString = () => Item_styled_1.StyledItem.toString();
//# sourceMappingURL=Item.js.map