import { bind } from "astal";
import Brightness from "../../../../util/brightness";

const brightness = Brightness.get_default();

const BrightnessModule = () => {
    const setBrightness = (value: number) => {
        brightness.set_property('screen', value / 100);
    }
    return (
        <box visible={bind(brightness, 'screenAvailable')}>
            <image iconName={"brightness-high-symbolic"}></image>
            <label label={bind(brightness, "screen").as(b => `${Math.round(100 * b)}%`)}></label>
            <slider
                value={bind(brightness, "screen").as(b => 100 * b)}
                hexpand
                max={100}
                min={0}
                step={1}
                vexpand
                onChangeValue={self => setBrightness(self.value)}
            ></slider>
        </box>
    );
};

export default {
    BrightnessModule
};
