(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", "../TabContext", "./styles"], 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 TabContext_1 = require("../TabContext");
    var styles_1 = require("./styles");
    var TabPanel = (0, react_1.forwardRef)(function (_a, ref) {
        var children = _a.children, style = _a.style, className = _a.className, value = _a.value, _b = _a.isKeepAlive, isKeepAlive = _b === void 0 ? false : _b, props = (0, tslib_1.__rest)(_a, ["children", "style", "className", "value", "isKeepAlive"]);
        var context = (0, TabContext_1.useTabContext)();
        var isLoaded = (0, react_1.useRef)(false);
        if (context === null) {
            throw new Error("No TabContext provided");
        }
        var isTabActive = value === context.value;
        if (isKeepAlive) {
            if (context.isLazy && !isLoaded.current && !isTabActive) {
                return null;
            }
            if (!isLoaded.current) {
                isLoaded.current = true;
            }
        }
        else {
            if (context.isLazy && !isTabActive) {
                return null;
            }
        }
        return (react_1.default.createElement(styles_1.TabPanelStyled, (0, tslib_1.__assign)({ ref: ref, isHidden: !isTabActive, role: "tabpanel", style: style, className: className }, props), children));
    });
    TabPanel.displayName = "TabPanel";
    exports.default = TabPanel;
});
