@oneclick.dev/cms-core-modules 0.0.102 → 0.0.103
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/AgendaOpeningHoursCard-B7ROIPWw.js +1 -0
- package/dist/AgendaOpeningHoursCard-Cp4wxUeK.mjs +172 -0
- package/dist/AppointmentListTable-DZJNmTMb.mjs +177 -0
- package/dist/AppointmentListTable-Dieu9US_.js +1 -0
- package/dist/{ContentEditor-Cjqgb64R.mjs → ContentEditor-B1nfKG_5.mjs} +706 -677
- package/dist/{ContentEditor-YgOS3kxS.js → ContentEditor-DdFU8piH.js} +15 -16
- package/dist/{Create-6uT9HWar.mjs → Create-BRBh0xjM.mjs} +2 -2
- package/dist/{Create-DuZ5nZrX.js → Create-qPeQxkdl.js} +1 -1
- package/dist/{DateFormatter-2B0R-DY4.mjs → DateFormatter-Bw-87W31.mjs} +212 -227
- package/dist/DateFormatter-CYAD4GBN.js +1 -0
- package/dist/{Detail-BZ-iE9vf.js → Detail-C857g62L.js} +1 -1
- package/dist/{Detail-CJVMJDP7.mjs → Detail-CujdFApD.mjs} +2 -2
- package/dist/EditLayout.vue_vue_type_script_setup_true_lang-DWMqQvHl.mjs +76 -0
- package/dist/EditLayout.vue_vue_type_script_setup_true_lang-kpjbVSXg.js +1 -0
- package/dist/{Entries-DkRhOt95.js → Entries-BaS6H6ak.js} +1 -1
- package/dist/{Entries-dLlCrXXe.mjs → Entries-C8UJkrVC.mjs} +1 -1
- package/dist/{Find-Bd1uLqSa.mjs → Find-B24ZEhYM.mjs} +1 -1
- package/dist/{NewReservationDialog.vue_vue_type_script_setup_true_lang-Bc946oSc.mjs → NewReservationDialog.vue_vue_type_script_setup_true_lang-9Q7TMm4u.mjs} +37 -37
- package/dist/{NewReservationDialog.vue_vue_type_script_setup_true_lang-CqERfyYb.js → NewReservationDialog.vue_vue_type_script_setup_true_lang-DiNzGl-q.js} +1 -1
- package/dist/{Overview-DoOASlNz.mjs → Overview-3HWhsqaz.mjs} +2 -2
- package/dist/{Overview-37nilXzE.js → Overview-CpHhuiaV.js} +1 -1
- package/dist/{Overview-DeQQ0FY3.js → Overview-DAxCu9XC.js} +1 -1
- package/dist/{Overview-C--dq51X.mjs → Overview-D_T3K6aq.mjs} +1 -1
- package/dist/ReservationDetailDialog.vue_vue_type_script_setup_true_lang-Cz_22Oce.mjs +2927 -0
- package/dist/ReservationDetailDialog.vue_vue_type_script_setup_true_lang-DPPNc-Z5.js +349 -0
- package/dist/TableView-CPAw3h8g.js +4 -0
- package/dist/TableView-DXmEF6pY.mjs +6143 -0
- package/dist/agenda-BNG05SAq.js +1 -0
- package/dist/agenda-D1RxMxBS.mjs +1152 -0
- package/dist/availability-CMrRa5y2.mjs +269 -0
- package/dist/availability-Cf2YfMwM.js +1 -0
- package/dist/booking-data-DgJd0BcM.mjs +889 -0
- package/dist/booking-data-Di5GmH_8.js +1 -0
- package/dist/cms-core-modules.css +1 -1
- package/dist/{exceptions-Bp5BSvxO.js → exceptions-CI0B4xVj.js} +1 -1
- package/dist/{exceptions-C97cNZYl.mjs → exceptions-vo8SA5SE.mjs} +68 -68
- package/dist/index-BtujSJeg.js +35 -0
- package/dist/{index-CrGjxSwa.mjs → index-CrgzoTyR.mjs} +1 -1
- package/dist/{index-D2a6wEPh.js → index-DPd3waTN.js} +1 -1
- package/dist/{index-CABh6Qn6.mjs → index-DrXxXB2F.mjs} +15 -15
- package/dist/{index-B-lVEpFX.mjs → index-MYWjg0zi.mjs} +3 -3
- package/dist/index-dOdMm1pV.mjs +1105 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.mjs +196 -143
- package/dist/interpolation-DEDSLETn.mjs +128 -0
- package/dist/interpolation-DERg6Lwt.js +1 -0
- package/dist/orders-CzzcFQha.mjs +559 -0
- package/dist/orders-ETtbA4aQ.js +1 -0
- package/dist/{payment-Bosr0m3u.mjs → payment-C3ohkehF.mjs} +1 -1
- package/dist/{payment-DDnC03jb.js → payment-Dfr-Ro-a.js} +1 -1
- package/dist/{resources-BtF5RUUq.js → resources-CxeFd57z.js} +1 -1
- package/dist/{resources-B7qDBC91.mjs → resources-WI_4SO6T.mjs} +2 -2
- package/dist/server-handlers.cjs.js +1 -1
- package/dist/server-handlers.mjs +457 -387
- package/dist/src/appointments/chat-components/AgendaOpeningHoursCard.vue.d.ts +15 -0
- package/dist/src/appointments/components/edit/CustomerInformationFieldEditorDialog.vue.d.ts +17 -5
- package/dist/src/appointments/components/edit/EventDialog/BookingsList.vue.d.ts +8 -3
- package/dist/src/appointments/components/edit/EventDialog/EventDialog.vue.d.ts +1 -0
- package/dist/src/appointments/components/edit/EventDialog/ReservationDetailDialog.vue.d.ts +6 -3
- package/dist/src/appointments/components/edit/EventTimeline.vue.d.ts +3 -0
- package/dist/src/appointments/components/edit/EventView.vue.d.ts +6 -1
- package/dist/src/appointments/components/edit/MetadataSchemaEditorDialog.vue.d.ts +12 -0
- package/dist/src/appointments/components/edit/OrderMetadataDisplay.vue.d.ts +21 -0
- package/dist/src/appointments/components/edit/dashboard/BookingsList.vue.d.ts +8 -3
- package/dist/src/appointments/index.d.ts +53 -0
- package/dist/src/appointments/pages/edit/agenda.vue.d.ts +3 -1
- package/dist/src/appointments/pages/edit/availability.vue.d.ts +1 -26
- package/dist/src/appointments/pages/edit/booking-data.vue.d.ts +65 -0
- package/dist/src/appointments/pages/edit/orders.vue.d.ts +7 -3
- package/dist/src/appointments/tools.d.ts +52 -0
- package/dist/src/appointments/types.d.ts +12 -0
- package/dist/src/table/config.d.ts +200 -0
- package/dist/src/table/get_data_flow-DEFAULT.json.d.ts +129 -0
- package/dist/src/table/index.d.ts +200 -0
- package/dist/utils-CanmrIWO.mjs +47 -0
- package/dist/utils-Yd6F5mea.js +3 -0
- package/package.json +2 -2
- package/src/appointments/tools.ts +38 -0
- package/dist/AppointmentListTable-CQ0WIXtj.js +0 -1
- package/dist/AppointmentListTable-aV_UJd6j.mjs +0 -159
- package/dist/DateFormatter-DbtOLV0L.js +0 -1
- package/dist/EditLayout.vue_vue_type_script_setup_true_lang-DXa-Xxue.mjs +0 -74
- package/dist/EditLayout.vue_vue_type_script_setup_true_lang-ozYrxb2g.js +0 -1
- package/dist/ReservationDetailDialog.vue_vue_type_script_setup_true_lang-CL5kbDII.mjs +0 -2782
- package/dist/ReservationDetailDialog.vue_vue_type_script_setup_true_lang-DcyyNvf6.js +0 -349
- package/dist/TableView-CIJs118q.mjs +0 -5929
- package/dist/TableView-DzZYf34i.js +0 -4
- package/dist/agenda-CCOjPiwP.mjs +0 -1133
- package/dist/agenda-CNPQfaIQ.js +0 -1
- package/dist/availability-B1D4Fyzi.mjs +0 -629
- package/dist/availability-DxrUcYbW.js +0 -1
- package/dist/index-BOnqrBfY.js +0 -35
- package/dist/index-Bj0qaL1N.mjs +0 -1091
- package/dist/interpolation-BBwG_ON6.mjs +0 -65
- package/dist/interpolation-CsOrww73.js +0 -1
- package/dist/orders-BJV5vRQr.mjs +0 -397
- package/dist/orders-C1C5IEIP.js +0 -1
- package/dist/regular-slots-Cc1jmKuC.mjs +0 -222
- package/dist/regular-slots-DBs1XVeN.js +0 -1
- package/dist/src/appointments/pages/edit/regular-slots.vue.d.ts +0 -2
- package/dist/utils-BVKy9S2J.mjs +0 -29
- package/dist/utils-D6CaKJbp.js +0 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),D=require("./EditLayout.vue_vue_type_script_setup_true_lang-ozYrxb2g.js"),V=require("lucide-vue-next"),_=require("@oneclick.dev/cms-kit"),R=require("./index-ijdf0d9-.js"),$={class:"flex gap-3 items-start p-4 border rounded-lg"},M={class:"flex-1 space-y-3"},L={class:"grid grid-cols-2 gap-3"},z={class:"flex items-center space-x-2 my-4"},j={class:"grid grid-cols-2 gap-2"},q={key:0},F={key:1},G={key:2},H={key:3},K={key:4},W={key:0},Y=e.defineComponent({__name:"Addon",props:{addOn:{type:Object,required:!0}},setup(a){const f=e.inject("form"),x=p=>{f.addOns=f.addOns.filter(o=>o.id!==p)};return(p,o)=>{const i=e.resolveComponent("Label"),m=e.resolveComponent("Input"),N=e.resolveComponent("Checkbox"),v=e.resolveComponent("SelectTrigger"),c=e.resolveComponent("SelectItem"),y=e.resolveComponent("SelectGroup"),T=e.resolveComponent("SelectContent"),B=e.resolveComponent("Select"),S=e.resolveComponent("Trash2"),O=e.resolveComponent("Button");return e.openBlock(),e.createElementBlock("div",$,[e.createElementVNode("div",M,[e.createElementVNode("div",L,[e.createElementVNode("div",null,[e.createVNode(i,{class:"text-xs mb-1 block"},{default:e.withCtx(()=>[...o[7]||(o[7]=[e.createTextVNode("Add-on Name",-1)])]),_:1}),e.createVNode(m,{modelValue:a.addOn.name,"onUpdate:modelValue":o[0]||(o[0]=u=>a.addOn.name=u),placeholder:"e.g., Swimsuit Rental, Towel Service"},null,8,["modelValue"])]),e.createElementVNode("div",null,[e.createVNode(i,{class:"text-xs mb-1 block"},{default:e.withCtx(()=>[...o[8]||(o[8]=[e.createTextVNode("Price",-1)])]),_:1}),e.createVNode(m,{modelValue:a.addOn.price,"onUpdate:modelValue":o[1]||(o[1]=u=>a.addOn.price=u),modelModifiers:{number:!0},type:"number",min:"0",step:"0.01",placeholder:"0.00",class:"no-spinner"},null,8,["modelValue"])])]),e.createElementVNode("div",null,[e.createVNode(i,{class:"text-xs mb-1 block"},{default:e.withCtx(()=>[...o[9]||(o[9]=[e.createTextVNode("Description (Optional)",-1)])]),_:1}),e.createVNode(m,{modelValue:a.addOn.description,"onUpdate:modelValue":o[2]||(o[2]=u=>a.addOn.description=u),placeholder:"Brief description of this add-on"},null,8,["modelValue"])]),e.createElementVNode("div",z,[e.createVNode(N,{id:`required-${a.addOn.id}`,modelValue:a.addOn.required,"onUpdate:modelValue":o[3]||(o[3]=u=>a.addOn.required=u)},null,8,["id","modelValue"]),e.createVNode(i,{for:`required-${a.addOn.id}`,class:"text-xs font-normal cursor-pointer"},{default:e.withCtx(()=>[...o[10]||(o[10]=[e.createTextVNode(" Required (customer must select this add-on) ",-1)])]),_:1},8,["for"])]),e.createElementVNode("div",j,[e.createElementVNode("div",null,[e.createVNode(i,{class:"text-xs mb-1 block"},{default:e.withCtx(()=>[...o[11]||(o[11]=[e.createTextVNode("Quantity limit",-1)])]),_:1}),e.createVNode(B,{modelValue:a.addOn.scope,"onUpdate:modelValue":o[4]||(o[4]=u=>a.addOn.scope=u)},{default:e.withCtx(()=>[e.createVNode(v,{class:"w-full"},{default:e.withCtx(()=>[a.addOn.scope==="RESERVATION"?(e.openBlock(),e.createElementBlock("span",q,"Once per reservation")):a.addOn.scope==="TICKET"?(e.openBlock(),e.createElementBlock("span",F,"Once per ticket / person")):a.addOn.scope==="UNLIMITED"?(e.openBlock(),e.createElementBlock("span",G,"Unlimited")):a.addOn.scope==="CUSTOM_LIMIT"?(e.openBlock(),e.createElementBlock("span",H,"Custom limit...")):(e.openBlock(),e.createElementBlock("span",K,"Select a limit…"))]),_:1}),e.createVNode(T,null,{default:e.withCtx(()=>[e.createVNode(y,{class:"max-w-96"},{default:e.withCtx(()=>[e.createVNode(c,{value:"RESERVATION"},{default:e.withCtx(()=>[...o[12]||(o[12]=[e.createElementVNode("div",{class:"flex flex-col"},[e.createElementVNode("p",{class:"text-sm font-bold mb-1"},"Once per reservation"),e.createElementVNode("p",{class:"text-xs"},"Max 1 per reservation line (charged per reservation).")],-1)])]),_:1}),e.createVNode(c,{value:"TICKET"},{default:e.withCtx(()=>[...o[13]||(o[13]=[e.createElementVNode("div",{class:"flex flex-col"},[e.createElementVNode("p",{class:"text-sm font-bold mb-1"},"Once per ticket / person"),e.createElementVNode("p",{class:"text-xs"},"Max 1 per ticket/person (charged per quantity).")],-1)])]),_:1}),e.createVNode(c,{value:"UNLIMITED"},{default:e.withCtx(()=>[...o[14]||(o[14]=[e.createElementVNode("div",{class:"flex flex-col"},[e.createElementVNode("p",{class:"text-sm font-bold mb-1"},"Unlimited"),e.createElementVNode("p",{class:"text-xs"},"No limit (can be added multiple times).")],-1)])]),_:1}),e.createVNode(c,{value:"CUSTOM_LIMIT"},{default:e.withCtx(()=>[...o[15]||(o[15]=[e.createElementVNode("div",{class:"flex flex-col"},[e.createElementVNode("p",{class:"text-sm font-bold mb-1"},"Custom limit..."),e.createElementVNode("p",{class:"text-xs"},"Set a fixed max amount (e.g. 2, 5, 10).")],-1)])]),_:1})]),_:1})]),_:1})]),_:1},8,["modelValue"])]),a.addOn.scope==="CUSTOM_LIMIT"?(e.openBlock(),e.createElementBlock("div",W,[e.createVNode(i,{class:"text-xs mb-1 block"},{default:e.withCtx(()=>[...o[16]||(o[16]=[e.createTextVNode("Fixed limit",-1)])]),_:1}),e.createVNode(m,{modelValue:a.addOn.limit,"onUpdate:modelValue":o[5]||(o[5]=u=>a.addOn.limit=u),modelModifiers:{number:!0},type:"number",min:"1",step:"1",placeholder:"1",class:"no-spinner"},null,8,["modelValue"])])):e.createCommentVNode("",!0)])]),e.createVNode(O,{onClick:o[6]||(o[6]=u=>x(a.addOn.id)),variant:"ghost",size:"icon",class:"mt-6"},{default:e.withCtx(()=>[e.createVNode(S,{class:"w-4 h-4 text-destructive"})]),_:1})])}}}),Q={class:"grid gap-2"},J=["id"],X=["onClick"],Z={class:"flex items-center gap-2"},ee={class:"flex items-center gap-1"},te={class:"overflow-hidden"},oe=e.defineComponent({__name:"AddonList",setup(a,{expose:f}){const{confirm:x}=_.useConfirmation(),p=e.inject("form"),o=e.ref([]),i=async m=>{if(!await x("Are you sure you want to remove this add-on?"))return;p.addOns=p.addOns.filter(c=>c.id!==m);const v=o.value.indexOf(m);v!==-1&&o.value.splice(v,1),R.toast("Success!",{description:"Add-on removed successfully."})};return f({openAddons:o}),(m,N)=>{const v=e.resolveComponent("Button");return e.openBlock(),e.createElementBlock("div",Q,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(p).addOns,c=>(e.openBlock(),e.createElementBlock("div",{key:c.id,class:"border p-2 rounded",id:`addon-${c.id}`},[e.createElementVNode("div",{onClick:y=>o.value.includes(c.id)?o.value.splice(o.value.indexOf(c.id),1):o.value.push(c.id),class:"cursor-pointer font-bold text-muted-foreground flex items-center justify-between gap-2 select-none"},[e.createElementVNode("span",Z,[e.createVNode(e.unref(V.DollarSign),{class:"size-4"}),e.createTextVNode(" "+e.toDisplayString(c.name||"Untitled Add-on"),1)]),e.createElementVNode("div",ee,[e.createVNode(v,{variant:"ghost",size:"icon"},{default:e.withCtx(()=>[e.createVNode(e.unref(V.Pencil),{class:"size-4"})]),_:1}),e.createVNode(v,{variant:"ghost",size:"icon",onClick:e.withModifiers(y=>i(c.id),["stop"])},{default:e.withCtx(()=>[e.createVNode(e.unref(V.Trash2),{class:"size-4 text-red-500"})]),_:1},8,["onClick"])])],8,X),e.createElementVNode("div",{class:e.normalizeClass(["grid",`${o.value.includes(c.id)?"grid-rows-[1fr]":"grid-rows-[0fr]"} transition-all duration-300 ease-in-out overflow-hidden`])},[e.createElementVNode("div",te,[e.createVNode(Y,{addOn:c},null,8,["addOn"])])],2)],8,J))),128))])}}}),ne={class:"flex items-center justify-between mb-4"},le={class:"space-y-3"},de={key:0,class:"text-center py-8 text-muted-foreground text-sm border rounded-lg"},ae=e.defineComponent({__name:"index",setup(a){const f=e.inject("form"),x=e.useTemplateRef("addonList"),p=async()=>{const o=Math.random().toString(36).substr(2,9);f.addOns.push({id:o,name:"",description:"",price:0,required:!1}),x.value?.openAddons.push(o),await e.nextTick(),document.getElementById(`addon-${o}`)?.scrollIntoView({behavior:"smooth",block:"start"})};return(o,i)=>{const m=e.resolveComponent("Label"),N=e.resolveComponent("Button");return e.openBlock(),e.createElementBlock("div",null,[e.createElementVNode("div",ne,[e.createElementVNode("div",null,[e.createVNode(m,{class:"text-base font-medium"},{default:e.withCtx(()=>[...i[0]||(i[0]=[e.createTextVNode(" Optional Add-ons & Upcharges ",-1)])]),_:1}),i[1]||(i[1]=e.createElementVNode("p",{class:"text-sm text-muted-foreground mt-1"}," Offer optional extras that customers can add to their booking (e.g., swimsuit rental). ",-1))]),e.createVNode(N,{onClick:p,variant:"outline",size:"sm"},{default:e.withCtx(()=>[e.createVNode(e.unref(V.PlusCircle),{class:"w-4 h-4 mr-2"}),i[2]||(i[2]=e.createTextVNode(" Add Add-on ",-1))]),_:1})]),e.createElementVNode("div",le,[e.createVNode(oe,{ref_key:"addonList",ref:x},null,512),e.unref(f).addOns.length===0?(e.openBlock(),e.createElementBlock("div",de,' No add-ons configured. Click "Add Add-on" to create optional extras. ')):e.createCommentVNode("",!0)])])}}}),re={key:0,class:"max-w-2xl space-y-12"},se={class:"flex gap-4 items-end"},ie={class:"w-32"},ce={class:"flex items-center justify-between mb-4 gap-4"},ue={class:"space-y-3"},me={class:"flex-1 space-y-3"},pe={class:"flex gap-3"},Ve={class:"flex-1"},fe={class:"flex-1"},xe={class:"flex items-end"},Ne={class:"flex items-center justify-between mb-4"},ve={class:"space-y-3"},ge={class:"flex-1 space-y-3"},Ce={class:"grid grid-cols-2 gap-3"},ye={class:"grid grid-cols-2 gap-3"},ke={key:0},we={class:"flex items-center gap-2"},Ee={key:0},be={key:1},he={key:2},_e={class:"space-y-1"},Te=["onClick"],Be={class:"size-5 rounded-full bg-muted flex items-center justify-center"},Se={key:0,class:"w-full h-full rounded-full bg-white scale-50"},Oe=["onClick"],Pe={class:"text-sm flex-1 truncate"},Ie={key:0,class:"w-3 h-3 text-white",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},Ue={key:0,class:"text-center py-8 text-muted-foreground text-sm border rounded-lg"},Ae={key:0,class:"mt-6 p-4 border rounded-lg bg-muted/30"},De={class:"space-y-4"},Re={class:"flex items-center gap-3"},$e={class:"flex-1"},Me={class:"text-sm text-muted-foreground"},Le={class:"text-xs text-muted-foreground"},ze={class:"flex justify-start pt-4 border-t"},je=e.defineComponent({__name:"payment",setup(a){const{params:f}=_.useModuleRoute(),{config:x}=_.useModule(),p=_.useFirebaseIntegration(x.project),o=e.reactive({paymentType:"full",currency:"USD",partialPayment:{type:"percentage",amount:50},pricingOptions:[{id:"1",name:"Standard Service",price:0,duration:30,isDefault:!0}],pricingRules:[],addOns:[]}),i=e.ref(!1),m=e.ref(!0),N=e.ref([]),v=(l,t)=>{if(!l.resourceIds)l.resourceIds=[t];else{const r=l.resourceIds.indexOf(t);r===-1?l.resourceIds.push(t):l.resourceIds.splice(r,1)}},c=(l,t)=>{l.resourceIds=t?null:[]},y=async()=>{i.value=!0;try{const l=f.value.id;if(!l)throw new Error("Missing agenda ID");await p.update(x.agendaCollection,l,{paymentType:o.paymentType||"full",currency:o.currency||"USD",partialPayment:{type:o.partialPayment.type||"percentage",amount:Math.max(Number(o.partialPayment.amount)||0,0)},pricingOptions:o.pricingOptions??[],pricingRules:o.pricingRules??[],addOns:o.addOns??[]})}catch(l){console.error("Error saving changes:",l)}finally{i.value=!1}},T=()=>{const l=Math.random().toString(36).substr(2,9);o.pricingOptions.push({id:l,name:"",price:0,duration:30,isDefault:!1})},B=l=>{o.pricingOptions=o.pricingOptions.filter(t=>t.id!==l)},S=l=>{o.pricingOptions.forEach(t=>{t.isDefault=t.id===l})},O=()=>{const l=Math.random().toString(36).substr(2,9);o.pricingRules.push({id:l,name:"",condition:"time_after",conditionValue:"17:00",modifier:"fixed",amount:10,resourceIds:null})},u=l=>{o.pricingRules=o.pricingRules.filter(t=>t.id!==l)};return(async()=>{try{const l=await p.get(x.agendaCollection,f.value.id);l&&(o.paymentType=l.paymentType||"full",o.currency=l.currency||"USD",o.partialPayment={type:l.partialPayment?.type||"percentage",amount:Number(l.partialPayment?.amount)&&l.partialPayment.amount>0?parseFloat(l.partialPayment.amount):50},o.pricingOptions=l.pricingOptions||[{id:"1",name:"Standard Service",price:0,duration:30,isDefault:!0}],o.pricingRules=l.pricingRules||[],o.addOns=l.addOns||[],N.value=(l.resources||[]).filter(t=>t.isActive))}catch(l){console.error("Error loading agenda data:",l)}finally{m.value=!1}})(),e.provide("form",o),(l,t)=>{const r=e.resolveComponent("Label"),w=e.resolveComponent("SelectValue"),E=e.resolveComponent("SelectTrigger"),s=e.resolveComponent("SelectItem"),b=e.resolveComponent("SelectContent"),h=e.resolveComponent("Select"),g=e.resolveComponent("Button"),C=e.resolveComponent("Input"),I=e.resolveComponent("PopoverTrigger"),U=e.resolveComponent("PopoverContent"),A=e.resolveComponent("Popover"),k=e.resolveComponent("RadioGroupItem"),P=e.resolveComponent("RadioGroup");return e.openBlock(),e.createBlock(D._sfc_main,null,{default:e.withCtx(()=>[t[53]||(t[53]=e.createElementVNode("h1",{class:"text-lg font-medium mb-8"},"Payment Settings",-1)),m.value?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("div",re,[e.createElementVNode("div",null,[e.createElementVNode("div",se,[e.createElementVNode("div",ie,[e.createVNode(r,{class:"text-base font-medium mb-2"},{default:e.withCtx(()=>[...t[4]||(t[4]=[e.createTextVNode(" Currency ",-1)])]),_:1}),e.createVNode(h,{modelValue:o.currency,"onUpdate:modelValue":t[0]||(t[0]=n=>o.currency=n)},{default:e.withCtx(()=>[e.createVNode(E,{id:"currency"},{default:e.withCtx(()=>[e.createVNode(w,{placeholder:"Currency"})]),_:1}),e.createVNode(b,null,{default:e.withCtx(()=>[e.createVNode(s,{value:"USD"},{default:e.withCtx(()=>[...t[5]||(t[5]=[e.createTextVNode("USD ($)",-1)])]),_:1}),e.createVNode(s,{value:"EUR"},{default:e.withCtx(()=>[...t[6]||(t[6]=[e.createTextVNode("EUR (€)",-1)])]),_:1}),e.createVNode(s,{value:"GBP"},{default:e.withCtx(()=>[...t[7]||(t[7]=[e.createTextVNode("GBP (£)",-1)])]),_:1}),e.createVNode(s,{value:"CAD"},{default:e.withCtx(()=>[...t[8]||(t[8]=[e.createTextVNode("CAD ($)",-1)])]),_:1})]),_:1})]),_:1},8,["modelValue"])])])]),e.createElementVNode("div",null,[e.createElementVNode("div",ce,[e.createElementVNode("div",null,[e.createVNode(r,{class:"text-base font-medium"},{default:e.withCtx(()=>[...t[9]||(t[9]=[e.createTextVNode(" Service Pricing Options ",-1)])]),_:1}),t[10]||(t[10]=e.createElementVNode("p",{class:"text-sm text-muted-foreground mt-1"}," Offer multiple service variations with different prices (e.g., haircut styles, massage types). ",-1))]),e.createVNode(g,{onClick:T,variant:"outline",size:"sm"},{default:e.withCtx(()=>[e.createVNode(e.unref(V.PlusCircle),{class:"w-4 h-4 mr-2"}),t[11]||(t[11]=e.createTextVNode(" Add Option ",-1))]),_:1})]),e.createElementVNode("div",ue,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(o.pricingOptions,n=>(e.openBlock(),e.createElementBlock("div",{key:n.id,class:"flex gap-3 items-start p-4 border rounded-lg"},[e.createElementVNode("div",me,[e.createElementVNode("div",null,[e.createVNode(r,{class:"text-xs mb-1 block"},{default:e.withCtx(()=>[...t[12]||(t[12]=[e.createTextVNode("Service Name",-1)])]),_:1}),e.createVNode(C,{modelValue:n.name,"onUpdate:modelValue":d=>n.name=d,placeholder:"e.g., Men's Haircut, Women's Haircut"},null,8,["modelValue","onUpdate:modelValue"])]),e.createElementVNode("div",pe,[e.createElementVNode("div",Ve,[e.createVNode(r,{class:"text-xs mb-1 block"},{default:e.withCtx(()=>[...t[13]||(t[13]=[e.createTextVNode("Price",-1)])]),_:1}),e.createVNode(C,{modelValue:n.price,"onUpdate:modelValue":d=>n.price=d,modelModifiers:{number:!0},type:"number",min:"0",step:"0.01",placeholder:"0.00",class:"no-spinner"},null,8,["modelValue","onUpdate:modelValue"])]),e.createElementVNode("div",fe,[e.createVNode(r,{class:"text-xs mb-1 block"},{default:e.withCtx(()=>[...t[14]||(t[14]=[e.createTextVNode("Duration",-1)])]),_:1}),e.createVNode(h,{modelValue:n.duration,"onUpdate:modelValue":d=>n.duration=d,modelModifiers:{number:!0}},{default:e.withCtx(()=>[e.createVNode(E,null,{default:e.withCtx(()=>[e.createVNode(w,{placeholder:"Duration"})]),_:1}),e.createVNode(b,null,{default:e.withCtx(()=>[e.createVNode(s,{value:15},{default:e.withCtx(()=>[...t[15]||(t[15]=[e.createTextVNode("15 min",-1)])]),_:1}),e.createVNode(s,{value:30},{default:e.withCtx(()=>[...t[16]||(t[16]=[e.createTextVNode("30 min",-1)])]),_:1}),e.createVNode(s,{value:45},{default:e.withCtx(()=>[...t[17]||(t[17]=[e.createTextVNode("45 min",-1)])]),_:1}),e.createVNode(s,{value:60},{default:e.withCtx(()=>[...t[18]||(t[18]=[e.createTextVNode("1 hour",-1)])]),_:1}),e.createVNode(s,{value:90},{default:e.withCtx(()=>[...t[19]||(t[19]=[e.createTextVNode("1.5 hours",-1)])]),_:1}),e.createVNode(s,{value:120},{default:e.withCtx(()=>[...t[20]||(t[20]=[e.createTextVNode("2 hours",-1)])]),_:1}),e.createVNode(s,{value:180},{default:e.withCtx(()=>[...t[21]||(t[21]=[e.createTextVNode("3 hours",-1)])]),_:1}),e.createVNode(s,{value:240},{default:e.withCtx(()=>[...t[22]||(t[22]=[e.createTextVNode("4 hours",-1)])]),_:1}),e.createVNode(s,{value:300},{default:e.withCtx(()=>[...t[23]||(t[23]=[e.createTextVNode("5 hours",-1)])]),_:1}),e.createVNode(s,{value:360},{default:e.withCtx(()=>[...t[24]||(t[24]=[e.createTextVNode("6 hours",-1)])]),_:1}),e.createVNode(s,{value:480},{default:e.withCtx(()=>[...t[25]||(t[25]=[e.createTextVNode("8 hours",-1)])]),_:1})]),_:1})]),_:1},8,["modelValue","onUpdate:modelValue"])]),e.createElementVNode("div",xe,[e.createVNode(g,{onClick:d=>S(n.id),variant:n.isDefault?"default":"outline",size:"sm"},{default:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(n.isDefault?"Default":"Set Default"),1)]),_:2},1032,["onClick","variant"])])])]),o.pricingOptions.length>1?(e.openBlock(),e.createBlock(g,{key:0,onClick:d=>B(n.id),variant:"ghost",size:"icon",class:"mt-6"},{default:e.withCtx(()=>[e.createVNode(e.unref(V.Trash2),{class:"w-4 h-4 text-destructive"})]),_:1},8,["onClick"])):e.createCommentVNode("",!0)]))),128))])]),e.createElementVNode("div",null,[e.createElementVNode("div",Ne,[e.createElementVNode("div",null,[e.createVNode(r,{class:"text-base font-medium"},{default:e.withCtx(()=>[...t[26]||(t[26]=[e.createTextVNode(" Conditional Pricing Rules ",-1)])]),_:1}),t[27]||(t[27]=e.createElementVNode("p",{class:"text-sm text-muted-foreground mt-1"}," Add extra fees based on time, day, or other conditions (e.g., +€10 after 5pm). ",-1))]),e.createVNode(g,{onClick:O,variant:"outline",size:"sm"},{default:e.withCtx(()=>[e.createVNode(e.unref(V.PlusCircle),{class:"w-4 h-4 mr-2"}),t[28]||(t[28]=e.createTextVNode(" Add Rule ",-1))]),_:1})]),e.createElementVNode("div",ve,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(o.pricingRules,n=>(e.openBlock(),e.createElementBlock("div",{key:n.id,class:"flex gap-3 items-start p-4 border rounded-lg"},[e.createElementVNode("div",ge,[e.createElementVNode("div",null,[e.createVNode(r,{class:"text-xs mb-1 block"},{default:e.withCtx(()=>[...t[29]||(t[29]=[e.createTextVNode("Rule Name",-1)])]),_:1}),e.createVNode(C,{modelValue:n.name,"onUpdate:modelValue":d=>n.name=d,placeholder:"e.g., After Hours Fee, Weekend Surcharge"},null,8,["modelValue","onUpdate:modelValue"])]),e.createElementVNode("div",Ce,[e.createElementVNode("div",null,[e.createVNode(r,{class:"text-xs mb-1 block"},{default:e.withCtx(()=>[...t[30]||(t[30]=[e.createTextVNode("Condition",-1)])]),_:1}),e.createVNode(h,{modelValue:n.condition,"onUpdate:modelValue":d=>n.condition=d},{default:e.withCtx(()=>[e.createVNode(E,null,{default:e.withCtx(()=>[e.createVNode(w,{placeholder:"Select condition"})]),_:1}),e.createVNode(b,null,{default:e.withCtx(()=>[e.createVNode(s,{value:"time_after"},{default:e.withCtx(()=>[...t[31]||(t[31]=[e.createTextVNode("Time After",-1)])]),_:1}),e.createVNode(s,{value:"time_before"},{default:e.withCtx(()=>[...t[32]||(t[32]=[e.createTextVNode("Time Before",-1)])]),_:1}),e.createVNode(s,{value:"time_between"},{default:e.withCtx(()=>[...t[33]||(t[33]=[e.createTextVNode("Time Between",-1)])]),_:1}),e.createVNode(s,{value:"day_of_week"},{default:e.withCtx(()=>[...t[34]||(t[34]=[e.createTextVNode("Day of Week",-1)])]),_:1}),e.createVNode(s,{value:"date_range"},{default:e.withCtx(()=>[...t[35]||(t[35]=[e.createTextVNode("Date Range",-1)])]),_:1})]),_:1})]),_:1},8,["modelValue","onUpdate:modelValue"])]),e.createElementVNode("div",null,[e.createVNode(r,{class:"text-xs mb-1 block"},{default:e.withCtx(()=>[...t[36]||(t[36]=[e.createTextVNode("Value",-1)])]),_:1}),e.createVNode(C,{modelValue:n.conditionValue,"onUpdate:modelValue":d=>n.conditionValue=d,type:n.condition.includes("time")?"time":"text",placeholder:"e.g., 17:00"},null,8,["modelValue","onUpdate:modelValue","type"])])]),e.createElementVNode("div",ye,[e.createElementVNode("div",null,[e.createVNode(r,{class:"text-xs mb-1 block"},{default:e.withCtx(()=>[...t[37]||(t[37]=[e.createTextVNode("Fee Type",-1)])]),_:1}),e.createVNode(h,{modelValue:n.modifier,"onUpdate:modelValue":d=>n.modifier=d},{default:e.withCtx(()=>[e.createVNode(E,null,{default:e.withCtx(()=>[e.createVNode(w,{placeholder:"Select type"})]),_:1}),e.createVNode(b,null,{default:e.withCtx(()=>[e.createVNode(s,{value:"fixed"},{default:e.withCtx(()=>[...t[38]||(t[38]=[e.createTextVNode("Fixed Amount",-1)])]),_:1}),e.createVNode(s,{value:"percentage"},{default:e.withCtx(()=>[...t[39]||(t[39]=[e.createTextVNode("Percentage",-1)])]),_:1})]),_:1})]),_:1},8,["modelValue","onUpdate:modelValue"])]),e.createElementVNode("div",null,[e.createVNode(r,{class:"text-xs mb-1 block"},{default:e.withCtx(()=>[...t[40]||(t[40]=[e.createTextVNode("Amount",-1)])]),_:1}),e.createVNode(C,{modelValue:n.amount,"onUpdate:modelValue":d=>n.amount=d,modelModifiers:{number:!0},type:"number",min:"0",step:"0.01",class:"no-spinner",placeholder:n.modifier==="percentage"?"10 (%)":"10.00"},null,8,["modelValue","onUpdate:modelValue","placeholder"])])]),N.value.length>0?(e.openBlock(),e.createElementBlock("div",ke,[e.createVNode(r,{class:"text-xs mb-1 block"},{default:e.withCtx(()=>[...t[41]||(t[41]=[e.createTextVNode("Apply To Resources",-1)])]),_:1}),e.createVNode(A,null,{default:e.withCtx(()=>[e.createVNode(I,{"as-child":""},{default:e.withCtx(()=>[e.createVNode(g,{variant:"outline",class:"w-full justify-between font-normal"},{default:e.withCtx(()=>[e.createElementVNode("div",we,[e.createVNode(e.unref(V.Users),{class:"w-4 h-4 text-muted-foreground"}),!n.resourceIds||n.resourceIds.length===0?(e.openBlock(),e.createElementBlock("span",Ee,"All Resources")):n.resourceIds.length===1?(e.openBlock(),e.createElementBlock("span",be,e.toDisplayString(N.value.find(d=>d.id===n.resourceIds[0])?.name||"1 resource"),1)):(e.openBlock(),e.createElementBlock("span",he,e.toDisplayString(n.resourceIds.length)+" resources",1))]),e.createVNode(e.unref(V.ChevronDown),{class:"w-4 h-4 opacity-50"})]),_:2},1024)]),_:2},1024),e.createVNode(U,{class:"w-64 p-2",align:"start"},{default:e.withCtx(()=>[e.createElementVNode("div",_e,[e.createElementVNode("div",{class:e.normalizeClass(["flex items-center gap-2 p-2 rounded-md hover:bg-muted cursor-pointer transition-colors",{"bg-muted":!n.resourceIds||n.resourceIds.length===0}]),onClick:d=>c(n,!0)},[e.createElementVNode("div",Be,[e.createVNode(e.unref(V.Users),{class:"w-3 h-3 text-muted-foreground"})]),t[42]||(t[42]=e.createElementVNode("span",{class:"text-sm flex-1"},"All Resources",-1)),e.createElementVNode("div",{class:e.normalizeClass(["size-4 rounded-full border-2",!n.resourceIds||n.resourceIds.length===0?"border-primary bg-primary":"border-muted-foreground"])},[!n.resourceIds||n.resourceIds.length===0?(e.openBlock(),e.createElementBlock("div",Se)):e.createCommentVNode("",!0)],2)],10,Te),t[44]||(t[44]=e.createElementVNode("div",{class:"border-t my-2"},null,-1)),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(N.value,d=>(e.openBlock(),e.createElementBlock("div",{key:d.id,class:"flex items-center gap-2 p-2 rounded-md hover:bg-muted cursor-pointer transition-colors",onClick:Fe=>{c(n,!1),v(n,d.id)}},[e.createElementVNode("div",{class:"size-5 rounded-full flex items-center justify-center text-white text-[10px] font-medium",style:e.normalizeStyle({backgroundColor:d.color||"#6b7280"})},e.toDisplayString(d.avatarLabel||d.name.charAt(0).toUpperCase()),5),e.createElementVNode("span",Pe,e.toDisplayString(d.name),1),e.createElementVNode("div",{class:e.normalizeClass(["size-4 rounded border-2 flex items-center justify-center",n.resourceIds?.includes(d.id)?"border-primary bg-primary":"border-muted-foreground"])},[n.resourceIds?.includes(d.id)?(e.openBlock(),e.createElementBlock("svg",Ie,[...t[43]||(t[43]=[e.createElementVNode("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"3",d:"M5 13l4 4L19 7"},null,-1)])])):e.createCommentVNode("",!0)],2)],8,Oe))),128))])]),_:2},1024)]),_:2},1024)])):e.createCommentVNode("",!0)]),e.createVNode(g,{onClick:d=>u(n.id),variant:"ghost",size:"icon",class:"mt-6"},{default:e.withCtx(()=>[e.createVNode(e.unref(V.Trash2),{class:"w-4 h-4 text-destructive"})]),_:1},8,["onClick"])]))),128)),o.pricingRules.length===0?(e.openBlock(),e.createElementBlock("div",Ue,' No pricing rules configured. Click "Add Rule" to create conditional fees. ')):e.createCommentVNode("",!0)])]),e.createVNode(ae),e.createElementVNode("div",null,[e.createVNode(r,{class:"text-base font-medium"},{default:e.withCtx(()=>[...t[45]||(t[45]=[e.createTextVNode(" Payment Preferences ",-1)])]),_:1}),t[52]||(t[52]=e.createElementVNode("p",{class:"text-sm text-muted-foreground mb-6"}," Let customers pay full or in part when booking a slot, or pay later. ",-1)),e.createVNode(P,{modelValue:o.paymentType,"onUpdate:modelValue":t[1]||(t[1]=n=>o.paymentType=n),class:"flex flex-col gap-4"},{default:e.withCtx(()=>[e.createVNode(r,{for:"r1",class:"flex items-start space-x-2 cursor-pointer"},{default:e.withCtx(()=>[e.createVNode(k,{id:"r1",value:"full"}),t[46]||(t[46]=e.createElementVNode("div",null,[e.createElementVNode("p",null,"Pay Full Amount when Booking"),e.createElementVNode("p",{class:"text-sm text-muted-foreground mt-1"}," Your customers are required to complete the payment to confirm their booking. ")],-1))]),_:1}),e.createVNode(r,{for:"r2",class:"flex items-start space-x-2 cursor-pointer"},{default:e.withCtx(()=>[e.createVNode(k,{id:"r2",value:"partial"}),t[47]||(t[47]=e.createElementVNode("div",null,[e.createElementVNode("p",null,"Pay Part Amount when Booking"),e.createElementVNode("p",{class:"text-sm text-muted-foreground mt-1"}," Your customers are required to pay a deposit to confirm their booking. ")],-1))]),_:1}),e.createVNode(r,{for:"r3",class:"flex items-start space-x-2 cursor-pointer"},{default:e.withCtx(()=>[e.createVNode(k,{id:"r3",value:"later"}),t[48]||(t[48]=e.createElementVNode("div",null,[e.createElementVNode("p",null,"Pay Later at Appointment"),e.createElementVNode("p",{class:"text-sm text-muted-foreground mt-1"}," Your customers can book now and pay in person at the time of their appointment. ")],-1))]),_:1})]),_:1},8,["modelValue"]),o.paymentType==="partial"?(e.openBlock(),e.createElementBlock("div",Ae,[e.createVNode(r,{class:"text-sm font-medium mb-4 block"},{default:e.withCtx(()=>[...t[49]||(t[49]=[e.createTextVNode(" Deposit Amount Configuration ",-1)])]),_:1}),e.createElementVNode("div",De,[e.createVNode(P,{modelValue:o.partialPayment.type,"onUpdate:modelValue":t[2]||(t[2]=n=>o.partialPayment.type=n),class:"flex gap-4"},{default:e.withCtx(()=>[e.createVNode(r,{class:"flex items-center space-x-2 cursor-pointer"},{default:e.withCtx(()=>[e.createVNode(k,{value:"percentage"}),t[50]||(t[50]=e.createElementVNode("span",null,"Percentage",-1))]),_:1}),e.createVNode(r,{class:"flex items-center space-x-2 cursor-pointer"},{default:e.withCtx(()=>[e.createVNode(k,{value:"fixed"}),t[51]||(t[51]=e.createElementVNode("span",null,"Fixed Amount",-1))]),_:1})]),_:1},8,["modelValue"]),e.createElementVNode("div",Re,[e.createElementVNode("div",$e,[e.createVNode(C,{modelValue:o.partialPayment.amount,"onUpdate:modelValue":t[3]||(t[3]=n=>o.partialPayment.amount=n),modelModifiers:{number:!0},type:"number",min:"0",max:o.partialPayment.type==="percentage"?100:void 0,step:"0.01",placeholder:o.partialPayment.type==="percentage"?"50":"10.00",class:"no-spinner"},null,8,["modelValue","max","placeholder"])]),e.createElementVNode("span",Me,e.toDisplayString(o.partialPayment.type==="percentage"?"%":o.currency),1)]),e.createElementVNode("p",Le,[o.partialPayment.type==="percentage"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[e.createTextVNode(" Customers will pay "+e.toDisplayString(o.partialPayment.amount)+"% of the total price upfront. ",1)],64)):(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[e.createTextVNode(" Customers will pay "+e.toDisplayString(o.currency)+" "+e.toDisplayString(o.partialPayment.amount)+" upfront. ",1)],64))])])])):e.createCommentVNode("",!0)]),e.createElementVNode("div",ze,[e.createVNode(g,{onClick:y,disabled:i.value},{default:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(i.value?"Saving...":"Save Changes"),1)]),_:1},8,["disabled"])])]))]),_:1})}}});exports.default=je;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),D=require("./EditLayout.vue_vue_type_script_setup_true_lang-kpjbVSXg.js"),V=require("lucide-vue-next"),_=require("@oneclick.dev/cms-kit"),R=require("./index-ijdf0d9-.js"),$={class:"flex gap-3 items-start p-4 border rounded-lg"},M={class:"flex-1 space-y-3"},L={class:"grid grid-cols-2 gap-3"},z={class:"flex items-center space-x-2 my-4"},j={class:"grid grid-cols-2 gap-2"},q={key:0},F={key:1},G={key:2},H={key:3},K={key:4},W={key:0},Y=e.defineComponent({__name:"Addon",props:{addOn:{type:Object,required:!0}},setup(a){const f=e.inject("form"),x=p=>{f.addOns=f.addOns.filter(o=>o.id!==p)};return(p,o)=>{const i=e.resolveComponent("Label"),m=e.resolveComponent("Input"),N=e.resolveComponent("Checkbox"),v=e.resolveComponent("SelectTrigger"),c=e.resolveComponent("SelectItem"),y=e.resolveComponent("SelectGroup"),T=e.resolveComponent("SelectContent"),B=e.resolveComponent("Select"),S=e.resolveComponent("Trash2"),O=e.resolveComponent("Button");return e.openBlock(),e.createElementBlock("div",$,[e.createElementVNode("div",M,[e.createElementVNode("div",L,[e.createElementVNode("div",null,[e.createVNode(i,{class:"text-xs mb-1 block"},{default:e.withCtx(()=>[...o[7]||(o[7]=[e.createTextVNode("Add-on Name",-1)])]),_:1}),e.createVNode(m,{modelValue:a.addOn.name,"onUpdate:modelValue":o[0]||(o[0]=u=>a.addOn.name=u),placeholder:"e.g., Swimsuit Rental, Towel Service"},null,8,["modelValue"])]),e.createElementVNode("div",null,[e.createVNode(i,{class:"text-xs mb-1 block"},{default:e.withCtx(()=>[...o[8]||(o[8]=[e.createTextVNode("Price",-1)])]),_:1}),e.createVNode(m,{modelValue:a.addOn.price,"onUpdate:modelValue":o[1]||(o[1]=u=>a.addOn.price=u),modelModifiers:{number:!0},type:"number",min:"0",step:"0.01",placeholder:"0.00",class:"no-spinner"},null,8,["modelValue"])])]),e.createElementVNode("div",null,[e.createVNode(i,{class:"text-xs mb-1 block"},{default:e.withCtx(()=>[...o[9]||(o[9]=[e.createTextVNode("Description (Optional)",-1)])]),_:1}),e.createVNode(m,{modelValue:a.addOn.description,"onUpdate:modelValue":o[2]||(o[2]=u=>a.addOn.description=u),placeholder:"Brief description of this add-on"},null,8,["modelValue"])]),e.createElementVNode("div",z,[e.createVNode(N,{id:`required-${a.addOn.id}`,modelValue:a.addOn.required,"onUpdate:modelValue":o[3]||(o[3]=u=>a.addOn.required=u)},null,8,["id","modelValue"]),e.createVNode(i,{for:`required-${a.addOn.id}`,class:"text-xs font-normal cursor-pointer"},{default:e.withCtx(()=>[...o[10]||(o[10]=[e.createTextVNode(" Required (customer must select this add-on) ",-1)])]),_:1},8,["for"])]),e.createElementVNode("div",j,[e.createElementVNode("div",null,[e.createVNode(i,{class:"text-xs mb-1 block"},{default:e.withCtx(()=>[...o[11]||(o[11]=[e.createTextVNode("Quantity limit",-1)])]),_:1}),e.createVNode(B,{modelValue:a.addOn.scope,"onUpdate:modelValue":o[4]||(o[4]=u=>a.addOn.scope=u)},{default:e.withCtx(()=>[e.createVNode(v,{class:"w-full"},{default:e.withCtx(()=>[a.addOn.scope==="RESERVATION"?(e.openBlock(),e.createElementBlock("span",q,"Once per reservation")):a.addOn.scope==="TICKET"?(e.openBlock(),e.createElementBlock("span",F,"Once per ticket / person")):a.addOn.scope==="UNLIMITED"?(e.openBlock(),e.createElementBlock("span",G,"Unlimited")):a.addOn.scope==="CUSTOM_LIMIT"?(e.openBlock(),e.createElementBlock("span",H,"Custom limit...")):(e.openBlock(),e.createElementBlock("span",K,"Select a limit…"))]),_:1}),e.createVNode(T,null,{default:e.withCtx(()=>[e.createVNode(y,{class:"max-w-96"},{default:e.withCtx(()=>[e.createVNode(c,{value:"RESERVATION"},{default:e.withCtx(()=>[...o[12]||(o[12]=[e.createElementVNode("div",{class:"flex flex-col"},[e.createElementVNode("p",{class:"text-sm font-bold mb-1"},"Once per reservation"),e.createElementVNode("p",{class:"text-xs"},"Max 1 per reservation line (charged per reservation).")],-1)])]),_:1}),e.createVNode(c,{value:"TICKET"},{default:e.withCtx(()=>[...o[13]||(o[13]=[e.createElementVNode("div",{class:"flex flex-col"},[e.createElementVNode("p",{class:"text-sm font-bold mb-1"},"Once per ticket / person"),e.createElementVNode("p",{class:"text-xs"},"Max 1 per ticket/person (charged per quantity).")],-1)])]),_:1}),e.createVNode(c,{value:"UNLIMITED"},{default:e.withCtx(()=>[...o[14]||(o[14]=[e.createElementVNode("div",{class:"flex flex-col"},[e.createElementVNode("p",{class:"text-sm font-bold mb-1"},"Unlimited"),e.createElementVNode("p",{class:"text-xs"},"No limit (can be added multiple times).")],-1)])]),_:1}),e.createVNode(c,{value:"CUSTOM_LIMIT"},{default:e.withCtx(()=>[...o[15]||(o[15]=[e.createElementVNode("div",{class:"flex flex-col"},[e.createElementVNode("p",{class:"text-sm font-bold mb-1"},"Custom limit..."),e.createElementVNode("p",{class:"text-xs"},"Set a fixed max amount (e.g. 2, 5, 10).")],-1)])]),_:1})]),_:1})]),_:1})]),_:1},8,["modelValue"])]),a.addOn.scope==="CUSTOM_LIMIT"?(e.openBlock(),e.createElementBlock("div",W,[e.createVNode(i,{class:"text-xs mb-1 block"},{default:e.withCtx(()=>[...o[16]||(o[16]=[e.createTextVNode("Fixed limit",-1)])]),_:1}),e.createVNode(m,{modelValue:a.addOn.limit,"onUpdate:modelValue":o[5]||(o[5]=u=>a.addOn.limit=u),modelModifiers:{number:!0},type:"number",min:"1",step:"1",placeholder:"1",class:"no-spinner"},null,8,["modelValue"])])):e.createCommentVNode("",!0)])]),e.createVNode(O,{onClick:o[6]||(o[6]=u=>x(a.addOn.id)),variant:"ghost",size:"icon",class:"mt-6"},{default:e.withCtx(()=>[e.createVNode(S,{class:"w-4 h-4 text-destructive"})]),_:1})])}}}),Q={class:"grid gap-2"},J=["id"],X=["onClick"],Z={class:"flex items-center gap-2"},ee={class:"flex items-center gap-1"},te={class:"overflow-hidden"},oe=e.defineComponent({__name:"AddonList",setup(a,{expose:f}){const{confirm:x}=_.useConfirmation(),p=e.inject("form"),o=e.ref([]),i=async m=>{if(!await x("Are you sure you want to remove this add-on?"))return;p.addOns=p.addOns.filter(c=>c.id!==m);const v=o.value.indexOf(m);v!==-1&&o.value.splice(v,1),R.toast("Success!",{description:"Add-on removed successfully."})};return f({openAddons:o}),(m,N)=>{const v=e.resolveComponent("Button");return e.openBlock(),e.createElementBlock("div",Q,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(p).addOns,c=>(e.openBlock(),e.createElementBlock("div",{key:c.id,class:"border p-2 rounded",id:`addon-${c.id}`},[e.createElementVNode("div",{onClick:y=>o.value.includes(c.id)?o.value.splice(o.value.indexOf(c.id),1):o.value.push(c.id),class:"cursor-pointer font-bold text-muted-foreground flex items-center justify-between gap-2 select-none"},[e.createElementVNode("span",Z,[e.createVNode(e.unref(V.DollarSign),{class:"size-4"}),e.createTextVNode(" "+e.toDisplayString(c.name||"Untitled Add-on"),1)]),e.createElementVNode("div",ee,[e.createVNode(v,{variant:"ghost",size:"icon"},{default:e.withCtx(()=>[e.createVNode(e.unref(V.Pencil),{class:"size-4"})]),_:1}),e.createVNode(v,{variant:"ghost",size:"icon",onClick:e.withModifiers(y=>i(c.id),["stop"])},{default:e.withCtx(()=>[e.createVNode(e.unref(V.Trash2),{class:"size-4 text-red-500"})]),_:1},8,["onClick"])])],8,X),e.createElementVNode("div",{class:e.normalizeClass(["grid",`${o.value.includes(c.id)?"grid-rows-[1fr]":"grid-rows-[0fr]"} transition-all duration-300 ease-in-out overflow-hidden`])},[e.createElementVNode("div",te,[e.createVNode(Y,{addOn:c},null,8,["addOn"])])],2)],8,J))),128))])}}}),ne={class:"flex items-center justify-between mb-4"},le={class:"space-y-3"},de={key:0,class:"text-center py-8 text-muted-foreground text-sm border rounded-lg"},ae=e.defineComponent({__name:"index",setup(a){const f=e.inject("form"),x=e.useTemplateRef("addonList"),p=async()=>{const o=Math.random().toString(36).substr(2,9);f.addOns.push({id:o,name:"",description:"",price:0,required:!1}),x.value?.openAddons.push(o),await e.nextTick(),document.getElementById(`addon-${o}`)?.scrollIntoView({behavior:"smooth",block:"start"})};return(o,i)=>{const m=e.resolveComponent("Label"),N=e.resolveComponent("Button");return e.openBlock(),e.createElementBlock("div",null,[e.createElementVNode("div",ne,[e.createElementVNode("div",null,[e.createVNode(m,{class:"text-base font-medium"},{default:e.withCtx(()=>[...i[0]||(i[0]=[e.createTextVNode(" Optional Add-ons & Upcharges ",-1)])]),_:1}),i[1]||(i[1]=e.createElementVNode("p",{class:"text-sm text-muted-foreground mt-1"}," Offer optional extras that customers can add to their booking (e.g., swimsuit rental). ",-1))]),e.createVNode(N,{onClick:p,variant:"outline",size:"sm"},{default:e.withCtx(()=>[e.createVNode(e.unref(V.PlusCircle),{class:"w-4 h-4 mr-2"}),i[2]||(i[2]=e.createTextVNode(" Add Add-on ",-1))]),_:1})]),e.createElementVNode("div",le,[e.createVNode(oe,{ref_key:"addonList",ref:x},null,512),e.unref(f).addOns.length===0?(e.openBlock(),e.createElementBlock("div",de,' No add-ons configured. Click "Add Add-on" to create optional extras. ')):e.createCommentVNode("",!0)])])}}}),re={key:0,class:"max-w-2xl space-y-12"},se={class:"flex gap-4 items-end"},ie={class:"w-32"},ce={class:"flex items-center justify-between mb-4 gap-4"},ue={class:"space-y-3"},me={class:"flex-1 space-y-3"},pe={class:"flex gap-3"},Ve={class:"flex-1"},fe={class:"flex-1"},xe={class:"flex items-end"},Ne={class:"flex items-center justify-between mb-4"},ve={class:"space-y-3"},ge={class:"flex-1 space-y-3"},Ce={class:"grid grid-cols-2 gap-3"},ye={class:"grid grid-cols-2 gap-3"},ke={key:0},we={class:"flex items-center gap-2"},Ee={key:0},be={key:1},he={key:2},_e={class:"space-y-1"},Te=["onClick"],Be={class:"size-5 rounded-full bg-muted flex items-center justify-center"},Se={key:0,class:"w-full h-full rounded-full bg-white scale-50"},Oe=["onClick"],Pe={class:"text-sm flex-1 truncate"},Ie={key:0,class:"w-3 h-3 text-white",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},Ue={key:0,class:"text-center py-8 text-muted-foreground text-sm border rounded-lg"},Ae={key:0,class:"mt-6 p-4 border rounded-lg bg-muted/30"},De={class:"space-y-4"},Re={class:"flex items-center gap-3"},$e={class:"flex-1"},Me={class:"text-sm text-muted-foreground"},Le={class:"text-xs text-muted-foreground"},ze={class:"flex justify-start pt-4 border-t"},je=e.defineComponent({__name:"payment",setup(a){const{params:f}=_.useModuleRoute(),{config:x}=_.useModule(),p=_.useFirebaseIntegration(x.project),o=e.reactive({paymentType:"full",currency:"USD",partialPayment:{type:"percentage",amount:50},pricingOptions:[{id:"1",name:"Standard Service",price:0,duration:30,isDefault:!0}],pricingRules:[],addOns:[]}),i=e.ref(!1),m=e.ref(!0),N=e.ref([]),v=(l,t)=>{if(!l.resourceIds)l.resourceIds=[t];else{const r=l.resourceIds.indexOf(t);r===-1?l.resourceIds.push(t):l.resourceIds.splice(r,1)}},c=(l,t)=>{l.resourceIds=t?null:[]},y=async()=>{i.value=!0;try{const l=f.value.id;if(!l)throw new Error("Missing agenda ID");await p.update(x.agendaCollection,l,{paymentType:o.paymentType||"full",currency:o.currency||"USD",partialPayment:{type:o.partialPayment.type||"percentage",amount:Math.max(Number(o.partialPayment.amount)||0,0)},pricingOptions:o.pricingOptions??[],pricingRules:o.pricingRules??[],addOns:o.addOns??[]})}catch(l){console.error("Error saving changes:",l)}finally{i.value=!1}},T=()=>{const l=Math.random().toString(36).substr(2,9);o.pricingOptions.push({id:l,name:"",price:0,duration:30,isDefault:!1})},B=l=>{o.pricingOptions=o.pricingOptions.filter(t=>t.id!==l)},S=l=>{o.pricingOptions.forEach(t=>{t.isDefault=t.id===l})},O=()=>{const l=Math.random().toString(36).substr(2,9);o.pricingRules.push({id:l,name:"",condition:"time_after",conditionValue:"17:00",modifier:"fixed",amount:10,resourceIds:null})},u=l=>{o.pricingRules=o.pricingRules.filter(t=>t.id!==l)};return(async()=>{try{const l=await p.get(x.agendaCollection,f.value.id);l&&(o.paymentType=l.paymentType||"full",o.currency=l.currency||"USD",o.partialPayment={type:l.partialPayment?.type||"percentage",amount:Number(l.partialPayment?.amount)&&l.partialPayment.amount>0?parseFloat(l.partialPayment.amount):50},o.pricingOptions=l.pricingOptions||[{id:"1",name:"Standard Service",price:0,duration:30,isDefault:!0}],o.pricingRules=l.pricingRules||[],o.addOns=l.addOns||[],N.value=(l.resources||[]).filter(t=>t.isActive))}catch(l){console.error("Error loading agenda data:",l)}finally{m.value=!1}})(),e.provide("form",o),(l,t)=>{const r=e.resolveComponent("Label"),w=e.resolveComponent("SelectValue"),E=e.resolveComponent("SelectTrigger"),s=e.resolveComponent("SelectItem"),b=e.resolveComponent("SelectContent"),h=e.resolveComponent("Select"),g=e.resolveComponent("Button"),C=e.resolveComponent("Input"),I=e.resolveComponent("PopoverTrigger"),U=e.resolveComponent("PopoverContent"),A=e.resolveComponent("Popover"),k=e.resolveComponent("RadioGroupItem"),P=e.resolveComponent("RadioGroup");return e.openBlock(),e.createBlock(D._sfc_main,null,{default:e.withCtx(()=>[t[53]||(t[53]=e.createElementVNode("h1",{class:"text-lg font-medium mb-8"},"Payment Settings",-1)),m.value?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("div",re,[e.createElementVNode("div",null,[e.createElementVNode("div",se,[e.createElementVNode("div",ie,[e.createVNode(r,{class:"text-base font-medium mb-2"},{default:e.withCtx(()=>[...t[4]||(t[4]=[e.createTextVNode(" Currency ",-1)])]),_:1}),e.createVNode(h,{modelValue:o.currency,"onUpdate:modelValue":t[0]||(t[0]=n=>o.currency=n)},{default:e.withCtx(()=>[e.createVNode(E,{id:"currency"},{default:e.withCtx(()=>[e.createVNode(w,{placeholder:"Currency"})]),_:1}),e.createVNode(b,null,{default:e.withCtx(()=>[e.createVNode(s,{value:"USD"},{default:e.withCtx(()=>[...t[5]||(t[5]=[e.createTextVNode("USD ($)",-1)])]),_:1}),e.createVNode(s,{value:"EUR"},{default:e.withCtx(()=>[...t[6]||(t[6]=[e.createTextVNode("EUR (€)",-1)])]),_:1}),e.createVNode(s,{value:"GBP"},{default:e.withCtx(()=>[...t[7]||(t[7]=[e.createTextVNode("GBP (£)",-1)])]),_:1}),e.createVNode(s,{value:"CAD"},{default:e.withCtx(()=>[...t[8]||(t[8]=[e.createTextVNode("CAD ($)",-1)])]),_:1})]),_:1})]),_:1},8,["modelValue"])])])]),e.createElementVNode("div",null,[e.createElementVNode("div",ce,[e.createElementVNode("div",null,[e.createVNode(r,{class:"text-base font-medium"},{default:e.withCtx(()=>[...t[9]||(t[9]=[e.createTextVNode(" Service Pricing Options ",-1)])]),_:1}),t[10]||(t[10]=e.createElementVNode("p",{class:"text-sm text-muted-foreground mt-1"}," Offer multiple service variations with different prices (e.g., haircut styles, massage types). ",-1))]),e.createVNode(g,{onClick:T,variant:"outline",size:"sm"},{default:e.withCtx(()=>[e.createVNode(e.unref(V.PlusCircle),{class:"w-4 h-4 mr-2"}),t[11]||(t[11]=e.createTextVNode(" Add Option ",-1))]),_:1})]),e.createElementVNode("div",ue,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(o.pricingOptions,n=>(e.openBlock(),e.createElementBlock("div",{key:n.id,class:"flex gap-3 items-start p-4 border rounded-lg"},[e.createElementVNode("div",me,[e.createElementVNode("div",null,[e.createVNode(r,{class:"text-xs mb-1 block"},{default:e.withCtx(()=>[...t[12]||(t[12]=[e.createTextVNode("Service Name",-1)])]),_:1}),e.createVNode(C,{modelValue:n.name,"onUpdate:modelValue":d=>n.name=d,placeholder:"e.g., Men's Haircut, Women's Haircut"},null,8,["modelValue","onUpdate:modelValue"])]),e.createElementVNode("div",pe,[e.createElementVNode("div",Ve,[e.createVNode(r,{class:"text-xs mb-1 block"},{default:e.withCtx(()=>[...t[13]||(t[13]=[e.createTextVNode("Price",-1)])]),_:1}),e.createVNode(C,{modelValue:n.price,"onUpdate:modelValue":d=>n.price=d,modelModifiers:{number:!0},type:"number",min:"0",step:"0.01",placeholder:"0.00",class:"no-spinner"},null,8,["modelValue","onUpdate:modelValue"])]),e.createElementVNode("div",fe,[e.createVNode(r,{class:"text-xs mb-1 block"},{default:e.withCtx(()=>[...t[14]||(t[14]=[e.createTextVNode("Duration",-1)])]),_:1}),e.createVNode(h,{modelValue:n.duration,"onUpdate:modelValue":d=>n.duration=d,modelModifiers:{number:!0}},{default:e.withCtx(()=>[e.createVNode(E,null,{default:e.withCtx(()=>[e.createVNode(w,{placeholder:"Duration"})]),_:1}),e.createVNode(b,null,{default:e.withCtx(()=>[e.createVNode(s,{value:15},{default:e.withCtx(()=>[...t[15]||(t[15]=[e.createTextVNode("15 min",-1)])]),_:1}),e.createVNode(s,{value:30},{default:e.withCtx(()=>[...t[16]||(t[16]=[e.createTextVNode("30 min",-1)])]),_:1}),e.createVNode(s,{value:45},{default:e.withCtx(()=>[...t[17]||(t[17]=[e.createTextVNode("45 min",-1)])]),_:1}),e.createVNode(s,{value:60},{default:e.withCtx(()=>[...t[18]||(t[18]=[e.createTextVNode("1 hour",-1)])]),_:1}),e.createVNode(s,{value:90},{default:e.withCtx(()=>[...t[19]||(t[19]=[e.createTextVNode("1.5 hours",-1)])]),_:1}),e.createVNode(s,{value:120},{default:e.withCtx(()=>[...t[20]||(t[20]=[e.createTextVNode("2 hours",-1)])]),_:1}),e.createVNode(s,{value:180},{default:e.withCtx(()=>[...t[21]||(t[21]=[e.createTextVNode("3 hours",-1)])]),_:1}),e.createVNode(s,{value:240},{default:e.withCtx(()=>[...t[22]||(t[22]=[e.createTextVNode("4 hours",-1)])]),_:1}),e.createVNode(s,{value:300},{default:e.withCtx(()=>[...t[23]||(t[23]=[e.createTextVNode("5 hours",-1)])]),_:1}),e.createVNode(s,{value:360},{default:e.withCtx(()=>[...t[24]||(t[24]=[e.createTextVNode("6 hours",-1)])]),_:1}),e.createVNode(s,{value:480},{default:e.withCtx(()=>[...t[25]||(t[25]=[e.createTextVNode("8 hours",-1)])]),_:1})]),_:1})]),_:1},8,["modelValue","onUpdate:modelValue"])]),e.createElementVNode("div",xe,[e.createVNode(g,{onClick:d=>S(n.id),variant:n.isDefault?"default":"outline",size:"sm"},{default:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(n.isDefault?"Default":"Set Default"),1)]),_:2},1032,["onClick","variant"])])])]),o.pricingOptions.length>1?(e.openBlock(),e.createBlock(g,{key:0,onClick:d=>B(n.id),variant:"ghost",size:"icon",class:"mt-6"},{default:e.withCtx(()=>[e.createVNode(e.unref(V.Trash2),{class:"w-4 h-4 text-destructive"})]),_:1},8,["onClick"])):e.createCommentVNode("",!0)]))),128))])]),e.createElementVNode("div",null,[e.createElementVNode("div",Ne,[e.createElementVNode("div",null,[e.createVNode(r,{class:"text-base font-medium"},{default:e.withCtx(()=>[...t[26]||(t[26]=[e.createTextVNode(" Conditional Pricing Rules ",-1)])]),_:1}),t[27]||(t[27]=e.createElementVNode("p",{class:"text-sm text-muted-foreground mt-1"}," Add extra fees based on time, day, or other conditions (e.g., +€10 after 5pm). ",-1))]),e.createVNode(g,{onClick:O,variant:"outline",size:"sm"},{default:e.withCtx(()=>[e.createVNode(e.unref(V.PlusCircle),{class:"w-4 h-4 mr-2"}),t[28]||(t[28]=e.createTextVNode(" Add Rule ",-1))]),_:1})]),e.createElementVNode("div",ve,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(o.pricingRules,n=>(e.openBlock(),e.createElementBlock("div",{key:n.id,class:"flex gap-3 items-start p-4 border rounded-lg"},[e.createElementVNode("div",ge,[e.createElementVNode("div",null,[e.createVNode(r,{class:"text-xs mb-1 block"},{default:e.withCtx(()=>[...t[29]||(t[29]=[e.createTextVNode("Rule Name",-1)])]),_:1}),e.createVNode(C,{modelValue:n.name,"onUpdate:modelValue":d=>n.name=d,placeholder:"e.g., After Hours Fee, Weekend Surcharge"},null,8,["modelValue","onUpdate:modelValue"])]),e.createElementVNode("div",Ce,[e.createElementVNode("div",null,[e.createVNode(r,{class:"text-xs mb-1 block"},{default:e.withCtx(()=>[...t[30]||(t[30]=[e.createTextVNode("Condition",-1)])]),_:1}),e.createVNode(h,{modelValue:n.condition,"onUpdate:modelValue":d=>n.condition=d},{default:e.withCtx(()=>[e.createVNode(E,null,{default:e.withCtx(()=>[e.createVNode(w,{placeholder:"Select condition"})]),_:1}),e.createVNode(b,null,{default:e.withCtx(()=>[e.createVNode(s,{value:"time_after"},{default:e.withCtx(()=>[...t[31]||(t[31]=[e.createTextVNode("Time After",-1)])]),_:1}),e.createVNode(s,{value:"time_before"},{default:e.withCtx(()=>[...t[32]||(t[32]=[e.createTextVNode("Time Before",-1)])]),_:1}),e.createVNode(s,{value:"time_between"},{default:e.withCtx(()=>[...t[33]||(t[33]=[e.createTextVNode("Time Between",-1)])]),_:1}),e.createVNode(s,{value:"day_of_week"},{default:e.withCtx(()=>[...t[34]||(t[34]=[e.createTextVNode("Day of Week",-1)])]),_:1}),e.createVNode(s,{value:"date_range"},{default:e.withCtx(()=>[...t[35]||(t[35]=[e.createTextVNode("Date Range",-1)])]),_:1})]),_:1})]),_:1},8,["modelValue","onUpdate:modelValue"])]),e.createElementVNode("div",null,[e.createVNode(r,{class:"text-xs mb-1 block"},{default:e.withCtx(()=>[...t[36]||(t[36]=[e.createTextVNode("Value",-1)])]),_:1}),e.createVNode(C,{modelValue:n.conditionValue,"onUpdate:modelValue":d=>n.conditionValue=d,type:n.condition.includes("time")?"time":"text",placeholder:"e.g., 17:00"},null,8,["modelValue","onUpdate:modelValue","type"])])]),e.createElementVNode("div",ye,[e.createElementVNode("div",null,[e.createVNode(r,{class:"text-xs mb-1 block"},{default:e.withCtx(()=>[...t[37]||(t[37]=[e.createTextVNode("Fee Type",-1)])]),_:1}),e.createVNode(h,{modelValue:n.modifier,"onUpdate:modelValue":d=>n.modifier=d},{default:e.withCtx(()=>[e.createVNode(E,null,{default:e.withCtx(()=>[e.createVNode(w,{placeholder:"Select type"})]),_:1}),e.createVNode(b,null,{default:e.withCtx(()=>[e.createVNode(s,{value:"fixed"},{default:e.withCtx(()=>[...t[38]||(t[38]=[e.createTextVNode("Fixed Amount",-1)])]),_:1}),e.createVNode(s,{value:"percentage"},{default:e.withCtx(()=>[...t[39]||(t[39]=[e.createTextVNode("Percentage",-1)])]),_:1})]),_:1})]),_:1},8,["modelValue","onUpdate:modelValue"])]),e.createElementVNode("div",null,[e.createVNode(r,{class:"text-xs mb-1 block"},{default:e.withCtx(()=>[...t[40]||(t[40]=[e.createTextVNode("Amount",-1)])]),_:1}),e.createVNode(C,{modelValue:n.amount,"onUpdate:modelValue":d=>n.amount=d,modelModifiers:{number:!0},type:"number",min:"0",step:"0.01",class:"no-spinner",placeholder:n.modifier==="percentage"?"10 (%)":"10.00"},null,8,["modelValue","onUpdate:modelValue","placeholder"])])]),N.value.length>0?(e.openBlock(),e.createElementBlock("div",ke,[e.createVNode(r,{class:"text-xs mb-1 block"},{default:e.withCtx(()=>[...t[41]||(t[41]=[e.createTextVNode("Apply To Resources",-1)])]),_:1}),e.createVNode(A,null,{default:e.withCtx(()=>[e.createVNode(I,{"as-child":""},{default:e.withCtx(()=>[e.createVNode(g,{variant:"outline",class:"w-full justify-between font-normal"},{default:e.withCtx(()=>[e.createElementVNode("div",we,[e.createVNode(e.unref(V.Users),{class:"w-4 h-4 text-muted-foreground"}),!n.resourceIds||n.resourceIds.length===0?(e.openBlock(),e.createElementBlock("span",Ee,"All Resources")):n.resourceIds.length===1?(e.openBlock(),e.createElementBlock("span",be,e.toDisplayString(N.value.find(d=>d.id===n.resourceIds[0])?.name||"1 resource"),1)):(e.openBlock(),e.createElementBlock("span",he,e.toDisplayString(n.resourceIds.length)+" resources",1))]),e.createVNode(e.unref(V.ChevronDown),{class:"w-4 h-4 opacity-50"})]),_:2},1024)]),_:2},1024),e.createVNode(U,{class:"w-64 p-2",align:"start"},{default:e.withCtx(()=>[e.createElementVNode("div",_e,[e.createElementVNode("div",{class:e.normalizeClass(["flex items-center gap-2 p-2 rounded-md hover:bg-muted cursor-pointer transition-colors",{"bg-muted":!n.resourceIds||n.resourceIds.length===0}]),onClick:d=>c(n,!0)},[e.createElementVNode("div",Be,[e.createVNode(e.unref(V.Users),{class:"w-3 h-3 text-muted-foreground"})]),t[42]||(t[42]=e.createElementVNode("span",{class:"text-sm flex-1"},"All Resources",-1)),e.createElementVNode("div",{class:e.normalizeClass(["size-4 rounded-full border-2",!n.resourceIds||n.resourceIds.length===0?"border-primary bg-primary":"border-muted-foreground"])},[!n.resourceIds||n.resourceIds.length===0?(e.openBlock(),e.createElementBlock("div",Se)):e.createCommentVNode("",!0)],2)],10,Te),t[44]||(t[44]=e.createElementVNode("div",{class:"border-t my-2"},null,-1)),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(N.value,d=>(e.openBlock(),e.createElementBlock("div",{key:d.id,class:"flex items-center gap-2 p-2 rounded-md hover:bg-muted cursor-pointer transition-colors",onClick:Fe=>{c(n,!1),v(n,d.id)}},[e.createElementVNode("div",{class:"size-5 rounded-full flex items-center justify-center text-white text-[10px] font-medium",style:e.normalizeStyle({backgroundColor:d.color||"#6b7280"})},e.toDisplayString(d.avatarLabel||d.name.charAt(0).toUpperCase()),5),e.createElementVNode("span",Pe,e.toDisplayString(d.name),1),e.createElementVNode("div",{class:e.normalizeClass(["size-4 rounded border-2 flex items-center justify-center",n.resourceIds?.includes(d.id)?"border-primary bg-primary":"border-muted-foreground"])},[n.resourceIds?.includes(d.id)?(e.openBlock(),e.createElementBlock("svg",Ie,[...t[43]||(t[43]=[e.createElementVNode("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"3",d:"M5 13l4 4L19 7"},null,-1)])])):e.createCommentVNode("",!0)],2)],8,Oe))),128))])]),_:2},1024)]),_:2},1024)])):e.createCommentVNode("",!0)]),e.createVNode(g,{onClick:d=>u(n.id),variant:"ghost",size:"icon",class:"mt-6"},{default:e.withCtx(()=>[e.createVNode(e.unref(V.Trash2),{class:"w-4 h-4 text-destructive"})]),_:1},8,["onClick"])]))),128)),o.pricingRules.length===0?(e.openBlock(),e.createElementBlock("div",Ue,' No pricing rules configured. Click "Add Rule" to create conditional fees. ')):e.createCommentVNode("",!0)])]),e.createVNode(ae),e.createElementVNode("div",null,[e.createVNode(r,{class:"text-base font-medium"},{default:e.withCtx(()=>[...t[45]||(t[45]=[e.createTextVNode(" Payment Preferences ",-1)])]),_:1}),t[52]||(t[52]=e.createElementVNode("p",{class:"text-sm text-muted-foreground mb-6"}," Let customers pay full or in part when booking a slot, or pay later. ",-1)),e.createVNode(P,{modelValue:o.paymentType,"onUpdate:modelValue":t[1]||(t[1]=n=>o.paymentType=n),class:"flex flex-col gap-4"},{default:e.withCtx(()=>[e.createVNode(r,{for:"r1",class:"flex items-start space-x-2 cursor-pointer"},{default:e.withCtx(()=>[e.createVNode(k,{id:"r1",value:"full"}),t[46]||(t[46]=e.createElementVNode("div",null,[e.createElementVNode("p",null,"Pay Full Amount when Booking"),e.createElementVNode("p",{class:"text-sm text-muted-foreground mt-1"}," Your customers are required to complete the payment to confirm their booking. ")],-1))]),_:1}),e.createVNode(r,{for:"r2",class:"flex items-start space-x-2 cursor-pointer"},{default:e.withCtx(()=>[e.createVNode(k,{id:"r2",value:"partial"}),t[47]||(t[47]=e.createElementVNode("div",null,[e.createElementVNode("p",null,"Pay Part Amount when Booking"),e.createElementVNode("p",{class:"text-sm text-muted-foreground mt-1"}," Your customers are required to pay a deposit to confirm their booking. ")],-1))]),_:1}),e.createVNode(r,{for:"r3",class:"flex items-start space-x-2 cursor-pointer"},{default:e.withCtx(()=>[e.createVNode(k,{id:"r3",value:"later"}),t[48]||(t[48]=e.createElementVNode("div",null,[e.createElementVNode("p",null,"Pay Later at Appointment"),e.createElementVNode("p",{class:"text-sm text-muted-foreground mt-1"}," Your customers can book now and pay in person at the time of their appointment. ")],-1))]),_:1})]),_:1},8,["modelValue"]),o.paymentType==="partial"?(e.openBlock(),e.createElementBlock("div",Ae,[e.createVNode(r,{class:"text-sm font-medium mb-4 block"},{default:e.withCtx(()=>[...t[49]||(t[49]=[e.createTextVNode(" Deposit Amount Configuration ",-1)])]),_:1}),e.createElementVNode("div",De,[e.createVNode(P,{modelValue:o.partialPayment.type,"onUpdate:modelValue":t[2]||(t[2]=n=>o.partialPayment.type=n),class:"flex gap-4"},{default:e.withCtx(()=>[e.createVNode(r,{class:"flex items-center space-x-2 cursor-pointer"},{default:e.withCtx(()=>[e.createVNode(k,{value:"percentage"}),t[50]||(t[50]=e.createElementVNode("span",null,"Percentage",-1))]),_:1}),e.createVNode(r,{class:"flex items-center space-x-2 cursor-pointer"},{default:e.withCtx(()=>[e.createVNode(k,{value:"fixed"}),t[51]||(t[51]=e.createElementVNode("span",null,"Fixed Amount",-1))]),_:1})]),_:1},8,["modelValue"]),e.createElementVNode("div",Re,[e.createElementVNode("div",$e,[e.createVNode(C,{modelValue:o.partialPayment.amount,"onUpdate:modelValue":t[3]||(t[3]=n=>o.partialPayment.amount=n),modelModifiers:{number:!0},type:"number",min:"0",max:o.partialPayment.type==="percentage"?100:void 0,step:"0.01",placeholder:o.partialPayment.type==="percentage"?"50":"10.00",class:"no-spinner"},null,8,["modelValue","max","placeholder"])]),e.createElementVNode("span",Me,e.toDisplayString(o.partialPayment.type==="percentage"?"%":o.currency),1)]),e.createElementVNode("p",Le,[o.partialPayment.type==="percentage"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[e.createTextVNode(" Customers will pay "+e.toDisplayString(o.partialPayment.amount)+"% of the total price upfront. ",1)],64)):(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[e.createTextVNode(" Customers will pay "+e.toDisplayString(o.currency)+" "+e.toDisplayString(o.partialPayment.amount)+" upfront. ",1)],64))])])])):e.createCommentVNode("",!0)]),e.createElementVNode("div",ze,[e.createVNode(g,{onClick:y,disabled:i.value},{default:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(i.value?"Saving...":"Save Changes"),1)]),_:1},8,["disabled"])])]))]),_:1})}}});exports.default=je;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),Z=require("./EditLayout.vue_vue_type_script_setup_true_lang-ozYrxb2g.js"),u=require("lucide-vue-next"),M=require("@oneclick.dev/cms-kit"),ee=require("./index-CxETuRsG.js"),te={class:"space-y-5 py-4"},oe={class:"flex flex-wrap gap-2 mt-2"},ne=["onClick"],le={class:"space-y-2"},ae={class:"flex items-center justify-between mb-2"},se={class:"text-sm font-medium"},re={class:"flex items-center gap-1"},de={class:"space-y-2"},ie={key:0,class:"text-sm text-muted-foreground italic py-1"},ce={class:"flex items-center justify-between rounded-lg border p-4"},ue={class:"space-y-0.5"},me={class:"text-xs text-muted-foreground"},pe={class:"w-full flex justify-between items-center gap-4 flex-col @sm/dialog-footer:flex-row"},ve={class:"flex items-center gap-2 ml-auto w-full @sm/dialog-footer:w-auto flex-col-reverse @sm/dialog-footer:flex-row"},fe=e.defineComponent({__name:"ResourceEditorDialog",emits:["add-resource","update-resource","remove-resource"],setup(Q,{expose:R,emit:y}){const C=y,i=e.ref(!1),p=e.ref("add"),d=["#ef4444","#f97316","#f59e0b","#eab308","#84cc16","#22c55e","#10b981","#14b8a6","#06b6d4","#0ea5e9","#3b82f6","#6366f1","#8b5cf6","#a855f7","#d946ef","#ec4899","#f43f5e"],g=[{value:1,label:"Monday"},{value:2,label:"Tuesday"},{value:3,label:"Wednesday"},{value:4,label:"Thursday"},{value:5,label:"Friday"},{value:6,label:"Saturday"},{value:0,label:"Sunday"}],n=e.reactive({id:"",name:"",publicLabel:"",avatarLabel:"",description:"",capacity:1,interval:30,openingHours:{0:[],1:[{start:"09:00",end:"17:00"}],2:[{start:"09:00",end:"17:00"}],3:[{start:"09:00",end:"17:00"}],4:[{start:"09:00",end:"17:00"}],5:[{start:"09:00",end:"17:00"}],6:[]},color:"blue",isActive:!0}),w=r=>{p.value=r?"edit":"add",n.id=r?.id||"",n.name=r?.name||"",n.publicLabel=r?.publicLabel||"",n.avatarLabel=r?.avatarLabel||"",n.description=r?.description||"",n.capacity=r?.capacity||1,n.interval=r?.interval||30,n.openingHours=r?.openingHours||{0:[],1:[{start:"09:00",end:"17:00"}],2:[{start:"09:00",end:"17:00"}],3:[{start:"09:00",end:"17:00"}],4:[{start:"09:00",end:"17:00"}],5:[{start:"09:00",end:"17:00"}],6:[]},n.color=r?.color||"blue",n.isActive=r?.isActive!==void 0?r.isActive:!0,i.value=!0},N=()=>{i.value=!1},k=()=>{C("add-resource",{...n}),i.value=!1},A=()=>{C("update-resource",{...n}),i.value=!1},f=()=>{C("remove-resource",n.id),i.value=!1},E=e.computed(()=>n.name.trim().length>0),z=r=>{n.openingHours[r]||(n.openingHours[r]=[]),n.openingHours[r].push({start:"09:00",end:"17:00"})},h=(r,t)=>{n.openingHours[r].splice(t,1)},L=r=>{const t=n.openingHours[r];g.forEach(x=>{n.openingHours[x.value]=JSON.parse(JSON.stringify(t))})},$=r=>{n.openingHours[r]=[]};return R({openDialog:w}),(r,t)=>{const x=e.resolveComponent("DialogTitle"),I=e.resolveComponent("DialogDescription"),D=e.resolveComponent("DialogHeader"),l=e.resolveComponent("Label"),o=e.resolveComponent("Input"),c=e.resolveComponent("NumberFieldDecrement"),U=e.resolveComponent("NumberFieldInput"),F=e.resolveComponent("NumberFieldIncrement"),b=e.resolveComponent("NumberFieldContent"),H=e.resolveComponent("NumberField"),j=e.resolveComponent("SelectValue"),q=e.resolveComponent("SelectTrigger"),V=e.resolveComponent("SelectItem"),O=e.resolveComponent("SelectContent"),B=e.resolveComponent("Select"),m=e.resolveComponent("Button"),P=e.resolveComponent("DropdownMenuTrigger"),S=e.resolveComponent("DropdownMenuItem"),Y=e.resolveComponent("DropdownMenuContent"),J=e.resolveComponent("DropdownMenu"),W=e.resolveComponent("Textarea"),s=e.resolveComponent("Switch"),_=e.resolveComponent("DialogFooter"),G=e.resolveComponent("DialogScrollContent"),X=e.resolveComponent("Dialog");return e.openBlock(),e.createBlock(X,{open:i.value,"onUpdate:open":t[7]||(t[7]=a=>i.value=a)},{default:e.withCtx(()=>[e.createVNode(G,{class:"sm:max-w-xl lg:max-w-2xl"},{default:e.withCtx(()=>[e.createVNode(D,null,{default:e.withCtx(()=>[e.createVNode(x,null,{default:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(p.value==="add"?"Add New Resource":"Edit Resource"),1)]),_:1}),e.createVNode(I,null,{default:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(p.value==="add"?"Define a new bookable resource such as staff member, room, or equipment.":"Update the details of this resource."),1)]),_:1})]),_:1}),e.createElementVNode("div",te,[e.createElementVNode("div",null,[e.createVNode(l,{class:"text-sm font-normal mb-1.5",for:"resource-name"},{default:e.withCtx(()=>[...t[8]||(t[8]=[e.createTextVNode(" Resource Name ",-1),e.createElementVNode("span",{class:"text-destructive"},"*",-1)])]),_:1}),e.createVNode(o,{modelValue:n.name,"onUpdate:modelValue":t[0]||(t[0]=a=>n.name=a),id:"resource-name",placeholder:"e.g., James, Box 1, Meeting Room A"},null,8,["modelValue"]),t[9]||(t[9]=e.createElementVNode("p",{class:"text-xs text-muted-foreground mt-1"}," Internal name visible to your team. ",-1))]),e.createElementVNode("div",null,[e.createVNode(l,{class:"text-sm font-normal mb-1.5",for:"resource-public-label"},{default:e.withCtx(()=>[...t[10]||(t[10]=[e.createTextVNode(" Public Label ",-1)])]),_:1}),e.createVNode(o,{modelValue:n.publicLabel,"onUpdate:modelValue":t[1]||(t[1]=a=>n.publicLabel=a),id:"resource-public-label",placeholder:"Name shown to customers"},null,8,["modelValue"]),t[11]||(t[11]=e.createElementVNode("p",{class:"text-xs text-muted-foreground mt-1"}," If empty, the internal name will be displayed to customers. ",-1))]),e.createElementVNode("div",null,[e.createVNode(l,{class:"text-sm font-normal mb-1.5",for:"resource-avatar-label"},{default:e.withCtx(()=>[...t[12]||(t[12]=[e.createTextVNode(" Avatar Label ",-1)])]),_:1}),e.createVNode(o,{modelValue:n.avatarLabel,"onUpdate:modelValue":t[2]||(t[2]=a=>n.avatarLabel=a),id:"resource-avatar-label",placeholder:"e.g., B1, 1, JD",maxlength:"3"},null,8,["modelValue"]),t[13]||(t[13]=e.createElementVNode("p",{class:"text-xs text-muted-foreground mt-1"}," Short text shown in the colored circle (max 3 characters). If empty, first letter of name is used. ",-1))]),e.createElementVNode("div",null,[e.createVNode(l,{class:"text-sm font-normal mb-1.5"},{default:e.withCtx(()=>[...t[14]||(t[14]=[e.createTextVNode("Color",-1)])]),_:1}),e.createElementVNode("div",oe,[(e.openBlock(),e.createElementBlock(e.Fragment,null,e.renderList(d,a=>e.createElementVNode("button",{key:a,type:"button",class:e.normalizeClass(["size-7 rounded-full transition-all ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",[n.color===a?"ring-2 ring-ring ring-offset-2":"hover:scale-110"]]),style:e.normalizeStyle({background:a}),onClick:v=>n.color=a},null,14,ne)),64))]),t[15]||(t[15]=e.createElementVNode("p",{class:"text-xs text-muted-foreground mt-2"}," Used for visual identification in the calendar. ",-1))]),e.createElementVNode("div",null,[e.createVNode(l,{class:"text-sm font-normal mb-1.5",for:"resource-capacity"},{default:e.withCtx(()=>[...t[16]||(t[16]=[e.createTextVNode(" Capacity ",-1)])]),_:1}),e.createVNode(H,{id:"resource-capacity",modelValue:n.capacity,"onUpdate:modelValue":t[3]||(t[3]=a=>n.capacity=a),min:1,max:999},{default:e.withCtx(()=>[e.createVNode(b,null,{default:e.withCtx(()=>[e.createVNode(c),e.createVNode(U),e.createVNode(F)]),_:1})]),_:1},8,["modelValue"]),t[17]||(t[17]=e.createElementVNode("p",{class:"text-xs text-muted-foreground mt-1"}," Maximum simultaneous bookings allowed for this resource. ",-1))]),e.createElementVNode("div",null,[e.createVNode(l,{class:"text-sm font-normal mb-1.5",for:"resource-interval"},{default:e.withCtx(()=>[...t[18]||(t[18]=[e.createTextVNode(" Booking Interval ",-1)])]),_:1}),e.createVNode(B,{modelValue:n.interval,"onUpdate:modelValue":t[4]||(t[4]=a=>n.interval=a),modelModifiers:{number:!0}},{default:e.withCtx(()=>[e.createVNode(q,{id:"resource-interval"},{default:e.withCtx(()=>[e.createVNode(j,{placeholder:"Select interval"})]),_:1}),e.createVNode(O,null,{default:e.withCtx(()=>[e.createVNode(V,{value:5},{default:e.withCtx(()=>[...t[19]||(t[19]=[e.createTextVNode("5 minutes",-1)])]),_:1}),e.createVNode(V,{value:10},{default:e.withCtx(()=>[...t[20]||(t[20]=[e.createTextVNode("10 minutes",-1)])]),_:1}),e.createVNode(V,{value:15},{default:e.withCtx(()=>[...t[21]||(t[21]=[e.createTextVNode("15 minutes",-1)])]),_:1}),e.createVNode(V,{value:30},{default:e.withCtx(()=>[...t[22]||(t[22]=[e.createTextVNode("30 minutes",-1)])]),_:1}),e.createVNode(V,{value:60},{default:e.withCtx(()=>[...t[23]||(t[23]=[e.createTextVNode("1 hour",-1)])]),_:1})]),_:1})]),_:1},8,["modelValue"]),t[24]||(t[24]=e.createElementVNode("p",{class:"text-xs text-muted-foreground mt-1"}," Time slots will be generated at this interval within operating hours. ",-1))]),e.createElementVNode("div",null,[e.createVNode(l,{class:"text-sm font-normal mb-2 flex items-center gap-2"},{default:e.withCtx(()=>[e.createVNode(e.unref(u.Clock),{class:"w-4 h-4"}),t[25]||(t[25]=e.createTextVNode(" Operating Hours ",-1))]),_:1}),e.createElementVNode("div",le,[(e.openBlock(),e.createElementBlock(e.Fragment,null,e.renderList(g,a=>e.createElementVNode("div",{key:a.value,class:"rounded-md bg-muted/30 p-2 sm:p-3"},[e.createElementVNode("div",ae,[e.createElementVNode("span",se,e.toDisplayString(a.label),1),e.createElementVNode("div",re,[e.createVNode(m,{variant:"outline",size:"sm",class:"h-7 px-2 text-xs",onClick:v=>z(a.value)},{default:e.withCtx(()=>[...t[26]||(t[26]=[e.createTextVNode(" Add ",-1)])]),_:1},8,["onClick"]),e.createVNode(J,null,{default:e.withCtx(()=>[e.createVNode(P,{"as-child":""},{default:e.withCtx(()=>[e.createVNode(m,{variant:"ghost",size:"icon",class:"size-7"},{default:e.withCtx(()=>[e.createVNode(e.unref(u.MoreHorizontal),{class:"w-4 h-4"})]),_:1})]),_:1}),e.createVNode(Y,{align:"end"},{default:e.withCtx(()=>[e.createVNode(S,{onClick:v=>L(a.value)},{default:e.withCtx(()=>[...t[27]||(t[27]=[e.createTextVNode(" Copy to all days ",-1)])]),_:1},8,["onClick"]),e.createVNode(S,{onClick:v=>$(a.value),variant:"destructive"},{default:e.withCtx(()=>[...t[28]||(t[28]=[e.createTextVNode(" Set as closed ",-1)])]),_:1},8,["onClick"])]),_:2},1024)]),_:2},1024)])]),e.createElementVNode("div",de,[n.openingHours[a.value]?.length===0?(e.openBlock(),e.createElementBlock("div",ie," Closed ")):e.createCommentVNode("",!0),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(n.openingHours[a.value],(v,K)=>(e.openBlock(),e.createElementBlock("div",{key:K,class:"flex items-center gap-1.5 sm:gap-2"},[e.createVNode(o,{modelValue:v.start,"onUpdate:modelValue":T=>v.start=T,type:"time",class:"flex-1 min-w-0 h-8 text-sm"},null,8,["modelValue","onUpdate:modelValue"]),t[29]||(t[29]=e.createElementVNode("span",{class:"text-muted-foreground text-xs sm:text-sm shrink-0"},"to",-1)),e.createVNode(o,{modelValue:v.end,"onUpdate:modelValue":T=>v.end=T,type:"time",class:"flex-1 min-w-0 h-8 text-sm"},null,8,["modelValue","onUpdate:modelValue"]),e.createVNode(m,{variant:"ghost",size:"icon",class:"size-7 shrink-0",onClick:T=>h(a.value,K)},{default:e.withCtx(()=>[e.createVNode(e.unref(u.Trash2),{class:"w-3.5 h-3.5 text-destructive"})]),_:1},8,["onClick"])]))),128))])])),64))]),t[30]||(t[30]=e.createElementVNode("p",{class:"text-xs text-muted-foreground mt-2"}," Define when this resource is available. You can add multiple time ranges per day for split shifts. ",-1))]),e.createElementVNode("div",null,[e.createVNode(l,{class:"text-sm font-normal mb-1.5",for:"resource-description"},{default:e.withCtx(()=>[...t[31]||(t[31]=[e.createTextVNode(" Description ",-1)])]),_:1}),e.createVNode(W,{modelValue:n.description,"onUpdate:modelValue":t[5]||(t[5]=a=>n.description=a),id:"resource-description",placeholder:"Internal notes about this resource...",rows:"3"},null,8,["modelValue"]),t[32]||(t[32]=e.createElementVNode("p",{class:"text-xs text-muted-foreground mt-1"}," Admin-only notes. Not shown to customers. ",-1))]),e.createElementVNode("div",ce,[e.createElementVNode("div",ue,[e.createVNode(l,{class:"text-sm font-medium"},{default:e.withCtx(()=>[...t[33]||(t[33]=[e.createTextVNode("Active",-1)])]),_:1}),e.createElementVNode("p",me,e.toDisplayString(n.isActive?"Resource can be used for new slots and bookings.":"Existing bookings stay, but no new ones can be created."),1)]),e.createVNode(s,{modelValue:n.isActive,"onUpdate:modelValue":t[6]||(t[6]=a=>n.isActive=a)},null,8,["modelValue"])])]),e.createVNode(_,{class:"@container/dialog-footer gap-2"},{default:e.withCtx(()=>[e.createElementVNode("div",pe,[p.value==="edit"?(e.openBlock(),e.createBlock(m,{key:0,variant:"destructive",onClick:f,class:"w-full @sm/dialog-footer:w-auto"},{default:e.withCtx(()=>[...t[34]||(t[34]=[e.createTextVNode(" Delete Resource ",-1)])]),_:1})):e.createCommentVNode("",!0),e.createElementVNode("div",ve,[e.createVNode(m,{variant:"outline",onClick:N,class:"w-full @sm/dialog-footer:w-auto"},{default:e.withCtx(()=>[...t[35]||(t[35]=[e.createTextVNode(" Cancel ",-1)])]),_:1}),p.value==="add"?(e.openBlock(),e.createBlock(m,{key:0,onClick:k,disabled:!E.value,class:"w-full @sm/dialog-footer:w-auto"},{default:e.withCtx(()=>[...t[36]||(t[36]=[e.createTextVNode(" Add Resource ",-1)])]),_:1},8,["disabled"])):(e.openBlock(),e.createBlock(m,{key:1,onClick:A,disabled:!E.value,class:"w-full @sm/dialog-footer:w-auto"},{default:e.withCtx(()=>[...t[37]||(t[37]=[e.createTextVNode(" Save Changes ",-1)])]),_:1},8,["disabled"]))])])]),_:1})]),_:1})]),_:1},8,["open"])}}}),xe={class:"@container/resources"},Ve={class:"flex flex-col @lg/resources:flex-row @lg/resources:items-center @lg/resources:justify-between gap-4 mb-6"},ge={class:"space-y-6"},Ne={key:0,class:"flex flex-col @md/resources:flex-row gap-4 items-start @md/resources:items-center justify-between"},Ce={class:"relative w-full @md/resources:w-64"},we={class:"text-sm text-muted-foreground"},be={key:1,class:"grid grid-cols-1 @2xl/resources:grid-cols-2 @4xl/resources:grid-cols-3 gap-4"},_e={class:"p-4 pl-5"},ye={class:"flex items-start gap-3"},ke={class:"flex-1 min-w-0"},Ee={class:"flex items-center gap-2"},he={class:"font-semibold truncate text-base"},De={key:0},Be={key:0,class:"text-sm text-muted-foreground truncate"},Se={key:0,class:"text-sm text-muted-foreground mt-3 line-clamp-2"},Te={class:"flex items-center flex-wrap gap-3 mt-4 pt-3 border-t"},Me={class:"flex items-center gap-1.5 text-xs text-muted-foreground"},Re={class:"flex items-center gap-1.5 text-xs text-muted-foreground"},Ae={class:"flex items-center gap-2"},ze={class:"text-xs text-muted-foreground"},Le={key:1,class:"flex items-center gap-1.5 text-xs text-orange-500"},$e={key:2,class:"text-center py-8 text-muted-foreground"},Ie={key:3,class:"flex justify-center py-12"},Ue={key:5,class:"fixed bottom-4 right-4 bg-background border rounded-lg px-4 py-2 shadow-lg flex items-center gap-2"},Fe=e.defineComponent({__name:"resources",setup(Q){const{width:R}=ee.useWindowSize(),{params:y}=M.useModuleRoute(),{confirm:C}=M.useConfirmation(),{config:i}=M.useModule(),p=M.useFirebaseIntegration(i.project),d=e.ref([]),g=e.ref(!1),n=e.ref(!0),w=e.ref(),N=e.ref(""),k=()=>Date.now().toString(36)+Math.random().toString(36).substr(2),A=async()=>{try{n.value=!0;const l=await p.get(i.agendaCollection,y.value.id);d.value=l.resources||[]}catch(l){console.error("Error loading resources:",l)}finally{n.value=!1}},f=async()=>{g.value=!0;try{await p.update(i.agendaCollection,y.value.id,{resources:d.value})}catch(l){console.error("Error saving resources:",l)}finally{g.value=!1}},E=l=>{const o={...l,id:k()};d.value.push(o),f()},z=l=>{const o=d.value.findIndex(c=>c.id===l.id);o!==-1&&(d.value[o]=l),f()},h=async l=>{await C("Are you sure you want to delete this resource? This action cannot be undone.","Delete Resource","Delete")&&(d.value=d.value.filter(c=>c.id!==l),f())},L=async l=>{const o=d.value.findIndex(c=>c.id===l.id);o!==-1&&(d.value[o].isActive=!d.value[o].isActive,await f())},$=l=>{const o={...l,id:k(),name:`${l.name} (Copy)`,publicLabel:l.publicLabel?`${l.publicLabel} (Copy)`:""};d.value.push(o),f()},r=()=>{w.value?.openDialog()},t=l=>{w.value?.openDialog(l)},x=e.computed(()=>{if(!N.value.trim())return d.value;const l=N.value.toLowerCase();return d.value.filter(o=>o.name.toLowerCase().includes(l)||o.publicLabel?.toLowerCase().includes(l))}),I=e.computed(()=>d.value.filter(l=>l.isActive).length),D=e.computed(()=>d.value.length);return A(),(l,o)=>{const c=e.resolveComponent("Button"),U=e.resolveComponent("Input"),F=e.resolveComponent("DropdownMenuTrigger"),b=e.resolveComponent("DropdownMenuItem"),H=e.resolveComponent("DropdownMenuSeparator"),j=e.resolveComponent("DropdownMenuContent"),q=e.resolveComponent("DropdownMenu"),V=e.resolveComponent("Switch"),O=e.resolveComponent("Card"),B=e.resolveComponent("Spinner"),m=e.resolveComponent("EmptyMedia"),P=e.resolveComponent("EmptyTitle"),S=e.resolveComponent("EmptyDescription"),Y=e.resolveComponent("EmptyHeader"),J=e.resolveComponent("EmptyContent"),W=e.resolveComponent("Empty");return e.openBlock(),e.createBlock(Z._sfc_main,null,{default:e.withCtx(()=>[e.createElementVNode("div",xe,[e.createElementVNode("div",Ve,[o[2]||(o[2]=e.createElementVNode("div",null,[e.createElementVNode("h1",{class:"text-lg font-medium"},"Resource Management"),e.createElementVNode("p",{class:"text-muted-foreground text-sm mt-1"}," Define the rooms, boxes, or staff that can be booked in this agenda. ")],-1)),d.value.length>0?(e.openBlock(),e.createBlock(c,{key:0,onClick:r},{default:e.withCtx(()=>[e.createVNode(e.unref(u.Plus),{class:"size-4 mr-1.5"}),o[1]||(o[1]=e.createTextVNode(" Add Resource ",-1))]),_:1})):e.createCommentVNode("",!0)]),e.createElementVNode("div",ge,[d.value.length>0?(e.openBlock(),e.createElementBlock("div",Ne,[e.createElementVNode("div",Ce,[e.createVNode(U,{modelValue:N.value,"onUpdate:modelValue":o[0]||(o[0]=s=>N.value=s),placeholder:"Search resources...",class:"pl-9"},null,8,["modelValue"]),o[3]||(o[3]=e.createElementVNode("svg",{class:"absolute left-3 top-1/2 -translate-y-1/2 size-4 text-muted-foreground",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[e.createElementVNode("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})],-1))]),e.createElementVNode("div",we,e.toDisplayString(I.value)+" active of "+e.toDisplayString(D.value)+" resource"+e.toDisplayString(D.value!==1?"s":""),1)])):e.createCommentVNode("",!0),x.value.length>0?(e.openBlock(),e.createElementBlock("div",be,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(x.value,s=>(e.openBlock(),e.createBlock(O,{key:s.id,class:e.normalizeClass(["group relative overflow-hidden transition-all duration-200 hover:shadow-md",s.isActive?"":"opacity-60 grayscale-[30%]"])},{default:e.withCtx(()=>[e.createElementVNode("div",{class:"absolute inset-y-0 left-0 w-1 transition-all duration-200 group-hover:w-1.5",style:e.normalizeStyle({background:s.color})},null,4),e.createElementVNode("div",_e,[e.createElementVNode("div",ye,[e.createElementVNode("div",{class:"size-11 rounded-xl flex-shrink-0 flex items-center justify-center text-white font-semibold text-sm shadow-sm",style:e.normalizeStyle({background:s.color})},e.toDisplayString(s.avatarLabel||s.name.charAt(0).toUpperCase()),5),e.createElementVNode("div",ke,[e.createElementVNode("div",Ee,[e.createElementVNode("h3",he,[e.createTextVNode(e.toDisplayString(s.name)+" ",1),s.isActive?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("span",De,"(Inactive)"))])]),s.publicLabel&&s.publicLabel!==s.name?(e.openBlock(),e.createElementBlock("p",Be,e.toDisplayString(s.publicLabel),1)):e.createCommentVNode("",!0)]),e.createVNode(q,null,{default:e.withCtx(()=>[e.createVNode(F,{"as-child":""},{default:e.withCtx(()=>[e.createVNode(c,{variant:"ghost",size:"icon",class:"size-8"},{default:e.withCtx(()=>[...o[4]||(o[4]=[e.createElementVNode("svg",{class:"size-4",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[e.createElementVNode("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M12 5v.01M12 12v.01M12 19v.01M12 6a1 1 0 110-2 1 1 0 010 2zm0 7a1 1 0 110-2 1 1 0 010 2zm0 7a1 1 0 110-2 1 1 0 010 2z"})],-1)])]),_:1})]),_:1}),e.createVNode(j,{align:"end"},{default:e.withCtx(()=>[e.createVNode(b,{onClick:_=>t(s)},{default:e.withCtx(()=>[e.createVNode(e.unref(u.Pencil),{class:"size-4 mr-2"}),o[5]||(o[5]=e.createTextVNode(" Edit ",-1))]),_:1},8,["onClick"]),e.createVNode(b,{onClick:_=>$(s)},{default:e.withCtx(()=>[e.createVNode(e.unref(u.Copy),{class:"size-4 mr-2"}),o[6]||(o[6]=e.createTextVNode(" Duplicate ",-1))]),_:1},8,["onClick"]),e.createVNode(H),e.createVNode(b,{variant:"destructive",onClick:_=>h(s.id)},{default:e.withCtx(()=>[e.createVNode(e.unref(u.Trash2),{class:"size-4 mr-2"}),o[7]||(o[7]=e.createTextVNode(" Delete ",-1))]),_:1},8,["onClick"])]),_:2},1024)]),_:2},1024)]),s.description?(e.openBlock(),e.createElementBlock("p",Se,e.toDisplayString(s.description),1)):e.createCommentVNode("",!0),e.createElementVNode("div",Te,[e.createElementVNode("div",Me,[e.createVNode(e.unref(u.Users),{class:"size-3.5"}),e.createElementVNode("span",null,e.toDisplayString(s.capacity)+" "+e.toDisplayString(s.capacity===1?"slot":"slots"),1)]),e.createElementVNode("div",Re,[o[8]||(o[8]=e.createElementVNode("svg",{class:"size-3.5",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[e.createElementVNode("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"})],-1)),e.createElementVNode("span",null,e.toDisplayString(s.interval)+" min",1)]),e.unref(R)>=640?(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[o[9]||(o[9]=e.createElementVNode("div",{class:"flex-1"},null,-1)),e.createElementVNode("div",Ae,[e.createElementVNode("span",ze,e.toDisplayString(s.isActive?"Active":"Inactive"),1),e.createVNode(V,{defaultValue:s.isActive,"onUpdate:modelValue":_=>L(s),class:"scale-90"},null,8,["defaultValue","onUpdate:modelValue"])])],64)):s.isActive?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("div",Le,[e.createVNode(e.unref(u.CircleAlert),{class:"size-3.5"}),o[10]||(o[10]=e.createElementVNode("span",null,"Inactive",-1))]))])])]),_:2},1032,["class"]))),128))])):d.value.length>0&&x.value.length===0?(e.openBlock(),e.createElementBlock("div",$e,[...o[11]||(o[11]=[e.createElementVNode("p",null,"No resources match your search.",-1)])])):n.value?(e.openBlock(),e.createElementBlock("div",Ie,[e.createVNode(B,{class:"size-8"})])):(e.openBlock(),e.createBlock(W,{key:4,class:"border border-dashed"},{default:e.withCtx(()=>[e.createVNode(Y,null,{default:e.withCtx(()=>[e.createVNode(m,{variant:"icon"},{default:e.withCtx(()=>[e.createVNode(e.unref(u.Users),{class:"size-6"})]),_:1}),e.createVNode(P,null,{default:e.withCtx(()=>[...o[12]||(o[12]=[e.createTextVNode("No Resources Yet",-1)])]),_:1}),e.createVNode(S,null,{default:e.withCtx(()=>[...o[13]||(o[13]=[e.createTextVNode(" You haven't added any bookable resources yet. Define your staff, rooms, or equipment to start configuring availability. ",-1)])]),_:1})]),_:1}),e.createVNode(J,null,{default:e.withCtx(()=>[e.createVNode(c,{variant:"outline",onClick:r},{default:e.withCtx(()=>[e.createVNode(e.unref(u.Plus),{class:"size-4 mr-1.5"}),o[14]||(o[14]=e.createTextVNode(" Add Your First Resource ",-1))]),_:1})]),_:1})]),_:1})),g.value?(e.openBlock(),e.createElementBlock("div",Ue,[e.createVNode(B,{class:"size-4"}),o[15]||(o[15]=e.createElementVNode("span",{class:"text-sm"},"Saving...",-1))])):e.createCommentVNode("",!0)])]),e.createVNode(fe,{ref_key:"resourceDialogRef",ref:w,onAddResource:E,onUpdateResource:z,onRemoveResource:h},null,512)]),_:1})}}});exports.default=Fe;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),Z=require("./EditLayout.vue_vue_type_script_setup_true_lang-kpjbVSXg.js"),u=require("lucide-vue-next"),M=require("@oneclick.dev/cms-kit"),ee=require("./index-CxETuRsG.js"),te={class:"space-y-5 py-4"},oe={class:"flex flex-wrap gap-2 mt-2"},ne=["onClick"],le={class:"space-y-2"},ae={class:"flex items-center justify-between mb-2"},se={class:"text-sm font-medium"},re={class:"flex items-center gap-1"},de={class:"space-y-2"},ie={key:0,class:"text-sm text-muted-foreground italic py-1"},ce={class:"flex items-center justify-between rounded-lg border p-4"},ue={class:"space-y-0.5"},me={class:"text-xs text-muted-foreground"},pe={class:"w-full flex justify-between items-center gap-4 flex-col @sm/dialog-footer:flex-row"},ve={class:"flex items-center gap-2 ml-auto w-full @sm/dialog-footer:w-auto flex-col-reverse @sm/dialog-footer:flex-row"},fe=e.defineComponent({__name:"ResourceEditorDialog",emits:["add-resource","update-resource","remove-resource"],setup(Q,{expose:R,emit:y}){const C=y,i=e.ref(!1),p=e.ref("add"),d=["#ef4444","#f97316","#f59e0b","#eab308","#84cc16","#22c55e","#10b981","#14b8a6","#06b6d4","#0ea5e9","#3b82f6","#6366f1","#8b5cf6","#a855f7","#d946ef","#ec4899","#f43f5e"],g=[{value:1,label:"Monday"},{value:2,label:"Tuesday"},{value:3,label:"Wednesday"},{value:4,label:"Thursday"},{value:5,label:"Friday"},{value:6,label:"Saturday"},{value:0,label:"Sunday"}],n=e.reactive({id:"",name:"",publicLabel:"",avatarLabel:"",description:"",capacity:1,interval:30,openingHours:{0:[],1:[{start:"09:00",end:"17:00"}],2:[{start:"09:00",end:"17:00"}],3:[{start:"09:00",end:"17:00"}],4:[{start:"09:00",end:"17:00"}],5:[{start:"09:00",end:"17:00"}],6:[]},color:"blue",isActive:!0}),w=r=>{p.value=r?"edit":"add",n.id=r?.id||"",n.name=r?.name||"",n.publicLabel=r?.publicLabel||"",n.avatarLabel=r?.avatarLabel||"",n.description=r?.description||"",n.capacity=r?.capacity||1,n.interval=r?.interval||30,n.openingHours=r?.openingHours||{0:[],1:[{start:"09:00",end:"17:00"}],2:[{start:"09:00",end:"17:00"}],3:[{start:"09:00",end:"17:00"}],4:[{start:"09:00",end:"17:00"}],5:[{start:"09:00",end:"17:00"}],6:[]},n.color=r?.color||"blue",n.isActive=r?.isActive!==void 0?r.isActive:!0,i.value=!0},N=()=>{i.value=!1},k=()=>{C("add-resource",{...n}),i.value=!1},A=()=>{C("update-resource",{...n}),i.value=!1},f=()=>{C("remove-resource",n.id),i.value=!1},E=e.computed(()=>n.name.trim().length>0),z=r=>{n.openingHours[r]||(n.openingHours[r]=[]),n.openingHours[r].push({start:"09:00",end:"17:00"})},h=(r,t)=>{n.openingHours[r].splice(t,1)},L=r=>{const t=n.openingHours[r];g.forEach(x=>{n.openingHours[x.value]=JSON.parse(JSON.stringify(t))})},$=r=>{n.openingHours[r]=[]};return R({openDialog:w}),(r,t)=>{const x=e.resolveComponent("DialogTitle"),I=e.resolveComponent("DialogDescription"),D=e.resolveComponent("DialogHeader"),l=e.resolveComponent("Label"),o=e.resolveComponent("Input"),c=e.resolveComponent("NumberFieldDecrement"),U=e.resolveComponent("NumberFieldInput"),F=e.resolveComponent("NumberFieldIncrement"),b=e.resolveComponent("NumberFieldContent"),H=e.resolveComponent("NumberField"),j=e.resolveComponent("SelectValue"),q=e.resolveComponent("SelectTrigger"),V=e.resolveComponent("SelectItem"),O=e.resolveComponent("SelectContent"),B=e.resolveComponent("Select"),m=e.resolveComponent("Button"),P=e.resolveComponent("DropdownMenuTrigger"),S=e.resolveComponent("DropdownMenuItem"),Y=e.resolveComponent("DropdownMenuContent"),J=e.resolveComponent("DropdownMenu"),W=e.resolveComponent("Textarea"),s=e.resolveComponent("Switch"),_=e.resolveComponent("DialogFooter"),G=e.resolveComponent("DialogScrollContent"),X=e.resolveComponent("Dialog");return e.openBlock(),e.createBlock(X,{open:i.value,"onUpdate:open":t[7]||(t[7]=a=>i.value=a)},{default:e.withCtx(()=>[e.createVNode(G,{class:"sm:max-w-xl lg:max-w-2xl"},{default:e.withCtx(()=>[e.createVNode(D,null,{default:e.withCtx(()=>[e.createVNode(x,null,{default:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(p.value==="add"?"Add New Resource":"Edit Resource"),1)]),_:1}),e.createVNode(I,null,{default:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(p.value==="add"?"Define a new bookable resource such as staff member, room, or equipment.":"Update the details of this resource."),1)]),_:1})]),_:1}),e.createElementVNode("div",te,[e.createElementVNode("div",null,[e.createVNode(l,{class:"text-sm font-normal mb-1.5",for:"resource-name"},{default:e.withCtx(()=>[...t[8]||(t[8]=[e.createTextVNode(" Resource Name ",-1),e.createElementVNode("span",{class:"text-destructive"},"*",-1)])]),_:1}),e.createVNode(o,{modelValue:n.name,"onUpdate:modelValue":t[0]||(t[0]=a=>n.name=a),id:"resource-name",placeholder:"e.g., James, Box 1, Meeting Room A"},null,8,["modelValue"]),t[9]||(t[9]=e.createElementVNode("p",{class:"text-xs text-muted-foreground mt-1"}," Internal name visible to your team. ",-1))]),e.createElementVNode("div",null,[e.createVNode(l,{class:"text-sm font-normal mb-1.5",for:"resource-public-label"},{default:e.withCtx(()=>[...t[10]||(t[10]=[e.createTextVNode(" Public Label ",-1)])]),_:1}),e.createVNode(o,{modelValue:n.publicLabel,"onUpdate:modelValue":t[1]||(t[1]=a=>n.publicLabel=a),id:"resource-public-label",placeholder:"Name shown to customers"},null,8,["modelValue"]),t[11]||(t[11]=e.createElementVNode("p",{class:"text-xs text-muted-foreground mt-1"}," If empty, the internal name will be displayed to customers. ",-1))]),e.createElementVNode("div",null,[e.createVNode(l,{class:"text-sm font-normal mb-1.5",for:"resource-avatar-label"},{default:e.withCtx(()=>[...t[12]||(t[12]=[e.createTextVNode(" Avatar Label ",-1)])]),_:1}),e.createVNode(o,{modelValue:n.avatarLabel,"onUpdate:modelValue":t[2]||(t[2]=a=>n.avatarLabel=a),id:"resource-avatar-label",placeholder:"e.g., B1, 1, JD",maxlength:"3"},null,8,["modelValue"]),t[13]||(t[13]=e.createElementVNode("p",{class:"text-xs text-muted-foreground mt-1"}," Short text shown in the colored circle (max 3 characters). If empty, first letter of name is used. ",-1))]),e.createElementVNode("div",null,[e.createVNode(l,{class:"text-sm font-normal mb-1.5"},{default:e.withCtx(()=>[...t[14]||(t[14]=[e.createTextVNode("Color",-1)])]),_:1}),e.createElementVNode("div",oe,[(e.openBlock(),e.createElementBlock(e.Fragment,null,e.renderList(d,a=>e.createElementVNode("button",{key:a,type:"button",class:e.normalizeClass(["size-7 rounded-full transition-all ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",[n.color===a?"ring-2 ring-ring ring-offset-2":"hover:scale-110"]]),style:e.normalizeStyle({background:a}),onClick:v=>n.color=a},null,14,ne)),64))]),t[15]||(t[15]=e.createElementVNode("p",{class:"text-xs text-muted-foreground mt-2"}," Used for visual identification in the calendar. ",-1))]),e.createElementVNode("div",null,[e.createVNode(l,{class:"text-sm font-normal mb-1.5",for:"resource-capacity"},{default:e.withCtx(()=>[...t[16]||(t[16]=[e.createTextVNode(" Capacity ",-1)])]),_:1}),e.createVNode(H,{id:"resource-capacity",modelValue:n.capacity,"onUpdate:modelValue":t[3]||(t[3]=a=>n.capacity=a),min:1,max:999},{default:e.withCtx(()=>[e.createVNode(b,null,{default:e.withCtx(()=>[e.createVNode(c),e.createVNode(U),e.createVNode(F)]),_:1})]),_:1},8,["modelValue"]),t[17]||(t[17]=e.createElementVNode("p",{class:"text-xs text-muted-foreground mt-1"}," Maximum simultaneous bookings allowed for this resource. ",-1))]),e.createElementVNode("div",null,[e.createVNode(l,{class:"text-sm font-normal mb-1.5",for:"resource-interval"},{default:e.withCtx(()=>[...t[18]||(t[18]=[e.createTextVNode(" Booking Interval ",-1)])]),_:1}),e.createVNode(B,{modelValue:n.interval,"onUpdate:modelValue":t[4]||(t[4]=a=>n.interval=a),modelModifiers:{number:!0}},{default:e.withCtx(()=>[e.createVNode(q,{id:"resource-interval"},{default:e.withCtx(()=>[e.createVNode(j,{placeholder:"Select interval"})]),_:1}),e.createVNode(O,null,{default:e.withCtx(()=>[e.createVNode(V,{value:5},{default:e.withCtx(()=>[...t[19]||(t[19]=[e.createTextVNode("5 minutes",-1)])]),_:1}),e.createVNode(V,{value:10},{default:e.withCtx(()=>[...t[20]||(t[20]=[e.createTextVNode("10 minutes",-1)])]),_:1}),e.createVNode(V,{value:15},{default:e.withCtx(()=>[...t[21]||(t[21]=[e.createTextVNode("15 minutes",-1)])]),_:1}),e.createVNode(V,{value:30},{default:e.withCtx(()=>[...t[22]||(t[22]=[e.createTextVNode("30 minutes",-1)])]),_:1}),e.createVNode(V,{value:60},{default:e.withCtx(()=>[...t[23]||(t[23]=[e.createTextVNode("1 hour",-1)])]),_:1})]),_:1})]),_:1},8,["modelValue"]),t[24]||(t[24]=e.createElementVNode("p",{class:"text-xs text-muted-foreground mt-1"}," Time slots will be generated at this interval within operating hours. ",-1))]),e.createElementVNode("div",null,[e.createVNode(l,{class:"text-sm font-normal mb-2 flex items-center gap-2"},{default:e.withCtx(()=>[e.createVNode(e.unref(u.Clock),{class:"w-4 h-4"}),t[25]||(t[25]=e.createTextVNode(" Operating Hours ",-1))]),_:1}),e.createElementVNode("div",le,[(e.openBlock(),e.createElementBlock(e.Fragment,null,e.renderList(g,a=>e.createElementVNode("div",{key:a.value,class:"rounded-md bg-muted/30 p-2 sm:p-3"},[e.createElementVNode("div",ae,[e.createElementVNode("span",se,e.toDisplayString(a.label),1),e.createElementVNode("div",re,[e.createVNode(m,{variant:"outline",size:"sm",class:"h-7 px-2 text-xs",onClick:v=>z(a.value)},{default:e.withCtx(()=>[...t[26]||(t[26]=[e.createTextVNode(" Add ",-1)])]),_:1},8,["onClick"]),e.createVNode(J,null,{default:e.withCtx(()=>[e.createVNode(P,{"as-child":""},{default:e.withCtx(()=>[e.createVNode(m,{variant:"ghost",size:"icon",class:"size-7"},{default:e.withCtx(()=>[e.createVNode(e.unref(u.MoreHorizontal),{class:"w-4 h-4"})]),_:1})]),_:1}),e.createVNode(Y,{align:"end"},{default:e.withCtx(()=>[e.createVNode(S,{onClick:v=>L(a.value)},{default:e.withCtx(()=>[...t[27]||(t[27]=[e.createTextVNode(" Copy to all days ",-1)])]),_:1},8,["onClick"]),e.createVNode(S,{onClick:v=>$(a.value),variant:"destructive"},{default:e.withCtx(()=>[...t[28]||(t[28]=[e.createTextVNode(" Set as closed ",-1)])]),_:1},8,["onClick"])]),_:2},1024)]),_:2},1024)])]),e.createElementVNode("div",de,[n.openingHours[a.value]?.length===0?(e.openBlock(),e.createElementBlock("div",ie," Closed ")):e.createCommentVNode("",!0),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(n.openingHours[a.value],(v,K)=>(e.openBlock(),e.createElementBlock("div",{key:K,class:"flex items-center gap-1.5 sm:gap-2"},[e.createVNode(o,{modelValue:v.start,"onUpdate:modelValue":T=>v.start=T,type:"time",class:"flex-1 min-w-0 h-8 text-sm"},null,8,["modelValue","onUpdate:modelValue"]),t[29]||(t[29]=e.createElementVNode("span",{class:"text-muted-foreground text-xs sm:text-sm shrink-0"},"to",-1)),e.createVNode(o,{modelValue:v.end,"onUpdate:modelValue":T=>v.end=T,type:"time",class:"flex-1 min-w-0 h-8 text-sm"},null,8,["modelValue","onUpdate:modelValue"]),e.createVNode(m,{variant:"ghost",size:"icon",class:"size-7 shrink-0",onClick:T=>h(a.value,K)},{default:e.withCtx(()=>[e.createVNode(e.unref(u.Trash2),{class:"w-3.5 h-3.5 text-destructive"})]),_:1},8,["onClick"])]))),128))])])),64))]),t[30]||(t[30]=e.createElementVNode("p",{class:"text-xs text-muted-foreground mt-2"}," Define when this resource is available. You can add multiple time ranges per day for split shifts. ",-1))]),e.createElementVNode("div",null,[e.createVNode(l,{class:"text-sm font-normal mb-1.5",for:"resource-description"},{default:e.withCtx(()=>[...t[31]||(t[31]=[e.createTextVNode(" Description ",-1)])]),_:1}),e.createVNode(W,{modelValue:n.description,"onUpdate:modelValue":t[5]||(t[5]=a=>n.description=a),id:"resource-description",placeholder:"Internal notes about this resource...",rows:"3"},null,8,["modelValue"]),t[32]||(t[32]=e.createElementVNode("p",{class:"text-xs text-muted-foreground mt-1"}," Admin-only notes. Not shown to customers. ",-1))]),e.createElementVNode("div",ce,[e.createElementVNode("div",ue,[e.createVNode(l,{class:"text-sm font-medium"},{default:e.withCtx(()=>[...t[33]||(t[33]=[e.createTextVNode("Active",-1)])]),_:1}),e.createElementVNode("p",me,e.toDisplayString(n.isActive?"Resource can be used for new slots and bookings.":"Existing bookings stay, but no new ones can be created."),1)]),e.createVNode(s,{modelValue:n.isActive,"onUpdate:modelValue":t[6]||(t[6]=a=>n.isActive=a)},null,8,["modelValue"])])]),e.createVNode(_,{class:"@container/dialog-footer gap-2"},{default:e.withCtx(()=>[e.createElementVNode("div",pe,[p.value==="edit"?(e.openBlock(),e.createBlock(m,{key:0,variant:"destructive",onClick:f,class:"w-full @sm/dialog-footer:w-auto"},{default:e.withCtx(()=>[...t[34]||(t[34]=[e.createTextVNode(" Delete Resource ",-1)])]),_:1})):e.createCommentVNode("",!0),e.createElementVNode("div",ve,[e.createVNode(m,{variant:"outline",onClick:N,class:"w-full @sm/dialog-footer:w-auto"},{default:e.withCtx(()=>[...t[35]||(t[35]=[e.createTextVNode(" Cancel ",-1)])]),_:1}),p.value==="add"?(e.openBlock(),e.createBlock(m,{key:0,onClick:k,disabled:!E.value,class:"w-full @sm/dialog-footer:w-auto"},{default:e.withCtx(()=>[...t[36]||(t[36]=[e.createTextVNode(" Add Resource ",-1)])]),_:1},8,["disabled"])):(e.openBlock(),e.createBlock(m,{key:1,onClick:A,disabled:!E.value,class:"w-full @sm/dialog-footer:w-auto"},{default:e.withCtx(()=>[...t[37]||(t[37]=[e.createTextVNode(" Save Changes ",-1)])]),_:1},8,["disabled"]))])])]),_:1})]),_:1})]),_:1},8,["open"])}}}),xe={class:"@container/resources"},Ve={class:"flex flex-col @lg/resources:flex-row @lg/resources:items-center @lg/resources:justify-between gap-4 mb-6"},ge={class:"space-y-6"},Ne={key:0,class:"flex flex-col @md/resources:flex-row gap-4 items-start @md/resources:items-center justify-between"},Ce={class:"relative w-full @md/resources:w-64"},we={class:"text-sm text-muted-foreground"},be={key:1,class:"grid grid-cols-1 @2xl/resources:grid-cols-2 @4xl/resources:grid-cols-3 gap-4"},_e={class:"p-4 pl-5"},ye={class:"flex items-start gap-3"},ke={class:"flex-1 min-w-0"},Ee={class:"flex items-center gap-2"},he={class:"font-semibold truncate text-base"},De={key:0},Be={key:0,class:"text-sm text-muted-foreground truncate"},Se={key:0,class:"text-sm text-muted-foreground mt-3 line-clamp-2"},Te={class:"flex items-center flex-wrap gap-3 mt-4 pt-3 border-t"},Me={class:"flex items-center gap-1.5 text-xs text-muted-foreground"},Re={class:"flex items-center gap-1.5 text-xs text-muted-foreground"},Ae={class:"flex items-center gap-2"},ze={class:"text-xs text-muted-foreground"},Le={key:1,class:"flex items-center gap-1.5 text-xs text-orange-500"},$e={key:2,class:"text-center py-8 text-muted-foreground"},Ie={key:3,class:"flex justify-center py-12"},Ue={key:5,class:"fixed bottom-4 right-4 bg-background border rounded-lg px-4 py-2 shadow-lg flex items-center gap-2"},Fe=e.defineComponent({__name:"resources",setup(Q){const{width:R}=ee.useWindowSize(),{params:y}=M.useModuleRoute(),{confirm:C}=M.useConfirmation(),{config:i}=M.useModule(),p=M.useFirebaseIntegration(i.project),d=e.ref([]),g=e.ref(!1),n=e.ref(!0),w=e.ref(),N=e.ref(""),k=()=>Date.now().toString(36)+Math.random().toString(36).substr(2),A=async()=>{try{n.value=!0;const l=await p.get(i.agendaCollection,y.value.id);d.value=l.resources||[]}catch(l){console.error("Error loading resources:",l)}finally{n.value=!1}},f=async()=>{g.value=!0;try{await p.update(i.agendaCollection,y.value.id,{resources:d.value})}catch(l){console.error("Error saving resources:",l)}finally{g.value=!1}},E=l=>{const o={...l,id:k()};d.value.push(o),f()},z=l=>{const o=d.value.findIndex(c=>c.id===l.id);o!==-1&&(d.value[o]=l),f()},h=async l=>{await C("Are you sure you want to delete this resource? This action cannot be undone.","Delete Resource","Delete")&&(d.value=d.value.filter(c=>c.id!==l),f())},L=async l=>{const o=d.value.findIndex(c=>c.id===l.id);o!==-1&&(d.value[o].isActive=!d.value[o].isActive,await f())},$=l=>{const o={...l,id:k(),name:`${l.name} (Copy)`,publicLabel:l.publicLabel?`${l.publicLabel} (Copy)`:""};d.value.push(o),f()},r=()=>{w.value?.openDialog()},t=l=>{w.value?.openDialog(l)},x=e.computed(()=>{if(!N.value.trim())return d.value;const l=N.value.toLowerCase();return d.value.filter(o=>o.name.toLowerCase().includes(l)||o.publicLabel?.toLowerCase().includes(l))}),I=e.computed(()=>d.value.filter(l=>l.isActive).length),D=e.computed(()=>d.value.length);return A(),(l,o)=>{const c=e.resolveComponent("Button"),U=e.resolveComponent("Input"),F=e.resolveComponent("DropdownMenuTrigger"),b=e.resolveComponent("DropdownMenuItem"),H=e.resolveComponent("DropdownMenuSeparator"),j=e.resolveComponent("DropdownMenuContent"),q=e.resolveComponent("DropdownMenu"),V=e.resolveComponent("Switch"),O=e.resolveComponent("Card"),B=e.resolveComponent("Spinner"),m=e.resolveComponent("EmptyMedia"),P=e.resolveComponent("EmptyTitle"),S=e.resolveComponent("EmptyDescription"),Y=e.resolveComponent("EmptyHeader"),J=e.resolveComponent("EmptyContent"),W=e.resolveComponent("Empty");return e.openBlock(),e.createBlock(Z._sfc_main,null,{default:e.withCtx(()=>[e.createElementVNode("div",xe,[e.createElementVNode("div",Ve,[o[2]||(o[2]=e.createElementVNode("div",null,[e.createElementVNode("h1",{class:"text-lg font-medium"},"Resource Management"),e.createElementVNode("p",{class:"text-muted-foreground text-sm mt-1"}," Define the rooms, boxes, or staff that can be booked in this agenda. ")],-1)),d.value.length>0?(e.openBlock(),e.createBlock(c,{key:0,onClick:r},{default:e.withCtx(()=>[e.createVNode(e.unref(u.Plus),{class:"size-4 mr-1.5"}),o[1]||(o[1]=e.createTextVNode(" Add Resource ",-1))]),_:1})):e.createCommentVNode("",!0)]),e.createElementVNode("div",ge,[d.value.length>0?(e.openBlock(),e.createElementBlock("div",Ne,[e.createElementVNode("div",Ce,[e.createVNode(U,{modelValue:N.value,"onUpdate:modelValue":o[0]||(o[0]=s=>N.value=s),placeholder:"Search resources...",class:"pl-9"},null,8,["modelValue"]),o[3]||(o[3]=e.createElementVNode("svg",{class:"absolute left-3 top-1/2 -translate-y-1/2 size-4 text-muted-foreground",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[e.createElementVNode("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})],-1))]),e.createElementVNode("div",we,e.toDisplayString(I.value)+" active of "+e.toDisplayString(D.value)+" resource"+e.toDisplayString(D.value!==1?"s":""),1)])):e.createCommentVNode("",!0),x.value.length>0?(e.openBlock(),e.createElementBlock("div",be,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(x.value,s=>(e.openBlock(),e.createBlock(O,{key:s.id,class:e.normalizeClass(["group relative overflow-hidden transition-all duration-200 hover:shadow-md",s.isActive?"":"opacity-60 grayscale-[30%]"])},{default:e.withCtx(()=>[e.createElementVNode("div",{class:"absolute inset-y-0 left-0 w-1 transition-all duration-200 group-hover:w-1.5",style:e.normalizeStyle({background:s.color})},null,4),e.createElementVNode("div",_e,[e.createElementVNode("div",ye,[e.createElementVNode("div",{class:"size-11 rounded-xl flex-shrink-0 flex items-center justify-center text-white font-semibold text-sm shadow-sm",style:e.normalizeStyle({background:s.color})},e.toDisplayString(s.avatarLabel||s.name.charAt(0).toUpperCase()),5),e.createElementVNode("div",ke,[e.createElementVNode("div",Ee,[e.createElementVNode("h3",he,[e.createTextVNode(e.toDisplayString(s.name)+" ",1),s.isActive?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("span",De,"(Inactive)"))])]),s.publicLabel&&s.publicLabel!==s.name?(e.openBlock(),e.createElementBlock("p",Be,e.toDisplayString(s.publicLabel),1)):e.createCommentVNode("",!0)]),e.createVNode(q,null,{default:e.withCtx(()=>[e.createVNode(F,{"as-child":""},{default:e.withCtx(()=>[e.createVNode(c,{variant:"ghost",size:"icon",class:"size-8"},{default:e.withCtx(()=>[...o[4]||(o[4]=[e.createElementVNode("svg",{class:"size-4",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[e.createElementVNode("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M12 5v.01M12 12v.01M12 19v.01M12 6a1 1 0 110-2 1 1 0 010 2zm0 7a1 1 0 110-2 1 1 0 010 2zm0 7a1 1 0 110-2 1 1 0 010 2z"})],-1)])]),_:1})]),_:1}),e.createVNode(j,{align:"end"},{default:e.withCtx(()=>[e.createVNode(b,{onClick:_=>t(s)},{default:e.withCtx(()=>[e.createVNode(e.unref(u.Pencil),{class:"size-4 mr-2"}),o[5]||(o[5]=e.createTextVNode(" Edit ",-1))]),_:1},8,["onClick"]),e.createVNode(b,{onClick:_=>$(s)},{default:e.withCtx(()=>[e.createVNode(e.unref(u.Copy),{class:"size-4 mr-2"}),o[6]||(o[6]=e.createTextVNode(" Duplicate ",-1))]),_:1},8,["onClick"]),e.createVNode(H),e.createVNode(b,{variant:"destructive",onClick:_=>h(s.id)},{default:e.withCtx(()=>[e.createVNode(e.unref(u.Trash2),{class:"size-4 mr-2"}),o[7]||(o[7]=e.createTextVNode(" Delete ",-1))]),_:1},8,["onClick"])]),_:2},1024)]),_:2},1024)]),s.description?(e.openBlock(),e.createElementBlock("p",Se,e.toDisplayString(s.description),1)):e.createCommentVNode("",!0),e.createElementVNode("div",Te,[e.createElementVNode("div",Me,[e.createVNode(e.unref(u.Users),{class:"size-3.5"}),e.createElementVNode("span",null,e.toDisplayString(s.capacity)+" "+e.toDisplayString(s.capacity===1?"slot":"slots"),1)]),e.createElementVNode("div",Re,[o[8]||(o[8]=e.createElementVNode("svg",{class:"size-3.5",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[e.createElementVNode("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"})],-1)),e.createElementVNode("span",null,e.toDisplayString(s.interval)+" min",1)]),e.unref(R)>=640?(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[o[9]||(o[9]=e.createElementVNode("div",{class:"flex-1"},null,-1)),e.createElementVNode("div",Ae,[e.createElementVNode("span",ze,e.toDisplayString(s.isActive?"Active":"Inactive"),1),e.createVNode(V,{defaultValue:s.isActive,"onUpdate:modelValue":_=>L(s),class:"scale-90"},null,8,["defaultValue","onUpdate:modelValue"])])],64)):s.isActive?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("div",Le,[e.createVNode(e.unref(u.CircleAlert),{class:"size-3.5"}),o[10]||(o[10]=e.createElementVNode("span",null,"Inactive",-1))]))])])]),_:2},1032,["class"]))),128))])):d.value.length>0&&x.value.length===0?(e.openBlock(),e.createElementBlock("div",$e,[...o[11]||(o[11]=[e.createElementVNode("p",null,"No resources match your search.",-1)])])):n.value?(e.openBlock(),e.createElementBlock("div",Ie,[e.createVNode(B,{class:"size-8"})])):(e.openBlock(),e.createBlock(W,{key:4,class:"border border-dashed"},{default:e.withCtx(()=>[e.createVNode(Y,null,{default:e.withCtx(()=>[e.createVNode(m,{variant:"icon"},{default:e.withCtx(()=>[e.createVNode(e.unref(u.Users),{class:"size-6"})]),_:1}),e.createVNode(P,null,{default:e.withCtx(()=>[...o[12]||(o[12]=[e.createTextVNode("No Resources Yet",-1)])]),_:1}),e.createVNode(S,null,{default:e.withCtx(()=>[...o[13]||(o[13]=[e.createTextVNode(" You haven't added any bookable resources yet. Define your staff, rooms, or equipment to start configuring availability. ",-1)])]),_:1})]),_:1}),e.createVNode(J,null,{default:e.withCtx(()=>[e.createVNode(c,{variant:"outline",onClick:r},{default:e.withCtx(()=>[e.createVNode(e.unref(u.Plus),{class:"size-4 mr-1.5"}),o[14]||(o[14]=e.createTextVNode(" Add Your First Resource ",-1))]),_:1})]),_:1})]),_:1})),g.value?(e.openBlock(),e.createElementBlock("div",Ue,[e.createVNode(B,{class:"size-4"}),o[15]||(o[15]=e.createElementVNode("span",{class:"text-sm"},"Saving...",-1))])):e.createCommentVNode("",!0)])]),e.createVNode(fe,{ref_key:"resourceDialogRef",ref:w,onAddResource:E,onUpdateResource:z,onRemoveResource:h},null,512)]),_:1})}}});exports.default=Fe;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { defineComponent as ce, ref as S, reactive as xe, computed as O, resolveComponent as a, openBlock as m, createBlock as C, withCtx as n, createVNode as t, createTextVNode as r, toDisplayString as v, createElementVNode as o, createElementBlock as f, Fragment as E, renderList as Y, normalizeStyle as ie, normalizeClass as me, unref as g, createCommentVNode as w } from "vue";
|
|
2
|
-
import { _ as be } from "./EditLayout.vue_vue_type_script_setup_true_lang-
|
|
2
|
+
import { _ as be } from "./EditLayout.vue_vue_type_script_setup_true_lang-DWMqQvHl.mjs";
|
|
3
3
|
import { Clock as _e, MoreHorizontal as we, Trash2 as pe, Plus as de, Pencil as ye, Copy as ke, Users as ue, CircleAlert as Ce } from "lucide-vue-next";
|
|
4
4
|
import { useModuleRoute as De, useConfirmation as Ve, useModule as he, useFirebaseIntegration as Se } from "@oneclick.dev/cms-kit";
|
|
5
|
-
import {
|
|
5
|
+
import { u as Re } from "./index-MYWjg0zi.mjs";
|
|
6
6
|
const Ae = { class: "space-y-5 py-4" }, Me = { class: "flex flex-wrap gap-2 mt-2" }, ze = ["onClick"], Le = { class: "space-y-2" }, $e = { class: "flex items-center justify-between mb-2" }, Ee = { class: "text-sm font-medium" }, Ie = { class: "flex items-center gap-1" }, Ue = { class: "space-y-2" }, Ne = {
|
|
7
7
|
key: 0,
|
|
8
8
|
class: "text-sm text-muted-foreground italic py-1"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("h3");require("vue");function b(f){const{initFirebase:v,normalizeTimestamps:D}=f,y=r.createRouter();async function l(u){const{supabase:d,instanceId:g}=u.context.module,{data:e,error:a}=await d.from("project_modules").select("config").eq("id",g).single();if(a||!e?.config)throw r.createError({statusCode:500,statusMessage:"Failed to load module config."});const o=e.config,t=o.project,s=o.productCollection||"products";if(!t)throw r.createError({statusCode:400,statusMessage:"Products module has no Firebase integration configured."});return{firebase:await v(u,t),collection:s}}return y.get("/products",r.defineEventHandler(async u=>{try{const{firebase:d,collection:g}=await l(u);return(await d.firestore().collection(g).get()).docs.map(a=>D({id:a.id,...a.data()}))}catch(d){throw console.error("Products handler — list error:",d),r.createError({statusCode:d.statusCode||500,statusMessage:d.statusMessage||"Failed to list products"})}})),y.get("/products/:productId",r.defineEventHandler(async u=>{const d=r.getRouterParam(u,"productId");if(!d)throw r.createError({statusCode:400,statusMessage:"Product ID is required."});try{const{firebase:g,collection:e}=await l(u),a=await g.firestore().collection(e).doc(d).get();if(!a.exists)throw r.createError({statusCode:404,statusMessage:"Product not found."});return D({id:a.id,...a.data()})}catch(g){throw console.error("Products handler — get error:",g),r.createError({statusCode:g.statusCode||500,statusMessage:g.statusMessage||"Failed to get product"})}})),y.get("/empty-stock",r.defineEventHandler(async u=>{const g=r.getQuery(u).category;try{const{firebase:e,collection:a}=await l(u);let o=e.firestore().collection(a).where("stock","==",0);g&&(o=o.where("collections","array-contains",g));const s=(await o.get()).docs.map(n=>D({id:n.id,...n.data()}));return{count:s.length,products:s.map(n=>({id:n.id,title:n.title,slug:n.slug,stock:n.stock,price:n.price,currency:n.currency,status:n.status}))}}catch(e){throw console.error("Products handler — empty-stock error:",e),r.createError({statusCode:e.statusCode||500,statusMessage:e.statusMessage||"Failed to query empty stock"})}})),y.handler}function M(f){const{initFirebase:v,normalizeTimestamps:D}=f,y=r.createRouter();async function l(d){const{supabase:g,instanceId:e}=d.context.module,{data:a,error:o}=await g.from("project_modules").select("config").eq("id",e).single();if(o||!a?.config)throw r.createError({statusCode:500,statusMessage:"Failed to load module config."});const t=a.config,s=t.project,n=t.reservationsCollection||"bookings_orders",i=t.agendaCollection||"agendas";if(!s)throw r.createError({statusCode:400,statusMessage:"Appointments module has no Firebase integration configured."});return{firebase:await v(d,s),reservationsCollection:n,agendaCollection:i}}function u(d){return(d.reservations||[]).map(e=>({orderId:d.id,reservationId:e.id,customerInfo:d.customerInfo,date:e.date,startTime:e.timeslot?.startTime,endTime:e.timeslot?.endTime,spots:e.spots,status:d.status,reservationStatus:e.status,resourceId:e.resourceId,reservationPrice:e.totalPrice,reservationBasePrice:e.basePrice,reservationAddOnsPrice:e.addOnsPrice,pricingOption:e.pricingOption,amountDue:d.amountDue,amountPaid:d.amountPaid,createdAt:d.createdAt}))}return y.get("/appointments",r.defineEventHandler(async d=>{const g=r.getQuery(d),e=Math.min(Number(g.quantity)||20,100);try{const{firebase:a,reservationsCollection:o}=await l(d),s=(await a.firestore().collection(o).orderBy("createdAt","desc").limit(e).get()).docs.flatMap(n=>u(D({id:n.id,...n.data()})));return{count:s.length,appointments:s}}catch(a){throw console.error("Appointments handler — list error:",a),r.createError({statusCode:a.statusCode||500,statusMessage:a.statusMessage||"Failed to list appointments"})}})),y.get("/appointments/find",r.defineEventHandler(async d=>{const g=r.getQuery(d),e=(g.name||"").toLowerCase().trim(),a=(g.email||"").toLowerCase().trim(),o=g.date;try{const{firebase:t,reservationsCollection:s}=await l(d);let n=t.firestore().collection(s);a&&(n=n.where("customerInfo.email","==",a));let c=(await n.orderBy("createdAt","desc").limit(200).get()).docs.flatMap(m=>u(D({id:m.id,...m.data()})));return o&&(c=c.filter(m=>m.date===o)),e&&(c=c.filter(m=>{const p=(m.customerInfo?.firstName||"").toLowerCase(),w=(m.customerInfo?.lastName||"").toLowerCase();return p.includes(e)||w.includes(e)||`${p} ${w}`.includes(e)})),{count:c.length,appointments:c}}catch(t){throw console.error("Appointments handler — find error:",t),r.createError({statusCode:t.statusCode||500,statusMessage:t.statusMessage||"Failed to find appointments"})}})),y.get("/appointments/:appointmentId",r.defineEventHandler(async d=>{const g=r.getRouterParam(d,"appointmentId");if(!g)throw r.createError({statusCode:400,statusMessage:"Appointment ID is required."});try{const{firebase:e,reservationsCollection:a}=await l(d),o=await e.firestore().collection(a).doc(g).get();if(!o.exists)throw r.createError({statusCode:404,statusMessage:"Appointment not found."});const t=D({id:o.id,...o.data()});return{...t,reservations:u(t)}}catch(e){throw console.error("Appointments handler — get error:",e),r.createError({statusCode:e.statusCode||500,statusMessage:e.statusMessage||"Failed to get appointment"})}})),y.handler}const P="https://analyticsdata.googleapis.com/v1beta",T=["https://www.googleapis.com/auth/analytics.readonly","https://www.googleapis.com/auth/webmasters.readonly"],S="https://searchconsole.googleapis.com/webmasters/v3";function N(f){const{decrypt:v,getGoogleAccessToken:D}=f,y=r.createRouter();async function l(e){const{supabase:a,instanceId:o}=e.context.module,{data:t,error:s}=await a.from("project_modules").select("config").eq("id",o).single();if(s||!t?.config)throw r.createError({statusCode:500,statusMessage:"Failed to load module config."});const n=t.config,i=n.propertyId,c=n.serviceAccount,m=n.siteUrl||"";if(!c)throw r.createError({statusCode:400,statusMessage:"No Google Service Account configured for this module."});if(!i)throw r.createError({statusCode:400,statusMessage:"No GA4 Property ID configured for this module."});const{data:p,error:w}=await a.from("integrations").select("config").eq("id",c).single();let h=p?.config;if(w||!h){const{data:I,error:q}=await a.from("agency_integrations").select("config").eq("id",c).single();if(q||!I?.config)throw r.createError({statusCode:500,statusMessage:"Failed to load Google Service Account credentials."});h=I.config}const A=v(h.clientEmail),E=v(h.privateKey),R=v(h.projectId);return{accessToken:await D({clientEmail:A,privateKey:E,projectId:R},T),propertyId:i,siteUrl:m}}async function u(e,a,o){const t=await fetch(`${P}/properties/${a}:runReport`,{method:"POST",headers:{Authorization:`Bearer ${e}`,"Content-Type":"application/json"},body:JSON.stringify(o)});if(!t.ok){const s=await t.json().catch(()=>({}));throw console.error("GA4 runReport failed:",s),r.createError({statusCode:t.status,statusMessage:s?.error?.message||"GA4 API request failed"})}return t.json()}y.get("/report",r.defineEventHandler(async e=>{const{accessToken:a,propertyId:o}=await l(e),t=r.getQuery(e),s=t.startDate||"30daysAgo",n=t.endDate||"today",i=s.match(/^(\d+)daysAgo$/),c=i?parseInt(i[1],10):30,m=`${c*2}daysAgo`,p=`${c+1}daysAgo`,w=[{name:"sessions"},{name:"totalUsers"},{name:"screenPageViews"},{name:"bounceRate"},{name:"averageSessionDuration"},{name:"newUsers"},{name:"engagementRate"},{name:"sessionsPerUser"},{name:"screenPageViewsPerSession"}];let h,A=!0;try{h=await u(a,o,{dateRanges:[{startDate:s,endDate:n,name:"current"},{startDate:m,endDate:p,name:"previous"}],dimensions:[{name:"date"}],metrics:w,metricAggregations:["TOTAL"],orderBys:[{dimension:{dimensionName:"date"}}]})}catch{A=!1,h=await u(a,o,{dateRanges:[{startDate:s,endDate:n}],dimensions:[{name:"date"}],metrics:w,metricAggregations:["TOTAL"],orderBys:[{dimension:{dimensionName:"date"}}]})}return H(h,A)})),y.get("/realtime",r.defineEventHandler(async e=>{const{accessToken:a,propertyId:o}=await l(e),t=await fetch(`${P}/properties/${o}:runRealtimeReport`,{method:"POST",headers:{Authorization:`Bearer ${a}`,"Content-Type":"application/json"},body:JSON.stringify({dimensions:[{name:"unifiedScreenName"}],metrics:[{name:"activeUsers"}],orderBys:[{metric:{metricName:"activeUsers"},desc:!0}],limit:5})});if(!t.ok){const c=await t.json().catch(()=>({}));throw r.createError({statusCode:t.status,statusMessage:c?.error?.message||"Realtime API failed"})}const s=await t.json(),n=(s?.rows||[]).reduce((c,m)=>c+parseInt(m.metricValues?.[0]?.value||"0",10),0),i=(s?.rows||[]).map(c=>({page:c.dimensionValues?.[0]?.value||"(not set)",activeUsers:parseInt(c.metricValues?.[0]?.value||"0",10)}));return{activeUsers:n,activePages:i}})),y.get("/top-pages",r.defineEventHandler(async e=>{const{accessToken:a,propertyId:o}=await l(e),t=r.getQuery(e),s=t.startDate||"30daysAgo",n=t.endDate||"today",i=parseInt(t.limit||"10",10),c=await u(a,o,{dateRanges:[{startDate:s,endDate:n}],dimensions:[{name:"pagePath"}],metrics:[{name:"screenPageViews"},{name:"totalUsers"},{name:"averageSessionDuration"}],orderBys:[{metric:{metricName:"screenPageViews"},desc:!0}],limit:i*2}),m=C(c,"pagePath"),p=new Map;for(const h of m.rows){const A=h.pagePath.toLowerCase().replace(/\/+$/,""),E=p.get(A);if(E){E.screenPageViews+=h.screenPageViews||0,E.totalUsers+=h.totalUsers||0;const R=E.screenPageViews;R>0&&(E.averageSessionDuration=(E.averageSessionDuration*(R-(h.screenPageViews||0))+(h.averageSessionDuration||0)*(h.screenPageViews||0))/R)}else p.set(A,{...h})}return{rows:[...p.values()].sort((h,A)=>(A.screenPageViews||0)-(h.screenPageViews||0)).slice(0,i),rowCount:m.rowCount}})),y.get("/top-sources",r.defineEventHandler(async e=>{const{accessToken:a,propertyId:o}=await l(e),t=r.getQuery(e),s=t.startDate||"30daysAgo",n=t.endDate||"today",i=await u(a,o,{dateRanges:[{startDate:s,endDate:n}],dimensions:[{name:"sessionSource"}],metrics:[{name:"sessions"},{name:"totalUsers"}],orderBys:[{metric:{metricName:"sessions"},desc:!0}],limit:10});return C(i,"sessionSource")})),y.get("/devices",r.defineEventHandler(async e=>{const{accessToken:a,propertyId:o}=await l(e),t=r.getQuery(e),s=t.startDate||"30daysAgo",n=t.endDate||"today",i=await u(a,o,{dateRanges:[{startDate:s,endDate:n}],dimensions:[{name:"deviceCategory"}],metrics:[{name:"sessions"},{name:"totalUsers"}],orderBys:[{metric:{metricName:"sessions"},desc:!0}]});return C(i,"deviceCategory")})),y.get("/countries",r.defineEventHandler(async e=>{const{accessToken:a,propertyId:o}=await l(e),t=r.getQuery(e),s=t.startDate||"30daysAgo",n=t.endDate||"today",i=await u(a,o,{dateRanges:[{startDate:s,endDate:n}],dimensions:[{name:"country"}],metrics:[{name:"sessions"},{name:"totalUsers"}],orderBys:[{metric:{metricName:"sessions"},desc:!0}],limit:10});return C(i,"country")})),y.get("/acquisition/channels",r.defineEventHandler(async e=>{const{accessToken:a,propertyId:o}=await l(e),t=r.getQuery(e),s=t.startDate||"30daysAgo",n=t.endDate||"today",i=await u(a,o,{dateRanges:[{startDate:s,endDate:n}],dimensions:[{name:"sessionDefaultChannelGroup"}],metrics:[{name:"sessions"},{name:"totalUsers"},{name:"newUsers"},{name:"engagementRate"},{name:"averageSessionDuration"},{name:"screenPageViewsPerSession"},{name:"conversions"}],orderBys:[{metric:{metricName:"sessions"},desc:!0}],limit:15});return C(i,"sessionDefaultChannelGroup")})),y.get("/acquisition/source-medium",r.defineEventHandler(async e=>{const{accessToken:a,propertyId:o}=await l(e),t=r.getQuery(e),s=t.startDate||"30daysAgo",n=t.endDate||"today",i=await u(a,o,{dateRanges:[{startDate:s,endDate:n}],dimensions:[{name:"sessionSourceMedium"}],metrics:[{name:"sessions"},{name:"totalUsers"},{name:"newUsers"},{name:"bounceRate"},{name:"averageSessionDuration"},{name:"conversions"}],orderBys:[{metric:{metricName:"sessions"},desc:!0}],limit:20});return C(i,"sessionSourceMedium")})),y.get("/acquisition/referrals",r.defineEventHandler(async e=>{const{accessToken:a,propertyId:o}=await l(e),t=r.getQuery(e),s=t.startDate||"30daysAgo",n=t.endDate||"today",i=await u(a,o,{dateRanges:[{startDate:s,endDate:n}],dimensions:[{name:"sessionSource"}],dimensionFilter:{filter:{fieldName:"sessionMedium",stringFilter:{value:"referral"}}},metrics:[{name:"sessions"},{name:"totalUsers"},{name:"engagementRate"},{name:"averageSessionDuration"}],orderBys:[{metric:{metricName:"sessions"},desc:!0}],limit:20});return C(i,"sessionSource")})),y.get("/acquisition/campaigns",r.defineEventHandler(async e=>{const{accessToken:a,propertyId:o}=await l(e),t=r.getQuery(e),s=t.startDate||"30daysAgo",n=t.endDate||"today",i=await u(a,o,{dateRanges:[{startDate:s,endDate:n}],dimensions:[{name:"sessionCampaignName"}],dimensionFilter:{notExpression:{filter:{fieldName:"sessionCampaignName",stringFilter:{value:"(not set)"}}}},metrics:[{name:"sessions"},{name:"totalUsers"},{name:"conversions"},{name:"engagementRate"}],orderBys:[{metric:{metricName:"sessions"},desc:!0}],limit:20});return C(i,"sessionCampaignName")})),y.get("/content/all-pages",r.defineEventHandler(async e=>{const{accessToken:a,propertyId:o}=await l(e),t=r.getQuery(e),s=t.startDate||"30daysAgo",n=t.endDate||"today",i=parseInt(t.limit||"50",10),c=await u(a,o,{dateRanges:[{startDate:s,endDate:n}],dimensions:[{name:"pagePath"}],metrics:[{name:"screenPageViews"},{name:"totalUsers"},{name:"averageSessionDuration"},{name:"bounceRate"},{name:"engagementRate"},{name:"sessions"},{name:"userEngagementDuration"}],orderBys:[{metric:{metricName:"screenPageViews"},desc:!0}],limit:i});return C(c,"pagePath")})),y.get("/content/landing-pages",r.defineEventHandler(async e=>{const{accessToken:a,propertyId:o}=await l(e),t=r.getQuery(e),s=t.startDate||"30daysAgo",n=t.endDate||"today",i=await u(a,o,{dateRanges:[{startDate:s,endDate:n}],dimensions:[{name:"landingPagePlusQueryString"}],metrics:[{name:"sessions"},{name:"totalUsers"},{name:"bounceRate"},{name:"averageSessionDuration"},{name:"screenPageViews"},{name:"engagementRate"}],orderBys:[{metric:{metricName:"sessions"},desc:!0}],limit:30});return C(i,"landingPagePlusQueryString")})),y.get("/content/exit-pages",r.defineEventHandler(async e=>{const{accessToken:a,propertyId:o}=await l(e),t=r.getQuery(e),s=t.startDate||"30daysAgo",n=t.endDate||"today",i=await u(a,o,{dateRanges:[{startDate:s,endDate:n}],dimensions:[{name:"pagePath"}],metrics:[{name:"sessions"},{name:"screenPageViews"},{name:"totalUsers"},{name:"bounceRate"}],orderBys:[{metric:{metricName:"screenPageViews"},desc:!0}],limit:20}),c=C(i,"pagePath");return c.rows=c.rows.map(m=>({...m,exitRate:m.bounceRate||0})),c})),y.get("/content/search-terms",r.defineEventHandler(async e=>{const{accessToken:a,propertyId:o,siteUrl:t}=await l(e),s=r.getQuery(e),n=s.startDate||"30daysAgo",i=s.endDate||"today";if(t)try{const p=`${S}/sites/${encodeURIComponent(t)}/searchAnalytics/query`,w=await fetch(p,{method:"POST",headers:{Authorization:`Bearer ${a}`,"Content-Type":"application/json"},body:JSON.stringify({startDate:d(n),endDate:d(i),dimensions:["query"],rowLimit:30})});if(w.ok){const A=((await w.json()).rows||[]).map(E=>({query:E.keys[0],clicks:E.clicks,impressions:E.impressions,ctr:E.ctr,position:E.position}));if(A.length>0)return{rows:A,rowCount:A.length,source:"search_console"}}else{const h=await w.text().catch(()=>"");console.error(`[GA Module] Search Console API error (${w.status}):`,h)}}catch(p){console.error("[GA Module] Search Console request failed:",p?.message||p)}else console.log("[GA Module] No siteUrl configured, skipping Search Console");try{const p=await u(a,o,{dateRanges:[{startDate:n,endDate:i}],dimensions:[{name:"sessionGoogleAdsQuery"}],metrics:[{name:"sessions"},{name:"totalUsers"},{name:"engagementRate"}],dimensionFilter:{andGroup:{expressions:[{notExpression:{filter:{fieldName:"sessionGoogleAdsQuery",stringFilter:{value:"(not set)"}}}},{notExpression:{filter:{fieldName:"sessionGoogleAdsQuery",stringFilter:{value:"(not provided)"}}}}]}},orderBys:[{metric:{metricName:"sessions"},desc:!0}],limit:30}),w=C(p,"sessionGoogleAdsQuery");if(w.rows.length>0)return{...w,source:"google_ads"}}catch{}const c=await u(a,o,{dateRanges:[{startDate:n,endDate:i}],dimensions:[{name:"landingPagePlusQueryString"}],metrics:[{name:"sessions"},{name:"totalUsers"},{name:"engagementRate"}],dimensionFilter:{andGroup:{expressions:[{filter:{fieldName:"sessionMedium",stringFilter:{matchType:"EXACT",value:"organic"}}},{notExpression:{filter:{fieldName:"landingPagePlusQueryString",stringFilter:{value:"(not set)"}}}}]}},orderBys:[{metric:{metricName:"sessions"},desc:!0}],limit:30});return{...C(c,"landingPagePlusQueryString"),source:"organic_landing_pages"}})),y.get("/audience/overview",r.defineEventHandler(async e=>{const{accessToken:a,propertyId:o}=await l(e),t=r.getQuery(e),s=t.startDate||"30daysAgo",n=t.endDate||"today",i=await u(a,o,{dateRanges:[{startDate:s,endDate:n}],dimensions:[{name:"newVsReturning"}],metrics:[{name:"totalUsers"},{name:"sessions"},{name:"engagementRate"},{name:"averageSessionDuration"},{name:"screenPageViewsPerSession"}],metricAggregations:["TOTAL"]});return C(i,"newVsReturning")})),y.get("/audience/technology",r.defineEventHandler(async e=>{const{accessToken:a,propertyId:o}=await l(e),t=r.getQuery(e),s=t.startDate||"30daysAgo",n=t.endDate||"today",i=t.dimension||"browser",m=["browser","operatingSystem","screenResolution"].includes(i)?i:"browser",p=await u(a,o,{dateRanges:[{startDate:s,endDate:n}],dimensions:[{name:m}],metrics:[{name:"totalUsers"},{name:"sessions"},{name:"engagementRate"}],orderBys:[{metric:{metricName:"totalUsers"},desc:!0}],limit:10});return C(p,m)})),y.get("/audience/languages",r.defineEventHandler(async e=>{const{accessToken:a,propertyId:o}=await l(e),t=r.getQuery(e),s=t.startDate||"30daysAgo",n=t.endDate||"today",i=await u(a,o,{dateRanges:[{startDate:s,endDate:n}],dimensions:[{name:"language"}],metrics:[{name:"totalUsers"},{name:"sessions"}],orderBys:[{metric:{metricName:"totalUsers"},desc:!0}],limit:15});return C(i,"language")})),y.get("/audience/hours",r.defineEventHandler(async e=>{const{accessToken:a,propertyId:o}=await l(e),t=r.getQuery(e),s=t.startDate||"30daysAgo",n=t.endDate||"today",i=await u(a,o,{dateRanges:[{startDate:s,endDate:n}],dimensions:[{name:"dayOfWeekName"},{name:"hour"}],metrics:[{name:"sessions"}],orderBys:[{dimension:{dimensionName:"dayOfWeekName"}},{dimension:{dimensionName:"hour"}}],limit:168});return k(i,["dayOfWeekName","hour"])})),y.get("/audience/cities",r.defineEventHandler(async e=>{const{accessToken:a,propertyId:o}=await l(e),t=r.getQuery(e),s=t.startDate||"30daysAgo",n=t.endDate||"today",i=await u(a,o,{dateRanges:[{startDate:s,endDate:n}],dimensions:[{name:"city"},{name:"country"}],metrics:[{name:"totalUsers"},{name:"sessions"}],dimensionFilter:{notExpression:{filter:{fieldName:"city",stringFilter:{value:"(not set)"}}}},orderBys:[{metric:{metricName:"totalUsers"},desc:!0}],limit:20});return k(i,["city","country"])}));function d(e){const a=e.match(/^(\d+)daysAgo$/);if(a){const o=new Date;return o.setDate(o.getDate()-parseInt(a[1],10)),o.toISOString().slice(0,10)}if(e==="today")return new Date().toISOString().slice(0,10);if(e==="yesterday"){const o=new Date;return o.setDate(o.getDate()-1),o.toISOString().slice(0,10)}return e}async function g(e,a,o){const t=`${S}/sites/${encodeURIComponent(a)}/searchAnalytics/query`,s=await fetch(t,{method:"POST",headers:{Authorization:`Bearer ${e}`,"Content-Type":"application/json"},body:JSON.stringify(o)});if(!s.ok){const n=await s.json().catch(()=>({}));throw r.createError({statusCode:s.status,statusMessage:n?.error?.message||"Search Console API request failed"})}return s.json()}return y.get("/seo/keywords",r.defineEventHandler(async e=>{const{accessToken:a,siteUrl:o}=await l(e);if(!o)throw r.createError({statusCode:400,statusMessage:"Search Console Site URL is not configured. Add it in module settings."});const t=r.getQuery(e),s=d(t.startDate||"30daysAgo"),n=d(t.endDate||"today"),i=Math.min(parseInt(t.limit)||50,100),c=await g(a,o,{startDate:s,endDate:n,dimensions:["query"],rowLimit:i});return{rows:(c.rows||[]).map(m=>({query:m.keys[0],clicks:m.clicks,impressions:m.impressions,ctr:m.ctr,position:m.position})),rowCount:c.rows?.length||0}})),y.get("/seo/pages",r.defineEventHandler(async e=>{const{accessToken:a,siteUrl:o}=await l(e);if(!o)throw r.createError({statusCode:400,statusMessage:"Search Console Site URL is not configured."});const t=r.getQuery(e),s=d(t.startDate||"30daysAgo"),n=d(t.endDate||"today"),i=Math.min(parseInt(t.limit)||50,100),c=await g(a,o,{startDate:s,endDate:n,dimensions:["page"],rowLimit:i});return{rows:(c.rows||[]).map(m=>({page:m.keys[0],clicks:m.clicks,impressions:m.impressions,ctr:m.ctr,position:m.position})),rowCount:c.rows?.length||0}})),y.get("/seo/trends",r.defineEventHandler(async e=>{const{accessToken:a,siteUrl:o}=await l(e);if(!o)throw r.createError({statusCode:400,statusMessage:"Search Console Site URL is not configured."});const t=r.getQuery(e),s=d(t.startDate||"30daysAgo"),n=d(t.endDate||"today"),c=((await g(a,o,{startDate:s,endDate:n,dimensions:["date"],rowLimit:500})).rows||[]).map(p=>({date:p.keys[0],clicks:p.clicks,impressions:p.impressions,ctr:p.ctr,position:p.position})).sort((p,w)=>p.date.localeCompare(w.date)),m=c.reduce((p,w)=>({clicks:p.clicks+w.clicks,impressions:p.impressions+w.impressions}),{clicks:0,impressions:0});return m.ctr=m.impressions>0?m.clicks/m.impressions:0,m.avgPosition=c.length>0?c.reduce((p,w)=>p+w.position,0)/c.length:0,{rows:c,totals:m,rowCount:c.length}})),y.get("/seo/query-pages",r.defineEventHandler(async e=>{const{accessToken:a,siteUrl:o}=await l(e);if(!o)throw r.createError({statusCode:400,statusMessage:"Search Console Site URL is not configured."});const t=r.getQuery(e),s=d(t.startDate||"30daysAgo"),n=d(t.endDate||"today"),i=await g(a,o,{startDate:s,endDate:n,dimensions:["query","page"],rowLimit:100});return{rows:(i.rows||[]).map(c=>({query:c.keys[0],page:c.keys[1],clicks:c.clicks,impressions:c.impressions,ctr:c.ctr,position:c.position})),rowCount:i.rows?.length||0}})),y.handler}function H(f,v=!0){const D=(f.metricHeaders||[]).map(s=>s.name),l=(f.dimensionHeaders||[]).map(s=>s.name).indexOf("date"),u=[];(f.rows||[]).forEach(s=>{const n=l>=0?s.dimensionValues[l]?.value:s.dimensionValues[0]?.value;if(!n||n.length<8)return;const c={date:`${n.slice(0,4)}-${n.slice(4,6)}-${n.slice(6,8)}`};D.forEach((m,p)=>{c[m]=parseFloat(s.metricValues[p]?.value||"0")}),u.push(c)});const d={},g={};f.totals&&f.totals.length>=2?D.forEach((s,n)=>{d[s]=parseFloat(f.totals[0]?.metricValues?.[n]?.value||"0"),g[s]=parseFloat(f.totals[1]?.metricValues?.[n]?.value||"0")}):f.totals&&f.totals.length===1&&D.forEach((s,n)=>{d[s]=parseFloat(f.totals[0]?.metricValues?.[n]?.value||"0")});const e={};D.forEach(s=>{const n=d[s]||0,i=g[s];i!==void 0&&i!==0?e[s]=(n-i)/i*100:e[s]=null});const a=new Map;for(const s of u)a.has(s.date)||a.set(s.date,s);const o=Array.from(a.values()).sort((s,n)=>s.date.localeCompare(n.date)),t=v&&f.totals&&f.totals.length>=2?o.slice(-Math.ceil(o.length/2)):o;return{rows:t,totals:d,previousTotals:g,changes:e,rowCount:t.length}}function C(f,v){const D=(f.metricHeaders||[]).map(l=>l.name),y=(f.rows||[]).map(l=>{const u={[v]:l.dimensionValues[0].value};return D.forEach((d,g)=>{u[d]=parseFloat(l.metricValues[g].value)}),u});return{rows:y,rowCount:f.rowCount||y.length}}function k(f,v){const D=(f.metricHeaders||[]).map(l=>l.name),y=(f.rows||[]).map(l=>{const u={};return v.forEach((d,g)=>{u[d]=l.dimensionValues[g]?.value||""}),D.forEach((d,g)=>{u[d]=parseFloat(l.metricValues[g].value)}),u});return{rows:y,rowCount:f.rowCount||y.length}}function U(f){const{decrypt:v}=f,D=r.createRouter();async function y(l){const{supabase:u,instanceId:d}=l.context.module,{data:g,error:e}=await u.from("project_modules").select("config").eq("id",d).single();if(e||!g?.config)throw r.createError({statusCode:500,statusMessage:"Failed to load module config."});const a=g.config,o=a.githubIntegration,t=a.githubRepo,s=a.githubOwner;if(!o||!t||!s)throw r.createError({statusCode:400,statusMessage:"No GitHub integration configured for this module."});const{data:n,error:i}=await u.from("integrations").select("config").eq("id",o).single();let c=n?.config;if(i||!c){const{data:p,error:w}=await u.from("agency_integrations").select("config").eq("id",o).single();if(w||!p?.config)throw r.createError({statusCode:500,statusMessage:"Failed to load Github credentials."});c=p.config}return{token:v(c.token),repo:t,owner:s}}return D.post("/github/deploy",r.defineEventHandler(async l=>{try{const{token:u,repo:d,owner:g}=await y(l);await fetch(`https://api.github.com/repos/${g}/${d}/dispatches`,{method:"POST",headers:{Authorization:`Bearer ${u}`,Accept:"application/vnd.github+json"},body:JSON.stringify({event_type:"deploy-site"})})}catch(u){throw console.error("Error triggering GitHub deployment:",u),r.createError({statusCode:500,statusMessage:"Failed to trigger deployment."})}})),D.handler}exports.appointments=M;exports.contentManager=U;exports.googleAnalytics=N;exports.products=b;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("h3");require("vue");function b(w){const{initFirebase:A,normalizeTimestamps:D}=w,p=n.createRouter();async function m(l){const{supabase:c,instanceId:u}=l.context.module,{data:e,error:o}=await c.from("project_modules").select("config").eq("id",u).single();if(o||!e?.config)throw n.createError({statusCode:500,statusMessage:"Failed to load module config."});const s=e.config,t=s.project,a=s.productCollection||"products";if(!t)throw n.createError({statusCode:400,statusMessage:"Products module has no Firebase integration configured."});return{firebase:await A(l,t),collection:a}}return p.get("/products",n.defineEventHandler(async l=>{try{const{firebase:c,collection:u}=await m(l);return(await c.firestore().collection(u).get()).docs.map(o=>D({id:o.id,...o.data()}))}catch(c){throw console.error("Products handler — list error:",c),n.createError({statusCode:c.statusCode||500,statusMessage:c.statusMessage||"Failed to list products"})}})),p.get("/products/:productId",n.defineEventHandler(async l=>{const c=n.getRouterParam(l,"productId");if(!c)throw n.createError({statusCode:400,statusMessage:"Product ID is required."});try{const{firebase:u,collection:e}=await m(l),o=await u.firestore().collection(e).doc(c).get();if(!o.exists)throw n.createError({statusCode:404,statusMessage:"Product not found."});return D({id:o.id,...o.data()})}catch(u){throw console.error("Products handler — get error:",u),n.createError({statusCode:u.statusCode||500,statusMessage:u.statusMessage||"Failed to get product"})}})),p.get("/empty-stock",n.defineEventHandler(async l=>{const u=n.getQuery(l).category;try{const{firebase:e,collection:o}=await m(l);let s=e.firestore().collection(o).where("stock","==",0);u&&(s=s.where("collections","array-contains",u));const a=(await s.get()).docs.map(r=>D({id:r.id,...r.data()}));return{count:a.length,products:a.map(r=>({id:r.id,title:r.title,slug:r.slug,stock:r.stock,price:r.price,currency:r.currency,status:r.status}))}}catch(e){throw console.error("Products handler — empty-stock error:",e),n.createError({statusCode:e.statusCode||500,statusMessage:e.statusMessage||"Failed to query empty stock"})}})),p.handler}function T(w){const{initFirebase:A,normalizeTimestamps:D}=w,p=n.createRouter();async function m(c){const{supabase:u,instanceId:e}=c.context.module,{data:o,error:s}=await u.from("project_modules").select("config").eq("id",e).single();if(s||!o?.config)throw n.createError({statusCode:500,statusMessage:"Failed to load module config."});const t=o.config,a=t.project,r=t.reservationsCollection||"bookings_orders",i=t.agendaCollection||"agendas";if(!a)throw n.createError({statusCode:400,statusMessage:"Appointments module has no Firebase integration configured."});return{firebase:await A(c,a),reservationsCollection:r,agendaCollection:i}}function l(c){return(c.reservations||[]).map(e=>({orderId:c.id,reservationId:e.id,customerInfo:c.customerInfo,date:e.date,startTime:e.timeslot?.startTime,endTime:e.timeslot?.endTime,spots:e.spots,status:c.status,reservationStatus:e.status,resourceId:e.resourceId,reservationPrice:e.totalPrice,reservationBasePrice:e.basePrice,reservationAddOnsPrice:e.addOnsPrice,pricingOption:e.pricingOption,amountDue:c.amountDue,amountPaid:c.amountPaid,createdAt:c.createdAt,metadata:c.metadata||{},reservationMetadata:e.metadata||{}}))}return p.get("/agendas",n.defineEventHandler(async c=>{try{const{firebase:u,agendaCollection:e}=await m(c),s=(await u.firestore().collection(e).get()).docs.map(t=>{const a=t.data();return{id:t.id,serviceName:a.serviceName||"",type:a.type||"regular"}});return{count:s.length,agendas:s}}catch(u){throw console.error("Appointments handler — list agendas error:",u),n.createError({statusCode:u.statusCode||500,statusMessage:u.statusMessage||"Failed to list agendas"})}})),p.get("/agendas/:agendaId/opening-hours",n.defineEventHandler(async c=>{const u=n.getRouterParam(c,"agendaId"),o=n.getQuery(c).date;if(!u)throw n.createError({statusCode:400,statusMessage:"Agenda ID is required."});if(!o)throw n.createError({statusCode:400,statusMessage:"Date is required (YYYY-MM-DD)."});try{const{firebase:s,agendaCollection:t}=await m(c),a=await s.firestore().collection(t).doc(u).get();if(!a.exists)throw n.createError({statusCode:404,statusMessage:"Agenda not found."});const r=a.data(),i=(r.resources||[]).filter(f=>f.isActive),d=r.exceptions||[],y=new Date(o+"T00:00:00").getDay(),h=i.map(f=>{const E=f.openingHours?.[y]||[],C=d.find(I=>{const P=o>=I.startDate&&o<=I.endDate,R=!I.resourceIds||I.resourceIds.length===0||I.resourceIds.includes(f.id);return P&&R});return C?{resourceId:f.id,resourceName:f.name,date:o,dayOfWeek:y,isClosed:C.isClosed,hours:C.isClosed?[]:(C.timeslots||[]).map(I=>({start:I.startTime,end:I.endTime})),isException:!0}:{resourceId:f.id,resourceName:f.name,date:o,dayOfWeek:y,isClosed:E.length===0,hours:E,isException:!1}});return{agendaId:u,serviceName:r.serviceName||"",date:o,resources:h}}catch(s){throw console.error("Appointments handler — opening hours error:",s),n.createError({statusCode:s.statusCode||500,statusMessage:s.statusMessage||"Failed to get opening hours"})}})),p.get("/appointments",n.defineEventHandler(async c=>{const u=n.getQuery(c),e=Math.min(Number(u.quantity)||20,100),o=u.status||"confirmed";try{const{firebase:s,reservationsCollection:t}=await m(c),r=(await s.firestore().collection(t).orderBy("createdAt","desc").where("status","==",o).limit(e).get()).docs.flatMap(i=>l(D({id:i.id,...i.data()})));return{count:r.length,appointments:r}}catch(s){throw console.error("Appointments handler — list error:",s),n.createError({statusCode:s.statusCode||500,statusMessage:s.statusMessage||"Failed to list appointments"})}})),p.get("/appointments/find",n.defineEventHandler(async c=>{const u=n.getQuery(c),e=(u.name||"").toLowerCase().trim(),o=(u.email||"").toLowerCase().trim(),s=u.date;try{const{firebase:t,reservationsCollection:a}=await m(c);let r=t.firestore().collection(a);o&&(r=r.where("customerInfo.email","==",o));let d=(await r.orderBy("createdAt","desc").limit(200).get()).docs.flatMap(g=>l(D({id:g.id,...g.data()})));return s&&(d=d.filter(g=>g.date===s)),e&&(d=d.filter(g=>{const y=(g.customerInfo?.firstName||"").toLowerCase(),h=(g.customerInfo?.lastName||"").toLowerCase();return y.includes(e)||h.includes(e)||`${y} ${h}`.includes(e)})),{count:d.length,appointments:d}}catch(t){throw console.error("Appointments handler — find error:",t),n.createError({statusCode:t.statusCode||500,statusMessage:t.statusMessage||"Failed to find appointments"})}})),p.get("/appointments/:appointmentId",n.defineEventHandler(async c=>{const u=n.getRouterParam(c,"appointmentId");if(!u)throw n.createError({statusCode:400,statusMessage:"Appointment ID is required."});try{const{firebase:e,reservationsCollection:o}=await m(c),s=await e.firestore().collection(o).doc(u).get();if(!s.exists)throw n.createError({statusCode:404,statusMessage:"Appointment not found."});const t=D({id:s.id,...s.data()});return{...t,reservations:l(t)}}catch(e){throw console.error("Appointments handler — get error:",e),n.createError({statusCode:e.statusCode||500,statusMessage:e.statusMessage||"Failed to get appointment"})}})),p.handler}const S="https://analyticsdata.googleapis.com/v1beta",N=["https://www.googleapis.com/auth/analytics.readonly","https://www.googleapis.com/auth/webmasters.readonly"],k="https://searchconsole.googleapis.com/webmasters/v3";function H(w){const{decrypt:A,getGoogleAccessToken:D}=w,p=n.createRouter();async function m(e){const{supabase:o,instanceId:s}=e.context.module,{data:t,error:a}=await o.from("project_modules").select("config").eq("id",s).single();if(a||!t?.config)throw n.createError({statusCode:500,statusMessage:"Failed to load module config."});const r=t.config,i=r.propertyId,d=r.serviceAccount,g=r.siteUrl||"";if(!d)throw n.createError({statusCode:400,statusMessage:"No Google Service Account configured for this module."});if(!i)throw n.createError({statusCode:400,statusMessage:"No GA4 Property ID configured for this module."});const{data:y,error:h}=await o.from("integrations").select("config").eq("id",d).single();let f=y?.config;if(h||!f){const{data:R,error:q}=await o.from("agency_integrations").select("config").eq("id",d).single();if(q||!R?.config)throw n.createError({statusCode:500,statusMessage:"Failed to load Google Service Account credentials."});f=R.config}const E=A(f.clientEmail),C=A(f.privateKey),I=A(f.projectId);return{accessToken:await D({clientEmail:E,privateKey:C,projectId:I},N),propertyId:i,siteUrl:g}}async function l(e,o,s){const t=await fetch(`${S}/properties/${o}:runReport`,{method:"POST",headers:{Authorization:`Bearer ${e}`,"Content-Type":"application/json"},body:JSON.stringify(s)});if(!t.ok){const a=await t.json().catch(()=>({}));throw console.error("GA4 runReport failed:",a),n.createError({statusCode:t.status,statusMessage:a?.error?.message||"GA4 API request failed"})}return t.json()}p.get("/report",n.defineEventHandler(async e=>{const{accessToken:o,propertyId:s}=await m(e),t=n.getQuery(e),a=t.startDate||"30daysAgo",r=t.endDate||"today",i=a.match(/^(\d+)daysAgo$/),d=i?parseInt(i[1],10):30,g=`${d*2}daysAgo`,y=`${d+1}daysAgo`,h=[{name:"sessions"},{name:"totalUsers"},{name:"screenPageViews"},{name:"bounceRate"},{name:"averageSessionDuration"},{name:"newUsers"},{name:"engagementRate"},{name:"sessionsPerUser"},{name:"screenPageViewsPerSession"}];let f,E=!0;try{f=await l(o,s,{dateRanges:[{startDate:a,endDate:r,name:"current"},{startDate:g,endDate:y,name:"previous"}],dimensions:[{name:"date"}],metrics:h,metricAggregations:["TOTAL"],orderBys:[{dimension:{dimensionName:"date"}}]})}catch{E=!1,f=await l(o,s,{dateRanges:[{startDate:a,endDate:r}],dimensions:[{name:"date"}],metrics:h,metricAggregations:["TOTAL"],orderBys:[{dimension:{dimensionName:"date"}}]})}return U(f,E)})),p.get("/realtime",n.defineEventHandler(async e=>{const{accessToken:o,propertyId:s}=await m(e),t=await fetch(`${S}/properties/${s}:runRealtimeReport`,{method:"POST",headers:{Authorization:`Bearer ${o}`,"Content-Type":"application/json"},body:JSON.stringify({dimensions:[{name:"unifiedScreenName"}],metrics:[{name:"activeUsers"}],orderBys:[{metric:{metricName:"activeUsers"},desc:!0}],limit:5})});if(!t.ok){const d=await t.json().catch(()=>({}));throw n.createError({statusCode:t.status,statusMessage:d?.error?.message||"Realtime API failed"})}const a=await t.json(),r=(a?.rows||[]).reduce((d,g)=>d+parseInt(g.metricValues?.[0]?.value||"0",10),0),i=(a?.rows||[]).map(d=>({page:d.dimensionValues?.[0]?.value||"(not set)",activeUsers:parseInt(d.metricValues?.[0]?.value||"0",10)}));return{activeUsers:r,activePages:i}})),p.get("/top-pages",n.defineEventHandler(async e=>{const{accessToken:o,propertyId:s}=await m(e),t=n.getQuery(e),a=t.startDate||"30daysAgo",r=t.endDate||"today",i=parseInt(t.limit||"10",10),d=await l(o,s,{dateRanges:[{startDate:a,endDate:r}],dimensions:[{name:"pagePath"}],metrics:[{name:"screenPageViews"},{name:"totalUsers"},{name:"averageSessionDuration"}],orderBys:[{metric:{metricName:"screenPageViews"},desc:!0}],limit:i*2}),g=v(d,"pagePath"),y=new Map;for(const f of g.rows){const E=f.pagePath.toLowerCase().replace(/\/+$/,""),C=y.get(E);if(C){C.screenPageViews+=f.screenPageViews||0,C.totalUsers+=f.totalUsers||0;const I=C.screenPageViews;I>0&&(C.averageSessionDuration=(C.averageSessionDuration*(I-(f.screenPageViews||0))+(f.averageSessionDuration||0)*(f.screenPageViews||0))/I)}else y.set(E,{...f})}return{rows:[...y.values()].sort((f,E)=>(E.screenPageViews||0)-(f.screenPageViews||0)).slice(0,i),rowCount:g.rowCount}})),p.get("/top-sources",n.defineEventHandler(async e=>{const{accessToken:o,propertyId:s}=await m(e),t=n.getQuery(e),a=t.startDate||"30daysAgo",r=t.endDate||"today",i=await l(o,s,{dateRanges:[{startDate:a,endDate:r}],dimensions:[{name:"sessionSource"}],metrics:[{name:"sessions"},{name:"totalUsers"}],orderBys:[{metric:{metricName:"sessions"},desc:!0}],limit:10});return v(i,"sessionSource")})),p.get("/devices",n.defineEventHandler(async e=>{const{accessToken:o,propertyId:s}=await m(e),t=n.getQuery(e),a=t.startDate||"30daysAgo",r=t.endDate||"today",i=await l(o,s,{dateRanges:[{startDate:a,endDate:r}],dimensions:[{name:"deviceCategory"}],metrics:[{name:"sessions"},{name:"totalUsers"}],orderBys:[{metric:{metricName:"sessions"},desc:!0}]});return v(i,"deviceCategory")})),p.get("/countries",n.defineEventHandler(async e=>{const{accessToken:o,propertyId:s}=await m(e),t=n.getQuery(e),a=t.startDate||"30daysAgo",r=t.endDate||"today",i=await l(o,s,{dateRanges:[{startDate:a,endDate:r}],dimensions:[{name:"country"}],metrics:[{name:"sessions"},{name:"totalUsers"}],orderBys:[{metric:{metricName:"sessions"},desc:!0}],limit:10});return v(i,"country")})),p.get("/acquisition/channels",n.defineEventHandler(async e=>{const{accessToken:o,propertyId:s}=await m(e),t=n.getQuery(e),a=t.startDate||"30daysAgo",r=t.endDate||"today",i=await l(o,s,{dateRanges:[{startDate:a,endDate:r}],dimensions:[{name:"sessionDefaultChannelGroup"}],metrics:[{name:"sessions"},{name:"totalUsers"},{name:"newUsers"},{name:"engagementRate"},{name:"averageSessionDuration"},{name:"screenPageViewsPerSession"},{name:"conversions"}],orderBys:[{metric:{metricName:"sessions"},desc:!0}],limit:15});return v(i,"sessionDefaultChannelGroup")})),p.get("/acquisition/source-medium",n.defineEventHandler(async e=>{const{accessToken:o,propertyId:s}=await m(e),t=n.getQuery(e),a=t.startDate||"30daysAgo",r=t.endDate||"today",i=await l(o,s,{dateRanges:[{startDate:a,endDate:r}],dimensions:[{name:"sessionSourceMedium"}],metrics:[{name:"sessions"},{name:"totalUsers"},{name:"newUsers"},{name:"bounceRate"},{name:"averageSessionDuration"},{name:"conversions"}],orderBys:[{metric:{metricName:"sessions"},desc:!0}],limit:20});return v(i,"sessionSourceMedium")})),p.get("/acquisition/referrals",n.defineEventHandler(async e=>{const{accessToken:o,propertyId:s}=await m(e),t=n.getQuery(e),a=t.startDate||"30daysAgo",r=t.endDate||"today",i=await l(o,s,{dateRanges:[{startDate:a,endDate:r}],dimensions:[{name:"sessionSource"}],dimensionFilter:{filter:{fieldName:"sessionMedium",stringFilter:{value:"referral"}}},metrics:[{name:"sessions"},{name:"totalUsers"},{name:"engagementRate"},{name:"averageSessionDuration"}],orderBys:[{metric:{metricName:"sessions"},desc:!0}],limit:20});return v(i,"sessionSource")})),p.get("/acquisition/campaigns",n.defineEventHandler(async e=>{const{accessToken:o,propertyId:s}=await m(e),t=n.getQuery(e),a=t.startDate||"30daysAgo",r=t.endDate||"today",i=await l(o,s,{dateRanges:[{startDate:a,endDate:r}],dimensions:[{name:"sessionCampaignName"}],dimensionFilter:{notExpression:{filter:{fieldName:"sessionCampaignName",stringFilter:{value:"(not set)"}}}},metrics:[{name:"sessions"},{name:"totalUsers"},{name:"conversions"},{name:"engagementRate"}],orderBys:[{metric:{metricName:"sessions"},desc:!0}],limit:20});return v(i,"sessionCampaignName")})),p.get("/content/all-pages",n.defineEventHandler(async e=>{const{accessToken:o,propertyId:s}=await m(e),t=n.getQuery(e),a=t.startDate||"30daysAgo",r=t.endDate||"today",i=parseInt(t.limit||"50",10),d=await l(o,s,{dateRanges:[{startDate:a,endDate:r}],dimensions:[{name:"pagePath"}],metrics:[{name:"screenPageViews"},{name:"totalUsers"},{name:"averageSessionDuration"},{name:"bounceRate"},{name:"engagementRate"},{name:"sessions"},{name:"userEngagementDuration"}],orderBys:[{metric:{metricName:"screenPageViews"},desc:!0}],limit:i});return v(d,"pagePath")})),p.get("/content/landing-pages",n.defineEventHandler(async e=>{const{accessToken:o,propertyId:s}=await m(e),t=n.getQuery(e),a=t.startDate||"30daysAgo",r=t.endDate||"today",i=await l(o,s,{dateRanges:[{startDate:a,endDate:r}],dimensions:[{name:"landingPagePlusQueryString"}],metrics:[{name:"sessions"},{name:"totalUsers"},{name:"bounceRate"},{name:"averageSessionDuration"},{name:"screenPageViews"},{name:"engagementRate"}],orderBys:[{metric:{metricName:"sessions"},desc:!0}],limit:30});return v(i,"landingPagePlusQueryString")})),p.get("/content/exit-pages",n.defineEventHandler(async e=>{const{accessToken:o,propertyId:s}=await m(e),t=n.getQuery(e),a=t.startDate||"30daysAgo",r=t.endDate||"today",i=await l(o,s,{dateRanges:[{startDate:a,endDate:r}],dimensions:[{name:"pagePath"}],metrics:[{name:"sessions"},{name:"screenPageViews"},{name:"totalUsers"},{name:"bounceRate"}],orderBys:[{metric:{metricName:"screenPageViews"},desc:!0}],limit:20}),d=v(i,"pagePath");return d.rows=d.rows.map(g=>({...g,exitRate:g.bounceRate||0})),d})),p.get("/content/search-terms",n.defineEventHandler(async e=>{const{accessToken:o,propertyId:s,siteUrl:t}=await m(e),a=n.getQuery(e),r=a.startDate||"30daysAgo",i=a.endDate||"today";if(t)try{const y=`${k}/sites/${encodeURIComponent(t)}/searchAnalytics/query`,h=await fetch(y,{method:"POST",headers:{Authorization:`Bearer ${o}`,"Content-Type":"application/json"},body:JSON.stringify({startDate:c(r),endDate:c(i),dimensions:["query"],rowLimit:30})});if(h.ok){const E=((await h.json()).rows||[]).map(C=>({query:C.keys[0],clicks:C.clicks,impressions:C.impressions,ctr:C.ctr,position:C.position}));if(E.length>0)return{rows:E,rowCount:E.length,source:"search_console"}}else{const f=await h.text().catch(()=>"");console.error(`[GA Module] Search Console API error (${h.status}):`,f)}}catch(y){console.error("[GA Module] Search Console request failed:",y?.message||y)}else console.log("[GA Module] No siteUrl configured, skipping Search Console");try{const y=await l(o,s,{dateRanges:[{startDate:r,endDate:i}],dimensions:[{name:"sessionGoogleAdsQuery"}],metrics:[{name:"sessions"},{name:"totalUsers"},{name:"engagementRate"}],dimensionFilter:{andGroup:{expressions:[{notExpression:{filter:{fieldName:"sessionGoogleAdsQuery",stringFilter:{value:"(not set)"}}}},{notExpression:{filter:{fieldName:"sessionGoogleAdsQuery",stringFilter:{value:"(not provided)"}}}}]}},orderBys:[{metric:{metricName:"sessions"},desc:!0}],limit:30}),h=v(y,"sessionGoogleAdsQuery");if(h.rows.length>0)return{...h,source:"google_ads"}}catch{}const d=await l(o,s,{dateRanges:[{startDate:r,endDate:i}],dimensions:[{name:"landingPagePlusQueryString"}],metrics:[{name:"sessions"},{name:"totalUsers"},{name:"engagementRate"}],dimensionFilter:{andGroup:{expressions:[{filter:{fieldName:"sessionMedium",stringFilter:{matchType:"EXACT",value:"organic"}}},{notExpression:{filter:{fieldName:"landingPagePlusQueryString",stringFilter:{value:"(not set)"}}}}]}},orderBys:[{metric:{metricName:"sessions"},desc:!0}],limit:30});return{...v(d,"landingPagePlusQueryString"),source:"organic_landing_pages"}})),p.get("/audience/overview",n.defineEventHandler(async e=>{const{accessToken:o,propertyId:s}=await m(e),t=n.getQuery(e),a=t.startDate||"30daysAgo",r=t.endDate||"today",i=await l(o,s,{dateRanges:[{startDate:a,endDate:r}],dimensions:[{name:"newVsReturning"}],metrics:[{name:"totalUsers"},{name:"sessions"},{name:"engagementRate"},{name:"averageSessionDuration"},{name:"screenPageViewsPerSession"}],metricAggregations:["TOTAL"]});return v(i,"newVsReturning")})),p.get("/audience/technology",n.defineEventHandler(async e=>{const{accessToken:o,propertyId:s}=await m(e),t=n.getQuery(e),a=t.startDate||"30daysAgo",r=t.endDate||"today",i=t.dimension||"browser",g=["browser","operatingSystem","screenResolution"].includes(i)?i:"browser",y=await l(o,s,{dateRanges:[{startDate:a,endDate:r}],dimensions:[{name:g}],metrics:[{name:"totalUsers"},{name:"sessions"},{name:"engagementRate"}],orderBys:[{metric:{metricName:"totalUsers"},desc:!0}],limit:10});return v(y,g)})),p.get("/audience/languages",n.defineEventHandler(async e=>{const{accessToken:o,propertyId:s}=await m(e),t=n.getQuery(e),a=t.startDate||"30daysAgo",r=t.endDate||"today",i=await l(o,s,{dateRanges:[{startDate:a,endDate:r}],dimensions:[{name:"language"}],metrics:[{name:"totalUsers"},{name:"sessions"}],orderBys:[{metric:{metricName:"totalUsers"},desc:!0}],limit:15});return v(i,"language")})),p.get("/audience/hours",n.defineEventHandler(async e=>{const{accessToken:o,propertyId:s}=await m(e),t=n.getQuery(e),a=t.startDate||"30daysAgo",r=t.endDate||"today",i=await l(o,s,{dateRanges:[{startDate:a,endDate:r}],dimensions:[{name:"dayOfWeekName"},{name:"hour"}],metrics:[{name:"sessions"}],orderBys:[{dimension:{dimensionName:"dayOfWeekName"}},{dimension:{dimensionName:"hour"}}],limit:168});return M(i,["dayOfWeekName","hour"])})),p.get("/audience/cities",n.defineEventHandler(async e=>{const{accessToken:o,propertyId:s}=await m(e),t=n.getQuery(e),a=t.startDate||"30daysAgo",r=t.endDate||"today",i=await l(o,s,{dateRanges:[{startDate:a,endDate:r}],dimensions:[{name:"city"},{name:"country"}],metrics:[{name:"totalUsers"},{name:"sessions"}],dimensionFilter:{notExpression:{filter:{fieldName:"city",stringFilter:{value:"(not set)"}}}},orderBys:[{metric:{metricName:"totalUsers"},desc:!0}],limit:20});return M(i,["city","country"])}));function c(e){const o=e.match(/^(\d+)daysAgo$/);if(o){const s=new Date;return s.setDate(s.getDate()-parseInt(o[1],10)),s.toISOString().slice(0,10)}if(e==="today")return new Date().toISOString().slice(0,10);if(e==="yesterday"){const s=new Date;return s.setDate(s.getDate()-1),s.toISOString().slice(0,10)}return e}async function u(e,o,s){const t=`${k}/sites/${encodeURIComponent(o)}/searchAnalytics/query`,a=await fetch(t,{method:"POST",headers:{Authorization:`Bearer ${e}`,"Content-Type":"application/json"},body:JSON.stringify(s)});if(!a.ok){const r=await a.json().catch(()=>({}));throw n.createError({statusCode:a.status,statusMessage:r?.error?.message||"Search Console API request failed"})}return a.json()}return p.get("/seo/keywords",n.defineEventHandler(async e=>{const{accessToken:o,siteUrl:s}=await m(e);if(!s)throw n.createError({statusCode:400,statusMessage:"Search Console Site URL is not configured. Add it in module settings."});const t=n.getQuery(e),a=c(t.startDate||"30daysAgo"),r=c(t.endDate||"today"),i=Math.min(parseInt(t.limit)||50,100),d=await u(o,s,{startDate:a,endDate:r,dimensions:["query"],rowLimit:i});return{rows:(d.rows||[]).map(g=>({query:g.keys[0],clicks:g.clicks,impressions:g.impressions,ctr:g.ctr,position:g.position})),rowCount:d.rows?.length||0}})),p.get("/seo/pages",n.defineEventHandler(async e=>{const{accessToken:o,siteUrl:s}=await m(e);if(!s)throw n.createError({statusCode:400,statusMessage:"Search Console Site URL is not configured."});const t=n.getQuery(e),a=c(t.startDate||"30daysAgo"),r=c(t.endDate||"today"),i=Math.min(parseInt(t.limit)||50,100),d=await u(o,s,{startDate:a,endDate:r,dimensions:["page"],rowLimit:i});return{rows:(d.rows||[]).map(g=>({page:g.keys[0],clicks:g.clicks,impressions:g.impressions,ctr:g.ctr,position:g.position})),rowCount:d.rows?.length||0}})),p.get("/seo/trends",n.defineEventHandler(async e=>{const{accessToken:o,siteUrl:s}=await m(e);if(!s)throw n.createError({statusCode:400,statusMessage:"Search Console Site URL is not configured."});const t=n.getQuery(e),a=c(t.startDate||"30daysAgo"),r=c(t.endDate||"today"),d=((await u(o,s,{startDate:a,endDate:r,dimensions:["date"],rowLimit:500})).rows||[]).map(y=>({date:y.keys[0],clicks:y.clicks,impressions:y.impressions,ctr:y.ctr,position:y.position})).sort((y,h)=>y.date.localeCompare(h.date)),g=d.reduce((y,h)=>({clicks:y.clicks+h.clicks,impressions:y.impressions+h.impressions}),{clicks:0,impressions:0});return g.ctr=g.impressions>0?g.clicks/g.impressions:0,g.avgPosition=d.length>0?d.reduce((y,h)=>y+h.position,0)/d.length:0,{rows:d,totals:g,rowCount:d.length}})),p.get("/seo/query-pages",n.defineEventHandler(async e=>{const{accessToken:o,siteUrl:s}=await m(e);if(!s)throw n.createError({statusCode:400,statusMessage:"Search Console Site URL is not configured."});const t=n.getQuery(e),a=c(t.startDate||"30daysAgo"),r=c(t.endDate||"today"),i=await u(o,s,{startDate:a,endDate:r,dimensions:["query","page"],rowLimit:100});return{rows:(i.rows||[]).map(d=>({query:d.keys[0],page:d.keys[1],clicks:d.clicks,impressions:d.impressions,ctr:d.ctr,position:d.position})),rowCount:i.rows?.length||0}})),p.handler}function U(w,A=!0){const D=(w.metricHeaders||[]).map(a=>a.name),m=(w.dimensionHeaders||[]).map(a=>a.name).indexOf("date"),l=[];(w.rows||[]).forEach(a=>{const r=m>=0?a.dimensionValues[m]?.value:a.dimensionValues[0]?.value;if(!r||r.length<8)return;const d={date:`${r.slice(0,4)}-${r.slice(4,6)}-${r.slice(6,8)}`};D.forEach((g,y)=>{d[g]=parseFloat(a.metricValues[y]?.value||"0")}),l.push(d)});const c={},u={};w.totals&&w.totals.length>=2?D.forEach((a,r)=>{c[a]=parseFloat(w.totals[0]?.metricValues?.[r]?.value||"0"),u[a]=parseFloat(w.totals[1]?.metricValues?.[r]?.value||"0")}):w.totals&&w.totals.length===1&&D.forEach((a,r)=>{c[a]=parseFloat(w.totals[0]?.metricValues?.[r]?.value||"0")});const e={};D.forEach(a=>{const r=c[a]||0,i=u[a];i!==void 0&&i!==0?e[a]=(r-i)/i*100:e[a]=null});const o=new Map;for(const a of l)o.has(a.date)||o.set(a.date,a);const s=Array.from(o.values()).sort((a,r)=>a.date.localeCompare(r.date)),t=A&&w.totals&&w.totals.length>=2?s.slice(-Math.ceil(s.length/2)):s;return{rows:t,totals:c,previousTotals:u,changes:e,rowCount:t.length}}function v(w,A){const D=(w.metricHeaders||[]).map(m=>m.name),p=(w.rows||[]).map(m=>{const l={[A]:m.dimensionValues[0].value};return D.forEach((c,u)=>{l[c]=parseFloat(m.metricValues[u].value)}),l});return{rows:p,rowCount:w.rowCount||p.length}}function M(w,A){const D=(w.metricHeaders||[]).map(m=>m.name),p=(w.rows||[]).map(m=>{const l={};return A.forEach((c,u)=>{l[c]=m.dimensionValues[u]?.value||""}),D.forEach((c,u)=>{l[c]=parseFloat(m.metricValues[u].value)}),l});return{rows:p,rowCount:w.rowCount||p.length}}function F(w){const{decrypt:A}=w,D=n.createRouter();async function p(m){const{supabase:l,instanceId:c}=m.context.module,{data:u,error:e}=await l.from("project_modules").select("config").eq("id",c).single();if(e||!u?.config)throw n.createError({statusCode:500,statusMessage:"Failed to load module config."});const o=u.config,s=o.githubIntegration,t=o.githubRepo,a=o.githubOwner;if(!s||!t||!a)throw n.createError({statusCode:400,statusMessage:"No GitHub integration configured for this module."});const{data:r,error:i}=await l.from("integrations").select("config").eq("id",s).single();let d=r?.config;if(i||!d){const{data:y,error:h}=await l.from("agency_integrations").select("config").eq("id",s).single();if(h||!y?.config)throw n.createError({statusCode:500,statusMessage:"Failed to load Github credentials."});d=y.config}return{token:A(d.token),repo:t,owner:a}}return D.post("/github/deploy",n.defineEventHandler(async m=>{try{const{token:l,repo:c,owner:u}=await p(m);await fetch(`https://api.github.com/repos/${u}/${c}/dispatches`,{method:"POST",headers:{Authorization:`Bearer ${l}`,Accept:"application/vnd.github+json"},body:JSON.stringify({event_type:"deploy-site"})})}catch(l){throw console.error("Error triggering GitHub deployment:",l),n.createError({statusCode:500,statusMessage:"Failed to trigger deployment."})}})),D.handler}exports.appointments=T;exports.contentManager=F;exports.googleAnalytics=H;exports.products=b;
|