{"version":3,"file":"booking_times_channel-f87036bb.js","sources":["../../../../app/frontend/entrypoints/booking_times_channel.js"],"sourcesContent":["import consumer from \"~/channels/consumer\"\nconst userToken = Math.random().toString(36).substr(2)\n\nimport { bookingTimesLoaded, updateCardWithAPIData, useHttpForBookingTimes } from \"~/components/b2c/directory/bookableTimes\"\n\nlet locationData = [];\nlet pendingLocationIds = [];\ndocument.querySelectorAll('[data-booking-times-controller]').forEach(controllerEl => {\n controllerEl.querySelectorAll('[data-booking-times-card]').forEach(async (card) => {\n let location_data = {}\n location_data.location_id = card.dataset.segmentLocationId\n location_data.number_of_booking_times = parseInt(card.dataset.numberOfBookingTimes) || 4;\n location_data.prevent_waitlist = card.dataset.preventWaitlist == \"true\"; locationData.push(location_data)\n pendingLocationIds.push(card.dataset.segmentLocationId)\n })\n})\n\nconsumer.subscriptions.create({ channel: \"BookingTimesChannel\", user_token: userToken, source: \"directory\", location_data: locationData }, {\n received(data) {\n let index = pendingLocationIds.indexOf(data.location_id)\n if (index > -1) {\n pendingLocationIds.splice(index, 1);\n }\n if (pendingLocationIds.length == 0) {\n consumer.disconnect()\n bookingTimesLoaded()\n }\n updateCardWithAPIData(data)\n }\n})\n\nsetTimeout(() => {\n if (pendingLocationIds.length > 0) {\n consumer.disconnect()\n let locationsToRetry = []\n pendingLocationIds.forEach(locationId => {\n let card = document.querySelector(`.unified-listing-card.unified-listing-card--new[data-segment-location-id=\"${locationId}\"]`);\n let locationToRetry = {\n id: locationId,\n prevent_waitlist: card.dataset.preventWaitlist == \"true\"\n }\n locationsToRetry.push(locationToRetry);\n })\n useHttpForBookingTimes(locationsToRetry)\n }\n}, 5000);\n\n\n// this delayed function is to report failures to load booking times. Uncomment this to initiate error reporting\n// setTimeout(() => {\n// let currentPendingLocationIds = [];\n// document.querySelectorAll('[data-booking-times-controller]').forEach(controllerEl => {\n// controllerEl.querySelectorAll('[data-booking-times-card]').forEach(async (card) => {\n// if (card.dataset.slotsLoaded != \"true\") {\n// currentPendingLocationIds.push(card.dataset.segmentLocationId)\n// }\n// })\n// })\n\n// if (currentPendingLocationIds.length > 0) {\n// consumer.disconnect()\n// reportError(currentPendingLocationIds)\n// }\n// }, 10000);"],"names":["userToken","locationData","pendingLocationIds","controllerEl","card","location_data","consumer","data","index","bookingTimesLoaded","updateCardWithAPIData","locationsToRetry","locationId","locationToRetry","useHttpForBookingTimes"],"mappings":"8OACA,MAAMA,EAAY,KAAK,OAAQ,EAAC,SAAS,EAAE,EAAE,OAAO,CAAC,EAIrD,IAAIC,EAAe,CAAA,EACfC,EAAqB,CAAA,EACzB,SAAS,iBAAiB,iCAAiC,EAAE,QAAQC,GAAgB,CACnFA,EAAa,iBAAiB,2BAA2B,EAAE,QAAQ,MAAOC,GAAS,CACjF,IAAIC,EAAgB,CAAE,EACtBA,EAAc,YAAcD,EAAK,QAAQ,kBACzCC,EAAc,wBAA0B,SAASD,EAAK,QAAQ,oBAAoB,GAAK,EACvFC,EAAc,iBAAmBD,EAAK,QAAQ,iBAAmB,OAAQH,EAAa,KAAKI,CAAa,EACxGH,EAAmB,KAAKE,EAAK,QAAQ,iBAAiB,CAC1D,CAAG,CACH,CAAC,EAEDE,EAAS,cAAc,OAAO,CAAE,QAAS,sBAAuB,WAAYN,EAAW,OAAQ,YAAa,cAAeC,CAAY,EAAI,CACzI,SAASM,EAAM,CACb,IAAIC,EAAQN,EAAmB,QAAQK,EAAK,WAAW,EACnDC,EAAQ,IACVN,EAAmB,OAAOM,EAAO,CAAC,EAEhCN,EAAmB,QAAU,IAC/BI,EAAS,WAAY,EACrBG,EAAoB,GAEtBC,EAAsBH,CAAI,CAC3B,CACH,CAAC,EAED,WAAW,IAAM,CACf,GAAIL,EAAmB,OAAS,EAAG,CACjCI,EAAS,WAAY,EACrB,IAAIK,EAAmB,CAAE,EACzBT,EAAmB,QAAQU,GAAc,CACvC,IAAIR,EAAO,SAAS,cAAc,6EAA6EQ,CAAU,IAAI,EACzHC,EAAkB,CACpB,GAAID,EACJ,iBAAkBR,EAAK,QAAQ,iBAAmB,MACnD,EACDO,EAAiB,KAAKE,CAAe,CAC3C,CAAK,EACDC,EAAuBH,CAAgB,CACxC,CACH,EAAG,GAAI"}