jQuery(document).ready(function ($){
let isKit=$("input[name=is-workshop-kit]").val()==="yes";
if(!isKit){
$("#twc_workshops_class_id").on('input', function (){
let remaining=$(this).find("option:selected").data('remaining');
let start=$(this).find("option:selected").data('start');
start=new Date(start);
let val=$(this).val();
$(".verbiage-remove").remove();
$("#twc-workshops-date-label-wrap").show();
$("#twc-workshops-date-label").text("Date: " + formatDate(start));
if(val===""){
$("#twc-workshops-date-label-wrap").hide();
$(".cart .quantity, .cart button[name=add-to-cart]").hide();
$("#waitlist-signup").hide();
}else{
if(remaining <=0){
$("#waitlist-signup").show();
$(".cart .quantity, .cart button[name=add-to-cart]").hide();
}else{
$(".cart .quantity, .cart button[name=add-to-cart]").show();
setMaxQty(remaining);
$(".cart .quantity .qty").val(1);
$("#waitlist-signup").hide();
$('div.quantity')
.before('<span class="verbiage-remove" style="display: inline-block">Number of guests at your table?&ensp;'+ (remaining <=3 ? `<br>Heads up! There ${remaining > 1 ? "are":"is"} only ${remaining} spot${remaining > 1 ? "s":""} remaining.`:'') +'</span>')
.after('<div class="verbiage-remove">' + 'Please ensure all guests are included in your reservation. Tables are preassigned before your arrival.')
}}
})
function showAvailableFirst(){
let foundAvailable=false;
let green='rgb(11, 122, 11)';
console.log($(".fc-daygrid-day-events").find(".fc-daygrid-event"));
$(".fc-daygrid-day-events").find(".fc-daygrid-event").each(function(){
foundAvailable=foundAvailable||$(this).css('background-color')===green;
});
if(foundAvailable){
$(".fc-daygrid-day-events").find(".fc-daygrid-event").first().css({'background-color': green, 'border-color': green});
}}
$(".fc-dayGridMonth-button").on('click', function (e){
e.preventDefault();
$("#twc-workshops-date-label-wrap").hide();
showAvailableFirst();
});
$("#twc-workshops-change-date").on('click', function (e){
e.preventDefault();
$("#twc-workshops-date-label-wrap").hide();
$("#twc-workshop-calendar").slideDown(300);
calendar.changeView('listWeek');
$(".cart .quantity, .cart button[name=add-to-cart]").hide();
$("#waitlist-signup").hide();
});
function setMaxQty(max){
$(".cart .quantity .qty").prop('max', max);
}
$("#waitlist-phone").on('input', function (){
let val=$(this).val();
val=val.replace(/[^0-9]/g, '');
let newVal="";
if(val){
newVal="(" + val.substring(0, 3);
if(val.length > 3){
newVal +=") " + val.substring(3, 6);
if(val.length > 6){
newVal +="-" + val.substring(6, 10);
}}
}
$(this).val(newVal);
});
$("#join-waitlist").on('click', function (e){
e.preventDefault();
let valid=true;
let firstName=$("#waitlist-first-name").val();
let lastName=$("#waitlist-last-name").val();
let email=$("#waitlist-email").val();
let phone=$("#waitlist-phone").val();
let seats=Number($("#waitlist-seats").val());
$("#waitlist-signup input").each(function (){
$(this).css('border-color', ($(this).val()) ? "":"#f00");
valid=valid&&$(this).val();
});
if(!(new RegExp('^(.+@.+[\.].+)$')).test(email)){
valid=false;
alert("Please enter a valid email.");
}else if(!(new RegExp('^([(]?[0-9]{3}[)]?[- ]?[0-9]{3}[- ]?[0-9]{4})$').test(phone))){
valid=false;
alert("Please enter a valid phone number.");
}else if(seats < 1||seats!==Math.floor(seats)){
valid=false;
alert("Please enter a valid number of seats.");
}
if(valid){
let data={
action: 'twc_workshops_join_waitlist',
classID: $("#twc_workshops_class_id").val(),
nonce_data: $("#wizard-nonce").data('magic')
};
data.firstName=firstName;
data.lastName=lastName;
data.email=email;
data.phone=phone;
data.seats=seats;
$.ajax({
url: '/wp-admin/admin-ajax.php',
data: data,
beforeSend: function (){
$("#waitlist-signup").fadeOut(300);
},
success: function (data){
if(data){
$("#waitlist-signup").html(`<h2>You have been added to the wait list!</h2>
<a class="button-default fusion-button-default-size" href="/">Back to Home</a>`
)
.fadeIn(300);
}else{
$("#waitlist-signup").slideDown(300);
alert("Something went wrong while trying to join...");
}},
error: function (){
$("#waitlist-signup").slideDown(300);
alert("Something went wrong while trying to join...");
}});
}});
$("#waitlist-signup input").on('input', function (){
$(this).css('border-color', ($(this).val()) ? "":"#f00")
});
}else{
$(".cart .quantity, .cart button[name=add-to-cart]").show();
let noticeSeen=[];
async function multipleNotices(notices, i=0){
if(notices[i]!==undefined){
let message=notices[i].message;
if(!noticeSeen.includes(message)){
$("#workshop-notice-text").html(message);
$("#workshop-notice").show();
$("#workshop-notice-confirmed").unbind('click').on('click', function (e){
e.preventDefault();
$("#workshop-notice").hide();
noticeSeen.push(message);
multipleNotices(notices, i + 1);
});
}}
}
$(document).on('change', '.wc-pao-addon-select', function (){
let value=$(this).val();
let categories=$("#hidden-workshop-category").val().split(",");
if(value.includes('king-st-vineland')){
if(categories.includes("624")){
multipleNotices([
{
message: "The kids March break DIY kits are intended for <b>children 12 and under only</b>. They will be created in our main building at <b>3725 King Street, Vineland</b>."
}
])
}else{
multipleNotices([
{
message: "DIY kits are now available for pick-up in the main building. Upon arrival, please head to the <b>Flower Shop</b> to collect your kit."
}
])
}}
})
}
function formatDate(date){
const months=[
'January', 'February', 'March', 'April', 'May', 'June', 'July',
'August', 'September', 'October', 'November', 'December'
];
const month=months[date.getMonth()];
const day=date.getDate();
const year=date.getFullYear();
const hour=date.getHours();
const minute=date.getMinutes();
const ampm=hour >=12 ? 'pm':'am';
let formattedHour=hour % 12;
formattedHour=formattedHour ? formattedHour:12;
return `${month} ${day}, ${year}, ${formattedHour}:${minute.toString().padStart(2, '0')}${ampm}`;
}
$("#twc-workshops-children").on('input', function (){
let val=parseInt($(this).val());
let price=parseFloat($("#twc-workshops-price-per-child").val());
$("#twc-workshops-children-tag-value").text(val);
$("#twc-workshops-children-tag-price").text(`$${(price * val).toFixed(2)}`);
})
});