from ._abstract import AbstractScraper
from ._utils import get_minutes, normalize_string

class TheSpruceEats(AbstractScraper):
    @classmethod
    def host(cls):
        return "thespruceeats.com"

    def title(self):
        return self.soup.find("h1", {"class": "heading__title"}).get_text()

    def total_time(self):
        return get_minutes(
            self.soup.find("span", text="Total: ").find_next_sibling(
                "span", {"class": "meta-text__data"}
            )
        )

    def yields(self):
        return (
            self.soup.find("span", text="Servings: ")
            .find_next_sibling("span", {"class": "meta-text__data"})
            .get_text()
        )

    def image(self):
        image = self.soup.find("img", {"class": "primary-image"})
        return image["src"] if image else None

    def ingredients(self):
        #ingredients = self.soup.findAll("li", {"class": "ingredient"})
        ingredients = self.soup.find("section", {"class": "comp section--fixed-width section--ingredients section"}).find_all(
            "li", {"class": "structured-ingredients__list-item"}
        )
        return [normalize_string(ingredient.get_text()) for ingredient in ingredients]

    def instructions(self):
        instructions = self.soup.find(
            "ol", {"class": "comp mntl-sc-block-group--OL mntl-sc-block mntl-sc-block-startgroup"}
        ).findAll("li")
        return "\n".join(
            [
                normalize_string(instruction.find("p").get_text())
                for instruction in instructions
            ]
        )

@@ -1250,16 +1250,23 @@
         
+nested_
 instruct
@@ -1291,131 +1291,224 @@
 ind(
-%0A            %22ol%22, %7B%22class%22: %22comp mntl-sc-block-group--OL mntl-sc-block mntl-sc-block-startgroup%22%7D%0A        )
+%22section%22, %7B%22class%22: %22section--instructions%22%7D).find_all(%22ol%22)%0A%0A        instructions = %5B%5D%0A        for each_instruction in nested_instructions:%0A            instructions = instructions + (each_instruction
 .find
-A
+_a
 ll(%22li%22)
 %0A   
@@ -1503,16 +1503,26 @@
 ll(%22li%22)
+)%0A        
 %0A       

handle nested recipe instructions for TheSpruceEats