from flask import Flask
from flask import Blueprint,render_template,request,url_for
from werkzeug.utils import redirect
import os
from chfi.models import Sensor
from datetime import datetime
#from smartfarm import app

bp = Blueprint('license', __name__, url_prefix='/license')

@bp.route('/',methods=["GET","POST"])
def	index():
	convert_result = ""
	active_tab = "home"	 # 기본값은	해시 탭
	
	if request.method == "POST":
		active_tab = request.form.get("active_tab",	"home")	 # 탭 정보	가져오기
		
		if active_tab == "home":
			input_text = request.form.get("inputText", "")
			if request.form.get("convert_select") == "encode":
				convert_result = input_text.encode("utf-8").hex()
			elif request.form.get("convert_select")	== "decode":
				try:
					convert_result = bytes.fromhex(input_text).decode("utf-8")
				except Exception:
					convert_result = "디지털포렌식전문가2급"
		elif active_tab	== "menu1":
			convert_result = "CHFI"

		elif active_tab	== "menu2":
			convert_result = "ENCE"

		elif active_tab	== "menu3":
			convert_result = "ACE"

	return render_template("license/index.html", convert_result=convert_result,	active_tab=active_tab)
	
	

