import o from"@arcgis/core/PopupTemplate";import t from"@arcgis/core/popup/ElementExpressionInfo";import e from"@arcgis/core/popup/FieldInfo";import{TextContent as r}from"@arcgis/core/popup/content";import n from"@arcgis/core/popup/content/AttachmentsContent";import p from"@arcgis/core/popup/content/BarChartMediaInfo";import i from"@arcgis/core/popup/content/ColumnChartMediaInfo";import s from"@arcgis/core/popup/content/ExpressionContent";import a from"@arcgis/core/popup/content/FieldsContent";import c from"@arcgis/core/popup/content/ImageMediaInfo";import m from"@arcgis/core/popup/content/LineChartMediaInfo";import f from"@arcgis/core/popup/content/MediaContent";import u from"@arcgis/core/popup/content/PieChartMediaInfo";import l from"@arcgis/core/popup/content/RelationshipContent.js";import{checkArg as d}from"../utilities/checkArg.js";import{isAttachmentsContent as h,isExpressionContent as y,isFieldsContent as O,isMediaContent as g,isRelationshipContent as I,isTextContent as N}from"../utilities/esri.js";import{deepClone as P}from"../utilities/object.js";export var PopupInfo;!function(t){t.toEsriApiPopupTemplate=function(t){d("json",t).isNotMissing();const e=P(t),r=o.fromJSON(e);return r.content||(r.content=[]),r},t.fromEsriApiPopupTemplate=function(o){return d("popupTemplate",o).isNotMissing(),o.toJSON()}}(PopupInfo||(PopupInfo={}));export var PopupContent;!function(o){o.toEsriApiPopupContent=function(o){d("json",o).isNotMissing();const t=P(o);switch(o.type){case"attachments":return n.fromJSON(t);case"expression":return s.fromJSON(t);case"fields":return a.fromJSON(t);case"media":return f.fromJSON(t);case"text":return r.fromJSON(t);case"relationship":return l.fromJSON(t);default:throw new Error(`Unknown PopupContent type: ${JSON.stringify(t)}`)}},o.fromEsriApiPopupContent=function(o){return d("PopupElement",o).isNotMissing(),o.toJSON()},o.applyToEsriApiPopupContent=function(o,r){d("elementJson",o).isNotMissing(),d("content",r).isNotMissing(),N(r)&&"text"===o.type?o.hasOwnProperty("text")&&(r.text=o.text):y(r)&&"expression"===o.type?o.hasOwnProperty("expressionInfo")&&(r.expressionInfo=t.fromJSON(o.expressionInfo)):(o.hasOwnProperty("title")&&(r.title=o.title),o.hasOwnProperty("description")&&(r.description=o.description)),h(r)&&"attachments"===o.type?o.hasOwnProperty("displayType")&&(r.displayType=o.displayType):O(r)&&"fields"===o.type?o.hasOwnProperty("fieldInfos")&&(r.fieldInfos=o.fieldInfos?.map((o=>e.fromJSON(o)))):g(r)&&"media"===o.type?o.hasOwnProperty("mediaInfos")&&(r.mediaInfos=o.mediaInfos?.map((o=>function(o){switch(o.type){case"image":return c.fromJSON(o);case"barchart":return p.fromJSON(o);case"columnchart":return i.fromJSON(o);case"linechart":return m.fromJSON(o);case"piechart":return u.fromJSON(o);default:throw new Error(`Unknown MediaInfo type: ${JSON.stringify(o)}`)}}(o)))):I(r)&&"relationship"===o.type&&(o.hasOwnProperty("displayCount")&&null!=o.displayCount&&(r.displayCount=o.displayCount),o.hasOwnProperty("relationshipId")&&null!=o.relationshipId&&(r.relationshipId=o.relationshipId))}}(PopupContent||(PopupContent={}));