interface IItemSprite {
  key: string;
  stackQty?: number;
  texturePath: string;
  isStackable?: boolean;
}

export const getItemTextureKeyPath = (
  item: IItemSprite,
  atlasJSON: Record<string, any>
): string => {
  if (!item.texturePath) {
    return '';
  }

  const textureKey = item.texturePath
    .split('/')
    .pop()
    ?.split('.')[0];

  if (!textureKey) {
    return '';
  }

  const stackQty = item.stackQty || 1;
  const isStackable = item.isStackable || false;

  if (isStackable && stackQty > 1) {
    const stackKey = `${textureKey}-stack`;
    if (atlasJSON.frames[stackKey]) {
      return stackKey;
    }
  }

  return textureKey;
};
