"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 callbackPointer;
var dll = ffi.Library(dllPath, {
    designerReport: ['void', ['string', 'string']],
    reportShowPreview: ['void', ['string', 'string']],
    reportPrinter: ['void', ['string', 'string', 'bool']],
    ReportToImage: ['string', ['string', 'string']],
    waitSaveOrClose: ['void', ['pointer']]
});
var ReportApi = /** @class */ (function () {
    function ReportApi() {
    }
    /**
     *设计模板
     *
     * @param {string} fileName 模板
     * @param {string} tempData 临时演示数据
     * @memberof ReportApi
     */
    ReportApi.designerReport = function (template, tempData, saveCallback) {
        callbackPointer = ffi.Callback('void', ['string', 'pointer'], function (data, func) {
            if (data) {
                var nativeCallback_1 = ffi.ForeignFunction(func, 'void', ['bool']);
                try {
                    saveCallback(data, function (result) {
                        if (result) {
                            nativeCallback_1(true);
                        }
                        else {
                            nativeCallback_1(false);
                        }
                        dll.waitSaveOrClose(callbackPointer);
                    });
                }
                catch (e) {
                    console.error(e);
                    nativeCallback_1(false);
                    dll.waitSaveOrClose(callbackPointer);
                }
            }
        });
        dll.designerReport(template, tempData);
        dll.waitSaveOrClose(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, isSelectPrinter) {
        dll.reportPrinter(fileName, jsonData, isSelectPrinter);
    };
    /**
     * 打印到图片(返回base64图片)
     *
     * @param {string} fileName 模板路径
     * @param {string} jsonData 数据
     * @memberof ReportApi
     */
    ReportApi.reportToImage = function (fileName, jsonData) {
        return dll.reportToImage(fileName, jsonData);
    };
    return ReportApi;
}());
exports["default"] = ReportApi;
