"use strict";

const idlUtils = require("../generated/utils");
const util = require("util");
var plugins = {
	"0": {
		"0": {
			"description": "Portable Document Format",
			"suffixes": "pdf",
			"type": "application/pdf",
			"enabledPlugin": []
		},
		"1": {
			"description": "Portable Document Format",
			"suffixes": "pdf",
			"type": "text/pdf",
			"enabledPlugin": []
		},
		"application/pdf": {
			"description": "Portable Document Format",
			"suffixes": "pdf",
			"type": "application/pdf",
			"enabledPlugin": []
		},
		"text/pdf": {
			"description": "Portable Document Format",
			"suffixes": "pdf",
			"type": "text/pdf",
			"enabledPlugin": []
		},
		"description": "Portable Document Format",
		"filename": "internal-pdf-viewer",
		"length": 2,
		"name": "PDF Viewer"
	},
	"1": {
		"0": {
			"description": "Portable Document Format",
			"suffixes": "pdf",
			"type": "application/pdf",
			"enabledPlugin": []
		},
		"1": {
			"description": "Portable Document Format",
			"suffixes": "pdf",
			"type": "text/pdf",
			"enabledPlugin": []
		},
		"application/pdf": {
			"description": "Portable Document Format",
			"suffixes": "pdf",
			"type": "application/pdf",
			"enabledPlugin": []
		},
		"text/pdf": {
			"description": "Portable Document Format",
			"suffixes": "pdf",
			"type": "text/pdf",
			"enabledPlugin": []
		},
		"description": "Portable Document Format",
		"filename": "internal-pdf-viewer",
		"length": 2,
		"name": "Chrome PDF Viewer"
	},
	"2": {
		"0": {
			"description": "Portable Document Format",
			"suffixes": "pdf",
			"type": "application/pdf",
			"enabledPlugin": []
		},
		"1": {
			"description": "Portable Document Format",
			"suffixes": "pdf",
			"type": "text/pdf",
			"enabledPlugin": []
		},
		"application/pdf": {
			"description": "Portable Document Format",
			"suffixes": "pdf",
			"type": "application/pdf",
			"enabledPlugin": []
		},
		"text/pdf": {
			"description": "Portable Document Format",
			"suffixes": "pdf",
			"type": "text/pdf",
			"enabledPlugin": []
		},
		"description": "Portable Document Format",
		"filename": "internal-pdf-viewer",
		"length": 2,
		"name": "Chromium PDF Viewer"
	},
	"3": {
		"0": {
			"description": "Portable Document Format",
			"suffixes": "pdf",
			"type": "application/pdf",
			"enabledPlugin": []
		},
		"1": {
			"description": "Portable Document Format",
			"suffixes": "pdf",
			"type": "text/pdf",
			"enabledPlugin": []
		},
		"application/pdf": {
			"description": "Portable Document Format",
			"suffixes": "pdf",
			"type": "application/pdf",
			"enabledPlugin": []
		},
		"text/pdf": {
			"description": "Portable Document Format",
			"suffixes": "pdf",
			"type": "text/pdf",
			"enabledPlugin": []
		},
		"description": "Portable Document Format",
		"filename": "internal-pdf-viewer",
		"length": 2,
		"name": "Microsoft Edge PDF Viewer"
	},
	"4": {
		"0": {
			"description": "Portable Document Format",
			"suffixes": "pdf",
			"type": "application/pdf",
			"enabledPlugin": []
		},
		"1": {
			"description": "Portable Document Format",
			"suffixes": "pdf",
			"type": "text/pdf",
			"enabledPlugin": []
		},
		"application/pdf": {
			"description": "Portable Document Format",
			"suffixes": "pdf",
			"type": "application/pdf",
			"enabledPlugin": []
		},
		"text/pdf": {
			"description": "Portable Document Format",
			"suffixes": "pdf",
			"type": "text/pdf",
			"enabledPlugin": []
		},
		"description": "Portable Document Format",
		"filename": "internal-pdf-viewer",
		"length": 2,
		"name": "WebKit built-in PDF"
	}
}
var plggs = [];
for (let i = 0; i < 5; i++) {
	plggs.push(plugins[i])

}

function randomSort(a, b) { return Math.random() > 0.5 ? -1 : 1; }
plggs.sort(randomSort);
for (let i = 0; i < 5; i++) {
	plugins[i] = idlUtils.proxy( plggs[i], 'plgs.' + i)
}

let proxy = function (tt, name) {
    return new Proxy(tt, {
        get(target, p, receiver) {
            let res = Reflect.get(target, p, receiver);
            console.log(`${name} get`, p, typeof res)

            return res;
        }
    })
}
exports.implementation = class PluginArray {
    refresh() {
    }

    get length() {
        console.log('getPlugin length', Object.keys(window.ENV.plugins).length)

        return Object.keys(window.ENV.plugins).length;
    }

    item() {
        console.log('getPlugin idx', arguments[0])

		let plugins = window.ENV.plugins
		var plggs = [];
		for (let i = 0; i < 5; i++) {
			plggs.push(plugins[i])

		}
        return proxy( plggs[arguments[0]], 'plugins.'+arguments[0])
        // switch (arguments[0]){
        //   case 2:
        //     return {
        //       description:"Portable Document Format",
        //       filename:"internal-pdf-viewer",
        //       length:2,
        //       name:"Chromium PDF Viewer"
        //     }
        //   case 0:
        //     return {
        //       description:"Portable Document Format",
        //       filename:"internal-pdf-viewer",
        //       length:2,
        //       name:"PDF Viewer"
        //     }
        //   default:
        //     return {
        //       description:"Portable Document Format",
        //       filename:"internal-pdf-viewer",
        //       length:2,
        //       name:"PDF Viewer"
        //     }
        // }
        // return null;
    }

    namedItem() {
        console.log('namedItem', arguments)
        return null;
    }

    get [idlUtils.supportedPropertyIndices]() {
        return [];
    }
};
