/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
import{differentValuesString as e}from"./inputUtils.js";import{isEmptyValue as t}from"../../../support/forms/formUtils.js";const n="esri_BatchAttributeForm_other_choice_checked",i=new WeakMap;function r(e,t){if(null==e||""===e)return[];const n=String(e);if(!t){const e=n.trim();return""===e?[]:[e]}return n.split(t).map(e=>e.trim()).filter(e=>""!==e)}function c({input:t,choiceValue:n,currentValue:i,isChecked:c}){const{multipleChoiceInput:o,multipleChoiceValues:u}=t;if(!o||!u)return i;const{choiceDelimiter:l}=o,s=new Set(u),a=r(i,l).filter(t=>t!==e&&s.has(t)),f=a.includes(n);if(!c){const e=f?a.filter(e=>e!==n):a;return e.length>0?e.join(l):null}return f||!s.has(n)?a.length>0?a.join(l):null:[...a,n].join(l)}function o({input:e,choiceValue:t}){const n=e.multipleChoiceInput?.choiceDelimiter,i=e.multipleChoiceValues;if(null==n||!i)return{checked:!1,indeterminate:!1};const c=e.features.length;if(!c)return{checked:!1,indeterminate:!1};let o=0;for(const u of e.features){r(u.getAttribute(e.fieldName),n).includes(t)&&(o+=1)}return o===c?{checked:!0,indeterminate:!1}:0===o?{checked:!1,indeterminate:!1}:{checked:!1,indeterminate:!0}}function u({input:e}){const t=e.multipleChoiceInput?.choiceDelimiter,n=e.multipleChoiceValues;if(null==t||!n)return{checked:!1,indeterminate:!1};if(0===n.length)return{checked:!1,indeterminate:!1};let i=!0,r=!1;for(const c of n){const t=o({input:e,choiceValue:c});(t.checked||t.indeterminate)&&(r=!0),t.checked||(i=!1)}return{checked:i,indeterminate:!i&&r}}function l({input:e,otherChoiceFieldName:n}){const i=e.features.length;if(!i)return{checked:!1,indeterminate:!1};const r=e.features.toArray().filter(e=>!t(e.getAttribute(n))).length;return 0===r?{checked:!1,indeterminate:!1}:r===i?{checked:!0,indeterminate:!1}:{checked:!1,indeterminate:!0}}function s(t){return!(null==t||""===t||t===n||t===e)}function a(e,t={}){const{includeDraftValues:n=!1}=t;if(!e)return;const r=new Set;for(const i of e.sharedForm.allFieldInputs)r.add(i.expressionsManager);for(const i of e.activeForm.allFieldInputs)r.add(i.expressionsManager);for(const c of r)i.get(c)?.clear();if(n){const t=new Set;for(const n of e.sharedForm.allFieldInputs)for(const e of n.features)t.add(e);for(const e of t)e.clearStashedAttributes()}}export{s as canRestoreMultipleChoiceOtherChoiceDraftValue,a as clearMultipleChoiceOtherChoiceStateForViewModel,o as getMultipleChoiceCheckboxState,l as getMultipleChoiceOtherChoiceState,u as getMultipleChoiceSelectAllState,c as getUpdatedMultipleChoiceValueForFeature,i as multipleChoiceOtherChoiceCheckedStateByExpressionsManager,n as otherChoiceCheckedPlaceholderValue,r as splitMultipleChoiceValue};
