1import{g as w,u as F,r as a,s as i,j as e,H as _}from"./index-mAFB58yJ.js";import{C as y,a as S,b as C,c as E,d as k}from"./card-Ctbiqdlu.js";import{B as L}from"./button-DTIxvefv.js";import{I as A}from"./input-Bon3i80E.js";import{L as $}from"./label-C_xxNvAO.js";import{H as q}from"./Header-CgRH3E9o.js";import H from"./Footer-B9EL6_wK.js";import{S as D}from"./SEOHead-BT_rbuim.js";import"./useScrollToSection-B_hERIue.js";import"./phone-BjH7Z17o.js";import"./user-FK4-xyPe.js";import"./chevron-down-Dmb5kpEg.js";import"./map-pin-sMpiGceb.js";const u="fuel_per_mile",Q=()=>{const m=w(),{toast:l}=F(),[p,x]=a.useState(!0),[g,f]=a.useState(!1),[c,h]=a.useState(null),[j,v]=a.useState(null),[n,b]=a.useState("0.20");a.useEffect(()=>{(async()=>{try{x(!0);const{data:{session:t}}=await i.auth.getSession();if(!t){m("/auth");return}const{data:d,error:s}=await i.rpc("is_admin_user",{_user_id:t.user.id});if(s||!d){h("Unauthorized. Admin access required.");return}const{data:r,error:o}=await i.from("pricing_config").select("key, value, description, updated_at").eq("key",u).maybeSingle();if(o)throw o;r&&(v(r),b(String(r.value)))}catch(t){h(t.message||"Failed to load pricing config")}finally{x(!1)}})()},[m]);const N=async()=>{var d;const t=Number(n);if(!Number.isFinite(t)||t<0||t>5){l({title:"Invalid value",description:"Fuel surcharge must be a number between 0 and 5.",variant:"destructive"});return}try{f(!0);const{data:{session:s}}=await i.auth.getSession(),{error:r}=await i.from("pricing_config").upsert({key:u,value:t,description:"Fuel surcharge added to every banded per-mile rate (open & enclosed).",updated_at:new Date().toISOString(),updated_by:((d=s==null?void 0:s.user)==null?void 0:d.id)??null},{onConflict:"key"});if(r)throw r;_(t),l({title:"Saved",description:`Fuel surcharge is now $${t.toFixed(2)} per mile. New quotes will use this rate immediately.`});const{data:o}=await i.from("pricing_config").select("key, value, description, updated_at").eq("key",u).maybeSingle();o&&v(o)}catch(s){l({title:"Save failed",description:s.message||"Could not update pricing config.",variant:"destructive"})}finally{f(!1)}};return e.jsxs(e.Fragment,{children:[e.jsx(D,{title:"Admin · Pricing",description:"Adjust pricing surcharges",noindex:!0}),e.jsxs("div",{className:"min-h-screen flex flex-col bg-background",children:[e.jsx(q,{}),e.jsxs("main",{className:"flex-1 container mx-auto px-4 py-12 max-w-2xl",children:[e.jsx("h1",{className:"text-3xl font-bold mb-6",children:"Pricing Settings"}),p&&e.jsx("p",{className:"text-muted-foreground",children:"Loadingâ¦"}),c&&e.jsx(y,{className:"border-destructive",children:e.jsx(S,{className:"pt-6 text-destructive",children:c})}),!p&&!c&&e.jsxs(y,{children:[e.jsxs(C,{children:[e.jsx(E,{children:"Fuel Surcharge (per mile)"}),e.jsx(k,{children:"Added on top of every banded per-mile rate, for both Open and Enclosed transport. Changes take effect immediately for new quotes and bookings â no redeploy needed."})]}),e.jsxs(S,{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx($,{htmlFor:"fuel",children:"USD per mile"}),e.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[e.jsx("span",{className:"text-muted-foreground",children:"$"}),e.jsx(A,{id:"fuel",type:"number",step:"0.01",min:"0",max:"5",value:n,onChange:t=>b(t.target.value),className:"max-w-[160px]"})]})]}),e.jsxs("div",{className:"text-sm text-muted-foreground space-y-1",children:[e.jsx("p",{children:e.jsx("strong",{children:"Current banded rates with this surcharge:"})}),e.jsxs("ul",{className:"list-disc pl-5",children:[e.jsxs("li",{children:["1â500 mi: $",(1.9+(Number(n)||0)).toFixed(2),"/mi (open)"]}),e.jsxs("li",{children:["501â1,500 mi: $",(.92+(Number(n)||0)).toFixed(2),"/mi (open)"]}),e.jsxs("li",{children:["1,500+ mi: $",(.585+(Number(n)||0)).toFixed(3),"/mi (open)"]})]}),e.jsx("p",{className:"pt-1",children:"Enclosed multiplies these by 1.33."})]}),j&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Last updated: ",new Date(j.updated_at).toLocaleString()]}),e.jsx(L,{onClick:N,disabled:g,children:g?"Savingâ¦":"Save"})]})]})]}),e.jsx(H,{})]})]})};export{Q 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.