function bindStateToController(controllerProperty, options) {
    return (proto, stateProperty)=>{
        const ctor = proto.constructor;
        ctor.addInitializer((instance)=>{
            const component = instance;
            const { disconnectedCallback, initialize } = component;
            component.initialize = function() {
                initialize?.call(this);
                if (!initialize) return console.error(`ControllerState: The "initialize" method has to be defined and instantiate a controller for the property ${controllerProperty.toString()}`, component);
                if (!component[controllerProperty]) return console.error(`${controllerProperty.toString()} property is not defined on component`, component);
                if (options?.onUpdateCallbackMethod && !component[options.onUpdateCallbackMethod]) return console.error(`ControllerState: The onUpdateCallbackMethod property "${options.onUpdateCallbackMethod}" is not defined`, component);
                const controller = component[controllerProperty];
                const updateCallback = options?.onUpdateCallbackMethod ? component[options.onUpdateCallbackMethod] : void 0;
                const unsubscribeController = controller.subscribe(()=>{
                    component[stateProperty] = controller.state;
                    'function' == typeof updateCallback && updateCallback();
                });
                component.disconnectedCallback = ()=>{
                    component.isConnected || unsubscribeController?.();
                    disconnectedCallback?.call(component);
                };
            };
        });
    };
}
export { bindStateToController };
