"Contains the information required for sunbelt layout"

from services.company_profile.data_classes.company_info import CompanyInfo
from services.ppt_generator.data_classes.project import Project
from utils.download_image import DownloadImage


class BeginningSlides:
    "Beginning slides"

    def __init__(self, prs, content, project: Project):
        self.prs = prs
        self.title = project.company_name
        self.content = content

        self.company_logo = CompanyInfo.get_company_info(
            project.company_url
        ).logo.logo_url
        di = DownloadImage()
        logo, logo_path = di._get_image(
            self.company_logo, f"{project.company_name}_logo.png"
        )
        self.logo_path = logo_path

    def main(self):
        "Create the beginning slides"
        self.add_title_slide()
        self.add_disclaimer_slide()

    def add_title_slide(
        self,
    ):
        "Create the title slide"
        # add a title slid
        prs_slide = self.prs.slides.add_slide(self.prs.slide_layouts[0])

        # go through the placeholders and find the text and image placeholders
        for placeholder in prs_slide.placeholders:
            if placeholder.name == "Text Placeholder 2":
                placeholder.text = self.title
            if placeholder.name == "Picture Placeholder 1":
                placeholder.text = ""
                # add an image shape that is the size of the placeholder
                left = placeholder.left
                top = placeholder.top
                width = placeholder.width
                height = placeholder.height
                # add the image to the slide
                prs_slide.shapes.add_picture(
                    self.logo_path,
                    left,
                    top,
                    width,
                    height,
                )

                # remove the placeholder
                sp = placeholder._element
                sp.getparent().remove(sp)

    def add_disclaimer_slide(
        self,
    ):
        "Create the disclaimer slide"
        # add a title slid
        prs_slide = self.prs.slides.add_slide(self.prs.slide_layouts[1])

        # go through the placeholders and find the text and image placeholders
        for placeholder in prs_slide.placeholders:
            if placeholder.name == "Text Placeholder 3":
                placeholder.text = self.content


if __name__ == "__main__":
    import pptx

    PPT_TEMPLATE = r"ppt_templates/tequity_ppt_template.pptx"
    prs = pptx.Presentation(PPT_TEMPLATE)

    add_title_slide(
        prs, "Metal Supermarkets Atlanta", "images\Metal_Supermarkets_logo.png.jpg"
    )
    add_disclaimer_slide(
        prs,
        "This presentation is confidential and intended for the recipient only. Do not distribute without permission.",
    )
    prs.save("sunbelt_ppt.pptx")
