import e from"@arcgis/core/PopupTemplate";import t from"@arcgis/core/portal/PortalItem";import{LayerDefinition as i}from"../portal/LayerDefinition.js";import{checkArg as r}from"../utilities/checkArg.js";export async function toEsriApiTable(e){const t=new((await import("@arcgis/core/layers/FeatureLayer")).default);return await applyToEsriTable(e,t),t}export async function applyToEsriTable(o,a){r("tableJson",o).isNotMissing(),r("table",a).isNotMissing(),r("tableJson.$tableType",o.$tableType).satisfies((e=>"ArcGISServiceTable"===e||void 0===e)),o.hasOwnProperty("id")&&(a.id=o.id),o.hasOwnProperty("title")&&(a.title=o.title),o.hasOwnProperty("url")&&(a.url=o.url),o.hasOwnProperty("itemId")&&(a.portalItem=new t({id:o.itemId})),o.hasOwnProperty("popupInfo")&&(a.popupTemplate=e.fromJSON(o.popupInfo)),o.hasOwnProperty("layerDefinition")&&await i.applyToEsriApiLayer(o.layerDefinition,a)}export function fromEsriTable(e){r("table",e).isNotMissing();const t={layerDefinition:i.fromEsriApiLayer(e)};return t.id=e.id,t.$tableType="ArcGISServiceTable",e.title&&(t.title=e.title),e.url&&(t.url=e.url),e.portalItem?.id&&(t.itemId=e.portalItem.id),e.popupTemplate&&(t.popupInfo=e.popupTemplate?.toJSON()),e.objectIdField&&(t.layerDefinition.objectIdField=e.objectIdField),t}