function e(e){return e==null?``:String(e).replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`).replace(/'/g,`&apos;`)}function t(t,n){return n==null||n===``?``:` ${t}="${e(n)}"`}function n(e,n,r={}){let i=Object.entries(r).map(([e,n])=>t(e,n)).join(``);return!n&&n!==`0`?`<${e}${i}/>`:`<${e}${i}>${n}</${e}>`}function r(e){return e?`<![CDATA[${e}]]>`:``}function i(e,t=2){let n=0;return e.replace(/>\s*</g,`>
<`).split(`
`).map(e=>{let r=e.trim();if(!r)return``;r.startsWith(`</`)&&(n=Math.max(0,n-1));let i=` `.repeat(n*t)+r;return!r.startsWith(`</`)&&!r.endsWith(`/>`)&&!r.startsWith(`<?`)&&(r.includes(`</`)||(n+=1)),i}).filter(Boolean).join(`
`)}function a(t){let r=t.styles??{},i=n(`Styles`,[r.font_name?n(`FontName`,e(r.font_name)):``,r.font_size==null?``:n(`FontSize`,e(r.font_size)),r.font_weight?n(`FontWeight`,e(r.font_weight)):``,r.font_style?n(`FontStyle`,e(r.font_style)):``,r.font_effect?n(`FontEffect`,e(r.font_effect)):``,r.text_color?n(`TextColor`,e(r.text_color)):``,r.back_color?n(`BackColor`,e(r.back_color)):``,r.alignment?n(`Alignment`,e(r.alignment)):``,r.word_wrap==null?``:n(`WordWrap`,e(r.word_wrap)),r.rotation_angle==null?``:n(`RotationAngle`,e(r.rotation_angle)),r.border_thickness==null?``:n(`BorderThickness`,e(r.border_thickness)),r.border_color?n(`BorderColor`,e(r.border_color)):``].join(``));return n(`Element`,[n(`Bounds`,``,{x:t.x,y:t.y,width:t.width,height:t.height}),t.text==null?``:n(`Text`,e(t.text)),n(`FieldPath`,e(t.field_path??``)),t.field_category?n(`FieldCategory`,e(t.field_category)):``,t.barcode_type?n(`BarcodeType`,e(t.barcode_type)):``,t.image_id?n(`ImageId`,e(t.image_id)):``,t.transform?n(`Transform`,JSON.stringify(t.transform)):``,i,n(`ShowOnPage`,e(t.show_on_page??`every`))].join(``),{id:t.id,type:t.type,section:t.section,visible:t.visible??!0,locked:t.locked??!1,zIndex:t.z_index??0,isPageBorder:t.is_page_border??!1})}function o(t){return n(`Column`,[n(`FieldPath`,e(t.field_path??``)),n(`Label`,e(t.label)),n(`Width`,e(t.width)),t.alignment?n(`Alignment`,e(t.alignment)):``,t.format==null?``:n(`Format`,e(t.format)),t.font_size==null?``:n(`FontSize`,e(t.font_size)),t.font_weight?n(`FontWeight`,e(t.font_weight)):``,t.function_type?n(`FunctionType`,e(t.function_type)):``,t.word_wrap==null?``:n(`WordWrap`,e(t.word_wrap)),t.transform?n(`Transform`,JSON.stringify(t.transform)):``].join(``))}function s(e){return n(`Config`,e.totals?.length?n(`Totals`,e.totals.map(e=>n(`Total`,``,{label:e.label,field_path:e.field_path,format:e.format,bold:e.bold})).join(``)):``,{show_grid_lines:e.show_grid_lines,grid_line_style:e.grid_line_style,show_header_row:e.show_header_row,header_bg_color:e.header_bg_color,header_text_color:e.header_text_color,header_font_size:e.header_font_size,header_font_name:e.header_font_name,row_height:e.row_height,alternate_row_color:e.alternate_row_color,alternate_color:e.alternate_color,show_totals:e.show_totals,totals_position:e.totals_position,font_size:e.font_size,font_name:e.font_name,expand_mode:e.expand_mode,body_x:e.body_x,body_y:e.body_y,body_width:e.body_width,body_height:e.body_height})}function c(t){return n(`BodyTable`,[n(`Name`,e(t.name)),n(`Columns`,(t.columns??[]).map(o).join(``)),s(t.config??{})].join(``),{id:t.id})}function l(t){let o=typeof t.screen==`object`?t.screen.id:t.screen,s=typeof t.screen==`object`?t.screen.name:t.screen_name,l=t.margins??{top:10,right:10,bottom:10,left:10},u=t.company_info??{},d=t.page_break_config??{};return i([`<?xml version="1.0" encoding="UTF-8"?>`,`<PrintLayout version="1.0" xmlns="urn:oquis:print-layout:v1">`,n(`Meta`,[n(`Id`,e(t.id)),n(`Name`,e(t.name)),n(`Description`,e(t.description)),n(`ScreenId`,e(o)),n(`ScreenName`,e(s)),n(`IsDefault`,e(t.is_default))].join(``)),n(`PageSetup`,[n(`PaperSize`,e(t.paper_size)),n(`Orientation`,e(t.orientation)),n(`DisplayUnit`,e(t.display_unit)),n(`GridSize`,e(t.grid_size)),n(`ShowGrid`,e(t.show_grid)),n(`Margins`,``,l),n(`HeaderHeight`,e(t.header_height)),n(`FooterHeight`,e(t.footer_height)),t.custom_width?n(`CustomWidth`,e(t.custom_width)):``,t.custom_height?n(`CustomHeight`,e(t.custom_height)):``,n(`DefaultFont`,``,{name:t.default_font_name,size:t.default_font_size})].join(``)),n(`CompanyInfo`,[n(`Name`,e(u.company_name)),n(`Address`,e(u.company_address)),n(`Phone`,e(u.company_phone)),n(`Email`,e(u.company_email)),n(`Website`,e(u.company_website)),n(`GSTIN`,e(u.company_gstin)),n(`PAN`,e(u.company_pan)),n(`CIN`,e(u.company_cin))].join(``)),n(`Elements`,(t.elements??[]).map(a).join(``)),n(`BodyTables`,(t.body_tables?.length?t.body_tables:t.body_columns?.length?[{id:`default`,columns:t.body_columns,config:t.body_table_config??{}}]:[]).map(c).join(``)),n(`PageBreakConfig`,``,{repeatHeader:d.repeat_header,repeatFooter:d.repeat_footer,showPageNumbers:d.show_page_numbers,pageNumberFormat:d.page_number_format,pageNumberPosition:d.page_number_position}),t.watermark_text?n(`Watermark`,e(t.watermark_text)):``,t.custom_css?n(`CustomCSS`,r(t.custom_css)):``,`</PrintLayout>`].join(``))}function u(e){let t=l(e),n=new Blob([t],{type:`application/xml;charset=utf-8`}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`${e.name.replace(/[^a-z0-9_-]/gi,`_`)||`print-layout`}.xml`,document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(r)}export{u as t};