vendor: 23,121 bytes, line 1
1import{c as V,r as l,j as e,g as Se,h as Z,i as K,s as w,t as y,B as N,T as be,k as Ar,l as mt,L as W,m as Or,S as pt}from"./main-BGPPHxHM.js";import{I as v}from"./input-D0ZnlPy7.js";import{L as f}from"./label-Cs-fnIPW.js";import{T as we}from"./textarea-C1GjMsvY.js";import{R as ht,A as Le,e as ke,P as xt,h as ft,u as gt,f as vt,F as jt,D as _t,C as yt,g as bt,S as F,a as L,b as $,c as z,d as S}from"./select-9BnniKoU.js";import{c as wt,I as Tr,R as Fr,T as Lr,a as $r,b as _e,d as ye,P as zr}from"./tabs-CkdpH30v.js";import{B as Br}from"./badge-zEFINaEp.js";import{D as qe,a as Vr,b as Ye,c as Je,d as Xe,e as Ze}from"./dialog-BWqNwiPR.js";import{c as $e,a as C,P as Y,d as Gr,u as Nt}from"./index-D3F3hwE6.js";import{u as Ct,a as Ur,c as Kr,b as Te}from"./index-Q-HDVsyn.js";import{P as ae}from"./index-CDLVY2j6.js";import{C as Hr}from"./chevron-right-ChkK1bCk.js";import{C as St}from"./check-Cx29d-FE.js";import{E as Wr}from"./external-link-CK93yfK1.js";import{P as Qe}from"./palette-D7Dp8342.js";import{P as qr}from"./package-B9jNKOt0.js";import{B as Yr}from"./building-2-DbhuPjwf.js";import{S as Jr}from"./search-DQkFYzwY.js";import{E as et}from"./eye-5ih1ta9I.js";import{B as tt}from"./banknote-BGmYL8KK.js";import{C as rt}from"./circle-check-D9BCjgai.js";import{P as nt}from"./pencil-z0E0LyrK.js";import{D as Xr}from"./download-C6W6ED4X.js";const Zr=[["rect",{width:"20",height:"5",x:"2",y:"3",rx:"1",key:"1wp1u1"}],["path",{d:"M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8",key:"1s80jp"}],["path",{d:"M10 12h4",key:"a56b0p"}]],st=V("archive",Zr);const Qr=[["path",{d:"M10.268 21a2 2 0 0 0 3.464 0",key:"vwvbt9"}],["path",{d:"M3.262 15.326A1 1 0 0 0 4 17h16a1 1 0 0 0 .74-1.673C19.41 13.956 18 12.499 18 8A6 6 0 0 0 6 8c0 4.499-1.411 5.956-2.738 7.326",key:"11g9vi"}]],en=V("bell",Qr);const tn=[["path",{d:"M17 3a2 2 0 0 1 2 2v15a1 1 0 0 1-1.496.868l-4.512-2.578a2 2 0 0 0-1.984 0l-4.512 2.578A1 1 0 0 1 5 20V5a2 2 0 0 1 2-2z",key:"oz39mx"}],["path",{d:"m9 10 2 2 4-4",key:"1gnqz4"}]],at=V("bookmark-check",tn);const rn=[["path",{d:"M3 3v16a2 2 0 0 0 2 2h16",key:"c24i48"}],["path",{d:"M18 17V9",key:"2bz60n"}],["path",{d:"M13 17V5",key:"1frdt8"}],["path",{d:"M8 17v-3",key:"17ska0"}]],ot=V("chart-column",rn);const nn=[["path",{d:"M18 6 7 17l-5-5",key:"116fxf"}],["path",{d:"m22 10-7.5 7.5L13 16",key:"ke71qq"}]],sn=V("check-check",nn);const an=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}]],on=V("circle",an);const ln=[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"12",cy:"5",r:"1",key:"gxeob9"}],["circle",{cx:"12",cy:"19",r:"1",key:"lyex9k"}]],cn=V("ellipsis-vertical",ln);const dn=[["polyline",{points:"22 12 16 12 14 15 10 15 8 12 2 12",key:"o97t9d"}],["path",{d:"M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z",key:"oot6mr"}]],un=V("inbox",dn);const mn=[["path",{d:"M2.586 17.414A2 2 0 0 0 2 18.828V21a1 1 0 0 0 1 1h3a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h1a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h.172a2 2 0 0 0 1.414-.586l.814-.814a6.5 6.5 0 1 0-4-4z",key:"1s6t7t"}],["circle",{cx:"16.5",cy:"7.5",r:".5",fill:"currentColor",key:"w0ekpg"}]],kt=V("key-round",mn);const pn=[["path",{d:"m16 17 5-5-5-5",key:"1bji2h"}],["path",{d:"M21 12H9",key:"dn1m92"}],["path",{d:"M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4",key:"1uf3rs"}]],it=V("log-out",pn);const hn=[["path",{d:"m10.344 4.688 1.181-2.393a.53.53 0 0 1 .95 0l2.31 4.679a2.12 2.12 0 0 0 1.595 1.16l5.166.756a.53.53 0 0 1 .294.904l-3.237 3.152",key:"19ctli"}],["path",{d:"m17.945 17.945.43 2.505a.53.53 0 0 1-.771.56l-4.618-2.428a2.12 2.12 0 0 0-1.973 0L6.396 21.01a.53.53 0 0 1-.77-.56l.881-5.139a2.12 2.12 0 0 0-.611-1.879L2.16 9.795a.53.53 0 0 1 .294-.906l5.165-.755a8 8 0 0 0 .4-.099",key:"ptqqvy"}],["path",{d:"m2 2 20 20",key:"1ooewy"}]],lt=V("star-off",hn);const xn=[["path",{d:"M11.525 2.295a.53.53 0 0 1 .95 0l2.31 4.679a2.123 2.123 0 0 0 1.595 1.16l5.166.756a.53.53 0 0 1 .294.904l-3.736 3.638a2.123 2.123 0 0 0-.611 1.878l.882 5.14a.53.53 0 0 1-.771.56l-4.618-2.428a2.122 2.122 0 0 0-1.973 0L6.396 21.01a.53.53 0 0 1-.77-.56l.881-5.139a2.122 2.122 0 0 0-.611-1.879L2.16 9.795a.53.53 0 0 1 .294-.906l5.165-.755a2.122 2.122 0 0 0 1.597-1.16z",key:"r04s7s"}]],ct=V("star",xn);function fn(t){const s=gn(t),n=l.forwardRef((o,a)=>{const{children:c,...r}=o,d=l.Children.toArray(c),m=d.find(jn);if(m){const u=m.props.children,p=d.map(h=>h===m?l.Children.count(u)>1?l.Children.only(null):l.isValidElement(u)?u.props.children:null:h);return e.jsx(s,{...r,ref:a,children:l.isValidElement(u)?l.cloneElement(u,void 0,p):null})}return e.jsx(s,{...r,ref:a,children:c})});return n.displayName=`${t}.Slot`,n}function gn(t){const s=l.forwardRef((n,o)=>{const{children:a,...c}=n;if(l.isValidElement(a)){const r=yn(a),d=_n(c,a.props);return a.type!==l.Fragment&&(d.ref=o?Se(o,r):r),l.cloneElement(a,d)}return l.Children.count(a)>1?l.Children.only(null):null});return s.displayName=`${t}.SlotClone`,s}var vn=Symbol("radix.slottable");function jn(t){return l.isValidElement(t)&&typeof t.type=="function"&&"__radixId"in t.type&&t.type.__radixId===vn}function _n(t,s){const n={...s};for(const o in s){const a=t[o],c=s[o];/^on[A-Z]/.test(o)?a&&c?n[o]=(...d)=>{const m=c(...d);return a(...d),m}:a&&(n[o]=a):o==="style"?n[o]={...a,...c}:o==="className"&&(n[o]=[a,c].filter(Boolean).join(" "))}return{...t,...n}}function yn(t){let s=Object.getOwnPropertyDescriptor(t.props,"ref")?.get,n=s&&"isReactWarning"in s&&s.isReactWarning;return n?t.ref:(s=Object.getOwnPropertyDescriptor(t,"ref")?.get,n=s&&"isReactWarning"in s&&s.isReactWarning,n?t.props.ref:t.props.ref||t.ref)}var Fe=["Enter"," "],bn=["ArrowDown","PageUp","Home"],Mt=["ArrowUp","PageDown","End"],wn=[...bn,...Mt],Nn={ltr:[...Fe,"ArrowRight"],rtl:[...Fe,"ArrowLeft"]},Cn={ltr:["ArrowLeft"],rtl:["ArrowRight"]},he="Menu",[me,Sn,kn]=Kr(he),[Q,Pt]=$e(he,[kn,ke,wt]),Me=ke(),Rt=wt(),[Mn,ee]=Q(he),[Pn,xe]=Q(he),Dt=t=>{const{__scopeMenu:s,open:n=!1,children:o,dir:a,onOpenChange:c,modal:r=!0}=t,d=Me(s),[m,u]=l.useState(null),p=l.useRef(!1),h=Ct(c),j=Ur(a);return l.useEffect(()=>{const P=()=>{p.current=!0,document.addEventListener("pointerdown",b,{capture:!0,once:!0}),document.addEventListener("pointermove",b,{capture:!0,once:!0})},b=()=>p.current=!1;return document.addEventListener("keydown",P,{capture:!0}),()=>{document.removeEventListener("keydown",P,{capture:!0}),document.removeEventListener("pointerdown",b,{capture:!0}),document.removeEventListener("pointermove",b,{capture:!0})}},[]),e.jsx(ht,{...d,children:e.jsx(Mn,{scope:s,open:n,onOpenChange:h,content:m,onContentChange:u,children:e.jsx(Pn,{scope:s,onClose:l.useCallback(()=>h(!1),[h]),isUsingKeyboardRef:p,dir:j,modal:r,children:o})})})};Dt.displayName=he;var Rn="MenuAnchor",ze=l.forwardRef((t,s)=>{const{__scopeMenu:n,...o}=t,a=Me(n);return e.jsx(Le,{...a,...o,ref:s})});ze.displayName=Rn;var Be="MenuPortal",[Dn,Et]=Q(Be,{forceMount:void 0}),It=t=>{const{__scopeMenu:s,forceMount:n,children:o,container:a}=t,c=ee(Be,s);return e.jsx(Dn,{scope:s,forceMount:n,children:e.jsx(ae,{present:n||c.open,children:e.jsx(xt,{asChild:!0,container:a,children:o})})})};It.displayName=Be;var B="MenuContent",[En,Ve]=Q(B),At=l.forwardRef((t,s)=>{const n=Et(B,t.__scopeMenu),{forceMount:o=n.forceMount,...a}=t,c=ee(B,t.__scopeMenu),r=xe(B,t.__scopeMenu);return e.jsx(me.Provider,{scope:t.__scopeMenu,children:e.jsx(ae,{present:o||c.open,children:e.jsx(me.Slot,{scope:t.__scopeMenu,children:r.modal?e.jsx(In,{...a,ref:s}):e.jsx(An,{...a,ref:s})})})})}),In=l.forwardRef((t,s)=>{const n=ee(B,t.__scopeMenu),o=l.useRef(null),a=Z(s,o);return l.useEffect(()=>{const c=o.current;if(c)return ft(c)},[]),e.jsx(Ge,{...t,ref:a,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:C(t.onFocusOutside,c=>c.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)})}),An=l.forwardRef((t,s)=>{const n=ee(B,t.__scopeMenu);return e.jsx(Ge,{...t,ref:s,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)})}),On=fn("MenuContent.ScrollLock"),Ge=l.forwardRef((t,s)=>{const{__scopeMenu:n,loop:o=!1,trapFocus:a,onOpenAutoFocus:c,onCloseAutoFocus:r,disableOutsidePointerEvents:d,onEntryFocus:m,onEscapeKeyDown:u,onPointerDownOutside:p,onFocusOutside:h,onInteractOutside:j,onDismiss:P,disableOutsideScroll:b,...G}=t,O=ee(B,n),I=xe(B,n),te=Me(n),Ee=Rt(n),oe=Sn(n),[ge,ie]=l.useState(null),X=l.useRef(null),ve=Z(s,X,O.onContentChange),U=l.useRef(0),T=l.useRef(""),je=l.useRef(0),M=l.useRef(null),le=l.useRef("right"),re=l.useRef(0),ce=b?vt:l.Fragment,Ie=b?{as:On,allowPinchZoom:!0}:void 0,Ae=i=>{const x=T.current+i,g=oe().filter(k=>!k.disabled),_=document.activeElement,D=g.find(k=>k.ref.current===_)?.textValue,E=g.map(k=>k.textValue),q=Wn(E,x,D),R=g.find(k=>k.textValue===q)?.ref.current;(function k(de){T.current=de,window.clearTimeout(U.current),de!==""&&(U.current=window.setTimeout(()=>k(""),1e3))})(x),R&&setTimeout(()=>R.focus())};l.useEffect(()=>()=>window.clearTimeout(U.current),[]),gt();const H=l.useCallback(i=>le.current===M.current?.side&&Yn(i,M.current?.area),[]);return e.jsx(En,{scope:n,searchRef:T,onItemEnter:l.useCallback(i=>{H(i)&&i.preventDefault()},[H]),onItemLeave:l.useCallback(i=>{H(i)||(X.current?.focus(),ie(null))},[H]),onTriggerLeave:l.useCallback(i=>{H(i)&&i.preventDefault()},[H]),pointerGraceTimerRef:je,onPointerGraceIntentChange:l.useCallback(i=>{M.current=i},[]),children:e.jsx(ce,{...Ie,children:e.jsx(jt,{asChild:!0,trapped:a,onMountAutoFocus:C(c,i=>{i.preventDefault(),X.current?.focus({preventScroll:!0})}),onUnmountAutoFocus:r,children:e.jsx(_t,{asChild:!0,disableOutsidePointerEvents:d,onEscapeKeyDown:u,onPointerDownOutside:p,onFocusOutside:h,onInteractOutside:j,onDismiss:P,children:e.jsx(Fr,{asChild:!0,...Ee,dir:I.dir,orientation:"vertical",loop:o,currentTabStopId:ge,onCurrentTabStopIdChange:ie,onEntryFocus:C(m,i=>{I.isUsingKeyboardRef.current||i.preventDefault()}),preventScrollOnEntryFocus:!0,children:e.jsx(yt,{role:"menu","aria-orientation":"vertical","data-state":Jt(O.open),"data-radix-menu-content":"",dir:I.dir,...te,...G,ref:ve,style:{outline:"none",...G.style},onKeyDown:C(G.onKeyDown,i=>{const g=i.target.closest("[data-radix-menu-content]")===i.currentTarget,_=i.ctrlKey||i.altKey||i.metaKey,D=i.key.length===1;g&&(i.key==="Tab"&&i.preventDefault(),!_&&D&&Ae(i.key));const E=X.current;if(i.target!==E||!wn.includes(i.key))return;i.preventDefault();const R=oe().filter(k=>!k.disabled).map(k=>k.ref.current);Mt.includes(i.key)&&R.reverse(),Kn(R)}),onBlur:C(t.onBlur,i=>{i.currentTarget.contains(i.target)||(window.clearTimeout(U.current),T.current="")}),onPointerMove:C(t.onPointerMove,pe(i=>{const x=i.target,g=re.current!==i.clientX;if(i.currentTarget.contains(x)&&g){const _=i.clientX>re.current?"right":"left";le.current=_,re.current=i.clientX}}))})})})})})})});At.displayName=B;var Tn="MenuGroup",Ue=l.forwardRef((t,s)=>{const{__scopeMenu:n,...o}=t;return e.jsx(Y.div,{role:"group",...o,ref:s})});Ue.displayName=Tn;var Fn="MenuLabel",Ot=l.forwardRef((t,s)=>{const{__scopeMenu:n,...o}=t;return e.jsx(Y.div,{...o,ref:s})});Ot.displayName=Fn;var Ne="MenuItem",dt="menu.itemSelect",Pe=l.forwardRef((t,s)=>{const{disabled:n=!1,onSelect:o,...a}=t,c=l.useRef(null),r=xe(Ne,t.__scopeMenu),d=Ve(Ne,t.__scopeMenu),m=Z(s,c),u=l.useRef(!1),p=()=>{const h=c.current;if(!n&&h){const j=new CustomEvent(dt,{bubbles:!0,cancelable:!0});h.addEventListener(dt,P=>o?.(P),{once:!0}),Gr(h,j),j.defaultPrevented?u.current=!1:r.onClose()}};return e.jsx(Tt,{...a,ref:m,disabled:n,onClick:C(t.onClick,p),onPointerDown:h=>{t.onPointerDown?.(h),u.current=!0},onPointerUp:C(t.onPointerUp,h=>{u.current||h.currentTarget?.click()}),onKeyDown:C(t.onKeyDown,h=>{const j=d.searchRef.current!=="";n||j&&h.key===" "||Fe.includes(h.key)&&(h.currentTarget.click(),h.preventDefault())})})});Pe.displayName=Ne;var Tt=l.forwardRef((t,s)=>{const{__scopeMenu:n,disabled:o=!1,textValue:a,...c}=t,r=Ve(Ne,n),d=Rt(n),m=l.useRef(null),u=Z(s,m),[p,h]=l.useState(!1),[j,P]=l.useState("");return l.useEffect(()=>{const b=m.current;b&&P((b.textContent??"").trim())},[c.children]),e.jsx(me.ItemSlot,{scope:n,disabled:o,textValue:a??j,children:e.jsx(Tr,{asChild:!0,...d,focusable:!o,children:e.jsx(Y.div,{role:"menuitem","data-highlighted":p?"":void 0,"aria-disabled":o||void 0,"data-disabled":o?"":void 0,...c,ref:u,onPointerMove:C(t.onPointerMove,pe(b=>{o?r.onItemLeave(b):(r.onItemEnter(b),b.defaultPrevented||b.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:C(t.onPointerLeave,pe(b=>r.onItemLeave(b))),onFocus:C(t.onFocus,()=>h(!0)),onBlur:C(t.onBlur,()=>h(!1))})})})}),Ln="MenuCheckboxItem",Ft=l.forwardRef((t,s)=>{const{checked:n=!1,onCheckedChange:o,...a}=t;return e.jsx(Vt,{scope:t.__scopeMenu,checked:n,children:e.jsx(Pe,{role:"menuitemcheckbox","aria-checked":Ce(n)?"mixed":n,...a,ref:s,"data-state":He(n),onSelect:C(a.onSelect,()=>o?.(Ce(n)?!0:!n),{checkForDefaultPrevented:!1})})})});Ft.displayName=Ln;var Lt="MenuRadioGroup",[$n,zn]=Q(Lt,{value:void 0,onValueChange:()=>{}}),$t=l.forwardRef((t,s)=>{const{value:n,onValueChange:o,...a}=t,c=Ct(o);return e.jsx($n,{scope:t.__scopeMenu,value:n,onValueChange:c,children:e.jsx(Ue,{...a,ref:s})})});$t.displayName=Lt;var zt="MenuRadioItem",Bt=l.forwardRef((t,s)=>{const{value:n,...o}=t,a=zn(zt,t.__scopeMenu),c=n===a.value;return e.jsx(Vt,{scope:t.__scopeMenu,checked:c,children:e.jsx(Pe,{role:"menuitemradio","aria-checked":c,...o,ref:s,"data-state":He(c),onSelect:C(o.onSelect,()=>a.onValueChange?.(n),{checkForDefaultPrevented:!1})})})});Bt.displayName=zt;var Ke="MenuItemIndicator",[Vt,Bn]=Q(Ke,{checked:!1}),Gt=l.forwardRef((t,s)=>{const{__scopeMenu:n,forceMount:o,...a}=t,c=Bn(Ke,n);return e.jsx(ae,{present:o||Ce(c.checked)||c.checked===!0,children:e.jsx(Y.span,{...a,ref:s,"data-state":He(c.checked)})})});Gt.displayName=Ke;var Vn="MenuSeparator",Ut=l.forwardRef((t,s)=>{const{__scopeMenu:n,...o}=t;return e.jsx(Y.div,{role:"separator","aria-orientation":"horizontal",...o,ref:s})});Ut.displayName=Vn;var Gn="MenuArrow",Kt=l.forwardRef((t,s)=>{const{__scopeMenu:n,...o}=t,a=Me(n);return e.jsx(bt,{...a,...o,ref:s})});Kt.displayName=Gn;var Un="MenuSub",[za,Ht]=Q(Un),ue="MenuSubTrigger",Wt=l.forwardRef((t,s)=>{const n=ee(ue,t.__scopeMenu),o=xe(ue,t.__scopeMenu),a=Ht(ue,t.__scopeMenu),c=Ve(ue,t.__scopeMenu),r=l.useRef(null),{pointerGraceTimerRef:d,onPointerGraceIntentChange:m}=c,u={__scopeMenu:t.__scopeMenu},p=l.useCallback(()=>{r.current&&window.clearTimeout(r.current),r.current=null},[]);return l.useEffect(()=>p,[p]),l.useEffect(()=>{const h=d.current;return()=>{window.clearTimeout(h),m(null)}},[d,m]),e.jsx(ze,{asChild:!0,...u,children:e.jsx(Tt,{id:a.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":a.contentId,"data-state":Jt(n.open),...t,ref:Se(s,a.onTriggerChange),onClick:h=>{t.onClick?.(h),!(t.disabled||h.defaultPrevented)&&(h.currentTarget.focus(),n.open||n.onOpenChange(!0))},onPointerMove:C(t.onPointerMove,pe(h=>{c.onItemEnter(h),!h.defaultPrevented&&!t.disabled&&!n.open&&!r.current&&(c.onPointerGraceIntentChange(null),r.current=window.setTimeout(()=>{n.onOpenChange(!0),p()},100))})),onPointerLeave:C(t.onPointerLeave,pe(h=>{p();const j=n.content?.getBoundingClientRect();if(j){const P=n.content?.dataset.side,b=P==="right",G=b?-5:5,O=j[b?"left":"right"],I=j[b?"right":"left"];c.onPointerGraceIntentChange({area:[{x:h.clientX+G,y:h.clientY},{x:O,y:j.top},{x:I,y:j.top},{x:I,y:j.bottom},{x:O,y:j.bottom}],side:P}),window.clearTimeout(d.current),d.current=window.setTimeout(()=>c.onPointerGraceIntentChange(null),300)}else{if(c.onTriggerLeave(h),h.defaultPrevented)return;c.onPointerGraceIntentChange(null)}})),onKeyDown:C(t.onKeyDown,h=>{const j=c.searchRef.current!=="";t.disabled||j&&h.key===" "||Nn[o.dir].includes(h.key)&&(n.onOpenChange(!0),n.content?.focus(),h.preventDefault())})})})});Wt.displayName=ue;var qt="MenuSubContent",Yt=l.forwardRef((t,s)=>{const n=Et(B,t.__scopeMenu),{forceMount:o=n.forceMount,...a}=t,c=ee(B,t.__scopeMenu),r=xe(B,t.__scopeMenu),d=Ht(qt,t.__scopeMenu),m=l.useRef(null),u=Z(s,m);return e.jsx(me.Provider,{scope:t.__scopeMenu,children:e.jsx(ae,{present:o||c.open,children:e.jsx(me.Slot,{scope:t.__scopeMenu,children:e.jsx(Ge,{id:d.contentId,"aria-labelledby":d.triggerId,...a,ref:u,align:"start",side:r.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:p=>{r.isUsingKeyboardRef.current&&m.current?.focus(),p.preventDefault()},onCloseAutoFocus:p=>p.preventDefault(),onFocusOutside:C(t.onFocusOutside,p=>{p.target!==d.trigger&&c.onOpenChange(!1)}),onEscapeKeyDown:C(t.onEscapeKeyDown,p=>{r.onClose(),p.preventDefault()}),onKeyDown:C(t.onKeyDown,p=>{const h=p.currentTarget.contains(p.target),j=Cn[r.dir].includes(p.key);h&&j&&(c.onOpenChange(!1),d.trigger?.focus(),p.preventDefault())})})})})})});Yt.displayName=qt;function Jt(t){return t?"open":"closed"}function Ce(t){return t==="indeterminate"}function He(t){return Ce(t)?"indeterminate":t?"checked":"unchecked"}function Kn(t){const s=document.activeElement;for(const n of t)if(n===s||(n.focus(),document.activeElement!==s))return}function Hn(t,s){return t.map((n,o)=>t[(s+o)%t.length])}function Wn(t,s,n){const a=s.length>1&&Array.from(s).every(u=>u===s[0])?s[0]:s,c=n?t.indexOf(n):-1;let r=Hn(t,Math.max(c,0));a.length===1&&(r=r.filter(u=>u!==n));const m=r.find(u=>u.toLowerCase().startsWith(a.toLowerCase()));return m!==n?m:void 0}function qn(t,s){const{x:n,y:o}=t;let a=!1;for(let c=0,r=s.length-1;c<s.length;r=c++){const d=s[c],m=s[r],u=d.x,p=d.y,h=m.x,j=m.y;p>o!=j>o&&n<(h-u)*(o-p)/(j-p)+u&&(a=!a)}return a}function Yn(t,s){if(!s)return!1;const n={x:t.clientX,y:t.clientY};return qn(n,s)}function pe(t){return s=>s.pointerType==="mouse"?t(s):void 0}var Jn=Dt,Xn=ze,Zn=It,Qn=At,es=Ue,ts=Ot,rs=Pe,ns=Ft,ss=$t,as=Bt,os=Gt,is=Ut,ls=Kt,cs=Wt,ds=Yt,Re="DropdownMenu",[us]=$e(Re,[Pt]),A=Pt(),[ms,Xt]=us(Re),Zt=t=>{const{__scopeDropdownMenu:s,children:n,dir:o,open:a,defaultOpen:c,onOpenChange:r,modal:d=!0}=t,m=A(s),u=l.useRef(null),[p,h]=Nt({prop:a,defaultProp:c??!1,onChange:r,caller:Re});return e.jsx(ms,{scope:s,triggerId:Te(),triggerRef:u,contentId:Te(),open:p,onOpenChange:h,onOpenToggle:l.useCallback(()=>h(j=>!j),[h]),modal:d,children:e.jsx(Jn,{...m,open:p,onOpenChange:h,dir:o,modal:d,children:n})})};Zt.displayName=Re;var Qt="DropdownMenuTrigger",er=l.forwardRef((t,s)=>{const{__scopeDropdownMenu:n,disabled:o=!1,...a}=t,c=Xt(Qt,n),r=A(n);return e.jsx(Xn,{asChild:!0,...r,children:e.jsx(Y.button,{type:"button",id:c.triggerId,"aria-haspopup":"menu","aria-expanded":c.open,"aria-controls":c.open?c.contentId:void 0,"data-state":c.open?"open":"closed","data-disabled":o?"":void 0,disabled:o,...a,ref:Se(s,c.triggerRef),onPointerDown:C(t.onPointerDown,d=>{!o&&d.button===0&&d.ctrlKey===!1&&(c.onOpenToggle(),c.open||d.preventDefault())}),onKeyDown:C(t.onKeyDown,d=>{o||(["Enter"," "].includes(d.key)&&c.onOpenToggle(),d.key==="ArrowDown"&&c.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(d.key)&&d.preventDefault())})})})});er.displayName=Qt;var ps="DropdownMenuPortal",tr=t=>{const{__scopeDropdownMenu:s,...n}=t,o=A(s);return e.jsx(Zn,{...o,...n})};tr.displayName=ps;var rr="DropdownMenuContent",nr=l.forwardRef((t,s)=>{const{__scopeDropdownMenu:n,...o}=t,a=Xt(rr,n),c=A(n),r=l.useRef(!1);return e.jsx(Qn,{id:a.contentId,"aria-labelledby":a.triggerId,...c,...o,ref:s,onCloseAutoFocus:C(t.onCloseAutoFocus,d=>{r.current||a.triggerRef.current?.focus(),r.current=!1,d.preventDefault()}),onInteractOutside:C(t.onInteractOutside,d=>{const m=d.detail.originalEvent,u=m.button===0&&m.ctrlKey===!0,p=m.button===2||u;(!a.modal||p)&&(r.current=!0)}),style:{...t.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});nr.displayName=rr;var hs="DropdownMenuGroup",xs=l.forwardRef((t,s)=>{const{__scopeDropdownMenu:n,...o}=t,a=A(n);return e.jsx(es,{...a,...o,ref:s})});xs.displayName=hs;var fs="DropdownMenuLabel",sr=l.forwardRef((t,s)=>{const{__scopeDropdownMenu:n,...o}=t,a=A(n);return e.jsx(ts,{...a,...o,ref:s})});sr.displayName=fs;var gs="DropdownMenuItem",ar=l.forwardRef((t,s)=>{const{__scopeDropdownMenu:n,...o}=t,a=A(n);return e.jsx(rs,{...a,...o,ref:s})});ar.displayName=gs;var vs="DropdownMenuCheckboxItem",or=l.forwardRef((t,s)=>{const{__scopeDropdownMenu:n,...o}=t,a=A(n);return e.jsx(ns,{...a,...o,ref:s})});or.displayName=vs;var js="DropdownMenuRadioGroup",_s=l.forwardRef((t,s)=>{const{__scopeDropdownMenu:n,...o}=t,a=A(n);return e.jsx(ss,{...a,...o,ref:s})});_s.displayName=js;var ys="DropdownMenuRadioItem",ir=l.forwardRef((t,s)=>{const{__scopeDropdownMenu:n,...o}=t,a=A(n);return e.jsx(as,{...a,...o,ref:s})});ir.displayName=ys;var bs="DropdownMenuItemIndicator",lr=l.forwardRef((t,s)=>{const{__scopeDropdownMenu:n,...o}=t,a=A(n);return e.jsx(os,{...a,...o,ref:s})});lr.displayName=bs;var ws="DropdownMenuSeparator",cr=l.forwardRef((t,s)=>{const{__scopeDropdownMenu:n,...o}=t,a=A(n);return e.jsx(is,{...a,...o,ref:s})});cr.displayName=ws;var Ns="DropdownMenuArrow",Cs=l.forwardRef((t,s)=>{const{__scopeDropdownMenu:n,...o}=t,a=A(n);return e.jsx(ls,{...a,...o,ref:s})});Cs.displayName=Ns;var Ss="DropdownMenuSubTrigger",dr=l.forwardRef((t,s)=>{const{__scopeDropdownMenu:n,...o}=t,a=A(n);return e.jsx(cs,{...a,...o,ref:s})});dr.displayName=Ss;var ks="DropdownMenuSubContent",ur=l.forwardRef((t,s)=>{const{__scopeDropdownMenu:n,...o}=t,a=A(n);return e.jsx(ds,{...a,...o,ref:s,style:{...t.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});ur.displayName=ks;var Ms=Zt,Ps=er,Rs=tr,mr=nr,pr=sr,hr=ar,xr=or,fr=ir,gr=lr,vr=cr,jr=dr,_r=ur;const Ds=Ms,Es=Ps,Is=l.forwardRef(({className:t,inset:s,children:n,...o},a)=>e.jsxs(jr,{ref:a,className:K("flex cursor-default select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",s&&"pl-8",t),...o,children:[n,e.jsx(Hr,{className:"ml-auto"})]}));Is.displayName=jr.displayName;const As=l.forwardRef(({className:t,...s},n)=>e.jsx(_r,{ref:n,className:K("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:sli
1de-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-(--radix-dropdown-menu-content-transform-origin)",t),...s}));As.displayName=_r.displayName;const yr=l.forwardRef(({className:t,sideOffset:s=4,...n},o)=>e.jsx(Rs,{children:e.jsx(mr,{ref:o,sideOffset:s,className:K("z-50 max-h-[var(--radix-dropdown-menu-content-available-height)] min-w-[8rem] overflow-y-auto overflow-x-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md","data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-(--radix-dropdown-menu-content-transform-origin)",t),...n})}));yr.displayName=mr.displayName;const ne=l.forwardRef(({className:t,inset:s,...n},o)=>e.jsx(hr,{ref:o,className:K("relative flex cursor-default select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&>svg]:size-4 [&>svg]:shrink-0",s&&"pl-8",t),...n}));ne.displayName=hr.displayName;const Os=l.forwardRef(({className:t,children:s,checked:n,...o},a)=>e.jsxs(xr,{ref:a,className:K("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",t),checked:n,...o,children:[e.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(gr,{children:e.jsx(St,{className:"h-4 w-4"})})}),s]}));Os.displayName=xr.displayName;const Ts=l.forwardRef(({className:t,children:s,...n},o)=>e.jsxs(fr,{ref:o,className:K("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",t),...n,children:[e.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(gr,{children:e.jsx(on,{className:"h-2 w-2 fill-current"})})}),s]}));Ts.displayName=fr.displayName;const Fs=l.forwardRef(({className:t,inset:s,...n},o)=>e.jsx(pr,{ref:o,className:K("px-2 py-1.5 text-sm font-semibold",s&&"pl-8",t),...n}));Fs.displayName=pr.displayName;const Ls=l.forwardRef(({className:t,...s},n)=>e.jsx(vr,{ref:n,className:K("-mx-1 my-1 h-px bg-muted",t),...s}));Ls.displayName=vr.displayName;function $s(t){const s=zs(t),n=l.forwardRef((o,a)=>{const{children:c,...r}=o,d=l.Children.toArray(c),m=d.find(Vs);if(m){const u=m.props.children,p=d.map(h=>h===m?l.Children.count(u)>1?l.Children.only(null):l.isValidElement(u)?u.props.children:null:h);return e.jsx(s,{...r,ref:a,children:l.isValidElement(u)?l.cloneElement(u,void 0,p):null})}return e.jsx(s,{...r,ref:a,children:c})});return n.displayName=`${t}.Slot`,n}function zs(t){const s=l.forwardRef((n,o)=>{const{children:a,...c}=n;if(l.isValidElement(a)){const r=Us(a),d=Gs(c,a.props);return a.type!==l.Fragment&&(d.ref=o?Se(o,r):r),l.cloneElement(a,d)}return l.Children.count(a)>1?l.Children.only(null):null});return s.displayName=`${t}.SlotClone`,s}var Bs=Symbol("radix.slottable");function Vs(t){return l.isValidElement(t)&&typeof t.type=="function"&&"__radixId"in t.type&&t.type.__radixId===Bs}function Gs(t,s){const n={...s};for(const o in s){const a=t[o],c=s[o];/^on[A-Z]/.test(o)?a&&c?n[o]=(...d)=>{const m=c(...d);return a(...d),m}:a&&(n[o]=a):o==="style"?n[o]={...a,...c}:o==="className"&&(n[o]=[a,c].filter(Boolean).join(" "))}return{...t,...n}}function Us(t){let s=Object.getOwnPropertyDescriptor(t.props,"ref")?.get,n=s&&"isReactWarning"in s&&s.isReactWarning;return n?t.ref:(s=Object.getOwnPropertyDescriptor(t,"ref")?.get,n=s&&"isReactWarning"in s&&s.isReactWarning,n?t.props.ref:t.props.ref||t.ref)}var De="Popover",[br]=$e(De,[ke]),fe=ke(),[Ks,J]=br(De),wr=t=>{const{__scopePopover:s,children:n,open:o,defaultOpen:a,onOpenChange:c,modal:r=!1}=t,d=fe(s),m=l.useRef(null),[u,p]=l.useState(!1),[h,j]=Nt({prop:o,defaultProp:a??!1,onChange:c,caller:De});return e.jsx(ht,{...d,children:e.jsx(Ks,{scope:s,contentId:Te(),triggerRef:m,open:h,onOpenChange:j,onOpenToggle:l.useCallback(()=>j(P=>!P),[j]),hasCustomAnchor:u,onCustomAnchorAdd:l.useCallback(()=>p(!0),[]),onCustomAnchorRemove:l.useCallback(()=>p(!1),[]),modal:r,children:n})})};wr.displayName=De;var Nr="PopoverAnchor",Hs=l.forwardRef((t,s)=>{const{__scopePopover:n,...o}=t,a=J(Nr,n),c=fe(n),{onCustomAnchorAdd:r,onCustomAnchorRemove:d}=a;return l.useEffect(()=>(r(),()=>d()),[r,d]),e.jsx(Le,{...c,...o,ref:s})});Hs.displayName=Nr;var Cr="PopoverTrigger",Sr=l.forwardRef((t,s)=>{const{__scopePopover:n,...o}=t,a=J(Cr,n),c=fe(n),r=Z(s,a.triggerRef),d=e.jsx(Y.button,{type:"button","aria-haspopup":"dialog","aria-expanded":a.open,"aria-controls":a.contentId,"data-state":Dr(a.open),...o,ref:r,onClick:C(t.onClick,a.onOpenToggle)});return a.hasCustomAnchor?d:e.jsx(Le,{asChild:!0,...c,children:d})});Sr.displayName=Cr;var We="PopoverPortal",[Ws,qs]=br(We,{forceMount:void 0}),kr=t=>{const{__scopePopover:s,forceMount:n,children:o,container:a}=t,c=J(We,s);return e.jsx(Ws,{scope:s,forceMount:n,children:e.jsx(ae,{present:n||c.open,children:e.jsx(xt,{asChild:!0,container:a,children:o})})})};kr.displayName=We;var se="PopoverContent",Mr=l.forwardRef((t,s)=>{const n=qs(se,t.__scopePopover),{forceMount:o=n.forceMount,...a}=t,c=J(se,t.__scopePopover);return e.jsx(ae,{present:o||c.open,children:c.modal?e.jsx(Js,{...a,ref:s}):e.jsx(Xs,{...a,ref:s})})});Mr.displayName=se;var Ys=$s("PopoverContent.RemoveScroll"),Js=l.forwardRef((t,s)=>{const n=J(se,t.__scopePopover),o=l.useRef(null),a=Z(s,o),c=l.useRef(!1);return l.useEffect(()=>{const r=o.current;if(r)return ft(r)},[]),e.jsx(vt,{as:Ys,allowPinchZoom:!0,children:e.jsx(Pr,{...t,ref:
1a,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:C(t.onCloseAutoFocus,r=>{r.preventDefault(),c.current||n.triggerRef.current?.focus()}),onPointerDownOutside:C(t.onPointerDownOutside,r=>{const d=r.detail.originalEvent,m=d.button===0&&d.ctrlKey===!0,u=d.button===2||m;c.current=u},{checkForDefaultPrevented:!1}),onFocusOutside:C(t.onFocusOutside,r=>r.preventDefault(),{checkForDefaultPrevented:!1})})})}),Xs=l.forwardRef((t,s)=>{const n=J(se,t.__scopePopover),o=l.useRef(!1),a=l.useRef(!1);return e.jsx(Pr,{...t,ref:s,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:c=>{t.onCloseAutoFocus?.(c),c.defaultPrevented||(o.current||n.triggerRef.current?.focus(),c.preventDefault()),o.current=!1,a.current=!1},onInteractOutside:c=>{t.onInteractOutside?.(c),c.defaultPrevented||(o.current=!0,c.detail.originalEvent.type==="pointerdown"&&(a.current=!0));const r=c.target;n.triggerRef.current?.contains(r)&&c.preventDefault(),c.detail.originalEvent.type==="focusin"&&a.current&&c.preventDefault()}})}),Pr=l.forwardRef((t,s)=>{const{__scopePopover:n,trapFocus:o,onOpenAutoFocus:a,onCloseAutoFocus:c,disableOutsidePointerEvents:r,onEscapeKeyDown:d,onPointerDownOutside:m,onFocusOutside:u,onInteractOutside:p,...h}=t,j=J(se,n),P=fe(n);return gt(),e.jsx(jt,{asChild:!0,loop:!0,trapped:o,onMountAutoFocus:a,onUnmountAutoFocus:c,children:e.jsx(_t,{asChild:!0,disableOutsidePointerEvents:r,onInteractOutside:p,onEscapeKeyDown:d,onPointerDownOutside:m,onFocusOutside:u,onDismiss:()=>j.onOpenChange(!1),children:e.jsx(yt,{"data-state":Dr(j.open),role:"dialog",id:j.contentId,...P,...h,ref:s,style:{...h.style,"--radix-popover-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-popover-content-available-width":"var(--radix-popper-available-width)","--radix-popover-content-available-height":"var(--radix-popper-available-height)","--radix-popover-trigger-width":"var(--radix-popper-anchor-width)","--radix-popover-trigger-height":"var(--radix-popper-anchor-height)"}})})})}),Rr="PopoverClose",Zs=l.forwardRef((t,s)=>{const{__scopePopover:n,...o}=t,a=J(Rr,n);return e.jsx(Y.button,{type:"button",...o,ref:s,onClick:C(t.onClick,()=>a.onOpenChange(!1))})});Zs.displayName=Rr;var Qs="PopoverArrow",ea=l.forwardRef((t,s)=>{const{__scopePopover:n,...o}=t,a=fe(n);return e.jsx(bt,{...a,...o,ref:s})});ea.displayName=Qs;function Dr(t){return t?"open":"closed"}var ta=wr,ra=Sr,na=kr,Er=Mr;const sa=ta,aa=ra,Ir=l.forwardRef(({className:t,align:s="center",sideOffset:n=4,...o},a)=>e.jsx(na,{children:e.jsx(Er,{ref:a,align:s,sideOffset:n,className:K("z-50 w-72 rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-(--radix-popover-content-transform-origin)",t),...o})}));Ir.displayName=Er.displayName;function oa(t){const s=Math.floor((Date.now()-new Date(t).getTime())/1e3);return s<60?"just now":s<3600?`${Math.floor(s/60)}m ago`:s<86400?`${Math.floor(s/3600)}h ago`:`${Math.floor(s/86400)}d ago`}function ut(){const[t,s]=l.useState([]),[n,o]=l.useState(!1),a=t.filter(u=>!u.read_at).length;async function c(){const{data:u,error:p}=await w.from("admin_notifications").select("*").order("created_at",{ascending:!1}).limit(50);if(p){console.error(p);return}s(u??[])}l.useEffect(()=>{c();const u=`admin-notifications-${Date.now()}-${Math.random().toString(36).slice(2)}`,p=w.channel(u).on("postgres_changes",{event:"*",schema:"public",table:"admin_notifications"},h=>{if(c(),h.eventType==="INSERT"){const j=h.new;y.info(j.title,{description:j.summary??void 0})}}).subscribe();return()=>{w.removeChannel(p)}},[]);async function r(u){await w.from("admin_notifications").update({read_at:new Date().toISOString()}).eq("id",u),c()}async function d(){const u=t.filter(p=>!p.read_at).map(p=>p.id);u.length!==0&&(await w.from("admin_notifications").update({read_at:new Date().toISOString()}).in("id",u),c())}async function m(u){await w.from("admin_notifications").delete().eq("id",u),c()}return e.jsxs(sa,{open:n,onOpenChange:o,children:[e.jsx(aa,{asChild:!0,children:e.jsxs(N,{variant:"outline",size:"icon","aria-label":"Notifications",className:"relative",children:[e.jsx(en,{className:"h-4 w-4"}),a>0&&e.jsx("span",{className:"absolute -right-1 -top-1 inline-flex h-5 min-w-5 items-center justify-center rounded-full bg-destructive px-1.5 text-[10px] font-semibold text-destructive-foreground",children:a>9?"9+":a})]})}),e.jsxs(Ir,{align:"end",className:"w-[22rem] p-0",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-border px-3 py-2",children:[e.jsx("p",{className:"text-sm font-semibold",children:"Notifications"}),e.jsxs(N,{variant:"ghost",size:"sm",onClick:d,disabled:a===0,className:"h-7 text-xs",children:[e.jsx(sn,{className:"mr-1 h-3.5 w-3.5"})," Mark all read"]})]}),e.jsx("div",{className:"max-h-[28rem] overflow-y-auto",children:t.length===0?e.jsx("p",{className:"px-3 py-10 text-center text-sm text-muted-foreground",children:"No notifications yet."}):e.jsx("ul",{className:"divide-y divide-border",children:t.map(u=>e.jsx("li",{className:K("group px-3 py-2.5 text-sm",!u.read_at&&"bg-accent/40"),children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("span",{className:K("mt-1.5 h-2 w-2 shrink-0 rounded-full",u.read_at?"bg-transparent":"bg-primary")}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"font-medium leading-snug",children:u.title}),u.summary&&e.jsx("p",{className:"mt-0.5 whitespace-pre-wrap text-xs text-muted-foreground",children:u.summary}),e.jsxs("div",{className:"mt-1 flex items-center gap-2",children:[e.jsx("span",{className:"text-[11px] text-muted-foreground",children:oa(u.created_at)}),u.link&&e.jsxs("a",{href:u.link,target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1 text-[11px] text-primary hover:underline",children:["Open ",e.jsx(Wr,{className:"h-3 w-3"})]})]})]}),e.jsxs("div",{className:"flex flex-col gap-1 opacity-0 transition-opacity group-hover:opacity-100",children:[!u.read_at&&e.jsx("button",{onClick:()=>r(u.id),className:"rounded p-1 hover:bg-accent","aria-label":"Mark read",children:e.jsx(St,{className:"h-3.5 w-3.5"})}),e.jsx("button",{onClick:()=>m(u.id),className:"rounded p-1 text-destructive hover:bg-destructive/10","aria-label":"Delete",children:e.jsx(be,{className:"h-3.5 w-3.5"})})]})]})},u.id))})})]})]})}function Ba(){const{user:t,isAdmin:s,loading:n,roleChecked:o,signOut:a}=Ar(),c=mt(),[r,d]=l.useState(0),m=l.useRef(null);return l.useEffect(()=>{n||!o||(!t||!s)&&c({to:"/admin/login"})},[n,o,t,s,c]),l.useEffect(()=>{if(!t||!s)return;let u=!0;async function p(){const{count:P}=await w.from("car_submissions").select("*",{count:"exact",head:!0}
1).eq("status","pending");if(!u)return;const b=P??0;if(m.current!==null&&b>m.current){const G=b-m.current;y.info(`${G} new submission${G>1?"s":""}`)}m.current=b,d(b)}p();const h=`submissions-notify-${Date.now()}-${Math.random().toString(36).slice(2)}`,j=w.channel(h).on("postgres_changes",{event:"*",schema:"public",table:"car_submissions"},()=>p()).subscribe();return()=>{u=!1,w.removeChannel(j)}},[t,s]),n||!o||!t||!s?e.jsx("div",{className:"flex min-h-screen items-center justify-center text-muted-foreground",children:"Loadingâ¦"}):e.jsxs("div",{className:"min-h-screen bg-surface",children:[e.jsx("header",{className:"border-b border-border bg-card",children:e.jsxs("div",{className:"mx-auto flex h-16 max-w-7xl items-center justify-between gap-2 px-3 sm:px-6 lg:px-8",children:[e.jsxs(W,{to:"/",className:"flex min-w-0 items-center gap-2 font-display font-bold","aria-label":"Pulse Cars admin home",children:[e.jsx(Or,{className:"h-9 shrink-0 sm:h-10"}),e.jsx("span",{className:"hidden truncate text-sm sm:inline",children:"Admin"})]}),e.jsxs("div",{className:"hidden items-center gap-2 md:flex",children:[e.jsx(ut,{}),e.jsx(N,{asChild:!0,variant:"outline",size:"sm",children:e.jsxs(W,{to:"/admin/analytics",children:[e.jsx(ot,{className:"mr-2 h-4 w-4"})," Analytics"]})}),e.jsx(N,{asChild:!0,variant:"outline",size:"sm",children:e.jsxs(W,{to:"/admin/sold",children:[e.jsx(st,{className:"mr-2 h-4 w-4"})," Sold"]})}),e.jsx(N,{asChild:!0,variant:"outline",size:"sm",children:e.jsxs(W,{to:"/admin/themes",children:[e.jsx(Qe,{className:"mr-2 h-4 w-4"})," Themes"]})}),e.jsx(N,{asChild:!0,variant:"outline",size:"sm",children:e.jsx(W,{to:"/admin/assistant",children:"AI Assistant"})}),e.jsxs(N,{variant:"ghost",size:"sm",onClick:async()=>{await a(),c({to:"/"})},children:[e.jsx(it,{className:"mr-2 h-4 w-4"})," Sign out"]})]}),e.jsxs("div",{className:"flex items-center gap-2 md:hidden",children:[e.jsx(ut,{}),e.jsxs(Ds,{children:[e.jsx(Es,{asChild:!0,children:e.jsx(N,{variant:"outline",size:"icon","aria-label":"Admin menu",children:e.jsx(cn,{className:"h-5 w-5"})})}),e.jsxs(yr,{align:"end",className:"w-52",children:[e.jsx(ne,{asChild:!0,children:e.jsxs(W,{to:"/admin/analytics",children:[e.jsx(ot,{className:"mr-2 h-4 w-4"})," Analytics"]})}),e.jsx(ne,{asChild:!0,children:e.jsxs(W,{to:"/admin/sold",children:[e.jsx(st,{className:"mr-2 h-4 w-4"})," Sold"]})}),e.jsx(ne,{asChild:!0,children:e.jsxs(W,{to:"/admin/themes",children:[e.jsx(Qe,{className:"mr-2 h-4 w-4"})," Themes"]})}),e.jsx(ne,{asChild:!0,children:e.jsxs(W,{to:"/admin/assistant",children:[e.jsx(pt,{className:"mr-2 h-4 w-4"})," AI Assistant"]})}),e.jsxs(ne,{onSelect:async()=>{await a(),c({to:"/"})},children:[e.jsx(it,{className:"mr-2 h-4 w-4"})," Sign out"]})]})]})]})]})}),e.jsxs("main",{className:"mx-auto max-w-7xl px-3 py-6 sm:px-6 sm:py-10 lg:px-8",children:[e.jsx("h1",{className:"font-display text-2xl font-bold sm:text-3xl",children:"Dashboard"}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground sm:text-base",children:"Manage inventory and review seller submissions."}),e.jsxs(Lr,{defaultValue:r>0?"submissions":"inventory",className:"mt-6 sm:mt-8",children:[e.jsxs($r,{className:"grid h-auto w-full grid-cols-2 gap-1 sm:flex sm:w-max sm:gap-0",children:[e.jsxs(_e,{value:"inventory",className:"justify-center text-xs sm:text-sm",children:[e.jsx(qr,{className:"mr-1.5 h-4 w-4 sm:mr-2"})," Inventory"]}),e.jsxs(_e,{value:"submissions",className:"relative justify-center text-xs sm:text-sm",children:[e.jsx(un,{className:"mr-1.5 h-4 w-4 sm:mr-2"})," Submissions",r>0&&e.jsx("span",{className:"ml-2 inline-flex h-5 min-w-5 items-center justify-center rounded-full bg-destructive px-1.5 text-xs font-semibold text-destructive-foreground",children:r})]}),e.jsxs(_e,{value:"dealer",className:"justify-center text-xs sm:text-sm",children:[e.jsx(Yr,{className:"mr-1.5 h-4 w-4 sm:mr-2"})," Dealer info"]}),e.jsxs(_e,{value:"account",className:"justify-center text-xs sm:text-sm",children:[e.jsx(kt,{className:"mr-1.5 h-4 w-4 sm:mr-2"})," Account"]})]}),e.jsx(ye,{value:"inventory",className:"mt-6",children:e.jsx(ca,{})}),e.jsx(ye,{value:"submissions",className:"mt-6",children:e.jsx(ma,{})}),e.jsx(ye,{value:"dealer",className:"mt-6",children:e.jsx(fa,{})}),e.jsx(ye,{value:"account",className:"mt-6",children:e.jsx(pa,{})})]})]})]})}function ia(){return{make:"",model:"",year:new Date().getFullYear(),price:0,mileage:0,fuel_type:"Petrol",transmission:"Manual",body_type:"Hatchback",color:"",description:"",image_url:"",status:"available",featured:!1,autotrader_url:"",variant:"",registration:"",registration_date:null,stock_number:"",location:"",engine:"",engine_size:null,horsepower:null,drivetrain:"",doors:null,seats:null,mpg_combined:null,mpg_city:null,mpg_highway:null,fuel_tank_size:null,co2_emissions:null,ulez_compliant:null,mot_expiry:null,previous_owners:null,length_mm:null,width_mm:null,height_mm:null,wheelbase_mm:null,features:[],offer_active:!1,offer_label:"",market_price:null,offer_expires_at:null,purchase_price:null}}function la(){return{sold_price:"",sold_at:new Date().toISOString().slice(0,10),purchase_price:"",prep_cost:"",customer_name:"",customer_phone:"",customer_email:"",customer_postcode:"",payment_method:"",lead_source:"",part_ex_taken:!1,part_ex_value:"",part_ex_registration:"",salesperson:"",notes:""}}function ca(){const t=mt(),[s,n]=l.useState([]),[o,a]=l.useState(!0),c="admin:car-draft:v1",[r,d]=l.useState(null),[m,u]=l.useState(!1),[p,h]=l.useState({}),[j,P]=l.useState(""),[b,G]=l.useState("all"),O=i=>{d(x=>{const g=typeof i=="function"?i(x):i;try{g?localStorage.setItem(c,JSON.stringify(g)):localStorage.removeItem(c)}catch{}return g})};l.useEffect(()=>{try{const i=localStorage.getItem(c);if(i){const x=JSON.parse(i);d(x),u(!0)}}catch{}},[]);async function I(){a(!0);const{data:i}=await w.from("cars").select("*").order("created_at",{ascending:!1});n(i??[]),a(!1);const{data:x}=await w.from("car_views").select("car_id,session_token"),g={};for(const _ of x??[]){const D=g[_.car_id]??(g[_.car_id]={total:0,unique:new Set});D.total+=1,_.session_token&&D.unique.add(_.session_token)}
1h(Object.fromEntries(Object.entries(g).map(([_,D])=>[_,{total:D.total,unique:D.unique.size}])))}l.useEffect(()=>{I()},[]);const te=(()=>{const i=j.trim().toLowerCase();return s.filter(x=>b!=="all"&&x.status!==b?!1:i?[x.make,x.model,x.variant,x.registration,x.stock_number,x.color,x.body_type,x.fuel_type,x.transmission,String(x.year??""),String(x.price??""),x.reserved_for_name].filter(Boolean).join(" ").toLowerCase().includes(i):!0)})();async function Ee(){if(!r)return;const i=(r.autotrader_url??"").trim();if(i&&!/^https?:\/\//i.test(i)){y.error("Listing URL must start with http:// or https://");return}const x=R=>{if(R===""||R===null||R===void 0)return null;const k=typeof R=="number"?R:parseFloat(String(R));return Number.isFinite(k)?k:null},g=R=>{const k=x(R);return k===null?null:Math.round(k)},_=R=>{const k=(R??"").toString().trim();return k||null},D=R=>{const k=(R??"").toString().trim();return k||null},E={make:String(r.make??""),model:String(r.model??""),year:Number(r.year),price:Number(r.price),mileage:Number(r.mileage??0),fuel_type:String(r.fuel_type??"Petrol"),transmission:String(r.transmission??"Manual"),body_type:String(r.body_type??"Hatchback"),color:r.color||null,description:r.description||null,image_url:r.image_url||null,status:String(r.status??"available"),featured:!!r.featured,autotrader_url:i||null,gallery_urls:Array.isArray(r.gallery_urls)?r.gallery_urls:[],variant:_(r.variant),registration:_(r.registration),registration_date:D(r.registration_date),stock_number:_(r.stock_number),location:_(r.location),engine:_(r.engine),engine_size:x(r.engine_size),horsepower:g(r.horsepower),drivetrain:_(r.drivetrain),doors:g(r.doors),seats:g(r.seats),mpg_combined:x(r.mpg_combined),mpg_city:x(r.mpg_city),mpg_highway:x(r.mpg_highway),fuel_tank_size:x(r.fuel_tank_size),co2_emissions:g(r.co2_emissions),ulez_compliant:typeof r.ulez_compliant=="boolean"?r.ulez_compliant:null,mot_expiry:D(r.mot_expiry),previous_owners:g(r.previous_owners),length_mm:g(r.length_mm),width_mm:g(r.width_mm),height_mm:g(r.height_mm),wheelbase_mm:g(r.wheelbase_mm),features:Array.isArray(r.features)?r.features.filter(Boolean):[],offer_active:!!r.offer_active,offer_label:_(r.offer_label),market_price:x(r.market_price),purchase_price:x(r.purchase_price),offer_expires_at:r.offer_expires_at?new Date(r.offer_expires_at).toISOString():null};if(!r.id&&!E.description&&E.make&&E.model)try{const{data:R}=await w.auth.getSession(),k=R.session?.access_token,de=await fetch("/api/admin/generate-description",{method:"POST",headers:{"Content-Type":"application/json",...k?{Authorization:`Bearer ${k}`}:{}},body:JSON.stringify({car:E})}),Oe=await de.json().catch(()=>({}));de.ok&&Oe.ok&&Oe.description&&(E.description=Oe.description,y.success("AI description auto-filled"))}catch{}const{error:q}=r.id?await w.from("cars").update(E).eq("id",r.id):await w.from("cars").insert(E);if(q){y.error(q.message);return}y.success(r.id?"Car updated":"Car added"),u(!1),O(null),I()}async function oe(i){if(!confirm("Delete this car?"))return;const{error:x}=await w.from("cars").delete().eq("id",i);if(x){y.error(x.message);return}y.success("Deleted"),I()}async function ge(i){await w.from("cars").update({featured:!i.featured}).eq("id",i.id),I()}async function ie(i,x){const g={status:x};x==="reserved"&&(g.reserved_at=new Date().toISOString()),x==="available"&&(g.reserved_for_name=null,g.reserved_for_phone=null,g.reserved_at=null,g.deposit_amount=null,g.deposit_taken_at=null);const{error:_}=await w.from("cars").update(g).eq("id",i);if(_){y.error(_.message);return}y.success(`Marked as ${x.replace("_"," ")}`),I()}async function X(i){const x=window.prompt("Customer name for reservation?",i.reserved_for_name??"");if(x===null)return;const g=window.prompt("Customer phone?",i.reserved_for_phone??"")??"",{error:_}=await w.from("cars").update({status:"reserved",reserved_for_name:x.trim()||null,reserved_for_phone:g.trim()||null,reserved_at:new Date().toISOString()}).eq("id",i.id);if(_){y.error(_.message);return}y.success("Reserved"),I()}async function ve(i){const x=window.prompt("Deposit amount (£)?",String(i.deposit_amount??""));if(x===null)return;const g=parseFloat(x);if(!Number.isFinite(g)||g<=0){y.error("Invalid amount");return}const _=window.prompt("Customer name?",i.reserved_for_name??"")??"",D=window.prompt("Customer phone?",i.reserved_for_phone??"")??"",{error:E}=await w.from("cars").update({status:"deposit_taken",deposit_amount:g,deposit_taken_at:new Date().toISOString(),reserved_for_name:_.trim()||i.reserved_for_name||null,reserved_for_phone:D.trim()||i.reserved_for_phone||null,reserved_at:i.reserved_at??new Date().toISOString()}).eq("id",i.id);if(E){y.error(E.message);return}
1y.success(`Deposit £${g.toLocaleString()} recorded`),I()}const U="admin:sold-draft:v1",[T,je]=l.useState(null),[M,le]=l.useState(la()),re=i=>{le(x=>{const g=typeof i=="function"?i(x):i;try{const _=localStorage.getItem(U),D=_?JSON.parse(_):{};localStorage.setItem(U,JSON.stringify({...D,form:g}))}catch{}return g})};function ce(i){je(i);try{if(i){const x=localStorage.getItem(U),g=x?JSON.parse(x):{};localStorage.setItem(U,JSON.stringify({...g,carId:i.id}))}else localStorage.removeItem(U)}catch{}}function Ie(i){ce(i),re({sold_price:String(i.price??""),sold_at:new Date().toISOString().slice(0,10),purchase_price:i.purchase_price!=null?String(i.purchase_price):"",prep_cost:"",customer_name:i.reserved_for_name??i.sold_to_name??"",customer_phone:i.reserved_for_phone??"",customer_email:"",customer_postcode:"",payment_method:"",lead_source:"",part_ex_taken:!1,part_ex_value:"",part_ex_registration:"",salesperson:"",notes:""})}l.useEffect(()=>{if(!(T||s.length===0))try{const i=localStorage.getItem(U);if(!i)return;const x=JSON.parse(i);if(!x.carId)return;const g=s.find(_=>_.id===x.carId);g&&(je(g),x.form&&le(x.form))}catch{}},[s]);async function Ae(){if(!T)return;const i=parseFloat(M.sold_price);if(!Number.isFinite(i)||i<=0){y.error("Sold price is required");return}const x=E=>{const q=parseFloat(E);return Number.isFinite(q)?q:null},g=E=>E.trim()||null,{data:_,error:D}=await w.rpc("archive_and_delete_car",{_car_id:T.id,_sold_price:i,_customer_name:g(M.customer_name)??void 0,_purchase_price:x(M.purchase_price)??void 0,_prep_cost:x(M.prep_cost)??void 0,_customer_phone:g(M.customer_phone)??void 0,_customer_email:g(M.customer_email)??void 0,_customer_postcode:g(M.customer_postcode)??void 0,_payment_method:g(M.payment_method)??void 0,_lead_source:g(M.lead_source)??void 0,_part_ex_taken:M.part_ex_taken,_part_ex_value:x(M.part_ex_value)??void 0,_part_ex_registration:g(M.part_ex_registration)??void 0,_salesperson:g(M.salesperson)??void 0,_notes:g(M.notes)??void 0,_sold_at:M.sold_at?new Date(M.sold_at).toISOString():void 0});if(D){y.error(D.message);return}y.success("Marked sold & archived",{action:_?{label:"Open receipt",onClick:()=>t({to:"/admin/receipt/$id",params:{id:String(_)}})}:void 0}),ce(null),I(),_&&t({to:"/admin/receipt/$id",params:{id:String(_)}})}const H=Ie;return e.jsxs("section",{children:[e.jsxs("div",{className:"mb-4 flex items-center justify-between gap-2",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:j||b!=="all"?`${te.length} of ${s.length} cars`:`${s.length} cars in stock`}),e.jsxs(qe,{open:m,onOpenChange:i=>{u(i),i||O(null)},children:[e.jsx(Vr,{asChild:!0,children:e.jsxs(N,{onClick:()=>O(ia()),className:"bg-gradient-hero shadow-elegant",children:[e.jsx(zr,{className:"mr-2 h-4 w-4"})," Add car"]})}),e.jsxs(Ye,{className:"max-h-[90vh] max-w-2xl overflow-y-auto",onInteractOutside:i=>i.preventDefault(),onPointerDownOutside:i=>i.preventDefault(),onEscapeKeyDown:i=>i.preventDefault(),children:[e.jsx(Je,{children:e.jsx(Xe,{children:r?.id?"Edit car":"Add car"})}),r&&!r.id&&e.jsx(ha,{onImported:i=>O(x=>({...x??{},...i}))}),r&&e.jsx(da,{car:r,setCar:O}),e.jsxs(Ze,{children:[e.jsx(N,{variant:"outline",onClick:()=>{u(!1),O(null)},children:"Cancel"}),e.jsx(N,{onClick:Ee,className:"bg-gradient-hero",children:"Save"})]})]})]})]}),e.jsxs("div",{className:"mb-4 flex flex-col gap-2 sm:flex-row sm:items-center",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(Jr,{className:"pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(v,{value:j,onChange:i=>P(i.target.value),placeholder:"Search by make, model, reg, stock #, colourâ¦",className:"pl-9"})]}),e.jsxs(F,{value:b,onValueChange:G,children:[e.jsx(L,{className:"w-full sm:w-48 capitalize",children:e.jsx($,{})}),e.jsxs(z,{children:[e.jsx(S,{value:"all",children:"All statuses"}),e.jsx(S,{value:"available",children:"Available"}),e.jsx(S,{value:"reserved",children:"Reserved"}),e.jsx(S,{value:"deposit_taken",children:"Deposit taken"}),e.jsx(S,{value:"pending_collection",children:"Pending collection"}),e.jsx(S,{value:"sold",children:"Sold"}),e.jsx(S,{value:"withdrawn",children:"Withdrawn"})]})]})]}),o?e.jsx("p",{className:"py-12 text-center text-muted-foreground",children:"Loadingâ¦"}):te.length===0?e.jsx("p",{className:"py-12 text-center text-muted-foreground",children:"No cars match your search."}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"grid gap-3 md:hidden",children:te.map(i=>e.jsxs("div",{className:"w-full overflow-hidden rounded-2xl border border-border bg-card p-3 shadow-card",children:[e.jsxs("div",{className:"flex gap-3",children:[i.image_url&&e.jsx("img",{src:i.image_url,alt:"",className:"h-16 w-20 shrink-0 rounded-md object-cover"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"break-words text-sm font-semibold leading-tight",children:[i.year," ",i.make," ",i.model]}),e.jsxs("div",{className:"mt-0.5 break-words text-[11px] text-muted-foreground",children:[i.stock_number&&e.jsxs("span",{className:"font-mono",children:["#",i.stock_number," · "]}),i.body_type," · ",i.transmission]}),e.jsxs("div",{className:"mt-1 font-display text-sm font-semibold",children:["£",Number(i.price).toLocaleStr
1ing()]}),e.jsxs("div",{className:"mt-1 inline-flex items-center gap-1 rounded-full bg-primary/10 px-2 py-0.5 text-[11px] font-medium text-primary",children:[e.jsx(et,{className:"h-3 w-3"}),p[i.id]?.total??0," views",p[i.id]?.unique?e.jsxs("span",{className:"text-muted-foreground",children:["· ",p[i.id].unique," unique"]}):null]}),i.reserved_for_name&&e.jsxs("div",{className:"mt-0.5 break-words text-[11px] text-muted-foreground",children:["Reserved for ",e.jsx("span",{className:"font-medium text-foreground",children:i.reserved_for_name}),i.deposit_amount?e.jsxs(e.Fragment,{children:[" · £",Number(i.deposit_amount).toLocaleString()]}):null]})]})]}),e.jsx("div",{className:"mt-3",children:e.jsxs(F,{value:i.status,onValueChange:x=>ie(i.id,x),children:[e.jsx(L,{className:"h-9 w-full capitalize",children:e.jsx($,{})}),e.jsxs(z,{children:[e.jsx(S,{value:"available",children:"Available"}),e.jsx(S,{value:"reserved",children:"Reserved"}),e.jsx(S,{value:"deposit_taken",children:"Deposit taken"}),e.jsx(S,{value:"pending_collection",children:"Pending collection"}),e.jsx(S,{value:"sold",children:"Sold"}),e.jsx(S,{value:"withdrawn",children:"Withdrawn"})]})]})}),e.jsxs("div",{className:"mt-3 grid grid-cols-2 gap-1.5",children:[e.jsxs(N,{size:"sm",variant:"outline",className:"min-w-0 justify-start px-2 text-xs",onClick:()=>X(i),children:[e.jsx(at,{className:"mr-1.5 h-3.5 w-3.5 shrink-0"})," ",e.jsx("span",{className:"truncate",children:"Reserve"})]}),e.jsxs(N,{size:"sm",variant:"outline",className:"min-w-0 justify-start px-2 text-xs",onClick:()=>ve(i),children:[e.jsx(tt,{className:"mr-1.5 h-3.5 w-3.5 shrink-0"})," ",e.jsx("span",{className:"truncate",children:"Deposit"})]}),e.jsxs(N,{size:"sm",variant:"outline",className:"min-w-0 justify-start px-2 text-xs",onClick:()=>H(i),children:[e.jsx(rt,{className:"mr-1.5 h-3.5 w-3.5 shrink-0 text-success"})," ",e.jsx("span",{className:"truncate",children:"Mark sold"})]}),e.jsxs(N,{size:"sm",variant:"outline",className:"min-w-0 justify-start px-2 text-xs",onClick:()=>ge(i),children:[i.featured?e.jsx(ct,{className:"mr-1.5 h-3.5 w-3.5 shrink-0 fill-current text-warning"}):e.jsx(lt,{className:"mr-1.5 h-3.5 w-3.5 shrink-0"}),e.jsx("span",{className:"truncate",children:i.featured?"Featured":"Feature"})]}),e.jsxs(N,{size:"sm",variant:"outline",className:"min-w-0 justify-start px-2 text-xs",onClick:()=>{O(i),u(!0)},children:[e.jsx(nt,{className:"mr-1.5 h-3.5 w-3.5 shrink-0"})," ",e.jsx("span",{className:"truncate",children:"Edit"})]}),e.jsxs(N,{size:"sm",variant:"outline",className:"min-w-0 justify-start px-2 text-xs text-destructive hover:text-destructive",onClick:()=>oe(i.id),children:[e.jsx(be,{className:"mr-1.5 h-3.5 w-3.5 shrink-0"})," ",e.jsx("span",{className:"truncate",children:"Delete"})]})]})]},i.id))}),e.jsx("div",{className:"hidden overflow-hidden rounded-2xl border border-border bg-card shadow-card md:block",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-muted/50 text-left text-xs uppercase tracking-wide text-muted-foreground",children:e.jsxs("tr",{children:[e.jsx("th",{className:"p-3",children:"Car"}),e.jsx("th",{className:"p-3",children:"Year"}),e.jsx("th",{className:"p-3",children:"Price"}),e.jsx("th",{className:"p-3",children:"Views"}),e.jsx("th",{className:"p-3",children:"Status"}),e.jsx("th",{className:"p-3 text-right",children:"Actions"})]})}),e.jsx("tbody",{children:te.map(i=>e.jsxs("tr",{className:"border-t border-border",children:[e.jsx("td",{className:"p-3",children:e.jsxs("div",{className:"flex items-center gap-3",children:[i.image_url&&e.jsx("img",{src:i.image_url,alt:"",className:"h-12 w-16 rounded-md object-cover"}),e.jsxs("div",{children:[e.jsxs("div",{className:"font-medium",children:[i.make," ",i.model]}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[i.stock_number&&e.jsxs("span",{className:"font-mono",children:["#",i.stock_number," · "]}),i.body_type," · ",i.transmission]}),i.reserved_for_name&&e.jsxs("div",{className:"text-[11px] text-muted-foreground",children:["Reserved for ",e.jsx("span",{className:"font-medium text-foreground",children:i.reserved_for_name}),i.deposit_amount?e.jsxs(e.Fragment,{children:[" · deposit £",Number(i.deposit_amount).toLocaleStr
1ing()]}):null]})]})]})}),e.jsx("td",{className:"p-3",children:i.year}),e.jsxs("td",{className:"p-3",children:["£",Number(i.price).toLocaleString()]}),e.jsxs("td",{className:"p-3",children:[e.jsxs("div",{className:"inline-flex items-center gap-1.5 rounded-full bg-primary/10 px-2 py-0.5 text-xs font-medium text-primary",children:[e.jsx(et,{className:"h-3.5 w-3.5"}),p[i.id]?.total??0,p[i.id]?.unique?e.jsxs("span",{className:"text-muted-foreground",children:["/ ",p[i.id].unique]}):null]}),e.jsx("div",{className:"mt-0.5 text-[10px] text-muted-foreground",children:"total / unique"})]}),e.jsx("td",{className:"p-3",children:e.jsxs(F,{value:i.status,onValueChange:x=>ie(i.id,x),children:[e.jsx(L,{className:"h-8 w-40 capitalize",children:e.jsx($,{})}),e.jsxs(z,{children:[e.jsx(S,{value:"available",children:"Available"}),e.jsx(S,{value:"reserved",children:"Reserved"}),e.jsx(S,{value:"deposit_taken",children:"Deposit taken"}),e.jsx(S,{value:"pending_collection",children:"Pending collection"}),e.jsx(S,{value:"sold",children:"Sold"}),e.jsx(S,{value:"withdrawn",children:"Withdrawn"})]})]})}),e.jsx("td",{className:"p-3",children:e.jsxs("div",{className:"flex flex-wrap justify-end gap-1.5",children:[e.jsxs(N,{size:"sm",variant:"outline",className:"h-8 px-2 text-xs",onClick:()=>X(i),children:[e.jsx(at,{className:"mr-1 h-3.5 w-3.5"})," Reserve"]}),e.jsxs(N,{size:"sm",variant:"outline",className:"h-8 px-2 text-xs",onClick:()=>ve(i),children:[e.jsx(tt,{className:"mr-1 h-3.5 w-3.5"})," Deposit"]}),e.jsxs(N,{size:"sm",variant:"outline",className:"h-8 px-2 text-xs",onClick:()=>H(i),children:[e.jsx(rt,{className:"mr-1 h-3.5 w-3.5 text-success"})," Sold"]}),e.jsxs(N,{size:"sm",variant:"outline",className:"h-8 px-2 text-xs",onClick:()=>ge(i),children:[i.featured?e.jsx(ct,{className:"mr-1 h-3.5 w-3.5 fill-current text-warning"}):e.jsx(lt,{className:"mr-1 h-3.5 w-3.5"}),i.featured?"Featured":"Feature"]}),e.jsxs(N,{size:"sm",variant:"outline",className:"h-8 px-2 text-xs",onClick:()=>{O(i),u(!0)},children:[e.jsx(nt,{className:"mr-1 h-3.5 w-3.5"})," Edit"]}),e.jsxs(N,{size:"sm",variant:"outline",className:"h-8 px-2 text-xs text-destructive hover:text-destructive",onClick:()=>oe(i.id),children:[e.jsx(be,{className:"mr-1 h-3.5 w-3.5"})," Delete"]})]})})]},i.id))})]})})})]}),e.jsx(qe,{open:!!T,onOpenChange:()=>{},children:e.jsxs(Ye,{className:"max-h-[90vh] max-w-2xl overflow-y-auto",onInteractOutside:i=>i.preventDefault(),onPointerDownOutside:i=>i.preventDefault(),onEscapeKeyDown:i=>i.preventDefault(),children:[e.jsxs(Je,{children:[e.jsx(Xe,{children:"Mark as sold"}),T&&e.jsxs("p",{className:"text-sm text-muted-foreground",children:[T.year," ",T.make," ",T.model," · Listed at £",Number(T.price).toLocaleString()]})]}),e.jsx(ua,{form:M,setForm:re}),e.jsxs(Ze,{children:[e.jsx(N,{variant:"outline",onClick:()=>ce(null),children:"Cancel"}),e.jsx(N,{onClick:Ae,className:"bg-gradient-hero",children:"Archive as sold"})]})]})})]})}function da({car:t,setCar:s}){const n=(r,d)=>s({...t,[r]:d}),[o,a]=l.useState(!1);async function c(r){const d=r.target.files?.[0];if(!d)return;a(!0);const m=d.name.split(".").pop()?.toLowerCase()||"jpg",u=`inventory/${Date.now()}-${Math.random().toString(36).slice(2,8)}.${m}`,{error:p}=await w.storage.from("car-photos").upload(u,d,{upsert:!1});if(p){y.error("Upload failed"),a(!1);return}const h=w.storage.from("car-photos").getPublicUrl(u).data.publicUrl;n("image_url",h),a(!1),y.success("Photo uploaded")}return e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx(f,{children:"Make"}),e.jsx(v,{value:t.make??"",onChange:r=>n("make",r.target.value)})]}),e.jsxs("div",{children:[e.jsx(f,{children:"Model"}),e.jsx(v,{value:t.model??"",onChange:r=>n("model",r.target.value)})]}),e.jsxs("div",{children:[e.jsx(f,{children:"Year"}),e.jsx(v,{type:"number",value:t.year??"",onChange:r=>n("year",Number(r.target.value))})]}),e.jsxs("div",{children:[e.jsx(f,{children:"Price (£)"}),e.jsx(v,{type:"number",value:t.price??"",onChange:r=>n("price",Number(r.target.value))})]}),e.jsxs("div",{children:[e.jsxs(f,{children:["Purchase price (£) ",e.jsx("span",{className:"text-xs text-muted-foreground",children:"â what you paid"})]}),e.jsx(v,{type:"number",value:t.purchase_price??"",onChange:r=>n("purchase_price",r.target.value===""?null:Number(r.target.value)),placeholder:"Used for profit stats"})]}),e.jsxs("div",{children:[e.jsx(f,{children:"Mileage"}),e.jsx(v,{type:"number",value:t.mileage??"",onChange:r=>n("mileage",Number(r.target.value))})]}),e.jsxs("div",{children:[e.jsx(f,{children:"Color"}),e.jsx(v,{value:t.color??"",onChange:r=>n("color",r.target.value)})]}),e.jsxs("div",{children:[e.jsx(f,{children:"Fuel"}),e.jsxs(F,{value:t.fuel_type,onValueChange:r=>n("fuel_type",r),children:[e.jsx(L,{children:e.jsx($,{})}),e.jsx(z,{children:["Petrol","Diesel","Hybrid","Electric"].map(r=>e.jsx(S,{value:r,children:r},r))})]})]}),e.jsxs("div",{children:[e.jsx(f,{children:"Transmission"}),e.jsxs(F,{value:t.transmission,onValueChange:r=>n("transmission",r),children:[e.jsx(L,{children:e.jsx($,{})}),e.jsx(z,{children:["Manual","Automatic"].map(r=>e.jsx(S,{value:r,children:r},r))})]})]}),e.jsxs("div",{children:[e.jsx(f,{children:"Body type"}),e.jsxs(F,{value:t.body_type,onValueChange:r=>n("body_type",r),children:[e.jsx(L,{children:e.jsx($,{})}),e.jsx(z,{children:["Hatchback","Saloon","Estate","SUV","Coupe","Convert
1ible","MPV","Van"].map(r=>e.jsx(S,{value:r,children:r},r))})]})]}),e.jsxs("div",{children:[e.jsx(f,{children:"Status"}),e.jsxs(F,{value:t.status,onValueChange:r=>n("status",r),children:[e.jsx(L,{children:e.jsx($,{})}),e.jsx(z,{children:["available","reserved","deposit_taken","pending_collection","sold","withdrawn"].map(r=>e.jsx(S,{value:r,className:"capitalize",children:r.replace("_"," ")},r))})]})]}),e.jsxs("div",{className:"sm:col-span-2",children:[e.jsx(f,{children:"Photo"}),e.jsx(v,{type:"file",accept:"image/*",onChange:c,disabled:o}),o&&e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Uploadingâ¦"}),t.image_url&&e.jsx("img",{src:t.image_url,alt:"Car",className:"mt-3 h-40 w-full rounded-lg border border-border object-cover"})]}),e.jsxs("div",{className:"sm:col-span-2",children:[e.jsx(f,{children:"Original listing URL (optional)"}),e.jsx(v,{type:"url",placeholder:"https://...",value:t.autotrader_url??"",onChange:r=>n("autotrader_url",r.target.value)}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:'Adds a "View original listing" button on the car page.'})]}),e.jsx("div",{className:"sm:col-span-2 mt-2 border-t border-border pt-4",children:e.jsx("h3",{className:"font-display text-sm font-semibold uppercase tracking-wide text-muted-foreground",children:"Identity"})}),e.jsxs("div",{className:"sm:col-span-2",children:[e.jsx(f,{children:"Variant / Trim"}),e.jsx(v,{value:t.variant??"",onChange:r=>n("variant",r.target.value),placeholder:"1.4i 16v Turbo Elite Nav"})]}),e.jsxs("div",{children:[e.jsx(f,{children:"Registration"}),e.jsx(v,{value:t.registration??"",onChange:r=>n("registration",r.target.value),placeholder:"CY18 NWN"})]}),e.jsxs("div",{children:[e.jsx(f,{children:"Registration date"}),e.jsx(v,{type:"date",value:t.registration_date??"",onChange:r=>n("registration_date",r.target.value)})]}),e.jsxs("div",{children:[e.jsx(f,{children:"Stock number"}),e.jsx(v,{value:t.stock_number??"",onChange:r=>n("stock_number",r.target.value)})]}),e.jsxs("div",{children:[e.jsx(f,{children:"Location"}),e.jsx(v,{value:t.location??"",onChange:r=>n("location",r.target.value),placeholder:"Birmingham"})]}),e.jsx("div",{className:"sm:col-span-2 mt-2 border-t border-border pt-4",children:e.jsx("h3",{className:"font-display text-sm font-semibold uppercase tracking-wide text-muted-foreground",children:"Engine & performance"})}),e.jsxs("div",{children:[e.jsx(f,{children:"Engine"}),e.jsx(v,{value:t.engine??"",onChange:r=>n("engine",r.target.value),placeholder:"I4 Petrol"})]}),e.jsxs("div",{children:[e.jsx(f,{children:"Engine size (L)"}),e.jsx(v,{type:"number",step:"0.1",value:t.engine_size??"",onChange:r=>n("engine_size",r.target.value===""?null:Number(r.target.value))})]}),e.jsxs("div",{children:[e.jsx(f,{children:"Horsepower (HP)"}),e.jsx(v,{type:"number",value:t.horsepower??"",onChange:r=>n("horsepower",r.target.value===""?null:Number(r.target.value))})]}),e.jsxs("div",{children:[e.jsx(f,{children:"Drivetrain"}),e.jsxs(F,{value:t.drivetrain??"",onValueChange:r=>n("drivetrain",r),children:[e.jsx(L,{children:e.jsx($,{placeholder:"Select"})}),e.jsx(z,{children:["Front-wheel drive","Rear-wheel drive","All-wheel drive","Four-wheel drive"].map(r=>e.jsx(S,{value:r,children:r},r))})]})]}),e.jsxs("div",{children:[e.jsx(f,{children:"Doors"}),e.jsx(v,{type:"number",value:t.doors??"",onChange:r=>n("doors",r.target.value===""?null:Number(r.target.value))})]}),e.jsxs("div",{children:[e.jsx(f,{children:"Seats"}),e.jsx(v,{type:"number",value:t.seats??"",onChange:r=>n("seats",r.target.value===""?null:Number(r.target.value))})]}),e.jsx("div",{className:"sm:col-span-2 mt-2 border-t border-border pt-4",children:e.jsx("h3",{className:"font-display text-sm font-semibold uppercase tracking-wide text-muted-foreground",children:"Fuel economy & emissions"})}),e.jsxs("div",{children:[e.jsx(f,{children:"Combined MPG"}),e.jsx(v,{type:"number",step:"0.1",value:t.mpg_combined??"",onChange:r=>n("mpg_combined",r.target.value===""?null:Number(r.target.value))})]}),e.jsxs("div",{children:[e.jsx(f,{children:"City MPG"}),e.jsx(v,{type:"number",step:"0.1",value:t.mpg_city??"",onChange:r=>n("mpg_city",r.target.value===""?null:Number(r.target.value))})]}),e.jsxs("div",{children:[e.jsx(f,{children:"Highway MPG"}),e.jsx(v,{type:"number",step:"0.1",value:t.mpg_highway??"",onChange:r=>n("mpg_highway",r.target.value===""?null:Number(r.target.value))})]}),e.jsxs("div",{children:[e.jsx(f,{children:"Fuel tank (L)"}),e.jsx(v,{type:"number",step:"0.1",value:t.fuel_tank_size??"",onChange:r=>n("fuel_tank_size",r.target.value===""?null:Number(r.target.value))})]}),e.jsxs("div",{children:[e.jsx(f,{children:"COâ emissions (g/km)"}),e.jsx(v,{type:"number",value:t.co2_emissions??"",onChange:r=>n("co2_emissions",r.target.value===""?null:Number(r.target.value))})]}),e.jsxs("div",{children:[e.jsx(f,{children:"ULEZ compliant"}),e.jsxs(F,{value:t.ulez_compliant===!0?"yes":t.ulez_compliant===!1?"no":"",onValueChange:r=>n("ulez_compliant",r==="yes"?!0:r==="no"?!1:null),children:[e.jsx(L,{children:e.jsx($,{placeholder:"Unknown"})}),e.jsxs(z,{children:[e.jsx(S,{value:"yes",children:"Yes"}),e.jsx(S,{value:"no",children:"No"})]})]})]}),e.jsx("div",{className:"sm:col-span-2 mt-2 border-t border-border pt-4",children:e.jsx("h3",{className:"font-display text-sm font-semibold uppercase tracking-wide text-muted-foreground",children:"History"})}),e.jsxs("div",{children:[e.jsx(f,{children:"MOT expiry"}),e.jsx(v,{type:"date",value:t.mot_expiry??"",onChange:r=>n("mot_expiry",r.target.value)})]}),e.jsxs("div",{children:[e.jsx(f,{children:"Previous owners"}),e.jsx(v,{type:"number",value:t.previous_owners??"",onChange:r=>n("previous_owners",r.target.value===""?null:Number(r.target.value))})]}),e.jsx("div",{className:"sm:col-span-2 mt-2 border-t border-border pt-4",children:e.jsx("h3",{className:"font-display text-sm font-semibold uppercase tracking-wide text-muted-foreground",children:"Dimensions (mm)"})}),e.jsxs("div",{children:[e.jsx(f,{children:"Length"}),e.jsx(v,{type:"number",value:t.length_mm??"",onChange:r=>n("length_mm",r.target.value===""?null:Number(r.target.value))})]}),e.jsxs("div",{children:[e.jsx(f,{children:"Width"}),e.jsx(v,{type:"number",value:t.width_mm??"",onChange:r=>n("width_mm",r.target.value===""?null:Number(r.target.value))})]}),e.jsxs("div",{children:[e.jsx(f,{children:"Height"}),e.jsx(v,{type:"number",value:t.height_mm??"",onChange:r=>n("height_mm",r.target.value===""?null:Number(r.target.value))})]}),e.jsxs("div",{children:[e.jsx(f,{children:"Wheelbase"}),e.jsx(v,{type:"number",value:t.wheelbase_mm??"",onChange:r=>n("wheelbase_mm",r.target.value===""?null:Number(r.target.value))})]}),e.jsx("div",{className:"sm:col-span-2 mt-2 border-t border-border pt-4",children:e.jsx("h3",{className:"font-display text-sm font-semibold uppercase tracking-wide text-muted-foreground",children:"Features & options"})}),e.jsxs("div",{className:"sm:col-span-2",children:[e.jsx(f,{children:"Features (one per line)"}),e.jsx(we,{rows:5,value:(t.features??[]).join(` 2`),onChange:r=>n("features",r.target.value.split(` 3`).map(d=>
3d.trim()).filter(Boolean)),placeholder:`Bluetooth 4Heated seats 5Sat nav 6Reversing camera`}),e.jsxs("p",{className:"mt-1 text-xs text-muted-foreground",children:[(t.features??[]).length," feature(s)"]})]}),e.jsx("div",{className:"sm:col-span-2 mt-2 border-t border-border pt-4"}),e.jsxs("div",{className:"sm:col-span-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(f,{children:"Description"}),e.jsx(xa,{car:t,onResult:r=>n("description",r)})]}),e.jsx(we,{rows:6,value:t.description??"",onChange:r=>n("description",r.target.value)})]}),e.jsxs("label",{className:"flex items-center gap-2 sm:col-span-2",children:[e.jsx("input",{type:"checkbox",checked:!!t.featured,onChange:r=>n("featured",r.target.checked)}),e.jsx("span",{className:"text-sm",children:"Featured on homepage"})]}),e.jsxs("div",{className:"sm:col-span-2 mt-2 border-t border-border pt-4",children:[e.jsx("h3",{className:"font-display text-sm font-semibold uppercase tracking-wide text-muted-foreground",children:"Special offer"}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Show an attention-grabbing banner and price comparison on this car."})]}),e.jsxs("label",{className:"flex items-center gap-2 sm:col-span-2",children:[e.jsx("input",{type:"checkbox",checked:!!t.offer_active,onChange:r=>n("offer_active",r.target.checked)}),e.jsx("span",{className:"text-sm",children:"Enable special offer banner"})]}),e.jsxs("div",{className:"sm:col-span-2",children:[e.jsx(f,{children:"Banner label"}),e.jsxs(F,{value:t.offer_label??"",onValueChange:r=>n("offer_label",r),children:[e.jsx(L,{children:e.jsx($,{placeholder:"Choose a preset or type a custom label below"})}),e.jsx(z,{children:["Special Offer","Limited Time Offer","Manager's Special","5% Discount","10% Discount","15% Discount","20% Discount","25% Discount","Save £250","Save £500","Save £750","Save £1,000","Save £1,500","Save £2,000","Below Market Value","Weekend Deal","Deal of the Week","Deal of the Month","Price Just Dropped","New Lower Price","Reduced Today","Final Reduction","Clearance Price","Last One at This Price","Only One Left","Hot Deal","Star Buy","Best Value in Stock","Staff Pick","Owner's Favourite","Great First Car","Family Favourite","Low Mileage Bargain","One Owner from New","Full Service History","Just Serviced & MOT'd","12 Months MOT Included","Free 6-Month Warranty","Free 12-Month Warranty","Free Home Delivery","Free Local Delivery","Free Full Valet","Free First Service","Free MOT for Life","Free Set of Mats","Free Fuel Tank","Free 7-Day Insurance","£99 Deposit Deal","Low Deposit Available","Part Exchange Welcome","Extra for Your Part Exchange","£500 Part Exchange Bonus","Trade-In Bonus","Drive Away Today","Ready to Drive Away","ULEZ Compliant Bargain","Low Road Tax","Cheap to Insure","Electric Saver Deal","Hybrid Saver Deal","Bank Holiday Special","Payday Special","End of Month Special","New Year Deal","Spring Sale","Summer Sale","Autumn Sale","Winter Sale","Black Friday Deal","Christmas Special","Birthday Sale","Anniversary Special","Ramadan Special","Eid Special","Diwali Special","Sale Now On","Priced to Sell","Must Go This Week","Make Me an Offer","Offers Invited"].map(r=>e.jsx(S,{value:r,children:r},r))})]}),e.jsx(v,{className:"mt-2",placeholder:"Or custom label (e.g. â£750 offâ)",value:t.offer_label??"",onChange:r=>n("offer_label",r.target.value)})]}),e.jsxs("div",{children:[e.jsx(f,{children:"Market value / original price (£)"}),e.jsx(v,{type:"number",placeholder:"e.g. 12500",value:t.market_price??"",onChange:r=>n("market_price",r.target.value===""?null:Number(r.target.value))}),e.jsxs("p",{className:"mt-1 text-xs text-muted-foreground",children:["Used to show the savings graph. Set to £",Number(t.price??0).toLocaleString()," + your discount."]})]}),e.jsxs("div",{children:[e.jsx(f,{children:"Offer expires (optional)"}),e.jsx(v,{type:"datetime-local",value:t.offer_expires_at?new Date(t.offer_expires_at).toISOString().slice(0,16):"",onChange:r=>n("offer_expires_at",r.target.value||null)}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Banner shows a live countdown."})]}),t.offer_active&&Number(t.market_price)>Number(t.price??0)&&e.jsxs("div",{className:"sm:col-span-2 rounded-lg border border-destructive/30 bg-destructive/5 p-3 text-sm",children:[e.jsx("strong",{className:"text-destructive",children:"Preview:"}
6)," Buyers will see they save"," ",e.jsxs("strong",{children:["£",(Number(t.market_price)-Number(t.price??0)).toLocaleString()]})," ","(",Math.round((Number(t.market_price)-Number(t.price??0))/Number(t.market_price)*100),"% off)."]})]})}function ua({form:t,setForm:s}){const n=(a,c)=>s({...t,[a]:c}),o=(()=>{const a=parseFloat(t.sold_price),c=parseFloat(t.purchase_price),r=parseFloat(t.prep_cost),d=t.part_ex_taken?parseFloat(t.part_ex_value):0;return!Number.isFinite(a)||!Number.isFinite(c)?null:a-c-(Number.isFinite(r)?r:0)-(Number.isFinite(d)?d:0)})();return e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsx("div",{className:"sm:col-span-2 -mb-2",children:e.jsx("h3",{className:"font-display text-sm font-semibold uppercase tracking-wide text-muted-foreground",children:"Sale"})}),e.jsxs("div",{children:[e.jsx(f,{children:"Sold price (£) *"}),e.jsx(v,{type:"number",value:t.sold_price,onChange:a=>n("sold_price",a.target.value)})]}),e.jsxs("div",{children:[e.jsx(f,{children:"Sold date"}),e.jsx(v,{type:"date",value:t.sold_at,onChange:a=>n("sold_at",a.target.value)})]}),e.jsxs("div",{children:[e.jsxs(f,{children:["Purchase price (£) ",e.jsx("span",{className:"text-xs text-muted-foreground",children:"â what you paid"})]}),e.jsx(v,{type:"number",value:t.purchase_price,onChange:a=>n("purchase_price",a.target.value)})]}),e.jsxs("div",{children:[e.jsx(f,{children:"Prep / reconditioning cost (£)"}),e.jsx(v,{type:"number",value:t.prep_cost,onChange:a=>n("prep_cost",a.target.value)})]}),e.jsxs("div",{children:[e.jsxs(f,{children:["Payment method ",e.jsx("span",{className:"text-xs text-muted-foreground",children:"â e.g. Cash, Card, Bank transfer"})]}),e.jsx(v,{value:t.payment_method,onChange:a=>n("payment_method",a.target.value),placeholder:"Type payment method (e.g. Cash, Card, Bank transfer, Finance)"})]}),e.jsxs("div",{children:[e.jsx(f,{children:"Lead source"}),e.jsxs(F,{value:t.lead_source,onValueChange:a=>n("lead_source",a),children:[e.jsx(L,{children:e.jsx($,{placeholder:"Where did the customer come from?"})}),e.jsx(z,{children:["Website","Walk-in","AutoTrader","CarGurus","AA Cars","Facebook","Instagram","Google","Referral","Phone","Repeat customer","Other"].map(a=>e.jsx(S,{value:a,children:a},a))})]})]}),o!==null&&e.jsxs("div",{className:"sm:col-span-2 rounded-lg border border-border bg-muted/30 px-3 py-2 text-sm",children:["Estimated gross profit: ",e.jsxs("span",{className:o>=0?"font-semibold text-primary":"font-semibold text-destructive",children:["£",o.toLocaleString(void 0,{maximumFractionDigits:0})]}),e.jsx("span",{className:"ml-1 text-xs text-muted-foreground",children:"(sold â purchase â prep â part-ex)"})]}),e.jsx("div",{className:"sm:col-span-2 mt-2 border-t border-border pt-4",children:e.jsx("h3",{className:"font-display text-sm font-semibold uppercase tracking-wide text-muted-foreground",children:"Customer"})}),e.jsxs("div",{children:[e.jsx(f,{children:"Customer name"}),e.jsx(v,{value:t.customer_name,onChange:a=>n("customer_name",a.target.value)})]}),e.jsxs("div",{children:[e.jsx(f,{children:"Phone"}),e.jsx(v,{value:t.customer_phone,onChange:a=>n("customer_phone",a.target.value)})]}),e.jsxs("div",{children:[e.jsx(f,{children:"Email"}),e.jsx(v,{type:"email",value:t.customer_email,onChange:a=>n("customer_email",a.target.value)})]}),e.jsxs("div",{children:[e.jsxs(f,{children:["Postcode ",e.jsx("span",{className:"text-xs text-muted-foreground",children:"â powers geography stats"})]}),e.jsx(v,{value:t.customer_postcode,onChange:a=>n("customer_postcode",a.target.value.toUpperCase()),placeholder:"B19 1ES"})]}),e.jsx("div",{className:"sm:col-span-2 mt-2 border-t border-border pt-4",children:e.jsx("h3",{className:"font-display text-sm font-semibold uppercase tracking-wide text-muted-foreground",children:"Part-exchange"})}),e.jsxs("div",{className:"sm:col-span-2 flex items-center gap-2",children:[e.jsx("input",{id:"px-taken",type:"checkbox",checked:t.part_ex_taken,onChange:a=>n("part_ex_taken",a.target.checked),className:"h-4 w-4"}),e.jsx(f,{htmlFor:"px-taken",className:"cursor-pointer",children:"Customer part-exchanged a vehicle"})]}),t.part_ex_taken&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx(f,{children:"Part-ex value (£)"}),e.jsx(v,{type:"number",value:t.part_ex_value,onChange:a=>n("part_ex_value",a.target.value)})]}),e.jsxs("div",{children:[e.jsx(f,{children:"Part-ex registration"}),e.jsx(v,{value:t.part_ex_registration,onChange:a=>n("part_ex_registration",a.target.value.toUpperCase())})]})]}),e.jsx("div",{className:"sm:col-span-2 mt-2 border-t border-border pt-4",children:e.jsx("h3",{className:"font-display text-sm font-semibold uppercase tracking-wide text-muted-foreground",children:"Other"})}),e.jsxs("div",{children:[e.jsx(f,{children:"Salesperson"}),e.jsx(v,{value:t.salesperson,onChange:a=>n("salesperson",a.target.value),placeholder:"Handled by"})]}),e.jsxs("div",{className:"sm:col-span-2",children:[e.jsx(f,{children:"Notes"}),e.jsx(we,{rows:3,value:t.notes,onChange:a=>n("notes",a.target.value)})]})]})}function ma(){const[t,s]=l.useState([]),[n,o]=l.useState(!0);async function a(){o(!0);const{data:d}=await w.from("car_submissions").select("*").order("created_at",{ascending:!1});s(d??[]),o(!1)}l.useEffect(()=>{a()},[]);async function c(d,m){await w.from("car_submissions").update({status:m}).eq("id",d),y.success("Status updated"),a()}async function r(d){confirm("Delete this submission?")&&(await w.from("car_submissions").delete().eq("id",d),a())}return n?e.jsx("p",{className:"py-12 text-center text-muted-foreground",children:"Loadingâ¦"}):t.length===0?e.jsx("p",{className:"py-12 text-center text-muted-foreground",children:"No submissions yet."}):e.jsx("div",{className:"grid gap-4",children:t.map(d=>e.jsx("article",{className:"rounded-2xl border border-border bg-card p-6 shadow-card",children:e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("h3",{className:"font-display text-lg font-semibold",children:[d.year," ",d.make," ",d.model]}),e.jsx(Br,{className:"capitalize",variant:d.status==="accepted"?"default":d.status==="rejected"?"destructive":"secondary",children:d.status})]}),e.jsxs("p",{className:"mt-1 text-sm text-muted-foreground",children:[d.mileage.toLocaleStr
6ing()," mi · ",d.condition," ·"," ",d.asking_price?`Asking £${Number(d.asking_price).toLocaleString()}`:"No asking price"]}),e.jsxs("p",{className:"mt-3 text-sm",children:[e.jsx("span",{className:"font-medium",children:d.seller_name})," · "," ",e.jsx("a",{href:`mailto:${d.seller_email}`,className:"text-primary hover:underline",children:d.seller_email})," · "," ",e.jsx("a",{href:`tel:${d.seller_phone}`,className:"text-primary hover:underline",children:d.seller_phone})]}),d.description&&e.jsx("p",{className:"mt-3 text-sm text-muted-foreground",children:d.description}),e.jsxs("p",{className:"mt-3 text-xs text-muted-foreground",children:["Submitted ",new Date(d.created_at).toLocaleString("en-GB")]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(F,{value:d.status,onValueChange:m=>c(d.id,m),children:[e.jsx(L,{className:"w-36",children:e.jsx($,{})}),e.jsx(z,{children:["pending","reviewed","accepted","rejected"].map(m=>e.jsx(S,{value:m,className:"capitalize",children:m},m))})]}),e.jsx(N,{size:"icon",variant:"ghost",onClick:()=>r(d.id),children:e.jsx(be,{className:"h-4 w-4 text-destructive"})})]})]})},d.id))})}function pa(){const[t,s]=l.useState(""),[n,o]=l.useState(""),[a,c]=l.useState(!1);async function r(d){if(d.preventDefault(),t.length<8){y.error("Password must be at least 8 characters");return}if(t!==n){y.error("Passwords do not match");return}c(!0);const{error:m}=await w.auth.updateUser({password:t});if(c(!1),m){y.error(m.message);return}s(""),o(""),y.success("Password updated")}return e.jsxs("div",{className:"max-w-md rounded-2xl border border-border bg-card p-6 shadow-sm",children:[e.jsx("h2",{className:"font-display text-xl font-bold",children:"Change password"}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"Use at least 8 characters. You'll stay signed in."}),e.jsxs("form",{onSubmit:r,className:"mt-5 space-y-4",children:[e.jsxs("div",{children:[e.jsx(f,{htmlFor:"np",children:"New password"}),e.jsx(v,{id:"np",type:"password",value:t,onChange:d=>s(d.target.value),required:!0,minLength:8})]}),e.jsxs("div",{children:[e.jsx(f,{htmlFor:"cp",children:"Confirm new password"}),e.jsx(v,{id:"cp",type:"password",value:n,onChange:d=>o(d.target.value),required:!0,minLength:8})]}),e.jsxs(N,{type:"submit",disabled:a,className:"bg-gradient-hero shadow-elegant",children:[e.jsx(kt,{className:"mr-2 h-4 w-4"}),a?"Updatingâ¦":"Update password"]})]})]})}function ha({onImported:t}){const[s,n]=l.useState(""),[o,a]=l.useState(!1);async function c(){if(!/^https?:\/\//i.test(s.trim())){y.error("Paste a full https:// listing URL");return}if(/autotrader\.co\.uk/i.test(s)){y.error("AutoTrader blocks scraping. Use a different listing source (e.g. CarGurus, Motors, eBay Motors, dealer site).");return}a(!0);try{const{data:r}=await w.auth.getSession(),d=r.session?.access_token,m=await fetch("/api/admin/import-autotrader",{method:"POST",headers:{"Content-Type":"application/json",...d?{Authorization:`Bearer ${d}`}:{}},body:JSON.stringify({url:s.trim()})}),u=await m.json().catch(()=>({}));if(!m.ok||!u.ok){y.error(u.error||"Import failed");return}const p=u.car;t({make:p.make,model:p.model,year:p.year,price:p.price,mileage:p.mileage,fuel_type:p.fuel_type,transmission:p.transmission,body_type:p.body_type,color:p.color??"",description:p.description??"",image_url:p.image_url??"",gallery_urls:p.gallery_urls??[],autotrader_url:s.trim()}),y.success(`Imported · ${p.photos_imported}
6/${p.photos_found} photos copied to your storage`)}catch(r){y.error(r instanceof Error?r.message:"Import failed")}finally{a(!1)}}return e.jsxs("div",{className:"mb-4 rounded-xl border border-dashed border-border bg-muted/30 p-4",children:[e.jsx(f,{className:"text-sm font-semibold",children:"Import from listing URL"}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Paste a full listing URL (CarGurus, Motors, eBay Motors, dealer site, etc.). AutoTrader is not supported â they block scraping. Photos are copied to your storage (5â15 sec)."}),e.jsxs("div",{className:"mt-3 flex gap-2",children:[e.jsx(v,{placeholder:"https://...",value:s,onChange:r=>n(r.target.value),disabled:o}),e.jsxs(N,{type:"button",onClick:c,disabled:o||!s,children:[e.jsx(Xr,{className:"mr-2 h-4 w-4"}),o?"Importingâ¦":"Import"]})]})]})}function xa({car:t,onResult:s}){const[n,o]=l.useState(!1);async function a(){if(!t.make||!t.model){y.error("Fill at least Make and Model first.");return}o(!0);try{const{data:c}=await w.auth.getSession(),r=c.session?.access_token,d=await fetch("/api/admin/generate-description",{method:"POST",headers:{"Content-Type":"application/json",...r?{Authorization:`Bearer ${r}`}:{}},body:JSON.stringify({car:t})}),m=await d.json().catch(()=>({}));if(!d.ok||!m.ok){y.error(m.error||"AI failed");return}s(m.description||""),y.success("Description generated")}catch(c){y.error(c instanceof Error?c.message:"AI failed")}finally{o(!1)}}return e.jsxs(N,{type:"button",size:"sm",variant:"outline",onClick:a,disabled:n,children:[e.jsx(pt,{className:"mr-2 h-4 w-4"}),n?"Generatingâ¦":"AI description"]})}function fa(){const[t,s]=l.useState({business_info:"",warranty_info:"",delivery_info:"",extras_info:""}),[n,o]=l.useState(!0),[a,c]=l.useState(!1);l.useEffect(()=>{(async()=>{const{data:m}=await w.from("dealer_settings").select("*").order("created_at",{ascending:!0}).limit(1).maybeSingle();m&&s({id:m.id,business_info:m.business_info??"",warranty_info:m.warranty_info??"",delivery_info:m.delivery_info??"",extras_info:m.extras_info??""}),o(!1)})()},[]);async function r(){c(!0);const m={business_info:t.business_info,warranty_info:t.warranty_info,delivery_info:t.delivery_info,extras_info:t.extras_info},{error:u}=t.id?await w.from("dealer_settings").update(m).eq("id",t.id):await w.from("dealer_settings").insert(m);if(c(!1),u){y.error(u.message);return}y.success("Dealer info saved")}if(n)return e.jsx("p",{className:"py-12 text-center text-muted-foreground",children:"Loadingâ¦"});const d=(m,u,p)=>e.jsxs("div",{children:[e.jsx(f,{children:m}),e.jsx(we,{rows:5,value:String(t[u]??""),onChange:h=>s({...t,[u]:h.target.value}),placeholder:p})]});return e.jsxs("div",{className:"max-w-3xl rounded-2xl border border-border bg-card p-6 shadow-card",children:[e.jsx("h2",{className:"font-display text-xl font-bold",children:"Dealer standard information"}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"Filled into every AI-generated car description. Keep it concise and factual."}),e.jsxs("div",{className:"mt-6 grid gap-4",children:[d("About the business","business_info","Family-run dealership in Birmingham, established 2008. Hand-picked stock, full HPI checks, finance available."),d("Warranty","warranty_info","All c
6ars sold with 3-month comprehensive warranty as standard. 12-month and 24-month options available."),d("Delivery","delivery_info","Free delivery within 50 miles. Nationwide delivery available from £99. Cars fully prepared and valeted before handover."),d("Extras & aftercare","extras_info","12 months MOT, fresh service, new wiper blades, fuel top-up. Part-exchange welcome. Click & collect.")]}),e.jsx("div",{className:"mt-6 flex justify-end",children:e.jsx(N,{onClick:r,disabled:a,className:"bg-gradient-hero shadow-elegant",children:a?"Savingâ¦":"Save"})})]})}export{Ba as component};
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.