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

import net.minecraft.util.Mth;

/**
 * Centralized layout constants for all TiedUp! GUI screens and widgets.
 * Provides standard spacing and responsive calculation utilities.
 *
 * Refactored for Responsive Design.
 */
public final class GuiLayoutConstants {

    private GuiLayoutConstants() {} // No instantiation

    // ==================== MARGINS & PADDING ====================

    public static final int MARGIN_XS = 2;
    public static final int MARGIN_S = 4;
    public static final int MARGIN_M = 8;
    public static final int MARGIN_L = 16;
    public static final int SCREEN_EDGE_MARGIN = 10;

    public static final int LINE_HEIGHT = 10;
    public static final int TITLE_HEIGHT = 20;

    // ==================== WIDGET DIMENSIONS ====================

    public static final int BUTTON_HEIGHT = 20;
    public static final int BUTTON_WIDTH_S = 40;
    public static final int BUTTON_WIDTH_M = 80;
    public static final int BUTTON_WIDTH_L = 120;
    public static final int BUTTON_WIDTH_XL = 160;

    public static final int SLOT_SIZE = 24; // Standard square slot
    public static final int SLOT_HEIGHT = 24;
    public static final int SLOT_SPACING = 3;
    public static final int ICON_SIZE = 16;

    public static final int SCROLLBAR_WIDTH = 6;

    // ==================== STATUS ICONS ====================

    public static final int STATUS_ICON_SIZE = 14;
    public static final int STATUS_ICON_SPACING = 4;

    // ==================== ENTRY/LIST DIMENSIONS ====================

    public static final int ENTRY_HEIGHT = 65;
    public static final int ENTRY_SPACING = 4;

    // ==================== PREVIEW SIZES ====================

    public static final int PREVIEW_WIDTH_S = 50;
    public static final int PREVIEW_WIDTH_M = 100;
    public static final int PREVIEW_WIDTH_L = 120;
    public static final int PREVIEW_HEIGHT = 160;

    // Slider specific dimensions
    public static final int SLIDER_THUMB_WIDTH = 8;
    public static final int SLIDER_THUMB_HEIGHT = 20;
    public static final int SLIDER_TRACK_WIDTH = 4;

    // ==================== LAYOUT HELPERS ====================

    /**
     * Calculates a responsive width constrained by min/max values.
     * @param screenWidth The current screen width
     * @param percentTarget Target percentage of screen width (0.0 - 1.0)
     * @param minWidth Minimum pixel width
     * @param maxWidth Maximum pixel width
     * @return Calculated width
     */
    public static int getResponsiveWidth(
        int screenWidth,
        float percentTarget,
        int minWidth,
        int maxWidth
    ) {
        int target = (int) (screenWidth * percentTarget);
        int available = screenWidth - (SCREEN_EDGE_MARGIN * 2);
        return Mth.clamp(target, minWidth, Math.min(maxWidth, available));
    }

    /**
     * Calculates a responsive height constrained by min/max values.
     * @param screenHeight The current screen height
     * @param percentTarget Target percentage of screen height (0.0 - 1.0)
     * @param minHeight Minimum pixel height
     * @param maxHeight Maximum pixel height
     * @return Calculated height
     */
    public static int getResponsiveHeight(
        int screenHeight,
        float percentTarget,
        int minHeight,
        int maxHeight
    ) {
        int target = (int) (screenHeight * percentTarget);
        int available = screenHeight - (SCREEN_EDGE_MARGIN * 2);
        return Mth.clamp(target, minHeight, Math.min(maxHeight, available));
    }

    /**
     * Centers an element coordinate X.
     */
    public static int centerX(int containerWidth, int elementWidth) {
        return (containerWidth - elementWidth) / 2;
    }

    /**
     * Centers an element coordinate Y.
     */
    public static int centerY(int containerHeight, int elementHeight) {
        return (containerHeight - elementHeight) / 2;
    }
}
