import * as XMLHelper from "./xmlhelper";
import { config } from "./config";
import * as I from "../types/types";
import * as Events from "./events";
import * as CartButtons from "./cartButtons";
export function addItem(inSeatObj: I.JSCSelectedSeat): void {
const color: string = `#${XMLHelper.getVenuePricescalePropertyByPricescaleID("color", inSeatObj.data.seatsObj.id[0])}`;
const category: string | undefined = XMLHelper.getVenuePricescalePropertyByPricescaleID("desc", inSeatObj.data.seatsObj.id[0]);
const seat: string = config.state.layoutRows[inSeatObj.id][5];
const row: string = config.state.layoutRows[inSeatObj.id][4];
const sectionID: string = config.state.layoutRows[inSeatObj.id][3];
const sectionDesc: string | undefined = XMLHelper.getSectionDescBySectionID(sectionID);
const seatStr: string | undefined = `${sectionDesc}
Reihe ${row} Platz ${seat}`;
const buyerTypes: I.TypeBuyerType = XMLHelper.getBuyerTypesByPricescaleID(inSeatObj.data.seatsObj.id[0]);
const cartID: string = `cartItem-${inSeatObj.id}`;
const dropdownBuyerTypesSelector: string = `#${cartID} .dropdownBuyerTypes`;
appendHTML(cartID, color, category, seatStr);
addDropdownBuyerTypeOptions(buyerTypes, dropdownBuyerTypesSelector);
Events.addCartDropdownBuyerTypes(dropdownBuyerTypesSelector, inSeatObj);
}
export function removeCartItems(): void {
jQuery("#cartItemHTML .cartItem").each(function () {
this.remove();
});
}
export function changedDropdownBuyerType(inSelect: HTMLSelectElement, inSeatObj: I.JSCSelectedSeat): void {
const index: number = config.state.selectedSeatsArr.findIndex(arr =>
arr[0] === inSeatObj.id);
config.state.selectedSeatsArr[index][1] = inSelect.value;
const buyerTypeCode = XMLHelper.getBuyerTypeCodeByBuyerTypeID(inSelect.value);
if (buyerTypeCode)
config.state.selectedSeatsArr[index][2] = buyerTypeCode;
calcOverallPrice();
CartButtons.setBtnCartText();
const url = generateCheckoutUrl();
Events.addRedirectCheckout(url);
}
export function calcOverallPrice(): string | undefined {
if (!config.state.selectedSeatsArr.length) {
config.state.priceOverall = "0";
return "0";
}
config.state.priceOverall = sumSeatPrices();
return config.state.priceOverall;
}
export function generateCartItems(): void {
if (!config.state.selectedSeatsArr.length)
return;
for (const key in config.state.selectedSeatsObj) {
if (Object.prototype.hasOwnProperty.call(config.state.selectedSeatsObj, key)) {
const element = config.state.selectedSeatsObj[key];
addItem(element);
}
}
}
export function initModalCart(): void {
jQuery("#modalCart-overlay").hide();
Events.addCartBack();
Events.addCartClose();
}
export function generateCheckoutUrl(): string | undefined {
if (!config.state.selectedSeatsArr.length)
return;
const inputsWithValue = config.state.inputsWithValue!;
const selectedSeatIndexes: string = XMLHelper.generateSelectedSeatIndexes();
return `${inputsWithValue["ticketPurchaseUrl"]}?user_context=${inputsWithValue.user_context}&pid=${inputsWithValue["pid"]}&selected_seat_indexes=${selectedSeatIndexes}&trxstate=148`;
}
function appendHTML(inCartID: string, inColor: string, inCategory: string | undefined, inSeatStr: string): void {
jQuery("#cartItemHTML .fl-html").append(`