"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useMember = void 0;
const contexts_1 = require("../contexts/index.js");
const react_1 = require("react");
const useMember = () => {
    const { roomstayMember, allBookings, cancelledBookings, upcomingBookings, pastBookings } = (0, react_1.useContext)(contexts_1.RoomstayMemberContext);
    const [fullName, setFullName] = (0, react_1.useState)('');
    (0, react_1.useEffect)(() => {
        if (roomstayMember) {
            setFullName(`${roomstayMember.forename} ${roomstayMember.surname}`);
        }
        else {
            setFullName('');
        }
    }, [roomstayMember]);
    const getItinerary = (id) => {
        for (const booking of allBookings) {
            if (booking.itineraryId === id) {
                return booking;
            }
        }
        return null;
    };
    /**
     * TODO:
     *
     * Add:
     *  * Is authenticated
     *  * Is Loading User
     */
    return {
        user: roomstayMember,
        fullName,
        allBookings,
        cancelledBookings,
        pastBookings,
        upcomingBookings,
        getItinerary,
    };
};
exports.useMember = useMember;
//# sourceMappingURL=LoggedInUserHook.js.map