import { extend } from './utils'
import Core from './core'

let singleton: Core = new Core({
    uiDesignWidth: window.innerWidth,
})

export const configComponents = (config: Component.config) => {
    if (config) {
        singleton = new Core(config)
    }
}

export function AnimatedSprite(animatedFrames: Layout.style['animatedFrames'], style: Layout.style = {}) {
    return singleton.createElement('AnimatedSprite', extend(style, {
        animatedFrames,
    }))
}

export function Sprite(image: Component.spriteImage, style: Layout.style = {}) {
    return singleton.createElement('Sprite', extend(style, {
        backgroundImage: image,
    }))
}

export function Container(style: Layout.style = {}) {
    return singleton.createElement('Container', style)
}

export function Rect(style: Layout.style = {}) {
    return singleton.createElement('Rect', style)
}

export function Text(content: string, style: Layout.style = {}) {
    return singleton.createElement('Text', extend(style, {
        content,
    }))
}

export function Circle(style: Layout.style = {}) {
    return singleton.createElement('Circle', style)
}
