"""
Product Finder Blueprint
Handles the product quiz and recommendations
"""
from flask import Blueprint, render_template, send_from_directory
from blueprints.auth import login_required
import os

products_bp = Blueprint('products', __name__, url_prefix='/quiz')

# Get base directory
basedir = os.path.dirname(os.path.dirname(__file__))

@products_bp.route('/')
@login_required
def product_finder():
    """Serve the product finder quiz page"""
    return render_template('product_finder.html')

@products_bp.route('/index')
@login_required
def quiz_index():
    """Alternative route for product finder"""
    return render_template('product_finder.html')

@products_bp.route('/advanced-search')
@login_required
def advanced_search():
    """Serve the advanced search page"""
    return render_template('advanced_search.html')

@products_bp.route('/css/<path:filename>')
def serve_css(filename):
    """Serve CSS files"""
    return send_from_directory(os.path.join(basedir, 'static', 'css'), filename)

@products_bp.route('/js/<path:filename>')
def serve_js(filename):
    """Serve JavaScript files"""
    return send_from_directory(os.path.join(basedir, 'static', 'js'), filename)

@products_bp.route('/images/<path:filename>')
def serve_images(filename):
    """Serve image files"""
    return send_from_directory(os.path.join(basedir, 'static', 'images'), filename)

@products_bp.route('/data/<path:filename>')
def serve_data(filename):
    """Serve data files (JSON)"""
    return send_from_directory(os.path.join(basedir, 'data'), filename)
