# SelectionAiPanel

- File ID: file:1ez5kuw:selectionaipanel-razor
- Path: NexusReader.UI.Shared/Components/Molecules/SelectionAiPanel.razor
- Role: ui-component
- Layer: frontend

## Purpose

Blazor UI component that shows an AI assistant panel for a user text selection, requests summaries/quizzes via an injected KnowledgeCoordinator, and notifies the reader interaction service when closed.

## Key Details

Razor component renders conditional UI based on SelectedText and Coordinates; it orchestrates async calls to an injected KnowledgeCoordinator to get AI-derived content and uses IReaderInteractionService to clear/propagate selection state. UI event handlers map directly to async methods that manage loading state and packet caching.

## Symbols

- SelectionAiPanel: Blazor UI component that shows an AI assistant panel for a user text selection, requests summaries/quizzes via an injected KnowledgeCoordinator, and notifies the reader interaction service when closed.
- IsVisible(): Computed property indicating if the selection panel should be shown (non-empty SelectedText and Coordinates present).
- PositionBelow(): Determines whether the panel should be positioned below the selection based on Coordinates.Top.
- OnParametersSet(): Lifecycle method called when component parameters change; logs state and resets the cached KnowledgePacket.
- PanelStyle(): Builds inline CSS positioning string for the panel using Coordinates and PositionBelow; returns empty string when Coordinates is null.
- RequestSummary(): Orchestrates an async request to the KnowledgeCoordinator to produce a summary/quiz for the selected text (optionally including full page context) and stores the resulting KnowledgePacket.
- GenerateFullQuiz(): Requests a summary/quiz for the entire page content, then closes the panel.
- CloseAsync(): Clears the cached packet and notifies the reader interaction service that selection has been cleared, effectively closing the panel.

## Dependencies

- imports NexusReader.UI.Shared/Services/KnowledgeCoordinator.cs
- imports NexusReader.UI.Shared/Services/IReaderInteractionService.cs
- imports NexusReader.Application/DTOs/AI/KnowledgePacket.cs

## Calls

- calls NexusReader.UI.Shared/Services/KnowledgeCoordinator.cs
- calls NexusReader.UI.Shared/Services/KnowledgeCoordinator.cs
- calls NexusReader.UI.Shared/Services/IReaderInteractionService.cs

## Unresolved References

- dependency-target: NexusReader.UI.Shared/Models/SelectionCoordinates.cs
- call-target: self
- interaction-target: Awaits Coordinator.RequestSummaryAndQuizAsync(...)
- interaction-target: Awaits Coordinator.RequestSummaryAndQuizAsync(FullPageContent)
- interaction-target: Awaits InteractionService.NotifyTextSelected(string.Empty, string.Empty, null!) to clear selection globally

## Coverage

- Symbols: 8
- Executable symbols: 7
- Executable symbols with control flow: 7
- Grounded edges: 14
- Unresolved references: 5
- Control-flow fragments: 7
- Unresolved jumps: 0
- Unsupported constructs: 0
- Control-flow coverage: 100%
- Required diagrams: 2
- Generated diagrams: 4

## Control Flow Fragments

- IsVisible: 6 nodes, 6 edges, 0 jumps, 0 unsupported constructs
- PositionBelow: 6 nodes, 6 edges, 0 jumps, 0 unsupported constructs
- OnParametersSet: 4 nodes, 3 edges, 0 jumps, 0 unsupported constructs
- PanelStyle: 7 nodes, 7 edges, 0 jumps, 0 unsupported constructs
- RequestSummary: 16 nodes, 17 edges, 1 jumps, 0 unsupported constructs
- GenerateFullQuiz: 11 nodes, 10 edges, 2 jumps, 0 unsupported constructs
- CloseAsync: 8 nodes, 7 edges, 1 jumps, 0 unsupported constructs

## Diagrams

### SelectionAiPanel Neighborhood

_Warnings: diagram file_1ez5kuw_selectionaipanel_razor_neighborhood_view exceeds preferred complexity thresholds (14 nodes, 6 edges)._

