package me.devsaki.hentoid.parsers.content;

import org.jsoup.nodes.Element;

import java.util.List;

import me.devsaki.hentoid.database.domains.Content;
import me.devsaki.hentoid.enums.AttributeType;
import me.devsaki.hentoid.enums.Site;
import me.devsaki.hentoid.enums.StatusContent;
import me.devsaki.hentoid.parsers.ParseHelper;
import me.devsaki.hentoid.util.AttributeMap;
import pl.droidsonroids.jspoon.annotation.Selector;

public class HentaiCafeContent {
    @Selector(value = "div.x-main.full article", attr="id", defValue = "")
    private String galleryUrl;
    @Selector(value = "div.x-column.x-sm.x-1-2 img", attr="src")
    private String coverUrl;
    @Selector("div.x-column.x-sm.x-1-2.last h3")
    private String title;
    @Selector(value = "div.x-column.x-sm.x-1-2.last a[href*='/artist/']")
    private List<Element> artists;
    @Selector(value = "div.x-column.x-sm.x-1-2.last a[href*='/tag/']")
    private List<Element> tags;


    public Content toContent()
    {
        Content result = new Content();

        result.setSite(Site.HENTAICAFE);
        if (galleryUrl.isEmpty()) return result;

        result.setUrl(galleryUrl.replace("post-", "/?p="));
        result.setCoverImageUrl(coverUrl);
        result.setTitle(title);
        result.setQtyPages(-1);

        AttributeMap attributes = new AttributeMap();
        ParseHelper.parseAttributes(attributes, AttributeType.ARTIST, artists, true, Site.HENTAICAFE);
        ParseHelper.parseAttributes(attributes, AttributeType.TAG, tags, true, Site.HENTAICAFE);

        result.addAttributes(attributes);

        return result;
    }
}

@@ -236,55 +236,8 @@
 te;%0A
-import me.devsaki.hentoid.enums.StatusContent;%0A
 impo
@@ -463,17 +463,19 @@
 e%22, attr
-=
+ = 
 %22id%22, de
@@ -545,35 +545,29 @@
  = %22div.
-x-column.x-sm.x-1-2
+entry-content
  img%22, a
@@ -569,17 +569,19 @@
 g%22, attr
-=
+ = 
 %22src%22)%0A 
@@ -595,23 +595,24 @@
 ate 
-String
+Element
  cover
-Url
+Img
 ;%0A  
@@ -928,20 +928,16 @@
 ontent()
-%0A   
  %7B%0A     
@@ -1122,16 +1122,164 @@
 /?p=%22));
+%0A%0A        String coverUrl = coverImg.attr(%22src%22);%0A        if (coverUrl.isEmpty()) coverUrl = coverImg.attr(%22data-cfsrc%22); // Cloudflare-served image
 %0A       
@@ -1314,16 +1314,17 @@
 erUrl);%0A
+%0A
         

Fix cover not detected in HentaiCafe