import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
/**
 * ActivationOptionsScreen — "What would you like to do?" prompt (v2).
 *
 * Shown when the user has the SDK installed but hasn't fully activated yet
 * (1-49 events). Offers next-step options without forcing a full re-run.
 */
import { Box, Text } from 'ink';
import { useState } from 'react';
import { useWizardStore } from '../hooks/useWizardStore.js';
import { useEscapeBack } from '../hooks/useEscapeBack.js';
import { PickerMenu } from '../primitives/index.js';
import { Colors, Icons } from '../styles.js';
import { OutroKind } from '../session-constants.js';
import { OUTBOUND_URLS } from '../../../lib/constants.js';
import { writeBugReport } from '../../../lib/bug-report.js';
import { getLogFilePath } from '../../../lib/observability/index.js';
import { analytics } from '../../../utils/analytics.js';
import opn from 'opn';
const DOCS_URL = OUTBOUND_URLS.sdkDocs;
export const ActivationOptionsScreen = ({ store, }) => {
    useWizardStore(store);
    useEscapeBack(store);
    const { snippetConfigured } = store.session;
    const [bugReportPathState, setBugReportPathState] = useState(null);
    const [bugReportFailed, setBugReportFailed] = useState(false);
    const handleSelect = (value) => {
        switch (value) {
            case 'test-locally':
                analytics.wizardCapture('activation options selected', {
                    choice: 'test locally',
                });
                // Route to Framework Detection by treating this as a new project
                store.setActivationOptionsComplete();
                break;
            case 'bug-report': {
                analytics.wizardCapture('activation options selected', {
                    choice: 'bug report',
                });
                // Write a sanitized support report and open the log file. Stay on
                // screen so the user can read the path before choosing a next step.
                const written = writeBugReport({
                    errorMessage: 'User reported they were blocked on activation.',
                    integration: store.session.integration,
                });
                analytics.wizardCapture('activation options bug report written', {
                    success: written !== null,
                });
                if (written) {
                    setBugReportPathState(written);
                    setBugReportFailed(false);
                    opn(getLogFilePath(), { wait: false }).catch(() => {
                        /* opn fails on some headless terminals — non-fatal */
                    });
                }
                else {
                    setBugReportFailed(true);
                }
                // Stay on screen — user can still pick another option
                break;
            }
            case 'docs':
                analytics.wizardCapture('activation options selected', {
                    choice: 'docs',
                });
                opn(DOCS_URL, { wait: false }).catch(() => {
                    /* fire-and-forget */
                });
                // Stay on screen — don't advance
                break;
            case 'exit':
                analytics.wizardCapture('activation options selected', {
                    choice: 'exit',
                });
                store.setOutroData({
                    kind: OutroKind.Cancel,
                    message: 'Come back once your app is deployed and sending events.',
                });
                break;
        }
    };
    return (_jsxs(Box, { flexDirection: "column", flexGrow: 1, children: [_jsxs(Text, { bold: true, color: Colors.accent, children: ["Your SDK is", snippetConfigured ? ' installed' : ' partially set up', ' ', Icons.dash, " waiting for events"] }), _jsxs(Box, { marginTop: 1, flexDirection: "column", children: [_jsx(Text, { color: Colors.secondary, children: "We can see your project is configured but hasn't received many events yet." }), _jsx(Text, { color: Colors.body, children: "What would you like to do?" })] }), _jsx(Box, { marginTop: 1, children: _jsx(PickerMenu, { options: [
                        {
                            value: 'test-locally',
                            label: 'Help me test locally',
                            hint: 'run the setup agent',
                        },
                        {
                            value: 'bug-report',
                            label: "I'm blocked — write a support report",
                            hint: 'open log + save shareable report',
                        },
                        { value: 'docs', label: 'Take me to the docs', hint: DOCS_URL },
                        {
                            value: 'exit',
                            label: "I'm done for now",
                            hint: 'exit and resume later',
                        },
                    ], onSelect: (v) => handleSelect(v) }) }), bugReportPathState && (_jsxs(Box, { marginTop: 1, flexDirection: "column", children: [_jsxs(Text, { color: Colors.success, children: [Icons.checkmark, " Wrote support report to:"] }), _jsx(Text, { bold: true, children: bugReportPathState }), _jsx(Text, { color: Colors.secondary, children: "We also tried to open your log file. Share both with support." })] })), bugReportFailed && (_jsxs(Box, { marginTop: 1, flexDirection: "column", children: [_jsx(Text, { color: Colors.warning, children: "Couldn't write the support report. You can still send us your log file:" }), _jsx(Text, { bold: true, children: getLogFilePath() })] }))] }));
};
