import Popup from "../utils/Popup";
import Alert from "../utils/Alert";
import DialogMsgBox from "../utils/DialogMsgBox";
import CommonUtils from "../utils/CommonUtils";
import { MenuItemConfig } from "../ZhongIcon";
import IFrameCrimeHandler from "./IFrameCrimeHandler";
import loadGS from "../../func/module/loadGS";
import ClassName from "../../container/ClassName";
import { Injectable } from "../../container/Injectable";
import { Container } from "../../container/Container";

@ClassName('AdditionalSettingsHandler')
@Injectable()
export default class AdditionalSettingsHandler {

    constructor(
        private readonly commonUtils: CommonUtils,
    ) {
    }

    public show(): void {
        let pop = new Popup('', '更多设定');
        // let insertHtml = '<p><button class="torn-btn">清空设置</button></p><p><button class="torn-btn">通知权限</button></p><p><button class="torn-btn">外部数据权限</button></p>';
        // pop.getElement().insertAdjacentHTML('beforeend', insertHtml);
        // let [btn1, btn2, btn3] = Array.from(pop.getElement().querySelectorAll('button'));
        // btn1.addEventListener('click', () => {
        //     new DialogMsgBox('将清空所有芜湖助手相关设置并刷新页面，确定？', {
        //         callback: () => {
        //             localStorage.removeItem('wh_trv_alarm');
        //             localStorage.removeItem('wh_trans_settings');
        //             localStorage.removeItem('whuuid');
        //             localStorage.removeItem('wh-gs-storage');
        //             localStorage.removeItem('WHTEST');
        //             new Alert('已清空，刷新页面');
        //             window.location.reload();
        //         }
        //     });
        // });
        // btn2.addEventListener('click', () => {
        // });
        // btn3.addEventListener('click', () => {
        // });

        let menuList: MenuItemConfig[] = [
            {
                domType: 'button', domId: '', domText: '清空设置', clickFunc() {
                    new DialogMsgBox('将清空所有芜湖助手相关设置并刷新页面，确定？', {
                        callback: () => {
                            localStorage.removeItem('wh_trv_alarm');
                            localStorage.removeItem('wh_trans_settings');
                            localStorage.removeItem('whuuid');
                            localStorage.removeItem('wh-gs-storage');
                            localStorage.removeItem('WHTEST');
                            new Alert('已清空，刷新页面');
                            window.location.reload();
                        }
                    });
                }
            },
            {
                domType: "button", domId: '', domText: '通知权限', clickFunc() {
                }
            },
            {
                domType: 'button', domId: '', domText: '第三方API通信权限', clickFunc() {
                }
            },
            {
                domType: 'button', domId: '', domText: '小窗犯罪', clickFunc() {
                    Container.factory(IFrameCrimeHandler).handle()
                }
            },
            {
                domType: 'button',
                domId: '',
                domText: '飞贼小助手',
                tip: '加载从PC端移植的伞佬的油猴版飞贼小助手',
                clickFunc: () => {
                    loadGS(this.commonUtils.getScriptEngine())
                }
            },
        ];
        menuList.forEach(i => pop.element.append(this.commonUtils.elemGenerator(i, pop.element)));
    }
}
