import fitz
from calibre.customize import FileTypePlugin

def has_toc(pdf_path):
    doc = fitz.open(pdf_path)
    toc = doc.get_toc()
    return len(toc) > 0

class TOCMarkerPlugin(FileTypePlugin):
    name = 'TOC Marker'
    description = 'Označuje PDF súbory obsahujúce TOC v Calibre'
    supported_platforms = ['windows', 'osx', 'linux']
    file_types = {'pdf'}

    def process_book(self, book, options):
        pdf_path = book.format_path('pdf')
        if pdf_path and has_toc(pdf_path):
            book.set_metadata('toc_present', 'true')
