import { IModel , IHubRequestOptions , cloneObject , propifyString , createId , normalizeSolutionTemplateItem , replaceItemId , getItemAssets , IModelTemplate } from "@esri/hub-common" ; import { getPageItemType } from "./get-page-item-type" ; import { convertLayoutToTemplate } from "../layout" ; import { getSiteDependencies } from "../get-site-dependencies" ; import { IItem } from "@esri/arcgis-rest-types" ; param { Object } model param { IHubRequestOptions } hubRequestOptions export function convertPageToTemplate ( model , hubRequestOptions ) { const tmpl = ( cloneObject ( model ) as unknown ) as IModelTemplate ; tmpl . type = getPageItemType ( hubRequestOptions . isPortal ) ; tmpl . key = `${ propifyString ( model . item . title ) }_${ createId ( "i" ) }` ; tmpl . itemId = model . item . id ; tmpl . item = normalizeSolutionTemplateItem ( tmpl . item as IItem ) ; tmpl . data . values . sites = [ ] ; [ "source" , "updatedAt" , "updatedBy" , "folderId" , "slug" ] . forEach ( p => { delete tmpl . data . values [ p ] ; } ) ; const layoutConversion = convertLayoutToTemplate ( tmpl . data . values . layout ) ; tmpl . data . values . layout = layoutConversion . layout ; tmpl . dependencies = getSiteDependencies ( model ) ; tmpl . data = replaceItemId ( tmpl . data , tmpl . itemId ) ; if ( ! tmpl . item . properties ) { tmpl . item . properties = { } ; } return getItemAssets ( model . item , hubRequestOptions ) . then ( assets => { tmpl . assets = assets ; return tmpl ; } ) ; }