/**
 * Interaction Tools Registrations
 *
 * Registers tools for interacting with question content:
 * - Answer Eliminator (strike through answer choices)
 * - Highlighter (highlight text passages)
 *
 * Maps to QTI 3.0 standard access features:
 * - answerMasking (assessment tool)
 * - strikethrough (visual transformation)
 * - highlighting (cognitive/reading support)
 */
import { hasChoiceInteraction, hasReadableText, } from "../../services/tool-context.js";
import { createToolElement, } from "../tool-tag-map.js";
import { createScopedVisibilityBinding, syncButtonAndOverlayVisibility, } from "./toolbar-registration-helpers.js";
/**
 * Answer Eliminator tool registration
 *
 * Allows students to strike through incorrect answer choices.
 * Only appears on multiple-choice style questions.
 */
export const answerEliminatorToolRegistration = {
    toolId: "answerEliminator",
    name: "Answer Eliminator",
    description: "Strike through answer choices",
    icon: "strikethrough",
    // Answer eliminator appears at item level only
    supportedLevels: ["item"],
    // PNP support IDs
    // Maps to QTI 3.0 standard feature: answerMasking
    pnpSupportIds: [
        "answerMasking", // QTI 3.0 standard (assessment.answerMasking)
        "answerEliminator", // QTI 3.0 standard (assessment.answerEliminator)
        "strikethrough", // Common variant
        "choiceMasking", // Common variant
    ],
    /**
     * Pass 2: Answer eliminator is relevant only for choice-based questions
     */
    isVisibleInContext(context) {
        return hasChoiceInteraction(context);
    },
    renderToolbar(context, toolbarContext) {
        const visibility = createScopedVisibilityBinding(this.toolId, toolbarContext);
        const componentOverrides = toolbarContext.componentOverrides ?? {};
        const overlay = createToolElement(this.toolId, context, toolbarContext, componentOverrides);
        overlay.setAttribute("tool-id", visibility.fullToolId);
        overlay.setAttribute("strategy", "strikethrough");
        overlay.setAttribute("button-alignment", "inline");
        const button = {
            toolId: this.toolId,
            label: this.name,
            icon: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="20" height="20" fill="currentColor" aria-hidden="true"><path d="M19,3H16.3H7.7H5A2,2 0 0,0 3,5V7.7V16.4V19A2,2 0 0,0 5,21H7.7H16.4H19A2,2 0 0,0 21,19V16.3V7.7V5A2,2 0 0,0 19,3M15.6,17L12,13.4L8.4,17L7,15.6L10.6,12L7,8.4L8.4,7L12,10.6L15.6,7L17,8.4L13.4,12L17,15.6L15.6,17Z"/></svg>',
            disabled: false,
            ariaLabel: "Answer eliminator - Strike through choices",
            tooltip: "Strike Through",
            onClick: () => toolbarContext.toggleTool(this.toolId),
            active: visibility.isActive(),
        };
        return {
            toolId: this.toolId,
            button,
            elements: [{ element: overlay, mount: "after-buttons" }],
            sync: () => {
                syncButtonAndOverlayVisibility({
                    button,
                    overlay,
                    isActive: visibility.isActive,
                });
                if (toolbarContext.toolCoordinator) {
                    overlay.coordinator = toolbarContext.toolCoordinator;
                }
                overlay.scopeElement = toolbarContext.getScopeElement?.() || null;
                if (toolbarContext.elementToolStateStore) {
                    overlay.elementToolStateStore = toolbarContext.elementToolStateStore;
                }
                const globalElementId = toolbarContext.getGlobalElementId?.();
                if (globalElementId) {
                    overlay.globalElementId = globalElementId;
                }
            },
            subscribeActive: visibility.subscribeActive,
        };
    },
};
/**
 * Highlighter tool registration
 *
 * Allows students to highlight text in passages and questions.
 * Appears on items with readable text content.
 */
export const highlighterToolRegistration = {
    toolId: "highlighter",
    name: "Highlighter",
    description: "Highlight text",
    icon: "highlighter",
    activation: "toolbar-toggle",
    // Highlighter appears at passage, rubric, item, and element levels
    supportedLevels: ["passage", "rubric", "item", "element"],
    // PNP support IDs
    pnpSupportIds: ["highlighter", "textHighlight", "annotation"],
    /**
     * Pass 2: Highlighter is relevant when readable text is available
     */
    isVisibleInContext(context) {
        return hasReadableText(context);
    },
    renderToolbar(context, toolbarContext) {
        const visibility = createScopedVisibilityBinding(this.toolId, toolbarContext);
        const button = {
            toolId: this.toolId,
            label: this.name,
            icon: typeof this.icon === "function" ? this.icon(context) : this.icon,
            disabled: false,
            ariaLabel: "Highlighter - Highlight text",
            tooltip: "Highlight",
            onClick: () => toolbarContext.toggleTool(this.toolId),
            active: visibility.isActive(),
        };
        const componentOverrides = toolbarContext.componentOverrides ?? {};
        const overlay = createToolElement(this.toolId, context, toolbarContext, componentOverrides);
        overlay.setAttribute("tool-id", visibility.fullToolId);
        return {
            toolId: this.toolId,
            button,
            elements: [{ element: overlay, mount: "after-buttons" }],
            sync: () => {
                syncButtonAndOverlayVisibility({
                    button,
                    overlay,
                    isActive: visibility.isActive,
                    onActiveChange: (active) => {
                        overlay.enabled = active;
                    },
                });
                if (toolbarContext.ttsService) {
                    overlay.ttsService = toolbarContext.ttsService;
                }
            },
            subscribeActive: visibility.subscribeActive,
        };
    },
};
//# sourceMappingURL=interaction-tools.js.map