import { CanvasSmbl } from '../infrastructure/canvas-smbl.js';

/**
 * @param {CanvasElement} canvas
 * @param {any} serializedData
 * @param {function(Blob):void} callBack
 */
export function fileSaveSvg(canvas, serializedData, callBack) {
    const svgVirtual = /** @type {SVGSVGElement} */(canvas.ownerSVGElement.cloneNode(true));

    svgVirtual.style.backgroundImage = null;
    svgVirtual.querySelectorAll('.select, .highlight').forEach(el => el.classList.remove('select', 'highlight'));

    const nonSvgElems = svgVirtual.getElementsByTagName('foreignObject');
    while (nonSvgElems[0]) { nonSvgElems[0].parentNode.removeChild(nonSvgElems[0]); }

/*     svgVirtual.querySelectorAll('g.hovertrack.shtxt.ta-1').forEach(group => {
        group.querySelectorAll('text, tspan').forEach(el => console.log(el));
    }); */

    const svgStr = new XMLSerializer().serializeToString(svgVirtual);
    const blob = new Blob([svgStr], { type: 'image/svg+xml;charset=utf-8' });
    callBack(blob);
}




/** @typedef { {x:number, y:number} } Point */
/** @typedef { import('../infrastructure/canvas-smbl.js').CanvasElement } CanvasElement */
