"use strict";(globalThis.webpackChunkbooktics=globalThis.webpackChunkbooktics||[]).push([[142],{3038:(e,t,s)=>{s.d(t,{A:()=>d});var i=s(47143),c=s(47767),r=s(40309),a=s(11534),l=s(56580),o=s(88802);const d=function(){const e=(0,i.useSelect)(e=>e(r.services).getServicesState(),[]),{selectedServices:t}=(0,i.useSelect)(e=>e(r.team).getTeamState(),[]),{setServicesState:s}=(0,i.useDispatch)(r.services),{setTeamState:d}=(0,i.useDispatch)(r.team),n=(0,l.useAdminLicense)(),{searchQuery:v,serviceList:u=[],total:S,singleService:g,selectedTeamMembers:f,selectedExtraServices:m=[],schedule:p,selectedLocations:h}=e,_=(0,c.Zp)(),{id:y}=(0,c.g)(),b=async(e={})=>{e?.resetFilter&&(e={search:"",category_id:"",team_member_id:""});const t={...v,...e};s({isFiltering:!0});try{const e=await(a.A?.service?.allServices(t));e?.success&&s({serviceList:e?.data?.items,total:e?.data?.total,searchQuery:t})}catch(e){console.error("Error fetching services:",e)}finally{return s({isFiltering:!1}),{complete:!0}}};return{createService:async(e,i=!0)=>{try{s({isFiltering:!0});const c=await(a.A?.service?.createService(e));c?.success&&(s({serviceList:[c?.data,...u||[]],total:S+1}),i?_(`/services/update/${c?.data.id}`):(s({visibleCreateServiceModal:!1}),d({selectedServices:[c.data.id,...t]})))}catch(e){console.error("Error creating service:",e)}finally{s({isFiltering:!1})}},updateService:async(e,t="deactive",i=!1)=>{if(i||s({loadingServiceId:!0}),e?.custom_field){let t=Array.isArray(e?.custom_field?.fields)?e?.custom_field?.fields?.map(e=>"global"===e?.from?e:{...e,from:"service"}):void 0;e.custom_field={...e?.custom_field,fields:t}}try{const i={...g,...e,status:t,extra_services:m,team_member:f,schedule:e.enable_custom_schedule?p:{},show_end_time:Number(e.show_end_time)||!1};delete i.extra_service_details,n||(delete i.extra_services,delete i.custom_field);const c=await a.A.service.updateService(y,i);if(c?.success){const e=u?.map(e=>e?.id===c?.data?.id?c?.data:e);s({serviceList:e}),s({loadingServiceId:!1})}return c}catch(e){console.error("Error updating service:",e)}finally{s({loadingServiceId:!1})}},updateStatus:async({id:e,...t})=>{try{delete t.extra_service_details;const s=await(a.A?.service?.updateService(e,t));if(s?.success){const e=(0,i.select)(r.services).getServicesState("serviceList"),t=e?.map(e=>e.id===s.data.id?s.data:e);(0,i.dispatch)(r.services).setServicesState({serviceList:t})}return s}catch(e){console.error("Error updating status:",e)}finally{(0,i.dispatch)(r.services).setServicesState({loadingServiceId:null})}},getServices:b,deleteSingleService:async e=>{try{const t=await(a.A?.service?.deleteSingleService(e));if(t?.success){const{serviceList:t,total:s}=(0,i.select)(r.services).getServicesState();(0,i.dispatch)(r.services).setServicesState({serviceList:t?.filter(t=>t.id!==e),total:s-1})}return t}catch(e){console.error("Error deleting service:",e)}},bulkDeleteService:async(e=[])=>{try{const t=await(a.A?.service?.bulkDeleteService({ids:e}));if(t?.success&&(s({serviceList:u.filter(t=>!e.includes(t.id))}),e.length<S)){const{paged:e="",per_page:t=""}=v;b({paged:e,per_page:t})}}catch(e){console.error("Error bulk deleting services:",e)}finally{return{complete:!0}}},duplicateService:async e=>{try{s({isFiltering:!0});const t=await(a.A?.service?.cloneService(e));if(t?.success){const i=u.findIndex(t=>t.id===e);if(-1===i)throw new Error("Service not found for duplication.");const c=[...u.slice(0,i+1),t.data,...u.slice(i+1)];s({serviceList:c,total:S+1})}}catch(e){console.error("Error duplicating service:",e)}finally{s({isFiltering:!1})}},getSingleService:async()=>{try{const e=await a.A.service.singleService(y);e.success&&s({singleService:{...e?.data,custom_field:{...e?.data?.custom_field,fields:e?.data?.custom_field?.fields?.length?e?.data?.custom_field?.fields:o.defaultFields}}})}catch(e){console.log(e)}},onPaginationChange:(e,t)=>{b({paged:e,per_page:t})}}}},30142:(e,t,s)=>{s.r(t),s.d(t,{default:()=>a});var i=s(51609),c=s(22564),r=s(3038);const a=()=>{const{getServices:e}=(0,r.A)();return window?.wp?.hooks.applyFilters("booktics_extra_service_edit",(0,i.createElement)(c.EmptyScreen,{isPro:!0}),{getServices:e})}}}]);