(function (factory) {
    if (typeof module === "object" && typeof module.exports === "object") {
        var v = factory(require, exports);
        if (v !== undefined) module.exports = v;
    }
    else if (typeof define === "function" && define.amd) {
        define(["require", "exports", "tslib", "react", "./styles", "./helpers/calculateChange"], factory);
    }
})(function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var tslib_1 = require("tslib");
    var react_1 = (0, tslib_1.__importStar)(require("react"));
    var styles_1 = require("./styles");
    var calculateChange_1 = require("./helpers/calculateChange");
    var Transparency = function (_a) {
        var colorRgb = _a.colorRgb, alpha = _a.alpha, setAlpha = _a.setAlpha;
        var container = (0, react_1.useRef)(null);
        var pointButtonRef = (0, react_1.useRef)(null);
        (0, react_1.useEffect)(function () { return function () { return unbindEventListeners(); }; }, []);
        var handleChange = function (e) {
            if (container.current && pointButtonRef.current) {
                setAlpha((0, calculateChange_1.calculateChange)(e, container.current) + "%");
            }
        };
        var handleMouseDown = function (e) {
            handleChange(e);
            window.addEventListener("mousemove", handleChange);
            window.addEventListener("mouseup", handleMouseUp);
        };
        var handleMouseUp = function () {
            unbindEventListeners();
        };
        var unbindEventListeners = function () {
            window.removeEventListener("mousemove", handleChange);
            window.removeEventListener("mouseup", handleMouseUp);
        };
        return (react_1.default.createElement(styles_1.TransparencyLine, { colorRgb: colorRgb, ref: container },
            react_1.default.createElement(styles_1.PointButton, { ref: pointButtonRef, onMouseDown: handleMouseDown, alpha: alpha / 100, colorRgb: colorRgb })));
    };
    exports.default = Transparency;
});
