"use strict";
'use client';
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = useBorrowBook;
const tslib_1 = require("tslib");
const __1 = require("../../../../..");
const constants_1 = require("../constants");
const mutation_1 = require("../mutation");
const use_book_state_1 = tslib_1.__importDefault(require("./use-book-state"));
function useBorrowBook() {
    const { listBookState } = (0, use_book_state_1.default)();
    const handleReturnBook = async (inBookshelfArrayId, inWarehouseArrayId, borrowBookId, returnTicketIdArray = []) => {
        var _a, _b, _c;
        const userInfo = (0, __1.PHXFuncGetLoggedInfo)();
        try {
            await (0, __1.PHXClientMutationV3)({
                query: mutation_1.returnBorrowBookMutation,
                variables: {
                    inWarehouseIdArray: inWarehouseArrayId,
                    inBookshelfIdArray: inBookshelfArrayId,
                    borrowBookIdArray: borrowBookId,
                    inWarehouseStateId: (_a = listBookState.find((item) => item.code === constants_1.IN_WAREHOUSE_STATE_CODE)) === null || _a === void 0 ? void 0 : _a.id,
                    inBookshelfStateId: (_b = listBookState.find((item) => item.code === constants_1.IN_BOOKSHELF_STATE_CODE)) === null || _b === void 0 ? void 0 : _b.id,
                },
            });
            if ((returnTicketIdArray === null || returnTicketIdArray === void 0 ? void 0 : returnTicketIdArray.length) > 0) {
                const { data: { library_ticket_state }, } = await (0, __1.PHXClientQueryV3)({
                    query: mutation_1.getTicketStateListQuery,
                    variables: { school_id: userInfo === null || userInfo === void 0 ? void 0 : userInfo.school_id },
                    isDelay: false,
                });
                const returnStateId = (_c = library_ticket_state.find((item) => item.code === constants_1.RETURNED_TICKET_CODE)) === null || _c === void 0 ? void 0 : _c.id;
                await (0, __1.PHXClientMutationV3)({
                    query: mutation_1.returnBorrowTicketMutation,
                    variables: {
                        idArray: returnTicketIdArray,
                        returnStateId,
                    },
                });
            }
        }
        catch (e) {
            console.log(e);
        }
    };
    return { handleReturnBook };
}
//# sourceMappingURL=use-borrow-book.js.map