"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var vdom_1 = require("@dojo/framework/core/vdom");
var icache_1 = require("@dojo/framework/core/middleware/icache");
var icache = icache_1.createICacheMiddleware();
var factory = vdom_1.create({ icache: icache });
exports.radioGroup = factory(function (_a) {
    var icache = _a.middleware.icache;
    return function (onValue, initialValue, value) {
        if (value === undefined) {
            var existingInitialValue = icache.get('initial');
            if (existingInitialValue !== initialValue) {
                icache.set('value', initialValue);
                icache.set('initial', initialValue);
            }
        }
        return function (key) {
            function checked(checked) {
                var 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: checked
            };
        };
    };
});

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