"use strict";
// import * as edge from 'edge-js';
exports.__esModule = true;
// let designerReport = edge.func({
//     assemblyFile: 'lib/GetEasy.Node.Printer.dll',
//     typeName: 'GetEasy.Node.Printer.NodeReportDesigner',
//     methodName: 'DesignerReport'
// });
// designerReport('', true);
var ffi = require("ffi");
var os = require("os");
var fs = require("fs");
var path = require("path");
var cpu = os.arch() === 'x64' ? '64' : '86';
var dllName = 'GetEasy.Node.Printer.' + cpu + '.dll';
var execDir = path.dirname(process.execPath);
var dllPath = path.join(execDir, dllName);
if (!fs.existsSync(dllPath)) {
    dllPath = path.join(__dirname, 'dll', dllName);
}
var dll = ffi.Library(dllPath, {
    designerReport: ['void', ['string', 'string', 'pointer']],
    reportShowPreview: ['void', ['string', 'string']],
    reportPrinter: ['void', ['string', 'string']]
});
var ReportApi = /** @class */ (function () {
    function ReportApi() {
    }
    /**
     *设计模板
     *
     * @param {string} fileName 模板
     * @param {string} tempData 临时演示数据
     * @memberof ReportApi
     */
    ReportApi.designerReport = function (template, tempData, saveCallback) {
        var callbackPointer = ffi.Callback('void', ['string', 'pointer'], function (data, func) {
            var nativeCallback = ffi.ForeignFunction(func, 'void', ['bool']);
            try {
                saveCallback(data, function (result) {
                    if (result) {
                        nativeCallback(true);
                    }
                    else {
                        nativeCallback(false);
                    }
                });
            }
            catch (e) {
                console.error(e);
                nativeCallback(false);
            }
        });
        dll.designerReport(template, tempData, callbackPointer);
    };
    /**
     *打印预览
     *
     * @param {string} fileName 模板路径
     * @param {string} jsonData 数据
     * @memberof ReportApi
     */
    ReportApi.reportShowPreview = function (fileName, jsonData) {
        dll.reportShowPreview(fileName, jsonData);
    };
    /**
     *打印
     *
     * @param {string} fileName 模板路径
     * @param {string} jsonData 数据
     * @memberof ReportApi
     */
    ReportApi.reportPrinter = function (fileName, jsonData) {
        dll.reportPrinter(fileName, jsonData);
    };
    return ReportApi;
}());
exports["default"] = ReportApi;
ReportApi.designerReport(null, null, function (data, callback) {
    callback(false);
});
