(() => {
const { pageHelper, EventManager, utils, actions, modules } = ShopbySkin;
const { InquiryForm } = modules;
const eventDetailHelper = pageHelper.eventDetailHelper();
const eventNo = DSDOENV.EventConfig.EVENT_NO_THE_PREMIUM_INFO;
const containerEl = document.querySelector(
'[shopby-helper-key="event-detail-helper-key"]'
);
const eventDetailRequest = {
eventNo,
sortType: "ADMIN_SETTING",
soldout: true,
};
const redirectLoginPage = () => {
const nextUrl = "/pages/sign-in/sign-in.html";
location.href = `${nextUrl}?from=${encodeURIComponent(location.href)}`;
};
eventDetailHelper.initialize({
helperKey: "event-detail-helper-key",
});
const likeHelper = {
toggleClassName: (likeEl) => {
likeEl.classList.toggle("is-active");
},
toggleLikeStatus: async (likeEl) => {
const productNo = likeEl.getAttribute("shopby-product-no") ?? 0;
await actions.toggleLikeStatus({
productNo: Number(productNo),
});
},
};
const CLICK_EVENT_HANDLER_MAP = {
HANDLE_COUPON_BTN_CLICK: () => {
if (!utils.isSignIn()) {
ShopbySkin.EventManager.fire("MODAL_CONFIRM_OPEN", {
noticeType: "CAUTION",
message: "로그인하셔야 본 서비스를 이용하실 수 있습니다.",
onConfirm: redirectLoginPage,
});
return;
}
const { coupon } =
document.querySelector("event-detail-product-list").store.state ?? {};
ShopbySkin.EventManager.fire("OPEN_LAYER_MODAL", {
title: "쿠폰받기",
name: "coupon-download",
data: {
coupons: coupon?.coupons ?? [],
eventNo,
},
isFull: false,
onClose: () => null,
});
},
HANDLE_SECTION_ID_CLICK: ({ target, helper }) => {
const tabId = target.getAttribute("shopby-tab-id");
helper.eventAction.selectEventCategory(tabId);
},
LIKE_PRODUCT: ({ target }) => {
if (!utils.isSignIn()) {
ShopbySkin.EventManager.fire("MODAL_CONFIRM_OPEN", {
noticeType: "CAUTION",
message: "로그인하셔야 본 서비스를 이용하실 수 있습니다.",
onConfirm: redirectLoginPage,
});
return;
}
const likeEl = target.closest("[shopby-product-no]");
likeHelper.toggleClassName(likeEl);
likeHelper.toggleLikeStatus(likeEl);
},
OPEN_PRODUCT_OPTION_MODAL: ({ target }) => {
const btn = target.closest("[shopby-product-no]");
const productNo = Number(btn.getAttribute("shopby-product-no") ?? 0);
const isSoldOut = utils.convertStringBooleanToBoolean(
btn.getAttribute("shopby-is-sold-out")
);
if (isSoldOut) {
return;
}
if (!utils.isAdultVerified(event)) {
EventManager.fire("MODAL_CONFIRM_OPEN", {
message: "성인인증이 필요한 상품입니다.",
noticeType: constants.NOTICE_MODAL_TYPE.CAUTION,
onConfirm: () => {
const nextUrl = `${location.origin}/pages/sign-in/sign-in.html`;
location.href = `${nextUrl}?from=${encodeURIComponent(
location.href
)}`;
},
});
return;
}
utils.isSignIn()
? EventManager.fire("OPEN_LAYER_MODAL", {
name: "select-product-option",
title: "옵션 선택",
isFull: false,
modalAddClass: "select-product-option-modal",
data: {
productNo,
},
})
: EventManager.fire("MODAL_CONFIRM_OPEN", {
message: `로그인하셔야 본 서비스를 이용하실 수 있습니다.`,
noticeType: constants.NOTICE_MODAL_TYPE.WARNING,
onConfirm: () => {
const nextUrl = `${location.origin}/pages/sign-in/sign-in.html`;
location.href = `${nextUrl}?from=${encodeURIComponent(
location.href
)}`;
},
});
},
};
const CHANGE_EVENT_HANDLER_MAP = {
HANDLE_SORT_CHANGE: ({ target, helper }) => {
helper.eventAction.fetchEventDetail({
...eventDetailRequest,
sortType: target.value,
});
},
};
EventManager.fire("INIT_EVENT_PRODUCT_SECTION_SLIDER", {
spaceBetween: 32,
direction: "horizontal",
effect: "slide",
slidesPerView: "auto",
});
EventManager.on("PAGE_LOAD_COMPLETED", () => {
eventDetailHelper.eventAction.fetchEventDetail(eventDetailRequest);
});
const clickEventListener = ({ target }) => {
const actionType =
target.getAttribute("shopby-action") ??
target.closest("button")?.getAttribute("shopby-action");
CLICK_EVENT_HANDLER_MAP[actionType]?.({
helper: eventDetailHelper,
target,
});
};
const changeEventListener = ({ target }) => {
const actionType = target.getAttribute("shopby-action");
CHANGE_EVENT_HANDLER_MAP[actionType]?.({
helper: eventDetailHelper,
target,
});
};
containerEl.addEventListener("click", clickEventListener);
containerEl.addEventListener("change", changeEventListener);
ShopbySkin.Handlebars.registerHelper('appealFormTypeName', (label) => typeof label === 'string' ? label.replace(/^이의 신청\s*-\s*/, '').trim() : '');
ShopbySkin.Handlebars.registerHelper('isAppealImageAttachment', (name) => /\.(jpe?g|png|gif|webp|bmp|svg|avif|ico|apng)$/i.test(name ?? ''));
// 이의 신청 모달 overriding
class CustomAppealForm extends InquiryForm {
constructor() {
super();
}
setup() {
super.setup();
this.eventManager.on("FETCH_INITIAL_INQUIRY_FORM", this.handleInitialInquiryForm);
}
handleInitialInquiryForm = () => {
EventManager.fire("INIT_BOARD_BUTTON_GROUP", { isModify: false });
const initialInquiryOptions = this.makeInquiryTypeSelectOptions();
this.store.setState({
inquiryTypeSelectOption: {
value: "",
options: initialInquiryOptions
.filter((option) => option.label.includes("이의"))
.map((option) => ({ label: option.label.replace("이의 신청 -", ""), value: option.value })),
},
isModify: false,
});
this.setSelectDisabled(false);
}
}
if(customElements.get("custom-appeal-form") === undefined) {
customElements.define("custom-appeal-form", CustomAppealForm);
}
})();