from flask import Blueprint, render_template, url_for
from jinja2 import Markup
from insignal.config.path import get_template_path, get_static_path

solutions_page = Blueprint('solutions', __name__, template_folder=get_template_path(),
                           static_folder=get_static_path(), url_prefix="/solutions")


@solutions_page.route("/")
@solutions_page.route("/android_smart_glass")
def android_smart_glass():
    return render_template("solutions/android_smart_glass.html", page_name="ANDROID SMART GLASS")


@solutions_page.route("/car_avn_rse")
def car_avn_rse():
    return render_template("solutions/car_avn_rse.html", page_name="CAR AVN/RSE")


@solutions_page.route("/hifi_loseless_audio")
def hifi_loseless_audio():
    return render_template("solutions/hifi_loseless_audio.html", page_name="HIFI LOSELESS AUDIO")


@solutions_page.route("/ai_speaker")
def ai_speaker():
    return render_template("solutions/ai_speaker.html", page_name="AI SPEAKER")


@solutions_page.route("/cloud_service")
def cloud_service():
    return render_template("solutions/cloud_service.html", page_name="CLOUD SERVICE")


@solutions_page.route("/ota_service")
def ota_service():
    return render_template("solutions/ota_service.html", page_name="OTA SERVICE")


@solutions_page.route("/isdb_t")
def isdb_t():
    return render_template("solutions/isdb_t.html", page_name="ISDB-T")


def get_sub_page_links():
    map_sub_page_links = (
        (url_for('solutions.ai_speaker'), "AI SPEAKER"),
        (url_for('solutions.cloud_service'), "CLOUD SERVICE"),
        (url_for('solutions.ota_service'), "OTA SERVICE"),
        (url_for('solutions.car_avn_rse'), "CAR AVN/RSE"),
        (url_for('solutions.hifi_loseless_audio'), "HIFI LOSELESS AUDIO"),
        (url_for('solutions.isdb_t'), "ISDB-T"),
        (url_for('solutions.android_smart_glass'), "ANDROID SMART GLASS"),
    )

    return Markup("\n".join(["<li><a href='{i[0]}'>{i[1]}</a></li>".format(i=item) for item in map_sub_page_links]))


@solutions_page.app_context_processor
def app_context_processor():
    return dict(page_links=get_sub_page_links)
