package space.animefu.starfallhaven;

/** Platform-neutral responsive measurements for the landscape Canvas HUD. */
public final class HavenHudLayout {
    public final float scale,topBar,bottomBar;
    public final boolean compact;

    private HavenHudLayout(float scale,float topBar,float bottomBar,boolean compact){
        this.scale=scale;this.topBar=topBar;this.bottomBar=bottomBar;this.compact=compact;
    }

    public static HavenHudLayout calculate(int width,int height,int safeLeft,int safeTop,int safeRight,int safeBottom,float physicalDensity){
        int usableW=Math.max(1,width-safeLeft-safeRight),usableH=Math.max(1,height-safeTop-safeBottom);
        float viewport=Math.min(usableW/1080f,usableH/480f);
        boolean compact=usableH<620||usableW<1180;
        float scale=compact?clamp(viewport,.90f,1f):clamp(Math.min(Math.max(1f,physicalDensity),viewport),1f,1.25f);
        float top=(compact?54f:82f)*scale;
        float bottom=(compact?58f:86f)*scale;
        return new HavenHudLayout(scale,top,bottom,compact);
    }

    public float worldHeight(int totalHeight,int safeTop,int safeBottom){return totalHeight-safeTop-safeBottom-topBar-bottomBar;}
    private static float clamp(float value,float low,float high){return Math.max(low,Math.min(high,value));}
}