```mermaid
---
config:
  flowchart:
    defaultRenderer: "elk"
---
flowchart LR
    class_5wh0z0_selectionaipanel("SelectionAiPanel")
    file_1ez5kuw_selectionaipanel_razor("SelectionAiPanel")
    method_1bkauax_generatefullquiz[["GenerateFullQuiz()"]]
    method_1g73g8y_positionbelow[["PositionBelow()"]]
    method_1kikefa_isvisible[["IsVisible()"]]
    method_1oq28g8_requestsummary[["RequestSummary()"]]
    method_1pecu6b_closeasync[["CloseAsync()"]]
    method_8m5lws_panelstyle[["PanelStyle()"]]
    method_ilkln5_onparametersset[["OnParametersSet()"]]
    file_1szg1zb_ireaderinteractionservice_cs[/"IReaderInteractionService"/]
    file_hjtala_knowledgepacket_cs[/"KnowledgePacket"/]
    file_uvydt4_knowledgecoordinator_cs[/"KnowledgeCoordinator"/]
    method_2y4xzb_requestsummaryandquizasync[/"KnowledgeCoordinator"/]
    method_p2mw02_notifytextselected[/"IReaderInteractionService"/]
    file_1ez5kuw_selectionaipanel_razor -->|IReaderInteractionService| file_1szg1zb_ireaderinteractionservice_cs
    file_1ez5kuw_selectionaipanel_razor -->|KnowledgePacket| file_hjtala_knowledgepacket_cs
    file_1ez5kuw_selectionaipanel_razor -->|KnowledgeCoordinator| file_uvydt4_knowledgecoordinator_cs
    method_1bkauax_generatefullquiz -->|KnowledgeCoordinator| method_2y4xzb_requestsummaryandquizasync
    method_1oq28g8_requestsummary -->|KnowledgeCoordinator| method_2y4xzb_requestsummaryandquizasync
    method_1pecu6b_closeasync -->|IReaderInteractionService| method_p2mw02_notifytextselected
```

### SelectionAiPanel Execution Overview

```mermaid
flowchart TD
    class_5wh0z0_selectionaipanel("SelectionAiPanel")
    method_1bkauax_generatefullquiz[["GenerateFullQuiz()"]]
    method_1g73g8y_positionbelow[["PositionBelow()"]]
    method_1kikefa_isvisible[["IsVisible()"]]
    method_1oq28g8_requestsummary[["RequestSummary()"]]
    method_1pecu6b_closeasync[["CloseAsync()"]]
    method_8m5lws_panelstyle[["PanelStyle()"]]
    method_ilkln5_onparametersset[["OnParametersSet()"]]
    method_2y4xzb_requestsummaryandquizasync[/"KnowledgeCoordinator"/]
    method_p2mw02_notifytextselected[/"IReaderInteractionService"/]
    unresolved_unresolved_1wlc2qr_interaction_target{"Unresolved: Awaits InteractionService.NotifyTextSelected(string.Empty, string.Empty, null!) to clear selection globally"}
    unresolved_unresolved_bj4qwl_interaction_target{"Unresolved: Awaits Coordinator.RequestSummaryAndQuizAsync(FullPageContent)"}
    unresolved_unresolved_ie7r18_call_target{"Unresolved: CloseAsync"}
    unresolved_unresolved_zyw832_interaction_target{"Unresolved: Awaits Coordinator.RequestSummaryAndQuizAsync(...)"}
    class_5wh0z0_selectionaipanel -->|contains| method_1bkauax_generatefullquiz
    class_5wh0z0_selectionaipanel -->|contains| method_1g73g8y_positionbelow
    class_5wh0z0_selectionaipanel -->|contains| method_1kikefa_isvisible
    class_5wh0z0_selectionaipanel -->|contains| method_1oq28g8_requestsummary
    class_5wh0z0_selectionaipanel -->|contains| method_1pecu6b_closeasync
    class_5wh0z0_selectionaipanel -->|contains| method_8m5lws_panelstyle
    class_5wh0z0_selectionaipanel -->|contains| method_ilkln5_onparametersset
    class_5wh0z0_selectionaipanel -->|unresolved interaction| unresolved_unresolved_1wlc2qr_interaction_target
    class_5wh0z0_selectionaipanel -->|unresolved interaction| unresolved_unresolved_bj4qwl_interaction_target
    class_5wh0z0_selectionaipanel -->|unresolved interaction| unresolved_unresolved_zyw832_interaction_target
    method_1bkauax_generatefullquiz -->|KnowledgeCoordinator| method_2y4xzb_requestsummaryandquizasync
    method_1bkauax_generatefullquiz -->|unresolved call| unresolved_unresolved_ie7r18_call_target
    method_1oq28g8_requestsummary -->|KnowledgeCoordinator| method_2y4xzb_requestsummaryandquizasync
    method_1pecu6b_closeasync -->|IReaderInteractionService| method_p2mw02_notifytextselected
```

### SelectionAiPanel Method Interactions

```mermaid
flowchart LR
    method_1bkauax_generatefullquiz[["GenerateFullQuiz()"]]
    method_1g73g8y_positionbelow[["PositionBelow()"]]
    method_1kikefa_isvisible[["IsVisible()"]]
    method_1oq28g8_requestsummary[["RequestSummary()"]]
    method_1pecu6b_closeasync[["CloseAsync()"]]
    method_8m5lws_panelstyle[["PanelStyle()"]]
    method_ilkln5_onparametersset[["OnParametersSet()"]]
    method_2y4xzb_requestsummaryandquizasync("KnowledgeCoordinator")
    method_p2mw02_notifytextselected("IReaderInteractionService")
    method_1bkauax_generatefullquiz -->|KnowledgeCoordinator| method_2y4xzb_requestsummaryandquizasync
    method_1oq28g8_requestsummary -->|KnowledgeCoordinator| method_2y4xzb_requestsummaryandquizasync
    method_1pecu6b_closeasync -->|IReaderInteractionService| method_p2mw02_notifytextselected
```

