"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 });
exports.CnAiListEventContext = void 0;
exports.useCnAiListEventNames = useCnAiListEventNames;
exports.useCnAiListInstanceKey = useCnAiListInstanceKey;
exports.CnAiListEventProvider = CnAiListEventProvider;
const React = __importStar(require("react"));
const event_constants_1 = require("../constants/event-constants");
const defaultValue = {
    instanceKey: (0, event_constants_1.normalizeCnAiListInstanceKey)(undefined),
    eventNames: event_constants_1.EVENT_NAMES,
};
exports.CnAiListEventContext = React.createContext(defaultValue);
/**
 * 当前 AI 列表实例在 `@ice/stark-data` 总线上的事件频道名集合。
 * 须在由 `CnAiListEventProvider` 或根组件（CnAiTable / CnAiAgent / CnAiFilter）包裹的子树内使用；未包裹时与历史单实例行为一致。
 */
function useCnAiListEventNames() {
    return React.useContext(exports.CnAiListEventContext).eventNames;
}
/** 当前子树对应的事件实例 key（与 `id` 规范化后一致） */
function useCnAiListInstanceKey() {
    return React.useContext(exports.CnAiListEventContext).instanceKey;
}
/**
 * 为子树提供按 `instanceId` 隔离的事件频道；不传或空串时使用默认命名空间（兼容单实例）。
 */
function CnAiListEventProvider({ instanceId, children }) {
    const value = React.useMemo(() => {
        const instanceKey = (0, event_constants_1.normalizeCnAiListInstanceKey)(instanceId);
        return {
            instanceKey,
            eventNames: (0, event_constants_1.buildCnAiListEventNames)(instanceKey),
        };
    }, [instanceId]);
    return React.createElement(exports.CnAiListEventContext.Provider, { value: value }, children);
}
