"use strict";
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;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ListItem = exports.ListItemBase = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("react");
const core_1 = require("../core");
const link_1 = __importDefault(require("../link"));
const utils_1 = require("../utils");
const context_1 = require("./context");
const listIcon_1 = __importDefault(require("./listIcon"));
const listText_1 = __importDefault(require("./listText"));
/** Used as optional content wrapper when list item should be a link. */
const ListItemLink = (0, core_1.vui)((props, ref) => ((0, jsx_runtime_1.jsx)(link_1.default, Object.assign({ borderRadius: "none", className: "vui-listItemLink", h: "100%", px: 2, ref: ref, variant: "plain", w: "100%" }, props))));
/*@formatter:off*/
exports.ListItemBase = core_1.styled.liBox `
  display: flex;
  line-height: normal;
  outline: none;
  transition-duration: fast;

  &[aria-disabled='true'] {
    cursor: not-allowed;
    user-select: none;
    opacity: 0.5;
  }

  &:focus-visible {
    z-index: 1;
  }
`;
/*@formatter:on*/
/**
 * Displays a list item with text and optional icons. Can be shown as interactive or selected.
 * Optionally wraps the content with an <a> element when rendering a link.
 */
exports.ListItem = (0, core_1.vui)((props, ref) => {
    const mergedProps = Object.assign(Object.assign({}, (0, context_1.useListContext)()), props);
    const { children, center, centerH, centerV = true, className, column, disabled, iconLeft, iconRight, isInteractive: isInteractiveProp, isSelected, isTruncated, itemLeft, itemRight, linkProps, onClick, text } = mergedProps, rest = __rest(mergedProps, ["children", "center", "centerH", "centerV", "className", "column", "disabled", "iconLeft", "iconRight", "isInteractive", "isSelected", "isTruncated", "itemLeft", "itemRight", "linkProps", "onClick", "text"]);
    const styles = (0, core_1.useStyleConfig)('List', (0, context_1.useListContext)());
    const _a = styles.item, { activeBg, hoverBg, selectedBg } = _a, itemStyles = __rest(_a, ["activeBg", "hoverBg", "selectedBg"]);
    const isLinkItem = linkProps !== undefined;
    const isInteractive = isInteractiveProp || isLinkItem || onClick !== undefined;
    const alignItems = (center || (column ? centerH : centerV)) && 'center';
    const flexDirection = column && 'column';
    const justifyContent = (center || (column ? centerV : centerH)) && 'center';
    const ContentWrapper = isLinkItem ? ListItemLink : react_1.Fragment;
    const interactiveProps = !disabled && isInteractive
        ? {
            cursor: 'pointer',
            focusVisibleRing: 2,
            hoverBg,
            activeBg,
            tabIndex: !isLinkItem ? 0 : undefined,
            userSelect: 'none',
        }
        : {};
    const aliasedProps = (0, utils_1.filterUndefined)({
        alignItems,
        bg: isSelected ? selectedBg : undefined,
        'aria-disabled': disabled,
        flexDirection,
        justifyContent,
        px: isLinkItem ? 0 : undefined,
    });
    return ((0, jsx_runtime_1.jsx)(exports.ListItemBase, Object.assign({ bg: disabled ? rest.disabledBg || 'sandstone.95' : undefined, className: (0, utils_1.cs)('vui-listItem', className), onClick: !disabled ? onClick : undefined, ref: ref }, itemStyles, interactiveProps, aliasedProps, rest, { children: (0, jsx_runtime_1.jsxs)(ContentWrapper, Object.assign({}, linkProps, { children: [itemLeft, (0, utils_1.isString)(iconLeft) ? (0, jsx_runtime_1.jsx)(listIcon_1.default, { mr: 1, name: iconLeft }) : iconLeft, children !== null && children !== void 0 ? children : ((0, utils_1.isReactText)(text) ? (0, jsx_runtime_1.jsx)(listText_1.default, { isTruncated, text }) : text), (0, utils_1.isString)(iconRight) ? (0, jsx_runtime_1.jsx)(listIcon_1.default, { ml: "auto", name: iconRight }) : iconRight, itemRight] })) })));
});
exports.ListItem.displayName = 'ListItem';
exports.default = exports.ListItem;
//# sourceMappingURL=listItem.js.map