package de.oaa.xxx.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Serves /css/variables.css dynamically from application.properties theme settings.
 * All HTML pages load this first, so changing app.theme.* immediately updates the whole UI.
 */
@RestController
public class ThemeController {

    @Value("${app.theme.color-bg:#1a1a2e}")
    private String colorBg;

    @Value("${app.theme.color-card:#16213e}")
    private String colorCard;

    @Value("${app.theme.color-primary:#e94560}")
    private String colorPrimary;

    @Value("${app.theme.color-secondary:#0f3460}")
    private String colorSecondary;

    @Value("${app.theme.color-text:#eeeeee}")
    private String colorText;

    @Value("${app.theme.color-muted:#888888}")
    private String colorMuted;

    @Value("${app.theme.color-success:#2ecc71}")
    private String colorSuccess;

    /** Mobile breakpoint in px (unitless integer). Used by sidebar.js and lightbox layout. */
    @Value("${app.theme.breakpoint-mobile:768}")
    private int breakpointMobile;

    @GetMapping(value = "/css/variables.css", produces = "text/css")
    public String variables() {
        return """
                :root {
                    --color-bg: %s;
                    --color-card: %s;
                    --color-primary: %s;
                    --color-secondary: %s;
                    --color-text: %s;
                    --color-muted: %s;
                    --color-success: %s;
                    --breakpoint-mobile: %d;
                }
                """.formatted(colorBg, colorCard, colorPrimary, colorSecondary, colorText, colorMuted, colorSuccess, breakpointMobile);
    }
}
