/**
 * use_field_action_slot - Hook that resolves per-field action slots for a
 * `HazoCollabForm*` component.
 *
 * Returns `{ row_end, row_below }` — two JSX elements (each possibly null)
 * ready to drop into the row. Components with a custom layout (checkbox,
 * radio, doc) call this directly; `BaseFieldLayout` calls it on behalf of
 * every component that uses it.
 *
 * Resolution order (v5.10+):
 *   1. If `field_actions` is non-empty in context → use `FieldActionArraySlot`
 *      for both positions (new composable path).
 *   2. Otherwise fall back to the legacy `FieldActionSlot` / `field_action_components`
 *      path (5.9.x parity).
 *
 * The hook silently yields null entries when:
 *
 *   - the consuming app renders the component outside HazoCollabFormView
 *     (no FormViewContext) — keeps backward compatibility with non-view callers
 *     and other one-off usages, and
 *   - neither `field_actions` nor `field_action_components` is set.
 */
'use client';
import { jsx as _jsx } from "react/jsx-runtime";
import { FieldActionSlot } from './field_action_slot.js';
import { FieldActionArraySlot } from './field_action_array_slot.js';
import { useFormViewContextOptional } from '../hazo_collab_form_view/context.js';
const NULL_SLOTS = { row_end: null, row_below: null };
/**
 * @param effective_field_id The id used for form_data / metadata lookups in
 *   the consuming component — typically `field_data_id || field_id_final`.
 *   For additional entries the `:N` suffix is stripped so the lookup hits
 *   the parent field's config.
 */
export function use_field_action_slot(effective_field_id) {
    const view_ctx = useFormViewContextOptional();
    if (!view_ctx)
        return NULL_SLOTS;
    const base_field_id = effective_field_id.includes(':')
        ? effective_field_id.split(':')[0]
        : effective_field_id;
    const lookup = view_ctx.field_lookup?.get(base_field_id);
    if (!lookup)
        return NULL_SLOTS;
    const merged_actions = view_ctx.field_actions ?? [];
    const action_ctx = {
        field: lookup.field,
        value: view_ctx.form_data?.[effective_field_id],
        mode: view_ctx.mode,
        section_id: lookup.section_id,
        group_id: lookup.group_id,
    };
    if (merged_actions.length > 0) {
        return {
            row_end: (_jsx(FieldActionArraySlot, { actions: merged_actions, position: "row_end", ctx: action_ctx })),
            row_below: (_jsx(FieldActionArraySlot, { actions: merged_actions, position: "row_below", ctx: action_ctx })),
        };
    }
    // Legacy path: field_action_components
    const common = {
        components: view_ctx.field_action_components,
        field: lookup.field,
        value: view_ctx.form_data?.[effective_field_id],
        mode: view_ctx.mode,
        section_id: lookup.section_id,
        group_id: lookup.group_id,
    };
    return {
        row_end: view_ctx.field_action_components
            ? _jsx(FieldActionSlot, { ...common, slot: "row_end" })
            : null,
        row_below: view_ctx.field_action_components?.row_below
            ? _jsx(FieldActionSlot, { ...common, slot: "row_below" })
            : null,
    };
}
//# sourceMappingURL=use_field_action_slot.js.map