(()=>{var e,t,s,a={6221:(e,t,s)=>{"use strict";s.d(t,{A:()=>l});var a=s(69783);class n extends a.A{getMountPath(){return"/ws/socket.io/"}}const l=new n},12055:(e,t,s)=>{"use strict";function a(e){const t=new URLSearchParams(window.location.search);t.delete(e);const s=window.location.pathname+(t.toString()?"?"+t.toString():"");window.history.replaceState({},"",s)}s.d(t,{V:()=>a})},23046:(e,t,s)=>{"use strict";s.d(t,{Gt:()=>n,Zk:()=>l,wE:()=>a});const a=()=>"https://app.base44.com";function n(){return a()+"/api"}function l(){return n()}},24394:()=>{},55194:(e,t,s)=>{"use strict";s.d(t,{O5:()=>l,QF:()=>r,VO:()=>n,b3:()=>a.A});s(73215);var a=s(76976);function n(){let e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];return a.A.fetchToken(e)}function l(e){a.A.setToken(e)}function r(){a.A.setToken(null)}},69167:(e,t,s)=>{"use strict";var a={};s.r(a),s.d(a,{cn:()=>Pe});var n={};s.r(n),s.d(n,{Alert:()=>De,AlertDescription:()=>Be,AlertTitle:()=>Fe});var l={};s.r(l),s.d(l,{Tooltip:()=>Et,TooltipContent:()=>Tt,TooltipProvider:()=>St,TooltipTrigger:()=>It});var r={};s.r(r),s.d(r,{Button:()=>Yt,buttonVariants:()=>Ht});var i={};s.r(i),s.d(i,{Badge:()=>es,badgeVariants:()=>Xt});var o={};s.r(o),s.d(o,{Card:()=>is,CardContent:()=>ms,CardDescription:()=>ds,CardFooter:()=>us,CardHeader:()=>os,CardTitle:()=>cs});var c={};s.r(c),s.d(c,{Separator:()=>ps});var d={};s.r(d),s.d(d,{Input:()=>fs});var m={};s.r(m),s.d(m,{Label:()=>Ns});var u={};s.r(u),s.d(u,{RadioGroup:()=>As,RadioGroupItem:()=>Ss});var x={};s.r(x),s.d(x,{Select:()=>zs,SelectContent:()=>Ys,SelectGroup:()=>Us,SelectItem:()=>$s,SelectLabel:()=>Gs,SelectScrollDownButton:()=>Hs,SelectScrollUpButton:()=>Vs,SelectSeparator:()=>Js,SelectTrigger:()=>qs,SelectValue:()=>Ws});var h={};s.r(h),s.d(h,{Avatar:()=>ma,AvatarFallback:()=>xa,AvatarImage:()=>ua});var p={};s.r(p),s.d(p,{Dialog:()=>Pa,DialogClose:()=>Ra,DialogContent:()=>Da,DialogDescription:()=>Ua,DialogFooter:()=>Ba,DialogHeader:()=>Fa,DialogOverlay:()=>Ma,DialogPortal:()=>Oa,DialogTitle:()=>za,DialogTrigger:()=>La});var g={};s.r(g),s.d(g,{reducer:()=>Xa,toast:()=>an,useToast:()=>nn});var f={};s.r(f),s.d(f,{Table:()=>zl,TableBody:()=>Wl,TableCaption:()=>Gl,TableCell:()=>Yl,TableFooter:()=>ql,TableHead:()=>Hl,TableHeader:()=>Ul,TableRow:()=>Vl});var v={};s.r(v),s.d(v,{Tabs:()=>kr,TabsContent:()=>Sr,TabsList:()=>Cr,TabsTrigger:()=>Ar});var b={};s.r(b),s.d(b,{DropdownMenu:()=>qr,DropdownMenuCheckboxItem:()=>Xr,DropdownMenuContent:()=>Kr,DropdownMenuGroup:()=>Hr,DropdownMenuItem:()=>Qr,DropdownMenuLabel:()=>ti,DropdownMenuPortal:()=>Yr,DropdownMenuRadioGroup:()=>$r,DropdownMenuRadioItem:()=>ei,DropdownMenuSeparator:()=>si,DropdownMenuShortcut:()=>ai,DropdownMenuSub:()=>Gr,DropdownMenuSubContent:()=>Zr,DropdownMenuSubTrigger:()=>Jr,DropdownMenuTrigger:()=>Vr});var j={};s.r(j),s.d(j,{Checkbox:()=>dm});var y={};s.r(y),s.d(y,{Textarea:()=>um});var N={};s.r(N),s.d(N,{ScrollArea:()=>gm,ScrollBar:()=>fm});var w={};s.r(w),s.d(w,{Switch:()=>ix});var _={};s.r(_),s.d(_,{Collapsible:()=>Fx,CollapsibleContent:()=>zx,CollapsibleTrigger:()=>Bx});var k={};s.r(k),s.d(k,{Command:()=>nh,CommandDialog:()=>lh,CommandEmpty:()=>oh,CommandGroup:()=>ch,CommandInput:()=>rh,CommandItem:()=>mh,CommandList:()=>ih,CommandSeparator:()=>dh,CommandShortcut:()=>uh});var C={};s.r(C),s.d(C,{Calendar:()=>fh});var A={};s.r(A),s.d(A,{Popover:()=>Nh,PopoverContent:()=>_h,PopoverTrigger:()=>wh});var S={};s.r(S),s.d(S,{Sheet:()=>tp,SheetClose:()=>ap,SheetContent:()=>ip,SheetDescription:()=>mp,SheetFooter:()=>cp,SheetHeader:()=>op,SheetOverlay:()=>lp,SheetPortal:()=>np,SheetTitle:()=>dp,SheetTrigger:()=>sp});var E={};s.r(E),s.d(E,{Skeleton:()=>hg});var I={};s.r(I),s.d(I,{Toast:()=>Lf,ToastAction:()=>Of,ToastClose:()=>Rf,ToastDescription:()=>Df,ToastProvider:()=>If,ToastTitle:()=>Mf,ToastViewport:()=>Tf});var T={};s.r(T),s.d(T,{Toaster:()=>Bf});var P={};s.r(P),s.d(P,{AlertDialog:()=>fv,AlertDialogAction:()=>Cv,AlertDialogCancel:()=>Av,AlertDialogContent:()=>yv,AlertDialogDescription:()=>kv,AlertDialogFooter:()=>wv,AlertDialogHeader:()=>Nv,AlertDialogOverlay:()=>jv,AlertDialogPortal:()=>bv,AlertDialogTitle:()=>_v,AlertDialogTrigger:()=>vv});var L={};s.r(L),s.d(L,{Progress:()=>xy});var O={};s.r(O),s.d(O,{Accordion:()=>uS,AccordionContent:()=>pS,AccordionItem:()=>xS,AccordionTrigger:()=>hS});var R={};s.r(R),s.d(R,{AspectRatio:()=>gS});var M={};s.r(M),s.d(M,{Carousel:()=>kS,CarouselContent:()=>CS,CarouselItem:()=>AS,CarouselNext:()=>ES,CarouselPrevious:()=>SS});var D={};s.r(D),s.d(D,{ContextMenu:()=>zS,ContextMenuCheckboxItem:()=>ZS,ContextMenuContent:()=>$S,ContextMenuGroup:()=>WS,ContextMenuItem:()=>JS,ContextMenuLabel:()=>QS,ContextMenuPortal:()=>qS,ContextMenuRadioGroup:()=>HS,ContextMenuRadioItem:()=>KS,ContextMenuSeparator:()=>XS,ContextMenuShortcut:()=>eE,ContextMenuSub:()=>VS,ContextMenuSubContent:()=>GS,ContextMenuSubTrigger:()=>YS,ContextMenuTrigger:()=>US});var F={};s.r(F),s.d(F,{Form:()=>lE,FormControl:()=>uE,FormDescription:()=>xE,FormField:()=>iE,FormItem:()=>dE,FormLabel:()=>mE,FormMessage:()=>hE,useFormField:()=>oE});var B={};s.r(B),s.d(B,{HoverCard:()=>fE,HoverCardContent:()=>bE,HoverCardTrigger:()=>vE});var z={};s.r(z),s.d(z,{Menubar:()=>DE,MenubarCheckboxItem:()=>qE,MenubarContent:()=>UE,MenubarGroup:()=>LE,MenubarItem:()=>WE,MenubarLabel:()=>HE,MenubarMenu:()=>PE,MenubarPortal:()=>OE,MenubarRadioGroup:()=>ME,MenubarRadioItem:()=>VE,MenubarSeparator:()=>YE,MenubarShortcut:()=>GE,MenubarSub:()=>RE,MenubarSubContent:()=>zE,MenubarSubTrigger:()=>BE,MenubarTrigger:()=>FE});var U={};s.r(U),s.d(U,{NavigationMenu:()=>tI,NavigationMenuContent:()=>rI,NavigationMenuIndicator:()=>cI,NavigationMenuItem:()=>aI,NavigationMenuLink:()=>iI,NavigationMenuList:()=>sI,NavigationMenuTrigger:()=>lI,NavigationMenuViewport:()=>oI,navigationMenuTriggerStyle:()=>nI});var W={};s.r(W),s.d(W,{Slider:()=>uI});var q={};s.r(q),s.d(q,{Toggle:()=>gI,toggleVariants:()=>pI});var V={};s.r(V),s.d(V,{Toaster:()=>vI});var H={};s.r(H),s.d(H,{Sidebar:()=>HI,SidebarContent:()=>XI,SidebarFooter:()=>KI,SidebarGroup:()=>eT,SidebarGroupAction:()=>sT,SidebarGroupContent:()=>aT,SidebarGroupLabel:()=>tT,SidebarHeader:()=>ZI,SidebarInput:()=>JI,SidebarInset:()=>$I,SidebarMenu:()=>nT,SidebarMenuAction:()=>oT,SidebarMenuBadge:()=>cT,SidebarMenuButton:()=>iT,SidebarMenuItem:()=>lT,SidebarMenuSkeleton:()=>dT,SidebarMenuSub:()=>mT,SidebarMenuSubButton:()=>xT,SidebarMenuSubItem:()=>uT,SidebarProvider:()=>VI,SidebarRail:()=>GI,SidebarSeparator:()=>QI,SidebarTrigger:()=>YI,useSidebar:()=>qI});var Y=s(9950),G=s(1352),$=s.t(G,2),J=s(42074),Z=s(28429),K=s(89379),Q=s(84125),X=s(36642),ee=s(23046);class te extends Q.y{getBaseURL(){return"/auth"}getCurrentUser(){return this.axios.get("/me")}regenerateApiKey(){return this.axios.post("/regenerate_api_key")}updateUser(e,t){return this.axios.post("/".concat(e,"/update-user"),(0,K.A)({},t))}listUsers(e){return this.axios.get("/list-users",{params:e})}async checkDomainSSO(e){try{return(await X.A.get("".concat((0,ee.Gt)(),"/workspace/public/sso/check-email-or-domain"),{params:{email_or_domain:e}})).data}catch(t){return{has_sso:!1}}}login(e,t){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;const a={email:e,password:t};return s&&(a.turnstile_token=s),this.axios.post("/login",a)}register(e,t){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null;const n={email:e,password:t};return s&&(n.turnstile_token=s),a&&(n.referral_code=a),this.axios.post("/register",n)}verifyOtp(e,t){return this.axios.post("/verify-otp",{email:e,otp_code:t})}resendOtp(e){return this.axios.post("/resend-otp",{email:e})}resetPasswordRequest(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;const s={email:e};return t&&(s.turnstile_token=t),this.axios.post("/reset-password-request",s)}resetPassword(e,t){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;const a={reset_token:e,new_password:t};return s&&(a.turnstile_token=s),this.axios.post("/reset-password",a)}changePassword(e,t,s){return this.axios.post("/change-password",{user_id:e,current_password:t,new_password:s})}}const se=new te;var ae=s(73215),ne=s(55194),le=s(44414);const re=(0,Y.createContext)(),ie=e=>{let{children:t}=e;const[s,a]=(0,Y.useState)(null),[n,l]=(0,Y.useState)(!1),[r,i]=(0,Y.useState)(!0);(0,Y.useEffect)(()=>{const e=(0,ne.VO)(!0);e?(localStorage.setItem("token",e),(0,ae.yI)("Authorization","Bearer ".concat(e)),c()):i(!1),(0,ae.Vp)(e=>{e.response&&401===e.response.status&&o()})},[]);const o=()=>{localStorage.removeItem("token"),localStorage.removeItem("base44_access_token"),(0,ae.xL)("Authorization"),a(null),l(!1),i(!1)},c=async()=>{try{i(!0);const e=await se.getCurrentUser();return a(e),l(!0),i(!1),e}catch(e){i(!1),o()}},d=(0,Y.useCallback)(async()=>{const e=await se.getCurrentUser();e&&a(e)},[]);return(0,le.jsx)(re.Provider,{value:{user:s,isAuthenticated:n,logout:function(){let e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];if(o(),l(!1),a(null),e){const e=encodeURIComponent(window.location.href);window.location.href="/login?from_url="+e}},isLoadingAuth:r,updateUser:e=>{a(e)},reloadUser:d},children:t})},oe=()=>(0,Y.useContext)(re);var ce=s(6221);class de extends Q.H{getBaseURL(){return"/workspace/invitations"}inviteUser(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"member",s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;const a=s?{workspaceId:s}:{};return this.axios.post("/invite",{email:e,role:t},{params:a})}bulkInviteUsers(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;const s=t?{workspaceId:t}:{};return this.axios.post("/bulk-invite",{invitations:e},{params:s})}getInvitationDetails(e){return this.axios.get("/".concat(e))}acceptInvitation(e){return this.axios.post("/".concat(e,"/accept"))}declineInvitation(e){return this.axios.post("/".concat(e,"/decline"))}}const me=new de;class ue extends Q.H{getBaseURL(){return"/workspace"}getWorkspaces(){return this.axios.get("/workspaces")}getAvailablePlans(){return this.axios.get("/available-plans")}createWorkspace(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return this.axios.post("/workspaces",{name:e,domain:t})}getDashboard(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;const t=e?{workspaceId:e}:{};return this.axios.get("",{params:t})}subscribeToDashboard(e,t,s){const a="workspace/".concat(e,"/dashboard");return s(t),ce.A.addListener(a,e=>{t=(0,K.A)((0,K.A)({},t),e),s(t,Object.keys(e))},async()=>{try{const t=await this.getDashboard(e);s(t,Object.keys(t))}catch(t){}})}updateWorkspace(e,t){const s=e?{workspaceId:e}:{};return this.axios.put("/update",t,{params:s})}inviteUser(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"member",s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;return me.inviteUser(e,t,s)}bulkInviteUsers(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return me.bulkInviteUsers(e,t)}buySeats(e,t){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;const a=s?{workspaceId:s}:{};return this.axios.post("/buy-seats",{plan:e,count:t},{params:a})}removeSeats(e,t){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;const a=s?{workspaceId:s}:{};return this.axios.post("/remove-seats",{plan:e,count:t},{params:a})}updateMemberRole(e,t){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;const a=s?{workspaceId:s}:{};return this.axios.put("/members/".concat(e,"/role"),{role:t},{params:a})}updateMemberSeat(e,t){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null;const n=s?{workspaceId:s}:{},l={seat_type:t};return null!==a&&(l.seat_id=a),this.axios.put("/members/".concat(e,"/seat"),l,{params:n})}removeMember(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;const s=t?{workspaceId:t}:{};return this.axios.delete("/members/".concat(e),{params:s})}getMySeatInfo(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;const t=e?{workspaceId:e}:{};return this.axios.get("/my-seat",{params:t})}getSeatUsage(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;const s=t?{workspaceId:t}:{};return this.axios.get("/seats/".concat(e,"/usage"),{params:s})}getWorkspaceInvoices(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;const t=e?{workspaceId:e}:{};return this.axios.get("/invoices",{params:t})}getInvitationDetails(e){return me.getInvitationDetails(e)}acceptInvitation(e){return me.acceptInvitation(e)}declineInvitation(e){return me.declineInvitation(e)}createWorkspacePortalSession(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;const t=e?{workspaceId:e}:{};return this.axios.post("/create-portal-session",{},{params:t})}checkSensitiveFeaturePermission(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;const s={feature:e};return t&&(s.organizationId=t),this.axios.get("/sensitive-feature-permission",{params:s})}}const xe=new ue,he=(0,Y.createContext)();function pe(e){let{children:t}=e;const[s,a]=(0,Y.useState)(()=>localStorage.getItem("activeWorkspaceId")||null),[n,l]=(0,Y.useState)([]),[r,i]=(0,Y.useState)(!0),[o,c]=(0,Y.useState)(!0),[d,m]=(0,Y.useState)(null),{reloadUser:u,isAuthenticated:x,user:h}=oe(),p=(0,Y.useMemo)(()=>{if(!s||!n.length)return null;return n.find(e=>e.id===s)||null},[s,n]);(0,Y.useEffect)(()=>((0,ae.r8)(()=>s),x&&u(),()=>{(0,ae.r8)(()=>null),x&&u()}),[s,x,u]),(0,Y.useEffect)(()=>{if(null==h||!h.id)return void i(!1);const e=localStorage.getItem("activeWorkspaceId");e&&(0,ae.r8)(()=>e),i(!1)},[null==h?void 0:h.id]),(0,Y.useEffect)(()=>{s?localStorage.setItem("activeWorkspaceId"+(null==h?void 0:h.id),s):localStorage.removeItem("activeWorkspaceId"+(null==h?void 0:h.id))},[s,null==h?void 0:h.id]);const g=(0,Y.useCallback)(async()=>{try{c(!0),m(null);const e=await xe.getWorkspaces();l(e.workspaces||e||[])}catch(e){m(e),l([])}finally{c(!1)}},[]);(0,Y.useEffect)(()=>{g()},[g]);const f=(0,Y.useCallback)(e=>{const t="string"==typeof e?e:null==e?void 0:e.id;a(t),(0,ae.r8)(()=>t),t?localStorage.setItem("activeWorkspaceId",t):localStorage.removeItem("activeWorkspaceId")},[]),v=(0,Y.useCallback)(()=>{a(null),(0,ae.r8)(()=>null),localStorage.removeItem("activeWorkspaceId")},[]),b={activeWorkspace:p,activeWorkspaceId:s,workspaces:n,isLoading:r,isLoadingWorkspaces:o,error:d,switchActiveWorkspace:f,clearActiveWorkspace:v,refetchWorkspaces:g};return(0,le.jsx)(he.Provider,{value:b,children:t})}function ge(){const e=(0,Y.useContext)(he);if(void 0===e)throw new Error("useWorkspace must be used within a WorkspaceProvider");return e}class fe extends Q.y{getBaseURL(){return"/apps"}addMessage(e,t){return this.axios.post("/".concat(e,"/chat/message"),t)}undoMessage(e,t){return this.axios.post("/".concat(e,"/chat/message/").concat(t,"/undo"))}inviteUser(e,t,s){return this.axios.post("/".concat(e,"/users/invite-user"),{user_email:t,role:s})}remixApp(e,t){return this.axios.post("/".concat(e,"/remix"),t)}remixAppRequirements(e){return this.axios.get("/".concat(e,"/remix/requirements"))}updateLogo(e,t){return this.axios.post("/".concat(e,"/metadata/update-logo"),t)}generateLogoFromPrompt(e,t){return this.axios.post("/".concat(e,"/metadata/generate-logo"),t)}stopChat(e){return this.axios.post("/".concat(e,"/chat/stop"))}submitToolCallInput(e,t,s,a){return this.axios.post("/".concat(e,"/chat/submit-tool-call-input"),{tool_call_id:t,action:s?"approved":"rejected",extra_user_input:a})}getDomainAppId(e){return this.axios.get("/public/prod/domain/".concat(e))}getRuntimeAuthToken(e,t){return this.axios.get("/".concat(e,"/auth/token"))}getLoginInfoBySlug(e){return this.axios.get("/public/login-info/by-slug/".concat(e))}getLoginInfoById(e){return this.axios.get("/public/login-info/by-id/".concat(e))}getSuggestions(e){return this.axios.get("/".concat(e,"/chat/suggestions/edit"))}dismissDomainSuggestion(e){return this.axios.put("/".concat(e,"/chat/suggestions/edit/dismiss-domain-suggestion"))}deployApp(e){return this.axios.post("/".concat(e,"/deploy"))}installIntegration(e,t,s){return this.axios.post("/".concat(e,"/install-integration/").concat(t,"/").concat(s))}deleteIntegration(e,t,s){return this.axios.post("/".concat(e,"/delete-integration/").concat(t,"/").concat(s))}redeployFunction(e,t,s){return this.axios.post("/".concat(e,"/coding/redeploy-function/").concat(t),{code:s})}moveToWorkspace(e,t){return this.axios.post("/".concat(e,"/metadata/move-to-workspace"),{target_workspace_id:t})}loadFullConversation(e){return this.axios.get("/".concat(e,"/chat/full-conversation"))}}const ve=new fe,be=s.p+"static/media/logo_v3.d98750a7c406dd97e5db.png";var je=s(34700),ye=s(67143),Ne=s(42989),we=s(61041),_e=s(52828),ke=s(75888),Ce=s(41397),Ae=s.n(Ce),Se=s(53986),Ee=s(94364),Ie=s(72004),Te=s(79800);function Pe(){for(var e=arguments.length,t=new Array(e),s=0;ssvg~*]:pl-7 [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-foreground",{variants:{variant:{default:"bg-background text-foreground",destructive:"border-destructive/50 text-destructive dark:border-destructive [&>svg]:text-destructive"}},defaultVariants:{variant:"default"}}),De=Y.forwardRef((e,t)=>{let{className:s,variant:a}=e,n=(0,Se.A)(e,Le);return(0,le.jsx)("div",(0,K.A)({ref:t,role:"alert",className:Pe(Me({variant:a}),s)},n))});De.displayName="Alert";const Fe=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,Oe);return(0,le.jsx)("h5",(0,K.A)({ref:t,className:Pe("mb-1 font-medium leading-none tracking-tight",s)},a))});Fe.displayName="AlertTitle";const Be=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,Re);return(0,le.jsx)("div",(0,K.A)({ref:t,className:Pe("text-sm [&_p]:leading-relaxed",s)},a))});Be.displayName="AlertDescription";class ze extends Q.H{getBaseURL(){return"/apps"}write(e,t,s){return this.axios.post("/".concat(e,"/coding/write"),{file_path:t,content:s})}exportToGithub(e){return this.axios.post("/".concat(e,"/coding/export-to-github"))}updateGithubRepo(e){return this.axios.post("/".concat(e,"/coding/update-github-repo"))}exportToZip(e){return this.axios.get("/".concat(e,"/coding/export-to-zip"),{responseType:"blob"})}inviteCollaborator(e,t){return this.axios.post("/".concat(e,"/coding/invite-collaborator"),{collaborator_username:t})}searchGithubUsers(e,t){return this.axios.post("/".concat(e,"/coding/search-github-users"),{query:t})}}const Ue=new ze;class We extends Q.y{getBaseURL(){return"/apps"}updateSecrets(e,t){return this.axios.post("/".concat(e,"/secrets"),t)}deleteSecret(e,t){return this.axios.delete("/".concat(e,"/secrets/").concat(t))}getSecrets(e){return this.axios.get("/".concat(e,"/secrets"))}getGeneralSecrets(e){return(0,ae.Ay)("/secrets").get(e)}}const qe=new We;var Ve=s(74925);const He="mixpanel_utm_params",Ye="mixpanel_utm_timestamp",Ge=["utm_source","utm_medium","utm_campaign","utm_content","utm_term","utm_id","utm_campaign_id","utm_source_platform","utm_creative_format","utm_marketing_tactic","impact_click_id"],$e=()=>{try{const e=localStorage.getItem(He),t=localStorage.getItem(Ye);return{params:e?JSON.parse(e):{},timestamp:t?parseInt(t):null}}catch(e){return{params:{},timestamp:null}}},Je={signup:{src:189,evid:1204},login:{src:189,evid:1200}};const Ze=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"signup",s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};try{if(!e)return;const a=Je[t];if(!a)return;const n=function(e){const t="; ".concat(document.cookie).split("; ".concat(e,"="));return 2===t.length?t.pop().split(";").shift():null}("_wixCIDX")||"no-cookie-found",l=e||"no-user-id",r={dt:0,e:[{dt:0,f:{src:a.src,evid:a.evid}}],g:{uuid:l,client_id:n}};Object.keys(s).length>0&&(r.additional_data=s),fetch("https://frog.wix.com/base44",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)}).then(e=>{if(!e.ok)throw new Error("Frog service responded with status: ".concat(e.status));return e.text()}).then(e=>{}).catch(e=>{})}catch(a){}},Ke=e=>{const t={event_type:"signup",timestamp:(new Date).toISOString()};Ze(e,"signup",t)};let Qe={feature_flags:[],tier:null};const Xe=[];function et(e,t){const s=(0,K.A)((0,K.A)({},t),{},{feature_flags:t.feature_flags||Qe.feature_flags,tier:t.tier||Qe.tier});Ve.A.track(e,s)}const tt=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};Ve.A.__loaded?et(e,t):Xe.push(()=>et(e,t))};function st(){const{user:e,isLoadingAuth:t}=oe();return(0,Y.useEffect)(()=>{if(t)return;Ve.A.init("eff913a25a5a2642acc7794bb28dc621",{debug:!1,opt_out_tracking_by_default:!1,ignore_dnt:!0,loaded:()=>{Ve.A.__loaded=!0;const{params:t}=$e();if(Object.keys(t).length>0&&Ve.A.register(t),e){s=e.id,Ve.A.__loaded?Ve.A.identify(s):Xe.push(()=>Ve.A.identify(s));const a={};for(Object.assign(a,t),a.is_beta=e.is_beta_tester||!1,a.tier=e.subscription_tier||"free",Qe.tier=e.subscription_tier||"free",e.feature_flags&&Array.isArray(e.feature_flags)&&(Qe.feature_flags=e.feature_flags,a.feature_flags=e.feature_flags,e.feature_flags.forEach(e=>{a["ff_".concat(e)]=!0})),((e,t)=>{Ve.A.__loaded?(Ve.A.identify(e),Ve.A.people.set(t)):Xe.push(()=>{Ve.A.identify(e),Ve.A.people.set(t)})})(e.id,a),tt("User Login",t),(e=>{const t={event_type:"login",timestamp:(new Date).toISOString()};Ze(e,"login",t)})(e.id);Xe.length>0;){Xe.shift()()}}var s}})},[t,e]),null}const at={signup:{src:189,evid:1204},login:{src:189,evid:1200},message_sent:{src:189,evid:1020},message_completed:{src:189,evid:1019},page_view:{src:189,evid:1023},user_clicked:{src:189,evid:1021},help_center_clicked:{src:189,evid:1308},support_main_page_view:{src:189,evid:1311},support_main_open_ticket_hover:{src:189,evid:1309},support_main_open_ticket_click:{src:189,evid:1310},support_my_tickets_page_view:{src:189,evid:1312},support_my_tickets_new_ticket_click:{src:189,evid:1302},support_ticket_modal_submitted:{src:189,evid:1304},support_ticket_modal_closed:{src:189,evid:1303},support_ticket_modal_view:{src:189,evid:1307},support_ticket_modal_help_type_click:{src:189,evid:1305},support_ticket_modal_bot_helped_click:{src:189,evid:1313},support_ticket_modal_still_need_help_click:{src:189,evid:1314}};function nt(e){return at[e]||null}async function lt(e,t){let{timeoutMs:s=2500}=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};const a=JSON.stringify(t),n=fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:a}),l=await function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:2500;return new Promise((s,a)=>{const n=setTimeout(()=>a(new Error("timeout")),t);e.then(e=>{clearTimeout(n),s(e)},e=>{clearTimeout(n),a(e)})})}(n,s);if(!l.ok)throw new Error("HTTP ".concat(l.status));return l}function rt(e,t){try{const s=new Blob([JSON.stringify(t)],{type:"application/json"});return navigator.sendBeacon(e,s)}catch(s){return!1}}const it="https://frog.wix.com/base44";const ot=new class{constructor(){this._ready=!1,this._readyPromise=null,this._eventQueue=[],this._flushTimer=null,this._isFlushInProgress=!1,this.BATCH_SIZE=10,this.FLUSH_INTERVAL=2e3,this.MAX_QUEUE_SIZE=100}getCookie(e){var t;if("undefined"==typeof document)return null;const s="; ".concat(document.cookie).split("; ".concat(e,"="));return 2===s.length&&(null===(t=s.pop())||void 0===t?void 0:t.split(";").shift())||null}getClientId(){return this.getCookie("_wixCIDX")||"no-cookie-found"}async ensureReady(){if(!this._ready)return this._readyPromise||(this._readyPromise=(async()=>{this._ready=!0})()),this._readyPromise}async track(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};try{await this.ensureReady();if(!nt(e))return;let l;try{l=await s}catch(n){l={}}const r=Date.now();if(a.immediate||a.useBeacon)return this._sendImmediately(e,t,l,r,a);const i={eventKey:e,session:t,additionalData:l,timestamp:r,useBeacon:a.useBeacon};if(this._eventQueue.push(i),this._eventQueue.length>this.MAX_QUEUE_SIZE&&this._eventQueue.shift(),this._eventQueue.length>=this.BATCH_SIZE)try{await this._flush()}catch(n){}else this._scheduleFlush()}catch(n){}}async flush(){try{return await this._flush()}catch(e){}}async _sendImmediately(e,t,s,a,n){try{const l=nt(e),r={dt:0,e:[{dt:0,f:(0,K.A)((0,K.A)({src:l.src,evid:l.evid,timestamp:a},s),t)}],g:{uuid:t.user_id||"no-user-id",client_id:this.getClientId()}};if(n.useBeacon){if(rt(it,r))return}await lt(it,r,{timeoutMs:2500})}catch(l){}}async _flush(){if(!this._isFlushInProgress&&0!==this._eventQueue.length){this._isFlushInProgress=!0;try{this._flushTimer&&(clearTimeout(this._flushTimer),this._flushTimer=null);const t=this._eventQueue.splice(0,this.BATCH_SIZE);let s;try{s=this._groupEventsBySession(t)}catch(e){return}try{await Promise.all(s.map(e=>this._sendEventBatch(e)))}catch(e){}}catch(e){}finally{this._isFlushInProgress=!1,this._eventQueue.length>0&&this._scheduleFlush()}}}_groupEventsBySession(e){const t=new Map;for(const s of e){const e=(null==s?void 0:s.session)||{},a="object"==typeof e&&null!==e&&e.user_id||"no-user",n="object"==typeof e&&null!==e&&e.app_id||"no-app",l="object"==typeof e&&null!==e&&e.conversation_id||"no-conversation",r="".concat(a,"-").concat(n,"-").concat(l);t.has(r)||t.set(r,[]),t.get(r).push(s)}return Array.from(t.values())}_scheduleFlush(){this._flushTimer&&(clearTimeout(this._flushTimer),this._flushTimer=null),this._flushTimer=setTimeout(async()=>{try{await this._flush()}catch(e){}},this.FLUSH_INTERVAL)}async _sendEventBatch(e){if(0!==e.length)try{var t,s;const a=e.some(e=>e.useBeacon),n={dt:0,e:e.map(t=>{const s=nt(t.eventKey);return{dt:t.timestamp-e[0].timestamp,f:(0,K.A)((0,K.A)({src:s.src,evid:s.evid,timestamp:t.timestamp},t.additionalData),t.session)}}),g:{uuid:(null===(t=e[0])||void 0===t||null===(s=t.session)||void 0===s?void 0:s.user_id)||"no-user-id",client_id:this.getClientId(),batch_size:e.length}};if(a){if(!rt(it,n))throw new Error("Beacon send failed")}else await lt(it,n,{timeoutMs:2500})}catch(a){}}destroy(){this._flushTimer&&(clearTimeout(this._flushTimer),this._flushTimer=null),this._eventQueue.length>0&&this._flush().catch(e=>{})}};async function ct(){try{const e=await Promise.resolve().then(s.bind(s,75888));return await e.default.getCurrentUsage()}catch(e){return{daily_limit:null,daily_usage:null,monthly_limit:null,monthly_usage:null}}}async function dt(){return function(e){if(!e)return null;const t="number"==typeof e.daily_limit?e.daily_limit:void 0,s="number"==typeof e.daily_usage?Math.round(e.daily_usage):void 0,a="number"==typeof e.monthly_limit?e.monthly_limit:void 0,n="number"==typeof e.monthly_usage?Math.round(e.monthly_usage):void 0;return"number"==typeof t?"number"!=typeof s?null:Math.max(0,t-s):"number"==typeof a?"number"!=typeof n?null:Math.max(0,a-n):null}(await ct())}function mt(e,t,s){ot.track("message_sent",e,function(e){return{user_message:String(e.user_message||""),has_files:Boolean(e.has_files),is_initial_creation_message:Boolean(e.is_initial_creation_message)}}(t),s)}function ut(e,t,s){ot.track("message_completed",e,async function(e){var t,s,a,n,l,r;const i=null!==(t=e.tokens_left)&&void 0!==t?t:await dt();return{message_id:null!==(s=e.message_id)&&void 0!==s?s:null,user_message:String(e.user_message||""),agent_message:null!==(a=e.agent_message)&&void 0!==a?a:null,model:null!==(n=e.model)&&void 0!==n?n:null,was_successful:Boolean(e.was_successful),tokens_left:i,duration:null!==(l=e.duration)&&void 0!==l?l:null,has_files:Boolean(e.has_files),error_message:null!==(r=e.error_message)&&void 0!==r?r:null,is_initial_creation_message:Boolean(e.is_initial_creation_message)}}(t),s)}function xt(e,t,s){ot.track("page_view",e,function(e){return{page_name:String(e.page_name||"")}}(t),s)}function ht(e,t,s){ot.track("user_clicked",e,function(e){return(0,K.A)({},e)}(t),s)}"undefined"!=typeof window&&window.addEventListener("beforeunload",()=>{ot.destroy()});const pt=e=>{var t,s,a;let{startTime:n,body:l,updatedApp:r=null,userMessageId:i=null,agentMessage:o=null,agentModel:c=null,wasSuccessful:d,error:m=null,userId:u=null,appId:x=null,isInitialCreation:h=!1}=e;const p=Date.now()-n,g=(null==r||null===(t=r.conversation)||void 0===t?void 0:t.id)||null,f={app_id:x,conversation_id:g,message_id:i,message:String((null==l?void 0:l.content)||""),has_files:((null===(s=l.file_urls)||void 0===s?void 0:s.length)||0)>0,user_id:u,was_successful:d,model:c,is_initial_creation_message:h,use_agentic_builder:(null==r?void 0:r.use_agentic_builder)||!1};if(!d&&m){var v,b;const e=m;f.error_message=(null==e||null===(v=e.response)||void 0===v||null===(b=v.data)||void 0===b?void 0:b.message)||(null==e?void 0:e.message)||"unknown"}tt("Message Completed",f),ut({user_id:u,app_id:x,conversation_id:g},(0,K.A)({message_id:i,user_message:String((null==l?void 0:l.content)||""),agent_message:o,model:c,was_successful:d,duration:p,has_files:((null===(a=l.file_urls)||void 0===a?void 0:a.length)||0)>0,is_initial_creation_message:h},f.error_message?{error_message:String(f.error_message)}:{}))};async function gt(e){var t,s;let{appId:a,body:n,app:l=null,user:r=null,onSuccess:i,onError:o}=e;const c=Date.now(),d=0===((null==l||null===(t=l.conversation)||void 0===t||null===(s=t.messages)||void 0===s?void 0:s.length)||0);try{var m,u,x,h;(e=>{var t,s;let{body:a,userId:n=null,appId:l=null,conversationId:r=null,isInitialCreation:i=!1}=e;const o={app_id:l,conversation_id:r,user_id:n,message:String((null==a?void 0:a.content)||""),has_files:((null===(t=a.file_urls)||void 0===t?void 0:t.length)||0)>0,is_initial_creation_message:i};tt("Message Sent",o),mt({user_id:n,app_id:l,conversation_id:r},{user_message:String((null==a?void 0:a.content)||""),has_files:((null===(s=a.file_urls)||void 0===s?void 0:s.length)||0)>0,is_initial_creation_message:i})})({body:n,userId:(null==r?void 0:r.id)||null,appId:a||null,conversationId:(null==l||null===(m=l.conversation)||void 0===m?void 0:m.id)||null,isInitialCreation:d});const e=await ve.addMessage(a,n),t=((e,t)=>{try{const r=e||[];if(null!=t)for(let e=r.length-1;e>=0;e--){var s,a;const n=r[e];if("user"===(null==n?void 0:n.role)&&String(null!==(s=null==n?void 0:n.content)&&void 0!==s?s:"")===String(null!==(a=t)&&void 0!==a?a:""))return(null==n?void 0:n.id)||null}for(let e=r.length-1;e>=0;e--){var n,l;if("user"===(null===(n=r[e])||void 0===n?void 0:n.role))return(null===(l=r[e])||void 0===l?void 0:l.id)||null}return null}catch(r){return null}})((null==e||null===(u=e.conversation)||void 0===u?void 0:u.messages)||null,null==n?void 0:n.content),{message:s,model:o}=(e=>{try{const n=e||[];for(let e=n.length-1;e>=0;e--){var t,s,a;if("assistant"===(null===(t=n[e])||void 0===t?void 0:t.role))return{message:String((null===(s=n[e])||void 0===s?void 0:s.content)||""),model:(null===(a=n[e])||void 0===a?void 0:a.model)||null}}return{message:null,model:null}}catch(n){return{message:null,model:null}}})((null==e||null===(x=e.conversation)||void 0===x?void 0:x.messages)||null),p=null!=e&&null!==(h=e.conversation)&&void 0!==h&&h.id?e:l;return pt({startTime:c,body:n,updatedApp:p||null,userMessageId:t,agentMessage:s,agentModel:o,wasSuccessful:!0,userId:(null==r?void 0:r.id)||null,appId:a||null,isInitialCreation:d}),i&&await i(e),e}catch(p){throw pt({startTime:c,body:n,updatedApp:l||null,userMessageId:null,agentMessage:null,agentModel:null,wasSuccessful:!1,error:p,userId:(null==r?void 0:r.id)||null,appId:a||null,isInitialCreation:d}),o&&await o(p),p}}function ft(){const e=window.location.hostname;if(e.startsWith("checkpoint--")){const t=e.split("--");if(t.length>=3){return t[2].split(".")[0]}}return e.startsWith("preview--")?"preview":"prod"}function vt(e,t,s){let a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};class n extends Q.y{constructor(){super(),this.axios.interceptors.response.use(e=>e,e=>{var a,n;const l="error trying to call ".concat(t.name," entity api: ").concat(e.config.url);let r=e.config.data;try{"string"!=typeof r&&(r=JSON.stringify(r)),r&&r.length>1e3&&(r=r.substring(0,997)+"...")}catch(m){r=String(r)}let i="";try{var o;i=JSON.stringify(null===(o=e.response)||void 0===o?void 0:o.data),i&&i.length>1e3&&(i=i.substring(0,997)+"...")}catch(m){var c;i=String((null===(c=e.response)||void 0===c?void 0:c.data)||"")}const d="When using the app, on url ".concat(window.location.href," the following entity api call failed: \nentity: ").concat(t.name,"\nurl: ").concat(e.config.baseURL).concat(e.config.url,"\nmethod: ").concat(e.config.method,"\ndata: ").concat(r,"\nerror:").concat((null===(a=e.response)||void 0===a||null===(n=a.data)||void 0===n?void 0:n.message)||e.message,"\nfulljson:").concat(i);return s(l,d),Promise.reject(e)})}getBaseURL(){return"https://base44.app/api"+"/apps/".concat(e,"/entities/").concat(t.name)}getClient(){return(0,ae.Ay)(this.getBaseURL(),a,!0,!0)}schema(){return t}bulkCreate(e){return this.axios.post("/bulk",e)}importEntities(e){const t=new FormData;return t.append("file",e,e.name),this.axios.post("/import",t,{headers:{"Content-Type":"multipart/form-data"}})}}return new n}function bt(e,t,s){let a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},n={};return Object.keys(e.entities).forEach(s=>{n[s]=vt(e.id,e.entities[s],t,a)}),n.User=vt(e.id,e.user_entity,t,a),n.User.updateMyUserData=async function(e){return await s.updateMyUserData(e)},n.User.me=async function(){return await s.getMyUserInfo()},n.User.logout=async function(){return await s.logout()},n.User.login=async function(){return await s.login()},n.User.loginWithRedirect=async function(e){return await s.loginWithRedirect(e)},n.User.isUserAuthenticated=function(){return s.isUserAuthenticated()},n}const jt=(0,Y.createContext)(),yt=e=>{let{children:t}=e;const{user:s,reloadUser:a,isAuthenticated:n}=oe(),{appId:l,pageName:r}=(0,Z.g)(),[i,o]=(0,Y.useState)(null),[c,d]=(0,Y.useState)(!0),[m,u]=(0,Y.useState)(!1),[x,h]=(0,Y.useState)(null),[p,g]=(0,Y.useState)([]),[f,v]=(0,Y.useState)(null),[b,j]=(0,Y.useState)(null),[y,N]=(0,Y.useState)([]),[w,_]=(0,Y.useState)(null),k=(0,Y.useRef)(null),[C,A]=(0,Y.useState)(!1),[S,E]=(0,Y.useState)(!1),[I,T]=(0,Y.useState)(null);(0,Y.useEffect)(()=>((0,ae.bx)(()=>l),n&&a(),()=>{(0,ae.bx)(()=>null),n&&a()}),[l,n]),(0,Y.useEffect)(()=>{if(!i||l&&(null==i?void 0:i.id)!==l)return(()=>{let e=null;return(async()=>{try{d(!0);let t=l;e=await ve.fetchAndSubscribe(t,(e,t)=>{if(t&&t.includes("_last_msg")){const t=(e=Ae().cloneDeep(e)).conversation.messages.findIndex(t=>t.id===e._last_msg.id);-1!==t?e.conversation.messages[t]=e._last_msg:e.conversation.messages.push(e._last_msg)}o(e),M()});const[a,n]=await Promise.all([ke.default.getCurrentUsage(),ve.getRuntimeAuthToken(l,s.api_key)]);j(a),L(t),_(n.token),O(t)}catch(n){var t,a;h("Failed to load app : "+((null===(t=n.response)||void 0===t||null===(a=t.data)||void 0===a?void 0:a.message)||n.message))}finally{d(!1)}})(),()=>{e&&e()}})()},[l]);let P=null;r?P=null!=i&&i.pages[r]?{name:r,code:null==i?void 0:i.pages[r]}:null:null!=i&&i.pages&&(P={name:Object.keys(null==i?void 0:i.pages)[0],code:null==i?void 0:i.pages[Object.keys(null==i?void 0:i.pages)[0]]});const L=async e=>{const t=await qe.getSecrets(e);N(Object.keys(t))},O=async e=>{if(!window.location.href.includes("/editor/"))return;const t=await ve.getSuggestions((null==i?void 0:i.id)||e);v(t)};let R=t;c?R=(0,le.jsx)("div",{className:"fixed inset-0 flex justify-center items-center",children:(0,le.jsx)(Ne.A,{className:"h-8 w-8 animate-spin"})}):x?R=(0,le.jsx)("div",{className:"p-8",children:(0,le.jsx)(De,{variant:"destructive",children:(0,le.jsxs)(Be,{children:[x,(0,le.jsx)("div",{className:"mt-2 text-sm",children:"Please try refreshing the page. If the problem persists, please contact our support team."}),(0,le.jsx)("button",{type:"button",onClick:()=>window.open("/support","_blank"),className:"underline text-primary hover:text-orange-500 transition-colors",children:"support system"})]})})}):i||(R=(0,le.jsx)(De,{variant:"destructive",children:(0,le.jsx)(Be,{children:"App not found"})}));const M=()=>{var e;if(!i||c)return;const t=null===(e=s.feature_flags)||void 0===e?void 0:e.includes("use-sandbox-from-ui");i.using_sandbox&&t||g([])};return(0,le.jsx)(jt.Provider,{value:{app:i,setApp:o,updateApp:async e=>{u(!0);try{const t=await ve.update(i.id,e);M(),o(t)}finally{u(!1)}},isLoading:c,isUpdatingApp:m,error:x,getEntitiesSDK:function(e){const t={"X-Bypass-RLS":"true",Authorization:"Bearer ".concat(w)};return bt(i,e,null,t)},appErrors:p,setAppErrors:g,onAppError:(e,t,s)=>{let a;a=Ae().isObject(e)?{title:e.title||e.message||e.toString(),details:e.details||e.stack||e.toString(),componentName:s||r}:{title:e,details:t,componentName:s||r},g(e=>{if(!e.some(e=>e.title===a.title))return[...e,a];{const t=e.find(e=>e.title===a.title);t&&i&&(i.components&&i.components[a.componentName]&&!i.components[t.componentName]||i.pages&&i.pages[a.componentName]&&!i.pages[t.componentName]&&!i.components[t.componentName])&&(t.componentName=a.componentName)}return e})},addChatMessage:async e=>{I&&(e.custom_context=[{type:"element",data:{element_tag_name:I.tagName,filename:I.dataset.filename,linenumber:I.dataset.linenumber},message:"User has selected an element to edit, here's the element's code position: file: ".concat(I.dataset.filename,", line number: ").concat(I.dataset.linenumber)}],T(null),E(!1)),e.additional_message_params=e.additional_message_params||{},P&&(e.additional_message_params.current_page=P.name),i.conversation.messages.push((0,K.A)((0,K.A)({},e),{},{role:"user"}));try{await gt({appId:l,body:e,app:i,user:s,onSuccess:async e=>{o(e),"pending"!==e.app_stage&&O(),await(async()=>{const e=await ke.default.getCurrentUsage();j(e)})()},onError:e=>{}})}catch(t){}},undoMessage:async e=>{try{const t=await ve.undoMessage(l,e);o(t)}catch(s){var t;const e=null===(t=s.response)||void 0===t?void 0:t.status;if(403===e)return void h("You do not have access to this app");if(400===e||404===e||500===e){try{const e=await ve.get(l);o(e)}catch(a){h("Failed to undo message. Please refresh the page.")}return}try{const e=await ve.get(l);o(e)}catch(a){h("An unexpected error occurred. Please refresh the page.")}}},currentPage:P,stopChat:async()=>{const e=await ve.stopChat(i.id);o(e)},submitToolCallInput:async(e,t,s)=>{const a=await ve.submitToolCallInput(i.id,e,t,s);o(a)},loadFullConversation:async()=>{const e=await ve.loadFullConversation(i.id);return o(t=>(0,K.A)((0,K.A)({},t),{},{conversation:e})),e},suggestions:f,refreshSuggestions:O,dismissDomainSuggestion:async()=>{const e=await ve.dismissDomainSuggestion((null==i?void 0:i.id)||l);v(e)},currentUsage:b,isSelectingDivMode:C,setIsSelectingDivMode:A,isElementMode:S,setIsElementMode:E,selectedElement:I,setSelectedElement:T,writeCodeToFile:async(e,t)=>{u(!0);try{const s=await Ue.write(i.id,e,t);M(),o(s)}finally{u(!1)}},existingSecretNames:y,updateSecrets:async e=>{await qe.updateSecrets(l,e),await L(l)},runtimeAuthToken:w,previewIframeRef:k,refreshApp:async()=>{const e=await ve.get(i.id);o(e)}},children:R})},Nt=()=>(0,Y.useContext)(jt);class wt extends Q.H{getBaseURL(){return"/files"}uploadFile(e){const t=new FormData;return t.append("file",e),this.axios.post("/",t,{headers:{"Content-Type":"multipart/form-data"}})}uploadAppFile(e,t){const s=new FormData;return s.append("file",e),this.axios.post("/apps/".concat(t,"/upload"),s,{headers:{"Content-Type":"multipart/form-data"}})}}const _t=new wt;var kt=s(52607),Ct=s(9305);const At=["className","sideOffset"],St=Ct.Kq,Et=Ct.bL,It=Ct.l9,Tt=Y.forwardRef((e,t)=>{let{className:s,sideOffset:a=4}=e,n=(0,Se.A)(e,At);return(0,le.jsx)(Ct.UC,(0,K.A)({ref:t,sideOffset:a,className:Pe("z-50 overflow-hidden rounded-md border bg-popover px-3 py-1.5 text-sm text-popover-foreground shadow-md animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-[--radix-tooltip-content-transform-origin]",s)},n))});function Pt(e){let{onFileUploadClick:t,customButtomRight:s,customButtomLeft:a,variant:n="default"}=e;const[l,r]=(0,Y.useState)(!0),i=(0,Y.useRef)(null);(0,Y.useEffect)(()=>{const e=()=>{if(i.current){const e=i.current.getBoundingClientRect().width;r(e>400)}};return e(),window.addEventListener("resize",e),()=>{window.removeEventListener("resize",e)}},[]);const o="home"===n?"flex justify-between text-sm p-4 rounded-b-xl":"flex justify-between text-sm p-2",c="home"===n?"flex items-center gap-1 px-2 py-1 rounded-md text-xs text-black hover:bg-gray-100":"flex items-center gap-1 px-1 py-1 rounded-md text-xs text-black hover:bg-gray-100",d=(0,le.jsx)(St,{children:(0,le.jsxs)(Et,{children:[(0,le.jsx)(It,{asChild:!0,children:(0,le.jsx)("button",{onClick:t,className:c,children:(0,le.jsx)(kt.A,{className:"h-4 w-4"})})}),(0,le.jsx)(Tt,{children:(0,le.jsx)("p",{children:"Upload files"})})]})});return(0,le.jsxs)("div",{className:o,ref:i,children:[(0,le.jsx)("div",{className:"flex gap-1 items-center",children:a?a(d):d}),(0,le.jsx)("div",{className:"flex gap-1 items-center",children:s})]})}Tt.displayName=Ct.UC.displayName;var Lt=s(59680);function Ot(e){let{files:t,uploadingFiles:s,onRemoveFile:a}=e;const[n,l]=(0,Y.useState)({});return 0===t.length&&0===s.length?null:(0,le.jsxs)("div",{className:"flex flex-wrap gap-4 p-4 border-b",children:[t.map((e,t)=>(0,le.jsx)("div",{className:"relative",children:e.match(/\.(jpg|jpeg|png|gif)$/i)?(0,le.jsxs)("div",{className:"relative group",children:[!n[e]&&(0,le.jsx)("div",{className:"w-[120px] h-[120px] flex items-center justify-center bg-gray-100 rounded-lg",children:(0,le.jsx)(Lt.A,{className:"w-4 h-4 animate-spin text-gray-500"})}),(0,le.jsx)("img",{src:e,alt:"Attached content",className:"max-w-[120px] max-h-[120px] object-contain rounded-lg border border-gray-200 shadow-sm ".concat(n[e]?"":"hidden"),onLoad:()=>(e=>{l(t=>(0,K.A)((0,K.A)({},t),{},{[e]:!0}))})(e)}),(0,le.jsx)("button",{onClick:()=>a(e),className:"absolute top-1 right-1 bg-white/80 text-gray-500 hover:text-gray-700 rounded-full p-1",children:"\xd7"})]}):(0,le.jsxs)("div",{className:"flex items-center gap-2 p-2 bg-white rounded-lg border border-gray-200 group relative",children:[(0,le.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-gray-500",children:[(0,le.jsx)("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),(0,le.jsx)("polyline",{points:"14 2 14 8 20 8"})]}),(0,le.jsx)("span",{className:"truncate max-w-[150px]",children:e.split("/").pop()}),(0,le.jsx)("button",{onClick:()=>a(e),className:"text-gray-500 hover:text-gray-700",children:"\xd7"})]})},t)),s.map((e,t)=>(0,le.jsxs)("div",{className:"flex items-center gap-2 p-2 bg-white rounded-lg border border-gray-200",children:[(0,le.jsx)(Lt.A,{className:"w-4 h-4 animate-spin text-gray-500"}),(0,le.jsxs)("span",{className:"truncate max-w-[150px] text-gray-500 text-sm",children:["Uploading ",e,"..."]})]},t))]})}var Rt=s(19900),Mt=s(88276),Dt=s(53034);const Ft=(0,Y.forwardRef)((e,t)=>{let{value:s,onValueChange:a,onKeyDown:n,onPaste:l,placeholder:r,disabled:i,isProcessing:o,onStop:c,onSend:d,isVisualEditMode:m,isDiscussionMode:u,variant:x="default"}=e;const h=(0,Y.useRef)(null);(0,Y.useImperativeHandle)(t,()=>h.current);(0,Y.useEffect)(()=>{h.current&&"default"===x&&(h.current.style.height="auto",h.current.scrollHeight>400?h.current.style.height="400px":h.current.style.height=h.current.scrollHeight+"px")},[s]);const p="home"===x?"w-full pl-[16px] pt-[6px] pr-12 md:pl-[24px] md:pt-[12px] md:pr-16 font-base44 text-[16px] font-thin mt-2 font-base44 resize-none overflow-auto focus:outline-none bg-transparent placeholder:text-gray-400":"w-full pl-4 pt-4 pr-16 text-sm resize-none overflow-auto focus:outline-none bg-transparent rounded-t-lg",g=Pe("absolute flex justify-center items-center top-4 right-2 md:right-4 p-1 bg-[#FF5C04] hover:bg-orange-600 rounded-[8px] text-white md:rounded-[12px] md:w-[40px] md:h-[40px] w-[30px] h-[30px] transition-colors",{"rotate-90":!o&&!i,"bg-[#FF5C04] cursor-not-allowed":i}),f=i||!s&&!o,v=Pe("absolute flex justify-center items-center top-4 w-[30px] h-[30px] right-4 p-1 text-white rounded-lg transition-colors",{[f?"bg-violet-300":"bg-violet-600 hover:bg-violet-800"]:u,[f?"bg-blue-300":"bg-blue-600 hover:bg-blue-800"]:!u&&m,[f?"bg-gray-400":"bg-gray-900 hover:bg-gray-800"]:!u&&!m}),b="home"===x?g:v;return(0,le.jsxs)("div",{className:"relative",children:[(0,le.jsx)("textarea",{ref:h,value:s,onChange:e=>a(e.target.value),onKeyDown:n,onPaste:l,placeholder:r,disabled:i,className:p,style:{default:{height:"auto",minHeight:"100px",maxHeight:"400px"},home:{height:"120px",minHeight:"110px",maxHeight:"200px"}}[x],onInput:e=>{}}),d&&(0,le.jsx)("button",{onClick:()=>{o?null==c||c():null==d||d()},className:"".concat(b," ").concat(s||o?"":"cursor-not-allowed"),"aria-label":o?"Stop processing":"Send message",title:o?"Stop processing":"Send message",disabled:f,children:o?(0,le.jsx)(Rt.A,{className:"w-4 h-4"}):i?(0,le.jsx)(Mt.A,{className:"w-4 h-4"}):(0,le.jsx)(Dt.A,{className:"w-4 h-4"})})]})});var Bt=s(96479);var zt=s(31115);function Ut(){return(0,zt.Ub)({maxWidth:767})}const Wt=(0,Y.forwardRef)((e,t)=>{let{value:s,files:a=[],onSend:n,placeholder:l,disabled:r,isProcessing:i,onValueChange:o,onFilesChange:c,onStop:d,customButtomRight:m,customButtomLeft:u,variant:x="default",isAdminMode:h=!1,isDiscussionMode:p=!1,isVisualEditMode:g=!1,className:f}=e;const v=Nt(),b=(0,Y.useRef)(),j=Ut(),[y,N]=(0,Y.useState)([]),[w,_]=(0,Y.useState)(null),k=()=>{n&&(n({text:s,files:a}),o(""),c([]),_(null))},C=async e=>{try{const{valid:s,error:a}=function(e){const t="."+e.name.split(".").pop().toLowerCase();if(![".jpg",".jpeg",".png",".pdf",".txt",".html"].includes(t))return{valid:!1,error:'File type "'.concat(e.name.split(".").pop(),'" is not supported. Supported types: jpg, jpeg, png, pdf, txt, html.')};const s=".pdf"===t,a=[".jpg",".jpeg",".png"].includes(t)?41943040:s?10485760:5242880;if(e.size>a){const t=a/1048576;return{valid:!1,error:'File "'.concat(e.name,'" exceeds the maximum allowed size of ').concat(t,"MB.")}}return{valid:!0,error:null}}(e);if(!s)return _(a),null;let n=e;if(e.type.startsWith("image/")){N(t=>[...t,"".concat(e.name," (processing...)")]);try{n=(await async function(e){if(!e.type.startsWith("image/"))return{file:e,mimeType:e.type};const t=1024,s=2097152,n="image/png"===e.type,l=n?"image/png":"image/jpeg",r=n?".png":".jpg";return new Promise((i,o)=>{const c=new FileReader;c.readAsDataURL(e),c.onload=c=>{const d=new Image;d.src=c.target.result,d.onload=()=>{try{let{width:c,height:m}=d;const u=c>t||m>t;if(e.size<=s&&!u)return void i({file:e,mimeType:e.type});u&&(c>m?(m=Math.round(m*t/c),c=t):(c=Math.round(c*t/m),m=t));const x=document.createElement("canvas");x.width=c,x.height=m;const h=x.getContext("2d");n?h.clearRect(0,0,x.width,x.height):(h.fillStyle="white",h.fillRect(0,0,x.width,x.height)),h.drawImage(d,0,0,c,m);const p=t=>{try{x.toBlob(n=>{if(n)if(n.size<=s)try{const t=e.name,s=t.substring(0,t.lastIndexOf("."))||t,a=new File([n],s+r,{type:l,lastModified:Date.now()});i({file:a,mimeType:l})}catch(a){i({file:e,mimeType:e.type})}else if(t>.55)p(t-.1);else try{const t=e.name,s=t.substring(0,t.lastIndexOf("."))||t,a=new File([n],s+r,{type:l,lastModified:Date.now()});i({file:a,mimeType:l})}catch(a){i({file:e,mimeType:e.type})}else o(new Error("Failed to create image blob"))},l,n?null:t)}catch(a){i({file:e,mimeType:e.type})}};p(.85)}catch(a){i({file:e,mimeType:e.type})}},d.onerror=t=>{i({file:e,mimeType:e.type})}},c.onerror=t=>{i({file:e,mimeType:e.type})}})}(e)).file}catch(t){}}N(t=>t.filter(t=>t!=="".concat(e.name," (processing...)"))),N(t=>[...t,e.name]);const l=null!=v&&v.app?await _t.uploadAppFile(n,v.app.id):await _t.uploadFile(n);return N(t=>t.filter(t=>t!==e.name)),_(null),l.url}catch(s){return N(t=>t.filter(t=>t!==e.name)),null}};return(0,le.jsxs)("div",{className:Pe("w-full relative",{"rounded-[30px] bg-white border border-[#E2E5EB] backdrop-blur px-2":"home"===x,"shadow-[0_8px_16px_0_rgba(0,0,0,0.04)]":!r&&"home"===x,"border border-gray-300 rounded-[16px] bg-white/80 backdrop-blur":"home"!==x,"shadow-[0px_1px_6px_3px_rgba(0,0,0,0.1)] ":!r&&"home"!==x},f),onDrop:async e=>{e.preventDefault();const t=Array.from(e.dataTransfer.files).map(e=>C(e)),s=(await Promise.all(t)).filter(e=>null!==e);s.length>0&&c([...a,...s])},onDragOver:e=>{e.preventDefault()},children:[(0,le.jsx)(Ot,{files:a,uploadingFiles:y,onRemoveFile:e=>c(a.filter(t=>t!==e))}),w&&(0,le.jsx)("div",{className:"px-4 py-2",children:(0,le.jsxs)(De,{variant:"destructive",className:"flex items-center justify-between",children:[(0,le.jsxs)(Be,{children:[w,(0,le.jsxs)("div",{className:"mt-1 text-xs",children:["Please request support for additional file types at ",(0,le.jsx)("a",{href:"https://feedback.base44.com",target:"_blank",rel:"noopener noreferrer",className:"underline hover:text-destructive-foreground/80",children:"feedback.base44.com"})]})]}),(0,le.jsx)("button",{onClick:()=>_(null),className:"ml-2 inline-flex h-5 w-5 items-center justify-center rounded-full bg-destructive/10 hover:bg-destructive/20",children:(0,le.jsx)(Bt.A,{className:"h-3 w-3"})})]})}),(0,le.jsx)(Ft,{ref:t,value:s,onValueChange:o,onKeyDown:e=>{h?"Enter"===e.key&&(e.ctrlKey||e.metaKey)&&(e.preventDefault(),k()):"Enter"!==e.key||e.shiftKey||(e.preventDefault(),k())},onPaste:async e=>{var t,s;const n=null===(t=e.clipboardData||(null===(s=e.originalEvent)||void 0===s?void 0:s.clipboardData))||void 0===t?void 0:t.items;if(!n)return;const l=[];for(let a of n)if("file"===a.kind){const e=a.getAsFile();e&&l.push(C(e))}const r=(await Promise.all(l)).filter(e=>null!==e);r.length>0&&c([...a,...r])},placeholder:l,disabled:r,isProcessing:i,onStop:d,onSend:n?k:null,variant:x,isAdminMode:h,isDiscussionMode:p,isVisualEditMode:g}),(0,le.jsx)("input",{ref:b,type:"file",id:"chat-file-upload",className:"hidden",multiple:!0,onChange:async e=>{const t=Array.from(e.target.files),s=[];for(let a of t){const e=await C(a);e&&s.push(e)}c([...a,...s]),b.current.value=""},accept:".jpg,.jpeg,.png,.pdf,.txt,.html"}),(0,le.jsx)(Pt,{onFileUploadClick:()=>document.getElementById("chat-file-upload").click(),value:s,isMobile:j,customButtomLeft:u,customButtomRight:m,variant:x})]})});var qt=s(92962);const Vt=["className","variant","size","asChild"],Ht=(0,Ee.cva)("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/90",outline:"border border-input bg-background hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-10 px-4 py-2",sm:"h-9 rounded-md px-3",lg:"h-11 rounded-md px-8",icon:"h-10 w-10"}},defaultVariants:{variant:"default",size:"default"}}),Yt=Y.forwardRef((e,t)=>{let{className:s,variant:a,size:n,asChild:l=!1}=e,r=(0,Se.A)(e,Vt);const i=l?qt.DX:"button";return(0,le.jsx)(i,(0,K.A)({className:Pe(Ht({variant:a,size:n,className:s})),ref:t},r))});Yt.displayName="Button";const Gt=[{id:"neo-brutalism",name:"Neo-Brutalism",description:'Bold colors, high contrast, thick borders, raw functionality, and intentionally "undesigned" aesthetics with rough edges.',features:["High contrast colors","Thick borders","Harsh shadows","Raw typography","Unconventional layouts"],brands:["Figma","Gumroad","Stripe Press"],color:"bg-yellow-400",textColor:"text-black",buttonColor:"bg-red-500",buttonTextColor:"text-white",borderColor:"border-black",prompt:'Use a Neo-Brutalism style with bold colors, high contrast, thick black borders (3-4px), and harsh drop shadows. Create an intentionally "undesigned" aesthetic with raw typography and slightly asymmetrical layouts. Buttons should have thick borders and strong color contrast. Avoid gradients and subtle shadows in favor of stark, bold design elements.'},{id:"neumorphism",name:"Neumorphism",description:"Soft, extruded UI elements that appear to push through the surface, using subtle shadows to create a physical, tactile feel.",features:["Subtle shadows","Soft UI","Monochromatic palette","Minimal depth","Light/dark versions"],brands:["Apple (iOS)","Tesla UI","Samsung One UI"],color:"bg-gray-200",textColor:"text-gray-700",buttonColor:"bg-gray-200",buttonTextColor:"text-gray-700",borderColor:"border-gray-300",prompt:"Create a Neumorphic UI with soft, extruded elements that appear to push through the surface. Use subtle dual shadows (both light and dark) to create a physical, tactile feel. Elements should use a monochromatic color palette with minimal depth and no hard borders. Buttons should have a soft pressed effect on interaction. The background should be a soft light gray (#e0e0e0) or very light color, and UI elements should appear to be carved from the same material as the background."},{id:"glassmorphism",name:"Glassmorphism",description:"Frosted glass effect with transparency, blur, and subtle borders that create depth and layering.",features:["Backdrop blur","Transparency","Subtle borders","Light reflections","Layered interfaces"],brands:["Apple (macOS)","Microsoft (Windows 11)","Spotify"],color:"bg-gradient-to-r from-purple-500 via-pink-500 to-red-500",textColor:"text-white",buttonColor:"bg-white/30",buttonTextColor:"text-white",borderColor:"border-white/50",prompt:"Design with a Glassmorphism style using frosted glass effects with transparency and backdrop blur. Elements should have subtle light borders (1px) and slight transparency. Create depth through layering of translucent elements. Use colorful backgrounds (gradients work well) with frosted glass UI elements on top. Apply backdrop-blur CSS properties and use RGBA colors with alpha transparency. Aim for a modern, clean aesthetic with subtle light reflections and shadows. The design should be unique, beautiful and detailed. the colors should work well together."},{id:"material-design",name:"Material Design",description:"Google's design language using grid-based layouts, responsive animations, padding, and depth effects like lighting and shadows.",features:["Paper metaphor","Bold colors","Grid system","Responsive animations","Elevation shadow system"],brands:["Google","Android","YouTube"],color:"bg-white",textColor:"text-gray-800",buttonColor:"bg-blue-500",buttonTextColor:"text-white",borderColor:"border-gray-200",prompt:"Follow Google's Material Design principles with paper-like cards, bold colors, and responsive animations. Use elevation shadows to indicate hierarchy and focus. Implement a consistent grid system with proper spacing and alignment. Buttons should be flat with hover effects and ripple animations on click. Use Google's typeface recommendations and follow Material color palette guidelines. Add subtle transitions between states and responsive micro-interactions."},{id:"claymorphism",name:"Claymorphism",description:"Soft, puffy, rounded UI elements that appear like clay, with soft shadows and pastel colors.",features:["Soft shadows","Rounded corners","Pastel colors","Puffy appearance","Playful feel"],brands:["Headspace","Duolingo","Clubhouse"],color:"bg-purple-100",textColor:"text-purple-700",buttonColor:"bg-purple-300",buttonTextColor:"text-purple-700",borderColor:"border-purple-200",prompt:"Design with Claymorphism using soft, puffy UI elements that appear like clay. Use large border radius (16-20px), soft inner and outer shadows, and pastel colors. Elements should look soft and squeezable with a playful feel. Implement soft shadows both inside and outside elements to create dimension. Use gentle pastel colors like lavender, mint green, and baby blue. Avoid hard edges and sharp contrasts in favor of soft, rounded corners and gentle color transitions. The design should be unique, beautiful and detailed. the colors should work well together."}];function $t(e){let{onSelectStyle:t}=e;const[s,a]=(0,Y.useState)({}),[n,l]=(0,Y.useState)({}),[r,i]=(0,Y.useState)(!0),o=e=>{l(t=>(0,K.A)((0,K.A)({},t),{},{[e]:(t[e]||0)+1})),a(t=>(0,K.A)((0,K.A)({},t),{},{[e]:!0})),setTimeout(()=>{a(t=>(0,K.A)((0,K.A)({},t),{},{[e]:!1}))},1e3)};return r?(0,le.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black bg-opacity-50",children:(0,le.jsxs)("div",{className:"bg-white rounded-xl shadow-2xl w-11/12 max-w-6xl max-h-[90vh] overflow-y-auto",children:[(0,le.jsxs)("div",{className:"sticky top-0 bg-white p-4 border-b flex justify-between items-center z-10",children:[(0,le.jsx)("h1",{className:"text-2xl font-bold text-gray-800",children:"Add styling instructions"}),(0,le.jsx)("button",{onClick:()=>i(!1),className:"text-gray-500 hover:text-gray-700",children:(0,le.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-6 w-6",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,le.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,le.jsx)("div",{className:"p-4",children:Gt.map(e=>(0,le.jsx)("section",{id:e.id,className:"mb-16 scroll-mt-32 rounded-xl overflow-hidden bg-white shadow-lg transition-colors duration-300",children:(0,le.jsxs)("div",{className:"flex flex-col md:flex-row",children:[(0,le.jsxs)("div",{className:"md:w-1/3 p-6",children:[(0,le.jsx)("h2",{className:"text-2xl font-bold mb-2 text-gray-800",children:e.name}),(0,le.jsx)("p",{className:"mb-6 text-gray-600",children:e.description}),(0,le.jsxs)("div",{className:"mb-6",children:[(0,le.jsx)("h3",{className:"text-lg font-semibold mb-2 text-gray-800",children:"Key Features"}),(0,le.jsx)("ul",{className:"list-disc list-inside text-gray-600",children:e.features.map((e,t)=>(0,le.jsx)("li",{className:"mb-1",children:e},t))})]}),(0,le.jsxs)("div",{className:"mb-6",children:[(0,le.jsx)("h3",{className:"text-lg font-semibold mb-2 text-gray-800",children:"Used By"}),(0,le.jsx)("div",{className:"flex flex-wrap gap-2",children:e.brands.map((e,t)=>(0,le.jsx)("span",{className:"inline-block px-3 py-1 rounded-full text-sm bg-gray-100 text-gray-700",children:e},t))})]}),(0,le.jsx)("button",{onClick:()=>{return s=e.id,t(s),void i(!1);var s},className:"w-full py-2 px-4 bg-gray-800 text-white font-medium rounded-lg hover:bg-black hover:shadow-sm transition-all duration-200 border border-transparent hover:border-gray-700",children:"Add Style Instructions"})]}),(0,le.jsx)("div",{className:"md:w-2/3",children:(0,le.jsx)("div",{className:"p-6 h-full flex items-center justify-center ".concat("neo-brutalism"===e.id?"bg-yellow-50":"neumorphism"===e.id?"bg-gray-100":"glassmorphism"===e.id?e.color:"material-design"===e.id?"bg-gray-50":"bg-purple-50"),children:(0,le.jsxs)("div",{className:"w-full max-w-lg",children:["neo-brutalism"===e.id&&(0,le.jsxs)("div",{className:"bg-yellow-400 p-6 border-4 border-black shadow-[8px_8px_0px_0px_rgba(0,0,0,1)] transform -rotate-1",children:[(0,le.jsx)("h3",{className:"text-xl font-bold mb-4 font-mono text-black",children:"Raw. Unfiltered. Brutal."}),(0,le.jsx)("p",{className:"mb-4 text-black",children:"Neo-Brutalism embraces imperfection and raw expression."}),(0,le.jsx)("button",{className:"bg-red-500 text-white font-bold py-2 px-4 border-4 border-black ".concat(s[e.id]?"animate-bounce":""," hover:bg-red-600 transform hover:-translate-y-1 transition-transform"),onClick:()=>o(e.id),children:"CLICK ME"}),(0,le.jsxs)("div",{className:"mt-4 grid grid-cols-3 gap-3",children:[(0,le.jsx)("div",{className:"bg-blue-500 border-4 border-black p-2",children:(0,le.jsx)("p",{className:"text-white text-sm font-bold",children:"Bold"})}),(0,le.jsx)("div",{className:"bg-green-500 border-4 border-black p-2",children:(0,le.jsx)("p",{className:"text-black text-sm font-bold",children:"Raw"})}),(0,le.jsx)("div",{className:"bg-purple-500 border-4 border-black p-2",children:(0,le.jsx)("p",{className:"text-white text-sm font-bold",children:"Expressive"})})]})]}),"neumorphism"===e.id&&(0,le.jsx)("div",{className:"bg-gray-200 p-6 rounded-xl",children:(0,le.jsxs)("div",{className:"bg-gray-200 p-6 rounded-xl shadow-[5px_5px_10px_rgba(0,0,0,0.1),_-5px_-5px_10px_rgba(255,255,255,0.8)]",children:[(0,le.jsx)("h3",{className:"text-xl font-medium mb-4 text-gray-700",children:"Soft & Tactile"}),(0,le.jsx)("p",{className:"mb-4 text-gray-600",children:"Neumorphism creates a soft UI that appears to extrude from the background."}),(0,le.jsx)("button",{className:"bg-gray-200 text-gray-700 font-medium py-2 px-4 rounded-xl ".concat(s[e.id]?"shadow-[inset_5px_5px_10px_rgba(0,0,0,0.1),_inset_-5px_-5px_10px_rgba(255,255,255,0.8)]":"shadow-[5px_5px_10px_rgba(0,0,0,0.1),_-5px_-5px_10px_rgba(255,255,255,0.8)]"," hover:shadow-[inset_5px_5px_10px_rgba(0,0,0,0.1),_inset_-5px_-5px_10px_rgba(255,255,255,0.8)] transition-shadow"),onClick:()=>o(e.id),children:"Soft Press"}),(0,le.jsx)("div",{className:"mt-4",children:(0,le.jsxs)("div",{className:"flex items-center justify-between bg-gray-200 p-3 rounded-xl shadow-[inset_3px_3px_6px_rgba(0,0,0,0.1),_inset_-3px_-3px_6px_rgba(255,255,255,0.8)]",children:[(0,le.jsx)("p",{className:"text-gray-700 font-medium",children:"Volume"}),(0,le.jsx)("div",{className:"w-32 h-4 bg-gray-200 rounded-full shadow-[inset_3px_3px_6px_rgba(0,0,0,0.1),_inset_-3px_-3px_6px_rgba(255,255,255,0.8)]",children:(0,le.jsx)("div",{className:"h-4 bg-blue-400 rounded-full transition-all duration-300",style:{width:"".concat(10*(n[e.id]||0),"%")}})})]})})]})}),"glassmorphism"===e.id&&(0,le.jsxs)("div",{className:"relative min-h-64 p-6 rounded-xl overflow-hidden",children:[(0,le.jsx)("div",{className:"absolute inset-0 flex justify-around items-center",children:[...Array(5)].map((t,a)=>(0,le.jsx)("div",{className:"bg-white rounded-full w-16 h-16 opacity-20 ".concat(s[e.id]?"animate-pulse":"")},a))}),(0,le.jsx)("div",{className:"relative z-10",children:(0,le.jsxs)("div",{className:"backdrop-blur-xl bg-white/30 p-6 rounded-xl border border-white/50 shadow-lg",children:[(0,le.jsx)("h3",{className:"text-xl font-medium mb-4 text-white",children:"Transparent & Blurred"}),(0,le.jsx)("p",{className:"mb-4 text-white/90",children:"Glassmorphism creates a frosted glass effect that adds depth and elegance."}),(0,le.jsx)("button",{className:"backdrop-blur-sm bg-white/30 text-white font-medium py-2 px-4 rounded-xl border border-white/50 hover:bg-white/40 transition-colors",onClick:()=>o(e.id),children:"See Through"}),(0,le.jsxs)("div",{className:"mt-4 flex space-x-2",children:[(0,le.jsx)("div",{className:"backdrop-blur-xl bg-white/20 p-2 rounded-xl border border-white/50 shadow-lg flex-1 text-center",children:(0,le.jsx)("p",{className:"text-white text-sm font-medium",children:"Layer 1"})}),(0,le.jsx)("div",{className:"backdrop-blur-xl bg-white/30 p-2 rounded-xl border border-white/50 shadow-lg flex-1 text-center",children:(0,le.jsx)("p",{className:"text-white text-sm font-medium",children:"Layer 2"})}),(0,le.jsx)("div",{className:"backdrop-blur-xl bg-white/40 p-2 rounded-xl border border-white/50 shadow-lg flex-1 text-center",children:(0,le.jsx)("p",{className:"text-white text-sm font-medium",children:"Layer 3"})})]})]})})]}),"material-design"===e.id&&(0,le.jsx)("div",{className:"bg-white p-6 rounded-lg shadow-lg",children:(0,le.jsxs)("div",{className:"bg-white p-6 rounded-lg shadow-md",children:[(0,le.jsx)("h3",{className:"text-xl font-medium mb-4 text-gray-800",children:"Elevated & Structured"}),(0,le.jsx)("p",{className:"mb-4 text-gray-600",children:"Material Design uses physics-inspired animations and layered interfaces."}),(0,le.jsx)("button",{className:"bg-blue-500 text-white font-medium py-2 px-4 rounded shadow-md ".concat(s[e.id]?"shadow-xl -translate-y-1":""," hover:shadow-lg hover:-translate-y-1 transition-all"),onClick:()=>o(e.id),children:"ELEVATE"}),(0,le.jsxs)("div",{className:"mt-4 grid grid-cols-2 gap-4",children:[(0,le.jsx)("div",{className:"bg-red-500 p-3 rounded shadow-md",children:(0,le.jsx)("p",{className:"text-white text-sm font-medium",children:"Cards"})}),(0,le.jsx)("div",{className:"bg-white p-3 rounded shadow-md",children:(0,le.jsxs)("div",{className:"flex items-center justify-between",children:[(0,le.jsx)("p",{className:"text-gray-700 text-sm font-medium",children:"Toggle"}),(0,le.jsx)("div",{className:"w-10 h-5 ".concat((n[e.id]||0)%2==0?"bg-gray-300":"bg-green-500"," rounded-full shadow-inner flex items-center transition-colors duration-300"),children:(0,le.jsx)("div",{className:"w-5 h-5 bg-white rounded-full shadow-md transform transition-transform duration-300 ".concat((n[e.id]||0)%2==0?"translate-x-0":"translate-x-5")})})]})})]})]})}),"claymorphism"===e.id&&(0,le.jsx)("div",{className:"bg-purple-100 p-6 rounded-3xl shadow-lg",children:(0,le.jsxs)("div",{className:"bg-blue-100 p-6 rounded-3xl shadow-[6px_6px_12px_rgba(0,0,0,0.1),_-6px_-6px_12px_rgba(255,255,255,0.8),_inset_1px_1px_2px_rgba(255,255,255,0.8)]",children:[(0,le.jsx)("h3",{className:"text-xl font-medium mb-4 text-blue-700",children:"Soft & Puffy"}),(0,le.jsx)("p",{className:"mb-4 text-blue-600",children:"Claymorphism creates a soft, puffy, and playful interface that looks like clay."}),(0,le.jsx)("button",{className:"bg-purple-300 text-purple-700 font-medium py-2 px-4 rounded-2xl \n ".concat(s[e.id]?"shadow-[inset_4px_4px_8px_rgba(0,0,0,0.1),_inset_-4px_-4px_8px_rgba(255,255,255,0.5)]":"shadow-[4px_4px_8px_rgba(0,0,0,0.1),_-4px_-4px_8px_rgba(255,255,255,0.5)]"," \n hover:shadow-[inset_4px_4px_8px_rgba(0,0,0,0.1),_inset_-4px_-4px_8px_rgba(255,255,255,0.5)] transition-shadow"),onClick:()=>o(e.id),children:"Squish Me"}),(0,le.jsxs)("div",{className:"mt-4 grid grid-cols-3 gap-2",children:[(0,le.jsx)("div",{className:"bg-green-100 p-2 rounded-2xl shadow-[6px_6px_12px_rgba(0,0,0,0.1),_-6px_-6px_12px_rgba(255,255,255,0.8),_inset_1px_1px_2px_rgba(255,255,255,0.8)]",children:(0,le.jsx)("p",{className:"text-green-600 text-sm font-medium text-center",children:"Soft"})}),(0,le.jsx)("div",{className:"bg-yellow-100 p-2 rounded-2xl shadow-[6px_6px_12px_rgba(0,0,0,0.1),_-6px_-6px_12px_rgba(255,255,255,0.8),_inset_1px_1px_2px_rgba(255,255,255,0.8)]",children:(0,le.jsx)("p",{className:"text-yellow-600 text-sm font-medium text-center",children:"Puffy"})}),(0,le.jsx)("div",{className:"bg-pink-100 p-2 rounded-2xl shadow-[6px_6px_12px_rgba(0,0,0,0.1),_-6px_-6px_12px_rgba(255,255,255,0.8),_inset_1px_1px_2px_rgba(255,255,255,0.8)]",children:(0,le.jsx)("p",{className:"text-pink-600 text-sm font-medium text-center",children:"Playful"})})]})]})})]})})})]})},e.id))})]})}):null}const Jt=["limit","skip","sort_by"];class Zt extends Q.y{listCatalogItems(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{limit:t,skip:s,sort_by:a}=e,n=(0,Se.A)(e,Jt);const l={};return Object.keys(n).length>0&&(l.q=JSON.stringify(n)),t&&(l.limit=t),s&&(l.skip=s),a&&(l.sort_by=a),this.axios.get("/catalog",Object.keys(l).length?{params:l}:void 0)}getCatalogItem(e){return this.axios.get("/catalog/".concat(e))}submitItem(e){return this.axios.post("/catalog",e)}upvoteItem(e){return this.axios.post("/catalog/".concat(e,"/upvote"))}approveItem(e,t){const s=t?{language:t}:void 0;return this.axios.post("/catalog/".concat(e,"/approve"),s)}declineItem(e,t){const s=t?{reason:t}:void 0;return this.axios.post("/catalog/".concat(e,"/decline"),s)}archiveItem(e){return this.axios.post("/catalog/".concat(e,"/archive"))}inviteAdmin(e,t){return this.axios.post("/catalog/".concat(e,"/invite"),{email:t})}}const Kt=new class extends Zt{getBaseURL(){return"/integration-catalog-items"}},Qt=["className","variant"],Xt=(0,Ee.cva)("inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground hover:bg-primary/80",secondary:"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",destructive:"border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80",outline:"text-foreground"}},defaultVariants:{variant:"default"}});function es(e){let{className:t,variant:s}=e,a=(0,Se.A)(e,Qt);return(0,le.jsx)("div",(0,K.A)({className:Pe(Xt({variant:s}),t)},a))}const ts=["className"],ss=["className"],as=["className"],ns=["className"],ls=["className"],rs=["className"],is=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,ts);return(0,le.jsx)("div",(0,K.A)({ref:t,className:Pe("rounded-lg border bg-card text-card-foreground shadow-sm",s)},a))});is.displayName="Card";const os=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,ss);return(0,le.jsx)("div",(0,K.A)({ref:t,className:Pe("flex flex-col space-y-1.5 p-6",s)},a))});os.displayName="CardHeader";const cs=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,as);return(0,le.jsx)("h3",(0,K.A)({ref:t,className:Pe("text-2xl font-semibold leading-none tracking-tight",s)},a))});cs.displayName="CardTitle";const ds=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,ns);return(0,le.jsx)("p",(0,K.A)({ref:t,className:Pe("text-sm text-muted-foreground",s)},a))});ds.displayName="CardDescription";const ms=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,ls);return(0,le.jsx)("div",(0,K.A)({ref:t,className:Pe("p-6 pt-0",s)},a))});ms.displayName="CardContent";const us=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,rs);return(0,le.jsx)("div",(0,K.A)({ref:t,className:Pe("flex items-center p-6 pt-0",s)},a))});us.displayName="CardFooter";var xs=s(48077);const hs=["className","orientation","decorative"],ps=Y.forwardRef((e,t)=>{let{className:s,orientation:a="horizontal",decorative:n=!0}=e,l=(0,Se.A)(e,hs);return(0,le.jsx)(xs.b,(0,K.A)({ref:t,decorative:n,orientation:a,className:Pe("shrink-0 bg-border","horizontal"===a?"h-[1px] w-full":"h-full w-[1px]",s)},l))});ps.displayName=xs.b.displayName;const gs=["className","type"],fs=Y.forwardRef((e,t)=>{let{className:s,type:a}=e,n=(0,Se.A)(e,gs);return(0,le.jsx)("input",(0,K.A)({type:a,className:Pe("flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-base ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",s),ref:t},n))});fs.displayName="Input";var vs=s(4321),bs=s(84128);const js=["className"],ys=(0,Ee.cva)("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),Ns=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,js);return(0,le.jsx)(bs.b,(0,K.A)({ref:t,className:Pe(ys(),s)},a))});Ns.displayName=bs.b.displayName;var ws=s(5995),_s=s(25675);const ks=["className"],Cs=["className"],As=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,ks);return(0,le.jsx)(ws.bL,(0,K.A)((0,K.A)({className:Pe("grid gap-2",s)},a),{},{ref:t}))});As.displayName=ws.bL.displayName;const Ss=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,Cs);return(0,le.jsx)(ws.q7,(0,K.A)((0,K.A)({ref:t,className:Pe("aspect-square h-4 w-4 rounded-full border border-primary text-primary ring-offset-background focus:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",s)},a),{},{children:(0,le.jsx)(ws.C1,{className:"flex items-center justify-center",children:(0,le.jsx)(_s.A,{className:"h-2.5 w-2.5 fill-current text-current"})})}))});Ss.displayName=ws.q7.displayName;var Es=s(58390),Is=s(27453),Ts=s(17684),Ps=s(86311);const Ls=["className","children","advancedDropdown"],Os=["className"],Rs=["className"],Ms=["className","children","position"],Ds=["className"],Fs=["className","children","hideCheckIcon"],Bs=["className"],zs=Es.bL,Us=Es.YJ,Ws=Es.WT,qs=Y.forwardRef((e,t)=>{let{className:s,children:a,advancedDropdown:n=!1}=e,l=(0,Se.A)(e,Ls);return(0,le.jsxs)(Es.l9,(0,K.A)((0,K.A)({ref:t,className:Pe("flex h-10 w-full items-center justify-between ".concat(n?"rounded-lg":"rounded-md"," border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1"),s)},l),{},{children:[n?(0,le.jsx)("div",{className:"flex-1 min-w-0",children:a}):a,(0,le.jsx)(Es.In,{asChild:!0,children:(0,le.jsx)(Is.A,{className:Pe("h-4 w-4 opacity-50",n?"flex-shrink-0 ml-2":"")})})]}))});qs.displayName=Es.l9.displayName;const Vs=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,Os);return(0,le.jsx)(Es.PP,(0,K.A)((0,K.A)({ref:t,className:Pe("flex cursor-default items-center justify-center py-1",s)},a),{},{children:(0,le.jsx)(Ts.A,{className:"h-4 w-4"})}))});Vs.displayName=Es.PP.displayName;const Hs=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,Rs);return(0,le.jsx)(Es.wn,(0,K.A)((0,K.A)({ref:t,className:Pe("flex cursor-default items-center justify-center py-1",s)},a),{},{children:(0,le.jsx)(Is.A,{className:"h-4 w-4"})}))});Hs.displayName=Es.wn.displayName;const Ys=Y.forwardRef((e,t)=>{let{className:s,children:a,position:n="popper"}=e,l=(0,Se.A)(e,Ms);return(0,le.jsx)(Es.ZL,{children:(0,le.jsxs)(Es.UC,(0,K.A)((0,K.A)({ref:t,className:Pe("relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2","popper"===n&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",s),position:n},l),{},{children:[(0,le.jsx)(Vs,{}),(0,le.jsx)(Es.LM,{className:Pe("p-1","popper"===n&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:a}),(0,le.jsx)(Hs,{})]}))})});Ys.displayName=Es.UC.displayName;const Gs=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,Ds);return(0,le.jsx)(Es.JU,(0,K.A)({ref:t,className:Pe("py-1.5 pl-8 pr-2 text-sm font-semibold",s)},a))});Gs.displayName=Es.JU.displayName;const $s=Y.forwardRef((e,t)=>{let{className:s,children:a,hideCheckIcon:n=!1}=e,l=(0,Se.A)(e,Fs);return(0,le.jsxs)(Es.q7,(0,K.A)((0,K.A)({ref:t,className:Pe("relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",n?"pl-2 pr-2":"pl-8 pr-2",s)},l),{},{children:[!n&&(0,le.jsx)("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:(0,le.jsx)(Es.VF,{children:(0,le.jsx)(Ps.A,{className:"h-4 w-4"})})}),(0,le.jsx)(Es.p4,{children:a})]}))});$s.displayName=Es.q7.displayName;const Js=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,Bs);return(0,le.jsx)(Es.wv,(0,K.A)({ref:t,className:Pe("-mx-1 my-1 h-px bg-muted",s)},a))});function Zs(e){let{secret:t,value:s,onChange:a}=e;const{user:n}=oe(),{name:l,description:r}=t,[i,o]=(0,Y.useState)([]),[c,d]=(0,Y.useState)(!0),[m,u]=(0,Y.useState)((null==s?void 0:s.type)||"value"),[x,h]=(0,Y.useState)((null==s?void 0:s.value)||""),[p,g]=(0,Y.useState)("clone"===(null==s?void 0:s.type)?s.value:"");(0,Y.useEffect)(()=>{(async()=>{try{const e=await qe.getGeneralSecrets(l);o(e||[])}catch(e){o([])}finally{d(!1)}})()},[l]),(0,Y.useEffect)(()=>{"value"===m?a(l,{type:"value",value:x}):"clone"===m&&p&&a(l,{type:"clone",value:p})},[m,x,p,l,a]);return(0,le.jsxs)("div",{className:"mb-8 pb-6 border-b border-gray-200 last:border-0 last:mb-0 last:pb-0",children:[(0,le.jsx)("div",{className:"flex items-center mb-4",children:(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[(0,le.jsx)(vs.A,{className:"h-4 w-4 text-gray-500"}),(0,le.jsx)(Ns,{className:"text-sm font-medium",children:l})]})}),(0,le.jsxs)(As,{value:m,onValueChange:u,className:"flex gap-8 mb-4",children:[(0,le.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,le.jsx)(Ss,{value:"value",id:"value-".concat(l),className:"h-4 w-4"}),(0,le.jsx)(Ns,{htmlFor:"value-".concat(l),className:"text-xs cursor-pointer",children:"New value"})]}),"platform_admin"===(null==n?void 0:n.platform_role)&&(0,le.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,le.jsx)(Ss,{value:"clone",id:"clone-".concat(l),className:"h-4 w-4"}),(0,le.jsx)(Ns,{htmlFor:"clone-".concat(l),className:"text-xs cursor-pointer",children:"Reuse existing"})]})]}),"value"===m?(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(fs,{type:"password",placeholder:"Enter ".concat(l),value:x,onChange:e=>{h(e.target.value)},className:"h-9 text-sm mt-3 transition-all focus:ring-2 focus:ring-offset-1 focus:ring-blue-500"}),r&&(0,le.jsx)("p",{className:"text-xs text-gray-500 mt-2 ml-1",children:r})]}):(0,le.jsxs)(le.Fragment,{children:[c?(0,le.jsxs)("div",{className:"flex items-center h-9 text-xs text-gray-500 mt-3 bg-gray-50 rounded-md px-3",children:[(0,le.jsx)(Ne.A,{className:"h-4 w-4 animate-spin mr-2"}),"Loading existing secrets..."]}):i.length>0?(0,le.jsxs)(zs,{value:p,onValueChange:e=>{g(e)},children:[(0,le.jsx)(qs,{className:"h-9 text-sm mt-3",children:(0,le.jsx)(Ws,{placeholder:"Select an existing secret"})}),(0,le.jsx)(Ys,{className:"max-h-[200px] overflow-y-auto",children:i.map(e=>(0,le.jsxs)($s,{value:e.id,className:"text-xs py-3",children:[e.app_name||"Unnamed App"," (",e.secret_name,")"]},e.id))})]}):(0,le.jsxs)("div",{className:"flex items-center h-9 text-xs text-gray-500 mt-3 bg-gray-50 rounded-md px-3",children:["No existing secrets found for ",l]}),r&&(0,le.jsx)("p",{className:"text-xs text-gray-500 mt-2 ml-1",children:r})]})]})}function Ks(e){let{secretNames:t,value:s={},onChange:a}=e;const n=(e,t)=>{a((0,K.A)((0,K.A)({},s),{},{[e]:t}))};return(0,le.jsx)("div",{className:"text-sm px-5 py-7",children:t.map((e,t)=>(0,le.jsx)("div",{className:"mb-6 last:mb-0",children:(0,le.jsx)(Zs,{secret:e,value:s[e.name],onChange:n})},t))})}Js.displayName=Es.wv.displayName;const Qs=e=>{let{integration:t,secrets:s,onSecretsChange:a,onRemove:n}=e;const{item:l}=t,r=l.required_secrets&&l.required_secrets.length>0,i=!(!r||l.required_secrets.every(e=>{const t=s[e.name];return!!t&&!!("value"!==t.type||t.value&&""!==t.value.trim())&&!!("clone"!==t.type||t.value&&""!==t.value.trim())}));return(0,le.jsx)(is,{className:"mt-4 border-slate-200 overflow-hidden ".concat(i?"border-red-200":""),children:(0,le.jsxs)(ms,{className:"p-0",children:[(0,le.jsx)("div",{className:"flex flex-col sm:flex-row",children:(0,le.jsxs)("div",{className:"flex-1 p-4",children:[(0,le.jsxs)("div",{className:"flex justify-between items-start",children:[(0,le.jsxs)("div",{className:"flex gap-3 items-center mb-2",children:[(0,le.jsx)("div",{className:"h-10 w-10 rounded-md border border-slate-200 flex-shrink-0 overflow-hidden bg-slate-50",children:l.image_url?(0,le.jsx)("img",{src:l.image_url,alt:l.name,className:"h-full w-full object-contain",onError:e=>{e.target.src="",e.target.parentElement.classList.add("bg-gradient-to-br","from-blue-100","to-teal-100"),e.target.parentElement.innerHTML=''.concat(l.name.charAt(0).toUpperCase(),"")}}):(0,le.jsx)("div",{className:"h-full w-full bg-gradient-to-br from-blue-100 to-teal-100 flex items-center justify-center",children:(0,le.jsx)("span",{className:"text-teal-600 text-lg font-semibold",children:l.name.charAt(0).toUpperCase()})})}),(0,le.jsxs)("div",{children:[(0,le.jsx)("h3",{className:"font-semibold text-slate-800",children:l.name}),(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[l.official&&(0,le.jsx)(es,{className:"bg-blue-50 text-blue-700 border-blue-100 hover:bg-blue-100 text-xs",children:"Official"}),l.requires_backend_functions&&(0,le.jsx)("span",{className:"text-xs text-slate-500",children:"Requires backend functions"})]})]})]}),(0,le.jsx)("button",{className:"text-slate-400 hover:text-slate-600 hover:bg-slate-100 p-1.5 rounded-md transition-colors",onClick:()=>n(t.item.id),title:"Remove integration","aria-label":"Remove integration",children:(0,le.jsx)(Bt.A,{className:"h-4 w-4"})})]}),l.description&&(0,le.jsx)("p",{className:"text-sm text-slate-600 mt-1",children:l.description})]})}),r&&(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(ps,{className:"my-1"}),(0,le.jsxs)("div",{className:"p-4 pt-3 bg-slate-50",children:[(0,le.jsxs)("div",{className:"flex justify-between items-center",children:[(0,le.jsx)("h4",{className:"text-xs uppercase tracking-wide text-slate-500 font-medium mb-3",children:"Required API Keys"}),i&&(0,le.jsxs)("div",{className:"flex items-center text-red-500 text-xs mb-3",children:[(0,le.jsx)(_e.A,{className:"h-3 w-3 mr-1"}),(0,le.jsx)("span",{children:"Missing required keys"})]})]}),(0,le.jsx)(Ks,{secretNames:l.required_secrets,value:s,onChange:a})]})]})]})})};var Xs=s(68108);const ea={CRM:[{title:"CRM for Artists",description:"Create a CRM for artists - should be tailored for visual artists to manage artworks, exhibitions, and clients. I want features to include saving images of sold artwork, custom fields for medium and price, inventory management for available pieces, exhibition schedules, and segmentation of client profiles."},{title:"CRM for Real Estate Agents",description:"Design a CRM for real estate agents - should manage property listings and client interactions. Include features like property images and descriptions, automatic reminders for contract renewals and viewings, integration with property portals, commission tracking, and geolocation mapping for properties."},{title:"CRM for Lawyers/Legal Practices",description:"Develop a CRM for law firms - should help manage cases, track billable hours, and store legal documents. Include features for case management, time tracking, legal workflows, team task delegation, client profiles with case history, and court date reminders."},{title:"CRM for Photographers",description:"Build a CRM for photographers - should handle client galleries and bookings. Include features for gallery management, photoshoot booking with reminders, file delivery systems, pricing packages, and client referral tracking for expanding the business."},{title:"CRM for Healthcare Practices",description:"Create a CRM for healthcare providers - should support clinics with patient management and compliance. Include features for medical history tracking, HIPAA-compliant communications, prescription tracking, billing integration with insurance claims, and patient satisfaction surveys."},{title:"CRM for Influencers/Content Creators",description:"Design a CRM for influencers - should help manage partnerships and content. Include features for campaign management, brand partnership tracking, content scheduling, revenue tracking from posts and merchandise, and audience segmentation by platform."},{title:"CRM for Wedding Planners",description:"Develop a CRM for wedding planners - should help manage tasks, budgets, and events. Include features for task management, client profiles segmented by couples and vendors, budget tracking, event timelines, and visual planning tools like seating arrangements."},{title:"CRM for Fitness Trainers/Gyms",description:"Build a CRM for fitness professionals - should track client progress and manage schedules. Include features for client progress tracking, integration with wearable devices, personalized workout plans, session reminders, and social tracking for referrals."},{title:"CRM for Musicians/Bands",description:"Create a CRM for musicians and bands - should handle events and fan interactions. Include features for event management, fan segmentation, music catalog management, collaboration tools, and tracking of streaming revenue and merchandise sales."},{title:"CRM for Construction Contractors",description:"Design a CRM for contractors - should manage projects, timelines, and resources. Include features for project milestones, resource tracking for materials and subcontractors, budget management, document storage for plans and permits, and client updates on project progress."}],"Dev productivity":[{title:"Online JSON Viewer",description:"Create an online JSON viewer - should allow users to view and format JSON data. Include features for syntax highlighting, collapsible tree structure, JSON validation, and the ability to upload or paste raw JSON for easy analysis."},{title:"Markdown to HTML Converter",description:"Develop a Markdown to HTML converter - should quickly convert Markdown text into HTML. Include features for live preview, support for common Markdown syntax (headings, links, code blocks), and export options to download the resulting HTML."},{title:"Regex Tester",description:"Build a regex tester tool - should help users test and refine regular expressions. Include features for real-time regex evaluation, examples, syntax highlighting, error notifications, and a library of commonly used regex patterns."},{title:"Code Diff Checker",description:"Create a code diff checker - should compare two code snippets side by side to highlight differences. Include features for line-by-line comparison, syntax highlighting for multiple programming languages, and exportable diff reports."},{title:"REST API Tester",description:"Design a REST API tester - should allow testing of API endpoints with customizable HTTP requests. Include features to set headers, body, and query parameters, store test cases, and view response details like headers and status codes."},{title:"Cron Expression Generator",description:"Develop a cron expression generator - should help create cron job expressions for scheduling tasks. Include an intuitive UI to select time intervals, a preview of the generated cron expression, and descriptions of each component of the expression."},{title:"Base64 Encoder/Decoder",description:"Build a Base64 encoder/decoder - should encode or decode text into Base64 format. Include support for large text blocks, file encoding/decoding, and one-click conversion between Base64 and plain text."},{title:"UUID Generator",description:"Create a UUID generator - should generate Universally Unique Identifiers (UUIDs) for use in applications. Include options for different UUID versions, batch generation, and the ability to copy or export UUIDs in bulk."},{title:"Color Palette Generator",description:"Design a color palette generator - should create and visualize color palettes for web design. Include hex and RGB code conversion, color harmonies (complementary, triadic), and the ability to save and export color schemes."}],Educational:[{title:"Interactive Flashcard Creator",description:"Develop an interactive flashcard creator - should allow users to create and study digital flashcards with spaced repetition algorithms for efficient learning."},{title:"Quiz Generator",description:"Build a quiz generator - should create quizzes from custom content or pre-existing question banks for various subjects."},{title:"Language Learning Games",description:"Design language learning games - should be fun and interactive, aimed at improving vocabulary, grammar, and pronunciation in foreign languages."},{title:"Math Problem Solver",description:"Create a math problem solver - should provide step-by-step solutions with explanations for various difficulty levels of math problems."},{title:"Historical Timeline Maker",description:"Develop a historical timeline maker - should allow users to create visual timelines of historical events with customizable layouts and multimedia integration."}],"Content Generation and Editing":[{title:"AI-Powered Writing Assistant",description:"Build an AI-powered writing assistant - should help improve writing with suggestions for grammar, style, and clarity using AI algorithms."},{title:"Social Media Post Generator",description:"Create a social media post generator - should produce engaging posts with customizable templates and trending hashtags."},{title:"Meme Creator",description:"Design an easy-to-use meme creator - should include a library of popular templates and a custom image upload option."},{title:"Infographic Maker",description:"Develop an infographic maker - should be a design tool for creating visually appealing infographics with pre-made templates and icons."},{title:"Resume Builder",description:"Build a resume builder - should craft professional resumes with industry-specific templates and content suggestions."}],"Personal Finance":[{title:"Budget Planner",description:"Create a budget planner - should help users create and manage personal or household budgets with customizable categories."},{title:"Expense Tracker",description:"Develop an expense tracker - should log and categorize expenses, providing insights and reports on spending habits."},{title:"Investment Calculator",description:"Build an investment calculator - should calculate potential returns on investments based on various parameters and market scenarios."},{title:"Debt Repayment Planner",description:"Design a debt repayment planner - should create strategies for efficient debt repayment, including snowball and avalanche methods."},{title:"Currency Converter",description:"Create a currency converter - should provide real-time currency conversion with historical rate charts and rate alerts."}],"Health and Wellness":[{title:"Meal Planner and Recipe Finder",description:"Develop a meal planner and recipe finder - should plan balanced meals and suggest recipes based on dietary preferences and restrictions."},{title:"Workout Routine Generator",description:"Build a workout routine generator - should create personalized workout plans based on fitness goals, equipment availability, and time constraints."},{title:"Meditation Timer and Guide",description:"Create a meditation timer and guide - should offer guided meditations and customizable meditation timers with ambient sounds."},{title:"Sleep Cycle Analyzer",description:"Design a sleep cycle analyzer - should track sleep patterns and provide insights for improving sleep quality."},{title:"Water Intake Tracker",description:"Develop a water intake tracker - should monitor daily water consumption and send reminders to stay hydrated."}],Productivity:[{title:"Pomodoro Timer",description:"Create a Pomodoro timer - should implement the Pomodoro Technique with customizable work and break intervals."},{title:"To-Do List Organizer",description:"Build a to-do list organizer - should manage tasks with priority levels, due dates, and collaboration features."},{title:"Mind Mapping Tool",description:"Design a mind mapping tool - should create visual mind maps for brainstorming and organizing ideas."},{title:"Goal Tracker",description:"Develop a goal tracker - should help set and track personal or professional goals with progress visualization."},{title:"Habit Formation Assistant",description:"Create a habit formation assistant - should help users build and maintain positive habits through reminders and streak tracking."}],"Travel Planning":[{title:"Itinerary Builder",description:"Build an itinerary builder - should create detailed travel itineraries with attractions, reservations, and transportation details."},{title:"Packing List Generator",description:"Develop a packing list generator - should generate customized packing lists based on destination, duration, and activities."},{title:"Flight Delay Predictor",description:"Create a flight delay predictor - should estimate the likelihood of flight delays based on historical data and current conditions."},{title:"Local Currency Converter",description:"Design a local currency converter - should convert currencies with offline support for travelers without constant internet access."},{title:"Travel Phrase Translator",description:"Build a travel phrase translator - should translate common travel phrases with audio pronunciation guides."}],Entertainment:[{title:"Movie Recommendation Engine",description:"Create a movie recommendation engine - should suggest movies based on user preferences, ratings, and viewing history."},{title:"Book Discovery Tool",description:"Develop a book discovery tool - should recommend books across genres based on reading preferences and past favorites."},{title:"Podcast Finder",description:"Build a podcast finder - should discover new podcasts based on topics of interest and listening habits."},{title:"TV Show Episode Tracker",description:"Design a TV show episode tracker - should keep track of watched episodes and provide notifications for new releases."},{title:"Random Activity Generator",description:"Create a random activity generator - should suggest random activities or hobbies to try when bored or looking for inspiration."}],Environmental:[{title:"Carbon Footprint Calculator",description:"Develop a carbon footprint calculator - should estimate personal or household carbon footprint and suggest reduction strategies."},{title:"Recycling Guide",description:"Build a recycling guide - should provide location-specific information on how to properly recycle various items."},{title:"Sustainable Product Finder",description:"Create a sustainable product finder - should help users find eco-friendly alternatives to common products."},{title:"Energy Usage Monitor",description:"Design an energy usage monitor - should track and analyze home energy consumption, offering tips for reduction."},{title:"Local Eco-Event Finder",description:"Develop a local eco-event finder - should locate and promote environmental events and volunteer opportunities in the user's area."}],"Home Management":[{title:"Home Inventory Tracker",description:"Create a home inventory tracker - should catalog household items for insurance purposes or organization."},{title:"Chore Scheduler",description:"Build a chore scheduler - should assign and rotate household chores among family members or roommates."},{title:"Plant Care Reminder",description:"Design a plant care reminder - should send reminders for watering and caring for house plants based on species and season."},{title:"DIY Project Planner",description:"Develop a DIY project planner - should help plan and track home improvement projects with material lists and tutorials."},{title:"Smart Home Device Dashboard",description:"Create a smart home device dashboard - should centralize control and monitoring of various smart home devices."}],"Creative Tools":[{title:"Color Scheme Generator",description:"Build a color scheme generator - should create harmonious color palettes for design projects with export options."},{title:"Font Pairing Assistant",description:"Design a font pairing assistant - should suggest complementary font combinations for typography projects."},{title:"Logo Maker",description:"Create a logo maker - should design simple logos using pre-made elements and customization options."},{title:"Music Chord Progression Generator",description:"Develop a music chord progression generator - should create chord progressions for songwriting inspiration across various genres."},{title:"Digital Art Sketchpad",description:"Build a digital art sketchpad - should provide a simple drawing interface with basic tools for digital sketching and doodling."}]};class ta extends Q.H{getBaseURL(){return"/"}getAppSuggestions(){return this.axios.get("/prompt-suggestions")}}const sa=new ta;function aa(e){let{onSetPrompt:t}=e;const[s,a]=(0,Y.useState)(null),[n,l]=(0,Y.useState)(null),[r,i]=(0,Y.useState)(!0),[o,c]=(0,Y.useState)([]),d=()=>[...Object.keys(ea)].sort(()=>.5-Math.random()).slice(0,5);(0,Y.useEffect)(()=>{c(d())},[]),(0,Y.useEffect)(()=>{(async()=>{try{i(!0);const e=await sa.getAppSuggestions();l(e)}catch(e){l(null)}finally{i(!1)}})()},[]);const m=e=>{t(e)};return r?(0,le.jsx)("div",{className:"px-[8px] w-full mt-4",children:(0,le.jsx)("div",{className:"flex flex-wrap gap-2.5",children:[...Array(5)].map((e,t)=>(0,le.jsx)("div",{className:"rounded-[100px] px-4 py-1.5 h-8 bg-slate-200 animate-pulse border border-slate-200",style:{width:"".concat(80+60*Math.random(),"px")}},t))})}):(0,le.jsxs)("div",{className:" w-full mt-4",children:[s?(0,le.jsxs)("button",{onClick:()=>{a(null)},className:"text-slate-700 text-sm font-light mb-3 font-base44 flex items-center hover:text-slate-900 transition-colors",children:[(0,le.jsx)(Xs.A,{className:"h-4 w-4 mr-1"}),"Back to categories"]}):n?null:(0,le.jsxs)("div",{className:"flex items-center justify-between mb-3",children:[(0,le.jsx)("h3",{className:"text-slate-700 text-sm font-light font-base44",children:"Ideas to get started"}),(0,le.jsxs)("button",{onClick:()=>{c(d())},className:"text-[#E14906] text-sm font-light font-base44 hover:bg-[rgba(255,172,105,0.35)] transition-colors rounded-[12px] bg-[rgba(255,172,105,0.15)] px-3 py-1.5 flex items-center gap-1.5",children:[(0,le.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 18 18",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:(0,le.jsx)("path",{"fill-rule":"evenodd","clip-rule":"evenodd",d:"M12.8666 7.5C12.4108 5.75002 10.9795 4.5 9 4.5C7.72136 4.5 6.7094 5.15855 5.67162 6.5H8V7.5H4V3.5H5V5.73571C6.17646 4.26385 7.39808 3.5 9 3.5C11.5163 3.5 13.4036 5 13.89 7.5C13.5 7.5 12.8666 7.5 12.8666 7.5ZM5.0271 9.5C5.4829 11.25 6.91417 12.5 8.8937 12.5C10.1723 12.5 11.1843 11.8414 12.2221 10.5H9.8937V9.5H13.8937V13.5H12.8937V11.2643C11.7172 12.7361 10.4956 13.5 8.8937 13.5C6.37744 13.5 4.5 12 4 9.5C4.5 9.5 5.0271 9.5 5.0271 9.5Z",fill:"#E14906"})}),"More ideas"]})]}),n?(()=>{if(!n)return null;const e=[{title:n.suggestion_1.title,prompt:n.suggestion_1.prompt},{title:n.suggestion_2.title,prompt:n.suggestion_2.prompt},{title:n.suggestion_3.title,prompt:n.suggestion_3.prompt},{title:n.suggestion_4.title,prompt:n.suggestion_4.prompt},{title:n.suggestion_5.title,prompt:n.suggestion_5.prompt}];return(0,le.jsx)("div",{className:"flex flex-wrap gap-2.5",children:e.map((e,t)=>(0,le.jsx)("button",{onClick:()=>m(e.prompt),className:"rounded-lg px-3.5 py-2 text-sm font-medium font-base44 flex items-center transition-all \n rounded-[30px] text-gray-800 bg-white/70 hover:shadow-sm",children:e.title},t))})})():s?(0,le.jsx)("div",{className:"flex flex-wrap gap-2.5",children:ea[s].map((e,t)=>(0,le.jsx)("button",{onClick:()=>m(e.description),className:"rounded-[100px] px-4 py-1.5 text-[14px] font-medium font-base44 flex items-center transition-all \n text-gray-800 bg-white/50 hover:shadow-sm",children:e.title},t))}):(0,le.jsx)("div",{className:"flex flex-wrap gap-2.5",children:o.map((e,t)=>(0,le.jsx)("button",{onClick:()=>(e=>{a(e)})(e),className:"rounded-[100px] px-4 hover:bg-black font-light hover:text-white hover:border-black py-1.5 text-[14px] font-base44 flex items-center transition-all \n text-gray-800 bg-white/50 hover:shadow-sm",children:e},t))})]})}function na(e){let{onStart:t,loading:s}=e;const[a,n]=(0,Y.useState)(""),[l,r]=(0,Y.useState)([]),[i,o]=(0,Y.useState)(!1),[c,d]=(0,Y.useState)(!1),[m,u]=(0,Y.useState)(null),[x]=(0,J.useSearchParams)(),h=(0,Z.Zp)(),[p,g]=(0,Y.useState)([]),[f,v]=(0,Y.useState)(!1),[b,j]=(0,Y.useState)({}),[y,N]=(0,Y.useState)(!1),[w,_]=(0,Y.useState)(!1),[k,C]=(0,Y.useState)(!1),[A,S]=(0,Y.useState)(!0);(0,Y.useEffect)(()=>{(async()=>{try{S(!0);const e=await ke.default.getCurrentUsage();_(e.is_over_limit),C(e.past_due)}catch(e){}finally{S(!1)}})()},[]),(0,Y.useEffect)(()=>{const e=x.get("integrations");if(e){const t=e.split(",");v(!0),Promise.all(t.map(e=>Kt.getCatalogItem(e))).then(e=>{const t=e.map(e=>e);g(t)}).catch(e=>{}).finally(()=>{v(!1)})}},[]);const E=()=>0===p.length||p.every(e=>{const t=e.item;return!t.required_secrets||0===t.required_secrets.length||t.required_secrets.every(e=>{const t=b[e.name];return!!t&&(!!("value"!==t.type||t.value&&""!==t.value.trim())&&!!("clone"!==t.type||t.value&&""!==t.value.trim()))})}),I=e=>{if(1===p.length)return n(""),r([]),u(null),o(!1),g([]),j({}),N(!1),void h("/");const t=p.filter(t=>t.item.id!==e);g(t);const s=t.map(e=>e.item.id).join(",");h(s?"/?integrations=".concat(s):"/");const a=(0,K.A)({},b),l=p.find(t=>t.item.id===e);l&&l.item.required_secrets&&(l.item.required_secrets.forEach(e=>{delete a[e.name]}),j(a)),N(!1)},T=()=>{h("/billing")},P=e=>{if(j(e),y){E()&&N(!1)}},L=()=>{var e;const t=m?(null===(e=Gt.find(e=>e.id===m))||void 0===e?void 0:e.name)||m:null;return(0,le.jsx)(St,{children:(0,le.jsxs)(Et,{children:[(0,le.jsx)(It,{asChild:!0,children:(0,le.jsxs)("button",{onClick:()=>d(!c),className:"flex items-center gap-1 px-2 py-1 rounded-md text-xs ".concat(m?"bg-purple-100 text-purple-700":"text-gray-600 hover:bg-gray-100"),children:[(0,le.jsx)(je.A,{className:"h-3 w-3"}),(0,le.jsx)("span",{children:t?"Style: ".concat(t):"Styling Instructions"})]})}),(0,le.jsx)(Tt,{side:"top",className:"bg-slate-800 text-white p-3 rounded-lg border-0 shadow-xl max-w-[300px]",children:(0,le.jsx)("div",{className:"space-y-2",children:(0,le.jsx)("p",{className:"text-xs leading-relaxed",children:"Select a UI style for your application. This will influence the visual design and components."})})})]})})},O=()=>0===p.length?null:(0,le.jsx)(St,{children:(0,le.jsxs)(Et,{children:[(0,le.jsx)(It,{asChild:!0,children:(0,le.jsxs)("div",{className:"flex items-center gap-1 px-2 py-1 rounded-md text-xs bg-green-100 text-green-700",children:[(0,le.jsx)(ye.A,{className:"h-3 w-3"}),(0,le.jsxs)("span",{children:["Integrations: ",p.length]})]})}),(0,le.jsx)(Tt,{side:"top",className:"bg-slate-800 text-white p-3 rounded-lg border-0 shadow-xl max-w-[300px]",children:(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsx)("p",{className:"text-xs font-medium",children:"Selected Integrations:"}),(0,le.jsx)("div",{className:"flex flex-wrap gap-1",children:p.map(e=>(0,le.jsx)(es,{className:"bg-green-700 text-xs",children:e.item.name},e.item.id))})]})})]})});return(0,le.jsxs)("div",{children:[(0,le.jsxs)("div",{className:"relative",children:[k&&(0,le.jsxs)("div",{className:"mb-3 p-4 bg-yellow-50 border border-yellow-200 rounded-md text-yellow-800 flex flex-col gap-3",children:[(0,le.jsxs)("div",{className:"flex items-center",children:[(0,le.jsx)(we.A,{className:"h-5 w-5 mr-2 flex-shrink-0"}),(0,le.jsx)("span",{className:"font-medium",children:"Subscription payment overdue"})]}),(0,le.jsx)("p",{className:"text-sm",children:"Your subscription payment is overdue, Access to some features is currently limited. Please update your payment method to regain full access."}),(0,le.jsx)("div",{children:(0,le.jsx)(Yt,{onClick:T,className:"bg-amber-600 hover:bg-amber-700 text-white",size:"sm",children:"Go to Billing"})})]}),!k&&w&&(0,le.jsxs)("div",{className:"mb-3 p-4 bg-amber-50 border border-amber-200 rounded-md text-amber-800 flex flex-col gap-3",children:[(0,le.jsxs)("div",{className:"flex items-center",children:[(0,le.jsx)(we.A,{className:"h-5 w-5 mr-2 flex-shrink-0"}),(0,le.jsx)("span",{className:"font-medium",children:"You've reached your usage limit"})]}),(0,le.jsx)("p",{className:"text-sm",children:"You need to upgrade your plan to continue creating apps."}),(0,le.jsx)("div",{children:(0,le.jsx)(Yt,{onClick:T,className:"bg-amber-600 hover:bg-amber-700 text-white",size:"sm",children:"Go to Billing"})})]}),y&&(0,le.jsxs)("div",{className:"mb-3 p-3 bg-red-50 border border-red-200 rounded-md text-red-600 text-sm flex items-center",children:[(0,le.jsx)(_e.A,{className:"h-4 w-4 mr-2 flex-shrink-0"}),(0,le.jsx)("span",{children:"Please fill in all required API keys before submitting."})]}),(0,le.jsx)(Wt,{value:a,files:l,onSend:()=>{const e=a.trim();if(e){if(w)return;if(!E())return void N(!0);t({text:e,files:l,deep_coding_mode:i,integrations:p.map(e=>e.item.id),secrets:b}),n(""),r([]),u(null),N(!1)}},placeholder:"Describe the app you want to create...",disabled:s||w||A,isProcessing:s||A,onValueChange:n,onFilesChange:r,variant:"home",customButtomLeft:e=>(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[e,(0,le.jsx)(L,{}),(0,le.jsx)(O,{})]})})]}),f?(0,le.jsxs)("div",{className:"mt-4 flex items-center justify-center p-4 bg-slate-50 rounded-lg border border-slate-200",children:[(0,le.jsx)(Ne.A,{className:"h-5 w-5 text-slate-400 animate-spin mr-3"}),(0,le.jsx)("p",{className:"text-sm text-slate-600",children:"Loading integration..."})]}):p.length>0?(0,le.jsx)("div",{children:p.map((e,t)=>(0,le.jsx)(Qs,{integration:e,secrets:b,onSecretsChange:P,onRemove:I},t))}):(0,le.jsx)(le.Fragment,{children:!w&&(0,le.jsx)(aa,{onSetPrompt:e=>{n(e)}})}),c&&(0,le.jsx)($t,{onSelectStyle:e=>{u(e),d(!1);const t=Gt.find(t=>t.id===e);t&&n(e=>{const s=e.trim();return s?"".concat(s,"\n------\n").concat(t.prompt):t.prompt})}})]})}var la=s(59051),ra=s.n(la),ia=s(75659);const oa=["className"],ca=["className"],da=["className"],ma=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,oa);return(0,le.jsx)(ia.bL,(0,K.A)({ref:t,className:Pe("relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",s)},a))});ma.displayName=ia.bL.displayName;const ua=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,ca);return(0,le.jsx)(ia._V,(0,K.A)({ref:t,className:Pe("aspect-square h-full w-full",s)},a))});ua.displayName=ia._V.displayName;const xa=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,da);return(0,le.jsx)(ia.H4,(0,K.A)({ref:t,className:Pe("flex h-full w-full items-center justify-center rounded-full bg-muted",s)},a))});xa.displayName=ia.H4.displayName;var ha=s(52257);function pa(){const e="https://app.base44.com";return e||"app.base44.com"}function ga(e){return e===function(){const e=pa();return new URL(e).host}()}function fa(e){return va(e.slug)}function va(e){const t="base44.app",s=(a=t).includes("localhost")||a.includes("127.0.0.1")?"http":"https";var a;return"".concat(s,"://").concat(e,".").concat(t)}const ba=function(e){let{app:t,linkToBuilder:s=!0}=e;const{user:a}=oe(),n=s?"/apps/".concat(t.id,"/editor/preview"):fa(t);return(0,le.jsx)(J.Link,{to:n,className:"block h-full group",title:"Open ".concat(t.name),children:(0,le.jsx)("div",{className:"bg-white rounded-[16px] overflow-hidden h-full border border-gray-100 hover:border-gray-700 hover:shadow-sm transition-all duration-300 p-3",children:(0,le.jsxs)("div",{className:"flex gap-3 h-full",children:[(0,le.jsx)("div",{className:"flex-shrink-0",children:(0,le.jsxs)(ma,{className:"h-20 w-20 rounded-[8px]",children:[(0,le.jsx)(ua,{src:t.logo_url,alt:"".concat(t.name," Logo")}),(0,le.jsx)(xa,{className:"bg-gradient-to-br from-orange-100 to-orange-50 text-orange-500 rounded-lg font-base44",children:(e=>{if(!e)return"?";const t=e.trim().split(" ");return 1===t.length?e.charAt(0).toUpperCase():(t[0].charAt(0)+t[1].charAt(0)).toUpperCase()})(t.name)})]})}),(0,le.jsxs)("div",{className:"flex-1 min-w-0 flex flex-col justify-between h-20",children:[(0,le.jsxs)("div",{className:"flex-1 mb-1",children:[(0,le.jsxs)("div",{className:"mb-1 flex items-center gap-1",children:[(0,le.jsx)("h3",{className:"font-medium text-slate-800 truncate font-base44 text-base leading-tight",children:t.name}),(0,le.jsx)("span",{className:"text-black opacity-0 group-hover:opacity-100 transition-opacity duration-300",children:(0,le.jsx)(ha.A,{size:16})})]}),(0,le.jsx)("p",{className:"text-sm text-slate-600 line-clamp-2 font-base44 leading-tight mb-1",children:t.user_description||"No description available"})]}),(0,le.jsx)("div",{className:"flex justify-between items-center",children:(0,le.jsxs)("div",{className:"flex items-center text-xs text-gray-400 font-base44",children:[(0,le.jsxs)("span",{className:"whitespace-nowrap flex-shrink-0",children:["Updated ",(l=t.updated_date,ra().utc(l,ra().ISO_8601).fromNow())]}),"platform_admin"===a.platform_role&&(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)("span",{className:"mx-2 w-1 h-1 bg-gray-200 rounded-full flex-shrink-0"}),(0,le.jsxs)("span",{className:"truncate min-w-0",children:["by ",(e=>{if(null!=e&&e.includes("@")){const t=e.split("@")[0];return t.charAt(0).toUpperCase()+t.slice(1)}return e})(t.created_by)]})]})]})})]})]})})});var l};const ja=function(){const[e,t]=(0,Y.useState)([]),[s,a]=(0,Y.useState)(!0),n=(0,Z.Zp)(),{activeWorkspaceId:l}=ge();(0,Y.useEffect)(()=>{r()},[l]);const r=async()=>{a(!0);try{const e=await ve.list("-updated_date",9,0,["id","name","user_description","status","updated_date","logo_url","created_date","created_by"].join(","));t(e)}catch(e){}finally{a(!1)}};return(0,le.jsxs)("div",{className:"fade-in",children:[(0,le.jsxs)("div",{className:"flex items-center justify-between mb-6",children:[(0,le.jsx)("div",{className:"relative",children:(0,le.jsx)("h2",{className:"text-xl font-bold text-slate-900 font-base44",children:"Recent Apps"})}),e.length>6&&(0,le.jsx)("button",{onClick:()=>{n("/apps")},className:"text-sm text-orange-600 hover:text-orange-700 font-medium",children:"View all"})]}),s?(0,le.jsx)("div",{className:"flex justify-center py-12",children:(0,le.jsx)("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-orange-500"})}):e.length>0?(0,le.jsx)("div",{className:"grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-5 slide-up",children:e.map((e,t)=>(0,le.jsx)("div",{className:"animate-in",style:{animationDelay:"".concat(80*t,"ms")},children:(0,le.jsx)(ba,{app:e})},e.id))}):(0,le.jsxs)("div",{className:"text-center py-12 border-2 border-dashed border-slate-200 rounded-xl fade-in md:p-8",children:[(0,le.jsx)("h3",{className:"text-xl mb-4 text-slate-800",children:"You haven't created any apps yet."}),(0,le.jsx)("p",{className:"text-slate-600 mb-6",children:"Create your first app using the form above!"})]}),(0,le.jsx)("style",{jsx:!0,global:!0,children:"\n .fade-in {\n animation: fadeIn 0.5s ease-out;\n }\n \n .slide-up > * {\n opacity: 0;\n transform: translateY(15px);\n }\n \n .animate-in {\n animation: slideUp 0.4s ease-out forwards;\n }\n \n @keyframes fadeIn {\n from { opacity: 0; }\n to { opacity: 1; }\n }\n \n @keyframes slideUp {\n from { \n opacity: 0;\n transform: translateY(15px);\n }\n to { \n opacity: 1;\n transform: translateY(0);\n }\n }\n "})]})};var ya=s(6890);class Na extends Q.H{getBaseURL(){return"/app-logs"}fetchLogs(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return this.axios.get("/".concat(e),{params:t})}logUserInApp(e,t){return this.axios.post("/".concat(e,"/log-user-in-app/").concat(t))}getStats(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return"all"===e?this.axios.get("/platform-admin/platform-stats",{params:t}):this.axios.get("/".concat(e,"/stats"),{params:t})}getUserStats(e){return this.axios.get("/user-stats/".concat(e))}getTrendingApps(){return(0,ae.Ay)("/apps/public").get("/trending")}}const wa=new Na;function _a(){const[e,t]=(0,Y.useState)([]),[s,a]=(0,Y.useState)(!0);return(0,Y.useEffect)(()=>{(async()=>{try{const e=await wa.getTrendingApps();t(e.trending_apps.map(e=>(0,K.A)((0,K.A)({},e),{},{created_by:"Community"})))}catch(e){}finally{a(!1)}})()},[]),s?(0,le.jsxs)("div",{className:"mt-12",children:[(0,le.jsxs)("h2",{className:"text-2xl font-bold mb-6 flex items-center",children:[(0,le.jsx)(ya.A,{className:"w-6 h-6 mr-2"}),"Trending Apps"]}),(0,le.jsx)("div",{className:"flex justify-center",children:(0,le.jsx)("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-primary"})})]}):e.length?(0,le.jsx)("div",{className:"mt-12",children:(0,le.jsx)("div",{className:"grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-6",children:e.map(e=>(0,le.jsx)(ba,{app:e,linkToBuilder:!1},e.id))})}):null}var ka=s(4174);const Ca=["className"],Aa=["className","children"],Sa=["className"],Ea=["className"],Ia=["className"],Ta=["className"],Pa=ka.Root,La=ka.Trigger,Oa=ka.Portal,Ra=ka.Close,Ma=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,Ca);return(0,le.jsx)(ka.Overlay,(0,K.A)({ref:t,className:Pe("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",s)},a))});Ma.displayName=ka.Overlay.displayName;const Da=Y.forwardRef((e,t)=>{let{className:s,children:a}=e,n=(0,Se.A)(e,Aa);return(0,le.jsxs)(Oa,{children:[(0,le.jsx)(Ma,{}),(0,le.jsxs)(ka.Content,(0,K.A)((0,K.A)({ref:t,className:Pe("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",s)},n),{},{children:[a,(0,le.jsxs)(ka.Close,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground",children:[(0,le.jsx)(Bt.A,{className:"h-4 w-4"}),(0,le.jsx)("span",{className:"sr-only",children:"Close"})]})]}))]})});Da.displayName=ka.Content.displayName;const Fa=e=>{let{className:t=""}=e,s=(0,Se.A)(e,Sa);return(0,le.jsx)("div",(0,K.A)({className:Pe("flex flex-col space-y-1.5 text-center sm:text-left",t)},s))};Fa.displayName="DialogHeader";const Ba=e=>{let{className:t}=e,s=(0,Se.A)(e,Ea);return(0,le.jsx)("div",(0,K.A)({className:Pe("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",t)},s))};Ba.displayName="DialogFooter";const za=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,Ia);return(0,le.jsx)(ka.Title,(0,K.A)({ref:t,className:Pe("text-lg font-semibold leading-none tracking-tight",s)},a))});za.displayName=ka.Title.displayName;const Ua=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,Ta);return(0,le.jsx)(ka.Description,(0,K.A)({ref:t,className:Pe("text-sm text-muted-foreground",s)},a))});Ua.displayName=ka.Description.displayName;var Wa=s(68935),qa=s(6285),Va=s(72916);class Ha extends Q.y{getBaseURL(){return"/custom-domains"}refreshStatus(e){return this.axios.post("/".concat(e,"/status"))}verify(e){return this.axios.post("/".concat(e,"/verify"))}unlink(e){return this.axios.post("/".concat(e,"/unlink"))}link(e){return this.axios.post("/".concat(e,"/link"))}getEntriToken(e){let{appId:t,appName:s,domain:a}=e;return(0,ae.Ay)("/apps/buy_domain").post("/start",{appId:t,appName:s,domain:a})}}const Ya=new Ha,Ga=e=>{let{app:t,isOpen:s,onClose:a}=e;const[n,l]=(0,Y.useState)([]);(0,Y.useEffect)(()=>{(async()=>{if(s&&t)try{const e=await Ya.filter({app_id:t.id});l(e)}catch(e){}})()},[s,null==t?void 0:t.id]);const r=e=>{const s=t?"I've built ".concat(t.name," with @base_44!"):"Check out what I built with @base_44!",a=t&&n.length>0?"https://".concat(n[0].domain):t?fa(t):window.location.href;"twitter"===e?window.open("https://x.com/intent/tweet?text=".concat(encodeURIComponent(s))):"linkedin"===e&&window.open("https://www.linkedin.com/sharing/share-offsite/?url=".concat(encodeURIComponent(a)))};return(0,le.jsx)(Pa,{open:s,onOpenChange:a,children:(0,le.jsxs)(Da,{className:"sm:max-w-[625px]",children:[(0,le.jsxs)(Fa,{children:[(0,le.jsx)("div",{className:"flex justify-between items-center",children:(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[(0,le.jsx)(Wa.A,{className:"h-5 w-5 text-primary"}),(0,le.jsx)(za,{className:"text-xl",children:t?"Share ".concat(t.name):"Share Project"})]})}),(0,le.jsx)(Ua,{className:"text-sm text-muted-foreground",children:"Share your project and earn 20 free credits to keep building!"})]}),(0,le.jsxs)("div",{className:"space-y-6",children:[(0,le.jsxs)("div",{className:"bg-secondary/20 p-4 rounded-lg space-y-3 border border-border",children:[(0,le.jsx)("h3",{className:"font-medium text-sm",children:"Sharing Guidelines"}),(0,le.jsxs)("ul",{className:"space-y-2.5 text-sm text-muted-foreground",children:[(0,le.jsxs)("li",{className:"flex items-center gap-2",children:[(0,le.jsx)("div",{className:"h-1.5 w-1.5 rounded-full bg-primary/70"}),"Tag ",(0,le.jsx)("span",{className:"font-medium text-foreground",children:"@base_44"})]}),(0,le.jsxs)("li",{className:"flex items-center gap-2",children:[(0,le.jsx)("div",{className:"h-1.5 w-1.5 rounded-full bg-primary/70"}),"Write at least 200 characters about your experience building with Base44"]}),(0,le.jsxs)("li",{className:"flex items-center gap-2",children:[(0,le.jsx)("div",{className:"h-1.5 w-1.5 rounded-full bg-primary/70"}),"Account must have over 100 followers"]}),(0,le.jsxs)("li",{className:"flex items-center gap-2",children:[(0,le.jsx)("div",{className:"h-1.5 w-1.5 rounded-full bg-primary/70"}),"Add a screenshot or video of your project (optional)"]}),(0,le.jsxs)("li",{className:"flex items-center gap-2",children:[(0,le.jsx)("div",{className:"h-1.5 w-1.5 rounded-full bg-primary/70"}),"Add a link to your project (optional)"]}),(0,le.jsxs)("li",{className:"flex items-center gap-2",children:[(0,le.jsx)("div",{className:"h-1.5 w-1.5 rounded-full bg-primary/70"}),"Open a ticket, at ",(0,le.jsx)("button",{type:"button",onClick:()=>{const e=null!=t&&t.id?"/support?appId=".concat(t.id):"/support";window.open(e,"_blank")},className:"underline text-primary hover:text-orange-500 transition-colors",children:"support system"}),", with the link to your post"]})]})]}),(0,le.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,le.jsxs)(Yt,{variant:"outline",className:"w-full justify-start gap-2 font-normal",onClick:()=>r("linkedin"),children:[(0,le.jsx)(qa.A,{className:"h-4 w-4"}),"Share on LinkedIn"]}),(0,le.jsxs)(Yt,{variant:"outline",className:"w-full justify-start gap-2 font-normal",onClick:()=>r("twitter"),children:[(0,le.jsx)(Va.A,{className:"h-4 w-4"}),"Share on X (Twitter)"]})]})]})]})})};const $a=new class extends Zt{getBaseURL(){return"/app-catalog-items"}async getListingIfExists(e){const t=await this.filter({app_id:e});return t.length>0?t[0]:null}};var Ja=s(20454);let Za=0;const Ka=new Map,Qa=e=>{if(Ka.has(e))return;const t=setTimeout(()=>{Ka.delete(e),sn({type:"REMOVE_TOAST",toastId:e})},1e6);Ka.set(e,t)},Xa=(e,t)=>{switch(t.type){case"ADD_TOAST":return(0,K.A)((0,K.A)({},e),{},{toasts:[t.toast,...e.toasts].slice(0,1)});case"UPDATE_TOAST":return(0,K.A)((0,K.A)({},e),{},{toasts:e.toasts.map(e=>e.id===t.toast.id?(0,K.A)((0,K.A)({},e),t.toast):e)});case"DISMISS_TOAST":{const{toastId:s}=t;return s?Qa(s):e.toasts.forEach(e=>{Qa(e.id)}),(0,K.A)((0,K.A)({},e),{},{toasts:e.toasts.map(e=>e.id===s||void 0===s?(0,K.A)((0,K.A)({},e),{},{open:!1}):e)})}case"REMOVE_TOAST":return void 0===t.toastId?(0,K.A)((0,K.A)({},e),{},{toasts:[]}):(0,K.A)((0,K.A)({},e),{},{toasts:e.toasts.filter(e=>e.id!==t.toastId)})}},en=[];let tn={toasts:[]};function sn(e){tn=Xa(tn,e),en.forEach(e=>{e(tn)})}function an(e){let t=Object.assign({},((0,Ja.A)(e),e));const s=(Za=(Za+1)%Number.MAX_SAFE_INTEGER,Za.toString()),a=()=>sn({type:"DISMISS_TOAST",toastId:s});return sn({type:"ADD_TOAST",toast:(0,K.A)((0,K.A)({},t),{},{id:s,open:!0,onOpenChange:e=>{e||a()}})}),{id:s,dismiss:a,update:e=>sn({type:"UPDATE_TOAST",toast:(0,K.A)((0,K.A)({},e),{},{id:s})})}}function nn(){const[e,t]=Y.useState(tn);return Y.useEffect(()=>(en.push(t),()=>{const e=en.indexOf(t);e>-1&&en.splice(e,1)}),[e]),(0,K.A)((0,K.A)({},e),{},{toast:an,dismiss:e=>sn({type:"DISMISS_TOAST",toastId:e})})}var ln=s(38554),rn=s(90983),on=s(37524),cn=s(7082);const dn=e=>e&&"string"==typeof e?cn.A.sanitize(e,{ALLOWED_TAGS:["p","br","strong","b","em","i","u","s","ol","ul","li","blockquote","h1","h2","h3","a","code","pre"],ALLOWED_ATTR:["href","target","rel"],ALLOWED_URI_REGEXP:/^(?:(?:https?|mailto):|[^a-z]|[a-z+.-]+(?:[^a-z+.-:]|$))/i,ALLOW_DATA_ATTR:!1,FORBID_SCRIPT:!0,FORBID_TAGS:["script","object","embed","iframe","form","input","button","svg","math","link","meta","style"],FORBID_ATTR:["onerror","onload","onclick","onmouseover","onfocus","onblur","onkeyup","onkeydown","onchange","onsubmit","onreset","onselect","onabort","style","cite"],KEEP_CONTENT:!0,RETURN_DOM:!1,RETURN_DOM_FRAGMENT:!1,RETURN_DOM_IMPORT:!1,SANITIZE_DOM:!0,HOOKS:{beforeSanitizeElements:e=>e}}):"";const mn=function(e){let{content:t}=e;return(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)("style",{dangerouslySetInnerHTML:{__html:"\n .expandable-description h1 { font-size: 1.25rem; font-weight: 600; margin-bottom: 0.75rem; color: #0f172a; }\n .expandable-description h2 { font-size: 1.125rem; font-weight: 600; margin-bottom: 0.5rem; color: #0f172a; }\n .expandable-description h3 { font-size: 1rem; font-weight: 600; margin-bottom: 0.5rem; color: #0f172a; }\n .expandable-description p { margin-bottom: 0.75rem; line-height: 1.6; color: #475569; }\n .expandable-description ul, .expandable-description ol { margin-bottom: 0.75rem; padding-left: 1.5rem; color: #475569; }\n .expandable-description li { margin-bottom: 0.25rem; }\n .expandable-description strong { font-weight: 600; color: #334155; }\n .expandable-description em { font-style: italic; }\n .expandable-description blockquote { border-left: 3px solid #e2e8f0; padding-left: 1rem; margin: 0.75rem 0; color: #64748b; }\n .expandable-description code { background: #f1f5f9; padding: 0.125rem 0.375rem; border-radius: 0.25rem; font-size: 0.875rem; color: #0f172a; }\n .expandable-description pre { background: #f1f5f9; padding: 1rem; border-radius: 0.5rem; overflow-x: auto; margin-bottom: 0.75rem; }\n .expandable-description a { color: #f97316; text-decoration: underline; }\n .expandable-description a:hover { color: #ea580c; }\n .expandable-description > *:last-child { margin-bottom: 0; }\n "}}),(0,le.jsx)("div",{className:"relative",children:(0,le.jsx)("div",{className:"expandable-description text-sm",dangerouslySetInnerHTML:{__html:dn(t)}})})]})},un=["className","children"],xn=e=>{let{className:t,children:s}=e,a=(0,Se.A)(e,un);return(0,le.jsxs)(ka.Portal,{children:[(0,le.jsx)(ka.Overlay,{className:"fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0"}),(0,le.jsx)(ka.Content,(0,K.A)((0,K.A)({className:Pe("fixed left-[50%] top-[50%] z-50 w-full translate-x-[-50%] translate-y-[-50%] bg-background shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] rounded-[16px]",t)},a),{},{children:s}))]})};const hn=function(e){var t,s,a,n,l,r;let{isOpen:i,onClose:o,selectedItem:c,onItemUpdate:d}=e;const{user:m}=oe(),[u,x]=(0,Y.useState)(0),[h,p]=(0,Y.useState)(!1);return(0,Y.useEffect)(()=>{i&&c&&x(0)},[i,c]),(0,le.jsx)(Pa,{open:i,onOpenChange:o,className:!0,children:(0,le.jsx)(xn,{className:"max-w-[80vw] md:max-w-[80vw] max-w-[95vw] h-[85vh] md:h-[85vh] h-[90vh] bg-white shadow-2xl",children:c&&(0,le.jsxs)("div",{className:"h-full flex flex-col",children:[(0,le.jsx)("div",{className:"flex-shrink-0 flex items-center justify-end rounded-t-[16px] px-3 pt-3",children:(0,le.jsx)(Yt,{variant:"ghost",size:"icon",onClick:o,className:"h-8 w-8",children:(0,le.jsx)(Bt.A,{className:"h-6 w-6"})})}),(0,le.jsx)("div",{className:"flex-1 p-[18px] md:p-[18px] p-4 overflow-y-auto md:overflow-y-auto overflow-visible",children:(0,le.jsxs)("div",{className:"flex flex-col md:flex-row md:h-full",children:[(0,le.jsxs)("div",{className:"w-full md:w-[65%] flex flex-col mb-6 md:mb-0",children:[(null===(t=c.item.screenshot_urls)||void 0===t?void 0:t.length)>0?(0,le.jsxs)("div",{className:"md:flex-1 relative rounded-[12px] overflow-hidden border border-black/10 rounded-[12px] min-h-[250px] md:min-h-0 aspect-video md:aspect-auto",children:[(0,le.jsx)("div",{className:"absolute inset-0",style:{backgroundImage:"url(".concat(c.item.screenshot_urls[u],")"),backgroundSize:"auto",backgroundPosition:"center",backgroundRepeat:"no-repeat",width:"100%",height:"100%",filter:"blur(10px)",opacity:.5}}),(0,le.jsx)("div",{className:"absolute inset-0 flex items-center justify-center",children:(0,le.jsx)("img",{src:c.item.screenshot_urls[u],alt:"Screenshot ".concat(u+1),className:"w-full h-full object-contain"})})]}):(0,le.jsx)("div",{className:"md:flex-1 rounded-[12px] flex items-center justify-center bg-slate-50 min-h-[250px] md:min-h-0 aspect-video md:aspect-auto",children:(0,le.jsx)(ln.A,{className:"w-16 h-16 text-slate-300"})}),(null===(s=c.item.screenshot_urls)||void 0===s?void 0:s.length)>1&&(0,le.jsxs)("div",{className:"flex items-center gap-4 mt-6 justify-center flex-shrink-0",children:[(0,le.jsx)("button",{onClick:()=>x(e=>e>0?e-1:c.item.screenshot_urls.length-1),className:"p-2 rounded-full hover:bg-slate-100 transition-colors","aria-label":"Previous screenshot",children:(0,le.jsx)(Xs.A,{className:"w-5 h-5 text-slate-600"})}),(0,le.jsx)("div",{className:"flex gap-3",children:c.item.screenshot_urls.map((e,t)=>(0,le.jsx)("button",{onClick:()=>x(t),className:Pe("w-3 h-3 rounded-full transition-all",u===t?"bg-slate-900":"bg-slate-200 hover:bg-slate-300"),"aria-label":"Go to screenshot ".concat(t+1)},t))}),(0,le.jsx)("button",{onClick:()=>x(e=>e{window.open("/apps/".concat(c.item.app_id,"/editor/workspace/app-settings?tab=appListing"),"_blank"),o()},className:"h-10 flex-1 w-[128px] border border-orange-500 text-orange-500 bg-white hover:bg-orange-50 rounded-[12px]",children:["Manage Listing ",(0,le.jsx)(on.A,{className:"w-4 h-4 ml-1"})]})}),(0,le.jsx)("div",{className:"flex gap-3",children:"platform_admin"===(null==m?void 0:m.platform_role)&&("approved"===c.item.status?(0,le.jsx)(Yt,{onClick:async()=>{p(!0);try{await $a.declineItem(c.item.id),an({title:"Success",description:"App listing declined successfully"}),d((0,K.A)((0,K.A)({},c),{},{item:(0,K.A)((0,K.A)({},c.item),{},{status:"pending"})}))}catch(e){an({title:"Error",description:"Failed to decline listing",variant:"destructive"})}finally{p(!1)}},disabled:h,className:"h-10 w-full border border-red-500 text-red-500 bg-white hover:bg-red-50 rounded-[12px]",children:h?(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(Ne.A,{className:"w-4 h-4 mr-2 animate-spin"}),"Declining..."]}):"Decline Listing"}):(0,le.jsx)(Yt,{onClick:async()=>{p(!0);try{await $a.approveItem(c.item.id),an({title:"Success",description:"App listing approved successfully"}),d((0,K.A)((0,K.A)({},c),{},{item:(0,K.A)((0,K.A)({},c.item),{},{status:"approved"})}))}catch(e){an({title:"Error",description:"Failed to approve listing",variant:"destructive"})}finally{p(!1)}},disabled:h,className:"h-10 w-full bg-green-500 text-white hover:bg-green-600 rounded-[12px]",children:h?(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(Ne.A,{className:"w-4 h-4 mr-2 animate-spin"}),"Approving..."]}):"Approve Listing"}))}),(0,le.jsxs)("div",{className:"flex gap-3",children:[(0,le.jsx)(Yt,{onClick:()=>{window.open("/remix-app/".concat(c.item.app_id),"_blank")},className:"h-10 flex-1 bg-slate-900 hover:bg-slate-800 text-white rounded-[12px]",children:"Clone App"}),(0,le.jsxs)(Yt,{variant:"outline",onClick:async()=>{const e=await ve.getLoginInfoById(c.item.app_id),t="https://".concat(e.slug,".base44.app");window.open(t,"_blank")},className:"h-10 w-[128px] rounded-[12px]",children:["View App ",(0,le.jsx)(on.A,{className:"w-4 h-4 ml-1"})]})]}),(0,le.jsx)("div",{className:"mt-[36px]",children:(0,le.jsx)("div",{className:"flex flex-wrap gap-2",children:c.item.categories&&c.item.categories.length>0?c.item.categories.map((e,t)=>(0,le.jsx)(es,{variant:"outline",className:"px-3 py-1 text-[14px] font-normal bg-slate-100 border border-slate-200 text-slate-700 ",children:e},t)):(0,le.jsx)(es,{variant:"secondary",className:"px-3 py-1 text-sm font-normal bg-slate-50 text-slate-700 border-slate-200",children:"No categories"})})})]}),(0,le.jsx)("div",{className:"space-y-8 mt-[18px]",children:(0,le.jsx)("div",{children:(0,le.jsx)(mn,{content:c.item.description||"

No description available

"})})})]})]})})]})})})};function pn(){return(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)("h1",{className:"text-5xl font-base44 font-medium mb-4 mt-6",children:"Explore templates from the community"}),(0,le.jsx)("p",{className:"text-lg font-base44 max-w-2xl mb-4",children:"Discover a curated collection of applications built by our community."})]})}const gn=["className","type"],fn=Y.forwardRef((e,t)=>{let{className:s,type:a}=e,n=(0,Se.A)(e,gn);return(0,le.jsx)("input",(0,K.A)({type:a,className:Pe("flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-base ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",s),ref:t},n))});fn.displayName="Input";var vn=s(13147),bn=s(29126);const jn=["className","variant"],yn=(0,Ee.cva)("inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground hover:bg-primary/80",secondary:"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",destructive:"border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80",outline:"text-foreground"}},defaultVariants:{variant:"default"}});function Nn(e){let{className:t,variant:s}=e,a=(0,Se.A)(e,jn);return(0,le.jsx)("div",(0,K.A)({className:Pe(yn({variant:s}),t)},a))}const wn=["className","children","advancedDropdown"],_n=["className"],kn=["className"],Cn=["className","children","position"],An=["className"],Sn=["className","children","hideCheckIcon"],En=["className"],In=Es.bL,Tn=(Es.YJ,Es.WT),Pn=Y.forwardRef((e,t)=>{let{className:s,children:a,advancedDropdown:n=!1}=e,l=(0,Se.A)(e,wn);return(0,le.jsxs)(Es.l9,(0,K.A)((0,K.A)({ref:t,className:Pe("flex h-10 w-full items-center justify-between ".concat(n?"rounded-lg":"rounded-md"," border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1"),s)},l),{},{children:[n?(0,le.jsx)("div",{className:"flex-1 min-w-0",children:a}):a,(0,le.jsx)(Es.In,{asChild:!0,children:(0,le.jsx)(Is.A,{className:Pe("h-4 w-4 opacity-50",n?"flex-shrink-0 ml-2":"")})})]}))});Pn.displayName=Es.l9.displayName;const Ln=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,_n);return(0,le.jsx)(Es.PP,(0,K.A)((0,K.A)({ref:t,className:Pe("flex cursor-default items-center justify-center py-1",s)},a),{},{children:(0,le.jsx)(Ts.A,{className:"h-4 w-4"})}))});Ln.displayName=Es.PP.displayName;const On=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,kn);return(0,le.jsx)(Es.wn,(0,K.A)((0,K.A)({ref:t,className:Pe("flex cursor-default items-center justify-center py-1",s)},a),{},{children:(0,le.jsx)(Is.A,{className:"h-4 w-4"})}))});On.displayName=Es.wn.displayName;const Rn=Y.forwardRef((e,t)=>{let{className:s,children:a,position:n="popper"}=e,l=(0,Se.A)(e,Cn);return(0,le.jsx)(Es.ZL,{children:(0,le.jsxs)(Es.UC,(0,K.A)((0,K.A)({ref:t,className:Pe("relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2","popper"===n&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",s),position:n},l),{},{children:[(0,le.jsx)(Ln,{}),(0,le.jsx)(Es.LM,{className:Pe("p-1","popper"===n&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:a}),(0,le.jsx)(On,{})]}))})});Rn.displayName=Es.UC.displayName;Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,An);return(0,le.jsx)(Es.JU,(0,K.A)({ref:t,className:Pe("py-1.5 pl-8 pr-2 text-sm font-semibold",s)},a))}).displayName=Es.JU.displayName;const Mn=Y.forwardRef((e,t)=>{let{className:s,children:a,hideCheckIcon:n=!1}=e,l=(0,Se.A)(e,Sn);return(0,le.jsxs)(Es.q7,(0,K.A)((0,K.A)({ref:t,className:Pe("relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",n?"pl-2 pr-2":"pl-8 pr-2",s)},l),{},{children:[!n&&(0,le.jsx)("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:(0,le.jsx)(Es.VF,{children:(0,le.jsx)(Ps.A,{className:"h-4 w-4"})})}),(0,le.jsx)(Es.p4,{children:a})]}))});Mn.displayName=Es.q7.displayName;Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,En);return(0,le.jsx)(Es.wv,(0,K.A)({ref:t,className:Pe("-mx-1 my-1 h-px bg-muted",s)},a))}).displayName=Es.wv.displayName;const Dn=["Marketing & Sales","Operations","Data & Analytics","Content Generation","HR & Legal","Finance","Education","Community","Lifestyle & Hobbies","Games & Entertainment"],Fn=[{value:"everyone",label:"Owned by everyone"},{value:"me",label:"Owned by me"},{value:"not_me",label:"Not owned by me"}],Bn=[{label:"English",value:"en"},{label:"Deutsch",value:"de"},{label:"Espa\xf1ol",value:"es"},{label:"Fran\xe7ais",value:"fr"},{label:"Italiano",value:"it"},{label:"\u65e5\u672c\u8a9e",value:"ja"},{label:"\u4e2d\u6587",value:"zh"},{label:"\u0939\u093f\u0928\u094d\u0926\u0940",value:"hi"},{label:"Portugu\xeas",value:"pt"},{label:"\u05e2\u05d1\u05e8\u05d9\u05ea",value:"he"},{label:"\u0627\u0644\u0639\u0631\u0628\u064a\u0629",value:"ar"},{label:"Bahasa Indonesia",value:"id"}],zn="everyone",Un="popular";function Wn(e){let{searchTerm:t,onSearchChange:s,selectedCategory:a,onCategoryChange:n,ownership:l,onOwnershipChange:r,sortBy:i,onSortByChange:o,selectedLanguage:c,onLanguageChange:d}=e;return(0,le.jsxs)("div",{className:"mt-[42px] mb-6",children:[(0,le.jsxs)("div",{className:"flex flex-col sm:flex-row sm:items-center gap-3 w-full sm:justify-between",children:[(0,le.jsxs)("div",{className:"flex items-center rounded-xl border border-[#E4E4E7] bg-white flex-1 max-w-[420px] h-[40px] px-3 sm:px-[11px]",children:[(0,le.jsx)(vn.A,{className:"w-4 h-4 text-[#000] flex-shrink-0"}),(0,le.jsx)(fn,{placeholder:"Search apps...",value:t,onChange:e=>s(e.target.value),className:"border-0 bg-transparent focus-visible:ring-0 focus-visible:ring-offset-0 placeholder:text-[#B4B4B4] text-black"})]}),(0,le.jsxs)("div",{className:"flex items-center gap-3 justify-start sm:justify-end",children:[(0,le.jsxs)(In,{value:l,onValueChange:r,children:[(0,le.jsx)(Pn,{className:"w-auto min-w-[140px] h-[40px] font-base44 border-0 bg-transparent px-0 text-black focus-visible:ring-0 focus-visible:ring-offset-0 [&>svg]:text-black [&>svg]:ml-2",children:(0,le.jsx)(Tn,{placeholder:"Ownership"})}),(0,le.jsx)(Rn,{children:Fn.map(e=>(0,le.jsx)(Mn,{value:e.value,className:"font-base44",children:e.label},e.value))})]}),(0,le.jsxs)(In,{value:c,onValueChange:d,children:[(0,le.jsx)(Pn,{className:"w-auto min-w-[120px] h-[40px] font-base44 border-0 bg-transparent px-0 text-black [&>svg]:text-black [&>svg]:ml-2",children:(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[(0,le.jsx)(bn.A,{className:"w-4 h-4 text-black"}),(0,le.jsx)(Tn,{placeholder:"Language"})]})}),(0,le.jsx)(Rn,{children:Bn.map(e=>(0,le.jsx)(Mn,{value:e.value,className:"font-base44",children:e.label},e.value))})]})]})]}),(0,le.jsx)("div",{className:"w-full overflow-x-auto pb-2 mt-[18px]",children:(0,le.jsxs)("div",{className:"flex items-center space-x-2 min-w-max",children:[(0,le.jsx)(Nn,{variant:"all"===a?"default":"outline",className:Pe("cursor-pointer text-sm px-3 font-base44 font-light py-1 bg-white","all"===a?"bg-slate-800 text-white hover:bg-slate-700":"hover:bg-slate-100 text-slate-800"),onClick:()=>n("all"),children:"All Apps"}),(0,le.jsx)("div",{className:"h-4 w-px bg-slate-200"}),Dn.map(e=>(0,le.jsx)(Nn,{variant:a===e?"default":"outline",className:Pe("cursor-pointer text-sm font-base44 font-light px-3 py-1 bg-white",a===e?"bg-slate-800 text-white hover:bg-slate-700":"hover:bg-slate-100 text-slate-800"),onClick:()=>n(e),children:e},e))]})})]})}const qn=["className","variant","size","asChild"],Vn=(0,Ee.cva)("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-colors disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/90",outline:"border border-input bg-background hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-10 px-4 py-2",sm:"h-9 rounded-md px-3",lg:"h-11 rounded-md px-8",icon:"h-10 w-10",tiny:"h-8 rounded-lg px-2"}},defaultVariants:{variant:"default",size:"default"}}),Hn=Y.forwardRef((e,t)=>{let{className:s,variant:a,size:n,asChild:l=!1}=e,r=(0,Se.A)(e,qn);const i=l?qt.DX:"button";return(0,le.jsx)(i,(0,K.A)({className:Pe(Vn({variant:a,size:n,className:s})),ref:t},r))});Hn.displayName="Button";const Yn=["className"],Gn=["className"],$n=["className"],Jn=["className"],Zn=["className"],Kn=["className"],Qn=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,Yn);return(0,le.jsx)("div",(0,K.A)({ref:t,className:Pe("rounded-lg border bg-card text-card-foreground shadow-sm",s)},a))});Qn.displayName="Card";const Xn=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,Gn);return(0,le.jsx)("div",(0,K.A)({ref:t,className:Pe("flex flex-col space-y-1.5 px-6 py-4",s)},a))});Xn.displayName="CardHeader";const el=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,$n);return(0,le.jsx)("h3",(0,K.A)({ref:t,className:Pe("font-medium leading-none tracking-tight",s)},a))});el.displayName="CardTitle";const tl=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,Jn);return(0,le.jsx)("p",(0,K.A)({ref:t,className:Pe("text-sm text-muted-foreground",s)},a))});tl.displayName="CardDescription";const sl=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,Zn);return(0,le.jsx)("div",(0,K.A)({ref:t,className:Pe("px-6 py-3",s)},a))});sl.displayName="CardContent";const al=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,Kn);return(0,le.jsx)("div",(0,K.A)({ref:t,className:Pe("flex items-center px-6 pt-0 pb-3",s)},a))});al.displayName="CardFooter";const nl=["className"],ll=["className"],rl=["className"],il=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,nl);return(0,le.jsx)(ia.bL,(0,K.A)({ref:t,className:Pe("relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",s)},a))});il.displayName=ia.bL.displayName;const ol=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,ll);return(0,le.jsx)(ia._V,(0,K.A)({ref:t,className:Pe("aspect-square h-full w-full",s)},a))});ol.displayName=ia._V.displayName;const cl=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,rl);return(0,le.jsx)(ia.H4,(0,K.A)({ref:t,className:Pe("flex h-full w-full items-center justify-center rounded-full bg-muted",s)},a))});cl.displayName=ia.H4.displayName;var dl=s(79992);function ml(e){const t={isSupabaseUrl:!1,originalUrl:e};try{const s=new URL(e);if(!s.hostname.includes("supabase.co"))return t;const a=s.hostname.match(/^([^.]+)\.supabase\.co$/);if(!a)return t;t.projectId=a[1],t.isSupabaseUrl=!0;const n=s.pathname.match(/^\/storage\/v1\/(object|render\/image)\/public\/([^/]+)\/(.+)$/);n&&(t.bucket=n[2],t.filePath=n[3],t.baseUrl="".concat(s.origin,"/storage/v1/render/image/public/").concat(t.bucket,"/").concat(t.filePath)),t.existingParams=new URLSearchParams(s.search)}catch(s){0}return t}function ul(e){const t=ml(e);return t.isSupabaseUrl&&!!t.bucket&&!!t.filePath}function xl(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const s=ml(e);if(!s.isSupabaseUrl||!s.baseUrl)return e;const a=new URLSearchParams;if(void 0!==t.width){const e=Math.min(Math.max(Math.round(t.width),1),2500);a.set("width",e.toString())}if(void 0!==t.height){const e=Math.min(Math.max(Math.round(t.height),1),2500);a.set("height",e.toString())}if(void 0!==t.quality){const e=Math.min(Math.max(Math.round(t.quality),20),100);a.set("quality",e.toString())}t.resize&&"cover"!==t.resize&&a.set("resize",t.resize),"origin"===t.format&&a.set("format","origin");const n=a.toString();return n?"".concat(s.baseUrl,"?").concat(n):s.baseUrl}function hl(e,t){const{baseWidth:s,baseHeight:a,devicePixelRatios:n=[1,2,3],quality:l=80,resize:r="cover",sizes:i}=t;if(!ul(e))return{srcset:e,src:e,sizes:i};const o=[];for(const d of n){const t={width:Math.round(s*d),quality:l,resize:r};a&&(t.height=Math.round(a*d));const n=xl(e,t);o.push("".concat(n," ").concat(d,"x"))}const c=xl(e,{width:s,height:a,quality:l,resize:r});return{srcset:o.join(", "),src:c,sizes:i}}function pl(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:20,s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:20;return ul(e)?xl(e,{width:t,quality:s,resize:"contain"}):e}const gl=e=>{let{src:t,alt:s,className:a="",quality:n=80,objectFit:l="cover",lazy:r=!0,placeholderQuality:i=20,placeholderWidth:o=20,onLoad:c,onError:d,width:m,height:u,resize:x,devicePixelRatios:h=[1,2,3],sizes:p,disableProgressiveLoading:g=!1,transitionDuration:f=300,disableTransition:v=!0,resizeDebounceMs:b=150,style:j}=e;const[y,N]=(0,Y.useState)(!1),[w,_]=(0,Y.useState)(!1),[k,C]=(0,Y.useState)(!r),[A,S]=(0,Y.useState)(null),E=(0,Y.useRef)(null),I=(0,Y.useRef)(null);(0,Y.useEffect)(()=>{if(!r||!E.current)return;const e=new IntersectionObserver(e=>{e.forEach(e=>{e.isIntersecting&&C(!0)})},{rootMargin:"50px",threshold:.01});return e.observe(E.current),()=>{e.disconnect()}},[r]);const T=(0,Y.useMemo)(()=>(0,Ce.debounce)((e,t)=>{e>0&&S({width:e,height:t})},b),[b]);(0,Y.useEffect)(()=>{if(!E.current)return;if(m&&u)return void S({width:m,height:u});const e=new ResizeObserver(e=>{for(const t of e){const{width:e,height:s}=t.contentRect;T(e,s)}});return e.observe(E.current),()=>{T.cancel(),e.disconnect()}},[m,u,T]);const P=ul(t),L=g?t:P?pl(t,o,i):t,O=(()=>{if(!P||!A)return{src:t,srcset:void 0,sizes:void 0};return hl(t,{baseWidth:m||A.width,baseHeight:u||A.height,devicePixelRatios:h,quality:n,resize:x||("contain"===l?"contain":"fill"===l?"fill":"cover"),sizes:p})})();return(0,le.jsxs)("div",{ref:E,className:"relative overflow-hidden ".concat(a),style:j,children:[!g&&k&&(0,le.jsx)("img",{src:L,alt:"",className:"absolute inset-0 w-full h-full",style:(0,K.A)({objectFit:l,filter:"blur(10px)",transform:"scale(1.1)",opacity:y?0:1},v?{}:{transition:"opacity ".concat(f,"ms ease-in-out")}),"aria-hidden":"true"}),k&&(0,le.jsx)("img",{ref:I,src:O.src,srcSet:O.srcset,sizes:O.sizes,alt:s,className:"relative w-full h-full",style:(0,K.A)({objectFit:l,opacity:y?1:0},v?{}:{transition:"opacity ".concat(f,"ms ease-in-out")}),onLoad:()=>{N(!0),null==c||c()},onError:e=>{_(!0);const s=new Error("Failed to load image: ".concat(t));null==d||d(s)},loading:r?"lazy":"eager"}),w&&(0,le.jsx)("div",{className:"absolute inset-0 flex items-center justify-center bg-slate-100",children:(0,le.jsxs)("div",{className:"text-center text-slate-500 text-sm",children:[(0,le.jsx)("svg",{className:"w-8 h-8 mx-auto mb-2 text-slate-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,le.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z"})}),(0,le.jsx)("span",{children:"Image not available"})]})})]})};function fl(e){var t,s,a;let{catalogItem:n,onCardClick:l,stripHtml:r,isHomepage:i=!1}=e;const o=n.item,c=null===(t=o.screenshot_urls)||void 0===t?void 0:t[0],d=n.item_creator,m=null===(s=n.categories)||void 0===s?void 0:s[0],[u,x]=(0,Y.useState)(!1);return(0,le.jsxs)(Qn,{className:Pe("border-0 cursor-pointer shadow-none group rounded-[16px] overflow-hidden",i?"bg-white":"bg-[#f4f3f2]"),onClick:()=>l(n),children:[(0,le.jsxs)("div",{className:"relative aspect-video overflow-hidden",children:[c&&!u?(0,le.jsx)(gl,{src:c,alt:o.name,className:"w-full h-full rounded-[8px] border border-gray-200",objectFit:"cover",quality:85,lazy:!0,onError:()=>x(!0)}):(0,le.jsx)("div",{className:"absolute inset-0 flex items-center justify-center bg-slate-50",children:(0,le.jsx)(ln.A,{className:"w-12 h-12 text-slate-400"})}),(0,le.jsxs)("div",{className:"absolute inset-0 bg-black/60 opacity-0 group-hover:opacity-100 transition-opacity duration-200 flex items-center justify-center gap-3 rounded-[16px]",children:[(0,le.jsx)(Hn,{onClick:e=>{e.stopPropagation(),window.open("/remix-app/".concat(o.app_id),"_blank")},className:"bg-orange-500 font-base44 hover:bg-orange-600 text-white font-medium px-6 py-2 rounded-[16px] transition-colors",children:"Clone App"}),(0,le.jsx)(Hn,{onClick:e=>{e.stopPropagation(),null==l||l(n)},variant:"outline",className:"bg-white font-base44 hover:bg-gray-50 text-black border-gray-200 font-medium px-6 py-2 rounded-[16px] transition-colors",children:"View Details"})]}),(0,le.jsx)("div",{className:"absolute top-3 right-3",children:m&&(0,le.jsx)(Nn,{className:"bg-orange-500/90 backdrop-blur-sm border-orange-600 text-white font-medium",children:m})})]}),(0,le.jsxs)(sl,{className:"py-2 px-0 space-y-2",children:[(0,le.jsx)("div",{children:(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[(0,le.jsx)("h3",{className:"font-medium font-base44 text-[16px] text-black line-clamp-1 hover:text-black transition-colors",children:o.name}),o.is_private&&(0,le.jsxs)("div",{className:"group/tooltip relative inline-flex bg-white border border-gray-200 p-1 rounded-[6px] w-[24px] h-[24px] items-center justify-center",children:[(0,le.jsx)(dl.A,{}),(0,le.jsx)("div",{className:"pointer-events-none absolute -top-8 left-1/2 -translate-x-1/2 px-2 py-1 bg-slate-800 text-white text-xs rounded opacity-0 group-hover/tooltip:opacity-100 transition-opacity whitespace-nowrap",children:"This app is private and only visible to you"})]})]})}),(0,le.jsx)("div",{className:"flex items-center justify-between mt-1",children:(0,le.jsxs)("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[(0,le.jsxs)(il,{className:"h-6 w-6 flex-shrink-0 border border-gray-200",children:[(0,le.jsx)(ol,{src:null==d?void 0:d.profile_image_url,alt:(null==d?void 0:d.full_name)||"User"}),(0,le.jsx)(cl,{className:"text-xs bg-slate-100 text-slate-600",children:(null==d||null===(a=d.full_name)||void 0===a?void 0:a[0])||"U"})]}),(0,le.jsxs)("div",{className:"min-w-0 flex-1 flex items-center gap-2",children:[(0,le.jsx)("p",{className:"text-sm text-slate-600 truncate",children:(null==d?void 0:d.full_name)||"Unknown User"}),(0,le.jsx)("div",{className:"w-1 h-1 rounded-full bg-slate-300"}),(0,le.jsxs)("div",{className:"group/tooltip relative",children:[(0,le.jsxs)("p",{className:"text-sm text-slate-600 flex items-center gap-1",children:[(0,le.jsx)("svg",{width:"24",height:"24",viewBox:"0 0 18 18",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:(0,le.jsx)("path",{"fill-rule":"evenodd","clip-rule":"evenodd",d:"M5 6V5C5 4.44772 5.44772 4 6 4H14C14.5523 4 15 4.44772 15 5V12C15 12.5523 14.5523 13 14 13H13V14C13 14.5523 12.5523 15 12 15H4C3.44772 15 3 14.5523 3 14V7C3 6.44772 3.44772 6 4 6H5ZM12 10H4V14H12V10ZM12 9V7H4V9H12ZM6 6H12C12.5523 6 13 6.44772 13 7V12H14V5H6V6Z",fill:"#9CA3AF"})}),n.usage]}),(0,le.jsx)("div",{className:"pointer-events-none absolute -top-6 left-1/2 -translate-x-1/2 px-2 py-1 bg-slate-800 text-white text-xs rounded opacity-0 group-hover/tooltip:opacity-100 transition-opacity whitespace-nowrap",children:"App Clones"})]})]})]})})]})]})}function vl(){return(0,le.jsxs)("div",{className:"group relative bg-white rounded-2xl border border-slate-100 overflow-hidden",children:[(0,le.jsx)("div",{className:"aspect-[16/9] bg-slate-100 animate-pulse"}),(0,le.jsxs)("div",{className:"p-5 space-y-4",children:[(0,le.jsx)("div",{className:"h-6 bg-slate-100 rounded-md animate-pulse w-3/4"}),(0,le.jsx)("div",{className:"flex items-center justify-between pt-2",children:(0,le.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,le.jsx)("div",{className:"w-8 h-8 bg-slate-100 rounded-full animate-pulse"}),(0,le.jsx)("div",{className:"h-4 w-24 bg-slate-100 rounded-md animate-pulse"})]})})]})]})}function bl(){return(0,le.jsxs)("div",{className:"space-y-8",children:[(0,le.jsx)("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 xl:grid-cols-4 gap-6",children:Array.from({length:8}).map((e,t)=>(0,le.jsx)(vl,{},t))}),(0,le.jsx)("div",{className:"flex items-center justify-center mt-8",children:(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[(0,le.jsx)("div",{className:"w-8 h-8 bg-slate-100 rounded-md animate-pulse"}),(0,le.jsx)("div",{className:"w-8 h-8 bg-slate-100 rounded-md animate-pulse"}),(0,le.jsx)("div",{className:"w-8 h-8 bg-slate-100 rounded-md animate-pulse"})]})})]})}var jl=s(12550);function yl(){return(0,le.jsxs)("div",{className:"text-center py-24",children:[(0,le.jsx)("div",{className:"inline-flex items-center justify-center w-16 h-16 rounded-2xl bg-slate-100 mb-4",children:(0,le.jsx)(jl.A,{className:"w-8 h-8 text-slate-400"})}),(0,le.jsx)("p",{className:"text-lg text-slate-600",children:"No apps found"}),(0,le.jsx)("p",{className:"text-sm text-slate-500 mt-1",children:"Try adjusting your search or filters"})]})}function Nl(e){let{isLoading:t,isLoadingMore:s=!1,items:a,onCardClick:n,stripHtml:l,hasMore:r=!1,targetRef:i,showViewAllButton:o=!1}=e;return(0,le.jsx)("div",{className:"",children:t?(0,le.jsx)(bl,{}):0===a.length?(0,le.jsx)(yl,{}):(0,le.jsxs)("div",{className:"space-y-8",children:[(0,le.jsx)("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 2xl:grid-cols-4 gap-8",children:a.map(e=>(0,le.jsx)(fl,{catalogItem:e,onCardClick:n,stripHtml:l,isHomepage:o},e.item.id))}),(0,le.jsx)("div",{ref:o?void 0:i,className:"w-full py-4",children:o?(0,le.jsx)("div",{className:"flex justify-center py-8",children:(0,le.jsx)(Hn,{onClick:()=>window.location.href="/app-templates",className:"bg-slate-900 hover:bg-slate-800 text-white font-medium px-8 py-3 rounded-[12px] font-base44",children:"View All Community Templates"})}):(0,le.jsxs)(le.Fragment,{children:[s&&(0,le.jsxs)("div",{className:"flex justify-center items-center py-8",children:[(0,le.jsx)("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-slate-600"}),(0,le.jsx)("span",{className:"ml-2 text-slate-600",children:"Loading more items..."})]}),!r&&a.length>0&&(0,le.jsx)("div",{className:"text-center py-8 text-slate-500",children:"No more apps to load"})]})})]})})}function wl(e){if(!e)return"";const t=document.createElement("div");return t.innerHTML=e,t.textContent||t.innerText||""}const _l=function(){const{user:e}=oe(),[t,s]=(0,Y.useState)([]),[a,n]=(0,Y.useState)(!0),[l,r]=(0,Y.useState)(""),[i,o]=(0,Y.useState)("all"),[c,d]=(0,Y.useState)(zn),[m,u]=(0,Y.useState)(Un),[x,h]=(0,Y.useState)("en"),[p,g]=(0,Y.useState)(!1),[f,v]=(0,Y.useState)(!0),[b,j]=(0,Y.useState)(!1),[y,N]=(0,Y.useState)(0),[w]=(0,Y.useState)(20),[_,k]=(0,Y.useState)(0),[C,A]=(0,Y.useState)(null),[S,E]=(0,Y.useState)(!1);(0,Y.useEffect)(()=>{const e=new URLSearchParams(window.location.search).get("category");if(e){const t=Dn.find(t=>t.toLowerCase()===e.toLowerCase());t?o(t):"my-apps"===e.toLowerCase()&&o("my-apps")}},[]),(0,Y.useEffect)(()=>{s([]),k(0),v(!0),I(!0)},[l,i,c,m,x]);const I=(0,Y.useCallback)(async function(){let t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];try{t?n(!0):j(!0);const a=t?0:_;let r={skip:a,limit:w,sort_by:T(m),categories:"all"!==i&&"my-apps"!==i?[i]:void 0};"me"===c||"my-apps"===i?r.created_by=e.email:"not_me"===c&&(r.created_by={$ne:e.email}),l&&"en"===x?r.$and=[{$or:[{name:{$regex:l,$options:"i"}},{description:{$regex:l,$options:"i"}},{categories:{$regex:l,$options:"i"}},{tags:{$regex:l,$options:"i"}},{created_by:{$regex:l,$options:"i"}}]},{$or:[{language:"en"},{language:{$exists:!1}},{language:null}]}]:l?(r.$or=[{name:{$regex:l,$options:"i"}},{description:{$regex:l,$options:"i"}},{categories:{$regex:l,$options:"i"}},{tags:{$regex:l,$options:"i"}},{created_by:{$regex:l,$options:"i"}}],x&&"en"!==x&&(r.language=x)):x&&("en"===x?r.$or=[{language:"en"},{language:{$exists:!1}},{language:null}]:r.language=x),Object.keys(r).forEach(e=>{void 0===r[e]&&delete r[e]});const o=await $a.listCatalogItems(r),d=o.items||o,u=o.total||d.length;t?(s(d),N(u)):s(e=>[...e,...d]),k(a+d.length),v(0!==d.length)}catch(a){an({title:"Error",description:"Failed to load catalog items",variant:"destructive"})}finally{n(!1),j(!1)}},[_,w,i,l,c,m,x,e]),T=e=>{switch(e){case"newest":return"created_at_desc";case"oldest":return"created_at_asc";default:return"usage"}},P=t.length,L=y>0?"Showing ".concat(P," of ").concat(y," items"):"";return(0,le.jsxs)("div",{className:"px-12 max-w-[1600px] mx-auto",children:[(0,le.jsx)(pn,{}),(0,le.jsx)(Wn,{searchTerm:l,onSearchChange:e=>{r(e)},selectedCategory:i,onCategoryChange:e=>{o(e)},showAllCategories:p,setShowAllCategories:g,totalItems:y,displayedItems:P,showingText:L,isLoading:a,ownership:c,onOwnershipChange:e=>{d(e)},sortBy:m,onSortByChange:e=>{u(e)},selectedLanguage:x,onLanguageChange:e=>{h(e)}}),(0,le.jsx)(Nl,{isLoading:a,isLoadingMore:b,items:t,onCardClick:e=>{A(e),E(!0)},stripHtml:wl,hasMore:f,targetRef:null,showViewAllButton:!0}),(0,le.jsx)(hn,{isOpen:S,onClose:()=>{E(!1),A(null)},selectedItem:C,onItemUpdate:e=>{A(e)}})]})};const kl=function(){const[e,t]=(0,Y.useState)(!1),[s,a]=(0,Y.useState)("my-apps"),[n,l]=(0,Y.useState)(!1),[r,i]=(0,Y.useState)(!0),o=(0,Z.Zp)(),c=(0,Z.zy)(),{user:d}=oe(),{activeWorkspaceId:m,switchActiveWorkspace:u}=ge();return(0,Y.useEffect)(()=>{const e=localStorage.getItem("activeWorkspaceId");e&&e!==m&&u(e)},[]),(0,le.jsxs)("div",{className:"min-h-screen",children:[(0,le.jsxs)("main",{className:"relative z-10 sm:max-w-screen-2xl mx-auto sm:px-6 lg:px-8 pb-12",children:[(0,le.jsxs)("div",{className:"mt-[8px] md:mt-[110px] mb-14 md:mb-16 px-[16px] sm:px-6 relative min-h-[65vh] pt-[6vh] md:pt-[4vh]",children:[(0,le.jsxs)("div",{className:"max-w-md sm:max-w-4xl mx-auto text-center mb-[32px] md:mb-[32px]",children:[(0,le.jsx)("h1",{className:"text-[26px] sm:text-[48px] font-base44 font-medium text-slate-800 mb-2 ",children:"What would you build today?"}),(0,le.jsxs)("p",{className:"text-gray-600 font-base44 font-light text-[18px] sm:text-lg",children:["Describe your app idea below or get inspired by our ",(0,le.jsx)("span",{className:"underline cursor-pointer hover:text-gray-800 transition-colors",onClick:()=>{var e;return null===(e=document.querySelector("#app-catalog-section"))||void 0===e?void 0:e.scrollIntoView({behavior:"smooth"})},children:"templates"})]})]}),(0,le.jsx)("div",{className:"sm:max-w-4xl mx-auto",children:(0,le.jsx)(na,{onStart:async e=>{let{text:s,files:a,deep_coding_mode:n,integrations:l,secrets:r}=e;if(s.trim()){t(!0);try{const e=new URLSearchParams(c.search).get("app_platform_version"),t={deep_coding_mode:!!n,status:{state:"processing",details:"Starting conversation..."},integrations:l,secrets:r};e&&(t.platform_version=parseInt(e,10));const i=await ve.create(t);o("/apps/".concat(i.id,"/editor/preview"),{state:{initialMessage:{content:s,file_urls:a}}})}catch(i){alert("Failed to create app. Please try again.")}finally{t(!1)}}else alert("Please enter an app description")},loading:e})})]}),(0,le.jsxs)("div",{className:"relative transition-opacity bg-white rounded-[30px] p-8 duration-200 pb-12 shadow-[0_5px_10px_0_rgba(35,107,215,0.05)]",children:[(0,le.jsx)("div",{className:"hidden md:block max-h-[600px] absolute left-1/2 transform -translate-x-1/2 pointer-events-none",style:{width:"min(2215px, 100vw)",height:"800px",flexShrink:0,borderRadius:"2215px",background:"radial-gradient(50% 50% at 50% 50%, #F50 0%, #FFEAA6 100%)",filter:"blur(153.39999389648438px)",zIndex:-1,top:"-150px"}}),(0,le.jsx)("div",{className:" max-h-[600px] absolute left-1/2 transform -translate-x-1/2 pointer-events-none",style:{width:"min(2215px, 100vw)",height:"1348px",flexShrink:0,borderRadius:"2215px",background:"radial-gradient(50% 50% at 50% 50%, #F50 0%, #FFEAA6 100%)",filter:"blur(153.39999389648438px)",zIndex:-1}}),"my-apps"===s&&(0,le.jsx)(ja,{}),"trending"===s&&(0,le.jsx)(_a,{})]}),(0,le.jsx)(Ga,{isOpen:n,onClose:()=>l(!1)})]}),(0,le.jsxs)("section",{id:"app-catalog-section",className:"relative bg-white md:py-16",children:[(0,le.jsx)("div",{className:"hidden md:block max-h-[600px] absolute left-1/2 transform -translate-x-1/2 pointer-events-none",style:{width:"min(2215px, 100vw)",height:"800px",flexShrink:0,borderRadius:"2215px",background:"radial-gradient(50% 50% at 50% 50%, #F50 0%, #FFEAA6 100%)",filter:"blur(153.39999389648438px)",zIndex:-1,top:"-150px"}}),(0,le.jsx)("div",{className:" max-h-[600px] absolute left-1/2 transform -translate-x-1/2 pointer-events-none",style:{width:"min(2215px, 100vw)",height:"1348px",flexShrink:0,borderRadius:"2215px",background:"radial-gradient(50% 50% at 50% 50%, #F50 0%, #FFEAA6 100%)",filter:"blur(153.39999389648438px)",zIndex:-1}}),(0,le.jsx)("div",{className:"relative z-10 bg-white pt-8",children:(0,le.jsx)(_l,{})})]})]})};var Cl=s(2263),Al=s(82407),Sl=s(24990),El=s(46327),Il=s(39193),Tl=s(9072);const Pl=["className"],Ll=["className"],Ol=["className"],Rl=["className"],Ml=["className"],Dl=["className"],Fl=["className"],Bl=["className"],zl=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,Pl);return(0,le.jsx)("div",{className:"relative w-full overflow-auto",children:(0,le.jsx)("table",(0,K.A)({ref:t,className:Pe("w-full caption-bottom text-sm",s)},a))})});zl.displayName="Table";const Ul=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,Ll);return(0,le.jsx)("thead",(0,K.A)({ref:t,className:Pe("[&_tr]:border-b",s)},a))});Ul.displayName="TableHeader";const Wl=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,Ol);return(0,le.jsx)("tbody",(0,K.A)({ref:t,className:Pe("[&_tr:last-child]:border-0",s)},a))});Wl.displayName="TableBody";const ql=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,Rl);return(0,le.jsx)("tfoot",(0,K.A)({ref:t,className:Pe("border-t bg-muted/50 font-medium [&>tr]:last:border-b-0",s)},a))});ql.displayName="TableFooter";const Vl=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,Ml);return(0,le.jsx)("tr",(0,K.A)({ref:t,className:Pe("border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",s)},a))});Vl.displayName="TableRow";const Hl=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,Dl);return(0,le.jsx)("th",(0,K.A)({ref:t,className:Pe("h-12 px-4 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0",s)},a))});Hl.displayName="TableHead";const Yl=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,Fl);return(0,le.jsx)("td",(0,K.A)({ref:t,className:Pe("p-4 align-middle [&:has([role=checkbox])]:pr-0",s)},a))});Yl.displayName="TableCell";const Gl=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,Bl);return(0,le.jsx)("caption",(0,K.A)({ref:t,className:Pe("mt-4 text-sm text-muted-foreground",s)},a))});Gl.displayName="TableCaption";const $l=function(){const{user:e}=oe(),[t,s]=(0,Y.useState)([]),[a,n]=(0,Y.useState)(!0),[l,r]=(0,Y.useState)(""),[i,o]=(0,Y.useState)("desc"),[c,d]=(0,Y.useState)(!1),[m,u]=(0,Y.useState)(!1),[x,h]=(0,Y.useState)(1),[p,g]=(0,Y.useState)(!0),[f,v]=(0,Y.useState)("grid"),b="grid"===f?24:100,{activeWorkspaceId:j}=((0,Z.Zp)(),ge());(0,Y.useEffect)(()=>{y()},[x,i,c,l,f,j]);const y=async()=>{try{const t="desc"===i?"-":"";let a={};c&&(a.created_by=e.email),l&&(a.$or=[{name:{$regex:l,$options:"i"}},{user_description:{$regex:l,$options:"i"}},{created_by:{$regex:l,$options:"i"}}]);const r=await ve.filter(a,"".concat(t,"updated_date"),b,(x-1)*b,["id","name","logo_url","user_description","created_by","created_date","updated_date","is_starred"].join(","));s(e=>1===x?r:[...e,...r]),g(r.length===b),n(!1)}catch(t){n(!1)}},N=t.filter(e=>!m||e.is_starred);return a&&1===x?(0,le.jsx)("div",{className:"flex justify-center items-center h-full",children:(0,le.jsx)("div",{className:"animate-spin h-8 w-8 border-4 border-primary border-t-transparent rounded-full"})}):(0,le.jsx)("div",{className:"p-6 min-h-full",children:(0,le.jsxs)("div",{className:"max-w-7xl mx-auto",children:[(0,le.jsxs)("div",{className:"flex flex-col md:flex-row justify-between items-start md:items-center gap-4 mb-8",children:[(0,le.jsx)("h2",{className:"text-3xl font-bold",children:"Apps"}),(0,le.jsxs)("div",{className:"flex flex-col sm:flex-row gap-4 w-full md:w-auto",children:[(0,le.jsxs)("div",{className:"relative",children:[(0,le.jsx)(vn.A,{className:"absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground h-4 w-4"}),(0,le.jsx)(fs,{type:"text",placeholder:"Search apps...",className:"pl-10 w-full sm:w-80",value:l,onChange:e=>{r(e.target.value),h(1),s([])}})]}),(0,le.jsxs)("div",{className:"flex gap-2",children:[(0,le.jsx)(Yt,{variant:c?"default":"outline",onClick:()=>{d(!c),h(1),s([])},children:c?"My Apps":"All Apps"}),(0,le.jsx)(Yt,{variant:m?"default":"outline",onClick:()=>u(!m),children:(0,le.jsx)(Cl.A,{className:"h-4 w-4 ".concat(m?"fill-current":"")})}),(0,le.jsx)(Yt,{variant:"outline",onClick:()=>{o("desc"===i?"asc":"desc"),h(1),s([])},children:"desc"===i?(0,le.jsx)(Al.A,{className:"h-4 w-4"}):(0,le.jsx)(Sl.A,{className:"h-4 w-4"})}),(0,le.jsx)(Yt,{variant:"outline",onClick:()=>{v(e=>"grid"===e?"table":"grid"),h(1),s([])},children:"grid"===f?(0,le.jsx)(El.A,{className:"h-4 w-4"}):(0,le.jsx)(jl.A,{className:"h-4 w-4"})})]})]})]}),"grid"===f?(0,le.jsx)("div",{className:"grid gap-4 sm:grid-cols-2 lg:grid-cols-3",children:N.map(e=>(0,le.jsx)(J.Link,{to:"/apps/".concat(e.id,"/editor/preview"),className:"block hover:shadow-lg transition-all duration-300",children:(0,le.jsxs)(is,{children:[(0,le.jsx)(os,{children:(0,le.jsxs)("div",{className:"flex items-center gap-4",children:[(0,le.jsx)(ma,{className:"h-12 w-12 rounded-xl",children:e.logo_url?(0,le.jsx)(ua,{src:e.logo_url,alt:"".concat(e.name," logo")}):(0,le.jsx)(xa,{className:"bg-primary/10",children:(0,le.jsx)(Il.A,{className:"h-6 w-6 text-primary"})})}),(0,le.jsx)("h3",{className:"font-semibold text-lg line-clamp-2",children:e.name})]})}),(0,le.jsxs)(ms,{children:[(0,le.jsxs)("p",{className:"text-muted-foreground mb-3 line-clamp-2",children:[e.user_description||"No description",e.user_description&&e.user_description.length>100&&(0,le.jsx)(Tl.A,{className:"inline ml-1 h-4 w-4"})]}),(0,le.jsxs)("div",{className:"text-xs text-muted-foreground flex flex-wrap gap-2",children:[(0,le.jsxs)("span",{children:["By ",e.created_by]}),(0,le.jsx)(ps,{orientation:"vertical",className:"h-4"}),(0,le.jsxs)("span",{children:["Created ",ra().utc(e.created_date).fromNow()]})]})]})]})},e.id))}):(0,le.jsx)(is,{children:(0,le.jsx)(ms,{className:"p-0",children:(0,le.jsxs)(zl,{children:[(0,le.jsx)(Ul,{children:(0,le.jsxs)(Vl,{children:[(0,le.jsx)(Hl,{className:"w-16"})," ",(0,le.jsx)(Hl,{children:"Name"}),(0,le.jsx)(Hl,{children:"Description"}),(0,le.jsx)(Hl,{children:"Created By"}),(0,le.jsx)(Hl,{children:"Last Updated"}),(0,le.jsx)(Hl,{className:"text-right",children:"Actions"})]})}),(0,le.jsx)(Wl,{children:N.map(e=>(0,le.jsxs)(Vl,{children:[(0,le.jsx)(Yl,{className:"p-2",children:(0,le.jsx)(ma,{className:"h-10 w-10 rounded-md",children:e.logo_url?(0,le.jsx)(ua,{src:e.logo_url,alt:"".concat(e.name," logo")}):(0,le.jsx)(xa,{className:"bg-primary/10 rounded-md",children:(0,le.jsx)(Il.A,{className:"h-5 w-5 text-primary"})})})}),(0,le.jsx)(Yl,{className:"font-medium py-2 pr-2",children:(0,le.jsx)(J.Link,{to:"/apps/".concat(e.id,"/editor/preview"),className:"hover:underline line-clamp-2",children:e.name})}),(0,le.jsx)(Yl,{className:"text-muted-foreground py-2 pr-2 line-clamp-2",children:e.user_description||"-"}),(0,le.jsx)(Yl,{className:"text-muted-foreground py-2 pr-2 whitespace-nowrap",children:e.created_by}),(0,le.jsx)(Yl,{className:"text-muted-foreground py-2 pr-2 whitespace-nowrap",children:ra().utc(e.updated_date).fromNow()}),(0,le.jsx)(Yl,{className:"py-2 pl-2 text-right",children:(0,le.jsx)(Yt,{variant:"ghost",size:"icon",onClick:t=>{t.stopPropagation(),alert("Actions for ".concat(e.name))},children:(0,le.jsx)(Tl.A,{className:"h-4 w-4"})})})]},e.id))})]})})}),0===N.length&&!a&&(0,le.jsx)("div",{className:"text-center py-12 text-muted-foreground",children:"No apps found matching your criteria"}),N.length>0&&(0,le.jsxs)("div",{className:"flex justify-center gap-2 mt-8",children:[(0,le.jsx)(Yt,{variant:"outline",onClick:()=>h(e=>Math.max(1,e-1)),disabled:1===x,children:"Previous"}),(0,le.jsx)(Yt,{variant:"outline",onClick:()=>h(e=>e+1),disabled:!p,children:"Next"})]}),a&&x>1&&(0,le.jsx)("div",{className:"flex justify-center items-center py-4",children:(0,le.jsx)("div",{className:"animate-spin h-8 w-8 border-4 border-primary border-t-transparent rounded-full"})})]})})};var Jl=s(32443),Zl=s(86805),Kl=s(74878),Ql=s(40978),Xl=s(29975),er=s(78419),tr=s(65330);const sr=(0,Y.createContext)();function ar(){const e=(0,Y.useContext)(sr);if(void 0===e)throw new Error("useActivity must be used within an ActivityProvider");return e}const nr=function(e){let{children:t}=e;const[s,a]=(0,Y.useState)({}),[n,l]=(0,Y.useState)(0);(0,Y.useEffect)(()=>{const e=e=>{const{type:t,requestId:s,logId:n,data:r}=e.data||{};if("api-request-start"===t)a(e=>(0,K.A)((0,K.A)({},e),{},{[s]:{id:s,type:"request",url:r.url,method:r.method,headers:r.headers,body:r.body,startTime:new Date,status:"pending"}})),l(e=>e+1);else if("api-request-end"===t)a(e=>{const t=e[s];return t?(0,K.A)((0,K.A)({},e),{},{[s]:(0,K.A)((0,K.A)({},t),{},{status:"completed",statusCode:r.statusCode,response:r.response,endTime:new Date,duration:t.startTime?new Date-t.startTime:0})}):e}),l(e=>Math.max(0,e-1));else if("console-log"===t){const e=new Date;a(t=>(0,K.A)((0,K.A)({},t),{},{[n]:{id:n,type:"log",message:r.message,severity:r.severity,component:r.component,timestamp:e}}))}};return window.addEventListener("message",e),()=>{window.removeEventListener("message",e)}},[]);const r=Object.values(s);return(0,le.jsx)(sr.Provider,{value:{allActivities:r,activeRequests:n,clearActivities:()=>a({})},children:t})},lr=ar;function rr(e){let{children:t}=e;const{app:s,isLoading:a}=Nt(),[n,l]=(0,Y.useState)(null),[r,i]=(0,Y.useState)([]),[o,c]=(0,Y.useState)(!0),[d,m]=(0,Y.useState)(!0),[u,x]=(0,Y.useState)(null),h=(0,Y.useMemo)(()=>(null==s?void 0:s.organization_id)||null,[null==s?void 0:s.organization_id]),p=(0,Y.useMemo)(()=>{if(!h||!r.length)return null;return r.find(e=>e.id===h)||null},[h,r]);(0,Y.useEffect)(()=>((0,ae.r8)(()=>h),()=>{const e=localStorage.getItem("activeWorkspaceId");e&&(0,ae.r8)(()=>e)}),[h]),(0,Y.useEffect)(()=>{l(p)},[p]);const g=(0,Y.useCallback)(async()=>{try{m(!0),x(null);const e=await xe.getWorkspaces();i(e.workspaces||e||[])}catch(e){x(e),i([])}finally{m(!1)}},[]);(0,Y.useEffect)(()=>{g()},[g]),(0,Y.useEffect)(()=>{c(a||d)},[a,d]);const f=(0,Y.useCallback)(e=>{},[]),v=(0,Y.useCallback)(()=>{},[]),b={activeWorkspace:n,activeWorkspaceId:h,workspaces:r,isLoading:o,isLoadingWorkspaces:d,error:u,switchActiveWorkspace:f,clearActiveWorkspace:v,refetchWorkspaces:g};return(0,le.jsx)(he.Provider,{value:b,children:t})}var ir=s(68432),or=s(81830),cr=s(35887),dr=s(52180),mr=s(89796),ur=s(72128),xr=s(10743),hr=s(67637),pr=s(70446);function gr(e,t){const s=[];let a=0;const n="<".concat(t," "),l="");for(;-1!==e.indexOf(n,a);){const t=e.indexOf(n,a);let r=e.indexOf(">",t)+1;0===r&&(r=e.length);const i=e.slice(t,r),o=e.indexOf(l,r);if(-1===o){s.push({openingTagIndex:t,closingTagIndex:null,openingTag:i,content:e.slice(r)});break}s.push({openingTagIndex:t,closingTagIndex:o,openingTag:i,content:e.slice(r,o)}),a=o+l.length}return s}function fr(e,t){const s=e.match(new RegExp("".concat(t,'="([^"]*)"'),"i"));return s?s[1]:void 0}class vr extends Q.H{getBaseURL(){return"/apps"}getCheckpointFileTree(e,t){return this.axios.get("/".concat(e,"/app-checkpoints/").concat(t,"/file-tree"))}getCheckpointCommitHash(e,t){return this.axios.get("/".concat(e,"/app-checkpoints/").concat(t,"/commit-hash"))}listCheckpoints(e){return this.axios.get("/".concat(e,"/app-checkpoints"))}loadCheckpoint(e,t){return this.axios.post("/".concat(e,"/app-checkpoints/").concat(t,"/load"))}}const br=new vr;var jr=s(35023),yr=s(37970);const Nr=["className"],wr=["className"],_r=["className"],kr=yr.bL,Cr=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,Nr);return(0,le.jsx)(yr.B8,(0,K.A)({ref:t,className:Pe("inline-flex h-10 items-center justify-center rounded-md bg-muted p-1 text-muted-foreground",s)},a))});Cr.displayName=yr.B8.displayName;const Ar=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,wr);return(0,le.jsx)(yr.l9,(0,K.A)({ref:t,className:Pe("inline-flex items-center justify-center whitespace-nowrap rounded-sm px-3 py-1.5 text-sm font-medium ring-offset-background transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow-sm",s)},a))});Ar.displayName=yr.l9.displayName;const Sr=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,_r);return(0,le.jsx)(yr.UC,(0,K.A)({ref:t,className:Pe("mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",s)},a))});Sr.displayName=yr.UC.displayName;const Er=e=>{let{originalCode:t="",modifiedCode:s="",language:a="javascript",title:n="Code Comparison",diffViewStyle:l="default"}=e;const r={readOnly:!0,renderSideBySide:!0,wordWrap:"on",scrollBeyondLastLine:!1,minimap:{enabled:!1},lineNumbers:"on",diffWordWrap:"on"},i="github"===l?"light":"vs";return(0,le.jsxs)(is,{className:"w-full shadow-md",children:[(0,le.jsx)(os,{className:"pb-2",children:(0,le.jsx)(cs,{className:"text-lg font-medium",children:n})}),(0,le.jsx)(ms,{children:(0,le.jsxs)(kr,{defaultValue:"diff",className:"w-full",children:[(0,le.jsxs)(Cr,{className:"mb-2",children:[(0,le.jsx)(Ar,{value:"diff",children:"Diff View"}),(0,le.jsx)(Ar,{value:"original",children:"Original"}),(0,le.jsx)(Ar,{value:"modified",children:"Modified"})]}),(0,le.jsx)(Sr,{value:"diff",className:"w-full",children:(0,le.jsx)("div",{className:"h-[500px] border rounded-md overflow-hidden",children:(0,le.jsx)(jr.zC,{height:"100%",language:a,original:t,modified:s,options:r,theme:i})})}),(0,le.jsx)(Sr,{value:"original",children:(0,le.jsx)("div",{className:"h-[500px] border rounded-md overflow-hidden",children:(0,le.jsx)(jr.zC,{height:"100%",language:a,original:t,modified:t,options:(0,K.A)((0,K.A)({},r),{},{renderSideBySide:!1}),theme:i})})}),(0,le.jsx)(Sr,{value:"modified",children:(0,le.jsx)("div",{className:"h-[500px] border rounded-md overflow-hidden",children:(0,le.jsx)(jr.zC,{height:"100%",language:a,original:s,modified:s,options:(0,K.A)((0,K.A)({},r),{},{renderSideBySide:!1}),theme:i})})})]})})]})};var Ir=s(61878),Tr=s(31641);function Pr(e){let{msgId:t,isOpen:s,onClose:a}=e;const{user:n}=oe(),{app:l}=Nt(),[r,i]=(0,Y.useState)(null),[o,c]=(0,Y.useState)(!0),[d,m]=(0,Y.useState)("diff"),[u,x]=(0,Y.useState)(!1),h=l.conversation.messages.findIndex(e=>e.id===t),p=l.conversation.messages[h],g=null!=p&&p.checkpoint_id?p:l.conversation.messages.slice(h+1).find(e=>"assistant"===e.role&&e.checkpoint_id),f=null!=p&&p.content?gr(p.content,"action"):[],v=async e=>{try{return await br.getCheckpointFileTree(l.id,e)}catch(t){return null}};(0,Y.useEffect)(()=>{(async()=>{if(c(!0),!g||!g.checkpoint_id)return void c(!1);const e=l.conversation.messages.findIndex(e=>e.id===g.id),t=l.conversation.messages.slice(0,e).reverse().find(e=>e.checkpoint_id),s=await v(g.checkpoint_id);let a=null;t&&t.checkpoint_id&&(a=await v(t.checkpoint_id));const n={};s&&a?(Object.entries(s.files).forEach(e=>{let[t,s]=e;const l=a.files[t];l&&JSON.stringify(l)===JSON.stringify(s)||(n[t]={original:l?"string"==typeof l?l:JSON.stringify(l,null,2):"",modified:"string"==typeof s?s:JSON.stringify(s,null,2),type:l?"modified":"added"})}),Object.keys(a.files).forEach(e=>{if(!s.files[e]){const t=a.files[e];n[e]={original:"string"==typeof t?t:JSON.stringify(t,null,2),modified:"",type:"deleted"}}})):s&&Object.entries(s.files).forEach(e=>{let[t,s]=e;n[t]={original:"",modified:"string"==typeof s?s:JSON.stringify(s,null,2),type:"added"}}),i(n),c(!1)})()},[t,l.id,h]);const b=p.metadata.created_date,j=p.metadata.created_by_email,y=ra().utc(b),N=y.clone().subtract(5,"minutes").format(),w=y.clone().add(5,"minutes").format(),_=encodeURIComponent("userId;string;;=;".concat(j)),k=encodeURIComponent("timestamp;datetime;;>;".concat(N,",timestamp;datetime;;<;").concat(w)),C="https://cloud.langfuse.com/project/cm23r6fre000rr9hhpjkrzoqx/traces?filter=".concat(_,",").concat(k),A=()=>{null!=p&&p.content&&(navigator.clipboard.writeText(p.content),x(!0),setTimeout(()=>x(!1),2e3))};return(0,le.jsx)(Pa,{open:s,onOpenChange:a,children:(0,le.jsxs)(Da,{className:"max-w-5xl max-h-[95vh] p-0 overflow-hidden flex flex-col border border-gray-200 rounded-md",children:[(0,le.jsx)(Fa,{className:"px-4 py-3 border-b border-gray-200 bg-gray-50 flex flex-row items-center justify-between",children:(0,le.jsx)(za,{className:"text-base font-medium",children:"Message Details"})}),(0,le.jsxs)(kr,{defaultValue:"diff",className:"flex-1 flex flex-col overflow-hidden",onValueChange:m,children:[(0,le.jsxs)(Cr,{className:"px-4 pt-2 bg-white border-b border-gray-200",children:[(0,le.jsxs)(Ar,{value:"diff",className:"flex items-center",children:[(0,le.jsx)(Kl.A,{className:"h-4 w-4 mr-2"}),"Code Changes"]}),"platform_admin"===n.platform_role&&(0,le.jsxs)(Ar,{value:"info",className:"flex items-center",children:[(0,le.jsx)(Ir.A,{className:"h-4 w-4 mr-2"}),"Message Info"]})]}),(0,le.jsx)(Sr,{value:"diff",className:"flex-1 overflow-auto p-0 m-0",children:o?(0,le.jsxs)("div",{className:"flex justify-center items-center h-64",children:[(0,le.jsx)(Ne.A,{className:"h-6 w-6 animate-spin text-gray-500"}),(0,le.jsx)("span",{className:"ml-2 text-gray-600",children:"Loading changes..."})]}):r&&0!==Object.keys(r).length?(0,le.jsx)("div",{className:"divide-y divide-gray-200",children:Object.entries(r).map((e,t)=>{let[s,a]=e;return(0,le.jsxs)("div",{className:"bg-white",children:[(0,le.jsxs)("div",{className:"flex items-center px-4 py-2 bg-gray-50 border-b border-gray-200",children:[(0,le.jsx)(hr.A,{className:"h-4 w-4 mr-2 text-gray-600"}),(0,le.jsx)("span",{className:"font-medium text-sm text-gray-700",children:s}),(0,le.jsx)("span",{className:"ml-2 px-2 py-0.5 text-xs rounded-full ".concat("added"===a.type?"bg-green-50 text-green-600 border border-green-100":"deleted"===a.type?"bg-red-50 text-red-600 border border-red-100":"bg-blue-50 text-blue-600 border border-blue-100"),children:a.type})]}),(0,le.jsx)("div",{className:"px-0",children:(0,le.jsx)(Er,{originalCode:a.original,modifiedCode:a.modified,language:s.endsWith(".css")?"css":"javascript",title:s,diffViewStyle:"github"})})]},t)})}):(0,le.jsxs)("div",{className:"flex flex-col items-center justify-center h-64 text-gray-500",children:[(0,le.jsx)(_e.A,{className:"h-10 w-10 mb-3 text-gray-400"}),(0,le.jsx)("p",{children:"No file changes detected for this message."})]})}),"platform_admin"===n.platform_role&&(0,le.jsx)(Sr,{value:"info",className:"flex-1 overflow-auto p-0 m-0",children:p?p?(0,le.jsxs)("div",{className:"p-4 space-y-4",children:[(0,le.jsxs)("div",{className:"rounded-lg border border-gray-200 bg-white",children:[(0,le.jsxs)("div",{className:"bg-gray-50 p-3 border-b border-gray-200 flex justify-between items-center",children:[(0,le.jsx)("h3",{className:"text-sm font-medium text-gray-700",children:"Message Attributes"}),(0,le.jsx)("button",{onClick:A,className:"flex items-center text-xs text-gray-600 hover:text-gray-900 bg-white hover:bg-gray-100 border border-gray-200 rounded px-2 py-1 transition-colors",children:u?(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(Ps.A,{className:"h-3.5 w-3.5 mr-1"}),"Copied!"]}):(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(or.A,{className:"h-3.5 w-3.5 mr-1"}),"Copy Content"]})})]}),(0,le.jsx)("div",{className:"p-4 space-y-2",children:Object.entries(p).filter(e=>{let[t]=e;return"content"!==t}).map(e=>{let[t,s]=e;return(0,le.jsxs)("div",{className:"flex",children:[(0,le.jsxs)("span",{className:"font-medium text-gray-700 min-w-[120px]",children:[t,":"]}),(0,le.jsx)("span",{className:"text-gray-600 break-all",children:"object"==typeof s?JSON.stringify(s):String(s)})]},t)})})]}),(0,le.jsxs)("div",{className:"rounded-lg border border-gray-200 bg-white",children:[(0,le.jsx)("div",{className:"bg-gray-50 p-3 border-b border-gray-200",children:(0,le.jsx)("h3",{className:"text-sm font-medium text-gray-700",children:"Langfuse Trace"})}),(0,le.jsx)("div",{className:"p-4",children:(0,le.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,le.jsx)("span",{className:"text-gray-600",children:"View trace in Langfuse:"}),(0,le.jsxs)("a",{href:C,target:"_blank",rel:"noopener noreferrer",className:"text-blue-600 hover:text-blue-800 hover:underline flex items-center",children:[C.substring(0,60),"...",(0,le.jsx)(Tr.A,{className:"h-4 w-4 ml-1"})]})]})})]}),(0,le.jsxs)("div",{className:"rounded-lg border border-gray-200 bg-white",children:[(0,le.jsx)("div",{className:"bg-gray-50 p-3 border-b border-gray-200",children:(0,le.jsxs)("h3",{className:"text-sm font-medium text-gray-700",children:["Actions (",f.length,")"]})}),(0,le.jsx)("div",{className:"divide-y divide-gray-200",children:0===f.length?(0,le.jsx)("div",{className:"p-4 text-gray-500 text-center",children:"No actions found in this message"}):f.map((e,t)=>{const s=e.openingTag.match(/action-type="([^"]*)"/)||e.openingTag.match(/type="([^"]*)"/),a=s?s[1]:"Unknown";return(0,le.jsxs)("div",{className:"p-4",children:[(0,le.jsxs)("div",{className:"mb-2",children:[(0,le.jsxs)("span",{className:"font-medium text-gray-700",children:["Action ",t+1,":"]}),(0,le.jsx)("span",{className:"ml-2 px-2 py-0.5 text-xs rounded-full bg-blue-50 text-blue-600 border border-blue-100",children:a})]}),(0,le.jsxs)("div",{className:"mt-2",children:[(0,le.jsx)("div",{className:"font-medium text-sm text-gray-700 mb-1",children:"Content:"}),(0,le.jsx)("pre",{className:"bg-gray-50 p-2 rounded text-xs overflow-x-auto",children:e.content})]})]},t)})})]})]}):null:(0,le.jsxs)("div",{className:"flex justify-center items-center h-64",children:[(0,le.jsx)(_e.A,{className:"h-10 w-10 mb-3 text-gray-400"}),(0,le.jsx)("span",{className:"ml-2 text-gray-600",children:"Message not found"})]})})]})]})})}var Lr=s(63653);const Or=["className","inset","children"],Rr=["className"],Mr=["className","sideOffset"],Dr=["className","inset"],Fr=["className","children","checked"],Br=["className","children"],zr=["className","inset"],Ur=["className"],Wr=["className"],qr=Lr.bL,Vr=Lr.l9,Hr=Lr.YJ,Yr=Lr.ZL,Gr=Lr.Pb,$r=Lr.z6,Jr=Y.forwardRef((e,t)=>{let{className:s,inset:a,children:n}=e,l=(0,Se.A)(e,Or);return(0,le.jsxs)(Lr.ZP,(0,K.A)((0,K.A)({ref:t,className:Pe("flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent",a&&"pl-8",s)},l),{},{children:[n,(0,le.jsx)(rn.A,{className:"ml-auto h-4 w-4"})]}))});Jr.displayName=Lr.ZP.displayName;const Zr=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,Rr);return(0,le.jsx)(Lr.G5,(0,K.A)({ref:t,className:Pe("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",s)},a))});Zr.displayName=Lr.G5.displayName;const Kr=Y.forwardRef((e,t)=>{let{className:s,sideOffset:a=4}=e,n=(0,Se.A)(e,Mr);return(0,le.jsx)(Lr.ZL,{children:(0,le.jsx)(Lr.UC,(0,K.A)({ref:t,sideOffset:a,className:Pe("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",s)},n))})});Kr.displayName=Lr.UC.displayName;const Qr=Y.forwardRef((e,t)=>{let{className:s,inset:a}=e,n=(0,Se.A)(e,Dr);return(0,le.jsx)(Lr.q7,(0,K.A)({ref:t,className:Pe("relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",a&&"pl-8",s)},n))});Qr.displayName=Lr.q7.displayName;const Xr=Y.forwardRef((e,t)=>{let{className:s,children:a,checked:n}=e,l=(0,Se.A)(e,Fr);return(0,le.jsxs)(Lr.H_,(0,K.A)((0,K.A)({ref:t,className:Pe("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",s),checked:n},l),{},{children:[(0,le.jsx)("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:(0,le.jsx)(Lr.VF,{children:(0,le.jsx)(Ps.A,{className:"h-4 w-4"})})}),a]}))});Xr.displayName=Lr.H_.displayName;const ei=Y.forwardRef((e,t)=>{let{className:s,children:a}=e,n=(0,Se.A)(e,Br);return(0,le.jsxs)(Lr.hN,(0,K.A)((0,K.A)({ref:t,className:Pe("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",s)},n),{},{children:[(0,le.jsx)("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:(0,le.jsx)(Lr.VF,{children:(0,le.jsx)(_s.A,{className:"h-2 w-2 fill-current"})})}),a]}))});ei.displayName=Lr.hN.displayName;const ti=Y.forwardRef((e,t)=>{let{className:s,inset:a}=e,n=(0,Se.A)(e,zr);return(0,le.jsx)(Lr.JU,(0,K.A)({ref:t,className:Pe("px-2 py-1.5 text-sm font-semibold",a&&"pl-8",s)},n))});ti.displayName=Lr.JU.displayName;const si=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,Ur);return(0,le.jsx)(Lr.wv,(0,K.A)({ref:t,className:Pe("-mx-1 my-1 h-px bg-muted",s)},a))});si.displayName=Lr.wv.displayName;const ai=e=>{let{className:t}=e,s=(0,Se.A)(e,Wr);return(0,le.jsx)("span",(0,K.A)({className:Pe("ml-auto text-xs tracking-widest opacity-60",t)},s))};ai.displayName="DropdownMenuShortcut";let ni=0;const li=new Map,ri=e=>{if(li.has(e))return;const t=setTimeout(()=>{li.delete(e),di({type:"REMOVE_TOAST",toastId:e})},1e6);li.set(e,t)},ii=(e,t)=>{switch(t.type){case"ADD_TOAST":return(0,K.A)((0,K.A)({},e),{},{toasts:[t.toast,...e.toasts].slice(0,1)});case"UPDATE_TOAST":return(0,K.A)((0,K.A)({},e),{},{toasts:e.toasts.map(e=>e.id===t.toast.id?(0,K.A)((0,K.A)({},e),t.toast):e)});case"DISMISS_TOAST":{const{toastId:s}=t;return s?ri(s):e.toasts.forEach(e=>{ri(e.id)}),(0,K.A)((0,K.A)({},e),{},{toasts:e.toasts.map(e=>e.id===s||void 0===s?(0,K.A)((0,K.A)({},e),{},{open:!1}):e)})}case"REMOVE_TOAST":return void 0===t.toastId?(0,K.A)((0,K.A)({},e),{},{toasts:[]}):(0,K.A)((0,K.A)({},e),{},{toasts:e.toasts.filter(e=>e.id!==t.toastId)})}},oi=[];let ci={toasts:[]};function di(e){ci=ii(ci,e),oi.forEach(e=>{e(ci)})}function mi(e){let t=Object.assign({},((0,Ja.A)(e),e));const s=(ni=(ni+1)%Number.MAX_SAFE_INTEGER,ni.toString()),a=()=>di({type:"DISMISS_TOAST",toastId:s});return di({type:"ADD_TOAST",toast:(0,K.A)((0,K.A)({},t),{},{id:s,open:!0,onOpenChange:e=>{e||a()}})}),{id:s,dismiss:a,update:e=>di({type:"UPDATE_TOAST",toast:(0,K.A)((0,K.A)({},e),{},{id:s})})}}function ui(){const[e,t]=Y.useState(ci);return Y.useEffect(()=>(oi.push(t),()=>{const e=oi.indexOf(t);e>-1&&oi.splice(e,1)}),[e]),(0,K.A)((0,K.A)({},e),{},{toast:mi,dismiss:e=>di({type:"DISMISS_TOAST",toastId:e})})}var xi=s(22796);const hi=e=>{let{content:t}=e;const{updateSecrets:s,existingSecretNames:a,addChatMessage:n}=Nt(),[l,r]=(0,Y.useState)(!1),[i,o]=(0,Y.useState)({}),[c,d]=(0,Y.useState)(!1),{toast:m}=ui(),u=Array.isArray(t)?t:[],x=u.map(e=>e.secretName).filter(Boolean),h=x.filter(e=>a&&a.includes(e)),p=h.length===x.length&&x.length>0,g=h.length>0&&h.length{r(e),e||o({})},children:[(0,le.jsx)(La,{asChild:!0,children:(0,le.jsxs)(Yt,{variant:"outline",size:"sm",className:"flex items-center gap-2 ".concat(p?"text-teal-600 border-teal-200 hover:bg-teal-50 hover:text-teal-700":g?"text-amber-600 border-amber-200 hover:bg-amber-50 hover:text-amber-700":"text-blue-600 border-blue-200 hover:bg-blue-50 hover:text-blue-700"),children:[p?(0,le.jsx)(pr.A,{size:16}):(0,le.jsx)(xi.A,{size:16}),g&&(0,le.jsx)(_e.A,{size:16}),(()=>{const e=p?"Update":"Set";if(1===x.length){const e=a&&a.includes(x[0]);return"".concat(e?"Update":"Set"," ").concat(x[0]," secret")}return"".concat(e," secrets: ").concat(x.join(", "))})(),g&&" (".concat(h.length,"/").concat(x.length," set)")]})}),(0,le.jsxs)(Da,{className:"sm:max-w-md",children:[(0,le.jsxs)(Fa,{children:[(0,le.jsxs)(za,{className:"text-teal-700",children:[p?"Update":"Set"," ",x.length>1?"Secrets":"".concat(x[0]," Secret")]}),(0,le.jsx)(Ua,{children:"Enter the values for the required secrets."})]}),(0,le.jsxs)("form",{onSubmit:async e=>{e.preventDefault();if(Object.values(i).some(e=>!e.trim()))m({variant:"destructive",title:"Secret values required",description:"Please enter values for all secrets"});else{d(!0);try{await s(i);const e=Object.keys(i).filter(e=>!a.includes(e));if(e.length>0){const t=e.join(", ");n({role:"user",content:"I've added ".concat(t," secrets")})}r(!1),o({}),m({title:"Secrets updated successfully",description:"The secrets have been set."})}catch(t){m({variant:"destructive",title:"Failed to set secrets",description:t.message||"An error occurred while setting the secrets"})}finally{d(!1)}}},children:[(0,le.jsx)("div",{className:"grid gap-6 py-4",children:u.map((e,t)=>(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsx)(Ns,{htmlFor:"secret-".concat(t),className:"block font-medium text-slate-700",children:e.secretName}),(0,le.jsx)(fs,{id:"secret-".concat(t),type:"password",value:i[e.secretName]||"",onChange:t=>{return s=e.secretName,a=t.target.value,void o(e=>(0,K.A)((0,K.A)({},e),{},{[s]:a}));var s,a},className:"w-full",placeholder:e.description||"Enter ".concat(e.secretName," value"),autoComplete:"off"}),e.description&&(0,le.jsx)("p",{className:"text-xs text-slate-500 mt-1",children:e.description})]},t))}),(0,le.jsxs)(Ba,{className:"gap-2 sm:gap-0",children:[(0,le.jsx)(Yt,{type:"button",variant:"outline",onClick:()=>r(!1),disabled:c,className:"border-slate-300 text-slate-700",children:"Cancel"}),(0,le.jsx)(Yt,{type:"submit",disabled:c,className:"bg-teal-600 hover:bg-teal-700 text-white",children:c?"Saving...":"Save Secrets"})]})]})]})]})},pi=["node"],gi=["node"],fi=["node"];function vi(e){let{msgId:t,title:s,children:a}=e;const[n,l]=(0,Y.useState)(!1);return(0,le.jsxs)("div",{className:"action-component action-group bg-white rounded-lg p-4 my-4 cursor-pointer","data-title":s,children:[(0,le.jsxs)("div",{className:"flex items-center justify-between gap-2 mb-4 pb-2 border-b border-gray-100",children:[(0,le.jsx)("h3",{className:"font-medium text-gray-800",children:s}),(0,le.jsx)("div",{className:"flex items-center",children:(0,le.jsxs)(qr,{children:[(0,le.jsx)(Vr,{className:"flex items-center justify-center p-1.5 text-gray-500 hover:text-gray-700 hover:bg-gray-50 rounded-md transition-colors",children:(0,le.jsx)(xr.A,{size:16})}),(0,le.jsx)(Kr,{align:"end",children:(0,le.jsxs)(Qr,{onClick:e=>{e.stopPropagation(),l(!0)},className:"flex items-center gap-2 cursor-pointer",children:[(0,le.jsx)(hr.A,{size:14,className:"text-gray-400"}),(0,le.jsx)("span",{children:"View Changes"})]})})]})})]}),(0,le.jsx)("div",{className:"space-y-3",children:a}),n&&(0,le.jsx)(Pr,{msgId:t,isOpen:n,onClose:e=>l(!1)})]})}function bi(e){let{title:t,details:s,componentName:a}=e;const[n,l]=Y.useState(!1),r=null==t?void 0:t.replace(/"/g,'"').replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/'/g,"'").replace(/'/g,"'"),i=null==s?void 0:s.replace(/"/g,'"').replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/'/g,"'").replace(/'/g,"'"),o=null==a?void 0:a.replace(/"/g,'"').replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/'/g,"'").replace(/'/g,"'");return(0,le.jsxs)("div",{className:"my-4 rounded-lg border border-red-200 bg-red-50",children:[(0,le.jsxs)("div",{className:"flex items-center gap-3 p-4 cursor-pointer",onClick:()=>l(!n),children:[(0,le.jsx)("div",{className:"text-red-500",children:(0,le.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,le.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,le.jsx)("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),(0,le.jsx)("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]})}),(0,le.jsxs)("div",{className:"flex-1",children:[(0,le.jsx)("h3",{className:"font-medium text-red-700",children:r}),o&&(0,le.jsxs)("p",{className:"text-sm text-red-600",children:["in ",o]})]}),(0,le.jsx)("div",{className:"transition-transform ".concat(n?"rotate-180":""),children:(0,le.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,le.jsx)("polyline",{points:"6 9 12 15 18 9"})})})]}),n&&i&&(0,le.jsx)("div",{className:"px-4 pb-4 pt-0",children:(0,le.jsx)("div",{className:"p-3 bg-white rounded border border-red-100 font-mono text-sm text-red-800 whitespace-pre-wrap",children:i})})]})}const ji=e=>{const t=e.split("/"),s=t[0];let a=t[t.length-1];return a.includes(".")&&(a=a.split(".").slice(0,-1).join(" ")),{name:a,artifactType:s}};function yi(e){let{node:t}=e;const{app:s}=Nt(),a=(0,Z.Zp)(),n=t.properties["action-type"]||t.properties.type;if("requestsecrets"===(null==n?void 0:n.toLowerCase())){let e;try{e=JSON.parse(atob(t.properties.dataContent))}catch(m){e=[]}return(0,le.jsx)(hi,{content:e})}let l=(null==n?void 0:n.replace(/(_)/g," ").replace(/\b\w/g,e=>e.toUpperCase()))||"";"file"===n&&t.properties.filepath&&(l=(e=>{const{name:t,artifactType:s}=ji(e);return"components"===s?"".concat(t," component"):"pages"===s?"".concat(t," page"):"entities"===s?"".concat(t," entity"):t.toLowerCase().includes("layout")?"Layout":"".concat(s," - ").concat(t)})(t.properties.filepath)),"insertentityrecords"===(null==n?void 0:n.toLowerCase())&&t.properties.dataInsertRecordsLength&&(l="Insert ".concat(t.properties.dataInsertRecordsLength," ").concat(t.properties.dataEntityName," Records"));const r=!0===t.properties.dataIsComplete||"true"===t.properties.dataIsComplete,i=t.properties.dataContentLength;let o=r?100:0;if(!r&&"file"===n&&t.properties.filepath){var c,d;const e=t.properties.filepath,{name:a,artifactType:n}=ji(e),l=(null===(c=s[n])||void 0===c||null===(d=c[a])||void 0===d?void 0:d.length)||15e3;o=Math.round(i/l*100),o=o>100?100:o}return(0,le.jsxs)("div",{className:"action-component action-step flex flex-col px-3 py-2 rounded-md hover:bg-gray-100 transition-colors","data-type":t.properties.dataActionType,"data-title":t.properties.dataTitle,onClick:()=>{if("file"===n&&t.properties.filepath){const e=t.properties.filepath;if(e.startsWith("agents/")){let t=e.split("/").pop();t.endsWith(".json")&&(t=t.slice(0,-5)),a("/apps/".concat(s.id,"/editor/workspace/agents?agent=").concat(t))}else a("/apps/".concat(s.id,"/editor/workspace/code?filePath=").concat(t.properties.filepath))}},children:[(0,le.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[!0===r||"true"===r?(0,le.jsx)(pr.A,{className:"w-4 h-4 text-green-500"}):(0,le.jsx)("div",{className:"relative w-4 h-4",children:(0,le.jsxs)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",children:[(0,le.jsx)("circle",{cx:"12",cy:"12",r:"10",fill:"none",stroke:"#e5e7eb",strokeWidth:"2"}),(0,le.jsx)("circle",{cx:"12",cy:"12",r:"10",fill:"none",stroke:"#3b82f6",strokeWidth:"2",strokeDasharray:"".concat(2*Math.PI*10),strokeDashoffset:"".concat(2*Math.PI*10*(1-o/100)),transform:"rotate(-90 12 12)",style:{transition:"stroke-dashoffset 0.3s ease"}})]})}),(0,le.jsx)("span",{className:"text-sm text-gray-700",children:t.properties.title||"Editing "+l})]}),"file"===n&&t.properties.filepath&&t.properties.filepath.startsWith("functions/")&&(0,le.jsx)("div",{className:"text-gray-400",children:(0,le.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,le.jsx)("path",{d:"m9 18 6-6-6-6"})})})]}),(0,le.jsx)("span",{className:"text-xs text-gray-400 ml-6",children:l})]})}function Ni(e){let{content:t,msgId:s,role:a}=e;const{user:n}=oe(),{app:l}=Nt(),r=function(e){let t=e;const s=gr(e,"action");for(let n=s.length-1;n>=0;n--){const e=s[n];let l=t.slice(0,e.openingTagIndex);if(e.closingTagIndex||e.openingTag.includes(">")){let s={"data-content-length":e.content.length,"data-is-complete":e.closingTagIndex?"true":"false"};const n=fr(e.openingTag,"action-type")||fr(e.openingTag,"type");if((null==n?void 0:n.toLowerCase())==="insertEntityRecords".toLowerCase()){if(s["data-entity-name"]=fr(e.openingTag,"entity-name"),s.title="Insert ".concat(s["data-entity-name"]," Records"),e.closingTagIndex)try{const t=JSON.parse(e.content);s["data-insert-records-length"]=t.length}catch(a){}}else if((null==n?void 0:n.toLowerCase())==="requestsecrets".toLowerCase())try{s["data-content"]=btoa(e.content)}catch(a){}e.openingTag.slice(0,-1).includes(">");const r="".concat(e.openingTag.slice(0,-1)," ").concat(Object.entries(s).map(e=>{let[t,s]=e;return"".concat(t,'="').concat(s,'"')}).join(" "),">");t=l+r+(e.closingTagIndex?t.slice(e.closingTagIndex+9):"")}else t=l}return t=t.replace(//g,""),t=t.replace(//g,""),t}(t),i={div:e=>{var t;let{node:a}=e,n=(0,Se.A)(e,pi),l=(null===(t=a.properties)||void 0===t?void 0:t.className)||"";if(Array.isArray(l)&&(l=l.join(" ")),"string"==typeof l&&l.includes("action-component")){if(l.includes("action-group"))return(0,le.jsx)(vi,(0,K.A)({msgId:s,title:a.properties.dataTitle},n));if(l.includes("action-single"))return(0,le.jsx)(yi,(0,K.A)({node:a},n))}return l.includes("error-component")?(0,le.jsx)(bi,(0,K.A)({},n)):(0,le.jsx)("div",(0,K.A)({},n))},action:e=>{let{node:t}=e,s=(0,Se.A)(e,gi);return(0,le.jsx)(yi,(0,K.A)({node:t},s))},diff:e=>{let{node:t}=e,s=(0,Se.A)(e,fi);return(0,le.jsx)("code",(0,K.A)({},s))}};return(0,le.jsx)("div",{className:"prose dark:prose-invert max-w-none base44-markdown relative",children:(0,le.jsx)(mr.oz,{rehypePlugins:"user"!==a||t.includes("a(!s),children:s?"hide errors":"see errors"})})]}),s&&(0,le.jsx)("div",{className:"mt-4",children:(0,le.jsx)(wi,{content:t.content})})]})};var ki=s(50270),Ci=s(78968),Ai=s(97820),Si=s(26209);const Ei={div:(0,le.jsx)(ki.A,{className:"h-3 w-3"}),button:(0,le.jsx)(Ci.A,{className:"h-3 w-3"}),p:(0,le.jsx)(Ai.A,{className:"h-3 w-3"}),h1:(0,le.jsx)(Si.A,{className:"h-3 w-3"}),h2:(0,le.jsx)(Si.A,{className:"h-3 w-3"}),h3:(0,le.jsx)(Si.A,{className:"h-3 w-3"}),h4:(0,le.jsx)(Si.A,{className:"h-3 w-3"}),h5:(0,le.jsx)(Si.A,{className:"h-3 w-3"})};var Ii=s(21570);const Ti=function(e){let{message:t}=e;const{app:s}=Nt(),{user:a}=oe(),[n,l]=(0,Y.useState)(!1);return(0,le.jsxs)("div",{className:"text-sm p-4 bg-white mx-auto mb-6 rounded-lg mb-6 relative",children:[(0,le.jsxs)("div",{className:"text-gray-700",children:["Files have been manually edited."," ",(0,le.jsx)("div",{className:"mt-2",children:(0,le.jsx)("a",{className:"text-teal-900/70 hover:underline cursor-pointer",onClick:()=>l(!n),children:n?"hide details":"see details"})})]}),n&&(0,le.jsx)("div",{className:"mt-4",children:(0,le.jsx)(wi,{content:t.content})}),(0,le.jsx)("div",{className:"cursor-pointer absolute bottom-[-10px] right-0 bg-white border border-gray-100 rounded-md p-1 text-xs text-gray-400",children:(0,le.jsxs)("a",{onClick:async()=>{var e;window.confirm("Are you sure you want to revert these manual edits? This will undo all changes made in this edit.")&&(tt("User clicked - revert this",{app_id:null==s?void 0:s.id,message_id:t.id}),ht({user_id:null==a?void 0:a.id,app_id:null==s?void 0:s.id,conversation_id:null==s||null===(e=s.conversation)||void 0===e?void 0:e.id},{cta:"revert this",origin:"manual_editing_message",message_id:t.id,target_route:null}),await ve.undoMessage(s.id,t.id))},className:"flex items-center gap-1",children:[(0,le.jsx)(Ii.A,{className:"h-3 w-3"}),"Revert this"]})})]})},Pi=e=>{let{reasoning:t}=e;const[s,a]=(0,Y.useState)(!1);if(!t)return null;const n=null!==t.end_date&&void 0!==t.end_date,l=(()=>{if(!n)return null;const e=ra()(t.start_date),s=ra()(t.end_date),a=ra().duration(s.diff(e));if(a.asSeconds()<1)return"less than a second";if(a.asSeconds()<60){const e=Math.round(a.asSeconds());return"".concat(e,"s")}if(a.asMinutes()<60){const e=Math.round(a.asMinutes());return"".concat(e,"m")}{const e=Math.round(a.asHours());return"".concat(e,"h")}})();return(0,le.jsxs)("div",{className:"mb-3",children:[(0,le.jsx)("div",{className:"inline-flex items-start gap-2",children:(0,le.jsx)("button",{onClick:()=>a(!s),className:"flex items-center gap-1.5 px-2.5 py-1 rounded-md transition-all ".concat(n?"bg-slate-50 hover:bg-slate-100 text-slate-600":"bg-gradient-to-r from-slate-50 to-slate-100 text-slate-600"),disabled:!n||!t.content,children:n?(0,le.jsxs)(le.Fragment,{children:[t.content&&(s?(0,le.jsx)(Is.A,{className:"h-3 w-3"}):(0,le.jsx)(rn.A,{className:"h-3 w-3"})),(0,le.jsxs)("span",{className:"text-xs font-medium",children:["Thought ",l&&(0,le.jsxs)("span",{className:"text-xs text-slate-500",children:["for ",l]})]})]}):(0,le.jsx)(le.Fragment,{children:(0,le.jsx)("span",{className:"text-xs font-medium animate-pulse",children:"Planning next steps..."})})})}),n&&t.content&&s&&(0,le.jsx)("div",{className:"mt-2 ml-0 animate-in slide-in-from-top-1 duration-200",children:(0,le.jsxs)("div",{className:"relative pl-4 py-2 pr-3 rounded-md bg-gradient-to-r from-slate-50 to-transparent",children:[(0,le.jsx)("div",{className:"absolute left-0 top-0 bottom-0 w-0.5 bg-gradient-to-b from-orange-300 to-teal-300 rounded-full"}),(0,le.jsx)("p",{className:"text-xs text-slate-600 leading-relaxed whitespace-pre-wrap",children:t.content})]})})]})};var Li=s(77737),Oi=s(25692),Ri=s(32033),Mi=s(82981);const Di=["className","sideOffset"],Fi=Ct.Kq,Bi=Ct.bL,zi=Ct.l9,Ui=Y.forwardRef((e,t)=>{let{className:s,sideOffset:a=4}=e,n=(0,Se.A)(e,Di);return(0,le.jsx)(Ct.UC,(0,K.A)({ref:t,sideOffset:a,className:Pe("z-50 overflow-hidden rounded-md border bg-popover px-3 py-1.5 text-sm text-popover-foreground shadow-md animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-[--radix-tooltip-content-transform-origin]",s)},n))});Ui.displayName=Ct.UC.displayName;const Wi="running",qi="success",Vi="error",Hi="failed",Yi="pending",Gi="waiting_for_user_input",$i=()=>(0,le.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:(0,le.jsx)("path",{d:"M13.3334 4L6.00008 11.3333L2.66675 8",stroke:"#25A55A",strokeWidth:"1.33",strokeLinecap:"round",strokeLinejoin:"round"})}),Ji=()=>(0,le.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:(0,le.jsx)("path",{d:"M7.99992 5.33301V7.99967M7.99992 10.6663H8.00659M14.6666 7.99967C14.6666 11.6816 11.6818 14.6663 7.99992 14.6663C4.31802 14.6663 1.33325 11.6816 1.33325 7.99967C1.33325 4.31778 4.31802 1.33301 7.99992 1.33301C11.6818 1.33301 14.6666 4.31778 14.6666 7.99967Z",stroke:"#DC2626",strokeWidth:"1.33",strokeLinecap:"round",strokeLinejoin:"round"})}),Zi=()=>(0,le.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:(0,le.jsx)("circle",{cx:"8",cy:"8",r:"3.5",fill:"#FF8904",stroke:"#FFD6A8"})});function Ki(e){let{icon:t,status:s,isLastRunningTool:a,result:n}=e;const l=s===Vi||s===Hi,r=s===qi,i=s===Yi,o=s===Gi,c=s===Wi&&a;return(0,le.jsx)("div",{className:"flex items-center justify-center p-1.5",children:c?(0,le.jsx)(Ne.A,{className:"h-4 w-4 animate-spin text-slate-500"}):r?(0,le.jsx)($i,{}):l?n?(0,le.jsxs)(Bi,{children:[(0,le.jsx)(zi,{asChild:!0,children:(0,le.jsx)("div",{className:"",children:(0,le.jsx)(Ji,{})})}),(0,le.jsx)(Ui,{side:"left",className:"max-w-xs break-words",children:n})]}):(0,le.jsx)(Ji,{}):o||i?(0,le.jsx)(Zi,{}):(0,le.jsx)(le.Fragment,{children:(0,le.jsx)(Ne.A,{className:"h-4 w-4 animate-spin text-slate-500"})})})}function Qi(e){let{icon:t,status:s,isLastAssistantMessage:a,isLastRunningTool:n,children:l,secondaryContent:r=null,requiresUserInput:i=!1,onClick:o,messageId:c,showViewChanges:d=!1,debugInfo:m=null,result:u=null}=e;const{user:x}=oe(),[h,p]=(0,Y.useState)(!1),[g,f]=(0,Y.useState)(!1),[v,b]=(0,Y.useState)(!1),[j,y]=(0,Y.useState)(!1),N="running"===s,w="error"===s||"failed"===s,_="success"===s,k=o&&"function"==typeof o&&_;return(0,le.jsxs)("div",{className:"relative",children:[(0,le.jsxs)("div",{className:Pe("flex items-center gap-2 text-sm transition-all duration-200",N&&!n?"text-slate-400":"text-slate-600",w&&"text-slate-700",k&&"cursor-pointer hover:bg-slate-50 rounded-md "),onClick:e=>{e.target.closest("[data-dropdown-menu]")||k&&o(e)},onMouseEnter:()=>b(!0),onMouseLeave:()=>b(!1),children:[t&&(0,le.jsx)(t,{className:"h-4 w-4 text-gray-400"}),(0,le.jsx)("div",{className:Pe("flex-1 min-w-0 text-black",w&&"relative"),children:l}),(0,le.jsx)("div",{className:"ml-auto","data-dropdown-menu":!0,children:(v||j)&&(d||m&&"platform_admin"===(null==x?void 0:x.platform_role))&&_?(0,le.jsxs)(qr,{onOpenChange:y,children:[(0,le.jsx)(Vr,{className:"flex items-center justify-center p-1.5 text-gray-500 hover:text-gray-700 hover:bg-gray-50 rounded-md transition-colors",children:(0,le.jsx)(xr.A,{size:16})}),(0,le.jsxs)(Kr,{align:"end",children:[d&&c&&(0,le.jsxs)(Qr,{onClick:e=>{e.stopPropagation(),p(!0)},className:"flex items-center gap-2 cursor-pointer",children:[(0,le.jsx)(hr.A,{size:14,className:"text-gray-400"}),(0,le.jsx)("span",{children:"View Changes"})]}),m&&"platform_admin"===(null==x?void 0:x.platform_role)&&(0,le.jsxs)(le.Fragment,{children:[d&&c&&(0,le.jsx)(si,{}),(0,le.jsxs)(Qr,{onClick:e=>{e.stopPropagation(),f(!0)},className:"flex items-center gap-2 cursor-pointer",children:[(0,le.jsx)(Mi.A,{size:14,className:"text-gray-400"}),(0,le.jsx)("span",{children:"Debug Info"})]})]})]})]}):(0,le.jsx)(Ki,{icon:t,status:s,isLastRunningTool:n,result:u})})]}),r,h&&c&&(0,le.jsx)(Pr,{msgId:c,isOpen:h,onClose:()=>p(!1)}),g&&m&&(0,le.jsx)(Pa,{open:g,onOpenChange:f,children:(0,le.jsxs)(Da,{className:"max-w-3xl max-h-[80vh] overflow-auto",children:[(0,le.jsx)(Fa,{children:(0,le.jsx)(za,{children:"Debug Info"})}),(0,le.jsxs)("div",{className:"space-y-4",children:[m.input&&(0,le.jsxs)("div",{children:[(0,le.jsx)("div",{className:"text-sm font-medium text-gray-700 mb-2",children:"Input:"}),(0,le.jsx)("pre",{className:"bg-slate-50 rounded-md p-3 text-xs text-slate-700 overflow-auto",children:JSON.stringify(m.input,null,2)})]}),m.output&&(0,le.jsxs)("div",{children:[(0,le.jsx)("div",{className:"text-sm font-medium text-gray-700 mb-2",children:"Output:"}),(0,le.jsx)("pre",{className:"bg-slate-50 rounded-md p-3 text-xs text-slate-700 overflow-auto",children:JSON.stringify(m.output,null,2)})]})]})]})})]})}function Xi(e){if(!e)return"file";let t=e.replace(/^(src\/|app\/|components\/|lib\/|utils\/)/,"");if(t=t.replace(/\.(jsx?|tsx?|css|scss|json|md|html|py|java|go|rb|php)$/i,""),e.match(/pages?\/.*\.jsx?$/i)){const e=t.split("/").pop(),s=e?e.replace(/([A-Z])/g," $1").replace(/[-_]/g," ").trim():"";return"".concat(s.charAt(0).toUpperCase()+s.slice(1)," Page")}if(e.match(/api\/.*\.jsx?$/i)){const e=t.split("/").slice(0,-1).pop()||t.split("/").pop(),s=e?e.replace(/([A-Z])/g," $1").replace(/[-_]/g," ").trim():"";return"".concat(s.charAt(0).toUpperCase()+s.slice(1)," API")}return t.split("/").map(e=>e.replace(/([A-Z])/g," $1").replace(/[-_]/g," ").trim()).join("/").trim()}function eo(e,t){if(!e||!t)return null;if(e.startsWith("agents/")){let s=e.split("/").pop();return s&&s.endsWith(".json")&&(s=s.slice(0,-5)),"/apps/".concat(t,"/editor/workspace/agents?agent=").concat(s)}return"/apps/".concat(t,"/editor/workspace/code?filePath=").concat(e)}const to=e=>{let{className:t}=e;return(0,le.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:t,children:(0,le.jsx)("path",{d:"M9.33341 1.33301V3.99967C9.33341 4.3533 9.47389 4.69244 9.72394 4.94248C9.97399 5.19253 10.3131 5.33301 10.6667 5.33301H13.3334M6.66675 7.99967C6.48994 7.99967 6.32037 8.06991 6.19534 8.19494C6.07032 8.31996 6.00008 8.48953 6.00008 8.66634V9.33301C6.00008 9.50982 5.92984 9.67939 5.80482 9.80441C5.67979 9.92944 5.51023 9.99967 5.33341 9.99967C5.51023 9.99967 5.67979 10.0699 5.80482 10.1949C5.92984 10.32 6.00008 10.4895 6.00008 10.6663V11.333C6.00008 11.5098 6.07032 11.6794 6.19534 11.8044C6.32037 11.9294 6.48994 11.9997 6.66675 11.9997M9.33341 11.9997C9.51023 11.9997 9.67979 11.9294 9.80482 11.8044C9.92984 11.6794 10.0001 11.5098 10.0001 11.333V10.6663C10.0001 10.4895 10.0703 10.32 10.1953 10.1949C10.3204 10.0699 10.4899 9.99967 10.6667 9.99967C10.4899 9.99967 10.3204 9.92944 10.1953 9.80441C10.0703 9.67939 10.0001 9.50982 10.0001 9.33301V8.66634C10.0001 8.48953 9.92984 8.31996 9.80482 8.19494C9.67979 8.06991 9.51023 7.99967 9.33341 7.99967M10.0001 1.33301H4.00008C3.64646 1.33301 3.30732 1.47348 3.05727 1.72353C2.80722 1.97358 2.66675 2.31272 2.66675 2.66634V13.333C2.66675 13.6866 2.80722 14.0258 3.05727 14.2758C3.30732 14.5259 3.64646 14.6663 4.00008 14.6663H12.0001C12.3537 14.6663 12.6928 14.5259 12.9429 14.2758C13.1929 14.0258 13.3334 13.6866 13.3334 13.333V4.66634L10.0001 1.33301Z",stroke:"currentColor",strokeWidth:"1.33",strokeLinecap:"round",strokeLinejoin:"round"})})};function so(e){let{toolCall:t,parsedArgs:s,messageId:a,isLastAssistantMessage:n,isLastRunningTool:l,debugInfo:r}=e;const i=(0,Z.Zp)(),{app:o}=Nt(),c=t.status,d=(null==s?void 0:s.file_path)||(null==s?void 0:s.target_file)||"file",m=Xi(d),u="running"===c;return(0,le.jsx)(Qi,{icon:to,status:c,isLastAssistantMessage:n,isLastRunningTool:l,onClick:()=>{const e=eo(d,null==o?void 0:o.id);e&&i(e)},messageId:a,showViewChanges:!0,debugInfo:r,children:(0,le.jsxs)("div",{className:"flex items-center gap-1",children:[u?"Editing":"Edited"," ",(0,le.jsx)("span",{className:"flex items-center justify-center gap-2.5 px-1 py-1 bg-gray-100 text-gray-700 rounded font-[400] text-xs ",children:"file"===m?"":m})]})})}const ao=e=>{let{className:t}=e;return(0,le.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:t,children:(0,le.jsx)("path",{d:"M9.33341 1.33301V3.99967C9.33341 4.3533 9.47389 4.69244 9.72394 4.94248C9.97399 5.19253 10.3131 5.33301 10.6667 5.33301H13.3334M6.66675 7.99967C6.48994 7.99967 6.32037 8.06991 6.19534 8.19494C6.07032 8.31996 6.00008 8.48953 6.00008 8.66634V9.33301C6.00008 9.50982 5.92984 9.67939 5.80482 9.80441C5.67979 9.92944 5.51023 9.99967 5.33341 9.99967C5.51023 9.99967 5.67979 10.0699 5.80482 10.1949C5.92984 10.32 6.00008 10.4895 6.00008 10.6663V11.333C6.00008 11.5098 6.07032 11.6794 6.19534 11.8044C6.32037 11.9294 6.48994 11.9997 6.66675 11.9997M9.33341 11.9997C9.51023 11.9997 9.67979 11.9294 9.80482 11.8044C9.92984 11.6794 10.0001 11.5098 10.0001 11.333V10.6663C10.0001 10.4895 10.0703 10.32 10.1953 10.1949C10.3204 10.0699 10.4899 9.99967 10.6667 9.99967C10.4899 9.99967 10.3204 9.92944 10.1953 9.80441C10.0703 9.67939 10.0001 9.50982 10.0001 9.33301V8.66634C10.0001 8.48953 9.92984 8.31996 9.80482 8.19494C9.67979 8.06991 9.51023 7.99967 9.33341 7.99967M10.0001 1.33301H4.00008C3.64646 1.33301 3.30732 1.47348 3.05727 1.72353C2.80722 1.97358 2.66675 2.31272 2.66675 2.66634V13.333C2.66675 13.6866 2.80722 14.0258 3.05727 14.2758C3.30732 14.5259 3.64646 14.6663 4.00008 14.6663H12.0001C12.3537 14.6663 12.6928 14.5259 12.9429 14.2758C13.1929 14.0258 13.3334 13.6866 13.3334 13.333V4.66634L10.0001 1.33301Z",stroke:"currentColor",strokeWidth:"1.33",strokeLinecap:"round",strokeLinejoin:"round"})})};function no(e){let{toolCall:t,parsedArgs:s,messageId:a,isLastAssistantMessage:n,isLastRunningTool:l,debugInfo:r}=e;const i=(0,Z.Zp)(),{app:o}=Nt(),c=t.status,d=(null==s?void 0:s.file_path)||(null==s?void 0:s.target_file)||"file",m=Xi(d),u="running"===c;return(0,le.jsx)(Qi,{icon:ao,status:c,isLastAssistantMessage:n,isLastRunningTool:l,onClick:()=>{const e=eo(d,null==o?void 0:o.id);e&&i(e)},messageId:a,showViewChanges:!0,debugInfo:r,children:(0,le.jsxs)("div",{className:"flex items-center gap-2.5",children:[u?"Reading":"Read"," ",(0,le.jsx)("span",{className:"flex items-center justify-center gap-2.5 px-1 py-1 bg-gray-100 text-gray-700 rounded font-[400] text-xs",children:m})]})})}const lo=e=>{let{className:t}=e;return(0,le.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",className:t,children:(0,le.jsx)("path",{d:"M14 3.33301C14 4.43758 11.3137 5.33301 8 5.33301C4.68629 5.33301 2 4.43758 2 3.33301M14 3.33301C14 2.22844 11.3137 1.33301 8 1.33301C4.68629 1.33301 2 2.22844 2 3.33301M14 3.33301V12.6663C14 13.1968 13.3679 13.7055 12.2426 14.0806C11.1174 14.4556 9.5913 14.6663 8 14.6663C6.4087 14.6663 4.88258 14.4556 3.75736 14.0806C2.63214 13.7055 2 13.1968 2 12.6663V3.33301M2 7.99967C2 8.53011 2.63214 9.03882 3.75736 9.41389C4.88258 9.78896 6.4087 9.99967 8 9.99967C9.5913 9.99967 11.1174 9.78896 12.2426 9.41389C13.3679 9.03882 14 8.53011 14 7.99967",stroke:"#9CA3AF",strokeWidth:"1.33",strokeLinecap:"round",strokeLinejoin:"round"})})};function ro(e){var t;let{toolCall:s,parsedArgs:a,isLastAssistantMessage:n,isLastRunningTool:l}=e;const{app:r}=Nt(),i=(0,Z.Zp)(),o=s.status,c=(null==a?void 0:a.entity_name)||"entities",d=null==a||null===(t=a.data)||void 0===t?void 0:t.length,m="running"===o;return(0,le.jsx)(Qi,{icon:lo,status:o,isLastAssistantMessage:n,isLastRunningTool:l,onClick:()=>{null!=r&&r.id&&c&&i("/apps/".concat(r.id,"/editor/workspace/entity-").concat(c))},children:(0,le.jsxs)("div",{className:"flex items-center gap-1",children:[m?"Creating":"Created","",d&&(0,le.jsxs)("div",{className:"flex items-center gap-1",children:[(0,le.jsxs)("span",{className:"font-medium",children:[d," ","records"," "]}),(0,le.jsx)("span",{className:"flex items-center gap-1 flex items-center justify-center px-1 py-1 bg-gray-100 text-gray-700 rounded font-[400] text-xs",children:c})]})]})})}const io=e=>{let{className:t}=e;return(0,le.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",className:t,children:(0,le.jsx)("path",{d:"M14 3.33301C14 4.43758 11.3137 5.33301 8 5.33301C4.68629 5.33301 2 4.43758 2 3.33301M14 3.33301C14 2.22844 11.3137 1.33301 8 1.33301C4.68629 1.33301 2 2.22844 2 3.33301M14 3.33301V12.6663C14 13.1968 13.3679 13.7055 12.2426 14.0806C11.1174 14.4556 9.5913 14.6663 8 14.6663C6.4087 14.6663 4.88258 14.4556 3.75736 14.0806C2.63214 13.7055 2 13.1968 2 12.6663V3.33301M2 7.99967C2 8.53011 2.63214 9.03882 3.75736 9.41389C4.88258 9.78896 6.4087 9.99967 8 9.99967C9.5913 9.99967 11.1174 9.78896 12.2426 9.41389C13.3679 9.03882 14 8.53011 14 7.99967",stroke:"#9CA3AF",strokeWidth:"1.33",strokeLinecap:"round",strokeLinejoin:"round"})})};function oo(e){let{toolCall:t,parsedArgs:s,isLastAssistantMessage:a,isLastRunningTool:n}=e;const{app:l}=Nt(),r=(0,Z.Zp)(),i=t.status,o=(null==s?void 0:s.entity_name)||"entities",c=(null==s?void 0:s.query)||{},d=null==s?void 0:s.limit,m=null==s?void 0:s.skip,u=null==s?void 0:s.sort,x="running"===i,h="success"===i,p=!c||0===Object.keys(c).length,g=(()=>{if(!t.results)return null;try{const e="string"==typeof t.results?JSON.parse(t.results):t.results;return Array.isArray(e)?e:null}catch(e){return null}})(),f=null==g?void 0:g.length;return(0,le.jsx)(Qi,{icon:io,status:i,isLastAssistantMessage:a,isLastRunningTool:n,onClick:()=>{null!=l&&l.id&&o&&r("/apps/".concat(l.id,"/editor/workspace/entity-").concat(o))},children:(0,le.jsxs)("div",{children:[(0,le.jsxs)("div",{className:"flex items-center gap-2.5",children:[x?"Reading":"Read"," ",(0,le.jsx)("span",{className:"flex items-center justify-center gap-2.5 px-1 py-1 bg-gray-100 text-gray-700 rounded font-[400] text-xs",children:o}),h&&void 0!==f&&(0,le.jsxs)("span",{className:"ml-1.5 text-slate-500",children:["\xb7 ",f," ",1===f?"record":"records"]})]}),(!p||d||m||u)&&(0,le.jsxs)("div",{className:"mt-1 text-xs text-slate-500 space-y-0.5",children:[!p&&(0,le.jsxs)("div",{children:["Filter: ",(0,le.jsx)("span",{className:"font-mono",children:JSON.stringify(c)})]}),(d||m)&&(0,le.jsxs)("div",{children:[d&&"Limit: ".concat(d),d&&m&&" \xb7 ",m&&"Skip: ".concat(m)]}),u&&(0,le.jsxs)("div",{children:["Sort: ",(0,le.jsx)("span",{className:"font-mono",children:JSON.stringify(u)})]})]})]})})}const co=e=>{let{className:t}=e;return(0,le.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",className:t,children:(0,le.jsx)("path",{d:"M14 3.33301C14 4.43758 11.3137 5.33301 8 5.33301C4.68629 5.33301 2 4.43758 2 3.33301M14 3.33301C14 2.22844 11.3137 1.33301 8 1.33301C4.68629 1.33301 2 2.22844 2 3.33301M14 3.33301V12.6663C14 13.1968 13.3679 13.7055 12.2426 14.0806C11.1174 14.4556 9.5913 14.6663 8 14.6663C6.4087 14.6663 4.88258 14.4556 3.75736 14.0806C2.63214 13.7055 2 13.1968 2 12.6663V3.33301M2 7.99967C2 8.53011 2.63214 9.03882 3.75736 9.41389C4.88258 9.78896 6.4087 9.99967 8 9.99967C9.5913 9.99967 11.1174 9.78896 12.2426 9.41389C13.3679 9.03882 14 8.53011 14 7.99967",stroke:"#9CA3AF",strokeWidth:"1.33",strokeLinecap:"round",strokeLinejoin:"round"})})};function mo(e){let{toolCall:t,parsedArgs:s,isLastAssistantMessage:a,isLastRunningTool:n}=e;const{submitToolCallInput:l,app:r}=Nt(),i=(0,Z.Zp)(),[o,c]=(0,Y.useState)(!1),d=t.status,m=(null==s?void 0:s.entity_name)||"entities",u=(null==s?void 0:s.query)||{},x="running"===d,h="waiting_for_user_input"===d,p="success"===d,g="stopped"===d,f=!u||0===Object.keys(u).length,v=async()=>{c(!0);try{await l(t.id,!0,{})}catch(e){}finally{c(!1)}},b=async()=>{c(!0);try{await l(t.id,!1,{})}catch(e){}finally{c(!1)}},j=()=>h?(0,le.jsx)("div",{className:"border border-slate-200 bg-slate-50 rounded-lg p-4 space-y-3 mt-2",children:(0,le.jsx)("div",{className:"flex items-start gap-2.5",children:(0,le.jsxs)("div",{className:"flex-1 space-y-3",children:[(0,le.jsxs)("div",{children:[(0,le.jsx)("div",{className:"text-sm font-medium text-slate-900 mb-4",children:"Approval Required"}),(0,le.jsx)("div",{className:"text-sm text-slate-600",children:f?(0,le.jsxs)(le.Fragment,{children:["Delete all"," ",(0,le.jsx)("span",{className:"font-mono text-xs bg-white px-1.5 py-0.5 rounded border border-slate-200",children:m})," records"]}):(0,le.jsxs)(le.Fragment,{children:["Delete"," ",(0,le.jsx)("span",{className:"font-mono text-xs bg-white px-1.5 py-0.5 rounded border border-slate-200",children:m})," records matching:"]})})]}),!f&&(0,le.jsx)("pre",{className:"text-xs bg-white rounded-md p-3 text-slate-700 overflow-x-auto border border-slate-200",children:JSON.stringify(u,null,2)}),a?(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[(0,le.jsx)(Yt,{size:"sm",onClick:v,disabled:o,className:"h-8 text-xs bg-slate-900 hover:bg-slate-800 disabled:opacity-50",children:o?(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(Ne.A,{className:"h-3 w-3 mr-1.5 animate-spin"}),"Approving..."]}):"Approve"}),(0,le.jsx)(Yt,{size:"sm",variant:"outline",onClick:b,disabled:o,className:"h-8 text-xs border-slate-300 hover:bg-slate-50 disabled:opacity-50",children:"Reject"})]}):(0,le.jsx)("div",{className:"text-xs text-slate-500 italic",children:"This approval request is from a previous message"})]})})}):null;return(0,le.jsx)(Qi,{icon:co,status:d,isLastAssistantMessage:a,isLastRunningTool:n,onClick:()=>{null!=r&&r.id&&m&&i("/apps/".concat(r.id,"/editor/workspace/entity-").concat(m))},secondaryContent:(0,le.jsx)(j,{}),result:t.results,children:(0,le.jsx)("div",{children:(0,le.jsxs)("div",{className:"flex items-center gap-1",children:[x?"Deleting":p?"Deleted":"Delete"," ",f&&(x||p)?"all records":"",(0,le.jsx)("span",{className:"flex items-center gap-1 flex items-center justify-center px-[6px] py-[2px] bg-gray-100 text-gray-500 rounded font-[400] font-mon text-xs",children:m}),g&&t.requires_user_input&&(0,le.jsx)("span",{className:"text-slate-400 text-xs italic",children:"rejected"})]})})})}var uo=s(16859);const xo=e=>{let{className:t}=e;return(0,le.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",className:t,children:(0,le.jsx)("path",{d:"M14 3.33301C14 4.43758 11.3137 5.33301 8 5.33301C4.68629 5.33301 2 4.43758 2 3.33301M14 3.33301C14 2.22844 11.3137 1.33301 8 1.33301C4.68629 1.33301 2 2.22844 2 3.33301M14 3.33301V12.6663C14 13.1968 13.3679 13.7055 12.2426 14.0806C11.1174 14.4556 9.5913 14.6663 8 14.6663C6.4087 14.6663 4.88258 14.4556 3.75736 14.0806C2.63214 13.7055 2 13.1968 2 12.6663V3.33301M2 7.99967C2 8.53011 2.63214 9.03882 3.75736 9.41389C4.88258 9.78896 6.4087 9.99967 8 9.99967C9.5913 9.99967 11.1174 9.78896 12.2426 9.41389C13.3679 9.03882 14 8.53011 14 7.99967",stroke:"#9CA3AF",strokeWidth:"1.33",strokeLinecap:"round",strokeLinejoin:"round"})})};function ho(e){let{toolCall:t,parsedArgs:s,isLastAssistantMessage:a,isLastRunningTool:n}=e;const{submitToolCallInput:l,app:r}=Nt(),i=(0,Z.Zp)(),[o,c]=(0,Y.useState)(!1),d=t.status,m=(null==s?void 0:s.entity_name)||"entities",u=(null==s?void 0:s.query)||{},x=(null==s?void 0:s.data)||{},h="running"===d,p="waiting_for_user_input"===d,g="success"===d,f="stopped"===d,v=!u||0===Object.keys(u).length,b=async()=>{c(!0);try{await l(t.id,!0,{})}catch(e){}finally{c(!1)}},j=async()=>{c(!0);try{await l(t.id,!1,{})}catch(e){}finally{c(!1)}};return p?(0,le.jsx)("div",{className:"border border-slate-200 bg-slate-50/50 rounded-lg p-4 space-y-3",children:(0,le.jsxs)("div",{className:"flex items-start gap-2.5",children:[(0,le.jsx)(uo.A,{className:"h-4 w-4 text-slate-500 mt-0.5 flex-shrink-0"}),(0,le.jsxs)("div",{className:"flex-1 space-y-3",children:[(0,le.jsxs)("div",{children:[(0,le.jsx)("div",{className:"text-sm font-medium text-slate-900 mb-1",children:"Approval Required"}),(0,le.jsx)("div",{className:"text-sm text-slate-600",children:v?(0,le.jsxs)(le.Fragment,{children:["Update all"," ",(0,le.jsx)("span",{className:"font-mono text-xs bg-white px-1.5 py-0.5 rounded border border-slate-200",children:m})," records"]}):(0,le.jsxs)(le.Fragment,{children:["Update"," ",(0,le.jsx)("span",{className:"font-mono text-xs bg-white px-1.5 py-0.5 rounded border border-slate-200",children:m})," records matching:"]})})]}),!v&&(0,le.jsxs)("div",{children:[(0,le.jsx)("div",{className:"text-xs text-slate-500 mb-1",children:"Query:"}),(0,le.jsx)("pre",{className:"text-xs bg-white rounded-md p-3 text-slate-700 overflow-x-auto border border-slate-200",children:JSON.stringify(u,null,2)})]}),(0,le.jsxs)("div",{children:[(0,le.jsx)("div",{className:"text-xs text-slate-500 mb-1",children:"Update with:"}),(0,le.jsx)("pre",{className:"text-xs bg-white rounded-md p-3 text-slate-700 overflow-x-auto border border-slate-200",children:JSON.stringify(x,null,2)})]}),a?(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[(0,le.jsx)(Yt,{size:"sm",onClick:b,disabled:o,className:"h-8 text-xs bg-slate-900 hover:bg-slate-800 disabled:opacity-50",children:o?(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(Ne.A,{className:"h-3 w-3 mr-1.5 animate-spin"}),"Approving..."]}):"Approve"}),(0,le.jsx)(Yt,{size:"sm",variant:"outline",onClick:j,disabled:o,className:"h-8 text-xs border-slate-300 hover:bg-slate-50 disabled:opacity-50",children:"Reject"})]}):(0,le.jsx)("div",{className:"text-xs text-slate-500 italic",children:"This approval request is from a previous message"})]})]})}):(0,le.jsx)(Qi,{icon:xo,status:d,isLastAssistantMessage:a,isLastRunningTool:n,onClick:()=>{null!=r&&r.id&&m&&i("/apps/".concat(r.id,"/editor/workspace/entity-").concat(m))},children:(0,le.jsxs)("div",{className:"flex items-center gap-2.5",children:[h?"Updating":g?"Updated":"Update"," ",v&&(h||g)?"all ":"",(0,le.jsx)("span",{className:"flex items-center justify-center gap-2.5 px-1 py-1 bg-gray-100 text-gray-700 rounded font-[400] text-xs",children:m})," records",f&&t.requires_user_input&&(0,le.jsx)("span",{className:"text-slate-400 text-xs italic",children:"rejected"})]})})}const po=["className"],go=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,po);return(0,le.jsx)(bs.b,(0,K.A)({ref:t,className:Pe("text-regular text-sm leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",s)},a))});go.displayName=bs.b.displayName;const fo=e=>{let{className:t}=e;return(0,le.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",className:t,children:(0,le.jsx)("path",{d:"M2.66683 14.6663H12.0002C12.3538 14.6663 12.6929 14.5259 12.943 14.2758C13.193 14.0258 13.3335 13.6866 13.3335 13.333V4.66634L10.0002 1.33301H4.00016C3.64654 1.33301 3.3074 1.47348 3.05735 1.72353C2.80731 1.97358 2.66683 2.31272 2.66683 2.66634V6.66634M9.3335 1.33301V3.99967C9.3335 4.3533 9.47397 4.69244 9.72402 4.94248C9.97407 5.19253 10.3132 5.33301 10.6668 5.33301H13.3335M6.66683 6.66634L3.66683 9.66634M6.00016 7.33301L6.66683 7.99967M4.00016 10.6663C4.00016 11.4027 3.40321 11.9997 2.66683 11.9997C1.93045 11.9997 1.3335 11.4027 1.3335 10.6663C1.3335 9.92996 1.93045 9.33301 2.66683 9.33301C3.40321 9.33301 4.00016 9.92996 4.00016 10.6663Z",stroke:"#9CA3AF",strokeWidth:"1.33",strokeLinecap:"round",strokeLinejoin:"round"})})};function vo(e){let{toolCall:t,parsedArgs:s,isLastAssistantMessage:a,isLastRunningTool:n}=e;const{submitToolCallInput:l}=Nt(),[r,i]=(0,Y.useState)(!1),[o,c]=(0,Y.useState)({}),d=t.status;let m=(null==s?void 0:s.secrets_schema)||[];if("string"==typeof m)try{m=JSON.parse(m)}catch(p){m=[]}const u="running"===d,x=async e=>{e.preventDefault(),i(!0);try{await l(t.id,!0,{secrets:o})}catch(s){}finally{i(!1)}},h=async()=>{i(!0);try{await l(t.id,!1,{})}catch(e){}finally{i(!1)}};return"waiting_for_user_input"===d?(0,le.jsx)("div",{className:"border border-slate-200 bg-slate-50/50 rounded-lg p-4 space-y-3",children:(0,le.jsxs)("div",{className:"flex items-start gap-2.5",children:[(0,le.jsx)(uo.A,{className:"h-4 w-4 text-slate-500 mt-0.5 flex-shrink-0"}),(0,le.jsxs)("div",{className:"flex-1 space-y-3",children:[(0,le.jsxs)("div",{children:[(0,le.jsx)("div",{className:"text-sm font-medium text-slate-900 mb-1",children:"Secrets Required"}),(0,le.jsx)("div",{className:"text-sm text-slate-600",children:"Please provide the following secrets:"})]}),Array.isArray(m)&&m.length>0&&a?(0,le.jsxs)("form",{onSubmit:x,className:"space-y-3",children:[m.map(e=>{const t=e.secretName;return(0,le.jsxs)("div",{className:"space-y-1.5",children:[(0,le.jsxs)(go,{htmlFor:t,className:"text-xs font-medium text-slate-700",children:[t,(0,le.jsx)("span",{className:"text-red-500 ml-1",children:"*"})]}),e.description&&(0,le.jsx)("p",{className:"text-xs text-slate-500",children:e.description}),(0,le.jsx)(fn,{id:t,type:"password",placeholder:"Enter ".concat(t),value:o[t]||"",onChange:e=>((e,t)=>{c(s=>(0,K.A)((0,K.A)({},s),{},{[e]:t}))})(t,e.target.value),className:"text-xs h-8",disabled:r})]},t)}),(0,le.jsxs)("div",{className:"flex items-center gap-2 pt-1",children:[(0,le.jsx)(Hn,{type:"submit",size:"sm",disabled:r,className:"h-8 text-xs bg-slate-900 hover:bg-slate-800 disabled:opacity-50",children:r?(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(Ne.A,{className:"h-3 w-3 mr-1.5 animate-spin"}),"Submitting..."]}):"Submit Secrets"}),(0,le.jsx)(Hn,{type:"button",size:"sm",variant:"outline",onClick:h,disabled:r,className:"h-8 text-xs border-slate-300 hover:bg-slate-50 disabled:opacity-50",children:"Skip"})]})]}):a?(0,le.jsx)("div",{className:"text-xs text-slate-500",children:"No secret fields defined in schema"}):(0,le.jsx)("div",{className:"text-xs text-slate-500 italic",children:"This secrets request is from a previous message"})]})]})}):(0,le.jsx)(Qi,{icon:fo,status:d,isLastAssistantMessage:a,isLastRunningTool:n,children:(0,le.jsxs)("div",{className:"flex items-center gap-2.5",children:[u?"Setting":"Set"," ",(0,le.jsx)("span",{className:"flex items-center justify-center gap-2.5 px-1 py-1 bg-gray-100 text-gray-700 rounded font-[400] text-xs",children:"secrets"}),Array.isArray(m)&&m.length>0&&(0,le.jsxs)("span",{className:"ml-1.5 text-slate-500",children:["\xb7 ",m.length," ",1===m.length?"field":"fields"]})]})})}const bo=e=>{let{className:t}=e;return(0,le.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:t,children:(0,le.jsx)("path",{d:"M9.33341 1.33301V3.99967C9.33341 4.3533 9.47389 4.69244 9.72394 4.94248C9.97399 5.19253 10.3131 5.33301 10.6667 5.33301H13.3334M6.66675 7.99967C6.48994 7.99967 6.32037 8.06991 6.19534 8.19494C6.07032 8.31996 6.00008 8.48953 6.00008 8.66634V9.33301C6.00008 9.50982 5.92984 9.67939 5.80482 9.80441C5.67979 9.92944 5.51023 9.99967 5.33341 9.99967C5.51023 9.99967 5.67979 10.0699 5.80482 10.1949C5.92984 10.32 6.00008 10.4895 6.00008 10.6663V11.333C6.00008 11.5098 6.07032 11.6794 6.19534 11.8044C6.32037 11.9294 6.48994 11.9997 6.66675 11.9997M9.33341 11.9997C9.51023 11.9997 9.67979 11.9294 9.80482 11.8044C9.92984 11.6794 10.0001 11.5098 10.0001 11.333V10.6663C10.0001 10.4895 10.0703 10.32 10.1953 10.1949C10.3204 10.0699 10.4899 9.99967 10.6667 9.99967C10.4899 9.99967 10.3204 9.92944 10.1953 9.80441C10.0703 9.67939 10.0001 9.50982 10.0001 9.33301V8.66634C10.0001 8.48953 9.92984 8.31996 9.80482 8.19494C9.67979 8.06991 9.51023 7.99967 9.33341 7.99967M10.0001 1.33301H4.00008C3.64646 1.33301 3.30732 1.47348 3.05727 1.72353C2.80722 1.97358 2.66675 2.31272 2.66675 2.66634V13.333C2.66675 13.6866 2.80722 14.0258 3.05727 14.2758C3.30732 14.5259 3.64646 14.6663 4.00008 14.6663H12.0001C12.3537 14.6663 12.6928 14.5259 12.9429 14.2758C13.1929 14.0258 13.3334 13.6866 13.3334 13.333V4.66634L10.0001 1.33301Z",stroke:"currentColor",strokeWidth:"1.33",strokeLinecap:"round",strokeLinejoin:"round"})})};function jo(e){let{toolCall:t,parsedArgs:s,isLastAssistantMessage:a,isLastRunningTool:n}=e;const l=t.status,r=(null==s?void 0:s.url)||"",i=(null==s?void 0:s.formats)||["markdown"],o="running"===l,c=(()=>{try{return new URL(r).hostname.replace("www.","")}catch(e){return r}})();return(0,le.jsx)(Qi,{icon:bo,status:l,isLastAssistantMessage:a,isLastRunningTool:n,children:(0,le.jsxs)("div",{children:[(0,le.jsxs)("div",{className:"flex items-center gap-2.5",children:[o?"Fetching":"Fetched"," ",(0,le.jsx)("span",{className:"flex items-center justify-center gap-2.5 px-1 py-1 bg-gray-100 text-gray-700 rounded font-[400] text-xs",children:c})]}),i&&i.length>0&&(0,le.jsxs)("div",{className:"mt-1 text-xs text-slate-500",children:[1===i.length?"Format":"Formats",":"," ",i.map((e,t)=>(0,le.jsxs)("span",{children:[(0,le.jsx)("span",{className:"font-medium ml-1",children:e}),t{let{className:t}=e;return(0,le.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",className:t,children:(0,le.jsx)("path",{d:"M14.0001 14L11.1335 11.1333M12.6667 7.33333C12.6667 10.2789 10.2789 12.6667 7.33333 12.6667C4.38781 12.6667 2 10.2789 2 7.33333C2 4.38781 4.38781 2 7.33333 2C10.2789 2 12.6667 4.38781 12.6667 7.33333Z",stroke:"#9CA3AF",strokeWidth:"1.33",strokeLinecap:"round",strokeLinejoin:"round"})})};function No(e){let{toolCall:t,parsedArgs:s,isLastAssistantMessage:a,isLastRunningTool:n}=e;const l=t.status,r=(null==s?void 0:s.query)||"",i="running"===l,o="success"===l,c=(()=>{if(!t.results)return null;try{const e="string"==typeof t.results?t.results:JSON.stringify(t.results);return(e.match(/----------/g)||[]).length}catch(e){return null}})();return(0,le.jsx)(Qi,{icon:yo,status:l,isLastAssistantMessage:a,isLastRunningTool:n,children:(0,le.jsxs)("div",{children:[(0,le.jsxs)("div",{className:"flex items-center gap-2.5",children:[i?"Searching":"Searched"," for"," ",(0,le.jsxs)("span",{className:"flex items-center justify-center gap-2.5 px-1 bg-gray-100 text-gray-700 rounded font-[400] text-xs",children:['"',r,'"']})]}),o&&null!==c&&(0,le.jsxs)("div",{className:"mt-1 text-gray-500 text-xs",children:["Found ",c," ",1===c?"result":"results"]})]})})}function wo(e){let{toolCall:t,messageId:s,isLastAssistantMessage:a,isLastRunningTool:n}=e;const[l,r]=(0,Y.useState)(!1),i=(null==t?void 0:t.name)||"Function",o=(null==t?void 0:t.status)||"pending",c=null==t?void 0:t.results,d=(()=>{if(null==t||!t.arguments_string)return null;try{return JSON.parse(t.arguments_string)}catch(e){return null}})(),m=(()=>{if(!c)return null;try{return"string"==typeof c?JSON.parse(c):c}catch(e){return c}})(),u={edit_file:so,read_file:no,create_entities:ro,create_entity_records:ro,read_entities:oo,update_entities:ho,delete_entities:mo,set_secrets:vo,fetch_website:jo,search_web:No}[i];if(u){const e=d||m?{input:d,output:m}:null;return(0,le.jsx)("div",{className:"px-3 py-2",children:(0,le.jsx)(u,{toolCall:t,parsedArgs:d,messageId:s,isLastAssistantMessage:a,isLastRunningTool:n,debugInfo:e})})}c&&(null==m||m.success);const x={pending:{icon:Li.A,color:"text-slate-400",text:"Pending"},waiting_for_user_input:{icon:Li.A,color:"text-slate-400",text:"Waiting for user input"},running:{icon:Ne.A,color:"text-slate-500",text:"Running...",spin:!0},success:{icon:pr.A,color:"text-green-600",text:"Success"},failed:{icon:_e.A,color:"text-red-500",text:"Failed"},error:{icon:_e.A,color:"text-red-500",text:"Failed"}}[o]||{icon:Oi.A,color:"text-slate-500",text:""},h=x.icon,p=i.split(".").reverse().join(" ").toLowerCase(),g=(()=>{if(!d)return"";if("edit_file"===i||"read_file"===i){return d.file_path||""}if("fetch_website"===i){const e=d.url||"";return e.length>50?e.substring(0,50)+"...":e}if("search_web"===i){const e=d.query||"";return e.length>40?e.substring(0,40)+"...":e}const e=Object.keys(d)[0];if(e){const t=d[e],s="string"==typeof t?t:JSON.stringify(t),a=s.length>30?s.substring(0,30)+"...":s;return"".concat(e,": ").concat(a)}return""})();return(0,le.jsxs)("div",{className:"mt-2 text-xs",children:[(0,le.jsxs)("button",{onClick:()=>r(!l),className:Pe("flex items-center gap-2 px-3 py-1.5 rounded-lg border transition-all","hover:bg-slate-50",l?"bg-slate-50 border-slate-300":"bg-white border-slate-200"),children:[(0,le.jsx)(h,{className:Pe("h-3 w-3",x.color,x.spin&&"animate-spin")}),(0,le.jsx)("span",{className:"text-slate-700",children:p}),g&&(0,le.jsx)("span",{className:"text-slate-600 font-mono text-xs bg-slate-100 px-1.5 py-0.5 rounded",children:g}),!x.spin&&(t.arguments_string||c)&&(0,le.jsx)(rn.A,{className:Pe("h-3 w-3 text-slate-400 transition-transform ml-auto",l&&"rotate-90")})]}),l&&!x.spin&&(0,le.jsxs)("div",{className:"mt-1.5 ml-3 pl-3 border-l-2 border-slate-200 space-y-2",children:[t.arguments_string&&(0,le.jsxs)("div",{children:[(0,le.jsx)("div",{className:"text-xs text-slate-500 mb-1",children:"Parameters:"}),(0,le.jsx)("pre",{className:"bg-slate-50 rounded-md p-2 text-xs text-slate-600 whitespace-pre-wrap",children:(()=>{try{return JSON.stringify(JSON.parse(t.arguments_string),null,2)}catch(e){return t.arguments_string}})()})]}),m&&(0,le.jsxs)("div",{children:[(0,le.jsx)("div",{className:"text-xs text-slate-500 mb-1",children:"Result:"}),(0,le.jsx)("pre",{className:"bg-slate-50 rounded-md p-2 text-xs text-slate-600 whitespace-pre-wrap max-h-48 overflow-auto",children:"object"==typeof m?JSON.stringify(m,null,2):m})]})]}),"request_secrets"===i&&"success"===o&&(()=>{try{const e=JSON.parse(c);if("request_secrets"===e.type&&e.secrets)return(0,le.jsx)("div",{className:"mt-2",children:(0,le.jsx)(hi,{content:e.secrets})})}catch(e){}return null})()]})}const _o=e=>{let{toolCalls:t,messageId:s,isLastMessageInChat:a}=e;const[n,l]=(0,Y.useState)(!0);if(!t||0===t.length)return null;const r=t.map((e,t)=>"running"===e.status?t:-1).filter(e=>-1!==e),i=r.length>0?r[r.length-1]:-1,o=1===t.length;return(0,le.jsx)("div",{className:"bg-white rounded-[10px] border border-slate-200 mt-3",children:(0,le.jsxs)(le.Fragment,{children:[!o&&(0,le.jsxs)("div",{className:"flex items-center gap-2 px-3 py-2.5",children:[(0,le.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",className:"transition-transform duration-200 cursor-pointer hover:bg-slate-100 rounded p-0.5 -ml-0.5 ".concat(n?"":"-rotate-90"),onClick:()=>l(!n),children:(0,le.jsx)("path",{d:"M4.66675 10.0003L8.00008 13.3337L11.3334 10.0003M4.66675 6.00033L8.00008 2.66699L11.3334 6.00033",stroke:"#9CA3AF",strokeWidth:"1.33",strokeLinecap:"round",strokeLinejoin:"round"})}),(0,le.jsx)("span",{className:"text-sm text-slate-700 font-medium",children:-1!==i?"Building...":"Used ".concat(t.length," tools")})]}),n&&(0,le.jsx)("div",{className:"border-t border-slate-100",children:t.map((e,t)=>(0,le.jsx)(wo,{toolCall:e,messageId:s,isLastAssistantMessage:a,isLastRunningTool:t===i},t))})]})})},ko=e=>{let{files:t}=e;const[s,a]=(0,Y.useState)(!1);if(!t||0===t.length)return null;const n=t.reduce((e,t)=>(t.startsWith("entities/")?e.entities.push(t):t.startsWith("pages/")||t.startsWith("components/")||t.startsWith("layout")?e.code.push(t):e.other.push(t),e),{entities:[],code:[],other:[]});return(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)("div",{className:"text-xs text-gray-400 cursor-pointer hover:underline",onClick:()=>a(!0),children:(0,le.jsxs)("span",{className:"flex items-center gap-1",children:[(0,le.jsx)(hr.A,{className:"h-3 w-3"}),"see context"]})}),s&&(0,le.jsx)("div",{className:"fixed inset-0 bg-black bg-opacity-50 z-50 flex items-center justify-center p-4",children:(0,le.jsxs)("div",{className:"bg-white dark:bg-gray-800 rounded-lg shadow-lg max-w-2xl w-full max-h-[80vh] flex flex-col",children:[(0,le.jsxs)("div",{className:"flex justify-between items-center p-4 border-b dark:border-gray-700",children:[(0,le.jsx)("h3",{className:"font-medium text-lg",children:"Files Selected for Context"}),(0,le.jsx)("button",{onClick:()=>a(!1),className:"text-gray-500 hover:text-gray-700 dark:hover:text-gray-300 transition-colors",children:(0,le.jsx)(Bt.A,{className:"h-5 w-5"})})]}),(0,le.jsxs)("div",{className:"p-5 overflow-y-auto flex-1",children:[(0,le.jsxs)("p",{className:"text-sm text-gray-600 dark:text-gray-300 mb-5",children:["In complex projects, for every user message, the platform automatically selects which code files ",(0,le.jsx)("b",{children:"might"})," be relevant for potential changes."]}),(0,le.jsxs)("p",{className:"text-sm text-teal-700 dark:text-teal-400 mb-5 border-l-2 border-teal-600 pl-3",children:[(0,le.jsx)("b",{children:"Important:"})," If you intended to modify a file that doesn't appear in this list, the AI might get confused and make changes in the wrong place or not make the changes at all. Consider mentioning the specific file path in your message for better results."]}),n.code.length>0&&(0,le.jsxs)("div",{className:"mb-5",children:[(0,le.jsxs)("h4",{className:"text-sm font-semibold mb-2 flex items-center gap-2",children:[(0,le.jsx)(Kl.A,{className:"h-4 w-4"}),"Code Files"]}),(0,le.jsx)("div",{className:"space-y-1 pl-2",children:n.code.map((e,t)=>(0,le.jsx)("div",{className:"text-sm py-1.5 px-3 bg-blue-50 dark:bg-blue-900/20 rounded border border-blue-100 dark:border-blue-800 text-gray-800 dark:text-gray-200",children:e},t))})]}),n.entities.length>0&&(0,le.jsxs)("div",{className:"mb-5",children:[(0,le.jsxs)("h4",{className:"text-sm font-semibold mb-2 flex items-center gap-2",children:[(0,le.jsx)(Cl.A,{className:"h-4 w-4"}),"Entity Files"]}),(0,le.jsx)("div",{className:"space-y-1 pl-2",children:n.entities.map((e,t)=>(0,le.jsx)("div",{className:"text-sm py-1.5 px-3 bg-purple-50 dark:bg-purple-900/20 rounded border border-purple-100 dark:border-purple-800 text-gray-800 dark:text-gray-200",children:e},t))})]}),n.other.length>0&&(0,le.jsxs)("div",{children:[(0,le.jsxs)("h4",{className:"text-sm font-semibold mb-2 flex items-center gap-2",children:[(0,le.jsx)(hr.A,{className:"h-4 w-4"}),"Other Files"]}),(0,le.jsx)("div",{className:"space-y-1 pl-2",children:n.other.map((e,t)=>(0,le.jsx)("div",{className:"text-sm py-1.5 px-3 bg-gray-50 dark:bg-gray-700 rounded border border-gray-100 dark:border-gray-600 text-gray-800 dark:text-gray-200",children:e},t))})]})]}),(0,le.jsx)("div",{className:"p-4 border-t dark:border-gray-700 flex justify-end",children:(0,le.jsx)("button",{onClick:()=>a(!1),className:"px-4 py-2 bg-gray-100 hover:bg-gray-200 dark:bg-gray-700 dark:hover:bg-gray-600 rounded text-sm font-medium transition-colors",children:"Close"})})]})})]})};function Co(e){var t,s,a,n,l;let{item:r,undoMessage:i,itemIndex:o}=e;const{user:c}=oe(),{app:d}=Nt();if(null===(t=r.additional_message_params)||void 0===t?void 0:t.automated_fix)return(0,le.jsx)("div",{className:"mb-6 relative",children:(0,le.jsx)(_i,{message:r})});if(null===(s=r.additional_message_params)||void 0===s?void 0:s.diff_message)return(0,le.jsx)("div",{className:"mb-6 relative",children:(0,le.jsx)(Ti,{message:r})});const m=null===(a=r.custom_context)||void 0===a?void 0:a.find(e=>{var t;return"files"===e.type&&(null===(t=e.data)||void 0===t?void 0:t.files)}),u=(null==m||null===(n=m.data)||void 0===n?void 0:n.files)||[],x="user"===r.role,h="user"===r.role||r.isLastAssistantMessage;return(0,le.jsxs)("div",{className:"".concat(h?"mb-6":"mb-2"," relative ").concat(x?"flex justify-end":""),children:["assistant"===r.role&&r.isFirstAssistantMessage&&(0,le.jsxs)("div",{className:"flex items-center gap-2 mb-2",children:[(0,le.jsx)("img",{src:be,alt:"Base44 AI",className:"w-6 h-6 object-cover rounded-full opacity-75"}),(0,le.jsx)("span",{className:"text-xs text-gray-500",children:"Base44"})]}),(0,le.jsx)(Pi,{reasoning:r.reasoning}),(0,le.jsx)("div",{className:"text-sm ps-2 rounded-lg ".concat(x?"pr-4 bg-slate-200 max-w-[85%] py-4":"pl-8"),children:(0,le.jsxs)("div",{children:[r.custom_context&&r.custom_context.map((e,t)=>{var s;if("element"===e.type&&null!==(s=e.data)&&void 0!==s&&s.element_tag_name){const s=e.data.element_tag_name.toLowerCase(),a=Ei[s]||(0,le.jsx)(Kl.A,{className:"h-3 w-3"});return(0,le.jsx)("div",{className:"mb-2 flex items-center gap-2 text-xs",children:(0,le.jsxs)("div",{className:"flex items-center gap-1 px-2 py-1 bg-gray-900 text-white rounded-md",children:[a,(0,le.jsx)("span",{children:s})]})},t)}return null}),r.file_urls&&r.file_urls.length>0&&(0,le.jsx)("div",{className:"mb-4 flex flex-wrap gap-4",children:r.file_urls.map((e,t)=>(0,le.jsx)("div",{className:"relative",children:e.match(/\.(jpg|jpeg|png|gif)$/i)?(0,le.jsx)("img",{src:e,alt:"Attached content",className:"max-w-[300px] max-h-[300px] rounded-lg border border-gray-200 shadow-sm"}):(0,le.jsxs)("div",{className:"flex items-center gap-2 p-2 bg-white rounded-lg border border-gray-200",children:[(0,le.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-gray-500",children:[(0,le.jsx)("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),(0,le.jsx)("polyline",{points:"14 2 14 8 20 8"})]}),(0,le.jsx)("a",{href:e,target:"_blank",rel:"noopener noreferrer",className:"text-blue-600 hover:underline",children:"Attached file"})]})},t))}),(0,le.jsx)(wi,{content:r.content,msgId:r.id,role:r.role}),(0,le.jsx)(_o,{toolCalls:r.tool_calls,messageId:r.id,isLastMessageInChat:r.isLastMessageInChat}),(null===(l=r.metadata)||void 0===l?void 0:l.created_date)&&("user"===r.role||r.isLastAssistantMessage)&&(0,le.jsxs)("div",{className:"text-xs text-gray-400 mt-2 flex items-center",children:[ra().utc(r.metadata.created_date,ra().ISO_8601).fromNow(),"user"===r.role&&u.length>0&&(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)("span",{className:"mx-2",children:"\u2022"}),(0,le.jsx)(ko,{files:u})]})]})]})}),"user"===r.role&&o>0&&r.checkpoint_id&&(0,le.jsx)("div",{className:"cursor-pointer absolute bottom-[-10px] right-0 bg-white border border-gray-200 rounded-md p-1 text-xs text-gray-400",children:(0,le.jsxs)("a",{onClick:()=>{var e;window.confirm("Are you sure you want to undo this message? This will load the state of the app before this message.")&&(tt("User clicked - revert this",{app_id:null==d?void 0:d.id,message_id:r.id}),ht({user_id:null==c?void 0:c.id,app_id:null==d?void 0:d.id,conversation_id:null==d||null===(e=d.conversation)||void 0===e?void 0:e.id},{cta:"revert this",origin:"chat_message",message_id:r.id,target_route:null}),i(r.id))},className:"flex items-center gap-1",children:[(0,le.jsx)(Ii.A,{className:"h-3 w-3"}),"Revert this"]})})]})}class Ao extends Y.Component{constructor(e){super(e),this.state={hasError:!1,error:null}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,t){}render(){return this.state.hasError?(0,le.jsx)("div",{className:"mx-4 my-3 px-6 py-4 rounded-lg bg-slate-50 border border-slate-200 text-slate-600 text-base",children:(0,le.jsx)("p",{className:"text-sm",children:"Could not render this message. It might contain special characters."})}):this.props.children}}const So=e=>{let{messages:t,undoMessage:s,loadFullConversation:a}=e;const[n,l]=(0,Y.useState)(20),[r,i]=(0,Y.useState)(!0),[o,c]=(0,Y.useState)(!1),[d,m]=(0,Y.useState)(!1),u=(0,Y.useRef)(null),x=(0,Y.useRef)(t.length);(0,Y.useEffect)(()=>{0===x.current&&t.length>0?(l(20),i(t.length>20),c(!1)):o?(l(t.length),i(!1)):l(e=>{const s=Math.min(20,t.length);return i(t.length>s),s}),x.current=t.length},[t.length,o]),(0,Y.useEffect)(()=>{const e=new URLSearchParams(window.location.search).get("msgId");e&&setTimeout(()=>{const t=document.getElementById("message-".concat(e));t&&(t.scrollIntoView({behavior:"smooth"}),t.classList.add("border-2"),t.classList.add("border-black"),t.classList.add("font-medium"))},1e3)},[]);const h=t.slice(-n);return(0,le.jsxs)("div",{ref:u,className:"relative",children:[r&&(0,le.jsx)("div",{className:"flex justify-center py-2",children:(0,le.jsxs)("button",{onClick:async()=>{const e=u.current,s=e.scrollHeight-e.scrollTop;if(a){m(!0);try{await a()}catch(n){}m(!1)}l(t.length),i(!1),c(!0),setTimeout(()=>{e&&(e.scrollTop=e.scrollHeight-s)},0)},disabled:d,className:"text-sm text-blue-500 hover:text-blue-600 hover:underline disabled:opacity-50 disabled:cursor-not-allowed flex items-center gap-2",children:[d&&(0,le.jsx)(Ne.A,{className:"h-3 w-3 animate-spin"}),"Load entire conversation"]})}),h.slice(0,h.length).map((e,t)=>(0,le.jsx)("div",{id:"message-".concat(e.id),children:(0,le.jsx)(Ao,{children:(0,le.jsx)(Co,{item:e,itemIndex:t,undoMessage:s})})},e.id||t))]})};var Eo=s(53291),Io=s(52229);function To(e){let{status:t,typingSpeed:s=40,className:a=""}=e;const[n,l]=(0,Y.useState)(""),[r,i]=(0,Y.useState)(!0),[o,c]=(0,Y.useState)(0),d=(0,Y.useRef)(t||""),m=(0,Y.useRef)(null);return(0,Y.useEffect)(()=>{t===d.current&&r||(c(e=>e+1),i(!0),l(""),d.current=t||"")},[t]),(0,Y.useEffect)(()=>{if(r&&d.current&&n.length{l(d.current.substring(0,n.length+1))},s),()=>clearTimeout(m.current);r&&d.current&&n.length===d.current.length&&i(!1)},[n,r,s]),(0,le.jsxs)("div",{className:"flex items-center h-[1.5em] sm:h-[2em]",children:[" ",(0,le.jsx)(Eo.N,{mode:"wait",children:(0,le.jsxs)(Io.P.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:{duration:.2},className:"text-slate-700 tracking-normal ".concat(a),children:[n,r?(0,le.jsx)(Io.P.span,{initial:{opacity:1},animate:{opacity:0},transition:{duration:.5,repeat:1/0,repeatType:"reverse"},className:"inline-block w-[2px] h-[1.1em] sm:h-[1.2em] bg-slate-600 ml-[1px] align-middle"}):(0,le.jsx)(Io.P.span,{initial:{opacity:0},animate:{opacity:[0,1,0]},transition:{duration:1.2,repeat:1/0,ease:"easeInOut",delay:.2},className:"inline-block w-[0.5em] sm:w-[0.55em] h-[1em] sm:h-[1.1em] bg-slate-600 ml-[2px] align-[-0.1em] sm:align-[-0.15em]"})]},o)})]})}const Po=e=>{let{status:t}=e;return(0,le.jsx)("div",{className:"mx-4 my-3 px-4 py-3 rounded-lg bg-red-50 border border-red-200 text-red-700 text-sm flex items-center",children:(0,le.jsx)("div",{className:"flex-1",children:t.details})})};function Lo(e){let{status:t,messages:s}=e;const[a,n]=(0,Y.useState)((new Date).getTime()),[l,r]=(0,Y.useState)(window.innerWidth<=768);(0,Y.useEffect)(()=>{const e=()=>{r(window.innerWidth<=768)};return window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[]),(0,Y.useEffect)(()=>{const e=new Date(t.last_updated_date).getTime();n(t=>!t||e>t?e:t)},[t.last_updated_date]),(0,Y.useEffect)(()=>{"processing"===t.state&&n((new Date).getTime())},[t.state]);const i=(a&&"processing"===t.state&&null!=s&&s.length?(new Date).getTime()-new Date(a).getTime():0)>6e5,o=l||(null==s?void 0:s.length)>2;return(0,le.jsxs)("div",{children:["error"===t.state&&(0,le.jsx)(Po,{status:t}),"processing"===t.state&&(0,le.jsxs)("div",{className:"",children:[i&&(0,le.jsxs)("div",{className:"text-xs text-gray-500 mt-2",children:["This has been running for a while. It might be stuck.",(0,le.jsxs)("div",{className:"mt-1",children:["If this persists, try to stop the chat, *revert your last message* and try again, or ",(0,le.jsx)("button",{type:"button",onClick:()=>window.open("/support","_blank"),className:"underline text-primary hover:text-orange-500 transition-colors",children:"contact support"}),"."]})]}),o&&(0,le.jsxs)("div",{className:"text-gray-500 mt-3 ml-4 flex items-center gap-2",children:[(0,le.jsx)("img",{src:be,alt:"Logo",className:"w-4 h-4 grayscale"}),(0,le.jsx)(To,{status:t.details,className:"text-xs"})]})]})]})}function Oo(e){if(!e)return"0";const t=parseInt(e.toString(),10);return t>=1e3?"".concat((t/1e3).toFixed(t%1e3==0?0:1),"k"):t.toString()}function Ro(e){return Boolean(e&&e.endsWith("_yearly"))}function Mo(e){return e&&e.endsWith("_yearly")?e.replace("_yearly",""):e||""}function Do(e){return"".concat(e,"_yearly")}function Fo(e){return e?e.replace(/\s*(yearly|Yearly)\s*/gi,"").replace(/\s*plan\s*/gi,"").replace(/\s*\.\.\.\s*/g,"").replace(/\s+/g," ").trim():""}const Bo=["starter","builder","pro","elite","elite_2","elite_3","elite_4"];function zo(e){return e&&"free"!==e.toLowerCase()?Ro(e)?"yearly":"monthly":"yearly"}function Uo(e){if(!e||"free"===e.toLowerCase())return"starter";const t=Mo(e),s=Bo.indexOf(t);return-1===s||s===Bo.length-1?null:Bo[s+1]}function Wo(e){if(null==e||!e.metadata)return{messageCredits:0,integrationCredits:0};return{messageCredits:parseInt(e.metadata.monthly_message_limit||"0",10),integrationCredits:parseInt(e.metadata.monthly_integration_credits||"0",10)}}function qo(e){return Oo(e)}function Vo(e){if(!e)return"";return{starter:"Starter",builder:"Builder",pro:"Pro",elite:"Elite",elite_2:"Elite 2",elite_3:"Elite 3",elite_4:"Elite 4"}[e]||e}function Ho(e,t){const s=zo(e),a=Uo(e),n=function(e,t){if(null==t||!t.pricing)return null;const s=Uo(e);return s&&("yearly"===zo(e)?t.pricing.yearly:t.pricing.monthly)[s]||null}(e,t);return{currentTier:e||"free",nextTier:a,billingPeriod:s,nextPlan:n}}function Yo(e,t){const s=function(e){let{currentUsage:t,stats:s}=e;const[a,n]=(0,Y.useState)(!0),[l,r]=(0,Y.useState)(null),i=(0,Y.useMemo)(()=>{if(!t||!s)return{currentPlan:null,nextPlan:null,billingPeriod:"yearly"};try{var e;const a=Ho(t.tier,s);return{currentPlan:null!==(e=s.stripe_subscription)&&void 0!==e&&e.plan&&Object.values(s.pricing.monthly).concat(Object.values(s.pricing.yearly)).find(e=>{var t,a;return e.id===(null===(t=s.stripe_subscription)||void 0===t||null===(a=t.plan)||void 0===a?void 0:a.id)})||null,nextPlan:a.nextPlan,billingPeriod:a.billingPeriod}}catch(a){return r("Failed to calculate billing information"),{currentPlan:null,nextPlan:null,billingPeriod:"yearly"}}},[t,s]);return(0,Y.useEffect)(()=>{null!==t&&null!==s?(n(!1),r(null)):n(!0)},[t,s]),{currentPlan:i.currentPlan,nextPlan:i.nextPlan,billingPeriod:i.billingPeriod,isLoading:a,error:l}}({currentUsage:e,stats:t}),a=(0,Y.useMemo)(()=>s.nextPlan?Wo(s.nextPlan):{messageCredits:0,integrationCredits:0},[s.nextPlan]);return(0,K.A)((0,K.A)({},s),{},{nextPlanCredits:a,hasNextPlan:null!==s.nextPlan})}class Go extends Q.H{getBaseURL(){return"/billing"}createCheckoutSession(e){return this.axios.post("/create-checkout-session/".concat(e))}createPortalSession(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"default";return this.axios.post("/create-portal-session",{},{params:{flow_type:e}})}updateSubscription(e){return this.axios.post("/update-subscription/".concat(e))}cancelSchedule(){return this.axios.delete("/cancel-schedule")}createWorkspaceCheckoutSession(e,t){return this.axios.post("/create-workspace-checkout-session",{workspace_id:e,pending_changes:t})}getInvoices(){return this.axios.get("/invoices")}}const $o=new Go,Jo=["className"],Zo=["className","children"],Ko=["className"],Qo=["className"],Xo=["className"],ec=["className"],tc=ka.Root,sc=ka.Trigger,ac=ka.Portal,nc=(ka.Close,Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,Jo);return(0,le.jsx)(ka.Overlay,(0,K.A)({ref:t,className:Pe("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",s)},a))}));nc.displayName=ka.Overlay.displayName;const lc=Y.forwardRef((e,t)=>{let{className:s,children:a}=e,n=(0,Se.A)(e,Zo);return(0,le.jsxs)(ac,{children:[(0,le.jsx)(nc,{}),(0,le.jsxs)(ka.Content,(0,K.A)((0,K.A)({ref:t,className:Pe("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",s)},n),{},{children:[a,(0,le.jsxs)(ka.Close,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground",children:[(0,le.jsx)(Bt.A,{className:"h-4 w-4"}),(0,le.jsx)("span",{className:"sr-only",children:"Close"})]})]}))]})});lc.displayName=ka.Content.displayName;const rc=e=>{let{className:t}=e,s=(0,Se.A)(e,Ko);return(0,le.jsx)("div",(0,K.A)({className:Pe("flex flex-col space-y-1.5 text-center sm:text-left",t)},s))};rc.displayName="DialogHeader";const ic=e=>{let{className:t}=e,s=(0,Se.A)(e,Qo);return(0,le.jsx)("div",(0,K.A)({className:Pe("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",t)},s))};ic.displayName="DialogFooter";const oc=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,Xo);return(0,le.jsx)(ka.Title,(0,K.A)({ref:t,className:Pe("text-lg font-semibold leading-none tracking-tight",s)},a))});oc.displayName=ka.Title.displayName;const cc=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,ec);return(0,le.jsx)(ka.Description,(0,K.A)({ref:t,className:Pe("text-sm text-muted-foreground",s)},a))});cc.displayName=ka.Description.displayName;const dc=e=>{let{question:t,answer:s}=e;const[a,n]=(0,Y.useState)(!1);return(0,le.jsxs)("div",{className:"border-b border-gray-200 py-4",children:[(0,le.jsxs)("button",{className:"flex justify-between items-center w-full text-left",onClick:()=>n(!a),children:[(0,le.jsx)("h3",{className:"text-lg font-medium text-gray-800",children:t}),(0,le.jsx)("span",{className:"text-gray-600 transition-transform duration-300 ".concat(a?"rotate-180":""),children:(0,le.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,le.jsx)("polyline",{points:"6 9 12 15 18 9"})})})]}),(0,le.jsx)(Eo.N,{children:a&&(0,le.jsx)(Io.P.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:.3},className:"overflow-hidden",children:(0,le.jsx)("div",{className:"pt-4 pb-2 text-gray-600",children:s})})})]})};function mc(){const e=[{question:"What is Base44?",answer:(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsx)("p",{children:"Base44 is an AI-powered platform that allows you to build custom software applications without coding. It uses natural language processing to understand your requirements and generate functional software based on your descriptions."}),(0,le.jsx)("p",{children:"Our platform is designed to be user-friendly and accessible to non-technical users, enabling you to create powerful applications through simple conversations with our AI."})]})},{question:"What's included in the free plan?",answer:(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsx)("p",{children:"The free plan gives you a daily allowance of 5 messages and a monthly cap of 25 messages total. You also get 100 integration credits to experiment with various integrations like authentication, database, and analytics."}),(0,le.jsx)("p",{children:"With the free plan, you have access to all core integration types, allowing you to build fully functional applications with user authentication, data storage, and more - all at no cost."})]})},{question:"What are integration credits?",answer:(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsx)("p",{children:"Integration credits are used to access Base44's various integrations within your application. Each integration request costs 1 credit, regardless of which integration you're using."}),(0,le.jsx)("p",{children:"These integrations enhance your app's functionality, including LLMs, file uploading, image understanding, image generation, email sending, SMS sending, database querying, and many more. The number of integration credits in your plan determines how many of these requests you can make per month."})]})},{question:"What types of applications can I build with Base44?",answer:(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsx)("p",{children:"Base44 is versatile and can be used to build a wide range of applications, including but not limited to: fully functional SaaS products, backoffice tools, personal productivity apps, customer portals, and business process automation tools."}),(0,le.jsx)("p",{children:"You can also use it for rapid prototyping and creating MVPs, allowing you to validate your ideas quickly without investing in expensive development resources."})]})},{question:"Who owns the applications created with Base44?",answer:(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsx)("p",{children:"Between you and Base44, all applications and content generated through our platform shall be considered your property. We make no ownership claims over anything you create using Base44. "}),(0,le.jsx)("p",{children:"Your intellectual property remains yours, and you're free to use, modify, distribute, or sell the generated applications as permitted by law. "})]})},{question:"How are Base44 applications deployed?",answer:(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsx)("p",{children:"With Base44, deployment is incredibly simple. Your applications are instantly usable and shareable as soon as you create them. Simply use and share the URL of your app with others."}),(0,le.jsx)("p",{children:"There's no need for separate hosting or deployment steps, making it incredibly easy to get your application up and running quickly."})]})},{question:"What happens if I reach my plan limits?",answer:(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsx)("p",{children:"When you reach your daily message limit, you'll need to wait until the next day to send more messages. If you hit your monthly limit, you won't be able to send additional messages or make integration requests until the beginning of your next billing cycle."}),(0,le.jsx)("p",{children:"To avoid interruptions in your app development and usage, you can upgrade to a higher tier plan with increased limits at any time from your billing dashboard."})]})}];return(0,le.jsxs)("div",{className:" rounded-xl p-8 mt-12",children:[(0,le.jsx)("h2",{className:"text-2xl font-semibold mb-6 text-gray-800",children:"Frequently Asked Questions"}),(0,le.jsx)("div",{className:"divide-y divide-gray-200",children:e.map((e,t)=>(0,le.jsx)(dc,{question:e.question,answer:e.answer},t))})]})}const uc=["trackingAction","ctaText","trackingContext","onClick","children"],xc=e=>{let{trackingAction:t,ctaText:s,trackingContext:a={},onClick:n,children:l}=e,r=(0,Se.A)(e,uc);const i=oe(),o=ge();let c=null,d=null;try{c=(null==i?void 0:i.user)||null}catch(m){}try{d=(null==o?void 0:o.activeWorkspace)||null}catch(m){}return(0,le.jsx)(Hn,(0,K.A)((0,K.A)({},r),{},{onClick:e=>{try{var l,r,i,o,u;const e=(0,K.A)({action:t||"unknown_action",element_type:"button",user_id:(null===(l=c)||void 0===l?void 0:l.id)||null,workspace_id:(null===(r=d)||void 0===r?void 0:r.id)||null,workspace_name:(null===(i=d)||void 0===i?void 0:i.name)||null,is_workspace_context:!(!d||d.is_personal),is_personal_workspace:(null===(o=d)||void 0===o?void 0:o.is_personal)||!1,user_email:(null===(u=c)||void 0===u?void 0:u.email)||null},a);try{tt("User - Click",e)}catch(p){}try{var x,h;ht({user_id:null!==(x=null===(h=c)||void 0===h?void 0:h.id)&&void 0!==x?x:null},(0,K.A)({cta:s||"Unknown CTA",origin:(null==a?void 0:a.origin)||"Unknown",target_route:(null==a?void 0:a.target_route)||null},a))}catch(g){}}catch(m){}try{null==n||n(e)}catch(m){throw m}},children:l}))},hc=["billingAction","ctaText","billingContext","children"],pc=e=>{let{billingAction:t,ctaText:s,billingContext:a={},children:n}=e,l=(0,Se.A)(e,hc),r={};try{r=(0,K.A)({origin:"BillingPage",target_route:"/billing",element_type:"button"},a)}catch(i){r={origin:"BillingPage",element_type:"button"}}return(0,le.jsx)(xc,(0,K.A)((0,K.A)({trackingAction:t||"unknown_billing_action",ctaText:s||"Unknown Button",trackingContext:r},l),{},{children:n}))};class gc extends Q.H{getBaseURL(){return"/credits"}addBonusCredits(e,t,s){return this.axios.post("/add-bonus-credits",{user_id:e,num_messages:t,reason:s})}createCouponCode(e,t,s,a){return this.axios.post("/create-coupon-code",{code:e,num_messages:t,max_number_of_people:s,domain:a})}getCouponCodes(){return this.axios.get("/coupon-codes")}getBonusCredits(e){return this.axios.get("/".concat(e,"/bonus-credits"))}addCouponCode(e){return this.axios.post("/add-coupon-code/".concat(e))}deleteBonusCredits(e,t){return this.axios.delete("/".concat(e,"/bonus-credits/").concat(t))}}const fc=new gc;var vc=s(34799);function bc(){const{toast:e}=nn(),{user:t}=oe(),{activeWorkspace:s}=ge(),[a,n]=(0,Y.useState)(null),[l,r]=(0,Y.useState)(!0),[i,o]=(0,Y.useState)(null);if((0,Y.useEffect)(()=>{(async()=>{if(null!=s&&s.id)try{r(!0),o(null);const e=await xe.getMySeatInfo(s.id);n(e)}catch(t){o(t),e({variant:"destructive",title:"Error",description:"Failed to load workspace billing information"})}finally{r(!1)}})()},[null==s?void 0:s.id,e]),l)return(0,le.jsx)("div",{className:"flex items-center justify-center py-8",children:(0,le.jsx)("div",{className:"animate-spin rounded-full h-8 w-8 border-t-2 border-b-2 border-slate-700"})});if(i||!a)return(0,le.jsx)(De,{className:"border-red-200 bg-red-50",children:(0,le.jsx)(Be,{className:"text-red-800",children:"Unable to load workspace billing information. Please try again later."})});const c=null==a?void 0:a.user_seat,d=null==a?void 0:a.workspace,m=null==a?void 0:a.is_admin,u=(null==a?void 0:a.workspace_admins)||[];return(0,le.jsxs)("div",{className:"space-y-6",children:["assigned"===(null==c?void 0:c.status)?(0,le.jsx)(is,{className:"border-slate-200",children:(0,le.jsx)(ms,{className:"pt-6 space-y-4",children:(0,le.jsxs)("div",{children:[(0,le.jsxs)("h2",{className:"text-2xl font-semibold text-slate-900 mb-3",children:[c.seat_type," Plan",(0,le.jsx)(St,{children:(0,le.jsxs)(Et,{children:[(0,le.jsx)(It,{asChild:!0,children:(0,le.jsx)(uo.A,{className:"h-4 w-4 text-slate-400 hover:text-slate-600 ml-2 inline"})}),(0,le.jsx)(Tt,{children:(0,le.jsxs)("p",{children:["Seat #",c.seat_id]})})]})})]}),(0,le.jsxs)("p",{className:"text-slate-700 mb-4",children:["You're currently on the ",c.seat_type," plan. To make changes, please contact your workspace ",u.some(e=>"owner"===e.role)?"owner":"administrator","."]}),(0,le.jsxs)("div",{className:"space-y-2",children:[u.filter(e=>"owner"===e.role).map((e,t)=>(0,le.jsxs)("p",{className:"text-sm text-slate-600",children:[(0,le.jsx)("span",{className:"font-medium",children:"Workspace owner:"})," ",e.email]},t)),u.filter(e=>"admin"===e.role).map((e,t)=>(0,le.jsxs)("p",{className:"text-sm text-slate-600",children:[(0,le.jsx)("span",{className:"font-medium",children:"Workspace admin:"})," ",e.email]},t))]})]})})}):(0,le.jsx)(is,{className:"border-slate-200",children:(0,le.jsx)(ms,{className:"pt-6 space-y-4",children:(0,le.jsxs)("div",{children:[(0,le.jsx)("h2",{className:"text-2xl font-semibold text-slate-900 mb-3",children:"Viewer Access"}),(0,le.jsxs)("p",{className:"text-slate-700 mb-4",children:["You currently have viewer access in this workspace. To get a seat with full access, please contact your workspace ",u.some(e=>"owner"===e.role)?"owner":"administrator","."]}),(0,le.jsxs)("div",{className:"space-y-2",children:[u.filter(e=>"owner"===e.role).map((e,t)=>(0,le.jsxs)("p",{className:"text-sm text-slate-600",children:[(0,le.jsx)("span",{className:"font-medium",children:"Workspace owner:"})," ",e.email]},t)),u.filter(e=>"admin"===e.role).map((e,t)=>(0,le.jsxs)("p",{className:"text-sm text-slate-600",children:[(0,le.jsx)("span",{className:"font-medium",children:"Workspace admin:"})," ",e.email]},t))]})]})})}),m&&(0,le.jsxs)(De,{className:"bg-teal-50 border-teal-200",children:[(0,le.jsx)(vc.A,{className:"h-4 w-4"}),(0,le.jsxs)(Be,{className:"text-teal-800",children:[(0,le.jsx)("strong",{children:"Administrator Access:"})," Visit the"," ",(0,le.jsx)("a",{href:"/workspace/".concat(d.id),className:"underline font-medium hover:text-teal-900",children:"workspace dashboard"})," ","to manage seats, billing, and team members."]})]})]})}var jc=s(15255);const yc="GTM-5WLCSX6J",Nc=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};window.dataLayer=window.dataLayer||[],window.dataLayer.push((0,K.A)({event:e,event_id:(0,jc.A)().toString()},t))};function wc(){const e=(0,Z.zy)();return(0,Y.useEffect)(()=>{!function(){if(document.getElementById("gtm-script"))return;const e=document.createElement("script");e.id="gtm-script",e.innerHTML="\n (function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':\n new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],\n j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=\n 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);\n })(window,document,'script','dataLayer','".concat(yc,"');\n "),document.head.prepend(e)}(),function(){if(document.getElementById("gtm-noscript"))return;const e=document.createElement("noscript");e.id="gtm-noscript",e.innerHTML='\n \n '),document.body.prepend(e)}()},[]),(0,Y.useEffect)(()=>{Nc("pageview",{page_path:e.pathname})},[e]),null}var _c=s(90386),kc=s.n(_c);function Cc(){return(0,le.jsxs)("div",{className:"bg-white rounded-[20px] p-6 flex flex-col h-[480px] border-2 border-[#E9E9E9] animate-pulse",children:[(0,le.jsxs)("div",{className:"mb-5",children:[(0,le.jsxs)("div",{className:"flex items-center justify-between mb-3",children:[(0,le.jsx)("div",{className:"h-5 bg-gray-200 rounded w-16"}),(0,le.jsx)("div",{className:"h-6 bg-gray-200 rounded w-20"})]}),(0,le.jsxs)("div",{className:"flex items-end mb-2",children:[(0,le.jsx)("div",{className:"h-8 bg-gray-200 rounded w-12"}),(0,le.jsx)("div",{className:"h-6 bg-gray-200 rounded w-16 ml-2"})]})]}),(0,le.jsx)("div",{className:"mb-4",children:(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsx)("div",{className:"h-4 bg-gray-200 rounded w-32"}),(0,le.jsx)("div",{className:"h-4 bg-gray-200 rounded w-28"})]})}),(0,le.jsx)("div",{className:"mb-4",children:(0,le.jsx)("div",{className:"h-10 bg-gray-200 rounded-[8px] w-full"})}),(0,le.jsxs)("div",{className:"space-y-2 flex-grow",children:[(0,le.jsx)("div",{className:"h-3 bg-gray-200 rounded w-full"}),(0,le.jsx)("div",{className:"h-3 bg-gray-200 rounded w-4/5"}),(0,le.jsx)("div",{className:"h-3 bg-gray-200 rounded w-3/4"}),(0,le.jsx)("div",{className:"h-3 bg-gray-200 rounded w-full"}),(0,le.jsx)("div",{className:"h-3 bg-gray-200 rounded w-2/3"}),(0,le.jsx)("div",{className:"h-3 bg-gray-200 rounded w-4/5"}),(0,le.jsx)("div",{className:"h-3 bg-gray-200 rounded w-1/2"})]})]})}const Ac=e=>{let{text:t,variant:s="default",disabled:a=!1,showX:n=!1,showGift:l=!1}=e;return(0,le.jsxs)("div",{className:"flex items-center text-sm ".concat(a?"text-gray-400":"text-gray-600"),children:[n?(0,le.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",className:"w-4 h-4 mr-3 flex-shrink-0 text-gray-500",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,le.jsx)("path",{d:"M18 6 6 18"}),(0,le.jsx)("path",{d:"m6 6 12 12"})]}):l?(0,le.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",className:"w-7 h-7 mr-3 flex-shrink-0 rounded-full p-1.5 ".concat(a?"text-gray-400":"text-teal-600"),style:{backgroundColor:"#F0FFE1"},width:"28",height:"28",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,le.jsx)("rect",{x:"3",y:"8",width:"18",height:"4",rx:"1"}),(0,le.jsx)("path",{d:"M12 8v13"}),(0,le.jsx)("path",{d:"M19 12v7a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2v-7"}),(0,le.jsx)("path",{d:"M7.5 8a2.5 2.5 0 0 1 0-5A4.8 8 0 0 1 12 8a4.8 8 0 0 1 4.5-5 2.5 2.5 0 0 1 0 5"})]}):(0,le.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",className:"w-4 h-4 mr-3 flex-shrink-0 ".concat(a?"text-gray-400":"text-teal-600"),width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,le.jsx)("path",{d:"M20 6L9 17l-5-5"})}),(0,le.jsx)("span",{className:"text-left font-light base44-font ".concat(a?"text-gray-400":"text-black"),children:t})]})};function Sc(e,t){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};try{var a;tt("Billing - Click",(0,K.A)({action:t},s)),ht({user_id:null!==(a=null==e?void 0:e.user_id)&&void 0!==a?a:null},(0,K.A)({cta:t,origin:s.origin||"BillingPage",target_route:"/billing"},s))}catch(n){}}const Ec=e=>{var t,s,a,n,l;let{planType:r,plan:i,allPlans:o,currentTier:c,stats:d,usage:m,onSubscribe:u,onUpgrade:x,onManageSubscription:h,upgrading:p,disabled:g=!1,billingPeriod:f="yearly"}=e;const[v,b]=(0,Y.useState)(!1),[j,y]=(0,Y.useState)(!1),[N,w]=(0,Y.useState)((()=>{if("elite"!==r)return"elite";const e=Mo(c);return["elite","elite_2","elite_3","elite_4"].includes(e)?e:"elite"})()),[_,k]=(0,Y.useState)(!1),[C,A]=(0,Y.useState)(!1),S="elite"===r,E=(()=>{if(!S)return i;const e="".concat(N,"_").concat(f),t=o.find(t=>{let[s]=t;return s===e});return t?t[1]:i})(),I=(null==E||null===(t=E.metadata)||void 0===t?void 0:t.monthly_message_limit)||0,T=(null==E||null===(s=E.metadata)||void 0===s?void 0:s.monthly_integration_credits)||0,P=Fo((null==E?void 0:E.nickname)||""),L=S?N:r,O=("active"===(null==d?void 0:d.subscription_status)||"past_due"===(null==d?void 0:d.subscription_status)||"incomplete"===(null==d?void 0:d.subscription_status))&&(null==d||null===(a=d.stripe_subscription)||void 0===a||null===(n=a.plan)||void 0===n?void 0:n.id)===E.id,R=function(e,t){const s=["free","starter","starter_yearly","builder","builder_yearly","pro","pro_yearly","elite","elite_yearly","elite_2","elite_2_yearly","elite_3","elite_3_yearly","elite_4","elite_4_yearly"],a=s.indexOf((null==e?void 0:e.toLowerCase())||""),n=s.indexOf((null==t?void 0:t.toLowerCase())||"");return n>a&&-1!==a&&-1!==n}(c,L),M=function(e,t){const s=["free","starter","starter_yearly","builder","builder_yearly","pro","pro_yearly","elite","elite_yearly","elite_2","elite_2_yearly","elite_3","elite_3_yearly","elite_4","elite_4_yearly"],a=s.indexOf((null==e?void 0:e.toLowerCase())||""),n=s.indexOf((null==t?void 0:t.toLowerCase())||"");return nMo(c).startsWith("elite"),z=(()=>{var e,t,s;if(!o)return(null==E||null===(e=E.metadata)||void 0===e?void 0:e.features)||"";const a=["starter","builder","pro"];let n=Mo(L);const l=n.startsWith("elite");l&&(n="pro");const r=a.indexOf(n);if(-1===r)return(null==E||null===(t=E.metadata)||void 0===t?void 0:t.features)||"";let i=[];for(let m=0;m<=r;m++){var c,d;const e=a[m],t="".concat(e,"_").concat(f),s=o.find(e=>{let[s,a]=e;return s===t});if(s&&null!==(c=s[1])&&void 0!==c&&null!==(d=c.metadata)&&void 0!==d&&d.features){const e=s[1].metadata.features.split(",").map(e=>e.trim()).filter(e=>e.length>0);i=[...i,...e]}}if(l&&null!=E&&null!==(s=E.metadata)&&void 0!==s&&s.features){const e=E.metadata.features.split(",").map(e=>e.trim()).filter(e=>e.length>0);i=[...i,...e]}return i.filter((e,t,s)=>t===s.findIndex(t=>t.toLowerCase()===e.toLowerCase())).join(",")})(),U=p?"Processing...":g?"Not Available":O?"Manage Payments":M?"Downgrade to ".concat(P):R&&!D?"Upgrade to ".concat(P):"Subscribe to ".concat(P),W=p||g,q=(0,Y.useCallback)(()=>{if(!S)return[];return["elite","elite_2","elite_3","elite_4"].map(e=>({value:e,label:"elite"===e?"Elite":"elite_2"===e?"Elite 2":"elite_3"===e?"Elite 3":"Elite 4"}))},[S]),V=(0,Y.useCallback)(()=>{const e=q();if(!c||"free"===c.toLowerCase())return e;return c&&!Ro(c)?e.filter(e=>function(e,t){if(!e||"free"===e.toLowerCase())return!0;if(Ro(e))return!0;const s=["starter","builder","pro","elite","elite_2","elite_3","elite_4"],a=Mo(e),n=Mo(t),l=s.indexOf(a);return s.indexOf(n)>=l}(c,Do(e.value))):e},[c,q]);(0,Y.useEffect)(()=>{if(S){const e=Mo(c);if(["elite","elite_2","elite_3","elite_4"].includes(e))w(e);else{const e=V();e.length>0&&!e.find(e=>e.value===N)&&w(e[0].value)}}},[c,S]);const H=E.unit_amount?"month"===(null===(l=E.recurring)||void 0===l?void 0:l.interval)?(E.unit_amount/100).toFixed(0):(E.unit_amount/100/12).toFixed(0):"0",G=(()=>{if(!F||!o)return null;const e=Do(Mo(c)),t=o.find(t=>{let[s]=t;return s===e});return t?t[1]:null})(),$=null!=G&&G.unit_amount?(G.unit_amount/100/12).toFixed(0):"0";return(0,le.jsx)(le.Fragment,{children:(0,le.jsxs)("div",{className:"relative h-full flex flex-col",children:[O&&(0,le.jsx)("div",{className:"absolute z-10 -top-[26px] left-1/4 -translate-x-1/2 px-3 py-1 bg-slate-700 text-white text-sm rounded-t-[12px]",children:"Current Plan"}),(0,le.jsxs)("div",{className:"bg-white rounded-[20px] p-6 flex flex-col transition-all duration-300 hover:shadow-xl min-h-[480px] h-full ".concat(O?"border-2 border-slate-700":"pro"!==r||g||B()?"border-2 border-[#E9E9E9]":"border-2 border-orange-300"),children:[(0,le.jsxs)("div",{className:"".concat(S?"mb-2":"mb-5"),children:[(0,le.jsxs)("div",{className:"flex items-center justify-between mb-3",children:[(0,le.jsx)("div",{className:"flex items-center gap-2",children:(0,le.jsx)("span",{className:"text-[18px] font-[400] ".concat(g?"text-gray-400":"text-gray-900"),children:P})}),"pro"===r&&!g&&!B()&&(0,le.jsx)("span",{className:"px-2 py-1 text-sm font-medium bg-[#FFE5DA] text-[#F16727] rounded-[6px]",children:"Recommended"})]}),(0,le.jsxs)("div",{className:"flex items-end mb-2",children:[(0,le.jsx)("span",{className:"text-3xl font-medium ".concat(g?"text-gray-400":"text-gray-900"),children:"$"}),(0,le.jsx)("span",{className:"text-3xl font-medium ".concat(g?"text-gray-400":"text-gray-900"),children:H}),(0,le.jsx)("span",{className:"font-thin ml-1 mb-1 text-[#C1C1C1] text-2xl",children:"/"}),(0,le.jsx)("span",{className:"font-normal mb-1 text-[#C1C1C1] text-[14px]",children:"mo"})]})]}),(0,le.jsx)("div",{className:"-mt-1 mb-2",children:S&&!g?(0,le.jsxs)(In,{value:N,onValueChange:e=>{Sc({user_id:null},"elite_tier_select",{origin:"PlanCard",billing_period:f,current_tier:c,selected_plan_type:r,selected_elite_tier:e,element_type:"dropdown"}),w(e)},children:[(0,le.jsx)(Pn,{advancedDropdown:!0,className:"w-full h-auto p-2 bg-white border border-gray-200",children:(0,le.jsx)("div",{className:"w-full text-left",children:(0,le.jsxs)("div",{className:"w-full flex flex-col gap-1",children:[(0,le.jsxs)("div",{className:"text-sm text-gray-900",children:[(0,le.jsx)("span",{className:"font-[500] inline-block min-w-[30px]",children:Oo(I)}),(0,le.jsx)("span",{className:"font-[400] text-[#5F5F5F]",children:"Monthly credits"})]}),(0,le.jsxs)("div",{className:"text-sm text-gray-900",children:[(0,le.jsx)("span",{className:"font-[500] inline-block min-w-[30px]",children:Oo(T)}),(0,le.jsx)("span",{className:"font-[400] text-[#5F5F5F]",children:"Integration credits"})]})]})})}),(0,le.jsx)(Rn,{className:"w-[calc(100%-1rem)] max-w-[320px] z-50 p-1.5",sideOffset:4,children:V().map(e=>{var t,s;const a="".concat(e.value,"_").concat(f),n=o.find(e=>{let[t]=e;return t===a}),l=n?n[1]:null,r=(null==l||null===(t=l.metadata)||void 0===t?void 0:t.monthly_message_limit)||0,i=(null==l||null===(s=l.metadata)||void 0===s?void 0:s.monthly_integration_credits)||0;return(0,le.jsx)(Mn,{value:e.value,className:"px-4 py-2 border-b border-gray-100 last:border-b-0",hideCheckIcon:!0,children:(0,le.jsxs)("div",{className:"w-full flex flex-col gap-1",children:[(0,le.jsxs)("div",{className:"text-sm leading-[17px] flex items-center gap-1.5 text-gray-900",children:[(0,le.jsx)("span",{className:"font-bold",children:Oo(r)}),(0,le.jsx)("span",{className:"text-gray-500",children:"monthly credits"})]}),(0,le.jsxs)("div",{className:"text-sm leading-[17px] flex items-center gap-1.5 text-gray-900",children:[(0,le.jsx)("span",{className:"font-bold",children:Oo(i)}),(0,le.jsx)("span",{className:"text-gray-500",children:"integration credits"})]})]})},e.value)})})]}):(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsxs)("div",{className:"text-sm ".concat(g?"text-gray-400":"text-gray-900"),children:[(0,le.jsx)("span",{className:"font-[500] inline-block min-w-[30px]",children:Oo(I)}),(0,le.jsx)("span",{className:"font-[400] text-[#5F5F5F]",children:"Monthly credits"})]}),(0,le.jsxs)("div",{className:"text-sm ".concat(g?"text-gray-400":"text-gray-900"),children:[(0,le.jsx)("span",{className:"font-[500] inline-block min-w-[30px]",children:Oo(T)}),(0,le.jsx)("span",{className:"font-[400] text-[#5F5F5F]",children:"Integration credits"})]})]})}),(0,le.jsx)("div",{className:"mb-4",children:(0,le.jsx)(pc,{billingAction:O?"manage_payments_click":M?"downgrade_click":R&&!D?"upgrade_click":"subscribe_click",ctaText:U,billingContext:{origin:"PlanCard",billing_period:f,current_tier:c,selected_plan_type:r,selected_elite_tier:S?N:void 0,price_id:E.id,subscription_status:(null==d?void 0:d.subscription_status)||null,target_route:O?"/stripe-portal":"/stripe-checkout",is_monthly_user:F,is_free_user:D,is_current_plan:O,can_upgrade:R,is_downgrade:M,is_elite_plan:S,monthly_usage:(null==m?void 0:m.monthly_usage)||0,daily_usage:(null==m?void 0:m.daily_usage)||0,monthly_limit:(null==m?void 0:m.monthly_limit)||0,daily_limit:(null==m?void 0:m.daily_limit)||0,extra_credits:(null==m?void 0:m.extra_credits)||0,is_over_limit:(null==m?void 0:m.is_over_limit)||!1,past_due:(null==m?void 0:m.past_due)||!1,monthly_messages:I,integration_credits:T,plan_display_name:P,button_text:U,button_disabled:W,plan_unit_amount:E.unit_amount,plan_currency:E.currency,organization_id:null==m?void 0:m.organization_id,product_id:null==d?void 0:d.product_id,current_credit_period_start_date:null==m?void 0:m.current_credit_period_start_date,current_credit_period_end_date:null==m?void 0:m.current_credit_period_end_date,next_period_start_date:null==m?void 0:m.next_period_start_date},onClick:()=>{if(!g&&!W)if(O)F?k(!0):h();else if(M)y(!0);else if(R&&!D)if(F){x(S?N:r)}else b(!0);else{u(S?N:r)}},className:"w-full py-2 text-[16px] font-medium transition-colors cursor-pointer rounded-[8px] ".concat(O?"bg-[#F4F4F5] py-2 text-[16px] font-medium shadow-sm hover:bg-gray-50 text-gray-700":g?"bg-gray-100 border border-gray-200 text-gray-400 cursor-not-allowed":"pro"!==r||B()?"bg-white border border-gray-300 hover:bg-[#F97316] text-black hover:text-white hover:border-white":"bg-[#F97316] hover:bg-[#000000] text-white"),disabled:W,children:U})}),(0,le.jsx)("div",{className:"space-y-1 flex-grow",children:null==z?void 0:z.split(",").map((e,t)=>(0,le.jsx)(Ac,{text:e.trim(),disabled:g,showGift:!1},t))})]}),(0,le.jsx)(tc,{open:v,onOpenChange:b,children:(0,le.jsxs)(lc,{className:"sm:max-w-md",children:[(0,le.jsxs)(rc,{children:[(0,le.jsx)(oc,{children:"Confirm Subscription Upgrade"}),(0,le.jsxs)(cc,{children:["You are about to upgrade to the ",P," plan for $",H,"/mo. Your subscription will be updated immediately and you'll be charged a prorated amount for the remainder of your billing cycle."]})]}),(0,le.jsxs)(ic,{className:"sm:justify-between",children:[(0,le.jsx)(pc,{billingAction:"dialog_cancel",ctaText:"Cancel",billingContext:{origin:"PlanCard",billing_period:f,current_tier:c,selected_plan_type:r,dialog_type:"upgrade"},onClick:()=>b(!1),variant:"outline",className:"text-sm",children:"Cancel"}),(0,le.jsx)(pc,{billingAction:"dialog_confirm",ctaText:p?"Processing...":"Confirm Upgrade",billingContext:{origin:"PlanCard",billing_period:f,current_tier:c,selected_plan_type:r,selected_elite_tier:S?N:void 0,dialog_type:"upgrade",price_id:E.id,target_route:"/stripe-checkout",is_monthly_user:F,is_free_user:D,can_upgrade:R,is_elite_plan:S,monthly_usage:(null==m?void 0:m.monthly_usage)||0,is_over_limit:(null==m?void 0:m.is_over_limit)||!1,plan_unit_amount:E.unit_amount},onClick:()=>{if(b(!1),F&&R&&!D){x(S?N:r)}else x(E.id)},disabled:p,className:"text-sm bg-teal-600 hover:bg-teal-700",children:p?"Processing...":"Confirm Upgrade"})]})]})}),(0,le.jsx)(tc,{open:j,onOpenChange:y,children:(0,le.jsxs)(lc,{className:"sm:max-w-md",children:[(0,le.jsxs)(rc,{children:[(0,le.jsx)(oc,{children:"Confirm Subscription Downgrade"}),(0,le.jsxs)(cc,{children:["You are about to downgrade to the ",P," plan for $",H,"/mo. This change will take effect at the end of your current billing cycle."]})]}),(0,le.jsxs)(ic,{className:"sm:justify-between",children:[(0,le.jsx)(pc,{billingAction:"dialog_cancel",ctaText:"Cancel",billingContext:{origin:"PlanCard",billing_period:f,current_tier:c,selected_plan_type:r,dialog_type:"downgrade"},onClick:()=>y(!1),variant:"outline",className:"text-sm",children:"Cancel"}),(0,le.jsx)(pc,{billingAction:"dialog_confirm",ctaText:"Confirm Downgrade",billingContext:{origin:"PlanCard",billing_period:f,current_tier:c,selected_plan_type:r,selected_elite_tier:S?N:void 0,dialog_type:"downgrade",price_id:E.id,target_route:"/stripe-checkout",is_monthly_user:F,is_downgrade:M,is_elite_plan:S,monthly_usage:(null==m?void 0:m.monthly_usage)||0,is_over_limit:(null==m?void 0:m.is_over_limit)||!1,plan_unit_amount:E.unit_amount},onClick:()=>{y(!1),x(E.id)},disabled:p,className:"text-sm bg-gray-500 hover:bg-gray-600",children:p?"Processing...":"Confirm Downgrade"})]})]})}),(0,le.jsx)(tc,{open:_,onOpenChange:k,children:(0,le.jsxs)(lc,{className:"sm:max-w-md",children:[(0,le.jsxs)(rc,{children:[(0,le.jsx)(oc,{children:"Manage Your Subscription"}),(0,le.jsxs)(cc,{children:["Choose how you'd like to manage your ",P," subscription."]})]}),(0,le.jsxs)("div",{className:"py-4 space-y-3",children:[(0,le.jsx)(pc,{billingAction:"upgrade_to_yearly_click",ctaText:"Upgrade to Yearly & Save",billingContext:{origin:"PlanCard",billing_period:f,current_tier:c,selected_plan_type:r,selected_elite_tier:S?N:void 0,dialog_type:"upgrade_to_yearly",target_route:"/billing-period-selector",is_monthly_user:F,is_current_plan:O,is_elite_plan:S,monthly_usage:(null==m?void 0:m.monthly_usage)||0,is_over_limit:(null==m?void 0:m.is_over_limit)||!1},onClick:()=>{k(!1),A(!0)},className:"w-full bg-teal-600 hover:bg-teal-700 text-white p-4 h-auto",disabled:!G,children:(0,le.jsxs)("div",{className:"text-left w-full",children:[(0,le.jsx)("div",{className:"font-medium",children:"Upgrade to Yearly"}),(0,le.jsx)("div",{className:"text-sm opacity-90 mt-1",children:"Save money and get a free domain + 25 credits to share!"})]})}),(0,le.jsx)(pc,{billingAction:"manage_payments_click",ctaText:"Manage Payments",billingContext:{origin:"PlanCard",billing_period:f,current_tier:c,selected_plan_type:r,selected_elite_tier:S?N:void 0,dialog_type:"manage_payments",target_route:"/stripe-portal",is_monthly_user:F,is_current_plan:O,is_elite_plan:S,subscription_status:(null==d?void 0:d.subscription_status)||null,monthly_usage:(null==m?void 0:m.monthly_usage)||0,is_over_limit:(null==m?void 0:m.is_over_limit)||!1,past_due:(null==m?void 0:m.past_due)||!1},onClick:()=>{k(!1),h()},variant:"outline",className:"w-full p-4 h-auto",children:(0,le.jsxs)("div",{className:"text-left w-full",children:[(0,le.jsx)("div",{className:"font-medium",children:"Manage Payments"}),(0,le.jsx)("div",{className:"text-sm text-gray-600 mt-1",children:"Update payment method, view invoices, and more"})]})})]})]})}),(0,le.jsx)(tc,{open:C,onOpenChange:A,children:(0,le.jsxs)(lc,{className:"sm:max-w-md",children:[(0,le.jsxs)(rc,{children:[(0,le.jsx)(oc,{children:"Confirm Subscription Upgrade"}),(0,le.jsxs)(cc,{children:["You are about to upgrade to the ",Fo((null==G?void 0:G.nickname)||"")," yearly plan for $",$,"/mo. Your subscription will be updated immediately and you'll be charged a prorated amount for the remainder of your billing cycle."]})]}),(0,le.jsx)("div",{className:"py-4",children:(0,le.jsxs)("div",{className:"bg-green-50 border border-green-200 rounded-lg p-4",children:[(0,le.jsx)("div",{className:"text-green-800 font-medium mb-2",children:"\u{1f381} Yearly Benefits"}),(0,le.jsxs)("ul",{className:"text-sm text-green-700 space-y-1",children:[(0,le.jsx)("li",{children:"\u2022 Get a free domain for a year"}),(0,le.jsx)("li",{children:"\u2022 25 credits to share with friends"}),(0,le.jsx)("li",{children:"\u2022 Better value with yearly pricing"})]})]})}),(0,le.jsxs)(ic,{className:"sm:justify-between",children:[(0,le.jsx)(pc,{billingAction:"dialog_cancel",ctaText:"Cancel",billingContext:{origin:"PlanCard",billing_period:f,current_tier:c,selected_plan_type:r,dialog_type:"upgrade_to_yearly"},onClick:()=>A(!1),variant:"outline",className:"text-sm",children:"Cancel"}),(0,le.jsx)(pc,{billingAction:"dialog_confirm",ctaText:"Confirm Upgrade",billingContext:{origin:"PlanCard",billing_period:f,current_tier:c,selected_plan_type:r,selected_elite_tier:S?N:void 0,dialog_type:"upgrade_to_yearly",price_id:(null==G?void 0:G.id)||null,target_route:"/stripe-checkout",is_monthly_user:F,is_current_plan:O,is_elite_plan:S,monthly_usage:(null==m?void 0:m.monthly_usage)||0,is_over_limit:(null==m?void 0:m.is_over_limit)||!1,plan_unit_amount:(null==G?void 0:G.unit_amount)||0},onClick:()=>{A(!1),G&&x(G.id)},disabled:p,className:"text-sm bg-teal-600 hover:bg-teal-700",children:p?"Processing...":"Confirm Upgrade"})]})]})})]})})},Ic=["className"],Tc=["className"],Pc=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,Ic);return(0,le.jsx)(ws.bL,(0,K.A)((0,K.A)({className:Pe("grid gap-2",s)},a),{},{ref:t}))});Pc.displayName=ws.bL.displayName;const Lc=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,Tc);return(0,le.jsx)(ws.q7,(0,K.A)((0,K.A)({ref:t,className:Pe("aspect-square h-4 w-4 rounded-full border border-primary text-primary ring-offset-background focus:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",s)},a),{},{children:(0,le.jsx)(ws.C1,{className:"flex items-center justify-center",children:(0,le.jsx)(_s.A,{className:"h-2.5 w-2.5 fill-current text-current"})})}))});Lc.displayName=ws.q7.displayName;var Oc=s(24082);const Rc=Oc.bL,Mc=Y.forwardRef((e,t)=>{let s=Object.assign({},((0,Ja.A)(e),e));return(0,le.jsx)(Oc.R6,(0,K.A)({ref:t},s))});Mc.displayName=Oc.R6.displayName;const Dc=Y.forwardRef((e,t)=>{let s=Object.assign({},((0,Ja.A)(e),e));return(0,le.jsx)(Oc.Ke,(0,K.A)({ref:t},s))});Dc.displayName=Oc.Ke.displayName;const Fc=e=>{var t,s;let{period:a,plan:n,monthlyPlan:l,features:r,isSelected:i,isExpanded:o,onSelect:c,onExpansionToggle:d,onYearlySelect:m,disabled:u=!1,userId:x}=e;const h=(null==n||null===(t=n.metadata)||void 0===t?void 0:t.monthly_message_limit)||0,p=(null==n||null===(s=n.metadata)||void 0===s?void 0:s.monthly_integration_credits)||0,g=(null==n?void 0:n.nickname)||"",f=Fo(g),v=g.toLowerCase().includes("starter");let b,j;"yearly"===a?(b=(n.unit_amount/100/12).toFixed(0),j=" x 12 months"):(b=n.unit_amount?(n.unit_amount/100).toFixed(0):"0",j=" / every month");const y="yearly"===a?"Yearly":"Monthly",N=(()=>{if("yearly"!==a||null==l||!l.unit_amount||null==n||!n.unit_amount)return 0;const e=12*l.unit_amount-n.unit_amount;return Math.round(e/100)})();return(0,le.jsx)(Rc,{open:o,onOpenChange:()=>{Sc({user_id:x||null},o?"plan_collapse":"plan_expand",(0,K.A)((0,K.A)({origin:"CollapsiblePlanOption"},"header"!==a&&{billing_period:a}),{},{selected_plan_type:f.toLowerCase(),expansion_state:o?"collapsed":"expanded",element_type:"toggle"})),d()},onClick:()=>{Sc({user_id:x||null},"select_period",(0,K.A)((0,K.A)({origin:"CollapsiblePlanOption"},"header"!==a&&{billing_period:a}),{},{selected_plan_type:f.toLowerCase(),element_type:"radio"})),c()},children:(0,le.jsxs)("div",{className:"font-base44 bg-white cursor-pointer rounded-[12px] ".concat(i?"border border-black":"border border-transparent"," ").concat(i?"":"hover:bg-gray-50"," ").concat(u?"text-gray-200":""," ").concat("yearly"===a?"mb-4":""," transition-all duration-200"),children:[(0,le.jsxs)("div",{className:"flex items-center justify-between p-4 sm:p-6",children:[(0,le.jsxs)("div",{className:"flex items-center space-x-3 sm:space-x-4 flex-1 cursor-pointer",children:[(0,le.jsx)(Lc,{value:a,id:a,className:i?"border-black text-black":""}),(0,le.jsx)("div",{className:"text-left flex-1 min-w-0",children:(0,le.jsxs)("label",{htmlFor:a,className:"text-base sm:text-lg flex flex-col sm:flex-row sm:items-center gap-1 sm:gap-3 ".concat(u?"text-gray-400":"text-gray-900"),children:[(0,le.jsx)("span",{className:"font-bold",children:y}),(0,le.jsx)("span",{className:"hidden sm:block h-px w-4 bg-gray-300"}),(0,le.jsxs)("span",{className:"font-normal text-sm sm:text-base",children:["$",b,j]})]})})]}),(0,le.jsxs)("div",{className:"flex items-center space-x-2 sm:space-x-3 flex-shrink-0",children:["yearly"===a&&N>0&&(0,le.jsxs)("span",{className:"px-2 sm:px-4 py-1 text-xs sm:text-sm font-bold ".concat(i?"bg-[#F0FFE1]":""," text-[#00A184] rounded-lg border border-[#00A184]"),children:["SAVE $",N]}),(0,le.jsx)(Mc,{asChild:!0,children:(0,le.jsx)("button",{className:"p-1 hover:bg-gray-100 rounded",children:o?(0,le.jsx)(Ts.A,{className:"h-5 w-5 text-gray-400"}):(0,le.jsx)(Is.A,{className:"h-5 w-5 text-gray-400"})})})]})]}),(0,le.jsx)(Dc,{children:(0,le.jsxs)("div",{className:"px-4 sm:px-6 pb-4 sm:pb-6",children:[(0,le.jsx)("div",{className:"border-t border-gray-200"}),(0,le.jsx)("div",{className:"mt-4 mb-6",children:(0,le.jsxs)("div",{className:"flex gap-3",children:[(0,le.jsxs)("div",{className:"text-sm flex items-center gap-2 ".concat(u?"text-gray-400":"text-gray-900 bg-slate-100 px-4 py-2 rounded-lg w-fit"),children:[(0,le.jsx)("span",{className:"font-bold",children:Oo(h)}),(0,le.jsx)("span",{className:"text-black",children:"Monthly credits"})]}),(0,le.jsxs)("div",{className:"text-sm flex items-center gap-2 ".concat(u?"text-gray-400":"text-gray-900 bg-slate-100 px-4 py-2 rounded-lg w-fit"),children:[(0,le.jsx)("span",{className:"font-semibold",children:Oo(p)}),(0,le.jsx)("span",{className:"text-black",children:"Integration credits"})]})]})}),!v&&(0,le.jsxs)("div",{className:"mb-4 ".concat("monthly"===a?"bg-slate-50 p-3 sm:p-4 rounded-lg border border-gray-200":""),children:[(0,le.jsx)("h4",{className:"text-sm font-bold mb-3",children:"monthly"===a?"NOTE: Monthly subscription doesn't include:":"What's included with the ".concat(a," plan")}),(0,le.jsx)("div",{className:"space-y-2",children:!v&&("yearly"===a||"monthly"===a)&&{yearly:["Enjoy a special discount and save money","Get a free domain for 1 year","Receive 25 credits to share with a friend"],monthly:["Special discount and savings","Free domain for 1 year","25 credits to share with a friend"]}[a].map((e,t)=>(0,le.jsx)(Ac,{text:e,disabled:u,showX:"monthly"===a,showGift:"yearly"===a},"additional-".concat(t)))}),"monthly"===a&&(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)("div",{className:"border-t border-gray-200 mt-4"}),(0,le.jsxs)("p",{className:"mt-4 text-sm",children:["Choose a ",(0,le.jsx)("span",{className:"text-blue-500 cursor-pointer hover:underline",onClick:()=>{null==m||m()},children:"yearly"})," subscription to get the most from your premium plan"]})]})]})]})})]})})},Bc=e=>{var t;let{selectedPlanType:s,stats:a,onSubscribe:n,onBack:l,selectedEliteTier:r,isUpgradeFlow:i=!1,onUpgrade:o,userId:c}=e;const[d,m]=(0,Y.useState)("yearly"),[u,x]=(0,Y.useState)("yearly"),[h,p]=(0,Y.useState)(!1),[g,f]=(0,Y.useState)(!1),v=r||s,b=a.pricing.monthly[v],j=a.pricing.yearly[v];if(!b||!j)return(0,le.jsxs)("div",{className:"text-center py-8 px-4",children:[(0,le.jsx)("p",{className:"text-gray-500",children:"Plan not found. Please try again."}),(0,le.jsx)(pc,{billingAction:"back_to_plans",ctaText:"Back",billingContext:{origin:"BillingPeriodSelector",selected_plan_type:v},onClick:l,variant:"outline",className:"mt-4",children:"Go Back"})]});const y=e=>{var t;return(null==e||null===(t=e.metadata)||void 0===t?void 0:t.features)||""},N=e=>{m(e),x(e),Sc({user_id:c},"select_period",{origin:"BillingPeriodSelector",billing_period:e,selected_plan_type:v})},w=e=>{x(u===e?null:e)};return(0,le.jsxs)("div",{className:"max-w-6xl mx-auto px-4 sm:px-6 lg:px-8",children:[(0,le.jsx)("div",{className:"rounded-lg",children:(0,le.jsxs)(Pc,{value:d,onValueChange:N,className:"gap-0",children:[(0,le.jsx)(Fc,{period:"yearly",plan:j,monthlyPlan:b,features:y(j),isSelected:"yearly"===d,isExpanded:"yearly"===u,onSelect:()=>N("yearly"),onExpansionToggle:()=>w("yearly"),userId:c}),(0,le.jsx)(Fc,{period:"monthly",plan:b,monthlyPlan:b,features:y(b),isSelected:"monthly"===d,isExpanded:"monthly"===u,onSelect:()=>N("monthly"),onExpansionToggle:()=>w("monthly"),onYearlySelect:()=>N("yearly"),userId:c})]})}),(0,le.jsx)("div",{className:"mt-6 flex justify-center sm:justify-end px-4 sm:px-0",children:(0,le.jsx)(pc,{billingAction:i?"upgrade_click":"continue_checkout",ctaText:i?"Confirm Subscription Upgrade":"Continue to Checkout",billingContext:{origin:"BillingPeriodSelector",billing_period:d,selected_plan_type:v,selected_elite_tier:r,price_id:("yearly"===d?j:b).id,is_upgrade_flow:i,target_route:"/stripe-checkout",current_tier:(null==a?void 0:a.tier)||"",subscription_status:(null==a?void 0:a.subscription_status)||null,monthly_usage:(null==a?void 0:a.monthly_usage)||0,daily_usage:(null==a?void 0:a.daily_usage)||0,monthly_limit:(null==a?void 0:a.monthly_limit)||0,daily_limit:(null==a?void 0:a.daily_limit)||0,is_over_limit:(null==a?void 0:a.is_over_limit)||!1,past_due:(null==a?void 0:a.past_due)||!1,plan_unit_amount:("yearly"===d?j:b).unit_amount,plan_currency:("yearly"===d?j:b).currency,organization_id:null==a?void 0:a.organization_id,user_email:null==a?void 0:a.user_email,product_id:null==a?void 0:a.product_id},onClick:()=>{if(i)p(!0);else{n(("yearly"===d?j:b).id)}},className:"w-full sm:w-auto px-6 py-4 text-md font-normal bg-black hover:bg-orange-600 text-white rounded-lg",disabled:g,children:i?"Confirm Subscription Upgrade":"Continue to Checkout"})}),i&&(0,le.jsx)(tc,{open:h,onOpenChange:p,children:(0,le.jsxs)(lc,{className:"sm:max-w-md",children:[(0,le.jsxs)(rc,{children:[(0,le.jsx)(oc,{children:"Confirm Subscription Upgrade"}),(0,le.jsxs)(cc,{children:["You are about to upgrade to the ",Fo((null===(t="yearly"===d?j:b)||void 0===t?void 0:t.nickname)||"")," plan for $",(_="yearly"===d?j:b,null!=_&&_.unit_amount?"month"===(null===(k=_.recurring)||void 0===k?void 0:k.interval)?(_.unit_amount/100).toFixed(0):(_.unit_amount/100/12).toFixed(0):"0"),"/mo. Your subscription will be updated immediately and you'll be charged a prorated amount for the remainder of your billing cycle."]})]}),(0,le.jsxs)(ic,{className:"sm:justify-between",children:[(0,le.jsx)(pc,{billingAction:"dialog_cancel",ctaText:"Cancel",billingContext:{origin:"BillingPeriodSelector",billing_period:d,selected_plan_type:v,dialog_type:"upgrade",is_upgrade_flow:!0},onClick:()=>p(!1),variant:"outline",disabled:g,className:"text-sm",children:"Cancel"}),(0,le.jsx)(pc,{billingAction:"dialog_confirm",ctaText:"Confirm Upgrade",billingContext:{origin:"BillingPeriodSelector",billing_period:d,selected_plan_type:v,selected_elite_tier:r,dialog_type:"upgrade",price_id:("yearly"===d?j:b).id,is_upgrade_flow:!0,target_route:"/stripe-checkout",current_tier:(null==a?void 0:a.tier)||"",subscription_status:(null==a?void 0:a.subscription_status)||null,monthly_usage:(null==a?void 0:a.monthly_usage)||0,is_over_limit:(null==a?void 0:a.is_over_limit)||!1,plan_unit_amount:("yearly"===d?j:b).unit_amount},onClick:async()=>{if(o){f(!0);try{const e="yearly"===d?j:b;await o(e.id),p(!1)}catch(e){}finally{f(!1)}}},disabled:g,className:"text-sm bg-teal-600 hover:bg-teal-700",children:g?"Processing...":"Confirm Upgrade"})]})]})})]});var _,k},zc=e=>{let{isOpen:t,onClose:s}=e;const a=(0,Y.useRef)(null),n=(0,Y.useRef)(null);(0,Y.useEffect)(()=>{if(t){if(window.hbspt)l();else{const e=document.createElement("script");e.src="//js-eu1.hsforms.net/forms/embed/v2.js",e.charset="utf-8",e.type="text/javascript",document.head.appendChild(e),e.onload=()=>{l()}}const e=document.createElement("style");return e.textContent='\n .hs-form-field {\n margin-bottom: 1rem;\n }\n .hs-form-field label {\n font-size: 0.875rem;\n font-weight: 500;\n color: #374151;\n margin-bottom: 0.5rem;\n display: block;\n }\n .hs-form-field input,\n .hs-form-field textarea {\n width: 100%;\n padding: 0.75rem;\n border: 1px solid #d1d5db;\n border-radius: 0.5rem;\n font-size: 0.875rem;\n transition: border-color 0.2s;\n }\n .hs-form-field input:focus,\n .hs-form-field textarea:focus {\n outline: none;\n border-color: #3b82f6;\n box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);\n }\n .hs-form-field textarea {\n min-height: 100px;\n resize: vertical;\n }\n .hs-error-msgs {\n color: #dc2626;\n font-size: 0.75rem;\n margin-top: 0.25rem;\n }\n .hs-button {\n background-color: #1f2937;\n color: white;\n padding: 0.75rem 1.5rem;\n border: none;\n border-radius: 0.5rem;\n font-weight: 500;\n cursor: pointer;\n transition: background-color 0.2s;\n width: 100%;\n margin-top: 1rem;\n }\n .hs-button:hover {\n background-color: #111827;\n }\n .hs-form {\n margin-top: 1rem;\n }\n .hs-form .hs-form-field {\n display: inline-block;\n width: calc(50% - 0.5rem);\n margin-right: 1rem;\n }\n .hs-form .hs-form-field:nth-child(even) {\n margin-right: 0;\n }\n .hs-form .hs-form-field:last-child,\n .hs-form .hs-form-field:nth-last-child(2) {\n width: 100%;\n margin-right: 0;\n }\n @media (max-width: 640px) {\n .hs-form .hs-form-field {\n width: 100%;\n margin-right: 0;\n }\n }\n \n /* Success message styling with Base44 colors */\n .hs-form .hs-error-msgs,\n .hs-form .hs-error-msgs label {\n display: none !important;\n }\n \n .success-message {\n text-align: center;\n padding: 3rem 2rem;\n background: linear-gradient(135deg, #fef7ed 0%, #fef3e2 100%);\n border-radius: 1rem;\n margin: 1rem 0;\n border: 1px solid #fed7aa;\n position: relative;\n overflow: hidden;\n }\n \n .success-message::before {\n content: "";\n position: absolute;\n top: 0;\n left: 0;\n right: 0;\n height: 4px;\n background: linear-gradient(90deg, #f97316, #ea580c);\n }\n \n .success-icon {\n display: flex;\n align-items: center;\n justify-content: center;\n width: 4rem;\n height: 4rem;\n background: #f97316;\n color: white;\n border-radius: 50%;\n margin: 0 auto 1.5rem;\n box-shadow: 0 4px 12px rgba(249, 115, 22, 0.3);\n }\n \n .success-title {\n color: #9a3412;\n font-size: 1.5rem;\n font-weight: 700;\n margin: 0 0 0.75rem 0;\n line-height: 1.2;\n }\n \n .success-description {\n color: #c2410c;\n font-size: 1rem;\n margin: 0;\n line-height: 1.6;\n max-width: 400px;\n margin: 0 auto;\n }\n \n .success-decoration {\n position: absolute;\n top: -10px;\n right: -10px;\n width: 60px;\n height: 60px;\n background: rgba(249, 115, 22, 0.1);\n border-radius: 50%;\n }\n \n .success-decoration:nth-child(2) {\n bottom: -10px;\n left: -10px;\n width: 40px;\n height: 40px;\n background: rgba(249, 115, 22, 0.05);\n }\n \n .base44-logo {\n width: 2rem;\n height: 2rem;\n margin: 0 auto 1rem;\n }\n ',document.head.appendChild(e),()=>{const e=document.querySelector("style[data-hubspot-modal]");e&&e.remove()}}},[t]);const l=()=>{window.hbspt&&n.current&&window.hbspt.forms.create({portalId:"146561033",formId:"6c32b630-0d03-43da-948e-3808a34bbeff",region:"eu1",target:"#hubspot-form-container",onFormSubmitted:function(e){const t=document.getElementById("hubspot-form-container");t&&(t.innerHTML='\n
\n
\n
\n
\n \n \n \n \n
\n

Thank you for reaching out!

\n

We\'ve received your message and our team will get back to you within 24 hours. We\'re excited to help you with your Base44 journey!

\n
\n ')}})};return t?(0,le.jsx)("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 p-4",children:(0,le.jsxs)("div",{ref:a,className:"bg-white rounded-xl shadow-xl max-w-lg w-full max-h-[90vh] overflow-y-auto",children:[(0,le.jsxs)("div",{className:"flex items-center justify-between p-6 border-b border-slate-100",children:[(0,le.jsxs)("div",{children:[(0,le.jsx)("h2",{className:"text-2xl font-bold text-slate-900",children:"Let's talk"}),(0,le.jsx)("p",{className:"text-slate-600 mt-1",children:"Connect with our team to see how Base44 can help your organization."})]}),(0,le.jsx)(Yt,{variant:"ghost",size:"sm",onClick:s,className:"h-8 w-8 p-0 hover:bg-slate-100 rounded-full",children:(0,le.jsx)(Bt.A,{className:"h-4 w-4"})})]}),(0,le.jsx)("div",{className:"p-6",children:(0,le.jsx)("div",{id:"hubspot-form-container",ref:n})})]})}):null};var Uc=s(55510),Wc=s(63997),qc=s(16243);const Vc=e=>{let{icon:t,title:s,description:a}=e;return(0,le.jsxs)("div",{className:"flex flex-col items-start gap-2",children:[(0,le.jsx)("div",{className:"w-5 h-5 flex items-center justify-center flex-shrink-0",children:t}),(0,le.jsxs)("div",{children:[(0,le.jsx)("h4",{className:"text-white font-bold mb-1 text-sm",children:s}),(0,le.jsx)("p",{className:"text-white font-normal text-sm",children:a})]})]})},Hc=()=>{const[e,t]=(0,Y.useState)(!1);return(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)("div",{className:"mt-8 max-w-full mx-auto px-4",children:(0,le.jsx)("div",{className:"bg-gradient-to-tl from-[#FE7F48] via-slate-800 to-slate-800 rounded-[20px] px-12 py-8 text-white",children:(0,le.jsxs)("div",{className:"flex flex-col lg:flex-row items-center gap-14",children:[(0,le.jsxs)("div",{className:"flex-[2] flex flex-col justify-center items-start",children:[(0,le.jsx)("h3",{className:"text-[24px] font-bold mb-2",children:"Base44 for Enterprise"}),(0,le.jsx)("p",{className:"text-white mb-6 font-light",children:"Empower large organizations to build solutions that fit their teams perfectly, safely and at scale"}),(0,le.jsx)(pc,{billingAction:"enterprise_contact",ctaText:"Contact Us",billingContext:{origin:"EnterpriseCard"},onClick:()=>t(!0),className:"bg-transparent text-white hover:bg-white hover:text-slate-800 font-medium px-8 py-3 border border-white hover:border-white rounded-lg transition-colors text-base",children:"Contact Us"})]}),(0,le.jsx)("div",{className:"flex-[3]",children:(0,le.jsxs)("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-14 w-full",children:[(0,le.jsx)(Vc,{icon:(0,le.jsx)(er.A,{className:"w-5 h-5 text-orange-400"}),title:"Onboarding & Training",description:"Tailored onboarding plans combined with live training and resources, designed to help admins and end users adopt quickly."}),(0,le.jsx)(Vc,{icon:(0,le.jsx)(Uc.A,{className:"w-5 h-5 text-orange-400"}),title:"Dedicated account Team",description:"Work with a named account manager and solution engineer, providing direct guidance, escalations, and roadmap alignment."}),(0,le.jsx)(Vc,{icon:(0,le.jsx)(Wc.A,{className:"w-5 h-5 text-orange-400"}),title:"Priority support, guaranteed",description:"Get guaranteed priority assistance and defined response times from a dedicated support channel."}),(0,le.jsx)(Vc,{icon:(0,le.jsx)(qc.A,{className:"w-5 h-5 text-orange-400"}),title:"Enterprise-Grade Capabilities",description:"Security, compliance, management, and monitoring features - providing the control and flexibility required at scale."})]})})]})})}),(0,le.jsx)(zc,{isOpen:e,onClose:()=>t(!1)})]})};var Yc=s(37358),Gc=s(53270);const $c=()=>(0,le.jsx)("div",{className:"mt-6 mb-2 flex items-center justify-center",children:(0,le.jsxs)("div",{className:"flex items-center justify-center gap-6 flex-wrap",children:[(0,le.jsx)("span",{style:{color:"#000624"},className:"text-sm font-normal leading-normal",children:"Base44 benefits:"}),(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[(0,le.jsx)(Yc.A,{size:16,style:{color:"#000624"}}),(0,le.jsx)("span",{style:{color:"#000624"},className:"text-sm font-medium leading-normal",children:"Responsive visual editor"})]}),(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[(0,le.jsx)(Gc.A,{size:16,style:{color:"#000624"}}),(0,le.jsx)("span",{style:{color:"#000624"},className:"text-sm font-medium leading-normal",children:"Built-in backend"})]}),(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[(0,le.jsx)(Xl.A,{size:16,style:{color:"#000624"}}),(0,le.jsx)("span",{style:{color:"#000624"},className:"text-sm font-medium leading-normal",children:"User management"})]})]})});var Jc=s(1323);const Zc=e=>{let{type:t,title:s,message:a,subMessage:n,buttonText:l,loadingText:r,onButtonClick:i,handleManageSubscription:o,isLoading:c}=e;const d="cancellation"===t?{container:"bg-gradient-to-r from-orange-50 to-orange-50/80 border-orange-200/60 shadow-sm",icon:"text-orange-500",title:"text-orange-900 font-semibold",description:"text-orange-800",subText:"text-orange-600",button:"bg-orange-100 border-orange-200 text-orange-800 hover:bg-orange-200 hover:border-orange-300 transition-all duration-200 font-medium shadow-sm"}:{container:"bg-gradient-to-r from-slate-50 to-slate-50/80 border-slate-200/60 shadow-sm",icon:"text-slate-500",title:"text-slate-900 font-semibold",description:"text-slate-700",subText:"text-slate-600",button:"bg-slate-100 border-slate-200 text-slate-800 hover:bg-slate-200 hover:border-slate-300 transition-all duration-200 font-medium shadow-sm"};return(0,le.jsx)(De,{className:"mb-3 ".concat(d.container," rounded-xl border p-4"),children:(0,le.jsxs)("div",{className:"flex items-start gap-3",children:[(0,le.jsx)(Jc._TA,{className:"h-4 w-4 ".concat(d.icon," mt-0.5 flex-shrink-0")}),(0,le.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,le.jsx)(Fe,{className:"".concat(d.title," text-sm mb-1 leading-tight"),children:s}),(0,le.jsxs)(Be,{className:"".concat(d.description," text-sm leading-relaxed"),children:[(0,le.jsx)("div",{className:"mb-1",children:a}),n&&(0,le.jsx)("div",{className:"text-xs ".concat(d.subText," leading-relaxed"),children:n})]})]}),l&&(0,le.jsx)("div",{className:"flex-shrink-0",children:(0,le.jsx)(pc,{billingAction:"subscription_notice_action",ctaText:l,billingContext:{notice_type:t},variant:"outline",size:"sm",className:"text-xs px-3 py-1.5 h-auto rounded-lg ".concat(d.button),onClick:()=>{"cancellation"===t?null==o||o():null==i||i()},disabled:c,children:c?r:l})})]})})};var Kc=s(97202);const Qc=()=>(0,le.jsxs)("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-3 lg:gap-4 max-w-full mx-auto px-4",children:[(0,le.jsx)(Cc,{}),(0,le.jsx)(Cc,{}),(0,le.jsx)(Cc,{}),(0,le.jsx)(Cc,{})]}),Xc=()=>{var e;const{toast:t}=nn(),{user:s}=oe(),{activeWorkspace:a}=ge(),n=(0,Y.useRef)(null),[l,r]=(0,Y.useState)("billing"),[i,o]=(0,Y.useState)("yearly"),[c,d]=(0,Y.useState)(""),[m,u]=(0,Y.useState)(!1),[x,h]=(0,Y.useState)(null),[p,g]=(0,Y.useState)(null),[f,v]=(0,Y.useState)(!0),[b,j]=(0,Y.useState)(!1),[y,N]=(0,Y.useState)(""),[w,_]=(0,Y.useState)(""),[k,C]=(0,Y.useState)(!1),[A,S]=(0,Y.useState)(""),[E,I]=(0,Y.useState)(!1),[T,P]=(0,Y.useState)(!1),L=a&&!a.is_personal;(0,Y.useEffect)(()=>{const e=(null==a?void 0:a.id)||null;null!==n.current&&n.current!==e&&(h(null),g(null),v(!0),r("billing"),o("monthly"),d(""),u(!1),j(!1),N(""),_(""),C(!1)),n.current=e},[null==a?void 0:a.id]),(0,Y.useEffect)(()=>{if(L)return;(async()=>{try{v(!0);const[e,t]=await Promise.all([ke.default.getCurrentUsage(),ke.default.getStats()]);h(e),g(t);const s=e;if(null!=s&&s.tier)if("free"===s.tier.toLowerCase())o("yearly");else{const e=s.tier.toLowerCase().includes("_yearly");o(e?"yearly":"monthly")}}catch(e){}finally{v(!1)}})()},[L]),(0,Y.useEffect)(()=>{if(s){"true"===new URLSearchParams(window.location.search).get("success")&&s.email&&(tt("Billing - Purchase",{}),Nc("Purchase",{email:(0,_c.sha256)(s.email),price:20,user_id:s.id}))}},[s]),(0,Y.useEffect)(()=>{s&&!L&&(tt("Package Picker",{}),Nc("package_picker",{user_id:s.id,email:(0,_c.sha256)(s.email)}))},[s,L]);const O=async e=>{const a=["starter","builder","pro","elite"].includes(e),n=["elite","elite_2","elite_3","elite_4"].includes(e);if(a||n)return Sc({user_id:(null==s?void 0:s.id)||null},"select_plan",{origin:"BillingPage",view:l,is_workspace_context:!!L,billing_period:i,current_tier:(null==x?void 0:x.tier)||"",subscription_status:(null==p?void 0:p.subscription_status)||null,selected_plan_type:n?"elite":e,selected_elite_tier:n?e:void 0}),N(a?e:"elite"),_(n?e:""),void j(!0);try{Sc({user_id:(null==s?void 0:s.id)||null},"continue_checkout",{origin:"BillingPage",view:l,is_workspace_context:!!L,billing_period:i,current_tier:(null==x?void 0:x.tier)||"",subscription_status:(null==p?void 0:p.subscription_status)||null,price_id:e}),tt("Hit Subscribe",{}),Nc("checkout_initiated",{email:(0,_c.sha256)(s.email),price:20,user_id:s.id});const t=await $o.createCheckoutSession(e),{sessionId:a}=t,n=null==p?void 0:p.publishable_key;if(!n)throw new Error("Stripe publishable key not available");const r=await(0,Kc.loadStripe)(n);await r.redirectToCheckout({sessionId:a})}catch(r){t({variant:"destructive",title:"Error",description:"Failed to create checkout session. Please try again later."})}},R=()=>{Sc({user_id:(null==s?void 0:s.id)||null},"back_to_plans",{origin:"BillingPage",view:l,is_workspace_context:!!L}),j(!1),N(""),_(""),C(!1)},M=async e=>{try{var a;Sc({user_id:(null==s?void 0:s.id)||null},"upgrade_click",{origin:"BillingPage",view:l,is_workspace_context:!!L,billing_period:i,current_tier:(null==x?void 0:x.tier)||"",subscription_status:(null==p?void 0:p.subscription_status)||null,price_id:e});const n=null===(a=(await $o.updateSubscription(e)).subscription)||void 0===a?void 0:a.is_downgrade;t({title:"Subscription Updated",description:n?"Your subscription has been scheduled to downgrade at the end of your billing cycle.":"Your subscription has been upgraded successfully. Changes will be reflected shortly."}),setTimeout(()=>{window.location.reload()},2e3)}catch(r){var n;t({variant:"destructive",title:"Error",description:(null===(n=r.response)||void 0===n?void 0:n.detail)||"Failed to update subscription. Please try again later."})}},D=async e=>{const t=["elite","elite_2","elite_3","elite_4"];if((["starter","builder","pro","elite"].includes(e)||t.includes(e))&&"monthly"===i)return Sc({user_id:(null==s?void 0:s.id)||null},"upgrade_click",{origin:"BillingPage",view:l,is_workspace_context:!!L,billing_period:i,current_tier:(null==x?void 0:x.tier)||"",subscription_status:(null==p?void 0:p.subscription_status)||null,selected_plan_type:t.includes(e)?"elite":e,selected_elite_tier:t.includes(e)?e:void 0}),N(t.includes(e)?"elite":e),t.includes(e)?_(e):_(""),C(!0),void j(!0);await M(e)},F=async()=>{try{Sc({user_id:(null==s?void 0:s.id)||null},"manage_payments_click",{origin:"BillingPage",view:l,is_workspace_context:!!L,billing_period:i,current_tier:(null==x?void 0:x.tier)||"",subscription_status:(null==p?void 0:p.subscription_status)||null});const e=await $o.createPortalSession();window.open(e.url,"_blank")}catch(e){t({variant:"destructive",title:"Error",description:"Failed to open subscription management. Please try again later."})}},B=null==s?void 0:s.subscription_schedule_id,z=!0===(null==p||null===(e=p.stripe_subscription)||void 0===e?void 0:e.cancel_at_period_end),U=()=>{if(null==p||!p.pricing)return[];const e=[];return Object.entries(p.pricing.monthly).forEach(t=>{let[s,a]=t;e.push(["".concat(s,"_monthly"),a])}),Object.entries(p.pricing.yearly).forEach(t=>{let[s,a]=t;e.push(["".concat(s,"_yearly"),a])}),e};return(0,le.jsxs)("div",{className:"container mx-auto px-2 sm:px-6 lg:px-6 py-6 sm:py-8 min-h-screen flex flex-col font-base44",children:[!L&&!f&&(null==x?void 0:x.past_due)&&(0,le.jsxs)("div",{className:"mb-6 p-4 bg-red-50 border border-red-200 rounded-md text-red-800",children:[(0,le.jsxs)("div",{className:"flex items-center justify-between",children:[(0,le.jsxs)("div",{className:"flex items-center",children:[(0,le.jsx)(we.A,{className:"h-5 w-5 mr-2 flex-shrink-0"}),(0,le.jsx)("span",{className:"font-medium",children:"Subscription payment overdue"})]}),(0,le.jsx)(pc,{billingAction:"payment_overdue_update",ctaText:"Update Payment Method",billingContext:{origin:"BillingPage",view:l,is_workspace_context:!!L,notice_type:"overdue",target_route:"/stripe-portal"},onClick:async()=>{try{const e="payment_method_update",t=await $o.createPortalSession(e);window.location.href=t.url}catch(e){t({variant:"destructive",title:"Error",description:"Failed to open payment management. Please try again."})}},variant:"outline",size:"sm",className:"border-red-300 text-red-700 hover:bg-red-100 hover:border-red-400",children:"Update Payment Method"})]}),(0,le.jsx)("p",{className:"text-sm mt-2",children:"Your subscription payment is overdue. Access to some features is currently limited. Please update your payment method to regain full access."})]}),b&&(0,le.jsx)("div",{className:"block lg:hidden mb-2",children:(0,le.jsxs)(pc,{billingAction:"back_to_plans",ctaText:"Back to Plans",billingContext:{origin:"BillingPage",view:l,is_workspace_context:!!L},onClick:R,variant:"ghost",className:"px-2 text-gray-600 hover:text-gray-900 flex items-center gap-1",children:[(0,le.jsx)(Xs.A,{className:"h-5 w-5"}),(0,le.jsx)("span",{className:"font-base44",children:"Back"})]})}),(0,le.jsx)("div",{className:"flex flex-col items-center text-center mb-6",children:b?(0,le.jsx)(le.Fragment,{children:(0,le.jsxs)("div",{className:"w-full relative",children:[(0,le.jsxs)(pc,{billingAction:"back_to_plans",ctaText:"Back to Plans",billingContext:{origin:"BillingPage",view:l,is_workspace_context:!!L},onClick:R,variant:"ghost",className:"hidden lg:flex absolute left-0 px-2 text-gray-600 hover:text-gray-900 items-center gap-1",children:[(0,le.jsx)(Xs.A,{className:"h-5 w-5"}),(0,le.jsx)("span",{className:"font-base44",children:"Back"})]}),(0,le.jsxs)("div",{className:"max-w-3xl mx-auto text-center mb-2",children:[(0,le.jsx)("h2",{className:"text-3xl md:text-4xl font-normal text-slate-900 mb-2 font-base44",children:k?"Choose your billing cycle for upgrading to ".concat(y):"Select a billing cycle for your ".concat(y," plan")}),(0,le.jsx)($c,{})]})]})}):(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)("h1",{className:"text-3xl md:text-4xl font-normal text-slate-900 base44-font",children:"billing"===l?"Choose the plan that's right for you":"Usage"}),(0,le.jsx)($c,{}),"billing"!==l&&(0,le.jsx)("div",{className:"flex justify-center mt-4",children:(0,le.jsxs)(pc,{billingAction:"view_billing_click",ctaText:L?"View Billing":"See Pricing",billingContext:{view:l,is_workspace_context:!!L},onClick:()=>{r("billing")},variant:"ghost",className:"text-sm text-orange-600 hover:text-orange-700 font-medium flex items-center p-0 h-auto",children:[(0,le.jsx)(we.A,{size:16}),L?"View Billing":"See Pricing"]})})]})}),L?"billing"===l?(0,le.jsxs)("div",{className:"space-y-6",children:[(0,le.jsx)(bc,{}),(0,le.jsx)(mc,{})]}):(0,le.jsx)("div",{className:"space-y-8"}):"billing"===l?(0,le.jsxs)("div",{className:"space-y-8",children:[B&&(0,le.jsx)(Zc,{type:"schedule-change",title:"Pending Subscription Change",message:"You have a subscription change to the ".concat((W=null==s?void 0:s.subscription_schedule_tier,W?W.split("_").map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(" "):"")," plan scheduled to take effect at the end of your current billing cycle."),subMessage:'Note: To cancel your subscription, first cancel this change, then use "manage payments" to cancel.',buttonText:"Cancel Change",loadingText:"Cancelling...",onButtonClick:async()=>{try{I(!0),await $o.cancelSchedule(),t({title:"Success",description:"Subscription schedule cancelled successfully"}),I(!1),setTimeout(()=>{window.location.reload()},2e3)}catch(e){t({variant:"destructive",title:"Error",description:"Failed to cancel subscription schedule. Please try again later."}),I(!1)}},handleManageSubscription:F,isLoading:E}),!B&&z&&(0,le.jsx)(Zc,{type:"cancellation",title:"Subscription Cancellation Scheduled",message:"Your subscription will end on ".concat((e=>{if(!e)return"";return new Date(e).toLocaleDateString("en-US",{year:"numeric",month:"long",day:"numeric"})})(null==s?void 0:s.subscription_period_end),". Until then, you have full access to all features."),subMessage:"Want to keep your subscription? You can reactivate it with one click.",buttonText:"Manage Payments",loadingText:"Processing...",handleManageSubscription:F,isLoading:T}),f?(0,le.jsx)(Qc,{}):b?(0,le.jsx)(le.Fragment,{children:(0,le.jsx)(Bc,{selectedPlanType:y,stats:p,onSubscribe:O,onBack:R,selectedEliteTier:w,isUpgradeFlow:k,onUpgrade:M})}):(0,le.jsx)("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-3 lg:gap-4 max-w-full mx-auto px-4 items-stretch",children:["starter","builder","pro","elite"].map(e=>{const t=(e=>{if(null==p||!p.pricing)return null;const t=("yearly"===i?p.pricing.yearly:p.pricing.monthly)[e];return t?[e,t]:null})(e);return t?(0,le.jsx)("div",{className:"w-full h-full ".concat("pro"===e?"lg:order-2 xl:order-2":"builder"===e?"lg:order-3 xl:order-3":"starter"===e?"lg:order-4 xl:order-4":"elite"===e?"lg:order-1 xl:order-1":""),children:(0,le.jsx)(Ec,{planType:e,plan:t[1],allPlans:U(),currentTier:(null==x?void 0:x.tier)||"",stats:p,usage:x,onSubscribe:O,onUpgrade:D,onManageSubscription:F,upgrading:!1,billingPeriod:i})},e):null})}),!b&&(0,le.jsx)(Hc,{}),!f&&!b&&(0,le.jsx)("div",{className:"flex justify-end mt-2",children:(0,le.jsxs)("div",{className:"relative group",children:[(0,le.jsx)(pc,{billingAction:"coupon_open",ctaText:"Have a coupon code?",billingContext:{view:l,is_workspace_context:!!L},onClick:()=>{var e;null===(e=document.getElementById("coupon-form"))||void 0===e||e.classList.toggle("hidden")},variant:"ghost",className:"text-xs text-gray-400 hover:text-gray-600 underline-offset-4 hover:underline p-0 h-auto font-normal",children:"Have a coupon code?"}),(0,le.jsx)("div",{id:"coupon-form",className:"hidden absolute right-0 mt-2 bg-white shadow-lg rounded-md p-3 border border-gray-100 z-10 w-64",children:(0,le.jsxs)("form",{onSubmit:async e=>{if(e.preventDefault(),c.trim()){u(!0);try{const e=await fc.addCouponCode(c.trim());t({title:"Success",description:"".concat(e.num_messages," credits added to your account!")}),d("")}catch(a){var s;t({variant:"destructive",title:"Error",description:(null===(s=a.response)||void 0===s?void 0:s.detail)||"Failed to apply coupon code. Please try again."})}finally{u(!1)}}},className:"flex gap-2 items-center",children:[(0,le.jsx)(fn,{type:"text",placeholder:"Enter code",value:c,onChange:e=>d(e.target.value),className:"flex-1 text-xs h-7"}),(0,le.jsx)(pc,{billingAction:"coupon_apply",ctaText:"Apply",billingContext:{origin:"BillingPage",view:l,is_workspace_context:!!L,coupon_code:c.trim()},type:"submit",disabled:m||!c.trim(),variant:"ghost",size:"sm",className:"text-xs h-7 px-2",children:m?"...":"Apply"})]})})]})}),(0,le.jsx)(mc,{})]}):(0,le.jsx)("div",{className:"space-y-8"})]});var W},ed=["className","children"],td=e=>{let{className:t,children:s}=e,a=(0,Se.A)(e,ed);return(0,le.jsxs)(ka.Portal,{children:[(0,le.jsx)(ka.Overlay,{className:"fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0"}),(0,le.jsx)(ka.Content,(0,K.A)((0,K.A)({className:Pe("fixed left-[50%] top-[50%] z-50 w-full translate-x-[-50%] translate-y-[-50%] bg-background shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] rounded-[16px]","max-w-[90vw] h-[90vh] overflow-hidden",t)},a),{},{children:s}))]})},sd=e=>{let{isOpen:t,onClose:s,onSubscriptionSuccess:a}=e;return(0,le.jsx)(tc,{open:t,onOpenChange:s,children:(0,le.jsx)(td,{className:"bg-white",children:(0,le.jsxs)("div",{className:"h-full flex flex-col",children:[(0,le.jsx)("div",{className:"flex-shrink-0 flex items-center justify-end px-6 pt-4",children:(0,le.jsxs)("button",{onClick:s,className:"h-8 w-8 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 flex items-center justify-center",children:[(0,le.jsx)(Bt.A,{className:"h-4 w-4"}),(0,le.jsx)("span",{className:"sr-only",children:"Close"})]})}),(0,le.jsx)("div",{className:"flex-1 overflow-auto",children:(0,le.jsx)(Xc,{})})]})})})};function ad(e){let{currentUsage:t,stats:s,className:a=""}=e;const{toast:n}=nn(),[l,r]=(0,Y.useState)(!1),[i,o]=(0,Y.useState)(!1),[c,d]=(0,Y.useState)(!1),[m,u]=(0,Y.useState)(!1),{app:x}=Nt(),{user:h}=oe(),{nextPlan:p,billingPeriod:g,isLoading:f,error:v}=Yo(t,s),b=(null==t?void 0:t.tier)||null,j=!b||"free"===b.toLowerCase(),y=zo(b),N=Uo(b),w=j&&(null==t?void 0:t.daily_usage)>=(null==t?void 0:t.daily_limit),_=(()=>{if(!N||null==s||!s.pricing)return null;return("yearly"===y?s.pricing.yearly:s.pricing.monthly)[N]||null})();(0,Y.useEffect)(()=>{try{if(t&&s){var e;const a={user_id:(null==h?void 0:h.id)||null,user_email:t.user_email,organization_id:t.organization_id,app_id:(null==x?void 0:x.id)||null,conversation_id:(null==x||null===(e=x.conversation)||void 0===e?void 0:e.id)||null,monthly_usage:t.monthly_usage,daily_usage:t.daily_usage,monthly_limit:t.monthly_limit,daily_limit:t.daily_limit,extra_credits:t.extra_credits,is_over_limit:t.is_over_limit,current_tier:b,is_free_user:j,next_tier:N,billing_period:y,hit_daily_limit:w,hit_monthly_limit:!w&&t.is_over_limit,current_period_start:t.current_credit_period_start_date,current_period_end:t.current_credit_period_end_date,next_period_start:t.next_period_start_date,past_due:t.past_due,has_pricing_data:!(null==s||!s.pricing),next_plan_price:(null==_?void 0:_.unit_amount)||null,next_plan_id:(null==_?void 0:_.id)||null};tt("User out of credits",a)}}catch(v){}},[]);const k=(e,s)=>{try{var a;const n={user_id:(null==h?void 0:h.id)||null,app_id:(null==x?void 0:x.id)||null,conversation_id:(null==x||null===(a=x.conversation)||void 0===a?void 0:a.id)||null},l={cta:e,origin:"chat out of credits message",target_route:j||!N?"/billing":"direct_upgrade",current_tier:b,next_tier:N,billing_period:y,upgrade_type:s,daily_usage:(null==t?void 0:t.daily_usage)||null,daily_limit:(null==t?void 0:t.daily_limit)||null,monthly_usage:(null==t?void 0:t.monthly_usage)||null,monthly_limit:(null==t?void 0:t.monthly_limit)||null,is_daily_limit_hit:w};tt("User clicked upgrade",(0,K.A)((0,K.A)({},n),l)),ht(n,l)}catch(v){}},C=()=>{u(!0);const e=j?"billing_dialog":"direct_upgrade",t=A();k(t,e),j?(d(!0),o(!0)):(async()=>{if(null!=_&&_.id){r(!0);try{var e;const t=null===(e=(await $o.updateSubscription(_.id)).subscription)||void 0===e?void 0:e.is_downgrade;n({title:"Subscription Updated",description:t?"Your subscription has been scheduled to downgrade at the end of your billing cycle.":"Your subscription has been upgraded successfully. Changes will be reflected shortly."}),setTimeout(()=>{window.location.reload()},2e3)}catch(v){var t;n({variant:"destructive",title:"Error",description:(null===(t=v.response)||void 0===t?void 0:t.detail)||"Failed to update subscription. Please try again later."})}finally{r(!1),u(!1)}}})()},A=()=>{if(j)return c?"Opening...":"View All Plans";if(!N)return"View All Plans";const e=Vo(N),t=y.charAt(0).toUpperCase()+y.slice(1);return"Upgrade to ".concat(e," ").concat(t)},S=()=>Wo(p),E=()=>{if(null==p||!p.unit_amount)return{price:"0",billingText:"billed monthly"};const e="yearly"===g;return{price:e?(p.unit_amount/100/12).toFixed(0):(p.unit_amount/100).toFixed(0),billingText:e?"billed yearly":"billed monthly"}};return f?(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)("div",{className:"py-2 px-2 ".concat(a," align-center w-full"),children:(0,le.jsx)("div",{className:"min-h-[100px] font-base44 rounded-[16px]",children:(0,le.jsxs)("div",{className:"p-2 text-center",children:[(0,le.jsx)("div",{className:"mb-2",children:(0,le.jsx)("div",{className:"font-light text-gray-700 mb-4 leading-relaxed",children:(0,le.jsxs)("div",{className:"animate-pulse",children:[(0,le.jsx)("div",{className:"h-4 bg-gray-200 rounded mb-2 w-3/4 mx-auto"}),(0,le.jsx)("div",{className:"h-3 bg-gray-200 rounded w-1/2 mx-auto"})]})})}),(0,le.jsx)("div",{className:"",children:(0,le.jsx)("div",{className:"animate-pulse",children:(0,le.jsx)("div",{className:"w-full h-[32px] bg-gray-200 rounded-[10px]"})})})]})})}),(0,le.jsx)(sd,{isOpen:i,onClose:()=>{o(!1),d(!1),u(!1)},onSubscriptionSuccess:()=>{o(!1),d(!1),u(!1),setTimeout(()=>{window.location.reload()},1e3)}})]}):v?(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)("div",{className:"py-6 px-6 ".concat(a," font-base44"),children:(0,le.jsxs)("div",{className:"max-w-lg",children:[(0,le.jsx)("div",{className:"mb-2",children:(0,le.jsx)("p",{className:"text-md font-light text-gray-700 mb-6 leading-relaxed",children:w?(0,le.jsxs)(le.Fragment,{children:["Looks like you've reached your daily credit limit. Your credits will reset tomorrow, or"," ",(0,le.jsx)("button",{onClick:()=>{k("upgrade now","billing_dialog"),o(!0)},className:"text-orange-600 underline hover:text-orange-700 bg-transparent border-none cursor-pointer",children:"upgrade now"})," ","for more credits immediately."]}):(0,le.jsxs)(le.Fragment,{children:["Looks like you've used all your credits for this month."," ",(0,le.jsx)("button",{onClick:()=>{k("See all plans","billing_dialog"),o(!0)},className:"text-orange-600 underline hover:text-orange-700 bg-transparent border-none cursor-pointer",children:"See all plans"}),"."]})})}),j?(0,le.jsx)("button",{onClick:C,disabled:c||m,className:"w-full inline-flex items-center justify-center gap-2 px-4 py-3 bg-orange-500 text-white text-md font-medium rounded-lg hover:bg-orange-400 transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:A()}):(0,le.jsx)("button",{onClick:C,disabled:l||m,className:"w-full inline-flex items-center justify-center gap-2 px-4 py-3 bg-orange-500 text-white text-md font-medium rounded-lg hover:bg-orange-400 transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:l?"Upgrading...":A()})]})}),(0,le.jsx)(sd,{isOpen:i,onClose:()=>{o(!1),d(!1),u(!1)},onSubscriptionSuccess:()=>{o(!1),d(!1),u(!1),setTimeout(()=>{window.location.reload()},1e3)}})]}):(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)("div",{className:"py-2 px-2 ".concat(a," align-center w-full"),children:(0,le.jsx)("div",{className:" min-h-[100px] font-base44 rounded-[16px]",children:(0,le.jsxs)("div",{className:"p-2 text-center",children:[(0,le.jsx)("div",{className:"mb-2",children:j?(0,le.jsx)("div",{className:"font-light text-gray-700 mb-4 leading-relaxed",children:w?(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)("div",{className:"text-black text-[16px]",children:"You're out of daily credits on your Free plan"}),(0,le.jsx)("div",{className:"text-[14px]",children:"Upgrade to a Premium plan and unlock instant credits and more power for your app"})]}):(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)("div",{className:"text-black text-[16px]",children:"You're out of monthly credits on your Free plan"}),(0,le.jsx)("div",{className:"text-[14px]",children:"Upgrade to a Premium plan and unlock instant credits and more power for your app"})]})}):N?(0,le.jsxs)("p",{className:"text-md font-light text-gray-700 mb-4 leading-relaxed",children:[(0,le.jsx)("span",{className:"font-bold text-md text-black",children:"You've hit this month's limit"}),(0,le.jsx)("br",{}),(0,le.jsxs)("span",{children:["Out of credits but still full of ideas? Upgrade to unlock more power for your app ",(0,le.jsx)("button",{onClick:()=>{k("Compare all plans","billing_dialog"),o(!0)},className:"text-indigo-500 hover:text-indigo-600 bg-transparent border-none cursor-pointer",children:"Compare all plans"})]})]}):(0,le.jsxs)("div",{className:"font-light text-gray-700 mb-4 leading-relaxed",children:[(0,le.jsx)("div",{className:"text-black text-[16px]",children:"You've hit the limit on our highest plan"}),(0,le.jsx)("div",{className:"text-[14px]",children:"Let's take it further - contact our sales team to create a custom plan for you"})]})}),j&&(0,le.jsx)("div",{className:"",children:(0,le.jsx)("button",{onClick:C,disabled:c||m,className:"font-base44 w-full inline-flex items-center justify-center px-6 h-[32px] bg-orange-500 text-white text-[16px] font-medium rounded-[10px] hover:bg-orange-600 disabled:opacity-50 disabled:cursor-not-allowed",children:A()})}),!j&&!N&&(0,le.jsx)("div",{className:"",children:(0,le.jsx)("a",{href:"https://base44.com/enterprise",target:"_blank",rel:"noopener noreferrer",onClick:()=>k("Contact Sales","contact_sales"),className:"font-base44 w-full inline-flex items-center justify-center px-6 h-[32px] bg-orange-500 text-white text-[16px] font-medium rounded-[10px] hover:bg-orange-600",children:"Contact Sales"})}),!j&&N&&(0,le.jsxs)("div",{className:"bg-white/50 rounded-[12px] p-4 font-base44",children:[(0,le.jsxs)("div",{className:"flex justify-between items-center mb-2",children:[(0,le.jsxs)("h3",{className:"text-lg font-semibold text-slate-900 font-base44",children:[Vo(N)," Plan"]}),(0,le.jsxs)("div",{className:"flex items-center gap-2 bg-white p-0.5 px-4 rounded-full",children:[(0,le.jsxs)("div",{className:"text-lg font-semibold text-slate-900",children:["$",E().price]}),(0,le.jsx)("div",{className:"text-xs text-slate-500 font-base44",children:E().billingText})]})]}),(0,le.jsxs)("div",{className:"space-y-2 mb-4",children:[(0,le.jsxs)("div",{className:"text-sm text-slate-600 flex",children:[(0,le.jsx)("span",{className:"text-orange-500 font-semibold min-w-[40px]",children:qo(S().messageCredits)})," Monthly credits"]}),(0,le.jsxs)("div",{className:"text-sm text-slate-600 flex",children:[(0,le.jsx)("span",{className:"text-orange-500 font-semibold min-w-[40px]",children:qo(S().integrationCredits)})," Integration credits"]})]}),(0,le.jsx)("div",{className:"mb-2 cursor-pointer",children:j?(0,le.jsx)("button",{onClick:C,disabled:c||m,className:"font-base44 w-full inline-flex items-center justify-center px-6 h-[32px] bg-orange-500 text-white text-[16px] font-medium rounded-[10px] hover:bg-orange-600 disabled:opacity-50 disabled:cursor-not-allowed",children:A()}):(0,le.jsx)("button",{onClick:C,disabled:l||m,className:"font-base44 cursor-pointer w-full inline-flex items-center justify-center px-6 h-[32px] bg-orange-500 text-white text-[16px] font-medium rounded-[10px] hover:bg-orange-600 disabled:opacity-50 disabled:cursor-not-allowed",children:l?"Upgrading...":A()})}),(0,le.jsx)("p",{className:"text-center text-sm font-thin text-slate-500",children:j?"View all available plans and pricing":"Clicking Upgrade will confirm your payment"})]})]})})}),(0,le.jsx)(sd,{isOpen:i,onClose:()=>{o(!1),d(!1),u(!1)},onSubscriptionSuccess:()=>{o(!1),d(!1),u(!1),setTimeout(()=>{window.location.reload()},1e3)}})]})}function nd(e){let{endDate:t,isDaily:s=!1}=e;const[a,n]=(0,Y.useState)("");return(0,Y.useEffect)(()=>{const e=()=>{if(s){const e=new Date,t=new Date(e);t.setUTCHours(24,0,0,0);const s=t.getTime()-e.getTime();if(s>0){const e=Math.floor(s/36e5),t=Math.floor(s%36e5/6e4);n(e>0?"".concat(e,"h : ").concat(t,"m"):"".concat(t,"m"))}else n("")}else{if(!t)return;const e=new Date,s=new Date(t+"T00:00:00").getTime()-e.getTime();if(s>0){const e=Math.floor(s/864e5),t=Math.floor(s%864e5/36e5),a=Math.floor(s%36e5/6e4);n(e>0?"".concat(e,"d : ").concat(t,"h"):t>0?"".concat(t,"h : ").concat(a,"m"):"".concat(a,"m"))}else n("Expired")}};e();const a=setInterval(e,6e4);return()=>clearInterval(a)},[t,s]),(0,le.jsx)("span",{className:"flex text-md text-white justify-center",children:a&&"".concat(a," until credits renew")})}function ld(e){let{changeCount:t,onRevert:s,onDiscardAll:a,onSaveAll:n,isSaving:l,onClose:r}=e;return 0===t?null:(0,le.jsx)("div",{className:"w-full mb-3 font-base44",children:(0,le.jsxs)("div",{className:"bg-white border border-gray-200 rounded-[12px] px-5 py-2 flex items-center justify-between gap-4 backdrop-blur-sm shadow-md",children:[(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[(0,le.jsx)("div",{className:"w-2 h-2 bg-red-500 rounded-full animate-pulse"}),(0,le.jsxs)("span",{className:"text-[13px] font-medium text-slate-700",children:["You have ",t," unsaved change",t>1?"s":""]})]}),(0,le.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,le.jsx)("button",{onClick:s,disabled:l||0===t,className:"flex items-center justify-center w-7 h-7 text-slate-500 hover:text-slate-700 hover:bg-slate-100 rounded-lg transition-all duration-200 disabled:opacity-40 disabled:cursor-not-allowed",title:"Revert last change",children:(0,le.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:[(0,le.jsx)("path",{d:"M2 4.6665V8.6665H6",stroke:"black","stroke-width":"1.33333","stroke-linecap":"round","stroke-linejoin":"round"}),(0,le.jsx)("path",{d:"M14 11.3335C14 9.7422 13.3679 8.21607 12.2426 7.09086C11.1174 5.96564 9.5913 5.3335 8 5.3335C6.52341 5.335 5.09924 5.88094 4 6.86683L2 8.66683",stroke:"black","stroke-width":"1.33333","stroke-linecap":"round","stroke-linejoin":"round"})]})}),(0,le.jsx)("div",{className:"w-px h-4 bg-slate-200"}),(0,le.jsx)("button",{onClick:a,disabled:l,className:"text-[12px] font-medium px-3 py-1 text-slate-600 hover:text-slate-800 hover:bg-slate-100 rounded-lg transition-all duration-200 disabled:opacity-40 disabled:cursor-not-allowed",children:"Discard"}),(0,le.jsx)("button",{onClick:n,disabled:l,className:"text-[12px] font-medium px-3.5 py-1 bg-blue-600 hover:bg-blue-700 text-white rounded-lg shadow-sm hover:shadow transition-all duration-200 disabled:opacity-60 disabled:cursor-not-allowed",children:"Save"})]})]})})}const rd=function(e){var t;let{minimizedChat:s=!1,chat:a,addMessage:n,undoMessage:l,status:r,onStop:i,loadFullConversation:o=null,suggestions:c=null,isDisabled:d=!1,isOutOfCredits:m=!1,currentUsage:u=null,billingStats:x=null,customButtomRight:h=null,customButtomLeft:p=null,placeholder:g="What would you like to change?",isDiscussionMode:f=!1,isVisualEditMode:v=!1,changeCount:b=0,onRevertChange:j=null,onDiscardAllChanges:y=null,onSaveAllChanges:N=null,isSavingChanges:w=!1,bannerDismissed:_=!1,onBannerDismiss:k=null}=e;const{user:C}=oe(),[A,S]=(0,Y.useState)(""),[E,I]=(0,Y.useState)([]),[T,P]=(0,Y.useState)(null),L=(0,Y.useRef)(null),O=(0,Y.useRef)(null),[R,M]=(0,Y.useState)(!1),[D,F]=(0,Y.useState)(!0),[B,z]=(0,Y.useState)(!1),U=null===(t=C.platform_role)||void 0===t?void 0:t.includes("admin"),W=(!(null!=u&&u.tier)||"free"===(null==u?void 0:u.tier.toLowerCase()))&&(null==u?void 0:u.daily_usage)>=(null==u?void 0:u.daily_limit);(0,Y.useEffect)(()=>{const e=sessionStorage.getItem("pendingChatMessage");e&&(S(e),sessionStorage.removeItem("pendingChatMessage"));const t=e=>{e.detail&&e.detail.message&&(S(e.detail.message),setTimeout(()=>{if(O.current&&O.current.focus&&(O.current.focus(),O.current.setSelectionRange)){var e;const t=(null===(e=O.current.value)||void 0===e?void 0:e.length)||0;O.current.setSelectionRange(t,t)}},100))};return window.addEventListener("pendingChatMessage",t),()=>{window.removeEventListener("pendingChatMessage",t)}},[]);const q=()=>{L.current&&D&&(L.current.scrollTop=L.current.scrollHeight)},V=()=>{const e=(()=>{if(!L.current)return!0;const e=L.current;return e.scrollHeight-e.scrollTop-e.clientHeight<=100})();M(!e),F(e),z(!0),clearTimeout(V.timeout),V.timeout=setTimeout(()=>{z(!1)},1500)},H=async()=>{if(A.trim()&&"processing"!==r.state)try{var e;if(T)tt("Suggestion - Sent",{suggestion_text:T.prompt,suggestion_title:T.title,suggestion_position:T.position,user_message_count:(null==a||null===(e=a.messages)||void 0===e?void 0:e.filter(e=>"user"===e.role).length)||0});const t={content:A,file_urls:E};S(""),I([]),P(null),F(!0),M(!1),await n(t)}catch(t){cr.toast.error("Failed to send message")}};(0,Y.useEffect)(()=>{new URLSearchParams(window.location.search).get("msgId")||R||q()},[null==a?void 0:a.messages,R]),(0,Y.useEffect)(()=>{R||q()},[r,R]),(0,Y.useEffect)(()=>{if(!L.current)return;const e=new MutationObserver(()=>{R||q()});e.observe(L.current,{childList:!0,subtree:!0,characterData:!0});const t=L.current;return t.addEventListener("scroll",V),()=>{e.disconnect(),t.removeEventListener("scroll",V)}},[R]);const G=(0,Y.useMemo)(()=>{const e=(null==a?void 0:a.messages.filter(e=>!0!==e.hidden))||[];return e.map((t,s)=>{let n=null==a?void 0:a.messages[s-1],l=null==a?void 0:a.messages[s+1];const r="assistant"===t.role&&(!n||"assistant"!==n.role),i="assistant"===t.role&&(!l||"assistant"!==l.role),o=s===e.length-1;return(0,K.A)((0,K.A)({},t),{},{isFirstAssistantMessage:r,isLastAssistantMessage:i,isLastMessageInChat:o})})},[(null==a?void 0:a.messages)||[]]);return a?s?(0,le.jsx)(Wt,{className:"shadow-none",value:A,onValueChange:S,files:E,onFilesChange:I,onSend:H,onStop:i,placeholder:g,disabled:"processing"===r.state||d,customButtomRight:h,customButtomLeft:p,isProcessing:"processing"===r.state,isDiscussionMode:f,isVisualEditMode:v}):(0,le.jsxs)("div",{className:"flex flex-col h-full w-full sm:bg-[#F8FAFC] relative p-0 ",children:[(0,le.jsx)("div",{className:""}),(0,le.jsx)("div",{ref:L,className:Pe("flex-grow overflow-y-auto px-4 sm:px-2 sm:py-2 space-y-2 pb-4 scrollbar-auto-hide relative z-10",{"scrollbar-visible":B}),onMouseEnter:()=>{z(!0)},onMouseLeave:()=>{clearTimeout(V.timeout),setTimeout(()=>{z(!1)},300)},children:(0,le.jsx)(So,{messages:G,undoMessage:l?e=>{const t=a.messages.find(t=>t.id===e);"user"===t.role&&(l(e),S(t.content))}:null,loadFullConversation:o})}),!_&&b>0&&j&&y&&N&&(0,le.jsx)(ld,{changeCount:b,onRevert:j,onDiscardAll:y,onSaveAll:N,isSaving:w,onClose:k}),(0,le.jsxs)("div",{className:"rounded-[12px] relative z-10",children:[(0,le.jsx)("div",{className:"relative flex-shrink-0",children:(0,le.jsx)("div",{className:Pe("w-full rounded-[16px] sm:rounded-none sm:shadow-none"),children:(0,le.jsxs)("div",{className:Pe("join w-full px-4 sm:px-2 pb-4","bg-slate-50","shadow-[0_-10px_20px_8px_rgba(248,250,252,1)]",{"bg-[linear-gradient(0deg,rgba(238,86,225,0.1)_0%,rgba(238,86,225,0.1)_52%,rgba(249,115,22,0.1)_79%,rgba(239,198,168,0.1)_100%)] shadow-[0_-10px_20px_8px_rgba(247,244,243,1)]":m}),children:[m&&(0,le.jsxs)("div",{className:"flex flex-col justify-center",children:[(0,le.jsx)(ad,{currentUsage:u,stats:x}),(null==u?void 0:u.current_credit_period_end_date)&&(0,le.jsx)("div",{className:"flex justify-center -mb-3",children:(0,le.jsx)("div",{className:"bg-[#C7BECF] rounded-t-[16px] pt-2 pb-4 px-4 w-full text-center",children:(0,le.jsx)(nd,{endDate:u.next_period_start_date,isDaily:W})})})]}),(0,le.jsxs)("div",{className:"flex flex-col",children:[(0,le.jsx)(Lo,{status:r,messages:G}),!m&&("ready"===r.state&&c?(0,le.jsxs)("div",{className:"px-4 py-3",children:[(0,le.jsxs)("div",{className:"flex items-center gap-1.5 text-gray-400 mb-3",children:[(0,le.jsx)(ir.A,{className:"w-4 h-4"}),(0,le.jsx)("span",{className:"text-xs",children:"Suggestions"})]}),(0,le.jsx)("div",{className:"flex items-center justify-start",children:[c.suggestion_1,c.suggestion_2,c.suggestion_3].map((e,t)=>(0,le.jsxs)("div",{className:"flex items-center",children:[t>0&&(0,le.jsx)("div",{className:"h-6 w-px bg-gray-300 mx-2"}),(0,le.jsx)("button",{className:"text-xs text-gray-600 hover:text-gray-900 cursor-pointer transition-colors px-2 text-left",onClick:()=>((e,t)=>{var s;tt("Suggestion - Clicked",{suggestion_text:e.prompt,suggestion_title:e.title,suggestion_position:t+1,user_message_count:(null==a||null===(s=a.messages)||void 0===s?void 0:s.filter(e=>"user"===e.role).length)||0}),S(e.prompt),P((0,K.A)((0,K.A)({},e),{},{position:t+1}))})(e,t),children:e.title})]},t))})]}):null)]}),(0,le.jsx)(Wt,{className:"md:shadow-none",ref:O,value:A,onValueChange:e=>{S(e),T&&e!==T.prompt&&P(null)},files:E,onFilesChange:I,onSend:H,onStop:i,placeholder:g,disabled:d,customButtomRight:h,customButtomLeft:p,isProcessing:"processing"===r.state,isDiscussionMode:f,isVisualEditMode:v,isOutOfCredits:m})]})})}),U&&(0,le.jsx)("div",{className:"text-xs text-gray-400 text-center opacity-0 hover:opacity-100 transition-opacity duration-200 absolute bottom-0 right-0",children:(0,le.jsxs)("a",{onClick:()=>{const e=a.messages.slice(-8).map(e=>"".concat(e.role,":\n").concat(e.content)).join("\n\n");navigator.clipboard.writeText(e)},className:"hover:underline inline-flex items-center gap-1",children:[(0,le.jsx)(or.A,{className:"w-3 h-3"}),"Copy"]})})]})]}):(0,le.jsx)("div",{className:"alert alert-warning m-4 text-sm",children:"No chat found"})};var id=s(50253);function od(e){let{isVisualEditMode:t,toggleVisualEditMode:s,isSaving:a}=e;return(0,le.jsxs)("button",{onClick:s,className:"flex items-center gap-1 px-2 py-1 rounded-md text-xs ".concat(t?"bg-blue-50 text-blue-600 hover:bg-blue-100":"text-gray-600 bg-gray-100 hover:bg-gray-200"),disabled:a,children:[(0,le.jsx)(id.A,{className:"h-4 w-4"}),(0,le.jsx)("span",{children:"Visual Edit"})]})}var cd=s(17119),dd=s.t(cd,2);const md="palette",ud="custom",xd="bg",hd="text",pd="#000000",gd=[{name:"Slate",prefix:"slate"},{name:"Gray",prefix:"gray"},{name:"Zinc",prefix:"zinc"},{name:"Neutral",prefix:"neutral"},{name:"Stone",prefix:"stone"},{name:"Red",prefix:"red"},{name:"Orange",prefix:"orange"},{name:"Amber",prefix:"amber"},{name:"Yellow",prefix:"yellow"},{name:"Lime",prefix:"lime"},{name:"Green",prefix:"green"},{name:"Emerald",prefix:"emerald"},{name:"Teal",prefix:"teal"},{name:"Cyan",prefix:"cyan"},{name:"Sky",prefix:"sky"},{name:"Blue",prefix:"blue"},{name:"Indigo",prefix:"indigo"},{name:"Violet",prefix:"violet"},{name:"Purple",prefix:"purple"},{name:"Fuchsia",prefix:"fuchsia"},{name:"Pink",prefix:"pink"},{name:"Rose",prefix:"rose"}],fd=[50,100,200,300,400,500,600,700,800,900,950],vd=e=>e<500?"text-gray-900":"text-white",bd=e=>{let{color:t}=e;if(!t)return(0,le.jsx)("span",{className:"text-sm text-gray-500",children:"None"});const s=t.type===ud?{backgroundColor:t.value,border:"1px solid rgba(0,0,0,0.1)"}:null,a=t.type===md?"bg-".concat(t.name,"-").concat(t.shade," border border-black/10"):"";return(0,le.jsxs)("div",{className:"flex items-center",children:[(0,le.jsx)("div",{className:"h-6 w-6 rounded-sm mr-2 ".concat(a),style:s}),(0,le.jsx)("span",{className:"text-sm text-gray-700",children:t.type===md?"".concat(t.name.charAt(0).toUpperCase()+t.name.slice(1)," ").concat(t.shade):t.value})]})},jd=e=>{let{mode:t,onModeChange:s}=e;return(0,le.jsx)("div",{className:"w-full",children:(0,le.jsxs)("div",{className:"flex h-8 items-center rounded-md bg-gray-100 p-0.5",children:[(0,le.jsx)("button",{type:"button",className:"flex-1 inline-flex items-center justify-center whitespace-nowrap rounded-sm px-3 py-1 text-sm font-medium ring-offset-white transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-slate-950 focus-visible:ring-offset-2 ".concat(t===md?"bg-white text-slate-950 shadow-sm":"text-slate-500 hover:text-slate-900"),onClick:()=>s(md),children:"Palettes"}),(0,le.jsx)("button",{type:"button",className:"flex-1 inline-flex items-center justify-center whitespace-nowrap rounded-sm px-3 py-1 text-sm font-medium ring-offset-white transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-slate-950 focus-visible:ring-offset-2 ".concat(t===ud?"bg-white text-slate-950 shadow-sm":"text-slate-500 hover:text-slate-900"),onClick:()=>s(ud),children:"Custom"})]})})},yd=e=>{let{color:t,onChange:s}=e;const[a,n]=(0,Y.useState)(100),[l,r]=(0,Y.useState)(50),[i,o]=(0,Y.useState)(0),[c,d]=(0,Y.useState)(!1),[m,u]=(0,Y.useState)(!1),x=(0,Y.useRef)(null),h=(0,Y.useRef)(null);(0,Y.useEffect)(()=>{if(t&&t.startsWith("#")&&7===t.length){const[e,s,a]=(e=>{if(!e||!e.startsWith("#")||7!==e.length)return[0,100,50];const t=parseInt(e.slice(1,3),16)/255,s=parseInt(e.slice(3,5),16)/255,a=parseInt(e.slice(5,7),16)/255,n=Math.max(t,s,a),l=Math.min(t,s,a);let r,i,o=(n+l)/2;if(n===l)r=i=0;else{const e=n-l;switch(i=o>.5?e/(2-n-l):e/(n+l),n){case t:r=(s-a)/e+(s{e=Math.max(0,Math.min(360,e))/360,t=Math.max(0,Math.min(100,t))/100;const a=(e,t,s)=>(s<0&&(s+=1),s>1&&(s-=1),s<1/6?e+6*(t-e)*s:s<.5?t:s<2/3?e+(t-e)*(2/3-s)*6:e),n=(s=Math.max(0,Math.min(100,s))/100)<.5?s*(1+t):s+t-s*t,l=2*s-n,r=a(l,n,e+1/3),i=a(l,n,e),o=a(l,n,e-1/3),c=e=>{const t=Math.max(0,Math.min(255,Math.round(255*e))).toString(16);return 1===t.length?"0"+t:t};return"#".concat(c(r)).concat(c(i)).concat(c(o))},g=(e,t)=>{if(!x.current)return;const o=x.current.getBoundingClientRect(),c=Math.max(0,Math.min(e-o.left,o.width)),d=Math.max(0,Math.min(t-o.top,o.height)),m=Math.round(c/o.width*100),u=Math.round(100-d/o.height*100),[h,g,f]=((e,t,s)=>{const a=(s/=100)*(2-(t/=100))/2,n=0!==a&&1!==a?(s-a)/Math.min(a,1-a):0;return[e,Math.round(100*n),Math.round(100*a)]})(i,m,u);if(Math.abs(g-a)>.5||Math.abs(f-l)>.5){n(g),r(f);const e=p(h,g,f);s(e)}},f=e=>{if(!h.current)return;const t=h.current.getBoundingClientRect(),n=Math.max(0,Math.min(e-t.left,t.width-1)),r=Math.max(0,Math.min(360,n/(t.width-1)*360));if(Math.abs(r-i)>1){o(r);const e=p(r,a,l);s(e)}};(0,Y.useEffect)(()=>{const e=e=>{e.preventDefault(),c?g(e.clientX,e.clientY):m&&f(e.clientX)},t=e=>{e.preventDefault(),d(!1),u(!1)};return(c||m)&&(document.addEventListener("mousemove",e,{passive:!1}),document.addEventListener("mouseup",t,{passive:!1}),document.body.style.userSelect="none",document.body.style.cursor=c?"crosshair":"pointer"),()=>{document.removeEventListener("mousemove",e),document.removeEventListener("mouseup",t),document.body.style.userSelect="",document.body.style.cursor=""}},[c,m,i,a,l]);const[v,b,j]=((e,t,s)=>{const a=(s/=100)+(t/=100)*Math.min(s,1-s),n=0===a?0:2*(1-s/a);return[e,Math.round(100*n),Math.round(100*a)]})(i,a,l);return(0,le.jsxs)("div",{className:"p-4 space-y-4",children:[(0,le.jsxs)("div",{className:"flex items-center gap-3",children:[(0,le.jsx)("div",{className:"w-12 h-12 rounded-lg border border-gray-200 shadow-sm",style:{backgroundColor:t||"#000000"}}),(0,le.jsx)("div",{className:"flex-1",children:(0,le.jsx)("input",{type:"text",value:t||"",onChange:e=>s(e.target.value),className:"w-full px-3 py-2 text-sm border border-gray-200 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent",placeholder:"#000000"})})]}),(0,le.jsx)("div",{className:"relative",children:(0,le.jsx)("div",{ref:x,className:"w-full h-32 rounded-md border border-gray-200 relative overflow-hidden select-none ".concat(c?"cursor-grabbing":"cursor-crosshair"),style:{background:"linear-gradient(to top, #000000, transparent), linear-gradient(to right, #ffffff, hsl(".concat(i,", 100%, 50%))")},onMouseDown:e=>{e.preventDefault(),"mousedown"===e.type&&d(!0),g(e.clientX,e.clientY)},children:(0,le.jsx)("div",{className:"absolute w-3 h-3 border-2 border-white rounded-full shadow-md transform -translate-x-1/2 -translate-y-1/2 pointer-events-none transition-transform ".concat(c?"scale-110":"scale-100"),style:{left:"".concat(Math.max(0,Math.min(100,b)),"%"),top:"".concat(Math.max(0,Math.min(100,100-j)),"%"),boxShadow:"0 0 0 1px rgba(0,0,0,0.3), 0 2px 4px rgba(0,0,0,0.2)"}})})}),(0,le.jsx)("div",{className:"relative",children:(0,le.jsx)("div",{ref:h,className:"w-full h-4 rounded-md border border-gray-200 relative overflow-hidden select-none ".concat(m?"cursor-grabbing":"cursor-pointer"),style:{background:"linear-gradient(to right, #ff0000 0%, #ffff00 17%, #00ff00 33%, #00ffff 50%, #0000ff 67%, #ff00ff 83%, #ff0000 100%)"},onMouseDown:e=>{e.preventDefault(),"mousedown"===e.type&&u(!0),f(e.clientX)},children:(0,le.jsx)("div",{className:"absolute w-4 h-6 border-2 border-white rounded-sm shadow-md transform -translate-x-1/2 -translate-y-1/2 pointer-events-none top-1/2 transition-transform ".concat(m?"scale-110":"scale-100"),style:{left:"".concat(Math.max(0,Math.min(100,i/360*100)),"%"),boxShadow:"0 0 0 1px rgba(0,0,0,0.3), 0 2px 4px rgba(0,0,0,0.2)"}})})})]})},Nd=e=>{let{selectedColorInfo:t,onColorSelect:s}=e;return(0,le.jsx)("div",{className:"overflow-y-auto max-h-64 p-2",children:gd.map(e=>(0,le.jsxs)("div",{className:"mb-3",children:[(0,le.jsx)("div",{className:"text-xs font-medium text-gray-900 mb-1",children:e.name}),(0,le.jsx)("div",{className:"flex flex-wrap gap-2",children:fd.map(a=>{const n=(null==t?void 0:t.name)===e.prefix&&(null==t?void 0:t.shade)===a;return(0,le.jsx)("button",{type:"button",className:"\n aspect-square border border-black/10 rounded-sm flex items-center hover:ring-2 hover:ring-offset-1 hover:ring-blue-500 justify-center w-6 h-6 bg-".concat(e.prefix,"-").concat(a," \n ").concat(vd(a)," ").concat(n?"ring-2 ring-offset-1 ring-blue-500":"","\n "),onClick:()=>s(e.prefix,a),children:n&&(0,le.jsx)(Ps.A,{className:"h-3 w-3"})},a)})})]},e.prefix))})};const wd=function(e){let{label:t,selectedColor:s,onChange:a,zIndexClass:n,onOpen:l,onClose:r,shouldClose:i,forceClose:o,direction:c="bottom"}=e;const[d,m]=(0,Y.useState)(!1),[u,x]=(0,Y.useState)(md),[h,p]=(0,Y.useState)(pd),[g,f]=(0,Y.useState)(null),v=(0,Y.useRef)(null),b=(0,Y.useRef)(null),j=(0,Y.useRef)(null),y=t.toLowerCase().includes("background")?xd:hd;(0,Y.useEffect)(()=>{const e=(e=>{if(!e)return null;const t=e.match(/^(bg|text)-([a-z]+)-(\d+)$/);if(t)return{type:md,name:t[2],shade:parseInt(t[3])};const s=e.match(/^(bg|text)-\[(.+)\]$/);return s?{type:ud,value:s[2]}:null})(s);if(!e)return f(null),void p(pd);e.type===ud?(x(ud),p(e.value),f(null)):(x(md),f({name:e.name,shade:e.shade}),p(pd))},[s]),(0,Y.useEffect)(()=>{i&&d&&(m(!1),r&&r(t))},[i,d,r,t]),(0,Y.useEffect)(()=>{void 0!==o&&m(!1)},[o]),(0,Y.useEffect)(()=>{const e=e=>{d&&j.current&&!j.current.contains(e.target)&&b.current&&!b.current.contains(e.target)&&(m(!1),r&&r(t))};return d&&document.addEventListener("mousedown",e),()=>{document.removeEventListener("mousedown",e)}},[d,r,t]);const N=()=>{f(null),p(pd),a("".concat(y,y===xd?"-transparent":"-black"))};return(0,le.jsxs)("div",{ref:v,className:"relative ".concat(n),children:[(0,le.jsx)("div",{className:"flex items-start justify-between gap-4",children:(0,le.jsx)("div",{className:"flex-1",children:(0,le.jsxs)("div",{className:"flex gap-4",children:[(0,le.jsx)("label",{className:"text-sm font-light text-gray-700 min-w-[100px] pt-2",children:t}),(0,le.jsxs)("button",{ref:b,type:"button",onClick:()=>{const e=!d;m(e),e&&l&&l(t)},className:"flex-1 flex items-center bg-gray-100 justify-between px-2 py-2 rounded-md hover:bg-gray-200 focus:outline-none focus:ring-1 focus:ring-gray-300",children:[bd({color:g?{type:md,name:g.name,shade:g.shade}:h!==pd?{type:ud,value:h}:null}),d?(0,le.jsx)(Ts.A,{className:"h-4 w-4 text-gray-500"}):(0,le.jsx)(Is.A,{className:"h-4 w-4 text-gray-500"})]})]})})}),d&&(0,le.jsx)("div",{ref:j,id:"color-dropdown",className:"absolute ".concat(n||"z-[10020]"," bg-white shadow-lg rounded-[8px] border border-gray-200 w-[320px] ").concat("top"===c?"bottom-full mb-1":"top-full mt-1"," left-0"),style:{maxHeight:"400px"},onClick:e=>e.stopPropagation(),onMouseDown:e=>e.stopPropagation(),children:(0,le.jsxs)("div",{className:"flex flex-col h-full",children:[(0,le.jsxs)("div",{className:"flex items-center justify-between p-2 border-b border-gray-200",children:[(0,le.jsx)("span",{className:"text-sm font-medium text-gray-700",children:"Choose Color"}),(0,le.jsx)("button",{onClick:()=>{m(!1),r&&r(t)},className:"p-1 rounded-md hover:bg-gray-100 transition-colors",title:"Close color picker",children:(0,le.jsx)(Bt.A,{className:"h-4 w-4 text-gray-500"})})]}),(0,le.jsx)("div",{className:"p-2",children:(0,le.jsx)(jd,{mode:u,onModeChange:x})}),(0,le.jsx)("div",{className:"flex-1 overflow-auto",children:u===md?(0,le.jsx)(Nd,{selectedColorInfo:g,onColorSelect:(e,t)=>{f({name:e,shade:t}),a("".concat(y,"-").concat(e,"-").concat(t))}}):(0,le.jsx)(yd,{color:h,onChange:e=>{p(e),a("".concat(y,"-[").concat(e,"]"))}})}),(0,le.jsx)("div",{className:"border-t border-gray-200",children:(0,le.jsxs)("div",{className:"flex items-center justify-between p-2 hover:bg-gray-50 cursor-pointer",onClick:N,children:[(0,le.jsx)("span",{className:"text-sm font-light text-gray-700",children:"Clear Color"}),(0,le.jsx)("button",{className:"w-6 h-6 rounded-sm border border-gray-300 relative hover:bg-gray-50",onClick:N,children:(0,le.jsx)("div",{className:"absolute inset-0 flex items-center justify-center",children:(0,le.jsx)("div",{className:"w-[2px] h-[120%] bg-red-500 rotate-45 transform origin-center"})})})]})})]})})]})};var _d=s(72995),kd=s(14703),Cd=s(45462),Ad=s(56404),Sd=s(25146),Ed=s(80369);const Id=[0,1,2,3,4,5,6,8,10,12,16,20,24,32,40,48,64];const Td=function(e){let{label:t,spacing:s,onChange:a}=e;const n=t.toLowerCase().startsWith("m")?"m":"p",[l,r]=(0,Y.useState)({all:0,t:0,r:0,b:0,l:0,x:0,y:0}),[i,o]=(0,Y.useState)("axes"),[c,d]=(0,Y.useState)(!1),m=(0,Y.useRef)(null);(0,Y.useEffect)(()=>{const e={all:0,t:0,r:0,b:0,l:0,x:0,y:0};let t=!1,a=!1,l=!1,i=!1;const c=s||{},u=e=>{if(!e)return 0;if("mx-auto"===e)return t=!0,0;const s=e.match(new RegExp("^".concat(n,"[ytrlbx]?-(\\d+)$")));if(!s)return 0;const a=parseInt(s[1]),l=Id.indexOf(a);return-1!==l?l:0};c.all&&(e.all=u(c.all),e.t=e.all,e.r=e.all,e.b=e.all,e.l=e.all,a=!0),"mx-auto"===c.x?(t=!0,l=!0):(c.x&&(e.x=u(c.x),e.l=e.x,e.r=e.x,l=!0),c.y&&(e.y=u(c.y),e.t=e.y,e.b=e.y,l=!0)),c.t&&(e.t=u(c.t),i=!0),c.r&&(e.r=u(c.r),i=!0),c.b&&(e.b=u(c.b),i=!0),c.l&&(e.l=u(c.l),i=!0),r(e),d(t);let x=m.current;x||(x=l?"axes":i?"sides":a?"all":"axes"),o(x)},[s,n]);const u=function(e,t){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:c;const l={};"all"===t?l.all="".concat(n,"-").concat(Id[e.all]):"axes"===t?(s&&"m"===n?l.x="mx-auto":e.x>0&&(l.x="".concat(n,"x-").concat(Id[e.x])),e.y>0&&(l.y="".concat(n,"y-").concat(Id[e.y]))):(e.t>0&&(l.t="".concat(n,"t-").concat(Id[e.t])),e.r>0&&(l.r="".concat(n,"r-").concat(Id[e.r])),e.b>0&&(l.b="".concat(n,"b-").concat(Id[e.b])),e.l>0&&(l.l="".concat(n,"l-").concat(Id[e.l]))),a(l)},x=(e,t)=>{const s=Math.max(0,Math.min(t,Id.length-1)),a=(0,K.A)({},l);a[e]=s,"all"===i?(a.t=s,a.r=s,a.b=s,a.l=s,a.x=s,a.y=s):"axes"===i&&("x"===e?(a.l=s,a.r=s):"y"===e&&(a.t=s,a.b=s)),s>0&&"x"===e&&c&&d(!1),r(a),u(a,i,"x"!==e&&c)},h=()=>{const e=!c;if(d(e),e){const e=(0,K.A)((0,K.A)({},l),{},{x:0,l:0,r:0});r(e),u(e,"axes",!0)}else u(l,i,!1)},p=(e,t)=>{const s=l[e];x(e,s+(t?1:-1))},g=e=>{let{label:t,icon:s,value:a,onChange:n}=e;return(0,le.jsx)("div",{className:"flex items-center space-x-2",children:(0,le.jsx)("div",{className:"flex-1 flex items-center",children:(0,le.jsx)("div",{className:"relative flex-1 w-full min-w-[90px] max-w-[140px]",children:(0,le.jsxs)("div",{className:"relative w-full",children:[(0,le.jsx)("div",{className:"absolute left-2 top-1/2 -translate-y-1/2",children:(0,le.jsx)("div",{className:"scale-75",children:s})}),(0,le.jsx)("input",{type:"text",value:Id[a],onChange:e=>{const t=parseInt(e.target.value),s=Id.indexOf(t);-1!==s&&n(s)},className:"w-full pl-9 pr-3 py-1.5 rounded-md bg-gray-100 hover:bg-gray-200 hover:text-indigo-600 disabled:opacity-30 disabled:hover:text-gray-500 focus:ring-1 focus:ring-gray-300 text-sm"}),(0,le.jsxs)("div",{className:"absolute inset-y-0 right-0 flex flex-col pr-1",children:[(0,le.jsx)("button",{type:"button",onClick:()=>p(t.toLowerCase(),!0),disabled:a>=Id.length-1,className:"flex-1 px-1 flex items-center justify-center hover:text-indigo-600 disabled:opacity-30 disabled:hover:text-gray-500",children:(0,le.jsx)(Ts.A,{className:"h-3 w-3"})}),(0,le.jsx)("button",{type:"button",onClick:()=>p(t.toLowerCase(),!1),disabled:a<=0,className:"flex-1 px-1 flex items-center justify-center hover:text-indigo-600 disabled:opacity-30 disabled:hover:text-gray-500",children:(0,le.jsx)(Is.A,{className:"h-3 w-3"})})]})]})})})})};return(0,le.jsx)("div",{className:"space-y-3",children:(0,le.jsxs)("div",{className:"flex items-start justify-between gap-4",children:[(0,le.jsx)("div",{className:"flex-1",children:(0,le.jsxs)("div",{className:"flex gap-4",children:[(0,le.jsx)("label",{className:"text-xs font-light text-gray-700 min-w-[100px] pt-2",children:t}),(0,le.jsxs)("div",{className:"flex-1 space-y-3",children:["axes"===i&&"m"===n&&(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)("div",{className:"flex items-center space-x-2",children:(0,le.jsx)("div",{className:"flex items-center gap-2 w-full",children:c?(0,le.jsxs)("button",{type:"button",onClick:h,className:"flex-1 flex items-center justify-center gap-1 px-3 py-2 bg-indigo-50 rounded-md min-w-[90px] max-w-[140px] w-full",children:[(0,le.jsx)(_d.A,{className:"h-4 w-4 text-indigo-500"}),(0,le.jsx)("span",{className:"text-xs text-indigo-700",children:"mx-auto"})]}):(0,le.jsx)(g,{label:"x",icon:(0,le.jsx)(Ad.A,{className:"h-4 w-4 text-gray-500"}),value:l.x,onChange:e=>x("x",e)})})}),(0,le.jsx)(g,{label:"y",icon:(0,le.jsx)(Sd.A,{className:"h-4 w-4 text-gray-500"}),value:l.y,onChange:e=>x("y",e)})]}),"axes"===i&&"m"!==n&&(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(g,{label:"x",icon:(0,le.jsx)(ha.A,{className:"h-4 w-4 text-gray-500"}),value:l.x,onChange:e=>x("x",e)}),(0,le.jsx)(g,{label:"y",icon:(0,le.jsx)(kd.A,{className:"h-4 w-4 text-gray-500"}),value:l.y,onChange:e=>x("y",e)})]}),"sides"===i&&(0,le.jsxs)("div",{className:"grid auto-rows-auto gap-3",style:{gridTemplateColumns:"repeat(auto-fit, minmax(90px, 140px))"},children:[(0,le.jsx)(g,{label:"t",icon:(0,le.jsx)(Dt.A,{className:"h-4 w-4 text-gray-500"}),value:l.t,onChange:e=>x("t",e)}),(0,le.jsx)(g,{label:"r",icon:(0,le.jsx)(ha.A,{className:"h-4 w-4 text-gray-500"}),value:l.r,onChange:e=>x("r",e)}),(0,le.jsx)(g,{label:"b",icon:(0,le.jsx)(kd.A,{className:"h-4 w-4 text-gray-500"}),value:l.b,onChange:e=>x("b",e)}),(0,le.jsx)(g,{label:"l",icon:(0,le.jsx)(Cd.A,{className:"h-4 w-4 text-gray-500"}),value:l.l,onChange:e=>x("l",e)})]})]})]})}),(0,le.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,le.jsx)("div",{className:"rounded-md overflow-hidden",children:(0,le.jsx)("button",{type:"button",className:"p-2 ".concat("axes"===i?"bg-white text-gray-700 hover:bg-gray-100":"bg-indigo-50 text-indigo-700 hover:bg-indigo-100"),onClick:()=>(e=>{o(e),m.current=e;const t=(0,K.A)({},l);"sides"===e?(l.x>0&&(t.l=l.x,t.r=l.x),l.y>0&&(t.t=l.y,t.b=l.y)):"axes"===e&&(t.x=l.l>0?l.l:l.r,t.y=l.t>0?l.t:l.b),r(t),"axes"!==e&&c?(d(!1),u(t,e,!1)):u(t,e,c)})("axes"===i?"sides":"axes"),children:(0,le.jsx)(Ed.A,{size:16})})}),"Margin"===t&&"axes"===i&&(0,le.jsx)("div",{children:(0,le.jsx)("button",{type:"button",onClick:h,className:"p-2 rounded ".concat(c?"bg-white text-gray-500 border-gray-300":"hover:bg-gray-100 text-gray-700"),children:(0,le.jsx)(_d.A,{className:"h-4 w-4"})})})]})]})})};var Pd=s(14666),Ld=s(92530),Od=s(54413),Rd=s(69367),Md=s(66291),Dd=s(68215);const Fd=[{label:"XS",value:"text-xs",size:"xs"},{label:"S",value:"text-sm",size:"sm"},{label:"Base",value:"text-base",size:"base"},{label:"L",value:"text-lg",size:"lg"},{label:"XL",value:"text-xl",size:"xl"},{label:"2XL",value:"text-2xl",size:"2xl"},{label:"3XL",value:"text-3xl",size:"3xl"},{label:"4XL",value:"text-4xl",size:"4xl"}],Bd=[{label:"Thin",value:"font-thin",weight:100},{label:"Extra Light",value:"font-extralight",weight:200},{label:"Light",value:"font-light",weight:300},{label:"Normal",value:"font-normal",weight:400},{label:"Medium",value:"font-medium",weight:500},{label:"Semi Bold",value:"font-semibold",weight:600},{label:"Bold",value:"font-bold",weight:700},{label:"Extra Bold",value:"font-extrabold",weight:800},{label:"Black",value:"font-black",weight:900}],zd=[{label:"Left",value:"text-left",icon:(0,le.jsx)(Pd.A,{className:"h-4 w-4"})},{label:"Center",value:"text-center",icon:(0,le.jsx)(Ld.A,{className:"h-4 w-4"})},{label:"Right",value:"text-right",icon:(0,le.jsx)(Od.A,{className:"h-4 w-4"})},{label:"Justify",value:"text-justify",icon:(0,le.jsx)(Rd.A,{className:"h-4 w-4"})}],Ud=[{label:"Underline",value:"underline",icon:(0,le.jsx)(Md.A,{className:"h-4 w-4"})},{label:"Line Through",value:"line-through",icon:(0,le.jsx)("span",{className:"text-xs line-through",children:"abc"})}],Wd=[{label:"Normal",value:"normal-case",icon:(0,le.jsx)(Dd.A,{className:"h-4 w-4"})},{label:"Uppercase",value:"uppercase",icon:(0,le.jsx)("span",{className:"text-xs",children:"AA"})},{label:"Lowercase",value:"lowercase",icon:(0,le.jsx)("span",{className:"text-xs",children:"aa"})},{label:"Capitalize",value:"capitalize",icon:(0,le.jsx)("span",{className:"text-xs",children:"Aa"})}];function qd(e){let{value:t,onChange:s,zIndexClass:a,forceClose:n,direction:l="bottom"}=e;const[r,i]=(0,Y.useState)(!1),o=(0,Y.useRef)(null);(0,Y.useEffect)(()=>{n&&i(!1)},[n]),(0,Y.useEffect)(()=>{const e=e=>{o.current&&!o.current.contains(e.target)&&i(!1)};return r&&document.addEventListener("mousedown",e),()=>{document.removeEventListener("mousedown",e)}},[r]);const c=Fd.findIndex(e=>e.value===t),d=-1===c?2:c,m=Fd[d];return(0,le.jsxs)("div",{className:"flex items-center gap-4",children:[(0,le.jsx)("label",{className:"text-sm font-light text-gray-700 whitespace-nowrap min-w-[100px]",children:"Size"}),(0,le.jsxs)("div",{className:"flex-1 flex items-center gap-2",children:[(0,le.jsxs)("div",{ref:o,className:"relative",children:[(0,le.jsxs)("button",{type:"button",onClick:()=>i(!r),className:"w-[80px] h-8 flex items-center justify-between text-sm font-light bg-gray-100 rounded-[6px] border-none hover:bg-gray-200 focus:outline-none focus:ring-0 px-3",children:[m.label,(0,le.jsx)(Is.A,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]}),r&&(0,le.jsx)("div",{className:"absolute ".concat(a||"z-[10020]"," ").concat("top"===l?"bottom-full mb-1":"top-full mt-1"," left-0 w-[120px] bg-white border border-gray-200 rounded-lg shadow-lg p-1"),children:Fd.map(e=>(0,le.jsx)("div",{className:"relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 px-2 text-xs outline-none hover:bg-gray-100 ".concat(t===e.value?"bg-gray-100 font-medium":""),onMouseDown:t=>((e,t)=>{t.preventDefault(),t.stopPropagation(),s(e.value)})(e,t),children:e.label},e.value))})]}),(0,le.jsx)("div",{className:"flex-1",children:(0,le.jsx)("input",{type:"range",min:"0",max:Fd.length-1,value:d,onChange:e=>s(Fd[parseInt(e.target.value)].value),className:"w-full h-2 bg-gray-100 rounded-lg appearance-none cursor-pointer [&::-webkit-slider-thumb]:bg-gray-800 [&::-webkit-slider-thumb]:w-4 [&::-webkit-slider-thumb]:h-4 [&::-webkit-slider-thumb]:rounded-full [&::-webkit-slider-thumb]:appearance-none [&::-moz-range-thumb]:bg-black [&::-moz-range-thumb]:w-4 [&::-moz-range-thumb]:h-4 [&::-moz-range-thumb]:rounded-full [&::-moz-range-thumb]:border-0",style:{background:"linear-gradient(to right, rgb(75, 85, 99) 0%, rgb(75, 85, 99) ".concat(d/(Fd.length-1)*100,"%, #f3f4f6 ").concat(d/(Fd.length-1)*100,"%, #f3f4f6 100%)")}})})]})]})}function Vd(e){let{value:t,onChange:s,zIndexClass:a,forceClose:n,direction:l="bottom"}=e;const[r,i]=(0,Y.useState)(!1),o=(0,Y.useRef)(null);(0,Y.useEffect)(()=>{n&&i(!1)},[n]),(0,Y.useEffect)(()=>{const e=e=>{o.current&&!o.current.contains(e.target)&&i(!1)};return r&&document.addEventListener("mousedown",e),()=>{document.removeEventListener("mousedown",e)}},[r]);const c=Bd.findIndex(e=>e.value===t),d=Bd[-1===c?3:c];return(0,le.jsxs)("div",{className:"flex items-center gap-4",children:[(0,le.jsx)("label",{className:"text-sm font-light text-gray-700 whitespace-nowrap min-w-[100px] max-w-[120px]",children:"Weight"}),(0,le.jsxs)("div",{ref:o,className:"relative flex-1",children:[(0,le.jsxs)("button",{type:"button",onClick:()=>i(!r),className:"w-full h-8 flex items-center justify-between text-sm font-light bg-gray-100 rounded-[6px] border-none hover:bg-gray-200 focus:outline-none focus:ring-0 px-3",children:[d.label,(0,le.jsx)(Is.A,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]}),r&&(0,le.jsx)("div",{className:"absolute ".concat(a||"z-[10020]"," ").concat("top"===l?"bottom-full mb-1":"top-full mt-1"," left-0 w-[160px] bg-white border border-gray-200 rounded-lg shadow-lg p-1"),children:Bd.map(e=>(0,le.jsx)("div",{className:"relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 px-2 text-xs outline-none hover:bg-gray-100 ".concat(t===e.value?"bg-gray-100 font-medium":""),onMouseDown:t=>((e,t)=>{t.preventDefault(),t.stopPropagation(),s(e.value)})(e,t),children:e.label},e.value))})]})]})}const Hd=function(e){let{typography:t,onChange:s,zIndexClass:a,forceClose:n,direction:l="bottom"}=e;const[r,i]=(0,Y.useState)(null),[o,c]=(0,Y.useState)(null),[d,m]=(0,Y.useState)(null),[u,x]=(0,Y.useState)([]),[h,p]=(0,Y.useState)(null);return(0,Y.useEffect)(()=>{i((null==t?void 0:t.size)||Fd[2].value),c((null==t?void 0:t.weight)||Bd[3].value),m((null==t?void 0:t.align)||zd[0].value);const e=((null==t?void 0:t.decoration)||"").split(" ").filter(e=>Ud.some(t=>t.value===e));x(e),p((null==t?void 0:t.transform)||Wd[0].value)},[t]),(0,le.jsxs)("div",{className:"space-y-4",children:[(0,le.jsx)(qd,{value:r,onChange:e=>{i(e),s((0,K.A)((0,K.A)({},t),{},{size:e}))},zIndexClass:a,forceClose:n,direction:l}),(0,le.jsx)(Vd,{value:o,onChange:e=>{c(e),s((0,K.A)((0,K.A)({},t),{},{weight:e}))},zIndexClass:a,forceClose:n,direction:l}),(0,le.jsxs)("div",{className:"flex items-center gap-3",children:[(0,le.jsx)("label",{className:"text-sm font-light text-gray-700 shrink-0 min-w-[105px]",children:"Decoration"}),(0,le.jsx)("div",{className:"flex border rounded-[6px] divide-x flex-1 overflow-hidden",children:Ud.map((e,a)=>(0,le.jsx)("button",{type:"button",className:"flex-1 flex justify-center py-1.5 ".concat(u.includes(e.value)?"bg-gray-200 text-gray-700":"bg-white text-gray-700 hover:bg-gray-50"),onClick:()=>(e=>{let a;a=u.includes(e)?u.filter(t=>t!==e):[...u,e],x(a),s((0,K.A)((0,K.A)({},t),{},{decoration:a.join(" ")}))})(e.value),title:e.label,children:e.icon},e.value))})]}),(0,le.jsxs)("div",{className:"flex items-center gap-3",children:[(0,le.jsx)("label",{className:"text-sm font-light text-gray-700 shrink-0 min-w-[105px]",children:"Alignment"}),(0,le.jsx)("div",{className:"flex border rounded-[6px] divide-x flex-1 overflow-hidden",children:zd.map((e,a)=>(0,le.jsx)("button",{type:"button",className:"flex-1 flex justify-center py-1.5 ".concat(d===e.value?"bg-gray-200 text-gray-700":"bg-white text-gray-700 hover:bg-gray-50"),onClick:()=>{return a=e.value,m(a),void s((0,K.A)((0,K.A)({},t),{},{align:a}));var a},title:e.label,children:e.icon},e.value))})]}),(0,le.jsxs)("div",{className:"flex items-center gap-3",children:[(0,le.jsx)("label",{className:"text-sm font-light text-gray-700 shrink-0 min-w-[105px]",children:"Transform"}),(0,le.jsx)("div",{className:"flex border rounded-[6px] divide-x flex-1 overflow-hidden",children:Wd.map((e,a)=>(0,le.jsx)("button",{type:"button",className:"flex-1 flex justify-center py-1.5 ".concat(h===e.value?"bg-gray-200 text-gray-700":"bg-white text-gray-700 hover:bg-gray-50"),onClick:()=>{return a=e.value,p(a),void s((0,K.A)((0,K.A)({},t),{},{transform:a}));var a},title:e.label,children:e.icon},e.value))})]})]})};function Yd(e){const t={colors:{bg:null,text:null},spacing:{margin:{t:null,r:null,b:null,l:null,x:null,y:null,all:null},padding:{t:null,r:null,b:null,l:null,x:null,y:null,all:null}},typography:{size:null,weight:null,align:null,decoration:null,transform:null,tracking:null,leading:null},opacity:null,borderRadius:null,other:[]};if(!e)return t;if("string"!=typeof e)return t;return e.trim().split(/\s+/).forEach(e=>{if(!e)return;let s=!1;e.startsWith("bg-")?(t.colors.bg=e,s=!0):!e.startsWith("text-")||e.startsWith("text-xs")||e.startsWith("text-sm")||e.startsWith("text-base")||e.startsWith("text-lg")||e.startsWith("text-xl")||e.startsWith("text-2xl")||e.startsWith("text-3xl")||e.startsWith("text-4xl")||e.startsWith("text-5xl")||e.startsWith("text-6xl")||e.startsWith("text-7xl")||e.startsWith("text-8xl")||e.startsWith("text-9xl")||e.startsWith("text-left")||e.startsWith("text-center")||e.startsWith("text-right")||e.startsWith("text-justify")?e.startsWith("m-")?(t.spacing.margin.x=e,t.spacing.margin.y=e,s=!0):e.startsWith("mt-")?(t.spacing.margin.t=e,s=!0):e.startsWith("mr-")?(t.spacing.margin.r=e,s=!0):e.startsWith("mb-")?(t.spacing.margin.b=e,s=!0):e.startsWith("ml-")?(t.spacing.margin.l=e,s=!0):e.startsWith("mx-")?(t.spacing.margin.x=e,s=!0):e.startsWith("my-")?(t.spacing.margin.y=e,s=!0):e.startsWith("p-")?(t.spacing.padding.x=e,t.spacing.padding.y=e,s=!0):e.startsWith("pt-")?(t.spacing.padding.t=e,s=!0):e.startsWith("pr-")?(t.spacing.padding.r=e,s=!0):e.startsWith("pb-")?(t.spacing.padding.b=e,s=!0):e.startsWith("pl-")?(t.spacing.padding.l=e,s=!0):e.startsWith("px-")?(t.spacing.padding.x=e,s=!0):e.startsWith("py-")?(t.spacing.padding.y=e,s=!0):e.startsWith("text-xs")||e.startsWith("text-sm")||e.startsWith("text-base")||e.startsWith("text-lg")||e.startsWith("text-xl")||e.startsWith("text-2xl")||e.startsWith("text-3xl")||e.startsWith("text-4xl")||e.startsWith("text-5xl")||e.startsWith("text-6xl")||e.startsWith("text-7xl")||e.startsWith("text-8xl")||e.startsWith("text-9xl")?(t.typography.size=e,s=!0):e.startsWith("font-")?(t.typography.weight=e,s=!0):e.startsWith("text-left")||e.startsWith("text-center")||e.startsWith("text-right")||e.startsWith("text-justify")?(t.typography.align=e,s=!0):e.startsWith("underline")||e.startsWith("line-through")||e.startsWith("no-underline")?(t.typography.decoration=e,s=!0):e.startsWith("uppercase")||e.startsWith("lowercase")||e.startsWith("capitalize")||e.startsWith("normal-case")?(t.typography.transform=e,s=!0):e.startsWith("tracking-")?(t.typography.tracking=e,s=!0):e.startsWith("leading-")?(t.typography.leading=e,s=!0):e.startsWith("opacity-")?(t.opacity=e,s=!0):e.startsWith("rounded")&&(t.borderRadius=e,s=!0):(t.colors.text=e,s=!0),s||t.other.push(e)}),t}function Gd(e){const t=new Set;if(e.colors&&(e.colors.bg&&t.add(e.colors.bg),e.colors.text&&t.add(e.colors.text)),e.spacing&&e.spacing.margin){const s=e.spacing.margin;s.all?t.add(s.all):(s.t&&t.add(s.t),s.r&&t.add(s.r),s.b&&t.add(s.b),s.l&&t.add(s.l),s.x&&t.add(s.x),s.y&&t.add(s.y))}if(e.spacing&&e.spacing.padding){const s=e.spacing.padding;s.all?t.add(s.all):(s.t&&t.add(s.t),s.r&&t.add(s.r),s.b&&t.add(s.b),s.l&&t.add(s.l),s.x&&t.add(s.x),s.y&&t.add(s.y))}if(e.typography){const{size:s,weight:a,align:n,decoration:l,transform:r,tracking:i,leading:o}=e.typography;s&&t.add(s),a&&t.add(a),n&&t.add(n),l&&t.add(l),r&&t.add(r),i&&t.add(i),o&&t.add(o)}return e.opacity&&t.add(e.opacity),e.borderRadius&&t.add(e.borderRadius),e.other&&Array.isArray(e.other)&&e.other.forEach(e=>{e&&t.add(e)}),Array.from(t).join(" ")}const $d=[0,2,4,6,8,10,12,14,16,20,24,28,32,40,48,64,9999];function Jd(e){let{parsedClasses:t,onBorderRadiusChange:s}=e;const[a,n]=(0,Y.useState)("simple"),[l,r]=(0,Y.useState)({all:4,tl:4,tr:4,br:4,bl:4}),i=(0,Y.useRef)(null);(0,Y.useEffect)(()=>{const e={all:4,tl:4,tr:4,br:4,bl:4};let s=!1;const a=t.borderRadius;if(a&&"rounded"!==a)if("rounded-none"===a)e.all=0;else if("rounded-sm"===a)e.all=2;else if("rounded-md"===a)e.all=6;else if("rounded-lg"===a)e.all=8;else if("rounded-xl"===a)e.all=12;else if("rounded-2xl"===a)e.all=16;else if("rounded-3xl"===a)e.all=24;else if("rounded-full"===a)e.all=9999;else if(a.startsWith("rounded-[")&&a.endsWith("]")){const t=a.match(/rounded-\[(\d+)px_(\d+)px_(\d+)px_(\d+)px\]/);if(t)e.tl=parseInt(t[1]),e.tr=parseInt(t[2]),e.br=parseInt(t[3]),e.bl=parseInt(t[4]),e.all=e.tl,s=!0;else{const t=a.match(/rounded-\[(\d+)px\]/);t&&(e.all=parseInt(t[1]))}}else a.includes(" ")&&(s=!0);else e.all=4;r(e),i.current||n(s?"advanced":"simple")},[t.borderRadius]);const o=e=>0===e?"rounded-none":2===e?"rounded-sm":4===e?"rounded":6===e?"rounded-md":8===e?"rounded-lg":12===e?"rounded-xl":16===e?"rounded-2xl":24===e?"rounded-3xl":9999===e?"rounded-full":"rounded-[".concat(e,"px]"),c=(e,t)=>{if("simple"===t){const t=o(e.all);s(t)}else if(e.tl===e.tr&&e.tr===e.br&&e.br===e.bl){const t=o(e.tl);s(t)}else{const t="rounded-[".concat(e.tl,"px_").concat(e.tr,"px_").concat(e.br,"px_").concat(e.bl,"px]");s(t)}},d=(e,t)=>{const s=Math.max(0,t),n=(0,K.A)({},l);n[e]=s,"simple"!==a&&"all"!==e||(n.tl=s,n.tr=s,n.br=s,n.bl=s),r(n),c(n,a)},m=(e,t)=>{const s=l[e];if(t){const t=$d.find(e=>e>s);d(e,void 0!==t?t:s+4)}else{const t=[...$d].reverse().find(e=>e{if(n(e),i.current=e,"simple"===e){const t={all:l.tl,tl:l.tl,tr:l.tl,br:l.tl,bl:l.tl};r(t),c(t,e)}},x=e=>{let{label:t,value:s,onChange:a}=e;return(0,le.jsx)("div",{className:"flex items-center space-x-2",children:(0,le.jsx)("div",{className:"flex-1 flex items-center",children:(0,le.jsx)("div",{className:"relative flex-1 w-full min-w-[90px] max-w-[140px]",children:(0,le.jsxs)("div",{className:"relative w-full",children:[(0,le.jsx)("input",{type:"text",value:s,onChange:e=>{const t=e.target.value;if(""===t||"-"===t)return void a(0);const s=parseInt(t);isNaN(s)||a(s)},onBlur:e=>{const t=parseInt(e.target.value);(isNaN(t)||t<0)&&a(0)},className:"w-full pl-3 pr-12 py-1.5 rounded-md bg-gray-100 hover:bg-gray-200 hover:text-indigo-600 disabled:opacity-30 disabled:hover:text-gray-500 focus:ring-1 focus:ring-gray-300 text-sm"}),(0,le.jsx)("div",{className:"absolute inset-y-0 right-0 flex items-center pr-1",children:(0,le.jsx)("span",{className:"text-xs text-gray-400 mr-1",children:"px"})}),(0,le.jsxs)("div",{className:"absolute inset-y-0 right-6 flex flex-col",children:[(0,le.jsx)("button",{type:"button",onClick:()=>m(t.toLowerCase(),!0),className:"flex-1 px-1 flex items-center justify-center hover:text-indigo-600 disabled:opacity-30 disabled:hover:text-gray-500",children:(0,le.jsx)(Ts.A,{className:"h-3 w-3"})}),(0,le.jsx)("button",{type:"button",onClick:()=>m(t.toLowerCase(),!1),disabled:s<=0,className:"flex-1 px-1 flex items-center justify-center hover:text-indigo-600 disabled:opacity-30 disabled:hover:text-gray-500",children:(0,le.jsx)(Is.A,{className:"h-3 w-3"})})]})]})})})})},h=e=>{let{children:t}=e;return(0,le.jsx)("span",{className:"text-xs text-gray-500 font-mono w-6",children:t})};return(0,le.jsxs)("div",{className:"space-y-3",children:[(0,le.jsx)("div",{className:"flex items-center justify-between gap-3",children:(0,le.jsx)("label",{className:"text-sm font-medium text-gray-700",children:"Corner Radius"})}),(0,le.jsxs)("div",{className:"space-y-2",children:["simple"===a&&(0,le.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,le.jsx)("div",{className:"flex-1",children:(0,le.jsx)(x,{label:"all",value:l.all,onChange:e=>d("all",e)})}),(0,le.jsx)("button",{type:"button",className:"p-1.5 rounded bg-gray-100 text-gray-700 hover:bg-gray-200 shrink-0",onClick:()=>u("advanced"),title:"Show individual corners",children:(0,le.jsx)(Ed.A,{size:14})})]}),"advanced"===a&&(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsxs)("div",{className:"flex gap-2",children:[(0,le.jsxs)("div",{className:"flex items-center gap-1 flex-1",children:[(0,le.jsx)(h,{children:(0,le.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",children:[(0,le.jsx)("rect",{width:"24",height:"24",fill:"white"}),(0,le.jsx)("path",{"fill-rule":"evenodd","clip-rule":"evenodd",d:"M5 9.5V20H4V9.5C4 7.01472 6.01472 5 8.5 5H19V6H8.5C6.567 6 5 7.567 5 9.5Z",fill:"#767574"})]})}),(0,le.jsx)(x,{label:"tl",value:l.tl,onChange:e=>d("tl",e)})]}),(0,le.jsxs)("div",{className:"flex items-center gap-1 flex-1",children:[(0,le.jsx)(h,{children:(0,le.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",children:[(0,le.jsxs)("g",{"clip-path":"url(#clip0_22_5272)",children:[(0,le.jsx)("rect",{width:"24",height:"24",fill:"white"}),(0,le.jsx)("mask",{id:"mask0_22_5272",maskUnits:"userSpaceOnUse",x:"0",y:"0",width:"24",height:"24",children:(0,le.jsx)("path",{d:"M24 0H0V24H24V0Z",fill:"white"})}),(0,le.jsx)("g",{mask:"url(#mask0_22_5272)",children:(0,le.jsx)("path",{"fill-rule":"evenodd","clip-rule":"evenodd",d:"M14.5 6H4V5H14.5C16.9853 5 19 7.01472 19 9.5V20H18V9.5C18 7.567 16.433 6 14.5 6Z",fill:"#767574"})})]}),(0,le.jsx)("defs",{children:(0,le.jsx)("clipPath",{id:"clip0_22_5272",children:(0,le.jsx)("rect",{width:"24",height:"24",fill:"white"})})})]})}),(0,le.jsx)(x,{label:"tr",value:l.tr,onChange:e=>d("tr",e)})]})]}),(0,le.jsxs)("div",{className:"flex gap-2",children:[(0,le.jsxs)("div",{className:"flex items-center gap-1 flex-1",children:[(0,le.jsx)(h,{children:(0,le.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",children:[(0,le.jsxs)("g",{"clip-path":"url(#clip0_22_5260)",children:[(0,le.jsx)("rect",{width:"24",height:"24",fill:"white"}),(0,le.jsx)("mask",{id:"mask0_22_5260",maskUnits:"userSpaceOnUse",x:"0",y:"0",width:"24",height:"24",children:(0,le.jsx)("path",{d:"M24 0H0V24H24V0Z",fill:"white"})}),(0,le.jsx)("g",{mask:"url(#mask0_22_5260)",children:(0,le.jsx)("path",{"fill-rule":"evenodd","clip-rule":"evenodd",d:"M8.5 19H19V20H8.5C6.01472 20 4 17.9853 4 15.5V5H5V15.5C5 17.433 6.567 19 8.5 19Z",fill:"#767574"})})]}),(0,le.jsx)("defs",{children:(0,le.jsx)("clipPath",{id:"clip0_22_5260",children:(0,le.jsx)("rect",{width:"24",height:"24",fill:"white"})})})]})}),(0,le.jsx)(x,{label:"bl",value:l.bl,onChange:e=>d("bl",e)})]}),(0,le.jsxs)("div",{className:"flex items-center gap-1 flex-1",children:[(0,le.jsx)(h,{children:(0,le.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",children:[(0,le.jsxs)("g",{"clip-path":"url(#clip0_22_5285)",children:[(0,le.jsx)("rect",{width:"24",height:"24",fill:"white"}),(0,le.jsx)("mask",{id:"mask0_22_5285",maskUnits:"userSpaceOnUse",x:"0",y:"0",width:"24",height:"24",children:(0,le.jsx)("path",{d:"M24 0H0V24H24V0Z",fill:"white"})}),(0,le.jsx)("g",{mask:"url(#mask0_22_5285)",children:(0,le.jsx)("path",{"fill-rule":"evenodd","clip-rule":"evenodd",d:"M18 15.5V5H19V15.5C19 17.9853 16.9853 20 14.5 20H4V19H14.5C16.433 19 18 17.433 18 15.5Z",fill:"#767574"})})]}),(0,le.jsx)("defs",{children:(0,le.jsx)("clipPath",{id:"clip0_22_5285",children:(0,le.jsx)("rect",{width:"24",height:"24",fill:"white"})})})]})}),(0,le.jsx)(x,{label:"br",value:l.br,onChange:e=>d("br",e)})]})]}),(0,le.jsx)("button",{type:"button",className:"w-full p-1.5 rounded bg-indigo-50 text-gray-700 hover:bg-indigo-100 text-xs font-medium",onClick:()=>u("simple"),title:"Show all corners",children:"Show all corners"})]})]})]})}function Zd(e){let{icon:t,tooltip:s,children:a,isOpen:n,onToggle:l,align:r="left",availableSpace:i,direction:o="bottom"}=e;const c=(0,Y.useRef)(null),d=(()=>{if("auto"!==r)return r;if(i){const e=280,t=10;if(i.right=e+t)return"right";if(i.righti.right?"right":"left"}}return"left"})();return(0,Y.useEffect)(()=>{function e(e){c.current&&!c.current.contains(e.target)&&l(!1)}return n&&document.addEventListener("mousedown",e),()=>{document.removeEventListener("mousedown",e)}},[n,l]),(0,le.jsxs)("div",{className:"relative",ref:c,children:[(0,le.jsxs)(Et,{children:[(0,le.jsx)(It,{asChild:!0,children:(0,le.jsx)("button",{onClick:()=>l(!n),className:"flex items-center justify-center w-[32px] h-[32px] rounded transition-colors duration-200 ".concat(n?"bg-gray-300 text-black":"text-gray-700 hover:text-gray-900 hover:bg-gray-100"),children:t})}),(0,le.jsx)(Tt,{children:(0,le.jsx)("p",{children:s})})]}),n&&(0,le.jsx)("div",{className:"absolute bg-white border border-gray-200 rounded-lg shadow-lg z-[10000] min-w-[280px] ".concat("top"===o?"bottom-full mb-1":"top-full mt-1"," ").concat("right"===d?"right-0":"left-0"),children:(0,le.jsx)("div",{className:"p-3",children:a})})]})}function Kd(e){let{element:t,onContentChange:s,isOpen:a,onToggle:n,availableSpace:l,direction:r}=e;return t.isTextElement?(0,le.jsx)(Zd,{icon:(0,le.jsx)("svg",{width:"18",height:"18",viewBox:"0 0 18 18",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:(0,le.jsx)("path",{d:"M14.25 3C14.6642 3 15 3.33579 15 3.75V6C15 6.41421 14.6642 6.75 14.25 6.75C13.8358 6.75 13.5 6.41421 13.5 6V4.5H9.75V13.5H11.25C11.6642 13.5 12 13.8358 12 14.25C12 14.6642 11.6642 15 11.25 15H6.75C6.33579 15 6 14.6642 6 14.25C6 13.8358 6.33579 13.5 6.75 13.5H8.25V4.5H4.5V6C4.5 6.41421 4.16421 6.75 3.75 6.75C3.33579 6.75 3 6.41421 3 6V3.75C3 3.33579 3.33579 3 3.75 3H14.25Z",fill:"#545454"})}),tooltip:"Edit content",isOpen:a,onToggle:n,align:"auto",availableSpace:l,direction:r,children:(0,le.jsxs)("div",{className:"space-y-3",children:[(0,le.jsx)("div",{className:"flex items-center justify-between",children:(0,le.jsx)("label",{className:"text-sm font-medium text-gray-700",children:"Text Content"})}),t.isDynamicContent?(0,le.jsx)("p",{className:"text-xs text-gray-500 bg-gray-50 p-2 rounded",children:"This content is dynamically generated and cannot be edited directly. You can modify the content via the chat."}):(0,le.jsx)("textarea",{className:"w-full p-2 border border-gray-200 text-sm rounded focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent resize-none",rows:3,value:t.content||"",onChange:e=>s(e.target.value),placeholder:"Enter text content..."})]})}):null}function Qd(e){let{parsedClasses:t,onColorChange:s,isOpen:a,onToggle:n,resetKey:l,availableSpace:r,direction:i}=e;const[o,c]=(0,Y.useState)(null);(0,Y.useEffect)(()=>{c(null)},[l]);const d=e=>{c(e)},m=e=>{c(null)};return(0,le.jsx)(Zd,{icon:(0,le.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:[(0,le.jsxs)("g",{"clip-path":"url(#clip0_23_2101)",children:[(0,le.jsx)("path",{d:"M12.6667 7.33333L7.33335 2L1.60002 7.73333C1.35571 7.98257 1.21887 8.31766 1.21887 8.66667C1.21887 9.01567 1.35571 9.35076 1.60002 9.6L5.06668 13.0667C5.60002 13.6 6.40002 13.6 6.93335 13.0667L12.6667 7.33333Z",stroke:"#545454","stroke-width":"1.33333","stroke-linecap":"round","stroke-linejoin":"round"}),(0,le.jsx)("path",{d:"M3.33331 1.33334L6.66665 4.66668",stroke:"#545454","stroke-width":"1.33333","stroke-linecap":"round","stroke-linejoin":"round"}),(0,le.jsx)("path",{d:"M1.33331 8.66666H11.3333",stroke:"#545454","stroke-width":"1.33333","stroke-linecap":"round","stroke-linejoin":"round"}),(0,le.jsx)("path",{d:"M14.6667 13.3333C14.6667 13.6869 14.5262 14.0261 14.2761 14.2761C14.0261 14.5262 13.687 14.6667 13.3333 14.6667C12.9797 14.6667 12.6406 14.5262 12.3905 14.2761C12.1405 14.0261 12 13.6869 12 13.3333C12 12.2667 13.1333 11.7333 13.3333 10.6667C13.5333 11.7333 14.6667 12.2667 14.6667 13.3333Z",stroke:"#545454","stroke-width":"1.33333","stroke-linecap":"round","stroke-linejoin":"round"})]}),(0,le.jsx)("defs",{children:(0,le.jsx)("clipPath",{id:"clip0_23_2101",children:(0,le.jsx)("rect",{width:"16",height:"16",fill:"white"})})})]}),tooltip:"Colors",isOpen:a,onToggle:n,align:"auto",availableSpace:r,direction:i,children:(0,le.jsxs)("div",{className:"space-y-4",children:[(0,le.jsx)("div",{className:"relative ".concat("Background"===o?"z-[10025]":"z-0"),children:(0,le.jsx)(wd,{label:"Background",selectedColor:t.colors.bg,onChange:e=>s("bg",e),zIndexClass:"z-[10020]",onOpen:d,onClose:m,shouldClose:null!==o&&"Background"!==o,forceClose:l,direction:i})}),(0,le.jsx)("div",{className:"relative ".concat("Text Color"===o?"z-[10025]":"z-0"),children:(0,le.jsx)(wd,{label:"Text Color",selectedColor:t.colors.text,onChange:e=>s("text",e),zIndexClass:"z-[10020]",onOpen:d,onClose:m,shouldClose:null!==o&&"Text Color"!==o,forceClose:l,direction:i})})]})})}function Xd(e){let{element:t,parsedClasses:s,onTypographyChange:a,isOpen:n,onToggle:l,availableSpace:r,direction:i}=e;const[o,c]=(0,Y.useState)(0);if(!t.isTextElement)return null;return(0,le.jsx)(Zd,{icon:(0,le.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 18 18",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[(0,le.jsx)("path",{d:"M5.5 5.25V4.5H12.5V5.25C12.5 5.66 12.84 6 13.25 6C13.66 6 14 5.66 14 5.25V4C14 3.45 13.55 3 13 3H5C4.45 3 4 3.45 4 4V5.25C4 5.66 4.34 6 4.75 6C5.16 6 5.5 5.66 5.5 5.25Z",fill:"#545454"}),(0,le.jsx)("path",{d:"M9 3V12",stroke:"#545454","stroke-width":"1.5","stroke-miterlimit":"10"}),(0,le.jsx)("path",{d:"M11.25 10.5H6.75C6.33579 10.5 6 10.8358 6 11.25C6 11.6642 6.33579 12 6.75 12H11.25C11.6642 12 12 11.6642 12 11.25C12 10.8358 11.6642 10.5 11.25 10.5Z",fill:"#545454"}),(0,le.jsx)("path",{d:"M3.75 14.25H14.25",stroke:"#545454","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round"})]}),tooltip:"Text style",isOpen:n,onToggle:l,align:"auto",availableSpace:r,direction:i,children:(0,le.jsxs)("div",{className:"space-y-3",onClick:e=>{const t=e.target;"BUTTON"===t.tagName||"INPUT"===t.tagName||t.closest("button")||t.closest('[role="combobox"]')||c(e=>e+1)},children:[(0,le.jsx)("div",{className:"flex items-center justify-between",children:(0,le.jsx)("label",{className:"text-sm font-medium text-gray-700",children:"Text Style"})}),(0,le.jsx)(Hd,{typography:s.typography,onChange:a,zIndexClass:"z-[10020]",forceClose:o,direction:i})]})})}function em(e){let{parsedClasses:t,onSpacingChange:s,isOpen:a,onToggle:n,availableSpace:l,direction:r}=e;return(0,le.jsx)(Zd,{icon:(0,le.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[(0,le.jsx)("path",{d:"M8.66667 4.66666H7.33333C6.59695 4.66666 6 5.26361 6 5.99999V9.99999C6 10.7364 6.59695 11.3333 7.33333 11.3333H8.66667C9.40305 11.3333 10 10.7364 10 9.99999V5.99999C10 5.26361 9.40305 4.66666 8.66667 4.66666Z",stroke:"#545454","stroke-width":"1.33333","stroke-linecap":"round","stroke-linejoin":"round"}),(0,le.jsx)("path",{d:"M2.66663 14.6667V1.33334",stroke:"#545454","stroke-width":"1.33333","stroke-linecap":"round","stroke-linejoin":"round"}),(0,le.jsx)("path",{d:"M13.3334 14.6667V1.33334",stroke:"#545454","stroke-width":"1.33333","stroke-linecap":"round","stroke-linejoin":"round"})]}),tooltip:"Spacing",isOpen:a,onToggle:n,align:"auto",availableSpace:l,direction:r,children:(0,le.jsxs)("div",{className:"space-y-4",children:[(0,le.jsx)("div",{children:(0,le.jsx)(Td,{label:"Margin",spacing:t.spacing.margin||{},onChange:e=>s("margin",e)})}),(0,le.jsx)("div",{className:"border-t border-gray-100 pt-4",children:(0,le.jsx)(Td,{label:"Padding",spacing:t.spacing.padding||{},onChange:e=>s("padding",e)})})]})})}function tm(e){let{parsedClasses:t,onOpacityChange:s,isOpen:a,onToggle:n,availableSpace:l,direction:r}=e;const i=(e=>{if(!e)return 100;const t=e.match(/opacity-(\d+)/);return t?parseInt(t[1]):100})(t.opacity);return(0,le.jsx)(Zd,{icon:(0,le.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:[(0,le.jsxs)("g",{"clip-path":"url(#clip0_23_2106)",children:[(0,le.jsx)("path",{d:"M6.00004 10.6667C8.57737 10.6667 10.6667 8.57734 10.6667 6.00001C10.6667 3.42268 8.57737 1.33334 6.00004 1.33334C3.42271 1.33334 1.33337 3.42268 1.33337 6.00001C1.33337 8.57734 3.42271 10.6667 6.00004 10.6667Z",stroke:"#545454","stroke-width":"1.33333","stroke-linecap":"round","stroke-linejoin":"round"}),(0,le.jsx)("path",{d:"M10 14.6667C12.5774 14.6667 14.6667 12.5773 14.6667 10C14.6667 7.42268 12.5774 5.33334 10 5.33334C7.42271 5.33334 5.33337 7.42268 5.33337 10C5.33337 12.5773 7.42271 14.6667 10 14.6667Z",stroke:"#545454","stroke-width":"1.33333","stroke-linecap":"round","stroke-linejoin":"round"})]}),(0,le.jsx)("defs",{children:(0,le.jsx)("clipPath",{id:"clip0_23_2106",children:(0,le.jsx)("rect",{width:"16",height:"16",fill:"white"})})})]}),tooltip:"Opacity",isOpen:a,onToggle:n,align:"auto",availableSpace:l,direction:r,children:(0,le.jsxs)("div",{className:"space-y-3",children:[(0,le.jsx)("label",{className:"text-sm font-medium text-gray-700",children:"Opacity"}),(0,le.jsxs)("div",{className:"flex items-center gap-3",children:[(0,le.jsx)("input",{type:"range",min:"0",max:"100",step:"5",value:i,onChange:e=>{return s((t=parseInt(e.target.value),"opacity-".concat(t)));var t},className:"flex-1 h-2 bg-gray-200 rounded-lg appearance-none cursor-pointer accent-blue-500"}),(0,le.jsxs)("span",{className:"text-sm text-gray-500 min-w-[3rem] text-right",children:[i,"%"]})]})]})})}function sm(e){let{parsedClasses:t,onBorderRadiusChange:s,isOpen:a,onToggle:n,availableSpace:l,direction:r}=e;return(0,le.jsx)(Zd,{icon:(0,le.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[(0,le.jsx)("path",{d:"M14 7.33333C14 5.91885 13.4381 4.56229 12.4379 3.5621C11.4377 2.5619 10.0811 2 8.66663 2",stroke:"#545454","stroke-width":"1.33333","stroke-linecap":"round","stroke-linejoin":"round"}),(0,le.jsx)("path",{d:"M14 10V12.6667C14 13.0203 13.8595 13.3594 13.6095 13.6095C13.3594 13.8595 13.0203 14 12.6667 14H3.33333C2.97971 14 2.64057 13.8595 2.39052 13.6095C2.14048 13.3594 2 13.0203 2 12.6667V3.33333C2 2.97971 2.14048 2.64057 2.39052 2.39052C2.64057 2.14048 2.97971 2 3.33333 2H6",stroke:"#545454","stroke-width":"1.33333","stroke-linecap":"round","stroke-linejoin":"round"})]}),tooltip:"Corners",isOpen:a,onToggle:n,align:"auto",availableSpace:l,direction:r,children:(0,le.jsx)(Jd,{parsedClasses:t,onBorderRadiusChange:s})})}function am(e){let{rawClasses:t,onRawClassChange:s,isOpen:a,onToggle:n,availableSpace:l,direction:r}=e;return(0,le.jsx)(Zd,{icon:(0,le.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[(0,le.jsx)("path",{d:"M14.6667 11.3333C14.6667 11.687 14.5262 12.0261 14.2762 12.2761C14.0261 12.5262 13.687 12.6667 13.3334 12.6667H4.55204C4.19845 12.6667 3.85936 12.8073 3.60937 13.0573L2.14137 14.5253C2.07518 14.5915 1.99084 14.6366 1.89903 14.6548C1.80722 14.6731 1.71206 14.6637 1.62558 14.6279C1.5391 14.5921 1.46518 14.5314 1.41316 14.4536C1.36115 14.3758 1.33339 14.2843 1.33337 14.1907V3.33333C1.33337 2.97971 1.47385 2.64057 1.7239 2.39052C1.97395 2.14048 2.31309 2 2.66671 2H13.3334C13.687 2 14.0261 2.14048 14.2762 2.39052C14.5262 2.64057 14.6667 2.97971 14.6667 3.33333V11.3333Z",stroke:"#545454","stroke-width":"1.33333","stroke-linecap":"round","stroke-linejoin":"round"}),(0,le.jsx)("path",{d:"M6.66663 5.33334L4.66663 7.33334L6.66663 9.33334",stroke:"#545454","stroke-width":"1.33333","stroke-linecap":"round","stroke-linejoin":"round"}),(0,le.jsx)("path",{d:"M9.33337 9.33334L11.3334 7.33334L9.33337 5.33334",stroke:"#545454","stroke-width":"1.33333","stroke-linecap":"round","stroke-linejoin":"round"})]}),tooltip:"Edit Tailwind",isOpen:a,onToggle:n,align:"auto",availableSpace:l,direction:r,children:(0,le.jsxs)("div",{className:"space-y-3",children:[(0,le.jsx)("div",{className:"flex items-center justify-between",children:(0,le.jsx)("label",{className:"text-sm font-medium text-gray-700",children:"Tailwind Classes"})}),(0,le.jsx)("textarea",{className:"w-full p-2 border border-gray-200 text-sm font-mono rounded focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent resize-none",rows:4,value:t,onChange:s,placeholder:"Enter Tailwind classes..."}),(0,le.jsx)("p",{className:"text-xs text-gray-500",children:"Enter custom Tailwind CSS classes for advanced styling"})]})})}function nm(e){var t,s,a,n;let{element:l,onChange:r,onContentChange:i,onDragStart:o,onClose:c,iframeRef:d,onCodeNavigation:m,onAskClick:u,onOpenDropdownsChange:x,popoverPosition:h,dropdownDirection:p="bottom",dimensions:g,currentElement:f,addToChangedElements:v,hasUnsavedChanges:b,isDiscussionMode:j}=e;const[y,N]=(0,Y.useState)({}),w=null!==(t=null==f?void 0:f.key)&&void 0!==t?t:null,_=null!==(s=null==f?void 0:f.parsedClasses)&&void 0!==s?s:{colors:{bg:null,text:null},spacing:{margin:{t:null,r:null,b:null,l:null,x:null,y:null,all:null},padding:{t:null,r:null,b:null,l:null,x:null,y:null,all:null}},typography:{size:null,weight:null,align:null,decoration:null,transform:null,tracking:null,leading:null},opacity:null,borderRadius:null,other:[]},k=null!==(a=null==f?void 0:f.rawClasses)&&void 0!==a?a:"",C=null!==(n=null==f?void 0:f.updateClasses)&&void 0!==n?n:()=>{},A=null!=v?v:()=>{},S=h||{left:300,right:300};(0,Y.useEffect)(()=>{if(l){(l.dataSourceLocation||l.tagName+JSON.stringify(l.linenumber))!==w&&N({})}},[null==l?void 0:l.dataSourceLocation,null==l?void 0:l.linenumber,null==l?void 0:l.tagName,w]);const E=(e,t)=>{N(s=>(0,K.A)((0,K.A)({},s),{},{[e]:t}))};(0,Y.useEffect)(()=>{const e=e=>{var t;"close-dropdowns"===(null===(t=e.data)||void 0===t?void 0:t.type)&&N({})};return window.addEventListener("message",e),()=>{window.removeEventListener("message",e)}},[]),(0,Y.useEffect)(()=>{var e;if(x&&x(y),null!=d&&null!==(e=d.current)&&void 0!==e&&e.contentWindow){const e=Object.values(y).some(Boolean);d.current.contentWindow.postMessage({type:"dropdown-state",data:{isOpen:e}},"*")}},[y,x,d]);const I=g?{minHeight:g.minHeight}:{};return(0,le.jsxs)("div",{className:(null==g?void 0:g.containerClassName)||"flex items-center bg-[#feffff] rounded-[10px] border border-[#E5E5E5] shadow-[0_6px_6px_0_rgba(22,45,61,0.06),0_0_18px_0_rgba(22,45,61,0.12)]",style:I,children:[(0,le.jsx)("div",{className:"flex items-center gap-2 px-2 py-2",children:(0,le.jsxs)("div",{className:"flex items-center gap-1",children:[u&&(0,le.jsxs)(Et,{children:[(0,le.jsx)(It,{asChild:!0,children:(0,le.jsx)("button",{disabled:b,onClick:u,className:"flex items-center gap-1.5 px-2.5 py-[7px] rounded-md text-[12px] transition-all duration-200 text-black whitespace-nowrap ".concat(j?"bg-violet-50 hover:bg-violet-100":"bg-[#F5F5F5] hover:bg-gray-200"," ").concat(!j&&b&&"text-gray-400 hover:bg-[#F5F5F5]"),children:(0,le.jsx)("span",{className:"font-[500] font-base44 ".concat(b?"text-gray-400":j?"text-violet-600":""),children:j?"Discuss":"Edit Element"})})}),(0,le.jsx)(Tt,{children:b&&(0,le.jsx)("p",{children:"Save changes before typing"})})]}),(0,le.jsx)(Kd,{element:l,onContentChange:e=>{A("content",e),i(e)},isOpen:y.content||!1,onToggle:e=>E("content",e),availableSpace:S,direction:p}),(0,le.jsx)(Xd,{element:l,parsedClasses:_,onTypographyChange:e=>{const t=(0,K.A)({},_);t.typography=(0,K.A)((0,K.A)({},t.typography),e);const s=Gd(t);C(s),A("classes",s),r(s)},isOpen:y.typography||!1,onToggle:e=>E("typography",e),availableSpace:S,direction:p}),(0,le.jsx)(Qd,{parsedClasses:_,onColorChange:(e,t)=>{const s=(0,K.A)({},_);s.colors[e]=t;const a=Gd(s);C(a),A("classes",a),r(a)},isOpen:y.colors||!1,onToggle:e=>E("colors",e),resetKey:w,availableSpace:S,direction:p}),(0,le.jsx)(tm,{parsedClasses:_,onOpacityChange:e=>{const t=(0,K.A)({},_);t.opacity=e;const s=Gd(t);C(s),A("classes",s),r(s)},isOpen:y.transparency||!1,onToggle:e=>E("transparency",e),availableSpace:S,direction:p}),(0,le.jsx)(em,{parsedClasses:_,onSpacingChange:(e,t)=>{const s=(0,K.A)({},_);s.spacing[e]=t;const a=Gd(s);C(a),A("classes",a),r(a)},isOpen:y.spacing||!1,onToggle:e=>E("spacing",e),availableSpace:S,direction:p}),(0,le.jsx)(sm,{parsedClasses:_,onBorderRadiusChange:e=>{const t=(0,K.A)({},_);t.borderRadius=e;const s=Gd(t);C(s),A("classes",s),r(s)},isOpen:y.borderRadius||!1,onToggle:e=>E("borderRadius",e),availableSpace:S,direction:p}),(0,le.jsx)(am,{rawClasses:k,onRawClassChange:e=>{const t=e.target.value;C(t),A("classes",t),r(t)},isOpen:y.advanced||!1,onToggle:e=>E("advanced",e),availableSpace:S,direction:p}),l.dataSourceLocation&&m&&(0,le.jsxs)(Et,{children:[(0,le.jsx)(It,{asChild:!0,children:(0,le.jsx)("button",{onClick:m,className:"flex items-center justify-center w-7 h-7 text-gray-600 hover:text-gray-700 hover:bg-gray-100 rounded transition-colors duration-200",children:(0,le.jsx)(Kl.A,{className:"h-3.5 w-3.5"})})}),(0,le.jsx)(Tt,{children:(0,le.jsx)("p",{children:"Code"})})]})]})}),l.dataSourceLocation&&m&&(0,le.jsx)("div",{className:"w-px h-6 bg-gray-200"}),(0,le.jsx)("div",{onClick:c,className:"flex items-center justify-center w-6 h-8 m-1 text-[#545454] hover:text-gray-600 hover:text-black cursor-pointer",title:"Close editor",children:(0,le.jsx)(Bt.A,{className:"h-3 w-3"})})]})}function lm(e){let{element:t,onAskQuestion:s,onClose:a,onBack:n,dimensions:l,isDiscussionMode:r}=e;const[i,o]=(0,Y.useState)(""),[c,d]=(0,Y.useState)(!1),m=(0,Y.useRef)(null),u=e=>{e&&e.preventDefault(),i.trim()&&s&&!c&&(d(!0),s(i,t),o(""))};if((0,Y.useEffect)(()=>{m.current&&m.current.focus()},[]),(0,Y.useEffect)(()=>{if(c){const e=setTimeout(()=>{a()},3e3);return()=>clearTimeout(e)}},[c,a]),!s)return null;const x=l?(0,K.A)({minHeight:l.minHeight},l.width?{width:"".concat(l.width,"px")}:{}):{};return(0,le.jsxs)("div",{className:(null==l?void 0:l.containerClassName)||"flex font-base44 items-center bg-[#feffff] rounded-[10px] border border-[#E5E5E5] shadow-[0_6px_6px_0_rgba(22,45,61,0.06),0_0_18px_0_rgba(22,45,61,0.12)]",style:x,children:[(0,le.jsx)("div",{onClick:n,className:"flex items-center justify-center w-8 h-8 text-[#545454] hover:text-gray-900 cursor-pointer ml-1",title:"Back to editor",children:(0,le.jsx)(Cd.A,{className:"h-4 w-4"})}),(0,le.jsxs)("form",{onSubmit:u,className:"flex-1 flex items-center px-2 py-2 gap-2",children:[(0,le.jsx)("input",{ref:m,type:"text",value:i,onChange:e=>o(e.target.value),onKeyDown:e=>{"Escape"===e.key&&a()},placeholder:r?"What to discuss?":"What to change?",disabled:c,className:"flex-1 px-2 py-1 text-sm border-none focus:outline-none focus:ring-0 bg-transparent disabled:opacity-50"}),(0,le.jsx)("button",{type:"button",onClick:()=>u(),disabled:!i.trim()||c,className:"flex justify-center items-center w-7 h-7 p-1 rounded-[8px] transition-colors ".concat(!i.trim()||c?r?"bg-purple-300 cursor-not-allowed":"bg-blue-300 cursor-not-allowed":r?"bg-purple-600 hover:bg-purple-700":"bg-blue-600 hover:bg-blue-700"," text-white"),title:c?"Processing...":"Send message",children:c?(0,le.jsx)(Ne.A,{className:"w-4 h-4 animate-spin"}):(0,le.jsx)(Dt.A,{className:"w-4 h-4"})})]}),(0,le.jsx)("div",{className:"w-px h-6 bg-gray-200"}),(0,le.jsx)("div",{onClick:a,className:"flex items-center justify-center w-6 h-8 m-1 text-[#545454] hover:text-gray-900 hover:text-black cursor-pointer",title:"Cancel",children:(0,le.jsx)(Bt.A,{className:"h-3 w-3"})})]})}const rm={minHeight:"50px",containerClassName:"flex font-base44 items-center bg-[#feffff] rounded-[10px] border border-[#E5E5E5] shadow-[0_6px_6px_0_rgba(22,45,61,0.06),0_0_18px_0_rgba(22,45,61,0.12)]"};function im(e){let{isVisible:t,selectedElement:s,position:a,onClose:n,onSave:l,onDiscard:r,onChange:i,onContentChange:o,isSaving:c,onElementRevert:d,onAskQuestion:m,openDropdowns:u={},onOpenDropdownsChange:x,currentElement:h,addToChangedElements:p,hasUnsavedChanges:g,isDiscussionMode:f}=e;const v=(0,Z.Zp)(),{app:b,previewIframeRef:j}=Nt(),y=(0,Y.useRef)(null),[N,w]=(0,Y.useState)({top:0,left:0}),[_,k]=(0,Y.useState)(!1),[C,A]=(0,Y.useState)({x:0,y:0}),[S,E]=(0,Y.useState)(null),[I,T]=(0,Y.useState)(!0),[P,L]=(0,Y.useState)("bottom"),[O,R]=(0,Y.useState)(!1),[M,D]=(0,Y.useState)(null),F=(0,Y.useRef)(null);(0,Y.useEffect)(()=>{var e;if(!t||!a||null==j||!j.current)return;const n=j.current.getBoundingClientRect(),l=n.top+a.top,r=n.left+a.left,i=40,o=Math.min(350,Math.max(200,.25*window.innerWidth)),c=window.innerWidth,d=window.innerHeight,m=(null==s||null===(e=s.tagName)||void 0===e?void 0:e.toLowerCase())||"",u=["body","html","main"].includes(m)||a.height>.5*d||a.width>.8*c,x=d-(l+a.height),h=l;let p,g;u?(p=r+10,g=l+10):(p=r,g=l+a.height+10,x<60&&(g=h>=60?l-i-10:Math.max(l+10,l+a.height/2-20)),p+o>c-10&&(p=Math.max(10,r+a.width-o))),p+o>c&&(p=c-o-10),p<10&&(p=10),g+i>d&&(g=d-i-10),g<10&&(g=10);L(g>d-d/3||d-(g+i)<250?"top":"bottom"),w(S||{top:g,left:p})},[t,a,j,null==s?void 0:s.tagName,S]),(0,Y.useEffect)(()=>{if(!t||null==j||!j.current)return;const e=e=>{if("element-position-update"===e.data.type&&e.data.position){const t=!1!==e.data.isInViewport;T(t);const s=j.current;if(s){const t=s.getBoundingClientRect(),a=t.top+e.data.position.top,n=t.left+e.data.position.left,l=40,r=Math.min(350,Math.max(200,.25*window.innerWidth)),i=window.innerWidth,o=window.innerHeight;let c=n,d=a+e.data.position.height+10;d+l>o&&(d=a-l-10),c+r>i&&(c=i-r-10),c<10&&(c=10),d<10&&(d=10),S||w({top:d,left:c})}}};var s,a;return window.addEventListener("message",e),null===(s=j.current)||void 0===s||null===(a=s.contentWindow)||void 0===a||a.postMessage({type:"request-element-position"},"*"),()=>{window.removeEventListener("message",e)}},[t,j]),(0,Y.useEffect)(()=>{const e=e=>{"Escape"===e.key&&t&&n()};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[t,n]);const B=e=>{if(!_)return;const t={left:e.clientX-C.x,top:e.clientY-C.y},s=Math.min(350,Math.max(200,.25*window.innerWidth)),a=window.innerWidth,n=window.innerHeight;t.left=Math.max(10,Math.min(t.left,a-s-10)),t.top=Math.max(10,Math.min(t.top,n-40-10));const l=n-(t.top+40),r=n/3,i=t.top>n-r||l<250;L(i?"top":"bottom"),E(t),w(t)},z=()=>{var e,t;k(!1),null===(e=j.current)||void 0===e||null===(t=e.contentWindow)||void 0===t||t.postMessage({type:"popover-drag-state",data:{isDragging:!1}},"*")};(0,Y.useEffect)(()=>(_&&(document.addEventListener("mousemove",B),document.addEventListener("mouseup",z)),()=>{document.removeEventListener("mousemove",B),document.removeEventListener("mouseup",z)}),[_,C]),(0,Y.useEffect)(()=>{t||(E(null),T(!0))},[t]),(0,Y.useEffect)(()=>{t&&s&&T(!0)},[s,t]),(0,Y.useEffect)(()=>{s&&R(!1)},[s]),(0,Y.useEffect)(()=>{if(!O&&F.current){const e=F.current.offsetWidth;D(e)}},[O,s]);if(!t||!s)return null;const U=(0,le.jsx)("div",{ref:y,className:"fixed z-[9999] transition-opacity duration-200",style:{top:N.top,left:N.left,cursor:_?"grabbing":"default",opacity:I?1:0,pointerEvents:I?"auto":"none"},children:O?(0,le.jsx)(lm,{element:s,onAskQuestion:m,onClose:()=>{n()},onBack:()=>{R(!1)},dimensions:(0,K.A)((0,K.A)({},rm),{},{width:M||void 0}),isDiscussionMode:f}):(0,le.jsx)("div",{ref:F,children:(0,le.jsx)(nm,{element:s,onChange:i,onContentChange:o,onSave:l,onDiscard:r,isSaving:c,onDragStart:e=>{var t,s,a;k(!0);const n=null===(t=y.current)||void 0===t?void 0:t.getBoundingClientRect();n&&A({x:e.clientX-n.left,y:e.clientY-n.top}),null===(s=j.current)||void 0===s||null===(a=s.contentWindow)||void 0===a||a.postMessage({type:"popover-drag-state",data:{isDragging:!0}},"*"),e.preventDefault()},onClose:n,iframeRef:j,onElementRevert:d,onCodeNavigation:()=>{if(null==s||!s.dataSourceLocation||null==b||!b.id)return;const e=s.dataSourceLocation,[t,a]=e.split(":");if(!t)return;const n=encodeURIComponent(t);let l="/apps/".concat(b.id,"/editor/workspace/code?filePath=").concat(n);a&&(l+="&line=".concat(a)),v(l)},onAskQuestion:m,onAskClick:()=>{R(!0)},onOpenDropdownsChange:x,popoverPosition:(()=>{const e=window.innerWidth,t=Math.min(350,Math.max(200,.25*window.innerWidth));return{left:N.left,right:e-(N.left+t)}})(),dropdownDirection:P,dimensions:rm,isDiscussionMode:f,currentElement:h,addToChangedElements:p,hasUnsavedChanges:g})})});return(0,cd.createPortal)(U,document.body)}var om=s(20939);const cm=["className"],dm=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,cm);return(0,le.jsx)(om.bL,(0,K.A)((0,K.A)({ref:t,className:Pe("peer h-4 w-4 shrink-0 rounded-sm border border-primary ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",s)},a),{},{children:(0,le.jsx)(om.C1,{className:Pe("flex items-center justify-center text-current"),children:(0,le.jsx)(Ps.A,{className:"h-4 w-4"})})}))});dm.displayName=om.bL.displayName;const mm=["className"],um=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,mm);return(0,le.jsx)("textarea",(0,K.A)({className:Pe("flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",s),ref:t},a))});um.displayName="Textarea";var xm=s(41443);const hm=["className","children"],pm=["className","orientation"],gm=Y.forwardRef((e,t)=>{let{className:s,children:a}=e,n=(0,Se.A)(e,hm);return(0,le.jsxs)(xm.bL,(0,K.A)((0,K.A)({ref:t,className:Pe("relative overflow-hidden",s)},n),{},{children:[(0,le.jsx)(xm.LM,{className:"h-full w-full rounded-[inherit]",children:a}),(0,le.jsx)(fm,{}),(0,le.jsx)(xm.OK,{})]}))});gm.displayName=xm.bL.displayName;const fm=Y.forwardRef((e,t)=>{let{className:s,orientation:a="vertical"}=e,n=(0,Se.A)(e,pm);return(0,le.jsx)(xm.VM,(0,K.A)((0,K.A)({ref:t,orientation:a,className:Pe("flex touch-none select-none transition-colors","vertical"===a&&"h-full w-2.5 border-l border-l-transparent p-[1px]","horizontal"===a&&"h-2.5 flex-col border-t border-t-transparent p-[1px]",s)},n),{},{children:(0,le.jsx)(xm.lr,{className:"relative flex-1 rounded-full bg-border"})}))});fm.displayName=xm.VM.displayName;var vm=s(89318),bm=s(81745);function jm(e){let{isOpen:t,onClose:s}=e;const{app:a,updateApp:n}=Nt(),[l,r]=(0,Y.useState)(""),[i,o]=(0,Y.useState)([]),[c,d]=(0,Y.useState)([]),[m,u]=(0,Y.useState)(!1);(0,Y.useEffect)(()=>{if(a){r(a.custom_instructions||""),o(a.frozen_files||[]);const e=[["pages",a.pages],["functions",a.functions],["components",a.components]].flatMap(e=>{let[t,s]=e;return Object.keys(s||{}).map(e=>"".concat(t,"/").concat(e))});d(e)}},[a,t]);const x=e=>{o(e?[...c]:[])};return(0,le.jsx)(Pa,{open:t,onOpenChange:s,children:(0,le.jsxs)(Da,{className:"max-w-[90vw] sm:max-w-[500px] p-0 overflow-hidden rounded-lg shadow-lg border-0",children:[(0,le.jsx)(Fa,{className:"px-6 pt-5 pb-3 bg-gradient-to-r from-slate-50 to-gray-50",children:(0,le.jsxs)(za,{className:"flex items-center gap-2 text-lg font-medium",children:[(0,le.jsx)(vm.A,{className:"h-5 w-5 text-gray-700"}),"AI Controls"]})}),(0,le.jsxs)("div",{className:"p-6 space-y-5 overflow-y-auto max-h-[70vh]",children:[(0,le.jsxs)("div",{className:"space-y-3",children:[(0,le.jsx)(Ns,{htmlFor:"custom-instructions",className:"text-sm font-medium flex items-center",children:"Custom Instructions"}),(0,le.jsx)("p",{className:"text-sm text-muted-foreground",children:"Provide additional instructions that will be included in every interaction with the AI. These can help guide the AI's behavior and responses."}),(0,le.jsx)(um,{id:"custom-instructions",value:l,onChange:e=>r(e.target.value),placeholder:"e.g., Keep dark themes, always break down to small files, RTL...",className:"min-h-[100px] resize-none border-gray-200 focus:border-gray-300 transition-colors"})]}),(0,le.jsx)(ps,{className:"my-5"}),(0,le.jsxs)("div",{className:"space-y-3",children:[(0,le.jsxs)("div",{className:"flex justify-between items-center",children:[(0,le.jsxs)(Ns,{className:"text-sm font-medium flex items-center gap-2",children:[(0,le.jsx)(Mt.A,{className:"h-4 w-4 text-gray-700"}),"Freeze Files",i.length>0&&(0,le.jsxs)(es,{variant:"secondary",className:"ml-1 bg-blue-50 text-blue-700 hover:bg-blue-100",children:[i.length," frozen"]})]}),(0,le.jsxs)("div",{className:"flex gap-2",children:[(0,le.jsx)(Yt,{variant:"outline",size:"sm",className:"h-8 text-xs border-gray-200 hover:bg-gray-50 hover:text-gray-900 transition-colors",onClick:()=>x(!0),children:"Freeze All"}),(0,le.jsx)(Yt,{variant:"outline",size:"sm",className:"h-8 text-xs border-gray-200 hover:bg-gray-50 hover:text-gray-900 transition-colors",onClick:()=>x(!1),children:"Unfreeze All"})]})]}),(0,le.jsx)("p",{className:"text-sm text-muted-foreground",children:"Select files that should be protected from AI edits. The AI will not modify frozen files."}),(0,le.jsx)(gm,{className:"h-[200px] border border-gray-200 rounded-lg overflow-hidden",children:(0,le.jsx)("div",{className:"p-1",children:c.map(e=>{const t=i.includes(e);return(0,le.jsxs)("div",{className:"flex items-center p-2 rounded-md transition-colors ".concat(t?"bg-blue-50 text-blue-800":"hover:bg-gray-50"),children:[(0,le.jsx)(dm,{id:"freeze-".concat(e),checked:t,onCheckedChange:()=>(e=>{o(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])})(e),className:t?"border-blue-500 text-blue-600":""}),(0,le.jsxs)("div",{className:"flex-1 flex items-center ml-3",children:[(0,le.jsx)(Ns,{htmlFor:"freeze-".concat(e),className:"cursor-pointer text-sm font-normal flex-1",children:e}),t?(0,le.jsx)(Mt.A,{className:"h-3.5 w-3.5 text-blue-500 ml-2"}):(0,le.jsx)(bm.A,{className:"h-3.5 w-3.5 text-gray-300 ml-2"})]})]},e)})})})]})]}),(0,le.jsx)(Ba,{className:"px-6 py-4 bg-gray-50 border-t border-gray-100",children:(0,le.jsxs)("div",{className:"flex w-full gap-3 sm:justify-end",children:[(0,le.jsx)(Yt,{type:"button",variant:"outline",onClick:s,disabled:m,className:"flex-1 sm:flex-initial border-gray-200",children:"Cancel"}),(0,le.jsx)(Yt,{type:"button",onClick:async()=>{try{u(!0),await n({custom_instructions:l,frozen_files:i}),s()}catch(e){}finally{u(!1)}},disabled:m,className:"flex-1 sm:flex-initial bg-[#2b3440] hover:bg-[#3a4555] text-white",children:m?(0,le.jsxs)("span",{className:"flex items-center gap-2",children:[(0,le.jsx)("span",{className:"h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent"}),"Saving..."]}):(0,le.jsxs)("span",{className:"flex items-center gap-1",children:[(0,le.jsx)(Ps.A,{className:"h-4 w-4"}),"Save Changes"]})})]})})]})})}var ym=s(52536),Nm=s(83817),wm=s(4940),_m=s(36876);function km(e,t,s,a){try{const n=(0,ym.parse)(e,{sourceType:"module",plugins:["jsx","typescript","decorators-legacy","classProperties","objectRestSpread","functionBind","exportDefaultFrom","exportNamespaceFrom","dynamicImport","nullishCoalescingOperator","optionalChaining","asyncGenerators","bigInt","optionalCatchBinding","throwExpressions"]});let l=!1;if((0,Nm.default)(n,{JSXElement(e){const n=e.node.openingElement,{start:r}=n.loc||{};if(r&&r.line===t&&r.column===s){if(void 0!==a.className){const e=n.attributes.findIndex(e=>_m.isJSXAttribute(e)&&_m.isJSXIdentifier(e.name)&&"className"===e.name.name),t=_m.jsxAttribute(_m.jsxIdentifier("className"),_m.stringLiteral(a.className));e>=0?n.attributes[e]=t:n.attributes.push(t)}if(void 0!==a.content&&!n.selfClosing){const t=_m.jsxText(a.content);e.node.children=[t]}l=!0,e.stop()}}}),!l)return{code:e,success:!0,found:!1,error:"Element not found at line ".concat(t,", column ").concat(s)};return{code:(0,wm.default)(n,{retainLines:!0,compact:!1,concise:!1}).code,success:!0,found:!0}}catch(n){return{code:e,success:!1,found:!1,error:n instanceof Error?n.message:"Unknown error"}}}var Cm=s(69830),Am=s(51981);function Sm(e){let{appId:t,onOpenChatSettings:s,frozenFiles:a}=e;const{app:n,updateApp:l}=Nt(),{toast:r}=nn(),[i,o]=(0,Y.useState)(!1),[c,d]=(0,Y.useState)(!1),[m,u]=(0,Y.useState)(!1),[x,h]=(0,Y.useState)(!1),p=(0,Y.useRef)(null);(0,Y.useEffect)(()=>{const e=e=>{p.current&&!p.current.contains(e.target)&&(o(!1),d(!1),u(!1))};return document.addEventListener("mousedown",e),()=>{document.removeEventListener("mousedown",e)}},[]);const g=async e=>{h(!0);try{await l({model:e}),u(!1),o(!1),r({title:"AI model updated",description:"Your app is now using a different AI model"})}catch(t){r({title:"Error",description:"Failed to update AI model",variant:"destructive"})}finally{h(!1)}},f=(null==a?void 0:a.length)||0,v=(e=>{switch(e){case"claude_3_7":return"Claude 3.7";case"claude_sonnet_4":return"Claude Sonnet 4.5";case"gemini_2_5_pro":return"Gemini 2.5 Pro";case"gpt_5":return"GPT-5";default:return"Default"}})(n.model);return(0,le.jsxs)("div",{className:"relative",ref:p,children:[(0,le.jsx)("div",{className:"flex items-center",children:(0,le.jsx)("button",{onClick:()=>o(!i),className:"flex items-center justify-center px-1 py-1 rounded-md rounded-md hover:bg-gray-100 transition-colors","aria-label":"App Settings",children:(0,le.jsx)(vm.A,{className:"h-4 w-4 transition-transform duration-300 ease-in-out ".concat(i?"rotate-90":"")})})}),i&&(0,le.jsxs)("div",{className:"absolute bottom-full left-0 mb-2 w-52 bg-white rounded-md shadow-lg z-10 border border-gray-200 py-0.5",children:[(0,le.jsxs)("div",{className:"relative border-t border-gray-100",children:[(0,le.jsx)("div",{className:"px-3 py-1.5 text-sm hover:bg-gray-50 cursor-pointer transition-colors ".concat(m?"bg-gray-50":""),onClick:()=>{u(!m),d(!1)},children:(0,le.jsxs)("div",{className:"flex items-center justify-between",children:[(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[(0,le.jsx)(Cm.A,{className:"w-3.5 h-3.5 text-gray-600"}),(0,le.jsxs)("div",{children:[(0,le.jsx)("span",{className:"font-medium",children:"AI Model"}),(0,le.jsx)("div",{className:"text-xs text-gray-500",children:v})]})]}),(0,le.jsx)(rn.A,{className:"w-3 h-3 text-gray-400 transition-transform duration-200 ".concat(m?"rotate-90":"")})]})}),m&&(0,le.jsxs)("div",{className:"absolute left-full bottom-0 ml-0.5 w-56 bg-white rounded-md shadow-lg border border-gray-200 py-0.5 z-20",children:[(0,le.jsxs)("button",{onClick:()=>g("default"),disabled:x,className:"w-full px-3 py-1.5 text-sm text-left hover:bg-gray-50 flex items-center justify-between transition-colors ".concat("default"!==n.model&&n.model?"":"bg-blue-50/70"),children:[(0,le.jsxs)("div",{className:"flex flex-col items-start",children:[(0,le.jsx)("span",{children:"Default"}),(0,le.jsx)("span",{className:"text-[10px] text-gray-500 mt-0.5",children:"Automatically selects the best model for your app"})]}),("default"===n.model||!n.model)&&(0,le.jsx)(Ps.A,{className:"w-3.5 h-3.5 text-blue-600 ml-2 flex-shrink-0"})]}),(0,le.jsxs)("button",{onClick:()=>g("claude_sonnet_4"),disabled:x,className:"w-full px-3 py-1.5 text-sm text-left hover:bg-gray-50 flex items-center justify-between transition-colors ".concat("claude_sonnet_4"===n.model?"bg-blue-50/70":""),children:[(0,le.jsx)("span",{children:"Claude Sonnet 4.5"}),"claude_sonnet_4"===n.model&&(0,le.jsx)(Ps.A,{className:"w-3.5 h-3.5 text-blue-600"})]}),(0,le.jsxs)("button",{onClick:()=>g("gemini_2_5_pro"),disabled:x,className:"w-full px-3 py-1.5 text-sm text-left hover:bg-gray-50 flex items-center justify-between transition-colors ".concat("gemini_2_5_pro"===n.model?"bg-blue-50/70":""),children:[(0,le.jsx)("span",{children:"Gemini 2.5 Pro"}),"gemini_2_5_pro"===n.model&&(0,le.jsx)(Ps.A,{className:"w-3.5 h-3.5 text-blue-600"})]}),(0,le.jsxs)("button",{onClick:()=>g("gpt_5"),disabled:x,className:"w-full px-3 py-1.5 text-sm text-left hover:bg-gray-50 flex items-center justify-between transition-colors ".concat("gpt_5"===n.model?"bg-blue-50/70":""),children:[(0,le.jsx)("span",{children:"GPT-5"}),"gpt_5"===n.model&&(0,le.jsx)(Ps.A,{className:"w-3.5 h-3.5 text-blue-600"})]}),x&&(0,le.jsxs)("div",{className:"flex justify-center items-center py-1.5 text-xs text-gray-500 bg-gray-50 border-t border-gray-100",children:[(0,le.jsx)("div",{className:"animate-spin h-3 w-3 border-2 border-blue-500 border-t-transparent rounded-full mr-2"}),"Updating..."]})]})]}),(0,le.jsxs)("button",{onClick:()=>{o(!1),s()},className:"w-full px-3 py-1.5 text-sm text-left text-gray-700 hover:bg-gray-50 flex items-center justify-between border-t border-gray-100 transition-colors",children:[(0,le.jsxs)("div",{className:"flex items-center",children:[(0,le.jsx)(Am.A,{size:13,className:"mr-2 text-gray-600"}),(0,le.jsx)("span",{className:"font-medium",children:"AI Controls"})]}),f>0&&(0,le.jsxs)("span",{className:"text-xs text-blue-600 font-medium bg-blue-50 px-1.5 py-0.5 rounded",children:[f," frozen"]})]})]})]})}var Em=s(33252);const Im=e=>{let{isDiscussionMode:t,setIsDiscussionMode:s}=e;return(0,le.jsxs)(Et,{children:[(0,le.jsx)(It,{asChild:!0,children:(0,le.jsxs)("button",{onClick:()=>s(!t),className:"flex items-center gap-1 px-2 py-1 rounded-md text-xs transition-all duration-200 ".concat(t?"bg-violet-50 text-violet-600 hover:bg-violet-100":"text-gray-600 bg-gray-100 hover:bg-gray-200"),children:[(0,le.jsx)(Em.A,{className:"h-3 w-3"}),(0,le.jsx)("span",{children:"Discuss"})]})}),(0,le.jsx)(Tt,{side:"top",align:"end",className:"max-w-[280px]",children:(0,le.jsxs)("div",{className:"space-y-1",children:[(0,le.jsx)("p",{className:"font-medium",children:"Discuss Mode"}),(0,le.jsx)("p",{className:"text-xs text-muted-foreground",children:"Chat with the AI about anything without making code changes. Uses 0.3 credits per request."})]})})]})};function Tm(e){let{minimizedChat:t=!1}=e;const[s,a]=(0,Y.useState)(!1),[n,l]=(0,Y.useState)(null),{app:r,addChatMessage:i,undoMessage:o,stopChat:c,loadFullConversation:d,suggestions:m,currentUsage:u,previewIframeRef:x}=Nt(),[h,p]=((0,Z.Zp)(),(0,Y.useState)(!1)),[g,f]=(0,Y.useState)({}),[v,b]=(0,Y.useState)(!1),{isVisualEditMode:j,selectedElement:y,isPopoverVisible:N,elementPosition:w,isSaving:_,shouldHideSelectElement:k,toggleVisualEditMode:C,handleClassesChange:A,handleContentChange:S,handleClosePopover:E,handleSave:I,handleBatchSave:T,handleDiscard:P,handleElementRevert:L}=function(){const{app:e,previewIframeRef:t,setSelectedElement:s,writeCodeToFile:a}=Nt(),[n,l]=(0,Y.useState)(!1),[r,i]=(0,Y.useState)(null),[o,c]=(0,Y.useState)(!1),[d,m]=(0,Y.useState)(null),[u,x]=(0,Y.useState)(!1),[h,p]=(0,Y.useState)(!1),g=(0,Y.useRef)(null),f=()=>!Object.keys(e.pages).length||!window.location.pathname.includes("preview")||window.innerWidth<768;(0,Y.useEffect)(()=>{f()&&(l(!1),c(!1),i(null),m(null),s(null))},[window.location.pathname]),(0,Y.useEffect)(()=>{if(f())return;const e=e=>{var t;const a=e.data;switch(a.type){case"element-selected":let e=null==a?void 0:a.filename,r=null==a?void 0:a.linenumber;if(!e||!r){var n,l;const[t,s]=null!==(n=null==a||null===(l=a.dataSourceLocation)||void 0===l?void 0:l.split(":"))&&void 0!==n?n:[];e=e||t,r=r||s}const o={tagName:a.tagName,classes:a.classes,linenumber:r,dataSourceLocation:a.dataSourceLocation,filename:e,visualSelectorId:a.visualSelectorId,content:a.content,isDynamicContent:a.isDynamicContent,isTextElement:["p","h1","h2","h3","h4","h5","h6","span","a","label"].includes(null===(t=a.tagName)||void 0===t?void 0:t.toLowerCase())};i(o),g.current=a.visualSelectorId,m(a.position),c(!0),s({tagName:a.tagName,dataset:{filename:e,linenumber:r}});break;case"element-position-update":a.visualSelectorId===g.current&&m(a.position)}};return window.addEventListener("message",e),()=>{window.removeEventListener("message",e)}},[s,window.location.pathname]);const v=e=>{c(!1),m(null),"boolean"==typeof e&&l(e),t.current&&t.current.contentWindow.postMessage({type:"unselect-element"},"*"),i(null),g.current=null,s(null)},b=t=>{if(!t)return null;try{if("layout"===t.toLowerCase())return e.layout;if(t.startsWith("pages/")){const s=t.split("pages/")[1];return e.pages[s]}if(t.startsWith("components/")){const s=t.split("components/")[1];return e.components[s]}}catch(s){}return null},j=async e=>{if(e&&0!==e.length)try{x(!0);const s={};for(const t of e){const{elementId:e,classes:a,content:n,isTextElement:l,isDynamicContent:r}=t;if(!e)continue;const[i,o,c]=e.split(":");let d=i;d.endsWith(".js")&&(d=d.replace(".js",""));const m=parseInt(o,10),u=parseInt(c,10);isNaN(m)||isNaN(u)||(s[d]||(s[d]=[]),s[d].push({line:m,column:u,classes:a,content:n,isTextElement:l,isDynamicContent:r}))}for(const[e,t]of Object.entries(s)){let s=b(e);if(s){for(let e=0;e{const e=!n;l(e),t.current&&t.current.contentWindow.postMessage({type:"toggle-visual-edit-mode",data:{enabled:e}},"*"),e||(i(null),g.current=null,c(!1),m(null),s(null),t.current&&t.current.contentWindow.postMessage({type:"unselect-element"},"*"))},handleClassesChange:e=>{g.current&&(i(t=>(0,K.A)((0,K.A)({},t),{},{classes:e})),t.current&&t.current.contentWindow.postMessage({type:"update-classes",data:{classes:e,visualSelectorId:g.current}},"*"))},handleContentChange:e=>{i(t=>(0,K.A)((0,K.A)({},t),{},{content:e})),p(!0),t.current&&t.current.contentWindow.postMessage({type:"update-content",data:{content:e,visualSelectorId:g.current}},"*")},handleClosePopover:v,handleSave:async function(e,t){const s=[{elementId:e.dataSourceLocation,classes:t,content:e.content,isTextElement:e.isTextElement,isDynamicContent:e.isDynamicContent}];await j(s)},handleBatchSave:j,handleDiscard:()=>{t.current&&(t.current.contentWindow.postMessage({type:"refresh-page"},"*"),v(),l(!1))},handleElementRevert:e=>{let{elementId:t,originalClasses:s,originalContent:a}=e;r&&r.dataSourceLocation===t&&i(e=>(0,K.A)((0,K.A)({},e),{},{classes:s,content:a}))}}}(),{changedElements:O,addToChangedElements:R,revertLastChangedElement:M,discardAllChanges:D,saveAllChanges:F,currentElement:B}=function(e){let{element:t,iframeRef:s,onElementRevert:a,onChange:n,onContentChange:l,onBatchSave:r,onDiscard:i,parseTailwindClasses:o,closeAllDropdowns:c}=e;const[d,m]=(0,Y.useState)({}),[u,x]=(0,Y.useState)(null),[h,p]=(0,Y.useState)({}),[g,f]=(0,Y.useState)(""),[v,b]=(0,Y.useState)({colors:{bg:null,text:null},spacing:{margin:{t:null,r:null,b:null,l:null,x:null,y:null,all:null},padding:{t:null,r:null,b:null,l:null,x:null,y:null,all:null}},typography:{size:null,weight:null,align:null,decoration:null,transform:null,tracking:null,leading:null},opacity:null,borderRadius:null,other:[]}),j=(0,Y.useCallback)((e,s)=>{const a=u;if(!a)return;const n=h[a];("classes"===e?(null==n?void 0:n.classes)||t.classes||"":(null==n?void 0:n.content)||t.content||"")!==s&&m(l=>l[a]?(0,K.A)((0,K.A)({},l),{},{[a]:(0,K.A)((0,K.A)({},l[a]),{},{currentClasses:"classes"===e?s:l[a].currentClasses,currentContent:"content"===e?s:l[a].currentContent,lastModified:Date.now()})}):(0,K.A)((0,K.A)({},l),{},{[a]:{originalClasses:(null==n?void 0:n.classes)||t.classes||"",originalContent:(null==n?void 0:n.content)||t.content||"",currentClasses:"classes"===e?s:t.classes||"",currentContent:"content"===e?s:t.content||"",lastModified:Date.now(),isTextElement:t.isTextElement||!1,isDynamicContent:t.isDynamicContent||!1}}))},[u,h,t.classes,t.content,t.isTextElement,t.isDynamicContent]),y=(0,Y.useCallback)(()=>{const e=Object.entries(d);if(0===e.length)return;const[t,r]=e.reduce((e,t)=>t[1].lastModified>e[1].lastModified?t:e);if(t===u){f(r.originalClasses);const e=o(r.originalClasses);b(e)}if(null!=s&&s.current){var i;const e={type:"update-classes",data:{classes:r.originalClasses,visualSelectorId:t,replace:!0}};if(null===(i=s.current.contentWindow)||void 0===i||i.postMessage(e,"*"),r.originalContent!==r.currentContent){var c;const e={type:"update-content",data:{content:r.originalContent,visualSelectorId:t}};null===(c=s.current.contentWindow)||void 0===c||c.postMessage(e,"*")}a&&a({elementId:t,originalClasses:r.originalClasses,originalContent:r.originalContent}),t===u&&(n(r.originalClasses),r.originalContent!==r.currentContent&&l(r.originalContent))}else n(r.originalClasses),r.originalContent!==r.currentContent&&l(r.originalContent);m(e=>{const s=(0,K.A)({},e);return delete s[t],s})},[d,u,s,a,n,l,f,b,o]),N=(0,Y.useCallback)(()=>{var e;if(0!==Object.keys(d).length){if(null!=s&&null!==(e=s.current)&&void 0!==e&&e.contentWindow&&Object.entries(d).forEach(e=>{let[t,a]=e;s.current.contentWindow.postMessage({type:"update-classes",data:{classes:a.originalClasses,visualSelectorId:t,replace:!0}},"*"),a.originalContent!==a.currentContent&&s.current.contentWindow.postMessage({type:"update-content",data:{content:a.originalContent,visualSelectorId:t}},"*")}),u&&h[u]){const e=h[u];f(e.classes),b(o(e.classes)),n(e.classes),void 0!==e.content&&l(e.content)}m({}),c(),i&&i()}},[d,c,i,s,u,h,o,n,l]),w=(0,Y.useCallback)(async()=>{if(c(),0===Object.keys(d).length)return;const e=(0,K.A)({},d);if(r){const e=Object.entries(d).map(e=>{let[t,s]=e;return{elementId:t,classes:s.currentClasses,content:s.currentContent,isTextElement:s.isTextElement,isDynamicContent:s.isDynamicContent}});try{await r(e)}catch(t){return}}p(t=>{const s=(0,K.A)({},t);return Object.entries(e).forEach(e=>{let[t,a]=e;s[t]={classes:a.currentClasses,content:a.currentContent}}),s}),m({})},[d,t,r,c,p]),_=Object.keys(d).length>0,k=(0,Y.useCallback)(e=>{if(null==(null==e?void 0:e.classes))return;const t=e.dataSourceLocation||e.tagName+JSON.stringify(e.linenumber);if(t!==u){x(t),f(e.classes);const s=o(e.classes);b(s),p(s=>s[t]?s:(0,K.A)((0,K.A)({},s),{},{[t]:{classes:e.classes,content:e.content||""}}))}},[u,o]),C=(0,Y.useCallback)(e=>{f(e);const t=o(e);b(t)},[o]);return(0,Y.useEffect)(()=>{t&&k(t)},[null==t?void 0:t.dataSourceLocation,null==t?void 0:t.linenumber,null==t?void 0:t.classes,null==t?void 0:t.content,null==t?void 0:t.tagName,k]),{changedElements:d,addToChangedElements:j,revertLastChangedElement:y,discardAllChanges:N,saveAllChanges:w,hasChanges:_,currentElement:{key:u,parsedClasses:v,rawClasses:g,updateClasses:C},selectElement:k}}({element:y||{classes:"",content:"",isTextElement:!1,tagName:""},iframeRef:x,onElementRevert:L,onChange:A,onContentChange:S,onBatchSave:T,onDiscard:P,parseTailwindClasses:Yd,closeAllDropdowns:()=>{f({})}}),z=Object.keys(O).length>0;(0,Y.useEffect)(()=>{Object.keys(O).length>0&&v&&b(!1)},[O,v]),(0,Y.useEffect)(()=>{u&&(async()=>{try{const e=await ke.default.getStats();l(e)}catch(e){}})()},[u]);const U=!!u&&(u.daily_usage>=(u.daily_limit||1e6)||null!==u.monthly_limit&&void 0!==u.monthly_limit&&u.monthly_usage>=u.monthly_limit),W=U?"0 credits remaining":z?"Save changes before typing":s?"What would you like to discuss?":"What would you like to change?";return(0,le.jsxs)("div",{className:"h-full flex flex-col",children:[(0,le.jsx)(rd,{chat:r.conversation,addMessage:e=>(j&&P(),s&&(e.additional_message_params=e.additional_message_params||{},e.additional_message_params.discussion_mode=!0),i(e)),status:r.status,undoMessage:o,onStop:c,loadFullConversation:d,suggestions:m,isDisabled:U||z,isOutOfCredits:U,currentUsage:u,billingStats:n,placeholder:W,isDiscussionMode:s,isVisualEditMode:j,minimizedChat:t,changeCount:Object.keys(O).length,onRevertChange:M,onDiscardAllChanges:()=>{0!==Object.keys(O).length&&(D(),b(!1))},onSaveAllChanges:async()=>{try{await F(),b(!1)}catch(e){cr.toast.error("Failed to save changes: ".concat(e.message||"Unknown error"))}},isSavingChanges:_,bannerDismissed:v,onBannerDismiss:()=>{b(!0)},customButtomRight:null,customButtomLeft:e=>(0,le.jsxs)("div",{className:"flex items-center gap-1",children:[(0,le.jsx)(Sm,{appId:r.id,onOpenChatSettings:()=>p(!0),frozenFiles:r.frozen_files}),(0,le.jsx)("div",{className:"h-6 w-px bg-gray-200 mx-2"}),e,!k&&(0,le.jsx)(od,{isVisualEditMode:j,toggleVisualEditMode:C,isSaving:_}),!U&&(0,le.jsx)(Im,{isDiscussionMode:s,setIsDiscussionMode:a})]})}),(0,le.jsx)(im,{isVisible:N,selectedElement:y,position:w,iframeRef:x,onClose:E,onSave:I,onDiscard:P,onChange:A,onContentChange:S,isSaving:_,onElementRevert:L,onAskQuestion:(e,t)=>{var a,n;const l={content:e,custom_context:[{type:"element",data:{element_tag_name:t.tagName,filename:(null===(a=t.dataSourceLocation)||void 0===a?void 0:a.split(":")[0])||"",linenumber:t.linenumber},message:"User has selected an element to edit, here's the element's code position: file: ".concat((null===(n=t.dataSourceLocation)||void 0===n?void 0:n.split(":")[0])||"",", line number: ").concat(t.linenumber)}]};s&&(l.additional_message_params=l.additional_message_params||{},l.additional_message_params.discussion_mode=!0),i(l)},openDropdowns:g,onOpenDropdownsChange:f,currentElement:B,addToChangedElements:R,hasUnsavedChanges:z,isDiscussionMode:s}),(0,le.jsx)(jm,{isOpen:h,onClose:()=>p(!1)})]})}var Pm=s(81646),Lm=s(13129);const Om=["className"],Rm=["withHandle","className"],Mm=e=>{let{className:t}=e,s=(0,Se.A)(e,Om);return(0,le.jsx)(Lm.YZ,(0,K.A)({className:Pe("flex h-full w-full data-[panel-group-direction=vertical]:flex-col",t)},s))},Dm=Lm.Zk,Fm=e=>{let{withHandle:t,className:s}=e,a=(0,Se.A)(e,Rm);return(0,le.jsx)(Lm.TW,(0,K.A)((0,K.A)({className:Pe("relative flex w-px items-center justify-center bg-border after:absolute after:inset-y-0 after:left-1/2 after:w-1 after:-translate-x-1/2 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-1 data-[panel-group-direction=vertical]:h-px data-[panel-group-direction=vertical]:w-full data-[panel-group-direction=vertical]:after:left-0 data-[panel-group-direction=vertical]:after:h-1 data-[panel-group-direction=vertical]:after:w-full data-[panel-group-direction=vertical]:after:-translate-y-1/2 data-[panel-group-direction=vertical]:after:translate-x-0 [&[data-panel-group-direction=vertical]>div]:rotate-90",s)},a),{},{children:t&&(0,le.jsx)("div",{className:"z-10 flex h-4 w-3 items-center justify-center rounded-sm border bg-border",children:(0,le.jsx)(Pm.A,{className:"h-2.5 w-2.5"})})}))},Bm=()=>(0,le.jsx)("div",{className:"flex flex-col h-full p-4",children:(0,le.jsx)("div",{className:"space-y-4",children:[1,2,3].map(e=>(0,le.jsxs)("div",{className:"border border-gray-200 dark:border-gray-700 rounded-lg p-4 animate-pulse",children:[(0,le.jsx)("div",{className:"h-4 bg-gray-200 dark:bg-gray-700 rounded mb-2 w-3/4"}),(0,le.jsx)("div",{className:"h-3 bg-gray-200 dark:bg-gray-700 rounded w-1/2"})]},e))})}),zm=e=>{const t=ra().utc(e);return{relative:t.fromNow(),absolute:t.format("MMM D, YYYY [at] h:mm A")}},Um=e=>{try{const t=gr(e,"action_group");if(t.length>0)for(const e of t){const t=e.openingTag.match(/title=["']([^"']*)["']/i);if(t&&t[1])return t[1]}const s=/# (.*)/,a=e.match(s);if(a)return a[1]}catch(t){}return"Untitled Version"};const Wm=e=>{let{isCurrentlyPublished:t}=e;return(0,le.jsx)("div",{className:"px-2 py-1 rounded-md inline-flex justify-center items-center ".concat(t?"bg-green-50 text-green-950 outline outline-1 outline-offset-[-1px] outline-green-200 dark:bg-green-900/30 dark:text-green-100 dark:outline-green-800":"bg-gray-50 text-gray-600 outline outline-1 outline-offset-[-1px] outline-gray-200 dark:bg-gray-800 dark:text-gray-400 dark:outline-gray-700"),children:(0,le.jsx)("div",{className:"text-xs font-medium leading-none",children:t?"Published":"Previously Published"})})},qm=e=>{let{deployedAt:t,isCurrentlyPublished:s}=e;const{relative:a,absolute:n}=zm(t);return(0,le.jsxs)("div",{className:"flex items-center justify-between pt-3",children:[(0,le.jsxs)(Bi,{delayDuration:100,children:[(0,le.jsx)(zi,{asChild:!0,children:(0,le.jsxs)("div",{className:"text-xs font-medium text-gray-500 dark:text-gray-400 ",children:["Published ",a]})}),(0,le.jsx)(Ui,{side:"bottom",sideOffset:4,children:(0,le.jsx)("p",{children:n})})]}),(0,le.jsx)(Wm,{isCurrentlyPublished:s})]})},Vm=e=>{let{checkpoint:t,isSelected:s,wasEverPublished:a,isCurrentlyPublished:n,onClick:l,size:r="default"}=e;const{relative:i,absolute:o}=zm(t.created_date),c="small"===r?"p-3":"p-4",d="small"===r?"font-medium text-sm pr-2":"font-medium pr-2";return(0,le.jsxs)("div",{className:"border border-gray-200 dark:border-gray-700 rounded-lg ".concat(c," relative cursor-pointer transition-all ").concat(s?"bg-blue-50 dark:bg-blue-900/20 border-blue-200 dark:border-blue-800":"hover:border-blue-200 dark:hover:border-blue-800 hover:bg-gray-50 dark:hover:bg-gray-800/50"),onClick:l,role:"button",tabIndex:0,onKeyDown:e=>{"Enter"!==e.key&&" "!==e.key||(e.preventDefault(),null==l||l(e))},children:[(0,le.jsx)("div",{className:"flex items-start justify-between mb-2",children:(0,le.jsx)("div",{className:d,children:t.name})}),(0,le.jsxs)("div",{className:"text-xs text-gray-400",children:[(0,le.jsxs)("div",{className:"font-medium",children:["Created ",i]}),(0,le.jsx)("div",{className:"opacity-75",children:o})]}),s&&(0,le.jsx)("div",{className:"absolute top-2 right-2",children:(0,le.jsx)(Ps.A,{className:"h-4 w-4 text-blue-500"})}),a&&(0,le.jsx)(qm,{deployedAt:t.last_deployed_at,isCurrentlyPublished:n})]})};var Hm=s(18247);const Ym=["className"],Gm=["className"],$m=["className"],Jm=["className"],Zm=["className"],Km=["className"],Qm=["className"],Xm=["className"],eu=Hm.bL,tu=(Hm.l9,Hm.ZL),su=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,Ym);return(0,le.jsx)(Hm.hJ,(0,K.A)((0,K.A)({className:Pe("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",s)},a),{},{ref:t}))});su.displayName=Hm.hJ.displayName;const au=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,Gm);return(0,le.jsxs)(tu,{children:[(0,le.jsx)(su,{}),(0,le.jsx)(Hm.UC,(0,K.A)({ref:t,className:Pe("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",s)},a))]})});au.displayName=Hm.UC.displayName;const nu=e=>{let{className:t}=e,s=(0,Se.A)(e,$m);return(0,le.jsx)("div",(0,K.A)({className:Pe("flex flex-col space-y-2 text-center sm:text-left",t)},s))};nu.displayName="AlertDialogHeader";const lu=e=>{let{className:t}=e,s=(0,Se.A)(e,Jm);return(0,le.jsx)("div",(0,K.A)({className:Pe("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",t)},s))};lu.displayName="AlertDialogFooter";const ru=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,Zm);return(0,le.jsx)(Hm.hE,(0,K.A)({ref:t,className:Pe("text-lg font-semibold",s)},a))});ru.displayName=Hm.hE.displayName;const iu=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,Km);return(0,le.jsx)(Hm.VY,(0,K.A)({ref:t,className:Pe("text-sm text-muted-foreground",s)},a))});iu.displayName=Hm.VY.displayName;const ou=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,Qm);return(0,le.jsx)(Hm.rc,(0,K.A)({ref:t,className:Pe(Ht(),s)},a))});ou.displayName=Hm.rc.displayName;const cu=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,Xm);return(0,le.jsx)(Hm.ZD,(0,K.A)({ref:t,className:Pe(Ht({variant:"outline"}),"mt-2 sm:mt-0",s)},a))});cu.displayName=Hm.ZD.displayName;const du=e=>{let{showRevertDialog:t,setShowRevertDialog:s,selectedCheckpoint:a}=e;return(0,le.jsx)(eu,{open:t,onOpenChange:s,children:(0,le.jsxs)(au,{children:[(0,le.jsxs)(nu,{children:[(0,le.jsx)(ru,{children:"Are you sure?"}),(0,le.jsxs)(iu,{children:['This action is irreversible. Your app will be reverted to "',null==a?void 0:a.name,'".']})]}),(0,le.jsxs)(lu,{children:[(0,le.jsx)(cu,{children:"Cancel"}),(0,le.jsx)(ou,{onClick:()=>{alert("Reverted to: ".concat(a.name)),s(!1)},children:"Revert"})]})]})})},mu=["mutate"],uu=(e,t)=>{let{query:s,enabled:a,initialData:n,throwErrorToBoundary:l,onError:r,logErrorMsg:i,onSuccess:o,onLoading:c,toastSuccess:d,toastError:m,retry:u}=e;const[x,h]=(0,Y.useState)(n),[p,g]=(0,Y.useState)(!1),[f,v]=(0,Y.useState)(void 0),{toast:b}=ui(),j=(0,Y.useRef)(!1),y="string"==typeof d?{title:"Success",description:d}:d,N="string"==typeof m?{title:"Error",description:m}:m;(0,Y.useEffect)(()=>(j.current=!0,()=>{j.current=!1}),[]);const w=(0,Y.useCallback)(async e=>{g(!0),null==c||c(!0,e);try{const t=await s(e);j.current&&h(t),j.current&&g(!1),null==o||o(t,e),null==c||c(!1,e),y&&b(y)}catch(i){var t,a,n,l;const s=null!==(t=null!==(a=null==e||null===(n=e.retryData)||void 0===n?void 0:n.retries)&&void 0!==a?a:null==u?void 0:u.retries)&&void 0!==t?t:0,o=Math.max(null!==(l=null==u?void 0:u.delay)&&void 0!==l?l:100,100);if(s>0)return void setTimeout(()=>{w({refetchData:null==e?void 0:e.refetchData,retryData:{retries:s-1}})},o);null==r||r(i,e),j.current&&v(i),N&&b((0,K.A)((0,K.A)({},N),{},{variant:"destructive"})),j.current&&g(!1),null==c||c(!1,e)}},[s,o,r]);if((0,Y.useEffect)(()=>{!1!==a&&w()},[...null!=t?t:[],a]),f&&l)throw f;const _=(0,Y.useCallback)(e=>{!1!==a&&w({refetchData:e})},[a,w]),k=(0,Y.useCallback)(e=>w({refetchData:e}),[w]),C=(0,Y.useCallback)(e=>{var t;h(null!==(t=null==e?void 0:e.data)&&void 0!==t?t:n),(null==e?void 0:e.refetch)&&k(null==e?void 0:e.refetchData)},[n,k,a]);return{data:x,isLoading:p,error:f,refetch:k,refetchIfEnabled:_,resetData:C}},xu=e=>{let{mutate:t}=e,s=(0,Se.A)(e,mu);const{refetch:a,data:n,isLoading:l,error:r}=uu((0,K.A)((0,K.A)({},s),{},{query:async e=>await t(null==e?void 0:e.refetchData),enabled:!1}),[]);return{data:n,isLoading:l,error:r,mutate:e=>a(e)}},hu=()=>{var e;const{app:t}=Nt(),{user:s}=oe(),a=null==s||null===(e=s.feature_flags)||void 0===e?void 0:e.includes("use-sandbox-from-ui");return(null==t?void 0:t.using_sandbox)&&a};class pu extends Q.H{getBaseURL(){return"/apps"}async getPreviewURL(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";try{const s=t?{checkpoint_id:t}:{};return(await this.axios.get("/".concat(e,"/sandbox/preview-url"),{params:s})).preview_url}catch(n){var s,a;throw new Error((null===(s=n.response)||void 0===s||null===(a=s.data)||void 0===a?void 0:a.detail)||"Failed to get preview url")}}async getAppFiles(e){try{return(await this.axios.get("/".concat(e,"/sandbox/files"))).files}catch(a){var t,s;throw new Error((null===(t=a.response)||void 0===t||null===(s=t.data)||void 0===s?void 0:s.detail)||"Failed to get app files")}}async updateMainPage(e,t){try{return await this.axios.post("/".concat(e,"/sandbox/main-page"),{main_page:t})}catch(n){var s,a;throw new Error((null===(s=n.response)||void 0===s||null===(a=s.data)||void 0===a?void 0:a.detail)||"Failed to update main page")}}async previewCheckpoint(e,t){try{return await this.axios.post("/".concat(e,"/sandbox/checkpoint/").concat(t,"/preview")),!0}catch(n){var s,a;throw new Error((null===(s=n.response)||void 0===s||null===(a=s.data)||void 0===a?void 0:a.detail)||"Failed to load checkpoint preview")}}async exitCheckpointPreview(e){try{return await this.axios.post("/".concat(e,"/sandbox/exit-checkpoint-preview")),!0}catch(a){var t,s;throw new Error((null===(t=a.response)||void 0===t||null===(s=t.data)||void 0===s?void 0:s.detail)||"Failed to exit checkpoint preview")}}async migrateToSandbox(e){try{return await this.axios.post("/".concat(e,"/sandbox/migrate"))}catch(a){var t,s;throw new Error((null===(t=a.response)||void 0===t||null===(s=t.data)||void 0===s?void 0:s.detail)||"Failed to migrate app to sandbox")}}async revertSandboxMigration(e){try{return await this.axios.post("/".concat(e,"/sandbox/revert-migration"))}catch(a){var t,s;throw new Error((null===(t=a.response)||void 0===t||null===(s=t.data)||void 0===s?void 0:s.detail)||"Failed to unmigrate app from sandbox")}}}const gu=new pu,fu=e=>{var t,s,a;const{app:n}=Nt(),l=(0,Y.useRef)(!1),{refetchIfEnabled:r,data:{checkpointsWithChatMatch:i,checkpointsWithNoMatch:o},isLoading:c,error:d}=uu({initialData:{checkpointsWithChatMatch:[],checkpointsWithNoMatch:[]},logErrorMsg:"Error fetching checkpoints",query:async()=>{const{checkpointsFromMessages:e,checkpointsWithNoMatch:t}=await async function(e){const t=await br.listCheckpoints(e.id),s=e.conversation.messages.filter((e,t,s)=>{var a,n;return e.checkpoint_id&&(e.content.includes("action_group")||(null===(a=s[t-1])||void 0===a||null===(n=a.tool_calls)||void 0===n?void 0:n.length)>0)}),a=s.map(e=>e.checkpoint_id),n=t.reduce((e,t)=>(0,K.A)((0,K.A)({},e),{},{[t.id]:t}),{});return{checkpointsFromMessages:s.map(t=>{var s,a,l;return{app_id:e.id,id:t.checkpoint_id,created_date:(null===(s=t.metadata)||void 0===s?void 0:s.created_date)||(new Date).toISOString(),name:(null===(a=n[t.checkpoint_id])||void 0===a?void 0:a.name)||Um(t.content),last_deployed_at:null===(l=n[t.checkpoint_id])||void 0===l?void 0:l.last_deployed_at}}).reverse(),checkpointsWithNoMatch:t.filter(e=>!a.includes(e.id))}}(n);return{checkpointsWithChatMatch:e,checkpointsWithNoMatch:t}},enabled:!(null==n||!n.id)&&!(null==n||null===(t=n.conversation)||void 0===t||null===(s=t.messages)||void 0===s||!s.length)&&e},[null==n?void 0:n.id]);return(0,Y.useEffect)(()=>{var e,t;"processing"===(null===(e=n.status)||void 0===e?void 0:e.state)?l.current=!0:"ready"===(null===(t=n.status)||void 0===t?void 0:t.state)&&l.current&&(r(),l.current=!1)},[null===(a=n.status)||void 0===a?void 0:a.state]),{refetch:r,checkpointsWithChatMatch:i,checkpointsWithNoMatch:o,allCheckpoints:[...i,...o],isLoading:c,error:d}},vu=async(e,t)=>{var s;const a=null!==(s=null==e?void 0:e.git_commit_hash)&&void 0!==s?s:(await br.getCheckpointCommitHash(t,e.id)).git_commit_hash;return Boolean(a)},bu=()=>{var e;const{app:t}=Nt(),[s,a]=(0,Y.useState)(null),n=(0,Y.useRef)({}),l=xu({mutate:async e=>{let{checkpointId:s}=e;if(n.current[s])return n.current[s];const a=await br.getCheckpointFileTree(t.id,s);return n.current[s]=a,a},onSuccess:e=>{a(e)}}),r=xu({mutate:async e=>{let{checkpointId:s}=e;if(n.current[s])return n.current[s];const a=await gu.getAppFiles(t.id);return n.current[s]={files:a,file_errors:{}},n.current[s]},onSuccess:e=>{a(e)}});return{filesTreeIsLoading:l.isLoading||r.isLoading||!s,filesTreeError:null!==(e=l.error)&&void 0!==e?e:r.error,filesTree:null!=s?s:{files:{},file_errors:{}},resetFilesTree:()=>{a(null)},fetchLegacyFilesTree:l.mutate,fetchSandboxFilesTree:r.mutate}},ju=(0,Y.createContext)(null),yu=e=>{let{children:t}=e;const s=(()=>{const{app:e}=Nt(),t=hu(),[s,a]=(0,Y.useState)(!1),[n,l]=(0,Y.useState)(!1),r=bu(),[i,o]=(0,Y.useState)(null),{allCheckpoints:c,checkpointsWithChatMatch:d,checkpointsWithNoMatch:m,isLoading:u,error:x}=fu(!i),{data:{activeSandboxCheckpoint:h,canUseSandboxPreview:p},isLoading:g}=uu({initialData:{activeSandboxCheckpoint:i,canUseSandboxPreview:!0},query:async()=>(null==i?void 0:i.id)===(null==h?void 0:h.id)?(r.fetchSandboxFilesTree({checkpointId:null==h?void 0:h.id}),{activeSandboxCheckpoint:h,canUseSandboxPreview:!0}):(r.resetFilesTree(),i?await vu(i,e.id)?(await gu.previewCheckpoint(e.id,i.id),r.fetchSandboxFilesTree({checkpointId:i.id}),{activeSandboxCheckpoint:i,canUseSandboxPreview:!0}):(r.fetchLegacyFilesTree({checkpointId:i.id}),{activeSandboxCheckpoint:h,canUseSandboxPreview:!1}):(await gu.exitCheckpointPreview(e.id),{activeSandboxCheckpoint:null,canUseSandboxPreview:!0})),enabled:t},[null==i?void 0:i.id]);return{showOtherCheckpoints:n,setShowOtherCheckpoints:l,checkpointsWithChatMatch:d,checkpointsWithNoMatch:m,allCheckpoints:c,hasCheckpoints:c.length>1,isLoading:u,isSyncingSandboxCheckpoint:g,error:x,selectedCheckpoint:i,activeSandboxCheckpoint:t?h:i,setSelectedCheckpoint:o,isRestoring:s,restoreSelectedCheckpoint:async()=>{if(window.confirm("Are you sure you want to restore this checkpoint? This action is irreversible.")){a(!0);try{(null==i?void 0:i.id)&&await br.loadCheckpoint(e.id,i.id),o(void 0)}catch(x){}finally{a(!1)}}},canUseSandboxPreview:p,filesTreeState:r}})();return(0,le.jsx)(ju.Provider,{value:s,children:t})};function Nu(){for(var e=arguments.length,t=new Array(e),s=0;s{const e="function"==typeof t[0],s=!e&&Boolean(null==t?void 0:t.length)&&(null==t?void 0:t.every(e=>"string"==typeof e));return e?t[0](a):s?t.reduce((e,t)=>(e[t]=a[t],e),{}):a},[a,t]);return n}const wu=()=>{const[e,t]=(0,Y.useState)(!1),{app:s}=Nt(),{checkpointsWithChatMatch:a,checkpointsWithNoMatch:n,isLoading:l,showOtherCheckpoints:r,setShowOtherCheckpoints:i,selectedCheckpoint:o,setSelectedCheckpoint:c}=Nu();return l?(0,le.jsx)(Bm,{}):(0,le.jsxs)("div",{className:"flex flex-col h-full",children:[(0,le.jsx)("div",{className:"space-y-4",children:a.map(e=>{const t=null!=e.last_deployed_at,a=s.last_deployed_checkpoint_id===e.id;return(0,le.jsx)(Vm,{checkpoint:e,wasEverPublished:t,isCurrentlyPublished:a,onClick:()=>c(e),isSelected:(null==o?void 0:o.id)===e.id,size:"default"},e.id)})}),n.length>0&&(0,le.jsxs)("div",{className:"mt-6 pt-4 border-t border-gray-200 dark:border-gray-700",children:[(0,le.jsx)(Hn,{variant:"ghost",className:"w-full justify-start p-3 h-auto text-left hover:bg-gray-50 dark:hover:bg-gray-800/50",onClick:()=>i(!r),children:(0,le.jsxs)("div",{className:"flex items-start justify-between w-full",children:[(0,le.jsxs)("div",{className:"flex-1 min-w-0 mr-3",children:[(0,le.jsx)("div",{className:"font-medium text-sm mb-1",children:"Alternative Versions"}),(0,le.jsxs)("div",{className:"text-xs text-gray-500 leading-relaxed",children:["These versions may be from alternative paths,",(0,le.jsx)("br",{}),"created when reverting to previous checkpoints"]})]}),(0,le.jsx)("div",{className:"flex-shrink-0 ml-2",children:r?(0,le.jsx)(Is.A,{className:"h-4 w-4 text-gray-400"}):(0,le.jsx)(rn.A,{className:"h-4 w-4 text-gray-400"})})]})}),r&&(0,le.jsx)("div",{className:"space-y-2 mt-3",children:n.map(e=>{const t=null!=e.last_deployed_at,a=s.last_deployed_checkpoint_id===e.id;return(0,le.jsx)(Vm,{checkpoint:e,wasEverPublished:t,isCurrentlyPublished:a,onClick:()=>c(e),isSelected:(null==o?void 0:o.id)===e.id,size:"small"},e.id)})})]}),(0,le.jsx)(du,{showRevertDialog:e,setShowRevertDialog:t,selectedCheckpoint:o})]})};var _u=s(319),ku=s(36391);function Cu(){const{app:e}=Nt(),{user:t}=oe();return(0,le.jsx)(Yt,{variant:"ghost",size:"sm",className:"w-7 h-7 p-0 text-gray-500 hover:text-gray-700 hover:bg-gray-100 ",onClick:()=>{var s;ot.track("help_center_clicked",{user_id:null==t?void 0:t.id,app_id:null==e?void 0:e.id,conversation_id:null==e||null===(s=e.conversation)||void 0===s?void 0:s.id},{},{useBeacon:!0}).catch();const a=null!=e&&e.id?"/support?appId=".concat(e.id):"/support";window.open(a,"_blank")},title:"Help Center",children:(0,le.jsx)(ku.A,{size:16})})}var Au=s(86009),Su=s(80903),Eu=s(3255),Iu=s(15332);const Tu=["className","inset","children"],Pu=["className"],Lu=["className","sideOffset"],Ou=["className","inset"],Ru=["className","children","checked"],Mu=["className","children"],Du=["className","inset"],Fu=["className"],Bu=Lr.bL,zu=Lr.l9;Lr.YJ,Lr.ZL,Lr.Pb,Lr.z6;Y.forwardRef((e,t)=>{let{className:s,inset:a,children:n}=e,l=(0,Se.A)(e,Tu);return(0,le.jsxs)(Lr.ZP,(0,K.A)((0,K.A)({ref:t,className:Pe("flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent",a&&"pl-8",s)},l),{},{children:[n,(0,le.jsx)(rn.A,{className:"ml-auto h-4 w-4"})]}))}).displayName=Lr.ZP.displayName;Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,Pu);return(0,le.jsx)(Lr.G5,(0,K.A)({ref:t,className:Pe("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",s)},a))}).displayName=Lr.G5.displayName;const Uu=Y.forwardRef((e,t)=>{let{className:s,sideOffset:a=4}=e,n=(0,Se.A)(e,Lu);return(0,le.jsx)(Lr.ZL,{children:(0,le.jsx)(Lr.UC,(0,K.A)({ref:t,sideOffset:a,className:Pe("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",s)},n))})});Uu.displayName=Lr.UC.displayName;const Wu=Y.forwardRef((e,t)=>{let{className:s,inset:a}=e,n=(0,Se.A)(e,Ou);return(0,le.jsx)(Lr.q7,(0,K.A)({ref:t,className:Pe("relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",a&&"pl-8",s)},n))});Wu.displayName=Lr.q7.displayName;Y.forwardRef((e,t)=>{let{className:s,children:a,checked:n}=e,l=(0,Se.A)(e,Ru);return(0,le.jsxs)(Lr.H_,(0,K.A)((0,K.A)({ref:t,className:Pe("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",s),checked:n},l),{},{children:[(0,le.jsx)("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:(0,le.jsx)(Lr.VF,{children:(0,le.jsx)(Ps.A,{className:"h-4 w-4"})})}),a]}))}).displayName=Lr.H_.displayName;Y.forwardRef((e,t)=>{let{className:s,children:a}=e,n=(0,Se.A)(e,Mu);return(0,le.jsxs)(Lr.hN,(0,K.A)((0,K.A)({ref:t,className:Pe("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",s)},n),{},{children:[(0,le.jsx)("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:(0,le.jsx)(Lr.VF,{children:(0,le.jsx)(_s.A,{className:"h-2 w-2 fill-current"})})}),a]}))}).displayName=Lr.hN.displayName;const qu=Y.forwardRef((e,t)=>{let{className:s,inset:a}=e,n=(0,Se.A)(e,Du);return(0,le.jsx)(Lr.JU,(0,K.A)({ref:t,className:Pe("px-2 py-1.5 text-sm font-semibold",a&&"pl-8",s)},n))});qu.displayName=Lr.JU.displayName;const Vu=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,Fu);return(0,le.jsx)(Lr.wv,(0,K.A)({ref:t,className:Pe("-mx-1 my-1 h-px bg-muted",s)},a))});Vu.displayName=Lr.wv.displayName;function Hu(){return(0,zt.Ub)({maxWidth:767})}function Yu(e){let{onDataChange:t,onReset:s}=e;const{activeWorkspace:a}=ge(),n=Hu(),[l,r]=(0,Y.useState)(""),[i,o]=(0,Y.useState)(""),[c,d]=(0,Y.useState)(""),[m,u]=(0,Y.useState)(!1),[x,h]=(0,Y.useState)(!1);(0,Y.useEffect)(()=>{if(a){const e=a.is_personal||!1;if(h(e),e)r("Personal Workspace"),o(a.description||""),d(""),u(!0);else{r(a.name||""),o(a.description||""),d(a.domain||"");const e=a.user_role||"member";u(["admin","owner"].includes(e))}}},[a]),(0,Y.useEffect)(()=>{t&&a&&t({name:l,description:i,domain:c,canEdit:m,isPersonalWorkspace:x,workspaceId:a.id,hasChanges:p()})},[l,i,c,m,x,a,t]),(0,Y.useEffect)(()=>{if(s){const e=()=>{a&&(x?(r("Personal Workspace"),d("")):(r(a.name||""),d(a.domain||"")),o(a.description||""))};window.workspaceInfoReset=e}},[a,x,s]);const p=()=>{if(!a)return!1;const e=x?"Personal Workspace":a.name||"",t=a.description||"",s=x?"":a.domain||"";return l!==e||i!==t||c!==s};return a?(0,le.jsxs)("div",{className:"flex flex-col gap-6",children:[!n&&(0,le.jsx)("div",{className:"flex flex-col gap-3",children:(0,le.jsx)("div",{className:"text-black text-base font-semibold",children:"Workspace info"})}),(0,le.jsxs)("div",{className:"flex flex-col gap-3",children:[(0,le.jsx)("div",{className:"flex gap-3",children:(0,le.jsxs)("div",{className:"flex-1 flex flex-col gap-2",children:[(0,le.jsx)("label",{className:"text-gray-700 text-sm font-medium",children:"Workspace name"}),(0,le.jsx)("input",{type:"text",value:l,onChange:e=>{!x&&m&&r(e.target.value)},disabled:x||!m,className:"px-3 py-1.5 rounded-md border border-gray-300 text-sm ".concat(x||!m?"bg-zinc-100 text-neutral-400 cursor-not-allowed":"bg-white focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent"),placeholder:"Enter workspace name"})]})}),!x&&(0,le.jsx)("div",{className:"flex gap-3",children:(0,le.jsxs)("div",{className:"flex-1 flex flex-col gap-2",children:[(0,le.jsx)("label",{className:"text-gray-700 text-sm font-medium",children:"Workspace Domain"}),(0,le.jsx)("input",{type:"text",value:c,onChange:e=>{!x&&m&&d(e.target.value)},disabled:!m,className:"px-3 py-1.5 rounded-md border border-gray-300 text-sm ".concat(m?"bg-white focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent":"bg-zinc-100 text-neutral-400 cursor-not-allowed"),placeholder:"e.g., example.com"}),(0,le.jsx)("p",{className:"text-xs text-gray-500",children:"The domain associated with your workspace (optional)"})]})}),(0,le.jsx)("div",{className:"flex gap-3",children:(0,le.jsxs)("div",{className:"flex-1 flex flex-col gap-2",children:[(0,le.jsx)("label",{className:"text-gray-700 text-sm font-medium",children:"Workspace Description"}),(0,le.jsx)("textarea",{value:i,onChange:e=>{m&&o(e.target.value)},disabled:!m,className:"h-24 px-3 py-1.5 rounded-md border border-gray-300 text-sm resize-none ".concat(m?"bg-white focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent":"bg-zinc-100 text-neutral-400 cursor-not-allowed"),placeholder:"Add description"})]})})]})]}):(0,le.jsxs)("div",{className:"flex flex-col gap-6",children:[(0,le.jsx)("div",{className:"flex flex-col gap-3",children:(0,le.jsx)("div",{className:"text-black text-base font-semibold",children:"Workspace info"})}),(0,le.jsx)("div",{className:"text-gray-500 text-sm",children:"Loading workspace information..."})]})}function Gu(e){let{title:t,current:s,total:a,percentage:n,remaining:l}=e;const[r,i]=(0,Y.useState)(0);(0,Y.useEffect)(()=>{const e=setTimeout(()=>{i(n)},100);return()=>clearTimeout(e)},[n]);return(0,le.jsxs)("div",{className:"flex flex-col gap-2 animate-in fade-in duration-500",children:[(0,le.jsxs)("div",{className:"flex justify-between items-center",children:[(0,le.jsx)("div",{className:"text-gray-700 text-sm font-medium leading-tight",children:t}),(0,le.jsxs)("div",{className:"text-black text-sm font-medium leading-tight",children:[s,"/",a]})]}),(0,le.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,le.jsx)("div",{className:"flex items-center gap-3",children:(0,le.jsx)("div",{className:"flex-1 flex items-center gap-1.5",children:(0,le.jsx)("div",{className:"flex-1 h-2 bg-slate-100 rounded-full flex",children:(0,le.jsx)("div",{className:"h-full bg-gray-900 rounded-full transition-all duration-700 ease-out ".concat((e=>e>90?"bg-red-500":e>75?"bg-yellow-500":"bg-slate-600")(n)),style:{width:"".concat(r,"%")}})})})}),(0,le.jsxs)("div",{className:"flex justify-between items-center",children:[(0,le.jsxs)("div",{className:"text-gray-500 text-sm font-normal leading-tight",children:[n,"% used"]}),(0,le.jsxs)("div",{className:"text-gray-500 text-sm font-normal leading-tight",children:[l," ",t.toLowerCase().includes("credit")?"credits":"messages"," remaining"]})]})]})]})}var $u=s(81095),Ju=s(80294),Zu=s(93245),Ku=s(60158),Qu=s(44813),Xu=s(40992),ex=s(85706);function tx(e){let{usageByDate:t,height:s}=e;const a=e=>{try{return new Date(e).toLocaleDateString("en-US",{month:"short",day:"numeric"})}catch(t){return e}},n=(e=>{if(!e||!Array.isArray(e))return[];return[...e].sort((e,t)=>new Date(e._id)-new Date(t._id)).slice(-10).map(e=>(0,K.A)((0,K.A)({},e),{},{date:a(e._id),total_messages:e.total_messages||0}))})(t),l=e=>{let{active:t,payload:s,label:a}=e;return t&&s&&s.length?(0,le.jsxs)("div",{className:"bg-white p-3 border border-gray-200 shadow-lg rounded-md text-xs",children:[(0,le.jsx)("p",{className:"font-medium text-gray-900",children:s[0].payload.date}),(0,le.jsxs)("p",{className:"text-slate-700 mt-1",children:[(0,le.jsx)("span",{className:"font-medium",children:s[0].value})," messages"]})]}):null};return n.length?(0,le.jsxs)("div",{className:"flex flex-col gap-6",children:[(0,le.jsx)("div",{className:"text-gray-700 text-sm font-medium leading-tight",children:"Daily Usage (Messages)"}),(0,le.jsx)("div",{className:"".concat(s||"h-40"),children:(0,le.jsx)($u.u,{width:"100%",height:"100%",children:(0,le.jsxs)(Ju.E,{data:n,margin:{top:0,right:0,left:0,bottom:0},padding:{top:0,right:0,left:0,bottom:0},children:[(0,le.jsx)(Zu.d,{stroke:"#F3F4F6",vertical:!1,strokeWidth:1}),(0,le.jsx)(Ku.W,{dataKey:"date",textAnchor:"middle",height:26,fontSize:12,stroke:"#6b7280",tickMargin:10,axisLine:!1,tickLine:!1}),(0,le.jsx)(Qu.h,{fontSize:12,stroke:"#6b7280",axisLine:!1,tickLine:!1,tickCount:5,tickFormatter:e=>0===e?"0":e,width:38}),(0,le.jsx)(Xu.m,{content:(0,le.jsx)(l,{}),cursor:{fill:"rgba(71, 85, 105, 0.1)"}}),(0,le.jsx)(ex.y,{dataKey:"total_messages",name:"Messages",fill:"#f1f5f9",stroke:"#d1d5db",strokeWidth:1,radius:[4,4,0,0],maxBarSize:50,animationDuration:2e3})]})})})]}):(0,le.jsxs)("div",{className:"flex flex-col gap-6",children:[(0,le.jsx)("div",{className:"text-gray-700 text-sm font-medium leading-tight",children:"Daily Usage (Messages)"}),(0,le.jsx)("div",{className:"h-40 flex items-center justify-center",children:(0,le.jsx)("div",{className:"text-gray-500 text-sm",children:"No usage data available"})})]})}function sx(){var e,t,s;const[a,n]=(0,Y.useState)([]),[l,r]=(0,Y.useState)(!0),[i,o]=(0,Y.useState)(null),[c,d]=(0,Y.useState)(null),[m,u]=(0,Y.useState)([]),{user:x}=oe(),h=Hu(),{toast:p}=nn();(0,Y.useEffect)(()=>{g()},[]);const g=async()=>{try{r(!0);const[e,t]=await Promise.all([ke.default.getStats(),ke.default.getCurrentIntegrationUsage()]),s=e,a=t,l=[{title:"Monthly Messages",current:Math.round((null==s?void 0:s.monthly_usage)||0),total:(null==s?void 0:s.monthly_limit)||0,percentage:null!=s&&s.monthly_limit?Math.round(s.monthly_usage/s.monthly_limit*100):0,remaining:Math.max(0,((null==s?void 0:s.monthly_limit)||0)-Math.round((null==s?void 0:s.monthly_usage)||0))},...null!=s&&s.daily_limit?[{title:"Daily Messages",current:Math.round((null==s?void 0:s.daily_usage)||0),total:(null==s?void 0:s.daily_limit)||0,percentage:null!=s&&s.daily_limit?Math.round(s.daily_usage/s.daily_limit*100):0,remaining:Math.max(0,((null==s?void 0:s.daily_limit)||0)-Math.round((null==s?void 0:s.daily_usage)||0))}]:[],{title:"Integration Credits",current:(null==a?void 0:a.credits_this_month)||0,total:(null==a?void 0:a.credits_limit)||0,percentage:null!=a&&a.credits_limit?Math.round(a.credits_this_month/a.credits_limit*100):0,remaining:Math.max(0,((null==a?void 0:a.credits_limit)||0)-((null==a?void 0:a.credits_this_month)||0))}];n(l),u((null==s?void 0:s.usage_by_date)||[]),d({subscription_status:null==s?void 0:s.subscription_status,is_over_limit:null==s?void 0:s.is_over_limit,past_due:null==s?void 0:s.past_due,tier:null==s?void 0:s.tier}),o(null)}catch(e){o("Failed to load usage statistics"),n([{title:"Monthly Messages",current:0,total:0,percentage:0,remaining:0},{title:"Integration Credits",current:0,total:0,percentage:0,remaining:0}]),u([])}finally{r(!1)}};return l?(0,le.jsxs)("div",{className:"flex flex-col gap-6 animate-in fade-in duration-300",children:[!h&&(0,le.jsx)("div",{className:"flex flex-col gap-3",children:(0,le.jsx)("div",{className:"text-black text-base font-semibold leading-normal",children:"Credits Usages"})}),(0,le.jsx)("div",{className:"bg-gray-100 rounded-xl border border-gray-200 flex flex-col transition-all duration-300",children:(0,le.jsx)("div",{className:"p-6 flex items-center justify-center",children:(0,le.jsx)("div",{className:"animate-spin rounded-full h-12 w-12 border-t-2 border-b-2 border-slate-700"})})})]}):i?(0,le.jsxs)("div",{className:"flex flex-col gap-6 animate-in fade-in duration-300",children:[!h&&(0,le.jsx)("div",{className:"flex flex-col gap-3",children:(0,le.jsx)("div",{className:"text-black text-base font-semibold leading-normal",children:"Credits Usages"})}),(0,le.jsx)("div",{className:"bg-gray-100 rounded-xl border border-gray-200 flex flex-col transition-all duration-300",children:(0,le.jsx)("div",{className:"p-6 flex items-center justify-center",children:(0,le.jsx)("div",{className:"text-red-500 animate-in fade-in duration-500",children:i})})})]}):(0,le.jsxs)("div",{className:"flex flex-col gap-6 animate-in fade-in duration-500",children:[!h&&(0,le.jsx)("div",{className:"flex flex-col gap-3",children:(0,le.jsx)("div",{className:"text-black text-base font-semibold leading-normal",children:"Credits Usages"})}),(0,le.jsxs)("div",{className:"bg-gray-100 rounded-xl border border-gray-200 flex flex-col transition-all duration-300",children:[(0,le.jsxs)("div",{className:"pl-6 pr-3 py-3 rounded-t-xl flex items-center gap-2.5 animate-in fade-in slide-in-from-top-2 duration-400",children:[(0,le.jsxs)("div",{className:"flex-1 flex items-center gap-2",children:[(0,le.jsxs)("div",{className:"text-black text-base font-medium leading-normal",children:["You're currently on the ",x.subscription_tier.charAt(0).toUpperCase()+x.subscription_tier.slice(1)," Plan"]}),(null==c?void 0:c.is_over_limit)&&(0,le.jsx)("div",{className:"px-2 py-1 bg-red-100 text-red-600 text-xs rounded-md animate-in fade-in duration-500",children:"Over Limit"})]}),"elite3"!==x.subscription_tier&&(0,le.jsx)("button",{onClick:async()=>{if(null!=c&&c.past_due)try{const e="payment_method_update",t=await $o.createPortalSession(e);window.location.href=t.url}catch(i){p({variant:"destructive",title:"Error",description:"Failed to open payment management. Please try again."})}else window.open("/billing","_blank")},className:"px-4 py-1.5 bg-white rounded-md shadow-[0px_1px_2px_0px_rgba(0,0,0,0.10)] border border-orange-500 flex items-center gap-2.5 hover:bg-orange-50 transition-all duration-200 animate-in fade-in slide-in-from-right-2 duration-500",children:(0,le.jsx)("div",{className:"text-orange-500 text-sm font-medium leading-tight",children:null!=c&&c.past_due?"Update Payment":"Upgrade Plan"})})]}),(null==c?void 0:c.past_due)&&(0,le.jsx)("div",{className:"mx-6 mt-3 mb-3 p-4 bg-orange-50 border border-orange-200 rounded-lg animate-in fade-in duration-500",children:(0,le.jsxs)("div",{className:"flex items-start gap-3",children:[(0,le.jsx)("div",{className:"flex-shrink-0 w-5 h-5 bg-orange-500 rounded-full flex items-center justify-center mt-0.5",children:(0,le.jsx)("svg",{className:"w-3 h-3 text-white",fill:"currentColor",viewBox:"0 0 20 20",children:(0,le.jsx)("path",{fillRule:"evenodd",d:"M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z",clipRule:"evenodd"})})}),(0,le.jsxs)("div",{className:"flex-1",children:[(0,le.jsx)("h3",{className:"text-orange-800 font-medium text-sm mb-1",children:"Payment overdue"}),(0,le.jsxs)("p",{className:"text-orange-700 text-sm",children:["Your subscription payment is past due. Credits and limits shown are based on your last paid plan (",(null==c||null===(e=c.tier)||void 0===e||null===(t=e.charAt(0))||void 0===t?void 0:t.toUpperCase())+(null==c||null===(s=c.tier)||void 0===s?void 0:s.slice(1)),")."]})]})]})}),(0,le.jsxs)("div",{className:"p-6 bg-white rounded-xl border border-gray-200 flex flex-col gap-6 animate-in fade-in slide-in-from-bottom-2 duration-600",children:[a.map((e,t)=>(0,le.jsx)("div",{style:{animationDelay:"".concat(100*t,"ms")},className:"animate-in fade-in slide-in-from-bottom-1 duration-500",children:(0,le.jsx)(Gu,(0,K.A)({},e))},t)),(0,le.jsx)("div",{style:{animationDelay:"".concat(100*a.length,"ms")},className:"animate-in fade-in slide-in-from-bottom-1 duration-500",children:(0,le.jsx)(tx,{usageByDate:m})})]})]})]})}function ax(){const e=Hu(),[t,s]=(0,Y.useState)(!1),[a,n]=(0,Y.useState)(null),l=(0,Y.useCallback)(e=>{n(e)},[]),r=(null==a?void 0:a.canEdit)&&(null==a?void 0:a.hasChanges);return(0,le.jsxs)("div",{className:"h-full flex flex-col",children:[(0,le.jsx)("div",{className:"flex-1 overflow-y-auto",children:(0,le.jsxs)("div",{className:"".concat(e?"px-5 pt-6":"px-6"," pb-6 md:px-8 md:pb-8 lg:px-10 lg:pb-10 space-y-8"),children:[(0,le.jsx)(Yu,{onDataChange:l,onReset:!0}),(0,le.jsx)(sx,{})]})}),r&&(0,le.jsxs)("div",{className:"flex-shrink-0 p-4 bg-white border-t border-gray-200 flex justify-end items-center gap-3",children:[(0,le.jsx)("button",{onClick:()=>{window.workspaceInfoReset&&window.workspaceInfoReset()},disabled:t,className:"px-4 py-2 bg-white rounded-md border border-gray-300 hover:bg-gray-50 transition-colors text-sm font-medium disabled:opacity-50 disabled:cursor-not-allowed",children:"Cancel"}),(0,le.jsx)("button",{onClick:async()=>{if(a&&a.canEdit&&a.hasChanges){s(!0);try{const e={};a.isPersonalWorkspace||void 0===a.name||(e.name=a.name),void 0!==a.description&&(e.description=a.description),a.isPersonalWorkspace||void 0===a.domain||(e.domain=a.domain),await xe.updateWorkspace(a.workspaceId,e),cr.default.success("Workspace settings updated successfully!")}catch(n){var e,t;cr.default.error("Failed to update workspace settings: "+((null===(e=n.response)||void 0===e||null===(t=e.data)||void 0===t?void 0:t.detail)||n.message||"Unknown error"))}finally{s(!1)}}},disabled:t,className:"px-4 py-2 bg-black text-white rounded-md hover:bg-gray-800 transition-colors text-sm font-medium disabled:opacity-50 disabled:cursor-not-allowed",children:t?"Saving...":"Save Changes"})]})]})}var nx=s(66987),lx=s(59222);const rx=["className"],ix=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,rx);return(0,le.jsx)(lx.bL,(0,K.A)((0,K.A)({className:Pe("peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",s)},a),{},{ref:t,children:(0,le.jsx)(lx.zi,{className:Pe("pointer-events-none block h-5 w-5 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-5 data-[state=unchecked]:translate-x-0")})}))});ix.displayName=lx.bL.displayName;const ox=["free","starter","builder","pro","elite","elite_2","elite_3","elite_4","enterprise"],cx=(e,t)=>{const s=(null==e?void 0:e.subscription_tier)||"free",a=ox.indexOf(s),n=ox.indexOf(t);return a>=0&&n>=0&&a>=n},dx=e=>cx(e,"builder"),mx=e=>cx(e,"builder");var ux=s(15924);const xx=()=>(0,le.jsxs)(De,{variant:"warning",className:"bg-gray-50 border-gray-200",children:[(0,le.jsx)(ux.A,{className:"h-4 w-4 text-gray-500"}),(0,le.jsx)(Fe,{className:"text-gray-800",children:"Premium Feature"}),(0,le.jsxs)(Be,{className:"text-gray-600",children:["Backend functions are available only for Builder tier and above.",(0,le.jsx)("a",{href:"/billing",className:"ml-1 underline font-medium text-gray-700 hover:text-gray-900",children:"Upgrade your plan"})," to unlock this feature."]})]});var hx=s(77834);function px(e){let{userEmail:t,userFullName:s,profileImageUrl:a,size:n="default"}=e;const{activeWorkspace:l}=ge(),r={default:{containerClass:"flex items-center gap-3 pl-4 pr-1 py-1 rounded-xl bg-[rgba(103,48,23,0.05)] hover:bg-[rgba(103,48,23,0.10)] transition-colors duration-150 cursor-pointer",imageClass:"h-7 w-7 rounded-lg object-cover bg-white",initialsClass:"h-7 w-7 rounded-lg bg-white flex items-center justify-center text-sm font-base44 font-semibold text-slate-600 select-none",showWorkspace:!0},lg:{containerClass:"flex items-center justify-center",imageClass:"h-16 w-16 rounded-2xl object-cover bg-white",initialsClass:"h-16 w-16 rounded-2xl bg-gray-100 flex items-center justify-center text-2xl font-base44 font-semibold text-slate-600 select-none",showWorkspace:!1}},i=r[n]||r.default;return(0,le.jsxs)("div",{className:i.containerClass,title:"".concat(s||"Unknown"," (").concat(t||"No email",")"),children:[i.showWorkspace&&(0,le.jsx)("span",{className:"text-sm font-base44 font-light text-slate-700",children:l&&!l.is_personal?"".concat(l.name.length>8?l.name.substring(0,8)+"...":l.name):"My Workspace"}),a?(0,le.jsx)("img",{src:a,alt:"".concat(s||"User"," profile"),className:i.imageClass,onError:e=>{e.target.style.display="none";const t=e.target.nextElementSibling;t&&(t.style.display="flex")}}):null,(0,le.jsx)("div",{className:i.initialsClass,style:{display:a?"none":"flex"},children:s?s.charAt(0).toUpperCase():"U"})]})}function gx(e){let{size:t="default"}=e;const{user:s}=oe();return s?(0,le.jsx)(px,{userEmail:null==s?void 0:s.email,userFullName:null==s?void 0:s.full_name,profileImageUrl:null==s?void 0:s.profile_image_url,size:t}):null}function fx(e){let{value:t,onChange:s,userEmail:a,userFullName:n}=e;const[l,r]=(0,Y.useState)(!1),[i,o]=(0,Y.useState)(!1),[c,d]=(0,Y.useState)(!1),m=(0,Y.useRef)(null);return(0,le.jsxs)("div",{className:"flex flex-col lg:flex-row lg:items-start gap-3",children:[(0,le.jsx)("div",{className:"text-gray-700 text-sm font-medium lg:w-48 lg:flex-shrink-0 lg:mt-2",children:"Profile Image"}),(0,le.jsxs)("div",{className:"flex-1",children:[(0,le.jsxs)("div",{className:"relative cursor-pointer group inline-block",onClick:()=>{var e;null===(e=m.current)||void 0===e||e.click()},title:"Click to upload image",children:[t&&!l?(0,le.jsx)("img",{src:t,alt:"Profile",className:"h-12 w-12 rounded-lg object-cover border border-slate-300 group-hover:border-slate-400 transition-colors",onLoad:()=>{r(!1),o(!0)},onError:()=>{r(!0),o(!1)},style:{display:i&&!l?"block":"none"}}):null,(!t||l||!i)&&(0,le.jsx)("div",{className:"h-12 w-12 rounded-lg text-slate-600 border border-slate-300 flex items-center justify-center bg-slate-50 font-medium group-hover:border-slate-400 transition-colors",children:n?n.charAt(0).toUpperCase():"U"}),(0,le.jsx)("div",{className:"absolute inset-0 bg-black bg-opacity-0 group-hover:bg-opacity-30 rounded-lg flex items-center justify-center transition-all duration-200",children:(0,le.jsx)(hx.A,{className:"w-4 h-4 text-white opacity-0 group-hover:opacity-100 transition-opacity"})}),c&&(0,le.jsx)("div",{className:"absolute inset-0 bg-white bg-opacity-75 rounded-lg flex items-center justify-center",children:(0,le.jsx)("div",{className:"animate-spin rounded-full h-6 w-6 border-t-2 border-b-2 border-gray-900"})})]}),(0,le.jsx)("input",{ref:m,type:"file",accept:"image/jpeg,image/jpg,image/png,image/gif,image/webp",onChange:async e=>{const t=e.target.files[0];if(!t)return;if(!["image/jpeg","image/jpg","image/png","image/gif","image/webp"].includes(t.type))return void cr.default.error("Please upload a valid image file (JPG, PNG, GIF, or WebP)");if(t.size>5242880)cr.default.error("Image must be less than 5MB");else try{d(!0);const e=(await _t.uploadFile(t)).url;s(e),cr.default.success("Profile image uploaded successfully!")}catch(a){cr.default.error("Failed to upload image. Please try again.")}finally{d(!1)}},className:"hidden"})]})]})}function vx(){const{user:e,updateUser:t}=oe(),s=Hu(),[a,n]=(0,Y.useState)(!1),l=dx(e),[r,i]=(0,Y.useState)(!1),[o,c]=(0,Y.useState)(!1),[d,m]=(0,Y.useState)({email:"",fullName:"",phoneNumber:"",profileImageUrl:"",notificationPreference:"every_prompt",enableBackendFunctionsByDefault:!1,enableAgentsByDefault:!1});(0,Y.useEffect)(()=>{if(e){const t=dx(e);m({email:e.email||"",fullName:e.full_name||"",phoneNumber:e.phone_number||"",profileImageUrl:e.profile_image_url||"",enableBackendFunctionsByDefault:t&&e.enable_backend_functions_by_default||!1,enableAgentsByDefault:e.enable_agents_by_default||!1,notificationPreference:e.notification_preference||"every_prompt"})}},[e]);const u=e&&(d.fullName!==(e.full_name||"")||d.phoneNumber!==(e.phone_number||"")||d.profileImageUrl!==(e.profile_image_url||"")||d.enableBackendFunctionsByDefault!==(l&&e.enable_backend_functions_by_default||!1)||d.enableAgentsByDefault!==(e.enable_agents_by_default||!1)||d.notificationPreference!==(e.notification_preference||"every_prompt")),x=(e,t)=>{m(s=>(0,K.A)((0,K.A)({},s),{},{[e]:t}))};return e?(0,le.jsxs)("div",{className:"h-full flex flex-col",children:[(0,le.jsx)("div",{className:"flex-1 overflow-y-auto",children:(0,le.jsx)("div",{className:"".concat(s?"px-5 pt-6":"px-6"," pb-6 md:px-8 md:pb-8 lg:px-10 lg:pb-10 space-y-8"),children:(0,le.jsxs)("div",{className:"space-y-6",children:[!s&&(0,le.jsx)("div",{className:"space-y-3",children:(0,le.jsx)("div",{className:"text-black text-base font-semibold",children:"Account"})}),(0,le.jsxs)("div",{className:"space-y-6",children:[(0,le.jsxs)("div",{className:"flex flex-col lg:flex-row lg:items-start gap-3",children:[(0,le.jsx)("div",{className:"text-gray-700 text-sm font-medium lg:w-48 lg:flex-shrink-0 lg:mt-2",children:"Email"}),(0,le.jsx)("div",{className:"flex-1",children:(0,le.jsx)("input",{type:"email",value:d.email,disabled:!0,className:"w-full px-3 py-1.5 bg-zinc-100 rounded-md border border-gray-300 text-neutral-400 text-sm",placeholder:"No email set"})})]}),(0,le.jsxs)("div",{className:"flex flex-col lg:flex-row lg:items-start gap-3",children:[(0,le.jsx)("div",{className:"text-gray-700 text-sm font-medium lg:w-48 lg:flex-shrink-0 lg:mt-2",children:"Full Name"}),(0,le.jsx)("div",{className:"flex-1",children:(0,le.jsx)("input",{type:"text",value:d.fullName,onChange:e=>x("fullName",e.target.value),className:"w-full px-3 py-1.5 bg-white rounded-md border border-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent text-sm",placeholder:"Enter your full name",required:!0})})]}),(0,le.jsxs)("div",{className:"flex flex-col lg:flex-row lg:items-start gap-3",children:[(0,le.jsx)("div",{className:"text-gray-700 text-sm font-medium lg:w-48 lg:flex-shrink-0 lg:mt-2",children:"Phone Number"}),(0,le.jsxs)("div",{className:"flex-1 space-y-2",children:[(0,le.jsx)("input",{type:"tel",value:d.phoneNumber,onChange:e=>x("phoneNumber",e.target.value),className:"w-full px-3 py-1.5 bg-white rounded-md border border-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent text-sm",placeholder:"Enter your phone number"}),(0,le.jsx)("div",{className:"text-gray-500 text-xs",children:"By entering your phone number, you agree to receive SMS notifications from us."})]})]}),(0,le.jsx)(fx,{value:d.profileImageUrl,onChange:e=>x("profileImageUrl",e),userEmail:d.email,userFullName:d.fullName}),(0,le.jsxs)("div",{className:"flex flex-col lg:flex-row lg:items-start gap-3",children:[(0,le.jsx)("div",{className:"text-gray-700 text-sm font-medium lg:w-48 lg:flex-shrink-0 lg:mt-2",children:"Notification Sound Preference"}),(0,le.jsxs)("div",{className:"flex-1 space-y-2",children:[(0,le.jsxs)(zs,{value:d.notificationPreference,onValueChange:e=>x("notificationPreference",e),children:[(0,le.jsx)(qs,{advancedDropdown:!0,className:"w-full h-auto p-2 bg-white border border-gray-200 hover:bg-gray-50 hover:border-gray-300 transition-colors duration-200",children:(0,le.jsx)("div",{className:"w-full text-left",children:(0,le.jsx)("div",{className:"w-full flex flex-col gap-1",children:(0,le.jsx)("div",{className:"text-sm text-gray-900",children:(0,le.jsx)("span",{className:"font-[500]",children:(e=>{switch(e){case"on_first_prompt":return"On first prompt only";case"every_prompt":default:return"On every prompt";case"never":return"Disable notification sounds"}})(d.notificationPreference)})})})})}),(0,le.jsxs)(Ys,{className:"w-[calc(100%-1rem)] max-w-[400px] z-50 p-1.5",sideOffset:4,children:[(0,le.jsx)($s,{value:"on_first_prompt",className:"px-4 py-3 border-b border-gray-100 last:border-b-0 hover:bg-gray-50 transition-colors duration-200",hideCheckIcon:!0,children:(0,le.jsx)("div",{className:"w-full flex flex-col gap-1",children:(0,le.jsx)("div",{className:"text-sm leading-[17px] text-gray-900",children:(0,le.jsx)("span",{className:"font-bold",children:"On first prompt only"})})})}),(0,le.jsx)($s,{value:"every_prompt",className:"px-4 py-3 border-b border-gray-100 last:border-b-0 hover:bg-gray-50 transition-colors duration-200",hideCheckIcon:!0,children:(0,le.jsx)("div",{className:"w-full flex flex-col gap-1",children:(0,le.jsx)("div",{className:"text-sm leading-[17px] text-gray-900",children:(0,le.jsx)("span",{className:"font-bold",children:"On every prompt"})})})}),(0,le.jsx)($s,{value:"never",className:"px-4 py-3 border-b border-gray-100 last:border-b-0 hover:bg-gray-50 transition-colors duration-200",hideCheckIcon:!0,children:(0,le.jsx)("div",{className:"w-full flex flex-col gap-1",children:(0,le.jsx)("div",{className:"text-sm leading-[17px] text-gray-900",children:(0,le.jsx)("span",{className:"font-bold",children:"Disable notification sounds"})})})})]})]}),(0,le.jsx)("div",{className:"text-gray-500 text-xs",children:"Choose when to play notification sounds when your app completes prompts."})]})]}),(0,le.jsxs)("div",{className:"flex flex-col lg:flex-row lg:items-start gap-3",children:[(0,le.jsx)("div",{className:"text-gray-700 text-sm font-medium lg:w-48 lg:flex-shrink-0 lg:mt-2",children:"Default Backend Functions"}),(0,le.jsxs)("div",{className:"flex-1 space-y-2",children:[(0,le.jsxs)("div",{className:"flex items-center gap-3",children:[(0,le.jsx)(ix,{checked:d.enableBackendFunctionsByDefault,onCheckedChange:e=>x("enableBackendFunctionsByDefault",e),disabled:!l,className:"data-[state=checked]:bg-black"}),(0,le.jsx)("div",{className:"text-sm text-gray-700",children:"Enable backend functions for new apps by default"})]}),(0,le.jsx)("div",{className:"text-gray-500 text-xs",children:"When enabled, new apps will automatically have backend functions activated."}),!l&&(0,le.jsx)(xx,{})]})]}),(0,le.jsxs)("div",{className:"flex flex-col lg:flex-row lg:items-start gap-3",children:[(0,le.jsx)("div",{className:"text-gray-700 text-sm font-medium lg:w-48 lg:flex-shrink-0 lg:mt-2",children:"Default Agents"}),(0,le.jsxs)("div",{className:"flex-1 space-y-2",children:[(0,le.jsxs)("div",{className:"flex items-center gap-3",children:[(0,le.jsx)(ix,{checked:d.enableAgentsByDefault,onCheckedChange:e=>x("enableAgentsByDefault",e),className:"data-[state=checked]:bg-black"}),(0,le.jsx)("div",{className:"text-sm text-gray-700",children:"Enable agents for new apps by default"})]}),(0,le.jsx)("div",{className:"text-gray-500 text-xs",children:"When enabled, new apps will automatically have agents enabled, allowing them to run autonomous tasks and use tools."})]})]}),(0,le.jsxs)("div",{className:"flex flex-col lg:flex-row lg:items-start gap-3",children:[(0,le.jsx)("div",{className:"text-gray-700 text-sm font-medium lg:w-48 lg:flex-shrink-0 lg:mt-2",children:"API Key"}),(0,le.jsxs)("div",{className:"flex-1 space-y-2",children:[(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[(0,le.jsx)("div",{className:"flex-1 h-10 px-3 py-2 bg-zinc-100 rounded-md border border-gray-300 flex items-center min-w-0",children:(0,le.jsx)("div",{className:"text-black text-sm font-mono truncate",children:e.api_key})}),(0,le.jsxs)("button",{onClick:async()=>{try{await navigator.clipboard.writeText(e.api_key),c(!0),cr.default.success("API key copied to clipboard!"),setTimeout(()=>c(!1),2e3)}catch(t){cr.default.error("Failed to copy API key")}},className:"w-9 h-9 bg-white rounded-md border border-stone-300 flex items-center justify-center hover:bg-gray-50 transition-colors relative flex-shrink-0",title:"Copy API key",children:[(0,le.jsx)(or.A,{size:16}),o&&(0,le.jsx)("div",{className:"absolute -top-8 left-1/2 transform -translate-x-1/2 bg-black text-white text-xs px-2 py-1 rounded",children:"Copied!"})]}),(0,le.jsxs)("button",{onClick:async()=>{i(!0);try{const s=await se.regenerateApiKey(e.id);t(s),cr.default.success("API key regenerated successfully!")}catch(s){cr.default.error("Failed to regenerate API key: "+(s.detail||s.message||"Unknown error"))}finally{i(!1)}},disabled:r,className:"h-9 px-2 sm:px-4 py-1.5 bg-white rounded-md border border-stone-300 hover:bg-gray-50 transition-colors flex items-center gap-1 sm:gap-2 disabled:opacity-50 disabled:cursor-not-allowed flex-shrink-0",children:[(0,le.jsx)(nx.A,{size:14,className:r?"animate-spin":""}),(0,le.jsx)("div",{className:"text-black text-xs sm:text-sm font-medium hidden sm:block",children:r?"Regenerating...":"Regenerate"}),(0,le.jsx)("div",{className:"text-black text-xs font-medium sm:hidden",children:r?"Regen...":"Regen"})]})]}),(0,le.jsx)("div",{className:"text-gray-500 text-xs",children:"Your API key provides access to your workspace. Do not share it with others."})]})]})]})]})})}),u&&(0,le.jsxs)("div",{className:"flex-shrink-0 p-4 bg-white border-t border-gray-200 flex justify-end items-center gap-3",children:[(0,le.jsx)("button",{onClick:()=>{if(e){const t=dx(e);m({email:e.email||"",fullName:e.full_name||"",phoneNumber:e.phone_number||"",profileImageUrl:e.profile_image_url||"",notificationPreference:e.notification_preference||"every_prompt",enableBackendFunctionsByDefault:t&&e.enable_backend_functions_by_default||!1,enableAgentsByDefault:e.enable_agents_by_default||!1})}},disabled:a,className:"px-4 py-2 bg-white rounded-md border border-gray-300 hover:bg-gray-50 transition-colors text-sm font-medium disabled:opacity-50 disabled:cursor-not-allowed",children:"Cancel"}),(0,le.jsx)("button",{onClick:async()=>{n(!0);try{const s=await se.updateUser(e.id,{full_name:d.fullName.length>0?d.fullName:null,phone_number:(d.phoneNumber||"").length>0?d.phoneNumber:null,profile_image_url:(d.profileImageUrl||"").length>0?d.profileImageUrl:null,notification_preference:d.notificationPreference,enable_backend_functions_by_default:!!l&&d.enableBackendFunctionsByDefault,enable_agents_by_default:d.enableAgentsByDefault});t(s);const a=dx(s);m({email:s.email||"",fullName:s.full_name||"",phoneNumber:s.phone_number||"",profileImageUrl:s.profile_image_url||"",notificationPreference:s.notification_preference||"every_prompt",enableBackendFunctionsByDefault:a&&s.enable_backend_functions_by_default||!1,enableAgentsByDefault:s.enable_agents_by_default||!1}),cr.default.success("Account settings updated successfully!")}catch(s){cr.default.error("Failed to update account settings: "+(s.detail||s.message||"Unknown error"))}finally{n(!1)}},disabled:a,className:"px-4 py-2 bg-black text-white rounded-md hover:bg-gray-800 transition-colors text-sm font-medium disabled:opacity-50 disabled:cursor-not-allowed",children:a?"Saving...":"Save Changes"})]})]}):(0,le.jsx)("div",{className:"h-full flex items-center justify-center",children:(0,le.jsx)("div",{className:"animate-spin rounded-full h-8 w-8 border-t-2 border-b-2 border-gray-900"})})}function bx(){const{user:e}=oe(),t=Hu(),[s,a]=(0,Y.useState)([]),[n,l]=(0,Y.useState)(!0),[r,i]=(0,Y.useState)(null),o=()=>{window.open("/billing","_blank")},c=e=>{const t=parseInt(e);if(t>=1e3){const e=t/1e3;return"".concat(e%1==0?e:e.toFixed(1),"k")}return t.toString()};(0,Y.useEffect)(()=>{(async()=>{try{l(!0);const e=await ke.default.getMonthlyPlans();if(e&&e.plans){const t=["starter","builder","pro","elite"],s=e.plans.filter(e=>t.includes(e.tier)),n=s.sort((e,t)=>t.price_data.unit_amount-e.price_data.unit_amount).map(e=>((e,t)=>{var s,a;const n=(null===(s=t.metadata)||void 0===s?void 0:s.monthly_message_limit)||"0",l=(null===(a=t.metadata)||void 0===a?void 0:a.monthly_integration_credits)||"0",r=e.charAt(0).toUpperCase()+e.slice(1),i="pro"===e?"Upgrade to "+r:"Upgrade";return{name:r,monthlyCredits:c(n),integrationCredits:c(l),buttonText:i,isRecommended:"pro"===e,price:"$".concat(Math.round(t.unit_amount/100))}})(e.tier,e.price_data));a(n)}else i("Unable to load pricing information")}catch(e){i("Failed to load plans")}finally{l(!1)}})()},[]);return n?(0,le.jsx)("div",{className:"self-stretch px-10 bg-white inline-flex flex-col justify-start items-start gap-10",children:(0,le.jsxs)("div",{className:"self-stretch flex flex-col justify-start items-start gap-3",children:[(0,le.jsx)("div",{className:"text-black text-base font-semibold leading-normal",children:"Plan & Billing"}),(0,le.jsx)("div",{className:"flex items-center justify-center h-32",children:(0,le.jsx)("div",{className:"animate-spin rounded-full h-8 w-8 border-t-2 border-b-2 border-gray-900"})})]})}):r?(0,le.jsx)("div",{className:"self-stretch px-10 bg-white inline-flex flex-col justify-start items-start gap-10",children:(0,le.jsxs)("div",{className:"self-stretch flex flex-col justify-start items-start gap-3",children:[(0,le.jsx)("div",{className:"text-black text-base font-semibold leading-normal",children:"Plan & Billing"}),(0,le.jsx)("div",{className:"text-red-500 text-sm",children:r})]})}):(0,le.jsx)("div",{className:"self-stretch ".concat(t?"px-5 pt-6":"px-10"," bg-white inline-flex flex-col justify-start items-start gap-10"),children:(0,le.jsxs)("div",{className:"self-stretch flex flex-col justify-start items-start gap-3",children:[!t&&(0,le.jsx)("div",{className:"self-stretch flex flex-col justify-center items-start gap-2",children:(0,le.jsx)("div",{className:"justify-start text-black text-base font-semibold leading-normal",children:"Plan & Billing"})}),(0,le.jsxs)("div",{className:"self-stretch inline-flex justify-between items-center",children:[(0,le.jsxs)("div",{className:"justify-start text-gray-600 text-sm font-normal leading-tight",children:["You're currently on the ",e.subscription_tier.charAt(0).toUpperCase()+e.subscription_tier.slice(1)," Plan"]}),(0,le.jsx)("div",{"data-prefix":"Off","data-size":"Small","data-state":"Default","data-suffix":"Off","data-type":"Link",className:"inline-flex flex-col justify-start items-start cursor-pointer",onClick:o,children:(0,le.jsx)("div",{className:"py-1.5 rounded-md flex flex-col justify-center items-center gap-2.5",children:(0,le.jsx)("div",{className:"inline-flex justify-center items-center gap-2.5",children:(0,le.jsx)("div",{className:"justify-start text-text-default text-xs font-medium leading-none",children:"Compare Plans"})})})})]}),(0,le.jsx)("div",{className:"self-stretch flex flex-col justify-start items-start",children:(0,le.jsx)("div",{className:"self-stretch inline-flex justify-start items-end gap-2",children:s.map(e=>{const t=e.isRecommended?"outline-orange-400":"outline-gray-200",s=e.isRecommended?"bg-orange-500":"bg-zinc-100",a=e.isRecommended?"text-white":"text-black";return(0,le.jsxs)("div",{className:"flex-1 rounded-xl outline outline-1 w-[171px] outline-offset-[-0.50px] ".concat(t," inline-flex flex-col justify-end items-start overflow-hidden"),children:[(0,le.jsxs)("div",{className:"self-stretch px-3 pt-3 bg-white rounded-bl-xl rounded-br-xl flex flex-col justify-start items-start",children:[(0,le.jsxs)("div",{className:"self-stretch h-6 inline-flex justify-start items-start gap-1",children:[(0,le.jsx)("div",{className:"justify-center text-black text-sm font-normal",children:e.name}),e.isRecommended&&(0,le.jsx)("div",{className:"px-2 py-0.5 bg-red-100 rounded flex justify-center items-center gap-2.5",children:(0,le.jsx)("div",{className:"justify-center text-orange-500 text-xs font-medium leading-3",children:"Recommended"})})]}),(0,le.jsx)("div",{className:"self-stretch pt-1.5 inline-flex justify-start items-end gap-[3px]",children:(0,le.jsxs)("div",{className:"flex justify-start items-end gap-0.5",children:[(0,le.jsx)("div",{className:"justify-center text-black text-xl font-semibold",children:e.price}),(0,le.jsx)("div",{className:"w-7 h-6 justify-start text-stone-300 text-sm font-normal",children:"/mo"})]})}),(0,le.jsxs)("div",{className:"self-stretch pt-11 pb-3 flex flex-col justify-start items-start gap-1",children:[(0,le.jsxs)("div",{className:"self-stretch inline-flex justify-start items-start gap-1.5",children:[(0,le.jsx)("div",{className:"w-7 justify-center text-black text-xs font-semibold leading-none",children:e.monthlyCredits}),(0,le.jsx)("div",{className:"flex-1 justify-center text-zinc-600 text-xs font-normal leading-none",children:"monthly credits"})]}),(0,le.jsxs)("div",{className:"self-stretch inline-flex justify-start items-start gap-1.5",children:[(0,le.jsx)("div",{className:"w-7 justify-center text-black text-xs font-semibold leading-none",children:e.integrationCredits}),(0,le.jsx)("div",{className:"flex-1 justify-center text-zinc-600 text-xs font-normal leading-none",children:"integration credits"})]})]})]}),(0,le.jsx)("div",{className:"self-stretch p-2 inline-flex justify-center items-center gap-2.5",children:(0,le.jsx)("div",{className:"flex-1 h-8 ".concat(s," rounded-md inline-flex flex-col justify-center items-center overflow-hidden"),children:(0,le.jsx)("div",{className:"self-stretch flex-1 px-4 rounded-md inline-flex justify-center items-center gap-1.5 cursor-pointer",onClick:o,children:(0,le.jsx)("div",{className:"inline-flex flex-col justify-center items-start",children:(0,le.jsx)("div",{className:"self-stretch justify-start text-sm font-medium leading-normal ".concat(a),children:e.buttonText})})})})})]},e.name)})})})]})})}function jx(e){var t;let{handleModalClose:s}=e;const{user:a}=oe(),n=(0,Z.Zp)(),l=Hu(),{toast:r}=nn(),[i,o]=(0,Y.useState)([]),[c,d]=(0,Y.useState)(null),[m,u]=(0,Y.useState)(!0),[x,h]=(0,Y.useState)(null),p=a.subscription_tier.replace(/_/g," "),g=p.charAt(0).toUpperCase()+p.slice(1);(0,Y.useEffect)(()=>{(async()=>{try{u(!0);const[e,t]=await Promise.all([$o.getInvoices(),ke.default.getStats()]);o(e.invoices||[]),d(t)}catch(e){h("Failed to load billing data")}finally{u(!1)}})()},[]);const f=async()=>{try{const e="past_due"===a.stripe_subscription_status?"payment_method_update":void 0,t=await $o.createPortalSession(e);"past_due"===a.stripe_subscription_status?window.location.href=t.url:window.open(t.url,"_blank")}catch(x){r({variant:"destructive",title:"Error",description:"Failed to open payment management. Please try again."})}},v=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"USD";return new Intl.NumberFormat("en-US",{style:"currency",currency:t}).format(e)},b=e=>e?new Date(e).toLocaleDateString("en-US",{year:"numeric",month:"long",day:"numeric"}):"N/A",j=!0===(null==c||null===(t=c.stripe_subscription)||void 0===t?void 0:t.cancel_at_period_end),y=e=>{switch(e.toLowerCase()){case"paid":return{background:"outline-emerald-700",text:"text-emerald-700"};case"pending":case"open":return{background:"outline-orange-500",text:"text-orange-500"};case"failed":case"past_due":return{background:"outline-red-500",text:"text-red-500"};default:return{background:"outline-gray-500",text:"text-gray-500"}}};return(0,le.jsx)("div",{className:"self-stretch bg-white flex flex-col justify-start items-start h-full overflow-y-auto",style:{scrollbarGutter:"stable"},children:(0,le.jsxs)("div",{className:"w-full ".concat(l?"px-5 pt-6":"px-10 pt-0"," pb-10 flex flex-col justify-start items-start gap-10"),children:[(0,le.jsxs)("div",{className:"self-stretch flex flex-col justify-start items-start gap-3",children:[!l&&(0,le.jsx)("div",{className:"self-stretch flex flex-col justify-center items-start gap-2",children:(0,le.jsx)("div",{className:"justify-start text-black text-base font-semibold leading-normal",children:"Plan & Billing"})}),(0,le.jsxs)("div",{className:"self-stretch flex flex-col justify-start items-start gap-2",children:[(0,le.jsx)("div",{className:"self-stretch px-4 py-3 bg-white rounded-xl outline outline-1 outline-offset-[-1px] outline-gray-200 flex flex-col justify-start items-start gap-2.5",children:(0,le.jsxs)("div",{className:"self-stretch inline-flex justify-between items-center",children:[(0,le.jsxs)("div",{className:"".concat(l?"text-sm flex-1 pr-2":"text-base"," justify-start text-text-default font-normal leading-normal"),children:["You're currently using the ",g," plan"]}),(0,le.jsxs)("div",{className:"flex justify-start items-center gap-2 flex-shrink-0",children:[!l&&(0,le.jsx)("div",{className:"inline-flex flex-col justify-start items-start",children:(0,le.jsx)("div",{className:"px-4 py-1.5 bg-bg-secondary rounded-md outline outline-1 outline-offset-[-1px] outline-zinc-200 flex flex-col justify-center items-center gap-2.5 cursor-pointer",onClick:f,children:(0,le.jsx)("div",{className:"inline-flex justify-center items-center gap-2.5",children:(0,le.jsx)("div",{className:"justify-start text-text-default text-sm font-medium leading-tight",children:"Manage Plan"})})})}),(0,le.jsx)("div",{className:"inline-flex flex-col justify-start items-start",children:(0,le.jsx)("div",{className:"".concat(l?"px-3 py-1.5":"px-4 py-1.5"," bg-bg-secondary rounded-md outline outline-1 outline-offset-[-1px] outline-orange-500 flex flex-col justify-center items-center gap-2.5 cursor-pointer"),onClick:()=>{"past_due"===a.stripe_subscription_status?f():(n("/billing"),s())},children:(0,le.jsx)("div",{className:"inline-flex justify-center items-center gap-2.5",children:(0,le.jsx)("div",{className:"justify-start text-orange-500 ".concat(l?"text-xs":"text-sm"," font-medium leading-tight"),children:"past_due"===a.stripe_subscription_status?"Update Payment":"Upgrade Plan"})})})})]})]})}),(0,le.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,le.jsx)("div",{className:"justify-start text-gray-600 ".concat(l?"text-xs":"text-sm"," font-normal leading-tight"),children:a.subscription_period_end?j?"Your subscription will end on ".concat(b(a.subscription_period_end)):"Your subscription renews on ".concat(b(a.subscription_period_end)):"No active subscription"}),j&&(0,le.jsxs)("div",{className:"justify-start text-gray-500 ".concat("text-xs"," font-normal leading-tight"),children:["Want to keep your subscription? Click ",(0,le.jsx)("span",{className:"underline text-blue-500 cursor-pointer",onClick:f,children:"Manage Plan"})," and Cancel the change."]})]})]})]}),"past_due"===a.stripe_subscription_status&&(0,le.jsx)("div",{className:"self-stretch mt-0 p-4 bg-orange-50 border border-orange-200 rounded-lg",children:(0,le.jsxs)("div",{className:"flex items-start gap-3",children:[(0,le.jsx)("div",{className:"flex-shrink-0 w-5 h-5 bg-orange-500 rounded-full flex items-center justify-center mt-0.5",children:(0,le.jsx)("svg",{className:"w-3 h-3 text-white",fill:"currentColor",viewBox:"0 0 20 20",children:(0,le.jsx)("path",{fillRule:"evenodd",d:"M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z",clipRule:"evenodd"})})}),(0,le.jsxs)("div",{className:"flex-1",children:[(0,le.jsx)("h3",{className:"text-orange-800 font-medium text-sm mb-1",children:"Payment overdue"}),(0,le.jsx)("p",{className:"text-orange-700 text-sm",children:"Your subscription payment is past due. Please update your payment method to restore full access to your plan features."})]})]})}),(0,le.jsxs)("div",{className:"self-stretch flex flex-col justify-start items-start gap-6",children:[(0,le.jsx)("div",{className:"self-stretch flex flex-col justify-center items-start gap-2",children:(0,le.jsx)("div",{className:"justify-start text-black text-base font-semibold leading-normal",children:"Billing History"})}),(0,le.jsxs)("div",{className:"self-stretch flex flex-col justify-start items-start gap-4 pb-6 md:pb-8 lg:pb-10",children:[m&&(0,le.jsx)("div",{className:"self-stretch text-center text-gray-500 py-8",children:"Loading billing history..."}),x&&(0,le.jsx)("div",{className:"self-stretch text-center text-red-500 py-8",children:x}),!m&&!x&&0===i.length&&(0,le.jsx)("div",{className:"self-stretch text-center text-gray-500 py-8",children:"No billing history available"}),!m&&!x&&i.map((e,t)=>{return(0,le.jsxs)(Y.Fragment,{children:[(0,le.jsxs)("div",{className:"w-full inline-flex justify-start items-center",children:[(0,le.jsx)("div",{className:"w-40 pr-3 flex justify-start items-center gap-2.5",children:(0,le.jsx)("div",{className:"justify-start text-gray-800 text-sm font-normal leading-tight",children:(s=e.date,new Date(1e3*s).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"}))})}),(0,le.jsx)("div",{className:"w-28 px-3 flex justify-start items-center gap-2.5",children:(0,le.jsx)("div",{className:"justify-start text-gray-800 text-sm font-normal leading-tight",children:v(e.amount,e.currency)})}),(0,le.jsx)("div",{className:"w-28 px-3 flex justify-start items-center gap-2.5",children:(0,le.jsx)("div",{className:"px-2 py-0.5 rounded-[100px] outline outline-1 outline-offset-[-1px] ".concat(y(e.status).background," flex justify-center items-center gap-2.5"),children:(0,le.jsx)("div",{className:"justify-start text-xs font-medium leading-none ".concat(y(e.status).text),children:e.status.charAt(0).toUpperCase()+e.status.slice(1)})})}),!l&&(0,le.jsx)("div",{className:"flex-1 px-3 flex justify-start items-center gap-2.5",children:(0,le.jsx)("div",{className:"justify-start text-gray-800 text-sm font-normal leading-tight",children:e.description||"".concat(g," Plan")})}),(0,le.jsx)("div",{className:"w-6 h-6 rounded-md flex justify-center items-center gap-2.5",children:e.invoice_pdf||e.hosted_invoice_url?(0,le.jsx)("div",{className:"relative cursor-pointer hover:text-blue-600",onClick:()=>{return t=e.invoice_pdf||e.hosted_invoice_url,void window.open(t,"_blank");var t},title:"Download Invoice",children:(0,le.jsxs)("svg",{width:"17",height:"16",viewBox:"0 0 17 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[(0,le.jsx)("path",{d:"M8.5 10V2",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round"}),(0,le.jsx)("path",{d:"M14.5 10V12.6667C14.5 13.0203 14.3595 13.3594 14.1095 13.6095C13.8594 13.8595 13.5203 14 13.1667 14H3.83333C3.47971 14 3.14057 13.8595 2.89052 13.6095C2.64048 13.3594 2.5 13.0203 2.5 12.6667V10",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round"}),(0,le.jsx)("path",{d:"M5.1665 6.6665L8.49984 9.99984L11.8332 6.6665",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round"})]})}):(0,le.jsx)("div",{className:"relative text-gray-400",title:"Invoice not available for download",children:(0,le.jsxs)("svg",{width:"17",height:"16",viewBox:"0 0 17 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",opacity:"0.5",children:[(0,le.jsx)("path",{d:"M8.5 10V2",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round"}),(0,le.jsx)("path",{d:"M14.5 10V12.6667C14.5 13.0203 14.3595 13.3594 14.1095 13.6095C13.8594 13.8595 13.5203 14 13.1667 14H3.83333C3.47971 14 3.14057 13.8595 2.89052 13.6095C2.64048 13.3594 2.5 13.0203 2.5 12.6667V10",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round"}),(0,le.jsx)("path",{d:"M5.1665 6.6665L8.49984 9.99984L11.8332 6.6665",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round"})]})})})]}),t{(async()=>{if(null!=e&&e.id)try{r(!0);let t=(await xe.getWorkspaceInvoices(e.id)).invoices||[];n(t)}catch(t){o("Failed to load workspace billing history")}finally{r(!1)}})()},[null==e?void 0:e.id]);const c=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"USD";return new Intl.NumberFormat("en-US",{style:"currency",currency:t}).format(e)},d=e=>{switch(e.toLowerCase()){case"paid":return{background:"outline-emerald-700",text:"text-emerald-700"};case"pending":case"open":return{background:"outline-orange-500",text:"text-orange-500"};case"failed":case"past_due":return{background:"outline-red-500",text:"text-red-500"};default:return{background:"outline-gray-500",text:"text-gray-500"}}};return(0,le.jsx)("div",{className:"self-stretch bg-white flex flex-col justify-start items-start h-full overflow-y-auto",style:{scrollbarGutter:"stable"},children:(0,le.jsxs)("div",{className:"w-full ".concat(t?"px-5 pt-6":"px-10 pt-0"," pb-10 flex flex-col justify-start items-start gap-10"),children:[(0,le.jsxs)("div",{className:"self-stretch flex flex-col justify-start items-start gap-3",children:[!t&&(0,le.jsx)("div",{className:"self-stretch flex flex-col justify-center items-start gap-2",children:(0,le.jsx)("div",{className:"justify-start text-black text-base font-semibold leading-normal",children:"Plan & Billing"})}),(0,le.jsxs)("div",{className:"self-stretch flex flex-col justify-start items-start gap-2",children:[(0,le.jsx)("div",{className:"self-stretch px-4 py-3 bg-white rounded-xl outline outline-1 outline-offset-[-1px] outline-gray-200 flex flex-col justify-start items-start gap-2.5",children:(0,le.jsxs)("div",{className:"self-stretch inline-flex justify-between items-center",children:[(0,le.jsxs)("div",{className:"".concat(t?"text-sm flex-1 pr-2":"text-base"," justify-start text-text-default font-normal leading-normal"),children:["Managing billing for ",(0,le.jsx)("strong",{children:(null==e?void 0:e.name)||"workspace"})]}),(0,le.jsxs)("div",{className:"flex justify-start items-center gap-2 flex-shrink-0",children:[!t&&"owner"===(null==e?void 0:e.user_role)&&(0,le.jsx)("div",{className:"inline-flex flex-col justify-start items-start",children:(0,le.jsx)("div",{className:"px-4 py-1.5 bg-bg-secondary rounded-md outline outline-1 outline-offset-[-1px] outline-zinc-200 flex flex-col justify-center items-center gap-2.5 cursor-pointer",onClick:async()=>{if(null!=e&&e.id)try{const t=await xe.createWorkspacePortalSession(e.id);t.url&&window.open(t.url,"_blank")}catch(i){s({variant:"destructive",title:"Error",description:"Failed to open billing portal. Please try again later."})}},children:(0,le.jsx)("div",{className:"inline-flex justify-center items-center gap-2.5",children:(0,le.jsx)("div",{className:"justify-start text-text-default text-sm font-medium leading-tight",children:"Manage"})})})}),(0,le.jsx)("div",{className:"inline-flex flex-col justify-start items-start",children:(0,le.jsx)("div",{className:"".concat(t?"px-3 py-1.5":"px-4 py-1.5"," bg-bg-secondary rounded-md outline outline-1 outline-offset-[-1px] outline-orange-500 flex flex-col justify-center items-center gap-2.5 cursor-pointer"),onClick:()=>{null!=e&&e.id&&window.open("/workspace/".concat(e.id),"_blank")},children:(0,le.jsx)("div",{className:"inline-flex justify-center items-center gap-2.5",children:(0,le.jsx)("div",{className:"justify-start text-orange-500 ".concat(t?"text-xs":"text-sm"," font-medium leading-tight"),children:"Add Seats"})})})})]})]})}),(0,le.jsx)("div",{className:"justify-start text-gray-600 ".concat(t?"text-xs":"text-sm"," font-normal leading-tight"),children:null!=e&&e.subscription_period_end?"Workspace subscription renews on ".concat((m=e.subscription_period_end,m?new Date(m).toLocaleDateString("en-US",{year:"numeric",month:"long",day:"numeric"}):"N/A")):"No active workspace subscription"})]})]}),(0,le.jsxs)("div",{className:"self-stretch flex flex-col justify-start items-start gap-6",children:[(0,le.jsx)("div",{className:"self-stretch flex flex-col justify-center items-start gap-2",children:(0,le.jsx)("div",{className:"justify-start text-black text-base font-semibold leading-normal",children:"Billing History"})}),(0,le.jsxs)("div",{className:"self-stretch flex flex-col justify-start items-start gap-4 pb-6 md:pb-8 lg:pb-10",children:[l&&(0,le.jsx)("div",{className:"self-stretch text-center text-gray-500 py-8",children:"Loading billing history..."}),i&&(0,le.jsx)("div",{className:"self-stretch text-center text-red-500 py-8",children:i}),!l&&!i&&0===a.length&&(0,le.jsx)("div",{className:"self-stretch text-center text-gray-500 py-8",children:"No billing history available"}),!l&&!i&&a.map((e,s)=>{return(0,le.jsxs)(Y.Fragment,{children:[(0,le.jsxs)("div",{className:"w-full inline-flex justify-start items-center",children:[(0,le.jsx)("div",{className:"w-40 pr-3 flex justify-start items-center gap-2.5",children:(0,le.jsx)("div",{className:"justify-start text-gray-800 text-sm font-normal leading-tight",children:(n=e.date,new Date(1e3*n).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"}))})}),(0,le.jsx)("div",{className:"w-28 px-3 flex justify-start items-center gap-2.5",children:(0,le.jsx)("div",{className:"justify-start text-gray-800 text-sm font-normal leading-tight",children:c(e.amount,e.currency)})}),(0,le.jsx)("div",{className:"w-28 px-3 flex justify-start items-center gap-2.5",children:(0,le.jsx)("div",{className:"px-2 py-0.5 rounded-[100px] outline outline-1 outline-offset-[-1px] ".concat(d(e.status).background," flex justify-center items-center gap-2.5"),children:(0,le.jsx)("div",{className:"justify-start text-xs font-medium leading-none ".concat(d(e.status).text),children:e.status.charAt(0).toUpperCase()+e.status.slice(1)})})}),!t&&(0,le.jsx)("div",{className:"flex-1 px-3 flex justify-start items-center gap-2.5",children:(0,le.jsx)("div",{className:"justify-start text-gray-800 text-sm font-normal leading-tight",children:e.description||"Workspace Seats"})}),(0,le.jsx)("div",{className:"w-6 h-6 rounded-md flex justify-center items-center gap-2.5",children:e.invoice_pdf||e.hosted_invoice_url?(0,le.jsx)("div",{className:"relative cursor-pointer hover:text-blue-600",onClick:()=>{return t=e.invoice_pdf||e.hosted_invoice_url,void window.open(t,"_blank");var t},title:"Download Invoice",children:(0,le.jsxs)("svg",{width:"17",height:"16",viewBox:"0 0 17 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[(0,le.jsx)("path",{d:"M8.5 10V2",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round"}),(0,le.jsx)("path",{d:"M14.5 10V12.6667C14.5 13.0203 14.3595 13.3594 14.1095 13.6095C13.8594 13.8595 13.5203 14 13.1667 14H3.83333C3.47971 14 3.14057 13.8595 2.89052 13.6095C2.64048 13.3594 2.5 13.0203 2.5 12.6667V10",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round"}),(0,le.jsx)("path",{d:"M5.1665 6.6665L8.49984 9.99984L11.8332 6.6665",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round"})]})}):(0,le.jsx)("div",{className:"relative text-gray-400",title:"Invoice not available for download",children:(0,le.jsxs)("svg",{width:"17",height:"16",viewBox:"0 0 17 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",opacity:"0.5",children:[(0,le.jsx)("path",{d:"M8.5 10V2",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round"}),(0,le.jsx)("path",{d:"M14.5 10V12.6667C14.5 13.0203 14.3595 13.3594 14.1095 13.6095C13.8594 13.8595 13.5203 14 13.1667 14H3.83333C3.47971 14 3.14057 13.8595 2.89052 13.6095C2.64048 13.3594 2.5 13.0203 2.5 12.6667V10",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round"}),(0,le.jsx)("path",{d:"M5.1665 6.6665L8.49984 9.99984L11.8332 6.6665",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round"})]})})})]}),s{(async()=>{if(null!=e&&e.id)try{l(!0);const t=await xe.getMySeatInfo(e.id);a(t)}catch(t){i("Failed to load seat information")}finally{l(!1)}})()},[null==e?void 0:e.id]);const o=e=>{if(null==e||!e.user_seat)return"Viewer access";const{user_seat:t}=e;return"assigned"===t.status&&t.seat_type?"".concat(t.seat_type," seat assigned"):"Viewer access"},c=e=>"assigned"===e?{background:"outline-emerald-700",text:"text-emerald-700"}:{background:"outline-gray-500",text:"text-gray-500"};return(0,le.jsxs)("div",{className:"self-stretch ".concat(t?"px-5 pt-6":"px-10"," bg-white flex flex-col justify-start items-start gap-10"),children:[!t&&(0,le.jsx)("div",{className:"self-stretch flex flex-col justify-start items-start gap-3",children:(0,le.jsx)("div",{className:"self-stretch flex flex-col justify-center items-start gap-2",children:(0,le.jsx)("div",{className:"justify-start text-black text-base font-semibold leading-normal",children:"Plan & Billing"})})}),n?(0,le.jsxs)("div",{className:"self-stretch flex flex-col justify-center items-center py-16",children:[(0,le.jsx)("div",{className:"animate-spin rounded-full h-8 w-8 border-t-2 border-b-2 border-slate-700"}),(0,le.jsx)("div",{className:"mt-4 text-gray-600",children:"Loading seat information..."})]}):r?(0,le.jsx)("div",{className:"self-stretch flex flex-col justify-center items-center py-16",children:(0,le.jsx)("div",{className:"text-red-500 text-center",children:r})}):(0,le.jsxs)(le.Fragment,{children:[(0,le.jsxs)("div",{className:"self-stretch flex flex-col justify-start items-start gap-4",children:[(0,le.jsx)("div",{className:"self-stretch px-4 py-3 bg-white rounded-xl outline outline-1 outline-offset-[-1px] outline-gray-200 flex flex-col justify-start items-start gap-2.5",children:(0,le.jsxs)("div",{className:"self-stretch inline-flex justify-between items-center",children:[(0,le.jsx)("div",{className:"justify-start text-text-default text-base font-normal leading-normal",children:(0,le.jsx)("strong",{children:(null==e?void 0:e.name)||"Workspace"})}),(0,le.jsx)("div",{className:"text-sm text-gray-600",children:(null==s?void 0:s.user_role)&&(0,le.jsxs)("span",{className:"capitalize",children:[s.user_role," access"]})})]})}),(0,le.jsx)("div",{className:"self-stretch px-4 py-3 bg-white rounded-xl outline outline-1 outline-offset-[-1px] outline-gray-200 flex flex-col justify-start items-start gap-2.5",children:(0,le.jsxs)("div",{className:"self-stretch inline-flex justify-between items-center",children:[(0,le.jsx)("div",{className:"justify-start text-text-default text-base font-normal leading-normal",children:o(s)}),(0,le.jsx)("div",{className:"px-2 py-0.5 rounded-[100px] outline outline-1 outline-offset-[-1px] ".concat(c(null==s||null===(d=s.user_seat)||void 0===d?void 0:d.status).background," flex justify-center items-center gap-2.5"),children:(0,le.jsx)("div",{className:"justify-start text-xs font-medium leading-none ".concat(c(null==s||null===(m=s.user_seat)||void 0===m?void 0:m.status).text),children:"assigned"===(null==s||null===(u=s.user_seat)||void 0===u?void 0:u.status)?"Active":"Viewer"})})]})}),"assigned"===(null==s||null===(x=s.user_seat)||void 0===x?void 0:x.status)&&(0,le.jsx)("div",{className:"self-stretch px-4 py-3 bg-white rounded-xl outline outline-1 outline-offset-[-1px] outline-gray-200 flex flex-col justify-start items-start gap-2.5",children:(0,le.jsxs)("div",{className:"self-stretch flex flex-col gap-2",children:[(0,le.jsx)("div",{className:"text-sm font-medium text-gray-700",children:"Seat Details"}),s.user_seat.seat_id&&(0,le.jsxs)("div",{className:"text-sm text-gray-600",children:["Seat ID: ",s.user_seat.seat_id]}),(0,le.jsxs)("div",{className:"text-sm text-gray-600",children:["Plan: ",s.user_seat.seat_type]})]})}),(null==e?void 0:e.subscription_period_end)&&(0,le.jsxs)("div",{className:"justify-start text-gray-600 text-sm font-normal leading-tight",children:["Workspace subscription renews on ",(p=e.subscription_period_end,p?new Date(p).toLocaleDateString("en-US",{year:"numeric",month:"long",day:"numeric"}):"N/A")]})]}),(null==s?void 0:s.workspace_admins)&&s.workspace_admins.length>0&&(0,le.jsxs)("div",{className:"self-stretch flex flex-col justify-start items-start gap-6",children:[(0,le.jsx)("div",{className:"self-stretch flex flex-col justify-center items-start gap-2",children:(0,le.jsx)("div",{className:"justify-start text-black text-base font-semibold leading-normal",children:"Workspace Administrators"})}),(0,le.jsxs)("div",{className:"self-stretch flex flex-col justify-start items-start gap-4",children:[(0,le.jsx)("div",{className:"justify-start text-gray-600 text-sm font-normal leading-tight",children:"Contact your workspace administrators for seat assignments:"}),(0,le.jsx)("div",{className:"self-stretch flex flex-col justify-start items-start gap-2",children:s.workspace_admins.map((e,t)=>(0,le.jsxs)("div",{className:"self-stretch px-4 py-2 bg-gray-50 rounded-lg flex justify-between items-center",children:[(0,le.jsx)("div",{className:"text-sm text-gray-800",children:e.email}),(0,le.jsx)("div",{className:"text-xs text-gray-600 capitalize",children:e.role})]},e.email))})]})]}),"assigned"!==(null==s||null===(h=s.user_seat)||void 0===h?void 0:h.status)&&(0,le.jsxs)("div",{className:"self-stretch flex flex-col justify-start items-start gap-6",children:[(0,le.jsx)("div",{className:"self-stretch flex flex-col justify-center items-start gap-2",children:(0,le.jsx)("div",{className:"justify-start text-black text-base font-semibold leading-normal",children:"Need a Seat?"})}),(0,le.jsx)("div",{className:"self-stretch px-4 py-3 bg-blue-50 rounded-xl outline outline-1 outline-offset-[-1px] outline-blue-200 flex flex-col justify-start items-start gap-2.5",children:(0,le.jsx)("div",{className:"text-sm text-blue-800",children:"You don't currently have a seat assigned in this workspace. Contact your workspace administrators to request a seat assignment."})})]})]})]});var d,m,u,x,h,p}function wx(e){let{handleModalClose:t}=e;const{user:s}=oe(),{activeWorkspace:a}=ge();if(a&&!a.is_personal){return a.user_role&&["admin","owner"].includes(a.user_role)?(0,le.jsx)(yx,{}):(0,le.jsx)(Nx,{})}return s.stripe_customer_id||s.stripe_subscription_status?(0,le.jsx)(jx,{handleModalClose:t}):(0,le.jsx)(bx,{})}const _x="workspace",kx="account",Cx="plan-billing",Ax=[{key:_x,label:"Workspace"},{key:Cx,label:"Plan & Billing"},{key:kx,label:"Account"}];function Sx(e){let{isOpen:t,onClose:s}=e;const[a,n]=(0,Y.useState)(_x),[l,r]=(0,Y.useState)("sidebar"),[i,o]=(0,Y.useState)(0),[c,d]=(0,Y.useState)(!1),[m,u]=(0,Y.useState)(0),[x,h]=(0,Y.useState)(!1),p=(0,Y.useRef)(0),g=(0,Y.useRef)(0),f=(0,Y.useRef)(null),v=Hu();(0,Y.useEffect)(()=>{if(v){const e=()=>{const e=.01*window.innerHeight;document.documentElement.style.setProperty("--vh","".concat(e,"px"))};return e(),window.addEventListener("resize",e),window.addEventListener("orientationchange",e),()=>{window.removeEventListener("resize",e),window.removeEventListener("orientationchange",e)}}},[v]),(0,Y.useEffect)(()=>{if(v&&t){const e=window.getComputedStyle(document.body).overflow;return document.body.style.overflow="hidden",document.body.style.position="fixed",document.body.style.width="100%",document.body.style.height="100%",()=>{document.body.style.overflow=e,document.body.style.position="",document.body.style.width="",document.body.style.height=""}}},[v,t]);const b=e=>{n(e),v&&r("content")},j=()=>{r("sidebar")},y=()=>{v&&(r("sidebar"),o(0),d(!1),u(0),h(!1),f.current=null),s()},N=(0,Y.useCallback)(e=>{v&&(e.stopPropagation(),p.current=e.touches[0].clientY,d(!0))},[v]),w=(0,Y.useCallback)(e=>{if(!v||!c)return;e.preventDefault(),e.stopPropagation();const t=e.touches[0].clientY-p.current;t>0&&o(t)},[v,c]),_=(0,Y.useCallback)(e=>{v&&c&&(e.stopPropagation(),d(!1),i>150?y():o(0))},[v,c,i,y]),k=(0,Y.useCallback)(e=>{v&&"content"===l&&(e.stopPropagation(),g.current=e.touches[0].clientX,p.current=e.touches[0].clientY,f.current=null)},[v,l]),C=(0,Y.useCallback)(e=>{if(!v||"content"!==l)return;const t=e.touches[0].clientX,s=e.touches[0].clientY,a=t-g.current,n=s-p.current;null===f.current&&(Math.abs(a)>10||Math.abs(n)>10)&&(f.current=Math.abs(a)>Math.abs(n)?"horizontal":"vertical"),"horizontal"===f.current&&(e.preventDefault(),e.stopPropagation(),x||h(!0),a>0&&u(a))},[v,l,x]),A=(0,Y.useCallback)(e=>{v&&"content"===l&&(e.stopPropagation(),x&&(h(!1),m>100&&j(),u(0)),f.current=null)},[v,l,x,m,j]),S=()=>{switch(a){case _x:return(0,le.jsx)(ax,{});case kx:return(0,le.jsx)(vx,{});case Cx:return(0,le.jsx)(wx,{handleModalClose:y});default:return(0,le.jsx)(ax,{})}};var E;return v?(0,le.jsxs)(Pa,{open:t,onOpenChange:y,children:[(0,le.jsx)("div",{className:"fixed inset-0 z-50 bg-black/80 transition-opacity duration-300",style:{opacity:t?.8:0,pointerEvents:t?"auto":"none",touchAction:"none"},onTouchStart:e=>e.preventDefault(),onTouchMove:e=>e.preventDefault(),onTouchEnd:e=>e.preventDefault()}),(0,le.jsx)("div",{className:"fixed inset-x-0 bottom-0 z-50 w-full transform-gpu",style:{height:"calc(var(--vh, 1vh) * 90)",maxHeight:"calc(var(--vh, 1vh) * 90)",transform:"translateY(".concat(t?"".concat(i,"px"):"100%",")"),transition:c?"none":"transform 0.3s ease-out",touchAction:"none"},onTouchStart:N,onTouchMove:w,onTouchEnd:_,children:(0,le.jsxs)("div",{className:"w-full h-full bg-white rounded-t-xl flex flex-col overflow-hidden relative",children:[(0,le.jsx)("div",{className:"w-full flex justify-center pt-2 pb-1",children:(0,le.jsx)("div",{className:"w-10 h-1 bg-gray-300 rounded-full"})}),(0,le.jsx)("div",{className:"flex-shrink-0 px-3 py-3 bg-white border-b border-gray-200 flex items-center justify-center relative",children:"sidebar"===l?(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)("div",{className:"text-black text-lg font-bold",children:"Settings"}),(0,le.jsx)("button",{onClick:y,className:"absolute right-3 w-8 h-8 flex items-center justify-center hover:bg-gray-100 rounded-full",children:(0,le.jsx)(Bt.A,{size:18})})]}):(0,le.jsxs)(le.Fragment,{children:[(0,le.jsxs)("div",{className:"absolute left-3 flex items-center",children:[(0,le.jsx)("button",{onClick:j,className:"w-8 h-8 flex items-center justify-center hover:bg-gray-100 rounded-full",children:(0,le.jsx)(Xs.A,{size:18})}),(0,le.jsx)("button",{onClick:j,className:"text-gray-600 text-sm font-medium hover:text-gray-800 transition-colors -ml-1.5",children:"Settings"})]}),(0,le.jsx)("div",{className:"text-black text-lg font-bold",children:null===(E=Ax.find(e=>e.key===a))||void 0===E?void 0:E.label}),(0,le.jsx)("button",{onClick:y,className:"absolute right-3 w-8 h-8 flex items-center justify-center hover:bg-gray-100 rounded-full",children:(0,le.jsx)(Bt.A,{size:18})})]})}),(0,le.jsxs)("div",{className:"flex-1 overflow-hidden relative",children:[x&&m>0&&(0,le.jsx)("div",{className:"absolute inset-0 bg-black/10 z-10 pointer-events-none",style:{opacity:Math.min(m/100,.3)}}),(0,le.jsxs)("div",{className:"flex w-[200%] h-full transition-transform duration-300 ease-in-out",style:{transform:"sidebar"===l?"translateX(0%)":"translateX(calc(-50% + ".concat(m,"px))"),transition:x?"none":"transform 0.3s ease-in-out"},children:[(0,le.jsx)("div",{className:"w-1/2 h-full overflow-y-auto",children:(0,le.jsx)("div",{className:"flex flex-col space-y-2 px-2 py-4",children:Ax.map(e=>(0,le.jsxs)("button",{onClick:()=>b(e.key),className:"px-4 py-4 rounded-xl flex items-center justify-between text-left transition-all active:scale-95 text-gray-700 font-medium hover:bg-gray-100 active:bg-gray-200",children:[(0,le.jsx)("div",{className:"text-base",children:e.label}),(0,le.jsx)(rn.A,{size:20,className:"text-gray-400"})]},e.key))})}),(0,le.jsxs)("div",{className:"w-1/2 h-full relative",onTouchStart:k,onTouchMove:C,onTouchEnd:A,children:["content"===l&&!x&&(0,le.jsx)("div",{className:"absolute left-0 top-1/2 transform -translate-y-1/2 w-1 h-12 bg-gray-300 rounded-r-full opacity-30 z-20"}),S()]})]})]})]})})]}):(0,le.jsx)(Pa,{open:t,onOpenChange:y,children:(0,le.jsx)(Da,{className:"max-w-6xl w-[90vw] max-w-[1000px] h-[90vh] p-0 [&>button]:hidden",children:(0,le.jsxs)("div",{className:"w-full h-full bg-white rounded-xl flex overflow-hidden",children:[(0,le.jsxs)("div",{className:"w-52 flex-shrink-0 bg-gray-50 border-r border-gray-200 flex flex-col",children:[(0,le.jsx)("div",{className:"px-4 py-6 flex items-center",children:(0,le.jsx)("div",{className:"text-black text-lg font-bold",children:"Settings"})}),(0,le.jsx)("div",{className:"flex flex-col space-y-1 px-3",children:Ax.map(e=>(0,le.jsx)("button",{onClick:()=>b(e.key),className:"p-3 rounded-md flex items-center text-left transition-colors ".concat(a===e.key?"bg-gray-100 text-black font-semibold":"text-gray-600 font-medium hover:bg-gray-100"),children:(0,le.jsx)("div",{className:"text-sm",children:e.label})},e.key))})]}),(0,le.jsxs)("div",{className:"flex-1 flex flex-col min-w-0",children:[(0,le.jsx)("div",{className:"flex-shrink-0 p-3 bg-white flex justify-end items-center",children:(0,le.jsx)("button",{onClick:y,className:"w-6 h-6 flex items-center justify-center hover:bg-gray-100 rounded",children:(0,le.jsx)(Bt.A,{size:16})})}),(0,le.jsx)("div",{className:"flex-1 min-h-0",children:S()})]})]})})})}const Ex=e=>{let{app:t,currentUsage:s,onShareModalOpen:a,onLogout:n,user:l}=e;const[r,i]=(0,Y.useState)(!1),o="Upgrade Plan",c=e=>{var s,a;tt("User clicked upgrade",{app_id:(null==t?void 0:t.id)||null,user_id:(null==l?void 0:l.id)||null,conversation_id:(null==t||null===(s=t.conversation)||void 0===s?void 0:s.id)||null,cta:e,origin:"editor account menu",target_route:"/billing"}),ht({user_id:(null==l?void 0:l.id)||null,app_id:(null==t?void 0:t.id)||null,conversation_id:(null==t||null===(a=t.conversation)||void 0===a?void 0:a.id)||null},{cta:e,origin:"editor account menu",target_route:"/billing"})};return(0,le.jsxs)(le.Fragment,{children:[(0,le.jsxs)(Bu,{children:[(0,le.jsx)(zu,{asChild:!0,children:(0,le.jsxs)("div",{className:"flex items-center gap-3 cursor-pointer flex-1 p-1 rounded-md hover:bg-gray-200 transition-colors",children:[(0,le.jsx)(il,{className:"h-6 w-6 rounded-xl",children:(0,le.jsx)(ol,{src:be,alt:"Base44"})}),(0,le.jsx)("div",{className:"flex-1 min-w-0",children:(0,le.jsx)(Is.A,{className:"h-4 w-4 text-muted-foreground"})})]})}),(0,le.jsxs)(Uu,{align:"start",className:"w-[240px] p-2 shadow-lg border border-slate-200 rounded-lg",children:[(0,le.jsx)(Wu,{asChild:!0,children:(0,le.jsxs)(J.Link,{to:"/",className:"flex items-center gap-2 cursor-pointer",children:[(0,le.jsx)(Xs.A,{className:"h-4 w-4"}),(0,le.jsx)("span",{children:"Back to Workspace"})]})}),(0,le.jsx)(Vu,{}),(0,le.jsx)(qu,{asChild:!0,children:(0,le.jsx)("div",{className:"px-2 py-1.5 text-gray-500",children:null==l?void 0:l.email})}),s&&(0,le.jsxs)("div",{className:"border border-slate-200 rounded-[10px] p-2 my-2",children:[(0,le.jsx)(qu,{children:(0,le.jsxs)("div",{className:"flex justify-between",children:[(0,le.jsx)("span",{children:"Credits"}),(0,le.jsx)("span",{className:"text-xs bg-slate-100 px-2 py-0.5 rounded",children:s.tier.charAt(0).toUpperCase()+s.tier.slice(1).toLowerCase()})]})}),(0,le.jsxs)("div",{className:"px-2 py-1.5",children:[(0,le.jsxs)("div",{className:"flex justify-between text-xs mb-1",children:[(0,le.jsx)("span",{children:"Monthly Credits"}),(0,le.jsxs)("span",{children:[(d=s.monthly_usage,d%1==0?d:d.toFixed(1)),"/",s.monthly_limit,s.extra_credits>0&&" (+".concat(s.extra_credits,")")]})]}),(0,le.jsx)("div",{className:"w-full bg-gray-200 rounded-full h-1.5",children:(0,le.jsx)("div",{className:"h-1.5 rounded-full ".concat(s.is_over_limit?"bg-red-500":"bg-primary"),style:{width:"".concat(Math.min(s.monthly_usage/s.monthly_limit*100,100),"%")}})})]}),s.daily_limit&&(0,le.jsx)("div",{className:"px-2 py-1.5",children:(0,le.jsxs)("div",{className:"flex justify-between text-xs",children:[(0,le.jsx)("span",{children:"Daily Credits"}),(0,le.jsxs)("span",{children:[s.daily_usage,"/",s.daily_limit]})]})}),(0,le.jsxs)("div",{className:"px-2 pb-1 text-xs text-muted-foreground",children:["Credits renew on: ",s.next_period_start_date]})]}),s&&a&&(0,le.jsxs)("div",{className:"border border-blue-200 rounded-[10px] h-10 flex items-center px-3 my-2 cursor-pointer bg-blue-50 hover:bg-blue-100",onClick:a,children:[(0,le.jsx)(Au.A,{className:"h-4 w-4 mr-2 text-blue-600"}),(0,le.jsx)("span",{className:"text-sm flex-1 text-blue-600",children:"Win Free Credits"}),(0,le.jsx)(rn.A,{className:"h-4 w-4 text-blue-600"})]}),(0,le.jsx)(Vu,{}),(0,le.jsx)(Wu,{asChild:!0,children:(0,le.jsxs)(J.Link,{to:"https://docs.base44.com",className:"flex items-center gap-2 cursor-pointer",target:"_blank",children:[(0,le.jsx)(Su.A,{className:"h-4 w-4"}),(0,le.jsx)("span",{children:"Documentation"})]})}),(0,le.jsxs)(Wu,{onClick:()=>i(!0),className:"flex items-center gap-2 cursor-pointer",children:[(0,le.jsx)(vm.A,{className:"h-4 w-4"}),(0,le.jsx)("span",{children:"Settings"})]}),(0,le.jsx)(Wu,{asChild:!0,children:(0,le.jsxs)(J.Link,{target:"_blank",onClick:()=>c("Billing"),to:"/billing",className:"flex items-center gap-2 cursor-pointer",children:[(0,le.jsx)(we.A,{className:"h-4 w-4"}),(0,le.jsx)("span",{children:"Billing"})]})}),(0,le.jsx)(Wu,{asChild:!0,children:(0,le.jsxs)(J.Link,{target:"_blank",to:"/support?appId=".concat(null==t?void 0:t.id),className:"flex items-center gap-2 cursor-pointer",onClick:()=>{var e;ot.track("help_center_clicked",{user_id:null==l?void 0:l.id,app_id:null==t?void 0:t.id,conversation_id:null==t||null===(e=t.conversation)||void 0===e?void 0:e.id},{},{useBeacon:!0}).catch()},children:[(0,le.jsx)(uo.A,{className:"h-4 w-4"}),(0,le.jsx)("span",{children:"Help Center"})]})}),(0,le.jsx)(Wu,{asChild:!0,children:(0,le.jsxs)(J.Link,{target:"_blank",to:"/billing",className:"flex items-center gap-2 cursor-pointer",onClick:()=>c(o),children:[(0,le.jsx)(Eu.A,{className:"h-4 w-4 text-orange-600 group-hover:text-orange-700"}),(0,le.jsx)("span",{className:"text-orange-600 group-hover:text-orange-700",children:o})]})}),(0,le.jsx)(Vu,{}),(0,le.jsxs)(Wu,{onClick:n,className:"flex items-center gap-2 cursor-pointer text-gray-800 hover:bg-gray-100",children:[(0,le.jsx)(Iu.A,{className:"h-4 w-4"}),(0,le.jsx)("span",{children:"Sign Out"})]})]})]}),(0,le.jsx)(Sx,{isOpen:r,onClose:()=>i(!1)})]});var d};var Ix=s(24276),Tx=s(43558),Px=s(90770);const Lx=e=>{var t;let{app:s}=e;return(0,le.jsxs)(Bu,{children:[(0,le.jsx)(zu,{asChild:!0,children:(0,le.jsxs)("div",{className:"flex items-center gap-3 cursor-pointer flex-1 p-1 rounded-md hover:bg-gray-200 transition-colors",children:[(0,le.jsxs)(il,{className:"h-6 w-6 rounded-xl",children:[(0,le.jsx)(ol,{src:null==s?void 0:s.logo_url,alt:(null==s?void 0:s.name)||"App"}),(0,le.jsx)(cl,{children:(null==s||null===(t=s.name)||void 0===t?void 0:t[0])||"A"})]}),(0,le.jsx)("div",{className:"flex-1 min-w-0",children:(0,le.jsxs)("div",{className:"flex items-center gap-1",children:[(0,le.jsx)("div",{className:"max-w-[120px]",title:(null==s?void 0:s.name)||"My App",children:(0,le.jsx)("h3",{className:"text-sm font-medium truncate",children:(null==s?void 0:s.name)||"My App"})}),(0,le.jsx)(Is.A,{className:"h-4 w-4 text-muted-foreground"})]})})]})}),(0,le.jsxs)(Uu,{align:"start",className:"w-[240px] p-1 shadow-lg border border-slate-200 rounded-lg",children:[(0,le.jsx)(Wu,{asChild:!0,children:(0,le.jsxs)(J.Link,{to:"/apps/".concat(null==s?void 0:s.id,"/editor/workspace/overview"),className:"flex items-center gap-2 cursor-pointer",children:[(0,le.jsx)(Ix.A,{className:"h-4 w-4"}),(0,le.jsx)("span",{children:"App Overview"})]})}),(0,le.jsx)(Wu,{asChild:!0,children:(0,le.jsxs)(J.Link,{to:"/apps/".concat(null==s?void 0:s.id,"/editor/workspace/users"),className:"flex items-center gap-2 cursor-pointer",children:[(0,le.jsx)(Tx.A,{className:"h-4 w-4"}),(0,le.jsx)("span",{children:"Users"})]})}),(0,le.jsx)(Wu,{asChild:!0,children:(0,le.jsxs)(J.Link,{to:"/apps/".concat(null==s?void 0:s.id,"/editor/workspace/security"),className:"flex items-center gap-2 cursor-pointer",children:[(0,le.jsx)(qc.A,{className:"h-4 w-4"}),(0,le.jsx)("span",{children:"Security"})]})}),(0,le.jsx)(Wu,{asChild:!0,children:(0,le.jsxs)(J.Link,{to:"/apps/".concat(null==s?void 0:s.id,"/editor/workspace/app-settings"),className:"flex items-center gap-2 cursor-pointer",children:[(0,le.jsx)(Px.A,{className:"h-4 w-4"}),(0,le.jsx)("span",{children:"App Settings"})]})})]})]})};const Ox=e=>{let{onToggleVersions:t,showVersions:s}=e;const{app:a,currentUsage:n}=Nt(),{logout:l,user:r}=oe(),i=(0,Z.Zp)(),[o,c]=(0,Y.useState)(!1);return(0,le.jsxs)("div",{className:"py-1.5 px-1 flex items-center bg-slate-50 relative z-10 shadow-[0_10px_23px_rgba(248,250,252,252.15)]",children:[(0,le.jsx)("div",{className:"flex items-center gap-3 flex-1",children:(0,le.jsxs)("div",{className:"flex items-center gap-3",children:[(0,le.jsx)(Ex,{app:a,currentUsage:n,user:r,onShareModalOpen:()=>c(!0),onLogout:()=>{l(),i("/login")}}),(0,le.jsx)("div",{className:"h-5 w-[1px] bg-slate-300 rotate-[25deg]"}),(0,le.jsx)(Lx,{app:a})]})}),(0,le.jsxs)("div",{className:"flex items-center mr-2",children:[(0,le.jsx)(Yt,{variant:s?"secondary":"ghost",size:"sm",className:"transition-colors w-7 h-7 mr-1 p-0 ".concat(s?"text-gray-700 bg-gray-200":"text-gray-500 hover:text-gray-700 hover:bg-gray-100"),onClick:t,title:"Version history",children:(0,le.jsx)(_u.A,{size:16})}),(0,le.jsx)(Cu,{})]}),(0,le.jsx)(Ga,{app:a,isOpen:o,onClose:()=>c(!1)})]})},Rx=e=>{var t,s;const{user:a}=oe(),n=(0,Y.useRef)(null),[l,r]=(0,Y.useState)(!1),[i,o]=(0,Y.useState)(!0),c=(0,Y.useRef)(null),d=(0,Y.useRef)(0);(0,Y.useEffect)(()=>{const e=()=>{o(!document.hidden)},t=()=>{o(!0)},s=()=>{o(!1)};return o(!document.hidden),document.addEventListener("visibilitychange",e),window.addEventListener("focus",t),window.addEventListener("blur",s),()=>{document.removeEventListener("visibilitychange",e),window.removeEventListener("focus",t),window.removeEventListener("blur",s)}},[]),(0,Y.useEffect)(()=>{if(!a||"never"===(null==a?void 0:a.notification_preference))return;if(!n.current){const e=new Audio("/sounds/notification.mp3");let t=!1;e.addEventListener("error",s=>{t||(t=!0),e.src="data:audio/wav;base64,UklGRnoGAABXQVZFZm10IBAAAAABAAEAQB8AAEAfAAABAAgAZGF0YQoGAACBhYqFbF1fdJivrJBhNjVgodDbq2EcBj+a2/LDciUFLIHO8tiJNwgZaLvt559NEAxQp+PwtmMcBjiR1/LMeSwFJHfH8N2QQAoUXrTp66hVFApGn+DyvmwhBSuBzvLZiTYIG2m98OScTgwOUarm7blmGgU7k9n1unEiBC13yO/eizEIHWq+8+OWT"}),n.current=e}const e=()=>{l||(r(!0),(()=>{const e=new Audio("data:audio/wav;base64,UklGRiIAAABXQVZFZm10IBAAAAABAAEAQB8AAEAfAAABAAgAZGF0YQAAAAA=");e.volume=0,e.play().catch(()=>{})})(),document.removeEventListener("click",e),document.removeEventListener("keydown",e))};return document.addEventListener("click",e),document.addEventListener("keydown",e),()=>{document.removeEventListener("click",e),document.removeEventListener("keydown",e)}},[l,a,null==a?void 0:a.notification_preference]),(0,Y.useEffect)(()=>()=>{n.current&&(n.current.pause(),n.current=null)},[]),(0,Y.useEffect)(()=>{var t,s,l,r,o;if(!n.current)return;const m=null===(t=e.status)||void 0===t?void 0:t.state,u=(null===(s=e.conversation)||void 0===s||null===(l=s.messages)||void 0===l?void 0:l.length)||0,x=(null===(r=e.conversation)||void 0===r||null===(o=r.messages)||void 0===o?void 0:o.some(e=>"user"===e.role))||!1;if("processing"===c.current&&"ready"===m&&x){(()=>!i&&("never"!==(null==a?void 0:a.notification_preference)&&("every_prompt"===(null==a?void 0:a.notification_preference)||"on_first_prompt"===(null==a?void 0:a.notification_preference)&&u<=2)))()&&(n.current.volume=.5,n.current.play().catch(()=>{}))}c.current=m||null,d.current=u},[null==e||null===(t=e.status)||void 0===t?void 0:t.state,null==e||null===(s=e.conversation)||void 0===s?void 0:s.messages,null==a?void 0:a.notification_preference,i])},Mx=()=>{const{app:e,setApp:t,refreshSuggestions:s}=Nt(),a=(0,Z.zy)(),n=(0,Z.Zp)(),{user:l}=oe();Rx(e),(0,Y.useEffect)(()=>(null!=e&&e.name?document.title="".concat(e.name," | Base44"):document.title="Base44",()=>{document.title="Base44"}),[null==e?void 0:e.name]),(0,Y.useEffect)(()=>{var r,i;if(null!=e&&e.id&&(null!==(r=a.state)&&void 0!==r&&r.initialPrompt||null!==(i=a.state)&&void 0!==i&&i.initialMessage)){const r=a.state.initialMessage||{content:a.state.initialPrompt};(async function(e,t){return gt({appId:e,body:t,user:{id:arguments.length>2&&void 0!==arguments[2]?arguments[2]:null},onSuccess:e=>{},onError:e=>{}})})(e.id,r,null==l?void 0:l.id).then(e=>{e&&(t(e),s())}),n(a.pathname,{replace:!0,state:{}})}},[a.state,null==e?void 0:e.id,null==l?void 0:l.id,n,a.pathname,t])};var Dx=s(18134);const Fx=Oc.bL,Bx=Oc.R6,zx=Oc.Ke,Ux={overview:Ix.A,data:hr.A,users:Xl.A,analytics:Dx.A,domains:bn.A,security:qc.A,code:ln.A,logs:hr.A,settings:vm.A,payments:we.A,secrets:hr.A,api:ln.A,agents:Cm.A},Wx=e=>{if(e.id&&e.id.startsWith("entity-"))return null;const t=Ux[e.id];return!t&&e.icon?(0,le.jsx)("div",{className:"min-w-[20px]",children:e.icon}):t?(0,le.jsx)(t,{className:"w-5 h-5"}):null},qx=(e,t)=>e.id===t||!!e.subitems&&e.subitems.some(e=>qx(e,t)),Vx=e=>{let{item:t,selected:s,onSelect:a,searchTerm:n,level:l=0}=e;const r=s===t.id,i=t.subitems&&t.subitems.some(e=>s===e.id||!!e.subitems&&qx(e,s));return!n||t.label.toLowerCase().includes(n.toLowerCase())||t.subitems&&t.subitems.some(e=>e.label.toLowerCase().includes(n.toLowerCase())||e.subitems&&e.subitems.some(e=>e.label.toLowerCase().includes(n.toLowerCase())))?t.subitems?(0,le.jsxs)(Fx,{defaultOpen:r||i,className:Pe("group",l>0?"ml-3":""),children:[(0,le.jsx)(Bx,{asChild:!0,children:(0,le.jsxs)(Yt,{variant:"ghost",className:Pe("w-full justify-start px-3 py-2.5 text-sm rounded-lg transition-colors",r||i?"bg-primary/10 text-primary":"text-foreground hover:bg-gray-100"),children:[(0,le.jsx)("div",{className:Pe("w-6 h-6 flex items-center justify-center",r?"text-primary":"text-muted-foreground"),children:Wx(t)}),(0,le.jsx)("span",{className:"ml-3 truncate",children:t.label}),t.badge&&(0,le.jsx)(es,{variant:"secondary",className:"ml-auto mr-2 px-1.5 py-0 text-xs",children:t.badge}),(0,le.jsx)("div",{className:t.badge?"":"ml-auto",children:(0,le.jsx)(Is.A,{className:"h-4 w-4 transition-transform group-data-[state=open]:rotate-180 text-muted-foreground"})})]})}),(0,le.jsxs)(zx,{className:"mt-1 relative",children:[(0,le.jsx)("div",{className:"absolute left-6 top-0 bottom-0 w-px bg-gray-200"}),t.subitems.map((e,t)=>(0,le.jsx)(Vx,{item:e,selected:s,onSelect:a,searchTerm:n,level:l+1},t))]})]}):(0,le.jsxs)(Yt,{variant:"ghost",className:Pe("w-full justify-start px-3 py-2.5 text-sm rounded-lg transition-colors",r?"bg-primary/10 text-primary":"text-foreground hover:bg-gray-100"),onClick:()=>a(t.id),children:[(0,le.jsx)("div",{className:Pe("w-6 h-6 flex items-center justify-center",r?"text-primary":"text-muted-foreground"),children:Wx(t)}),(0,le.jsx)("span",{className:"ml-3 truncate",children:t.label}),t.badge&&(0,le.jsx)(es,{variant:"secondary",className:"ml-auto px-1.5 py-0 text-xs",children:t.badge})]}):null},Hx=e=>{let{items:t,selected:s,onSelect:a,isOpen:n,onClose:l,title:r,showBackButton:i,onBack:o,showSearch:c=!1,style:d}=e;const[m,u]=(0,Y.useState)(""),[x,h]=(0,Y.useState)(!1);return(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)("div",{className:"fixed inset-0 bg-black/50 backdrop-blur-sm transition-opacity lg:hidden ".concat(n?"opacity-100 z-40":"opacity-0 pointer-events-none"),onClick:l}),(0,le.jsxs)("div",{className:"fixed lg:static inset-y-0 left-0 transform ".concat(n?"translate-x-0":"-translate-x-full"," lg:translate-x-0 transition duration-200 ease-in-out bg-white border-r z-50 lg:z-0 w-full h-full flex flex-col"),style:d,children:[(0,le.jsx)("div",{className:"p-2 flex justify-end lg:hidden",children:(0,le.jsx)(Yt,{variant:"ghost",size:"icon",onClick:l,children:(0,le.jsx)(Bt.A,{className:"h-4 w-4"})})}),i&&(0,le.jsxs)(Yt,{variant:"ghost",className:"justify-start mx-3 mb-2 px-4 text-sm",onClick:o,children:[(0,le.jsx)(rn.A,{className:"h-4 w-4 mr-2 rotate-180"}),"Back to Editor"]}),c&&(0,le.jsx)("div",{className:"px-3 pt-2 pb-4",children:(0,le.jsxs)("div",{className:Pe("relative flex items-center",x?"ring-2 ring-ring":""),children:[(0,le.jsx)(vn.A,{className:"absolute left-3 h-4 w-4 text-muted-foreground"}),(0,le.jsx)("input",{type:"text",placeholder:"Search...",value:m,onChange:e=>u(e.target.value),className:Pe("w-full py-2 pl-9 pr-3 bg-gray-100 rounded-lg text-sm","focus:outline-none transition-all","placeholder:text-muted-foreground","text-foreground"),onFocus:()=>h(!0),onBlur:()=>h(!1)})]})}),(0,le.jsx)("nav",{className:"flex-1 overflow-y-auto py-1 px-3 space-y-1 scrollbar-thin scrollbar-thumb-muted",children:t.map((e,t)=>(0,le.jsx)(Vx,{item:e,selected:s,onSelect:a,searchTerm:m},t))})]})]})};var Yx=s(58907),Gx=s(27255),$x=s(98989);var Jx=s(34079);const Zx=["className"],Kx=["children"],Qx=["className"],Xx=["className"],eh=["className"],th=["className"],sh=["className"],ah=["className"],nh=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,Zx);return(0,le.jsx)(Jx.uB,(0,K.A)({ref:t,className:Pe("flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",s)},a))});nh.displayName=Jx.uB.displayName;const lh=e=>{let{children:t}=e,s=(0,Se.A)(e,Kx);return(0,le.jsx)(Pa,(0,K.A)((0,K.A)({},s),{},{children:(0,le.jsx)(Da,{className:"overflow-hidden p-0 shadow-lg",children:(0,le.jsx)(nh,{className:"[&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-group]]:px-2 [&_[cmdk-input-wrapper]_svg]:h-5 [&_[cmdk-input-wrapper]_svg]:w-5 [&_[cmdk-input]]:h-12 [&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-3 [&_[cmdk-item]_svg]:h-5 [&_[cmdk-item]_svg]:w-5",children:t})})}))},rh=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,Qx);return(0,le.jsxs)("div",{className:"flex items-center border-b px-3","cmdk-input-wrapper":"",children:[(0,le.jsx)(vn.A,{className:"mr-2 h-4 w-4 shrink-0 opacity-50"}),(0,le.jsx)(Jx.uB.Input,(0,K.A)({ref:t,className:Pe("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",s)},a))]})});rh.displayName=Jx.uB.Input.displayName;const ih=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,Xx);return(0,le.jsx)(Jx.uB.List,(0,K.A)({ref:t,className:Pe("max-h-[300px] overflow-y-auto overflow-x-hidden",s)},a))});ih.displayName=Jx.uB.List.displayName;const oh=Y.forwardRef((e,t)=>(0,le.jsx)(Jx.uB.Empty,(0,K.A)({ref:t,className:"py-6 text-center text-sm"},e)));oh.displayName=Jx.uB.Empty.displayName;const ch=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,eh);return(0,le.jsx)(Jx.uB.Group,(0,K.A)({ref:t,className:Pe("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",s)},a))});ch.displayName=Jx.uB.Group.displayName;const dh=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,th);return(0,le.jsx)(Jx.uB.Separator,(0,K.A)({ref:t,className:Pe("-mx-1 h-px bg-border",s)},a))});dh.displayName=Jx.uB.Separator.displayName;const mh=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,sh);return(0,le.jsx)(Jx.uB.Item,(0,K.A)({ref:t,className:Pe("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",s)},a))});mh.displayName=Jx.uB.Item.displayName;const uh=e=>{let{className:t}=e,s=(0,Se.A)(e,ah);return(0,le.jsx)("span",(0,K.A)({className:Pe("ml-auto text-xs tracking-widest text-muted-foreground",t)},s))};uh.displayName="CommandShortcut";const xh=e=>{let{value:t,onChange:s,options:a,isMulti:n,placeholder:l,optionsNames:r=null}=e;const i=a.map((e,t)=>null==e?{label:(null==r?void 0:r[t])||"null",value:null}:"object"==typeof e?{label:e.label||r[t],value:e.value}:{label:r?r[t]:e,value:e});let o=[];if(t)if(n)o=t.map(e=>i.find(t=>t.value===e)).filter(Boolean);else{const e=i.find(e=>e.value===t);e&&(o=[e])}const c=e=>{const t=o.filter(t=>t.value!==e.value);s(t.map(e=>e.value))};var d;return n?(0,le.jsxs)(nh,{className:"border rounded-md",children:[(0,le.jsx)("div",{className:"flex gap-1 flex-wrap p-2",children:null===(d=o)||void 0===d?void 0:d.map(e=>(0,le.jsxs)(es,{variant:"secondary",className:"max-w-[200px]",children:[(0,le.jsx)("span",{className:"truncate",children:e.label}),(0,le.jsx)("button",{className:"ml-1 ring-offset-background rounded-full outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",onKeyDown:t=>{"Enter"===t.key&&c(e)},onMouseDown:e=>{e.preventDefault(),e.stopPropagation()},onClick:()=>c(e),children:(0,le.jsx)(Bt.A,{className:"h-3 w-3 text-muted-foreground hover:text-foreground"})})]},e.value))}),(0,le.jsx)(rh,{placeholder:l||"Search...",className:"border-none focus:ring-0"}),(0,le.jsx)(ch,{className:"max-h-[200px] overflow-auto",children:0===(null==i?void 0:i.length)?(0,le.jsx)("div",{className:"py-6 text-center text-sm text-muted-foreground",children:"No options available"}):null==i?void 0:i.map(e=>{var t;return(0,le.jsx)("div",{className:"cursor-pointer px-2 py-1.5 ".concat(null!==(t=o)&&void 0!==t&&t.some(t=>t.value===e.value)?"bg-muted":""),onClick:()=>(e=>{if(n){const t=o.some(t=>t.value===e.value)?o.filter(t=>t.value!==e.value):[...o,e];s(t.map(e=>e.value))}else s(e.value)})(e),children:e.label},e.value)})})]}):(0,le.jsxs)(zs,{value:null==t?void 0:t.toString(),onValueChange:e=>s(e),children:[(0,le.jsx)(qs,{children:(0,le.jsx)(Ws,{placeholder:l})}),(0,le.jsx)(Ys,{children:(0,le.jsx)(Us,{children:0===i.length?(0,le.jsx)("div",{className:"py-6 text-center text-sm text-muted-foreground",children:"No options available"}):i.map(e=>{var t;return(0,le.jsx)($s,{value:(null===(t=e.value)||void 0===t?void 0:t.toString())||null,children:e.label},e.value||"null")})})})]})};function hh(e){let{value:t,onChange:s,name:a,itemSchema:n,isMulti:l=!1}=e;const{getEntitiesSDK:r}=Nt(),[i,o]=(0,Y.useState)([]),[c,d]=(0,Y.useState)(!1),m=r();return(0,Y.useEffect)(()=>{d(!0);const e=n.$ref.split("/");if(4!==e.length||""!==e[0]||"entities"!==e[1]||"id"!==e[3])throw new Error("Error in ".concat(a," field. Invalid $ref format: ").concat(n.$ref,". should be like /entities/EntityName/id"));const t=e[2];m[t].list().then(e=>{o(e.map(e=>{const s=m[t].schema();let a="id";for(const t in s.properties)if(t.toLowerCase().includes("name")||t.toLowerCase().includes("title")){a=t;break}return{label:e[a],value:e.id}})),d(!1)})},[n.$ref]),c?(0,le.jsx)("div",{children:"Loading..."}):(0,le.jsx)(xh,{options:i,onChange:s,isMulti:l,value:t})}var ph=s(53938);const gh=["className","classNames","showOutsideDays"];function fh(e){let{className:t,classNames:s,showOutsideDays:a=!0}=e,n=(0,Se.A)(e,gh);return(0,le.jsx)(ph.hv,(0,K.A)({showOutsideDays:a,className:Pe("p-3",t),classNames:(0,K.A)({months:"flex flex-col sm:flex-row space-y-4 sm:space-x-4 sm:space-y-0",month:"space-y-4",caption:"flex justify-center pt-1 relative items-center",caption_label:"text-sm font-medium",nav:"space-x-1 flex items-center",nav_button:Pe(Ht({variant:"outline"}),"h-7 w-7 bg-transparent p-0 opacity-50 hover:opacity-100"),nav_button_previous:"absolute left-1",nav_button_next:"absolute right-1",table:"w-full border-collapse space-y-1",head_row:"flex",head_cell:"text-muted-foreground rounded-md w-9 font-normal text-[0.8rem]",row:"flex w-full mt-2",cell:"h-9 w-9 text-center text-sm p-0 relative [&:has([aria-selected].day-range-end)]:rounded-r-md [&:has([aria-selected].day-outside)]:bg-accent/50 [&:has([aria-selected])]:bg-accent first:[&:has([aria-selected])]:rounded-l-md last:[&:has([aria-selected])]:rounded-r-md focus-within:relative focus-within:z-20",day:Pe(Ht({variant:"ghost"}),"h-9 w-9 p-0 font-normal aria-selected:opacity-100"),day_range_end:"day-range-end",day_selected:"bg-primary text-primary-foreground hover:bg-primary hover:text-primary-foreground focus:bg-primary focus:text-primary-foreground",day_today:"bg-accent text-accent-foreground",day_outside:"day-outside text-muted-foreground opacity-50 aria-selected:bg-accent/50 aria-selected:text-muted-foreground aria-selected:opacity-30",day_disabled:"text-muted-foreground opacity-50",day_range_middle:"aria-selected:bg-accent aria-selected:text-accent-foreground",day_hidden:"invisible"},s),components:{IconLeft:e=>{Object.assign({},((0,Ja.A)(e),e));return(0,le.jsx)(Xs.A,{className:"h-4 w-4"})},IconRight:e=>{Object.assign({},((0,Ja.A)(e),e));return(0,le.jsx)(rn.A,{className:"h-4 w-4"})}}},n))}fh.displayName="Calendar";var vh=s(32264),bh=s(19201),jh=s(48367);const yh=["className","align","sideOffset"],Nh=jh.bL,wh=jh.l9,_h=Y.forwardRef((e,t)=>{let{className:s,align:a="center",sideOffset:n=4}=e,l=(0,Se.A)(e,yh);return(0,le.jsx)(jh.ZL,{children:(0,le.jsx)(jh.UC,(0,K.A)({ref:t,align:a,sideOffset:n,className:Pe("z-50 w-72 rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",s)},l))})});function kh(e){let{value:t,onChange:s,format:a="date",className:n}=e;const l=(e,t)=>{if(t){const[s,a]=t.split(":");e.setHours(parseInt(s)),e.setMinutes(parseInt(a))}s(e)};let r=t;return r=null==t||""===t?null:new Date(t),(0,le.jsxs)(Nh,{children:[(0,le.jsx)(wh,{asChild:!0,children:(0,le.jsxs)(Yt,{variant:"outline",className:Pe("w-full justify-start text-left font-normal",!r&&"text-muted-foreground",n),children:[(0,le.jsx)(bh.A,{className:"mr-2 h-4 w-4"}),r?"date"===a?(0,vh.GP)(r,"PPP"):"date-time"===a?(0,vh.GP)(r,"PPP HH:mm:ss"):(0,vh.GP)(r,"HH:mm:ss"):(0,le.jsx)("span",{children:"Pick a date"})]})}),(0,le.jsx)(_h,{className:"w-auto p-0",style:{zIndex:9999,position:"relative",isolation:"isolate",pointerEvents:"auto"},onInteractOutside:e=>{e.target.closest('[role="dialog"]')&&e.preventDefault()},forceMount:!0,children:(0,le.jsxs)("div",{className:"p-3 bg-popover shadow-lg rounded-md border",style:{pointerEvents:"auto"},children:[(0,le.jsx)(fh,{mode:"single",selected:r,onSelect:e=>l(e),initialFocus:!0,className:"pointer-events-auto"}),("date-time"===a||"time"===a)&&(0,le.jsx)("input",{type:"time",className:"mt-3 w-full px-3 py-2 border rounded pointer-events-auto",value:r?(0,vh.GP)(r,"HH:mm"):"",onChange:e=>l(r||new Date,e.target.value)})]})})]})}function Ch(e){let{value:t,onChange:s,isMulti:a}=e;const n=Nt(),[l,r]=(0,Y.useState)([]),[i,o]=(0,Y.useState)(!1);(0,Y.useEffect)(()=>{if(t){r((a?t:[t]).map(e=>({name:e.split("/").pop(),url:e})))}},[t,a]);const c=(0,Y.useCallback)(async e=>{o(!0);try{const t=await Promise.all(e.map(async e=>{const t=null!=n&&n.app?await _t.uploadAppFile(e,n.app.id):await _t.uploadFile(e);return{name:e.name,url:t.url}}));r(e=>{const s=a?[...e,...t]:t;return d(s),s})}catch(t){}finally{o(!1)}},[a,s]),d=e=>{s(a?e.map(e=>e.url):e.length>0?e[0].url:null)};return(0,le.jsxs)("div",{className:"w-full",children:[(0,le.jsxs)("div",{className:Pe("flex items-center justify-center w-full rounded-lg border border-dashed","border-muted-foreground/25 hover:border-primary transition-colors","p-4 cursor-pointer"),onClick:()=>{var e;return null===(e=document.getElementById("fileInput"))||void 0===e?void 0:e.click()},children:[i?(0,le.jsx)("div",{className:"loading loading-spinner"}):(0,le.jsx)(hx.A,{className:"h-5 w-5 text-muted-foreground"}),(0,le.jsx)("input",{id:"fileInput",type:"file",multiple:a,className:"hidden",onChange:e=>c(Array.from(e.target.files||[])),disabled:i})]}),l.length>0&&(0,le.jsx)("div",{className:"mt-2 space-y-1",children:l.map((e,t)=>(0,le.jsxs)("div",{className:"flex items-center justify-between bg-muted/50 p-1 rounded",children:[(0,le.jsx)("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",className:"text-xs hover:underline truncate",children:e.name}),(0,le.jsx)(Yt,{variant:"ghost",size:"icon",onClick:()=>{return t=e,void r(e=>{const s=e.filter(e=>e!==t);return d(s),s});var t},className:"h-4 w-4 p-0",children:(0,le.jsx)(Bt.A,{className:"h-3 w-3"})})]},t))})]})}_h.displayName=jh.UC.displayName;const Ah=e=>{let{value:t,onChange:s}=e;return(0,le.jsx)(dm,{checked:t,onCheckedChange:s})},Sh=e=>{let{value:t,onChange:s}=e;const[a,n]=(0,Y.useState)("");return(0,le.jsxs)("div",{className:"flex flex-wrap items-center border rounded-md p-1",children:[t&&t.map((e,a)=>(0,le.jsxs)("span",{className:"bg-gray-200 rounded-md px-2 py-1 m-1 flex items-center",children:[e,(0,le.jsx)("button",{type:"button",onClick:()=>(e=>{const a=t.filter((t,s)=>s!==e);s(a)})(a),className:"ml-1 text-gray-500 hover:text-gray-700 focus:outline-none",children:"\xd7"})]},a)),(0,le.jsx)("input",{type:"text",value:a,onChange:e=>{n(e.target.value)},onKeyDown:e=>{if("Enter"===e.key&&a.trim()){e.preventDefault();const l=[...t||[],a.trim()];s(l),n("")}else if("Backspace"===e.key&&!a&&t&&t.length>0){const e=t.slice(0,-1);s(e)}},className:"flex-grow outline-none px-2 py-1",placeholder:"enter values..."})]})};function Eh(e){if(void 0!==e.default)return e.default;switch(e.type){case"string":return"";case"number":return 0;case"boolean":return!1;default:return null}}function Ih(e){let{path:t,schema:s,value:a,setValueAt:n,getValueAt:l,uiSchema:r,validationErrors:i}=e;const o=a||[];if("string"===s.items.type&&!s.items.$ref&&!s.items.enum&&!s.items.format)return(0,le.jsx)(Sh,{value:o,onChange:e=>n(t,e)});if("string"===s.items.type&&s.items.enum)return(0,le.jsx)(xh,{options:s.items.enum,isMulti:!0,value:o,onChange:e=>n(t,e),optionsNames:s.items.enumNames});if("string"===s.items.type&&"file"===s.items.format)return(0,le.jsx)(Ch,{value:o,onChange:e=>n(t,e),isMulti:!0});if(s.items.$ref)return(0,le.jsx)(hh,{value:o,onChange:e=>n(t,e),name:t[t.length-1],itemSchema:s.items,isMulti:!0});const c=s.items.default||"object"===s.items.type?{}:null;if(!s.hasOwnProperty("items"))throw new Error("Error in json schema for array: items is required. path: ".concat(t.join(".")));return(0,le.jsxs)("div",{className:"space-y-4 ps-4 border-s-2 border-gray-200",children:[o.map((e,a)=>(0,le.jsxs)("div",{className:"relative",children:[(0,le.jsx)("button",{className:"absolute top-0 right-0 p-1 text-gray-500 hover:text-gray-700",onClick:()=>(e=>{const s=[...o];s.splice(e,1),n(t,s)})(a),children:(0,le.jsx)(Bt.A,{size:16})}),(0,le.jsx)(Ph,{path:[...t,a],value:e,schema:s.items,setValueAt:n,getValueAt:l,uiSchema:r,validationErrors:i[a]||{}},a)]},a)),(0,le.jsx)("div",{className:"mt-2",children:(0,le.jsxs)("button",{type:"button",onClick:e=>{e.preventDefault(),n([...t,o.length],c)},className:"btn btn-outline btn-sm",children:[(0,le.jsx)(kt.A,{size:16})," Add Item"]})})]})}function Th(e){let{path:t,schema:s,value:a,setValueAt:n,getValueAt:l,uiSchema:r,validationErrors:i,suppressLabel:o}=e;const c=a||{},[d,m]=Y.useState(""),[u,x]=Y.useState(Eh(s.additionalProperties));return(0,le.jsxs)("div",{className:"space-y-2 ps-4 border-s-2 border-gray-200",children:[Object.entries(c).map(e=>{let[a,o]=e;return(0,le.jsx)("div",{children:(0,le.jsxs)("div",{className:"flex items-center gap-4 mb-1",children:[(0,le.jsx)("div",{className:"flex-1 mt-4",children:(0,le.jsx)(fs,{type:"text",value:a,disabled:!0,className:"bg-gray-50"})}),(0,le.jsx)("div",{className:"flex-1",children:(0,le.jsx)(Ph,{path:[...t,a],value:o,schema:s.additionalProperties,setValueAt:n,getValueAt:l,uiSchema:r,validationErrors:i[a]||{},suppressLabel:!0})}),(0,le.jsx)("button",{className:"mt-4 p-1 text-gray-500 hover:text-gray-700",onClick:()=>(e=>{const s=(0,K.A)({},c);delete s[e],n(t,s)})(a),"aria-label":"Remove",children:(0,le.jsx)(Bt.A,{size:16})})]})},a)}),(0,le.jsxs)("div",{children:[(0,le.jsxs)("div",{className:"flex items-center gap-4",children:[(0,le.jsx)("div",{className:"flex-1 mt-4",children:(0,le.jsx)(fs,{type:"text",value:d,onChange:e=>m(e.target.value),placeholder:"Key",className:"flex-1"})}),(0,le.jsx)("div",{className:"flex-1",children:(0,le.jsx)(Ph,{path:[...t,"new"],value:u,schema:s.additionalProperties,setValueAt:(e,t)=>x(t),getValueAt:()=>u,uiSchema:r,validationErrors:{},suppressLabel:!0})})]}),(0,le.jsx)("div",{className:"mt-2 flex",children:(0,le.jsx)("button",{type:"button",onClick:e=>{if(e.preventDefault(),!d)return;const a=(0,K.A)({},c);a[d]=u,n(t,a),m(""),x(Eh(s.additionalProperties))},className:"btn btn-outline btn-sm",children:"+ Add"})})]})]})}function Ph(e){let{path:t,getValueAt:s,setValueAt:a,schema:n,uiSchema:l,validationErrors:r,suppressLabel:i}=e;if("hidden"===l["ui:widget"])return(0,le.jsx)(le.Fragment,{});if(!n)throw new Error("Error in json schema: schema for the property is required. property path: ".concat(t.join(".")));const o=void 0===s(t)?n.default||null:s(t);let c;if(!i)if(l["ui:title"])c=l["ui:title"];else if(n.title)c=n.title;else{const e=t[t.length-1];c="number"==typeof e?void 0:e}return(0,le.jsxs)("div",{className:"mt-4",children:[c&&(0,le.jsxs)("div",{className:"mb-2",children:[(0,le.jsx)("label",{htmlFor:t.join("__"),className:"text-sm font-medium text-gray-900",children:c}),n.description&&(0,le.jsx)("p",{className:"text-sm text-gray-500",children:n.description})]}),(()=>{if(Ae().isFunction(l["ui:widget"]))return l["ui:widget"]({value:o,onChange:e=>a(t,e),getValueAt:s,setValueAt:a,schema:n,uiSchema:l,path:t});if(n.enum&&"array"!==n.type&&"object"!==n.type)return(0,le.jsx)(xh,{options:n.enum,optionsNames:n.enumNames,value:o,onChange:e=>a(t,e)});if(n.$ref)return(0,le.jsx)(hh,{value:o,onChange:e=>a(t,e),name:t[t.length-1],itemSchema:n});if("string"===n.type)return"date"===n.format||"date-time"===n.format||"time"===n.format?(0,le.jsx)(kh,{format:n.format,value:o,onChange:e=>a(t,e)}):"file"===n.format?(0,le.jsx)(Ch,{value:o,onChange:e=>a(t,e)}):"textarea"===l["ui:widget"]?(0,le.jsx)(um,{value:null!=o?o:"",onChange:e=>a(t,e.target.value)}):(0,le.jsx)(fs,{type:"text",value:null!=o?o:"",onChange:e=>a(t,e.target.value)});if("number"===n.type||"integer"===n.type)return(0,le.jsx)(fs,{type:"number",value:null!=o?o:"",onChange:e=>a(t,parseFloat(e.target.value)),min:n.minimum,max:n.maximum,step:"integer"===n.type?1:"any"});if("boolean"===n.type)return(0,le.jsx)(Ah,{value:o,onChange:e=>a(t,e)});if("array"===n.type)return(0,le.jsx)(Ih,{path:t,schema:n,value:o,setValueAt:a,getValueAt:s,uiSchema:l.hasOwnProperty("items")?l.items:l,validationErrors:r});if("object"===n.type){if(n.additionalProperties)return(0,le.jsx)(Th,{path:t,schema:n,value:o,setValueAt:a,getValueAt:s,uiSchema:l,validationErrors:r,suppressLabel:i});if(!n.properties)throw new Error("Error in json schema: properties is required for object type. property path: ".concat(t.join("."),". if you need the user to insert a flexible object, JsonSchemaFrom might not be the right choice"));return(0,le.jsx)("div",{className:"space-y-4 ps-4 border-s-2 border-gray-200",children:Object.entries(n.properties).map(e=>{let[n,i]=e;return(0,le.jsx)(Ph,{path:[...t,n],getValueAt:s,setValueAt:a,schema:i,uiSchema:l[n]||{},validationErrors:r[n]||{}},n)})})}})(),r&&Ae().isString(r)&&(0,le.jsx)("div",{style:{color:"red"},children:r})]})}function Lh(e,t,s){if(0===t.length)return s;const[a,...n]=t,l=Ae().isNumber(n[0]),r=Ae().isArray(e)?[...e]:(0,K.A)({},e);return 0===n.length?r[a]=s:r[a]=Lh(l?r[a]||[]:r[a]||{},n,s),r}function Oh(e,t){if(Ae().isNil(e)||0===t.length)return e;const[s,...a]=t;return 0===a.length?e[s]:Oh(e[s],a)}const Rh=e=>{let{schema:t,onChange:s,onSubmit:a,initialValues:n,uiSchema:l}=e;const[r,i]=(0,Y.useState)(n||{}),[o,c]=(0,Y.useState)({});if(!t||Ae().isEmpty(t)||Ae().isEmpty(t.properties))throw new Error("Error In JsonSchemaForm: valid json schema is required, but got: "+JSON.stringify(t));const d=function(e,t){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[];const a={};if("object"===e.type&&e.properties){Object.entries(e.properties).forEach(e=>{let[n,l]=e;const r=[...s,n],i=d(l,t,r);Ae().isEmpty(i)||(a[n]=i)});const n=function(e){if(!e||(0,Ce.isEmpty)(e))throw new Error("JSON Schema error is required, got: "+JSON.stringify(e));if((0,Ce.isEmpty)(e.properties))throw new Error("JSON Schema error: properties are required in schema, got schema: "+JSON.stringify(e));return e.required||[]}(e)||[];n.forEach(n=>{const r=[...s,n],i=Oh(t,r)||e.properties[n].default,o=Oh(l,r),c="hidden"===(null==o?void 0:o["ui:widget"]);"boolean"===e.properties[n].type||null!=i&&""!==i||c||(a[n]="This field is required")})}else if("array"===e.type&&e.items){(Oh(t,s)||[]).forEach((n,l)=>{const r=[...s,l],i=d(e.items,t,r);Ae().isEmpty(i)||(a[l]=i)})}return a},m=(e,t)=>{const a=Lh(r,e,t);i(a),s&&s(a)};if(Ae().isFunction(l)&&(l=l(r)),l&&"object"==typeof l){const e={};Object.entries(l).forEach(t=>{let[s,a]=t;const n=s.split(".");let l=e;for(let e=0;e{let[t,s]=e;return(0,le.jsx)(Ph,{path:[t],value:r[t],setValueAt:m,getValueAt:e=>Oh(r,e),schema:s,uiSchema:(l||{})[t]||{},validationErrors:o[t]||{}},t)}),a&&(0,le.jsx)("div",{className:"mt-4",children:(0,le.jsx)(Yt,{onClick:e=>{e.preventDefault();(()=>{const e=d(t,r);return c(e),Ae().isEmpty(e)})()?a(r):(0,cr.toast)("some fields are required: "+Object.keys(o).join(", "))},children:"Submit"})})]})},Mh=Rh,Dh=e=>{let{isOpen:t,onClose:s,title:a,children:n}=e;return t?(0,le.jsx)("div",{className:"modal modal-open",children:(0,le.jsxs)("div",{className:"modal-box",children:[(0,le.jsx)("h3",{className:"font-bold text-lg",children:a}),(0,le.jsx)("div",{className:"py-4",children:n}),(0,le.jsx)("div",{className:"modal-action",children:(0,le.jsx)("button",{className:"btn",onClick:s,children:"Close"})})]})}):null},Fh={type:"object",properties:{title:{type:"string",title:"Title",default:""},description:{type:"string",title:"Description",default:null},type:{type:"string",title:"Type",default:"string",enum:["string","number","boolean","object","array","binary"]}}};function Bh(e){let t=Ae().cloneDeep(Fh);return"array"===e.type&&(e.items?t.properties.items=Bh(e.items):t.properties.items=Ae().cloneDeep(Fh)),"string"===e.type&&(t.properties.format={type:"string",title:"Format",default:null,enum:["date","email","file","uri","date-time","ipv4","ipv6","regex"]},"file"!==e.format&&(t.properties.enum={type:"array",title:"Enum",default:null,items:{type:"string"}})),e.type,t}function zh(e){let{value:t,onSubmit:s}=e;const[a,n]=(0,Y.useState)(t),l=Bh(a);return(0,le.jsx)(Mh,{schema:l,initialValues:a,onChange:e=>{n(e)},onSubmit:s})}var Uh=s(388),Wh=s(59807),qh=s(81807),Vh=s(78541),Hh=s(14754);function Yh(e,t){if(t.$ref)return(0,le.jsx)(Tr.A,{size:16});switch(e){case"array":return(0,le.jsx)(El.A,{size:16});case"date-time":case"date":return(0,le.jsx)(bh.A,{size:16});case"email":return(0,le.jsx)(Uh.A,{size:16});case"uri":case"url":return(0,le.jsx)(Wh.A,{size:16});case"number":return(0,le.jsx)(qh.A,{size:16});case"boolean":return(0,le.jsx)(Vh.A,{size:16});case"object":return(0,le.jsx)(Hh.A,{size:16});default:return(0,le.jsx)(hr.A,{size:16})}}function Gh(e){let{name:t,prop:s,schema:a,onEdit:n}=e;const l=Object.entries(s).filter(e=>{let[t]=e;return!["type","description","default","title","format","$ref","enum","items","properties","required"].includes(t)}),r=function(e){if("array"===e.type)return"array";if("string"===e.type){if("date-time"===e.format)return"date-time";if("date"===e.format)return"date";if("email"===e.format)return"email";if("uri"===e.format)return"uri";if("url"===e.format)return"url";if(e.$ref){const t=e.$ref.split("/");return t[t.length-2]}return"text"}return e.type}(s);return(0,le.jsx)("li",{className:"py-4",children:(0,le.jsxs)("div",{className:"flex flex-col space-y-2",children:[(0,le.jsx)("div",{className:"flex items-center justify-between",children:(0,le.jsxs)("div",{className:"flex items-center",children:[(0,le.jsx)("h5",{className:"font-semibold text-gray-900 me-2",children:s.title||t})," ("," ",Yh(r,s),(0,le.jsx)("span",{className:"ml-1",children:r}),a.required&&a.required.includes(t)&&(0,le.jsx)("span",{className:"ml-2",children:", required"}),")"]})}),s.description&&(0,le.jsx)("p",{className:"text-sm text-gray-700",children:s.description}),void 0!==s.default&&(0,le.jsxs)("div",{className:"text-sm",children:[(0,le.jsx)("span",{className:"font-medium",children:"Default:"})," ",JSON.stringify(s.default)]}),s.enum&&(0,le.jsxs)("div",{className:"text-sm",children:[(0,le.jsx)("span",{className:"font-medium",children:"Options:"})," ",s.enum.join(", ")]}),s.items&&(0,le.jsx)("div",{className:"ps-6 border-s-4 border-gray-300",children:(0,le.jsx)($h,{schema:s.items})}),s.properties&&(0,le.jsx)("div",{className:"ps-6 border-s-4 border-gray-300",children:(0,le.jsx)($h,{schema:s})}),l.length>0&&(0,le.jsxs)("div",{className:"mt-2",children:[(0,le.jsx)("h4",{className:"text-sm font-medium text-gray-900",children:"Additional Properties:"}),(0,le.jsx)("ul",{className:"mt-1 space-y-1",children:l.map(e=>{let[t,s]=e;return(0,le.jsxs)("li",{className:"text-sm text-gray-600",children:[(0,le.jsxs)("span",{className:"font-medium",children:[t,":"]})," ",JSON.stringify(s)]},t)})})]})]})},t)}function $h(e){let{schema:t,onEdit:s}=e;const[a,n]=(0,Y.useState)(null),l=(e,t)=>{n({name:e,prop:t})};return(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)("ul",{className:"ps-4 border-s-4 border-gray-300",children:Object.entries(t.properties||{}).map(e=>{let[a,n]=e;return(0,le.jsx)(Gh,{name:a,prop:n,schema:t,onEdit:s?l:null},a)})}),a&&(0,le.jsx)(Dh,{isOpen:!!a,onClose:()=>{n(null)},title:"Edit ".concat(a.name),children:(0,le.jsx)(zh,{value:a.prop,onSubmit:e=>{s&&s(a.name,e),n(null)}})})]})}const Jh=["className"],Zh=["side","className","children"],Kh=["className"],Qh=["className"],Xh=["className"],ep=["className"],tp=ka.Root,sp=ka.Trigger,ap=ka.Close,np=ka.Portal,lp=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,Jh);return(0,le.jsx)(ka.Overlay,(0,K.A)((0,K.A)({className:Pe("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",s)},a),{},{ref:t}))});lp.displayName=ka.Overlay.displayName;const rp=(0,Ee.cva)("fixed z-50 gap-4 bg-background p-6 shadow-lg transition ease-in-out data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:duration-300 data-[state=open]:duration-500",{variants:{side:{top:"inset-x-0 top-0 border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top",bottom:"inset-x-0 bottom-0 border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom",left:"inset-y-0 left-0 h-full w-3/4 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-sm",right:"inset-y-0 right-0 h-full w-3/4 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-sm"}},defaultVariants:{side:"right"}}),ip=Y.forwardRef((e,t)=>{let{side:s="right",className:a,children:n}=e,l=(0,Se.A)(e,Zh);return(0,le.jsxs)(np,{children:[(0,le.jsx)(lp,{}),(0,le.jsxs)(ka.Content,(0,K.A)((0,K.A)({ref:t,className:Pe(rp({side:s}),a)},l),{},{children:[n,(0,le.jsxs)(ka.Close,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-secondary",children:[(0,le.jsx)(Bt.A,{className:"h-4 w-4"}),(0,le.jsx)("span",{className:"sr-only",children:"Close"})]})]}))]})});ip.displayName=ka.Content.displayName;const op=e=>{let{className:t}=e,s=(0,Se.A)(e,Kh);return(0,le.jsx)("div",(0,K.A)({className:Pe("flex flex-col space-y-2 text-center sm:text-left",t)},s))};op.displayName="SheetHeader";const cp=e=>{let{className:t}=e,s=(0,Se.A)(e,Qh);return(0,le.jsx)("div",(0,K.A)({className:Pe("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",t)},s))};cp.displayName="SheetFooter";const dp=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,Xh);return(0,le.jsx)(ka.Title,(0,K.A)({ref:t,className:Pe("text-lg font-semibold text-foreground",s)},a))});dp.displayName=ka.Title.displayName;const mp=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,ep);return(0,le.jsx)(ka.Description,(0,K.A)({ref:t,className:Pe("text-sm text-muted-foreground",s)},a))});mp.displayName=ka.Description.displayName;const up=e=>{let{children:t,className:s,title:a,prefix:n,subtitle:l,primaryAction:r,actions:i,filters:o,content:c}=e;return(0,le.jsxs)("div",{className:Pe("flex flex-col p-6 gap-6 h-full font-base44 md:max-w-[1200px] mx-auto",s),children:[(0,le.jsxs)("div",{className:"grid grid-cols-[".concat(n?"min-content_":"","1fr_max-content] gap-6"),children:[n&&(0,le.jsx)("div",{className:"flex mr-2",children:n}),(0,le.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,le.jsx)("h2",{className:"font-semibold text-xl",children:a}),l&&(0,le.jsx)("p",{className:"text-sm text-[#71717A] font-normal",children:l})]}),(i||r)&&(0,le.jsxs)("div",{className:"flex flex-row gap-2 items-center",children:[i,r]})]}),o&&(0,le.jsx)("div",{className:"flex md:flex-row md:items-center flex-wrap gap-2 w-full items-left",children:o}),(0,le.jsxs)("div",{className:"flex flex-col gap-3 pb-6",children:[c,t]})]})};function xp(e){let{entity:t}=e;const{app:s,updateApp:a}=Nt();return(0,le.jsx)($h,{schema:t,onEdit:(e,n)=>{t.properties[e]=n,s.entities[t.name]=t,a({entities:s.entities})}})}const hp=function(e){let{entity:t}=e;const{app:s,getEntitiesSDK:a}=Nt(),{toast:n}=nn(),[l,r]=(0,Y.useState)(!1),[i,o]=(0,Y.useState)(!1),[c,d]=(0,Y.useState)(null),[m,u]=(0,Y.useState)(!1),[x,h]=(0,Y.useState)(!1),[p,g]=(0,Y.useState)(!1),[f,v]=(0,Y.useState)(1),b=a(),{data:{entities:j,hasMore:y}={entities:[],hasMore:!1},isLoading:N,error:w,refetch:_}=uu({query:async()=>{const e=50*(f-1),s=await b[t.name].list(null,51,e),a=s.length>50;return{entities:s.slice(0,50),hasMore:a}},toastError:"Failed to load records"},[t.name,f]);return(0,Y.useEffect)(()=>{v(1)},[t]),(0,le.jsxs)(up,{title:t.name,subtitle:t.description,primaryAction:(0,le.jsxs)(Yt,{size:"sm",onClick:()=>{d(null),r(!0)},children:[(0,le.jsx)(kt.A,{className:"h-4 w-4 mr-2"}),"Add"]}),actions:[(0,le.jsx)(fs,{type:"file",accept:".csv",className:"hidden",id:"csv-upload",onChange:async e=>{const s=e.target.files[0];if(s){u(!0);try{const e=await b[t.name].importEntities(s);"success"===e.status&&(n({title:"Import Successful",description:"Successfully imported ".concat(e.n_entities_created," ").concat(t.name," records")}),_())}catch(w){var a,l;n({title:"Import Failed",description:(null===(a=w.response)||void 0===a||null===(l=a.data)||void 0===l?void 0:l.message)||w.message,variant:"destructive"})}finally{u(!1),e.target.value=""}}},disabled:m}),(0,le.jsxs)(qr,{children:[(0,le.jsx)(Vr,{asChild:!0,children:(0,le.jsx)(Yt,{size:"sm",variant:"outline",children:(0,le.jsx)(Tl.A,{className:"h-4 w-4"})})}),(0,le.jsxs)(Kr,{align:"end",children:[(0,le.jsxs)(Qr,{onClick:()=>document.getElementById("csv-upload").click(),disabled:m,children:[m?(0,le.jsx)(Ne.A,{className:"h-4 w-4 animate-spin mr-2"}):(0,le.jsx)(Yx.A,{className:"h-4 w-4 mr-2"}),"Import"]}),(0,le.jsxs)(Qr,{onClick:async()=>{h(!0);try{const e=await b[t.name].list(),s=Object.keys(e[0]||{}),a=[s.join(","),...Object.values(e).map(e=>s.map(t=>{const s=e[t];let a;a="object"==typeof s&&null!==s?JSON.stringify(s):String(null!=s?s:"");const n=a.replace(/"/g,'""');return'"'.concat(n,'"')}).join(","))],l=a.join("\n"),r=new Blob([l],{type:"text/csv"}),i=window.URL.createObjectURL(r),o=document.createElement("a");o.href=i,o.download="".concat(t.name,"_export.csv"),document.body.appendChild(o),o.click(),document.body.removeChild(o),window.URL.revokeObjectURL(i),n({title:"Export Successful",description:"Successfully exported entities to CSV"})}catch(w){var e,s;n({title:"Export Failed",description:(null===(e=w.response)||void 0===e||null===(s=e.data)||void 0===s?void 0:s.message)||w.message,variant:"destructive"})}finally{h(!1)}},disabled:x,children:[x?(0,le.jsx)(Ne.A,{className:"h-4 w-4 animate-spin mr-2"}):(0,le.jsx)(Gx.A,{className:"h-4 w-4 mr-2"}),"Export"]}),(0,le.jsxs)(Qr,{onClick:()=>o(!0),children:[(0,le.jsx)(Ed.A,{className:"h-4 w-4 mr-2"}),"Schema"]}),(0,le.jsxs)(Qr,{onClick:async()=>{if(window.confirm("Are you sure you want to delete all records? This cannot be undone.")){g(!0);try{await b[t.name].deleteMany({}),await _(),n({title:"Success",description:"All records deleted successfully"})}catch(w){var e,s;n({title:"Error",description:(null===(e=w.response)||void 0===e||null===(s=e.data)||void 0===s?void 0:s.message)||w.message,variant:"destructive"})}finally{g(!1)}}},disabled:p||0===j.length,className:"text-red-500 hover:text-red-600 focus:text-red-600",children:[p?(0,le.jsx)(Ne.A,{className:"h-4 w-4 animate-spin mr-2"}):(0,le.jsx)($x.A,{className:"h-4 w-4 mr-2"}),"Delete All"]})]})]})],children:[(0,le.jsxs)("div",{className:"border rounded-md",children:[(0,le.jsx)("div",{className:"h-[600px] w-full overflow-auto",children:(0,le.jsxs)(zl,{className:"min-w-full",children:[(0,le.jsx)(Ul,{className:"sticky top-0 bg-background z-10",children:(0,le.jsxs)(Vl,{children:[Object.keys(t.properties).map(e=>(0,le.jsx)(Hl,{className:"text-xs whitespace-nowrap",children:t.properties[e].title||e},e)),(0,le.jsx)(Hl,{className:"text-xs",children:"Actions"})]})}),(0,le.jsx)(Wl,{children:N?(0,le.jsx)(Vl,{children:(0,le.jsxs)(Yl,{colSpan:Object.keys(t.properties).length+1,className:"text-center py-4",children:[(0,le.jsx)(Ne.A,{className:"h-6 w-6 animate-spin mx-auto"}),(0,le.jsx)("p",{className:"text-sm text-muted-foreground mt-2",children:"Loading records..."})]})}):0===j.length?(0,le.jsx)(Vl,{children:(0,le.jsxs)(Yl,{colSpan:Object.keys(t.properties).length+1,className:"text-center py-8",children:[(0,le.jsx)("p",{className:"text-sm text-muted-foreground",children:"No records found"}),(0,le.jsxs)(Yt,{variant:"outline",size:"sm",className:"mt-2",onClick:()=>{d(null),r(!0)},children:[(0,le.jsx)(kt.A,{className:"h-4 w-4 mr-2"}),"Add your first record"]})]})}):j.map(e=>(0,le.jsxs)(Vl,{className:"cursor-pointer hover:bg-muted/50",onClick:()=>{d(e),r(!0)},children:[Object.keys(t.properties).map(t=>{var s;return(0,le.jsx)(Yl,{className:"text-xs whitespace-nowrap overflow-hidden text-ellipsis",style:{maxWidth:"200px"},children:"object"==typeof e[t]?JSON.stringify(e[t]):String(null!==(s=e[t])&&void 0!==s?s:"")},t)}),(0,le.jsx)(Yl,{className:"whitespace-nowrap",children:(0,le.jsx)("div",{className:"flex gap-1",children:(0,le.jsx)(Yt,{size:"xs",variant:"ghost",onClick:s=>{s.stopPropagation(),(async e=>{try{await b[t.name].delete(e.id),await _(),n({title:"Success",description:"Item deleted successfully"})}catch(w){var s,a;n({title:"Error",description:(null===(s=w.response)||void 0===s||null===(a=s.data)||void 0===a?void 0:a.message)||w.message,variant:"destructive"})}})(e)},className:"text-red-500 hover:text-red-600",children:(0,le.jsx)($x.A,{className:"h-3 w-3"})})})})]},e.id))})]})}),(0,le.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-t",children:[(0,le.jsxs)("div",{className:"text-sm text-muted-foreground",children:["Page ",f]}),(0,le.jsxs)("div",{className:"flex gap-2",children:[(0,le.jsxs)(Yt,{size:"sm",variant:"outline",onClick:()=>v(e=>e-1),disabled:1===f||N,children:[(0,le.jsx)(Xs.A,{className:"h-4 w-4 mr-1"}),"Previous"]}),(0,le.jsxs)(Yt,{size:"sm",variant:"outline",onClick:()=>v(e=>e+1),disabled:!y||N,children:["Next",(0,le.jsx)(rn.A,{className:"h-4 w-4 ml-1"})]})]})]})]}),(0,le.jsx)(tp,{open:l,onOpenChange:r,children:(0,le.jsxs)(ip,{className:"w-[400px] overflow-y-auto",children:[(0,le.jsx)(op,{children:(0,le.jsx)(dp,{children:c?"Edit ".concat(t.name):"Add New ".concat(t.name)})}),(0,le.jsx)("div",{className:"py-4",children:(0,le.jsx)(Mh,{schema:t,onSubmit:c?async e=>{try{await b[t.name].update(c.id,e),await _(),r(!1),d(null),n({title:"Success",description:"Item updated successfully"})}catch(w){var s,a;n({title:"Error",description:(null===(s=w.response)||void 0===s||null===(a=s.data)||void 0===a?void 0:a.message)||w.message,variant:"destructive"})}}:async e=>{try{await b[t.name].create(e),r(!1),await _(),n({title:"Success",description:"New item created successfully"})}catch(w){var s,a;n({title:"Error",description:(null===(s=w.response)||void 0===s||null===(a=s.data)||void 0===a?void 0:a.message)||w.message,variant:"destructive"})}},initialValues:c})})]})}),(0,le.jsx)(tp,{open:i,onOpenChange:o,children:(0,le.jsxs)(ip,{className:"w-[600px] overflow-y-auto",children:[(0,le.jsx)(op,{children:(0,le.jsx)(dp,{children:"Schema Editor"})}),(0,le.jsx)("div",{className:"py-4",children:(0,le.jsx)(xp,{entity:t})})]})})]})};var pp=s(2737);const gp=e=>{let{isVisible:t,onCancel:s,onInviteSuccess:a}=e;const{user:n}=oe(),{app:l}=Nt(),{toast:r}=ui(),[i,o]=(0,Y.useState)(""),[c,d]=(0,Y.useState)("user"),[m,u]=(0,Y.useState)(""),[x,h]=(0,Y.useState)(!1),[p,g]=(0,Y.useState)([]),f="free"===(null==n?void 0:n.subscription_tier),v=p.length>0?"https://".concat(p[0].domain):fa(l);(0,Y.useEffect)(()=>{(async()=>{if(t)try{const e=await Ya.filter({app_id:l.id});g(e)}catch(m){}})()},[t,l.id]);return(0,le.jsx)(Pa,{open:t,onOpenChange:s,children:(0,le.jsxs)(Da,{className:"sm:max-w-[520px] p-0 overflow-hidden",children:[(0,le.jsx)("div",{className:"bg-gradient-to-br from-slate-50 to-slate-100/50 px-6 py-8",children:(0,le.jsx)(Fa,{className:"space-y-3",children:(0,le.jsxs)("div",{className:"flex items-center gap-3",children:[(0,le.jsx)("div",{className:"p-2 bg-orange-100 rounded-xl",children:(0,le.jsx)(Wa.A,{className:"w-5 h-5 text-orange-600"})}),(0,le.jsxs)("div",{children:[(0,le.jsx)(za,{className:"text-2xl font-semibold text-slate-900",children:"Share Your App"}),(0,le.jsxs)(Ua,{className:"text-slate-600 mt-1",children:["Give others access to ",l.name]})]})]})})}),(0,le.jsxs)("div",{className:"px-6 pb-6 space-y-8",children:[(0,le.jsxs)("div",{className:"space-y-4",children:[(0,le.jsxs)("div",{className:"flex items-center gap-2 mb-3",children:[(0,le.jsx)(bn.A,{className:"w-4 h-4 text-slate-500"}),(0,le.jsx)("h3",{className:"font-medium text-slate-900",children:"Public Access"})]}),(0,le.jsxs)("div",{className:"bg-slate-50 rounded-xl p-4 border border-slate-200",children:[(0,le.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,le.jsx)("p",{className:"text-sm font-medium text-slate-700",children:"Share URL"}),(0,le.jsxs)(Yt,{variant:"ghost",size:"sm",onClick:()=>{navigator.clipboard.writeText(v),r({title:"URL Copied",description:"App URL has been copied to clipboard"})},className:"h-8 px-3 text-xs text-slate-600 hover:text-orange-600 hover:bg-orange-50",children:[(0,le.jsx)(or.A,{className:"h-3 w-3 mr-1.5"}),"Copy"]})]}),(0,le.jsx)(fs,{readOnly:!0,value:v,className:"bg-white border-slate-200 font-mono text-sm text-slate-600 focus:ring-orange-500 focus:border-orange-500"}),(0,le.jsx)("p",{className:"text-xs text-slate-500 mt-2",children:"Anyone with this link can access your app"})]})]}),(0,le.jsxs)("div",{className:"relative",children:[(0,le.jsx)("div",{className:"absolute inset-0 flex items-center",children:(0,le.jsx)(ps,{className:"w-full"})}),(0,le.jsx)("div",{className:"relative flex justify-center text-xs uppercase",children:(0,le.jsx)("span",{className:"bg-white px-3 text-slate-500 font-medium",children:"or"})})]}),(0,le.jsxs)("form",{onSubmit:async e=>{if(e.preventDefault(),u(""),i){h(!0);try{await ve.inviteUser(l.id,i,c),r({title:"Success",description:"Invitation sent successfully"}),a(),s()}catch(m){var t,n;const s=(null===(t=m.response)||void 0===t||null===(n=t.data)||void 0===n?void 0:n.detail)||m.message||"Failed to send invitation";u(s)}finally{h(!1)}}else u("Please enter an email address")},className:"space-y-6",children:[(0,le.jsxs)("div",{className:"space-y-4",children:[(0,le.jsxs)("div",{className:"flex items-center gap-2 mb-3",children:[(0,le.jsx)(Uh.A,{className:"w-4 h-4 text-slate-500"}),(0,le.jsx)("h3",{className:"font-medium text-slate-900",children:"Send Invitation"})]}),(0,le.jsxs)("div",{className:"space-y-4",children:[(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsx)(Ns,{htmlFor:"email",className:"text-sm font-medium text-slate-700",children:"Email address"}),(0,le.jsx)(fs,{id:"email",type:"email",placeholder:"colleague@company.com",value:i,onChange:e=>o(e.target.value),className:"h-11 border-slate-200 focus:ring-orange-500 focus:border-orange-500"})]}),(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsx)(Ns,{htmlFor:"role",className:"text-sm font-medium text-slate-700",children:"Access level"}),(0,le.jsxs)(zs,{value:c,onValueChange:d,children:[(0,le.jsx)(qs,{id:"role",className:"h-11 border-slate-200 focus:ring-orange-500 focus:border-orange-500",children:(0,le.jsx)(Ws,{placeholder:"Select access level"})}),(0,le.jsxs)(Ys,{children:[(0,le.jsx)($s,{value:"user",className:"py-3",children:(0,le.jsxs)("div",{className:"flex flex-col",children:[(0,le.jsx)("span",{className:"font-medium",children:"User"}),(0,le.jsx)("span",{className:"text-xs text-slate-500",children:"Can use the app"})]})}),(0,le.jsx)($s,{value:"admin",disabled:f,className:"py-3",children:(0,le.jsxs)("div",{className:"flex flex-col",children:[(0,le.jsx)("span",{className:"font-medium",children:"Admin"}),(0,le.jsxs)("span",{className:"text-xs text-slate-500",children:["Can manage users and settings ",f&&"\u2022 Paid plans only"]})]})})]})]}),f&&(0,le.jsxs)("div",{className:"flex items-start gap-3 mt-3 p-4 bg-gradient-to-r from-orange-50 to-orange-50/50 border border-orange-200 rounded-xl",children:[(0,le.jsx)("div",{className:"p-1 bg-orange-100 rounded-full",children:(0,le.jsx)(_e.A,{className:"h-3 w-3 text-orange-600"})}),(0,le.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,le.jsx)("p",{className:"text-sm text-orange-800 font-medium",children:"Admin access requires a paid plan"}),(0,le.jsx)(J.Link,{to:"/billing",className:"text-sm text-orange-600 hover:text-orange-700 font-medium hover:underline inline-flex items-center gap-1 mt-1",children:"Upgrade now \u2192"})]})]})]}),m&&(0,le.jsxs)("div",{className:"flex items-start gap-3 p-4 bg-red-50 border border-red-200 rounded-xl",children:[(0,le.jsx)("div",{className:"p-1 bg-red-100 rounded-full",children:(0,le.jsx)(_e.A,{className:"h-3 w-3 text-red-600"})}),(0,le.jsx)("p",{className:"text-sm text-red-800 font-medium",children:m})]})]})]}),(0,le.jsxs)(Ba,{className:"gap-3 pt-2",children:[(0,le.jsx)(Yt,{variant:"outline",type:"button",onClick:s,className:"h-11 px-6 border-slate-200 text-slate-700 hover:bg-slate-50",children:"Cancel"}),(0,le.jsx)(Yt,{type:"submit",disabled:x,className:"h-11 px-6 bg-orange-600 hover:bg-orange-700 text-white font-medium",children:x?(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)("div",{className:"w-4 h-4 border-2 border-white/30 border-t-white rounded-full animate-spin mr-2"}),"Sending..."]}):(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(pp.A,{className:"w-4 h-4 mr-2"}),"Send Invitation"]})})]})]})]})]})})};function fp(e){let{entity:t}=e;const{app:s,updateApp:a}=Nt();return(0,le.jsx)($h,{schema:t,onEdit:(e,n)=>{t.properties[e]=n,s.user_entity=t,a({user_entity:s.user_entity})}})}function vp(){const{app:e}=Nt(),{state:t,updateState:s,loadUsers:a,users:n,hasMore:l,isLoading:r}=(()=>{const[e,t]=(0,Y.useState)({isDrawerOpen:!1,isSchemaDrawerOpen:!1,isInviteModalOpen:!1,editingItem:null,currentPage:1}),{user:s}=oe(),a=Nt().getEntitiesSDK(),{data:{users:n,hasMore:l}={users:[],hasMore:!1},isLoading:r,error:i,refetch:o}=uu({query:async()=>{const t=50*(e.currentPage-1);let n=await a.User.list(null,51,t);const l=n.length>50;return null!=s&&s.email&&(s.email.endsWith("@base44.com")||s.email.endsWith("@wix.com"))||(n=n.filter(e=>!e.email.includes("@base44.com")&&!e.email.includes("@wix.com"))),{users:n.slice(0,50),hasMore:l}},toastError:"Failed to load users"},[e.currentPage]);return{state:e,updateState:e=>{t(t=>(0,K.A)((0,K.A)({},t),e))},loadUsers:o,users:n,hasMore:l,isLoading:r}})();return(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(up,{title:"Users",subtitle:"Manage users and their roles",primaryAction:(0,le.jsxs)(Yt,{size:"sm",onClick:()=>s({isInviteModalOpen:!0}),children:[(0,le.jsx)(kt.A,{className:"h-4 w-4"}),"Invite User"]}),actions:(0,le.jsxs)(Yt,{size:"sm",variant:"outline",onClick:()=>s({isSchemaDrawerOpen:!0}),children:[(0,le.jsx)(Ed.A,{className:"h-4 w-4 mr-2"}),"Schema"]}),children:(0,le.jsx)(bp,{state:t,updateState:s,loadUsers:a,users:n,hasMore:l,isLoading:r})}),(0,le.jsx)(gp,{isVisible:t.isInviteModalOpen,onCancel:()=>s({isInviteModalOpen:!1}),onInviteSuccess:()=>{s({currentPage:1}),a()}}),(0,le.jsx)(tp,{open:t.isSchemaDrawerOpen,onOpenChange:()=>s({isSchemaDrawerOpen:!1}),children:(0,le.jsxs)(ip,{className:"w-[600px] overflow-y-auto",children:[(0,le.jsx)(op,{children:(0,le.jsx)(dp,{children:"User Schema Editor"})}),(0,le.jsx)("div",{className:"py-4",children:(0,le.jsx)(fp,{entity:e.user_entity})})]})})]})}const bp=e=>{let{state:t,updateState:s,loadUsers:a,users:n,hasMore:l,isLoading:r}=e;const{app:i}=Nt(),{navigate:o}=(0,Z.Zp)(),{user:c}=oe(),d=Nt().getEntitiesSDK(),{toast:m}=nn(),{isDrawerOpen:u,editingItem:x,currentPage:h}=t;return(0,le.jsxs)("div",{className:"border rounded-md",children:[(0,le.jsx)("div",{className:"h-[600px] overflow-auto",children:(0,le.jsxs)(zl,{children:[(0,le.jsx)(Ul,{children:(0,le.jsxs)(Vl,{children:[Object.keys(i.user_entity.properties).map(e=>(0,le.jsx)(Hl,{className:"text-xs whitespace-nowrap",children:i.user_entity.properties[e].title||e},e)),(0,le.jsx)(Hl,{className:"text-xs",children:"Actions"})]})}),(0,le.jsx)(Wl,{children:r?(0,le.jsx)(Vl,{children:(0,le.jsxs)(Yl,{colSpan:Object.keys(i.user_entity.properties).length+1,className:"text-center py-4",children:[(0,le.jsx)(Ne.A,{className:"h-6 w-6 animate-spin mx-auto"}),(0,le.jsx)("p",{className:"text-sm text-muted-foreground mt-2",children:"Loading users..."})]})}):0===n.length?(0,le.jsx)(Vl,{children:(0,le.jsxs)(Yl,{colSpan:Object.keys(i.user_entity.properties).length+1,className:"text-center py-8",children:[(0,le.jsx)("p",{className:"text-sm text-muted-foreground",children:"No users found"}),(0,le.jsxs)(Yt,{variant:"outline",size:"sm",className:"mt-2",onClick:()=>s({isInviteModalOpen:!0}),children:[(0,le.jsx)(kt.A,{className:"h-4 w-4 mr-2"}),"Invite your first user"]})]})}):n.map(e=>(0,le.jsxs)(Vl,{className:"cursor-pointer hover:bg-muted/50",onClick:()=>{s({editingItem:e,isDrawerOpen:!0})},children:[Object.keys(i.user_entity.properties).map(t=>{var s;return(0,le.jsx)(Yl,{className:"text-xs whitespace-nowrap overflow-hidden text-ellipsis",style:{maxWidth:"200px"},children:"object"==typeof e[t]?JSON.stringify(e[t]):String(null!==(s=e[t])&&void 0!==s?s:"")},t)}),(0,le.jsx)(Yl,{className:"whitespace-nowrap",children:(0,le.jsx)("div",{className:"flex gap-1",children:(0,le.jsx)(Yt,{size:"xs",variant:"ghost",onClick:t=>{t.stopPropagation(),(async e=>{try{await d.User.delete(e.id),await a(),m({title:"Success",description:"User removed successfully"})}catch(n){var t,s;m({title:"Error",description:(null===(t=n.response)||void 0===t||null===(s=t.data)||void 0===s?void 0:s.message)||n.message,variant:"destructive"})}})(e)},className:"text-red-500 hover:text-red-600",children:(0,le.jsx)($x.A,{className:"h-3 w-3"})})})})]},e.id))})]})}),(0,le.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-t",children:[(0,le.jsxs)("div",{className:"text-sm text-muted-foreground",children:["Page ",h]}),(0,le.jsxs)("div",{className:"flex gap-2",children:[(0,le.jsxs)(Yt,{size:"sm",variant:"outline",onClick:()=>s({currentPage:h-1}),disabled:1===h||r,children:[(0,le.jsx)(Xs.A,{className:"h-4 w-4 mr-1"}),"Previous"]}),(0,le.jsxs)(Yt,{size:"sm",variant:"outline",onClick:()=>s({currentPage:h+1}),disabled:!l||r,children:["Next",(0,le.jsx)(rn.A,{className:"h-4 w-4 ml-1"})]})]})]}),(0,le.jsx)(tp,{open:u,onOpenChange:()=>s({isDrawerOpen:!1}),children:(0,le.jsxs)(ip,{className:"w-[400px] overflow-y-auto",children:[(0,le.jsx)(op,{children:(0,le.jsx)(dp,{children:"Edit User"})}),(0,le.jsx)("div",{className:"py-4",children:(0,le.jsx)(Mh,{schema:i.user_entity,onSubmit:async e=>{try{if("admin"===e.role&&"admin"!==x.role&&"free"===c.subscription_tier)return void m({title:"Subscription Required",description:(0,le.jsxs)("div",{children:["Only paying users can make other users admins.",(0,le.jsx)(Yt,{variant:"link",className:"p-0 h-auto font-semibold underline",onClick:()=>o("/billing"),children:"Upgrade your subscription"}),"to continue."]}),variant:"destructive"});await d.User.update(x.id,e),await a(),s({isDrawerOpen:!1,editingItem:null}),m({title:"Success",description:"User updated successfully"})}catch(l){var t,n;m({title:"Error",description:(null===(t=l.response)||void 0===t||null===(n=t.data)||void 0===n?void 0:n.message)||l.message,variant:"destructive"})}},initialValues:x,uiSchema:{email:{"ui:widget":"hidden"},full_name:{"ui:widget":"hidden"}}})})]})})]})},jp=["className"],yp=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,jp);return(0,le.jsx)("textarea",(0,K.A)({className:Pe("flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",s),ref:t},a))});yp.displayName="Textarea";const Np=["className"],wp=["className"],_p=["className"],kp=yr.bL,Cp=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,Np);return(0,le.jsx)(yr.B8,(0,K.A)({ref:t,className:Pe("inline-flex h-10 items-center justify-center rounded-md bg-muted p-1 text-muted-foreground",s)},a))});Cp.displayName=yr.B8.displayName;const Ap=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,wp);return(0,le.jsx)(yr.l9,(0,K.A)({ref:t,className:Pe("inline-flex items-center justify-center whitespace-nowrap rounded-sm px-3 py-1.5 text-sm font-medium ring-offset-background transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow-sm",s)},a))});Ap.displayName=yr.l9.displayName;const Sp=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,_p);return(0,le.jsx)(yr.UC,(0,K.A)({ref:t,className:Pe("mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",s)},a))});Sp.displayName=yr.UC.displayName;const Ep=(e,t)=>{var s;const{toast:a}=nn(),[n,l]=(0,Y.useState)(!1),[r,i]=(0,Y.useState)(null!==(s=null==t?void 0:t.initialResult)&&void 0!==s?s:null),[o,c]=(0,Y.useState)(null),d="string"==typeof(null==t?void 0:t.toastSuccess)?{title:"Success",description:t.toastSuccess}:null==t?void 0:t.toastSuccess,m="string"==typeof(null==t?void 0:t.toastError)?{title:"Error",description:t.toastError}:null==t?void 0:t.toastError;return{isLoading:n,update:async function(){l(!0);try{const s=await e(...arguments);return(null==t?void 0:t.toastSuccess)&&a(d),i(s),s}catch(o){(null==t?void 0:t.toastError)&&a((0,K.A)((0,K.A)({},m),{},{variant:"destructive"})),c(o)}finally{l(!1)}},result:r,error:o}};var Ip=s(84814),Tp=s(35254),Pp=s.n(Tp);s(17687);const Lp=(0,Y.createContext)(),Op=e=>{let{children:t}=e;const{appId:s}=(0,Z.g)(),[a,n]=(0,Y.useState)(null),[l,r]=(0,Y.useState)(null),[i,o]=(0,Y.useState)(!0),[c,d]=(0,Y.useState)(null),m=async()=>{if(s){o(!0);try{const e=await ve.get(s);n(e);try{const e=await $a.getListingIfExists(s);r(e)}catch(t){r(null)}}catch(t){var e;d(t),403===(null==t||null===(e=t.response)||void 0===e?void 0:e.status)&&d(new Error("You do not have access to this app"))}finally{o(!1)}}};(0,Y.useEffect)(()=>{m()},[s]);const u={app:a,listing:l,isLoading:i,error:c,hasListing:!(null==l||!l.id||null!=l&&l.archived),createOrUpdateListing:async e=>{if(null!=l&&l.id){const t=await $a.update(l.id,e);return r(t),t}{const t=await $a.create((0,K.A)((0,K.A)({},e),{},{app_id:s}));return r(t),t}},refetch:()=>{m()}};return(0,le.jsx)(Lp.Provider,{value:u,children:t})},Rp=()=>{const e=(0,Y.useContext)(Lp);if(!e)throw new Error("useAppListing must be used within an AppListingProvider");return e},Mp=["timestamp"],Dp=["Marketing & Sales","Operations","Data & Analytics","Content Generation","HR & Legal","Finance","Education","Community","Lifestyle & Hobbies","Games & Entertainment"],Fp=e=>e&&Array.isArray(e)?e.filter(e=>Dp.includes(e)):[],Bp=(e,t)=>"app_listing_autosave_".concat(e,"_").concat(t||"new"),zp=(e,t)=>{try{const s=Bp(e,t),a=localStorage.getItem(s);if(a){const e=JSON.parse(a);if(Date.now()-e.timestamp<6048e5){const{timestamp:t}=e;return(0,Se.A)(e,Mp)}}return null}catch(s){return null}};function Up(e){let{listingId:t,listing:s,onSave:a,onRouteChange:n,app:l}=e;const r=(0,Y.useRef)(null),[i,o]=(0,Y.useState)(s||null),[c,d]=(0,Y.useState)(!1),[m,u]=(0,Y.useState)(null),[x,h]=(0,Y.useState)(!1),[p,g]=(0,Y.useState)(!1),[f,v]=(0,Y.useState)(!1),[b,j]=(0,Y.useState)(null),[y,N]=(0,Y.useState)(null),[w,_]=(0,Y.useState)(!1),[k,C]=(0,Y.useState)(!1),[A,S]=(0,Y.useState)(null),[E,I]=(0,Y.useState)(!1),T=(0,Y.useRef)(null),P=(0,Y.useRef)(null),[L,O]=(0,Y.useState)({name:"",description:"",screenshot_urls:[],categories:[],is_private:!1}),R=(0,Y.useCallback)(e=>{null!=l&&l.id&&(C(!0),((e,t,s)=>{try{const a=Bp(e,t),n=(0,K.A)((0,K.A)({},s),{},{timestamp:Date.now()});localStorage.setItem(a,JSON.stringify(n))}catch(m){}})(l.id,t,e),S(new Date),setTimeout(()=>C(!1),500))},[null==l?void 0:l.id,t]),M=(0,Y.useCallback)(e=>{T.current&&clearTimeout(T.current),T.current=setTimeout(()=>{R(e)},1e3)},[R]);(0,Y.useEffect)(()=>{if(t&&!s)(async()=>{try{d(!0);const e=await $a.get(t);o(e);const s=null!=l&&l.id?zp(l.id,t):null;if(s){if(O((0,K.A)((0,K.A)({},s),{},{categories:Fp(s.categories||[])})),v(!0),!E){I(!0);const e=an({title:"Draft Restored",description:"Your unsaved changes have been restored from a previous session",variant:"default"});P.current=e}}else O({name:e.name||"",description:dn(e.description||""),screenshot_urls:e.screenshot_urls||[],categories:Fp(e.categories||[]),is_private:e.is_private||!1})}catch(e){u(e),an({title:"Error",description:"Failed to load listing",variant:"destructive"})}finally{d(!1)}})();else if(s){const e=null!=l&&l.id?zp(l.id,t):null;if(e){if(O((0,K.A)((0,K.A)({},e),{},{categories:Fp(e.categories||[])})),v(!0),!E){I(!0);const e=an({title:"Draft Restored",description:"Your unsaved changes have been restored from a previous session",variant:"default"});P.current=e}}else O({name:s.name||"",description:dn(s.description||""),screenshot_urls:s.screenshot_urls||[],categories:Fp(s.categories||[]),is_private:s.is_private||!1,archived:!1})}},[t,s,null==l?void 0:l.id,E]),(0,Y.useEffect)(()=>{r.current&&r.current.scrollIntoView({behavior:"smooth",block:"start"})},[]),(0,Y.useEffect)(()=>()=>{T.current&&clearTimeout(T.current),P.current&&P.current.dismiss()},[]);const D=(e,t)=>{const s="description"===e?dn(t):t;O(t=>{const a=(0,K.A)((0,K.A)({},t),{},{[e]:s});return M(a),a}),v(!0)},F=async()=>{h(!0),_(!1),P.current&&(P.current.dismiss(),P.current=null);try{let e;if(a)e=await a(L);else{if(!(null!=i&&i.id||t))throw new Error("No save handler provided for new listing");e=await $a.update((null==i?void 0:i.id)||t,L)}o(e),v(!1),null!=l&&l.id&&((e,t)=>{try{const s=Bp(e,t);localStorage.removeItem(s)}catch(m){}})(l.id,t),n("main"),an({title:"Success",description:null!=i&&i.id?"Listing updated successfully":"Listing created successfully"})}catch(m){an({title:"Error",description:m.message||"Failed to save listing",variant:"destructive"})}finally{h(!1)}},B=(0,Y.useCallback)(async e=>{if(L.screenshot_urls.length>7)return void an({title:"Error",description:"Maximum of 7 screenshots allowed",variant:"destructive"});if(["image/jpeg","image/jpg","image/png","image/webp"].includes(e.type))if(e.size>5242880)an({title:"Error",description:"Image size must be less than 5MB",variant:"destructive"});else{g(!0);try{const t=await _t.uploadAppFile(e,l.id),s=t.url||t.file_url||t;O(e=>{const t=(0,K.A)((0,K.A)({},e),{},{screenshot_urls:[...e.screenshot_urls,s]});return M(t),v(!0),t}),an({title:"Success",description:"Screenshot uploaded successfully"})}catch(m){an({title:"Error",description:"Failed to upload screenshot",variant:"destructive"})}finally{g(!1)}}else an({title:"Error",description:"Only JPEG, JPG, and PNG files are allowed",variant:"destructive"})},[L.screenshot_urls.length,M]);(0,Y.useEffect)(()=>{const e=async e=>{var t;const s=null===(t=e.clipboardData)||void 0===t?void 0:t.items;if(s)for(const a of s)if(-1!==a.type.indexOf("image")){e.preventDefault();const t=a.getAsFile();t&&await B(t)}};return document.addEventListener("paste",e),()=>document.removeEventListener("paste",e)},[B]);const z=()=>{N(null)},U=(e,t)=>{e.preventDefault(),null!==b&&b!==t&&((e,t)=>{const s=[...L.screenshot_urls],[a]=s.splice(e,1);s.splice(t,0,a),D("screenshot_urls",s)})(b,t),j(null),N(null)},W=()=>{j(null),N(null)};if(c)return(0,le.jsx)("div",{className:"flex items-center justify-center min-h-[400px]",children:(0,le.jsx)("div",{className:"text-muted-foreground",children:"Loading listing..."})});if(m)return(0,le.jsx)("div",{className:"flex items-center justify-center min-h-[400px]",children:(0,le.jsxs)("div",{className:"text-red-600",children:["Error: ",m.message]})});const q=!(null!=i&&i.id||t);return(0,le.jsxs)("div",{ref:r,className:"w-full",children:[(0,le.jsxs)("div",{className:"sticky top-0 z-10 bg-slate-50 py-4 mb-4",children:[(0,le.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground mb-4",children:[(0,le.jsx)("button",{onClick:()=>n("main"),className:"hover:text-foreground hover:underline transition-colors cursor-pointer",children:"App Settings"}),(0,le.jsx)("span",{children:"/"}),(0,le.jsx)("span",{className:"transition-colors",children:"App Templates Listing"})]}),(0,le.jsxs)("div",{className:"flex flex-col sm:flex-row sm:justify-between sm:items-start gap-4 w-full",children:[(0,le.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,le.jsx)("h2",{className:"text-xl sm:text-2xl font-semibold text-gray-800 truncate",children:q?"Create Listing":"Manage Listing"}),(0,le.jsx)("div",{className:"flex items-center gap-3 mt-1",children:(0,le.jsx)("p",{className:"text-muted-foreground text-sm sm:text-base",children:q?"Create your app's template listing":"Update your app's template listing"})})]}),(0,le.jsx)("div",{className:"flex-shrink-0",children:(0,le.jsxs)("div",{className:"flex items-center gap-2 sm:gap-3",children:[(0,le.jsx)(Yt,{onClick:()=>n("main"),variant:"outline",className:"border-gray-200 hover:bg-gray-50 hover:text-gray-700 h-8 px-2 sm:px-3 py-1 text-sm",children:"Cancel"}),(0,le.jsx)(Yt,{onClick:async()=>{q||"approved"!==(null==i?void 0:i.status)&&"rejected"!==(null==i?void 0:i.status)?await F():_(!0)},disabled:!f&&!q&&!(null!=i&&i.archived)||x||0===L.screenshot_urls.length||0===L.categories.length,className:"bg-gray-900 hover:bg-gray-500 text-white h-8 px-2 sm:px-3 py-1 text-sm whitespace-nowrap",children:x?"Saving...":q?"Create Listing":"Update Listing"})]})})]})]}),(0,le.jsx)("style",{dangerouslySetInnerHTML:{__html:"\n .prose-editor .quill {\n border: 1px solid hsl(var(--border));\n border-radius: calc(var(--radius) - 2px);\n background: hsl(var(--background));\n width: 100%;\n max-width: 100%;\n overflow: hidden;\n }\n .prose-editor .ql-toolbar {\n border: none;\n border-bottom: 1px solid hsl(var(--border));\n background: hsl(var(--muted) / 0.3);\n border-radius: calc(var(--radius) - 2px) calc(var(--radius) - 2px) 0 0;\n flex-wrap: wrap;\n }\n .prose-editor .ql-container {\n border: none;\n font-family: inherit;\n width: 100%;\n max-width: 100%;\n }\n .prose-editor .ql-editor {\n min-height: 150px;\n font-size: 0.875rem;\n line-height: 1.5rem;\n width: 100%;\n max-width: 100%;\n word-wrap: break-word;\n overflow-wrap: break-word;\n }\n .prose-editor .ql-editor.ql-blank::before {\n color: hsl(var(--muted-foreground));\n font-style: normal;\n }\n .prose-editor .ql-editor p {\n margin-bottom: 0.75rem;\n }\n .prose-editor .ql-editor p:last-child {\n margin-bottom: 0;\n }\n .prose-editor .ql-toolbar button:hover {\n background: hsl(var(--accent));\n }\n .prose-editor .ql-toolbar button.ql-active {\n background: hsl(var(--accent));\n color: hsl(var(--accent-foreground));\n }\n"}}),(0,le.jsxs)("div",{className:"space-y-4 w-full max-w-full overflow-hidden",children:[(0,le.jsxs)(is,{className:"border-none rounded-[12px]",children:[(0,le.jsx)(os,{className:"py-4 px-6",children:(0,le.jsx)(cs,{className:"text-sm font-medium",children:"App Info"})}),(0,le.jsx)(ps,{}),(0,le.jsxs)(ms,{className:"space-y-6 pt-6",children:[(0,le.jsxs)("div",{className:"space-y-1",children:[(0,le.jsxs)(Ns,{htmlFor:"name",className:"text-sm font-medium",children:["App Name",(0,le.jsx)("span",{className:"text-red-500",children:"*"})]}),(0,le.jsx)(fs,{id:"name",value:L.name,onChange:e=>D("name",e.target.value),placeholder:"Enter your app name",className:"max-w-md"})]}),(0,le.jsxs)("div",{className:"space-y-1",children:[(0,le.jsxs)(Ns,{htmlFor:"description",className:"text-sm font-medium",children:["App Description",(0,le.jsx)("span",{className:"text-red-500",children:"*"})]}),(0,le.jsx)("p",{className:"text-sm text-muted-foreground",children:"Tell users what makes your app worth trying."}),(0,le.jsx)("div",{className:"prose-editor w-full max-w-full pt-2",children:(0,le.jsx)(Pp(),{theme:"snow",value:L.description,onChange:e=>D("description",e),placeholder:"Describe what your app does...",modules:{toolbar:[[{header:[1,2,3,!1]}],["bold","italic","underline","strike"],[{list:"ordered"},{list:"bullet"}],["blockquote","code-block"],["link"],["clean"]]},className:"bg-white rounded-md w-full",style:{minHeight:"150px",maxWidth:"100%"}})})]}),(0,le.jsxs)("div",{className:"space-y-1",children:[(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[(0,le.jsxs)(Ns,{children:["Categories",(0,le.jsx)("span",{className:"text-red-500",children:"*"})]}),(0,le.jsxs)("span",{className:"text-sm text-muted-foreground",children:["(",L.categories.length," selected)"]})]}),(0,le.jsx)("p",{className:"text-sm text-muted-foreground",children:"Select categories that best describe your app to help users discover it"}),(0,le.jsx)("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-x-3 gap-y-2 py-3",children:Dp.map(e=>(0,le.jsxs)("div",{className:"flex items-center space-x-2 min-w-0",children:[(0,le.jsx)(dm,{id:"category-".concat(e),checked:L.categories.includes(e),onCheckedChange:()=>(e=>{O(t=>{const s=t.categories.includes(e)?t.categories.filter(t=>t!==e):[...t.categories,e],a=(0,K.A)((0,K.A)({},t),{},{categories:s});return M(a),v(!0),a})})(e),className:"flex-shrink-0 shadow-sm border-slate-200"}),(0,le.jsx)(Ns,{htmlFor:"category-".concat(e),className:"text-sm font-normal cursor-pointer truncate",children:e})]},e))}),0===L.categories.length&&(0,le.jsx)("p",{className:"text-sm text-orange-600",children:"At least one category is required"})]}),(0,le.jsxs)("div",{className:"space-y-4",children:[(0,le.jsxs)("div",{className:"flex items-center justify-between",children:[(0,le.jsxs)("div",{children:[(0,le.jsxs)(Ns,{children:["Screenshots",(0,le.jsx)("span",{className:"text-red-500",children:"*"})]}),(0,le.jsx)("p",{className:"text-sm text-muted-foreground mt-1",children:"Add screenshots to your listing to help users understand what your app does (JPG, PNG, WEBP, 5MB max)"})]}),(null==l?void 0:l.slug)&&(0,le.jsxs)(Yt,{variant:"outline",size:"sm",onClick:()=>window.open(null!=l&&l.slug?"localhost"===window.location.hostname?"http://".concat(l.slug,".localhost:3000"):window.location.hostname.includes("base44.io")||window.location.hostname.includes("beta-base44")?"https://".concat(l.slug,".base44.io"):window.location.hostname.includes("ba11.me")?"https://".concat(l.slug,".ba11.me"):window.location.hostname.includes("ba22.me")?"https://".concat(l.slug,".ba22.me"):window.location.hostname.includes("ba33.me")?"https://".concat(l.slug,".ba33.me"):"https://".concat(l.slug,".base44.app"):"","_blank"),className:"flex items-center gap-2 border-gray-200 hover:bg-gray-50 hover:text-gray-700 h-7",children:[(0,le.jsx)("span",{children:"Preview App"}),(0,le.jsx)(Tr.A,{className:"w-3 h-3"})]})]}),(0,le.jsxs)("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4",children:[L.screenshot_urls.map((e,t)=>(0,le.jsxs)("div",{className:"relative group cursor-move min-w-0 ".concat(b===t?"opacity-50":""," ").concat(y===t?"ring-2 ring-orange-400 ring-offset-2":""),draggable:!0,onDragStart:e=>((e,t)=>{j(t),e.dataTransfer.effectAllowed="move",e.dataTransfer.setData("text/html",e.target.outerHTML),e.dataTransfer.setDragImage(e.target,e.target.offsetWidth/2,e.target.offsetHeight/2)})(e,t),onDragOver:e=>((e,t)=>{e.preventDefault(),e.dataTransfer.dropEffect="move",N(t)})(e,t),onDragLeave:z,onDrop:e=>U(e,t),onDragEnd:W,children:[0===t&&(0,le.jsx)("div",{className:"absolute top-2 left-2 z-10 bg-orange-500 text-white text-xs px-2 py-1 rounded font-medium shadow-sm",children:"Primary"}),(0,le.jsx)("img",{src:e,alt:"Screenshot ".concat(t+1),className:"w-full h-32 object-cover rounded-lg border shadow-sm",onError:e=>{e.target.src="/placeholder.png",e.target.onerror=null}}),(0,le.jsx)("div",{className:"absolute inset-0 opacity-0 group-hover:opacity-100 transition-opacity rounded-lg",children:(0,le.jsx)(Yt,{size:"sm",variant:"destructive",onClick:()=>(e=>{const t=L.screenshot_urls.filter((t,s)=>s!==e);D("screenshot_urls",t)})(t),className:"absolute bottom-2 right-2 h-8 w-8 p-0 bg-red-500 hover:bg-red-600 text-white shadow-lg",children:(0,le.jsx)(Ip.A,{className:"h-4 w-4"})})}),(0,le.jsx)("div",{className:"absolute top-2 right-2 opacity-0 group-hover:opacity-90 transition-opacity",children:(0,le.jsx)("div",{className:"text-white text-xs bg-black/70 px-2 py-1 rounded",children:"Drag to reorder"})})]},t)),(0,le.jsxs)("div",{className:"relative",children:[(0,le.jsx)(fs,{type:"file",accept:".jpg,.jpeg,.png,image/jpeg,image/png",multiple:!0,onChange:async e=>{const t=e.target.files;if(t&&0!==t.length)for(const s of t)await B(s)},className:"absolute inset-0 w-full h-full opacity-0 cursor-pointer",disabled:p||L.screenshot_urls.length>=7}),(0,le.jsx)("div",{className:"w-full h-32 rounded-lg border-2 border-dashed border-gray-300 flex flex-col items-center justify-center transition-colors ".concat(L.screenshot_urls.length>=7?"bg-gray-100 cursor-not-allowed":"bg-gray-50 hover:bg-gray-100 cursor-pointer"),children:p?(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(nx.A,{className:"w-6 h-6 text-gray-400 animate-spin mb-2"}),(0,le.jsx)("span",{className:"text-sm text-gray-500",children:"Uploading..."})]}):L.screenshot_urls.length>=7?(0,le.jsx)(le.Fragment,{children:(0,le.jsx)("span",{className:"text-sm text-gray-500",children:"Maximum screenshots reached (7)"})}):(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(kt.A,{className:"w-6 h-6 text-gray-400 mb-2"}),(0,le.jsx)("span",{className:"text-sm text-gray-500",children:"Add Screenshot"})]})})]})]}),(0,le.jsx)("div",{className:"rounded-lg bg-slate-50 p-3 flex items-center gap-2",children:(0,le.jsx)("p",{className:"text-sm text-slate-600",children:"Tip: You can paste screenshots directly from your clipboard (Ctrl/Cmd + V) or drag and drop images to reorder them"})}),0===L.screenshot_urls.length&&(0,le.jsx)("p",{className:"text-sm text-orange-600",children:"At least one screenshot is required for your listing"})]})]})]}),(0,le.jsxs)(is,{className:"border-none rounded-[12px]",children:[(0,le.jsx)(os,{className:"py-4 px-6",children:(0,le.jsx)(cs,{className:"text-sm font-medium",children:"Settings"})}),(0,le.jsx)(ps,{className:"mb-4"}),(0,le.jsx)(ms,{className:"space-y-6",children:(0,le.jsxs)("div",{className:"flex items-center justify-between",children:[(0,le.jsxs)("div",{className:"space-y-1",children:[(0,le.jsx)(Ns,{htmlFor:"is_private",className:"text-sm font-medium",children:"Visible to Everyone"}),(0,le.jsx)("p",{className:"text-sm text-regular text-muted-foreground",children:"Make your listing public and discoverable by others"})]}),(0,le.jsx)(ix,{id:"is_private",checked:!L.is_private,onCheckedChange:e=>D("is_private",!e)})]})})]})]}),(0,le.jsx)(Pa,{open:w,onOpenChange:_,children:(0,le.jsxs)(Da,{className:"sm:max-w-md",children:[(0,le.jsxs)(Fa,{children:[(0,le.jsx)(za,{children:"Attention"}),(0,le.jsx)(Ua,{children:"approved"===(null==i?void 0:i.status)?"Making changes to your app will require re-approval before it appears in the catalog again":"rejected"===(null==i?void 0:i.status)?"Your app will be reviewed again for approval":""})]}),(0,le.jsxs)(Ba,{className:"flex gap-2",children:[(0,le.jsx)(Yt,{variant:"outline",onClick:()=>_(!1),disabled:x,children:"Cancel"}),(0,le.jsx)(Yt,{onClick:F,disabled:x,className:"bg-gray-900 hover:bg-gray-500 text-white",children:x?"Saving...":"Continue"})]})]})})]})}function Wp(e){let{onRouteChange:t}=e;const{app:s,listing:a,isLoading:n,error:l,createOrUpdateListing:r}=Rp();return n?(0,le.jsx)("div",{className:"p-6",children:"Loading..."}):l?(0,le.jsxs)("div",{className:"p-6 text-red-600",children:["Error: ",l.message]}):(0,le.jsx)(Up,{listingId:null==a?void 0:a.id,onRouteChange:t,onSave:r,app:s,listing:a||{name:(null==s?void 0:s.name)||"",description:dn((null==s?void 0:s.user_description)||"

"),screenshot_urls:[],categories:Fp((null==s?void 0:s.categories)||[]),is_private:!1}})}var qp=s(85354);function Vp(){const{app:e}=Nt(),{user:t}=oe(),{workspaces:s}=ge(),[a,n]=(0,Y.useState)(!1),[l,r]=(0,Y.useState)(!0);return(0,Y.useEffect)(()=>{(()=>{if(!e.organization_id||!s||!t)return n(!1),void r(!1);const a=s.find(t=>t.id===e.organization_id);if(!a)return n(!1),void r(!1);const l=!a.is_personal&&a.id!==t.personal_organization_id;n(l),r(!1)})()},[e.organization_id,s,t]),{isInSharedWorkspace:a,isLoading:l}}class Hp extends Q.H{getBaseURL(){return"/workspace"}getAppSettings(e){return this.axios.get("/".concat(e,"/app-settings"))}updateAppSettings(e,t){return this.axios.put("/".concat(e,"/app-settings"),t)}}const Yp=new Hp;function Gp(){const{app:e}=Nt(),{user:t}=oe(),{workspaces:s}=ge(),[a,n]=(0,Y.useState)(null),[l,r]=(0,Y.useState)(!0),[i,o]=(0,Y.useState)(null),[c,d]=(0,Y.useState)(null);(0,Y.useEffect)(()=>{(async()=>{if(null==e||!e.organization_id||!s||!t)return n(null),o(null),d(null),void r(!1);const a=s.find(t=>t.id===e.organization_id);if(!a)return n(null),o(null),d(null),void r(!1);o(a);const l=a.user_role||a.role||"member";if(d(l),a.is_personal||a.id===t.personal_organization_id)n(null);else try{const t=await Yp.getAppSettings(e.organization_id);n((null==t?void 0:t.settings)||null)}catch(i){n(null)}r(!1)})()},[null==e?void 0:e.organization_id,s,t]);return{settings:a,workspace:i,userRole:c,isLoading:l,isEnterpriseWorkspace:null!==i&&!0===i.is_enterprise}}function $p(e,t,s,a){if("admin"===s||"owner"===s)return["private_with_login","workspace_with_login","public_with_login","public_without_login"];if(!a||!t)return["private_with_login","workspace_with_login","public_with_login","public_without_login"];const n=["private_with_login","workspace_with_login","public_with_login","public_without_login"];return t.members_can_create_public_apps?n:n.filter(e=>"public_with_login"!==e&&"public_without_login"!==e)}const Jp=["className","children"],Zp=Y.forwardRef((e,t)=>{let{className:s,children:a}=e,n=(0,Se.A)(e,Jp);return(0,le.jsx)(Es.q7,(0,K.A)((0,K.A)({ref:t,className:Pe("relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-3 pr-2 text-sm outline-none focus:bg-slate-100 focus:text-slate-900 data-[disabled]:pointer-events-none data-[disabled]:opacity-50",s)},n),{},{children:(0,le.jsx)(Es.p4,{children:a})}))});Zp.displayName="SelectItemNoCheck";const Kp=e=>{let{options:t=[],value:s,onValueChange:a,placeholder:n="Select option",disabled:l=!1,className:r}=e;const i=t.find(e=>e.value===s);return(0,le.jsxs)(In,{value:s,onValueChange:a,disabled:l,children:[(0,le.jsx)(Pn,{className:Pe("w-full h-10 px-3 py-2 text-sm","border border-slate-200 rounded-md","bg-white","hover:border-slate-300","focus:border-slate-400 focus:ring-1 focus:ring-slate-400","disabled:bg-slate-50 disabled:text-slate-400 disabled:cursor-not-allowed","transition-colors duration-200",r),children:(0,le.jsx)(Tn,{children:i?(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[i.icon&&(0,le.jsx)(i.icon,{className:"w-4 h-4 flex-shrink-0 text-slate-500"}),(0,le.jsx)("span",{className:"truncate text-sm font-medium text-slate-900",children:i.label})]}):(0,le.jsx)("span",{className:"text-slate-400 text-sm",children:n})})}),(0,le.jsx)(Rn,{className:"bg-white border border-slate-200 rounded-md shadow-lg",children:t.map(e=>(0,le.jsx)(Zp,{value:e.value,className:Pe("py-2 cursor-pointer","hover:bg-slate-50 focus:bg-slate-50","data-[state=checked]:bg-slate-100"),children:(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[e.icon&&(0,le.jsx)(e.icon,{className:"w-4 h-4 flex-shrink-0 text-slate-500"}),(0,le.jsx)("span",{className:"text-sm font-medium text-slate-900",children:e.label})]})},e.value))})]})},Qp=["className"],Xp=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,Qp);return(0,le.jsx)(om.bL,(0,K.A)((0,K.A)({ref:t,className:Pe("peer h-4 w-4 shrink-0 rounded-sm border border-primary ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",s)},a),{},{children:(0,le.jsx)(om.C1,{className:Pe("flex items-center justify-center text-current"),children:(0,le.jsx)(Ps.A,{className:"h-4 w-4"})})}))});Xp.displayName=om.bL.displayName;const eg=e=>{let{checked:t,onCheckedChange:s,label:a,disabled:n=!1,className:l,checkboxClassName:r,labelClassName:i}=e;return(0,le.jsxs)("div",{className:Pe("flex items-center space-x-2",!n&&"hover:opacity-70 cursor-pointer",n&&"cursor-not-allowed","transition-opacity duration-200",l),onClick:()=>{!n&&s&&s(!t)},children:[(0,le.jsx)(Xp,{checked:t,onCheckedChange:()=>{},disabled:n,className:Pe("h-4 w-4","border-slate-300 rounded-sm","data-[state=checked]:bg-slate-900 data-[state=checked]:border-slate-900","data-[state=checked]:text-white","focus-visible:ring-2 focus-visible:ring-slate-400 focus-visible:ring-offset-2","disabled:opacity-50","transition-colors duration-200","pointer-events-none",r)}),(0,le.jsx)(go,{className:Pe("text-sm text-slate-700","font-normal","select-none","peer-disabled:opacity-50","pointer-events-none",i),children:a})]})},tg=e=>[{value:"private",label:"Private",icon:Mt.A},...e?[{value:"workspace",label:"Workspace",icon:Xl.A}]:[],{value:"public",label:"Public",icon:bn.A}];function sg(e,t){return"private"===e?"private_with_login":"workspace"===e?"workspace_with_login":"public"===e?t?"public_with_login":"public_without_login":"private_with_login"}function ag(e){let{value:t,onValueChange:s,disabled:a=!1,showWorkspace:n=!0,className:l,allowedOptions:r}=e;const i=function(e){switch(e){case"private_with_login":default:return"private";case"workspace_with_login":return"workspace";case"public_with_login":case"public_without_login":return"public"}}(t),o="public_without_login"!==t;let c=tg(n);if(r&&r.length>0){const e=new Set;r.includes("public_without_login"),r.includes("public_with_login");r.some(e=>e.startsWith("private"))&&e.add("private"),r.some(e=>e.startsWith("workspace"))&&e.add("workspace"),r.some(e=>e.startsWith("public"))&&e.add("public"),c=c.filter(t=>e.has(t.value)),e.has("public")}const d=a||"public"!==i||r&&"public"===i&&!r.includes("public_without_login");return(0,le.jsxs)("div",{className:Pe("space-y-2",l),children:[(0,le.jsx)(Kp,{options:c,value:i,onValueChange:e=>{let t=!0;"public"===e&&(t=!(!r||r.includes("public_without_login"))||o);const a=sg(e,t);s(a)},disabled:a,placeholder:"Select visibility"}),(0,le.jsx)(eg,{checked:o,onCheckedChange:e=>{if("public"===i){if(!e&&r&&!r.includes("public_without_login"))return;const t=sg(i,e);s(t)}},disabled:d,label:"Require login to access"})]})}const ng=["className","variant"],lg=["className"],rg=["className"],ig=(0,Ee.cva)("relative w-full rounded-lg border p-4 [&>svg~*]:pl-7 [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-foreground",{variants:{variant:{default:"bg-background text-foreground",destructive:"border-destructive/50 text-destructive dark:border-destructive [&>svg]:text-destructive"}},defaultVariants:{variant:"default"}}),og=Y.forwardRef((e,t)=>{let{className:s,variant:a}=e,n=(0,Se.A)(e,ng);return(0,le.jsx)("div",(0,K.A)({ref:t,role:"alert",className:Pe(ig({variant:a}),s)},n))});og.displayName="Alert";const cg=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,lg);return(0,le.jsx)("h5",(0,K.A)({ref:t,className:Pe("mb-1 font-medium leading-none tracking-tight",s)},a))});cg.displayName="AlertTitle";const dg=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,rg);return(0,le.jsx)("div",(0,K.A)({ref:t,className:Pe("text-sm [&_p]:leading-relaxed",s)},a))});dg.displayName="AlertDescription";class mg extends Q.H{getBaseURL(){return"/apps"}activateBackendFunctions(e){return this.axios.post("/".concat(e,"/activate-backend-functions"))}getBackendFunctionsLogs(e,t,s){return this.axios.get("/".concat(e,"/functions-mgmt/").concat(t,"/logs"),{params:s})}}const ug=new mg,xg=["className"];function hg(e){let{className:t}=e,s=(0,Se.A)(e,xg);return(0,le.jsx)("div",(0,K.A)({className:Pe("animate-pulse rounded-md bg-muted",t)},s))}function pg(e){let{onRouteChange:t}=e;const{hasListing:s,listing:a,isLoading:n,refetch:l}=Rp(),[r,i]=(0,Y.useState)(!1);return n?(0,le.jsx)("div",{className:"space-y-4",children:(0,le.jsxs)("div",{className:"flex flex-col sm:flex-row justify-between items-start gap-4",children:[(0,le.jsxs)("div",{className:"flex-grow space-y-2",children:[(0,le.jsx)(hg,{className:"h-4 w-20"}),(0,le.jsx)(hg,{className:"h-3 w-full max-w-md"})]}),(0,le.jsx)(hg,{className:"h-9 w-36"})]})}):(0,le.jsxs)(le.Fragment,{children:[(0,le.jsxs)("div",{className:"flex flex-col sm:flex-row justify-between items-start gap-4",children:[(0,le.jsxs)("div",{children:[(0,le.jsx)("h3",{className:"text-sm font-medium",children:"App Templates"}),(0,le.jsx)("p",{className:"text-sm text-muted-foreground",children:s?"Manage your template listing":"Share your template with the community so others can discover and use it."})]}),(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[(0,le.jsxs)(Yt,{onClick:()=>t("appListing"),variant:"outline",className:"flex items-center border-gray-200 hover:bg-gray-50 hover:text-gray-700 cursor-pointer",children:[(0,le.jsx)(El.A,{className:"mr-2 h-4 w-4"}),s?"Manage Listing":"Publish to App Templates"]}),s&&(0,le.jsxs)(qr,{children:[(0,le.jsx)(Vr,{asChild:!0,children:(0,le.jsx)(Yt,{variant:"outline",className:"flex items-center border-gray-200 hover:bg-gray-50 hover:text-gray-700 cursor-pointer p-2",children:(0,le.jsx)(Tl.A,{})})}),(0,le.jsxs)(Kr,{align:"end",children:[(0,le.jsx)(Qr,{onClick:()=>window.open("/app-templates?category=my-apps","_blank"),children:"See on App Templates"}),(0,le.jsx)(Qr,{onClick:async()=>{if(window.confirm("Are you sure you want to remove this listing? This action will remove it from the App templates.")){i(!0);try{await $a.archiveItem(null==a?void 0:a.id,!(null!=a&&a.archived)),an({title:"Success",description:"Listing removed from catalog successfully"}),await l()}catch(e){an({title:"Error",description:e.message||"Failed to remove listing from catalog",variant:"destructive"})}finally{i(!1)}}},disabled:!s||r,className:"text-red-600 focus:text-red-600",children:r?(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(Ne.A,{className:"w-4 h-4 mr-2 animate-spin"}),"Removing..."]}):"Remove from App Templates"})]})]})]})]}),s&&a&&(0,le.jsxs)("div",{className:"flex flex-col sm:flex-row gap-4",children:[(0,le.jsx)("div",{className:"flex-shrink-0",children:(0,le.jsx)("div",{className:"w-20 h-20 sm:w-20 sm:h-20 rounded-lg overflow-hidden bg-white border border-slate-200 shadow-sm",children:a.screenshot_urls&&a.screenshot_urls[0]?(0,le.jsx)("img",{src:a.screenshot_urls[0],alt:"".concat(a.name," screenshot"),className:"w-full h-full object-cover"}):(0,le.jsx)("div",{className:"w-full h-full flex items-center justify-center text-slate-400",children:(0,le.jsx)(vm.A,{className:"w-6 h-6"})})})}),(0,le.jsx)("div",{className:"flex-grow min-w-0",children:(0,le.jsx)("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-2",children:(0,le.jsxs)("div",{className:"min-w-0",children:[(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[(0,le.jsx)("h4",{className:"font-medium text-slate-900 truncate",children:a.name}),(0,le.jsx)("span",{className:"inline-flex items-center px-2.5 py-1 rounded-lg text-xs font-medium ".concat("approved"===a.status?"bg-teal-100 text-teal-800":"pending"===a.status?"bg-yellow-50 text-yellow-600 border border-yellow-200 rounded-[20px]":"bg-red-100 text-red-800"),children:a.status.charAt(0).toUpperCase()+a.status.slice(1)})]}),(0,le.jsx)("p",{className:"text-sm text-gray-500 mt-0.5",children:a.updated_date?new Date(a.updated_date).toLocaleString("en-US",{year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric"}):"Published to App Templates"}),"rejected"===a.status&&a.rejected_reason&&(0,le.jsxs)("p",{className:"text-xs bg-red-100 text-red-800 mt-1 rounded-lg p-2 font-medium",children:["Rejected Reason: ",a.rejected_reason]})]})})})]})]})}const gg=e=>{let{onClose:t,isOpen:s}=e;const{app:a}=Nt();return(0,Y.useEffect)(()=>{s&&ve.getLoginInfoById(a.id).then(e=>{})},[s]),(0,le.jsx)(tc,{open:s,onOpenChange:e=>!e&&t(),children:(0,le.jsxs)(lc,{className:"w-full gap-4 font-base44",children:[(0,le.jsx)(Fa,{className:"space-y-0",children:(0,le.jsx)(oc,{children:"Edit App Logo"})}),(0,le.jsx)(fg,{onSubmit:t})]})})},fg=e=>{var t,s;let{onSubmit:a}=e;const{app:n}=Nt(),{isLoading:l,logoPrompt:r,defaultPrompt:i,handleRegenerateLogo:o,handleUploadLogo:c,handlePromptChange:d,handleUploadImageFile:m,logoUrl:u,isDirty:x}=(()=>{const{app:e}=Nt(),t="A modern, minimalist logo for a business app",[s,a]=(0,Y.useState)(e.logo_prompt),[n,l]=(0,Y.useState)(e.logo_url);(0,Y.useEffect)(()=>()=>{l(void 0)},[]);const r=Ep(async()=>{const a=await ve.generateLogoFromPrompt(e.id,{prompt:s||t});return l(a.logo_url),a.logo_url},{toastError:"Failed to regenerate logo"}),i=Ep(async t=>{const s=await _t.uploadAppFile(t,e.id);return l(s.url),s.url},{toastError:"Failed to upload logo",initialResult:e.logo_url}),o=Ep(async t=>{var s;const a=null!==(s=t.url)&&void 0!==s?s:(await _t.uploadAppFile(t.file,e.id)).url;return l(a),ve.updateLogo(e.id,{logo_url:a})},{toastSuccess:"Logo uploaded successfully",toastError:"Failed to upload logo"});return{isLoading:r.isLoading||o.isLoading||i.isLoading,logoPrompt:s,defaultPrompt:t,handleRegenerateLogo:r.update,handleUploadLogo:o.update,handleUploadImageFile:i.update,handlePromptChange:e=>a(e.target.value),logoUrl:n,isDirty:n!==e.logo_url}})(),[h,p]=(0,Y.useState)(!1),g=l||h;return(0,le.jsxs)(le.Fragment,{children:[(0,le.jsxs)("div",{className:"flex flex-col py-2 gap-3 items-center justify-center",children:[(0,le.jsx)("div",{className:"flex w-20 h-20 border-[1px] border-[rgba(0,0,0,0.1)] rounded-xl items-center justify-center",children:n.logo_url?(0,le.jsx)("img",{src:null!=u?u:n.logo_url,alt:"".concat(n.name," logo"),className:" w-full h-full object-contain rounded-xl",onLoadStart:()=>p(!0),onLoad:()=>p(!1)}):(0,le.jsx)("div",{className:"p-1 bg-gray-100 rounded-xl flex items-center justify-center",children:(0,le.jsx)("span",{className:"text-xl font-bold text-gray-400",children:(null===(t=n.name)||void 0===t||null===(s=t[0])||void 0===s?void 0:s.toUpperCase())||"A"})})}),(0,le.jsxs)(kp,{defaultValue:"upload",className:"w-full space-y-6",children:[(0,le.jsxs)(Cp,{className:"grid w-full grid-cols-2 bg-normal",children:[(0,le.jsx)(Ap,{value:"upload",className:"border-b-2 data-[state=active]:border-primary border-secondary rounded-none font-normal text-foreground",children:"Upload Logo"}),(0,le.jsx)(Ap,{value:"generate",className:"border-b-2 data-[state=active]:border-primary border-secondary rounded-none font-normal text-foreground",children:"Generate Logo"})]}),(0,le.jsx)(Sp,{value:"upload",className:" h-full rounded-lg",children:(0,le.jsxs)("div",{className:"flex flex-col items-center justify-center border-2 border-dashed rounded-lg p-8 hover:border-primary/50 transition-colors bg-gray-50 min-h-[170px]",onDragOver:e=>e.preventDefault(),onDrop:e=>{m(e.dataTransfer.files[0])},children:[(0,le.jsx)("input",{type:"file",id:"logo-upload",className:"hidden pointer-events-none ",disabled:g,accept:"image/*",onChange:e=>{m(e.target.files[0])}}),(0,le.jsxs)("label",{htmlFor:"logo-upload",className:"pointer-events-none text-center",children:[(0,le.jsx)("p",{className:"text-sm text-foreground ",children:"Drag and drop or click to upload"}),(0,le.jsx)("p",{className:"text-xs text-muted-foreground",children:"PNG, JPG up to 5MB"}),(0,le.jsx)(Hn,{disabled:g,variant:"outline",size:"tiny",className:"mt-3 pointer-events-auto",onClick:()=>{var e;null===(e=document.getElementById("logo-upload"))||void 0===e||e.click()},children:"Upload"})]})]})}),(0,le.jsxs)(Sp,{value:"generate",className:"space-y-1",children:[(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsx)(go,{htmlFor:"logo-prompt",className:"text-muted-foreground",children:"What should yout logo look like?"}),(0,le.jsx)(yp,{id:"logo-prompt",value:r,onChange:d,className:"min-h-[100px] rounded-lg",placeholder:i})]}),(0,le.jsx)(Hn,{onClick:o,disabled:g,variant:"secondary",size:"tiny",className:"w-full",children:g?"Generating...":"Generate new logo"})]})]})]}),(0,le.jsxs)("div",{className:"flex flex-row gap-2 items-center justify-end w-full",children:[(0,le.jsx)(Hn,{autoFocus:!x,variant:"outline",size:"tiny",onClick:a,children:"Cancel"}),(0,le.jsx)(Hn,{autoFocus:x,size:"tiny",onClick:async()=>{await c({url:u}),null==a||a()},disabled:g||!x,children:"Save"})]})]})};const vg=function(e){var t,s;let{onRouteChange:a}=e;const{user:n}=oe(),{app:l,updateApp:r}=Nt(),{isInSharedWorkspace:i}=Vp(),{settings:o,userRole:c,isEnterpriseWorkspace:d}=Gp(),m=(0,Z.Zp)(),u=(0,Z.zy)(),{toast:x}=nn(),[h,p]=(0,Y.useState)(!1),[g,f]=(0,Y.useState)(!1),[v,b]=(0,Y.useState)(!1),[j,y]=(0,Y.useState)(!1),[N,w]=(0,Y.useState)(!1),[_,k]=(0,Y.useState)(null),C=(0,Y.useRef)(null),A=(0,Y.useRef)(null),S=(0,Y.useRef)(null),E=(0,Y.useRef)(null),I=(0,Y.useRef)(null),T=(0,Y.useRef)(null),P=(0,Y.useRef)(null),L=(0,Y.useRef)(null),O=(0,Y.useRef)(null),R=dx(n),M=(null==l?void 0:l.using_sandbox)&&(null==n||null===(t=n.feature_flags)||void 0===t?void 0:t.includes("use-sandbox-from-ui"));(0,Y.useEffect)(()=>{const e=new URLSearchParams(u.search).get("selectedParam");if(e){k(e);let t=null;switch(e){case"main-page":t=C;break;case"visibility":t=A;break;case"branding-badge":t=S;break;case"hide-created-by":t=E;break;case"enable-agents":t=I;break;case"clone-app":t=T;break;case"backend-functions":t=P;break;case"delete-app":t=L;break;case"admin-controls":t=O}t&&t.current&&setTimeout(()=>{t.current.scrollIntoView({behavior:"smooth",block:"center"})},300)}},[u.search]);const D=async()=>{try{await ve.delete(l.id),x({title:"Success",description:"App deleted successfully"}),m("/")}catch(e){x({title:"Error",description:"Failed to delete app",variant:"destructive"})}},F=e=>_===e?"selected-section p-4 rounded-md":"";return(0,le.jsxs)(up,{title:"App Settings",children:[(0,le.jsx)("style",{jsx:!0,global:!0,children:"\n .selected-section {\n position: relative;\n border-left: 4px solid #334155;\n background-color: rgba(241, 245, 249, 0.7);\n box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);\n transition: all 0.4s ease;\n padding-left: 16px !important;\n padding-top: 14px !important;\n padding-bottom: 14px !important;\n margin: 4px 0 !important;\n border-radius: 4px;\n }\n\n /* Left border with animated glow */\n .selected-section::before {\n content: '';\n position: absolute;\n left: -4px;\n top: 0;\n width: 4px;\n height: 100%;\n background: linear-gradient(to bottom, #0f766e, #334155);\n box-shadow: 0 0 12px rgba(15, 118, 110, 0.5);\n animation: border-pulse 2.5s infinite ease-in-out;\n z-index: 1;\n }\n \n /* Light effect */\n .selected-section::after {\n content: '';\n position: absolute;\n left: 0;\n top: 0;\n height: 100%;\n width: 100%;\n background: linear-gradient(to right, rgba(15, 118, 110, 0.08), transparent 50%);\n animation: light-pulse 2.5s infinite ease-in-out;\n pointer-events: none;\n border-radius: 4px;\n }\n \n @keyframes border-pulse {\n 0%, 100% {\n box-shadow: 0 0 8px rgba(15, 118, 110, 0.4);\n }\n 50% {\n box-shadow: 0 0 20px rgba(15, 118, 110, 0.7);\n }\n }\n \n @keyframes light-pulse {\n 0%, 100% {\n opacity: 0.3;\n background: linear-gradient(to right, rgba(15, 118, 110, 0.05), transparent 50%);\n }\n 50% {\n opacity: 0.7;\n background: linear-gradient(to right, rgba(15, 118, 110, 0.12), transparent 60%);\n }\n }\n "}),(0,le.jsx)(bg,{}),(0,le.jsxs)(Qn,{children:[(0,le.jsx)(Xn,{className:"border-b border-gray-100",children:(0,le.jsx)(el,{className:"text-gray-800",children:"General Settings"})}),(0,le.jsxs)(sl,{className:"space-y-6 pt-6",children:[(0,le.jsxs)("div",{ref:C,className:"flex flex-col sm:flex-row justify-between sm:items-center gap-2 ".concat(F("main-page")),children:[(0,le.jsxs)("div",{children:[(0,le.jsx)("h3",{className:"text-sm font-medium",children:"Main Page"}),(0,le.jsx)("p",{className:"text-sm text-muted-foreground",children:"Set the default landing page for your app"})]}),(0,le.jsx)("div",{className:"w-full sm:w-64",children:(0,le.jsxs)(zs,{value:l.main_page||"",onValueChange:async e=>{try{r({main_page:e}),M&&await gu.updateMainPage(l.id,e),x({title:"Success",description:"Main page updated successfully"})}catch(t){x({title:"Error",description:"Failed to update main page",variant:"destructive"})}},children:[(0,le.jsx)(qs,{children:(0,le.jsx)(Ws,{placeholder:"Select main page"})}),(0,le.jsx)(Ys,{children:Object.keys(l.pages||{}).map(e=>(0,le.jsx)($s,{value:e,children:e},e))})]})})]}),(0,le.jsx)(ps,{}),(0,le.jsxs)("div",{ref:A,className:"flex flex-col sm:flex-row justify-between sm:items-center gap-2 ".concat(F("visibility")),children:[(0,le.jsxs)("div",{children:[(0,le.jsx)("h3",{className:"text-sm font-medium",children:"App Visibility"}),(0,le.jsx)("p",{className:"text-sm text-muted-foreground",children:"Control who can access your application"})]}),(0,le.jsx)("div",{className:"w-full sm:w-64",children:(0,le.jsx)(ag,{value:l.public_settings||"private_with_login",onValueChange:async e=>{f(!0);try{await r({public_settings:e}),x({title:"Success",description:"App visibility updated successfully"})}catch(t){x({title:"Error",description:"Failed to update app visibility",variant:"destructive"})}finally{f(!1)}},disabled:g,showWorkspace:i,allowedOptions:$p(l.public_settings,o,c,d)})})]}),(0,le.jsx)(ps,{}),(0,le.jsxs)("div",{ref:S,className:"flex flex-col sm:flex-row justify-between sm:items-center gap-2 ".concat(F("platform-badge")),children:[(0,le.jsxs)("div",{className:"flex-grow space-y-1",children:[(0,le.jsx)("h3",{className:"text-sm font-medium",children:"Platform Badge"}),(0,le.jsx)("p",{className:"text-sm text-muted-foreground",children:'Show or hide the "Edit with Base44" badge on your app.'}),"free"===n.subscription_tier&&(0,le.jsxs)("p",{className:"text-xs text-orange-500 pt-1",children:[(0,le.jsx)(Mt.A,{className:"h-3 w-3 inline-block mr-1 relative -top-px"}),"Available only for paying users.",(0,le.jsx)("a",{href:"/billing",className:"ml-1 underline font-medium hover:text-orange-700",children:"Upgrade now"})]})]}),(0,le.jsxs)("div",{className:"flex items-center space-x-2 flex-shrink-0 mt-2 sm:mt-0",children:[(0,le.jsx)(ix,{id:"platform-badge-switch",checked:!0===l.is_remixable,onCheckedChange:async e=>{b(!0);try{r({is_remixable:e}),x({title:"Success",description:"Platform badge will be ".concat(e?"visible":"hidden",".")})}catch(t){x({title:"Error",description:"Failed to update platform badge visibility.",variant:"destructive"})}finally{b(!1)}},disabled:"free"===n.subscription_tier||v,"aria-label":"Toggle platform badge visibility"}),(0,le.jsx)(Ns,{htmlFor:"platform-badge-switch",className:"text-sm text-muted-foreground",children:!0===l.is_remixable?"Visible":"Hidden"})]})]}),(0,le.jsx)(ps,{}),(0,le.jsxs)("div",{ref:E,className:"flex flex-col sm:flex-row justify-between sm:items-center gap-2 ".concat(F("hide-created-by")),children:[(0,le.jsxs)("div",{children:[(0,le.jsx)("h3",{className:"text-sm font-medium",children:"Hide Entity Creator"}),(0,le.jsx)("p",{className:"text-sm text-muted-foreground",children:'Hide who created each record in your app\'s data tables. When enabled, the "created by" field will not be shown to users.'})]}),(0,le.jsxs)("div",{className:"flex items-center space-x-2 flex-shrink-0 mt-2 sm:mt-0",children:[(0,le.jsx)(ix,{id:"hide-created-by-switch",checked:!0===l.hide_entity_created_by,onCheckedChange:async e=>{y(!0);try{r({hide_entity_created_by:e}),x({title:"Success",description:"Entity creator information will be ".concat(e?"hidden":"visible"," in your app.")})}catch(t){x({title:"Error",description:"Failed to update entity creator visibility.",variant:"destructive"})}finally{y(!1)}},disabled:j,"aria-label":"Toggle hide entity creator"}),(0,le.jsx)(Ns,{htmlFor:"hide-created-by-switch",className:"text-sm text-muted-foreground",children:!0===l.hide_entity_created_by?"Hidden":"Visible"})]})]}),(0,le.jsx)(ps,{}),(0,le.jsxs)("div",{ref:I,className:"flex flex-col sm:flex-row justify-between sm:items-center gap-2 ".concat(F("enable-agents")),children:[(0,le.jsxs)("div",{children:[(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[(0,le.jsx)("h3",{className:"text-sm font-medium",children:"AI Agents"}),(0,le.jsx)("span",{className:"px-2 py-0.5 text-xs font-medium bg-blue-100 text-blue-700 rounded-full",children:"Beta"})]}),(0,le.jsx)("p",{className:"text-sm text-muted-foreground",children:"Build AI agents into your app using Base44's AI agents infrastructure"})]}),(0,le.jsxs)("div",{className:"flex items-center space-x-2 flex-shrink-0 mt-2 sm:mt-0",children:[(0,le.jsx)(ix,{id:"enable-agents-switch",checked:!0===l.agents_enabled,onCheckedChange:async e=>{w(!0);try{await r({agents_enabled:e}),x({title:"Success",description:"AI agents ".concat(e?"enabled":"disabled"," successfully.")})}catch(t){x({title:"Error",description:"Failed to update AI agents setting.",variant:"destructive"})}finally{w(!1)}},disabled:N,"aria-label":"Toggle AI agents"}),(0,le.jsx)(Ns,{htmlFor:"enable-agents-switch",className:"text-sm text-muted-foreground",children:!0===l.agents_enabled?"Enabled":"Disabled"})]})]}),l.agents_enabled&&(0,le.jsxs)(og,{className:"bg-blue-50 border-blue-200",children:[(0,le.jsx)(Cm.A,{className:"h-4 w-4 text-blue-600"}),(0,le.jsx)(cg,{className:"text-blue-800",children:"AI Agents Enabled"}),(0,le.jsx)(dg,{className:"text-blue-700",children:"Your app now has access to Base44's AI agents infrastructure. You can create intelligent agents that can help users with various tasks, answer questions, and interact with your app's data. Use the chat to build and configure your agents."})]}),(0,le.jsx)(ps,{}),(0,le.jsxs)("div",{ref:T,className:"flex flex-col sm:flex-row justify-between sm:items-center gap-2 ".concat(F("clone-app")),children:[(0,le.jsxs)("div",{children:[(0,le.jsx)("h3",{className:"text-sm font-medium",children:"Clone App"}),(0,le.jsx)("p",{className:"text-sm text-muted-foreground",children:"Create a duplicate of this app"})]}),(0,le.jsxs)(Yt,{onClick:async()=>{window.open("/remix-app/".concat(l.id,"?clone_history=true"),"_blank")},variant:"outline",className:"flex items-center border-gray-200 hover:bg-gray-50 hover:text-gray-700",children:[(0,le.jsx)(or.A,{className:"mr-2 h-4 w-4"}),"Create Copy"]})]}),(0,le.jsx)(ps,{}),(0,le.jsx)(pg,{onRouteChange:a}),(0,le.jsx)(ps,{}),(0,le.jsxs)("div",{ref:P,className:"flex flex-col sm:flex-row justify-between sm:items-center gap-2 ".concat(F("backend-functions")),children:[(0,le.jsxs)("div",{children:[(0,le.jsx)("h3",{className:"text-sm font-medium",children:"Backend Functions"}),(0,le.jsx)("p",{className:"text-sm text-muted-foreground",children:"Enable server-side functionality \u2022 Recommended for developers"})]}),R?(0,le.jsxs)(Yt,{onClick:async()=>{try{p(!0),await ug.activateBackendFunctions(l.id),x({title:"Success",description:"Backend functions activated successfully. Prompt the chat to build your backend functions."})}catch(e){x({title:"Error",description:"Failed to activate backend functions",variant:"destructive"})}finally{p(!1)}},disabled:h||!!l.has_backend_functions_enabled,variant:"outline",className:"flex items-center border-gray-200 hover:bg-gray-50 hover:text-gray-700",children:[(0,le.jsx)(Kl.A,{className:"mr-2 h-4 w-4"}),h?"Activating...":l.has_backend_functions_enabled?"Activated":"Activate"]}):(0,le.jsxs)(Yt,{variant:"outline",className:"flex items-center text-gray-500 border-gray-200 hover:bg-gray-50",onClick:()=>m("/billing"),children:[(0,le.jsx)(Tr.A,{className:"mr-2 h-4 w-4"}),"Upgrade Plan"]})]}),!R&&(0,le.jsx)(xx,{})]})]}),(0,le.jsxs)(Qn,{className:"border-gray-200",children:[(0,le.jsxs)(Xn,{className:"border-b border-gray-100",children:[(0,le.jsx)(el,{className:"text-gray-800",children:"Danger Zone"}),(0,le.jsx)(tl,{className:"text-gray-600",children:"Irreversible actions that affect your app"})]}),(0,le.jsxs)(sl,{className:"space-y-6",children:[(0,le.jsxs)("div",{ref:L,className:"flex flex-col sm:flex-row justify-between sm:items-center gap-2 ".concat(F("delete-app")),children:[(0,le.jsxs)("div",{children:[(0,le.jsx)("h3",{className:"text-sm font-medium",children:"Delete App"}),(0,le.jsx)("p",{className:"text-sm text-muted-foreground",children:"Permanently remove this app and all its data"})]}),(0,le.jsxs)(Yt,{onClick:()=>{window.confirm("Are you sure you want to delete this app? This action cannot be undone.")&&D()},variant:"destructive",className:"flex items-center bg-red-500/90 hover:bg-red-600 text-white",children:[(0,le.jsx)(Ip.A,{className:"mr-2 h-4 w-4"}),"Delete App"]})]}),(null===(s=n.platform_role)||void 0===s?void 0:s.includes("admin"))&&(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(ps,{}),(0,le.jsxs)("div",{ref:O,className:"flex flex-col sm:flex-row justify-between sm:items-center gap-2 ".concat(F("admin-controls")),children:[(0,le.jsxs)("div",{children:[(0,le.jsx)("h3",{className:"text-sm font-medium",children:"Admin Controls"}),(0,le.jsx)("p",{className:"text-sm text-muted-foreground",children:"Manage app availability"})]}),(0,le.jsxs)(Yt,{onClick:async()=>{try{r({is_blocked:!l.is_blocked}),x({title:"Success",description:"App ".concat(l.is_blocked?"unblocked":"blocked"," successfully")})}catch(e){x({title:"Error",description:"Failed to ".concat(l.is_blocked?"unblock":"block"," app"),variant:"destructive"})}},variant:"outline",className:"flex items-center border-gray-200 hover:bg-gray-50 hover:text-gray-700",children:[(0,le.jsx)(qp.A,{className:"mr-2 h-4 w-4"}),l.is_blocked?"Unblock App":"Block App"]})]})]})]})]})]})},bg=()=>{var e,t;const{app:s,updateApp:a}=Nt(),[n,l]=(0,Y.useState)(!1),[r,i]=(0,Y.useState)(s.description),[o,c]=(0,Y.useState)(!1),d=Ep(async e=>{await a({user_description:e})},{toastSuccess:{title:"Description Updated",description:"Your app description has been updated successfully"},toastError:"Failed to update app description"});return(0,Y.useEffect)(()=>{s.user_description&&i(s.user_description)},[s.user_description]),(0,le.jsxs)(le.Fragment,{children:[(0,le.jsxs)(Qn,{children:[(0,le.jsx)(Xn,{children:(0,le.jsx)(el,{children:"App Info"})}),(0,le.jsxs)(sl,{className:" flex flex-col gap-4",children:[(0,le.jsx)(ps,{}),(0,le.jsxs)("div",{className:"flex justify-between w-full h-full items-center",children:[(0,le.jsxs)("div",{className:"flex flex-row gap-3 items-center",children:[(0,le.jsx)("div",{className:"flex w-12 h-12 rounded-lg bg-white shadow items-center justify-center",children:s.logo_url?(0,le.jsx)("img",{src:s.logo_url,alt:"".concat(s.name," logo"),className:"w-full h-full object-contain rounded-lg"}):(0,le.jsx)("div",{className:"p-1 bg-gray-100 rounded-lg flex items-center justify-center object-contain",children:(0,le.jsx)("span",{className:"text-sm font-bold text-gray-400",children:(null===(e=s.name)||void 0===e||null===(t=e[0])||void 0===t?void 0:t.toUpperCase())||"A"})})}),(0,le.jsx)(Ns,{children:"App Logo"})]}),(0,le.jsx)(Hn,{onClick:()=>l(!0),variant:"outline",size:"tiny",children:"Edit Logo"})]}),(0,le.jsx)(ps,{}),(0,le.jsxs)("div",{className:"flex flex-col justify-between w-full h-full gap-3",children:[(0,le.jsxs)("div",{className:"flex flex-row gap-3 items-center justify-between",children:[(0,le.jsx)(Ns,{children:"App Description"}),(0,le.jsxs)("div",{className:"flex flex-row gap-2 items-center",children:[(0,le.jsx)(Hn,{size:"tiny",variant:"outline",onClick:()=>{c(e=>!e)},children:o?(0,le.jsx)(Bt.A,{}):(0,le.jsx)(Ql.A,{})}),o&&(0,le.jsx)(Hn,{disabled:!o,onClick:()=>{d.update(r),c(!1)},size:"tiny",children:"Save Description"})]})]}),(0,le.jsx)("div",{className:"h-20",children:o?(0,le.jsx)(yp,{disabled:!o,value:r,initialValue:s.user_description,onChange:e=>i(e.target.value),placeholder:"Describe your app...",className:"h-full resize-none"}):(0,le.jsx)("p",{className:"text-gray-600 text-sm mt-1",children:r})})]})]})]}),(0,le.jsx)(gg,{isOpen:n,onClose:()=>l(!1)})]})};function jg(){const[e,t]=(0,Y.useState)(()=>"appListing"===new URLSearchParams(window.location.search).get("tab")?"appListing":"main"),s=e=>{t(e)},a={main:(0,le.jsx)(vg,{onRouteChange:s}),appListing:(0,le.jsx)("div",{className:"max-w-8xl mx-auto p-4",children:(0,le.jsx)(Wp,{onRouteChange:s})})};return(0,le.jsx)(Op,{children:a[e]||a.main})}function yg(e){return(null==e?void 0:e.auth_config)||{enable_username_password:!1,enable_google_login:!0,enable_microsoft_login:!1,enable_facebook_login:!1,enable_sso_login:!1,sso_provider_name:null}}class Ng extends Q.H{getBaseURL(){return"/workspace"}getSSOSettings(e){return this.axios.get("/".concat(e,"/sso/settings"))}enableSSO(e){return this.axios.post("/".concat(e,"/sso/enable"),{})}disableSSO(e){return this.axios.post("/".concat(e,"/sso/disable"),{})}updateSSOSettings(e,t){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;const a=s?{provider_name:s}:{};return this.axios.put("/".concat(e,"/sso/settings"),t,{params:a})}}const wg=new Ng,_g=["value","onChange","onClear","disabled"],kg=e=>{let{children:t,content:s,side:a="left"}=e;const n="right"===a,l="top"===a,r="bottom"===a,i="left"===a;return(0,le.jsxs)("div",{className:"relative group",children:[t,(0,le.jsxs)("div",{className:"\n absolute px-3 py-2 bg-gray-900 text-white text-xs rounded-md \n opacity-0 group-hover:opacity-100 transition-opacity duration-200 \n pointer-events-none whitespace-nowrap z-50 min-w-max\n ".concat(r?"top-full mt-2 left-1/2 transform -translate-x-1/2":l?"bottom-full mb-2 left-1/2 transform -translate-x-1/2":n?"bottom-full mb-2 right-0":i?"right-full mr-2 top-1/2 transform -translate-y-1/2":"bottom-full mb-2 left-0","\n "),children:[s,(0,le.jsx)("div",{className:"\n absolute border-4 border-transparent\n ".concat(r?"bottom-full -mb-1 left-1/2 transform -translate-x-1/2 border-b-gray-900":l?"top-full -mt-1 left-1/2 transform -translate-x-1/2 border-t-gray-900":n?"top-full -mt-1 right-4 border-t-gray-900":i?"left-full -ml-1 top-1/2 transform -translate-y-1/2 border-l-gray-900":"top-full -mt-1 left-4 border-t-gray-900","\n ")})]})]})},Cg=e=>e&&"string"==typeof e&&(e.match(/^x+$/i)||e.match(/^\u2022+$/)),Ag=e=>Cg(e)?"\u2022".repeat(20):e,Sg=e=>{let{value:t,onChange:s,onClear:a,disabled:n}=e,l=(0,Se.A)(e,_g);return(0,le.jsx)(fs,(0,K.A)((0,K.A)({},l),{},{value:Ag(t),onChange:e=>{n||Cg(e.target.value)||s(e.target.value)},onFocus:()=>{!n&&Cg(t)&&a()},disabled:n}))},Eg=e=>{let{provider:t,icon:s,iconBg:a,title:n,description:l,checked:r,onToggle:i,disabled:o,children:c,expanded:d,forceUnchecked:m=!1}=e;const u=a||"bg-white border-gray-200",x=!m&&r;return(0,le.jsxs)("div",{className:"bg-white rounded-lg outline outline-1 outline-offset-[-1px] outline-gray-200 overflow-hidden ".concat(o?"opacity-60":""),children:[(0,le.jsxs)("div",{className:"p-4 flex justify-start items-center gap-4",children:[(0,le.jsx)("div",{className:"w-10 h-10 rounded-lg border flex items-center justify-center ".concat(u),children:s}),(0,le.jsxs)("div",{className:"flex-1 flex flex-col justify-start items-start gap-0.5",children:[(0,le.jsx)("div",{className:"flex justify-center items-center gap-2",children:(0,le.jsx)("div",{className:"text-gray-900 text-sm font-medium leading-tight ".concat(o?"text-gray-500":""),children:n})}),(0,le.jsx)("div",{className:"self-stretch flex justify-center items-center gap-2.5",children:(0,le.jsx)("div",{className:"flex-1 text-gray-500 text-sm font-normal leading-tight ".concat(o?"text-gray-400":""),children:l})})]}),(0,le.jsx)(ix,{id:"".concat(t,"-auth-switch"),checked:x,onCheckedChange:e=>i(t,e),disabled:o})]}),r&&d&&c&&(0,le.jsx)("div",{children:c})]})};function Ig(){var e;const{user:t}=oe(),{app:s,updateApp:a,updateSecrets:n}=Nt(),{activeWorkspace:l}=ge(),r=cx(t,"elite"),i=cx(t,"builder"),o=r||!0===(null==l?void 0:l.is_enterprise),c=(0,Z.zy)(),{toast:d}=nn(),[m,u]=(0,Y.useState)(!1),[x,h]=(0,Y.useState)(!1),[p,g]=(0,Y.useState)(new Set),[f,v]=(0,Y.useState)(!1),[b,j]=(0,Y.useState)({name:"",client_id:"",client_secret:"",discovery_url:"",scope:"openid email profile",auth_endpoint:"",token_endpoint:"",userinfo_endpoint:"",jwks_uri:"",tenant_id:"",okta_domain:""}),[y,N]=(0,Y.useState)(""),[w,_]=(0,Y.useState)(null),[k,C]=(0,Y.useState)(null),[A,S]=(0,Y.useState)(!1),[E,I]=(0,Y.useState)(!1),[T,P]=(0,Y.useState)({email_password:!1,google:!1,microsoft:!1,facebook:!1}),[L,O]=(0,Y.useState)({email_password:!1,google:!1,microsoft:!1,facebook:!1}),[R,M]=(0,Y.useState)("default"),[D,F]=(0,Y.useState)("default"),[B,z]=(0,Y.useState)({client_id:"",client_secret:""}),[U,W]=(0,Y.useState)({client_id:"",client_secret:""}),[q,V]=(0,Y.useState)(!1),H=[{id:"email_password",title:"Email and password authentication",description:"Members can log in with email and password",iconBg:"bg-slate-900 border-slate-900",icon:(0,le.jsx)("svg",{className:"w-5 h-5 text-white",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,le.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3 8l7.89 4.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"})})},{id:"google",title:"Google authentication",description:"Members can log in with a Google account",iconBg:"bg-white border-gray-200",icon:(0,le.jsxs)("svg",{className:"w-5 h-5",viewBox:"0 0 24 24",children:[(0,le.jsx)("path",{fill:"#4285F4",d:"M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z"}),(0,le.jsx)("path",{fill:"#34A853",d:"M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z"}),(0,le.jsx)("path",{fill:"#FBBC05",d:"M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z"}),(0,le.jsx)("path",{fill:"#EA4335",d:"M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z"})]})},{id:"microsoft",title:"Microsoft authentication",description:"Members can log in with a Microsoft account",iconBg:"bg-white border-gray-200",icon:(0,le.jsxs)("svg",{className:"w-5 h-5",viewBox:"0 0 24 24",children:[(0,le.jsx)("path",{fill:"#F25022",d:"M0 0h11.5v11.5H0z"}),(0,le.jsx)("path",{fill:"#00A4EF",d:"M12.5 0H24v11.5H12.5z"}),(0,le.jsx)("path",{fill:"#7FBA00",d:"M0 12.5h11.5V24H0z"}),(0,le.jsx)("path",{fill:"#FFB900",d:"M12.5 12.5H24V24H12.5z"})]})},{id:"facebook",title:"Facebook authentication",description:"Members can log in with a Facebook account",iconBg:"bg-[#1877F2] border-[#1877F2]",icon:(0,le.jsx)("svg",{className:"w-5 h-5 text-white",fill:"currentColor",viewBox:"0 0 24 24",children:(0,le.jsx)("path",{d:"M24 12.073c0-6.627-5.373-12-12-12s-12 5.373-12 12c0 5.99 4.388 10.954 10.125 11.854v-8.385H7.078v-3.47h3.047V9.43c0-3.007 1.792-4.669 4.533-4.669 1.312 0 2.686.235 2.686.235v2.953H15.83c-1.491 0-1.956.925-1.956 1.874v2.25h3.328l-.532 3.47h-2.796v8.385C19.612 23.027 24 18.062 24 12.073z"})})}],G=null!=k&&k.sso_enabled&&l&&!l.is_personal?{workspace_sso:{name:"workspace_sso",displayName:"".concat(k.sso_provider_name||"Workspace"," (Workspace SSO)"),description:"Use the SSO settings configured for your workspace (".concat(l.name,")"),isWorkspaceSSO:!0,fields:[{name:"workspace",label:"Workspace",value:l.name,readOnly:!0,row:1},{name:"provider_name",label:"Provider Name",value:k.sso_provider_name||"Not configured",readOnly:!0,row:2}]}}:{},$=(0,K.A)((0,K.A)({},G),{},{google:{name:"google",displayName:"Google Workspace",description:"Google Workspace (formerly G Suite) SSO",defaults:{discovery_url:"https://accounts.google.com/.well-known/openid-configuration",scope:"openid email profile"},fields:[{name:"client_id",required:!0,row:1,tooltip:"The OAuth client ID provided by your identity provider"},{name:"client_secret",required:!0,row:1,tooltip:"The OAuth client secret provided by your identity provider (keep this confidential)"},{name:"scope",required:!1,row:2,tooltip:"OAuth scopes to request (openid, email, profile are commonly used)"},{name:"discovery_url",required:!1,row:2,tooltip:"OIDC discovery endpoint (pre-configured for Google)"}]},microsoft:{name:"microsoft",displayName:"Microsoft Azure AD",description:"Microsoft Azure Active Directory (requires tenant ID)",defaults:{scope:"openid email profile"},fields:[{name:"client_id",required:!0,row:1,tooltip:"The OAuth client ID provided by your identity provider"},{name:"client_secret",required:!0,row:1,tooltip:"The OAuth client secret provided by your identity provider (keep this confidential)"},{name:"tenant_id",required:!0,row:2,tooltip:"Azure AD Directory (tenant) ID - found in Azure Portal \u2192 Azure Active Directory \u2192 Overview",placeholder:"Your Azure AD tenant ID"},{name:"scope",required:!1,row:2,tooltip:"OAuth scopes to request (openid, email, profile are commonly used)"},{name:"discovery_url",required:!1,row:3,tooltip:"OIDC discovery endpoint automatically generated from your tenant ID"}],autoGenerate:{field:"tenant_id",template:e=>"https://login.microsoftonline.com/".concat(e,"/v2.0/.well-known/openid-configuration"),target:"discovery_url"}},github:{name:"github",displayName:"GitHub",description:"GitHub OAuth (not OIDC compatible)",defaults:{scope:"user:email",auth_endpoint:"https://github.com/login/oauth/authorize",token_endpoint:"https://github.com/login/oauth/access_token",userinfo_endpoint:"https://api.github.com/user"},fields:[{name:"client_id",required:!0,row:1,tooltip:"The OAuth client ID provided by your identity provider"},{name:"client_secret",required:!0,row:1,tooltip:"The OAuth client secret provided by your identity provider (keep this confidential)"},{name:"scope",required:!1,row:2,tooltip:"OAuth scopes to request (user:email for GitHub)"},{name:"auth_endpoint",required:!1,row:2,tooltip:"GitHub OAuth authorization endpoint (pre-configured)"},{name:"token_endpoint",required:!1,row:3,tooltip:"GitHub OAuth token endpoint (pre-configured)"},{name:"userinfo_endpoint",required:!1,row:3,tooltip:"GitHub API user endpoint (pre-configured)"}]},okta:{name:"okta",displayName:"Okta",description:"Okta (requires your tenant domain)",defaults:{scope:"openid email profile"},fields:[{name:"client_id",required:!0,row:1,tooltip:"The OAuth client ID provided by your identity provider"},{name:"client_secret",required:!0,row:1,tooltip:"The OAuth client secret provided by your identity provider (keep this confidential)"},{name:"okta_domain",required:!0,row:2,tooltip:"Your Okta domain name (e.g., 'your-company' from your-company.okta.com)",placeholder:"your-company"},{name:"scope",required:!1,row:2,tooltip:"OAuth scopes to request (openid, email, profile are commonly used)"},{name:"discovery_url",required:!1,row:3,tooltip:"OIDC discovery endpoint automatically generated from your Okta domain"}],autoGenerate:{field:"okta_domain",template:e=>"https://".concat(e,".okta.com/.well-known/openid-configuration"),target:"discovery_url"}},advanced:{name:"advanced",displayName:"Advanced / Manual Configuration",description:"Configure all fields manually for any OAuth/OIDC provider",defaults:{scope:"email profile"},fields:[{name:"name",required:!0,row:1,tooltip:"Custom name for your SSO provider"},{name:"client_id",required:!0,row:1,tooltip:"The OAuth client ID provided by your identity provider"},{name:"client_secret",required:!0,row:2,tooltip:"The OAuth client secret provided by your identity provider (keep this confidential)"},{name:"discovery_url",required:!1,row:2,tooltip:"OIDC discovery endpoint URL (if supported by your provider)"},{name:"scope",required:!1,row:3,tooltip:"OAuth scopes to request (openid, email, profile are commonly used)"},{name:"auth_endpoint",required:!1,row:3,tooltip:"OAuth authorization endpoint URL"},{name:"token_endpoint",required:!1,row:4,tooltip:"OAuth token endpoint URL"},{name:"userinfo_endpoint",required:!1,row:4,tooltip:"OAuth userinfo endpoint URL"},{name:"jwks_uri",required:!1,row:5,tooltip:"JSON Web Key Set URI for token verification"}]}}),J=(0,Y.useRef)(null);(0,Y.useEffect)(()=>{const e=new URLSearchParams(c.search).get("selectedParam");if(e){_(e);let t=null;if("sso-settings"===e)t=J,h(!0);t&&t.current&&setTimeout(()=>{t.current.scrollIntoView({behavior:"smooth",block:"center"})},300)}},[c.search]),(0,Y.useEffect)(()=>{if(s){const e=yg(s),t=e.enable_sso_login;Object.values(L).some(e=>e)||P({email_password:e.enable_username_password||!1,google:!t&&(e.enable_google_login||!1),microsoft:!t&&(e.enable_microsoft_login||!1),facebook:!t&&(e.enable_facebook_login||!1)})}},[null==s?void 0:s.auth_config,L]),(0,Y.useEffect)(()=>{(async()=>{if(null!=s&&s.id&&null!=s&&s.auth_config)try{const e=yg(s),t=e.google_oauth_mode||"default";M(t),F(t);const a=(await qe.getSecrets(s.id)).google_oauth_client_secret||"",n={client_id:e.google_oauth_client_id||"",client_secret:a};z(n),W(n)}catch(e){}})()},[null==s?void 0:s.id]),(0,Y.useEffect)(()=>{(async()=>{if(null!=s&&s.id)try{const e=yg(s);if(e.use_workspace_sso&&null!=k&&k.sso_enabled)return N("workspace_sso"),void S(!0);const t=await qe.getSecrets(s.id),a=Object.keys(t).filter(e=>e.startsWith("sso_")).reduce((e,s)=>(e[s.replace("sso_","")]=t[s],e),{}),n={name:e.sso_provider_name||"",client_id:a.client_id?a.client_id.match(/^x+$/i)?"\u2022".repeat(20):a.client_id:"",client_secret:a.client_secret?a.client_secret.match(/^x+$/i)?"\u2022".repeat(20):a.client_secret:"",discovery_url:a.discovery_url?a.discovery_url.match(/^x+$/i)?"\u2022".repeat(20):a.discovery_url:"",scope:a.scope?a.scope.match(/^x+$/i)?"\u2022".repeat(20):a.scope:"openid email profile",auth_endpoint:a.auth_endpoint?a.auth_endpoint.match(/^x+$/i)?"\u2022".repeat(20):a.auth_endpoint:"",token_endpoint:a.token_endpoint?a.token_endpoint.match(/^x+$/i)?"\u2022".repeat(20):a.token_endpoint:"",userinfo_endpoint:a.userinfo_endpoint?a.userinfo_endpoint.match(/^x+$/i)?"\u2022".repeat(20):a.userinfo_endpoint:"",jwks_uri:a.jwks_uri?a.jwks_uri.match(/^x+$/i)?"\u2022".repeat(20):a.jwks_uri:"",tenant_id:a.tenant_id?a.tenant_id.match(/^x+$/i)?"\u2022".repeat(20):a.tenant_id:"",okta_domain:a.okta_domain?a.okta_domain.match(/^x+$/i)?"\u2022".repeat(20):a.okta_domain:""};let r="";if(e.sso_provider_name)r=$[e.sso_provider_name]?e.sso_provider_name:"advanced";else if(n.name){const e=Object.entries($).find(e=>{let[t,s]=e;return s.name===n.name});r=e?e[0]:"advanced"}else f&&!e.sso_provider_name&&(null!=k&&k.sso_enabled&&l&&!l.is_personal?(r="workspace_sso",S(!0)):r="google");let i=n;const o=new Set;if(r&&"advanced"===r)i=(0,K.A)((0,K.A)({},n),{},{name:e.sso_provider_name||n.name||""}),e.sso_provider_name&&e.sso_provider_name!==n.name&&o.add("name");else if(r&&$[r]){const e=$[r],t={};if(Object.entries(e.defaults||{}).forEach(e=>{let[s,a]=e;n[s]||(t[s]=a,o.add(s))}),i=(0,K.A)((0,K.A)((0,K.A)({},n),t),{},{name:e.name}),e.name!==n.name&&o.add("name"),e.autoGenerate){const t=i[e.autoGenerate.field];t&&!i[e.autoGenerate.target]&&(i[e.autoGenerate.target]=e.autoGenerate.template(t),o.add(e.autoGenerate.target))}}"workspace_sso"!==r&&j(i),N(r),g(o)}catch(e){const t=yg(s);j({name:t.sso_provider_name||"",client_id:"",client_secret:"",discovery_url:"",scope:"openid email profile",auth_endpoint:"",token_endpoint:"",userinfo_endpoint:"",jwks_uri:"",tenant_id:"",okta_domain:""}),null!=k&&k.sso_enabled&&l&&!l.is_personal?(N("workspace_sso"),S(!0)):N(""),g(new Set)}})()},[null==s?void 0:s.id,null==s?void 0:s.auth_config,f,k]),(0,Y.useEffect)(()=>{(async()=>{if(null!=s&&s.organization_id&&l&&!l.is_personal)try{const t=await wg.getSSOSettings(s.organization_id);if(null!=t&&t.config){C(t.config);const n=yg(s);if((n.use_workspace_sso||t.config.apps_must_use_workspace_sso)&&(S(!0),t.config.apps_must_use_workspace_sso&&!n.use_workspace_sso))try{const e=(0,K.A)((0,K.A)({},n),{},{use_workspace_sso:!0,enable_sso_login:!1,sso_provider_name:null});await a({auth_config:e})}catch(e){}}}catch(t){C(null)}else C(null)})()},[null==s?void 0:s.organization_id,null==s?void 0:s.id,l]);const Q=(e,t)=>{j(s=>{const a=(0,K.A)((0,K.A)({},s),{},{[e]:t}),n=$[y];if(null!=n&&n.autoGenerate&&e===n.autoGenerate.field&&t){const e=n.autoGenerate.template(t);a[n.autoGenerate.target]=e,g(e=>new Set(e).add(n.autoGenerate.target))}return a}),g(t=>new Set(t).add(e))},X=e=>e&&$[e]&&$[e].fields||[],ee=async()=>{V(!0);try{const e={google_oauth_mode:R};"custom"===R?((e,t,s)=>{s&&!Cg(s)&&(e[t]=s.trim())})(e,"google_oauth_client_id",B.client_id):e.google_oauth_client_id=null,await a({auth_config:(0,K.A)((0,K.A)({},s.auth_config),e)}),"custom"===R&&B.client_secret&&!Cg(B.client_secret)&&await n({google_oauth_client_secret:B.client_secret}),F(R),W((0,K.A)({},B)),d({title:"Success",description:"custom"===R?"Google custom OAuth settings updated successfully":"Switched to default Base44 OAuth"})}catch(e){d({title:"Error",description:"Failed to update Google OAuth settings",variant:"destructive"})}finally{V(!1)}},te=async(e,t)=>{if(L[e])return;const n=yg(s);if(t&&n.enable_sso_login&&"email_password"!==e)return void d({title:"Cannot Enable Social Provider",description:"Please disable SSO first before enabling social providers",variant:"destructive"});const l={email_password:{field:"enable_username_password",name:"Email and Password"},google:{field:"enable_google_login",name:"Google"},microsoft:{field:"enable_microsoft_login",name:"Microsoft"},facebook:{field:"enable_facebook_login",name:"Facebook"}}[e];if(l){P(s=>(0,K.A)((0,K.A)({},s),{},{[e]:t})),O(t=>(0,K.A)((0,K.A)({},t),{},{[e]:!0}));try{s.auth_config[l.field]=t,await a({auth_config:(0,K.A)((0,K.A)({},s.auth_config),{},{[l.field]:t})}),d({title:"".concat(l.name,t?" Authentication Enabled":" Authentication Disabled"),description:"".concat(l.name,t?" authentication is now enabled for your app":" authentication has been disabled")})}catch(r){P(s=>(0,K.A)((0,K.A)({},s),{},{[e]:!t})),d({title:"Error",description:"Failed to update ".concat(l.name," authentication"),variant:"destructive"})}finally{O(t=>(0,K.A)((0,K.A)({},t),{},{[e]:!1}))}}},se=i,ae=(0,Y.useCallback)(e=>{var a,n;tt("User clicked upgrade",{app_id:(null==s?void 0:s.id)||null,user_id:(null==t?void 0:t.id)||null,user_tier:(null==t?void 0:t.subscription_tier)||null,conversation_id:(null==s||null===(a=s.conversation)||void 0===a?void 0:a.id)||null,cta:e,origin:"custom google auth",target_route:"/billing"}),ht({user_id:(null==t?void 0:t.id)||null,user_tier:(null==t?void 0:t.subscription_tier)||null,app_id:(null==s?void 0:s.id)||null,conversation_id:(null==s||null===(n=s.conversation)||void 0===n?void 0:n.id)||null},{cta:e,origin:"custom google auth",target_route:"/billing"})},[null==s?void 0:s.id,null==s||null===(e=s.conversation)||void 0===e?void 0:e.id,null==t?void 0:t.id,null==t?void 0:t.subscription_tier]),ne=()=>{if(R!==D)return!0;const e=Object.keys(B).some(e=>{const t=B[e],s=U[e];return(!Cg(t)||!Cg(s))&&(!(Cg(t)||!Cg(s))||t!==s)});return e},re=()=>{var e,t;if("custom"!==R)return!0;const s=null===(e=B.client_id)||void 0===e?void 0:e.trim(),a=null===(t=B.client_secret)||void 0===t?void 0:t.trim();return Boolean(s)&&Boolean(a)};return(0,le.jsxs)("div",{className:"max-w-4xl mx-auto p-4 space-y-6",children:[(0,le.jsx)("style",{jsx:!0,global:!0,children:"\n .selected-section {\n position: relative;\n border-left: 4px solid #334155;\n background-color: rgba(241, 245, 249, 0.7);\n box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);\n transition: all 0.4s ease;\n padding-left: 16px !important;\n padding-top: 14px !important;\n padding-bottom: 14px !important;\n margin: 4px 0 !important;\n border-radius: 4px;\n }\n\n /* Left border with animated glow */\n .selected-section::before {\n content: '';\n position: absolute;\n left: -4px;\n top: 0;\n width: 4px;\n height: 100%;\n background: linear-gradient(to bottom, #0f766e, #334155);\n box-shadow: 0 0 12px rgba(15, 118, 110, 0.5);\n animation: border-pulse 2.5s infinite ease-in-out;\n z-index: 1;\n }\n \n /* Light effect */\n .selected-section::after {\n content: '';\n position: absolute;\n left: 0;\n top: 0;\n height: 100%;\n width: 100%;\n background: linear-gradient(to right, rgba(15, 118, 110, 0.08), transparent 50%);\n animation: light-pulse 2.5s infinite ease-in-out;\n pointer-events: none;\n border-radius: 4px;\n }\n \n @keyframes border-pulse {\n 0%, 100% {\n box-shadow: 0 0 8px rgba(15, 118, 110, 0.4);\n }\n 50% {\n box-shadow: 0 0 20px rgba(15, 118, 110, 0.7);\n }\n }\n \n @keyframes light-pulse {\n 0%, 100% {\n opacity: 0.3;\n background: linear-gradient(to right, rgba(15, 118, 110, 0.05), transparent 50%);\n }\n 50% {\n opacity: 0.7;\n background: linear-gradient(to right, rgba(15, 118, 110, 0.12), transparent 60%);\n }\n }\n "}),(0,le.jsxs)("div",{className:"space-y-6",children:[(0,le.jsxs)("div",{children:[(0,le.jsx)("h2",{className:"text-2xl font-semibold text-gray-800",children:"Authentication"}),(0,le.jsxs)("p",{className:"text-gray-600 mt-1",children:["Configure the authentication methods that members of your app can use to log in to ",(null==s?void 0:s.name)||"(AppName)","."]})]}),null!=k&&k.sso_enabled&&null!=k&&k.apps_must_use_workspace_sso&&l&&!l.is_personal?(0,le.jsx)("div",{className:"bg-white border border-gray-200 rounded-lg p-4",children:(0,le.jsx)("div",{className:"flex items-start justify-between",children:(0,le.jsxs)("div",{className:"flex-1",children:[(0,le.jsxs)("div",{className:"flex items-center justify-between mb-1",children:[(0,le.jsx)("span",{className:"text-base font-medium text-gray-900",children:"Workspace SSO"}),(0,le.jsx)(ix,{checked:!0,disabled:!0,className:"data-[state=checked]:bg-teal-600 opacity-60"})]}),(0,le.jsx)("p",{className:"text-sm text-gray-600 mb-3",children:"Single Sign-On (SSO) is managed at the workspace level. All apps in this workspace use the same SSO provider configured by your admin."}),(0,le.jsxs)("div",{className:"flex items-center gap-4 text-sm text-gray-500",children:[(0,le.jsxs)("span",{children:["Workspace: ",l.name]}),(0,le.jsx)("span",{children:"\u2022"}),(0,le.jsxs)("span",{children:["Provider: ",k.sso_provider_name||"Configured"]})]})]})})}):(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)("div",{className:"space-y-3",children:H.map(e=>(0,le.jsx)(Eg,{provider:e.id,icon:e.icon,iconBg:e.iconBg,title:e.title,description:e.description,checked:T[e.id],onToggle:te,disabled:(!!yg(s).enable_sso_login||A)&&"email_password"!==e.id,forceUnchecked:(!!yg(s).enable_sso_login||A)&&"email_password"!==e.id,expanded:"google"===e.id,children:"google"===e.id&&(0,le.jsx)(Fi,{children:(0,le.jsxs)("div",{className:"p-4 flex flex-col gap-6",children:[(0,le.jsxs)(As,{value:R,onValueChange:M,className:"flex flex-col gap-6",children:[(0,le.jsxs)("div",{className:"inline-flex items-center gap-3",children:[(0,le.jsx)(Ss,{value:"default",id:"google-auth-default",className:"border-slate-300 text-slate-900"}),(0,le.jsx)("label",{htmlFor:"google-auth-default",className:"flex flex-col gap-1.5 cursor-pointer",children:(0,le.jsx)("div",{className:"text-slate-900 text-sm font-medium leading-none",children:"Use the default Base44 OAuth"})})]}),(0,le.jsxs)("div",{className:"flex flex-col gap-1.5",children:[(0,le.jsxs)("div",{className:"inline-flex items-center gap-3",children:[(0,le.jsx)(Ss,{value:"custom",id:"google-auth-custom",className:"border-slate-300 text-slate-900 self-start mt-0.5",disabled:!se}),(0,le.jsxs)("div",{className:"flex flex-col gap-1.5 flex-1",children:[(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[(0,le.jsx)("label",{htmlFor:"google-auth-custom",className:"text-slate-900 text-sm font-medium leading-none ".concat(se?"cursor-pointer":"cursor-not-allowed opacity-60"),children:"Use a custom OAuth from Google console"}),(0,le.jsxs)("div",{className:"inline-flex items-center gap-1 px-2 py-0.5 bg-orange-50 border border-orange-200 rounded-full",children:[(0,le.jsx)("div",{className:"w-1.5 h-1.5 bg-orange-400 rounded-full"}),(0,le.jsx)("span",{className:"text-xs font-medium text-orange-800",children:"Builder+"})]}),!se&&(0,le.jsx)("a",{href:"/billing",className:"text-orange-600 hover:text-orange-700 text-xs font-medium underline",onClick:e=>{e.stopPropagation(),ae("Upgrade now")},children:"Upgrade now"})]}),(0,le.jsxs)("div",{className:"text-slate-500 text-sm font-normal leading-tight ".concat(se?"":"opacity-60"),children:["Ensure users log in using your custom Google authentication."," ",(0,le.jsx)("a",{href:"https://docs.base44.com/Guides/Managing-login-and-registration#customizing-the-google-login",target:"_blank",rel:"noopener noreferrer",className:"text-blue-600 hover:text-blue-700 underline",onClick:e=>e.stopPropagation(),children:"Here's how to set it up"})]})]})]}),"custom"===R&&(0,le.jsx)("div",{className:"flex flex-col gap-6",children:(0,le.jsx)("div",{className:"pl-7 flex flex-col gap-3",children:(0,le.jsxs)("div",{className:"grid grid-cols-2 gap-6",children:[(0,le.jsxs)("div",{className:"flex flex-col",children:[(0,le.jsxs)("div",{className:"h-8 inline-flex items-center gap-1",children:[(0,le.jsx)(Ns,{className:"text-slate-500 text-sm font-normal leading-tight",children:"Client ID*"}),(0,le.jsxs)(Bi,{children:[(0,le.jsx)(zi,{asChild:!0,children:(0,le.jsx)(uo.A,{className:"w-4 h-4 text-slate-600 hover:text-slate-700"})}),(0,le.jsx)(Ui,{side:"bottom",children:(0,le.jsx)("p",{children:"The OAuth client ID from Google Console"})})]})]}),(0,le.jsx)(Sg,{className:"px-3 py-1.5 bg-white",type:"text",value:B.client_id,onChange:e=>se&&z((0,K.A)((0,K.A)({},B),{},{client_id:e})),onClear:()=>se&&z((0,K.A)((0,K.A)({},B),{},{client_id:""})),disabled:!se})]}),(0,le.jsxs)("div",{className:"flex flex-col",children:[(0,le.jsxs)("div",{className:"h-8 inline-flex items-center gap-1",children:[(0,le.jsx)(Ns,{className:"text-slate-500 text-sm font-normal leading-tight",children:"Client Secret*"}),(0,le.jsxs)(Bi,{children:[(0,le.jsx)(zi,{asChild:!0,children:(0,le.jsx)(uo.A,{className:"w-4 h-4 text-slate-600 hover:text-slate-700"})}),(0,le.jsx)(Ui,{side:"bottom",children:(0,le.jsx)("p",{children:"The OAuth client secret from Google Console (keep this confidential)"})})]})]}),(0,le.jsx)(Sg,{className:"px-3 py-1.5 bg-white",type:"password",value:B.client_secret,onChange:e=>se&&z((0,K.A)((0,K.A)({},B),{},{client_secret:e})),onClear:()=>se&&z((0,K.A)((0,K.A)({},B),{},{client_secret:""})),disabled:!se})]})]})})})]})]}),(0,le.jsx)("div",{className:"flex flex-col items-end gap-2.5",children:(0,le.jsx)(Yt,{onClick:ee,disabled:!se||q||!ne()||!re(),className:"h-9 px-4 py-2 bg-slate-900 hover:bg-slate-800 text-white rounded-lg shadow-sm",children:q?"Updating...":"Update"})})]})})},e.id))}),(0,le.jsxs)("div",{className:"flex items-center py-2",children:[(0,le.jsx)("div",{className:"flex-1 border-t border-gray-200"}),(0,le.jsx)("div",{className:"px-3 text-gray-500 text-sm font-medium",children:"or"}),(0,le.jsx)("div",{className:"flex-1 border-t border-gray-200"})]}),(0,le.jsxs)("div",{ref:J,className:"bg-white rounded-lg outline outline-1 outline-offset-[-1px] outline-gray-200 ".concat((ie="sso-settings",w===ie?"selected-section p-4 rounded-md":"")," ").concat(o?"":"opacity-75"),children:[(0,le.jsxs)("div",{className:"p-4 flex justify-start items-center gap-4",children:[(0,le.jsx)("div",{className:"w-10 h-10 bg-slate-900 rounded-lg border border-slate-900 flex items-center justify-center",children:(0,le.jsx)("svg",{className:"w-5 h-5 text-white",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,le.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z"})})}),(0,le.jsxs)("div",{className:"flex-1 flex flex-col justify-start items-start gap-0.5",children:[(0,le.jsxs)("div",{className:"flex justify-center items-center gap-2",children:[(0,le.jsx)("div",{className:"text-gray-900 text-sm font-medium leading-tight",children:"Single Sign-on (SSO)"}),null!=l&&l.is_enterprise?(0,le.jsx)(kg,{content:"Enterprise workspace feature",side:"top",children:(0,le.jsx)("div",{className:"inline-flex items-center gap-1 px-2 py-0.5 bg-blue-50 border border-blue-200 rounded-full",children:(0,le.jsx)("span",{className:"text-xs font-medium text-blue-800",children:"Enterprise"})})}):(0,le.jsx)(kg,{content:"Early-stage feature for feedback. Subject to change or removal.",side:"top",children:(0,le.jsxs)("div",{className:"inline-flex items-center gap-1 px-2 py-0.5 bg-orange-50 border border-orange-200 rounded-full",children:[(0,le.jsx)("div",{className:"w-1.5 h-1.5 bg-orange-400 rounded-full animate-pulse"}),(0,le.jsx)("span",{className:"text-xs font-medium text-orange-800",children:"Elite Early Preview"})]})})]}),(0,le.jsx)("div",{className:"self-stretch text-gray-500 text-sm font-normal leading-tight",children:"Allow members to log in using a custom SSO that fits your organization's needs."}),(0,le.jsx)("button",{onClick:()=>window.open("https://docs.base44.com/Guides/Setting-up-SSO","_blank","noopener,noreferrer"),className:"text-blue-600 text-sm font-medium hover:text-blue-700 underline",children:"Learn more about SSO"})]}),(0,le.jsx)("div",{className:"flex items-center gap-3",children:(yg(s).sso_provider_name||A||yg(s).use_workspace_sso)&&!f?(0,le.jsx)(ix,{id:"sso-toggle",checked:!0===yg(s).enable_sso_login||A||yg(s).use_workspace_sso,onCheckedChange:async e=>{if(m)return;if(A&&!e){u(!0);try{const e=(0,K.A)((0,K.A)({},yg(s)),{},{use_workspace_sso:!1});await a({auth_config:e}),S(!1),d({title:"Workspace SSO Disabled",description:"Your app will use its own authentication settings"})}catch(l){d({title:"Error",description:l.message||"Failed to disable workspace SSO",variant:"destructive"})}finally{u(!1)}return}yg(s).sso_provider_name;const t=(0,K.A)({},T),n=x;e?(P(e=>(0,K.A)((0,K.A)({},e),{},{google:!1,microsoft:!1,facebook:!1})),h(!0)):h(!1),u(!0);try{e?(await a({auth_config:(0,K.A)((0,K.A)({},s.auth_config),{},{sso_provider_name:"google",enable_sso_login:!0,enable_google_login:!1,enable_microsoft_login:!1,enable_facebook_login:!1})}),d({title:"SSO Enabled",description:"Single Sign-On has been enabled and social login providers have been disabled. Please configure your SSO settings."})):(await a({auth_config:(0,K.A)((0,K.A)({},s.auth_config),{},{enable_sso_login:!1})}),v(!1),d({title:"SSO Disabled",description:"Single Sign-On has been disabled"}))}catch(l){P(t),h(n),d({title:"Error",description:"Failed to update SSO settings",variant:"destructive"})}finally{u(!1)}},disabled:null==k?void 0:k.apps_must_use_workspace_sso}):f?(0,le.jsx)(ix,{id:"sso-toggle",checked:!1,onCheckedChange:()=>{},disabled:!0}):(0,le.jsx)(kg,{content:o?"Configure Single Sign-On for your app":"SSO is available for Elite tier and above or Enterprise workspaces",side:"left",children:(0,le.jsx)("button",{onClick:()=>{o&&(v(!0),h(!0),null!=k&&k.sso_enabled&&l&&!l.is_personal?(N("workspace_sso"),S(!0)):N("google"))},className:"px-4 py-2 border rounded-md text-xs font-medium leading-4 tracking-normal transition-colors ".concat(o?"bg-white border-gray-300 text-gray-700 hover:bg-gray-50":"bg-gray-100 border-gray-200 text-gray-400 cursor-not-allowed"),disabled:m||!o,children:m?"Setting up...":"Set Up"})})})]}),(yg(s).sso_provider_name||f||A||yg(s).use_workspace_sso)&&!x&&(0,le.jsx)("div",{className:"px-4 pb-4",children:(0,le.jsxs)("button",{onClick:()=>{const e=x;if(h(!x),e)N(""),g(new Set);else{const e=yg(s);A||e.use_workspace_sso?(N("workspace_sso"),S(!0)):e.sso_provider_name?$[e.sso_provider_name]?N(e.sso_provider_name):N("advanced"):null!=k&&k.sso_enabled&&l&&!l.is_personal?(N("workspace_sso"),S(!0)):N("google")}},className:"w-full h-10 flex items-center justify-between hover:bg-gray-50 transition-colors group bg-white rounded-md border border-gray-200",style:{paddingTop:"4px",paddingRight:"4px",paddingBottom:"4px",paddingLeft:"12px"},children:[(0,le.jsx)("div",{className:"text-gray-900 text-sm font-medium",children:f?"Set up SSO Configuration":((e,t,a)=>{const n=yg(s);return A||n.use_workspace_sso?"".concat((null==k?void 0:k.sso_provider_name)||"Workspace"," (Workspace SSO)"):(null===(e=$[n.sso_provider_name])||void 0===e?void 0:e.displayName)||(null===(t=n.sso_provider_name)||void 0===t?void 0:t.charAt(0).toUpperCase())+(null===(a=n.sso_provider_name)||void 0===a?void 0:a.slice(1))+" SSO"})()}),(0,le.jsxs)("div",{className:"flex items-center gap-2 text-gray-500",children:[(0,le.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,le.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15.232 5.232l3.536 3.536m-2.036-5.036a2.5 2.5 0 113.536 3.536L6.5 21.036H3v-3.572L16.732 3.732z"})}),(0,le.jsx)("span",{className:"text-sm",children:f?"Set up":"Configure"}),(0,le.jsx)(Is.A,{className:"w-4 h-4 transition-transform ".concat(x?"rotate-180":"")})]})]})}),x&&(yg(s).sso_provider_name||f||A||yg(s).use_workspace_sso)&&(0,le.jsx)("div",{className:"border-t border-gray-100 p-4 bg-white",children:(0,le.jsxs)("div",{className:"space-y-4",children:[(0,le.jsxs)("div",{children:[(0,le.jsx)("div",{className:"text-gray-500 text-sm font-normal leading-tight mb-2",children:"Select SSO Provider"}),(0,le.jsxs)(zs,{value:y,onValueChange:e=>{if(N(e),"workspace_sso"===e)return void S(!0);S(!1);const t=yg(s);if("advanced"===e){const e=t.sso_provider_name&&!$[t.sso_provider_name];j(e?e=>(0,K.A)((0,K.A)({},e),{},{name:t.sso_provider_name||e.name||"advanced"}):{name:"",client_id:"",client_secret:"",discovery_url:"",scope:"openid email profile",auth_endpoint:"",token_endpoint:"",userinfo_endpoint:"",jwks_uri:"",tenant_id:"",okta_domain:""})}else if(e&&$[e]){const s=$[e];if(t.sso_provider_name===e)j(e=>(0,K.A)((0,K.A)({},e),{},{name:s.name}));else{const e={name:s.name,client_id:"",client_secret:"",discovery_url:"",scope:"openid email profile",auth_endpoint:"",token_endpoint:"",userinfo_endpoint:"",jwks_uri:"",tenant_id:"",okta_domain:""},t=(0,K.A)((0,K.A)({},e),s.defaults);if(s.autoGenerate){const e=t[s.autoGenerate.field];if(e){const a=s.autoGenerate.template(e);t[s.autoGenerate.target]=a}}j(t)}}},children:[(0,le.jsx)(qs,{className:"w-full px-4 py-3 bg-white rounded-md shadow-sm outline outline-1 outline-offset-[-1px] outline-gray-200",children:(0,le.jsx)(Ws,{placeholder:"Select SSO Provider"})}),(0,le.jsx)(Ys,{children:Object.entries($).map(e=>{let[t,s]=e;return(0,le.jsx)($s,{value:t,children:s.displayName},t)})})]})]}),(e=>{if("workspace_sso"===e){const t=$[e];return t&&t.fields?(0,le.jsxs)("div",{className:"space-y-4",children:[t.fields.map(e=>(0,le.jsxs)("div",{children:[(0,le.jsx)(Ns,{className:"text-gray-500 text-sm",children:e.label}),(0,le.jsx)(fs,{className:"mt-1 w-full h-8 bg-gray-50",type:"text",value:e.value,readOnly:!0,disabled:!0})]},e.name)),(0,le.jsx)("div",{className:"text-sm text-gray-500",children:"SSO settings are managed at the workspace level."})]}):null}const t=X(e);if(!t.length)return null;const s=t.reduce((e,t)=>{const s=t.row||1;return e[s]||(e[s]=[]),e[s].push(t),e},{});return(0,le.jsx)("div",{className:"space-y-4",children:Object.entries(s).sort((e,t)=>{let[s]=e,[a]=t;return parseInt(s)-parseInt(a)}).map(t=>{let[s,a]=t;return(0,le.jsx)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:a.map((t,s)=>{var n,l,r,i;const o=a.length>1&&1===s,c=b[t.name]||"",d=t.placeholder||"Enter ".concat(t.name.replace("_"," ")),m=Ag(c),u="discovery_url"===t.name&&"discovery_url"===(null===(n=$[e])||void 0===n||null===(l=n.autoGenerate)||void 0===l?void 0:l.target)&&c;return(0,le.jsxs)("div",{children:[(0,le.jsxs)(Ns,{className:"text-gray-500 text-sm flex items-center gap-1",children:[t.name.replace("_"," ").replace(/\b\w/g,e=>e.toUpperCase()),t.required&&" *",t.name===(null===(r=$[e])||void 0===r||null===(i=r.autoGenerate)||void 0===i?void 0:i.target)&&c&&" (Auto-generated)",(0,le.jsx)(kg,{content:t.tooltip,side:o?"right":"left",children:(0,le.jsx)(uo.A,{className:"w-3.5 h-3.5 text-gray-400 hover:text-gray-600 cursor-help"})})]}),(0,le.jsx)(fs,{className:"mt-1 w-full h-8 ".concat(u?"bg-gray-50":""),type:"text",placeholder:d,value:m,onChange:e=>{Cg(e.target.value)||Q(t.name,e.target.value)},onFocus:e=>{Cg(m)&&(e.target.value="",Q(t.name,""))},readOnly:u})]},t.name)})},s)})})})(y),(0,le.jsxs)("div",{className:"flex justify-between pt-4",children:[(0,le.jsx)(Yt,{onClick:()=>{h(!1),f&&v(!1),N(""),g(new Set),"workspace_sso"!==y||yg(s).use_workspace_sso||S(!1)},variant:"outline",className:"border-gray-300 text-gray-700 hover:bg-gray-50",children:f?"Cancel Setup":"Dismiss"}),(0,le.jsx)(Yt,{onClick:"workspace_sso"===y?async()=>{u(!0);try{const e=(0,K.A)((0,K.A)({},yg(s)),{},{use_workspace_sso:!0,enable_sso_login:!1,sso_provider_name:null});await a({auth_config:e}),S(!0),h(!1),v(!1),N("workspace_sso"),P(e=>(0,K.A)((0,K.A)({},e),{},{google:!1,microsoft:!1,facebook:!1})),d({title:"Workspace SSO Enabled",description:"Your app will now use the workspace SSO settings"})}catch(e){d({title:"Error",description:e.message||"Failed to enable workspace SSO",variant:"destructive"})}finally{u(!1)}}:async()=>{u(!0);try{const e={};Object.keys(b).forEach(t=>{const s=b[t];!s||Cg(s)||!p.has(t)&&""===s||(e["sso_".concat(t)]=s)}),Object.keys(e).length>0&&await n(e);let t=null;y&&"advanced"!==y?t=y:"advanced"===y&&(t=b.name||"advanced");const l={sso_provider_name:t,enable_sso_login:!0,use_workspace_sso:!1};f&&(l.enable_google_login=!1,l.enable_microsoft_login=!1,l.enable_facebook_login=!1),await a({auth_config:(0,K.A)((0,K.A)({},s.auth_config),l)}),g(new Set),S(!1),f&&(v(!1),P(e=>(0,K.A)((0,K.A)({},e),{},{google:!1,microsoft:!1,facebook:!1}))),h(!1);const r=Object.keys(e).length;d({title:"Success",description:f?"SSO has been enabled and configured successfully":r>0?"SSO settings updated successfully (".concat(r," configuration").concat(1===r?"":"s"," saved)"):"SSO provider updated successfully"})}catch(e){d({title:"Error",description:"Failed to update SSO settings",variant:"destructive"})}finally{u(!1)}},disabled:m||!y||"workspace_sso"!==y&&X(y).some(e=>e.required&&!b[e.name]),className:"bg-gray-900 text-white",children:m?"Saving...":"workspace_sso"===y?"Enable Workspace SSO":f?"Enable SSO":"Save SSO Settings"})]})]})})]})]})]})]});var ie}const Tg=["value","onChange","language","readOnly","height","className","style","isSaving"],Pg=e=>{let{value:t,onChange:s,language:a="javascript",readOnly:n=!1,height:l,className:r,style:i,isSaving:o}=e,c=(0,Se.A)(e,Tg);const d={};return l&&(d.height=l),(0,le.jsxs)("div",{className:"relative h-full",children:[(0,le.jsx)(jr.KE,(0,K.A)((0,K.A)({defaultLanguage:a,value:t,onChange:e=>{s&&!n&&s(e)},options:{minimap:{enabled:!1},scrollBeyondLastLine:!1,fontSize:14,readOnly:n}},d),c)),o&&(0,le.jsx)("div",{className:"absolute top-2 right-2 bg-gray-700 text-white text-xs px-2 py-1 rounded opacity-70",children:"Saving..."})]})};const Lg=function(){var e;const{user:t}=oe(),{app:s}=Nt(),[a,n]=(0,Y.useState)(!1),[l,r]=(0,Y.useState)(Object.keys(s.entities)[0]||"EntityName"),[i,o]=(0,Y.useState)("javascript"),c=(null===(e=s.entities[l])||void 0===e?void 0:e.properties)||{},d=Object.keys(c).join(", "),m="// JavaScript Example: Reading Entities\n// Filterable fields: ".concat(d,"\nasync function fetch").concat(l,"Entities() {\n const response = await fetch(`").concat((0,ee.Gt)(),"/apps/").concat(s.id,"/entities/").concat(l,"`, {\n headers: {\n 'api_key': '").concat(t.api_key,"', // or use await User.me() to get the API key\n 'Content-Type': 'application/json'\n }\n });\n const data = await response.json();\n console.log(data);\n}\n\n// JavaScript Example: Updating an Entity\n// Filterable fields: ").concat(d,"\nasync function update").concat(l,"Entity(entityId, updateData) {\n const response = await fetch(`").concat((0,ee.Gt)(),"/apps/").concat(s.id,"/entities/").concat(l,"/${entityId}`, {\n method: 'PUT',\n headers: {\n 'api_key': '").concat(t.api_key,"', // or use await User.me() to get the API key\n 'Content-Type': 'application/json'\n },\n body: JSON.stringify(updateData)\n });\n const data = await response.json();\n console.log(data);\n}"),u="# Python Example: Reading Entities\n# Filterable fields: ".concat(d,"\nimport requests\n\ndef make_api_request(api_path, method='GET', data=None):\n url = f'").concat((0,ee.Gt)(),"/{api_path}'\n headers = {\n 'api_key': '").concat(t.api_key,"',\n 'Content-Type': 'application/json'\n }\n if method.upper() == 'GET':\n response = requests.request(method, url, headers=headers, params=data)\n else:\n response = requests.request(method, url, headers=headers, json=data)\n response.raise_for_status()\n return response.json()\n\nentities = make_api_request(f'apps/").concat(s.id,"/entities/").concat(l,"')\nprint(entities)\n\n# Python Example: Updating an Entity\n# Filterable fields: ").concat(d,"\ndef update_entity(entity_id, update_data):\n response = requests.put(\n f'").concat((0,ee.Gt)(),"/apps/").concat(s.id,"/entities/").concat(l,"/{entity_id}',\n headers={\n 'api_key': '").concat(t.api_key,"',\n 'Content-Type': 'application/json'\n },\n json=update_data\n )\n response.raise_for_status()\n return response.json()");return(0,le.jsx)(up,{title:"API Integration",subtitle:"Get copy-paste examples for API integration.",children:(0,le.jsx)(Qn,{children:(0,le.jsx)(sl,{className:"p-6",children:(0,le.jsx)(up,{className:"gap-4 p-0 text-lg",title:(0,le.jsx)("div",{className:"font-normal",children:"Example: API Operations"}),subtitle:"Select an entity to generate code examples for reading and updating:",filters:[Object.keys(s.entities||{}).length>0?(0,le.jsx)("div",{className:"min-w-[180px]",children:(0,le.jsxs)(In,{value:l,onValueChange:e=>r(e),children:[(0,le.jsx)(Pn,{children:(0,le.jsx)(Tn,{placeholder:"Select main page"})}),(0,le.jsx)(Rn,{children:Object.keys(s.entities).map(e=>(0,le.jsx)(Mn,{value:e,children:e},e))})]})}):null,(0,le.jsxs)("div",{className:"flex flex-row gap-2",children:[(0,le.jsx)(Hn,{variant:"javascript"===i?"secondary":"ghost",onClick:()=>o("javascript"),className:"".concat("javascript"===i?"font-bold":""),children:"JavaScript"}),(0,le.jsx)(Hn,{variant:"python"===i?"secondary":"ghost",onClick:()=>o("python"),className:"".concat("python"===i?"font-bold":""),children:"Python"})]})],children:(0,le.jsxs)("div",{className:"border rounded-md p-2 relative",children:[(0,le.jsx)(Pg,{value:"javascript"===i?m:u,language:i,readOnly:!0,height:"600px"}),(0,le.jsx)("div",{className:"absolute top-0 right-0",children:(0,le.jsx)(Hn,{variant:"outline",className:"w-9 m-2 shadow-lg",size:"sm",onClick:()=>(e=>{navigator.clipboard.writeText(e),n(!0),setTimeout(()=>n(!1),2e3)})("javascript"===i?m:u),children:a?(0,le.jsx)(Ps.A,{className:"h-4 w-4"}):(0,le.jsx)(or.A,{className:"h-4 w-4"})})})]})})})})})};var Og=s(51654);const Rg=["onClick","saveSize","className"],Mg=(0,Ee.cva)("rounded-full relative z-10",{variants:{saveSize:{sm:"h-5 w-5",default:"h-6 w-6",lg:"h-8 w-8",xl:"h-10 w-10"}},defaultVariants:{saveSize:"default"}});function Dg(e){let{onClick:t,saveSize:s="default",className:a}=e,n=(0,Se.A)(e,Rg);const l="sm"===s?"h-3 w-3":"lg"===s?"h-5 w-5":"xl"===s?"h-6 w-6":"h-4 w-4";return(0,le.jsx)(Hn,(0,K.A)((0,K.A)({},n),{},{onMouseDown:e=>{e.preventDefault(),e.stopPropagation(),n.disabled||t()},className:Pe(Mg({saveSize:s}),a),children:(0,le.jsx)(Ps.A,{className:l})}))}function Fg(e){let{initialText:t,onChange:s,className:a="",minWidth:n=60,maxWidth:l=280,validate:r}=e;const[i,o]=(0,Y.useState)(!1),[c,d]=(0,Y.useState)(t),[m,u]=(0,Y.useState)(t),[x,h]=(0,Y.useState)(n),[p,g]=(0,Y.useState)(!1),f=(0,Y.useRef)(null),v=(0,Y.useRef)(null),b=(0,Y.useRef)(null),j=()=>{if(b.current){const e=b.current.scrollWidth||b.current.offsetWidth,t=Math.min(Math.max(e,n),l),s=l;h(i?s:t),f.current&&(f.current.style.width="".concat(s,"px"))}};(0,Y.useEffect)(()=>{i&&f.current&&(f.current.focus(),j())},[i]),(0,Y.useEffect)(()=>{j()},[c,i,n,l]),(0,Y.useEffect)(()=>{d(t)},[t]);const y=()=>{u(c),o(!0)},N=()=>{g(!0),s(c),o(!1),g(!1)},w=()=>{d(m),o(!1)},_=()=>!r||r(c);return(0,le.jsxs)("div",{className:"inline-flex items-center group relative",children:[(0,le.jsxs)("div",{className:"relative",style:{minWidth:"".concat(n,"px"),maxWidth:"".concat(l,"px")},children:[i?(0,le.jsx)("input",{ref:f,type:"text",value:c,onChange:e=>{d(e.target.value)},onKeyDown:e=>{"Enter"===e.key?(e.preventDefault(),_()&&N()):"Escape"===e.key&&w()},onBlur:()=>{p||w()},className:"bg-transparent border-none outline-none p-0 m-0 ".concat(a),style:{font:"inherit",fontSize:"inherit",fontWeight:"inherit",lineHeight:"inherit",letterSpacing:"inherit",color:"inherit"}}):(0,le.jsx)("span",{ref:v,onClick:y,className:"cursor-pointer whitespace-nowrap overflow-hidden text-ellipsis block ".concat(a),children:c}),(0,le.jsx)("span",{ref:b,className:"absolute opacity-0 pointer-events-none whitespace-nowrap ".concat(a),style:{font:"inherit",fontSize:"inherit",fontWeight:"inherit",lineHeight:"inherit",letterSpacing:"inherit",top:0,left:0,zIndex:-1},children:c}),(0,le.jsx)("div",{className:"absolute bottom-0 left-0 h-0.5 transition-all duration-200 pointer-events-none ".concat(i?"bg-slate-400":"border-b-2 border-dashed border-slate-400 opacity-0 group-hover:opacity-100"),style:{width:"".concat(x,"px"),zIndex:1}})]}),(0,le.jsx)("div",{className:"ml-2 w-7 h-7 flex items-center justify-center relative",children:i?(0,le.jsx)(Dg,{onClick:N,disabled:!_(),saveSize:"lg",variant:"outline"}):(0,le.jsx)(Ql.A,{className:"h-5 w-5 text-slate-400 cursor-pointer",onClick:y})})]})}const Bg=()=>{const{user:e}=oe();return{hasFlag:t=>{var s;return(null==e||null===(s=e.feature_flags)||void 0===s?void 0:s.includes(t))||!1}}};function zg(e){let{onClosePublish:t}=e;const{app:s}=Nt(),a=(0,Z.Zp)(),{hasFlag:n}=Bg(),[l,r]=(0,Y.useState)(!1),[i,o]=(0,Y.useState)(!1),c=(e=>{if(!e||!e.entities)return!1;const t=Object.values(e.entities),s=t.length>0&&t.some(e=>!e.rls),a="public_without_login"===e.public_settings||"public_with_login"===e.public_settings;return s&&a})(s),d="security-warning-dismissed-".concat(s.id),m=n("show-publish-security-warning");(0,Y.useEffect)(()=>{"true"===localStorage.getItem(d)&&r(!0)},[d]);const u=()=>{i||(o(!0),t&&t(),a("/apps/".concat(s.id,"/editor/workspace/security?autoStartScan=1")),o(!1))};return c&&!l&&m?(0,le.jsx)("div",{className:"pt-2",children:(0,le.jsx)(De,{variant:"destructive",className:"border-amber-300 bg-amber-100 text-gray-800 p-3",children:(0,le.jsx)("div",{className:"flex items-start justify-between w-full",children:(0,le.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,le.jsx)("div",{className:"font-semibold text-gray-800 text-sm mb-1",children:(0,le.jsx)("span",{children:"Your app data is publicly accessible"})}),(0,le.jsxs)(Be,{className:"text-gray-800 text-sm ",children:["Run a security scan and follow the recommendations to protect it.",(0,le.jsx)("div",{className:"mt-3",children:(0,le.jsx)(Yt,{size:"sm",onClick:u,disabled:i,className:"bg-amber-300 hover:bg-amber-400 text-gray-800 font-medium h-6 px-4 py-4 rounded-md",children:i?"Starting scan\u2026":"Run Security Scan"})})]})]})})})}):null}var Ug=s(61165);function Wg(e){let{app:t}=e;const{workspaces:s}=ge(),{user:a}=oe(),{toast:n}=nn(),[l,r]=((0,Z.Zp)(),(0,Y.useState)(!1)),[i,o]=(0,Y.useState)(""),[c,d]=(0,Y.useState)(!1),m=(null==t?void 0:t.organization_id)===(null==a?void 0:a.organization_id),u=(null==t?void 0:t.organization_id)===(null==a?void 0:a.personal_organization_id),x=null==s?void 0:s.find(e=>e.id===(null==t?void 0:t.organization_id)),h=!0===(null==x?void 0:x.is_personal),p=m||u||h,g=(null==s?void 0:s.filter(e=>!e.is_personal&&e.id!==(null==a?void 0:a.personal_organization_id)&&e.user_role))||[];return p?0===g.length?null:(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(is,{className:"mt-4",children:(0,le.jsx)(ms,{className:"p-4",children:(0,le.jsxs)("div",{className:"flex items-center justify-between",children:[(0,le.jsxs)("div",{children:[(0,le.jsx)("h3",{className:"text-base font-semibold",children:"Move to Workspace"}),(0,le.jsx)("p",{className:"text-gray-600 text-xs mt-1",children:"Move this app from your personal workspace to a shared workspace"})]}),(0,le.jsxs)(Yt,{variant:"outline",size:"sm",onClick:()=>r(!0),className:"gap-1.5",children:[(0,le.jsx)(Ug.A,{className:"w-3.5 h-3.5"}),"Move App"]})]})})}),(0,le.jsx)(Pa,{open:l,onOpenChange:r,children:(0,le.jsxs)(Da,{className:"sm:max-w-md",children:[(0,le.jsxs)(Fa,{children:[(0,le.jsx)(za,{children:"Move App to Workspace"}),(0,le.jsx)(Ua,{children:"Select a workspace to move this app to. This action cannot be undone."})]}),(0,le.jsxs)("div",{className:"py-4 space-y-4",children:[(0,le.jsxs)("div",{children:[(0,le.jsx)("label",{className:"text-sm font-medium mb-2 block",children:"Target Workspace"}),(0,le.jsxs)(zs,{value:i,onValueChange:o,children:[(0,le.jsx)(qs,{children:(0,le.jsx)(Ws,{placeholder:"Select a workspace"})}),(0,le.jsx)(Ys,{children:g.map(e=>(0,le.jsx)($s,{value:e.id,children:e.name},e.id))})]})]}),(0,le.jsxs)("div",{className:"text-sm text-gray-600 space-y-2",children:[(0,le.jsxs)("p",{children:["\u26a0\ufe0f ",(0,le.jsx)("strong",{children:"Important:"})]}),(0,le.jsxs)("ul",{className:"list-disc list-inside space-y-1 text-xs",children:[(0,le.jsx)("li",{children:"The app will be moved to the selected workspace"}),(0,le.jsx)("li",{children:"Future usage will count against the new workspace's credits"}),(0,le.jsx)("li",{children:"Workspace members with appropriate permissions will gain access"}),(0,le.jsx)("li",{children:"You will retain ownership as the app creator"})]})]})]}),(0,le.jsxs)(Ba,{children:[(0,le.jsx)(Yt,{variant:"outline",onClick:()=>r(!1),children:"Cancel"}),(0,le.jsx)(Yt,{onClick:async()=>{if(i){d(!0);try{await ve.moveToWorkspace(t.id,i),n({title:"Success",description:"App moved to workspace successfully"}),window.location.reload()}catch(a){var e,s;n({title:"Error",description:(null===(e=a.response)||void 0===e||null===(s=e.data)||void 0===s?void 0:s.detail)||"Failed to move app to workspace",variant:"destructive"})}finally{d(!1),r(!1)}}else n({title:"Error",description:"Please select a target workspace",variant:"destructive"})},disabled:!i||c,children:c?"Moving...":"Move App"})]})]})})]}):null}function qg(){var e,t;const{app:s,updateApp:a}=Nt(),{isInSharedWorkspace:n}=Vp(),{settings:l,userRole:r,isEnterpriseWorkspace:i}=Gp(),o=(0,Z.Zp)(),{toast:c}=nn(),[d,m]=(0,Y.useState)(!1),[u,x]=(0,Y.useState)(!1),[h,p]=(0,Y.useState)(!1),[g,f]=(0,Y.useState)(!1),[v,b]=(0,Y.useState)(!1),[j,y]=(0,Y.useState)(""),[N,w]=(0,Y.useState)([]),[_,k]=(0,Y.useState)(!1);(0,Y.useEffect)(()=>{(async()=>{if(null!=s&&s.id)try{const e=await Ya.filter({app_id:s.id});w(e)}catch(e){}})()},[null==s?void 0:s.id]);const C=N.length>0?"https://".concat(N[0].domain):fa(s);(0,Y.useEffect)(()=>{s.user_description&&y(s.user_description)},[s.user_description]);return(0,le.jsxs)("div",{className:"h-full bg-gray-50 p-4 sm:p-6",children:[(0,le.jsxs)("div",{className:"max-w-6xl mx-auto",children:[(0,le.jsxs)("div",{className:"space-y-6 mb-8",children:[(0,le.jsxs)("div",{className:"flex flex-col sm:flex-row gap-4 sm:gap-6 items-start sm:items-center",children:[(0,le.jsxs)("div",{className:"relative cursor-pointer",onClick:()=>k(!0),children:[(0,le.jsx)("div",{className:"h-full w-full pointer-events-auto bg-[rgba(0,0,0,0.4)] flex opacity-0 hover:opacity-100 transition-opacity duration-300 absolute rounded-xl items-center justify-center",children:(0,le.jsx)(Ql.A,{color:"white",className:"h-5 w-5"})}),(0,le.jsx)("div",{className:"shrink-0 w-16 sm:w-20 h-16 sm:h-20 rounded-xl bg-white shadow p-0 flex items-center justify-center",children:s.logo_url?(0,le.jsx)("img",{src:s.logo_url,alt:"".concat(s.name," logo"),className:"w-full h-full object-contain rounded-xl"}):(0,le.jsx)("div",{className:"p-1 bg-gray-100 rounded-xl flex items-center justify-center",children:(0,le.jsx)("span",{className:"text-xl font-bold text-gray-400",children:(null===(e=s.name)||void 0===e||null===(t=e[0])||void 0===t?void 0:t.toUpperCase())||"A"})})})]}),(0,le.jsxs)("div",{className:"flex-grow min-w-0",children:[(0,le.jsxs)("div",{className:"flex items-center justify-between flex-wrap",children:[(0,le.jsx)("h1",{className:"text-2xl font-bold text-gray-900",children:(0,le.jsx)(Fg,{initialText:s.name||"untitled",onChange:async e=>{var t;"ready"===(null===(t=s.status)||void 0===t?void 0:t.state)?0!==e.length?a({name:e}):c({title:"Error",description:"App name cannot be empty",variant:"destructive"}):c({title:"Error",description:"App is still loading... name not updated",variant:"destructive"})},validate:e=>e.trim().length>0})}),(0,le.jsx)(Yt,{variant:"ghost",size:"sm",onClick:()=>{a({is_starred:!s.is_starred}),c({title:s.is_starred?"Removed from favorites":"Added to favorites",description:s.is_starred?"App removed from your starred list":"App added to your starred list"})},className:"hover:bg-yellow-100 transition-colors ".concat(s.is_starred?"text-yellow-500":"text-gray-400"),children:(0,le.jsx)(Cl.A,{className:"h-4 w-4 ".concat(s.is_starred?"fill-current":"")})})]}),(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[(0,le.jsx)("p",{className:"text-gray-600 text-sm mt-1",children:s.user_description}),(0,le.jsx)(Yt,{variant:"ghost",size:"sm",onClick:()=>{y(s.user_description||""),b(!0)},className:"mt-1 p-1 pr-3 h-auto",children:(0,le.jsx)(Ql.A,{className:"h-3 w-3 text-gray-400"})})]}),(0,le.jsxs)("p",{className:"text-xs text-muted-foreground mt-1",children:["Created ",ra().utc(s.created_date).fromNow()]})]})]}),(0,le.jsxs)("div",{className:"flex flex-wrap gap-3",children:[(0,le.jsxs)(Yt,{variant:"outline",onClick:()=>{o("/apps/".concat(s.id,"/editor/preview/").concat(Object.keys(s.pages)[0]))},className:"gap-1.5 w-36 h-10",children:[(0,le.jsx)(Tr.A,{className:"w-4 h-4"}),"Open App"]}),(0,le.jsxs)(Yt,{variant:"outline",onClick:()=>p(!0),className:"gap-1.5 w-36 h-10",children:[(0,le.jsx)(Wa.A,{className:"w-4 h-4 ml-[-8px]"}),(0,le.jsxs)("div",{className:"flex flex-col items-start",children:[(0,le.jsx)("span",{className:"mb-[-6px]",children:"Share App"}),(0,le.jsx)("span",{className:"text-[9px] mb-[-3px] text-gray-500",children:"win free credits!"})]})]})]})]}),(0,le.jsxs)("div",{className:"grid sm:grid-cols-2 gap-4",children:[(0,le.jsx)(is,{children:(0,le.jsxs)(ms,{className:"p-4",children:[(0,le.jsx)("div",{className:"flex items-center justify-between mb-6",children:(0,le.jsxs)("div",{children:[(0,le.jsx)("h3",{className:"text-base font-semibold",children:"App Visibility"}),(0,le.jsx)("p",{className:"text-gray-600 text-xs mt-1",children:"Control who can access your application"})]})}),(0,le.jsxs)("div",{children:[(0,le.jsx)(ag,{value:s.public_settings||"private_with_login",onValueChange:async e=>{m(!0);try{await a({public_settings:e})}finally{m(!1)}},disabled:d,showWorkspace:n,allowedOptions:$p(s.public_settings,l,r,i)}),(0,le.jsx)(zg,{})]})]})}),(0,le.jsx)(is,{children:(0,le.jsxs)(ms,{className:"p-4",children:[(0,le.jsxs)("div",{className:"flex items-start justify-between mb-6",children:[(0,le.jsxs)("div",{children:[(0,le.jsx)("h3",{className:"text-base font-semibold mb-1",children:"Invite Users"}),(0,le.jsx)("p",{className:"text-gray-600 text-xs",children:"Grow your user base by inviting others"})]}),(0,le.jsx)(Xl.A,{className:"w-4 h-4 text-gray-400"})]}),(0,le.jsxs)("div",{className:"flex gap-2",children:[(0,le.jsxs)(Yt,{variant:"outline",className:"w-full h-10 text-sm",onClick:()=>{return e=C,navigator.clipboard.writeText(e),f(!0),void setTimeout(()=>f(!1),2e3);var e},children:[(0,le.jsx)(or.A,{className:"w-3 h-3 mr-1"}),g?"Copied!":"Copy Link"]}),(0,le.jsx)(Yt,{className:"w-full h-10 text-sm bg-blue-600 hover:bg-blue-700",onClick:()=>x(!0),children:"Send Invites"})]})]})})]}),(0,le.jsx)(Wg,{app:s}),!0===s.is_remixable&&(0,le.jsx)(is,{className:"mt-4",children:(0,le.jsx)(ms,{className:"p-4",children:(0,le.jsxs)("div",{className:"flex items-center justify-between",children:[(0,le.jsxs)("div",{children:[(0,le.jsx)("h3",{className:"text-base font-semibold",children:"Platform Badge"}),(0,le.jsx)("p",{className:"text-gray-600 text-xs mt-1",children:'The "Edit with Base44" badge is currently visible on your app.'})]}),(0,le.jsxs)(Yt,{variant:"outline",size:"sm",onClick:()=>{o("/apps/".concat(s.id,"/editor/workspace/app-settings?selectedParam=platform-badge"))},className:"gap-1.5",children:[(0,le.jsx)(Og.A,{className:"w-3.5 h-3.5"}),"Hide Badge"]})]})})})]}),(0,le.jsx)(gg,{isOpen:_,onClose:()=>k(!1)}),(0,le.jsx)(gp,{isVisible:u,onCancel:()=>x(!1),onInviteSuccess:()=>x(!1)}),(0,le.jsx)(Ga,{app:s,isOpen:h,onClose:()=>p(!1)}),(0,le.jsx)(Pa,{open:v,onOpenChange:b,children:(0,le.jsxs)(Da,{className:"sm:max-w-md",children:[(0,le.jsxs)(Fa,{children:[(0,le.jsx)(za,{children:"Edit App Description"}),(0,le.jsx)(Ua,{children:"Provide a brief description of your app's purpose and functionality."})]}),(0,le.jsx)("div",{className:"py-4",children:(0,le.jsx)(um,{value:j,onChange:e=>y(e.target.value),placeholder:"Describe your app...",className:"min-h-[100px]"})}),(0,le.jsxs)(Ba,{children:[(0,le.jsx)(Yt,{variant:"outline",onClick:()=>b(!1),children:"Cancel"}),(0,le.jsx)(Yt,{onClick:async()=>{try{await a({user_description:j}),b(!1),c({title:"Description updated",description:"Your app description has been updated successfully"})}catch(e){c({title:"Error",description:"Failed to update app description",variant:"destructive"})}},children:"Save"})]})]})})]})}var Vg=s(45833);const Hg=function(){const{app:e}=Nt(),[t,s]=(0,Y.useState)(1),[a,n]=(0,Y.useState)(null),[l,r]=(0,Y.useState)({userEmail:"",showFailuresOnly:!1,logType:"all"}),{data:i,isLoading:o,refetch:c}=uu({query:async()=>{const{userEmail:s,showFailuresOnly:a,logType:n}=l;let r=(0,K.A)((0,K.A)((0,K.A)({},s&&{user_email:s}),a&&{status:"error"}),"all"!==n&&{log_type:n});return wa.fetchLogs(e.id,{sort:"-created_date",q:r,skip:50*(t-1),limit:50})},initialData:[],enabled:!(null==e||!e.id),logErrorMsg:"Error fetching logs"},[null==e?void 0:e.id,l,t,50]),d=e=>{switch(e){case"error":return(0,le.jsx)(St,{children:(0,le.jsxs)(Et,{children:[(0,le.jsx)(It,{asChild:!0,children:(0,le.jsx)("div",{children:(0,le.jsx)(_e.A,{className:"text-destructive",size:16})})}),(0,le.jsx)(Tt,{children:(0,le.jsx)("p",{children:"Error"})})]})});case"success":return(0,le.jsx)(St,{children:(0,le.jsxs)(Et,{children:[(0,le.jsx)(It,{asChild:!0,children:(0,le.jsx)("div",{children:(0,le.jsx)(Vg.A,{className:"text-success",size:16})})}),(0,le.jsx)(Tt,{children:(0,le.jsx)("p",{children:"Success"})})]})});default:return(0,le.jsx)(St,{children:(0,le.jsxs)(Et,{children:[(0,le.jsx)(It,{asChild:!0,children:(0,le.jsx)("div",{children:(0,le.jsx)(uo.A,{className:"text-primary",size:16})})}),(0,le.jsx)(Tt,{children:(0,le.jsx)("p",{children:"Info"})})]})})}},m=[...new Set(i.map(e=>e.log_type))];return(0,le.jsxs)(up,{title:"Logs Explorer",subtitle:"Monitor system logs across your application.",actions:[(0,le.jsxs)(Hn,{variant:"outline",size:"sm",onClick:()=>{c()},children:[(0,le.jsx)(nx.A,{className:"h-4 w-4 mr-1"}),"Refresh"]}),(0,le.jsx)(Hn,{variant:"outline",size:"sm",disabled:!0,children:"Export Logs"})],filters:[(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[(0,le.jsx)(vn.A,{className:"h-4 w-4 text-muted-foreground"}),(0,le.jsx)(fs,{placeholder:"Filter by email...",className:"h-8 w-44",value:l.userEmail,onChange:e=>r(t=>(0,K.A)((0,K.A)({},t),{},{userEmail:e.target.value}))})]}),(0,le.jsxs)(zs,{value:l.logType,onValueChange:e=>r(t=>(0,K.A)((0,K.A)({},t),{},{logType:e})),children:[(0,le.jsx)(qs,{className:"h-8 w-36",children:(0,le.jsx)(Ws,{placeholder:"Log type"})}),(0,le.jsxs)(Ys,{children:[(0,le.jsx)($s,{value:"all",children:"All types"}),m.map(e=>(0,le.jsx)($s,{value:e,children:e},e))]})]}),(0,le.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,le.jsx)(dm,{id:"showFailures",checked:l.showFailuresOnly,onCheckedChange:e=>r(t=>(0,K.A)((0,K.A)({},t),{},{showFailuresOnly:!!e}))}),(0,le.jsx)("label",{htmlFor:"showFailures",className:"text-sm cursor-pointer",children:"Errors only"})]}),(0,le.jsxs)(Hn,{className:"w-min",variant:"ghost",size:"sm",onClick:()=>r({userEmail:"",showFailuresOnly:!1,logType:"all"}),children:[(0,le.jsx)(Bt.A,{className:"h-3.5 w-3.5 md:mr-1"}),"Clear"]})],children:[o?(0,le.jsx)("div",{className:"flex h-40 items-center justify-center",children:(0,le.jsx)("div",{className:"h-8 w-8 animate-spin rounded-full border-4 border-primary border-t-transparent"})}):(0,le.jsx)("div",{className:"rounded-md border bg-card",children:(0,le.jsxs)(zl,{children:[(0,le.jsx)(Ul,{children:(0,le.jsxs)(Vl,{children:[(0,le.jsx)(Hl,{className:"w-12"}),(0,le.jsx)(Hl,{children:"Type"}),(0,le.jsx)(Hl,{children:"User"}),(0,le.jsx)(Hl,{children:"Timestamp"}),(0,le.jsx)(Hl,{className:"w-10"})]})}),(0,le.jsx)(Wl,{children:0===i.length?(0,le.jsx)(Vl,{children:(0,le.jsx)(Yl,{colSpan:5,className:"h-32 text-center text-muted-foreground",children:"No logs found"})}):i.map((e,t)=>{return(0,le.jsxs)(Y.Fragment,{children:[(0,le.jsxs)(Vl,{className:(null==a?void 0:a.created_date)===e.created_date?"bg-muted/50":"",children:[(0,le.jsx)(Yl,{className:"pr-0",children:d(e.status)}),(0,le.jsx)(Yl,{className:"font-medium",children:e.object_name||e.log_type}),(0,le.jsx)(Yl,{className:"text-sm text-muted-foreground",children:e.user_email}),(0,le.jsx)(Yl,{className:"text-sm text-muted-foreground",children:(s=e.created_date,new Date(s).toLocaleString())}),(0,le.jsx)(Yl,{className:"text-right",children:(0,le.jsx)(Hn,{variant:"ghost",size:"sm",onClick:()=>n((null==a?void 0:a.created_date)===e.created_date?null:e),children:(null==a?void 0:a.created_date)===e.created_date?(0,le.jsx)(Ts.A,{size:16}):(0,le.jsx)(Is.A,{size:16})})})]}),(null==a?void 0:a.created_date)===e.created_date&&(0,le.jsx)(Vl,{children:(0,le.jsx)(Yl,{colSpan:5,className:"p-0",children:(0,le.jsx)("div",{className:"bg-muted/30 px-6 py-3",children:(0,le.jsxs)("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-2",children:[(0,le.jsxs)("div",{children:[(0,le.jsx)("h4",{className:"mb-2 text-sm font-semibold",children:"Inputs"}),(0,le.jsx)("pre",{className:"max-h-60 overflow-auto rounded bg-card p-2 text-xs",children:JSON.stringify(e.inputs,null,2)})]}),e.outputs&&(0,le.jsxs)("div",{children:[(0,le.jsx)("h4",{className:"mb-2 text-sm font-semibold",children:"Outputs"}),(0,le.jsx)("pre",{className:"max-h-60 overflow-auto rounded bg-card p-2 text-xs",children:JSON.stringify(e.outputs,null,2)})]}),e.error&&(0,le.jsxs)("div",{className:e.outputs?"col-span-2":"",children:[(0,le.jsx)("h4",{className:"mb-2 text-sm font-semibold text-destructive",children:"Error"}),(0,le.jsx)("pre",{className:"max-h-60 overflow-auto rounded bg-destructive/10 p-2 text-xs text-destructive-foreground",children:e.error})]})]})})})})]},t);var s})})]})}),(0,le.jsxs)("div",{className:"flex items-center justify-between",children:[(0,le.jsx)(Hn,{variant:"outline",size:"sm",disabled:1===t,onClick:()=>s(e=>Math.max(1,e-1)),children:"Previous"}),(0,le.jsxs)("span",{className:"text-sm text-muted-foreground",children:["Page ",t]}),(0,le.jsx)(Hn,{variant:"outline",size:"sm",disabled:i.length<50,onClick:()=>s(e=>e+1),children:"Next"})]})]})};var Yg=s(45403),Gg=s(81850);const $g=jh.bL,Jg=jh.l9,Zg=Y.forwardRef((e,t)=>(0,le.jsx)(_h,(0,K.A)({ref:t},e)));Zg.displayName=jh.UC.displayName;const Kg=["className","classNames","showOutsideDays"];function Qg(e){let{className:t,classNames:s,showOutsideDays:a=!0}=e,n=(0,Se.A)(e,Kg);return(0,le.jsx)(fh,(0,K.A)({className:t,classNames:s,showOutsideDays:a},n))}Qg.displayName="Calendar";const Xg=e=>{let{data:t,title:s="Bar Chart",barColor:a="#2A9D90;",maxWidth:n="800px",maxLabelWidth:l="150px",backgroundColor:r="white",textColor:i="#1f2937",className:o,renderLabel:c=e=>e.name,renderValue:d=e=>e.value}=e;const[m,u]=(0,Y.useState)(!1),x=Math.max(...t.map(e=>e.value)),h=t.length;(0,Y.useEffect)(()=>{u(!1);const e=setTimeout(()=>u(!0),100);return()=>clearTimeout(e)},[]);const p=h<=5?"40px":h<=10?"32px":h<=20?"24px":"16px",g=h<=5?"14px":h<=10?"12px":h<=20?"10px":"8px";return(0,le.jsxs)("div",{className:o,style:{width:"100%",maxWidth:n,backgroundColor:r,overflow:"hidden"},children:[s&&(0,le.jsx)("h2",{style:{fontSize:"24px",fontWeight:"bold",marginBottom:"24px",color:i,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:s}),(0,le.jsxs)("div",{className:"text-[".concat(g,"] text-[").concat(i,"]"),style:{display:"grid",gridTemplateColumns:"max-content 1fr",gap:"10px",gridTemplateRows:"repeat(".concat(t.length,", ").concat(p,")")},children:[(0,le.jsx)("div",{className:"align-left max-w-[".concat(l,"]"),children:t.map((e,t)=>{let{name:s}=e;return(0,le.jsx)("div",{className:"align-middle h-[".concat(p,"] flex items-center"),children:s},t)})}),(0,le.jsx)("div",{children:t.map((e,t)=>{let{value:s}=e;return(0,le.jsxs)("div",{className:"p-1 flex row gap-1 align-middle h-[".concat(p,"]"),children:[(0,le.jsx)("div",{className:"bg-[".concat(a,"] w-[").concat((m?s:0)/x*100,"%] rounded-lg"),style:{transition:"width 0.5s ease-in-out"}},t),(0,le.jsx)("div",{className:"align-middle flex items-center ",children:s},t)]})})})]})]})};var ef=s(68354),tf=s(10734);function sf(){const{state:e,updateState:t}=(()=>{var e,t;const{app:s}=Nt(),a=s.id,[n,l]=(0,Y.useState)({appId:a,pageNames:Object.keys(s.pages),date:{from:void 0,to:void 0},selectedPage:"all",selectedUser:null,showAllUsers:!1}),r=e=>{l(t=>(0,K.A)((0,K.A)({},t),e))},{isLoading:i,data:o}=uu({query:()=>{var e,t;return wa.getStats(a,{date_from:null!==(e=n.date)&&void 0!==e&&e.from?(0,vh.GP)(n.date.from,"yyyy-MM-dd"):void 0,date_to:null!==(t=n.date)&&void 0!==t&&t.to?(0,vh.GP)(n.date.to,"yyyy-MM-dd"):void 0,page_name:"all"!==n.selectedPage?n.selectedPage:void 0,user_email:n.selectedUser?n.selectedUser:void 0})},initialData:null,logErrorMsg:"Failed to fetch stats",onLoading(e){r({isLoading:e})},onSuccess(e){r({stats:e})}},[a,null===(e=n.date)||void 0===e?void 0:e.from,null===(t=n.date)||void 0===t?void 0:t.to,n.selectedPage,n.selectedUser]);return{state:(0,K.A)((0,K.A)({},n),{},{isLoading:i,stats:o}),updateState:r}})(),{appId:s,selectedPage:a,showAllUsers:n,stats:l}=e;return l?(0,le.jsxs)(up,{title:"Analytics",subtitle:"Manage your app\u2019s data",filters:(0,le.jsx)(af,{updateState:t,state:e}),children:[(0,le.jsx)(nf,{stats:l}),(0,le.jsx)(lf,{updateState:t,stats:l,showAllUsers:n}),(0,le.jsx)(rf,{stats:l,selectedPage:a,appId:s}),(0,le.jsx)(of,{stats:l}),(0,le.jsx)(cf,{stats:l})]}):(0,le.jsx)("div",{className:"h-full w-full flex items-center justify-center",children:(0,le.jsx)(Ne.A,{className:"h-8 w-8 animate-spin text-muted-foreground"})})}const af=e=>{let{state:t,updateState:s}=e;const{date:a,selectedPage:n,pageNames:l,selectedUser:r,isLoading:i}=t;return(0,le.jsxs)("div",{className:"flex flex-col sm:flex-row gap-3",children:[(0,le.jsxs)($g,{children:[(0,le.jsx)(Jg,{asChild:!0,children:(0,le.jsxs)(Hn,{variant:"outline",className:Pe("w-full sm:w-[240px] justify-start text-left font-normal",!a&&"text-muted-foreground"),children:[(0,le.jsx)(bh.A,{className:"mr-2 h-4 w-4"}),null!=a&&a.from?a.to?(0,le.jsxs)(le.Fragment,{children:[(0,vh.GP)(a.from,"LLL dd, y")," - ",(0,vh.GP)(a.to,"LLL dd, y")]}):(0,vh.GP)(a.from,"LLL dd, y"):(0,le.jsx)("span",{children:"Pick a date range"})]})}),(0,le.jsx)(Zg,{className:"w-auto p-0",align:"start",children:(0,le.jsx)(Qg,{initialFocus:!0,mode:"range",defaultMonth:null==a?void 0:a.from,selected:a,onSelect:e=>s({date:{to:null==e?void 0:e.to,from:null==e?void 0:e.from}}),numberOfMonths:1})})]}),(0,le.jsxs)(In,{value:n,onValueChange:e=>s({selectedPage:e}),children:[(0,le.jsx)(Pn,{className:"w-full sm:w-[240px]",children:(0,le.jsx)(Tn,{placeholder:"Filter by page"})}),(0,le.jsxs)(Rn,{children:[(0,le.jsx)(Mn,{value:"all",children:"All Pages"}),null==l?void 0:l.map(e=>(0,le.jsx)(Mn,{value:e,children:e},e))]})]}),r&&(0,le.jsxs)("div",{className:"flex items-center gap-2 bg-muted px-3 py-2 rounded-md",children:[(0,le.jsxs)("span",{className:"text-sm",children:["Filtered by user: ",r]}),(0,le.jsx)("button",{onClick:()=>s({selectedUser:null}),className:"text-muted-foreground hover:text-foreground",children:(0,le.jsx)(Gg.A,{className:"h-4 w-4"})})]}),i&&(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[(0,le.jsx)(Ne.A,{className:"h-4 w-4 animate-spin text-muted-foreground"}),(0,le.jsx)("span",{className:"text-sm text-muted-foreground",children:"Updating..."})]})]})},nf=e=>{let{stats:t}=e;return(0,le.jsx)(Qn,{children:(0,le.jsxs)(Xn,{className:"py-6",children:[(0,le.jsx)(el,{className:"text-lg",children:(null==t?void 0:t.unique_users_count)||0}),(0,le.jsx)(tl,{children:"Total Unique Users"})]})})},lf=e=>{var t,s;let{stats:a,updateState:n,showAllUsers:l}=e;const r=null!=a&&a.top_users?l?a.top_users:null===(t=a.top_users)||void 0===t?void 0:t.slice(0,5):[],i=(null==a||null===(s=a.top_users)||void 0===s?void 0:s.length)>5;return 0===r.length?null:(0,le.jsxs)(Qn,{children:[(0,le.jsx)(Xn,{children:(0,le.jsx)(el,{children:"Top Users"})}),(0,le.jsx)(sl,{children:(0,le.jsxs)("div",{className:"space-y-2",children:[null==r?void 0:r.map((e,t)=>(0,le.jsxs)("div",{className:"flex justify-between items-center text-sm cursor-pointer hover:bg-muted rounded-md",onClick:()=>n({selectedUser:e.email}),children:[(0,le.jsx)("span",{className:"truncate max-w-[180px]",children:e.email}),(0,le.jsxs)("span",{className:"font-semibold",children:[e.visits," visits"]})]},t)),i&&(0,le.jsx)(Hn,{variant:"ghost",className:"w-full mt-2 text-sm text-muted-foreground hover:text-foreground",onClick:()=>n({showAllUsers:!l}),children:l?(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(Ts.A,{className:"h-4 w-4 mr-2"})," Show Less"]}):(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(Is.A,{className:"h-4 w-4 mr-2"})," Show More Users"]})})]})})]})},rf=e=>{var t,s;let{stats:a,selectedPage:n,appId:l}=e;const r=(null!==(t="all"===n?null==a?void 0:a.top_pages:null===(s=a.top_pages)||void 0===s?void 0:s.filter(e=>e.url===n))&&void 0!==t?t:[]).map(e=>({name:e.page_name,value:e.visits}));return(0,le.jsxs)(Qn,{children:[(0,le.jsxs)(Xn,{children:[(0,le.jsx)(el,{children:"Top Pages"}),(0,le.jsx)(tl,{children:"Shows the most visited pages in your app and their total visit count"})]}),(0,le.jsx)(sl,{children:(0,le.jsx)(Xg,{data:r,title:"",maxWidth:"80%",backgroundColor:"transparent",renderLabel:e=>"all"===l?(0,le.jsx)(J.Link,{to:"/apps/".concat(e.name),target:"_blank",className:"hover:underline",children:e.name}):e.name})})]})},of=e=>{var t;let{stats:s}=e;return(0,le.jsxs)(Qn,{children:[(0,le.jsxs)(Xn,{children:[(0,le.jsx)(el,{children:"Unique Users Over Time"}),(0,le.jsx)(tl,{children:"Tracks the number of distinct users accessing your app each day"})]}),(0,le.jsx)(sl,{children:(null==s||null===(t=s.users_per_date)||void 0===t?void 0:t.length)<=1?(0,le.jsx)("div",{className:"h-[200px] flex items-center justify-center text-muted-foreground",children:"Not enough data to show trends"}):(0,le.jsx)("div",{className:"h-[300px]",children:(0,le.jsx)($u.u,{width:"100%",height:"100%",children:(0,le.jsxs)(ef.Q,{data:s.users_per_date,margin:{top:10,right:10,left:0,bottom:0},children:[(0,le.jsx)(Zu.d,{strokeDasharray:"3 3"}),(0,le.jsx)(Ku.W,{dataKey:"date"}),(0,le.jsx)(Qu.h,{}),(0,le.jsx)(Xu.m,{}),(0,le.jsx)(tf.G,{type:"monotone",dataKey:"unique_users",stroke:"#8884d8",fill:"#8884d8",name:"Unique Users"})]})})})})]})},cf=e=>{var t;let{stats:s}=e;return(0,le.jsxs)(Qn,{children:[(0,le.jsxs)(Xn,{children:[(0,le.jsx)(el,{children:"Total Usage Over Time"}),(0,le.jsx)(tl,{children:"Shows the total number of visits to your app, including repeat visits from the same users"})]}),(0,le.jsx)(sl,{children:(null==s||null===(t=s.users_per_date)||void 0===t?void 0:t.length)<=1?(0,le.jsx)("div",{className:"h-[200px] flex items-center justify-center text-muted-foreground",children:"Not enough data to show trends"}):(0,le.jsx)("div",{className:"h-[300px]",children:(0,le.jsx)($u.u,{width:"100%",height:"100%",children:(0,le.jsxs)(ef.Q,{data:s.users_per_date,margin:{top:10,right:10,left:0,bottom:0},children:[(0,le.jsx)(Zu.d,{strokeDasharray:"3 3"}),(0,le.jsx)(Ku.W,{dataKey:"date"}),(0,le.jsx)(Qu.h,{}),(0,le.jsx)(Xu.m,{}),(0,le.jsx)(tf.G,{type:"monotone",dataKey:"total_visits",stroke:"#82ca9d",fill:"#82ca9d",name:"Total Visits"})]})})})})]})};var df=s(71742);function mf(e){let{isSaving:t,hasEditorErrors:s,onDiscard:a,onSave:n,onSaveAndRedeploy:l,hasUnsavedChanges:r,isFunction:i,deploymentError:o,onClearError:c}=e;if(!r&&!o)return null;const d=(e=>{if(!e)return null;const t=e.match(/Deployment (.*?) failed with error (.*)/);return t?{deployment:"".concat(t[1]," failed"),error:t[2].replace(/\\n\\n+/g,": ").replace(/\\n+/g," ").trim()}:void 0})(o);return d?(0,le.jsx)("div",{className:"fixed bottom-2 right-6 w-full max-w-2xl z-[100]",children:(0,le.jsxs)("div",{className:"flex flex-col bg-white/95 backdrop-blur border border-red-200 text-red-700 rounded-lg shadow-lg overflow-hidden",children:[(0,le.jsxs)("div",{className:"flex items-start p-3 gap-3 bg-red-50/80",children:[(0,le.jsx)("div",{className:"flex-1 min-w-0",children:(0,le.jsx)("div",{className:"font-medium text-base text-red-800",children:d.deployment})}),(0,le.jsx)("button",{onClick:c,className:"text-red-600 hover:text-red-700 hover:bg-red-100 p-1.5 rounded-md transition-colors","aria-label":"Close",children:(0,le.jsx)(Bt.A,{className:"w-4 h-4"})})]}),d.error&&(0,le.jsx)("div",{className:"p-3 bg-white/50 border-t border-red-100",children:(0,le.jsx)("div",{className:"font-mono text-xs text-red-600 whitespace-pre-wrap break-words bg-red-50/50 rounded-md p-3",children:d.error})})]})}):(0,le.jsxs)("div",{className:"fixed bottom-6 right-6 flex flex-col gap-2 w-56 z-[200]",children:[s&&(0,le.jsxs)("div",{className:"flex items-center gap-2 mb-1 px-2 py-1 bg-red-50 border border-red-200 text-red-700 text-xs rounded shadow",children:[(0,le.jsx)(_e.A,{className:"w-4 h-4 text-red-500"}),(0,le.jsx)("span",{children:"Editor has errors"})]}),(0,le.jsxs)(Yt,{variant:"outline",size:"lg",className:"rounded-full shadow-lg w-full",onClick:a,disabled:t,children:[(0,le.jsx)(Ii.A,{className:"w-4 h-4 mr-2"}),"Discard"]}),i?(0,le.jsxs)(Yt,{size:"lg",className:"relative rounded-full shadow-lg bg-gray-900 text-white hover:bg-gray-800 w-full justify-center",onClick:l,disabled:t,children:[t?(0,le.jsx)(nx.A,{className:"w-4 h-4 mr-2 animate-spin"}):(0,le.jsx)(nx.A,{className:"w-4 h-4 mr-2"}),"Save & Redeploy"]}):(0,le.jsxs)(Yt,{size:"lg",className:"rounded-full shadow-lg bg-gray-900 text-white hover:bg-gray-800 w-full",onClick:n,disabled:t,children:[t?(0,le.jsx)(df.A,{className:"w-4 h-4 mr-2 animate-spin"}):(0,le.jsx)(df.A,{className:"w-4 h-4 mr-2"}),"Save"]})]})}function uf(e){let{filepath:t,selectedLine:s,onEdit:a,onSaveOrDiscard:n,isFunction:l,onRedeployFunction:r,functionHelperRef:i,cachedAppFiles:o,isLoadingAppFiles:c,shouldFetchFilesFromSandbox:d,onUpdateCachedFile:m}=e;const{user:u}=oe(),{app:x,writeCodeToFile:h,refreshApp:p}=Nt(),[g,f]=(0,Y.useState)(!1),[v,b]=(0,Y.useState)(""),[j,y]=(0,Y.useState)(!1),[N,w]=(0,Y.useState)(!1),[_,k]=(0,Y.useState)(null),C=(0,Y.useRef)(null),A=(0,Y.useRef)(null),S="free"===(null==u?void 0:u.subscription_tier),E=(0,Y.useRef)(null),I=(0,Y.useRef)(""),T=(0,Y.useRef)(t),[P,L]=(0,Y.useState)(!0),O=()=>{if(C.current&&A.current){const e=C.current.getModel(),t=A.current;if(e&&t){const s=t.editor.getModelMarkers({resource:e.uri}).some(e=>e.severity===t.MarkerSeverity.Error);L(s)}}};(0,Y.useEffect)(()=>{if(t&&x){if(w(!1),C.current&&(E.current=C.current.saveViewState()),d&&o){const e=(e=>o&&o[e]||"")(t);b(e),I.current=e,w(!0)}else d&&c?(b(""),I.current="",w(!1)):(e=>{let t="";if("layout"===e)t=x.layout;else if(e.startsWith("pages/")){const s=e.split("pages/")[1];t=x.pages[s]}else if(e.startsWith("components/")){const s=e.split("components/")[1];t=x.components[s]}else if(e.startsWith("functions/")){const s=e.split("functions/")[1];t=x.functions[s]}else if(e.startsWith("entities/")){const s=e.split("entities/")[1];t=JSON.stringify(x.entities[s],null,2)}b(t),I.current=t,w(!0)})(t);if(T.current=t,C.current){const e=C.current.getModel();if(e){const t=e.onDidChangeDecorations(()=>{O(),t&&t.dispose&&t.dispose()})}}}},[t,x,d,o,c]),(0,Y.useEffect)(()=>{C.current&&E.current&&(C.current.restoreViewState(E.current),C.current.focus(),E.current=null)},[v,j]),(0,Y.useEffect)(()=>{s&&j&&N&&v&&(()=>{if(!(C.current&&s&&j&&N))return;const e=C.current,t=e.getModel();if(!t)return;const a=parseInt(s,10);if(isNaN(a)||a<=0)return;const n=t.getLineCount(),l=Math.min(a,n);requestAnimationFrame(()=>{requestAnimationFrame(()=>{try{e.revealLineInCenter(l,0),setTimeout(()=>{e.setPosition({lineNumber:l,column:1}),e.setSelection({startLineNumber:l,startColumn:1,endLineNumber:l,endColumn:t.getLineMaxColumn(l)}),e.focus()},50)}catch(s){}})})})()},[s,j,N,v]),(0,Y.useEffect)(()=>{if(!C.current||!A.current)return;const e=C.current.getModel(),t=A.current;if(!e||!t)return;const s=t.editor.onDidChangeMarkers(t=>{t.some(t=>t.toString()===e.uri.toString())&&O()});return O(),()=>{s&&s.dispose&&s.dispose()}},[j,v]),(0,Y.useEffect)(()=>{k(null)},[t]);const R=v!==I.current;return(0,le.jsxs)("div",{className:"h-full relative",children:[(0,le.jsx)(mf,{isSaving:g,hasEditorErrors:P,onDiscard:()=>{var e;b(I.current),k(null),null!=i&&null!==(e=i.current)&&void 0!==e&&e.clearDeploymentError&&i.current.clearDeploymentError(),C.current&&E.current&&(C.current.restoreViewState(E.current),C.current.focus()),n&&n()},onSave:async()=>{f(!0);try{await(async e=>{S||(f(!0),await h(t,e),f(!1))})(v),I.current=v,m&&m(t,v),await p(),n&&n()}catch(e){}finally{f(!1)}},onSaveAndRedeploy:async()=>{var e;if(k(null),null!=i&&null!==(e=i.current)&&void 0!==e&&e.clearDeploymentError&&i.current.clearDeploymentError(),r){f(!0);try{await r(v),I.current=v,n&&n()}catch(t){k(t.message||"Failed to redeploy function")}finally{f(!1)}}},hasUnsavedChanges:R,isFunction:l,deploymentError:_,onClearError:()=>{k(null)}}),(0,le.jsx)(jr.KE,{defaultLanguage:"javascript",value:v,onChange:e=>{S||(b(e),C.current&&(E.current=C.current.saveViewState()),a&&a())},onMount:(e,t)=>{C.current=e,A.current=t,y(!0);const s=e.getModel();s&&s.onDidChangeContent(()=>{w(!0)})},options:{minimap:{enabled:!1},scrollBeyondLastLine:!1,fontSize:14,readOnly:S||g||c,padding:{top:S?40:0}},height:"100%"}),S&&(0,le.jsxs)("div",{className:"absolute top-0 left-0 right-0 bg-amber-50 border-b border-amber-200 p-3 z-10 text-sm text-amber-800",children:["Code editing is only available on paid plans.",(0,le.jsx)(J.Link,{to:"/billing",className:"ml-2 text-blue-600 hover:underline",children:"Upgrade your plan"})]}),g&&(0,le.jsx)("div",{className:"absolute top-10 right-2 bg-gray-700 text-white text-xs px-2 py-1 rounded opacity-70"}),c&&(0,le.jsx)("div",{className:"absolute top-10 right-16 bg-blue-600 text-white text-xs px-2 py-1 rounded opacity-70"})]})}function xf(e,t){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};const a=ft(),n=(0,K.A)({"Base44-Functions-Version":a},s),l=(0,ae.Ay)("https://base44.app/api"+"/apps/".concat(e.id,"/functions"),n,!0,!1,!1);t=t||(e=>{}),l.interceptors.response.use(e=>e,e=>{const s="error trying to call function: ".concat(e.config.url);let a=e.config.data;try{"string"!=typeof a&&(a=JSON.stringify(a)),a&&a.length>1e3&&(a=a.substring(0,997)+"...")}catch(i){a=String(a)}let n="";try{var l;null!==(l=e.response)&&void 0!==l&&l.data?(n="object"==typeof e.response.data?JSON.stringify(e.response.data):String(e.response.data),n.length>1e3&&(n=n.substring(0,997)+"...")):n=e.message||"Unknown error"}catch(i){n=String(e)||"Unknown error"}const r="When using the app, on url ".concat(window.location.href," the following function call failed: \nurl: ").concat(e.config.baseURL).concat(e.config.url,"\nmethod: ").concat(e.config.method,"\ndata: ").concat(a,"\nerror: ").concat(n);return t(s,r),Promise.reject(e)});let r={};return(e.function_names||Object.keys(e.functions||{})).forEach(e=>{r[e]=async t=>await l.post("/".concat(e),t||{})}),r}var hf=s(7838),pf=s(30621),gf=s(5487);const ff=(0,Y.forwardRef)((e,t)=>{let{functionName:s,hasUnsavedChanges:a}=e;const{user:n}=oe(),{app:l,runtimeAuthToken:r,refreshApp:i}=Nt(),[o,c]=(0,Y.useState)(null),[d,m]=(0,Y.useState)(!1),[u,x]=(0,Y.useState)(!1),[h,p]=(0,Y.useState)(!1),[g,f]=(0,Y.useState)("{\n \n}"),[v,b]=(0,Y.useState)(null),[j,y]=(0,Y.useState)(!1),[N,w]=(0,Y.useState)(null),[_,k]=(0,Y.useState)(null),[C,A]=(0,Y.useState)(!1),[S,E]=(0,Y.useState)(!1),[I,T]=(0,Y.useState)(!1),[P,L]=(0,Y.useState)([]),[O,R]=(0,Y.useState)(!1),[M,D]=(0,Y.useState)(null),[F,B]=(0,Y.useState)(0),[z]=(0,Y.useState)(50),[U,W]=(0,Y.useState)(!0);(0,Y.useEffect)(()=>{c(xf(l,()=>{},{Authorization:"Bearer ".concat(r),"Base44-Functions-Version":"preview"}))},[null==l?void 0:l.id,null==l?void 0:l.functions]),(0,Y.useEffect)(()=>{w(null)},[s]);const q=async e=>{if(null!=l&&l.id&&s){w(null);try{await ve.redeployFunction(l.id,s,e),await i()}catch(n){var t,a;const e=(null===(t=n.response)||void 0===t||null===(a=t.data)||void 0===a?void 0:a.message)||n.message||"An error occurred while redeploying the function";throw w(e),new Error(e)}}};(0,Y.useImperativeHandle)(t,()=>({handleRedeployFunction:q,clearDeploymentError:()=>w(null)}));const V=async(e,t)=>{try{await navigator.clipboard.writeText(e),"url"===t?(A(!0),setTimeout(()=>A(!1),2e3)):"headers"===t?(E(!0),setTimeout(()=>E(!1),2e3)):"curl"===t&&(T(!0),setTimeout(()=>T(!1),2e3))}catch(s){}},H=()=>null!=l&&l.slug&&null!=l&&l.id&&s?"".concat(fa(l),"/api/apps/").concat(l.id,"/functions/").concat(s):"",G=()=>{const e={"Content-Type":"application/json"};return null!=n&&n.api_key&&(e.api_key=n.api_key),e},$=async function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(null!=l&&l.id&&s){R(!0),D(null);try{const a=await ug.getBackendFunctionsLogs(l.id,s,{limit:z,offset:e});L(t||0===e?a:e=>[...e,...a]),W(a.length===z),B(e)}catch(r){var a,n;D((null===(a=r.response)||void 0===a||null===(n=a.data)||void 0===n?void 0:n.message)||r.message||"Failed to fetch logs")}finally{R(!1)}}},J=e=>{try{return new Date(e).toLocaleString()}catch(t){return e}},Z=e=>{switch(null==e?void 0:e.toLowerCase()){case"error":return"text-red-600 bg-red-50 border-red-200";case"warn":case"warning":return"text-amber-600 bg-amber-50 border-amber-200";case"info":return"text-blue-600 bg-blue-50 border-blue-200";case"debug":return"text-purple-600 bg-purple-50 border-purple-200";default:return"text-slate-600 bg-slate-50 border-slate-200"}};return(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)("div",{className:"fixed bottom-6 right-6",children:!a&&(0,le.jsxs)("div",{className:"bg-white/95 backdrop-blur-sm border border-slate-200 rounded-2xl shadow-2xl p-2 flex items-center gap-1",children:[(0,le.jsxs)(Yt,{variant:"ghost",size:"sm",className:"rounded-xl text-slate-600 hover:text-slate-800 hover:bg-slate-100 transition-all duration-200",onClick:()=>m(!0),children:[(0,le.jsx)(Oi.A,{className:"h-4 w-4 mr-2"}),"Test Function"]}),(0,le.jsx)("div",{className:"w-px h-6 bg-slate-300 mx-1"}),(0,le.jsxs)(Yt,{variant:"ghost",size:"sm",className:"rounded-xl text-slate-600 hover:text-slate-800 hover:bg-slate-100 transition-all duration-200",onClick:()=>{p(!0),0===P.length&&$(0,!0)},children:[(0,le.jsx)(hf.A,{className:"h-4 w-4 mr-2"}),"Logs"]}),(0,le.jsx)("div",{className:"w-px h-6 bg-slate-300 mx-1"}),(0,le.jsxs)(Yt,{variant:"ghost",size:"sm",className:"rounded-xl text-slate-600 hover:text-slate-800 hover:bg-slate-100 transition-all duration-200",onClick:()=>x(!0),children:[(0,le.jsx)(Kl.A,{className:"h-4 w-4 mr-2"}),"API"]})]})}),N&&(0,le.jsx)("div",{className:"fixed bottom-24 right-6 max-w-md z-50",children:(0,le.jsxs)(De,{variant:"destructive",className:"bg-white/95 backdrop-blur-sm border-red-200 shadow-xl",children:[(0,le.jsx)(gf.A,{className:"h-4 w-4"}),(0,le.jsx)(Fe,{children:"Deployment Error"}),(0,le.jsx)(Be,{className:"font-mono text-sm whitespace-pre-wrap break-all",children:N})]})}),(0,le.jsx)(tp,{open:h&&!a,onOpenChange:p,children:(0,le.jsxs)(ip,{className:"sm:max-w-3xl md:max-w-5xl w-[96vw]",children:[(0,le.jsx)(op,{className:"pb-3",children:(0,le.jsxs)("div",{className:"flex items-center justify-between",children:[(0,le.jsxs)("div",{className:"flex items-center gap-3",children:[(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[(0,le.jsx)(hf.A,{className:"h-5 w-5 text-teal-600"}),(0,le.jsx)(dp,{className:"text-slate-800 text-lg",children:"Logs"})]}),(0,le.jsx)("div",{className:"text-sm text-slate-500 font-mono bg-slate-100 px-2 py-1 rounded",children:s})]}),(0,le.jsxs)(Yt,{variant:"outline",size:"sm",onClick:()=>{$(0,!0)},disabled:O,className:"text-teal-600 hover:text-teal-700 hover:bg-teal-50 border-teal-200",children:[(0,le.jsx)(nx.A,{className:"h-4 w-4 mr-1 ".concat(O?"animate-spin":"")}),"Refresh"]})]})}),(0,le.jsxs)("div",{className:"space-y-3",children:[M&&(0,le.jsxs)(De,{variant:"destructive",className:"mb-4",children:[(0,le.jsx)(gf.A,{className:"h-4 w-4"}),(0,le.jsx)(Fe,{children:"Error"}),(0,le.jsx)(Be,{children:M})]}),0===P.length&&!O&&!M&&(0,le.jsxs)("div",{className:"text-center py-8 text-slate-500",children:[(0,le.jsx)(hr.A,{className:"h-8 w-8 mx-auto mb-3 text-slate-400"}),(0,le.jsx)("p",{className:"font-medium mb-1",children:"No logs found"}),(0,le.jsx)("p",{className:"text-xs text-slate-400",children:"This function hasn't generated any logs yet."})]}),P.length>0&&(0,le.jsx)("div",{className:"max-h-[70vh] overflow-y-auto border border-slate-200 rounded-lg",children:(0,le.jsx)("div",{className:"divide-y divide-slate-100",children:P.map((e,t)=>{return(0,le.jsxs)("div",{className:"px-3 py-2 hover:bg-slate-50/50 transition-colors ".concat(Z(e.level).includes("red")?"bg-red-50/30":Z(e.level).includes("amber")?"bg-amber-50/30":Z(e.level).includes("blue")?"bg-blue-50/30":Z(e.level).includes("purple")?"bg-purple-50/30":""),children:[(0,le.jsx)("div",{className:"flex items-start gap-3 mb-1",children:(0,le.jsxs)("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.level&&(0,le.jsx)("span",{className:"text-xs font-medium uppercase px-1.5 py-0.5 rounded-sm ".concat("error"===e.level.toLowerCase()?"bg-red-100 text-red-700 border border-red-200":"warn"===e.level.toLowerCase()||"warning"===e.level.toLowerCase()?"bg-amber-100 text-amber-700 border border-amber-200":"info"===e.level.toLowerCase()?"bg-blue-100 text-blue-700 border border-blue-200":"debug"===e.level.toLowerCase()?"bg-purple-100 text-purple-700 border border-purple-200":"bg-slate-100 text-slate-700 border border-slate-200"),children:e.level}),(0,le.jsx)("span",{className:"text-xs text-slate-400 font-mono min-w-0",children:J(e.time).split(", ")[1]}),e.region&&(0,le.jsx)("span",{className:"text-xs text-slate-400 bg-slate-100 px-1.5 py-0.5 rounded-sm font-mono",children:e.region.replace("gcp-","")})]})}),(0,le.jsx)("div",{className:"font-mono text-xs leading-relaxed text-slate-700 whitespace-pre-wrap break-words pl-1",children:"string"==typeof e.message?(s=e.message.trim(),"string"!=typeof s?s:s.replace(/\u001b\[[0-9;]*m/g,"")):JSON.stringify(e.message,null,2)})]},"".concat(e.time,"-").concat(t));var s})})}),U&&P.length>0&&(0,le.jsx)("div",{className:"flex justify-center pt-2",children:(0,le.jsx)(Yt,{variant:"outline",size:"sm",onClick:()=>{!O&&U&&$(F+z)},disabled:O,className:"text-slate-600 hover:text-slate-800 text-xs",children:O?(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(Ne.A,{className:"mr-1 h-3 w-3 animate-spin"}),"Loading..."]}):(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(rn.A,{className:"mr-1 h-3 w-3"}),"Load More"]})})}),O&&0===P.length&&(0,le.jsx)("div",{className:"flex justify-center py-8",children:(0,le.jsxs)("div",{className:"flex items-center text-slate-500 text-sm",children:[(0,le.jsx)(Ne.A,{className:"mr-2 h-4 w-4 animate-spin"}),"Loading logs..."]})})]})]})}),(0,le.jsx)(tp,{open:u&&!a,onOpenChange:x,children:(0,le.jsxs)(ip,{className:"sm:max-w-md md:max-w-lg w-[90vw] flex flex-col",children:[(0,le.jsxs)(op,{className:"pb-4 flex-shrink-0",children:[(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[(0,le.jsx)(Kl.A,{className:"h-5 w-5 text-teal-600"}),(0,le.jsx)(dp,{className:"text-slate-800 text-lg",children:"API Information"})]}),(0,le.jsx)("div",{className:"text-sm text-slate-500 font-mono bg-slate-100 px-2 py-1 rounded w-fit",children:s})]}),(0,le.jsxs)("div",{className:"flex-1 overflow-y-auto mt-6 space-y-6 pr-2",children:[(0,le.jsxs)("div",{className:"space-y-3",children:[(0,le.jsxs)("div",{className:"flex items-center justify-between",children:[(0,le.jsx)("h3",{className:"text-sm font-semibold text-slate-700 uppercase tracking-wider",children:"Function URL"}),(0,le.jsx)(Yt,{variant:"ghost",size:"sm",onClick:()=>V(H(),"url"),className:"text-teal-600 hover:text-teal-700 hover:bg-teal-50",children:C?(0,le.jsx)(Ps.A,{className:"h-4 w-4"}):(0,le.jsx)(or.A,{className:"h-4 w-4"})})]}),(0,le.jsx)("div",{className:"bg-slate-50 border border-slate-200 rounded-lg p-4",children:(0,le.jsx)("code",{className:"text-sm font-mono text-slate-800 break-all",children:H()})}),(0,le.jsx)("p",{className:"text-xs text-slate-500",children:"Make POST requests to this endpoint with your function payload."})]}),(0,le.jsxs)("div",{className:"space-y-3",children:[(0,le.jsxs)("div",{className:"flex items-center justify-between",children:[(0,le.jsx)("h3",{className:"text-sm font-semibold text-slate-700 uppercase tracking-wider",children:"Headers"}),(0,le.jsx)(Yt,{variant:"ghost",size:"sm",onClick:()=>V(JSON.stringify(G(),null,2),"headers"),className:"text-teal-600 hover:text-teal-700 hover:bg-teal-50",children:S?(0,le.jsx)(Ps.A,{className:"h-4 w-4"}):(0,le.jsx)(or.A,{className:"h-4 w-4"})})]}),(0,le.jsx)("div",{className:"bg-slate-50 border border-slate-200 rounded-lg p-4",children:(0,le.jsx)("pre",{className:"text-sm font-mono text-slate-800 whitespace-pre-wrap",children:JSON.stringify(G(),null,2)})}),(0,le.jsxs)("div",{className:"text-xs text-slate-500 space-y-1",children:[(0,le.jsxs)("p",{children:[(0,le.jsx)("strong",{children:"Content-Type:"})," Always required for JSON payloads."]}),null!=n&&n.api_key?(0,le.jsxs)("p",{children:[(0,le.jsx)("strong",{children:"api_key:"})," Your personal API key - only include this if your function requires authentication. Keep it secure and don't expose it publicly."]}):(0,le.jsxs)("p",{className:"text-amber-600",children:[(0,le.jsx)("strong",{children:"api_key:"})," Not found. Include your personal API key here only if your function requires authentication."]})]})]}),(0,le.jsxs)("div",{className:"space-y-3",children:[(0,le.jsx)("h3",{className:"text-sm font-semibold text-slate-700 uppercase tracking-wider",children:"Request Body"}),(0,le.jsx)("div",{className:"bg-slate-50 border border-slate-200 rounded-lg p-4",children:(0,le.jsx)("pre",{className:"text-sm font-mono text-slate-800 whitespace-pre-wrap",children:'{\n "param1": "value1",\n "param2": "value2"\n}'})}),(0,le.jsx)("p",{className:"text-xs text-slate-500",children:"Send a JSON object in the request body with any parameters your function requires. The structure depends on what your function expects to receive."})]}),(0,le.jsxs)("div",{className:"space-y-3",children:[(0,le.jsxs)("div",{className:"flex items-center justify-between",children:[(0,le.jsx)("h3",{className:"text-sm font-semibold text-slate-700 uppercase tracking-wider",children:"Usage Example (cURL)"}),(0,le.jsx)(Yt,{variant:"ghost",size:"sm",onClick:()=>V('curl -X POST "'.concat(H(),'" \\\n -H "Content-Type: application/json" ').concat(null!=n&&n.api_key?'\\\n -H "api_key: '.concat(n.api_key,'" '):"",'\\\n -d \'{"param1": "value1", "param2": "value2"}\''),"curl"),className:"text-teal-600 hover:text-teal-700 hover:bg-teal-50",children:I?(0,le.jsx)(Ps.A,{className:"h-4 w-4"}):(0,le.jsx)(or.A,{className:"h-4 w-4"})})]}),(0,le.jsx)("div",{className:"bg-slate-900 rounded-lg p-4",children:(0,le.jsx)("pre",{className:"text-sm font-mono text-green-400 whitespace-pre-wrap break-all",children:'curl -X POST "'.concat(H(),'" \\\n -H "Content-Type: application/json" ').concat(null!=n&&n.api_key?'\\\n -H "api_key: '.concat(n.api_key,'" '):"",'\\\n -d \'{"param1": "value1", "param2": "value2"}\'')})})]})]})]})}),(0,le.jsx)(tp,{open:d&&!a,onOpenChange:m,children:(0,le.jsxs)(ip,{className:"sm:max-w-md md:max-w-lg w-[90vw]",children:[(0,le.jsxs)(op,{className:"pb-4",children:[(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[(0,le.jsx)(Oi.A,{className:"h-5 w-5 text-orange-600"}),(0,le.jsx)(dp,{className:"text-slate-800 text-lg",children:"Test Function"})]}),(0,le.jsx)("div",{className:"text-sm text-slate-500 font-mono bg-slate-100 px-2 py-1 rounded w-fit",children:s})]}),(0,le.jsxs)("div",{className:"mt-6 space-y-4",children:[(0,le.jsxs)("div",{children:[(0,le.jsx)("h3",{className:"text-sm font-medium mb-2",children:"Payload"}),(0,le.jsx)(um,{value:g,onChange:e=>f(e.target.value),className:"font-mono h-40",placeholder:"Enter JSON payload"})]}),(0,le.jsx)(Yt,{onClick:async()=>{if(o&&s){y(!0),k(null),b(null);try{const e=JSON.parse(g),t=await o[s](e);b(t)}catch(r){var e,t,a,n,l;k({message:(null===(e=r.response)||void 0===e||null===(t=e.data)||void 0===t?void 0:t.error)||(null===(a=r.response)||void 0===a||null===(n=a.data)||void 0===n?void 0:n.message)||r.message||"An error occurred while executing the function",details:(null===(l=r.response)||void 0===l?void 0:l.data)||null})}finally{y(!1)}}},disabled:j,className:"w-full",children:j?(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(Ne.A,{className:"mr-2 h-4 w-4 animate-spin"}),"Running..."]}):(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(pf.A,{className:"mr-2 h-4 w-4"}),"Run Function"]})}),_&&(0,le.jsxs)(De,{variant:"destructive",children:[(0,le.jsx)(gf.A,{className:"h-4 w-4"}),(0,le.jsx)(Fe,{children:"Function Execution Error"}),(0,le.jsxs)(Be,{className:"font-mono text-sm whitespace-pre-wrap break-all",children:[null==_?void 0:_.message,(null==_?void 0:_.details)&&(0,le.jsxs)("div",{className:"mt-2 pt-2 border-t border-red-300 dark:border-red-700",children:[(0,le.jsx)("h4",{className:"text-xs font-semibold mb-1 uppercase tracking-wider text-red-700 dark:text-red-300",children:"Technical Details (JSON RESPONSE):"}),(0,le.jsx)("div",{className:"bg-red-50 dark:bg-red-900/30 p-2 rounded-md overflow-auto max-h-40",children:(0,le.jsx)("pre",{className:"text-xs font-mono whitespace-pre-wrap break-all",children:"string"==typeof _.details?_.details:JSON.stringify(_.details,null,2)})})]})]})]}),v&&(0,le.jsxs)("div",{className:"mt-4",children:[(0,le.jsx)("h3",{className:"text-sm font-medium mb-2",children:"Result"}),(0,le.jsxs)(kr,{defaultValue:"formatted",children:[(0,le.jsxs)(Cr,{className:"mb-2",children:[(0,le.jsx)(Ar,{value:"formatted",children:"Formatted"}),(0,le.jsx)(Ar,{value:"raw",children:"Raw"})]}),(0,le.jsx)(Sr,{value:"formatted",children:(0,le.jsx)("div",{className:"bg-gray-50 p-4 rounded-md overflow-auto max-h-60",children:(0,le.jsx)("pre",{className:"text-sm font-mono whitespace-pre-wrap",children:(e=>{try{return JSON.stringify(e,null,2)}catch(t){return String(e)}})(v)})})}),(0,le.jsx)(Sr,{value:"raw",children:(0,le.jsx)("div",{className:"bg-gray-50 p-4 rounded-md overflow-auto max-h-60",children:(0,le.jsx)("pre",{className:"text-sm font-mono whitespace-pre-wrap",children:JSON.stringify(v)})})})]})]})]})]})})]})});var vf=s(57543),bf=s(15939);const jf=e=>{let{selectedFile:t,onFileSelect:s,onBack:a,app:n,width:l="100%",hasUnsavedChanges:r=!1,readOnly:i=!1,backButtonText:o="Back to Dashboard",title:c="Files",showEmptyMessage:d=!1,emptyMessage:m=null}=e;const[u,x]=(0,Y.useState)(""),[h,p]=(0,Y.useState)([]),[g,f]=(0,Y.useState)(!1),[v,b]=(0,Y.useState)({}),j=e=>{const t={};return Object.keys(e||{}).forEach(e=>{const s=e.split("/");let a=t;for(let t=0;tObject.entries(e).map(e=>{let[a,n]=e;const l=t?"".concat(t,"/").concat(a):"".concat(s,":").concat(a);if(n.isFile){return{id:l,label:a,icon:"entities"===s?(0,le.jsx)(Gc.A,{className:"w-4 h-4"}):(0,le.jsx)(vf.A,{className:"w-4 h-4"})}}{const e=y(n.children,l,s);return{id:l,label:a,icon:(0,le.jsx)(bf.A,{className:"w-4 h-4"}),subitems:e}}}),N=e=>{if(e.includes("/")){const[t,a]=(e=>{if(-1!==e.indexOf(":"))return e.split(":");const t=e.split("/"),s=t[0];return 1===t.length?[s,""]:[s,t.slice(1).join("/")]})(e);let l=!1;("pages"===t&&n.pages&&n.pages[a]||"components"===t&&n.components&&n.components[a]||"functions"===t&&n.functions&&n.functions[a]||"entities"===t&&n.entities&&n.entities[a])&&(l=!0),l&&s("".concat(t,":").concat(a))}else s(e)};(0,Y.useEffect)(()=>{if(u.length<2||!g)return void p([]);const e=[],t=(t,s)=>{s&&Object.entries(s).forEach(s=>{let[a,n]=s;const l=n.toString().split("\n").map((e,t)=>({line:e,idx:t+1})).filter(e=>{let{line:t}=e;return t.toLowerCase().includes(u.toLowerCase())});l.length>0&&e.push({type:t,key:a,matches:l.map(e=>{let{line:t,idx:s}=e;return{lineNumber:s,content:t,preview:t.trim()}})})})};if(t("pages",n.pages),t("components",n.components),t("entities",n.entities),t("functions",n.functions),n.layout){const t=n.layout.toString().split("\n").map((e,t)=>({line:e,idx:t+1})).filter(e=>{let{line:t}=e;return t.toLowerCase().includes(u.toLowerCase())});t.length>0&&e.push({type:"layout",key:"main",matches:t.map(e=>{let{line:t,idx:s}=e;return{lineNumber:s,content:t,preview:t.trim()}})})}p(e)},[u,n,g]);const w=e=>{let{item:t,selected:s,onSelect:a}=e;const n=v[t.id]||!1,l=n?t.matches:t.matches.slice(0,3),i=t.matches.length>3;return(0,le.jsxs)("div",{className:"pl-2 mb-2",children:[(0,le.jsxs)(Yt,{variant:s===t.id?"secondary":"ghost",className:"w-full justify-start text-left ".concat(s===t.id?"bg-primary/10 text-primary hover:bg-primary/20":"hover:bg-gray-100"," ").concat(r?"pointer-events-none opacity-60 cursor-not-allowed":""),onClick:()=>{r||a(t.id)},title:r?"You have unsaved changes. Save or discard to jump to a line.":"",children:[t.icon,(0,le.jsx)("span",{className:"ml-2 truncate max-w-[250px] inline-block",children:t.label})]}),(0,le.jsxs)("div",{className:"pl-4 mt-1 text-xs",children:[l.map((e,s)=>(0,le.jsxs)("div",{className:"text-gray-600 bg-gray-100 rounded p-1 mb-1 overflow-hidden cursor-pointer hover:bg-gray-200 ".concat(r?"pointer-events-none opacity-60 cursor-not-allowed":""),onClick:()=>{return s=e.lineNumber,void(r||a(t.id,s));var s},title:r?"You have unsaved changes. Save or discard to jump to a line.":"",children:[(0,le.jsxs)("span",{className:"text-gray-500",children:[e.lineNumber,": "]}),(0,le.jsx)("span",{className:"whitespace-nowrap overflow-hidden text-ellipsis inline-block max-w-[180px]",children:e.preview})]},s)),i&&(0,le.jsxs)("div",{className:"text-gray-500 italic pl-1 flex items-center cursor-pointer hover:text-gray-700",onClick:e=>{e.stopPropagation(),b(e=>(0,K.A)((0,K.A)({},e),{},{[t.id]:!n}))},children:[(0,le.jsx)("span",{className:"mr-1 inline-block w-4 h-4 text-center leading-4 bg-gray-200 rounded-full",children:n?"\u2212":"+"}),n?"Collapse matches":"".concat(t.matches.length-3," more matches")]})]})]})};return(0,le.jsxs)("div",{className:"flex flex-col h-full bg-gray-100 border-r",style:{width:"100%"},children:[(0,le.jsx)("div",{className:"border-b p-2 bg-gray-50",children:(0,le.jsxs)(Yt,{variant:"ghost",className:"w-full justify-start text-sm",onClick:a,children:[(0,le.jsx)(Xs.A,{className:"h-4 w-4 mr-2"}),o]})}),(0,le.jsx)("div",{className:"p-3 border-b",children:(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[(0,le.jsx)(fs,{type:"text",placeholder:"Search in files...",value:u,onChange:e=>{x(e.target.value),f(e.target.value.length>=2)},className:"text-sm w-full"}),u&&(0,le.jsx)(Yt,{variant:"ghost",size:"icon",onClick:()=>{x(""),f(!1)},children:(0,le.jsx)(Jc.MKb,{className:"h-4 w-4"})})]})}),g&&h.length>0?(0,le.jsxs)("div",{className:"flex-1 overflow-y-auto",children:[(0,le.jsxs)("div",{className:"p-2 text-xs text-gray-500",children:[h.length," result",1!==h.length?"s":""," in ",h.length," file",1!==h.length?"s":""]}),(0,le.jsx)("div",{className:"space-y-1",children:h.map(e=>({id:"".concat(e.type,":").concat(e.key),label:e.key,icon:"entities"===e.type?(0,le.jsx)(Gc.A,{className:"w-4 h-4"}):"layout"===e.type?(0,le.jsx)(ki.A,{className:"w-4 h-4"}):(0,le.jsx)(vf.A,{className:"w-4 h-4"}),matches:e.matches})).map((e,a)=>(0,le.jsx)(w,{item:e,selected:t?"".concat(t.type,":").concat(t.key):null,onSelect:s},a))})]}):(0,le.jsx)("div",{className:"flex-1 overflow-y-auto",children:(()=>{const e=(()=>{const e=[];if(n.pages&&Object.keys(n.pages).length>0){const t=j(n.pages);e.push({id:"pages",label:"Pages",icon:(0,le.jsx)(bf.A,{className:"w-4 h-4"}),subitems:y(t,null,"pages")})}if(n.components&&Object.keys(n.components).length>0){const t=j(n.components);e.push({id:"components",label:"Components",icon:(0,le.jsx)(bf.A,{className:"w-4 h-4"}),subitems:y(t,null,"components")})}if(n.entities&&Object.keys(n.entities).length>0){const t=j(n.entities);e.push({id:"entities",label:"Entities",icon:(0,le.jsx)(bf.A,{className:"w-4 h-4"}),subitems:y(t,null,"entities")})}if(n.layout&&e.push({id:"layout:main",label:"Layout.js",icon:(0,le.jsx)(ki.A,{className:"w-4 h-4"})}),n.has_backend_functions_enabled&&n.functions){const t=j(n.functions);e.push({id:"functions",label:"Functions",icon:(0,le.jsx)(bf.A,{className:"w-4 h-4"}),subitems:y(t,null,"functions")})}return e})();return d&&0===e.length?(0,le.jsx)("div",{className:"p-4 text-sm text-gray-500",children:m||(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)("div",{className:"mb-2",children:"No files available"}),(0,le.jsx)("div",{className:"text-xs",children:"This view appears to be empty."})]})}):(0,le.jsx)(Hx,{items:e,selected:t?"".concat(t.type,":").concat(t.key):null,onSelect:N,title:c,showBackButton:!1,onBack:a,showSearch:!1,style:{width:"100%"}})})()})]})},yf=()=>{var e;const{app:t,refreshApp:s}=Nt(),{user:a}=oe(),[n,l]=(0,Y.useState)(null),[r,i]=(0,Y.useState)(null),[o,c]=(0,Y.useState)(!1),d=(0,Y.useRef)(null),m=(0,Z.Zp)(),u=(0,Z.zy)(),[x,h]=(0,Y.useState)(!1),[p,g]=(0,Y.useState)(null),[f,v]=(0,Y.useState)(!1),b=(null==t?void 0:t.using_sandbox)&&(null==a||null===(e=a.feature_flags)||void 0===e?void 0:e.includes("use-sandbox-from-ui"));(0,Y.useEffect)(()=>{(async()=>{if(t){if(v(!0),!b)return await s(),void v(!1);try{const e=await gu.getAppFiles(t.id);g(e)}catch(e){g(null)}finally{v(!1)}}})()},[b]),(0,Y.useEffect)(()=>{const e=new URLSearchParams(u.search),s=e.get("filePath"),a=e.get("line");if(i(a?parseInt(a,10):null),s&&t){const e=s.replace(/\.\w+$/,"").split("/");if(e.length>=2){const s=e[0],a=e.slice(1).join("/");let n=!1;("pages"===s&&t.pages&&t.pages[a]||"components"===s&&t.components&&t.components[a]||"functions"===s&&t.functions&&t.functions[a]||"entities"===s&&t.entities&&t.entities[a]||"layout"===s&&t.layout)&&(n=!0),n&&l({type:s,key:a})}}},[t,u.search]);const j=(()=>{if(!n)return null;switch(n.type){case"pages":return"pages/".concat(n.key);case"components":return"components/".concat(n.key);case"functions":return"functions/".concat(n.key);case"entities":return"entities/".concat(n.key);case"layout":return"layout";default:return null}})(),y="functions"===(null==n?void 0:n.type);return(0,le.jsx)("div",{className:"h-full w-full border rounded-lg overflow-hidden bg-white shadow-sm",children:(0,le.jsxs)(Mm,{direction:"horizontal",children:[(0,le.jsx)(Dm,{defaultSize:33,minSize:20,maxSize:40,className:"h-full overflow-hidden",children:(0,le.jsx)(jf,{selectedFile:n,onFileSelect:function(e){let s,a,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;if(e.includes(":"))[s,a]=e.split(":");else{if(!e.includes("/"))return s=e,void(a="");{const n=e.split("/");s=n[0],a=n.slice(1).join("/");let l=!1;if(("pages"===s&&t.pages&&t.pages[a]||"components"===s&&t.components&&t.components[a]||"functions"===s&&t.functions&&t.functions[a]||"entities"===s&&t.entities&&t.entities[a])&&(l=!0),!l)return}}l({type:s,key:a}),i(n);const r="layout"===s?"layout/main":"".concat(s,"/").concat(a),o=new URLSearchParams;o.set("filePath",r),n&&o.set("line",n),m("?".concat(o.toString()),{replace:!0})},onBack:()=>{m("/apps/".concat(t.id,"/editor/workspace/overview"))},app:t})}),(0,le.jsx)(Fm,{withHandle:!0,className:"group transition-opacity opacity-0 hover:opacity-100 focus:opacity-100"}),(0,le.jsx)(Dm,{defaultSize:75,className:"flex-1 overflow-x-auto",children:j?(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(uf,{filepath:j,selectedLine:r,onEdit:()=>{if(c(!0),null!==r){i(null);const e=new URLSearchParams(u.search);e.delete("line"),m("?".concat(e.toString()),{replace:!0})}},onSaveOrDiscard:()=>{c(!1)},isFunction:y,onRedeployFunction:async e=>{if(d.current)try{await d.current.handleRedeployFunction(e),h(!1)}catch(t){throw t}},functionHelperRef:d,isSaving:x,cachedAppFiles:p,isLoadingAppFiles:f,shouldFetchFilesFromSandbox:b,onUpdateCachedFile:(e,t)=>{p&&g(s=>(0,K.A)((0,K.A)({},s),{},{[e]:t}))}}),y&&(0,le.jsx)(ff,{ref:d,functionName:n.key,hasUnsavedChanges:o})]}):(0,le.jsx)("div",{className:"h-full flex items-center justify-center text-gray-500",children:"Select a file to view code"})})]})})};function Nf(e){let{appId:t,appName:s,disabled:a=!1,disabledReason:n="",onError:l=()=>{}}=e;const[r,i]=(0,Y.useState)(!1),[o,c]=(0,Y.useState)(!1);(0,Y.useEffect)(()=>{(async()=>{if(!window.entri)return new Promise(e=>{const t=document.createElement("script");t.src="https://cdn.goentri.com/entri.js",t.async=!0,t.onload=()=>{c(!0),e()},document.body.appendChild(t)});c(!0)})()},[]);return(0,le.jsx)(Yt,{size:"sm",onClick:async()=>{if(a)l("Cannot purchase domain",n||"Domain purchase is currently disabled");else if(o){i(!0);try{const e=await Ya.getEntriToken({appId:t,appName:s}),a=(0,K.A)({},e.config);await window.entri.purchaseDomain(a),tt("Domain - Buy",{})}catch(c){var e,r;const t=(null===(e=c.response)||void 0===e||null===(r=e.data)||void 0===r?void 0:r.detail)||c.message||"Failed to get purchase config",s=t.includes("Maximum of")&&t.includes("domains allowed");l(s?"Domain limit reached":"Error purchasing domain",t)}i(!1)}else l("Error","Entri is not ready yet. Please try again in a moment.")},disabled:r||!o||a,className:"h-8 px-4 rounded-md text-sm ".concat(a?"bg-red-100 hover:bg-red-100 text-red-700 border border-red-200 cursor-not-allowed":"bg-black text-white hover:bg-gray-800"),children:r?"Buy Domain":o?a?(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(qp.A,{className:"h-3 w-3 mr-2"}),"Domain Limit Reached"]}):"Buy Domain":(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(nx.A,{className:"h-3 w-3 mr-2 animate-spin"}),"Loading Entri..."]})})}var wf=s(39181);const _f=["className"],kf=["className","variant"],Cf=["className"],Af=["className"],Sf=["className"],Ef=["className"],If=wf.Provider,Tf=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,_f);return(0,le.jsx)(wf.Viewport,(0,K.A)({ref:t,className:Pe("fixed top-0 z-[100] flex max-h-screen w-full flex-col-reverse p-4 sm:bottom-0 sm:right-0 sm:top-auto sm:flex-col md:max-w-[420px]",s)},a))});Tf.displayName=wf.Viewport.displayName;const Pf=(0,Ee.cva)("group pointer-events-auto relative flex w-full items-center justify-between space-x-4 overflow-hidden rounded-md border p-6 pr-8 shadow-lg transition-all data-[swipe=cancel]:translate-x-0 data-[swipe=end]:translate-x-[var(--radix-toast-swipe-end-x)] data-[swipe=move]:translate-x-[var(--radix-toast-swipe-move-x)] data-[swipe=move]:transition-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[swipe=end]:animate-out data-[state=closed]:fade-out-80 data-[state=closed]:slide-out-to-right-full data-[state=open]:slide-in-from-top-full data-[state=open]:sm:slide-in-from-bottom-full",{variants:{variant:{default:"border bg-background text-foreground",destructive:"destructive group border-destructive bg-destructive text-destructive-foreground"}},defaultVariants:{variant:"default"}}),Lf=Y.forwardRef((e,t)=>{let{className:s,variant:a}=e,n=(0,Se.A)(e,kf);return(0,le.jsx)(wf.Root,(0,K.A)({ref:t,className:Pe(Pf({variant:a}),s)},n))});Lf.displayName=wf.Root.displayName;const Of=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,Cf);return(0,le.jsx)(wf.Action,(0,K.A)({ref:t,className:Pe("inline-flex h-8 shrink-0 items-center justify-center rounded-md border bg-transparent px-3 text-sm font-medium ring-offset-background transition-colors hover:bg-secondary focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 group-[.destructive]:border-muted/40 group-[.destructive]:hover:border-destructive/30 group-[.destructive]:hover:bg-destructive group-[.destructive]:hover:text-destructive-foreground group-[.destructive]:focus:ring-destructive",s)},a))});Of.displayName=wf.Action.displayName;const Rf=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,Af);return(0,le.jsx)(wf.Close,(0,K.A)((0,K.A)({ref:t,className:Pe("absolute right-2 top-2 rounded-md p-1 text-foreground/50 opacity-0 transition-opacity hover:text-foreground focus:opacity-100 focus:outline-none focus:ring-2 group-hover:opacity-100 group-[.destructive]:text-red-300 group-[.destructive]:hover:text-red-50 group-[.destructive]:focus:ring-red-400 group-[.destructive]:focus:ring-offset-red-600",s),"toast-close":""},a),{},{children:(0,le.jsx)(Bt.A,{className:"h-4 w-4"})}))});Rf.displayName=wf.Close.displayName;const Mf=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,Sf);return(0,le.jsx)(wf.Title,(0,K.A)({ref:t,className:Pe("text-sm font-semibold",s)},a))});Mf.displayName=wf.Title.displayName;const Df=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,Ef);return(0,le.jsx)(wf.Description,(0,K.A)({ref:t,className:Pe("text-sm opacity-90",s)},a))});Df.displayName=wf.Description.displayName;const Ff=["id","title","description","action"];function Bf(){const{toasts:e}=nn();return(0,le.jsxs)(If,{children:[e.map(function(e){let{id:t,title:s,description:a,action:n}=e,l=(0,Se.A)(e,Ff);return(0,le.jsxs)(Lf,(0,K.A)((0,K.A)({},l),{},{children:[(0,le.jsxs)("div",{className:"grid gap-1",children:[s&&(0,le.jsx)(Mf,{children:s}),a&&(0,le.jsx)(Df,{children:a})]}),n,(0,le.jsx)(Rf,{})]}),t)}),(0,le.jsx)(Tf,{})]})}const zf=["isLoading","loadingText","children"],Uf=150,Wf=e=>{let{isLoading:t,loadingText:s,children:a}=e,n=(0,Se.A)(e,zf);return(0,le.jsx)(Yt,(0,K.A)((0,K.A)({},n),{},{children:t?(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(nx.A,{className:"h-4 w-4 mr-2 animate-spin"}),s]}):a}))},qf=e=>{let{open:t,onOpenChange:s,title:a,description:n,isLoading:l,loadingText:r,confirmText:i,onConfirm:o,variant:c="destructive"}=e;return(0,le.jsx)(Pa,{open:t,onOpenChange:s,children:(0,le.jsxs)(Da,{children:[(0,le.jsxs)(Fa,{children:[(0,le.jsx)(za,{children:a}),(0,le.jsx)(Ua,{children:n})]}),(0,le.jsxs)("div",{className:"flex justify-end gap-2 pt-4",children:[(0,le.jsx)(Yt,{variant:"outline",onClick:()=>s(!1),children:"Cancel"}),(0,le.jsx)(Wf,{variant:c,onClick:o,disabled:l,isLoading:l,loadingText:r,children:i})]})]})})},Vf=e=>{var t,s;let{domain:a}=e;const n=void 0!==(null===(t=a.purchase_info)||void 0===t?void 0:t.purchase_time),l=!0===(null===(s=a.purchase_info)||void 0===s?void 0:s.blocked);return!0===a.disabled?(0,le.jsx)("span",{className:"px-2 py-0.5 text-xs bg-red-100 text-red-700 rounded-full",children:"Blocked"}):l?(0,le.jsx)("span",{className:"px-2 py-0.5 text-xs bg-orange-100 text-orange-700 rounded-full",children:"Propagation Blocked"}):n?(0,le.jsx)("span",{className:"px-2 py-0.5 text-xs bg-blue-100 text-blue-700 rounded-full",children:"Base44 Domain"}):null},Hf=e=>{let{status:t,lastChecked:s,lastPollingTime:a,isBoughtDomain:n,isActive:l,isUnlinked:r,isDisabled:i}=e;return i?(0,le.jsxs)("div",{className:"space-y-1",children:[(0,le.jsx)("p",{className:"text-sm text-red-600",children:"Domain requires Builder plan or above"}),(0,le.jsx)("a",{href:"/billing",className:"text-xs text-blue-600 hover:text-blue-800 underline",children:"Update billing to restore access"})]}):r?(0,le.jsx)("p",{className:"text-sm text-gray-500",children:t}):(0,le.jsxs)("div",{className:"space-y-1",children:[(0,le.jsx)("p",{className:"text-sm text-gray-500",children:t}),!n&&s&&(0,le.jsx)("div",{className:"flex items-center gap-2 text-xs text-gray-400",children:(0,le.jsxs)("span",{children:["Last checked: ",ra().utc(s).fromNow()]})}),n&&!l&&a&&(0,le.jsx)("div",{className:"flex items-center gap-2 text-xs text-gray-400",children:(0,le.jsxs)("span",{children:["Last checked: ",ra()(a).format("HH:mm:ss")]})})]})},Yf=e=>{var t,s,a,n;let{domain:l,isChecking:r,isVerifying:i,isUnlinking:o,onCheck:c,onVerify:d,onUnlink:m}=e;const[u,x]=(0,Y.useState)(!1),{toast:h}=nn(),p=void 0!==(null===(t=l.purchase_info)||void 0===t?void 0:t.purchase_time),g=!0===(null===(s=l.purchase_info)||void 0===s?void 0:s.unlinked),f=(null===(a=l.purchase_info)||void 0===a?void 0:a.purchase_time)&&(null===(n=l.purchase_info)||void 0===n?void 0:n.propagation_status);if(!0===l.disabled)return null;const v=async()=>{x(!0);try{await Ya.link(l.id),h({title:"Domain linked",description:"Domain has been linked to your project",duration:3e3}),c()}catch(s){var e,t;h({variant:"destructive",title:"Error linking domain",description:(null===(e=s.response)||void 0===e||null===(t=e.data)||void 0===t?void 0:t.detail)||"Something went wrong",duration:3e3})}x(!1)};return g?(0,le.jsx)("div",{className:"flex items-center gap-2 justify-end",children:(0,le.jsx)(Wf,{variant:"outline",size:"sm",onClick:v,disabled:u,isLoading:u,loadingText:"Linking...",children:"Link Domain"})}):(0,le.jsxs)("div",{className:"flex items-center gap-2 justify-end",children:[!f&&(0,le.jsxs)(Wf,{variant:"ghost",size:"sm",onClick:c,className:"text-gray-500",disabled:r,isLoading:r,loadingText:"Checking...",children:[(0,le.jsx)(nx.A,{className:"h-4 w-4 mr-2"}),"Check Status"]}),!p&&(0,le.jsx)(Wf,{variant:"outline",size:"sm",onClick:d,disabled:i,isLoading:i,loadingText:"Verifying...",children:"Verify Domain"}),p&&!g&&(0,le.jsx)(Wf,{variant:"outline",size:"sm",onClick:m,disabled:o,isLoading:o,loadingText:"Unlinking...",children:"Unlink Domain"})]})},Gf=e=>{var t,s,a,n;let{domain:l,onUpdate:r,lastPollingTime:i}=e;const{toast:o}=nn(),[c,d]=(0,Y.useState)(!1),[m,u]=(0,Y.useState)(!1),[x,h]=(0,Y.useState)(!1),[p,g]=(0,Y.useState)(!1),[f,v]=(0,Y.useState)(!1),[b,j]=(0,Y.useState)(!1),y=void 0!==(null===(t=l.purchase_info)||void 0===t?void 0:t.purchase_time),N=!0===(null===(s=l.purchase_info)||void 0===s?void 0:s.unlinked),w=l.disabled?"Blocked":null!==(_=l.purchase_info)&&void 0!==_&&_.unlinked?"Unlinked":null!==(k=l.purchase_info)&&void 0!==k&&k.purchase_time&&null!==(C=l.purchase_info)&&void 0!==C&&C.propagation_status?"Domain Active":null===(A=l.purchase_info)||void 0===A||!A.purchase_time||null!==(S=l.purchase_info)&&void 0!==S&&S.blocked?"verified"===(null===(E=l.last_status_payload)||void 0===E?void 0:E.verificationStatus)?"Verified":"error"===(null===(I=l.last_status_payload)||void 0===I?void 0:I.verificationStatus)?"Error":"Pending":"Waiting for DNS Propagation";var _,k,C,A,S,E,I;const T=!0===l.disabled;return(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(qf,{open:f,onOpenChange:v,title:"Delete Domain",description:"Are you sure you want to delete?",isLoading:m,loadingText:"Deleting...",confirmText:"Delete Domain",onConfirm:async()=>{u(!0);try{await Ya.delete(l.id),o({title:"Domain deleted",duration:3e3}),r()}catch(s){var e,t;o({variant:"destructive",title:"Error deleting domain",description:(null===(e=s.response)||void 0===e||null===(t=e.data)||void 0===t?void 0:t.detail)||"Something went wrong",duration:3e3})}u(!1),v(!1)}}),(0,le.jsx)(qf,{open:b,onOpenChange:j,variant:"default",title:"Unlink Domain",description:"This domain was purchased through Base44.\n\nIt will remain listed under your domains but will no longer be connected to your project.",isLoading:p,loadingText:"Unlinking...",confirmText:"Unlink Domain",onConfirm:async()=>{g(!0);try{await Ya.unlink(l.id),o({title:"Domain unlinked",description:"Domain has been unlinked from your project",duration:3e3}),r()}catch(s){var e,t;o({variant:"destructive",title:"Error unlinking domain",description:(null===(e=s.response)||void 0===e||null===(t=e.data)||void 0===t?void 0:t.detail)||"Something went wrong",duration:3e3})}g(!1),j(!1)}}),(0,le.jsx)(is,{className:"hover:bg-gray-50 transition-colors ".concat(N||l.disabled?"opacity-60":""),children:(0,le.jsx)(ms,{className:"p-4",children:(0,le.jsxs)("div",{className:"flex flex-col space-y-4",children:[(0,le.jsxs)("div",{className:"flex items-center justify-between",children:[(0,le.jsxs)("div",{className:"flex items-center gap-3",children:["Domain Active"===w||"Verified"===w?(0,le.jsx)(pr.A,{className:"h-5 w-5 text-green-500"}):"Blocked"===w?(0,le.jsx)(_e.A,{className:"h-5 w-5 text-red-500"}):(0,le.jsx)(_e.A,{className:"h-5 w-5 text-yellow-500"}),(0,le.jsxs)("div",{children:[(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[(0,le.jsx)("a",{href:"https://".concat(l.domain),target:"_blank",children:(0,le.jsx)("p",{className:"font-medium",children:l.domain})}),(0,le.jsx)(Vf,{domain:l})]}),(0,le.jsx)(Hf,{status:w,lastChecked:l.last_status_check,lastPollingTime:i,isUnlinked:N,isBoughtDomain:y,isActive:(null===(a=l.purchase_info)||void 0===a?void 0:a.purchase_time)&&(null===(n=l.purchase_info)||void 0===n?void 0:n.propagation_status),isDisabled:T})]})]}),(0,le.jsx)(Yt,{variant:"ghost",size:"sm",onClick:()=>v(!0),className:"text-red-500 hover:text-red-600 hover:bg-red-50",disabled:m||y&&!N&&!l.disabled,children:(0,le.jsx)(Ip.A,{className:"h-4 w-4 ".concat(m?"animate-spin":"")})})]}),(0,le.jsx)(Yf,{domain:l,isChecking:x,isVerifying:c,isUnlinking:p,onCheck:async()=>{h(!0);try{var e;const t=void 0!==(null===(e=l.purchase_info)||void 0===e?void 0:e.purchase_time);t||await Ya.refreshStatus(l.id),r(),t&&await new Promise(e=>setTimeout(e,1e3))}catch(a){var t,s;o({variant:"destructive",title:"Error checking status",description:(null===(t=a.response)||void 0===t||null===(s=t.data)||void 0===s?void 0:s.detail)||"Something went wrong",duration:3e3})}h(!1)},onVerify:async()=>{d(!0);try{await Ya.verify(l.id),o({title:"Verification initiated",description:"Please check back in a few minutes",duration:3e3}),r()}catch(s){var e,t;o({variant:"destructive",title:"Error verifying domain",description:(null===(e=s.response)||void 0===e||null===(t=e.data)||void 0===t?void 0:t.detail)||"Something went wrong",duration:3e3})}d(!1)},onUnlink:()=>j(!0)})]})})})]})},$f=e=>{let{onAdd:t,loading:s,open:a,setOpen:n,disabled:l=!1,disabledReason:r=""}=e;const[i,o]=(0,Y.useState)("");return(0,le.jsxs)(Pa,{open:a,onOpenChange:n,children:[(0,le.jsx)(La,{asChild:!0,children:(0,le.jsx)(Yt,{variant:"outline",disabled:l,className:"text-gray-700 hover:text-gray-900 hover:bg-gray-100 ".concat(l?"bg-red-50 border-red-200 text-red-600 cursor-not-allowed hover:bg-red-50 hover:text-red-600":""),children:l?(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(ux.A,{className:"h-4 w-4 mr-2"}),"Domain Limit Reached"]}):(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(kt.A,{className:"h-4 w-4 mr-2"}),"Add Domain"]})})}),(0,le.jsxs)(Da,{children:[(0,le.jsxs)(Fa,{children:[(0,le.jsx)(za,{children:"Add New Domain"}),(0,le.jsx)(Ua,{children:"Enter your domain name below. Make sure it follows the format: app.example.com"})]}),(0,le.jsxs)("div",{className:"space-y-4 pt-4",children:[(0,le.jsx)(fs,{placeholder:"Enter domain (e.g. app.example.com)",value:i,onChange:e=>o(e.target.value)}),(0,le.jsx)("div",{className:"flex justify-end",children:(0,le.jsx)(Wf,{onClick:async()=>{if(l)return;const e=i.toLowerCase().trim();await t(e),o(""),n(!1)},disabled:s||!i,isLoading:s,loadingText:"Adding...",children:"Add Domain"})})]})]})]})},Jf=e=>{let{onUpgrade:t}=e;return(0,le.jsx)("div",{className:"w-full",children:(0,le.jsxs)("div",{className:"w-full rounded-lg p-12 text-center",style:{borderWidth:"2px",borderStyle:"dashed",borderColor:"#e5e7eb",borderRadius:"12px"},children:[(0,le.jsx)("h3",{className:"text-xl font-semibold mb-2",children:"Want to use your domain?"}),(0,le.jsxs)("p",{className:"text-gray-600 mb-6",children:["Custom domains are available on our Builder plan and above.",(0,le.jsx)("br",{}),"Upgrade to connect your domain to this app."]}),(0,le.jsx)(Yt,{onClick:t,className:"bg-black text-white hover:bg-gray-800",children:"View Plans"})]})})},Zf=e=>{let{domain:t,appId:s,appName:a,onDismiss:n,hasReachedDomainLimit:l,onError:r}=e;const[i,o]=(0,Y.useState)(!1),[c,d]=(0,Y.useState)(!1);(0,Y.useEffect)(()=>{(async()=>{if(!window.entri)return new Promise(e=>{const t=document.createElement("script");t.src="https://cdn.goentri.com/entri.js",t.async=!0,t.onload=()=>{d(!0),e()},document.body.appendChild(t)});d(!0)})()},[]);return(0,le.jsx)(is,{className:"border border-slate-200 bg-slate-50/50 hover:bg-slate-50 hover:border-slate-300 transition-all",children:(0,le.jsx)(ms,{className:"p-4",children:(0,le.jsx)("div",{className:"flex items-center justify-between gap-4",children:(0,le.jsxs)("div",{className:"flex items-center gap-3 flex-1",children:[(0,le.jsx)(bn.A,{className:"h-4 w-4 text-slate-400 shrink-0"}),(0,le.jsx)("div",{className:"flex-1",children:(0,le.jsxs)("p",{className:"text-sm text-slate-700",children:[(0,le.jsx)("span",{className:"font-medium text-slate-900",children:t})," is available"]})}),(0,le.jsx)(Yt,{onClick:async()=>{if(l)r("Cannot purchase domain","Maximum of ".concat(Uf," domains reached for this app"));else if(c){o(!0);try{const e=await Ya.getEntriToken({appId:s,appName:a,domain:t}),n=(0,K.A)({},e.config);await window.entri.purchaseDomain(n),tt("Domain - Buy from Suggestion",{domain:t})}catch(i){var e,n;const t=(null===(e=i.response)||void 0===e||null===(n=e.data)||void 0===n?void 0:n.detail)||i.message||"Failed to get purchase config",s=t.includes("Maximum of")&&t.includes("domains allowed");r(s?"Domain limit reached":"Error purchasing domain",t)}o(!1)}else r("Error","Entri is not ready yet. Please try again in a moment.")},variant:"outline",size:"sm",disabled:i||!c||l,className:"shrink-0",children:i?(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(nx.A,{className:"h-3.5 w-3.5 mr-2 animate-spin"}),"Processing..."]}):c?"Purchase":(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(nx.A,{className:"h-3.5 w-3.5 mr-2 animate-spin"}),"Loading..."]})}),(0,le.jsx)("button",{onClick:n,className:"p-1 text-slate-400 hover:text-slate-600 hover:bg-slate-200 rounded transition-colors shrink-0","aria-label":"Dismiss suggestion",children:(0,le.jsx)(Bt.A,{size:14})})]})})})})},Kf=()=>(0,le.jsx)(is,{children:(0,le.jsx)(ms,{className:"p-4",children:(0,le.jsxs)("div",{className:"flex items-start gap-3",children:[(0,le.jsx)(ku.A,{className:"h-5 w-5 text-blue-500 shrink-0 mt-0.5"}),(0,le.jsxs)("div",{className:"space-y-2 text-sm",children:[(0,le.jsxs)("p",{className:"font-medium",children:[(0,le.jsx)("b",{children:"After adding a domain"}),", connect it via your DNS provider:"]}),(0,le.jsxs)("ol",{className:"list-decimal list-inside space-y-1 text-gray-600",children:[(0,le.jsxs)("li",{children:["Add CNAME record: ",(0,le.jsx)("code",{className:"bg-gray-100 px-1.5 py-0.5 rounded",children:"www \u2192 base44.onrender.com"})]}),(0,le.jsxs)("li",{children:["Add ANAME/ALIAS record: ",(0,le.jsx)("code",{className:"bg-gray-100 px-1.5 py-0.5 rounded",children:"empty or @ \u2192 base44.onrender.com"})]}),(0,le.jsxs)("li",{children:["If your DNS provider doesn't support ANAME/ALIAS, use A record: ",(0,le.jsx)("code",{className:"bg-gray-100 px-1.5 py-0.5 rounded",children:"@ \u2192 216.24.57.1"})]}),(0,le.jsx)("li",{children:"Remove any AAAA records from your domain while configuring DNS. AAAA records map to an IPv6 address, and Base44 uses IPv4. These records can cause unexpected behavior for your custom domain."})]}),(0,le.jsx)("p",{className:"text-gray-600",children:"Note: After adding DNS records, it may take some time for changes to fully propagate across the internet. During this time, the domain may not work properly."}),(0,le.jsxs)("p",{className:"text-xs text-gray-500",children:["Need help? Create a ticket at ",(0,le.jsx)("button",{type:"button",onClick:()=>{window.open("/support","_blank")},className:"underline text-primary hover:text-orange-500 transition-colors",children:"support system"})]})]})]})})}),Qf=e=>{let{currentCount:t,maxCount:s}=e;return(0,le.jsx)(is,{className:"border-orange-200 bg-orange-50",children:(0,le.jsx)(ms,{className:"p-4",children:(0,le.jsxs)("div",{className:"flex items-start gap-3",children:[(0,le.jsx)(ux.A,{className:"h-5 w-5 text-orange-500 shrink-0 mt-0.5"}),(0,le.jsxs)("div",{className:"space-y-2 text-sm",children:[(0,le.jsx)("p",{className:"font-medium text-orange-800",children:"Domain Limit Reached"}),(0,le.jsxs)("p",{className:"text-orange-700",children:["You have reached the maximum of ",s," domains for this app (",t,"/",s,"). Please remove some domains before adding new ones."]})]})]})})})},Xf=e=>{let{app:t,onUpdate:s,isPaidTier:a=!0}=e;const[n,l]=(0,Y.useState)(!1),{toast:r}=nn(),i=fa(t).replace(/^https?:\/\//,"");return t?(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(ev,{app:t,onUpdate:s,open:n,onOpenChange:l,isPaidTier:a}),(0,le.jsx)(is,{className:"border rounded-lg",children:(0,le.jsx)(ms,{className:"p-4",children:(0,le.jsxs)("div",{className:"flex items-center justify-between",children:[(0,le.jsxs)("div",{className:"flex-1",children:[(0,le.jsx)("div",{className:"text-[16px] font-medium mb-1",children:i}),(0,le.jsx)("div",{className:"text-sm text-gray-500",children:"Never Expires"})]}),(0,le.jsx)(Yt,{variant:"outline",size:"sm",onClick:()=>l(!0),className:"ml-4",children:"Edit URL"})]})})})]}):null},ev=e=>{let{app:t,onUpdate:s,open:a,onOpenChange:n,isPaidTier:l=!0}=e;const[r,i]=(0,Y.useState)((null==t?void 0:t.slug)||""),[o,c]=(0,Y.useState)(!1),[d,m]=(0,Y.useState)(""),{toast:u}=nn(),x=(0,Z.Zp)();(0,Y.useEffect)(()=>{i((null==t?void 0:t.slug)||""),m("")},[null==t?void 0:t.slug]);if(!t)return null;return(0,le.jsx)(Pa,{open:a,onOpenChange:n,children:(0,le.jsxs)(Da,{className:"w-[634px] max-w-[634px] p-6",children:[(0,le.jsx)(Fa,{className:"text-left mb-3",children:(0,le.jsx)(za,{className:"text-lg font-semibold",children:"Edit URL"})}),(0,le.jsx)("div",{className:"space-y-6",children:(0,le.jsxs)("div",{children:[(0,le.jsxs)("div",{className:"flex justify-between items-center mb-2",children:[(0,le.jsx)("p",{className:"text-sm font-normal text-gray-500",children:"Base44 Built-in domain"}),r&&(0,le.jsx)("button",{onClick:async()=>{c(!0);try{await s({slug:null});const e=fa(t).replace(/^https?:\/\//,"");u({title:"Slug reset to default",description:"Your app is now available at ".concat(e),duration:3e3}),tt("Custom URL - Reset to Default",{}),n(!1),i("")}catch(d){var e,a;u({variant:"destructive",title:"Error resetting slug",description:(null===(e=d.response)||void 0===e||null===(a=e.data)||void 0===a?void 0:a.detail)||"Failed to reset to default slug",duration:3e3})}c(!1)},disabled:o,className:"text-sm text-black hover:text-gray-600 disabled:opacity-50 disabled:cursor-not-allowed",children:"Reset to default"})]}),l?(0,le.jsxs)(le.Fragment,{children:[(0,le.jsxs)("div",{className:"relative flex items-center h-10 rounded-md border border-gray-300 bg-white hover:bg-gray-50 focus-within:ring-2 focus-within:ring-black focus-within:border-black",children:[(0,le.jsx)("span",{className:"text-sm text-gray-500 pl-3 select-none",children:"https://"}),(0,le.jsx)("input",{value:r,onChange:e=>{i(e.target.value.toLowerCase()),m("")},className:"flex-1 text-base bg-transparent outline-none"}),(0,le.jsxs)("span",{className:"text-sm text-gray-400 pr-3 select-none",children:[".","base44.app"]})]}),d&&(0,le.jsxs)("div",{className:"flex items-center gap-2 text-sm text-red-600 mt-2",children:[(0,le.jsx)(_e.A,{className:"h-4 w-4"}),(0,le.jsx)("span",{children:d})]}),(0,le.jsx)("div",{className:"flex justify-end items-center mt-6",children:(0,le.jsx)(Wf,{onClick:async()=>{c(!0);try{if(!r){await s({slug:null});const e=fa(t).replace(/^https?:\/\//,"");return u({title:"URL updated",description:"Custom url removed. Your app is now available at ".concat(e),duration:3e3}),n(!1),i(""),void c(!1)}await s({slug:r});const e=fa((0,K.A)((0,K.A)({},t),{},{slug:r})).replace(/^https?:\/\//,"");u({title:"URL updated",description:"Your app is now available at ".concat(e),duration:3e3}),tt("Custom URL - Updated",{}),n(!1),i(r)}catch(d){var e,a;const s=(null===(e=d.response)||void 0===e||null===(a=e.data)||void 0===a?void 0:a.detail)||d.message||"Something went wrong";s.toLowerCase().includes("is already in use")?m("URL change failed, this URL is already taken. Please try a different one."):s.toLowerCase().includes("this subdomain is reserved")?m("This URL is reserved. Please try a different one."):m("This URL is invalid. Please try a different one.")}c(!1)},disabled:o||r===(null==t?void 0:t.slug),isLoading:o,loadingText:"Changing...",className:"bg-black text-white hover:bg-gray-800 ml-auto",children:"Change"})})]}):(0,le.jsxs)(le.Fragment,{children:[(0,le.jsxs)("div",{className:"relative flex items-center h-10 rounded-md border border-gray-300 bg-gray-100",children:[(0,le.jsx)("span",{className:"text-sm text-gray-500 pl-3 select-none",children:"https://"}),(0,le.jsx)("input",{value:null==t?void 0:t.slug,disabled:!0,className:"flex-1 text-base bg-transparent outline-none"}),(0,le.jsxs)("span",{className:"text-sm text-gray-400 pr-3 select-none",children:[".","base44.app"]})]}),(0,le.jsx)("div",{className:"bg-blue-50 border border-blue-200 rounded-lg p-4 mt-4",children:(0,le.jsxs)("div",{className:"flex items-start gap-3",children:[(0,le.jsx)(_e.A,{className:"h-4 w-4 text-blue-500 mt-0.5 shrink-0"}),(0,le.jsxs)("p",{className:"text-sm text-blue-800",children:["URL editing requires a starter plan."," ",(0,le.jsx)("button",{onClick:()=>{n(!1),x("/billing")},className:"underline font-medium hover:text-blue-900",children:"Upgrade to Premium"})]})]})})]})]})})]})})};function tv(e){var t;let{appId:s,appName:a}=e;const{user:n}=oe(),{app:l,updateApp:r,suggestions:i,dismissDomainSuggestion:o}=Nt(),[c,d]=(0,Y.useState)([]),[m,u]=(0,Y.useState)(!1),{toast:x}=nn(),h=(0,Z.Zp)(),p=(0,Y.useRef)(null),[g,f]=(0,Y.useState)(!1),[v,b]=(0,Y.useState)(null),[j,y]=(0,Y.useState)(!1),[N,w]=(0,Y.useState)(!1),[_,k]=(0,Y.useState)(null),C=cx(n,"builder"),A=c.length>=Uf,S=async()=>{try{const t=await Ya.filter({app_id:s});if(d(t),k(Date.now()),v){const s=t.find(e=>e.domain===v);var e;if(s)b(null),null!==(e=s.purchase_info)&&void 0!==e&&e.propagation_status||g?I():E()}const a=t.some(e=>{var t,s,a;return(null===(t=e.purchase_info)||void 0===t?void 0:t.purchase_time)&&!(null!==(s=e.purchase_info)&&void 0!==s&&s.propagation_status)&&!(null!==(a=e.purchase_info)&&void 0!==a&&a.blocked)&&!e.disabled});a&&!g?E():!a&&g&&I()}catch(n){var t,a;x({variant:"destructive",title:"Error fetching domains",description:(null===(t=n.response)||void 0===t||null===(a=t.data)||void 0===a?void 0:a.detail)||"Something went wrong",duration:3e3})}},E=()=>{f(!0),p.current&&clearInterval(p.current),p.current=setInterval(S,1e4)},I=()=>{f(!1),p.current&&(clearInterval(p.current),p.current=null)};(0,Y.useEffect)(()=>(C&&S(),()=>{I()}),[s,C]),(0,Y.useEffect)(()=>{const e=new URLSearchParams(window.location.search),t=e.get("result"),s=e.get("domain");if(t||s||tt("Domain - Manage",{}),t&&s){"success"===t?(x({title:"Domain Purchased!",description:"Your domain ".concat(s," was purchased successfully. Waiting for it to appear in your domains...")}),b(s),E(),tt("Domain - Purchased Successfully",{domain:s})):x({variant:"destructive",title:"Domain Purchase Failed",description:"Purchase failed for ".concat(s,".")});const e=new URL(window.location);e.searchParams.delete("result"),e.searchParams.delete("domain"),window.history.replaceState({},document.title,e.pathname)}},[]);const T=async e=>{if(e)if(A)x({variant:"destructive",title:"Domain limit reached",description:"You can only have up to ".concat(Uf," domains per app. Please remove some domains first."),duration:5e3});else{u(!0);try{await Ya.create({domain:e,app_id:s}),await S(),x({title:"Domain added successfully",description:"Please verify your domain to complete setup",duration:3e3})}catch(n){var t,a;x({variant:"destructive",title:"Error creating domain",description:(null===(t=n.response)||void 0===t||null===(a=t.data)||void 0===a?void 0:a.detail)||"Something went wrong",duration:3e3})}u(!1)}},P=(e,t)=>{const s=e.includes("Domain limit reached")||t.includes("Maximum of");x({variant:"destructive",title:e,description:t,duration:s?5e3:3e3})};return(0,le.jsxs)(up,{title:"Domains",subtitle:(0,le.jsxs)("p",{children:["Buy, connect and manage your domains. ",(0,le.jsx)("a",{href:"https://docs.base44.com/Guides/Setting-up-your-custom-domain#custom-domain-setup-and-troubleshooting-guide",target:"_blank",rel:"noopener noreferrer",className:"text-blue-600 hover:underline",children:"Learn more"})]}),children:[(0,le.jsx)(Bf,{}),(0,le.jsxs)("div",{children:[(0,le.jsxs)("div",{className:"mb-12",children:[(0,le.jsx)("h3",{className:"text-base font-medium text-black mb-4",children:"Built-in domain"}),(0,le.jsx)(Xf,{app:l,onUpdate:r,isPaidTier:!0})]}),(0,le.jsxs)("div",{className:"mb-8",children:[(0,le.jsx)("h3",{className:"text-base font-medium text-black mb-4",children:"Custom domains"}),C&&(null==i?void 0:i.domain_suggestion)&&!i.domain_suggestion.dismissed&&(0,le.jsx)("div",{className:"mb-4",children:(0,le.jsx)(Zf,{domain:null===(t=i.domain_suggestion.api_response)||void 0===t?void 0:t.domain,appId:s,appName:a,onDismiss:o,hasReachedDomainLimit:A,onError:P})}),C?!A&&(0,le.jsxs)("div",{className:"flex items-center gap-2.5 mb-4",children:[(0,le.jsx)(Yt,{variant:"outline",size:"sm",onClick:()=>y(e=>!e),className:"h-8 px-4 rounded-md border text-sm bg-white",children:"Connect your Domain"}),(0,le.jsx)("div",{className:"inline-block",children:(0,le.jsx)(Nf,{appId:s,appName:a,disabled:A,disabledReason:A?"Maximum of ".concat(Uf," domains reached for this app"):"",onError:P})})]}):(0,le.jsx)(Jf,{onUpgrade:()=>h("/billing")})]}),C&&A&&(0,le.jsx)(Qf,{currentCount:c.length,maxCount:Uf}),C&&j&&!A&&(0,le.jsxs)("div",{className:"space-y-2 mb-4 w-full max-w-xl",children:[(0,le.jsx)($f,{onAdd:T,loading:m,open:N,setOpen:w,disabled:A,disabledReason:A?"Maximum of ".concat(Uf," domains reached"):""}),(0,le.jsx)(Kf,{})]}),C&&A&&j&&(0,le.jsxs)("div",{className:"space-y-2 mb-4 w-full max-w-xl",children:[(0,le.jsx)($f,{onAdd:T,loading:m,open:N,setOpen:w,disabled:A,disabledReason:A?"Maximum of ".concat(Uf," domains reached"):""}),(0,le.jsx)("div",{className:"text-sm text-red-600 mt-2 p-3 bg-red-50 border border-red-200 rounded-md",children:(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[(0,le.jsx)(ux.A,{className:"h-4 w-4"}),(0,le.jsxs)("span",{children:["Cannot add domains: You have reached the maximum limit of ",Uf," domains per app."]})]})})]}),C&&(0,le.jsx)("div",{className:"grid gap-6",children:c.length>0&&(0,le.jsx)("div",{className:"space-y-4",children:c.map(e=>(0,le.jsx)(Gf,{domain:e,onUpdate:S,lastPollingTime:_},e.id))})})]})]})}var sv=s(35097),av=s(54699),nv=s(81064),lv=s(81946);function rv(e){let{rule:t}=e;if(!t)return(0,le.jsx)("span",{className:"text-muted-foreground",children:"No restrictions"});if("{{user.email}}"===t.created_by)return(0,le.jsxs)("span",{className:"flex items-center gap-1.5",children:[(0,le.jsx)(nv.A,{className:"h-3.5 w-3.5",style:{color:"#64748b"}})," Creator only"]});if(t.user_condition&&"admin"===t.user_condition.role)return(0,le.jsxs)("span",{className:"flex items-center gap-1.5",children:[(0,le.jsx)(lv.A,{className:"h-3.5 w-3.5",style:{color:"#64748b"}})," Admin only"]});if(t.$or)return(0,le.jsxs)("span",{className:"flex items-center gap-1.5",children:[(0,le.jsx)("span",{className:"bg-secondary text-secondary-foreground text-xs rounded-md px-1.5 py-0.5",children:"OR"}),(0,le.jsxs)("span",{children:[t.$or.length," conditions"]})]});if(t.$and)return(0,le.jsxs)("span",{className:"flex items-center gap-1.5",children:[(0,le.jsx)("span",{className:"bg-secondary text-secondary-foreground text-xs rounded-md px-1.5 py-0.5",children:"AND"}),(0,le.jsxs)("span",{children:[t.$and.length," conditions"]})]});const s=Object.keys(t).filter(e=>!e.startsWith("$"));if(s.length){const e=s[0],a=t[e];if("string"==typeof a&&a.startsWith("{{user."))return(0,le.jsxs)("span",{className:"flex items-center gap-1.5",children:[(0,le.jsx)(hr.A,{className:"h-3.5 w-3.5",style:{color:"#64748b"}}),(0,le.jsxs)("span",{className:"text-xs font-medium",children:[e.replace("data.","")," = user field"]})]})}if(t.field_condition){const e=Object.entries(t.field_condition).map(e=>{let[t,s]=e;return"".concat(t,": ").concat(JSON.stringify(s))}).join(", ");return(0,le.jsxs)("span",{className:"flex items-center gap-1.5",children:[(0,le.jsx)(hr.A,{className:"h-3.5 w-3.5",style:{color:"#64748b"}}),(0,le.jsxs)("span",{className:"text-xs font-medium",children:["Field(s): ",e]})]})}return(0,le.jsxs)("span",{className:"text-xs font-medium flex items-center gap-1.5",children:[(0,le.jsx)(qc.A,{className:"h-3.5 w-3.5",style:{color:"#64748b"}}),"Custom rule"]})}function iv(e){let{rec:t,onApply:s,onDismiss:a,forceOpen:n,onOpen:l}=e;const[r,i]=(0,Y.useState)(!!n),[o,c]=(0,Y.useState)(!1),d=(e,t,s)=>(0,le.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,le.jsxs)("div",{className:"flex items-center gap-2 mb-1 text-black font-medium text-sm",children:[t,s]}),o?(0,le.jsx)("textarea",{className:"w-full font-mono text-xs border border-slate-200 rounded p-2 resize-none text-black",style:{background:"#F3F6F9"},rows:3,value:e,readOnly:!0}):(0,le.jsx)("div",{className:"w-full text-xs min-h-[32px] flex flex-col gap-1",children:(()=>{try{const t="string"==typeof e?JSON.parse(e):e;if(t&&(t.$or||t.$and)){return(t.$or||t.$and).map((e,t)=>(0,le.jsx)(rv,{rule:e},t))}return(0,le.jsx)(rv,{rule:t})}catch(t){return(0,le.jsx)("span",{children:e})}})()})]});return t?r?(0,le.jsxs)("div",{className:"mt-6 border border-slate-200 rounded-xl p-6 flex flex-col gap-4 shadow-sm animate-in fade-in relative",style:{background:"#fff"},children:[(0,le.jsxs)("div",{className:"flex items-center gap-2 mb-2",children:[(0,le.jsx)("button",{className:"rec-collapsible-trigger mr-2 p-0.5 flex items-center justify-center",style:{width:24,height:24,background:"none",border:"none",boxShadow:"none"},onClick:e=>{e.stopPropagation(),i(!1),a&&a()},"aria-label":"Collapse recommendations",children:(0,le.jsx)(Ts.A,{className:"h-4 w-4 text-slate-500"})}),(0,le.jsx)(ux.A,{className:"h-5 w-5 text-black",strokeWidth:2,fill:"none"}),(0,le.jsx)("span",{className:"font-semibold text-[1.08rem] text-black",children:"RLS Recommendation"})]}),(0,le.jsx)("div",{className:"text-muted-foreground text-sm mb-2",children:t.description}),(0,le.jsxs)("div",{className:"flex items-center gap-1 mb-2",children:[(0,le.jsx)("span",{className:"text-xs text-slate-700",children:"JSON"}),(0,le.jsx)(ix,{checked:o,onCheckedChange:c,onClick:e=>e.stopPropagation(),onFocus:e=>e.stopPropagation(),className:"scale-75"})]}),(0,le.jsxs)("div",{className:o?"flex flex-col gap-3":"grid grid-cols-2 gap-3",children:[t.create_rule&&"{}"!==t.create_rule&&d(t.create_rule,(0,le.jsx)(sv.A,{className:"h-4 w-4 text-green-600 opacity-60"}),"Create"),t.read_rule&&"{}"!==t.read_rule&&d(t.read_rule,(0,le.jsx)(hf.A,{className:"h-4 w-4 text-blue-600 opacity-60"}),"Read"),t.update_rule&&"{}"!==t.update_rule&&d(t.update_rule,(0,le.jsx)(av.A,{className:"h-4 w-4 text-amber-600 opacity-60"}),"Update"),t.delete_rule&&"{}"!==t.delete_rule&&d(t.delete_rule,(0,le.jsx)(Ip.A,{className:"h-4 w-4 text-red-600 opacity-60"}),"Delete")]}),(0,le.jsxs)("div",{className:"flex justify-end gap-2 mt-6",children:[(0,le.jsx)(Yt,{variant:"ghost",className:"text-black border border-transparent hover:border-slate-300 px-4 py-2 rounded rec-save-btn",onClick:e=>{e.stopPropagation(),i(!1),a&&a()},children:"Dismiss"}),(0,le.jsx)(Yt,{className:"bg-black hover:bg-slate-800 text-white font-semibold px-4 rounded-md shadow rec-save-btn text-xs flex items-center justify-center",style:{minWidth:102,height:28},onClick:e=>{e.stopPropagation(),s&&s()},children:"Apply Fixes"})]})]}):(0,le.jsxs)("div",{className:"mt-6 w-full bg-white border border-slate-200 rounded-lg px-4 py-2 pb-3 cursor-pointer text-xs flex flex-wrap md:flex-nowrap items-center justify-between gap-2",style:{marginBottom:0,paddingBottom:0},onClick:e=>{e.stopPropagation(),n||(i(!0),l&&l())},children:[(0,le.jsxs)("div",{className:"flex items-center gap-2 whitespace-nowrap flex-1 min-w-0",children:[(0,le.jsx)("button",{className:"rec-collapsible-trigger mr-2 p-0.5 flex items-center justify-center",style:{width:24,height:24,background:"none",border:"none",boxShadow:"none"},onClick:e=>{e.stopPropagation(),n||(i(!0),l&&l())},"aria-label":"Expand recommendations",children:(0,le.jsx)(Is.A,{className:"h-4 w-4 text-slate-500"})}),(0,le.jsx)(ux.A,{className:"h-5 w-5 text-black",strokeWidth:2,fill:"none"}),(0,le.jsx)("span",{className:"font-semibold text-black text-xs truncate",children:"RLS Recommendation"})]}),(0,le.jsx)("div",{className:"flex-shrink-0 w-full md:w-auto flex justify-end",children:(0,le.jsx)(Yt,{className:"bg-black hover:bg-slate-800 text-white font-semibold px-4 rounded-md shadow rec-save-btn text-xs flex items-center justify-center mt-1 mb-2 md:mt-0 mr-2 md:mr-4",style:{minWidth:102,height:28},onClick:e=>{e.stopPropagation(),s&&s()},children:"Apply Fixes"})})]}):null}function ov(e){let{entity:t,scanResult:s,rlsRecs:a,onSaveRecommendation:n,onClick:l,clickable:r,forceOpenRLS:i,onRLSOpen:o}=e;const c=t.rls&&Object.keys(t.rls).length>0,d=c&&t.rls.read&&Object.keys(t.rls.read).length>0,m=c&&t.rls.write&&Object.keys(t.rls.write).length>0,u=c&&t.rls.create&&Object.keys(t.rls.create).length>0,x=c&&t.rls.update&&Object.keys(t.rls.update).length>0,h=c&&t.rls.delete&&Object.keys(t.rls.delete).length>0;let p=[];s&&a&&a.length>0&&(p=a.map((e,t)=>(0,K.A)((0,K.A)({},e),{},{_idx:t})).filter(e=>e.entity_name===t.name));return(0,le.jsxs)("div",{className:"w-full h-full rounded-xl border bg-white shadow-sm p-6 transition-all cursor-pointer hover:shadow-md flex flex-col ".concat(r?"hover:bg-muted/30":""),onClick:e=>{e.target.closest(".rec-collapsible-trigger")||e.target.closest(".rec-save-btn")||r&&l&&l()},tabIndex:r?0:void 0,role:r?"button":void 0,children:[(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[(0,le.jsx)("span",{className:"text-base font-semibold",children:t.title||t.name}),(0,le.jsxs)(es,{variant:c?"default":"outline",className:"ml-2 ".concat(c?"bg-blue-100 text-blue-800 hover:bg-blue-200":""),children:[c?(0,le.jsx)(Mt.A,{className:"h-3 w-3 mr-1"}):(0,le.jsx)(hf.A,{className:"h-3 w-3 mr-1"}),c?"Restricted":"Public"]})]}),(0,le.jsx)("div",{className:"space-y-3 text-sm mt-2",children:c?(0,le.jsx)(le.Fragment,{children:(0,le.jsxs)("div",{className:"grid grid-cols-2 gap-4 w-full",children:[(0,le.jsxs)("div",{className:"flex flex-col items-start",children:[(0,le.jsxs)("div",{className:"flex items-center gap-2 mb-1 min-h-[24px]",children:[(0,le.jsx)(sv.A,{className:"h-4 w-4 text-green-600 opacity-60"}),(0,le.jsx)("span",{className:"text-muted-foreground font-medium",children:"Create:"})]}),(0,le.jsx)("div",{className:"flex flex-col gap-0.5 w-full",children:u?Array.isArray(t.rls.create.$or)?t.rls.create.$or.map((e,t)=>(0,le.jsx)("div",{className:"flex items-center py-0.5",children:(0,le.jsx)(rv,{rule:e})},t)):(0,le.jsx)("div",{className:"flex items-center py-0.5",children:(0,le.jsx)(rv,{rule:t.rls.create})}):(0,le.jsx)("span",{className:"text-muted-foreground",children:"No restrictions"})})]}),(0,le.jsxs)("div",{className:"flex flex-col items-start",children:[(0,le.jsxs)("div",{className:"flex items-center gap-2 mb-1 min-h-[24px]",children:[(0,le.jsx)(hf.A,{className:"h-4 w-4 text-blue-600 opacity-60"}),(0,le.jsx)("span",{className:"text-muted-foreground font-medium",children:"Read:"})]}),(0,le.jsx)("div",{className:"flex flex-col gap-0.5 w-full",children:d?Array.isArray(t.rls.read.$or)?t.rls.read.$or.map((e,t)=>(0,le.jsx)("div",{className:"flex items-center py-0.5",children:(0,le.jsx)(rv,{rule:e})},t)):(0,le.jsx)("div",{className:"flex items-center py-0.5",children:(0,le.jsx)(rv,{rule:t.rls.read})}):(0,le.jsx)("span",{className:"text-muted-foreground",children:"No restrictions"})})]}),(0,le.jsxs)("div",{className:"flex flex-col items-start",children:[(0,le.jsxs)("div",{className:"flex items-center gap-2 mb-1 min-h-[24px]",children:[(0,le.jsx)(av.A,{className:"h-4 w-4 text-amber-600 opacity-60"}),(0,le.jsx)("span",{className:"text-muted-foreground font-medium",children:"Update:"})]}),(0,le.jsx)("div",{className:"flex flex-col gap-0.5 w-full",children:x?Array.isArray(t.rls.update.$or)?t.rls.update.$or.map((e,t)=>(0,le.jsx)("div",{className:"flex items-center py-0.5",children:(0,le.jsx)(rv,{rule:e})},t)):(0,le.jsx)("div",{className:"flex items-center py-0.5",children:(0,le.jsx)(rv,{rule:t.rls.update})}):m?Array.isArray(t.rls.write.$or)?t.rls.write.$or.map((e,t)=>(0,le.jsx)("div",{className:"flex items-center py-0.5",children:(0,le.jsx)(rv,{rule:e})},t)):(0,le.jsx)("div",{className:"flex items-center py-0.5",children:(0,le.jsx)(rv,{rule:t.rls.write})}):(0,le.jsx)("span",{className:"text-muted-foreground",children:"No restrictions"})})]}),(0,le.jsxs)("div",{className:"flex flex-col items-start",children:[(0,le.jsxs)("div",{className:"flex items-center gap-2 mb-1 min-h-[24px]",children:[(0,le.jsx)(Ip.A,{className:"h-4 w-4 text-red-600 opacity-60"}),(0,le.jsx)("span",{className:"text-muted-foreground font-medium",children:"Delete:"})]}),(0,le.jsx)("div",{className:"flex flex-col gap-0.5 w-full",children:h?Array.isArray(t.rls.delete.$or)?t.rls.delete.$or.map((e,t)=>(0,le.jsx)("div",{className:"flex items-center py-0.5",children:(0,le.jsx)(rv,{rule:e})},t)):(0,le.jsx)("div",{className:"flex items-center py-0.5",children:(0,le.jsx)(rv,{rule:t.rls.delete})}):m?Array.isArray(t.rls.write.$or)?t.rls.write.$or.map((e,t)=>(0,le.jsx)("div",{className:"flex items-center py-0.5",children:(0,le.jsx)(rv,{rule:e})},t)):(0,le.jsx)("div",{className:"flex items-center py-0.5",children:(0,le.jsx)(rv,{rule:t.rls.write})}):(0,le.jsx)("span",{className:"text-muted-foreground",children:"No restrictions"})})]})]})}):(0,le.jsxs)("div",{className:"flex items-center text-muted-foreground",children:[(0,le.jsx)(_e.A,{className:"h-4 w-4 mr-2 text-red-500"}),(0,le.jsx)("span",{children:"All users have full access"})]})}),p.length>0&&(0,le.jsx)(iv,{rec:p[0],onApply:()=>n(p[0]._idx),forceOpenRLS:i,onOpen:o})]})}const cv=["className"],dv=["className"],mv=["className"],uv=["className"],xv=["className"],hv=["className"],pv=["className"],gv=["className"],fv=Hm.bL,vv=Hm.l9,bv=Hm.ZL,jv=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,cv);return(0,le.jsx)(Hm.hJ,(0,K.A)((0,K.A)({className:Pe("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",s)},a),{},{ref:t}))});jv.displayName=Hm.hJ.displayName;const yv=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,dv);return(0,le.jsxs)(bv,{children:[(0,le.jsx)(jv,{}),(0,le.jsx)(Hm.UC,(0,K.A)({ref:t,className:Pe("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",s)},a))]})});yv.displayName=Hm.UC.displayName;const Nv=e=>{let{className:t}=e,s=(0,Se.A)(e,mv);return(0,le.jsx)("div",(0,K.A)({className:Pe("flex flex-col space-y-2 text-center sm:text-left",t)},s))};Nv.displayName="AlertDialogHeader";const wv=e=>{let{className:t}=e,s=(0,Se.A)(e,uv);return(0,le.jsx)("div",(0,K.A)({className:Pe("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",t)},s))};wv.displayName="AlertDialogFooter";const _v=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,xv);return(0,le.jsx)(Hm.hE,(0,K.A)({ref:t,className:Pe("text-lg font-semibold",s)},a))});_v.displayName=Hm.hE.displayName;const kv=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,hv);return(0,le.jsx)(Hm.VY,(0,K.A)({ref:t,className:Pe("text-sm text-muted-foreground",s)},a))});kv.displayName=Hm.VY.displayName;const Cv=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,pv);return(0,le.jsx)(Hm.rc,(0,K.A)({ref:t,className:Pe(Ht(),s)},a))});Cv.displayName=Hm.rc.displayName;const Av=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,gv);return(0,le.jsx)(Hm.ZD,(0,K.A)({ref:t,className:Pe(Ht({variant:"outline"}),"mt-2 sm:mt-0",s)},a))});function Sv(e){var t;let{rule:s,onChange:a,onDelete:n,canRemove:l,index:r}=e;const{app:i}=Nt(),[o,c]=(0,Y.useState)(()=>s&&0!==Object.keys(s).length?"{{user.email}}"===s.created_by?"creatorOnly":s.user_condition?"userProperty":"fieldComparison":"none"),[d,m]=(0,Y.useState)(""),[u,x]=(0,Y.useState)(""),[h,p]=(0,Y.useState)("role"),[g,f]=(0,Y.useState)(""),v=(null==i||null===(t=i.user_entity)||void 0===t?void 0:t.properties)||{},b=Object.keys(v).filter(e=>!["role","email","full_name"].includes(e));(0,Y.useEffect)(()=>{if(s&&Object.keys(s).length>0)if(s.user_condition){c("userProperty");const e=Object.keys(s.user_condition)[0];p(e),f(s.user_condition[e])}else if("{{user.email}}"===s.created_by)c("creatorOnly");else{const e=Object.keys(s).filter(e=>!e.startsWith("$"));if(e.length){const t=e[0],a=s[t];"string"==typeof a&&a.startsWith("{{user.")&&(c("fieldComparison"),m(t.replace("data.","")),x(a.substring(7,a.length-2)))}}else c("none"),m(""),x(""),p("role"),f("")},[s]);(0,Y.useEffect)(()=>{if("fieldComparison"===o&&d&&u){let e=d;["id","created_by","updated_date","created_date"].includes(d)||(e="data.".concat(d)),a({[e]:"{{user.".concat(u,"}}")})}},[d,u,o,a]),(0,Y.useEffect)(()=>{"userProperty"===o&&h&&g&&a({user_condition:{[h]:g}})},[h,g,o,a]);return(0,le.jsxs)("div",{className:"p-5 border rounded-lg relative mb-5 bg-white shadow-sm",children:[l&&(0,le.jsx)(Yt,{variant:"ghost",size:"icon",className:"absolute top-3 right-3 h-7 w-7 text-destructive hover:bg-red-50",onClick:n,title:"Remove rule",children:(0,le.jsx)(Ip.A,{className:"h-4 w-4"})}),(0,le.jsxs)(As,{value:o,onValueChange:e=>{c(e),"none"===e?a(null):"creatorOnly"===e?a({created_by:"{{user.email}}"}):"fieldComparison"===e?(m(""),x("")):"userProperty"===e&&(p("role"),f(""))},className:"space-y-4",children:[(0,le.jsxs)("div",{className:"flex items-start space-x-3 p-3 rounded-lg border hover:bg-muted/30 transition-colors",children:[(0,le.jsx)(Ss,{value:"none",id:"none-".concat(r),className:"mt-1"}),(0,le.jsxs)("div",{className:"space-y-1",children:[(0,le.jsxs)(Ns,{htmlFor:"none-".concat(r),className:"font-medium flex items-center gap-2",children:[(0,le.jsx)(hf.A,{className:"h-4 w-4 text-green-500"}),"No Restrictions"]}),(0,le.jsx)("p",{className:"text-sm text-muted-foreground",children:"All users can access records"})]})]}),(0,le.jsxs)("div",{className:"flex items-start space-x-3 p-3 rounded-lg border hover:bg-muted/30 transition-colors",children:[(0,le.jsx)(Ss,{value:"creatorOnly",id:"creatorOnly-".concat(r),className:"mt-1"}),(0,le.jsxs)("div",{className:"space-y-1",children:[(0,le.jsxs)(Ns,{htmlFor:"creatorOnly-".concat(r),className:"font-medium flex items-center gap-2",children:[(0,le.jsx)(nv.A,{className:"h-4 w-4 text-indigo-500"}),"Creator Only"]}),(0,le.jsx)("p",{className:"text-sm text-muted-foreground",children:"Users can only access records they created"})]})]}),(0,le.jsxs)("div",{className:"flex items-start space-x-3 p-3 rounded-lg border hover:bg-muted/30 transition-colors",children:[(0,le.jsx)(Ss,{value:"fieldComparison",id:"fieldComparison-".concat(r),className:"mt-1"}),(0,le.jsxs)("div",{className:"space-y-1 w-full",children:[(0,le.jsxs)(Ns,{htmlFor:"fieldComparison-".concat(r),className:"font-medium flex items-center gap-2",children:[(0,le.jsx)(hr.A,{className:"h-4 w-4 text-emerald-500"}),"Entity-User Field Comparison"]}),(0,le.jsx)("p",{className:"text-sm text-muted-foreground mb-2",children:"Compare a field in this entity with a user property"}),"fieldComparison"===o&&(0,le.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4 mt-4 p-3 bg-muted/20 rounded-lg",children:[(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsxs)(Ns,{className:"flex items-center gap-1.5",children:[(0,le.jsx)(Gc.A,{className:"h-3.5 w-3.5 text-primary/70"}),"Entity Field"]}),(0,le.jsx)(fs,{placeholder:"e.g. department",value:d,onChange:e=>m(e.target.value),className:"border-muted-foreground/30 focus:border-primary"}),(0,le.jsx)("p",{className:"text-xs text-muted-foreground",children:"Field in the entity to compare"})]}),(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsxs)(Ns,{className:"flex items-center gap-1.5",children:[(0,le.jsx)(nv.A,{className:"h-3.5 w-3.5 text-primary/70"}),"User Field"]}),(0,le.jsxs)(zs,{value:u,onValueChange:x,children:[(0,le.jsx)(qs,{className:"border-muted-foreground/30 focus:border-primary",children:(0,le.jsx)(Ws,{placeholder:"Select user field"})}),(0,le.jsx)(Ys,{children:(()=>{const e=b.map(e=>({value:"data.".concat(e),label:e.charAt(0).toUpperCase()+e.slice(1).replace(/_/g," ")}));return[{value:"email",label:"Email"},{value:"role",label:"Role"},{value:"id",label:"User ID"},{value:"full_name",label:"Full Name"},...e]})().map(e=>(0,le.jsx)($s,{value:e.value,children:e.label},e.value))})]}),(0,le.jsx)("p",{className:"text-xs text-muted-foreground",children:"Field from the user to compare"})]})]})]})]}),(0,le.jsxs)("div",{className:"flex items-start space-x-3 p-3 rounded-lg border hover:bg-muted/30 transition-colors",children:[(0,le.jsx)(Ss,{value:"userProperty",id:"userProperty-".concat(r),className:"mt-1"}),(0,le.jsxs)("div",{className:"space-y-1 w-full",children:[(0,le.jsxs)(Ns,{htmlFor:"userProperty-".concat(r),className:"font-medium flex items-center gap-2",children:[(0,le.jsx)(lv.A,{className:"h-4 w-4 text-amber-500"}),"User Property Check"]}),(0,le.jsx)("p",{className:"text-sm text-muted-foreground mb-2",children:"Check if a user property matches a specific value"}),"userProperty"===o&&(0,le.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4 mt-4 p-3 bg-muted/20 rounded-lg",children:[(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsxs)(Ns,{className:"flex items-center gap-1.5",children:[(0,le.jsx)(nv.A,{className:"h-3.5 w-3.5 text-primary/70"}),"User Property"]}),(0,le.jsxs)(zs,{value:h,onValueChange:p,children:[(0,le.jsx)(qs,{className:"border-muted-foreground/30 focus:border-primary",children:(0,le.jsx)(Ws,{placeholder:"Select user property"})}),(0,le.jsxs)(Ys,{children:[(0,le.jsx)($s,{value:"role",children:"User Role"}),(0,le.jsx)($s,{value:"email",children:"User Email"}),(0,le.jsx)($s,{value:"full_name",children:"Full Name"}),b.map(e=>(0,le.jsx)($s,{value:"data.".concat(e),children:e.charAt(0).toUpperCase()+e.slice(1).replace(/_/g," ")},"data.".concat(e)))]})]})]}),(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsxs)(Ns,{className:"flex items-center gap-1.5",children:[(0,le.jsx)(Vg.A,{className:"h-3.5 w-3.5 text-primary/70"}),"Required Value"]}),"role"===h?(0,le.jsxs)(zs,{value:g,onValueChange:f,children:[(0,le.jsx)(qs,{className:"border-muted-foreground/30 focus:border-primary",children:(0,le.jsx)(Ws,{placeholder:"Select role"})}),(0,le.jsxs)(Ys,{children:[(0,le.jsx)($s,{value:"admin",children:"Admin"}),(0,le.jsx)($s,{value:"user",children:"User"})]})]}):(0,le.jsx)(fs,{placeholder:"email"===h?"e.g. admin@example.com":"e.g. required value",value:g,onChange:e=>f(e.target.value),className:"border-muted-foreground/30 focus:border-primary"}),(0,le.jsx)("p",{className:"text-xs text-muted-foreground",children:"role"===h?"Select the required user role":"Value that the user property must match"})]})]})]})]})]})]})}function Ev(e){let{entity:t,onSave:s,onBack:a}=e;const[n,l]=(0,Y.useState)(Iv(t.rls)),[r,i]=(0,Y.useState)("create"),[o,c]=(0,Y.useState)(t.rls&&Object.keys(t.rls).length>0?"restricted":"public"),[d,m]=(0,Y.useState)(!1),u=e=>{switch(e){case"create":return"Create Access";case"read":return"Read Access";case"update":return"Update Access";case"delete":return"Delete Access";default:return"Access"}},x=e=>{const t=n[e];return t?t.$or?t.$or:[t]:[{}]},h=(e,t)=>{const s=t.filter(e=>null!=e);let a;a=0===s.length?void 0:1===s.length?s[0]:{$or:s},l(t=>(0,K.A)((0,K.A)({},t),{},{[e]:a}))};return(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(fv,{open:d,onOpenChange:m,children:(0,le.jsxs)(yv,{children:[(0,le.jsxs)(Nv,{children:[(0,le.jsxs)(_v,{className:"flex items-center gap-2",children:[(0,le.jsx)(ux.A,{className:"h-5 w-5 text-amber-500"}),"Remove All Security Rules"]}),(0,le.jsx)(kv,{children:"This will remove all security rules for this entity, allowing all users to access all records. Are you sure you want to continue?"})]}),(0,le.jsxs)(wv,{children:[(0,le.jsx)(Av,{children:"Cancel"}),(0,le.jsx)(Cv,{onClick:()=>{c("public"),l({}),m(!1)},className:"bg-red-600 hover:bg-red-700 text-white",children:"Remove All Rules"})]})]})}),(0,le.jsxs)("div",{className:"flex items-center justify-between mb-6 space-x-4 border-b pb-4",children:[(0,le.jsxs)("div",{className:"flex items-center gap-3",children:[(0,le.jsxs)(Yt,{variant:"outline",size:"sm",onClick:a,className:"hover:bg-muted/50",children:[(0,le.jsx)(Cd.A,{className:"h-4 w-4 mr-2"})," Back"]}),(0,le.jsxs)("div",{children:[(0,le.jsxs)("h2",{className:"text-xl font-semibold flex items-center gap-2",children:[(0,le.jsx)(qc.A,{className:"h-5 w-5 text-primary"}),"Security Rules: ",t.title||t.name]}),"restricted"===o&&(0,le.jsx)("p",{className:"text-sm text-muted-foreground mt-1",children:"Create rules to control who can read and write records. Multiple rules are combined with OR logic."})]})]}),"restricted"===o&&(0,le.jsx)(Yt,{variant:"outline",size:"sm",onClick:()=>m(!0),className:"border-red-300 text-red-600 hover:bg-red-50 hover:text-red-700",children:"Remove All Rules"})]}),(0,le.jsxs)(is,{className:"w-full border-muted-foreground/20 shadow-sm",children:[(0,le.jsx)(ms,{className:"space-y-6 pt-6",children:"public"===o?(0,le.jsx)("div",{className:"p-6 border rounded-lg bg-muted/5 space-y-4",children:(0,le.jsxs)("div",{className:"flex items-start gap-4",children:[(0,le.jsx)("div",{className:"bg-green-50 p-2 rounded-full",children:(0,le.jsx)(bm.A,{className:"h-5 w-5 text-green-600"})}),(0,le.jsxs)("div",{className:"space-y-2 flex-1",children:[(0,le.jsx)("h3",{className:"text-lg font-medium",children:"Public Access"}),(0,le.jsx)("p",{className:"text-muted-foreground",children:"Currently all users can access all records in this entity. There are no access restrictions."})]}),(0,le.jsxs)(Yt,{onClick:()=>{c("restricted")},className:"gap-2 whitespace-nowrap",children:[(0,le.jsx)(Mt.A,{className:"h-4 w-4"}),"Create Access Rules"]})]})}):(0,le.jsx)(le.Fragment,{children:(0,le.jsxs)(kr,{value:r,onValueChange:i,className:"w-full",children:[(0,le.jsxs)(Cr,{className:"grid grid-cols-4 w-full mb-4",children:[(0,le.jsxs)(Ar,{value:"create",className:"flex items-center gap-2",children:[(0,le.jsx)(sv.A,{className:"h-4 w-4"})," Create"]}),(0,le.jsxs)(Ar,{value:"read",className:"flex items-center gap-2",children:[(0,le.jsx)(hf.A,{className:"h-4 w-4"})," Read"]}),(0,le.jsxs)(Ar,{value:"update",className:"flex items-center gap-2",children:[(0,le.jsx)(av.A,{className:"h-4 w-4"})," Update"]}),(0,le.jsxs)(Ar,{value:"delete",className:"flex items-center gap-2",children:[(0,le.jsx)(Ip.A,{className:"h-4 w-4"})," Delete"]})]}),(0,le.jsxs)(Sr,{value:r,className:"space-y-4",children:[(0,le.jsxs)("div",{className:"flex items-center justify-between mb-4",children:[(0,le.jsxs)(Ns,{className:"text-base font-medium flex items-center gap-2",children:[(e=>{switch(e){case"create":return(0,le.jsx)(sv.A,{className:"h-4 w-4 text-green-500"});case"read":return(0,le.jsx)(hf.A,{className:"h-4 w-4 text-blue-500"});case"update":return(0,le.jsx)(av.A,{className:"h-4 w-4 text-amber-500"});case"delete":return(0,le.jsx)(Ip.A,{className:"h-4 w-4 text-red-500"});default:return(0,le.jsx)(lv.A,{className:"h-4 w-4"})}})(r),u(r)," Rules"]}),(0,le.jsxs)(Yt,{variant:"outline",size:"sm",onClick:()=>{const e=x(r);h(r,[...e,{}])},className:"flex items-center gap-1.5 border-primary/30 hover:bg-primary/5",children:[(0,le.jsx)(kt.A,{className:"h-3.5 w-3.5"})," Add Rule"]})]}),x(r).map((e,t)=>(0,le.jsx)(Sv,{rule:e,onChange:e=>((e,t,s)=>{const a=[...x(e)];a[t]=s,h(e,a)})(r,t,e),onDelete:()=>((e,t)=>{const s=x(e);if(s.length>1){const a=s.filter((e,s)=>s!==t);h(e,a)}})(r,t),canRemove:x(r).length>1,index:t},"".concat(r,"-").concat(t))),(0,le.jsxs)("div",{className:"space-y-2 bg-muted/10 p-4 rounded-lg border",children:[(0,le.jsxs)("div",{className:"flex justify-between items-center",children:[(0,le.jsxs)(Ns,{className:"font-medium flex items-center gap-2",children:[(0,le.jsx)(hr.A,{className:"h-4 w-4 text-primary/70"}),"Generated ",u(r)," Rules (JSON)"]}),(0,le.jsx)(es,{variant:"outline",className:"bg-primary/5 border-primary/20",children:x(r).filter(e=>null!==e).length})]}),(0,le.jsx)(um,{rows:4,value:n[r]?JSON.stringify(n[r],null,2):"",readOnly:!0,className:"font-mono text-sm bg-muted/30 border-muted-foreground/20"})]})]})]})})}),(0,le.jsx)(us,{className:"flex justify-end pt-4 border-t bg-muted/5",children:(0,le.jsxs)(Yt,{onClick:()=>{if("public"===o){const e=(0,K.A)((0,K.A)({},t),{},{rls:void 0});return void s(e)}const e=(0,K.A)({},n);e.update&&e.delete&&JSON.stringify(e.update)===JSON.stringify(e.delete)?e.write=e.update:delete e.write;const a=(0,K.A)((0,K.A)({},t),{},{rls:e});s(a)},size:"lg",className:"gap-2",children:[(0,le.jsx)(qc.A,{className:"h-4 w-4"}),"Save Security Rules"]})})]})]})}Av.displayName=Hm.ZD.displayName;const Iv=e=>{if(!e)return{};const t=(0,K.A)({},e);return t.write&&(t.update||(t.update=t.write),t.delete||(t.delete=t.write)),t};class Tv extends Q.H{getBaseURL(){return"/apps"}runSecurityScan(e){return this.axios.post("/".concat(e,"/security/generate-suggestions")).then(e=>e.result||e)}}const Pv=new Tv;function Lv(e){let{title:t,count:s,subtitle:a,noIssuesSubtitle:n,rightElement:l}=e;const r=s>0,i=r?(0,le.jsx)(_e.A,{className:"h-4 w-4 mr-2 text-red-600",strokeWidth:2}):(0,le.jsx)(Vg.A,{className:"h-4 w-4 text-green-500 mr-2",strokeWidth:2});return(0,le.jsxs)("div",{className:"flex flex-col items-start w-full",children:[(0,le.jsxs)("div",{className:"flex items-center w-full",children:[(0,le.jsxs)("span",{className:"flex items-center font-semibold text-sm text-black flex-1",children:[i,t]}),l&&(0,le.jsx)("span",{children:l})]}),(0,le.jsx)("span",{className:"text-sm leading-5 font-normal mt-1 text-black ml-6",children:r?a:n})]})}function Ov(e){let{title:t,issues:s=[],subtitle:a,noIssuesSubtitle:n}=e;const[l,r]=(0,Y.useState)(!1),i=s.length>0,o=i?l?(0,le.jsx)(Ts.A,{className:"h-5 w-5 text-slate-500"}):(0,le.jsx)(Is.A,{className:"h-5 w-5 text-slate-500"}):null;return(0,le.jsxs)("div",{className:"w-full rounded-lg border border-[#E4E4E7] bg-white shadow-sm",children:[(0,le.jsx)("button",{className:"flex items-center justify-between w-full px-4 py-5 focus:outline-none rounded-lg",onClick:()=>i&&r(e=>!e),"aria-expanded":l,style:{border:"none",background:"transparent",boxShadow:"none"},children:(0,le.jsx)(Lv,{title:t,count:s.length,subtitle:a,noIssuesSubtitle:n,rightElement:o})}),l&&i&&(0,le.jsx)("div",{className:"flex flex-col gap-4 mb-[12px] px-4 pb-4",children:s.map((e,t)=>(0,le.jsxs)("div",{className:"flex flex-row items-start w-full rounded-lg border border-[#E4E4E7] bg-white py-3 px-4 gap-x-3 shadow-sm",children:[(0,le.jsx)("div",{className:"flex items-start",children:(0,le.jsx)(_e.A,{className:"h-4 w-4 text-red-700 mt-0.5",strokeWidth:2})}),(0,le.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,le.jsx)("div",{className:"text-red-600 text-sm font-medium leading-5 flex items-start gap-2",children:e.description}),(0,le.jsxs)("div",{className:"text-[#71717A] text-sm font-normal leading-5",children:["File: ",e.filePath]})]})]},t))})]})}function Rv(){const{app:e,refreshApp:t}=Nt(),s=(0,Z.zy)(),a=(0,Z.Zp)(),[n,l]=(0,Y.useState)(null),[r,i]=(0,Y.useState)("list"),[o,c]=(0,Y.useState)(null),[d,m]=(0,Y.useState)(!1),{toast:u}=nn(),[x,h]=(0,Y.useState)(null),p=e.entities||{},g=Object.keys(p);(0,Y.useEffect)(()=>{t()},[]),(0,Y.useEffect)(()=>{o&&o.rls_recommendations&&h([...o.rls_recommendations])},[o]);const f=(0,Y.useCallback)(async()=>{tt("Security Scan Started",{app_id:e.id,app_name:e.name}),m(!0),c(null);try{const t=await Pv.runSecurityScan(e.id);c(t.result||t),u({title:"Security scan complete",description:"Review the findings below."})}catch(t){u({title:"Security scan failed",description:t.message,variant:"destructive"})}finally{m(!1)}},[e.id,e.name,u]);(0,Y.useEffect)(()=>{const e=new URLSearchParams(s.search);if("1"===e.get("autoStartScan")&&!d&&!o){f(),e.delete("autoStartScan");const t=e.toString(),n="".concat(s.pathname).concat(t?"?".concat(t):"");a(n,{replace:!0})}},[s.search,f,d,o,a,s.pathname]);const v=()=>{const e=document.getElementById("data-entities-section");e&&e.scrollIntoView({behavior:"smooth",block:"start"})};return"list"===r?(0,le.jsxs)(up,{title:"App Security",subtitle:"Configure row-level security policies to control who can access your app's data",children:[(0,le.jsxs)("div",{className:"flex items-center justify-between bg-white border border-slate-200 rounded-lg px-6 py-3 mb-6 w-full shadow-sm",children:[(0,le.jsxs)("div",{className:"flex flex-col",children:[(0,le.jsx)("span",{className:"font-semibold text-base text-black",children:"Scan issues"}),(0,le.jsx)("span",{className:"text-sm text-slate-500",children:"Scan typically takes few minutes to complete"})]}),(0,le.jsx)(Yt,{onClick:f,disabled:d,className:"bg-black hover:bg-slate-800 text-white font-semibold rounded-lg px-4 text-sm flex items-center justify-center",style:{width:175,height:34,minWidth:0},children:d?(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(Ne.A,{className:"animate-spin h-4 w-4"}),(0,le.jsx)("span",{className:"ml-2",children:"Scanning"})]}):(0,le.jsx)("span",{children:"Start Security Check"})})]}),o?(0,le.jsxs)("div",{className:"bg-white border border-slate-200 rounded-lg p-6 mb-8 shadow-sm animate-in fade-in",children:[(0,le.jsx)("div",{className:"font-bold text-2xl text-black mb-6",children:"Scan Results"}),(0,le.jsxs)("div",{className:"space-y-3",children:[(0,le.jsx)("div",{className:"bg-white border border-slate-200 rounded-lg p-6 shadow-sm",children:(0,le.jsx)(Lv,{title:"RLS Recommendations",count:(null==x?void 0:x.length)||0,subtitle:x&&x.length>0?(0,le.jsxs)(le.Fragment,{children:["".concat(x.length," RLS recommendation").concat(x.length>1?"s":""," found, "),(0,le.jsx)("button",{onClick:v,className:"inline text-black font-medium underline ml-1 hover:text-slate-800 transition p-0 bg-transparent border-0 outline-none",style:{fontSize:"inherit",lineHeight:"inherit"},type:"button",children:"View recommendations"})]}):null,noIssuesSubtitle:"No RLS recommendations found",rightElement:null})}),(0,le.jsx)(Ov,{title:"Secrets",subtitle:"".concat(o.hardcoded_secrets.length," Exposed secrets found"),noIssuesSubtitle:"No exposed secrets found",issues:(o.hardcoded_secrets||[]).map(e=>({description:e.description,filePath:e.file_path}))}),(0,le.jsx)(Ov,{title:"Backend Functions",subtitle:"".concat(o.backend_functions.length," Unauthenticated backend functions found"),noIssuesSubtitle:"No unauthenticated backend functions found",issues:(o.backend_functions||[]).map(e=>({description:e.description,filePath:e.file_path}))})]})]}):null,(0,le.jsxs)("div",{className:"flex items-center justify-between",children:[(0,le.jsxs)("h2",{id:"data-entities-section",className:"text-xl font-medium flex items-center gap-2",children:[(0,le.jsx)(Gc.A,{className:"h-5 w-5 text-primary/70"}),"Data Entities"]}),(0,le.jsxs)(es,{variant:"outline",className:"bg-primary/5 border-primary/20 px-3 py-1",children:[(0,le.jsx)(Xl.A,{className:"h-3.5 w-3.5 mr-1.5"}),g.length," entities"]})]}),(0,le.jsx)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6 w-full mx-auto items-stretch",children:g.map(t=>(0,le.jsx)("div",{className:"h-full flex flex-col",children:(0,le.jsx)(ov,{entity:p[t],scanResult:o,rlsRecs:x,app:e,onSaveRecommendation:s=>(async(t,s)=>{const a=x.filter((e,a)=>e.entity_name===t&&a===s);if(0===a.length)return;const n=a[0];try{const t={create:n.create_rule?JSON.parse(n.create_rule):void 0,read:n.read_rule?JSON.parse(n.read_rule):void 0,update:n.update_rule?JSON.parse(n.update_rule):void 0,delete:n.delete_rule?JSON.parse(n.delete_rule):void 0};await Ue.write(e.id,"entities/".concat(n.entity_name),JSON.stringify((0,K.A)((0,K.A)({},p[n.entity_name]),{},{rls:t}),null,2)),h(e=>e.filter((e,t)=>t!==s)),u({title:"Rule saved for ".concat(n.entity_name),description:"The recommended rule has been saved.",variant:"success"})}catch(l){u({title:"Failed to save rule",description:l.message,variant:"destructive"})}})(t,s),onClick:()=>(e=>{l(e),i("edit")})(t),clickable:!0},t)}))})]}):(0,le.jsx)("div",{className:"max-w-full py-6 p-4",children:(0,le.jsx)(Ev,{entity:p[n],onSave:t=>{Ue.write(e.id,"entities/".concat(t.name),JSON.stringify(t,null,2)),i("list")},onBack:()=>{i("list"),l(null)}})})}var Mv=s(81872);const Dv=e=>{let{secretName:t,appId:s,onUpdate:a}=e;const{toast:n}=ui(),[l,r]=(0,Y.useState)(!1),[i,o]=(0,Y.useState)(!1),[c,d]=(0,Y.useState)(""),[m,u]=(0,Y.useState)(!1),[x,h]=(0,Y.useState)(!1),{updateSecrets:p}=Nt();return(0,le.jsx)(is,{children:(0,le.jsx)(ms,{className:"p-4",children:(0,le.jsxs)("div",{className:"flex items-center justify-between",children:[(0,le.jsxs)("div",{className:"flex items-center gap-3",children:[(0,le.jsx)(pr.A,{className:"h-5 w-5 text-green-500"}),(0,le.jsxs)("div",{children:[(0,le.jsx)("p",{className:"font-medium",children:t}),i?(0,le.jsx)("div",{className:"mt-2 space-y-2",children:(0,le.jsxs)("div",{className:"flex gap-2",children:[(0,le.jsxs)("div",{className:"relative",children:[(0,le.jsx)(fs,{type:x?"text":"password",placeholder:"New secret value",value:c,onChange:e=>d(e.target.value),className:"h-8 w-48 pr-10"}),(0,le.jsx)(Yt,{type:"button",variant:"ghost",size:"sm",className:"absolute right-0 top-0 h-full px-2 py-1 hover:bg-transparent",onClick:()=>{h(e=>!e)},children:x?(0,le.jsx)(Og.A,{className:"h-3 w-3"}):(0,le.jsx)(hf.A,{className:"h-3 w-3"})})]}),(0,le.jsx)(Yt,{size:"sm",onClick:async()=>{if(c){u(!0);try{await p({[t]:c}),n({title:"Secret updated",duration:3e3}),a(),o(!1),d(""),h(!1)}catch(l){var e,s;n({variant:"destructive",title:"Error updating secret",description:(null===(e=l.response)||void 0===e||null===(s=e.data)||void 0===s?void 0:s.detail)||"Something went wrong",duration:3e3})}u(!1)}},disabled:m||!c,className:"h-8",children:m?(0,le.jsx)(nx.A,{className:"h-4 w-4 animate-spin"}):"Save"}),(0,le.jsx)(Yt,{size:"sm",variant:"outline",onClick:()=>{o(!1),d(""),h(!1)},className:"h-8",children:"Cancel"})]})}):(0,le.jsx)("p",{className:"text-sm text-gray-500",children:"\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022"})]})]}),(0,le.jsxs)("div",{className:"flex gap-2",children:[!i&&(0,le.jsx)(Yt,{variant:"ghost",size:"sm",onClick:()=>{o(!0)},className:"text-blue-500 hover:text-blue-600 hover:bg-blue-50",children:(0,le.jsx)(Mv.A,{className:"h-4 w-4"})}),(0,le.jsx)(Yt,{variant:"ghost",size:"sm",onClick:async()=>{r(!0);try{await qe.deleteSecret(s,t),n({title:"Secret deleted",duration:3e3}),a()}catch(i){var e,l;n({variant:"destructive",title:"Error deleting secret",description:(null===(e=i.response)||void 0===e||null===(l=e.data)||void 0===l?void 0:l.detail)||"Something went wrong",duration:3e3})}r(!1)},className:"text-red-500 hover:text-red-600 hover:bg-red-50",disabled:l,children:(0,le.jsx)(Ip.A,{className:"h-4 w-4 ".concat(l?"animate-spin":"")})})]})]})})})},Fv=e=>{let{onAdd:t,loading:s}=e;const[a,n]=(0,Y.useState)(""),[l,r]=(0,Y.useState)(""),[i,o]=(0,Y.useState)(!1),[c,d]=(0,Y.useState)(!1),m=a.includes(" "),u=m;return(0,le.jsxs)(Pa,{open:i,onOpenChange:o,children:[(0,le.jsx)(La,{asChild:!0,children:(0,le.jsxs)(Yt,{children:[(0,le.jsx)(kt.A,{className:"h-4 w-4 mr-2"}),"Add Secret"]})}),(0,le.jsxs)(Da,{children:[(0,le.jsxs)(Fa,{children:[(0,le.jsx)(za,{children:"Add New Secret"}),(0,le.jsx)(Ua,{children:"Enter your secret name and value below. Secrets are encrypted and securely stored."})]}),(0,le.jsxs)("div",{className:"space-y-4 pt-4",children:[(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsx)("label",{className:"text-sm font-medium",children:"Secret Name"}),(0,le.jsx)(fs,{placeholder:"Enter secret name (e.g. API_KEY)",value:a,onChange:e=>n(e.target.value),className:m?"border-red-500":""}),m&&(0,le.jsx)("p",{className:"text-sm text-red-500",children:"Secret name cannot contain spaces. Use underscores instead (e.g. API_KEY)."})]}),(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsx)("label",{className:"text-sm font-medium",children:"Secret Value"}),(0,le.jsxs)("div",{className:"relative",children:[(0,le.jsx)(fs,{type:c?"text":"password",placeholder:"Enter secret value",value:l,onChange:e=>r(e.target.value),className:"pr-10"}),(0,le.jsx)(Yt,{type:"button",variant:"ghost",size:"sm",className:"absolute right-0 top-0 h-full px-3 py-2 hover:bg-transparent",onClick:()=>{d(e=>!e)},children:c?(0,le.jsx)(Og.A,{className:"h-4 w-4"}):(0,le.jsx)(hf.A,{className:"h-4 w-4"})})]})]}),(0,le.jsx)("div",{className:"flex justify-end",children:(0,le.jsx)(Yt,{onClick:async()=>{u||(await t(a,l),n(""),r(""),d(!1),o(!1))},disabled:s||!a||!l||u,children:s?(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(nx.A,{className:"h-4 w-4 mr-2 animate-spin"}),"Adding..."]}):"Add Secret"})})]})]})]})},Bv=e=>{let{app:t}=e;return(0,le.jsx)(is,{children:(0,le.jsx)(ms,{className:"p-4",children:(0,le.jsxs)("div",{className:"flex items-start gap-3",children:[(0,le.jsx)(lv.A,{className:"h-5 w-5 text-blue-500 shrink-0 mt-0.5"}),(0,le.jsxs)("div",{className:"space-y-2 text-sm",children:[(0,le.jsx)("p",{className:"font-medium",children:(0,le.jsx)("b",{children:"About Secrets Management"})}),(0,le.jsx)("p",{className:"text-gray-600",children:"Secrets are environment variables that contain sensitive information like API keys, tokens, and passwords. They are encrypted at rest and securely injected into your application at runtime."}),(0,le.jsxs)("ul",{className:"list-disc list-inside space-y-1 text-gray-600",children:[(0,le.jsx)("li",{children:"Secrets are used by your backend functions to access external services"}),(0,le.jsx)("li",{children:"All secrets are encrypted and stored securely"}),(0,le.jsx)("li",{children:"You can add, update, or delete secrets as needed for your application"})]}),(0,le.jsxs)("p",{className:"text-xs text-gray-500",children:["Need help? Create a ticket at ",(0,le.jsx)("button",{type:"button",onClick:()=>{const e=null!=t&&t.id?"/support?appId=".concat(t.id):"/support";window.open(e,"_blank")},className:"underline text-primary hover:text-orange-500 transition-colors",children:"support system"})]})]})]})})})};function zv(){const{app:e,updateSecrets:t,existingSecretNames:s}=Nt(),a=null==e?void 0:e.id,[n,l]=(0,Y.useState)({}),[r,i]=(0,Y.useState)(!1),{toast:o}=ui(),c=((0,Z.Zp)(),async()=>{try{const e=await qe.getSecrets(a);l(e)}catch(s){var e,t;o({variant:"destructive",title:"Error fetching secrets",description:(null===(e=s.response)||void 0===e||null===(t=e.data)||void 0===t?void 0:t.detail)||"Something went wrong",duration:3e3})}});(0,Y.useEffect)(()=>{c()},[a]);return(0,le.jsx)("div",{className:"space-y-6 p-6",children:(0,le.jsxs)("div",{children:[(0,le.jsxs)("div",{className:"flex items-center justify-between mb-6",children:[(0,le.jsx)("h2",{className:"text-2xl font-bold",children:"Application Secrets"}),(0,le.jsx)(Fv,{onAdd:async(e,s)=>{if(e&&s){i(!0);try{await t({[e]:s}),await c(),o({title:"Secret added successfully",duration:3e3})}catch(l){var a,n;o({variant:"destructive",title:"Error creating secret",description:(null===(a=l.response)||void 0===a||null===(n=a.data)||void 0===n?void 0:n.detail)||"Something went wrong",duration:3e3})}i(!1)}},loading:r})]}),(0,le.jsxs)("div",{className:"grid gap-6",children:[Object.keys(n).length>0?(0,le.jsxs)("div",{className:"space-y-4",children:[(0,le.jsxs)("h3",{className:"text-lg font-semibold text-green-600 flex items-center",children:[(0,le.jsx)(xi.A,{className:"h-5 w-5 mr-2"}),"Configured Secrets"]}),Object.keys(n).map(e=>(0,le.jsx)(Dv,{secretName:e,appId:a,onUpdate:c},e))]}):(0,le.jsx)("div",{className:"text-center py-8 text-gray-500",children:(0,le.jsx)("p",{children:"No secrets configured yet. Add your first secret to get started."})}),(0,le.jsx)(Bv,{app:e})]})]})})}var Uv=s(69783);let Wv=null;const qv=function(e,t){class s extends Uv.A{getMountPath(){return"/ws-user-apps/socket.io/"}getSocketQuery(){let s=super.getSocketQuery();return t&&(s.token=t),s.app_id=e,s}}return Wv||(Wv=new s),Wv};var Vv=s(76976);let Hv=null;function Yv(e,t,s){class a extends Q.y{constructor(){super(),this.socketManager=qv(e,t),this.axios.interceptors.response.use(e=>e,e=>{var t,a;return s((null===(t=e.response)||void 0===t||null===(a=t.data)||void 0===a?void 0:a.message)||e.message),Promise.reject(e)})}getClient(){return t?(0,ae.Ay)(this.getBaseURL(),{Authorization:"Bearer ".concat(t)}):super.getClient()}getBaseURL(){return"https://base44.app/api"+"/apps/".concat(e,"/agents")}getConversations(){return this.axios.get("/conversations")}getConversation(e){return this.axios.get("/conversations/".concat(e))}listConversations(e){return this.axios.get("/conversations",{params:e})}createConversation(e){return this.axios.post("/conversations",e)}addMessage(e,t){let s=null;return Hv&&Hv.id===e.id?s=Hv.messages:(Hv=e,s=e.messages),e.messages=[...s,t],this.socketManager.onUpdateModel({room:"/agent-conversations/".concat(e.id),data:JSON.stringify(e)}),this.axios.post("/conversations/".concat(e.id,"/messages"),t)}getWhatsAppConnectURL(s){const a="".concat("https://base44.app","/api/apps/").concat(e,"/agents/").concat(encodeURIComponent(s),"/whatsapp"),n=null!=t?t:Vv.A.getToken();return n?"".concat(a,"?token=").concat(n):a}subscribeToConversation(e,t){return this.socketManager.addListener("/agent-conversations/".concat(e),e=>{Hv&&Hv.id===e.id&&(Hv=e),t(e)})}}return new a}var Gv=s(21449);function $v(e){var t,s,a,n,l,r;let{agent:i,color:o,onEdit:c,onStartChat:d,isSelected:m=!1,agentsSDK:u,onSaveWhatsAppGreeting:x,onToggleWhatsApp:h}=e;const p=(null===(t=i.tool_configs)||void 0===t||null===(s=t.filter(e=>e.entity_name))||void 0===s?void 0:s.length)||0,g=(null===(a=i.tool_configs)||void 0===a||null===(n=a.filter(e=>e.function_name))||void 0===n?void 0:n.length)||0;return(0,le.jsx)("div",{className:Pe("group relative bg-white transition-all p-4 font-base44","rounded-[12px] border border-gray-100"),children:(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsxs)("div",{className:"flex items-start justify-between",children:[(0,le.jsxs)("div",{className:"flex items-start gap-3",children:[(0,le.jsx)("div",{className:Pe("h-10 w-10 flex items-center justify-center flex-shrink-0",(null==o?void 0:o.light)||"bg-slate-100"),children:(0,le.jsx)(Cm.A,{className:Pe("h-5 w-5",(null==o?void 0:o.text)||"text-slate-500")})}),(0,le.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,le.jsx)("h3",{className:"font-semibold text-slate-900 text-base font-base44",children:i.name}),p>0&&(0,le.jsxs)("div",{className:"flex items-center gap-2 flex-wrap mt-1",children:[(0,le.jsxs)("div",{className:"flex items-center gap-1.5 text-xs text-slate-600 font-base44",children:[(0,le.jsx)(Gc.A,{className:"h-3 w-3"}),(0,le.jsx)("span",{children:"Entities:"})]}),(0,le.jsxs)("div",{className:"flex flex-wrap gap-1",children:[null===(l=i.tool_configs)||void 0===l?void 0:l.filter(e=>e.entity_name).slice(0,3).map((e,t)=>(0,le.jsx)(es,{variant:"secondary",className:"text-xs px-2 py-0 bg-slate-100 text-slate-600 border-0 font-base44",children:e.entity_name},t)),(null===(r=i.tool_configs)||void 0===r?void 0:r.filter(e=>e.entity_name).length)>3&&(0,le.jsxs)(es,{variant:"secondary",className:"text-xs px-2 py-0 bg-slate-100 text-slate-600 border-0 font-base44",children:["+",i.tool_configs.filter(e=>e.entity_name).length-3," more"]})]})]})]})]}),(0,le.jsxs)("div",{className:"flex gap-2 ml-3",children:[(0,le.jsx)(Yt,{size:"sm",variant:"outline",onClick:e=>{e.stopPropagation(),c(i)},className:"h-8 text-xs font-base44 rounded-[12px] hidden sm:flex",children:"Edit Agent"}),(0,le.jsx)(Yt,{size:"sm",variant:"outline",onClick:e=>{e.stopPropagation(),c(i)},className:"h-8 w-8 font-base44 rounded-[12px] sm:hidden flex items-center justify-center",children:"Edit"}),(0,le.jsx)(Yt,{size:"sm",onClick:e=>{e.stopPropagation(),d(i)},className:"h-8 text-xs bg-slate-800 hover:bg-slate-900 text-white font-base44 rounded-[8px] hidden sm:flex",children:"Start Chat"}),(0,le.jsx)(Yt,{size:"sm",onClick:e=>{e.stopPropagation(),d(i)},className:"h-8 w-8 bg-slate-800 hover:bg-slate-900 text-white font-base44 rounded-[8px] sm:hidden flex items-center justify-center",children:"Chat"})]})]}),g>0&&(0,le.jsxs)("div",{className:"pl-[52px] sm:pl-[52px] pl-0 flex items-center gap-1.5 text-xs text-slate-600 font-base44",children:[(0,le.jsx)(Kl.A,{className:"h-3 w-3"}),(0,le.jsxs)("span",{children:[g," ",1===g?"function":"functions"]})]}),(0,le.jsx)("div",{className:"pl-[52px] sm:pl-[52px] pl-0",children:(0,le.jsx)("p",{className:"text-sm text-slate-600 line-clamp-2 font-base44",children:i.description||"No description provided"})})]})})}function Jv(e){try{const t=new Date(e);if(isNaN(t.getTime()))return"Recently";const s=new Date,a=Math.abs(s-t),n=Math.ceil(a/864e5);return 0===n?"Today":1===n?"Yesterday":n<7?"".concat(n," days ago"):n<30?"".concat(Math.floor(n/7)," weeks ago"):n<365?"".concat(Math.floor(n/30)," months ago"):"".concat(Math.floor(n/365)," years ago")}catch(t){return"Recently"}}function Zv(e){var t,s,a,n,l;let{conversation:r,agentColor:i,onSelect:o,isSelected:c}=e;const d=null===(t=r.messages)||void 0===t?void 0:t.slice(-1)[0],m=(null===(s=r.messages)||void 0===s?void 0:s.length)||0;return(0,le.jsx)("div",{className:Pe("group font-base44 relative bg-white rounded-[12px] border transition-all cursor-pointer hover:shadow-sm p-3",c?"border-slate-400 shadow-sm":"border-gray-100 hover:border-slate-300"),onClick:()=>o(r),children:(0,le.jsxs)("div",{className:"flex items-start gap-3",children:[(0,le.jsx)("div",{className:Pe("h-8 w-8 rounded-lg flex items-center justify-center flex-shrink-0",(null==i?void 0:i.light)||"bg-slate-100"),children:(0,le.jsx)(Cm.A,{className:Pe("h-4 w-4",(null==i?void 0:i.text)||"text-slate-500")})}),(0,le.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,le.jsxs)("div",{className:"flex items-center gap-2 mb-1",children:[(0,le.jsx)("span",{className:"text-sm font-medium text-slate-800",children:r.agent_name}),"whatsapp"===(null===(a=r.metadata)||void 0===a?void 0:a.channel)&&(0,le.jsxs)("div",{className:"flex items-center gap-1 px-1.5 py-0.5 bg-green-50 rounded",children:[(0,le.jsx)(Ir.A,{className:"h-3 w-3 text-green-600"}),(0,le.jsx)("span",{className:"text-xs text-green-700 font-medium",children:"WhatsApp"})]}),(0,le.jsx)(es,{variant:"outline",className:"text-xs px-1.5 py-0 border-slate-300",children:m})]}),d&&(0,le.jsxs)("p",{className:"text-xs text-slate-500 line-clamp-1",children:[null===(n=d.content)||void 0===n?void 0:n.substring(0,150),"..."]}),(0,le.jsxs)("div",{className:"flex items-center gap-2 text-xs text-slate-400 mt-1",children:[(0,le.jsx)("span",{children:Jv(r.created_at)}),(null===(l=r.metadata)||void 0===l?void 0:l.phone_number)&&(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)("span",{children:"\u2022"}),(0,le.jsx)("span",{children:r.metadata.phone_number})]})]})]}),(0,le.jsx)(rn.A,{className:"h-4 w-4 text-slate-400 opacity-0 group-hover:opacity-100 transition-opacity"})]})})}const Kv=["inline","className","children"],Qv=["children"];function Xv(e){var t;let{message:s}=e;const a="user"===s.role;return(0,le.jsxs)("div",{className:Pe("flex gap-3",a?"justify-end":"justify-start"),children:[!a&&(0,le.jsx)("div",{className:"h-7 w-7 rounded-lg bg-slate-100 flex items-center justify-center mt-0.5",children:(0,le.jsx)("div",{className:"h-1.5 w-1.5 rounded-full bg-slate-400"})}),(0,le.jsxs)("div",{className:Pe("max-w-[85%]",a&&"flex flex-col items-end"),children:[s.content&&(0,le.jsx)("div",{className:Pe("rounded-2xl px-4 py-2.5",a?"bg-slate-800 text-white":"bg-white border border-slate-200"),children:a?(0,le.jsx)("p",{className:"text-sm leading-relaxed",children:s.content}):(0,le.jsx)(mr.oz,{className:"text-sm prose prose-sm prose-slate max-w-none [&>*:first-child]:mt-0 [&>*:last-child]:mb-0",components:{code:e=>{let{inline:t,className:s,children:a}=e,n=(0,Se.A)(e,Kv);const l=/language-(\w+)/.exec(s||"");return!t&&l?(0,le.jsxs)("div",{className:"relative group/code",children:[(0,le.jsx)("pre",{className:"bg-slate-900 text-slate-100 rounded-lg p-3 overflow-x-auto my-2",children:(0,le.jsx)("code",(0,K.A)((0,K.A)({className:s},n),{},{children:a}))}),(0,le.jsx)(Yt,{size:"icon",variant:"ghost",className:"absolute top-2 right-2 h-6 w-6 opacity-0 group-hover/code:opacity-100 bg-slate-800 hover:bg-slate-700",onClick:()=>{navigator.clipboard.writeText(String(a).replace(/\n$/,"")),Ri.toast.success("Code copied")},children:(0,le.jsx)(or.A,{className:"h-3 w-3 text-slate-400"})})]}):(0,le.jsx)("code",{className:"px-1 py-0.5 rounded bg-slate-100 text-slate-700 text-xs",children:a})},a:e=>{let{children:t}=e,s=(0,Se.A)(e,Qv);return(0,le.jsx)("a",(0,K.A)((0,K.A)({},s),{},{target:"_blank",rel:"noopener noreferrer",children:t}))},p:e=>{let{children:t}=e;return(0,le.jsx)("p",{className:"my-1 leading-relaxed",children:t})},ul:e=>{let{children:t}=e;return(0,le.jsx)("ul",{className:"my-1 ml-4 list-disc",children:t})},ol:e=>{let{children:t}=e;return(0,le.jsx)("ol",{className:"my-1 ml-4 list-decimal",children:t})},li:e=>{let{children:t}=e;return(0,le.jsx)("li",{className:"my-0.5",children:t})},h1:e=>{let{children:t}=e;return(0,le.jsx)("h1",{className:"text-lg font-semibold my-2",children:t})},h2:e=>{let{children:t}=e;return(0,le.jsx)("h2",{className:"text-base font-semibold my-2",children:t})},h3:e=>{let{children:t}=e;return(0,le.jsx)("h3",{className:"text-sm font-semibold my-2",children:t})},blockquote:e=>{let{children:t}=e;return(0,le.jsx)("blockquote",{className:"border-l-2 border-slate-300 pl-3 my-2 text-slate-600",children:t})}},children:s.content})}),(null===(t=s.tool_calls)||void 0===t?void 0:t.length)>0&&(0,le.jsx)("div",{className:"space-y-1",children:s.tool_calls.map((e,t)=>(0,le.jsx)(wo,{toolCall:e},t))})]})]})}function eb(e){let{conversation:t,agentColor:s,agentsSDK:a,onBack:n}=e;const[l,r]=(0,Y.useState)(""),[i,o]=(0,Y.useState)(!1),c=(0,Y.useRef)(null),d=(0,Y.useRef)(null),m=t.messages||[];(0,Y.useEffect)(()=>{var e;null===(e=d.current)||void 0===e||e.scrollIntoView({behavior:"smooth"})},[m]);const u=async()=>{if(!l.trim()||i)return;const e={id:Date.now().toString(),role:"user",content:l.trim()};r(""),o(!0);try{await a.addMessage(t,e)}catch(s){Ri.toast.error("Failed to send message")}finally{o(!1)}};return(0,le.jsxs)("div",{className:"flex flex-col h-full w-full bg-white font-base44",children:[(0,le.jsx)("div",{className:"border-b bg-white px-6 py-4",children:(0,le.jsxs)("div",{className:"flex items-center gap-3",children:[(0,le.jsx)(Yt,{variant:"ghost",size:"icon",onClick:n,className:"h-7 w-7",children:(0,le.jsx)(Xs.A,{className:"h-4 w-4"})}),(0,le.jsx)("div",{className:Pe("h-8 w-8 rounded-lg flex items-center justify-center",(null==s?void 0:s.light)||"bg-slate-100"),children:(0,le.jsx)(Cm.A,{className:Pe("h-4 w-4",(null==s?void 0:s.text)||"text-slate-500")})}),(0,le.jsxs)("div",{className:"flex-1",children:[(0,le.jsx)("h3",{className:"font-semibold text-sm text-slate-900",children:t.agent_name}),(0,le.jsx)("p",{className:"text-xs text-slate-500",children:"Active conversation"})]})]})}),(0,le.jsx)(gm,{className:"flex-1 px-6 py-4",ref:c,children:(0,le.jsxs)("div",{className:"space-y-4",children:[0===m.length?(0,le.jsxs)("div",{className:"text-center py-8",children:[(0,le.jsx)("div",{className:"h-12 w-12 rounded-xl bg-slate-100 flex items-center justify-center mx-auto mb-3",children:(0,le.jsx)(Ir.A,{className:"h-6 w-6 text-slate-400"})}),(0,le.jsx)("p",{className:"text-sm text-slate-500",children:"Start your conversation"}),(0,le.jsx)("p",{className:"text-xs text-slate-400 mt-1",children:"Type a message below to begin"})]}):m.map(e=>e?(0,le.jsx)(Xv,{message:e},e.id):null),i&&(0,le.jsxs)("div",{className:"flex gap-3",children:[(0,le.jsx)("div",{className:"flex-shrink-0 mt-0.5",children:(0,le.jsx)(hg,{className:"h-7 w-7 rounded-lg"})}),(0,le.jsx)("div",{className:"bg-white border border-slate-200 rounded-2xl px-4 py-2.5",children:(0,le.jsx)(hg,{className:"h-4 w-32"})})]}),(0,le.jsx)("div",{ref:d})]})}),(0,le.jsx)("div",{className:"border-t bg-white px-6 py-4",children:(0,le.jsxs)("div",{className:"flex gap-2",children:[(0,le.jsx)(fs,{value:l,onChange:e=>r(e.target.value),onKeyPress:e=>"Enter"===e.key&&!e.shiftKey&&u(),placeholder:"Type your message...",disabled:i,className:"flex-1 text-sm border-slate-200 focus:border-slate-400"}),(0,le.jsx)(Yt,{onClick:u,disabled:i||!l.trim(),size:"sm",className:"bg-slate-800 hover:bg-slate-900 text-white",children:i?(0,le.jsx)(Ne.A,{className:"h-4 w-4 animate-spin"}):(0,le.jsx)(pp.A,{className:"h-4 w-4"})})]})})]})}const tb=e=>{let{className:t}=e;return(0,le.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 360 362",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:t,children:(0,le.jsx)("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M307.546 52.5655C273.709 18.685 228.706 0.0171895 180.756 0C81.951 0 1.53846 80.404 1.50408 179.235C1.48689 210.829 9.74646 241.667 25.4319 268.844L0 361.736L95.0236 336.811C121.203 351.096 150.683 358.616 180.679 358.625H180.756C279.544 358.625 359.966 278.212 360 179.381C360.017 131.483 341.392 86.4547 307.546 52.5741V52.5655ZM180.756 328.354H180.696C153.966 328.346 127.744 321.16 104.865 307.589L99.4242 304.358L43.034 319.149L58.0834 264.168L54.5423 258.53C39.6304 234.809 31.749 207.391 31.7662 179.244C31.8006 97.1036 98.6334 30.2707 180.817 30.2707C220.61 30.2879 258.015 45.8015 286.145 73.9665C314.276 102.123 329.755 139.562 329.738 179.364C329.703 261.513 262.871 328.346 180.756 328.346V328.354ZM262.475 216.777C257.997 214.534 235.978 203.704 231.869 202.209C227.761 200.713 224.779 199.966 221.796 204.452C218.814 208.939 210.228 219.029 207.615 222.011C205.002 225.002 202.389 225.372 197.911 223.128C193.434 220.885 179.003 216.158 161.891 200.902C148.578 189.024 139.587 174.362 136.975 169.875C134.362 165.389 136.7 162.965 138.934 160.739C140.945 158.728 143.412 155.505 145.655 152.892C147.899 150.279 148.638 148.406 150.133 145.423C151.629 142.432 150.881 139.82 149.764 137.576C148.646 135.333 139.691 113.287 135.952 104.323C132.316 95.5909 128.621 96.777 125.879 96.6309C123.266 96.5019 120.284 96.4762 117.293 96.4762C114.302 96.4762 109.454 97.5935 105.346 102.08C101.238 106.566 89.6691 117.404 89.6691 139.441C89.6691 161.478 105.716 182.785 107.959 185.776C110.202 188.767 139.544 234.001 184.469 253.408C195.153 258.023 203.498 260.782 210.004 262.845C220.731 266.257 230.494 265.776 238.212 264.624C246.816 263.335 264.71 253.786 268.44 243.326C272.17 232.866 272.17 223.893 271.053 222.028C269.936 220.163 266.945 219.037 262.467 216.794L262.475 216.777Z",fill:"currentColor"})})};function sb(e){let{agent:t,agentColor:s,appId:a,onClose:n,onSave:l,agentsSDK:r}=e;const{app:i,refreshApp:o}=Nt(),[c,d]=(0,Y.useState)(t.description||""),[m,u]=(0,Y.useState)(t.instructions||""),[x,h]=(0,Y.useState)(t.tool_configs||[]),[p,g]=(0,Y.useState)(t.whatsapp_greeting||""),[f,v]=(0,Y.useState)(!1),[b,j]=(0,Y.useState)([]),[y,N]=(0,Y.useState)([]),[w,_]=(0,Y.useState)("guidelines");(0,Y.useEffect)(()=>{const e=Object.keys((null==i?void 0:i.entities)||{});j(e);const t=Object.keys((null==i?void 0:i.functions)||{});N(t)},[i]);const k=()=>{const e=x.filter(e=>e.entity_name).map(e=>e.entity_name);return b.filter(t=>!e.includes(t))},C=()=>{const e=x.filter(e=>e.function_name).map(e=>e.function_name);return y.filter(t=>!e.includes(t))},A=()=>x.filter(e=>"entity_name"in e).lengthx.filter(e=>"function_name"in e).length{h(x.filter((t,s)=>s!==e))},I=(e,t)=>{const s=[...x];s[e]=(0,K.A)((0,K.A)({},s[e]),t),h(s)},T=["create","read","update","delete"],P=e=>"entity_name"in e;return(0,le.jsx)("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4 md:p-8",children:(0,le.jsxs)("div",{className:"w-full max-w-6xl h-[90vh] md:h-[85vh] bg-white rounded-lg shadow-xl flex flex-col md:flex-row overflow-hidden",children:[(0,le.jsxs)("div",{className:"md:w-64 bg-slate-50 border-b md:border-b-0 md:border-r border-slate-200 p-4 md:p-6",children:[(0,le.jsx)("div",{className:"mb-4 md:mb-8",children:(0,le.jsxs)("div",{className:"flex items-center gap-3 mb-3",children:[(0,le.jsx)("div",{className:Pe("h-8 w-8 md:h-10 md:w-10 rounded-lg flex items-center justify-center",(null==s?void 0:s.light)||"bg-slate-100"),children:(0,le.jsx)(Cm.A,{className:Pe("h-4 w-4 md:h-5 md:w-5",(null==s?void 0:s.text)||"text-slate-500")})}),(0,le.jsxs)("div",{children:[(0,le.jsx)("h2",{className:"text-base md:text-lg font-base44 font-semibold text-slate-900 truncate max-w-[150px]",children:t.name}),(0,le.jsx)("p",{className:"text-xs font-base44 text-slate-500",children:"Agent Configuration"})]})]})}),(0,le.jsxs)("nav",{className:"flex md:flex-col space-x-1 md:space-x-0 md:space-y-1",children:[(0,le.jsxs)("button",{onClick:()=>_("guidelines"),className:Pe("flex-1 md:w-full text-center md:text-left px-3 py-2 rounded-md text-sm font-medium transition-colors","guidelines"===w?"bg-white text-slate-900 shadow-sm":"text-slate-600 hover:bg-slate-100"),children:[(0,le.jsx)(hr.A,{className:"inline-block w-4 h-4 mr-0 md:mr-2"}),(0,le.jsx)("span",{className:"block md:inline mt-1 md:mt-0 text-xs md:text-sm",children:"Guidelines"})]}),(0,le.jsxs)("button",{onClick:()=>_("tools"),className:Pe("flex-1 md:w-full text-center md:text-left px-3 py-2 rounded-md text-sm font-medium transition-colors","tools"===w?"bg-white text-slate-900 shadow-sm":"text-slate-600 hover:bg-slate-100"),children:[(0,le.jsx)(Ed.A,{className:"inline-block w-4 h-4 mr-0 md:mr-2"}),(0,le.jsx)("span",{className:"block md:inline mt-1 md:mt-0 text-xs md:text-sm",children:"Tools"})]}),(0,le.jsxs)("button",{onClick:()=>_("whatsapp"),className:Pe("flex-1 md:w-full text-center md:text-left px-3 py-2 rounded-md text-sm font-medium transition-colors","whatsapp"===w?"bg-white text-slate-900 shadow-sm":"text-slate-600 hover:bg-slate-100"),children:[(0,le.jsx)(tb,{className:"inline-block w-4 h-4 mr-0 md:mr-2"}),(0,le.jsx)("span",{className:"block md:inline mt-1 md:mt-0 text-xs md:text-sm",children:"WhatsApp"})]})]})]}),(0,le.jsxs)("div",{className:"flex-1 flex flex-col min-h-0",children:[(0,le.jsxs)("div",{className:"px-4 md:px-8 py-4 border-b border-slate-200 flex items-center justify-between",children:[(0,le.jsx)("h3",{className:"text-base md:text-lg font-semibold text-slate-900 truncate",children:"guidelines"===w?"Guidelines":"Tools and Capabilities"}),(0,le.jsx)(Yt,{variant:"ghost",size:"icon",onClick:n,className:"h-8 w-8 flex-shrink-0",children:(0,le.jsx)(Bt.A,{className:"h-4 w-4"})})]}),(0,le.jsx)("div",{className:"flex-1 overflow-y-auto px-4 md:px-8 py-4 md:py-6",children:"guidelines"===w?(0,le.jsxs)("div",{className:"space-y-6 max-w-4xl",children:[(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsx)(Ns,{htmlFor:"description",className:"text-sm font-base44 font-medium text-slate-700",children:"Description"}),(0,le.jsx)("p",{className:"text-xs font-base44 text-slate-500",children:"This is the system prompt that defines the agent's behavior"}),(0,le.jsx)(um,{id:"description",value:c,onChange:e=>d(e.target.value),placeholder:"Brief description of what this agent does...",className:"min-h-[120px] resize-none font-mono text-sm"})]}),(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsx)(Ns,{htmlFor:"instructions",className:"text-sm font-base44 font-medium text-slate-700",children:"Instructions"}),(0,le.jsx)("p",{className:"text-xs font-base44 text-slate-500",children:"Specific guidelines and rules the agent should follow"}),(0,le.jsx)(um,{id:"instructions",value:m,onChange:e=>u(e.target.value),placeholder:"Detailed instructions for the agent...",className:"min-h-[200px] resize-none font-mono text-sm"})]})]}):"tools"===w?(0,le.jsx)("div",{className:"space-y-6 max-w-4xl",children:(0,le.jsxs)("div",{className:"space-y-4",children:[(0,le.jsxs)("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3",children:[(0,le.jsxs)("div",{children:[(0,le.jsx)("h4",{className:"text-sm font-base44 font-medium text-slate-700",children:"Available Tools"}),(0,le.jsx)("p",{className:"text-xs font-base44 text-slate-500 mt-1",children:"Configure what tools and data this agent can access"})]}),(0,le.jsxs)(qr,{children:[(0,le.jsx)(Vr,{asChild:!0,children:(0,le.jsxs)(Yt,{size:"sm",variant:"outline",className:"text-xs w-full sm:w-auto",disabled:!A()&&!S(),children:[(0,le.jsx)(kt.A,{className:"h-3.5 w-3.5 mr-1 sm:hidden"}),"Add",(0,le.jsx)(Is.A,{className:"h-3.5 w-3.5 ml-1"})]})}),(0,le.jsxs)(Kr,{align:"end",className:"w-72",children:[(0,le.jsxs)(Qr,{onClick:()=>{h([...x,{entity_name:"",allowed_operations:[]}])},disabled:!A(),className:"cursor-pointer",children:[(0,le.jsx)(Gc.A,{className:"h-4 w-4 mr-2"}),(0,le.jsxs)("div",{className:"flex flex-col",children:[(0,le.jsx)("span",{className:"text-sm font-medium",children:A()?"Add Entity Tool":"All Entity Slots Used"}),(0,le.jsx)("span",{className:"text-xs text-slate-500",children:"Database operations and CRUD access"})]})]}),(0,le.jsxs)(Qr,{onClick:()=>{h([...x,{function_name:"",description:""}])},disabled:!S(),className:"cursor-pointer",children:[(0,le.jsx)(Kl.A,{className:"h-4 w-4 mr-2"}),(0,le.jsxs)("div",{className:"flex flex-col",children:[(0,le.jsx)("span",{className:"text-sm font-medium",children:S()?"Add Backend Function":"All Function Slots Used"}),(0,le.jsx)("span",{className:"text-xs text-slate-500",children:"Custom backend logic and integrations"})]})]})]})]})]}),(0,le.jsx)("div",{className:"space-y-3",children:0===x.length?(0,le.jsxs)("div",{className:"text-center py-12 bg-slate-50 rounded-lg border border-slate-200 border-dashed",children:[(0,le.jsx)(Gc.A,{className:"h-8 w-8 text-slate-400 mx-auto mb-3"}),(0,le.jsx)("p",{className:"text-sm text-slate-500",children:"No tools configured"}),(0,le.jsx)("p",{className:"text-xs text-slate-400 mt-1",children:"Add entity tools or backend functions to give the agent capabilities"})]}):x.map((e,t)=>{var s,a,n;return(0,le.jsx)("div",{className:"border rounded-lg p-4 bg-white border-slate-200",children:P(e)?(0,le.jsxs)("div",{className:"space-y-3",children:[(0,le.jsxs)("div",{className:"flex items-start justify-between",children:[(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[(0,le.jsx)(Gc.A,{className:"h-4 w-4 text-teal-600"}),(0,le.jsx)("span",{className:"text-sm font-medium text-slate-700",children:"Entity Tool"})]}),(0,le.jsx)(Yt,{size:"icon",variant:"ghost",onClick:()=>E(t),className:"h-6 w-6 hover:bg-red-50",children:(0,le.jsx)(Ip.A,{className:"h-3.5 w-3.5 text-red-500 hover:text-red-600"})})]}),(0,le.jsxs)(zs,{value:e.entity_name||"",onValueChange:e=>I(t,{entity_name:e}),children:[(0,le.jsx)(qs,{className:"w-full",children:(0,le.jsx)(Ws,{placeholder:"Select entity"})}),(0,le.jsx)(Ys,{children:k().concat(e.entity_name?[e.entity_name]:[]).map(e=>(0,le.jsx)($s,{value:e,children:e},e))})]}),(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsxs)("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-2",children:[(0,le.jsx)("p",{className:"text-sm font-base44 font-thin text-black ",children:"Allowed operations"}),(0,le.jsx)("div",{className:"flex flex-wrap gap-2",children:T.map(s=>{var a,n;const l=(null===(a=e.allowed_operations)||void 0===a?void 0:a.includes("read"))||!1,r=("update"===s||"delete"===s)&&!l;return(0,le.jsxs)("label",{className:Pe("flex items-center gap-1.5 px-2 py-1 rounded-md",r?"cursor-not-allowed opacity-50":"cursor-pointer hover:bg-slate-50"),children:[(0,le.jsx)(dm,{checked:(null===(n=e.allowed_operations)||void 0===n?void 0:n.includes(s))||!1,onCheckedChange:()=>!r&&((e,t)=>{const s=x[e];if(!s.entity_name)return;const a=s.allowed_operations||[];let n;a.includes(t)?(n=a.filter(e=>e!==t),"read"===t&&(n=n.filter(e=>"update"!==e&&"delete"!==e))):n=[...a,t],I(e,{allowed_operations:n})})(t,s),disabled:r,className:"h-3.5 w-3.5"}),(0,le.jsx)("span",{className:Pe("text-xs font-base44 capitalize",r?"text-slate-400":"text-slate-600"),children:s})]},s)})})]}),(null===(s=e.allowed_operations)||void 0===s?void 0:s.includes("delete"))&&(0,le.jsxs)("div",{className:"flex items-center justify-end gap-2 mt-2",children:[(0,le.jsx)(ux.A,{className:"h-3.5 w-3.5 text-amber-500 flex-shrink-0"}),(0,le.jsx)("p",{className:"text-xs font-base44 text-slate-600",children:"Careful, deleted data by the agent can't be restored"})]})]})]}):(0,le.jsxs)("div",{className:"space-y-3",children:[(0,le.jsxs)("div",{className:"flex items-start justify-between",children:[(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[(0,le.jsx)(Kl.A,{className:"h-4 w-4 text-orange-600"}),(0,le.jsx)("span",{className:"text-sm font-medium text-slate-700",children:"Backend Function"})]}),(0,le.jsx)(Yt,{size:"icon",variant:"ghost",onClick:()=>E(t),className:"h-6 w-6 hover:bg-red-50",children:(0,le.jsx)(Ip.A,{className:"h-3.5 w-3.5 text-red-500 hover:text-red-600"})})]}),(0,le.jsxs)(zs,{value:e.function_name||"",onValueChange:s=>{var a;const n=null==i||null===(a=i.functions)||void 0===a?void 0:a[s];I(t,{function_name:s,description:(null==n?void 0:n.description)||e.description||""})},children:[(0,le.jsx)(qs,{className:"w-full",children:(0,le.jsx)(Ws,{placeholder:"Select backend function"})}),(0,le.jsx)(Ys,{children:C().concat(e.function_name?[e.function_name]:[]).map(e=>(0,le.jsx)($s,{value:e,children:e},e))})]}),e.function_name&&(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsx)(Ns,{htmlFor:"func-desc-".concat(t),className:"text-xs font-medium text-slate-600",children:"Function Description"}),(0,le.jsx)(um,{id:"func-desc-".concat(t),value:e.description||"",onChange:e=>I(t,{description:e.target.value}),placeholder:"Describe when and how this function should be used...",className:"min-h-[60px] resize-none text-xs"}),(null==i||null===(a=i.functions)||void 0===a||null===(n=a[e.function_name])||void 0===n?void 0:n.description)&&(0,le.jsxs)("p",{className:"text-xs text-slate-400 italic mt-1",children:["Default: ",i.functions[e.function_name].description]})]})]})},t)})})]})}):(0,le.jsxs)("div",{className:"space-y-6 max-w-4xl",children:[(0,le.jsxs)("div",{className:"flex items-center justify-between pb-2",children:[(0,le.jsxs)("div",{className:"flex items-center gap-3",children:[(0,le.jsx)("div",{className:"p-2 bg-green-50 rounded-lg",children:(0,le.jsx)(tb,{className:"w-6 h-6 text-green-600"})}),(0,le.jsxs)("div",{children:[(0,le.jsx)("h3",{className:"text-lg font-semibold text-slate-900",children:"WhatsApp Integration"}),(0,le.jsx)("p",{className:"text-sm text-slate-500",children:"Connect your agent to WhatsApp for seamless communication"})]})]}),(0,le.jsx)(Yt,{asChild:!0,className:"flex items-center gap-2.5 bg-green-500 hover:bg-green-600 text-white px-6 py-2.5 rounded-lg font-medium text-sm transition-all hover:shadow-md",children:(0,le.jsxs)("a",{href:r.getWhatsAppConnectURL(t.name),target:"_blank",rel:"noopener noreferrer",children:[(0,le.jsx)(tb,{className:"w-5 h-5"}),(0,le.jsx)("span",{children:"Test Chat"})]})})]}),(0,le.jsx)(is,{className:"border-slate-200 bg-white",children:(0,le.jsx)(ms,{className:"p-5",children:(0,le.jsxs)("div",{className:"space-y-3",children:[(0,le.jsxs)("div",{children:[(0,le.jsx)("h4",{className:"text-sm font-semibold text-slate-900",children:"Add WhatsApp to Your App"}),(0,le.jsx)("p",{className:"text-xs text-slate-600 mt-1",children:"Enable WhatsApp access for your users with a single command"})]}),(0,le.jsx)("div",{className:"flex items-center gap-2",children:(0,le.jsxs)("div",{className:"flex-1 flex items-center gap-2 bg-slate-50 border border-slate-200 rounded-lg px-3 py-2 group hover:border-slate-300 transition-colors",children:[(0,le.jsxs)("code",{className:"text-sm text-slate-700 font-mono flex-1",children:["Add a WhatsApp button for the ",t.name||"agent"]}),(0,le.jsxs)(Yt,{onClick:()=>{const e="Add a WhatsApp button for the ".concat(t.name||"agent");sessionStorage.setItem("pendingChatMessage",e),window.dispatchEvent(new CustomEvent("pendingChatMessage",{detail:{message:e}})),n(),Ri.toast.success("Command added to chat. Press Enter to send.")},className:"h-auto px-4 py-1.5 rounded-md bg-slate-100 hover:bg-slate-200 text-slate-700 text-xs font-medium transition-all hover:shadow-sm flex items-center gap-2",children:["Send to Chat",(0,le.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,le.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 7l5 5m0 0l-5 5m5-5H6"})})]})]})})]})})}),(0,le.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[(0,le.jsx)(is,{className:"border-slate-200 hover:border-slate-300 transition-colors",children:(0,le.jsx)(ms,{className:"p-4",children:(0,le.jsxs)("div",{className:"flex items-start gap-3",children:[(0,le.jsx)("div",{className:"p-1.5 bg-orange-50 rounded-lg flex-shrink-0",children:(0,le.jsx)("svg",{className:"w-5 h-5 text-orange-600",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,le.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"})})}),(0,le.jsxs)("div",{children:[(0,le.jsx)("h4",{className:"text-sm font-medium text-slate-900",children:"Full Chat Capabilities"}),(0,le.jsx)("p",{className:"text-xs text-slate-600 mt-1",children:"All web chat features work seamlessly in WhatsApp, including tools and data access"})]})]})})}),(0,le.jsx)(is,{className:"border-slate-200 hover:border-slate-300 transition-colors",children:(0,le.jsx)(ms,{className:"p-4",children:(0,le.jsxs)("div",{className:"flex items-start gap-3",children:[(0,le.jsx)("div",{className:"p-1.5 bg-teal-50 rounded-lg flex-shrink-0",children:(0,le.jsx)("svg",{className:"w-5 h-5 text-teal-600",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,le.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 11a7 7 0 01-7 7m0 0a7 7 0 01-7-7m7 7v4m0 0H8m4 0h4m-4-8a3 3 0 01-3-3V5a3 3 0 116 0v6a3 3 0 01-3 3z"})})}),(0,le.jsxs)("div",{children:[(0,le.jsx)("h4",{className:"text-sm font-medium text-slate-900",children:"Voice & Media Support"}),(0,le.jsx)("p",{className:"text-xs text-slate-600 mt-1",children:"Users can send voice notes and images for natural interaction"})]})]})})}),(0,le.jsx)(is,{className:"border-slate-200 hover:border-slate-300 transition-colors",children:(0,le.jsx)(ms,{className:"p-4",children:(0,le.jsxs)("div",{className:"flex items-start gap-3",children:[(0,le.jsx)("div",{className:"p-1.5 bg-orange-50 rounded-lg flex-shrink-0",children:(0,le.jsx)("svg",{className:"w-5 h-5 text-orange-600",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,le.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 18h.01M8 21h8a2 2 0 002-2V5a2 2 0 00-2-2H8a2 2 0 00-2 2v14a2 2 0 002 2z"})})}),(0,le.jsxs)("div",{children:[(0,le.jsxs)("h4",{className:"text-sm font-medium text-slate-900",children:["Custom Numbers ",(0,le.jsx)(es,{variant:"outline",className:"ml-2 text-xs",children:"Coming Soon"})]}),(0,le.jsx)("p",{className:"text-xs text-slate-600 mt-1",children:"Connect your own WhatsApp Business numbers"})]})]})})}),(0,le.jsx)(is,{className:"border-slate-200 hover:border-slate-300 transition-colors",children:(0,le.jsx)(ms,{className:"p-4",children:(0,le.jsxs)("div",{className:"flex items-start gap-3",children:[(0,le.jsx)("div",{className:"p-1.5 bg-teal-50 rounded-lg flex-shrink-0",children:(0,le.jsx)("svg",{className:"w-5 h-5 text-teal-600",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,le.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 20l4-16m4 4l4 4-4 4M6 16l-4-4 4-4"})})}),(0,le.jsxs)("div",{children:[(0,le.jsx)("h4",{className:"text-sm font-medium text-slate-900",children:"Easy UI Integration"}),(0,le.jsx)("p",{className:"text-xs text-slate-600 mt-1",children:"Add WhatsApp button to your app with a simple chat command"})]})]})})})]}),(0,le.jsxs)(is,{className:"border-slate-200",children:[(0,le.jsx)(os,{className:"pb-4",children:(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[(0,le.jsx)("svg",{className:"w-5 h-5 text-slate-600",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,le.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M11 5.882V19.24a1.76 1.76 0 01-3.417.592l-2.147-6.15M18 13a3 3 0 100-6M5.436 13.683A4.001 4.001 0 017 6h1.832c4.1 0 7.625-1.234 9.168-3v14c-1.543-1.766-5.067-3-9.168-3H7a3.988 3.988 0 01-1.564-.317z"})}),(0,le.jsx)(cs,{className:"text-base",children:"Welcome Message"})]})}),(0,le.jsxs)(ms,{className:"space-y-3",children:[(0,le.jsx)("p",{className:"text-sm text-slate-600",children:"Craft a warm greeting that introduces your agent and sets expectations"}),(0,le.jsxs)("div",{className:"relative",children:[(0,le.jsx)(um,{id:"whatsapp-greeting",value:p,onChange:e=>g(e.target.value),placeholder:"Hello! Welcome to ".concat((null==i?void 0:i.name)||"our app"," \u{1f44b}\n\nI'm your AI assistant, here to help you with any questions or tasks.\n\nHow can I assist you today?"),className:"min-h-[120px] resize-none text-sm font-normal pr-12"}),(0,le.jsxs)("div",{className:"absolute top-2 right-2 text-xs text-slate-400",children:[p.length,"/500"]})]})]})]})]})}),(0,le.jsxs)("div",{className:"px-4 md:px-8 py-4 border-t border-slate-200 flex flex-col sm:flex-row justify-end gap-3 bg-slate-50",children:[(0,le.jsx)(Yt,{variant:"outline",onClick:n,className:"px-6 order-2 sm:order-1",children:"Cancel"}),(0,le.jsx)(Yt,{onClick:async()=>{v(!0);try{const e=x.filter(e=>e.entity_name||e.function_name).map(e=>e.entity_name?{entity_name:e.entity_name,allowed_operations:e.allowed_operations||[]}:{function_name:e.function_name,description:e.description||""});l&&await l((0,K.A)((0,K.A)({},t),{},{description:c,instructions:m,tool_configs:e,whatsapp_greeting:p})),n()}catch(e){Ri.toast.error("Failed to save agent configuration")}finally{v(!1)}},disabled:f,className:"px-6 bg-slate-900 hover:bg-slate-800 text-white order-1 sm:order-2",children:f?"Saving...":"Save"})]})]})]})})}const ab=[{bg:"bg-rose-500",text:"text-rose-500",light:"bg-rose-100"},{bg:"bg-blue-500",text:"text-blue-500",light:"bg-blue-100"},{bg:"bg-emerald-500",text:"text-emerald-500",light:"bg-emerald-100"},{bg:"bg-amber-500",text:"text-amber-500",light:"bg-amber-100"},{bg:"bg-purple-500",text:"text-purple-500",light:"bg-purple-100"},{bg:"bg-teal-500",text:"text-teal-500",light:"bg-teal-100"},{bg:"bg-orange-500",text:"text-orange-500",light:"bg-orange-100"},{bg:"bg-indigo-500",text:"text-indigo-500",light:"bg-indigo-100"},{bg:"bg-pink-500",text:"text-pink-500",light:"bg-pink-100"},{bg:"bg-cyan-500",text:"text-cyan-500",light:"bg-cyan-100"},{bg:"bg-lime-500",text:"text-lime-500",light:"bg-lime-100"},{bg:"bg-violet-500",text:"text-violet-500",light:"bg-violet-100"},{bg:"bg-fuchsia-500",text:"text-fuchsia-500",light:"bg-fuchsia-100"},{bg:"bg-sky-500",text:"text-sky-500",light:"bg-sky-100"},{bg:"bg-yellow-500",text:"text-yellow-500",light:"bg-yellow-100"},{bg:"bg-red-500",text:"text-red-500",light:"bg-red-100"},{bg:"bg-green-500",text:"text-green-500",light:"bg-green-100"},{bg:"bg-slate-500",text:"text-slate-500",light:"bg-slate-100"},{bg:"bg-zinc-500",text:"text-zinc-500",light:"bg-zinc-100"},{bg:"bg-stone-500",text:"text-stone-500",light:"bg-stone-100"}];function nb(e){if(!e)return ab[0];let t=0;for(let a=0;a{Ri.toast.error(e||"An error occurred")}),y=Object.entries(e.agents||{}).map(e=>{let[t,s]=e;return(0,K.A)((0,K.A)({},s),{},{key:t,name:t})});(0,Y.useEffect)(()=>{const e=new URLSearchParams(l.search),t=e.get("agent"),s=e.get("conversation"),a=e.get("tab");s?(w(s),p("conversations")):t?(b(t),p("agents")):a&&p(a)},[l.search]),(0,Y.useEffect)(()=>{N()},[]);const N=async()=>{x(!0);try{const e=await j.getConversations();c(e||[])}catch(e){Ri.toast.error("Failed to load conversations")}finally{x(!1)}},w=async e=>{try{const t=await j.getConversation(e);m(t),p("conversations")}catch(t){Ri.toast.error("Failed to load conversation")}},_=e=>{const t=new URLSearchParams(l.search);t.delete("agent"),t.delete("conversation"),t.delete("tab"),Object.entries(e).forEach(e=>{let[s,a]=e;a&&t.set(s,a)});const s=t.toString(),a=l.pathname+(s?"?".concat(s):"");n(a,{replace:!0})},k=async e=>{f(!0);try{const t=await j.createConversation({agent_name:e.name});c(e=>[t,...e]),m(t),p("conversations"),_({conversation:t.id,tab:"conversations"}),Ri.toast.success("Conversation started")}catch(t){Ri.toast.error("Failed to start conversation")}finally{f(!1)}},C=async e=>{try{const t=await j.getConversation(e.id);m(t),_({conversation:e.id,tab:"conversations"})}catch(t){Ri.toast.error("Failed to load conversation")}},A=e=>{i(e.name),_({agent:e.name,tab:"agents"})};(0,Y.useEffect)(()=>{let e=null;if(d)return e=j.subscribeToConversation(d.id,e=>{m(t=>(0,K.A)((0,K.A)({},t),{},{messages:e.messages}))}),()=>{e&&e()}},[null==d?void 0:d.id]);const S=async()=>{try{await a({agents_enabled:!0}),Ri.toast.success("AI agents enabled successfully")}catch(e){Ri.toast.error("Failed to enable AI agents")}};return e.agents_enabled&&0!==y.length?d?(0,le.jsx)("div",{className:"h-full p-4 bg-slate-50",children:(0,le.jsx)(eb,{conversation:d,agentColor:nb(d.agent_name),agentsSDK:j,onBack:()=>{m(null),N(),_({tab:"conversations"})}})}):(0,le.jsxs)(up,{title:"AI Agents",subtitle:"Manage agents and conversations",children:[(0,le.jsx)("div",{className:"flex-1 overflow-hidden",children:0===y.length?(0,le.jsx)("div",{className:"h-full flex items-center pt-16",children:(0,le.jsx)(is,{className:"max-w-md w-full border-dashed mx-auto",children:(0,le.jsxs)(ms,{className:"flex flex-col items-center justify-center py-8",children:[(0,le.jsx)("div",{className:"h-16 w-16 rounded-2xl bg-gradient-to-br from-teal-100 to-slate-100 flex items-center justify-center mb-4",children:(0,le.jsx)(Cm.A,{className:"h-8 w-8 text-teal-600"})}),(0,le.jsx)("h3",{className:"text-base font-semibold text-slate-700 mb-2",children:"No Agents Yet"}),(0,le.jsx)("p",{className:"text-sm text-slate-500 text-center",children:"Prompt the chat to create your first AI agent"})]})})}):(0,le.jsxs)(kr,{value:h,onValueChange:e=>{p(e),_({tab:e})},className:"h-full flex flex-col",children:[(0,le.jsxs)(Cr,{className:"flex w-fit items-center justify-center gap-0.5 px-1 py-0 rounded-lg bg-gradient-to-r from-slate-200 to-slate-200 shadow-inner",children:[(0,le.jsx)(Ar,{value:"agents",className:"text-sm font-base44 px-3 py-1 rounded-md transition-all duration-200 hover:bg-white/50 data-[state=active]:bg-white data-[state=active]:shadow-sm data-[state=active]:text-slate-900",children:"Agents"}),(0,le.jsxs)(Ar,{value:"conversations",className:"text-sm font-base44 px-4 py-1 rounded-md transition-all duration-200 hover:bg-white/50 data-[state=active]:bg-white data-[state=active]:shadow-sm data-[state=active]:text-slate-900 flex items-center",children:["Conversations",o.filter(e=>e.messages&&e.messages.length>0).length>0&&(0,le.jsx)(es,{variant:"secondary",className:"ml-1.5 px-1.5 py-0.5 text-xs bg-white border-0",children:o.filter(e=>e.messages&&e.messages.length>0).length})]})]}),(0,le.jsxs)("div",{className:"flex-1 ",children:[(0,le.jsx)(Sr,{value:"agents",className:"mt-4 h-full",children:g?(0,le.jsx)("div",{className:"grid grid-cols-1 gap-3 max-w-4xl",children:[...Array(3)].map((e,t)=>(0,le.jsxs)("div",{className:"bg-white border border-gray-100 rounded-[12px] p-4",children:[(0,le.jsxs)("div",{className:"flex items-start justify-between mb-2",children:[(0,le.jsxs)("div",{className:"flex items-start gap-3 flex-1",children:[(0,le.jsx)(hg,{className:"h-10 w-10 rounded-lg"}),(0,le.jsx)(hg,{className:"h-6 w-32"})]}),(0,le.jsxs)("div",{className:"flex gap-2",children:[(0,le.jsx)(hg,{className:"h-8 w-16"}),(0,le.jsx)(hg,{className:"h-8 w-16"})]})]}),(0,le.jsxs)("div",{className:"pl-[52px]",children:[(0,le.jsx)(hg,{className:"h-4 w-24 mb-2"}),(0,le.jsxs)("div",{className:"flex gap-1 mb-2",children:[(0,le.jsx)(hg,{className:"h-5 w-16"}),(0,le.jsx)(hg,{className:"h-5 w-20"})]}),(0,le.jsx)(hg,{className:"h-4 w-full"}),(0,le.jsx)(hg,{className:"h-4 w-3/4 mt-1"})]})]},t))}):(0,le.jsx)("div",{className:"grid grid-cols-1 gap-3 max-w-4xl",children:y.map((t,a)=>(0,le.jsx)("div",{onClick:()=>(e=>{b(e.name),_({agent:e.name,tab:"agents"})})(t),className:"cursor-pointer",children:(0,le.jsx)($v,{agent:t,color:nb(t.name),onEdit:A,onStartChat:k,isSelected:v===t.name,agentsSDK:j,onSaveWhatsAppGreeting:a=>(async(t,a)=>{const n=e.agents[t];if(!n)return;const l=(0,K.A)((0,K.A)({},n),{},{whatsapp_greeting:a});await s("agents/"+t,JSON.stringify(l,null,2))})(t.name,a),onToggleWhatsApp:(a,n)=>async function(t,a){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;const l=e.agents[t];if(!l)return;const r=(0,K.A)((0,K.A)({},l),{},{whatsapp_enabled:a});a&&n&&(r.whatsapp_greeting=n),await s("agents/"+t,JSON.stringify(r,null,2))}(t.name,a,n)})},t.key))})}),(0,le.jsx)(Sr,{value:"conversations",className:"mt-4 h-full",children:u?(0,le.jsx)("div",{className:"grid grid-cols-1 gap-2 max-w-4xl",children:[...Array(4)].map((e,t)=>(0,le.jsx)("div",{className:"bg-white border border-gray-100 rounded-lg p-4",children:(0,le.jsxs)("div",{className:"flex items-start gap-3",children:[(0,le.jsx)(hg,{className:"h-8 w-8 rounded-lg"}),(0,le.jsxs)("div",{className:"flex-1",children:[(0,le.jsx)(hg,{className:"h-5 w-32 mb-1"}),(0,le.jsx)(hg,{className:"h-4 w-48 mb-2"}),(0,le.jsx)(hg,{className:"h-3 w-20"})]})]})},t))}):0===o.length?(0,le.jsx)(is,{className:"border-dashed max-w-4xl",children:(0,le.jsxs)(ms,{className:"py-8 text-center",children:[(0,le.jsx)(Gv.A,{className:"h-10 w-10 text-slate-300 mx-auto mb-3"}),(0,le.jsx)("p",{className:"text-sm text-slate-500",children:"No conversations yet"}),(0,le.jsx)("p",{className:"text-xs text-slate-400 mt-1",children:"Go to the Agents tab to start a conversation"})]})}):(0,le.jsx)("div",{className:"grid grid-cols-1 gap-2 max-w-4xl",children:o.filter(e=>e.messages&&e.messages.length>0).map(e=>(0,le.jsx)(Zv,{conversation:e,agentColor:nb(e.agent_name),onSelect:C,isSelected:(null==d?void 0:d.id)===e.id},e.id))})})]})]})}),r&&(0,le.jsx)(sb,{agent:e.agents[r],agentColor:nb(r),appId:e.id,onClose:()=>{i(null),_({tab:"agents"})},onSave:async e=>{const t={description:e.description,instructions:e.instructions,tool_configs:e.tool_configs,whatsapp_greeting:e.whatsapp_greeting};await s("agents/"+r,JSON.stringify(t,null,2)),i(null),_({agent:r,tab:"agents"})},agentsSDK:j})]}):(0,le.jsx)("div",{className:"h-full bg-slate-50 flex flex-col items-center p-8",children:(0,le.jsxs)("div",{className:"flex-1 flex flex-col items-center pt-16",children:[(0,le.jsx)("div",{className:"text-center mb-8",children:(0,le.jsx)("h1",{className:"text-3xl font-base44 text-slate-700",children:"Set up Agents"})}),(0,le.jsx)("div",{className:"w-full max-w-3xl",children:(0,le.jsx)("div",{className:"relative flex items-center justify-center",children:(0,le.jsx)("div",{className:"w-full max-w-2xl",children:(0,le.jsxs)("div",{className:"space-y-16",children:[(0,le.jsx)("div",{className:"relative ".concat(e.agents_enabled?"opacity-60":""),children:(0,le.jsxs)("div",{className:"flex items-start gap-6",children:[(0,le.jsx)("div",{className:"flex-shrink-0 w-8 h-8 bg-gray-200 text-black rounded-full flex items-center justify-center text-sm font-base44 relative z-10",children:e.agents_enabled?"\u2713":"1"}),(0,le.jsxs)("div",{className:"flex-1",children:[(0,le.jsx)("h3",{className:"text-xl font-base44 mb-1 ".concat(e.agents_enabled?"text-slate-600":"text-slate-900"),children:"Enable Agents"}),(0,le.jsx)("p",{className:"text-base font-base44 mb-6 ".concat(e.agents_enabled?"text-slate-500":"text-slate-600"),children:"Turn on the toggle to allow agent creation"}),(0,le.jsx)("div",{className:"bg-white rounded-[16px] p-6 border border-slate-200 font-base44",children:(0,le.jsxs)("div",{className:"flex items-center justify-between",children:[(0,le.jsxs)("div",{children:[(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[(0,le.jsx)("span",{className:"text-sm font-base44 text-slate-900",children:"AI Agents"}),(0,le.jsx)(es,{variant:"secondary",className:"text-xs bg-blue-100 text-blue-700 border-0 font-base44 font-thin",children:"Beta"})]}),(0,le.jsx)("p",{className:"text-xs font-base44 text-slate-600 mt-1",children:"Build AI agents into your app using Base44's AI agents infrastructure"})]}),(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[(0,le.jsx)("span",{className:"text-xs font-base44 text-slate-500",children:"Enabled"}),(0,le.jsx)("button",{onClick:e.agents_enabled?void 0:S,disabled:e.agents_enabled,className:"relative inline-flex h-6 w-11 items-center rounded-full transition-colors focus:outline-none focus:ring-2 focus:ring-offset-2 ".concat(e.agents_enabled?"bg-teal-600 focus:ring-teal-500 cursor-default":"bg-slate-300 focus:ring-slate-400 cursor-pointer hover:bg-slate-400"),children:(0,le.jsx)("span",{className:"inline-block h-4 w-4 transform rounded-full bg-white transition-transform ".concat(e.agents_enabled?"translate-x-6":"translate-x-1")})})]})]})})]})]})}),(0,le.jsx)("div",{className:"relative ".concat(e.agents_enabled?"":"opacity-50"),children:(0,le.jsxs)("div",{className:"flex items-start gap-6",children:[(0,le.jsx)("div",{className:"flex-shrink-0 w-8 h-8 rounded-full flex items-center justify-center text-sm font-base44 relative z-10 ".concat(e.agents_enabled?"bg-slate-600 text-white":"bg-slate-300 text-slate-500"),children:"2"}),(0,le.jsxs)("div",{className:"flex-1",children:[(0,le.jsx)("h3",{className:"text-xl font-base44 mb-1 ".concat(e.agents_enabled?"text-slate-900":"text-slate-500"),children:"Add your first Agent"}),(0,le.jsx)("p",{className:"text-base font-base44 ".concat(e.agents_enabled?"text-gray-500":"text-slate-500"),children:"Ask the chat to create an agent for you. Describe what role the agent should have and what tasks it should perform."})]})]})})]})})})})]})})}function rb(){const{app:e}=Nt(),{workspaceView:t}=(0,Z.g)(),s=(0,Z.Zp)(),[a,n]=(0,Y.useState)(!1),[l,r]=(0,Y.useState)(!1),[i,o]=(0,Y.useState)(!1);(0,Y.useEffect)(()=>{e&&e.id&&r(!0)},[e]),(0,Y.useEffect)(()=>{const e=()=>{o(window.innerWidth<1024)};return e(),window.addEventListener("resize",e),()=>{window.removeEventListener("resize",e)}},[]);const c=t||"overview",d="code"===c,m=()=>{if(!l)return(0,le.jsx)("div",{className:"w-full h-full flex items-center justify-center",children:(0,le.jsxs)("div",{className:"text-center",children:[(0,le.jsx)("div",{className:"animate-spin h-8 w-8 border-4 border-blue-500 rounded-full border-t-transparent mx-auto mb-4"}),(0,le.jsx)("p",{className:"text-gray-500",children:"Loading app data..."})]})});if(d)return(0,le.jsx)(yf,{});let t;if("overview"===c)t=(0,le.jsx)(qg,{appId:e.id});else if("analytics"===c)t=(0,le.jsx)(sf,{appId:e.id});else if("domains"===c)t=(0,le.jsx)(tv,{appId:e.id,appName:e.name});else if("secrets"===c)t=(0,le.jsx)(zv,{appId:e.id});else if("security"===c)t=(0,le.jsx)(Rv,{appId:e.id});else if(c.startsWith("entity-")){const s=c.split("entity-")[1],a=e.entities[s];t=a?(0,le.jsx)(hp,{entity:a}):null}else if("users"===c)t=(0,le.jsx)(vp,{appId:e.id});else if("app-settings"===c)t=(0,le.jsx)(jg,{});else if("api"===c)t=(0,le.jsx)(Lg,{appId:e.id});else if("logs"===c)t=(0,le.jsx)(Hg,{appId:e.id});else if("authentication"===c)t=(0,le.jsx)(Ig,{});else{if("agents"!==c)return(0,le.jsx)("div",{className:"p-6",children:"Unknown view"});t=(0,le.jsx)(lb,{})}return(0,le.jsx)("div",{className:"h-full w-full overflow-auto",children:t})},u=t=>{s("/apps/".concat(e.id,"/editor/workspace/").concat(t))};let x=[{id:"overview",label:"Overview",icon:"\u{1f4cb}"},{id:"users",label:"Users",icon:"\u{1f465}"},{id:"data",label:"Data",icon:"\u{1f5c4}\ufe0f",subitems:e&&e.entities?Object.keys(e.entities).map(e=>({id:"entity-".concat(e),label:e,icon:"\u{1f4c4}"})):[]},{id:"analytics",label:"Analytics",icon:"\u{1f4c8}"},{id:"domains",label:"Domains",icon:"\u{1f310}"},{id:"security",label:"Security",icon:"\u{1f512}"},{id:"code",label:"Code",icon:"\u{1f4bb}"},{id:"agents",label:"Agents",icon:"\u{1f916}",badge:"Beta"},{id:"logs",label:"Logs",icon:"\u{1f50d}"},{id:"api",label:"API",icon:"\u{1f511}"},{id:"settings",label:"Settings",icon:"\u2699\ufe0f",subitems:[{id:"app-settings",label:"App Settings"},{id:"authentication",label:"Authentication"}]}];return e&&e.has_backend_functions_enabled&&x.push({id:"secrets",label:"Secrets",icon:"\u{1f511}"}),d?(0,le.jsx)("div",{className:"h-full w-full relative",children:m()}):i?(0,le.jsxs)("div",{className:"h-full w-full flex flex-col",children:[(0,le.jsxs)("div",{className:"w-full bg-white border-b p-2 flex items-center",children:[(0,le.jsx)("button",{className:"p-2 rounded-md hover:bg-gray-100 transition-colors",onClick:()=>n(!0),children:(0,le.jsx)(Yg.A,{size:20})}),(0,le.jsx)("div",{className:"ml-2 font-medium",children:"App Editor"})]}),(0,le.jsx)(Hx,{items:x,selected:c,onSelect:e=>{u(e),n(!1)},isOpen:a,onClose:()=>n(!1),title:"App Editor",showSearch:!1}),(0,le.jsx)("div",{className:"flex-1 overflow-auto",children:m()})]}):(0,le.jsx)("div",{className:"h-full w-full relative",children:(0,le.jsxs)(Mm,{direction:"horizontal",children:[(0,le.jsx)(Dm,{defaultSize:25,minSize:15,maxSize:30,className:"h-full overflow-hidden",children:(0,le.jsx)(Hx,{items:x,selected:c,onSelect:e=>{u(e),n(!1)},isOpen:a,onClose:()=>n(!1),title:"App Editor",showSearch:!1})}),(0,le.jsx)(Fm,{withHandle:!0,className:"group transition-opacity opacity-0 hover:opacity-100 focus:opacity-100"}),(0,le.jsx)(Dm,{defaultSize:75,className:"flex-1 overflow-auto",children:m()})]})})}const ib=e=>{let{children:t,menuControl:s,toggleControl:a,actionControl:n,hideToolbar:l=!1,noPadding:r=!1}=e;return Ut()?(0,le.jsxs)("div",{className:"flex flex-col h-full overflow-hidden",children:[!l&&(0,le.jsxs)("div",{className:Pe("flex items-center border-b gap-2",{"px-4 py-3":!r}),children:[(0,le.jsx)("div",{className:" flex",children:s}),(0,le.jsx)("div",{className:"flex-1 flex",children:a}),(0,le.jsx)("div",{className:" flex",children:n})]}),(0,le.jsx)("div",{className:"flex-1 overflow-auto",children:t})]}):(0,le.jsxs)("div",{className:"flex flex-col h-full overflow-hidden pr-2",children:[!l&&(0,le.jsxs)("div",{className:"flex items-center justify-between py-1",children:[(0,le.jsx)("div",{className:"flex items-center gap-2",children:s}),(0,le.jsx)("div",{children:n})]}),(0,le.jsx)("div",{className:"flex-1 overflow-auto border border-slate-200 rounded-[10px] mb-2",children:t})]})},ob=e=>{let{url:t,iframeRef:s}=e;if(s.current){const e=null!=t?t:s.current.src;s.current.src="",setTimeout(()=>{s.current&&(s.current.src=e)},50)}},cb=e=>{let{selectedCheckpointId:t}=e;const{app:s,runtimeAuthToken:a,previewIframeRef:n}=Nt(),l=(0,Y.useCallback)(()=>{const e=window.location.pathname.split("/preview")[1],n=t?function(e,t){return va("checkpoint--".concat(e.id,"--").concat(t.id))}(s,{id:t}):function(e){return va("preview--".concat(e.slug))}(s),l=new URLSearchParams({access_token:a,hide_badge:"true"});return"".concat(n).concat(e,"?").concat(l.toString())},[t]);return{getIframeURL:l,refreshPreview:()=>{ob({url:l(),iframeRef:n})}}},db=(0,Y.createContext)(null),mb=e=>{let{children:t}=e;const s=(0,Y.useRef)({});return(0,le.jsx)(db.Provider,{value:{refreshPreview:()=>{Object.values(s.current).forEach(e=>null==e?void 0:e())},setRefreshPreviewHandler:(e,t)=>{s.current[e]=t}},children:t})},ub=()=>{var e;return null!==(e=(0,Y.useContext)(db))&&void 0!==e?e:{}},xb=e=>{var t,s;let{isPhoneMode:a,view:n}=e;const{app:l,previewIframeRef:r}=Nt(),i=(0,Z.Zp)(),o=Nu(e=>e.selectedCheckpoint),c=null!==(t=null==o?void 0:o.id)&&void 0!==t?t:"",{getIframeURL:d}=cb({selectedCheckpointId:c}),m=Ut(),{setRefreshPreviewHandler:u}=ub();return(0,Y.useEffect)(()=>(null==u||u("DefaultPreview",()=>ob({url:d(),iframeRef:r})),()=>{null==u||u("DefaultPreview",void 0)}),[d,r]),(0,Y.useEffect)(()=>{const e=d();if(c)"workspace"===n.toLowerCase()?i("/apps/".concat(l.id,"/editor/preview/").concat(l.main_page)):ob({url:e,iframeRef:r});else{var t,s;if("ready"!==l.status.state)return;(null===(t=l.conversation)||void 0===t||null===(s=t.messages)||void 0===s?void 0:s.length)<=2?setTimeout(()=>{ob({url:e,iframeRef:r})},1e3):ob({url:e,iframeRef:r})}},[c,n,null===(s=l.status)||void 0===s?void 0:s.last_updated_date]),(0,Y.useEffect)(()=>{if(l.slug&&r.current&&!r.current.src.includes(l.slug)){const e=d();r.current.src=e,setTimeout(()=>{r.current&&(r.current.src=e)},50)}},[l.slug]),(0,le.jsx)("iframe",{title:"App Preview",allow:"accelerometer; autoplay; camera; encrypted-media; fullscreen; geolocation; gyroscope; microphone; midi; clipboard-read; clipboard-write; payment; usb; vr; xr-spatial-tracking; screen-wake-lock; magnetometer; ambient-light-sensor; battery; gamepad; picture-in-picture; display-capture; bluetooth;",ref:r,id:"preview-iframe",className:Pe("transition-all duration-300 ease-in-out w-full h-full",{"w-[375px] h-[667px] border border-gray-300 rounded-xl shadow-md":a}),style:m&&!a?{height:"100vh"}:{}})},hb=["data"],pb=e=>{let{isPhoneMode:t,className:s}=e;const{sandboxPreviewUrl:a,isLoadingSandbox:n,isUpdatingSandbox:l}=gb(),{previewIframeRef:r}=Nt(),i=Hu(),o=n||l;return(0,le.jsxs)("div",{className:Pe("relative w-full h-full",s),children:[o&&(0,le.jsx)("div",{className:"absolute w-full h-full flex items-center justify-center bg-white/50 backdrop-blur-sm",children:(0,le.jsx)("div",{className:"w-12 h-12 border-4 border-gray-200 border-t-black rounded-full animate-spin"})}),(0,le.jsx)("iframe",{title:"App Preview",allow:"accelerometer; autoplay; camera; encrypted-media; fullscreen; geolocation; gyroscope; microphone; midi; clipboard-read; clipboard-write; payment; usb; vr; xr-spatial-tracking; screen-wake-lock; magnetometer; ambient-light-sensor; battery; gamepad; picture-in-picture; display-capture; bluetooth;",ref:r,id:"preview-iframe",src:a,className:Pe("transition-all duration-300 ease-in-out w-full h-full",{"w-[375px] h-[667px] border border-gray-300 rounded-xl shadow-md":t}),style:i&&!t?{height:"100vh"}:{}})]})},gb=()=>{const{app:e,runtimeAuthToken:t,setAppErrors:s,isUpdatingApp:a}=Nt(),{pageName:n}=(0,Z.g)(),l=hu(),{activeSandboxCheckpoint:r,isSyncingSandboxCheckpoint:i}=Nu("activeSandboxCheckpoint","isSyncingSandboxCheckpoint"),[o,c]=(0,Y.useState)(!1),d=(0,Y.useRef)(!1),{setRefreshPreviewHandler:m}=ub(),u=uu({query:async t=>{var a;return(null==t||null===(a=t.refetchData)||void 0===a||!a.keepAlive)&&s([]),gu.getPreviewURL(e.id,(null==r?void 0:r.id)||"")},initialData:null,enabled:Boolean(l&&null!=(null==e?void 0:e.id)),retry:{delay:1e3,retries:3},logErrorMsg:"Failed to fetch sandbox preview URL",onLoading:e=>{e||(d.current=!1)}},[null==e?void 0:e.id,null==r?void 0:r.id]),{data:x}=u,h=(0,Se.A)(u,hb),p=(0,Y.useMemo)(()=>{if(!x)return null;const s=n||e.main_page||"";return"".concat(x,"/").concat(s)+"?"+new URLSearchParams({access_token:t,hide_badge:"true",server_url:"https://base44.app"}).toString()},[t,x]);(0,Y.useEffect)(()=>{const e=setInterval(()=>{d.current=!0,h.refetchIfEnabled({keepAlive:!0})},6e4);return()=>{clearInterval(e)}},[h.refetchIfEnabled]);const g=(0,Y.useCallback)(()=>{c(!1),s([]),h.resetData({refetch:!0})},[h.resetData]);(0,Y.useEffect)(()=>(null==m||m("SandboxPreview",g),()=>{null==m||m("SandboxPreview",void 0)}),[g]);const f=e=>{var t;switch(null===(t=e.data)||void 0===t?void 0:t.type){case"sandbox:beforeUpdate":c(!0),s([]),setTimeout(()=>{c(!1)},1e4);break;case"sandbox:afterUpdate":case"sandbox:error":c(!1)}};(0,Y.useEffect)(()=>(window.addEventListener("message",f),()=>{window.removeEventListener("message",f)}),[]);const v=o||a||i;return{sandboxPreviewUrl:p,isLoadingSandbox:h.isLoading&&!d.current||!p,isUpdatingSandbox:v}},fb=["className"],vb=["withHandle","className"],bb=e=>{let{className:t}=e,s=(0,Se.A)(e,fb);return(0,le.jsx)(Lm.YZ,(0,K.A)({className:Pe("flex h-full w-full data-[panel-group-direction=vertical]:flex-col",t)},s))},jb=Lm.Zk,yb=e=>{let{withHandle:t,className:s}=e,a=(0,Se.A)(e,vb);return(0,le.jsx)(Lm.TW,(0,K.A)((0,K.A)({className:Pe("relative flex w-px items-center justify-center bg-border after:absolute after:inset-y-0 after:left-1/2 after:w-1 after:-translate-x-1/2 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-1 data-[panel-group-direction=vertical]:h-px data-[panel-group-direction=vertical]:w-full data-[panel-group-direction=vertical]:after:left-0 data-[panel-group-direction=vertical]:after:h-1 data-[panel-group-direction=vertical]:after:w-full data-[panel-group-direction=vertical]:after:-translate-y-1/2 data-[panel-group-direction=vertical]:after:translate-x-0 [&[data-panel-group-direction=vertical]>div]:rotate-90",s)},a),{},{children:t&&(0,le.jsx)("div",{className:"z-10 flex h-4 w-3 items-center justify-center rounded-sm border bg-border",children:(0,le.jsx)(Pm.A,{className:"h-2.5 w-2.5"})})}))},Nb=["onBack","checkpointId","useSandbox"],wb=e=>{var t;let{onBack:s,checkpointId:a,useSandbox:n}=e,l=(0,Se.A)(e,Nb);const[r,i]=(0,Y.useState)(null),[o,c]=(0,Y.useState)(""),{loading:d,error:m,fetchedFileTree:u}=(e=>{let{checkpointId:t,useSandbox:s,enabled:a}=e;const{app:n}=Nt(),[l,r]=(0,Y.useState)(a),[i,o]=(0,Y.useState)(null),[c,d]=(0,Y.useState)(null);return(0,Y.useEffect)(()=>{a&&s&&(async()=>{try{r(!0),o(null);const e=await gu.getAppFiles(n.id);d({files:e,file_errors:{}}),r(!1)}catch(e){o("Failed to load checkpoint code"),r(!1)}})()},[s,t,n.id]),(0,Y.useEffect)(()=>{a&&!s&&t&&(async()=>{try{r(!0),o(null);const e=await br.getCheckpointFileTree(n.id,t);d(e),r(!1)}catch(e){o("Failed to load checkpoint code"),r(!1)}})()},[s,t,n.id]),{loading:l,error:i,fetchedFileTree:c}})({checkpointId:a,useSandbox:n,enabled:!l.fileTree}),[x,h,p,g]=l.fileTree?[l.selectedFile,l.setSelectedFile,l.fileContent,l.setFileContent]:[r,i,o,c],f=null!==(t=l.fileTree)&&void 0!==t?t:u,v=(e,t)=>"layout"===e&&"main"===t?"layout":"globals"===e&&"css"===t?"globals.css":e&&t?"".concat(e,"/").concat(t):"",b=e=>"object"==typeof e?JSON.stringify(e,null,2):e||"";(0,Y.useEffect)(()=>{if(!f||!x)return;const e=v(x.type,x.key);e&&void 0!==f.files[e]&&g(b(f.files[e]))},[f,x]);if(d)return(0,le.jsx)("div",{className:"h-full flex items-center justify-center bg-white","data-testid":"loading-state",children:(0,le.jsxs)("div",{className:"flex flex-col items-center gap-3",children:[(0,le.jsx)("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-slate-600"}),(0,le.jsx)("div",{className:"text-slate-500",children:"Loading checkpoint code..."})]})});if(m)return(0,le.jsxs)("div",{className:"h-full flex flex-col items-center justify-center bg-white","data-testid":"error-state",children:[(0,le.jsx)("div",{className:"text-red-500 mb-4",children:m}),(0,le.jsx)("button",{onClick:s,className:"px-4 py-2 border border-slate-200 rounded-md hover:bg-slate-50",children:"Back to Preview"})]});const j=(()=>{if(!f||!f.files)return{pages:{},components:{},entities:{},functions:{},agents:{},layout:null,globals_css:null,has_backend_functions_enabled:!1};const e={pages:{},components:{},entities:{},functions:{},agents:{},layout:null,globals_css:null,has_backend_functions_enabled:!1};return Object.entries(f.files).forEach(t=>{let[s,a]=t;if(s.startsWith("pages/"))e.pages[s.substring(6)]=a;else if(s.startsWith("components/"))e.components[s.substring(11)]=a;else if(s.startsWith("entities/")){const t="object"==typeof a?JSON.stringify(a,null,2):a;e.entities[s.substring(9)]=t}else if(s.startsWith("functions/"))e.functions[s.substring(10)]=a,e.has_backend_functions_enabled=!0;else if(s.startsWith("agents/")){const t="object"==typeof a?JSON.stringify(a,null,2):a;e.agents[s.substring(7)]=t}else"layout"===s?e.layout=a:"globals.css"===s.toLowerCase()&&(e.globals_css=a)}),e})();(null==f?void 0:f.files)&&Object.keys(f.files).length;return(0,le.jsx)("div",{className:"h-full w-full bg-white","data-testid":"checkpoint-code-view",children:(0,le.jsxs)(bb,{direction:"horizontal",className:"",children:[(0,le.jsx)(jb,{defaultSize:25,minSize:20,maxSize:40,className:"h-full overflow-hidden",children:(0,le.jsx)(jf,{selectedFile:x,onFileSelect:(e,t)=>{if(!f||!f.files)return;let s,a;if(e.includes(":"))[s,a]=e.split(":");else{if(!e.includes("/"))return;{const t=e.split("/");s=t[0],a=t.slice(1).join("/")}}const n=v(s,a);n&&void 0!==f.files[n]&&(h({type:s,key:a}),g(b(f.files[n])))},onBack:s,app:j,readOnly:!0,backButtonText:"Back to Preview",title:"Checkpoint Files",showEmptyMessage:!0,emptyMessage:(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)("div",{className:"mb-2",children:"This checkpoint appears to be empty."}),(0,le.jsx)("div",{className:"text-xs",children:"No code files found."})]})})}),(0,le.jsx)(yb,{withHandle:!0,className:"group transition-opacity opacity-0 hover:opacity-100 focus:opacity-100"}),(0,le.jsx)(jb,{defaultSize:75,className:"flex-1 overflow-x-auto",children:x?(0,le.jsxs)("div",{className:"h-full relative","data-testid":"code-editor-container",children:[(0,le.jsxs)("div",{className:"absolute top-0 left-0 right-0 bg-slate-50 border-b border-slate-200 px-4 py-2 z-10",children:[(0,le.jsx)("div",{className:"text-sm font-medium text-slate-700","data-testid":"selected-file-name",children:(()=>{if(!x)return"";const{type:e,key:t}=x;return"layout"===e&&"main"===t?"layout":"globals"===e&&"css"===t?"globals.css":"".concat(e,"/").concat(t)})()}),(0,le.jsx)("div",{className:"text-xs text-slate-500 mt-0.5",children:"Read-only view"})]}),(0,le.jsx)("div",{className:"h-full pt-14",children:(0,le.jsx)(jr.KE,{language:(()=>{if(!x)return"javascript";const{type:e,key:t}=x;return null!=t&&t.endsWith(".css")||"globals"===e?"css":"entities"===e||"agents"===e?"json":"javascript"})(),value:p,options:{readOnly:!0,minimap:{enabled:!1},scrollBeyondLastLine:!1,fontSize:14,lineNumbers:"on",renderLineHighlight:"none",occurrencesHighlight:"off",selectionHighlight:!1,wordWrap:"on"},theme:"vs-light"})})]}):(0,le.jsx)("div",{className:"h-full flex items-center justify-center text-slate-500","data-testid":"no-file-selected",children:"Select a file to view code"})})]})})},_b=e=>{let{onBack:t}=e;const{filesTreeState:s}=Nu(),[a,n]=(0,Y.useState)(null),[l,r]=(0,Y.useState)("");return s.filesTreeIsLoading?(0,le.jsx)("div",{className:"h-full flex items-center justify-center bg-white","data-testid":"loading-state",children:(0,le.jsxs)("div",{className:"flex flex-col items-center gap-3",children:[(0,le.jsx)("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-slate-600"}),(0,le.jsx)("div",{className:"text-slate-500",children:"Loading checkpoint code..."})]})}):s.filesTreeError?(0,le.jsxs)("div",{className:"h-full flex flex-col items-center justify-center bg-white","data-testid":"error-state",children:[(0,le.jsx)("div",{className:"text-red-500 mb-4",children:"Error fetching files"}),(0,le.jsx)("button",{onClick:t,className:"px-4 py-2 border border-slate-200 rounded-md hover:bg-slate-50",children:"Back to Preview"})]}):(0,le.jsx)(wb,{onBack:t,fileTree:s.filesTree,selectedFile:a,setSelectedFile:n,fileContent:l,setFileContent:r})};var kb=s(81103);const Cb=e=>{let{onExit:t,setShowCodeView:s,showCodeView:a}=e;const n=Hu(),{selectedCheckpoint:l,restoreSelectedCheckpoint:r,isRestoring:i}=Nu("selectedCheckpoint","restoreSelectedCheckpoint","isRestoring");return!l||n?null:(0,le.jsx)("div",{className:"fixed top-0 left-0 right-0 z-50 bg-slate-50",children:(0,le.jsx)("div",{className:"max-w-4xl mx-auto px-4 pt-2",children:(0,le.jsxs)("div",{className:"flex items-center justify-between",children:[(0,le.jsxs)("div",{className:"flex items-center gap-3",children:[(0,le.jsx)("div",{className:"w-2 h-2 bg-orange-400 rounded-full"}),(0,le.jsxs)("div",{children:[(0,le.jsx)("p",{className:"text-sm font-medium text-slate-800",children:"Viewing Version History"}),(0,le.jsx)("p",{className:"text-xs text-slate-500",children:l.name})]})]}),(0,le.jsx)("div",{className:"absolute left-1/2 transform translate-x-12",children:(0,le.jsxs)(Hn,{variant:"outline",size:"sm",className:"h-8 text-xs",onClick:()=>s(!a),children:[(0,le.jsx)(Kl.A,{className:"w-3 h-3 mr-2"}),a?"View App":"View Code"]})}),(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[(0,le.jsx)(Hn,{variant:"outline",size:"sm",className:"h-8 text-xs",onClick:r,disabled:i,children:i?(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(kb.A,{className:"mr-2 h-3 w-3 animate-spin"}),"Restoring..."]}):"Restore This Version"}),(0,le.jsx)(Hn,{variant:"ghost",size:"sm",className:"h-8 text-xs text-slate-600",onClick:t,disabled:i,children:"Exit"})]})]})})})},Ab={"#130":"Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: %s. This often happens due to incorrect import/export statements. Check default vs named exports.","#310":"Rendered more hooks than during the previous render. Never call hooks inside conditionals/loops/early returns. Hooks must be called in the same order every render.","#31":"Objects are not valid as a React child. If you meant to render a collection of children, use an array instead.","#185":"Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops.","#300":"Cannot update a component while rendering a different component. To locate the bad setState() call, follow the stack trace.","#301":"Rendered fewer hooks than expected. This may be caused by an accidental early return statement.","#181":"Invalid hook call. Hooks can only be called inside of the body of a function component. Check for: 1) Mismatching versions of React and React DOM, 2) Breaking the Rules of Hooks, 3) Multiple copies of React.","#321":"Invalid argument passed as callback. Expected a function. Instead received: %s.","#60":"ReactDOM.render(): Invalid component element. Instead of passing a string like 'div', pass React.createElement('div').","#62":"The root container is not a DOM element."},Sb=e=>{const t=(e=>{if(e.title&&e.title.includes("Minified React error"))for(const[t,s]of Object.entries(Ab))if(e.title.includes("Minified React error ".concat(t)))return(0,K.A)((0,K.A)({},e),{},{details:s});return e})(e),s=Ae().escape(t.title),a=Ae().escape(t.details||"no details");return'\n\n')+"\n\n"},Eb=()=>{var e,t;const{app:s,appErrors:a,setAppErrors:n,addChatMessage:l}=Nt(),{user:r}=oe(),i=Hu(),[o,c]=(0,Y.useState)(!1);if(0===a.length||"ready"!==s.app_stage)return null;const d=async()=>{c(!0);const e=a.map(e=>Sb(e)).join("\n\n"),t="the following errors happened in the app:\n".concat(e,"\n---\nplease help me fix these errors");(async e=>{try{var t,a;tt("User clicked resolve with AI",{user_id:(null==r?void 0:r.id)||null,app_id:s.id,app_name:s.name,conversation_id:(null==s||null===(t=s.conversation)||void 0===t?void 0:t.id)||null,error_message:e}),ht({user_id:(null==r?void 0:r.id)||null,app_id:(null==s?void 0:s.id)||null,conversation_id:(null==s||null===(a=s.conversation)||void 0===a?void 0:a.id)||null},{cta:"resolve with ai",origin:"editor",target_route:"same_page",error_message:e})}catch(n){}})(t),await l({role:"user",content:t}),n([]),c(!1)};return(0,le.jsx)("div",{className:Pe("fixed bottom-4 right-4 z-50 max-w-md bg-white rounded-lg shadow-xl p-4 border border-gray-100",{"bottom-2 right-2 left-2 z-50 max-w-full":i}),children:(0,le.jsxs)("div",{className:"flex flex-col gap-3",children:[(0,le.jsxs)("div",{className:"flex justify-between items-center",children:[(0,le.jsx)("div",{className:"font-medium text-gray-800",children:"Issues Found"}),(0,le.jsx)("button",{onClick:()=>n([]),className:"p-1 hover:bg-gray-100 rounded-md",children:(0,le.jsx)(Bt.A,{size:16})})]}),a.map(e=>(0,le.jsxs)("div",{className:"text-sm text-gray-600",children:[e.componentName&&(0,le.jsxs)("div",{className:"text-xs text-gray-500 mb-1",children:["In ",e.componentName," component:"]}),e.title]},e.title)),(0,le.jsx)("button",{onClick:()=>d(),disabled:"processing"===(null===(e=s.status)||void 0===e?void 0:e.state)||o,className:"px-4 py-2 bg-gray-900 hover:bg-gray-800 text-white text-sm rounded-md transition-colors mt-2 ".concat("processing"===(null===(t=s.status)||void 0===t?void 0:t.state)?"opacity-50 cursor-not-allowed":""),children:"Resolve with AI"}),"free"!==r.subscription_tier&&(0,le.jsx)("div",{className:"text-xs text-gray-500 mt-1 italic",children:"This action won't deduct credits from your account."})]})})};function Ib(e){let{app:t}=e;return(0,le.jsx)("div",{className:"h-full flex items-center justify-center pt-4",children:(0,le.jsxs)("div",{className:"flex flex-col items-center space-y-8 max-w-md text-center px-4",children:[(0,le.jsxs)("div",{className:"relative",children:[(0,le.jsx)("div",{className:"w-16 h-16 rounded-full bg-orange-500/20 backdrop-blur-sm flex items-center justify-center",children:(0,le.jsx)("div",{className:"w-8 h-8 rounded-full bg-gradient-to-br from-orange-400 to-orange-500"})}),(0,le.jsx)("div",{className:"absolute top-0 left-0 w-16 h-16 rounded-full bg-orange-400/20 animate-ping"}),(0,le.jsx)("div",{className:"absolute top-2 left-2 w-12 h-12 rounded-full bg-orange-300/10 animate-ping",style:{animationDelay:"0.2s"}})]}),(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsx)("h2",{className:"text-2xl font-medium tracking-tight text-slate-700",children:"Creating Your App"}),(0,le.jsx)("p",{className:"text-sm font-light text-teal-700/60 tracking-wide",children:"This might take a few minutes..."})]}),(0,le.jsx)("div",{className:"text-base text-teal-600/80 font-light tracking-wide",children:(0,le.jsx)(To,{status:t.status.details})})]})})}var Tb=s(28017);const Pb=e=>{var t;let{onClickOnLoader:s}=e;const{app:a}=Nt();switch(!0){case"pending"!==a.app_stage:return null;case"processing"===(null===(t=a.status)||void 0===t?void 0:t.state):return(0,le.jsx)(Ib,{app:a});default:return(0,le.jsx)("div",{className:"h-full flex items-center justify-center pt-4",children:(0,le.jsxs)("div",{className:"flex flex-col items-center space-y-6 max-w-md text-center px-4",children:[(0,le.jsx)("div",{className:"w-12 h-12 rounded-full bg-gray-100 flex items-center justify-center",onClick:s,children:(0,le.jsx)(Tb.A,{className:"w-6 h-6 text-gray-400"})}),(0,le.jsx)("h2",{className:"text-xl font-light text-gray-700",children:"Let's Build Your App"}),(0,le.jsx)("p",{className:"text-sm text-gray-500",children:"Tell me what you'd like to create using the chat"})]})})}};function Lb(e){let{view:t,toolbars:s,isPhoneMode:a}=e;const{selectedCheckpoint:n,canUseSandboxPreview:l,setSelectedCheckpoint:r,isLoading:i}=Nu(),{app:o}=Nt(),c="pending"===o.app_stage,[d,m]=(0,Y.useState)(!1),u=(0,Z.Zp)(),[x,h]=(0,Y.useState)(!1),p=hu(),g=p&&l;(()=>{const{app:e,onAppError:t}=Nt(),s=hu(),a=(0,Z.Zp)(),n=Ut(),l=(0,Y.useCallback)(l=>{var r,i;if("app_error"===(null===(r=l.data)||void 0===r?void 0:r.type)&&l.data.error&&t(l.data.error.title,l.data.error.details,l.data.error.componentName),"app_changed_url"===(null===(i=l.data)||void 0===i?void 0:i.type)&&l.data.url&&window.location.href.includes("/preview")){const t=new URL(l.data.url),r=t.pathname,i=new URLSearchParams(t.search);i.delete("access_token"),i.delete("hide_badge"),i.delete("server_url");let o=r;if(s){if(r.startsWith("/apps")){const t=r.split("/");if(t.length>3){const s=t[3];o="/apps/".concat(e.id,"/editor/preview/").concat(s)}else o="/apps/".concat(e.id,"/editor/preview/").concat(e.main_page)}else if("/"===r||""===r)o="/apps/".concat(e.id,"/editor/preview/").concat(e.main_page);else{const t=r.startsWith("/")?r.slice(1):r;o="/apps/".concat(e.id,"/editor/preview/").concat(t)}i.toString()&&(o+="?"+i.toString()),a(o)}else{if(r.startsWith("/apps"))return o="/"+r.split("/").pop(),o.includes("".concat(e.slug))?void 0:void a("/apps/".concat(e.id,"/editor/preview").concat(o));"/"===r||r==="/".concat(e.slug)?o="/apps/".concat(e.id,"/editor/preview/").concat(e.main_page):r.startsWith("/apps")||r.includes("".concat(e.slug))||(o="/apps/".concat(e.id,"/editor/preview").concat(r));const t=i.toString();t&&(o+="?".concat(t)),n||a(o)}}},[t,a,n,e.slug,e.id,e.main_page]);(0,Y.useEffect)(()=>(window.addEventListener("message",l),()=>window.removeEventListener("message",l)),[l])})(),(0,Y.useEffect)(()=>{n&&"workspace"===t.toLowerCase()&&!i&&u("/apps/".concat(o.id,"/editor/preview/").concat(o.main_page))},[n,i]);const f="workspace"===t&&!c,v="preview"===t&&!c&&n&&x,b="preview"===t&&!c&&!g&&!v,j=v||f||c||b;return(0,le.jsxs)("div",{className:"flex-grow h-full overflow-y-auto",children:[(0,le.jsxs)(ib,{hideToolbar:c,menuControl:null==s?void 0:s.left,toggleControl:null==s?void 0:s.middle,actionControl:null==s?void 0:s.right,noPadding:null==s?void 0:s.noPadding,children:[c&&(0,le.jsx)(Pb,{}),p&&(0,le.jsx)(pb,{isPhoneMode:a,className:Pe({hidden:j})}),b&&(0,le.jsx)("div",{className:"w-full h-full flex justify-center ".concat(a?"items-start pt-4":""),children:(0,le.jsx)(xb,{isPhoneMode:a,view:t})}),f&&(0,le.jsx)(rb,{}),v&&(0,le.jsx)(_b,{onBack:()=>h(!1)})]}),(0,le.jsx)(gp,{isVisible:d,onCancel:()=>m(!1),onInviteSuccess:()=>m(!1)}),(0,le.jsx)(Cb,{showCodeView:x,setShowCodeView:h,onExit:()=>{r(void 0),h(!1)}}),(0,le.jsx)(Eb,{})]})}var Ob=s(58406),Rb=s(52245);function Mb(e){let{onClose:t}=e;const{allActivities:s,clearActivities:a}=ar(),[n,l]=(0,Y.useState)("all"),[r,i]=(0,Y.useState)("all"),[o,c]=(0,Y.useState)(""),[d,m]=(0,Y.useState)(!1),u=(0,Y.useRef)(null),x=(0,Y.useRef)(null),h=[{value:"all",label:"All",count:s.length},{value:"requests",label:"Requests",count:s.filter(e=>"request"===e.type).length},{value:"logs",label:"Logs",count:s.filter(e=>"log"===e.type).length}].filter(e=>e.count>0),p=s.filter(e=>{if(!((e,t)=>{if(!t.trim())return!0;const s=t.toLowerCase();if("log"===e.type){var a,n;const t=(null===(a=e.message)||void 0===a?void 0:a.toString().toLowerCase())||"",l=(null===(n=e.component)||void 0===n?void 0:n.toLowerCase())||"";return t.includes(s)||l.includes(s)}if("request"===e.type){var l;const t=(null===(l=e.url)||void 0===l?void 0:l.toLowerCase())||"",a="string"==typeof e.body?e.body.toLowerCase():JSON.stringify(e.body||{}).toLowerCase(),n="string"==typeof e.response?e.response.toLowerCase():JSON.stringify(e.response||{}).toLowerCase();return t.includes(s)||a.includes(s)||n.includes(s)}return!1})(e,o))return!1;if("all"===n);else if("requests"===n){if("request"!==e.type)return!1}else{if("logs"!==n)return!1;if("log"!==e.type)return!1}if("requests"===n&&"all"!==r){const t=parseInt(r);return"request"===e.type&&"completed"===e.status&&e.statusCode===t}return!0}),g=[...p].sort((e,t)=>{const s="request"===e.type?e.startTime:e.timestamp,a="request"===t.type?t.startTime:t.timestamp;return new Date(s)-new Date(a)}),f=(()=>{if("requests"!==n)return[];const e=new Set;s.forEach(t=>{"request"===t.type&&"completed"===t.status&&t.statusCode&&e.add(t.statusCode)});const t=[{value:"all",label:"All",count:s.filter(e=>"request"===e.type).length}];return Array.from(e).sort((e,t)=>e-t).forEach(e=>{const a=s.filter(t=>"request"===t.type&&"completed"===t.status&&t.statusCode===e).length;t.push({value:e.toString(),label:"".concat(e),count:a,statusCode:e})}),t.filter(e=>e.count>0)})(),v=e=>e>=200&&e<300?"bg-emerald-50 text-emerald-700 border-emerald-200":e>=300&&e<400?"bg-blue-50 text-blue-700 border-blue-200":e>=400&&e<500?"bg-amber-50 text-amber-700 border-amber-200":e>=500?"bg-rose-50 text-rose-700 border-rose-200":"bg-slate-50 text-slate-700 border-slate-200",b=e=>e>=200&&e<300?(0,le.jsx)(Vg.A,{className:"h-3 w-3"}):e>=300&&e<400?(0,le.jsx)(uo.A,{className:"h-3 w-3"}):e>=400&&e<500?(0,le.jsx)(ux.A,{className:"h-3 w-3"}):e>=500?(0,le.jsx)(Gg.A,{className:"h-3 w-3"}):(0,le.jsx)(uo.A,{className:"h-3 w-3"}),j=()=>{m(!0),setTimeout(()=>{u.current&&u.current.focus()},100)};(0,Y.useEffect)(()=>{if(d&&u.current){const e=setTimeout(()=>{u.current&&document.activeElement!==u.current&&u.current.focus()},50);return()=>clearTimeout(e)}},[n,d]);const y=()=>{m(!1),c("")};(0,Y.useEffect)(()=>{const e=e=>{if(d&&x.current&&!x.current.contains(e.target)){const t=e.target.closest('[role="combobox"]')||e.target.closest("[data-radix-collection-item]")||e.target.closest("button");o.trim()||t||m(!1)}};return d&&document.addEventListener("mousedown",e),()=>{document.removeEventListener("mousedown",e)}},[d,o]);const N=s.filter(e=>"request"===e.type).length,w=s.filter(e=>"log"===e.type).length;return(0,le.jsxs)("div",{className:"flex flex-col h-full bg-white shadow-lg rounded-lg relative",children:[(0,le.jsxs)("div",{className:"flex justify-between items-center py-3 px-4 border-b",children:[(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[(0,le.jsx)("h2",{className:"font-semibold",children:"Activity Monitor"}),(0,le.jsx)("div",{className:"text-xs text-muted-foreground",children:s.length>0&&(0,le.jsxs)(es,{variant:"outline",className:"font-normal bg-slate-50",children:[s.length," entries"]})})]}),(0,le.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,le.jsxs)(zs,{value:n,onValueChange:e=>{l(e),"requests"!==e&&i("all")},children:[(0,le.jsxs)(qs,{className:"h-8 w-auto min-w-[90px] bg-white border-slate-200",children:[(0,le.jsx)(Rb.A,{className:"h-3.5 w-3.5 mr-1.5 text-slate-500"}),(0,le.jsx)(Ws,{})]}),(0,le.jsx)(Ys,{className:"bg-white border-slate-200",children:h.map(e=>(0,le.jsx)($s,{value:e.value,className:"hover:bg-slate-50",children:(0,le.jsxs)("div",{className:"flex items-center justify-between w-full",children:[(0,le.jsx)("span",{children:e.label}),(0,le.jsx)("span",{className:"text-xs text-slate-400 ml-2",children:e.count})]})},e.value))})]}),"requests"===n&&f.length>1&&(0,le.jsxs)(zs,{value:r,onValueChange:i,children:[(0,le.jsx)(qs,{className:"h-8 w-auto min-w-[70px] bg-white border-slate-200",children:(0,le.jsx)(Ws,{})}),(0,le.jsx)(Ys,{className:"bg-white border-slate-200",children:f.map(e=>(0,le.jsx)($s,{value:e.value,className:"hover:bg-slate-50",children:(0,le.jsxs)("div",{className:"flex items-center justify-between w-full",children:[(0,le.jsx)("span",{className:"flex items-center gap-1",children:e.statusCode?(0,le.jsxs)(le.Fragment,{children:[b(e.statusCode),(0,le.jsx)(es,{variant:"outline",className:Pe("text-xs px-1 py-0.5",v(e.statusCode)),children:e.label})]}):e.label}),(0,le.jsx)("span",{className:"text-xs text-slate-400 ml-1.5",children:e.count})]})},e.value))})]}),(0,le.jsx)(Yt,{variant:"outline",size:"sm",onClick:()=>{a(),c(""),l("all"),i("all"),m(!1)},className:"h-8",children:(0,le.jsx)(Ip.A,{className:"h-3.5 w-3.5"})}),t&&(0,le.jsx)(Yt,{variant:"ghost",size:"sm",onClick:t,className:"h-8 w-8 p-0",children:(0,le.jsx)(Bt.A,{className:"h-4 w-4"})})]})]}),(d||o.trim())&&(0,le.jsx)("div",{ref:x,className:"border-b border-slate-200 px-4 py-2",children:d?(0,le.jsxs)("div",{className:"relative animate-in slide-in-from-top-2 duration-200",children:[(0,le.jsx)(vn.A,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 h-3.5 w-3.5 text-slate-400"}),(0,le.jsx)(fs,{ref:u,type:"text",placeholder:(()=>{switch(n){case"logs":return"Search logs...";case"requests":return"Search requests...";default:return"Search logs and requests..."}})(),value:o,onChange:e=>c(e.target.value),onKeyDown:e=>{"Escape"===e.key&&y()},className:"h-10 w-full pl-10 pr-10 text-sm bg-white border-slate-200 placeholder:text-slate-400 focus:ring-2 focus:ring-orange-100 focus:border-orange-300"},"network-search-input"),(0,le.jsx)(Yt,{variant:"ghost",size:"sm",onClick:y,className:"absolute right-2 top-1/2 transform -translate-y-1/2 h-6 w-6 p-0 hover:bg-slate-100",children:(0,le.jsx)(Bt.A,{className:"h-3 w-3"})})]}):(0,le.jsxs)(Yt,{variant:"outline",size:"sm",onClick:j,className:"h-8 w-full justify-start gap-2 bg-orange-50 border-orange-200 text-orange-700",children:[(0,le.jsx)(vn.A,{className:"h-3.5 w-3.5"}),(0,le.jsxs)("span",{className:"text-sm",children:['Search: "',o.length>30?o.substring(0,30)+"...":o,'"']})]})}),s.length>0&&(0,le.jsxs)("div",{className:"flex justify-between items-center text-xs border-b px-4 py-1 bg-slate-50",children:[(0,le.jsxs)("div",{className:"flex items-center gap-3",children:[!d&&!o.trim()&&(0,le.jsx)(Yt,{variant:"ghost",size:"sm",onClick:j,className:"h-4 w-4 p-0 text-slate-400 hover:text-slate-500 hover:bg-transparent",children:(0,le.jsx)(vn.A,{className:"h-3 w-3"})}),(0,le.jsxs)("span",{children:[N," requests"]}),(0,le.jsxs)("span",{children:[w," logs"]})]}),(o.trim()||"all"!==n||"all"!==r)&&(0,le.jsxs)("div",{className:"text-slate-500",children:["Showing ",p.length," of ",s.length]})]}),0===s.length&&!d&&!o.trim()&&(0,le.jsx)("div",{className:"px-4 py-1 border-b border-slate-200",children:(0,le.jsx)(Yt,{variant:"ghost",size:"sm",onClick:j,className:"h-4 w-4 p-0 text-slate-400 hover:text-slate-500 hover:bg-transparent",children:(0,le.jsx)(vn.A,{className:"h-3 w-3"})})}),(0,le.jsx)(gm,{className:"flex-grow",children:0===g.length?(0,le.jsxs)("div",{className:"flex flex-col items-center justify-center h-full text-muted-foreground p-8",children:[(0,le.jsx)("p",{className:"text-sm",children:0===s.length?"No activities logged":o.trim()?"No ".concat("all"===n?"activities":n,' found matching "').concat(o,'"'):"No matching activities found"}),o.trim()&&(0,le.jsx)("p",{className:"text-xs mt-2 text-slate-400",children:"Try a different search term or clear filters"})]}):(0,le.jsx)("div",{className:"p-2 space-y-1",children:[...g].reverse().map(e=>"request"===e.type?(0,le.jsx)(Fb,{request:e},e.id):(0,le.jsx)(Db,{log:e},e.id))})})]})}function Db(e){var t,s,a;let{log:n}=e;const{icon:l,className:r}=(e=>{switch(e){case"error":return{icon:(0,le.jsx)(Gg.A,{className:"h-3.5 w-3.5"}),className:"bg-rose-50 text-rose-700"};case"warn":return{icon:(0,le.jsx)(ux.A,{className:"h-3.5 w-3.5"}),className:"bg-amber-50 text-amber-700"};default:return{icon:(0,le.jsx)(uo.A,{className:"h-3.5 w-3.5"}),className:"bg-slate-50 text-slate-700"}}})(n.severity),i=e=>e?ra()(e).fromNow():"";return(0,le.jsxs)(Fx,{className:"border rounded overflow-hidden hover:shadow-sm transition-all duration-200",children:[(0,le.jsxs)(Bx,{className:"flex w-full p-2 hover:bg-accent/5 text-left",children:[(0,le.jsx)("div",{className:"flex-shrink-0 w-16 flex justify-center",children:(0,le.jsxs)(es,{variant:"outline",className:"bg-purple-50 text-purple-700 font-mono text-xs uppercase",children:[(0,le.jsx)(gf.A,{className:"h-3 w-3 mr-1"})," Log"]})}),(0,le.jsxs)("div",{className:"flex-grow mx-3",children:[n.component&&(0,le.jsx)("div",{className:"text-xs text-muted-foreground mb-0.5 font-medium",children:n.component}),(0,le.jsxs)("div",{className:"text-sm font-normal truncate",children:[null===(t=n.message)||void 0===t?void 0:t.toString().substring(0,60),(null===(s=n.message)||void 0===s?void 0:s.toString().length)>60?"...":""]})]}),(0,le.jsxs)("div",{className:"flex items-center gap-2 shrink-0",children:[(0,le.jsx)("div",{className:"text-xs text-muted-foreground text-right",children:i(n.timestamp)}),(0,le.jsx)(es,{variant:"outline",className:Pe("flex items-center",r),children:l}),(0,le.jsx)(Is.A,{className:"h-3.5 w-3.5 text-muted-foreground"})]})]}),(0,le.jsx)(zx,{children:(0,le.jsx)("div",{className:"p-4 border-t bg-slate-50/50",children:(0,le.jsxs)("div",{className:"space-y-3",children:[(0,le.jsxs)("div",{children:[(0,le.jsx)("p",{className:"text-sm font-medium",children:"Message"}),(0,le.jsx)("pre",{className:"p-3 rounded bg-white text-xs overflow-auto max-h-60 border whitespace-pre-wrap",children:null===(a=n.message)||void 0===a?void 0:a.toString()})]}),(0,le.jsxs)("div",{className:"grid grid-cols-2 gap-3",children:[(0,le.jsxs)("div",{children:[(0,le.jsx)("p",{className:"text-sm font-medium",children:"Severity"}),(0,le.jsx)("p",{className:"text-sm text-muted-foreground",children:n.severity})]}),n.component&&(0,le.jsxs)("div",{children:[(0,le.jsx)("p",{className:"text-sm font-medium",children:"Component"}),(0,le.jsx)("p",{className:"text-sm text-muted-foreground",children:n.component})]}),(0,le.jsxs)("div",{children:[(0,le.jsx)("p",{className:"text-sm font-medium",children:"Time"}),(0,le.jsx)("p",{className:"text-sm text-muted-foreground",children:i(n.timestamp)})]})]})]})})})]})}function Fb(e){var t;let{request:s}=e;const{app:a}=Nt(),n=e=>e?ra()(e).fromNow():"";return(0,le.jsxs)(Fx,{className:"border rounded overflow-hidden hover:shadow-sm transition-all duration-200",children:[(0,le.jsxs)(Bx,{className:"flex w-full p-2 hover:bg-accent/5 text-left",children:[(0,le.jsx)("div",{className:"flex-shrink-0 w-16 flex justify-center",children:(0,le.jsx)(es,{variant:"outline",className:Pe("font-mono text-xs",(e=>{switch(e){case"GET":return"bg-blue-50 text-blue-700";case"POST":return"bg-green-50 text-green-700";case"PUT":return"bg-amber-50 text-amber-700";case"DELETE":return"bg-rose-50 text-rose-700";default:return"bg-slate-100 text-slate-700"}})(s.method)),children:null===(t=s.method)||void 0===t?void 0:t.toLowerCase()})}),(0,le.jsx)("div",{className:"flex-grow mx-3",children:(0,le.jsx)("div",{className:"text-sm font-normal truncate",children:(e=>{let t=e;return e.startsWith("http")&&(t=new URL(e).pathname),t.startsWith("/api/apps/"+(null==a?void 0:a.id))&&(t=t.replace("/api/apps/"+a.id,"")),null!=a&&a.id&&t.includes(a.id)&&(t=t.replace(a.id,"{app_id}")),t})(s.url)})}),(0,le.jsxs)("div",{className:"flex items-center gap-2 shrink-0",children:[(0,le.jsx)("div",{className:"text-xs text-muted-foreground text-right",children:n(s.startTime)}),(0,le.jsxs)(es,{variant:"outline",className:Pe("flex items-center",(l=s.status,r=s.statusCode,"pending"===l?"bg-slate-100 text-slate-700":r>=200&&r<300?"bg-emerald-50 text-emerald-700":"bg-rose-50 text-rose-700")),children:[((e,t)=>"pending"===e?(0,le.jsx)(Ne.A,{className:"h-3.5 w-3.5 animate-spin"}):t>=200&&t<300?(0,le.jsx)(Vg.A,{className:"h-3.5 w-3.5"}):(0,le.jsx)(_e.A,{className:"h-3.5 w-3.5"}))(s.status,s.statusCode),"completed"===s.status&&s.statusCode]}),(0,le.jsx)(Is.A,{className:"h-3.5 w-3.5 text-muted-foreground"})]})]}),(0,le.jsx)(zx,{children:(0,le.jsx)("div",{className:"p-4 border-t bg-slate-50/50",children:(0,le.jsxs)(kr,{defaultValue:"general",children:[(0,le.jsxs)(Cr,{className:"mb-3",children:[(0,le.jsx)(Ar,{value:"general",children:"General"}),(0,le.jsx)(Ar,{value:"request",children:"Request"}),"completed"===s.status&&(0,le.jsx)(Ar,{value:"response",children:"Response"})]}),(0,le.jsxs)(Sr,{value:"general",className:"space-y-3",children:[(0,le.jsxs)("div",{children:[(0,le.jsx)("p",{className:"text-sm font-medium",children:"URL"}),(0,le.jsx)("p",{className:"text-sm text-muted-foreground break-all",children:s.url})]}),(0,le.jsxs)("div",{className:"grid grid-cols-2 gap-3",children:[(0,le.jsxs)("div",{children:[(0,le.jsx)("p",{className:"text-sm font-medium",children:"Method"}),(0,le.jsx)("p",{className:"text-sm text-muted-foreground",children:s.method})]}),(0,le.jsxs)("div",{children:[(0,le.jsx)("p",{className:"text-sm font-medium",children:"Status"}),(0,le.jsx)("p",{className:"text-sm text-muted-foreground",children:"completed"===s.status?"".concat(s.statusCode," (").concat(s.duration,"ms)"):(0,le.jsxs)("span",{className:"flex items-center",children:[(0,le.jsx)(Ne.A,{className:"h-3 w-3 mr-1 animate-spin"}),"Pending"]})})]})]}),(0,le.jsxs)("div",{children:[(0,le.jsx)("p",{className:"text-sm font-medium",children:"Time"}),(0,le.jsxs)("p",{className:"text-sm text-muted-foreground",children:["Started: ",n(s.startTime),s.endTime&&(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)("br",{}),"Completed: ",n(s.endTime)]})]})]})]}),(0,le.jsx)(Sr,{value:"request",children:s.body?(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsx)("p",{className:"text-sm font-medium",children:"Request Data"}),(0,le.jsx)("pre",{className:"p-3 rounded bg-white text-xs overflow-auto max-h-60 border",children:"object"==typeof s.body?JSON.stringify(s.body,null,2):s.body})]}):(0,le.jsx)("p",{className:"text-sm text-muted-foreground",children:"No request data"})}),"completed"===s.status&&(0,le.jsx)(Sr,{value:"response",children:s.response?(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsx)("p",{className:"text-sm font-medium",children:"Response Data"}),(0,le.jsx)("pre",{className:"p-3 rounded bg-white text-xs overflow-auto max-h-60 border",children:"object"==typeof s.response?JSON.stringify(s.response,null,2):s.response})]}):(0,le.jsx)("p",{className:"text-sm text-muted-foreground",children:"No response data"})})]})})})]});var l,r}function Bb(){const{activeRequests:e}=lr(),[t,s]=(0,Y.useState)(!1);return(0,le.jsxs)(tp,{open:t,onOpenChange:s,children:[(0,le.jsx)(sp,{asChild:!0,children:(0,le.jsxs)("button",{className:"relative flex items-center justify-center p-1.5 text-gray-500 hover:bg-gray-200 rounded-md transition-colors","aria-label":"Network Activity",children:[(0,le.jsx)(Ob.A,{className:Pe("h-5 w-5",e>0?"text-primary animate-pulse":"text-muted-foreground")}),e>0&&(0,le.jsx)("span",{className:"absolute -top-1 -right-1 flex items-center justify-center w-5 h-5 text-[10px] font-medium bg-primary/15 text-primary rounded-full animate-[pulse_1.5s_ease-in-out_infinite]",children:e})]})}),(0,le.jsx)(ip,{side:"right",className:"min-w-[600px]",children:(0,le.jsx)(Mb,{onClose:()=>s(!1)})})]})}var zb=s(72420),Ub=s(4084),Wb=s(41186);function qb(e){let{isOpen:t,onClose:s}=e;const{user:a}=oe(),{app:n}=Nt(),[l,r]=(0,Y.useState)(!1),[i,o]=(0,Y.useState)(""),[c,d]=(0,Y.useState)("update"),[m,u]=(0,Y.useState)([]),[x,h]=(0,Y.useState)(!1),[p,g]=(0,Y.useState)(!1),[f,v]=(0,Y.useState)(""),b=(0,Y.useRef)(null),j=(0,Y.useRef)(null),y=(0,Y.useRef)(null),[N,w]=(0,Y.useState)(null),[_,k]=(0,Y.useState)((null==n?void 0:n.github_repo_url)||null),[C,A]=(0,Y.useState)(""),[S,E]=(0,Y.useState)(0),[I,T]=(0,Y.useState)(!1),P=mx(a);(0,Y.useEffect)(()=>{"invite"===c&&y.current&&y.current.focus()},[c]),(0,Y.useEffect)(()=>{if(i.includes("@")||i.includes("."))return v("GitHub usernames cannot contain @ or . characters"),u([]),void g(!1);if(v(""),i.trim().length>=2){b.current&&clearTimeout(b.current);const e=Date.now()-S,t=1e3;if(i.trim()===C)return void g(m.length>0);h(!0);const s=e{L(i),A(i.trim()),E(Date.now())},s)}else u([]),g(!1);return()=>{b.current&&clearTimeout(b.current)}},[i,null==n?void 0:n.id,C,S,m.length]);const L=async e=>{try{h(!0);const t=await Ue.searchGithubUsers(n.id,e);u(t.users||[]),g(t.users&&t.users.length>0)}catch(t){}finally{h(!1)}};return(0,le.jsx)(Pa,{open:t,onOpenChange:s,children:(0,le.jsxs)(Da,{className:"sm:max-w-[500px]",children:[(0,le.jsxs)(Fa,{children:[(0,le.jsxs)(za,{className:"flex items-center gap-2",children:[(0,le.jsx)(Ub.A,{className:"h-5 w-5"}),"GitHub Integration"]}),(0,le.jsx)(Ua,{children:null!=n&&n.github_repo_url?"Manage your GitHub repository and collaborators":"Export your app to GitHub to collaborate with others"})]}),(()=>{if(!N)return null;const e="success"===N.type?"bg-green-50 border-green-200":"error"===N.type?"bg-red-50 border-red-200":"bg-blue-50 border-blue-200",t="success"===N.type?"text-green-700":"error"===N.type?"text-red-700":"text-blue-700",s="success"===N.type?Vg.A:"error"===N.type?_e.A:null;return(0,le.jsxs)("div",{className:"flex items-center gap-2 p-3 my-3 rounded-md border ".concat(e),children:[s&&(0,le.jsx)(s,{className:"h-5 w-5 ".concat(t)}),(0,le.jsx)("p",{className:"text-sm ".concat(t),children:N.text})]})})(),P?_?(0,le.jsxs)("div",{className:"space-y-4 py-2",children:[(0,le.jsxs)("div",{className:"rounded-lg bg-muted p-3 mb-4",children:[(0,le.jsx)("p",{className:"text-sm font-medium mb-1",children:"Repository URL:"}),(0,le.jsx)("a",{href:_,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-blue-500 hover:underline break-all",children:_})]}),I&&(0,le.jsxs)("div",{className:"rounded-lg bg-blue-50 border border-blue-200 p-4 mb-4",children:[(0,le.jsx)("h3",{className:"text-sm font-medium text-blue-800 mb-1",children:"Important Next Step"}),(0,le.jsx)("p",{className:"text-sm text-blue-700",children:"To access this repository directly from your GitHub account, you need to invite yourself as a collaborator."}),(0,le.jsxs)(Yt,{variant:"outline",className:"mt-3 border-blue-300 hover:bg-blue-100 text-blue-800",onClick:()=>{o(a.github_username||""),d("invite")},children:[(0,le.jsx)(nv.A,{className:"h-4 w-4 mr-2"}),"Invite Yourself as Collaborator",(0,le.jsx)(ha.A,{className:"h-4 w-4 ml-2"})]})]}),(0,le.jsxs)(kr,{defaultValue:"update",value:c,onValueChange:d,children:[(0,le.jsxs)(Cr,{className:"grid w-full grid-cols-2",children:[(0,le.jsx)(Ar,{value:"update",children:"Update Repository"}),(0,le.jsx)(Ar,{value:"invite",children:"Invite Collaborator"})]}),(0,le.jsxs)(Sr,{value:"update",className:"space-y-4 pt-4",children:[(0,le.jsx)("p",{className:"text-sm text-muted-foreground",children:"Push the latest changes from your app to the GitHub repository."}),(0,le.jsx)(Yt,{onClick:async()=>{try{r(!0),w({type:"loading",text:"Updating GitHub repository..."});const e=await Ue.updateGithubRepo(n.id);e&&e.repository_url&&k(e.repository_url),w({type:"success",text:"Successfully updated GitHub repository"})}catch(i){var e,t,s,a,l;if(null!==(e=i.response)&&void 0!==e&&null!==(t=e.data)&&void 0!==t&&null!==(s=t.message)&&void 0!==s&&s.includes("nothing to commit, working tree clean"))w({type:"success",text:"Repository is already up to date. No changes to commit."});else w({type:"error",text:"Failed to update GitHub repository: "+((null===(a=i.response)||void 0===a||null===(l=a.data)||void 0===l?void 0:l.message)||i.message||"Unknown error")})}finally{r(!1)}},className:"w-full",disabled:l,children:l?"Updating...":"Update Repository"})]}),(0,le.jsxs)(Sr,{value:"invite",className:"space-y-4 pt-4",children:[(0,le.jsxs)("p",{className:"text-sm text-muted-foreground",children:["Invite a collaborator to work on your GitHub repository.",!I&&(0,le.jsx)("span",{className:"block mt-1 font-medium text-blue-600",children:"Don't forget to invite yourself to access the repository directly from your GitHub account."})]}),(0,le.jsxs)("div",{className:"relative",children:[(0,le.jsxs)("div",{className:"flex space-x-2",children:[(0,le.jsxs)("div",{className:"relative flex-1",children:[(0,le.jsx)(fs,{ref:y,placeholder:"Enter GitHub username",value:i,onChange:e=>o(e.target.value),disabled:l,onFocus:()=>i.trim().length>=2&&!f&&g(!0)}),x&&(0,le.jsx)("div",{className:"absolute right-3 top-1/2 transform -translate-y-1/2",children:(0,le.jsx)(vn.A,{className:"h-4 w-4 animate-pulse text-muted-foreground"})})]}),(0,le.jsx)(Yt,{onClick:async()=>{if(i.trim())try{r(!0),w({type:"loading",text:"Inviting ".concat(i,"...")}),await Ue.inviteCollaborator(n.id,i),w({type:"success",text:"Successfully invited ".concat(i," as a collaborator")}),o(""),T(!1)}catch(s){var e,t;w({type:"error",text:"Failed to invite collaborator: "+((null===(e=s.response)||void 0===e||null===(t=e.data)||void 0===t?void 0:t.message)||s.message||"Unknown error")})}finally{r(!1)}else w({type:"error",text:"Please enter a GitHub username"})},disabled:l||!i.trim()||f,children:l?"Inviting...":"Invite"})]}),f&&(0,le.jsx)("div",{className:"mt-2 text-sm text-red-600 bg-red-50 p-2 rounded-md border border-red-200",children:f}),p&&!f&&(0,le.jsx)("div",{ref:j,className:"absolute z-10 mt-1 w-full max-h-48 overflow-auto bg-background border rounded-md shadow-lg",children:0===m.length?(0,le.jsx)("div",{className:"p-2 text-sm text-muted-foreground",children:"No users found"}):(0,le.jsx)("ul",{children:m.map(e=>(0,le.jsxs)("li",{className:"flex items-center gap-2 p-2 hover:bg-accent cursor-pointer",onClick:()=>{return t=e.username,o(t),void g(!1);var t},children:[(0,le.jsx)("img",{src:e.avatar_url,alt:e.username,className:"w-8 h-8 rounded-full"}),(0,le.jsxs)("div",{children:[(0,le.jsx)("div",{className:"text-sm font-medium",children:e.username}),e.name&&(0,le.jsx)("div",{className:"text-xs text-muted-foreground",children:e.name})]})]},e.username))})})]})]})]})]}):(0,le.jsxs)("div",{className:"space-y-4 py-4",children:[(0,le.jsxs)("div",{className:"rounded-lg bg-muted p-4",children:[(0,le.jsx)("p",{className:"text-sm text-muted-foreground",children:"Export your app to GitHub to enable version control, collaboration, and easier deployment."}),(0,le.jsxs)("p",{className:"text-sm text-muted-foreground mt-2",children:[(0,le.jsx)("strong",{children:"Important:"})," After exporting, you'll need to invite yourself as a collaborator to access the repository directly."]})]}),(0,le.jsx)(Yt,{onClick:async()=>{try{r(!0),w({type:"loading",text:"Exporting to GitHub..."});const e=await Ue.exportToGithub(n.id);k(e.repository_url),w({type:"success",text:"Successfully exported to GitHub"}),T(!0),d("invite")}catch(s){var e,t;w({type:"error",text:"Failed to export to GitHub: "+((null===(e=s.response)||void 0===e||null===(t=e.data)||void 0===t?void 0:t.message)||s.message||"Unknown error")})}finally{r(!1)}},className:"w-full",disabled:l,children:l?"Exporting...":"Export to GitHub"})]}):(0,le.jsx)("div",{className:"space-y-4 py-4",children:(0,le.jsxs)("div",{className:"rounded-lg bg-amber-50 border border-amber-200 p-4",children:[(0,le.jsx)("h3",{className:"text-sm font-medium text-amber-800 mb-1",children:"Upgrade Required"}),(0,le.jsx)("p",{className:"text-sm text-amber-700",children:"GitHub integration is only available on Builder, Pro, Elite and Enterprise plans."}),(0,le.jsx)(J.Link,{to:"/billing",children:(0,le.jsx)(Yt,{variant:"outline",className:"mt-3 border-amber-300 hover:bg-amber-100 text-amber-800",children:"Upgrade Your Plan"})})]})}),(0,le.jsx)(Ba,{children:(0,le.jsx)(Yt,{variant:"outline",onClick:s,children:"Close"})})]})})}function Vb(e){let{isOpen:t,onClose:s}=e;const{user:a}=oe(),{app:n}=Nt(),[l,r]=(0,Y.useState)(!1),[i,o]=(0,Y.useState)(null),c=mx(a);return(0,le.jsx)(Pa,{open:t,onOpenChange:s,children:(0,le.jsxs)(Da,{className:"sm:max-w-[500px]",children:[(0,le.jsxs)(Fa,{children:[(0,le.jsxs)(za,{className:"flex items-center gap-2",children:[(0,le.jsx)(Wb.A,{className:"h-5 w-5"}),"Export to ZIP"]}),(0,le.jsx)(Ua,{children:"Download your app code as a ZIP file"})]}),(()=>{if(!i)return null;const e="success"===i.type?"bg-green-50 border-green-200":"error"===i.type?"bg-red-50 border-red-200":"bg-blue-50 border-blue-200",t="success"===i.type?"text-green-700":"error"===i.type?"text-red-700":"text-blue-700",s="success"===i.type?Vg.A:"error"===i.type?_e.A:null;return(0,le.jsxs)("div",{className:"flex items-center gap-2 p-3 my-3 rounded-md border ".concat(e),children:[s&&(0,le.jsx)(s,{className:"h-5 w-5 ".concat(t)}),(0,le.jsx)("p",{className:"text-sm ".concat(t),children:i.text})]})})(),c?(0,le.jsxs)("div",{className:"space-y-4 py-4",children:[(0,le.jsxs)("div",{className:"rounded-lg bg-muted p-4",children:[(0,le.jsx)("p",{className:"text-sm text-muted-foreground",children:"Export your app to a ZIP file to download the code for local development or deployment."}),(0,le.jsx)("p",{className:"text-sm text-muted-foreground mt-2",children:"This will include all your app's code and the necessary project structure to run it locally."})]}),null!=a&&a.api_key?(0,le.jsx)("a",{href:(()=>{if(null==n||!n.id||null==a||!a.api_key)return null;const e="/apps/".concat(n.id,"/coding/export-to-zip?api_key=").concat(a.api_key);return"".concat((0,ee.Gt)()).concat(e)})(),download:"".concat((null==n?void 0:n.slug)||"app",".zip"),className:"w-full inline-block",onClick:()=>(o({type:"success",text:"Download started. If it doesn't begin automatically, click the download button again."}),void r(!1)),children:(0,le.jsx)(Yt,{className:"w-full",disabled:l,onClick:()=>{r(!0),o({type:"loading",text:"Initiating download..."}),setTimeout(()=>{r(!1),o({type:"success",text:"Download initiated. Check your downloads folder."})},1e3)},children:l?"Preparing Download...":"Download ZIP"})}):(0,le.jsx)(Yt,{className:"w-full",disabled:!0,children:"Unable to generate download link"})]}):(0,le.jsx)("div",{className:"space-y-4 py-4",children:(0,le.jsxs)("div",{className:"rounded-lg bg-amber-50 border border-amber-200 p-4",children:[(0,le.jsx)("h3",{className:"text-sm font-medium text-amber-800 mb-1",children:"Upgrade Required"}),(0,le.jsx)("p",{className:"text-sm text-amber-700",children:"ZIP file export is only available on Builder, Pro, Elite and Enterprise plans."}),(0,le.jsx)(J.Link,{to:"/billing",children:(0,le.jsx)(Yt,{variant:"outline",className:"mt-3 border-amber-300 hover:bg-amber-100 text-amber-800",children:"Upgrade Your Plan"})})]})}),(0,le.jsx)(Ba,{children:(0,le.jsx)(Yt,{variant:"outline",onClick:s,children:"Close"})})]})})}function Hb(e){let{showFiles:t}=e;const{app:s,currentPage:a}=Nt(),[n,l]=(0,Y.useState)(!1),[r,i]=(0,Y.useState)(null),[o,c]=(0,Y.useState)(!1),[d,m]=(0,Y.useState)(!1);let u=[];if(t&&a){const{name:e,code:t}=a;if(s.layout){u.push("layout");const e=Yb(s,s.layout);u=[...u,...e.map(e=>"components/"+e)]}u.push("pages/"+e);const n=Yb(s,t);u=[...u,...n.map(e=>"components/"+e)],u=[...new Set(u)]}const x=e=>{l(!1),setTimeout(()=>{i(e),l(!0)},150)};return(0,le.jsxs)(le.Fragment,{children:[(0,le.jsxs)(qr,{children:[(0,le.jsx)(Vr,{asChild:!0,children:(0,le.jsx)("button",{className:"p-1.5 text-gray-500 hover:bg-gray-200 rounded-md transition-colors duration-200 flex items-center justify-center",title:"Github & code editing",children:(0,le.jsx)(gf.A,{size:20,className:"text-gray-600"})})}),(0,le.jsxs)(Kr,{align:"end",className:"w-64 border border-gray-200 shadow-lg rounded-lg animate-in fade-in-80",children:[t&&(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)("div",{className:"px-3 py-1 text-[10px] text-gray-500 bg-gray-50 rounded mx-1",children:"FILES USED IN THIS PAGE"}),(0,le.jsx)("div",{className:"max-h-[250px] overflow-y-auto",children:u.map((e,t)=>{const s=e.split("/"),a="layout"===e;let n=s[s.length-1],l=s.slice(0,-1).join("/");return a&&(n="layout",l="Application Layout"),(0,le.jsxs)(Qr,{className:"cursor-pointer flex flex-col items-start px-3 py-1 text-xs text-gray-600 hover:bg-gray-100 rounded-md mx-1 transition-colors",onClick:()=>x(e),children:[(0,le.jsxs)("span",{className:"font-medium",children:[n,".jsx"]}),l&&(0,le.jsx)("span",{className:"text-gray-400 text-[10px] mt-0.5",children:l})]},t)})}),(0,le.jsx)(si,{className:"my-1 bg-gray-200"})]}),(0,le.jsx)(Qr,{asChild:!0,children:(0,le.jsxs)(J.Link,{to:"/apps/".concat(s.id,"/editor/workspace/code"),className:"cursor-pointer flex items-center px-3 py-2 text-sm hover:bg-gray-100 rounded-md mx-1 my-1 transition-colors",children:[(0,le.jsx)(zb.A,{className:"mr-2 h-4 w-4 text-gray-600"}),"See all files"]})}),(0,le.jsx)(si,{className:"my-1 bg-gray-200"}),(0,le.jsx)("div",{className:"px-3 py-1 text-[10px] text-gray-500 bg-gray-50 rounded mx-1",children:"BETA FEATURES"}),(0,le.jsxs)(Qr,{className:"cursor-pointer flex items-center px-3 py-2 text-sm hover:bg-gray-100 rounded-md mx-1 my-1 transition-colors",onClick:()=>c(!0),children:[(0,le.jsx)(Ub.A,{className:"mr-2 h-4 w-4 text-gray-600"}),"Export project to GitHub"]}),(0,le.jsxs)(Qr,{className:"cursor-pointer flex items-center px-3 py-2 text-sm hover:bg-gray-100 rounded-md mx-1 my-1 transition-colors",onClick:()=>m(!0),children:[(0,le.jsx)(Wb.A,{className:"mr-2 h-4 w-4 text-gray-600"}),"Export project as ZIP"]})]})]}),n&&(0,le.jsxs)("div",{className:"fixed inset-0 z-50",children:[(0,le.jsx)("div",{className:"absolute inset-0 bg-black/50",onClick:()=>l(!1)}),(0,le.jsxs)("div",{className:"absolute right-0 h-full w-3/4 bg-white dark:bg-gray-900 shadow-xl flex flex-col",children:[(0,le.jsxs)("div",{className:"flex justify-between items-center p-4 border-b flex-shrink-0",children:[(0,le.jsxs)("h3",{className:"text-lg font-semibold",children:["Code Editor - ",r]}),(0,le.jsx)(Yt,{variant:"ghost",size:"sm",onClick:()=>l(!1),children:"\u2715"})]}),(0,le.jsx)("div",{className:"flex-1 min-h-0",children:(0,le.jsx)(uf,{filepath:r,onSaveOrDiscard:()=>x(r)})})]})]}),(0,le.jsx)(qb,{isOpen:o,onClose:()=>c(!1)}),(0,le.jsx)(Vb,{isOpen:d,onClose:()=>m(!1)})]})}function Yb(e,t){if(!e||!t)return[];const s=Object.keys(e.components||{});if(0===s.length)return[];const a=new Set;const n=function t(n){let l=[];const r=n.split("\n");for(const i of r)if(i.includes("/components/")){const n=i.split("/components/")[1];if(n){const r=n.match(/^([a-zA-Z0-9_/-]+)/);if(r&&r[1]){const n=r[1].trim();if(s.includes(n)&&!a.has(n)){l.push(n),a.add(n);const s=t(e.components[n]);l=[...l,...s]}else{const r=n.split("/").pop();if(s.includes(r)&&!a.has(r)){l.push(r),a.add(r);const s=t(e.components[r]);l=[...l,...s]}}}}}return l}(t);return[...new Set(n)]}const Gb={COPY_LINK:"Copy link",COPIED:"Copied"},$b={TITLE:"Available Domains",MANAGE_BUTTON:"Manage"},Jb={NO_CUSTOM_DOMAINS:"No custom domains configured",MORE_DOMAINS:"more domains"},Zb=e=>{let{url:t,displayUrl:s,copiedUrl:a,onCopy:n}=e;const[l,r]=(0,Y.useState)(!1),i=(0,Y.useRef)(null),o=a===t;(0,Y.useEffect)(()=>()=>{i.current&&clearTimeout(i.current)},[]),(0,Y.useEffect)(()=>{o?(r(!0),i.current&&clearTimeout(i.current),i.current=setTimeout(()=>{r(!1)},2e3)):r(!1)},[o]);return(0,le.jsxs)("div",{className:"group flex items-center justify-between text-sm bg-slate-100 hover:bg-transparent rounded-md",onMouseOut:()=>{r(!1)},children:[(0,le.jsxs)("div",{className:"flex items-center flex-1 overflow-hidden group-hover:bg-slate-200 group-hover:rounded-md py-2 pl-3",children:[(0,le.jsx)(bn.A,{className:"h-4 w-4 mr-2 flex-shrink-0 text-gray-400","data-testid":"globe-icon"}),(0,le.jsx)("a",{href:t,target:"_blank",rel:"noopener noreferrer",className:"text-blue-600 hover:underline truncate",children:s})]}),(0,le.jsxs)("div",{className:"relative",children:[(0,le.jsx)(Fi,{delayDuration:500,children:(0,le.jsxs)(Bi,{children:[(0,le.jsx)(zi,{asChild:!0,children:(0,le.jsx)("button",{onClick:e=>{n(t)},className:"ml-2 p-1 text-gray-500 hover:text-gray-700 rounded-md transition-colors opacity-0 group-hover:opacity-100",children:o?(0,le.jsx)(Ps.A,{className:"h-4 w-4","data-testid":"check-icon"}):(0,le.jsx)(or.A,{className:"h-4 w-4","data-testid":"copy-icon"})})}),(0,le.jsx)(Ui,{side:"top",sideOffset:4,children:(0,le.jsx)("p",{children:Gb.COPY_LINK})})]})}),l&&(0,le.jsx)(Fi,{children:(0,le.jsxs)(Bi,{open:!0,children:[(0,le.jsx)(zi,{asChild:!0,children:(0,le.jsx)("div",{className:"absolute inset-0 pointer-events-none"})}),(0,le.jsx)(Ui,{side:"top",sideOffset:4,children:(0,le.jsx)("p",{children:Gb.COPIED})})]})})]})]})},Kb=e=>{let{publishLink:t,domains:s,appId:a,onManageDomainsClick:n}=e;const l=(0,Z.Zp)(),[r,i]=(0,Y.useState)("");(0,Y.useEffect)(()=>{if(r){const e=setTimeout(()=>{i("")},2e3);return()=>clearTimeout(e)}},[r]);const o=e=>{navigator.clipboard.writeText(e).then(()=>{i(e)}).catch(e=>{})},c=(0,Y.useCallback)(()=>{null==n||n(),l("/apps/".concat(a,"/editor/workspace/domains"))},[n,l,a]);return(0,le.jsxs)("div",{className:"py-4",children:[(0,le.jsxs)("div",{className:"flex items-center justify-between mb-1",children:[(0,le.jsx)("h4",{className:"font-medium text-sm leading-5 text-gray-700",children:$b.TITLE}),(0,le.jsx)(Hn,{variant:"ghost",size:"sm",className:"h-5 px-0 py-0 texwt-xs text-black hover:bg-transparent hover:text-gray-600",onClick:c,children:$b.MANAGE_BUTTON})]}),(0,le.jsxs)("div",{className:"space-y-1",children:[(0,le.jsx)(Zb,{url:t,displayUrl:t.replace(/(https?:\/\/)/,""),copiedUrl:r,onCopy:o},t),s&&s.length>0?s.slice(0,4).map(e=>(0,le.jsx)(Zb,{url:"https://".concat(e.domain),displayUrl:e.domain,copiedUrl:r,onCopy:o},e.domain)):(0,le.jsx)("p",{className:"text-xs text-gray-500",children:Jb.NO_CUSTOM_DOMAINS}),s&&s.length>4&&(0,le.jsxs)("p",{className:"text-xs text-gray-500 pl-1",children:["+",s.length-4," ",Jb.MORE_DOMAINS]})]})]})};const Qb=e=>{let{value:t,showWorkspace:s=!0,onNavigation:a}=e;const n=(0,Z.Zp)(),{app:l}=Nt(),r=function(e){switch(e){case"private_with_login":default:return"Private access (login required)";case"workspace_with_login":return"Workspace access (login required)";case"public_with_login":return"Public access (login required)";case"public_without_login":return"Public access (no login required)"}}(t),i=function(e){switch(e){case"private_with_login":default:return Mt.A;case"workspace_with_login":return Xl.A;case"public_with_login":case"public_without_login":return bn.A}}(t);return(0,le.jsx)("div",{className:"pt-4 pb-1 border-t border-slate-200",children:(0,le.jsxs)("button",{onClick:()=>{null!=l&&l.id&&(null==a||a(),n("/apps/".concat(l.id,"/editor/workspace/overview")))},className:"group w-full flex items-center gap-3 text-left text-sm text-slate-600 hover:text-slate-900 transition-colors",children:[(0,le.jsx)("div",{className:"flex-shrink-0 bg-gray-100 rounded-md p-[5px]",children:(0,le.jsx)(i,{size:16})}),(0,le.jsxs)("div",{className:"flex-1 flex items-center gap-1",children:[(0,le.jsx)("span",{children:r}),(0,le.jsx)(Yc.A,{size:14,className:"opacity-0 group-hover:opacity-100 transition-opacity"})]})]})})},Xb=e=>{var t,s,a;let{appId:n,conversationId:l,source:r,onNavigate:i}=e;const{user:o}=oe(),{suggestions:c,dismissDomainSuggestion:d}=Nt();if(null==c||null===(t=c.domain_suggestion)||void 0===t||!t.api_response||c.domain_suggestion.dismissed||!c.domain_suggestion.api_response.available)return null;const m=(null===(s=c.domain_suggestion)||void 0===s||null===(a=s.api_response)||void 0===a?void 0:a.domain)||"",u=m.length>21?m.substring(0,21)+"...":m;return(0,le.jsx)("div",{className:"pb-3 px-1 w-full",children:(0,le.jsxs)("div",{className:"flex items-center gap-2 px-2.5 py-1.5 rounded-md group transition-colors w-full",style:{borderRadius:"6px",border:"1px solid #D8AD41",background:"linear-gradient(78deg, #FFF 36.7%, #FFF5DF 78.12%)"},children:[(0,le.jsxs)(J.Link,{to:"/apps/".concat(n,"/editor/workspace/domains"),className:"flex items-center justify-between gap-1.5 text-xs text-slate-600 hover:text-slate-900 transition-colors flex-1",onClick:()=>{var e,t,s,a;tt("Domain Suggestion - Clicked",{source:r,domain:null===(e=c.domain_suggestion)||void 0===e||null===(t=e.api_response)||void 0===t?void 0:t.domain,app_id:n}),ht({user_id:(null==o?void 0:o.id)||null,app_id:n||null,conversation_id:l||null},{cta:"domain_suggestion",origin:r,target_route:"domains_page",domain:null===(s=c.domain_suggestion)||void 0===s||null===(a=s.api_response)||void 0===a?void 0:a.domain}),null==i||i()},children:[(0,le.jsx)("span",{className:"font-medium",style:{color:"#724202",fontSize:"12px"},children:u}),(0,le.jsx)("span",{className:"font-medium text-sm",style:{background:"linear-gradient(90deg, #A05200 0%, #C3871E 50%, #A05200 100%)",WebkitBackgroundClip:"text",WebkitTextFillColor:"transparent",backgroundClip:"text"},children:"Get Domain"})]}),(0,le.jsx)("button",{onClick:e=>{e.preventDefault(),e.stopPropagation(),d()},className:"p-0.5 text-slate-400 hover:text-slate-600 rounded transition-colors flex-shrink-0","aria-label":"Dismiss suggestion",children:(0,le.jsx)(Bt.A,{size:12})})]})})};function ej(e){var t;let{isMobile:s=!1,app:a}=e;const{isInSharedWorkspace:n}=Vp(),{user:l}=oe(),[r,i]=(0,Y.useState)(!1),[o,c]=(0,Y.useState)(!1),[d,m]=(0,Y.useState)(null),[u,x]=(0,Y.useState)([]),[h,p]=(0,Y.useState)(!1),[g,f]=(0,Y.useState)(""),[v,b]=(0,Y.useState)(!0),[j,y]=(0,Y.useState)(null),[N,w]=(0,Y.useState)(!1),_=null!=a&&a.slug?fa(a):"";(0,Y.useEffect)(()=>{(r||h)&&null!=a&&a.id&&(async()=>{try{const e=await Ya.filter({app_id:a.id});x(e)}catch(e){}})()},[r,h,null==a?void 0:a.id]),(0,Y.useEffect)(()=>{(async()=>{if(null==a||!a.id||null==a||!a.organization_id)return b(!0),void y(null);try{const e=await xe.checkSensitiveFeaturePermission("publish_app",a.organization_id);b(e.allowed),y(e.restriction_reason)}catch(e){b(!0),y(null)}})()},[null==a?void 0:a.id,null==a?void 0:a.organization_id]),(0,Y.useEffect)(()=>{w(!1)},[v]),(0,Y.useEffect)(()=>{if(g){const e=setTimeout(()=>{f("")},2e3);return()=>clearTimeout(e)}},[g]);const k=e=>{let{url:t,displayUrl:s}=e;const a=g===t;return(0,le.jsxs)("div",{className:"flex items-center justify-between text-sm","data-testid":"domain-item",children:[(0,le.jsxs)("div",{className:"flex items-center flex-1 overflow-hidden",children:[(0,le.jsx)(bn.A,{className:"h-4 w-4 mr-2 flex-shrink-0 text-gray-500"}),(0,le.jsx)("a",{href:t,target:"_blank",rel:"noopener noreferrer",className:"text-blue-600 hover:underline truncate whitespace-break-spaces",children:s})]}),(0,le.jsx)("button",{onClick:()=>(e=>{navigator.clipboard.writeText(e).then(()=>{f(e)}).catch(e=>{})})(t),className:"ml-2 p-1 text-gray-500 hover:bg-gray-100 rounded-md transition-colors",title:"Copy to clipboard",children:a?(0,le.jsx)(Ps.A,{className:"h-4 w-4 text-green-500"}):(0,le.jsx)(or.A,{className:"h-4 w-4"})})]})},C=async()=>{null!=a&&a.id&&(((e,t)=>{try{var s;ht({user_id:(null==l?void 0:l.id)||null,app_id:(null==a?void 0:a.id)||null,conversation_id:(null==a||null===(s=a.conversation)||void 0===s?void 0:s.id)||null},{cta:"publish",origin:e,target_route:t}),tt("User Clicked Publish Button",{user_id:(null==l?void 0:l.id)||null,app_id:a.id,origin:e,target_route:t})}catch(n){}})("publish_modal","publish"),await A())},A=async()=>{try{c(!0),m(null),await ve.deployApp(a.id),tt("App Published",{app_id:a.id,app_name:a.name,has_custom_domains:u.length>0});const e=u.length>0?"https://".concat(u[0].domain):_;window.open(e,"_blank")}catch(e){m(e.message||"Failed to deploy app")}finally{c(!1),s&&p(!1)}};return s?(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(Hn,{size:"tiny",onClick:()=>p(!0),disabled:o,"data-testid":"publish-button",children:"Publish"}),(0,le.jsx)(Pa,{open:h,onOpenChange:p,children:(0,le.jsxs)(Da,{className:"sm:max-w-md",children:[(0,le.jsx)(Fa,{children:(0,le.jsx)(za,{children:"Publish Your App"})}),null!=a&&a.last_deployed_at?(0,le.jsxs)("div",{className:"py-3 text-sm text-gray-600",children:[(0,le.jsx)("p",{className:"mb-2",children:"Publishing will make your current version available at the public link."}),(0,le.jsxs)("p",{className:"mb-2",children:["Last published: ",ra().utc(null==a?void 0:a.last_deployed_at).fromNow()]})]}):(0,le.jsxs)("div",{className:"py-3 text-sm text-gray-600",children:[(0,le.jsx)("p",{className:"mb-2",children:"This will be the first public version of your app."}),(0,le.jsx)("p",{children:"Publishing will make your app accessible to users at the public link."})]}),d&&(0,le.jsx)("div",{className:"py-2 text-sm text-red-600 bg-red-50 border-t border-b border-red-100",children:(0,le.jsxs)("div",{className:"flex items-center",children:[(0,le.jsx)(_e.A,{className:"h-4 w-4 mr-2"}),(0,le.jsx)("p",{children:d})]})}),(0,le.jsxs)("div",{className:"py-3",children:[(0,le.jsx)("h4",{className:"font-medium text-gray-900 mb-2",children:"Available Domains"}),(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsx)(k,{url:_,displayUrl:_.replace(/(https?:\/\/)/,"")}),u.length>0?u.map((e,t)=>(0,le.jsx)("div",{className:"px-1",children:(0,le.jsx)(k,{url:"https://".concat(e.domain),displayUrl:e.domain})},t)):(0,le.jsx)("p",{className:"text-sm text-gray-500",children:"No custom domains configured"})]})]}),(0,le.jsxs)(Ba,{children:[(0,le.jsx)(Hn,{className:"w-full ".concat(v?"bg-gray-900 text-white hover:bg-gray-800":"bg-gray-300 text-gray-500 cursor-not-allowed"),onClick:C,disabled:o||!v,children:o?(0,le.jsxs)("span",{className:"flex items-center justify-center",children:[(0,le.jsx)(Ne.A,{className:"mr-2 h-4 w-4 animate-spin"}),"Publishing..."]}):"Publish App"}),!v&&j&&(0,le.jsx)("div",{className:"text-sm text-red-600 text-center mt-2",children:j})]})]})})]}):v?(0,le.jsx)(St,{children:(0,le.jsxs)(Et,{open:r,children:[(0,le.jsxs)(qr,{open:r,onOpenChange:i,children:[(0,le.jsx)(Vr,{asChild:!0,children:(0,le.jsx)(It,{asChild:!0,children:(0,le.jsx)(Hn,{size:"sm",className:"px-3 py-1 h-[32px] text-white text-sm rounded-md hover:bg-gray-800 transition-colors",disabled:o||!(null!=a&&a.id),children:o?(0,le.jsxs)("span",{className:"flex items-center",children:[(0,le.jsx)(Ne.A,{className:"mr-2 h-3.5 w-3.5 animate-spin"}),"Publishing..."]}):(0,le.jsx)("span",{children:"Publish"})})})}),(0,le.jsx)(Tt,{children:(0,le.jsx)("p",{children:"Publish your app"})}),(0,le.jsxs)(Kr,{align:"end",className:"w-80 p-0 rounded-xl","data-hook":"publish-dropdown-menu-content",children:[(0,le.jsxs)("div",{className:"p-4",children:[(0,le.jsxs)("div",{className:"flex items-center justify-between",children:[(0,le.jsx)("h3",{className:"font-semibold text-gray-900",children:"Publish Your App"}),(null==a?void 0:a.logo_url)&&(0,le.jsx)("img",{src:a.logo_url,alt:"".concat((null==a?void 0:a.name)||"App"," logo"),className:"w-8 h-8 ml-3 rounded-md object-cover border border-black/10 bg-gray-300"})]}),null!=a&&a.last_deployed_at?null:(0,le.jsx)("div",{className:"py-3 text-sm text-gray-600 border-b border-slate-100",children:(0,le.jsx)("p",{children:"This will be the first public version of your app. Publishing will make your app accessible to users at the public link."})}),d&&(0,le.jsx)("div",{className:"py-2 text-sm text-red-600 bg-red-50 border-t border-b border-red-100",children:(0,le.jsxs)("div",{className:"flex items-center",children:[(0,le.jsx)(_e.A,{className:"h-4 w-4 mr-2"}),(0,le.jsx)("p",{children:d})]})}),(0,le.jsx)(Kb,{publishLink:_,domains:u,appId:(null==a?void 0:a.id)||""}),(0,le.jsx)(Xb,{appId:null==a?void 0:a.id,conversationId:null==a||null===(t=a.conversation)||void 0===t?void 0:t.id,source:"publish_dialog",onNavigate:()=>i(!1)}),(0,le.jsx)(Qb,{value:(null==a?void 0:a.public_settings)||"private_with_login",showWorkspace:n,onNavigation:()=>i(!1)}),(0,le.jsx)(zg,{onClosePublish:()=>i(!1)}),(0,le.jsx)("div",{className:"pt-3",children:(0,le.jsx)(Hn,{className:"w-full h-8 bg-gray-900 text-white text-sm rounded-md hover:bg-gray-800 transition-colors py-2",onClick:C,disabled:o,"data-testid":"publish-button",children:o?(0,le.jsxs)("span",{className:"flex items-center justify-center",children:[(0,le.jsx)(Ne.A,{className:"mr-2 h-4 w-4 animate-spin"}),"Publishing..."]}):"Publish App"})})]}),(null==a?void 0:a.last_deployed_at)&&(0,le.jsx)("div",{className:"text-center",children:(0,le.jsxs)("p",{className:"text-xs bg-slate-100 py-[6px] font-normal leading-4 text-center text-[var(--text-muted,#71717A)]",children:["Last published ",ra().utc(a.last_deployed_at).fromNow()]})})]})]}),(0,le.jsx)(Tt,{children:(0,le.jsx)("p",{children:"Publish app and open in new tab"})})]})}):(0,le.jsxs)("div",{className:"relative",children:[(0,le.jsx)("div",{className:"px-3 py-1 bg-gray-300 text-gray-500 cursor-not-allowed text-sm rounded-md h-8 inline-flex items-center justify-center border border-gray-300",onClick:e=>e.preventDefault(),onMouseEnter:()=>w(!0),onMouseLeave:()=>w(!1),title:j||"Publishing is currently disabled",children:(0,le.jsx)("span",{children:"Publish"})}),N&&(0,le.jsxs)("div",{className:"absolute bottom-full left-1/2 transform -translate-x-1/2 mb-2 px-3 py-2 bg-gray-900 text-white text-sm rounded-md shadow-lg z-50 whitespace-nowrap",children:[j||"Publishing is currently disabled",(0,le.jsx)("div",{className:"absolute top-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-l-4 border-r-4 border-t-4 border-l-transparent border-r-transparent border-t-gray-900"})]})]})}var tj=s(53980),sj=s(74874),aj=s(55064),nj=s(27304);const lj=()=>{var e;const{user:t}=oe(),{app:s,refreshApp:a}=Nt(),{toast:n}=nn(),[l,r]=(0,Y.useState)(!1),i=null==t||null===(e=t.feature_flags)||void 0===e?void 0:e.includes("sandbox-migration-button");return!1===(null==s?void 0:s.using_sandbox)&&i?(0,le.jsx)("div",{className:"flex items-center gap-1.5 ml-2",children:(0,le.jsx)(St,{delayDuration:200,disableHoverableContent:!0,children:(0,le.jsxs)(Et,{children:[(0,le.jsx)(It,{asChild:!0,children:(0,le.jsx)(Yt,{onClick:async()=>{if(null!=s&&s.id){tt("Sandbox Migration - Clicked",{app_id:s.id}),r(!0);try{const e=await gu.migrateToSandbox(s.id);if(e&&!1===e.success)return void n({title:"Upgrade failed",description:e.error||"Failed to migrate app.",variant:"destructive"});tt("Sandbox Migration - Completed",{app_id:s.id}),n({title:"Upgrade successful",description:"App engine updated successfully"}),await a()}catch(e){n({title:"Upgrade failed",description:e.message||"An error occurred during upgrade",variant:"destructive"})}finally{r(!1)}}},disabled:l,variant:"outline",className:"group border-0 font-base44 relative h-8 px-3.5 bg-gray-100 text-black font-medium text-sm rounded-[8px] shadow-sm hover:shadow transition-all duration-200 disabled:opacity-50 disabled:cursor-not-allowed",children:l?(0,le.jsxs)("span",{className:"flex items-center gap-2",children:[(0,le.jsx)(Ne.A,{className:"h-3.5 w-3.5 animate-spin"}),(0,le.jsx)("span",{children:"Switch to the new infrastructure"})]}):(0,le.jsxs)("span",{className:"flex items-center gap-2",children:[(0,le.jsx)(nj.A,{className:"h-3.5 w-3.5"}),(0,le.jsx)("span",{children:"Switch to the new infrastructure"})]})})}),(0,le.jsx)(Tt,{side:"bottom",className:"max-w-md bg-black text-white border-slate-700 shadow-2xl p-4 font-base44",sideOffset:8,children:(0,le.jsxs)("div",{className:"space-y-2.5",children:[(0,le.jsx)("div",{className:"flex items-start gap-1",children:(0,le.jsx)("span",{className:"text-sm font-semibold leading-relaxed text-slate-100 ",children:"Move Your App to the New infrastructure (Recommended)"})}),(0,le.jsx)("p",{className:"text-sm leading-relaxed text-slate-200",children:"We've rebuilt Base44's backend to make your published app faster, more stable, and better optimized."}),(0,le.jsxs)("div",{className:"space-y-2 text-[13px] leading-relaxed pt-1 border-t border-slate-700/50",children:[(0,le.jsx)("p",{className:"font-semibold text-white",children:"What's improved:"}),(0,le.jsxs)("ul",{className:"space-y-1.5 text-slate-200",children:[(0,le.jsxs)("li",{className:"flex items-start gap-2",children:[(0,le.jsx)(Ps.A,{className:"h-4 w-4 text-orange-400 flex-shrink-0 mt-0.5"}),(0,le.jsx)("span",{children:"Faster load time"})]}),(0,le.jsxs)("li",{className:"flex items-start gap-2",children:[(0,le.jsx)(Ps.A,{className:"h-4 w-4 text-orange-400 flex-shrink-0 mt-0.5"}),(0,le.jsx)("span",{children:"Smoother publishing and performance"})]}),(0,le.jsxs)("li",{className:"flex items-start gap-2",children:[(0,le.jsx)(Ps.A,{className:"h-4 w-4 text-orange-400 flex-shrink-0 mt-0.5"}),(0,le.jsx)("span",{children:"Greater stability and reliability"})]})]}),(0,le.jsx)("p",{className:"text-slate-300 text-xs pt-1",children:"Switch now \u2014 you will be able to switch back if you want to."})]})]})})]})})}):null},rj=()=>{const{app:e,refreshApp:t}=Nt(),{toast:s}=nn(),[a,n]=(0,Y.useState)(!1);return null!=e&&e.using_sandbox&&null!=e&&e.migrated_to_sandbox?(0,le.jsx)("div",{className:"flex items-center gap-1.5 ml-2",children:(0,le.jsx)(St,{delayDuration:200,disableHoverableContent:!0,children:(0,le.jsxs)(Et,{children:[(0,le.jsx)(It,{asChild:!0,children:(0,le.jsx)(Yt,{onClick:async()=>{if(null!=e&&e.id){tt("Sandbox Migration - Revert Clicked",{app_id:e.id}),n(!0);try{const a=await gu.revertSandboxMigration(e.id);if(a&&!1===a.success)return void s({title:"Revert failed",description:a.error||"Failed to revert engine",variant:"destructive"});tt("Sandbox Migration - Revert Completed",{app_id:e.id}),s({title:"Revert successful",description:"The app engine has been switched back to the previous version"}),await t()}catch(a){s({title:"Revert failed",description:a.message||"An error occurred while reverting",variant:"destructive"})}finally{n(!1)}}},disabled:a,variant:"outline",className:"group border-0 font-base44 relative h-8 px-3.5 bg-gray-100 text-black font-medium text-sm rounded-[8px] shadow-sm hover:shadow transition-all duration-200 disabled:opacity-50 disabled:cursor-not-allowed",children:a?(0,le.jsxs)("span",{className:"flex items-center gap-2",children:[(0,le.jsx)(Ne.A,{className:"h-3.5 w-3.5 animate-spin"}),(0,le.jsx)("span",{children:"Revert infrastructure"})]}):(0,le.jsx)("span",{className:"flex items-center gap-2",children:(0,le.jsx)("span",{children:"Revert infrastructure"})})})}),(0,le.jsx)(Tt,{side:"bottom",className:"max-w-md bg-black text-white border-slate-700 shadow-2xl p-4",sideOffset:8,children:(0,le.jsxs)("div",{className:"space-y-2.5",children:[(0,le.jsx)("div",{className:"flex items-start gap-2",children:(0,le.jsx)("span",{className:"text-sm font-medium leading-relaxed text-slate-100",children:"Revert back to the old Base44 infrastructure"})}),(0,le.jsxs)("div",{className:"space-y-2 text-[13px] leading-relaxed pt-1 border-t border-slate-700/50",children:[(0,le.jsx)("p",{className:"font-semibold text-white",children:"Reverting will:"}),(0,le.jsxs)("ul",{className:"space-y-1.5 text-slate-200",children:[(0,le.jsxs)("li",{className:"flex items-start gap-2",children:[(0,le.jsx)("span",{className:"text-gray-300 font-bold",children:"\u2022"}),(0,le.jsx)("span",{children:"Move your app back to the previous infrastructure"})]}),(0,le.jsxs)("li",{className:"flex items-start gap-2",children:[(0,le.jsx)("span",{className:"text-gray-300 font-bold",children:"\u2022"}),(0,le.jsx)("span",{children:"Restore the original deployment environment"})]})]}),(0,le.jsx)("p",{className:"text-slate-300 text-xs pt-1",children:"You can upgrade to the new engine at any time."})]})]})})]})})}):null};var ij=s(14664),oj=s(225);const cj=e=>{let{view:t,onRefreshClicked:s,isPhoneMode:a,setIsPhoneMode:n}=e;const{app:l}=Nt(),{pageName:r}=(0,Z.g)(),i=(0,Z.Zp)();if("preview"!==t||null==l||!l.pages||0===Object.keys(l.pages).length)return null;const o=Object.keys(l.pages),c=o.find(e=>e.toLowerCase()===(null==r?void 0:r.toLowerCase()))||o.find(e=>{var t;return e.toLowerCase()===(null===(t=l.main_page)||void 0===t?void 0:t.toLowerCase())})||o[0],d=o.length;return(0,le.jsxs)("div",{className:"flex items-center border border-gray-200 bg-white overflow-hidden h-[32px] rounded-[10px]",children:[(0,le.jsx)(Fi,{children:1===d?(0,le.jsx)("div",{className:"h-full w-[160px] px-3 flex items-center text-[14px] text-gray-700 overflow-hidden",children:(0,le.jsx)("span",{className:"truncate",children:c})}):(0,le.jsxs)(Bi,{children:[(0,le.jsx)(zi,{asChild:!0,children:(0,le.jsxs)(In,{value:c,onValueChange:e=>{i("/apps/".concat(l.id,"/editor/preview/").concat(e)),setTimeout(()=>s(),100)},children:[(0,le.jsx)(Pn,{className:"h-full w-[160px] text-xs border-0 focus:ring-0 focus:ring-offset-0",children:(0,le.jsx)("div",{className:"flex items-center gap-2 text-[14px] overflow-hidden",children:(0,le.jsx)(Tn,{placeholder:"Select page",className:"truncate"})})}),(0,le.jsx)(Rn,{className:"max-h-[360px] overflow-y-auto",children:Object.keys(l.pages).map(e=>(0,le.jsx)(Mn,{value:e,className:"text-[14px] [&>span:first-child]:hidden pl-2",children:(0,le.jsx)("div",{className:"flex items-center gap-2 font-base44 font-light text-[14px] cursor-pointer overflow-hidden",children:(0,le.jsx)("span",{className:"truncate",children:e})})},e))})]})}),(0,le.jsx)(Ui,{children:(0,le.jsx)("p",{children:"Select page to preview"})})]})}),(0,le.jsx)("div",{className:"h-[80%] w-px bg-gray-200"}),(0,le.jsxs)("div",{className:"flex items-center px-1 gap-1 bg-white",children:[(0,le.jsxs)(Bi,{children:[(0,le.jsx)(zi,{asChild:!0,children:(0,le.jsx)("button",{onClick:()=>n(!a),className:"p-1 cursor-pointer text-gray-500 hover:bg-gray-100 rounded transition-colors",children:a?(0,le.jsx)(ij.A,{size:16}):(0,le.jsx)(oj.A,{size:16})})}),(0,le.jsx)(Ui,{children:(0,le.jsx)("p",{children:a?"Switch to desktop view":"Switch to mobile view"})})]}),(0,le.jsxs)(Bi,{children:[(0,le.jsx)(zi,{asChild:!0,children:(0,le.jsx)("button",{onClick:s,className:"p-1 cursor-pointer text-gray-500 hover:bg-gray-100 rounded transition-colors",children:(0,le.jsx)(nx.A,{size:16})})}),(0,le.jsx)(Ui,{children:(0,le.jsx)("p",{children:"Refresh preview"})})]})]})]})},dj=e=>{let{view:t}=e;const{app:s}=Nt(),[a,n]=(0,Y.useState)(!1);return(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[(0,le.jsx)(lj,{}),(0,le.jsx)(rj,{}),(0,le.jsxs)(Fi,{children:[(0,le.jsxs)(Bi,{children:[(0,le.jsx)(zi,{asChild:!0,children:(0,le.jsx)(Bb,{})}),(0,le.jsx)(Ui,{children:(0,le.jsx)("p",{children:"Network requests"})})]}),(0,le.jsxs)(Bi,{children:[(0,le.jsx)(zi,{asChild:!0,children:(0,le.jsx)(Hb,{showFiles:"preview"===t})}),(0,le.jsx)(Ui,{children:(0,le.jsx)("p",{children:"Github & code editing"})})]}),(0,le.jsxs)(Bi,{children:[(0,le.jsx)(zi,{asChild:!0,children:(0,le.jsx)(Hn,{onClick:()=>n(!0),variant:"outline",size:"sm",className:"gap-2 h-[32px]",children:"Share"})}),(0,le.jsx)(Ui,{children:(0,le.jsx)("p",{children:"Share app"})})]}),(0,le.jsx)(ej,{app:s})]}),(0,le.jsx)(gp,{isVisible:a,onCancel:()=>n(!1),onInviteSuccess:()=>n(!1)})]})},mj=e=>{var t;let{toggleLeftPanel:s,isLeftPanelHidden:a,view:n,handleViewChange:l,isMobile:r,onRefreshClicked:i,isPhoneMode:o,setIsPhoneMode:c}=e;const{user:d}=oe(),{app:m,suggestions:u,dismissDomainSuggestion:x}=Nt(),h=null==d||null===(t=d.feature_flags)||void 0===t?void 0:t.includes("use-sandbox-from-ui"),p=(null==m?void 0:m.using_sandbox)&&h&&"platform_admin"===(null==d?void 0:d.platform_role);return(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[!r&&(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[(0,le.jsx)(Fi,{children:(0,le.jsxs)(Bi,{children:[(0,le.jsx)(zi,{asChild:!0,children:(0,le.jsx)("button",{onClick:s,className:"p-1.5 text-gray-500 hover:bg-gray-200 rounded-md transition-colors",children:a?(0,le.jsx)(tj.A,{size:16}):(0,le.jsx)(sj.A,{size:16})})}),(0,le.jsx)(Ui,{children:(0,le.jsx)("p",{children:a?"Show chat panel":"Hide chat panel"})})]})}),(0,le.jsx)("div",{className:"h-6 w-[1px] bg-gray-300"})]}),(0,le.jsx)(kp,{value:"preview"===n?"preview":"workspace",onValueChange:l,children:(0,le.jsxs)(Cp,{className:"h-[32px] rounded-[8px]",children:[(0,le.jsx)(Ap,{value:"workspace",className:"h-7 rounded-[8px] cursor-pointer",children:"Dashboard"}),(0,le.jsx)("div",{className:"h-6 w-[2px] bg-gray-100"}),(0,le.jsx)(Ap,{value:"preview",className:"h-7 rounded-[8px] cursor-pointer",children:"Preview"})]})}),!r&&(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)("div",{children:(0,le.jsx)(cj,{view:n,onRefreshClicked:i,isPhoneMode:o,setIsPhoneMode:c})}),p&&(0,le.jsxs)("div",{className:"inline-flex items-center gap-1.5 px-2.5 py-1 bg-gradient-to-r from-teal-50 to-teal-100/50 border border-teal-200 rounded-full ml-2",children:[(0,le.jsx)(aj.A,{className:"h-3.5 w-3.5 text-teal-600"}),(0,le.jsx)("span",{className:"text-xs font-medium text-teal-700",children:"Sandbox Mode"})]})]})]})},uj=e=>{let{onExit:t}=e;const{restoreSelectedCheckpoint:s,isRestoring:a,setSelectedCheckpoint:n}=Nu("restoreSelectedCheckpoint","isRestoring","setSelectedCheckpoint");return(0,le.jsxs)("div",{className:"flex items-center gap-4 py-2",children:[(0,le.jsx)("p",{className:"text-sm font-medium",children:"Viewing checkpoint version"}),(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[(0,le.jsx)(Hn,{variant:"outline",size:"sm",className:"h-8",onClick:s,disabled:a,children:a?(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(kb.A,{className:"mr-2 h-3 w-3 animate-spin"}),"Restoring..."]}):"Restore this version"}),(0,le.jsx)(Hn,{variant:"secondary",size:"sm",className:"h-8",onClick:()=>{n(void 0),null==t||t()},disabled:a,children:"Exit"})]})]})},xj=()=>{const e=(0,Z.Zp)(),t=(0,Z.zy)(),{app:s}=Nt(),a=(0,Y.useMemo)(()=>{if(t.pathname.includes("/workspace/")){const e=t.pathname.split("/workspace/");if(e.length>1){const s=e[1];return t.search?"".concat(s).concat(t.search):s}}return"overview"},[t.pathname,t.search]);return{handleViewChange:t=>{"workspace"===t.toLowerCase()?e("/apps/".concat(s.id,"/editor/workspace/").concat(a)):e("/apps/".concat(s.id,"/editor/preview/").concat(s.main_page))},lastWorkspaceLocation:a}},hj=e=>{let{view:t}=e;const[s,a]=(0,Y.useState)(!1),[n,l]=(0,Y.useState)(!1),[r,i]=(0,Y.useState)(!1),{selectedCheckpoint:o,setSelectedCheckpoint:c}=Nu("selectedCheckpoint","setSelectedCheckpoint");Mx();const d=pj({view:t,isPhoneMode:n,setIsPhoneMode:l,isLeftPanelHidden:r,toggleLeftPannel:()=>i(e=>!e),onVersionsBack:()=>{a(!1)}});return(0,le.jsx)("div",{className:"flex flex-row h-screen bg-slate-50",children:(0,le.jsxs)(Mm,{direction:"horizontal",children:[(0,le.jsx)(Dm,{defaultSize:r?0:24,minSize:r?0:20,maxSize:r?0:40,className:"h-full overflow-hidden relative ".concat(r?"hidden":""),style:{minWidth:r?"0px":"250px"},children:(0,le.jsxs)("div",{className:"flex flex-col h-full",children:[(0,le.jsx)("div",{className:"flex-shrink-0",children:(0,le.jsx)(Ox,{onToggleVersions:()=>a(e=>!e),showVersions:s})}),(0,le.jsx)("div",{className:"flex-1 overflow-y-auto",children:s?(0,le.jsxs)("div",{className:"flex flex-col h-full p-4 overflow-y-auto",children:[(0,le.jsxs)("div",{className:"flex items-center mb-4",children:[(0,le.jsx)(Hn,{variant:"ghost",size:"icon",onClick:()=>{a(!1),c(void 0)},children:(0,le.jsx)(Cd.A,{className:"h-4 w-4"})}),(0,le.jsx)("h2",{className:"text-lg font-semibold ml-2",children:"Version History"})]}),(0,le.jsx)("div",{className:"flex-1 overflow-y-auto",children:(0,le.jsx)(wu,{})})]}):(0,le.jsx)(Tm,{})})]})}),(0,le.jsx)(Fm,{withHandle:!0,className:"group transition-opacity ".concat(r?"hidden":"opacity-0 hover:opacity-100 focus:opacity-100")}),(0,le.jsx)(Dm,{defaultSize:r?100:67,className:"flex-1 overflow-x-auto ".concat(r?"pl-4":""),children:(0,le.jsx)(Lb,{view:t,toolbars:d,isPhoneMode:n})})]})})},pj=e=>{let{view:t,onVersionsBack:s,isPhoneMode:a,setIsPhoneMode:n,isLeftPanelHidden:l,toggleLeftPannel:r}=e;const{handleViewChange:i}=xj(),{refreshPreview:o}=ub(),c=Nu(e=>e.selectedCheckpoint),d={default:{left:(0,le.jsx)(mj,{toggleLeftPanel:r,isLeftPanelHidden:l,view:t,handleViewChange:i,isMobile:!1,onRefreshClicked:o,isPhoneMode:a,setIsPhoneMode:n}),middle:null,right:(0,le.jsx)(dj,{view:t})},checkpoint:{left:null,middle:null,right:(0,le.jsx)(uj,{onExit:()=>{null==s||s()}})}};return c?d.checkpoint:d.default};var gj=s(42390),fj=s(66148);const vj=["className"],bj=["side","header","noOverlay","className","children"],jj=["className","closeButton","actions"],yj=["className"],Nj=["className"],wj=ka.Root,_j=(ka.Trigger,ka.Close,ka.Portal),kj=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,vj);return(0,le.jsx)(ka.Overlay,(0,K.A)((0,K.A)({className:Pe("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",s)},a),{},{ref:t}))});kj.displayName=ka.Overlay.displayName;const Cj=(0,Ee.cva)("fixed z-50 gap-4 bg-background p-6 shadow-lg transition ease-in-out data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:duration-300 data-[state=open]:duration-500",{variants:{side:{top:"inset-x-0 top-0 border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top",bottom:"inset-x-0 bottom-0 border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom",left:"inset-y-0 left-0 h-full w-3/4 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-sm",right:"inset-y-0 right-0 h-full w-3/4 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-sm"}},defaultVariants:{side:"right"}}),Aj=Y.forwardRef((e,t)=>{let{side:s="right",header:a,noOverlay:n=!1,className:l,children:r}=e,i=(0,Se.A)(e,bj);return(0,le.jsxs)(_j,{children:[!n&&(0,le.jsx)(kj,{}),(0,le.jsxs)(ka.Content,(0,K.A)((0,K.A)({ref:t,className:Pe(Cj({side:s}),l)},i),{},{children:[a,"bottom"===s&&(0,le.jsx)("div",{className:"absolute top-2 left-1/2 w-full ",children:(0,le.jsx)("div",{className:"w-[50px] border-2 border-gray-100 translate-x-[-50%]"})}),r]}))]})});Aj.displayName=ka.Content.displayName;const Sj=e=>{let{className:t,closeButton:s,actions:a}=e,n=(0,Se.A)(e,jj);return(0,le.jsxs)("div",{className:Pe("flex flex-row justify-between",t),children:[(0,le.jsx)("div",(0,K.A)({className:"flex flex-col space-y-2 text-center sm:text-left"},n)),(0,le.jsxs)("div",{className:"flex flex-row gap-4 z-5 ring-offset-background transition-opacity opacity-70 hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none cursor-pointer data-[state=open]:bg-secondary items-center",children:[a,!1!==s&&(0,le.jsxs)(ka.Close,{children:[null!=s?s:(0,le.jsx)(Bt.A,{className:"h-6 w-6"}),(0,le.jsx)("span",{className:"sr-only",children:"Close"})]})]})]})};Sj.displayName="SheetHeader";const Ej=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,yj);return(0,le.jsx)(ka.Title,(0,K.A)({ref:t,className:Pe("text-lg font-semibold text-foreground",s)},a))});Ej.displayName=ka.Title.displayName;Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,Nj);return(0,le.jsx)(ka.Description,(0,K.A)({ref:t,className:Pe("text-sm text-muted-foreground",s)},a))}).displayName=ka.Description.displayName;var Ij=s(31628),Tj=s.n(Ij);const Pj=e=>(e.preventDefault(),e.stopPropagation(),!1),Lj=e=>{let{children:t,boundsId:s,onDragging:a,disabled:n}=e;const[l,r]=(0,Y.useState)(!1),[i,o]=(0,Y.useState)();return(0,Y.useEffect)(()=>{null==a||a(l)},[l,a]),(0,Y.useEffect)(()=>()=>{window.removeEventListener("scroll",Pj),window.removeEventListener("touchmove",Pj)},[]),(0,Y.useEffect)(()=>{if(!l&&i){const e=document.documentElement.getBoundingClientRect(),t=Math.abs(i.x);t>1&&to(e=>({x:.9*e.x,y:e.y})),5)}},[l,i]),(0,Y.useEffect)(()=>{n&&i&&Math.max(Math.abs(i.x),Math.abs(i.y))>1&&setTimeout(()=>o(e=>({x:.9*e.x,y:.9*e.y})),5)},[n,i]),(0,le.jsx)(Tj(),{allowAnyClick:!0,allowMobileScroll:!0,bounds:s,defaultClassName:"z-20",disabled:n,onDrag:(e,t)=>{o({x:t.x,y:t.y}),l||setTimeout(()=>r(!0),100)},position:i,onStop:()=>{window.removeEventListener("scroll",Pj),window.removeEventListener("touchmove",Pj),setTimeout(()=>r(!1),0)},onStart:()=>{window.addEventListener("scroll",Pj,{passive:!1}),window.addEventListener("touchmove",Pj,{passive:!1})},children:"function"==typeof t?t({isDragging:l,btnPos:i}):t})},Oj=()=>{const{app:e,currentUsage:t}=Nt(),{logout:s,user:a}=oe(),n=(0,Z.Zp)();return(0,le.jsx)(Ex,{app:e,currentUsage:t,onShareModalOpen:null,onLogout:()=>{s(),n("/login")},user:a})},Rj=()=>{const{app:e}=Nt();return(0,le.jsx)("div",{className:"flex items-center",children:(0,le.jsx)(ej,{app:e,isMobile:!0})})},Mj=e=>{var t;let{onBack:s}=e;const{restoreSelectedCheckpoint:a,setSelectedCheckpoint:n,isRestoring:l,selectedCheckpoint:r,isLoading:i,isSyncingSandboxCheckpoint:o,allCheckpoints:c}=Nu(),[d,m]=(0,Y.useState)(null!==(t=c.findIndex(e=>e.id===(null==r?void 0:r.id)))&&void 0!==t?t:0),u=((e,t)=>{const[s,a]=(0,Y.useState)(e);return(0,Y.useEffect)(()=>{const s=setTimeout(()=>a(e),t);return()=>clearTimeout(s)},[e,t]),s})(d,500),x=d>0,h=d{n(c[u])},[u]);const p=(0,Y.useMemo)(()=>{var e;return null===(e=c[d])||void 0===e?void 0:e.name},[d]);(0,Y.useEffect)(()=>{var e;m(null!==(e=c.findIndex(e=>e.id===(null==r?void 0:r.id)))&&void 0!==e?e:0)},[null==r?void 0:r.id]);const g=l||i||o;return(0,le.jsxs)("div",{className:"flex flex-col w-full",children:[(0,le.jsxs)("div",{className:"flex flex-row gap-2 items-center p-3",children:[(0,le.jsxs)("div",{className:"flex flex-1 flex-row gap-2 items-center",onClick:s,children:[(0,le.jsx)(Cd.A,{width:24,height:16}),(0,le.jsx)("p",{children:"Back"})]}),(0,le.jsx)("div",{className:"flex justify-end items-center",children:(0,le.jsx)(Hn,{size:"tiny",className:"bg-orange-600",disabled:l||!r||g,onClick:a,children:l?"Restoring...":"Restore"})})]}),(0,le.jsx)(ps,{}),(0,le.jsxs)("div",{className:"flex flex-row gap-2 justify-between items-center p-3",children:[(0,le.jsx)(Hn,{disabled:!x||g,size:"icon",variant:"outline",onClick:()=>{m(d-1)},children:(0,le.jsx)(Xs.A,{})}),(0,le.jsx)("div",{className:"flex flex-1 justify-center text-sm text-center ",children:(0,le.jsx)("p",{children:null!=p?p:"Latest"})}),(0,le.jsx)(Hn,{disabled:!h||g,size:"icon",variant:"outline",onClick:()=>{m(d+1)},children:(0,le.jsx)(rn.A,{})})]})]})},Dj=e=>{var t,s,a,n,l;let{view:r}=e;const{app:i}=Nt(),[o,c]=(0,Y.useState)(null),[d,m]=(0,Y.useState)(!1),[u,x]=(0,Y.useState)("chat"),[h,p]=(0,Y.useState)(!1),{selectedCheckpoint:g,setSelectedCheckpoint:f,hasCheckpoints:v}=Nu("selectedCheckpoint","setSelectedCheckpoint","hasCheckpoints");Mx();const b=Bj({view:r,onVersionsBack:()=>{p(!0)}});return(0,Y.useEffect)(()=>{var e,t,s,a,n;const l="processing"===(null===(e=i.status)||void 0===e?void 0:e.state),r=(null===(t=i.conversation)||void 0===t||null===(s=t.messages)||void 0===s?void 0:s.length)<=3;l&&r&&(x("chat"),p(!0)),"processing"===o&&"processing"!==(null===(a=i.status)||void 0===a?void 0:a.state)&&r&&p(!1),c(null===(n=i.status)||void 0===n?void 0:n.state)},[null===(t=i.status)||void 0===t?void 0:t.state,null===(s=i.conversation)||void 0===s||null===(a=s.messages)||void 0===a?void 0:a.length,o]),(0,Y.useEffect)(()=>{null==g?x("chat"):(x("versions"),p(!1))},[g]),(0,le.jsxs)("div",{className:"relative w-full min-h-screen bg-slate-50 rounded-tr-lg rounded-br-lg",children:[(0,le.jsx)("div",{id:"user-app-editor-main-bounds",className:"w-full h-full p-6 pt-14 absolute pointer-events-none"}),(0,le.jsx)("div",{className:"absolute w-full h-full ".concat(d?"opacity-50 pointer-events-none":""," transition-opacity duration-200 ease-in-out"),children:(0,le.jsx)(Lb,{view:r,toolbars:b})}),(0,le.jsx)(Lj,{onDragging:m,boundsId:"#user-app-editor-main-bounds",children:(0,le.jsx)(Hn,{id:"user-app-editor-main-btn",className:Pe("fixed bottom-6 right-6 rounded-xl shadow-lg z-50 bg-gray-900 hover:bg-gray-800 flex items-center gap-2 px-4 ","bg-orange-500 hover:bg-orange-700",{"shadow-[0px_6px_6px_3px_rgba(0,0,0,0.4)]":d},{hidden:"versions"===u}),onClick:()=>{!d&&p(!0)},children:"processing"===(null===(n=i.status)||void 0===n?void 0:n.state)?(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)("div",{className:"h-5 w-5 border-2 border-white border-t-transparent rounded-full animate-spin"}),(0,le.jsx)("span",{className:"text-white text-sm",children:"Processing..."})]}):(0,le.jsx)("span",{className:"text-white text-sm",children:null!=g?"Version History":"Chat to Edit"})})}),(0,le.jsx)(wj,{open:["chat","versions"].includes(u)&&h,onOpenChange:e=>{p(e),!e&&x("chat")},children:(0,le.jsx)(Aj,{side:"bottom",className:Pe("fixed bottom-0 w-full flex flex-col h-[95%] transition-all duration-300 ease-in-out p-0 gap-0 rounded-t-xl",{"h-[80%]":"versions"===u&&null!=g}),header:"chat"===u?(0,le.jsx)(Fj,{onVersionsClicked:()=>x("versions"),onMinimizeClicked:()=>x("miniChat"),hasCheckpoints:v}):(0,le.jsx)(Fj,{children:"Version History"}),children:"chat"===u?(0,le.jsx)("div",{className:"h-[90%]",children:(0,le.jsx)(Tm,{})}):(0,le.jsx)("div",{className:"flex h-[90%] pb-4 px-4",children:(0,le.jsx)("div",{className:"flex-1 overflow-y-auto ",children:(0,le.jsx)(wu,{})})})})}),(0,le.jsx)(wj,{open:"miniChat"===u&&h,onOpenChange:p,children:(0,le.jsx)(Aj,{className:"flex flex-col p-0 gap-0 rounded-t-xl shadow-[0_0_6px_5px_rgba(0,0,0,0.1)] border-grey border-2 ",onOpenAutoFocus:e=>e.preventDefault(),side:"bottom",noOverlay:!0,header:(0,le.jsx)(Fj,{onVersionsClicked:()=>x("versions"),onMaximizeClicked:()=>x("chat"),hasCheckpoints:v}),children:(0,le.jsx)("div",{className:Pe("px-4 pb-4",{"h-5":"processing"===(null===(l=i.status)||void 0===l?void 0:l.state)}),children:(0,le.jsx)(Tm,{minimizedChat:!0})})})})]})},Fj=e=>{var t,s;let{children:a,onVersionsClicked:n,onMinimizeClicked:l,onMaximizeClicked:r,hasCheckpoints:i,className:o}=e;const{app:c}=Nt(),d="processing"===(null===(t=c.status)||void 0===t?void 0:t.state)?"Building your app...":null!==(s=null==c?void 0:c.name)&&void 0!==s?s:"AI App Editor",m=[];return i&&n&&m.push((0,le.jsx)(_u.A,{className:"h-6 w-6 p-1 mx-auto",onClick:n})),r&&m.push((0,le.jsx)(gj.A,{className:"h-6 w-6 p-1 mx-auto",onClick:r})),l&&m.push((0,le.jsx)(fj.A,{className:"h-6 w-6 p-1 mx-auto",onClick:l})),(0,le.jsx)(Sj,{className:Pe("p-4",o),actions:m,children:(0,le.jsx)("div",{className:"flex justify-between items-center",children:(0,le.jsx)("div",{className:"flex items-center justify-start gap-3",children:(0,le.jsx)(Ej,{className:"m-0 text-md text-start",children:null!=a?a:d})})})})},Bj=e=>{let{view:t,onVersionsBack:s}=e;const{refreshPreview:a}=ub(),{selectedCheckpoint:n,setSelectedCheckpoint:l}=Nu("selectedCheckpoint","setSelectedCheckpoint"),{handleViewChange:r}=xj(),i={default:{left:(0,le.jsx)(Oj,{}),middle:(0,le.jsx)(mj,{toggleLeftPanel:()=>{},isLeftPanelHidden:!0,view:t,handleViewChange:r,isMobile:!0,onRefreshClicked:a,isPhoneMode:!1,setIsPhoneMode:()=>{}}),right:(0,le.jsx)(Rj,{})},checkpoint:{left:null,middle:(0,le.jsx)(Mj,{onBack:()=>{l(void 0),null==s||s()}}),right:null,noPadding:!0}};return n?i.checkpoint:i.default},zj=e=>{let{view:t}=e;return Ut()?(0,le.jsx)(Dj,{view:t}):(0,le.jsx)(hj,{view:t})},Uj=e=>{let{view:t}=e;return(0,le.jsx)(yt,{children:(0,le.jsx)(rr,{children:(0,le.jsx)(nr,{children:(0,le.jsx)(mb,{children:(0,le.jsx)(yu,{children:(0,le.jsx)(zj,{view:t})})})})})})};function Wj(){const e=(0,Z.Zp)(),t=(0,Z.zy)(),s=new URLSearchParams(t.search),a=s.get("prompt"),[n,l]=(0,Y.useState)(null);return(0,Y.useEffect)(()=>{!async function(){if(a)try{const t=s.get("app_platform_version"),n={status:{state:"processing",details:"Starting conversation..."}};t&&(n.platform_version=parseInt(t,10));const l=await ve.create(n);e("/apps/".concat(l.id,"/editor/preview"),{state:{initialPrompt:a}})}catch(t){l(t.message||"Error creating app")}else l("No prompt provided")}()},[a,e,s]),n?(0,le.jsx)("div",{className:"flex items-center justify-center h-screen",children:(0,le.jsx)("div",{className:"bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded",children:(0,le.jsx)("span",{children:n})})}):(0,le.jsx)("div",{className:"flex items-center justify-center h-screen",children:(0,le.jsx)("div",{"data-testid":"loading-spinner",className:"animate-spin rounded-full h-12 w-12 border-4 border-gray-300 border-t-blue-600"})})}function qj(e){let{text:t,variant:s="default",disabled:a=!1}=e;return(0,le.jsxs)("div",{className:"flex items-center text-sm ".concat(a?"text-gray-400":"text-gray-900"),children:[(0,le.jsx)("svg",{className:"w-4 h-4 mr-3 flex-shrink-0 ".concat(a?"text-gray-400":"text-teal-600"),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,le.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M5 13l4 4L19 7"})}),(0,le.jsx)("span",{className:"text-left font-light",children:t})]})}function Vj(e){if(!e)return"0";const t=parseInt(e,10);return t>=1e3?"".concat((t/1e3).toFixed(t%1e3==0?0:1),"k"):t.toString()}function Hj(e){return e&&e.endsWith("_yearly")?e.replace("_yearly",""):e}function Yj(e,t){const s=["free","starter","starter_yearly","builder","builder_yearly","pro","pro_yearly","elite","elite_yearly","elite_2","elite_2_yearly","elite_3","elite_3_yearly","elite_4","elite_4_yearly"],a=s.indexOf(null==e?void 0:e.toLowerCase()),n=s.indexOf(null==t?void 0:t.toLowerCase());return n>a&&-1!==a&&-1!==n}function Gj(e,t){const s=["free","starter","starter_yearly","builder","builder_yearly","pro","pro_yearly","elite","elite_yearly","elite_2","elite_2_yearly","elite_3","elite_3_yearly","elite_4","elite_4_yearly"],a=s.indexOf(null==e?void 0:e.toLowerCase()),n=s.indexOf(null==t?void 0:t.toLowerCase());return ne&&e.endsWith("_yearly")?e.replace("_yearly",""):e,v=(null==a||null===(t=a.metadata)||void 0===t?void 0:t.monthly_message_limit)||0,b=(null==a||null===(s=a.metadata)||void 0===s?void 0:s.monthly_integration_credits)||0,j=(null==a?void 0:a.nickname)||"";let y=0,N="";const w=(_=null==a?void 0:a.nickname)?_.replace(/\s*(yearly|Yearly)\s*/gi,"").replace(/\s*plan\s*/gi,"").replace(/\s*\.\.\.\s*/g,"").replace(/\s+/g," ").trim():"";var _;j.toLowerCase().includes("starter")?(y=1,N="yearly"===l?"starter_yearly":"starter"):j.toLowerCase().includes("builder")?(y=2,N="yearly"===l?"builder_yearly":"builder"):j.toLowerCase().includes("pro")?(y=3,N="yearly"===l?"pro_yearly":"pro"):j.toLowerCase().includes("elite 4")||j.toLowerCase().includes("elite4")?(y=7,N="yearly"===l?"elite_4_yearly":"elite_4"):j.toLowerCase().includes("elite 3")||j.toLowerCase().includes("elite3")?(y=6,N="yearly"===l?"elite_3_yearly":"elite_3"):j.toLowerCase().includes("elite 2")||j.toLowerCase().includes("elite2")?(y=5,N="yearly"===l?"elite_2_yearly":"elite_2"):j.toLowerCase().includes("elite")&&(y=4,N="yearly"===l?"elite_yearly":"elite");const k=(()=>{var e,t;if(!n)return(null==a||null===(e=a.metadata)||void 0===e?void 0:e.features)||"";const s=["starter","builder","pro"],l=f(N),r=s.indexOf(l);if(-1===r)return(null==a||null===(t=a.metadata)||void 0===t?void 0:t.features)||"";let i=[];for(let a=0;a<=r;a++){var o,c;const e=s[a],t=n.find(t=>{let[s,a]=t;return f(s)===e||a.nickname.toLowerCase().includes(e)});if(t&&null!==(o=t[1])&&void 0!==o&&null!==(c=o.metadata)&&void 0!==c&&c.features){const e=t[1].metadata.features.split(",").map(e=>e.trim()).filter(e=>e.length>0);i=[...i,...e]}}return i.filter((e,t,s)=>t===s.findIndex(t=>t.toLowerCase()===e.toLowerCase())).join(",")})(),C=(null==d?void 0:d.toLowerCase())===N,A=Yj(d,N),S=Gj(d,N),E="free"===(null==d?void 0:d.toLowerCase()),I=$j(d,N,l),T=e=>e?e.replace("_yearly",""):"",P=d&&N&&T(d.toLowerCase())===T(N),L=m||!I||u,O=m?"Processing...":u?"Not Available":I?C?"Manage Payments":P?"".concat(w," ").concat("yearly"===l?"Yearly":"Monthly"):S?"Downgrade to ".concat(w):A&&!E?"Upgrade to ".concat(w):"Subscribe to ".concat(w):"Not Available",R="yearly"===l?(a.unit_amount/100/12).toFixed(0):(a.unit_amount/100).toFixed(0),M="yearly"===l?"\u2022 billed annually":"";return(0,le.jsx)(le.Fragment,{children:(0,le.jsxs)("div",{className:"relative",children:[C&&(0,le.jsx)("div",{className:"absolute z-10 -top-[26px] left-1/4 -translate-x-1/2 px-3 py-1 bg-slate-700 text-white text-sm rounded-t-[12px]",children:"Current Plan"}),(0,le.jsxs)("div",{className:"bg-white rounded-[20px] p-6 flex flex-col transition-all duration-300 hover:shadow-xl h-[480px] ".concat(C?"border-2 border-slate-700":j.toLowerCase().includes("pro")&&!u?"border-2 border-orange-300 mb-2":"border-2 border-[#E9E9E9]"),children:[(0,le.jsxs)("div",{className:"mb-5",children:[(0,le.jsxs)("div",{className:"flex items-center justify-between mb-3",children:[(0,le.jsx)("div",{className:"flex items-center gap-2",children:(0,le.jsx)("span",{className:"text-[18px] font-[400] ".concat(!I||u?"text-gray-400":"text-gray-900"),children:w})}),j.toLowerCase().includes("pro")&&!u&&(0,le.jsx)("span",{className:"px-2 py-1 text-sm font-medium bg-[#FFE5DA] text-[#F16727] rounded-[6px]",children:"Recommended"})]}),(0,le.jsxs)("div",{className:"flex items-end mb-2",children:[(0,le.jsx)("span",{className:"text-3xl font-medium ".concat(!I||u?"text-gray-400":"text-gray-900"),children:"$"}),(0,le.jsx)("span",{className:"text-3xl font-medium ".concat(!I||u?"text-gray-400":"text-gray-900"),children:R}),(0,le.jsx)("span",{className:"font-thin ml-1 mb-1 text-[#C1C1C1] text-2xl",children:"/"}),(0,le.jsxs)("span",{className:"font-normal mb-1 text-[#C1C1C1] text-[14px]",children:["mo ",M]})]})]}),(0,le.jsx)("div",{className:"mb-4",children:(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsxs)("div",{className:"text-sm ".concat(!I||u?"text-gray-400":"text-gray-900"),children:[(0,le.jsx)("span",{className:"font-[500] inline-block min-w-[30px]",children:Vj(v)}),(0,le.jsx)("span",{className:"font-[400] text-[#5F5F5F]",children:"Monthly credits"})]}),(0,le.jsxs)("div",{className:"text-sm ".concat(!I||u?"text-gray-400":"text-gray-900"),children:[(0,le.jsx)("span",{className:"font-[500] inline-block min-w-[30px]",children:Vj(b)}),(0,le.jsx)("span",{className:"font-[400] text-[#5F5F5F]",children:"Integration credits"})]})]})}),(0,le.jsxs)("div",{className:"mb-4",children:[!u&&!I&&(0,le.jsxs)("p",{className:"text-xs text-gray-400 mb-2 text-center",children:["Switch to ","yearly"===l?"monthly":"yearly"," billing to access this plan"]}),C?(0,le.jsx)(Yt,{className:"w-full bg-[#F4F4F5] py-2 text-[16px] font-medium shadow-sm hover:bg-gray-50 text-gray-700",onClick:c,children:"Manage Payments"}):(0,le.jsx)(Yt,{className:"w-full py-2 text-[16px] font-medium transition-colors cursor-pointer rounded-[8px] ".concat(!I||u?"bg-gray-100 border border-gray-200 text-gray-400 cursor-not-allowed":S?"bg-white border border-gray-300 hover:bg-gray-50 text-gray-700":A&&!E?j.toLowerCase().includes("pro")?"bg-[#F97316] hover:bg-[#000000] text-white":"bg-white border border-gray-300 hover:bg-gray-50 text-black ":j.toLowerCase().includes("pro")?"bg-[#F97316] hover:bg-[#000000] text-white":"bg-white border border-gray-300 hover:bg-[#F97316] text-black hover:text-white hover:border-white"),onClick:()=>{I&&!u&&(S?g(!0):A&&!E?h(!0):i(a.id))},disabled:L,children:O})]}),(0,le.jsx)("div",{className:"space-y-1 flex-grow",children:null==k?void 0:k.split(",").map((e,t)=>(0,le.jsx)(qj,{text:e.trim(),disabled:!I||u},t))})]}),(0,le.jsx)(Pa,{open:x,onOpenChange:h,children:(0,le.jsxs)(Da,{className:"sm:max-w-md",children:[(0,le.jsxs)(Fa,{children:[(0,le.jsx)(za,{children:"Confirm Subscription Upgrade"}),(0,le.jsxs)(Ua,{children:["You are about to ",P?"switch to":"upgrade to"," the ",w," ",P?"yearly"===l?"yearly":"monthly":"plan"," for $",R,"/mo (",M.toLowerCase(),"). Your subscription will be updated immediately and you'll be charged a prorated amount for the remainder of your billing cycle."]})]}),(0,le.jsxs)(Ba,{className:"sm:justify-between",children:[(0,le.jsx)(Yt,{variant:"outline",onClick:()=>h(!1),className:"text-sm",children:"Cancel"}),(0,le.jsx)(Yt,{onClick:()=>{h(!1),o(a.id)},disabled:m,className:"text-sm bg-teal-600 hover:bg-teal-700",children:m?"Processing...":"Confirm Upgrade"})]})]})}),(0,le.jsx)(Pa,{open:p,onOpenChange:g,children:(0,le.jsxs)(Da,{className:"sm:max-w-md",children:[(0,le.jsxs)(Fa,{children:[(0,le.jsx)(za,{children:"Confirm Subscription Downgrade"}),(0,le.jsxs)(Ua,{children:["You are about to ",P?"switch to":"downgrade to"," the ",w," ",P?"yearly"===l?"yearly":"monthly":"plan"," for $",R,"/mo (",M.toLowerCase(),"). This change will take effect at the end of your current billing cycle."]})]}),(0,le.jsxs)(Ba,{className:"sm:justify-between",children:[(0,le.jsx)(Yt,{variant:"outline",onClick:()=>g(!1),className:"text-sm",children:"Cancel"}),(0,le.jsx)(Yt,{onClick:()=>{g(!1),o(a.id)},disabled:m,className:"text-sm bg-gray-500 hover:bg-gray-600",children:m?"Processing...":"Confirm Downgrade"})]})]})})]})})}function Zj(e){var t,s,a,n,l,r,i,o,c;let{elitePlans:d,allPlans:m,billingPeriod:u="monthly",currentTier:x,subscriptionStatus:h,stripeSubscription:p,isCurrentYearly:g,onSubscribe:f,onUpgrade:v,onManageSubscription:b,upgrading:j=!1,isCurrentlyMonthly:y=!1,isViewingYearly:N=!1}=e;const w=e=>e&&e.endsWith("_yearly")?e.replace("_yearly",""):e,_=()=>"yearly"===u?"elite_yearly":"elite",k=()=>{if(null==x||!x.toLowerCase().includes("elite"))return _();const e=x.toLowerCase(),t=(s=e)&&s.endsWith("_yearly");var s;return"yearly"===u&&!t||"monthly"===u&&t?_():e},[C,A]=(0,Y.useState)(k()),[S,E]=(0,Y.useState)(null),[I,T]=(0,Y.useState)(!1),[P,L]=(0,Y.useState)(!1);(0,Y.useEffect)(()=>{const e=k();A(e)},[u,x]),(0,Y.useEffect)(()=>{const e=d.find(e=>{var t;return(null===(t=e.metadata)||void 0===t?void 0:t.tier)===C});E(e)},[C,d]);const O=(()=>{var e;if(!m||!C)return"";const t=["starter","builder","pro","elite","elite_2","elite_3","elite_4"],s=w(C),a=t.indexOf(s);if(-1===a)return(null==S||null===(e=S.metadata)||void 0===e?void 0:e.features)||"";let n=[];for(let c=0;c<=a;c++){const e=t[c];let s;var l,r,i,o;if(e.startsWith("elite")){if(s=d.find(t=>{var s;return w(null===(s=t.metadata)||void 0===s?void 0:s.tier)===e}),null!==(l=s)&&void 0!==l&&null!==(r=l.metadata)&&void 0!==r&&r.features){const e=s.metadata.features.split(",").map(e=>e.trim()).filter(e=>e.length>0);n=[...n,...e]}}else if(s=m.find(t=>{let[s,a]=t;return w(s)===e||a.nickname.toLowerCase().includes(e)}),s&&null!==(i=s[1])&&void 0!==i&&null!==(o=i.metadata)&&void 0!==o&&o.features){const e=s[1].metadata.features.split(",").map(e=>e.trim()).filter(e=>e.length>0);n=[...n,...e]}}return n.filter((e,t,s)=>t===s.findIndex(t=>t.toLowerCase()===e.toLowerCase())).join(",")})(),R=(null==S||null===(t=S.metadata)||void 0===t?void 0:t.monthly_message_limit)||0,M=(null==S||null===(s=S.metadata)||void 0===s?void 0:s.monthly_integration_credits)||0,D=("active"===(null==p?void 0:p.status)||"past_due"===(null==p?void 0:p.status))&&(null==p||null===(a=p.plan)||void 0===a?void 0:a.id)===(null==S?void 0:S.id),F=Yj(x,C),B="free"===(null==x?void 0:x.toLowerCase()),z=Gj(x,C),U=e=>e?e.replace("_yearly",""):"",W=x&&C&&U(x.toLowerCase())===U(C),q=["elite","elite_2","elite_3","elite_4"].map(e=>({tier:"yearly"===u?(e=>"".concat(e,"_yearly"))(e):e,displayName:e.replace("_"," ").split(" ").map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(" ")})),V=$j(x,C,u),H=e=>{if(!x||"free"===x.toLowerCase())return!0;const t=w(x.toLowerCase()),s=w(e),a=["elite","elite_2","elite_3","elite_4"],n=a.indexOf(t),l=a.indexOf(s);return-1===n||l>=n},G=!H(C),$=q.some(e=>{let{tier:t}=e;return H(t)&&$j(x,t,u)});(0,Y.useEffect)(()=>{if(G&&$){const e=q.filter(e=>{let{tier:t}=e;return H(t)&&$j(x,t,u)});e.length>0&&A(e[0].tier)}},[G,$,x,u,q]);const J="yearly"===u?((null==S?void 0:S.unit_amount)/100/12).toFixed(0):((null==S?void 0:S.unit_amount)/100).toFixed(0),Z="yearly"===u?"\u2022 billed annually":"",K=j||!V||!$,Q=j?"Processing...":$&&V?D?"Manage Payments":W?"".concat((null===(n=q.find(e=>e.tier===C))||void 0===n?void 0:n.displayName)||"Elite"," ").concat("yearly"===u?"Yearly":"Monthly"):z?"Downgrade to ".concat((null===(l=q.find(e=>e.tier===C))||void 0===l?void 0:l.displayName)||"Elite"):F&&!B?"Upgrade to ".concat((null===(r=q.find(e=>e.tier===C))||void 0===r?void 0:r.displayName)||"Elite"):"Subscribe to ".concat((null===(i=q.find(e=>e.tier===C))||void 0===i?void 0:i.displayName)||"Elite"):"Not Available";return(0,le.jsx)(le.Fragment,{children:(0,le.jsxs)("div",{className:"relative",children:[D&&(0,le.jsx)("div",{className:"absolute z-10 -top-[26px] left-1/4 -translate-x-1/2 px-3 py-1 bg-slate-700 text-white text-sm rounded-t-[12px]",children:"Current Plan"}),(0,le.jsxs)("div",{className:"bg-white rounded-[20px] p-6 flex flex-col transition-all duration-300 hover:shadow-xl h-[480px] ".concat(D?"border-2 border-slate-700":"border-2 border-[#E9E9E9]"),children:[(0,le.jsxs)("div",{className:"mb-5",children:[(0,le.jsx)("div",{className:"flex items-center justify-between mb-3",children:(0,le.jsx)("div",{className:"flex items-center gap-2",children:(0,le.jsx)("span",{className:"text-[18px] font-[400] ".concat(V&&$?"text-gray-900":"text-gray-400"),children:"Elite"})})}),(0,le.jsxs)("div",{className:"flex items-end mb-2",children:[(0,le.jsx)("span",{className:"text-3xl font-medium ".concat(V&&$?"text-gray-900":"text-gray-400"),children:"$"}),(0,le.jsx)("span",{className:"text-3xl font-medium ".concat(V&&$?"text-gray-900":"text-gray-400"),children:J}),(0,le.jsx)("span",{className:"font-thin ml-1 mb-1 text-[#C1C1C1] text-2xl",children:"/"}),(0,le.jsxs)("span",{className:"font-normal mb-1 text-[#C1C1C1] text-[14px]",children:["mo ",Z]})]})]}),(0,le.jsx)("div",{className:"-mt-1 mb-2",children:(0,le.jsxs)(zs,{value:C,onValueChange:e=>{A(e)},disabled:!V||!$,children:[(0,le.jsx)(qs,{advancedDropdown:!0,className:"w-full h-auto p-2 ".concat(V&&$?"bg-white border border-gray-200":"bg-gray-100 border border-gray-200 text-gray-400 cursor-not-allowed"),children:(0,le.jsx)("div",{className:"w-full text-left",children:(0,le.jsxs)("div",{className:"w-full flex flex-col gap-1",children:[(0,le.jsxs)("div",{className:"text-sm ".concat(V&&$?"text-gray-900":"text-gray-400"),children:[(0,le.jsx)("span",{className:"font-[500] inline-block min-w-[30px]",children:Vj(R)}),(0,le.jsx)("span",{className:"font-[400] text-[#5F5F5F]",children:"Monthly credits"})]}),(0,le.jsxs)("div",{className:"text-sm ".concat(V&&$?"text-gray-900":"text-gray-400"),children:[(0,le.jsx)("span",{className:"font-[500] inline-block min-w-[30px]",children:Vj(M)}),(0,le.jsx)("span",{className:"font-[400] text-[#5F5F5F]",children:"Integration credits"})]})]})})}),(0,le.jsx)(Ys,{className:"w-[calc(100%-1rem)] max-w-[320px] z-50 p-1.5",sideOffset:4,children:q.filter(e=>{let{tier:t}=e;return H(t)&&$j(x,t,u)}).map(e=>{var t,s;let{tier:a,displayName:n}=e;const l=d.find(e=>{var t;return(null===(t=e.metadata)||void 0===t?void 0:t.tier)===a}),r=(null==l||null===(t=l.metadata)||void 0===t?void 0:t.monthly_message_limit)||0,i=(null==l||null===(s=l.metadata)||void 0===s?void 0:s.monthly_integration_credits)||0;return(0,le.jsx)($s,{value:a,className:"px-4 py-2 border-b border-gray-100 last:border-b-0",hideCheckIcon:!0,children:(0,le.jsxs)("div",{className:"w-full flex flex-col gap-1",children:[(0,le.jsxs)("div",{className:"text-sm leading-[17px] flex items-center gap-1.5 text-gray-900",children:[(0,le.jsx)("span",{className:"font-bold",children:Vj(r)}),(0,le.jsx)("span",{className:"text-gray-500",children:"monthly credits"})]}),(0,le.jsxs)("div",{className:"text-sm leading-[17px] flex items-center gap-1.5 text-gray-900",children:[(0,le.jsx)("span",{className:"font-bold",children:Vj(i)}),(0,le.jsx)("span",{className:"text-gray-500",children:"integration credits"})]})]})},a)})})]})}),(0,le.jsxs)("div",{className:"mb-4",children:[!$&&(0,le.jsx)("p",{className:"text-xs text-gray-400 mb-2 text-center",children:"No Elite yearly plans available for your tier."}),$&&!V&&(0,le.jsxs)("p",{className:"text-xs text-gray-400 mb-2 text-center",children:["Switch to ","yearly"===u?"monthly":"yearly"," billing to access this plan"]}),D?(0,le.jsx)(Yt,{className:"w-full bg-[#F4F4F5] py-2 text-[16px] font-medium shadow-sm hover:bg-gray-50 text-gray-700",onClick:b,children:"Manage Payments"}):(0,le.jsx)(Yt,{className:"w-full py-2 text-[16px] font-medium transition-colors cursor-pointer rounded-[8px] ".concat(V&&$?z?"bg-white border border-gray-300 hover:bg-gray-50 text-gray-700":F&&!B?"bg-white border border-gray-300 hover:bg-gray-50 text-black":"bg-white border border-gray-300 hover:bg-[#F97316] text-black hover:text-white hover:border-white":"bg-gray-100 border border-gray-200 text-gray-400 cursor-not-allowed"),onClick:()=>{V&&$&&(z?L(!0):F&&!B?T(!0):f(S.id))},disabled:K,children:Q})]}),(0,le.jsx)("div",{className:"space-y-1 flex-grow",children:null==O?void 0:O.split(",").map((e,t)=>(0,le.jsx)(qj,{text:e.trim().replace(/_/g," "),disabled:!V||!$},t))})]}),(0,le.jsx)(Pa,{open:I,onOpenChange:T,children:(0,le.jsxs)(Da,{className:"sm:max-w-md",children:[(0,le.jsxs)(Fa,{children:[(0,le.jsx)(za,{children:"Confirm Subscription Upgrade"}),(0,le.jsxs)(Ua,{children:["You are about to ",W?"switch to":"upgrade to"," the ",(null===(o=q.find(e=>e.tier===C))||void 0===o?void 0:o.displayName)||"Elite"," ",W?u:"plan"," for $",J,"/mo","(",Z.toLowerCase(),"). Your subscription will be updated immediately and you'll be charged a prorated amount for the remainder of your billing cycle."]})]}),(0,le.jsxs)(Ba,{className:"sm:justify-between",children:[(0,le.jsx)(Yt,{variant:"outline",onClick:()=>T(!1),className:"text-sm",children:"Cancel"}),(0,le.jsx)(Yt,{onClick:()=>{T(!1),v(S.id)},disabled:j,className:"text-sm bg-teal-600 hover:bg-teal-700",children:j?"Processing...":"Confirm Upgrade"})]})]})}),(0,le.jsx)(Pa,{open:P,onOpenChange:L,children:(0,le.jsxs)(Da,{className:"sm:max-w-md",children:[(0,le.jsxs)(Fa,{children:[(0,le.jsx)(za,{children:"Confirm Subscription Downgrade"}),(0,le.jsxs)(Ua,{children:["You are about to ",W?"switch to":"downgrade to"," the ",(null===(c=q.find(e=>e.tier===C))||void 0===c?void 0:c.displayName)||"Elite"," ",W?u:"plan"," for $",J,"/mo","(",Z.toLowerCase(),"). This change will take effect at the end of your current billing cycle."]})]}),(0,le.jsxs)(Ba,{className:"sm:justify-between",children:[(0,le.jsx)(Yt,{variant:"outline",onClick:()=>L(!1),className:"text-sm",children:"Cancel"}),(0,le.jsx)(Yt,{onClick:()=>{L(!1),v(S.id)},disabled:j,className:"text-sm bg-gray-500 hover:bg-gray-600",children:j?"Processing...":"Confirm Downgrade"})]})]})})]})})}const Kj=()=>(0,le.jsx)("div",{children:(0,le.jsxs)("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-3 lg:gap-4 max-w-full mx-auto px-4",children:[(0,le.jsx)(Cc,{}),(0,le.jsx)(Cc,{}),(0,le.jsx)(Cc,{}),(0,le.jsx)(Cc,{})]})}),Qj=()=>{const{user:e}=oe(),[t,s]=(0,Y.useState)(!1),a=null==e?void 0:e.subscription_schedule_tier,n=(l=a)?l.split("_").map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(" "):"";var l;return(0,le.jsxs)(De,{className:"mb-4 bg-gray-50 border-gray-200 py-3",children:[(0,le.jsx)(Jc._TA,{className:"h-4 w-4 text-gray-500"}),(0,le.jsx)(Fe,{className:"text-gray-800 font-medium text-sm",children:"Pending Subscription Change"}),(0,le.jsxs)(Be,{className:"text-gray-600 text-sm space-y-2",children:[(0,le.jsxs)("div",{children:["You have a subscription change to the ",(0,le.jsx)("span",{className:"font-semibold",children:n})," plan scheduled to take effect at the end of your current billing cycle."]}),(0,le.jsx)("div",{className:"text-xs text-gray-500",children:'Note: To cancel your subscription, first cancel this change, then use "manage payments" to cancel.'}),(0,le.jsx)("div",{className:"flex justify-end pt-1",children:(0,le.jsx)(Yt,{variant:"outline",size:"sm",className:"text-xs px-3 py-1 h-7",onClick:async()=>{try{s(!0),await $o.cancelSchedule(),mi({title:"Success",description:"Subscription schedule cancelled successfully"}),s(!1),setTimeout(()=>{window.location.reload()},2e3)}catch(e){mi({variant:"destructive",title:"Error",description:"Failed to cancel subscription schedule. Please try again later."})}},disabled:t,children:t?"Cancelling...":"Cancel Change"})})]})]})};function Xj(e){let{billingPeriod:t="yearly"}=e;const{user:s}=oe(),[a,n]=(0,Y.useState)(!1),[l,r]=(0,Y.useState)(null),[i,o]=(0,Y.useState)(null),[c,d]=(0,Y.useState)(!0),[m,u]=(0,Y.useState)("yearly"),[x,h]=(0,Y.useState)(!1);(0,Y.useEffect)(()=>{(async()=>{try{const e=await ke.default.getPricingAndSubscription();r(e.pricing),o(e.stripe_subscription),"free"!==s.subscription_tier?u(s.subscription_is_yearly?"yearly":"monthly"):u(t)}catch(e){mi({variant:"destructive",title:"Error",description:"Failed to load billing information"})}finally{d(!1)}})()},[]),(0,Y.useEffect)(()=>{s&&(tt("Package Picker",{}),Nc("package_picker",{user_id:s.id,email:kc()(s.email)})),"free"===s.subscription_tier?u(t):s.subscription_is_yearly||u(t)},[t,s.subscription_tier]);const p=async e=>{try{tt("Hit Subscribe",{}),Nc("checkout_initiated",{email:kc()(s.email),price:20,user_id:s.id});const t=await $o.createCheckoutSession(e),{sessionId:a}=t,n=await(0,Kc.loadStripe)("pk_live_51QK05lD5KgnLQ3Da11GxDxTfiDHUUr9QGgmU8BY0JIRuCUkU01wxJoKJ8wP72hPAS30JxEsTdEJ4puysUKwQn2te00tAMQjxt9");await n.redirectToCheckout({sessionId:a})}catch(t){mi({variant:"destructive",title:"Error",description:"Failed to create checkout session. Please try again later."})}},g=async e=>{try{var t;n(!0);const s=await $o.updateSubscription(e);mi({title:"Subscription Updated",description:(null===(t=s.subscription)||void 0===t?void 0:t.is_downgrade)?"Your subscription has been scheduled to downgrade at the end of your billing cycle.":"Your subscription has been upgraded successfully. Changes will be reflected shortly."}),setTimeout(()=>{window.location.reload()},2e3)}catch(l){var s,a;mi({variant:"destructive",title:"Error",description:(null===(s=l.response)||void 0===s||null===(a=s.data)||void 0===a?void 0:a.detail)||"Failed to update subscription. Please try again later."})}finally{n(!1)}},f=async()=>{try{const e=await $o.createPortalSession();window.location.href=e.url}catch(e){mi({variant:"destructive",title:"Error",description:"Failed to open subscription management. Please try again later."})}},v=null==s?void 0:s.subscription_schedule_id;if(c)return(0,le.jsx)(Kj,{});const b=null==l?void 0:l[m];if(!b)return(0,le.jsx)("div",{className:"flex items-center justify-center min-h-screen",children:(0,le.jsx)("div",{className:"text-center",children:(0,le.jsx)("p",{className:"text-gray-500",children:"Unable to load pricing information"})})});const j=s.subscription_tier,y=j&&!s.subscription_is_yearly,N="yearly"===m,w=(e,t)=>{if(y&&N){const t="".concat(e,"_yearly");return!function(e,t,s){if(!e||"free"===e.toLowerCase())return!0;if(t)return!0;const a=["starter","builder","pro","elite","elite_2","elite_3","elite_4"],n=Hj(e),l=Hj(s),r=a.indexOf(n);return a.indexOf(l)>=r}(j,s.subscription_is_yearly,t)}return!1},_=Object.entries(b),k=_.filter(e=>{let[t,s]=e;return s.nickname.toLowerCase().includes("elite")}).map(e=>{let[t,s]=e;return(0,K.A)((0,K.A)({},s),{},{disabled:w(t),tier:t})}),C=_.filter(e=>{let[t,s]=e;return!s.nickname.toLowerCase().includes("elite")}).map(e=>{let[t,s]=e;return(0,K.A)((0,K.A)({},s),{},{disabled:w(t),tier:t})});return(0,le.jsxs)("div",{children:[v&&(0,le.jsx)(Qj,{}),(0,le.jsx)("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-3 lg:gap-4 max-w-full mx-auto px-4",children:(0,le.jsxs)(le.Fragment,{children:[k.length>0&&(0,le.jsx)("div",{className:"w-full lg:order-1 xl:order-1",children:(0,le.jsx)(Zj,{elitePlans:k,allPlans:_,billingPeriod:m,currentTier:s.subscription_tier,subscriptionStatus:s.subscription_status,stripeSubscription:i,onSubscribe:p,onUpgrade:g,onManageSubscription:f,upgrading:a,isCurrentlyMonthly:y,isViewingYearly:N})}),C.slice().reverse().map((e,t)=>{var n;return(0,le.jsx)("div",{className:"w-full ".concat(e.nickname.toLowerCase().includes("pro")?"lg:order-2 xl:order-2":e.nickname.toLowerCase().includes("builder")?"lg:order-3 xl:order-3":e.nickname.toLowerCase().includes("starter")?"lg:order-4 xl:order-4":""),children:(0,le.jsx)(Jj,{plan:e,allPlans:_,billingPeriod:m,isCurrentPlan:("active"===s.subscription_status||"past_due"===s.subscription_status)&&(null==i||null===(n=i.plan)||void 0===n?void 0:n.id)===e.id,onSubscribe:p,onUpgrade:g,onManageSubscription:f,currentTier:s.subscription_tier,upgrading:a,disabled:e.disabled})},e.id)})]})}),(0,le.jsx)("div",{className:"mt-8 max-w-full mx-auto px-4",children:(0,le.jsx)("div",{className:"bg-gradient-to-tl from-[#FE7F48] via-slate-800 to-slate-800 rounded-xl p-8 text-white",style:{display:"flex",flexDirection:"column",alignItems:"flex-start"},children:(0,le.jsxs)("div",{className:"flex flex-col lg:flex-row items-start lg:items-center justify-between gap-6 w-full",children:[(0,le.jsxs)("div",{className:"flex-1 mr-15",children:[(0,le.jsx)("h3",{className:"text-[32px] font-semibold mb-2",children:"Tailored Plan for Enterprise Teams"}),(0,le.jsx)("p",{className:"text-white mb-4 font-light",children:"Get access to custom plans tailored for your organization's unique requirements"}),(0,le.jsx)(Yt,{className:"bg-white text-slate-800 hover:bg-slate-200 font-medium min-w-[250px] hover:text-black",onClick:()=>h(!0),children:"Contact us"})]}),(0,le.jsx)("div",{className:"flex-1",children:(0,le.jsxs)("div",{className:"space-y-3",children:[(0,le.jsxs)("div",{className:"flex items-center gap-3",children:[(0,le.jsx)("div",{className:"w-5 h-5 bg-orange-500 rounded-full flex items-center justify-center",children:(0,le.jsx)("svg",{className:"w-3 h-3 text-white",fill:"currentColor",viewBox:"0 0 20 20",children:(0,le.jsx)("path",{fillRule:"evenodd",d:"M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z",clipRule:"evenodd"})})}),(0,le.jsx)("span",{className:"text-white font-light",children:"All Business Elite benefits"})]}),(0,le.jsxs)("div",{className:"flex items-center gap-3",children:[(0,le.jsx)("div",{className:"w-5 h-5 bg-orange-500 rounded-full flex items-center justify-center",children:(0,le.jsx)("svg",{className:"w-3 h-3 text-white",fill:"currentColor",viewBox:"0 0 20 20",children:(0,le.jsx)("path",{fillRule:"evenodd",d:"M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z",clipRule:"evenodd"})})}),(0,le.jsx)("span",{className:"text-white font-light",children:"Access to custom plans"})]}),(0,le.jsxs)("div",{className:"flex items-center gap-3",children:[(0,le.jsx)("div",{className:"w-5 h-5 bg-orange-500 rounded-full flex items-center justify-center",children:(0,le.jsx)("svg",{className:"w-3 h-3 text-white",fill:"currentColor",viewBox:"0 0 20 20",children:(0,le.jsx)("path",{fillRule:"evenodd",d:"M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z",clipRule:"evenodd"})})}),(0,le.jsx)("span",{className:"text-white font-light",children:"Dedicated solution architect"})]}),(0,le.jsxs)("div",{className:"flex items-center gap-3",children:[(0,le.jsx)("div",{className:"w-5 h-5 bg-orange-500 rounded-full flex items-center justify-center",children:(0,le.jsx)("svg",{className:"w-3 h-3 text-white",fill:"currentColor",viewBox:"0 0 20 20",children:(0,le.jsx)("path",{fillRule:"evenodd",d:"M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z",clipRule:"evenodd"})})}),(0,le.jsx)("span",{className:"text-white font-light",children:"Tailored account support"})]})]})})]})})}),(0,le.jsx)(zc,{isOpen:x,onClose:()=>h(!1)})]})}function ey(){return(0,le.jsx)("div",{className:"flex justify-center mb-8",children:(0,le.jsxs)("div",{className:"bg-gray-200 animate-pulse p-1 rounded-[6px] inline-flex",children:[(0,le.jsx)("div",{className:"py-1 px-[12px] rounded-[6px] w-20 h-8 bg-gray-300"}),(0,le.jsx)("div",{className:"py-1 px-[12px] rounded-[6px] w-20 h-8 bg-gray-300 ml-1"})]})})}const ty=()=>(0,le.jsxs)("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-3 lg:gap-4 max-w-full mx-auto px-4",children:[(0,le.jsx)(Cc,{}),(0,le.jsx)(Cc,{}),(0,le.jsx)(Cc,{}),(0,le.jsx)(Cc,{})]});function sy(){const{toast:e}=nn(),{user:t}=oe(),{activeWorkspace:s}=ge(),[a,n]=(0,Y.useState)(null),[l,r]=(0,Y.useState)("yearly"),[i,o]=(0,Y.useState)(""),[c,d]=(0,Y.useState)(!1),[m,u]=(0,Y.useState)(!0),x=(0,Y.useRef)(null),h=s&&!s.is_personal;(0,Y.useEffect)(()=>{const e=(null==s?void 0:s.id)||null;null!==x.current&&x.current!==e&&(u(!0),o(""),d(!1),r("monthly")),x.current=e},[null==s?void 0:s.id]),(0,Y.useEffect)(()=>{if(h)return;(async()=>{try{u(!0);const e=await ke.default.getPricingAndSubscription();n(e.pricing)}catch(e){}finally{u(!1)}})()},[h]),(0,Y.useEffect)(()=>{"free"!==t.subscription_tier&&r(t.subscription_is_yearly?"yearly":"monthly")},[t.subscription_tier]),(0,Y.useEffect)(()=>{if(t){"true"===new URLSearchParams(window.location.search).get("success")&&t.email&&(tt("Billing - Purchase",{}),Nc("Purchase",{email:kc()(t.email),price:20,user_id:t.id}))}},[t]);return(0,le.jsxs)("div",{className:"container mx-auto px-2 sm:px-6 lg:px-8 py-6 sm:py-8 min-h-screen flex flex-col max-w-8xl",children:[!h&&!m&&"past_due"===t.stripe_subscription_status&&(0,le.jsxs)("div",{className:"mb-6 p-4 bg-red-50 border border-red-200 rounded-md text-red-800",children:[(0,le.jsxs)("div",{className:"flex items-center justify-between",children:[(0,le.jsxs)("div",{className:"flex items-center",children:[(0,le.jsx)(we.A,{className:"h-5 w-5 mr-2 flex-shrink-0"}),(0,le.jsx)("span",{className:"font-medium",children:"Subscription payment overdue"})]}),(0,le.jsx)(Yt,{onClick:async()=>{try{const e="payment_method_update",t=await $o.createPortalSession(e);window.location.href=t.url}catch(t){e({variant:"destructive",title:"Error",description:"Failed to open payment management. Please try again."})}},variant:"outline",size:"sm",className:"border-red-300 text-red-700 hover:bg-red-100 hover:border-red-400",children:"Update Payment Method"})]}),(0,le.jsx)("p",{className:"text-sm mt-2",children:"Your subscription payment is overdue. Access to some features is currently limited. Please update your payment method to regain full access."})]}),(0,le.jsx)("div",{className:"flex items-center justify-between mb-6",children:(0,le.jsx)("div",{className:"relative",children:(0,le.jsx)("h1",{className:"text-2xl sm:text-3xl md:text-4xl font-bold text-slate-900 mb-4",children:"Plans and Pricing"})})}),!h&&(m?(0,le.jsx)(ey,{}):!m&&a&&!t.subscription_is_yearly&&(0,le.jsx)("div",{className:"flex justify-center mb-10",children:(0,le.jsxs)("div",{className:"bg-[#DFDCD9] p-1 rounded-[6px] inline-flex",children:[(0,le.jsx)("button",{onClick:()=>r("monthly"),className:" py-1 px-[12px] rounded-[6px] text-sm font-medium transition-colors ".concat("monthly"===l?"bg-white text-slate-900 shadow-sm":"text-slate-600 hover:text-slate-900"),children:"Monthly"}),(0,le.jsxs)("button",{onClick:()=>r("yearly"),className:" py-1 px-[12px] rounded-[6px] text-sm font-medium transition-colors ".concat("yearly"===l?"bg-white text-slate-900 shadow-sm":"text-slate-600 hover:text-slate-900"),children:["Yearly",(0,le.jsx)("span",{className:"ml-1 text-teal-700 text-xs font-semibold rounded-full",children:"Save 20%"})]})]})})),h?(0,le.jsxs)("div",{className:"space-y-6",children:[(0,le.jsx)(bc,{}),(0,le.jsx)(mc,{})]}):(0,le.jsxs)("div",{className:"space-y-8",children:[m?(0,le.jsx)(ty,{}):(0,le.jsx)(Xj,{billingPeriod:l}),!m&&(0,le.jsx)("div",{className:"flex justify-end mt-2",children:(0,le.jsxs)("div",{className:"relative group",children:[(0,le.jsx)("button",{type:"button",className:"text-xs text-gray-400 hover:text-gray-600 underline-offset-4 hover:underline",onClick:()=>document.getElementById("coupon-form").classList.toggle("hidden"),children:"Have a coupon code?"}),(0,le.jsx)("div",{id:"coupon-form",className:"hidden absolute right-0 mt-2 bg-white shadow-lg rounded-md p-3 border border-gray-100 z-10 w-64",children:(0,le.jsxs)("form",{onSubmit:async t=>{if(t.preventDefault(),i.trim()){d(!0);try{const t=await fc.addCouponCode(i.trim());e({title:"Success",description:"".concat(t.num_messages," credits added to your account!")}),o("")}catch(n){var s,a;e({variant:"destructive",title:"Error",description:(null===(s=n.response)||void 0===s||null===(a=s.data)||void 0===a?void 0:a.detail)||"Failed to apply coupon code. Please try again."})}finally{d(!1)}}},className:"flex gap-2 items-center",children:[(0,le.jsx)(fs,{type:"text",placeholder:"Enter code",value:i,onChange:e=>o(e.target.value),className:"flex-1 text-xs h-7"}),(0,le.jsx)(Yt,{type:"submit",disabled:c||!i.trim(),variant:"ghost",size:"sm",className:"text-xs h-7 px-2",children:c?"...":"Apply"})]})})]})}),(0,le.jsx)(mc,{})]})]})}var ay=s(85113),ny=s(58799),ly=s(73581),ry=s(2847),iy=s(56473);function oy(e){let{stats:t}=e;const[s,a]=(0,Y.useState)("30days"),[n,l]=(0,Y.useState)(!1);return(0,le.jsxs)(le.Fragment,{children:[(0,le.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4 mb-8",children:[(0,le.jsx)(is,{children:(0,le.jsxs)(ms,{className:"flex items-center p-6",children:[(0,le.jsx)(Xl.A,{className:"w-8 h-8 text-blue-500 mr-4"}),(0,le.jsxs)("div",{children:[(0,le.jsx)("p",{className:"text-sm text-gray-600",children:"Total Users"}),(0,le.jsx)("p",{className:"text-2xl font-bold",children:t.total_users})]})]})}),(0,le.jsx)(is,{children:(0,le.jsxs)(ms,{className:"flex items-center p-6",children:[(0,le.jsx)(sv.A,{className:"w-8 h-8 text-green-500 mr-4"}),(0,le.jsxs)("div",{children:[(0,le.jsx)("p",{className:"text-sm text-gray-600",children:"New Today"}),(0,le.jsx)("p",{className:"text-2xl font-bold",children:t.new_users_today})]})]})}),(0,le.jsx)(is,{children:(0,le.jsxs)(ms,{className:"flex items-center p-6",children:[(0,le.jsx)(ly.A,{className:"w-8 h-8 text-yellow-500 mr-4"}),(0,le.jsxs)("div",{children:[(0,le.jsx)("p",{className:"text-sm text-gray-600",children:"Premium Users"}),(0,le.jsx)("p",{className:"text-2xl font-bold",children:t.paying_users})]})]})})]}),(0,le.jsx)(is,{className:"mb-8",children:(0,le.jsxs)(ms,{className:"p-6",children:[(0,le.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,le.jsx)("h3",{className:"text-lg font-semibold",children:"User Growth"}),(0,le.jsxs)("div",{className:"flex space-x-2",children:[(0,le.jsx)(Yt,{variant:"7days"===s?"default":"outline",size:"sm",onClick:()=>a("7days"),children:"7 Days"}),(0,le.jsx)(Yt,{variant:"30days"===s?"default":"outline",size:"sm",onClick:()=>a("30days"),children:"30 Days"}),(0,le.jsx)(Yt,{variant:"90days"===s?"default":"outline",size:"sm",onClick:()=>a("90days"),children:"90 Days"}),(0,le.jsx)(Yt,{variant:"year"===s?"default":"outline",size:"sm",onClick:()=>a("year"),children:"1 Year"}),(0,le.jsx)(Yt,{variant:"all"===s?"default":"outline",size:"sm",onClick:()=>a("all"),children:"All Time"}),(0,le.jsx)(Yt,{variant:n?"default":"outline",size:"sm",onClick:()=>l(!n),children:n?"Show Today":"Hide Today"})]})]}),(0,le.jsx)("div",{className:"h-[200px] w-full",children:(0,le.jsx)($u.u,{width:"100%",height:"100%",children:(0,le.jsxs)(ry.b,{data:(()=>{if(!t.new_users_by_day)return[];ra()();let e;switch(s){case"7days":e=ra()().subtract(7,"days");break;case"30days":default:e=ra()().subtract(30,"days");break;case"90days":e=ra()().subtract(90,"days");break;case"year":e=ra()().subtract(1,"year");break;case"all":return n?t.new_users_by_day.filter(e=>!ra()(e.date).isSame(ra()(),"day")):t.new_users_by_day}let a=t.new_users_by_day.filter(t=>ra()(t.date).isAfter(e));return n&&(a=a.filter(e=>!ra()(e.date).isSame(ra()(),"day"))),a})(),children:[(0,le.jsx)(Ku.W,{dataKey:"date",tickFormatter:e=>ra()(e).format("MMM DD")}),(0,le.jsx)(Qu.h,{}),(0,le.jsx)(Xu.m,{labelFormatter:e=>ra()(e).format("MMMM DD, YYYY"),formatter:e=>["".concat(e," new users")]}),(0,le.jsx)(iy.N,{type:"monotone",dataKey:"count",stroke:"#2563eb",strokeWidth:2})]})})})]})})]})}function cy(e){let{details:t,selectedUser:s,onUpdateUser:a,loading:n}=e;return t.is_personal?(0,le.jsxs)(le.Fragment,{children:[(0,le.jsxs)("div",{children:[(0,le.jsx)("h3",{className:"mb-2 font-medium",children:"Subscription Tier"}),(0,le.jsxs)(zs,{value:s.subscription_tier,onValueChange:e=>a(s.id,{subscription_tier:e}),disabled:n,children:[(0,le.jsx)(qs,{children:(0,le.jsx)(Ws,{})}),(0,le.jsxs)(Ys,{children:[(0,le.jsx)($s,{value:"free",children:"Free"}),(0,le.jsx)($s,{value:"starter",children:"Starter"}),(0,le.jsx)($s,{value:"builder",children:"Builder"}),(0,le.jsx)($s,{value:"pro",children:"Pro"}),(0,le.jsx)($s,{value:"elite",children:"Elite"}),(0,le.jsx)($s,{value:"enterprise",children:"Enterprise"})]})]})]}),(0,le.jsxs)("div",{className:"bg-gray-50 p-4 rounded-lg space-y-4",children:[(0,le.jsxs)("div",{children:[(0,le.jsx)("h3",{className:"mb-2 font-medium",children:"Stripe Customer ID"}),(0,le.jsx)("p",{className:"text-sm text-gray-600 font-mono",children:t.stripe_customer_id||"-"})]}),(0,le.jsxs)("div",{children:[(0,le.jsx)("h3",{className:"mb-2 font-medium",children:"Stripe Subscription ID"}),(0,le.jsx)("p",{className:"text-sm text-gray-600 font-mono",children:t.stripe_subscription_id||"-"})]}),(0,le.jsxs)("div",{children:[(0,le.jsx)("h3",{className:"mb-2 font-medium",children:"Stripe Subscription Status"}),(0,le.jsx)("p",{className:"text-sm text-gray-600",children:t.stripe_subscription_status||"-"})]})]})]}):(0,le.jsxs)("div",{className:"bg-gray-50 p-4 rounded-lg space-y-4",children:[(0,le.jsxs)("div",{children:[(0,le.jsx)("h3",{className:"mb-2 font-medium",children:"Workspace Role"}),(0,le.jsx)("span",{className:"px-2 py-1 rounded-full text-xs ".concat("owner"===t.user_role?"bg-purple-100 text-purple-800":"admin"===t.user_role?"bg-blue-100 text-blue-800":"bg-gray-100 text-gray-800"),children:t.user_role})]}),(0,le.jsxs)("div",{children:[(0,le.jsx)("h3",{className:"mb-2 font-medium",children:"Seat Status"}),(0,le.jsx)("span",{className:"px-2 py-1 rounded-full text-xs ".concat("assigned"===t.seat_status?"bg-green-100 text-green-800":"bg-orange-100 text-orange-800"),children:"assigned"===t.seat_status?"Assigned":"Viewer"})]}),"assigned"===t.seat_status&&(0,le.jsxs)(le.Fragment,{children:[(0,le.jsxs)("div",{children:[(0,le.jsx)("h3",{className:"mb-2 font-medium",children:"Seat Plan"}),(0,le.jsx)("p",{className:"text-sm text-gray-600",children:t.seat_type_name})]}),(0,le.jsxs)("div",{children:[(0,le.jsx)("h3",{className:"mb-2 font-medium",children:"Seat Number"}),(0,le.jsxs)("p",{className:"text-sm text-gray-600",children:["#",t.seat_id]})]})]})]})}function dy(e){let{selectedUser:t,workspaceDetails:s,onUpdateUser:a,loading:n,loadingStates:l}=e;return t?(0,le.jsxs)("div",{className:"space-y-4",children:[(0,le.jsxs)("div",{children:[(0,le.jsx)("h3",{className:"mb-2 font-medium",children:"Full Name"}),(0,le.jsx)(fs,{type:"text",value:t.full_name||"",onChange:e=>a(t.id,{full_name:e.target.value}),disabled:n})]}),(0,le.jsxs)("div",{children:[(0,le.jsx)("h3",{className:"mb-2 font-medium",children:"Username"}),(0,le.jsx)("p",{className:"text-gray-600",children:t.username||"-"})]}),(0,le.jsxs)("div",{children:[(0,le.jsx)("h3",{className:"mb-2 font-medium",children:"Phone Number"}),(0,le.jsx)(fs,{type:"text",value:t.phone_number||"",onChange:e=>a(t.id,{phone_number:e.target.value}),disabled:n})]}),(0,le.jsxs)("div",{children:[(0,le.jsx)("h3",{className:"mb-2 font-medium",children:"Platform Role"}),(0,le.jsxs)(zs,{value:t.platform_role,onValueChange:e=>a(t.id,{platform_role:e}),disabled:n,children:[(0,le.jsx)(qs,{children:(0,le.jsx)(Ws,{})}),(0,le.jsxs)(Ys,{children:[(0,le.jsx)($s,{value:"user",children:"User"}),(0,le.jsx)($s,{value:"platform_admin",children:"Platform Admin"})]})]})]}),l.workspaces?(0,le.jsx)("div",{className:"bg-gray-50 p-4 rounded-lg",children:(0,le.jsxs)("div",{className:"flex items-center gap-2 text-sm text-gray-500",children:[(0,le.jsx)(Ne.A,{className:"h-4 w-4 animate-spin"}),"Loading workspace details..."]})}):s?(0,le.jsx)(cy,{details:s,selectedUser:t,onUpdateUser:a,loading:n}):null,(0,le.jsxs)("div",{children:[(0,le.jsx)("h3",{className:"mb-2 font-medium",children:"API Key"}),(0,le.jsx)("p",{className:"text-sm text-gray-600 font-mono break-all",children:t.api_key||"-"})]}),(0,le.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,le.jsx)(dm,{id:"beta-tester",checked:t.is_beta_tester||!1,onCheckedChange:e=>a(t.id,{is_beta_tester:e}),disabled:n}),(0,le.jsx)("label",{htmlFor:"beta-tester",className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:"Beta Tester"})]}),(0,le.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,le.jsx)(dm,{id:"user-disabled",checked:t.disabled||!1,onCheckedChange:e=>a(t.id,{disabled:e}),disabled:n}),(0,le.jsx)("label",{htmlFor:"user-disabled",className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:"Disable User Account"})]}),(0,le.jsxs)("div",{children:[(0,le.jsx)("h3",{className:"mb-2 font-medium",children:"Account Status"}),(0,le.jsx)("span",{className:"px-2 py-1 rounded-full text-xs ".concat(t.disabled?"bg-red-100 text-red-800":"bg-green-100 text-green-800"),children:t.disabled?"Disabled":"Active"})]})]}):null}var my=s(82237);const uy=["className","value"],xy=Y.forwardRef((e,t)=>{let{className:s,value:a}=e,n=(0,Se.A)(e,uy);return(0,le.jsx)(my.bL,(0,K.A)((0,K.A)({ref:t,className:Pe("relative h-4 w-full overflow-hidden rounded-full bg-secondary",s)},n),{},{children:(0,le.jsx)(my.C1,{className:"h-full w-full flex-1 bg-primary transition-all",style:{transform:"translateX(-".concat(100-(a||0),"%)")}})}))});function hy(e){let{userUsageStats:t,dateRange:s,onDateRangeChange:a,selectedWorkspace:n,onSwitchToCreditsTab:l,isLoading:r}=e;const[i,o]=(0,Y.useState)(!1),[c,d]=(0,Y.useState)(null),[m,u]=(0,Y.useState)(!1),x=(e,t)=>{d({startDate:e,endDate:t})};return r||!t?(0,le.jsx)("div",{className:"flex items-center justify-center py-12",children:(0,le.jsxs)("div",{className:"text-center",children:[(0,le.jsx)(Ne.A,{className:"h-8 w-8 animate-spin mx-auto mb-4 text-gray-400"}),(0,le.jsx)("p",{className:"text-gray-500",children:"Loading usage statistics..."})]})}):(0,le.jsxs)("div",{className:"space-y-8",children:[(0,le.jsxs)("div",{className:"bg-white rounded-lg shadow p-4",children:[(0,le.jsx)("h3",{className:"text-lg font-semibold mb-2",children:"Current Usage"}),(0,le.jsxs)("div",{className:"space-y-4",children:[(0,le.jsxs)("div",{children:[(0,le.jsxs)("div",{className:"flex justify-between mb-1",children:[(0,le.jsxs)("span",{className:"text-sm font-medium",children:["Monthly Usage: ",t.monthly_usage," / ",t.monthly_limit]}),(0,le.jsxs)("span",{className:"text-sm text-gray-500",children:[Math.round(t.monthly_usage/t.monthly_limit*100),"%"]})]}),(0,le.jsx)(xy,{value:t.monthly_usage/t.monthly_limit*100,className:"h-2",indicatorClassName:t.is_over_limit?"bg-red-500":void 0})]}),t.daily_limit&&(0,le.jsxs)("div",{children:[(0,le.jsxs)("div",{className:"flex justify-between mb-1",children:[(0,le.jsxs)("span",{className:"text-sm font-medium",children:["Daily Usage: ",t.daily_usage," / ",t.daily_limit]}),(0,le.jsxs)("span",{className:"text-sm text-gray-500",children:[Math.round(t.daily_usage/t.daily_limit*100),"%"]})]}),(0,le.jsx)(xy,{value:t.daily_usage/t.daily_limit*100,className:"h-2",indicatorClassName:t.is_over_limit?"bg-red-500":void 0})]})]})]}),t.usage_by_date&&(0,le.jsxs)("div",{className:"bg-white rounded-lg shadow p-6",children:[(0,le.jsxs)("div",{className:"flex justify-between items-center mb-6",children:[(0,le.jsx)("h3",{className:"text-lg font-semibold",children:"Usage History"}),(0,le.jsxs)(Nh,{open:i,onOpenChange:o,children:[(0,le.jsx)(wh,{asChild:!0,children:(0,le.jsxs)(Yt,{variant:"outline",className:"flex items-center gap-2",disabled:m,children:[(0,le.jsx)(bh.A,{className:"h-4 w-4"}),s.startDate&&s.endDate?"".concat(ra()(s.startDate).format("MMM D, YYYY")," - ").concat(ra()(s.endDate).format("MMM D, YYYY")):"Select Date Range"]})}),(0,le.jsx)(_h,{className:"w-auto p-0",align:"end",children:(0,le.jsxs)("div",{className:"p-3 border-b",children:[(0,le.jsx)("h4",{className:"font-medium mb-2",children:"Select Date Range"}),(0,le.jsxs)("div",{className:"grid grid-cols-2 gap-2",children:[(0,le.jsxs)("div",{children:[(0,le.jsx)("label",{className:"text-sm text-gray-600",children:"Start Date"}),(0,le.jsx)(fh,{mode:"single",selected:(null==c?void 0:c.startDate)||s.startDate,onSelect:e=>x(e,(null==c?void 0:c.endDate)||s.endDate),className:"rounded-md border"})]}),(0,le.jsxs)("div",{children:[(0,le.jsx)("label",{className:"text-sm text-gray-600",children:"End Date"}),(0,le.jsx)(fh,{mode:"single",selected:(null==c?void 0:c.endDate)||s.endDate,onSelect:e=>x((null==c?void 0:c.startDate)||s.startDate,e),className:"rounded-md border"})]})]}),(0,le.jsxs)("div",{className:"flex justify-end gap-2 mt-3",children:[(0,le.jsx)(Yt,{variant:"outline",size:"sm",onClick:()=>{if(t){const e=new Date(t.current_credit_period_start_date),s=new Date(t.current_credit_period_end_date);u(!0),a(e,s,n,()=>{u(!1)})}d(null)},children:"Reset"}),(0,le.jsx)(Yt,{size:"sm",onClick:()=>{c&&(u(!0),a(c.startDate,c.endDate,n,()=>{u(!1)})),o(!1)},children:"Apply"})]})]})})]})]}),(0,le.jsx)("div",{className:"h-[300px]",children:(0,le.jsx)(tx,{usageByDate:t.usage_by_date,height:"h-[260px]"})})]}),(0,le.jsx)(is,{children:(0,le.jsxs)(ms,{className:"pt-6 space-y-6",children:[(0,le.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,le.jsxs)("div",{className:"bg-gray-50 p-4 rounded-lg",children:[(0,le.jsx)("h4",{className:"text-sm font-medium text-gray-700 mb-2",children:"Subscription Tier"}),(0,le.jsx)("p",{className:"text-lg font-semibold capitalize",children:t.tier})]}),(0,le.jsxs)("div",{className:"bg-gray-50 p-4 rounded-lg",children:[(0,le.jsx)("h4",{className:"text-sm font-medium text-gray-700 mb-2",children:"Bonus Credits"}),(0,le.jsx)("p",{className:"text-lg font-semibold",children:t.extra_credits})]})]}),(0,le.jsxs)("div",{className:"bg-gray-50 p-4 rounded-lg",children:[(0,le.jsx)("h3",{className:"text-sm font-medium text-gray-700 mb-3",children:"Billing Period"}),(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsxs)("div",{className:"flex justify-between",children:[(0,le.jsx)("span",{className:"font-medium",children:"Start:"}),(0,le.jsx)("span",{children:ra()(t.current_credit_period_start_date).format("MMM DD, YYYY")})]}),(0,le.jsxs)("div",{className:"flex justify-between",children:[(0,le.jsx)("span",{className:"font-medium",children:"End:"}),(0,le.jsx)("span",{children:ra()(t.current_credit_period_end_date).format("MMM DD, YYYY")})]}),(0,le.jsxs)("div",{className:"flex justify-between",children:[(0,le.jsx)("span",{className:"font-medium",children:"Next Start:"}),(0,le.jsx)("span",{children:ra()(t.next_period_start_date).format("MMM DD, YYYY")})]})]})]})]})}),t.is_over_limit&&(0,le.jsxs)("div",{className:"bg-red-50 border border-red-200 text-red-800 px-4 py-3 rounded-lg",children:[(0,le.jsx)("p",{className:"font-medium",children:"User is over their usage limit"}),(0,le.jsx)("p",{className:"text-sm",children:"Consider adding bonus credits or upgrading their subscription tier."})]}),(0,le.jsxs)(Yt,{onClick:l,className:"w-full mt-8",children:[(0,le.jsx)(Au.A,{className:"h-4 w-4 mr-2"}),"Add Bonus Credits"]})]})}function py(e){let{userBonusCredits:t,onAddBonusCredits:s,onDeleteBonusCredit:a,loading:n}=e;const[l,r]=(0,Y.useState)({numMessages:0,reason:""});return(0,le.jsxs)("div",{className:"space-y-6",children:[(0,le.jsx)("h3",{className:"text-lg font-semibold",children:"Bonus Credits"}),t.length>0?(0,le.jsx)("div",{className:"space-y-3 mb-4",children:t.map((e,t)=>(0,le.jsxs)("div",{className:"bg-blue-50 p-3 rounded-md",children:[(0,le.jsxs)("div",{className:"flex justify-between",children:[(0,le.jsxs)("span",{className:"font-medium",children:[e.num_messages," messages"]}),(0,le.jsx)("span",{className:"text-sm text-gray-600",children:ra()(e.created_date).format("MMM DD, YYYY")})]}),(0,le.jsx)("p",{className:"text-sm text-gray-700 mt-1",children:e.reason}),(0,le.jsxs)("div",{className:"flex justify-between items-center mt-1",children:[(0,le.jsxs)("p",{className:"text-xs text-gray-500",children:["Expires: ",ra()(e.expires_date).format("MMM DD, YYYY")]}),(0,le.jsx)(Yt,{variant:"ghost",size:"sm",className:"text-red-500 hover:text-red-700 hover:bg-red-50",onClick:()=>a(e.id),disabled:n,children:(0,le.jsx)(Ip.A,{className:"h-4 w-4"})})]})]},t))}):(0,le.jsx)("p",{className:"text-gray-500 mb-4",children:"No bonus credits found for this user."}),(0,le.jsxs)("div",{className:"bg-gray-50 p-4 rounded-lg",children:[(0,le.jsx)("h4",{className:"font-medium mb-3",children:"Add Bonus Credits"}),(0,le.jsxs)("div",{className:"space-y-3",children:[(0,le.jsxs)("div",{children:[(0,le.jsx)("label",{className:"text-sm text-gray-600",children:"Number of Messages"}),(0,le.jsx)(fs,{type:"number",min:"1",value:l.numMessages,onChange:e=>r((0,K.A)((0,K.A)({},l),{},{numMessages:e.target.value})),disabled:n})]}),(0,le.jsxs)("div",{children:[(0,le.jsx)("label",{className:"text-sm text-gray-600",children:"Reason"}),(0,le.jsx)(fs,{type:"text",value:l.reason,onChange:e=>r((0,K.A)((0,K.A)({},l),{},{reason:e.target.value})),placeholder:"e.g., Promotional offer, Customer support",disabled:n})]}),(0,le.jsxs)(Yt,{onClick:()=>{l.numMessages&&l.reason&&(s(parseInt(l.numMessages),l.reason),r({numMessages:0,reason:""}))},disabled:n||!l.numMessages||!l.reason,className:"w-full",children:[(0,le.jsx)(kt.A,{className:"h-4 w-4 mr-2"}),"Add Credits"]})]})]})]})}function gy(e){let{workspaces:t,selectedWorkspace:s,onWorkspaceChange:a,loading:n,disabled:l=!1}=e;return(0,le.jsxs)("div",{className:"w-full relative",children:[(0,le.jsxs)(zs,{value:s||"",onValueChange:a,disabled:n||l,children:[(0,le.jsx)(qs,{className:"text-sm",children:(0,le.jsx)(Ws,{placeholder:"Select workspace..."})}),(0,le.jsx)(Ys,{children:t.map(e=>(0,le.jsx)($s,{value:e.id,children:(0,le.jsx)("span",{children:e.is_personal?"Personal":e.name})},e.id))})]}),n&&(0,le.jsx)("div",{className:"absolute right-8 top-1/2 transform -translate-y-1/2",children:(0,le.jsx)(Ne.A,{className:"h-4 w-4 animate-spin text-gray-400"})})]})}xy.displayName=my.bL.displayName;const fy={workspaces:!1,usageStats:!1};function vy(e){let{selectedUser:t,onClose:s,onUpdateUser:a,userBonusCredits:n,onAddBonusCredits:l,onDeleteBonusCredit:r,loading:i,userUsageStats:o,onDateRangeChange:c,dateRange:d}=e;const[m,u]=(0,Y.useState)("details"),[x,h]=(0,Y.useState)(d),[p,g]=(0,Y.useState)([]),[f,v]=(0,Y.useState)(null),[b,j]=(0,Y.useState)(null),[y,N]=(0,Y.useState)(fy);(0,Y.useEffect)(()=>{h(d)},[d]),(0,Y.useEffect)(()=>{if(o&&(null==d||!d.startDate)&&(null==x||!x.startDate)){const e=new Date(o.current_credit_period_start_date),t=new Date(o.current_credit_period_end_date);h({startDate:e,endDate:t})}},[o,d,x]),(0,Y.useEffect)(()=>{if(!t)return g([]),v(null),void j(null);(async()=>{N(e=>(0,K.A)((0,K.A)({},e),{},{workspaces:!0}));try{var e;const s=await ke.default.getUserWorkspacesWithDetails(t.id);g(s.workspaces||[]);const a=null===(e=s.workspaces)||void 0===e?void 0:e.find(e=>e.is_personal);a&&(v(a.id),j(a))}catch(s){g([])}finally{N(e=>(0,K.A)((0,K.A)({},e),{},{workspaces:!1}))}})()},[t]);return(0,le.jsx)(tp,{open:!!t,onOpenChange:s,className:"bg-white",children:(0,le.jsxs)(ip,{className:"sm:max-w-xl overflow-y-auto",children:[(0,le.jsx)(op,{children:(0,le.jsx)(dp,{children:"User Details"})}),t&&(0,le.jsxs)("div",{className:"py-6",children:[(0,le.jsxs)("div",{className:"mb-6",children:[(0,le.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,le.jsx)("h3",{className:"text-lg font-semibold",children:t.full_name||t.email}),p&&p.length>1&&(0,le.jsx)("div",{className:"w-48",children:(0,le.jsx)(gy,{workspaces:p,selectedWorkspace:f,onWorkspaceChange:e=>{v(e);const t=p.find(t=>t.id===e);j(t),x.startDate&&x.endDate&&(N(e=>(0,K.A)((0,K.A)({},e),{},{usageStats:!0})),c(x.startDate,x.endDate,e,()=>{N(e=>(0,K.A)((0,K.A)({},e),{},{usageStats:!1}))}))},loading:y.workspaces})})]}),(0,le.jsx)("p",{className:"text-gray-600",children:t.email}),b&&!b.is_personal&&(0,le.jsxs)("p",{className:"text-sm text-gray-500 mt-1",children:[b.name," (".concat(b.user_role,")")]})]}),(0,le.jsxs)(kr,{defaultValue:"details",className:"w-full",onValueChange:u,value:m,children:[(0,le.jsxs)(Cr,{className:"grid grid-cols-3 mb-6",children:[(0,le.jsxs)(Ar,{value:"details",className:"flex items-center gap-2",children:[(0,le.jsx)(nv.A,{className:"h-4 w-4"}),"Details"]}),(0,le.jsxs)(Ar,{value:"usage",className:"flex items-center gap-2",children:[(0,le.jsx)(tr.A,{className:"h-4 w-4"}),"Usage"]}),(0,le.jsxs)(Ar,{value:"credits",className:"flex items-center gap-2",children:[(0,le.jsx)(Au.A,{className:"h-4 w-4"}),"Credits"]})]}),(0,le.jsx)(Sr,{value:"details",children:(0,le.jsx)(dy,{selectedUser:t,workspaceDetails:b,onUpdateUser:a,loading:i,loadingStates:y})}),(0,le.jsx)(Sr,{value:"usage",children:(0,le.jsx)(hy,{userUsageStats:o,dateRange:x,onDateRangeChange:c,selectedWorkspace:f,onSwitchToCreditsTab:()=>u("credits"),isLoading:y.usageStats})}),(0,le.jsx)(Sr,{value:"credits",children:(0,le.jsx)(py,{userBonusCredits:n,onAddBonusCredits:(e,s)=>{l(t.id,e,s)},onDeleteBonusCredit:e=>{r(e)},loading:i})})]})]})]})})}class by extends Q.y{getBaseURL(){return"/admin/analytics"}getAdminStats(){return this.axios.get("/overall")}getTopUsers(e,t){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:100;return this.axios.get("/top-users",{params:{start_date:e,end_date:t,limit:s}})}getUserAnalytics(){return this.axios.get("/user-analytics")}getOrganizationsWithPlans(){return this.axios.get("/organizations-with-plans")}searchOrganizations(e){return this.axios.get("/search-organizations",{params:{search:e}})}getOrganizationUsage(e){return this.axios.get("/organization/".concat(e,"/usage"))}}const jy=new by;function yy(){const[e,t]=(0,Y.useState)(!1),[s,a]=(0,Y.useState)([]),[n,l]=(0,Y.useState)({startDate:ra()().subtract(7,"days").format("YYYY-MM-DD"),endDate:ra()().format("YYYY-MM-DD")}),[r,i]=(0,Y.useState)(!1),[o,c]=(0,Y.useState)(!1);(0,Y.useEffect)(()=>{d()},[n.startDate,n.endDate]);const d=async()=>{t(!0);try{const e=await jy.getTopUsers(n.startDate,n.endDate);a(e)}catch(e){}finally{t(!1)}},m=e=>{l("ever"===e?{startDate:"2020-01-01",endDate:ra()().format("YYYY-MM-DD")}:{startDate:ra()().subtract(e,"days").format("YYYY-MM-DD"),endDate:ra()().format("YYYY-MM-DD")})};return(0,le.jsxs)(is,{className:"mb-8",children:[(0,le.jsx)(os,{children:(0,le.jsxs)(cs,{className:"flex justify-between items-center",children:[(0,le.jsx)("span",{children:"Top Users by Message Count"}),(0,le.jsxs)("div",{className:"flex items-center space-x-2 text-sm",children:[(0,le.jsx)(Yt,{variant:"outline",size:"sm",onClick:()=>m(1),className:n.startDate===ra()().subtract(1,"days").format("YYYY-MM-DD")?"bg-blue-50":"",children:"1 Day"}),(0,le.jsx)(Yt,{variant:"outline",size:"sm",onClick:()=>m(7),className:n.startDate===ra()().subtract(7,"days").format("YYYY-MM-DD")?"bg-blue-50":"",children:"7 Days"}),(0,le.jsx)(Yt,{variant:"outline",size:"sm",onClick:()=>m(15),className:n.startDate===ra()().subtract(15,"days").format("YYYY-MM-DD")?"bg-blue-50":"",children:"15 Days"}),(0,le.jsx)(Yt,{variant:"outline",size:"sm",onClick:()=>m(30),className:n.startDate===ra()().subtract(30,"days").format("YYYY-MM-DD")?"bg-blue-50":"",children:"30 Days"}),(0,le.jsx)(Yt,{variant:"outline",size:"sm",onClick:()=>m("ever"),className:"2020-01-01"===n.startDate?"bg-blue-50":"",children:"All Time"}),(0,le.jsxs)("div",{className:"flex items-center space-x-2 ml-4",children:[(0,le.jsxs)(Nh,{open:r,onOpenChange:i,children:[(0,le.jsx)(wh,{asChild:!0,children:(0,le.jsxs)(Yt,{variant:"outline",size:"sm",className:"flex items-center gap-1",children:[(0,le.jsx)(bh.A,{className:"h-3.5 w-3.5"}),(0,le.jsx)("span",{children:n.startDate})]})}),(0,le.jsx)(_h,{className:"w-auto p-0",children:(0,le.jsx)(fh,{mode:"single",selected:new Date(n.startDate),onSelect:e=>{const t=ra()(e).format("YYYY-MM-DD");l(e=>(0,K.A)((0,K.A)({},e),{},{startDate:t})),i(!1)},initialFocus:!0,disabled:e=>e>new Date(n.endDate)||e>new Date})})]}),(0,le.jsx)("span",{children:"to"}),(0,le.jsxs)(Nh,{open:o,onOpenChange:c,children:[(0,le.jsx)(wh,{asChild:!0,children:(0,le.jsxs)(Yt,{variant:"outline",size:"sm",className:"flex items-center gap-1",children:[(0,le.jsx)(bh.A,{className:"h-3.5 w-3.5"}),(0,le.jsx)("span",{children:n.endDate})]})}),(0,le.jsx)(_h,{className:"w-auto p-0",children:(0,le.jsx)(fh,{mode:"single",selected:new Date(n.endDate),onSelect:e=>{const t=ra()(e).format("YYYY-MM-DD");l(e=>(0,K.A)((0,K.A)({},e),{},{endDate:t})),c(!1)},initialFocus:!0,disabled:e=>enew Date})})]})]})]})]})}),(0,le.jsx)(ms,{children:e?(0,le.jsx)("div",{className:"text-center py-8",children:"Loading top users data..."}):0===s.length?(0,le.jsx)("div",{className:"text-center py-8 text-gray-500",children:"No data available for the selected date range"}):(0,le.jsx)("div",{className:"overflow-x-auto",children:(0,le.jsxs)(zl,{children:[(0,le.jsx)(Ul,{children:(0,le.jsxs)(Vl,{children:[(0,le.jsx)(Hl,{children:"Email"}),(0,le.jsx)(Hl,{children:"Full Name"}),(0,le.jsx)(Hl,{children:"Subscription"}),(0,le.jsx)(Hl,{children:"Role"}),(0,le.jsx)(Hl,{className:"text-right",children:(0,le.jsxs)("div",{className:"flex items-center justify-end",children:[(0,le.jsx)(Ir.A,{className:"h-4 w-4 mr-2"}),"Messages"]})})]})}),(0,le.jsx)(Wl,{children:s.map((e,t)=>{var s,a,n,l,r;return(0,le.jsxs)(Vl,{children:[(0,le.jsx)(Yl,{className:"font-medium",children:e.email}),(0,le.jsx)(Yl,{children:e.full_name||"-"}),(0,le.jsx)(Yl,{children:(0,le.jsx)("span",{className:"px-2 py-1 rounded-full text-xs ".concat(null!==(s=e.subscription_tier)&&void 0!==s&&s.toLowerCase().includes("enterprise")?"bg-yellow-100 text-yellow-800":null!==(a=e.subscription_tier)&&void 0!==a&&a.toLowerCase().includes("elite")?"bg-purple-100 text-purple-800":null!==(n=e.subscription_tier)&&void 0!==n&&n.toLowerCase().includes("pro")?"bg-blue-100 text-blue-800":null!==(l=e.subscription_tier)&&void 0!==l&&l.toLowerCase().includes("builder")?"bg-indigo-100 text-indigo-800":null!==(r=e.subscription_tier)&&void 0!==r&&r.toLowerCase().includes("starter")?"bg-green-100 text-green-800":"bg-gray-100 text-gray-800"),children:e.subscription_tier||"Free"})}),(0,le.jsx)(Yl,{children:(0,le.jsx)("span",{className:"px-2 py-1 rounded-full text-xs ".concat("platform_admin"===e.platform_role?"bg-purple-100 text-purple-800":"bg-gray-100 text-gray-800"),children:e.platform_role})}),(0,le.jsx)(Yl,{className:"text-right font-semibold",children:e.message_count.toLocaleString()})]},t)})})]})})})]})}var Ny=s(89284);class wy extends Q.y{getBaseURL(){return"/workspace"}updateWorkspace(e,t){const s={workspaceId:e};return this.axios.put("/admin/update",t,{params:s})}}const _y=new wy,ky=[{value:"stripe",label:"Stripe Billing"},{value:"no_billing",label:"No Billing (Free)"}];function Cy(e){let{workspace:t,isOpen:s,onClose:a,onSave:n}=e;const[l,r]=(0,Y.useState)({billing_type:"stripe",is_enterprise:!1,plans:[]}),[i,o]=(0,Y.useState)({billing_type:"stripe",is_enterprise:!1,plans:[]}),[c,d]=(0,Y.useState)(!1),[m,u]=(0,Y.useState)(""),[x,h]=(0,Y.useState)([]),[p,g]=(0,Y.useState)(!1);(0,Y.useEffect)(()=>{s&&f()},[s]),(0,Y.useEffect)(()=>{if(t){const e={billing_type:t.billing_type||"stripe",is_enterprise:t.is_enterprise||!1,plans:t.plans?t.plans.map(e=>({name:e.name.toLowerCase(),price_id:e.price_id,total_seats:e.total_seats||0})):[]};r(e),o(JSON.parse(JSON.stringify(e))),u("")}},[t]);const f=async()=>{g(!0);try{const e=await xe.getAvailablePlans();if(null==e||!e.plans)throw new Error("Failed to load available plans");{const t=e.plans.map(e=>({name:e.name.toLowerCase(),price_id:e.price_id,displayName:e.name.charAt(0).toUpperCase()+e.name.slice(1)}));h(t)}}catch(e){u("Failed to load available plans")}finally{g(!1)}},v=e=>{const t=l.plans.find(t=>t.name===e);return t?t.total_seats:0},b=()=>{if(l.billing_type!==i.billing_type)return!0;if(l.is_enterprise!==i.is_enterprise)return!0;const e=[...l.plans].sort((e,t)=>e.name.localeCompare(t.name)),t=[...i.plans].sort((e,t)=>e.name.localeCompare(t.name));if(e.length!==t.length)return!0;for(let s=0;s{u(""),a()};return t?(0,le.jsx)(Pa,{open:s,onOpenChange:j,children:(0,le.jsxs)(Da,{className:"max-w-2xl max-h-[90vh] overflow-y-auto",children:[(0,le.jsx)(Fa,{children:(0,le.jsx)(za,{className:"flex items-center gap-2",children:(0,le.jsxs)("span",{children:["Edit Workspace: ",t.name||t.domain||"Unknown"]})})}),(0,le.jsxs)("div",{className:"space-y-6",children:[m&&(0,le.jsxs)(De,{variant:"destructive",children:[(0,le.jsx)(_e.A,{className:"h-4 w-4"}),(0,le.jsx)(Be,{children:m})]}),(0,le.jsxs)(is,{children:[(0,le.jsx)(os,{children:(0,le.jsx)(cs,{className:"text-lg",children:"Billing Configuration"})}),(0,le.jsx)(ms,{children:(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsx)(Ns,{htmlFor:"billing-type",children:"Billing Type"}),(0,le.jsxs)(zs,{value:l.billing_type,onValueChange:e=>{r(t=>(0,K.A)((0,K.A)({},t),{},{billing_type:e}))},children:[(0,le.jsx)(qs,{children:(0,le.jsx)(Ws,{placeholder:"Select billing type"})}),(0,le.jsx)(Ys,{children:ky.map(e=>(0,le.jsx)($s,{value:e.value,children:e.label},e.value))})]})]})})]}),(0,le.jsxs)(is,{children:[(0,le.jsx)(os,{children:(0,le.jsxs)(cs,{className:"text-lg flex items-center gap-2",children:[(0,le.jsx)(Ny.A,{className:"h-5 w-5"}),"Enterprise Features"]})}),(0,le.jsx)(ms,{children:(0,le.jsxs)("div",{className:"flex items-center justify-between",children:[(0,le.jsxs)("div",{className:"space-y-1",children:[(0,le.jsx)(Ns,{htmlFor:"is-enterprise",className:"text-base",children:"Enable Enterprise Features"}),(0,le.jsx)("p",{className:"text-sm text-slate-600",children:"Enables SSO, advanced security features, and enterprise-level support"})]}),(0,le.jsx)(ix,{id:"is-enterprise",checked:l.is_enterprise,onCheckedChange:e=>r(t=>(0,K.A)((0,K.A)({},t),{},{is_enterprise:e}))})]})})]}),(0,le.jsxs)(is,{children:[(0,le.jsxs)(os,{children:[(0,le.jsx)(cs,{className:"text-lg",children:"Seat Plans"}),(0,le.jsx)("p",{className:"text-sm text-slate-600",children:"Set the total seat count for each plan. Set to 0 to remove a plan."})]}),(0,le.jsx)(ms,{children:p?(0,le.jsxs)("div",{className:"flex items-center justify-center py-8",children:[(0,le.jsx)(Ne.A,{className:"h-6 w-6 animate-spin text-slate-600"}),(0,le.jsx)("span",{className:"ml-2 text-slate-600",children:"Loading plans..."})]}):(0,le.jsx)("div",{className:"space-y-4",children:x.map(e=>(0,le.jsxs)("div",{className:"flex items-center justify-between p-3 border rounded-lg",children:[(0,le.jsxs)("div",{className:"flex-1",children:[(0,le.jsx)("div",{className:"font-medium text-slate-900",children:e.displayName}),(0,le.jsxs)("div",{className:"text-sm text-slate-500",children:["Price ID: ",e.price_id]})]}),(0,le.jsxs)("div",{className:"flex items-center gap-2 min-w-[120px]",children:[(0,le.jsx)(Ns,{htmlFor:"".concat(e.name,"-seats"),className:"text-sm whitespace-nowrap",children:"Total Seats:"}),(0,le.jsx)(fs,{id:"".concat(e.name,"-seats"),type:"number",min:"0",value:v(e.name),onChange:t=>((e,t)=>{const s=parseInt(t)||0,a=x.find(t=>t.name===e);r(t=>{const n=[...t.plans],l=n.findIndex(t=>t.name===e);if(s>0){const t={name:e,price_id:a.price_id,total_seats:s};l>=0?n[l]=t:n.push(t)}else l>=0&&n.splice(l,1);return(0,K.A)((0,K.A)({},t),{},{plans:n})})})(e.name,t.target.value),className:"w-20 text-center",placeholder:"0"})]})]},e.name))})})]}),(0,le.jsxs)("div",{className:"flex justify-end gap-3 pt-4 border-t",children:[(0,le.jsxs)(Yt,{variant:"outline",onClick:j,disabled:c,children:[(0,le.jsx)(Bt.A,{className:"h-4 w-4 mr-2"}),"Cancel"]}),(0,le.jsxs)(Yt,{onClick:async()=>{if(t)if(b()){d(!0),u("");try{await n(t.id||t.organization_id,l),a()}catch(e){u(e.message||"Failed to update workspace")}finally{d(!1)}}else a()},disabled:c||!b(),className:"bg-orange-600 hover:bg-orange-700 disabled:bg-slate-300 disabled:text-slate-500",children:[(0,le.jsx)(df.A,{className:"h-4 w-4 mr-2"}),c?"Saving...":b()?"Save Changes":"No Changes"]})]})]})]})}):null}function Ay(){const[e,t]=(0,Y.useState)(null),[s,a]=(0,Y.useState)(null),[n,l]=(0,Y.useState)(!0),[r,i]=(0,Y.useState)(""),[o,c]=(0,Y.useState)(!1),[d,m]=(0,Y.useState)(null),[u,x]=(0,Y.useState)(!0),[h,p]=(0,Y.useState)(!1);(0,Y.useEffect)(()=>{g()},[]);const g=async()=>{try{const e=await jy.getOrganizationsWithPlans();null!=e&&e.success&&a(e.data)}catch(e){}};(0,Y.useEffect)(()=>{u?v():r.length>=3?f(r):t({organizations:[],all_plans:[],total_organizations_with_plans:0})},[u]);const f=(0,Y.useCallback)((0,Ce.debounce)(async e=>{if(!u&&e.length>=3){p(!0);try{const s=await jy.searchOrganizations(e);if(null!=s&&s.success){const e=s.data,a=e.organizations||[],n=e.all_plans||[],l=a.filter(e=>e.plans&&e.plans.length>0).length;let r=0,i=0;a.forEach(e=>{e.plans&&e.plans.forEach(e=>{r+=e.total_seats||0,i+=e.used_seats||0})});const o=r>0?Math.round(i/r*100*100)/100:0,c={};a.forEach(e=>{e.plans&&e.plans.forEach(e=>{if(e.created_date){const t=new Date(e.created_date).toISOString().split("T")[0];c[t]=(c[t]||0)+(e.total_seats||0)}})}),a.forEach(e=>{if(e.plans){const t=e.plans.reduce((e,t)=>e+(t.total_seats||0),0),s=e.plans.reduce((e,t)=>e+(t.used_seats||0),0),a=t>0?Math.round(s/t*100*100)/100:0;e.plan_summary={total_seats:t,used_seats:s,utilization_rate:a}}else e.plan_summary={total_seats:0,used_seats:0,utilization_rate:0}});t({organizations:a,all_plans:n,total_organizations_with_plans:l,total_seats_purchased:r,total_seats_used:i,overall_utilization_rate:o,seats_by_day:c})}}catch(s){}finally{p(!1)}}},500),[u]);(0,Y.useEffect)(()=>{u||(r.length>=3?f(r):t({organizations:[],all_plans:[],total_organizations_with_plans:0}))},[r,u,f]);const v=async()=>{try{const e=await jy.getOrganizationsWithPlans();if(null==e||!e.success)return void t(null);const s=e.data,n=s.organizations||[],l=s.all_plans||[],r=n.filter(e=>e.plans&&e.plans.length>0).length;let i=0,o=0;n.forEach(e=>{e.plans&&e.plans.forEach(e=>{i+=e.total_seats||0,o+=e.used_seats||0})});const c=i>0?Math.round(o/i*100*100)/100:0,d={};n.forEach(e=>{e.plans&&e.plans.forEach(e=>{if(e.created_date){const t=new Date(e.created_date).toISOString().split("T")[0];d[t]=(d[t]||0)+(e.total_seats||0)}})}),n.forEach(e=>{if(e.plans){const t=e.plans.reduce((e,t)=>e+(t.total_seats||0),0),s=e.plans.reduce((e,t)=>e+(t.used_seats||0),0),a=t>0?Math.round(s/t*100*100)/100:0;e.plan_summary={total_seats:t,used_seats:s,utilization_rate:a}}else e.plan_summary={total_seats:0,used_seats:0,utilization_rate:0}});const m={organizations:n,all_plans:l,total_organizations_with_plans:r,total_seats_purchased:i,total_seats_used:o,overall_utilization_rate:c,seats_by_day:d};t(m),u&&a(m)}catch(e){t(null)}finally{l(!1)}};if(n)return(0,le.jsx)("div",{className:"flex items-center justify-center h-64",children:(0,le.jsxs)("div",{className:"text-center",children:[(0,le.jsx)("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-slate-600 mx-auto mb-4"}),(0,le.jsx)("p",{className:"text-slate-600",children:"Loading organizations..."})]})});if(!e)return(0,le.jsxs)("div",{className:"text-center py-8",children:[(0,le.jsx)("p",{className:"text-slate-600",children:"Failed to load organizations data"}),(0,le.jsx)("p",{className:"text-sm text-slate-500 mt-2",children:"Check console for debugging information"})]});const b=e.organizations||[],j=(null==s?void 0:s.organizations)||[],y=(null==s?void 0:s.seats_by_day)||{},N=j.reduce((e,t)=>{var s;return e+((null===(s=t.plan_summary)||void 0===s?void 0:s.total_seats)||0)},0),w=j.reduce((e,t)=>{var s;return e+((null===(s=t.plan_summary)||void 0===s?void 0:s.used_seats)||0)},0),_=N>0?Math.round(w/N*100*100)/100:0,k=j.reduce((e,t)=>{var s;const a=null===(s=t.plans)||void 0===s?void 0:s.find(e=>{var t;return null===(t=e.name)||void 0===t?void 0:t.toLowerCase().includes("starter")});return e+((null==a?void 0:a.total_seats)||0)},0),C=j.reduce((e,t)=>{var s;const a=null===(s=t.plans)||void 0===s?void 0:s.find(e=>{var t;return null===(t=e.name)||void 0===t?void 0:t.toLowerCase().includes("builder")});return e+((null==a?void 0:a.total_seats)||0)},0),A=j.reduce((e,t)=>{var s;const a=null===(s=t.plans)||void 0===s?void 0:s.find(e=>{var t;return null===(t=e.name)||void 0===t?void 0:t.toLowerCase().includes("pro")});return e+((null==a?void 0:a.total_seats)||0)},0),S=j.reduce((e,t)=>{var s;return e+((null===(s=t.plans)||void 0===s?void 0:s.filter(e=>{var t;return null===(t=e.name)||void 0===t?void 0:t.toLowerCase().includes("elite")}))||[]).reduce((e,t)=>e+(t.total_seats||0),0)},0),E=u?b.filter(e=>{var t,s;return!r.trim()||(null===(t=e.name)||void 0===t?void 0:t.toLowerCase().includes(r.toLowerCase()))||(null===(s=e.domain)||void 0===s?void 0:s.toLowerCase().includes(r.toLowerCase()))}).sort((e,t)=>{var s,a;const n=(null===(s=e.plan_summary)||void 0===s?void 0:s.total_seats)||0;return((null===(a=t.plan_summary)||void 0===a?void 0:a.total_seats)||0)-n}):b.sort((e,t)=>{var s,a;const n=(null===(s=e.plan_summary)||void 0===s?void 0:s.total_seats)||0;return((null===(a=t.plan_summary)||void 0===a?void 0:a.total_seats)||0)-n});return(0,le.jsxs)("div",{className:"space-y-6",children:[(0,le.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-4 gap-4",children:[(0,le.jsx)("div",{className:"bg-white p-4 rounded-lg shadow",children:(0,le.jsxs)("div",{className:"flex items-center",children:[(0,le.jsx)(Ny.A,{className:"h-8 w-8 text-slate-600"}),(0,le.jsxs)("div",{className:"ml-3",children:[(0,le.jsx)("p",{className:"text-sm font-medium text-slate-600",children:"Orgs with Plans"}),(0,le.jsx)("p",{className:"text-2xl font-bold text-slate-900",children:(null==s?void 0:s.total_organizations_with_plans)||0})]})]})}),(0,le.jsx)("div",{className:"bg-white p-4 rounded-lg shadow",children:(0,le.jsxs)("div",{className:"flex items-center",children:[(0,le.jsx)(ye.A,{className:"h-8 w-8 text-slate-600"}),(0,le.jsxs)("div",{className:"ml-3",children:[(0,le.jsx)("p",{className:"text-sm font-medium text-slate-600",children:"Total Seats Purchased"}),(0,le.jsx)("p",{className:"text-2xl font-bold text-slate-900",children:N})]})]})}),(0,le.jsx)("div",{className:"bg-white p-4 rounded-lg shadow",children:(0,le.jsxs)("div",{className:"flex items-center",children:[(0,le.jsx)(Xl.A,{className:"h-8 w-8 text-slate-600"}),(0,le.jsxs)("div",{className:"ml-3",children:[(0,le.jsx)("p",{className:"text-sm font-medium text-slate-600",children:"Total Seats Used"}),(0,le.jsx)("p",{className:"text-2xl font-bold text-slate-900",children:w})]})]})}),(0,le.jsx)("div",{className:"bg-white p-4 rounded-lg shadow",children:(0,le.jsxs)("div",{className:"flex items-center",children:[(0,le.jsx)(ya.A,{className:"h-8 w-8 text-slate-600"}),(0,le.jsxs)("div",{className:"ml-3",children:[(0,le.jsx)("p",{className:"text-sm font-medium text-slate-600",children:"Utilization Rate"}),(0,le.jsxs)("p",{className:"text-2xl font-bold text-slate-900",children:[_,"%"]})]})]})})]}),(0,le.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-4 gap-4",children:[(0,le.jsx)("div",{className:"bg-white p-4 rounded-lg shadow border-l-4 border-green-500",children:(0,le.jsxs)("div",{className:"flex items-center",children:[(0,le.jsx)("div",{className:"h-8 w-8 bg-green-100 rounded-lg flex items-center justify-center",children:(0,le.jsx)("span",{className:"text-green-600 font-bold text-sm",children:"S"})}),(0,le.jsxs)("div",{className:"ml-3",children:[(0,le.jsx)("p",{className:"text-sm font-medium text-slate-600",children:"Starter Seats"}),(0,le.jsx)("p",{className:"text-2xl font-bold text-slate-900",children:k})]})]})}),(0,le.jsx)("div",{className:"bg-white p-4 rounded-lg shadow border-l-4 border-blue-500",children:(0,le.jsxs)("div",{className:"flex items-center",children:[(0,le.jsx)("div",{className:"h-8 w-8 bg-blue-100 rounded-lg flex items-center justify-center",children:(0,le.jsx)("span",{className:"text-blue-600 font-bold text-sm",children:"B"})}),(0,le.jsxs)("div",{className:"ml-3",children:[(0,le.jsx)("p",{className:"text-sm font-medium text-slate-600",children:"Builder Seats"}),(0,le.jsx)("p",{className:"text-2xl font-bold text-slate-900",children:C})]})]})}),(0,le.jsx)("div",{className:"bg-white p-4 rounded-lg shadow border-l-4 border-purple-500",children:(0,le.jsxs)("div",{className:"flex items-center",children:[(0,le.jsx)("div",{className:"h-8 w-8 bg-purple-100 rounded-lg flex items-center justify-center",children:(0,le.jsx)("span",{className:"text-purple-600 font-bold text-sm",children:"P"})}),(0,le.jsxs)("div",{className:"ml-3",children:[(0,le.jsx)("p",{className:"text-sm font-medium text-slate-600",children:"Pro Seats"}),(0,le.jsx)("p",{className:"text-2xl font-bold text-slate-900",children:A})]})]})}),(0,le.jsx)("div",{className:"bg-white p-4 rounded-lg shadow border-l-4 border-orange-500",children:(0,le.jsxs)("div",{className:"flex items-center",children:[(0,le.jsx)("div",{className:"h-8 w-8 bg-orange-100 rounded-lg flex items-center justify-center",children:(0,le.jsx)("span",{className:"text-orange-600 font-bold text-sm",children:"E"})}),(0,le.jsxs)("div",{className:"ml-3",children:[(0,le.jsx)("p",{className:"text-sm font-medium text-slate-600",children:"Elite Seats"}),(0,le.jsx)("p",{className:"text-2xl font-bold text-slate-900",children:S})]})]})})]}),Object.keys(y).length>0&&(0,le.jsxs)("div",{className:"bg-white p-6 rounded-lg shadow",children:[(0,le.jsxs)("h3",{className:"text-lg font-semibold text-slate-900 mb-4 flex items-center",children:[(0,le.jsx)(bh.A,{className:"h-5 w-5 mr-2"}),"Seats Purchased by Day"]}),(0,le.jsx)("div",{className:"grid grid-cols-2 md:grid-cols-4 lg:grid-cols-6 gap-3",children:Object.entries(y).sort((e,t)=>{let[s]=e,[a]=t;return new Date(s)-new Date(a)}).map(e=>{let[t,s]=e;return(0,le.jsxs)("div",{className:"text-center p-3 bg-slate-50 rounded-lg",children:[(0,le.jsx)("div",{className:"text-sm font-medium text-slate-600",children:ra()(t).format("MMM DD")}),(0,le.jsx)("div",{className:"text-lg font-bold text-slate-900",children:s}),(0,le.jsx)("div",{className:"text-xs text-slate-500",children:"seats"})]},t)})})]}),(0,le.jsxs)("div",{className:"flex justify-between items-center",children:[(0,le.jsxs)("div",{className:"flex items-center gap-4",children:[(0,le.jsxs)("div",{className:"relative w-72",children:[(0,le.jsx)(vn.A,{className:"absolute left-2 top-2.5 h-4 w-4 text-slate-500"}),(0,le.jsx)(fs,{placeholder:u?"Search organizations...":"Search (min 3 chars)...",className:"pl-8",value:r,onChange:e=>i(e.target.value)})]}),(0,le.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,le.jsx)(dm,{id:"with-plans",checked:u,onCheckedChange:e=>{x(e)}}),(0,le.jsx)("label",{htmlFor:"with-plans",className:"text-sm font-medium text-slate-700 cursor-pointer select-none",children:"With Plans"})]})]}),(0,le.jsx)("div",{className:"text-sm text-slate-600",children:h?(0,le.jsx)("span",{children:"Searching..."}):(0,le.jsx)(le.Fragment,{children:u?(0,le.jsxs)(le.Fragment,{children:[E.length," of ",b.length," organizations"]}):(0,le.jsx)(le.Fragment,{children:r.length<3?"Enter at least 3 characters to search":(0,le.jsxs)(le.Fragment,{children:[b.length," organizations found"]})})})})]}),(0,le.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,le.jsx)("div",{className:"p-6 border-b",children:(0,le.jsx)("h3",{className:"text-lg font-semibold text-slate-900",children:"Organizations"})}),(0,le.jsxs)(zl,{children:[(0,le.jsx)(Ul,{children:(0,le.jsxs)(Vl,{children:[(0,le.jsx)(Hl,{children:"Organization Name"}),(0,le.jsx)(Hl,{children:"Enterprise"}),(0,le.jsx)(Hl,{children:"Total Seats"}),(0,le.jsx)(Hl,{children:"Used Seats"}),(0,le.jsx)(Hl,{children:"Starter"}),(0,le.jsx)(Hl,{children:"Builder"}),(0,le.jsx)(Hl,{children:"Pro"}),(0,le.jsx)(Hl,{children:"Elite"}),(0,le.jsx)(Hl,{children:"Utilization Rate"}),(0,le.jsx)(Hl,{children:"Created Date"}),(0,le.jsx)(Hl,{children:"Actions"})]})}),(0,le.jsx)(Wl,{children:0===E.length?(0,le.jsx)(Vl,{children:(0,le.jsx)(Yl,{colSpan:11,className:"text-center py-8",children:!u&&r.length<3?"Enter at least 3 characters to search organizations":r?"No organizations found matching your search":"No organizations found"})}):E.map(e=>{var t,s,a,n,l,r,i;const o=(null===(t=e.plans)||void 0===t?void 0:t.find(e=>{var t;return null===(t=e.name)||void 0===t?void 0:t.toLowerCase().includes("starter")}))||{total_seats:0,used_seats:0},d=(null===(s=e.plans)||void 0===s?void 0:s.find(e=>{var t;return null===(t=e.name)||void 0===t?void 0:t.toLowerCase().includes("builder")}))||{total_seats:0,used_seats:0},u=(null===(a=e.plans)||void 0===a?void 0:a.find(e=>{var t;return null===(t=e.name)||void 0===t?void 0:t.toLowerCase().includes("pro")}))||{total_seats:0,used_seats:0},x=(null===(n=e.plans)||void 0===n?void 0:n.filter(e=>{var t;return null===(t=e.name)||void 0===t?void 0:t.toLowerCase().includes("elite")}))||[],h=x.reduce((e,t)=>e+(t.total_seats||0),0),p=x.reduce((e,t)=>e+(t.used_seats||0),0);return(0,le.jsxs)(Vl,{className:"hover:bg-slate-50 transition-colors",children:[(0,le.jsx)(Yl,{className:"font-medium",children:e.name||e.domain||"No name"}),(0,le.jsx)(Yl,{children:e.is_enterprise?(0,le.jsx)("div",{className:"flex items-center justify-center",children:(0,le.jsx)(lv.A,{className:"h-5 w-5 text-yellow-600",title:"Enterprise Enabled"})}):(0,le.jsx)("div",{className:"flex items-center justify-center",children:(0,le.jsx)("span",{className:"text-slate-400",children:"-"})})}),(0,le.jsx)(Yl,{children:(0,le.jsx)("span",{className:"px-2 py-1 rounded-full text-xs bg-slate-100 text-slate-800",children:(null===(l=e.plan_summary)||void 0===l?void 0:l.total_seats)||0})}),(0,le.jsx)(Yl,{children:(0,le.jsx)("span",{className:"px-2 py-1 rounded-full text-xs bg-orange-100 text-orange-800",children:(null===(r=e.plan_summary)||void 0===r?void 0:r.used_seats)||0})}),(0,le.jsx)(Yl,{children:(0,le.jsxs)("div",{className:"text-center",children:[(0,le.jsx)("div",{className:"text-sm font-medium text-slate-900",children:o.total_seats}),(0,le.jsxs)("div",{className:"text-xs text-slate-500",children:[o.used_seats," used"]})]})}),(0,le.jsx)(Yl,{children:(0,le.jsxs)("div",{className:"text-center",children:[(0,le.jsx)("div",{className:"text-sm font-medium text-slate-900",children:d.total_seats}),(0,le.jsxs)("div",{className:"text-xs text-slate-500",children:[d.used_seats," used"]})]})}),(0,le.jsx)(Yl,{children:(0,le.jsxs)("div",{className:"text-center",children:[(0,le.jsx)("div",{className:"text-sm font-medium text-slate-900",children:u.total_seats}),(0,le.jsxs)("div",{className:"text-xs text-slate-500",children:[u.used_seats," used"]})]})}),(0,le.jsx)(Yl,{children:(0,le.jsxs)("div",{className:"text-center",children:[(0,le.jsx)("div",{className:"text-sm font-medium text-slate-900",children:h}),(0,le.jsxs)("div",{className:"text-xs text-slate-500",children:[p," used"]})]})}),(0,le.jsx)(Yl,{children:(0,le.jsxs)("span",{className:"px-2 py-1 rounded-full text-xs bg-blue-100 text-blue-800",children:[(null===(i=e.plan_summary)||void 0===i?void 0:i.utilization_rate)||0,"%"]})}),(0,le.jsx)(Yl,{children:(0,le.jsx)("span",{className:"text-sm text-slate-600",children:e.created_date?ra().utc(e.created_date).format("YYYY-MM-DD"):"-"})}),(0,le.jsx)(Yl,{children:(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[(e.id||e.organization_id)&&(0,le.jsxs)("a",{href:"/workspace/".concat(e.id||e.organization_id),target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 px-2 py-1 text-xs font-medium text-slate-600 hover:text-slate-900 hover:bg-slate-100 rounded-md transition-colors",title:"Manage workspace",children:[(0,le.jsx)(Tr.A,{className:"h-3 w-3"}),"Manage"]}),(0,le.jsxs)("button",{onClick:()=>(m(e),void c(!0)),className:"inline-flex items-center gap-1 px-2 py-1 text-xs font-medium text-slate-600 hover:text-slate-900 hover:bg-slate-100 rounded-md transition-colors",title:"Edit workspace configuration",children:[(0,le.jsx)(Ql.A,{className:"h-3 w-3"}),"Edit"]})]})})]},e.id||e.organization_id)})})]})]}),(0,le.jsx)(Cy,{workspace:d,isOpen:o,onClose:()=>{c(!1),m(null)},onSave:async(e,t)=>{try{await _y.updateWorkspace(e,t),await v()}catch(s){throw s}}})]})}var Sy=s(9449);const Ey=()=>{const[e,t]=(0,Y.useState)([]),[s,a]=(0,Y.useState)(!0),{register:n,handleSubmit:l,reset:r,formState:{errors:i}}=(0,Sy.useForm)({defaultValues:{code:"",numMessages:"",maxNumberOfPeople:"",domain:""}}),o=async()=>{try{a(!0);const e=await fc.getCouponCodes();t(e||[])}catch(e){mi({title:"Error",description:"Failed to fetch coupon codes",variant:"destructive"})}finally{a(!1)}};(0,Y.useEffect)(()=>{o()},[]);return(0,le.jsxs)("div",{className:"container mx-auto py-8 space-y-6",children:[(0,le.jsx)("h1",{className:"text-3xl font-bold",children:"Coupon Code Management"}),(0,le.jsxs)(is,{children:[(0,le.jsxs)(os,{children:[(0,le.jsx)(cs,{children:"Create Coupon Code"}),(0,le.jsx)(ds,{children:"Create a new coupon code for users to redeem"})]}),(0,le.jsx)(ms,{children:(0,le.jsxs)("form",{onSubmit:l(async e=>{try{a(!0),await fc.createCouponCode(e.code,parseInt(e.numMessages),parseInt(e.maxNumberOfPeople),e.domain||null),mi({title:"Success",description:"Coupon code created successfully"}),r(),o()}catch(t){mi({title:"Error",description:"Failed to create coupon code",variant:"destructive"})}finally{a(!1)}}),className:"space-y-4",children:[(0,le.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsx)(Ns,{htmlFor:"code",children:"Code"}),(0,le.jsx)(fs,(0,K.A)({id:"code",placeholder:"SUMMER2023"},n("code",{required:"Code is required"}))),i.code&&(0,le.jsx)("span",{className:"text-sm text-red-500",children:i.code.message})]}),(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsx)(Ns,{htmlFor:"numMessages",children:"Number of Messages"}),(0,le.jsx)(fs,(0,K.A)({id:"numMessages",type:"number",placeholder:"100"},n("numMessages",{required:"Number of messages is required",min:{value:1,message:"Must be at least 1"}}))),i.numMessages&&(0,le.jsx)("span",{className:"text-sm text-red-500",children:i.numMessages.message})]}),(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsx)(Ns,{htmlFor:"maxNumberOfPeople",children:"Max Number of People"}),(0,le.jsx)(fs,(0,K.A)({id:"maxNumberOfPeople",type:"number",placeholder:"50"},n("maxNumberOfPeople",{required:"Max number of people is required",min:{value:1,message:"Must be at least 1"}}))),i.maxNumberOfPeople&&(0,le.jsx)("span",{className:"text-sm text-red-500",children:i.maxNumberOfPeople.message})]}),(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsx)(Ns,{htmlFor:"domain",children:"Domain (Optional)"}),(0,le.jsx)(fs,(0,K.A)({id:"domain",placeholder:"example.com"},n("domain"))),(0,le.jsx)("p",{className:"text-xs text-gray-500",children:"Limit code to specific email domain"})]})]}),(0,le.jsx)(Yt,{type:"submit",disabled:s,children:"Create Coupon Code"})]})})]}),(0,le.jsxs)(is,{children:[(0,le.jsxs)(os,{children:[(0,le.jsx)(cs,{children:"Existing Coupon Codes"}),(0,le.jsx)(ds,{children:"View and manage all available coupon codes"})]}),(0,le.jsx)(ms,{children:s?(0,le.jsx)("div",{className:"flex justify-center items-center py-8",children:(0,le.jsx)("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900"})}):0===e.length?(0,le.jsx)("div",{className:"text-center py-8 text-gray-500",children:"No coupon codes found"}):(0,le.jsx)("div",{className:"rounded-md border",children:(0,le.jsxs)(zl,{children:[(0,le.jsx)(Ul,{children:(0,le.jsxs)(Vl,{children:[(0,le.jsx)(Hl,{children:"Code"}),(0,le.jsx)(Hl,{children:"Messages"}),(0,le.jsx)(Hl,{children:"Max Users"}),(0,le.jsx)(Hl,{children:"Domain"}),(0,le.jsx)(Hl,{children:"Usage"})]})}),(0,le.jsx)(Wl,{children:e.map((e,t)=>(0,le.jsxs)(Vl,{children:[(0,le.jsx)(Yl,{className:"font-medium",children:e.code}),(0,le.jsx)(Yl,{children:e.num_messages}),(0,le.jsx)(Yl,{children:e.max_number_of_people}),(0,le.jsx)(Yl,{children:e.domain||"Any"}),(0,le.jsxs)(Yl,{children:[e.used_credits||0," / ",e.max_number_of_people]})]},t))})]})})})]})]})};class Iy extends Q.H{getBaseURL(){return"/notifications"}async getChangelog(){return await this.axios.get("/changelog")}async markChangelogAsSeen(){return await this.axios.put("/changelog/mark-as-seen")}async createChangelogItem(e){return await this.axios.post("/changelog",e)}async updateChangelogItem(e,t){return await this.axios.put("/changelog/".concat(e),t)}async deleteChangelogItem(e){return await this.axios.delete("/changelog/".concat(e))}async getAllChangelogItems(){return await this.axios.get("/changelog")}}const Ty=new Iy,Py=["is_seen"];function Ly(){const[e,t]=(0,Y.useState)([]),[s,a]=(0,Y.useState)(!1),[n,l]=(0,Y.useState)(!1),[r,i]=(0,Y.useState)(null),[o,c]=(0,Y.useState)(!1),[d,m]=(0,Y.useState)({title:"",content:"",image_url:"",link_url:""}),u=(0,Y.useRef)(null);(0,Y.useRef)(null);(0,Y.useEffect)(()=>{x()},[]),(0,Y.useEffect)(()=>{if(n)return document.addEventListener("paste",f),()=>{document.removeEventListener("paste",f)}},[n]);const x=async()=>{a(!0);try{const e=(await Ty.getAllChangelogItems()).map(e=>{let{is_seen:t}=e;return(0,Se.A)(e,Py)}).sort((e,t)=>new Date(t.created_date)-new Date(e.created_date));t(e)}catch(e){cr.toast.error("Failed to load changelog items")}finally{a(!1)}},h=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;e?(i(e),m({title:e.title,content:e.content,image_url:e.image_url,link_url:e.link_url})):(i(null),m({title:"",content:"",image_url:"",link_url:""})),l(!0)},p=()=>{l(!1),i(null),m({title:"",content:"",image_url:"",link_url:""})},g=async e=>{if(e)if(e.type.startsWith("image/"))if(e.size>5242880)cr.toast.error("Image must be less than 5MB");else{c(!0);try{const t=(await _t.uploadFile(e)).url;if(!t)throw new Error("No URL returned from upload");m(e=>(0,K.A)((0,K.A)({},e),{},{image_url:t})),cr.toast.success("Image uploaded successfully")}catch(t){cr.toast.error("Failed to upload image")}finally{c(!1)}}else cr.toast.error("Please upload an image file")},f=async e=>{var t;const s=null===(t=e.clipboardData)||void 0===t?void 0:t.items;if(s)for(const a of s)if(a.type.startsWith("image/")){e.preventDefault();const t=a.getAsFile();t&&await g(t);break}};return(0,le.jsxs)("div",{children:[(0,le.jsxs)("div",{className:"flex justify-between items-center mb-6",children:[(0,le.jsx)("h2",{className:"text-2xl font-bold",children:"What's New Management"}),(0,le.jsxs)(Yt,{onClick:()=>h(),className:"flex items-center gap-2",children:[(0,le.jsx)(kt.A,{className:"h-4 w-4"}),"Add New Item"]})]}),(0,le.jsx)("div",{className:"bg-white rounded-lg shadow",children:(0,le.jsxs)(zl,{children:[(0,le.jsx)(Ul,{children:(0,le.jsxs)(Vl,{children:[(0,le.jsx)(Hl,{className:"w-[50px]",children:"Image"}),(0,le.jsx)(Hl,{children:"Title"}),(0,le.jsx)(Hl,{children:"Content"}),(0,le.jsx)(Hl,{children:"Created Date"}),(0,le.jsx)(Hl,{className:"text-right",children:"Actions"})]})}),(0,le.jsx)(Wl,{children:s?(0,le.jsx)(Vl,{children:(0,le.jsx)(Yl,{colSpan:5,className:"text-center py-8",children:"Loading changelog items..."})}):0===e.length?(0,le.jsx)(Vl,{children:(0,le.jsx)(Yl,{colSpan:5,className:"text-center py-8",children:"No changelog items found"})}):e.map(e=>(0,le.jsxs)(Vl,{children:[(0,le.jsx)(Yl,{children:e.image_url&&(0,le.jsx)("img",{src:e.image_url,alt:"",className:"w-12 h-12 rounded object-cover"})}),(0,le.jsx)(Yl,{className:"font-medium",children:(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[e.title,e.link_url&&(0,le.jsx)("a",{href:e.link_url,target:"_blank",rel:"noopener noreferrer",className:"text-blue-500 hover:text-blue-700",children:(0,le.jsx)(Tr.A,{className:"h-3 w-3"})})]})}),(0,le.jsx)(Yl,{children:(0,le.jsx)("p",{className:"text-sm text-gray-600 line-clamp-2 max-w-md",children:e.content})}),(0,le.jsx)(Yl,{children:(0,le.jsxs)("div",{className:"flex items-center gap-1 text-sm text-gray-500",children:[(0,le.jsx)(bh.A,{className:"h-3 w-3"}),ra()(e.created_date).format("MMM DD, YYYY")]})}),(0,le.jsx)(Yl,{className:"text-right",children:(0,le.jsxs)("div",{className:"flex justify-end gap-2",children:[(0,le.jsx)(Yt,{variant:"outline",size:"sm",onClick:()=>h(e),children:(0,le.jsx)(Mv.A,{className:"h-4 w-4"})}),(0,le.jsx)(Yt,{variant:"outline",size:"sm",onClick:()=>(async e=>{if(window.confirm("Are you sure you want to delete this changelog item?"))try{a(!0),await Ty.deleteChangelogItem(e),cr.toast.success("Changelog item deleted successfully"),x()}catch(t){cr.toast.error("Failed to delete item")}finally{a(!1)}})(e.id),className:"text-red-600 hover:bg-red-50",children:(0,le.jsx)(Ip.A,{className:"h-4 w-4"})})]})})]},e.id))})]})}),(0,le.jsx)(Pa,{open:n,onOpenChange:l,children:(0,le.jsxs)(Da,{className:"sm:max-w-[525px]",children:[(0,le.jsxs)(Fa,{children:[(0,le.jsx)(za,{children:r?"Edit Changelog Item":"Create New Changelog Item"}),(0,le.jsx)(Ua,{children:r?"Update the details of the changelog item below.":"Fill in the details for the new changelog item."})]}),(0,le.jsxs)("div",{className:"grid gap-4 py-4",children:[(0,le.jsxs)("div",{className:"grid gap-2",children:[(0,le.jsx)(Ns,{htmlFor:"title",children:"Title"}),(0,le.jsx)(fs,{id:"title",value:d.title,onChange:e=>m((0,K.A)((0,K.A)({},d),{},{title:e.target.value})),placeholder:"New Feature: Enhanced User Experience"})]}),(0,le.jsxs)("div",{className:"grid gap-2",children:[(0,le.jsx)(Ns,{htmlFor:"content",children:"Content"}),(0,le.jsx)(um,{id:"content",value:d.content,onChange:e=>m((0,K.A)((0,K.A)({},d),{},{content:e.target.value})),placeholder:"Describe what's new or what has changed...",rows:4})]}),(0,le.jsxs)("div",{className:"grid gap-2",children:[(0,le.jsx)(Ns,{htmlFor:"image_url",children:"Image"}),(0,le.jsxs)("div",{className:"space-y-2",children:[d.image_url&&(0,le.jsxs)("div",{className:"relative",children:[(0,le.jsx)("img",{src:d.image_url,alt:"Preview",className:"w-full h-48 object-cover rounded-lg border"}),(0,le.jsx)(Yt,{variant:"outline",size:"sm",className:"absolute top-2 right-2",onClick:()=>m((0,K.A)((0,K.A)({},d),{},{image_url:""})),children:"Remove"})]}),(0,le.jsxs)("div",{className:"flex gap-2",children:[(0,le.jsx)(fs,{id:"image_url",value:d.image_url,onChange:e=>m((0,K.A)((0,K.A)({},d),{},{image_url:e.target.value})),placeholder:"https://example.com/image.jpg",className:"flex-1"}),(0,le.jsx)("input",{ref:u,type:"file",accept:"image/*",onChange:async e=>{var t;const s=null===(t=e.target.files)||void 0===t?void 0:t[0];s&&await g(s)},className:"hidden"}),(0,le.jsx)(Yt,{type:"button",variant:"outline",onClick:()=>{var e;return null===(e=u.current)||void 0===e?void 0:e.click()},disabled:o,children:o?(0,le.jsx)(Ne.A,{className:"h-4 w-4 animate-spin"}):(0,le.jsx)(hx.A,{className:"h-4 w-4"})})]}),(0,le.jsx)("p",{className:"text-xs text-gray-500",children:"Upload an image or paste from clipboard (Ctrl/Cmd + V)"})]})]}),(0,le.jsxs)("div",{className:"grid gap-2",children:[(0,le.jsx)(Ns,{htmlFor:"link_url",children:"Link URL (Optional)"}),(0,le.jsx)(fs,{id:"link_url",value:d.link_url,onChange:e=>m((0,K.A)((0,K.A)({},d),{},{link_url:e.target.value})),placeholder:"https://docs.example.com/changelog"})]})]}),(0,le.jsxs)(Ba,{children:[(0,le.jsx)(Yt,{variant:"outline",onClick:p,children:"Cancel"}),(0,le.jsx)(Yt,{onClick:async()=>{try{a(!0),r?(await Ty.updateChangelogItem(r.id,d),cr.toast.success("Changelog item updated successfully")):(await Ty.createChangelogItem(d),cr.toast.success("Changelog item created successfully")),p(),x()}catch(e){cr.toast.error(r?"Failed to update item":"Failed to create item")}finally{a(!1)}},disabled:s||!d.title||!d.content||!d.image_url,children:r?"Update":"Create"})]})]})})]})}function Oy(){const{user:e}=oe(),[t,s]=(0,J.useSearchParams)(),[a,n]=(0,Y.useState)([]),[l,r]=(0,Y.useState)(null),[i,o]=(0,Y.useState)(!1),[c,d]=(0,Y.useState)(""),[m,u]=(0,Y.useState)({key:"created_date",direction:"desc"}),[x,h]=(0,Y.useState)({totalUsers:0,newUsersToday:0,premiumUsers:0}),[p,g]=(0,Y.useState)([]),[f,v]=(0,Y.useState)(null),[b,j]=(0,Y.useState)(null),[y,N]=(0,Y.useState)({startDate:null,endDate:null}),w=(0,Y.useRef)(0);(0,Y.useEffect)(()=>{C()},[]),(0,Y.useEffect)(()=>(f&&clearTimeout(f),v(setTimeout(()=>{c.trim()?k(c):_()},500)),()=>{f&&clearTimeout(f)}),[c]),(0,Y.useEffect)(()=>{l?(A(l.id),S(l.id),y.startDate||N({startDate:null,endDate:null})):(j(null),N({startDate:null,endDate:null}))},[l]),(0,Y.useEffect)(()=>{const e=t.get("userId");if(e&&a.length>0){const t=a.find(t=>t.id===e);t?r(t):E(e)}},[a,t]);const _=async()=>{o(!0);try{const e=await se.listUsers({limit:100});n(e)}catch(e){}finally{o(!1)}},k=async e=>{o(!0);try{const t=await se.listUsers({limit:100,q:JSON.stringify({$or:[{email:{$regex:e,$options:"i"}},{full_name:{$regex:e,$options:"i"}}]})});n(t)}catch(t){}finally{o(!1)}},C=async()=>{const e=await jy.getUserAnalytics();h(e)},A=async e=>{try{const t=await fc.getBonusCredits(e);g(t)}catch(t){g([])}},S=async function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null;const l=Date.now();w.current=l,null!==a&&j(null);try{const n=await ke.default.getUserStats(e,t,s,a);l>=w.current&&j(n)}catch(r){l>=w.current&&j(null)}finally{n&&n()}},E=async e=>{o(!0);try{const t=await se.get(e);r(t)}catch(a){const e=new URLSearchParams(t);e.delete("userId"),s(e)}finally{o(!1)}},I=e=>{u({key:e,direction:m.key===e&&"asc"===m.direction?"desc":"asc"})},T=a.sort((e,t)=>"created_date"===m.key?"asc"===m.direction?new Date(e[m.key])-new Date(t[m.key]):new Date(t[m.key])-new Date(e[m.key]):"asc"===m.direction?e[m.key]>t[m.key]?1:-1:t[m.key]>e[m.key]?1:-1);return e.platform_role.includes("admin")?(0,le.jsxs)("div",{className:"container mx-auto py-10 px-4",children:[(0,le.jsx)("h1",{className:"text-3xl font-bold mb-6",children:"Admin Portal"}),(0,le.jsxs)(kr,{defaultValue:"users",className:"mb-8",children:[(0,le.jsxs)(Cr,{className:"grid grid-cols-5 w-[700px] mb-4",children:[(0,le.jsx)(Ar,{value:"users",children:"User Management"}),(0,le.jsx)(Ar,{value:"organizations",children:"Organizations"}),(0,le.jsx)(Ar,{value:"statistics",children:"Statistics"}),(0,le.jsx)(Ar,{value:"coupons",children:"Coupon Codes"}),(0,le.jsx)(Ar,{value:"changelog",children:"What's New"})]}),(0,le.jsxs)(Sr,{value:"users",children:[(0,le.jsxs)("div",{className:"mb-4",children:[(0,le.jsx)("h2",{className:"text-2xl font-bold mb-4",children:"User Management"}),(0,le.jsx)(oy,{stats:x}),(0,le.jsxs)("div",{className:"flex justify-between items-center mb-6 mt-6",children:[(0,le.jsxs)("div",{className:"relative w-72",children:[(0,le.jsx)(vn.A,{className:"absolute left-2 top-2.5 h-4 w-4 text-gray-500"}),(0,le.jsx)(fs,{placeholder:"Search users...",className:"pl-8",value:c,onChange:e=>d(e.target.value)})]}),(0,le.jsxs)(Yt,{onClick:()=>{const e=T.map(e=>[e.email,e.full_name||"",e.platform_role,ra().utc(e.created_date).format("YYYY-MM-DD HH:mm:ss"),e.subscription_tier||"Free",e.stripe_customer_id||"",e.api_key||""]),t=[["Email","Full Name","Platform Role","Created Date","Subscription Tier","Stripe Customer ID","API Key"].join(","),...e.map(e=>e.map(e=>'"'.concat(e,'"')).join(","))].join("\n"),s=new Blob([t],{type:"text/csv;charset=utf-8;"}),a=document.createElement("a"),n=URL.createObjectURL(s);a.setAttribute("href",n),a.setAttribute("download","users_".concat(ra()().format("YYYY-MM-DD"),".csv")),a.style.visibility="hidden",document.body.appendChild(a),a.click(),document.body.removeChild(a)},className:"flex items-center gap-2",children:[(0,le.jsx)(Gx.A,{className:"h-4 w-4"}),"Download CSV"]})]})]}),(0,le.jsx)("div",{className:"bg-white rounded-lg shadow",children:(0,le.jsxs)(zl,{children:[(0,le.jsx)(Ul,{children:(0,le.jsxs)(Vl,{children:[(0,le.jsx)(Hl,{className:"cursor-pointer",onClick:()=>I("email"),children:(0,le.jsxs)("div",{className:"flex items-center",children:["Email",(0,le.jsx)(ny.A,{className:"ml-2 h-4 w-4"})]})}),(0,le.jsx)(Hl,{className:"cursor-pointer",onClick:()=>I("full_name"),children:(0,le.jsxs)("div",{className:"flex items-center",children:["Full Name",(0,le.jsx)(ny.A,{className:"ml-2 h-4 w-4"})]})}),(0,le.jsx)(Hl,{className:"cursor-pointer",onClick:()=>I("platform_role"),children:(0,le.jsxs)("div",{className:"flex items-center",children:["Platform Role",(0,le.jsx)(ny.A,{className:"ml-2 h-4 w-4"})]})}),(0,le.jsx)(Hl,{className:"cursor-pointer",onClick:()=>I("created_date"),children:(0,le.jsxs)("div",{className:"flex items-center",children:["Created Date",(0,le.jsx)(ny.A,{className:"ml-2 h-4 w-4"})]})}),(0,le.jsx)(Hl,{className:"cursor-pointer",onClick:()=>I("subscription_tier"),children:(0,le.jsxs)("div",{className:"flex items-center",children:["Subscription Plan",(0,le.jsx)(ny.A,{className:"ml-2 h-4 w-4"})]})}),(0,le.jsx)(Hl,{children:"Actions"})]})}),(0,le.jsx)(Wl,{children:i?(0,le.jsx)(Vl,{children:(0,le.jsx)(Yl,{colSpan:6,className:"text-center py-8",children:"Loading users..."})}):0===T.length?(0,le.jsx)(Vl,{children:(0,le.jsx)(Yl,{colSpan:6,className:"text-center py-8",children:"No users found"})}):T.map(e=>{var a,n,l,i,o;return(0,le.jsxs)(Vl,{className:"hover:bg-gray-50 cursor-pointer",onClick:()=>{r(e);const a=new URLSearchParams(t);a.set("userId",e.id),s(a)},children:[(0,le.jsx)(Yl,{className:"font-medium",children:e.email}),(0,le.jsx)(Yl,{children:e.full_name||"-"}),(0,le.jsx)(Yl,{children:(0,le.jsx)("span",{className:"px-2 py-1 rounded-full text-xs ".concat("platform_admin"===e.platform_role?"bg-purple-100 text-purple-800":"bg-gray-100 text-gray-800"),children:e.platform_role})}),(0,le.jsx)(Yl,{children:ra().utc(e.created_date).fromNow()}),(0,le.jsx)(Yl,{children:(0,le.jsx)("span",{className:"px-2 py-1 rounded-full text-xs ".concat(null!==(a=e.subscription_tier)&&void 0!==a&&a.toLowerCase().includes("enterprise")?"bg-yellow-100 text-yellow-800":null!==(n=e.subscription_tier)&&void 0!==n&&n.toLowerCase().includes("elite")?"bg-purple-100 text-purple-800":null!==(l=e.subscription_tier)&&void 0!==l&&l.toLowerCase().includes("pro")?"bg-blue-100 text-blue-800":null!==(i=e.subscription_tier)&&void 0!==i&&i.toLowerCase().includes("builder")?"bg-indigo-100 text-indigo-800":null!==(o=e.subscription_tier)&&void 0!==o&&o.toLowerCase().includes("starter")?"bg-green-100 text-green-800":"bg-gray-100 text-gray-800"),children:e.subscription_tier||"Free"})}),(0,le.jsx)(Yl,{children:(0,le.jsx)(Yt,{variant:"outline",size:"sm",onClick:a=>{a.stopPropagation(),r(e);const n=new URLSearchParams(t);n.set("userId",e.id),s(n)},children:"Edit"})})]},e.id)})})]})})]}),(0,le.jsx)(Sr,{value:"organizations",children:(0,le.jsx)(Ay,{})}),(0,le.jsx)(Sr,{value:"statistics",children:(0,le.jsxs)("div",{children:[(0,le.jsx)("h2",{className:"text-2xl font-bold mb-4",children:"User Statistics"}),(0,le.jsx)(yy,{})]})}),(0,le.jsx)(Sr,{value:"coupons",children:(0,le.jsxs)("div",{children:[(0,le.jsx)("h2",{className:"text-2xl font-bold mb-4",children:"Coupon Code Management"}),(0,le.jsx)(Ey,{})]})}),(0,le.jsx)(Sr,{value:"changelog",children:(0,le.jsx)(Ly,{})})]}),(0,le.jsx)(vy,{selectedUser:l,onClose:()=>{r(null);const e=new URLSearchParams(t);e.delete("userId"),s(e)},onUpdateUser:async(e,t)=>{o(!0);try{const s=await se.updateUser(e,t);n(a.map(t=>t.id===e?s:t)),r(s)}catch(s){}finally{o(!1)}},userBonusCredits:p,onAddBonusCredits:async(e,t,s)=>{o(!0);try{await fc.addBonusCredits(e,t,s),await A(e)}catch(a){}finally{o(!1)}},onDeleteBonusCredit:async e=>{if(l&&e){o(!0);try{await $o.deleteBonusCredits(l.id,e),await A(l.id)}catch(t){}finally{o(!1)}}},loading:i,userUsageStats:b,onDateRangeChange:(e,t,s,a)=>{N({startDate:e,endDate:t}),l?S(l.id,e,t,s,a):a&&a()},dateRange:y})]}):(0,le.jsx)("div",{className:"flex items-center justify-center h-screen",children:(0,le.jsxs)("div",{className:"text-center",children:[(0,le.jsx)(ay.A,{className:"w-16 h-16 text-red-500 mx-auto mb-4"}),(0,le.jsx)("h2",{className:"text-2xl font-bold text-gray-800",children:"Access Denied"}),(0,le.jsx)("p",{className:"text-gray-600",children:"You are not authorized to access this page"})]})})}const Ry=e=>{let{data:t,title:s="Bar Chart",barColor:a="#14b8a6",maxWidth:n="800px",maxLabelWidth:l="40%",backgroundColor:r="white",textColor:i="#1f2937",renderLabel:o=e=>e.name,renderValue:c=e=>e.value}=e;const d=Math.max(...t.map(e=>e.value)),m=t.length,u=m<=5?"40px":m<=10?"32px":m<=20?"24px":"16px",x=m<=5?"14px":m<=10?"12px":m<=20?"10px":"8px";return(0,le.jsxs)("div",{style:{width:"100%",maxWidth:n,margin:"0 auto",padding:"24px",backgroundColor:r,borderRadius:"8px",overflow:"hidden"},children:[s&&(0,le.jsx)("h2",{style:{fontSize:"24px",fontWeight:"bold",marginBottom:"24px",color:i,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:s}),(0,le.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:t.map((e,t)=>{const s=e.value/d*100;return(0,le.jsxs)("div",{style:{position:"relative",height:u,marginBottom:"8px",overflow:"hidden"},children:[(0,le.jsx)("div",{style:{position:"absolute",top:0,left:0,height:"100%",width:"".concat(s,"%"),backgroundColor:a,borderRadius:"4px",transition:"width 0.5s ease-in-out"}}),(0,le.jsx)("div",{style:{position:"absolute",left:"8px",top:"50%",transform:"translateY(-50%)",fontSize:x,fontWeight:"500",color:i,zIndex:1,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",maxWidth:l},children:o(e)}),(0,le.jsx)("div",{style:{position:"absolute",right:"8px",top:"50%",transform:"translateY(-50%)",fontSize:x,fontWeight:"500",color:i,overflow:"hidden",textOverflow:"ellipsis"},children:c(e)})]},t)})})]})};function My(e){var t;let{appId:s,pageNames:a}=e;const[n,l]=(0,Y.useState)(null),[r,i]=(0,Y.useState)({from:void 0,to:void 0}),[o,c]=(0,Y.useState)("all"),[d,m]=(0,Y.useState)(null),[u,x]=(0,Y.useState)(!0),[h,p]=(0,Y.useState)(!1);(0,Y.useEffect)(()=>{(async()=>{x(!0);try{const e={};null!=r&&r.from&&(e.date_from=(0,vh.GP)(r.from,"yyyy-MM-dd")),null!=r&&r.to&&(e.date_to=(0,vh.GP)(r.to,"yyyy-MM-dd")),"all"!==o&&(e.page_name=o),d&&(e.user_email=d);const t=await wa.getStats(s,e);l(t)}catch(e){}finally{x(!1)}})()},[s,r,o,d]);const g=(n?"all"===o?n.top_pages:n.top_pages.filter(e=>e.url===o):[]).map(e=>({name:e.page_name,value:e.visits})),f=null!=n&&n.top_users?h?n.top_users:n.top_users.slice(0,5):[],v=(null==n||null===(t=n.top_users)||void 0===t?void 0:t.length)>5;return u&&!n?(0,le.jsx)("div",{className:"h-full w-full flex items-center justify-center",children:(0,le.jsx)(Ne.A,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):(0,le.jsxs)("div",{className:"space-y-4 p-4",children:[(0,le.jsxs)("div",{className:"flex flex-col sm:flex-row gap-3",children:[(0,le.jsxs)(Nh,{children:[(0,le.jsx)(wh,{asChild:!0,children:(0,le.jsxs)(Yt,{variant:"outline",className:Pe("w-full sm:w-[240px] justify-start text-left font-normal",!r&&"text-muted-foreground"),children:[(0,le.jsx)(bh.A,{className:"mr-2 h-4 w-4"}),null!=r&&r.from?r.to?(0,le.jsxs)(le.Fragment,{children:[(0,vh.GP)(r.from,"LLL dd, y")," - ",(0,vh.GP)(r.to,"LLL dd, y")]}):(0,vh.GP)(r.from,"LLL dd, y"):(0,le.jsx)("span",{children:"Pick a date range"})]})}),(0,le.jsx)(_h,{className:"w-auto p-0",align:"start",children:(0,le.jsx)(fh,{initialFocus:!0,mode:"range",defaultMonth:null==r?void 0:r.from,selected:r,onSelect:i,numberOfMonths:1})})]}),(0,le.jsxs)(zs,{value:o,onValueChange:c,children:[(0,le.jsx)(qs,{className:"w-full sm:w-[240px]",children:(0,le.jsx)(Ws,{placeholder:"Filter by page"})}),(0,le.jsxs)(Ys,{children:[(0,le.jsx)($s,{value:"all",children:"All Pages"}),null==a?void 0:a.map(e=>(0,le.jsx)($s,{value:e,children:e},e))]})]}),d&&(0,le.jsxs)("div",{className:"flex items-center gap-2 bg-muted px-3 py-2 rounded-md",children:[(0,le.jsxs)("span",{className:"text-sm",children:["Filtered by user: ",d]}),(0,le.jsx)("button",{onClick:()=>m(null),className:"text-muted-foreground hover:text-foreground",children:(0,le.jsx)(Gg.A,{className:"h-4 w-4"})})]}),u&&(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[(0,le.jsx)(Ne.A,{className:"h-4 w-4 animate-spin text-muted-foreground"}),(0,le.jsx)("span",{className:"text-sm text-muted-foreground",children:"Updating..."})]})]}),(0,le.jsxs)("div",{className:"grid gap-4 grid-cols-1 md:grid-cols-2",children:[(0,le.jsxs)(is,{children:[(0,le.jsx)(os,{className:"pb-2",children:(0,le.jsx)(cs,{className:"text-lg",children:"Total Unique Users"})}),(0,le.jsx)(ms,{children:(0,le.jsx)("div",{className:"text-3xl font-bold",children:(null==n?void 0:n.unique_users_count)||0})})]}),(0,le.jsxs)(is,{children:[(0,le.jsx)(os,{className:"pb-2",children:(0,le.jsx)(cs,{className:"text-lg",children:"Top Users"})}),(0,le.jsx)(ms,{children:(0,le.jsxs)("div",{className:"space-y-2",children:[f.map((e,t)=>(0,le.jsxs)("div",{className:"flex justify-between items-center text-sm cursor-pointer hover:bg-muted p-2 rounded-md",onClick:()=>m(e.email),children:[(0,le.jsx)("span",{className:"truncate max-w-[180px]",children:e.email}),(0,le.jsxs)("span",{className:"font-semibold",children:[e.visits," visits"]})]},t)),v&&(0,le.jsx)(Yt,{variant:"ghost",className:"w-full mt-2 text-sm text-muted-foreground hover:text-foreground",onClick:()=>p(!h),children:h?(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(Ts.A,{className:"h-4 w-4 mr-2"})," Show Less"]}):(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(Is.A,{className:"h-4 w-4 mr-2"})," Show More Users"]})})]})})]})]}),(0,le.jsxs)(is,{children:[(0,le.jsx)(os,{children:(0,le.jsx)(cs,{className:"text-lg",children:"Top Pages"})}),(0,le.jsxs)(ms,{children:[(0,le.jsx)("p",{className:"text-sm text-muted-foreground mb-4",children:"Shows the most visited pages in your app and their total visit count"}),(0,le.jsx)(Ry,{data:g,title:"",maxWidth:"100%",maxLabelWidth:"60%",backgroundColor:"transparent",renderLabel:e=>"all"===s?(0,le.jsx)(J.Link,{to:"/apps/".concat(e.name),target:"_blank",className:"hover:underline",children:e.name}):e.name})]})]}),(0,le.jsxs)(is,{children:[(0,le.jsx)(os,{children:(0,le.jsx)(cs,{className:"text-lg",children:"Unique Users Over Time"})}),(0,le.jsxs)(ms,{children:[(0,le.jsx)("p",{className:"text-sm text-muted-foreground mb-4",children:"Tracks the number of distinct users accessing your app each day"}),(null==n?void 0:n.users_per_date.length)<=1?(0,le.jsx)("div",{className:"h-[200px] flex items-center justify-center text-muted-foreground",children:"Not enough data to show trends"}):(0,le.jsx)("div",{className:"h-[300px]",children:(0,le.jsx)($u.u,{width:"100%",height:"100%",children:(0,le.jsxs)(ef.Q,{data:n.users_per_date,margin:{top:10,right:10,left:0,bottom:0},children:[(0,le.jsx)(Zu.d,{strokeDasharray:"3 3"}),(0,le.jsx)(Ku.W,{dataKey:"date"}),(0,le.jsx)(Qu.h,{}),(0,le.jsx)(Xu.m,{}),(0,le.jsx)(tf.G,{type:"monotone",dataKey:"unique_users",stroke:"#8884d8",fill:"#8884d8",name:"Unique Users"})]})})})]})]}),(0,le.jsxs)(is,{children:[(0,le.jsx)(os,{children:(0,le.jsx)(cs,{className:"text-lg",children:"Total Usage Over Time"})}),(0,le.jsxs)(ms,{children:[(0,le.jsx)("p",{className:"text-sm text-muted-foreground mb-4",children:"Shows the total number of visits to your app, including repeat visits from the same users"}),(null==n?void 0:n.users_per_date.length)<=1?(0,le.jsx)("div",{className:"h-[200px] flex items-center justify-center text-muted-foreground",children:"Not enough data to show trends"}):(0,le.jsx)("div",{className:"h-[300px]",children:(0,le.jsx)($u.u,{width:"100%",height:"100%",children:(0,le.jsxs)(ef.Q,{data:n.users_per_date,margin:{top:10,right:10,left:0,bottom:0},children:[(0,le.jsx)(Zu.d,{strokeDasharray:"3 3"}),(0,le.jsx)(Ku.W,{dataKey:"date"}),(0,le.jsx)(Qu.h,{}),(0,le.jsx)(Xu.m,{}),(0,le.jsx)(tf.G,{type:"monotone",dataKey:"total_visits",stroke:"#82ca9d",fill:"#82ca9d",name:"Total Visits"})]})})})]})]})]})}const Dy=function(){var e,t;const[s,a]=(0,Y.useState)(null),[n,l]=(0,Y.useState)([]),[r,i]=(0,Y.useState)(!0);if((0,Y.useEffect)(()=>{(async()=>{try{const[e,t]=await Promise.all([jy.getAdminStats(),wa.getTrendingApps()]);a(e),l(t.trending_apps)}catch(e){}finally{i(!1)}})()},[]),r)return(0,le.jsx)("div",{className:"h-full w-full flex items-center justify-center",children:(0,le.jsx)(Ne.A,{className:"h-8 w-8 animate-spin text-muted-foreground"})});const o=(null==s||null===(e=s.usage_by_date)||void 0===e?void 0:e.map(e=>({date:e._id,messages:e.total_messages})))||[],c=(null==s||null===(t=s.tokens_by_user_7d)||void 0===t?void 0:t.map(e=>({user:e._id,tokens:e.total_tokens})))||[],d=n.map(e=>({name:e.name,visits:e.total_visits,users:e.unique_users}));return(0,le.jsxs)("div",{className:"container mx-auto py-6 space-y-6",children:[(0,le.jsx)("h1",{className:"text-2xl font-bold mb-6",children:"Platform Analytics"}),(0,le.jsxs)(is,{children:[(0,le.jsx)(os,{children:(0,le.jsx)(cs,{children:"Messages Per Day"})}),(0,le.jsx)(ms,{children:(0,le.jsx)("div",{className:"h-[400px]",children:(0,le.jsx)($u.u,{width:"100%",height:"100%",children:(0,le.jsxs)(ef.Q,{data:o,children:[(0,le.jsx)(Zu.d,{strokeDasharray:"3 3"}),(0,le.jsx)(Ku.W,{dataKey:"date"}),(0,le.jsx)(Qu.h,{}),(0,le.jsx)(Xu.m,{}),(0,le.jsx)(tf.G,{type:"monotone",dataKey:"messages",stroke:"#8884d8",fill:"#8884d8",fillOpacity:.3})]})})})})]}),(0,le.jsxs)(is,{children:[(0,le.jsx)(os,{children:(0,le.jsx)(cs,{children:"Top Users by Token Usage (Last 7 Days)"})}),(0,le.jsx)(ms,{children:(0,le.jsx)("div",{className:"h-[400px]",children:(0,le.jsx)($u.u,{width:"100%",height:"100%",children:(0,le.jsxs)(Ju.E,{data:c,children:[(0,le.jsx)(Zu.d,{strokeDasharray:"3 3"}),(0,le.jsx)(Ku.W,{dataKey:"user",angle:-45,textAnchor:"end",height:100}),(0,le.jsx)(Qu.h,{}),(0,le.jsx)(Xu.m,{}),(0,le.jsx)(ex.y,{dataKey:"tokens",fill:"#82ca9d"})]})})})})]}),(0,le.jsxs)(is,{children:[(0,le.jsx)(os,{children:(0,le.jsx)(cs,{children:"Trending Apps (Last 7 Days)"})}),(0,le.jsx)(ms,{children:(0,le.jsx)("div",{className:"h-[400px]",children:(0,le.jsx)($u.u,{width:"100%",height:"100%",children:(0,le.jsxs)(Ju.E,{data:d,children:[(0,le.jsx)(Zu.d,{strokeDasharray:"3 3"}),(0,le.jsx)(Ku.W,{dataKey:"name",angle:-45,textAnchor:"end",height:100}),(0,le.jsx)(Qu.h,{}),(0,le.jsx)(Xu.m,{}),(0,le.jsx)(ex.y,{dataKey:"visits",fill:"#8884d8",name:"Total Visits"}),(0,le.jsx)(ex.y,{dataKey:"users",fill:"#82ca9d",name:"Unique Users"})]})})})})]}),(0,le.jsx)(My,{appId:"all"})]})},Fy=["className","variant","size","asChild"],By=(0,Ee.cva)("inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-slate-950 disabled:pointer-events-none disabled:opacity-50 dark:focus-visible:ring-slate-300",{variants:{variant:{default:"bg-slate-900 text-slate-50 shadow hover:bg-slate-900/90",destructive:"bg-red-500 text-slate-50 shadow-sm hover:bg-red-500/90",outline:"border border-slate-200 bg-white shadow-sm hover:bg-slate-100 hover:text-slate-900",secondary:"bg-slate-100 text-slate-900 shadow-sm hover:bg-slate-100/80",ghost:"hover:bg-slate-100 hover:text-slate-900",link:"text-slate-900 underline-offset-4 hover:underline"},size:{default:"h-9 px-4 py-2",sm:"h-8 rounded-md px-3 text-xs",lg:"h-10 rounded-md px-8",icon:"h-9 w-9"}},defaultVariants:{variant:"default",size:"default"}}),zy=Y.forwardRef((e,t)=>{let{className:s,variant:a,size:n,asChild:l=!1}=e,r=(0,Se.A)(e,Fy);const i=l?qt.DX:"button";return(0,le.jsx)(i,(0,K.A)({className:Pe(By({variant:a,size:n,className:s})),ref:t},r))});zy.displayName="Button";const Uy=["className","type"],Wy=Y.forwardRef((e,t)=>{let{className:s,type:a}=e,n=(0,Se.A)(e,Uy);return(0,le.jsx)("input",(0,K.A)({type:a,className:Pe("flex h-9 w-full rounded-md border border-slate-200 bg-transparent px-3 py-1 text-sm shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-slate-500 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-slate-950 disabled:cursor-not-allowed disabled:opacity-50 dark:border-slate-800 dark:placeholder:text-slate-400 dark:focus-visible:ring-slate-300",s),ref:t},n))});function qy(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"/";return function(e){if(!e)return!1;try{const s=decodeURIComponent(e);if(s.match(/^(javascript|data|vbscript|file|about):/i))return!1;if(s.startsWith("/")&&!s.startsWith("//"))return!s.includes(":");let a;try{a=new URL(s)}catch(t){return!1}return!!["http:","https:"].includes(a.protocol)}catch(s){return!1}}(e)?e:t}Wy.displayName="Input";const Vy=e=>{let{buttonText:t={default:"Continue with Google",loading:"Please wait..."},showLastUsed:s=!1}=e;const a=(0,Z.zy)(),n=new URLSearchParams(a.search),[l,r]=(0,Y.useState)(!1);return(0,le.jsxs)("div",{className:"relative",children:[(0,le.jsxs)(zy,{variant:"outline",className:"w-full h-10 bg-white hover:bg-gray-100 py-2 px-4 gap-2.5 rounded-md shadow-xs ".concat(s?"border border-[#FF983B]":"border border-[#E4E4E7]"),type:"button",onClick:async()=>{r(!0);try{sessionStorage.setItem("pendingAuthMethod","google"),localStorage.setItem("lastUsedAuthMethod","google");const e=qy(n.get("from_url"),"/"),t=n.get("ref");let s="".concat((0,ee.Zk)(),"/auth/login?from_url=").concat(encodeURIComponent(e),"&auth_method=google");t&&(s+="&ref=".concat(encodeURIComponent(t))),window.location.href=s}catch(e){r(!1)}},disabled:l,children:[(0,le.jsxs)("svg",{className:"h-4 w-4",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:[(0,le.jsx)("path",{d:"M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z",fill:"#4285F4"}),(0,le.jsx)("path",{d:"M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z",fill:"#34A853"}),(0,le.jsx)("path",{d:"M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z",fill:"#FBBC05"}),(0,le.jsx)("path",{d:"M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z",fill:"#EA4335"})]}),l?t.loading:t.default]}),s&&!l&&(0,le.jsx)("div",{className:"absolute",style:{top:"-25px",right:"20px"},children:(0,le.jsx)("span",{className:"inline-flex items-center px-2 py-1 text-xs font-medium bg-[#FF983B] text-white",style:{borderRadius:"8px 8px 0 0"},children:"Last Used"})})]})},Hy=e=>{let{className:t=""}=e;return(0,le.jsx)("div",{className:"hidden lg:block relative min-h-screen p-4 ".concat(t),children:(0,le.jsx)("div",{className:"h-full w-full bg-white rounded-2xl p-4",children:(0,le.jsxs)("div",{className:"relative h-full w-full",children:[(0,le.jsx)("img",{src:"/assets/auth/auth-page-image.jpg",alt:"Creative workspace",className:"absolute inset-0 h-full w-full object-cover rounded-2xl"}),(0,le.jsx)("div",{className:"absolute inset-0 flex items-center justify-center py-6 px-12 xl:px-16 2xl:px-20",children:(0,le.jsx)("div",{className:"w-full max-w-3xl",children:(0,le.jsx)("div",{className:"bg-gradient-to-br from-white/80 to-white/30 backdrop-blur-md rounded-[12px] xl:rounded-[16px] 2xl:rounded-[20px] p-3 border border-white/30",children:(0,le.jsxs)("div",{className:"flex items-center gap-4",children:[(0,le.jsxs)("div",{className:"flex-1 flex items-center gap-3",children:[(0,le.jsx)("span",{className:"text-slate-400 text-[22px] xl:text-[30px] 2xl:text-[40px] pl-2 font-normal bg-gradient-to-r from-[#BCD2EB] via-[#A7BDD5] to-[#A7BDD5] bg-clip-text text-transparent",children:"Turn your ideas into apps"}),(0,le.jsx)("div",{className:"w-0.5 h-[30px] xl:h-[40px] 2xl:h-[54px] bg-gradient-to-b from-slate-300 to-slate-400"})]}),(0,le.jsx)("div",{className:"flex-shrink-0",children:(0,le.jsx)("div",{className:"w-[30px] h-[30px] xl:w-[40px] xl:h-[40px] 2xl:w-[54px] 2xl:h-[54px] rounded-md xl:rounded-[8px] 2xl:rounded-[12px] bg-gradient-to-br from-slate-400/80 to-slate-300/80 flex items-center justify-center",children:(0,le.jsx)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",className:"text-white",children:(0,le.jsx)("path",{d:"M12 4L12 20M12 4L18 10M12 4L6 10",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})})})]})})})})]})})})},Yy=e=>{let{className:t=""}=e;return(0,le.jsx)("div",{className:"lg:hidden absolute inset-0 ".concat(t),children:(0,le.jsx)("img",{src:"/assets/auth/auth-page-image.jpg",alt:"Creative workspace",className:"absolute inset-0 h-full w-full object-cover"})})},Gy=e=>{let{title:t,subtitle:s,showImageColumn:a=!0,backLink:n,footerContent:l,children:r,className:i=""}=e;return(0,le.jsx)("div",{className:"min-h-screen bg-white",children:(0,le.jsxs)("div",{className:"".concat(a?"grid grid-cols-1 lg:grid-cols-2":""," min-h-screen"),children:[(0,le.jsxs)("div",{className:"relative min-h-screen",children:[(0,le.jsx)(Yy,{}),(0,le.jsx)("div",{className:"absolute top-6 lg:top-8 z-10 ml-4",children:(0,le.jsx)(J.Link,{to:"/",children:(0,le.jsx)("img",{src:"/Logo_v5.png",alt:"Base44",width:"114",height:"28"})})}),(0,le.jsx)("div",{className:"flex items-center justify-center min-h-screen p-6 lg:p-8 relative z-10",children:(0,le.jsxs)("div",{className:"w-full max-w-md bg-white rounded-2xl p-6 lg:p-8 lg:bg-transparent lg:rounded-none space-y-6 shadow-lg lg:shadow-none ".concat(i),children:[n&&(0,le.jsx)("div",{className:"mb-6",children:(0,le.jsxs)(J.Link,{to:n.href,className:"inline-flex items-center text-sm text-[#71717A] hover:text-[#09090B] font-medium",children:[(0,le.jsx)("svg",{className:"w-4 h-4 mr-2",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,le.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 19l-7-7 7-7"})}),n.text]})}),(0,le.jsxs)("div",{className:"space-y-2 text-center",children:[(0,le.jsx)("h1",{className:"text-[20px] lg:text-[48px] font-semibold text-[#09090B] leading-[61px] tracking-[0%] text-center",children:t}),s&&(0,le.jsx)("p",{className:"text-[#71717A] text-base leading-6",children:s})]}),r]})}),l&&(0,le.jsx)("div",{className:"absolute bottom-6 left-6 right-6 lg:bottom-8 lg:left-8 lg:right-8 z-20",children:l})]}),a&&(0,le.jsx)(Hy,{})]})})},$y=()=>{const[e,t]=(0,Y.useState)(!1),[s,a]=(0,Y.useState)(null),[n,l]=(0,Y.useState)(null),[r,i]=(0,Y.useState)(!1),[o,c]=(0,Y.useState)(null),[d,m]=(0,Y.useState)(!1),[u,x]=(0,Y.useState)(!1),[h,p]=(0,Y.useState)(null),[g,f]=(0,Y.useState)(!1),[v,b]=(0,Y.useState)({email:"",password:""}),j=(0,Z.Zp)(),y=(0,Z.zy)(),{isAuthenticated:N}=oe();(0,Y.useEffect)(()=>{if(N){const e=qy(new URLSearchParams(y.search).get("from_url"),"/");j(e)}},[N,j,y.search]),(0,Y.useEffect)(()=>{const e=y.state;null!=e&&e.message&&(l(e.message),e.email&&b(t=>(0,K.A)((0,K.A)({},t),{},{email:e.email})));const t=new URLSearchParams(window.location.search),s=t.get("auth_method"),a=sessionStorage.getItem("pendingAuthMethod");"google"!==s&&"google"!==a||(localStorage.setItem("lastUsedAuthMethod","google"),sessionStorage.removeItem("pendingAuthMethod")),"true"===t.get("auth_success")&&a&&(localStorage.setItem("lastUsedAuthMethod",a),sessionStorage.removeItem("pendingAuthMethod"));const n=localStorage.getItem("lastUsedAuthMethod");c(n)},[y]);const w=e=>{const{name:t,value:r}=e.target;b(e=>(0,K.A)((0,K.A)({},e),{},{[t]:r})),s&&a(null),n&&l(null)};return(0,le.jsxs)(Gy,{title:"Welcome to Base44",showImageColumn:!0,footerContent:(0,le.jsxs)("p",{className:"text-center text-xs text-slate-500",children:[(0,le.jsx)("a",{href:"https://base44.com/terms-of-service",target:"_blank",rel:"noopener noreferrer",className:"font-medium underline hover:text-slate-700 cursor-pointer",children:"Terms of Service"})," ","and"," ",(0,le.jsx)("a",{href:"https://base44.com/privacy-policy",target:"_blank",rel:"noopener noreferrer",className:"font-medium underline hover:text-slate-700 cursor-pointer",children:"Privacy Policy"}),"."]}),children:[(0,le.jsx)(Vy,{buttonText:{default:"Log in with Google",loading:"Logging in..."},showLastUsed:"google"===o}),(0,le.jsxs)("div",{className:"relative",children:[(0,le.jsx)("div",{className:"absolute inset-0 flex items-center",children:(0,le.jsx)(ps,{})}),(0,le.jsx)("div",{className:"relative flex justify-center text-xs uppercase",children:(0,le.jsx)("span",{className:"bg-white px-2 text-slate-500",children:"Or"})})]}),r&&(0,le.jsxs)("div",{className:"p-4 text-sm text-red-600 bg-red-50 border border-red-200 rounded-md",children:["Please verify your email before logging in. Check your email for the verification code.",(0,le.jsx)("div",{className:"mt-2",children:(0,le.jsx)("button",{onClick:async()=>{if(v.email)try{t(!0),await se.resendOtp(v.email),j("/verify-email",{state:{email:v.email,isFromLogin:!0}})}catch(s){a("Failed to resend verification code. Please try again.")}finally{t(!1)}else a("Please enter your email address first.")},disabled:e,className:"text-orange-600 hover:text-orange-500 underline",children:"Resend verification code"})})]}),(0,le.jsxs)("form",{onSubmit:async e=>{if(e.preventDefault(),u)if(null!=h&&h.has_sso)(()=>{if(!h||!h.workspace_id)return void a("SSO configuration error. Please try again.");const e=new URLSearchParams(window.location.search).get("from_url")||"/",t="".concat((0,ee.Zk)(),"/workspaces/").concat(h.workspace_id,"/auth/sso/login?from_url=").concat(encodeURIComponent(e));window.location.replace(t)})();else{t(!0),a(null),l(null),i(!1);try{const e=await se.login(v.email,v.password,null);if(e.success&&e.access_token){(0,ne.O5)(e.access_token),localStorage.setItem("lastUsedAuthMethod","email");const t=new URLSearchParams(window.location.search),s=qy(t.get("from_url"),"/");window.location.href=s}else a("Login failed. Please try again.")}catch(s){var n;if(400===(null===(n=s.response)||void 0===n?void 0:n.status)){var r;const t=(null===(r=s.response.data)||void 0===r?void 0:r.detail)||"Invalid email or password";t.includes("verify your email")?(i(!0),a("Please verify your email before logging in. Check your email for the verification code.")):a(t)}else a("Login failed. Please try again.")}finally{t(!1)}}else await(async()=>{var e;const t=v.email;if(t.includes("@")&&null!==(e=t.split("@")[1])&&void 0!==e&&e.includes(".")){f(!0),a(null);try{const e=await se.checkDomainSSO(t);p(e),x(!0),m(!e.has_sso)}catch(s){x(!0),m(!0),p(null)}finally{f(!1)}}else a("Please enter a valid email address")})()},className:"space-y-6",children:[(0,le.jsxs)("div",{className:"relative",children:[(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsx)("label",{htmlFor:"email",className:"text-sm font-medium leading-5 tracking-normal text-[#09090B]",children:"Email"}),(0,le.jsxs)("div",{className:"relative",children:[(0,le.jsx)(Wy,{name:"email",type:"email",placeholder:"Enter your email address",value:v.email,onChange:e=>{w(e),u&&(x(!1),m(!1),p(null))},required:!0,disabled:e||u,className:"bg-white text-[#09090B] h-9 px-3 py-1 rounded-md shadow-xs border border-[#E4E4E7] w-full ".concat(u?"pr-12":"")}),u&&!g&&(0,le.jsx)("button",{type:"button",onClick:()=>{x(!1),m(!1),p(null),a(null)},className:"absolute right-3 top-1/2 transform -translate-y-1/2 text-sm font-medium text-[#71717A] hover:text-[#09090B] underline",children:"Edit"})]})]}),"email"===o&&!u&&(0,le.jsx)("div",{className:"absolute -top-2 right-0",children:(0,le.jsx)("span",{className:"inline-flex items-center px-2 py-1 rounded-md text-xs font-medium bg-[#FF983B] text-white",children:"Last Used"})})]}),u&&!g&&(0,le.jsx)(le.Fragment,{children:null!=h&&h.has_sso?(0,le.jsxs)("div",{className:"p-3 bg-slate-50 border border-slate-200 rounded-md",children:[(0,le.jsxs)("p",{className:"text-sm text-slate-800",children:["SSO is enabled for ",(0,le.jsx)("strong",{children:h.workspace_name})]}),(0,le.jsx)("p",{className:"text-xs text-slate-600 mt-1",children:"Click below to continue with your organization's login"})]}):(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsxs)("div",{className:"flex items-center justify-between",children:[(0,le.jsx)("label",{htmlFor:"password",className:"text-sm font-medium leading-5 tracking-normal text-[#09090B]",children:"Password"}),(0,le.jsx)(J.Link,{to:"/forgot-password",className:"text-sm font-medium leading-5 tracking-normal text-[#71717A]",children:"Forgot password?"})]}),(0,le.jsx)(Wy,{name:"password",type:"password",placeholder:"Enter your password",value:v.password,onChange:w,required:!(null!=h&&h.has_sso),disabled:e,autoFocus:!0,className:"bg-white text-[#09090B] h-9 px-3 py-1 rounded-md shadow-xs ".concat(s&&!r&&u?"border border-[#DC2626]":"border border-[#E4E4E7]")})]})}),s&&!r&&(0,le.jsx)("p",{className:"text-[14px] leading-[20px] tracking-[0%] text-[#DC2626] font-normal",children:s}),g&&(0,le.jsxs)("div",{className:"flex items-center justify-center gap-2 text-sm text-gray-500",children:[(0,le.jsx)("div",{className:"animate-spin rounded-full h-4 w-4 border-b-2 border-gray-500"}),"Checking authentication method..."]}),(0,le.jsxs)("div",{className:"space-y-4",children:[(0,le.jsx)(zy,{type:"submit",className:"w-full h-[40px] bg-black text-[#FAFAFA] border border-[#E4E4E7] rounded-md shadow-xs px-4 py-2",disabled:e||g||!u&&!v.email,children:g?"Checking...":e?"Logging in...":u?null!=h&&h.has_sso?"Continue with ".concat(h.sso_provider||"SSO"):"Log In":"Continue"}),n&&(0,le.jsx)("div",{className:"p-4 text-sm text-green-600 bg-green-50 border border-green-200 rounded-md",children:n}),(0,le.jsxs)("p",{className:"text-center text-sm text-[#71717A]",children:["Don't have an account?"," ",(0,le.jsx)(J.Link,{to:"/register".concat(y.search),className:"font-medium text-black underline",children:"Sign up"})]})]})]})]})},Jy=e=>{let{name:t,value:s,onChange:a,placeholder:n="Enter your email address",required:l=!1,disabled:r=!1,label:i="Email",onValidationChange:o}=e;const[c,d]=Y.useState(null);return(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsx)("label",{htmlFor:t,className:"text-sm font-medium leading-5 tracking-normal text-[#09090B]",children:i}),(0,le.jsx)(Wy,{name:t,type:"email",placeholder:n,value:s,onChange:e=>{const{value:t}=e.target;c&&(d(null),null==o||o(!0)),a(e)},onBlur:e=>{const{value:t}=e.target;t&&!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t)?(d("That's not a valid email. Try a different email address."),null==o||o(!1)):t&&(d(null),null==o||o(!0))},required:l,disabled:r,className:"bg-white text-[#09090B] h-9 px-3 py-1 rounded-md shadow-xs ".concat(c?"border border-[#DC2626]":"border border-[#E4E4E7]")}),c&&(0,le.jsx)("p",{className:"text-[14px] leading-[20px] tracking-[0%] text-[#DC2626] font-normal mt-1",children:c})]})},Zy=(0,Y.forwardRef)((e,t)=>{let{siteKey:s,onSuccess:a,onError:n,onExpired:l,theme:r="light",size:i="normal",className:o=""}=e;const c=(0,Y.useRef)(null),[d,m]=(0,Y.useState)(null),[u,x]=(0,Y.useState)(!1);(0,Y.useEffect)(()=>{const e=()=>{window.turnstile?x(!0):setTimeout(e,100)};e()},[]),(0,Y.useEffect)(()=>{if(u&&c.current&&!d)try{const e=window.turnstile.render(c.current,{sitekey:s,theme:r,size:i,callback:e=>{null==a||a(e)},"error-callback":e=>{null==n||n(e)},"expired-callback":()=>{null==l||l()}});m(e)}catch(e){null==n||n("Failed to load security verification")}return()=>{if(d&&window.turnstile)try{window.turnstile.remove(d)}catch(e){}}},[u,s,r,i,d,a,n,l]);const h=()=>{if(d&&window.turnstile)try{window.turnstile.reset(d)}catch(e){}},p=()=>{if(d&&window.turnstile)try{return window.turnstile.getResponse(d)}catch(e){return""}return""};return(0,Y.useImperativeHandle)(t,()=>({reset:h,getResponse:p})),(0,le.jsx)("div",{className:"turnstile-container ".concat(o),children:(0,le.jsx)("div",{ref:c})})});Zy.displayName="Turnstile";const Ky=Zy,Qy="0x4AAAAAABkwg1ZNNlkay6SI",Xy="light",eN="normal",tN=!0,sN=e=>e&&e.length>0,aN=e=>{let{onSuccess:t,onError:s,onExpired:a,isVerified:n=!1,className:l=""}=e;return tN?n?null:(0,le.jsx)("div",{className:"space-y-2 ".concat(l),children:(0,le.jsx)(Ky,{siteKey:Qy,theme:Xy,size:eN,onSuccess:t,onError:s,onExpired:a,className:"flex justify-center"})}):null};class nN extends Q.H{getBaseURL(){return"/referrals"}async generateReferralCode(){try{return(await this.axios.post("/generate-code")).referral_code}catch(s){var e,t;throw new Error((null===(e=s.response)||void 0===e||null===(t=e.data)||void 0===t?void 0:t.detail)||"Failed to generate referral code")}}async validateReferralCode(e){try{return await this.axios.post("/validate",{referral_code:e})}catch(a){var t,s;throw new Error((null===(t=a.response)||void 0===t||null===(s=t.data)||void 0===s?void 0:s.detail)||"Failed to validate referral code")}}async getReferralStats(){try{return await this.axios.get("/stats")}catch(s){var e,t;throw new Error((null===(e=s.response)||void 0===e||null===(t=e.data)||void 0===t?void 0:t.detail)||"Failed to fetch referral statistics")}}}const lN=new nN,rN=e=>{const t=e.length>=8,s=/[a-z]/.test(e)&&/[A-Z]/.test(e),a=/[#$&@!%*?&]/.test(e);let n=0;t&&n++,s&&n++,a&&n++;let l="Weak password";return n>=3?l="Strong password":n>=2&&(l="Average password"),{score:n,label:l,hasMinLength:t,hasUpperLower:s,hasSymbol:a}},iN=e=>e>=3?"bg-green-500":e>=2?"bg-yellow-500":"bg-orange-500",oN=e=>{const t=[];for(let s=0;s<3;s++)t.push((0,le.jsx)("div",{className:"h-1 flex-1 rounded-full ".concat(s{let{password:t,showTooltip:s,onMouseEnter:a,onMouseLeave:n}=e;const l=rN(t);return s&&t?(0,le.jsxs)("div",{className:"absolute left-full top-1/2 -translate-y-1/2 ml-3 w-[265px] bg-white border border-[#E4E4E7] rounded-lg shadow-lg py-3 px-3 z-10",style:{borderRadius:"8px"},onMouseEnter:a,onMouseLeave:n,children:[(0,le.jsx)("div",{className:"absolute right-full top-1/2 -translate-y-1/2 w-0 h-0 border-t-[6px] border-b-[6px] border-r-[6px] border-t-transparent border-b-transparent border-r-[#E4E4E7]"}),(0,le.jsx)("div",{className:"absolute right-full top-1/2 -translate-y-1/2 translate-x-px w-0 h-0 border-t-[6px] border-b-[6px] border-r-[6px] border-t-transparent border-b-transparent border-r-white"}),(0,le.jsxs)("div",{className:"space-y-3",children:[(0,le.jsxs)("div",{children:[(0,le.jsx)("div",{className:"flex justify-between items-center mb-2",children:(0,le.jsx)("span",{className:"text-sm font-medium text-[#09090B]",children:l.label})}),(0,le.jsx)("div",{className:"flex space-x-1",children:oN(l.score)})]}),(0,le.jsxs)("div",{children:[(0,le.jsx)("p",{className:"text-sm text-[#71717A] mb-2",children:"Password must include:"}),(0,le.jsxs)("ul",{className:"space-y-1 text-sm",children:[(0,le.jsxs)("li",{className:"flex items-center gap-2",children:[(0,le.jsx)("div",{className:"w-[18px] h-[18px] rounded-full border-2 flex items-center justify-center border-[#71717A]",children:l.hasMinLength&&(0,le.jsx)("svg",{width:"10",height:"8",viewBox:"0 0 10 8",fill:"none",children:(0,le.jsx)("path",{d:"M9 1L3.5 6.5L1 4",stroke:"#71717A",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),(0,le.jsx)("span",{className:"text-[#09090B]",children:"At least 8 characters"})]}),(0,le.jsxs)("li",{className:"flex items-center gap-2",children:[(0,le.jsx)("div",{className:"w-[18px] h-[18px] rounded-full border-2 flex items-center justify-center border-[#71717A]",children:l.hasUpperLower&&(0,le.jsx)("svg",{width:"10",height:"8",viewBox:"0 0 10 8",fill:"none",children:(0,le.jsx)("path",{d:"M9 1L3.5 6.5L1 4",stroke:"#71717A",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),(0,le.jsx)("span",{className:"text-[#09090B]",children:"Upper & lower case letters"})]}),(0,le.jsxs)("li",{className:"flex items-center gap-2",children:[(0,le.jsx)("div",{className:"w-[18px] h-[18px] rounded-full border-2 flex items-center justify-center border-[#71717A]",children:l.hasSymbol&&(0,le.jsx)("svg",{width:"10",height:"8",viewBox:"0 0 10 8",fill:"none",children:(0,le.jsx)("path",{d:"M9 1L3.5 6.5L1 4",stroke:"#71717A",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),(0,le.jsx)("span",{className:"text-[#09090B]",children:"A symbol (#$&)"})]})]})]})]})]}):null},dN=e=>{let{password:t,showTooltip:s}=e;const a=rN(t);return s&&t?(0,le.jsxs)("div",{className:"w-full bg-[#F8F9FA] border border-[#E4E4E7] rounded-xl p-4 space-y-3",children:[(0,le.jsx)("p",{className:"text-sm font-medium text-[#09090B] mb-3",children:"Password must include:"}),(0,le.jsxs)("ul",{className:"space-y-3",children:[(0,le.jsxs)("li",{className:"flex items-center gap-3",children:[(0,le.jsx)("div",{className:"w-5 h-5 rounded-full border-2 flex items-center justify-center ".concat(a.hasMinLength?"bg-[#71717A] border-[#71717A]":"border-[#71717A] bg-transparent"),children:a.hasMinLength&&(0,le.jsx)("svg",{width:"12",height:"10",viewBox:"0 0 12 10",fill:"none",children:(0,le.jsx)("path",{d:"M10 2L4.5 7.5L2 5",stroke:"white",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}),(0,le.jsx)("span",{className:"text-sm text-[#09090B]",children:"At least 8 characters"})]}),(0,le.jsxs)("li",{className:"flex items-center gap-3",children:[(0,le.jsx)("div",{className:"w-5 h-5 rounded-full border-2 flex items-center justify-center ".concat(a.hasUpperLower?"bg-[#71717A] border-[#71717A]":"border-[#71717A] bg-transparent"),children:a.hasUpperLower&&(0,le.jsx)("svg",{width:"12",height:"10",viewBox:"0 0 12 10",fill:"none",children:(0,le.jsx)("path",{d:"M10 2L4.5 7.5L2 5",stroke:"white",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}),(0,le.jsx)("span",{className:"text-sm text-[#09090B]",children:"Upper & lower case letters"})]}),(0,le.jsxs)("li",{className:"flex items-center gap-3",children:[(0,le.jsx)("div",{className:"w-5 h-5 rounded-full border-2 flex items-center justify-center ".concat(a.hasSymbol?"bg-[#71717A] border-[#71717A]":"border-[#71717A] bg-transparent"),children:a.hasSymbol&&(0,le.jsx)("svg",{width:"12",height:"10",viewBox:"0 0 12 10",fill:"none",children:(0,le.jsx)("path",{d:"M10 2L4.5 7.5L2 5",stroke:"white",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}),(0,le.jsx)("span",{className:"text-sm text-[#09090B]",children:"At least one symbol (#$&)"})]})]})]}):null},mN=e=>{let{email:t,onSuccess:s,successRedirectPath:a="/login",isFromLogin:n=!1}=e;const[l,r]=(0,Y.useState)(!1),[i,o]=(0,Y.useState)(null),[c,d]=(0,Y.useState)(["","","","","",""]),[m,u]=(0,Y.useState)([!1,!1,!1,!1,!1,!1]),[x,h]=(0,Y.useState)(null),p=(0,Z.Zp)(),g=(0,Y.useRef)([]);(0,Y.useEffect)(()=>{var e;null===(e=g.current[0])||void 0===e||e.focus()},[]);const f=e=>{e.preventDefault();const t=e.clipboardData.getData("text").slice(0,6),s=[...c];for(let r=0;r!e);var n,l;-1!==a?null===(n=g.current[a])||void 0===n||n.focus():null===(l=g.current[5])||void 0===l||l.focus()};return(0,le.jsxs)(Gy,{title:"Verify your email",subtitle:"We sent a verification code to ".concat(t),showImageColumn:!0,children:[i&&(0,le.jsx)("div",{className:"p-4 text-sm text-red-600 bg-red-50 border border-red-200 rounded-md",children:i}),(0,le.jsxs)("form",{onSubmit:async e=>{e.preventDefault(),r(!0),o(null),h(null);const l=c.map(e=>!e);if(l.some(e=>e))return u(l),h("Please fill out all fields."),void r(!1);const d=c.join("");try{const e=await se.verifyOtp(t,d);e.success?(n||(Nc("registration_completed",{email:(0,_c.sha256)(t),user_id:e.id,registration_method:"email&password"}),Ke(e.id)),s?s():p(a,{state:{message:n?"Email verified successfully! You can now log in.":"Email verified successfully! Please log in to continue.",email:t}})):o("Invalid verification code. Please try again.")}catch(i){var m,x;if(400===(null===(m=i.response)||void 0===m?void 0:m.status)||429===(null===(x=i.response)||void 0===x?void 0:x.status)){var g;const t=(null===(g=i.response.data)||void 0===g?void 0:g.detail)||"Invalid verification code";o(t)}else o("Verification failed. Please try again.")}finally{r(!1)}},className:"space-y-6",children:[(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsx)("label",{htmlFor:"otpCode",className:"text-sm font-medium leading-5 tracking-normal text-[#09090B]",children:"Verification Code"}),(0,le.jsx)("div",{className:"flex gap-2",children:c.map((e,t)=>(0,le.jsx)(Wy,{name:"otpCode".concat(t),type:"text",inputMode:"numeric",pattern:"\\d{1}",value:e,onChange:e=>((e,t)=>{if(t.length>1)return;const s=[...c];if(s[e]=t,d(s),t){const t=[...m];t[e]=!1,u(t),s.every(e=>e)&&h(null)}var a;t&&e<5&&(null===(a=g.current[e+1])||void 0===a||a.focus())})(t,e.target.value),onKeyDown:e=>((e,t)=>{var s;"Backspace"===t.key&&!c[e]&&e>0&&(null===(s=g.current[e-1])||void 0===s||s.focus())})(t,e),onPaste:0===t?f:void 0,disabled:l,className:"w-11 h-11 text-center text-lg font-semibold bg-white text-[#09090B] rounded-md shadow-xs ".concat(m[t]?"border border-[#DC2626]":"border border-[#E4E4E7] focus:border-slate-400 focus:ring-slate-400"),maxLength:1,ref:e=>g.current[t]=e},t))}),x&&(0,le.jsx)("p",{className:"text-[14px] leading-[20px] tracking-[0%] text-[#DC2626] font-normal mt-1",children:x}),(0,le.jsx)("p",{className:"text-xs text-slate-500 mt-3",children:"Enter the verification code sent to your email"})]}),(0,le.jsxs)("div",{className:"space-y-4",children:[(0,le.jsx)(zy,{type:"submit",className:"w-full h-[40px] bg-black text-[#FAFAFA] border border-[#E4E4E7] rounded-md shadow-xs px-4 py-2",disabled:l,children:l?"Verifying...":"Verify Email"}),(0,le.jsxs)("p",{className:"text-sm text-slate-600",children:["Didn't receive the code?"," ",(0,le.jsx)("button",{type:"button",onClick:async()=>{try{var e;r(!0),o(null),await se.resendOtp(t),o("New verification code sent to your email."),d(["","","","","",""]),null===(e=g.current[0])||void 0===e||e.focus()}catch(i){o("Failed to resend verification code. Please try again.")}finally{r(!1)}},disabled:l,className:"font-medium text-black hover:text-slate-700 underline",children:"Resend email"})]})]})]})]})};var uN=s(29221);const xN=()=>{const[e]=(0,J.useSearchParams)(),t=(0,Z.Zp)(),s=(0,Z.zy)(),a=e.get("ref"),[n,l]=(0,Y.useState)(!1),[r,i]=(0,Y.useState)(null),[o,c]=(0,Y.useState)({isValidating:!1,isValid:null,referrerInfo:null,validationMessage:null}),[d,m]=(0,Y.useState)(!1),[u,x]=(0,Y.useState)(""),[h,p]=(0,Y.useState)(!1),[g,f]=(0,Y.useState)(null),[v,b]=(0,Y.useState)(!1),[j,y]=(0,Y.useState)({score:0,label:"Weak password",hasMinLength:!1,hasUpperLower:!1,hasSymbol:!1}),[N,w]=(0,Y.useState)({email:"",password:""}),{user:_,isAuthenticated:k}=oe();(0,Y.useEffect)(()=>{if(k){const e=qy(new URLSearchParams(s.search).get("from_url"),"/");t(e)}},[k,t,s.search]),(0,Y.useEffect)(()=>{const e="sign_up",t={user_id:k&&null!=_&&_.id?_.id:null,app_id:null,conversation_id:null};xt(t,{page_name:e}),tt("Page View",{page_name:e,page_url:window.location.pathname,user_id:t.user_id})},[]);const{turnstileToken:C,isVerified:A,handleTurnstileSuccess:S,handleTurnstileError:E,handleTurnstileExpired:I,validateTurnstileToken:T}=(e=>{const[t,s]=(0,Y.useState)(null),a=sN(t),n=(0,Y.useCallback)(t=>{s(t),e&&e("")},[e]),l=(0,Y.useCallback)(t=>{s(null),e&&e((e=>{switch(e){case"timeout":return"Security verification timed out. Please try again.";case"network-error":return"Network error during security verification. Please check your connection.";case"invalid-sitekey":return"Invalid security configuration. Please contact support.";default:return"Security verification failed. Please try again."}})(t))},[e]),r=(0,Y.useCallback)(()=>{s(null)},[]),i=(0,Y.useCallback)(()=>!(tN&&!sN(t)&&(e&&e("Please complete the security verification"),1)),[t,e]),o=(0,Y.useCallback)(t=>{e&&e(t)},[e]),c=(0,Y.useCallback)(()=>{e&&e("")},[e]);return{turnstileToken:t,isVerified:a,handleTurnstileSuccess:n,handleTurnstileError:l,handleTurnstileExpired:r,validateTurnstileToken:i,setError:o,clearError:c}})(i);(0,Y.useEffect)(()=>()=>{g&&clearTimeout(g)},[g]),(0,Y.useEffect)(()=>{a&&P()},[a]);const P=async()=>{if(a){c(e=>(0,K.A)((0,K.A)({},e),{},{isValidating:!0}));try{const e=await lN.validateReferralCode(a);c({isValidating:!1,isValid:e.is_valid,referrerInfo:e.referrer,validationMessage:e.message})}catch(r){c({isValidating:!1,isValid:!1,referrerInfo:null,validationMessage:"Failed to validate referral code"})}}},L=e=>{const{name:t,value:s}=e.target;w(e=>(0,K.A)((0,K.A)({},e),{},{[t]:s})),"password"===t&&y(rN(s)),r&&i(null)};if(d){const e="/login".concat(s.search);return(0,le.jsx)(mN,{email:u,isFromLogin:!1,successRedirectPath:e})}return(0,le.jsxs)(Gy,{title:"Create your account",showImageColumn:!0,footerContent:(0,le.jsxs)("p",{className:"text-center text-xs text-slate-500",children:['By clicking "Sign Up", you agree to our'," ",(0,le.jsx)("a",{href:"https://base44.com/terms-of-service",target:"_blank",rel:"noopener noreferrer",className:"font-medium underline hover:text-slate-700 cursor-pointer",children:"Terms of Service"})," ","and"," ",(0,le.jsx)("a",{href:"https://base44.com/privacy-policy",target:"_blank",rel:"noopener noreferrer",className:"font-medium underline hover:text-slate-700 cursor-pointer",children:"Privacy Policy"}),"."]}),children:[a&&(0,le.jsx)("div",{className:"mb-6 p-4 rounded-lg text-center border ".concat((o.isValidating||o.isValid,"bg-gray-50 border-gray-200")),children:o.isValidating?(0,le.jsxs)("div",{className:"flex items-center justify-center",children:[(0,le.jsx)("div",{className:"animate-spin rounded-full h-4 w-4 border-b-2 border-gray-600 mr-2"}),(0,le.jsx)("span",{className:"text-sm font-medium text-gray-800",children:"Validating referral code..."})]}):!1===o.isValid?(0,le.jsxs)("div",{children:[(0,le.jsxs)("div",{className:"flex items-center justify-center mb-2",children:[(0,le.jsx)(uN.A,{className:"h-5 w-5 text-gray-600 mr-2"}),(0,le.jsx)("span",{className:"text-sm font-medium text-gray-800",children:"Invalid Referral Code"})]}),(0,le.jsx)("p",{className:"text-sm text-gray-700",children:o.validationMessage})]}):o.isValid&&o.referrerInfo?(0,le.jsxs)("div",{children:[(0,le.jsxs)("div",{className:"flex items-center justify-center mb-2",children:[(0,le.jsx)("svg",{className:"h-5 w-5 text-gray-600 mr-2",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,le.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M16 12a4 4 0 10-8 0 4 4 0 008 0zm0 0v1.5a2.5 2.5 0 005 0V12a9 9 0 10-9 9m4.5-1.206a8.959 8.959 0 01-4.5 1.207"})}),(0,le.jsx)("span",{className:"text-sm font-medium text-gray-800",children:"You've been invited!"})]}),(0,le.jsxs)("p",{className:"text-sm text-gray-700 mb-1",children:[(0,le.jsx)("strong",{children:o.referrerInfo.first_name||o.referrerInfo.email})," invited you to join Base44"]}),(0,le.jsx)("p",{className:"text-sm text-gray-600",children:"Sign up to get 10 free credits!"})]}):(0,le.jsxs)("div",{children:[(0,le.jsx)("span",{className:"text-sm font-medium text-gray-800",children:"You've been invited!"}),(0,le.jsx)("p",{className:"text-sm text-gray-700",children:"Let's build something amazing together!"}),(0,le.jsx)("p",{className:"text-sm text-gray-600",children:"Sign up to get 10 free credits!"})]})}),(0,le.jsx)(Vy,{buttonText:{default:"Sign up with Google",loading:"Signing up..."}}),(0,le.jsxs)("div",{className:"relative",children:[(0,le.jsx)("div",{className:"absolute inset-0 flex items-center",children:(0,le.jsx)(ps,{})}),(0,le.jsx)("div",{className:"relative flex justify-center text-xs uppercase",children:(0,le.jsx)("span",{className:"bg-white px-2 text-slate-500",children:"Or"})})]}),r&&(0,le.jsx)("div",{className:"p-4 text-sm text-red-600 bg-red-50 rounded-md",children:r}),(0,le.jsxs)("form",{onSubmit:async e=>{if(e.preventDefault(),l(!0),i(null),T())try{const e=a&&o.isValid?a:null;(await se.register(N.email,N.password,C,e)).id?(x(N.email),m(!0),i(null)):i("Registration failed. Please try again.")}catch(r){var t;if(400===(null===(t=r.response)||void 0===t?void 0:t.status)){var s;const t=(null===(s=r.response.data)||void 0===s?void 0:s.detail)||"Registration failed";i(t)}else i("Registration failed. Please try again.")}finally{l(!1)}else l(!1)},className:"space-y-6",children:[(0,le.jsx)(Jy,{name:"email",value:N.email,onChange:e=>{L(e)},placeholder:"Enter your email address",required:!0,disabled:n,label:"Email"}),(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsx)("label",{htmlFor:"password",className:"text-sm font-medium leading-5 tracking-normal text-[#09090B]",children:"Password"}),(0,le.jsxs)("div",{className:"relative",children:[(0,le.jsx)(Wy,{name:"password",type:v?"text":"password",placeholder:"Enter your password",value:N.password,onChange:L,onFocus:()=>{g&&(clearTimeout(g),f(null)),p(!0)},onBlur:()=>{const e=setTimeout(()=>{p(!1)},150);f(e)},required:!0,disabled:n,className:"bg-white text-[#09090B] h-9 px-3 py-1 pr-20 border border-[#E4E4E7] rounded-md shadow-xs",minLength:8}),N.password&&(0,le.jsx)("div",{className:"absolute right-9 top-1/2 -translate-y-1/2 h-[18px] flex items-center",children:(0,le.jsx)("span",{className:"text-xs text-[#71717A] font-normal leading-none tracking-normal",children:j.label.replace(" password","")})}),N.password&&(0,le.jsx)("button",{type:"button",onClick:()=>b(!v),className:"absolute right-3 top-1/2 -translate-y-1/2 w-[18px] h-[18px] flex items-center justify-center text-[#71717A] hover:text-[#09090B]",children:v?(0,le.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,le.jsx)("path",{d:"M17.94 17.94A10.07 10.07 0 0 1 12 20c-7 0-11-8-11-8a18.45 18.45 0 0 1 5.06-5.94M9.9 4.24A9.12 9.12 0 0 1 12 4c7 0 11 8 11 8a18.5 18.5 0 0 1-2.16 3.19m-6.72-1.07a3 3 0 1 1-4.24-4.24"}),(0,le.jsx)("line",{x1:"1",y1:"1",x2:"23",y2:"23"})]}):(0,le.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,le.jsx)("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"}),(0,le.jsx)("circle",{cx:"12",cy:"12",r:"3"})]})}),(0,le.jsx)("div",{className:"hidden lg:block",children:(0,le.jsx)(cN,{password:N.password,showTooltip:h,onMouseEnter:()=>{g&&(clearTimeout(g),f(null))},onMouseLeave:()=>{p(!1)}})})]})]}),(0,le.jsx)("div",{className:"lg:hidden",children:(0,le.jsx)(dN,{password:N.password,showTooltip:!!N.password})}),(0,le.jsxs)("div",{className:"space-y-4",children:[(0,le.jsx)(zy,{type:"submit",className:"w-full h-[40px] bg-black text-[#FAFAFA] border border-[#E4E4E7] rounded-md shadow-xs px-4 py-2",disabled:n||j.score<3,children:n?"Creating account...":"Sign Up"}),(0,le.jsx)(aN,{onSuccess:S,onError:E,onExpired:I,isVerified:A,className:"flex justify-center"}),(0,le.jsxs)("p",{className:"text-center text-sm text-[#71717A]",children:["Already have a Base44 account?"," ",(0,le.jsx)(J.Link,{to:"/login".concat(s.search),className:"font-medium text-black underline",children:"Log in"})]})]})]})]})},hN=()=>{var e,t;const s=(0,Z.zy)(),a=(0,Z.g)(),n=(null===(e=s.state)||void 0===e?void 0:e.email)||a.email||new URLSearchParams(s.search).get("email"),l=(null===(t=s.state)||void 0===t?void 0:t.isFromLogin)||!1;return n?(0,le.jsx)(mN,{email:n,isFromLogin:l,successRedirectPath:"/login"}):(0,le.jsx)(Z.C5,{to:"/login",replace:!0})},pN=()=>{const[e,t]=(0,Y.useState)(!1),[s,a]=(0,Y.useState)(null),[n,l]=(0,Y.useState)(""),r=(0,Z.Zp)();return(0,le.jsxs)(Gy,{title:"Reset your password",subtitle:"Enter the email address you used to sign up, and we'll send you a link to reset your password.",showImageColumn:!0,backLink:{href:"/login",text:"Back to log in"},children:[s&&(0,le.jsx)("div",{className:"p-4 text-sm text-red-600 bg-red-50 border border-red-200 rounded-md",children:s}),(0,le.jsxs)("form",{onSubmit:async e=>{e.preventDefault(),t(!0),a(null);try{await se.resetPasswordRequest(n,null);r("/check-email",{state:{email:n}})}catch(s){var l;if(400===(null===(l=s.response)||void 0===l?void 0:l.status)){var i;const t=(null===(i=s.response.data)||void 0===i?void 0:i.detail)||"Invalid email address";a(t)}else a("Failed to send reset link. Please try again.")}finally{t(!1)}},className:"space-y-6",children:[(0,le.jsx)(Jy,{name:"email",value:n,onChange:e=>{(e=>{l(e.target.value),s&&a(null)})(e)},placeholder:"e.g., name@email.com",required:!0,disabled:e,label:"Login email"}),(0,le.jsx)("div",{className:"space-y-4",children:(0,le.jsx)(zy,{type:"submit",className:"w-full h-[40px] bg-black text-[#FAFAFA] border border-[#E4E4E7] rounded-md shadow-xs px-4 py-2",disabled:e,children:e?"Sending...":"Verify Email"})})]})]})},gN=()=>{const[e,t]=(0,Y.useState)(!1),[s,a]=(0,Y.useState)(null),[n,l]=(0,Y.useState)(""),r=(0,Z.zy)(),i=(0,Z.Zp)();(0,Y.useEffect)(()=>{const e=r.state;null!=e&&e.email&&l(e.email)},[r]);return(0,le.jsxs)(Gy,{title:"Check your email",subtitle:(0,le.jsxs)(le.Fragment,{children:["We've sent password reset instructions to"," ",(0,le.jsx)("span",{className:"font-medium text-[#09090B]",children:n}),"."]}),showImageColumn:!0,backLink:{href:"/forgot-password",text:"Back to Reset password"},children:[(0,le.jsx)("div",{className:"py-3 px-4 bg-[#FAFAFA] border border-[#E4E4E7] rounded-lg gap-x-3",children:(0,le.jsxs)("p",{className:"text-sm text-[#71717A] text-center leading-relaxed",children:[(0,le.jsx)("span",{className:"block",children:"Please check your email for the password reset link."}),(0,le.jsx)("span",{className:"block",children:"It may take a few minutes to arrive."})]})}),s&&(0,le.jsx)("div",{className:"p-4 text-sm text-red-600 bg-red-50 border border-red-200 rounded-md",children:s}),(0,le.jsxs)("div",{className:"space-y-4",children:[(0,le.jsx)(zy,{onClick:()=>i("/login"),className:"w-full h-[40px] bg-black text-[#FAFAFA] border border-[#E4E4E7] rounded-md shadow-xs p-2 px-4 gap-2.5",children:"Go to Sign In"}),(0,le.jsx)("div",{className:"text-center",children:(0,le.jsxs)("span",{className:"text-sm text-[#71717A]",children:["Didn't get the email?"," ",(0,le.jsx)("button",{onClick:async()=>{if(n){t(!0),a(null);try{await se.resetPasswordRequest(n),a("New password reset email sent. Please check your inbox.")}catch(s){var e;if(400===(null===(e=s.response)||void 0===e?void 0:e.status)){var l;const e=(null===(l=s.response.data)||void 0===l?void 0:l.detail)||"Failed to send email";a(e)}else a("Failed to resend email. Please try again.")}finally{t(!1)}}else a("Email address not found. Please go back and try again.")},disabled:e,className:"font-medium text-black hover:underline",children:e?"Resending...":"Resend email"})]})})]})]})},fN=()=>{const[e,t]=(0,Y.useState)(!1),[s,a]=(0,Y.useState)(null),[n,l]=(0,Y.useState)(null),[r,i]=(0,Y.useState)(""),[o,c]=(0,Y.useState)(""),[d,m]=(0,Y.useState)(!1),[u,x]=(0,Y.useState)(!1),[h,p]=(0,Y.useState)(!1),[g,f]=(0,Y.useState)(null),[v,b]=(0,Y.useState)({score:0,label:"Weak password",hasMinLength:!1,hasUpperLower:!1,hasSymbol:!1}),[j]=(0,J.useSearchParams)(),y=(0,Z.Zp)(),N=j.get("token");Y.useEffect(()=>{N||y("/forgot-password")},[N,y]),(0,Y.useEffect)(()=>()=>{g&&clearTimeout(g)},[g]);return(0,le.jsxs)(Gy,{title:"Set new password",subtitle:"Enter your new password for Base44",showImageColumn:!1,children:[s&&(0,le.jsx)("div",{className:"p-4 text-sm text-red-600 bg-red-50 border border-red-200 rounded-md",children:s}),(0,le.jsxs)("form",{onSubmit:async e=>{if(e.preventDefault(),N)if(r===o)if(v.score<3)a("Please create a strong password that meets all requirements.");else{t(!0),a(null),l(null);try{const e=await se.resetPassword(N,r,null);e&&e.id?(l("Password reset successfully! Redirecting to login..."),setTimeout(()=>{y("/login",{state:{message:"Password reset successfully! Please log in with your new password."}})},2e3)):a("Failed to reset password. Please try again.")}catch(s){var n;if(400===(null===(n=s.response)||void 0===n?void 0:n.status)){var i;const t=(null===(i=s.response.data)||void 0===i?void 0:i.detail)||"Invalid or expired reset token";a(t)}else a("Failed to reset password. Please try again.")}finally{t(!1)}}else a("Passwords do not match. Please try again.");else a("Invalid or missing reset token. Please request a new password reset.")},className:"space-y-6",children:[(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsx)("label",{htmlFor:"newPassword",className:"text-sm font-medium leading-5 tracking-normal text-[#09090B]",children:"New password"}),(0,le.jsxs)("div",{className:"relative",children:[(0,le.jsx)(Wy,{name:"newPassword",type:d?"text":"password",placeholder:"Enter your new password",value:r,onChange:e=>{const t=e.target.value;i(t),b(rN(t)),s&&a(null),n&&l(null)},onFocus:()=>{g&&(clearTimeout(g),f(null)),p(!0)},onBlur:()=>{const e=setTimeout(()=>{p(!1)},150);f(e)},required:!0,disabled:e,className:"bg-white text-[#09090B] h-9 px-3 py-1 pr-20 border border-[#E4E4E7] rounded-md shadow-xs",minLength:8}),r&&(0,le.jsx)("div",{className:"absolute right-9 top-1/2 -translate-y-1/2 h-[18px] flex items-center",children:(0,le.jsx)("span",{className:"text-xs text-[#71717A] font-normal leading-none tracking-normal",children:v.label.replace(" password","")})}),r&&(0,le.jsx)("button",{type:"button",onClick:()=>m(!d),className:"absolute right-3 top-1/2 -translate-y-1/2 w-[18px] h-[18px] flex items-center justify-center text-[#71717A] hover:text-[#09090B]",children:d?(0,le.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,le.jsx)("path",{d:"M17.94 17.94A10.07 10.07 0 0 1 12 20c-7 0-11-8-11-8a18.45 18.45 0 0 1 5.06-5.94M9.9 4.24A9.12 9.12 0 0 1 12 4c7 0 11 8 11 8a18.5 18.5 0 0 1-2.16 3.19m-6.72-1.07a3 3 0 1 1-4.24-4.24"}),(0,le.jsx)("line",{x1:"1",y1:"1",x2:"23",y2:"23"})]}):(0,le.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,le.jsx)("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"}),(0,le.jsx)("circle",{cx:"12",cy:"12",r:"3"})]})}),(0,le.jsx)("div",{className:"hidden lg:block",children:(0,le.jsx)(cN,{password:r,showTooltip:h,onMouseEnter:()=>{g&&(clearTimeout(g),f(null))},onMouseLeave:()=>{p(!1)}})})]})]}),(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsx)("label",{htmlFor:"confirmPassword",className:"text-sm font-medium leading-5 tracking-normal text-[#09090B]",children:"Confirm new password"}),(0,le.jsxs)("div",{className:"relative",children:[(0,le.jsx)(Wy,{name:"confirmPassword",type:u?"text":"password",placeholder:"Confirm your new password",value:o,onChange:e=>{c(e.target.value),s&&a(null),n&&l(null)},required:!0,disabled:e,className:"bg-white text-[#09090B] h-9 px-3 py-1 pr-10 border border-[#E4E4E7] rounded-md shadow-xs",minLength:8}),o&&(0,le.jsx)("button",{type:"button",onClick:()=>x(!u),className:"absolute right-3 top-1/2 -translate-y-1/2 w-[18px] h-[18px] flex items-center justify-center text-[#71717A] hover:text-[#09090B]",children:u?(0,le.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,le.jsx)("path",{d:"M17.94 17.94A10.07 10.07 0 0 1 12 20c-7 0-11-8-11-8a18.45 18.45 0 0 1 5.06-5.94M9.9 4.24A9.12 9.12 0 0 1 12 4c7 0 11 8 11 8a18.5 18.5 0 0 1-2.16 3.19m-6.72-1.07a3 3 0 1 1-4.24-4.24"}),(0,le.jsx)("line",{x1:"1",y1:"1",x2:"23",y2:"23"})]}):(0,le.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,le.jsx)("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"}),(0,le.jsx)("circle",{cx:"12",cy:"12",r:"3"})]})})]})]}),(0,le.jsx)("div",{className:"lg:hidden",children:(0,le.jsx)(dN,{password:r,showTooltip:!!r})}),(0,le.jsxs)("div",{className:"space-y-4",children:[(0,le.jsx)(zy,{type:"submit",className:"w-full h-[40px] bg-black text-[#FAFAFA] border border-[#E4E4E7] rounded-md shadow-xs px-4 py-2",disabled:e||v.score<3,children:e?"Resetting...":"Reset Password"}),n&&(0,le.jsx)("div",{className:"p-4 text-sm text-green-600 bg-green-50 border border-green-200 rounded-md",children:n}),(0,le.jsx)("div",{className:"text-center",children:(0,le.jsx)(J.Link,{to:"/login",className:"text-sm font-medium text-[#09090B] underline hover:text-[#71717A] leading-5 tracking-normal",children:"Back to Log In"})})]})]})]})};function vN(e){let{children:t}=e;return(0,le.jsx)(mr.oz,{className:"base44-markdown prose",remarkPlugins:[dr.A],children:t})}const bN=()=>{const e=(0,Z.Zp)();return(0,le.jsx)("div",{className:"flex items-center justify-center min-h-screen bg-slate-50",children:(0,le.jsxs)("div",{className:"max-w-md mx-auto text-center px-6",children:[(0,le.jsxs)("div",{className:"mb-8",children:[(0,le.jsx)("h1",{className:"text-8xl font-light text-slate-300 mb-4",children:"404"}),(0,le.jsx)("h2",{className:"text-2xl font-medium text-slate-900 mb-3",children:"Page not found"}),(0,le.jsx)("p",{className:"text-slate-600 leading-relaxed",children:"The page you're looking for doesn't exist or has been moved."})]}),(0,le.jsx)("button",{onClick:()=>e("/"),className:"inline-flex items-center px-6 py-3 text-sm font-medium text-white bg-orange-500 rounded-lg hover:bg-orange-600 transition-colors duration-200 focus:outline-none focus:ring-2 focus:ring-orange-500 focus:ring-offset-2",children:"Go home"})]})})};class jN extends Q.y{getBaseURL(){return"/integrations/StripeIntegration"}getOrCreateAccount(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"express";return this.axios.post("/get-or-create-account",{account_type:e})}getAccount(){return this.axios.get("/get-account")}createAccountLink(e,t){if(!e)throw new Error("Account ID is required for this operation");return this.axios.post("/".concat(e,"/create-account-link"))}checkAccountStatus(e){if(!e)throw new Error("Account ID is required for this operation");return this.axios.get("/".concat(e,"/check-account-status"))}refreshProductCatalog(e){if(!e)throw new Error("Account ID is required for this operation");return this.axios.post("/".concat(e,"/refresh-product-catalog"))}connectToApp(e,t){if(!e)throw new Error("Account ID is required for this operation");return this.axios.get("/".concat(e,"/connect-to-app/").concat(t))}createCheckoutSession(e,t){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1;if(!e)throw new Error("Account ID is required for this operation");const a=window.location.href;return this.axios.post("/".concat(e,"/create-checkout-session"),{price_id:t,quantity:s,success_url:"".concat(a,"?checkout_status=success"),cancel_url:"".concat(a,"?checkout_status=canceled")})}deleteAccount(e){if(!e)throw new Error("Account ID is required for this operation");return this.axios.delete("/".concat(e,"/delete-account"))}}const yN=new jN;function NN(e){let{onAccountCreated:t}=e;const[s,a]=(0,Y.useState)(!1),[n,l]=(0,Y.useState)("express"),{toast:r}=ui();return(0,le.jsxs)(is,{children:[(0,le.jsxs)(os,{children:[(0,le.jsx)(cs,{children:"Get Started with Stripe"}),(0,le.jsx)(ds,{children:"Create a Stripe account to start accepting payments in your apps"})]}),(0,le.jsxs)(ms,{children:[(0,le.jsx)("p",{className:"text-muted-foreground mb-4",children:"With Stripe, you can accept payments, manage subscriptions, and more. Your Stripe account will be created using Stripe Connect, which will allow your users to pay you directly."}),(0,le.jsxs)("div",{className:"mt-6",children:[(0,le.jsx)("h3",{className:"text-lg font-medium mb-4",children:"Choose Account Type"}),(0,le.jsxs)(As,{value:n,onValueChange:l,className:"space-y-4",children:[(0,le.jsxs)("div",{className:"flex items-start space-x-2 rounded-md border p-4",children:[(0,le.jsx)(Ss,{value:"express",id:"express",className:"mt-1"}),(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsxs)("div",{className:"flex space-x-2",children:[(0,le.jsx)(Ns,{htmlFor:"express",className:"font-medium",children:"Express Account"}),(0,le.jsx)("span",{className:"inline-flex items-center rounded-full bg-blue-50 px-2 py-1 text-xs font-medium text-blue-700",children:"Recommended for new users"})]}),(0,le.jsx)("p",{className:"text-sm text-muted-foreground",children:"Best for people who don't have a Stripe account yet. Express accounts offer a simplified onboarding process with a Stripe-hosted setup and dashboard. This is the quickest way to get started."})]})]}),(0,le.jsxs)("div",{className:"flex items-start space-x-2 rounded-md border p-4",children:[(0,le.jsx)(Ss,{value:"standard",id:"standard",className:"mt-1"}),(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsxs)("div",{className:"flex space-x-2",children:[(0,le.jsx)(Ns,{htmlFor:"standard",className:"font-medium",children:"Standard Account"}),(0,le.jsx)("span",{className:"inline-flex items-center rounded-full bg-purple-50 px-2 py-1 text-xs font-medium text-purple-700",children:"For experienced users"})]}),(0,le.jsx)("p",{className:"text-sm text-muted-foreground",children:"Best for people who already have a Stripe account set up. Standard accounts provide more customization options and direct access to the full Stripe Dashboard. This option requires more setup steps but offers greater flexibility."})]})]})]})]})]}),(0,le.jsx)(us,{className:"flex justify-end",children:(0,le.jsx)(Yt,{onClick:async()=>{a(!0);try{const e=await yN.getOrCreateAccount(n);t(e),r({title:"Success",description:"Stripe account created successfully",variant:"success"})}catch(e){r({variant:"destructive",title:"Error",description:"Failed to create Stripe account"})}finally{a(!1)}},disabled:s,children:s?(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(Ne.A,{className:"mr-2 h-4 w-4 animate-spin"}),"Creating Account..."]}):(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(Tr.A,{className:"mr-2 h-4 w-4"}),"Create Stripe Account"]})})})]})}function wN(e){var t;let{account:s,onAccountVerified:a}=e;const[n,l]=(0,Y.useState)(!0),[r,i]=(0,Y.useState)(null),[o,c]=(0,Y.useState)(!1),{toast:d}=ui();(0,Y.useEffect)(()=>{s&&m()},[s]);const m=async()=>{l(!0);try{const e=await yN.checkAccountStatus(s.id);i(e),e.is_complete&&a()}catch(e){d({variant:"destructive",title:"Error",description:"Failed to check Stripe account status"})}finally{l(!1)}};if(n)return(0,le.jsxs)(is,{children:[(0,le.jsxs)(os,{children:[(0,le.jsx)(cs,{children:"Checking Your Stripe Account"}),(0,le.jsx)(ds,{children:"Verifying your Stripe account setup..."})]}),(0,le.jsx)(ms,{className:"flex justify-center items-center p-8",children:(0,le.jsx)(Ne.A,{className:"h-8 w-8 animate-spin text-muted-foreground"})})]});if(null!=r&&r.is_complete)return(0,le.jsxs)(is,{children:[(0,le.jsxs)(os,{children:[(0,le.jsx)(cs,{children:"Stripe Account Setup Complete"}),(0,le.jsx)(ds,{children:"Your Stripe account is fully set up and ready to use"})]}),(0,le.jsx)(ms,{children:(0,le.jsxs)(De,{className:"bg-green-50 border-green-200",children:[(0,le.jsx)(Vg.A,{className:"h-4 w-4 text-green-600"}),(0,le.jsx)(Fe,{className:"text-green-600",children:"Ready to accept payments"}),(0,le.jsx)(Be,{children:"Your Stripe account is ready to process payments and receive payouts."})]})}),(0,le.jsx)(us,{className:"flex justify-end",children:(0,le.jsx)(Yt,{onClick:a,children:"Continue to Next Step"})})]});const u=(null==r||null===(t=r.requirements)||void 0===t?void 0:t.currently_due)||[];return(0,le.jsxs)(is,{children:[(0,le.jsxs)(os,{children:[(0,le.jsx)(cs,{children:"Complete Your Stripe Account Setup"}),(0,le.jsx)(ds,{children:"Your Stripe account needs additional information to start accepting payments"})]}),(0,le.jsxs)(ms,{className:"space-y-4",children:[(0,le.jsxs)(De,{variant:"warning",className:"bg-yellow-50 border-yellow-200",children:[(0,le.jsx)(_e.A,{className:"h-4 w-4 text-yellow-600"}),(0,le.jsx)(Fe,{className:"text-yellow-600",children:"Account setup incomplete"}),(0,le.jsx)(Be,{children:"Please continue the Stripe onboarding process to complete your account setup."})]}),(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsx)("div",{className:"flex items-center gap-2",children:(0,le.jsxs)("div",{className:null!=r&&r.details_submitted?"text-green-600":"text-muted-foreground",children:[null!=r&&r.details_submitted?(0,le.jsx)(Vg.A,{className:"inline h-4 w-4 mr-1"}):(0,le.jsx)(Gg.A,{className:"inline h-4 w-4 mr-1"}),"Account details provided"]})}),(0,le.jsx)("div",{className:"flex items-center gap-2",children:(0,le.jsxs)("div",{className:null!=r&&r.charges_enabled?"text-green-600":"text-muted-foreground",children:[null!=r&&r.charges_enabled?(0,le.jsx)(Vg.A,{className:"inline h-4 w-4 mr-1"}):(0,le.jsx)(Gg.A,{className:"inline h-4 w-4 mr-1"}),"Charges enabled"]})}),(0,le.jsx)("div",{className:"flex items-center gap-2",children:(0,le.jsxs)("div",{className:null!=r&&r.payouts_enabled?"text-green-600":"text-muted-foreground",children:[null!=r&&r.payouts_enabled?(0,le.jsx)(Vg.A,{className:"inline h-4 w-4 mr-1"}):(0,le.jsx)(Gg.A,{className:"inline h-4 w-4 mr-1"}),"Payouts enabled"]})})]}),u.length>0&&(0,le.jsxs)("div",{className:"mt-4",children:[(0,le.jsx)("h4",{className:"text-sm font-medium mb-2",children:"Required Information:"}),(0,le.jsx)("ul",{className:"text-sm text-muted-foreground space-y-1 list-disc pl-5",children:u.map((e,t)=>(0,le.jsx)("li",{children:e.split(".").join(" ").replace(/_/g," ")},t))})]})]}),(0,le.jsxs)(us,{className:"flex justify-between items-center",children:[(0,le.jsx)(Yt,{variant:"outline",onClick:m,children:"Refresh Status"}),(0,le.jsx)(Yt,{onClick:async()=>{c(!0);try{const e="".concat(window.location.origin,"/integrations/stripe"),t=await yN.createAccountLink(s.id,e);t.account_link_url&&(window.location.href=t.account_link_url)}catch(e){d({variant:"destructive",title:"Error",description:"Failed to create Stripe account link"}),c(!1)}},disabled:o,children:o?(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(Ne.A,{className:"mr-2 h-4 w-4 animate-spin"}),"Preparing Onboarding..."]}):(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(Tr.A,{className:"mr-2 h-4 w-4"}),"Complete Stripe Onboarding"]})})]})]})}var _N=s(37656);function kN(e){let{integrationInstance:t}=e;const[s,a]=(0,Y.useState)(null),[n,l]=(0,Y.useState)(!1),{toast:r}=ui(),i=e=>{if(!e||!e.unit_amount)return"N/A";const t=e.unit_amount/100;return new Intl.NumberFormat("en-US",{style:"currency",currency:e.currency||"USD"}).format(t)},o=async()=>{try{l(!0),await yN.refreshProductCatalog(t.id),r({title:"Success",description:"Product catalog refreshed successfully from Stripe",variant:"success"})}catch(e){r({variant:"destructive",title:"Error",description:"Failed to refresh product catalog from Stripe"})}finally{l(!1)}};return t.product_catalog&&0!==t.product_catalog.length?(0,le.jsxs)("div",{children:[(0,le.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,le.jsx)("h3",{className:"text-lg font-medium",children:"Product Catalog"}),(0,le.jsx)(Yt,{variant:"outline",size:"sm",onClick:o,disabled:n,children:n?(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(Ne.A,{className:"mr-2 h-4 w-4 animate-spin"}),"Refreshing..."]}):(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(nx.A,{className:"mr-2 h-4 w-4"}),"Refresh Catalog"]})})]}),(0,le.jsx)("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:t.product_catalog.map(e=>(0,le.jsx)(is,{className:"overflow-hidden",children:(0,le.jsxs)("div",{className:"p-4",children:[(0,le.jsx)("h4",{className:"font-semibold",children:e.name}),(0,le.jsx)("p",{className:"text-sm text-muted-foreground mt-1",children:e.description||"No description"}),e.images&&e.images.length>0&&(0,le.jsx)("div",{className:"mt-2",children:(0,le.jsx)("img",{src:e.images[0],alt:e.name,className:"w-full h-32 object-cover rounded-md"})}),e.prices&&e.prices.length>0?(0,le.jsxs)("div",{className:"mt-3",children:[(0,le.jsx)("h5",{className:"text-sm font-medium mb-1",children:"Prices:"}),(0,le.jsx)("div",{className:"space-y-1 max-h-32 overflow-y-auto",children:e.prices.map(e=>(0,le.jsxs)("div",{className:"bg-muted/30 p-2 rounded-md text-xs",children:[(0,le.jsxs)("div",{className:"flex justify-between",children:[(0,le.jsx)("span",{className:"font-medium",children:i(e)}),(0,le.jsx)("span",{className:"text-muted-foreground",children:e.recurring?"".concat(e.recurring.interval_count," ").concat(e.recurring.interval):"One-time"})]}),(0,le.jsxs)("div",{className:"flex justify-between items-center mt-2",children:[(0,le.jsxs)("div",{className:"text-muted-foreground text-xs truncate",title:e.id,children:["ID: ",e.id.substring(0,10),"..."]}),(0,le.jsxs)(Yt,{size:"sm",variant:"secondary",className:"h-6 text-xs px-2",onClick:()=>(async e=>{try{a(e);const s=await yN.createCheckoutSession(t.id,e);s.checkout_url&&window.open(s.checkout_url,"_blank")}catch(s){}finally{a(null)}})(e.id),disabled:s===e.id,children:[s===e.id?(0,le.jsx)(Ne.A,{className:"h-3 w-3 animate-spin mr-1"}):null,"Checkout"]})]})]},e.id))})]}):(0,le.jsx)("div",{className:"mt-2 text-xs text-muted-foreground italic",children:"No prices defined for this product"}),(0,le.jsxs)("div",{className:"mt-2 text-xs text-muted-foreground",children:["ID: ",e.id]})]})},e.id))})]}):(0,le.jsxs)("div",{className:"text-center py-6 bg-muted/30 rounded-lg",children:[(0,le.jsx)("p",{className:"text-muted-foreground mb-4",children:"No products available."}),(0,le.jsx)(Yt,{variant:"outline",size:"sm",onClick:o,disabled:n,children:n?(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(Ne.A,{className:"mr-2 h-4 w-4 animate-spin"}),"Refreshing..."]}):(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(nx.A,{className:"mr-2 h-4 w-4"}),"Refresh Products from Stripe"]})}),(0,le.jsx)("p",{className:"text-xs text-muted-foreground mt-2",children:"This will fetch the latest products and prices from your Stripe account."})]})}function CN(e){let{account:t,onContinue:s}=e;const[a,n]=(0,Y.useState)(!1),{toast:l}=ui();return(0,le.jsxs)("div",{className:"space-y-6",children:[(0,le.jsxs)(is,{children:[(0,le.jsxs)(os,{children:[(0,le.jsx)(cs,{children:"Manage Your Product Catalog"}),(0,le.jsx)(ds,{children:"Set up products and prices in Stripe to offer to your customers"})]}),(0,le.jsxs)(ms,{className:"space-y-4",children:[(0,le.jsxs)(De,{children:[(0,le.jsx)(_N.A,{className:"h-4 w-4"}),(0,le.jsx)(Fe,{children:"Optional Step"}),(0,le.jsx)(Be,{children:"Create products in the Stripe dashboard to offer one-time purchases or subscriptions to your customers. This step is optional, but recommended if you want to offer paid content."})]}),(0,le.jsxs)("div",{className:"p-4 bg-muted/20 rounded-lg",children:[(0,le.jsx)("h3",{className:"text-sm font-medium mb-3",children:"Instructions"}),(0,le.jsxs)("ol",{className:"space-y-2 text-sm text-muted-foreground list-decimal pl-5",children:[(0,le.jsx)("li",{children:"Go to the Stripe Dashboard by clicking the button below"}),(0,le.jsx)("li",{children:'Navigate to "Products" in the sidebar'}),(0,le.jsx)("li",{children:"Create new products with appropriate pricing"}),(0,le.jsx)("li",{children:"For subscriptions, set up recurring prices with the desired interval"}),(0,le.jsx)("li",{children:"Return here and refresh your product catalog when complete"})]})]})]}),(0,le.jsxs)(us,{className:"flex justify-between",children:[(0,le.jsxs)(Yt,{variant:"outline",onClick:()=>window.open("https://dashboard.stripe.com/account","_blank"),children:[(0,le.jsx)(Tr.A,{className:"mr-2 h-4 w-4"}),"Open Stripe Dashboard"]}),(0,le.jsx)(Yt,{onClick:async()=>{n(!0);try{await yN.refreshProductCatalog(t.id),l({title:"Success",description:"Product catalog refreshed successfully",variant:"success"})}catch(e){l({variant:"destructive",title:"Error",description:"Failed to refresh product catalog"})}finally{n(!1)}},disabled:a,children:a?(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(Ne.A,{className:"mr-2 h-4 w-4 animate-spin"}),"Refreshing..."]}):(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(nx.A,{className:"mr-2 h-4 w-4"}),"Refresh Product Catalog"]})})]})]}),(0,le.jsxs)(is,{children:[(0,le.jsxs)(os,{children:[(0,le.jsx)(cs,{children:"Current Product Catalog"}),(0,le.jsx)(ds,{children:"Products and prices available for your apps"})]}),(0,le.jsx)(ms,{children:(0,le.jsx)(kN,{integrationInstance:t})}),(0,le.jsx)(us,{className:"flex justify-end",children:(0,le.jsx)(Yt,{onClick:s,children:"Continue to Next Step"})})]})]})}var AN=s(56150),SN=s(2999);function EN(){const e=(0,Z.Zp)();return(0,le.jsxs)(is,{children:[(0,le.jsx)(os,{children:(0,le.jsxs)("div",{className:"flex items-start justify-between",children:[(0,le.jsxs)("div",{children:[(0,le.jsx)(cs,{children:"Stripe Integration Complete"}),(0,le.jsx)(ds,{children:"Your Stripe integration is ready to use with your apps"})]}),(0,le.jsx)("div",{className:"p-1.5 rounded-full bg-green-100",children:(0,le.jsx)(AN.A,{className:"h-5 w-5 text-green-600"})})]})}),(0,le.jsx)(ms,{children:(0,le.jsxs)(kr,{defaultValue:"navigation",children:[(0,le.jsxs)(Cr,{className:"grid w-full grid-cols-2",children:[(0,le.jsx)(Ar,{value:"navigation",children:"Navigation Instructions"}),(0,le.jsx)(Ar,{value:"code",children:"Code Integration"})]}),(0,le.jsxs)(Sr,{value:"navigation",className:"space-y-4 mt-4",children:[(0,le.jsxs)("div",{className:"p-4 bg-muted/20 rounded-lg space-y-4",children:[(0,le.jsx)("h3",{className:"text-sm font-medium",children:"How to Use Your Stripe Integration"}),(0,le.jsxs)("div",{className:"space-y-1",children:[(0,le.jsx)("h4",{className:"text-sm font-medium",children:"1. Navigate to an App"}),(0,le.jsx)("p",{className:"text-sm text-muted-foreground",children:"Go to your app dashboard and select the app you want to add payment functionality to."})]}),(0,le.jsxs)("div",{className:"space-y-1",children:[(0,le.jsx)("h4",{className:"text-sm font-medium",children:"2. Go to the Payments Tab"}),(0,le.jsx)("p",{className:"text-sm text-muted-foreground",children:'Open the app editor and click on the "Payments" tab in the sidebar.'})]}),(0,le.jsxs)("div",{className:"space-y-1",children:[(0,le.jsx)("h4",{className:"text-sm font-medium",children:"3. Connect Your Stripe Account"}),(0,le.jsx)("p",{className:"text-sm text-muted-foreground",children:'Click "Connect Payments" to link your Stripe account to the app.'})]}),(0,le.jsxs)("div",{className:"space-y-1",children:[(0,le.jsx)("h4",{className:"text-sm font-medium",children:"4. Use the Product Catalog"}),(0,le.jsx)("p",{className:"text-sm text-muted-foreground",children:"Once connected, use your Stripe products and prices in the app through the Product Catalog interface."})]})]}),(0,le.jsx)("div",{className:"flex justify-end",children:(0,le.jsxs)(Yt,{onClick:()=>e("/apps"),children:["Go to My Apps ",(0,le.jsx)(rn.A,{className:"ml-2 h-4 w-4"})]})})]}),(0,le.jsx)(Sr,{value:"code",className:"space-y-4 mt-4",children:(0,le.jsxs)("div",{className:"p-4 bg-muted/20 rounded-lg space-y-4",children:[(0,le.jsx)("h3",{className:"text-sm font-medium",children:"Code Integration"}),(0,le.jsxs)("div",{className:"space-y-1",children:[(0,le.jsx)("h4",{className:"text-sm font-medium",children:"Using the API"}),(0,le.jsx)("p",{className:"text-sm text-muted-foreground",children:"Access your Stripe integration programmatically by making API calls to create checkout sessions, access product catalogs, or check purchase history."})]}),(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsx)("h4",{className:"text-sm font-medium",children:"Example: Create a Checkout Session"}),(0,le.jsx)("pre",{className:"p-3 bg-muted/40 rounded-md text-xs overflow-x-auto",children:(0,le.jsx)("code",{children:"// Example API call\nconst createCheckout = async (priceId) => {\n try {\n const response = await fetch('/api/integrations/stripe/{account_id}/create-checkout-session', {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n price_id: priceId,\n quantity: 1,\n success_url: window.location.origin + '/success',\n cancel_url: window.location.origin + '/cancel'\n })\n });\n \n const data = await response.json();\n window.location.href = data.checkout_url;\n } catch (error) {\n console.error('Error creating checkout session:', error);\n }\n}"})})]})]})})]})}),(0,le.jsxs)(us,{className:"flex justify-between",children:[(0,le.jsxs)(Yt,{variant:"outline",onClick:()=>window.open("https://stripe.com/docs","_blank"),children:[(0,le.jsx)(SN.A,{className:"mr-2 h-4 w-4"}),"Stripe Documentation"]}),(0,le.jsxs)(Yt,{variant:"outline",onClick:()=>window.open("https://dashboard.stripe.com","_blank"),children:[(0,le.jsx)(Kl.A,{className:"mr-2 h-4 w-4"}),"Stripe Dashboard"]})]})]})}var IN=s(44153);function TN(e){let{currentStep:t,totalSteps:s}=e;return(0,le.jsx)("div",{className:"flex items-center justify-center my-6",children:(0,le.jsx)("div",{className:"flex items-center",children:Array.from({length:s}).map((e,a)=>(0,le.jsxs)("div",{className:"flex items-center",children:[(0,le.jsxs)("div",{className:"flex flex-col items-center",children:[(0,le.jsx)("div",{className:"rounded-full flex items-center justify-center h-8 w-8 ".concat(ar(!1),disabled:a,children:"Cancel"}),(0,le.jsx)(Yt,{variant:"destructive",onClick:async()=>{n(!0),o(null);try{await yN.deleteAccount(t.id),c({title:"Account Deleted",description:"Your Stripe integration has been successfully deleted.",variant:"success"}),r(!1),s&&s()}catch(i){var e,a;const s=(null===(e=i.response)||void 0===e||null===(a=e.data)||void 0===a?void 0:a.detail)||"Failed to delete Stripe account. Please try again.";o(s),c({variant:"destructive",title:"Error",description:"Failed to delete Stripe account"})}finally{n(!1)}},disabled:a,children:a?(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(Ne.A,{className:"mr-2 h-4 w-4 animate-spin"}),"Deleting..."]}):"Delete Integration"})]})]})]})})]})}function LN(){const{user:e}=oe(),[t,s]=(0,Y.useState)(!0),[a,n]=(0,Y.useState)(null),[l,r]=(0,Y.useState)(0),[i,o]=(0,Y.useState)(null),{toast:c}=ui(),d=(0,Z.Zp)();(0,Y.useEffect)(()=>{(async()=>{try{s(!0);const e=await yN.getAccount();e?(n(e),r(1)):r(0)}catch(i){o("Failed to load Stripe account information"),c({variant:"destructive",title:"Error",description:"Failed to load Stripe account information"})}finally{s(!1)}})()},[c]);const m=e=>{n(e),r(1)},u=()=>{r(2)},x=()=>{r(3)};if(!cx(e,"builder"))return(0,le.jsxs)("div",{className:"p-6 max-w-4xl mx-auto",children:[(0,le.jsxs)("div",{className:"mb-6",children:[(0,le.jsx)("h2",{className:"text-3xl font-bold tracking-tight",children:"Stripe Integration"}),(0,le.jsx)("p",{className:"text-muted-foreground mt-2",children:"Set up Stripe to accept payments in your apps"})]}),(0,le.jsxs)(De,{children:[(0,le.jsx)(Fe,{children:"Subscription Required"}),(0,le.jsx)(Be,{children:"Stripe integration is currently available only for Pro and Enterprise users. Please upgrade your subscription to access this feature."})]}),(0,le.jsx)("div",{className:"mt-4",children:(0,le.jsx)(Yt,{onClick:()=>d("/billing"),children:"Upgrade Subscription"})})]});return t?(0,le.jsxs)("div",{className:"p-6 max-w-4xl mx-auto",children:[(0,le.jsxs)("div",{className:"mb-6",children:[(0,le.jsx)("h2",{className:"text-3xl font-bold tracking-tight",children:"Stripe Integration"}),(0,le.jsx)("p",{className:"text-muted-foreground mt-2",children:"Set up Stripe to accept payments in your apps"})]}),(0,le.jsx)("div",{className:"flex justify-center items-center p-12",children:(0,le.jsx)(Ne.A,{className:"h-8 w-8 animate-spin text-muted-foreground"})})]}):i?(0,le.jsxs)("div",{className:"p-6 max-w-4xl mx-auto",children:[(0,le.jsxs)("div",{className:"mb-6",children:[(0,le.jsx)("h2",{className:"text-3xl font-bold tracking-tight",children:"Stripe Integration"}),(0,le.jsx)("p",{className:"text-muted-foreground mt-2",children:"Set up Stripe to accept payments in your apps"})]}),(0,le.jsx)("div",{className:"bg-amber-50 border border-amber-200 rounded-md p-4 mb-4",children:(0,le.jsxs)("div",{className:"flex items-start",children:[(0,le.jsx)(ux.A,{className:"h-5 w-5 text-amber-500 mt-0.5 mr-3"}),(0,le.jsxs)("div",{children:[(0,le.jsx)("h3",{className:"text-sm font-medium text-amber-800",children:"Something went wrong"}),(0,le.jsxs)("p",{className:"text-sm text-amber-700 mt-1",children:[i,". Refreshing the page might help resolve this issue."]})]})]})}),(0,le.jsx)("div",{className:"mt-4",children:(0,le.jsx)(Yt,{onClick:()=>window.location.reload(),children:"Refresh Page"})})]}):(0,le.jsxs)("div",{className:"p-6 max-w-4xl mx-auto",children:[(0,le.jsxs)("div",{className:"mb-6 flex justify-between items-center",children:[(0,le.jsxs)("div",{children:[(0,le.jsx)("h2",{className:"text-3xl font-bold tracking-tight",children:"Stripe Integration"}),(0,le.jsx)("p",{className:"text-muted-foreground mt-2",children:"Set up Stripe to accept payments in your apps"})]}),l>0&&(0,le.jsxs)(Yt,{variant:"outline",onClick:()=>r(Math.max(0,l-1)),children:[(0,le.jsx)(Cd.A,{className:"mr-2 h-4 w-4"}),"Back"]})]}),(0,le.jsx)(TN,{currentStep:l,totalSteps:4}),(()=>{switch(l){case 0:default:return(0,le.jsx)(NN,{onAccountCreated:m});case 1:return(0,le.jsx)(wN,{account:a,onAccountVerified:u});case 2:return(0,le.jsx)(CN,{account:a,onContinue:x});case 3:return(0,le.jsx)(EN,{})}})(),a&&(0,le.jsx)("div",{className:"mt-8",children:(0,le.jsx)(PN,{account:a,onAccountDeleted:()=>{n(null),r(0),c({title:"Account Deleted",description:"Your Stripe integration has been successfully removed.",variant:"success"})}})})]})}function ON(){return(0,le.jsx)("div",{className:"p-9",children:(0,le.jsx)(vN,{children:"\n\n**Base44 Responsible Use Policy**\n\nLast Updated: March 23, 2025 \n\nThis Responsible Use Policy (\u201c**RUP**\u201d) supplements the Base44 Terms of Service, or any other agreement or order form between Base44, Inc. or its affiliates (\u201c**Base44**\u201d) and you, being any Customer or User thereof (\u201c**you**\u201d), governing the use of Base44\u2019s Platform, Website, the Generated Output or other products and services (each of the foregoing, together and separately, the \u201c**Agreement\u201d**). The RUP applies to your access and use of the Platform, Customer Data (including the Input Data you provide to the Platform and the Generated Output created on its basis), whether as part of your Platform or your use of Generated Output outside of it. Capitalized but undefined terms used in the RUP have the meanings set forth in your applicable Agreement with Base44.\n\nYou will not share with the Platform any Input Data that, nor knowingly use the Platform to generate any Generated Output or use or make available to others any Generated Output:\n\n1. That in any way violates any applicable national, federal, state, local or international law or regulation;\n2. Generating and distributing spam in violation of the CAN-SPAM Act of 2003 and other applicable laws;\n3. For the purpose of exploiting, harming or attempting to exploit or harm minors in any way;\n4. Contains pornographic, sexually explicit, or adult content;\n5. To generate or disseminate verifiably false, misleading or deceptive information and/or content (including with regard to medicine, health and science);\n6. To generate or disseminate personal identifiable information that can be used to harm an individual;\n7. To generate or disseminate information and/or content (e.g. images, code, posts, articles), and place the information and/or content in any context (e.g. bot generating tweets) without expressly and intelligibly disclaiming that the information and/or content is machine generated;\n8. To defame, disparage, cyber-bully or otherwise harass others, or encourage self-harm or harm to others;\n9. To impersonate or attempt to impersonate (e.g. deepfakes) others without their consent;\n10. For fully automated decision making that adversely impacts an individual\u2019s legal rights or otherwise creates or modifies a binding, enforceable obligation;\n11. For any use intended to or which has the effect of discriminating against or harming individuals or groups based on online or offline social behavior or known or predicted personal or personality characteristics, or in a manner that is obscene, violent, hateful, racist or discriminatory or is otherwise offensive;\n12. To exploit any of the vulnerabilities of a specific group of persons based on their age, social, physical or mental characteristics, in order to materially distort the behavior of a person pertaining to that group in a manner that causes or is likely to cause that person or another person physical or psychological harm;\n13. For any use intended to or which has the effect of discriminating against individuals or groups based on legally protected characteristics or categories;\n14. To engage in political lobbying or campaigns to actively influence the decisions of government officials, legislators, or regulatory agencies on legislative, regulatory, or policy matters;\n15. To provide medical advice and medical results interpretation, or promote pharmaceutical or medical products and services, without having the qualifications, licenses and permits required by applicable law;\n16. To engage in and promote regulated services and professions, and/or deliver any regulated products or services, including but not limited to legal and accounting services, investment advice, insurance, banking and securities, without having the qualifications, licenses and permits required by applicable law;\n17. To generate or disseminate information for the purpose to be used for administration of justice, law enforcement, immigration or asylum processes, such as predicting an individual will commit fraud/crime commitment (e.g. by text profiling, drawing causal relationships between assertions made in documents, indiscriminate and arbitrarily-targeted use);\n18. To infringe, violate or misappropriate any patent, trademark, trade secret, copyright, or other intellectual property or other proprietary rights of any other person;\n19. To transmit or otherwise makes available any malicious code, including any virus, worm, trojan horse, time bomb, web bug, spyware, or any other malicious or harmful computer code, library, file, or program;\n20. To circumvent the technical and other safeguards set out by Base44 or our Third- Party Service providers meant to ensure adherence with the RUP and such Third- Party Service providers' equivalent usage policies, as applicable.\n\nTo the extent the Platform or Generated Output generate Generated Output containing any of the above, you will notify us in writing without undue delay upon becoming aware of it.\n\nEnforcing the RUP, including the determination whether a violation occurred and determining its severity, is at Baser44\u2019s sole and complete discretion, and failure to enforce it in one instance does not constitute a waiver to enforce it in any other instances.\n\nYou will promptly cease use of any Customer Data, Input Data or Generated Output violating this RUP, and Base44 has the right to promptly remove or delete any violating Customer Data, remove violating Generated Output from the Platform and Website in its sole discretion or modify the Platform to ensure compliance with the RUP and applicable law.\n\n"})})}function RN(e){let{onLoadMore:t,hasMore:s=!0,isLoading:a=!1,threshold:n=.1}=e;const[l,r]=(0,Y.useState)(!1),i=(0,Y.useRef)(null),o=(0,Y.useRef)(null),c=(0,Y.useCallback)(()=>{s&&!a&&t&&t()},[s,a,t]);return(0,Y.useEffect)(()=>{const e=i.current;if(e)return o.current=new IntersectionObserver(e=>{const[t]=e;r(t.isIntersecting),t.isIntersecting&&s&&!a&&c()},{threshold:n,rootMargin:"50px"}),o.current.observe(e),()=>{o.current&&o.current.disconnect()}},[c,s,a,n]),{targetRef:i,isIntersecting:l,hasMore:s}}function MN(e){let{activeTab:t,onTabChange:s}=e;const a="\n relative h-12 rounded-none border-0 bg-transparent px-3 sm:px-6 pb-3 pt-3 \n font-base44 font-medium text-gray-600 shadow-none transition-colors hover:text-gray-900 \n focus-visible:ring-0 focus-visible:ring-offset-0 \n data-[state=active]:bg-transparent data-[state=active]:text-black data-[state=active]:shadow-none \n data-[state=active]:after:absolute data-[state=active]:after:bottom-0 data-[state=active]:after:left-0 \n data-[state=active]:after:right-0 data-[state=active]:after:h-0.5 data-[state=active]:after:bg-black \n data-[state=active]:after:content-['']\n ".trim().replace(/\s+/g," ");return(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)("h1",{className:"text-3xl sm:text-4xl lg:text-5xl font-base44 font-medium mb-4 mt-6",children:"Integrations"}),(0,le.jsx)("p",{className:"text-base sm:text-lg font-base44 mb-6",children:"Discover pre-built integrations that let you connect to APIs, services, and tools to extend your app's capabilities."}),(0,le.jsx)(kp,{value:t,onValueChange:s,className:"mb-8",children:(0,le.jsxs)(Cp,{className:"h-auto w-full bg-transparent p-0 border-b border-gray-200 justify-start",children:[(0,le.jsx)(Ap,{value:"catalog",className:a,children:"Integrations Catalog"}),(0,le.jsx)(Ap,{value:"my-integrations",className:a,children:"My Integrations"})]})})]})}const DN=[{value:"most-upvoted",label:"Most Popular"},{value:"newest",label:"Newest first"},{value:"oldest",label:"Oldest first"}];function FN(e){let{searchTerm:t,onSearchChange:s,selectedCategory:a,onCategoryChange:n,sortBy:l,onSortByChange:r,privacyFilter:i,onPrivacyFilterChange:o,statusFilter:c,onStatusFilterChange:d,isAdmin:m}=e;const[u,x]=(0,Y.useState)(t),h=(0,Y.useCallback)(e=>setTimeout(()=>{s(e)},300),[s]);return(0,Y.useEffect)(()=>{const e=h(u);return()=>clearTimeout(e)},[u,h]),(0,Y.useEffect)(()=>{x(t)},[t]),(0,le.jsx)("div",{className:"mt-[42px] mb-6 font-base44",children:(0,le.jsxs)("div",{className:"flex flex-col sm:flex-row sm:items-center gap-3 w-full sm:justify-between",children:[(0,le.jsxs)("div",{className:"flex items-center rounded-xl border border-[#E4E4E7] bg-white flex-1 sm:max-w-[420px] h-[40px] px-3 sm:px-[11px]",children:[(0,le.jsx)(vn.A,{className:"w-4 h-4 text-[#000] flex-shrink-0"}),(0,le.jsx)(fn,{placeholder:"Search integrations...",value:u,onChange:e=>x(e.target.value),className:"border-0 bg-transparent focus-visible:ring-0 focus-visible:ring-offset-0 placeholder:text-[#B4B4B4] text-black"})]}),(0,le.jsx)("div",{className:"flex items-center gap-3 justify-end sm:justify-start",children:(0,le.jsxs)(In,{value:l,onValueChange:r,children:[(0,le.jsx)(Pn,{className:"w-auto min-w-[140px] h-[40px] font-base44 border-0 bg-transparent px-0 text-black focus-visible:ring-0 focus-visible:ring-offset-0 [&>svg]:text-black [&>svg]:ml-2",children:(0,le.jsx)(Tn,{placeholder:"Sort by"})}),(0,le.jsx)(Rn,{children:DN.map(e=>(0,le.jsx)(Mn,{value:e.value,className:"font-base44",children:e.label},e.value))})]})})]})})}var BN=s(95445);const zN=e=>{var t,s;let{item:a,onSelect:n,isAdmin:l,currentUser:r}=e;const{item:i,usage:o}=a,c=(null==r?void 0:r.email)===i.owner_email,d=!("pending"===i.status&&!i.is_private)||l||c,m="\n h-full overflow-hidden transition-all duration-200 \n bg-white flex flex-col rounded-[16px] font-base44 shadow-none border-0\n ".concat(d?"hover:shadow-md cursor-pointer border-gray-100":"border-dashed border-gray-100 bg-slate-50 opacity-70 cursor-not-allowed","\n ");return(0,le.jsxs)(Qn,{className:m,onClick:()=>{d&&n(i.id)},children:[(0,le.jsx)(Xn,{className:"pb-1 px-4 pt-4",children:(0,le.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,le.jsxs)(il,{className:"h-12 w-12 flex-shrink-0 rounded-md",children:[(0,le.jsx)(ol,{src:i.image_url,alt:i.name,className:"object-contain"}),(0,le.jsx)(cl,{className:"bg-gradient-to-br from-blue-100 to-teal-100 text-teal-700 text-sm font-medium",children:(null===(t=i.name)||void 0===t||null===(s=t.charAt(0))||void 0===s?void 0:s.toUpperCase())||"I"})]}),(0,le.jsxs)("div",{className:"w-full",children:[(0,le.jsx)(el,{className:"text-[16px] font-regular",children:i.name}),(0,le.jsxs)("div",{className:"flex gap-1.5 flex-wrap",children:[i.official&&(0,le.jsxs)(Nn,{variant:"outline",className:"bg-blue-50 px-1.5 py-0 h-5 font-normal",children:[(0,le.jsx)(BN.A,{className:"h-3 w-3 mr-0.5"}),(0,le.jsx)("span",{className:"text-xs",children:"Official"})]}),i.is_private&&(0,le.jsxs)(Nn,{variant:"outline",className:"bg-slate-100 text-slate-700 border-slate-200 px-1.5 py-0 h-5 font-normal",children:[(0,le.jsx)(Mt.A,{className:"h-3 w-3 mr-0.5"}),(0,le.jsx)("span",{className:"text-xs",children:"Private"})]}),"pending"===i.status&&!i.is_private&&(0,le.jsxs)(Nn,{variant:"outline",className:"bg-amber-50 text-amber-700 border-amber-200 px-1.5 py-0 h-5 font-normal",children:[(0,le.jsx)(Li.A,{className:"h-3 w-3 mr-0.5"}),(0,le.jsx)("span",{className:"text-xs",children:"Pending Review"})]})]})]})]})}),(0,le.jsx)(sl,{className:"pb-3 px-4 flex-1",children:(0,le.jsx)("div",{className:" overflow-hidden",children:(0,le.jsx)("p",{className:"text-sm font-light line-clamp-3 text-[#3C444C]",children:i.description||"No description provided."})})}),(0,le.jsx)(al,{className:"px-4 py-2 flex mt-auto",children:(0,le.jsx)("div",{className:"flex gap-1 text-sm",children:(0,le.jsxs)("span",{className:"font-light font-base44 text-[#3C444C]",children:[o||0," installs"]})})})]})},UN=()=>{const e=(0,Z.Zp)(),t=()=>{e("/integrations-catalog/editor")};return(0,le.jsxs)(Qn,{className:"\n p-4 h-full overflow-hidden transition-all duration-300 ease-out\n flex flex-col rounded-[16px] font-base44 shadow-lg border-0\n hover:shadow-2xl cursor-pointer group relative\n hover:scale-[1.03] hover:-translate-y-1\n ",style:{background:" linear-gradient(211deg, rgba(48, 45, 56, 1) 0%, rgba(48, 45, 56, 1) 37%, rgba(140, 72, 55, 1) 85%, rgba(254, 127, 72, 1) 100%)"},onClick:t,children:[(0,le.jsx)(Xn,{className:"pb-1 px-4 pt-4 relative z-10",children:(0,le.jsx)(el,{className:"text-[16px] font-regular text-white leading-tight text-left",children:"Create Your Integration"})}),(0,le.jsx)(sl,{className:"pb-3 px-4 flex-1 relative z-10",children:(0,le.jsx)("div",{className:"text-left",children:(0,le.jsx)("p",{className:"text-sm font-light line-clamp-3 text-white/90",children:"Automate your workflow or build for the community \u2013 create powerful integrations in just a few clicks"})})}),(0,le.jsx)(al,{className:"px-4 py-2 flex mt-auto relative z-10",children:(0,le.jsx)("button",{className:"bg-orange-500 hover:bg-orange-600 text-white font-medium py-2 px-4 rounded-[12px] transition-all duration-200 text-sm",onClick:e=>{e.stopPropagation(),t()},children:"Create Integration"})})]})},WN=()=>(0,le.jsxs)(Qn,{className:"h-full overflow-hidden bg-white flex flex-col rounded-[16px] font-base44 shadow-none border-0 border-gray-100 animate-pulse",children:[(0,le.jsx)(Xn,{className:"pb-1 px-4 pt-4",children:(0,le.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,le.jsx)("div",{className:"h-12 w-12 flex-shrink-0 rounded-md bg-slate-200"}),(0,le.jsx)("div",{className:"w-full",children:(0,le.jsx)("div",{className:"h-5 bg-slate-200 rounded w-3/4 mb-2"})})]})}),(0,le.jsx)(sl,{className:"pb-3 px-4 flex-1",children:(0,le.jsx)("div",{className:"overflow-hidden",children:(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsx)("div",{className:"h-4 bg-slate-200 rounded w-full"}),(0,le.jsx)("div",{className:"h-4 bg-slate-200 rounded w-5/6"}),(0,le.jsx)("div",{className:"h-4 bg-slate-200 rounded w-4/6"})]})})}),(0,le.jsx)(al,{className:"px-4 py-2 flex mt-auto",children:(0,le.jsx)("div",{className:"h-4 bg-slate-200 rounded w-20"})})]}),qN=e=>{let{count:t=12}=e;return(0,le.jsx)("div",{className:"space-y-6",children:(0,le.jsx)("div",{className:"grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 2xl:grid-cols-4 gap-5",children:Array.from({length:t}).map((e,t)=>(0,le.jsx)(WN,{},"skeleton-".concat(t)))})})},VN=e=>{let{isLoading:t,isLoadingMore:s,items:a,onCardClick:n,hasMore:l,targetRef:r,isAdmin:i,onCreateIntegration:o,activeTab:c,currentUser:d}=e;if(t)return(0,le.jsx)(qN,{});if(0===a.length)return"my-integrations"===c?(0,le.jsx)("div",{className:"text-center py-16 px-8",children:(0,le.jsxs)("div",{className:"max-w-sm mx-auto",children:[(0,le.jsx)("div",{className:"relative mb-6",children:(0,le.jsx)("div",{className:"w-16 h-16 mx-auto bg-gradient-to-br from-teal-100 to-blue-100 rounded-full flex items-center justify-center",children:(0,le.jsx)(er.A,{className:"h-8 w-8 text-teal-600"})})}),(0,le.jsx)("h3",{className:"text-xl font-base44 font-medium text-slate-900 mb-3",children:"Create your first integration"}),(0,le.jsx)("p",{className:"text-slate-600 font-base44 mb-6 leading-relaxed",children:"Build custom integrations to connect your apps with external APIs and services. Share them with the community to earn credits!"}),(0,le.jsxs)("button",{onClick:o,className:"inline-flex items-center px-6 py-3 bg-teal-600 hover:bg-teal-700 text-white font-base44 font-medium rounded-lg transition-colors shadow-sm focus:outline-none focus:ring-2 focus:ring-teal-500 focus:ring-offset-2",children:[(0,le.jsx)(kt.A,{className:"h-4 w-4 mr-2"}),"Create Integration"]})]})}):(0,le.jsxs)("div",{className:"text-center p-12 border rounded-lg bg-slate-50",children:[(0,le.jsx)("div",{className:"text-slate-400 mb-3",children:(0,le.jsx)(vn.A,{className:"h-12 w-12 mx-auto"})}),(0,le.jsx)("h3",{className:"text-lg font-medium text-slate-700 mb-1",children:"No matching integrations found"}),(0,le.jsx)("p",{className:"text-slate-500 text-sm",children:"Try adjusting your search or filter settings."})]});return(0,le.jsxs)("div",{className:"space-y-6",children:[(0,le.jsx)("div",{className:"grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 2xl:grid-cols-4 gap-5",children:(()=>{const e=[];return a.forEach((t,s)=>{5===s&&e.push((0,le.jsx)(UN,{},"create-integration-card")),e.push((0,le.jsx)(zN,{item:t,onSelect:n,isAdmin:i,currentUser:d},t.item.id))}),a.length<6&&e.push((0,le.jsx)(UN,{},"create-integration-card")),e})()}),s&&(0,le.jsxs)("div",{className:"flex justify-center items-center py-8",children:[(0,le.jsx)(Ne.A,{className:"h-6 w-6 text-teal-600 animate-spin mr-2"}),(0,le.jsx)("span",{className:"text-sm text-slate-500",children:"Loading more integrations..."})]}),l&&!s&&(0,le.jsx)("div",{ref:r,className:"h-1"}),!l&&a.length>0&&(0,le.jsx)("div",{className:"text-center py-8 text-sm text-slate-500",children:"You've reached the end of the integrations catalog"})]})};const HN=function(){const{user:e}=oe(),t=(0,Y.useRef)(0),[s,a]=(0,Y.useState)("catalog"),[n,l]=(0,Y.useState)([]),[r,i]=(0,Y.useState)(!0),[o,c]=(0,Y.useState)(""),[d,m]=(0,Y.useState)("all"),[u,x]=(0,Y.useState)("most-upvoted"),[h,p]=(0,Y.useState)("all"),[g,f]=(0,Y.useState)("all"),[v,b]=(0,Y.useState)(new Set),j=(0,Z.Zp)(),[y,N]=(0,Y.useState)(!0),[w,_]=(0,Y.useState)(!1),[k,C]=(0,Y.useState)(0),[A]=(0,Y.useState)(20),[S,E]=(0,Y.useState)(0),I="platform_admin"===(null==e?void 0:e.platform_role),T=e=>{switch(e){case"newest":return"-created_date";case"oldest":return"created_date";default:return"-usage"}},P=(0,Y.useCallback)(async function(){let a=arguments.length>0&&void 0!==arguments[0]&&arguments[0];const n=++t.current;try{a?_(!0):(i(!0),E(0));const r=(()=>{const t={};return"my-integrations"===s&&null!=e&&e.email&&(t.created_by=e.email),o.trim()&&(t.$or=[{name:{$regex:o.trim(),$options:"i"}},{description:{$regex:o.trim(),$options:"i"}},{created_by:{$regex:o.trim(),$options:"i"}}]),"all"!==d&&(t.categories=d),I&&("private"===h?t.is_private=!0:"public"===h&&(t.is_private=!1),"pending"===g?t.status="pending":"approved"===g&&(t.status="approved")),t})(),c=a?S:0,m=await Kt.listCatalogItems((0,K.A)((0,K.A)({},r),{},{limit:A,skip:c,sort_by:T(u)}));if(n!==t.current)return;const x=m.data||m||[];a?(l(e=>[...e,...x]),E(e=>e+A)):(l(x),E(A)),N(x.length===A),C(e=>a?e+x.length:x.length);const p=new Set(x.filter(e=>e.did_current_user_upvote).map(e=>e.item.id));b(a?e=>new Set([...Array.from(e),...Array.from(p)]):p)}catch(r){if(n!==t.current)return;an({title:"Error",description:"Failed to load integrations",variant:"destructive"}),a||l([])}finally{n===t.current&&(i(!1),_(!1))}},[s,u,h,g,o,d,I,S,A,null==e?void 0:e.email]);(0,Y.useEffect)(()=>{P()},[]),(0,Y.useEffect)(()=>{P(!1)},[s,o,d,u,h,g]);const{targetRef:L}=RN({onLoadMore:()=>{y&&!w&&P(!0)},hasMore:y,isLoading:r||w}),O=n.length,R=k>0?"Showing ".concat(O," of ").concat(k," integrations"):"";return(0,le.jsxs)("div",{className:"px-4 sm:px-6 md:px-8 lg:px-12 max-w-[1600px] mx-auto",children:[(0,le.jsx)(MN,{activeTab:s,onTabChange:e=>{e!==s&&(l([]),i(!0),a(e),E(0),N(!0),C(0))}}),(0,le.jsx)(FN,{searchTerm:o,onSearchChange:e=>{c(e)},selectedCategory:d,onCategoryChange:e=>{m(e)},sortBy:u,onSortByChange:e=>{x(e)},privacyFilter:h,onPrivacyFilterChange:e=>{p(e)},statusFilter:g,onStatusFilterChange:e=>{f(e)},totalItems:k,displayedItems:O,showingText:R,isLoading:r,isAdmin:I}),(0,le.jsx)(VN,{isLoading:r,isLoadingMore:w,items:n,onCardClick:e=>{j("/integrations-catalog/item/".concat(e))},hasMore:y,targetRef:L,isAdmin:I,onCreateIntegration:()=>{j("/integrations-catalog/editor")},activeTab:s})]})};var YN=s(32369);const GN=["className","orientation","decorative"],$N=Y.forwardRef((e,t)=>{let{className:s,orientation:a="horizontal",decorative:n=!0}=e,l=(0,Se.A)(e,GN);return(0,le.jsx)(xs.b,(0,K.A)({ref:t,decorative:n,orientation:a,className:Pe("shrink-0 bg-border","horizontal"===a?"h-[1px] w-full":"h-full w-[1px]",s)},l))});$N.displayName=xs.b.displayName;const JN=()=>(0,le.jsx)("div",{className:"min-h-screen bg-white font-base44 animate-pulse",children:(0,le.jsxs)("div",{className:"mx-auto",children:[(0,le.jsx)("div",{className:"max-w-7xl mx-auto px-4 sm:px-6 py-4",children:(0,le.jsxs)("nav",{className:"flex items-center space-x-2 text-sm",children:[(0,le.jsx)("div",{className:"h-4 w-20 bg-slate-200 rounded"}),(0,le.jsx)("span",{children:"/"}),(0,le.jsx)("div",{className:"h-4 w-32 bg-slate-200 rounded"})]})}),(0,le.jsx)("div",{className:"border-b border-slate-200"}),(0,le.jsxs)("div",{className:"flex flex-col lg:flex-row max-w-7xl mx-auto gap-6 lg:gap-8 p-4 sm:p-6",children:[(0,le.jsx)("div",{className:"w-full lg:w-80 lg:flex-shrink-0",children:(0,le.jsxs)("div",{className:"mb-8",children:[(0,le.jsx)("div",{className:"flex gap-4 items-start mb-4",children:(0,le.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,le.jsx)("div",{className:"h-16 w-16 rounded-xl bg-slate-200"}),(0,le.jsxs)("div",{className:"text-center",children:[(0,le.jsx)("div",{className:"h-6 w-40 bg-slate-200 rounded mb-2 mx-auto"}),(0,le.jsx)("div",{className:"h-4 w-16 bg-slate-200 rounded mx-auto"})]})]})}),(0,le.jsxs)("div",{className:"space-y-3 mb-6",children:[(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[(0,le.jsx)("div",{className:"h-4 w-4 bg-slate-200 rounded"}),(0,le.jsx)("div",{className:"h-4 w-16 bg-slate-200 rounded"})]}),(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[(0,le.jsx)("div",{className:"h-4 w-4 bg-slate-200 rounded"}),(0,le.jsx)("div",{className:"h-4 w-24 bg-slate-200 rounded"})]})]}),(0,le.jsx)("div",{className:"w-full lg:w-[280px] h-12 bg-slate-200 rounded-[16px] mb-4"}),(0,le.jsxs)("div",{className:"space-y-4",children:[(0,le.jsxs)("div",{children:[(0,le.jsx)("div",{className:"h-4 w-12 bg-slate-200 rounded mb-2"}),(0,le.jsx)("div",{className:"h-4 w-28 bg-slate-200 rounded"})]}),(0,le.jsxs)("div",{children:[(0,le.jsx)("div",{className:"h-4 w-full bg-slate-200 rounded mb-1"}),(0,le.jsx)("div",{className:"h-4 w-3/4 bg-slate-200 rounded"})]})]}),(0,le.jsx)("div",{className:"h-px w-full bg-slate-200 my-6"}),(0,le.jsxs)("div",{className:"mt-6 space-y-3",children:[(0,le.jsxs)("div",{className:"flex items-center justify-between w-full",children:[(0,le.jsx)("div",{className:"h-4 w-36 bg-slate-200 rounded"}),(0,le.jsx)("div",{className:"h-4 w-4 bg-slate-200 rounded"})]}),(0,le.jsxs)("div",{className:"flex items-center justify-between w-full",children:[(0,le.jsx)("div",{className:"h-4 w-32 bg-slate-200 rounded"}),(0,le.jsx)("div",{className:"h-4 w-4 bg-slate-200 rounded"})]})]})]})}),(0,le.jsxs)("div",{className:"flex-1 border border-slate-200 p-6 rounded-[20px] min-w-0",children:[(0,le.jsxs)("div",{className:"mb-8",children:[(0,le.jsx)("div",{className:"h-6 sm:h-8 w-28 bg-slate-200 rounded mb-4"}),(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsx)("div",{className:"h-4 w-full bg-slate-200 rounded"}),(0,le.jsx)("div",{className:"h-4 w-full bg-slate-200 rounded"}),(0,le.jsx)("div",{className:"h-4 w-3/4 bg-slate-200 rounded"})]})]}),(0,le.jsxs)("div",{className:"mb-8",children:[(0,le.jsx)("div",{className:"h-6 w-40 bg-slate-200 rounded mb-4"}),(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsx)("div",{className:"bg-slate-100 rounded-lg px-4 py-3",children:(0,le.jsx)("div",{className:"h-4 w-full bg-slate-200 rounded"})}),(0,le.jsx)("div",{className:"bg-slate-100 rounded-lg px-4 py-3",children:(0,le.jsx)("div",{className:"h-4 w-5/6 bg-slate-200 rounded"})}),(0,le.jsx)("div",{className:"bg-slate-100 rounded-lg px-4 py-3",children:(0,le.jsx)("div",{className:"h-4 w-4/5 bg-slate-200 rounded"})})]})]}),(0,le.jsxs)("div",{className:"mb-8",children:[(0,le.jsxs)("div",{className:"bg-slate-100 p-1 mb-6 rounded-md flex gap-1",children:[(0,le.jsx)("div",{className:"h-8 w-24 bg-slate-200 rounded"}),(0,le.jsx)("div",{className:"h-8 w-32 bg-slate-200 rounded"})]}),(0,le.jsx)("div",{className:"space-y-4",children:(0,le.jsxs)("div",{children:[(0,le.jsxs)("div",{className:"flex items-center justify-between mb-3",children:[(0,le.jsx)("div",{className:"h-5 w-32 bg-slate-200 rounded"}),(0,le.jsx)("div",{className:"h-4 w-24 bg-slate-200 rounded"})]}),(0,le.jsx)("div",{className:"h-4 w-full bg-slate-200 rounded mb-4"}),(0,le.jsxs)("div",{className:"space-y-3",children:[(0,le.jsxs)("div",{className:"bg-slate-100 rounded-lg p-4 border border-slate-200",children:[(0,le.jsx)("div",{className:"h-5 w-24 bg-slate-200 rounded mb-2"}),(0,le.jsx)("div",{className:"h-4 w-full bg-slate-200 rounded"})]}),(0,le.jsxs)("div",{className:"bg-slate-100 rounded-lg p-4 border border-slate-200",children:[(0,le.jsx)("div",{className:"h-5 w-32 bg-slate-200 rounded mb-2"}),(0,le.jsx)("div",{className:"h-4 w-5/6 bg-slate-200 rounded"})]})]})]})})]}),(0,le.jsx)("div",{className:"mb-8 p-4 bg-slate-100 border border-slate-200 rounded-lg",children:(0,le.jsxs)("div",{className:"flex items-start gap-3",children:[(0,le.jsx)("div",{className:"h-8 w-8 rounded-full bg-slate-200 flex-shrink-0"}),(0,le.jsxs)("div",{children:[(0,le.jsx)("div",{className:"h-5 w-28 bg-slate-200 rounded mb-2"}),(0,le.jsx)("div",{className:"h-9 w-36 bg-slate-200 rounded"})]})]})})]})]}),(0,le.jsx)("div",{className:"max-w-7xl mx-auto px-4 sm:px-6 pb-8",children:(0,le.jsxs)("div",{className:"bg-slate-100 rounded-2xl border border-slate-200 p-6",children:[(0,le.jsxs)("div",{className:"mb-4",children:[(0,le.jsx)("div",{className:"h-6 w-48 bg-slate-200 rounded mb-2"}),(0,le.jsxs)("div",{className:"space-y-1",children:[(0,le.jsx)("div",{className:"h-4 w-full bg-slate-200 rounded"}),(0,le.jsx)("div",{className:"h-4 w-2/3 bg-slate-200 rounded"})]})]}),(0,le.jsxs)("div",{className:"flex flex-col sm:flex-row sm:flex-wrap gap-3",children:[(0,le.jsx)("div",{className:"h-10 w-36 bg-slate-200 rounded-xl"}),(0,le.jsx)("div",{className:"h-10 w-28 bg-slate-200 rounded-xl"}),(0,le.jsx)("div",{className:"h-10 w-32 bg-slate-200 rounded-xl"}),(0,le.jsx)("div",{className:"h-10 w-20 bg-slate-200 rounded-xl"})]})]})})]})}),ZN=()=>{var e;const{itemId:t}=(0,Z.g)(),s=(0,Z.Zp)(),{user:a}=oe(),[n,l]=(0,Y.useState)(null),[r,i]=(0,Y.useState)(!0),[o,c]=(0,Y.useState)(null),[d,m]=(0,Y.useState)("details"),[u,x]=(0,Y.useState)(!1),[h,p]=(0,Y.useState)(!1),[g,f]=(0,Y.useState)(!1),[v,b]=(0,Y.useState)(!1),[j,y]=(0,Y.useState)(!1),[N,w]=(0,Y.useState)(""),[_,k]=(0,Y.useState)(!1),C=a&&"platform_admin"===a.platform_role,A=a&&("free"===a.subscription_tier||"starter"===a.subscription_tier);(0,Y.useEffect)(()=>{t&&S()},[t]);const S=async()=>{if(t)try{i(!0);const e=await Kt.getCatalogItem(t);l(e.data||e),i(!1)}catch(e){c("Failed to load item details"),i(!1)}};if(r)return(0,le.jsx)(JN,{});if(o)return(0,le.jsxs)("div",{className:"flex flex-col items-center justify-center min-h-[500px] text-center p-4",children:[(0,le.jsxs)("div",{className:"text-red-500 text-xl font-semibold mb-2",children:["\u26a0\ufe0f ",o]}),(0,le.jsx)("button",{className:"px-4 py-2 bg-blue-500 text-white rounded-md hover:bg-blue-600 transition-colors",onClick:S,children:"Try Again"})]});if(!n)return null;const{item:E,is_user_the_owner:I}=n,T="approved"!==E.status,P=E.required_secrets&&E.required_secrets.length>0,L=E.requires_backend_functions&&A;return(0,le.jsx)("div",{className:"min-h-screen bg-white font-base44",children:(0,le.jsxs)("div",{className:"mx-auto",children:[(0,le.jsx)("div",{className:"max-w-7xl mx-auto px-4 sm:px-6 py-4",children:(0,le.jsxs)("nav",{className:"flex items-center space-x-2 text-sm text-slate-600",children:[(0,le.jsx)("button",{onClick:()=>{s("/integrations-catalog")},className:"hover:text-slate-900 transition-colors",children:"Integrations"}),(0,le.jsx)("span",{children:"/"}),(0,le.jsx)("span",{className:"text-slate-900 font-medium",children:E.name})]})}),(0,le.jsx)("div",{className:"border-b border-slate-200"}),(0,le.jsxs)("div",{className:"flex flex-col lg:flex-row max-w-7xl mx-auto gap-6 lg:gap-8 p-4 sm:p-6",children:[(0,le.jsx)("div",{className:"w-full lg:w-80 lg:flex-shrink-0",children:(0,le.jsxs)("div",{className:"mb-8",children:[(0,le.jsx)("div",{className:"flex gap-4 items-start mb-4",children:(0,le.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,le.jsx)("div",{className:"h-16 w-16 rounded-xl overflow-hidden bg-white",children:E.image_url?(0,le.jsx)(gl,{src:E.image_url,alt:E.name,className:"h-full w-full",objectFit:"contain",quality:85,lazy:!1}):(0,le.jsx)("div",{className:"h-full w-full bg-slate-50 flex items-center justify-center",children:(0,le.jsx)("span",{className:"text-slate-600 text-lg font-semibold",children:E.name.charAt(0).toUpperCase()})})}),(0,le.jsx)("div",{className:"text-center",children:(0,le.jsx)("h1",{className:"text-lg sm:text-xl font-semibold break-words",children:E.name})}),E.official&&(0,le.jsxs)("div",{className:"flex items-center gap-1 mt-2",children:[(0,le.jsx)(BN.A,{className:"h-4 w-4 text-blue-600"}),(0,le.jsx)("span",{className:"text-sm text-blue-600 font-medium",children:"Official"})]})]})}),(0,le.jsxs)("div",{className:"space-y-3 mb-6",children:[(0,le.jsxs)("div",{className:"flex items-center gap-2 text-sm text-slate-600",children:[(0,le.jsx)(bn.A,{className:"h-4 w-4"}),(0,le.jsx)("span",{children:E.is_private?"Private":"Public"})]}),E.created_at&&(0,le.jsxs)("div",{className:"flex items-center gap-2 text-sm text-slate-600",children:[(0,le.jsx)(Li.A,{className:"h-4 w-4"}),(0,le.jsxs)("span",{children:["Added ",ra().utc(E.created_at).fromNow()]})]})]}),L?(0,le.jsx)(Hn,{size:"lg",className:"w-full lg:w-[280px] bg-slate-200 text-slate-500 cursor-not-allowed mb-4 text-md rounded-[16px]",disabled:!0,children:"Use this integration"}):(0,le.jsx)(Hn,{onClick:()=>{s("/?integrations=".concat(t))},size:"lg",className:"w-full lg:w-[280px] bg-orange-500 hover:bg-orange-600 text-white mb-4 text-md rounded-[16px]",children:"Use this integration"}),L&&(0,le.jsx)("div",{className:"bg-amber-50 border border-amber-200 rounded-md p-3 mb-4",children:(0,le.jsxs)("div",{className:"flex gap-2",children:[(0,le.jsx)(_e.A,{className:"h-4 w-4 text-amber-600 flex-shrink-0 mt-0.5"}),(0,le.jsx)("p",{className:"text-sm text-amber-800",children:"This integration requires backend functions, a feature available only on Builder tier and above."})]})}),(0,le.jsxs)("div",{className:"space-y-4",children:[(0,le.jsxs)("div",{className:"flex justify-between items-center",children:[(0,le.jsx)("span",{className:"text-sm font-medium text-slate-900",children:"Status"}),"approved"===E.status?(0,le.jsxs)(Nn,{className:"bg-green-100 text-green-800 hover:bg-green-200",children:[(0,le.jsx)(Vg.A,{className:"h-3 w-3 mr-1"}),"Approved"]}):(0,le.jsx)(Nn,{className:"bg-amber-100 text-amber-800 hover:bg-amber-200",children:"Pending Approval"})]}),(0,le.jsxs)("div",{children:[(0,le.jsx)("h4",{className:"text-sm font-medium text-slate-900 mb-3",children:"Share this integration"}),(0,le.jsxs)("div",{className:"flex items-center gap-1.5 p-1.5 bg-slate-50 rounded-md border border-slate-200",children:[(0,le.jsx)("div",{className:"flex-1 text-xs text-slate-600 truncate font-mono",children:window.location.href}),(0,le.jsx)(Hn,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 hover:bg-slate-200",onClick:async()=>{try{f(!0);const e=window.location.href;await navigator.clipboard.writeText(e),an({title:"Link copied",description:"Integration link has been copied to clipboard"}),setTimeout(()=>f(!1),1e3)}catch(e){an({title:"Error",description:"Failed to copy link to clipboard",variant:"destructive"}),f(!1)}},disabled:g,title:g?"Copied!":"Copy link",children:g?(0,le.jsx)(Ps.A,{className:"h-3.5 w-3.5 text-green-600"}):(0,le.jsx)(or.A,{className:"h-3.5 w-3.5 text-slate-500"})})]})]}),E.requires_backend_functions&&(0,le.jsxs)("div",{children:[(0,le.jsx)("p",{className:"text-sm text-slate-600 break-words",children:"Using this integration will automatically activate backend functions."}),(0,le.jsx)("p",{className:"text-sm text-slate-600 mt-1 break-words",children:"Available on the Builder tier and above."})]})]}),(0,le.jsx)($N,{className:"my-6 bg-gray-400"}),P&&(0,le.jsxs)("div",{className:"mt-6 space-y-3",children:[(0,le.jsxs)("button",{className:"flex items-center justify-between w-full text-sm text-slate-600 hover:text-slate-900",children:[(0,le.jsx)("span",{children:"How to get your API key"}),(0,le.jsx)("span",{children:"\u2197"})]}),(0,le.jsxs)("button",{className:"flex items-center justify-between w-full text-sm text-slate-600 hover:text-slate-900",onClick:()=>s("/support"),children:[(0,le.jsx)("span",{children:"Base44 support hub"}),(0,le.jsx)("span",{children:"\u2197"})]})]})]})}),(0,le.jsxs)("div",{className:"flex-1 border border-slate-200 p-6 rounded-[20px] min-w-0",children:[(0,le.jsxs)("div",{className:"mb-8",children:[(0,le.jsx)("h1",{className:"text-xl sm:text-2xl font-bold text-slate-900 mb-4",children:"Overview"}),(0,le.jsx)("p",{className:"text-slate-600 text-base leading-relaxed break-words",children:E.description})]}),E.example_asks&&E.example_asks.length>0&&(0,le.jsxs)("div",{className:"mb-8",children:[(0,le.jsx)("h3",{className:"text-lg font-semibold text-slate-900 mb-4",children:"Example prompts"}),(0,le.jsx)("div",{className:"space-y-2",children:E.example_asks.map((e,t)=>(0,le.jsx)("div",{className:"bg-slate-50 rounded-lg px-4 py-3 text-sm text-slate-700 break-words",children:e},t))})]}),(P||E.prompt)&&(0,le.jsx)("div",{className:"mb-8",children:(0,le.jsxs)(kp,{defaultValue:P?"requirements":"instructions",className:"w-full",children:[(0,le.jsxs)(Cp,{className:"bg-slate-50 p-1 mb-6",children:[P&&(0,le.jsx)(Ap,{value:"requirements",className:"text-sm data-[state=active]:bg-white data-[state=active]:shadow-sm",children:"Requirements"}),E.prompt&&(0,le.jsx)(Ap,{value:"instructions",className:"text-sm data-[state=active]:bg-white data-[state=active]:shadow-sm",children:"Instructions Set"})]}),P&&(0,le.jsx)(Sp,{value:"requirements",children:(0,le.jsx)("div",{className:"space-y-4",children:(0,le.jsxs)("div",{children:[(0,le.jsxs)("div",{className:"flex items-center justify-between mb-3",children:[(0,le.jsx)("h4",{className:"font-semibold text-slate-900",children:"Required API Keys"}),(0,le.jsxs)("button",{className:"text-sm text-blue-600 hover:text-blue-800 flex items-center gap-1",children:["Documentation ",(0,le.jsx)("span",{children:"\u2197"})]})]}),(0,le.jsx)("p",{className:"text-sm text-slate-600 mb-4",children:"You'll need these credentials to use this integration:"}),(0,le.jsx)("div",{className:"space-y-3",children:null===(e=E.required_secrets)||void 0===e?void 0:e.map((e,t)=>(0,le.jsxs)("div",{className:"bg-slate-50 rounded-lg p-4 border border-slate-200",children:[(0,le.jsx)("h5",{className:"font-medium text-slate-900 mb-2 break-words",children:e.name}),(0,le.jsx)("p",{className:"text-sm text-slate-600 break-words",children:e.description||"Required for this integration to work properly."})]},t))})]})})}),E.prompt&&(0,le.jsx)(Sp,{value:"instructions",children:(0,le.jsxs)("div",{className:"space-y-4",children:[(0,le.jsx)("div",{children:(0,le.jsx)("p",{className:"text-sm text-slate-600 mb-4",children:"These instructions will be injected into Base44's AI when this integration is used"})}),(0,le.jsx)("div",{className:"bg-blue-50 border border-blue-200 rounded-lg p-4",children:(0,le.jsxs)("div",{className:"flex gap-2",children:[(0,le.jsx)(ir.A,{className:"h-4 w-4 text-blue-600 flex-shrink-0 mt-0.5"}),(0,le.jsx)("div",{children:(0,le.jsxs)("p",{className:"text-sm text-blue-800",children:[(0,le.jsx)("span",{className:"font-medium",children:"How this works:"})," When you use this integration, these instructions are automatically injected into Base44's AI system, enabling it to perform the specific tasks defined here."]})})]})}),(0,le.jsx)("div",{className:"bg-slate-50 p-4 rounded-lg border border-slate-200 overflow-auto max-h-[500px]",children:(0,le.jsx)("pre",{className:"whitespace-pre-wrap text-sm text-slate-700 font-mono break-words overflow-hidden",children:E.prompt})})]})})]})}),C&&T&&(0,le.jsx)("div",{className:"mb-8 p-4 bg-blue-50 border border-blue-200 rounded-lg",children:(0,le.jsxs)("div",{className:"flex items-start gap-3",children:[(0,le.jsx)("div",{className:"h-8 w-8 rounded-full bg-blue-100 flex items-center justify-center flex-shrink-0",children:(0,le.jsx)(qc.A,{className:"h-4 w-4 text-blue-600"})}),(0,le.jsxs)("div",{children:[(0,le.jsx)("h4",{className:"font-medium text-slate-900",children:"Admin Actions"}),(0,le.jsx)("div",{className:"mt-2",children:(0,le.jsxs)(Hn,{onClick:async()=>{if(t)try{x(!0),await Kt.approveItem(t),an({title:"Success",description:"Integration has been approved"}),S()}catch(e){an({title:"Error",description:"Failed to approve integration",variant:"destructive"})}finally{x(!1)}},disabled:u,size:"sm",className:"bg-green-600 hover:bg-green-700 text-white",children:[(0,le.jsx)(Vg.A,{className:"h-4 w-4 mr-1.5"}),u?"Approving...":"Approve Integration"]})})]})]})})]})]}),I&&(0,le.jsx)(le.Fragment,{children:(0,le.jsx)("div",{className:"max-w-7xl mx-auto px-4 sm:px-6 pb-8",children:(0,le.jsxs)("div",{className:"bg-slate-50 rounded-2xl border border-slate-200 p-6",children:[(0,le.jsxs)("div",{className:"mb-4",children:[(0,le.jsx)("h3",{className:"text-lg font-semibold text-slate-900 mb-2",children:"Integration Management"}),(0,le.jsx)("p",{className:"text-sm text-slate-600",children:"As the owner of this integration, you can manage its settings and visibility."})]}),(0,le.jsxs)("div",{className:"flex flex-col sm:flex-row sm:flex-wrap gap-3",children:[(0,le.jsxs)(Hn,{variant:"outline",size:"default",onClick:()=>{s("/integrations-catalog/editor/".concat(t))},className:"bg-white text-slate-700 border-slate-300 hover:bg-slate-50 rounded-xl px-6",children:[(0,le.jsx)(Ql.A,{className:"h-4 w-4 mr-2"}),"Edit Integration"]}),(0,le.jsx)(Hn,{variant:"outline",size:"default",onClick:async()=>{if(t&&n)try{y(!0),await Kt.update(t,{is_private:!n.item.is_private}),an({title:"Success",description:n.item.is_private?"Integration is now public":"Integration is now private"}),S()}catch(e){an({title:"Error",description:"Failed to update integration privacy setting",variant:"destructive"})}finally{y(!1)}},disabled:j,className:"bg-white text-slate-700 border-slate-300 hover:bg-slate-50 rounded-xl px-6",children:j?(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)("div",{className:"h-4 w-4 mr-2 animate-spin rounded-full border-2 border-slate-400 border-t-transparent"}),"Updating..."]}):E.is_private?(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(bn.A,{className:"h-4 w-4 mr-2"}),"Make Public"]}):(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(Mt.A,{className:"h-4 w-4 mr-2"}),"Make Private"]})}),(0,le.jsxs)(tc,{open:_,onOpenChange:k,children:[(0,le.jsx)(sc,{asChild:!0,children:(0,le.jsxs)(Hn,{variant:"outline",size:"default",className:"bg-white text-slate-700 border-slate-300 hover:bg-slate-50 rounded-xl px-6",children:[(0,le.jsx)(sv.A,{className:"h-4 w-4 mr-2"}),"Invite Admin"]})}),(0,le.jsxs)(lc,{className:"sm:max-w-[425px]",children:[(0,le.jsxs)(rc,{children:[(0,le.jsx)(oc,{children:"Invite User"}),(0,le.jsx)(cc,{children:"Invite a user to edit and administer this catalog item"})]}),(0,le.jsx)("div",{className:"grid gap-4 py-4",children:(0,le.jsxs)("div",{className:"grid grid-cols-4 items-center gap-4",children:[(0,le.jsx)(go,{htmlFor:"email",className:"text-right",children:"Email"}),(0,le.jsx)(fn,{id:"email",type:"email",placeholder:"user@example.com",className:"col-span-3",value:N,onChange:e=>w(e.target.value)})]})}),(0,le.jsx)(ic,{children:(0,le.jsx)(Hn,{onClick:async()=>{if(t&&N&&N.includes("@"))try{b(!0),await Kt.inviteAdmin(t,N),an({title:"Success",description:"Invitation sent to ".concat(N)}),w(""),k(!1)}catch(e){an({title:"Error",description:"Failed to send invitation",variant:"destructive"})}finally{b(!1)}else an({title:"Invalid email",description:"Please enter a valid email address",variant:"destructive"})},disabled:v||!N,className:"bg-slate-900 hover:bg-slate-800 text-white",children:v?"Sending...":"Send Invitation"})})]})]}),(0,le.jsxs)(Hn,{variant:"outline",size:"default",onClick:async()=>{if(t)try{p(!0),await Kt.archiveItem(t),an({title:"Success",description:"Integration has been archived"}),s("/integrations-catalog")}catch(e){an({title:"Error",description:"Failed to archive integration",variant:"destructive"}),p(!1)}},disabled:h,className:"bg-white text-red-600 border-red-200 hover:bg-red-50 rounded-xl px-6",children:[(0,le.jsx)(YN.A,{className:"h-4 w-4 mr-2"}),h?"Archiving...":"Archive"]})]})]})})})]})})};var KN=s(23198),QN=s(13052),XN=s(11464);const ew=["className"],tw=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,ew);return(0,le.jsx)(lx.bL,(0,K.A)((0,K.A)({className:Pe("peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",s)},a),{},{ref:t,children:(0,le.jsx)(lx.zi,{className:Pe("pointer-events-none block h-5 w-5 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-5 data-[state=unchecked]:translate-x-0")})}))});tw.displayName=lx.bL.displayName;const sw=e=>{let{children:t}=e;return(0,le.jsx)(Fi,{children:(0,le.jsxs)(Bi,{delayDuration:300,children:[(0,le.jsx)(zi,{asChild:!0,children:(0,le.jsx)(ku.A,{className:"h-4 w-4 text-slate-400 ml-1.5 cursor-help"})}),(0,le.jsx)(Ui,{className:"max-w-xs p-3 text-xs",children:t})]})})},aw=()=>{const{itemId:e}=(0,Z.g)(),t=(0,Z.Zp)(),{toast:s}=nn(),a=!!e,[n,l]=(0,Y.useState)(null),[r,i]=(0,Y.useState)(!!e),[o,c]=(0,Y.useState)(!1),[d,m]=(0,Y.useState)(!1),[u,x]=(0,Y.useState)(null),[h,p]=(0,Y.useState)({name:"",description:"",prompt:"",image_url:"",example_asks:[],required_secrets:[],requires_backend_functions:!0,is_private:!1}),[g,f]=(0,Y.useState)("metadata"),[v,b]=(0,Y.useState)(""),[j,y]=(0,Y.useState)(""),[N,w]=(0,Y.useState)("");(0,Y.useEffect)(()=>{e?(async()=>{if(e)try{i(!0);const t=await Kt.getCatalogItem(e),s=t.data||t;l(s);const a=s.item;p({name:a.name||"",description:a.description||"",prompt:a.prompt||"",image_url:a.image_url||"",example_asks:a.example_asks||[],required_secrets:a.required_secrets||[],requires_backend_functions:!1!==a.requires_backend_functions,is_private:a.is_private||!1})}catch(t){x("Failed to load integration. It may have been deleted or you may not have permission to view it.")}finally{i(!1)}})():i(!1)},[e]);const _=e=>{const{name:t,value:s}=e.target;p(e=>(0,K.A)((0,K.A)({},e),{},{[t]:s}))},k=(e,t)=>{p(s=>(0,K.A)((0,K.A)({},s),{},{[e]:t}))},C=async n=>{if(n&&n.preventDefault(),h.name.trim()?h.description.trim()?!(h.prompt.trim().length<50&&(s({title:"Validation Error",description:"Integration prompt must be at least 50 characters",variant:"destructive"}),f("content"),1)):(s({title:"Validation Error",description:"Integration description is required",variant:"destructive"}),f("metadata"),0):(s({title:"Validation Error",description:"Integration name is required",variant:"destructive"}),f("metadata"),0)){c(!0),x(null);try{let n;if(a&&e)await Kt.update(e,h),n=e;else{var l;const e=await Kt.create(h);n=(null===(l=e.data)||void 0===l?void 0:l.id)||e.id}s({title:"Success",description:a?"Integration updated successfully":"Integration created successfully"}),t("/integrations-catalog/item/".concat(n))}catch(r){x("Failed to save integration. Please try again."),s({title:"Error",description:"Failed to save integration. Please try again.",variant:"destructive"}),c(!1)}}},A=()=>{t("/integrations-catalog")};return r?(0,le.jsxs)("div",{className:"flex items-center justify-center h-[80vh]",children:[(0,le.jsx)(Ne.A,{className:"h-8 w-8 text-teal-600 animate-spin"}),(0,le.jsx)("span",{className:"ml-2 text-lg text-slate-700",children:"Loading integration..."})]}):u&&e&&!h.name?(0,le.jsxs)("div",{className:"flex flex-col items-center justify-center h-[80vh]",children:[(0,le.jsx)("div",{className:"text-red-500 text-lg mb-4",children:u}),(0,le.jsx)(Hn,{onClick:A,className:"px-4 py-2 bg-teal-600 text-white rounded hover:bg-teal-700",children:"Return to Catalog"})]}):(0,le.jsxs)("div",{className:"max-w-screen-xl mx-auto px-4 py-8",children:[(0,le.jsxs)("div",{className:"flex justify-between items-center mb-8",children:[(0,le.jsxs)("div",{className:"flex items-center gap-3",children:[(0,le.jsx)(Hn,{variant:"ghost",size:"icon",onClick:A,className:"h-10 w-10 rounded-full",children:(0,le.jsx)(Cd.A,{className:"h-5 w-5"})}),(0,le.jsx)("h1",{className:"text-2xl font-bold text-slate-900",children:a?"Edit Integration":"Create New Integration"})]}),(0,le.jsxs)("div",{className:"flex items-center gap-3",children:[(0,le.jsx)(Hn,{variant:"outline",onClick:A,className:"px-4",children:"Cancel"}),(0,le.jsxs)(Hn,{onClick:()=>C(),disabled:o,className:"bg-teal-600 hover:bg-teal-700 px-4",children:[o?(0,le.jsx)(Ne.A,{className:"h-4 w-4 mr-2 animate-spin"}):(0,le.jsx)(df.A,{className:"h-4 w-4 mr-2"}),o?"Saving...":"Save Integration"]})]})]}),(0,le.jsxs)("div",{className:"bg-gradient-to-r from-amber-50 to-amber-100 border border-amber-200 rounded-lg p-4 mb-6 flex items-center",children:[(0,le.jsx)(nj.A,{className:"h-5 w-5 text-amber-500 mr-3 flex-shrink-0"}),(0,le.jsxs)("p",{className:"text-amber-800",children:[(0,le.jsx)("span",{className:"font-semibold",children:"Earn 250 credits!"})," Create a public integration that gets approved and we'll reward you with 250 credits to your account."]})]}),u&&(0,le.jsx)(og,{variant:"destructive",className:"mb-6",children:(0,le.jsx)(dg,{children:u})}),(0,le.jsx)("div",{className:"bg-white rounded-xl border shadow-sm overflow-hidden",children:(0,le.jsxs)(kp,{value:g,onValueChange:f,className:"w-full",children:[(0,le.jsx)("div",{className:"px-6 pt-6 border-b",children:(0,le.jsxs)(Cp,{className:"grid w-full grid-cols-2 max-w-md",children:[(0,le.jsxs)(Ap,{value:"metadata",className:"flex items-center gap-2",children:[(0,le.jsx)(vm.A,{className:"h-4 w-4"}),(0,le.jsx)("span",{children:"Integration Metadata"})]}),(0,le.jsxs)(Ap,{value:"content",className:"flex items-center gap-2",children:[(0,le.jsx)(Kl.A,{className:"h-4 w-4"}),(0,le.jsx)("span",{children:"Integration Content"})]})]})}),(0,le.jsx)(Sp,{value:"metadata",className:"p-6 space-y-8",children:(0,le.jsxs)("div",{className:"grid gap-8 max-w-3xl mx-auto",children:[(0,le.jsxs)("div",{className:"space-y-4",children:[(0,le.jsxs)("div",{className:"flex items-center",children:[(0,le.jsx)("h2",{className:"text-lg font-semibold text-slate-900",children:"Integration Name"}),(0,le.jsx)(sw,{children:"A descriptive name for your integration that will be displayed in the catalog."})]}),(0,le.jsx)(fn,{id:"name",name:"name",value:h.name,onChange:_,placeholder:"E.g., OpenAI Text-To-Speech",required:!0,className:"text-lg"})]}),(0,le.jsxs)("div",{className:"space-y-4",children:[(0,le.jsxs)("div",{className:"flex items-center",children:[(0,le.jsx)("h2",{className:"text-lg font-semibold text-slate-900",children:"Description"}),(0,le.jsx)(sw,{children:"A brief explanation of what this integration does and how it helps users."})]}),(0,le.jsx)(yp,{id:"description",name:"description",value:h.description,onChange:_,placeholder:"Describe what this integration does and how it can be useful...",rows:3,required:!0})]}),(0,le.jsxs)("div",{className:"space-y-4",children:[(0,le.jsxs)("div",{className:"flex items-center",children:[(0,le.jsx)("h2",{className:"text-lg font-semibold text-slate-900",children:"Integration Logo"}),(0,le.jsx)(sw,{children:"An image that represents your integration. Square images work best."})]}),(0,le.jsxs)("div",{className:"flex items-center gap-8",children:[h.image_url?(0,le.jsx)("div",{className:"w-32 h-32 rounded-lg overflow-hidden border shadow-sm flex-shrink-0",children:(0,le.jsx)("img",{src:h.image_url,alt:"Integration Logo",className:"h-full w-full object-cover",onError:e=>{const t=e.target;t.src="",t.alt=""}})}):(0,le.jsxs)("div",{className:"w-32 h-32 rounded-lg border border-dashed flex-shrink-0 bg-slate-50 flex flex-col items-center justify-center",children:[(0,le.jsx)(KN.A,{className:"h-8 w-8 text-slate-400 mb-2"}),(0,le.jsx)("p",{className:"text-xs text-slate-500 text-center px-2",children:"No logo uploaded"})]}),(0,le.jsxs)("div",{className:"flex-1 max-w-sm",children:[(0,le.jsx)("input",{type:"file",id:"logo-upload",className:"hidden",accept:"image/*",onChange:async e=>{var t;const s=null===(t=e.target.files)||void 0===t?void 0:t[0];if(s)try{m(!0);const e=(await _t.uploadFile(s)).url;p(t=>(0,K.A)((0,K.A)({},t),{},{image_url:e}))}catch(a){x("Failed to upload logo. Please try again.")}finally{m(!1)}}}),(0,le.jsxs)(Hn,{type:"button",variant:h.image_url?"outline":"default",disabled:d,className:"w-full mb-3",onClick:()=>{var e;return null===(e=document.getElementById("logo-upload"))||void 0===e?void 0:e.click()},children:[(0,le.jsx)(hx.A,{className:"h-4 w-4 mr-2"}),d?"Uploading...":h.image_url?"Change Logo":"Upload Logo"]}),(0,le.jsx)("p",{className:"text-xs text-slate-500",children:"Upload a square image in PNG or JPG format (recommended size: 256\xd7256px)"})]})]})]}),(0,le.jsxs)("div",{className:"space-y-4",children:[(0,le.jsxs)("div",{className:"flex items-center",children:[(0,le.jsxs)("h2",{className:"text-lg font-semibold text-slate-900 flex items-center",children:[(0,le.jsx)(Ir.A,{className:"h-4 w-4 mr-2 text-teal-600"}),"Example Prompts"]}),(0,le.jsx)(sw,{children:"Add examples of how users can ask for this integration in plain language"})]}),(0,le.jsxs)("div",{className:"grid gap-4",children:[(0,le.jsxs)("div",{className:"flex gap-2",children:[(0,le.jsx)(fn,{placeholder:"E.g., Convert text to speech",value:v,onChange:e=>b(e.target.value)}),(0,le.jsxs)(Hn,{type:"button",onClick:()=>{v.trim()&&(p(e=>(0,K.A)((0,K.A)({},e),{},{example_asks:[...e.example_asks,v.trim()]})),b(""))},className:"bg-teal-600 hover:bg-teal-700 flex-shrink-0",children:[(0,le.jsx)(QN.A,{className:"h-4 w-4 mr-1"})," Add"]})]}),h.example_asks.length>0?(0,le.jsx)("div",{className:"flex flex-wrap gap-2",children:h.example_asks.map((e,t)=>(0,le.jsxs)(Nn,{variant:"outline",className:"bg-teal-50 text-teal-700 border-teal-200 px-3 py-1 flex items-center gap-1",children:[e,(0,le.jsx)("button",{type:"button",onClick:()=>(e=>{p(t=>(0,K.A)((0,K.A)({},t),{},{example_asks:t.example_asks.filter((t,s)=>s!==e)}))})(t),className:"ml-1 text-teal-700 hover:text-teal-900",children:(0,le.jsx)(Bt.A,{className:"h-3 w-3"})})]},t))}):(0,le.jsx)("div",{className:"text-sm text-slate-500 p-4 bg-slate-50 rounded-md border text-center",children:"No example prompts added yet. Add 3-5 examples to help users understand how to use this integration."})]})]}),(0,le.jsxs)("div",{className:"space-y-4",children:[(0,le.jsxs)("div",{className:"flex items-center",children:[(0,le.jsx)("h2",{className:"text-lg font-semibold text-slate-900",children:"Integration Visibility"}),(0,le.jsx)(sw,{children:"Control whether your integration is private or public"})]}),(0,le.jsxs)("div",{className:"bg-white rounded-lg p-4 border flex items-center gap-4",children:[(0,le.jsx)("div",{className:"h-10 w-10 rounded-full bg-slate-100 flex items-center justify-center flex-shrink-0",children:h.is_private?(0,le.jsx)(Mt.A,{className:"h-5 w-5 text-slate-700"}):(0,le.jsx)(bn.A,{className:"h-5 w-5 text-teal-600"})}),(0,le.jsxs)("div",{className:"flex-1",children:[(0,le.jsx)("h3",{className:"font-medium text-slate-900",children:h.is_private?"Private Integration":"Public Integration"}),(0,le.jsx)("p",{className:"text-sm text-slate-600",children:h.is_private?"Only visible to you and invited collaborators":"Visible to all users and eligible for 250 credits when approved"})]}),(0,le.jsx)(tw,{checked:!h.is_private,onCheckedChange:e=>k("is_private",!e)})]})]}),(0,le.jsx)("div",{className:"flex justify-end",children:(0,le.jsx)(Hn,{onClick:()=>f("content"),className:"bg-teal-600 hover:bg-teal-700",children:"Continue to Integration Content"})})]})}),(0,le.jsx)(Sp,{value:"content",className:"p-6",children:(0,le.jsxs)("div",{className:"max-w-6xl mx-auto",children:[(0,le.jsxs)("div",{className:"mb-8 bg-blue-50 rounded-lg p-4 border border-blue-100",children:[(0,le.jsxs)("h3",{className:"text-lg font-medium text-blue-800 mb-2 flex items-center",children:[(0,le.jsx)(uo.A,{className:"h-5 w-5 mr-2"}),"About Integration Content"]}),(0,le.jsx)("p",{className:"text-blue-700 text-sm",children:"This section contains the core functionality of your integration. The prompt provides implementation instructions, and you can specify any API keys needed to make it work."})]}),(0,le.jsxs)("div",{className:"mb-8",children:[(0,le.jsxs)("div",{className:"flex items-center mb-2",children:[(0,le.jsx)("h2",{className:"text-xl font-semibold text-slate-900",children:"Integration Settings"}),(0,le.jsx)(sw,{children:"Configure how your integration should behave and what capabilities it needs."})]}),(0,le.jsx)("p",{className:"text-sm text-slate-600 mb-4",children:"These settings determine how your integration functions and what features it can access."}),(0,le.jsx)(Qn,{className:"border-slate-200",children:(0,le.jsx)(sl,{className:"pt-6 space-y-6",children:(0,le.jsxs)("div",{className:"flex items-center gap-4",children:[(0,le.jsx)("div",{className:"h-10 w-10 rounded-full bg-slate-100 flex items-center justify-center flex-shrink-0",children:(0,le.jsx)(XN.A,{className:"h-5 w-5 text-slate-700"})}),(0,le.jsxs)("div",{className:"flex-1",children:[(0,le.jsx)("h3",{className:"font-medium text-slate-900",children:"Backend Functions"}),(0,le.jsx)("p",{className:"text-sm text-slate-600",children:"Most integrations with external APIs require backend functions"})]}),(0,le.jsx)(tw,{checked:h.requires_backend_functions,onCheckedChange:e=>k("requires_backend_functions",e)})]})})})]}),h.requires_backend_functions&&(0,le.jsxs)("div",{className:"mb-8",children:[(0,le.jsxs)("div",{className:"flex items-center mb-2",children:[(0,le.jsx)("h2",{className:"text-xl font-semibold text-slate-900",children:"Required API Keys"}),(0,le.jsx)(sw,{children:"API keys that users will need to configure to use this integration."})]}),(0,le.jsx)("p",{className:"text-sm text-slate-600 mb-4",children:"Define the credentials needed to connect to external services and how users can obtain them."}),(0,le.jsxs)(Qn,{className:"border-slate-200 shadow-sm mb-4",children:[(0,le.jsxs)(Xn,{className:"pb-0",children:[(0,le.jsx)(el,{className:"text-base font-medium",children:"Add API Keys"}),(0,le.jsx)(tl,{children:"Specify the API keys users will need to configure to use your integration"})]}),(0,le.jsx)(sl,{className:"pt-4",children:(0,le.jsxs)("div",{className:"grid grid-cols-1 gap-4",children:[(0,le.jsxs)("div",{children:[(0,le.jsx)(go,{htmlFor:"newSecretName",className:"mb-1 block",children:"Secret Name"}),(0,le.jsx)(fn,{id:"newSecretName",placeholder:"E.g., OPENAI_API_KEY",value:j,onChange:e=>y(e.target.value)}),(0,le.jsx)("p",{className:"text-xs text-slate-500 mt-1",children:"This is the environment variable name used in code"})]}),(0,le.jsxs)("div",{children:[(0,le.jsx)(go,{htmlFor:"newSecretDescription",className:"mb-1 block",children:"Instructions for obtaining"}),(0,le.jsx)(fn,{id:"newSecretDescription",placeholder:"E.g., Get from platform.openai.com/api-keys",value:N,onChange:e=>w(e.target.value)}),(0,le.jsx)("p",{className:"text-xs text-slate-500 mt-1",children:"Help users understand where to find this key"})]})]})}),(0,le.jsx)(al,{className:"border-t pt-4 bg-slate-50",children:(0,le.jsxs)(Hn,{type:"button",onClick:()=>{if(j.trim()){const e={name:j.trim(),description:N.trim()};p(t=>(0,K.A)((0,K.A)({},t),{},{required_secrets:[...t.required_secrets,e]})),y(""),w("")}},className:"w-full bg-teal-600 hover:bg-teal-700",children:[(0,le.jsx)(QN.A,{className:"h-4 w-4 mr-2"})," Add API Key"]})})]}),h.required_secrets.length>0?(0,le.jsx)("div",{className:"space-y-3",children:h.required_secrets.map((e,t)=>(0,le.jsxs)("div",{className:"bg-white rounded-lg p-4 border flex justify-between items-start",children:[(0,le.jsxs)("div",{children:[(0,le.jsxs)("div",{className:"flex items-center",children:[(0,le.jsx)(vs.A,{className:"h-4 w-4 text-slate-600 mr-2"}),(0,le.jsx)("h4",{className:"font-medium text-slate-900",children:e.name})]}),(0,le.jsx)("p",{className:"text-sm text-slate-600 mt-1 ml-6",children:e.description||"Required for this integration"})]}),(0,le.jsx)(Hn,{variant:"ghost",size:"sm",onClick:()=>(e=>{p(t=>(0,K.A)((0,K.A)({},t),{},{required_secrets:t.required_secrets.filter((t,s)=>s!==e)}))})(t),className:"text-red-500 hover:text-red-700 hover:bg-red-50",children:(0,le.jsx)(Ip.A,{className:"h-4 w-4"})})]},t))}):(0,le.jsxs)("div",{className:"bg-slate-50 p-5 rounded-lg border text-center",children:[(0,le.jsx)(vs.A,{className:"h-10 w-10 text-slate-400 mx-auto mb-2"}),(0,le.jsx)("p",{className:"text-slate-600 mb-1",children:"No API keys added yet"}),(0,le.jsx)("p",{className:"text-sm text-slate-500",children:"Add keys if your integration requires external API access"})]})]}),(0,le.jsxs)("div",{className:"mb-8",children:[(0,le.jsxs)("div",{className:"flex items-center mb-2",children:[(0,le.jsx)("h2",{className:"text-xl font-semibold text-slate-900",children:"Integration Prompt"}),(0,le.jsx)(sw,{children:"The implementation guide for your integration."})]}),(0,le.jsx)("p",{className:"text-sm text-slate-600 mb-4",children:"Write detailed instructions on how to use this integration, including code examples and configuration guidance."}),(0,le.jsxs)("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-6",children:[(0,le.jsx)("div",{className:"lg:col-span-2",children:(0,le.jsxs)(Qn,{className:"h-full",children:[(0,le.jsxs)(Xn,{className:"pb-2",children:[(0,le.jsx)(el,{className:"text-base font-medium",children:"Implementation Guide"}),(0,le.jsx)(tl,{children:"Provide detailed instructions on how to use this integration"})]}),(0,le.jsxs)(sl,{children:[(0,le.jsx)(yp,{id:"prompt",name:"prompt",value:h.prompt,onChange:_,placeholder:"# Integration Name This integration allows you to... ## Example Code ```javascript\n// Code example\n``` ## Configuration Options - Option 1: Description\n- Option 2: Description ## Usage Tips ...",className:"font-mono min-h-[400px] bg-slate-50 border-slate-200"}),(0,le.jsxs)("div",{className:"flex justify-between items-center mt-2 text-xs",children:[(0,le.jsx)("div",{className:"text-slate-500",children:(0,le.jsx)("span",{children:"Supports Markdown formatting"})}),(0,le.jsx)("div",{children:(0,le.jsx)("span",{className:"font-medium ".concat(h.prompt.length<50?"text-red-500":"text-green-600"," flex items-center"),children:h.prompt.length<50?(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(Bt.A,{className:"h-3 w-3 mr-1"}),h.prompt.length,"/50 characters (minimum)"]}):(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(Ps.A,{className:"h-3 w-3 mr-1"}),h.prompt.length," characters"]})})})]})]})]})}),(0,le.jsx)("div",{className:"lg:col-span-1",children:(0,le.jsxs)(Qn,{className:"bg-slate-50 border border-slate-200 h-full",children:[(0,le.jsxs)(Xn,{className:"pb-2",children:[(0,le.jsxs)(el,{className:"text-base font-medium flex items-center text-slate-700",children:[(0,le.jsx)(uo.A,{className:"h-4 w-4 mr-2 text-teal-600"}),"Tips for writing effective prompts"]}),(0,le.jsx)(tl,{children:"Guidelines to help users implement your integration"})]}),(0,le.jsxs)(sl,{className:"space-y-4",children:[(0,le.jsxs)("div",{children:[(0,le.jsx)("h4",{className:"font-medium text-slate-800 mb-1",children:"Structure your guide clearly"}),(0,le.jsxs)("ul",{className:"space-y-2 text-sm text-slate-600 list-disc pl-5",children:[(0,le.jsx)("li",{children:"Start with an introduction explaining what the integration does"}),(0,le.jsx)("li",{children:"Include complete code examples with explanations"}),(0,le.jsx)("li",{children:"Provide configuration and setup instructions"})]})]}),h.requires_backend_functions&&(0,le.jsxs)("div",{children:[(0,le.jsx)("h4",{className:"font-medium text-slate-800 mb-1",children:"Backend Function Tips"}),(0,le.jsxs)("ul",{className:"space-y-2 text-sm text-slate-600 list-disc pl-5",children:[(0,le.jsxs)("li",{children:["Show how to implement with ",(0,le.jsx)("strong",{children:"Deno serve"})," (this is how backend functions run)"]}),(0,le.jsx)("li",{children:"Document the output schema for each function"}),(0,le.jsx)("li",{children:"Include examples of how to call these functions from frontend components"}),(0,le.jsx)("li",{children:"Provide error handling guidance"})]})]}),(0,le.jsxs)("div",{children:[(0,le.jsx)("h4",{className:"font-medium text-slate-800 mb-1",children:"Recommended sections"}),(0,le.jsxs)("ul",{className:"space-y-2 text-sm text-slate-600 list-disc pl-5",children:[(0,le.jsxs)("li",{children:[(0,le.jsx)("strong",{children:"Introduction:"})," What the integration does"]}),(0,le.jsxs)("li",{children:[(0,le.jsx)("strong",{children:"API Reference:"})," Available functions and parameters"]}),(0,le.jsxs)("li",{children:[(0,le.jsx)("strong",{children:"Example Usage:"})," Practical implementation examples"]}),(0,le.jsxs)("li",{children:[(0,le.jsx)("strong",{children:"Troubleshooting:"})," Common issues and solutions"]})]})]}),(0,le.jsxs)("div",{className:"bg-blue-50 p-3 rounded-md text-sm text-blue-700 border border-blue-100",children:[(0,le.jsx)("p",{className:"font-medium mb-1",children:"Pro Tip"}),(0,le.jsx)("p",{children:"The better your documentation, the more likely users will successfully implement your integration!"})]})]})]})})]})]}),(0,le.jsxs)("div",{className:"flex justify-between pt-4 border-t",children:[(0,le.jsxs)(Hn,{onClick:()=>f("metadata"),variant:"outline",children:[(0,le.jsx)(Cd.A,{className:"h-4 w-4 mr-2"}),"Back to Metadata"]}),(0,le.jsx)(Hn,{onClick:()=>C(),disabled:o,className:"bg-teal-600 hover:bg-teal-700",children:o?(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(Ne.A,{className:"h-4 w-4 mr-2 animate-spin"}),"Saving..."]}):(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(df.A,{className:"h-4 w-4 mr-2"}),"Save Integration"]})})]})]})})]})})]})};function nw(e){let{isHowToModalOpen:t,setIsHowToModalOpen:s}=e;return(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)("h1",{className:"text-5xl font-base44 font-medium mb-4 mt-6",children:"App Templates"}),(0,le.jsxs)(tc,{open:t,onOpenChange:s,children:[(0,le.jsxs)("p",{className:"text-lg font-base44 max-w-2xl mb-4",children:["Explore a curated collection of applications built by our community."," ",(0,le.jsx)(sc,{asChild:!0,children:(0,le.jsx)("button",{className:"text-orange-500 font-base44 hover:text-orange-600 text-lg font-medium hover:underline-offset-4 transition-all",children:"Learn more"})})]}),(0,le.jsxs)(lc,{className:"max-w-2xl",children:[(0,le.jsx)(rc,{children:(0,le.jsx)(oc,{className:"text-xl font-semibold text-slate-900",children:"How to Share Your App with the Community"})}),(0,le.jsxs)("div",{className:"space-y-6 pt-2",children:[(0,le.jsx)("p",{className:"text-slate-600 leading-relaxed",children:"Follow these simple steps:"}),(0,le.jsxs)("div",{className:"space-y-4",children:[(0,le.jsxs)("div",{className:"flex items-start gap-3 p-4 rounded-xl bg-slate-50 border border-slate-200",children:[(0,le.jsx)("div",{className:"flex-shrink-0 w-6 h-6 rounded-full bg-orange-500 text-white text-sm font-medium flex items-center justify-center mt-0.5",children:"1"}),(0,le.jsxs)("div",{className:"space-y-1",children:[(0,le.jsx)("p",{className:"font-medium text-slate-900",children:"Open your app's builder"}),(0,le.jsx)("p",{className:"text-sm text-slate-600",children:"Navigate to an app you created or have admin access to"})]})]}),(0,le.jsx)("div",{className:"flex items-center justify-center",children:(0,le.jsx)(kd.A,{className:"w-4 h-4 text-slate-400"})}),(0,le.jsxs)("div",{className:"flex items-start gap-3 p-4 rounded-xl bg-slate-50 border border-slate-200",children:[(0,le.jsx)("div",{className:"flex-shrink-0 w-6 h-6 rounded-full bg-orange-500 text-white text-sm font-medium flex items-center justify-center mt-0.5",children:"2"}),(0,le.jsxs)("div",{className:"space-y-1",children:[(0,le.jsx)("p",{className:"font-medium text-slate-900",children:"Go to catalog settings"}),(0,le.jsx)("p",{className:"text-sm text-slate-600",children:(0,le.jsx)("span",{className:"font-mono text-xs bg-white px-2 py-1 rounded border",children:"Workspace \u2192 Settings \u2192 App Templates \u2192 Manage Listing"})})]})]}),(0,le.jsx)("div",{className:"flex items-center justify-center",children:(0,le.jsx)(kd.A,{className:"w-4 h-4 text-slate-400"})}),(0,le.jsxs)("div",{className:"flex items-start gap-3 p-4 rounded-xl bg-slate-50 border border-slate-200",children:[(0,le.jsx)("div",{className:"flex-shrink-0 w-6 h-6 rounded-full bg-orange-500 text-white text-sm font-medium flex items-center justify-center mt-0.5",children:"3"}),(0,le.jsxs)("div",{className:"space-y-1",children:[(0,le.jsx)("p",{className:"font-medium text-slate-900",children:"Publish your listing"}),(0,le.jsx)("p",{className:"text-sm text-slate-600",children:"Add a description, screenshots, and configure your listing visibility"})]})]})]}),(0,le.jsx)("div",{className:"p-4 rounded-xl bg-orange-50 border border-orange-200",children:(0,le.jsxs)("p",{className:"text-sm text-orange-800",children:[(0,le.jsx)("strong",{children:"Tip:"})," Make sure your app is deployed and has an engaging description to attract more users!"]})})]})]})]})]})}function lw(e){if(!e)return"";const t=document.createElement("div");return t.innerHTML=e,t.textContent||t.innerText||""}const rw=function(){const{user:e}=oe(),[t,s]=(0,Y.useState)([]),[a,n]=(0,Y.useState)(!0),[l,r]=(0,Y.useState)(""),[i,o]=(0,Y.useState)("all"),[c,d]=(0,Y.useState)(zn),[m,u]=(0,Y.useState)(Un),[x,h]=(0,Y.useState)("en"),[p,g]=(0,Y.useState)(new Set),[f,v]=(0,Y.useState)(!1),[b,j]=(0,Y.useState)(!0),[y,N]=(0,Y.useState)(!1),[w,_]=(0,Y.useState)(0),[k]=(0,Y.useState)(20),[C,A]=(0,Y.useState)(0),[S,E]=(0,Y.useState)(null),[I,T]=(0,Y.useState)(!1);(0,Y.useEffect)(()=>{const e=new URLSearchParams(window.location.search).get("category");if(e){const t=Dn.find(t=>t.toLowerCase()===e.toLowerCase());t?o(t):"my-apps"===e.toLowerCase()&&o("my-apps")}},[]),(0,Y.useEffect)(()=>{const e=e=>{I&&("ArrowLeft"===e.key?M():"ArrowRight"===e.key&&D())};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[I,S]),(0,Y.useEffect)(()=>{s([]),A(0),j(!0),P(!0)},[l,i,c,m,x]);const P=(0,Y.useCallback)(async function(){let t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];try{t?n(!0):N(!0);const a=t?0:C;let r={skip:a,limit:k,sort_by:L(m),categories:"all"!==i&&"my-apps"!==i?[i]:void 0};"me"===c||"my-apps"===i?r.created_by=e.email:"not_me"===c&&(r.created_by={$ne:e.email}),l&&"en"===x?r.$and=[{$or:[{name:{$regex:l,$options:"i"}},{description:{$regex:l,$options:"i"}},{categories:{$regex:l,$options:"i"}},{tags:{$regex:l,$options:"i"}},{created_by:{$regex:l,$options:"i"}}]},{$or:[{language:"en"},{language:{$exists:!1}},{language:null}]}]:l?(r.$or=[{name:{$regex:l,$options:"i"}},{description:{$regex:l,$options:"i"}},{categories:{$regex:l,$options:"i"}},{tags:{$regex:l,$options:"i"}},{created_by:{$regex:l,$options:"i"}}],x&&"en"!==x&&(r.language=x)):x&&("en"===x?r.$or=[{language:"en"},{language:{$exists:!1}},{language:null}]:r.language=x),Object.keys(r).forEach(e=>{void 0===r[e]&&delete r[e]});const o=await $a.listCatalogItems(r),d=o.items||o,u=o.total||d.length;t?(s(d),_(u)):s(e=>[...e,...d]),A(a+d.length),j(0!==d.length);const h=new Set(d.filter(e=>e.did_current_user_upvote).map(e=>e.item.id));g(t?h:e=>new Set([...e,...h]))}catch(a){an({title:"Error",description:"Failed to load catalog items",variant:"destructive"})}finally{n(!1),N(!1)}},[C,k,i,l,c,m,x,e.email]),L=e=>{switch(e){case"newest":return"created_at_desc";case"oldest":return"created_at_asc";default:return"usage"}},O=(0,Y.useCallback)(()=>{!b||y||a||P(!1)},[b,y,a,P]),{targetRef:R}=RN({onLoadMore:O,hasMore:b,isLoading:y||a}),M=()=>{const e=t.findIndex(e=>e.item.id===S.item.id);e>0&&E(t[e-1])},D=()=>{const e=t.findIndex(e=>e.item.id===S.item.id);e0?"Showing ".concat(F," of ").concat(w," items"):"";return(0,le.jsxs)("div",{className:"px-12 max-w-[1600px] mx-auto",children:[(0,le.jsx)(nw,{}),(0,le.jsx)(Wn,{searchTerm:l,onSearchChange:e=>{r(e)},selectedCategory:i,onCategoryChange:e=>{o(e)},showAllCategories:f,setShowAllCategories:v,totalItems:w,displayedItems:F,showingText:B,isLoading:a,ownership:c,onOwnershipChange:e=>{d(e)},sortBy:m,onSortByChange:e=>{u(e)},selectedLanguage:x,onLanguageChange:e=>{h(e)}}),(0,le.jsx)(Nl,{isLoading:a,isLoadingMore:y,items:t,upvotedItems:p,onCardClick:e=>{E(e),T(!0)},onUpvote:async(e,t)=>{e.stopPropagation();try{await $a.upvoteItem(t),g(e=>new Set([...e,t])),s(e=>e.map(e=>e.item.id===t?(0,K.A)((0,K.A)({},e),{},{upvotes:e.upvotes+1,did_current_user_upvote:!0}):e)),S&&S.item.id===t&&E(e=>(0,K.A)((0,K.A)({},e),{},{upvotes:e.upvotes+1,did_current_user_upvote:!0})),an({title:"Success",description:"Upvoted successfully"})}catch(a){an({title:"Error",description:"Failed to upvote",variant:"destructive"})}},stripHtml:lw,hasMore:b,targetRef:R}),(0,le.jsx)(hn,{isOpen:I,onClose:()=>{T(!1),E(null)},selectedItem:S,filteredItems:t,onPrevious:M,onNext:D,upvotedItems:p,onUpvote:e=>{g(t=>new Set([...t,e])),s(t=>t.map(t=>t.item.id===e?(0,K.A)((0,K.A)({},t),{},{upvotes:t.upvotes+1,did_current_user_upvote:!0}):t))},onItemUpdate:e=>{E(e)}})]})};function iw(){const{user:e}=oe(),{appId:t}=(0,Z.g)(),s=(0,Z.Zp)(),[a,n]=(0,Y.useState)(!0),[l,r]=(0,Y.useState)(!1),[i,o]=(0,Y.useState)(null),[c,d]=(0,Y.useState)(null),[m,u]=(0,Y.useState)({}),[x,h]=(0,Y.useState)(!1),p=new URLSearchParams(window.location.search).get("clone_history"),g=(0,Y.useCallback)(()=>{r(!0),o(null),ve.remixApp(t,{with_chat_history:"true"===p,secret_values:m}).then(e=>{s("/apps/".concat(e.id,"/editor/preview"))}).catch(e=>{o(e.message||"An error occurred while cloning the app"),r(!1)})},[t,m,s]);(0,Y.useEffect)(()=>{n(!0),ve.remixAppRequirements(t).then(t=>{d(t);t&&(!t.app_secret_names||0===t.app_secret_names.length)&&!(t.requires_backend_functions&&("free"===e.subscription_tier||"starter"===e.subscription_tier))?g():t&&t.app_secret_names&&t.app_secret_names.length>0&&(!t.requires_backend_functions||"free"!==e.subscription_tier&&"starter"!==e.subscription_tier)&&h(!0),n(!1)}).catch(e=>{o(e.message||"An error occurred while fetching cloning requirements"),n(!1)})},[t,e.subscription_tier]);return a?(0,le.jsx)("div",{className:"fixed inset-0 flex items-center justify-center",children:(0,le.jsx)("div",{className:"flex flex-col items-center space-y-4",children:(0,le.jsx)(Ne.A,{className:"h-8 w-8 animate-spin"})})}):l?(0,le.jsx)("div",{className:"fixed inset-0 flex items-center justify-center",children:(0,le.jsxs)("div",{className:"flex flex-col items-center space-y-4",children:[(0,le.jsx)("div",{className:"w-12 h-12 border-4 border-gray-200 border-t-black rounded-full animate-spin"}),(0,le.jsxs)("p",{className:"text-gray-600",children:["Cloning ",(null==c?void 0:c.name)||"app","..."]})]})}):i?(0,le.jsx)("div",{className:"fixed inset-0 flex items-center justify-center",children:(0,le.jsxs)("div",{className:"flex flex-col items-center space-y-4 p-8 bg-white rounded-lg shadow-xl max-w-md mx-auto",children:[(0,le.jsx)(_e.A,{className:"h-12 w-12 text-red-500"}),(0,le.jsx)("div",{className:"text-red-600 text-lg font-medium",children:"Error"}),(0,le.jsx)("p",{className:"text-gray-600 text-center",children:i}),(0,le.jsx)(Yt,{onClick:()=>s(-1),variant:"outline",children:"Go Back"})]})}):c&&c.requires_backend_functions&&("free"===e.subscription_tier||"starter"===e.subscription_tier)?(0,le.jsx)("div",{className:"fixed inset-0 flex items-center justify-center",children:(0,le.jsxs)("div",{className:"flex flex-col items-center space-y-4 p-8 bg-white rounded-lg shadow-xl max-w-md mx-auto",children:[(0,le.jsx)(_e.A,{className:"h-12 w-12 text-red-500"}),(0,le.jsx)("div",{className:"text-red-600 text-lg font-medium",children:"Clone Not Allowed"}),(0,le.jsx)("p",{className:"text-gray-600 text-center",children:"This app requires backend functions. You need to be on the Builder tier or above to remix it."}),(0,le.jsx)(Yt,{onClick:()=>s(-1),variant:"outline",children:"Go Back"})]})}):(0,le.jsx)("div",{className:"container mx-auto p-4 pt-10 max-w-2xl",children:x?(0,le.jsxs)("div",{className:"mb-6 p-6 border rounded-lg bg-slate-50",children:[(0,le.jsxs)("h1",{className:"text-2xl font-semibold mb-6",children:["Clone ",(null==c?void 0:c.name)||"App"]}),(0,le.jsx)("h2",{className:"text-lg font-medium mb-4 text-slate-700",children:"Configure Secrets"}),(0,le.jsx)(Ks,{secretNames:c.app_secret_names.map(e=>({name:e})),value:m,onChange:e=>{u(e)}}),(0,le.jsx)(Yt,{onClick:g,disabled:l,className:"w-full mt-4",children:l?"Cloning ".concat((null==c?void 0:c.name)||"App","..."):"Clone ".concat((null==c?void 0:c.name)||"App")})]}):(0,le.jsx)("div",{className:"fixed inset-0 flex items-center justify-center",children:(0,le.jsxs)("div",{className:"flex flex-col items-center space-y-4",children:[(0,le.jsx)("div",{className:"w-12 h-12 border-4 border-gray-200 border-t-black rounded-full animate-spin"}),(0,le.jsx)("p",{className:"text-gray-600",children:"Preparing..."})]})})})}var ow=s(35219),cw=s(97104);function dw(){const e=(0,J.useSearchParams)()[0].get("appId"),{user:t}=oe();return{sessionContext:{app_id:e,user_id:null==t?void 0:t.id}}}const mw=e=>{let{className:t}=e;return(0,le.jsx)("svg",{className:t,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:(0,le.jsx)("path",{d:"M18.8943 4.34399C17.5183 3.71467 16.057 3.256 14.5317 3C14.3396 3.33067 14.1263 3.77866 13.977 4.13067C12.3546 3.89599 10.7439 3.89599 9.14391 4.13067C8.99457 3.77866 8.77056 3.33067 8.58922 3C7.05325 3.256 5.59191 3.71467 4.22552 4.34399C1.46286 8.41865 0.716188 12.3973 1.08952 16.3226C2.92418 17.6559 4.69486 18.4666 6.4346 19C6.86126 18.424 7.24527 17.8053 7.57594 17.1546C6.9466 16.92 6.34927 16.632 5.77327 16.2906C5.9226 16.184 6.07194 16.0667 6.21061 15.9493C9.68793 17.5387 13.4543 17.5387 16.889 15.9493C17.0383 16.0667 17.177 16.184 17.3263 16.2906C16.7503 16.632 16.153 16.92 15.5236 17.1546C15.8543 17.8053 16.2383 18.424 16.665 19C18.4036 18.4666 20.185 17.6559 22.01 16.3226C22.4687 11.7787 21.2836 7.83202 18.8943 4.34399ZM8.05593 13.9013C7.01058 13.9013 6.15725 12.952 6.15725 11.7893C6.15725 10.6267 6.98925 9.67731 8.05593 9.67731C9.11191 9.67731 9.97588 10.6267 9.95454 11.7893C9.95454 12.952 9.11191 13.9013 8.05593 13.9013ZM15.065 13.9013C14.0196 13.9013 13.1652 12.952 13.1652 11.7893C13.1652 10.6267 13.9983 9.67731 15.065 9.67731C16.121 9.67731 16.985 10.6267 16.9636 11.7893C16.9636 12.952 16.1317 13.9013 15.065 13.9013Z",stroke:"currentColor",strokeWidth:"1.5",strokeLinejoin:"round"})})},uw=e=>{let{icon:t,title:s,description:a,action:n,variant:l="default",external:r=!1,onHover:i}=e;return(0,le.jsxs)("div",{className:"group cursor-pointer relative overflow-hidden rounded-2xl transition-all duration-500 hover:scale-[1.02] hover:-translate-y-1",onClick:n,onMouseEnter:i,children:[(0,le.jsx)("div",{className:"absolute inset-0 transition-all duration-500 ".concat("primary"===l?"bg-gradient-to-br from-orange-500 to-orange-600 group-hover:from-orange-600 group-hover:to-orange-700":"secondary"===l?"bg-gradient-to-br from-teal-500 to-teal-600 group-hover:from-teal-600 group-hover:to-teal-700":"bg-gradient-to-br from-slate-700 to-slate-800 group-hover:from-slate-800 group-hover:to-slate-900")}),(0,le.jsxs)("div",{className:"relative z-10 p-8 text-white",children:[(0,le.jsxs)("div",{className:"flex items-start justify-between mb-6",children:[(0,le.jsx)("div",{className:"w-14 h-14 bg-white/20 backdrop-blur-sm rounded-xl flex items-center justify-center group-hover:scale-110 transition-transform duration-300",children:(0,le.jsx)(t,{className:"w-7 h-7"})}),r&&(0,le.jsx)(Tr.A,{className:"w-5 h-5 opacity-60 group-hover:opacity-100 transition-opacity"})]}),(0,le.jsxs)("div",{className:"space-y-3",children:[(0,le.jsx)("h3",{className:"text-xl font-bold leading-tight",children:s}),(0,le.jsx)("p",{className:"text-white/80 text-sm leading-relaxed",children:a})]}),(0,le.jsxs)("div",{className:"mt-6 inline-flex items-center text-sm font-semibold group-hover:translate-x-1 transition-transform duration-300",children:[(0,le.jsx)("span",{children:"Get Started"}),(0,le.jsx)(ha.A,{className:"w-4 h-4 ml-2"})]})]})]})},xw=e=>{let{icon:t,title:s,description:a,action:n,count:l}=e;return(0,le.jsx)("div",{className:"group cursor-pointer p-6 bg-white rounded-xl border border-slate-200 hover:border-slate-300 hover:shadow-lg transition-all duration-300",onClick:n,children:(0,le.jsxs)("div",{className:"flex items-start space-x-4",children:[(0,le.jsx)("div",{className:"w-12 h-12 bg-slate-100 text-slate-600 rounded-lg flex items-center justify-center group-hover:bg-orange-100 group-hover:text-orange-600 transition-colors",children:(0,le.jsx)(t,{className:"w-6 h-6"})}),(0,le.jsxs)("div",{className:"flex-1",children:[(0,le.jsxs)("div",{className:"flex items-center justify-between mb-1",children:[(0,le.jsx)("h4",{className:"font-semibold text-slate-900",children:s}),void 0!==l&&(0,le.jsx)("span",{className:"text-sm font-medium text-slate-500",children:l})]}),(0,le.jsx)("p",{className:"text-sm text-slate-600",children:a})]}),(0,le.jsx)(ha.A,{className:"w-5 h-5 text-slate-400 group-hover:text-slate-600 group-hover:translate-x-1 transition-all"})]})})};function hw(e){let{appId:t}=e;const[s]=(0,J.useSearchParams)(),a=(0,Z.Zp)(),[n,l]=(0,Y.useState)(t),r=function(){const e=dw();return{pageView:()=>{ot.track("support_main_page_view",e.sessionContext,{},{useBeacon:!0}).catch()},openTicketHover:t=>{let{type:s,ticketId:a}=t;ot.track("support_main_open_ticket_hover",e.sessionContext,{type:s,ticket_id:a},{useBeacon:!0}).catch()},openTicketClick:t=>{let{type:s,ticketId:a}=t;ot.track("support_main_open_ticket_click",e.sessionContext,{type:s,ticket_id:a},{useBeacon:!0}).catch()}}}();(0,Y.useEffect)(()=>{r.pageView()},[]),(0,Y.useEffect)(()=>{const e=s.get("appId");l(e||t)},[s,t]);return(0,le.jsx)(le.Fragment,{children:(0,le.jsxs)("div",{className:"w-full max-w-7xl mx-auto px-6 py-12",children:[(0,le.jsx)("div",{className:"text-center mb-16",children:(0,le.jsxs)("div",{className:"space-y-4",children:[(0,le.jsx)("h1",{className:"text-5xl font-bold text-slate-900 tracking-tight",children:"Help & Support"}),(0,le.jsx)("div",{className:"w-24 h-1 bg-gradient-to-r from-orange-500 to-teal-500 mx-auto rounded-full"}),(0,le.jsx)("p",{className:"text-xl text-slate-600 max-w-2xl mx-auto leading-relaxed",children:"Get the help you need to build amazing applications with BASE44"})]})}),n&&(0,le.jsx)("div",{className:"mb-12 p-6 bg-slate-50 border border-slate-200 rounded-xl",children:(0,le.jsxs)("div",{className:"flex items-center space-x-3",children:[(0,le.jsx)("div",{className:"w-10 h-10 bg-slate-100 text-slate-600 rounded-lg flex items-center justify-center",children:(0,le.jsx)(ow.A,{className:"w-5 h-5"})}),(0,le.jsxs)("div",{children:[(0,le.jsx)("h3",{className:"font-semibold text-slate-900",children:"App-Specific Support"}),(0,le.jsxs)("p",{className:"text-sm text-slate-600",children:["Support requests will be associated with app: ",(0,le.jsx)("span",{className:"font-mono bg-slate-100 px-2 py-1 rounded text-slate-800",children:n})]})]})]})}),(0,le.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-8 mb-16",children:[(0,le.jsx)(uw,{icon:Su.A,title:"Documentation",description:"Explore comprehensive guides, tutorials, FAQs,and best practices for building with Base44.",action:()=>{window.open("https://docs.base44.com","_blank")},variant:"primary",external:!0}),(0,le.jsx)(uw,{icon:mw,title:"Discord Community",description:"Connect with fellow builders and get instant help from our active community.",action:()=>{window.open("https://discord.com/invite/ThpYPZpVts","_blank")},variant:"secondary",external:!0}),(0,le.jsx)(uw,{icon:cw.A,title:"Open Support Ticket",description:"Submit a detailed support ticket and get personalized assistance.",action:()=>{r.openTicketClick({});const e=new URLSearchParams({openNew:"true"});n&&e.set("appId",n),a("/support/conversations?".concat(e.toString()))},variant:"default",onHover:()=>r.openTicketHover({})})]}),(0,le.jsxs)("div",{className:"bg-slate-50 rounded-2xl p-8",children:[(0,le.jsxs)("div",{className:"mb-6",children:[(0,le.jsx)("h2",{className:"text-2xl font-bold text-slate-900 mb-2",children:"Quick Actions"}),(0,le.jsx)("p",{className:"text-slate-600",children:"Manage your support experience"})]}),(0,le.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[(0,le.jsx)(xw,{icon:Ir.A,title:"My Support Tickets",description:"View and manage your existing support tickets",action:()=>{const e=new URLSearchParams;n&&e.set("appId",n),a("/support/conversations".concat(e.toString()?"?".concat(e.toString()):""))}}),(0,le.jsx)(xw,{icon:Xl.A,title:"Community Forum",description:"Our brand-new reddit community",action:()=>{window.open("https://www.reddit.com/r/Base44","_blank")}})]})]})]})})}var pw=s(83655);class gw extends Q.y{getBaseURL(){return"/support/conversations"}async addMessage(e,t){return await this.axios.post("/".concat(e,"/messages"),t)}async updateConversationNotifications(e,t){return await this.axios.put("/".concat(e,"/notifications"),t)}async closeTicket(e){return await this.axios.patch("/".concat(e,"/close"))}}const fw=new gw;class vw extends Q.H{getBaseURL(){return"/support/admin"}async getTickets(e){const t=Object.fromEntries(Object.entries(e||{}).filter(e=>{let[t,s]=e;return null!==s}));return await this.axios.get("",{params:t})}async getTicketDetail(e){return await this.axios.get("/".concat(e))}async updateTicketStatus(e,t){return await this.axios.patch("/".concat(e,"/status"),{status:t})}async polishResponse(e,t){return await this.axios.post("/".concat(e,"/messages/polish"),{text:t})}async changeTicketStatus(e,t){return await this.axios.patch("/".concat(e,"/change_ticket_status"),{status:t})}async assignTicket(e,t){return await this.axios.patch("/".concat(e,"/assign"),{user_email:t})}async escalateTicket(e){return await this.axios.patch("/".concat(e,"/escalate"))}async unescalateTicket(e){return await this.axios.patch("/".concat(e,"/unescalate"))}async updateInternalCategories(e,t){return await this.axios.patch("/".concat(e,"/internal_categories"),{internal_categories:t})}async updateInternalNotes(e,t){return await this.axios.patch("/".concat(e,"/internal_notes"),{internal_notes:t})}async updateTicketCategory(e,t){return await this.axios.patch("/".concat(e,"/category"),{category:t})}async resolveMany(e){return await this.axios.patch("/resolve-many",{ticket_ids:e})}async deleteMessage(e,t){return await this.axios.delete("/".concat(e,"/messages"),{data:{message_id:t}})}}const bw=new vw;class jw extends Q.H{getBaseURL(){return"/docs"}async getArticles(){return await this.axios.get("/articles")}async createArticle(e){return await this.axios.post("/articles",e)}async updateArticle(e,t){return await this.axios.put("/articles/".concat(e),t)}async deleteArticle(e){return await this.axios.delete("/articles/".concat(e))}async getAgentProperties(){return await this.axios.get("/agent")}async updateAgentProperties(e){return await this.axios.put("/agent",e)}}const yw=new jw;class Nw extends Q.H{getBaseURL(){return"/support/analytics"}async exportTicketsCSV(e,t){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;const a={start_date:e,end_date:t};s&&(a.category=s);const n=await this.axios.get("/export-csv",{params:a,responseType:"blob"}),l=window.URL.createObjectURL(new Blob([n])),r=document.createElement("a");return r.href=l,r.setAttribute("download","support_tickets_".concat(e.split("T")[0],"_").concat(t.split("T")[0],".csv")),document.body.appendChild(r),r.click(),r.remove(),window.URL.revokeObjectURL(l),n}async runTrendAnalysis(e,t){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;const a={start_date:e,end_date:t};return s&&(a.category=s),await this.axios.post("/trend-analysis",a)}async getOperationalMetrics(e,t){const s={start_date:e,end_date:t};return await this.axios.get("/operational-metrics",{params:s})}}const ww=new Nw;class _w extends Q.H{getBaseURL(){return"/support/bot"}async requestAnswer(e,t,s){let a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:[];return await this.axios.post("/request",{title:e,content:t,category:s,file_urls:a})}async logAnswer(e,t,s){let a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null;return await this.axios.post("/log_answer",{support_ticket_id:e,answer:t,is_useful:s,ticket_body:a})}}const kw=new _w;class Cw extends Q.y{getBaseURL(){return"/support/agents"}updateRecord(e,t){return this.axios.post("/realtime/".concat(e,"/").concat(t))}}const Aw=new Cw;var Sw=s(59027),Ew=s(62702);const Iw=e=>{let{imageUrl:t,isOpen:s,onClose:a}=e;return s?(0,le.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[(0,le.jsx)("div",{className:"absolute inset-0 bg-black/80 backdrop-blur-sm",onClick:a}),(0,le.jsxs)("div",{className:"relative z-10 max-w-7xl max-h-[90vh] mx-4",children:[(0,le.jsx)("button",{onClick:a,className:"absolute -top-12 right-0 w-10 h-10 bg-white/10 hover:bg-white/20 backdrop-blur-sm rounded-full flex items-center justify-center text-white transition-all duration-200 hover:scale-110",children:(0,le.jsx)(Bt.A,{size:20})}),(0,le.jsx)("img",{src:t,alt:"Full size image",className:"max-w-full max-h-[90vh] object-contain rounded-lg shadow-2xl"})]})]}):null},Tw=e=>{var t,s,a;let{message:n,onImageClick:l,isAdmin:r=!1,conversationId:i,onMessageDeleted:o}=e;const c="user"===n.role,d=null===(t=n.additional_message_params)||void 0===t?void 0:t.is_admin_message,m=null===(s=n.metadata)||void 0===s?void 0:s.created_by_full_name,[u,x]=(0,Y.useState)(!1),[h,p]=(0,Y.useState)(!1);return(0,le.jsx)("div",{className:"flex ".concat(c?"justify-end":"justify-start"," mb-4"),onMouseEnter:()=>p(!0),onMouseLeave:()=>p(!1),children:(0,le.jsxs)("div",{className:"flex max-w-[80%] ".concat(c?"flex-row-reverse":"flex-row"," items-start space-x-3 relative"),children:[(0,le.jsx)("div",{className:"flex-shrink-0 w-8 h-8 rounded-full flex items-center justify-center ".concat(c?"bg-slate-200 text-slate-600 ml-3":d?"bg-slate-700 text-white mr-3":"bg-teal-100 text-teal-600 mr-3"),children:c?(0,le.jsx)(nv.A,{size:16}):d?(0,le.jsx)(lv.A,{size:16}):(0,le.jsx)(Cm.A,{size:16})}),(0,le.jsxs)("div",{className:"flex flex-col ".concat(c?"items-end":"items-start"),children:[d&&m&&(0,le.jsxs)("div",{className:"mb-2 flex items-center space-x-2",children:[(0,le.jsx)("div",{className:"text-xs font-medium text-slate-700",children:m.split(" ")[0]}),(0,le.jsx)("div",{className:"w-1 h-1 bg-slate-300 rounded-full"}),(0,le.jsx)("div",{className:"text-xs text-slate-500",children:"Support Team"})]}),(0,le.jsxs)("div",{className:"rounded-2xl px-4 py-3 max-w-full ".concat(c?"bg-slate-700 text-white":"bg-white text-slate-900 border border-slate-200 shadow-sm"),children:[n.file_urls&&n.file_urls.length>0&&(0,le.jsx)("div",{className:"mb-3 flex flex-wrap gap-3",children:n.file_urls.map((e,t)=>(0,le.jsx)("div",{className:"relative",children:e.match(/\.(jpg|jpeg|png|gif|webp)$/i)?(0,le.jsxs)("div",{className:"relative group cursor-pointer",onClick:()=>l(e),children:[(0,le.jsx)("img",{src:e,alt:"Attached content",className:"max-w-[250px] max-h-[250px] rounded-lg border border-slate-200 shadow-sm object-cover transition-all duration-200 group-hover:shadow-lg group-hover:scale-[1.02]"}),(0,le.jsx)("div",{className:"absolute inset-0 bg-black/0 group-hover:bg-black/20 rounded-lg transition-all duration-200 flex items-center justify-center",children:(0,le.jsx)("div",{className:"bg-white/90 backdrop-blur-sm rounded-full p-2 opacity-0 group-hover:opacity-100 transition-all duration-200 transform scale-75 group-hover:scale-100",children:(0,le.jsx)(Ew.A,{size:16,className:"text-slate-700"})})})]}):(0,le.jsxs)("div",{className:"flex items-center gap-2 p-2 rounded-lg border ".concat(c?"bg-slate-600 border-slate-500 text-slate-200":"bg-slate-50 border-slate-200 text-slate-700"),children:[(0,le.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"flex-shrink-0",children:[(0,le.jsx)("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),(0,le.jsx)("polyline",{points:"14 2 14 8 20 8"})]}),(0,le.jsx)("a",{href:e,target:"_blank",rel:"noopener noreferrer",className:"text-sm hover:underline ".concat(c?"text-slate-200":"text-blue-600"),children:"Attached file"})]})},t))}),(0,le.jsx)("div",{className:"text-sm leading-relaxed prose prose-sm max-w-[550px]",children:(0,le.jsx)(mr.oz,{components:{p:e=>{let{children:t}=e;return(0,le.jsx)("p",{className:"mb-2 last:mb-0",children:t})},ul:e=>{let{children:t}=e;return(0,le.jsx)("ul",{className:"list-disc list-inside mb-2 last:mb-0",children:t})},ol:e=>{let{children:t}=e;return(0,le.jsx)("ol",{className:"list-decimal list-inside mb-2 last:mb-0",children:t})},li:e=>{let{children:t}=e;return(0,le.jsx)("li",{className:"mb-1",children:t})},code:e=>{let{children:t,inline:s}=e;return s?(0,le.jsx)("code",{className:"px-1 py-0.5 rounded text-xs font-mono ".concat(c?"bg-slate-600 text-slate-200":"bg-slate-100 text-slate-800"),children:t}):(0,le.jsx)("pre",{className:"p-2 rounded text-xs font-mono overflow-x-auto ".concat(c?"bg-slate-600 text-slate-200":"bg-slate-100 text-slate-800"),children:(0,le.jsx)("code",{children:t})})},blockquote:e=>{let{children:t}=e;return(0,le.jsx)("blockquote",{className:"border-l-4 pl-3 italic ".concat(c?"border-slate-400":"border-slate-300"),children:t})},strong:e=>{let{children:t}=e;return(0,le.jsx)("strong",{className:"font-semibold",children:t})},em:e=>{let{children:t}=e;return(0,le.jsx)("em",{className:"italic",children:t})},h1:e=>{let{children:t}=e;return(0,le.jsx)("h1",{className:"text-lg font-bold mb-2",children:t})},h2:e=>{let{children:t}=e;return(0,le.jsx)("h2",{className:"text-base font-bold mb-2",children:t})},h3:e=>{let{children:t}=e;return(0,le.jsx)("h3",{className:"text-sm font-bold mb-1",children:t})}},children:n.content})})]}),(0,le.jsxs)("div",{className:"flex items-center gap-2 mt-1 ".concat(c?"justify-end":"justify-start"),children:[(null===(a=n.metadata)||void 0===a?void 0:a.created_date)&&(0,le.jsx)("div",{className:"text-xs text-slate-500",children:(g=n.metadata.created_date,ra().utc(g).fromNow())}),r&&!c&&"assistant"===n.role&&h&&(0,le.jsx)("button",{onClick:async()=>{if(!n.id||!i)return;if(window.confirm("Are you sure you want to delete this message?"))try{x(!0),await bw.deleteMessage(i,n.id),o&&o()}catch(e){alert("Failed to delete message. Please try again.")}finally{x(!1)}},disabled:u,className:"ml-2 p-1 rounded-full transition-all duration-200 ".concat(u?"bg-red-100 text-red-400 cursor-not-allowed":"hover:bg-red-100 text-slate-400 hover:text-red-600"),title:"Delete message",children:u?(0,le.jsx)("div",{className:"animate-spin rounded-full h-3 w-3 border-b-2 border-red-400"}):(0,le.jsx)(Ip.A,{size:14})})]})]})]})});var g},Pw=()=>(0,le.jsx)("div",{className:"flex justify-start mb-4",children:(0,le.jsxs)("div",{className:"flex items-start space-x-3",children:[(0,le.jsx)("div",{className:"flex-shrink-0 w-8 h-8 rounded-full flex items-center justify-center bg-teal-100 text-teal-600 mr-3",children:(0,le.jsx)(Cm.A,{size:16})}),(0,le.jsx)("div",{className:"bg-white text-slate-900 border border-slate-200 shadow-sm rounded-2xl px-4 py-3",children:(0,le.jsxs)("div",{className:"flex space-x-1",children:[(0,le.jsx)("div",{className:"w-2 h-2 bg-slate-400 rounded-full animate-bounce"}),(0,le.jsx)("div",{className:"w-2 h-2 bg-slate-400 rounded-full animate-bounce",style:{animationDelay:"0.1s"}}),(0,le.jsx)("div",{className:"w-2 h-2 bg-slate-400 rounded-full animate-bounce",style:{animationDelay:"0.2s"}})]})})]})});function Lw(e){let{messages:t,isTyping:s,isAdmin:a=!1,conversationId:n,onMessageDeleted:l}=e;const r=(0,Y.useRef)(null),[i,o]=(0,Y.useState)(null);(0,Y.useEffect)(()=>{var e;null===(e=r.current)||void 0===e||e.scrollIntoView({behavior:"smooth"})},[t,s]);const c=e=>{o(e)};return(0,le.jsxs)("div",{className:"h-full overflow-y-auto px-4 py-4",children:[0===t.length?(0,le.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,le.jsxs)("div",{className:"text-center",children:[(0,le.jsx)("div",{className:"w-16 h-16 bg-slate-100 text-slate-400 rounded-full flex items-center justify-center mx-auto mb-4",children:(0,le.jsx)(Cm.A,{size:24})}),(0,le.jsx)("h3",{className:"text-lg font-medium text-slate-900 mb-2",children:"Start the conversation"}),(0,le.jsx)("p",{className:"text-slate-600",children:"Send a message to begin your support conversation"})]})}):(0,le.jsxs)("div",{className:"space-y-4",children:[t.map((e,t)=>(0,le.jsx)(Tw,{message:e,onImageClick:c,isAdmin:a,conversationId:n,onMessageDeleted:l},e.id||t)),s&&(0,le.jsx)(Pw,{}),(0,le.jsx)("div",{ref:r})]}),i&&(0,le.jsx)(Iw,{imageUrl:i,isOpen:!!i,onClose:()=>o(null)})]})}const Ow="support_templates",Rw=()=>{try{const e=localStorage.getItem(Ow);return e?JSON.parse(e):[]}catch(e){return[]}},Mw=e=>{let{onTemplateSelect:t,className:s=""}=e;const[a,n]=(0,Y.useState)([]),[l,r]=(0,Y.useState)(!1),[i,o]=(0,Y.useState)(!0);if((0,Y.useEffect)(()=>{n(Rw());const e=e=>{e.key===Ow&&n(Rw())};window.addEventListener("storage",e);const t=()=>{n(Rw())};return window.addEventListener("templatesUpdated",t),()=>{window.removeEventListener("storage",e),window.removeEventListener("templatesUpdated",t)}},[]),0===a.length||!i)return null;const c=["bg-blue-100 text-blue-800 border-blue-200 hover:bg-blue-200","bg-green-100 text-green-800 border-green-200 hover:bg-green-200","bg-purple-100 text-purple-800 border-purple-200 hover:bg-purple-200","bg-orange-100 text-orange-800 border-orange-200 hover:bg-orange-200","bg-teal-100 text-teal-800 border-teal-200 hover:bg-teal-200","bg-pink-100 text-pink-800 border-pink-200 hover:bg-pink-200","bg-indigo-100 text-indigo-800 border-indigo-200 hover:bg-indigo-200","bg-yellow-100 text-yellow-800 border-yellow-200 hover:bg-yellow-200","bg-red-100 text-red-800 border-red-200 hover:bg-red-200","bg-cyan-100 text-cyan-800 border-cyan-200 hover:bg-cyan-200"],d=a.length>10,m=l?a:a.slice(0,10);return(0,le.jsxs)("div",{className:"space-y-2 ".concat(s),children:[(0,le.jsxs)("div",{className:"flex items-center justify-between mb-1",children:[(0,le.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,le.jsx)(hr.A,{className:"w-3 h-3 text-slate-500"}),(0,le.jsx)("span",{className:"text-xs font-medium text-slate-700",children:"Quick Templates"}),(0,le.jsxs)("span",{className:"text-xs text-slate-500",children:["(",a.length,")"]})]}),(0,le.jsx)(Yt,{variant:"ghost",size:"sm",onClick:()=>o(!1),className:"h-5 w-5 p-0 text-slate-400 hover:text-slate-600",children:(0,le.jsx)(Bt.A,{className:"w-3 h-3"})})]}),(0,le.jsxs)("div",{className:"flex flex-wrap gap-2",children:[m.map((e,s)=>{const a=c[s%c.length];return(0,le.jsx)("button",{onClick:()=>t(e.content),className:"\n px-2 py-1 rounded-md border text-xs font-medium \n transition-all duration-200 hover:shadow-sm\n max-w-32 truncate\n ".concat(a,"\n "),title:"".concat(e.name,"\n\nPreview: ").concat(e.content.substring(0,100),"..."),children:e.name},e.id)}),d&&(0,le.jsxs)("button",{onClick:()=>r(!l),className:"px-2 py-1 rounded-md border border-slate-300 bg-slate-50 text-slate-600 hover:bg-slate-100 text-xs font-medium transition-all duration-200 flex items-center space-x-1",children:[(0,le.jsx)(Tl.A,{className:"w-3 h-3"}),(0,le.jsx)("span",{children:l?"Less":"+".concat(a.length-10)}),l?(0,le.jsx)(Ts.A,{className:"w-3 h-3"}):(0,le.jsx)(Is.A,{className:"w-3 h-3"})]})]})]})};function Dw(e){var t;let{conversationId:s,isAdmin:a=!1,onMessageSent:n}=e;const{user:l}=oe(),[r,i]=(0,Y.useState)(null),[o,c]=(0,Y.useState)(!1),[d,m]=(0,Y.useState)(null),[u,x]=(0,Y.useState)(!1),[h,p]=(0,Y.useState)(!1),[g,f]=(0,Y.useState)(""),[v,b]=(0,Y.useState)(!1),[j,y]=(0,Y.useState)(""),[N,w]=(0,Y.useState)([]),[_,k]=(0,Y.useState)(!1),[C,A]=(0,Y.useState)(!1),[S,E]=(0,Y.useState)(!1),[I,T]=(0,Y.useState)(!1),P=a?null:500,L=s?"support-draft-".concat(s):"support-draft-temp";(0,Y.useEffect)(()=>{if(s&&O(),a){const e=localStorage.getItem(L);y(e||"")}},[s,L,a]),(0,Y.useEffect)(()=>{a&&j&&localStorage.setItem(L,j)},[j,a,L]),(0,Y.useEffect)(()=>{a&&null!=r&&r.draft&&!h&&(p(!0),f(r.draft),b(!1))},[null==r?void 0:r.draft,a]),(0,Y.useEffect)(()=>{void 0!==(null==r?void 0:r.notify_via_email_on_admin_response)&&A(r.notify_via_email_on_admin_response)},[null==r?void 0:r.notify_via_email_on_admin_response]),(0,Y.useEffect)(()=>{if(!a)return;const e=e=>{(navigator.platform.toUpperCase().indexOf("MAC")>=0?e.metaKey&&"k"===e.key:e.ctrlKey&&"k"===e.key)&&(e.preventDefault(),j.trim()&&!_&&R())};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[a,j,_]);const O=async()=>{try{c(!0),m(null);return await fw.fetchAndSubscribe(s,e=>{i(e),c(!1)})}catch(e){m("Failed to load conversation. Please try again."),c(!1)}},R=async()=>{if(j.trim())try{k(!0);const e=await bw.polishResponse(s,j);y(e)}catch(d){}finally{k(!1)}};if(o)return(0,le.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,le.jsxs)("div",{className:"text-center",children:[(0,le.jsx)("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-slate-400 mx-auto mb-4"}),(0,le.jsx)("p",{className:"text-slate-600",children:"Loading conversation..."})]})});if(d)return(0,le.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,le.jsxs)("div",{className:"text-center",children:[(0,le.jsx)("div",{className:"w-16 h-16 bg-red-100 text-red-500 rounded-full flex items-center justify-center mx-auto mb-4",children:(0,le.jsx)(Ir.A,{className:"w-8 h-8"})}),(0,le.jsx)("h3",{className:"text-lg font-medium text-slate-900 mb-2",children:"Error Loading Conversation"}),(0,le.jsx)("p",{className:"text-slate-600 mb-4",children:d}),(0,le.jsx)(Yt,{onClick:O,variant:"outline",size:"sm",children:"Try Again"})]})});if(!r)return(0,le.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,le.jsxs)("div",{className:"text-center",children:[(0,le.jsx)("div",{className:"w-16 h-16 bg-slate-100 text-slate-400 rounded-full flex items-center justify-center mx-auto mb-4",children:(0,le.jsx)(Ir.A,{className:"w-8 h-8"})}),(0,le.jsx)("h3",{className:"text-lg font-medium text-slate-900 mb-2",children:"No Conversation Found"}),(0,le.jsx)("p",{className:"text-slate-600",children:"This conversation doesn't exist or you don't have access to it."})]})});const M="premium"==(((null==l?void 0:l.subscription_tier)||"free").toLowerCase().includes("elite")?"premium":"standard")?{tier:"Premium Support",message:"Priority support with faster response times",color:"text-slate-700 bg-slate-100 border-slate-200"}:{tier:"Standard Support",message:"Responses on standard support could take up to 48 hours, typically less",color:"text-slate-600 bg-slate-50 border-slate-200"},D="pending_admin_response"===(null==r?void 0:r.status),F=a?(0,le.jsx)(Yt,{variant:"ghost",size:"sm",onClick:R,disabled:!j.trim()||_,className:"text-slate-600 hover:text-slate-900 hover:bg-slate-100",title:"Improve Grammar",children:_?(0,le.jsx)("div",{className:"animate-spin rounded-full h-4 w-4 border-b-2 border-slate-400"}):(0,le.jsx)(nj.A,{className:"w-4 h-4"})}):null;return(0,le.jsxs)("div",{className:"flex flex-col h-full max-h-full overflow-hidden",children:[!a&&r&&(0,le.jsx)("div",{className:"flex-shrink-0 border-b border-slate-200 px-4 py-3 bg-slate-50",children:(0,le.jsxs)("div",{className:"flex items-center justify-between",children:[(0,le.jsxs)("div",{className:"flex items-center space-x-3",children:[(0,le.jsx)("div",{className:"w-6 h-6 bg-orange-100 text-orange-600 rounded-full flex items-center justify-center text-sm",children:"\u{1f4b3}"}),(0,le.jsxs)("div",{children:[(0,le.jsx)("h3",{className:"text-sm font-medium text-slate-900 line-clamp-1",children:r.title||"Support Ticket"}),(0,le.jsx)("p",{className:"text-xs text-slate-500 capitalize",children:(null===(t=r.category)||void 0===t?void 0:t.replace(/_/g," "))||"General"})]})]}),"closed"!==r.status&&"resolved"!==r.ticket_status&&(0,le.jsx)(Yt,{variant:"outline",size:"sm",onClick:async()=>{if(window.confirm("Are you sure you want to close this ticket? This will mark it as resolved."))try{T(!0),await fw.closeTicket(s);const e=window.location.pathname;e.includes("/support")&&!e.includes("/support/conversations/")?window.location.reload():(await O(),n&&n({conversationId:s,action:"ticket_closed",role:a?"admin":"user",conversation:r}))}catch(d){alert("Failed to close ticket. Please try again.")}finally{T(!1)}},disabled:I,className:"text-teal-600 hover:text-teal-700 hover:bg-teal-50 border-teal-300 h-7 px-3 text-xs",children:I?(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)("div",{className:"animate-spin rounded-full h-3 w-3 border-b-2 border-teal-600 mr-1"}),"Closing..."]}):(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(pr.A,{className:"w-3 h-3 mr-1"}),"Close Ticket"]})})]})}),(0,le.jsx)("div",{className:"flex-1 min-h-0 overflow-hidden",children:(0,le.jsx)(Lw,{messages:r.messages||[],isTyping:r.is_bot_writing,isAdmin:a,conversationId:s,onMessageDeleted:async()=>{await O()}})}),(0,le.jsx)("div",{className:"flex-shrink-0",children:a&&h&&g?(0,le.jsx)("div",{className:"px-4 py-2 border-t border-slate-200 bg-teal-50",children:(0,le.jsx)(is,{className:"border-teal-200 bg-white",children:(0,le.jsxs)(ms,{className:"p-3",children:[(0,le.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,le.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,le.jsx)(ir.A,{className:"w-4 h-4 text-teal-600"}),(0,le.jsx)("span",{className:"text-sm font-medium text-teal-800",children:"AI Suggested Response"})]}),(0,le.jsxs)("div",{className:"flex items-center space-x-1",children:[(0,le.jsx)(Yt,{variant:"ghost",size:"sm",onClick:()=>{b(!v)},className:"h-6 px-2 text-xs text-teal-700 hover:bg-teal-100",children:v?(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(Ts.A,{className:"w-3 h-3 mr-1"}),"Collapse"]}):(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(Is.A,{className:"w-3 h-3 mr-1"}),"View All"]})}),(0,le.jsx)(Yt,{variant:"ghost",size:"sm",onClick:()=>{p(!1),f(""),b(!1)},className:"h-6 w-6 p-0 text-slate-400 hover:text-slate-600",children:(0,le.jsx)(Bt.A,{className:"w-3 h-3"})})]})]}),(0,le.jsxs)("div",{className:"space-y-3",children:[(0,le.jsxs)("div",{className:"text-sm text-slate-700 bg-slate-50 p-3 rounded border transition-all duration-200 relative ".concat(v?"max-h-none":"max-h-20 overflow-hidden"),children:[(0,le.jsx)("pre",{className:"whitespace-pre-wrap font-sans text-xs leading-relaxed",children:g}),!v&&g.length>150&&(0,le.jsx)("div",{className:"absolute bottom-0 left-0 right-0 h-8 bg-gradient-to-t from-slate-50 to-transparent pointer-events-none"})]}),(0,le.jsx)("div",{className:"flex items-center",children:(0,le.jsxs)(Yt,{size:"sm",onClick:async()=>{y(g),p(!1),f(""),b(!1)},className:"bg-teal-600 hover:bg-teal-700 h-7 px-3 text-xs",children:[(0,le.jsx)(Sw.A,{className:"w-3 h-3 mr-1"}),"Use"]})})]})]})})}):!a&&(0,le.jsx)("div",{className:"px-4 py-3 border-t border-slate-200 bg-slate-50",children:(0,le.jsxs)("div",{className:"p-3 rounded-lg border ".concat(M.color),children:[(0,le.jsxs)("div",{className:"flex items-center space-x-2 mb-2",children:[(0,le.jsx)("div",{className:"w-2 h-2 rounded-full bg-current"}),(0,le.jsx)("span",{className:"text-sm font-medium",children:M.tier})]}),(0,le.jsx)("p",{className:"text-xs opacity-80",children:M.message}),D&&(0,le.jsx)("div",{className:"flex items-start space-x-2 mt-2 pt-2 border-t border-current/20",children:(0,le.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,le.jsx)(dm,{id:"email-notifications",checked:C,onCheckedChange:async e=>{try{E(!0),await fw.updateConversationNotifications(s,{notify_via_email_on_admin_response:e}),A(e)}catch(d){A(!e)}finally{E(!1)}},disabled:S,className:"h-3 w-3 data-[state=checked]:bg-slate-600 data-[state=checked]:border-slate-600 border-slate-400 rounded-sm"}),(0,le.jsxs)("label",{htmlFor:"email-notifications",className:"text-xs opacity-80 cursor-pointer flex items-center space-x-1",children:[(0,le.jsx)(Uh.A,{className:"w-3 h-3 flex-shrink-0"}),(0,le.jsx)("span",{children:"Notify me when a Base44 representative responds"})]})]})})]})})}),(0,le.jsxs)("div",{className:"flex-shrink-0 p-2",children:[a&&(0,le.jsx)("div",{className:"mb-2",children:(0,le.jsx)(Mw,{onTemplateSelect:e=>{const t=P?e.substring(0,P):e;y(t),setTimeout(()=>{const e=document.querySelector('textarea[placeholder*="Type your"]');e&&(e.focus(),e.setSelectionRange(e.value.length,e.value.length))},100)},className:"px-2"})}),"closed"===r.status?(0,le.jsx)("div",{className:"flex items-center justify-center py-4 text-slate-500 bg-slate-50 rounded-lg border",children:(0,le.jsx)("span",{className:"text-sm",children:"This conversation is closed"})}):"resolved"!==r.ticket_status||a?(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsx)(Wt,{value:j,files:N,onSend:async e=>{let t,{text:l,files:r}=e;x(!0);try{t={id:"temp-".concat(Date.now()),role:a?"assistant":"user",content:l,file_urls:r||[],created_date:(new Date).toISOString(),is_admin_message:a,is_temp:!0},i(e=>(0,K.A)((0,K.A)({},e),{},{messages:[...(null==e?void 0:e.messages)||[],t]}));const e=await fw.addMessage(s,{role:a?"assistant":"user",content:l,file_urls:r||[],additional_message_params:a?{is_admin_message:!0}:{}});a&&localStorage.removeItem(L),n&&n({conversationId:s,action:"message_sent",role:a?"admin":"user",conversation:e})}catch(d){var o,c,m,u;if(t&&i(e=>(0,K.A)((0,K.A)({},e),{},{messages:((null==e?void 0:e.messages)||[]).filter(e=>e.id!==t.id)})),400===(null===(o=d.response)||void 0===o?void 0:o.status)&&null!==(c=d.response)&&void 0!==c&&null!==(m=c.data)&&void 0!==m&&null!==(u=m.detail)&&void 0!==u&&u.includes("already resolved"))return alert("This ticket has been resolved. Please create a new ticket for additional support."),void await O();throw d}finally{x(!1)}},placeholder:a?"Type your response...":"Type your message...",disabled:u||"resolved"===r.ticket_status&&!a,isProcessing:u,onValueChange:e=>{const t=P?e.substring(0,P):e;y(t)},onFilesChange:w,variant:"default",customButtomRight:F,isAdminMode:a}),P&&(0,le.jsxs)("div",{className:"flex justify-between items-center px-3 py-1 text-xs text-slate-500",children:[(0,le.jsx)("span",{}),(0,le.jsxs)("span",{className:"".concat(j.length>.9*P?"text-orange-600 font-medium":j.length===P?"text-red-600 font-medium":""),children:[j.length,"/",P]})]})]}):(0,le.jsxs)("div",{className:"flex flex-col items-center justify-center py-6 text-slate-500 bg-slate-50 rounded-lg border space-y-3",children:[(0,le.jsx)(pr.A,{className:"w-8 h-8 text-teal-500"}),(0,le.jsxs)("div",{className:"text-center",children:[(0,le.jsx)("p",{className:"text-sm font-medium text-slate-700 mb-1",children:"This ticket has been resolved"}),(0,le.jsx)("p",{className:"text-xs text-slate-500",children:"Please create a new ticket for additional support"})]})]})]})]})}const Fw={authentication:"\u{1f510}",billing:"\u{1f4b3}",bug_report:"\u{1f41b}",integrations_and_backend_functions:"\u26a1",chat_issues:"\u{1f4ac}",security:"\u{1f6e1}\ufe0f",other:"\u2753"};function Bw(e){let{conversationId:t,isOpen:s,onClose:a,ticketTitle:n,ticket:l,onTicketUpdated:r}=e;const{user:i}=oe();return s?(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)("div",{className:"fixed inset-0 bg-black/20 backdrop-blur-sm z-40 transition-opacity duration-300",onClick:a}),(0,le.jsxs)("div",{className:"fixed right-0 top-0 h-screen w-full max-w-2xl bg-white shadow-2xl z-50 transform transition-transform duration-300 ease-out flex flex-col ".concat(s?"translate-x-0":"translate-x-full"),children:[(0,le.jsxs)("div",{className:"flex-shrink-0 p-4 border-b border-slate-200 bg-white",children:[(0,le.jsxs)("div",{className:"flex items-center justify-between mb-3",children:[(0,le.jsxs)("div",{className:"flex items-center space-x-3 flex-1 min-w-0",children:[(0,le.jsx)(Yt,{variant:"ghost",size:"sm",onClick:a,className:"p-1.5 hover:bg-slate-100",children:(0,le.jsx)(Cd.A,{className:"w-4 h-4"})}),(0,le.jsx)("div",{className:"flex-1 min-w-0",children:(0,le.jsx)("h2",{className:"text-base font-semibold text-slate-900 leading-tight truncate",children:n||"Support Conversation"})})]}),(0,le.jsx)(Yt,{variant:"ghost",size:"sm",onClick:a,className:"p-1.5 hover:bg-slate-100",children:(0,le.jsx)(Bt.A,{className:"w-4 h-4"})})]}),(0,le.jsxs)("div",{className:"flex items-center justify-between text-xs text-slate-600",children:[(0,le.jsxs)("div",{className:"flex items-center space-x-3",children:[(0,le.jsxs)("span",{className:"font-mono bg-slate-100 px-2 py-1 rounded text-xs",children:["#",null==t?void 0:t.slice(0,8)]}),(null==l?void 0:l.created_date)&&(0,le.jsxs)("span",{className:"flex items-center space-x-1",children:[(0,le.jsx)(bh.A,{className:"w-3 h-3"}),(0,le.jsx)("span",{children:ra().utc(l.created_date).fromNow()})]})]}),(0,le.jsxs)("div",{className:"flex items-center space-x-2",children:[(null==l?void 0:l.category)&&(0,le.jsxs)("span",{className:"flex items-center space-x-1 text-xs",children:[(0,le.jsx)("span",{children:Fw[l.category]||"\u{1f4cb}"}),(0,le.jsx)("span",{className:"hidden sm:inline",children:l.category.replace(/_/g," ").replace(/\b\w/g,e=>e.toUpperCase())})]}),(null==l?void 0:l.app_id)&&(0,le.jsxs)("a",{href:"/apps/".concat(l.app_id),className:"flex items-center space-x-1 text-blue-600 hover:text-blue-800 hover:underline",children:[(0,le.jsx)(pw.A,{className:"w-3 h-3"}),(0,le.jsx)("span",{className:"hidden sm:inline",children:"App"}),(0,le.jsx)(Tr.A,{className:"w-3 h-3"})]})]})]})]}),(0,le.jsx)(Dw,{conversationId:t,isAdmin:!1,onMessageSent:e=>{r&&null!=e&&e.conversation&&r(t,"message_sent","user",e.conversation)}})]})]}):null}const zw=["node"],Uw=["node","inline"],Ww=["node"],qw=["node"],Vw=["node"],Hw=["node"],Yw=["node"],Gw=["node"],$w=["node"],Jw=["node"],Zw=[{value:"authentication",label:"Authentication",icon:Mt.A},{value:"billing",label:"Billing",icon:we.A},{value:"bug_report",label:"Bug Report",icon:Mi.A},{value:"integrations_and_backend_functions",label:"Integrations & Backend",icon:Oi.A},{value:"chat_issues",label:"Chat Issues",icon:Gv.A},{value:"security",label:"Security",icon:lv.A},{value:"social_post_bonus_credits",label:"Social Post Bonus Credits",icon:Au.A},{value:"other",label:"Other",icon:ku.A}],Kw=["billing","security","social_post_bonus_credits","other"],Qw=(e,t)=>!t&&(e&&!Kw.includes(e));function Xw(e){let{value:t,onChange:s}=e;return(0,le.jsxs)(zs,{value:t,onValueChange:s,children:[(0,le.jsx)(qs,{className:"w-full",children:(0,le.jsx)(Ws,{placeholder:"Select a category"})}),(0,le.jsx)(Ys,{children:Zw.map(e=>{const t=e.icon;return(0,le.jsx)($s,{value:e.value,children:(0,le.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,le.jsx)(t,{className:"w-4 h-4"}),(0,le.jsx)("span",{children:e.label})]})},e.value)})})]})}function e_(e){var t,s,a;let{appId:n,onSubmit:l,onCancel:r}=e;const{user:i}=oe(),[o,c]=(0,Y.useState)(""),[d,m]=(0,Y.useState)(""),[u,x]=(0,Y.useState)([]),[h,p]=(0,Y.useState)(""),[g,f]=(0,Y.useState)(""),[v,b]=(0,Y.useState)(!1),[j,y]=(0,Y.useState)({}),[N,w]=(0,Y.useState)(null),[_,k]=(0,Y.useState)(!1),C=function(){const e=dw(),t=(0,Y.useRef)({}),s=e=>{t.current=(0,K.A)((0,K.A)({},t.current),e)};return{submitClicked:()=>{s({submitTicketClicked:!0})},botAnswered:e=>{let{answerExists:t}=e;s({hasBotAnswer:t})},ticketCreated:t=>{let{ticketData:a}=t;s({ticketData:a}),ot.track("support_ticket_modal_submitted",e.sessionContext,{ticket_id:null==a?void 0:a.id,conversation_id:null==a?void 0:a.id,category_selected:null==a?void 0:a.category,description:null==a?void 0:a.content,subject_selected:null==a?void 0:a.title},{useBeacon:!0}).catch()},pageClosed:function(){var s,a;let{action:n}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};ot.track("support_ticket_modal_closed",e.sessionContext,{action:null!==(s=null!=n?n:t.current.closeAction)&&void 0!==s?s:"x_button",ticket_id:null===(a=t.current.ticketData)||void 0===a?void 0:a.id,is_after_bot_answer:t.current.hasBotAnswer},{useBeacon:!0}).catch(),t.current={}},botAnswerHelped:()=>{var s,a,n,l,r;ot.track("support_ticket_modal_bot_helped_click",e.sessionContext,{ticket_id:null===(s=t.current.ticketData)||void 0===s?void 0:s.id,conversation_id:null===(a=t.current.ticketData)||void 0===a?void 0:a.id,category_selected:null===(n=t.current.ticketData)||void 0===n?void 0:n.category,description:null===(l=t.current.ticketData)||void 0===l?void 0:l.content,subject_selected:null===(r=t.current.ticketData)||void 0===r?void 0:r.title},{useBeacon:!0}).catch()},botAnswerNotHelped:()=>{var s,a,n,l,r;ot.track("support_ticket_modal_still_need_help_click",e.sessionContext,{ticket_id:null===(s=t.current.ticketData)||void 0===s?void 0:s.id,conversation_id:null===(a=t.current.ticketData)||void 0===a?void 0:a.id,category_selected:null===(n=t.current.ticketData)||void 0===n?void 0:n.category,description:null===(l=t.current.ticketData)||void 0===l?void 0:l.content,subject_selected:null===(r=t.current.ticketData)||void 0===r?void 0:r.title},{useBeacon:!0}).catch()},pageView:()=>{t.current={},ot.track("support_ticket_modal_view",e.sessionContext,{},{useBeacon:!0}).catch()},closeClicked:e=>{let{action:t}=e;s({closeAction:t})},helpTypeClick:s=>{var a;let{type:n}=s;ot.track("support_ticket_modal_help_type_click",e.sessionContext,{ticket_id:null===(a=t.current.ticketData)||void 0===a?void 0:a.id,type:n},{useBeacon:!0}).catch()}}}();(0,Y.useEffect)(()=>(C.pageView(),()=>{C.pageClosed({})}),[]);const A=async()=>{b(!0);try{const e={title:o.trim(),content:d.trim(),category:h,app_id:n||null,app_link:g.trim()||null,file_urls:u||[]},t=await fw.create(e);c(""),m(""),x([]),p(""),f(""),y({}),w(null),null==l||l(t),C.ticketCreated({ticketData:{id:t.id,category:h,content:d,title:o}})}catch(e){e.response&&e.response.data?y({submit:e.response.data.message}):y({submit:"Failed to submit your support ticket. Please try again."})}finally{b(!1)}},S=async e=>{if(null==e||e.preventDefault(),(()=>{const e={};return(!o.trim()||o.length<5)&&(e.title="Title must be at least 5 characters"),o.length>100&&(e.title="Title must be less than 100 characters"),(!d.trim()||d.length<20)&&(e.content="Please provide more details (at least 20 characters)"),d.length>500&&(e.content="Description must be less than 500 characters"),h||(e.category="Please select a category"),Qw(h,n)&&!g.trim()&&(e.appLink="App link is required for technical issues. Please provide a link to your app."),g.trim()&&!g.match(/^https?:\/\/.+/)&&(e.appLink="Please enter a valid URL (starting with http:// or https://)"),y(e),0===Object.keys(e).length})()){k(!0),w(null),y({}),C.submitClicked();try{const e=await kw.requestAnswer(o.trim(),d.trim(),h,u||[]);e.answer_exists?(w(e),C.botAnswered({answerExists:!0})):await A()}catch(t){await A()}finally{k(!1)}}},E=async()=>{if(N)try{const t=N;w(null),b(!0);const s={title:o.trim(),content:d.trim(),category:h,app_id:n||null,app_link:g.trim()||null,file_urls:u||[]},a=await fw.create(s);try{const e="category: ".concat(h,"\ntitle: ").concat(o.trim(),"\n\ncontent: ").concat(d.trim());await kw.logAnswer(a.id,t,!1,e)}catch(e){}c(""),m(""),x([]),p(""),f(""),y({}),null==l||l(a),C.ticketCreated({ticketData:{id:a.id,category:h,content:d,title:o}}),C.botAnswerNotHelped()}catch(t){t.response&&t.response.data?y({submit:t.response.data.message}):y({submit:"Failed to submit your support ticket. Please try again."})}finally{b(!1)}else await A()},I=async()=>{if(N){try{const e="category: ".concat(h,"\ntitle: ").concat(o.trim(),"\n\ncontent: ").concat(d.trim());await kw.logAnswer(null,N,!0,e)}catch(e){}C.botAnswerHelped()}c(""),m(""),x([]),p(""),f(""),y({}),w(null),C.closeClicked({action:"bot_answer_helped_click"}),null==r||r()};return N&&N.answer_exists?(0,le.jsxs)("div",{className:"w-full p-6",children:[(0,le.jsx)("div",{className:"mb-4",children:(0,le.jsxs)("button",{onClick:()=>{w(null),C.closeClicked({action:"back_button_click"})},className:"inline-flex items-center text-xs text-slate-500 hover:text-slate-700 transition-colors",children:[(0,le.jsx)(Xs.A,{className:"w-3 h-3 mr-1"}),"Back"]})}),(0,le.jsxs)("div",{className:"mb-6",children:[(0,le.jsx)("h2",{className:"text-base font-medium text-slate-900 mb-1",children:"This might help"}),(0,le.jsx)("p",{className:"text-sm text-slate-500",children:"Here's what we found in our documentation"})]}),(0,le.jsx)("div",{className:"border-t border-b border-slate-200 py-6 mb-6",children:(0,le.jsx)("div",{children:(0,le.jsx)("div",{className:"prose prose-slate prose-sm max-w-none",children:(0,le.jsx)(mr.oz,{remarkPlugins:[dr.A],components:{a:e=>{let{node:t}=e,s=(0,Se.A)(e,zw);return(0,le.jsx)("a",(0,K.A)((0,K.A)({},s),{},{className:"text-slate-700 underline decoration-slate-300 hover:text-slate-900 hover:decoration-slate-500 transition-colors",target:"_blank",rel:"noopener noreferrer"}))},code:e=>{let{node:t,inline:s}=e,a=(0,Se.A)(e,Uw);return s?(0,le.jsx)("code",(0,K.A)({className:"bg-slate-100 px-1 py-0.5 rounded text-xs font-mono text-slate-700"},a)):(0,le.jsx)("code",(0,K.A)({className:"block bg-white border border-slate-200 p-3 rounded text-xs font-mono overflow-x-auto text-slate-700"},a))},blockquote:e=>{let{node:t}=e,s=(0,Se.A)(e,Ww);return(0,le.jsx)("blockquote",(0,K.A)({className:"border-l-2 border-slate-300 pl-4 text-slate-600"},s))},h1:e=>{let{node:t}=e,s=(0,Se.A)(e,qw);return(0,le.jsx)("h1",(0,K.A)({className:"text-lg font-semibold text-slate-900 mt-6 mb-3"},s))},h2:e=>{let{node:t}=e,s=(0,Se.A)(e,Vw);return(0,le.jsx)("h2",(0,K.A)({className:"text-base font-medium text-slate-900 mt-5 mb-2"},s))},h3:e=>{let{node:t}=e,s=(0,Se.A)(e,Hw);return(0,le.jsx)("h3",(0,K.A)({className:"text-sm font-medium text-slate-900 mt-4 mb-2"},s))},ul:e=>{let{node:t}=e,s=(0,Se.A)(e,Yw);return(0,le.jsx)("ul",(0,K.A)({className:"list-disc pl-5 space-y-1 text-sm mb-4"},s))},ol:e=>{let{node:t}=e,s=(0,Se.A)(e,Gw);return(0,le.jsx)("ol",(0,K.A)({className:"list-decimal pl-5 space-y-1 text-sm mb-4"},s))},li:e=>{let{node:t}=e,s=(0,Se.A)(e,$w);return(0,le.jsx)("li",(0,K.A)({className:"text-slate-600"},s))},p:e=>{var t;let{node:s}=e,a=(0,Se.A)(e,Jw);const n=(null===(t=a.children)||void 0===t?void 0:t.toString())||"",l=n.startsWith("Important")||n.startsWith("Source:");return(0,le.jsx)("p",(0,K.A)({className:"text-slate-600 leading-relaxed text-sm ".concat(l?"mt-5 mb-3":"mb-3")},a))}},children:N.answer})})})}),(0,le.jsxs)("div",{className:"flex flex-col sm:flex-row gap-3",children:[(0,le.jsxs)(Yt,{onClick:I,className:"flex-1 bg-slate-900 hover:bg-slate-800 text-white",children:[(0,le.jsx)(pr.A,{className:"w-4 h-4 mr-2"}),"This helps"]}),(0,le.jsx)(Yt,{variant:"outline",onClick:E,disabled:v,className:"flex-1 border-slate-300 text-slate-700 hover:bg-slate-50",children:v?(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)("div",{className:"w-4 h-4 border-2 border-slate-600 border-t-transparent rounded-full animate-spin mr-2"}),"Submitting ticket..."]}):(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(Gv.A,{className:"w-4 h-4 mr-2"}),"Still need help"]})})]}),(0,le.jsx)("p",{className:"text-xs text-slate-400 mt-4 text-center",children:"Not the answer you're looking for? Submit a ticket for human support."})]}):(0,le.jsx)(le.Fragment,{children:(0,le.jsxs)("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-8 p-6",children:[(0,le.jsx)("div",{className:"lg:col-span-2 space-y-6",children:(0,le.jsxs)("form",{onSubmit:S,className:"space-y-6",children:[(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsx)(Ns,{className:"text-sm font-medium text-gray-700",children:"Category"}),(0,le.jsx)(Xw,{value:h,onChange:p}),j.category&&(0,le.jsx)("p",{className:"text-sm text-red-600",children:j.category}),h&&!n&&Qw(h,n)&&(0,le.jsx)("div",{className:"bg-orange-50 border border-orange-200 rounded-md p-2",children:(0,le.jsxs)("p",{className:"text-xs text-orange-700 flex items-start",children:[(0,le.jsx)(_e.A,{className:"w-3 h-3 mr-1 mt-0.5 flex-shrink-0"}),(0,le.jsxs)("span",{children:["For ",h.replace(/_/g," ")," issues, you'll need to provide a link to your app."]})]})})]}),(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsx)(Ns,{htmlFor:"title",className:"text-sm font-medium text-gray-700",children:"Subject"}),(0,le.jsx)(fs,{id:"title",value:o,onChange:e=>c(e.target.value),placeholder:"Brief description of your issue",className:"w-full ".concat(j.title?"border-red-500":"")}),j.title&&(0,le.jsx)("p",{className:"text-sm text-red-600",children:j.title})]}),!n&&(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsxs)(Ns,{htmlFor:"appLink",className:"text-sm font-medium text-gray-700",children:["App Link ",Qw(h,n)?(0,le.jsx)("span",{className:"text-red-500",children:"*"}):(0,le.jsx)("span",{className:"text-gray-400",children:"(optional)"})]}),(0,le.jsx)(fs,{id:"appLink",value:g,onChange:e=>f(e.target.value),placeholder:"https://your-app-url.com or https://yourapp.base44.app",className:"w-full ".concat(j.appLink?"border-red-500":"")}),(0,le.jsxs)("div",{className:"space-y-1",children:[Qw(h,n)?(0,le.jsxs)("div",{className:"flex items-start space-x-1",children:[(0,le.jsx)(_e.A,{className:"w-3 h-3 text-orange-500 mt-0.5 flex-shrink-0"}),(0,le.jsxs)("p",{className:"text-xs text-orange-600",children:["App link is required for ",null==h?void 0:h.replace(/_/g," ")," issues. This helps us investigate and resolve your issue faster."]})]}):(0,le.jsx)("p",{className:"text-xs text-gray-500",children:"Provide a link to your app to help us better understand the context of your issue."}),h&&Kw.includes(h)&&(0,le.jsxs)("p",{className:"text-xs text-gray-400 italic",children:["App link is optional for ",h.replace(/_/g," ")," issues."]})]}),j.appLink&&(0,le.jsx)("p",{className:"text-sm text-red-600",children:j.appLink})]}),(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsx)(Ns,{className:"text-sm font-medium text-gray-700",children:"Steps to Reproduce / Description"}),(0,le.jsx)("div",{className:"".concat(j.content?"border border-red-500 rounded-lg":""),children:(0,le.jsx)(Wt,{value:d,files:u,placeholder:"Please provide detailed information about your issue, including any error messages, steps to reproduce, or relevant context...",disabled:v,isProcessing:!1,onValueChange:m,onFilesChange:x,variant:"default",customButtomRight:()=>null})}),(0,le.jsxs)("div",{className:"flex justify-between items-center",children:[(0,le.jsx)("p",{className:"text-xs text-gray-500",children:"Please provide: what happened, what you expected, steps to recreate the issue, relevant links, and screenshots. The more specific details you include, the faster we can resolve your issue."}),(0,le.jsxs)("p",{className:"text-xs ".concat(d.length>500?"text-red-500":d.length>450?"text-orange-500":"text-gray-400"),children:[d.length,"/500"]})]}),j.content&&(0,le.jsx)("p",{className:"text-sm text-red-600",children:j.content})]}),j.submit&&(0,le.jsx)(De,{variant:"destructive",children:(0,le.jsx)(Be,{children:j.submit})})]})}),(0,le.jsxs)("div",{className:"space-y-6",children:[(0,le.jsxs)("div",{className:"bg-gray-50 rounded-lg p-4 space-y-3",children:[(0,le.jsx)("h3",{className:"text-sm font-semibold text-gray-900",children:"Ticket Information"}),n&&(0,le.jsxs)("div",{className:"space-y-1",children:[(0,le.jsx)("p",{className:"text-xs text-gray-500",children:"App ID"}),(0,le.jsx)("p",{className:"text-sm font-mono text-gray-900 bg-white px-2 py-1 rounded border",children:n})]}),!n&&g&&(0,le.jsxs)("div",{className:"space-y-1",children:[(0,le.jsx)("p",{className:"text-xs text-gray-500",children:"App Link"}),(0,le.jsx)("p",{className:"text-sm text-gray-900 bg-white px-2 py-1 rounded border break-all",children:g})]}),(0,le.jsxs)("div",{className:"space-y-1",children:[(0,le.jsx)("p",{className:"text-xs text-gray-500",children:"Support Tier"}),(0,le.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,le.jsx)("span",{className:"inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium ".concat(null!=i&&null!==(t=i.subscription_tier)&&void 0!==t&&t.toLowerCase().includes("elite")?"bg-purple-100 text-purple-800":null!=i&&null!==(s=i.subscription_tier)&&void 0!==s&&s.toLowerCase().includes("pro")?"bg-blue-100 text-blue-800":"bg-gray-100 text-gray-800"),children:(null==i?void 0:i.subscription_tier)||"free"}),(null==i||null===(a=i.subscription_tier)||void 0===a?void 0:a.toLowerCase().includes("elite"))&&(0,le.jsx)("span",{className:"text-xs text-purple-600",children:"Priority Support"})]})]})]}),(0,le.jsxs)("div",{className:"space-y-3",children:[(0,le.jsx)(Yt,{onClick:S,disabled:v||_,className:"w-full bg-blue-600 hover:bg-blue-700 text-white",children:_?(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)("div",{className:"w-4 h-4 border-2 border-white border-t-transparent rounded-full animate-spin mr-2"}),"Checking for solutions..."]}):v?(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)("div",{className:"w-4 h-4 border-2 border-white border-t-transparent rounded-full animate-spin mr-2"}),"Submitting..."]}):(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(pp.A,{className:"w-4 h-4 mr-2"}),"Submit Ticket"]})}),(0,le.jsxs)(Yt,{variant:"outline",onClick:()=>{C.closeClicked({action:"cancel_click"}),null==r||r()},className:"w-full",children:[(0,le.jsx)(Bt.A,{className:"w-4 h-4 mr-2"}),"Cancel"]})]}),(0,le.jsx)("div",{className:"text-xs text-gray-500 space-y-2",children:(0,le.jsxs)("p",{children:[(0,le.jsx)("strong",{children:"Need immediate help?"})," Check our"," ",(0,le.jsx)("a",{onClick:()=>C.helpTypeClick({type:"documentation"}),href:"https://docs.base44.com",target:"_blank",rel:"noopener noreferrer",className:"text-blue-600 hover:underline",children:"documentation"})," ","or join our"," ",(0,le.jsx)("a",{onClick:()=>C.helpTypeClick({type:"discord"}),href:"https://discord.gg/ThpYPZpVts",target:"_blank",rel:"noopener noreferrer",className:"text-blue-600 hover:underline",children:"Discord community"}),"."]})})]})]})})}const t_={authentication:Mt.A,billing:we.A,bug_report:Mi.A,integrations_and_backend_functions:Oi.A,chat_issues:Gv.A,security:lv.A,other:ku.A},s_={open:{label:"Open",color:"bg-orange-100 text-orange-800 border-orange-200",icon:Li.A},resolved:{label:"Resolved",color:"bg-green-100 text-green-800 border-green-200",icon:Vg.A}},a_=e=>{var t,s,a,n,l;let{ticket:r,onClick:i,isSelected:o}=e;const c=(null===(t=s_[r.ticket_status])||void 0===t?void 0:t.icon)||_e.A,d=t_[r.category]||ku.A;return(0,le.jsxs)(is,{className:"group hover:shadow-lg transition-all duration-300 cursor-pointer ".concat(o?"border-orange-500 bg-orange-50 shadow-lg":"border-slate-200 hover:border-slate-300"),onClick:()=>i(r),children:[(0,le.jsx)(os,{className:"pb-3",children:(0,le.jsxs)("div",{className:"flex items-start justify-between",children:[(0,le.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,le.jsx)(cs,{className:"text-lg font-semibold truncate transition-colors ".concat(o?"text-orange-900":"text-slate-900 group-hover:text-slate-700"),children:r.title}),(0,le.jsxs)("div",{className:"flex items-center space-x-3 mt-2",children:[(0,le.jsxs)(es,{variant:"secondary",className:"".concat(null===(s=s_[r.ticket_status])||void 0===s?void 0:s.color," border text-xs font-medium"),children:[(0,le.jsx)(c,{className:"w-3 h-3 mr-1"}),null===(a=s_[r.ticket_status])||void 0===a?void 0:a.label]}),r.category&&(0,le.jsxs)(es,{variant:"outline",className:"text-xs",children:[(0,le.jsx)(d,{className:"w-3 h-3 mr-1"}),r.category.replace(/_/g," ").replace(/\b\w/g,e=>e.toUpperCase())]})]})]}),(0,le.jsxs)("div",{className:"ml-4 flex items-center",children:[(0,le.jsx)(bh.A,{className:"w-3 h-3 mr-2 text-slate-400"}),(e=>{if(!e)return"Not available";const t=ra().utc(e);return(0,le.jsxs)("div",{className:"text-right text-xs text-slate-500",children:[(0,le.jsx)("div",{className:"font-medium",children:t.format("MMM DD, YYYY")}),(0,le.jsx)("div",{className:"text-slate-400 mt-0.5",children:t.fromNow()})]})})(r.created_date)]})]})}),(0,le.jsxs)(ms,{className:"pt-0",children:[(0,le.jsx)("p",{className:"text-slate-600 text-sm leading-relaxed line-clamp-2 mb-3",children:r.content}),(0,le.jsxs)("div",{className:"flex items-center justify-between text-xs text-slate-500",children:[(0,le.jsx)("div",{className:"flex items-center space-x-4",children:r.app_id&&(0,le.jsxs)("div",{className:"flex items-center",children:[(0,le.jsx)(pw.A,{className:"w-3 h-3 mr-1"}),(0,le.jsxs)("span",{children:["App: ",r.app_id]})]})}),(0,le.jsx)(es,{variant:"outline",className:"text-xs ".concat(null!==(n=r.user_subscription_tier)&&void 0!==n&&n.toLowerCase().includes("elite")?"border-purple-200 text-purple-700":null!==(l=r.user_subscription_tier)&&void 0!==l&&l.toLowerCase().includes("pro")?"border-blue-200 text-blue-700":"border-gray-200 text-gray-700"),children:r.user_subscription_tier||"free"})]})]})]})},n_=e=>{let{filter:t,onCreateTicket:s}=e;return(0,le.jsxs)("div",{className:"text-center py-16",children:[(0,le.jsx)("div",{className:"mx-auto w-24 h-24 bg-slate-100 rounded-full flex items-center justify-center mb-6",children:(0,le.jsx)(ow.A,{className:"w-12 h-12 text-slate-400"})}),(0,le.jsxs)("h3",{className:"text-xl font-semibold text-slate-900 mb-2",children:["No ","open"===t?"Open":"closed"===t?"Closed":""," Tickets"]}),(0,le.jsx)("p",{className:"text-slate-600 max-w-md mx-auto mb-6",children:"open"===t?"You don't have any open support tickets at the moment.":"closed"===t?"No closed tickets found.":"You haven't submitted any support tickets yet."}),(0,le.jsxs)(Yt,{className:"bg-orange-500 hover:bg-orange-600",onClick:s,children:[(0,le.jsx)(kt.A,{className:"w-4 h-4 mr-2"}),"Create New Ticket"]})]})};function l_(){const[e,t]=(0,J.useSearchParams)(),s=(0,Z.Zp)(),{toast:a}=nn(),n=e.get("appId"),l="true"===e.get("openNew"),[r,i]=(0,Y.useState)([]),[o,c]=(0,Y.useState)(!0),[d,m]=(0,Y.useState)(null),[u,x]=(0,Y.useState)("open"),[h,p]=(0,Y.useState)(null),[g,f]=(0,Y.useState)(!1),[v,b]=(0,Y.useState)(!1),j=function(){const e=dw();return{pageView:()=>{ot.track("support_my_tickets_page_view",e.sessionContext,{},{useBeacon:!0}).catch()},newTicketClick:()=>{ot.track("support_my_tickets_new_ticket_click",e.sessionContext,{},{useBeacon:!0}).catch()}}}();(0,Y.useEffect)(()=>{y(),j.pageView()},[n]),(0,Y.useEffect)(()=>{if(l){b(!0);const s=new URLSearchParams(e);s.delete("openNew"),t(s,{replace:!0})}},[l,e,t]);const y=async()=>{try{c(!0),m(null);const e=await fw.list("-updated_date",1e3);e&&1e3===e.length&&a({title:"Ticket Limit Reached",description:"There are more tickets than can be loaded. Only the top 1000 most recent tickets were loaded.",variant:"default"});let t=e||[];n&&(t=t.filter(e=>e.app_id===n)),i(t)}catch(e){m("Failed to load support tickets. Please try again.")}finally{c(!1)}},N=e=>{p(e),f(!0)},w=()=>{b(!0),j.newTicketClick()},_=(()=>{switch(u){case"open":return r.filter(e=>"open"===e.ticket_status);case"closed":return r.filter(e=>"resolved"===e.ticket_status);default:return r}})(),k=r.filter(e=>"open"===e.ticket_status).length,C=r.filter(e=>"resolved"===e.ticket_status).length;return o?(0,le.jsx)("div",{className:"w-full max-w-6xl mx-auto px-6 py-12",children:(0,le.jsxs)("div",{className:"animate-pulse space-y-6",children:[(0,le.jsx)("div",{className:"h-8 bg-slate-200 rounded w-1/3"}),(0,le.jsx)("div",{className:"space-y-4",children:[1,2,3].map(e=>(0,le.jsx)("div",{className:"h-32 bg-slate-200 rounded-lg"},e))})]})}):d?(0,le.jsx)("div",{className:"w-full max-w-6xl mx-auto px-6 py-12",children:(0,le.jsxs)("div",{className:"text-center py-16",children:[(0,le.jsx)("div",{className:"mx-auto w-24 h-24 bg-red-100 rounded-full flex items-center justify-center mb-6",children:(0,le.jsx)(_e.A,{className:"w-12 h-12 text-red-500"})}),(0,le.jsx)("h3",{className:"text-xl font-semibold text-slate-900 mb-2",children:"Error Loading Tickets"}),(0,le.jsx)("p",{className:"text-slate-600 mb-6",children:d}),(0,le.jsx)(Yt,{onClick:y,variant:"outline",children:"Try Again"})]})}):(0,le.jsxs)(le.Fragment,{children:[(0,le.jsxs)("div",{className:"w-full max-w-6xl mx-auto px-6 py-12",children:[(0,le.jsxs)("div",{className:"mb-8",children:[(0,le.jsxs)("div",{className:"flex items-center justify-between mb-4",children:[(0,le.jsxs)("div",{className:"flex items-center space-x-4",children:[(0,le.jsxs)(Yt,{variant:"ghost",size:"sm",onClick:()=>{s("/support")},className:"text-slate-600 hover:text-slate-900 hover:bg-slate-100",children:[(0,le.jsx)(Cd.A,{className:"w-4 h-4 mr-2"}),"Back to Support"]}),(0,le.jsxs)("div",{children:[(0,le.jsx)("h1",{className:"text-3xl font-bold text-slate-900",children:"My Support Tickets"}),n&&(0,le.jsxs)("p",{className:"text-slate-600 mt-1",children:["Showing tickets for App: ",(0,le.jsx)("span",{className:"font-mono text-sm",children:n})]})]})]}),(0,le.jsxs)("div",{className:"flex items-center space-x-3",children:[(0,le.jsxs)(Yt,{onClick:y,variant:"outline",size:"sm",children:[(0,le.jsx)(Rb.A,{className:"w-4 h-4 mr-2"}),"Refresh"]}),(0,le.jsxs)(Yt,{className:"bg-orange-500 hover:bg-orange-600",size:"sm",onClick:w,children:[(0,le.jsx)(kt.A,{className:"w-4 h-4 mr-2"}),"New Ticket"]})]})]}),n&&(0,le.jsx)("div",{className:"mb-6",children:(0,le.jsxs)("div",{className:"inline-flex items-center gap-2 bg-blue-50 border border-blue-200 rounded-lg px-4 py-2",children:[(0,le.jsx)(Rb.A,{className:"w-4 h-4 text-blue-600"}),(0,le.jsxs)("span",{className:"text-sm font-medium text-blue-800",children:["Filtered by App: ",(0,le.jsx)("span",{className:"font-mono",children:n})]}),(0,le.jsx)(Yt,{variant:"ghost",size:"sm",onClick:()=>{window.location.href="/support/conversations"},className:"h-auto p-1 text-blue-600 hover:text-blue-800 hover:bg-blue-100",children:(0,le.jsx)(Bt.A,{className:"w-4 h-4"})})]})})]}),(0,le.jsxs)(kr,{value:u,onValueChange:x,className:"mb-6",children:[(0,le.jsxs)(Cr,{className:"grid w-full grid-cols-3 lg:w-96",children:[(0,le.jsxs)(Ar,{value:"open",className:"flex items-center space-x-2",children:[(0,le.jsx)(Li.A,{className:"w-4 h-4"}),(0,le.jsxs)("span",{children:["Open (",k,")"]})]}),(0,le.jsxs)(Ar,{value:"closed",className:"flex items-center space-x-2",children:[(0,le.jsx)(Vg.A,{className:"w-4 h-4"}),(0,le.jsxs)("span",{children:["Closed (",C,")"]})]}),(0,le.jsxs)(Ar,{value:"all",className:"flex items-center space-x-2",children:[(0,le.jsx)(ow.A,{className:"w-4 h-4"}),(0,le.jsxs)("span",{children:["All (",r.length,")"]})]})]}),(0,le.jsx)(Sr,{value:u,className:"mt-6",children:0===_.length?(0,le.jsx)(n_,{filter:u,onCreateTicket:w}):(0,le.jsx)("div",{className:"grid grid-cols-1 gap-4",children:_.map(e=>(0,le.jsx)(a_,{ticket:e,onClick:N,isSelected:(null==h?void 0:h.id)===e.id},e.id))})})]})]}),(0,le.jsx)(Pa,{open:v,onOpenChange:b,children:(0,le.jsxs)(Da,{className:"max-w-6xl max-h-[90vh] overflow-y-auto",children:[(0,le.jsx)(Fa,{children:(0,le.jsx)(za,{className:"text-2xl font-bold",children:"Submit Support Ticket"})}),(0,le.jsx)(e_,{appId:n,onSubmit:async e=>{b(!1),await y();const t=await fw.list("-updated_date",1e3);t&&1e3===t.length&&a({title:"Ticket Limit Reached",description:"There are more tickets than can be loaded. Only the top 1000 most recent tickets were loaded.",variant:"default"});let s=t||[];n&&(s=s.filter(e=>e.app_id===n));const l=s.find(t=>t.title===e.title&&t.content===e.content);l&&(p(l),f(!0),i(s))},onCancel:()=>{b(!1)}})]})}),(0,le.jsx)(Bw,{conversationId:null==h?void 0:h.id,isOpen:g,onClose:()=>{f(!1),p(null)},ticketTitle:null==h?void 0:h.title,ticket:h,onTicketUpdated:(e,t,s,a)=>{if(i(n=>n.map(n=>{if(n.id===e){if(a){let e="admin";if(a.messages&&a.messages.length>0){e="user"===a.messages[a.messages.length-1].role?"admin":"user"}return(0,K.A)((0,K.A)((0,K.A)({},n),a),{},{pending_response_from:e,updated_date:(new Date).toISOString()})}if("message_sent"===t){const e="user"===s;return(0,K.A)((0,K.A)({},n),{},{pending_response_from:e?"admin":"user",updated_date:(new Date).toISOString()})}return n}return n})),h&&h.id===e&&a){let e="admin";if(a.messages&&a.messages.length>0){const t=a.messages[a.messages.length-1];e="user"===t.role?"admin":"user"}p(t=>(0,K.A)((0,K.A)((0,K.A)({},t),a),{},{pending_response_from:e,updated_date:(new Date).toISOString()}))}}})]})}function r_(e){let{error:t,onRetry:s}=e;return(0,le.jsx)("div",{className:"w-full max-w-7xl mx-auto px-6 py-12",children:(0,le.jsxs)("div",{className:"text-center py-16",children:[(0,le.jsx)("div",{className:"mx-auto w-24 h-24 bg-red-100 rounded-full flex items-center justify-center mb-6",children:(0,le.jsx)(_e.A,{className:"w-12 h-12 text-red-500"})}),(0,le.jsx)("h3",{className:"text-xl font-semibold text-slate-900 mb-2",children:"Error Loading Tickets"}),(0,le.jsx)("p",{className:"text-slate-600 mb-6",children:t}),(0,le.jsx)(Yt,{onClick:s,variant:"outline",children:"Try Again"})]})})}var i_=s(45536),o_=s(91412);const c_={authentication:Mt.A,billing:we.A,bug_report:Mi.A,integrations_and_backend_functions:Oi.A,chat_issues:Gv.A,security:lv.A,social_post_bonus_credits:Au.A,other:ku.A},d_=(Li.A,Vg.A,{starter:{label:"Starter",color:"bg-green-100 text-green-800 border-green-200",icon:Eu.A},starter_yearly:{label:"Starter(Yearly)",color:"bg-green-100 text-green-800 border-green-200",icon:Eu.A},builder:{label:"Builder",color:"bg-blue-100 text-blue-800 border-blue-200",icon:vc.A},builder_yearly:{label:"Builder(Yearly)",color:"bg-blue-100 text-blue-800 border-blue-200",icon:vc.A},pro:{label:"Pro",color:"bg-indigo-100 text-indigo-800 border-indigo-200",icon:Cl.A},pro_yearly:{label:"Pro(Yearly)",color:"bg-indigo-100 text-indigo-800 border-indigo-200",icon:Cl.A},elite:{label:"Elite",color:"bg-purple-100 text-purple-800 border-purple-200",icon:i_.A},elite_yearly:{label:"Elite(Yearly)",color:"bg-purple-100 text-purple-800 border-purple-200",icon:i_.A},elite_2:{label:"Elite 2",color:"bg-violet-100 text-violet-800 border-violet-200",icon:o_.A},elite_2_yearly:{label:"Elite 2(Yearly)",color:"bg-violet-100 text-violet-800 border-violet-200",icon:o_.A},elite_3:{label:"Elite 3",color:"bg-pink-100 text-pink-800 border-pink-200",icon:nj.A},elite_3_yearly:{label:"Elite 3 (Yearly)",color:"bg-pink-100 text-pink-800 border-pink-200",icon:nj.A},elite_4:{label:"Elite 4",color:"bg-pink-100 text-pink-800 border-pink-200",icon:nj.A},elite_4_yearly:{label:"Elite 4 (Yearly)",color:"bg-pink-100 text-pink-800 border-pink-200",icon:nj.A},free:{label:"Free",color:"bg-gray-100 text-gray-800 border-gray-200",icon:Xl.A}});function m_(e){let{userEmail:t,currentTicketId:s}=e;const[a,n]=(0,Y.useState)([]),[l,r]=(0,Y.useState)(!0),[i,o]=(0,Y.useState)(null);(0,Y.useEffect)(()=>{t&&c()},[t]);const c=async()=>{try{r(!0);const e=(await bw.getTickets({created_by:t,show_resolved:!0})||[]).sort((e,t)=>new Date(t.created_date)-new Date(e.created_date));n(e)}catch(i){o(i)}finally{r(!1)}};return l?(0,le.jsx)("div",{className:"flex items-center justify-center py-4",children:(0,le.jsx)("div",{className:"animate-spin rounded-full h-4 w-4 border-b-2 border-slate-400"})}):i?(0,le.jsx)("div",{className:"text-xs text-red-600 p-2",children:"Failed to load tickets"}):0===a.length?(0,le.jsx)("div",{className:"text-xs text-slate-500 italic p-2",children:"No previous tickets found"}):(0,le.jsxs)("div",{className:"space-y-2 max-h-96 overflow-y-auto",children:[a.slice(0,10).map(e=>{const t=e.id===s;return(0,le.jsxs)(J.Link,{to:"/support/admin/conversations?conversationId=".concat(e.id),className:"block p-2 rounded-lg border transition-colors group ".concat(t?"border-teal-500 bg-teal-50 ring-1 ring-teal-500":"border-slate-200 hover:border-slate-300 hover:bg-slate-50"),children:[(0,le.jsxs)("div",{className:"space-y-1",children:[(0,le.jsx)("h4",{className:"text-xs font-medium text-slate-900 line-clamp-2 group-hover:text-slate-700",children:e.title}),(0,le.jsxs)("div",{className:"flex items-center justify-between",children:[(0,le.jsx)("div",{className:"flex items-center space-x-2",children:"resolved"===e.ticket_status?(0,le.jsxs)(es,{variant:"secondary",className:"text-[10px] bg-green-100 text-green-800 border-green-200 h-auto py-0.5 px-1",children:[(0,le.jsx)(Vg.A,{className:"w-2.5 h-2.5 mr-0.5"}),"Resolved"]}):(0,le.jsxs)(es,{variant:"secondary",className:"text-[10px] h-auto py-0.5 px-1 ".concat("admin"===e.pending_response_from?"bg-orange-100 text-orange-800 border-orange-200":"bg-blue-100 text-blue-800 border-blue-200"),children:[(0,le.jsx)(Li.A,{className:"w-2.5 h-2.5 mr-0.5"}),"admin"===e.pending_response_from?"Pending Admin":"Pending User"]})}),(0,le.jsx)("span",{className:"text-[10px] text-slate-500",children:ra().utc(e.created_date).fromNow()})]}),e.category&&(0,le.jsxs)("div",{className:"flex items-center text-[10px] text-slate-600",children:[(0,le.jsx)(Ir.A,{className:"w-2.5 h-2.5 mr-1"}),(0,le.jsx)("span",{className:"capitalize",children:e.category.replace(/_/g," ")})]})]}),(0,le.jsx)("div",{className:"flex items-center justify-end mt-1",children:t?(0,le.jsx)("span",{className:"text-[10px] text-teal-600 font-medium",children:"Current ticket"}):(0,le.jsx)(Tr.A,{className:"w-2.5 h-2.5 text-slate-400 opacity-0 group-hover:opacity-100 transition-opacity"})})]},e.id)}),a.length>10&&(0,le.jsxs)("div",{className:"text-[10px] text-slate-500 text-center py-2",children:["Showing 10 of ",a.length," tickets"]})]})}const u_=function(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(!e)return"Not available";const s=ra().utc(e);return t?"".concat(s.format("MMM DD, YYYY [at] HH:mm [UTC]")," (").concat(s.fromNow(),")"):"".concat(s.format("MMM DD, YYYY")," (").concat(s.fromNow(),")")},x_=[{value:"open",label:"Open",icon:Li.A,color:"text-orange-600"},{value:"resolved",label:"Resolved",icon:Vg.A,color:"text-green-600"}],h_=[{value:"authentication",label:"Authentication"},{value:"billing",label:"Billing"},{value:"bug_report",label:"Bug Report"},{value:"integrations_and_backend_functions",label:"Integrations & Backend"},{value:"chat_issues",label:"Chat Issues"},{value:"security",label:"Security"},{value:"social_post_bonus_credits",label:"Social Post Bonus Credits"},{value:"other",label:"Other"}],p_=e=>{let{category:t}=e;const s=c_[t]||_e.A,a=t?t.replace(/_/g," ").replace(/\b\w/g,e=>e.toUpperCase()):"Uncategorized";return(0,le.jsxs)(es,{variant:"outline",className:"text-xs",children:[(0,le.jsx)(s,{className:"w-3 h-3 mr-1"}),a]})},g_=e=>{let{title:t,icon:s,children:a,isCollapsible:n=!1,defaultExpanded:l=!0}=e;const[r,i]=(0,Y.useState)(l);return(0,le.jsxs)(is,{className:"border-slate-200",children:[(0,le.jsx)("div",{className:"p-3 ".concat(n?"cursor-pointer":""),onClick:n?()=>i(!r):void 0,children:(0,le.jsxs)("div",{className:"flex items-center justify-between",children:[(0,le.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,le.jsx)(s,{className:"w-4 h-4 text-slate-600"}),(0,le.jsx)("h3",{className:"text-sm font-semibold text-slate-900",children:t})]}),n&&(0,le.jsx)("div",{className:"text-slate-400",children:r?(0,le.jsx)(Ts.A,{className:"w-4 h-4"}):(0,le.jsx)(Is.A,{className:"w-4 h-4"})})]})}),r&&(0,le.jsx)(ms,{className:"pt-0 pb-3 px-3",children:a})]})},f_=e=>{let{label:t,value:s,className:a=""}=e;return(0,le.jsxs)("div",{className:"flex justify-between items-start py-1.5 ".concat(a),children:[(0,le.jsx)("span",{className:"text-xs text-slate-600 flex-shrink-0 w-20",children:t}),(0,le.jsx)("span",{className:"text-xs text-slate-900 text-right flex-1",children:s})]})};function v_(e){var t,s,a,n,l;let{conversationId:r,onTicketUpdated:i}=e;const{conversationId:o}=(0,Z.g)(),[c]=(0,J.useSearchParams)(),d=c.get("conversationId"),m=r||o||d,[u,x]=(0,Y.useState)(null),[h,p]=(0,Y.useState)(!0),[g,f]=(0,Y.useState)(null),[v,b]=(0,Y.useState)(!1),[j,y]=(0,Y.useState)([]),[N,w]=(0,Y.useState)([]),[_,k]=(0,Y.useState)(!1),[C,A]=(0,Y.useState)([]),[S,E]=(0,Y.useState)(!1),[I,T]=(0,Y.useState)(""),[P,L]=(0,Y.useState)(""),[O,R]=(0,Y.useState)(!1),[M,D]=(0,Y.useState)(""),[F,B]=(0,Y.useState)(!1),[z,U]=(0,Y.useState)(""),[W,q]=(0,Y.useState)(!1),[V,H]=(0,Y.useState)(!1),[G,$]=(0,Y.useState)(!1);(0,Y.useEffect)(()=>{m&&(x(null),p(!0),f(null),K())},[m]);const K=async()=>{try{var e,t;p(!0),f(null);const[s,a]=await Promise.all([bw.getTicketDetail(m),yw.getAgentProperties()]);x(s),y((null==a?void 0:a.internal_category_options)||[]),w((null==s||null===(e=s.ticket)||void 0===e?void 0:e.internal_categories)||[]),D((null==s||null===(t=s.ticket)||void 0===t?void 0:t.internal_notes)||"")}catch(s){f("Failed to load ticket details. Please try again.")}finally{p(!1)}},Q=async()=>{const e=(t=I).trim()?/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t)?t.endsWith("@base44.com")||t.endsWith("@wix.com")?"":"Email must be from @base44.com or @wix.com domain":"Please enter a valid email address":"Email is required";var t;if(e)L(e);else try{R(!0),L(""),await bw.assignTicket(m,I.trim()),await K(),i&&i(m,"assigned",I.trim()),E(!1),T("")}catch(s){L("Failed to assign ticket. Please try again.")}finally{R(!1)}};if(h)return(0,le.jsx)("div",{className:"h-full flex items-center justify-center",children:(0,le.jsxs)("div",{className:"text-center",children:[(0,le.jsx)("div",{className:"animate-spin rounded-full h-6 w-6 border-b-2 border-slate-400 mx-auto mb-3"}),(0,le.jsx)("p",{className:"text-sm text-slate-600",children:"Loading conversation..."})]})});if(g)return(0,le.jsx)("div",{className:"h-full flex items-center justify-center p-6",children:(0,le.jsxs)("div",{className:"text-center",children:[(0,le.jsx)("div",{className:"w-12 h-12 bg-red-100 rounded-full flex items-center justify-center mx-auto mb-3",children:(0,le.jsx)(_e.A,{className:"w-6 h-6 text-red-500"})}),(0,le.jsx)("h3",{className:"text-sm font-semibold text-slate-900 mb-2",children:"Error Loading Ticket"}),(0,le.jsx)("p",{className:"text-xs text-slate-600 mb-4",children:g}),(0,le.jsx)(Yt,{onClick:K,variant:"outline",size:"sm",children:"Try Again"})]})});const X=(null==u?void 0:u.ticket)||{id:m,title:"Loading...",content:"Loading ticket content...",status:"pending_admin_response",category:"other",app_id:null,created_by:"unknown@example.com",user_subscription_tier:"free",created_date:(new Date).toISOString(),updated_date:(new Date).toISOString()},ee=(null==u?void 0:u.user)||{id:"unknown",email:X.created_by||"unknown@example.com",name:"Unknown User",stripe_customer_id:null,created_date:(new Date).toISOString()},te=(null==u?void 0:u.subscriptions)||[];return(0,le.jsxs)("div",{className:"h-full flex flex-col min-h-0",children:[(0,le.jsx)("div",{className:"border-b border-slate-200 p-4 bg-slate-50 flex-shrink-0 min-h-fit",children:(0,le.jsx)("div",{className:"space-y-4",children:(0,le.jsxs)("div",{className:"flex items-start justify-between gap-4",children:[(0,le.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,le.jsxs)("div",{className:"flex items-start gap-2",children:[(0,le.jsx)("h2",{className:"text-lg font-semibold text-slate-900 leading-snug break-words",children:X.title}),X.is_escalated&&(0,le.jsxs)(es,{variant:"destructive",className:"bg-red-100 text-red-800 border-red-200 flex-shrink-0",children:[(0,le.jsx)(ux.A,{className:"w-3 h-3 mr-1"}),"Escalated"]})]}),(0,le.jsxs)("div",{className:"flex items-start justify-between mt-3 gap-4",children:[(0,le.jsxs)("div",{className:"flex items-center space-x-3 flex-wrap min-w-0",children:[(0,le.jsx)(p_,{category:X.category}),(0,le.jsx)("div",{className:"text-xs text-slate-600",children:(0,le.jsx)("span",{className:"font-medium capitalize",children:X.ticket_status})}),X.assigned_to&&(0,le.jsxs)("div",{className:"text-xs text-slate-600",children:[(0,le.jsx)(ly.A,{className:"w-3 h-3 inline mr-1"}),(0,le.jsx)("span",{className:"font-medium",children:X.assigned_to})]})]}),(0,le.jsxs)("div",{className:"flex items-center space-x-2 flex-shrink-0 flex-wrap",children:["resolved"!==X.ticket_status&&(0,le.jsxs)(Yt,{variant:X.is_escalated?"destructive":"outline",size:"sm",onClick:async()=>{try{var e;$(!0);(null==u||null===(e=u.ticket)||void 0===e?void 0:e.is_escalated)||!1?await bw.unescalateTicket(m):await bw.escalateTicket(m),await K(),i&&i(m,"escalation_updated")}catch(t){f("Failed to change escalation status. Please try again.")}finally{$(!1)}},disabled:G,className:"h-auto py-1 px-2 text-xs ".concat(X.is_escalated?"bg-red-500 hover:bg-red-600 text-white":"text-slate-600 hover:text-slate-900 hover:bg-slate-100"),children:[G?(0,le.jsx)("div",{className:"animate-spin rounded-full h-3 w-3 border-b-2 border-current mr-1"}):(0,le.jsx)(ux.A,{className:"w-3 h-3 mr-1"}),X.is_escalated?"Unescalate":"Escalate"]}),"resolved"!==X.ticket_status&&(0,le.jsxs)(Yt,{variant:"outline",size:"sm",onClick:()=>{T(""),L(""),E(!0)},className:"text-slate-600 hover:text-slate-900 hover:bg-slate-100 h-auto py-1 px-2 text-xs",children:[(0,le.jsx)(sv.A,{className:"w-3 h-3 mr-1"}),X.assigned_to?"Reassign":"Assign"]}),(0,le.jsxs)(zs,{value:X.category||"other",onValueChange:async e=>{try{H(!0),await bw.updateTicketCategory(m,e),await K(),i&&i(m,"category_updated")}catch(t){f("Failed to change ticket category. Please try again.")}finally{H(!1)}},disabled:V,children:[(0,le.jsx)(qs,{className:"h-auto py-1 w-auto text-xs border-slate-300 hover:border-slate-400",children:(0,le.jsxs)("div",{className:"flex items-center",children:[V?(0,le.jsx)("div",{className:"animate-spin rounded-full h-3 w-3 border-b-2 border-slate-400 mr-1"}):(0,le.jsx)(pw.A,{className:"w-3 h-3 mr-1"}),(0,le.jsx)("span",{className:"mr-1",children:"Category:"}),(0,le.jsx)(Ws,{})]})}),(0,le.jsx)(Ys,{children:h_.map(e=>(0,le.jsx)($s,{value:e.value,children:e.label},e.value))})]}),(0,le.jsxs)(zs,{value:X.ticket_status,onValueChange:async e=>{try{b(!0),await bw.changeTicketStatus(m,e),await K(),i&&i(m,e)}catch(t){f("Failed to change ticket status. Please try again.")}finally{b(!1)}},disabled:v,children:[(0,le.jsx)(qs,{className:"h-auto py-1 w-auto text-xs border-slate-300 hover:border-slate-400",children:(0,le.jsxs)("div",{className:"flex items-center",children:[v?(0,le.jsx)("div",{className:"animate-spin rounded-full h-3 w-3 border-b-2 border-slate-400 mr-1"}):(()=>{const e=x_.find(e=>e.value===X.ticket_status),t=(null==e?void 0:e.icon)||Li.A;return(0,le.jsx)(t,{className:"w-3 h-3 mr-1"})})(),(0,le.jsx)(Ws,{})]})}),(0,le.jsx)(Ys,{children:x_.map(e=>{const t=e.icon;return(0,le.jsx)($s,{value:e.value,children:(0,le.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,le.jsx)(t,{className:"w-4 h-4 ".concat(e.color)}),(0,le.jsx)("span",{children:e.label})]})},e.value)})})]})]})]})]}),(0,le.jsxs)("div",{className:"flex flex-col items-end space-y-1 text-xs text-slate-600 flex-shrink-0",children:[(0,le.jsxs)("span",{className:"font-mono bg-white px-2 py-1 rounded text-xs whitespace-nowrap",children:["id: ",X.id]}),(0,le.jsx)("span",{className:"text-right text-xs",children:u_(X.created_date)})]})]})})}),(0,le.jsxs)(Mm,{direction:"horizontal",className:"flex-1 overflow-hidden min-h-0",children:[(0,le.jsx)(Dm,{defaultSize:90,minSize:20,children:(0,le.jsx)("div",{className:"h-full flex flex-col min-h-0",children:(0,le.jsx)(Dw,{conversationId:m,isAdmin:!0,onMessageSent:e=>{"object"==typeof e&&e.conversationId?i&&i(e.conversationId,e.action,e.role,e.conversation):i&&i(m,"message_sent","admin")}},m)})}),(0,le.jsx)(Fm,{withHandle:!0,className:"hidden lg:flex group transition-opacity opacity-0 hover:opacity-100 focus:opacity-100"}),(0,le.jsx)(Dm,{defaultSize:30,minSize:15,maxSize:40,className:"hidden lg:block",children:(0,le.jsx)("div",{className:"w-full border-l border-slate-200 bg-slate-50 h-full flex flex-col",children:(0,le.jsxs)("div",{className:"flex-1 overflow-y-auto p-3 space-y-3",children:[(0,le.jsx)(g_,{title:"User",icon:nv.A,isCollapsible:!0,defaultExpanded:!0,children:(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsx)(f_,{label:"Email",value:ee.email}),(0,le.jsx)(f_,{label:"Name",value:ee.full_name||"Not provided"}),(0,le.jsx)(f_,{label:"Subscription Status",value:ee.stripe_subscription_status||"Not provided"}),(0,le.jsx)(f_,{label:"Manage",value:(0,le.jsxs)(J.Link,{to:"/user-management?userId=".concat(ee.id),target:"_blank",className:"inline-flex items-center text-slate-600 hover:text-slate-900 text-xs transition-colors",children:["View Profile",(0,le.jsx)(Tr.A,{className:"w-2 h-2 ml-1"})]})}),ee.stripe_customer_id&&(0,le.jsx)(f_,{label:"Stripe",value:(0,le.jsxs)("a",{href:"https://dashboard.stripe.com/customers/".concat(ee.stripe_customer_id),target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center text-blue-600 hover:text-blue-800 text-xs",children:["View",(0,le.jsx)(Tr.A,{className:"w-2 h-2 ml-1"})]})})]})}),(0,le.jsx)(g_,{title:"Previous Tickets",icon:_u.A,isCollapsible:!0,defaultExpanded:!0,children:(0,le.jsx)(m_,{userEmail:ee.email,currentTicketId:m})}),(0,le.jsx)(g_,{title:"Subscription",icon:we.A,isCollapsible:!0,defaultExpanded:!0,children:te&&te.length>0?(0,le.jsx)("div",{className:"space-y-2",children:te.map((e,t)=>{var s,a,n;return(0,le.jsxs)("div",{className:"space-y-1",children:[(0,le.jsx)(f_,{label:"Plan",value:(null===(s=e.plan)||void 0===s?void 0:s.nickname)||"Unknown"}),(0,le.jsx)(f_,{label:"Status",value:e.status}),(0,le.jsx)(f_,{label:"Amount",value:"$".concat(((null===(a=e.plan)||void 0===a?void 0:a.amount)/100).toFixed(2),"/").concat(null===(n=e.plan)||void 0===n?void 0:n.interval)})]},t)})}):(0,le.jsx)("p",{className:"text-xs text-slate-600",children:"No subscriptions found."})}),(0,le.jsx)(g_,{title:"App",icon:Ir.A,isCollapsible:!0,defaultExpanded:!0,children:(0,le.jsxs)("div",{className:"space-y-2",children:[(null==u?void 0:u.app_deleted)&&(0,le.jsx)("div",{className:"bg-amber-50 border border-amber-200 rounded-md p-3 mb-2",children:(0,le.jsxs)("div",{className:"flex items-start gap-2",children:[(0,le.jsx)(ux.A,{className:"w-4 h-4 text-amber-600 flex-shrink-0 mt-0.5"}),(0,le.jsxs)("div",{className:"flex-1",children:[(0,le.jsx)("p",{className:"text-xs font-medium text-amber-800",children:"App Deleted"}),(0,le.jsx)("p",{className:"text-xs text-amber-700 mt-1",children:"This ticket was linked to an app that has been deleted."}),(null==u?void 0:u.deleted_app_id)&&(0,le.jsxs)("p",{className:"text-xs text-amber-600 font-mono mt-1",children:["ID: ",u.deleted_app_id]})]})]})}),(0,le.jsx)(f_,{label:"Name",value:(null==u||null===(t=u.app)||void 0===t?void 0:t.name)||(null!=u&&u.app_deleted?"Deleted":"None")}),(0,le.jsx)(f_,{label:"Link",value:null!=u&&null!==(s=u.app)&&void 0!==s&&s.id?(0,le.jsxs)("a",{href:"https://app.base44.com/apps/".concat(u.app.id),target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center text-blue-600 hover:text-blue-800 text-xs",children:["View App",(0,le.jsx)(Tr.A,{className:"w-2 h-2 ml-1"})]}):null!=u&&u.app_deleted?(0,le.jsx)("span",{className:"text-xs text-amber-600",children:"App was deleted"}):"No app linked"}),(0,le.jsx)(f_,{label:"App Visiblity",value:(null==u||null===(a=u.app)||void 0===a?void 0:a.visibility)||"Not available"}),(0,le.jsx)(f_,{label:"Created",value:null!=u&&null!==(n=u.app)&&void 0!==n&&n.created_date?u_(u.app.created_date):"Not available"}),(0,le.jsx)(f_,{label:"Updated",value:null!=u&&null!==(l=u.app)&&void 0!==l&&l.updated_date?u_(u.app.updated_date):"Not available"}),(0,le.jsx)(f_,{label:"App ID",value:(null==u?void 0:u.deleted_app_id)||(null==X?void 0:X.app_id)||"None"})]})}),(0,le.jsx)(g_,{title:"Internal Categories",icon:pw.A,isCollapsible:!0,defaultExpanded:!0,children:(0,le.jsxs)("div",{className:"space-y-3",children:[(0,le.jsx)("div",{className:"text-xs text-slate-600 mb-2",children:"Internal categories for admin organization and tracking."}),_?(0,le.jsxs)("div",{className:"space-y-3",children:[(0,le.jsx)("div",{className:"space-y-2",children:j.map(e=>(0,le.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,le.jsx)(dm,{id:"category-".concat(e),checked:C.includes(e),onCheckedChange:()=>(e=>{A(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])})(e),className:"h-3 w-3"}),(0,le.jsx)("label",{htmlFor:"category-".concat(e),className:"text-xs text-slate-700 cursor-pointer",children:e})]},e))}),(0,le.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,le.jsxs)(Yt,{variant:"default",size:"sm",onClick:async()=>{try{await bw.updateInternalCategories(m,C),w([...C]),k(!1),A([]),i&&i(m,"categories_updated")}catch(e){f("Failed to update internal categories. Please try again.")}},className:"h-6 px-2 text-xs",children:[(0,le.jsx)(df.A,{className:"w-3 h-3 mr-1"}),"Save"]}),(0,le.jsxs)(Yt,{variant:"outline",size:"sm",onClick:()=>{A([]),k(!1)},className:"h-6 px-2 text-xs",children:[(0,le.jsx)(Bt.A,{className:"w-3 h-3 mr-1"}),"Cancel"]})]})]}):(0,le.jsxs)("div",{className:"space-y-2",children:[N.length>0?(0,le.jsx)("div",{className:"flex flex-wrap gap-1",children:N.map(e=>(0,le.jsx)(es,{variant:"secondary",className:"text-xs",children:e},e))}):(0,le.jsx)("p",{className:"text-xs text-slate-500 italic",children:"No internal categories assigned."}),(0,le.jsxs)(Yt,{variant:"outline",size:"sm",onClick:()=>{A([...N]),k(!0)},className:"h-6 px-2 text-xs",children:[(0,le.jsx)(Ql.A,{className:"w-3 h-3 mr-1"}),"Edit Categories"]})]})]})}),(0,le.jsx)(g_,{title:"Internal Notes",icon:hr.A,isCollapsible:!0,defaultExpanded:!0,children:(0,le.jsxs)("div",{className:"space-y-3",children:[(0,le.jsx)("div",{className:"text-xs text-slate-600 mb-2",children:"Private notes visible only to admins."}),F?(0,le.jsxs)("div",{className:"space-y-3",children:[(0,le.jsx)(um,{value:z,onChange:e=>U(e.target.value),placeholder:"Add internal notes here...",className:"min-h-[100px] text-xs resize-none",disabled:W}),(0,le.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,le.jsx)(Yt,{variant:"default",size:"sm",onClick:async()=>{try{q(!0),await bw.updateInternalNotes(m,z),D(z),B(!1),U(""),i&&i(m,"notes_updated")}catch(e){f("Failed to update internal notes. Please try again.")}finally{q(!1)}},disabled:W,className:"h-6 px-2 text-xs",children:W?(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)("div",{className:"animate-spin rounded-full h-3 w-3 border-b-2 border-white mr-1"}),"Saving..."]}):(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(df.A,{className:"w-3 h-3 mr-1"}),"Save"]})}),(0,le.jsxs)(Yt,{variant:"outline",size:"sm",onClick:()=>{U(""),B(!1)},disabled:W,className:"h-6 px-2 text-xs",children:[(0,le.jsx)(Bt.A,{className:"w-3 h-3 mr-1"}),"Cancel"]})]})]}):(0,le.jsxs)("div",{className:"space-y-2",children:[M?(0,le.jsx)("div",{className:"p-2 bg-slate-50 rounded-lg border border-slate-200",children:(0,le.jsx)("p",{className:"text-xs text-slate-700 whitespace-pre-wrap",children:M})}):(0,le.jsx)("p",{className:"text-xs text-slate-500 italic",children:"No internal notes added."}),(0,le.jsxs)(Yt,{variant:"outline",size:"sm",onClick:()=>{U(M),B(!0)},className:"h-6 px-2 text-xs",children:[(0,le.jsx)(Ql.A,{className:"w-3 h-3 mr-1"}),M?"Edit Notes":"Add Notes"]})]})]})})]})})})]}),(0,le.jsx)(Pa,{open:S,onOpenChange:E,children:(0,le.jsxs)(Da,{className:"sm:max-w-md",children:[(0,le.jsx)(Fa,{children:(0,le.jsxs)(za,{className:"flex items-center",children:[(0,le.jsx)(sv.A,{className:"w-5 h-5 mr-2"}),X.assigned_to?"Reassign Ticket":"Assign Ticket"]})}),(0,le.jsxs)("div",{className:"space-y-4 py-4",children:[(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsx)(Ns,{htmlFor:"assignEmail",children:"Agent Email"}),(0,le.jsx)(fs,{id:"assignEmail",type:"email",value:I,onChange:e=>{T(e.target.value),P&&L("")},onKeyPress:e=>{"Enter"===e.key&&(e.preventDefault(),Q())},placeholder:"agent@base44.com",className:"w-full ".concat(P?"border-red-500":""),disabled:O}),P&&(0,le.jsx)("p",{className:"text-sm text-red-600",children:P}),(0,le.jsx)("p",{className:"text-xs text-slate-500",children:"Email must be from @base44.com or @wix.com domain"})]}),X.assigned_to&&(0,le.jsxs)("div",{className:"p-3 bg-slate-50 rounded-lg",children:[(0,le.jsx)("p",{className:"text-xs text-slate-600 mb-1",children:"Currently assigned to:"}),(0,le.jsx)("p",{className:"text-sm font-medium text-slate-900",children:X.assigned_to})]})]}),(0,le.jsxs)("div",{className:"flex justify-end space-x-3",children:[(0,le.jsx)(Yt,{variant:"outline",onClick:()=>{T(""),L(""),E(!1)},disabled:O,children:"Cancel"}),(0,le.jsx)(Yt,{onClick:Q,disabled:O||!I.trim(),children:O?(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)("div",{className:"w-4 h-4 border-2 border-white border-t-transparent rounded-full animate-spin mr-2"}),"Assigning..."]}):(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(ly.A,{className:"w-4 h-4 mr-2"}),X.assigned_to?"Reassign":"Assign"," Ticket"]})})]})]})})]})}const b_=e=>{var t,s,a,n,l,r,i,o;let{filters:c,onFilterChange:d,onClearFilters:m,ticketCounts:u,searchQuery:x,onSearchChange:h,showResolved:p,onShowResolvedChange:g}=e;const f=[{value:"",label:"Open Only",count:u.total-u.resolved},{value:"admin",label:"Pending Admin",count:u.pending_admin},{value:"user",label:"Pending User",count:u.pending_user},{value:"resolved",label:"Resolved Only",count:u.resolved},{value:"all",label:"All Tickets",count:u.total}],v=[{value:"",label:"All",count:u.total},{value:"authentication",label:"Auth",count:(null===(t=u.category)||void 0===t?void 0:t.authentication)||0},{value:"billing",label:"Billing",count:(null===(s=u.category)||void 0===s?void 0:s.billing)||0},{value:"bug_report",label:"Bugs",count:(null===(a=u.category)||void 0===a?void 0:a.bug_report)||0},{value:"integrations_and_backend_functions",label:"Integrations",count:(null===(n=u.category)||void 0===n?void 0:n.integrations_and_backend_functions)||0},{value:"chat_issues",label:"Chat",count:(null===(l=u.category)||void 0===l?void 0:l.chat_issues)||0},{value:"security",label:"Security",count:(null===(r=u.category)||void 0===r?void 0:r.security)||0},{value:"other",label:"Other",count:(null===(i=u.category)||void 0===i?void 0:i.other)||0}],b=[{value:"",label:"All Assigned",count:u.total},{value:"unassigned",label:"Unassigned",count:(null===(o=u.assigned_to)||void 0===o?void 0:o.unassigned)||0},...Object.entries(u.assigned_to||{}).filter(e=>{let[t]=e;return"unassigned"!==t}).map(e=>{let[t,s]=e;return{value:t,label:t.split("@")[0],count:s}})];return(0,le.jsxs)("div",{className:"w-full h-full bg-white border-r border-slate-200 flex flex-col",children:[(0,le.jsx)("div",{className:"flex-shrink-0 p-3 border-b border-slate-100",children:(0,le.jsxs)("div",{className:"relative",children:[(0,le.jsx)(vn.A,{className:"absolute left-2 top-1/2 transform -translate-y-1/2 text-slate-400 w-3 h-3"}),(0,le.jsx)(fs,{placeholder:"Search...",value:x,onChange:e=>h(e.target.value),className:"pl-7 text-xs h-8"})]})}),(0,le.jsxs)("div",{className:"flex-1 overflow-y-auto p-3 space-y-4 text-xs",children:[(0,le.jsx)("div",{className:"space-y-2",children:(0,le.jsxs)("div",{className:"flex items-center space-x-2 p-2 bg-slate-50 rounded border",children:[(0,le.jsx)(dm,{id:"show-resolved",checked:p,onCheckedChange:g,className:"h-4 w-4"}),(0,le.jsx)("label",{htmlFor:"show-resolved",className:"text-xs font-medium text-slate-700 cursor-pointer flex-1",children:"Include resolved tickets"})]})}),(0,le.jsxs)("div",{className:"space-y-1",children:[(0,le.jsx)("h3",{className:"text-xs font-semibold text-slate-600 uppercase tracking-wide",children:"Pending Response"}),(0,le.jsx)("div",{className:"space-y-0.5",children:f.map(e=>(0,le.jsx)("button",{onClick:()=>d("status",c.status===e.value?"":e.value),className:"w-full text-left px-2 py-1 rounded text-xs transition-colors ".concat(c.status===e.value?"bg-teal-100 text-teal-800 font-medium":"text-slate-600 hover:bg-slate-50"),children:(0,le.jsxs)("div",{className:"flex items-center justify-between",children:[(0,le.jsx)("span",{className:"truncate",children:e.label}),void 0!==e.count&&(0,le.jsx)(es,{variant:"secondary",className:"text-xs h-4 px-1",children:e.count})]})},e.value))})]}),u.escalated>0&&(0,le.jsxs)("div",{className:"space-y-1",children:[(0,le.jsx)("h3",{className:"text-xs font-semibold text-slate-600 uppercase tracking-wide",children:"Priority"}),(0,le.jsx)("div",{className:"space-y-0.5",children:(0,le.jsx)("button",{onClick:()=>d("is_escalated",!0!==c.is_escalated||""),className:"w-full text-left px-2 py-1 rounded text-xs transition-colors ".concat(!0===c.is_escalated?"bg-red-100 text-red-800 font-medium":"text-slate-600 hover:bg-slate-50"),children:(0,le.jsxs)("div",{className:"flex items-center justify-between",children:[(0,le.jsxs)("div",{className:"flex items-center space-x-1",children:[(0,le.jsx)(ux.A,{className:"w-3 h-3"}),(0,le.jsx)("span",{className:"truncate",children:"Escalated"})]}),(0,le.jsx)(es,{variant:"secondary",className:"text-xs h-4 px-1",children:u.escalated})]})})})]}),(0,le.jsxs)("div",{className:"space-y-1",children:[(0,le.jsx)("h3",{className:"text-xs font-semibold text-slate-600 uppercase tracking-wide",children:"Assigned"}),(0,le.jsx)("div",{className:"space-y-0.5 max-h-32 overflow-y-auto",children:b.map(e=>(0,le.jsx)("button",{onClick:()=>d("assigned_to",c.assigned_to===e.value?"":e.value),className:"w-full text-left px-2 py-1 rounded text-xs transition-colors ".concat(c.assigned_to===e.value?"bg-blue-100 text-blue-800 font-medium":"text-slate-600 hover:bg-slate-50"),children:(0,le.jsxs)("div",{className:"flex items-center justify-between",children:[(0,le.jsx)("span",{className:"truncate",children:e.label}),void 0!==e.count&&(0,le.jsx)(es,{variant:"secondary",className:"text-xs h-4 px-1",children:e.count})]})},e.value))})]}),(0,le.jsxs)("div",{className:"space-y-1",children:[(0,le.jsx)("h3",{className:"text-xs font-semibold text-slate-600 uppercase tracking-wide",children:"Subscription"}),(0,le.jsxs)("div",{className:"space-y-0.5 max-h-32 overflow-y-auto",children:[(0,le.jsx)("button",{onClick:()=>d("user_subscription_tier",(c.user_subscription_tier,"")),className:"w-full text-left px-2 py-1 rounded text-xs transition-colors ".concat(""===c.user_subscription_tier?"bg-purple-100 text-purple-800 font-medium":"text-slate-600 hover:bg-slate-50"),children:(0,le.jsxs)("div",{className:"flex items-center justify-between",children:[(0,le.jsx)("span",{className:"truncate",children:"All Tiers"}),u.tier&&(0,le.jsx)(es,{variant:"secondary",className:"text-xs h-4 px-1",children:Object.values(u.tier).reduce((e,t)=>e+t,0)})]})}),Object.entries(d_).map(e=>{var t;let[s,a]=e;const n=(null===(t=u.tier)||void 0===t?void 0:t[s])||0;return 0===n?null:(0,le.jsx)("button",{onClick:()=>d("user_subscription_tier",c.user_subscription_tier===s?"":s),className:"w-full text-left px-2 py-1 rounded text-xs transition-colors ".concat(c.user_subscription_tier===s?"bg-purple-100 text-purple-800 font-medium":"text-slate-600 hover:bg-slate-50"),children:(0,le.jsxs)("div",{className:"flex items-center justify-between",children:[(0,le.jsx)("span",{className:"truncate",children:a.label}),(0,le.jsx)(es,{variant:"secondary",className:"text-xs h-4 px-1",children:n})]})},s)})]})]}),(0,le.jsxs)("div",{className:"space-y-1",children:[(0,le.jsx)("h3",{className:"text-xs font-semibold text-slate-600 uppercase tracking-wide",children:"Category"}),(0,le.jsx)("div",{className:"space-y-0.5",children:v.map(e=>(0,le.jsx)("button",{onClick:()=>d("category",c.category===e.value?"":e.value),className:"w-full text-left px-2 py-1 rounded text-xs transition-colors ".concat(c.category===e.value?"bg-orange-100 text-orange-800 font-medium":"text-slate-600 hover:bg-slate-50"),children:(0,le.jsxs)("div",{className:"flex items-center justify-between",children:[(0,le.jsx)("span",{className:"truncate",children:e.label}),void 0!==e.count&&(0,le.jsx)(es,{variant:"secondary",className:"text-xs h-4 px-1",children:e.count})]})},e.value))})]}),u.internal_categories&&Object.keys(u.internal_categories).length>0&&(0,le.jsxs)("div",{className:"space-y-1",children:[(0,le.jsx)("h3",{className:"text-xs font-semibold text-slate-600 uppercase tracking-wide",children:"Internal Categories"}),(0,le.jsx)("div",{className:"space-y-0.5 max-h-32 overflow-y-auto",children:Object.entries(u.internal_categories).map(e=>{let[t,s]=e;return(0,le.jsx)("button",{onClick:()=>d("internal_category",c.internal_category===t?"":t),className:"w-full text-left px-2 py-1 rounded text-xs transition-colors ".concat(c.internal_category===t?"bg-purple-100 text-purple-800 font-medium":"text-slate-600 hover:bg-slate-50"),children:(0,le.jsxs)("div",{className:"flex items-center justify-between",children:[(0,le.jsx)("span",{className:"truncate",children:t}),(0,le.jsx)(es,{variant:"secondary",className:"text-xs h-4 px-1",children:s})]})},t)})})]}),(c.status||c.category||c.assigned_to||c.internal_category||c.user_subscription_tier||c.is_escalated||x||p)&&(0,le.jsx)(Yt,{variant:"outline",size:"sm",onClick:m,className:"w-full text-xs h-7",children:"Clear Filters"})]})]})},j_=e=>{let{ticket:t,isSelected:s,onClick:a,onCheckboxToggle:n,showCheckbox:l,activeAgents:r,isCurrentUserViewing:i}=e;const o=c_[t.category],c=r||[];return(0,le.jsxs)("div",{className:"flex items-start p-3 border-b border-slate-100 transition-colors ".concat(s?"bg-teal-50 border-l-4 border-l-teal-500":"hover:bg-slate-50"),children:["resolved"!==t.ticket_status&&(0,le.jsx)("div",{className:"mr-3 mt-1",children:(0,le.jsx)(dm,{checked:l,onCheckedChange:e=>{n(t.id,e)},onClick:e=>e.stopPropagation(),className:"h-4 w-4"})}),(0,le.jsxs)("div",{onClick:()=>a(t),className:"flex-1 cursor-pointer space-y-1.5",children:[(0,le.jsxs)("div",{className:"flex items-start gap-1",children:[(0,le.jsx)("h4",{className:"font-medium text-slate-900 text-sm line-clamp-2 leading-tight flex-1",children:t.title}),t.is_escalated&&(0,le.jsx)(ux.A,{className:"w-3.5 h-3.5 text-red-500 flex-shrink-0 mt-0.5",title:"Escalated"})]}),(0,le.jsxs)("div",{className:"flex items-center justify-between text-xs text-slate-500",children:[(0,le.jsx)("span",{className:"truncate",children:t.created_by}),t.category&&(0,le.jsxs)("div",{className:"flex items-center space-x-1 flex-shrink-0 ml-2",children:[o&&(0,le.jsx)(o,{className:"w-3 h-3 text-slate-500"}),(0,le.jsx)("span",{className:"capitalize",children:"integrations_and_backend_functions"===t.category?"Integrations":t.category.replace("_"," ")})]})]}),(0,le.jsxs)("div",{className:"flex items-center justify-between text-xs text-slate-500",children:[(0,le.jsxs)("span",{children:[(0,le.jsx)("span",{className:"text-slate-400",children:"created:"})," ",ra().utc(t.created_date).fromNow()]}),t.last_agent_response_date&&(0,le.jsxs)("span",{children:[(0,le.jsx)("span",{className:"text-slate-400",children:"wait time:"})," ",ra().utc(t.last_agent_response_date).fromNow()]})]}),(0,le.jsxs)("div",{className:"flex items-center justify-between",children:[(0,le.jsx)("div",{className:"flex items-center space-x-2",children:t.pending_response_from?(0,le.jsx)(es,{variant:"secondary",className:"text-xs ".concat("admin"===t.pending_response_from?"bg-orange-100 text-orange-800 border-orange-200":"user"===t.pending_response_from?"bg-blue-100 text-blue-800 border-blue-200":"bg-gray-100 text-gray-800 border-gray-200"),children:"admin"===t.pending_response_from?"Pending Admin":"user"===t.pending_response_from?"Pending User":t.pending_response_from}):(0,le.jsx)(es,{variant:"secondary",className:"text-xs bg-green-100 text-green-800 border-green-200",children:"Resolved"})}),(0,le.jsx)("div",{className:"flex items-center space-x-2",children:(0,le.jsx)("span",{className:"text-xs text-slate-500",children:t.assigned_to?(0,le.jsxs)("span",{children:[(0,le.jsx)("span",{className:"text-slate-400",children:"assigned:"})," ",t.assigned_to.split("@")[0]]}):(0,le.jsx)("span",{className:"text-slate-400 italic",children:"Unassigned"})})})]}),(c.length>0||i)&&(0,le.jsxs)("div",{className:"mt-1.5 flex items-center space-x-1.5 bg-teal-50 rounded-md px-2 py-1",children:[(0,le.jsx)(hf.A,{className:"w-3 h-3 text-teal-600"}),(0,le.jsxs)("div",{className:"flex -space-x-2",children:[i&&(0,le.jsx)("div",{className:"relative inline-flex items-center justify-center w-5 h-5 bg-orange-500 text-white rounded-full ring-2 ring-teal-50 text-[10px] font-medium shadow-sm hover:z-10 transition-all",title:"You",children:"Me"}),c.slice(0,i?2:3).map((e,t)=>(0,le.jsx)("div",{className:"relative inline-flex items-center justify-center w-5 h-5 bg-teal-500 text-white rounded-full ring-2 ring-teal-50 text-xs font-medium shadow-sm hover:z-10 transition-all",title:e.name,children:e.name.split(" ").map(e=>e[0]).join("").toUpperCase().slice(0,2)},e.id)),c.length>(i?2:3)&&(0,le.jsxs)("div",{className:"relative inline-flex items-center justify-center w-5 h-5 bg-slate-400 text-white rounded-full ring-2 ring-teal-50 text-xs font-medium shadow-sm",title:"".concat(c.length-(i?2:3)," more agents viewing"),children:["+",c.length-(i?2:3)]})]}),(0,le.jsxs)("div",{className:"flex items-center space-x-1",children:[(0,le.jsx)("div",{className:"w-1.5 h-1.5 bg-teal-500 rounded-full animate-pulse"}),(0,le.jsx)("span",{className:"text-xs text-teal-700 font-medium",children:[...i?["You"]:[],...c.map(e=>e.name.split(" ")[0])].join(", ")})]})]})]})]})};function y_(){const{user:e}=oe(),t=(0,Z.Zp)(),[s]=(0,J.useSearchParams)(),a=s.get("conversationId"),[n,l]=(0,Y.useState)([]),[r,i]=(0,Y.useState)(!0),[o,c]=(0,Y.useState)(!1),[d,m]=(0,Y.useState)(null),[u,x]=(0,Y.useState)(""),[h,p]=(0,Y.useState)(null),[g,f]=(0,Y.useState)(new Set),[v,b]=(0,Y.useState)(!1),[j,y]=(0,Y.useState)("desc"),[N,w]=(0,Y.useState)("last_agent_response_date"),[_,k]=(0,Y.useState)(!1),[C,A]=(0,Y.useState)({}),[S,E]=(0,Y.useState)({status:"",category:"",user_subscription_tier:"",app_id:"",created_by:"",assigned_to:"",internal_category:"",is_escalated:""});(0,Y.useEffect)(()=>{I(!0)},[]),(0,Y.useEffect)(()=>{n.length>0&&I()},[_,N,j]),(0,Y.useEffect)(()=>{p(a||null)},[a]),(0,Y.useEffect)(()=>{if(h&&n.length>0){if(!n.find(e=>e.id===h)){p(null);const e=new URLSearchParams(window.location.search);e.delete("conversationId"),t("?".concat(e.toString()),{replace:!0})}}},[n,h,t]),(0,Y.useEffect)(()=>{const e=()=>{const e=new URLSearchParams(window.location.search).get("conversationId");if(e){n.find(t=>t.id===e)&&p(e)}else p(null)};return window.addEventListener("popstate",e),()=>window.removeEventListener("popstate",e)},[n]);const I=async function(){let e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];try{e?i(!0):c(!0),m(null);const t=await bw.getTickets({show_resolved:_,sort_field:N,sort_direction:j});l(t||[])}catch(t){m("Failed to load support tickets. Please try again.")}finally{i(!1),c(!1)}},T=e=>{p(e.id);const s=new URLSearchParams(window.location.search);s.set("conversationId",e.id),t("?".concat(s.toString()),{replace:!0})};(0,Y.useEffect)(()=>{let e=null;return(async()=>{e=await Aw.fetchAndSubscribe("realtime",e=>{if(e&&e.records){const t={};e.records.forEach(e=>{t[e.ticket_id]||(t[e.ticket_id]=[]),t[e.ticket_id].push({id:e.agent_user_id,name:e.agent_name,updatedAt:e.updated_date})}),A(t)}})})(),()=>{e&&e()}},[]),(0,Y.useEffect)(()=>{e&&e.id&&h?Aw.updateRecord(e.id,h):e&&e.id&&!h&&Aw.updateRecord(e.id,null)},[e,h]);const P=(e,t)=>{f(s=>{const a=new Set(s);return t?a.add(e):a.delete(e),a})},L=((e,t)=>{if(!t)return e;const s=t.toLowerCase();return e.filter(e=>{var t,a,n,l;return(null===(t=e.title)||void 0===t?void 0:t.toLowerCase().includes(s))||(null===(a=e.content)||void 0===a?void 0:a.toLowerCase().includes(s))||(null===(n=e.app_id)||void 0===n?void 0:n.toLowerCase().includes(s))||(null===(l=e.created_by)||void 0===l?void 0:l.toLowerCase().includes(s))})})((()=>{let e=n;return"resolved"===S.status?e=e.filter(e=>"resolved"===e.ticket_status):"all"===S.status||("admin"===S.status||"user"===S.status?e=e.filter(e=>"resolved"!==e.ticket_status&&e.pending_response_from===S.status):_&&(e=e.filter(e=>"resolved"!==e.ticket_status))),S.category&&(e=e.filter(e=>e.category===S.category)),S.user_subscription_tier&&(e=e.filter(e=>e.user_subscription_tier===S.user_subscription_tier)),S.assigned_to&&(e="unassigned"===S.assigned_to?e.filter(e=>!e.assigned_to):e.filter(e=>e.assigned_to===S.assigned_to)),S.internal_category&&(e=e.filter(e=>e.internal_categories&&e.internal_categories.includes(S.internal_category))),!0===S.is_escalated&&(e=e.filter(e=>!0===e.is_escalated)),e})(),u),O=[...L].sort((e,t)=>{let s=0;if("updated_date"===N||"created_date"===N||"last_agent_response_date"===N){s=new Date(e[N])-new Date(t[N])}else"subject"===N?s=(e.title||"").localeCompare(t.title||""):"category"===N?s=(e.category||"").localeCompare(t.category||""):"assigned_to"===N&&(s=(e.assigned_to||"").localeCompare(t.assigned_to||""));return"desc"===j?-s:s}),R=(e=>{const t={status:{},tier:{},category:{},assigned_to:{},internal_categories:{},escalated:0};return e.forEach(e=>{if("resolved"===e.ticket_status)return void(t.status.resolved=(t.status.resolved||0)+1);const s=e.pending_response_from;s&&(t.status[s]=(t.status[s]||0)+1);const a=e.user_subscription_tier||"free";t.tier[a]=(t.tier[a]||0)+1;const n=e.category;n&&(t.category[n]=(t.category[n]||0)+1);const l=e.assigned_to||"unassigned";t.assigned_to[l]=(t.assigned_to[l]||0)+1,!0===e.is_escalated&&t.escalated++,e.internal_categories&&Array.isArray(e.internal_categories)&&e.internal_categories.forEach(e=>{t.internal_categories[e]=(t.internal_categories[e]||0)+1})}),t.total=e.length,t.pending_admin=t.status.admin||0,t.pending_user=t.status.user||0,t.resolved=t.status.resolved||0,t})(n),M=h?n.find(e=>e.id===h):null;return r?(0,le.jsx)("div",{className:"h-screen flex items-center justify-center",children:(0,le.jsxs)("div",{className:"text-center",children:[(0,le.jsx)("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-slate-400 mx-auto mb-4"}),(0,le.jsx)("p",{className:"text-slate-600",children:"Loading conversations..."})]})}):d&&0===n.length?(0,le.jsx)(r_,{error:d,onRetry:()=>I(!0)}):(0,le.jsxs)("div",{className:"w-full h-screen bg-slate-50",children:[(0,le.jsx)("div",{className:"bg-white border-b border-slate-200 px-4 md:px-6 py-3 relative z-10",children:(0,le.jsxs)("div",{className:"flex items-center justify-between flex-wrap gap-2",children:[(0,le.jsxs)("div",{className:"flex items-center space-x-2 md:space-x-4",children:[(0,le.jsx)("h1",{className:"text-lg md:text-xl font-semibold text-slate-900",children:"Support Admin"}),(0,le.jsxs)("span",{className:"text-xs md:text-sm text-slate-500",children:[O.length," conversations"]}),o&&(0,le.jsxs)("div",{className:"flex items-center space-x-2 text-sm text-slate-500",children:[(0,le.jsx)("div",{className:"animate-spin rounded-full h-3 w-3 border-b-2 border-slate-400"}),(0,le.jsx)("span",{children:"Refreshing..."})]})]}),(0,le.jsxs)("div",{className:"flex items-center space-x-2",children:[g.size>0&&(0,le.jsxs)(Yt,{onClick:async()=>{if(0===g.size)return;const e="Are you sure you want to resolve ".concat(g.size," ticket").concat(g.size>1?"s":"","?");if(window.confirm(e))try{b(!0);const e=Array.from(g),s=await bw.resolveMany(e);if(s.resolved&&s.resolved.length>0){var t;f(new Set),await I();const e=s.resolved.length,a=(null===(t=s.errors)||void 0===t?void 0:t.length)||0;let n="Successfully resolved ".concat(e," ticket").concat(e>1?"s":"");a>0&&(n+=" (".concat(a," failed)")),alert(n)}}catch(s){alert("Failed to resolve tickets. Please try again.")}finally{b(!1)}},disabled:v,variant:"default",size:"sm",className:"bg-green-600 hover:bg-green-700",children:[v?(0,le.jsx)("div",{className:"animate-spin rounded-full h-4 w-4 border-b-2 border-white mr-2"}):(0,le.jsx)(pr.A,{className:"w-4 h-4 mr-2"}),"Resolve ",g.size," ticket",g.size>1?"s":""]}),(0,le.jsxs)(Yt,{onClick:()=>t("/support/admin/agent-backoffice"),variant:"outline",size:"sm",children:[(0,le.jsx)(vm.A,{className:"w-4 h-4 mr-2"}),"AI Settings"]}),(0,le.jsxs)(Yt,{onClick:()=>I(),variant:"outline",size:"sm",disabled:o,children:[(0,le.jsx)(nx.A,{className:"w-4 h-4 mr-2 ".concat(o?"animate-spin":"")}),"Refresh"]})]})]})}),(0,le.jsxs)(Mm,{direction:"horizontal",style:{height:"calc(100vh - 80px)"},children:[(0,le.jsx)(Dm,{defaultSize:8,minSize:5,maxSize:25,className:"hidden md:block",children:(0,le.jsx)(b_,{filters:S,onFilterChange:(e,t)=>{E(s=>(0,K.A)((0,K.A)({},s),{},{[e]:"all"===t?"":t}))},onClearFilters:()=>{E({status:"",category:"",user_subscription_tier:"",app_id:"",created_by:"",assigned_to:"",internal_category:"",is_escalated:""}),x(""),k(!1)},ticketCounts:R,searchQuery:u,onSearchChange:x,showResolved:_,onShowResolvedChange:k})}),(0,le.jsx)(Fm,{withHandle:!0,className:"hidden md:flex group transition-opacity opacity-0 hover:opacity-100 focus:opacity-100"}),(0,le.jsxs)(Dm,{defaultSize:10,minSize:5,maxSize:40,className:"bg-white border-r border-slate-200 flex flex-col",children:[O.some(e=>"resolved"!==e.ticket_status)&&(0,le.jsxs)("div",{className:"flex-shrink-0 bg-white border-b border-slate-200 p-3 flex items-center justify-between",children:[(0,le.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,le.jsx)(dm,{checked:g.size>0&&g.size===O.filter(e=>"resolved"!==e.ticket_status).length,onCheckedChange:()=>{const e=O.filter(e=>"resolved"!==e.ticket_status);g.size===e.length?f(new Set):f(new Set(e.map(e=>e.id)))},className:"h-4 w-4"}),(0,le.jsx)("span",{className:"text-xs text-slate-600",children:"Select all open tickets"})]}),(0,le.jsxs)("div",{className:"flex items-center space-x-1 text-xs text-slate-500",children:[(0,le.jsx)("span",{children:"Sort:"}),(0,le.jsxs)("select",{value:N,onChange:e=>w(e.target.value),className:"bg-transparent border-none text-xs text-slate-600 focus:outline-none",children:[(0,le.jsx)("option",{value:"last_agent_response_date",children:"Wait Time"}),(0,le.jsx)("option",{value:"updated_date",children:"Updated"}),(0,le.jsx)("option",{value:"created_date",children:"Created"}),(0,le.jsx)("option",{value:"subject",children:"Subject"}),(0,le.jsx)("option",{value:"category",children:"Category"}),(0,le.jsx)("option",{value:"assigned_to",children:"Assigned"})]}),(0,le.jsx)(Yt,{onClick:()=>y("desc"===j?"asc":"desc"),variant:"ghost",size:"sm",className:"h-5 w-5 p-0",children:"desc"===j?(0,le.jsx)(kd.A,{className:"w-3 h-3"}):(0,le.jsx)(Dt.A,{className:"w-3 h-3"})})]})]}),(0,le.jsx)("div",{className:"flex-1 overflow-y-auto",children:0===L.length?(0,le.jsx)("div",{className:"p-8 text-center text-slate-500",children:(0,le.jsx)("p",{children:"No conversations found"})}):(0,le.jsx)("div",{children:O.map(e=>(0,le.jsx)(j_,{ticket:e,isSelected:h===e.id,onClick:T,onCheckboxToggle:P,showCheckbox:g.has(e.id),activeAgents:C[e.id],isCurrentUserViewing:h===e.id},e.id))})})]}),(0,le.jsx)(Fm,{withHandle:!0,className:"group transition-opacity opacity-0 hover:opacity-100 focus:opacity-100"}),(0,le.jsx)(Dm,{defaultSize:50,minSize:10,className:"bg-white min-w-0 overflow-hidden",children:M?(0,le.jsx)(v_,{conversationId:h,isEmbedded:!0,onTicketUpdated:(e,t,s,a)=>{l(n=>n.map(n=>{if(n.id===e){if(a){let e="admin";if(a.messages&&a.messages.length>0){e="user"===a.messages[a.messages.length-1].role?"admin":"user"}return(0,K.A)((0,K.A)((0,K.A)({},n),a),{},{pending_response_from:e,updated_date:(new Date).toISOString()})}if("assigned"===t)return(0,K.A)((0,K.A)({},n),{},{assigned_to:s,updated_date:(new Date).toISOString()});if("categories_updated"===t)return(0,K.A)((0,K.A)({},n),{},{updated_date:(new Date).toISOString()});if("message_sent"===t){const e="admin"===s;return(0,K.A)((0,K.A)({},n),{},{pending_response_from:e?"user":"admin",updated_date:(new Date).toISOString()})}return"ticket_closed"===t?(0,K.A)((0,K.A)({},n),{},{ticket_status:"resolved",updated_date:(new Date).toISOString()}):(0,K.A)((0,K.A)({},n),{},{ticket_status:t,updated_date:(new Date).toISOString()})}return n}))}}):(0,le.jsx)("div",{className:"h-full flex items-center justify-center text-slate-500 p-4",children:(0,le.jsxs)("div",{className:"text-center max-w-md",children:[(0,le.jsx)("div",{className:"w-16 h-16 bg-slate-100 rounded-full flex items-center justify-center mx-auto mb-4",children:(0,le.jsx)(vm.A,{className:"w-8 h-8"})}),(0,le.jsx)("h3",{className:"text-lg font-medium text-slate-900 mb-2",children:"Select a conversation"}),(0,le.jsx)("p",{className:"text-slate-600 text-sm",children:"Choose a support ticket from the list to view details and respond"})]})})})]})]})}const N_=e=>{if(!e)return"Not available";const t=ra().utc(e);return"".concat(t.format("MMM DD, YYYY")," (").concat(t.fromNow(),")")},w_=e=>{let{article:t,onEdit:s,onDelete:a}=e;return(0,le.jsxs)(is,{className:"group hover:shadow-lg transition-all duration-300 border-slate-200 hover:border-slate-300",children:[(0,le.jsx)(os,{className:"pb-3",children:(0,le.jsxs)("div",{className:"flex items-start justify-between",children:[(0,le.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,le.jsx)(cs,{className:"text-lg font-semibold text-slate-900 truncate group-hover:text-slate-700 transition-colors",children:t.title}),(0,le.jsxs)("div",{className:"flex items-center space-x-2 mt-2",children:[(0,le.jsxs)(es,{variant:"outline",className:"text-xs",children:[(0,le.jsx)(hr.A,{className:"w-3 h-3 mr-1"}),"Article"]}),t.created_date&&(0,le.jsxs)("span",{className:"text-xs text-slate-500",children:["Created ",N_(t.created_date)]})]})]}),(0,le.jsxs)("div",{className:"flex items-center space-x-2 ml-4",children:[(0,le.jsx)(Yt,{variant:"ghost",size:"sm",onClick:()=>s(t),className:"opacity-0 group-hover:opacity-100 transition-opacity",children:(0,le.jsx)(Ql.A,{className:"w-4 h-4"})}),(0,le.jsx)(Yt,{variant:"ghost",size:"sm",onClick:()=>a(t),className:"opacity-0 group-hover:opacity-100 transition-opacity text-red-600 hover:text-red-800",children:(0,le.jsx)(Ip.A,{className:"w-4 h-4"})})]})]})}),(0,le.jsx)(ms,{className:"pt-0",children:(0,le.jsx)("p",{className:"text-slate-600 text-sm leading-relaxed line-clamp-3",children:t.content||"No content available"})})]})},__=e=>{let{article:t,isOpen:s,onClose:a,onSave:n,isCreating:l}=e;const[r,i]=(0,Y.useState)(""),[o,c]=(0,Y.useState)(""),[d,m]=(0,Y.useState)(!1);(0,Y.useEffect)(()=>{t?(i(t.title||""),c(t.content||"")):(i(""),c(""))},[t,s]);return(0,le.jsx)(Pa,{open:s,onOpenChange:a,children:(0,le.jsxs)(Da,{className:"max-w-4xl max-h-[80vh] overflow-y-auto",children:[(0,le.jsx)(Fa,{children:(0,le.jsxs)(za,{className:"flex items-center",children:[(0,le.jsx)(hr.A,{className:"w-5 h-5 mr-2"}),l?"Create New Article":"Edit Article"]})}),(0,le.jsxs)("div",{className:"space-y-6 py-4",children:[(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsx)(Ns,{htmlFor:"title",children:"Title"}),(0,le.jsx)(fs,{id:"title",value:r,onChange:e=>i(e.target.value),placeholder:"Enter article title...",className:"w-full"})]}),(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsx)(Ns,{htmlFor:"content",children:"Content"}),(0,le.jsx)(um,{id:"content",value:o,onChange:e=>c(e.target.value),placeholder:"Enter article content...",className:"min-h-[400px] resize-none"}),(0,le.jsx)("p",{className:"text-xs text-slate-500",children:"You can use markdown formatting for better presentation."})]}),(0,le.jsxs)("div",{className:"flex justify-end space-x-3",children:[(0,le.jsx)(Yt,{variant:"outline",onClick:a,children:"Cancel"}),(0,le.jsx)(Yt,{onClick:async()=>{if(r.trim()&&o.trim()){m(!0);try{await n({id:null==t?void 0:t.id,title:r.trim(),content:o.trim()}),a()}catch(e){}finally{m(!1)}}},disabled:d||!r.trim()||!o.trim(),children:d?(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)("div",{className:"w-4 h-4 border-2 border-white border-t-transparent rounded-full animate-spin mr-2"}),"Saving..."]}):(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(df.A,{className:"w-4 h-4 mr-2"}),l?"Create Article":"Save Changes"]})})]})]})]})})},k_=e=>{let{categories:t,onSave:s}=e;const[a,n]=(0,Y.useState)([]),[l,r]=(0,Y.useState)(""),[i,o]=(0,Y.useState)(!1),[c,d]=(0,Y.useState)(!1);(0,Y.useEffect)(()=>{n(t||[])},[t]);const m=()=>{const e=l.trim();e&&!a.includes(e)&&(n([...a,e]),r(""))};return(0,le.jsxs)(is,{children:[(0,le.jsx)(os,{children:(0,le.jsxs)("div",{className:"flex items-center justify-between",children:[(0,le.jsxs)(cs,{className:"flex items-center",children:[(0,le.jsx)(pw.A,{className:"w-5 h-5 mr-2"}),"Internal Category Options"]}),!i&&(0,le.jsxs)(Yt,{variant:"outline",size:"sm",onClick:()=>o(!0),children:[(0,le.jsx)(Ql.A,{className:"w-4 h-4 mr-2"}),"Edit"]})]})}),(0,le.jsx)(ms,{children:i?(0,le.jsxs)("div",{className:"space-y-4",children:[(0,le.jsxs)("div",{className:"space-y-3",children:[(0,le.jsxs)("div",{className:"flex space-x-2",children:[(0,le.jsx)(fs,{value:l,onChange:e=>r(e.target.value),placeholder:"Add new internal category...",onKeyPress:e=>{"Enter"===e.key&&(e.preventDefault(),m())},className:"flex-1"}),(0,le.jsx)(Yt,{onClick:m,disabled:!l.trim(),children:(0,le.jsx)(kt.A,{className:"w-4 h-4"})})]}),(0,le.jsxs)("div",{className:"space-y-2 max-h-48 overflow-y-auto",children:[a.map((e,t)=>(0,le.jsxs)("div",{className:"flex items-center justify-between p-2 bg-slate-50 rounded-lg",children:[(0,le.jsx)("span",{className:"text-sm text-slate-700",children:e}),(0,le.jsx)(Yt,{variant:"ghost",size:"sm",onClick:()=>{return t=e,void n(a.filter(e=>e!==t));var t},className:"text-red-600 hover:text-red-800 h-6 w-6 p-0",children:(0,le.jsx)(Bt.A,{className:"w-3 h-3"})})]},t)),0===a.length&&(0,le.jsx)("p",{className:"text-sm text-slate-500 text-center py-4",children:"No internal categories defined yet"})]})]}),(0,le.jsxs)("div",{className:"flex justify-end space-x-3",children:[(0,le.jsxs)(Yt,{variant:"outline",onClick:()=>{n(t||[]),r(""),o(!1)},children:[(0,le.jsx)(Bt.A,{className:"w-4 h-4 mr-2"}),"Cancel"]}),(0,le.jsx)(Yt,{onClick:async()=>{d(!0);try{await s(a),o(!1)}catch(e){}finally{d(!1)}},disabled:c,children:c?(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)("div",{className:"w-4 h-4 border-2 border-white border-t-transparent rounded-full animate-spin mr-2"}),"Saving..."]}):(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(df.A,{className:"w-4 h-4 mr-2"}),"Save Categories"]})})]})]}):(0,le.jsxs)("div",{className:"space-y-3",children:[(0,le.jsx)("div",{className:"flex flex-wrap gap-2",children:a.length>0?a.map((e,t)=>(0,le.jsxs)(es,{variant:"outline",className:"text-xs",children:[(0,le.jsx)(pw.A,{className:"w-3 h-3 mr-1"}),e]},t)):(0,le.jsx)("div",{className:"text-sm text-slate-500 bg-slate-50 rounded-lg p-4 text-center w-full",children:"No internal categories defined yet"})}),(0,le.jsx)("p",{className:"text-xs text-slate-500",children:"These categories can be assigned to support tickets for internal organization and tracking."})]})})]})},C_=e=>{let{title:t,systemPrompt:s,onSave:a,promptKey:n}=e;const[l,r]=(0,Y.useState)(""),[i,o]=(0,Y.useState)(!1),[c,d]=(0,Y.useState)(!1);(0,Y.useEffect)(()=>{r(s||"")},[s]);return(0,le.jsxs)(is,{children:[(0,le.jsx)(os,{children:(0,le.jsxs)("div",{className:"flex items-center justify-between",children:[(0,le.jsxs)(cs,{className:"flex items-center",children:[(0,le.jsx)(Oi.A,{className:"w-5 h-5 mr-2"}),t]}),!i&&(0,le.jsxs)(Yt,{variant:"outline",size:"sm",onClick:()=>o(!0),children:[(0,le.jsx)(Ql.A,{className:"w-4 h-4 mr-2"}),"Edit"]})]})}),(0,le.jsx)(ms,{children:i?(0,le.jsxs)("div",{className:"space-y-4",children:[(0,le.jsx)(um,{value:l,onChange:e=>r(e.target.value),placeholder:"Enter ".concat(t.toLowerCase()," for AI assistance..."),className:"min-h-[200px] resize-none"}),(0,le.jsxs)("div",{className:"flex justify-end space-x-3",children:[(0,le.jsxs)(Yt,{variant:"outline",onClick:()=>{r(s||""),o(!1)},children:[(0,le.jsx)(Bt.A,{className:"w-4 h-4 mr-2"}),"Cancel"]}),(0,le.jsx)(Yt,{onClick:async()=>{d(!0);try{await a(n,l),o(!1)}catch(e){}finally{d(!1)}},disabled:c,children:c?(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)("div",{className:"w-4 h-4 border-2 border-white border-t-transparent rounded-full animate-spin mr-2"}),"Saving..."]}):(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(df.A,{className:"w-4 h-4 mr-2"}),"Save Prompt"]})})]})]}):(0,le.jsxs)("div",{className:"space-y-3",children:[(0,le.jsx)("div",{className:"bg-slate-50 rounded-lg p-4 border",children:(0,le.jsx)("pre",{className:"whitespace-pre-wrap text-sm text-slate-700 font-sans leading-relaxed",children:l||"No ".concat(t.toLowerCase()," configured")})}),(0,le.jsx)("p",{className:"text-xs text-slate-500",children:"response_system_prompt"===n?"This prompt guides the AI when responding to support questions.":"This prompt guides the AI when polishing and improving message grammar."})]})})]})},A_="support_templates",S_=()=>{try{const e=localStorage.getItem(A_);return e?JSON.parse(e):[]}catch(e){return[]}},E_=e=>{try{localStorage.setItem(A_,JSON.stringify(e)),window.dispatchEvent(new CustomEvent("templatesUpdated"))}catch(t){}},I_=e=>{let{onTemplateUpdated:t}=e;const[s,a]=(0,Y.useState)([]),[n,l]=(0,Y.useState)(null),[r,i]=(0,Y.useState)(!1),[o,c]=(0,Y.useState)(""),[d,m]=(0,Y.useState)(""),[u,x]=(0,Y.useState)(!1),[h,p]=(0,Y.useState)(null);(0,Y.useEffect)(()=>{a(S_())},[]);const g=()=>{l(null),i(!0),c(""),m("")};return(0,le.jsxs)("div",{className:"space-y-6",children:[(r||n)&&(0,le.jsxs)(is,{children:[(0,le.jsx)(os,{children:(0,le.jsxs)(cs,{className:"flex items-center",children:[(0,le.jsx)(hr.A,{className:"w-5 h-5 mr-2"}),r?"Create New Template":"Edit Template"]})}),(0,le.jsxs)(ms,{className:"space-y-4",children:[(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsx)(Ns,{htmlFor:"templateName",children:"Template Name"}),(0,le.jsx)(fs,{id:"templateName",value:o,onChange:e=>c(e.target.value),placeholder:"Enter template name...",className:"w-full"})]}),(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsx)(Ns,{htmlFor:"templateContent",children:"Template Content"}),(0,le.jsx)(um,{id:"templateContent",value:d,onChange:e=>m(e.target.value),placeholder:"Enter template content...",className:"min-h-[200px] resize-none"})]}),(0,le.jsxs)("div",{className:"flex justify-end space-x-3",children:[(0,le.jsxs)(Yt,{variant:"outline",onClick:()=>{l(null),i(!1),c(""),m("")},children:[(0,le.jsx)(Bt.A,{className:"w-4 h-4 mr-2"}),"Cancel"]}),(0,le.jsx)(Yt,{onClick:async()=>{if(o.trim()&&d.trim()){x(!0);try{const e={id:(null==n?void 0:n.id)||Date.now().toString(),name:o.trim(),content:d.trim(),created_date:(null==n?void 0:n.created_date)||(new Date).toISOString(),updated_date:(new Date).toISOString()},r=n?s.map(t=>t.id===n.id?e:t):[...s,e];a(r),E_(r),l(null),i(!1),c(""),m(""),t&&t(r)}catch(e){}finally{x(!1)}}},disabled:u||!o.trim()||!d.trim(),children:u?(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)("div",{className:"w-4 h-4 border-2 border-white border-t-transparent rounded-full animate-spin mr-2"}),"Saving..."]}):(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(df.A,{className:"w-4 h-4 mr-2"}),r?"Create Template":"Save Changes"]})})]})]})]}),(0,le.jsxs)(is,{children:[(0,le.jsx)(os,{children:(0,le.jsxs)("div",{className:"flex items-center justify-between",children:[(0,le.jsxs)(cs,{className:"flex items-center",children:[(0,le.jsx)(hr.A,{className:"w-5 h-5 mr-2"}),"Response Templates (",s.length,")"]}),!r&&!n&&(0,le.jsxs)(Yt,{onClick:g,children:[(0,le.jsx)(kt.A,{className:"w-4 h-4 mr-2"}),"New Template"]})]})}),(0,le.jsx)(ms,{children:0===s.length?(0,le.jsxs)("div",{className:"text-center py-8",children:[(0,le.jsx)("div",{className:"mx-auto w-16 h-16 bg-slate-100 rounded-full flex items-center justify-center mb-4",children:(0,le.jsx)(hr.A,{className:"w-8 h-8 text-slate-400"})}),(0,le.jsx)("h3",{className:"text-lg font-medium text-slate-900 mb-2",children:"No Templates Yet"}),(0,le.jsx)("p",{className:"text-slate-600 mb-4",children:"Create reusable response templates to speed up your workflow."}),(0,le.jsxs)(Yt,{onClick:g,children:[(0,le.jsx)(kt.A,{className:"w-4 h-4 mr-2"}),"Create First Template"]})]}):(0,le.jsx)("div",{className:"space-y-3",children:s.map(e=>(0,le.jsxs)("div",{className:"border border-slate-200 rounded-lg p-4 hover:bg-slate-50 transition-colors",children:[(0,le.jsxs)("div",{className:"flex items-start justify-between mb-2",children:[(0,le.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,le.jsx)("h4",{className:"text-sm font-medium text-slate-900 truncate",children:e.name}),(0,le.jsxs)("p",{className:"text-xs text-slate-500 mt-1",children:["Created ",N_(e.created_date),e.updated_date!==e.created_date&&(0,le.jsxs)("span",{children:[" \u2022 Updated ",N_(e.updated_date)]})]})]}),(0,le.jsxs)("div",{className:"flex items-center space-x-2 ml-4",children:[(0,le.jsx)(Yt,{variant:"ghost",size:"sm",onClick:()=>(e=>{l(e),i(!1),c(e.name),m(e.content)})(e),className:"h-8 w-8 p-0",children:(0,le.jsx)(Ql.A,{className:"w-4 h-4"})}),(0,le.jsx)(Yt,{variant:"ghost",size:"sm",onClick:()=>(e=>{p(e)})(e),className:"h-8 w-8 p-0 text-red-600 hover:text-red-800",children:(0,le.jsx)(Ip.A,{className:"w-4 h-4"})})]})]}),(0,le.jsx)("div",{className:"text-sm text-slate-600 bg-slate-50 rounded p-3 border",children:(0,le.jsx)("div",{className:"line-clamp-3",children:e.content})})]},e.id))})})]}),(0,le.jsx)(Pa,{open:!!h,onOpenChange:()=>p(null),children:(0,le.jsxs)(Da,{children:[(0,le.jsx)(Fa,{children:(0,le.jsxs)(za,{className:"flex items-center text-red-600",children:[(0,le.jsx)(_e.A,{className:"w-5 h-5 mr-2"}),"Delete Template"]})}),(0,le.jsx)("div",{className:"py-4",children:(0,le.jsxs)("p",{className:"text-slate-600",children:['Are you sure you want to delete the template "',null==h?void 0:h.name,'"? This action cannot be undone.']})}),(0,le.jsxs)("div",{className:"flex justify-end space-x-3",children:[(0,le.jsx)(Yt,{variant:"outline",onClick:()=>p(null),children:"Cancel"}),(0,le.jsxs)(Yt,{variant:"destructive",onClick:()=>{if(h){const e=s.filter(e=>e.id!==h.id);a(e),E_(e),p(null),t&&t(e)}},children:[(0,le.jsx)(Ip.A,{className:"w-4 h-4 mr-2"}),"Delete Template"]})]})]})})]})};function T_(){const e=(0,Z.Zp)(),[t,s]=(0,Y.useState)([]),[a,n]=(0,Y.useState)(""),[l,r]=(0,Y.useState)(""),[i,o]=(0,Y.useState)([]),[c,d]=(0,Y.useState)([]),[m,u]=(0,Y.useState)(!0),[x,h]=(0,Y.useState)(null),[p,g]=(0,Y.useState)(""),[f,v]=(0,Y.useState)(null),[b,j]=(0,Y.useState)(!1),[y,N]=(0,Y.useState)(!1),[w,_]=(0,Y.useState)(null);(0,Y.useEffect)(()=>{k(),d(S_())},[]);const k=async()=>{try{u(!0),h(null);const[e,t]=await Promise.all([yw.getArticles(),yw.getAgentProperties()]);s((null==e?void 0:e.articles)||e||[]),n((null==t?void 0:t.response_system_prompt)||""),r((null==t?void 0:t.polish_system_prompt)||""),o((null==t?void 0:t.internal_category_options)||[])}catch(e){h("Failed to load documentation data. Please try again.")}finally{u(!1)}},C=()=>{v(null),N(!0),j(!0)},A=e=>{v(e),N(!1),j(!0)},S=e=>{_(e)},E=async(e,t)=>{const s={};s[e]=t,await yw.updateAgentProperties(s),"response_system_prompt"===e?n(t):"polish_system_prompt"===e&&r(t)},I=t.filter(e=>{var t,s;return(null===(t=e.title)||void 0===t?void 0:t.toLowerCase().includes(p.toLowerCase()))||(null===(s=e.content)||void 0===s?void 0:s.toLowerCase().includes(p.toLowerCase()))});return m?(0,le.jsx)("div",{className:"w-full max-w-7xl mx-auto px-6 py-12",children:(0,le.jsxs)("div",{className:"animate-pulse space-y-6",children:[(0,le.jsx)("div",{className:"h-8 bg-slate-200 rounded w-1/3"}),(0,le.jsxs)("div",{className:"grid grid-cols-1 gap-6",children:[(0,le.jsx)("div",{className:"h-48 bg-slate-200 rounded-lg"}),(0,le.jsx)("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:[1,2,3,4,5,6].map(e=>(0,le.jsx)("div",{className:"h-32 bg-slate-200 rounded-lg"},e))})]})]})}):x?(0,le.jsx)("div",{className:"w-full max-w-7xl mx-auto px-6 py-12",children:(0,le.jsxs)("div",{className:"text-center py-16",children:[(0,le.jsx)("div",{className:"mx-auto w-24 h-24 bg-red-100 rounded-full flex items-center justify-center mb-6",children:(0,le.jsx)(_e.A,{className:"w-12 h-12 text-red-500"})}),(0,le.jsx)("h3",{className:"text-xl font-semibold text-slate-900 mb-2",children:"Error Loading Documentation"}),(0,le.jsx)("p",{className:"text-slate-600 mb-6",children:x}),(0,le.jsx)(Yt,{onClick:k,variant:"outline",children:"Try Again"})]})}):(0,le.jsxs)("div",{className:"w-full max-w-7xl mx-auto px-6 py-12",children:[(0,le.jsx)("div",{className:"mb-8",children:(0,le.jsxs)("div",{className:"flex items-center justify-between mb-6",children:[(0,le.jsxs)("div",{className:"flex items-center space-x-4",children:[(0,le.jsxs)(Yt,{variant:"ghost",size:"sm",onClick:()=>e("/support/admin/conversations"),className:"text-slate-600 hover:text-slate-900",children:[(0,le.jsx)(Cd.A,{className:"w-4 h-4 mr-2"}),"Back to list"]}),(0,le.jsxs)("div",{children:[(0,le.jsx)("h1",{className:"text-3xl font-bold text-slate-900",children:"AI Settings"}),(0,le.jsx)("p",{className:"text-slate-600 mt-1",children:"Manage support articles and AI system prompts"})]})]}),(0,le.jsxs)("div",{className:"flex items-center space-x-3",children:[(0,le.jsxs)(Yt,{onClick:k,variant:"outline",size:"sm",children:[(0,le.jsx)(nx.A,{className:"w-4 h-4 mr-2"}),"Refresh"]}),(0,le.jsxs)(Yt,{onClick:C,children:[(0,le.jsx)(kt.A,{className:"w-4 h-4 mr-2"}),"New Article"]})]})]})}),(0,le.jsxs)(kr,{defaultValue:"articles",className:"space-y-6",children:[(0,le.jsxs)(Cr,{className:"grid w-full grid-cols-4 lg:w-[800px]",children:[(0,le.jsxs)(Ar,{value:"articles",className:"flex items-center space-x-2",children:[(0,le.jsx)(Su.A,{className:"w-4 h-4"}),(0,le.jsxs)("span",{children:["Articles (",t.length,")"]})]}),(0,le.jsxs)(Ar,{value:"system-prompts",className:"flex items-center space-x-2",children:[(0,le.jsx)(vm.A,{className:"w-4 h-4"}),(0,le.jsx)("span",{children:"System Prompts"})]}),(0,le.jsxs)(Ar,{value:"templates",className:"flex items-center space-x-2",children:[(0,le.jsx)(hr.A,{className:"w-4 h-4"}),(0,le.jsx)("span",{children:"Templates"})]}),(0,le.jsxs)(Ar,{value:"internal-categories",className:"flex items-center space-x-2",children:[(0,le.jsx)(pw.A,{className:"w-4 h-4"}),(0,le.jsx)("span",{children:"Categories"})]})]}),(0,le.jsxs)(Sr,{value:"articles",className:"space-y-6",children:[(0,le.jsx)("div",{className:"flex items-center space-x-4",children:(0,le.jsxs)("div",{className:"relative flex-1 max-w-md",children:[(0,le.jsx)(vn.A,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 text-slate-400 w-4 h-4"}),(0,le.jsx)(fs,{placeholder:"Search articles...",value:p,onChange:e=>g(e.target.value),className:"pl-10"})]})}),0===I.length?(0,le.jsxs)("div",{className:"text-center py-16",children:[(0,le.jsx)("div",{className:"mx-auto w-24 h-24 bg-slate-100 rounded-full flex items-center justify-center mb-6",children:(0,le.jsx)(hr.A,{className:"w-12 h-12 text-slate-400"})}),(0,le.jsx)("h3",{className:"text-xl font-semibold text-slate-900 mb-2",children:p?"No Articles Found":"No Articles Yet"}),(0,le.jsx)("p",{className:"text-slate-600 max-w-md mx-auto mb-6",children:p?"No articles match your search criteria. Try adjusting your search terms.":"Get started by creating your first support article."}),!p&&(0,le.jsxs)(Yt,{onClick:C,children:[(0,le.jsx)(kt.A,{className:"w-4 h-4 mr-2"}),"Create First Article"]})]}):(0,le.jsx)("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6",children:I.map(e=>(0,le.jsx)(w_,{article:e,onEdit:A,onDelete:S},e.id))})]}),(0,le.jsxs)(Sr,{value:"system-prompts",className:"space-y-6",children:[(0,le.jsx)(C_,{title:"Response System Prompt",systemPrompt:a,onSave:E,promptKey:"response_system_prompt"}),(0,le.jsx)(C_,{title:"Polish System Prompt",systemPrompt:l,onSave:E,promptKey:"polish_system_prompt"})]}),(0,le.jsx)(Sr,{value:"templates",className:"space-y-6",children:(0,le.jsx)(I_,{onTemplateUpdated:e=>{d(e)}})}),(0,le.jsx)(Sr,{value:"internal-categories",className:"space-y-6",children:(0,le.jsx)(k_,{categories:i,onSave:async e=>{await yw.updateAgentProperties({internal_category_options:e}),o(e)}})})]}),(0,le.jsx)(__,{article:f,isOpen:b,onClose:()=>j(!1),onSave:async e=>{y?await yw.createArticle(e):await yw.updateArticle(e.id,e),await k()},isCreating:y}),(0,le.jsx)(Pa,{open:!!w,onOpenChange:()=>_(null),children:(0,le.jsxs)(Da,{children:[(0,le.jsx)(Fa,{children:(0,le.jsxs)(za,{className:"flex items-center text-red-600",children:[(0,le.jsx)(_e.A,{className:"w-5 h-5 mr-2"}),"Delete Article"]})}),(0,le.jsx)("div",{className:"py-4",children:(0,le.jsxs)("p",{className:"text-slate-600",children:['Are you sure you want to delete "',null==w?void 0:w.title,'"? This action cannot be undone.']})}),(0,le.jsxs)("div",{className:"flex justify-end space-x-3",children:[(0,le.jsx)(Yt,{variant:"outline",onClick:()=>_(null),children:"Cancel"}),(0,le.jsxs)(Yt,{variant:"destructive",onClick:async()=>{if(w)try{await yw.deleteArticle(w.id),await k(),_(null)}catch(x){}},children:[(0,le.jsx)(Ip.A,{className:"w-4 h-4 mr-2"}),"Delete Article"]})]})]})})]})}var P_=s(57456);const L_=(0,Y.createContext)();function O_(e){var t;let{children:s,workspaceId:a}=e;const[n,l]=(0,Y.useState)(null),[r,i]=(0,Y.useState)(!0),[o,c]=(0,Y.useState)(null),[d,m]=(0,Y.useState)([]),[u,x]=(0,Y.useState)(!1),[h,p]=(0,Y.useState)(!1),[g,f]=(0,Y.useState)(null),v=(0,Y.useRef)(null),b=(0,Y.useCallback)(async()=>{try{i(!0),c(null);const e=await xe.getDashboard(a);l(e),v.current&&v.current(),v.current=xe.subscribeToDashboard(a,e,(t,s)=>{var a,n;const r=(0,K.A)((0,K.A)((0,K.A)({},e),t),{},{workspace:(0,K.A)((0,K.A)((0,K.A)({},e.workspace),t.workspace),{},{is_personal:void 0!==(null===(a=t.workspace)||void 0===a?void 0:a.is_personal)?t.workspace.is_personal:null===(n=e.workspace)||void 0===n?void 0:n.is_personal})});l(r)})}catch(e){c(e)}finally{i(!1)}},[a]),j=(0,Y.useCallback)(async()=>{try{const e=await xe.getAvailablePlans();m(e.plans||[])}catch(o){m([])}},[]),y=(0,Y.useCallback)(async()=>{await b()},[b]),N=(0,Y.useCallback)(()=>{var e;return!(null!=n&&null!==(e=n.workspace)&&void 0!==e&&e.is_personal)&&["owner","admin"].includes(null==n?void 0:n.user_role)},[n]),w=(0,Y.useCallback)(()=>["owner","admin"].includes(null==n?void 0:n.user_role),[n]),_=(0,Y.useCallback)(async(e,t)=>{x(!0);try{await xe.inviteUser(e,t,a)}catch(o){throw o}finally{x(!1)}},[a]),k=(0,Y.useCallback)(async(e,t)=>{x(!0);try{await xe.updateMemberRole(e,t,a)}catch(o){throw o}finally{x(!1)}},[a]),C=(0,Y.useCallback)(async(e,t)=>{x(!0);try{await xe.updateMemberSeat(e,t,a)}catch(o){throw o}finally{x(!1)}},[a]),A=(0,Y.useCallback)(e=>{f(e),p(!0)},[]),S=(0,Y.useCallback)(()=>{p(!1),f(null)},[]),E=(0,Y.useCallback)(async()=>{if(g){p(!1),x(!0);try{await xe.removeMember(g.email,a),f(null)}catch(o){throw o}finally{x(!1)}}},[g,a]),I=(0,Y.useCallback)(async(e,t,s)=>{x(!0);try{let l;if(l="buy"===s?await xe.buySeats(e,t,a):await xe.removeSeats(e,t,a),!l)throw new Error("Invalid response from server");if("stripe_checkout_required"===l.status)try{const e=await $o.createWorkspaceCheckoutSession(l.workspace_id,l.pending_changes);if(e.subscription_updated);else{if(!e.url)throw new Error("No checkout URL received from billing service");window.location.href=e.url}}catch(n){throw n}}catch(o){throw o}finally{x(!1)}},[a]);(0,Y.useEffect)(()=>(b(),j(),()=>{v.current&&v.current()}),[b,j]);const T={loading:r,error:o,actionLoading:u,availablePlans:d,currentWorkspace:null==n?void 0:n.workspace,plans:(null==n||null===(t=n.workspace)||void 0===t?void 0:t.plans)||[],members:(null==n?void 0:n.members)||[],userRole:(null==n?void 0:n.user_role)||"member",currentUser:null==n?void 0:n.current_user,workspaceId:a,showRemoveDialog:h,memberToRemove:g,loadDashboard:b,inviteUser:_,updateMemberRole:k,updateMemberSeat:C,showRemoveMemberDialog:A,hideRemoveMemberDialog:S,confirmRemoveMember:E,manageSeat:I,handleCheckoutSuccess:y,canInviteUsers:N,canManageSeats:w};return(0,le.jsx)(L_.Provider,{value:T,children:s})}function R_(){const e=(0,Y.useContext)(L_);if(!e)throw new Error("useWorkspaceDashboard must be used within a WorkspaceDashboardProvider");return e}var M_=s(40602);const D_=e=>{let{users:t,onSelectUser:s,anchorElement:a,onClose:n}=e;const[l,r]=(0,Y.useState)({left:0,top:0,width:0}),i=(0,Y.useRef)(null);(0,Y.useEffect)(()=>{const e=()=>{if(!a)return;const e=a.getBoundingClientRect(),t=window.innerHeight,s=window.innerWidth,n=Math.max(e.width,300),l=t-e.bottom,i=e.top,o=l<192&&i>192;let c=e.left;c+n>s&&(c=s-n-10),c<10&&(c=10),r({left:c,top:o?e.top-192-4:e.bottom+4,width:n})};e();const t=()=>e(),s=()=>e();return window.addEventListener("scroll",t,!0),window.addEventListener("resize",s),()=>{window.removeEventListener("scroll",t,!0),window.removeEventListener("resize",s)}},[a]),(0,Y.useEffect)(()=>{const e=e=>{i.current&&!i.current.contains(e.target)&&a&&!a.contains(e.target)&&n()};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[n,a]);const o=(0,le.jsx)("div",{ref:i,className:"fixed z-[1000] bg-white border border-slate-200 rounded-md shadow-xl max-h-48 overflow-y-auto",style:{left:"".concat(l.left,"px"),top:"".concat(l.top,"px"),width:"".concat(l.width,"px")},children:t.map(e=>(0,le.jsx)("div",{className:"px-3 py-2 hover:bg-orange-50 cursor-pointer transition-colors border-b border-slate-100 last:border-b-0",onClick:()=>s(e.email),children:(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[(0,le.jsx)("div",{className:"w-6 h-6 bg-gradient-to-br from-orange-100 to-orange-200 rounded-full flex items-center justify-center",children:(0,le.jsx)(nv.A,{className:"w-3 h-3 text-orange-600"})}),(0,le.jsxs)("div",{className:"flex flex-col",children:[(0,le.jsx)("span",{className:"text-sm font-medium text-slate-700 truncate max-w-[200px]",children:e.email}),"pending"===e.status&&(0,le.jsx)("span",{className:"text-xs text-orange-500 font-medium",children:"Pending invitation"})]})]})},e.email))});return cd.createPortal(o,document.body)},F_=e=>{let{anchorElement:t,onClose:s}=e;const[a,n]=(0,Y.useState)({left:0,top:0,width:0}),l=(0,Y.useRef)(null);(0,Y.useEffect)(()=>{const e=()=>{if(!t)return;const e=t.getBoundingClientRect(),s=window.innerWidth,a=Math.max(e.width,300);let l=e.left;l+a>s&&(l=s-a-10),l<10&&(l=10),n({left:l,top:e.bottom+4,width:a})};e();const s=()=>e(),a=()=>e();return window.addEventListener("scroll",s,!0),window.addEventListener("resize",a),()=>{window.removeEventListener("scroll",s,!0),window.removeEventListener("resize",a)}},[t]),(0,Y.useEffect)(()=>{const e=e=>{l.current&&!l.current.contains(e.target)&&t&&!t.contains(e.target)&&s()};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[s,t]);const r=(0,le.jsx)("div",{ref:l,className:"fixed z-[1000] bg-white border border-slate-200 rounded-md shadow-xl",style:{left:"".concat(a.left,"px"),top:"".concat(a.top,"px"),width:"".concat(a.width,"px")},children:(0,le.jsx)("div",{className:"px-3 py-2 text-sm text-slate-500 text-center",children:"No users found"})});return cd.createPortal(r,document.body)},B_=e=>{let{open:t,onOpenChange:s,planName:a}=e;const[n,l]=(0,Y.useState)(null),[r,i]=(0,Y.useState)(!1),[o,c]=(0,Y.useState)(null),[d,m]=(0,Y.useState)(new Set),[u,x]=(0,Y.useState)(null),[h,p]=(0,Y.useState)(""),[g,f]=(0,Y.useState)(null),{workspaceId:v,members:b}=R_();(0,Y.useEffect)(()=>{t&&a?j():t||(x(null),p(""),f(null))},[t,a]),(0,Y.useEffect)(()=>{p(""),f(null)},[u]);const j=async()=>{try{i(!0),c(null),l(null);const e=await xe.getSeatUsage(a,v);l(e.data||e)}catch(s){var e,t;c((null===(e=s.response)||void 0===e||null===(t=e.data)||void 0===t?void 0:t.detail)||"Failed to fetch seat usage data")}finally{i(!1)}},y=async function(e,t){let s=arguments.length>2&&void 0!==arguments[2]&&arguments[2];const r="".concat(a,"_").concat(t);try{if(m(e=>new Set([...e,r])),x(null),p(""),f(null),s)await xe.updateMemberSeat(e,null,v);else{var i;const s=null==n||null===(i=n.plan)||void 0===i?void 0:i.price_id;if(!s)throw new Error("Plan price ID not found");await xe.updateMemberSeat(e,s,v,t)}l(a=>{if(!a)return a;const n=a.seats.map(a=>a.assigned_user===e&&a.seat_number!==t?(0,K.A)((0,K.A)({},a),{},{assigned_user:null,status:"available"}):a.seat_number===t?(0,K.A)((0,K.A)({},a),{},{assigned_user:s?null:e,status:s?"available":"assigned"}):a),l=n.filter(e=>"assigned"===e.status).length,r=a.plan.total_seats-l;return(0,K.A)((0,K.A)({},a),{},{seats:n,summary:(0,K.A)((0,K.A)({},a.summary),{},{total_assigned:l,total_available:r}),plan:(0,K.A)((0,K.A)({},a.plan),{},{used_seats:l,available_seats:r})})})}catch(u){var o,d;c((null===(o=u.response)||void 0===o||null===(d=o.data)||void 0===d?void 0:d.detail)||"Failed to assign user to seat")}finally{m(e=>{const t=new Set(e);return t.delete(r),t})}},N=e=>"assigned"===e?(0,le.jsx)(nv.A,{className:"w-3 h-3"}):(0,le.jsx)(Xl.A,{className:"w-3 h-3"});return(0,le.jsx)(Pa,{open:t,onOpenChange:s,children:(0,le.jsxs)(Da,{className:"max-w-5xl max-h-[90vh] flex flex-col",children:[(0,le.jsxs)(Fa,{className:"pb-3",children:[(0,le.jsxs)(za,{className:"flex items-center gap-2 text-lg",children:[(0,le.jsx)("div",{className:"w-8 h-8 bg-gradient-to-br from-orange-100 to-orange-200 rounded-full flex items-center justify-center",children:(0,le.jsx)(Xl.A,{className:"w-4 h-4 text-orange-600"})}),(0,le.jsxs)("span",{className:"font-semibold text-slate-800",children:[a," Seats Usage"]})]}),(0,le.jsx)(Ua,{className:"text-slate-600 text-sm ml-10",children:"Detailed view of seat allocation and usage for this plan. Click available seats to assign users."})]}),r&&(0,le.jsx)("div",{className:"flex items-center justify-center p-8",children:(0,le.jsx)("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-orange-500"})}),o&&(0,le.jsx)("div",{className:"p-4 bg-red-50 border border-red-200 rounded-lg",children:(0,le.jsx)("p",{className:"text-red-800 text-sm",children:o})}),n&&(0,le.jsxs)("div",{className:"flex flex-col flex-1 min-h-0",children:[(0,le.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-3 mb-4",children:[(0,le.jsxs)(is,{className:"p-3 bg-gradient-to-br from-orange-50 to-orange-100 border-orange-200",children:[(0,le.jsxs)("div",{className:"flex items-center gap-2 mb-2",children:[(0,le.jsx)("div",{className:"w-6 h-6 bg-orange-500 rounded-full flex items-center justify-center",children:(0,le.jsx)(Xl.A,{className:"w-3 h-3 text-white"})}),(0,le.jsx)("span",{className:"text-xs font-semibold text-slate-700",children:"Total Seats"})]}),(0,le.jsx)("div",{className:"text-xl font-bold text-slate-900",children:n.plan.total_seats})]}),(0,le.jsxs)(is,{className:"p-3 bg-gradient-to-br from-green-50 to-green-100 border-green-200",children:[(0,le.jsxs)("div",{className:"flex items-center gap-2 mb-2",children:[(0,le.jsx)("div",{className:"w-6 h-6 bg-green-500 rounded-full flex items-center justify-center",children:(0,le.jsx)(nv.A,{className:"w-3 h-3 text-white"})}),(0,le.jsx)("span",{className:"text-xs font-semibold text-slate-700",children:"Assigned"})]}),(0,le.jsx)("div",{className:"text-xl font-bold text-slate-900",children:n.summary.total_assigned})]}),(0,le.jsxs)(is,{className:"p-3 bg-gradient-to-br from-teal-50 to-teal-100 border-teal-200",children:[(0,le.jsxs)("div",{className:"flex items-center gap-2 mb-2",children:[(0,le.jsx)("div",{className:"w-6 h-6 bg-teal-500 rounded-full flex items-center justify-center",children:(0,le.jsx)(ya.A,{className:"w-3 h-3 text-white"})}),(0,le.jsx)("span",{className:"text-xs font-semibold text-slate-700",children:"Period Usage"})]}),(0,le.jsxs)("div",{className:"text-xl font-bold text-slate-900",children:[n.summary.current_month_usage,"/",n.summary.monthly_limit||0]}),(0,le.jsx)("div",{className:"text-xs text-slate-500 mt-1 font-medium",children:n.summary.period})]})]}),(0,le.jsx)(ps,{className:"mb-4"}),(0,le.jsxs)("div",{children:[(0,le.jsx)("h3",{className:"text-base font-semibold text-slate-900 mb-3",children:"Individual Seats"}),(0,le.jsxs)("div",{className:"border rounded-xl overflow-hidden bg-white shadow-sm",children:[(0,le.jsx)(zl,{children:(0,le.jsx)(Ul,{className:"bg-gradient-to-r from-slate-50 to-slate-100 border-b border-slate-200",children:(0,le.jsxs)(Vl,{children:[(0,le.jsx)(Hl,{className:"w-20 font-semibold text-slate-700 py-2",children:"Seat #"}),(0,le.jsx)(Hl,{className:"w-24 font-semibold text-slate-700 py-2",children:"Status"}),(0,le.jsx)(Hl,{className:"font-semibold text-slate-700 py-2",children:"Assigned User"}),(0,le.jsx)(Hl,{className:"w-32 text-right font-semibold text-slate-700 py-2",children:"Period Usage"})]})})}),(0,le.jsx)("div",{className:"max-h-96 overflow-y-auto",children:(0,le.jsx)(zl,{children:(0,le.jsx)(Wl,{children:n.seats.map(e=>{const t=(()=>{if(!b)return[];let e=b.filter(e=>"active"===e.status||"pending"===e.status);return h.trim()&&(e=e.filter(e=>e.email.toLowerCase().includes(h.toLowerCase()))),e})(),s=d.has("".concat(a,"_").concat(e.seat_number)),n=u===e.seat_number;return(0,le.jsxs)(Vl,{className:"hover:bg-slate-50/50 transition-colors",children:[(0,le.jsxs)(Yl,{className:"font-semibold w-20 text-slate-600 py-2",children:["#",e.seat_number]}),(0,le.jsx)(Yl,{className:"w-24 py-2",children:(0,le.jsxs)(es,{className:"text-xs font-medium ".concat((l=e.status,"assigned"===l?"bg-green-100 text-green-800 border-green-200 hover:bg-green-100 hover:text-green-800":"bg-slate-100 text-slate-600 border-slate-200 hover:bg-slate-100 hover:text-slate-600")),children:[N(e.status),(0,le.jsx)("span",{className:"ml-1 capitalize",children:e.status})]})}),(0,le.jsx)(Yl,{className:"py-2",children:s?(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[(0,le.jsx)("div",{className:"w-6 h-6 bg-gradient-to-br from-orange-100 to-orange-200 rounded-full flex items-center justify-center",children:(0,le.jsx)("div",{className:"animate-spin rounded-full h-3 w-3 border border-orange-400 border-t-transparent"})}),(0,le.jsx)("span",{className:"text-sm font-medium text-orange-600 animate-pulse",children:"Updating..."})]}):e.assigned_user?(0,le.jsxs)("div",{className:"flex items-center gap-2 group",children:[(0,le.jsx)("div",{className:"w-6 h-6 bg-gradient-to-br from-green-100 to-green-200 rounded-full flex items-center justify-center",children:(0,le.jsx)(nv.A,{className:"w-3 h-3 text-green-600"})}),(0,le.jsx)("div",{className:"flex-1 min-w-0",children:(0,le.jsx)("span",{className:"text-sm font-medium text-slate-700 truncate block",children:e.assigned_user})}),(0,le.jsx)(Yt,{variant:"ghost",size:"sm",disabled:s,onClick:()=>y(e.assigned_user,e.seat_number,!0),className:"h-6 w-6 p-0 opacity-0 group-hover:opacity-100 transition-opacity hover:bg-red-50 hover:text-red-600 rounded-full",title:"Remove user from seat",children:"\xd7"})]}):n?(0,le.jsxs)("div",{className:"relative",children:[(0,le.jsxs)("div",{className:"relative",children:[(0,le.jsx)(vn.A,{className:"absolute left-2 top-2.5 h-3 w-3 text-slate-400"}),(0,le.jsx)(fs,{placeholder:"Search users...",value:h,onChange:e=>p(e.target.value),className:"pl-7 pr-8 h-8 text-sm border-orange-200 focus:border-orange-400 focus:ring-orange-200",autoFocus:!0,ref:e=>{e&&!g&&f(e)}}),(0,le.jsx)(Yt,{variant:"ghost",size:"sm",onClick:()=>{x(null),p(""),f(null)},className:"absolute right-1 top-1 h-6 w-6 p-0 hover:bg-slate-100 rounded-full",children:(0,le.jsx)(Bt.A,{className:"h-3 w-3 text-slate-400"})})]}),g&&t.length>0&&(0,le.jsx)(D_,{users:t,onSelectUser:t=>y(t,e.seat_number),anchorElement:g,onClose:()=>{x(null),p(""),f(null)}}),g&&h&&0===t.length&&(0,le.jsx)(F_,{anchorElement:g,onClose:()=>{x(null),p(""),f(null)}})]}):(0,le.jsxs)("div",{className:"flex items-center gap-2 group",children:[(0,le.jsx)("div",{className:"w-6 h-6 bg-gradient-to-br from-slate-100 to-slate-200 rounded-full flex items-center justify-center",children:(0,le.jsx)(sv.A,{className:"w-3 h-3 text-slate-500"})}),(0,le.jsx)("span",{className:"text-sm text-slate-500 cursor-pointer hover:text-orange-600 hover:underline transition-colors font-medium",onClick:t=>{x(e.seat_number)},title:"Click to assign user",children:"Available for assignment"})]})}),(0,le.jsx)(Yl,{className:"text-right w-32 py-2",children:(0,le.jsxs)("div",{className:"font-semibold text-slate-700 bg-slate-50 px-2 py-1 rounded-md inline-block text-sm",children:[e.current_month_usage,"/",e.monthly_limit||0]})})]},e.seat_number);var l})})})})]})]})]})]})})},z_={Starter:(0,le.jsx)(Eu.A,{className:"text-orange-500"}),Builder:(0,le.jsx)(M_.A,{className:"text-teal-500"}),Pro:(0,le.jsx)(o_.A,{className:"text-orange-400"}),Elite:(0,le.jsx)(Oi.A,{className:"text-purple-500"})};function U_(e){let{onRemoveSeats:t,onBuySeats:s}=e;const{plans:a,canManageSeats:n}=R_(),[l,r]=(0,Y.useState)({open:!1,planName:null});return a&&0!==a.length?(0,le.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-4 gap-4 mb-8",children:[a.map(e=>(0,le.jsxs)(is,{className:"bg-white rounded-xl shadow-sm p-6 flex flex-col gap-3",children:[(0,le.jsxs)("div",{className:"flex items-start justify-between",children:[(0,le.jsxs)("div",{className:"flex items-center gap-3",children:[(0,le.jsx)("div",{className:"flex-shrink-0",children:z_[e.name]}),(0,le.jsxs)("span",{className:"font-semibold text-lg",children:[e.name," Seats"]})]}),n()&&(0,le.jsxs)(qr,{children:[(0,le.jsx)(Vr,{asChild:!0,children:(0,le.jsx)(Yt,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 text-slate-400 hover:text-slate-600 hover:bg-transparent",children:(0,le.jsx)(xr.A,{className:"h-3 w-3"})})}),(0,le.jsxs)(Kr,{align:"end",className:"w-40",children:[(0,le.jsxs)(Qr,{onClick:()=>{return t=e.name,void r({open:!0,planName:t});var t},className:"text-slate-700 hover:bg-slate-50 focus:bg-slate-50",children:[(0,le.jsx)(Dx.A,{className:"w-4 h-4 mr-2"}),"Seats Usage"]}),(0,le.jsx)(Qr,{onClick:()=>{return t=e.name,void s(t);var t},className:"text-slate-700 hover:bg-slate-50 focus:bg-slate-50",children:"Add Seats"}),e.used_seats{return s=e.name,void t(s);var s},className:"text-slate-700 hover:bg-slate-50 focus:bg-slate-50",children:"Remove Seats"})]})]})]}),(0,le.jsxs)("div",{className:"text-2xl font-bold",children:[e.used_seats," / ",e.total_seats]}),(0,le.jsxs)("div",{className:"text-slate-500 text-sm",children:[e.available_seats," seats available"]})]},e.name)),n()&&(0,le.jsxs)(is,{className:"bg-gradient-to-br from-orange-50 to-teal-50 border-orange-200/50 rounded-xl shadow-sm p-6 flex flex-col justify-center items-center text-center hover:shadow-md transition-all duration-200 cursor-pointer",onClick:()=>s(),children:[(0,le.jsxs)("div",{className:"flex items-center gap-3 mb-4",children:[(0,le.jsx)("div",{className:"flex-shrink-0",children:(0,le.jsx)(kt.A,{className:"w-6 h-6 text-orange-500"})}),(0,le.jsx)("span",{className:"font-semibold text-lg text-slate-900",children:"Buy More Seats"})]}),(0,le.jsx)("div",{className:"text-slate-600 text-sm",children:"Expand your workspace size"})]}),(0,le.jsx)(B_,{open:l.open,onOpenChange:()=>{r({open:!1,planName:null})},planName:l.planName})]}):(0,le.jsx)("div",{className:"mb-8",children:(0,le.jsx)(is,{className:"bg-gradient-to-br from-orange-50 to-teal-50 border-orange-200/50 rounded-xl shadow-sm p-8",children:(0,le.jsxs)("div",{className:"text-center",children:[(0,le.jsx)("div",{className:"mx-auto w-16 h-16 bg-orange-100 rounded-full flex items-center justify-center mb-4",children:(0,le.jsx)(Xl.A,{className:"w-8 h-8 text-orange-600"})}),(0,le.jsx)("h3",{className:"text-xl font-semibold text-slate-900 mb-2",children:"Get Started with Workspace Seats"}),(0,le.jsx)("p",{className:"text-slate-600 mb-6 max-w-md mx-auto",children:"Purchase seats to invite workspace members and start collaborating. Choose from our flexible plans designed for workspaces of all sizes."}),n()&&(0,le.jsxs)(Yt,{onClick:()=>s(),className:"bg-orange-500 hover:bg-orange-600 text-white px-6 py-2 rounded-lg font-medium transition-colors",children:[(0,le.jsx)(kt.A,{className:"w-4 h-4 mr-2"}),"Buy Your First Seats"]})]})})})}const W_={Starter:(0,le.jsx)(Eu.A,{className:"text-orange-500"}),Builder:(0,le.jsx)(M_.A,{className:"text-teal-500"}),Pro:(0,le.jsx)(o_.A,{className:"text-orange-400"}),Elite:(0,le.jsx)(Oi.A,{className:"text-purple-500"})};function q_(e){var t;let{member:s}=e;const{currentUser:a,plans:n,userRole:l,canManageSeats:r,updateMemberRole:i,updateMemberSeat:o,showRemoveMemberDialog:c,actionLoading:d}=R_(),[m,u]=(0,Y.useState)(!1),[x,h]=(0,Y.useState)(!1),{displayStatus:p,seatPlan:g,seatTypeName:f}=(0,Y.useMemo)(()=>{let e=s.status;if("pending"===s.status){s.invitation_expires_at&&new Date(s.invitation_expires_at)e.price_id===s.seat_type):null;return{displayStatus:e,seatPlan:t,seatTypeName:t?t.name:null}},[s,n]),v=["owner","admin"].includes(l),b=v&&s.email!==(null==a?void 0:a.email),j=s.email===(null==a?void 0:a.email),y=v&&!j&&("owner"===l||"admin"===l&&"owner"!==s.role),N=v&&!j&&("owner"===l||"admin"===l&&"owner"!==s.role),w="owner"===l&&!j,_=async e=>{if(s.role!==e&&v){u(!0);try{await i(s.email,e)}finally{u(!1)}}},k=async e=>{if(s.seat_type!==e&&r()){h(!0);try{await o(s.email,e)}finally{h(!1)}}};return(0,le.jsxs)("div",{className:"flex items-center justify-between py-4 border-b border-slate-100 last:border-b-0",children:[(0,le.jsxs)("div",{className:"flex items-center gap-3",children:[(0,le.jsx)(ma,{className:"h-10 w-10",children:(0,le.jsx)(xa,{className:"bg-slate-100 text-slate-700 font-bold text-sm",children:null===(t=s.email[0])||void 0===t?void 0:t.toUpperCase()})}),(0,le.jsx)("div",{children:(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[(0,le.jsx)("span",{className:"font-medium text-slate-900",children:s.email}),"pending"===p&&(0,le.jsx)(es,{variant:"secondary",className:"bg-orange-100 text-orange-700 border-orange-200 text-xs",children:"Pending"}),"expired"===p&&(0,le.jsx)(es,{variant:"destructive",className:"bg-red-100 text-red-700 border-red-200 text-xs",children:"Expired"})]})})]}),(0,le.jsxs)("div",{className:"flex items-center gap-3",children:[(0,le.jsxs)(qr,{children:[(0,le.jsx)(Vr,{asChild:!0,children:(0,le.jsxs)(Yt,{variant:"outline",size:"sm",className:"min-w-[100px] justify-between",disabled:m||d||!y&&!N&&!w,children:[(0,le.jsxs)("div",{className:"flex items-center gap-1",children:[m?(0,le.jsx)(Ne.A,{className:"h-3 w-3 animate-spin"}):(0,le.jsx)(nv.A,{className:"h-3 w-3"}),(0,le.jsx)("span",{className:"capitalize",children:s.role})]}),(0,le.jsx)(Is.A,{className:"h-3 w-3"})]})}),(0,le.jsxs)(Kr,{align:"end",className:"w-40",children:[(0,le.jsxs)(Qr,{onClick:()=>_("member"),disabled:"member"===s.role||!y||m,children:[(0,le.jsx)(nv.A,{className:"mr-2 h-4 w-4"}),"Member"]}),(0,le.jsxs)(Qr,{onClick:()=>_("admin"),disabled:"admin"===s.role||!N||m,children:[(0,le.jsx)(nv.A,{className:"mr-2 h-4 w-4"}),"Admin"]}),(0,le.jsxs)(Qr,{onClick:()=>_("owner"),disabled:"owner"===s.role||!w||m,children:[(0,le.jsx)(nv.A,{className:"mr-2 h-4 w-4"}),"Owner"]}),b&&(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)("div",{className:"border-t border-slate-100 my-1"}),(0,le.jsxs)(Qr,{onClick:()=>{c(s)},disabled:d||m,className:"text-red-600 hover:text-red-700 focus:text-red-700",children:[d?(0,le.jsx)(Ne.A,{className:"mr-2 h-4 w-4 animate-spin"}):(0,le.jsx)(nv.A,{className:"mr-2 h-4 w-4"}),"Remove Member"]})]})]})]}),(0,le.jsxs)(qr,{children:[(0,le.jsx)(Vr,{asChild:!0,children:(0,le.jsxs)(Yt,{variant:"outline",size:"sm",className:"min-w-[120px] justify-between",disabled:x||d,children:[(0,le.jsx)("div",{className:"flex items-center gap-1",children:x?(0,le.jsx)(Ne.A,{className:"h-3 w-3 animate-spin"}):f?(0,le.jsxs)(le.Fragment,{children:[W_[f],(0,le.jsx)("span",{children:f})]}):(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(nv.A,{className:"h-3 w-3"}),(0,le.jsx)("span",{children:"Viewer"})]})}),(0,le.jsx)(Is.A,{className:"h-3 w-3"})]})}),(0,le.jsxs)(Kr,{align:"end",className:"w-50",children:[(0,le.jsxs)(Qr,{onClick:()=>k(null),disabled:!s.seat_type||x,children:[(0,le.jsx)(nv.A,{className:"mr-2 h-4 w-4"}),"Viewer"]}),n.length>0&&(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)("div",{className:"border-t border-slate-100 my-1"}),n.map(e=>(0,le.jsxs)(Qr,{onClick:()=>k(e.price_id),disabled:s.seat_type===e.price_id||!r()||x||0===e.available_seats,className:0===e.available_seats?"opacity-50":"",children:[(0,le.jsx)("div",{className:"flex items-center mr-2 h-4 w-4",children:W_[e.name]}),(0,le.jsxs)("div",{className:"flex flex-col",children:[(0,le.jsx)("span",{children:e.name}),(0,le.jsxs)("span",{className:"text-xs text-slate-500",children:[e.available_seats," available"]})]})]},e.price_id))]})]})]})]})]})}function V_(e){let{onInviteUser:t,onBulkInvite:s}=e;const{currentOrganization:a,members:n,canInviteUsers:l,plans:r}=R_(),[i,o]=(0,Y.useState)(""),c=(0,Y.useMemo)(()=>{if(!i.trim())return n;const e=i.toLowerCase();return n.filter(t=>{var s,a,n;const l=(e=>{if(!e.seat_type)return"no seat";const t=null==r?void 0:r.find(t=>t.price_id===e.seat_type);return t?t.name.toLowerCase():"no seat"})(t);return(null===(s=t.email)||void 0===s?void 0:s.toLowerCase().includes(e))||(null===(a=t.role)||void 0===a?void 0:a.toLowerCase().includes(e))||(null===(n=t.status)||void 0===n?void 0:n.toLowerCase().includes(e))||l.includes(e)})},[n,i,r]),d=n&&n.length>0,m=c&&c.length>0;return(0,le.jsxs)(is,{children:[(0,le.jsxs)(os,{className:"flex flex-row items-center justify-between",children:[(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[(0,le.jsx)(Xl.A,{className:"text-slate-400"}),(0,le.jsxs)(cs,{children:["Members ",i?(0,le.jsxs)("span",{children:["(",(null==c?void 0:c.length)||0," of ",(null==n?void 0:n.length)||0,")"]}):(0,le.jsxs)("span",{children:["(",(null==n?void 0:n.length)||0,")"]})]})]}),l()&&(0,le.jsxs)("div",{className:"flex gap-2",children:[(0,le.jsxs)(Yt,{variant:"outline",onClick:s,className:"text-orange-600 border-orange-200 hover:bg-orange-50",children:[(0,le.jsx)(hx.A,{className:"h-4 w-4 mr-2"}),"Bulk Invite"]}),(0,le.jsxs)(Yt,{onClick:t,children:[(0,le.jsx)(kt.A,{className:"h-4 w-4"}),"Invite User"]})]})]}),(0,le.jsxs)(ms,{children:[d&&(0,le.jsxs)("div",{className:"mb-4",children:[(0,le.jsxs)("div",{className:"relative",children:[(0,le.jsx)(vn.A,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 text-slate-400 h-4 w-4"}),(0,le.jsx)(fs,{type:"text",placeholder:"Search by email, role, status, or seat type (e.g., starter, pro)...",value:i,onChange:e=>o(e.target.value),className:"pl-10 bg-white border-slate-200 focus:border-orange-300 focus:ring-orange-200"})]}),i&&(0,le.jsx)("div",{className:"mt-2 text-xs text-slate-500",children:'Tip: Search for seat types like "starter", "builder", "pro", "elite", or "no seat"'})]}),d?!m&&i?(0,le.jsxs)("div",{className:"flex flex-col items-center justify-center py-12",children:[(0,le.jsx)(vn.A,{className:"text-slate-200 text-5xl mb-2"}),(0,le.jsx)("div",{className:"font-semibold text-lg",children:"No members found"}),(0,le.jsxs)("div",{className:"text-slate-500",children:['No members match "',i,'"']}),(0,le.jsx)(Yt,{variant:"outline",onClick:()=>o(""),className:"mt-4 text-orange-600 border-orange-200 hover:bg-orange-50",children:"Clear search"})]}):(0,le.jsx)("div",{className:"space-y-0",children:c.map(e=>(0,le.jsx)(q_,{member:e},e.id))}):(0,le.jsxs)("div",{className:"flex flex-col items-center justify-center py-12",children:[(0,le.jsx)(Xl.A,{className:"text-slate-200 text-5xl mb-2"}),(0,le.jsx)("div",{className:"font-semibold text-lg",children:"No workspace members yet"}),(0,le.jsx)("div",{className:"text-slate-500",children:null!=a&&a.is_personal?"Personal workspaces contain only you":"Start by inviting your first workspace member"})]})]})]})}function H_(e){let{isOpen:t,onClose:s,onInvite:a}=e;const{actionLoading:n}=R_(),[l,r]=(0,Y.useState)(""),[i,o]=(0,Y.useState)("member"),[c,d]=(0,Y.useState)(""),m=()=>{r(""),o("member"),d(""),s()};return(0,le.jsx)(Pa,{open:t,onOpenChange:m,children:(0,le.jsxs)(Da,{className:"max-w-md",children:[(0,le.jsx)(Fa,{children:(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[(0,le.jsx)("div",{className:"rounded bg-teal-100 p-2",children:(0,le.jsx)(Uh.A,{className:"text-teal-600 w-5 h-5"})}),(0,le.jsx)(za,{className:"text-2xl font-bold",children:"Invite Workspace Member"})]})}),(0,le.jsxs)("form",{onSubmit:async e=>{if(e.preventDefault(),l.trim())if(l.includes("@"))try{d(""),await a(l.trim(),i),m()}catch(n){var t,s;d((null==n||null===(t=n.response)||void 0===t||null===(s=t.data)||void 0===s?void 0:s.detail)||n.message||"Failed to invite user")}else d("Please enter a valid email address");else d("Email is required")},className:"space-y-4",children:[(0,le.jsxs)("div",{children:[(0,le.jsx)("label",{className:"block text-sm font-medium text-slate-700 mb-1",children:"Email Address"}),(0,le.jsxs)("div",{className:"relative",children:[(0,le.jsx)(Uh.A,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 text-slate-400 w-4 h-4"}),(0,le.jsx)(fs,{type:"email",placeholder:"colleague@company.com",value:l,onChange:e=>r(e.target.value),disabled:n,className:"pl-10 focus:ring-2 focus:ring-teal-500",autoFocus:!0})]})]}),(0,le.jsxs)("div",{children:[(0,le.jsx)("label",{className:"block text-sm font-medium text-slate-700 mb-1",children:"Role"}),(0,le.jsxs)("select",{className:"w-full border rounded px-3 py-2 focus:ring-2 focus:ring-teal-500",value:i,onChange:e=>o(e.target.value),disabled:n,children:[(0,le.jsx)("option",{value:"member",children:"Member"}),(0,le.jsx)("option",{value:"admin",children:"Admin"})]})]}),c&&(0,le.jsx)("div",{className:"bg-red-50 border border-red-200 rounded-lg p-3",children:(0,le.jsx)("p",{className:"text-red-700 text-sm",children:c})}),(0,le.jsxs)(Ba,{children:[(0,le.jsx)(Yt,{type:"button",variant:"outline",onClick:m,disabled:n,children:"Cancel"}),(0,le.jsx)(Yt,{type:"submit",className:"bg-teal-600 hover:bg-teal-700 text-white",disabled:n||!l.trim(),children:n?(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(Ne.A,{className:"mr-2 h-4 w-4 animate-spin"}),"Sending Invite..."]}):"Send Invite"})]})]})]})})}const Y_=[{value:"member",label:"Member"},{value:"admin",label:"Admin"}];function G_(e){let{isOpen:t,onClose:s,onSuccess:a}=e;const{workspaceId:n,plans:l,availablePlans:r}=R_(),[i,o]=(0,Y.useState)(null),[c,d]=(0,Y.useState)("member"),[m,u]=(0,Y.useState)(null),[x,h]=(0,Y.useState)(""),[p,g]=(0,Y.useState)([]),[f,v]=(0,Y.useState)([]),[b,j]=(0,Y.useState)(!1),[y,N]=(0,Y.useState)(!1),[w,_]=(0,Y.useState)(!1),k=(0,Y.useRef)(),C=Y.useMemo(()=>{const e=[{value:null,label:"Viewer"}];return r&&r.length>0&&e.push(...r.map(e=>({value:e.name.toLowerCase(),label:e.name}))),e},[r]),A=e=>"text/csv"===e.type||e.name.endsWith(".csv")?(o(e),h(""),S(e),!0):(h("Please upload a CSV file"),!1),S=e=>{const t=new FileReader;t.onload=e=>{try{const t=e.target.result.split("\n").filter(e=>e.trim());if(0===t.length)return void h("CSV file is empty");const s=t[0].split(",").map(e=>e.trim().toLowerCase());if(!s.includes("email"))return void h('CSV must contain an "email" column');const a=[];for(let e=1;ee.trim()),l={};s.forEach((e,t)=>{l[e]=n[t]||""}),l.email&&a.push({email:l.email,role:l.role||"",seat:l.seat||""})}if(0===a.length)return void h("No valid email addresses found in CSV");v(a),j(!0),h("")}catch(t){const e="string"==typeof t.message?t.message:"Unknown parsing error";h("Error parsing CSV file: "+e)}},t.readAsText(e)},E=async e=>{if(e.preventDefault(),i)if(0!==p.length){N(!0),h("");try{const e=new FileReader;e.onload=async e=>{try{const t=e.target.result.split("\n").filter(e=>e.trim()),s=t[0].split(",").map(e=>e.trim().toLowerCase()),l=[];for(let e=1;ee.trim()),n={};s.forEach((e,t)=>{n[e]=a[t]||""}),n.email&&l.push({email:n.email,role:n.role||c,seat:n.seat||m})}I(l),await xe.bulkInviteUsers(l,n),a&&a(),T()}catch(l){var t,s;let e="Failed to send bulk invitations";null!=l&&null!==(t=l.response)&&void 0!==t&&null!==(s=t.data)&&void 0!==s&&s.detail?"string"==typeof l.response.data.detail?e=l.response.data.detail:Array.isArray(l.response.data.detail)?e=l.response.data.detail.map(e=>e.msg||e.message||e).join(", "):"object"==typeof l.response.data.detail&&(e=l.response.data.detail.msg||l.response.data.detail.message||JSON.stringify(l.response.data.detail)):null!=l&&l.message&&(e=l.message),h(e)}finally{N(!1)}},e.readAsText(i)}catch(l){var t,s;let e="Failed to send bulk invitations";null!=l&&null!==(t=l.response)&&void 0!==t&&null!==(s=t.data)&&void 0!==s&&s.detail?"string"==typeof l.response.data.detail?e=l.response.data.detail:Array.isArray(l.response.data.detail)?e=l.response.data.detail.map(e=>e.msg||e.message||e).join(", "):"object"==typeof l.response.data.detail&&(e=l.response.data.detail.msg||l.response.data.detail.message||JSON.stringify(l.response.data.detail)):null!=l&&l.message&&(e=l.message),h(e),N(!1)}}else h("No valid invitations to send");else h("Please upload a CSV file")},I=e=>{const t={};if(e.forEach(e=>{e.seat&&"none"!==e.seat&&(t[e.seat]=(t[e.seat]||0)+1)}),0===Object.keys(t).length)return;const s=[],a=[],n=[];if(Object.entries(t).forEach(e=>{let[t,i]=e;const o=r.find(e=>e.name.toLowerCase()===t.toLowerCase());if(!o)return void n.push("Invalid seat type: ".concat(t,". Available types: ").concat(r.map(e=>e.name.toLowerCase()).join(", ")));const c=l.find(e=>e.name.toLowerCase()===t.toLowerCase());c?c.available_seats0||s.length>0||n.length>0){let e="\u{1f6ab} Cannot proceed with bulk invite - seat issues detected:\n\n";throw a.length>0&&(e+="\u{1f4cb} Plans Not Purchased:\n",a.forEach(t=>{e+="\u25b6 ".concat(t.plan_name," Plan: You need to purchase this plan first (").concat(t.requested," seat").concat(t.requested>1?"s":""," needed)\n")}),e+="\n"),s.length>0&&(e+="\u{1f4ca} Insufficient Seats:\n",s.forEach(t=>{e+="\u25b6 ".concat(t.plan_name," Plan: Need to purchase ").concat(t.needed," more seat").concat(t.needed>1?"s":"","\n"),e+=" (You're trying to assign ".concat(t.requested," seats, but only ").concat(t.available," are available)\n")}),e+="\n"),(a.length>0||s.length>0)&&(e+="\u{1f4a1} Next Steps:\n",e+="1. Go to Workspace Settings \u2192 Seat Management\n",e+="2. Purchase the required plans/seats\n",e+="3. Return here to complete the bulk invite\n\n",e+="\u{1f504} Alternatively, you can reduce the number of seat assignments in your CSV file."),n.length>0&&(e+="\n\n\u274c Invalid Seat Types:\n"+n.join("\n")),new Error(e)}},T=()=>{o(null),d("member"),u(null),h(""),g([]),v([]),j(!1),N(!1),_(!1),k.current&&(k.current.value=""),s()};return(0,Y.useEffect)(()=>{if(f.length>0){const e=f.map(e=>({email:e.email,role:e.role||c,seat:e.seat||m}));g(e)}},[c,m,f]),(0,le.jsx)(Pa,{open:t,onOpenChange:T,children:(0,le.jsxs)(Da,{className:"max-w-2xl max-h-[90vh] overflow-hidden flex flex-col",children:[(0,le.jsx)(Fa,{children:(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[(0,le.jsx)("div",{className:"rounded bg-orange-100 p-2",children:(0,le.jsx)(Xl.A,{className:"text-orange-600 w-5 h-5"})}),(0,le.jsx)(za,{className:"text-2xl font-bold",children:"Bulk Invite Members"})]})}),(0,le.jsx)("div",{className:"flex-1 overflow-y-auto",children:(0,le.jsxs)("form",{onSubmit:E,className:"space-y-6",children:[(0,le.jsxs)("div",{className:"space-y-4",children:[(0,le.jsxs)("div",{className:"flex items-center justify-between",children:[(0,le.jsx)(Ns,{className:"text-sm font-medium text-slate-700",children:"CSV File"}),(0,le.jsxs)(Yt,{type:"button",variant:"outline",size:"sm",onClick:()=>{var e,t;const s=(null===(e=r[0])||void 0===e?void 0:e.name.toLowerCase())||"starter",a=(null===(t=r[1])||void 0===t?void 0:t.name.toLowerCase())||"pro",n="email,role,seat\nexample@company.com,member,".concat(s,"\nuser2@company.com,admin,").concat(a),l=new Blob([n],{type:"text/csv"}),i=window.URL.createObjectURL(l),o=document.createElement("a");o.href=i,o.download="bulk_invite_template.csv",o.click(),window.URL.revokeObjectURL(i)},className:"text-orange-600 border-orange-200 hover:bg-orange-50",children:[(0,le.jsx)(Gx.A,{className:"h-4 w-4 mr-1.5"}),"Download Template"]})]}),(0,le.jsxs)("div",{className:"border-2 border-dashed border-slate-200 rounded-lg p-6 text-center hover:border-orange-300 transition-colors ".concat(w?"border-orange-300 bg-orange-50":""),onDragOver:e=>{e.preventDefault(),e.stopPropagation(),w||_(!0)},onDragEnter:e=>{e.preventDefault(),e.stopPropagation(),_(!0)},onDragLeave:e=>{e.preventDefault(),e.stopPropagation();const t=e.currentTarget.getBoundingClientRect(),s=e.clientX,a=e.clientY;(s=t.right||a=t.bottom)&&_(!1)},onDrop:e=>{e.preventDefault(),e.stopPropagation(),_(!1);const t=e.dataTransfer.files;if(t.length>0){const e=t[0];A(e)}},children:[(0,le.jsx)(hx.A,{className:"mx-auto h-8 w-8 mb-2 transition-colors ".concat(w?"text-orange-500":"text-slate-400")}),(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsx)("p",{className:"text-sm transition-colors ".concat(w?"text-orange-600 font-medium":"text-slate-600"),children:w?"Drop your CSV file here":"Drag & drop a CSV file or click to upload"}),(0,le.jsxs)("p",{className:"text-xs text-slate-500",children:["CSV should contain columns: ",(0,le.jsx)("span",{className:"font-mono text-orange-600",children:"email, role, seat"})]}),(0,le.jsx)(fs,{ref:k,type:"file",accept:".csv",onChange:e=>{const t=e.target.files[0];t&&A(t)},disabled:y,className:"max-w-xs mx-auto"})]}),i&&(0,le.jsxs)("div",{className:"mt-3 flex items-center justify-center gap-2 text-sm text-green-600",children:[(0,le.jsx)(hr.A,{className:"h-4 w-4"}),i.name]})]}),(0,le.jsxs)(De,{children:[(0,le.jsx)(_e.A,{className:"h-4 w-4"}),(0,le.jsx)(Be,{className:"text-sm",children:"CSV format: email (required), role (optional), seat (optional). If role or seat are empty, default values below will be used."})]})]}),(0,le.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsx)(Ns,{htmlFor:"defaultRole",className:"text-sm font-medium text-slate-700",children:"Default Role"}),(0,le.jsxs)(zs,{value:c,onValueChange:d,children:[(0,le.jsx)(qs,{id:"defaultRole",className:"h-11 border-slate-200 focus:ring-orange-500 focus:border-orange-500",children:(0,le.jsx)(Ws,{placeholder:"Select default role"})}),(0,le.jsx)(Ys,{children:Y_.map(e=>(0,le.jsx)($s,{value:e.value,className:"py-3",children:(0,le.jsx)("div",{className:"flex flex-col",children:(0,le.jsx)("span",{className:"font-medium",children:e.label})})},e.value))})]})]}),(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsx)(Ns,{htmlFor:"defaultSeat",className:"text-sm font-medium text-slate-700",children:"Default Seat"}),(0,le.jsxs)(zs,{value:m||"none",onValueChange:e=>u("none"===e?null:e),children:[(0,le.jsx)(qs,{id:"defaultSeat",className:"h-11 border-slate-200 focus:ring-orange-500 focus:border-orange-500",children:(0,le.jsx)(Ws,{placeholder:"Select default seat"})}),(0,le.jsx)(Ys,{children:C.map(e=>(0,le.jsx)($s,{value:e.value||"none",className:"py-3",children:(0,le.jsx)("div",{className:"flex flex-col",children:(0,le.jsx)("span",{className:"font-medium",children:e.label})})},e.value||"none"))})]})]})]}),b&&p.length>0&&(0,le.jsxs)("div",{className:"space-y-3",children:[(0,le.jsxs)(Ns,{className:"text-sm font-medium text-slate-700",children:["Preview (",p.length," invitation",1!==p.length?"s":"",")"]}),(0,le.jsx)("div",{className:"bg-slate-50 rounded-lg border border-slate-200 max-h-48 overflow-y-auto",children:(0,le.jsxs)("table",{className:"w-full text-sm",children:[(0,le.jsx)("thead",{className:"bg-slate-100 sticky top-0",children:(0,le.jsxs)("tr",{children:[(0,le.jsx)("th",{className:"text-left p-3 font-medium",children:"Email"}),(0,le.jsx)("th",{className:"text-left p-3 font-medium",children:"Role"}),(0,le.jsx)("th",{className:"text-left p-3 font-medium",children:"Seat"})]})}),(0,le.jsx)("tbody",{children:p.map((e,t)=>(0,le.jsxs)("tr",{className:"border-t border-slate-200",children:[(0,le.jsx)("td",{className:"p-3 font-mono text-xs",children:e.email}),(0,le.jsx)("td",{className:"p-3 capitalize",children:e.role}),(0,le.jsx)("td",{className:"p-3 capitalize",children:e.seat||"Viewer"})]},t))})]})})]})]})}),x&&(0,le.jsxs)("div",{className:"px-6 pb-4 relative",children:[(0,le.jsxs)(De,{variant:"destructive",children:[(0,le.jsx)(_e.A,{className:"h-4 w-4"}),(0,le.jsx)(Be,{className:"whitespace-pre-line text-sm pr-8",children:x})]}),(0,le.jsx)(Yt,{variant:"ghost",size:"sm",onClick:()=>h(""),className:"absolute top-5 right-9 h-5 w-5 p-0 text-red-600 hover:text-red-800 hover:bg-red-100/50 transition-colors flex items-center justify-center rounded-sm",children:(0,le.jsx)(Bt.A,{className:"h-3 w-3"})})]}),(0,le.jsxs)(Ba,{className:"gap-3 pt-4 border-t",children:[(0,le.jsx)(Yt,{variant:"outline",type:"button",onClick:T,disabled:y,children:"Cancel"}),(0,le.jsx)(Yt,{onClick:E,className:"bg-orange-600 hover:bg-orange-700 text-white",disabled:y||!i||0===p.length,children:y?(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)("div",{className:"w-4 h-4 border-2 border-white/30 border-t-white rounded-full animate-spin mr-2"}),"Sending Invitations..."]}):(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(Xl.A,{className:"w-4 h-4 mr-2"}),"Send ",p.length," Invitation",1!==p.length?"s":""]})})]})]})})}function $_(e){let{isOpen:t,onClose:s,onAction:a,action:n="buy",selectedPlanName:l=null}=e;const{plans:r,availablePlans:i,currentWorkspace:o,actionLoading:c}=R_(),[d,m]=(0,Y.useState)(""),[u,x]=(0,Y.useState)(1),[h,p]=(0,Y.useState)(""),[g,f]=(0,Y.useState)(!1);(0,Y.useEffect)(()=>{if(t)if(p(""),f(!1),l)m(l);else if("buy"===n&&i.length>0){const e=i.find(e=>"pro"===e.name.toLowerCase());m(e?e.name:i[0].name)}else if("remove"===n&&r.length>0){var e;m((null===(e=r[0])||void 0===e?void 0:e.name)||"")}},[t,n,i,r,l]);const v=()=>{m(""),x(1),p(""),f(!1),s()},b="buy"===n?i:r,j=b.find(e=>e.name===d),y=c||g,N=o&&!o.is_personal,w=d&&u>=1&&("buy"===n||"remove"===n&&j&&u<=j.available_seats);return(0,le.jsx)(Pa,{open:t,onOpenChange:v,children:(0,le.jsxs)(Da,{className:"max-w-md",children:[(0,le.jsx)(Fa,{children:(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[(0,le.jsx)("div",{className:"buy"===n?"rounded bg-teal-100 p-2":"rounded bg-red-100 p-2",children:(0,le.jsx)(Xl.A,{className:"buy"===n?"text-teal-600 w-5 h-5":"text-red-600 w-5 h-5"})}),(0,le.jsx)(za,{className:"text-2xl font-bold",children:"buy"===n?"Purchase Seats":"Remove Seats"})]})}),c&&!g?(0,le.jsx)("div",{className:"flex items-center justify-center py-8",children:(0,le.jsxs)("div",{className:"flex flex-col items-center gap-3",children:[(0,le.jsx)(Ne.A,{className:"h-8 w-8 animate-spin text-teal-600"}),(0,le.jsx)("p",{className:"text-slate-600",children:"Loading plans..."})]})}):(0,le.jsxs)("form",{onSubmit:async e=>{if(e.preventDefault(),!d||u<1)p("Please select a valid plan and enter a quantity of at least 1");else{if("remove"===n){const e=r.find(e=>e.name===d);if(e&&u>e.available_seats)return void p("Cannot remove ".concat(u," seat").concat(u>1?"s":"",". Only ").concat(e.available_seats," seat").concat(e.available_seats>1?"s are":" is"," available to remove."));if(e&&0===e.available_seats)return void p("No ".concat(d," seats are available to remove."))}try{p(""),f(!0),await a(d,u),v()}catch(l){var t,s;const e=(null==l||null===(t=l.response)||void 0===t||null===(s=t.data)||void 0===s?void 0:s.detail)||l.message||"Failed to ".concat(n," seats. Please try again.");p(e)}finally{f(!1)}}},className:"space-y-4",children:[(0,le.jsxs)("div",{className:"flex gap-4",children:[(0,le.jsxs)("div",{className:"flex-1",children:[(0,le.jsx)("label",{className:"block text-sm font-medium text-slate-700 mb-1",children:"Seat Type"}),(0,le.jsx)("select",{className:"w-full border rounded px-3 py-2 focus:ring-2 focus:ring-teal-500",value:d,onChange:e=>m(e.target.value),disabled:y,children:0===b.length?(0,le.jsx)("option",{children:"buy"===n?"No plans available":"No seats to remove"}):b.map(e=>(0,le.jsxs)("option",{value:e.name,children:[e.name," ","remove"===n?"(".concat(e.available_seats," available)"):""]},e.name))})]}),(0,le.jsxs)("div",{className:"flex-1",children:[(0,le.jsx)("label",{className:"block text-sm font-medium text-slate-700 mb-1",children:"Quantity"}),(0,le.jsx)("input",{type:"number",min:1,max:"remove"===n?(null==j?void 0:j.available_seats)||0:void 0,className:"w-full border rounded px-3 py-2 focus:ring-2 focus:ring-teal-500",value:u,onChange:e=>x(Math.max(1,Number(e.target.value))),disabled:y})]})]}),(0,le.jsxs)("div",{className:"bg-slate-50 rounded-xl p-4 border",children:[(0,le.jsxs)("div",{className:"flex justify-between text-slate-600 text-sm mb-1",children:[(0,le.jsx)("span",{children:"Seat Type"}),(0,le.jsx)("span",{className:"font-medium",children:d||"None selected"})]}),"buy"===n&&(null==j?void 0:j.price)&&(0,le.jsxs)("div",{className:"flex justify-between text-slate-600 text-sm mb-1",children:[(0,le.jsx)("span",{children:"Price per seat"}),(0,le.jsxs)("span",{className:"font-medium",children:["$",j.price,"/month"]})]}),(0,le.jsxs)("div",{className:"flex justify-between text-slate-600 text-sm mb-1",children:[(0,le.jsx)("span",{children:"Quantity"}),(0,le.jsxs)("span",{className:"font-medium",children:[u," seat",u>1?"s":""]})]}),"remove"===n&&j&&(0,le.jsxs)("div",{className:"flex justify-between text-slate-600 text-sm mb-1",children:[(0,le.jsx)("span",{children:"Available to remove"}),(0,le.jsxs)("span",{className:"font-medium",children:[j.available_seats," seat",j.available_seats>1?"s":""]})]}),(0,le.jsx)("hr",{className:"my-2"}),(0,le.jsxs)("div",{className:"flex justify-between items-center",children:[(0,le.jsx)("span",{className:"font-bold text-lg",children:"buy"===n?"Total Cost":"Action"}),(0,le.jsx)("span",{className:"buy"===n?"font-bold text-2xl text-green-600":"font-bold text-2xl text-red-600",children:"buy"===n&&null!=j&&j.price?"$".concat((j.price*u).toLocaleString(),"/month"):"".concat("buy"===n?"+":"-").concat(u," seat").concat(u>1?"s":"")})]})]}),N&&(0,le.jsx)("div",{className:"bg-teal-50 border border-teal-200 rounded-lg p-3",children:(0,le.jsxs)("p",{className:"text-teal-800 text-sm",children:[(0,le.jsx)(Tr.A,{className:"inline w-4 h-4 mr-1"}),"buy"===n?null!=o&&o.stripe_subscription_id?"Seats will be added immediately to your existing subscription.":"You'll be redirected to Stripe checkout to complete your payment. Seats will be added only after successful payment.":null!=o&&o.stripe_subscription_id?"Changes will be applied immediately to your existing subscription.":"You'll be redirected to Stripe billing to update your subscription. Changes will be applied after confirmation."]})}),h&&(0,le.jsx)("div",{className:"bg-red-50 border border-red-200 rounded-lg p-3",children:(0,le.jsx)("p",{className:"text-red-700 text-sm",children:h})}),(0,le.jsxs)(Ba,{children:[(0,le.jsx)(Yt,{type:"button",variant:"outline",onClick:v,disabled:y,children:"Cancel"}),(0,le.jsx)(Yt,{type:"submit",className:"buy"===n?"bg-teal-600 hover:bg-teal-700 text-white":"bg-red-600 hover:bg-red-700 text-white",disabled:y||!w,children:y?(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(Ne.A,{className:"mr-2 h-4 w-4 animate-spin"}),"buy"===n?"Processing...":"Removing..."]}):"buy"===n?"Purchase Seats":"Remove Seats"})]})]})]})})}const J_=e=>{let{children:t,content:s,side:a="left"}=e;const n="right"===a,l="top"===a,r="bottom"===a,i="left"===a;return(0,le.jsxs)("div",{className:"relative group",children:[t,(0,le.jsxs)("div",{className:"\n absolute px-3 py-2 bg-gray-900 text-white text-xs rounded-md \n opacity-0 group-hover:opacity-100 transition-opacity duration-200 \n pointer-events-none whitespace-nowrap z-50 min-w-max\n ".concat(r?"top-full mt-2 left-1/2 transform -translate-x-1/2":l?"bottom-full mb-2 left-1/2 transform -translate-x-1/2":n?"bottom-full mb-2 right-0":i?"right-full mr-2 top-1/2 transform -translate-y-1/2":"bottom-full mb-2 left-0","\n "),children:[s,(0,le.jsx)("div",{className:"\n absolute border-4 border-transparent\n ".concat(r?"bottom-full -mb-1 left-1/2 transform -translate-x-1/2 border-b-gray-900":l?"top-full -mt-1 left-1/2 transform -translate-x-1/2 border-t-gray-900":n?"top-full -mt-1 right-4 border-t-gray-900":i?"left-full -ml-1 top-1/2 transform -translate-y-1/2 border-l-gray-900":"top-full -mt-1 left-4 border-t-gray-900","\n ")})]})]})};function Z_(e){var t;let{workspace:s,userRole:a}=e;const{toast:n}=nn(),[l,r]=(0,Y.useState)(!1),[i,o]=(0,Y.useState)(!1),[c,d]=(0,Y.useState)(new Set),[m,u]=(0,Y.useState)(!1),[x,h]=(0,Y.useState)({sso_provider_name:"",sso_enabled:!1,is_enterprise:!1}),[p,g]=(0,Y.useState)(!1),[f,v]=(0,Y.useState)({name:"",client_id:"",client_secret:"",discovery_url:"",scope:"openid email profile",auth_endpoint:"",token_endpoint:"",userinfo_endpoint:"",jwks_uri:"",tenant_id:"",okta_domain:""}),[b,j]=(0,Y.useState)(""),y="owner"===a&&(null==s?void 0:s.is_enterprise),N={google:{name:"google",displayName:"Google Workspace",description:"Google Workspace (formerly G Suite) SSO",defaults:{discovery_url:"https://accounts.google.com/.well-known/openid-configuration",scope:"openid email profile"},fields:[{name:"client_id",required:!0,row:1,tooltip:"The OAuth client ID provided by your identity provider"},{name:"client_secret",required:!0,row:1,tooltip:"The OAuth client secret provided by your identity provider (keep this confidential)"},{name:"scope",required:!1,row:2,tooltip:"OAuth scopes to request (openid, email, profile are commonly used)"},{name:"discovery_url",required:!1,row:2,tooltip:"OIDC discovery endpoint (pre-configured for Google)"}]},microsoft:{name:"microsoft",displayName:"Microsoft Azure AD",description:"Microsoft Azure Active Directory (requires tenant ID)",defaults:{scope:"openid email profile"},fields:[{name:"client_id",required:!0,row:1,tooltip:"The OAuth client ID provided by your identity provider"},{name:"client_secret",required:!0,row:1,tooltip:"The OAuth client secret provided by your identity provider (keep this confidential)"},{name:"tenant_id",required:!0,row:2,tooltip:"Azure AD Directory (tenant) ID - found in Azure Portal \u2192 Azure Active Directory \u2192 Overview",placeholder:"Your Azure AD tenant ID"},{name:"scope",required:!1,row:2,tooltip:"OAuth scopes to request (openid, email, profile are commonly used)"},{name:"discovery_url",required:!1,row:3,tooltip:"OIDC discovery endpoint automatically generated from your tenant ID"}],autoGenerate:{field:"tenant_id",template:e=>"https://login.microsoftonline.com/".concat(e,"/v2.0/.well-known/openid-configuration"),target:"discovery_url"}},github:{name:"github",displayName:"GitHub",description:"GitHub OAuth (not OIDC compatible)",defaults:{scope:"user:email",auth_endpoint:"https://github.com/login/oauth/authorize",token_endpoint:"https://github.com/login/oauth/access_token",userinfo_endpoint:"https://api.github.com/user"},fields:[{name:"client_id",required:!0,row:1,tooltip:"The OAuth client ID provided by your identity provider"},{name:"client_secret",required:!0,row:1,tooltip:"The OAuth client secret provided by your identity provider (keep this confidential)"},{name:"scope",required:!1,row:2,tooltip:"OAuth scopes to request (user:email for GitHub)"},{name:"auth_endpoint",required:!1,row:2,tooltip:"GitHub OAuth authorization endpoint (pre-configured)"},{name:"token_endpoint",required:!1,row:3,tooltip:"GitHub OAuth token endpoint (pre-configured)"},{name:"userinfo_endpoint",required:!1,row:3,tooltip:"GitHub API user endpoint (pre-configured)"}]},okta:{name:"okta",displayName:"Okta",description:"Okta (requires your tenant domain)",defaults:{scope:"openid email profile"},fields:[{name:"client_id",required:!0,row:1,tooltip:"The OAuth client ID provided by your identity provider"},{name:"client_secret",required:!0,row:1,tooltip:"The OAuth client secret provided by your identity provider (keep this confidential)"},{name:"okta_domain",required:!0,row:2,tooltip:"Your Okta domain name (e.g., 'your-company' from your-company.okta.com)",placeholder:"your-company"},{name:"scope",required:!1,row:2,tooltip:"OAuth scopes to request (openid, email, profile are commonly used)"},{name:"discovery_url",required:!1,row:3,tooltip:"OIDC discovery endpoint automatically generated from your Okta domain"}],autoGenerate:{field:"okta_domain",template:e=>"https://".concat(e,".okta.com/.well-known/openid-configuration"),target:"discovery_url"}},advanced:{name:"advanced",displayName:"Advanced / Manual Configuration",description:"Configure all fields manually for any OAuth/OIDC provider",defaults:{scope:"email profile"},fields:[{name:"name",required:!0,row:1,tooltip:"Custom name for your SSO provider"},{name:"client_id",required:!0,row:1,tooltip:"The OAuth client ID provided by your identity provider"},{name:"client_secret",required:!0,row:2,tooltip:"The OAuth client secret provided by your identity provider (keep this confidential)"},{name:"discovery_url",required:!1,row:2,tooltip:"OIDC discovery endpoint URL (if supported by your provider)"},{name:"scope",required:!1,row:3,tooltip:"OAuth scopes to request (openid, email, profile are commonly used)"},{name:"auth_endpoint",required:!1,row:3,tooltip:"OAuth authorization endpoint URL"},{name:"token_endpoint",required:!1,row:4,tooltip:"OAuth token endpoint URL"},{name:"userinfo_endpoint",required:!1,row:4,tooltip:"OAuth userinfo endpoint URL"},{name:"jwks_uri",required:!1,row:5,tooltip:"JSON Web Key Set URI for token verification"}]}};(0,Y.useEffect)(()=>{(async()=>{if(null!=s&&s.id&&y)try{const e=await wg.getSSOSettings(s.id);h(e.config);const t=(0,K.A)({},e.settings);Object.keys(t).forEach(e=>{t[e]&&t[e].match(/^X+$/)&&(t[e]="\u2022".repeat(20))}),v(t),e.config.sso_provider_name&&(N[e.config.sso_provider_name]?j(e.config.sso_provider_name):j("advanced"))}catch(e){}})(),(async()=>{if(null!=s&&s.id)try{var e;const t=await Yp.getAppSettings(s.id);null!=t&&null!==(e=t.settings)&&void 0!==e&&e.apps_must_use_workspace_sso&&g(t.settings.apps_must_use_workspace_sso)}catch(t){}})()},[null==s?void 0:s.id,y]);const w=(e,t)=>{v(s=>{const a=(0,K.A)((0,K.A)({},s),{},{[e]:t}),n=N[b];if(null!=n&&n.autoGenerate&&e===n.autoGenerate.field&&t){const e=n.autoGenerate.template(t);a[n.autoGenerate.target]=e,d(e=>new Set(e).add(n.autoGenerate.target))}return a}),d(t=>new Set(t).add(e))},_=e=>e&&"string"==typeof e&&(e.match(/^X+$/)||e.match(/^\u2022+$/)),k=e=>e&&N[e]&&N[e].fields||[];return null!=s&&s.is_enterprise?y?(0,le.jsxs)("div",{className:"space-y-6",children:[(0,le.jsxs)("div",{children:[(0,le.jsx)("h2",{className:"text-xl font-semibold text-gray-800",children:"Single Sign-On (SSO)"}),(0,le.jsx)("p",{className:"text-gray-600 mt-1",children:"Configure SSO to allow workspace members to authenticate using your organization's identity provider."})]}),(0,le.jsxs)("div",{className:"bg-white rounded-lg outline outline-1 outline-offset-[-1px] outline-gray-200",children:[(0,le.jsxs)("div",{className:"p-4 flex justify-start items-center gap-4",children:[(0,le.jsx)("div",{className:"w-10 h-10 bg-slate-900 rounded-lg border border-slate-900 flex items-center justify-center",children:(0,le.jsx)("svg",{className:"w-5 h-5 text-white",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,le.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z"})})}),(0,le.jsxs)("div",{className:"flex-1 flex flex-col justify-start items-start gap-0.5",children:[(0,le.jsxs)("div",{className:"flex justify-center items-center gap-2",children:[(0,le.jsx)("div",{className:"text-gray-900 text-sm font-medium leading-tight",children:"Single Sign-on Configuration"}),(0,le.jsx)(J_,{content:"Configure SSO for your workspace",side:"top",children:(0,le.jsx)("div",{className:"inline-flex items-center gap-1 px-2 py-0.5 bg-blue-50 border border-blue-200 rounded-full",children:(0,le.jsx)("span",{className:"text-xs font-medium text-blue-800",children:"Enterprise"})})})]}),(0,le.jsx)("div",{className:"self-stretch text-gray-500 text-sm font-normal leading-tight",children:"Enable SSO to streamline authentication for your workspace members."})]}),(0,le.jsx)("div",{className:"flex items-center gap-3",children:x.sso_provider_name&&!m?(0,le.jsx)(ix,{id:"sso-toggle",checked:!0===x.sso_enabled,onCheckedChange:async e=>{if(!l){r(!0);try{e?(await wg.enableSSO(s.id),h(e=>(0,K.A)((0,K.A)({},e),{},{sso_enabled:!0})),o(!0),!b&&x.sso_provider_name&&(N[x.sso_provider_name]?j(x.sso_provider_name):j("advanced")),n({title:"SSO Enabled",description:"Single Sign-On has been enabled for your workspace"})):(await wg.disableSSO(s.id),h(e=>(0,K.A)((0,K.A)({},e),{},{sso_enabled:!1})),n({title:"SSO Disabled",description:"Single Sign-On has been disabled"}))}catch(t){n({title:"Error",description:t.message||"Failed to update SSO status",variant:"destructive"})}finally{r(!1)}}},disabled:l}):(0,le.jsx)(Yt,{onClick:()=>{u(!0),o(!0),j("google")},variant:"outline",size:"sm",disabled:l,children:l?"Setting up...":"Set Up"})})]}),(x.sso_provider_name||m)&&!i&&(0,le.jsx)("div",{className:"px-4 pb-4 space-y-2",children:(0,le.jsxs)("button",{onClick:()=>{o(!i),i||b||!x.sso_provider_name||(N[x.sso_provider_name]?j(x.sso_provider_name):j("advanced"))},className:"w-full h-10 flex items-center justify-between hover:bg-gray-50 transition-colors group bg-white rounded-md border border-gray-200 px-3",children:[(0,le.jsx)("div",{className:"flex items-center gap-3",children:(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[(0,le.jsx)("div",{className:"text-gray-900 text-sm font-medium",children:m?"Set up SSO Configuration":(null===(t=N[x.sso_provider_name])||void 0===t?void 0:t.displayName)||"".concat(x.sso_provider_name," SSO")}),!m&&p&&(0,le.jsx)(J_,{content:"This SSO is enforced for all apps in the workspace, meaning they automatically use it for authentication. To update enforcement settings, go to Apps Configuration.",side:"top",children:(0,le.jsx)("span",{className:"inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-slate-100 text-slate-700 border border-slate-200",children:"Enforced for apps"})})]})}),(0,le.jsxs)("div",{className:"flex items-center gap-2 text-gray-500",children:[(0,le.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,le.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15.232 5.232l3.536 3.536m-2.036-5.036a2.5 2.5 0 113.536 3.536L6.5 21.036H3v-3.572L16.732 3.732z"})}),(0,le.jsx)("span",{className:"text-sm",children:m?"Set up":"Configure"}),(0,le.jsx)(Is.A,{className:"w-4 h-4 transition-transform ".concat(i?"rotate-180":"")})]})]})}),i&&(x.sso_provider_name||m)&&(0,le.jsx)("div",{className:"border-t border-gray-100 p-4 bg-white",children:(0,le.jsxs)("div",{className:"space-y-4",children:[(0,le.jsxs)("div",{children:[(0,le.jsx)("div",{className:"text-gray-500 text-sm font-normal leading-tight mb-2",children:"Select SSO Provider"}),(0,le.jsxs)(zs,{value:b,onValueChange:e=>{if(j(e),"advanced"===e)v({name:"",client_id:"",client_secret:"",discovery_url:"",scope:"openid email profile",auth_endpoint:"",token_endpoint:"",userinfo_endpoint:"",jwks_uri:"",tenant_id:"",okta_domain:""});else if(e&&N[e]){const t=N[e],s={name:t.name,client_id:"",client_secret:"",discovery_url:"",scope:"openid email profile",auth_endpoint:"",token_endpoint:"",userinfo_endpoint:"",jwks_uri:"",tenant_id:"",okta_domain:""};v((0,K.A)((0,K.A)({},s),t.defaults))}},children:[(0,le.jsx)(qs,{className:"w-full px-4 py-3 bg-white rounded-md shadow-sm outline outline-1 outline-offset-[-1px] outline-gray-200",children:(0,le.jsx)(Ws,{placeholder:"Select SSO Provider"})}),(0,le.jsx)(Ys,{children:Object.entries(N).map(e=>{let[t,s]=e;return(0,le.jsx)($s,{value:t,children:s.displayName},t)})})]})]}),(e=>{const t=k(e);if(!t.length)return null;const s=t.reduce((e,t)=>{const s=t.row||1;return e[s]||(e[s]=[]),e[s].push(t),e},{});return(0,le.jsx)("div",{className:"space-y-4",children:Object.entries(s).sort((e,t)=>{let[s]=e,[a]=t;return parseInt(s)-parseInt(a)}).map(t=>{let[s,a]=t;return(0,le.jsx)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:a.map((t,s)=>{var n,l,r,i;const o=a.length>1&&1===s,c=f[t.name]||"",d=t.placeholder||"Enter ".concat(t.name.replace("_"," ")),m=(t.name,_(u=c)?"\u2022".repeat(20):u);var u;const x="discovery_url"===t.name&&"discovery_url"===(null===(n=N[e])||void 0===n||null===(l=n.autoGenerate)||void 0===l?void 0:l.target)&&c;return(0,le.jsxs)("div",{children:[(0,le.jsxs)(Ns,{className:"text-gray-500 text-sm flex items-center gap-1",children:[t.name.replace("_"," ").replace(/\b\w/g,e=>e.toUpperCase()),t.required&&" *",t.name===(null===(r=N[e])||void 0===r||null===(i=r.autoGenerate)||void 0===i?void 0:i.target)&&c&&" (Auto-generated)",(0,le.jsx)(J_,{content:t.tooltip,side:o?"right":"left",children:(0,le.jsx)(uo.A,{className:"w-3.5 h-3.5 text-gray-400 hover:text-gray-600 cursor-help"})})]}),(0,le.jsx)(fs,{className:"mt-1 w-full h-8 ".concat(x?"bg-gray-50":""),type:"text",placeholder:d,value:m,onChange:e=>{_(e.target.value)||w(t.name,e.target.value)},onFocus:e=>{_(m)&&(e.target.value="",w(t.name,""))},readOnly:x,disabled:!y})]},t.name)})},s)})})})(b),(0,le.jsxs)("div",{className:"flex justify-between pt-4",children:[(0,le.jsx)(Yt,{onClick:()=>{o(!1),m&&u(!1),j(""),d(new Set)},variant:"outline",className:"border-gray-300 text-gray-700 hover:bg-gray-50",children:m?"Cancel Setup":"Dismiss"}),(0,le.jsx)(Yt,{onClick:async()=>{r(!0);try{const e={};c.forEach(t=>{const s=f[t];!s||s.match(/^\u2022+$/)||s.match(/^X+$/)||(e[t]=s)});let t=b;"advanced"===b&&(t=f.name||"advanced"),await wg.updateSSOSettings(s.id,e,t),h(e=>(0,K.A)((0,K.A)({},e),{},{sso_provider_name:t,sso_enabled:!0})),d(new Set),u(!1),o(!1),n({title:"Success",description:"SSO settings updated successfully"})}catch(e){n({title:"Error",description:e.message||"Failed to update SSO settings",variant:"destructive"})}finally{r(!1)}},disabled:l||!b||k(b).some(e=>e.required&&!f[e.name]),className:"bg-gray-900 text-white",children:l?"Saving...":m?"Enable SSO":"Save SSO Settings"})]})]})})]})]}):(0,le.jsx)("div",{className:"bg-yellow-50 rounded-lg p-4",children:(0,le.jsxs)("div",{className:"flex items-start gap-3",children:[(0,le.jsx)(ux.A,{className:"w-5 h-5 text-yellow-600 mt-0.5"}),(0,le.jsxs)("div",{children:[(0,le.jsx)("h3",{className:"text-sm font-medium text-yellow-900",children:"Limited Access"}),(0,le.jsx)("p",{className:"text-sm text-yellow-700 mt-1",children:"Only workspace owners can configure SSO settings."})]})]})}):(0,le.jsxs)("div",{className:"bg-gray-50 rounded-lg p-6 text-center",children:[(0,le.jsx)(Mt.A,{className:"w-12 h-12 text-gray-400 mx-auto mb-4"}),(0,le.jsx)("h3",{className:"text-lg font-semibold text-gray-900 mb-2",children:"Enterprise Feature"}),(0,le.jsx)("p",{className:"text-gray-600",children:"Single Sign-On (SSO) is available for enterprise workspaces only."})]})}const K_=ix,Q_=Ns,X_=zs,ek=qs,tk=Ws,sk=Ys,ak=$s,nk=Et,lk=It,rk=Tt,ik=St,ok=[{value:"private_with_login",label:"Private",description:"Only specific users can access the app - login required",icon:Mt.A,isPublic:!1},{value:"workspace_with_login",label:"Workspace",description:"All workspace members can access the app - login required",icon:Xl.A,isPublic:!1},{value:"public_with_login",label:"Public (Login Required)",description:"Anyone on the internet can access the app - login required",icon:bn.A,isPublic:!0},{value:"public_without_login",label:"Public (No Login)",description:"Anyone on the internet can access the app - no login required",icon:bn.A,isPublic:!0}];const ck=e=>{let{workspace:t,userRole:s}=e;const{toast:a}=nn(),[n,l]=(0,Y.useState)(!0),[r,i]=(0,Y.useState)(!1),[o,c]=(0,Y.useState)({default_app_visibility:"private_with_login",members_can_create_public_apps:!1,apps_must_use_workspace_sso:!1}),d=["owner","admin"].includes(s),[m,u]=(0,Y.useState)(null),[x,h]=(0,Y.useState)(!0),p=(0,Y.useCallback)(async()=>{try{l(!0);const e=await Yp.getAppSettings(t.id);null!=e&&e.settings&&c(e.settings)}catch(n){var e,s;a({title:"Error loading settings",description:(null===(e=n.response)||void 0===e||null===(s=e.data)||void 0===s?void 0:s.detail)||"Failed to load workspace app settings",variant:"destructive"})}finally{l(!1)}},[null==t?void 0:t.id,a]),g=(0,Y.useCallback)(async()=>{if(null!=t&&t.is_enterprise)try{h(!0);const e=await wg.getSSOSettings(t.id);null!=e&&e.config&&u(e.config)}catch(e){}finally{h(!1)}else h(!1)},[null==t?void 0:t.id,null==t?void 0:t.is_enterprise]);(0,Y.useEffect)(()=>{null!=t&&t.id&&(p(),g())},[null==t?void 0:t.id,p,g]);return n?(0,le.jsx)("div",{className:"flex items-center justify-center py-8",children:(0,le.jsx)("div",{className:"animate-spin rounded-full h-8 w-8 border-t-2 border-b-2 border-teal-500"})}):(0,le.jsxs)("div",{className:"space-y-6",children:[(0,le.jsxs)("div",{children:[(0,le.jsx)("h2",{className:"text-2xl font-semibold text-slate-900",children:"Apps Configuration"}),(0,le.jsx)("p",{className:"text-slate-600 mt-1",children:"Manage workspace-wide app settings"})]}),(0,le.jsxs)("div",{className:"bg-white rounded-lg border border-slate-200",children:[(0,le.jsx)("div",{className:"px-6 py-4 border-b border-slate-200",children:(0,le.jsx)("h3",{className:"text-lg font-semibold text-slate-900",children:"Apps Visibility"})}),(0,le.jsxs)("div",{className:"p-6 space-y-6",children:[(0,le.jsxs)("div",{className:"flex items-start justify-between pb-6 border-b border-slate-200",children:[(0,le.jsxs)("div",{className:"flex-1 space-y-1",children:[(0,le.jsx)("div",{className:"flex items-center gap-2",children:(0,le.jsx)(Q_,{htmlFor:"public-apps-permission",className:"text-base font-medium text-slate-900 cursor-pointer",children:"Allow members to create public apps"})}),(0,le.jsx)("p",{className:"text-sm text-slate-500",children:"Members can create apps with public visibility, accessible to anyone on the internet. When turned off, members can only create private or workspace-visible apps"})]}),(0,le.jsx)(K_,{id:"public-apps-permission",checked:o.members_can_create_public_apps||!1,onCheckedChange:async e=>{if(d)try{var s;i(!0);let n={members_can_create_public_apps:e};if(!e){const e=ok.find(e=>e.value===o.default_app_visibility);null!=e&&e.isPublic&&(n.default_app_visibility="private_with_login")}c(e=>(0,K.A)((0,K.A)({},e),n));const l=await Yp.updateAppSettings(t.id,n);null!=l&&null!==(s=l.data)&&void 0!==s&&s.new_settings&&c(l.data.new_settings),a({title:"Settings updated",description:e?"Members can now create public apps":"Members cannot create public apps",variant:"default"})}catch(r){var n,l;const e=r;await p(),a({title:"Error updating settings",description:(null===(n=e.response)||void 0===n||null===(l=n.data)||void 0===l?void 0:l.detail)||"Failed to update workspace app settings",variant:"destructive"})}finally{i(!1)}},disabled:!d||r,className:"data-[state=checked]:bg-teal-600"})]}),(0,le.jsxs)("div",{className:"space-y-4",children:[(0,le.jsxs)("div",{children:[(0,le.jsx)("h4",{className:"text-base font-medium text-slate-900",children:"Initial app visibility"}),(0,le.jsx)("p",{className:"text-sm text-slate-500 mt-1",children:"Choose the starting visibility for new apps created in this workspace."})]}),(0,le.jsxs)(X_,{value:o.default_app_visibility,onValueChange:async e=>{if(!d)return;if(!["private_with_login","workspace_with_login","public_with_login","public_without_login"].includes(e))return;const s=ok.find(t=>t.value===e);if(null==s||!s.isPublic||o.members_can_create_public_apps)try{var n;i(!0);const s={default_app_visibility:e};c(e=>(0,K.A)((0,K.A)({},e),s));const l=await Yp.updateAppSettings(t.id,s);null!=l&&null!==(n=l.data)&&void 0!==n&&n.new_settings&&c(l.data.new_settings),a({title:"Settings updated",description:"Default app visibility updated successfully",variant:"default"})}catch(m){var l,r;const e=m;await p(),a({title:"Error updating settings",description:(null===(l=e.response)||void 0===l||null===(r=l.data)||void 0===r?void 0:r.detail)||"Failed to update workspace app settings",variant:"destructive"})}finally{i(!1)}},disabled:!d||r,children:[(0,le.jsx)(ek,{className:"w-full h-auto min-h-[56px] px-4 py-3",children:(0,le.jsx)(tk,{children:(()=>{const e=ok.find(e=>e.value===o.default_app_visibility);if(e){const t=e.icon;return(0,le.jsxs)("div",{className:"flex items-center gap-3",children:[(0,le.jsx)(t,{className:"h-5 w-5 text-slate-600 flex-shrink-0"}),(0,le.jsxs)("div",{className:"text-left",children:[(0,le.jsx)("div",{className:"font-medium text-slate-900",children:e.label}),(0,le.jsx)("div",{className:"text-xs text-slate-500",children:e.description})]})]})}return null})()})}),(0,le.jsx)(sk,{className:"w-[var(--radix-select-trigger-width)]",children:ok.map(e=>{const t=e.icon,s=e.isPublic&&!o.members_can_create_public_apps;return(0,le.jsx)(ak,{value:e.value,disabled:s,className:"cursor-pointer py-3 px-3 focus:bg-slate-50 ".concat(s?"opacity-50 cursor-not-allowed":""),children:(0,le.jsxs)("div",{className:"flex items-center gap-3 w-full",children:[(0,le.jsx)(t,{className:"h-5 w-5 ".concat(s?"text-slate-400":"text-slate-600"," flex-shrink-0")}),(0,le.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,le.jsx)("div",{className:"font-medium ".concat(s?"text-slate-400":"text-slate-900"),children:e.label}),(0,le.jsx)("div",{className:"text-xs mt-0.5 whitespace-normal ".concat(s?"text-slate-400":"text-slate-500"),children:e.description})]})]})},e.value)})})]})]}),!d&&(0,le.jsx)("div",{className:"bg-slate-50 border border-slate-200 rounded-lg p-4 mt-6",children:(0,le.jsxs)("div",{className:"flex items-start gap-3",children:[(0,le.jsx)(qc.A,{className:"h-5 w-5 text-slate-500 mt-0.5 flex-shrink-0"}),(0,le.jsxs)("div",{className:"space-y-1",children:[(0,le.jsx)("p",{className:"text-sm font-medium text-slate-700",children:"View Only"}),(0,le.jsx)("p",{className:"text-sm text-slate-600",children:"Only workspace administrators and owners can modify workspace app settings."})]})]})})]})]}),(null==t?void 0:t.is_enterprise)&&(null==m?void 0:m.sso_enabled)&&(0,le.jsxs)("div",{className:"bg-white rounded-lg border border-slate-200",children:[(0,le.jsx)("div",{className:"px-6 py-4 border-b border-slate-200",children:(0,le.jsx)("h3",{className:"text-lg font-semibold text-slate-900",children:"Apps SSO"})}),(0,le.jsx)("div",{className:"p-6",children:(0,le.jsxs)("div",{className:"flex items-start justify-between",children:[(0,le.jsxs)("div",{className:"flex-1 space-y-1",children:[(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[(0,le.jsx)(Q_,{htmlFor:"sso-enforcement",className:"text-base font-medium text-slate-900 cursor-pointer",children:"Enforce workspace SSO for all apps"}),(0,le.jsx)(ik,{children:(0,le.jsxs)(nk,{children:[(0,le.jsx)(lk,{asChild:!0,children:(0,le.jsx)(uo.A,{className:"w-4 h-4 text-slate-400 cursor-help"})}),(0,le.jsxs)(rk,{className:"max-w-xs bg-black text-white border-black",children:[(0,le.jsx)("p",{className:"text-sm text-white",children:"When enabled, all apps in this workspace will use the same SSO provider configured for the workspace."}),(0,le.jsxs)("p",{className:"text-sm text-white mt-1",children:["Workspace SSO: ",(null==m?void 0:m.sso_provider_name)||"Workspace SSO"]}),(0,le.jsx)("p",{className:"text-sm text-white mt-1",children:"To edit, go to Workspace SSO"})]})]})})]}),(0,le.jsx)("p",{className:"text-sm text-slate-500",children:"All apps in this workspace will automatically use the workspace SSO settings. App-level configuration is disabled."})]}),(0,le.jsx)(K_,{id:"sso-enforcement",checked:o.apps_must_use_workspace_sso||!1,onCheckedChange:async e=>{if(!r)try{var s;i(!0),c(t=>(0,K.A)((0,K.A)({},t),{},{apps_must_use_workspace_sso:e}));const n=await Yp.updateAppSettings(t.id,{apps_must_use_workspace_sso:e});null!=n&&null!==(s=n.data)&&void 0!==s&&s.new_settings&&c(n.data.new_settings),a({title:"Settings updated",description:e?"Apps must now use workspace SSO":"Apps can now configure their own authentication",variant:"default"})}catch(o){var n,l;const e=o;await p(),a({title:"Error updating settings",description:(null===(n=e.response)||void 0===n||null===(l=n.data)||void 0===l?void 0:l.detail)||"Failed to update SSO enforcement setting",variant:"destructive"})}finally{i(!1)}},disabled:!d||r||x,className:"data-[state=checked]:bg-teal-600"})]})})]})]})};function dk(){const{currentWorkspace:e,userRole:t,loading:s,actionLoading:a,inviteUser:n,manageSeat:l,handleCheckoutSuccess:r,showRemoveDialog:i,memberToRemove:o,hideRemoveMemberDialog:c,confirmRemoveMember:d}=R_(),[m,u]=(0,J.useSearchParams)(),x=(0,Z.Zp)(),[h,p]=(0,Y.useState)(!1),[g,f]=(0,Y.useState)(!1),[v,b]=(0,Y.useState)(!1),[j,y]=(0,Y.useState)("buy"),[N,w]=(0,Y.useState)(null);(0,Y.useEffect)(()=>{const e=m.get("success"),t=m.get("subscription_update");"true"!==e&&"success"!==t||(m.delete("success"),m.delete("subscription_update"),u(m,{replace:!0}),r())},[m,u,r]);const _=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;y(e),t?(w(t),b(!0)):(w(null),b(!0))};return s?(0,le.jsx)("div",{className:"flex items-center justify-center min-h-screen",children:(0,le.jsx)("div",{className:"animate-spin rounded-full h-12 w-12 border-t-2 border-b-2 border-teal-500"})}):e?!e||e.is_personal||["owner","admin"].includes(t)?(0,le.jsxs)("div",{className:"container mx-auto px-4 sm:px-6 lg:px-8 py-6 sm:py-8 min-h-screen flex flex-col max-w-6xl",children:[(0,le.jsxs)("div",{className:"mb-8 relative",children:[(0,le.jsxs)("h1",{className:"text-4xl font-bold text-slate-900 mb-1",children:[e.name," Workspace Dashboard"]}),(0,le.jsx)("p",{className:"text-slate-500 text-lg",children:"Manage your workspace and seats"}),(0,le.jsx)("div",{className:"absolute -bottom-2.5 left-0 w-48 h-0.5 bg-orange-500 rounded-full"})]}),(0,le.jsxs)(kr,{defaultValue:"overview",className:"space-y-6",children:[(0,le.jsxs)(Cr,{className:"".concat(e.is_enterprise?"grid w-full grid-cols-3 max-w-xl":"grid w-full grid-cols-1 max-w-xs"," bg-slate-200 p-1"),children:[(0,le.jsx)(Ar,{value:"overview",className:"data-[state=active]:bg-white data-[state=active]:text-slate-900 data-[state=active]:shadow-sm text-slate-600",children:"Overview"}),e.is_enterprise&&(0,le.jsxs)(le.Fragment,{children:[(0,le.jsxs)(Ar,{value:"sso",className:"flex items-center gap-2 whitespace-nowrap data-[state=active]:bg-white data-[state=active]:text-slate-900 data-[state=active]:shadow-sm text-slate-600",children:[(0,le.jsx)(lv.A,{className:"w-4 h-4 flex-shrink-0"}),(0,le.jsx)("span",{children:"SSO"})]}),(0,le.jsxs)(Ar,{value:"management",className:"flex items-center gap-2 whitespace-nowrap data-[state=active]:bg-white data-[state=active]:text-slate-900 data-[state=active]:shadow-sm text-slate-600",children:[(0,le.jsx)(P_.A,{className:"w-4 h-4 flex-shrink-0"}),(0,le.jsx)("span",{children:"Apps"})]})]})]}),(0,le.jsxs)(Sr,{value:"overview",className:"space-y-6",children:[(0,le.jsx)(U_,{onRemoveSeats:e=>_("remove",e),onBuySeats:e=>_("buy",e)}),(0,le.jsx)(V_,{onInviteUser:()=>p(!0),onBulkInvite:()=>f(!0)})]}),e.is_enterprise&&(0,le.jsx)(Sr,{value:"management",className:"space-y-6",children:(0,le.jsx)(ck,{workspace:e,userRole:t})}),e.is_enterprise&&(0,le.jsx)(Sr,{value:"sso",className:"space-y-6",children:(0,le.jsx)(Z_,{workspace:e,userRole:t})})]}),(0,le.jsx)(H_,{isOpen:h,onClose:()=>p(!1),onInvite:async(e,t)=>{try{await n(e,t),p(!1)}catch(s){}}}),(0,le.jsx)(G_,{isOpen:g,onClose:()=>f(!1),onSuccess:()=>{}}),(0,le.jsx)($_,{isOpen:v,onClose:()=>{b(!1),w(null)},onAction:async(e,t)=>{try{const s="remove"===j&&N?N:e;await l(s,t,j),b(!1),w(null)}catch(s){}},action:j,selectedPlanName:N}),(0,le.jsx)(fv,{open:i,onOpenChange:c,children:(0,le.jsxs)(yv,{children:[(0,le.jsxs)(Nv,{children:[(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[(0,le.jsx)(ux.A,{className:"h-5 w-5 text-orange-500"}),(0,le.jsx)(_v,{children:"Remove Member"})]}),(0,le.jsxs)(kv,{className:"space-y-2 pt-2",children:[(0,le.jsxs)("p",{children:["Are you sure you want to remove ",(0,le.jsx)("strong",{children:null==o?void 0:o.email})," from this workspace?"]}),(0,le.jsx)("div",{className:"bg-orange-50 border border-orange-200 rounded-lg p-3",children:(0,le.jsxs)("div",{className:"flex items-start gap-2",children:[(0,le.jsx)(ux.A,{className:"h-4 w-4 text-orange-600 mt-0.5 flex-shrink-0"}),(0,le.jsxs)("div",{className:"text-sm text-orange-800",children:[(0,le.jsx)("strong",{children:"Warning:"})," This user will no longer have access to workspace apps and will be removed from all workspace applications with restricted access."]})]})})]})]}),(0,le.jsxs)(wv,{children:[(0,le.jsx)(Av,{children:"Cancel"}),(0,le.jsx)(Cv,{onClick:d,className:"bg-red-600 hover:bg-red-700 focus:ring-red-600",children:"Remove Member"})]})]})})]}):(0,le.jsx)("div",{className:"flex items-center justify-center min-h-screen",children:(0,le.jsxs)("div",{className:"text-center max-w-md mx-auto p-8",children:[(0,le.jsx)(Mt.A,{className:"mx-auto h-16 w-16 text-slate-400 mb-4"}),(0,le.jsx)("h2",{className:"text-2xl font-bold text-slate-900 mb-2",children:"Access Restricted"}),(0,le.jsxs)("p",{className:"text-slate-500 mb-6",children:["You don't have permission to access the workspace dashboard for ",(0,le.jsx)("strong",{children:e.name}),". Only workspace administrators and owners can manage workspace settings."]}),(0,le.jsx)("button",{onClick:()=>x("/"),className:"bg-teal-600 hover:bg-teal-700 text-white px-6 py-2 rounded-lg font-medium transition-colors",children:"Go to Home"})]})}):(0,le.jsx)("div",{className:"flex items-center justify-center py-12",children:(0,le.jsxs)("div",{className:"text-center",children:[(0,le.jsx)(Ny.A,{className:"mx-auto h-12 w-12 text-slate-400 mb-4"}),(0,le.jsx)("h2",{className:"text-xl font-bold text-slate-900 mb-2",children:"Workspace Not Found"}),(0,le.jsx)("p",{className:"text-slate-500",children:"The requested workspace could not be found or you don't have access to it."})]})})}function mk(){const{workspaceId:e}=(0,Z.g)();return(0,le.jsx)(O_,{workspaceId:e,children:(0,le.jsx)(dk,{})})}function uk(){const e=(0,Z.Zp)(),[t,s]=(0,Y.useState)(""),[a,n]=(0,Y.useState)(!1),[l,r]=(0,Y.useState)("");return(0,le.jsx)("div",{className:"min-h-screen p-8",children:(0,le.jsxs)("div",{className:"max-w-2xl mx-auto",children:[(0,le.jsxs)("div",{className:"mb-8",children:[(0,le.jsxs)(Yt,{variant:"ghost",onClick:()=>e(-1),className:"mb-4 text-slate-600 hover:text-slate-800",children:[(0,le.jsx)(Cd.A,{className:"mr-2 h-4 w-4"}),"Back"]}),(0,le.jsxs)("div",{className:"flex items-center gap-3 mb-2",children:[(0,le.jsx)("div",{className:"rounded-lg bg-orange-100 p-3",children:(0,le.jsx)(Xl.A,{className:"h-6 w-6 text-orange-600"})}),(0,le.jsxs)("div",{children:[(0,le.jsx)("h1",{className:"text-3xl font-bold text-slate-900",children:"Create a Workspace"}),(0,le.jsx)("p",{className:"text-slate-600",children:"Start collaborating with your workspace members"})]})]})]}),(0,le.jsxs)(is,{className:"shadow-sm",children:[(0,le.jsx)(os,{children:(0,le.jsxs)(cs,{className:"flex items-center gap-2",children:[(0,le.jsx)(Xl.A,{className:"h-5 w-5 text-slate-600"}),"Workspace Information"]})}),(0,le.jsx)(ms,{children:(0,le.jsxs)("form",{onSubmit:async s=>{if(s.preventDefault(),t.trim()){n(!0),r("");try{const s=(await xe.createWorkspace(t.trim())).workspace_id;e("/workspace/".concat(s))}catch(i){var a,l;const e=(null==i||null===(a=i.response)||void 0===a||null===(l=a.data)||void 0===l?void 0:l.detail)||i.message||"Failed to create workspace";e.includes("Workspace limit reached")?r("Workspace limit reached. You can create a maximum of 3 workspaces."):r(e)}finally{n(!1)}}else r("Workspace name is required")},className:"space-y-6",children:[(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsxs)(Ns,{htmlFor:"workspaceName",className:"text-sm font-medium text-slate-700",children:["Workspace Name ",(0,le.jsx)("span",{className:"text-red-500",children:"*"})]}),(0,le.jsx)(fs,{id:"workspaceName",type:"text",placeholder:"Enter your workspace name",value:t,onChange:e=>s(e.target.value),disabled:a,className:"w-full",maxLength:100}),(0,le.jsx)("p",{className:"text-xs text-slate-500",children:"Choose a name that represents your workspace"})]}),l&&(0,le.jsx)("div",{className:"p-3 bg-red-50 border border-red-200 rounded-md",children:(0,le.jsx)("p",{className:"text-sm text-red-600",children:l})}),(0,le.jsxs)("div",{className:"flex gap-3",children:[(0,le.jsx)(Yt,{type:"button",variant:"outline",onClick:()=>e(-1),disabled:a,className:"flex-1",children:"Cancel"}),(0,le.jsx)(Yt,{type:"submit",disabled:a||!t.trim(),className:"flex-1 bg-orange-500 hover:bg-orange-600 text-white",children:a?(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)("div",{className:"animate-spin rounded-full h-4 w-4 border-t-2 border-b-2 border-white mr-2"}),"Creating Workspace..."]}):(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(Xl.A,{className:"mr-2 h-4 w-4"}),"Create Workspace"]})})]})]})})]}),(0,le.jsx)(is,{className:"mt-6 bg-teal-50 border-teal-200",children:(0,le.jsx)(ms,{className:"pt-6",children:(0,le.jsxs)("div",{className:"flex items-start gap-3",children:[(0,le.jsx)("div",{className:"rounded-full bg-teal-100 p-2 mt-0.5",children:(0,le.jsx)(Xl.A,{className:"h-4 w-4 text-teal-600"})}),(0,le.jsxs)("div",{children:[(0,le.jsx)("h3",{className:"font-medium text-teal-900 mb-1",children:"What happens next?"}),(0,le.jsxs)("ul",{className:"text-sm text-teal-800 space-y-1",children:[(0,le.jsx)("li",{children:"\u2022 You'll be the workspace owner with full management permissions"}),(0,le.jsx)("li",{children:"\u2022 You can invite workspace members and manage seats"}),(0,le.jsx)("li",{children:"\u2022 Access your workspace dashboard to get started"})]})]})]})})})]})})}const xk=()=>{var e,t,s,a;const[n,l]=(0,Y.useState)(null),[r,i]=(0,Y.useState)(!0),[o,c]=(0,Y.useState)(!1),[d,m]=(0,Y.useState)(null),u=(0,Z.zy)(),x=(0,Z.Zp)(),{user:h,logout:p}=oe(),{switchActiveWorkspace:g,refetchWorkspaces:f}=ge(),v=new URLSearchParams(u.search).get("token");(0,Y.useEffect)(()=>{if(!v)return m("Invalid invitation link"),void i(!1);b()},[v]);const b=async()=>{try{const e=await xe.getInvitationDetails(v);l(e)}catch(s){var e,t;404===(null===(e=s.response)||void 0===e?void 0:e.status)?m("Invitation not found"):410===(null===(t=s.response)||void 0===t?void 0:t.status)?m("This invitation has expired"):m("Failed to load invitation details")}finally{i(!1)}};return r?(0,le.jsx)("div",{className:"min-h-screen bg-slate-50 flex items-center justify-center",children:(0,le.jsxs)("div",{className:"flex items-center gap-3 text-slate-600",children:[(0,le.jsx)(Ne.A,{className:"h-6 w-6 animate-spin"}),(0,le.jsx)("span",{children:"Loading invitation..."})]})}):d?(0,le.jsx)("div",{className:"min-h-screen bg-slate-50 flex items-center justify-center p-4",children:(0,le.jsxs)(is,{className:"w-full max-w-md",children:[(0,le.jsxs)(os,{className:"text-center",children:[(0,le.jsx)("div",{className:"mx-auto w-12 h-12 bg-red-100 rounded-full flex items-center justify-center mb-4",children:(0,le.jsx)(_e.A,{className:"h-6 w-6 text-red-600"})}),(0,le.jsx)(cs,{className:"text-red-900",children:"Invitation Error"}),(0,le.jsx)(ds,{className:"text-red-600",children:d})]}),(0,le.jsx)(ms,{children:(0,le.jsx)(Yt,{onClick:()=>x("/"),className:"w-full",variant:"outline",children:"Go to Homepage"})})]})}):(0,le.jsx)("div",{className:"min-h-screen bg-slate-50 flex items-center justify-center p-4",children:(0,le.jsxs)(is,{className:"w-full max-w-lg",children:[(0,le.jsxs)(os,{className:"text-center",children:[(0,le.jsx)("div",{className:"mx-auto w-16 h-16 bg-gradient-to-br from-orange-400 to-orange-600 rounded-full flex items-center justify-center mb-4",children:(0,le.jsx)(Xl.A,{className:"h-8 w-8 text-white"})}),(0,le.jsx)(cs,{className:"text-2xl text-slate-900",children:"You're Invited!"}),(0,le.jsx)(ds,{className:"text-slate-600",children:"Join your workspace and start collaborating"})]}),(0,le.jsxs)(ms,{className:"space-y-6",children:[(0,le.jsxs)("div",{className:"bg-slate-50 rounded-lg p-4 space-y-3",children:[(0,le.jsxs)("div",{className:"flex items-center gap-3",children:[(0,le.jsx)(Xl.A,{className:"h-5 w-5 text-slate-500"}),(0,le.jsxs)("div",{children:[(0,le.jsx)("p",{className:"font-semibold text-slate-900",children:n.workspace.name}),(0,le.jsx)("p",{className:"text-sm text-slate-600",children:n.workspace.domain})]})]}),(0,le.jsxs)("div",{className:"flex items-center gap-3",children:[(0,le.jsx)(Uh.A,{className:"h-5 w-5 text-slate-500"}),(0,le.jsxs)("div",{children:[(0,le.jsx)("p",{className:"text-sm text-slate-600",children:"Invited as"}),(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[(0,le.jsx)("span",{className:"font-medium text-slate-900",children:n.email}),(0,le.jsx)(es,{className:(e=>{switch(e){case"owner":return"bg-purple-100 text-purple-800 hover:bg-purple-200";case"admin":return"bg-blue-100 text-blue-800 hover:bg-blue-200";case"member":return"bg-green-100 text-green-800 hover:bg-green-200";default:return"bg-slate-100 text-slate-800 hover:bg-slate-200"}})(n.role),children:n.role})]})]})]}),n.expires_at&&(0,le.jsxs)("div",{className:"flex items-center gap-3",children:[(0,le.jsx)(bh.A,{className:"h-5 w-5 text-slate-500"}),(0,le.jsxs)("div",{children:[(0,le.jsx)("p",{className:"text-sm text-slate-600",children:"Expires"}),(0,le.jsx)("p",{className:"font-medium text-slate-900",children:(e=>{if(!e)return"";return new Date(e).toLocaleDateString("en-US",{year:"numeric",month:"long",day:"numeric",hour:"2-digit",minute:"2-digit"})})(n.expires_at)})]})]})]}),(null==h||null===(e=h.email)||void 0===e?void 0:e.toLowerCase())!==(null==n||null===(t=n.email)||void 0===t?void 0:t.toLowerCase())&&(0,le.jsxs)(De,{className:"border-amber-200 bg-amber-50",children:[(0,le.jsx)(_e.A,{className:"h-4 w-4 text-amber-600"}),(0,le.jsx)(Be,{className:"text-amber-800",children:(0,le.jsxs)("div",{className:"flex flex-col gap-3",children:[(0,le.jsxs)("div",{children:["This invitation was sent to ",(0,le.jsx)("strong",{children:n.email}),", but you're logged in as ",(0,le.jsx)("strong",{children:h.email}),". Please log in with the correct account to accept this invitation."]}),(0,le.jsx)(Yt,{onClick:async()=>{try{await p(),cr.toast.success("Logged out successfully. Please log in with the correct email address."),x("/login")}catch(e){cr.toast.error("Failed to log out")}},size:"sm",className:"self-start bg-amber-600 hover:bg-amber-700 text-white",disabled:o,children:o?(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(Ne.A,{className:"mr-2 h-3 w-3 animate-spin"}),"Logging out..."]}):"Logout & Login with Correct Email"})]})})]}),(null==h||null===(s=h.email)||void 0===s?void 0:s.toLowerCase())===(null==n||null===(a=n.email)||void 0===a?void 0:a.toLowerCase())&&(0,le.jsxs)("div",{className:"flex gap-3",children:[(0,le.jsx)(Yt,{onClick:async()=>{var e,t;if((null==h||null===(e=h.email)||void 0===e?void 0:e.toLowerCase())===(null==n||null===(t=n.email)||void 0===t?void 0:t.toLowerCase())){c(!0);try{var s;const e=await xe.acceptInvitation(v);await f(),null!==(s=e.workspace)&&void 0!==s&&s.id&&g(e.workspace.id),cr.toast.success("Welcome to ".concat(e.workspace.name,"!")),x("/")}catch(r){var a,l;const e=(null===(a=r.response)||void 0===a||null===(l=a.data)||void 0===l?void 0:l.detail)||r.message||"Failed to accept invitation";cr.toast.error(e)}finally{c(!1)}}else cr.toast.error("This invitation is for a different email address")},className:"flex-1 bg-gradient-to-r from-orange-500 to-orange-600 hover:from-orange-600 hover:to-orange-700 text-white",disabled:o,children:o?(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(Ne.A,{className:"mr-2 h-4 w-4 animate-spin"}),"Accepting..."]}):(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(Vg.A,{className:"mr-2 h-4 w-4"}),"Accept Invitation"]})}),(0,le.jsx)(Yt,{onClick:async()=>{c(!0);try{await xe.declineInvitation(v),cr.toast.success("Invitation declined"),x("/")}catch(s){var e,t;const a=(null===(e=s.response)||void 0===e||null===(t=e.data)||void 0===t?void 0:t.detail)||s.message||"Failed to decline invitation";cr.toast.error(a)}finally{c(!1)}},variant:"outline",className:"flex-1 border-slate-300 text-slate-700 hover:bg-slate-50",disabled:o,children:o?(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(Ne.A,{className:"mr-2 h-4 w-4 animate-spin"}),"Declining..."]}):(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(Gg.A,{className:"mr-2 h-4 w-4"}),"Decline"]})})]}),(0,le.jsx)("div",{className:"text-center",children:(0,le.jsx)("p",{className:"text-xs text-slate-500",children:"If you didn't expect this invitation, you can safely ignore it."})})]})]})})};var hk=s(12671),pk=s(54203),gk=s(72528);const fk={primary:"#0ea5e9",secondary:"#64748b",success:"#10b981",warning:"#f59e0b",danger:"#ef4444",purple:"#8b5cf6",teal:"#14b8a6",orange:"#f97316"},vk=[fk.primary,fk.teal,fk.purple,fk.warning,fk.orange,fk.danger],bk=e=>{let{title:t,value:s,description:a,icon:n,trend:l,color:r=fk.primary}=e;return(0,le.jsxs)(is,{children:[(0,le.jsxs)(os,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[(0,le.jsx)(cs,{className:"text-sm font-medium",children:t}),(0,le.jsx)(n,{className:"h-4 w-4",style:{color:r}})]}),(0,le.jsxs)(ms,{children:[(0,le.jsx)("div",{className:"text-2xl font-bold",children:s}),a&&(0,le.jsx)("p",{className:"text-xs text-muted-foreground",children:a}),l&&(0,le.jsxs)("div",{className:"flex items-center text-xs mt-2",children:[(0,le.jsx)(ya.A,{className:"h-3 w-3 mr-1",style:{color:l>0?fk.success:fk.danger}}),(0,le.jsxs)("span",{style:{color:l>0?fk.success:fk.danger},children:[Math.abs(l),"% from last period"]})]})]})]})},jk=e=>{let{ticketClass:t}=e;return(0,le.jsxs)(is,{className:"hover:shadow-lg transition-shadow",children:[(0,le.jsxs)(os,{children:[(0,le.jsx)(cs,{className:"text-lg",children:t.class_name}),(0,le.jsx)(ds,{children:t.description})]}),(0,le.jsxs)(ms,{className:"space-y-4",children:[(0,le.jsxs)("div",{children:[(0,le.jsx)("h4",{className:"text-sm font-semibold mb-2",children:"Example Tickets:"}),(0,le.jsx)("ul",{className:"text-sm text-muted-foreground space-y-1",children:t.example_titles.slice(0,3).map((e,t)=>(0,le.jsxs)("li",{className:"line-clamp-1",children:["\u2022 ",e]},t))})]}),(0,le.jsxs)("div",{children:[(0,le.jsx)("h4",{className:"text-sm font-semibold mb-2",children:"Common Issues:"}),(0,le.jsx)("div",{className:"flex flex-wrap gap-1",children:t.common_issues.slice(0,3).map((e,t)=>(0,le.jsx)(es,{variant:"secondary",className:"text-xs",children:e},t))})]}),t.suggested_improvements&&(0,le.jsxs)("div",{className:"pt-2 border-t",children:[(0,le.jsx)("h4",{className:"text-sm font-semibold mb-1 text-teal-700",children:"Suggested Improvements:"}),(0,le.jsx)("p",{className:"text-xs text-muted-foreground",children:t.suggested_improvements})]}),(0,le.jsxs)("div",{className:"text-xs text-muted-foreground",children:[t.ticket_ids.length," tickets in this category"]})]})]})};function yk(){const[e,t]=(0,Y.useState)(!0),[s,a]=(0,Y.useState)(!1),[n,l]=(0,Y.useState)(!1),[r,i]=(0,Y.useState)(null),[o,c]=(0,Y.useState)(null),[d,m]=(0,Y.useState)(null),[u,x]=(0,Y.useState)({preset:"last7days",startDate:ra()().subtract(7,"days").startOf("day").toISOString(),endDate:ra()().endOf("day").toISOString()}),[h,p]=(0,Y.useState)(null),g=[{value:"today",label:"Today",getDates:()=>({startDate:ra()().startOf("day").toISOString(),endDate:ra()().endOf("day").toISOString()})},{value:"yesterday",label:"Yesterday",getDates:()=>({startDate:ra()().subtract(1,"day").startOf("day").toISOString(),endDate:ra()().subtract(1,"day").endOf("day").toISOString()})},{value:"last2days",label:"Last 2 Days",getDates:()=>({startDate:ra()().subtract(2,"days").startOf("day").toISOString(),endDate:ra()().endOf("day").toISOString()})},{value:"last3days",label:"Last 3 Days",getDates:()=>({startDate:ra()().subtract(3,"days").startOf("day").toISOString(),endDate:ra()().endOf("day").toISOString()})},{value:"last7days",label:"Last 7 Days",getDates:()=>({startDate:ra()().subtract(7,"days").startOf("day").toISOString(),endDate:ra()().endOf("day").toISOString()})},{value:"last14days",label:"Last 14 Days",getDates:()=>({startDate:ra()().subtract(14,"days").startOf("day").toISOString(),endDate:ra()().endOf("day").toISOString()})},{value:"last30days",label:"Last 30 Days",getDates:()=>({startDate:ra()().subtract(30,"days").startOf("day").toISOString(),endDate:ra()().endOf("day").toISOString()})},{value:"last60days",label:"Last 60 Days",getDates:()=>({startDate:ra()().subtract(60,"days").startOf("day").toISOString(),endDate:ra()().endOf("day").toISOString()})},{value:"last90days",label:"Last 90 Days",getDates:()=>({startDate:ra()().subtract(90,"days").startOf("day").toISOString(),endDate:ra()().endOf("day").toISOString()})},{value:"thisWeek",label:"This Week",getDates:()=>({startDate:ra()().startOf("week").toISOString(),endDate:ra()().endOf("day").toISOString()})},{value:"lastWeek",label:"Last Week",getDates:()=>({startDate:ra()().subtract(1,"week").startOf("week").toISOString(),endDate:ra()().subtract(1,"week").endOf("week").toISOString()})},{value:"thisMonth",label:"This Month",getDates:()=>({startDate:ra()().startOf("month").toISOString(),endDate:ra()().endOf("day").toISOString()})},{value:"lastMonth",label:"Last Month",getDates:()=>({startDate:ra()().subtract(1,"month").startOf("month").toISOString(),endDate:ra()().subtract(1,"month").endOf("month").toISOString()})},{value:"thisQuarter",label:"This Quarter",getDates:()=>({startDate:ra()().startOf("quarter").toISOString(),endDate:ra()().endOf("day").toISOString()})},{value:"lastQuarter",label:"Last Quarter",getDates:()=>({startDate:ra()().subtract(1,"quarter").startOf("quarter").toISOString(),endDate:ra()().subtract(1,"quarter").endOf("quarter").toISOString()})},{value:"thisYear",label:"This Year",getDates:()=>({startDate:ra()().startOf("year").toISOString(),endDate:ra()().endOf("day").toISOString()})},{value:"lastYear",label:"Last Year",getDates:()=>({startDate:ra()().subtract(1,"year").startOf("year").toISOString(),endDate:ra()().subtract(1,"year").endOf("year").toISOString()})}];(0,Y.useEffect)(()=>{f()},[u]);const f=async()=>{try{t(!0),m(null);const e=await ww.getOperationalMetrics(u.startDate,u.endDate);i(e)}catch(e){m("Failed to load analytics data")}finally{t(!1)}},v=e=>e?e<1?"".concat(Math.round(60*e),"m"):e<24?"".concat(e.toFixed(1),"h"):"".concat(Math.round(e/24),"d"):"N/A",b=r?Object.entries(r.tickets_by_category).map(e=>{let[t,s]=e;return{name:"uncategorized"===t?"Uncategorized":t.replace(/_/g," "),value:s}}):[],j=r?Object.entries(r.tickets_by_user_tier).map(e=>{let[t,s]=e;return{name:"unknown"===t?"Unknown":t,value:s}}):[],y=(null==r?void 0:r.busiest_days)||[],N=(null==r?void 0:r.tickets_by_hour)||[];return e?(0,le.jsx)("div",{className:"h-full w-full flex items-center justify-center",children:(0,le.jsx)(Ne.A,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):d?(0,le.jsx)("div",{className:"h-full w-full flex items-center justify-center",children:(0,le.jsxs)(is,{className:"p-6",children:[(0,le.jsxs)("div",{className:"flex items-center space-x-2 text-red-600",children:[(0,le.jsx)(_e.A,{className:"h-5 w-5"}),(0,le.jsx)("p",{children:d})]}),(0,le.jsx)(Yt,{onClick:f,className:"mt-4",children:"Retry"})]})}):(0,le.jsxs)("div",{className:"container mx-auto py-6 space-y-6",children:[(0,le.jsxs)("div",{className:"flex items-center justify-between",children:[(0,le.jsxs)("div",{children:[(0,le.jsx)("h1",{className:"text-3xl font-bold text-slate-900",children:"Support Analytics"}),(0,le.jsx)("p",{className:"text-muted-foreground mt-1",children:"Analyze support ticket trends and performance metrics"}),(0,le.jsxs)("p",{className:"text-sm text-muted-foreground mt-2 flex items-center gap-1",children:[(0,le.jsx)(bh.A,{className:"h-3 w-3"}),ra()(u.startDate).format("MMM DD, YYYY")," - ",ra()(u.endDate).format("MMM DD, YYYY")]})]}),(0,le.jsxs)("div",{className:"flex items-center gap-3",children:[(0,le.jsxs)(zs,{value:u.preset,onValueChange:e=>{const t=g.find(t=>t.value===e);if(t){const s=t.getDates();x((0,K.A)({preset:e},s))}},children:[(0,le.jsxs)(qs,{className:"w-[200px]",children:[(0,le.jsx)(bh.A,{className:"h-4 w-4 mr-2"}),(0,le.jsx)(Ws,{})]}),(0,le.jsxs)(Ys,{className:"max-h-[400px]",children:[(0,le.jsx)("div",{className:"px-2 py-1.5 text-xs font-semibold text-muted-foreground",children:"Quick Ranges"}),g.slice(0,9).map(e=>(0,le.jsx)($s,{value:e.value,children:e.label},e.value)),(0,le.jsx)("div",{className:"my-1 h-px bg-border"}),(0,le.jsx)("div",{className:"px-2 py-1.5 text-xs font-semibold text-muted-foreground",children:"Weekly/Monthly"}),g.slice(9,13).map(e=>(0,le.jsx)($s,{value:e.value,children:e.label},e.value)),(0,le.jsx)("div",{className:"my-1 h-px bg-border"}),(0,le.jsx)("div",{className:"px-2 py-1.5 text-xs font-semibold text-muted-foreground",children:"Quarterly/Yearly"}),g.slice(13).map(e=>(0,le.jsx)($s,{value:e.value,children:e.label},e.value))]})]}),(0,le.jsxs)(Yt,{onClick:async()=>{try{a(!0),await ww.exportTicketsCSV(u.startDate,u.endDate,h)}catch(e){alert("Failed to export tickets")}finally{a(!1)}},disabled:s,variant:"outline",children:[s?(0,le.jsx)(Ne.A,{className:"h-4 w-4 animate-spin mr-2"}):(0,le.jsx)(Gx.A,{className:"h-4 w-4 mr-2"}),"Export CSV"]})]})]}),(0,le.jsxs)("div",{className:"grid gap-4 md:grid-cols-2 lg:grid-cols-4",children:[(0,le.jsx)(bk,{title:"Total Tickets",value:(null==r?void 0:r.total_tickets)||0,description:"".concat((null==r?void 0:r.open_tickets)||0," open, ").concat((null==r?void 0:r.resolved_tickets)||0," resolved"),icon:Ir.A,color:fk.primary}),(0,le.jsx)(bk,{title:"Avg Response Time",value:v(null==r?void 0:r.avg_response_time_hours),description:"First admin response",icon:Li.A,color:fk.teal}),(0,le.jsx)(bk,{title:"Avg Resolution Time",value:v(null==r?void 0:r.avg_resolution_time_hours),description:"Time to resolve tickets",icon:Vg.A,color:fk.success}),(0,le.jsx)(bk,{title:"Pending Admin Response",value:(null==r?void 0:r.tickets_pending_admin_response)||0,description:"".concat((null==r?void 0:r.tickets_pending_user_response)||0," pending user response"),icon:_e.A,color:fk.warning})]}),(0,le.jsxs)(kr,{defaultValue:"overview",className:"space-y-4",children:[(0,le.jsxs)(Cr,{children:[(0,le.jsx)(Ar,{value:"overview",children:"Overview"}),(0,le.jsx)(Ar,{value:"trends",children:"AI Trend Analysis"}),(0,le.jsx)(Ar,{value:"performance",children:"Performance"})]}),(0,le.jsxs)(Sr,{value:"overview",className:"space-y-4",children:[(0,le.jsxs)("div",{className:"grid gap-4 md:grid-cols-2",children:[(0,le.jsxs)(is,{children:[(0,le.jsxs)(os,{children:[(0,le.jsx)(cs,{children:"Tickets by Category"}),(0,le.jsx)(ds,{children:"Distribution of support tickets across categories"})]}),(0,le.jsx)(ms,{children:(0,le.jsx)("div",{className:"h-[300px]",children:(0,le.jsx)($u.u,{width:"100%",height:"100%",children:(0,le.jsxs)(hk.r,{children:[(0,le.jsx)(pk.F,{data:b,cx:"50%",cy:"50%",labelLine:!1,outerRadius:80,fill:"#8884d8",dataKey:"value",label:e=>{let{name:t,percent:s}=e;return"".concat(t," ").concat((100*s).toFixed(0),"%")},children:b.map((e,t)=>(0,le.jsx)(gk.f,{fill:vk[t%vk.length]},"cell-".concat(t)))}),(0,le.jsx)(Xu.m,{})]})})})})]}),(0,le.jsxs)(is,{children:[(0,le.jsxs)(os,{children:[(0,le.jsx)(cs,{children:"Tickets by User Tier"}),(0,le.jsx)(ds,{children:"Support requests by subscription tier"})]}),(0,le.jsx)(ms,{children:(0,le.jsx)("div",{className:"h-[300px]",children:(0,le.jsx)($u.u,{width:"100%",height:"100%",children:(0,le.jsxs)(Ju.E,{data:j,children:[(0,le.jsx)(Zu.d,{strokeDasharray:"3 3"}),(0,le.jsx)(Ku.W,{dataKey:"name"}),(0,le.jsx)(Qu.h,{}),(0,le.jsx)(Xu.m,{}),(0,le.jsx)(ex.y,{dataKey:"value",fill:fk.purple})]})})})})]})]}),(0,le.jsxs)(is,{children:[(0,le.jsxs)(os,{children:[(0,le.jsx)(cs,{children:"Ticket Volume Over Time"}),(0,le.jsx)(ds,{children:"Daily ticket creation trends"})]}),(0,le.jsx)(ms,{children:(0,le.jsx)("div",{className:"h-[300px]",children:(0,le.jsx)($u.u,{width:"100%",height:"100%",children:(0,le.jsxs)(ef.Q,{data:y,children:[(0,le.jsx)(Zu.d,{strokeDasharray:"3 3"}),(0,le.jsx)(Ku.W,{dataKey:"date",tickFormatter:e=>ra()(e).format("MMM DD")}),(0,le.jsx)(Qu.h,{}),(0,le.jsx)(Xu.m,{labelFormatter:e=>ra()(e).format("MMMM DD, YYYY")}),(0,le.jsx)(tf.G,{type:"monotone",dataKey:"count",stroke:fk.primary,fill:fk.primary,fillOpacity:.3,name:"Tickets"})]})})})})]}),(0,le.jsxs)(is,{children:[(0,le.jsxs)(os,{children:[(0,le.jsx)(cs,{children:"Tickets by Hour of Day"}),(0,le.jsx)(ds,{children:"When support tickets are typically created"})]}),(0,le.jsx)(ms,{children:(0,le.jsx)("div",{className:"h-[300px]",children:(0,le.jsx)($u.u,{width:"100%",height:"100%",children:(0,le.jsxs)(Ju.E,{data:N,children:[(0,le.jsx)(Zu.d,{strokeDasharray:"3 3"}),(0,le.jsx)(Ku.W,{dataKey:"label",angle:-45,textAnchor:"end",height:60}),(0,le.jsx)(Qu.h,{}),(0,le.jsx)(Xu.m,{labelFormatter:e=>"Hour: ".concat(e),formatter:e=>["".concat(e," tickets"),"Count"]}),(0,le.jsx)(ex.y,{dataKey:"count",fill:fk.teal,radius:[4,4,0,0]})]})})})})]})]}),(0,le.jsx)(Sr,{value:"trends",className:"space-y-4",children:(0,le.jsxs)(is,{children:[(0,le.jsxs)(os,{children:[(0,le.jsxs)(cs,{className:"flex items-center gap-2",children:[(0,le.jsx)(nj.A,{className:"h-5 w-5 text-purple-500"}),"AI-Powered Trend Analysis"]}),(0,le.jsx)(ds,{children:"Use AI to identify patterns and group similar tickets"})]}),(0,le.jsxs)(ms,{children:[(0,le.jsxs)("div",{className:"flex items-center gap-3 mb-4",children:[(0,le.jsxs)(zs,{value:h||"all",onValueChange:e=>p("all"===e?null:e),children:[(0,le.jsx)(qs,{className:"w-[200px]",children:(0,le.jsx)(Ws,{placeholder:"Filter by category"})}),(0,le.jsxs)(Ys,{children:[(0,le.jsx)($s,{value:"all",children:"All Categories"}),(0,le.jsx)($s,{value:"authentication",children:"Authentication"}),(0,le.jsx)($s,{value:"billing",children:"Billing"}),(0,le.jsx)($s,{value:"bug_report",children:"Bug Reports"}),(0,le.jsx)($s,{value:"integrations_and_backend_functions",children:"Integrations"}),(0,le.jsx)($s,{value:"chat_issues",children:"Chat Issues"}),(0,le.jsx)($s,{value:"security",children:"Security"}),(0,le.jsx)($s,{value:"other",children:"Other"})]})]}),(0,le.jsx)(Yt,{onClick:async()=>{try{l(!0),c(null);const e=await ww.runTrendAnalysis(u.startDate,u.endDate,h);c(e)}catch(e){alert("Failed to run trend analysis")}finally{l(!1)}},disabled:n,children:n?(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(Ne.A,{className:"h-4 w-4 animate-spin mr-2"}),"Analyzing..."]}):(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(Dx.A,{className:"h-4 w-4 mr-2"}),"Run Analysis"]})})]}),o&&(0,le.jsxs)("div",{className:"space-y-4",children:[(0,le.jsxs)("div",{className:"bg-slate-50 p-4 rounded-lg",children:[(0,le.jsx)("h3",{className:"font-semibold mb-2",children:"Analysis Summary"}),(0,le.jsx)("p",{className:"text-sm text-muted-foreground",children:o.analysis_summary}),(0,le.jsxs)("p",{className:"text-xs text-muted-foreground mt-2",children:["Analyzed ",o.total_tickets_analyzed," tickets"]})]}),(0,le.jsxs)("div",{children:[(0,le.jsx)("h3",{className:"font-semibold mb-3",children:"Identified Ticket Classes"}),(0,le.jsx)("div",{className:"grid gap-4 md:grid-cols-2",children:o.ticket_classes.map((e,t)=>(0,le.jsx)(jk,{ticketClass:e},t))})]}),o.recommendations&&o.recommendations.length>0&&(0,le.jsxs)("div",{className:"bg-teal-50 p-4 rounded-lg",children:[(0,le.jsx)("h3",{className:"font-semibold mb-2 text-teal-900",children:"Strategic Recommendations"}),(0,le.jsx)("ul",{className:"space-y-2",children:o.recommendations.map((e,t)=>(0,le.jsxs)("li",{className:"text-sm text-teal-800 flex items-start",children:[(0,le.jsx)("span",{className:"text-teal-600 mr-2",children:"\u2022"}),e]},t))})]})]}),!o&&!n&&(0,le.jsxs)("div",{className:"text-center py-12 text-muted-foreground",children:[(0,le.jsx)(Dx.A,{className:"h-12 w-12 mx-auto mb-3 text-slate-300"}),(0,le.jsx)("p",{children:'Click "Run Analysis" to generate AI insights'})]})]})]})}),(0,le.jsx)(Sr,{value:"performance",className:"space-y-4",children:(0,le.jsxs)("div",{className:"grid gap-4 md:grid-cols-2",children:[(0,le.jsxs)(is,{children:[(0,le.jsxs)(os,{children:[(0,le.jsx)(cs,{children:"Tickets by Assignee"}),(0,le.jsx)(ds,{children:"Workload distribution across team members"})]}),(0,le.jsx)(ms,{children:(0,le.jsx)("div",{className:"space-y-3",children:r&&Object.entries(r.tickets_by_assignee).map(e=>{let[t,s]=e;return(0,le.jsxs)("div",{className:"flex items-center justify-between",children:[(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[(0,le.jsx)(Xl.A,{className:"h-4 w-4 text-muted-foreground"}),(0,le.jsx)("span",{className:"text-sm",children:"unassigned"===t?"Unassigned":t})]}),(0,le.jsx)(es,{variant:"unassigned"===t?"secondary":"default",children:s})]},t)})})})]}),(0,le.jsxs)(is,{children:[(0,le.jsxs)(os,{children:[(0,le.jsx)(cs,{children:"Response Status"}),(0,le.jsx)(ds,{children:"Current pending responses breakdown"})]}),(0,le.jsx)(ms,{children:(0,le.jsxs)("div",{className:"space-y-4",children:[(0,le.jsxs)("div",{className:"flex items-center justify-between p-3 bg-orange-50 rounded-lg",children:[(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[(0,le.jsx)(_e.A,{className:"h-5 w-5 text-orange-600"}),(0,le.jsx)("span",{className:"font-medium",children:"Pending Admin"})]}),(0,le.jsx)("span",{className:"text-2xl font-bold text-orange-600",children:(null==r?void 0:r.tickets_pending_admin_response)||0})]}),(0,le.jsxs)("div",{className:"flex items-center justify-between p-3 bg-blue-50 rounded-lg",children:[(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[(0,le.jsx)(Li.A,{className:"h-5 w-5 text-blue-600"}),(0,le.jsx)("span",{className:"font-medium",children:"Pending User"})]}),(0,le.jsx)("span",{className:"text-2xl font-bold text-blue-600",children:(null==r?void 0:r.tickets_pending_user_response)||0})]})]})})]})]})})]})]})}const Nk=["className"],wk=["className"],_k=["className"],kk=["className"],Ck=["className"],Ak=["className"],Sk=["className"],Ek=["className"],Ik=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,Nk);return(0,le.jsx)("div",{className:"relative w-full overflow-auto",children:(0,le.jsx)("table",(0,K.A)({ref:t,className:Pe("w-full caption-bottom text-sm",s)},a))})});Ik.displayName="Table";const Tk=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,wk);return(0,le.jsx)("thead",(0,K.A)({ref:t,className:Pe("[&_tr]:border-b",s)},a))});Tk.displayName="TableHeader";const Pk=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,_k);return(0,le.jsx)("tbody",(0,K.A)({ref:t,className:Pe("[&_tr:last-child]:border-0",s)},a))});Pk.displayName="TableBody";Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,kk);return(0,le.jsx)("tfoot",(0,K.A)({ref:t,className:Pe("border-t bg-muted/50 font-medium [&>tr]:last:border-b-0",s)},a))}).displayName="TableFooter";const Lk=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,Ck);return(0,le.jsx)("tr",(0,K.A)({ref:t,className:Pe("border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",s)},a))});Lk.displayName="TableRow";const Ok=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,Ak);return(0,le.jsx)("th",(0,K.A)({ref:t,className:Pe("h-12 px-4 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0",s)},a))});Ok.displayName="TableHead";const Rk=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,Sk);return(0,le.jsx)("td",(0,K.A)({ref:t,className:Pe("p-4 align-middle [&:has([role=checkbox])]:pr-0",s)},a))});Rk.displayName="TableCell";Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,Ek);return(0,le.jsx)("caption",(0,K.A)({ref:t,className:Pe("mt-4 text-sm text-muted-foreground",s)},a))}).displayName="TableCaption";const Mk=[{label:"English",value:"en"},{label:"Deutsch",value:"de"},{label:"Espa\xf1ol",value:"es"},{label:"Fran\xe7ais",value:"fr"},{label:"Italiano",value:"it"},{label:"\u65e5\u672c\u8a9e",value:"ja"},{label:"\u4e2d\u6587",value:"zh"},{label:"\u0939\u093f\u0928\u094d\u0926\u0940",value:"hi"},{label:"Portugu\xeas",value:"pt"},{label:"\u05e2\u05d1\u05e8\u05d9\u05ea",value:"he"},{label:"\u0627\u0644\u0639\u0631\u0628\u064a\u0629",value:"ar"},{label:"Bahasa Indonesia",value:"id"}];function Dk(){var e,t,s,a;const{user:n}=oe(),[l,r]=(0,Y.useState)([]),[i,o]=(0,Y.useState)(!1),[c,d]=(0,Y.useState)(""),[m,u]=(0,Y.useState)({key:"created_date",direction:"desc"}),[x,h]=(0,Y.useState)(null),[p,g]=(0,Y.useState)({}),[f,v]=(0,Y.useState)({}),[b,j]=(0,Y.useState)(new Set),[y,N]=(0,Y.useState)("all"),[w,_]=(0,Y.useState)("en"),[k,C]=(0,Y.useState)("all"),[A,S]=(0,Y.useState)(""),[E,I]=(0,Y.useState)(""),[T,P]=(0,Y.useState)(1),[L,O]=(0,Y.useState)(0),R=100,[M,D]=(0,Y.useState)(!1),[F,B]=(0,Y.useState)([]),[z,U]=(0,Y.useState)(!1),[W,q]=(0,Y.useState)({isOpen:!1,action:null,item:null}),[V,H]=(0,Y.useState)(""),[G,$]=(0,Y.useState)("en"),[J,Z]=(0,Y.useState)({isOpen:!1,imageUrl:"",imageAlt:""});(0,Y.useEffect)(()=>{Q()},[]),(0,Y.useEffect)(()=>{if(x&&clearTimeout(x),1===T)return h(setTimeout(()=>{Q()},500)),()=>{x&&clearTimeout(x)};P(1)},[c,y,w,k,A,E,m]),(0,Y.useEffect)(()=>{Q()},[T]);const Q=async()=>{o(!0);try{let e={};if(c&&(e.$or=[{name:{$regex:c,$options:"i"}},{description:{$regex:c,$options:"i"}},{categories:{$regex:c,$options:"i"}},{created_by:{$regex:c,$options:"i"}}]),y&&"all"!==y&&(e.status=y),w&&("en"===w?c?(e.$and=[e.$or?{$or:e.$or}:{},{$or:[{language:"en"},{language:{$exists:!1}},{language:null}]}],delete e.$or):e.$or=[{language:"en"},{language:{$exists:!1}},{language:null}]:e.language=w),"all"!==k){const t=ra()();let s;switch(k){case"today":s=t.clone().startOf("day"),e.created_at={$gte:s.toISOString()};break;case"week":s=t.clone().subtract(7,"days").startOf("day"),e.created_at={$gte:s.toISOString()};break;case"month":s=t.clone().subtract(30,"days").startOf("day"),e.created_at={$gte:s.toISOString()};break;case"custom":A&&E?e.created_at={$gte:ra()(A).startOf("day").toISOString(),$lte:ra()(E).endOf("day").toISOString()}:A?e.created_at={$gte:ra()(A).startOf("day").toISOString()}:E&&(e.created_at={$lte:ra()(E).endOf("day").toISOString()})}}const t=await $a.listCatalogItems((0,K.A)((0,K.A)({},e),{},{limit:R,skip:(T-1)*R,sort_by:"desc"===m.direction?"-".concat(m.key):m.key})),s=t.items||t;r(s),s.length{$(t.item.language||"en"),q({isOpen:!0,action:e,item:t})},ee=()=>{q({isOpen:!1,action:null,item:null}),H("")},te=e=>{const t=m.key===e&&"asc"===m.direction?"desc":"asc";u({key:e,direction:t}),P(1)},se=()=>"all"!==y||"en"!==w||"all"!==k||""!==c||""!==A||""!==E,ae=e=>{const t=Mk.find(t=>t.value===e);return t?t.label:e},ne=e=>{switch(e){case"approved":return(0,le.jsxs)(Nn,{className:"bg-emerald-100 text-emerald-700 border-emerald-200 font-medium px-2.5 py-0.5 text-xs",children:[(0,le.jsx)("div",{className:"w-1.5 h-1.5 bg-emerald-500 rounded-full mr-1.5"}),"Approved"]});case"pending":return(0,le.jsxs)(Nn,{className:"bg-amber-100 text-amber-700 border-amber-200 font-medium px-2.5 py-0.5 text-xs",children:[(0,le.jsx)(Li.A,{className:"w-3 h-3 mr-1.5"}),"Pending"]});case"rejected":return(0,le.jsxs)(Nn,{className:"bg-red-100 text-red-700 border-red-200 font-medium px-2.5 py-0.5 text-xs",children:[(0,le.jsx)("div",{className:"w-1.5 h-1.5 bg-red-500 rounded-full mr-1.5"}),"Rejected"]});case"archived":return(0,le.jsxs)(Nn,{className:"bg-gray-100 text-gray-700 border-gray-200 font-medium px-2.5 py-0.5 text-xs",children:[(0,le.jsx)(YN.A,{className:"w-3 h-3 mr-1.5"}),"Archived"]});default:return(0,le.jsx)(Nn,{variant:"secondary",className:"font-medium px-2.5 py-0.5 text-xs",children:e})}};return null!=n&&null!==(e=n.platform_role)&&void 0!==e&&e.includes("admin")?(0,le.jsxs)("div",{className:"container mx-auto py-10 px-4",children:[(0,le.jsxs)("div",{className:"flex items-center justify-between mb-6",children:[(0,le.jsx)("h1",{className:"text-3xl font-bold",children:"App Templates Management"}),(0,le.jsxs)(Hn,{onClick:()=>M?D(!1):(async()=>{U(!0);try{const e=await $a.listCatalogItems({limit:1e4,skip:0,sort_by:"-created_date"}),t=e.items||e;B(t),D(!0)}catch(e){an({title:"Error",description:"Failed to fetch analytics data",variant:"destructive"})}finally{U(!1)}})(),disabled:z,className:"flex items-center gap-2",variant:M?"default":"outline",children:[(0,le.jsx)(Dx.A,{className:"h-4 w-4"}),z?"Analyzing...":M?"Hide Analytics":"Analyze"]})]}),M&&F.length>0&&(0,le.jsxs)("div",{className:"mb-8 bg-gradient-to-br from-slate-50 to-white p-8 rounded-2xl border border-slate-200 shadow-lg",children:[(0,le.jsxs)("div",{className:"flex items-center justify-between mb-8",children:[(0,le.jsxs)("div",{className:"flex items-center gap-3",children:[(0,le.jsx)("div",{className:"p-2 bg-blue-100 rounded-xl",children:(0,le.jsx)(Dx.A,{className:"h-6 w-6 text-blue-600"})}),(0,le.jsxs)("div",{children:[(0,le.jsx)("h2",{className:"text-2xl font-bold text-slate-900",children:"Analytics Dashboard"}),(0,le.jsxs)("p",{className:"text-sm text-slate-600 mt-1",children:["Real-time insights across ",F.length," catalog items"]})]})]}),(0,le.jsx)(Hn,{variant:"ghost",size:"sm",onClick:()=>D(!1),className:"h-10 w-10 p-0 hover:bg-slate-100 rounded-xl",children:(0,le.jsx)(Bt.A,{className:"h-5 w-5 text-slate-400"})})]}),(()=>{const e=(e=>{const t={total:e.length,approved:e.filter(e=>"approved"===e.item.status).length,pending:e.filter(e=>"pending"===e.item.status).length,rejected:e.filter(e=>"rejected"===e.item.status).length,archived:e.filter(e=>e.item.archived).length},s=e.reduce((e,t)=>{const s=t.item.language||"en";return e[s]=(e[s]||0)+1,e},{}),a={totalUsage:e.reduce((e,t)=>e+t.usage,0),averageUsage:e.length?e.reduce((e,t)=>e+t.usage,0)/e.length:0,topUsage:Math.max(...e.map(e=>e.usage),0),zeroUsage:e.filter(e=>0===e.usage).length},n={withDescriptions:e.filter(e=>e.item.description&&e.item.description.trim()).length,withScreenshots:e.filter(e=>e.item.screenshot_urls&&e.item.screenshot_urls.length>0).length,publicApps:e.filter(e=>!e.item.is_private).length,privateApps:e.filter(e=>e.item.is_private).length},l=e.reduce((e,t)=>{var s;const a=(null===(s=t.item_creator)||void 0===s?void 0:s.full_name)||"Unknown";return e[a]=(e[a]||0)+1,e},{}),r=e.reduce((e,t)=>{var s;return null===(s=t.item.categories)||void 0===s||s.forEach(t=>{e[t]=(e[t]||0)+1}),e},{}),i=ra()(),o=e.filter(e=>ra()(e.item.created_date).isSame(i,"month")).length,c=e.filter(e=>ra()(e.item.created_date).isSame(i,"quarter")).length;return{statusStats:t,languageStats:s,usageStats:a,contentStats:n,creatorStats:Object.entries(l).sort((e,t)=>{let[,s]=e,[,a]=t;return a-s}).slice(0,10),categories:Object.entries(r).sort((e,t)=>{let[,s]=e,[,a]=t;return a-s}).slice(0,10),temporalStats:{thisMonth:o,thisQuarter:c,totalCreators:Object.keys(l).length}}})(F);return(0,le.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6",children:[(0,le.jsxs)("div",{className:"bg-white p-6 rounded-xl border border-slate-200 shadow-sm hover:shadow-md transition-shadow",children:[(0,le.jsxs)("div",{className:"flex items-center gap-3 mb-6",children:[(0,le.jsx)("div",{className:"p-2 bg-emerald-100 rounded-lg",children:(0,le.jsx)(nj.A,{className:"h-5 w-5 text-emerald-600"})}),(0,le.jsxs)("div",{children:[(0,le.jsx)("h3",{className:"font-semibold text-slate-800",children:"Status Overview"}),(0,le.jsx)("p",{className:"text-xs text-slate-500",children:"Approval pipeline health"})]})]}),(0,le.jsxs)("div",{className:"space-y-4",children:[(0,le.jsxs)("div",{className:"text-center p-4 bg-slate-50 rounded-lg",children:[(0,le.jsx)("div",{className:"text-3xl font-bold text-slate-900",children:e.statusStats.total}),(0,le.jsx)("div",{className:"text-sm text-slate-600 font-medium",children:"Total Apps"})]}),(0,le.jsxs)("div",{className:"space-y-3",children:[(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsxs)("div",{className:"flex justify-between items-center",children:[(0,le.jsx)("span",{className:"text-sm font-medium text-emerald-700",children:"Approved"}),(0,le.jsxs)("span",{className:"text-sm font-bold text-emerald-700",children:[e.statusStats.approved," (",(e.statusStats.approved/e.statusStats.total*100).toFixed(1),"%)"]})]}),(0,le.jsx)("div",{className:"w-full bg-emerald-100 rounded-full h-2",children:(0,le.jsx)("div",{className:"bg-emerald-500 h-2 rounded-full transition-all duration-500",style:{width:"".concat(e.statusStats.approved/e.statusStats.total*100,"%")}})})]}),(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsxs)("div",{className:"flex justify-between items-center",children:[(0,le.jsx)("span",{className:"text-sm font-medium text-amber-700",children:"Pending"}),(0,le.jsxs)("span",{className:"text-sm font-bold text-amber-700",children:[e.statusStats.pending," (",(e.statusStats.pending/e.statusStats.total*100).toFixed(1),"%)"]})]}),(0,le.jsx)("div",{className:"w-full bg-amber-100 rounded-full h-2",children:(0,le.jsx)("div",{className:"bg-amber-500 h-2 rounded-full transition-all duration-500",style:{width:"".concat(e.statusStats.pending/e.statusStats.total*100,"%")}})})]}),(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsxs)("div",{className:"flex justify-between items-center",children:[(0,le.jsx)("span",{className:"text-sm font-medium text-red-700",children:"Rejected"}),(0,le.jsxs)("span",{className:"text-sm font-bold text-red-700",children:[e.statusStats.rejected," (",(e.statusStats.rejected/e.statusStats.total*100).toFixed(1),"%)"]})]}),(0,le.jsx)("div",{className:"w-full bg-red-100 rounded-full h-2",children:(0,le.jsx)("div",{className:"bg-red-500 h-2 rounded-full transition-all duration-500",style:{width:"".concat(e.statusStats.rejected/e.statusStats.total*100,"%")}})})]})]})]})]}),(0,le.jsxs)("div",{className:"bg-white p-6 rounded-xl border border-slate-200 shadow-sm hover:shadow-md transition-shadow",children:[(0,le.jsxs)("div",{className:"flex items-center gap-3 mb-6",children:[(0,le.jsx)("div",{className:"p-2 bg-blue-100 rounded-lg",children:(0,le.jsx)(or.A,{className:"h-5 w-5 text-blue-600"})}),(0,le.jsxs)("div",{children:[(0,le.jsx)("h3",{className:"font-semibold text-slate-800",children:"Usage Analytics"}),(0,le.jsx)("p",{className:"text-xs text-slate-500",children:"Clone and adoption metrics"})]})]}),(0,le.jsxs)("div",{className:"space-y-4",children:[(0,le.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,le.jsxs)("div",{className:"text-center p-3 bg-gradient-to-br from-blue-50 to-blue-100 rounded-lg",children:[(0,le.jsx)("div",{className:"text-2xl font-bold text-blue-900",children:e.usageStats.totalUsage.toLocaleString()}),(0,le.jsx)("div",{className:"text-xs text-blue-700 font-medium",children:"Total Clones"})]}),(0,le.jsxs)("div",{className:"text-center p-3 bg-gradient-to-br from-indigo-50 to-indigo-100 rounded-lg",children:[(0,le.jsx)("div",{className:"text-2xl font-bold text-indigo-900",children:e.usageStats.averageUsage.toFixed(1)}),(0,le.jsx)("div",{className:"text-xs text-indigo-700 font-medium",children:"Avg per App"})]})]}),(0,le.jsxs)("div",{className:"p-4 bg-slate-50 rounded-lg border-l-4 border-green-500",children:[(0,le.jsxs)("div",{className:"flex justify-between items-center",children:[(0,le.jsx)("span",{className:"text-sm font-medium text-slate-700",children:"Top Performer"}),(0,le.jsx)("span",{className:"text-lg font-bold text-green-600",children:e.usageStats.topUsage.toLocaleString()})]}),(0,le.jsx)("div",{className:"text-xs text-slate-500 mt-1",children:"Most cloned app"})]}),(0,le.jsxs)("div",{className:"p-4 bg-orange-50 rounded-lg border-l-4 border-orange-500",children:[(0,le.jsxs)("div",{className:"flex justify-between items-center",children:[(0,le.jsx)("span",{className:"text-sm font-medium text-slate-700",children:"Zero Usage"}),(0,le.jsx)("span",{className:"text-lg font-bold text-orange-600",children:e.usageStats.zeroUsage})]}),(0,le.jsxs)("div",{className:"text-xs text-slate-500 mt-1",children:[(e.usageStats.zeroUsage/e.statusStats.total*100).toFixed(1),"% of total apps"]})]})]})]}),(0,le.jsxs)("div",{className:"bg-white p-6 rounded-xl border border-slate-200 shadow-sm hover:shadow-md transition-shadow",children:[(0,le.jsxs)("div",{className:"flex items-center gap-3 mb-6",children:[(0,le.jsx)("div",{className:"p-2 bg-purple-100 rounded-lg",children:(0,le.jsx)(hf.A,{className:"h-5 w-5 text-purple-600"})}),(0,le.jsxs)("div",{children:[(0,le.jsx)("h3",{className:"font-semibold text-slate-800",children:"Content Quality"}),(0,le.jsx)("p",{className:"text-xs text-slate-500",children:"Completeness metrics"})]})]}),(0,le.jsxs)("div",{className:"space-y-4",children:[(0,le.jsxs)("div",{className:"space-y-3",children:[(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsxs)("div",{className:"flex justify-between items-center",children:[(0,le.jsx)("span",{className:"text-sm font-medium text-slate-700",children:"With Descriptions"}),(0,le.jsxs)("span",{className:"text-sm font-bold text-slate-900",children:[(e.contentStats.withDescriptions/e.statusStats.total*100).toFixed(1),"%"]})]}),(0,le.jsx)("div",{className:"w-full bg-gray-200 rounded-full h-2",children:(0,le.jsx)("div",{className:"bg-gradient-to-r from-green-400 to-green-600 h-2 rounded-full transition-all duration-500",style:{width:"".concat(e.contentStats.withDescriptions/e.statusStats.total*100,"%")}})})]}),(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsxs)("div",{className:"flex justify-between items-center",children:[(0,le.jsx)("span",{className:"text-sm font-medium text-slate-700",children:"With Screenshots"}),(0,le.jsxs)("span",{className:"text-sm font-bold text-slate-900",children:[(e.contentStats.withScreenshots/e.statusStats.total*100).toFixed(1),"%"]})]}),(0,le.jsx)("div",{className:"w-full bg-gray-200 rounded-full h-2",children:(0,le.jsx)("div",{className:"bg-gradient-to-r from-blue-400 to-blue-600 h-2 rounded-full transition-all duration-500",style:{width:"".concat(e.contentStats.withScreenshots/e.statusStats.total*100,"%")}})})]})]}),(0,le.jsxs)("div",{className:"grid grid-cols-2 gap-3 pt-2",children:[(0,le.jsxs)("div",{className:"text-center p-3 bg-green-50 rounded-lg border border-green-200",children:[(0,le.jsx)("div",{className:"text-xl font-bold text-green-700",children:e.contentStats.publicApps}),(0,le.jsx)("div",{className:"text-xs text-green-600 font-medium",children:"Public"})]}),(0,le.jsxs)("div",{className:"text-center p-3 bg-orange-50 rounded-lg border border-orange-200",children:[(0,le.jsx)("div",{className:"text-xl font-bold text-orange-700",children:e.contentStats.privateApps}),(0,le.jsx)("div",{className:"text-xs text-orange-600 font-medium",children:"Private"})]})]})]})]}),(0,le.jsxs)("div",{className:"bg-white p-6 rounded-xl border border-slate-200 shadow-sm hover:shadow-md transition-shadow",children:[(0,le.jsxs)("div",{className:"flex items-center gap-3 mb-6",children:[(0,le.jsx)("div",{className:"p-2 bg-teal-100 rounded-lg",children:(0,le.jsx)(bn.A,{className:"h-5 w-5 text-teal-600"})}),(0,le.jsxs)("div",{children:[(0,le.jsx)("h3",{className:"font-semibold text-slate-800",children:"Language Distribution"}),(0,le.jsx)("p",{className:"text-xs text-slate-500",children:"Global reach insights"})]})]}),(0,le.jsx)("div",{className:"space-y-3",children:Object.entries(e.languageStats).sort((e,t)=>{let[,s]=e,[,a]=t;return a-s}).slice(0,6).map((t,s)=>{let[a,n]=t;const l=n/e.statusStats.total*100;return(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsxs)("div",{className:"flex justify-between items-center",children:[(0,le.jsx)("span",{className:"text-sm font-medium text-slate-700",children:ae(a)}),(0,le.jsxs)("span",{className:"text-sm font-bold text-slate-900",children:[n," (",l.toFixed(1),"%)"]})]}),(0,le.jsx)("div",{className:"w-full bg-gray-200 rounded-full h-2",children:(0,le.jsx)("div",{className:"".concat(["bg-blue-500","bg-green-500","bg-purple-500","bg-orange-500","bg-pink-500","bg-indigo-500"][s]," h-2 rounded-full transition-all duration-500"),style:{width:"".concat(l,"%")}})})]},a)})})]}),(0,le.jsxs)("div",{className:"bg-white p-6 rounded-xl border border-slate-200 shadow-sm hover:shadow-md transition-shadow",children:[(0,le.jsxs)("div",{className:"flex items-center gap-3 mb-6",children:[(0,le.jsx)("div",{className:"p-2 bg-rose-100 rounded-lg",children:(0,le.jsx)(Xl.A,{className:"h-5 w-5 text-rose-600"})}),(0,le.jsxs)("div",{children:[(0,le.jsx)("h3",{className:"font-semibold text-slate-800",children:"Top Creators"}),(0,le.jsx)("p",{className:"text-xs text-slate-500",children:"Most active contributors"})]})]}),(0,le.jsxs)("div",{className:"space-y-4",children:[(0,le.jsxs)("div",{className:"text-center p-3 bg-gradient-to-br from-rose-50 to-rose-100 rounded-lg",children:[(0,le.jsx)("div",{className:"text-2xl font-bold text-rose-900",children:e.temporalStats.totalCreators}),(0,le.jsx)("div",{className:"text-xs text-rose-700 font-medium",children:"Total Creators"})]}),(0,le.jsx)("div",{className:"space-y-3",children:e.creatorStats.slice(0,5).map((e,t)=>{let[s,a]=e;return(0,le.jsxs)("div",{className:"flex items-center justify-between p-3 bg-slate-50 rounded-lg",children:[(0,le.jsxs)("div",{className:"flex items-center gap-3",children:[(0,le.jsx)("div",{className:"w-8 h-8 bg-gradient-to-br from-blue-500 to-purple-600 rounded-full flex items-center justify-center text-white text-sm font-bold",children:t+1}),(0,le.jsx)("span",{className:"text-sm font-medium text-slate-700 truncate max-w-24",children:s})]}),(0,le.jsx)("div",{className:"flex items-center gap-2",children:(0,le.jsxs)("div",{className:"text-right",children:[(0,le.jsx)("div",{className:"text-sm font-bold text-slate-900",children:a}),(0,le.jsx)("div",{className:"text-xs text-slate-500",children:"apps"})]})})]},s)})})]})]}),(0,le.jsxs)("div",{className:"bg-white p-6 rounded-xl border border-slate-200 shadow-sm hover:shadow-md transition-shadow",children:[(0,le.jsxs)("div",{className:"flex items-center gap-3 mb-6",children:[(0,le.jsx)("div",{className:"p-2 bg-cyan-100 rounded-lg",children:(0,le.jsx)(bh.A,{className:"h-5 w-5 text-cyan-600"})}),(0,le.jsxs)("div",{children:[(0,le.jsx)("h3",{className:"font-semibold text-slate-800",children:"Recent Activity"}),(0,le.jsx)("p",{className:"text-xs text-slate-500",children:"Growth and trends"})]})]}),(0,le.jsxs)("div",{className:"space-y-4",children:[(0,le.jsxs)("div",{className:"grid grid-cols-1 gap-3",children:[(0,le.jsxs)("div",{className:"p-4 bg-gradient-to-r from-green-50 to-emerald-50 rounded-lg border border-green-200",children:[(0,le.jsxs)("div",{className:"flex justify-between items-center",children:[(0,le.jsx)("span",{className:"text-sm font-medium text-green-700",children:"This Month"}),(0,le.jsx)("span",{className:"text-xl font-bold text-green-900",children:e.temporalStats.thisMonth})]}),(0,le.jsx)("div",{className:"text-xs text-green-600 mt-1",children:"new submissions"})]}),(0,le.jsxs)("div",{className:"p-4 bg-gradient-to-r from-blue-50 to-cyan-50 rounded-lg border border-blue-200",children:[(0,le.jsxs)("div",{className:"flex justify-between items-center",children:[(0,le.jsx)("span",{className:"text-sm font-medium text-blue-700",children:"This Quarter"}),(0,le.jsx)("span",{className:"text-xl font-bold text-blue-900",children:e.temporalStats.thisQuarter})]}),(0,le.jsx)("div",{className:"text-xs text-blue-600 mt-1",children:"total submissions"})]})]}),e.categories.length>0&&(0,le.jsxs)("div",{className:"p-4 bg-gradient-to-br from-purple-50 to-pink-50 rounded-lg border border-purple-200",children:[(0,le.jsx)("div",{className:"text-sm font-medium text-purple-700 mb-2",children:"Most Popular Category"}),(0,le.jsx)("div",{className:"text-lg font-bold text-purple-900",children:e.categories[0][0]}),(0,le.jsxs)("div",{className:"text-xs text-purple-600 mt-1",children:[e.categories[0][1]," apps in this category"]})]})]})]})]})})()]}),(0,le.jsxs)("div",{className:"mb-8 space-y-4",children:[(0,le.jsx)("div",{className:"bg-white p-4 rounded-xl border border-gray-100 shadow-sm",children:(0,le.jsxs)("div",{className:"flex flex-col lg:flex-row gap-3 items-start lg:items-center justify-between",children:[(0,le.jsxs)("div",{className:"flex flex-col sm:flex-row gap-3 items-start sm:items-center flex-1",children:[(0,le.jsxs)("div",{className:"relative w-full sm:w-80",children:[(0,le.jsx)(vn.A,{className:"absolute left-3 top-2.5 h-4 w-4 text-gray-400"}),(0,le.jsx)(fn,{placeholder:"Search apps, creators, categories...",className:"pl-10 h-9 border-gray-200 focus:border-blue-500 focus:ring-blue-500/20 transition-all duration-200",value:c,onChange:e=>d(e.target.value)})]}),(0,le.jsxs)(In,{value:y,onValueChange:N,children:[(0,le.jsx)(Pn,{className:"w-36 h-9 border-gray-200 hover:border-gray-300 transition-colors",children:(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[(0,le.jsx)(nj.A,{className:"h-3.5 w-3.5 text-gray-400"}),(0,le.jsx)(Tn,{placeholder:"Status"})]})}),(0,le.jsxs)(Rn,{children:[(0,le.jsx)(Mn,{value:"all",children:"All Status"}),(0,le.jsx)(Mn,{value:"pending",children:"Pending"}),(0,le.jsx)(Mn,{value:"approved",children:"Approved"}),(0,le.jsx)(Mn,{value:"rejected",children:"Rejected"}),(0,le.jsx)(Mn,{value:"archived",children:"Archived"})]})]}),(0,le.jsxs)(In,{value:w,onValueChange:_,children:[(0,le.jsx)(Pn,{className:"w-40 h-9 border-gray-200 hover:border-gray-300 transition-colors",children:(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[(0,le.jsx)(bn.A,{className:"h-3.5 w-3.5 text-gray-400"}),(0,le.jsx)(Tn,{placeholder:"Language"})]})}),(0,le.jsx)(Rn,{children:Mk.map(e=>(0,le.jsx)(Mn,{value:e.value,children:e.label},e.value))})]}),se()&&(0,le.jsxs)(Hn,{variant:"outline",size:"sm",onClick:()=>{N("all"),_("en"),C("all"),S(""),I(""),d(""),P(1)},className:"h-9 px-3 text-gray-600 border-gray-200 hover:bg-gray-50 hover:text-gray-900 transition-all duration-200",children:[(0,le.jsx)(Bt.A,{className:"h-3.5 w-3.5 mr-1"}),"Clear"]})]}),(0,le.jsxs)("div",{className:"flex items-center gap-2 text-sm text-gray-500 bg-gray-50 px-3 py-1.5 rounded-lg",children:[(0,le.jsx)(hf.A,{className:"h-3.5 w-3.5"}),L>0?"".concat(L," total apps"):"".concat(l.length," apps")]})]})}),"custom"===k&&(0,le.jsx)("div",{className:"bg-blue-50 p-4 rounded-lg border border-blue-100",children:(0,le.jsxs)("div",{className:"flex gap-4 items-center",children:[(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[(0,le.jsx)("label",{className:"text-sm font-medium text-gray-700",children:"From:"}),(0,le.jsx)(fn,{type:"date",value:A,onChange:e=>S(e.target.value),className:"w-40 h-8 border-gray-200 focus:border-blue-500 focus:ring-blue-500/20"})]}),(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[(0,le.jsx)("label",{className:"text-sm font-medium text-gray-700",children:"To:"}),(0,le.jsx)(fn,{type:"date",value:E,onChange:e=>I(e.target.value),className:"w-40 h-8 border-gray-200 focus:border-blue-500 focus:ring-blue-500/20"})]})]})}),se()&&(0,le.jsxs)("div",{className:"flex flex-wrap gap-2 items-center p-3 bg-gradient-to-r from-blue-50 to-indigo-50 rounded-lg border border-blue-100",children:[(0,le.jsxs)("span",{className:"text-sm font-medium text-gray-700 flex items-center gap-1",children:[(0,le.jsx)(Rb.A,{className:"h-3.5 w-3.5"}),"Active filters:"]}),"all"!==y&&(0,le.jsxs)(Nn,{className:"bg-blue-100 text-blue-800 hover:bg-blue-200 transition-colors",children:["Status: ",y,(0,le.jsx)("button",{onClick:()=>N("all"),className:"ml-1 hover:bg-blue-300 rounded-full p-0.5 transition-colors",children:(0,le.jsx)(Bt.A,{className:"h-3 w-3"})})]}),"en"!==w&&(0,le.jsxs)(Nn,{className:"bg-teal-100 text-teal-800 hover:bg-teal-200 transition-colors",children:["Language: ",ae(w),(0,le.jsx)("button",{onClick:()=>_("en"),className:"ml-1 hover:bg-teal-300 rounded-full p-0.5 transition-colors",children:(0,le.jsx)(Bt.A,{className:"h-3 w-3"})})]}),"all"!==k&&(0,le.jsxs)(Nn,{className:"bg-purple-100 text-purple-800 hover:bg-purple-200 transition-colors",children:["Date: ","custom"===k?"Custom":k,(0,le.jsx)("button",{onClick:()=>C("all"),className:"ml-1 hover:bg-purple-300 rounded-full p-0.5 transition-colors",children:(0,le.jsx)(Bt.A,{className:"h-3 w-3"})})]}),c&&(0,le.jsxs)(Nn,{className:"bg-green-100 text-green-800 hover:bg-green-200 transition-colors",children:['Search: "',c,'"',(0,le.jsx)("button",{onClick:()=>d(""),className:"ml-1 hover:bg-green-300 rounded-full p-0.5 transition-colors",children:(0,le.jsx)(Bt.A,{className:"h-3 w-3"})})]})]})]}),(0,le.jsx)("div",{className:"bg-white rounded-xl border border-gray-200 shadow-sm overflow-hidden",children:(0,le.jsxs)(Ik,{children:[(0,le.jsx)(Tk,{children:(0,le.jsxs)(Lk,{children:[(0,le.jsx)(Ok,{className:"w-8"}),(0,le.jsx)(Ok,{className:"cursor-pointer",onClick:()=>te("name"),children:(0,le.jsxs)("div",{className:"flex items-center",children:["App Name",(0,le.jsx)(ny.A,{className:"ml-2 h-4 w-4"})]})}),(0,le.jsx)(Ok,{className:"cursor-pointer w-24",onClick:()=>te("item_creator"),children:(0,le.jsxs)("div",{className:"flex items-center",children:["Creator",(0,le.jsx)(ny.A,{className:"ml-2 h-4 w-4"})]})}),(0,le.jsx)(Ok,{className:"cursor-pointer",onClick:()=>te("status"),children:(0,le.jsxs)("div",{className:"flex items-center",children:["Status",(0,le.jsx)(ny.A,{className:"ml-2 h-4 w-4"})]})}),(0,le.jsx)(Ok,{className:"cursor-pointer w-40",onClick:()=>te("created_date"),children:(0,le.jsxs)("div",{className:"flex items-center",children:["Created Date",(0,le.jsx)(ny.A,{className:"ml-2 h-4 w-4"})]})}),(0,le.jsx)(Ok,{className:"cursor-pointer",onClick:()=>te("usage"),children:(0,le.jsxs)("div",{className:"flex items-center",children:["#Clones",(0,le.jsx)(ny.A,{className:"ml-2 h-4 w-4"})]})}),(0,le.jsx)(Ok,{className:"cursor-pointer",onClick:()=>te("is_private"),children:(0,le.jsxs)("div",{className:"flex items-center",children:["Privacy",(0,le.jsx)(ny.A,{className:"ml-2 h-4 w-4"})]})}),(0,le.jsx)(Ok,{className:"cursor-pointer",onClick:()=>te("language"),children:(0,le.jsxs)("div",{className:"flex items-center",children:["Language",(0,le.jsx)(ny.A,{className:"ml-2 h-4 w-4"})]})}),(0,le.jsx)(Ok,{children:"Actions"})]})}),(0,le.jsx)(Pk,{children:i?(0,le.jsx)(Lk,{children:(0,le.jsx)(Rk,{colSpan:9,className:"text-center py-8",children:"Loading apps..."})}):0===l.length?(0,le.jsx)(Lk,{children:(0,le.jsx)(Rk,{colSpan:9,className:"text-center py-8",children:"No apps found"})}):l.map(e=>{var t,s;return(0,le.jsxs)(le.Fragment,{children:[(0,le.jsxs)(Lk,{className:"hover:bg-gray-50/80 transition-colors duration-200 group h-12",children:[(0,le.jsx)(Rk,{className:"py-2",children:(0,le.jsx)(Hn,{variant:"ghost",size:"sm",onClick:()=>{return t=e.item.id,void j(e=>{const s=new Set(e);return s.has(t)?s.delete(t):s.add(t),s});var t},className:"h-6 w-6 p-0 rounded hover:bg-gray-100 transition-all duration-200 group",children:b.has(e.item.id)?(0,le.jsx)(Is.A,{className:"h-3 w-3 text-gray-600 group-hover:text-gray-900 transition-colors"}):(0,le.jsx)(rn.A,{className:"h-3 w-3 text-gray-600 group-hover:text-gray-900 transition-colors"})})}),(0,le.jsx)(Rk,{className:"font-medium py-2 text-sm",children:e.item.name}),(0,le.jsx)(Rk,{className:"py-2 text-xs w-24 truncate",children:e.item_creator.full_name}),(0,le.jsx)(Rk,{className:"py-2",children:ne(e.item.status)}),(0,le.jsx)(Rk,{className:"py-2 w-40",children:ra().utc(e.item.created_date).fromNow()}),(0,le.jsx)(Rk,{className:"py-2",children:(0,le.jsxs)("div",{className:"flex items-center gap-1 text-sm",children:[(0,le.jsx)(or.A,{className:"h-3 w-3 text-gray-500"}),e.usage||0]})}),(0,le.jsx)(Rk,{className:"py-2",children:(0,le.jsx)("div",{className:"flex items-center gap-1",children:e.item.is_private?(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(Mt.A,{className:"h-3 w-3 text-gray-500"}),(0,le.jsx)("span",{className:"text-xs text-gray-600",children:"Private"})]}):(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(bn.A,{className:"h-3 w-3 text-green-500"}),(0,le.jsx)("span",{className:"text-xs text-green-600",children:"Public"})]})})}),(0,le.jsx)(Rk,{className:"py-2",children:(0,le.jsx)("span",{className:"text-xs text-gray-700",children:ae(e.item.language||"en")})}),(0,le.jsx)(Rk,{className:"py-2",children:(0,le.jsxs)("div",{className:"flex gap-1",children:[(0,le.jsx)(Hn,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0 text-green-600 hover:text-green-700 hover:bg-green-50 rounded transition-all duration-200 group",onClick:t=>{t.stopPropagation(),X("approve",e)},disabled:p[e.item.id],title:"Approve",children:(0,le.jsx)(Ps.A,{className:"h-3.5 w-3.5 group-hover:scale-110 transition-transform"})}),(0,le.jsx)(Hn,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0 text-red-600 hover:text-red-700 hover:bg-red-50 rounded transition-all duration-200 group",onClick:t=>{t.stopPropagation(),X("decline",e)},disabled:p[e.item.id],title:"Decline",children:(0,le.jsx)(Bt.A,{className:"h-3.5 w-3.5 group-hover:scale-110 transition-transform"})}),(0,le.jsx)(Hn,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0 text-gray-600 hover:text-gray-700 hover:bg-gray-100 rounded transition-all duration-200 group",onClick:t=>{t.stopPropagation(),X("archive",e)},disabled:p[e.item.id],title:"Archive",children:(0,le.jsx)(YN.A,{className:"h-3.5 w-3.5 group-hover:scale-110 transition-transform"})}),(0,le.jsx)(Hn,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0 text-blue-600 hover:text-blue-700 hover:bg-blue-50 rounded transition-all duration-200 group",onClick:t=>{t.stopPropagation(),(async e=>{v(t=>(0,K.A)((0,K.A)({},t),{},{[e]:!0}));try{const t=await ve.getLoginInfoById(e),s="https://".concat(t.slug,".base44.app");window.open(s,"_blank")}catch(t){an({title:"Error",description:"Failed to open app",variant:"destructive"})}finally{v(t=>(0,K.A)((0,K.A)({},t),{},{[e]:!1}))}})(e.item.app_id)},disabled:f[e.item.app_id],title:"Open New Tab",children:(0,le.jsx)(Tr.A,{className:"h-3.5 w-3.5 group-hover:scale-110 transition-transform"})})]})})]},e.item.id),b.has(e.item.id)&&(0,le.jsx)(Lk,{children:(0,le.jsx)(Rk,{colSpan:9,className:"bg-gradient-to-br from-gray-50 to-gray-100/50 p-8 border-t border-gray-100",children:(0,le.jsxs)("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-8",children:[(0,le.jsxs)("div",{className:"space-y-6",children:[(0,le.jsxs)("div",{className:"bg-white p-4 rounded-lg border border-gray-200",children:[(0,le.jsxs)("h4",{className:"font-semibold text-gray-900 mb-3 flex items-center gap-2",children:[(0,le.jsx)("div",{className:"w-1 h-5 bg-blue-500 rounded-full"}),"Description"]}),(0,le.jsx)("div",{className:"text-sm text-gray-600 prose prose-sm max-w-none",dangerouslySetInnerHTML:{__html:dn(e.item.description||'

No description available

')}})]}),(0,le.jsxs)("div",{className:"bg-white p-4 rounded-lg border border-gray-200",children:[(0,le.jsxs)("h4",{className:"font-semibold text-gray-900 mb-3 flex items-center gap-2",children:[(0,le.jsx)("div",{className:"w-1 h-5 bg-green-500 rounded-full"}),"Technical Details"]}),(0,le.jsxs)("div",{className:"grid grid-cols-1 gap-3 text-sm",children:[(0,le.jsxs)("div",{className:"flex justify-between items-center py-2 border-b border-gray-100",children:[(0,le.jsx)("span",{className:"font-medium text-gray-700",children:"App ID:"}),(0,le.jsx)("code",{className:"text-gray-600 bg-gray-100 px-2 py-1 rounded text-xs",children:e.item.app_id})]}),(0,le.jsxs)("div",{className:"flex justify-between items-center py-2 border-b border-gray-100",children:[(0,le.jsx)("span",{className:"font-medium text-gray-700",children:"Organization:"}),(0,le.jsx)("code",{className:"text-gray-600 bg-gray-100 px-2 py-1 rounded text-xs",children:e.item.organization_id})]}),(0,le.jsxs)("div",{className:"flex justify-between items-center py-2 border-b border-gray-100",children:[(0,le.jsx)("span",{className:"font-medium text-gray-700",children:"Created:"}),(0,le.jsx)("span",{className:"text-gray-600",children:ra().utc(e.item.created_date).format("MMM DD, YYYY HH:mm")})]}),(0,le.jsxs)("div",{className:"flex justify-between items-center py-2",children:[(0,le.jsx)("span",{className:"font-medium text-gray-700",children:"Updated:"}),(0,le.jsx)("span",{className:"text-gray-600",children:ra().utc(e.item.updated_date).format("MMM DD, YYYY HH:mm")})]})]})]}),"rejected"===e.item.status&&e.item.rejected_reason&&(0,le.jsxs)("div",{className:"bg-red-50 p-4 rounded-lg border border-red-200",children:[(0,le.jsxs)("h4",{className:"font-semibold text-red-900 mb-3 flex items-center gap-2",children:[(0,le.jsx)("div",{className:"w-1 h-5 bg-red-500 rounded-full"}),"Rejection Reason"]}),(0,le.jsx)("div",{className:"text-sm text-red-800 bg-white p-3 rounded border border-red-200",children:e.item.rejected_reason})]}),(null===(t=e.item.categories)||void 0===t?void 0:t.length)>0&&(0,le.jsxs)("div",{className:"bg-white p-4 rounded-lg border border-gray-200",children:[(0,le.jsxs)("h4",{className:"font-semibold text-gray-900 mb-3 flex items-center gap-2",children:[(0,le.jsx)("div",{className:"w-1 h-5 bg-purple-500 rounded-full"}),"Categories"]}),(0,le.jsx)("div",{className:"flex flex-wrap gap-2",children:e.item.categories.map((e,t)=>(0,le.jsx)(Nn,{className:"bg-purple-50 text-purple-700 border-purple-200 hover:bg-purple-100 transition-colors",children:e},t))})]})]}),(0,le.jsxs)("div",{className:"bg-white p-4 rounded-lg border border-gray-200 h-fit",children:[(0,le.jsxs)("h4",{className:"font-semibold text-gray-900 mb-3 flex items-center gap-2",children:[(0,le.jsx)("div",{className:"w-1 h-5 bg-orange-500 rounded-full"}),"Screenshots"]}),(null===(s=e.item.screenshot_urls)||void 0===s?void 0:s.length)>0?(0,le.jsxs)("div",{className:"grid grid-cols-1 gap-4",children:[e.item.screenshot_urls.slice(0,3).map((t,s)=>(0,le.jsxs)("div",{className:"relative rounded-lg overflow-hidden border border-gray-200 group",children:[(0,le.jsx)("img",{src:t,alt:"Screenshot ".concat(s+1),className:"w-full h-36 object-cover group-hover:scale-105 transition-all duration-300 cursor-pointer",onClick:a=>{var n,l;a.stopPropagation(),n=t,l="".concat(e.item.name," - Screenshot ").concat(s+1),Z({isOpen:!0,imageUrl:n,imageAlt:l})}}),(0,le.jsx)("div",{className:"absolute inset-0 bg-black/0 group-hover:bg-black/10 transition-colors duration-300 flex items-center justify-center",children:(0,le.jsx)("div",{className:"opacity-0 group-hover:opacity-100 transition-opacity duration-300 bg-white/90 backdrop-blur-sm rounded-full p-2",children:(0,le.jsx)(hf.A,{className:"h-4 w-4 text-gray-700"})})})]},s)),e.item.screenshot_urls.length>3&&(0,le.jsx)("div",{className:"text-center py-2 bg-gray-50 rounded-lg border border-gray-200",children:(0,le.jsxs)("p",{className:"text-sm text-gray-600 font-medium",children:["+",e.item.screenshot_urls.length-3," more screenshots"]})})]}):(0,le.jsxs)("div",{className:"text-center py-8 text-gray-400 bg-gray-50 rounded-lg border-2 border-dashed border-gray-200",children:[(0,le.jsx)(hf.A,{className:"h-8 w-8 mx-auto mb-2 opacity-50"}),(0,le.jsx)("p",{className:"text-sm",children:"No screenshots available"})]})]})]})})})]})})})]})}),l.length>0&&(0,le.jsxs)("div",{className:"flex items-center justify-between py-4",children:[(0,le.jsx)("div",{className:"flex items-center gap-2 text-sm text-gray-500",children:(0,le.jsxs)("span",{children:["Showing ",(T-1)*R+1," to ",Math.min(T*R,L)," of ",L," items"]})}),(0,le.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,le.jsx)(Hn,{variant:"outline",size:"sm",onClick:()=>P(e=>Math.max(e-1,1)),disabled:1===T||i,className:"h-8 px-3",children:"Previous"}),(0,le.jsxs)("div",{className:"flex items-center gap-1",children:[T>2&&(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(Hn,{variant:"outline",size:"sm",onClick:()=>P(1),className:"h-8 w-8 p-0",children:"1"}),T>3&&(0,le.jsx)("span",{className:"px-1 text-gray-400",children:"..."})]}),T>1&&(0,le.jsx)(Hn,{variant:"outline",size:"sm",onClick:()=>P(e=>e-1),className:"h-8 w-8 p-0",children:T-1}),(0,le.jsx)(Hn,{variant:"default",size:"sm",className:"h-8 w-8 p-0",children:T}),l.length===R&&(0,le.jsx)(Hn,{variant:"outline",size:"sm",onClick:()=>P(e=>e+1),disabled:i,className:"h-8 w-8 p-0",children:T+1})]}),(0,le.jsx)(Hn,{variant:"outline",size:"sm",onClick:()=>P(e=>e+1),disabled:l.length{Z({isOpen:!1,imageUrl:"",imageAlt:""})},children:(0,le.jsxs)(lc,{className:"max-w-4xl max-h-[90vh] p-0 overflow-hidden z-[100]",children:[(0,le.jsx)(rc,{className:"p-6 pb-0",children:(0,le.jsx)(oc,{className:"text-lg font-semibold text-gray-900",children:J.imageAlt})}),(0,le.jsx)("div",{className:"p-6 pt-4",children:(0,le.jsx)("div",{className:"relative rounded-lg overflow-hidden bg-gray-100",children:(0,le.jsx)("img",{src:J.imageUrl,alt:J.imageAlt,className:"w-full max-h-[70vh] object-contain"})})})]})}),(0,le.jsx)(tc,{open:W.isOpen,onOpenChange:ee,children:(0,le.jsxs)(lc,{children:[(0,le.jsxs)(rc,{children:[(0,le.jsxs)(oc,{children:["approve"===W.action&&"Approve App Listing","decline"===W.action&&"Decline App Listing","archive"===W.action&&"Archive App Listing"]}),(0,le.jsxs)(cc,{children:["approve"===W.action&&(0,le.jsxs)(le.Fragment,{children:["Are you sure you want to approve ",(0,le.jsx)("strong",{children:null===(t=W.item)||void 0===t?void 0:t.item.name}),"?",(0,le.jsx)("br",{}),"This will make the app publicly visible in the catalog.",(0,le.jsxs)("div",{className:"mt-4",children:[(0,le.jsx)("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:"Language:"}),(0,le.jsxs)(In,{value:G,onValueChange:$,children:[(0,le.jsx)(Pn,{className:"w-full",children:(0,le.jsx)(Tn,{placeholder:"Select language"})}),(0,le.jsx)(Rn,{children:Mk.map(e=>(0,le.jsx)(Mn,{value:e.value,children:e.label},e.value))})]})]})]}),"decline"===W.action&&(0,le.jsxs)(le.Fragment,{children:["Are you sure you want to decline ",(0,le.jsx)("strong",{children:null===(s=W.item)||void 0===s?void 0:s.item.name}),"?",(0,le.jsx)("br",{}),"This will remove the app from public visibility in the catalog.",(0,le.jsxs)("div",{className:"mt-4",children:[(0,le.jsx)("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:"Reason for decline (optional):"}),(0,le.jsx)("textarea",{placeholder:"Enter reason for declining this app listing...",value:V,onChange:e=>H(e.target.value),className:"flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50"})]})]}),"archive"===W.action&&(0,le.jsxs)(le.Fragment,{children:["Are you sure you want to archive ",(0,le.jsx)("strong",{children:null===(a=W.item)||void 0===a?void 0:a.item.name}),"?",(0,le.jsx)("br",{}),"This will permanently remove the app from the catalog."]})]})]}),(0,le.jsxs)(ic,{children:[(0,le.jsx)(Hn,{variant:"outline",onClick:ee,children:"Cancel"}),(0,le.jsxs)(Hn,{onClick:async()=>{if(!W.action||!W.item)return;const{action:e,item:t}=W,s=t.item.id;g(e=>(0,K.A)((0,K.A)({},e),{},{[s]:!0})),ee();try{switch(e){case"approve":await $a.approveItem(s,G);break;case"decline":await $a.declineItem(s,V||void 0);break;case"archive":await $a.archiveItem(s)}an({title:"Success",description:"Item ".concat(e,"d successfully")}),await Q()}catch(a){an({title:"Error",description:"Failed to ".concat(e," item"),variant:"destructive"})}finally{g(e=>(0,K.A)((0,K.A)({},e),{},{[s]:!1}))}},className:"approve"===W.action?"bg-green-600 hover:bg-green-700":"decline"===W.action?"bg-red-600 hover:bg-red-700":"bg-gray-600 hover:bg-gray-700",children:["approve"===W.action&&"Approve","decline"===W.action&&"Decline","archive"===W.action&&"Archive"]})]})]})})]}):(0,le.jsx)("div",{className:"flex items-center justify-center h-screen",children:(0,le.jsxs)("div",{className:"text-center",children:[(0,le.jsx)(ay.A,{className:"w-16 h-16 text-red-500 mx-auto mb-4"}),(0,le.jsx)("h2",{className:"text-2xl font-bold text-gray-800",children:"Access Denied"}),(0,le.jsx)("p",{className:"text-gray-600",children:"You are not authorized to access this page"})]})})}function Fk(e){let{currentPage:t,totalPages:s,onPageChange:a}=e;return s<=1?null:(0,le.jsxs)("div",{className:"flex items-center justify-center space-x-2 mt-12",children:[(0,le.jsxs)(Hn,{variant:"outline",size:"sm",onClick:()=>a(Math.max(1,t-1)),disabled:1===t,className:"h-9 px-3",children:[(0,le.jsx)(Xs.A,{className:"w-4 h-4 mr-1"}),"Previous"]}),(0,le.jsx)("div",{className:"flex items-center space-x-1",children:Array.from({length:Math.min(s,7)},(e,n)=>{let l;return l=s<=7||t<=4?n+1:t>=s-3?s-6+n:t-3+n,(0,le.jsx)(Hn,{variant:t===l?"default":"outline",size:"sm",onClick:()=>a(l),className:"h-9 w-9 p-0",children:l},l)})}),(0,le.jsxs)(Hn,{variant:"outline",size:"sm",onClick:()=>a(Math.min(s,t+1)),disabled:t===s,className:"h-9 px-3",children:["Next",(0,le.jsx)(rn.A,{className:"w-4 h-4 ml-1"})]})]})}function Bk(){var e,t,s,a;const{user:n}=oe(),[l,r]=(0,Y.useState)([]),[i,o]=(0,Y.useState)(!1),[c,d]=(0,Y.useState)(""),[m,u]=(0,Y.useState)({key:"created_date",direction:"desc"}),[x,h]=(0,Y.useState)(null),[p,g]=(0,Y.useState)({}),[f,v]=(0,Y.useState)(new Set),[b,j]=(0,Y.useState)(1),[y,N]=(0,Y.useState)(20),[w,_]=(0,Y.useState)(0),[k,C]=(0,Y.useState)(1),[A,S]=(0,Y.useState)("all"),[E,I]=(0,Y.useState)("all"),[T,P]=(0,Y.useState)(""),[L,O]=(0,Y.useState)(""),[R,M]=(0,Y.useState)({isOpen:!1,action:null,item:null}),[D,F]=(0,Y.useState)("");(0,Y.useEffect)(()=>{B()},[]),(0,Y.useEffect)(()=>(x&&clearTimeout(x),h(setTimeout(()=>{B()},500)),()=>{x&&clearTimeout(x)}),[c,A,E,T,L,b,y]);const B=async()=>{o(!0);try{let e={limit:y,skip:(b-1)*y,sort_by:"".concat("desc"===m.direction?"-":"").concat(m.key)};if(c&&(e.$or=[{name:{$regex:c,$options:"i"}},{description:{$regex:c,$options:"i"}},{categories:{$regex:c,$options:"i"}},{created_by:{$regex:c,$options:"i"}}]),A&&"all"!==A&&(e.status=A),"all"!==E){const t=ra()();let s;switch(E){case"today":s=t.clone().startOf("day"),e.created_at={$gte:s.toISOString()};break;case"week":s=t.clone().subtract(7,"days").startOf("day"),e.created_at={$gte:s.toISOString()};break;case"month":s=t.clone().subtract(30,"days").startOf("day"),e.created_at={$gte:s.toISOString()};break;case"custom":T&&L?e.created_at={$gte:ra()(T).startOf("day").toISOString(),$lte:ra()(L).endOf("day").toISOString()}:T?e.created_at={$gte:ra()(T).startOf("day").toISOString()}:L&&(e.created_at={$lte:ra()(L).endOf("day").toISOString()})}}const t=await Kt.listCatalogItems(e),s=t.items||t,a=t.total||s.length;r(s),_(a),C(Math.ceil(a/y))}catch(e){an({title:"Error",description:"Failed to load catalog items",variant:"destructive"})}finally{o(!1)}},z=(e,t)=>{M({isOpen:!0,action:e,item:t})},U=()=>{M({isOpen:!1,action:null,item:null}),F("")},W=e=>{u({key:e,direction:m.key===e&&"asc"===m.direction?"desc":"asc"}),j(1)},q=()=>"all"!==A||"all"!==E||""!==c||""!==T||""!==L,V=e=>{switch(e){case"approved":return(0,le.jsxs)(Nn,{className:"bg-emerald-100 text-emerald-700 border-emerald-200 font-medium px-2.5 py-0.5 text-xs",children:[(0,le.jsx)("div",{className:"w-1.5 h-1.5 bg-emerald-500 rounded-full mr-1.5"}),"Approved"]});case"pending":return(0,le.jsxs)(Nn,{className:"bg-amber-100 text-amber-700 border-amber-200 font-medium px-2.5 py-0.5 text-xs",children:[(0,le.jsx)(Li.A,{className:"w-3 h-3 mr-1.5"}),"Pending"]});case"declined":return(0,le.jsxs)(Nn,{className:"bg-red-100 text-red-700 border-red-200 font-medium px-2.5 py-0.5 text-xs",children:[(0,le.jsx)("div",{className:"w-1.5 h-1.5 bg-red-500 rounded-full mr-1.5"}),"Declined"]});case"archived":return(0,le.jsxs)(Nn,{className:"bg-gray-100 text-gray-700 border-gray-200 font-medium px-2.5 py-0.5 text-xs",children:[(0,le.jsx)(YN.A,{className:"w-3 h-3 mr-1.5"}),"Archived"]});default:return(0,le.jsx)(Nn,{variant:"secondary",className:"font-medium px-2.5 py-0.5 text-xs",children:e})}},H=l;return null!=n&&null!==(e=n.platform_role)&&void 0!==e&&e.includes("admin")?(0,le.jsxs)("div",{className:"container mx-auto py-10 px-4",children:[(0,le.jsx)("h1",{className:"text-3xl font-bold mb-6",children:"Integration Catalog Management"}),(0,le.jsxs)("div",{className:"mb-8 space-y-4",children:[(0,le.jsx)("div",{className:"bg-white p-4 rounded-xl border border-gray-100 shadow-sm",children:(0,le.jsxs)("div",{className:"flex flex-col lg:flex-row gap-3 items-start lg:items-center justify-between",children:[(0,le.jsxs)("div",{className:"flex flex-col sm:flex-row gap-3 items-start sm:items-center flex-1",children:[(0,le.jsxs)("div",{className:"relative w-full sm:w-80",children:[(0,le.jsx)(vn.A,{className:"absolute left-3 top-2.5 h-4 w-4 text-gray-400"}),(0,le.jsx)(fn,{placeholder:"Search integrations, creators, categories...",className:"pl-10 h-9 border-gray-200 focus:border-blue-500 focus:ring-blue-500/20 transition-all duration-200",value:c,onChange:e=>d(e.target.value)})]}),(0,le.jsxs)(In,{value:A,onValueChange:S,children:[(0,le.jsx)(Pn,{className:"w-36 h-9 border-gray-200 hover:border-gray-300 transition-colors",children:(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[(0,le.jsx)(nj.A,{className:"h-3.5 w-3.5 text-gray-400"}),(0,le.jsx)(Tn,{placeholder:"Status"})]})}),(0,le.jsxs)(Rn,{children:[(0,le.jsx)(Mn,{value:"all",children:"All Status"}),(0,le.jsx)(Mn,{value:"pending",children:"Pending"}),(0,le.jsx)(Mn,{value:"approved",children:"Approved"}),(0,le.jsx)(Mn,{value:"declined",children:"Declined"}),(0,le.jsx)(Mn,{value:"archived",children:"Archived"})]})]}),q()&&(0,le.jsxs)(Hn,{variant:"outline",size:"sm",onClick:()=>{S("all"),I("all"),P(""),O(""),d(""),j(1)},className:"h-9 px-3 text-gray-600 border-gray-200 hover:bg-gray-50 hover:text-gray-900 transition-all duration-200",children:[(0,le.jsx)(Bt.A,{className:"h-3.5 w-3.5 mr-1"}),"Clear"]})]}),(0,le.jsxs)("div",{className:"flex items-center gap-2 text-sm text-gray-500 bg-gray-50 px-3 py-1.5 rounded-lg",children:[(0,le.jsx)(hf.A,{className:"h-3.5 w-3.5"}),w," total integrations"]})]})}),"custom"===E&&(0,le.jsx)("div",{className:"bg-blue-50 p-4 rounded-lg border border-blue-100",children:(0,le.jsxs)("div",{className:"flex gap-4 items-center",children:[(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[(0,le.jsx)("label",{className:"text-sm font-medium text-gray-700",children:"From:"}),(0,le.jsx)(fn,{type:"date",value:T,onChange:e=>P(e.target.value),className:"w-40 h-8 border-gray-200 focus:border-blue-500 focus:ring-blue-500/20"})]}),(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[(0,le.jsx)("label",{className:"text-sm font-medium text-gray-700",children:"To:"}),(0,le.jsx)(fn,{type:"date",value:L,onChange:e=>O(e.target.value),className:"w-40 h-8 border-gray-200 focus:border-blue-500 focus:ring-blue-500/20"})]})]})}),q()&&(0,le.jsxs)("div",{className:"flex flex-wrap gap-2 items-center p-3 bg-gradient-to-r from-blue-50 to-indigo-50 rounded-lg border border-blue-100",children:[(0,le.jsxs)("span",{className:"text-sm font-medium text-gray-700 flex items-center gap-1",children:[(0,le.jsx)(Rb.A,{className:"h-3.5 w-3.5"}),"Active filters:"]}),"all"!==A&&(0,le.jsxs)(Nn,{className:"bg-blue-100 text-blue-800 hover:bg-blue-200 transition-colors",children:["Status: ",A,(0,le.jsx)("button",{onClick:()=>S("all"),className:"ml-1 hover:bg-blue-300 rounded-full p-0.5 transition-colors",children:(0,le.jsx)(Bt.A,{className:"h-3 w-3"})})]}),"all"!==E&&(0,le.jsxs)(Nn,{className:"bg-purple-100 text-purple-800 hover:bg-purple-200 transition-colors",children:["Date: ","custom"===E?"Custom":E,(0,le.jsx)("button",{onClick:()=>I("all"),className:"ml-1 hover:bg-purple-300 rounded-full p-0.5 transition-colors",children:(0,le.jsx)(Bt.A,{className:"h-3 w-3"})})]}),c&&(0,le.jsxs)(Nn,{className:"bg-green-100 text-green-800 hover:bg-green-200 transition-colors",children:['Search: "',c,'"',(0,le.jsx)("button",{onClick:()=>d(""),className:"ml-1 hover:bg-green-300 rounded-full p-0.5 transition-colors",children:(0,le.jsx)(Bt.A,{className:"h-3 w-3"})})]})]})]}),(0,le.jsx)("div",{className:"bg-white rounded-xl border border-gray-200 shadow-sm overflow-hidden",children:(0,le.jsxs)(Ik,{children:[(0,le.jsx)(Tk,{children:(0,le.jsxs)(Lk,{className:"hover:bg-transparent border-b",children:[(0,le.jsx)(Ok,{className:"w-8"}),(0,le.jsx)(Ok,{className:"cursor-pointer font-semibold py-3",onClick:()=>W("name"),children:(0,le.jsxs)("div",{className:"flex items-center",children:["Integration Name",(0,le.jsx)(ny.A,{className:"ml-2 h-4 w-4 opacity-50"})]})}),(0,le.jsx)(Ok,{className:"cursor-pointer font-semibold py-3 w-32",onClick:()=>W("status"),children:(0,le.jsxs)("div",{className:"flex items-center",children:["Status",(0,le.jsx)(ny.A,{className:"ml-2 h-4 w-4 opacity-50"})]})}),(0,le.jsx)(Ok,{className:"cursor-pointer font-semibold py-3 w-36",onClick:()=>W("created_date"),children:(0,le.jsxs)("div",{className:"flex items-center",children:["Created",(0,le.jsx)(ny.A,{className:"ml-2 h-4 w-4 opacity-50"})]})}),(0,le.jsx)(Ok,{className:"cursor-pointer font-semibold py-3 w-36",onClick:()=>W("updated_date"),children:(0,le.jsxs)("div",{className:"flex items-center",children:["Updated",(0,le.jsx)(ny.A,{className:"ml-2 h-4 w-4 opacity-50"})]})}),(0,le.jsx)(Ok,{className:"font-semibold py-3 w-40",children:"Categories"}),(0,le.jsx)(Ok,{className:"cursor-pointer font-semibold py-3 w-24",onClick:()=>W("is_private"),children:(0,le.jsxs)("div",{className:"flex items-center",children:["Privacy",(0,le.jsx)(ny.A,{className:"ml-2 h-4 w-4 opacity-50"})]})})]})}),(0,le.jsx)(Pk,{children:i?(0,le.jsx)(Lk,{children:(0,le.jsx)(Rk,{colSpan:7,className:"text-center py-8",children:"Loading integrations..."})}):0===H.length?(0,le.jsx)(Lk,{children:(0,le.jsx)(Rk,{colSpan:7,className:"text-center py-8",children:"No integrations found"})}):H.map(e=>{var t,s,a,n;return(0,le.jsxs)(le.Fragment,{children:[(0,le.jsxs)(Lk,{className:"hover:bg-gray-50/60 transition-colors duration-150 group border-b border-gray-100",children:[(0,le.jsx)(Rk,{className:"py-3",children:(0,le.jsx)(Hn,{variant:"ghost",size:"sm",onClick:()=>{return t=e.item.id,void v(e=>{const s=new Set(e);return s.has(t)?s.delete(t):s.add(t),s});var t},className:"h-6 w-6 p-0 rounded-md hover:bg-gray-100 transition-all duration-150",children:f.has(e.item.id)?(0,le.jsx)(Is.A,{className:"h-3.5 w-3.5 text-gray-500"}):(0,le.jsx)(rn.A,{className:"h-3.5 w-3.5 text-gray-500"})})}),(0,le.jsx)(Rk,{className:"font-medium py-3 text-sm",children:(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[(0,le.jsx)("span",{className:"truncate",children:e.item.name}),(0,le.jsxs)("div",{className:"flex gap-1",children:[(0,le.jsx)(Hn,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0 text-green-600 hover:text-green-700 hover:bg-green-50 rounded opacity-0 group-hover:opacity-100 transition-opacity",onClick:t=>{t.stopPropagation(),z("approve",e)},disabled:p[e.item.id],title:"Approve",children:(0,le.jsx)(Ps.A,{className:"h-3 w-3"})}),(0,le.jsx)(Hn,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0 text-red-600 hover:text-red-700 hover:bg-red-50 rounded opacity-0 group-hover:opacity-100 transition-opacity",onClick:t=>{t.stopPropagation(),z("decline",e)},disabled:p[e.item.id],title:"Decline",children:(0,le.jsx)(Bt.A,{className:"h-3 w-3"})}),(0,le.jsx)(Hn,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0 text-blue-600 hover:text-blue-700 hover:bg-blue-50 rounded opacity-0 group-hover:opacity-100 transition-opacity",onClick:t=>{t.stopPropagation(),window.open("/integrations-catalog/item/".concat(e.item.id),"_blank")},title:"View Integration",children:(0,le.jsx)(hf.A,{className:"h-3 w-3"})})]})]})}),(0,le.jsx)(Rk,{className:"py-3",children:V(e.item.status)}),(0,le.jsx)(Rk,{className:"py-3 text-sm text-gray-600",children:(0,le.jsxs)("div",{className:"flex items-center gap-1",children:[(0,le.jsx)(bh.A,{className:"h-3 w-3 text-gray-400"}),ra().utc(e.item.created_date).format("MMM DD")]})}),(0,le.jsx)(Rk,{className:"py-3 text-sm text-gray-600",children:(0,le.jsxs)("div",{className:"flex items-center gap-1",children:[(0,le.jsx)(Li.A,{className:"h-3 w-3 text-gray-400"}),ra().utc(e.item.updated_date).format("MMM DD")]})}),(0,le.jsx)(Rk,{className:"py-3",children:(0,le.jsx)("div",{className:"flex flex-wrap gap-1",children:(null===(t=e.item.categories)||void 0===t?void 0:t.length)>0?(0,le.jsxs)(le.Fragment,{children:[e.item.categories.slice(0,2).map((e,t)=>(0,le.jsx)(Nn,{variant:"outline",className:"text-xs px-1.5 py-0 h-5",children:e},t)),e.item.categories.length>2&&(0,le.jsxs)(Nn,{variant:"outline",className:"text-xs px-1.5 py-0 h-5 bg-gray-50",children:["+",e.item.categories.length-2]})]}):(0,le.jsx)("span",{className:"text-gray-400 text-xs",children:"None"})})}),(0,le.jsx)(Rk,{className:"py-3",children:(0,le.jsx)("div",{className:"flex items-center gap-1.5",children:e.item.is_private?(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(Mt.A,{className:"h-3 w-3 text-amber-500"}),(0,le.jsx)("span",{className:"text-xs text-amber-600 font-medium",children:"Private"})]}):(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(bn.A,{className:"h-3 w-3 text-green-500"}),(0,le.jsx)("span",{className:"text-xs text-green-600 font-medium",children:"Public"})]})})})]},e.item.id),f.has(e.item.id)&&(0,le.jsx)(Lk,{children:(0,le.jsx)(Rk,{colSpan:7,className:"bg-gradient-to-br from-gray-50 to-gray-100/50 p-6 border-t border-gray-100",children:(0,le.jsxs)("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-6",children:[(0,le.jsxs)("div",{className:"space-y-4",children:[(0,le.jsxs)("div",{className:"bg-white p-4 rounded-lg border border-gray-200 shadow-sm",children:[(0,le.jsxs)("h4",{className:"font-semibold text-gray-900 mb-3 flex items-center gap-2",children:[(0,le.jsx)("div",{className:"w-1 h-4 bg-blue-500 rounded-full"}),"Creator & Usage"]}),(0,le.jsxs)("div",{className:"space-y-3 text-sm",children:[(0,le.jsxs)("div",{className:"flex justify-between items-center",children:[(0,le.jsx)("span",{className:"text-gray-600",children:"Creator:"}),(0,le.jsx)("span",{className:"font-medium text-gray-900",children:(null===(s=e.item_creator)||void 0===s?void 0:s.full_name)||(0,le.jsx)("span",{className:"text-gray-400 italic",children:"Unknown"})})]}),(0,le.jsxs)("div",{className:"flex justify-between items-center",children:[(0,le.jsx)("span",{className:"text-gray-600",children:"Uses:"}),(0,le.jsxs)("div",{className:"flex items-center gap-1",children:[(0,le.jsx)(or.A,{className:"h-3 w-3 text-gray-500"}),(0,le.jsx)("span",{className:"font-medium text-gray-900",children:e.usage||0})]})]}),(0,le.jsxs)("div",{className:"flex justify-between items-center",children:[(0,le.jsx)("span",{className:"text-gray-600",children:"Status:"}),V(e.item.status)]})]})]}),(0,le.jsxs)("div",{className:"bg-white p-4 rounded-lg border border-gray-200 shadow-sm",children:[(0,le.jsxs)("h4",{className:"font-semibold text-gray-900 mb-3 flex items-center gap-2",children:[(0,le.jsx)("div",{className:"w-1 h-4 bg-purple-500 rounded-full"}),"Admin Actions"]}),(0,le.jsxs)("div",{className:"flex gap-2",children:[(0,le.jsxs)(Hn,{size:"sm",className:"bg-green-600 hover:bg-green-700 text-white",onClick:t=>{t.stopPropagation(),z("approve",e)},disabled:p[e.item.id],children:[(0,le.jsx)(Ps.A,{className:"h-3 w-3 mr-1"}),"Approve"]}),(0,le.jsxs)(Hn,{size:"sm",variant:"outline",className:"text-red-600 border-red-200 hover:bg-red-50",onClick:t=>{t.stopPropagation(),z("decline",e)},disabled:p[e.item.id],children:[(0,le.jsx)(Bt.A,{className:"h-3 w-3 mr-1"}),"Decline"]}),(0,le.jsxs)(Hn,{size:"sm",variant:"outline",onClick:t=>{t.stopPropagation(),window.open("/integrations-catalog/item/".concat(e.item.id),"_blank")},children:[(0,le.jsx)(hf.A,{className:"h-3 w-3 mr-1"}),"View"]})]})]})]}),(0,le.jsxs)("div",{className:"space-y-4",children:[(0,le.jsxs)("div",{className:"bg-white p-4 rounded-lg border border-gray-200 shadow-sm",children:[(0,le.jsxs)("h4",{className:"font-semibold text-gray-900 mb-3 flex items-center gap-2",children:[(0,le.jsx)("div",{className:"w-1 h-4 bg-emerald-500 rounded-full"}),"Description"]}),(0,le.jsx)("div",{className:"text-sm text-gray-600 prose prose-sm max-w-none",dangerouslySetInnerHTML:{__html:dn(e.item.description||'

No description available

')}})]}),(0,le.jsxs)("div",{className:"bg-white p-4 rounded-lg border border-gray-200 shadow-sm",children:[(0,le.jsxs)("h4",{className:"font-semibold text-gray-900 mb-3 flex items-center gap-2",children:[(0,le.jsx)("div",{className:"w-1 h-4 bg-orange-500 rounded-full"}),"Technical Details"]}),(0,le.jsxs)("div",{className:"space-y-2 text-sm",children:[(0,le.jsxs)("div",{className:"flex justify-between items-center py-1",children:[(0,le.jsx)("span",{className:"text-gray-600",children:"Integration ID:"}),(0,le.jsx)("code",{className:"text-gray-900 bg-gray-100 px-2 py-0.5 rounded text-xs font-mono",children:e.item.integration_id})]}),(0,le.jsxs)("div",{className:"flex justify-between items-center py-1",children:[(0,le.jsx)("span",{className:"text-gray-600",children:"Organization:"}),(0,le.jsx)("code",{className:"text-gray-900 bg-gray-100 px-2 py-0.5 rounded text-xs font-mono",children:e.item.organization_id})]}),(0,le.jsxs)("div",{className:"flex justify-between items-center py-1",children:[(0,le.jsx)("span",{className:"text-gray-600",children:"Created:"}),(0,le.jsx)("span",{className:"text-gray-900 font-medium",children:ra().utc(e.item.created_date).format("MMM DD, YYYY")})]}),(0,le.jsxs)("div",{className:"flex justify-between items-center py-1",children:[(0,le.jsx)("span",{className:"text-gray-600",children:"Updated:"}),(0,le.jsx)("span",{className:"text-gray-900 font-medium",children:ra().utc(e.item.updated_date).format("MMM DD, YYYY")})]})]})]}),(null===(a=e.item.categories)||void 0===a?void 0:a.length)>0&&(0,le.jsxs)("div",{className:"bg-white p-4 rounded-lg border border-gray-200",children:[(0,le.jsxs)("h4",{className:"font-semibold text-gray-900 mb-3 flex items-center gap-2",children:[(0,le.jsx)("div",{className:"w-1 h-5 bg-purple-500 rounded-full"}),"Categories"]}),(0,le.jsx)("div",{className:"flex flex-wrap gap-2",children:e.item.categories.map((e,t)=>(0,le.jsx)(Nn,{className:"bg-purple-50 text-purple-700 border-purple-200 hover:bg-purple-100 transition-colors",children:e},t))})]})]}),(0,le.jsxs)("div",{className:"bg-white p-4 rounded-lg border border-gray-200 h-fit",children:[(0,le.jsxs)("h4",{className:"font-semibold text-gray-900 mb-3 flex items-center gap-2",children:[(0,le.jsx)("div",{className:"w-1 h-5 bg-orange-500 rounded-full"}),"Screenshots"]}),(null===(n=e.item.screenshot_urls)||void 0===n?void 0:n.length)>0?(0,le.jsxs)("div",{className:"grid grid-cols-1 gap-4",children:[e.item.screenshot_urls.slice(0,3).map((e,t)=>(0,le.jsxs)("div",{className:"relative rounded-lg overflow-hidden border border-gray-200 group",children:[(0,le.jsx)("img",{src:e,alt:"Screenshot ".concat(t+1),className:"w-full h-36 object-cover group-hover:scale-105 transition-all duration-300 cursor-pointer",onClick:()=>window.open(e,"_blank")}),(0,le.jsx)("div",{className:"absolute inset-0 bg-black/0 group-hover:bg-black/10 transition-colors duration-300 flex items-center justify-center",children:(0,le.jsx)("div",{className:"opacity-0 group-hover:opacity-100 transition-opacity duration-300 bg-white/90 backdrop-blur-sm rounded-full p-2",children:(0,le.jsx)(hf.A,{className:"h-4 w-4 text-gray-700"})})})]},t)),e.item.screenshot_urls.length>3&&(0,le.jsx)("div",{className:"text-center py-2 bg-gray-50 rounded-lg border border-gray-200",children:(0,le.jsxs)("p",{className:"text-sm text-gray-600 font-medium",children:["+",e.item.screenshot_urls.length-3," more screenshots"]})})]}):(0,le.jsxs)("div",{className:"text-center py-8 text-gray-400 bg-gray-50 rounded-lg border-2 border-dashed border-gray-200",children:[(0,le.jsx)(hf.A,{className:"h-8 w-8 mx-auto mb-2 opacity-50"}),(0,le.jsx)("p",{className:"text-sm",children:"No screenshots available"})]})]})]})})})]})})})]})}),(0,le.jsxs)("div",{className:"mt-6 flex flex-col sm:flex-row items-center justify-between gap-4",children:[(0,le.jsxs)("div",{className:"flex items-center gap-4 text-sm text-gray-600",children:[(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[(0,le.jsx)("span",{children:"Showing"}),(0,le.jsxs)("span",{className:"font-semibold text-gray-900",children:[Math.min((b-1)*y+1,w),"-",Math.min(b*y,w)]}),(0,le.jsx)("span",{children:"of"}),(0,le.jsx)("span",{className:"font-semibold text-gray-900",children:w}),(0,le.jsx)("span",{children:"integrations"})]}),(0,le.jsxs)(In,{value:y.toString(),onValueChange:e=>{return t=parseInt(e),N(t),void j(1);var t},children:[(0,le.jsx)(Pn,{className:"w-24 h-8 text-sm",children:(0,le.jsx)(Tn,{})}),(0,le.jsxs)(Rn,{children:[(0,le.jsx)(Mn,{value:"10",children:"10"}),(0,le.jsx)(Mn,{value:"20",children:"20"}),(0,le.jsx)(Mn,{value:"50",children:"50"}),(0,le.jsx)(Mn,{value:"100",children:"100"})]})]}),(0,le.jsx)("span",{className:"text-gray-500",children:"per page"})]}),(0,le.jsx)(Fk,{currentPage:b,totalPages:k,onPageChange:e=>{j(e)}})]}),(0,le.jsx)(tc,{open:R.isOpen,onOpenChange:U,children:(0,le.jsxs)(lc,{children:[(0,le.jsxs)(rc,{children:[(0,le.jsxs)(oc,{children:["approve"===R.action&&"Approve Integration","decline"===R.action&&"Decline Integration","archive"===R.action&&"Archive Integration"]}),(0,le.jsxs)(cc,{children:["approve"===R.action&&(0,le.jsxs)(le.Fragment,{children:["Are you sure you want to approve ",(0,le.jsx)("strong",{children:null===(t=R.item)||void 0===t?void 0:t.item.name}),"?",(0,le.jsx)("br",{}),"This will make the integration publicly visible in the catalog."]}),"decline"===R.action&&(0,le.jsxs)(le.Fragment,{children:["Are you sure you want to decline ",(0,le.jsx)("strong",{children:null===(s=R.item)||void 0===s?void 0:s.item.name}),"?",(0,le.jsx)("br",{}),"This will remove the integration from public visibility in the catalog.",(0,le.jsxs)("div",{className:"mt-4",children:[(0,le.jsx)("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:"Reason for decline (optional):"}),(0,le.jsx)("textarea",{placeholder:"Enter reason for declining this integration...",value:D,onChange:e=>F(e.target.value),className:"flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50"})]})]}),"archive"===R.action&&(0,le.jsxs)(le.Fragment,{children:["Are you sure you want to archive ",(0,le.jsx)("strong",{children:null===(a=R.item)||void 0===a?void 0:a.item.name}),"?",(0,le.jsx)("br",{}),"This will permanently remove the integration from the catalog."]})]})]}),(0,le.jsxs)(ic,{children:[(0,le.jsx)(Hn,{variant:"outline",onClick:U,children:"Cancel"}),(0,le.jsxs)(Hn,{onClick:async()=>{if(!R.action||!R.item)return;const{action:e,item:t}=R,s=t.item.id;g(e=>(0,K.A)((0,K.A)({},e),{},{[s]:!0})),U();try{switch(e){case"approve":await Kt.approveItem(s);break;case"decline":await Kt.declineItem(s,D||void 0);break;case"archive":await Kt.archiveItem(s)}an({title:"Success",description:"Integration ".concat(e,"d successfully")}),await B()}catch(a){an({title:"Error",description:"Failed to ".concat(e," integration"),variant:"destructive"})}finally{g(e=>(0,K.A)((0,K.A)({},e),{},{[s]:!1}))}},className:"approve"===R.action?"bg-green-600 hover:bg-green-700":"decline"===R.action?"bg-red-600 hover:bg-red-700":"bg-gray-600 hover:bg-gray-700",children:["approve"===R.action&&"Approve","decline"===R.action&&"Decline","archive"===R.action&&"Archive"]})]})]})})]}):(0,le.jsx)("div",{className:"flex items-center justify-center h-screen",children:(0,le.jsxs)("div",{className:"text-center",children:[(0,le.jsx)(ay.A,{className:"w-16 h-16 text-red-500 mx-auto mb-4"}),(0,le.jsx)("h2",{className:"text-2xl font-bold text-gray-800",children:"Access Denied"}),(0,le.jsx)("p",{className:"text-gray-600",children:"You are not authorized to access this page"})]})})}const zk=["steps","currentStep","title","description","children","onNext","onPrevious","onClose","onSubmit","isNextDisabled","isLoading","nextButtonText","submitButtonText","previousButtonText","hideCloseButton","className","banner","footerLeftContent"];function Uk(e){let{steps:t,currentStep:s,title:a,description:n,children:l,onNext:r,onPrevious:i,onClose:o,onSubmit:c,isNextDisabled:d=!1,isLoading:m=!1,nextButtonText:u="Next",submitButtonText:x="Submit",previousButtonText:h="Back",hideCloseButton:p=!1,className:g,banner:f,footerLeftContent:v}=e,b=(0,Se.A)(e,zk);const j=0===s,y=s===t.length-1,N=(s+1)/t.length*100;return(0,le.jsxs)("div",(0,K.A)((0,K.A)({"data-testid":"stepped-wizard",className:Pe("bg-theme-card bg-white rounded-[20px] shadow-lg inline-flex flex-col justify-start items-start overflow-hidden",g)},b),{},{children:[(0,le.jsx)("div",{className:"w-full h-2 bg-gradient-to-r from-[#FFC787] via-[#FF6900] to-[#5F5DD8] flex flex-col justify-start items-end overflow-hidden",children:(0,le.jsx)("div",{className:"h-2 bg-slate-200 transition-all duration-300 ease-in-out",style:{width:"".concat(100-N,"%")}})}),(0,le.jsxs)("div",{className:"self-stretch px-6 pt-4 pb-3 border-b border-theme-border inline-flex justify-between items-start",children:[(0,le.jsxs)("div",{className:"w-full inline-flex flex-col justify-start items-start gap-1.5",children:[(0,le.jsx)("div",{"data-testid":"wizard-title",className:"justify-start text-2xl font-semibold font-base44",children:a}),n&&(0,le.jsx)("div",{"data-testid":"wizard-description",className:"self-stretch justify-start text-gray-700 text-sm font-normal font-base44 leading-tight",children:n})]}),!p&&o&&(0,le.jsx)("div",{className:"w-36 flex justify-end items-center gap-3",children:(0,le.jsx)("button",{"data-testid":"wizard-close-button",onClick:o,className:"flex justify-start items-start","aria-label":"Close",children:(0,le.jsx)("div",{className:"w-6 h-6 relative",children:(0,le.jsx)("div",{className:"w-5 h-5 absolute",children:(0,le.jsx)(Bt.A,{className:"w-5 h-5"})})})})})]}),(0,le.jsx)("div",{className:"flex-1 self-stretch overflow-y-auto",children:l}),(0,le.jsx)("div",{className:"self-stretch px-6 py-4 border-t border-gray-200",children:(0,le.jsxs)("div",{className:"flex flex-col gap-3 min-[470px]:flex-row min-[470px]:items-center min-[470px]:gap-2 ".concat(v?"min-[470px]:justify-between":"min-[470px]:justify-end"),children:[v&&(0,le.jsx)("div",{className:"flex justify-start items-center order-1 min-[470px]:order-1",children:v}),(0,le.jsxs)("div",{className:"flex justify-end items-center gap-6 order-2 min-[470px]:order-2",children:[(0,le.jsxs)("div",{"data-testid":"step-indicator",className:"justify-center text-gray-500 text-sm font-normal font-base44 leading-tight",children:["Step ",s+1," of ",t.length]}),(0,le.jsxs)("div",{className:"flex justify-start items-center gap-3",children:[!j&&i&&(0,le.jsx)(Hn,{"data-testid":"wizard-previous-button",variant:"outline",size:"sm",onClick:i,disabled:m,className:"w-9 h-9 rounded-lg shadow-[0px_1px_2px_0px_rgba(0,0,0,0.05)] flex justify-center items-center p-0",children:(0,le.jsx)(Xs.A,{className:"w-4 h-4"})}),(y?c:r)&&(0,le.jsxs)(Hn,{"data-testid":y?"wizard-submit-button":"wizard-next-button",onClick:y?c:r,variant:"default",disabled:d||m,className:"h-9 rounded-lg min-w-24",children:[(0,le.jsx)("span",{className:"text-center justify-center text-sm font-medium font-base44 leading-tight",children:m?"Loading...":y?x:u}),!m&&!y&&(0,le.jsx)(rn.A,{className:"w-4 h-4 "})]})]})]})]})}),f&&f]}))}function Wk(e){let{label:t,placeholder:s,value:a,onChange:n,error:l,type:r="text",icon:i,className:o="",required:c=!1,helperText:d,rows:m=4,tooltipText:u}=e;const x="".concat("textarea"===r?"h-20":"h-10"," ").concat(l?"border-red-500":"border-slate-200"," ").concat(o),h=e=>{n(e.target.value)};return(0,le.jsxs)("div",{className:t?"space-y-1":"",children:[t&&(0,le.jsxs)("div",{className:"flex items-center gap-1",children:[(0,le.jsxs)(go,{className:"text-center justify-center text-gray-700 text-sm font-medium font-base44 leading-tight",children:[t,c&&(0,le.jsx)("span",{className:"text-red-500 ml-1",children:"*"})]}),u&&(0,le.jsxs)(Bi,{delayDuration:100,children:[(0,le.jsx)(zi,{asChild:!0,children:(0,le.jsx)(uo.A,{className:"h-4 w-4 text-gray-600 hover:text-gray-900"})}),(0,le.jsx)(Ui,{className:"max-w-[240px] p-3 text-xs",children:(0,le.jsx)("p",{children:u})})]})]}),"textarea"===r?(0,le.jsx)(yp,{placeholder:s,value:a,onChange:h,rows:m,className:x}):(0,le.jsx)(fn,{type:r,placeholder:s,value:a,onChange:h,className:x}),l&&(0,le.jsx)("p",{className:"text-sm text-red-500 mt-2",children:l}),d&&!l&&(0,le.jsx)("p",{className:"text-xs text-slate-400 mt-2",children:d})]})}var qk=s(88434),Vk=s(56003);const Hk=["Application Development","UI/UX Design","Security Expert","Strategic Consulting","Mobile Development","AI Expert","API & Integrations","QA & Testing","Other"],Yk=[{label:"English",value:"en"},{label:"Hebrew",value:"he"},{label:"Spanish",value:"es"},{label:"French",value:"fr"},{label:"German",value:"de"},{label:"Italian",value:"it"},{label:"Portuguese",value:"pt"},{label:"Russian",value:"ru"},{label:"Chinese",value:"zh"},{label:"Japanese",value:"ja"},{label:"Korean",value:"ko"},{label:"Arabic",value:"ar"},{label:"Turkish",value:"tr"},{label:"Dutch",value:"nl"},{label:"Polish",value:"pl"},{label:"Romanian",value:"ro"},{label:"Czech",value:"cs"},{label:"Hungarian",value:"hu"},{label:"Bulgarian",value:"bg"},{label:"Croatian",value:"hr"},{label:"Serbian",value:"sr"},{label:"Slovak",value:"sk"},{label:"Slovenian",value:"sl"},{label:"Estonian",value:"et"},{label:"Latvian",value:"lv"}],Gk=[{label:"Afghanistan",value:"af"},{label:"\xc5land Islands",value:"ax"},{label:"Albania",value:"al"},{label:"Algeria",value:"dz"},{label:"American Samoa",value:"as"},{label:"Andorra",value:"ad"},{label:"Angola",value:"ao"},{label:"Anguilla",value:"ai"},{label:"Antigua & Barbuda",value:"ag"},{label:"Argentina",value:"ar"},{label:"Armenia",value:"am"},{label:"Aruba",value:"aw"},{label:"Australia",value:"au"},{label:"Austria",value:"at"},{label:"Azerbaijan",value:"az"},{label:"Bahamas",value:"bs"},{label:"Bahrain",value:"bh"},{label:"Bangladesh",value:"bd"},{label:"Barbados",value:"bb"},{label:"Belarus",value:"by"},{label:"Belgium",value:"be"},{label:"Belize",value:"bz"},{label:"Benin",value:"bj"},{label:"Bermuda",value:"bm"},{label:"Bhutan",value:"bt"},{label:"Bolivia",value:"bo"},{label:"Bosnia & Herzegovina",value:"ba"},{label:"Botswana",value:"bw"},{label:"Brazil",value:"br"},{label:"British Indian Ocean Territory",value:"io"},{label:"British Virgin Islands",value:"vg"},{label:"Brunei",value:"bn"},{label:"Bulgaria",value:"bg"},{label:"Burkina Faso",value:"bf"},{label:"Burundi",value:"bi"},{label:"Cambodia",value:"kh"},{label:"Cameroon",value:"cm"},{label:"Canada",value:"ca"},{label:"Cape Verde",value:"cv"},{label:"Caribbean Netherlands",value:"bq"},{label:"Cayman Islands",value:"ky"},{label:"Central African Republic",value:"cf"},{label:"Chad",value:"td"},{label:"Chile",value:"cl"},{label:"China",value:"cn"},{label:"Christmas Island",value:"cx"},{label:"Cocos (Keeling) Islands",value:"cc"},{label:"Colombia",value:"co"},{label:"Comoros",value:"km"},{label:"Congo - Brazzaville",value:"cg"},{label:"Congo - Kinshasa",value:"cd"},{label:"Cook Islands",value:"ck"},{label:"Costa Rica",value:"cr"},{label:"C\xf4te d'Ivoire",value:"ci"},{label:"Croatia",value:"hr"},{label:"Cura\xe7ao",value:"cw"},{label:"Cyprus",value:"cy"},{label:"Czechia",value:"cz"},{label:"Denmark",value:"dk"},{label:"Djibouti",value:"dj"},{label:"Dominica",value:"dm"},{label:"Dominican Republic",value:"do"},{label:"Ecuador",value:"ec"},{label:"Egypt",value:"eg"},{label:"El Salvador",value:"sv"},{label:"Equatorial Guinea",value:"gq"},{label:"Eritrea",value:"er"},{label:"Estonia",value:"ee"},{label:"Eswatini",value:"sz"},{label:"Ethiopia",value:"et"},{label:"Falkland Islands",value:"fk"},{label:"Faroe Islands",value:"fo"},{label:"Fiji",value:"fj"},{label:"Finland",value:"fi"},{label:"France",value:"fr"},{label:"French Guiana",value:"gf"},{label:"French Polynesia",value:"pf"},{label:"Gabon",value:"ga"},{label:"Gambia",value:"gm"},{label:"Georgia",value:"ge"},{label:"Germany",value:"de"},{label:"Ghana",value:"gh"},{label:"Gibraltar",value:"gi"},{label:"Greece",value:"gr"},{label:"Greenland",value:"gl"},{label:"Grenada",value:"gd"},{label:"Guadeloupe",value:"gp"},{label:"Guam",value:"gu"},{label:"Guatemala",value:"gt"},{label:"Guernsey",value:"gg"},{label:"Guinea",value:"gn"},{label:"Guinea-Bissau",value:"gw"},{label:"Guyana",value:"gy"},{label:"Haiti",value:"ht"},{label:"Honduras",value:"hn"},{label:"Hong Kong SAR China",value:"hk"},{label:"Hungary",value:"hu"},{label:"Iceland",value:"is"},{label:"India",value:"in"},{label:"Indonesia",value:"id"},{label:"Iraq",value:"iq"},{label:"Ireland",value:"ie"},{label:"Isle of Man",value:"im"},{label:"Israel",value:"il"},{label:"Italy",value:"it"},{label:"Jamaica",value:"jm"},{label:"Japan",value:"jp"},{label:"Jersey",value:"je"},{label:"Jordan",value:"jo"},{label:"Kazakhstan",value:"kz"},{label:"Kenya",value:"ke"},{label:"Kiribati",value:"ki"},{label:"Kuwait",value:"kw"},{label:"Kyrgyzstan",value:"kg"},{label:"Laos",value:"la"},{label:"Latvia",value:"lv"},{label:"Lebanon",value:"lb"},{label:"Lesotho",value:"ls"},{label:"Liberia",value:"lr"},{label:"Libya",value:"ly"},{label:"Liechtenstein",value:"li"},{label:"Lithuania",value:"lt"},{label:"Luxembourg",value:"lu"},{label:"Macao SAR China",value:"mo"},{label:"Madagascar",value:"mg"},{label:"Malawi",value:"mw"},{label:"Malaysia",value:"my"},{label:"Maldives",value:"mv"},{label:"Mali",value:"ml"},{label:"Malta",value:"mt"},{label:"Marshall Islands",value:"mh"},{label:"Martinique",value:"mq"},{label:"Mauritania",value:"mr"},{label:"Mauritius",value:"mu"},{label:"Mayotte",value:"yt"},{label:"Mexico",value:"mx"},{label:"Micronesia",value:"fm"},{label:"Moldova",value:"md"},{label:"Monaco",value:"mc"},{label:"Mongolia",value:"mn"},{label:"Montenegro",value:"me"},{label:"Montserrat",value:"ms"},{label:"Morocco",value:"ma"},{label:"Mozambique",value:"mz"},{label:"Myanmar (Burma)",value:"mm"},{label:"Namibia",value:"na"},{label:"Nauru",value:"nr"},{label:"Nepal",value:"np"},{label:"Netherlands",value:"nl"},{label:"New Caledonia",value:"nc"},{label:"New Zealand",value:"nz"},{label:"Nicaragua",value:"ni"},{label:"Niger",value:"ne"},{label:"Nigeria",value:"ng"},{label:"Niue",value:"nu"},{label:"Norfolk Island",value:"nf"},{label:"North Macedonia",value:"mk"},{label:"Northern Mariana Islands",value:"mp"},{label:"Norway",value:"no"},{label:"Oman",value:"om"},{label:"Pakistan",value:"pk"},{label:"Palau",value:"pw"},{label:"Palestinian Territories",value:"ps"},{label:"Panama",value:"pa"},{label:"Papua New Guinea",value:"pg"},{label:"Paraguay",value:"py"},{label:"Peru",value:"pe"},{label:"Philippines",value:"ph"},{label:"Poland",value:"pl"},{label:"Portugal",value:"pt"},{label:"Puerto Rico",value:"pr"},{label:"Qatar",value:"qa"},{label:"R\xe9union",value:"re"},{label:"Romania",value:"ro"},{label:"Rwanda",value:"rw"},{label:"Samoa",value:"ws"},{label:"San Marino",value:"sm"},{label:"S\xe3o Tom\xe9 & Pr\xedncipe",value:"st"},{label:"Saudi Arabia",value:"sa"},{label:"Senegal",value:"sn"},{label:"Serbia",value:"rs"},{label:"Seychelles",value:"sc"},{label:"Sierra Leone",value:"sl"},{label:"Singapore",value:"sg"},{label:"Sint Maarten",value:"sx"},{label:"Slovakia",value:"sk"},{label:"Slovenia",value:"si"},{label:"Solomon Islands",value:"sb"},{label:"Somalia",value:"so"},{label:"South Africa",value:"za"},{label:"South Korea",value:"kr"},{label:"South Sudan",value:"ss"},{label:"Spain",value:"es"},{label:"Sri Lanka",value:"lk"},{label:"St. Barth\xe9lemy",value:"bl"},{label:"St. Helena",value:"sh"},{label:"St. Kitts & Nevis",value:"kn"},{label:"St. Lucia",value:"lc"},{label:"St. Martin",value:"mf"},{label:"St. Pierre & Miquelon",value:"pm"},{label:"St. Vincent & Grenadines",value:"vc"},{label:"Sudan",value:"sd"},{label:"Suriname",value:"sr"},{label:"Svalbard & Jan Mayen",value:"sj"},{label:"Sweden",value:"se"},{label:"Switzerland",value:"ch"},{label:"Syria",value:"sy"},{label:"Taiwan",value:"tw"},{label:"Tajikistan",value:"tj"},{label:"Tanzania",value:"tz"},{label:"Thailand",value:"th"},{label:"Timor-Leste",value:"tl"},{label:"Togo",value:"tg"},{label:"Tokelau",value:"tk"},{label:"Tonga",value:"to"},{label:"Trinidad & Tobago",value:"tt"},{label:"Tunisia",value:"tn"},{label:"Turkey",value:"tr"},{label:"Turkmenistan",value:"tm"},{label:"Turks & Caicos Islands",value:"tc"},{label:"Tuvalu",value:"tv"},{label:"U.S. Virgin Islands",value:"vi"},{label:"Uganda",value:"ug"},{label:"Ukraine",value:"ua"},{label:"United Arab Emirates",value:"ae"},{label:"United Kingdom",value:"gb"},{label:"United States",value:"us"},{label:"Uruguay",value:"uy"},{label:"Uzbekistan",value:"uz"},{label:"Vanuatu",value:"vu"},{label:"Vatican City",value:"va"},{label:"Venezuela",value:"ve"},{label:"Vietnam",value:"vn"},{label:"Wallis & Futuna",value:"wf"},{label:"Western Sahara",value:"eh"},{label:"Yemen",value:"ye"},{label:"Zambia",value:"zm"},{label:"Zimbabwe",value:"zw"}],$k=e=>{const t=Gk.find(t=>t.value===e);return t?t.label:e},Jk=qk.Yj().url("Please enter a valid URL"),Zk=qk.Ik({url:qk.Yj(),allow_public_showcase:qk.zM().default(!0)}),Kk=qk.Yj().url("Please enter a valid URL").refine(e=>e.toLowerCase().includes("linkedin.com"),"Please enter a valid LinkedIn URL"),Qk=qk.Yj().optional().refine(e=>!e||""===e.trim()||!isNaN(Number(e))&&Number(e)>=0,"Please enter a valid number"),Xk=(e,t)=>{const s=e.website_url&&""!==e.website_url.trim(),a=e.linkedin_url&&""!==e.linkedin_url.trim();if(s||a||(t.addIssue({code:Vk.eq.custom,message:"Please provide either a website or LinkedIn URL",path:["website_url"]}),t.addIssue({code:Vk.eq.custom,message:"Please provide either a website or LinkedIn URL",path:["linkedin_url"]})),s){Jk.safeParse(e.website_url).success||t.addIssue({code:Vk.eq.custom,message:"Please enter a valid URL",path:["website_url"]})}if(a){const s=Kk.safeParse(e.linkedin_url);var n;if(!s.success)t.addIssue({code:Vk.eq.custom,message:(null===(n=s.error.errors[0])||void 0===n?void 0:n.message)||"Please enter a valid LinkedIn URL",path:["linkedin_url"]})}},eC=(e,t)=>{const s=e.budget_starting_from_dollars&&""!==e.budget_starting_from_dollars.trim(),a=e.hourly_rate&&""!==e.hourly_rate.trim();s||a||t.addIssue({code:Vk.eq.custom,message:"Please provide at least one pricing option",path:["pricing"]})},tC=(e,t)=>{var s;null===(s=e.services)||void 0===s||!s.includes("Other")||e.other_service_description&&""!==e.other_service_description.trim()||t.addIssue({code:Vk.eq.custom,message:"Please describe your other service",path:["other_service_description"]})},sC=(e,t)=>{if(e.has_apps_to_share){0===(e.apps||[]).filter(e=>e.url&&e.url.trim()).length&&t.addIssue({code:Vk.eq.custom,message:"Please provide at least one app URL",path:["apps"]}),e.apps&&e.apps.length>0&&e.apps.forEach((e,s)=>{e.url&&e.url.trim()&&(qk.Yj().url().safeParse(e.url).success||t.addIssue({code:Vk.eq.custom,message:"App ".concat(s+1," must be a valid URL"),path:["apps"]}))})}else(!e.no_apps_explanation||e.no_apps_explanation.trim().length<20)&&t.addIssue({code:Vk.eq.custom,message:"Please provide an explanation of at least 20 characters",path:["no_apps_explanation"]})},aC=qk.Ik({name:qk.Yj().min(1,"Company/Personal name is required").max(100,"Name must be less than 100 characters"),description:qk.Yj().min(20,"Please provide at least 20 characters").max(500,"Description must be less than 500 characters"),logo_url:qk.Yj().optional(),country:qk.Yj().min(1,"Country is required"),city:qk.Yj().min(1,"City is required").max(50,"City name must be less than 50 characters"),individual_or_team:qk.k5(["individual","team"],{required_error:"Please select team size"}),website_url:qk.Yj().optional(),linkedin_url:qk.Yj().optional(),languages:qk.YO(qk.Yj()).min(1,"Please select at least one language"),budget_starting_from_dollars:Qk,hourly_rate:Qk,services:qk.YO(qk.Yj()).min(1,"Please select at least one service"),other_service_description:qk.Yj().max(30,"Service description must be 30 characters or less").optional(),apps:qk.YO(Zk).max(5,"Maximum 5 apps allowed").default([]),has_apps_to_share:qk.zM().default(!0),no_apps_explanation:qk.Yj().max(500,"Explanation must be less than 500 characters").optional(),terms_accepted:qk.zM().refine(e=>!0===e,"You must agree to the terms of use to continue")}),nC=aC.superRefine((e,t)=>{Xk(e,t),eC(e,t),tC(e,t),sC(e,t)}),lC=aC.pick({name:!0,description:!0,country:!0,city:!0}).extend({logo:qk.zM().refine(e=>!0===e,"Logo upload is required")}),rC=aC.pick({individual_or_team:!0,website_url:!0,linkedin_url:!0,languages:!0,budget_starting_from_dollars:!0,hourly_rate:!0}).superRefine((e,t)=>{Xk(e,t),eC(e,t)}),iC=aC.pick({services:!0,other_service_description:!0}).superRefine((e,t)=>{tC(e,t)}),oC=aC.pick({apps:!0,has_apps_to_share:!0,no_apps_explanation:!0}).superRefine((e,t)=>{sC(e,t)}),cC=e=>{const t={};return e.errors.forEach(e=>{const s=e.path.join(".");s&&(t[s]=e.message)}),t},dC=e=>{let{value:t,onValueChange:s,placeholder:a="Select a country",error:n,required:l=!1,disabled:r=!1,className:i=""}=e;Gk.find(e=>e.value===t);const o="w-full h-10 ".concat(n?"border-red-500":"border-slate-200"," ").concat(i);return(0,le.jsxs)("div",{className:"w-full",children:[(0,le.jsxs)(In,{value:t,onValueChange:s,disabled:r,children:[(0,le.jsx)(Pn,{className:"w-full ".concat(o," focus:outline-none focus-visible:outline-none focus:ring-1 focus:ring-black focus:border-black data-[state=open]:ring-1 data-[state=open]:ring-black data-[state=open]:border-black"),style:{color:t?"#000000":"#94a3b8"},children:(0,le.jsx)(Tn,{placeholder:a,className:"text-sm font-normal font-base44 leading-tight"})}),(0,le.jsx)(Rn,{className:"bg-white border border-slate-200 rounded-md shadow-lg max-h-60 w-[var(--radix-select-trigger-width)]",position:"popper",sideOffset:4,children:Gk.map(e=>(0,le.jsx)(Mn,{value:e.value,hideCheckIcon:!0,className:"w-full p-1.5 rounded-md cursor-pointer inline-flex justify-start items-center gap-2 hover:!bg-slate-50 focus:!bg-slate-50 data-[highlighted]:!bg-slate-50 data-[state=checked]:!bg-slate-700 data-[state=checked]:!text-white data-[state=checked]:hover:!bg-slate-700 data-[state=checked]:data-[highlighted]:!bg-slate-700",children:(0,le.jsx)("div",{className:"flex-1 justify-start text-sm font-normal font-base44 leading-tight",children:e.label})},e.value))})]}),n&&(0,le.jsx)("p",{className:"text-sm text-red-500 mt-2",children:n})]})};function mC(e){let{label:t,placeholder:s,value:a,onChange:n,error:l,className:r="",required:i=!1,helperText:o,tooltipText:c,disabled:d=!1}=e;return(0,le.jsxs)("div",{className:"w-full space-y-1",children:[t&&(0,le.jsxs)("div",{className:"flex items-center gap-1",children:[(0,le.jsxs)(go,{className:"text-center justify-center text-gray-700 text-sm font-medium font-base44 leading-tight",children:[t,i&&(0,le.jsx)("span",{className:"text-red-500 ml-1",children:"*"})]}),c&&(0,le.jsxs)(Bi,{delayDuration:100,children:[(0,le.jsx)(zi,{asChild:!0,children:(0,le.jsx)(uo.A,{className:"h-4 w-4 text-gray-600 hover:text-gray-900"})}),(0,le.jsx)(Ui,{className:"max-w-[240px] p-3 text-xs",children:(0,le.jsx)("p",{children:c})})]})]}),(0,le.jsx)(dC,{value:a,onValueChange:n,placeholder:s,error:l,disabled:d,className:r}),l&&(0,le.jsx)("p",{className:"text-sm text-red-500 mt-2",children:l}),o&&!l&&(0,le.jsx)("p",{className:"text-xs text-slate-400 mt-2",children:o})]})}const uC=e=>{let{formData:t,errors:s,logoPreview:a,onInputChange:n,onLogoUpload:l,onLogoRemove:r}=e;return(0,le.jsxs)("div",{"data-testid":"basic-info-step",className:"w-full p-6 bg-white flex flex-col justify-start items-start gap-6 overflow-hidden",children:[(0,le.jsxs)("div",{className:"w-full flex flex-col justify-start items-start",children:[(0,le.jsx)("div",{className:"w-full inline-flex justify-start items-start",children:(0,le.jsx)("div",{className:"flex-1 flex justify-start items-start",children:(0,le.jsx)("div",{className:"flex-1 self-stretch inline-flex flex-col justify-start items-start gap-2",children:(0,le.jsxs)("div",{className:"inline-flex justify-start items-start gap-4",children:[(0,le.jsx)("div",{className:"w-20 h-20 rounded-2xl overflow-hidden bg-gray-100 flex items-center justify-center",children:a?(0,le.jsx)("img",{src:a,alt:"Logo preview",className:"w-20 h-20 rounded-2xl object-cover"}):(0,le.jsx)("div",{className:"w-20 h-20 bg-gray-200 rounded-2xl flex items-center justify-center",children:(0,le.jsx)(hx.A,{"data-testid":"placeholder-upload-icon",className:"h-8 w-8 text-gray-400"})})}),(0,le.jsxs)("div",{className:"inline-flex flex-col justify-start items-start gap-3",children:[(0,le.jsxs)("div",{"data-testid":"logo-label",className:"self-stretch justify-center text-gray-700 text-sm font-medium font-base44 leading-tight",children:["Logo/profile",(0,le.jsx)("span",{className:"text-red-500 ml-1",children:"*"})]}),(0,le.jsxs)("div",{className:"self-stretch flex flex-col justify-start items-start gap-1.5",children:[(0,le.jsxs)("div",{className:"inline-flex justify-start items-start gap-3",children:[(0,le.jsx)("input",{"data-testid":"logo-upload-input",type:"file",id:"logo-upload-basic",className:"hidden",accept:"image/*",onChange:l}),(0,le.jsx)(Hn,{variant:"secondary",size:"sm",asChild:!0,className:"h-7 px-3",children:(0,le.jsxs)("label",{"data-testid":"upload-button",htmlFor:"logo-upload-basic",className:"cursor-pointer gap-1.5",children:[(0,le.jsx)(hx.A,{"data-testid":"upload-icon",className:"w-4 h-4"}),"Upload logo"]})}),a&&(0,le.jsx)(Hn,{"data-testid":"remove-logo-button",variant:"outline",size:"sm",onClick:r,className:"h-7 px-3",children:"Remove"})]}),(0,le.jsx)("div",{"data-testid":"file-format-text",className:"justify-start text-gray-500 text-xs font-normal font-base44 leading-none",children:"We support PNGs and JPEGs"})]})]})]})})})}),s.logo&&(0,le.jsx)("p",{"data-testid":"logo-error",className:"text-sm text-red-500 mt-2",children:s.logo})]}),(0,le.jsx)("div",{"data-testid":"name-field-container",className:"w-full",children:(0,le.jsx)(Wk,{"data-testid":"name-input",label:"Display name (you or your company)",placeholder:"Enter your name or company name",value:t.name,onChange:e=>n("name",e),error:s.name,required:!0,className:"w-full",tooltipText:"Your display name shows who you are. Company name is best, but your own name works too."})}),(0,le.jsx)("div",{"data-testid":"description-field-container",className:"w-full",children:(0,le.jsx)(Wk,{"data-testid":"description-input",label:"What should users know about your services or company? (2 sentences)",placeholder:"Describe your expertise and what makes you unique...",value:t.description,onChange:e=>n("description",e),error:s.description,type:"textarea",helperText:"".concat(t.description.length," characters (minimum 20)"),required:!0,className:"w-full"})}),(0,le.jsxs)("div",{"data-testid":"location-fields-container",className:"w-full grid grid-cols-1 sm:grid-cols-2 gap-3",children:[(0,le.jsx)(mC,{"data-testid":"country-select",label:"Country",placeholder:"Select your country",value:t.country,onChange:e=>n("country",e),error:s.country,required:!0,className:"w-full",tooltipText:"Providing your location ensures smoother collaboration with people in different places"}),(0,le.jsx)(Wk,{"data-testid":"city-input",label:"City",placeholder:"e.g., San Francisco",value:t.city,onChange:e=>n("city",e),error:s.city,required:!0,className:"w-full",tooltipText:"Providing your location ensures smoother collaboration with people in different places"})]})]})},xC=e=>{let{label:t,value:s,onValueChange:a,options:n,className:l="",error:r}=e;return(0,le.jsxs)("div",{className:"w-full flex flex-col justify-start items-start gap-1 ".concat(l),children:[(0,le.jsx)(go,{className:"text-gray-700 text-sm font-medium font-base44 leading-tight",children:t}),(0,le.jsx)(Pc,{value:s,onValueChange:a,className:"w-full grid grid-cols-1 sm:grid-cols-2 gap-3",children:n.map(e=>(0,le.jsxs)(go,{htmlFor:"radio-".concat(e.value),className:"p-3 bg-white rounded-lg border border-slate-200 flex justify-start items-center gap-3 cursor-pointer hover:bg-slate-50 transition-colors",children:[(0,le.jsx)(Lc,{id:"radio-".concat(e.value),value:e.value,className:"w-4 h-4"}),(0,le.jsx)("span",{className:"text-black text-sm font-medium font-base44 leading-tight",children:e.label})]},e.value))}),r&&(0,le.jsx)("p",{className:"text-sm text-red-500 mt-1",children:r})]})},hC=e=>{let{formData:t,errors:s,onInputChange:a,onLanguageToggle:n}=e;return(0,le.jsxs)("div",{"data-testid":"profile-step",className:"w-full p-6 bg-white flex flex-col justify-start items-start gap-6 overflow-hidden",children:[(0,le.jsx)(xC,{label:"Your team size",value:t.individual_or_team,onValueChange:e=>a("individual_or_team",e),options:[{value:"individual",label:"Individual"},{value:"team",label:"Team/Agency"}],error:s.individual_or_team}),(0,le.jsxs)("div",{className:"w-full flex flex-col justify-start items-start gap-3",children:[(0,le.jsxs)("div",{className:"w-full grid grid-cols-1 sm:grid-cols-2 gap-3",children:[(0,le.jsxs)("div",{className:"flex flex-col justify-start items-start gap-1",children:[(0,le.jsx)(go,{className:"text-gray-700 text-sm font-medium font-base44 leading-tight",children:"Starting budget (USD)"}),(0,le.jsxs)("div",{className:"w-full h-10 px-3 py-2 bg-white rounded-lg border border-slate-200 inline-flex justify-start items-center gap-2 overflow-hidden",children:[(0,le.jsx)("span",{className:"text-slate-500 text-sm font-normal font-base44 leading-tight",children:"$"}),(0,le.jsx)("input",{type:"number",min:"0",placeholder:"e.g, 5000",value:t.budget_starting_from_dollars,onChange:e=>a("budget_starting_from_dollars",e.target.value),className:"flex-1 text-sm font-normal font-base44 leading-tight bg-transparent border-none outline-none placeholder:text-slate-400"})]}),s.budget_starting_from_dollars&&(0,le.jsx)("p",{className:"text-sm text-red-500 mt-1",children:s.budget_starting_from_dollars})]}),(0,le.jsxs)("div",{className:"flex flex-col justify-start items-start gap-1",children:[(0,le.jsx)(go,{className:"text-gray-700 text-sm font-medium font-base44 leading-tight",children:"Hourly rate (USD)"}),(0,le.jsxs)("div",{className:"w-full h-10 px-3 py-2 bg-white rounded-lg border border-slate-200 inline-flex justify-start items-center gap-2",children:[(0,le.jsx)("span",{className:"text-slate-500 text-sm font-normal font-base44 leading-tight",children:"$"}),(0,le.jsx)("input",{type:"number",min:"0",placeholder:"e.g, 150",value:t.hourly_rate,onChange:e=>a("hourly_rate",e.target.value),className:"flex-1 text-sm font-normal font-base44 leading-tight bg-transparent border-none outline-none placeholder:text-slate-400"})]}),s.hourly_rate&&(0,le.jsx)("p",{className:"text-sm text-red-500 mt-1",children:s.hourly_rate})]})]}),s.pricing&&(0,le.jsx)("p",{className:"text-sm text-red-500 mt-1",children:s.pricing})]}),(0,le.jsxs)("div",{className:"w-full flex flex-col justify-start items-start gap-2",children:[(0,le.jsxs)("div",{className:"w-full grid grid-cols-1 sm:grid-cols-2 gap-3",children:[(0,le.jsx)(Wk,{label:"Add Website link",placeholder:"Paste website URL",value:t.website_url,onChange:e=>a("website_url",e),error:s.website_url,type:"url",className:"w-full"}),(0,le.jsx)(Wk,{label:"LinkedIn link",placeholder:"Paste LinkedIn URL",value:t.linkedin_url,onChange:e=>a("linkedin_url",e),error:s.linkedin_url,type:"url",className:"w-full"})]}),(0,le.jsx)("div",{className:"w-full flex flex-col justify-start items-start",children:(0,le.jsx)("p",{className:"text-slate-500 text-sm font-normal font-base44 leading-tight",children:"At least one link is required."})})]}),(0,le.jsxs)("div",{className:"w-full flex flex-col justify-start items-start gap-1",children:[(0,le.jsx)(go,{className:"text-gray-700 text-sm font-medium font-base44 leading-tight",children:"What is your preferred working language?"}),(0,le.jsx)("div",{className:"w-full h-40 bg-white rounded-lg border border-slate-200 overflow-hidden",children:(0,le.jsx)("div",{className:"h-full overflow-y-auto pl-3 pr-1.5 py-3",children:(0,le.jsx)("div",{className:"grid grid-cols-2 gap-x-3 gap-y-1.5",children:Yk.map(e=>(0,le.jsxs)("div",{className:"inline-flex justify-start items-center gap-2",children:[(0,le.jsx)(Xp,{id:"lang-".concat(e.value),checked:t.languages.includes(e.value),onCheckedChange:()=>n(e.value),className:"w-4 h-4"}),(0,le.jsx)(go,{htmlFor:"lang-".concat(e.value),className:"text-gray-700 text-sm font-normal font-base44 leading-tight cursor-pointer",children:e.label})]},e.value))})})}),s.languages&&(0,le.jsx)("p",{className:"text-sm text-red-500 mt-1",children:s.languages})]})]})},pC=e=>{let{options:t,selectedOptions:s,onToggle:a,getOptionLabel:n=e=>String(e),getOptionKey:l=e=>String(e),className:r,buttonClassName:i,multiple:o=!0,disabled:c=!1}=e;return(0,le.jsx)("div",{className:Pe("w-full inline-flex justify-start items-start gap-3 flex-wrap content-start",r),children:t.map(e=>{const t=(e=>s.some(t=>l(t)===l(e)))(e);return(0,le.jsx)("button",{type:"button",onClick:()=>(e=>{c||a(e)})(e),disabled:c,className:Pe("p-3 rounded-lg outline outline-1 outline-offset-[-1px] flex justify-center items-center gap-3 transition-all duration-200",t?"bg-gray-800 outline-gray-800 text-white hover:bg-gray-900 hover:outline-gray-900":"bg-white outline-gray-200 text-black hover:bg-slate-100 hover:outline-slate-950/50",c&&"opacity-50 cursor-not-allowed hover:bg-white hover:outline-gray-200",c&&t&&"hover:bg-gray-800 hover:outline-gray-800",i),children:(0,le.jsx)("div",{className:"inline-flex flex-col justify-center items-start gap-0.5",children:(0,le.jsx)("div",{className:"inline-flex justify-start items-center gap-2",children:(0,le.jsx)("span",{className:"text-sm font-normal font-base44 leading-tight",children:n(e)})})})},l(e))})})},gC=e=>{var t,s;let{formData:a,errors:n,onInputChange:l,onServiceToggle:r}=e;return(0,le.jsxs)("div",{className:"w-full p-6 bg-white flex flex-col justify-start items-start gap-6",children:[(0,le.jsxs)("div",{className:"w-full flex flex-col justify-start items-start gap-2",children:[(0,le.jsxs)("div",{className:"flex flex-col justify-start items-start gap-0.5",children:[(0,le.jsx)(go,{className:"text-gray-700 text-sm font-medium font-base44 leading-tight",children:"Which services do you offer?"}),(0,le.jsx)("p",{className:"text-slate-500 text-sm font-normal font-base44 leading-tight",children:"Please select at least one service"})]}),(0,le.jsx)(pC,{options:Hk,selectedOptions:a.services,onToggle:r}),n.services&&(0,le.jsx)("p",{className:"text-sm text-red-500 mt-1",children:n.services})]}),a.services.includes("Other")&&(0,le.jsx)("div",{className:"w-full",children:(0,le.jsx)(Wk,{label:"Tell us what service you offer",placeholder:"Describe your service...",value:a.other_service_description||"",onChange:e=>l("other_service_description",e),error:n.other_service_description,helperText:"".concat(null!==(t=null===(s=a.other_service_description)||void 0===s?void 0:s.length)&&void 0!==t?t:0,"/30 characters"),className:"w-full"})})]})},fC=e=>{let{formData:t,errors:s,onInputChange:a,onAppsModeToggle:n}=e;const l=t.apps&&t.apps.length>0?t.apps.length<2?[...t.apps,...Array(2-t.apps.length).fill({url:"",allow_public_showcase:!0})]:t.apps:[{url:"",allow_public_showcase:!0},{url:"",allow_public_showcase:!0}],r=t.has_apps_to_share?"has_apps":"no_apps";return(0,le.jsxs)("div",{"data-testid":"apps-step",className:"w-full p-6 bg-white flex flex-col justify-start items-start gap-4 overflow-hidden",children:[(0,le.jsx)("div",{className:"flex flex-col justify-start items-start gap-1",children:(0,le.jsx)("div",{className:"flex flex-col justify-start items-start",children:(0,le.jsx)("div",{className:"justify-center text-gray-700 text-base font-semibold font-base44 leading-normal",children:"Show us your work on Base44"})})}),(0,le.jsx)(xC,{label:"",value:r,onValueChange:e=>n("has_apps"===e),options:[{value:"has_apps",label:"I have apps to share"},{value:"no_apps",label:"I don't have apps to share"}]}),t.has_apps_to_share?(0,le.jsxs)("div",{className:"w-full pt-3 flex flex-col justify-start items-start gap-2",children:[(0,le.jsxs)("div",{className:"w-full flex gap-4",children:[(0,le.jsx)("div",{className:"flex-[3] min-w-0",children:(0,le.jsxs)("div",{className:"text-left text-gray-700 text-sm font-medium font-base44 leading-tight",children:["App links",s.apps&&(0,le.jsx)("div",{className:"text-red-500 text-xs mt-1 font-normal",children:s.apps})]})}),(0,le.jsx)("div",{className:"flex-[2] min-w-0",children:(0,le.jsxs)("div",{className:"text-left text-gray-700 text-sm font-medium font-base44 leading-tight flex items-center gap-1",children:["Share apps publicly",(0,le.jsx)(Fi,{children:(0,le.jsxs)(Bi,{delayDuration:100,children:[(0,le.jsx)(zi,{asChild:!0,children:(0,le.jsx)(uo.A,{className:"h-4 w-4 text-gray-600 hover:text-gray-900"})}),(0,le.jsx)(Ui,{className:"max-w-[240px] p-3 text-xs",children:(0,le.jsx)("p",{children:"Public apps will be showcased to other users. Private apps are only shared with us for review."})})]})})]})})]}),(0,le.jsx)("div",{className:"w-full flex flex-col gap-3",children:l.map((e,s)=>(0,le.jsxs)("div",{className:"w-full flex gap-4 items-center",children:[(0,le.jsx)("div",{className:"flex-[3] min-w-0",children:(0,le.jsx)(Wk,{label:"",placeholder:"https://base44.com/app/my-app",value:e.url,onChange:e=>((e,s)=>{const n=[...t.apps||[]];for(;n.length<2;)n.push({url:"",allow_public_showcase:!0});n[e]||(n[e]={url:"",allow_public_showcase:!0}),n[e]=(0,K.A)((0,K.A)({},n[e]),{},{url:s}),a("apps",n)})(s,e),error:null,type:"url",className:"w-full"})}),(0,le.jsx)("div",{className:"flex-[2] min-w-0",children:(0,le.jsxs)("div",{className:"flex justify-start items-center gap-2",children:[(0,le.jsx)(Xp,{id:"showcase-".concat(s),checked:e.allow_public_showcase,onCheckedChange:e=>((e,s)=>{const n=[...t.apps||[]];n[e]||(n[e]={url:"",allow_public_showcase:!0}),n[e]=(0,K.A)((0,K.A)({},n[e]),{},{allow_public_showcase:s}),a("apps",n)})(s,e),className:"w-4 h-4"}),(0,le.jsx)(go,{htmlFor:"showcase-".concat(s),className:"text-gray-950 text-sm font-normal font-base44 leading-tight pointer-events-none",children:"Share publicly"})]})})]},s))}),(0,le.jsxs)(Hn,{type:"button",variant:"secondary",size:"sm",onClick:()=>{const e=[...t.apps||[]];for(;e.length<2;)e.push({url:"",allow_public_showcase:!0});e.length<5&&e.push({url:"",allow_public_showcase:!0}),a("apps",e)},disabled:l.length>=5,className:"h-7 px-3 gap-1.5",children:[l.length<5?(0,le.jsx)(kt.A,{className:"w-4 h-4"}):null,l.length>=5?"Maximum 5 apps":"Add link"]})]}):(0,le.jsx)("div",{className:"w-full pt-3",children:(0,le.jsx)(Wk,{label:"What makes you a great partner?",placeholder:"Describe your relevant experience",value:t.no_apps_explanation||"",onChange:e=>a("no_apps_explanation",e),error:s.no_apps_explanation,type:"textarea",required:!0,helperText:"".concat((t.no_apps_explanation||"").length," characters (minimum 20)"),rows:4,className:"w-full h-30",tooltipText:"Will be reviewed internally by Base44"})})]})},vC=e=>{var t;let{formData:s,userEmail:a,logoPreview:n}=e;const l=(()=>{const e=[];return s.website_url&&e.push(s.website_url.replace(/^https?:\/\//,"").replace(/^www\./,"")),s.linkedin_url&&e.push(s.linkedin_url.replace(/^https?:\/\//,"").replace(/^www\./,"")),e})(),r=(()=>{let e=[...s.services];return e.includes("Other")&&s.other_service_description&&(e=e.filter(e=>"Other"!==e),e.push(s.other_service_description)),e})(),i=[{label:"Type",value:"individual"===s.individual_or_team?"Individual":"Team/Agency"},{label:"Location",value:"".concat(s.city,", ").concat(s.country)},{label:"Links",value:(0,le.jsx)("div",{className:"flex flex-wrap items-center gap-3",children:l.map((e,t)=>(0,le.jsxs)(Y.Fragment,{children:[(0,le.jsx)("div",{className:"text-gray-950 text-sm font-medium font-base44 leading-tight break-words",children:e}),t0},{label:"Languages",value:s.languages.map(e=>{var t;return(null===(t=Yk.find(t=>t.value===e))||void 0===t?void 0:t.label)||e}).join(", "),show:s.languages.length>0},{label:"Services",value:(0,le.jsx)("div",{className:"flex flex-col gap-1",children:r.map((e,t)=>(0,le.jsxs)("div",{className:"text-gray-950 text-sm font-medium font-base44 leading-tight break-words",children:["\u2022 ",e]},t))}),show:s.services.length>0},{label:"Pricing",value:(0,le.jsxs)("div",{className:"flex flex-wrap items-center gap-3",children:[s.budget_starting_from_dollars&&(0,le.jsxs)(le.Fragment,{children:[(0,le.jsxs)("div",{className:"text-gray-950 text-sm font-medium font-base44 leading-tight break-words",children:["From $",s.budget_starting_from_dollars]}),s.hourly_rate&&(0,le.jsx)("div",{className:"w-1 h-1 bg-gray-500 rounded-full flex-shrink-0"})]}),s.hourly_rate&&(0,le.jsxs)("div",{className:"text-gray-950 text-sm font-medium font-base44 leading-tight break-words",children:["$",s.hourly_rate,"/hour"]})]}),show:!(!s.budget_starting_from_dollars&&!s.hourly_rate)},{label:"Description",value:(0,le.jsx)("div",{className:"text-gray-950 text-sm font-medium font-base44 leading-tight whitespace-pre-wrap break-words",children:s.description}),show:!!s.description},{label:"Apps",value:(0,le.jsx)("div",{className:"flex flex-col gap-2",children:null===(t=s.apps)||void 0===t?void 0:t.filter(e=>e.url&&e.url.trim()).map((e,t)=>{return(0,le.jsxs)("div",{className:"flex flex-col sm:flex-row sm:items-start gap-1 sm:gap-2",children:[(0,le.jsxs)("div",{className:"flex-1 justify-start text-gray-950 text-sm font-medium font-base44 leading-tight break-words",children:["\u2022 ",(s=e.url,s.replace(/^https?:\/\//,"").replace(/^www\./,""))]}),e.allow_public_showcase&&(0,le.jsx)("span",{className:"text-xs text-slate-900 bg-gray-200 px-2 py-1 max-w-16 rounded flex-shrink-0",children:"Allowed"})]},t);var s})}),show:s.has_apps_to_share&&s.apps&&s.apps.length>0&&s.apps.some(e=>e.url&&e.url.trim())},{label:"Experience",value:(0,le.jsx)("div",{className:"text-gray-950 text-sm font-medium font-base44 leading-tight whitespace-pre-wrap break-words",children:s.no_apps_explanation}),show:!s.has_apps_to_share&&!!s.no_apps_explanation}];return(0,le.jsxs)("div",{className:"w-full p-6 bg-white inline-flex flex-col justify-start items-start gap-3 overflow-hidden",children:[(0,le.jsxs)("p",{className:"w-full text-gray-700 text-sm font-normal font-base44 leading-tight",children:["Our team will review your application and get back to you soon. You'll receive an email at"," ",(0,le.jsx)("span",{className:"font-medium",children:a})," once it has been processed."]}),(0,le.jsx)("p",{className:"w-full text-gray-700 text-sm font-medium font-base44 leading-tight",children:"Review your profile card"}),(0,le.jsxs)("div",{className:"w-full p-4 bg-slate-50 rounded-lg border border-slate-300 flex flex-col justify-start items-start gap-3 overflow-hidden",children:[(0,le.jsxs)("div",{className:"w-full inline-flex justify-start items-center gap-3",children:[(0,le.jsx)("div",{className:"w-10 h-10 rounded-md border border-black/10 bg-gray-100 flex items-center justify-center overflow-hidden",children:n||s.logo_url?(0,le.jsx)("img",{src:n||s.logo_url,alt:"Company logo",className:"w-10 h-10 object-cover"}):(0,le.jsx)("div",{className:"w-10 h-10 bg-gray-200 rounded-md flex items-center justify-center",children:(0,le.jsx)("span",{className:"text-xs text-gray-400 font-base44",children:s.name.charAt(0).toUpperCase()})})}),(0,le.jsx)("div",{className:"flex-1 text-black text-base font-medium font-base44 leading-tight",children:s.name})]}),(0,le.jsx)("div",{className:"w-full flex flex-col justify-start items-start gap-[3px] min-w-0",children:i.filter(e=>!1!==e.show).map((e,t)=>(0,le.jsxs)("div",{className:"w-full py-[3px] flex flex-col sm:flex-row sm:items-start gap-1 sm:gap-0",children:[(0,le.jsx)("div",{className:"sm:w-44 sm:flex-shrink-0 justify-start text-black text-sm font-normal font-base44 leading-tight",children:e.label}),(0,le.jsx)("div",{className:"flex-1 justify-start text-gray-950 text-sm font-medium font-base44 leading-tight break-words",children:e.value})]},t))})]})]})};const bC=new class extends Zt{getBaseURL(){return"/partners"}getPartnerById(e){return this.axios.get("/catalog/".concat(e))}contactRequest(e){return this.axios.post("/contact-requests",e)}getAllContactRequests(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return this.axios.get("/contact-requests",{params:e})}},jC={name:"",description:"",logo_url:"",website_url:"",linkedin_url:"",country:"",city:"",individual_or_team:"individual",services:[],languages:[],budget_starting_from_dollars:"",hourly_rate:"",other_service_description:"",apps:[],has_apps_to_share:!0,no_apps_explanation:"",terms_accepted:!1},yC=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"create",s=arguments.length>2?arguments[2]:void 0;const[a,n]=(0,Y.useState)(e||jC),[l,r]=(0,Y.useState)({}),[i,o]=(0,Y.useState)(null),[c,d]=(0,Y.useState)((null==e?void 0:e.logo_url)||null),[m,u]=(0,Y.useState)(!1),x=(e,t)=>{n(s=>(0,K.A)((0,K.A)({},s),{},{[e]:t})),l[e]&&r(t=>(0,K.A)((0,K.A)({},t),{},{[e]:null})),("budget_starting_from_dollars"===e||"hourly_rate"===e)&&l.pricing&&t&&r(e=>(0,K.A)((0,K.A)({},e),{},{pricing:null}))};return{formData:a,errors:l,logoFile:i,logoPreview:c,isSubmitting:m,handleInputChange:x,handleServiceToggle:e=>{const t=a.services.includes(e)?a.services.filter(t=>t!==e):[...a.services,e];x("services",t)},handleLanguageToggle:e=>{const t=a.languages.includes(e)?a.languages.filter(t=>t!==e):[...a.languages,e];x("languages",t)},handleAppsModeToggle:e=>{n(t=>(0,K.A)((0,K.A)({},t),{},{has_apps_to_share:e})),r(e=>(0,K.A)((0,K.A)({},e),{},{apps:null,no_apps_explanation:null}))},handleLogoUpload:e=>{var t;const s=null===(t=e.target.files)||void 0===t?void 0:t[0];if(!s)return;if(!s.type.startsWith("image/"))return void an({title:"Invalid file type",description:"Please upload an image file (PNG, JPG, SVG)",variant:"destructive"});if(s.size>5242880)return void an({title:"File too large",description:"Please upload an image smaller than 5MB",variant:"destructive"});o(s),l.logo&&r(e=>(0,K.A)((0,K.A)({},e),{},{logo:null}));const a=new FileReader;a.onloadend=()=>{d(a.result)},a.readAsDataURL(s)},handleLogoRemove:()=>{o(null),d(null),r(e=>(0,K.A)((0,K.A)({},e),{},{logo:"Logo upload is required"}))},handleTermsToggle:()=>{x("terms_accepted",!a.terms_accepted)},validateStep:e=>{let t;switch(e){case 0:t=((e,t)=>{const s=(0,K.A)((0,K.A)({},e),{},{logo:t}),a=lC.safeParse(s);return a.success?{success:!0,errors:{}}:{success:!1,errors:cC(a.error)}})(a,!(!i&&!a.logo_url));break;case 1:t=(e=>{const t=rC.safeParse(e);return t.success?{success:!0,errors:{}}:{success:!1,errors:cC(t.error)}})(a);break;case 2:t=(e=>{const t=iC.safeParse(e);return t.success?{success:!0,errors:{}}:{success:!1,errors:cC(t.error)}})(a);break;case 3:t=(e=>{const t=oC.safeParse(e);return t.success?{success:!0,errors:{}}:{success:!1,errors:cC(t.error)}})(a);break;default:return!0}return r(t.errors),t.success},handleSubmit:async e=>{const n=(e=>{const t=nC.safeParse(e);return t.success?{success:!0,errors:{}}:{success:!1,errors:cC(t.error)}})(a);if(!n.success)return r(n.errors),!1;if(!e)return an({title:"Authentication Required",description:"Please log in to submit a partner application.",variant:"destructive"}),!1;u(!0);try{let n=a.logo_url;if(i)try{n=(await _t.uploadFile(i)).url}catch(c){an({title:"Logo upload failed",description:"Continuing with application without logo",variant:"destructive"})}const l=(0,K.A)((0,K.A)({},a),{},{logo_url:n,budget_starting_from_dollars:a.budget_starting_from_dollars?parseInt(a.budget_starting_from_dollars):null,hourly_rate:a.hourly_rate?parseInt(a.hourly_rate):null,apps:(a.apps||[]).filter(e=>e.url&&e.url.trim())});if("edit"===t){if(!s)throw new Error("Partner ID is required for updating a partner profile");await bC.update(s,l)}else await bC.create(l);return an("edit"===t?{title:"Success",description:"Partner details updated successfully"}:{description:(0,le.jsx)("div",{className:"flex items-start gap-2",children:(0,le.jsxs)("div",{children:[(0,le.jsx)("p",{className:"font-medium",children:"Thank you for applying to become a partner!"}),(0,le.jsxs)("p",{className:"text-sm text-slate-600 mt-1",children:["We'll review your application and notify you via email at ",e,"."]})]})}),duration:1e4}),!0}catch(c){var l,o;return an({title:"Submission Failed",description:(null===(l=c.response)||void 0===l||null===(o=l.data)||void 0===o?void 0:o.detail)||"Failed to submit application. Please try again.",variant:"destructive"}),!1}finally{u(!1)}},resetForm:()=>{n(jC),o(null),d(null),r({})}}},NC=e=>{let{isOpen:t,onClose:s,mode:a="create",initialData:n,partnerId:l,onSuccess:r}=e;const{user:i}=oe(),[o,c]=(0,Y.useState)(0),{formData:d,errors:m,logoPreview:u,isSubmitting:x,handleInputChange:h,handleServiceToggle:p,handleLanguageToggle:g,handleAppsModeToggle:f,handleLogoUpload:v,handleLogoRemove:b,handleTermsToggle:j,validateStep:y,handleSubmit:N,resetForm:w}=yC(n,a,l),_=[{id:1,title:"Basic Info",description:"Tell us about yourself and your location"},{id:2,title:"Profile",description:"Add your online presence and languages"},{id:3,title:"Services",description:"Define your services and pricing"},{id:4,title:"Apps",description:"Share your apps or explain your experience"},{id:5,title:"Review",description:"Review your application before submitting"}];return t?(0,le.jsx)(Fi,{children:(0,le.jsx)("div",{"data-testid":"become-partner-modal",className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 backdrop-blur-sm",children:(0,le.jsx)(Uk,{"data-testid":"partner-wizard",steps:_,currentStep:o,title:"edit"===a?"Edit Partner Profile":"Become a Base44 Partner",description:"edit"===a?"Update partner information":(0,le.jsxs)(le.Fragment,{children:["Information you provide here will be shown on your Partner profile and will be visible to potential clients."," ",(0,le.jsx)("a",{href:"/partners/terms",target:"_blank",rel:"noopener noreferrer",className:"text-gray-700 hover:text-gray-800 text-sm underline transition-colors",children:"Partners terms of use"})]}),onNext:()=>{y(o)&&c(e=>Math.min(e+1,_.length-1))},onPrevious:()=>{c(e=>Math.max(e-1,0))},onSubmit:async()=>{await N(null==i?void 0:i.email)&&(w(),c(0),s(),r&&r())},onClose:s,isLoading:x,submitButtonText:"edit"===a?"Save Changes":"Submit",className:"w-[640px] h-[600px]",footerLeftContent:o!==_.length-1||"edit"===a?null:(0,le.jsxs)("div",{className:"flex justify-start items-center gap-2",children:[(0,le.jsx)("button",{type:"button",onClick:j,className:"w-4 h-4 rounded outline outline-1 outline-offset-[-1px] flex justify-center items-center transition-colors ".concat(m.terms_accepted?"bg-white outline-red-500 hover:outline-red-600":d.terms_accepted?"bg-gray-800 outline-gray-800":"bg-white outline-gray-300 hover:outline-gray-400"),children:d.terms_accepted&&(0,le.jsx)(Ps.A,{className:"w-3 h-3 text-white",strokeWidth:2})}),(0,le.jsxs)("div",{className:"flex justify-start items-center gap-1",children:[(0,le.jsxs)("span",{className:"text-gray-700 text-sm font-normal font-base44 leading-tight",children:["Agree to"," "]}),(0,le.jsx)("a",{href:"/partners/terms",target:"_blank",rel:"noopener noreferrer",className:"text-gray-700 text-sm font-normal font-base44 underline leading-tight hover:text-gray-800 transition-colors",children:"terms of use"}),m.terms_accepted&&(0,le.jsxs)(Bi,{delayDuration:100,children:[(0,le.jsx)(zi,{asChild:!0,children:(0,le.jsx)(uo.A,{className:"w-4 h-4 text-red-500"})}),(0,le.jsx)(Ui,{children:(0,le.jsx)("p",{children:"You must agree to the terms of service to become a partner."})})]})]})]}),children:(0,le.jsx)("div",{"data-testid":"step-content",children:(()=>{switch(o){case 0:return(0,le.jsx)(uC,{formData:d,errors:m,logoPreview:u,onInputChange:h,onLogoUpload:v,onLogoRemove:b});case 1:return(0,le.jsx)(hC,{formData:d,errors:m,onInputChange:h,onLanguageToggle:g});case 2:return(0,le.jsx)(gC,{formData:d,errors:m,onInputChange:h,onServiceToggle:p});case 3:return(0,le.jsx)(fC,{formData:d,errors:m,onInputChange:h,onAppsModeToggle:f});case 4:return(0,le.jsx)(vC,{formData:d,userEmail:null==i?void 0:i.email,logoPreview:u});default:return null}})()})})})}):null};var wC=s(76274),_C=s(78130),kC=s(41016),CC=s(31855),AC=s(14215);const SC=e=>e&&Array.isArray(e)?e.map(e=>{const t=Yk.find(t=>t.value===e);return t?t.label:e}):[];function EC(e){let{showAnalytics:t=!1,setShowAnalytics:s=()=>{}}=e;const[a,n]=(0,Y.useState)([]),[l,r]=(0,Y.useState)(!0),[i,o]=(0,Y.useState)("all"),[c,d]=(0,Y.useState)(""),[m,u]=(0,Y.useState)(null),[x,h]=(0,Y.useState)(!1),[p,g]=(0,Y.useState)(""),[f,v]=(0,Y.useState)(null),[b,j]=(0,Y.useState)(!1),[y,N]=(0,Y.useState)(1),[w,_]=(0,Y.useState)(0),[k,C]=(0,Y.useState)({key:"created_date",direction:"desc"}),[A,S]=(0,Y.useState)(null),[E,I]=(0,Y.useState)({}),[T,P]=(0,Y.useState)(new Set),[L,O]=(0,Y.useState)("all"),[R,M]=(0,Y.useState)(""),D=50,[F,B]=(0,Y.useState)([]),[z,U]=(0,Y.useState)([]),[W,q]=(0,Y.useState)(!1);(0,Y.useEffect)(()=>{if(A&&clearTimeout(A),1===y)return S(setTimeout(()=>{V()},500)),()=>{A&&clearTimeout(A)};N(1)},[c,i,L,R,k]),(0,Y.useEffect)(()=>{V()},[y]);const V=async()=>{try{r(!0);let e={archived:!1};c&&(e.$or=[{name:{$regex:c,$options:"i"}},{description:{$regex:c,$options:"i"}},{city:{$regex:c,$options:"i"}},{country:{$regex:c,$options:"i"}},{services:{$regex:c,$options:"i"}},{languages:{$regex:c,$options:"i"}}]),"all"!==i&&(e.status=i),"all"!==L&&(e.individual_or_team=L),R&&(e.$or=e.$or?[...e.$or,{city:{$regex:R,$options:"i"}},{country:{$regex:R,$options:"i"}}]:[{city:{$regex:R,$options:"i"}},{country:{$regex:R,$options:"i"}}]);const t=(0,K.A)((0,K.A)({},e),{},{limit:D,skip:(y-1)*D,sort_by:"desc"===k.direction?"-".concat(k.key):k.key}),s=await bC.listCatalogItems(t),a=s.items||s;n(a),a.length{const t=e.item.id;I(e=>(0,K.A)((0,K.A)({},e),{},{[t]:!0}));try{await bC.approveItem(t),an({title:"Success",description:"".concat(e.item.name," has been approved")}),await V()}catch(s){an({title:"Error",description:"Failed to approve partner",variant:"destructive"})}finally{I(e=>(0,K.A)((0,K.A)({},e),{},{[t]:!1}))}},G=e=>{u(e),g(""),h(!0)},$=e=>{const t=k.key===e&&"asc"===k.direction?"desc":"asc";C({key:e,direction:t}),N(1)},J=()=>"all"!==i||"all"!==L||""!==R||""!==c,Z=e=>{switch(e){case"approved":return(0,le.jsxs)(es,{className:"bg-emerald-100 text-emerald-700 border-emerald-200 font-medium px-2.5 py-0.5 text-xs",children:[(0,le.jsx)("div",{className:"w-1.5 h-1.5 bg-emerald-500 rounded-full mr-1.5"}),"Approved"]});case"rejected":return(0,le.jsxs)(es,{className:"bg-red-100 text-red-700 border-red-200 font-medium px-2.5 py-0.5 text-xs",children:[(0,le.jsx)("div",{className:"w-1.5 h-1.5 bg-red-500 rounded-full mr-1.5"}),"Rejected"]});default:return(0,le.jsxs)(es,{className:"bg-amber-100 text-amber-700 border-amber-200 font-medium px-2.5 py-0.5 text-xs",children:[(0,le.jsx)(Li.A,{className:"w-3 h-3 mr-1.5"}),"Pending"]})}};return(0,le.jsxs)(le.Fragment,{children:[(0,le.jsxs)("div",{className:"flex items-center justify-between mb-6",children:[(0,le.jsx)("h1",{className:"text-3xl font-bold",children:"Partner Management"}),(0,le.jsxs)(Yt,{onClick:()=>t?s(!1):(async()=>{q(!0);try{const[e,t]=await Promise.all([bC.listCatalogItems({limit:1e4,skip:0,sort_by:"-created_date"}),bC.getAllContactRequests({limit:1e4,skip:0,sort_by:"-created_date"})]),a=e.items||e,n=t.items||t;B(a),U(n),s(!0)}catch(e){an({title:"Error",description:"Failed to fetch analytics data",variant:"destructive"})}finally{q(!1)}})(),disabled:W,className:"flex items-center gap-2",variant:t?"default":"outline",children:[(0,le.jsx)(Dx.A,{className:"h-4 w-4"}),W?"Analyzing...":t?"Hide Analytics":"Analyze"]})]}),t&&F.length>0&&(0,le.jsxs)("div",{className:"mb-8 bg-gradient-to-br from-slate-50 to-white p-8 rounded-2xl border border-slate-200 shadow-lg",children:[(0,le.jsxs)("div",{className:"flex items-center justify-between mb-8",children:[(0,le.jsxs)("div",{className:"flex items-center gap-3",children:[(0,le.jsx)("div",{className:"p-2 bg-blue-100 rounded-xl",children:(0,le.jsx)(Dx.A,{className:"h-6 w-6 text-blue-600"})}),(0,le.jsxs)("div",{children:[(0,le.jsx)("h2",{className:"text-2xl font-bold text-slate-900",children:"Partner Analytics Dashboard"}),(0,le.jsxs)("p",{className:"text-sm text-slate-600 mt-1",children:["Real-time insights across ",F.length," partners"]})]})]}),(0,le.jsx)(Yt,{variant:"ghost",size:"sm",onClick:()=>s(!1),className:"h-10 w-10 p-0 hover:bg-slate-100 rounded-xl",children:(0,le.jsx)(Bt.A,{className:"h-5 w-5 text-slate-400"})})]}),(()=>{const e=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];const s={total:e.length,approved:e.filter(e=>"approved"===e.item.status).length,pending:e.filter(e=>"pending"===e.item.status).length,rejected:e.filter(e=>"rejected"===e.item.status).length,archived:e.filter(e=>e.item.archived).length},a={individual:e.filter(e=>"individual"===e.item.individual_or_team).length,team:e.filter(e=>"team"===e.item.individual_or_team).length},n=e.reduce((e,t)=>(t.item.languages&&t.item.languages.forEach(t=>{e[t]=(e[t]||0)+1}),e),{}),l=e.reduce((e,t)=>{const s=$k(t.item.country)||t.item.country||"Unknown";return e[s]=(e[s]||0)+1,e},{}),r=e.reduce((e,t)=>(t.item.services&&t.item.services.forEach(t=>{e[t]=(e[t]||0)+1}),e),{}),i={withBudget:e.filter(e=>e.item.budget_starting_from_dollars).length,withHourlyRate:e.filter(e=>e.item.hourly_rate).length,averageBudget:e.filter(e=>e.item.budget_starting_from_dollars).reduce((e,t)=>e+t.item.budget_starting_from_dollars,0)/e.filter(e=>e.item.budget_starting_from_dollars).length||0,averageHourlyRate:e.filter(e=>e.item.hourly_rate).reduce((e,t)=>e+t.item.hourly_rate,0)/e.filter(e=>e.item.hourly_rate).length||0},o={withDescriptions:e.filter(e=>e.item.description&&e.item.description.trim()).length,withLogos:e.filter(e=>e.item.logo_url&&e.item.logo_url.trim()).length,withWebsites:e.filter(e=>e.item.website_url&&e.item.website_url.trim()).length,withApps:e.filter(e=>e.item.has_apps_to_share&&e.item.apps&&e.item.apps.length>0).length,termsAccepted:e.filter(e=>e.item.terms_accepted).length},c=e.reduce((e,t)=>{var s;const a=(null===(s=t.item_creator)||void 0===s?void 0:s.full_name)||"Unknown";return e[a]=(e[a]||0)+1,e},{}),d=ra()(),m=e.filter(e=>ra()(e.item.created_date).isSame(d,"month")).length,u=e.filter(e=>ra()(e.item.created_date).isSame(d,"quarter")).length,x={total:t.length,thisMonth:t.filter(e=>ra()(e.created_date).isSame(d,"month")).length,thisQuarter:t.filter(e=>ra()(e.created_date).isSame(d,"quarter")).length},h=t.reduce((e,t)=>{const s=t.partner_name||"Unknown";return e[s]=(e[s]||0)+1,e},{}),p=t.reduce((e,t)=>{const s=t.project_type||"unknown";return e[s]=(e[s]||0)+1,e},{}),g=t.reduce((e,t)=>{const s=t.work_basis||"unknown";return e[s]=(e[s]||0)+1,e},{}),f=t.reduce((e,t)=>{const s=t.start_date||"unknown";return e[s]=(e[s]||0)+1,e},{}),v={uniqueClients:new Set(t.map(e=>e.client_email)).size,averageRequestsPerClient:t.length/new Set(t.map(e=>e.client_email)).size||0,repeatClients:Object.values(t.reduce((e,t)=>(e[t.client_email]=(e[t.client_email]||0)+1,e),{})).filter(e=>e>1).length};return{statusStats:s,typeStats:a,languageStats:n,countryStats:l,serviceStats:r,pricingStats:i,contentStats:o,creatorStats:Object.entries(c).sort((e,t)=>{let[,s]=e,[,a]=t;return a-s}).slice(0,10),topCountries:Object.entries(l).sort((e,t)=>{let[,s]=e,[,a]=t;return a-s}).slice(0,5),topServices:Object.entries(r).sort((e,t)=>{let[,s]=e,[,a]=t;return a-s}).slice(0,5),temporalStats:{thisMonth:m,thisQuarter:u,totalCreators:Object.keys(c).length},contactRequestsStats:x,topPartnersByRequests:Object.entries(h).sort((e,t)=>{let[,s]=e,[,a]=t;return a-s}).slice(0,10),projectTypeStats:p,workBasisStats:g,startDateStats:f,clientEngagementStats:v}}(F,z);return(0,le.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6",children:[(0,le.jsxs)("div",{className:"bg-white p-6 rounded-xl border border-slate-200 shadow-sm hover:shadow-md transition-shadow",children:[(0,le.jsxs)("div",{className:"flex items-center gap-3 mb-6",children:[(0,le.jsx)("div",{className:"p-2 bg-emerald-100 rounded-lg",children:(0,le.jsx)(nj.A,{className:"h-5 w-5 text-emerald-600"})}),(0,le.jsxs)("div",{children:[(0,le.jsx)("h3",{className:"font-semibold text-slate-800",children:"Status Overview"}),(0,le.jsx)("p",{className:"text-xs text-slate-500",children:"Approval pipeline health"})]})]}),(0,le.jsxs)("div",{className:"space-y-4",children:[(0,le.jsxs)("div",{className:"text-center p-4 bg-slate-50 rounded-lg",children:[(0,le.jsx)("div",{className:"text-3xl font-bold text-slate-900",children:e.statusStats.total}),(0,le.jsx)("div",{className:"text-sm text-slate-600 font-medium",children:"Total Partners"})]}),(0,le.jsxs)("div",{className:"space-y-3",children:[(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsxs)("div",{className:"flex justify-between items-center",children:[(0,le.jsx)("span",{className:"text-sm font-medium text-emerald-700",children:"Approved"}),(0,le.jsxs)("span",{className:"text-sm font-bold text-emerald-700",children:[e.statusStats.approved," (",(e.statusStats.approved/e.statusStats.total*100).toFixed(1),"%)"]})]}),(0,le.jsx)("div",{className:"w-full bg-emerald-100 rounded-full h-2",children:(0,le.jsx)("div",{className:"bg-emerald-500 h-2 rounded-full transition-all duration-500",style:{width:"".concat(e.statusStats.approved/e.statusStats.total*100,"%")}})})]}),(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsxs)("div",{className:"flex justify-between items-center",children:[(0,le.jsx)("span",{className:"text-sm font-medium text-amber-700",children:"Pending"}),(0,le.jsxs)("span",{className:"text-sm font-bold text-amber-700",children:[e.statusStats.pending," (",(e.statusStats.pending/e.statusStats.total*100).toFixed(1),"%)"]})]}),(0,le.jsx)("div",{className:"w-full bg-amber-100 rounded-full h-2",children:(0,le.jsx)("div",{className:"bg-amber-500 h-2 rounded-full transition-all duration-500",style:{width:"".concat(e.statusStats.pending/e.statusStats.total*100,"%")}})})]}),(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsxs)("div",{className:"flex justify-between items-center",children:[(0,le.jsx)("span",{className:"text-sm font-medium text-red-700",children:"Rejected"}),(0,le.jsxs)("span",{className:"text-sm font-bold text-red-700",children:[e.statusStats.rejected," (",(e.statusStats.rejected/e.statusStats.total*100).toFixed(1),"%)"]})]}),(0,le.jsx)("div",{className:"w-full bg-red-100 rounded-full h-2",children:(0,le.jsx)("div",{className:"bg-red-500 h-2 rounded-full transition-all duration-500",style:{width:"".concat(e.statusStats.rejected/e.statusStats.total*100,"%")}})})]})]})]})]}),(0,le.jsxs)("div",{className:"bg-white p-6 rounded-xl border border-slate-200 shadow-sm hover:shadow-md transition-shadow",children:[(0,le.jsxs)("div",{className:"flex items-center gap-3 mb-6",children:[(0,le.jsx)("div",{className:"p-2 bg-blue-100 rounded-lg",children:(0,le.jsx)(Xl.A,{className:"h-5 w-5 text-blue-600"})}),(0,le.jsxs)("div",{children:[(0,le.jsx)("h3",{className:"font-semibold text-slate-800",children:"Partner Analytics"}),(0,le.jsx)("p",{className:"text-xs text-slate-500",children:"Types and geographic distribution"})]})]}),(0,le.jsxs)("div",{className:"space-y-4",children:[(0,le.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,le.jsxs)("div",{className:"text-center p-3 bg-gradient-to-br from-blue-50 to-blue-100 rounded-lg",children:[(0,le.jsx)("div",{className:"text-2xl font-bold text-blue-900",children:e.typeStats.individual}),(0,le.jsx)("div",{className:"text-xs text-blue-700 font-medium",children:"Individuals"})]}),(0,le.jsxs)("div",{className:"text-center p-3 bg-gradient-to-br from-indigo-50 to-indigo-100 rounded-lg",children:[(0,le.jsx)("div",{className:"text-2xl font-bold text-indigo-900",children:e.typeStats.team}),(0,le.jsx)("div",{className:"text-xs text-indigo-700 font-medium",children:"Teams"})]})]}),(0,le.jsxs)("div",{className:"p-4 bg-slate-50 rounded-lg border-l-4 border-green-500",children:[(0,le.jsx)("div",{className:"text-sm font-medium text-slate-700 mb-2",children:"Top Regions"}),(0,le.jsx)("div",{className:"space-y-2",children:e.topCountries.slice(0,3).map((e,t)=>{let[s,a]=e;return(0,le.jsxs)("div",{className:"flex justify-between items-center",children:[(0,le.jsx)("span",{className:"text-xs text-slate-600",children:s}),(0,le.jsx)("span",{className:"text-xs font-bold text-slate-900",children:a})]},s)})})]})]})]}),(0,le.jsxs)("div",{className:"bg-white p-6 rounded-xl border border-slate-200 shadow-sm hover:shadow-md transition-shadow",children:[(0,le.jsxs)("div",{className:"flex items-center gap-3 mb-6",children:[(0,le.jsx)("div",{className:"p-2 bg-purple-100 rounded-lg",children:(0,le.jsx)(wC.A,{className:"h-5 w-5 text-purple-600"})}),(0,le.jsxs)("div",{children:[(0,le.jsx)("h3",{className:"font-semibold text-slate-800",children:"Profile Quality"}),(0,le.jsx)("p",{className:"text-xs text-slate-500",children:"Completeness metrics"})]})]}),(0,le.jsxs)("div",{className:"space-y-4",children:[(0,le.jsxs)("div",{className:"space-y-3",children:[(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsxs)("div",{className:"flex justify-between items-center",children:[(0,le.jsx)("span",{className:"text-sm font-medium text-slate-700",children:"With Descriptions"}),(0,le.jsxs)("span",{className:"text-sm font-bold text-slate-900",children:[(e.contentStats.withDescriptions/e.statusStats.total*100).toFixed(1),"%"]})]}),(0,le.jsx)("div",{className:"w-full bg-gray-200 rounded-full h-2",children:(0,le.jsx)("div",{className:"bg-gradient-to-r from-green-400 to-green-600 h-2 rounded-full transition-all duration-500",style:{width:"".concat(e.contentStats.withDescriptions/e.statusStats.total*100,"%")}})})]}),(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsxs)("div",{className:"flex justify-between items-center",children:[(0,le.jsx)("span",{className:"text-sm font-medium text-slate-700",children:"Terms Accepted"}),(0,le.jsxs)("span",{className:"text-sm font-bold text-slate-900",children:[(e.contentStats.termsAccepted/e.statusStats.total*100).toFixed(1),"%"]})]}),(0,le.jsx)("div",{className:"w-full bg-gray-200 rounded-full h-2",children:(0,le.jsx)("div",{className:"bg-gradient-to-r from-blue-400 to-blue-600 h-2 rounded-full transition-all duration-500",style:{width:"".concat(e.contentStats.termsAccepted/e.statusStats.total*100,"%")}})})]})]}),(0,le.jsxs)("div",{className:"grid grid-cols-2 gap-3 pt-2",children:[(0,le.jsxs)("div",{className:"text-center p-3 bg-green-50 rounded-lg border border-green-200",children:[(0,le.jsx)("div",{className:"text-xl font-bold text-green-700",children:e.contentStats.withLogos}),(0,le.jsx)("div",{className:"text-xs text-green-600 font-medium",children:"With Logos"})]}),(0,le.jsxs)("div",{className:"text-center p-3 bg-orange-50 rounded-lg border border-orange-200",children:[(0,le.jsx)("div",{className:"text-xl font-bold text-orange-700",children:e.contentStats.withApps}),(0,le.jsx)("div",{className:"text-xs text-orange-600 font-medium",children:"With Apps"})]})]})]})]}),(0,le.jsxs)("div",{className:"bg-white p-6 rounded-xl border border-slate-200 shadow-sm hover:shadow-md transition-shadow",children:[(0,le.jsxs)("div",{className:"flex items-center gap-3 mb-6",children:[(0,le.jsx)("div",{className:"p-2 bg-teal-100 rounded-lg",children:(0,le.jsx)(bn.A,{className:"h-5 w-5 text-teal-600"})}),(0,le.jsxs)("div",{children:[(0,le.jsx)("h3",{className:"font-semibold text-slate-800",children:"Services & Languages"}),(0,le.jsx)("p",{className:"text-xs text-slate-500",children:"Service portfolio analysis"})]})]}),(0,le.jsx)("div",{className:"space-y-4",children:(0,le.jsxs)("div",{className:"space-y-3",children:[(0,le.jsx)("div",{className:"text-sm font-medium text-slate-700",children:"Top Services"}),e.topServices.slice(0,4).map((t,s)=>{let[a,n]=t;const l=n/e.statusStats.total*100;return(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsxs)("div",{className:"flex justify-between items-center",children:[(0,le.jsx)("span",{className:"text-sm font-medium text-slate-700",children:a}),(0,le.jsxs)("span",{className:"text-sm font-bold text-slate-900",children:[n," (",l.toFixed(1),"%)"]})]}),(0,le.jsx)("div",{className:"w-full bg-gray-200 rounded-full h-2",children:(0,le.jsx)("div",{className:"".concat(["bg-blue-500","bg-green-500","bg-purple-500","bg-orange-500"][s]," h-2 rounded-full transition-all duration-500"),style:{width:"".concat(l,"%")}})})]},a)})]})})]}),(0,le.jsxs)("div",{className:"bg-white p-6 rounded-xl border border-slate-200 shadow-sm hover:shadow-md transition-shadow",children:[(0,le.jsxs)("div",{className:"flex items-center gap-3 mb-6",children:[(0,le.jsx)("div",{className:"p-2 bg-rose-100 rounded-lg",children:(0,le.jsx)(_C.A,{className:"h-5 w-5 text-rose-600"})}),(0,le.jsxs)("div",{children:[(0,le.jsx)("h3",{className:"font-semibold text-slate-800",children:"Top Contributors"}),(0,le.jsx)("p",{className:"text-xs text-slate-500",children:"Most active partner creators"})]})]}),(0,le.jsxs)("div",{className:"space-y-4",children:[(0,le.jsxs)("div",{className:"text-center p-3 bg-gradient-to-br from-rose-50 to-rose-100 rounded-lg",children:[(0,le.jsx)("div",{className:"text-2xl font-bold text-rose-900",children:e.temporalStats.totalCreators}),(0,le.jsx)("div",{className:"text-xs text-rose-700 font-medium",children:"Total Contributors"})]}),(0,le.jsx)("div",{className:"space-y-3",children:e.creatorStats.slice(0,5).map((e,t)=>{let[s,a]=e;return(0,le.jsxs)("div",{className:"flex items-center justify-between p-3 bg-slate-50 rounded-lg",children:[(0,le.jsxs)("div",{className:"flex items-center gap-3",children:[(0,le.jsx)("div",{className:"w-8 h-8 bg-gradient-to-br from-blue-500 to-purple-600 rounded-full flex items-center justify-center text-white text-sm font-bold",children:t+1}),(0,le.jsx)("span",{className:"text-sm font-medium text-slate-700 truncate max-w-24",children:s})]}),(0,le.jsx)("div",{className:"flex items-center gap-2",children:(0,le.jsxs)("div",{className:"text-right",children:[(0,le.jsx)("div",{className:"text-sm font-bold text-slate-900",children:a}),(0,le.jsx)("div",{className:"text-xs text-slate-500",children:"partners"})]})})]},s)})})]})]}),(0,le.jsxs)("div",{className:"bg-white p-6 rounded-xl border border-slate-200 shadow-sm hover:shadow-md transition-shadow",children:[(0,le.jsxs)("div",{className:"flex items-center gap-3 mb-6",children:[(0,le.jsx)("div",{className:"p-2 bg-cyan-100 rounded-lg",children:(0,le.jsx)(ya.A,{className:"h-5 w-5 text-cyan-600"})}),(0,le.jsxs)("div",{children:[(0,le.jsx)("h3",{className:"font-semibold text-slate-800",children:"Recent Activity"}),(0,le.jsx)("p",{className:"text-xs text-slate-500",children:"Growth and trends"})]})]}),(0,le.jsxs)("div",{className:"space-y-4",children:[(0,le.jsxs)("div",{className:"grid grid-cols-1 gap-3",children:[(0,le.jsxs)("div",{className:"p-4 bg-gradient-to-r from-green-50 to-emerald-50 rounded-lg border border-green-200",children:[(0,le.jsxs)("div",{className:"flex justify-between items-center",children:[(0,le.jsx)("span",{className:"text-sm font-medium text-green-700",children:"This Month"}),(0,le.jsx)("span",{className:"text-xl font-bold text-green-900",children:e.temporalStats.thisMonth})]}),(0,le.jsx)("div",{className:"text-xs text-green-600 mt-1",children:"new partners"})]}),(0,le.jsxs)("div",{className:"p-4 bg-gradient-to-r from-blue-50 to-cyan-50 rounded-lg border border-blue-200",children:[(0,le.jsxs)("div",{className:"flex justify-between items-center",children:[(0,le.jsx)("span",{className:"text-sm font-medium text-blue-700",children:"This Quarter"}),(0,le.jsx)("span",{className:"text-xl font-bold text-blue-900",children:e.temporalStats.thisQuarter})]}),(0,le.jsx)("div",{className:"text-xs text-blue-600 mt-1",children:"total registrations"})]})]}),(0,le.jsxs)("div",{className:"grid grid-cols-1 gap-3",children:[e.pricingStats.averageBudget>0&&(0,le.jsxs)("div",{className:"p-4 bg-gradient-to-br from-purple-50 to-pink-50 rounded-lg border border-purple-200",children:[(0,le.jsx)("div",{className:"text-sm font-medium text-purple-700 mb-2",children:"Average Project Budget"}),(0,le.jsxs)("div",{className:"text-lg font-bold text-purple-900",children:["$",e.pricingStats.averageBudget.toLocaleString()]}),(0,le.jsxs)("div",{className:"text-xs text-purple-600 mt-1",children:["starting budget across ",e.pricingStats.withBudget," partners"]})]}),e.pricingStats.averageHourlyRate>0&&(0,le.jsxs)("div",{className:"p-4 bg-gradient-to-br from-emerald-50 to-teal-50 rounded-lg border border-emerald-200",children:[(0,le.jsx)("div",{className:"text-sm font-medium text-emerald-700 mb-2",children:"Average Hourly Rate"}),(0,le.jsxs)("div",{className:"text-lg font-bold text-emerald-900",children:["$",e.pricingStats.averageHourlyRate.toFixed(0),"/hr"]}),(0,le.jsxs)("div",{className:"text-xs text-emerald-600 mt-1",children:["across ",e.pricingStats.withHourlyRate," partners"]})]})]})]})]}),(0,le.jsxs)("div",{className:"bg-white p-6 rounded-xl border border-slate-200 shadow-sm hover:shadow-md transition-shadow",children:[(0,le.jsxs)("div",{className:"flex items-center gap-3 mb-6",children:[(0,le.jsx)("div",{className:"p-2 bg-indigo-100 rounded-lg",children:(0,le.jsx)(Ir.A,{className:"h-5 w-5 text-indigo-600"})}),(0,le.jsxs)("div",{children:[(0,le.jsx)("h3",{className:"font-semibold text-slate-800",children:"Contact Requests"}),(0,le.jsx)("p",{className:"text-xs text-slate-500",children:"Client engagement metrics"})]})]}),(0,le.jsxs)("div",{className:"space-y-4",children:[(0,le.jsxs)("div",{className:"text-center p-4 bg-slate-50 rounded-lg",children:[(0,le.jsx)("div",{className:"text-3xl font-bold text-slate-900",children:e.contactRequestsStats.total}),(0,le.jsx)("div",{className:"text-sm text-slate-600 font-medium",children:"Total Requests"})]}),(0,le.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,le.jsxs)("div",{className:"text-center p-3 bg-gradient-to-br from-indigo-50 to-indigo-100 rounded-lg",children:[(0,le.jsx)("div",{className:"text-2xl font-bold text-indigo-900",children:e.clientEngagementStats.uniqueClients}),(0,le.jsx)("div",{className:"text-xs text-indigo-700 font-medium",children:"Unique Clients"})]}),(0,le.jsxs)("div",{className:"text-center p-3 bg-gradient-to-br from-purple-50 to-purple-100 rounded-lg",children:[(0,le.jsx)("div",{className:"text-2xl font-bold text-purple-900",children:e.clientEngagementStats.repeatClients}),(0,le.jsx)("div",{className:"text-xs text-purple-700 font-medium",children:"Repeat Clients"})]})]}),(0,le.jsx)("div",{className:"space-y-2",children:(0,le.jsxs)("div",{className:"p-3 bg-green-50 rounded-lg border-l-4 border-green-500",children:[(0,le.jsxs)("div",{className:"flex justify-between items-center",children:[(0,le.jsx)("span",{className:"text-sm font-medium text-green-700",children:"This Month"}),(0,le.jsx)("span",{className:"text-lg font-bold text-green-900",children:e.contactRequestsStats.thisMonth})]}),(0,le.jsx)("div",{className:"text-xs text-green-600 mt-1",children:"new requests"})]})})]})]}),(0,le.jsxs)("div",{className:"bg-white p-6 rounded-xl border border-slate-200 shadow-sm hover:shadow-md transition-shadow",children:[(0,le.jsxs)("div",{className:"flex items-center gap-3 mb-6",children:[(0,le.jsx)("div",{className:"p-2 bg-emerald-100 rounded-lg",children:(0,le.jsx)(or.A,{className:"h-5 w-5 text-emerald-600"})}),(0,le.jsxs)("div",{children:[(0,le.jsx)("h3",{className:"font-semibold text-slate-800",children:"Most Contacted Partners"}),(0,le.jsx)("p",{className:"text-xs text-slate-500",children:"Popular partner rankings"})]})]}),(0,le.jsxs)("div",{className:"space-y-4",children:[(0,le.jsx)("div",{className:"space-y-3",children:e.topPartnersByRequests.slice(0,5).map((e,t)=>{let[s,a]=e;return(0,le.jsxs)("div",{className:"flex items-center justify-between p-3 bg-slate-50 rounded-lg",children:[(0,le.jsxs)("div",{className:"flex items-center gap-3",children:[(0,le.jsx)("div",{className:"w-8 h-8 bg-gradient-to-br from-emerald-500 to-teal-600 rounded-full flex items-center justify-center text-white text-sm font-bold",children:t+1}),(0,le.jsx)("span",{className:"text-sm font-medium text-slate-700 truncate max-w-24",children:s})]}),(0,le.jsx)("div",{className:"flex items-center gap-2",children:(0,le.jsxs)("div",{className:"text-right",children:[(0,le.jsx)("div",{className:"text-sm font-bold text-slate-900",children:a}),(0,le.jsx)("div",{className:"text-xs text-slate-500",children:"requests"})]})})]},s)})}),0===e.topPartnersByRequests.length&&(0,le.jsx)("div",{className:"text-center py-4 text-slate-500",children:(0,le.jsx)("div",{className:"text-sm",children:"No contact requests yet"})})]})]}),(0,le.jsxs)("div",{className:"bg-white p-6 rounded-xl border border-slate-200 shadow-sm hover:shadow-md transition-shadow",children:[(0,le.jsxs)("div",{className:"flex items-center gap-3 mb-6",children:[(0,le.jsx)("div",{className:"p-2 bg-orange-100 rounded-lg",children:(0,le.jsx)(kC.A,{className:"h-5 w-5 text-orange-600"})}),(0,le.jsxs)("div",{children:[(0,le.jsx)("h3",{className:"font-semibold text-slate-800",children:"Project Insights"}),(0,le.jsx)("p",{className:"text-xs text-slate-500",children:"Client preferences analysis"})]})]}),(0,le.jsxs)("div",{className:"space-y-4",children:[(0,le.jsxs)("div",{className:"space-y-3",children:[(0,le.jsx)("div",{className:"text-sm font-medium text-slate-700",children:"Project Types"}),Object.entries(e.projectTypeStats).map((t,s)=>{let[a,n]=t;const l=n/e.contactRequestsStats.total*100,r="new_project"===a?"New Project":"Existing Project";return(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsxs)("div",{className:"flex justify-between items-center",children:[(0,le.jsx)("span",{className:"text-sm font-medium text-slate-700",children:r}),(0,le.jsxs)("span",{className:"text-sm font-bold text-slate-900",children:[n," (",l.toFixed(1),"%)"]})]}),(0,le.jsx)("div",{className:"w-full bg-gray-200 rounded-full h-2",children:(0,le.jsx)("div",{className:"".concat(["bg-blue-500","bg-green-500"][s]," h-2 rounded-full transition-all duration-500"),style:{width:"".concat(l,"%")}})})]},a)})]}),(0,le.jsxs)("div",{className:"space-y-3",children:[(0,le.jsx)("div",{className:"text-sm font-medium text-slate-700",children:"Work Basis Preference"}),Object.entries(e.workBasisStats).map((t,s)=>{let[a,n]=t;const l=n/e.contactRequestsStats.total*100,r="hourly"===a?"Hourly Rate":"fixed_price"===a?"Fixed Price":a;return(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsxs)("div",{className:"flex justify-between items-center",children:[(0,le.jsx)("span",{className:"text-sm font-medium text-slate-700",children:r}),(0,le.jsxs)("span",{className:"text-sm font-bold text-slate-900",children:[n," (",l.toFixed(1),"%)"]})]}),(0,le.jsx)("div",{className:"w-full bg-gray-200 rounded-full h-2",children:(0,le.jsx)("div",{className:"".concat(["bg-purple-500","bg-pink-500"][s]," h-2 rounded-full transition-all duration-500"),style:{width:"".concat(l,"%")}})})]},a)})]})]})]})]})})()]}),(0,le.jsxs)("div",{className:"mb-8 space-y-4",children:[(0,le.jsx)("div",{className:"bg-white p-4 rounded-xl border border-gray-100 shadow-sm",children:(0,le.jsxs)("div",{className:"flex flex-col lg:flex-row gap-3 items-start lg:items-center justify-between",children:[(0,le.jsxs)("div",{className:"flex flex-col sm:flex-row gap-3 items-start sm:items-center flex-1",children:[(0,le.jsxs)("div",{className:"relative w-full sm:w-80",children:[(0,le.jsx)(vn.A,{className:"absolute left-3 top-2.5 h-4 w-4 text-gray-400"}),(0,le.jsx)(fs,{placeholder:"Search partners, services, locations...",className:"pl-10 h-9 border-gray-200 focus:border-blue-500 focus:ring-blue-500/20 transition-all duration-200",value:c,onChange:e=>d(e.target.value)})]}),(0,le.jsxs)(zs,{value:i,onValueChange:o,children:[(0,le.jsx)(qs,{className:"w-36 h-9 border-gray-200 hover:border-gray-300 transition-colors",children:(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[(0,le.jsx)(lv.A,{className:"h-3.5 w-3.5 text-gray-400"}),(0,le.jsx)(Ws,{placeholder:"Status"})]})}),(0,le.jsxs)(Ys,{children:[(0,le.jsx)($s,{value:"all",children:"All Status"}),(0,le.jsx)($s,{value:"pending",children:"Pending"}),(0,le.jsx)($s,{value:"approved",children:"Approved"}),(0,le.jsx)($s,{value:"rejected",children:"Rejected"})]})]}),(0,le.jsxs)(zs,{value:L,onValueChange:O,children:[(0,le.jsx)(qs,{className:"w-36 h-9 border-gray-200 hover:border-gray-300 transition-colors",children:(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[(0,le.jsx)(Xl.A,{className:"h-3.5 w-3.5 text-gray-400"}),(0,le.jsx)(Ws,{placeholder:"Type"})]})}),(0,le.jsxs)(Ys,{children:[(0,le.jsx)($s,{value:"all",children:"All Types"}),(0,le.jsx)($s,{value:"individual",children:"Individual"}),(0,le.jsx)($s,{value:"team",children:"Team"})]})]}),(0,le.jsxs)("div",{className:"relative w-full sm:w-40",children:[(0,le.jsx)(CC.A,{className:"absolute left-3 top-2.5 h-4 w-4 text-gray-400"}),(0,le.jsx)(fs,{placeholder:"Location...",className:"pl-10 h-9 border-gray-200 focus:border-blue-500 focus:ring-blue-500/20 transition-all duration-200",value:R,onChange:e=>M(e.target.value)})]}),J()&&(0,le.jsxs)(Yt,{variant:"outline",size:"sm",onClick:()=>{o("all"),O("all"),M(""),d(""),N(1)},className:"h-9 px-3 text-gray-600 border-gray-200 hover:bg-gray-50 hover:text-gray-900 transition-all duration-200",children:[(0,le.jsx)(Bt.A,{className:"h-3.5 w-3.5 mr-1"}),"Clear"]})]}),(0,le.jsxs)("div",{className:"flex items-center gap-2 text-sm text-gray-500 bg-gray-50 px-3 py-1.5 rounded-lg",children:[(0,le.jsx)(hf.A,{className:"h-3.5 w-3.5"}),w>0?"".concat(w," total partners"):"".concat(a.length," partners")]})]})}),J()&&(0,le.jsxs)("div",{className:"flex flex-wrap gap-2 items-center p-3 bg-gradient-to-r from-blue-50 to-indigo-50 rounded-lg border border-blue-100",children:[(0,le.jsxs)("span",{className:"text-sm font-medium text-gray-700 flex items-center gap-1",children:[(0,le.jsx)(Rb.A,{className:"h-3.5 w-3.5"}),"Active filters:"]}),"all"!==i&&(0,le.jsxs)(es,{className:"bg-blue-100 text-blue-800 hover:bg-blue-200 transition-colors",children:["Status: ",i,(0,le.jsx)("button",{onClick:()=>o("all"),className:"ml-1 hover:bg-blue-300 rounded-full p-0.5 transition-colors",children:(0,le.jsx)(Bt.A,{className:"h-3 w-3"})})]}),"all"!==L&&(0,le.jsxs)(es,{className:"bg-teal-100 text-teal-800 hover:bg-teal-200 transition-colors",children:["Type: ",L,(0,le.jsx)("button",{onClick:()=>O("all"),className:"ml-1 hover:bg-teal-300 rounded-full p-0.5 transition-colors",children:(0,le.jsx)(Bt.A,{className:"h-3 w-3"})})]}),R&&(0,le.jsxs)(es,{className:"bg-purple-100 text-purple-800 hover:bg-purple-200 transition-colors",children:["Location: ",R,(0,le.jsx)("button",{onClick:()=>M(""),className:"ml-1 hover:bg-purple-300 rounded-full p-0.5 transition-colors",children:(0,le.jsx)(Bt.A,{className:"h-3 w-3"})})]}),c&&(0,le.jsxs)(es,{className:"bg-green-100 text-green-800 hover:bg-green-200 transition-colors",children:['Search: "',c,'"',(0,le.jsx)("button",{onClick:()=>d(""),className:"ml-1 hover:bg-green-300 rounded-full p-0.5 transition-colors",children:(0,le.jsx)(Bt.A,{className:"h-3 w-3"})})]})]})]}),(0,le.jsx)("div",{className:"bg-white rounded-xl border border-gray-200 shadow-sm overflow-hidden",children:(0,le.jsxs)(zl,{children:[(0,le.jsx)(Ul,{children:(0,le.jsxs)(Vl,{children:[(0,le.jsx)(Hl,{className:"w-8"}),(0,le.jsx)(Hl,{className:"cursor-pointer",onClick:()=>$("name"),children:(0,le.jsxs)("div",{className:"flex items-center",children:["Partner",(0,le.jsx)(ny.A,{className:"ml-2 h-4 w-4"})]})}),(0,le.jsx)(Hl,{className:"cursor-pointer",onClick:()=>$("city"),children:(0,le.jsxs)("div",{className:"flex items-center",children:["Location",(0,le.jsx)(ny.A,{className:"ml-2 h-4 w-4"})]})}),(0,le.jsx)(Hl,{className:"cursor-pointer",onClick:()=>$("individual_or_team"),children:(0,le.jsxs)("div",{className:"flex items-center",children:["Type",(0,le.jsx)(ny.A,{className:"ml-2 h-4 w-4"})]})}),(0,le.jsx)(Hl,{children:"Services"}),(0,le.jsx)(Hl,{children:"Languages"}),(0,le.jsx)(Hl,{className:"cursor-pointer",onClick:()=>$("status"),children:(0,le.jsxs)("div",{className:"flex items-center",children:["Status",(0,le.jsx)(ny.A,{className:"ml-2 h-4 w-4"})]})}),(0,le.jsx)(Hl,{className:"cursor-pointer w-40",onClick:()=>$("created_date"),children:(0,le.jsxs)("div",{className:"flex items-center",children:["Created Date",(0,le.jsx)(ny.A,{className:"ml-2 h-4 w-4"})]})}),(0,le.jsx)(Hl,{children:"Actions"})]})}),(0,le.jsx)(Wl,{children:l?(0,le.jsx)(Vl,{children:(0,le.jsx)(Yl,{colSpan:9,className:"text-center py-8",children:"Loading partners..."})}):0===a.length?(0,le.jsx)(Vl,{children:(0,le.jsx)(Yl,{colSpan:9,className:"text-center py-8",children:"No partners found"})}):a.map(e=>(0,le.jsxs)(le.Fragment,{children:[(0,le.jsxs)(Vl,{className:"hover:bg-gray-50/80 transition-colors duration-200 group h-12",children:[(0,le.jsx)(Yl,{className:"py-2",children:(0,le.jsx)(Yt,{variant:"ghost",size:"sm",onClick:()=>{return t=e.item.id,void P(e=>{const s=new Set(e);return s.has(t)?s.delete(t):s.add(t),s});var t},className:"h-6 w-6 p-0 rounded hover:bg-gray-100 transition-all duration-200 group",children:T.has(e.item.id)?(0,le.jsx)(Is.A,{className:"h-3 w-3 text-gray-600 group-hover:text-gray-900 transition-colors"}):(0,le.jsx)(rn.A,{className:"h-3 w-3 text-gray-600 group-hover:text-gray-900 transition-colors"})})}),(0,le.jsx)(Yl,{className:"font-medium py-2 text-sm",children:(0,le.jsxs)("div",{className:"flex items-center gap-3",children:[e.item.logo_url&&""!==e.item.logo_url.trim()?(0,le.jsx)("img",{src:e.item.logo_url,alt:"".concat(e.item.name," logo"),className:"h-8 w-8 rounded-full object-cover border border-gray-200",onError:e=>{e.target.style.display="none"}}):(0,le.jsx)(Ny.A,{className:"h-8 w-8 text-gray-400 p-1 border border-gray-200 rounded-full bg-gray-50"}),(0,le.jsxs)("div",{children:[(0,le.jsx)("div",{className:"font-medium text-gray-900",children:e.item.name}),(0,le.jsxs)("div",{className:"flex items-center gap-2 mt-0.5",children:[e.item.website_url&&(0,le.jsxs)("a",{href:e.item.website_url,target:"_blank",rel:"noopener noreferrer",className:"text-xs text-gray-500 hover:text-gray-700 flex items-center gap-1",children:[(0,le.jsx)(bn.A,{className:"h-3 w-3"}),"Website"]}),e.item.linkedin_url&&(0,le.jsxs)("a",{href:e.item.linkedin_url,target:"_blank",rel:"noopener noreferrer",className:"text-xs text-gray-500 hover:text-gray-700 flex items-center gap-1",children:[(0,le.jsx)(qa.A,{className:"h-3 w-3"}),"LinkedIn"]})]})]})]})}),(0,le.jsx)(Yl,{className:"py-2",children:(0,le.jsxs)("div",{className:"flex items-center gap-1 text-sm text-gray-600",children:[(0,le.jsx)(CC.A,{className:"h-3.5 w-3.5"}),e.item.city,", ",$k(e.item.country)]})}),(0,le.jsx)(Yl,{className:"py-2",children:(0,le.jsx)("div",{className:"flex items-center gap-1 text-sm",children:"individual"===e.item.individual_or_team?(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(nv.A,{className:"h-3.5 w-3.5 text-gray-400"}),(0,le.jsx)("span",{className:"text-gray-600",children:"Individual"})]}):(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(Xl.A,{className:"h-3.5 w-3.5 text-gray-400"}),(0,le.jsx)("span",{className:"text-gray-600",children:"Team"})]})})}),(0,le.jsx)(Yl,{className:"py-2",children:(0,le.jsx)("div",{className:"text-sm text-gray-600",children:e.item.services&&e.item.services.length>0?(0,le.jsxs)("div",{className:"flex flex-wrap gap-1",children:[e.item.services.slice(0,2).map((t,s)=>(0,le.jsx)("span",{className:"inline-block px-2 py-1 text-xs bg-gray-100 text-gray-700 rounded-md",children:"Other"===t&&e.item.other_service_description?"Other: ".concat(e.item.other_service_description.substring(0,20),"..."):t},s)),e.item.services.length>2&&(0,le.jsxs)("span",{className:"text-xs text-gray-500",children:["+",e.item.services.length-2]})]}):(0,le.jsx)("span",{className:"text-gray-400 text-xs",children:"No services"})})}),(0,le.jsx)(Yl,{className:"py-2",children:(0,le.jsx)("div",{className:"text-sm text-gray-600",children:e.item.languages&&e.item.languages.length>0?(0,le.jsxs)("div",{className:"flex flex-wrap gap-1",children:[SC(e.item.languages.slice(0,2)).map((e,t)=>(0,le.jsx)("span",{className:"inline-block px-2 py-1 text-xs bg-blue-100 text-blue-700 rounded-md",children:e},t)),e.item.languages.length>2&&(0,le.jsxs)("span",{className:"text-xs text-gray-500",children:["+",e.item.languages.length-2]})]}):(0,le.jsx)("span",{className:"text-gray-400 text-xs",children:"No languages"})})}),(0,le.jsxs)(Yl,{className:"py-2",children:[Z(e.item.status),"rejected"===e.item.status&&e.item.rejected_reason&&(0,le.jsx)("div",{className:"mt-1 text-xs text-red-600 max-w-xs truncate",children:e.item.rejected_reason})]}),(0,le.jsx)(Yl,{className:"py-2 w-40",children:ra().utc(e.item.created_date).fromNow()}),(0,le.jsx)(Yl,{className:"py-2",children:(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[(0,le.jsxs)(Yt,{size:"sm",variant:"ghost",onClick:t=>{t.stopPropagation(),(e=>{var t,s;const a={name:e.item.name||"",description:e.item.description||"",logo_url:e.item.logo_url||"",website_url:e.item.website_url||"",linkedin_url:e.item.linkedin_url||"",country:e.item.country||"",city:e.item.city||"",individual_or_team:e.item.individual_or_team||"individual",services:e.item.services||[],languages:e.item.languages||[],budget_starting_from_dollars:(null===(t=e.item.budget_starting_from_dollars)||void 0===t?void 0:t.toString())||"",hourly_rate:(null===(s=e.item.hourly_rate)||void 0===s?void 0:s.toString())||"",other_service_description:e.item.other_service_description||"",apps:e.item.apps||[],has_apps_to_share:!0===e.item.has_apps_to_share,no_apps_explanation:e.item.no_apps_explanation||"",terms_accepted:e.item.terms_accepted||!1};v((0,K.A)((0,K.A)({},e),{},{editData:a})),j(!0)})(e)},disabled:E[e.item.id],className:"text-blue-600 hover:text-blue-700 hover:bg-blue-50 h-8 px-3 transition-all duration-200",children:[(0,le.jsx)(Mv.A,{className:"h-3.5 w-3.5 mr-1"}),"Edit"]}),"pending"===e.item.status&&(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(Yt,{size:"sm",variant:"ghost",onClick:t=>{t.stopPropagation(),H(e)},disabled:E[e.item.id],className:"text-green-600 hover:text-green-700 hover:bg-green-50 h-8 px-3 transition-all duration-200",children:"Approve"}),(0,le.jsx)(Yt,{size:"sm",variant:"ghost",onClick:t=>{t.stopPropagation(),G(e)},disabled:E[e.item.id],className:"text-red-600 hover:text-red-700 hover:bg-red-50 h-8 px-3 transition-all duration-200",children:"Reject"})]}),"rejected"===e.item.status&&(0,le.jsx)(Yt,{size:"sm",variant:"ghost",onClick:t=>{t.stopPropagation(),H(e)},disabled:E[e.item.id],className:"text-green-600 hover:text-green-700 hover:bg-green-50 h-8 px-3 transition-all duration-200",children:"Approve"}),"approved"===e.item.status&&(0,le.jsx)(Yt,{size:"sm",variant:"ghost",onClick:t=>{t.stopPropagation(),G(e)},disabled:E[e.item.id],className:"text-amber-600 hover:text-amber-700 hover:bg-amber-50 h-8 px-3 transition-all duration-200",children:"Revoke"}),(0,le.jsx)(Yt,{size:"sm",variant:"ghost",onClick:t=>{t.stopPropagation(),(async e=>{const t=e.item.id;I(e=>(0,K.A)((0,K.A)({},e),{},{[t]:!0}));try{await bC.archiveItem(t),an({title:"Success",description:"".concat(e.item.name," has been archived")}),await V()}catch(s){an({title:"Error",description:"Failed to archive partner",variant:"destructive"})}finally{I(e=>(0,K.A)((0,K.A)({},e),{},{[t]:!1}))}})(e)},disabled:E[e.item.id],className:"text-gray-500 hover:text-gray-700 hover:bg-gray-100 h-8 px-3 transition-all duration-200",children:"Archive"})]})})]},e.item.id),T.has(e.item.id)&&(0,le.jsx)(Vl,{children:(0,le.jsx)(Yl,{colSpan:9,className:"bg-gradient-to-br from-gray-50 to-gray-100/50 p-8 border-t border-gray-100",children:(0,le.jsxs)("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-8",children:[(0,le.jsxs)("div",{className:"space-y-6",children:[(0,le.jsxs)("div",{className:"bg-white p-4 rounded-lg border border-gray-200",children:[(0,le.jsxs)("h4",{className:"font-semibold text-gray-900 mb-3 flex items-center gap-2",children:[(0,le.jsx)("div",{className:"w-1 h-5 bg-blue-500 rounded-full"}),"Description"]}),(0,le.jsx)("div",{className:"text-sm text-gray-600",children:e.item.description||(0,le.jsx)("span",{className:"text-gray-400 italic",children:"No description available"})})]}),(0,le.jsxs)("div",{className:"bg-white p-4 rounded-lg border border-gray-200",children:[(0,le.jsxs)("h4",{className:"font-semibold text-gray-900 mb-3 flex items-center gap-2",children:[(0,le.jsx)("div",{className:"w-1 h-5 bg-green-500 rounded-full"}),"Services & Pricing"]}),(0,le.jsxs)("div",{className:"space-y-3",children:[e.item.services&&e.item.services.length>0&&(0,le.jsxs)("div",{children:[(0,le.jsx)("span",{className:"font-medium text-gray-700 text-sm",children:"Services:"}),(0,le.jsx)("div",{className:"flex flex-wrap gap-2 mt-2",children:e.item.services.map((t,s)=>(0,le.jsx)(es,{className:"bg-blue-50 text-blue-700 border-blue-200",children:"Other"===t&&e.item.other_service_description?"Other: ".concat(e.item.other_service_description):t},s))})]}),(e.item.budget_starting_from_dollars||e.item.hourly_rate)&&(0,le.jsxs)("div",{children:[(0,le.jsx)("span",{className:"font-medium text-gray-700 text-sm",children:"Pricing:"}),(0,le.jsxs)("div",{className:"mt-2 space-y-1",children:[e.item.budget_starting_from_dollars&&(0,le.jsxs)("div",{className:"flex items-center gap-1 text-sm text-gray-600",children:[(0,le.jsx)(AC.A,{className:"h-3.5 w-3.5"}),"Starting from $",e.item.budget_starting_from_dollars.toLocaleString()]}),e.item.hourly_rate&&(0,le.jsxs)("div",{className:"flex items-center gap-1 text-sm text-gray-600",children:[(0,le.jsx)(Li.A,{className:"h-3.5 w-3.5"}),"$",e.item.hourly_rate,"/hour"]})]})]})]})]}),e.item.languages&&e.item.languages.length>0&&(0,le.jsxs)("div",{className:"bg-white p-4 rounded-lg border border-gray-200",children:[(0,le.jsxs)("h4",{className:"font-semibold text-gray-900 mb-3 flex items-center gap-2",children:[(0,le.jsx)("div",{className:"w-1 h-5 bg-purple-500 rounded-full"}),"Languages"]}),(0,le.jsx)("div",{className:"flex flex-wrap gap-2",children:SC(e.item.languages).map((e,t)=>(0,le.jsx)(es,{className:"bg-purple-50 text-purple-700 border-purple-200",children:e},t))})]})]}),(0,le.jsxs)("div",{className:"space-y-6",children:[(0,le.jsxs)("div",{className:"bg-white p-4 rounded-lg border border-gray-200",children:[(0,le.jsxs)("h4",{className:"font-semibold text-gray-900 mb-3 flex items-center gap-2",children:[(0,le.jsx)("div",{className:"w-1 h-5 bg-orange-500 rounded-full"}),e.item.has_apps_to_share?"Portfolio Apps":"Experience"]}),e.item.has_apps_to_share?(0,le.jsx)("div",{children:e.item.apps&&e.item.apps.length>0?(0,le.jsx)("div",{className:"space-y-3",children:e.item.apps.map((e,t)=>(0,le.jsxs)("div",{className:"flex items-center justify-between p-3 bg-gray-50 rounded-lg",children:[(0,le.jsx)("div",{children:(0,le.jsxs)("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",className:"text-sm font-medium text-blue-600 hover:text-blue-800 flex items-center gap-1",children:[(0,le.jsx)(Tr.A,{className:"h-3.5 w-3.5"}),e.url.replace(/^https?:\/\//,"").split("/")[0]]})}),e.allow_public_showcase&&(0,le.jsx)(es,{className:"bg-green-100 text-green-700 text-xs",children:"Public Showcase"})]},t))}):(0,le.jsx)("p",{className:"text-sm text-gray-600",children:"No apps shared"})}):(0,le.jsx)("div",{className:"text-sm text-gray-600",children:e.item.no_apps_explanation||(0,le.jsx)("span",{className:"text-gray-400 italic",children:"No experience description provided"})})]}),(0,le.jsxs)("div",{className:"bg-white p-4 rounded-lg border border-gray-200",children:[(0,le.jsxs)("h4",{className:"font-semibold text-gray-900 mb-3 flex items-center gap-2",children:[(0,le.jsx)("div",{className:"w-1 h-5 bg-teal-500 rounded-full"}),"Terms & Conditions"]}),(0,le.jsx)("div",{className:"text-sm",children:e.item.terms_accepted?(0,le.jsxs)("div",{className:"flex items-center gap-2 text-green-700",children:[(0,le.jsx)(lv.A,{className:"h-4 w-4"}),(0,le.jsx)("span",{className:"font-medium",children:"Terms Accepted"}),e.item.terms_accepted_at&&(0,le.jsxs)("span",{className:"text-gray-500",children:["on ",new Date(e.item.terms_accepted_at).toLocaleDateString()]})]}):(0,le.jsxs)("div",{className:"flex items-center gap-2 text-red-600",children:[(0,le.jsx)(_e.A,{className:"h-4 w-4"}),(0,le.jsx)("span",{className:"font-medium",children:"Terms Not Accepted"})]})})]}),"rejected"===e.item.status&&e.item.rejected_reason&&(0,le.jsxs)("div",{className:"bg-red-50 p-4 rounded-lg border border-red-200",children:[(0,le.jsxs)("h4",{className:"font-semibold text-red-900 mb-3 flex items-center gap-2",children:[(0,le.jsx)("div",{className:"w-1 h-5 bg-red-500 rounded-full"}),"Rejection Reason"]}),(0,le.jsx)("div",{className:"text-sm text-red-800 bg-white p-3 rounded border border-red-200",children:e.item.rejected_reason})]})]})]})})})]}))})]})}),a.length>0&&(0,le.jsxs)("div",{className:"flex items-center justify-between py-4",children:[(0,le.jsx)("div",{className:"flex items-center gap-2 text-sm text-gray-500",children:(0,le.jsxs)("span",{children:["Showing ",(y-1)*D+1," to ",Math.min(y*D,w)," of ",w," items"]})}),(0,le.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,le.jsx)(Yt,{variant:"outline",size:"sm",onClick:()=>N(e=>Math.max(e-1,1)),disabled:1===y||l,className:"h-8 px-3",children:"Previous"}),(0,le.jsxs)("div",{className:"flex items-center gap-1",children:[y>2&&(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(Yt,{variant:"outline",size:"sm",onClick:()=>N(1),className:"h-8 w-8 p-0",children:"1"}),y>3&&(0,le.jsx)("span",{className:"px-1 text-gray-400",children:"..."})]}),y>1&&(0,le.jsx)(Yt,{variant:"outline",size:"sm",onClick:()=>N(e=>e-1),className:"h-8 w-8 p-0",children:y-1}),(0,le.jsx)(Yt,{variant:"default",size:"sm",className:"h-8 w-8 p-0",children:y}),a.length===D&&(0,le.jsx)(Yt,{variant:"outline",size:"sm",onClick:()=>N(e=>e+1),disabled:l,className:"h-8 w-8 p-0",children:y+1})]}),(0,le.jsx)(Yt,{variant:"outline",size:"sm",onClick:()=>N(e=>e+1),disabled:a.lengthg(e.target.value),className:"mt-2 min-h-[100px]"})]}),(0,le.jsx)("div",{className:"p-3 bg-amber-50 border border-amber-200 rounded-lg",children:(0,le.jsxs)("div",{className:"flex gap-2",children:[(0,le.jsx)(_e.A,{className:"h-4 w-4 text-amber-600 mt-0.5 flex-shrink-0"}),(0,le.jsx)("p",{className:"text-sm text-amber-800",children:"This action will mark the partner as rejected and they will need to reapply."})]})})]}),(0,le.jsxs)(Ba,{children:[(0,le.jsx)(Yt,{variant:"outline",onClick:()=>h(!1),children:"Cancel"}),(0,le.jsx)(Yt,{variant:"destructive",onClick:async()=>{if(!m)return;const e=m.item.id;I(t=>(0,K.A)((0,K.A)({},t),{},{[e]:!0})),h(!1);try{await bC.declineItem(e,p),an({title:"Partner Rejected",description:"".concat(m.item.name," has been rejected")}),await V()}catch(t){an({title:"Error",description:"Failed to reject partner",variant:"destructive"})}finally{I(t=>(0,K.A)((0,K.A)({},t),{},{[e]:!1}))}},disabled:E[null==m?void 0:m.item.id],children:"Reject Partner"})]})]})}),f&&(0,le.jsx)(NC,{isOpen:b,onClose:()=>{j(!1),v(null)},mode:"edit",initialData:f.editData,partnerId:f.item.id,onSuccess:()=>{V()}})]})}function IC(){const[e,t]=(0,Y.useState)([]),[s,a]=(0,Y.useState)(!0),[n,l]=(0,Y.useState)(""),[r,i]=(0,Y.useState)(null),[o,c]=(0,Y.useState)(!1),[d,m]=(0,Y.useState)(0),[u,x]=(0,Y.useState)(1),[h,p]=(0,Y.useState)({key:"created_date",direction:"desc"}),[g,f]=(0,Y.useState)(null),[v,b]=(0,Y.useState)("all"),[j,y]=(0,Y.useState)("all"),N=25;(0,Y.useEffect)(()=>{if(g&&clearTimeout(g),1===u)return f(setTimeout(()=>{w()},500)),()=>{g&&clearTimeout(g)};x(1)},[n,v,j,h]),(0,Y.useEffect)(()=>{w()},[u]);const w=async()=>{try{var e;a(!0);let s={skip:(u-1)*N,limit:N,sort_by:"desc"===h.direction?"-".concat(h.key):h.key};n&&(s.search=n),"all"!==v&&(s.project_type=v),"all"!==j&&(s.work_basis=j);const l=await bC.getAllContactRequests(s);t(l.items||[]),m(l.total||(null===(e=l.items)||void 0===e?void 0:e.length)||0)}catch(s){an({title:"Error",description:"Failed to load contact requests",variant:"destructive"})}finally{a(!1)}},_=e=>{const t=h.key===e&&"asc"===h.direction?"desc":"asc";p({key:e,direction:t}),x(1)},k=()=>"all"!==v||"all"!==j||""!==n,C=e=>{switch(e){case"as_soon_as_possible":return"ASAP";case"within_a_week":return"Within a week";case"within_a_month":return"Within a month";case"more_than_a_month":return"1+ months";default:return e}},A=e=>"hourly"===e?"Hourly Rate":"Fixed Price",S=e=>"new_project"===e?"New Project":"Existing Project";return(0,le.jsxs)(le.Fragment,{children:[(0,le.jsxs)("div",{className:"mb-8 space-y-4",children:[(0,le.jsx)("div",{className:"bg-white p-4 rounded-xl border border-gray-100 shadow-sm",children:(0,le.jsxs)("div",{className:"flex flex-col lg:flex-row gap-3 items-start lg:items-center justify-between",children:[(0,le.jsxs)("div",{className:"flex flex-col sm:flex-row gap-3 items-start sm:items-center flex-1",children:[(0,le.jsxs)("div",{className:"relative w-full sm:w-80",children:[(0,le.jsx)(vn.A,{className:"absolute left-3 top-2.5 h-4 w-4 text-gray-400"}),(0,le.jsx)(fs,{placeholder:"Search clients, partners, projects...",className:"pl-10 h-9 border-gray-200 focus:border-blue-500 focus:ring-blue-500/20 transition-all duration-200",value:n,onChange:e=>l(e.target.value)})]}),(0,le.jsxs)(zs,{value:v,onValueChange:b,children:[(0,le.jsx)(qs,{className:"w-36 h-9 border-gray-200 hover:border-gray-300 transition-colors",children:(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[(0,le.jsx)(kC.A,{className:"h-3.5 w-3.5 text-gray-400"}),(0,le.jsx)(Ws,{placeholder:"Project"})]})}),(0,le.jsxs)(Ys,{children:[(0,le.jsx)($s,{value:"all",children:"All Projects"}),(0,le.jsx)($s,{value:"new_project",children:"New Project"}),(0,le.jsx)($s,{value:"existing_project",children:"Existing Project"})]})]}),(0,le.jsxs)(zs,{value:j,onValueChange:y,children:[(0,le.jsx)(qs,{className:"w-36 h-9 border-gray-200 hover:border-gray-300 transition-colors",children:(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[(0,le.jsx)(AC.A,{className:"h-3.5 w-3.5 text-gray-400"}),(0,le.jsx)(Ws,{placeholder:"Pricing"})]})}),(0,le.jsxs)(Ys,{children:[(0,le.jsx)($s,{value:"all",children:"All Pricing"}),(0,le.jsx)($s,{value:"hourly",children:"Hourly Rate"}),(0,le.jsx)($s,{value:"fixed",children:"Fixed Price"})]})]}),k()&&(0,le.jsxs)(Yt,{variant:"outline",size:"sm",onClick:()=>{b("all"),y("all"),l(""),x(1)},className:"h-9 px-3 text-gray-600 border-gray-200 hover:bg-gray-50 hover:text-gray-900 transition-all duration-200",children:[(0,le.jsx)(Bt.A,{className:"h-3.5 w-3.5 mr-1"}),"Clear"]})]}),(0,le.jsxs)("div",{className:"flex items-center gap-2 text-sm text-gray-500 bg-gray-50 px-3 py-1.5 rounded-lg",children:[(0,le.jsx)(hf.A,{className:"h-3.5 w-3.5"}),d>0?"".concat(d," total requests"):"".concat(e.length," requests")]})]})}),k()&&(0,le.jsxs)("div",{className:"flex flex-wrap gap-2 items-center p-3 bg-gradient-to-r from-blue-50 to-indigo-50 rounded-lg border border-blue-100",children:[(0,le.jsxs)("span",{className:"text-sm font-medium text-gray-700 flex items-center gap-1",children:[(0,le.jsx)(Rb.A,{className:"h-3.5 w-3.5"}),"Active filters:"]}),"all"!==v&&(0,le.jsxs)(es,{className:"bg-blue-100 text-blue-800 hover:bg-blue-200 transition-colors",children:["Type: ","new_project"===v?"New Project":"Existing Project",(0,le.jsx)("button",{onClick:()=>b("all"),className:"ml-1 hover:bg-blue-300 rounded-full p-0.5 transition-colors",children:(0,le.jsx)(Bt.A,{className:"h-3 w-3"})})]}),"all"!==j&&(0,le.jsxs)(es,{className:"bg-teal-100 text-teal-800 hover:bg-teal-200 transition-colors",children:["Pricing: ","hourly"===j?"Hourly Rate":"Fixed Price",(0,le.jsx)("button",{onClick:()=>y("all"),className:"ml-1 hover:bg-teal-300 rounded-full p-0.5 transition-colors",children:(0,le.jsx)(Bt.A,{className:"h-3 w-3"})})]}),n&&(0,le.jsxs)(es,{className:"bg-green-100 text-green-800 hover:bg-green-200 transition-colors",children:['Search: "',n,'"',(0,le.jsx)("button",{onClick:()=>l(""),className:"ml-1 hover:bg-green-300 rounded-full p-0.5 transition-colors",children:(0,le.jsx)(Bt.A,{className:"h-3 w-3"})})]})]})]}),(0,le.jsx)("div",{className:"bg-white rounded-xl border border-gray-200 shadow-sm overflow-hidden",children:(0,le.jsxs)(zl,{children:[(0,le.jsx)(Ul,{children:(0,le.jsxs)(Vl,{children:[(0,le.jsx)(Hl,{className:"cursor-pointer",onClick:()=>_("client_name"),children:(0,le.jsxs)("div",{className:"flex items-center",children:["Client",(0,le.jsx)(ny.A,{className:"ml-2 h-4 w-4"})]})}),(0,le.jsx)(Hl,{className:"cursor-pointer",onClick:()=>_("partner_name"),children:(0,le.jsxs)("div",{className:"flex items-center",children:["Partner",(0,le.jsx)(ny.A,{className:"ml-2 h-4 w-4"})]})}),(0,le.jsx)(Hl,{children:"Project Description"}),(0,le.jsx)(Hl,{className:"cursor-pointer",onClick:()=>_("project_type"),children:(0,le.jsxs)("div",{className:"flex items-center",children:["Type",(0,le.jsx)(ny.A,{className:"ml-2 h-4 w-4"})]})}),(0,le.jsx)(Hl,{className:"cursor-pointer",onClick:()=>_("work_basis"),children:(0,le.jsxs)("div",{className:"flex items-center",children:["Pricing",(0,le.jsx)(ny.A,{className:"ml-2 h-4 w-4"})]})}),(0,le.jsx)(Hl,{className:"cursor-pointer",onClick:()=>_("start_date"),children:(0,le.jsxs)("div",{className:"flex items-center",children:["Start Date",(0,le.jsx)(ny.A,{className:"ml-2 h-4 w-4"})]})}),(0,le.jsx)(Hl,{className:"cursor-pointer w-40",onClick:()=>_("created_date"),children:(0,le.jsxs)("div",{className:"flex items-center",children:["Created",(0,le.jsx)(ny.A,{className:"ml-2 h-4 w-4"})]})}),(0,le.jsx)(Hl,{children:"Actions"})]})}),(0,le.jsx)(Wl,{children:s?(0,le.jsx)(Vl,{children:(0,le.jsx)(Yl,{colSpan:8,className:"text-center py-8",children:"Loading contact requests..."})}):0===e.length?(0,le.jsx)(Vl,{children:(0,le.jsx)(Yl,{colSpan:8,className:"text-center py-8",children:"No contact requests found"})}):e.map(e=>{var t;return(0,le.jsxs)(Vl,{className:"hover:bg-gray-50/80 transition-colors duration-200",children:[(0,le.jsx)(Yl,{className:"font-medium py-2 text-sm",children:(0,le.jsxs)("div",{children:[(0,le.jsx)("div",{className:"font-medium text-gray-900",children:e.client_name}),(0,le.jsxs)("div",{className:"flex items-center gap-1 mt-0.5 text-xs text-gray-500",children:[(0,le.jsx)(Uh.A,{className:"h-3 w-3"}),e.client_email]}),(0,le.jsxs)("div",{className:"flex items-center gap-1 mt-0.5 text-xs text-gray-500",children:[(0,le.jsx)(nv.A,{className:"h-3 w-3"}),"Account: ",e.requester_email]})]})}),(0,le.jsx)(Yl,{className:"py-2 text-sm",children:(0,le.jsxs)("div",{className:"flex items-center gap-1 text-gray-700",children:[(0,le.jsx)(Ny.A,{className:"h-3.5 w-3.5 text-gray-400"}),e.partner_name]})}),(0,le.jsx)(Yl,{className:"py-2 text-sm max-w-xs",children:(0,le.jsx)("div",{className:"truncate text-gray-600",title:e.project_description,children:(null===(t=e.project_description)||void 0===t?void 0:t.length)>100?"".concat(e.project_description.substring(0,100),"..."):e.project_description})}),(0,le.jsx)(Yl,{className:"py-2",children:(0,le.jsx)(es,{variant:"outline",className:"text-xs",children:S(e.project_type)})}),(0,le.jsx)(Yl,{className:"py-2",children:(0,le.jsx)(es,{variant:"outline",className:"text-xs",children:A(e.work_basis)})}),(0,le.jsx)(Yl,{className:"py-2 text-sm text-gray-600",children:(0,le.jsxs)("div",{className:"flex items-center gap-1",children:[(0,le.jsx)(bh.A,{className:"h-3 w-3"}),C(e.start_date)]})}),(0,le.jsx)(Yl,{className:"py-2 w-40 text-sm text-gray-500",children:ra().utc(e.created_date).fromNow()}),(0,le.jsx)(Yl,{className:"py-2",children:(0,le.jsxs)(Yt,{size:"sm",variant:"outline",onClick:()=>(e=>{i(e),c(!0)})(e),className:"h-7 text-xs",children:["View Details",(0,le.jsx)(rn.A,{className:"h-3 w-3 ml-1"})]})})]},e.id)})})]})}),e.length>0&&(0,le.jsxs)("div",{className:"flex items-center justify-between py-4",children:[(0,le.jsx)("div",{className:"flex items-center gap-2 text-sm text-gray-500",children:(0,le.jsxs)("span",{children:["Showing ",(u-1)*N+1," to ",Math.min(u*N,d)," of ",d," items"]})}),(0,le.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,le.jsx)(Yt,{variant:"outline",size:"sm",onClick:()=>x(e=>Math.max(e-1,1)),disabled:1===u||s,className:"h-8 px-3",children:"Previous"}),(0,le.jsxs)("div",{className:"flex items-center gap-1",children:[u>2&&(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(Yt,{variant:"outline",size:"sm",onClick:()=>x(1),className:"h-8 w-8 p-0",children:"1"}),u>3&&(0,le.jsx)("span",{className:"px-1 text-gray-400",children:"..."})]}),u>1&&(0,le.jsx)(Yt,{variant:"outline",size:"sm",onClick:()=>x(e=>e-1),className:"h-8 w-8 p-0",children:u-1}),(0,le.jsx)(Yt,{variant:"default",size:"sm",className:"h-8 w-8 p-0",children:u}),e.length===N&&(0,le.jsx)(Yt,{variant:"outline",size:"sm",onClick:()=>x(e=>e+1),disabled:s,className:"h-8 w-8 p-0",children:u+1})]}),(0,le.jsx)(Yt,{variant:"outline",size:"sm",onClick:()=>x(e=>e+1),disabled:e.length{const e={user_id:(null==a?void 0:a.id)||null,app_id:null,conversation_id:null},t={cta:"Apply here",origin:"partner_catalog_hero",target_route:null,section:"catalog_header"};tt("User clicked apply as partner",(0,K.A)((0,K.A)({},e),t)),ht(e,t),s()},className:"text-base font-medium text-orange-500 leading-loose hover:text-orange-600 transition-colors whitespace-nowrap",children:"Apply here"})]})]})})]})}function LC(e){let{title:t,onApply:s,onClearAll:a,onClearAndApply:n,children:l,width:r="w-80"}=e;return(0,le.jsxs)("div",{className:"".concat(r," flex flex-col gap-2"),children:[(0,le.jsx)("div",{className:"p-4",children:(0,le.jsx)(go,{className:"text-xs font-medium text-slate-500 tracking-wide block",children:t})}),(0,le.jsx)("div",{className:"px-4",children:l}),(0,le.jsx)("div",{className:"border-t border-slate-200 px-4 py-4",children:(0,le.jsxs)("div",{className:"flex justify-between items-center",children:[(0,le.jsx)(Hn,{variant:"ghost",size:"sm",onClick:n,className:"text-slate-500 hover:text-slate-700 hover:bg-transparent px-0",children:"Clear All"}),(0,le.jsx)(Hn,{onClick:s,className:"px-6",size:"sm",children:"Apply"})]})})]})}const OC=["Application Development","Mobile Development","UI/UX Design","AI Specialist","Security Specialist","API & Integrations","Strategic consulting","QA & Testing","Other"];function RC(e){let{onApply:t,initialServices:s=[],onClose:a}=e;const[n,l]=(0,Y.useState)(s);(0,Y.useEffect)(()=>{l(s)},[s]);return(0,le.jsx)(LC,{title:"Services",onApply:()=>{t(n)},onClearAll:()=>{l([])},onClearAndApply:()=>{l([]),t([]),null==a||a()},children:(0,le.jsx)("div",{className:"space-y-3 max-h-64 overflow-y-auto",children:OC.map(e=>(0,le.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,le.jsx)(Xp,{id:e,checked:n.includes(e),onCheckedChange:()=>(e=>{n.includes(e)?l(n.filter(t=>t!==e)):l([...n,e])})(e)}),(0,le.jsx)("label",{htmlFor:e,className:"text-sm text-slate-700 cursor-pointer select-none flex-1",children:e})]},e))})})}function MC(e){let{onApply:t,initialLanguages:s=[],onClose:a}=e;const[n,l]=(0,Y.useState)(s);(0,Y.useEffect)(()=>{l(s)},[s]);return(0,le.jsx)(LC,{title:"Language",onApply:()=>{t(n)},onClearAll:()=>{l([])},onClearAndApply:()=>{l([]),t([]),null==a||a()},children:(0,le.jsx)("div",{className:"grid grid-cols-2 gap-x-4 gap-y-3 max-h-64 overflow-y-auto",children:Yk.map(e=>(0,le.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,le.jsx)(Xp,{id:e.value,checked:n.includes(e.value),onCheckedChange:()=>{return t=e.value,void(n.includes(t)?l(n.filter(e=>e!==t)):l([...n,t]));var t}}),(0,le.jsx)("label",{htmlFor:e.value,className:"text-sm text-slate-700 cursor-pointer select-none flex-1",children:e.label})]},e.value))})})}function DC(e){let{selectedServices:t,onServicesChange:s,budgetRange:a,onBudgetRangeChange:n,selectedLanguages:l,onLanguagesChange:r,onBudgetApply:i,onServicesApply:o,onLanguagesApply:c}=e;const[d,m]=(0,Y.useState)(!1),[u,x]=(0,Y.useState)(!1);return(0,le.jsx)("div",{className:"w-full bg-white border-t border-b border-slate-200 font-base44",children:(0,le.jsx)("div",{className:"max-w-7xl mx-auto px-6 lg:px-8 py-6 flex justify-between items-center",children:(0,le.jsx)("div",{className:"flex justify-end items-center gap-6",children:(0,le.jsxs)("div",{className:"flex justify-start items-center gap-10",children:[(0,le.jsxs)($g,{open:d,onOpenChange:m,children:[(0,le.jsx)(Jg,{asChild:!0,children:(0,le.jsxs)(Hn,{variant:"ghost",className:"flex justify-end items-center gap-1 p-0 h-auto hover:bg-transparent",children:[(0,le.jsx)("span",{className:"text-black text-sm font-normal",children:"Service"}),(0,le.jsx)(Is.A,{className:"w-4 h-4 text-zinc-500"})]})}),(0,le.jsx)(Zg,{className:"w-auto p-0",align:"start",children:(0,le.jsx)(RC,{onApply:e=>{o(e),m(!1)},initialServices:t,onClose:()=>m(!1)})})]}),(0,le.jsxs)($g,{open:u,onOpenChange:x,children:[(0,le.jsx)(Jg,{asChild:!0,children:(0,le.jsxs)(Hn,{variant:"ghost",className:"flex justify-end items-center gap-1 p-0 h-auto hover:bg-transparent",children:[(0,le.jsx)("span",{className:"text-black text-sm font-normal",children:"Language"}),(0,le.jsx)(Is.A,{className:"w-4 h-4 text-zinc-500"})]})}),(0,le.jsx)(Zg,{className:"w-auto p-0",align:"start",children:(0,le.jsx)(MC,{onApply:e=>{c(e),x(!1)},initialLanguages:l,onClose:()=>x(!1)})})]})]})})})})}function FC(e){if(!e)return null;const t="string"==typeof e?Number(e):e;if(isNaN(t)||t<=0)return null;if(t>=1e3){const e=t/1e3;return"From $".concat(e%1==0?e.toFixed(0):e.toFixed(1),"K")}return"From $".concat(t)}function BC(e){if(!e)return null;const t="string"==typeof e?Number(e):e;if(isNaN(t)||t<=0)return null;if(t>=1e3){const e=t/1e3;return"$".concat(e%1==0?e.toFixed(0):e.toFixed(1),"K/hr")}return"$".concat(t,"/hr")}function zC(e){if(!e)return null;try{return new URL(e).hostname.replace(/^www\./,"")}catch(t){return e}}const UC=function(e){var t,s;let{partner:a,onContactClick:n}=e;const{item:l}=a,{user:r}=oe(),[i,o]=(0,Y.useState)(!1),c=(0,Y.useRef)(null),d=Array.isArray(l.services)?l.services.slice(0,4):[],m=Array.isArray(l.services)&&l.services.length>4?l.services.length-4:0;(0,Y.useEffect)(()=>{const e=e=>{c.current&&!c.current.contains(e.target)&&o(!1)},t=e=>{c.current&&!c.current.contains(e.relatedTarget)&&o(!1)};return i&&(document.addEventListener("mousedown",e),document.addEventListener("focusout",t)),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("focusout",t)}},[i]);const u=e=>{o(!i)};return(0,le.jsx)("div",{ref:c,className:"group cursor-pointer h-full",onClick:u,children:(0,le.jsxs)("div",{className:"h-full bg-white rounded-2xl border border-slate-200 hover:border-slate-300 transition-all duration-300 hover:shadow-sm overflow-hidden flex flex-col",children:[(0,le.jsxs)("div",{className:"p-5 flex-1 flex flex-col",children:[(0,le.jsxs)("div",{className:"flex flex-col",children:[(0,le.jsxs)("div",{className:"flex items-start gap-3",children:[(0,le.jsx)("div",{className:"w-16 h-16 rounded-xl bg-slate-100 flex items-center justify-center overflow-hidden shadow-[inset_0_0_0_1px_rgba(226,232,240,1)]",children:l.logo_url?(0,le.jsx)("img",{src:l.logo_url,alt:l.name||"Partner",className:"w-full h-full object-contain"}):(0,le.jsx)("span",{className:"text-2xl font-light text-slate-400",children:null===(t=l.name)||void 0===t?void 0:t.charAt(0).toUpperCase()})}),(0,le.jsx)("div",{className:"flex-1 min-w-0",children:(0,le.jsxs)("div",{className:"flex flex-col min-w-0 space-y-2",children:[(0,le.jsx)("h3",{className:"text-gray-900 text-base font-semibold font-base44 leading-4 truncate",children:l.name}),(l.city||l.country)&&(0,le.jsx)(Fi,{children:(0,le.jsxs)(Bi,{children:[(0,le.jsx)(zi,{asChild:!0,children:(0,le.jsx)("div",{className:"text-gray-500 text-sm font-normal font-base44 leading-4 truncate",children:[l.city,l.country?$k(l.country):null].filter(Boolean).join(", ")})}),(0,le.jsx)(Ui,{children:(0,le.jsx)("p",{children:[l.city,l.country?$k(l.country):null].filter(Boolean).join(", ")})})]})}),(l.website_url||l.linkedin_url)&&(0,le.jsxs)("div",{className:"flex items-center gap-3 min-w-0",children:[l.website_url&&(0,le.jsx)("a",{href:l.website_url,target:"_blank",rel:"noopener noreferrer",onClick:e=>e.stopPropagation(),className:"flex items-center gap-1.5 text-sm text-blue-500 hover:text-blue-400 font-base44 leading-4 min-w-0",children:(0,le.jsxs)("div",{className:"inline-flex justify-start items-start gap-1",children:[(0,le.jsx)("div",{className:"justify-start text-sm font-normal font-base44 leading-4 truncate max-w-32",children:zC(l.website_url)}),(0,le.jsx)("div",{"data-filled":"False","data-size":"Small",className:"flex justify-start items-start",children:(0,le.jsx)("div",{className:"w-4 h-4 relative",children:(0,le.jsx)(Tr.A,{className:"w-4 h-4 absolute "})})})]})}),l.linkedin_url&&(0,le.jsx)("a",{href:l.linkedin_url,target:"_blank",rel:"noopener noreferrer",onClick:e=>e.stopPropagation(),children:(0,le.jsx)("div",{className:"justify-start text-blue-500 text-sm hover:text-blue-400 font-normal leading-4",children:"LinkedIn"})})]})]})})]}),d.length>0&&(0,le.jsxs)("div",{className:"mt-4 flex flex-wrap gap-1.5",children:[null===(s=i?l.services:d)||void 0===s?void 0:s.map(e=>(0,le.jsx)(Nn,{variant:"secondary",className:"rounded-2xl border border-slate-200 bg-white text-slate-700 px-3 py-1 shadow-[0_1px_0_rgba(0,0,0,0.02)] hover:bg-white",children:e},e)),m>0&&!i&&(0,le.jsxs)(Nn,{variant:"secondary",className:"rounded-2xl border border-slate-200 bg-white text-slate-700 px-3 py-1 shadow-[0_1px_0_rgba(0,0,0,0.02)] cursor-pointer hover:bg-white",onClick:e=>{e.stopPropagation(),u()},children:["+",m]})]}),l.description&&(0,le.jsx)("div",{className:"mt-4 cursor-pointer",onClick:e=>{e.stopPropagation(),u()},children:(0,le.jsx)("p",{className:"\n self-stretch justify-start text-gray-600 text-sm font-normal font-base44 break-words transition-all duration-300 ease-in-out\n ".concat(i?"leading-normal":"max-h-10 leading-normal line-clamp-2 overflow-hidden","\n "),children:l.description})}),l.languages&&l.languages.length>0&&(0,le.jsxs)("div",{className:"mt-4 text-[15px] text-slate-500",children:[(0,le.jsx)("span",{className:"text-slate-500",children:"Languages:"})," ",(0,le.jsx)("span",{className:"text-slate-900",children:(x=l.languages,SC(x).join(", "))})]})]}),(0,le.jsx)("div",{className:"flex-1"})]}),(0,le.jsxs)("div",{className:"flex flex-wrap items-center gap-4 border-t border-slate-200 px-5 py-5 flex-shrink-0",children:[(0,le.jsxs)("div",{className:"flex flex-wrap items-center gap-3 text-[15px] flex-1 min-w-0",children:[FC(l.budget_starting_from_dollars)&&(0,le.jsxs)("div",{className:"flex items-center gap-2 text-slate-600 whitespace-nowrap",children:[(0,le.jsx)(AC.A,{className:"h-4 w-4 text-slate-400"}),(0,le.jsx)("span",{children:FC(l.budget_starting_from_dollars)})]}),BC(l.hourly_rate)&&(0,le.jsxs)("div",{className:"flex items-center gap-2 text-slate-600 whitespace-nowrap",children:[(0,le.jsx)(Li.A,{className:"h-4 w-4 text-slate-400"}),(0,le.jsx)("span",{children:BC(l.hourly_rate)})]})]}),(0,le.jsxs)(Hn,{onClick:e=>{e.stopPropagation();const t={user_id:(null==r?void 0:r.id)||null,app_id:null,conversation_id:null},s={cta:"Contact",origin:"partner_card",target_route:null,partner_id:l.id,partner_name:l.name||null,partner_services:l.services||[],partner_country:l.country||null};tt("User clicked contact partner",(0,K.A)((0,K.A)({},t),s)),ht(t,s),null==n||n()},variant:"outline",size:"lg",className:"h-10 px-5 rounded-xl border-slate-300 text-slate-800 bg-white hover:bg-slate-50 shadow-[0_1px_0_rgba(0,0,0,0.02)] flex-shrink-0",children:["Contact",(0,le.jsx)(ha.A,{className:"h-3.5 w-3.5 ml-2"})]})]})]})});var x};function WC(e){let{isLoading:t,isLoadingMore:s,partners:a,onContactClick:n,onBecomePartnerClick:l,hasMore:r,targetRef:i}=e;return t?(0,le.jsx)("div",{className:"flex justify-center items-center py-32",children:(0,le.jsxs)("div",{className:"flex flex-col items-center gap-3",children:[(0,le.jsx)("div",{className:"w-8 h-8 border-2 border-slate-200 border-t-slate-600 rounded-full animate-spin"}),(0,le.jsx)("p",{className:"text-sm text-slate-500",children:"Loading partners..."})]})}):t||0!==a.length?(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)("div",{className:"grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-6",children:a.map(e=>(0,le.jsx)(UC,{partner:e,onContactClick:()=>n(e)},e.item.id))}),r&&(0,le.jsx)("div",{ref:i,className:"flex justify-center items-center py-12",children:s&&(0,le.jsxs)("div",{className:"flex items-center gap-3",children:[(0,le.jsx)("div",{className:"w-5 h-5 border-2 border-slate-200 border-t-slate-600 rounded-full animate-spin"}),(0,le.jsx)("span",{className:"text-sm text-slate-500",children:"Loading more..."})]})})]}):(0,le.jsx)("div",{className:"text-center py-32",children:(0,le.jsxs)("div",{className:"max-w-sm mx-auto",children:[(0,le.jsx)("div",{className:"w-16 h-16 bg-slate-100 rounded-full flex items-center justify-center mx-auto mb-4",children:(0,le.jsx)("svg",{className:"w-8 h-8 text-slate-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,le.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0zm6 3a2 2 0 11-4 0 2 2 0 014 0zM7 10a2 2 0 11-4 0 2 2 0 014 0z"})})}),(0,le.jsx)("h3",{className:"text-lg font-medium text-slate-900 mb-2",children:"No partners found"}),(0,le.jsx)("p",{className:"text-sm text-slate-500 leading-relaxed mb-6",children:"Try adjusting your filters or search to find the right partner for your project."}),l&&(0,le.jsxs)("div",{className:"pt-6 border-t border-slate-100",children:[(0,le.jsx)("p",{className:"text-sm text-slate-600 mb-3",children:"Are you a developer or agency?"}),(0,le.jsxs)(Hn,{variant:"outline",size:"sm",onClick:l,className:"border-slate-300",children:[(0,le.jsx)(kt.A,{className:"h-4 w-4 mr-2"}),"Become a Partner"]})]})]})})}const qC=e=>{let{label:t,options:s,selectedValue:a,onValueChange:n,error:l,className:r=""}=e;return(0,le.jsxs)("div",{className:"w-full flex flex-col justify-start items-start gap-1 ".concat(r),children:[(0,le.jsx)(go,{className:"text-gray-700 text-sm font-medium font-base44 leading-tight",children:t}),(0,le.jsx)("div",{className:"w-full inline-flex justify-start items-start gap-3 mt-3",children:s.map(e=>(0,le.jsx)("button",{type:"button",onClick:()=>n(e.value),className:"flex-1 p-3 rounded-lg border flex justify-center items-center gap-3 transition-colors ".concat(a===e.value?"bg-white border-slate-950 text-black":"bg-white border-slate-200 text-black hover:bg-slate-50"),children:(0,le.jsxs)("div",{className:"inline-flex flex-col justify-center items-center gap-0.5",children:[(0,le.jsx)("div",{className:"inline-flex justify-start items-center gap-2",children:(0,le.jsx)("span",{className:"text-center text-sm font-medium font-base44 leading-tight",children:e.label})}),(0,le.jsx)("div",{className:"text-center text-sm font-normal font-base44 leading-tight",children:e.description})]})},e.value))}),l&&(0,le.jsx)("p",{className:"text-sm text-red-500 mt-2",children:l})]})},VC=e=>{let{label:t,helperText:s,selectedServices:a,onServiceToggle:n,error:l,className:r=""}=e;return(0,le.jsxs)("div",{className:"w-full flex flex-col justify-start items-start gap-2 ".concat(r),children:[(0,le.jsxs)("div",{className:"flex flex-col justify-start items-start gap-0.5",children:[(0,le.jsx)(go,{className:"text-gray-700 text-sm font-medium font-base44 leading-tight",children:t}),s&&(0,le.jsx)("p",{className:"text-slate-500 text-sm font-normal font-base44 leading-tight",children:s})]}),(0,le.jsx)(pC,{options:Hk,selectedOptions:a,onToggle:n}),l&&(0,le.jsx)("p",{className:"text-sm text-red-500 mt-1",children:l})]})},HC=[{value:"new_project",label:"New project",description:"Start from scratch"},{value:"existing_project",label:"Existing project",description:"Update or improve current project"}],YC=[{value:"as_soon_as_possible",label:"ASAP (start right away)"},{value:"within_a_week",label:"Within the next 1\u20132 weeks"},{value:"within_a_month",label:"Within the next month"},{value:"more_than_a_month",label:"Flexible"}],GC=[{value:"less_than_a_week",label:"Less than a week"},{value:"about_1_week",label:"About 1 week"},{value:"about_1_month",label:"About 1 month"},{value:"more_than_1_month",label:"More than 1 month"},{value:"i_dont_know",label:"I don't know"}],$C=qk.Ik({project_type:qk.k5(["new_project","existing_project"],{required_error:"Please select a project type"}),project_description:qk.Yj().min(20,"Please provide at least 20 characters").max(1e3,"Description must be less than 1000 characters"),services:qk.YO(qk.Yj()).min(1,"Please select at least one service"),work_basis:qk.k5(["hourly","fixed_price"],{required_error:"Please select a work basis"}),start_date:qk.KC([qk.k5(["as_soon_as_possible","within_a_week","within_a_month","more_than_a_month"]),qk.eu("")]).refine(e=>""!==e,{message:"Please select a timeline"}),estimated_project_duration:qk.KC([qk.k5(["less_than_a_week","about_1_week","about_1_month","more_than_1_month","i_dont_know"]),qk.eu("")]).refine(e=>""!==e,{message:"Please select estimated project duration"}),client_name:qk.Yj().min(1,"Name is required").max(100,"Name must be less than 100 characters"),client_email:qk.Yj().min(1,"Email is required").email("Please enter a valid email address")}),JC=$C.pick({project_type:!0,project_description:!0,services:!0}),ZC=$C.pick({work_basis:!0,start_date:!0,estimated_project_duration:!0}),KC=$C.pick({client_name:!0,client_email:!0}),QC=$C,XC=e=>{const t={};return e.errors.forEach(e=>{const s=e.path.join(".");s&&(t[s]=e.message)}),t},eA=e=>{let{formData:t,errors:s,onInputChange:a,onServiceToggle:n}=e;return(0,le.jsxs)("div",{className:"w-full p-6 bg-white flex flex-col justify-start items-start gap-6 overflow-hidden",children:[(0,le.jsx)(qC,{label:"Project type",options:HC,selectedValue:t.project_type,onValueChange:e=>a("project_type",e),error:s.project_type}),(0,le.jsxs)("div",{className:"w-full flex flex-col justify-start items-start gap-1",children:[(0,le.jsx)(go,{htmlFor:"project_description",className:"text-gray-700 text-sm font-medium font-base44 leading-tight",children:"Project description"}),(0,le.jsx)(yp,{id:"project_description",placeholder:"Describe your project goals, requirements, and any specific technologies needed\u2026",value:t.project_description,onChange:e=>a("project_description",e.target.value),className:"min-h-[120px] resize-none mt-3 ".concat(s.project_description?"border-red-500":"border-slate-200")}),s.project_description&&(0,le.jsx)("p",{className:"text-sm text-red-500 mt-2",children:s.project_description}),(0,le.jsxs)("p",{className:"text-sm text-slate-400 mt-1",children:[t.project_description.length," characters (minimum 20)"]})]}),(0,le.jsx)(VC,{label:"What do you need help with?",selectedServices:t.services,onServiceToggle:n,error:s.services})]})},tA=e=>{let{label:t,placeholder:s="",value:a,options:n,onValueChange:l,error:r,helperText:i,required:o=!1,tooltipText:c,className:d=""}=e;const m="w-full h-10 ".concat(r?"border-red-500":"border-slate-200"," ").concat(d);return(0,le.jsxs)("div",{className:"w-full space-y-2",children:[(0,le.jsxs)("div",{className:"flex items-center gap-1",children:[(0,le.jsxs)(go,{className:"text-center justify-center text-gray-700 text-sm font-medium font-base44 leading-tight",children:[t,o&&(0,le.jsx)("span",{className:"text-red-500 ml-1",children:"*"})]}),c&&(0,le.jsxs)(Bi,{delayDuration:100,children:[(0,le.jsx)(zi,{asChild:!0,children:(0,le.jsx)(uo.A,{className:"h-4 w-4 text-gray-600 hover:text-gray-900"})}),(0,le.jsx)(Ui,{className:"max-w-[240px] p-3 text-xs",children:(0,le.jsx)("p",{children:c})})]})]}),(0,le.jsxs)(In,{value:a,onValueChange:l,children:[(0,le.jsx)(Pn,{className:"w-full ".concat(m," focus:outline-none focus-visible:outline-none focus:ring-1 focus:ring-black focus:border-black data-[state=open]:ring-1 data-[state=open]:ring-black data-[state=open]:border-black"),style:{color:a?"#000000":"#94a3b8"},children:(0,le.jsx)(Tn,{placeholder:s,className:"text-sm font-normal font-base44 leading-tight"})}),(0,le.jsx)(Rn,{className:"bg-white border border-slate-200 rounded-md shadow-lg",position:"popper",sideOffset:0,children:n.map(e=>(0,le.jsx)(Mn,{value:e.value,hideCheckIcon:!0,className:"w-full p-1.5 rounded-md cursor-pointer inline-flex justify-start items-center gap-2 hover:!bg-slate-50 focus:!bg-slate-50 data-[highlighted]:!bg-slate-50 data-[state=checked]:!bg-slate-700 data-[state=checked]:!text-white data-[state=checked]:hover:!bg-slate-700 data-[state=checked]:data-[highlighted]:!bg-slate-700",children:(0,le.jsx)("div",{className:"flex-1 justify-start text-sm font-normal font-base44 leading-tight ",children:e.label})},e.value))})]}),r&&(0,le.jsx)("p",{className:"text-sm text-red-500 mt-2",children:r}),i&&!r&&(0,le.jsx)("p",{className:"text-xs text-slate-400 mt-2",children:i})]})},sA=e=>{let{formData:t,errors:s,onInputChange:a}=e;return(0,le.jsxs)("div",{className:"w-full p-6 bg-white flex flex-col justify-start items-start gap-6 overflow-hidden",children:[(0,le.jsx)(qC,{label:"Work basis",options:[{value:"hourly",label:"Hourly payment",description:"Pay based on working hours"},{value:"fixed_price",label:"Fixed price",description:"Agree on the total cost upfront"}],selectedValue:t.work_basis,onValueChange:e=>a("work_basis",e),error:s.work_basis}),(0,le.jsx)(tA,{label:"Preferred start time",placeholder:"Select start time",value:t.start_date,options:YC,onValueChange:e=>a("start_date",e),error:s.start_date}),(0,le.jsx)(tA,{label:"Estimated project duration",placeholder:"Select project duration",value:t.estimated_project_duration,options:GC,onValueChange:e=>a("estimated_project_duration",e),error:s.estimated_project_duration})]})},aA=e=>{let{formData:t,errors:s,onInputChange:a}=e;return(0,le.jsxs)("div",{className:"w-full p-6 bg-white flex flex-col justify-start items-start gap-6 overflow-hidden",children:[(0,le.jsxs)("div",{className:"w-full flex flex-col justify-start items-start gap-1",children:[(0,le.jsx)(go,{htmlFor:"client_name",className:"text-gray-700 text-sm font-medium font-base44 leading-tight",children:"Your Name"}),(0,le.jsx)(fn,{id:"client_name",type:"text",placeholder:"Full name",value:t.client_name,onChange:e=>a("client_name",e.target.value),className:"h-11 mt-3 ".concat(s.client_name?"border-red-500":"border-slate-200")}),s.client_name&&(0,le.jsx)("p",{className:"text-sm text-red-500 mt-2",children:s.client_name})]}),(0,le.jsxs)("div",{className:"w-full flex flex-col justify-start items-start gap-1",children:[(0,le.jsx)(go,{htmlFor:"client_email",className:"text-gray-700 text-sm font-medium font-base44 leading-tight",children:"Email Address"}),(0,le.jsx)(fn,{id:"client_email",type:"email",placeholder:"your@email.com",value:t.client_email,onChange:e=>a("client_email",e.target.value),className:"h-11 mt-3 ".concat(s.client_email?"border-red-500":"border-slate-200")}),s.client_email&&(0,le.jsx)("p",{className:"text-sm text-red-500 mt-2",children:s.client_email}),(0,le.jsx)("p",{className:"text-xs text-slate-400 mt-2",children:"This email will be shared with the partner for communication"})]})]})},nA=e=>{let{title:t,items:s,className:a=""}=e;const n=s.filter(e=>!1!==e.show);return(0,le.jsxs)("div",{className:"w-full flex flex-col gap-3 ".concat(a),children:[t&&(0,le.jsx)("div",{className:"w-full justify-center text-gray-700 text-sm font-medium font-base44 leading-tight",children:t}),(0,le.jsx)("div",{className:"w-full p-4 bg-slate-50 rounded-lg border border-slate-300 flex flex-col justify-start items-start gap-3",children:(0,le.jsx)("div",{className:"w-full flex flex-col justify-start items-start gap-[3px]",children:n.map((e,t)=>(0,le.jsxs)("div",{className:"w-full py-[3px] flex flex-col sm:flex-row sm:items-start gap-1 sm:gap-0",children:[(0,le.jsx)("div",{className:"sm:w-44 sm:flex-shrink-0 justify-start text-black text-sm font-normal font-base44 leading-tight",children:e.label}),(0,le.jsx)("div",{className:"flex-1 justify-start text-gray-950 text-sm font-medium font-base44 leading-tight break-words",children:e.value})]},t))})})]})},lA=e=>{let{formData:t,partner:s}=e;const a=[{label:"Partner",value:s.item.name||"Partner"},{label:"Project Type",value:(l=t.project_type,"new_project"===l?"New Project":"Existing Project")},{label:"Work Basis",value:(n=t.work_basis,"hourly"===n?"Hourly Rate":"Fixed Price")},{label:"Preferred start time",value:(e=>{const t=YC.find(t=>t.value===e);return t?t.label:e})(t.start_date)},{label:"Estimated duration",value:(e=>{const t=GC.find(t=>t.value===e);return t?t.label:e})(t.estimated_project_duration)},{label:"Contact",value:t.client_email},{label:"Services",value:t.services.join(", "),show:t.services.length>0},{label:"Description",value:t.project_description}];var n,l;return(0,le.jsxs)("div",{className:"w-full p-6 bg-white inline-flex flex-col justify-start items-start gap-3 overflow-hidden",children:[(0,le.jsxs)("div",{className:"w-full justify-start text-gray-700 text-sm font-normal font-base44 leading-tight",children:["We'll share your request with ",s.item.name||"this partner",". After reviewing your project details, they'll get in touch with you by email."]}),(0,le.jsx)(nA,{title:"Request summary",items:a})]})},rA={project_type:"existing_project",project_description:"",services:[],work_basis:"hourly",start_date:"",estimated_project_duration:"",client_name:"",client_email:""},iA=(e,t)=>{const[s,a]=(0,Y.useState)((0,K.A)((0,K.A)({},rA),{},{client_name:e||"",client_email:t||""})),[n,l]=(0,Y.useState)({}),[r,i]=(0,Y.useState)(!1),o=(e,t)=>{a(s=>(0,K.A)((0,K.A)({},s),{},{[e]:t})),n[e]&&l(t=>(0,K.A)((0,K.A)({},t),{},{[e]:null}))},c=()=>{a((0,K.A)((0,K.A)({},rA),{},{client_name:e||"",client_email:t||""})),l({}),i(!1)};return{formData:s,errors:n,isSubmitting:r,handleInputChange:o,handleServiceToggle:e=>{const t=s.services.includes(e)?s.services.filter(t=>t!==e):[...s.services,e];o("services",t)},validateStep:e=>{let t;switch(e){case 0:t=(e=>{const t=JC.safeParse(e);return t.success?{success:!0,errors:{}}:{success:!1,errors:XC(t.error)}})(s);break;case 1:t=(e=>{const t=ZC.safeParse(e);return t.success?{success:!0,errors:{}}:{success:!1,errors:XC(t.error)}})(s);break;case 2:t=(e=>{const t=KC.safeParse(e);return t.success?{success:!0,errors:{}}:{success:!1,errors:XC(t.error)}})(s);break;default:return!0}return l(t.errors),t.success},resetForm:c,handleSubmit:async e=>{const t=(e=>{const t=QC.safeParse(e);return t.success?{success:!0,errors:{}}:{success:!1,errors:XC(t.error)}})(s);if(!t.success)return l(t.errors),!1;i(!0);try{return await e(s),c(),!0}catch(a){return!1}finally{i(!1)}}}},oA=e=>{let{isOpen:t,onClose:s,partner:a,onSubmit:n}=e;const{user:l}=oe(),[r,i]=(0,Y.useState)(0),{formData:o,errors:c,isSubmitting:d,handleInputChange:m,handleServiceToggle:u,validateStep:x,resetForm:h,handleSubmit:p}=iA(null==l?void 0:l.full_name,null==l?void 0:l.email),g=[{id:1,title:"Project",description:"Tell us about your project"},{id:2,title:"Timeline",description:"Define work basis and timeline"},{id:3,title:"Contact",description:"Your contact information"},{id:4,title:"Review",description:"Review and submit your request"}];if(!t||!a)return null;const f=(0,le.jsx)("div",{className:"w-full px-2.5 py-2 bg-slate-100 border-t border-slate-200 flex justify-center items-center gap-2.5",children:(0,le.jsxs)("div",{className:"text-center flex items-center",children:[(0,le.jsx)("span",{className:"text-gray-600 text-xs font-normal font-base44 leading-tight",children:"Services are delivered by independent Partners. Base44 isn't responsible for them."}),(0,le.jsx)("a",{href:"/partners/terms",target:"_blank",rel:"noopener noreferrer",className:"ml-1 text-gray-600 text-xs font-normal font-base44 underline leading-tight cursor-pointer hover:text-gray-800",children:"Terms of use"})]})});return(0,le.jsx)("div",{"data-testid":"contact-request-modal",className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 backdrop-blur-sm",children:(0,le.jsx)(Uk,{"data-testid":"contact-request-wizard",steps:g,currentStep:r,title:"Contact ".concat(a.item.name||"Partner"),description:"We will share this information with the partner to enable communication.",onNext:()=>{x(r)&&i(e=>Math.min(e+1,g.length-1))},onPrevious:()=>{i(e=>Math.max(e-1,0))},onClose:()=>{d||(h(),i(0),s())},onSubmit:async()=>{await p(n)&&(i(0),s())},isNextDisabled:!1,isLoading:d,nextButtonText:"Next",submitButtonText:"Submit",className:"w-[640px] h-[600px]",banner:f,children:(0,le.jsx)("div",{"data-testid":"contact-request-step-content",children:(()=>{if(!a)return null;switch(r){case 0:return(0,le.jsx)(eA,{formData:o,errors:c,onInputChange:m,onServiceToggle:u});case 1:return(0,le.jsx)(sA,{formData:o,errors:c,onInputChange:m});case 2:return(0,le.jsx)(aA,{formData:o,errors:c,onInputChange:m});case 3:return(0,le.jsx)(lA,{formData:o,partner:a});default:return null}})()})})})};function cA(){oe();const{partnerId:e}=(0,Z.g)(),t=(0,Z.Zp)(),[s,a]=(0,Y.useState)([]),[n,l]=(0,Y.useState)(!0),[r,i]=(0,Y.useState)([]),[o,c]=(0,Y.useState)("all"),[d,m]=(0,Y.useState)([]),[u]=(0,Y.useState)("relevance"),[x,h]=(0,Y.useState)(0),[p,g]=(0,Y.useState)(1e5),[f,v]=(0,Y.useState)(!0),[b,j]=(0,Y.useState)(!1),[y,N]=(0,Y.useState)(0),[w]=(0,Y.useState)(12),[_,k]=(0,Y.useState)(0),[C,A]=(0,Y.useState)(!1),[S,E]=(0,Y.useState)(!1),I=(0,Y.useCallback)(async function(){let e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];try{e?l(!0):j(!0);const t=e?0:_,s={skip:t,limit:w,sort_by:L(u),status:"approved"};r.length>0&&(s.services={$in:r}),d.length>0&&(s.languages={$in:d}),(x>0||p<1e5)&&(s.budget_starting_from_dollars={},x>0&&(s.budget_starting_from_dollars.$gte=x),p<1e5&&(s.budget_starting_from_dollars.$lte=p)),Object.keys(s).forEach(e=>{void 0===s[e]&&delete s[e]});const n=await bC.listCatalogItems(s),i=Array.isArray(n)?n:n.items,o=Array.isArray(n)?i.length:n.total||i.length;e?(a(i),N(o)):a(e=>[...e,...i]),k(t+i.length),v(i.length===w)}catch(t){an({title:"Error",description:"Failed to load partners. Please try again.",variant:"destructive"})}finally{l(!1),j(!1)}},[_,w,r,d,u,x,p]);(0,Y.useEffect)(()=>{a([]),k(0),v(!0),I(!0)},[r,d,u,x,p]);const{data:T,resetData:P}=uu({query:async()=>{var t,s;if((null==T||null===(t=T.item)||void 0===t||null===(s=t.id)||void 0===s?void 0:s.toString())===e)return T;const a=await bC.getPartnerById(e);return A(!0),{item:a.item}},enabled:!!e,initialData:null,onError:()=>{t("/partners",{replace:!0})},logErrorMsg:"Error fetching partner by ID:",toastError:{title:"Error",description:"Partner not found or unavailable."}},[e]),L=e=>{switch(e){case"budget_low":return"budget_starting_from_dollars_asc";case"budget_high":return"budget_starting_from_dollars_desc";case"hourly_low":return"hourly_rate_asc";case"hourly_high":return"hourly_rate_desc";case"newest":return"created_at_desc";default:return"usage"}},O=(0,Y.useCallback)(()=>{!f||b||n||I(!1)},[f,b,n,I]),{targetRef:R}=RN({onLoadMore:O,hasMore:f,isLoading:b||n}),M=()=>{A(!1),e&&(t("/partners",{replace:!0}),P({data:null,refetch:!1}))};return(0,le.jsxs)("div",{"data-testid":"partners-catalog",className:"min-h-screen bg-white",children:[(0,le.jsx)(PC,{"data-testid":"catalog-header",totalPartners:y,onBecomePartnerClick:()=>E(!0)}),(0,le.jsx)(DC,{"data-testid":"filter-bar",selectedServices:r,onServicesChange:i,budgetRange:o,onBudgetRangeChange:c,selectedLanguages:d,onLanguagesChange:m,onBudgetApply:(e,t)=>{h(e),g(t)},onServicesApply:e=>{i(e)},onLanguagesApply:e=>{m(e)},currentBudgetMin:x,currentBudgetMax:p}),(0,le.jsxs)("div",{"data-testid":"partners-catalog-content",className:"max-w-7xl mx-auto px-6 lg:px-8 py-12",children:[(0,le.jsx)(WC,{"data-testid":"partners-grid",isLoading:n,isLoadingMore:b,partners:s,onContactClick:e=>{t("/partners/".concat(e.item.id),{replace:!1}),P({data:e,refetch:!1}),A(!0)},onBecomePartnerClick:()=>E(!0),hasMore:f,targetRef:R}),(0,le.jsx)(oA,{isOpen:C,onClose:M,partner:T,onSubmit:async e=>{try{await bC.contactRequest((0,K.A)((0,K.A)({},e),{},{partner_profile_id:null==T?void 0:T.item.id})),an({title:"Success",description:"Your contact request has been sent successfully!"}),M()}catch(a){var t,s;null!==(t=a.response)&&void 0!==t&&null!==(s=t.data)&&void 0!==s&&s.detail?an({title:"Error",description:a.response.data.detail,variant:"destructive"}):(alert(a.message),an({title:"Error",description:"Failed to send contact request. Please try again.",variant:"destructive"}))}}}),(0,le.jsx)(NC,{isOpen:S,onClose:()=>E(!1)})]})]})}function dA(){return(0,le.jsx)("div",{className:"min-h-screen bg-gradient-to-br from-slate-50 to-slate-100",children:(0,le.jsx)("div",{className:"max-w-4xl mx-auto px-6 py-12",children:(0,le.jsxs)("div",{className:"bg-white rounded-2xl shadow-xl border border-slate-200 overflow-hidden",children:[(0,le.jsxs)("div",{className:"bg-gradient-to-r from-orange-500 to-orange-600 px-8 py-6",children:[(0,le.jsx)("h1",{className:"text-3xl font-bold text-white",children:"Base44 Partners Terms of Use"}),(0,le.jsx)("p",{className:"text-orange-100 mt-2",children:"Last updated: September 11, 2025"})]}),(0,le.jsx)("div",{className:"px-8 py-8",children:(0,le.jsxs)("div",{className:"prose prose-slate max-w-none prose-headings:text-slate-800 prose-headings:font-semibold prose-p:text-slate-700 prose-p:leading-relaxed prose-strong:text-slate-900",children:[(0,le.jsx)("style",{dangerouslySetInnerHTML:{__html:"\n .partners-terms a {\n color: #2563eb !important;\n text-decoration: underline !important;\n }\n .partners-terms a:hover {\n color: #1d4ed8 !important;\n }\n "}}),(0,le.jsx)("div",{className:"partners-terms",children:(0,le.jsx)(vN,{children:'\n\nWelcome to the Base44 Partners: A venue in which Base44 users can review the work of freelance web professionals and agencies, and request to acquire custom services (the "Services").\n\nThese terms and conditions (the "Partners Terms") are a binding agreement between you and Base44 Inc. ("Base44"). These Base44 Partners Terms govern your use of this Platform, including all content and services available through the [Base44.com/partners](https://base44.com/partners) (the "Base44 Partners"). \n\nBY USING AND/OR VISITING THIS WEBSITE, you hereby consent to these terms and conditions, AND TO the general Terms of Use of Base44, as may be amended from time to time, which can be reviewed at [https://base44.com/terms-of-service](https://base44.com/terms-of-service) ; (the "Base44 Terms") You further acknowledge that you have read the terms and conditions of Base44\'s privacy policy, which are published at [https://base44.com/privacy-policy](https://base44.com/privacy-policy), as may be amended from time to time, (the "Privacy Policy"). \n\nThe Base44 Terms and the Privacy Policy are incorporated herein by reference and govern your use of the Base44 Partners. \n\nBY JOINING THE BASE44 PARTNERS, YOU ACKNOWLEDGE THAT YOU HAVE READ THE BASE44 PARTNERS TERMS AND FURTHER UNDERSTAND AND AGREE TO BE BOUND BY SUCH TERMS, INCLUDING ANY FUTURE MODIFICATIONS THERETO. WE MAY REVISE THESE TERMS AT ANY TIME BY POSTING AN UPDATED VERSION ON OUR WEBSITE. YOU ARE ENCOURAGED TO REVIEW THIS AGREEMENT FROM TIME-TO-TIME BECAUSE YOU ARE BOUND BY THESE TERMS. YOUR CONTINUED USE OF THE BASE44 PARTNERS AFTER A CHANGE TO THESE TERMS CONSTITUTES YOUR BINDING ACCEPTANCE OF THESE TERMS. IF, AT ANY TIME, YOU DO NOT AGREE TO ANY OF THE TERMS OF THIS AGREEMENT IN EFFECT AT SUCH TIME, PLEASE DO NOT USE THE BASE44 PARTNERS. NOTWITHSTANDING THE FORGOING, BASE44 SHALL HAVE THE RIGHT TO TERMINATE YOUR ACCOUNT AS A BASE44 PARTNER (AS DEFINED BELOW) AND REMOVE YOU FROM THE PARTNERS AT ANY TIME FOLLOWING SUCH NOTICE.\n\n## 1. General Description\n\nThe Base44 Partners (i) allows any eligible web professionals, freelancers, agencies, and other businesses (either individuals or entities) with a valid user account (the "Base44 Partner(s)") to create a profile dedicated to their work (the "Profile") allows visitors to review the Base44 Partners\' Profiles and allows Base44 users with a valid User Account (the "Base44 Member(s)") to find Base44 Partners that may suit their needs to provide with Services; and (iii) facilitates the initial communication between a Base44 Member and the chosen Base44 Partner so they can connect directly regarding the Services needs of the Base44 Member (Base44 Partners and Base44 Members, together, "Users", and individually: "User" or "you" ).\n\nWithin the Base44 Partners, Base44 Members may request and obtain Services for both free websites on the Base44 platform and websites under any Base44 Premium Plan. The Services are not provided free of charge. Any Custom Services acquired beyond the Marketplace Templates shall be separately and freely negotiated between Base44 Partner and Base44 Members.\n\nBase44 itself does not offer or provide any such tailored website services under the Base44 Partners and has no responsibility or liability for any Services provided by the Base44 Partners.\n\nThe Base44 Partners is not an employment or matching agency, and except as specifically stated herein, the Base44 Partners does not engage as a referral, matching or placement service and does not provide, refer, place, offer or seek to obtain employment or engagements for any of its Users.\n\n## 2. Additional Terms Applicable to Base44 Partners\n\nThe Base44 Partner Program, as currently offered by Base44 at [add URL]. Base44 Partners may sell their Services on the Base44 Partners and present their services in their dedicated Profile. Once Base44 Partners access is granted, the Base44 Partner will have the opportunity to create its Profile, and Base44 Members shall be able to view such Profile after the Base44 Partner completes as indicated.\n\nBase44 reserves the right to make changes from time to time to the Partner Program, including, but not limited to, including, without limitation, accessibility and use of the Base44 Partners, as set forth in the Base44 Partner Terms.\n\nBase44 shall have sole and absolute discretion regarding the eligibility of any Base44 Partner to access and use the Base44 Partners, and does not guarantee that any Base44 Partner will be presented on the Base44 Partners [catalog] for any minimum period of time or at all. Base44 reserves the right to remove any Base44 Partner from the Base44 Partners [catalog] or may require a Base44 Partner to remove any its Profile or User Content included in its Profile, at Base44\'s discretion. Base44 shall not be obligated to provide any explanations regarding its decisions in this respect.\n\n## 3. License \n\nBy creating, posting or sharing any information through the Service, you grant Base44 a world-wide, non-exclusive, sublicensable, royalty-free, fully paid, perpetual, transferable license and unrestricted right, on or through the Base44 Website or Base44 Partners [catalog] to use, modify, remove, publish, transmit, sublicense or display such information or User Content in any now existing or hereinafter medium developed in order to operate Base44\'s business, and to provide Services, including, without limitation, to advertise and promote the Service, the catalog, your Profile. You waive any claims against Base44 or anyone on its behalf relating to any past, present or future moral rights, artists\' rights, or any other similar rights worldwide that you may have with respect to such permitted uses.\n\n**Intellectual Property Rights.** Base44 does not acquire any ownership interest in your Profile, or other User Content under these Partners Terms. Base44 Partner and its licensors (as applicable) shall retain their right, title and interest in the Marks and other User Content. In the event of any third party claim that a Base44 Member\'s possession or use of a service infringes on a third party\'s intellectual property rights, you, not Base44, will be solely responsible for the investigation, defense, settlement and discharge of any such intellectual property infringement claim.\n\n## 4. Base44 Partner Representations and Warranties.\n\nBy using the Base Partners you confirm, undertake, acknowledge, represent and warrant that:\n\nYou are at least 18 years of age or the legal age of majority. To the extent Base44 Partner is an entity, such Base44 Partner further represents and warrants it is duly organized and validly existing under the laws of its jurisdiction and has the requisite power and authority to enter into this agreement and to perform its obligations hereunder; \n\nYou will at all times provide true, accurate, current, and complete information when submitting any registration form(s) or otherwise providing any information to Base44 through the Partners [catalog]. You are solely responsible for editing and updating such information on your Profile. You shall keep any User Content in your Profile up-to-date with no broken links or misinformation. You are responsible for removing from your Profile, any User Content you are not authorized to use anymore. \n\nYou own or otherwise have the full right and authority to present and publish the User Content or other content presented in your Profile, and your Portfolio (including, without limitation, links and third party websites). You must not submit, upload, post, display or share any User Content or other content that you do not have the right to copy, use, link to or share for the purpose of your use of the Base44 Partners. The posting and use of User Content or other content on or through the Service does not violate the privacy rights, publicity rights, copyrights, contract rights, intellectual property rights, or any other rights of any person. You shall be solely liable for any damages resulting from any infringement of copyrights, trademarks or other intellectual property rights, or any other harm resulting from your uploading, posting or publishing User Content or other content in your Templates or to the Base44 Partners. You should have all rights required to present your Profile. You acknowledge and agree that all information presented in your Profile is non-confidential.\n\nYou may not advertise and/or address non-Base44 apps and/or platforms in your Profile. The websites presented in your Profile should accurately reflect your abilities and the services you are being hired to perform and/or the Templates you are offering for sale. Any content presented in your profile will be free of viruses, Trojan horses, worms, spyware, disabling, or other such malicious code.\n\nYou agree that your use of the Service will not violate any applicable laws.\n\nYou agree that your use of the Service will not include sending unsolicited marketing messages or broadcasts (i.e. spam). Base44 may block anyone violating this provision from using the Service.\n\nYou shall abide by fair business practices and ethics in any dealings with any Base44 Member.\n\nNone of the Base44 Partner, its subsidiaries, or any director or officer thereof, is, or is owned or controlled by individuals or entities that are: (i) the target of any sanctions administered or enforced by the U.S. Department of the Treasury Office of Foreign Asset Control ("OFAC"), the U.S. State Department or any other U.S. government agency or department, the United Nations Security Council, the European Union or Her Majesty Treasury and/or the target of any Israeli sanctions (collectively, "Sanctions"), or (ii) located, organized or resident in a country or territory that is the subject of comprehensive territorial Sanctions.\n\n## 5. Use of the Service by the Partner.\n\nYou confirm and acknowledge that some Personal Information and other Information (as those terms are defined in Base44\'s Privacy Policy) you provide Base44 may become public and accessible to Base44 Members and other Base44 website visitors reviewing your Profile on the Base44 Partners [catalog].\n\nThe order of presentation of the Base44 Partners\' Profiles on the Base44 Partners is subject to Base44\'s sole and absolute discretion. Ranking is determined by parameters decided by Base44. Parameters that may influence your ranking include, without limitation, the nature of the Feedback we may receive from Base44 Members who have used your Services.\n\n**Accuracy of Information.** Any information communicated to you about a Base44 Member via the Base44 Partners [catalog] shall be conveyed in conformity with the information provided to Base44 by such Base44 Member. Base44 is not responsible for the truthfulness and validity of information provided by any Base44 Member. Base44 is not responsible for information provided by third parties. You are solely responsible for the management of Base44 Members\' information in your Base44 Partner [catalog], whether such information is added and/or uploaded by you, or by Base44 on your behalf, in accordance with applicable law.\n\n**Profile.** Each Base44 Partner may have only one Profile presented on the Base44 Partners. You may not have more than one profile in the Base44 Partners.\n\n**Account Protection.** Only you may use your account and authentication credentials (e.g., keys, tokens, password) associated with your Profile, and you are fully responsible for safeguarding such information from compromise and for using them only as authorized by Base44 and in accordance with these terms.\n\n**Guidelines.** Base44 has the right to determine instructions and guidelines in connection with the use of the Base44 Partners, including regarding any languages to be used in the Profiles. \n\n**Removal.** Base44 reserves the right to remove any Base44 Partner from the Base44 Partners without notice, for any reason.\n\n## 6. Submission, Approval and Withdrawal.\n\nYou must submit each Profile that you wish to offer to Base44 Members and or Users, as well as any material updates to such Profile, for Base44\'s prior approval. Any such updates shall be subject to the terms and conditions set forth in this Agreement. \n\n**Minimum Requirements.** The Profile must comply with all terms and conditions set forth in this Agreement; the Profile must not infringe or misappropriate any intellectual property or personal right of any third party and, the Profile must comply with any other requirements provided to you by Base44.\n\n**Approval.** Prior to making any Profile available, Base44, or a third party on its behalf, will review and evaluate each Profile (including any updates or changes if Base44 deems it necessary) submitted by Base44 Partner. Base44 Partner agrees to cooperate with Base44 in the reviewing, testing and evaluation process and to answer questions and provide information and materials reasonably requested by Base44. Base44 may require Base44 Partner to make adjustments and/or modifications to its Profile, as necessary to ensure the compliance with this Agreement. Base44 Partner shall make such required adjustments within a reasonable period of time as determined by Base44. It is clarified that Base44 shall have no obligation to include any Profile in the [Catalog] even if such Profile was previously approved by Base44.\n\n**Removal.** Base44 may remove or suspend any Profile from the [catalog] at any time, at its sole discretion with no obligation to provide any explanation or prior notice and with no liability to Base44 Partner. Base44 Partners may remove their own Profiles at any time.\n\n**Responding to Claims.** You, as a Base44 Partner, understand and agree that you are solely responsible for providing relevant support and assistance to a Base44 Member in relation to the purchase and use of the Services. If Base44 receives a claim from a third party concerning a Service, Base44 may refer such claim to you. You must respond to the claim promptly, and take any and all actions required for the Service to comply with the law when applicable. If you discover or are notified that a Service violates these Terms, you shall immediately take the required actions to correct such violation. You must state in your Profile your name, address and all the required contact information to which any Base44 Member questions, complaints or claims with respect to the Services you provide should be directed.\n\n**Warranty.** You are solely responsible for any warranties, whether expressed or implied by law, to the extent not effectively disclaimed, for any services you provide. Base44 will have no warranty obligation whatsoever with respect to the services you provide.\n\n## 7. Pricing\n\n**Pricing.** Base44 Partners are required to publish and present their starting rates for each Service they support in their Profiles and to clearly define and present the prices. Prices should be charged in U.S. Dollars.\n\n**Taxes.** Base44 Partner shall be responsible for the payment of any and all taxes assessments, fees and other governmental charges of any kind, as well as withholding and reporting obligations applicable to the conduct of Base44 Partner\'s business. \n\n## 8. Economic Sanctions and Exports Controls\n\nBase44 Partner acknowledges that any use of its services may not be provided to or used by any person in any of the countries that are subject to comprehensive economic sanctions under the EAR, OFAC, or Israeli regulations, which currently include Crimea - region of Ukraine, Cuba, Iran, North Korea, and Syria. Moreover, Base44 Partner shall not allow and fully restrict any usage relating to its Services from Members (individuals and entities) identified on any Sanctions list, including but not limited to OFAC\'s Specially Designated Nationals and Blocked Parties List (the "SDN List"), entities owned 50% or more by any individuals or entities on the SDN List, or individuals or entities that are located in any comprehensively sanctioned country.\n\nBase44 Partner shall (i) be solely responsible to check the applicable Export Controls regulations and any updates or modifications thereof; (ii) be solely responsible to strictly comply with Export Controls at all times during which this Agreement is in force; and (iii) be liable for any infractions or imposed sanctions thereunder.\n\n## 9. User Data Terms\n\nWithout limiting Base44 Partners\' other representations, warranties and obligations under these Partners Terms, to the extent Base44 Partner performs any form of processing activity with respect to or in connection with any personal data of Base44 Members, Base44 Users ("User Data"), then Base44 Partner, Base44 Partner\'s Services, must comply with all applicable privacy and data protection laws, including (but not limited to) the General Data Protection Legislation ((EU) 2016/679) (GDPR) and any applicable national implementing laws, regulations and secondary legislation relating to the Processing of Personal Data (collectively, "Data Privacy Laws"), including, without limitation, any and all consent or notice requirements. \n\n**Definitions:** (i) "GDPR" means the Regulation (EU) 2016/679 of the European Parliament and of the Council of 27 April 2016 on the protection of natural persons with regard to the processing of personal data and on the free movement of such data, and repealing Directive 95/46/EC (General Data Protection Regulation).\n\nBase44 Partner shall limit its Base44 Member Data Processing activities only to the extent required to operate the Base44 Partner\'s Services to the Base44 Members. Base44 Partner is prohibited from Processing, either directly or through a processor, any Base44 Member Data provided to Base44 Partner by Base44 for the purposes of marketing, advertising, sales, personalization, except at the instruction of the Base44 Member and in compliance with applicable Data Privacy Laws.\n\nBase44 Partner further acknowledges and agrees that Base44 is not and shall not be deemed a Controller of any processing activity concerning Personal Data of Base44 Users that is conducted by Base44 Partner outside the Base44 platform, whether through your business or personal email or otherwise.\n\n## 10. Additional Terms Applicable to Base44 Members\n\n**Overview.** As a Base44 Member participating in the Base44 Partners, you agree and acknowledge that: \n\na) Base44 is not the employer of any Base44 Partner, nor does Base44 supervise, direct or control the Base44 Partners\' work or Services, in any manner. Base44 does not provide any training to the Base44 Partners, and has no control over the quality, timing, legality, failure to provide, or any other aspect whatsoever of the Services.\n \nb) Each Base44 Partner provides you services as an independent contractor and is not an employee, joint venturer, partner, agent, or franchisee of Base44 for any purpose whatsoever.\n\nc) Base44 is not responsible for the truthfulness and validity of information presented by any Base44 Partner. Base44 does not have any obligation to independently verify any information provided to it by any Base44 Partner, their experience or training, and shall not be responsible or liable for any representation or undertaking made by any Base44 Partner.\n\nd) You are at least 18 years of age or the legal age of majority;\n\ne) You are not located in a region that is subject to a U.S. government embargo or included on any list of prohibited or restricted parties. Any breach of the foregoing representations and warranties entitles Base44 to immediately terminate the Base44 Terms and/or seek any and all remedies available at law or equity.\n\n**No Endorsement.** In no event shall any reference by Base44 to any Base44 Partner or offered by a third party be construed as an approval or endorsement by Base44 of such Base44 Partner and any Services provided by them. You are responsible for exercising appropriate judgment and caution and Base44 does not enforce or accept any responsibility for the content or use of such Services.\n\n**Relationship.** Any relationship between any Base44 Member and a Base44 Partner listed on the Marketplace will be according to the terms to be agreed upon between such Base44 Member and the specific Base44 Partner they decide to work with. Base44 does not take responsibility, in any way or manner, for the quality of the Services provided to any Base44 Member by any of the Base44 Partners.\n\n**Responsibility.** You accept sole responsibility for all of your activities using the Base44 Partners, including your conduct on the site and any and all content you may submit or present via the Base44 Partners [catalog].\n\n## 11. Information and Communication\n\n**Information Management.** By providing the information required to participate in the Base44 Partners (including without limitation your email address and phone number), you confirm and acknowledge that Base44 may transfer such information, as well as other required Personal Information in your account, to the Base44 Partner(s) you have chosen, and that both Base44 and the Base44 Partner(s) may, to the extent permitted by applicable law, use both your Personal Information and Non Personal Information, in order to facilitate and provide your requested Services. You acknowledge that Base44 Partners are solely responsible for the management of information, including Base44 Members\' Personal Information.\n\n**Communication.** You agree to receive from time to time messages and promotional materials from Base44 by e-mail or any other contact form you may provide us with (including your phone number for calls or text messages), including, without limitation, messages featuring Profiles of various Base44 Partners. If you do not wish to receive such promotional materials or notices, please notify us at any time.\n\n## 12. Termination\n\n**Term and Termination.** Base44 shall have the right to terminate this agreement from any reason. If you are a Base44 Partner, termination will result in the deactivation of your account from the Partners Catalog. \n\n**Disclaimer.** BASE44 IS NOT AFFILIATED WITH OR RESPONSIBLE FOR THE FUNCTIONALITY OR PERFORMANCE OF ANY SERVICES OFFERED BY A BASE44 PARTNER. ALL BASE44 PARTNERS ARE INDEPENDENT PARTIES FROM BASE44. BASE44 HAS NO CONTROL OVER AND SHALL THEREFORE ASSUME NO RESPONSIBILITY FOR ANY TEMPLATE AND ITS CONTENT, FUNCTIONALITY, PRIVACY POLICY OR TERMS OF USE (AND THE PRESENCE, DISPLAY, TERMS, CONDITIONS, OR POLICIES OF SUCH PRIVACY POLICY OR TERMS OF USE), AND AVAILABLE OR RELATED PRODUCTS OR SERVICES.\n\n## 13. Third-Party Disputes\n\nBase44 Members and Base44 Partners must resolve any issues, disputes or concerns directly with each other. Any commercial interaction with any party or person other than Base44 or purchase of Services from such party is done at your own risk. If you have a dispute with a Base44 Partner including, without limitation, regarding their support, services, performance, and/or conduct you will need to handle it through the means they provide. Base44 will not mediate any Base44 Partner -to-Base44 Members disputes.\n\n## 14. Warranty Disclaimer & Limitation of Liability\n\nThe following disclaimers and limitations of liability are supplemental to the disclaimers and limitations of liability under the Base44 Terms:\n\nYOU AGREE THAT YOUR USE OF THE BASE44 PARTNERS [CATALOG], EITHER AS A BASE44 PARTNER OR AS A BASE44 MEMBER, SHALL BE AT YOUR SOLE RISK. TO THE FULLEST EXTENT PERMITTED BY LAW, BASE44, ITS OFFICERS, DIRECTORS, EMPLOYEES, AND AGENTS (COLLECTIVELY: "BASE44 REPRESENTATIVES") DISCLAIM ALL WARRANTIES, EXPRESS OR IMPLIED, AND ASSUME NO RESPONSIBILITY IN CONNECTION WITH (A) THE SERVICES OFFERED BY THE BASE44 PARTNERS ON THE BASE44 PARTNERS [CATALOG] AND THE USE THEREOF BY ANY USER; (B) ANY BASE44 PARTNER\'S REGISTRATION, OR PROFESSIONAL ACCREDITATION; (C) THE RESULTS THAT MAY BE OBTAINED FROM THE USE OF THE BASE44 PARTNERS [CATALOG]; (D) THE TIMELINESS, ACCURACY, RELIABILITY, QUALITY, SUITABILITY, SAFETY, COMPLETENESS OR CONTENT OF THE SERVICES, OR ANY PRODUCTS, MERCHANDISE, CONTENT, INFORMATION OR MATERIALS PROVIDED THROUGH OR IN CONNECTION WITH THE USE OF THE BASE44 PARTNERS [CATALOG]; AND (E) THE SUITABILITY, LEGALITY OR ABILITY OF ANY BASE44 PARTNER TO PROVIDE SERVICES.\n\nNEITHER BASE44 NOR BASE44 REPRESENTATIVES ARE RESPONSIBLE FOR THE CONDUCT, WHETHER ONLINE OR OFFLINE, OF ANY USER OF THE BASE44 PARTNERS (INCLUDING BUT NOT LIMITED TO THE CONDUCT OF ANY BASE44 MEMBER OR BASE44 PARTNERS).\n\nIN ADDITION TO THE LIMITATIONS OF LIABILITY AS STIPULATED IN THE BASE44 TERMS, IN NO EVENT SHALL BASE44 OR ANY BASE44 REPRESENTATIVES BE LIABLE TO YOU FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, PUNITIVE, OR CONSEQUENTIAL DAMAGES WHATSOEVER RESULTING FROM (I) THE USE OR THE INABILITY TO USE THE SERVICE; (II) UNAUTHORIZED ACCESS TO OR ALTERATION OF YOUR ACCOUNT; (III) YOUR RELIANCE ON USER CONTENT, INCLUDING THE TEMPLATES; (IV) ANY COMMUNICATION BETWEEN ANY BASE44 MEMBER AND ANY BASE44 PARTNER LISTED ON THE BASE44 MARKETPLACE AND (V) ANY OTHER MATTER RELATING TO THE SERVICE. SOME JURISDICTIONS DO NOT PERMIT THE EXCLUSION OF CERTAIN LIABILITIES. ACCORDINGLY, CERTAIN LIMITATIONS DESCRIBED HEREIN MAY NOT APPLY TO YOU. \n\nYOU EXPRESSLY WAIVE AND RELEASE BASE44 AND BASE44 REPRESENTATIVES FROM ANY AND ALL LIABILITY, CLAIMS OR DAMAGES ARISING FROM OR IN ANY WAY RELATED TO THE SERVICES (ACTUAL, DIRECT OR CONSEQUENTIAL) OF EVERY KIND AND NATURE, KNOWN AND UNKNOWN, SUSPECTED AND UNSUSPECTED, DISCLOSED AND UNDISCLOSED, ARISING OUT OF OR IN ANY WAY CONNECTED WITH SUCH DISPUTE. AS WITH THE PURCHASE OF A PRODUCT OR SERVICE THROUGH ANY MEDIUM OR IN ANY ENVIRONMENT, USERS SHOULD USE THEIR BEST JUDGMENT AND EXERCISE CAUTION WHERE APPROPRIATE. YOUR USE OF THE BASE44 PARTNERS AND THE SERVICES IS AT YOUR OWN RISK. THE FOREGOING LIMITATIONS OF LIABILITY SHALL APPLY TO THE FULLEST EXTENT PERMITTED BY LAW IN THE APPLICABLE JURISDICTION. \n\nNOTHING IN BASE44 PARTNERS TERMS AND CONDITIONS OR THE BASE44 PARTNERS CONSTITUTES, OR IS MEANT TO CONSTITUTE, ADVICE OF ANY KIND. \n\n## 15. Indemnification\n\nAs a Base44 User, in addition to your obligation of indemnification under the Base44 Terms, you agree to defend, indemnify and hold harmless Base44, its officers, directors, shareholders, employees, affiliates and agents, from and against any and all claims, damages, obligations, losses, liabilities, costs, debt and expenses (including attorneys\' fees) arising from the following, as applicable:\n\nFor each Base44 Partner and Base44 Member (1) your violation of any third party right, including any copyright, property, or privacy right, resulting from your Profile or User Content, or your usage of the Services; and/or (2) your use of the Base44 Partners and/or the Services including in connection with any transactions and interactions resulting from the usages thereof. \n\n## 16. Feedback\n\nBase44 enables both Base44 Partners and Base44 Members to provide feedback regarding the Base44 Partners [_], the Services rendered ("Feedback"). Such Feedback may be viewed by other Base44 Users. Base44 has sole and complete discretion to remove any Feedback, including Feedback which may be deemed as defamatory, libelous, obscene, harassing, threatening, incendiary, abusive, racist, offensive, deceptive or fraudulent, encouraging criminal or harmful conduct, or which otherwise violates the rights of Base44 or any third party (including any intellectual property rights, privacy rights, contractual or fiduciary rights), or otherwise shows any person, entity or brand in a bad or disparaging light, without their prior explicit approval.\n'})})]})}),(0,le.jsx)("div",{className:"bg-slate-50 px-8 py-6 border-t border-slate-200",children:(0,le.jsx)("p",{className:"text-sm text-slate-600 text-center",children:"For questions about these terms, please contact us at partners@base44.com."})})]})})})}const mA=()=>{const[e]=(0,J.useSearchParams)(),t=e.get("appId"),[s,a]=(0,Y.useState)(!0);return(0,Y.useEffect)(()=>{(async()=>{if(t)try{const e=await ve.getLoginInfoById(t),{slug:s}=e;s?window.location.href="https://".concat(s,".base44.app"):a(!1)}catch(e){a(!1)}else a(!1)})()},[t]),t?s?(0,le.jsx)("div",{className:"flex items-center justify-center min-h-screen bg-slate-50",children:(0,le.jsxs)("div",{className:"text-center",children:[(0,le.jsx)("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-orange-500 mx-auto mb-4"}),(0,le.jsx)("p",{className:"text-slate-600",children:"Redirecting to app..."})]})}):null:(0,le.jsx)("div",{className:"flex items-center justify-center min-h-screen bg-slate-50",children:(0,le.jsx)("div",{className:"text-center",children:(0,le.jsx)("p",{className:"text-slate-500 text-sm",children:"No app found"})})})},uA=[{url:"https://qtrypzzcjebvfcihiynt.supabase.co/storage/v1/object/public/base44-prod/public/7d29cd82d_image.png",name:"Task management flow"},{url:"https://qtrypzzcjebvfcihiynt.supabase.co/storage/v1/object/public/base44-prod/public/5c09f40a9_Screenshot2025-08-05at72216PM.png",name:"Interactive Floating Sidebar UI"},{url:"https://qtrypzzcjebvfcihiynt.supabase.co/storage/v1/object/public/base44-prod/public/6e210e9d2_image.png",name:"Tuesday.com"},{url:"https://qtrypzzcjebvfcihiynt.supabase.co/storage/v1/object/public/base44-prod/public/99957f317_image.png",name:"CryptoPulse AI"},{url:"https://qtrypzzcjebvfcihiynt.supabase.co/storage/v1/object/public/base44-prod/public/50c296c5a_Screenshot2025-08-05at75928PM.png",name:"Digital Asset Trading Interface"},{url:"https://qtrypzzcjebvfcihiynt.supabase.co/storage/v1/object/public/base44-prod/public/7117fa9d7_image.png",name:"Moda Studio"},{url:"https://qtrypzzcjebvfcihiynt.supabase.co/storage/v1/object/public/base44-prod/public/476d38fcc_AccuPro.jpg",name:"AccuPro"},{url:"https://qtrypzzcjebvfcihiynt.supabase.co/storage/v1/object/public/base44-prod/public/3cb61189d_Screenshot2025-08-07at60618PM.png",name:"Dark glassmorphic interface"},{url:"https://qtrypzzcjebvfcihiynt.supabase.co/storage/v1/object/public/base44-prod/public/68c00d37cf382c8b00deb66e/be38563c8_Screenshot2025-09-09171606.png",name:"CODE GEN AI"},{url:"https://qtrypzzcjebvfcihiynt.supabase.co/storage/v1/object/public/base44-prod/public/06acedf4e_Screenshot2025-08-05at73529PM.png",name:"Interactive Globe"},{url:"https://qtrypzzcjebvfcihiynt.supabase.co/storage/v1/object/public/base44-prod/public/8a6304e4b_Screenshot1.png",name:"CodeMaster"},{url:"https://qtrypzzcjebvfcihiynt.supabase.co/storage/v1/object/public/base44-prod/public/148eedd97_Screenshot2025-08-06034625.png",name:"CompanyHub"},{url:"https://qtrypzzcjebvfcihiynt.supabase.co/storage/v1/object/public/base44-prod/public/bc3a6408d_Screenshot2025-08-05at94004PM.png",name:"Financial Education Academy"},{url:"https://qtrypzzcjebvfcihiynt.supabase.co/storage/v1/object/public/base44-prod/public/010274a5c_Screenshot2025-08-28092749.png",name:"SETH"},{url:"https://qtrypzzcjebvfcihiynt.supabase.co/storage/v1/object/public/base44-prod/public/4f97403a2_IMG_2122.jpeg",name:"Star AI"},{url:"https://qtrypzzcjebvfcihiynt.supabase.co/storage/v1/object/public/base44-prod/public/eb22e5da9_Srenity-SpaSalon-HeroSection-2.png",name:"Serenity- Spa & Salon"},{url:"https://qtrypzzcjebvfcihiynt.supabase.co/storage/v1/object/public/base44-prod/public/42cbdff5a_Screenshot2025-08-28at44953PM.png",name:"StudyBuddy"},{url:"https://qtrypzzcjebvfcihiynt.supabase.co/storage/v1/object/public/base44-prod/public/8aee77a9c_image.png",name:"Burger Builder"},{url:"https://qtrypzzcjebvfcihiynt.supabase.co/storage/v1/object/public/base44-prod/public/de3be3bad_Mathsolver.jpeg",name:"ClayMath Solver"},{url:"https://qtrypzzcjebvfcihiynt.supabase.co/storage/v1/object/public/base44-prod/public/3649b0995_Screenshot2025-08-04at105545pm.png",name:"FormForge"}];const xA=function(){const{user:e}=oe(),[t,s]=(0,J.useSearchParams)(),[a,n]=(0,Y.useState)("new"===t.get("renderer")),[l,r]=(0,Y.useState)("false"!==t.get("lazy")),[i,o]=(0,Y.useState)(parseInt(t.get("quality")||"80",10)),[c,d]=(0,Y.useState)(parseInt(t.get("duration")||"300",10)),[m,u]=(0,Y.useState)("true"!==t.get("transition")),[x,h]=(0,Y.useState)({}),[p,g]=(0,Y.useState)(Date.now()),f=(e,a)=>{const n=new URLSearchParams(t);n.set(e,a.toString()),s(n)},v=()=>{h({}),g(Date.now()),window.location.reload()},b=(e,t)=>{const s=Date.now()-t;h(t=>(0,K.A)((0,K.A)({},t),{},{[e]:s}))};return e&&"platform_admin"===e.platform_role?(0,le.jsx)("div",{className:"min-h-screen bg-slate-50 py-8 px-4",children:(0,le.jsxs)("div",{className:"max-w-7xl mx-auto",children:[(0,le.jsx)("div",{className:"bg-gradient-to-r from-orange-500 to-orange-600 text-white rounded-lg p-6 mb-6 shadow-lg",children:(0,le.jsxs)("div",{className:"flex items-start gap-4",children:[(0,le.jsx)("div",{className:"text-4xl",children:"\u26a0\ufe0f"}),(0,le.jsxs)("div",{className:"flex-1",children:[(0,le.jsx)("h2",{className:"text-2xl font-bold mb-2",children:"First Time Testing? Read This!"}),(0,le.jsx)("p",{className:"text-orange-50 mb-3",children:"To see accurate results and avoid cached images, you MUST clear your cache first."}),(0,le.jsxs)("div",{className:"flex flex-wrap gap-3",children:[(0,le.jsx)(Hn,{onClick:v,className:"bg-white text-orange-600 hover:bg-orange-50 font-semibold",size:"lg",children:"\u{1f504} Click Here to Clear Cache & Reload"}),(0,le.jsxs)("div",{className:"flex items-center gap-2 text-orange-50 text-sm",children:[(0,le.jsx)("span",{children:"OR press:"}),(0,le.jsx)("kbd",{className:"bg-orange-700 px-2 py-1 rounded font-mono",children:"Cmd+Shift+R"}),(0,le.jsx)("span",{children:"(Mac)"}),(0,le.jsx)("kbd",{className:"bg-orange-700 px-2 py-1 rounded font-mono",children:"Ctrl+Shift+F5"}),(0,le.jsx)("span",{children:"(Windows)"})]})]})]})]})}),(0,le.jsxs)("div",{className:"mb-8",children:[(0,le.jsx)("h1",{className:"text-4xl font-bold text-slate-900 mb-2",children:"Image Rendering Test Page"}),(0,le.jsxs)("p",{className:"text-slate-600 text-lg",children:["Compare the old ",(0,le.jsx)("code",{className:"bg-slate-200 px-2 py-1 rounded",children:"img"})," tag with the new ",(0,le.jsx)("code",{className:"bg-slate-200 px-2 py-1 rounded",children:"ImageRenderer"})," component"]})]}),(0,le.jsx)(Qn,{className:"mb-8",children:(0,le.jsx)(sl,{className:"p-6",children:(0,le.jsxs)("div",{className:"space-y-6",children:[(0,le.jsxs)("div",{className:"flex items-center justify-between",children:[(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsx)("h2",{className:"text-xl font-semibold text-slate-900",children:"Rendering Mode"}),(0,le.jsx)("p",{className:"text-sm text-slate-600",children:"Switch between old and new image rendering"})]}),(0,le.jsxs)("div",{className:"flex items-center gap-4",children:[(0,le.jsx)(go,{htmlFor:"renderer-switch",className:"text-base font-medium",children:a?(0,le.jsx)(Nn,{className:"bg-green-500 hover:bg-green-600",children:"New ImageRenderer \u2728"}):(0,le.jsx)(Nn,{className:"bg-slate-500 hover:bg-slate-600",children:"Old tag"})}),(0,le.jsx)(tw,{id:"renderer-switch",checked:a,onCheckedChange:e=>{n(e),f("renderer",e?"new":"old"),h({}),g(Date.now())}})]})]}),a&&(0,le.jsxs)(le.Fragment,{children:[(0,le.jsxs)("div",{className:"border-t pt-6 space-y-4",children:[(0,le.jsxs)("div",{className:"flex items-center justify-between",children:[(0,le.jsxs)("div",{children:[(0,le.jsx)(go,{htmlFor:"lazy-switch",className:"text-base font-medium",children:"Lazy Loading"}),(0,le.jsx)("p",{className:"text-sm text-slate-600",children:"Only load images when they enter viewport"})]}),(0,le.jsx)(tw,{id:"lazy-switch",checked:l,onCheckedChange:e=>{r(e),f("lazy",e)}})]}),(0,le.jsxs)("div",{children:[(0,le.jsxs)(go,{htmlFor:"quality-slider",className:"text-base font-medium block mb-2",children:["Image Quality: ",i]}),(0,le.jsx)("input",{id:"quality-slider",type:"range",min:"20",max:"100",value:i,onChange:e=>{return t=Number(e.target.value),o(t),void f("quality",t);var t},className:"w-full"}),(0,le.jsx)("p",{className:"text-sm text-slate-600 mt-1",children:"Lower quality = smaller file size, faster loading"})]}),(0,le.jsxs)("div",{className:"flex items-center justify-between",children:[(0,le.jsxs)("div",{children:[(0,le.jsx)(go,{htmlFor:"transition-switch",className:"text-base font-medium",children:"Opacity Transition"}),(0,le.jsx)("p",{className:"text-sm text-slate-600",children:"Smooth fade between placeholder and full image"})]}),(0,le.jsx)(tw,{id:"transition-switch",checked:!m,onCheckedChange:e=>{u(!e),f("transition",e)}})]}),!m&&(0,le.jsxs)("div",{children:[(0,le.jsxs)(go,{htmlFor:"duration-slider",className:"text-base font-medium block mb-2",children:["Transition Duration: ",c,"ms"]}),(0,le.jsx)("input",{id:"duration-slider",type:"range",min:"0",max:"1000",step:"50",value:c,onChange:e=>{return t=Number(e.target.value),d(t),void f("duration",t);var t},className:"w-full"}),(0,le.jsx)("p",{className:"text-sm text-slate-600 mt-1",children:"How fast the blur-to-sharp transition happens"})]})]}),(0,le.jsxs)("div",{className:"border-t pt-6",children:[(0,le.jsx)("h3",{className:"font-semibold mb-3",children:"Features Active:"}),(0,le.jsxs)("div",{className:"flex flex-wrap gap-2",children:[(0,le.jsx)(Nn,{variant:"outline",className:"bg-blue-50 text-blue-700 border-blue-200",children:"\u2705 Progressive Loading (blur-up)"}),(0,le.jsx)(Nn,{variant:"outline",className:"bg-blue-50 text-blue-700 border-blue-200",children:"\u2705 Responsive srcset (1x, 2x, 3x)"}),(0,le.jsx)(Nn,{variant:"outline",className:"bg-blue-50 text-blue-700 border-blue-200",children:"\u2705 Automatic WebP conversion"}),l&&(0,le.jsx)(Nn,{variant:"outline",className:"bg-blue-50 text-blue-700 border-blue-200",children:"\u2705 Lazy Loading"}),!m&&(0,le.jsxs)(Nn,{variant:"outline",className:"bg-blue-50 text-blue-700 border-blue-200",children:["\u2705 Smooth transitions (",c,"ms)"]}),(0,le.jsx)(Nn,{variant:"outline",className:"bg-blue-50 text-blue-700 border-blue-200",children:"\u2705 Error handling"})]})]})]})]})})}),(0,le.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4 mb-8",children:[(0,le.jsx)(Qn,{children:(0,le.jsxs)(sl,{className:"p-4",children:[(0,le.jsx)("div",{className:"text-sm text-slate-600",children:"Total Images"}),(0,le.jsx)("div",{className:"text-2xl font-bold text-slate-900",children:uA.length})]})}),(0,le.jsx)(Qn,{children:(0,le.jsxs)(sl,{className:"p-4",children:[(0,le.jsx)("div",{className:"text-sm text-slate-600",children:"Images Loaded"}),(0,le.jsx)("div",{className:"text-2xl font-bold text-slate-900",children:Object.keys(x).length})]})}),(0,le.jsx)(Qn,{children:(0,le.jsxs)(sl,{className:"p-4",children:[(0,le.jsx)("div",{className:"text-sm text-slate-600",children:"Avg Load Time"}),(0,le.jsxs)("div",{className:"text-2xl font-bold text-slate-900",children:[Object.keys(x).length>0?Math.round(Object.values(x).reduce((e,t)=>e+t,0)/Object.values(x).length):0,"ms"]})]})})]}),(0,le.jsx)("div",{className:"bg-orange-50 border border-orange-200 rounded-lg p-4 mb-8",children:(0,le.jsxs)("div",{className:"flex items-start justify-between gap-4",children:[(0,le.jsxs)("div",{className:"flex-1",children:[(0,le.jsx)("h3",{className:"font-semibold text-orange-900 mb-2",children:"\u{1f9ea} Testing Instructions:"}),(0,le.jsxs)("ul",{className:"text-sm text-orange-800 space-y-1 list-disc list-inside",children:[(0,le.jsxs)("li",{children:[(0,le.jsx)("strong",{children:"First time:"})," Press Cmd+Shift+R (Mac) or Ctrl+Shift+F5 (Windows) to hard reload"]}),(0,le.jsx)("li",{children:"Open DevTools Network tab to see image requests"}),(0,le.jsx)("li",{children:"Toggle between old and new renderer to compare"}),(0,le.jsx)("li",{children:"Watch for blur-up effect with new renderer (small placeholder \u2192 full image)"}),(0,le.jsx)("li",{children:"Scroll down to see lazy loading in action"}),(0,le.jsx)("li",{children:"Check image URLs - new renderer adds transformation parameters"}),(0,le.jsx)("li",{children:"Compare file sizes in Network tab (WebP vs original format)"})]})]}),(0,le.jsx)(Hn,{onClick:v,variant:"outline",className:"bg-white border-orange-300 text-orange-700 hover:bg-orange-50 whitespace-nowrap",children:"\u{1f504} Clear Cache & Reload"})]})}),(0,le.jsx)("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-6",children:uA.map((e,t)=>{const s=Date.now(),n="".concat(e.url).concat(e.url.includes("?")?"&":"?","_cb=").concat(p);return(0,le.jsxs)(Qn,{className:"overflow-hidden",children:[(0,le.jsx)("div",{className:"relative aspect-video bg-slate-100",children:a?(0,le.jsx)(gl,{src:n,alt:e.name,className:"w-full h-full",objectFit:"cover",quality:i,lazy:l,transitionDuration:c,disableTransition:m,onLoad:()=>b(t,s),onError:()=>{}}):(0,le.jsx)("img",{src:n,alt:e.name,className:"w-full h-full object-cover",onLoad:()=>b(t,s),onError:()=>{}})}),(0,le.jsxs)(sl,{className:"p-4",children:[(0,le.jsx)("h3",{className:"font-medium text-slate-900 text-sm mb-2 truncate",children:e.name}),(0,le.jsxs)("div",{className:"flex items-center justify-between text-xs text-slate-600",children:[(0,le.jsxs)("span",{children:["Image ",t+1]}),x[t]&&(0,le.jsxs)(Nn,{variant:"outline",className:"text-xs",children:[x[t],"ms"]})]})]})]},t)})}),(0,le.jsxs)("div",{className:"mt-12 space-y-4",children:[(0,le.jsxs)("div",{className:"text-center text-slate-600 text-sm",children:[(0,le.jsx)("p",{children:"Open DevTools Network tab to see the difference in image requests and file sizes"}),(0,le.jsx)("p",{className:"mt-2",children:"Expected: 40-60% bandwidth reduction with ImageRenderer + WebP conversion"})]}),(0,le.jsxs)("div",{className:"bg-slate-100 border border-slate-200 rounded-lg p-4 text-sm",children:[(0,le.jsx)("h4",{className:"font-semibold text-slate-900 mb-2",children:"\u{1f4a1} URL Parameters"}),(0,le.jsx)("p",{className:"text-slate-600 mb-2",children:"Settings are saved in URL - share your configuration:"}),(0,le.jsxs)("div",{className:"space-y-1 text-slate-600 font-mono text-xs",children:[(0,le.jsxs)("div",{children:["\u2022 ",(0,le.jsx)("code",{children:"?renderer=new"})," - Use new ImageRenderer"]}),(0,le.jsxs)("div",{children:["\u2022 ",(0,le.jsx)("code",{children:"?renderer=old"})," - Use old tag (default)"]}),(0,le.jsxs)("div",{children:["\u2022 ",(0,le.jsx)("code",{children:"?lazy=true"})," - Enable lazy loading"]}),(0,le.jsxs)("div",{children:["\u2022 ",(0,le.jsx)("code",{children:"?quality=85"})," - Set image quality"]}),(0,le.jsxs)("div",{children:["\u2022 ",(0,le.jsx)("code",{children:"?transition=true"})," - Enable smooth transitions"]}),(0,le.jsxs)("div",{children:["\u2022 ",(0,le.jsx)("code",{children:"?duration=500"})," - Set transition duration (ms)"]})]}),(0,le.jsxs)("p",{className:"text-slate-600 mt-3",children:["Example: ",(0,le.jsx)("code",{className:"text-orange-600",children:"/img-test?renderer=new&quality=90&transition=true&duration=400"})]})]})]})]})}):(0,le.jsx)(Z.C5,{to:"/",replace:!0})};function hA(){const{fileId:e}=(0,Z.g)();window.location.href="".concat((0,ee.wE)(),"/api/files/").concat(e)}function pA(e){let{url:t}=e;window.location.href=t}function gA(e){let{urlChangeHandler:t}=e;const s=(0,Z.g)(),a=window.location.pathname,n=t(a,s);return n!==a&&(window.location.href=n),(0,le.jsx)("div",{children:"Loading..."})}function fA(){const{hasFlag:e}=Bg();return e("billing-page-toggle")?(0,le.jsx)(sy,{}):(0,le.jsx)(Xc,{})}const vA=[{name:"Home",url:"/",component:(0,le.jsx)(kl,{}),icon:(0,le.jsx)(Jl.A,{})},{name:"Login",url:"/login",component:(0,le.jsx)($y,{}),requiresAuth:!1,usesLayout:!1,hide:!0},{name:"Register",url:"/register",component:(0,le.jsx)(xN,{}),requiresAuth:!1,usesLayout:!1,hide:!0},{name:"VerifyEmail",url:"/verify-email",component:(0,le.jsx)(hN,{}),requiresAuth:!1,usesLayout:!1,hide:!0},{name:"ForgotPassword",url:"/forgot-password",component:(0,le.jsx)(pN,{}),requiresAuth:!1,usesLayout:!1,hide:!0},{name:"CheckEmail",url:"/check-email",component:(0,le.jsx)(gN,{}),requiresAuth:!1,usesLayout:!1,hide:!0},{name:"ResetPassword",url:"/reset-password",component:(0,le.jsx)(fN,{}),requiresAuth:!1,usesLayout:!1,hide:!0},{name:"PrivacyPolicy",url:"/privacy-policy",component:(0,le.jsx)(pA,{url:"https://base44.com/privacy-policy"}),requiresAuth:!1,hide:!0},{name:"TermsOfService",url:"/terms-of-service",component:(0,le.jsx)(pA,{url:"https://base44.com/terms-of-service"}),requiresAuth:!1,hide:!0},{name:"ResponsibleUse",url:"/responsible-use-policy",component:(0,le.jsx)(ON,{}),requiresAuth:!1,hide:!0},{name:"File",url:"/api/files/:fileId",component:(0,le.jsx)(hA,{}),requiresAuth:!1,usesLayout:!1,hide:!0},{name:"App Preview",url:"/app_preview",component:(0,le.jsx)(mA,{}),requiresAuth:!1,usesLayout:!1,hide:!0},{name:"Image Test",url:"/img-test",component:(0,le.jsx)(xA,{}),hide:!0},{name:"User Apps",url:"/user-apps/:appId/show/:pageName?",component:(0,le.jsx)(gA,{urlChangeHandler:e=>e.replace("/user-apps/","/apps/")}),icon:(0,le.jsx)(Zl.A,{}),showInMenu:!1,requiresAuth:!1},{name:"User Apps",url:"/apps",component:(0,le.jsx)($l,{}),icon:(0,le.jsx)(Zl.A,{}),children:[{name:"User App Dashboard",url:"/apps/:appId",component:(0,le.jsx)(Uj,{view:"workspace"}),icon:(0,le.jsx)(Zl.A,{}),usesLayout:!1},{name:"App Show",url:"/apps-show/:appSlug/:pageName?",component:(0,le.jsx)(gA,{urlChangeHandler:(e,t)=>{const s=t.appSlug,a=t.pageName,n=window.location.host;return"https://".concat(s,".").concat(n,"/").concat(a||"")}}),icon:(0,le.jsx)(Kl.A,{}),usesLayout:!1,requiresAuth:!1},{name:"Edit User App",url:"/apps/:appId/editor/preview/:pageName",component:(0,le.jsx)(Uj,{view:"preview"}),icon:(0,le.jsx)(Ql.A,{}),usesLayout:!1},{name:"Remix User App",url:"/remix-app/:appId",component:(0,le.jsx)(iw,{}),icon:(0,le.jsx)(Ql.A,{})},{name:"Edit User App",url:"/apps/:appId/dashboard",component:(0,le.jsx)(Uj,{view:"workspace"}),icon:(0,le.jsx)(Ql.A,{}),usesLayout:!1},{name:"Edit User App",url:"/apps/:appId/editor/preview",component:(0,le.jsx)(Uj,{view:"preview"}),icon:(0,le.jsx)(Ql.A,{}),usesLayout:!1},{name:"Edit User App",url:"/apps/:appId/editor/workspace/:workspaceView",component:(0,le.jsx)(Uj,{view:"workspace"}),icon:(0,le.jsx)(Ql.A,{}),usesLayout:!1},{name:"Create App",url:"/create-app",component:(0,le.jsx)(Wj,{}),icon:(0,le.jsx)(kt.A,{})}]},{name:"Billing",url:"/billing",component:(0,le.jsx)(fA,{}),icon:(0,le.jsx)(we.A,{}),hide:!0},{name:"Support",url:"/support",component:(0,le.jsx)(hw,{})},{name:"My Tickets",url:"/support/conversations",component:(0,le.jsx)(l_,{})},{name:"Admin Support Tickets",url:"/support/admin/conversations",component:(0,le.jsx)(y_,{}),usesLayout:!1},{name:"Admin Support Docs",url:"/support/admin/agent-backoffice",component:(0,le.jsx)(T_,{})},{name:"Admin Analytics",url:"/support/admin/analytics",component:(0,le.jsx)(yk,{})},{name:"User Management",url:"/user-management",component:(0,le.jsx)(Oy,{}),icon:(0,le.jsx)(Xl.A,{}),hide:!0},{name:"App Templates Management",url:"/app-templates-management",component:(0,le.jsx)(Dk,{}),icon:(0,le.jsx)(Xl.A,{}),hide:!0},{name:"Integration Management",url:"/integration-management",component:(0,le.jsx)(Bk,{}),icon:(0,le.jsx)(er.A,{}),hide:!0},{name:"Integrations Catalog",url:"/integrations-catalog",component:(0,le.jsx)(HN,{}),icon:(0,le.jsx)(er.A,{}),children:[{name:"Integrations Catalog Item",url:"/integrations-catalog/item/:itemId",component:(0,le.jsx)(ZN,{})},{name:"Integration Editor",url:"/integrations-catalog/editor/:itemId?",component:(0,le.jsx)(aw,{})}]},{name:"App Templates",url:"/app-templates",component:(0,le.jsx)(rw,{}),icon:(0,le.jsx)(Zl.A,{}),children:[{name:"Manage Listing",url:"/app-templates/manage-listing/:appId",component:(0,le.jsx)(Wp,{})}]},{name:"Partners Catalog",url:"/partners",component:(0,le.jsx)(cA,{}),icon:(0,le.jsx)(Xl.A,{}),children:[{name:"Partner Contact",url:"/partners/:partnerId",component:(0,le.jsx)(cA,{})}]},{name:"Partners Terms",url:"/partners/terms",component:(0,le.jsx)(dA,{}),requiresAuth:!1,hide:!0},{name:"Partner Admin",url:"/admin/partners",component:(0,le.jsx)(TC,{}),icon:(0,le.jsx)(Xl.A,{}),hide:!0},{name:"Analytics",url:"/admin/analytics",component:(0,le.jsx)(Dy,{}),icon:(0,le.jsx)(tr.A,{}),hide:!0},{name:"Stripe",url:"/integrations/stripe",component:(0,le.jsx)(LN,{}),icon:(0,le.jsx)(we.A,{}),hide:!0},{name:"Workspace Dashboard",url:"/workspace/:workspaceId",component:(0,le.jsx)(mk,{}),hide:!0},{name:"Create Workspace",url:"/create-workspace",component:(0,le.jsx)(uk,{}),hide:!0},{name:"Accept Invitation",url:"/invite/accept",component:(0,le.jsx)(xk,{}),hide:!0,usesLayout:!1,requiresAuth:!0},{name:"NotFound",url:"*",component:(0,le.jsx)(bN,{}),hide:!0,usesLayout:!1,requiresAuth:!1}];var bA=s(78602),jA=s(30772);function yA(e){let{isMobile:t=!1,onItemClick:s}=e;const a=(0,Z.Zp)(),{workspaces:n,isLoadingWorkspaces:l,activeWorkspace:r,switchActiveWorkspace:i}=ge(),o=e=>{i(e),s&&s()},c=e=>{a("/workspace/".concat(e.id)),s&&s()},d=e=>{if(e.is_personal)return!1;const t=e.user_role||e.role||"member";return["owner","admin"].includes(t)},m=()=>{a("/create-workspace"),s&&s()};return t?(0,le.jsxs)("div",{className:"p-1",children:[(0,le.jsxs)("div",{className:"flex items-center justify-between px-4 py-2",children:[(0,le.jsx)("div",{className:"text-sm font-medium text-gray-900 font-base44 p-0",children:"Workspaces"}),(n?n.filter(e=>!e.is_personal).length:0)>=3?null:(0,le.jsx)("button",{onClick:m,className:"flex items-center justify-center w-6 h-6 bg-gray-50 hover:bg-gray-100 border border-gray-200 rounded-lg transition-colors",title:"Create a Workspace",children:(0,le.jsx)(kt.A,{className:"h-3 w-3 text-gray-600"})})]}),l?(0,le.jsxs)("div",{className:"px-4 py-3 flex items-center justify-center",children:[(0,le.jsx)(Ne.A,{className:"h-4 w-4 animate-spin text-gray-400"}),(0,le.jsx)("span",{className:"ml-2 text-sm text-gray-500 font-base44",children:"Loading..."})]}):n.length>0?(0,le.jsx)("div",{className:"space-y-1",children:n.map(e=>(0,le.jsxs)("button",{onClick:()=>o(e),className:"cursor-pointer flex items-center justify-between px-4 py-4 hover:bg-gray-50 rounded-lg font-base44 w-full group ".concat((null==r?void 0:r.id)===e.id?"bg-orange-50 border-l-2 border-orange-500 text-orange-600 hover:bg-orange-300":"border-l-2 border-transparent"),children:[(0,le.jsx)("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:(0,le.jsxs)("div",{className:"min-w-0 flex-1 text-left",children:[(0,le.jsx)("div",{className:"truncate text-base font-light ".concat((null==r?void 0:r.id)===e.id?"text-orange-600":"text-gray-900"),children:e.is_personal?"My Workspace":"".concat(e.name.charAt(0).toUpperCase()+e.name.slice(1)," Workspace")}),e.domain&&!e.is_personal&&(0,le.jsx)("div",{className:"text-xs text-gray-500 truncate mt-0.5",children:e.domain})]})}),(0,le.jsx)("div",{className:"flex items-center gap-1 flex-shrink-0",children:d(e)&&(0,le.jsx)("button",{onClick:t=>{t.stopPropagation(),c(e)},className:"px-2 py-1 hover:bg-gray-200 hover:shadow-sm rounded-lg transition-all opacity-0 group-hover:opacity-100 text-xs text-gray-600 hover:text-gray-800",title:"Manage Workspace",children:"Manage"})})]},e.id))}):(0,le.jsx)("div",{className:"px-4 py-3",children:(0,le.jsx)("div",{className:"text-sm text-gray-500 text-center font-base44",children:"No workspaces found"})})]}):(0,le.jsxs)("div",{className:"p-1",children:[(0,le.jsxs)("div",{className:"flex items-center justify-between px-4 py-2",children:[(0,le.jsx)(ti,{className:"text-sm font-medium text-gray-900 font-base44 p-0",children:"Workspaces"}),(n?n.filter(e=>!e.is_personal).length:0)>=3?null:(0,le.jsx)("button",{onClick:m,className:"flex items-center justify-center w-6 h-6 bg-gray-50 hover:bg-gray-100 border border-gray-200 rounded-lg transition-colors",title:"Create a Workspace",children:(0,le.jsx)(kt.A,{className:"h-3 w-3 text-gray-600"})})]}),l?(0,le.jsxs)("div",{className:"px-4 py-3 flex items-center justify-center",children:[(0,le.jsx)(Ne.A,{className:"h-4 w-4 animate-spin text-gray-400"}),(0,le.jsx)("span",{className:"ml-2 text-sm text-gray-500 font-base44",children:"Loading..."})]}):n.length>0?(0,le.jsx)("div",{className:"space-y-1",children:n.map(e=>(0,le.jsxs)(Qr,{onClick:()=>o(e),className:"cursor-pointer flex items-center justify-between px-4 py-2 rounded-lg font-base44 group ".concat((null==r?void 0:r.id)===e.id?"bg-orange-50 border-l-2 border-orange-500 text-orange-600 hover:bg-orange-100":"border-l-2 border-transparent"),children:[(0,le.jsx)("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:(0,le.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,le.jsx)("div",{className:"truncate text-sm font-light ".concat((null==r?void 0:r.id)===e.id?"text-orange-600":"text-gray-900"),children:e.is_personal?"My Workspace":"".concat(e.name.charAt(0).toUpperCase()+e.name.slice(1)," Workspace")}),e.domain&&!e.is_personal&&(0,le.jsx)("div",{className:"text-xs text-gray-500 truncate mt-0.5",children:e.domain})]})}),(0,le.jsx)("div",{className:"flex items-center gap-1 flex-shrink-0",children:d(e)&&(0,le.jsx)("button",{onClick:t=>{t.stopPropagation(),c(e)},className:"px-2 py-1 hover:bg-gray-200 hover:shadow-sm rounded-lg transition-all opacity-0 group-hover:opacity-100 text-xs text-gray-600 hover:text-gray-800",title:"Manage Workspace",children:"Manage"})})]},e.id))}):(0,le.jsx)("div",{className:"px-4 py-3",children:(0,le.jsx)("div",{className:"text-sm text-gray-500 text-center font-base44",children:"No workspaces found"})})]})}var NA=s(42309);const wA=e=>{let{referral:t}=e;const s="published"===t.status;return(0,le.jsxs)("div",{className:"flex items-center justify-between py-1 hover:opacity-80 transition-all duration-200",style:{borderRadius:"12px",background:"rgba(103, 48, 23, 0.05)",paddingLeft:"12px",paddingRight:"12px"},children:[(0,le.jsx)("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:(0,le.jsx)("div",{className:"min-w-0 flex-1",children:(0,le.jsx)("p",{className:"text-sm font-light text-black truncate font-base44",children:t.email})})}),(0,le.jsx)("div",{className:"flex-shrink-0 ml-2",children:(0,le.jsx)("span",{className:"inline-flex items-center gap-1 px-3 py-1 rounded-full text-xs font-light font-base44 ".concat(s?"text-[#229954] border border-[#229954]":"bg-white text-black border border-slate-200"),style:s?{backgroundColor:"#E9F6EE"}:{},children:s?(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(NA.A,{className:"h-3 w-3"}),"+10"]}):"Registered"})})]})};function _A(e){let{isOpen:t,onClose:s}=e;const{user:a,reloadUser:n}=oe(),[l,r]=(0,Y.useState)((null==a?void 0:a.referral_code)||null),[i,o]=(0,Y.useState)(!1),[c,d]=(0,Y.useState)(!1),[m,u]=(0,Y.useState)(null),[x,h]=(0,Y.useState)(null),[p,g]=(0,Y.useState)(!1),[f,v]=(0,Y.useState)(!1),b=(0,Y.useRef)(!1),j=(0,Y.useRef)(null),y=(0,Y.useRef)(null),N=(0,Y.useRef)(null),w=(0,Y.useRef)(null),_=(e,t)=>{e.current&&(e.current.classList.add("show-scrollbar"),t.current&&clearTimeout(t.current),t.current=setTimeout(()=>{e.current&&e.current.classList.remove("show-scrollbar")},1e3))};(0,Y.useEffect)(()=>{const e=j.current,t=y.current,s=()=>_(j,N),a=()=>_(y,w);return e&&e.addEventListener("scroll",s,{passive:!0}),t&&t.addEventListener("scroll",a,{passive:!0}),()=>{e&&e.removeEventListener("scroll",s),t&&t.removeEventListener("scroll",a),[N,w].forEach(e=>{e.current&&clearTimeout(e.current)})}},[f,x]);const k=l?"https://app.base44.com/register?ref=".concat(l):"",C=((null==x?void 0:x.referrals)||[]).slice(0,5),A=((null==x?void 0:x.total_referrals)||0)>=5,S=(0,Y.useCallback)(async()=>{if(!p)try{g(!0);const e=await lN.getReferralStats();h(e)}catch(e){h({referrals:[],total_referrals:0,published_referrals:0})}finally{g(!1)}},[]),E=(0,Y.useCallback)(async()=>{if(!i)try{o(!0),u(null);const e=await lN.generateReferralCode();r(e),await n(),await S()}catch(e){u(e.message)}finally{o(!1)}},[]);(0,Y.useEffect)(()=>{t&&a&&!b.current&&(b.current=!0,l?S():E()),t||(b.current=!1)},[t,a,l]);const I=()=>{d(!1),u(null),v(!1),s()};return(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)("style",{jsx:!0,children:"\n .custom-scrollbar {\n scrollbar-gutter: stable;\n scrollbar-width: none;\n -ms-overflow-style: none;\n }\n .custom-scrollbar::-webkit-scrollbar {\n width: 6px;\n }\n .custom-scrollbar::-webkit-scrollbar-track {\n background: transparent;\n }\n .custom-scrollbar::-webkit-scrollbar-thumb {\n background: transparent;\n border-radius: 3px;\n }\n .custom-scrollbar.show-scrollbar {\n scrollbar-width: thin;\n }\n .custom-scrollbar.show-scrollbar::-webkit-scrollbar-track {\n background: rgba(0, 0, 0, 0.05);\n }\n .custom-scrollbar.show-scrollbar::-webkit-scrollbar-thumb {\n background: rgba(0, 0, 0, 0.3);\n }\n .custom-scrollbar.show-scrollbar::-webkit-scrollbar-thumb:hover {\n background: rgba(0, 0, 0, 0.5);\n }\n "}),(0,le.jsx)(Pa,{open:t,onOpenChange:I,children:(0,le.jsxs)(Da,{className:"font-base44 w-[90vw] max-w-[90vw] sm:w-full sm:max-w-[800px] max-h-[90vh] overflow-hidden bg-transparent border-none backdrop-blur-none relative fixed top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 p-0 [&>button]:hidden",children:[(0,le.jsxs)("div",{className:"rounded-[20px] sm:rounded-[40px] p-3 sm:p-3",style:{background:"linear-gradient(180deg, rgba(255, 255, 255, 0.60) 0%, rgba(233, 232, 248, 0.60) 106.43%), rgba(255, 255, 255, 0.10)"},children:[(0,le.jsxs)("div",{className:"rounded-[18px] sm:rounded-[40px] relative overflow-hidden flex min-h-[500px] sm:min-h-[600px]",style:{background:"linear-gradient(180deg, rgba(255, 255, 255, 0.00) 0%, #FBF3EC 100%), #FFF"},children:[!f&&(0,le.jsx)(le.Fragment,{children:(0,le.jsxs)("div",{className:"hidden sm:flex flex-col w-[270px] flex-shrink-0 rounded-tl-[36px] relative overflow-hidden",children:[(0,le.jsx)("img",{src:"/assets/invite/invite_bg.webp",alt:"Creative workspace",className:"absolute inset-0 h-full w-full object-cover rounded-tl-[36px]"}),(0,le.jsx)("div",{className:"absolute inset-0 bg-gradient-to-br from-orange-400/20 via-transparent to-orange-300/30 rounded-tl-[36px]"}),(0,le.jsx)("div",{className:"absolute bottom-0 left-0 right-0 h-2/3 bg-gradient-to-t from-orange-500/40 via-orange-400/20 to-transparent"})]})}),(0,le.jsxs)("div",{className:"flex-1 relative p-4 sm:p-0 ".concat(f?"rounded-[18px] sm:rounded-[36px]":"rounded-[18px] sm:rounded-r-[36px]"," flex flex-col h-[500px] sm:h-[600px]"),style:{background:"linear-gradient(180deg, rgba(255, 255, 255, 0.95) 0%, rgba(239, 238, 251, 0.95) 100%), #FFF"},children:[(0,le.jsx)("div",{className:"flex-shrink-0 absolute top-0 left-0 right-0 z-40",children:(0,le.jsxs)("div",{className:"flex items-center justify-between px-4 sm:px-9 pt-4 sm:pt-6",children:[f?(0,le.jsxs)("button",{onClick:()=>{v(!1)},className:"p-2 hover:bg-black/10 rounded-lg transition-all duration-200 flex items-center gap-2",title:"Back",children:[(0,le.jsx)(Cd.A,{className:"h-6 w-6 text-black"}),(0,le.jsx)("span",{className:"text-black font-base44 text-sm",children:"Back"})]}):(0,le.jsx)("div",{}),(0,le.jsx)("button",{onClick:I,className:"p-2 hover:bg-black/10 rounded-lg transition-all duration-200",title:"Close",children:(0,le.jsx)("svg",{className:"h-6 w-6 text-black",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,le.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})}),f?(0,le.jsx)(le.Fragment,{children:(0,le.jsxs)("div",{ref:j,className:"flex-1 overflow-y-auto sm:px-5 pb-5 custom-scrollbar",style:{paddingTop:"60px"},children:[(0,le.jsx)("div",{className:"mb-6",children:(0,le.jsxs)(Fa,{children:[(0,le.jsx)(za,{className:"text-left font-base44 text-2xl font-bold text-black mb-2",children:"Terms & Conditions"}),(0,le.jsx)(Ua,{className:"text-left text-sm text-black font-base44",children:"Referral program terms and conditions"})]})}),(0,le.jsxs)("div",{className:"space-y-6 text-sm",children:[(0,le.jsxs)("div",{children:[(0,le.jsx)("h4",{className:"font-semibold text-slate-800 mb-4 font-base44",children:"Eligibility"}),(0,le.jsxs)("ul",{className:"space-y-3 ml-4",children:[(0,le.jsx)("li",{className:"text-slate-700 leading-relaxed font-base44",children:"Only brand-new users can join through this referral offer. Existing accounts aren't included."}),(0,le.jsx)("li",{className:"text-slate-700 leading-relaxed font-base44",children:"We ask that you share your referral link responsibly. Posting it in irrelevant or spammy places may lead to removal from the program."})]})]}),(0,le.jsxs)("div",{children:[(0,le.jsx)("h4",{className:"font-semibold text-slate-800 mb-4 font-base44",children:"Referral Credits"}),(0,le.jsxs)("ul",{className:"list-disc list-inside ml-4 space-y-3 text-slate-700",children:[(0,le.jsx)("li",{className:"leading-relaxed font-base44",children:"You earn 10 credits when a referred friend publishes their first app"}),(0,le.jsx)("li",{className:"leading-relaxed font-base44",children:"Referred friends receive 10 bonus credits upon registration"}),(0,le.jsx)("li",{className:"leading-relaxed font-base44",children:"Maximum of 5 successful referrals per account"}),(0,le.jsx)("li",{className:"leading-relaxed font-base44",children:"Credits have no cash value and cannot be transferred"})]})]}),(0,le.jsxs)("div",{children:[(0,le.jsx)("h4",{className:"font-semibold text-slate-800 mb-4 font-base44",children:"Restrictions"}),(0,le.jsxs)("ul",{className:"list-disc list-inside ml-4 space-y-3 text-slate-700",children:[(0,le.jsx)("li",{className:"leading-relaxed font-base44",children:"Base44 reserves the right to void fraudulent referrals"}),(0,le.jsx)("li",{className:"leading-relaxed font-base44",children:"Referral codes are non-transferable"})]})]})]})]})}):(0,le.jsx)(le.Fragment,{children:(0,le.jsxs)("div",{ref:y,className:"flex-1 overflow-y-auto sm:px-9 pb-5 custom-scrollbar",children:[(0,le.jsxs)("div",{className:"relative mb-4 sm:mb-6 pt-4 sm:pt-8 max-w-sm",children:[(0,le.jsxs)(Fa,{children:[(0,le.jsxs)(za,{className:"text-left font-base44 font-normal text-black mb-1 text-xl sm:text-5xl leading-tight sm:leading-none",children:[(0,le.jsx)("span",{className:"sm:hidden",children:"Invite & Earn Credits"}),(0,le.jsxs)("span",{className:"hidden sm:inline",children:["Invite Friends &",(0,le.jsx)("br",{}),"Earn Credits"]})]}),(0,le.jsx)(Ua,{className:"text-left text-sm sm:text-md text-black mt-1 font-base44",children:"Share your link and earn 10 credits when friends publish their first app"})]}),A&&(0,le.jsx)("div",{className:"mt-3 mb-1",children:(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[(0,le.jsx)("div",{className:"text-lg",children:"\u{1f389}"}),(0,le.jsxs)("div",{children:[(0,le.jsx)("p",{className:"text-sm font-semibold text-black font-base44",children:"Amazing! You've reached the maximum referrals"}),(0,le.jsxs)("p",{className:"text-xs text-gray-600 mt-1 font-base44",children:["You can refer up to ",5," friends total",((null==x?void 0:x.total_referrals)||0)>5&&" (".concat(((null==x?void 0:x.total_referrals)||0)-5," additional won't earn credits)")]})]})]})})]}),(0,le.jsxs)("div",{className:"relative z-10",children:[(0,le.jsx)("div",{className:"mb-4",children:i||!l?(0,le.jsx)("div",{children:(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[(0,le.jsx)(hg,{className:"flex-1 h-10 rounded"}),(0,le.jsx)(hg,{className:"w-16 h-10 rounded"})]})}):m?(0,le.jsxs)("div",{className:"p-4 rounded-xl bg-red-50 border border-red-200",children:[(0,le.jsx)("p",{className:"text-sm text-red-600 font-medium font-base44",children:m}),(0,le.jsx)("button",{onClick:E,className:"mt-2 text-sm text-red-700 hover:text-red-800 underline font-medium font-base44",children:"Try again"})]}):(0,le.jsxs)("div",{className:"relative",children:[(0,le.jsxs)("div",{className:"flex items-center gap-2",children:[(0,le.jsx)("input",{type:"text",value:k,readOnly:!0,className:"flex-1 px-3 py-2 border border-[#ECEBFA] rounded-xl text-xs bg-white font-mono focus:outline-none focus:ring-1 focus:ring-black/20 focus:border-black transition-all duration-200 text-[#62748E] shadow-[0_1px_2px_0_rgba(0,0,0,0.05)]",style:{height:"40px"}}),(0,le.jsx)("button",{onClick:async()=>{if(k)try{await navigator.clipboard.writeText(k),d(!0),setTimeout(()=>d(!1),2e3)}catch(e){}},className:"px-4 py-2 bg-black text-white rounded-[12px] hover:bg-black/90 transition-all duration-200 focus:outline-none focus:ring-1 focus:ring-black/20 flex items-center gap-2 font-medium text-xs font-base44",style:{height:"40px"},title:"Copy to clipboard",children:c?(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(Ps.A,{className:"h-4 w-4"}),"Copied"]}):(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(or.A,{className:"h-4 w-4"}),"Copy"]})})]}),(0,le.jsx)("div",{className:"absolute top-full left-0 right-0 mt-2 transition-all duration-200 ".concat(c?"opacity-100 translate-y-0":"opacity-0 -translate-y-2 pointer-events-none"),children:(0,le.jsxs)("div",{className:"flex items-center gap-2 p-2 bg-emerald-50 border border-emerald-200/50 rounded-lg text-xs",children:[(0,le.jsx)(Vg.A,{className:"w-3 h-3 text-emerald-600 flex-shrink-0"}),(0,le.jsx)("p",{className:"text-emerald-700 font-medium font-base44",children:"Copied to clipboard!"})]})})]})}),(0,le.jsxs)("div",{className:"space-y-1.5",children:[(0,le.jsx)("h3",{className:"text-sm font-light text-gray-700 font-base44",children:"How it Works"}),(0,le.jsx)("div",{className:"flex flex-col",children:[{icon:Wa.A,text:"Share your unique referral link with friends"},{icon:Au.A,text:"They get 10 credits when they sign up"},{icon:Au.A,text:"You earn 10 credits when they publish their first app"}].map((e,t)=>{const s=e.icon;return(0,le.jsxs)("div",{className:"flex items-center py-0.5 rounded-lg",children:[(0,le.jsx)("div",{className:"flex-shrink-0 rounded-full",style:{display:"flex",width:"40px",height:"40px",flexDirection:"column",justifyContent:"center",alignItems:"center",gap:"10px"},children:(0,le.jsx)(s,{className:"w-5 h-5 text-[#272524]"})}),(0,le.jsx)("p",{className:"text-sm text-black font-base44",dangerouslySetInnerHTML:{__html:e.text}})]},t)})})]})]}),(C.length>0||void 0!==(null==x?void 0:x.total_referrals))&&(0,le.jsxs)("div",{children:[(0,le.jsx)("div",{className:"mb-3 mt-3",children:(0,le.jsxs)("h4",{className:"text-sm font-light text-gray-700 font-base44",children:["Your Referrals (",(null==x?void 0:x.total_referrals)||0,"/",5,")"]})}),C.length>0&&(0,le.jsx)("div",{className:"space-y-1.5",children:C.map((e,t)=>(0,le.jsx)(wA,{referral:e},t))})]})]})}),(0,le.jsx)("div",{className:"flex-shrink-0 relative border-t border-slate-300 text-center px-4 sm:px-9 py-3 sm:py-6",children:f?(0,le.jsx)("p",{className:"text-sm text-slate-700 leading-relaxed font-base44",children:"Base44 reserves the right to modify or terminate this referral program at any time. Changes will be communicated through the platform."}):(0,le.jsx)("button",{onClick:()=>{v(!0)},className:"text-sm text-black transition-colors hover:underline font-base44",children:"Terms & Conditions"})})]})," "]})," "]})," "]})})]})}var kA=s(59469),CA=s(33978);function AA(){const[e,t]=(0,Y.useState)([]),[s,a]=(0,Y.useState)(!0),[n,l]=(0,Y.useState)(null),[r,i]=(0,Y.useState)(!1),[o,c]=(0,Y.useState)(new Set),d=async()=>{try{a(!0);const e=await Ty.getChangelog();t(e),l(null)}catch(e){l(e.message)}finally{a(!1)}};(0,Y.useEffect)(()=>{d();const e=setInterval(d,12e5);return()=>clearInterval(e)},[]);const m=e.filter(e=>!e.is_seen).length;return(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)("style",{children:"\n.hover-scrollbar {\n scrollbar-width: none;\n}\n\n.hover-scrollbar::-webkit-scrollbar {\n width: 0px;\n background: transparent;\n}\n"}),(0,le.jsxs)(qr,{open:r,onOpenChange:async s=>{i(s),await Ty.markChangelogAsSeen(),t(e.map(e=>(0,K.A)((0,K.A)({},e),{},{is_seen:!0})))},children:[(0,le.jsx)(Vr,{className:"relative p-2 hover:bg-gray-100 rounded-lg transition-colors focus:outline-none",children:(0,le.jsx)("div",{className:"flex items-center justify-center p-2 hover:bg-gray-200 hover:rounded-[10px]",children:(0,le.jsxs)("div",{className:"relative",children:[(0,le.jsx)(kA.A,{size:18,className:"text-gray-800"}),m>0&&(0,le.jsx)("div",{className:"absolute -top-1 -right-1 h-2.5 w-2.5 rounded-full bg-red-500 border-2 border-gray-100"})]})})}),(0,le.jsxs)(Kr,{align:"end",className:"w-96 max-h-[80vh] overflow-hidden flex flex-col p-0 rounded-xl font-base44 shadow-sm",sideOffset:8,children:[(0,le.jsx)("div",{className:"px-4 pt-3",children:(0,le.jsx)("h3",{className:"text-[22px] font-semibold",children:"What's new"})}),(0,le.jsx)("div",{className:"overflow-y-auto flex-1 hover-scrollbar",children:s?(0,le.jsx)("div",{className:"px-4 py-8 text-center text-gray-500",children:"Loading notifications..."}):n?(0,le.jsx)("div",{className:"px-4 py-8 text-center text-red-500",children:"Failed to load notifications"}):0===e.length?(0,le.jsx)("div",{className:"px-4 py-8 text-center text-gray-500",children:"No notifications yet"}):(0,le.jsx)("div",{className:"space-y-0",children:e.map((e,t)=>(0,le.jsxs)("div",{className:"relative",children:[t>0&&(0,le.jsx)("div",{className:"border-t border-gray-100 mx-2"}),(0,le.jsx)("div",{className:"px-2 py-2",children:(0,le.jsx)("div",{className:"p-0 hover:bg-slate-50 hover:rounded-xl cursor-pointer transition-all duration-200",onClick:()=>((e,t)=>{0===t&&e.link_url&&window.open(e.link_url,"_blank")})(e,t),children:0===t?(0,le.jsxs)("div",{className:"px-2 py-2",children:[e.image_url&&(0,le.jsx)("div",{className:"w-full mb-4",children:(0,le.jsx)("img",{src:e.image_url,alt:"",className:"w-full h-48 object-cover rounded-lg"})}),(0,le.jsxs)("div",{className:"flex items-start justify-between mb-2",children:[(0,le.jsx)("h4",{className:"text-[15px] font-semibold text-gray-900",children:e.title}),!e.is_seen&&(0,le.jsx)("div",{className:"w-2 h-2 bg-orange-500 rounded-full flex-shrink-0 ml-3 mt-1"})]}),(0,le.jsxs)("div",{children:[(0,le.jsx)("p",{className:"text-[14px] text-gray-600 mb-2",children:e.content}),(0,le.jsx)("p",{className:"text-xs text-gray-400",children:(0,CA.m)(new Date(e.created_date),{addSuffix:!0})})]})]}):(0,le.jsxs)("div",{className:"px-2 py-2",children:[e.image_url&&(0,le.jsx)("div",{className:"w-full mb-4",children:(0,le.jsx)("img",{src:e.image_url,alt:"",className:"w-full h-48 object-cover rounded-lg"})}),(0,le.jsxs)("div",{className:"flex items-start justify-between mb-2",children:[(0,le.jsx)("h4",{className:"text-[15px] font-semibold text-gray-900",children:e.title}),!e.is_seen&&(0,le.jsx)("div",{className:"w-2 h-2 bg-orange-500 rounded-full flex-shrink-0 ml-3 mt-1"})]}),(0,le.jsxs)("div",{children:[(0,le.jsx)("p",{className:"text-[14px] text-gray-600 mb-1 ".concat(o.has(e.id||t)?"":"line-clamp-2"),children:e.content}),(0,le.jsx)("div",{className:"mb-2",children:(0,le.jsx)("span",{className:"text-black hover:text-gray-700 text-xs cursor-pointer font-light underline",onClick:s=>((e,t,s)=>{if(e.stopPropagation(),s>0){const e=t.id||s;c(t=>{const s=new Set;return t.has(e)||s.add(e),s})}})(s,e,t),children:o.has(e.id||t)?"Show less":"Read more"})}),(0,le.jsx)("p",{className:"text-xs text-gray-400",children:(0,CA.m)(new Date(e.created_date),{addSuffix:!0})})]})]})})})]},e.id||t))})})]})]})]})}const SA="text-gray-700 hover:text-gray-800",EA="",IA=()=>(0,le.jsx)("img",{src:"/Logo_v5.png",alt:"Base44",width:"114",height:"28"});function TA(){var e,t;const{logout:s,user:a}=oe(),n=(0,Z.Zp)(),l=(0,Z.zy)(),{workspaces:r,isLoadingWorkspaces:i,activeWorkspace:o,switchActiveWorkspace:c}=ge(),{hasFlag:d}=Bg(),[m,u]=(0,Y.useState)(!1),[x,h]=(0,Y.useState)(!1),[p,g]=(0,Y.useState)(!1),[f,v]=(0,Y.useState)(!1),b=()=>{u(!1)};(0,Y.useEffect)(()=>{!i&&r.length>0&&!o&&c(r[0])},[r,i,o,c]);const j=e=>l.pathname===e,y=[{key:"settings",icon:(0,le.jsx)(vm.A,{size:18,className:"mr-2 font-base44 text-gray-800"}),label:"Settings",onClick:()=>g(!0)},{key:"referrals",icon:(0,le.jsx)(Au.A,{size:18,className:"mr-2 font-base44 text-gray-800"}),label:"Refer Friends",onClick:()=>v(!0)},{key:"billing",icon:(0,le.jsx)(we.A,{size:18,className:"mr-2 font-base44 text-gray-800"}),label:"Billing",onClick:()=>{tt("User Clicked Billing",{source:"top_bar_user_menu",destination:"/billing"}),ht({user_id:(null==a?void 0:a.id)||null,app_id:null,conversation_id:null},{cta:"billing",origin:"top_bar_user_menu",target_route:"/billing"}),n("/billing")}}],N=[{key:"affiliates",icon:(0,le.jsx)(bA.A,{size:18,className:"mr-2 font-base44 text-gray-800"}),label:"Become an Affiliate!",onClick:()=>window.open("https://base44.com/affiliates","_blank"),className:"text-black font-base44 font-light"},{key:"logout",icon:(0,le.jsx)(Iu.A,{size:18,className:"mr-2 font-base44 text-gray-800"}),label:"Sign Out",onClick:()=>{s(),n("/login")},className:"text-black font-base44 font-light"}],w=[{href:"/apps",external:!1,label:"Apps"},{href:"/integrations-catalog",external:!1,label:"Integrations"},{href:"/app-templates",external:!1,label:"App Templates"},{href:"/partners",external:!1,label:"Hire A Partner"},{href:"https://base44.com/affiliates",external:!0,label:"Affiliates"},{href:"https://app.base44.com/support",external:!0,label:"Docs & Support"}],_=[{href:"https://discord.gg/ThpYPZpVts",title:"Join our Discord",icon:(0,le.jsx)("svg",{className:"h-7 w-7",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:(0,le.jsx)("path",{d:"M18.8943 4.34399C17.5183 3.71467 16.057 3.256 14.5317 3C14.3396 3.33067 14.1263 3.77866 13.977 4.13067C12.3546 3.89599 10.7439 3.89599 9.14391 4.13067C8.99457 3.77866 8.77056 3.33067 8.58922 3C7.05325 3.256 5.59191 3.71467 4.22552 4.34399C1.46286 8.41865 0.716188 12.3973 1.08952 16.3226C2.92418 17.6559 4.69486 18.4666 6.4346 19C6.86126 18.424 7.24527 17.8053 7.57594 17.1546C6.9466 16.92 6.34927 16.632 5.77327 16.2906C5.9226 16.184 6.07194 16.0667 6.21061 15.9493C9.68793 17.5387 13.4543 17.5387 16.889 15.9493C17.0383 16.0667 17.177 16.184 17.3263 16.2906C16.7503 16.632 16.153 16.92 15.5236 17.1546C15.8543 17.8053 16.2383 18.424 16.665 19C18.4036 18.4666 20.185 17.6559 22.01 16.3226C22.4687 11.7787 21.2836 7.83202 18.8943 4.34399ZM8.05593 13.9013C7.01058 13.9013 6.15725 12.952 6.15725 11.7893C6.15725 10.6267 6.98925 9.67731 8.05593 9.67731C9.11191 9.67731 9.97588 10.6267 9.95454 11.7893C9.95454 12.952 9.11191 13.9013 8.05593 13.9013ZM15.065 13.9013C14.0196 13.9013 13.1652 12.952 13.1652 11.7893C13.1652 10.6267 13.9983 9.67731 15.065 9.67731C16.121 9.67731 16.985 10.6267 16.9636 11.7893C16.9636 12.952 16.1317 13.9013 15.065 13.9013Z",stroke:"currentColor",strokeWidth:"1.5",strokeLinejoin:"round"})})},{href:"https://x.com/base_44",title:"Follow on X",icon:(0,le.jsx)(Va.A,{size:26})},{href:"https://www.linkedin.com/company/106589953",title:"Follow on LinkedIn",icon:(0,le.jsx)(qa.A,{size:26})}];return(0,le.jsxs)("header",{className:"sticky top-0 z-50",children:[(0,le.jsx)("div",{className:"mx-auto px-4 sm:px-6 lg:px-8",children:(0,le.jsxs)("div",{className:"flex items-center justify-between h-16",children:[(0,le.jsxs)("div",{className:"flex items-center",children:[(0,le.jsx)(J.Link,{to:"/",children:(0,le.jsx)(IA,{})}),(0,le.jsx)("nav",{className:"hidden md:flex items-center ml-6 sm:ml-8 space-x-4 sm:space-x-6",children:w.map((e,t)=>e.external?(0,le.jsxs)("a",{href:e.href,target:"_blank",rel:"noopener noreferrer",className:"relative flex font-base44 items-center text-sm font-medium text-gray-700 py-2 transition-colors duration-200 hover:text-orange-500 group",children:[e.icon,e.label,(0,le.jsx)("span",{className:"absolute bottom-1 left-0 w-full h-0.5 bg-orange-500 transform scale-x-0 transition-transform duration-200 group-hover:scale-x-100"})]},t):(0,le.jsxs)(J.Link,{to:e.href,className:"relative flex font-base44 items-center text-sm font-medium py-2 transition-colors duration-200 group ".concat(j(e.href)?"text-orange-500":"text-gray-700 hover:text-orange-500"),children:[e.icon,e.label,(0,le.jsx)("span",{className:"absolute bottom-1 left-0 w-full h-0.5 bg-orange-500 transform transition-transform duration-200 ".concat(j(e.href)?"scale-x-100":"scale-x-0 group-hover:scale-x-100")})]},t))})]}),(0,le.jsxs)("div",{className:"flex items-center",children:[(0,le.jsxs)("div",{className:"hidden md:flex items-center mr-2",children:[(0,le.jsx)(AA,{}),(0,le.jsx)("button",{onClick:()=>v(!0),className:"".concat(SA," ").concat(EA," p-2 hover:bg-gray-200 hover:rounded-[10px]"),title:"Refer Friends",children:(0,le.jsx)(Au.A,{size:20})})]}),(0,le.jsxs)("div",{className:"flex items-center font-base44",children:[(0,le.jsx)("div",{className:"hidden md:block",children:(0,le.jsxs)(qr,{children:[(0,le.jsx)(Vr,{className:"outline-none",children:(0,le.jsx)("div",{className:"flex items-center gap-2",children:(0,le.jsxs)("div",{className:"".concat(SA," ").concat(EA," cursor-pointer relative"),children:[(0,le.jsx)(gx,{}),o&&!o.is_personal&&(0,le.jsx)("div",{className:"absolute -bottom-1 -right-1 w-3 h-3 bg-orange-500 border-2 border-white rounded-full"})]})})}),(0,le.jsxs)(Kr,{align:"end",className:"w-64 p-0 shadow-lg border-none rounded-lg min-w-[128px]",children:[a&&(0,le.jsxs)("div",{className:"px-4 py-3 border-b border-slate-100 font-base44",children:[(0,le.jsx)("div",{className:"font-medium",children:null===(e=a.full_name)||void 0===e?void 0:e.split(" ").map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(" ")}),(0,le.jsx)("div",{className:"text-xs text-muted-foreground truncate mt-0.5",children:a.email})]}),(0,le.jsx)("div",{className:"p-1",children:y.map(e=>(0,le.jsxs)(Qr,{onClick:e.onClick,className:"cursor-pointer flex items-center px-4 py-2 hover:bg-slate-50 font-base44",children:[e.icon,(0,le.jsx)("span",{children:e.label})]},e.key))}),(0,le.jsx)(si,{}),(0,le.jsx)(yA,{}),(0,le.jsx)(si,{}),(0,le.jsx)("div",{className:"p-1",children:N.map(e=>(0,le.jsxs)(Qr,{onClick:e.onClick,className:"cursor-pointer flex items-center px-4 py-2 hover:bg-slate-50 ".concat("logout"===e.key?"text-red-600 hover:text-red-700":e.className||""),children:["logout"===e.key?(0,le.jsx)(Iu.A,{size:18,className:"mr-2 font-base44"}):e.icon,(0,le.jsx)("span",{children:e.label})]},e.key))})]})]})}),(0,le.jsxs)("div",{className:"md:hidden",children:[(0,le.jsx)("button",{onClick:()=>h(!0),className:"outline-none",children:(0,le.jsx)("div",{className:"flex items-center gap-2",children:(0,le.jsxs)("div",{className:"".concat(SA," ").concat(EA," cursor-pointer relative"),children:[(0,le.jsx)(gx,{}),o&&!o.is_personal&&(0,le.jsx)("div",{className:"absolute -bottom-1 -right-1 w-3 h-3 bg-orange-500 border-2 border-white rounded-full"})]})})}),(0,le.jsx)(tp,{open:x,onOpenChange:h,children:(0,le.jsx)(ip,{side:"bottom",className:"h-[90vh] max-h-[600px] p-0 rounded-t-3xl border-t border-gray-200",children:(0,le.jsxs)("div",{className:"flex flex-col h-full",children:[(0,le.jsx)("div",{className:"flex justify-center pt-3 pb-2",children:(0,le.jsx)("div",{className:"w-12 h-1 bg-gray-300 rounded-full"})}),a&&(0,le.jsx)("div",{className:"px-6 py-6 border-b border-gray-100",children:(0,le.jsxs)("div",{className:"flex items-center space-x-4",children:[(0,le.jsxs)("div",{className:"relative",children:[(0,le.jsx)(gx,{size:"lg"}),o&&!o.is_personal&&(0,le.jsx)("div",{className:"absolute -bottom-1 -right-1 w-4 h-4 bg-orange-500 border-2 border-white rounded-full"})]}),(0,le.jsxs)("div",{children:[(0,le.jsx)("div",{className:"font-semibold text-lg text-gray-900 font-base44",children:null===(t=a.full_name)||void 0===t?void 0:t.split(" ").map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(" ")}),(0,le.jsx)("div",{className:"text-sm text-gray-500 mt-1",children:a.email})]})]})}),(0,le.jsxs)("div",{className:"flex-1 overflow-y-auto scrollbar-auto-hide",children:[(0,le.jsx)("div",{className:"py-2",children:y.map(e=>(0,le.jsxs)("button",{onClick:()=>{e.onClick(),h(!1)},className:"w-full flex items-center px-6 py-2 hover:bg-gray-50 transition-colors font-base44",children:[(0,le.jsx)("span",{className:"text-gray-600",children:e.icon}),(0,le.jsx)("span",{className:"ml-3 text-base font-medium text-gray-900",children:e.label})]},e.key))}),(0,le.jsx)("div",{className:"border-t border-gray-100 py-2",children:(0,le.jsx)(yA,{isMobile:!0,onItemClick:()=>h(!1)})}),(0,le.jsx)("div",{className:"border-t border-gray-100 py-2",children:N.map(e=>(0,le.jsxs)("button",{onClick:()=>{e.onClick(),h(!1)},className:"w-full flex items-center px-6 py-2 hover:bg-gray-50 transition-colors font-base44 ".concat("logout"===e.key?"text-red-600":"text-gray-900"),children:[(0,le.jsx)("span",{className:"logout"===e.key?"text-red-600":"text-gray-600",children:"logout"===e.key?(0,le.jsx)(Iu.A,{size:18,className:"mr-2 font-base44"}):e.icon}),(0,le.jsx)("span",{className:"ml-3 text-base font-medium ".concat("logout"===e.key?"text-red-600":"text-gray-900"),children:e.label})]},e.key))})]})]})})})]}),(0,le.jsx)("div",{className:"md:hidden ml-4 flex items-center",children:(0,le.jsxs)(tp,{open:m,onOpenChange:u,children:[(0,le.jsx)(sp,{asChild:!0,children:(0,le.jsx)("button",{className:"".concat(SA," ").concat(EA," flex items-center justify-center"),children:(0,le.jsx)(jA.A,{size:24})})}),(0,le.jsx)(ip,{side:"right",className:"w-[80%] sm:w-[350px] p-0",children:(0,le.jsxs)("div",{className:"flex flex-col h-full",children:[(0,le.jsx)("div",{className:"flex-1 px-6 py-8",children:(0,le.jsx)("nav",{className:"space-y-1",children:w.map((e,t)=>e.external?(0,le.jsx)("a",{href:e.href,target:"_blank",rel:"noopener noreferrer",className:"block py-4 min-h-[44px] flex items-center text-lg font-medium text-gray-700 hover:text-orange-500 transition-colors",onClick:b,children:e.label},t):(0,le.jsx)(J.Link,{to:e.href,className:"py-4 min-h-[44px] flex items-center text-lg font-medium text-gray-700 hover:text-orange-500 transition-colors",onClick:b,children:e.label},t))})}),(0,le.jsx)("div",{className:"px-6 py-8 border-t border-gray-100",children:(0,le.jsx)("div",{className:"flex justify-center space-x-8",children:_.map((e,t)=>(0,le.jsx)("a",{href:e.href,target:"_blank",rel:"noopener noreferrer",className:"text-gray-600 hover:text-orange-500 transition-colors",title:e.title,"aria-label":e.title,children:e.icon},t))})})]})})]})})]})]})]})}),(0,le.jsx)(Sx,{isOpen:p,onClose:()=>g(!1)}),(0,le.jsx)(_A,{isOpen:f,onClose:()=>v(!1)})]})}const PA=e=>{let{children:t}=e;return(0,le.jsxs)(St,{children:[(0,le.jsx)(Bf,{}),(0,le.jsx)("div",{className:"flex flex-col h-screen relative overflow-hidden",style:{background:"linear-gradient(148deg, rgba(242, 225, 208, 0.30) 3.86%, rgba(227, 232, 241, 0.30) 100%), #F8FAFC"},children:(0,le.jsxs)("div",{className:"flex flex-col h-full w-full relative z-10",children:[(0,le.jsx)(TA,{}),(0,le.jsx)("div",{className:"flex-1 overflow-auto",children:(0,le.jsx)("main",{className:"w-full h-full",children:t})})]})})]})};var LA=s(39330),OA=s(15441);const RA=(0,Y.createContext)();class MA extends Q.y{getBaseURL(){return"/apps"}getCurrentUser(e){return this.axios.get("/".concat(e,"/entities/User/me"))}}const DA=new MA,FA=e=>{let{children:t,appId:s}=e;const[a,n]=(0,Y.useState)(null),[l,r]=(0,Y.useState)(!1),[i,o]=(0,Y.useState)(!0),[c,d]=(0,Y.useState)(null),[m,u]=(0,Y.useState)(null);(0,Y.useEffect)(()=>{const e=(0,ne.VO)(!0);if(e)(0,ne.O5)(e),u("platform"),h();else{const e=ne.b3.getSSOTokens();e&&e.access_token?(d(e),u("sso"),ne.b3.setSSOTokens({sso_access_token:e.access_token,sso_token_type:e.token_type,sso_expires_at:e.expires_at,sso_scope:e.scope,sso_provider:e.provider,sso_id_token:e.id_token}),o(!1)):o(!1)}const t=ne.b3.addListener((e,t)=>{if("sso_tokens_updated"===e){const e=t.tokens;d(e);!(0,ne.VO)(!1)&&e&&e.access_token&&u("sso")}else"sso_tokens_cleared"===e&&(d(null),"sso"===m&&(u(null),r(!1),n(null)))});return()=>{t()}},[]);const x=()=>{(0,ne.QF)(),n(null),r(!1),o(!1),d(null),u(null),ne.b3.clearSSOTokens()},h=async()=>{try{o(!0);const e=await DA.getCurrentUser(s);return window.FS&&window.FS("setIdentity",{uid:e.id,properties:{displayName:e.full_name||e.email,email:e.email}}),n(e),r(!0),o(!1),e}catch(e){o(!1),x()}},p=()=>c||ne.b3.getSSOTokens();return(0,le.jsx)(RA.Provider,{value:{user:a,isAuthenticated:l,logout:function(){let e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];if(x(),r(!1),n(null),e){const e=encodeURIComponent(window.location.href);window.location.href="/login?from_url="+e}},isLoadingAuth:i,updateUser:e=>{n(e)},ssoTokens:c,authMethod:m,loginWithSSO:function(){let e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];const t=window.location.href,a="/api/apps/".concat(s,"/auth/sso/login?from_url=").concat(encodeURIComponent(t),"&include_external_tokens=").concat(e);window.location.href=a},getSSOTokens:p,getSSOAuthHeader:()=>{const e=p();return e&&e.access_token?{Authorization:"".concat(e.token_type," ").concat(e.access_token)}:null},fetchWithSSO:async function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return ne.b3.fetchWithSSO(e,t)},clearSSOTokens:()=>{ne.b3.clearSSOTokens(),d(null)}},children:t})},BA=()=>(0,Y.useContext)(RA);async function zA(e,t){const s=(0,ae.Ay)("https://base44.app/api"+"/apps/".concat(e,"/integration-endpoints"),{"X-App-Id":e},!0,!0),a=await s.get("/schema");let n={};return(a.installed_packages||a).forEach(e=>{n[e.package_name]=function(e,t,s){const a={};return t.endpoints.forEach(n=>{a[n.name]=async a=>{if("create_checkout_session"===n.name&&window.parent!==window&&alert("Note - you're creating a stripe checkout session, but stripe does not allow this to be done inside an iframe. Please use the publish button to test the checkout flow."),"string"==typeof a)throw new Error("Integration ".concat(n.name," must receive an object with named parameters, received: ").concat(a));try{let s,l;a instanceof FormData||a&&Object.values(a).some(e=>e instanceof File)?(s=new FormData,Object.keys(a).forEach(e=>{a[e]instanceof File?s.append(e,a[e],a[e].name):"object"==typeof a[e]&&null!==a[e]?s.append(e,JSON.stringify(a[e])):s.append(e,a[e])}),l="multipart/form-data"):(s=a,l="application/json");const r="Core"===t.package_name?"/Core/".concat(n.name):"/".concat(t.package_name,"/").concat(n.name),i=e.post(r,s||a,{headers:{"Content-Type":l}});return await i}catch(i){var l,r;throw s("Error calling integration ".concat(n.name,": ").concat((null===(l=i.response)||void 0===l||null===(r=l.data)||void 0===r?void 0:r.detail)||i.message),"When using the app, the following integration call failed:\ninput parameters:\n".concat(JSON.stringify(a,null,2)),null,i),i}}}),a}(s,e,t)}),n.getMissingPackages=()=>a.missing_packages||[],n}function UA(e,t,s){class a extends Q.y{getBaseURL(){return"https://base44.app/api"+"/apps/".concat(e)}inviteUser(e,t){return this.axios.post("/users/invite-user",{user_email:e,role:t})}getMyUserInfo(){return this.axios.get("/entities/User/me")}updateMyUserData(e){return this.axios.put("/entities/User/me",e)}async logout(){s.logout(!1),window.location.reload()}async login(){const t=window.location.href,s="".concat((0,ee.Zk)(),"/apps/auth/login?from_url=").concat(t,"&app_id=").concat(e);window.location.href=s}async loginWithRedirect(e){const t=window.location.href.substring(0,window.location.href.lastIndexOf("/")+1);window.location.href="".concat(t,"login?from_url=").concat(encodeURIComponent(e))}isUserAuthenticated(){return s.isUserAuthenticated()}register(e){return this.axios.post("/auth/register",e)}verifyOtp(e,t){return this.axios.post("/auth/verify-otp",{email:e,otp_code:t})}resendOtp(e){return this.axios.post("/auth/resend-otp",{email:e})}loginViaUsernamePassword(e,t){return this.axios.post("/auth/login",{email:e,password:t})}resetPasswordRequest(e){return this.axios.post("/auth/reset-password-request",{email:e},{headers:{"X-Origin-Host":window.location.hostname}})}resetPassword(e,t){return this.axios.post("/auth/reset-password",{reset_token:e,new_password:t})}changePassword(e,t,s){return this.axios.post("/auth/change-password",{user_id:e,current_password:t,new_password:s})}}return new a(t)}async function WA(e){const t=(0,ae.Ay)("https://base44.app/api/apps/public",{"X-App-Id":e.id,"X-App-Slug":e.slug});if(!e.id&&!e.slug)throw new Error("Either id or slug must be provided");let s;s=e.slug?await t.get("/prod/by-slug/".concat(e.slug)):await t.get("/prod/by-id/".concat(e.id));const a=ft(),n={};n["api/base44Client.js"]="import { createClient } from '@base44/sdk';\n\nexport const base44 = createClient({\n appId: \"".concat(s.id,'",\n serverUrl: "').concat("https://base44.app",'",\n functionsVersion: "').concat(a,'"\n});\n');const l=(t,a,n,l)=>{let r=n;if(a&&"string"==typeof a){const e=a.match(/at\s+(\w+)\s+/);if(e&&e[1]){const t=e[1];if(s.components&&s.components[t])r=t;else if(s.pages&&s.pages[t])r=t;else{for(const e in s.components||{})if(s.components[e].includes("function ".concat(t))){r=e;break}for(const e in s.pages||{})if(s.pages[e].includes("function ".concat(t))){r=e;break}}}}e.onError(t,a,r,l)},r=UA(s.id,l,e.authProps),i=bt(s,l,r),o=await zA(s.id,l),c=xf(s,l),d=Yv(s.id,void 0,l);return{appId:s.id,files:(0,K.A)((0,K.A)({},s),{},{coreFiles:n}),entities:i,integrations:o,functions:c,users:r,agents:d,getCurrentPage:()=>function(e){let t=window.location.pathname;t.endsWith("/")&&(t=t.slice(0,-1));let s=t.split("/").pop();return s.includes("?")&&(s=s.split("?")[0]),Object.keys(e.pages).map(e=>e.toLowerCase()).includes(s.toLowerCase())?{name:s,code:e.pages[s]}:s===e.slug||s===e.id||"preview"===s||""===s?{name:e.main_page,code:e.pages[e.main_page]}:null}(s),createPageUrl:(e,t)=>((e,t,s)=>{const a=window.location.hostname;return!["localhost","base44.com","base44.app","app.base44.com","base44.onrender.com","apper-test.onrender.com","beta-base44.onrender.com","base44.io","ba11.me","ba22.me","ba33.me"].includes(a)||a.startsWith("app--")||a.startsWith("preview--")?s&&"object"==typeof s?"/".concat(t,"?").concat(Object.keys(s).map(e=>"".concat(e,"=").concat(s[e])).join("&")):s&&"string"==typeof s?s.startsWith("?")?"/".concat(t).concat(s):"/".concat(t,"?").concat(s):"/".concat(t):s&&"object"==typeof s?"/apps-show/".concat(e.slug,"/").concat(t,"?").concat(Object.keys(s).map(e=>"".concat(e,"=").concat(s[e])).join("&")):s&&"string"==typeof s?s.startsWith("?")?"/apps-show/".concat(e.slug,"/").concat(t).concat(s):"/apps-show/".concat(e.slug,"/").concat(t,"?").concat(s):"/apps-show/".concat(e.slug,"/").concat(t)})(s,e,t),options:(0,K.A)((0,K.A)({},e),{},{onError:l})}}var qA=s(37906);function VA(e){let t=!1;function s(e){!function(e){if(_m.isJSXExpressionContainer(e)){const t=e.expression;if(_m.isJSXEmptyExpression(t))return!1;if(!_m.isLiteral(t))return!0}if(_m.isTemplateLiteral(e)&&e.expressions.length>0)return!0;if(_m.isMemberExpression(e))return!0;if(_m.isCallExpression(e))return!0;if(_m.isConditionalExpression(e))return!0;if(_m.isIdentifier(e)&&["props","state","data","item","value","text","content"].some(t=>e.name.includes(t)))return!0;return!1}(e)?Object.keys(e).forEach(t=>{const a=e[t];Array.isArray(a)?a.forEach(e=>{e&&"object"==typeof e&&e.type&&s(e)}):a&&"object"==typeof a&&a.type&&s(a)}):t=!0}return e.children.forEach(e=>{t||s(e)}),t}function HA(e,t){const s=function(e,t){e.includes(".")&&(e=e.split(".")[0]);try{const s=(0,ym.parse)(t,{sourceType:"module",plugins:["jsx","typescript","decorators-legacy","classProperties","objectRestSpread","functionBind","exportDefaultFrom","exportNamespaceFrom","dynamicImport","nullishCoalescingOperator","optionalChaining","asyncGenerators","bigInt","optionalCatchBinding","throwExpressions"]});return(0,Nm.default)(s,{JSXElement(t){var s;const a=t.node,n=a.openingElement;if(_m.isJSXFragment(a))return;if(n.attributes.some(e=>_m.isJSXAttribute(e)&&_m.isJSXIdentifier(e.name)&&"data-source-location"===e.name.name))return;const{line:l,column:r}=(null===(s=n.loc)||void 0===s?void 0:s.start)||{line:1,column:0},i=_m.jsxAttribute(_m.jsxIdentifier("data-source-location"),_m.stringLiteral("".concat(e,":").concat(l,":").concat(r))),o=VA(a),c=_m.jsxAttribute(_m.jsxIdentifier("data-dynamic-content"),_m.stringLiteral(o?"true":"false"));n.attributes.unshift(i,c)}}),{code:(0,wm.default)(s,{retainLines:!0,compact:!1,concise:!1}).code,success:!0}}catch(s){return{code:t,success:!1,error:s instanceof Error?s.message:"Unknown error"}}}(e,t);return s.code}function YA(){const e="preview_";return{getItem:t=>localStorage.getItem(e+t),setItem:(t,s)=>localStorage.setItem(e+t,s),removeItem:t=>localStorage.removeItem(e+t)}}function GA(e){(e.startsWith("./")||e.startsWith("@/"))&&(e=e.substring(2));const t=e.split("/"),s=[];for(const n of t)".."===n?s.pop():"."!==n&&s.push(n);let a=s.join("/");return/\.\w+$/.test(a)||(a+=".js"),a}function $A(e,t){let s=arguments.length>2&&void 0!==arguments[2]&&arguments[2];const a={get(t,a){if(!t.hasOwnProperty(a)&&"PropTypes"!==a&&"__esModule"!==a&&a.charAt(0)===a.charAt(0).toUpperCase()){if("function"==typeof t&&a.charAt(0)===a.charAt(0).toUpperCase())return t;if(!s&&a===e.split("/").pop().split(".")[0]&&t.default)return t.default;throw new Error("'".concat(a,"' does not exist in module: ").concat(e))}return t[a]}};return new Proxy(t,a)}function JA(e,t,s){try{const a=crypto.randomUUID?crypto.randomUUID():Date.now().toString();window.parent.postMessage({type:"console-log",logId:a,data:{message:"object"==typeof e?JSON.stringify(e):e,severity:t,component:s}},"*")}catch(a){}}function ZA(e,t){const s="[".concat(e,"]");return{log:function(){for(var t=arguments.length,a=new Array(t),n=0;n"object"==typeof e?JSON.stringify(e):String(e)).join(" "),"log",e)},error:function(){for(var a=arguments.length,n=new Array(a),l=0;le instanceof Error),i=n.map(e=>(null==e?void 0:e.message)||(null==e?void 0:e.toString())).join(" - "),o={title:i,details:i,originalError:r,componentName:e};t(o.title,o.details,o.componentName,o.originalError),JA(i,"error",e)},warn:function(){for(var t=arguments.length,a=new Array(t),n=0;n"object"==typeof e?JSON.stringify(e):String(e)).join(" "),"warn",e)}}}var KA=s(84079),QA=s(94048),XA=s(93204),eS=s(86991),tS=s(79476),sS=s(95670),aS=s(59019),nS=s(2527),lS=s(99603),rS=s(65604),iS=(s(55392),s(56687)),oS=s(39040);const cS=["className"],dS=["className","children"],mS=["className","children"],uS=oS.bL,xS=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,cS);return(0,le.jsx)(oS.q7,(0,K.A)({ref:t,className:Pe("border-b",s)},a))});xS.displayName="AccordionItem";const hS=Y.forwardRef((e,t)=>{let{className:s,children:a}=e,n=(0,Se.A)(e,dS);return(0,le.jsx)(oS.Y9,{className:"flex",children:(0,le.jsxs)(oS.l9,(0,K.A)((0,K.A)({ref:t,className:Pe("flex flex-1 items-center justify-between py-4 font-medium transition-all hover:underline [&[data-state=open]>svg]:rotate-180",s)},n),{},{children:[a,(0,le.jsx)(Is.A,{className:"h-4 w-4 shrink-0 transition-transform duration-200"})]}))})});hS.displayName=oS.l9.displayName;const pS=Y.forwardRef((e,t)=>{let{className:s,children:a}=e,n=(0,Se.A)(e,mS);return(0,le.jsx)(oS.UC,(0,K.A)((0,K.A)({ref:t,className:"overflow-hidden text-sm transition-all data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down"},n),{},{children:(0,le.jsx)("div",{className:Pe("pb-4 pt-0",s),children:a})}))});pS.displayName=oS.UC.displayName;const gS=s(61980).b;var fS=s(55421);const vS=["orientation","opts","setApi","plugins","className","children"],bS=["className"],jS=["className"],yS=["className","variant","size"],NS=["className","variant","size"],wS=Y.createContext(null);function _S(){const e=Y.useContext(wS);if(!e)throw new Error("useCarousel must be used within a ");return e}const kS=Y.forwardRef((e,t)=>{let{orientation:s="horizontal",opts:a,setApi:n,plugins:l,className:r,children:i}=e,o=(0,Se.A)(e,vS);const[c,d]=(0,fS.A)((0,K.A)((0,K.A)({},a),{},{axis:"horizontal"===s?"x":"y"}),l),[m,u]=Y.useState(!1),[x,h]=Y.useState(!1),p=Y.useCallback(e=>{e&&(u(e.canScrollPrev()),h(e.canScrollNext()))},[]),g=Y.useCallback(()=>{null==d||d.scrollPrev()},[d]),f=Y.useCallback(()=>{null==d||d.scrollNext()},[d]),v=Y.useCallback(e=>{"ArrowLeft"===e.key?(e.preventDefault(),g()):"ArrowRight"===e.key&&(e.preventDefault(),f())},[g,f]);return Y.useEffect(()=>{d&&n&&n(d)},[d,n]),Y.useEffect(()=>{if(d)return p(d),d.on("reInit",p),d.on("select",p),()=>{null==d||d.off("select",p)}},[d,p]),(0,le.jsx)(wS.Provider,{value:{carouselRef:c,api:d,opts:a,orientation:s||("y"===(null==a?void 0:a.axis)?"vertical":"horizontal"),scrollPrev:g,scrollNext:f,canScrollPrev:m,canScrollNext:x},children:(0,le.jsx)("div",(0,K.A)((0,K.A)({ref:t,onKeyDownCapture:v,className:Pe("relative",r),role:"region","aria-roledescription":"carousel"},o),{},{children:i}))})});kS.displayName="Carousel";const CS=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,bS);const{carouselRef:n,orientation:l}=_S();return(0,le.jsx)("div",{ref:n,className:"overflow-hidden",children:(0,le.jsx)("div",(0,K.A)({ref:t,className:Pe("flex","horizontal"===l?"-ml-4":"-mt-4 flex-col",s)},a))})});CS.displayName="CarouselContent";const AS=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,jS);const{orientation:n}=_S();return(0,le.jsx)("div",(0,K.A)({ref:t,role:"group","aria-roledescription":"slide",className:Pe("min-w-0 shrink-0 grow-0 basis-full","horizontal"===n?"pl-4":"pt-4",s)},a))});AS.displayName="CarouselItem";const SS=Y.forwardRef((e,t)=>{let{className:s,variant:a="outline",size:n="icon"}=e,l=(0,Se.A)(e,yS);const{orientation:r,scrollPrev:i,canScrollPrev:o}=_S();return(0,le.jsxs)(Yt,(0,K.A)((0,K.A)({ref:t,variant:a,size:n,className:Pe("absolute h-8 w-8 rounded-full","horizontal"===r?"-left-12 top-1/2 -translate-y-1/2":"-top-12 left-1/2 -translate-x-1/2 rotate-90",s),disabled:!o,onClick:i},l),{},{children:[(0,le.jsx)(Cd.A,{className:"h-4 w-4"}),(0,le.jsx)("span",{className:"sr-only",children:"Previous slide"})]}))});SS.displayName="CarouselPrevious";const ES=Y.forwardRef((e,t)=>{let{className:s,variant:a="outline",size:n="icon"}=e,l=(0,Se.A)(e,NS);const{orientation:r,scrollNext:i,canScrollNext:o}=_S();return(0,le.jsxs)(Yt,(0,K.A)((0,K.A)({ref:t,variant:a,size:n,className:Pe("absolute h-8 w-8 rounded-full","horizontal"===r?"-right-12 top-1/2 -translate-y-1/2":"-bottom-12 left-1/2 -translate-x-1/2 rotate-90",s),disabled:!o,onClick:i},l),{},{children:[(0,le.jsx)(ha.A,{className:"h-4 w-4"}),(0,le.jsx)("span",{className:"sr-only",children:"Next slide"})]}))});ES.displayName="CarouselNext";var IS=s(21984);const TS=["className","inset","children"],PS=["className"],LS=["className"],OS=["className","inset"],RS=["className","children","checked"],MS=["className","children"],DS=["className","inset"],FS=["className"],BS=["className"],zS=IS.bL,US=IS.l9,WS=IS.YJ,qS=IS.ZL,VS=IS.Pb,HS=IS.z6,YS=Y.forwardRef((e,t)=>{let{className:s,inset:a,children:n}=e,l=(0,Se.A)(e,TS);return(0,le.jsxs)(IS.ZP,(0,K.A)((0,K.A)({ref:t,className:Pe("flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[state=open]:bg-accent data-[state=open]:text-accent-foreground",a&&"pl-8",s)},l),{},{children:[n,(0,le.jsx)(rn.A,{className:"ml-auto h-4 w-4"})]}))});YS.displayName=IS.ZP.displayName;const GS=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,PS);return(0,le.jsx)(IS.G5,(0,K.A)({ref:t,className:Pe("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",s)},a))});GS.displayName=IS.G5.displayName;const $S=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,LS);return(0,le.jsx)(IS.ZL,{children:(0,le.jsx)(IS.UC,(0,K.A)({ref:t,className:Pe("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md animate-in fade-in-80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",s)},a))})});$S.displayName=IS.UC.displayName;const JS=Y.forwardRef((e,t)=>{let{className:s,inset:a}=e,n=(0,Se.A)(e,OS);return(0,le.jsx)(IS.q7,(0,K.A)({ref:t,className:Pe("relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",a&&"pl-8",s)},n))});JS.displayName=IS.q7.displayName;const ZS=Y.forwardRef((e,t)=>{let{className:s,children:a,checked:n}=e,l=(0,Se.A)(e,RS);return(0,le.jsxs)(IS.H_,(0,K.A)((0,K.A)({ref:t,className:Pe("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",s),checked:n},l),{},{children:[(0,le.jsx)("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:(0,le.jsx)(IS.VF,{children:(0,le.jsx)(Ps.A,{className:"h-4 w-4"})})}),a]}))});ZS.displayName=IS.H_.displayName;const KS=Y.forwardRef((e,t)=>{let{className:s,children:a}=e,n=(0,Se.A)(e,MS);return(0,le.jsxs)(IS.hN,(0,K.A)((0,K.A)({ref:t,className:Pe("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",s)},n),{},{children:[(0,le.jsx)("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:(0,le.jsx)(IS.VF,{children:(0,le.jsx)(_s.A,{className:"h-2 w-2 fill-current"})})}),a]}))});KS.displayName=IS.hN.displayName;const QS=Y.forwardRef((e,t)=>{let{className:s,inset:a}=e,n=(0,Se.A)(e,DS);return(0,le.jsx)(IS.JU,(0,K.A)({ref:t,className:Pe("px-2 py-1.5 text-sm font-semibold text-foreground",a&&"pl-8",s)},n))});QS.displayName=IS.JU.displayName;const XS=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,FS);return(0,le.jsx)(IS.wv,(0,K.A)({ref:t,className:Pe("-mx-1 my-1 h-px bg-border",s)},a))});XS.displayName=IS.wv.displayName;const eE=e=>{let{className:t}=e,s=(0,Se.A)(e,BS);return(0,le.jsx)("span",(0,K.A)({className:Pe("ml-auto text-xs tracking-widest text-muted-foreground",t)},s))};eE.displayName="ContextMenuShortcut";const tE=["className"],sE=["className"],aE=["className"],nE=["className","children"],lE=Sy.FormProvider,rE=Y.createContext({}),iE=e=>{let t=Object.assign({},((0,Ja.A)(e),e));return(0,le.jsx)(rE.Provider,{value:{name:t.name},children:(0,le.jsx)(Sy.Controller,(0,K.A)({},t))})},oE=()=>{const e=Y.useContext(rE),t=Y.useContext(cE),{getFieldState:s,formState:a}=(0,Sy.useFormContext)(),n=s(e.name,a);if(!e)throw new Error("useFormField should be used within ");const{id:l}=t;return(0,K.A)({id:l,name:e.name,formItemId:"".concat(l,"-form-item"),formDescriptionId:"".concat(l,"-form-item-description"),formMessageId:"".concat(l,"-form-item-message")},n)},cE=Y.createContext({}),dE=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,tE);const n=Y.useId();return(0,le.jsx)(cE.Provider,{value:{id:n},children:(0,le.jsx)("div",(0,K.A)({ref:t,className:Pe("space-y-2",s)},a))})});dE.displayName="FormItem";const mE=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,sE);const{error:n,formItemId:l}=oE();return(0,le.jsx)(Ns,(0,K.A)({ref:t,className:Pe(n&&"text-destructive",s),htmlFor:l},a))});mE.displayName="FormLabel";const uE=Y.forwardRef((e,t)=>{let s=Object.assign({},((0,Ja.A)(e),e));const{error:a,formItemId:n,formDescriptionId:l,formMessageId:r}=oE();return(0,le.jsx)(qt.DX,(0,K.A)({ref:t,id:n,"aria-describedby":a?"".concat(l," ").concat(r):"".concat(l),"aria-invalid":!!a},s))});uE.displayName="FormControl";const xE=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,aE);const{formDescriptionId:n}=oE();return(0,le.jsx)("p",(0,K.A)({ref:t,id:n,className:Pe("text-sm text-muted-foreground",s)},a))});xE.displayName="FormDescription";const hE=Y.forwardRef((e,t)=>{let{className:s,children:a}=e,n=(0,Se.A)(e,nE);const{error:l,formMessageId:r}=oE(),i=l?String(null==l?void 0:l.message):a;return i?(0,le.jsx)("p",(0,K.A)((0,K.A)({ref:t,id:r,className:Pe("text-sm font-medium text-destructive",s)},n),{},{children:i})):null});hE.displayName="FormMessage";var pE=s(29037);const gE=["className","align","sideOffset"],fE=pE.bL,vE=pE.l9,bE=Y.forwardRef((e,t)=>{let{className:s,align:a="center",sideOffset:n=4}=e,l=(0,Se.A)(e,gE);return(0,le.jsx)(pE.UC,(0,K.A)({ref:t,align:a,sideOffset:n,className:Pe("z-50 w-64 rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",s)},l))});bE.displayName=pE.UC.displayName;var jE=s(55102);const yE=["className"],NE=["className"],wE=["className","inset","children"],_E=["className"],kE=["className","align","alignOffset","sideOffset"],CE=["className","inset"],AE=["className","children","checked"],SE=["className","children"],EE=["className","inset"],IE=["className"],TE=["className"],PE=jE.W1,LE=jE.YJ,OE=jE.ZL,RE=jE.Pb,ME=jE.z6,DE=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,yE);return(0,le.jsx)(jE.bL,(0,K.A)({ref:t,className:Pe("flex h-10 items-center space-x-1 rounded-md border bg-background p-1",s)},a))});DE.displayName=jE.bL.displayName;const FE=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,NE);return(0,le.jsx)(jE.l9,(0,K.A)({ref:t,className:Pe("flex cursor-default select-none items-center rounded-sm px-3 py-1.5 text-sm font-medium outline-none focus:bg-accent focus:text-accent-foreground data-[state=open]:bg-accent data-[state=open]:text-accent-foreground",s)},a))});FE.displayName=jE.l9.displayName;const BE=Y.forwardRef((e,t)=>{let{className:s,inset:a,children:n}=e,l=(0,Se.A)(e,wE);return(0,le.jsxs)(jE.ZP,(0,K.A)((0,K.A)({ref:t,className:Pe("flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[state=open]:bg-accent data-[state=open]:text-accent-foreground",a&&"pl-8",s)},l),{},{children:[n,(0,le.jsx)(rn.A,{className:"ml-auto h-4 w-4"})]}))});BE.displayName=jE.ZP.displayName;const zE=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,_E);return(0,le.jsx)(jE.G5,(0,K.A)({ref:t,className:Pe("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",s)},a))});zE.displayName=jE.G5.displayName;const UE=Y.forwardRef((e,t)=>{let{className:s,align:a="start",alignOffset:n=-4,sideOffset:l=8}=e,r=(0,Se.A)(e,kE);return(0,le.jsx)(jE.ZL,{children:(0,le.jsx)(jE.UC,(0,K.A)({ref:t,align:a,alignOffset:n,sideOffset:l,className:Pe("z-50 min-w-[12rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",s)},r))})});UE.displayName=jE.UC.displayName;const WE=Y.forwardRef((e,t)=>{let{className:s,inset:a}=e,n=(0,Se.A)(e,CE);return(0,le.jsx)(jE.q7,(0,K.A)({ref:t,className:Pe("relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",a&&"pl-8",s)},n))});WE.displayName=jE.q7.displayName;const qE=Y.forwardRef((e,t)=>{let{className:s,children:a,checked:n}=e,l=(0,Se.A)(e,AE);return(0,le.jsxs)(jE.H_,(0,K.A)((0,K.A)({ref:t,className:Pe("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",s),checked:n},l),{},{children:[(0,le.jsx)("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:(0,le.jsx)(jE.VF,{children:(0,le.jsx)(Ps.A,{className:"h-4 w-4"})})}),a]}))});qE.displayName=jE.H_.displayName;const VE=Y.forwardRef((e,t)=>{let{className:s,children:a}=e,n=(0,Se.A)(e,SE);return(0,le.jsxs)(jE.hN,(0,K.A)((0,K.A)({ref:t,className:Pe("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",s)},n),{},{children:[(0,le.jsx)("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:(0,le.jsx)(jE.VF,{children:(0,le.jsx)(_s.A,{className:"h-2 w-2 fill-current"})})}),a]}))});VE.displayName=jE.hN.displayName;const HE=Y.forwardRef((e,t)=>{let{className:s,inset:a}=e,n=(0,Se.A)(e,EE);return(0,le.jsx)(jE.JU,(0,K.A)({ref:t,className:Pe("px-2 py-1.5 text-sm font-semibold",a&&"pl-8",s)},n))});HE.displayName=jE.JU.displayName;const YE=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,IE);return(0,le.jsx)(jE.wv,(0,K.A)({ref:t,className:Pe("-mx-1 my-1 h-px bg-muted",s)},a))});YE.displayName=jE.wv.displayName;const GE=e=>{let{className:t}=e,s=(0,Se.A)(e,TE);return(0,le.jsx)("span",(0,K.A)({className:Pe("ml-auto text-xs tracking-widest text-muted-foreground",t)},s))};GE.displayname="MenubarShortcut";var $E=s(47624);const JE=["className","children"],ZE=["className"],KE=["className","children"],QE=["className"],XE=["className"],eI=["className"],tI=Y.forwardRef((e,t)=>{let{className:s,children:a}=e,n=(0,Se.A)(e,JE);return(0,le.jsxs)($E.bL,(0,K.A)((0,K.A)({ref:t,className:Pe("relative z-10 flex max-w-max flex-1 items-center justify-center",s)},n),{},{children:[a,(0,le.jsx)(oI,{})]}))});tI.displayName=$E.bL.displayName;const sI=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,ZE);return(0,le.jsx)($E.B8,(0,K.A)({ref:t,className:Pe("group flex flex-1 list-none items-center justify-center space-x-1",s)},a))});sI.displayName=$E.B8.displayName;const aI=$E.q7,nI=(0,Ee.cva)("group inline-flex h-10 w-max items-center justify-center rounded-md bg-background px-4 py-2 text-sm font-medium transition-colors hover:bg-accent hover:text-accent-foreground focus:bg-accent focus:text-accent-foreground focus:outline-none disabled:pointer-events-none disabled:opacity-50 data-[active]:bg-accent/50 data-[state=open]:bg-accent/50"),lI=Y.forwardRef((e,t)=>{let{className:s,children:a}=e,n=(0,Se.A)(e,KE);return(0,le.jsxs)($E.l9,(0,K.A)((0,K.A)({ref:t,className:Pe(nI(),"group",s)},n),{},{children:[a," ",(0,le.jsx)(Is.A,{className:"relative top-[1px] ml-1 h-3 w-3 transition duration-200 group-data-[state=open]:rotate-180","aria-hidden":"true"})]}))});lI.displayName=$E.l9.displayName;const rI=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,QE);return(0,le.jsx)($E.UC,(0,K.A)({ref:t,className:Pe("left-0 top-0 w-full data-[motion^=from-]:animate-in data-[motion^=to-]:animate-out data-[motion^=from-]:fade-in data-[motion^=to-]:fade-out data-[motion=from-end]:slide-in-from-right-52 data-[motion=from-start]:slide-in-from-left-52 data-[motion=to-end]:slide-out-to-right-52 data-[motion=to-start]:slide-out-to-left-52 md:absolute md:w-auto ",s)},a))});rI.displayName=$E.UC.displayName;const iI=$E.N_,oI=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,XE);return(0,le.jsx)("div",{className:Pe("absolute left-0 top-full flex justify-center"),children:(0,le.jsx)($E.LM,(0,K.A)({className:Pe("origin-top-center relative mt-1.5 h-[var(--radix-navigation-menu-viewport-height)] w-full overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-90 md:w-[var(--radix-navigation-menu-viewport-width)]",s),ref:t},a))})});oI.displayName=$E.LM.displayName;const cI=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,eI);return(0,le.jsx)($E.C1,(0,K.A)((0,K.A)({ref:t,className:Pe("top-full z-[1] flex h-1.5 items-end justify-center overflow-hidden data-[state=visible]:animate-in data-[state=hidden]:animate-out data-[state=hidden]:fade-out data-[state=visible]:fade-in",s)},a),{},{children:(0,le.jsx)("div",{className:"relative top-[60%] h-2 w-2 rotate-45 rounded-tl-sm bg-border shadow-md"})}))});cI.displayName=$E.C1.displayName;var dI=s(23379);const mI=["className"],uI=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,mI);return(0,le.jsxs)(dI.bL,(0,K.A)((0,K.A)({ref:t,className:Pe("relative flex w-full touch-none select-none items-center",s)},a),{},{children:[(0,le.jsx)(dI.CC,{className:"relative h-2 w-full grow overflow-hidden rounded-full bg-secondary",children:(0,le.jsx)(dI.Q6,{className:"absolute h-full bg-primary"})}),(0,le.jsx)(dI.zi,{className:"block h-5 w-5 rounded-full border-2 border-primary bg-background ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50"})]}))});uI.displayName=dI.bL.displayName;var xI=s(52982);const hI=["className","variant","size"],pI=(0,Ee.cva)("inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-background transition-colors hover:bg-muted hover:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=on]:bg-accent data-[state=on]:text-accent-foreground",{variants:{variant:{default:"bg-transparent",outline:"border border-input bg-transparent hover:bg-accent hover:text-accent-foreground"},size:{default:"h-10 px-3",sm:"h-9 px-2.5",lg:"h-11 px-5"}},defaultVariants:{variant:"default",size:"default"}}),gI=Y.forwardRef((e,t)=>{let{className:s,variant:a,size:n}=e,l=(0,Se.A)(e,hI);return(0,le.jsx)(xI.b,(0,K.A)({ref:t,className:Pe(pI({variant:a,size:n,className:s}))},l))});gI.displayName=xI.b.displayName;var fI=s(85162);const vI=e=>{let t=Object.assign({},((0,Ja.A)(e),e));const{theme:s="system"}=(0,fI.D)();return(0,le.jsx)(Ri.Toaster,(0,K.A)({theme:s,className:"toaster group",toastOptions:{classNames:{toast:"group toast group-[.toaster]:bg-background group-[.toaster]:text-foreground group-[.toaster]:border-border group-[.toaster]:shadow-lg",description:"group-[.toast]:text-muted-foreground",actionButton:"group-[.toast]:bg-primary group-[.toast]:text-primary-foreground",cancelButton:"group-[.toast]:bg-muted group-[.toast]:text-muted-foreground"}}},t))};function bI(){for(var e=arguments.length,t=new Array(e),s=0;s{let{defaultOpen:s=!0,open:a,onOpenChange:n,className:l,style:r,children:i}=e,o=(0,Se.A)(e,jI);const c=Ut(),[d,m]=Y.useState(!1),[u,x]=Y.useState(s),h=null!=a?a:u,p=Y.useCallback(e=>{const t="function"==typeof e?e(h):e;n?n(t):x(t),document.cookie="".concat("sidebar_state","=").concat(t,"; path=/; max-age=").concat(604800)},[n,h]),g=Y.useCallback(()=>c?m(e=>!e):p(e=>!e),[c,p,m]);Y.useEffect(()=>{const e=e=>{"b"===e.key&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),g())};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[g]);const f=h?"expanded":"collapsed",v=Y.useMemo(()=>({state:f,open:h,setOpen:p,isMobile:c,openMobile:d,setOpenMobile:m,toggleSidebar:g}),[f,h,p,c,d,m,g]);return(0,le.jsx)(WI.Provider,{value:v,children:(0,le.jsx)(St,{delayDuration:0,children:(0,le.jsx)("div",(0,K.A)((0,K.A)({style:(0,K.A)({"--sidebar-width":"16rem","--sidebar-width-icon":"3rem"},r),className:bI("group/sidebar-wrapper flex min-h-svh w-full has-[[data-variant=inset]]:bg-sidebar",l),ref:t},o),{},{children:i}))})})});VI.displayName="SidebarProvider";const HI=Y.forwardRef((e,t)=>{let{side:s="left",variant:a="sidebar",collapsible:n="offcanvas",className:l,children:r}=e,i=(0,Se.A)(e,yI);const{isMobile:o,state:c,openMobile:d,setOpenMobile:m}=qI();return"none"===n?(0,le.jsx)("div",(0,K.A)((0,K.A)({className:bI("flex h-full w-[--sidebar-width] flex-col bg-sidebar text-sidebar-foreground",l),ref:t},i),{},{children:r})):o?(0,le.jsx)(tp,(0,K.A)((0,K.A)({open:d,onOpenChange:m},i),{},{children:(0,le.jsxs)(ip,{"data-sidebar":"sidebar","data-mobile":"true",className:"w-[--sidebar-width] bg-sidebar p-0 text-sidebar-foreground [&>button]:hidden",style:{"--sidebar-width":"18rem"},side:s,children:[(0,le.jsxs)(op,{className:"sr-only",children:[(0,le.jsx)(dp,{children:"Sidebar"}),(0,le.jsx)(mp,{children:"Displays the mobile sidebar."})]}),(0,le.jsx)("div",{className:"flex h-full w-full flex-col",children:r})]})})):(0,le.jsxs)("div",{ref:t,className:"group peer hidden text-sidebar-foreground md:block","data-state":c,"data-collapsible":"collapsed"===c?n:"","data-variant":a,"data-side":s,children:[(0,le.jsx)("div",{className:bI("relative w-[--sidebar-width] bg-transparent transition-[width] duration-200 ease-linear","group-data-[collapsible=offcanvas]:w-0","group-data-[side=right]:rotate-180","floating"===a||"inset"===a?"group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)_+_theme(spacing.4))]":"group-data-[collapsible=icon]:w-[--sidebar-width-icon]")}),(0,le.jsx)("div",(0,K.A)((0,K.A)({className:bI("fixed inset-y-0 z-10 hidden h-svh w-[--sidebar-width] transition-[left,right,width] duration-200 ease-linear md:flex","left"===s?"left-0 group-data-[collapsible=offcanvas]:left-[calc(var(--sidebar-width)*-1)]":"right-0 group-data-[collapsible=offcanvas]:right-[calc(var(--sidebar-width)*-1)]","floating"===a||"inset"===a?"p-2 group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)_+_theme(spacing.4)_+2px)]":"group-data-[collapsible=icon]:w-[--sidebar-width-icon] group-data-[side=left]:border-r group-data-[side=right]:border-l",l)},i),{},{children:(0,le.jsx)("div",{"data-sidebar":"sidebar",className:"flex h-full w-full flex-col bg-sidebar group-data-[variant=floating]:rounded-lg group-data-[variant=floating]:border group-data-[variant=floating]:border-sidebar-border group-data-[variant=floating]:shadow",children:r})}))]})});HI.displayName="Sidebar";const YI=Y.forwardRef((e,t)=>{let{className:s,onClick:a,asChild:n=!1}=e,l=(0,Se.A)(e,NI);const{toggleSidebar:r}=qI();return(0,le.jsx)(Yt,(0,K.A)((0,K.A)({ref:t,"data-sidebar":"trigger",variant:"ghost",size:"icon",className:bI("h-7 w-7",s),onClick:e=>{null==a||a(e),r()},asChild:n},l),{},{children:n?(0,le.jsx)(Yg.A,{}):(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(Yg.A,{}),(0,le.jsx)("span",{className:"sr-only",children:"Toggle Sidebar"})]})}))});YI.displayName="SidebarTrigger";const GI=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,wI);const{toggleSidebar:n}=qI();return(0,le.jsx)("button",(0,K.A)({ref:t,"data-sidebar":"rail","aria-label":"Toggle Sidebar",tabIndex:-1,onClick:n,title:"Toggle Sidebar",className:bI("absolute inset-y-0 z-20 hidden w-4 -translate-x-1/2 transition-all ease-linear after:absolute after:inset-y-0 after:left-1/2 after:w-[2px] hover:after:bg-sidebar-border group-data-[side=left]:-right-4 group-data-[side=right]:left-0 sm:flex","[[data-side=left]_&]:cursor-w-resize [[data-side=right]_&]:cursor-e-resize","[[data-side=left][data-state=collapsed]_&]:cursor-e-resize [[data-side=right][data-state=collapsed]_&]:cursor-w-resize","group-data-[collapsible=offcanvas]:translate-x-0 group-data-[collapsible=offcanvas]:after:left-full group-data-[collapsible=offcanvas]:hover:bg-sidebar","[[data-side=left][data-collapsible=offcanvas]_&]:-right-2","[[data-side=right][data-collapsible=offcanvas]_&]:-left-2",s)},a))});GI.displayName="SidebarRail";const $I=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,_I);return(0,le.jsx)("main",(0,K.A)({ref:t,className:bI("relative flex w-full flex-1 flex-col bg-background","md:peer-data-[variant=inset]:m-2 md:peer-data-[state=collapsed]:peer-data-[variant=inset]:ml-2 md:peer-data-[variant=inset]:ml-0 md:peer-data-[variant=inset]:rounded-xl md:peer-data-[variant=inset]:shadow",s)},a))});$I.displayName="SidebarInset";const JI=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,kI);return(0,le.jsx)(fs,(0,K.A)({ref:t,"data-sidebar":"input",className:bI("h-8 w-full bg-background shadow-none focus-visible:ring-2 focus-visible:ring-sidebar-ring",s)},a))});JI.displayName="SidebarInput";const ZI=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,CI);return(0,le.jsx)("div",(0,K.A)({ref:t,"data-sidebar":"header",className:bI("flex flex-col gap-2 p-2",s)},a))});ZI.displayName="SidebarHeader";const KI=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,AI);return(0,le.jsx)("div",(0,K.A)({ref:t,"data-sidebar":"footer",className:bI("flex flex-col gap-2 p-2",s)},a))});KI.displayName="SidebarFooter";const QI=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,SI);return(0,le.jsx)(ps,(0,K.A)({ref:t,"data-sidebar":"separator",className:bI("mx-2 w-auto bg-sidebar-border",s)},a))});QI.displayName="SidebarSeparator";const XI=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,EI);return(0,le.jsx)("div",(0,K.A)({ref:t,"data-sidebar":"content",className:bI("flex min-h-0 flex-1 flex-col gap-2 overflow-auto group-data-[collapsible=icon]:overflow-hidden",s)},a))});XI.displayName="SidebarContent";const eT=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,II);return(0,le.jsx)("div",(0,K.A)({ref:t,"data-sidebar":"group",className:bI("relative flex w-full min-w-0 flex-col p-2",s)},a))});eT.displayName="SidebarGroup";const tT=Y.forwardRef((e,t)=>{let{className:s,asChild:a=!1}=e,n=(0,Se.A)(e,TI);const l=a?qt.DX:"div";return(0,le.jsx)(l,(0,K.A)({ref:t,"data-sidebar":"group-label",className:bI("flex h-8 shrink-0 items-center rounded-md px-2 text-xs font-medium text-sidebar-foreground/70 outline-none ring-sidebar-ring transition-[margin,opacity] duration-200 ease-linear focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0","group-data-[collapsible=icon]:-mt-8 group-data-[collapsible=icon]:opacity-0",s)},n))});tT.displayName="SidebarGroupLabel";const sT=Y.forwardRef((e,t)=>{let{className:s,asChild:a=!1}=e,n=(0,Se.A)(e,PI);const l=a?qt.DX:"button";return(0,le.jsx)(l,(0,K.A)({ref:t,"data-sidebar":"group-action",className:bI("absolute right-3 top-3.5 flex aspect-square w-5 items-center justify-center rounded-md p-0 text-sidebar-foreground outline-none ring-sidebar-ring transition-transform hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0","after:absolute after:-inset-2 after:md:hidden","group-data-[collapsible=icon]:hidden",s)},n))});sT.displayName="SidebarGroupAction";const aT=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,LI);return(0,le.jsx)("div",(0,K.A)({ref:t,"data-sidebar":"group-content",className:bI("w-full text-sm",s)},a))});aT.displayName="SidebarGroupContent";const nT=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,OI);return(0,le.jsx)("ul",(0,K.A)({ref:t,"data-sidebar":"menu",className:bI("flex w-full min-w-0 flex-col gap-1",s)},a))});nT.displayName="SidebarMenu";const lT=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,RI);return(0,le.jsx)("li",(0,K.A)({ref:t,"data-sidebar":"menu-item",className:bI("group/menu-item relative",s)},a))});lT.displayName="SidebarMenuItem";const rT=(0,Ee.cva)("peer/menu-button flex w-full items-center gap-2 overflow-hidden rounded-md p-2 text-left text-sm outline-none ring-sidebar-ring transition-[width,height,padding] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 active:bg-sidebar-accent active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 group-has-[[data-sidebar=menu-action]]/menu-item:pr-8 aria-disabled:pointer-events-none aria-disabled:opacity-50 data-[active=true]:bg-sidebar-accent data-[active=true]:font-medium data-[active=true]:text-sidebar-accent-foreground data-[state=open]:hover:bg-sidebar-accent data-[state=open]:hover:text-sidebar-accent-foreground group-data-[collapsible=icon]:!size-8 group-data-[collapsible=icon]:!p-2 [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0",{variants:{variant:{default:"hover:bg-sidebar-accent hover:text-sidebar-accent-foreground",outline:"bg-background shadow-[0_0_0_1px_hsl(var(--sidebar-border))] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground hover:shadow-[0_0_0_1px_hsl(var(--sidebar-accent))]"},size:{default:"h-8 text-sm",sm:"h-7 text-xs",lg:"h-12 text-sm group-data-[collapsible=icon]:!p-0"}},defaultVariants:{variant:"default",size:"default"}}),iT=Y.forwardRef((e,t)=>{let{asChild:s=!1,isActive:a=!1,variant:n="default",size:l="default",tooltip:r,className:i}=e,o=(0,Se.A)(e,MI);const c=s?qt.DX:"button",{isMobile:d,state:m}=qI(),u=(0,le.jsx)(c,(0,K.A)({ref:t,"data-sidebar":"menu-button","data-size":l,"data-active":a,className:bI(rT({variant:n,size:l}),i)},o));return r?("string"==typeof r&&(r={children:r}),(0,le.jsxs)(Et,{children:[(0,le.jsx)(It,{asChild:!0,children:u}),(0,le.jsx)(Tt,(0,K.A)({side:"right",align:"center",hidden:"collapsed"!==m||d},r))]})):u});iT.displayName="SidebarMenuButton";const oT=Y.forwardRef((e,t)=>{let{className:s,asChild:a=!1,showOnHover:n=!1}=e,l=(0,Se.A)(e,DI);const r=a?qt.DX:"button";return(0,le.jsx)(r,(0,K.A)({ref:t,"data-sidebar":"menu-action",className:bI("absolute right-1 top-1.5 flex aspect-square w-5 items-center justify-center rounded-md p-0 text-sidebar-foreground outline-none ring-sidebar-ring transition-transform hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 peer-hover/menu-button:text-sidebar-accent-foreground [&>svg]:size-4 [&>svg]:shrink-0","after:absolute after:-inset-2 after:md:hidden","peer-data-[size=sm]/menu-button:top-1","peer-data-[size=default]/menu-button:top-1.5","peer-data-[size=lg]/menu-button:top-2.5","group-data-[collapsible=icon]:hidden",n&&"group-focus-within/menu-item:opacity-100 group-hover/menu-item:opacity-100 data-[state=open]:opacity-100 peer-data-[active=true]/menu-button:text-sidebar-accent-foreground md:opacity-0",s)},l))});oT.displayName="SidebarMenuAction";const cT=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,FI);return(0,le.jsx)("div",(0,K.A)({ref:t,"data-sidebar":"menu-badge",className:bI("pointer-events-none absolute right-1 flex h-5 min-w-5 select-none items-center justify-center rounded-md px-1 text-xs font-medium tabular-nums text-sidebar-foreground","peer-hover/menu-button:text-sidebar-accent-foreground peer-data-[active=true]/menu-button:text-sidebar-accent-foreground","peer-data-[size=sm]/menu-button:top-1","peer-data-[size=default]/menu-button:top-1.5","peer-data-[size=lg]/menu-button:top-2.5","group-data-[collapsible=icon]:hidden",s)},a))});cT.displayName="SidebarMenuBadge";const dT=Y.forwardRef((e,t)=>{let{className:s,showIcon:a=!1}=e,n=(0,Se.A)(e,BI);const l=Y.useMemo(()=>"".concat(Math.floor(40*Math.random())+50,"%"),[]);return(0,le.jsxs)("div",(0,K.A)((0,K.A)({ref:t,"data-sidebar":"menu-skeleton",className:bI("flex h-8 items-center gap-2 rounded-md px-2",s)},n),{},{children:[a&&(0,le.jsx)(hg,{className:"size-4 rounded-md","data-sidebar":"menu-skeleton-icon"}),(0,le.jsx)(hg,{className:"h-4 max-w-[--skeleton-width] flex-1","data-sidebar":"menu-skeleton-text",style:{"--skeleton-width":l}})]}))});dT.displayName="SidebarMenuSkeleton";const mT=Y.forwardRef((e,t)=>{let{className:s}=e,a=(0,Se.A)(e,zI);return(0,le.jsx)("ul",(0,K.A)({ref:t,"data-sidebar":"menu-sub",className:bI("mx-3.5 flex min-w-0 translate-x-px flex-col gap-1 border-l border-sidebar-border px-2.5 py-0.5","group-data-[collapsible=icon]:hidden",s)},a))});mT.displayName="SidebarMenuSub";const uT=Y.forwardRef((e,t)=>{let s=Object.assign({},((0,Ja.A)(e),e));return(0,le.jsx)("li",(0,K.A)({ref:t},s))});uT.displayName="SidebarMenuSubItem";const xT=Y.forwardRef((e,t)=>{let{asChild:s=!1,size:a="md",isActive:n,className:l}=e,r=(0,Se.A)(e,UI);const i=s?qt.DX:"a";return(0,le.jsx)(i,(0,K.A)({ref:t,"data-sidebar":"menu-sub-button","data-size":a,"data-active":n,className:bI("flex h-7 min-w-0 -translate-x-px items-center gap-2 overflow-hidden rounded-md px-2 text-sidebar-foreground outline-none ring-sidebar-ring hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 active:bg-sidebar-accent active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0 [&>svg]:text-sidebar-accent-foreground","data-[active=true]:bg-sidebar-accent data-[active=true]:text-sidebar-accent-foreground","sm"===a&&"text-xs","md"===a&&"text-sm","group-data-[collapsible=icon]:hidden",l)},r))});xT.displayName="SidebarMenuSubButton";var hT=s(92319),pT=s(22164),gT=s(31815),fT=s(69504),vT=s(13437),bT=s(11728),jT=s(15061),yT=s(14237),NT=s(88141),wT=s(81052),_T=s(18545);ra().locale("en-US");class kT{constructor(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:()=>{};this.appSDK=e;let G=(0,K.A)({},e.files.coreFiles);for(const a in e.files.pages)G["pages/"+a+".js"]=e.files.pages[a];for(const a in e.files.components)G["components/"+a+".js"]=e.files.components[a];e.files.layout&&(G["layout.js"]=e.files.layout),this.appFiles=G,this.packages={recharts:tS,"react-hot-toast":cr,moment:ra(),"moment/locale/he":eS,"moment/locale/ar":KA,"moment/locale/fr":QA,"moment/locale/es":XA,react:Y,"lucide-react":sS,"react-quill":Tp,"@hello-pangea/dnd":iS,"date-fns":hT,"date-fns/locale":pT,three:vT,"three/addons/controls/OrbitControls.js":bT,"three/addons/loaders/GLTFLoader.js":jT,sonner:Ri,"@stripe/stripe-js":Kc,"@stripe/react-stripe-js":rS,"@radix-ui/react-toast":wf,"@radix-ui/react-dialog":ka,"class-variance-authority":Ee,"@/components/ui/sidebar":H,"react-dom":dd,"react-dom/client":$,"react-markdown":gT,"@tanstack/react-query":fT,lodash:Ce,jspdf:aS,"framer-motion":yT,"react-router-dom":J,"react-hook-form":Sy,"react-quill/dist/quill.snow.css":{},"react-leaflet":lS,leaflet:nS,"leaflet/dist/leaflet.css":{},"canvas-confetti":NT,html2canvas:wT,"@/lib/utils":a,"@/components/lib/utils":a,"./components/lib/utils":a,"@/components/ui/accordion":O,"@/components/ui/alert":n,"@/components/ui/alert-dialog":P,"@/components/ui/aspect-ratio":R,"@/components/ui/avatar":h,"@/components/ui/badge":i,"@/components/ui/button":r,"@/components/ui/calendar":C,"@/components/ui/card":o,"@/components/ui/checkbox":j,"@/components/ui/collapsible":_,"@/components/ui/carousel":M,"@/components/ui/command":k,"@/components/ui/context-menu":D,"@/components/ui/dialog":p,"@/components/ui/dropdown-menu":b,"@/components/ui/form":F,"@/components/ui/hover-card":B,"@/components/ui/input":d,"@/components/ui/label":m,"@/components/ui/menubar":z,"@/components/ui/navigation-menu":U,"@/components/ui/popover":A,"@/components/ui/progress":L,"@/components/ui/radio-group":u,"@/components/ui/scroll-area":N,"@/components/ui/select":x,"@/components/ui/separator":c,"@/components/ui/sheet":S,"@/components/ui/skeleton":E,"@/components/ui/slider":W,"@/components/ui/switch":w,"@/components/ui/table":f,"@/components/ui/tabs":v,"@/components/ui/textarea":y,"@/components/ui/toast":I,"@/hooks/use-toast":g,"@/components/ui/use-toast":g,"@/components/ui/toaster":T,"@/components/ui/toggle":q,"@/components/ui/tooltip":l,"@/components/ui/sonner":V,"@base44/sdk":_T},this.globals=t,this.moduleCache={},this.compilingModules=new Set,this.importFile=this.importFile.bind(this),this.onError=s}_importAppSDK(e){let t=e;if(e.split("/").length>2&&(t=e.split("/").pop()),e.includes("/entities"))return t?(0,K.A)((0,K.A)({},this.appSDK.entities),{},{default:this.appSDK.entities[t]}):this.appSDK.entities;if(e.includes("/functions"))return t?(0,K.A)((0,K.A)({},this.appSDK.functions),{},{default:()=>alert="ok!!!"}):this.appSDK.functions;if(e.includes("/integrations")){if(t)return this.appSDK.integrations[t];let e={};return Object.keys(this.appSDK.integrations).forEach(t=>{e["@/integrations/".concat(t)]=this.appSDK.integrations[t],e["./integrations/".concat(t)]=this.appSDK.integrations[t]}),e}return"./utils"==e||"@/utils"==e||"../utils"===e?{createPageUrl:this.appSDK.createPageUrl}:e.includes("/agents")?{agentSDK:this.appSDK.agents,default:this.appSDK.agents}:void alert("importing "+e)}importAppSDK(e){return this._importAppSDK(e)}importFile(e,t){if(e.endsWith(".css"))return this.handleCSSImport(e);const s=GA(e);if(this.appFiles[s]&&!s.includes("use-toast"))return this.importAppFile(e,t);if(e.includes("components/ui/")||e.includes("@/components/ui/")){let t=e;if(e.startsWith("./")||e.startsWith("../")){const s=e.split("/"),a=s[s.length-1];t="@/components/ui/".concat(a)}return this.importPackage(t)}return"@/lib/utils"===e?this.importPackage(e):e.startsWith("./")||e.startsWith("@/")||e.startsWith("../")?e.includes("/entities/")||e.includes("/functions/")||e.includes("/integrations/")||e.includes("/agents")||"./utils"==e||"@/utils"==e||"../utils"===e?this.importAppSDK(e):this.importAppFile(e,t):this.importPackage(e)}importPackage(e){if(!this.packages.hasOwnProperty(e)){const t=e.split("/");if(this.packages.hasOwnProperty(t[0])){let s=this.packages[t[0]];for(let a=1;a0&&l.pop():e&&l.push(e));let r=l.join("/");if(r.startsWith("./")&&(r=r.substring(2)),r.startsWith("../")&&(r=r.substring(3)),r.startsWith("@/")&&(r=r.substring(2)),s[r])return r;if(s[r+".js"])return r+".js";const i=Object.keys(s).find(t=>t.endsWith(e));if(i)return i}return a}(e,t,this.appFiles);if(this.moduleCache[s])return this.moduleCache[s];if(this.compilingModules.has(s))return{};this.compilingModules.add(s);let a=this.appFiles[s];if(!a){const n=s.toLowerCase(),l=Object.keys(this.appFiles).find(e=>e.toLowerCase()===n);if(!l)throw new Error("Error in ".concat(t,": can't import file ").concat(e,", it doesn't exist (checked case-insensitive also)."));a=this.appFiles[l]}const n=function(e,t){e.includes(".")&&(e=e.split(".")[0]);const s=HA(e,t).split("\n"),a=/(<[A-Z][a-zA-Z]*|<[a-z][a-zA-Z0-9]*)(\s|>|\/>)/g;return s.map((t,s)=>{const n=s+1;return a.test(t)?(a.lastIndex=0,t.replace(a,(s,a,l)=>{const r=t.substring(0,t.indexOf(a)).includes('"')?"'":'"';return l.includes(">")?(l.indexOf(">"),"".concat(a," data-filename=").concat(r).concat(e).concat(r," data-linenumber=").concat(r).concat(n).concat(r," data-visual-selector-id=").concat(r).concat(e).concat(n).concat(r).concat(l)):"".concat(a).concat(l,"data-filename=").concat(r).concat(e).concat(r," data-linenumber=").concat(r).concat(n).concat(r," data-visual-selector-id=").concat(r).concat(e).concat(n).concat(r," ")})):t}).join("\n")}(s,a);let l;try{l=this.compileJSXToJavascript(s,n,!1)}catch(i){l=this.compileJSXToJavascript(s,a,!0)}const r=this.evaluateJavascriptCode(s,l);return this.moduleCache[s]=r,this.compilingModules.delete(s),r}compileJSXToJavascript(e,t){let s=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];if(!t||"string"!=typeof t)throw new Error('Invalid code content for "'.concat(e,'"'));const a=t.trim();let n;try{n=(0,qA.pd)(a,{transforms:["jsx","imports"],production:!1,filePath:e})}catch(r){throw s&&this.onError(null==r?void 0:r.message,null==r?void 0:r.toString(),e,r),r}let l=n.code;l.startsWith('"use strict";')&&(l=l.substring(13));return"\n // Initialize module objects\n const module = { exports: {} };\n const exports = module.exports;\n \n ".concat(l,"\n \n // No need for regex transforms - module.exports will naturally capture all exports\n ")}evaluateJavascriptCode(e,t){const s=(0,K.A)({React:Y,require:t=>this.importFile(t,e),console:ZA(e,this.onError)},this.globals),a=Object.keys(s),n=a.map(e=>s[e]);try{const s=new Function(...a,t+"; return { moduleExports: module.exports, exportsObj: exports };")(...n),l=s.moduleExports&&Object.keys(s.moduleExports).length>0?s.moduleExports:s.exportsObj;return $A(e,l)}catch(l){return this.onError("Error evaluating module ".concat(e,": ").concat(l.message),l.toString(),e,l),$A(e,{})}}render(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[];const a=this.importAppFile(e);if(!a)throw new Error('[AppProjectCompiler] No exports found in "'.concat(e,'"'));let n=null;if("function"==typeof a)n=a;else if(a.default&&"function"==typeof a.default)n=a.default;else for(const l of Object.keys(a))if("function"==typeof a[l]&&(l.includes("Component")||l.endsWith("Provider")||l.startsWith("App")||"Main"===l||l.charAt(0)===l.charAt(0).toUpperCase())){n=a[l];break}if(!n)throw new Error('No component found in "'.concat(e,'"'));return Y.createElement(n,t,...s)}handleCSSImport(e){const t=GA(e);if(this.constructor.injectedCSS||(this.constructor.injectedCSS=new Set),this.constructor.injectedCSS.has(t))return{};let s="";if(!this.appFiles[t])return this.packages[e],{};if(s=this.appFiles[t],s){const e=document.createElement("style");e.textContent=s,e.setAttribute("data-source",t),document.head.appendChild(e),this.constructor.injectedCSS.add(t)}return{}}}function CT(){const[e,t]=(0,Y.useState)(!1),s=(0,Y.useRef)(!1),[a,n]=(0,Y.useState)(null),[l,r]=(0,Y.useState)(!1),i=(0,Y.useRef)(!1),[o,c]=(0,Y.useState)(!1),d=(0,Y.useRef)(!1),m=(0,Y.useRef)([]),u=(0,Y.useRef)([]),x=(0,Y.useRef)([]),h=(0,Y.useRef)(null),p=function(){let e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];const t=document.createElement("div");return t.style.position="absolute",t.style.pointerEvents="none",t.style.transition="all 0.1s ease-in-out",t.style.zIndex="9999",e?t.style.border="2px solid #2563EB":(t.style.border="2px solid #95a5fc",t.style.backgroundColor="rgba(99, 102, 241, 0.05)"),t},g=function(e,t){let a=arguments.length>2&&void 0!==arguments[2]&&arguments[2];if(!t||!s.current)return;t.offsetWidth;const n=t.getBoundingClientRect();e.style.top="".concat(n.top+window.scrollY,"px"),e.style.left="".concat(n.left+window.scrollX,"px"),e.style.width="".concat(n.width,"px"),e.style.height="".concat(n.height,"px");let l=e.querySelector("div");l||(l=document.createElement("div"),l.textContent=t.tagName.toLowerCase(),l.style.position="absolute",l.style.top="-27px",l.style.left="-2px",l.style.padding="2px 8px",l.style.fontSize="11px",l.style.fontWeight=a?"500":"400",l.style.color=a?"#ffffff":"#526cff",l.style.backgroundColor=a?"#526cff":"#DBEAFE",l.style.borderRadius="3px",l.style.boxShadow="none",l.style.minWidth="24px",l.style.textAlign="center",e.appendChild(l))},f=e=>{if(!e)return[];const t=[...document.querySelectorAll('[data-source-location="'.concat(e,'"]'))];return t.length>0?t:[...document.querySelectorAll('[data-visual-selector-id="'.concat(e,'"]'))]},v=()=>{m.current.forEach(e=>{e&&e.parentNode&&e.remove()}),m.current=[],x.current=[]},b=e=>{if(!s.current||i.current)return;if(d.current)return void v();if("path"===e.target.tagName.toLowerCase())return void v();const t=e.target.closest("[data-source-location], [data-visual-selector-id]");if(!t)return void v();const a=t.dataset.sourceLocation||t.dataset.visualSelectorId;t.dataset.sourceLocation;if(h.current===a)return void v();const n=f(a);v(),n.forEach(e=>{const t=p(!1);document.body.appendChild(t),m.current.push(t),g(t,e)}),x.current=n},j=()=>{i.current||v()},y=e=>{var t;if(!s.current)return;if(d.current)return e.preventDefault(),e.stopPropagation(),e.stopImmediatePropagation(),void window.parent.postMessage({type:"close-dropdowns"},"*");if("path"===e.target.tagName.toLowerCase())return;e.preventDefault(),e.stopPropagation(),e.stopImmediatePropagation();const a=e.target.closest("[data-source-location], [data-visual-selector-id]");if(!a)return;const l=a.dataset.sourceLocation||a.dataset.visualSelectorId;a.dataset.sourceLocation;u.current.forEach(e=>{e&&e.parentNode&&e.remove()}),u.current=[];f(l).forEach(e=>{const t=p(!0);document.body.appendChild(t),u.current.push(t),g(t,e,!0)}),n(a),h.current=l,v();const r=a.getBoundingClientRect(),i={top:r.top,left:r.left,right:r.right,bottom:r.bottom,width:r.width,height:r.height,centerX:r.left+r.width/2,centerY:r.top+r.height/2},o={type:"element-selected",tagName:a.tagName,classes:(null===(t=a.className)||void 0===t?void 0:t.baseVal)||a.className||"",visualSelectorId:l,content:a.innerText,dataSourceLocation:a.dataset.sourceLocation,isDynamicContent:"true"===a.dataset.dynamicContent,linenumber:a.dataset.linenumber,filename:a.dataset.filename,position:i};window.parent.postMessage(o,"*")};return(0,Y.useEffect)(()=>{document.querySelectorAll("[data-visual-selector-id]");document.querySelectorAll("[data-linenumber]:not([data-visual-selector-id])").forEach((e,t)=>{const s="visual-id-".concat(e.dataset.filename,"-").concat(e.dataset.linenumber,"-").concat(t);e.dataset.visualSelectorId=s});const e=()=>{if(h.current){const e=f(h.current);if(e.length>0){const t=e[0].getBoundingClientRect(),s=window.innerHeight,a=window.innerWidth,n=t.top0&&t.left0,l={top:t.top,left:t.left,right:t.right,bottom:t.bottom,width:t.width,height:t.height,centerX:t.left+t.width/2,centerY:t.top+t.height/2};window.parent.postMessage({type:"element-position-update",position:l,isInViewport:n,visualSelectorId:h.current},"*")}}},a=e=>{const a=e.data;switch(a.type){case"toggle-visual-edit-mode":l=a.data.enabled,t(l),s.current=l,l?(document.body.style.cursor="crosshair",document.addEventListener("mouseover",b),document.addEventListener("mouseout",j),document.addEventListener("click",y,!0)):(v(),u.current.forEach(e=>{e&&e.parentNode&&e.remove()}),u.current=[],x.current=[],n(null),h.current=null,document.body.style.cursor="default",document.removeEventListener("mouseover",b),document.removeEventListener("mouseout",j),document.removeEventListener("click",y,!0));break;case"update-classes":a.data&&void 0!==a.data.classes&&function(e,t){let s=arguments.length>2&&void 0!==arguments[2]&&arguments[2];const a=f(e);0!==a.length&&(a.forEach(e=>{if(s)e.className=t;else{var a;const s=(null===(a=e.className)||void 0===a?void 0:a.baseVal)||e.className||"";e.className=(0,Te.QP)(s,t)}}),setTimeout(()=>{var t,s;(h.current===e&&u.current.forEach((e,t)=>{t0)&&((null===(t=x.current[0])||void 0===t||null===(s=t.dataset)||void 0===s?void 0:s.visualSelectorId)===e&&m.current.forEach((e,t)=>{t{e&&e.parentNode&&e.remove()}),u.current=[],n(null),h.current=null;break;case"refresh-page":window.location.reload();break;case"update-content":a.data&&void 0!==a.data.content&&((e,t)=>{const s=f(e);0!==s.length&&(s.forEach(e=>{e.innerText=t}),setTimeout(()=>{h.current===e&&u.current.forEach((e,t)=>{t0){const t=e[0].getBoundingClientRect(),s=window.innerHeight,a=window.innerWidth,n=t.top0&&t.left0,l={top:t.top,left:t.left,right:t.right,bottom:t.bottom,width:t.width,height:t.height,centerX:t.left+t.width/2,centerY:t.top+t.height/2};window.parent.postMessage({type:"element-position-update",position:l,isInViewport:n,visualSelectorId:h.current},"*")}}break;case"popover-drag-state":a.data&&void 0!==a.data.isDragging&&(r(a.data.isDragging),i.current=a.data.isDragging,a.data.isDragging&&v());break;case"dropdown-state":a.data&&void 0!==a.data.isOpen&&(c(a.data.isOpen),d.current=a.data.isOpen,a.data.isOpen&&v())}var l};return window.addEventListener("message",a),window.addEventListener("scroll",e,!0),document.addEventListener("scroll",e,!0),window.parent.postMessage({type:"visual-edit-agent-ready"},"*"),()=>{window.removeEventListener("message",a),window.removeEventListener("scroll",e,!0),document.removeEventListener("scroll",e,!0),document.removeEventListener("mouseover",b),document.removeEventListener("mouseout",j),document.removeEventListener("click",y,!0),v(),u.current.forEach(e=>{e&&e.parentNode&&e.remove()})}},[]),(0,Y.useEffect)(()=>{s.current=e},[e]),(0,Y.useEffect)(()=>{i.current=l},[l]),(0,Y.useEffect)(()=>{d.current=o},[o]),(0,Y.useEffect)(()=>{const e=()=>{if(h.current){const e=f(h.current);u.current.forEach((t,s)=>{s0&&m.current.forEach((e,t)=>{t{t.some(e=>{const t=e=>{if(e.nodeType===Node.ELEMENT_NODE){if(e.dataset&&e.dataset.visualSelectorId)return!0;for(let s=0;s{window.removeEventListener("resize",e),window.removeEventListener("scroll",e),t.disconnect()}},[]),null}function AT(e){let{appId:t}=e;const[s,a]=(0,Y.useState)(!1),[n,l]=(0,Y.useState)(!0);(0,Y.useEffect)(()=>{"true"===new URLSearchParams(window.location.search).get("hide_badge")&&l(!1)},[]);return n?(0,le.jsxs)("div",{dir:"ltr",className:"fixed z-50 text-white bottom-4 right-4 flex items-center gap-2 bg-black pt-2 pb-2 pl-3 pr-3 rounded-md shadow-lg cursor-pointer transition-all hover:shadow-xl border border-neutral-800",onClick:async()=>{a(!0);const e=pa();window.open("".concat(e,"/remix-app/").concat(t),"_blank"),a(!1)},children:[(0,le.jsx)("img",{src:"https://base44.app/logo_v3.png",alt:"base44",className:"w-5 h-5"}),(0,le.jsx)("span",{className:"whitespace-nowrap text-xs",children:s?(0,le.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,le.jsx)(Ne.A,{className:"w-3 h-3 animate-spin"}),(0,le.jsx)("span",{children:"Cloning..."})]}):(0,le.jsxs)("div",{className:"flex items-center gap-1.5 align-middle justify-center text-sm",children:[(0,le.jsx)("span",{children:"Edit with "}),(0,le.jsx)("span",{className:"mb-0.5",children:(0,le.jsx)("img",{src:"/base44_text.png",alt:"Base44",height:18,width:56})})]})}),(0,le.jsx)("button",{className:"p-0.5 ml-0.5 rounded-full hover:bg-neutral-700 transition-colors","aria-label":"Close badge",onClick:e=>{e.stopPropagation(),l(!1)},children:(0,le.jsx)(Bt.A,{className:"w-3.5 h-3.5"})})]}):null}function ST(e){let{}=e;const{user:t,isAuthenticated:s}=BA(),{pageName:a}=(0,Z.g)();return(0,le.jsx)("div",{className:"min-h-screen flex items-center justify-center p-6 bg-slate-50",children:(0,le.jsx)("div",{className:"max-w-md w-full",children:(0,le.jsxs)("div",{className:"text-center space-y-6",children:[(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsx)("h1",{className:"text-7xl font-light text-slate-300",children:"404"}),(0,le.jsx)("div",{className:"h-0.5 w-16 bg-slate-200 mx-auto"})]}),(0,le.jsxs)("div",{className:"space-y-3",children:[(0,le.jsx)("h2",{className:"text-2xl font-medium text-slate-800",children:"Page Not Found"}),(0,le.jsxs)("p",{className:"text-slate-600 leading-relaxed",children:["The page ",(0,le.jsxs)("span",{className:"font-medium text-slate-700",children:['"',a,'"']})," could not be found in this application."]})]}),s&&"admin"===(null==t?void 0:t.role)&&(0,le.jsx)("div",{className:"mt-8 p-4 bg-slate-100 rounded-lg border border-slate-200",children:(0,le.jsxs)("div",{className:"flex items-start space-x-3",children:[(0,le.jsx)("div",{className:"flex-shrink-0 w-5 h-5 rounded-full bg-orange-100 flex items-center justify-center mt-0.5",children:(0,le.jsx)("div",{className:"w-2 h-2 rounded-full bg-orange-400"})}),(0,le.jsxs)("div",{className:"text-left space-y-1",children:[(0,le.jsx)("p",{className:"text-sm font-medium text-slate-700",children:"Admin Note"}),(0,le.jsx)("p",{className:"text-sm text-slate-600 leading-relaxed",children:"This could mean that the AI hasn't implemented this page yet. Ask it to implement it in the chat."})]})]})}),(0,le.jsx)("div",{className:"pt-6",children:(0,le.jsxs)("button",{onClick:()=>window.location.href="/",className:"inline-flex items-center px-4 py-2 text-sm font-medium text-slate-700 bg-white border border-slate-200 rounded-lg hover:bg-slate-50 hover:border-slate-300 transition-colors duration-200 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-slate-500",children:[(0,le.jsx)("svg",{className:"w-4 h-4 mr-2",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,le.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3m-6 0a1 1 0 001-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 001 1m-6 0h6"})}),"Go Home"]})})]})})})}const ET=e=>{let{className:t="",width:s=36,height:a=36}=e;return(0,le.jsxs)("svg",{width:s,height:a,viewBox:"0 0 36 36",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:t,children:[(0,le.jsx)("path",{d:"M28.2533 31.4621C28.2999 31.4621 28.3204 31.5214 28.2833 31.5498C25.3198 33.8234 21.6115 35.1751 17.5875 35.1751C13.5635 35.1751 9.85519 33.8238 6.8917 31.5498C6.85457 31.5214 6.87509 31.4621 6.92166 31.4621H28.2537H28.2533ZM32.8411 26.3487C32.2268 27.416 31.5034 28.4127 30.6869 29.3236C30.656 29.3582 30.6117 29.3777 30.5654 29.3777H4.60988C4.56364 29.3777 4.51934 29.3582 4.4884 29.3236C3.67156 28.4127 2.94852 27.416 2.33426 26.3487C2.30918 26.3054 2.34077 26.251 2.39093 26.251H32.7844C32.8346 26.251 32.8661 26.3054 32.8411 26.3487ZM34.8272 21.0855C34.6181 22.1209 34.3181 23.1234 33.9361 24.0845C33.9162 24.134 33.868 24.1666 33.8146 24.1666H1.36043C1.30702 24.1666 1.25882 24.134 1.23895 24.0845C0.856909 23.1237 0.556944 22.1212 0.347848 21.0855C0.339706 21.0451 0.370647 21.0074 0.41201 21.0074H34.763C34.804 21.0074 34.8353 21.0451 34.8272 21.0855ZM17.4686 0.000392079C27.2365 -0.0640954 35.175 7.83464 35.175 17.5876C35.175 18.0162 35.1597 18.4412 35.1297 18.8623C35.1274 18.8965 35.0988 18.9229 35.0646 18.9229H0.110743C0.076545 18.9229 0.0478839 18.8965 0.045604 18.8623C0.0156401 18.4467 0.000332489 18.0269 6.79435e-06 17.6035C-0.00846126 8.0343 7.89972 0.0639025 17.4686 0.000392079Z",fill:"black"}),(0,le.jsx)("path",{d:"M28.2533 31.4621C28.2999 31.4621 28.3204 31.5214 28.2833 31.5498C25.3198 33.8234 21.6115 35.1751 17.5875 35.1751C13.5635 35.1751 9.85519 33.8238 6.8917 31.5498C6.85457 31.5214 6.87509 31.4621 6.92166 31.4621H28.2537H28.2533ZM32.8411 26.3487C32.2268 27.416 31.5034 28.4127 30.6869 29.3236C30.656 29.3582 30.6117 29.3777 30.5654 29.3777H4.60988C4.56364 29.3777 4.51934 29.3582 4.4884 29.3236C3.67156 28.4127 2.94852 27.416 2.33426 26.3487C2.30918 26.3054 2.34077 26.251 2.39093 26.251H32.7844C32.8346 26.251 32.8661 26.3054 32.8411 26.3487ZM34.8272 21.0855C34.6181 22.1209 34.3181 23.1234 33.9361 24.0845C33.9162 24.134 33.868 24.1666 33.8146 24.1666H1.36043C1.30702 24.1666 1.25882 24.134 1.23895 24.0845C0.856909 23.1237 0.556944 22.1212 0.347848 21.0855C0.339706 21.0451 0.370647 21.0074 0.41201 21.0074H34.763C34.804 21.0074 34.8353 21.0451 34.8272 21.0855ZM17.4686 0.000392079C27.2365 -0.0640954 35.175 7.83464 35.175 17.5876C35.175 18.0162 35.1597 18.4412 35.1297 18.8623C35.1274 18.8965 35.0988 18.9229 35.0646 18.9229H0.110743C0.076545 18.9229 0.0478839 18.8965 0.045604 18.8623C0.0156401 18.4467 0.000332489 18.0269 6.79435e-06 17.6035C-0.00846126 8.0343 7.89972 0.0639025 17.4686 0.000392079Z",fill:"#FF983B"})]})};function IT(){return(0,le.jsxs)("div",{className:"min-h-screen bg-[#F8FAFC] flex flex-col relative overflow-hidden font-base44",children:[(0,le.jsx)("div",{className:"absolute right-0 top-1/2 transform -translate-y-1/2 w-[50%] h-[100%] rounded-full opacity-60 blur-3xl",style:{background:"radial-gradient(circle, #FF5500 10%, #FFEAA6 70%)",right:"-25%",top:"50%"}}),(0,le.jsx)("div",{className:"md:px-[60px] px-[16px] md:py-[24px] py-[16px]",children:(0,le.jsxs)("div",{className:"flex items-center space-x-3 h-[44px]",children:[(0,le.jsx)(ET,{width:32,height:32}),(0,le.jsx)("span",{className:"text-xl font-semibold text-slate-800",children:"Base 44"})]})}),(0,le.jsx)("div",{className:"flex-1 flex items-center md:px-[90px] px-[16px]",children:(0,le.jsxs)("div",{className:" w-full",children:[(0,le.jsxs)("h1",{className:"md:text-[100px] text-[42px] md:font-medium text-[#001E36] md:leading-[109px] tracking-[-1px] mb-6",children:["Your app is",(0,le.jsx)("br",{}),"waiting to shine!"]}),(0,le.jsxs)("div",{className:"md:text-[28px] text-[18px] font-normal text-black space-y-2",children:[(0,le.jsx)("p",{children:"But it isn't live yet."}),(0,le.jsx)("p",{children:"Publish it to make it visible here."})]})]})})]})}const TT=()=>(0,le.jsx)("div",{className:"flex flex-col items-center justify-center min-h-screen bg-gradient-to-b from-white to-gray-50",children:(0,le.jsx)("div",{className:"max-w-md w-full p-8 bg-white rounded-lg shadow-lg border border-gray-100",children:(0,le.jsxs)("div",{className:"text-center",children:[(0,le.jsx)("div",{className:"inline-flex items-center justify-center w-16 h-16 mb-6 rounded-full bg-red-100",children:(0,le.jsx)("svg",{className:"w-8 h-8 text-red-600",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,le.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})})}),(0,le.jsx)("h1",{className:"text-3xl font-bold text-gray-900 mb-4",children:"Access Restricted"}),(0,le.jsx)("p",{className:"text-gray-600 mb-8",children:"You are not registered to use this application. Please contact the app administrator to request access."}),(0,le.jsxs)("div",{className:"p-4 bg-gray-50 rounded-md text-sm text-gray-600",children:[(0,le.jsx)("p",{children:"If you believe this is an error, you can:"}),(0,le.jsxs)("ul",{className:"list-disc list-inside mt-2 space-y-1",children:[(0,le.jsx)("li",{children:"Verify you are logged in with the correct account"}),(0,le.jsx)("li",{children:"Contact the app administrator for access"}),(0,le.jsx)("li",{children:"Try logging out and back in again"})]})]})]})})});function PT(e){var t,s,a,n;let{appId:l}=e;const{isAuthenticated:r,isLoadingAuth:i,logout:o}=BA(),c=(0,Z.zy)(),d=(0,Z.Zp)(),{appId:m,pageName:u}=(0,Z.g)(),[x,h]=(0,Y.useState)(null),[p,g]=(0,Y.useState)(null),[f,v]=(0,Y.useState)(!0),[b,j]=(0,Y.useState)(!1),y=e=>{const t=new kT(e,{cn:Pe,localStorage:YA()},(t,s,a,n)=>{e.options.onError(t,s,a,n)}),s=e.getCurrentPage();if(!s)return void g((0,le.jsx)(ST,{}));const a=t.render("pages/"+s.name);if(e.files.layout){const e=t.render("layout",{currentPageName:null==s?void 0:s.name},[a]);g(e)}else g(a)};(0,Y.useEffect)(()=>{WA({id:l||m,onError:N,authProps:{isLoadingAuth:i,logout:o,isUserAuthenticated:()=>r}}).then(e=>{h(e)}).catch(e=>{var t,s,a,n,l,r,i,o,c,d;e.response&&403===e.response.status&&null!==(t=e.response.data)&&void 0!==t&&null!==(s=t.extra_data)&&void 0!==s&&s.reason?"auth_required"===(null===(a=e.response.data)||void 0===a||null===(n=a.extra_data)||void 0===n?void 0:n.reason)?k(null===(c=e.response.data)||void 0===c||null===(d=c.extra_data)||void 0===d?void 0:d.app_id):"user_not_registered"===(null===(l=e.response.data)||void 0===l||null===(r=l.extra_data)||void 0===r?void 0:r.reason)?v(!1):"not_deployed"===(null===(i=e.response.data)||void 0===i||null===(o=i.extra_data)||void 0===o?void 0:o.reason)&&j(!0):N("Failed to load app "+e.message,"none","general",e)})},[]);const N=(e,t,s,a)=>{var n,l;402!==(null==a||null===(n=a.response)||void 0===n?void 0:n.status)&&(null===(l=window.parent)||void 0===l||l.postMessage({type:"app_error",error:{title:e.toString(),details:null==t?void 0:t.toString(),componentName:null==s?void 0:s.toString()}},"*"))};(0,Y.useEffect)(()=>{window.parent.postMessage({type:"app_changed_url",url:window.location.href},"*"),x&&y(x)},[c,u,x]);const w=e=>{var t;const s=null===(t=e.reason.stack.match(/at\s+(\w+)\s+\(eval/))||void 0===t?void 0:t[1],a=s?"Error in ".concat(s,": ").concat(e.reason.toString()):e.reason.toString();N(a,e.reason.toString(),s,e.reason)},_=e=>{var t,s;let a=null===(s=(null===(t=e.error)||void 0===t?void 0:t.stack).match(/at\s+(\w+)\s+\(eval/))||void 0===s?void 0:s[1];"eval"===a&&(a=null);const n=a?"in ".concat(a,": ").concat(e.error.toString()):e.error.toString();N(n,e.error.toString(),a,e.error)};(0,Y.useEffect)(()=>(window.addEventListener("unhandledrejection",w),window.addEventListener("error",_),()=>{window.removeEventListener("unhandledrejection",w),window.removeEventListener("error",_)}),[]);const k=e=>{d("/login?from_url=".concat(window.location.href,"&app_id=").concat(e))};return(0,Y.useEffect)(()=>{let e=null==x?void 0:x.getCurrentPage();r&&null!=x&&x.appId&&null!=e&&e.name&&wa.logUserInApp(x.appId,e.name)},[r,null==x?void 0:x.appId,null==x||null===(t=x.getCurrentPage())||void 0===t?void 0:t.name]),f?b?(0,le.jsx)(IT,{}):x?i?(0,le.jsx)("div",{className:"fixed inset-0 flex items-center justify-center",children:(0,le.jsx)("div",{className:"w-8 h-8 border-4 border-gray-200 border-t-black rounded-full animate-spin"})}):(0,le.jsxs)("div",{className:"min-h-screen w-full relative app-preview",children:[(0,le.jsx)(CT,{}),(null==x||null===(s=x.files)||void 0===s?void 0:s.is_remixable)&&(null==x||null===(a=x.files)||void 0===a||null===(n=a.public_settings)||void 0===n?void 0:n.includes("public"))&&(0,le.jsx)(AT,{appId:l}),(0,le.jsx)("div",{className:"flex flex-col w-full h-full",id:"app-demo",children:(0,le.jsx)("div",{className:"bg-white w-full min-h-full overflow-auto",children:(0,le.jsx)("div",{id:"component-preview-container",children:p})})})]}):(0,le.jsx)("div",{className:"fixed inset-0 flex items-center justify-center",children:(0,le.jsx)("div",{className:"flex flex-col items-center space-y-4",children:(0,le.jsx)("div",{className:"w-12 h-12 border-4 border-gray-200 border-t-black rounded-full animate-spin"})})}):(0,le.jsx)(TT,{})}function LT(e){let{appId:t,appPlatformVersion:s,authSDK:a,onSuccess:n,onSwitchToRegister:l,onSwitchToResetPassword:r}=e;const[i,o]=(0,Y.useState)(""),[c,d]=(0,Y.useState)(""),[m,u]=(0,Y.useState)(""),[x,h]=(0,Y.useState)(!1);return(0,le.jsxs)("form",{onSubmit:async e=>{e.preventDefault(),u(""),h(!0);try{if(3===s){const e=(0,_T.createClient)({appId:t,serverUrl:(0,ee.wE)()}),s=await e.auth.loginViaEmailPassword(i,c);s&&n(s.user)}else{const e=await a.loginViaUsernamePassword(i,c);e&&((0,ne.O5)(e.access_token),n(e.user))}}catch(o){var l,r;u((null===(l=o.response)||void 0===l||null===(r=l.data)||void 0===r?void 0:r.detail)||"Invalid email or password")}finally{h(!1)}},className:"space-y-4 sm:space-y-5",children:[(0,le.jsxs)("div",{className:"space-y-3 sm:space-y-4",children:[(0,le.jsxs)("div",{className:"space-y-1.5",children:[(0,le.jsx)(Ns,{htmlFor:"email",className:"text-sm font-medium text-slate-700",children:"Email"}),(0,le.jsxs)("div",{className:"relative",children:[(0,le.jsx)(Uh.A,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-slate-400"}),(0,le.jsx)(fs,{id:"email",type:"email",placeholder:"you@example.com",value:i,onChange:e=>o(e.target.value),required:!0,disabled:x,className:"pl-10 h-11 sm:h-12 bg-slate-50/50 border-slate-200 focus:border-slate-400 focus:ring-slate-400 rounded-xl placeholder:text-slate-400"})]})]}),(0,le.jsxs)("div",{className:"space-y-1.5",children:[(0,le.jsx)(Ns,{htmlFor:"password",className:"text-sm font-medium text-slate-700",children:"Password"}),(0,le.jsxs)("div",{className:"relative",children:[(0,le.jsx)(Mt.A,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-slate-400"}),(0,le.jsx)(fs,{id:"password",type:"password",placeholder:"\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022",value:c,onChange:e=>d(e.target.value),required:!0,disabled:x,className:"pl-10 h-11 sm:h-12 bg-slate-50/50 border-slate-200 focus:border-slate-400 focus:ring-slate-400 rounded-xl placeholder:text-slate-400"})]})]})]}),m&&(0,le.jsx)(De,{className:"bg-red-50/70 border-red-200 rounded-xl",children:(0,le.jsx)(Be,{className:"text-red-700 text-sm",children:m})}),(0,le.jsxs)("div",{className:"space-y-3",children:[(0,le.jsx)(Yt,{type:"submit",disabled:x,className:"w-full h-11 sm:h-12 bg-slate-900 hover:bg-slate-800 text-white font-medium shadow-sm rounded-xl transition-all duration-200",children:x?(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(Ne.A,{className:"mr-2 h-4 w-4 animate-spin"}),"Signing in..."]}):"Sign in"}),(0,le.jsxs)("div",{className:"flex flex-col sm:flex-row items-center justify-between gap-2 sm:gap-0",children:[(0,le.jsx)("button",{type:"button",onClick:r,className:"text-sm text-slate-500 hover:text-slate-700 font-medium transition-colors",children:"Forgot password?"}),(0,le.jsxs)("button",{type:"button",onClick:l,className:"text-sm text-slate-500 hover:text-slate-700 transition-colors",children:["Need an account? ",(0,le.jsx)("span",{className:"font-medium text-slate-700",children:"Sign up"})]})]})]})]})}function OT(e){let{authSDK:t,onSuccess:s,onSwitchToLogin:a,onSwitchToOtpVerification:n}=e;const[l,r]=(0,Y.useState)({email:"",password:"",confirmPassword:""}),[i,o]=(0,Y.useState)(""),[c,d]=(0,Y.useState)(!1),m=(e,t)=>{r(s=>(0,K.A)((0,K.A)({},s),{},{[e]:t}))};return(0,le.jsxs)("div",{className:"space-y-4",children:[(0,le.jsxs)("button",{type:"button",onClick:a,className:"flex items-center gap-2 text-sm text-slate-500 hover:text-slate-700 font-medium transition-colors -mb-2",children:[(0,le.jsx)(Cd.A,{className:"h-4 w-4"}),"Back to sign in"]}),(0,le.jsx)("h2",{className:"text-xl sm:text-2xl font-bold text-slate-900",children:"Create your account"}),(0,le.jsxs)("form",{onSubmit:async e=>{if(e.preventDefault(),o(""),l.password===l.confirmPassword)if(l.password.length<8)o("Password must be at least 8 characters long");else{d(!0);try{await t.register({email:l.email,password:l.password})&&n(l.email)}catch(r){var s,a;o((null===(s=r.response)||void 0===s||null===(a=s.data)||void 0===a?void 0:a.detail)||"Registration failed. Please try again.")}finally{d(!1)}}else o("Passwords do not match")},className:"space-y-3 sm:space-y-4",children:[(0,le.jsxs)("div",{className:"space-y-3",children:[(0,le.jsxs)("div",{className:"space-y-1.5",children:[(0,le.jsx)(Ns,{htmlFor:"email",className:"text-sm font-medium text-slate-700",children:"Email"}),(0,le.jsxs)("div",{className:"relative",children:[(0,le.jsx)(Uh.A,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-slate-400"}),(0,le.jsx)(fs,{id:"email",type:"email",placeholder:"you@example.com",value:l.email,onChange:e=>m("email",e.target.value),required:!0,disabled:c,className:"pl-10 h-10 sm:h-11 bg-slate-50/50 border-slate-200 focus:border-slate-400 focus:ring-slate-400 rounded-xl placeholder:text-slate-400 text-sm sm:text-base"})]})]}),(0,le.jsxs)("div",{className:"space-y-1.5",children:[(0,le.jsx)(Ns,{htmlFor:"password",className:"text-sm font-medium text-slate-700",children:"Password"}),(0,le.jsxs)("div",{className:"relative",children:[(0,le.jsx)(Mt.A,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-slate-400"}),(0,le.jsx)(fs,{id:"password",type:"password",placeholder:"Min. 8 characters",value:l.password,onChange:e=>m("password",e.target.value),required:!0,disabled:c,className:"pl-10 h-10 sm:h-11 bg-slate-50/50 border-slate-200 focus:border-slate-400 focus:ring-slate-400 rounded-xl placeholder:text-slate-400 text-sm sm:text-base"})]})]}),(0,le.jsxs)("div",{className:"space-y-1.5",children:[(0,le.jsx)(Ns,{htmlFor:"confirmPassword",className:"text-sm font-medium text-slate-700",children:"Confirm Password"}),(0,le.jsxs)("div",{className:"relative",children:[(0,le.jsx)(Mt.A,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-slate-400"}),(0,le.jsx)(fs,{id:"confirmPassword",type:"password",placeholder:"Re-enter password",value:l.confirmPassword,onChange:e=>m("confirmPassword",e.target.value),required:!0,disabled:c,className:"pl-10 h-10 sm:h-11 bg-slate-50/50 border-slate-200 focus:border-slate-400 focus:ring-slate-400 rounded-xl placeholder:text-slate-400 text-sm sm:text-base"})]})]})]}),i&&(0,le.jsx)(De,{className:"bg-red-50/70 border-red-200 rounded-xl",children:(0,le.jsx)(Be,{className:"text-red-700 text-sm",children:i})}),(0,le.jsx)(Yt,{type:"submit",disabled:c,className:"w-full h-10 sm:h-11 bg-slate-900 hover:bg-slate-800 text-white font-medium shadow-sm rounded-xl transition-all duration-200",children:c?(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(Ne.A,{className:"mr-2 h-4 w-4 animate-spin"}),"Creating account..."]}):"Create account"})]})]})}function RT(e){let{authSDK:t,email:s,onSuccess:a,onSwitchToLogin:n}=e;const[l,r]=(0,Y.useState)(["","","","","",""]),[i,o]=(0,Y.useState)(""),[c,d]=(0,Y.useState)(""),[m,u]=(0,Y.useState)(!1),[x,h]=(0,Y.useState)(!1),p=(0,Y.useRef)([]);(0,Y.useEffect)(()=>{var e;null===(e=p.current[0])||void 0===e||e.focus()},[]);const g=e=>{e.preventDefault();const t=e.clipboardData.getData("text").slice(0,6),s=[...l];for(let l=0;l!e);var n,i;-1!==a?null===(n=p.current[a])||void 0===n||n.focus():null===(i=p.current[5])||void 0===i||i.focus()};return(0,le.jsxs)("div",{className:"space-y-4 sm:space-y-6",children:[(0,le.jsxs)("button",{type:"button",onClick:n,className:"flex items-center gap-2 text-sm text-slate-500 hover:text-slate-700 font-medium transition-colors -mb-2",children:[(0,le.jsx)(Cd.A,{className:"h-4 w-4"}),"Back to sign in"]}),(0,le.jsxs)("div",{className:"text-center space-y-2",children:[(0,le.jsx)("div",{className:"mx-auto w-14 h-14 sm:w-16 sm:h-16 bg-slate-100 rounded-full flex items-center justify-center mb-3 sm:mb-4",children:(0,le.jsx)(qc.A,{className:"h-7 w-7 sm:h-8 sm:w-8 text-slate-700"})}),(0,le.jsx)("h2",{className:"text-xl sm:text-2xl font-bold text-slate-900",children:"Verify your email"}),(0,le.jsxs)("p",{className:"text-slate-600 text-sm sm:text-base",children:["We've sent a 6-digit code to",(0,le.jsx)("br",{}),(0,le.jsx)("span",{className:"font-medium text-slate-900",children:s})]})]}),(0,le.jsxs)("form",{onSubmit:async e=>{e.preventDefault(),o(""),d("");const a=l.join("");if(6===a.length){u(!0);try{await t.verifyOtp(s,a)&&(d("Email verified successfully! Redirecting to login..."),setTimeout(()=>{n()},2e3))}catch(c){var r,i;o((null===(r=c.response)||void 0===r||null===(i=r.data)||void 0===i?void 0:i.detail)||"Invalid verification code")}finally{u(!1)}}else o("Please enter all 6 digits")},className:"space-y-4 sm:space-y-6",children:[(0,le.jsxs)("div",{children:[(0,le.jsx)("div",{className:"flex gap-2 justify-center",children:l.map((e,t)=>(0,le.jsx)(fs,{ref:e=>p.current[t]=e,type:"text",inputMode:"numeric",pattern:"\\d{1}",maxLength:1,value:e,onChange:e=>((e,t)=>{if(t.length>1)return;const s=[...l];var a;s[e]=t,r(s),t&&e<5&&(null===(a=p.current[e+1])||void 0===a||a.focus())})(t,e.target.value),onKeyDown:e=>((e,t)=>{var s;"Backspace"===t.key&&!l[e]&&e>0&&(null===(s=p.current[e-1])||void 0===s||s.focus())})(t,e),onPaste:0===t?g:void 0,disabled:m||x,className:"w-11 h-11 sm:w-12 sm:h-12 text-center text-lg font-semibold bg-slate-50/50 border-slate-200 focus:border-slate-400 focus:ring-slate-400 rounded-xl"},t))}),(0,le.jsx)("p",{className:"text-xs text-slate-500 text-center mt-3",children:"Enter the verification code sent to your email"})]}),i&&(0,le.jsx)(De,{className:"bg-red-50/70 border-red-200 rounded-xl",children:(0,le.jsx)(Be,{className:"text-red-700 text-sm",children:i})}),c&&(0,le.jsx)(De,{className:"bg-green-50/70 border-green-200 rounded-xl",children:(0,le.jsx)(Be,{className:"text-green-700 text-sm",children:c})}),(0,le.jsxs)("div",{className:"space-y-3",children:[(0,le.jsx)(Yt,{type:"submit",disabled:m||x,className:"w-full h-10 sm:h-11 bg-slate-900 hover:bg-slate-800 text-white font-medium shadow-sm rounded-xl transition-all duration-200",children:m?(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(Ne.A,{className:"mr-2 h-4 w-4 animate-spin"}),"Verifying..."]}):"Verify email"}),(0,le.jsx)("div",{className:"text-center",children:(0,le.jsxs)("p",{className:"text-sm text-slate-600",children:["Didn't receive the code?"," ",(0,le.jsx)("button",{type:"button",onClick:async()=>{o(""),d(""),h(!0);try{var e;await t.resendOtp(s),d("New verification code sent to your email"),r(["","","","","",""]),null===(e=p.current[0])||void 0===e||e.focus()}catch(l){var a,n;o((null===(a=l.response)||void 0===a||null===(n=a.data)||void 0===n?void 0:n.detail)||"Failed to resend code")}finally{h(!1)}},disabled:x||m,className:"font-medium text-slate-700 hover:text-slate-900 disabled:opacity-50 transition-colors",children:x?"Sending...":"Resend"})]})})]})]})]})}function MT(e){let{authSDK:t,onSwitchToLogin:s}=e;const[a,n]=(0,Y.useState)(""),[l,r]=(0,Y.useState)(""),[i,o]=(0,Y.useState)(!1),[c,d]=(0,Y.useState)(!1);return i?(0,le.jsxs)("div",{className:"space-y-4 sm:space-y-6",children:[(0,le.jsxs)("div",{className:"text-center space-y-3 sm:space-y-4",children:[(0,le.jsx)("div",{className:"mx-auto w-14 h-14 sm:w-16 sm:h-16 bg-slate-100 rounded-full flex items-center justify-center",children:(0,le.jsx)(Uh.A,{className:"h-7 w-7 sm:h-8 sm:w-8 text-slate-700"})}),(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsx)("h2",{className:"text-xl sm:text-2xl font-bold text-slate-900",children:"Check your email"}),(0,le.jsxs)("p",{className:"text-slate-600 text-sm sm:text-base",children:["We've sent password reset instructions to",(0,le.jsx)("br",{}),(0,le.jsx)("span",{className:"font-medium text-slate-900",children:a})]})]})]}),(0,le.jsx)(De,{className:"bg-green-50/70 border-green-200 rounded-xl",children:(0,le.jsx)(Be,{className:"text-green-700 text-sm",children:"Please check your email for the password reset link. It may take a few minutes to arrive."})}),(0,le.jsxs)("button",{onClick:s,className:"w-full flex items-center justify-center gap-2 text-sm text-slate-500 hover:text-slate-700 font-medium transition-colors",children:[(0,le.jsx)(Cd.A,{className:"h-4 w-4"}),"Back to sign in"]})]}):(0,le.jsxs)("div",{className:"space-y-4 sm:space-y-6",children:[(0,le.jsxs)("button",{type:"button",onClick:s,className:"flex items-center gap-2 text-sm text-slate-500 hover:text-slate-700 font-medium transition-colors -mb-2",children:[(0,le.jsx)(Cd.A,{className:"h-4 w-4"}),"Back to sign in"]}),(0,le.jsxs)("div",{className:"text-center space-y-2",children:[(0,le.jsx)("h2",{className:"text-xl sm:text-2xl font-bold text-slate-900",children:"Reset your password"}),(0,le.jsx)("p",{className:"text-slate-600 text-sm sm:text-base",children:"Enter your email and we'll send you a link to reset your password"})]}),(0,le.jsxs)("form",{onSubmit:async e=>{e.preventDefault(),r(""),o(!1),d(!0);try{await t.resetPasswordRequest(a),o(!0)}catch(l){var s,n;r((null===(s=l.response)||void 0===s||null===(n=s.data)||void 0===n?void 0:n.detail)||"Failed to send reset email")}finally{d(!1)}},className:"space-y-4 sm:space-y-5",children:[(0,le.jsxs)("div",{className:"space-y-1.5",children:[(0,le.jsx)(Ns,{htmlFor:"email",className:"text-sm font-medium text-slate-700",children:"Email"}),(0,le.jsxs)("div",{className:"relative",children:[(0,le.jsx)(Uh.A,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-slate-400"}),(0,le.jsx)(fs,{id:"email",type:"email",placeholder:"you@example.com",value:a,onChange:e=>n(e.target.value),required:!0,disabled:c,className:"pl-10 h-10 sm:h-11 bg-slate-50/50 border-slate-200 focus:border-slate-400 focus:ring-slate-400 rounded-xl placeholder:text-slate-400"})]})]}),l&&(0,le.jsx)(De,{className:"bg-red-50/70 border-red-200 rounded-xl",children:(0,le.jsx)(Be,{className:"text-red-700 text-sm",children:l})}),(0,le.jsx)(Yt,{type:"submit",disabled:c,className:"w-full h-10 sm:h-11 bg-slate-900 hover:bg-slate-800 text-white font-medium shadow-sm rounded-xl transition-all duration-200",children:c?(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(Ne.A,{className:"mr-2 h-4 w-4 animate-spin"}),"Sending..."]}):"Send reset link"})]})]})}const DT=()=>(0,le.jsxs)("svg",{className:"h-5 w-5",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:[(0,le.jsx)("path",{d:"M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z",fill:"#4285F4"}),(0,le.jsx)("path",{d:"M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z",fill:"#34A853"}),(0,le.jsx)("path",{d:"M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z",fill:"#FBBC05"}),(0,le.jsx)("path",{d:"M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z",fill:"#EA4335"})]}),FT=()=>(0,le.jsxs)("svg",{className:"h-5 w-5",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:[(0,le.jsx)("path",{fill:"#F25022",d:"M1 1h10v10H1z"}),(0,le.jsx)("path",{fill:"#00A4EF",d:"M13 1h10v10H13z"}),(0,le.jsx)("path",{fill:"#7FBA00",d:"M1 13h10v10H1z"}),(0,le.jsx)("path",{fill:"#FFB900",d:"M13 13h10v10H13z"})]}),BT=()=>(0,le.jsx)("svg",{className:"h-5 w-5",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:(0,le.jsx)("path",{fill:"#1877F2",d:"M24 12.073c0-6.627-5.373-12-12-12s-12 5.373-12 12c0 5.99 4.388 10.954 10.125 11.854v-8.385H7.078v-3.47h3.047V9.43c0-3.007 1.792-4.669 4.533-4.669 1.312 0 2.686.235 2.686.235v2.953H15.83c-1.491 0-1.956.925-1.956 1.874v2.25h3.328l-.532 3.47h-2.796v8.385C19.612 23.027 24 18.062 24 12.073z"})}),zT={google:{name:"Google",icon:DT},microsoft:{name:"Microsoft",icon:FT},github:{name:"GitHub",icon:()=>(0,le.jsx)("svg",{className:"h-5 w-5",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:(0,le.jsx)("path",{fill:"#181717",d:"M12 0c-6.626 0-12 5.373-12 12 0 5.302 3.438 9.8 8.207 11.387.599.111.793-.261.793-.577v-2.234c-3.338.726-4.033-1.416-4.033-1.416-.546-1.387-1.333-1.756-1.333-1.756-1.089-.745.083-.729.083-.729 1.205.084 1.839 1.237 1.839 1.237 1.07 1.834 2.807 1.304 3.492.997.107-.775.418-1.305.762-1.604-2.665-.305-5.467-1.334-5.467-5.931 0-1.311.469-2.381 1.236-3.221-.124-.303-.535-1.524.117-3.176 0 0 1.008-.322 3.301 1.23.957-.266 1.983-.399 3.003-.404 1.02.005 2.047.138 3.006.404 2.291-1.552 3.297-1.23 3.297-1.23.653 1.653.242 2.874.118 3.176.77.84 1.235 1.911 1.235 3.221 0 4.609-2.807 5.624-5.479 5.921.43.372.823 1.102.823 2.222v3.293c0 .319.192.694.801.576 4.765-1.589 8.199-6.086 8.199-11.386 0-6.627-5.373-12-12-12z"})})},okta:{name:"Okta",icon:()=>(0,le.jsx)("svg",{className:"h-5 w-5",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:(0,le.jsx)("path",{fill:"#007DC1",d:"M12 0C5.383 0 0 5.383 0 12s5.383 12 12 12 12-5.383 12-12S18.617 0 12 0zm0 4.8c3.971 0 7.2 3.229 7.2 7.2s-3.229 7.2-7.2 7.2S4.8 15.971 4.8 12 8.029 4.8 12 4.8z"})})}};function UT(e){var t;let{appId:s}=e;const a=(0,Z.zy)(),n=UA(s,()=>{},{}),[l,r]=(0,Y.useState)(!0),[i,o]=(0,Y.useState)(null),[c,d]=(0,Y.useState)(null),[m,u]=(0,Y.useState)("login"),[x,h]=(0,Y.useState)(""),[p,g]=(0,Y.useState)(!1),f=new URLSearchParams(a.search),v=e=>{const t=qy(f.get("from_url"),"/"),a=f.get("app_id")||s;let n;n="google"===e?"".concat((0,ee.Zk)(),"/apps/auth/login?from_url=").concat(encodeURIComponent(t)):"".concat((0,ee.Zk)(),"/apps/auth/").concat(e,"/login?from_url=").concat(encodeURIComponent(t)),a&&(n+="&app_id=".concat(a)),window.location.href=n},b=()=>{const e=qy(f.get("from_url"),"/"),t=f.get("app_id")||s;let a;N.use_workspace_sso&&null!=c&&c.organization_id?a="".concat((0,ee.Zk)(),"/apps/").concat(c.organization_id,"/").concat(t,"/auth/sso/login?from_url=").concat(encodeURIComponent(e)):(a="".concat((0,ee.Zk)(),"/apps/").concat(t,"/auth/sso/login?from_url=").concat(encodeURIComponent(e)),t&&(a+="&app_id=".concat(t))),window.location.href=a},j=e=>{const t=qy(f.get("from_url"),"/");window.location.href=t},y=e=>{h(e),u("otp")},N=yg(c),w=[{id:"google",name:"Google",enabled:!1!==N.enable_google_login,handler:()=>v("google"),icon:DT},{id:"microsoft",name:"Microsoft",enabled:N.enable_microsoft_login,handler:()=>v("microsoft"),icon:FT},{id:"facebook",name:"Facebook",enabled:N.enable_facebook_login,handler:()=>v("facebook"),icon:BT}],_=N.enable_sso_login||N.use_workspace_sso?[]:w.filter(e=>e.enabled),k=e=>{const t=e.icon;return(0,le.jsxs)("button",{onClick:e.handler,className:"w-full flex items-center justify-center gap-3 bg-white text-slate-700 px-5 py-3.5 rounded-xl border border-slate-200 hover:bg-slate-50 hover:border-slate-300 hover:shadow-sm transition-all duration-200 font-medium text-[16px] group",children:[(0,le.jsx)("div",{className:" transition-transform duration-200 ".concat("google"===e.id?"-ml-4":""),children:(0,le.jsx)(t,{})}),(0,le.jsxs)("span",{children:["Continue with ",e.name]})]},e.id)},C=()=>{if(!N.sso_provider_name||!1===N.enable_sso_login)return null;const e=zT[N.sso_provider_name],t=e?"Continue with ".concat(e.name):"Continue with ".concat(N.sso_provider_name," SSO"),s=null==e?void 0:e.icon;return(0,le.jsxs)("button",{onClick:b,className:"w-full flex items-center justify-center gap-3 bg-white text-slate-700 px-5 py-3.5 rounded-xl border border-slate-200 hover:bg-slate-50 hover:border-slate-300 hover:shadow-sm transition-all duration-200 font-medium text-[15px] group",children:[s&&(0,le.jsx)("div",{className:"group-hover:scale-110 transition-transform duration-200",children:(0,le.jsx)(s,{})}),(0,le.jsx)("span",{children:t})]})};if((0,Y.useEffect)(()=>{(async()=>{try{const e=await ve.getLoginInfoById(s);if(e.not_published)return g(!0),void r(!1);d(e),r(!1)}catch(i){o(i),r(!1)}})()},[s]),l)return(0,le.jsx)("div",{className:"min-h-screen flex items-center justify-center bg-gradient-to-br from-slate-50 to-slate-100",children:(0,le.jsx)("div",{className:"p-8",children:(0,le.jsx)(Ne.A,{className:"h-10 w-10 animate-spin text-slate-400"})})});if(p)return(0,le.jsx)(IT,{});if(i)return(0,le.jsx)("div",{className:"min-h-screen flex items-center justify-center bg-gradient-to-br from-slate-50 to-slate-100",children:(0,le.jsx)("div",{className:"p-8 text-base font-medium text-red-600 bg-white rounded-2xl shadow-sm border border-red-100",children:"An error occurred while loading the app"})});return(0,le.jsx)("div",{className:"min-h-screen flex items-center justify-center bg-gradient-to-br from-slate-50 to-slate-100 p-4",children:(0,le.jsxs)("div",{className:"w-full max-w-md",children:[(0,le.jsxs)(is,{className:"relative overflow-hidden border-0 shadow-2xl bg-white/95 backdrop-blur-sm rounded-2xl",children:[(0,le.jsx)("div",{className:"absolute top-0 left-0 right-0 h-1 bg-gradient-to-r from-slate-200 via-slate-300 to-slate-200"}),(0,le.jsx)(ms,{className:"p-8 sm:p-10 md:pt-12 md:pb-10 md:px-10",children:(0,le.jsxs)("div",{className:"flex flex-col items-center text-center space-y-6 sm:space-y-8",children:[(null==c?void 0:c.logo_url)&&"login"===m&&(0,le.jsxs)("div",{className:"relative group",children:[(0,le.jsx)("div",{className:"absolute inset-0 bg-gradient-to-br from-slate-200 to-slate-300 rounded-full blur-xl opacity-30 group-hover:opacity-40 transition-opacity duration-300"}),(0,le.jsxs)(ma,{className:"relative h-20 w-20 sm:h-24 sm:w-24 shadow-lg ring-4 ring-white/50 group-hover:shadow-xl transition-all duration-300",children:[(0,le.jsx)(ua,{src:c.logo_url,alt:"".concat(c.name," logo"),className:"object-cover"}),(0,le.jsx)(xa,{className:"bg-gradient-to-br from-slate-100 to-slate-200 text-xl sm:text-2xl font-bold text-slate-700",children:null===(t=c.name)||void 0===t?void 0:t[0]})]})]}),"login"===m&&(0,le.jsxs)("div",{className:"space-y-2 sm:space-y-3",children:[(0,le.jsxs)("h1",{className:"text-2xl sm:text-3xl font-bold text-slate-900 tracking-tight",children:["Welcome to ",null==c?void 0:c.name]}),(0,le.jsx)("p",{className:"text-slate-500 text-sm sm:text-base font-medium",children:"Sign in to continue"})]}),(0,le.jsx)("div",{className:"w-full",children:(()=>{if(N.enable_username_password)switch(m){case"register":return(0,le.jsx)(OT,{authSDK:n,onSuccess:j,onSwitchToLogin:()=>u("login"),onSwitchToOtpVerification:y});case"otp":return(0,le.jsx)(RT,{authSDK:n,email:x,onSuccess:j,onSwitchToLogin:()=>u("login")});case"reset":return(0,le.jsx)(MT,{authSDK:n,onSwitchToLogin:()=>u("login")});default:return(0,le.jsxs)(le.Fragment,{children:[(0,le.jsxs)("div",{className:"space-y-3",children:[_.map(e=>k(e)),C()]}),(_.length>0||C())&&(0,le.jsxs)("div",{className:"relative my-6",children:[(0,le.jsx)("div",{className:"absolute inset-0 flex items-center",children:(0,le.jsx)(ps,{className:"w-full bg-slate-200"})}),(0,le.jsx)("div",{className:"relative flex justify-center text-xs uppercase",children:(0,le.jsx)("span",{className:"bg-white px-3 text-slate-400 font-medium tracking-wider",children:"or"})})]}),(0,le.jsx)(LT,{appId:s,appPlatformVersion:null==c?void 0:c.platform_version,authSDK:n,onSuccess:j,onSwitchToRegister:()=>u("register"),onSwitchToResetPassword:()=>u("reset")})]})}return(0,le.jsxs)("div",{className:"space-y-3",children:[_.map(e=>k(e)),C()]})})()})]})})]}),(0,le.jsx)("div",{className:"mt-8 text-center text-xs text-slate-400 sm:hidden",children:(0,le.jsx)("p",{children:"\xa0"})})]})})}function WT(e){let{appId:t}=e;const s=(0,Z.zy)(),a=(0,Z.Zp)(),n=UA(t,()=>{},{}),l=new URLSearchParams(s.search).get("token"),[r,i]=(0,Y.useState)({password:"",confirmPassword:""}),[o,c]=(0,Y.useState)(""),[d,m]=(0,Y.useState)(!1),[u,x]=(0,Y.useState)(!1),[h,p]=(0,Y.useState)(null),[g,f]=(0,Y.useState)(!0);(0,Y.useEffect)(()=>{(async()=>{try{const e=await ve.getLoginInfoById(t);p(e)}catch(o){}finally{f(!1)}})(),l||c("Invalid reset link. Please request a new password reset.")},[l,t]);const v=(e,t)=>{i(s=>(0,K.A)((0,K.A)({},s),{},{[e]:t}))};return g?(0,le.jsx)("div",{className:"min-h-screen flex items-center justify-center bg-gray-50",children:(0,le.jsx)("div",{className:"p-8",children:(0,le.jsx)(Ne.A,{className:"h-10 w-10 animate-spin text-gray-600"})})}):u?(0,le.jsx)("div",{className:"min-h-screen flex items-center justify-center bg-gray-50 p-4",children:(0,le.jsx)(is,{className:"max-w-md w-full overflow-hidden border-0 shadow-lg bg-white",children:(0,le.jsxs)(ms,{className:"pt-12 pb-10 px-12 text-center space-y-6",children:[(0,le.jsx)("div",{className:"mx-auto w-20 h-20 bg-gray-100 rounded-full flex items-center justify-center",children:(0,le.jsx)(Vg.A,{className:"h-10 w-10 text-green-600"})}),(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsx)("h2",{className:"text-2xl font-bold text-gray-900",children:"Password reset successful!"}),(0,le.jsx)("p",{className:"text-gray-600",children:"Your password has been reset. Redirecting to login..."})]}),(null==h?void 0:h.name)&&(0,le.jsxs)("p",{className:"text-sm text-gray-500",children:["You can now sign in to ",h.name," with your new password"]})]})})}):l?(0,le.jsx)("div",{className:"min-h-screen flex items-center justify-center bg-gray-50 p-4",children:(0,le.jsxs)(is,{className:"relative max-w-md w-full overflow-hidden border-0 shadow-lg bg-white",children:[(0,le.jsx)("div",{className:"absolute top-0 left-0 right-0 h-0.5 bg-gray-900"}),(0,le.jsxs)(ms,{className:"pt-12 pb-10 px-12 space-y-8",children:[(0,le.jsxs)("div",{className:"text-center space-y-2",children:[(0,le.jsx)("h2",{className:"text-2xl font-bold text-gray-900",children:"Set new password"}),(0,le.jsx)("p",{className:"text-gray-600",children:null!=h&&h.name?"Enter your new password for ".concat(h.name):"Please enter your new password below"})]}),(0,le.jsxs)("form",{onSubmit:async e=>{if(e.preventDefault(),c(""),r.password===r.confirmPassword)if(r.password.length<8)c("Password must be at least 8 characters long");else{m(!0);try{await n.resetPassword(l,r.password),x(!0),setTimeout(()=>{a("/login")},3e3)}catch(i){var t,s;c((null===(t=i.response)||void 0===t||null===(s=t.data)||void 0===s?void 0:s.detail)||"Failed to reset password. The link may have expired.")}finally{m(!1)}}else c("Passwords do not match")},className:"space-y-6",children:[(0,le.jsxs)("div",{className:"space-y-5",children:[(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsx)(Ns,{htmlFor:"password",className:"text-sm font-medium text-gray-700",children:"New Password"}),(0,le.jsxs)("div",{className:"relative",children:[(0,le.jsx)(Mt.A,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-gray-400"}),(0,le.jsx)(fs,{id:"password",type:"password",placeholder:"\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022",value:r.password,onChange:e=>v("password",e.target.value),required:!0,disabled:d,className:"pl-10 h-11 bg-gray-50/50 border-gray-200 focus:border-gray-400 focus:ring-gray-400"})]}),(0,le.jsx)("p",{className:"text-xs text-gray-500",children:"Must be at least 8 characters"})]}),(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsx)(Ns,{htmlFor:"confirmPassword",className:"text-sm font-medium text-gray-700",children:"Confirm New Password"}),(0,le.jsxs)("div",{className:"relative",children:[(0,le.jsx)(Mt.A,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-gray-400"}),(0,le.jsx)(fs,{id:"confirmPassword",type:"password",placeholder:"\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022",value:r.confirmPassword,onChange:e=>v("confirmPassword",e.target.value),required:!0,disabled:d,className:"pl-10 h-11 bg-gray-50/50 border-gray-200 focus:border-gray-400 focus:ring-gray-400"})]})]})]}),o&&(0,le.jsx)(De,{className:"bg-red-50/50 border-red-200",children:(0,le.jsx)(Be,{className:"text-red-800 text-sm",children:o})}),(0,le.jsxs)("div",{className:"space-y-3",children:[(0,le.jsx)(Yt,{type:"submit",disabled:d,className:"w-full h-11 bg-gray-900 hover:bg-gray-800 text-white font-medium shadow-sm",children:d?(0,le.jsxs)(le.Fragment,{children:[(0,le.jsx)(Ne.A,{className:"mr-2 h-4 w-4 animate-spin"}),"Resetting password..."]}):"Reset password"}),(0,le.jsx)("button",{type:"button",onClick:()=>a("/login"),className:"w-full text-sm text-gray-600 hover:text-gray-700",children:"Back to login"})]})]})]})]})}):(0,le.jsx)("div",{className:"min-h-screen flex items-center justify-center bg-gray-50 p-4",children:(0,le.jsx)(is,{className:"max-w-md w-full overflow-hidden border-0 shadow-lg bg-white",children:(0,le.jsxs)(ms,{className:"pt-12 pb-10 px-12 text-center space-y-6",children:[(0,le.jsx)("div",{className:"mx-auto w-20 h-20 bg-red-100 rounded-full flex items-center justify-center",children:(0,le.jsx)(_e.A,{className:"h-10 w-10 text-red-600"})}),(0,le.jsxs)("div",{className:"space-y-2",children:[(0,le.jsx)("h2",{className:"text-2xl font-bold text-gray-900",children:"Invalid Reset Link"}),(0,le.jsx)("p",{className:"text-gray-600",children:"This password reset link is invalid or has expired."})]}),(0,le.jsx)(Yt,{onClick:()=>a("/login"),className:"w-full h-11 bg-gray-900 hover:bg-gray-800 text-white font-medium shadow-sm",children:"Back to Login"})]})})})}function qT(e){let{}=e;const[t,s]=(0,Y.useState)(null),[a,n]=(0,Y.useState)(null),[l,r]=(0,Y.useState)(!0),i=window.location.host.includes("localhost")?window.location.host:window.location.hostname,[o]=(0,Y.useState)(()=>new LA.E);return(0,Y.useEffect)(()=>{ve.getDomainAppId(i).then(e=>{s(e),window.appId=e,r(!1)}).catch(e=>{n(!0),r(!1)})},[]),l?(0,le.jsx)("div",{className:"fixed inset-0 flex items-center justify-center",children:(0,le.jsx)("div",{className:"w-12 h-12 border-4 border-gray-200 border-t-black rounded-full animate-spin"})}):a?(0,le.jsxs)("div",{className:"relative font-base44 w-full min-h-screen overflow-hidden bg-gradient-to-br from-slate-50 via-orange-50/30 to-orange-100/40",children:[(0,le.jsx)("div",{className:"absolute right-0 bottom-0 translate-x-1/2 translate-y-1/2 w-[800px] h-[800px] bg-orange-400/20 rounded-full mix-blend-multiply filter blur-[120px]"}),(0,le.jsx)("div",{className:"absolute right-0 bottom-0 translate-x-1/2 translate-y-1/2 w-[600px] h-[600px] bg-yellow-300/25 rounded-full mix-blend-multiply filter blur-[100px]"}),(0,le.jsx)("div",{className:"absolute right-0 bottom-0 translate-x-1/2 translate-y-1/2 w-[500px] h-[500px] bg-orange-500/15 rounded-full mix-blend-multiply filter blur-[80px]"}),(0,le.jsx)("div",{className:"absolute top-0 left-0 w-full px-[4%] md:px-[60px] py-4 md:py-6 flex items-center gap-5 md:gap-10 z-10",children:(0,le.jsx)("div",{className:"flex items-center w-[114px] h-[28px]",children:(0,le.jsx)("img",{src:"https://app.base44.com/Logo_v5.png",alt:"Base44",width:"114",height:"28"})})}),(0,le.jsx)("div",{className:"relative z-10 flex items-start md:items-center min-h-screen px-[4%] md:pl-[4%] pt-32 md:pt-0 pb-30 md:pb-0",children:(0,le.jsxs)("div",{className:"w-full max-w-6xl",children:[(0,le.jsx)("div",{className:"text-[20px] md:text-[32px] font-normal mb-4 tracking-[0.1em] md:tracking-[0.05em] text-[#001E36]",children:"ERROR: 404"}),(0,le.jsx)("h1",{className:"text-[48px] md:text-[100px] font-[300] leading-[52px] md:leading-[109px] tracking-[0.02em] md:tracking-[-1px] m-0 text-[#001E36]",children:"This app was not found"}),(0,le.jsxs)("div",{className:"text-[18px] md:text-[24px] text-black leading-relaxed mt-8 font-[300] tracking-[0.01em] md:tracking-normal",children:["This usually happens when the app's subdomain has been changed, the app has been deleted, or there's a typo in the URL.",(0,le.jsx)("br",{}),(0,le.jsx)("br",{}),"Are you looking for Base44?",(0,le.jsx)("br",{}),(0,le.jsx)("a",{href:"https://app.base44.com",className:"text-slate-800 underline decoration-1 underline-offset-2 hover:text-orange-600 transition-colors",children:"Visit Base44 home \u2192"})]})]})}),(0,le.jsx)("div",{className:"fixed bottom-8 left-1/2 -translate-x-1/2 text-center px-5 z-10",children:(0,le.jsxs)("div",{className:"text-sm md:text-[0.875rem] text-black tracking-[0.02em] whitespace-nowrap",children:["Need help? visit our"," ",(0,le.jsx)("a",{href:"https://app.base44.com/support",className:"text-black underline decoration-1 underline-offset-2 hover:text-slate-800 transition-colors",children:"support center"})]})})]}):(0,le.jsxs)(J.BrowserRouter,{children:[(0,le.jsx)("div",{children:(0,le.jsx)(cr.Toaster,{})}),(0,le.jsx)("div",{children:(0,le.jsx)(vI,{})}),(0,le.jsx)("div",{children:(0,le.jsx)(cr.Toaster,{})}),(0,le.jsx)(FA,{appId:t,children:(0,le.jsx)(OA.Ht,{client:o,children:(0,le.jsxs)(Z.BV,{children:[(0,le.jsx)(Z.qh,{path:"/login",element:(0,le.jsx)(UT,{appId:t})}),(0,le.jsx)(Z.qh,{path:"/reset-password",element:(0,le.jsx)(WT,{appId:t})}),(0,le.jsx)(Z.qh,{path:"/:pageName?",element:(0,le.jsx)(PT,{appId:t})})]})})})]})}var VT=s(12055);let HT=!1;const YT=[],GT=async e=>{var t;if(!HT&&e)for(await(t=e.email,new Promise(e=>{var s,a,n,l,r,i;window.fbq||(s=window,a=document,n="script",s.fbq||(l=s.fbq=function(){l.callMethod?l.callMethod.apply(l,arguments):l.queue.push(arguments)},s._fbq||(s._fbq=l),l.push=l,l.loaded=!0,l.version="2.0",l.queue=[],(r=a.createElement(n)).async=!0,r.src="https://connect.facebook.net/en_US/fbevents.js",(i=a.getElementsByTagName(n)[0]).parentNode.insertBefore(r,i)),window.fbq("init","2102574843552117",t?{em:t}:{})),e()})),HT=!0;YT.length>0;){YT.shift()()}};function $T(){const{user:e,isLoadingAuth:t}=oe(),s=(0,Z.zy)(),a="true"===new URLSearchParams(s.search).get("is_new_user"),n=(0,Y.useRef)(!1);return(0,Y.useEffect)(()=>{!t&&e&&(GT(e),a&&!n.current&&(n.current=!0,tt("Registration Completed",{}),Nc("registration_completed",{email:kc()(e.email),user_id:e.id,registration_method:"google"}),Ke(e.id),(0,VT.V)("is_new_user")))},[t,e,a]),null}let JT=!1;function ZT(){return(0,Y.useEffect)(()=>{new Promise(e=>{if(window.turnstile||JT)return void e();const t=document.createElement("script");t.src="https://challenges.cloudflare.com/turnstile/v0/api.js",t.async=!0,t.defer=!0,t.onload=()=>{JT=!0,e()},t.onerror=()=>{e()},document.head.appendChild(t)})},[]),null}function KT(e){let{page:t}=e;const s=!(!1===t.requiresAuth),a=!(!1===t.usesLayout),n=vA.filter(e=>!1!==e.showInMenu);let l=a?(0,le.jsx)(PA,{pages:n,children:t.component}):t.component;return s&&(l=(0,le.jsx)(QT,{children:l})),l}const QT=e=>{let{children:t}=e;const{isAuthenticated:s,isLoadingAuth:a}=oe();if(a)return(0,le.jsx)("div",{className:"flex justify-center items-center h-screen",children:(0,le.jsx)(Ne.A,{className:"h-8 w-8 animate-spin"})});if(!s){const e=encodeURIComponent(window.location.href);return ga(window.location.host)||(window.location.href="https://app.base44.com/login?from_url=".concat(e)),(0,le.jsx)(Z.C5,{to:"/login?from_url=".concat(e),replace:!0})}return t},XT=()=>{(0,Y.useEffect)(()=>{(()=>{try{const e=new URLSearchParams(window.location.search),t={};let s=!1;if(Ge.forEach(a=>{const n=e.get(a);n&&(t[a]=n,s||(s=!0))}),s){const e=$e();return e.params&&0!==Object.keys(e.params).length?e.params:(localStorage.setItem(He,JSON.stringify(t)),localStorage.setItem(Ye,Date.now().toString()),t)}return{}}catch(e){return{}}})()},[]);const e=Ae().flatMapDeep(vA,e=>[e,...e.children||[]]);return(0,le.jsx)(J.BrowserRouter,{children:(0,le.jsx)(ie,{children:(0,le.jsxs)(pe,{children:[(0,le.jsx)(Z.BV,{children:e.map(e=>(0,le.jsx)(Z.qh,{path:e.url,element:(0,le.jsx)(KT,{page:e})},e.url))}),(0,le.jsx)($T,{}),(0,le.jsx)(st,{}),(0,le.jsx)(wc,{}),(0,le.jsx)(ZT,{})]})})})},eP=()=>{const e=window.location.host;let t=(0,le.jsx)(XT,{});return ga(e)||(t=(0,le.jsx)(qT,{})),(0,le.jsxs)("div",{className:"font-sans",children:[(0,le.jsx)("div",{children:(0,le.jsx)(Bf,{})}),(0,le.jsx)("div",{children:(0,le.jsx)(vI,{})}),(0,le.jsx)("div",{children:(0,le.jsx)(cr.Toaster,{})}),(0,le.jsx)(St,{children:t})]})},tP=e=>{e&&e instanceof Function&&s.e(96).then(s.bind(s,88206)).then(t=>{let{getCLS:s,getFID:a,getFCP:n,getLCP:l,getTTFB:r}=t;s(e),a(e),n(e),l(e),r(e)})};G.createRoot(document.getElementById("root")).render((0,le.jsx)(eP,{})),tP()},69783:(e,t,s)=>{"use strict";s.d(t,{A:()=>o});var a=s(73422),n=s(41397),l=s.n(n),r=s(23046),i=s(55194);class o{constructor(){this._roomToListeners=void 0,this.historicalSocketIds=void 0,this.socket=void 0,this.tokenUnsubscribe=null,this._roomToListeners={},this.historicalSocketIds=[],this.initializeSocket(),this.setupTokenListener()}setupTokenListener(){this.tokenUnsubscribe=i.b3.addListener(e=>{"token_changed"===e&&this.reconnectWithAuth()})}getMountPath(){throw new Error("Not implemented")}getSocketQuery(){return{token:i.b3.getToken()}}initializeSocket(){const e={path:this.getMountPath(),transports:["websocket"]};e.query=this.getSocketQuery(),this.socket=(0,a.io)((0,r.wE)(),e),this.socket.on("connect",()=>{this.historicalSocketIds=l().uniq(this.historicalSocketIds.concat([this.socket.id])),this.reconnectAllRooms()}),this.socket.on("disconnect",()=>{}),this.socket.on("update_model",e=>this.onUpdateModel(e)),this.socket.on("user_joined",e=>{}),this.socket.on("user_left",e=>{}),this.socket.on("error",e=>{"Authentication required to join rooms"===e.message||"Access denied to this room"===e.message||e.message}),this.socket.on("*",e=>{})}reconnectWithAuth(){this.socket&&this.socket.disconnect(),this.initializeSocket()}getSocketId(){return this.socket.id}reconnectAllRooms(){Object.keys(this._roomToListeners).forEach(e=>{this.joinRoom(e),Object.values(this._roomToListeners[e]).forEach(e=>{let{reconnectCallback:t}=e;t&&t()})})}hasListeners(e){return Object.keys(this._roomToListeners[e]||{}).length>0}joinRoom(e){this.socket.emit("join",e)}leaveRoom(e){this.socket.emit("leave",e)}addListener(e,t,s){this.hasListeners(e)||(this.joinRoom(e),this._roomToListeners[e]={});const a="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)});this._roomToListeners[e][a]={callback:t,reconnectCallback:s};const n=this;return()=>{n.removeListener(a)}}getListeners(e){return this._roomToListeners[e]}removeListener(e){Object.keys(this._roomToListeners).forEach(t=>{this._roomToListeners[t][e]&&(delete this._roomToListeners[t][e],0===Object.keys(this._roomToListeners[t]).length&&(this.leaveRoom(t),delete this._roomToListeners[t]))})}onUpdateModel(e){const t=e.room,s=JSON.parse(e.data);this._roomToListeners[t]&&Object.values(this._roomToListeners[t]).forEach(e=>{let{callback:t}=e;t(s)})}cleanup(){this.tokenUnsubscribe&&(this.tokenUnsubscribe(),this.tokenUnsubscribe=null),this.socket&&this.socket.disconnect()}}},73215:(e,t,s)=>{"use strict";s.d(t,{Ay:()=>v,Vp:()=>x,bx:()=>f,r8:()=>p,xL:()=>m,yI:()=>d});var a=s(36642),n=s(41397),l=s.n(n),r=s(23046),i=s(6221),o=s(15255);let c={};function d(e,t){c[e]=t}function m(e){delete c[e]}let u=[];function x(e){u.push(e)}let h=()=>null;function p(e){h=e}let g=()=>null;function f(e){g=e}function v(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},s=arguments.length>2&&void 0!==arguments[2]&&arguments[2],n=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],d=!(arguments.length>4&&void 0!==arguments[4])||arguments[4];const m=a.A.create();let x;return x=e.startsWith("/")?(0,r.Gt)()+e:e,m.defaults.baseURL=x,n&&(m.defaults.headers.common["Content-Type"]="application/json",m.defaults.headers.common.Accept="application/json"),Object.keys(t).forEach(e=>{m.defaults.headers.common[e]=t[e]}),m.interceptors.request.use(t=>{t.headers=l().merge(l().cloneDeep(c),t.headers),t.headers["X-Socket-Id"]=i.A.getSocketId(),t.headers["X-Origin-URL"]=window.location.href;const a=h();a&&(t.headers["X-Active-Workspace-Id"]=a);const n=g();n&&(t.headers["X-Active-App-Id"]=n);const r=(0,o.A)();if(t.requestId=r,s)try{window.parent.postMessage({type:"api-request-start",requestId:r,data:{url:e+t.url,method:t.method,body:t.data instanceof FormData?"[FormData object]":t.data}},"*")}catch(d){}return t},e=>Promise.reject(e)),m.interceptors.response.use(e=>{if(s)try{window.parent.postMessage({type:"api-request-end",requestId:e.config.requestId,data:{statusCode:e.status,response:e.data}},"*")}catch(t){}return n?e.data:e},e=>{var t,s,a,n,l;null!==(t=e.config)&&void 0!==t&&t.requestId&&window.parent.postMessage({type:"api-request-end",requestId:e.config.requestId,data:{statusCode:(null===(n=e.response)||void 0===n?void 0:n.status)||0,response:(null===(l=e.response)||void 0===l?void 0:l.data)||{error:e.message}}},"*");if(d)for(const r of u)r(e);if(null!==(s=e.response)&&void 0!==s&&null!==(a=s.data)&&void 0!==a&&a.traceback);return Promise.reject(e)}),m}},75888:(e,t,s)=>{"use strict";s.r(t),s.d(t,{default:()=>l});var a=s(84125);class n extends a.y{getBaseURL(){return"/usage-logs"}async getStats(){return await this.axios.get("/stats")}async getMonthlyPlans(){return await this.axios.get("/monthly-plans")}async getCurrentUsage(){return await this.axios.get("/current-usage")}async getPricingAndSubscription(){return await this.axios.get("/pricing-and-subscription")}getUserStats(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null;const n={};return t&&s&&(n.start_date=t.toISOString(),n.end_date=s.toISOString()),a&&(n.workspace_id=a),this.axios.get("/user-stats/".concat(e),{params:n})}getUserWorkspacesWithDetails(e){return this.axios.get("/user-workspaces-with-details/".concat(e))}getCurrentIntegrationUsage(){return this.axios.get("/current-integration-usage")}}const l=new n},76976:(e,t,s)=>{"use strict";s.d(t,{A:()=>r});var a=s(89379),n=s(73215),l=s(12055);const r=new class{constructor(){this.listeners=new Set,setTimeout(()=>{this.processSSOTokensFromURL()},0)}getToken(){return this.fetchToken(!1)||localStorage.getItem("token")||localStorage.getItem("base44_access_token")}fetchToken(){let e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];const t=new URLSearchParams(window.location.search),s=t.get("access_token")||localStorage.getItem("token")||localStorage.getItem("base44_access_token");return e&&t.has("access_token")&&(0,l.V)("access_token"),s}setToken(e){e?(localStorage.setItem("token",e),localStorage.setItem("base44_access_token",e),(0,n.yI)("Authorization","Bearer ".concat(e))):(localStorage.removeItem("token"),localStorage.removeItem("base44_access_token"),(0,n.xL)("Authorization")),this.notifyListeners("token_changed",{token:e})}addListener(e){return this.listeners.add(e),()=>this.listeners.delete(e)}notifyListeners(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this.listeners.forEach(s=>{try{s(e,t)}catch(a){}})}processSSOTokensFromURL(){const e=new URLSearchParams(window.location.search);if(e.get("sso_access_token")){const t={sso_access_token:e.get("sso_access_token"),sso_token_type:e.get("sso_token_type"),sso_expires_at:e.get("sso_expires_at"),sso_scope:e.get("sso_scope"),sso_provider:e.get("sso_provider"),sso_id_token:e.get("sso_id_token")};this.setSSOTokens(t);["sso_access_token","sso_token_type","sso_expires_at","sso_scope","sso_provider","sso_id_token"].forEach(t=>{e.delete(t)});const s=window.location.pathname+(e.toString()?"?"+e.toString():"");window.history.replaceState({},"",s),this.notifyListeners("sso_tokens_updated",{tokens:this.getSSOTokens()})}}setSSOTokens(e){const t={access_token:e.sso_access_token,token_type:e.sso_token_type,expires_at:e.sso_expires_at,scope:e.sso_scope,provider:e.sso_provider,id_token:e.sso_id_token,stored_at:Date.now()},s=Object.fromEntries(Object.entries(t).filter(e=>{let[t,s]=e;return null!=s}));if(localStorage.setItem("sso_tokens",JSON.stringify(s)),s.access_token)try{(0,n.yI)("SSO_AUTHORIZATION","".concat(s.token_type," ").concat(s.access_token))}catch(a){setTimeout(()=>{try{(0,n.yI)("SSO_AUTHORIZATION","".concat(s.token_type," ").concat(s.access_token))}catch(e){}},100)}}getSSOTokens(){try{const e=localStorage.getItem("sso_tokens");if(!e)return null;const t=JSON.parse(e);return t.expires_at&&new Date(1e3*t.expires_at)<=new Date?(this.clearSSOTokens(),null):t}catch(e){return this.clearSSOTokens(),null}}clearSSOTokens(){localStorage.removeItem("sso_tokens");try{(0,n.xL)("SSO_AUTHORIZATION")}catch(e){setTimeout(()=>{try{(0,n.xL)("SSO_AUTHORIZATION")}catch(e){}},100)}this.notifyListeners("sso_tokens_cleared")}getSSOAuthHeader(){const e=this.getSSOTokens();return e&&e.access_token?{SSO_AUTHORIZATION:"".concat(e.token_type," ").concat(e.access_token)}:null}async fetchWithSSO(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const s=this.getSSOAuthHeader();if(!s)throw new Error("No valid SSO tokens available");const n=(0,a.A)((0,a.A)({},s),{},{"Content-Type":"application/json"},t.headers);return fetch(e,(0,a.A)((0,a.A)({},t),{},{headers:n}))}debugSSOTokens(){const e=localStorage.getItem("sso_tokens");if(e)try{const t=JSON.parse(e);if(t.expires_at){new Date(1e3*t.expires_at)}}catch(t){}}}},84125:(e,t,s)=>{"use strict";s.d(t,{H:()=>r,y:()=>i});var a=s(89379),n=s(73215),l=s(6221);class r{constructor(){this.axios=this.getClient()}getBaseURL(){return"/"}getClient(){return(0,n.Ay)(this.getBaseURL())}}class i extends r{parseInstance(e){return e}list(e,t,s,a){let n={};return e&&(n.sort=e),t&&(n.limit=t),s&&(n.skip=s),a&&(n.fields=a),this.axios.get("",{params:n}).then(e=>e.map(this.parseInstance))}filter(e,t,s,a,n){let l={q:JSON.stringify(e)};return t&&(l.sort=t),s&&(l.limit=s),a&&(l.skip=a),n&&(l.fields=n),this.axios.get("",{params:l}).then(e=>e.map(this.parseInstance))}get(e){return this.axios.get("/".concat(e)).then(this.parseInstance)}subscribe(e,t,s){const n=this;s(this.parseInstance(t));const r=this.getBaseURL()+"/"+e;return l.A.addListener(r,e=>{t=(0,a.A)((0,a.A)({},t),e),s(this.parseInstance(t),Object.keys(e))},async()=>{const t=await n.get(e);s(this.parseInstance(t),Object.keys(t))})}async fetchAndSubscribe(e,t){let s=await this.get(e);return this.subscribe(e,s,t)}schema(){return this.axios.get("/schema")}create(e){return this.axios.post("",e).then(this.parseInstance)}update(e,t){return this.axios.put("/".concat(e),t).then(this.parseInstance).then(s=>{const a=l.A.getListeners(this.getBaseURL()+"/"+e)||[];return Object.values(a).forEach(e=>e.callback(s,Object.keys(t))),s})}delete(e){return this.axios.delete("/".concat(e))}deleteMany(e){return this.axios.delete("",{data:e})}}},91903:()=>{}},n={};function l(e){var t=n[e];if(void 0!==t)return t.exports;var s=n[e]={id:e,loaded:!1,exports:{}};return a[e].call(s.exports,s,s.exports,l),s.loaded=!0,s.exports}l.m=a,l.amdO={},e=[],l.O=(t,s,a,n)=>{if(!s){var r=1/0;for(d=0;d=n)&&Object.keys(l.O).every(e=>l.O[e](s[o]))?s.splice(o--,1):(i=!1,n0&&e[d-1][2]>n;d--)e[d]=e[d-1];e[d]=[s,a,n]},l.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return l.d(t,{a:t}),t},s=Object.getPrototypeOf?e=>Object.getPrototypeOf(e):e=>e.__proto__,l.t=function(e,a){if(1&a&&(e=this(e)),8&a)return e;if("object"==typeof e&&e){if(4&a&&e.__esModule)return e;if(16&a&&"function"==typeof e.then)return e}var n=Object.create(null);l.r(n);var r={};t=t||[null,s({}),s([]),s(s)];for(var i=2&a&&e;("object"==typeof i||"function"==typeof i)&&!~t.indexOf(i);i=s(i))Object.getOwnPropertyNames(i).forEach(t=>r[t]=()=>e[t]);return r.default=()=>e,l.d(n,r),n},l.d=(e,t)=>{for(var s in t)l.o(t,s)&&!l.o(e,s)&&Object.defineProperty(e,s,{enumerable:!0,get:t[s]})},l.e=()=>Promise.resolve(),l.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),l.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),l.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},l.nmd=e=>(e.paths=[],e.children||(e.children=[]),e),l.p="/",(()=>{var e={792:0};l.O.j=t=>0===e[t];var t=(t,s)=>{var a,n,r=s[0],i=s[1],o=s[2],c=0;if(r.some(t=>0!==e[t])){for(a in i)l.o(i,a)&&(l.m[a]=i[a]);if(o)var d=o(l)}for(t&&t(s);cl(69167));r=l.O(r)})();