/**
 * @license
 * Copyright 2017 Google LLC
 * SPDX-License-Identifier: BSD-3-Clause
 */
import{isSingleExpression as e}from"./directive-helpers.js";import{Directive as t,PartType as i}from"./directive.js";export*from"./directive.js";const notifyChildrenConnectedChanged=(e,t)=>{const i=e._$disconnectableChildren;if(void 0===i)return!1;for(const e of i)e._$notifyDirectiveConnectionChanged?.(t,!1),notifyChildrenConnectedChanged(e,t);return!0},removeDisconnectableFromParent=e=>{let t,i;do{if(void 0===(t=e._$parent))break;i=t._$disconnectableChildren,i.delete(e),e=t}while(0===i?.size)},addDisconnectableToParent=e=>{for(let t;t=e._$parent;e=t){let i=t._$disconnectableChildren;if(void 0===i)t._$disconnectableChildren=i=new Set;else if(i.has(e))break;i.add(e),installDisconnectAPI(t)}};function reparentDisconnectables(e){void 0!==this._$disconnectableChildren?(removeDisconnectableFromParent(this),this._$parent=e,addDisconnectableToParent(this)):this._$parent=e}function notifyChildPartConnectedChanged(e,t=!1,i=0){const n=this._$committedValue,s=this._$disconnectableChildren;if(void 0!==s&&0!==s.size)if(t)if(Array.isArray(n))for(let e=i;e<n.length;e++)notifyChildrenConnectedChanged(n[e],!1),removeDisconnectableFromParent(n[e]);else null!=n&&(notifyChildrenConnectedChanged(n,!1),removeDisconnectableFromParent(n));else notifyChildrenConnectedChanged(this,e)}const installDisconnectAPI=e=>{e.type==i.CHILD&&(e._$notifyConnectionChanged??=notifyChildPartConnectedChanged,e._$reparentDisconnectables??=reparentDisconnectables)};export class AsyncDirective extends t{constructor(){super(...arguments),this._$disconnectableChildren=void 0}_$initialize(e,t,i){super._$initialize(e,t,i),addDisconnectableToParent(this),this.isConnected=e._$isConnected}_$notifyDirectiveConnectionChanged(e,t=!0){e!==this.isConnected&&(this.isConnected=e,e?this.reconnected?.():this.disconnected?.()),t&&(notifyChildrenConnectedChanged(this,e),removeDisconnectableFromParent(this))}setValue(t){if(e(this.__part))this.__part._$setValue(t,this);else{if(void 0===this.__attributeIndex)throw new Error("Expected this.__attributeIndex to be a number");const e=[...this.__part._$committedValue];e[this.__attributeIndex]=t,this.__part._$setValue(e,this,0)}}disconnected(){}reconnected(){}}