"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;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = __importStar(require("react"));
const acui_1 = require("@Acme Corporation/acui");
const DashboardWidget = (0, react_1.memo)(({ title, subtitle, icon, actions = [], children, className = '', minHeight = '200px', maxHeight, loading = false, error = null, fullWidth = false, collapsible = false, defaultCollapsed = false, onClick, style = {}, footer, ariaLabel = 'Dashboard Widget', zIndex = 1050, status, statusMessage, role = 'region', tabIndex = 0 }) => {
    const theme = (0, acui_1.useTheme)();
    const [collapsed, setCollapsed] = react_1.default.useState(defaultCollapsed);
    const widgetId = react_1.default.useId();
    const handleCollapse = react_1.default.useCallback((e) => {
        e.stopPropagation();
        setCollapsed(prev => !prev);
    }, []);
    const widgetStyle = react_1.default.useMemo(() => ({
        minHeight: collapsed ? 'auto' : minHeight,
        maxHeight: collapsed ? 'auto' : maxHeight,
        cursor: onClick ? "pointer" : 'default',
        ...style
    }), [collapsed, minHeight, maxHeight, onClick, style]);
    const iconStyle = react_1.default.useMemo(() => ({
        backgroundColor: theme.colors.primaryLight,
        color: theme.colors.primary
    }), [theme.colors.primaryLight, theme.colors.primary]);
    const titleStyle = react_1.default.useMemo(() => ({
        color: theme.colors.textPrimary,
        fontSize: theme.typography.fontSize.large
    }), [theme.colors.textPrimary, theme.typography.fontSize.large]);
    const subtitleStyle = react_1.default.useMemo(() => ({
        color: theme.colors.textSecondary,
        fontSize: theme.typography.fontSize.small
    }), [theme.colors.textSecondary, theme.typography.fontSize.small]);
    const contentStyle = react_1.default.useMemo(() => ({
        padding: theme.spacing.medium
    }), [theme.spacing.medium]);
    const loadingStyle = react_1.default.useMemo(() => ({
        color: theme.colors.textSecondary
    }), [theme.colors.textSecondary]);
    const errorStyle = react_1.default.useMemo(() => ({
        color: theme.colors.error
    }), [theme.colors.error]);
    const handleKeyPress = (event) => {
        if (onClick && (event.key === 'Enter' || event.key === ' ')) {
            event.preventDefault();
            onClick();
        }
    };
    const renderStatus = () => {
        if (!status || !statusMessage)
            return null;
        return ((0, jsx_runtime_1.jsx)("div", { className: "bf-widget-status", role: "status", "aria-live": "polite", children: (0, jsx_runtime_1.jsx)(acui_1.Badge, { variant: status, children: statusMessage }) }));
    };
    const renderContent = () => {
        if (loading) {
            return ((0, jsx_runtime_1.jsxs)("div", { className: "bf-widget-loading", role: "status", "aria-label": "Loading widget content", children: [(0, jsx_runtime_1.jsx)("div", { className: "bf-spinner" }), (0, jsx_runtime_1.jsx)("p", { children: "Loading..." })] }));
        }
        if (error) {
            return ((0, jsx_runtime_1.jsxs)("div", { className: "bf-widget-error", role: "alert", "aria-live": "assertive", children: [(0, jsx_runtime_1.jsx)(acui_1.Icon, { name: "error" }), (0, jsx_runtime_1.jsx)("p", { children: error.message })] }));
        }
        return children;
    };
    return ((0, jsx_runtime_1.jsxs)(acui_1.Card, { id: widgetId, className: `bf-dashboard-widget ${className} ${fullWidth ? "bf-widget-full-width" : ""}`, style: widgetStyle, onClick: onClick, onKeyPress: handleKeyPress, "aria-label": ariaLabel, style: { zIndex }, role: role, tabIndex: onClick ? tabIndex : undefined, children: [(title || icon || actions.length > 0) && ((0, jsx_runtime_1.jsxs)("div", { className: "bf-widget-header", children: [(0, jsx_runtime_1.jsxs)("div", { className: "bf-widget-title-container", children: [icon && ((0, jsx_runtime_1.jsx)("div", { className: "bf-widget-icon", style: iconStyle, "aria-hidden": "true", children: icon })), (0, jsx_runtime_1.jsxs)("div", { children: [title && ((0, jsx_runtime_1.jsx)("h2", { className: "bf-widget-title", style: titleStyle, children: title })), subtitle && ((0, jsx_runtime_1.jsx)("p", { className: "bf-widget-subtitle", style: subtitleStyle, children: subtitle }))] })] }), (0, jsx_runtime_1.jsxs)("div", { className: "bf-widget-actions", role: "toolbar", "aria-label": "Widget actions", children: [actions.map((action, index) => ((0, jsx_runtime_1.jsx)("div", { className: "bf-widget-action", children: action }, index))), collapsible && ((0, jsx_runtime_1.jsx)(acui_1.Tooltip, { content: collapsed ? "Expand" : "Collapse", children: (0, jsx_runtime_1.jsx)(acui_1.Button, { variant: "icon", onClick: handleCollapse, "aria-label": collapsed ? "Expand" : "Collapse", children: (0, jsx_runtime_1.jsx)(acui_1.Icon, { name: collapsed ? "chevron-down" : "chevron-up" }) }) }))] })] })), !collapsed && ((0, jsx_runtime_1.jsxs)("div", { className: "bf-widget-content", style: contentStyle, children: [renderStatus(), renderContent()] })), footer && (0, jsx_runtime_1.jsx)("div", { className: "bf-widget-footer", children: footer })] }));
});
DashboardWidget.displayName = 'DashboardWidget';
exports.default = DashboardWidget;
//# sourceMappingURL=DashboardWidget.js.map