import { AcApDocManager } from '../app';
/**
 * Utility class for exporting the current CAD drawing to DXF format.
 */
var AcApDxfConvertor = /** @class */ (function () {
    function AcApDxfConvertor() {
    }
    /**
     * Exports the current drawing database to a DXF file and downloads it.
     */
    AcApDxfConvertor.prototype.convert = function () {
        var document = AcApDocManager.instance.curDocument;
        var dxfContent = document.database.dxfOut(undefined, 6);
        var baseName = this.getBaseName(document.fileName || document.docTitle);
        this.createFileAndDownloadIt(dxfContent, "".concat(baseName, ".dxf"));
    };
    AcApDxfConvertor.prototype.createFileAndDownloadIt = function (dxfContent, fileName) {
        var dxfBlob = new Blob([dxfContent], {
            type: 'application/dxf;charset=utf-8'
        });
        var url = URL.createObjectURL(dxfBlob);
        var downloadLink = document.createElement('a');
        downloadLink.href = url;
        downloadLink.download = fileName;
        document.body.appendChild(downloadLink);
        downloadLink.click();
        document.body.removeChild(downloadLink);
        URL.revokeObjectURL(url);
    };
    AcApDxfConvertor.prototype.getBaseName = function (fileName) {
        var normalizedName = (fileName === null || fileName === void 0 ? void 0 : fileName.trim()) || 'drawing';
        return normalizedName.replace(/\.[^.]+$/, '') || 'drawing';
    };
    return AcApDxfConvertor;
}());
export { AcApDxfConvertor };
//# sourceMappingURL=AcApDxfConvertor.js.map