/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import e from"../../core/Error.js";import{getLayersWithChartSupport as r}from"../../layers/support/layerUtils.js";import{newUnsupportedError as o,webDocUnsupportedErrorSet as t}from"./unsupportedErrors.js";async function s(e){const r=[];for(const o of e.allLayers)if("beforeSave"in o&&"function"==typeof o.beforeSave){const e=o.beforeSave();e&&r.push(e)}await Promise.allSettled(r)}function n(r,s,n){let i=(r.messages??[]).filter(({type:e})=>"error"===e).map(({name:r,message:o,details:t})=>new e(r,o,t));if(r.blockedRelativeUrls&&(i=i.concat(r.blockedRelativeUrls.map(e=>o("url",`Relative url '${e}' is not supported`)))),n){const{ignoreUnsupported:e,supplementalUnsupportedErrors:r=[],requiredPropertyChecksDisabled:o}=n;e&&(i=i.filter(({name:e})=>!(t.has(e)||r.includes(e)))),o&&(i=i.filter(e=>"web-document-write:property-required"!==e.name))}if(i.length>0)throw new e(s.errorName,"Failed to save due to unsupported or invalid content. See 'details.errors' for more detailed information",{errors:i})}function i(e){return r(e).some(e=>!!e.charts?.length)}export{s as beforeSave,n as evaluateWriteErrors,i as hasCharts};
