"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.standardizationRules = void 0;
const TidyService_1 = require("../../services/TidyService");
exports.standardizationRules = [
    {
        id: "standardization/design-debt",
        name: "Standardization Debt",
        description: "Detects hardcoded design tokens (colors) and literal strings that should be constants.",
        category: "nextjs",
        severity: "warning",
        help: "Run 'mycontext tidy' to interactive audit and refactor hardcoded literals into semantic design tokens and constants.",
        appliesTo: ["nextjs", "node", "turbo"],
        async check(context) {
            const diagnostics = [];
            const tidyService = new TidyService_1.TidyService(context.root);
            try {
                await tidyService.initialize();
                // Audit core directories
                const suggestions = await tidyService.audit(["src", "app", "components", "lib"]);
                if (suggestions.length > 0) {
                    const colorDebt = suggestions.filter(s => s.type === "token" || s.type === "new_token").length;
                    const tailwindDebt = suggestions.filter(s => s.type === "tailwind_semantic").length;
                    const stringDebt = suggestions.filter(s => s.type === "constant").length;
                    if (colorDebt > 0) {
                        diagnostics.push({
                            ruleId: "standardization/design-debt",
                            filePath: "Project Wide",
                            severity: "warning",
                            message: `Found ${colorDebt} hardcoded color literals.`,
                            help: "Run 'mycontext tidy --tokens' to replace literals with theme variables.",
                            autoFixable: true
                        });
                    }
                    if (tailwindDebt > 0) {
                        diagnostics.push({
                            ruleId: "standardization/design-debt",
                            filePath: "Project Wide",
                            severity: "warning",
                            message: `Found ${tailwindDebt} default Tailwind palette classes that can use semantic theme utilities.`,
                            help: "Run 'mycontext tidy' (with --semantic-tailwind) to map classes like bg-white to theme tokens.",
                            autoFixable: true
                        });
                    }
                    if (stringDebt > 0) {
                        diagnostics.push({
                            ruleId: "standardization/design-debt",
                            filePath: "Project Wide",
                            severity: "warning",
                            message: `Found ${stringDebt} repeated string literals matching constants.`,
                            help: "Run 'mycontext tidy --constants' to standardize string usage.",
                            autoFixable: true
                        });
                    }
                }
            }
            catch (e) {
                // Silently fail if audit fails during doctor
            }
            return diagnostics;
        },
        async fix(context, diag) {
            const tidyService = new TidyService_1.TidyService(context.root);
            try {
                await tidyService.initialize();
                const suggestions = await tidyService.audit(["src", "app", "components", "lib"]);
                // Only fix high-confidence non-ambiguous suggestions automatically
                const fixable = suggestions.filter(s => s.confidence >= 0.9 && !s.ambiguousCandidates);
                let fixedCount = 0;
                for (const s of fixable) {
                    const applied = await tidyService.applySuggestion(s);
                    if (applied)
                        fixedCount++;
                }
                return fixedCount > 0;
            }
            catch {
                return false;
            }
        }
    }
];
//# sourceMappingURL=standardization-rules.js.map