1import{r as i,J as e,am as u}from"./vendor-BES_ooCv.js";import{C as p,I as t,B as N}from"./index-Bvy0P6lC.js";import{C as d,a as c,b as m,d as x,c as h}from"./card-DYLuWcbP.js";import{L as r}from"./label-8Zyl7q-I.js";import{T as C}from"./textarea-CWYQALEm.js";import{S as w}from"./switch-C7-ZB6Gy.js";import{S as T,a as P,b as E,c as D,d as g}from"./select-Cisidc3I.js";import{g as V}from"./invoicePdf-isbbveOK.js";import{L as S,ay as B,az as Q,ax as M}from"./icons-wPotDBXb.js";import"./maplibre--9FVgYzZ.js";import"./datefns-DVp9_6zc.js";import"./radix-CiT1R7ZI.js";import"./query-XefPi0rm.js";import"./router-lIC-Scp8.js";import"./helmet-BmunKl-J.js";import"./supabase-B2M7Kmhn.js";const k={id:1,company_name:"Pristine End of Tenancy Cleaning",address:"",vat_number:"",company_number:"",logo_url:"",brand_color:"#039AA1",invoice_layout:"classic",invoice_footer:"",phone:"",email:"",website:"",bank_name:"",bank_sort_code:"",bank_account_number:"",payment_reference_prefix:"INV-",vat_rate:20,show_payment_details:!0,qr_enabled:!0,qr_url_template:"https://endoftenancycleaning.site/pay/{number}"};function re(){const[s,j]=i.useState(k),[L,I]=i.useState(!0),[v,b]=i.useState(!1),[f,_]=i.useState(!1);i.useEffect(()=>{(async()=>{const{data:a}=await p.from("company_settings").select("*").eq("id",1).maybeSingle();a&&j({...k,...a}),I(!1)})()},[]);const n=(a,l)=>j(o=>({...o,[a]:l})),U=async a=>{_(!0);try{const l=a.name.split(".").pop()||"png",o=`company/logo-${Date.now()}.${l}`,{error:y}=await p.storage.from("customer-files").upload(o,a,{upsert:!0});if(y)throw y;const{data:R}=p.storage.from("customer-files").getPublicUrl(o);n("logo_url",R.publicUrl),u.success("Logo uploaded")}catch(l){u.error(`Upload failed: ${l.message??l}`)}finally{_(!1)}},A=async()=>{b(!0);const{id:a,...l}=s,{error:o}=await p.from("company_settings").update(l).eq("id",1);b(!1),o?u.error(`Save failed: ${o.message}`):u.success("Settings saved")},q=()=>V({type:"INVOICE",number:"000120",issue_date:new Date().toISOString(),due_date:new Date(Date.now()+7*864e5).toISOString(),bill_to:{name:"Sample Customer",contact:"Property Management Team",address:`1 Milligan Street 2London E14 8AU`},items:[{quantity:1,description:"End of Tenancy Cleaning - 2 Bed Flat",unit_price:195,vat_rate:s.vat_rate}]},s);return L?e.jsxs("div",{className:"p-6 flex items-center gap-2 text-muted-foreground",children:[e.jsx(S,{className:"h-4 w-4 animate-spin"})," Loading settingsâ¦"]}):e.jsxs("div",{className:"p-6 max-w-4xl space-y-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-heading text-foreground",children:"Configuration"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Manage branding, invoice template, and payment details. All changes propagate to the dashboard automatically."})]}),e.jsxs(d,{children:[e.jsxs(c,{children:[e.jsx(m,{children:"Company Details"}),e.jsx(x,{children:"Used on invoices, quotes, emails, and dashboard header."})]}),e.jsxs(h,{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("div",{className:"md:col-span-2",children:[e.jsx(r,{children:"Company Name"}),e.jsx(t,{value:s.company_name,onChange:a=>n("company_name",a.target.value)})]}),e.jsxs("div",{className:"md:col-span-2",children:[e.jsx(r,{children:"Registered Address"}),e.jsx(C,{rows:2,value:s.address??"",onChange:a=>n("address",a.target.value)})]}),e.jsxs("div",{children:[e.jsx(r,{children:"Phone"}),e.jsx(t,{value:s.phone??"",onChange:a=>n("phone",a.target.value)})]}),e.jsxs("div",{children:[e.jsx(r,{children:"Email"}),e.jsx(t,{type:"email",value:s.email??"",onChange:a=>n("email",a.target.value)})]}),e.jsxs("div",{children:[e.jsx(r,{children:"Website"}),e.jsx(t,{value:s.website??"",onChange:a=>n("website",a.target.value)})]}),e.jsxs("div",{children:[e.jsx(r,{children:"VAT Number"}),e.jsx(t,{value:s.vat_number??"",onChange:a=>n("vat_number",a.target.value)})]}),e.jsxs("div",{children:[e.jsx(r,{children:"Company Registration Number"}),e.jsx(t,{value:s.company_number??"",onChange:a=>n("company_number",a.target.value)})]}),e.jsxs("div",{children:[e.jsx(r,{children:"VAT Rate (%)"}),e.jsx(t,{type:"number",value:s.vat_rate,onChange:a=>n("vat_rate",Number(a.target.value))})]})]})]}),e.jsxs(d,{children:[e.jsxs(c,{children:[e.jsx(m,{children:"Branding"}),e.jsx(x,{children:"Logo and brand colour shown across the dashboard and invoices."})]}),e.jsxs(h,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"h-20 w-20 rounded-lg border border-border bg-muted flex items-center justify-center overflow-hidden",children:s.logo_url?e.jsx("img",{src:s.logo_url,alt:"Logo",className:"max-h-full max-w-full object-contain"}):e.jsx("span",{className:"text-xs text-muted-foreground",children:"No logo"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx(r,{children:"Upload Logo (PNG/SVG)"}),e.jsx(t,{type:"file",accept:"image/*",disabled:f,onChange:a=>{var o;const l=(o=a.target.files)==null?void 0:o[0];l&&U(l)}}),f&&e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Uploadingâ¦"}),e.jsx(t,{className:"mt-2",placeholder:"â¦or paste a logo URL",value:s.logo_url??"",onChange:a=>n("logo_url",a.target.value)})]})]}),e.jsxs("div",{className:"flex items-end gap-3",children:[e.jsxs("div",{children:[e.jsxs(r,{className:"flex items-center gap-2",children:[e.jsx(B,{className:"h-4 w-4"})," Brand Colour"]}),e.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[e.jsx(t,{type:"color",className:"h-10 w-16 p-1",value:s.brand_color,onChange:a=>n("brand_color",a.target.value)}),e.jsx(t,{className:"w-32",value:s.brand_color,onChange:a=>n("brand_color",a.target.value)})]})]}),e.jsx("div",{className:"h-10 flex-1 rounded-md border border-border",style:{backgroundColor:s.brand_color}})]})]})]}),e.jsxs(d,{children:[e.jsxs(c,{children:[e.jsx(m,{children:"Payment Details (on Invoices)"}),e.jsx(x,{children:"Bank details printed at the bottom of invoices."})]}),e.jsxs(h,{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("div",{className:"md:col-span-2 flex items-center justify-between rounded-lg border border-border p-3",children:[e.jsxs("div",{children:[e.jsx(r,{className:"text-base",children:"Show payment details on invoices"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Hide for cash-only or pre-paid services."})]}),e.jsx(w,{checked:s.show_payment_details,onCheckedChange:a=>n("show_payment_details",a)})]}),e.jsxs("div",{children:[e.jsx(r,{children:"Bank Name"}),e.jsx(t,{value:s.bank_name??"",onChange:a=>n("bank_name",a.target.value),placeholder:"e.g. Mettle"})]}),e.jsxs("div",{children:[e.jsx(r,{children:"Sort Code"}),e.jsx(t,{value:s.bank_sort_code??"",onChange:a=>n("bank_sort_code",a.target.value),placeholder:"04-03-33"})]}),e.jsxs("div",{children:[e.jsx(r,{children:"Account Number"}),e.jsx(t,{value:s.bank_account_number??"",onChange:a=>n("bank_account_number",a.target.value),placeholder:"67627483"})]}),e.jsxs("div",{children:[e.jsx(r,{children:"Payment Reference Prefix"}),e.jsx(t,{value:s.payment_reference_prefix??"",onChange:a=>n("payment_reference_prefix",a.target.value),placeholder:"INV-"})]})]})]}),e.jsxs(d,{children:[e.jsxs(c,{children:[e.jsxs(m,{className:"flex items-center gap-2",children:[e.jsx(Q,{className:"h-5 w-5"})," QR Code on Invoices & Quotes"]}),e.jsxs(x,{children:["Auto-generated QR linking to the URL template. Use ",e.jsx("code",{children:"{number}"})," for the document number."]})]}),e.jsxs(h,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between rounded-lg border border-border p-3",children:[e.jsx(r,{className:"text-base",children:"Attach QR code"}),e.jsx(w,{checked:s.qr_enabled,onCheckedChange:a=>n("qr_enabled",a)})]}),e.jsxs("div",{children:[e.jsx(r,{children:"QR URL Template"}),e.jsx(t,{value:s.qr_url_template??"",onChange:a=>n("qr_url_template",a.target.value),placeholder:"https://example.com/pay/{number}"})]})]})]}),e.jsxs(d,{children:[e.jsxs(c,{children:[e.jsx(m,{children:"Invoice Template"}),e.jsx(x,{children:"Layout style and footer text for both invoices and quotes."})]}),e.jsxs(h,{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx(r,{children:"Layout Style"}),e.jsxs(T,{value:s.invoice_layout,onValueChange:a=>n("invoice_layout",a),children:[e.jsx(P,{children:e.jsx(E,{})}),e.jsxs(D,{children:[e.jsx(g,{value:"classic",children:"Classic (Haus-style)"}),e.jsx(g,{value:"modern",children:"Modern"}),e.jsx(g,{value:"minimal",children:"Minimal"})]})]})]}),e.jsxs("div",{className:"md:col-span-2",children:[e.jsx(r,{children:"Invoice / Quote Footer"}),e.jsx(C,{rows:3,value:s.invoice_footer??"",onChange:a=>n("invoice_footer",a.target.value),placeholder:"Additional notes printed at the bottom of every invoice/quote."})]}),e.jsx("div",{className:"md:col-span-2 flex justify-end",children:e.jsx(N,{variant:"outline",onClick:q,className:"gap-2",children:"Preview Sample Invoice"})})]})]}),e.jsx("div",{className:"flex justify-end gap-2 sticky bottom-4 bg-background/80 backdrop-blur p-2 rounded-lg border border-border",children:e.jsxs(N,{onClick:A,disabled:v,className:"gap-2",children:[v?e.jsx(S,{className:"h-4 w-4 animate-spin"}):e.jsx(M,{className:"h-4 w-4"}),"Save Settings"]})})]})}export{re as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.