import { readFileSync, existsSync, readdirSync } from "fs";
import { join } from "path";
export async function parseBorderTokens(tokensPath) {
    const tokens = [];
    // Parse border tokens
    const borderPath = join(tokensPath, "properties", "border");
    if (existsSync(borderPath)) {
        const files = readdirSync(borderPath).filter((f) => f.endsWith(".json"));
        for (const file of files) {
            const filePath = join(borderPath, file);
            try {
                const content = readFileSync(filePath, "utf-8");
                const data = JSON.parse(content);
                const relativePath = `properties/border/${file}`;
                const borderData = data.border || data;
                for (const [sizeName, borderDef] of Object.entries(borderData)) {
                    if (typeof borderDef !== "object" || !("value" in borderDef))
                        continue;
                    const value = borderDef.value;
                    const numValue = typeof value === "number" ? value : parseFloat(String(value));
                    tokens.push({
                        category: "border",
                        subcategory: "width",
                        name: sizeName,
                        path: `border.${sizeName}`,
                        cssVariable: `--border-${sizeName}`,
                        scssVariable: `$border-${sizeName}`,
                        valueRaw: String(value),
                        valueNumber: numValue,
                        valueUnit: "px",
                        valueComputed: `${numValue}px`,
                        description: borderDef.description || `Border width ${sizeName}`,
                        platform: "all",
                        sourceFile: relativePath,
                    });
                }
            }
            catch (error) {
                console.warn(`Warning: Could not parse ${filePath}:`, error);
            }
        }
    }
    // Parse radius tokens
    const radiusPath = join(tokensPath, "properties", "radius");
    if (existsSync(radiusPath)) {
        const files = readdirSync(radiusPath).filter((f) => f.endsWith(".json"));
        for (const file of files) {
            const filePath = join(radiusPath, file);
            try {
                const content = readFileSync(filePath, "utf-8");
                const data = JSON.parse(content);
                const relativePath = `properties/radius/${file}`;
                const radiusData = data.radius || data;
                for (const [sizeName, radiusDef] of Object.entries(radiusData)) {
                    if (typeof radiusDef !== "object" || !("value" in radiusDef))
                        continue;
                    const value = radiusDef.value;
                    const numValue = typeof value === "number" ? value : parseFloat(String(value));
                    tokens.push({
                        category: "radius",
                        subcategory: undefined,
                        name: sizeName,
                        path: `radius.${sizeName}`,
                        cssVariable: `--radius-${sizeName}`,
                        scssVariable: `$radius-${sizeName}`,
                        valueRaw: String(value),
                        valueNumber: numValue,
                        valueUnit: "px",
                        valueComputed: `${numValue}px`,
                        description: radiusDef.description || `Border radius ${sizeName}`,
                        platform: "all",
                        sourceFile: relativePath,
                    });
                }
            }
            catch (error) {
                console.warn(`Warning: Could not parse ${filePath}:`, error);
            }
        }
    }
    return tokens;
}
//# sourceMappingURL=border-parser.js.map