'use client';
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
import * as React from 'react';
// Inner component that actually calls action.render() — errors thrown here
// are caught by the surrounding ActionErrorBoundary class component.
function ActionRenderer({ action, ctx }) {
    return _jsx(_Fragment, { children: action.render(ctx) });
}
class ActionErrorBoundary extends React.Component {
    constructor() {
        super(...arguments);
        this.state = { hasError: false };
    }
    static getDerivedStateFromError() { return { hasError: true }; }
    componentDidCatch(err) {
        if (typeof console !== 'undefined')
            console.warn('field_action_render_failed', this.props.action.id, err);
    }
    render() {
        if (this.state.hasError)
            return null;
        return _jsx(ActionRenderer, { action: this.props.action, ctx: this.props.ctx });
    }
}
export function FieldActionArraySlot({ actions, position, ctx }) {
    const filtered = React.useMemo(() => (actions
        .filter(a => a.position === position && (a.when?.(ctx) ?? true))
        .sort((a, b) => (a.order ?? 100) - (b.order ?? 100))), [actions, position, ctx.field.id, ctx.value, ctx.mode, ctx.section_id, ctx.group_id]);
    if (filtered.length === 0)
        return null;
    return (_jsx(_Fragment, { children: filtered.map(a => (_jsx(ActionErrorBoundary, { action: a, ctx: ctx }, a.id))) }));
}
//# sourceMappingURL=field_action_array_slot.js.map