All files / src/issue-reporting/ui report-modal.ts

0% Statements 0/285
100% Branches 1/1
100% Functions 1/1
0% Lines 0/285

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           
/**
 * Issue Report Modal - VS Code Webview Panel
 *
 * Multi-step wizard for reporting highlight issues with privacy-first code obfuscation.
 */
 
import * as vscode from "vscode";
import * as path from "node:path";
import { Logger } from "../../logger";
import { ReportIssueCommandData } from "../commands/report-issue-command";
import {
    IssueType,
    IssueSeverity,
    IssueReportFormData,
    ObfuscatedCodeContext,
    DEFAULT_ISSUE_TYPES,
    DEFAULT_SEVERITY_LEVELS,
    DEFAULT_DATA_SHARING_OPTIONS,
    DEFAULT_PRIVACY_NOTICE,
} from "../models";
import { obfuscateCode, ObfuscationUnavailableError } from "../obfuscation";
import {
    IssueReportMetadataResponse,
    IssueReportRequest,
    IssueReportHighlightContext,
} from "@dataflint/mcp-server";
 
// Import DataFlintServerService type - using any to avoid circular dependency
type DataFlintService = {
    getIssueReportMetadata(): Promise<IssueReportMetadataResponse>;
    submitIssueReport(
        jobId: number,
        request: IssueReportRequest
    ): Promise<{ report_id: string; status: string; message: string }>;
};
 
export class IssueReportModal {
    private panel: vscode.WebviewPanel | undefined;
    private readonly extensionContext: vscode.ExtensionContext;
    private readonly dataflintService: DataFlintService;
    private readonly highlightData: ReportIssueCommandData;
    private metadata: IssueReportMetadataResponse | null = null;
    private logger = Logger.getInstance();
 
    constructor(
        context: vscode.ExtensionContext,
        dataflintService: DataFlintService,
        highlightData: ReportIssueCommandData
    ) {
        this.extensionContext = context;
        this.dataflintService = dataflintService;
        this.highlightData = highlightData;
    }
 
    /**
     * Show the issue report modal
     */
    public async show(): Promise<void> {
        this.logger.info("Opening issue report modal");
 
        // Try to fetch metadata from server, fall back to defaults
        try {
            this.metadata =
                await this.dataflintService.getIssueReportMetadata();
            this.logger.info("Fetched issue report metadata from server");
        } catch (error) {
            this.logger.warn(
                `Failed to fetch metadata from server, using defaults: ${error}`
            );
            this.metadata = null;
        }
 
        // Create webview panel
        this.panel = vscode.window.createWebviewPanel(
            "dataflintIssueReport",
            "Report Issue - DataFlint",
            vscode.ViewColumn.Beside,
            {
                enableScripts: true,
                retainContextWhenHidden: true,
                localResourceRoots: [
                    vscode.Uri.file(
                        path.join(
                            this.extensionContext.extensionPath,
                            "resources"
                        )
                    ),
                ],
            }
        );
 
        // Set HTML content
        this.panel.webview.html = this.getHtmlContent();
 
        // Handle messages from webview
        this.panel.webview.onDidReceiveMessage(
            async (message) => {
                switch (message.command) {
                    case "submit":
                        await this.handleSubmit(message.data);
                        break;
                    case "preview":
                        await this.handlePreview(message.data);
                        break;
                    case "cancel":
                        this.panel?.dispose();
                        break;
                    case "log":
                        this.logger.debug(`[Webview] ${message.text}`);
                        break;
                }
            },
            undefined,
            this.extensionContext.subscriptions
        );
 
        // Clean up on dispose
        this.panel.onDidDispose(() => {
            this.panel = undefined;
            this.logger.info("Issue report modal closed");
        });
    }
 
