#include "config.hpp"
#include <SDL.h>
#include <SDL_image.h>
#include <SDL_log.h>
#include <state.hpp>
#include <texture.hpp>

PhoenixTexture PLoadTexture(std::string filePath) {
  SDL_Log("Loading texture from path: %s", filePath.c_str());

  PhoenixTexture texture{};
  texture.texture = IMG_LoadTexture(state.renderer, filePath.c_str());

  if (texture.texture == NULL) {
    SDL_Log("Failed to load image: %s", SDL_GetError());
    abort();
  }

  return texture;
}

void PDestroyTexture(PhoenixTexture *texture) {
  SDL_DestroyTexture(texture->texture);
}

void PRenderTexture(PhoenixTexture *texture, int x, int y) {
  SDL_Rect dstRect{};
  dstRect.x = x;
  dstRect.y = y;
  dstRect.w = TEXTURE_WIDTH;
  dstRect.h = TEXTURE_HEIGHT;

  SDL_RenderCopy(state.renderer, texture->texture, NULL, &dstRect);
}
