"use strict";

const idlUtils = require("../generated/utils");
var plugins = {
    "0":
        {
            "description":"Portable Document Format",
            "filename": "internal-pdf-viewer",
            "length": 2,
            "name": "PDF Viewer",
            "text/pdf":{
                    "description":
                        "Portable Document Format", "suffixes":
                        "pdf", "type":
                        "text/pdf"
                },
            "application/pdf": {
                description: "Portable Document Format",
                enabledPlugin: [],
                suffixes: "pdf",
                type: "application/pdf",
            }
        }
    ,
    "1":
        {
            "description":
                "Portable Document Format", "filename":
                "internal-pdf-viewer", "length":
                2, "name":
                "Chrome PDF Viewer", "text/pdf":
                {
                    "description":
                        "Portable Document Format", "suffixes":
                        "pdf", "type":
                        "text/pdf"
                },
            "application/pdf": {
                description: "Portable Document Format",
                enabledPlugin: [],
                suffixes: "pdf",
                type: "application/pdf",
            }
        }
    ,
    "2":
        {
            "description":
                "Portable Document Format", "filename":
                "internal-pdf-viewer", "length":
                2, "name":
                "Chromium PDF Viewer", "text/pdf":
                {
                    "description":
                        "Portable Document Format", "suffixes":
                        "pdf", "type":
                        "text/pdf"
                },
            "application/pdf": {
                description: "Portable Document Format",
                enabledPlugin: [],
                suffixes: "pdf",
                type: "application/pdf",
            }
        }
    ,
    "3":
        {
            "description":
                "Portable Document Format", "filename":
                "internal-pdf-viewer", "length":
                2, "name":
                "Microsoft Edge PDF Viewer", "text/pdf":
                {
                    "description":
                        "Portable Document Format", "suffixes":
                        "pdf", "type":
                        "text/pdf"
                },
            "application/pdf": {
                description: "Portable Document Format",
                enabledPlugin: [],
                suffixes: "pdf",
                type: "application/pdf",
            }
        }
    ,
    "4":
        {
            "description":
                "Portable Document Format", "filename":
                "internal-pdf-viewer", "length":
                2, "name":
                "WebKit built-in PDF", "text/pdf":
                {
                    "description":
                        "Portable Document Format", "suffixes":
                        "pdf", "type":
                        "text/pdf"
                },
            "application/pdf": {
                description: "Portable Document Format",
                enabledPlugin: [],
                suffixes: "pdf",
                type: "application/pdf",
            }
        }
}
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)
            if (name.startsWith('plugins') && (p === '0' || p === '1')) {
                return  proxy({description: "Portable Document Format",
                enabledPlugin: [],
                suffixes: "pdf",
                type: "application/pdf",}, name + '.' + p)
            }
            return res;
        }
    })
}
exports.implementation = class PluginArray {
    refresh() {
    }

    get length() {
        return 5;
    }

    item() {
        console.log('getPlugin idx', arguments[0], plugins[arguments[0]])
        return proxy( plugins[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 [];
    }
};