    /**
     * Handle form submission
     */
    private async handleSubmit(formData: IssueReportFormData): Promise<void> {
        this.logger.info("Processing issue report submission");
 
        try {
            // Show progress
            await vscode.window.withProgress(
                {
                    location: vscode.ProgressLocation.Notification,
                    title: "Submitting issue report...",
                    cancellable: false,
                },
                async () => {
                    // Obfuscate code if user opted in
                    let obfuscatedCode: ObfuscatedCodeContext | undefined;
                    let codeOmissionReason: string | undefined;
 
                    if (
                        formData.includeSourceLine ||
                        formData.includeContextLines
                    ) {
                        try {
                            obfuscatedCode = await this.obfuscateSourceCode(
                                formData.includeContextLines
                            );
                        } catch (error) {
                            if (error instanceof ObfuscationUnavailableError) {
                                // Can't obfuscate = don't send code, but record reason
                                codeOmissionReason =
                                    "obfuscation_unavailable: No AI model available for code obfuscation";
                                this.logger.warn(
                                    "Obfuscation not available, submitting without code"
                                );
                                vscode.window.showWarningMessage(
                                    "Code obfuscation not available. Report will be submitted without source code."
                                );
                            } else {
                                throw error;
                            }
                        }
                    }
 
                    // Build highlight context
                    const highlightContext: IssueReportHighlightContext = {
                        file_path: this.highlightData.filePath,
                        line_number: this.highlightData.codeLine,
                        sql_ids: this.highlightData.sqlIds,
                        node_ids: this.highlightData.nodeIds,
                        display_text: this.highlightData.displayText,
                        is_hotspot: this.highlightData.isHotspot,
                        severity: this.highlightData.severity,
                        query_prefix: this.highlightData.queryPrefix,
                    };
 
                    // Build request
                    const request: IssueReportRequest = {
                        issue_type: formData.issueType,
                        highlight: highlightContext,
                        severity: formData.severity,
                        description: formData.description,
                        expected_line: formData.expectedLine,
                        include_source_line: formData.includeSourceLine,
                        include_context_lines: formData.includeContextLines,
                        obfuscated_code: obfuscatedCode
                            ? {
                                  file_extension: obfuscatedCode.fileExtension,
                                  total_lines_in_file:
                                      obfuscatedCode.totalLinesInFile,
                                  lines: obfuscatedCode.lines.map((line) => ({
                                      line_number: line.lineNumber,
                                      obfuscated_content:
                                          line.obfuscatedContent,
                                      is_target_line: line.isTargetLine,
                                  })),
                              }
                            : undefined,
                        code_omission_reason: codeOmissionReason,
                        extension_version: this.getExtensionVersion(),
                        editor_type: this.getEditorType(),
                    };
 
                    // Submit to server
                    const response =
                        await this.dataflintService.submitIssueReport(
                            this.highlightData.jobId,
                            request
                        );
 
                    // Show success message
                    vscode.window.showInformationMessage(
                        `Report submitted successfully! ID: ${response.report_id}`
                    );
 
                    // Close modal
                    this.panel?.dispose();
                }
            );
        } catch (error) {
            this.logger.error("Failed to submit issue report:", error);
            vscode.window.showErrorMessage(
                `Failed to submit report: ${error instanceof Error ? error.message : "Unknown error"}`
            );
        }
    }
 
    /**
     * Handle code preview request
     */
    private async handlePreview(options: {
        includeSourceLine: boolean;
        includeContextLines: boolean;
    }): Promise<void> {
        try {
            if (!options.includeSourceLine && !options.includeContextLines) {
                // Send empty preview
                this.panel?.webview.postMessage({
                    command: "previewResult",
                    lines: [],
                });
                return;
            }
 
            const obfuscatedCode = await this.obfuscateSourceCode(
                options.includeContextLines
            );
 
            this.panel?.webview.postMessage({
                command: "previewResult",
                lines: obfuscatedCode.lines,
            });
        } catch (error) {
            this.logger.error("Failed to generate preview:", error);
 
            const isUnavailable = error instanceof ObfuscationUnavailableError;
            this.panel?.webview.postMessage({
                command: "previewResult",
                error: isUnavailable
                    ? "Code obfuscation not available (no AI model). Code will not be included in the report."
                    : error instanceof Error
                      ? error.message
                      : "Failed to generate preview",
                obfuscationUnavailable: isUnavailable,
            });
        }
    }
 
