class Preloader extends Phaser.Scene {
    constructor() {
        super('Preloader');
    }

    init() {
        var barW = 400;
        var barH = 24;
        var barX = (800 - barW) / 2;
        var barY = 300;

        this.add.rectangle(400, 280, barW + 4, barH + 4).setStrokeStyle(2, 0xffffff);

        var bar = this.add.rectangle(barX + 2, barY, 4, barH - 4, 0x00ff9d).setOrigin(0, 0.5);

        this.add.text(400, 240, 'FSYS AGENT', {
            fontFamily: 'Arial Black',
            fontSize: '32px',
            color: '#00ff9d'
        }).setOrigin(0.5);

        this.add.text(400, 340, 'Loading...', {
            fontFamily: 'Arial',
            fontSize: '14px',
            color: '#b9cbbc'
        }).setOrigin(0.5);

        this.load.on('progress', function(progress) {
            bar.width = 4 + (barW - 4) * progress;
        });
    }

    preload() {
        // Player sprites — sci-fi agent
        this.load.image('player_idle', 'public/assets/sprites/character_agent_idle.png');
        this.load.image('player_walk_a', 'public/assets/sprites/character_agent_walk_a.png');
        this.load.image('player_walk_b', 'public/assets/sprites/character_agent_walk_b.png');
        this.load.image('player_jump', 'public/assets/sprites/character_agent_jump.png');
        this.load.image('player_hit', 'public/assets/sprites/character_agent_hit.png');

        // Card images — pre-scaled 56×76 thumbs for crisp rendering
        var cardNames = [
            '1-gift-of-water-action', '2-grow-greens-action', '3-fine-dining-compost-dish-action',
            '4-buzzing-with-wisdom-action', '5-baking-flatbread', '6-mixed-wastemonster-action',
            '7-ingredient-detective-action', '8-mindful-eating-action', '9-fermentastic-action',
            '10-tree-planter', '11-seed-scout', '12-natural-spritz',
            '13-dashboard-designer', '14-onion-bodyguard', '15-local-investor'
        ];

        for (var i = 0; i < cardNames.length; i++) {
            this.load.image('card_' + cardNames[i], 'public/images/cards/thumbs/' + cardNames[i] + '.png');
        }

        // Tile textures
        this.load.image('bush_tile', 'public/assets/tiles/bush.png');
        this.load.image('cloud_tile', 'public/images/cloud.png');

        // Jump pad sprite
        this.load.image('jump_pad', 'public/images/jump_pad.png');

        // Background
        this.load.image('bg_platform', 'public/images/fsys_platform_bg.png');

        // Sound effects
        this.load.audio('sfx_jump', 'public/assets/sounds/sfx_jump.ogg');
        this.load.audio('sfx_coin', 'public/assets/sounds/sfx_coin.ogg');
        this.load.audio('sfx_hurt', 'public/assets/sounds/sfx_hurt.ogg');
    }

    create() {
        this.scene.start('TitleScreen');
    }
}
