import{c as E,j as e}from"./index-D9pJRAs5.js";import{r as d}from"./vendor-D6aTFYy9.js";import{O as S,X as T,v as I,F as B,s as G,m as C,ae as U,aS as Y,ag as q,ah as K,ai as _,aj as H,aT as Q,av as W,b as X,n as z,aU as J,I as V}from"./ui-CtYVlq7P.js";const se=({isOpen:D,onClose:y})=>{const{orders:u,updateSSTPercentage:R,sstHistory:b,companyInfo:j}=E(),[i,M]=d.useState(6),[$,x]=d.useState(!1),[h,f]=d.useState(6),[w,F]=d.useState(new Date().toISOString().split("T")[0]),[k,v]=d.useState(""),[n,N]=d.useState("month"),[o,A]=d.useState("overview");if(!D)return null;const c=(()=>{const t={};return u.forEach(a=>{if(a.paymentStatus==="fully_paid"||a.paymentStatus==="deposit_paid"){const r=new Date(a.createdAt),l=`${r.getFullYear()}-${String(r.getMonth()+1).padStart(2,"0")}`,s=r.toLocaleString("default",{month:"short",year:"numeric"});t[l]||(t[l]={month:s,sst:0,sales:0});const O=a.totalPrice*(a.sstPercentage||6)/100;t[l].sst+=O,t[l].sales+=a.totalPrice}}),Object.values(t).sort((a,r)=>a.month.localeCompare(r.month))})(),m=c.reduce((t,a)=>t+a.sst,0),g=c.reduce((t,a)=>t+a.sales,0),p=u.filter(t=>(t.paymentStatus==="fully_paid"||t.paymentStatus==="deposit_paid")&&(t.sstPercentage||0)>0),P=()=>{R(h,new Date(w),k),M(h),x(!1),v("")},L=()=>{const t=`
SST REPORT - ${new Date().toLocaleDateString()}
${j.name}
${j.address}

Period: ${n==="month"?"Current Month":n==="quarter"?"Current Quarter":n==="year"?"Current Year":"All Time"}

Total Sales: RM ${g.toFixed(2)}
Total SST Collected: RM ${m.toFixed(2)}
Current SST Rate: ${i}%

Monthly Breakdown:
${c.map(s=>`${s.month}: Sales RM ${s.sales.toFixed(2)}, SST RM ${s.sst.toFixed(2)}`).join(`
`)}

Order Details:
${p.map(s=>`${s.invoiceNumber} (${new Date(s.createdAt).toLocaleDateString()}) - ${s.customerName}
   Amount: RM ${s.totalPrice.toFixed(2)}
   SST (${s.sstPercentage||6}%): RM ${(s.totalPrice*(s.sstPercentage||6)/100).toFixed(2)}`).join(`

`)}

SST Rate History:
${b.map(s=>`${new Date(s.effectiveDate).toLocaleDateString()}: ${s.percentage}%`).join(`
`)}

Generated on: ${new Date().toLocaleString()}
    `,a=new Blob([t],{type:"text/plain"}),r=URL.createObjectURL(a),l=document.createElement("a");l.href=r,l.download=`sst-report-${new Date().toISOString().split("T")[0]}.txt`,l.click(),URL.revokeObjectURL(r)};return e.jsx("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center p-4 z-50",onClick:y,children:e.jsxs("div",{className:"bg-white dark:bg-gray-800 rounded-2xl max-w-6xl w-full max-h-[95vh] overflow-y-auto shadow-2xl",onClick:t=>t.stopPropagation(),children:[e.jsx("div",{className:"bg-gradient-to-r from-blue-600 to-purple-600 text-white p-8 rounded-t-2xl",children:e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{className:"flex items-center space-x-3",children:[e.jsx("div",{className:"bg-white bg-opacity-20 p-3 rounded-xl",children:e.jsx(S,{className:"h-8 w-8"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold",children:"SST Management"}),e.jsx("p",{className:"text-blue-100",children:"Sales and Service Tax Administration"})]})]}),e.jsx("button",{onClick:y,className:"text-white hover:bg-white hover:bg-opacity-20 p-2 rounded-lg transition-colors",children:e.jsx(T,{className:"h-6 w-6"})})]})}),e.jsx("div",{className:"px-8 py-4 border-b border-gray-200 dark:border-gray-700",children:e.jsx("div",{className:"flex space-x-4",children:[{key:"overview",label:"Overview",icon:I},{key:"reports",label:"Reports",icon:B},{key:"settings",label:"Settings",icon:G}].map(t=>{const a=t.icon;return e.jsxs("button",{onClick:()=>A(t.key),className:`flex items-center space-x-2 px-4 py-2 rounded-lg font-medium transition-colors ${o===t.key?"bg-blue-600 text-white":"text-gray-600 hover:bg-gray-100 dark:text-gray-300 dark:hover:bg-gray-700"}`,children:[e.jsx(a,{className:"h-4 w-4"}),e.jsx("span",{children:t.label})]},t.key)})})}),e.jsxs("div",{className:"p-8",children:[o==="overview"&&e.jsxs("div",{className:"space-y-8",children:[e.jsx("div",{className:"bg-blue-50 dark:bg-gray-700 p-6 rounded-xl border border-blue-200 dark:border-blue-800",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center space-x-3",children:[e.jsx("div",{className:"bg-blue-600 text-white p-3 rounded-lg",children:e.jsx(S,{className:"h-6 w-6"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-bold text-gray-900 dark:text-white",children:"Current SST Rate"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400",children:"Applied to all new orders"})]})]}),e.jsxs("div",{className:"text-3xl font-bold text-blue-600 dark:text-blue-400",children:[i,"%"]})]})}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-6",children:[e.jsxs("div",{className:"bg-white dark:bg-gray-700 p-6 rounded-xl shadow-md border border-gray-200 dark:border-gray-600",children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-white mb-2",children:"Total SST Collected"}),e.jsxs("p",{className:"text-3xl font-bold text-green-600 dark:text-green-400",children:["RM ",m.toFixed(2)]}),e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400 mt-1",children:"All time"})]}),e.jsxs("div",{className:"bg-white dark:bg-gray-700 p-6 rounded-xl shadow-md border border-gray-200 dark:border-gray-600",children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-white mb-2",children:"Total Taxable Sales"}),e.jsxs("p",{className:"text-3xl font-bold text-blue-600 dark:text-blue-400",children:["RM ",g.toFixed(2)]}),e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400 mt-1",children:"All time"})]}),e.jsxs("div",{className:"bg-white dark:bg-gray-700 p-6 rounded-xl shadow-md border border-gray-200 dark:border-gray-600",children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-white mb-2",children:"Orders with SST"}),e.jsx("p",{className:"text-3xl font-bold text-purple-600 dark:text-purple-400",children:p.length}),e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400 mt-1",children:"Total count"})]})]}),e.jsxs("div",{className:"bg-white dark:bg-gray-700 p-6 rounded-xl shadow-md border border-gray-200 dark:border-gray-600",children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-white",children:"Monthly SST Collection"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400",children:"Trend over time"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(C,{className:"h-4 w-4 text-gray-400"}),e.jsxs("select",{value:n,onChange:t=>N(t.target.value),className:"px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 dark:bg-gray-600 dark:border-gray-500",children:[e.jsx("option",{value:"month",children:"This Month"}),e.jsx("option",{value:"quarter",children:"This Quarter"}),e.jsx("option",{value:"year",children:"This Year"}),e.jsx("option",{value:"all",children:"All Time"})]})]})]}),e.jsx(U,{width:"100%",height:300,children:e.jsxs(Y,{data:c,children:[e.jsx(q,{strokeDasharray:"3 3",stroke:"rgba(128,128,128,0.2)"}),e.jsx(K,{dataKey:"month",stroke:"rgb(156 163 175)"}),e.jsx(_,{stroke:"rgb(156 163 175)"}),e.jsx(H,{contentStyle:{backgroundColor:"rgba(31, 41, 55, 0.8)",border:"1px solid rgba(128,128,128,0.3)"},formatter:t=>[`RM ${t.toFixed(2)}`,"SST Collected"]}),e.jsx(Q,{dataKey:"sst",fill:"#3b82f6",name:"SST Collected"})]})})]}),e.jsxs("div",{className:"bg-white dark:bg-gray-700 p-6 rounded-xl shadow-md border border-gray-200 dark:border-gray-600",children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-white mb-4",children:"SST Rate History"}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"min-w-full divide-y divide-gray-200 dark:divide-gray-600",children:[e.jsx("thead",{className:"bg-gray-50 dark:bg-gray-600",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-300 uppercase tracking-wider",children:"Effective Date"}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-300 uppercase tracking-wider",children:"SST Rate"}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-300 uppercase tracking-wider",children:"Changed By"}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-300 uppercase tracking-wider",children:"Notes"})]})}),e.jsx("tbody",{className:"bg-white dark:bg-gray-700 divide-y divide-gray-200 dark:divide-gray-600",children:b.map((t,a)=>e.jsxs("tr",{className:"hover:bg-gray-50 dark:hover:bg-gray-600",children:[e.jsx("td",{className:"px-6 py-4 whitespace-nowrap text-sm text-gray-900 dark:text-gray-300",children:new Date(t.effectiveDate).toLocaleDateString()}),e.jsxs("td",{className:"px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900 dark:text-white",children:[t.percentage,"%"]}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap text-sm text-gray-900 dark:text-gray-300",children:t.changedBy||"System"}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap text-sm text-gray-900 dark:text-gray-300",children:t.notes||"-"})]},a))})]})})]})]}),o==="reports"&&e.jsxs("div",{className:"space-y-8",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row justify-between items-start sm:items-center gap-4",children:[e.jsx("div",{className:"flex items-center space-x-4",children:e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(C,{className:"h-4 w-4 text-gray-500 dark:text-gray-400"}),e.jsxs("select",{value:n,onChange:t=>N(t.target.value),className:"px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 dark:bg-gray-600 dark:border-gray-500",children:[e.jsx("option",{value:"month",children:"This Month"}),e.jsx("option",{value:"quarter",children:"This Quarter"}),e.jsx("option",{value:"year",children:"This Year"}),e.jsx("option",{value:"all",children:"All Time"})]})]})}),e.jsxs("button",{onClick:L,className:"bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-lg flex items-center space-x-2 transition-colors",children:[e.jsx(W,{className:"h-4 w-4"}),e.jsx("span",{children:"Download SST Report"})]})]}),e.jsxs("div",{className:"bg-white dark:bg-gray-700 rounded-xl shadow-md border border-gray-200 dark:border-gray-600 overflow-hidden",children:[e.jsx("div",{className:"px-6 py-4 border-b border-gray-200 dark:border-gray-600",children:e.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-white",children:"SST Collection Report"})}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"min-w-full divide-y divide-gray-200 dark:divide-gray-600",children:[e.jsx("thead",{className:"bg-gray-50 dark:bg-gray-600",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-300 uppercase tracking-wider",children:"Invoice #"}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-300 uppercase tracking-wider",children:"Date"}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-300 uppercase tracking-wider",children:"Customer"}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-300 uppercase tracking-wider",children:"Amount (RM)"}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-300 uppercase tracking-wider",children:"SST Rate"}),e.jsx("th",{className:"px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-300 uppercase tracking-wider",children:"SST Amount (RM)"})]})}),e.jsx("tbody",{className:"bg-white dark:bg-gray-700 divide-y divide-gray-200 dark:divide-gray-600",children:p.map(t=>{const a=t.totalPrice*(t.sstPercentage||6)/100;return e.jsxs("tr",{className:"hover:bg-gray-50 dark:hover:bg-gray-600",children:[e.jsx("td",{className:"px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900 dark:text-white",children:t.invoiceNumber}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap text-sm text-gray-900 dark:text-gray-300",children:new Date(t.createdAt).toLocaleDateString()}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap text-sm text-gray-900 dark:text-gray-300",children:t.customerName}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap text-sm text-gray-900 dark:text-gray-300",children:t.totalPrice.toFixed(2)}),e.jsxs("td",{className:"px-6 py-4 whitespace-nowrap text-sm text-gray-900 dark:text-gray-300",children:[t.sstPercentage||6,"%"]}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900 dark:text-white",children:a.toFixed(2)})]},t.id)})}),e.jsx("tfoot",{className:"bg-gray-50 dark:bg-gray-600",children:e.jsxs("tr",{children:[e.jsx("td",{colSpan:3,className:"px-6 py-4 whitespace-nowrap text-sm font-bold text-gray-900 dark:text-white text-right",children:"Total:"}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap text-sm font-bold text-gray-900 dark:text-white",children:g.toFixed(2)}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap text-sm font-bold text-gray-900 dark:text-white",children:"-"}),e.jsx("td",{className:"px-6 py-4 whitespace-nowrap text-sm font-bold text-gray-900 dark:text-white",children:m.toFixed(2)})]})})]})})]}),e.jsx("div",{className:"bg-yellow-50 dark:bg-yellow-900/20 p-6 rounded-xl border border-yellow-200 dark:border-yellow-800",children:e.jsxs("div",{className:"flex items-start space-x-3",children:[e.jsx(X,{className:"h-6 w-6 text-yellow-600 dark:text-yellow-400 mt-0.5"}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold text-yellow-900 dark:text-yellow-300 mb-2",children:"SST Reporting Guidelines"}),e.jsxs("div",{className:"text-sm text-yellow-800 dark:text-yellow-200 space-y-2",children:[e.jsx("p",{children:"• SST returns must be submitted to the Royal Malaysian Customs Department (RMCD) bi-monthly"}),e.jsx("p",{children:"• Due date: Last day of the month following the taxable period"}),e.jsx("p",{children:"• Late submission penalties: 10% of the tax amount for the first 30 days, 15% for the next 30 days, and 15% for the next 30 days (maximum penalty: 40%)"}),e.jsx("p",{children:"• Keep all records for 7 years for audit purposes"}),e.jsx("p",{children:"• For more information, visit the official RMCD website or consult your tax advisor"})]})]})]})})]}),o==="settings"&&e.jsxs("div",{className:"space-y-8",children:[e.jsxs("div",{className:"bg-white dark:bg-gray-700 p-6 rounded-xl shadow-md border border-gray-200 dark:border-gray-600",children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-white mb-4",children:"SST Rate Configuration"}),$?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:"New SST Percentage (%)"}),e.jsxs("div",{className:"flex items-center",children:[e.jsx("input",{type:"number",min:"0",max:"100",step:"0.1",value:h,onChange:t=>f(parseFloat(t.target.value)),className:"w-32 px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 dark:bg-gray-600 dark:border-gray-500"}),e.jsx("span",{className:"ml-2 text-gray-600 dark:text-gray-400",children:"%"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:"Effective Date"}),e.jsx("input",{type:"date",value:w,onChange:t=>F(t.target.value),className:"w-full px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 dark:bg-gray-600 dark:border-gray-500"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2",children:"Notes (Optional)"}),e.jsx("textarea",{placeholder:"e.g., Government policy change",className:"w-full px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 dark:bg-gray-600 dark:border-gray-500",value:k,onChange:t=>v(t.target.value),rows:3})]}),e.jsxs("div",{className:"flex space-x-3 pt-2",children:[e.jsxs("button",{onClick:P,className:"bg-green-600 hover:bg-green-700 text-white px-4 py-2 rounded-lg flex items-center space-x-2 transition-colors",children:[e.jsx(z,{className:"h-4 w-4"}),e.jsx("span",{children:"Save Changes"})]}),e.jsxs("button",{onClick:()=>{x(!1),f(i)},className:"bg-gray-600 hover:bg-gray-700 text-white px-4 py-2 rounded-lg flex items-center space-x-2 transition-colors",children:[e.jsx(T,{className:"h-4 w-4"}),e.jsx("span",{children:"Cancel"})]})]})]}):e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-gray-600 dark:text-gray-400",children:"Current SST Rate:"}),e.jsxs("p",{className:"text-3xl font-bold text-gray-900 dark:text-white",children:[i,"%"]})]}),e.jsxs("button",{onClick:()=>x(!0),className:"bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-lg flex items-center space-x-2 transition-colors",children:[e.jsx(J,{className:"h-4 w-4"}),e.jsx("span",{children:"Change Rate"})]})]})]}),e.jsx("div",{className:"bg-blue-50 dark:bg-blue-900/20 p-6 rounded-xl border border-blue-200 dark:border-blue-800",children:e.jsxs("div",{className:"flex items-start space-x-3",children:[e.jsx(V,{className:"h-6 w-6 text-blue-600 dark:text-blue-400 mt-0.5"}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold text-blue-900 dark:text-blue-300 mb-2",children:"About Sales & Service Tax (SST)"}),e.jsxs("div",{className:"text-sm text-blue-800 dark:text-blue-200 space-y-2",children:[e.jsx("p",{children:"• SST was reintroduced in Malaysia on September 1, 2018, replacing the Goods and Services Tax (GST)"}),e.jsx("p",{children:"• Sales Tax: Generally 5% or 10% on taxable goods manufactured in or imported into Malaysia"}),e.jsx("p",{children:"• Service Tax: 6% on taxable services"}),e.jsx("p",{children:"• For printing services, the standard rate is 6%"}),e.jsx("p",{children:"• Changes to SST rates are typically announced during the annual budget or through special announcements by the Ministry of Finance"}),e.jsx("p",{children:"• When the government changes the SST rate, businesses must update their systems and apply the new rate from the effective date"}),e.jsx("p",{children:"• The last SST rate change was from 6% to 8% on March 1, 2023, and back to 6% on May 1, 2023"})]})]})]})})]})]})]})})};export{se as S};
