use crate::ecs::text::components::TextProperties;
use crate::ecs::world::{Entity, Vec2, World};

use crate::prelude::*;
pub fn load_font_from_bytes(
    world: &mut World,
    font_data: Vec<u8>,
    font_size: f32,
) -> Result<usize, String> {
    world
        .resources
        .loading
        .pending_font_loads
        .push(PendingFontLoad {
            font_data,
            font_size,
        });
    Ok(0)
}

pub struct PendingFontLoad {
    pub font_data: Vec<u8>,
    pub font_size: f32,
}

pub fn spawn_ui_text(world: &mut World, text: impl Into<String>, _position: Vec2) -> Entity {
    let text_index = world.resources.text.cache.add_text(text);
    let entity = spawn_entities(world, crate::ecs::world::TEXT, 1)[0];

    world
        .core
        .set_text(entity, crate::ecs::text::components::Text::new(text_index));

    entity
}

pub fn spawn_ui_text_with_properties(
    world: &mut World,
    text: impl Into<String>,
    _position: Vec2,
    properties: TextProperties,
) -> Entity {
    let text_index = world.resources.text.cache.add_text(text);
    let entity = spawn_entities(world, crate::ecs::world::TEXT, 1)[0];

    let mut text_component = crate::ecs::text::components::Text::new(text_index);
    text_component.properties = properties;
    world.core.set_text(entity, text_component);

    entity
}
