"use strict";(globalThis.webpackChunksugar_calendar_bookings_scheduling_appointments=globalThis.webpackChunksugar_calendar_bookings_scheduling_appointments||[]).push([[9597],{4918(e,i,s){function a({locationId:e,service:i=null,services:s=[],serviceId:a=null,stepData:n,bookingData:t,stepId:c,handleStepDataChange:o,updateBookingData:l}){let d=i;!d&&s.length>0&&(a?d=s.find((e=>e.id===a)):n?.selectedService?.id?d=s.find((e=>e.id===n.selectedService.id)):t?.service?.id&&(d=s.find((e=>e.id===t.service.id))));const r=d?.locations?.find((i=>{if("number"==typeof i.id){const s=Number(e);if(!isNaN(s)&&i.id===s)return!0}return"string"==typeof i.uid&&i.uid===e}));if(!d||!r)return;const u={...n,selectedLocation:r},g={...t,service:{...t.service,location:r.name},[c]:u},m=Boolean(u.selectedService&&u.selectedLocation);g.stepValidation={...t.stepValidation,[c]:m},o(u),l(g)}s.d(i,{A:()=>a})},1173(e,i,s){s.d(i,{A:()=>u});var a=s(6087),n=s(7723),t=s(6377),c=s(4918),o=s(5600),l=s(9115),d=s(6538),r=s(790);function u(){const{state:e,config:i,actions:s,currentStep:u,handlers:g}=(0,t.q)(),{bookingData:m}=e,{updateBookingData:v}=s,{handleStepDataChange:_}=g,h=u.id,[p,b]=(0,a.useState)(null),k=e.bookingData.services||[],x=m[h]||{},j=x.selectedService,f=x.selectedLocation,N=(e,i)=>`${e} ${{hr:1===e?"hour":"hours",min:1===e?"minute":"minutes"}[i]||i}`,S=e=>{const i=k.find((i=>i.id===e));if(!i)return;b(p===e?null:e);const s=i.locations[0],a={selectedService:i,selectedLocation:s},n={...m,service:{id:i.id,name:i.name,description:i.description,price:i.price,duration:N(i.duration,i.duration_unit),category:i.category||"",image:i.feature_image_url||"",location:s.name,totalPrice:i.price,paymentGateways:i.payment_gateways},[h]:a},t=Boolean(a.selectedService&&a.selectedLocation);n.stepValidation={...m.stepValidation,[h]:t},_(a),v(n)};(0,a.useEffect)((()=>{1!==k.length||j||S(k[0].id)}),[k.length]);const D=1===k.length;return(0,r.jsx)("div",{className:"scbookings-service-selection",children:(0,r.jsx)("div",{className:"scbookings-service-selection__services",children:k.map((e=>{const s=j?.id===e.id,a=D||p===e.id,t=i?.showServiceImage||!1,u=(e.locations?.length||0)>1,g=(0,r.jsxs)("div",{className:"scbookings-service-item__content",children:[t&&e.feature_image_url&&(0,r.jsx)("div",{className:"scbookings-service-item__thumbnail",children:(0,r.jsx)("img",{src:e.feature_image_url,alt:e.name,className:"scbookings-service-item__image"})}),(0,r.jsxs)("div",{className:"scbookings-service-item__details",children:[(0,r.jsx)("h3",{className:"scbookings-service-item__title",children:e.name}),(0,r.jsxs)("div",{className:"scbookings-service-item__duration",children:[(0,r.jsx)(l.A,{}),(0,r.jsx)("span",{children:N(e.duration,e.duration_unit)})]})]}),(0,r.jsx)("div",{className:"scbookings-service-item__price",children:e.price})]});return(0,r.jsxs)("div",{className:`scbookings-service-item${s?" scbookings-service-item--selected":""}${D?" scbookings-service-item--static":""}`,children:[D?(0,r.jsx)("div",{className:"scbookings-service-item__static",children:g}):(0,r.jsx)("button",{type:"button",className:"scbookings-service-item__button",onClick:()=>S(e.id),"aria-expanded":u?a:void 0,"aria-controls":u?`service-locations-${e.id}`:void 0,children:g}),a&&u&&(0,r.jsxs)("div",{id:`service-locations-${e.id}`,className:"scbookings-service-item__locations",children:[(0,r.jsxs)("div",{className:"scbookings-service-item__locations-header",children:[(0,r.jsx)(d.A,{}),(0,r.jsx)("span",{children:(0,n.__)("Location","sugar-calendar-bookings-scheduling-appointments-lite")})]}),(0,r.jsxs)("div",{className:"scbookings-service-item__location-select-wrapper",children:[(0,r.jsxs)("select",{id:`location-select-${e.id}`,className:"scbookings-service-item__location-select",value:f&&(f.id||f.uid)||"",onChange:i=>((e,i=null)=>{(0,c.A)({locationId:e,service:i,services:k,serviceId:i?.id||j?.id,stepData:x,bookingData:m,stepId:h,handleStepDataChange:_,updateBookingData:v})})(i.target.value,e),"aria-label":(0,n.__)("Select Location","sugar-calendar-bookings-scheduling-appointments-lite"),children:[(0,r.jsx)("option",{value:"",children:(0,n.__)("Choose a location…","sugar-calendar-bookings-scheduling-appointments-lite")}),e.locations.map((e=>(0,r.jsx)("option",{value:e.id||e.uid,children:e.name},e.id||e.uid)))]}),(0,r.jsx)(o.A,{className:"scbookings-service-item__location-chevron"})]})]})]},e.id)}))})})}},9597(e,i,s){let a;s.r(i),s.d(i,{default:()=>n}),a=s(1173).A;const n=a}}]);