import { create } from '@dojo/framework/core/vdom';
import { createICacheMiddleware } from '@dojo/framework/core/middleware/icache';
const icache = createICacheMiddleware();
const factory = create({ icache });
export const radioGroup = factory(({ middleware: { icache } }) => {
    return (onValue, initialValue, value) => {
        if (value === undefined) {
            const existingInitialValue = icache.get('initial');
            if (existingInitialValue !== initialValue) {
                icache.set('value', initialValue);
                icache.set('initial', initialValue);
            }
        }
        return (key) => {
            function checked(checked) {
                const existingValue = value === undefined ? icache.get('value') : value;
                if (checked === undefined) {
                    return existingValue === key;
                }
                else if (checked && existingValue !== key) {
                    icache.set('value', key);
                    onValue(key);
                }
            }
            return {
                checked
            };
        };
    };
});

/*# sourceMappingURL=middleware.mjs.map*/