import { cloneObject } from "@esri/hub-common" ; import { convertSection } from "./convert-section" ; import { ILayout , ITemplatizedLayout } from "./types" ; param { ILayout } layout export function convertLayoutToTemplate ( layout ) { if ( ! layout ) { return null ; } const converted = layout . sections . reduce ( ( acc , section ) => { const _result = convertSection ( section ) ; acc . assets = acc . assets . concat ( _result . assets ) ; acc . sections . push ( _result . section ) ; return acc ; } , { assets : [ ] , sections : [ ] } ) ; const result = { assets : converted . assets , layout : { sections : converted . sections } } as ITemplatizedLayout ; if ( layout . header ) { result . layout . header = cloneObject ( layout . header ) ; } if ( layout . footer ) { result . layout . footer = cloneObject ( layout . footer ) ; } return result ; }