from flask import Blueprint, send_from_directory, request, render_template
import os
from configs import index_tags

react_bp = Blueprint('react_bp', __name__, static_folder=f'{os.getcwd()}/cdrm-frontend/dist', static_url_path='/',
                     template_folder=f'{os.getcwd()}/cdrm-frontend/dist')

@react_bp.route('/', methods=['GET'])
@react_bp.route('/<path:path>', methods=["GET"])
@react_bp.route('/<path>', methods=["GET"])
def index(path=''):
    if request.method == 'GET':
        if path != "" and os.path.exists(react_bp.static_folder + '/' + path):
            return send_from_directory(react_bp.static_folder, path)
        elif path.lower() == '':
            data = index_tags.tags['index']
            return render_template('index.html', data=data)
        elif path.lower() == 'cache':
            data = index_tags.tags['cache']
            return render_template('index.html', data=data)
        elif path.lower() == 'api':
            data = index_tags.tags['api']
            return render_template('index.html', data=data)
        elif path.lower() == 'testplayer':
            data = index_tags.tags['test_player']
            return render_template('index.html', data=data)
        else:
            return send_from_directory(react_bp.static_folder, 'index.html')
    else:
        return
