
/* Smart UI v18.0.1 (2024-01-22) 
Copyright (c) 2011-2023 jQWidgets. 
License: https://htmlelements.com/license/ */ //

(()=>{"use strict";class e{_setRowProperty(e,t,o){const r=this,s=r.rowById[e];s&&(s[t]=o,r.stateSettings.autoSave&&r.stateSettings.current&&!r.stateSettings.loading&&r.saveState())}_setRowsProperty(e,t,o){const r=this;r._refreshLayout(),r._refreshRowHierarchy(!0);const s=r._recyclingRows;r.rows.canNotify=!1;for(let r=0;r<s.length;r++){const a=s[r];o&&-1===o.indexOf(a.id)||(a[e]=t)}r.rows.canNotify=!0,r.refresh()}expandRowsToGroupLevel(e){this._expandCollapseGroupsToLevel(!0,e)}_expandCollapseGroupsToLevel(e,t){const o=this;o._refreshLayout(),o._refreshRowHierarchy(!0);const r=o._recyclingRows;o.rows.canNotify=!1;for(let s=0;s<r.length;s++){const a=r[s];a.data.level<t&&(a.expanded=a.data.expanded=e,o.dataSource&&(e?o.dataSource._expandedRowIds[a.data.$.id]=!0:delete o.dataSource._expandedRowIds[a.data.$.id]))}o.rows.canNotify=!0,o.refresh()}_applyThreeStates(e){const t=this,o=e!==t.rowHierarchy;if(!t.rowHierarchy)return;const r=o?e.children:t.rowHierarchy.filter((e=>{if(0===e.level)return e}));let s=0,a=0;for(let c=0;c<r.length;c++){const d=r[c];e.checked&&(d.checked=!0),!1===d.leaf&&t._applyThreeStates(d),o&&(d.checked?s++:null===d.checked&&a++)}o&&(s===e.children.length?e.checked=!0:0===s&&0===a?e.checked=!1:t.checkBoxes.hasThreeStates?e.checked=null:e.checked=!1)}_hasThreeStates(e,t){const o=this;let r=e;for(e!==t&&(e.checked?e.checked=!1:e.checked=!0);r.parent;){const e=r.parent,t=e.children;let s=0,a=0;for(let e=0;e<t.length;e++)t[e].checked?s++:o.checkBoxes.hasThreeStates&&null===t[e].checked&&a++;s===e.children.length?e.checked=!0:0===s&&0===a?e.checked=!1:o.checkBoxes.hasThreeStates?e.checked=null:e.checked=!1,r=e}e.leaf||function e(t,o){const r=t.children;for(let t=0;t<r.length;t++){const s=r[t];s.checked=o,!1===s.leaf&&e(s,o)}}(e,e.checked)}_expandCollapseGroup(e,t){const o=this;if(!o.grouping.enabled||!o.rowHierarchy)return;e&&e.indexOf&&e.indexOf("Item")>=0&&(e=e.replace("Item",""));const r=(""+e).split(".");let s=o.rowHierarchy[r[0]];if(!s)return;const a=o.rows.canNotify;o.rows.canNotify=!1,null===t&&(t=!s.expanded),s.expanded=s.data.expanded=t,o._saveRowState(s.id,!s.expanded);for(let e=1;e<r.length&&(s=s.children[r[e]],s&&!s.leaf);e++)s.expanded=s.data.expanded=t;o.rows.canNotify=a,o._refresh(),o.stateSettings.autoSave&&o.stateSettings.current&&!o.stateSettings.loading&&o.saveState()}_saveRowState(e,t=!1){const o=this,r=o.rowById[e];if(r&&o.dataSource){if(t)return void delete o.dataSource._expandedRowIds[r.data.$.id];o.dataSource._expandedRowIds[r.data.$.id]=!0}}expandRow(e){const t=this;t.grouping.enabled?t._expandCollapseGroup(e,!0):e&&Array.isArray(e)?t._setRowsProperty("expanded",!0,e):(t._setRowProperty(e,"expanded",!0),t._saveRowState(e))}expandAllRows(){const e=this;e.grouping.enabled?e._expandCollapseGroupsToLevel(!0,99):e._setRowsProperty("expanded",!0)}collapseAllRows(){const e=this;e.grouping.enabled?e._expandCollapseGroupsToLevel(!1,99):e._setRowsProperty("expanded",!1)}toggleRow(e){const t=this;if(t.grouping.enabled)return void t._expandCollapseGroup(e,null);const o=t.rowById[e];o&&(o.expanded?o.expanded=!1:o.expanded=!0)}collapseRow(e){const t=this;t.grouping.enabled?t._expandCollapseGroup(e,!1):e&&Array.isArray(e)?t._setRowsProperty("expanded",!1,e):(t._setRowProperty(e,"expanded",!1),t._saveRowState(e,!0))}checkRow(e){const t=this;e&&Array.isArray(e)?t._setRowsProperty("checked",!0,e):t._setRowProperty(e,"checked",!0)}uncheckRow(e){const t=this;e&&Array.isArray(e)?t._setRowsProperty("checked",!1,e):t._setRowProperty(e,"checked",!1)}checkAllRows(){this._setRowsProperty("checked",!0)}uncheckAllRows(){this._setRowsProperty("checked",!1)}}Smart.Utilities.Grid.Tree=e})();