"""Routes generating PDFs for surveys."""
import os, io, routes.survey, tempfile
#import pdfkit
#from selenium import webdriver
#from selenium.webdriver.firefox.options import Options
from bottle import Bottle, route, response, request, abort

# Abandon hope all ye who enter here

pdf = Bottle()

"""logger = logging.getLogger('weasyprint')
logger.setLevel(0)"""

@pdf.route("/surveys/<name>/pdf")
def generate_pdf(name):
    """with tempfile.NamedTemporaryFile() as temp:
        url = "http://{}/surveys/{}".format(request.get_header("host"), name)
        options = Options()
        options.headless = True
        driver = webdriver.Firefox(options=options)
        driver.get(url)
        screenshot = driver.save_screenshot(temp.name)
        driver.quit()
        return io.BytesIO(temp.read())"""

    """# Output to object
    html_str = routes.survey.get_survey(name)
    with tempfile.NamedTemporaryFile() as temp:
        html = weasyprint.HTML(string=html_str)
        html.write_pdf(temp.name, stylesheets=[ weasyprint.CSS(filename="static/layout.css"), weasyprint.CSS(filename="static/survey.css") ])
        response.content_type = "application/pdf"
        return io.BytesIO(temp.read())"""


    """html = routes.survey.get_survey(name)
    output = pdfkit.from_string(html, b"", options={"enable-local-file-access": None})
    response.content_type = "application/pdf"
    return output"""

    """html = routes.survey.get_survey(name)
    with tempfile.NamedTemporaryFile(suffix=".pdf") as temp:
        result = pypandoc.convert_text(html, "pdf", format="html", outputfile=temp.name)
        response.content_type = "application/pdf"
        return io.BytesIO(temp.read())"""

    """url = "http://{}/surveys/{}".format(request.get_header("host"), name)
    output = pdfkit.from_url(url, b"")
    response.content_type = "application/pdf"
    return output"""

    abort(501)
