"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.PrivateRoute = void 0;
const contexts_1 = require("../contexts/index.js");
const react_1 = __importDefault(require("react"));
const react_router_dom_1 = require("react-router-dom");
const PrivateRoute = ({ children }) => {
    const { cognitoLoginState, loading } = (0, contexts_1.useAuthentication)();
    const isAuthenticated = cognitoLoginState === contexts_1.CognitoLoginState.Success;
    const location = (0, react_router_dom_1.useLocation)();
    if (loading) {
        return null;
    }
    if (!isAuthenticated) {
        return react_1.default.createElement(react_router_dom_1.Navigate, { to: "/find-reservation", state: { from: location }, replace: true });
    }
    return react_1.default.createElement(react_1.default.Fragment, null, children);
};
exports.PrivateRoute = PrivateRoute;
//# sourceMappingURL=PrivateRoute.js.map