package com.tiedup.remake.client.gui.util;

import com.tiedup.remake.v2.BodyRegionV2;

/**
 * Color constants for TiedUp! GUI elements.
 * All colors are in ARGB format (0xAARRGGBB).
 *
 */
public class GuiColors {

    // === Backgrounds ===
    public static final int BG_DARK = 0xFF1A1A1A; // #1A1A1A
    public static final int BG_MEDIUM = 0xFF2D2D2D; // #2D2D2D
    public static final int BG_LIGHT = 0xFF3D3D3D; // #3D3D3D

    // === Accents (leather/rope theme) ===
    public static final int ACCENT_BROWN = 0xFF8B4513; // #8B4513 SaddleBrown
    public static final int ACCENT_TAN = 0xFFCD853F; // #CD853F Peru
    public static final int ACCENT_ROPE = 0xFFD2691E; // #D2691E Chocolate

    // === Text ===
    public static final int TEXT_WHITE = 0xFFFFFFFF;
    public static final int TEXT_GRAY = 0xFFAAAAAA;
    public static final int TEXT_DISABLED = 0xFF666666;

    // === States ===
    public static final int SUCCESS = 0xFF4CAF50; // Green
    public static final int WARNING = 0xFFFF9800; // Orange
    public static final int ERROR = 0xFFF44336; // Red
    public static final int INFO = 0xFF2196F3; // Blue

    // === Borders ===
    public static final int BORDER_DARK = 0xFF0A0A0A;
    public static final int BORDER_LIGHT = 0xFF4A4A4A;

    // === Slot states ===
    public static final int SLOT_EMPTY = 0xFF555555;
    public static final int SLOT_FILLED = 0xFF666666;
    public static final int SLOT_HOVER = 0xFF777777;
    public static final int SLOT_SELECTED = 0xFF8B4513;

    // === Bondage Type Colors ===
    public static final int TYPE_BIND = 0xFF8B4513; // Brown (rope)
    public static final int TYPE_GAG = 0xFFFF6B6B; // Red
    public static final int TYPE_BLINDFOLD = 0xFF333333; // Dark gray
    public static final int TYPE_EARPLUGS = 0xFFFFD93D; // Yellow
    public static final int TYPE_COLLAR = 0xFF6BCB77; // Green
    public static final int TYPE_CLOTHES = 0xFF4D96FF; // Blue
    public static final int TYPE_MITTENS = 0xFFFF9F43; // Orange

    // === Action Hover Colors ===
    public static final int HOVER_REMOVE = 0xFF5D2020; // Dark red
    public static final int HOVER_LOCK = 0xFF5D4520; // Dark orange
    public static final int HOVER_UNLOCK = 0xFF205D20; // Dark green
    public static final int BUTTON_REMOVE = 0xFFCC4444;
    public static final int BUTTON_REMOVE_HOVER = 0xFFFF6B6B;

    /**
     * Get the color for a V2 body region.
     *
     * @param region The body region
     * @return The corresponding color
     */
    public static int getRegionColor(BodyRegionV2 region) {
        return switch (region) {
            case HEAD -> 0xFF9C27B0; // Purple
            case EYES -> TYPE_BLINDFOLD;
            case EARS -> TYPE_EARPLUGS;
            case MOUTH -> TYPE_GAG;
            case NECK -> TYPE_COLLAR;
            case TORSO -> TYPE_CLOTHES;
            case ARMS -> TYPE_BIND;
            case HANDS -> TYPE_MITTENS;
            case FINGERS -> 0xFFFFAB91; // Light orange
            case WAIST -> 0xFF795548; // Brown
            case LEGS -> 0xFF607D8B; // Blue-gray
            case FEET -> 0xFF78909C; // Light blue-gray
            case TAIL -> 0xFFCE93D8; // Light purple
            case WINGS -> 0xFF80DEEA; // Light cyan
        };
    }

    /**
     * Get the color for a bondage item type.
     *
     * @param type The bondage item type name (lowercase)
     * @return The corresponding color
     */
    public static int getTypeColor(String type) {
        return switch (type.toLowerCase()) {
            case "bind" -> TYPE_BIND;
            case "gag" -> TYPE_GAG;
            case "blindfold" -> TYPE_BLINDFOLD;
            case "earplugs" -> TYPE_EARPLUGS;
            case "collar" -> TYPE_COLLAR;
            case "clothes" -> TYPE_CLOTHES;
            case "mittens" -> TYPE_MITTENS;
            default -> TEXT_WHITE;
        };
    }

    /**
     * Create a color with custom alpha.
     *
     * @param color Base color (ARGB)
     * @param alpha Alpha value (0-255)
     * @return Color with new alpha
     */
    public static int withAlpha(int color, int alpha) {
        return (color & 0x00FFFFFF) | (alpha << 24);
    }

    /**
     * Lighten a color by a factor.
     *
     * @param color Base color (ARGB)
     * @param factor Factor (0.0 = no change, 1.0 = white)
     * @return Lightened color
     */
    public static int lighten(int color, float factor) {
        int a = (color >> 24) & 0xFF;
        int r = (color >> 16) & 0xFF;
        int g = (color >> 8) & 0xFF;
        int b = color & 0xFF;

        r = (int) (r + (255 - r) * factor);
        g = (int) (g + (255 - g) * factor);
        b = (int) (b + (255 - b) * factor);

        return (a << 24) | (r << 16) | (g << 8) | b;
    }

    /**
     * Darken a color by a factor.
     *
     * @param color Base color (ARGB)
     * @param factor Factor (0.0 = no change, 1.0 = black)
     * @return Darkened color
     */
    public static int darken(int color, float factor) {
        int a = (color >> 24) & 0xFF;
        int r = (color >> 16) & 0xFF;
        int g = (color >> 8) & 0xFF;
        int b = color & 0xFF;

        r = (int) (r * (1 - factor));
        g = (int) (g * (1 - factor));
        b = (int) (b * (1 - factor));

        return (a << 24) | (r << 16) | (g << 8) | b;
    }
}
