"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getOfficialChannelsDocsSummary = exports.getOfficialChannelMacOSHelp = exports.getOfficialChannelClearTokenHelp = exports.getOfficialChannelTokenHelp = exports.getOfficialChannelsLegacyEnableHelp = exports.getOfficialChannelsSetHelp = exports.getOfficialChannelsRuntimeNote = exports.getOfficialChannelsSectionDescription = exports.getOfficialChannelConfiguredPlaceholder = exports.getOfficialChannelDefaultTokenPlaceholder = exports.isOfficialChannelTokenRequired = exports.getTokenValueLabel = exports.getChannelConfigSelectionLabel = exports.getOfficialChannelsSupportedProfiles = exports.isOfficialChannelSelectionValid = exports.getOfficialChannelChoices = exports.expandOfficialChannelSelection = exports.buildOfficialChannelsLaunchPreview = exports.buildOfficialChannelsReadinessSummary = exports.buildOfficialChannelSetupSummary = exports.getOfficialChannelReadyMessage = exports.getOfficialChannelUnavailableReason = exports.getOfficialChannelSummary = exports.getOfficialChannelStateDirEnvKey = exports.getOfficialChannelEnvDir = exports.officialChannelRequiresMacOS = exports.getOfficialChannelEnvKey = exports.getOfficialChannelPluginSpec = exports.getOfficialChannelDisplayName = exports.getOfficialChannelManualSetupCommands = exports.getOfficialChannelTokenIds = exports.resolveOfficialChannelsLaunchPlan = exports.buildOfficialChannelsArgs = exports.getOfficialChannelsEnvironmentStatus = exports.getOfficialChannelsAccountStatusCaveat = exports.getOfficialChannelsSupportMessage = exports.getOfficialChannelsStateScopeMessage = exports.resolveOfficialChannelsAuthSummary = exports.resolveOfficialChannelsVersionSummary = exports.hasExplicitPermissionOverride = exports.hasExplicitChannelsFlag = exports.isDiscordChannelsSessionSupported = exports.isMacOS = exports.isBunAvailable = exports.MINIMUM_OFFICIAL_CHANNELS_CLAUDE_VERSION = exports.resolveLegacyDiscordSelection = exports.normalizeOfficialChannelIds = exports.isOfficialChannelId = exports.OFFICIAL_CHANNEL_IDS = exports.OFFICIAL_CHANNELS = void 0;
exports.getOfficialChannelsSelectionSummary = exports.getOfficialChannelsPermissionBypassMessage = exports.getOfficialChannelsNoSelectionMessage = exports.getOfficialChannelsCompatibilityMessage = exports.getOfficialChannelsBunMissingMessage = exports.getOfficialChannelTokenMissingMessage = exports.getOfficialChannelsExplicitOverrideMessage = exports.getOfficialChannelSyncSkipReason = exports.getOfficialChannelSyncFailureMessage = void 0;
const child_process_1 = require("child_process");
const claude_detector_1 = require("../utils/claude-detector");
const claude_subcommand_detector_1 = require("../utils/claude-subcommand-detector");
exports.OFFICIAL_CHANNELS = {
    telegram: {
        id: 'telegram',
        displayName: 'Telegram',
        pluginSpec: 'plugin:telegram@claude-plugins-official',
        envKey: 'TELEGRAM_BOT_TOKEN',
        envDir: 'telegram',
        stateDirEnvKey: 'TELEGRAM_STATE_DIR',
        manualSetupCommands: [
            '/plugin install telegram@claude-plugins-official',
            '/telegram:configure <token>',
            '/telegram:access pair <code>',
            '/telegram:access policy allowlist',
        ],
    },
    discord: {
        id: 'discord',
        displayName: 'Discord',
        pluginSpec: 'plugin:discord@claude-plugins-official',
        envKey: 'DISCORD_BOT_TOKEN',
        envDir: 'discord',
        stateDirEnvKey: 'DISCORD_STATE_DIR',
        manualSetupCommands: [
            '/plugin install discord@claude-plugins-official',
            '/discord:configure <token>',
            '/discord:access pair <code>',
            '/discord:access policy allowlist',
        ],
    },
    imessage: {
        id: 'imessage',
        displayName: 'iMessage',
        pluginSpec: 'plugin:imessage@claude-plugins-official',
        envDir: 'imessage',
        stateDirEnvKey: 'IMESSAGE_STATE_DIR',
        requiresMacOS: true,
        manualSetupCommands: [
            '/plugin install imessage@claude-plugins-official',
            '/imessage:access allow +15551234567',
        ],
    },
};
// Re-export from leaf module so config-loader can use these without pulling
// in this file's claude-detector / shell-executor dep chain.
const official_channels_ids_1 = require("./official-channels-ids");
Object.defineProperty(exports, "OFFICIAL_CHANNEL_IDS", { enumerable: true, get: function () { return official_channels_ids_1.OFFICIAL_CHANNEL_IDS; } });
Object.defineProperty(exports, "isOfficialChannelId", { enumerable: true, get: function () { return official_channels_ids_1.isOfficialChannelId; } });
Object.defineProperty(exports, "normalizeOfficialChannelIds", { enumerable: true, get: function () { return official_channels_ids_1.normalizeOfficialChannelIds; } });
Object.defineProperty(exports, "resolveLegacyDiscordSelection", { enumerable: true, get: function () { return official_channels_ids_1.resolveLegacyDiscordSelection; } });
exports.MINIMUM_OFFICIAL_CHANNELS_CLAUDE_VERSION = '2.1.80';
function isBunAvailable() {
    const result = (0, child_process_1.spawnSync)('bun', ['--version'], { stdio: 'ignore' });
    return result.status === 0;
}
exports.isBunAvailable = isBunAvailable;
function isMacOS() {
    return process.platform === 'darwin';
}
exports.isMacOS = isMacOS;
function isDiscordChannelsSessionSupported(target, profileType) {
    return target === 'claude' && (profileType === 'default' || profileType === 'account');
}
exports.isDiscordChannelsSessionSupported = isDiscordChannelsSessionSupported;
function hasExplicitChannelsFlag(args) {
    return args.some((arg) => arg === '--channels' || arg.startsWith('--channels='));
}
exports.hasExplicitChannelsFlag = hasExplicitChannelsFlag;
function hasExplicitPermissionOverride(args) {
    return args.some((arg) => arg === '--allow-dangerously-skip-permissions' ||
        arg === '--dangerously-skip-permissions' ||
        arg === '--permission-mode' ||
        arg.startsWith('--permission-mode='));
}
exports.hasExplicitPermissionOverride = hasExplicitPermissionOverride;
function isTeamOrEnterpriseSubscription(subscriptionType) {
    const normalized = subscriptionType?.trim().toLowerCase() ?? '';
    return normalized.includes('team') || normalized.includes('enterprise');
}
function resolveOfficialChannelsVersionSummary(version) {
    if (!version) {
        return {
            current: null,
            minimum: exports.MINIMUM_OFFICIAL_CHANNELS_CLAUDE_VERSION,
            state: 'unknown',
            message: `Unable to detect Claude Code version. Official Channels require v${exports.MINIMUM_OFFICIAL_CHANNELS_CLAUDE_VERSION}+.`,
        };
    }
    if ((0, claude_detector_1.isClaudeCliVersionAtLeast)(version, exports.MINIMUM_OFFICIAL_CHANNELS_CLAUDE_VERSION)) {
        return {
            current: version,
            minimum: exports.MINIMUM_OFFICIAL_CHANNELS_CLAUDE_VERSION,
            state: 'supported',
            message: `Claude Code v${version}`,
        };
    }
    return {
        current: version,
        minimum: exports.MINIMUM_OFFICIAL_CHANNELS_CLAUDE_VERSION,
        state: 'unsupported',
        message: `Official Channels require Claude Code v${exports.MINIMUM_OFFICIAL_CHANNELS_CLAUDE_VERSION}+ (found v${version}).`,
    };
}
exports.resolveOfficialChannelsVersionSummary = resolveOfficialChannelsVersionSummary;
function resolveOfficialChannelsAuthSummary(authStatus) {
    if (!authStatus) {
        return {
            checked: false,
            loggedIn: false,
            authMethod: null,
            subscriptionType: null,
            state: 'unknown',
            eligible: false,
            message: 'Unable to verify Claude auth status. Official Channels require claude.ai login.',
        };
    }
    if (!authStatus.loggedIn) {
        return {
            checked: true,
            loggedIn: false,
            authMethod: authStatus.authMethod ?? null,
            subscriptionType: authStatus.subscriptionType ?? null,
            state: 'ineligible',
            eligible: false,
            message: 'Official Channels require claude.ai login. Run `claude auth login` first.',
        };
    }
    if (authStatus.authMethod !== 'claude.ai') {
        return {
            checked: true,
            loggedIn: true,
            authMethod: authStatus.authMethod ?? null,
            subscriptionType: authStatus.subscriptionType ?? null,
            state: 'ineligible',
            eligible: false,
            message: `Official Channels require claude.ai login. Current auth method: ${authStatus.authMethod ?? 'unknown'}.`,
        };
    }
    return {
        checked: true,
        loggedIn: true,
        authMethod: authStatus.authMethod,
        subscriptionType: authStatus.subscriptionType ?? null,
        state: 'eligible',
        eligible: true,
        message: 'Authenticated with claude.ai.',
        ...(isTeamOrEnterpriseSubscription(authStatus.subscriptionType ?? null)
            ? {
                orgRequirementMessage: 'Team and Enterprise orgs also need channels enabled by an admin before messages will arrive.',
            }
            : {}),
    };
}
exports.resolveOfficialChannelsAuthSummary = resolveOfficialChannelsAuthSummary;
function getOfficialChannelsStateScopeMessage() {
    return "Telegram and Discord tokens live in Claude's machine-level channel state under ~/.claude/channels/. Native Claude sessions share that state unless you manually override the official *_STATE_DIR variables.";
}
exports.getOfficialChannelsStateScopeMessage = getOfficialChannelsStateScopeMessage;
function getOfficialChannelsSupportMessage() {
    return 'Works only for native Claude default/account sessions. It does not apply to API, OAuth, or non-Claude targets such as `ccs glm`, `ccs gemini`, `ccs codex`, `ccs --target droid`, or `ccs --target codex`.';
}
exports.getOfficialChannelsSupportMessage = getOfficialChannelsSupportMessage;
function getOfficialChannelsAccountStatusCaveat() {
    return 'Dashboard status reflects the base Claude install visible to the current CCS process. Isolated native account sessions can still differ until that account signs in with claude.ai.';
}
exports.getOfficialChannelsAccountStatusCaveat = getOfficialChannelsAccountStatusCaveat;
function getOfficialChannelsEnvironmentStatus(authEnvOverrides) {
    return {
        bunInstalled: isBunAvailable(),
        supportedProfiles: getOfficialChannelsSupportedProfiles(),
        stateScopeMessage: getOfficialChannelsStateScopeMessage(),
        claudeVersion: resolveOfficialChannelsVersionSummary((0, claude_detector_1.getClaudeCliVersion)()),
        auth: resolveOfficialChannelsAuthSummary((0, claude_detector_1.getClaudeAuthStatus)(authEnvOverrides)),
    };
}
exports.getOfficialChannelsEnvironmentStatus = getOfficialChannelsEnvironmentStatus;
function buildOfficialChannelsArgs(args, channels, includePermissionBypass) {
    const nextArgs = [
        ...args,
        '--channels',
        ...channels.map((channel) => exports.OFFICIAL_CHANNELS[channel].pluginSpec),
    ];
    if (includePermissionBypass) {
        nextArgs.push('--dangerously-skip-permissions');
    }
    return nextArgs;
}
exports.buildOfficialChannelsArgs = buildOfficialChannelsArgs;
function resolveOfficialChannelsLaunchPlan(input) {
    const { args, config, target, profileType, environment, channelReadiness } = input;
    const skippedMessages = [];
    if (config.selected.length === 0) {
        return {
            applied: false,
            wantsPermissionBypass: false,
            appliedChannels: [],
            skippedMessages,
        };
    }
    // Claude subcommands (agents, doctor, mcp, ...) don't accept official-channels
    // plugin args. Skip silently — channels are session-only. Issue #1218.
    if ((0, claude_subcommand_detector_1.isClaudeSubcommandInvocation)(args)) {
        return {
            applied: false,
            wantsPermissionBypass: false,
            appliedChannels: [],
            skippedMessages,
        };
    }
    if (!isDiscordChannelsSessionSupported(target, profileType)) {
        return {
            applied: false,
            wantsPermissionBypass: false,
            appliedChannels: [],
            skippedMessages: [getOfficialChannelsCompatibilityMessage()],
        };
    }
    if (hasExplicitChannelsFlag(args)) {
        return {
            applied: false,
            wantsPermissionBypass: false,
            appliedChannels: [],
            skippedMessages,
        };
    }
    if (!environment.bunInstalled) {
        return {
            applied: false,
            wantsPermissionBypass: false,
            appliedChannels: [],
            skippedMessages: ['Official Channels auto-enable skipped because Bun is not installed.'],
        };
    }
    if (environment.claudeVersion.state !== 'supported') {
        return {
            applied: false,
            wantsPermissionBypass: false,
            appliedChannels: [],
            skippedMessages: [environment.claudeVersion.message],
        };
    }
    if (environment.auth.state !== 'eligible') {
        return {
            applied: false,
            wantsPermissionBypass: false,
            appliedChannels: [],
            skippedMessages: [environment.auth.message],
        };
    }
    const appliedChannels = [];
    for (const channelId of (0, official_channels_ids_1.normalizeOfficialChannelIds)(config.selected)) {
        const channel = exports.OFFICIAL_CHANNELS[channelId];
        if (channel.requiresMacOS && !isMacOS()) {
            skippedMessages.push(`${channel.displayName} auto-enable skipped because it requires macOS.`);
            continue;
        }
        if (!channelReadiness[channelId]) {
            skippedMessages.push(channel.envKey
                ? `${channel.displayName} auto-enable skipped because ${channel.envKey} is not configured.`
                : `${channel.displayName} auto-enable skipped because it is not ready on this machine.`);
            continue;
        }
        appliedChannels.push(channelId);
    }
    return {
        applied: appliedChannels.length > 0,
        wantsPermissionBypass: config.unattended && !hasExplicitPermissionOverride(args),
        appliedChannels,
        skippedMessages,
    };
}
exports.resolveOfficialChannelsLaunchPlan = resolveOfficialChannelsLaunchPlan;
function getOfficialChannelTokenIds() {
    return official_channels_ids_1.OFFICIAL_CHANNEL_IDS.filter((channelId) => Boolean(exports.OFFICIAL_CHANNELS[channelId].envKey));
}
exports.getOfficialChannelTokenIds = getOfficialChannelTokenIds;
function getOfficialChannelManualSetupCommands(channelId) {
    return exports.OFFICIAL_CHANNELS[channelId].manualSetupCommands;
}
exports.getOfficialChannelManualSetupCommands = getOfficialChannelManualSetupCommands;
function getOfficialChannelDisplayName(channelId) {
    return exports.OFFICIAL_CHANNELS[channelId].displayName;
}
exports.getOfficialChannelDisplayName = getOfficialChannelDisplayName;
function getOfficialChannelPluginSpec(channelId) {
    return exports.OFFICIAL_CHANNELS[channelId].pluginSpec;
}
exports.getOfficialChannelPluginSpec = getOfficialChannelPluginSpec;
function getOfficialChannelEnvKey(channelId) {
    return exports.OFFICIAL_CHANNELS[channelId].envKey;
}
exports.getOfficialChannelEnvKey = getOfficialChannelEnvKey;
function officialChannelRequiresMacOS(channelId) {
    return Boolean(exports.OFFICIAL_CHANNELS[channelId].requiresMacOS);
}
exports.officialChannelRequiresMacOS = officialChannelRequiresMacOS;
function getOfficialChannelEnvDir(channelId) {
    return exports.OFFICIAL_CHANNELS[channelId].envDir;
}
exports.getOfficialChannelEnvDir = getOfficialChannelEnvDir;
function getOfficialChannelStateDirEnvKey(channelId) {
    return exports.OFFICIAL_CHANNELS[channelId].stateDirEnvKey;
}
exports.getOfficialChannelStateDirEnvKey = getOfficialChannelStateDirEnvKey;
function getOfficialChannelSummary(channelId) {
    if (channelId === 'telegram') {
        return 'Bot token required. Runtime-only while Claude is running; Telegram pairing and access policy still happen in Claude.';
    }
    if (channelId === 'discord') {
        return 'Bot token required. Runtime-only while Claude is running; Discord pairing and access policy still happen in Claude.';
    }
    return 'macOS-only. Runtime-only while Claude is running; plugin install, Full Disk Access, and the first-reply Automation approval are still required.';
}
exports.getOfficialChannelSummary = getOfficialChannelSummary;
function getOfficialChannelUnavailableReason(channelId) {
    if (channelId === 'imessage' && !isMacOS()) {
        return 'Requires macOS.';
    }
    return undefined;
}
exports.getOfficialChannelUnavailableReason = getOfficialChannelUnavailableReason;
function getOfficialChannelReadyMessage(channelId) {
    if (channelId === 'imessage') {
        return isMacOS()
            ? 'Needs Claude-side install plus Full Disk Access and the first-reply Automation prompt.'
            : 'Unavailable on this platform.';
    }
    const envKey = getOfficialChannelEnvKey(channelId);
    return envKey
        ? `${envKey} must be configured before CCS can auto-enable this channel. Claude-side pairing and access policy are still required.`
        : 'Claude-side setup required.';
}
exports.getOfficialChannelReadyMessage = getOfficialChannelReadyMessage;
function buildOfficialChannelSetupSummary(channel) {
    if (!channel.selected) {
        return {
            state: 'not_selected',
            label: 'Not selected',
            detail: 'CCS will not auto-add this channel until you turn it on here.',
            nextStep: 'Turn this channel on if you want CCS to add it on supported native Claude runs.',
        };
    }
    if (channel.unavailableReason) {
        return {
            state: 'unavailable',
            label: channel.unavailableReason,
            detail: `${channel.displayName} is selected, but this machine cannot use it right now.`,
            nextStep: 'Turn it off here, or switch to a supported machine before relying on it.',
        };
    }
    if (channel.id === 'imessage') {
        return {
            state: 'needs_claude_setup',
            label: 'Claude-side setup remaining',
            detail: 'CCS can add iMessage on the next native Claude run, but plugin install, sender allowlist, Full Disk Access, and the first-reply Automation prompt are still local steps.',
            nextStep: 'Complete the one-time Claude and macOS setup below before relying on iMessage.',
        };
    }
    const envKey = getOfficialChannelEnvKey(channel.id);
    if (channel.requiresToken && !channel.tokenAvailable) {
        return {
            state: 'needs_token',
            label: 'Needs token',
            detail: `${envKey} is missing. CCS cannot auto-add ${channel.displayName} until you save it here or provide it in the current CCS process env.`,
            nextStep: `Save ${envKey} below, or export it before launching CCS.`,
        };
    }
    const sourceDetail = channel.savedInClaudeState
        ? `${envKey} is saved in Claude channel state.`
        : `${envKey} is available from the current CCS process env.`;
    return {
        state: 'ready',
        label: channel.savedInClaudeState
            ? 'Ready for next native run'
            : 'Ready from current CCS process env',
        detail: channel.savedInClaudeState
            ? `${sourceDetail}${channel.processEnvAvailable ? ` The current CCS process env also provides ${envKey}.` : ''} CCS can auto-add ${channel.displayName} on the next supported native Claude run. Claude-side pairing and access policy still happen in Claude.`
            : `${sourceDetail} CCS can auto-add ${channel.displayName} on the next supported native Claude run. Claude-side pairing and access policy still happen in Claude.`,
        nextStep: channel.savedInClaudeState
            ? 'Run `ccs` or a native Claude account profile. Claude-side pairing and access policy may still be required.'
            : 'Run CCS from this same env, or save the token here if you want persistent Claude state.',
    };
}
exports.buildOfficialChannelSetupSummary = buildOfficialChannelSetupSummary;
function buildOfficialChannelsReadinessSummary(input) {
    const { config, environment, channels } = input;
    if (config.selected.length === 0) {
        return {
            state: 'needs_setup',
            title: 'No channels selected yet',
            message: 'Choose at least one official channel before CCS can auto-add it on supported native Claude runs.',
            nextStep: 'Turn on Telegram, Discord, and/or iMessage below.',
            blockers: ['Select at least one channel for auto-enable.'],
        };
    }
    const blockers = [];
    if (!environment.bunInstalled) {
        blockers.push('Install Bun to use Anthropic official channel plugins.');
    }
    if (environment.claudeVersion.state !== 'supported') {
        blockers.push(environment.claudeVersion.message);
    }
    if (environment.auth.state !== 'eligible') {
        blockers.push(environment.auth.message);
    }
    const selectedChannels = channels.filter((channel) => channel.selected);
    const missingTokenChannels = selectedChannels.filter((channel) => channel.requiresToken && !channel.tokenAvailable);
    if (missingTokenChannels.length > 0) {
        blockers.push(`Missing bot token for ${missingTokenChannels.map((channel) => channel.displayName).join(', ')}.`);
    }
    if (blockers.length > 0) {
        return {
            state: 'needs_setup',
            title: 'Needs setup before CCS can auto-add these channels',
            message: blockers[0] ?? 'Official Channels still need setup.',
            nextStep: 'Resolve the blockers below, then launch a supported native Claude session again.',
            blockers,
        };
    }
    const limitedNotes = [];
    const unavailableSelectedChannels = selectedChannels.filter((channel) => Boolean(channel.unavailableReason));
    if (unavailableSelectedChannels.length > 0) {
        limitedNotes.push(`${unavailableSelectedChannels.map((channel) => channel.displayName).join(', ')} cannot run on this machine.`);
    }
    if (selectedChannels.some((channel) => channel.id === 'imessage')) {
        limitedNotes.push('iMessage still needs Claude-side install plus local macOS permissions before it is dependable.');
    }
    if (limitedNotes.length > 0) {
        return {
            state: 'limited',
            title: 'Selected, but some channels still need manual setup',
            message: limitedNotes[0] ?? 'Some selected channels still need additional setup.',
            nextStep: 'Review the channel cards below before relying on this from a native Claude run.',
            blockers: limitedNotes,
        };
    }
    const selectedLabels = selectedChannels.map((channel) => channel.displayName).join(', ');
    const envOnlyChannels = selectedChannels.filter((channel) => channel.processEnvAvailable && !channel.savedInClaudeState);
    return {
        state: 'ready',
        title: 'Ready for the next native Claude run',
        message: envOnlyChannels.length === 0
            ? `CCS can auto-add ${selectedLabels} the next time you run \`ccs\` or a native Claude account profile.`
            : envOnlyChannels.length === selectedChannels.length
                ? `CCS can auto-add ${selectedLabels} on the next supported native Claude run from this same CCS process env.`
                : `CCS can auto-add ${selectedLabels} on the next supported native Claude run. ${envOnlyChannels.map((channel) => channel.displayName).join(', ')} currently depends on this same CCS process env.`,
        nextStep: envOnlyChannels.length === 0
            ? 'Claude-side pairing and access policy may still be required inside Claude, but CCS-side prerequisites are ready.'
            : envOnlyChannels.length === selectedChannels.length
                ? 'Run CCS from this same env, or save the token here first if you want persistent Claude channel state.'
                : 'Save env-only tokens here if you want persistent Claude channel state across shells.',
        blockers: [],
    };
}
exports.buildOfficialChannelsReadinessSummary = buildOfficialChannelsReadinessSummary;
function buildOfficialChannelsLaunchPreview(input) {
    const { config, environment, channels } = input;
    if (config.selected.length === 0) {
        return {
            state: 'disabled',
            title: 'Nothing will be auto-added yet',
            detail: 'Turn on at least one channel below before `ccs` can add official channel flags.',
            command: 'ccs',
            appendedArgs: [],
            appliedChannels: [],
            permissionBypassIncluded: false,
            skippedMessages: [],
        };
    }
    const channelReadiness = Object.fromEntries(channels.map((channel) => [
        channel.id,
        !channel.unavailableReason &&
            (channel.id === 'imessage' || !channel.requiresToken || channel.tokenAvailable),
    ]));
    const plan = resolveOfficialChannelsLaunchPlan({
        args: [],
        config,
        target: 'claude',
        profileType: 'default',
        environment,
        channelReadiness,
    });
    const appendedArgs = plan.applied
        ? buildOfficialChannelsArgs([], plan.appliedChannels, plan.wantsPermissionBypass)
        : [];
    if (!plan.applied) {
        return {
            state: 'blocked',
            title: 'Running `ccs` now will not auto-add channels',
            detail: plan.skippedMessages[0] ??
                'Official Channels are selected, but this machine is not ready to auto-add them yet.',
            command: 'ccs',
            appendedArgs: [],
            appliedChannels: [],
            permissionBypassIncluded: false,
            skippedMessages: plan.skippedMessages,
        };
    }
    const appliedLabels = plan.appliedChannels.map((channelId) => getOfficialChannelDisplayName(channelId));
    if (plan.skippedMessages.length > 0) {
        return {
            state: 'partial',
            title: `CCS will auto-add ${appliedLabels.join(', ')}`,
            detail: 'Some selected channels are still skipped. Review the notes below before relying on the rest.',
            command: 'ccs',
            appendedArgs,
            appliedChannels: plan.appliedChannels,
            permissionBypassIncluded: plan.wantsPermissionBypass,
            skippedMessages: plan.skippedMessages,
        };
    }
    return {
        state: 'ready',
        title: `CCS will auto-add ${appliedLabels.join(', ')}`,
        detail: plan.wantsPermissionBypass
            ? 'Running `ccs` will add the selected official channels and skip permission prompts for that launch.'
            : 'Running `ccs` will add the selected official channels automatically on this machine.',
        command: 'ccs',
        appendedArgs,
        appliedChannels: plan.appliedChannels,
        permissionBypassIncluded: plan.wantsPermissionBypass,
        skippedMessages: [],
    };
}
exports.buildOfficialChannelsLaunchPreview = buildOfficialChannelsLaunchPreview;
function expandOfficialChannelSelection(selection) {
    if (selection.trim().toLowerCase() === 'all') {
        return [...official_channels_ids_1.OFFICIAL_CHANNEL_IDS];
    }
    return (0, official_channels_ids_1.normalizeOfficialChannelIds)(selection
        .split(',')
        .map((value) => value.trim().toLowerCase())
        .filter(Boolean));
}
exports.expandOfficialChannelSelection = expandOfficialChannelSelection;
function getOfficialChannelChoices() {
    return official_channels_ids_1.OFFICIAL_CHANNEL_IDS.join(', ');
}
exports.getOfficialChannelChoices = getOfficialChannelChoices;
function isOfficialChannelSelectionValid(selection) {
    const parsed = selection
        .split(',')
        .map((value) => value.trim().toLowerCase())
        .filter(Boolean);
    return (parsed.length > 0 && parsed.every((value) => value === 'all' || (0, official_channels_ids_1.isOfficialChannelId)(value)));
}
exports.isOfficialChannelSelectionValid = isOfficialChannelSelectionValid;
function getOfficialChannelsSupportedProfiles() {
    return ['default', 'account'];
}
exports.getOfficialChannelsSupportedProfiles = getOfficialChannelsSupportedProfiles;
function getChannelConfigSelectionLabel(selected) {
    if (selected.length === 0) {
        return 'None';
    }
    return selected.map((channelId) => getOfficialChannelDisplayName(channelId)).join(', ');
}
exports.getChannelConfigSelectionLabel = getChannelConfigSelectionLabel;
function getTokenValueLabel(channelId) {
    return getOfficialChannelEnvKey(channelId) ?? '';
}
exports.getTokenValueLabel = getTokenValueLabel;
function isOfficialChannelTokenRequired(channelId) {
    return Boolean(getOfficialChannelEnvKey(channelId));
}
exports.isOfficialChannelTokenRequired = isOfficialChannelTokenRequired;
function getOfficialChannelDefaultTokenPlaceholder(channelId) {
    const envKey = getOfficialChannelEnvKey(channelId);
    return envKey ? `Paste ${envKey}` : '';
}
exports.getOfficialChannelDefaultTokenPlaceholder = getOfficialChannelDefaultTokenPlaceholder;
function getOfficialChannelConfiguredPlaceholder(channelId) {
    const envKey = getOfficialChannelEnvKey(channelId);
    return envKey ? `Configured. Enter a new ${envKey} to replace it.` : '';
}
exports.getOfficialChannelConfiguredPlaceholder = getOfficialChannelConfiguredPlaceholder;
function getOfficialChannelsSectionDescription() {
    return 'Auto-enable Anthropic official channels for compatible Claude sessions. CCS only stores selection in config.yaml; Claude keeps machine-level channel state under ~/.claude/channels/.';
}
exports.getOfficialChannelsSectionDescription = getOfficialChannelsSectionDescription;
function getOfficialChannelsRuntimeNote() {
    return 'CCS does not persist a global Claude channels default. It only injects runtime flags for the current Claude session when prerequisites are met.';
}
exports.getOfficialChannelsRuntimeNote = getOfficialChannelsRuntimeNote;
function getOfficialChannelsSetHelp() {
    return `Set selected channels with --set <csv>. Supported values: ${getOfficialChannelChoices()}, or all.`;
}
exports.getOfficialChannelsSetHelp = getOfficialChannelsSetHelp;
function getOfficialChannelsLegacyEnableHelp() {
    return 'Legacy aliases: --enable adds Discord, --disable removes Discord.';
}
exports.getOfficialChannelsLegacyEnableHelp = getOfficialChannelsLegacyEnableHelp;
function getOfficialChannelTokenHelp() {
    return 'Use --set-token <channel>=<token>. If no channel is provided, Discord is assumed for backward compatibility.';
}
exports.getOfficialChannelTokenHelp = getOfficialChannelTokenHelp;
function getOfficialChannelClearTokenHelp() {
    return 'Use --clear-token to clear all saved bot tokens, or --clear-token <channel> to clear one token.';
}
exports.getOfficialChannelClearTokenHelp = getOfficialChannelClearTokenHelp;
function getOfficialChannelMacOSHelp() {
    return 'iMessage needs macOS Full Disk Access plus the Messages automation prompt on first reply.';
}
exports.getOfficialChannelMacOSHelp = getOfficialChannelMacOSHelp;
function getOfficialChannelsDocsSummary() {
    return 'Supported official channels are Telegram, Discord, and iMessage.';
}
exports.getOfficialChannelsDocsSummary = getOfficialChannelsDocsSummary;
function getOfficialChannelSyncFailureMessage(channelId, targetPath) {
    return `${getOfficialChannelDisplayName(channelId)} auto-enable skipped: failed to sync channel env to ${targetPath}`;
}
exports.getOfficialChannelSyncFailureMessage = getOfficialChannelSyncFailureMessage;
function getOfficialChannelSyncSkipReason(channelId) {
    return `${getOfficialChannelDisplayName(channelId)} auto-enable skipped.`;
}
exports.getOfficialChannelSyncSkipReason = getOfficialChannelSyncSkipReason;
function getOfficialChannelsExplicitOverrideMessage() {
    return undefined;
}
exports.getOfficialChannelsExplicitOverrideMessage = getOfficialChannelsExplicitOverrideMessage;
function getOfficialChannelTokenMissingMessage(channelId) {
    const envKey = getOfficialChannelEnvKey(channelId);
    return envKey
        ? `${getOfficialChannelDisplayName(channelId)} auto-enable skipped because ${envKey} is not configured.`
        : `${getOfficialChannelDisplayName(channelId)} auto-enable skipped because it is not ready.`;
}
exports.getOfficialChannelTokenMissingMessage = getOfficialChannelTokenMissingMessage;
function getOfficialChannelsBunMissingMessage() {
    return 'Official Channels auto-enable skipped because Bun is not installed.';
}
exports.getOfficialChannelsBunMissingMessage = getOfficialChannelsBunMissingMessage;
function getOfficialChannelsCompatibilityMessage() {
    return 'Official Channels auto-enable only works for native Claude default/account sessions. It does not apply to `ccs glm`, other API/OAuth profiles, or Droid targets.';
}
exports.getOfficialChannelsCompatibilityMessage = getOfficialChannelsCompatibilityMessage;
function getOfficialChannelsNoSelectionMessage() {
    return 'No official channels selected.';
}
exports.getOfficialChannelsNoSelectionMessage = getOfficialChannelsNoSelectionMessage;
function getOfficialChannelsPermissionBypassMessage() {
    return '--dangerously-skip-permissions';
}
exports.getOfficialChannelsPermissionBypassMessage = getOfficialChannelsPermissionBypassMessage;
function getOfficialChannelsSelectionSummary(selected) {
    return selected.map((channelId) => getOfficialChannelDisplayName(channelId));
}
exports.getOfficialChannelsSelectionSummary = getOfficialChannelsSelectionSummary;
//# sourceMappingURL=official-channels-runtime.js.map