    /**
     * Obfuscate source code for the highlight
     */
    private async obfuscateSourceCode(
        includeContext: boolean
    ): Promise<ObfuscatedCodeContext> {
        const filePath = this.highlightData.filePath;
        const targetLine = this.highlightData.codeLine;
        const contextSize = includeContext ? 5 : 0;
 
        // Read the file
        const document = await vscode.workspace.openTextDocument(
            vscode.Uri.file(filePath)
        );
 
        const startLine = Math.max(1, targetLine - contextSize);
        const endLine = Math.min(document.lineCount, targetLine + contextSize);
 
        const lines: string[] = [];
        for (let i = startLine - 1; i < endLine; i++) {
            lines.push(document.lineAt(i).text);
        }
 
        // Obfuscate the code
        const obfuscated = obfuscateCode(
            filePath,
            lines,
            startLine,
            targetLine,
            document.lineCount
        );
 
        return obfuscated;
    }
 
    /**
     * Get extension version
     */
    private getExtensionVersion(): string {
        const packageJson = vscode.extensions.getExtension(
            "dataflint.dataflint-copilot"
        )?.packageJSON;
        return packageJson?.version || "unknown";
    }
 
    /**
     * Get editor type (vscode or cursor)
     */
    private getEditorType(): "vscode" | "cursor" {
        // Check if running in Cursor by looking at the app name
        const appName = vscode.env.appName.toLowerCase();
        return appName.includes("cursor") ? "cursor" : "vscode";
    }
 
