"""
The index.html file has been uploaded to 'danialcalayt' >
yta_resources > otros > web_resources > discord_message_image'
"""
from yta_web_resources import _WebResource
from yta_general_utils.url.dataclasses import UrlParameters, UrlParameter


class _AnimationWebResource(_WebResource):
    """
    *For internal use only*

    Web resource to create a simple animation with
    different consecutive frames.

    This is associated with the `web.animation.index.html`
    resource.
    """

    def get_animation(
        self,
        duration: 3,
        output_filename: str = 'animation.png'
    ) -> str:
        """
        Navigate to the web resource and obtain an Animation
        with the parameters provided, that will be stored with
        the `output_filename` filename provided.
        """
        fps = 10

        for i in range(int(duration * fps)):
            parameters = UrlParameters([
                UrlParameter('duration', duration),
                UrlParameter('frame', i)
            ])

            self._load(parameters)

            # The screenshot is taken respecting the alpha
            self.scraper.screenshot_element(
                element = self.scraper.find_element_by_id_waiting('container'),
                do_include_alpha = True,
                output_filename = output_filename.replace('.png', f'{str(i)}.png')
            )

        # ffmpeg -framerate 30 -i animation%01d.png -c:v libvpx-vp9 -pix_fmt yuva420p anim.webm

        """
        This code below is to transform all the frames to
        a video that has the transparency and its working
        correctly to be imported to a project.
        """
        # ffmpeg -framerate 30 -i animation%01d.png -c:v prores_ks -profile:v 4444 anim.mov

        return output_filename

# Instances to export here below
AnimationWebResource = lambda do_use_local_url = True, do_use_gui = False: _AnimationWebResource(
    local_path = 'src/yta_web_resources/web/animation/index.html',
    google_drive_direct_download_url = 'https://drive.google.com/file/d/1jf0RvU326_p7r3rXOT0REbd2jqESu445/view?usp=sharing',
    do_use_local_url = do_use_local_url,
    do_use_gui = do_use_gui
)