PageSourceSearch

https://carbidder-connect.lovable.app/assets/ApiKeyManagementPage-CDOM3jVY.js

js carbidder-connect.lovable.app collected 2026-10-03 03:24:32 UTC 101,761 bytes, 83 lines download raw bytes

1import{f as En,r as s,s as F,J as P,j as e,z as re,Y as ie,V as Y,aj as Ee,ak as Ae,aq as We,ab as ge,B as U,am as dt,a1 as ws,a2 as ks,q as Ns,t as Ss,a3 as Cs,ac as st,ad as at,ae as rt,af as it,ag as ae,p as pe,A as Dt,a8 as It,au as qt,R as zt,D as Yt,M as Ot,b as He,a as ot,G as An,cu as lt,C as Xt,cz as $s,cn as Pn,cA as Es,cB as As,cC as Ps,cD as Ts,cE as Se,cF as Rs,cG as Ds,cH as Is,cI as Os,cJ as Ls,cK as Ms,bY as Fs,w as q,e as de,at as Us,K as Hs}from"./index-C7rjTsh5.js";import{L as I}from"./label-DEMqrK65.js";import{T as Vs,a as Bs,b as dn,c as me,d as Ws,e as fe}from"./table-DZHnpRRN.js";import{B as xe}from"./badge-Be4waKn8.js";import{D as Ks,d as Gs,a as qs,b as zs,c as Ys,e as Xs}from"./dialog-BqIQ1XMZ.js";import{A as Lt,b as Mt,a as Ft}from"./alert-De4v_MUd.js";import{S as ve}from"./switch-tQfXujs_.js";import{C as ct}from"./checkbox-DBElXt-B.js";import{R as Zs}from"./radio-xCuI6Hmy.js";import{C as Tn}from"./copy-BlVyKajD.js";import{F as Js}from"./flask-conical-BMaf1Nyy.js";import{T as Rn}from"./triangle-alert-CCELUU2A.js";import{E as ut}from"./eye-BmsYy3rY.js";import{L as Qs}from"./link-ChbTYDVl.js";import{U as Dn}from"./user-plus-BV1abdaT.js";import{Z as ea}from"./zap-3Yfir6a9.js";import{C as In}from"./circle-check-DEXR_owX.js";import{T as On}from"./timer-CDpFD_Hr.js";import{C as un}from"./circle-x-CNCJGsDv.js";import{C as Zt}from"./calendar-check-Cx4CwB7-.js";import{P as Xe,a as Ze,b as Je}from"./popover-DBvi-PqK.js";import{S as ta}from"./search-BavRZthq.js";import{S as na}from"./shield-check-Li8bt6ZA.js";import{P as sa}from"./plus-DZ7xOdh4.js";import{E as aa}from"./eye-off-d01S2lhA.js";import{T as ra}from"./trash-2-Dmi-p3qr.js";import{f as _t}from"./format-iV6bfs-r.js";import"./en-US-BzMcWhXf.js";import"./toDate-2Nz3Yi75.js";/**
2 * @license lucide-react v0.555.0 - ISC
3 *
4 * This source code is licensed under the ISC license.
5 * See the LICENSE file in the root directory of this source tree.
6 */const ia=[["path",{d:"m7 15 5 5 5-5",key:"1hf1tw"}],["path",{d:"m7 9 5-5 5 5",key:"sgt6xg"}]],Qe=En("chevrons-up-down",ia);/**
7 * @license lucide-react v0.555.0 - ISC
8 *
9 * This source code is licensed under the ISC license.
10 * See the LICENSE file in the root directory of this source tree.
11 */const oa=[["path",{d:"M18 16.98h-5.99c-1.1 0-1.95.94-2.48 1.9A4 4 0 0 1 2 17c.01-.7.2-1.4.57-2",key:"q3hayz"}],["path",{d:"m6 17 3.13-5.78c.53-.97.1-2.18-.5-3.1a4 4 0 1 1 6.89-4.06",key:"1go1hn"}],["path",{d:"m12 6 3.13 5.73C15.66 12.7 16.9 13 18 13a4 4 0 0 1 0 8",key:"qlwsc0"}]],la=En("webhook",oa);function K(){return K=Object.assign?Object.assign.bind():function(t){for(var n=1;n<arguments.length;n++){var a=arguments[n];for(var r in a)({}).hasOwnProperty.call(a,r)&&(t[r]=a[r])}return t},K.apply(null,arguments)}const jt={enabled:!1,webhookUrl:"",events:{auctionStarted:!0,bidPlaced:!0,endingSoon:!0,auctionEnded:!0,auctionCancelled:!0},includeImages:!0,includeValuations:!0};function ca(){const[t,n]=s.useState(jt),[a,r]=s.useState(!0),[i,o]=s.useState(!1),[d,l]=s.useState(!1),[f,h]=s.useState(!1),[u,v]=s.useState(!1),k="https://ykppdfajqmeqsjxmkcjf.supabase.co/functions/v1/get-live-auctions";s.useEffect(()=>{w()},[]);const w=async()=>{r(!0);try{const{data:y,error:_}=await F.from("auction_settings").select("setting_key, setting_value").in("setting_key",["live_auction_api_enabled","live_auction_webhook_url","live_auction_events","live_auction_include_images","live_auction_include_valuations"]);if(_)throw _;const g={...jt};y==null||y.forEach($=>{const b=$.setting_value;switch($.setting_key){case"live_auction_api_enabled":g.enabled=b===!0||b==="true";break;case"live_auction_webhook_url":g.webhookUrl=typeof b=="string"?b:"";break;case"live_auction_events":typeof b=="object"&&b!==null&&(g.events={...jt.events,...b});break;case"live_auction_include_images":g.includeImages=b!==!1&&b!=="false";break;case"live_auction_include_valuations":g.includeValuations=b!==!1&&b!=="false";break}}),n(g)}catch(y){console.error("Failed to fetch live auction API settings:",y),P.error("Failed to load settings")}finally{r(!1)}},E=async(y,_)=>{const{error:g}=await F.from("auction_settings").upsert({setting_key:y,setting_value:_,updated_at:new Date().toISOString()},{onConflict:"setting_key"});if(g)throw g},m=async()=>{o(!0);try{await Promise.all([E("live_auction_api_enabled",t.enabled),E("live_auction_webhook_url",t.webhookUrl),E("live_auction_events",t.events),E("live_auction_include_images",t.includeImages),E("live_auction_include_valuations",t.includeValuations)]),P.success("Live Auction API settings saved")}catch(y){console.error("Failed to save settings:",y),P.error("Failed to save settings")}finally{o(!1)}},x=async()=>
11{if(!t.webhookUrl){P.error("Please enter a webhook URL first");return}l(!0);try{const y={event_type:"test.connection",external_auction_id:"test-connection-"+Date.now(),timestamp:new Date().toISOString(),message:"This is a test connection from CarSolve Live Auction API"},_=await fetch(t.webhookUrl,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(y)});_.ok?P.success("Test webhook sent successfully!"):P.error(`Webhook test failed: HTTP ${_.status}`)}catch(y){console.error("Webhook test error:",y),P.error("Failed to connect to webhook URL")}finally{l(!1)}},N=async()=>{if(!t.webhookUrl){P.error("Please enter a webhook URL first");return}h(!0);try{const{data:y,error:_}=await F.from("cars").select("*").eq("status","active").gt("end_time",new Date().toISOString());if(_)throw _;if(!y||y.length===0){P.info("No active auctions to push"),h(!1);return}let g=0,$=0;for(const b of y){const R={event_type:"manual.push",external_auction_id:b.id,timestamp:new Date().toISOString(),auction:{external_auction_id:b.id,auction_id:b.id,vin:b.vin,year:b.year,make:b.make,model:b.model,trim:b.trim,mileage:b.mileage,condition:b.condition,exterior_color:b.color,images:t.includeImages?b.images:void 0,starting_bid:b.starting_bid,current_bid:b.current_bid,bid_count:b.bid_count,reserve_met:b.reserve_met,end_time:b.end_time,time_remaining_seconds:Math.max(0,Math.floor((new Date(b.end_time).getTime()-Date.now())/1e3)),valuations:t.includeValuations?{kbb_value:b.kbb_value,kbb_lending:b.kbb_lending_value,kbb_booksheet_url:b.kbb_booksheet_url,mmr:b.mmr_value,acv:b.acv_value,retail:b.retail_value,days_supply:b.days_supply}:void 0,condition_flags:{title_status:b.title_status,accident_history:b.accident_history,airbag_deployed:b.airbag_deployed,is_canadian:b.is_canadian,is_non_runner:b.is_non_runner,has_damage:b.has_damage,has_mechanical_issues:b.has_mechanical_issues},location:{city:b.location_city,state:b.location_state,zip:b.location_zip}}};try{(await fetch(t.webhookUrl,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(R)})).ok?g++:$++}catch{$++}}$===0?P.success(`Successfully pushed ${g} live auction(s)`):P.warning(`Pushed ${g} auction(s), ${$} failed`)}catch(y){console.error("Manual push error:",y),P.error("Failed to push live auctions")}finally{h(!1)}},S=y=>{navigator.clipboard.writeText(y),P.success("Copied to clipboard")};return a?e.jsx(re,{children:e.jsx(ie,{className:"flex items-center justify-center py-8",children:e.jsx(Y,{className:"h-6 w-6 animate-spin text-muted-foreground"})})}):e.jsxs(re,{children:[e.jsxs(Ee,{children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Zs,{className:"h-5 w-5 text-primary"}),e.jsx(Ae,{children:"Live Auction API"})]}),e.jsx(ve,{checked:t.enabled,onCheckedChange:y=>n({...t,enabled:y})})]}),e.jsx(We,{children:"Send real-time auction updates to external platforms"})]}),e.jsxs(ie,{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsx("h4",{className:"font-medium text-sm text-muted-foreground uppercase tracking-wide",children:"Push Notifications"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(I,{htmlFor:"webhook_url",children:"Webhook URL"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(ge,{id:"webhook_url",placeholder:"https://your-platform.com/webhook",value:t.webhookUrl,onChange:y=>n({...t,webhookUrl:y.target.value}),className:"flex-1"}),e.jsx(U,{variant:"outline",onClick:x,disabled:d||!t.webhookUrl,children:d?e.jsx(Y,{className:"h-4 w-4 animate-spin"}):"Test"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(U,{variant:"secondary",onClick:N,disabled:f||!t.webhookUrl,className:"flex items-center gap-2",children:f?e.jsxs(e.Fragment,{children:[e.jsx(Y,{className:"h-4 w-4 animate-spin"}),"Pushing..."]}):e.jsxs(e.Fragment,{children:[e.jsx(dt,{className:"h-4 w-4"}),"Manual Push All Live Auctions"]})}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Push all currently active auctions to the webhook"})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(I,{children:"Events to Send"}),e.jsx("div",{className:"grid grid-cols-2 gap-3",children:[{key:"auctionStarted",label:"Auction Started"},{key:"bidPlaced",label:"Bid Placed"},{key:"endingSoon",label:"Ending Soon"},{key:"auctionEnded",label:"Auction Ended"},{key:"auctionCancelled",label:"Auction Cancelled"}].map(({key:y,label:_})=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(ct,{id:y,checked:t.events[y],onCheckedChange:g=>n({...t,events:{...t.events,[y]:g===!0}})}),e.jsx(I,{htmlFor:y,className:"text-sm font-normal cursor-pointer",children:_})]},y))})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(I,{children:"Data Options"}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(ct,{id:"includeImages",checked:t.includeImages,onCheckedChange:y=>n({...t,includeImages:y===!0})}),e.jsx(I,{htmlFor:"includeImages",className:"text-sm font-normal cursor-pointer",children:"Include vehicle images in payloads"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(ct,{id:"includeValuations",checked:t.includeValuations,onCheckedChange:y=>n({...t,includeValuations:y===!0})}),e.jsx(I,{htmlFor:"includeValuations",className:"text-sm font-normal cursor-pointer",children:"Include valuation data (KBB, MMR, ACV)"})]})]})]})]}),e.jsxs(ws,{open:u,onOpenChange:v,children:[e.jsx(ks,{asChild:!0,children:e.jsxs(U,{variant:"ghost",className:"w-full justify-between p-0 h-auto",children:[e.jsx("span",{className:"font-medium text-sm text-muted-foreground uppercase tracking-wide",children:"Pull Endpoint Documentation"}),u?e.jsx(Ns,{className:"h-4 w-4"}):e.jsx(Ss,{className:"h-4 w-4"})]})}),e.jsxs(Cs,{className:"space-y-4 pt-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(I,{children:"Endpoint"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("code",{className:"flex-1 bg-muted px-3 py-2 rounded text-sm font-mono break-all",children:["GET ",k]}),e.jsx(U,{variant:"outline",size:"icon",onClick:()=>S(k),children:e.jsx(Tn,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(I,{children:"Authentication"}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Include your API key in the"," ",e.jsx("code",{className:"bg-muted px-1 rounded",children:"x-api-key"})," header."]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(I,{children:"Query Parameters"}),e.jsxs("div",{className:"bg-muted rounded p-3 space-y-2 text-sm",children:[e.jsxs("div",{children:[e.jsx("code",{className:"font-mono",children:"updated_since"}),e.jsx("span",{className:"text-muted-foreground ml-2",children:"ISO timestamp for incremental sync"})]}),e.jsxs("div",{children:[e.jsx("code",{className:"font-mono",children:"page"}),e.jsx("span",{className:"text-muted-foreground ml-2",children:"Page number (default: 1)"})]}),e.jsxs("div",{children:[e.jsx("code",{className:"font-mono",children:"limit"}),e.jsx("span",{className:"text-muted-foreground ml-2",children:"Results per page (default: 50, max: 100)"})]}),e.jsxs("div",{children:[e.jsx("code",{className:"font-mono",children:"include_images"}),e.jsx("span",{className:"text-muted-foreground ml-2",children:"Include image URLs (default: true)"})]}),e.jsxs("div",{children:[e.jsx("code",{className:"font-mono",children:"include_valuations"}),e.jsx("span",{className:"text-muted-foreground ml-2",children:"Include KBB/MMR data (default: true)"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(I,{children:"Example Request"}),e.jsx("pre",{className:"bg-muted p-3 rounded text-xs overflow-x-auto",children:`curl -X GET \\
12  "${k}?page=1&limit=25" \\
13  -H "x-api-key: YOUR_API_KEY"`})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(I,{children:"Example Response"}),e.jsx("pre",{className:"bg-muted p-3 rounded text-xs overflow-x-auto max-h-64",children:`{
14  "success": true,
15  "timestamp": "2025-12-17T12:00:00Z",
16  "total_count": 25,
17  "page": 1,
18  "limit": 25,
19  "auctions": [
20    {
21      "auction_id": "uuid",
22      "vin": "1HGCV1F...",
23      "year": 2022,
24      "make": "Honda",
25      "model": "Accord",
26      "trim": "Sport",
27      "mileage": 35000,
28      "condition": "Good",
29      "exterior_color": "White",
30      "images": ["url1", "url2"],
31      "starting_bid": 15000,
32      "current_bid": 18500,
33      "bid_count": 12,
34      "reserve_met": true,
35      "end_time": "2025-12-18T15:00:00Z",
36      "time_remaining_seconds": 86400,
37      "valuations": {
38        "kbb_lending": 19500,
39        "mmr": 18000,
40        "acv": 17500
41      },
42      "condition_flags": {
43        "title_status": "clean",
44        "accident_history": "none"
45      },
46      "location": {
47        "city": "Dallas",
48        "state": "TX"
49      },
50      "auction_url": "https://.../auctions/uuid"
51    }
52  ]
53}`})]})]})]}),e.jsx("div",{className:"flex justify-end pt-4 border-t",children:e.jsx(U,{onClick:m,disabled:i,children:i?e.jsxs(e.Fragment,{children:[e.jsx(Y,{className:"h-4 w-4 mr-2 animate-spin"}),"Saving..."]}):"Save Settings"})})]})]})}const T={carId:"11111111-1111-1111-1111-111111111111",carsolveVehicleId:"cs-veh-22222222-2222-2222-2222-222222222222",bidId:"33333333-3333-3333-3333-333333333333",userId:"44444444-4444-4444-4444-444444444444",dealershipId:"66666666-6666-6666-6666-666666666666",directOfferId:"77777777-7777-7777-7777-777777777777",dealerCounterId:"88888888-8888-8888-8888-888888888888",vin:"CSTESTSYNTH00000001",directOfferVin:"CSTESTSYNTH_DIRECTOFFER_001",dealerCounterVin:"CSTESTSYNTH_DEALERCOUNTER_001",externalId:"sandbox-synth-001",endTime:"2026-06-08T22:00:00.000Z",endTimeMs:17813016e5,eventSequence:17812026e5,bidTimestamp:"2026-06-07T18:29:55.000Z",dealershipName:"Sandbox Motors LLC",contactName:"Sandbox Rep",email:"[email protected]",phone:"+15555550100",address:"100 Test Way, Seattle, WA 98101",logoUrl:"https://cdn.example/logo.png",website:"https://sandbox-motors.example"},Ln=`https://carsolvelive.com/auctions/${T.carId}`;function Mn(){return{dealership_id:T.dealershipId,dealership_name:T.dealershipName,display_name:T.dealershipName,user_id:T.userId,contact_name:T.contactName,email:T.email,phone:T.phone,address:T.address,logo_url:T.logoUrl,website:T.website}}function wt(t,n,a,r,i){return{event:t,event_id:n,event_sequence:T.eventSequence,event_schema_version:"1.1",occurred_at:a,carsolve_vehicle_id:T.carsolveVehicleId,carsolve_id:T.carId,external_id:T.externalId,car_id:T.carId,vin:r,auction_url:Ln,offer:i,dealer:Mn(),_diagnostic:!0}}function da(t,n=new Date().toISOString()){if(t==="auction.live"||t==="sale.finalized"){const a={event_sequence:T.eventSequence,event_schema_version:"1.1",carsolve_vehicle_id:T.carsolveVehicleId,occurred_at:n,carsolve_id:T.carId,external_id:T.externalId,vin:T.vin,starting_bid:1e3,current_bid:8500,bid_count:7,reserve_price:12e3,high_bi
53dder_name:T.dealershipName,end_time:T.endTime,auction_url:Ln,bid:{id:T.bidId,amount:8500,bidder_name:T.dealershipName,placed_at:T.bidTimestamp},_diagnostic:!0};return t==="auction.live"?{event:"auction.live",event_id:`status:${T.carId}:active:${T.endTimeMs}`,...a,status:"active",sale_stage:null,reserve_met:!1,sale_price:null,sold_date:null,winning_dealer:null}:{event:"sale.finalized",event_id:`sale:${T.carId}:sold`,...a,status:"sold",sale_stage:"completed",reserve_met:!0,sale_price:8500,sold_date:n,winning_dealer:Mn()}}if(t==="direct_offer.created"){const a=new Date(new Date(n).getTime()+1728e5).toISOString();return wt("direct_offer.created",`direct_offer:${T.directOfferId}:created`,n,T.directOfferVin,{offer_id:T.directOfferId,offer_type:"direct_offer",amount_cents:2e6,amount_dollars:2e4,currency:"USD",message:"Cash today, no inspection required.",expires_at:a,received_at:n,status:"pending"})}return t==="direct_offer.expired"?wt("direct_offer.expired",`direct_offer:${T.directOfferId}:expired`,n,T.directOfferVin,{offer_id:T.directOfferId,offer_type:"direct_offer",amount_cents:2e6,amount_dollars:2e4,currency:"USD",message:"Cash today, no inspection required.",expires_at:n,received_at:n,status:"expired"}):wt("dealer_counter.created",`dealer_counter:${T.dealerCounterId}:created`,n,T.dealerCounterVin,{offer_id:T.dealerCounterId,offer_type:"dealer_counter",amount_cents:195e4,amount_dollars:19500,currency:"USD",message:null,expires_at:null,received_at:n,status:"pending"})}function ua(){var _;const[t,n]=s.useState("auction.live"),[a,r]=s.useState(""),[i,o]=s.useState(!1),[d,l]=s.useState(!1),[f,h]=s.useState(!1),[u,v]=s.useState(null),[k,w]=s.useState(null),[E,m]=s.useState(null);s.useEffect(()=>()=>{r(""),w(null),v(null)},[]),s.useEffect(()=>{w(null),l(!1),v(null)},[t,a]);const x=s.useMemo(()=>({"Content-Type":"application/json","x-auction-api-key":"••••••••(server-injected by relay)"}),[]),N=(()=>{try{return new URL(a).protocol==="https:"}catch{return!1}})(),S=()=>{if(!N){P.error("Destination URL must be a valid https:// URL");return}const g=new Date().toISOString();m(g),w(da(t,g)),o(!0),l(!1),v(null)},y=async()=>{if(!(!k||!d||!N)){h(!0),v(null);try{const{data:g,error:$}=await F.functions.invoke("synthetic-webhook-relay",{body:{destinationUrl:a,payload:k,authMode:"nexus"}});$?(P.error(`Relay error: ${$.message}`),v({ok:!1,status:0,statusText:$.message,durationMs:0,responseBody:"",networkError:$.message,requestPreview:{destinationHost:"",destinationPath:"",method:"POST",headers:{},bodyBytes:0,authMode:"nexus"}})):(v(g),g!=null&&g.ok?P.success("Synthetic webhook delivered"):P.warning(`Delivered with non-2xx (${g==null?void 0:g.status})`),r(""),w(null),l(!1))}catch(g){const $=g instanceof Error?g.message:String(g);P.error(`Send failed: ${$}`)}finally{h(!1)}}};return e.jsxs(re,{children:[e.jsxs(Ee,{children:[e.jsxs(Ae,{className:"flex items-center gap-2",children:[e.jsx(Js,{className:"h-5 w-5"}),"Synthetic Webhook Diagnostics",e.jsx(xe,{variant:"secondary",children:"Admin only"})]}),e.jsx(We,{children:"Sends one fully synthetic enriched event to a pasted URL. Does not read or mutate any auction records."})]}),e.jsxs(ie,{className:"space-y-4",children:[e.jsxs(Lt,{children:[e.jsx(Rn,{className:"h-4 w-4"}),e.jsx(Mt,{children:"Diagnostic tool"}),e.jsx(Ft,{children:"This sends one synthetic webhook for CarSolve OS capture testing. It does not save settings, does not touch live auctions, and never exposes the Nexus API key (the relay injects it server-side)."})]}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(I,{htmlFor:"synth-event-type",children:"Payload type"}),e.jsxs(st,{value:t,onValueChange:g=>n(g),disabled:f,children:[e.jsx(at,{id:"synth-event-type",children:e.jsx(rt,{})}),e.jsxs(it,{children:[e.jsx(ae,{value:"auction.live",children:"auction.live"}),e.jsx(ae,{value:"sale.finalized",children:"sale.finalized"}),e.jsx(ae,{value:"direct_offer.created",children:"direct_offer.created"}),e.jsx(ae,{value:"direct_offer.expired",children:"direct_offer.expired"}),e.jsx(ae,{value:"dealer_counter.created",children:"dealer_counter.created"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(I,{htmlFor:"synth-dest",children:"Destination URL (sandbox)"}),e.jsx(ge,{id:"synth-dest",type:"url",placeholder:"https://<carsolve-os-host>/functions/v1/auction-webhook",value:a,onChange:g=>r(g.target.value),disabled:f,autoComplete:"off",spellCheck:!1}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Must be https. Host must be on the relay allowlist."})]})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:e.jsxs(U,{type:"button",variant:"outline",onClick:S,disabled:!N||f,children:[e.jsx(ut,{className:"mr-2 h-4 w-4"}),"Generate Preview"]})}),k&&e.jsxs("div",{className:"space-y-3 rounded-md border bg-muted/40 p-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-sm",children:[e.jsx(xe,{variant:"outline",children:"Preview"}),e.jsxs("span",{className:"text-muted-foreground",children:["Generated at ",E]})]}),e.jsxs("div",{className:"space-y-1 text-sm",children:[e.jsxs("div",{children:[e.jsx("span",{className:"font-medium",children:"Destination:"})," ",e.jsx("code",{className:"break-all rounded bg-background px-1.5 py-0.5 text-xs",children:a})]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-medium",children:"Payload type:"})," ",e.jsx("code",{className:"rounded bg-background px-1.5 py-0.5 text-xs",children:t})]})]}),e.jsxs("div",{children:[e.jsx(I,{className:"text-xs",children:"Headers (redacted)"}),e.jsx("pre",{className:"mt-1 overflow-x-auto rounded bg-background p-2 text-xs",children:Object.entries(x).map(([g,$])=>`${g}: ${$}`).join(`
54`)})]}),e.jsxs("div",{children:[e.jsx(I,{className:"text-xs",children:"Body"}),e.jsx("pre",{className:"mt-1 max-h-96 overflow-auto rounded bg-background p-2 text-xs",children:JSON.stringify(k,null,2)})]}),e.jsxs("div",{className:"flex items-start gap-2 pt-1",children:[e.jsx(ct,{id:"synth-confirm",checked:d,onCheckedChange:g=>l(g===!0),disabled:f}),e.jsx(I,{htmlFor:"synth-confirm",className:"text-sm leading-snug font-normal",children:"I confirm CarSolve OS capture window is open and this URL is a sandbox endpoint."})]}),e.jsxs(U,{type:"button",onClick:y,disabled:!d||f,children:[e.jsx(dt,{className:"mr-2 h-4 w-4"}),f?"Sending…":"Send Now"]})]}),u&&e.jsxs("div",{className:"space-y-2 rounded-md border p-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-sm",children:[e.jsx(xe,{variant:u.ok?"default":"destructive",children:u.ok?"OK":"FAILED"}),e.jsxs("span",{className:"font-mono",children:["HTTP ",u.status," ",u.statusText]}),e.jsxs("span",{className:"text-muted-foreground",children:[u.durationMs,"ms"]}),((_=u.requestPreview)==null?void 0:_.destinationHost)&&e.jsxs("span",{className:"text-muted-foreground",children:["→ ",u.requestPreview.destinationHost,u.requestPreview.destinationPath]})]}),u.networkError&&e.jsxs(Lt,{variant:"destructive",children:[e.jsx(Mt,{children:"Network error"}),e.jsx(Ft,{className:"font-mono text-xs",children:u.networkError})]}),u.responseBody&&e.jsxs("div",{children:[e.jsx(I,{className:"text-xs",children:"Response body"}),e.jsx("pre",{className:"mt-1 max-h-64 overflow-auto rounded bg-muted p-2 text-xs",children:u.responseBody})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Result is shown for this session only. It is not persisted."})]})]})]})}const kt={ghl_crm_enabled:!1,ghl_location_id:"",ghl_webhook_url:"",ghl_events:{dataSync:!0,leadCreated:!0,listingLive:!0,newBid:!0,directOffer:!0,counterOffer:!0,auctionEnded:!0,appointmentScheduled:!0,viewedMarketReport:!0,vehicleProfileComplete:!0,liveAuctionDuration:!0,auctionEndedResult:!0,sellerCounterOffer:!0,dealerReCounter:!0,sellerReCounter:!0,counterOfferDeclined:!0,noSale:!0,soldWaitingAppointment:!0,soldAppointmentScheduled:!0,soldDealerRescheduled:!0,soldAppointmentConfirmed:!0,soldConfirmedPurchase:!0}},ma=[{key:"dataSync",label:"Sync All Fields",description:"Push all vehicle data to GHL (color, bid, appointment, etc.)",icon:zt,section:"Data Sync"},{key:"leadCreated",label:"Lead Created",description:"When a new lead arrives via ClearCar/ADF form (includes instant login link)",icon:Dn,section:"Lead Creation"},{key:"listingLive",label:"Listing Live",description:"When a vehicle goes live in auction (includes instant login link)",icon:ea,section:"Notifications"},{key:"newBid",label:"New Bid",description:"When a new bid is placed on the vehicle",icon:Yt,section:"Notifications"},{key:"directOffer",label:"Direct Offer",description:"When a dealer makes a direct offer",icon:Ot,section:"Notifications"},{key:"counterOffer",label:"Counter Offer",description:"When a counter offer is submitted",icon:Ot,section:"Notifications"}
54,{key:"auctionEnded",label:"Auction Ended",description:"When the auction timer expires",icon:He,section:"Notifications"},{key:"appointmentScheduled",label:"Appointment Scheduled",description:"Send appointment date/time to GHL contact",icon:ot,section:"Notifications"},{key:"viewedMarketReport",label:"Viewed Market Report",description:"Update timestamp when customer views page",icon:ut,section:"Profile Tracking"},{key:"vehicleProfileComplete",label:"Vehicle Profile Complete",description:"Set profile status to Complete",icon:In,section:"Profile Tracking"},{key:"liveAuctionDuration",label:"Live Auction Duration",description:"Update how long vehicle has been live",icon:On,section:"Auction Status"},{key:"auctionEndedResult",label:"Auction Ended Result",description:"Update final highest bid/price",icon:An,section:"Auction Status"},{key:"sellerCounterOffer",label:"Seller Counter Offer",description:"Update seller counter offer amount",icon:lt,section:"Counter Offers"},{key:"dealerReCounter",label:"Dealer Re-Counter",description:"Update dealer re-counter amount",icon:lt,section:"Counter Offers"},{key:"sellerReCounter",label:"Seller Re-Counter",description:"Update seller re-counter amount",icon:lt,section:"Counter Offers"},{key:"counterOfferDeclined",label:"Counter Offer Declined",description:"Mark counter offer as declined",icon:un,section:"Counter Offers"},{key:"noSale",label:"No Sale",description:"Mark vehicle as No Sale",icon:un,section:"Sale Status"},{key:"soldWaitingAppointment",label:"Sold - Waiting for Appointment",description:"Set sold appointment status",icon:He,section:"Sale Status"},{key:"soldAppointmentScheduled",label:"Sold - Appointment Scheduled",description:"Set to Appointment Scheduled",icon:ot,section:"Sale Status"},{key:"soldDealerRescheduled",label:"Sold - Dealer Rescheduled",description:"Set to Dealer Rescheduled",icon:ot,section:"Sale Status"},{key:"soldAppointmentConfirmed",label:"Sold - Appointment Confirmed",description:"Set to Appointment Confirmed",icon:Zt,section:"Sale Status"},{key:"soldConfirmedPurchase",label:"Sold - Confirmed Purchase",description:"Mark as Confirmed purchase",icon:Xt,section:"Sale Status"}],fa=["Data Sync","Lead Creation","Notifications","Profile Tracking","Auction Status","Counter Offers","Sale Status"],ha={"Data Sync":zt,"Lead Creation":Dn,Notifications:qt,"Profile Tracking":ut,"Auction Status":On,"Counter Offers":lt,"Sale Status":Xt};function pa(){const[t,n]=s.useState(kt),[a,r]=s.useState(!0),[i,o]=s.useState(!1),[d,l]=s.useState(!1),[f,h]=s.useState(null);s.useEffect(()=>{u()},[]);const u=async()=>{r(!0);try{const{data:m,error:x}=await F.from("auction_settings").select("setting_key, setting_value").in("setting_key",["ghl_crm_enabled","ghl_location_id","ghl_webhook_url","ghl_events"]);if(x)throw x;const N={...kt};m==null||m.forEach(S=>{const y=S.setting_key;y==="ghl_crm_enabled"?N.ghl_crm_enabled=S.setting_value===!0||S.setting_value==="true":y==="ghl_location_id"?N.ghl_location_id=typeof S.setting_value=="string"?S.setting_value.replace(/"/g,""):String(S.setting_value||""):y==="ghl_webhook_url"?N.ghl_webhook_url=typeof S.setting_value=="string"?S.setting_value.replace(/"/g,""):String(S.setting_value||""):y==="ghl_events"&&typeof S.setting_value=="object"&&(N.ghl_events={...kt.ghl_events,...S.setting_value})}),n(N)}catch(m){console.error("Error fetching GHL settings:",m),P.error("Failed to load GHL CRM settings")}finally{r(!1)}},v=async(m,x)=>{const{error:N}=await F.from("auction_settings").upsert({setting_key:m,setting_value:x,description:`Go High Level CRM - ${m}`,updated_at:new Date().toISOString()},{onConflict:"setting_key"});if(N)throw N},k=async()=>{o(!0);try{await Promise.all([v("ghl_crm_enabled",t.ghl_crm_enabled),v("ghl_location_id",t.ghl_location_id),v("ghl_webhook_url",t.ghl_webhook_url),v("ghl_events",t.ghl_events)]),P.success("GHL CRM settings saved successfully")}catch(m){console.error("Error saving GHL settings:",m),P.error("Failed to save GHL CRM settings")}finally{o(!1)}},w=async()=>{l(!0),h(null);try{const{data:m}=await F.from("cars").select("id").limit(1).maybeSingle();if(!m){P.error("No vehicles available to test with"),h("error");return}const{data:x,error:N}=await F.functions.invoke("ghl-crm-webhook",{body:{event_type:"listingLive",car_id:m.id,test_mode:!0}});if(N)throw N;if(x!=null&&x.success){h("success");const S=x.location_name?` (${x.location_name})`:"";P.success(`GHL credentials validated${S}! No customer data was sent.`)}else h("error"),P.error((x==null?void 0:x.reason)||(x==null?void 0:x.error)||"Connection test failed")}catch(m){console.error("Error testing GHL connection:",m),h("error"),P.error("Failed to test GHL connection")}finally{l(!1)}},E=m=>{n(x=>({...x,ghl_events:{...x.ghl_events,[m]:!x.ghl_events[m]}}))};return a?e.jsx(re,{children:e.jsx(ie,{className:"flex items-center justify-center py-8",children:e.jsx(Y,{className:"h-6 w-6 animate-spin text-muted-foreground"})})}):e.jsxs(re,{children:[e.jsx(Ee,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsxs(Ae,{className:"flex items-center gap-2",children:[e.jsx(Qs,{className:"h-5 w-5"}),"Go High Level CRM Integration"]}),e.jsx(We,{children:"Automatically send customer notifications through Go High Level for auction events"})]}),e.jsx(xe,{variant:t.ghl_crm_enabled?"default":"secondary",children:t.ghl_crm_enabled?"Enabled":"Disabled"})]})}),e.jsxs(ie,{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between rounded-lg border p-4 bg-muted/30",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(I,{className:"text-base font-medium",children:"Enable GHL CRM Integration"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"When enabled, customer data will be sent to Go High Level for automated workflows"})]}),e.jsx(ve,{checked:t.ghl_crm_enabled,onCheckedChange:m=>n(x=>({...x,ghl_crm_enabled:m}))})]}),e.jsx(pe,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(I,{htmlFor:"location-id",children:"GHL Location ID"}),e.jsx(ge,{id:"location-id",value:t.ghl_location_id,onChange:m=>n(x=>({...x,ghl_location_id:m.target.value})),placeholder:"Enter your GHL Location ID"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Found in GHL under Settings → Business Profile → Location ID"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(I,{htmlFor:"webhook-url",children:"GHL Workflow Webhook URL (Optional)"}),e.jsx(ge,{id:"webhook-url",value:t.ghl_webhook_url,onChange:m=>n(x=>({...x,ghl_webhook_url:m.target.value})),placeholder:"https://services.leadconnectorhq.com/hooks/..."}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Optional: Direct webhook URL for triggering specific GHL workflows"})]}),e.jsx(pe,{}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx(I,{className:"text-base font-medium",children:"Notification 
54Events"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Choose which events trigger updates to GHL contacts"})]}),fa.map(m=>{const x=ha[m],N=ma.filter(S=>S.section===m);return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-semibold text-muted-foreground uppercase tracking-wide",children:[e.jsx(x,{className:"h-4 w-4"}),m]}),e.jsx("div",{className:"grid gap-2",children:N.map(S=>{const y=S.icon;return e.jsxs("div",{className:"flex items-center justify-between rounded-lg border p-3 hover:bg-muted/30 transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex h-8 w-8 items-center justify-center rounded-md bg-primary/10",children:e.jsx(y,{className:"h-4 w-4 text-primary"})}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:S.label}),e.jsx("p",{className:"text-xs text-muted-foreground",children:S.description})]})]}),e.jsx(ve,{checked:t.ghl_events[S.key]??!0,onCheckedChange:()=>E(S.key)})]},S.key)})})]},m)})]}),e.jsx(pe,{}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(U,{variant:"outline",onClick:w,disabled:d||!t.ghl_location_id,children:[d?e.jsx(Y,{className:"mr-2 h-4 w-4 animate-spin"}):f==="success"?e.jsx(Dt,{className:"mr-2 h-4 w-4 text-green-500"}):f==="error"?e.jsx(It,{className:"mr-2 h-4 w-4 text-destructive"}):e.jsx(qt,{className:"mr-2 h-4 w-4"}),"Test Connection"]}),e.jsxs(U,{onClick:k,disabled:i,children:[i?e.jsx(Y,{className:"mr-2 h-4 w-4 animate-spin"}):null,"Save Settings"]})]}),e.jsxs("div",{className:"rounded-lg border border-blue-200 bg-blue-50 p-4 dark:border-blue-900 dark:bg-blue-950",children:[e.jsx("h4",{className:"font-medium text-blue-900 dark:text-blue-100 mb-2",children:"How it works"}),e.jsxs("ul",{className:"text-sm text-blue-800 dark:text-blue-200 space-y-1 list-disc list-inside",children:[e.jsx("li",{children:"Customer contact info is sent to GHL when events occur"}),e.jsx("li",{children:'"Listing Live" includes an instant login link for the customer'}),e.jsx("li",{children:"GHL workflows can be triggered to send SMS/email notifications"}),e.jsx("li",{children:"Per-vehicle control available via the CRM toggle on each listing"})]})]})]})]})}var mn=1,va=.9,xa=.8,ga=.17,Nt=.1,St=.999,ba=.9999,ya=.99,_a=/[\\\/_+.#"@\[\(\{&]/,ja=/[\\\/_+.#"@\[\(\{&]/g,wa=/[\s-]/,Fn=/[\s-]/g;function Ut(t,n,a,r,i,o,d){if(o===n.length)return i===t.length?mn:ya;var l=`${i},${o}`;if(d[l]!==void 0)return d[l];for(var f=r.charAt(o),h=a.indexOf(f,i),u=0,v,k,w,E;h>=0;)v=Ut(t,n,a,r,h+1,o+1,d),v>u&&(h===i?v*=mn:_a.test(t.charAt(h-1))?(v*=xa,w=t.slice(i,h-1).match(ja),w&&i>0&&(v*=Math.pow(St,w.length))):wa.test(t.charAt(h-1))?(v*=va,E=t.slice(i,h-1).match(Fn),E&&i>0&&(v*=Math.pow(St,E.length))):(v*=ga,i>0&&(v*=Math.pow(St,h-i))),t.charAt(h)!==n.charAt(o)&&(v*=ba)),(v<Nt&&a.charAt(h-1)===r.charAt(o+1)||r.charAt(o+1)===r.charAt(o)&&a.charAt(h-1)!==r.charAt(o))&&(k=Ut(t,n,a,r,h+1,o+2,d),k*Nt>v&&(v=k*Nt)),v>u&&(u=v),h=a.indexOf(f,h+1);return d[l]=u,u}function fn(t){return t.toLowerCase().replace(Fn," ")}function ka(t,n,a){return t=a&&a.length>0?`${t+" "+a.join(" ")}`:t,Ut(t,n,fn(t),fn(n),0,0,{})}function $e(t,n,{checkForDefaultPrevented:a=!0}={}){return function(i){if(t==null||t(i),a===!1||!i.defaultPrevented)return n==null?void 0:n(i)}}function Na(t,n){typeof t=="function"?t(n):t!=null&&(t.current=n)}function Un(...t){return n=>t.forEach(a=>Na(a,n))}function Ke(...t){return s.useCallback(Un(...t),t)}function Sa(t,n=[]){let a=[];function r(o,d){const l=s.createContext(d),f=a.length;a=[...a,d];function h(v){const{scope:k,children:w,...E}=v,m=(k==null?void 0:k[t][f])||l,x=s.useMemo(()=>E,Object.values(E));return s.createElement(m.Provider,{value:x},w)}function u(v,k){const w=(k==null?void 0:k[t][f])||l,E=s.useContext(w);if(E)return E;if(d!==void 0)return d;throw new Error(`\`${v}\` must be used within \`${o}\``)}return h.displayName=o+"Provider",[h,u]}const i=()=>{const o=a.map(d=>s.createContext(d));return function(l){const f=(l==null?void 0:l[t])||o;return s.useMemo(()=>({[`__scope${t}`]:{...l,[t]:f}}
54),[l,f])}};return i.scopeName=t,[r,Ca(i,...n)]}function Ca(...t){const n=t[0];if(t.length===1)return n;const a=()=>{const r=t.map(i=>({useScope:i(),scopeName:i.scopeName}));return function(o){const d=r.reduce((l,{useScope:f,scopeName:h})=>{const v=f(o)[`__scope${h}`];return{...l,...v}},{});return s.useMemo(()=>({[`__scope${n.scopeName}`]:d}),[d])}};return a.scopeName=n.scopeName,a}const $a=globalThis!=null&&globalThis.document?s.useLayoutEffect:()=>{},Ea=$s.useId||(()=>{});let Aa=0;function Ct(t){const[n,a]=s.useState(Ea());return $a(()=>{t||a(r=>r??String(Aa++))},[t]),t||(n?`radix-${n}`:"")}function Hn(t){const n=s.useRef(t);return s.useEffect(()=>{n.current=t}),s.useMemo(()=>(...a)=>{var r;return(r=n.current)===null||r===void 0?void 0:r.call(n,...a)},[])}function Pa({prop:t,defaultProp:n,onChange:a=()=>{}}){const[r,i]=Ta({defaultProp:n,onChange:a}),o=t!==void 0,d=o?t:r,l=Hn(a),f=s.useCallback(h=>{if(o){const v=typeof h=="function"?h(t):h;v!==t&&l(v)}else i(h)},[o,t,i,l]);return[d,f]}function Ta({defaultProp:t,onChange:n}){const a=s.useState(t),[r]=a,i=s.useRef(r),o=Hn(n);return s.useEffect(()=>{i.current!==r&&(o(r),i.current=r)},[r,i,o]),a}function Ra(t,n){typeof t=="function"?t(n):t!=null&&(t.current=n)}function Da(...t){return n=>t.forEach(a=>Ra(a,n))}const Vn=s.forwardRef((t,n)=>{const{children:a,...r}=t,i=s.Children.toArray(a),o=i.find(Oa);if(o){const d=o.props.children,l=i.map(f=>f===o?s.Children.count(d)>1?s.Children.only(null):s.isValidElement(d)?d.props.children:null:f);return s.createElement(Ht,K({},r,{ref:n}),s.isValidElement(d)?s.cloneElement(d,void 0,l):null)}return s.createElement(Ht,K({},r,{ref:n}),a)});Vn.displayName="Slot";const Ht=s.forwardRef((t,n)=>{const{children:a,...r}=t;return s.isValidElement(a)?s.cloneElement(a,{...La(r,a.props),ref:n?Da(n,a.ref):a.ref}):s.Children.count(a)>1?s.Children.only(null):null});Ht.displayName="SlotClone";const Ia=({children:t})=>s.createElement(s.Fragment,null,t);function Oa(t){return s.isValidElement(t)&&t.type===Ia}function La(t,n){const a={...n};for(const r in n){const i=t[r],o=n[r];/^on[A-Z]/.test(r)?i&&o?a[r]=(...l)=>{o(...l),i(...l)}:i&&(a[r]=i):r==="style"?a[r]={...i,...o}:r==="className"&&(a[r]=[i,o].filter(Boolean).join(" "))}return{...t,...a}}const Ma=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","span","svg","ul"],X=Ma.reduce((t,n)=>{const a=s.forwardRef((r,i)=>{const{asChild:o,...d}=r,l=o?Vn:n;return s.useEffect(()=>{window[Symbol.for("radix-ui")]=!0},[]),s.createElement(l,K({},d,{ref:i}))});return a.displayName=`Primitive.${n}`,{...t,[n]:a}},{});function Fa(t,n){t&&Pn.flushSync(()=>t.dispatchEvent(n))}function Jt(t){const n=s.useRef(t);return s.useEffect(()=>{n.current=t}),s.useMemo(()=>(...a)=>{var r;return(r=n.current)===null||r===void 0?void 0:r.call(n,...a)},[])}function Ua(t,n=globalThis==null?void 0:globalThis.document){const a=Jt(t);s.useEffect(()=>{const r=i=>{i.key==="Escape"&&a(i)};return n.addEventListener("keydown",r),()=>n.removeEventListener("keydown",r)},[a,n])}const Vt="dismissableLayer.update",Ha="dismissableLayer.pointerDownOutside",Va="dismissableLayer.focusOutside";let hn;const Ba=s.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),Wa=s.forwardRef((t,n)=>{var a;const{disableOutsidePointerEvents:r=!1,onEscapeKeyDown:i,onPointerDownOutside:o,onFocusOutside:d,onInteractOutside:l,onDismiss:f,...h}=t,u=s.useContext(Ba),[v,k]=s.useState(null),w=(a=v==null?void 0:v.ownerDocument)!==null&&a!==void 0?a:globalThis==null?void 0:globalThis.document,[,E]=s.useState({}),m=Ke(n,R=>k(R)),x=Array.from(u.layers),[N]=[...u.layersWithOutsidePointerEventsDisabled].slice(-1),S=x.indexOf(N),y=v?x.indexOf(v):-1,_=u.layersWithOutsidePointerEventsDisabled.size>0,g=y>=S,$=Ka(R=>{const W=R.target,Z=[...u.branches].some(J=>J.contains(W));!g||Z||(o==null||o(R),l==null||l(R),R.defaultPrevented||f==null||f())},w),b=Ga(R=>{const W=R.target;[...u.branches].some(J=>J.contains(W))||(d==null||d(R),l==null||l(R),R.defaultPrevented||f==null||f())},w);return Ua(R=>{y===u.layers.size-1&&(i==null||i(R),!R.defaultPrevented&&f&&(R.preventDefault(),f()))},w),s.useEffect(()=>{if(v)return r&&(u.layersWithOutsidePointerEventsDisabled.size===0&&(hn=w.body.style.pointerEvents,w.body.style.pointerEvents="none"),u.layersWithOutsidePointerEventsDisabled.add(v)),u.layers.add(v),pn(),()=>{r&&u.layersWithOutsidePointerEventsDisabled.size===1&&(w.body.style.pointerEvents=hn)}},[v,w,r,u]),s.useEffect(()=>()=>{v&&(u.layers.delete(v),u.layersWithOutsidePointerEventsDisabled.delete(v),pn())},[v,u]),s.useEffect(()=>{const R=()=>E({});return document.addEventListener(Vt,R),()=>document.removeEventListener(Vt,R)},[]),s.createElement(X.div,K({},h,{ref:m,style:{pointerEvents:_?g?"auto":"none":void 0,...t.style},onFocusCapture:$e(t.onFocusCapture,b.onFocusCapture),onBlurCapture:$e(t.onBlurCapture,b.onBlurCapture),onPointerDownCapture:$e(t.onPointerDownCapture,$.onPointerDownCapture)}))});function Ka(t,n=globalThis==null?void 0:globalThis.document){const a=Jt(t),r=s.useRef(!1),i=s.useRef(()=>{});return s.useEffect(()=>{const o=l=>{if(l.target&&!r.current){let h=function(){Bn(Ha,a,f,{discrete:!0})};const f={originalEvent:l};l.pointerType==="touch"?(n.removeEventListener("click",i.current),i.current=h,n.addEventListener("click",i.current,{once:!0})):h()}else n.removeEventListener("click",i.current);r.current=!1},d=window.setTimeout(()=>{n.addEventListener("pointerdown",o)},0);return()=>{window.clearTimeout(d),n.removeEventListener("pointerdown",o),n.removeEventListener("click",i.current)}},[n,a]),{onPointerDownCapture:()=>r.current=!0}}function Ga(t,n=globalThis==null?void 0:globalThis.document){const a=Jt(t),r=s.useRef(!1);return s.useEffect(()=>{const i=o=>{o.target&&!r.current&&Bn(Va,a,{originalEvent:o},{discrete:!1})};return n.addEventListener("focusin",i),()=>n.removeEventListener("focusin",i)},[n,a]),{onFocusCapture:()=>r.current=!0,onBlurCapture:()=>r.current=!1}}function pn(){const t=new CustomEvent(Vt);document.dispatchEvent(t)}function Bn(t,n,a,{discrete:r}){const i=a.originalEvent.target,o=new CustomEvent(t,{bubbles:!1,cancelable:!0,detail:a});n&&i.addEventListener(t,n,{once:!0}),r?Fa(i,o):i.dispatchEvent(o)}function vn(t){const n=s.useRef(t);return s.useEffect(()=>{n.current=t}),s.useMemo(()=>(...a)=>{var r;return(r=n.current)===null||r===void 0?void 0:r.call(n,...a)},[])}const $t="focusScope.autoFocusOnMount",Et="focusScope.autoFocusOnUnmount",xn={bubbles:!1,cancelable:!0}
vendor: 4,250 bytes, line 54
54,qa=s.forwardRef((t,n)=>{const{loop:a=!1,trapped:r=!1,onMountAutoFocus:i,onUnmountAutoFocus:o,...d}=t,[l,f]=s.useState(null),h=vn(i),u=vn(o),v=s.useRef(null),k=Ke(n,m=>f(m)),w=s.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;s.useEffect(()=>{if(r){let m=function(y){if(w.paused||!l)return;const _=y.target;l.contains(_)?v.current=_:ue(v.current,{select:!0})},x=function(y){if(w.paused||!l)return;const _=y.relatedTarget;_!==null&&(l.contains(_)||ue(v.current,{select:!0}))},N=function(y){if(document.activeElement===document.body)for(const g of y)g.removedNodes.length>0&&ue(l)};document.addEventListener("focusin",m),document.addEventListener("focusout",x);const S=new MutationObserver(N);return l&&S.observe(l,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",m),document.removeEventListener("focusout",x),S.disconnect()}}},[r,l,w.paused]),s.useEffect(()=>{if(l){bn.add(w);const m=document.activeElement;if(!l.contains(m)){const N=new CustomEvent($t,xn);l.addEventListener($t,h),l.dispatchEvent(N),N.defaultPrevented||(za(Qa(Wn(l)),{select:!0}),document.activeElement===m&&ue(l))}return()=>{l.removeEventListener($t,h),setTimeout(()=>{const N=new CustomEvent(Et,xn);l.addEventListener(Et,u),l.dispatchEvent(N),N.defaultPrevented||ue(m??document.body,{select:!0}),l.removeEventListener(Et,u),bn.remove(w)},0)}}},[l,h,u,w]);const E=s.useCallback(m=>{if(!a&&!r||w.paused)return;const x=m.key==="Tab"&&!m.altKey&&!m.ctrlKey&&!m.metaKey,N=document.activeElement;if(x&&N){const S=m.currentTarget,[y,_]=Ya(S);y&&_?!m.shiftKey&&N===_?(m.preventDefault(),a&&ue(y,{select:!0})):m.shiftKey&&N===y&&(m.preventDefault(),a&&ue(_,{select:!0})):N===S&&m.preventDefault()}},[a,r,w.paused]);return s.createElement(X.div,K({tabIndex:-1},d,{ref:k,onKeyDown:E}))});function za(t,{select:n=!1}={}){const a=document.activeElement;for(const r of t)if(ue(r,{select:n}),document.activeElement!==a)return}function Ya(t){const n=Wn(t),a=gn(n,t),r=gn(n.reverse(),t);return[a,r]}function Wn(t){const n=[],a=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT,{acceptNode:r=>{const i=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||i?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;a.nextNode();)n.push(a.currentNode);return n}function gn(t,n){for(const a of t)if(!Xa(a,{upTo:n}))return a}function Xa(t,{upTo:n}){if(getComputedStyle(t).visibility==="hidden")return!0;for(;t;){if(n!==void 0&&t===n)return!1;if(getComputedStyle(t).display==="none")return!0;t=t.parentElement}return!1}function Za(t){return t instanceof HTMLInputElement&&"select"in t}function ue(t,{select:n=!1}={}){if(t&&t.focus){const a=document.activeElement;t.focus({preventScroll:!0}),t!==a&&Za(t)&&n&&t.select()}}const bn=Ja();function Ja(){let t=[];return{add(n){const a=t[0];n!==a&&(a==null||a.pause()),t=yn(t,n),t.unshift(n)},remove(n){var a;t=yn(t,n),(a=t[0])===null||a===void 0||a.resume()}}}function yn(t,n){const a=[...t],r=a.indexOf(n);return r!==-1&&a.splice(r,1),a}function Qa(t){return t.filter(n=>n.tagName!=="A")}const er=s.forwardRef((t,n)=>{var a;const{container:r=globalThis==null||(a=globalThis.document)===null||a===void 0?void 0:a.body,...i}=t;return r?Es.createPortal(s.createElement(X.div,K({},i,{ref:n})),r):null}),_n=globalThis!=null&&globalThis.document?s.useLayoutEffect:()=>{};function tr(t,n){return s.useReducer((a,r)=>{const i=n[a][r];return i??a},t)}const mt=t=>{const{present:n,children:a}=t,r=nr(n),i=typeof a=="function"?a({present:r.isPresent}):s.Children.only(a),o=Ke(r.ref,i.ref);return typeof a=="function"||r.isPresent?s.cloneElement(i,{ref:o}):null};mt.displayName="Presence";function nr(t){const[n,a]=s.useState(),r=s.useRef({}),i=s.useRef(t),o=s.useRef("none"),d=t?"mounted":"unmounted",[l,f]=tr(d,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return s.useEffect(()=>{const h=et(r.current);o.current=l==="mounted"?h:"none"},[l]),_n(()=>{const h=r.current,u=i.current;if(u!==t){const k=o.current,w=et(h);t?f("MOUNT"):w==="none"||(h==null?void 0:h.display)==="none"?f("UNMOUNT"):f(u&&k!==w?"ANIMATION_OUT":"UNMOUNT"),i.current=t}},[t,f]),_n(()=>
54{if(n){const h=v=>{const w=et(r.current).includes(v.animationName);v.target===n&&w&&Pn.flushSync(()=>f("ANIMATION_END"))},u=v=>{v.target===n&&(o.current=et(r.current))};return n.addEventListener("animationstart",u),n.addEventListener("animationcancel",h),n.addEventListener("animationend",h),()=>{n.removeEventListener("animationstart",u),n.removeEventListener("animationcancel",h),n.removeEventListener("animationend",h)}}else f("ANIMATION_END")},[n,f]),{isPresent:["mounted","unmountSuspended"].includes(l),ref:s.useCallback(h=>{h&&(r.current=getComputedStyle(h)),a(h)},[])}}function et(t){return(t==null?void 0:t.animationName)||"none"}let At=0;function sr(){s.useEffect(()=>{var t,n;const a=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",(t=a[0])!==null&&t!==void 0?t:jn()),document.body.insertAdjacentElement("beforeend",(n=a[1])!==null&&n!==void 0?n:jn()),At++,()=>{At===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(r=>r.remove()),At--}},[])}function jn(){const t=document.createElement("span");return t.setAttribute("data-radix-focus-guard",""),t.tabIndex=0,t.style.cssText="outline: none; opacity: 0; position: fixed; pointer-events: none",t}var Kn=As(),Pt=function(){},ft=s.forwardRef(function(t,n){var a=s.useRef(null),r=s.useState({onScrollCapture:Pt,onWheelCapture:Pt,onTouchMoveCapture:Pt}),i=r[0],o=r[1],d=t.forwardProps,l=t.children,f=t.className,h=t.removeScrollBar,u=t.enabled,v=t.shards,k=t.sideCar,w=t.noIsolation,E=t.inert,m=t.allowPinchZoom,x=t.as,N=x===void 0?"div":x,S=Ps(t,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noIsolation","inert","allowPinchZoom","as"]),y=k,_=Ts([a,n]),g=Se(Se({},S),i);return s.createElement(s.Fragment,null,u&&s.createElement(y,{sideCar:Kn,removeScrollBar:h,shards:v,noIsolation:w,inert:E,setCallbacks:o,allowPinchZoom:!!m,lockRef:a}),d?s.cloneElement(s.Children.only(l),Se(Se({},g),{ref:_})):s.createElement(N,Se({},g,{className:f,ref:_}),l))});ft.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1};ft.classNames={fullWidth:Rs,zeroRight:Ds};var Bt=!1;if(typeof window<"u")try{var tt=Object.defineProperty({},"passive",{get:function(){return Bt=!0,!0}});window.addEventListener("test",tt,tt),window.removeEventListener("test",tt,tt)}catch{Bt=!1}var ke=Bt?{passive:!1}:!1,ar=function(t){return t.tagName==="TEXTAREA"},Gn=function(t,n){var a=window.getComputedStyle(t);return a[n]!=="hidden"&&!(a.overflowY===a.overflowX&&!ar(t)&&a[n]==="visible")},rr=function(t){return Gn(t,"overflowY")},ir=function(t){return Gn(t,"overflowX")},wn=function(t,n){var a=n;do{typeof ShadowRoot<"u"&&a instanceof ShadowRoot&&(a=a.host);var r=qn(t,a);if(r){var i=zn(t,a),o=i[1],d=i[2];if(o>d)return!0}a=a.parentNode}while(a&&a!==document.body);return!1},or=function(t){var n=t.scrollTop,a=t.scrollHeight,r=t.clientHeight;return[n,a,r]},lr=function(t){var n=t.scrollLeft,a=t.scrollWidth,r=t.clientWidth;return[n,a,r]},qn=function(t,n){return t==="v"?rr(n):ir(n)},zn=function(t,n){return t==="v"?or(n):lr(n)},cr=function(t,n){return t==="h"&&n==="rtl"?-1:1},dr=function(t,n,a,r,i){var o=cr(t,window.getComputedStyle(n).direction),d=o*r,l=a.target,f=n.contains(l),h=!1,u=d>0,v=0,k=0;do{var w=zn(t,l),E=w[0],m=w[1],x=w[2],N=m-x-o*E;(E||N)&&qn(t,l)&&(v+=N,k+=E),l=l.parentNode}while(!f&&l!==document.body||f&&(n.contains(l)||n===l));return(u&&(v===0||!i)||!u&&(k===0||!i))&&(h=!0),h},nt=function(t){return"changedTouches"in t?[t.changedTouches[0].clientX,t.changedTouches[0].clientY]:[0,0]},kn=function(t){return[t.deltaX,t.deltaY]},Nn=function(t){return t&&"current"in t?t.current:t},ur=function(t,n){return t[0]===n[0]&&t[1]===n[1]},mr=function(t){return`
55  .block-interactivity-`.concat(t,` {pointer-events: none;}
56  .allow-interactivity-`).concat(t,` {pointer-events: all;}
57`)},fr=0,Ne=[];function hr(t){var n=s.useRef([]),a=s.useRef([0,0]),r=s.useRef(),i=s.useState(fr++)[0],o=s.useState(function(){return Is()})[0],d=s.useRef(t);s.useEffect(function(){d.current=t},[t]),s.useEffect(function(){if(t.inert){document.body.classList.add("block-interactivity-".concat(i));
57var m=Os([t.lockRef.current],(t.shards||[]).map(Nn),!0).filter(Boolean);return m.forEach(function(x){return x.classList.add("allow-interactivity-".concat(i))}),function(){document.body.classList.remove("block-interactivity-".concat(i)),m.forEach(function(x){return x.classList.remove("allow-interactivity-".concat(i))})}}},[t.inert,t.lockRef.current,t.shards]);var l=s.useCallback(function(m,x){if("touches"in m&&m.touches.length===2)return!d.current.allowPinchZoom;var N=nt(m),S=a.current,y="deltaX"in m?m.deltaX:S[0]-N[0],_="deltaY"in m?m.deltaY:S[1]-N[1],g,$=m.target,b=Math.abs(y)>Math.abs(_)?"h":"v";if("touches"in m&&b==="h"&&$.type==="range")return!1;var R=wn(b,$);if(!R)return!0;if(R?g=b:(g=b==="v"?"h":"v",R=wn(b,$)),!R)return!1;if(!r.current&&"changedTouches"in m&&(y||_)&&(r.current=g),!g)return!0;var W=r.current||g;return dr(W,x,m,W==="h"?y:_,!0)},[]),f=s.useCallback(function(m){var x=m;if(!(!Ne.length||Ne[Ne.length-1]!==o)){var N="deltaY"in x?kn(x):nt(x),S=n.current.filter(function(g){return g.name===x.type&&g.target===x.target&&ur(g.delta,N)})[0];if(S&&S.should){x.cancelable&&x.preventDefault();return}if(!S){var y=(d.current.shards||[]).map(Nn).filter(Boolean).filter(function(g){return g.contains(x.target)}),_=y.length>0?l(x,y[0]):!d.current.noIsolation;_&&x.cancelable&&x.preventDefault()}}},[]),h=s.useCallback(function(m,x,N,S){var y={name:m,delta:x,target:N,should:S};n.current.push(y),setTimeout(function(){n.current=n.current.filter(function(_){return _!==y})},1)},[]),u=s.useCallback(function(m){a.current=nt(m),r.current=void 0},[]),v=s.useCallback(function(m){h(m.type,kn(m),m.target,l(m,t.lockRef.current))},[]),k=s.useCallback(function(m){h(m.type,nt(m),m.target,l(m,t.lockRef.current))},[]);s.useEffect(function(){return Ne.push(o),t.setCallbacks({onScrollCapture:v,onWheelCapture:v,onTouchMoveCapture:k}),document.addEventListener("wheel",f,ke),document.addEventListener("touchmove",f,ke),document.addEventListener("touchstart",u,ke),function(){Ne=Ne.filter(function(m){return m!==o}),document.removeEventListener("wheel",f,ke),document.removeEventListener("touchmove",f,ke),document.removeEventListener("touchstart",u,ke)}},[]);var w=t.removeScrollBar,E=t.inert;return s.createElement(s.Fragment,null,E?s.createElement(o,{styles:mr(i)}):null,w?s.createElement(Ls,{gapMode:"margin"}):null)}const pr=Ms(Kn,hr);var Yn=s.forwardRef(function(t,n){return s.createElement(ft,Se({},t,{ref:n,sideCar:pr}))});Yn.classNames=ft.classNames;const Xn=s.forwardRef((t,n)=>{const{children:a,...r}=t,i=s.Children.toArray(a),o=i.find(xr);if(o){const d=o.props.children,l=i.map(f=>f===o?s.Children.count(d)>1?s.Children.only(null):s.isValidElement(d)?d.props.children:null:f);return s.createElement(Wt,K({},r,{ref:n}),s.isValidElement(d)?s.cloneElement(d,void 0,l):null)}return s.createElement(Wt,K({},r,{ref:n}),a)});Xn.displayName="Slot";const Wt=s.forwardRef((t,n)=>{const{children:a,...r}=t;return s.isValidElement(a)?s.cloneElement(a,{...gr(r,a.props),ref:n?Un(n,a.ref):a.ref}):s.Children.count(a)>1?s.Children.only(null):null});Wt.displayName="SlotClone";const vr=({children:t})=>s.createElement(s.Fragment,null,t);function xr(t){return s.isValidElement(t)&&t.type===vr}function gr(t,n){const a={...n};for(const r in n){const i=t[r],o=n[r];/^on[A-Z]/.test(r)?i&&o?a[r]=(...l)=>{o(...l),i(...l)}:i&&(a[r]=i):r==="style"?a[r]={...i,...o}:r==="className"&&(a[r]=[i,o].filter(Boolean).join(" "))}return{...t,...a}}const Zn="Dialog",[Jn,Ni]=Sa(Zn),[br,_e]=Jn(Zn),yr=t=>{const{__scopeDialog:n,children:a,open:r,defaultOpen:i,onOpenChange:o,modal:d=!0}=t,l=s.useRef(null),f=s.useRef(null),[h=!1,u]=Pa({prop:r,defaultProp:i,onChange:o});return s.createElement(br,{scope:n,triggerRef:l,contentRef:f,contentId:Ct(),titleId:Ct(),descriptionId:Ct(),open:h,onOpenChange:u,onOpenToggle:s.useCallback(()=>u(v=>!v),[u]),modal:d},a)},Qn="DialogPortal",[_r,es]=Jn(Qn,{forceMount:void 0}),jr=t=>{const{__scopeDialog:n,forceMount:a,children:r,container:i}=t,o=_e(Qn,n);return s.createElement(_r,{scope:n,forceMount:a},s.Children.map(r,d=>s.createElement(mt,{present:a||o.open},s.createElement(er,{asChild:!0,container:i},d))))}
57,Kt="DialogOverlay",wr=s.forwardRef((t,n)=>{const a=es(Kt,t.__scopeDialog),{forceMount:r=a.forceMount,...i}=t,o=_e(Kt,t.__scopeDialog);return o.modal?s.createElement(mt,{present:r||o.open},s.createElement(kr,K({},i,{ref:n}))):null}),kr=s.forwardRef((t,n)=>{const{__scopeDialog:a,...r}=t,i=_e(Kt,a);return s.createElement(Yn,{as:Xn,allowPinchZoom:!0,shards:[i.contentRef]},s.createElement(X.div,K({"data-state":ns(i.open)},r,{ref:n,style:{pointerEvents:"auto",...r.style}})))}),Ve="DialogContent",Nr=s.forwardRef((t,n)=>{const a=es(Ve,t.__scopeDialog),{forceMount:r=a.forceMount,...i}=t,o=_e(Ve,t.__scopeDialog);return s.createElement(mt,{present:r||o.open},o.modal?s.createElement(Sr,K({},i,{ref:n})):s.createElement(Cr,K({},i,{ref:n})))}),Sr=s.forwardRef((t,n)=>{const a=_e(Ve,t.__scopeDialog),r=s.useRef(null),i=Ke(n,a.contentRef,r);return s.useEffect(()=>{const o=r.current;if(o)return Fs(o)},[]),s.createElement(ts,K({},t,{ref:i,trapFocus:a.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:$e(t.onCloseAutoFocus,o=>{var d;o.preventDefault(),(d=a.triggerRef.current)===null||d===void 0||d.focus()}),onPointerDownOutside:$e(t.onPointerDownOutside,o=>{const d=o.detail.originalEvent,l=d.button===0&&d.ctrlKey===!0;(d.button===2||l)&&o.preventDefault()}),onFocusOutside:$e(t.onFocusOutside,o=>o.preventDefault())}))}),Cr=s.forwardRef((t,n)=>{const a=_e(Ve,t.__scopeDialog),r=s.useRef(!1),i=s.useRef(!1);return s.createElement(ts,K({},t,{ref:n,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:o=>{var d;if((d=t.onCloseAutoFocus)===null||d===void 0||d.call(t,o),!o.defaultPrevented){var l;r.current||(l=a.triggerRef.current)===null||l===void 0||l.focus(),o.preventDefault()}r.current=!1,i.current=!1},onInteractOutside:o=>{var d,l;(d=t.onInteractOutside)===null||d===void 0||d.call(t,o),o.defaultPrevented||(r.current=!0,o.detail.originalEvent.type==="pointerdown"&&(i.current=!0));const f=o.target;((l=a.triggerRef.current)===null||l===void 0?void 0:l.contains(f))&&o.preventDefault(),o.detail.originalEvent.type==="focusin"&&i.current&&o.preventDefault()}}))}),ts=s.forwardRef((t,n)=>{const{__scopeDialog:a,trapFocus:r,onOpenAutoFocus:i,onCloseAutoFocus:o,...d}=t,l=_e(Ve,a),f=s.useRef(null),h=Ke(n,f);return sr(),s.createElement(s.Fragment,null,s.createElement(qa,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:o},s.createElement(Wa,K({role:"dialog",id:l.contentId,"aria-describedby":l.descriptionId,"aria-labelledby":l.titleId,"data-state":ns(l.open)},d,{ref:h,onDismiss:()=>l.onOpenChange(!1)}))),!1)});function ns(t){return t?"open":"closed"}const $r=yr,Er=jr,Ar=wr,Pr=Nr;var Ie='[cmdk-group=""]',Tt='[cmdk-group-items=""]',Tr='[cmdk-group-heading=""]',Qt='[cmdk-item=""]',Sn=`${Qt}:not([aria-disabled="true"])`,Gt="cmdk-item-select",he="data-value",Rr=(t,n,a)=>ka(t,n,a),ss=s.createContext(void 0),Ge=()=>s.useContext(ss),as=s.createContext(void 0),en=()=>s.useContext(as),rs=s.createContext(void 0),is=s.forwardRef((t,n)=>{let a=Ce(()=>{var p,A;return{search:"",value:(A=(p=t.value)!=null?p:t.defaultValue)!=null?A:"",filtered:{count:0,items:new Map,groups:new Set}}}),r=Ce(()=>new Set),i=Ce(()=>new Map),o=Ce(()=>new Map),d=Ce(()=>new Set),l=os(t),{label:f,children:h,value:u,onValueChange:v,filter:k,shouldFilter:w,loop:E,disablePointerSelection:m=!1,vimBindings:x=!0,...N}=t,S=s.useId(),y=s.useId(),_=s.useId(),g=s.useRef(null),$=Wr();be(()=>{if(u!==void 0){let p=u.trim();a.current.value=p,b.emit()}},[u]),be(()=>{$(6,Pe)},[]);let b=s.useMemo(()=>({subscribe:p=>(d.current.add(p),()=>d.current.delete(p)),snapshot:()=>a.current,setState:(p,A,D)=>{var C,L,H;if(!Object.is(a.current[p],A)){if(a.current[p]=A,p==="search")Q(),Z(),$(1,J);else if(p==="value"&&(D||$(5,Pe),((C=l.current)==null?void 0:C.value)!==void 0)){let V=A??"";(H=(L=l.current).onValueChange)==null||H.call(L,V);return}b.emit()}},emit:()=>{d.current.forEach(p=>p())}}),[]),R=s.useMemo(()=>({value:(p,A,D)=>{var C;A!==((C=o.current.get(p))==null?void 0:C.value)&&(o.current.set(p,{value:A,keywords:D}),a.current.filtered.items.set(p,W(A,D)),$(2,()=>{Z(),b.emit()}))},item:(p,A)=>(r.current.add(p),A&&(i.current.has(A)?i.current.get(A).add(p):i.current.set(A,new Set([p]))),$(3,()=>{Q(),Z(),a.current.value||J(),b.emit()}),()=>{o.current.delete(p),r.current.delete(p),a.current.filtered.items.delete(p);let D=ne();$(4,()=>{Q(),(D==null?void 0:D.getAttribute("id"))===p&&J(),b.emit()})}),group:p=>(i.current.has(p)||i.current.set(p,new Set),()=>{o.current.delete(p),i.current.delete(p)}),filter:()=>l.current.shouldFilter,label:f||t["aria-label"],disablePointerSelection:m,listId:S,inputId:_,labelId:y,listInnerRef:g}),[]);function W(p,A){var D,C;let L=(C=(D=l.current)==null?void 0:D.filter)!=null?C:Rr;return p?L(p,a.current.search,A):0}function Z(){if(!a.current.search||l.current.shouldFilter===!1)return;let p=a.current.filtered.items,A=[];a.current.filtered.groups.forEach(C=>{let L=i.current.get(C),H=0;
vendor: 9,013 bytes, line 57
57L.forEach(V=>{let ee=p.get(V);H=Math.max(ee,H)}),A.push([C,H])});let D=g.current;oe().sort((C,L)=>{var H,V;let ee=C.getAttribute("id"),te=L.getAttribute("id");return((H=p.get(te))!=null?H:0)-((V=p.get(ee))!=null?V:0)}).forEach(C=>{let L=C.closest(Tt);L?L.appendChild(C.parentElement===L?C:C.closest(`${Tt} > *`)):D.appendChild(C.parentElement===D?C:C.closest(`${Tt} > *`))}),A.sort((C,L)=>L[1]-C[1]).forEach(C=>{let L=g.current.querySelector(`${Ie}[${he}="${encodeURIComponent(C[0])}"]`);L==null||L.parentElement.appendChild(L)})}function J(){let p=oe().find(D=>D.getAttribute("aria-disabled")!=="true"),A=p==null?void 0:p.getAttribute(he);b.setState("value",A||void 0)}function Q(){var p,A,D,C;if(!a.current.search||l.current.shouldFilter===!1){a.current.filtered.count=r.current.size;return}a.current.filtered.groups=new Set;let L=0;for(let H of r.current){let V=(A=(p=o.current.get(H))==null?void 0:p.value)!=null?A:"",ee=(C=(D=o.current.get(H))==null?void 0:D.keywords)!=null?C:[],te=W(V,ee);a.current.filtered.items.set(H,te),te>0&&L++}for(let[H,V]of i.current)for(let ee of V)if(a.current.filtered.items.get(ee)>0){a.current.filtered.groups.add(H);break}a.current.filtered.count=L}function Pe(){var p,A,D;let C=ne();C&&(((p=C.parentElement)==null?void 0:p.firstChild)===C&&((D=(A=C.closest(Ie))==null?void 0:A.querySelector(Tr))==null||D.scrollIntoView({block:"nearest"})),C.scrollIntoView({block:"nearest"}))}function ne(){var p;return(p=g.current)==null?void 0:p.querySelector(`${Qt}[aria-selected="true"]`)}function oe(){var p;return Array.from((p=g.current)==null?void 0:p.querySelectorAll(Sn))}function le(p){let A=oe()[p];A&&b.setState("value",A.getAttribute(he))}function Te(p){var A;let D=ne(),C=oe(),L=C.findIndex(V=>V===D),H=C[L+p];(A=l.current)!=null&&A.loop&&(H=L+p<0?C[C.length-1]:L+p===C.length?C[0]:C[L+p]),H&&b.setState("value",H.getAttribute(he))}function je(p){let A=ne(),D=A==null?void 0:A.closest(Ie),C;for(;D&&!C;)D=p>0?Vr(D,Ie):Br(D,Ie),C=D==null?void 0:D.querySelector(Sn);C?b.setState("value",C.getAttribute(he)):Te(p)}let Re=()=>le(oe().length-1),ce=p=>{p.preventDefault(),p.metaKey?Re():p.altKey?je(1):Te(1)},De=p=>{p.preventDefault(),p.metaKey?le(0):p.altKey?je(-1):Te(-1)};return s.createElement(X.div,{ref:n,tabIndex:-1,...N,"cmdk-root":"",onKeyDown:p=>{var A;if((A=N.onKeyDown)==null||A.call(N,p),!p.defaultPrevented)switch(p.key){case"n":case"j":{x&&p.ctrlKey&&ce(p);break}case"ArrowDown":{ce(p);break}case"p":case"k":{x&&p.ctrlKey&&De(p);break}case"ArrowUp":{De(p);break}case"Home":{p.preventDefault(),le(0);break}case"End":{p.preventDefault(),Re();break}case"Enter":if(!p.nativeEvent.isComposing&&p.keyCode!==229){p.preventDefault();let D=ne();if(D){let C=new Event(Gt);D.dispatchEvent(C)}}}}},s.createElement("label",{"cmdk-label":"",htmlFor:R.inputId,id:R.labelId,style:Gr},f),ht(t,p=>s.createElement(as.Provider,{value:b},s.createElement(ss.Provider,{value:R},p))))}),Dr=s.forwardRef((t,n)=>{var a,r;let i=s.useId(),o=s.useRef(null),d=s.useContext(rs),l=Ge(),f=os(t),h=(r=(a=f.current)==null?void 0:a.forceMount)!=null?r:d==null?void 0:d.forceMount;be(()=>{if(!h)return l.item(i,d==null?void 0:d.id)},[h]);let u=ls(i,o,[t.value,t.children,o],t.keywords),v=en(),k=ye($=>$.value&&$.value===u.current),w=ye($=>h||l.filter()===!1?!0:$.search?$.filtered.items.get(i)>0:!0);s.useEffect(()=>{let $=o.current;if(!(!$||t.disabled))return $.addEventListener(Gt,E),()=>$.removeEventListener(Gt,E)},[w,t.onSelect,t.disabled]);function E(){var $,b;m(),(b=($=f.current).onSelect)==null||b.call($,u.current)}function m(){v.setState("value",u.current,!0)}if(!w)return null;let{disabled:x,value:N,onSelect:S,forceMount:y,keywords:_,...g}=t;return s.createElement(X.div,{ref:Be([o,n]),...g,id:i,"cmdk-item":"",role:"option","aria-disabled":!!x,"aria-selected":!!k,"data-disabled":!!x,"data-selected":!!k,onPointerMove:x||l.disablePointerSelection?void 0:m,onClick:x?void 0:E},t.children)}),Ir=s.forwardRef((t,n)=>{let{heading:a,children:r,forceMount:i,...o}=t,d=s.useId(),l=s.useRef(null),f=s.useRef(null),h=s.useId(),u=Ge(),v=ye(w=>i||u.filter()===!1?!0:w.search?w.filtered.groups.has(d):!0);be(()=>u.group(d),[]),ls(d,l,[t.value,t.heading,f]);let k=s.useMemo(()=>({id:d,forceMount:i}),[i]);return s.createElement(X.div,{ref:Be([l,n]),...o,"cmdk-group":"",role:"presentation",hidden:v?void 0:!0},a&&s.createElement("div",{ref:f,"cmdk-group-heading":"","aria-hidden":!0,id:h},a),ht(t,w=>s.createElement("div",{"cmdk-group-items":"",role:"group","aria-labelledby":a?h:void 0},s.createElement(rs.Provider,{value:k},w))))}),Or=s.forwardRef((t,n)=>{let{alwaysRender:a,...r}=t,i=s.useRef(null),o=ye(d=>!d.search);return!a&&!o?null:s.createElement(X.div,{ref:Be([i,n]),...r,"cmdk-separator":"",role:"separator"})}),Lr=s.forwardRef((t,n)=>{let{onValueChange:a,...r}=t,i=t.value!=null,o=en(),d=ye(u=>u.search),l=ye(u=>u.value),f=Ge(),h=s.useMemo(()=>{var u;let v=(u=f.listInnerRef.current)==null?void 0:u.querySelector(`${Qt}[${he}="${encodeURIComponent(l)}"]`);return v==null?void 0:v.getAttribute("id")},[]);return s.useEffect(()=>{t.value!=null&&o.setState("search",t.value)},[t.value]),s.createElement(X.input,{ref:n,...r,"cmdk-input":"",autoComplete:"off",autoCorrect:"off",spellCheck:!1,"aria-autocomplete":"list",role:"combobox","aria-expanded":!0,"aria-controls":f.listId,"aria-labelledby":f.labelId,"aria-activedescendant":h,id:f.inputId,type:"text",value:i?t.value:d,onChange:u=>{i||o.setState("search",u.target.value),a==null||a(u.target.value)}})}),Mr=s.forwardRef((t,n)=>{let{children:a,label:r="Suggestions",...i}=t,o=s.useRef(null),d=s.useRef(null),l=Ge();return s.useEffect(()=>{if(d.current&&o.current){let f=d.current,h=o.current,u,v=new ResizeObserver(()=>{u=requestAnimationFrame(()=>{let k=f.offsetHeight;h.style.setProperty("--cmdk-list-height",k.toFixed(1)+"px")})});return v.observe(f),()=>{cancelAnimationFrame(u),v.unobserve(f)}}},[]),s.createElement(X.div,{ref:Be([o,n]),...i,"cmdk-list":"",role:"listbox","aria-label":r,id:l.listId},ht(t,f=>s.createElement("div",{ref:Be([d,l.listInnerRef]),"cmdk-list-sizer":""},f)))}),Fr=s.forwardRef((t,n)=>{let{open:a,onOpenChange:r,overlayClassName:i,contentClassName:o,container:d,...l}=t;return s.createElement($r,{open:a,onOpenChange:r},s.createElement(Er,{container:d},s.createElement(Ar,{"cmdk-overlay":"",className:i}),s.createElement(Pr,{"aria-label":t.label,"cmdk-dialog":"",className:o},s.createElement(is,{ref:n,...l}))))}),Ur=s.forwardRef((t,n)=>ye(a=>a.filtered.count===0)?s.createElement(X.div,{ref:n,...t,"cmdk-empty":"",role:"presentation"}):null),Hr=s.forwardRef((t,n)=>{let{progress:a,children:r,label:i="Loading...",...o}=t;return s.createElement(X.div,{ref:n,...o,"cmdk-loading":"",role:"progressbar","aria-valuenow":a,"aria-valuemin":0,"aria-valuemax":100,"aria-label":i},ht(t,d=>s.createElement("div",{"aria-hidden":!0},d)))}),z=Object.assign(is,{List:Mr,Item:Dr,Input:Lr,Group:Ir,Separator:Or,Dialog:Fr,Empty:Ur,Loading:Hr});function Vr(t,n){let a=t.nextElementSibling;for(;a;){if(a.matches(n))return a;a=a.nextElementSibling}}function Br(t,n){let a=t.previousElementSibling;for(;a;){if(a.matches(n))return a;a=a.previousElementSibling}}function os(t){let n=s.useRef(t);return be(()=>{n.current=t}),n}var be=typeof window>"u"?s.useEffect:s.useLayoutEffect;function Ce(t){let n=s.useRef();return n.current===void 0&&(n.current=t()),n}function Be(t){return n=>{t.forEach(a=>{typeof a=="function"?a(n):a!=null&&(a.current=n)})}}function ye(t){let n=en(),a=()=>t(n.snapshot());return s.useSyncExternalStore(n.subscribe,a,a)}function ls(t,n,a,r=[]){let i=s.useRef(),o=Ge();return be(()=>{var d;let l=(()=>{var h;for(let u of a){if(typeof u=="string")return u.trim();if(typeof u=="object"&&"current"in u)return u.current?(h=u.current.textContent)==null?void 0:h.trim():i.current}})(),f=r.map(h=>h.trim());o.value(t,l,f),(d=n.current)==null||d.setAttribute(he,l),i.current=l}),i}var Wr=()=>{let[t,n]=s.useState(),a=Ce(()=>new Map);return be(()=>{a.current.forEach(r=>r()),a.current=new Map},[t]),(r,i)=>{a.current.set(r,i),n({})}};function Kr(t){let n=t.type;return typeof n=="function"?n(t.props):"render"in n?n.render(t.props):t}function ht({asChild:t,children:n},a){return t&&s.isValidElement(n)?s.cloneElement(Kr(n),{ref:n.ref},a(n.props.children)):a(n)}var Gr={position:"absolute",width:"1px",height:"1px",padding:"0",margin:"-1px",overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",borderWidth:"0"};const Oe=s.forwardRef(({className:t,...n},a)=>e.jsx(z,{ref:a,className:q("flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",t),...n}));Oe.displayName=z.displayName;const Le=s.forwardRef(({className:t,...n},a)=>e.jsxs("div",{className:"flex items-center border-b px-3","cmdk-input-wrapper":"",children:[e.jsx(ta,{className:"mr-2 h-4 w-4 shrink-0 opacity-50"}),e.jsx(z.Input,{ref:a,className:q("flex h-11 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",t),...n})]}));
57Le.displayName=z.Input.displayName;const Me=s.forwardRef(({className:t,...n},a)=>e.jsx(z.List,{ref:a,className:q("max-h-[300px] overflow-y-auto overflow-x-hidden",t),...n}));Me.displayName=z.List.displayName;const Fe=s.forwardRef((t,n)=>e.jsx(z.Empty,{ref:n,className:"py-6 text-center text-sm",...t}));Fe.displayName=z.Empty.displayName;const Ue=s.forwardRef(({className:t,...n},a)=>e.jsx(z.Group,{ref:a,className:q("overflow-hidden p-1 text-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",t),...n}));Ue.displayName=z.Group.displayName;const qr=s.forwardRef(({className:t,...n},a)=>e.jsx(z.Separator,{ref:a,className:q("-mx-1 h-px bg-border",t),...n}));qr.displayName=z.Separator.displayName;const se=s.forwardRef(({className:t,...n},a)=>e.jsx(z.Item,{ref:a,className:q("relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none data-[disabled=true]:pointer-events-none data-[selected='true']:bg-accent data-[selected=true]:text-accent-foreground data-[disabled=true]:opacity-50",t),...n}));se.displayName=z.Item.displayName;const Cn=[{value:"test_connection",label:"Connection Test (Simple Ping)"},{value:"outbid_alert",label:"Outbid Alert"},{value:"auction_won",label:"You Ended High Bidder"},{value:"new_vehicle_listed",label:"New Vehicle Listed"},{value:"auction_ending_soon",label:"Auction Ending Soon"},{value:"daily_auction_ending_digest",label:"Daily Auction Digest"},{value:"auctions_closing_today_digest",label:"Auctions Closing Today (11am & 2pm PT)"},{value:"counter_offer_received",label:"Counter Offer Received"},{value:"appointment_request",label:"Appointment Requested"},{value:"appointment_scheduled",label:"Appointment Scheduled"},{value:"appointment_reminder",label:"Appointment Reminder"},{value:"offer_accepted",label:"Offer Accepted"}],$n=[{value:"admin_car_sold",label:"Admin: Car Sold"},{value:"admin_appointment_scheduled",label:"Admin: Appointment Scheduled"}],Rt={make_enabled:!1,make_webhook_url:"",make_events:{outbid_alert:!0,auction_won:!0,new_vehicle_listed:!0,auction_ending_soon:!0,daily_auction_ending_digest:!0,auctions_closing_today_digest:!0,counter_offer_received:!0,appointment_request:!0,appointment_scheduled:!0,appointment_reminder:!0,offer_accepted:!0}},zr=[{key:"outbid_alert",label:"Outbid Alert",description:"Notify dealers when they have been outbid",icon:Yt},{key:"auction_won",label:"You Ended High Bidder",description:"Notify dealers when they end as high bidder",icon:An},{key:"new_vehicle_listed",label:"New Vehicle Listed",description:"Alert dealers about new vehicles in auction",icon:Xt},{key:"auction_ending_soon",label:"Auction Ending Soon (Per Vehicle)",description:"Individual reminder before each auction ends",icon:He},{key:"daily_auction_ending_digest",label:"Daily Auction Digest",description:"Aggregated email ~30 min before the configured sale-end time, listing all vehicles ending in that sale",icon:He},{key:"auctions_closing_today_digest",label:"Auctions Closing Today",description:"Single email to ALL dealers listing every vehicle in today's sale. Sent ~4 hours and ~1 hour before the configured sale-end time on Mon/Wed/Fri.",icon:He},{key:"counter_offer_received",label:"Counter Offer Received",description:"When a seller counters a direct offer",icon:Ot},{key:"appointment_request",label:"Appointment Requested",description:"When customers request vehicle appointments",icon:ot},{key:"appointment_scheduled",label:"Appointment Scheduled",description:"When an appointment is confirmed with date/time",icon:Zt},{key:"appointment_reminder",label:"Appointment Reminder",description:"Day-of reminder for appointments",icon:qt},{key:"offer_accepted",label:"Offer Accepted",description:"When a customer accepts a dealer's offer and moves to Sold – Waiting for Appointment",icon:In}];function Yr(){const[t,n]=s.useState(Rt),[a,r]=s.useState(!0),[i,o]=s.useState(!1),[d,l]=s.useState(!1),[f,h]=s.useState(null),[u,v]=s.useState("test_connection"),[k,w]=s.useState([]),[E,m]=s.useState([]),[x,N]=s.useState(null),[S,y]=s.useState(null),[_,g]=s.useState(!1),[$,b]=s.useState(!1),[R,W]=s.useState(!1),[Z,J]=s.useState({admin_car_sold:!0,admin_appointment_scheduled:!0}),[Q,Pe]=s.useState([]),[ne,oe]=s.useState(!1),[le,Te]=s.useState("admin_car_sold"),[je,Re]=s.useState(!0),[ce,De]=s.useState(""),[p,A]=s.useState(""),[D,C]=s.useState(!1),[L,H]=s.useState(null),[V,ee]=s.useState(null),[te,pt]=s.useState(null),[qe,tn]=s.useState([]),[nn,cs]=s.useState(!1),[sn,vt]=s.useState(!1),[an,xt]=s.useState(!1);s.useEffect(()=>{hs(),ds(),on(),ps()},[]),s.useEffect(()=>{y(null),m([]),x&&rn(x,m,W)},[x]),s.useEffect(()=>{pt(null),tn([]),V&&rn(V,tn,cs)},[V]);const ds=async()=>{const{data:c,error:j}=await F.from("dealerships").select("id, name").order("name",{ascending:!0});if(j){console.error("Failed to load dealerships",j);return}w(c||[])},rn=async(c,j,M)=>{M(!0);try{const O=new Date(Date.now()-7776e6).toISOString(),{data:B}=await F.from("cars").select("id, year, make, model, vin, updated_at").eq("dealership_id",c).gte("updated_at",O).order("updated_at",{ascending:!1}).limit(25),{data:G}=await F.from("dealership_users").select("user_id").eq("dealership_id",c);let Ye=[];
57if(G&&G.length>0){const we=G.map(js=>js.user_id),{data:yt}=await F.from("cars").select("id, year, make, model, vin, updated_at").in("high_bidder_id",we).gte("updated_at",O).order("updated_at",{ascending:!1}).limit(25);Ye=yt||[]}const{data:bt}=await F.from("cars").select("id, year, make, model, vin, updated_at").in("status",["review_submission","pending_review","pending"]).gte("updated_at",O).order("updated_at",{ascending:!1}).limit(25),ys=[...B||[],...Ye,...bt||[]],cn=new Set,_s=ys.filter(we=>cn.has(we.id)?!1:(cn.add(we.id),!0)).sort((we,yt)=>(yt.updated_at||"").localeCompare(we.updated_at||""));j(_s.slice(0,50))}catch(O){console.error("Failed to load vehicles for dealership",O)}finally{M(!1)}},gt=s.useMemo(()=>{var c;return(c=k.find(j=>j.id===x))==null?void 0:c.name},[k,x]),us=s.useMemo(()=>{const c=E.find(j=>j.id===S);return c?`${c.year??""} ${c.make??""} ${c.model??""}`.trim()+(c.vin?` · ${c.vin.slice(-6)}`:""):null},[E,S]),ms=s.useMemo(()=>{var c;return(c=k.find(j=>j.id===V))==null?void 0:c.name},[k,V]),fs=s.useMemo(()=>{const c=qe.find(j=>j.id===te);return c?`${c.year??""} ${c.make??""} ${c.model??""}`.trim()+(c.vin?` · ${c.vin.slice(-6)}`:""):null},[qe,te]),hs=async()=>{r(!0);try{const{data:c,error:j}=await F.from("auction_settings").select("setting_key, setting_value").in("setting_key",["make_enabled","make_webhook_url","make_events","make_admin_events"]);if(j)throw j;const M={...Rt};let O={admin_car_sold:!0,admin_appointment_scheduled:!0};c==null||c.forEach(B=>{const G=B.setting_key;G==="make_enabled"?M.make_enabled=B.setting_value===!0||B.setting_value==="true":G==="make_webhook_url"?M.make_webhook_url=typeof B.setting_value=="string"?B.setting_value.replace(/"/g,""):String(B.setting_value||""):G==="make_events"?typeof B.setting_value=="object"&&(M.make_events={...Rt.make_events,...B.setting_value}):G==="make_admin_events"&&typeof B.setting_value=="object"&&B.setting_value&&(O={...O,...B.setting_value})}),n(M),J(O)}catch(c){console.error("Error fetching Make.com settings:",c),P.error("Failed to load Make.com settings")}finally{r(!1)}},on=async()=>{oe(!0);try{const{data:c,error:j}=await F.from("user_roles").select("user_id").eq("role","admin").eq("admin_level","master");if(j)throw j;const M=(c||[]).map(B=>B.user_id);if(M.length===0){Pe([]);return}const{data:O}=await F.from("users").select("id, name, email").in("id",M);Pe((O||[]).sort((B,G)=>(B.name||B.email||"").localeCompare(G.name||G.email||"")))}catch(c){console.error("Failed to load master admins",c)}finally{oe(!1)}},ps=async()=>{try{const{data:{user:c}}=await F.auth.getUser();if(c!=null&&c.email){De(c.email);const{data:j}=await F.from("users").select("name").eq("id",c.id).maybeSingle();A((j==null?void 0:j.name)||"Admin")}}catch(c){console.warn("Could not load current user",c)}},ze=async(c,j)=>{const{error:M}=await F.from("auction_settings").upsert({setting_key:c,setting_value:j,description:`Make.com Integration - ${c}`,updated_at:new Date().toISOString()},{onConflict:"setting_key"});if(M)throw M},vs=async()=>{o(!0);try{await Promise.all([ze("make_enabled",t.make_enabled),ze("make_webhook_url",t.make_webhook_url),ze("make_events",t.make_events),ze("make_admin_events",Z)]),P.success("Make.com settings saved successfully")}catch(c){console.error("Error saving Make.com settings:",c),P.error("Failed to save Make.com settings")}finally{o(!1)}},ln=c=>{J(j=>({...j,[c]:!j[c]}))},xs=async()=>{var c;if(!t.make_webhook_url){P.error("Please enter a webhook URL first");return}C(!0),H(null);try{const j={event_type:le,test_mode:!0},M=te||S;M&&(j.car_id=M),V&&(j.test_dealership_id=V),je&&ce&&(j.test_recipient_email=ce,j.test_recipient_name=p||"Admin");const{data:O,error:B}=await F.functions.invoke("admin-notification-orchestrator",{body:j});if(B)throw B;if(O!=null&&O.success){H("success");const G=((c=$n.find(bt=>bt.value===le))==null?void 0:c.label)||le,Ye=je?` (sent only to ${ce})`:` (sent to ${(O==null?void 0:O.recipients_count)??"?"} master admin${((O==null?void 0:O.recipients_count)??0)===1?"":"s"})`;P.success(`Test "${G}" dispatched${Ye}`)}else H("error"),P.error((O==null?void 0:O.error)||(O==null?void 0:O.reason)||"Admin test failed")}catch(j){console.error("Admin test failed:",j),H("error"),P.error((j==null?void 0:j.message)||"Failed to send admin test")}finally{C(!1)}},gs=async()=>{var c;if(!t.make_webhook_url){P.error("Please enter a webhook URL first");return}l(!0),h(null);try{const{data:j,error:M}=await F.functions.invoke("make-dealer-webhook",{body:{event_type:u,test_mode:!0,test_event_type:u,test_dealership_id:x||void 0,test_car_id:S||void 0}});if(M)throw M;if(j!=null&&j.success){h("success");const O=((c=Cn.find(G=>G.value===u))==null?void 0:c.label)||u,B=gt?` as ${gt}`:"";P.success(`Test "${O}"${B} sent successfully! Check your Make.com scenario.`)}else h("error"),P.error((j==null?void 0:j.error)||"Connection test failed")}catch(j){console.error("Error testing Make.com connection:",j),h("error"),P.error("Failed to test c
57onnection")}finally{l(!1)}},bs=c=>{n(j=>({...j,make_events:{...j.make_events,[c]:!j.make_events[c]}}))};return a?e.jsx(re,{children:e.jsx(ie,{className:"flex items-center justify-center py-8",children:e.jsx(Y,{className:"h-6 w-6 animate-spin text-muted-foreground"})})}):e.jsxs(re,{children:[e.jsx(Ee,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsxs(Ae,{className:"flex items-center gap-2",children:[e.jsx(la,{className:"h-5 w-5"}),"Make.com Dealer Notifications"]}),e.jsx(We,{children:"Send SMS and email notifications to dealers via Make.com automation"})]}),e.jsx(xe,{variant:t.make_enabled?"default":"secondary",children:t.make_enabled?"Enabled":"Disabled"})]})}),e.jsxs(ie,{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between rounded-lg border p-4 bg-muted/30",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(I,{className:"text-base font-medium",children:"Enable Make.com Integration"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"When enabled, dealer notifications will be sent to Make.com for automated workflows"})]}),e.jsx(ve,{checked:t.make_enabled,onCheckedChange:c=>n(j=>({...j,make_enabled:c}))})]}),e.jsx(pe,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(I,{htmlFor:"make-webhook-url",children:"Make.com Webhook URL"}),e.jsx(ge,{id:"make-webhook-url",value:t.make_webhook_url,onChange:c=>n(j=>({...j,make_webhook_url:c.target.value})),placeholder:"https://hook.us1.make.com/..."}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Create a Webhook trigger in Make.com and paste the URL here"})]}),e.jsx(pe,{}),e.jsxs("div",{className:"space-y-4",children:[e.jsx(I,{className:"text-base font-medium",children:"Dealer Notification Events"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Choose which events trigger notifications to dealers via Make.com"}),e.jsx("div",{className:"grid gap-3",children:zr.map(c=>{const j=c.icon;return e.jsxs("div",{className:"flex items-center justify-between rounded-lg border p-3 hover:bg-muted/30 transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex h-8 w-8 items-center justify-center rounded-md bg-primary/10",children:e.jsx(j,{className:"h-4 w-4 text-primary"})}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:c.label}),e.jsx("p",{className:"text-xs text-muted-foreground",children:c.description})]})]}),e.jsx(ve,{checked:t.make_events[c.key],onCheckedChange:()=>bs(c.key)})]},c.key)})})]}),e.jsx(pe,{}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx(I,{className:"text-sm font-medium",children:"Send a Test Webhook"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Pick an event, optionally pick a real dealership + vehicle to populate the payload with their actual data (great for mapping fields in Make.com)."})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(st,{value:u,onValueChange:v,children:[e.jsx(at,{className:"w-[220px]",children:e.jsx(rt,{placeholder:"Select event type"})}),e.jsx(it,{children:Cn.map(c=>e.jsx(ae,{value:c.value,children:c.label},c.value))})]}),e.jsxs(Xe,{open:_,onOpenChange:g,children:[e.jsx(Ze,{asChild:!0,children:e.jsxs(U,{variant:"outline",role:"combobox","aria-expanded":_,className:"w-[240px] justify-between",children:[e.jsx("span",{className:"truncate",children:gt||"— Use mock data —"}),e.jsx(Qe,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(Je,{className:"w-[300px] p-0",align:"start",children:e.jsxs(Oe,{children:[e.jsx(Le,{placeholder:"Search dealership…"}),e.jsxs(Me,{children:[e.jsx(Fe,{children:"No dealership found."}),e.jsxs(Ue,{children:[e.jsxs(se,{value:"__none__",onSelect:()=>{N(null),g(!1)},children:[e.jsx(de,{className:q("mr-2 h-4 w-4",x?"opacity-0":"opacity-100")}),"— Use mock data —"]}),k.map(c=>e.jsxs(se,{value:c.name,onSelect:()=>{N(c.id),g(!1)},children:[e.jsx(de,{className:q("mr-2 h-4 w-4",x===c.id?"opacity-100":"opacity-0")}),c.name]},c.id))]})]})]})})]}),x&&e.jsxs(Xe,{open:$,onOpenChange:b,children:[e.jsx(Ze,{asChild:!0,children:e.jsxs(U,{variant:"outline",role:"combobox","aria-expanded":$,className:"w-[260px] justify-between",disabled:R,children:[e.jsx("span",{className:"truncate",children:R?"Loading vehicles…":us||"— Auto-pick most recent —"}),e.jsx(Qe,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(Je,{className:"w-[320px] p-0",align:"start",children:e.jsxs(Oe,{children:[e.jsx(Le,{placeholder:"Search vehicle…"}
57),e.jsxs(Me,{children:[e.jsx(Fe,{children:E.length===0?"No recent vehicles found.":"No match."}),e.jsxs(Ue,{children:[e.jsxs(se,{value:"__auto__",onSelect:()=>{y(null),b(!1)},children:[e.jsx(de,{className:q("mr-2 h-4 w-4",S?"opacity-0":"opacity-100")}),"— Auto-pick most recent —"]}),E.map(c=>{const j=`${c.year??""} ${c.make??""} ${c.model??""}`.trim(),M=c.vin?` · ${c.vin.slice(-6)}`:"";return e.jsxs(se,{value:`${j} ${c.vin??""}`,onSelect:()=>{y(c.id),b(!1)},children:[e.jsx(de,{className:q("mr-2 h-4 w-4",S===c.id?"opacity-100":"opacity-0")}),j,M]},c.id)})]})]})]})})]}),e.jsxs(U,{variant:"outline",onClick:gs,disabled:d||!t.make_webhook_url,children:[d?e.jsx(Y,{className:"mr-2 h-4 w-4 animate-spin"}):f==="success"?e.jsx(Dt,{className:"mr-2 h-4 w-4 text-green-500"}):f==="error"?e.jsx(It,{className:"mr-2 h-4 w-4 text-destructive"}):e.jsx(dt,{className:"mr-2 h-4 w-4"}),"Send Test"]}),e.jsx("div",{className:"ml-auto",children:e.jsxs(U,{onClick:vs,disabled:i,children:[i?e.jsx(Y,{className:"mr-2 h-4 w-4 animate-spin"}):null,"Save Settings"]})})]})]}),e.jsx(pe,{}),e.jsxs("div",{className:"space-y-4 rounded-lg border border-blue-200 bg-blue-50/50 p-4 dark:border-blue-900 dark:bg-blue-950/30",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"flex h-9 w-9 items-center justify-center rounded-md bg-blue-600 text-white",children:e.jsx(na,{className:"h-5 w-5"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx(I,{className:"text-base font-medium",children:"Admin-Facing Notifications"}),e.jsxs("p",{className:"text-sm text-muted-foreground mt-0.5",children:["Sent to all ",e.jsx("strong",{children:"Master Admin"})," accounts via the same Make.com webhook. Routed in your scenario by ",e.jsx("code",{className:"text-xs bg-muted px-1 py-0.5 rounded",children:"event_type"}),"."]})]})]}),e.jsxs("div",{className:"grid gap-3",children:[e.jsxs("div",{className:"flex items-center justify-between rounded-lg border bg-background p-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex h-8 w-8 items-center justify-center rounded-md bg-emerald-100 dark:bg-emerald-900/40",children:e.jsx(Yt,{className:"h-4 w-4 text-emerald-700 dark:text-emerald-300"})}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:"Admin: Car Sold"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Fires when any vehicle is sold (offer accepted)"})]})]}),e.jsx(ve,{checked:Z.admin_car_sold,onCheckedChange:()=>ln("admin_car_sold")})]}),e.jsxs("div",{className:"flex items-center justify-between rounded-lg border bg-background p-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex h-8 w-8 items-center justify-center rounded-md bg-emerald-100 dark:bg-emerald-900/40",children:e.jsx(Zt,{className:"h-4 w-4 text-emerald-700 dark:text-emerald-300"})}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:"Admin: Appointment Scheduled"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Fires when any dealership has an appointment confirmed"})]})]}),e.jsx(ve,{checked:Z.admin_appointment_scheduled,onCheckedChange:()=>ln("admin_appointment_scheduled")})]})]}),e.jsxs("div",{className:"rounded-lg border bg-background p-3",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs(I,{className:"text-sm font-medium flex items-center gap-2",children:[e.jsx(Us,{className:"h-4 w-4"}),"Master Admin Recipients",e.jsx(xe,{variant:"secondary",className:"ml-1",children:Q.length})]}),e.jsx(U,{variant:"ghost",size:"sm",onClick:on,disabled:ne,className:"h-7 text-xs",children:ne?e.jsx(Y,{className:"h-3 w-3 animate-spin"}):"Refresh"})]}),e.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:"These admins automatically receive every admin-facing notification."}),Q.length===0&&!ne?e.jsxs("p",{className:"text-xs text-amber-700 dark:text-amber-400",children:["No master admins found. Assign ",e.jsx("code",{children:"admin_level = 'master'"})," in ",e.jsx("code",{children:"user_roles"})," to enroll recipients."]}):e.jsx("ul",{className:"divide-y rounded-md border",children:Q.map(c=>e.jsxs("li",{className:"flex items-center justify-between px-3 py-2",children:[e.jsx("span",{className:"text-sm font-medium",children:c.name||"—"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:c.email||"no email"})]},c.id))})]}),e.jsxs("div",{className:"rounded-lg border bg-background p-3 space-y-3",children:[e.jsxs("div",{children:[e.jsx(I,{className:"text-sm font-medium",children:"Send Admin Test"}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["Dispatch a test admin payload. Pick a real dealership + vehicle below to populate the data, or leave as ",e.jsx("span",{className:"font-mono",children:"— Use mock data —"}),"."]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(I,{className:"text-xs text-muted-foreground",children:"Event Type"}),e.jsxs(st,{value:le,onValueChange:Te,children:[e.jsx(at,{className:"w-full",children:e.jsx(rt,{placeholder:"Select admin event"})}),e.jsx(it,{children:$n.map(c=>e.jsx(ae,{value:c.value,children:c.label},c.value))})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(I,{className:"text-xs text-muted-foreground",children:"Recipient"}),e.jsxs(st,{value:je&&ce?`solo:${ce}`:"all",onValueChange:c=>{if(c==="all"){Re(!1);return}if(c.startsWith("solo:")){const j=c.slice(5),M=Q.find(O=>(O.email||"").toLowerCase()===j.toLowerCase());De(j),A((M==null?void 0:M.name)||"Admin"),Re(!0)}},children:[e.jsx(at,{className:"w-full",children:e.jsx(rt,{placeholder:"Select recipient"})}),e.jsxs(it,{children:[e.jsxs(ae,{value:"all",children:["All Master Admins (",Q.length,")"]}),Q.filter(c=>!!c.email).map(c=>e.jsx(ae,{value:`solo:${c.email}`,children:c.name?`${c.name} — ${c.email}`:c.email},c.id))]})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(I,{className:"text-xs text-muted-foreground",children:"Mock Dealership"}),e.jsxs(Xe,{open:sn,onOpenChange:vt,children:[e.jsx(Ze,{asChild:!0,children:e.jsxs(U,{variant:"outline",role:"combobox","aria-expanded":sn,className:"w-full justify-between",children:[e.jsx("span",{className:"truncate",children:ms||"— Use mock data —"}),e.jsx(Qe,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(Je,{className:"w-[300px] p-0",align:"start",children:e.jsxs(Oe,{children:[e.jsx(Le,{placeholder:"Search dealership…"}),e.jsxs(Me,{children:[e.jsx(Fe,{children:"No dealership found."}),e.jsxs(Ue,{children:[e.jsxs(se,{value:"__none__",onSelect:()=>{ee(null),vt(!1)},children:[e.jsx(de,{className:q("mr-2 h-4 w-4",V?"opacity-0":"opacity-100")}),"— Use mock data —"]}),k.map(c=>e.jsxs(se,{value:c.name,onSelect:()=>
57{ee(c.id),vt(!1)},children:[e.jsx(de,{className:q("mr-2 h-4 w-4",V===c.id?"opacity-100":"opacity-0")}),c.name]},c.id))]})]})]})})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(I,{className:"text-xs text-muted-foreground",children:"Mock Vehicle"}),e.jsxs(Xe,{open:an,onOpenChange:xt,children:[e.jsx(Ze,{asChild:!0,children:e.jsxs(U,{variant:"outline",role:"combobox","aria-expanded":an,className:"w-full justify-between",disabled:!V||nn,children:[e.jsx("span",{className:"truncate",children:V?nn?"Loading vehicles…":fs||"— Auto-pick most recent —":"— Pick a dealership first —"}),e.jsx(Qe,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(Je,{className:"w-[320px] p-0",align:"start",children:e.jsxs(Oe,{children:[e.jsx(Le,{placeholder:"Search vehicle…"}),e.jsxs(Me,{children:[e.jsx(Fe,{children:qe.length===0?"No recent vehicles found.":"No match."}),e.jsxs(Ue,{children:[e.jsxs(se,{value:"__auto__",onSelect:()=>{pt(null),xt(!1)},children:[e.jsx(de,{className:q("mr-2 h-4 w-4",te?"opacity-0":"opacity-100")}),"— Auto-pick most recent —"]}),qe.map(c=>{const j=`${c.year??""} ${c.make??""} ${c.model??""}`.trim(),M=c.vin?` · ${c.vin.slice(-6)}`:"";return e.jsxs(se,{value:`${j} ${c.vin??""}`,onSelect:()=>{pt(c.id),xt(!1)},children:[e.jsx(de,{className:q("mr-2 h-4 w-4",te===c.id?"opacity-100":"opacity-0")}),j,M]},c.id)})]})]})]})})]})]})]}),e.jsx("div",{className:"flex justify-end",children:e.jsxs(U,{variant:"outline",onClick:xs,disabled:D||!t.make_webhook_url,children:[D?e.jsx(Y,{className:"mr-2 h-4 w-4 animate-spin"}):L==="success"?e.jsx(Dt,{className:"mr-2 h-4 w-4 text-green-500"}):L==="error"?e.jsx(It,{className:"mr-2 h-4 w-4 text-destructive"}):e.jsx(dt,{className:"mr-2 h-4 w-4"}),"Send Admin Test"]})})]})]}),e.jsxs("div",{className:"rounded-lg border border-purple-200 bg-purple-50 p-4 dark:border-purple-900 dark:bg-purple-950",children:[e.jsx("h4",{className:"font-medium text-purple-900 dark:text-purple-100 mb-2",children:"How it works"}),e.jsxs("ul",{className:"text-sm text-purple-800 dark:text-purple-200 space-y-1 list-disc list-inside",children:[e.jsx("li",{children:"Create a scenario in Make.com with a Webhook trigger"}),e.jsx("li",{children:"Add Twilio/Telnyx for SMS and SendGrid for email"}),e.jsx("li",{children:"Use filters based on dealer preferences (prefers_sms, prefers_email)"}),e.jsx("li",{children:"Dealers can customize their notification preferences in their account settings"}),e.jsx("li",{children:"This is separate from GHL which handles seller/customer notifications"})]})]})]})]})}function Si(){const[t,n]=s.useState([]),[a,r]=s.useState(!0),[i,o]=s.useState(!1),[d,l]=s.useState(""),[f,h]=s.useState(null),[u,v]=s.useState(!1),k=async()=>{r(!0);const{data:_,error:g}=await F.from("auction_api_keys").select("id, key_prefix, name, is_active, last_used_at, created_at, expires_at").order("created_at",{ascending:!1});g?(P.error("Failed to fetch API keys"),console.error(g)):n(_||[]),r(!1)};s.useEffect(()=>{k()},[]);const w=()=>{const _=new Uint8Array(32);return crypto.getRandomValues(_),Array.from(_,g=>g.toString(16).padStart(2,"0")).join("")},E=async _=>{const $=new TextEncoder().encode(_),b=await crypto.subtle.digest("SHA-256",$);return Array.from(new Uint8Array(b)).map(W=>W.toString(16).padStart(2,"0")).join("")},m=async()=>{var W;if(!d.trim()){P.error("Please enter a name for the API key");return}const _=w(),g=await E(_),$=_.substring(0,8),{data:b}=await F.auth.getUser(),{error:R}=await F.from("auction_api_keys").insert({key_hash:g,key_prefix:$,name:d.trim(),created_by:(W=b==null?void 0:b.user)==null?void 0:W.id,is_active:!0});R?(P.error("Failed to create API key"),console.error(R)):(h(_),k())},x=()=>{f&&(navigator.clipboard.writeText(f),P.success("API key copied to clipboard"))},N=()=>{o(!1),l(""),h(null),v(!1)},S=async(_,g)=>{const{error:$}=await F.from("auction_api_keys").update({is_active:!g}).eq("id",_);$?P.error("Failed to update key status"):(P.success(`API key ${g?"revoked":"activated"}`),k())},y=async _=>{if(!confirm("Are you sure you want to permanently delete this API key?"))return;const{error:g}=await F.from("auction_api_keys").delete().eq("id",_);g?P.error("Failed to delete API key"):(P.success("API key deleted"),k())};return e.jsxs("div",{className:"container mx-auto p-6 space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-2xl font-bold flex items-center gap-2",children:[e.jsx(Hs,{className:"h-6 w-6"}),"API Key Management"]}),e.jsx("p",{className:"text-muted-foreground",children:"Manage API keys for external auction system integration"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(U,{variant:"outline",onClick:k,disabled:a,children:[e.jsx(zt,{className:`h-4 w-4 mr-2 ${a?"animate-spin":""}`}),"Refresh"]}),e.jsxs(Ks,{open:i,onOpenChange:o,children:[e.jsx(Gs,{asChild:!0,children:e.jsxs(U,{children:[e.jsx(sa,{className:"h-4 w-4 mr-2"}),"Generate New Key"]})}),e.jsxs(qs,{children:[e.jsxs(zs,{children:[e.jsx(Ys,{children:f?"API Key Generated":"Generate New API Key"}),e.jsx(Xs,{children:f?"Copy this key now. You won't be able to see it again.":"Create a new API key for external auction system access."})]}),f?e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs(Lt,{variant:"destructive",children:[e.jsx(Rn,{className:"h-4 w-4"}),e.jsx(Mt,{children:"Important"}),e.jsx(Ft,{children:"This is the only time you'll see this API key. Copy it now and store it securely."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(I,{children:"API Key"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(ge,{readOnly:!0,t
57ype:u?"text":"password",value:f,className:"font-mono text-sm"}),e.jsx(U,{variant:"outline",size:"icon",onClick:()=>v(!u),children:u?e.jsx(aa,{className:"h-4 w-4"}):e.jsx(ut,{className:"h-4 w-4"})}),e.jsx(U,{variant:"outline",size:"icon",onClick:x,children:e.jsx(Tn,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{className:"bg-muted p-3 rounded-md",children:[e.jsx("p",{className:"text-sm font-medium mb-2",children:"Usage:"}),e.jsxs("code",{className:"text-xs block bg-background p-2 rounded",children:["curl -X POST \\",e.jsx("br",{}),'  -H "x-auction-api-key: ',f.substring(0,8),'..." \\',e.jsx("br",{}),'  -H "Content-Type: application/json" \\',e.jsx("br",{}),`  -d '{"vehicles": [...]}' \\`,e.jsx("br",{}),"  https://ykppdfajqmeqsjxmkcjf.supabase.co/functions/v1/auction-webhook"]})]}),e.jsx("div",{className:"flex justify-end",children:e.jsx(U,{onClick:N,children:"Done"})})]}):e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(I,{htmlFor:"key_name",children:"Key Name *"}),e.jsx(ge,{id:"key_name",placeholder:"e.g., Production Auction Integration",value:d,onChange:_=>l(_.target.value)}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"A descriptive name to identify this API key"})]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(U,{variant:"outline",onClick:N,children:"Cancel"}),e.jsx(U,{onClick:m,children:"Generate Key"})]})]})]})]})]})]}),e.jsxs(re,{children:[e.jsxs(Ee,{children:[e.jsxs(Ae,{children:["API Keys (",t.length,")"]}),e.jsx(We,{children:"Active and revoked API keys for auction webhook authentication"})]}),e.jsx(ie,{children:a?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"Loading..."}):t.length===0?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"No API keys found. Generate one to get started."}):e.jsxs(Vs,{children:[e.jsx(Bs,{children:e.jsxs(dn,{children:[e.jsx(me,{children:"Name"}),e.jsx(me,{children:"Key Prefix"}),e.jsx(me,{children:"Status"}),e.jsx(me,{children:"Last Used"}),e.jsx(me,{children:"Created"}),e.jsx(me,{children:"Expires"}),e.jsx(me,{className:"text-right",children:"Actions"})]})}),e.jsx(Ws,{children:t.map(_=>e.jsxs(dn,{children:[e.jsx(fe,{className:"font-medium",children:_.name}),e.jsxs(fe,{className:"font-mono",children:[_.key_prefix,"..."]}),e.jsx(fe,{children:e.jsx(xe,{variant:_.is_active?"default":"secondary",children:_.is_active?"Active":"Revoked"})}),e.jsx(fe,{children:_.last_used_at?_t(new Date(_.last_used_at),"MMM d, yyyy HH:mm"):"Never"}),e.jsx(fe,{children:_t(new Date(_.created_at),"MMM d, yyyy")}),e.jsx(fe,{children:_.expires_at?_t(new Date(_.expires_at),"MMM d, yyyy"):"Never"}),e.jsx(fe,{className:"text-right",children:e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(U,{variant:_.is_active?"outline":"default",size:"sm",onClick:()=>S(_.id,_.is_active),children:_.is_active?"Revoke":"Activate"}),e.jsx(U,{variant:"ghost",size:"icon",className:"text-destructive hover:text-destructive",onClick:()=>y(_.id),children:e.jsx(ra,{className:"h-4 w-4"})})]})})]},_.id))})]})})]}),e.jsx(ca,{}),e.jsx(ua,{}),e.jsx(pa,{}),e.jsx(Yr,{}),e.jsxs(re,{children:[e.jsx(Ee,{children:e.jsx(Ae,{children:"API Documentation"})}),e.jsxs(ie,{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"text-lg font-semibold",children:"Vehicle Import (Nexus → Review Pipeline)"}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-medium mb-2",children:"Endpoint"}),e.jsx("code",{className:"bg-muted px-2 py-1 rounded text-sm",children:"POST https://ykppdfajqmeqsjxmkcjf.supabase.co/functions/v1/import-vehicle"})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-medium mb-2",children:"Authentication"}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Include the API key in the ",e.jsx("code",{className:"bg-muted px-1 rounded",children:"x-api-key"})," or ",e.jsx("code",{className:"bg-muted px-1 rounded",children:"x-auction-api-key"})," header."]})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-medium mb-2",children:"Request Body Example"}),e.jsx("pre",{className:"bg-muted p-3 rounded text-xs overflow-x-auto",children:`{
58  "vehicle": {
59    "vin": "1HGCV1F3XLA000001",
60    "year": 2022,
61    "make": "Honda",
62    "model": "Accord",
63    "mileage": 45000,
64    "color": "White",
65    "condition": "good"
66  },
67  "images": ["https://example.com/photo1.jpg"],
68  "source": "nexus"
69}`})]})]}),e.jsx("hr",{}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"text-lg font-semibold",children:"Auction Pricing Engine"}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-medium mb-2",children:"Endpoint"}),e.jsx("code",{className:"bg-muted px-2 py-1 rounded text-sm",children:"POST https://ykppdfajqmeqsjxmkcjf.supabase.co/functions/v1/auction-webhook"})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-medium mb-2",children:"Authentication"}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Include the API key in the ",e.jsx("code",{className:"bg-muted px-1 rounded",children:"x-auction-api-key"})," header."]})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-medium mb-2",children:"Request Body Example"}),e.jsx("pre",{className:"bg-muted p-3 rounded text-xs overflow-x-auto",children:`{
70  "vehicles": [
71    {
72      "year": 2022,
73      "make": "Ford",
74      "model": "F-150",
75      "mileage": 45000,
76      "condition": "good",
77      "retail_value": 35000,
78      "market_days_supply": 32,
79      "auction_lot_id": "LOT-2024-12345"
80    }
81  ],
82  "dealer_ids": ["DEALER-001", "DEALER-002"]
83}`})]})]})]})]})]})}export{Si 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.