### RequestSummary() Control Flow

```mermaid
flowchart TD
    method_1oq28g8_requestsummary__call_83_RequestSummaryAndQuizAsync[["RequestSummaryAndQuizAsync"]]
    method_1oq28g8_requestsummary__action_41_ui_action_binding_41__linear("Invoked from button")
    method_1oq28g8_requestsummary__action_78_state_mutation_78__linear("Set loading start")
    method_1oq28g8_requestsummary__action_79_branch_79__condition{"!string.IsNullOrWhiteSpace(FullPageContent)"}
    method_1oq28g8_requestsummary__action_79_branch_79__false("no extra context")
    method_1oq28g8_requestsummary__action_79_branch_79__merge("merge")
    method_1oq28g8_requestsummary__action_79_branch_79__true("include full page context")
    method_1oq28g8_requestsummary__action_83_requestsummary_await_83_0__await[["Waits for async work"]]
    method_1oq28g8_requestsummary__action_84_fallback_84__condition{"result.IsSuccess"}
    method_1oq28g8_requestsummary__action_84_fallback_84__false("Packet cleared")
    method_1oq28g8_requestsummary__action_84_fallback_84__merge("merge")
    method_1oq28g8_requestsummary__action_84_fallback_84__true("Packet assigned")
    method_1oq28g8_requestsummary__action_85_state_mutation_85__linear("Set loading end")
    method_1oq28g8_requestsummary__entry(["RequestSummary entry"])
    method_1oq28g8_requestsummary__action_83_external_call_83__linear("Coordinator request")
    method_1oq28g8_requestsummary__implicit_return(["return"])
    method_1oq28g8_requestsummary__action_41_ui_action_binding_41__linear -->|next| method_1oq28g8_requestsummary__action_78_state_mutation_78__linear
    method_1oq28g8_requestsummary__action_78_state_mutation_78__linear -->|next| method_1oq28g8_requestsummary__action_79_branch_79__condition
    method_1oq28g8_requestsummary__action_79_branch_79__condition -->|no extra context| method_1oq28g8_requestsummary__action_79_branch_79__false
    method_1oq28g8_requestsummary__action_79_branch_79__condition -->|include full page context| method_1oq28g8_requestsummary__action_79_branch_79__true
    method_1oq28g8_requestsummary__action_79_branch_79__false -->|next| method_1oq28g8_requestsummary__action_79_branch_79__merge
    method_1oq28g8_requestsummary__action_79_branch_79__merge -->|next| method_1oq28g8_requestsummary__action_83_requestsummary_await_83_0__await
    method_1oq28g8_requestsummary__action_79_branch_79__true -->|next| method_1oq28g8_requestsummary__action_79_branch_79__merge
    method_1oq28g8_requestsummary__action_83_external_call_83__linear -->|string: contextPrompt + SelectedText includes FullPageContent if not empty| method_1oq28g8_requestsummary__call_83_RequestSummaryAndQuizAsync
    method_1oq28g8_requestsummary__action_83_requestsummary_await_83_0__await -->|next| method_1oq28g8_requestsummary__action_83_external_call_83__linear
    method_1oq28g8_requestsummary__action_84_fallback_84__condition -->|Packet cleared| method_1oq28g8_requestsummary__action_84_fallback_84__false
    method_1oq28g8_requestsummary__action_84_fallback_84__condition -->|Packet assigned| method_1oq28g8_requestsummary__action_84_fallback_84__true
    method_1oq28g8_requestsummary__action_84_fallback_84__false -->|next| method_1oq28g8_requestsummary__action_84_fallback_84__merge
    method_1oq28g8_requestsummary__action_84_fallback_84__merge -->|next| method_1oq28g8_requestsummary__action_85_state_mutation_85__linear
    method_1oq28g8_requestsummary__action_84_fallback_84__true -->|next| method_1oq28g8_requestsummary__action_84_fallback_84__merge
    method_1oq28g8_requestsummary__action_85_state_mutation_85__linear -->|return| method_1oq28g8_requestsummary__implicit_return
    method_1oq28g8_requestsummary__call_83_RequestSummaryAndQuizAsync -->|fallback| method_1oq28g8_requestsummary__action_84_fallback_84__condition
    method_1oq28g8_requestsummary__entry -->|next| method_1oq28g8_requestsummary__action_41_ui_action_binding_41__linear
```

## Diagram Validation

- Status: warn
- Warning: neighborhood-view: diagram file_1ez5kuw_selectionaipanel_razor_neighborhood_view exceeds preferred complexity thresholds (14 nodes, 6 edges).
