import time
from itertools import cycle
from .utils import isWindows, isCmd, ColorUtils
from .gradients import Gradient, Gradients
from .loggers import Logs

class Animate:
    @staticmethod
    def Write(text: str, speed: float = 0.05):
        output = ""
        for char in text:
            print(char, end="", flush=True)
            output += char
            time.sleep(speed)
        print()
        return output

    @staticmethod
    def Column(text: str, speed: float = 0.05):
        lines = text.split("\n")
        max_len = max(len(line) for line in lines)
        padded_lines = [line.ljust(max_len) for line in lines]
        for col in range(max_len):
            for row in range(len(padded_lines)):
                print(padded_lines[row][col], end="")
            print()
            time.sleep(speed)
        return text

    @staticmethod
    def Row(text: str, speed: float = 0.05):
        lines = text.split("\n")
        for i in range(max(len(lines), max(len(line) for line in lines))):
            for line in lines:
                if i < len(line):
                    print(line[i], end="")
            print()
            time.sleep(speed)
        return text

    @staticmethod
    def LogWrite(logger: Logs, text: str, speed: float = 0.05):
        output = Animate.Write(text, speed)
        if logger:
            logger.Info(output)
        return output

    @staticmethod
    def LogColumn(logger: Logs, text: str, speed: float = 0.05):
        output = Animate.Column(text, speed)
        if logger:
            logger.Info(output)
        return output

    @staticmethod
    def LogRow(logger: Logs, text: str, speed: float = 0.05):
        output = Animate.Row(text, speed)
        if logger:
            logger.Info(output)
        return output
