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