"use strict";(globalThis.webpackChunkbooktics=globalThis.webpackChunkbooktics||[]).push([[7794],{87794:(e,t,o)=>{o.r(t),o.d(t,{default:()=>U});var a=o(51609),r=o(47143),n=o(86087),l=o(47767),i=o(48876),s=o(40309),c=o(22564),d=o(74353),m=o.n(d),b=o(11534),u=o(27723);const p=[{value:"current_week",label:(0,u.__)("Current Week","booktics")},{value:"last_week",label:(0,u.__)("Last Week","booktics")},{value:"current_month",label:(0,u.__)("Current Month","booktics")},{value:"last_month",label:(0,u.__)("Last Month","booktics")},{value:"last_three_months",label:(0,u.__)("Last 3 Month","booktics")}],g=e=>{const t=m()();let o,a;switch(e){case"current_week":o=t.startOf("week").add(1,"day"),a=o.add(6,"day");break;case"last_week":o=t.startOf("week").add(1,"day").subtract(7,"day"),a=o.add(6,"day");break;case"current_month":default:o=t.startOf("month"),a=t.endOf("month");break;case"last_month":const e=t.subtract(1,"month");o=e.startOf("month"),a=e.endOf("month");break;case"last_three_months":o=t.subtract(3,"month").startOf("month"),a=t.subtract(1,"month").endOf("month")}return{start_date:o.format("YYYY-MM-DD"),end_date:a.format("YYYY-MM-DD")}},h=(e,t,o,a,r)=>({label:e,data:t,borderColor:o,pointBackgroundColor:o,pointBorderColor:"#fff",pointBorderWidth:2,pointRadius:6,tension:.4,fill:!0,backgroundColor:e=>{const{ctx:t,chartArea:o}=e.chart;if(o)return((e,t,o,a)=>{const r=e.createLinearGradient(0,t.top,0,t.bottom);return r.addColorStop(0,o),r.addColorStop(1,a),r})(t,o,a,r)}}),k={total_bookings:(0,u.__)("Total Bookings","booktics"),total_revenue:(0,u.__)("Total Revenue","booktics"),total_customers:(0,u.__)("Total Customers","booktics")},_={total_bookings:(0,u.__)("Total number of bookings that were successfully completed during the selected time period.","booktics"),total_customers:(0,u.__)("Total income generated from successfully completed and paid bookings during the selected time period.","booktics"),total_revenue:(0,u.__)("Revenue earned from bookings during the selected time.","booktics")},f=()=>{const{setDashboardState:e}=(0,r.useDispatch)(s.dashboard),{topCards:t,booking_reports:o}=(0,r.useSelect)(e=>e(s.dashboard).getDashboardState()),a=async(t="current_month")=>{let a={...o};try{e({booking_reports:{...a,loading:!0}});const o={booking_reports:{...g(t),filter_option:t}},r=await b.A.dashboard.getDashboardReports(o);if(r.success){const{booking_reports:e}=r?.data||{},o=Object.keys(e),n=o.map(t=>e[t].completed),l=o.map(t=>e[t].cancel);a={labels:o,completedData:n,canceledData:l,filteredKey:t}}}catch(e){console.error(e)}finally{e({booking_reports:{...a,loading:!1}})}},n=async()=>{const o="current_month",a=g(o),r={filter_option:o,...a},n=["total_bookings","total_revenue","total_customers"],l=n.reduce((e,t)=>(e[t]=r,e),{});let i={...t};try{i=n.reduce((e,t)=>(e[t]={...i?.[t],loading:!0},e),{}),e({topCards:i});const t=await b.A.dashboard.getDashboardReports(l);t.success&&(i=n.reduce((e,a)=>(e[a]={...i?.[a],filteredKey:o,...t.data?.[a]},e),{}))}catch(e){console.error("Failed to fetch dashboard reports:",e)}finally{i=n.reduce((e,t)=>(e[t]={...i?.[t],loading:!1},e),{}),e({topCards:i})}},l=async()=>{try{const t=m()().format("YYYY-MM-DD"),o=await b.A.appointment.getAppointments({date_from:t,status:"approved"});o.success&&e({upcomingBookings:o?.data?.items})}catch(t){console.error(t),e({upcomingBookings:[]})}};return{fetchSingleCardData:async(o,a="current_month")=>{let r={...t};const n={[o]:{...g(a),filter_option:a}};try{r={...r,[o]:{...r?.[o],loading:!0}},e({topCards:r});const t=await b.A.dashboard.getDashboardReports(n);return t.success&&(r={...r,[o]:{...r?.[o],filteredKey:a,...t.data?.[o]}}),t}catch(e){throw console.error(`Error fetching ${o}:`,e),e}finally{r={...r,[o]:{...r?.[o],loading:!1}},e({topCards:r})}},getBookingReport:a,loadBookingData:async()=>{try{await Promise.all([n(),a(),l()])}catch(e){console.error("Error loading booking data:",e)}}}};var v=o(56580);const w=({token:e,data:t={}})=>{const{loading:o,filteredKey:r="current_month"}=t,{fetchSingleCardData:n,getBookingReport:l}=f();return(0,a.createElement)(c.SelectInput,{className:"bkt-overview-filter",defaultValue:"current_month",value:r,onChange:t=>{"booking_report"===e?l(t):n(e,t)},options:p,disabled:o})};var E=o(59e3);const x=(0,E.A)(c.Flex)`
    .ant-select-single {
        height: 36px;

        svg path {
            stroke: ${({theme:e})=>e.colors.text};
        }
    }

    .ant-select-selection-item {
        font-weight: 600;
    }

    .bkt-overview-report-chart {
        height: 500px;
    }

    .bkt-upcoming-booking-button {
        font-weight: 700;
        height: 36px;
        border-width: 1.3px;
    }

    .bkt-overview-filter {
        width: 150px;
    }
`,y=(0,E.A)(c.Card)`
    .ant-card-body {
        height: 170px;
    }

    .bkt-overview-card-data {
        font-weight: 700;
        font-size: 50px;
    }

    .ant-select-single {
        height: 36px;

        svg path {
            stroke: ${({theme:e})=>e.colors.text};
        }
    }

    .ant-select-selection-item {
        font-weight: 600;
    }

    .bkt-overview-info {
        position: relative;
    }
`,C=(0,E.A)(c.Card)`
    .ant-card-body {
        height: 600px;
    }

    .bkt-upcoming-booking-lists {
        height: 450px;
        overflow-y: auto;

        /* Firefox */
        scrollbar-width: thin;
        scrollbar-color: #bbb transparent;

        /* WebKit (Chrome, Edge, Safari) */
        &::-webkit-scrollbar {
            width: 6px;
        }

        &::-webkit-scrollbar-track {
            background: transparent;
        }

        &::-webkit-scrollbar-thumb {
            background-color: #bbb;
            border-radius: 4px;
        }

        &::-webkit-scrollbar-thumb:hover {
            background-color: #999;
        }

        .ant-list-item {
            column-gap: 80px;
            row-gap: 10px;
            font-weight: 500;
            font-size: 16px;

            .ant-list-item-meta {
                min-width: 160px;
            }
        }
        .bkt-appointment-title {
            width: 100%;
        }
    }
`,D=(0,E.A)(c.Space)`
    position: absolute;
    top: 12px;
    font-size: 18px;
    font-weight: 700;
    color: ${({theme:e,isPositive:t})=>t?e.colors.primary:"#E42D23"};
`,{CaretDownOutlined:S,CaretUpOutlined:F}=window?.booktics?.libraryIcons||{},O=({data:e={}})=>{if(!e?.trend||"neutral"===e?.trend)return;const t="positive"===e?.trend;return(0,a.createElement)(D,{isPositive:t,size:0},e?.percentage_changed,"%",t?(0,a.createElement)(F,null):(0,a.createElement)(S,null))},{QuestionCircleFilled:A}=window?.booktics?.libraryIcons||{},B=()=>{const{settingsData:e,dashboardData:t}=(0,r.useSelect)(e=>({settingsData:e(s.settings).getSettingsState(),dashboardData:e(s.dashboard).getDashboardState()})),{isAdmin:o}=(0,v.useUserRole)(),l=t?.topCards||{},i=(0,n.useMemo)(()=>e=>e.split("_").map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(" "),[]),d=(0,n.useMemo)(()=>{if(!l)return{};if(!o){const e=["total_bookings","total_revenue"];return Object.fromEntries(Object.entries(l).filter(([t])=>e.includes(t)))}return l},[l,o]),m=(0,n.useCallback)(e=>_[e]);return(0,a.createElement)(c.Row,{gutter:[20,20]},Object.entries(d).map(([t,o],r,n)=>{var l,s;return(0,a.createElement)(c.Col,{xs:24,md:12,xl:2===n.length?12:8,key:t},(0,a.createElement)(y,{loading:o?.loading},(0,a.createElement)(c.Flex,{vertical:!0,justify:"space-between",className:"bkt-h-100"},(0,a.createElement)(c.Flex,{justify:"space-between",gap:"small"},(0,a.createElement)(c.Flex,{align:"center",gap:6},(0,a.createElement)(c.Title,{level:4,text:null!==(l=k[t])&&void 0!==l?l:i(t)}),(0,a.createElement)(c.Tooltip,{title:m(t)},(0,a.createElement)(A,null))),(0,a.createElement)(w,{token:t,data:o})),(0,a.createElement)(c.Space,{className:"bkt-overview-info",size:"small"},(0,a.createElement)(c.Title,{className:"bkt-overview-card-data",level:3,text:"total_revenue"===t?(0,a.createElement)(c.Pricing,{settings:e,price:o?.total}):null!==(s=o?.total)&&void 0!==s?s:0}),(0,a.createElement)(O,{data:o})))))}))};var N=o(70106),T=o(44731);N.t1.register(N.No,N.PP,N.kc,N.FN,N.dN,N.m_,N.s$);const R={responsive:!0,maintainAspectRatio:!1,plugins:{legend:{position:"top",labels:{usePointStyle:!0,padding:20}}},scales:{x:{grid:{display:!1}},y:{min:0,grid:{color:"rgba(0,0,0,0.05)"}}}},M=()=>{const{booking_reports:e}=(0,r.useSelect)(e=>e(s.dashboard).getDashboardState()),{labels:t,completedData:o,canceledData:n,loading:l}=e;if(!n||!o)return;const i={labels:t,datasets:[h("Completed",o,"#009959","rgba(229, 240, 255, 0.5)","rgba(229, 240, 255, 0)"),h("Canceled",n,"#FF8694","rgba(252, 205, 210, 0.5)","rgba(252, 205, 210, 0)")]};return(0,a.createElement)(c.Spin,{spinning:l},(0,a.createElement)("div",{className:"bkt-overview-report-chart"},(0,a.createElement)(T.N1,{data:i,options:R})))},{QuestionCircleFilled:Y}=window?.booktics?.libraryIcons,P=()=>{const{booking_reports:e}=(0,r.useSelect)(e=>e(s.dashboard).getDashboardState());return(0,a.createElement)(C,null,(0,a.createElement)(c.Flex,{vertical:!0,gap:"small"},(0,a.createElement)(c.Flex,{justify:"space-between",gap:"small"},(0,a.createElement)(c.Flex,{gap:6,align:"center"},(0,a.createElement)(c.Title,{level:4,text:(0,u.__)("Booking report","booktics")}),(0,a.createElement)(c.Tooltip,{title:(0,u.__)("Chart of completed and canceled bookings over time.","booktics")},(0,a.createElement)(Y,null))),(0,a.createElement)(w,{token:"booking_report",data:e}))),(0,a.createElement)("div",{className:"bkt-overview-report-chart"},(0,a.createElement)(M,null)))};var I=o(22639);const{__}=wp.i18n,{List:j}=window?.booktics?.library||{},{ArrowRightOutlined:z}=window?.booktics?.libraryIcons||{},{QuestionCircleFilled:L}=window?.booktics?.libraryIcons,$=({loading:e})=>{const t=(0,l.Zp)(),{upcomingBookings:o}=(0,r.useSelect)(e=>e(s.dashboard).getDashboardState());return(0,a.createElement)(C,null,(0,a.createElement)(c.Flex,{vertical:!0,className:"bkt-h-100"},(0,a.createElement)(c.Flex,{gap:6},(0,a.createElement)(c.Title,{level:4,text:__("Upcoming Confirmed Bookings","booktics")}),(0,a.createElement)(c.Tooltip,{title:__("List of all upcoming confirmed bookings","booktics")},(0,a.createElement)(L,null))),(0,a.createElement)(c.Divider,null),(0,a.createElement)(j,{className:"bkt-upcoming-booking-lists",itemLayout:"horizontal",dataSource:o,loading:!o,renderItem:e=>(0,a.createElement)(j.Item,null,(0,a.createElement)(j.Item.Meta,{title:e?.date,description:(0,a.createElement)(c.Space,{size:3},__("@","booktics"),e?.start_time,__("to","booktics"),e?.end_time)}),(0,a.createElement)(c.Flex,{vertical:!0,className:"bkt-appointment-title",justify:"flex-start"},(0,a.createElement)(c.Text,{text:e?.service?.title}),(0,a.createElement)(c.Text,{text:`Simplified with ${e?.customer?.name||""} & ${e?.team_member?.display_name}`})))}),(0,a.createElement)(c.PrimaryOutlinedButton,{block:!0,onClick:()=>t(I.yq),icon:(0,a.createElement)(z,null),text:__("View All Bookings","booktics"),iconPosition:"end",size:"middle",className:"bkt-upcoming-booking-button"})))},{PlusOutlined:K}=window?.booktics?.libraryIcons||{},U=()=>{const{loadBookingData:e}=f(),{resetDashboard:t}=(0,r.useDispatch)(s.dashboard),o=(0,l.Zp)();return(0,n.useEffect)(()=>(e(),()=>t()),[]),(0,a.createElement)(a.Fragment,null,(0,a.createElement)(i.A,{title:(0,u.__)("Overview","booktics"),rightContent:(0,a.createElement)(c.PrimaryButton,{text:(0,u.__)("New Service","booktics"),icon:(0,a.createElement)(K,null),onClick:()=>o("/services/create")})}),(0,a.createElement)(c.ResponsiveContainer,null,(0,a.createElement)(x,{vertical:!0,gap:"middle",className:"bkt-overview-flex"},(0,a.createElement)(B,null),(0,a.createElement)(c.Row,{gutter:[20,20]},(0,a.createElement)(c.Col,{xs:24,md:24,xl:14,xxl:14},(0,a.createElement)(P,null)),(0,a.createElement)(c.Col,{xs:24,md:24,xl:10,xxl:10},(0,a.createElement)($,null))))))}}}]);