from calibre.constants import DEBUG, CONFIG_DIR_MODE, config_dir 
import json
import os

## for saving and loading fields
PLUGIN_PATH = os.path.join(config_dir, 'plugins')
FIELD_SAVE_PATH = PLUGIN_PATH + os.sep + "AI Custom Tag Extractor-Fields.json"

class UIState():
    
    def saveUIFields(fields):
        json_string = json.dumps(fields)
        try:
            with open(FIELD_SAVE_PATH, "w") as file:
                file.write(json_string)
            return True
        except Exception as e:
            return e
    
    def loadUIFields():
        try:
            with open(FIELD_SAVE_PATH, "r") as file:
                #fields = {line.rstrip() for line in file}        
                fields = json.load(file)
            return fields            
        except Exception as e:
            print(e)
            return e

