"use strict";
// The require scope
var __webpack_require__ = {};
/************************************************************************/ // webpack/runtime/compat_get_default_export
(()=>{
    // getDefaultExport function for compatibility with non-ESM modules
    __webpack_require__.n = function(module) {
        var getter = module && module.__esModule ? function() {
            return module['default'];
        } : function() {
            return module;
        };
        __webpack_require__.d(getter, {
            a: getter
        });
        return getter;
    };
})();
// webpack/runtime/define_property_getters
(()=>{
    __webpack_require__.d = function(exports1, definition) {
        for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
            enumerable: true,
            get: definition[key]
        });
    };
})();
// webpack/runtime/has_own_property
(()=>{
    __webpack_require__.o = function(obj, prop) {
        return Object.prototype.hasOwnProperty.call(obj, prop);
    };
})();
// webpack/runtime/make_namespace_object
(()=>{
    // define __esModule on exports
    __webpack_require__.r = function(exports1) {
        if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
            value: 'Module'
        });
        Object.defineProperty(exports1, '__esModule', {
            value: true
        });
    };
})();
/************************************************************************/ var __webpack_exports__ = {};
// ESM COMPAT FLAG
__webpack_require__.r(__webpack_exports__);
// EXPORTS
__webpack_require__.d(__webpack_exports__, {
    default: ()=>/* binding */ ResourceList_rslib_entry_
});
const external_react_namespaceObject = require("react");
var external_react_default = /*#__PURE__*/ __webpack_require__.n(external_react_namespaceObject);
const external_react_router_dom_namespaceObject = require("react-router-dom");
const react_namespaceObject = require("@chakra-ui/react");
const Section_js_namespaceObject = require("../Section/Section.js");
var Section_js_default = /*#__PURE__*/ __webpack_require__.n(Section_js_namespaceObject);
const colors_js_namespaceObject = require("../../styles/colors.js");
const Empty_js_namespaceObject = require("../Empty/Empty.js");
var Empty_js_default = /*#__PURE__*/ __webpack_require__.n(Empty_js_namespaceObject);
const md_namespaceObject = require("react-icons/md");
const ResourceListRowItem = ({ row, testId, templateColumns, columns, lastRow, alignSelf, content, isExpandable })=>{
    const borderColor = (0, react_namespaceObject.useColorModeValue)('gray.100', 'gray.700');
    const lastRowStyle = {
        borderRadius: '0 0 5px 5px'
    };
    const onClickStyle = {
        cursor: 'pointer'
    };
    const { isOpen, getButtonProps } = (0, react_namespaceObject.useDisclosure)();
    const buttonProps = getButtonProps();
    return /*#__PURE__*/ external_react_default().createElement(react_namespaceObject.Box, {
        "data-testid": testId,
        py: 3.5,
        px: 6,
        borderBottom: "1px solid",
        borderColor: borderColor,
        _last: lastRow ? lastRowStyle : {},
        style: row.onClick ? onClickStyle : {},
        ...buttonProps
    }, /*#__PURE__*/ external_react_default().createElement(react_namespaceObject.Grid, {
        templateColumns: templateColumns
    }, columns.map((column)=>{
        const thisRow = row;
        return /*#__PURE__*/ external_react_default().createElement(react_namespaceObject.Box, {
            key: column.key,
            justifyContent: column?.align,
            alignSelf: alignSelf
        }, thisRow[column.key]);
    }), isExpandable && /*#__PURE__*/ external_react_default().createElement(react_namespaceObject.Icon, {
        as: md_namespaceObject.MdKeyboardArrowUp,
        boxSize: 6,
        "data-testid": "content-chevron-icon",
        __css: {
            // Mirror the Accordion behavior
            transform: isOpen ? void 0 : 'rotate(-180deg)',
            transition: 'transform 0.2s',
            transformOrigin: 'center'
        }
    })), isExpandable ? /*#__PURE__*/ external_react_default().createElement(react_namespaceObject.Collapse, {
        in: isOpen,
        animateOpacity: true
    }, /*#__PURE__*/ external_react_default().createElement(react_namespaceObject.Box, {
        mt: 6,
        mb: 4,
        "data-testid": "content-wrapper"
    }, content)) : /*#__PURE__*/ external_react_default().createElement(react_namespaceObject.Box, {
        "data-testid": "content-wrapper"
    }, content));
};
function ResourceList({ testId, columns, rows, alignSelf, showColumns = true, isExpandable = false }) {
    const templateColumns = columns.map((item)=>`minmax(0, ${item.width || '1fr'})`).join(' ');
    const isAccordionResourceList = rows?.some(({ content })=>!!content);
    const gridTemplateColumns = isAccordionResourceList ? `${templateColumns} minmax(0, 0.1fr)` : templateColumns;
    const style = (0, react_namespaceObject.useColorModeValue)({
        sectionBorderColor: 'gray.200',
        borderColor: 'gray.100',
        background: 'gray.50',
        boxShadow: '0px 0px 1px 1px var(--chakra-colors-blackAlpha-200)'
    }, {
        sectionBorderColor: 'gray.700',
        borderColor: 'gray.700',
        background: 'gray.800',
        boxShadow: '0px 0px 1px 1px var(--chakra-colors-whiteAlpha-200)'
    });
    const selectStyle = {
        '> div': {
            position: 'relative',
            zIndex: 2,
            bg: 'gray.50',
            _dark: {
                bg: 'gray.800'
            }
        }
    };
    // Note: LinkBox defaultProps are not working in `./styles/components` so we must set outline color here
    const focusStyle = {
        ...selectStyle,
        outline: `${colors_js_namespaceObject.colors.focus["500"]} auto 2px !important`
    };
    return /*#__PURE__*/ external_react_default().createElement(Section_js_default(), {
        p: 0,
        border: "1px solid",
        borderColor: style.sectionBorderColor
    }, /*#__PURE__*/ external_react_default().createElement(react_namespaceObject.Stack, {
        spacing: "0px"
    }, showColumns && /*#__PURE__*/ external_react_default().createElement(react_namespaceObject.Box, {
        py: 2,
        px: 6,
        borderBottom: "1px solid",
        borderColor: style.sectionBorderColor,
        fontWeight: "600",
        background: style.background,
        fontSize: "sm",
        rounded: "lg",
        borderBottomRadius: "0"
    }, /*#__PURE__*/ external_react_default().createElement(react_namespaceObject.Grid, {
        templateColumns: gridTemplateColumns
    }, columns.map((header)=>/*#__PURE__*/ external_react_default().createElement(react_namespaceObject.Box, {
            "data-testid": `resource-list-column-${header.content}`,
            key: header.key,
            justifyContent: header.align,
            alignSelf: alignSelf || 'center'
        }, header.content)))), /*#__PURE__*/ external_react_default().createElement(react_namespaceObject.Stack, {
        spacing: "0px"
    }, 0 === rows.length && /*#__PURE__*/ external_react_default().createElement(Empty_js_default(), null), rows.map(({ key, link, content, ...row }, i)=>{
        // generate key if none is passed in
        key = key || `resourceListItem--${i}`;
        if (link || row.onClick) return /*#__PURE__*/ external_react_default().createElement(react_namespaceObject.LinkBox, {
            as: external_react_router_dom_namespaceObject.Link,
            key: key,
            to: link || '',
            "data-testid": `${key}-link`,
            _hover: selectStyle,
            _focus: focusStyle,
            onClick: (event)=>{
                if (row.onClick) {
                    event.preventDefault();
                    row.onClick(event);
                }
            }
        }, /*#__PURE__*/ external_react_default().createElement(ResourceListRowItem, {
            testId: testId,
            templateColumns: gridTemplateColumns,
            row: row,
            columns: columns,
            lastRow: i === rows.length - 1,
            alignSelf: alignSelf || 'center'
        }));
        return /*#__PURE__*/ external_react_default().createElement(ResourceListRowItem, {
            key: key,
            testId: testId,
            templateColumns: gridTemplateColumns,
            row: row,
            columns: columns,
            lastRow: i === rows.length - 1,
            alignSelf: alignSelf || 'center',
            isExpandable: isExpandable,
            content: content
        });
    }))));
}
/* ESM default export */ const ResourceList_rslib_entry_ = ResourceList;
var __webpack_export_target__ = exports;
for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
    value: true
});
