//
//  PrefsUtil.swift
//  AppBuilder
//
//  Created by Kevin Maulana on 23/03/22.
//

import Foundation


class PrefsUtil {
    static let CPAAS_MODE_FLOATING = 0
    static let CPAAS_MODE_DOCKED = 1
    static let CPAAS_MODE_BURGER = 2
    static let CPAAS_MODE_MIX = 4
    static let DEFAULT_CPAAS_MODE = CPAAS_MODE_DOCKED
    
    static func getCpaasMode() -> Int {
        let mode = UserDefaults.standard.integer(forKey: "cpaas_mode")
        if(mode != 0) {
            return mode - 1
        }
        return PrefsUtil.DEFAULT_CPAAS_MODE
    }
    
    static func setCpaasMode(mode: Int){
        UserDefaults.standard.set(mode+1, forKey: "cpaas_mode")
    }
    
    static var CUSTOM_TAB = "1,2,3,4"
    
    static func getCustomTab() -> String {
        if let cust = UserDefaults.standard.string(forKey: "custom_tab"){
            if(!cust.isEmpty){
                return cust
            }
        }
        return PrefsUtil.CUSTOM_TAB
    }
    
    static func setCustomTab(cust: String){
        UserDefaults.standard.set(cust, forKey: "custom_tab")
    }
    
    static func getURLFirstTab() -> String? {
        return UserDefaults.standard.string(forKey: "app_builder_url_first_tab")
    }
    
    static func getURLThirdTab() -> String? {
        return UserDefaults.standard.string(forKey: "app_builder_url_third_tab")
    }
    static func getURLBase() -> String {
        return UserDefaults.standard.string(forKey: "app_builder_url_base") ?? "https://newuniverse.io/"
    }
    static func getURLQMS() -> String? {
        return UserDefaults.standard.string(forKey: "app_builder_url_qms")
    }
    static func getIconDock() -> String? {
        return UserDefaults.standard.string(forKey: "app_builder_icon_dock")
    }
    static func getIconSS() -> String? {
        return UserDefaults.standard.string(forKey: "app_builder_icon_ss")
    }
    static func getBackground() -> String? {
        return UserDefaults.standard.string(forKey: "app_builder_background")
    }
    static func getUrlSS() -> String? {
        return PrefsUtil.getURLBase() + "dashboardv2/uploads/splashscreen/" + PrefsUtil.getIconSS()!
    }
    static func getUrlDock() -> String? {
        return PrefsUtil.getURLBase() + "dashboardv2/uploads/fb_icon/" + PrefsUtil.getIconDock()!
    }
    
    static func setURLFirstTab(value: String) {
        UserDefaults.standard.set(value, forKey: "app_builder_url_first_tab")
    }
    
    static func setURLThirdTab(value: String) {
        UserDefaults.standard.set(value, forKey: "app_builder_url_third_tab")
    }
    static func setURLBase(value: String) {
        UserDefaults.standard.set(value, forKey: "app_builder_url_base")
    }
    static func setURLQMS(value: String) {
        UserDefaults.standard.set(value, forKey: "app_builder_url_qms")
    }
    static func setIconDock(value: String) {
        UserDefaults.standard.set(value, forKey: "app_builder_icon_dock")
    }
    static func setIconSS(value: String) {
        UserDefaults.standard.set(value, forKey: "app_builder_icon_ss")
    }
    static func setBackground(value: String) {
        UserDefaults.standard.set(value, forKey: "app_builder_background")
    }
    static func getTerms() -> Bool {
        return UserDefaults.standard.bool(forKey: "terms_app")
    }
    
    static func setTerms(value: Bool){
        UserDefaults.standard.set(value, forKey: "terms_app")
    }
    
    static func getURLPrivacyPolicy() -> String {
        return UserDefaults.standard.string(forKey: "app_builder_url_privacy_policy") ?? "https://newuniverse.io/privacypolicy"
    }
    
    static func setURLPrivacyPolicy(value: String){
        UserDefaults.standard.set(value, forKey: "app_builder_url_privacy_policy")
    }
    
    static func getEnablePrivacyPolicy() -> Bool {
        return UserDefaults.standard.bool(forKey: "app_builder_enable_privacy_policy")
    }
    
    static func setEnablePrivacyPolicy(value: Bool){
        UserDefaults.standard.set(value, forKey: "app_builder_enable_privacy_policy")
    }
    
    static func getAgreePrivacyPolicy() -> Bool {
        return UserDefaults.standard.bool(forKey: "agree_privacy_policy")
    }
    
