/**
 * A LitElement controller that observes changes to specific properties of a LiveData instance
 * and requests an update to the host LitElement when those properties change.
 */
export class LiveDataController {
    liveData;
    paths;
    host;
    unsubscribe;
    /**
     * Creates a new LiveDataController.
     *
     * @param host - The LitElement that is hosting this controller.
     * @param paths - An array of dot-notation paths to properties within the LiveData object that should be observed.
     */
    constructor(host, paths = []) {
        this.host = host;
        this.paths = paths;
        host.addController(this);
    }
    /**
     * Sets the LiveData instance to observe.
     * It will remove existing listeners.
     *
     * @param liveData - The LiveData instance. When not set it only removes any previously added listenr.
     * @param paths - An array of dot-notation paths to properties within the LiveData object that should be observed.
     */
    setLiveData(liveData, paths) {
        this.unsubscribe?.();
        this.unsubscribe = undefined;
        this.liveData = liveData;
        this.paths = paths || this.paths;
        this.connect();
    }
    hostConnected() {
        this.connect();
    }
    hostDisconnected() {
        this.unsubscribe?.();
        this.unsubscribe = undefined;
    }
    connect() {
        if (!this.liveData) {
            return;
        }
        this.unsubscribe = this.liveData.observeProperties(this.paths, () => {
            this.host.requestUpdate();
        });
    }
    /**
     * Reads the value of a LiveData instance using the dot notation
     *
     * @param path The dot-notation path to the property (e.g., "user.address.city").
     * @returns The value at the specified path, or undefined if the path is invalid or the value is not found.
     */
    get(path) {
        if (!this.liveData) {
            return undefined;
        }
        return this.liveData.get(path);
    }
}
//# sourceMappingURL=LiveDataController.js.map