import crypto from 'crypto'; // export function generatePaletteName(tones: Tone[]): string { // const hexString = tones.map(t => t.hex.toLowerCase()).join(''); // const hash = crypto.createHash('sha256').update(hexString).digest('hex'); // return `palette-${hash.slice(0, 8)}`; // } export function generateColorName(hex: string): string { const hash = crypto.createHash("sha256").update(hex.toLowerCase()).digest("hex"); return `color-${hash.slice(0, 8)}`; } // export function generateExtractColorName(hex: string, hue?: number, sat?: number, area?: number): string { // const data = `${hex.toLowerCase()}-${hue ?? 0}-${sat ?? 0}-${area ?? 0}`; // const hash = crypto.createHash("sha256").update(data).digest("hex"); // return `extract-${hash.slice(0, 8)}`; // } export function rgbToHex(rgb: number[]): string { return `#${rgb .map((val) => Math.round(val).toString(16).padStart(2, "0")) .join("")}`; } export function argbToHex(argb: number): string { return `#${argb.toString(16).slice(2).padStart(6, "0")}`; } // export function extractPaletteTones( // palette: TonalPalette, tones: number[] = [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100] // ) { // return tones.map((t) => ({ // tone: t, // hex: argbToHex(palette.tone(t)), // })); // } // export async function upsertPalettes(tones: Tone[], imageId: string, type: string) { // const paletteName = generatePaletteName(tones); // const existingPalette = await prisma.colorPalette.findFirst({ // where: { name: paletteName }, // include: { items: true }, // }); // // // const palette = existingPalette ?? await prisma.colorPalette.create({ // data: { // name: paletteName, // items: { // create: tones.map(tone => ({ // tone: tone.tone, // hex: tone.hex, // })) // } // } // }); // await prisma.imagePalette.upsert({ // where: { // imageId_type: { // imageId, // type, // } // }, // update: { // paletteId: palette.id // }, // create: { // imageId, // paletteId: palette.id, // type, // } // }); // // const newPalette = await prisma.colorPalette.create({ // // data: { // // name: paletteName, // // type: type, // // items: { // // create: tones.map(t => ({ // // tone: t.tone, // // hex: t.hex, // // })), // // }, // // images: { // // connect: { id: imageId }, // // }, // // }, // // include: { items: true }, // // }); // return palette; // }