package com.iofferyoutea.WitchQueen

import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.Texture
import com.badlogic.gdx.graphics.g2d.BitmapFont
import com.badlogic.gdx.scenes.scene2d.ui.Button
import com.badlogic.gdx.scenes.scene2d.ui.Button.ButtonStyle
import com.badlogic.gdx.scenes.scene2d.ui.Container
import com.badlogic.gdx.scenes.scene2d.ui.HorizontalGroup
import com.badlogic.gdx.scenes.scene2d.ui.Image
import com.badlogic.gdx.scenes.scene2d.ui.Label
import com.badlogic.gdx.scenes.scene2d.ui.Table
import com.badlogic.gdx.scenes.scene2d.ui.VerticalGroup
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable
import ktx.assets.toInternalFile

class PlayerTableButton(val playerIconPath: String = "default.png", val newPlayerName: String = "PLAYER"):
    Table() {
    val playerIcon = Image(Texture(playerIconPath))
    val playerNameStyle = Label.LabelStyle(BitmapFont("default.fnt".toInternalFile()), Color.WHITE)
    val playerName = Label(newPlayerName, playerNameStyle)
    // Change preparedItems and kickButton into actual buttons
    var preparedItems: MutableList<Image> = mutableListOf( // We should use libGDX scene2d.ui List?
        Image(Texture("prepared-item-frame.png")),
        Image(Texture("prepared-item-frame.png")),
        Image(Texture("prepared-item-frame.png")),
        Image(Texture("prepared-item-frame.png"))
    )
    val preparedItemsGroup = HorizontalGroup().apply {
        for (item in preparedItems) addActor(item)
    }
    val kickButton = Image(Texture("red-x.png"))

    // Sub-table for Player/Items stack - Use VerticalGroup instead
//    val playerPlusItemsStack = Table().apply {
//        add(playerName)
//        row()
//        for (item in preparedItems) add(item)
//    }
    val playerLabelPlusItemsGroup = VerticalGroup().apply {
        addActor(playerName)
        addActor(preparedItemsGroup)
    }

    // Sub-table for the contents of the PlayerTableButton - Use HorizontalGroup instead
//    val subTable = Table().apply {
//        add(playerName, playerPlusItemsStack, kickButton)
//    }
    val componentCollection = HorizontalGroup().apply {
        addActor(playerIcon)
        addActor(playerLabelPlusItemsGroup)
        addActor(kickButton)
    }

    // Base Button stuff
    val buttonUp = TextureRegionDrawable(Texture("transparent.png"))
    val buttonDown = TextureRegionDrawable(Texture("transparent.png"))
    val buttonChecked = TextureRegionDrawable(Texture("transparent.png"))

    val buttonStyle = ButtonStyle().apply { up = buttonUp; down = buttonDown; checked = buttonChecked }

    val button = Button(componentCollection, buttonStyle)

    val container = Container<HorizontalGroup>(componentCollection)
}
