/*!
 * KoliBri - The accessible HTML-Standard
 */
import { clampedNumberValueProp, highProp, labelProp, lowProp, maxProp, minProp, optimumProp, orientationProp, unitProp } from "../../props";
import { BaseController } from "../base-controller";
import { meterPropsConfig } from "./api";
export class MeterController extends BaseController {
    constructor(stateAccess) {
        super(stateAccess, meterPropsConfig);
        this.meterData = { high: undefined, low: undefined, optimum: undefined };
    }
    componentWillLoad(props) {
        const { high, label, low, max, min, optimum, orientation, unit, value } = props;
        this.watchHigh(high);
        this.watchLabel(label);
        this.watchLow(low);
        this.watchMax(max);
        this.watchMin(min);
        this.watchOptimum(optimum);
        this.watchOrientation(orientation);
        this.watchUnit(unit);
        this.watchValue(value);
    }
    getMeterData() {
        return this.meterData;
    }
    watchHigh(value) {
        if (value === undefined) {
            this.meterData.high = undefined;
        }
        else {
            highProp.apply(value, (v) => {
                this.meterData.high = v;
            });
        }
    }
    watchLabel(value) {
        labelProp.apply(value, (v) => {
            this.setRenderProp('label', v);
        });
    }
    watchLow(value) {
        if (value === undefined) {
            this.meterData.low = undefined;
        }
        else {
            lowProp.apply(value, (v) => {
                this.meterData.low = v;
            });
        }
    }
    watchMax(value) {
        maxProp.apply(value, (v) => {
            this.setRenderProp('max', v);
            this.watchValue(this.getRawProp('value'));
        });
    }
    watchMin(value) {
        minProp.apply(value, (v) => {
            this.setRenderProp('min', v);
            this.watchValue(this.getRawProp('value'));
        });
    }
    watchOptimum(value) {
        if (value === undefined) {
            this.meterData.optimum = undefined;
        }
        else {
            optimumProp.apply(value, (v) => {
                this.meterData.optimum = v;
            });
        }
    }
    watchOrientation(value) {
        orientationProp.apply(value, (v) => {
            this.setRenderProp('orientation', v);
        });
    }
    watchUnit(value) {
        unitProp.apply(value, (v) => {
            this.setRenderProp('unit', v);
        });
    }
    watchValue(value) {
        this.setRawProp('value', value);
        clampedNumberValueProp.apply(value, (v) => {
            this.setRenderProp('value', v);
        }, { min: this.getRenderProp('min'), max: this.getRenderProp('max') });
    }
}
//# sourceMappingURL=controller.js.map