    static func setAgreePrivacyPolicy(value: Bool){
        UserDefaults.standard.set(value, forKey: "agree_privacy_policy")
    }
    
}
//public static String getHeaderColorSetting(Context pContext) {
//        final SharedPreferences sharedPref = pContext.getSharedPreferences("PREF_SYS", Context.MODE_PRIVATE);
//        String header_color = sharedPref.getString("header_color", "#00000000");
//        return header_color;
//    }
//
//    public static String getHeaderTextColorSetting(Context pContext) {
//        final SharedPreferences sharedPref = pContext.getSharedPreferences("PREF_SYS", Context.MODE_PRIVATE);
//        String header_text_color = sharedPref.getString("header_text_color", "#FF000000");
//        return header_text_color;
//    }
//
//    public static void setContentFilter(Context pContext, String new_value) {
//        final SharedPreferences sharedPref = pContext.getSharedPreferences("PREF_SYS", Context.MODE_PRIVATE);
//        SharedPreferences.Editor edit = sharedPref.edit();
//        edit.putString("content_filter",new_value);
//        edit.apply();
//    }
//
//    public static String getContentFilter(Context pContext) {
//        final SharedPreferences sharedPref = pContext.getSharedPreferences("PREF_SYS", Context.MODE_PRIVATE);
//        String header_text_color = sharedPref.getString("content_filter", "1,2,3,4,5");
//        return header_text_color;
//    }
//
//    public static void setContentSort(Context pContext, int new_value) {
//        final SharedPreferences sharedPref = pContext.getSharedPreferences("PREF_SYS", Context.MODE_PRIVATE);
//        SharedPreferences.Editor edit = sharedPref.edit();
//        edit.putInt("content_sort",new_value);
//        edit.apply();
//    }
//
//    public static int getContentSort(Context pContext) {
//        final SharedPreferences sharedPref = pContext.getSharedPreferences("PREF_SYS", Context.MODE_PRIVATE);
//        int header_text_color = sharedPref.getInt("content_sort", 1);
//        return header_text_color;
//    }
//
//    public static void setContentClassification(Context pContext, String new_value) {
//        final SharedPreferences sharedPref = pContext.getSharedPreferences("PREF_SYS", Context.MODE_PRIVATE);
//        SharedPreferences.Editor edit = sharedPref.edit();
//        edit.putString("content_class",new_value);
//        edit.apply();
//    }
//
//    public static String getContentClassification(Context pContext) {
//        final SharedPreferences sharedPref = pContext.getSharedPreferences("PREF_SYS", Context.MODE_PRIVATE);
//        String header_text_color = sharedPref.getString("content_class", "1,2,3,4");
//        return header_text_color;
//    }
//
//    public static final int CPAAS_MODE_FLOATING = 0;
//    public static final int CPAAS_MODE_DOCKED = 1;
//    public static final int CPAAS_MODE_BURGER = 2;
//    public static final int CPAAS_MODE_MIX = 4;
//    public static final int DEFAULT_CPAAS_MODE = CPAAS_MODE_DOCKED;
//    public static int getCpaasMode(Context pContext) {
//        final SharedPreferences sharedPref = pContext.getSharedPreferences("PREF_SYS", Context.MODE_PRIVATE);
//        int mode_index = sharedPref.getInt("cpaas_mode", DEFAULT_CPAAS_MODE);
//        return mode_index;
//    }
//
//    public static void setCpaasMode(Context pContext, int new_value) {
//        final SharedPreferences sharedPref = pContext.getSharedPreferences("PREF_SYS", Context.MODE_PRIVATE);
//        SharedPreferences.Editor edit = sharedPref.edit();
//        edit.putInt("cpaas_mode",new_value);
//        edit.apply();
//    }
//
//    public static final int CPAAS_FLOAT_MODE_IN_APP = 3;
//    public static final int CPAAS_FLOAT_MODE_OUT_APP = 4;
//    public static int getCpaasFloatMode(Context pContext) {
//        final SharedPreferences sharedPref = pContext.getSharedPreferences("PREF_SYS", Context.MODE_PRIVATE);
//        int mode_index = sharedPref.getInt("cpaas_float_mode", CPAAS_FLOAT_MODE_IN_APP);
//        return mode_index;
//    }
//    public static void setCpaasFloatMode(Context pContext, int new_value) {
//        final SharedPreferences sharedPref = pContext.getSharedPreferences("PREF_SYS", Context.MODE_PRIVATE);
//        SharedPreferences.Editor edit = sharedPref.edit();
//        edit.putInt("cpaas_float_mode",new_value);
//        edit.apply();
//    }
//
//    public static String getURLFirstTab() {
//        return CoreDataSqlite_PrefsDB.get("app_builder_url_first_tab", "");
//    }
//
//    public static String getURLThirdTab() {
//        return  CoreDataSqlite_PrefsDB.get("app_builder_url_third_tab", "");
//    }
//
//    public static String getURLBase() {
//        return  CoreDataSqlite_PrefsDB.get("app_builder_url_base", Util_RandomCrypt.decrypt("3<rl;duhpt<<=vswwk"));
//    }
//
//    public static void setURLFirstTab(String new_value) {
//        CoreDataSqlite_PrefsDB.put("app_builder_url_first_tab", new_value);
//    }
//
//    public static void setURLThirdTab(String new_value) {
//        CoreDataSqlite_PrefsDB.put("app_builder_url_third_tab", new_value);
//    }
//
//    public static void setURLBase(String new_value) {
//        CoreDataSqlite_PrefsDB.put("app_builder_url_base", new_value);
//    }
//
//    public static String DEFAULT_TAB_AMOUNT = "4";
//
//    public static String getTabAmount(){
//        return CoreDataSqlite_PrefsDB.get("app_builder_tab_amount", DEFAULT_TAB_AMOUNT);
//    }
//
//    public static void setTabAmount(Context pContext, String new_value){
//        CoreDataSqlite_PrefsDB.put("app_builder_tab_amount", new_value);
//    }