    /**
     * Generate HTML content for the webview
     */
    private getHtmlContent(): string {
        // Use server metadata or fall back to defaults
        const issueTypes = this.metadata?.issue_types || DEFAULT_ISSUE_TYPES;
        const severityLevels =
            this.metadata?.severity_levels || DEFAULT_SEVERITY_LEVELS;
        const dataSharingOptions =
            this.metadata?.data_sharing_options || DEFAULT_DATA_SHARING_OPTIONS;
        const privacyNotice =
            this.metadata?.privacy_notice || DEFAULT_PRIVACY_NOTICE;
 
        const highlightInfo = this.highlightData;
 
        return `<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Report Issue</title>
    <style>
        :root {
            --df-orange: #FF8900;
            --df-gold: #FBBF02;
            --df-mint: #A3F5B9;
            --report-bg: var(--vscode-editor-background);
            --report-card: var(--vscode-editorWidget-background);
            --report-border: var(--vscode-panel-border);
            --report-accent: var(--df-orange);
            --report-text: var(--vscode-editor-foreground);
            --report-muted: var(--vscode-descriptionForeground);
        }
 
        * { box-sizing: border-box; }
 
        body {
            font-family: var(--vscode-font-family);
            font-size: var(--vscode-font-size);
            color: var(--report-text);
            background: var(--report-bg);
            margin: 0;
            padding: 16px;
            line-height: 1.5;
        }
 
        .container {
            max-width: 520px;
            margin: 0 auto;
        }
 
        /* Header */
        .header {
            display: flex;
            align-items: center;
            gap: 12px;
            margin-bottom: 20px;
            padding-bottom: 16px;
            border-bottom: 1px solid var(--report-border);
        }
 
        .header-icon {
            width: 40px;
            height: 40px;
            background: linear-gradient(135deg, var(--df-orange), var(--df-gold));
            border-radius: 8px;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 20px;
        }
 
        .header-text h1 {
            margin: 0;
            font-size: 1.25em;
            font-weight: 600;
        }
 
        .header-text .subtitle {
            color: var(--report-muted);
            font-size: 0.85em;
            margin-top: 2px;
        }
 
        /* Cards */
        .card {
            background: var(--report-card);
            border: 1px solid var(--report-border);
            border-radius: 8px;
            padding: 16px;
            margin-bottom: 12px;
        }
 
        .card-title {
            font-size: 0.8em;
            font-weight: 600;
            text-transform: uppercase;
            letter-spacing: 0.5px;
            color: var(--report-muted);
            margin-bottom: 12px;
        }
 
        /* Issue Type - Compact horizontal */
        .issue-types {
            display: grid;
            grid-template-columns: repeat(2, 1fr);
            gap: 8px;
        }
 
        .issue-type {
            display: flex;
            align-items: center;
            gap: 8px;
            padding: 10px 12px;
            border: 1px solid var(--report-border);
            border-radius: 6px;
            cursor: pointer;
            transition: all 0.15s;
            background: transparent;
        }
 
        .issue-type:hover {
            background: var(--vscode-list-hoverBackground);
            border-color: var(--report-muted);
        }
 
        .issue-type.selected {
            border-color: var(--df-orange);
            background: rgba(255, 137, 0, 0.1);
        }
 
        .issue-type input { display: none; }
 
        .issue-type-icon {
            font-size: 1.1em;
            width: 24px;
            text-align: center;
        }
 
        .issue-type-label {
            font-size: 0.9em;
            font-weight: 500;
        }
 
        /* Severity - Inline pills */
        .severity-row {
            display: flex;
            gap: 6px;
        }
 
        .severity-pill {
            flex: 1;
            padding: 8px 4px;
            border: 1px solid var(--report-border);
            border-radius: 20px;
            cursor: pointer;
            background: transparent;
            color: var(--report-text);
            font-size: 0.85em;
            text-align: center;
            transition: all 0.15s;
        }
 
        .severity-pill:hover { background: var(--vscode-list-hoverBackground); }
 
        .severity-pill.selected {
            background: var(--df-orange);
            color: white;
            border-color: var(--df-orange);
        }
 
        .severity-pill[data-severity="low"].selected { background: #6b7280; border-color: #6b7280; }
        .severity-pill[data-severity="medium"].selected { background: #ca8a04; border-color: #ca8a04; }
        .severity-pill[data-severity="high"].selected { background: #ea580c; border-color: #ea580c; }
        .severity-pill[data-severity="critical"].selected { background: #dc2626; border-color: #dc2626; }
 
        /* Details textarea */
        textarea {
            width: 100%;
            padding: 10px;
            border: 1px solid var(--report-border);
            border-radius: 6px;
            background: var(--vscode-input-background);
            color: var(--vscode-input-foreground);
            font-family: inherit;
            font-size: inherit;
            resize: vertical;
            min-height: 60px;
        }
 
        textarea:focus {
            outline: none;
            border-color: var(--df-orange);
        }
 
        textarea::placeholder { color: var(--report-muted); }
 
        /* Expected line */
        .expected-line {
            display: none;
            margin-top: 12px;
        }
 
        .expected-line.visible { display: block; }
 
        .expected-line input {
            width: 100px;
            padding: 6px 10px;
            border: 1px solid var(--report-border);
            border-radius: 4px;
            background: var(--vscode-input-background);
            color: var(--vscode-input-foreground);
        }
 
        /* Code sharing section */
        .privacy-box {
            background: rgba(163, 245, 185, 0.1);
            border: 1px solid var(--df-mint);
            border-radius: 6px;
            padding: 10px 12px;
            margin-bottom: 12px;
            font-size: 0.85em;
            display: flex;
            align-items: flex-start;
            gap: 8px;
        }
 
        .privacy-box-icon { font-size: 1.1em; }
 
        .share-options {
            display: flex;
            gap: 16px;
        }
 
        .share-option {
            display: flex;
            align-items: center;
            gap: 6px;
            cursor: pointer;
            font-size: 0.9em;
        }
 
        .share-option input[type="checkbox"] {
            accent-color: var(--df-orange);
        }
 
        /* Code preview */
        .code-preview {
            background: var(--vscode-textCodeBlock-background);
            border: 1px solid var(--report-border);
            border-radius: 6px;
            margin-top: 12px;
            overflow: hidden;
            display: none;
        }
 
        .code-preview.visible { display: block; }
 
        .code-preview-header {
            background: var(--vscode-editorWidget-background);
            padding: 6px 10px;
            font-size: 0.8em;
            color: var(--report-muted);
            display: flex;
            align-items: center;
            gap: 6px;
        }
 
        .code-preview-content {
            padding: 8px 10px;
            font-family: var(--vscode-editor-font-family, monospace);
            font-size: 0.85em;
            overflow-x: auto;
            max-height: 120px;
            overflow-y: auto;
        }
 
        .code-line {
            display: flex;
            white-space: pre;
            line-height: 1.4;
        }
 
        .code-line-number {
            min-width: 32px;
            text-align: right;
            padding-right: 10px;
            color: var(--report-muted);
            user-select: none;
        }
 
        .code-line.target {
            background: rgba(255, 137, 0, 0.15);
            border-radius: 2px;
        }
 
        /* Actions */
        .actions {
            display: flex;
            justify-content: flex-end;
            gap: 8px;
            margin-top: 16px;
        }
 
        .btn {
            padding: 10px 20px;
            border: none;
            border-radius: 6px;
            cursor: pointer;
            font-size: 0.9em;
            font-weight: 500;
            transition: all 0.15s;
        }
 
        .btn-cancel {
            background: transparent;
            color: var(--report-muted);
            border: 1px solid var(--report-border);
        }
 
        .btn-cancel:hover {
            background: var(--vscode-list-hoverBackground);
            color: var(--report-text);
        }
 
        .btn-submit {
            background: linear-gradient(135deg, var(--df-orange), var(--df-gold));
            color: white;
        }
 
        .btn-submit:hover {
            opacity: 0.9;
            transform: translateY(-1px);
        }
 
        .hidden { display: none; }
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <div class="header-icon">๐Ÿšฉ</div>
            <div class="header-text">
                <h1>Report Issue</h1>
                <div class="subtitle">${path.basename(highlightInfo.filePath)}:${highlightInfo.codeLine} ยท ${highlightInfo.displayText || "Highlight"}</div>
            </div>
        </div>
 
        <!-- Issue Type -->
        <div class="card">
            <div class="card-title">What's wrong?</div>
            <div class="issue-types">
                ${issueTypes
                    .map(
                        (type, index) => `
                    <label class="issue-type ${index === 0 ? "selected" : ""}" data-value="${type.value}">
                        <input type="radio" name="issueType" value="${type.value}" ${index === 0 ? "checked" : ""}>
                        <span class="issue-type-icon">${this.getIssueTypeIcon(type.value)}</span>
                        <span class="issue-type-label">${type.label}</span>
                    </label>
                `
                    )
                    .join("")}
            </div>
        </div>
 
        <!-- Severity -->
        <div class="card">
            <div class="card-title">Impact level</div>
            <div class="severity-row">
                ${severityLevels
                    .map(
                        (level, index) => `
                    <button class="severity-pill ${index === 1 ? "selected" : ""}" data-severity="${level.value}" title="${level.description}">
                        ${level.label}
                    </button>
                `
                    )
                    .join("")}
            </div>
        </div>
 
        <!-- Details -->
        <div class="card">
            <div class="card-title">Details <span style="font-weight: normal; text-transform: none;">(optional)</span></div>
            <textarea id="description" placeholder="Describe what's wrong or what you expected..."></textarea>
            <div class="expected-line" id="expectedLineSection">
                <label style="font-size: 0.9em; color: var(--report-muted);">
                    Expected line: <input type="number" id="expectedLine" min="1" placeholder="Line #">
                </label>
            </div>
        </div>
 
        <!-- Code Sharing -->
        <div class="card">
            <div class="card-title">๐Ÿ”’ Share code context</div>
            <div class="privacy-box">
                <span class="privacy-box-icon">โœ“</span>
                <span>Code is <strong>automatically anonymized</strong> before sharing. Variable names, strings, and comments are replaced with placeholders.</span>
            </div>
            <div class="share-options">
                ${dataSharingOptions
                    .map((option) => {
                        const isChecked =
                            (option as any).default_checked ||
                            (option as any).defaultChecked ||
                            false;
                        return `
                    <label class="share-option">
                        <input type="checkbox" id="${option.key}" ${isChecked ? "checked" : ""}>
                        <span>${option.label}</span>
                    </label>
                `;
                    })
                    .join("")}
            </div>
            <div class="code-preview" id="codePreview">
                <div class="code-preview-header">
                    <span>๐Ÿ”’</span>
                    <span>Preview (anonymized)</span>
                </div>
                <div class="code-preview-content" id="codePreviewContent">
                    <em style="color: var(--report-muted);">Select options above to preview</em>
                </div>
            </div>
        </div>
 
        <div class="actions">
            <button class="btn btn-cancel" id="cancelBtn">Cancel</button>
            <button class="btn btn-submit" id="submitBtn">Submit Report</button>
        </div>
    </div>
 
    <script>
        const vscode = acquireVsCodeApi();
 
        // State
        let selectedIssueType = '${issueTypes[0]?.value || "incorrect_data"}';
        let selectedSeverity = '${severityLevels[1]?.value || "medium"}';
 
        // Issue type selection
        document.querySelectorAll('.issue-type').forEach(option => {
            option.addEventListener('click', () => {
                const radio = option.querySelector('input[type="radio"]');
                radio.checked = true;
                selectedIssueType = radio.value;
                
                // Update selection styling
                document.querySelectorAll('.issue-type').forEach(o => o.classList.remove('selected'));
                option.classList.add('selected');
                
                // Show/hide expected line input for "misplaced" type
                const expectedLineSection = document.getElementById('expectedLineSection');
                if (selectedIssueType === 'misplaced' || selectedIssueType === 'both') {
                    expectedLineSection.classList.add('visible');
                } else {
                    expectedLineSection.classList.remove('visible');
                }
            });
        });
 
        // Severity pills
        document.querySelectorAll('.severity-pill').forEach(pill => {
            pill.addEventListener('click', () => {
                document.querySelectorAll('.severity-pill').forEach(p => p.classList.remove('selected'));
                pill.classList.add('selected');
                selectedSeverity = pill.dataset.severity;
            });
        });
 
        // Code sharing checkboxes
        document.querySelectorAll('.share-option input[type="checkbox"]').forEach(checkbox => {
            checkbox.addEventListener('change', updatePreview);
        });
 
        function updatePreview() {
            const includeSourceLine = document.getElementById('include_source_line')?.checked || false;
            const includeContextLines = document.getElementById('include_context_lines')?.checked || false;
            
            // Show/hide preview based on selections
            const previewBox = document.getElementById('codePreview');
            if (includeSourceLine || includeContextLines) {
                previewBox.classList.add('visible');
                vscode.postMessage({
                    command: 'preview',
                    data: { includeSourceLine, includeContextLines }
                });
            } else {
                previewBox.classList.remove('visible');
            }
        }
 
        // Handle preview result from extension
        window.addEventListener('message', event => {
            const message = event.data;
            if (message.command === 'previewResult') {
                const content = document.getElementById('codePreviewContent');
                const previewBox = document.getElementById('codePreview');
                
                if (message.error) {
                    content.innerHTML = '<em style="color: var(--vscode-errorForeground);">' + message.error + '</em>';
                    previewBox.classList.add('visible');
                } else if (!message.lines || message.lines.length === 0) {
                    content.innerHTML = '<em style="color: var(--report-muted);">No code will be shared</em>';
                } else {
                    content.innerHTML = message.lines.map(line => 
                        '<div class="code-line' + (line.isTargetLine ? ' target' : '') + '">' +
                        '<span class="code-line-number">' + line.lineNumber + '</span>' +
                        '<span>' + escapeHtml(line.obfuscatedContent) + '</span>' +
                        '</div>'
                    ).join('');
                }
            }
        });
 
        function escapeHtml(text) {
            const div = document.createElement('div');
            div.textContent = text;
            return div.innerHTML;
        }
 
        // Cancel button
        document.getElementById('cancelBtn').addEventListener('click', () => {
            vscode.postMessage({ command: 'cancel' });
        });
 
        // Submit button
        document.getElementById('submitBtn').addEventListener('click', () => {
            const description = document.getElementById('description').value;
            const expectedLine = document.getElementById('expectedLine')?.value;
            const includeSourceLine = document.getElementById('include_source_line')?.checked || false;
            const includeContextLines = document.getElementById('include_context_lines')?.checked || false;
 
            vscode.postMessage({
                command: 'submit',
                data: {
                    issueType: selectedIssueType,
                    severity: selectedSeverity,
                    description: description || undefined,
                    expectedLine: expectedLine ? parseInt(expectedLine, 10) : undefined,
                    includeSourceLine,
                    includeContextLines
                }
            });
        });
    </script>
</body>
</html>`;
    }
 
    /**
     * Get icon for issue type
     */
    private getIssueTypeIcon(type: IssueType): string {
        switch (type) {
            case "incorrect_data":
                return "โŒ";
            case "misplaced":
                return "๐Ÿ“";
            case "both":
                return "โš ๏ธ";
            case "other":
                return "๐Ÿ’ฌ";
            default:
                return "๐Ÿ“";
        }
    }
}