(()=>{var e,s,t,a={6221:(e,s,t)=>{"use strict";t.d(s,{A:()=>r});var a=t(69783);class n extends a.A{getMountPath(){return"/ws/socket.io/"}}const r=new n},12055:(e,s,t)=>{"use strict";function a(e){const s=new URLSearchParams(window.location.search);s.delete(e);const t=window.location.pathname+(s.toString()?"?"+s.toString():"");window.history.replaceState({},"",t)}t.d(s,{V:()=>a})},23046:(e,s,t)=>{"use strict";t.d(s,{Gt:()=>n,Zk:()=>r,wE:()=>a});const a=()=>"https://app.base44.com";function n(){return a()+"/api"}function r(){return n()}},24394:()=>{},39865:(e,s,t)=>{"use strict";var a={};t.r(a),t.d(a,{cn:()=>is});var n={};t.r(n),t.d(n,{Alert:()=>us,AlertDescription:()=>hs,AlertTitle:()=>xs});var r={};t.r(r),t.d(r,{Tooltip:()=>Ts,TooltipContent:()=>Ls,TooltipProvider:()=>Is,TooltipTrigger:()=>Ps});var l={};t.r(l),t.d(l,{Button:()=>Hs,buttonVariants:()=>Ys});var i={};t.r(i),t.d(i,{Badge:()=>et,badgeVariants:()=>Qs});var o={};t.r(o),t.d(o,{Card:()=>it,CardContent:()=>mt,CardDescription:()=>dt,CardFooter:()=>ut,CardHeader:()=>ot,CardTitle:()=>ct});var c={};t.r(c),t.d(c,{Separator:()=>pt});var d={};t.r(d),t.d(d,{Input:()=>ft});var m={};t.r(m),t.d(m,{Label:()=>Nt});var u={};t.r(u),t.d(u,{RadioGroup:()=>St,RadioGroupItem:()=>Ct});var x={};t.r(x),t.d(x,{Select:()=>Ut,SelectContent:()=>Ht,SelectGroup:()=>zt,SelectItem:()=>$t,SelectLabel:()=>Gt,SelectScrollDownButton:()=>Yt,SelectScrollUpButton:()=>Vt,SelectSeparator:()=>Jt,SelectTrigger:()=>Wt,SelectValue:()=>qt});var h={};t.r(h),t.d(h,{Avatar:()=>ma,AvatarFallback:()=>xa,AvatarImage:()=>ua});var p={};t.r(p),t.d(p,{Dialog:()=>Pa,DialogClose:()=>Ra,DialogContent:()=>Ma,DialogDescription:()=>za,DialogFooter:()=>Ba,DialogHeader:()=>Fa,DialogOverlay:()=>Da,DialogPortal:()=>Oa,DialogTitle:()=>Ua,DialogTrigger:()=>La});var g={};t.r(g),t.d(g,{reducer:()=>Qa,toast:()=>an,useToast:()=>nn});var f={};t.r(f),t.d(f,{Table:()=>Or,TableBody:()=>Dr,TableCaption:()=>zr,TableCell:()=>Ur,TableFooter:()=>Mr,TableHead:()=>Br,TableHeader:()=>Rr,TableRow:()=>Fr});var v={};t.r(v),t.d(v,{Tabs:()=>hl,TabsContent:()=>fl,TabsList:()=>pl,TabsTrigger:()=>gl});var b={};t.r(b),t.d(b,{DropdownMenu:()=>Pl,DropdownMenuCheckboxItem:()=>ql,DropdownMenuContent:()=>Ul,DropdownMenuGroup:()=>Ol,DropdownMenuItem:()=>zl,DropdownMenuLabel:()=>Vl,DropdownMenuPortal:()=>Rl,DropdownMenuRadioGroup:()=>Ml,DropdownMenuRadioItem:()=>Wl,DropdownMenuSeparator:()=>Yl,DropdownMenuShortcut:()=>Hl,DropdownMenuSub:()=>Dl,DropdownMenuSubContent:()=>Bl,DropdownMenuSubTrigger:()=>Fl,DropdownMenuTrigger:()=>Ll});var j={};t.r(j),t.d(j,{Checkbox:()=>ed});var y={};t.r(y),t.d(y,{Textarea:()=>td});var N={};t.r(N),t.d(N,{ScrollArea:()=>ld,ScrollBar:()=>id});var w={};t.r(w),t.d(w,{Collapsible:()=>Ad,CollapsibleContent:()=>Cd,CollapsibleTrigger:()=>Sd});var _={};t.r(_),t.d(_,{Command:()=>Hd,CommandDialog:()=>Gd,CommandEmpty:()=>Zd,CommandGroup:()=>Kd,CommandInput:()=>$d,CommandItem:()=>Qd,CommandList:()=>Jd,CommandSeparator:()=>Xd,CommandShortcut:()=>em});var k={};t.r(k),t.d(k,{Calendar:()=>rm});var A={};t.r(A),t.d(A,{Popover:()=>dm,PopoverContent:()=>um,PopoverTrigger:()=>mm});var S={};t.r(S),t.d(S,{Sheet:()=>Vm,SheetClose:()=>Hm,SheetContent:()=>Zm,SheetDescription:()=>eu,SheetFooter:()=>Xm,SheetHeader:()=>Km,SheetOverlay:()=>$m,SheetPortal:()=>Gm,SheetTitle:()=>Qm,SheetTrigger:()=>Ym});var C={};t.r(C),t.d(C,{Switch:()=>wu});var E={};t.r(E),t.d(E,{Skeleton:()=>ox});var I={};t.r(I),t.d(I,{Toast:()=>Dh,ToastAction:()=>Mh,ToastClose:()=>Fh,ToastDescription:()=>Uh,ToastProvider:()=>Lh,ToastTitle:()=>Bh,ToastViewport:()=>Oh});var T={};t.r(T),t.d(T,{Toaster:()=>qh});var P={};t.r(P),t.d(P,{AlertDialog:()=>vp,AlertDialogAction:()=>Sp,AlertDialogCancel:()=>Cp,AlertDialogContent:()=>Np,AlertDialogDescription:()=>Ap,AlertDialogFooter:()=>_p,AlertDialogHeader:()=>wp,AlertDialogOverlay:()=>yp,AlertDialogPortal:()=>jp,AlertDialogTitle:()=>kp,AlertDialogTrigger:()=>bp});var L={};t.r(L),t.d(L,{Progress:()=>ov});var O={};t.r(O),t.d(O,{Accordion:()=>$_,AccordionContent:()=>K_,AccordionItem:()=>J_,AccordionTrigger:()=>Z_});var R={};t.r(R),t.d(R,{AspectRatio:()=>X_});var D={};t.r(D),t.d(D,{Carousel:()=>ik,CarouselContent:()=>ok,CarouselItem:()=>ck,CarouselNext:()=>mk,CarouselPrevious:()=>dk});var M={};t.r(M),t.d(M,{ContextMenu:()=>Nk,ContextMenuCheckboxItem:()=>Pk,ContextMenuContent:()=>Ik,ContextMenuGroup:()=>_k,ContextMenuItem:()=>Tk,ContextMenuLabel:()=>Ok,ContextMenuPortal:()=>kk,ContextMenuRadioGroup:()=>Sk,ContextMenuRadioItem:()=>Lk,ContextMenuSeparator:()=>Rk,ContextMenuShortcut:()=>Dk,ContextMenuSub:()=>Ak,ContextMenuSubContent:()=>Ek,ContextMenuSubTrigger:()=>Ck,ContextMenuTrigger:()=>wk});var F={};t.r(F),t.d(F,{Form:()=>zk,FormControl:()=>$k,FormDescription:()=>Jk,FormField:()=>Wk,FormItem:()=>Hk,FormLabel:()=>Gk,FormMessage:()=>Zk,useFormField:()=>Vk});var B={};t.r(B),t.d(B,{HoverCard:()=>Qk,HoverCardContent:()=>sA,HoverCardTrigger:()=>eA});var U={};t.r(U),t.d(U,{Menubar:()=>bA,MenubarCheckboxItem:()=>kA,MenubarContent:()=>wA,MenubarGroup:()=>pA,MenubarItem:()=>_A,MenubarLabel:()=>SA,MenubarMenu:()=>hA,MenubarPortal:()=>gA,MenubarRadioGroup:()=>vA,MenubarRadioItem:()=>AA,MenubarSeparator:()=>CA,MenubarShortcut:()=>EA,MenubarSub:()=>fA,MenubarSubContent:()=>NA,MenubarSubTrigger:()=>yA,MenubarTrigger:()=>jA});var z={};t.r(z),t.d(z,{NavigationMenu:()=>MA,NavigationMenuContent:()=>qA,NavigationMenuIndicator:()=>YA,NavigationMenuItem:()=>BA,NavigationMenuLink:()=>WA,NavigationMenuList:()=>FA,NavigationMenuTrigger:()=>zA,NavigationMenuViewport:()=>VA,navigationMenuTriggerStyle:()=>UA});var q={};t.r(q),t.d(q,{Slider:()=>$A});var W={};t.r(W),t.d(W,{Toggle:()=>XA,toggleVariants:()=>KA});var V={};t.r(V),t.d(V,{Toaster:()=>eS});var Y={};t.r(Y),t.d(Y,{Sidebar:()=>SS,SidebarContent:()=>RS,SidebarFooter:()=>LS,SidebarGroup:()=>DS,SidebarGroupAction:()=>FS,SidebarGroupContent:()=>BS,SidebarGroupLabel:()=>MS,SidebarHeader:()=>PS,SidebarInput:()=>TS,SidebarInset:()=>IS,SidebarMenu:()=>US,SidebarMenuAction:()=>VS,SidebarMenuBadge:()=>YS,SidebarMenuButton:()=>WS,SidebarMenuItem:()=>zS,SidebarMenuSkeleton:()=>HS,SidebarMenuSub:()=>GS,SidebarMenuSubButton:()=>JS,SidebarMenuSubItem:()=>$S,SidebarProvider:()=>AS,SidebarRail:()=>ES,SidebarSeparator:()=>OS,SidebarTrigger:()=>CS,useSidebar:()=>kS});var H=t(9950),G=t(1352),$=t.t(G,2),J=t(42074),Z=t(28429),K=t(89379),X=t(84125),Q=t(36642),ee=t(23046);class se extends X.y{getBaseURL(){return"/auth"}getCurrentUser(){return this.axios.get("/me")}regenerateApiKey(){return this.axios.post("/regenerate_api_key")}updateUser(e,s){return this.axios.post("/".concat(e,"/update-user"),(0,K.A)({},s))}listUsers(e){return this.axios.get("/list-users",{params:e})}async checkDomainSSO(e){try{return(await Q.A.get("".concat((0,ee.Gt)(),"/workspace/public/sso/check-domain"),{params:{domain:e}})).data}catch(s){return{has_sso:!1}}}login(e,s){let t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;const a={email:e,password:s};return t&&(a.turnstile_token=t),this.axios.post("/login",a)}register(e,s){let t=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:s};return t&&(n.turnstile_token=t),a&&(n.referral_code=a),this.axios.post("/register",n)}verifyOtp(e,s){return this.axios.post("/verify-otp",{email:e,otp_code:s})}resendOtp(e){return this.axios.post("/resend-otp",{email:e})}resetPasswordRequest(e){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;const t={email:e};return s&&(t.turnstile_token=s),this.axios.post("/reset-password-request",t)}resetPassword(e,s){let t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;const a={reset_token:e,new_password:s};return t&&(a.turnstile_token=t),this.axios.post("/reset-password",a)}changePassword(e,s,t){return this.axios.post("/change-password",{user_id:e,current_password:s,new_password:t})}}const te=new se;var ae=t(73215),ne=t(55194),re=t(44414);const le=(0,H.createContext)(),ie=e=>{let{children:s}=e;const[t,a]=(0,H.useState)(null),[n,r]=(0,H.useState)(!1),[l,i]=(0,H.useState)(!0);(0,H.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"),(0,ae.xL)("Authorization"),a(null),r(!1),i(!1)},c=async()=>{try{i(!0);const e=await te.getCurrentUser();return a(e),r(!0),i(!1),e}catch(e){i(!1),o()}},d=(0,H.useCallback)(async()=>{const e=await te.getCurrentUser();e&&a(e)},[]);return(0,re.jsx)(le.Provider,{value:{user:t,isAuthenticated:n,logout:function(){let e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];if(o(),r(!1),a(null),e){const e=encodeURIComponent(window.location.href);window.location.href="/login?from_url="+e}},isLoadingAuth:l,updateUser:e=>{a(e)},reloadUser:d},children:s})},oe=()=>(0,H.useContext)(le);var ce=t(6221);class de extends X.H{getBaseURL(){return"/workspace/invitations"}inviteUser(e){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"member",t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;const a=t?{workspaceId:t}:{};return this.axios.post("/invite",{email:e,role:s},{params:a})}bulkInviteUsers(e){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;const t=s?{workspaceId:s}:{};return this.axios.post("/bulk-invite",{invitations:e},{params:t})}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 X.H{getBaseURL(){return"/workspace"}getWorkspaces(){return this.axios.get("/workspaces")}getAvailablePlans(){return this.axios.get("/available-plans")}createWorkspace(e){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return this.axios.post("/workspaces",{name:e,domain:s})}getDashboard(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;const s=e?{workspaceId:e}:{};return this.axios.get("",{params:s})}subscribeToDashboard(e,s,t){const a="workspace/".concat(e,"/dashboard");return t(s),ce.A.addListener(a,e=>{s=(0,K.A)((0,K.A)({},s),e),t(s,Object.keys(e))},async()=>{try{const s=await this.getDashboard(e);t(s,Object.keys(s))}catch(s){}})}updateWorkspace(e,s){const t=e?{workspaceId:e}:{};return this.axios.put("/update",s,{params:t})}inviteUser(e){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"member",t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;return me.inviteUser(e,s,t)}bulkInviteUsers(e){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return me.bulkInviteUsers(e,s)}buySeats(e,s){let t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;const a=t?{workspaceId:t}:{};return this.axios.post("/buy-seats",{plan:e,count:s},{params:a})}removeSeats(e,s){let t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;const a=t?{workspaceId:t}:{};return this.axios.post("/remove-seats",{plan:e,count:s},{params:a})}updateMemberRole(e,s){let t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;const a=t?{workspaceId:t}:{};return this.axios.put("/members/".concat(e,"/role"),{role:s},{params:a})}updateMemberSeat(e,s){let t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null;const n=t?{workspaceId:t}:{},r={seat_type:s};return null!==a&&(r.seat_id=a),this.axios.put("/members/".concat(e,"/seat"),r,{params:n})}removeMember(e){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;const t=s?{workspaceId:s}:{};return this.axios.delete("/members/".concat(e),{params:t})}getMySeatInfo(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;const s=e?{workspaceId:e}:{};return this.axios.get("/my-seat",{params:s})}getSeatUsage(e){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;const t=s?{workspaceId:s}:{};return this.axios.get("/seats/".concat(e,"/usage"),{params:t})}getWorkspaceInvoices(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;const s=e?{workspaceId:e}:{};return this.axios.get("/invoices",{params:s})}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 s=e?{workspaceId:e}:{};return this.axios.post("/create-portal-session",{},{params:s})}checkSensitiveFeaturePermission(e){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;const t={feature:e};return s&&(t.organizationId=s),this.axios.get("/sensitive-feature-permission",{params:t})}}const xe=new ue,he=(0,H.createContext)();function pe(e){let{children:s}=e;const[t,a]=(0,H.useState)(null),[n,r]=(0,H.useState)([]),[l,i]=(0,H.useState)(!0),[o,c]=(0,H.useState)(!0),[d,m]=(0,H.useState)(null),{reloadUser:u,isAuthenticated:x}=oe(),h=(0,H.useMemo)(()=>{if(!t||!n.length)return null;return n.find(e=>e.id===t)||null},[t,n]);(0,H.useEffect)(()=>((0,ae.r8)(()=>t),x&&u(),()=>{(0,ae.r8)(()=>null),x&&u()}),[t,x,u]),(0,H.useEffect)(()=>{const e=localStorage.getItem("activeWorkspaceId");if(e)try{a(e)}catch(d){localStorage.removeItem("activeWorkspaceId")}i(!1)},[]),(0,H.useEffect)(()=>{t?localStorage.setItem("activeWorkspaceId",t):localStorage.removeItem("activeWorkspaceId")},[t]);const p=(0,H.useCallback)(async()=>{try{c(!0),m(null);const e=await xe.getWorkspaces();r(e.workspaces||e||[])}catch(e){m(e),r([])}finally{c(!1)}},[]);(0,H.useEffect)(()=>{p()},[p]);const g=(0,H.useCallback)(e=>{const s="string"==typeof e?e:null==e?void 0:e.id;a(s)},[]),f=(0,H.useCallback)(()=>{a(null)},[]),v={activeWorkspace:h,activeWorkspaceId:t,workspaces:n,isLoading:l,isLoadingWorkspaces:o,error:d,switchActiveWorkspace:g,clearActiveWorkspace:f,refetchWorkspaces:p};return(0,re.jsx)(he.Provider,{value:v,children:s})}function ge(){const e=(0,H.useContext)(he);if(void 0===e)throw new Error("useWorkspace must be used within a WorkspaceProvider");return e}class fe extends X.y{getBaseURL(){return"/apps"}addMessage(e,s){return this.axios.post("/".concat(e,"/chat/message"),s)}undoMessage(e,s){return this.axios.post("/".concat(e,"/chat/message/").concat(s,"/undo"))}inviteUser(e,s,t){return this.axios.post("/".concat(e,"/users/invite-user"),{user_email:s,role:t})}remixApp(e,s){return this.axios.post("/".concat(e,"/remix"),s)}remixAppRequirements(e){return this.axios.get("/".concat(e,"/remix/requirements"))}updateLogo(e,s){return this.axios.post("/".concat(e,"/metadata/update-logo"),s)}generateLogoFromPrompt(e,s){return this.axios.post("/".concat(e,"/metadata/generate-logo"),s)}stopChat(e){return this.axios.post("/".concat(e,"/chat/stop"))}getDomainAppId(e){return this.axios.get("/public/prod/domain/".concat(e))}getRuntimeAuthToken(e,s){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.post("/".concat(e,"/chat/generate-suggestions"))}deployApp(e){return this.axios.post("/".concat(e,"/deploy"))}installIntegration(e,s,t){return this.axios.post("/".concat(e,"/install-integration/").concat(s,"/").concat(t))}deleteIntegration(e,s,t){return this.axios.post("/".concat(e,"/delete-integration/").concat(s,"/").concat(t))}redeployFunction(e,s,t){return this.axios.post("/".concat(e,"/coding/redeploy-function/").concat(s),{code:t})}moveToWorkspace(e,s){return this.axios.post("/".concat(e,"/metadata/move-to-workspace"),{target_workspace_id:s})}}const ve=new fe;var be=t(74925);const je="mixpanel_utm_params",ye="mixpanel_utm_timestamp",Ne=["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"],we=()=>{try{const e=localStorage.getItem(je),s=localStorage.getItem(ye);return{params:e?JSON.parse(e):{},timestamp:s?parseInt(s):null}}catch(e){return{params:{},timestamp:null}}},_e={signup:{src:189,evid:1204},login:{src:189,evid:1200}};const ke=function(e){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"signup",t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};try{if(!e)return;const a=_e[s];if(!a)return;const n=function(e){const s="; ".concat(document.cookie).split("; ".concat(e,"="));return 2===s.length?s.pop().split(";").shift():null}("_wixCIDX")||"no-cookie-found",r=e||"no-user-id",l={dt:0,e:[{dt:0,f:{src:a.src,evid:a.evid}}],g:{uuid:r,client_id:n}};Object.keys(t).length>0&&(l.additional_data=t),fetch("https://frog.wix.com/base44",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(l)}).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){}},Ae=e=>{const s={event_type:"signup",timestamp:(new Date).toISOString()};ke(e,"signup",s)};let Se={feature_flags:[],tier:null};const Ce=[];function Ee(e,s){const t=(0,K.A)((0,K.A)({},s),{},{feature_flags:s.feature_flags||Se.feature_flags,tier:s.tier||Se.tier});be.A.track(e,t)}const Ie=function(e){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};be.A.__loaded?Ee(e,s):Ce.push(()=>Ee(e,s))};function Te(){const{user:e,isLoadingAuth:s}=oe();return(0,H.useEffect)(()=>{if(s)return;be.A.init("eff913a25a5a2642acc7794bb28dc621",{debug:!1,opt_out_tracking_by_default:!1,ignore_dnt:!0,loaded:()=>{be.A.__loaded=!0;const{params:s}=we();if(Object.keys(s).length>0&&be.A.register(s),e){t=e.id,be.A.__loaded?be.A.identify(t):Ce.push(()=>be.A.identify(t));const a={};for(Object.assign(a,s),a.is_beta=e.is_beta_tester||!1,a.tier=e.subscription_tier||"free",Se.tier=e.subscription_tier||"free",e.feature_flags&&Array.isArray(e.feature_flags)&&(Se.feature_flags=e.feature_flags,a.feature_flags=e.feature_flags,e.feature_flags.forEach(e=>{a["ff_".concat(e)]=!0})),((e,s)=>{be.A.__loaded?(be.A.identify(e),be.A.people.set(s)):Ce.push(()=>{be.A.identify(e),be.A.people.set(s)})})(e.id,a),Ie("User Login",s),(e=>{const s={event_type:"login",timestamp:(new Date).toISOString()};ke(e,"login",s)})(e.id);Ce.length>0;){Ce.shift()()}}var t}})},[s,e]),null}const Pe={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}};function Le(e){return Pe[e]||null}async function Oe(e,s){let{timeoutMs:t=2500}=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};const a=JSON.stringify(s),n=fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:a}),r=await function(e){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:2500;return new Promise((t,a)=>{const n=setTimeout(()=>a(new Error("timeout")),s);e.then(e=>{clearTimeout(n),t(e)},e=>{clearTimeout(n),a(e)})})}(n,t);if(!r.ok)throw new Error("HTTP ".concat(r.status));return r}function Re(e,s){try{const t=new Blob([JSON.stringify(s)],{type:"application/json"});return navigator.sendBeacon(e,t)}catch(t){return!1}}const De="https://frog.wix.com/base44";const Me=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 s;if("undefined"==typeof document)return null;const t="; ".concat(document.cookie).split("; ".concat(e,"="));return 2===t.length&&(null===(s=t.pop())||void 0===s?void 0:s.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 s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};try{await this.ensureReady();if(!Le(e))return;let r;try{r=await t}catch(n){r={}}const l=Date.now();if(a.immediate||a.useBeacon)return this._sendImmediately(e,s,r,l,a);const i={eventKey:e,session:s,additionalData:r,timestamp:l,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,s,t,a,n){try{const r=Le(e),l={dt:0,e:[{dt:0,f:(0,K.A)((0,K.A)({src:r.src,evid:r.evid,timestamp:a},t),s)}],g:{uuid:s.user_id||"no-user-id",client_id:this.getClientId()}};if(n.useBeacon){if(Re(De,l))return}await Oe(De,l,{timeoutMs:2500})}catch(r){}}async _flush(){if(!this._isFlushInProgress&&0!==this._eventQueue.length){this._isFlushInProgress=!0;try{this._flushTimer&&(clearTimeout(this._flushTimer),this._flushTimer=null);const s=this._eventQueue.splice(0,this.BATCH_SIZE);let t;try{t=this._groupEventsBySession(s)}catch(e){return}try{await Promise.all(t.map(e=>this._sendEventBatch(e)))}catch(e){}}catch(e){}finally{this._isFlushInProgress=!1,this._eventQueue.length>0&&this._scheduleFlush()}}}_groupEventsBySession(e){const s=new Map;for(const t of e){const e=(null==t?void 0:t.session)||{},a="object"==typeof e&&null!==e&&e.user_id||"no-user",n="object"==typeof e&&null!==e&&e.app_id||"no-app",r="object"==typeof e&&null!==e&&e.conversation_id||"no-conversation",l="".concat(a,"-").concat(n,"-").concat(r);s.has(l)||s.set(l,[]),s.get(l).push(t)}return Array.from(s.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 s,t;const a=e.some(e=>e.useBeacon),n={dt:0,e:e.map(s=>{const t=Le(s.eventKey);return{dt:s.timestamp-e[0].timestamp,f:(0,K.A)((0,K.A)({src:t.src,evid:t.evid,timestamp:s.timestamp},s.additionalData),s.session)}}),g:{uuid:(null===(s=e[0])||void 0===s||null===(t=s.session)||void 0===t?void 0:t.user_id)||"no-user-id",client_id:this.getClientId(),batch_size:e.length}};if(a){if(!Re(De,n))throw new Error("Beacon send failed")}else await Oe(De,n,{timeoutMs:2500})}catch(a){}}destroy(){this._flushTimer&&(clearTimeout(this._flushTimer),this._flushTimer=null),this._eventQueue.length>0&&this._flush().catch(e=>{})}};async function Fe(){try{const e=await Promise.resolve().then(t.bind(t,75888));return await e.default.getCurrentUsage()}catch(e){return{daily_limit:null,daily_usage:null,monthly_limit:null,monthly_usage:null}}}async function Be(){return function(e){if(!e)return null;const s="number"==typeof e.daily_limit?e.daily_limit:void 0,t="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 s?"number"!=typeof t?null:Math.max(0,s-t):"number"==typeof a?"number"!=typeof n?null:Math.max(0,a-n):null}(await Fe())}function Ue(e,s,t){Me.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)}}(s),t)}function ze(e,s,t){Me.track("message_completed",e,async function(e){var s,t,a,n,r,l;const i=null!==(s=e.tokens_left)&&void 0!==s?s:await Be();return{message_id:null!==(t=e.message_id)&&void 0!==t?t: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!==(r=e.duration)&&void 0!==r?r:null,has_files:Boolean(e.has_files),error_message:null!==(l=e.error_message)&&void 0!==l?l:null}}(s),t)}function qe(e,s,t){Me.track("page_view",e,function(e){return{page_name:String(e.page_name||"")}}(s),t)}function We(e,s,t){Me.track("user_clicked",e,function(e){return(0,K.A)({},e)}(s),t)}"undefined"!=typeof window&&window.addEventListener("beforeunload",()=>{Me.destroy()});const Ve=e=>{var s,t,a;let{startTime:n,body:r,updatedApp:l=null,userMessageId:i=null,agentMessage:o=null,agentModel:c=null,wasSuccessful:d,error:m=null,userId:u=null,appId:x=null}=e;const h=Date.now()-n,p=(null==l||null===(s=l.conversation)||void 0===s?void 0:s.id)||null,g={app_id:x,conversation_id:p,message_id:i,message:String((null==r?void 0:r.content)||""),has_files:((null===(t=r.file_urls)||void 0===t?void 0:t.length)||0)>0,user_id:u,was_successful:d,model:c};if(!d&&m){var f,v;const e=m;g.error_message=(null==e||null===(f=e.response)||void 0===f||null===(v=f.data)||void 0===v?void 0:v.message)||(null==e?void 0:e.message)||"unknown"}Ie("Message Completed",g),ze({user_id:u,app_id:x,conversation_id:p},(0,K.A)({message_id:i,user_message:String((null==r?void 0:r.content)||""),agent_message:o,model:c,was_successful:d,duration:h,has_files:((null===(a=r.file_urls)||void 0===a?void 0:a.length)||0)>0},g.error_message?{error_message:String(g.error_message)}:{}))};async function Ye(e){let{appId:s,body:t,app:a=null,user:n=null,onSuccess:r,onError:l}=e;const i=Date.now();try{var o,c,d,m,u,x;(e=>{var s,t;let{body:a,userId:n=null,appId:r=null,conversationId:l=null,isInitialCreation:i=!1}=e;const o={app_id:r,conversation_id:l,user_id:n,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};Ie("Message Sent",o),Ue({user_id:n,app_id:r,conversation_id:l},{user_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})})({body:t,userId:(null==n?void 0:n.id)||null,appId:s||null,conversationId:(null==a||null===(o=a.conversation)||void 0===o?void 0:o.id)||null,isInitialCreation:0===((null==a||null===(c=a.conversation)||void 0===c||null===(d=c.messages)||void 0===d?void 0:d.length)||0)});const e=await ve.addMessage(s,t),l=((e,s)=>{try{const l=e||[];if(null!=s)for(let e=l.length-1;e>=0;e--){var t,a;const n=l[e];if("user"===(null==n?void 0:n.role)&&String(null!==(t=null==n?void 0:n.content)&&void 0!==t?t:"")===String(null!==(a=s)&&void 0!==a?a:""))return(null==n?void 0:n.id)||null}for(let e=l.length-1;e>=0;e--){var n,r;if("user"===(null===(n=l[e])||void 0===n?void 0:n.role))return(null===(r=l[e])||void 0===r?void 0:r.id)||null}return null}catch(l){return null}})((null==e||null===(m=e.conversation)||void 0===m?void 0:m.messages)||null,null==t?void 0:t.content),{message:h,model:p}=(e=>{try{const n=e||[];for(let e=n.length-1;e>=0;e--){var s,t,a;if("assistant"===(null===(s=n[e])||void 0===s?void 0:s.role))return{message:String((null===(t=n[e])||void 0===t?void 0:t.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===(u=e.conversation)||void 0===u?void 0:u.messages)||null),g=null!=e&&null!==(x=e.conversation)&&void 0!==x&&x.id?e:a;return Ve({startTime:i,body:t,updatedApp:g||null,userMessageId:l,agentMessage:h,agentModel:p,wasSuccessful:!0,userId:(null==n?void 0:n.id)||null,appId:s||null}),r&&await r(e),e}catch(h){throw Ve({startTime:i,body:t,updatedApp:a||null,userMessageId:null,agentMessage:null,agentModel:null,wasSuccessful:!1,error:h,userId:(null==n?void 0:n.id)||null,appId:s||null}),l&&await l(h),h}}async function He(e,s){return Ye({appId:e,body:s,user:{id:arguments.length>2&&void 0!==arguments[2]?arguments[2]:null},onError:e=>{}})}const Ge=t.p+"static/media/logo_v3.bc182c1c9f0bff68838e.png";var $e=t(34700),Je=t(67143),Ze=t(42989),Ke=t(61041),Xe=t(52828),Qe=t(31115),es=t(75888),ss=t(41397),ts=t.n(ss),as=t(53986),ns=t(94364),rs=t(72004),ls=t(79800);function is(){for(var e=arguments.length,s=new Array(e),t=0;tsvg~*]: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"}}),us=H.forwardRef((e,s)=>{let{className:t,variant:a}=e,n=(0,as.A)(e,os);return(0,re.jsx)("div",(0,K.A)({ref:s,role:"alert",className:is(ms({variant:a}),t)},n))});us.displayName="Alert";const xs=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,cs);return(0,re.jsx)("h5",(0,K.A)({ref:s,className:is("mb-1 font-medium leading-none tracking-tight",t)},a))});xs.displayName="AlertTitle";const hs=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,ds);return(0,re.jsx)("div",(0,K.A)({ref:s,className:is("text-sm [&_p]:leading-relaxed",t)},a))});hs.displayName="AlertDescription";class ps extends X.H{getBaseURL(){return"/apps"}write(e,s,t){return this.axios.post("/".concat(e,"/coding/write"),{file_path:s,content:t})}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,s){return this.axios.post("/".concat(e,"/coding/invite-collaborator"),{collaborator_username:s})}searchGithubUsers(e,s){return this.axios.post("/".concat(e,"/coding/search-github-users"),{query:s})}}const gs=new ps;class fs extends X.y{getBaseURL(){return"/apps"}updateSecrets(e,s){return this.axios.post("/".concat(e,"/secrets"),s)}deleteSecret(e,s){return this.axios.delete("/".concat(e,"/secrets/").concat(s))}getSecrets(e){return this.axios.get("/".concat(e,"/secrets"))}getGeneralSecrets(e){return(0,ae.Ay)("/secrets").get(e)}}const vs=new fs;function bs(){const e=window.location.hostname;if(e.startsWith("checkpoint--")){const s=e.split("--");if(s.length>=3){return s[2].split(".")[0]}}return e.startsWith("preview--")?"preview":"prod"}function js(e,s,t){let a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};class n extends X.y{constructor(){super(),this.axios.interceptors.response.use(e=>e,e=>{var a,n;const r="error trying to call ".concat(s.name," entity api: ").concat(e.config.url);let l=e.config.data;try{"string"!=typeof l&&(l=JSON.stringify(l)),l&&l.length>1e3&&(l=l.substring(0,997)+"...")}catch(m){l=String(l)}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(s.name,"\nurl: ").concat(e.config.baseURL).concat(e.config.url,"\nmethod: ").concat(e.config.method,"\ndata: ").concat(l,"\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 t(r,d),Promise.reject(e)})}getBaseURL(){return"https://base44.app/api"+"/apps/".concat(e,"/entities/").concat(s.name)}getClient(){return(0,ae.Ay)(this.getBaseURL(),a,!0,!0)}schema(){return s}bulkCreate(e){return this.axios.post("/bulk",e)}importEntities(e){const s=new FormData;return s.append("file",e,e.name),this.axios.post("/import",s,{headers:{"Content-Type":"multipart/form-data"}})}}return new n}function ys(e,s,t){let a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},n={};return Object.keys(e.entities).forEach(t=>{n[t]=js(e.id,e.entities[t],s,a)}),n.User=js(e.id,e.user_entity,s,a),n.User.updateMyUserData=async function(e){return await t.updateMyUserData(e)},n.User.me=async function(){return await t.getMyUserInfo()},n.User.logout=async function(){return await t.logout()},n.User.login=async function(){return await t.login()},n.User.loginWithRedirect=async function(e){return await t.loginWithRedirect(e)},n.User.isUserAuthenticated=function(){return t.isUserAuthenticated()},n}const Ns=(0,H.createContext)(),ws=e=>{let{children:s}=e;const{user:t,reloadUser:a,isAuthenticated:n}=oe(),{appId:r,pageName:l}=(0,Z.g)(),[i,o]=(0,H.useState)(null),[c,d]=(0,H.useState)(!0),[m,u]=(0,H.useState)(null),[x,h]=(0,H.useState)([]),[p,g]=(0,H.useState)(null),[f,v]=(0,H.useState)(null),[b,j]=(0,H.useState)([]),[y,N]=(0,H.useState)(null),[w,_]=(0,H.useState)(!1),[k,A]=(0,H.useState)(!1),[S,C]=(0,H.useState)(null);(0,H.useEffect)(()=>((0,ae.bx)(()=>r),n&&a(),()=>{(0,ae.bx)(()=>null),n&&a()}),[r,n]),(0,H.useEffect)(()=>{if(!i||r&&(null==i?void 0:i.id)!==r)return(()=>{let e=null;return(async()=>{try{d(!0);let s=r;e=await ve.fetchAndSubscribe(s,(e,s)=>{if(s&&s.includes("_last_msg")){const s=(e=ts().cloneDeep(e)).conversation.messages.findIndex(s=>s.id===e._last_msg.id);-1!==s?e.conversation.messages[s]=e._last_msg:e.conversation.messages.push(e._last_msg)}o(e),h([])});const[a,n]=await Promise.all([es.default.getCurrentUsage(),ve.getRuntimeAuthToken(r,t.api_key)]);v(a),T(s),I(s),N(n.token)}catch(a){var s;u("Failed to load app : "+((null===(s=a.response.data)||void 0===s?void 0:s.message)||a.message))}finally{d(!1)}})(),()=>{e&&e()}})()},[r]);let E=null;l?E=null!=i&&i.pages[l]?{name:l,code:null==i?void 0:i.pages[l]}:null:null!=i&&i.pages&&(E={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 I=async e=>{const s=await vs.getSecrets(e);j(Object.keys(s))},T=async e=>{if(!window.location.href.includes("/editor/"))return;const s=await ve.getSuggestions((null==i?void 0:i.id)||e);g(s)};let P=s;return c?P=(0,re.jsx)("div",{className:"fixed inset-0 flex justify-center items-center",children:(0,re.jsx)(Ze.A,{className:"h-8 w-8 animate-spin"})}):m?P=(0,re.jsx)("div",{className:"p-8",children:(0,re.jsx)(us,{variant:"destructive",children:(0,re.jsxs)(hs,{children:[m,(0,re.jsx)("div",{className:"mt-2 text-sm",children:"Please try refreshing the page. If the problem persists, please contact our support team."}),(0,re.jsx)("button",{type:"button",onClick:()=>window.open("/support","_blank"),className:"underline text-primary hover:text-orange-500 transition-colors",children:"support system"})]})})}):i||(P=(0,re.jsx)(us,{variant:"destructive",children:(0,re.jsx)(hs,{children:"App not found"})})),(0,re.jsx)(Ns.Provider,{value:{app:i,setApp:o,updateApp:async e=>{const s=await ve.update(i.id,e);h([]),o(s)},isLoading:c,error:m,getEntitiesSDK:function(e){const s={"X-Bypass-RLS":"true",Authorization:"Bearer ".concat(y)};return ys(i,e,null,s)},appErrors:x,setAppErrors:h,onAppError:(e,s,t)=>{let a;a=ts().isObject(e)?{title:e.title||e.message||e.toString(),details:e.details||e.stack||e.toString(),componentName:t||l}:{title:e,details:s,componentName:t||l},h(e=>{if(!e.some(e=>e.title===a.title))return[...e,a];{const s=e.find(e=>e.title===a.title);s&&i&&(i.components&&i.components[a.componentName]&&!i.components[s.componentName]||i.pages&&i.pages[a.componentName]&&!i.pages[s.componentName]&&!i.components[s.componentName])&&(s.componentName=a.componentName)}return e})},addChatMessage:async e=>{S&&(e.custom_context=[{type:"element",data:{element_tag_name:S.tagName,filename:S.dataset.filename,linenumber:S.dataset.linenumber},message:"User has selected an element to edit, here's the element's code position: file: ".concat(S.dataset.filename,", line number: ").concat(S.dataset.linenumber)}],C(null),A(!1)),e.additional_message_params=e.additional_message_params||{},E&&(e.additional_message_params.current_page=E.name),i.conversation.messages.push((0,K.A)((0,K.A)({},e),{},{role:"user"}));try{await Ye({appId:r,body:e,app:i,user:t,onSuccess:async e=>{o(e),"pending"!==i.app_stage&&T(),await(async()=>{const e=await es.default.getCurrentUsage();v(e)})()},onError:e=>{}})}catch(s){}},undoMessage:async e=>{try{const s=await ve.undoMessage(r,e);o(s)}catch(a){var s,t;if(403===(null===(s=a.response)||void 0===s?void 0:s.status))u("You do not have access to this app");else u("Failed to undo message: "+((null===(t=a.response.data)||void 0===t?void 0:t.message)||a.message))}},currentPage:E,stopChat:async()=>{const e=await ve.stopChat(i.id);o(e)},suggestions:p,currentUsage:f,isSelectingDivMode:w,setIsSelectingDivMode:_,isElementMode:k,setIsElementMode:A,selectedElement:S,setSelectedElement:C,writeCodeToFile:async(e,s)=>{const t=await gs.write(i.id,e,s);h([]),o(t)},existingSecretNames:b,updateSecrets:async e=>{await vs.updateSecrets(r,e),await I(r)},runtimeAuthToken:y},children:P})},_s=()=>(0,H.useContext)(Ns);class ks extends X.H{getBaseURL(){return"/files"}uploadFile(e){const s=new FormData;return s.append("file",e),this.axios.post("/",s,{headers:{"Content-Type":"multipart/form-data"}})}uploadAppFile(e,s){const t=new FormData;return t.append("file",e),this.axios.post("/apps/".concat(s,"/upload"),t,{headers:{"Content-Type":"multipart/form-data"}})}}const As=new ks;var Ss=t(52607),Cs=t(9305);const Es=["className","sideOffset"],Is=Cs.Kq,Ts=Cs.bL,Ps=Cs.l9,Ls=H.forwardRef((e,s)=>{let{className:t,sideOffset:a=4}=e,n=(0,as.A)(e,Es);return(0,re.jsx)(Cs.UC,(0,K.A)({ref:s,sideOffset:a,className:is("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]",t)},n))});function Os(e){let{onFileUploadClick:s,customButtomRight:t,customButtomLeft:a,variant:n="default"}=e;const[r,l]=(0,H.useState)(!0),i=(0,H.useRef)(null);(0,H.useEffect)(()=>{const e=()=>{if(i.current){const e=i.current.getBoundingClientRect().width;l(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,re.jsx)(Is,{children:(0,re.jsxs)(Ts,{children:[(0,re.jsx)(Ps,{asChild:!0,children:(0,re.jsx)("button",{onClick:s,className:c,children:(0,re.jsx)(Ss.A,{className:"h-4 w-4"})})}),(0,re.jsx)(Ls,{children:(0,re.jsx)("p",{children:"Upload files"})})]})});return(0,re.jsxs)("div",{className:o,ref:i,children:[(0,re.jsx)("div",{className:"flex gap-1 items-center",children:a?a(d):d}),(0,re.jsx)("div",{className:"flex gap-1 items-center",children:t})]})}Ls.displayName=Cs.UC.displayName;var Rs=t(59680);function Ds(e){let{files:s,uploadingFiles:t,onRemoveFile:a}=e;const[n,r]=(0,H.useState)({});return 0===s.length&&0===t.length?null:(0,re.jsxs)("div",{className:"flex flex-wrap gap-4 p-4 border-b",children:[s.map((e,s)=>(0,re.jsx)("div",{className:"relative",children:e.match(/\.(jpg|jpeg|png|gif)$/i)?(0,re.jsxs)("div",{className:"relative group",children:[!n[e]&&(0,re.jsx)("div",{className:"w-[120px] h-[120px] flex items-center justify-center bg-gray-100 rounded-lg",children:(0,re.jsx)(Rs.A,{className:"w-4 h-4 animate-spin text-gray-500"})}),(0,re.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=>{r(s=>(0,K.A)((0,K.A)({},s),{},{[e]:!0}))})(e)}),(0,re.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,re.jsxs)("div",{className:"flex items-center gap-2 p-2 bg-white rounded-lg border border-gray-200 group relative",children:[(0,re.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,re.jsx)("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),(0,re.jsx)("polyline",{points:"14 2 14 8 20 8"})]}),(0,re.jsx)("span",{className:"truncate max-w-[150px]",children:e.split("/").pop()}),(0,re.jsx)("button",{onClick:()=>a(e),className:"text-gray-500 hover:text-gray-700",children:"\xd7"})]})},s)),t.map((e,s)=>(0,re.jsxs)("div",{className:"flex items-center gap-2 p-2 bg-white rounded-lg border border-gray-200",children:[(0,re.jsx)(Rs.A,{className:"w-4 h-4 animate-spin text-gray-500"}),(0,re.jsxs)("span",{className:"truncate max-w-[150px] text-gray-500 text-sm",children:["Uploading ",e,"..."]})]},s))]})}var Ms=t(19900),Fs=t(88276),Bs=t(53034);const Us=(0,H.forwardRef)((e,s)=>{let{value:t,onValueChange:a,onKeyDown:n,onPaste:r,placeholder:l,disabled:i,isProcessing:o,onStop:c,onSend:d,isVisualEditMode:m,isDiscussionMode:u,variant:x="default"}=e;const h=(0,H.useRef)(null);(0,H.useImperativeHandle)(s,()=>h.current);(0,H.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")},[t]);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="home"===x?"absolute flex justify-center ".concat(!o&&!i?"rotate-90":""," items-center top-4 right-2 md:right-4 p-1 ").concat(i?"bg-[#FF5C04]":"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 ").concat(i?"cursor-not-allowed":""):"absolute flex justify-center items-center top-4 w-[30px] h-[30px] right-4 p-1 ".concat(u?i?"bg-violet-300":"bg-violet-600 hover:bg-violet-800":m?i?"bg-blue-300":"bg-blue-600 hover:bg-blue-800":"bg-gray-900 hover:bg-gray-800"," text-white rounded-lg transition-colors");return(0,re.jsxs)("div",{className:"relative",children:[(0,re.jsx)("textarea",{ref:h,value:t,onChange:e=>a(e.target.value),onKeyDown:n,onPaste:r,placeholder:l,disabled:i,className:p,style:{default:{height:"auto",minHeight:"100px",maxHeight:"400px"},home:{height:"120px",minHeight:"110px",maxHeight:"200px"}}[x],onInput:e=>{}}),d&&(0,re.jsx)("button",{onClick:()=>{o?c&&c():d&&d()},className:"".concat(g," ").concat(t||o?"":"cursor-not-allowed"),"aria-label":o?"Stop processing":"Send message",title:o?"Stop processing":"Send message",disabled:!t&&!o,children:o?(0,re.jsx)(Ms.A,{className:"w-4 h-4"}):i?(0,re.jsx)(Fs.A,{className:"w-4 h-4"}):(0,re.jsx)(Bs.A,{className:"w-4 h-4"})})]})});var zs=t(96479);const qs=(0,H.forwardRef)((e,s)=>{let{value:t,files:a=[],onSend:n,placeholder:r,disabled:l,isProcessing:i,onValueChange:o,onFilesChange:c,onStop:d,customButtomRight:m,customButtomLeft:u,variant:x="default",isAdminMode:h=!1,isDiscussionMode:p=!1,isVisualEditMode:g=!1,isOutOfCredits:f=!1}=e;const v=_s(),b=(0,H.useRef)(),j=(0,Qe.Ub)({maxWidth:767}),[y,N]=(0,H.useState)([]),[w,_]=(0,H.useState)(null),k=()=>{n&&(n({text:t,files:a}),o(""),c([]),_(null))},A=async e=>{try{const{valid:t,error:a}=function(e){const s="."+e.name.split(".").pop().toLowerCase();if(![".jpg",".jpeg",".png",".pdf",".txt",".html"].includes(s))return{valid:!1,error:'File type "'.concat(e.name.split(".").pop(),'" is not supported. Supported types: jpg, jpeg, png, pdf, txt, html.')};const t=".pdf"===s,a=[".jpg",".jpeg",".png"].includes(s)?41943040:t?10485760:5242880;if(e.size>a){const s=a/1048576;return{valid:!1,error:'File "'.concat(e.name,'" exceeds the maximum allowed size of ').concat(s,"MB.")}}return{valid:!0,error:null}}(e);if(!t)return _(a),null;let n=e;if(e.type.startsWith("image/")){N(s=>[...s,"".concat(e.name," (processing...)")]);try{n=(await async function(e){if(!e.type.startsWith("image/"))return{file:e,mimeType:e.type};const s=1024,t=2097152,n="image/png"===e.type,r=n?"image/png":"image/jpeg",l=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>s||m>s;if(e.size<=t&&!u)return void i({file:e,mimeType:e.type});u&&(c>m?(m=Math.round(m*s/c),c=s):(c=Math.round(c*s/m),m=s));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=s=>{try{x.toBlob(n=>{if(n)if(n.size<=t)try{const s=e.name,t=s.substring(0,s.lastIndexOf("."))||s,a=new File([n],t+l,{type:r,lastModified:Date.now()});i({file:a,mimeType:r})}catch(a){i({file:e,mimeType:e.type})}else if(s>.55)p(s-.1);else try{const s=e.name,t=s.substring(0,s.lastIndexOf("."))||s,a=new File([n],t+l,{type:r,lastModified:Date.now()});i({file:a,mimeType:r})}catch(a){i({file:e,mimeType:e.type})}else o(new Error("Failed to create image blob"))},r,n?null:s)}catch(a){i({file:e,mimeType:e.type})}};p(.85)}catch(a){i({file:e,mimeType:e.type})}},d.onerror=s=>{i({file:e,mimeType:e.type})}},c.onerror=s=>{i({file:e,mimeType:e.type})}})}(e)).file}catch(s){}}N(s=>s.filter(s=>s!=="".concat(e.name," (processing...)"))),N(s=>[...s,e.name]);const r=null!=v&&v.app?await As.uploadAppFile(n,v.app.id):await As.uploadFile(n);return N(s=>s.filter(s=>s!==e.name)),_(null),r.url}catch(t){return N(s=>s.filter(s=>s!==e.name)),null}},S="home"===x?"w-full relative ".concat(!l&&"shadow-[0_8px_16px_0_rgba(0,0,0,0.04)]"," rounded-[30px] bg-white border border-[#E2E5EB] backdrop-blur px-2"):"w-full relative ".concat(!l&&"shadow-sm shadow-[0_-10px_20px_8px_rgba(248,250,252,1)]"," border border-gray-200 rounded-[16px] bg-white/80 backdrop-blur");return(0,re.jsxs)("div",{className:S,onDrop:async e=>{e.preventDefault();const s=Array.from(e.dataTransfer.files).map(e=>A(e)),t=(await Promise.all(s)).filter(e=>null!==e);t.length>0&&c([...a,...t])},onDragOver:e=>{e.preventDefault()},children:[(0,re.jsx)(Ds,{files:a,uploadingFiles:y,onRemoveFile:e=>c(a.filter(s=>s!==e))}),w&&(0,re.jsx)("div",{className:"px-4 py-2",children:(0,re.jsxs)(us,{variant:"destructive",className:"flex items-center justify-between",children:[(0,re.jsxs)(hs,{children:[w,(0,re.jsxs)("div",{className:"mt-1 text-xs",children:["Please request support for additional file types at ",(0,re.jsx)("a",{href:"https://feedback.base44.com",target:"_blank",rel:"noopener noreferrer",className:"underline hover:text-destructive-foreground/80",children:"feedback.base44.com"})]})]}),(0,re.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,re.jsx)(zs.A,{className:"h-3 w-3"})})]})}),(0,re.jsx)(Us,{ref:s,value:t,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 s,t;const n=null===(s=e.clipboardData||(null===(t=e.originalEvent)||void 0===t?void 0:t.clipboardData))||void 0===s?void 0:s.items;if(!n)return;const r=[];for(let a of n)if("file"===a.kind){const e=a.getAsFile();e&&r.push(A(e))}const l=(await Promise.all(r)).filter(e=>null!==e);l.length>0&&c([...a,...l])},placeholder:r,disabled:l,isProcessing:i,onStop:d,onSend:n?k:null,variant:x,isAdminMode:h,isDiscussionMode:p,isVisualEditMode:g}),(0,re.jsx)("input",{ref:b,type:"file",id:"chat-file-upload",className:"hidden",multiple:!0,onChange:async e=>{const s=Array.from(e.target.files),t=[];for(let a of s){const e=await A(a);e&&t.push(e)}c([...a,...t]),b.current.value=""},accept:".jpg,.jpeg,.png,.pdf,.txt,.html"}),(0,re.jsx)(Os,{onFileUploadClick:()=>document.getElementById("chat-file-upload").click(),value:t,isMobile:j,customButtomLeft:u,customButtomRight:m,variant:x})]})});var Ws=t(92962);const Vs=["className","variant","size","asChild"],Ys=(0,ns.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"}}),Hs=H.forwardRef((e,s)=>{let{className:t,variant:a,size:n,asChild:r=!1}=e,l=(0,as.A)(e,Vs);const i=r?Ws.DX:"button";return(0,re.jsx)(i,(0,K.A)({className:is(Ys({variant:a,size:n,className:t})),ref:s},l))});Hs.displayName="Button";const Gs=[{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 $s(e){let{onSelectStyle:s}=e;const[t,a]=(0,H.useState)({}),[n,r]=(0,H.useState)({}),[l,i]=(0,H.useState)(!0),o=e=>{r(s=>(0,K.A)((0,K.A)({},s),{},{[e]:(s[e]||0)+1})),a(s=>(0,K.A)((0,K.A)({},s),{},{[e]:!0})),setTimeout(()=>{a(s=>(0,K.A)((0,K.A)({},s),{},{[e]:!1}))},1e3)};return l?(0,re.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black bg-opacity-50",children:(0,re.jsxs)("div",{className:"bg-white rounded-xl shadow-2xl w-11/12 max-w-6xl max-h-[90vh] overflow-y-auto",children:[(0,re.jsxs)("div",{className:"sticky top-0 bg-white p-4 border-b flex justify-between items-center z-10",children:[(0,re.jsx)("h1",{className:"text-2xl font-bold text-gray-800",children:"Add styling instructions"}),(0,re.jsx)("button",{onClick:()=>i(!1),className:"text-gray-500 hover:text-gray-700",children:(0,re.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,re.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,re.jsx)("div",{className:"p-4",children:Gs.map(e=>(0,re.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,re.jsxs)("div",{className:"flex flex-col md:flex-row",children:[(0,re.jsxs)("div",{className:"md:w-1/3 p-6",children:[(0,re.jsx)("h2",{className:"text-2xl font-bold mb-2 text-gray-800",children:e.name}),(0,re.jsx)("p",{className:"mb-6 text-gray-600",children:e.description}),(0,re.jsxs)("div",{className:"mb-6",children:[(0,re.jsx)("h3",{className:"text-lg font-semibold mb-2 text-gray-800",children:"Key Features"}),(0,re.jsx)("ul",{className:"list-disc list-inside text-gray-600",children:e.features.map((e,s)=>(0,re.jsx)("li",{className:"mb-1",children:e},s))})]}),(0,re.jsxs)("div",{className:"mb-6",children:[(0,re.jsx)("h3",{className:"text-lg font-semibold mb-2 text-gray-800",children:"Used By"}),(0,re.jsx)("div",{className:"flex flex-wrap gap-2",children:e.brands.map((e,s)=>(0,re.jsx)("span",{className:"inline-block px-3 py-1 rounded-full text-sm bg-gray-100 text-gray-700",children:e},s))})]}),(0,re.jsx)("button",{onClick:()=>{return t=e.id,s(t),void i(!1);var t},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,re.jsx)("div",{className:"md:w-2/3",children:(0,re.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,re.jsxs)("div",{className:"w-full max-w-lg",children:["neo-brutalism"===e.id&&(0,re.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,re.jsx)("h3",{className:"text-xl font-bold mb-4 font-mono text-black",children:"Raw. Unfiltered. Brutal."}),(0,re.jsx)("p",{className:"mb-4 text-black",children:"Neo-Brutalism embraces imperfection and raw expression."}),(0,re.jsx)("button",{className:"bg-red-500 text-white font-bold py-2 px-4 border-4 border-black ".concat(t[e.id]?"animate-bounce":""," hover:bg-red-600 transform hover:-translate-y-1 transition-transform"),onClick:()=>o(e.id),children:"CLICK ME"}),(0,re.jsxs)("div",{className:"mt-4 grid grid-cols-3 gap-3",children:[(0,re.jsx)("div",{className:"bg-blue-500 border-4 border-black p-2",children:(0,re.jsx)("p",{className:"text-white text-sm font-bold",children:"Bold"})}),(0,re.jsx)("div",{className:"bg-green-500 border-4 border-black p-2",children:(0,re.jsx)("p",{className:"text-black text-sm font-bold",children:"Raw"})}),(0,re.jsx)("div",{className:"bg-purple-500 border-4 border-black p-2",children:(0,re.jsx)("p",{className:"text-white text-sm font-bold",children:"Expressive"})})]})]}),"neumorphism"===e.id&&(0,re.jsx)("div",{className:"bg-gray-200 p-6 rounded-xl",children:(0,re.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,re.jsx)("h3",{className:"text-xl font-medium mb-4 text-gray-700",children:"Soft & Tactile"}),(0,re.jsx)("p",{className:"mb-4 text-gray-600",children:"Neumorphism creates a soft UI that appears to extrude from the background."}),(0,re.jsx)("button",{className:"bg-gray-200 text-gray-700 font-medium py-2 px-4 rounded-xl ".concat(t[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,re.jsx)("div",{className:"mt-4",children:(0,re.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,re.jsx)("p",{className:"text-gray-700 font-medium",children:"Volume"}),(0,re.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,re.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,re.jsxs)("div",{className:"relative min-h-64 p-6 rounded-xl overflow-hidden",children:[(0,re.jsx)("div",{className:"absolute inset-0 flex justify-around items-center",children:[...Array(5)].map((s,a)=>(0,re.jsx)("div",{className:"bg-white rounded-full w-16 h-16 opacity-20 ".concat(t[e.id]?"animate-pulse":"")},a))}),(0,re.jsx)("div",{className:"relative z-10",children:(0,re.jsxs)("div",{className:"backdrop-blur-xl bg-white/30 p-6 rounded-xl border border-white/50 shadow-lg",children:[(0,re.jsx)("h3",{className:"text-xl font-medium mb-4 text-white",children:"Transparent & Blurred"}),(0,re.jsx)("p",{className:"mb-4 text-white/90",children:"Glassmorphism creates a frosted glass effect that adds depth and elegance."}),(0,re.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,re.jsxs)("div",{className:"mt-4 flex space-x-2",children:[(0,re.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,re.jsx)("p",{className:"text-white text-sm font-medium",children:"Layer 1"})}),(0,re.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,re.jsx)("p",{className:"text-white text-sm font-medium",children:"Layer 2"})}),(0,re.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,re.jsx)("p",{className:"text-white text-sm font-medium",children:"Layer 3"})})]})]})})]}),"material-design"===e.id&&(0,re.jsx)("div",{className:"bg-white p-6 rounded-lg shadow-lg",children:(0,re.jsxs)("div",{className:"bg-white p-6 rounded-lg shadow-md",children:[(0,re.jsx)("h3",{className:"text-xl font-medium mb-4 text-gray-800",children:"Elevated & Structured"}),(0,re.jsx)("p",{className:"mb-4 text-gray-600",children:"Material Design uses physics-inspired animations and layered interfaces."}),(0,re.jsx)("button",{className:"bg-blue-500 text-white font-medium py-2 px-4 rounded shadow-md ".concat(t[e.id]?"shadow-xl -translate-y-1":""," hover:shadow-lg hover:-translate-y-1 transition-all"),onClick:()=>o(e.id),children:"ELEVATE"}),(0,re.jsxs)("div",{className:"mt-4 grid grid-cols-2 gap-4",children:[(0,re.jsx)("div",{className:"bg-red-500 p-3 rounded shadow-md",children:(0,re.jsx)("p",{className:"text-white text-sm font-medium",children:"Cards"})}),(0,re.jsx)("div",{className:"bg-white p-3 rounded shadow-md",children:(0,re.jsxs)("div",{className:"flex items-center justify-between",children:[(0,re.jsx)("p",{className:"text-gray-700 text-sm font-medium",children:"Toggle"}),(0,re.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,re.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,re.jsx)("div",{className:"bg-purple-100 p-6 rounded-3xl shadow-lg",children:(0,re.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,re.jsx)("h3",{className:"text-xl font-medium mb-4 text-blue-700",children:"Soft & Puffy"}),(0,re.jsx)("p",{className:"mb-4 text-blue-600",children:"Claymorphism creates a soft, puffy, and playful interface that looks like clay."}),(0,re.jsx)("button",{className:"bg-purple-300 text-purple-700 font-medium py-2 px-4 rounded-2xl \n ".concat(t[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,re.jsxs)("div",{className:"mt-4 grid grid-cols-3 gap-2",children:[(0,re.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,re.jsx)("p",{className:"text-green-600 text-sm font-medium text-center",children:"Soft"})}),(0,re.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,re.jsx)("p",{className:"text-yellow-600 text-sm font-medium text-center",children:"Puffy"})}),(0,re.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,re.jsx)("p",{className:"text-pink-600 text-sm font-medium text-center",children:"Playful"})})]})]})})]})})})]})},e.id))})]})}):null}const Js=["limit","skip","sort_by"];class Zs extends X.y{listCatalogItems(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{limit:s,skip:t,sort_by:a}=e,n=(0,as.A)(e,Js);const r={};return Object.keys(n).length>0&&(r.q=JSON.stringify(n)),s&&(r.limit=s),t&&(r.skip=t),a&&(r.sort_by=a),this.axios.get("/catalog",Object.keys(r).length?{params:r}: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,s){const t=s?{language:s}:void 0;return this.axios.post("/catalog/".concat(e,"/approve"),t)}declineItem(e,s){const t=s?{reason:s}:void 0;return this.axios.post("/catalog/".concat(e,"/decline"),t)}archiveItem(e){return this.axios.post("/catalog/".concat(e,"/archive"))}inviteAdmin(e,s){return this.axios.post("/catalog/".concat(e,"/invite"),{email:s})}}const Ks=new class extends Zs{getBaseURL(){return"/integration-catalog-items"}},Xs=["className","variant"],Qs=(0,ns.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 et(e){let{className:s,variant:t}=e,a=(0,as.A)(e,Xs);return(0,re.jsx)("div",(0,K.A)({className:is(Qs({variant:t}),s)},a))}const st=["className"],tt=["className"],at=["className"],nt=["className"],rt=["className"],lt=["className"],it=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,st);return(0,re.jsx)("div",(0,K.A)({ref:s,className:is("rounded-lg border bg-card text-card-foreground shadow-sm",t)},a))});it.displayName="Card";const ot=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,tt);return(0,re.jsx)("div",(0,K.A)({ref:s,className:is("flex flex-col space-y-1.5 p-6",t)},a))});ot.displayName="CardHeader";const ct=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,at);return(0,re.jsx)("h3",(0,K.A)({ref:s,className:is("text-2xl font-semibold leading-none tracking-tight",t)},a))});ct.displayName="CardTitle";const dt=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,nt);return(0,re.jsx)("p",(0,K.A)({ref:s,className:is("text-sm text-muted-foreground",t)},a))});dt.displayName="CardDescription";const mt=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,rt);return(0,re.jsx)("div",(0,K.A)({ref:s,className:is("p-6 pt-0",t)},a))});mt.displayName="CardContent";const ut=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,lt);return(0,re.jsx)("div",(0,K.A)({ref:s,className:is("flex items-center p-6 pt-0",t)},a))});ut.displayName="CardFooter";var xt=t(48077);const ht=["className","orientation","decorative"],pt=H.forwardRef((e,s)=>{let{className:t,orientation:a="horizontal",decorative:n=!0}=e,r=(0,as.A)(e,ht);return(0,re.jsx)(xt.b,(0,K.A)({ref:s,decorative:n,orientation:a,className:is("shrink-0 bg-border","horizontal"===a?"h-[1px] w-full":"h-full w-[1px]",t)},r))});pt.displayName=xt.b.displayName;const gt=["className","type"],ft=H.forwardRef((e,s)=>{let{className:t,type:a}=e,n=(0,as.A)(e,gt);return(0,re.jsx)("input",(0,K.A)({type:a,className:is("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",t),ref:s},n))});ft.displayName="Input";var vt=t(4321),bt=t(84128);const jt=["className"],yt=(0,ns.cva)("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),Nt=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,jt);return(0,re.jsx)(bt.b,(0,K.A)({ref:s,className:is(yt(),t)},a))});Nt.displayName=bt.b.displayName;var wt=t(5995),_t=t(25675);const kt=["className"],At=["className"],St=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,kt);return(0,re.jsx)(wt.bL,(0,K.A)((0,K.A)({className:is("grid gap-2",t)},a),{},{ref:s}))});St.displayName=wt.bL.displayName;const Ct=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,At);return(0,re.jsx)(wt.q7,(0,K.A)((0,K.A)({ref:s,className:is("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",t)},a),{},{children:(0,re.jsx)(wt.C1,{className:"flex items-center justify-center",children:(0,re.jsx)(_t.A,{className:"h-2.5 w-2.5 fill-current text-current"})})}))});Ct.displayName=wt.q7.displayName;var Et=t(58390),It=t(27453),Tt=t(17684),Pt=t(86311);const Lt=["className","children","advancedDropdown"],Ot=["className"],Rt=["className"],Dt=["className","children","position"],Mt=["className"],Ft=["className","children","hideCheckIcon"],Bt=["className"],Ut=Et.bL,zt=Et.YJ,qt=Et.WT,Wt=H.forwardRef((e,s)=>{let{className:t,children:a,advancedDropdown:n=!1}=e,r=(0,as.A)(e,Lt);return(0,re.jsxs)(Et.l9,(0,K.A)((0,K.A)({ref:s,className:is("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"),t)},r),{},{children:[n?(0,re.jsx)("div",{className:"flex-1 min-w-0",children:a}):a,(0,re.jsx)(Et.In,{asChild:!0,children:(0,re.jsx)(It.A,{className:is("h-4 w-4 opacity-50",n?"flex-shrink-0 ml-2":"")})})]}))});Wt.displayName=Et.l9.displayName;const Vt=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,Ot);return(0,re.jsx)(Et.PP,(0,K.A)((0,K.A)({ref:s,className:is("flex cursor-default items-center justify-center py-1",t)},a),{},{children:(0,re.jsx)(Tt.A,{className:"h-4 w-4"})}))});Vt.displayName=Et.PP.displayName;const Yt=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,Rt);return(0,re.jsx)(Et.wn,(0,K.A)((0,K.A)({ref:s,className:is("flex cursor-default items-center justify-center py-1",t)},a),{},{children:(0,re.jsx)(It.A,{className:"h-4 w-4"})}))});Yt.displayName=Et.wn.displayName;const Ht=H.forwardRef((e,s)=>{let{className:t,children:a,position:n="popper"}=e,r=(0,as.A)(e,Dt);return(0,re.jsx)(Et.ZL,{children:(0,re.jsxs)(Et.UC,(0,K.A)((0,K.A)({ref:s,className:is("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",t),position:n},r),{},{children:[(0,re.jsx)(Vt,{}),(0,re.jsx)(Et.LM,{className:is("p-1","popper"===n&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:a}),(0,re.jsx)(Yt,{})]}))})});Ht.displayName=Et.UC.displayName;const Gt=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,Mt);return(0,re.jsx)(Et.JU,(0,K.A)({ref:s,className:is("py-1.5 pl-8 pr-2 text-sm font-semibold",t)},a))});Gt.displayName=Et.JU.displayName;const $t=H.forwardRef((e,s)=>{let{className:t,children:a,hideCheckIcon:n=!1}=e,r=(0,as.A)(e,Ft);return(0,re.jsxs)(Et.q7,(0,K.A)((0,K.A)({ref:s,className:is("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",t)},r),{},{children:[!n&&(0,re.jsx)("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:(0,re.jsx)(Et.VF,{children:(0,re.jsx)(Pt.A,{className:"h-4 w-4"})})}),(0,re.jsx)(Et.p4,{children:a})]}))});$t.displayName=Et.q7.displayName;const Jt=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,Bt);return(0,re.jsx)(Et.wv,(0,K.A)({ref:s,className:is("-mx-1 my-1 h-px bg-muted",t)},a))});function Zt(e){let{secret:s,value:t,onChange:a}=e;const{user:n}=oe(),{name:r,description:l}=s,[i,o]=(0,H.useState)([]),[c,d]=(0,H.useState)(!0),[m,u]=(0,H.useState)((null==t?void 0:t.type)||"value"),[x,h]=(0,H.useState)((null==t?void 0:t.value)||""),[p,g]=(0,H.useState)("clone"===(null==t?void 0:t.type)?t.value:"");(0,H.useEffect)(()=>{(async()=>{try{const e=await vs.getGeneralSecrets(r);o(e||[])}catch(e){o([])}finally{d(!1)}})()},[r]),(0,H.useEffect)(()=>{"value"===m?a(r,{type:"value",value:x}):"clone"===m&&p&&a(r,{type:"clone",value:p})},[m,x,p,r,a]);return(0,re.jsxs)("div",{className:"mb-8 pb-6 border-b border-gray-200 last:border-0 last:mb-0 last:pb-0",children:[(0,re.jsx)("div",{className:"flex items-center mb-4",children:(0,re.jsxs)("div",{className:"flex items-center gap-2",children:[(0,re.jsx)(vt.A,{className:"h-4 w-4 text-gray-500"}),(0,re.jsx)(Nt,{className:"text-sm font-medium",children:r})]})}),(0,re.jsxs)(St,{value:m,onValueChange:u,className:"flex gap-8 mb-4",children:[(0,re.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,re.jsx)(Ct,{value:"value",id:"value-".concat(r),className:"h-4 w-4"}),(0,re.jsx)(Nt,{htmlFor:"value-".concat(r),className:"text-xs cursor-pointer",children:"New value"})]}),"platform_admin"===(null==n?void 0:n.platform_role)&&(0,re.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,re.jsx)(Ct,{value:"clone",id:"clone-".concat(r),className:"h-4 w-4"}),(0,re.jsx)(Nt,{htmlFor:"clone-".concat(r),className:"text-xs cursor-pointer",children:"Reuse existing"})]})]}),"value"===m?(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(ft,{type:"password",placeholder:"Enter ".concat(r),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"}),l&&(0,re.jsx)("p",{className:"text-xs text-gray-500 mt-2 ml-1",children:l})]}):(0,re.jsxs)(re.Fragment,{children:[c?(0,re.jsxs)("div",{className:"flex items-center h-9 text-xs text-gray-500 mt-3 bg-gray-50 rounded-md px-3",children:[(0,re.jsx)(Ze.A,{className:"h-4 w-4 animate-spin mr-2"}),"Loading existing secrets..."]}):i.length>0?(0,re.jsxs)(Ut,{value:p,onValueChange:e=>{g(e)},children:[(0,re.jsx)(Wt,{className:"h-9 text-sm mt-3",children:(0,re.jsx)(qt,{placeholder:"Select an existing secret"})}),(0,re.jsx)(Ht,{className:"max-h-[200px] overflow-y-auto",children:i.map(e=>(0,re.jsxs)($t,{value:e.id,className:"text-xs py-3",children:[e.app_name||"Unnamed App"," (",e.secret_name,")"]},e.id))})]}):(0,re.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 ",r]}),l&&(0,re.jsx)("p",{className:"text-xs text-gray-500 mt-2 ml-1",children:l})]})]})}function Kt(e){let{secretNames:s,value:t={},onChange:a}=e;const n=(e,s)=>{a((0,K.A)((0,K.A)({},t),{},{[e]:s}))};return(0,re.jsx)("div",{className:"text-sm px-5 py-7",children:s.map((e,s)=>(0,re.jsx)("div",{className:"mb-6 last:mb-0",children:(0,re.jsx)(Zt,{secret:e,value:t[e.name],onChange:n})},s))})}Jt.displayName=Et.wv.displayName;const Xt=e=>{let{integration:s,secrets:t,onSecretsChange:a,onRemove:n}=e;const{item:r}=s,l=r.required_secrets&&r.required_secrets.length>0,i=!(!l||r.required_secrets.every(e=>{const s=t[e.name];return!!s&&!!("value"!==s.type||s.value&&""!==s.value.trim())&&!!("clone"!==s.type||s.value&&""!==s.value.trim())}));return(0,re.jsx)(it,{className:"mt-4 border-slate-200 overflow-hidden ".concat(i?"border-red-200":""),children:(0,re.jsxs)(mt,{className:"p-0",children:[(0,re.jsx)("div",{className:"flex flex-col sm:flex-row",children:(0,re.jsxs)("div",{className:"flex-1 p-4",children:[(0,re.jsxs)("div",{className:"flex justify-between items-start",children:[(0,re.jsxs)("div",{className:"flex gap-3 items-center mb-2",children:[(0,re.jsx)("div",{className:"h-10 w-10 rounded-md border border-slate-200 flex-shrink-0 overflow-hidden bg-slate-50",children:r.image_url?(0,re.jsx)("img",{src:r.image_url,alt:r.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(r.name.charAt(0).toUpperCase(),"")}}):(0,re.jsx)("div",{className:"h-full w-full bg-gradient-to-br from-blue-100 to-teal-100 flex items-center justify-center",children:(0,re.jsx)("span",{className:"text-teal-600 text-lg font-semibold",children:r.name.charAt(0).toUpperCase()})})}),(0,re.jsxs)("div",{children:[(0,re.jsx)("h3",{className:"font-semibold text-slate-800",children:r.name}),(0,re.jsxs)("div",{className:"flex items-center gap-2",children:[r.official&&(0,re.jsx)(et,{className:"bg-blue-50 text-blue-700 border-blue-100 hover:bg-blue-100 text-xs",children:"Official"}),r.requires_backend_functions&&(0,re.jsx)("span",{className:"text-xs text-slate-500",children:"Requires backend functions"})]})]})]}),(0,re.jsx)("button",{className:"text-slate-400 hover:text-slate-600 hover:bg-slate-100 p-1.5 rounded-md transition-colors",onClick:()=>n(s.item.id),title:"Remove integration","aria-label":"Remove integration",children:(0,re.jsx)(zs.A,{className:"h-4 w-4"})})]}),r.description&&(0,re.jsx)("p",{className:"text-sm text-slate-600 mt-1",children:r.description})]})}),l&&(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(pt,{className:"my-1"}),(0,re.jsxs)("div",{className:"p-4 pt-3 bg-slate-50",children:[(0,re.jsxs)("div",{className:"flex justify-between items-center",children:[(0,re.jsx)("h4",{className:"text-xs uppercase tracking-wide text-slate-500 font-medium mb-3",children:"Required API Keys"}),i&&(0,re.jsxs)("div",{className:"flex items-center text-red-500 text-xs mb-3",children:[(0,re.jsx)(Xe.A,{className:"h-3 w-3 mr-1"}),(0,re.jsx)("span",{children:"Missing required keys"})]})]}),(0,re.jsx)(Kt,{secretNames:r.required_secrets,value:t,onChange:a})]})]})]})})};var Qt=t(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 sa extends X.H{getBaseURL(){return"/"}getAppSuggestions(){return this.axios.get("/app-suggestions")}}const ta=new sa;function aa(e){let{onSetPrompt:s}=e;const[t,a]=(0,H.useState)(null),[n,r]=(0,H.useState)(null),[l,i]=(0,H.useState)(!0),[o,c]=(0,H.useState)([]),d=()=>[...Object.keys(ea)].sort(()=>.5-Math.random()).slice(0,5);(0,H.useEffect)(()=>{c(d())},[]),(0,H.useEffect)(()=>{(async()=>{try{i(!0);const e=await ta.getAppSuggestions();r(e)}catch(e){r(null)}finally{i(!1)}})()},[]);const m=e=>{s(e)};return l?(0,re.jsx)("div",{className:"px-[8px] w-full mt-4",children:(0,re.jsx)("div",{className:"flex flex-wrap gap-2.5",children:[...Array(5)].map((e,s)=>(0,re.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")}},s))})}):(0,re.jsxs)("div",{className:" w-full mt-4",children:[t?(0,re.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,re.jsx)(Qt.A,{className:"h-4 w-4 mr-1"}),"Back to categories"]}):n?null:(0,re.jsxs)("div",{className:"flex items-center justify-between mb-3",children:[(0,re.jsx)("h3",{className:"text-slate-700 text-sm font-light font-base44",children:"Ideas to get started"}),(0,re.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,re.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 18 18",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:(0,re.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.app_suggestion_1.title,prompt:n.app_suggestion_1.prompt},{title:n.app_suggestion_2.title,prompt:n.app_suggestion_2.prompt},{title:n.app_suggestion_3.title,prompt:n.app_suggestion_3.prompt},{title:n.app_suggestion_4.title,prompt:n.app_suggestion_4.prompt},{title:n.app_suggestion_5.title,prompt:n.app_suggestion_5.prompt}];return(0,re.jsx)("div",{className:"flex flex-wrap gap-2.5",children:e.map((e,s)=>(0,re.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},s))})})():t?(0,re.jsx)("div",{className:"flex flex-wrap gap-2.5",children:ea[t].map((e,s)=>(0,re.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},s))}):(0,re.jsx)("div",{className:"flex flex-wrap gap-2.5",children:o.map((e,s)=>(0,re.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},s))})]})}function na(e){let{onStart:s,loading:t}=e;const[a,n]=(0,H.useState)(""),[r,l]=(0,H.useState)([]),[i,o]=(0,H.useState)(!1),[c,d]=(0,H.useState)(!1),[m,u]=(0,H.useState)(null),[x]=(0,J.useSearchParams)(),h=(0,Z.Zp)(),[p,g]=(0,H.useState)([]),[f,v]=(0,H.useState)(!1),[b,j]=(0,H.useState)({}),[y,N]=(0,H.useState)(!1),[w,_]=(0,H.useState)(!1),[k,A]=(0,H.useState)(!1),[S,C]=(0,H.useState)(!0);(0,H.useEffect)(()=>{(async()=>{try{C(!0);const e=await es.default.getCurrentUsage();_(e.is_over_limit),A(e.past_due)}catch(e){}finally{C(!1)}})()},[]),(0,H.useEffect)(()=>{const e=x.get("integrations");if(e){const s=e.split(",");v(!0),Promise.all(s.map(e=>Ks.getCatalogItem(e))).then(e=>{const s=e.map(e=>e);g(s)}).catch(e=>{}).finally(()=>{v(!1)})}},[]);const E=()=>0===p.length||p.every(e=>{const s=e.item;return!s.required_secrets||0===s.required_secrets.length||s.required_secrets.every(e=>{const s=b[e.name];return!!s&&(!!("value"!==s.type||s.value&&""!==s.value.trim())&&!!("clone"!==s.type||s.value&&""!==s.value.trim()))})}),I=e=>{if(1===p.length)return n(""),l([]),u(null),o(!1),g([]),j({}),N(!1),void h("/");const s=p.filter(s=>s.item.id!==e);g(s);const t=s.map(e=>e.item.id).join(",");h(t?"/?integrations=".concat(t):"/");const a=(0,K.A)({},b),r=p.find(s=>s.item.id===e);r&&r.item.required_secrets&&(r.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 s=m?(null===(e=Gs.find(e=>e.id===m))||void 0===e?void 0:e.name)||m:null;return(0,re.jsx)(Is,{children:(0,re.jsxs)(Ts,{children:[(0,re.jsx)(Ps,{asChild:!0,children:(0,re.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,re.jsx)($e.A,{className:"h-3 w-3"}),(0,re.jsx)("span",{children:s?"Style: ".concat(s):"Styling Instructions"})]})}),(0,re.jsx)(Ls,{side:"top",className:"bg-slate-800 text-white p-3 rounded-lg border-0 shadow-xl max-w-[300px]",children:(0,re.jsx)("div",{className:"space-y-2",children:(0,re.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,re.jsx)(Is,{children:(0,re.jsxs)(Ts,{children:[(0,re.jsx)(Ps,{asChild:!0,children:(0,re.jsxs)("div",{className:"flex items-center gap-1 px-2 py-1 rounded-md text-xs bg-green-100 text-green-700",children:[(0,re.jsx)(Je.A,{className:"h-3 w-3"}),(0,re.jsxs)("span",{children:["Integrations: ",p.length]})]})}),(0,re.jsx)(Ls,{side:"top",className:"bg-slate-800 text-white p-3 rounded-lg border-0 shadow-xl max-w-[300px]",children:(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsx)("p",{className:"text-xs font-medium",children:"Selected Integrations:"}),(0,re.jsx)("div",{className:"flex flex-wrap gap-1",children:p.map(e=>(0,re.jsx)(et,{className:"bg-green-700 text-xs",children:e.item.name},e.item.id))})]})})]})});return(0,re.jsxs)("div",{children:[(0,re.jsxs)("div",{className:"relative",children:[k&&(0,re.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,re.jsxs)("div",{className:"flex items-center",children:[(0,re.jsx)(Ke.A,{className:"h-5 w-5 mr-2 flex-shrink-0"}),(0,re.jsx)("span",{className:"font-medium",children:"Subscription payment overdue"})]}),(0,re.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,re.jsx)("div",{children:(0,re.jsx)(Hs,{onClick:T,className:"bg-amber-600 hover:bg-amber-700 text-white",size:"sm",children:"Go to Billing"})})]}),!k&&w&&(0,re.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,re.jsxs)("div",{className:"flex items-center",children:[(0,re.jsx)(Ke.A,{className:"h-5 w-5 mr-2 flex-shrink-0"}),(0,re.jsx)("span",{className:"font-medium",children:"You've reached your usage limit"})]}),(0,re.jsx)("p",{className:"text-sm",children:"You need to upgrade your plan to continue creating apps."}),(0,re.jsx)("div",{children:(0,re.jsx)(Hs,{onClick:T,className:"bg-amber-600 hover:bg-amber-700 text-white",size:"sm",children:"Go to Billing"})})]}),y&&(0,re.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,re.jsx)(Xe.A,{className:"h-4 w-4 mr-2 flex-shrink-0"}),(0,re.jsx)("span",{children:"Please fill in all required API keys before submitting."})]}),(0,re.jsx)(qs,{value:a,files:r,onSend:()=>{const e=a.trim();if(e){if(w)return;if(!E())return void N(!0);s({text:e,files:r,deep_coding_mode:i,integrations:p.map(e=>e.item.id),secrets:b}),n(""),l([]),u(null),N(!1)}},placeholder:"Describe the app you want to create...",disabled:t||w||S,isProcessing:t||S,onValueChange:n,onFilesChange:l,variant:"home",customButtomLeft:e=>(0,re.jsxs)("div",{className:"flex items-center gap-2",children:[e,(0,re.jsx)(L,{}),(0,re.jsx)(O,{})]})})]}),f?(0,re.jsxs)("div",{className:"mt-4 flex items-center justify-center p-4 bg-slate-50 rounded-lg border border-slate-200",children:[(0,re.jsx)(Ze.A,{className:"h-5 w-5 text-slate-400 animate-spin mr-3"}),(0,re.jsx)("p",{className:"text-sm text-slate-600",children:"Loading integration..."})]}):p.length>0?(0,re.jsx)("div",{children:p.map((e,s)=>(0,re.jsx)(Xt,{integration:e,secrets:b,onSecretsChange:P,onRemove:I},s))}):(0,re.jsx)(re.Fragment,{children:!w&&(0,re.jsx)(aa,{onSetPrompt:e=>{n(e)}})}),c&&(0,re.jsx)($s,{onSelectStyle:e=>{u(e),d(!1);const s=Gs.find(s=>s.id===e);s&&n(e=>{const t=e.trim();return t?"".concat(t,"\n------\n").concat(s.prompt):s.prompt})}})]})}var ra=t(59051),la=t.n(ra),ia=t(75659);const oa=["className"],ca=["className"],da=["className"],ma=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,oa);return(0,re.jsx)(ia.bL,(0,K.A)({ref:s,className:is("relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",t)},a))});ma.displayName=ia.bL.displayName;const ua=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,ca);return(0,re.jsx)(ia._V,(0,K.A)({ref:s,className:is("aspect-square h-full w-full",t)},a))});ua.displayName=ia._V.displayName;const xa=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,da);return(0,re.jsx)(ia.H4,(0,K.A)({ref:s,className:is("flex h-full w-full items-center justify-center rounded-full bg-muted",t)},a))});xa.displayName=ia.H4.displayName;var ha=t(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 s="base44.app",t=(a=s).includes("localhost")||a.includes("127.0.0.1")?"http":"https";var a;return"".concat(t,"://").concat(e,".").concat(s)}const ba=function(e){let{app:s,linkToBuilder:t=!0}=e;const{user:a}=oe(),n=t?"/apps/".concat(s.id,"/editor/preview"):fa(s);return(0,re.jsx)(J.Link,{to:n,className:"block h-full group",title:"Open ".concat(s.name),children:(0,re.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,re.jsxs)("div",{className:"flex gap-3 h-full",children:[(0,re.jsx)("div",{className:"flex-shrink-0",children:(0,re.jsxs)(ma,{className:"h-20 w-20 rounded-[8px]",children:[(0,re.jsx)(ua,{src:s.logo_url,alt:"".concat(s.name," Logo")}),(0,re.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 s=e.trim().split(" ");return 1===s.length?e.charAt(0).toUpperCase():(s[0].charAt(0)+s[1].charAt(0)).toUpperCase()})(s.name)})]})}),(0,re.jsxs)("div",{className:"flex-1 min-w-0 flex flex-col justify-between h-20",children:[(0,re.jsxs)("div",{className:"flex-1 mb-1",children:[(0,re.jsxs)("div",{className:"mb-1 flex items-center gap-1",children:[(0,re.jsx)("h3",{className:"font-medium text-slate-800 truncate font-base44 text-base leading-tight",children:s.name}),(0,re.jsx)("span",{className:"text-black opacity-0 group-hover:opacity-100 transition-opacity duration-300",children:(0,re.jsx)(ha.A,{size:16})})]}),(0,re.jsx)("p",{className:"text-sm text-slate-600 line-clamp-2 font-base44 leading-tight mb-1",children:s.user_description||"No description available"})]}),(0,re.jsx)("div",{className:"flex justify-between items-center",children:(0,re.jsxs)("div",{className:"flex items-center text-xs text-gray-400 font-base44",children:[(0,re.jsxs)("span",{className:"whitespace-nowrap flex-shrink-0",children:["Updated ",(r=s.updated_date,la().utc(r,la().ISO_8601).fromNow())]}),"platform_admin"===a.platform_role&&(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)("span",{className:"mx-2 w-1 h-1 bg-gray-200 rounded-full flex-shrink-0"}),(0,re.jsxs)("span",{className:"truncate min-w-0",children:["by ",(e=>{if(null!=e&&e.includes("@")){const s=e.split("@")[0];return s.charAt(0).toUpperCase()+s.slice(1)}return e})(s.created_by)]})]})]})})]})]})})});var r};const ja=function(){const[e,s]=(0,H.useState)([]),[t,a]=(0,H.useState)(!0),n=(0,Z.Zp)(),{activeWorkspaceId:r}=ge();(0,H.useEffect)(()=>{l()},[r]);const l=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(","));s(e)}catch(e){}finally{a(!1)}};return(0,re.jsxs)("div",{className:"fade-in",children:[(0,re.jsxs)("div",{className:"flex items-center justify-between mb-6",children:[(0,re.jsx)("div",{className:"relative",children:(0,re.jsx)("h2",{className:"text-xl font-bold text-slate-900 font-base44",children:"Recent Apps"})}),e.length>6&&(0,re.jsx)("button",{onClick:()=>{n("/apps")},className:"text-sm text-orange-600 hover:text-orange-700 font-medium",children:"View all"})]}),t?(0,re.jsx)("div",{className:"flex justify-center py-12",children:(0,re.jsx)("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-orange-500"})}):e.length>0?(0,re.jsx)("div",{className:"grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-5 slide-up",children:e.map((e,s)=>(0,re.jsx)("div",{className:"animate-in",style:{animationDelay:"".concat(80*s,"ms")},children:(0,re.jsx)(ba,{app:e})},e.id))}):(0,re.jsxs)("div",{className:"text-center py-12 border-2 border-dashed border-slate-200 rounded-xl fade-in md:p-8",children:[(0,re.jsx)("h3",{className:"text-xl mb-4 text-slate-800",children:"You haven't created any apps yet."}),(0,re.jsx)("p",{className:"text-slate-600 mb-6",children:"Create your first app using the form above!"})]}),(0,re.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=t(6890);class Na extends X.H{getBaseURL(){return"/app-logs"}fetchLogs(e){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return this.axios.get("/".concat(e),{params:s})}logUserInApp(e,s){return this.axios.post("/".concat(e,"/log-user-in-app/").concat(s))}getStats(e){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return"all"===e?this.axios.get("/platform-admin/platform-stats",{params:s}):this.axios.get("/".concat(e,"/stats"),{params:s})}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,s]=(0,H.useState)([]),[t,a]=(0,H.useState)(!0);return(0,H.useEffect)(()=>{(async()=>{try{const e=await wa.getTrendingApps();s(e.trending_apps.map(e=>(0,K.A)((0,K.A)({},e),{},{created_by:"Community"})))}catch(e){}finally{a(!1)}})()},[]),t?(0,re.jsxs)("div",{className:"mt-12",children:[(0,re.jsxs)("h2",{className:"text-2xl font-bold mb-6 flex items-center",children:[(0,re.jsx)(ya.A,{className:"w-6 h-6 mr-2"}),"Trending Apps"]}),(0,re.jsx)("div",{className:"flex justify-center",children:(0,re.jsx)("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-primary"})})]}):e.length?(0,re.jsx)("div",{className:"mt-12",children:(0,re.jsx)("div",{className:"grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-6",children:e.map(e=>(0,re.jsx)(ba,{app:e,linkToBuilder:!1},e.id))})}):null}var ka=t(4174);const Aa=["className"],Sa=["className","children"],Ca=["className"],Ea=["className"],Ia=["className"],Ta=["className"],Pa=ka.Root,La=ka.Trigger,Oa=ka.Portal,Ra=ka.Close,Da=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,Aa);return(0,re.jsx)(ka.Overlay,(0,K.A)({ref:s,className:is("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",t)},a))});Da.displayName=ka.Overlay.displayName;const Ma=H.forwardRef((e,s)=>{let{className:t,children:a}=e,n=(0,as.A)(e,Sa);return(0,re.jsxs)(Oa,{children:[(0,re.jsx)(Da,{}),(0,re.jsxs)(ka.Content,(0,K.A)((0,K.A)({ref:s,className:is("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",t)},n),{},{children:[a,(0,re.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,re.jsx)(zs.A,{className:"h-4 w-4"}),(0,re.jsx)("span",{className:"sr-only",children:"Close"})]})]}))]})});Ma.displayName=ka.Content.displayName;const Fa=e=>{let{className:s=""}=e,t=(0,as.A)(e,Ca);return(0,re.jsx)("div",(0,K.A)({className:is("flex flex-col space-y-1.5 text-center sm:text-left",s)},t))};Fa.displayName="DialogHeader";const Ba=e=>{let{className:s}=e,t=(0,as.A)(e,Ea);return(0,re.jsx)("div",(0,K.A)({className:is("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",s)},t))};Ba.displayName="DialogFooter";const Ua=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,Ia);return(0,re.jsx)(ka.Title,(0,K.A)({ref:s,className:is("text-lg font-semibold leading-none tracking-tight",t)},a))});Ua.displayName=ka.Title.displayName;const za=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,Ta);return(0,re.jsx)(ka.Description,(0,K.A)({ref:s,className:is("text-sm text-muted-foreground",t)},a))});za.displayName=ka.Description.displayName;var qa=t(68935),Wa=t(6285),Va=t(72916);class Ya extends X.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:s,appName:t}=e;return(0,ae.Ay)("/apps/buy_domain").post("/start",{appId:s,appName:t})}}const Ha=new Ya,Ga=e=>{let{app:s,isOpen:t,onClose:a}=e;const[n,r]=(0,H.useState)([]);(0,H.useEffect)(()=>{(async()=>{if(t&&s)try{const e=await Ha.filter({app_id:s.id});r(e)}catch(e){}})()},[t,null==s?void 0:s.id]);const l=e=>{const t=s?"I've built ".concat(s.name," with @base_44!"):"Check out what I built with @base_44!",a=s&&n.length>0?"https://".concat(n[0].domain):s?fa(s):window.location.href;"twitter"===e?window.open("https://x.com/intent/tweet?text=".concat(encodeURIComponent(t))):"linkedin"===e&&window.open("https://www.linkedin.com/sharing/share-offsite/?url=".concat(encodeURIComponent(a)))};return(0,re.jsx)(Pa,{open:t,onOpenChange:a,children:(0,re.jsxs)(Ma,{className:"sm:max-w-[625px]",children:[(0,re.jsxs)(Fa,{children:[(0,re.jsx)("div",{className:"flex justify-between items-center",children:(0,re.jsxs)("div",{className:"flex items-center gap-2",children:[(0,re.jsx)(qa.A,{className:"h-5 w-5 text-primary"}),(0,re.jsx)(Ua,{className:"text-xl",children:s?"Share ".concat(s.name):"Share Project"})]})}),(0,re.jsx)(za,{className:"text-sm text-muted-foreground",children:"Share your project and earn 20 free credits to keep building!"})]}),(0,re.jsxs)("div",{className:"space-y-6",children:[(0,re.jsxs)("div",{className:"bg-secondary/20 p-4 rounded-lg space-y-3 border border-border",children:[(0,re.jsx)("h3",{className:"font-medium text-sm",children:"Sharing Guidelines"}),(0,re.jsxs)("ul",{className:"space-y-2.5 text-sm text-muted-foreground",children:[(0,re.jsxs)("li",{className:"flex items-center gap-2",children:[(0,re.jsx)("div",{className:"h-1.5 w-1.5 rounded-full bg-primary/70"}),"Tag ",(0,re.jsx)("span",{className:"font-medium text-foreground",children:"@base_44"})]}),(0,re.jsxs)("li",{className:"flex items-center gap-2",children:[(0,re.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,re.jsxs)("li",{className:"flex items-center gap-2",children:[(0,re.jsx)("div",{className:"h-1.5 w-1.5 rounded-full bg-primary/70"}),"Account must have over 100 followers"]}),(0,re.jsxs)("li",{className:"flex items-center gap-2",children:[(0,re.jsx)("div",{className:"h-1.5 w-1.5 rounded-full bg-primary/70"}),"Add a screenshot or video of your project (optional)"]}),(0,re.jsxs)("li",{className:"flex items-center gap-2",children:[(0,re.jsx)("div",{className:"h-1.5 w-1.5 rounded-full bg-primary/70"}),"Add a link to your project (optional)"]}),(0,re.jsxs)("li",{className:"flex items-center gap-2",children:[(0,re.jsx)("div",{className:"h-1.5 w-1.5 rounded-full bg-primary/70"}),"Open a ticket, at ",(0,re.jsx)("button",{type:"button",onClick:()=>{const e=null!=s&&s.id?"/support?appId=".concat(s.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,re.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,re.jsxs)(Hs,{variant:"outline",className:"w-full justify-start gap-2 font-normal",onClick:()=>l("linkedin"),children:[(0,re.jsx)(Wa.A,{className:"h-4 w-4"}),"Share on LinkedIn"]}),(0,re.jsxs)(Hs,{variant:"outline",className:"w-full justify-start gap-2 font-normal",onClick:()=>l("twitter"),children:[(0,re.jsx)(Va.A,{className:"h-4 w-4"}),"Share on X (Twitter)"]})]})]})]})})};const $a=new class extends Zs{getBaseURL(){return"/app-catalog-items"}async getListingIfExists(e){const s=await this.filter({app_id:e});return s.length>0?s[0]:null}};var Ja=t(20454);let Za=0;const Ka=new Map,Xa=e=>{if(Ka.has(e))return;const s=setTimeout(()=>{Ka.delete(e),tn({type:"REMOVE_TOAST",toastId:e})},1e6);Ka.set(e,s)},Qa=(e,s)=>{switch(s.type){case"ADD_TOAST":return(0,K.A)((0,K.A)({},e),{},{toasts:[s.toast,...e.toasts].slice(0,1)});case"UPDATE_TOAST":return(0,K.A)((0,K.A)({},e),{},{toasts:e.toasts.map(e=>e.id===s.toast.id?(0,K.A)((0,K.A)({},e),s.toast):e)});case"DISMISS_TOAST":{const{toastId:t}=s;return t?Xa(t):e.toasts.forEach(e=>{Xa(e.id)}),(0,K.A)((0,K.A)({},e),{},{toasts:e.toasts.map(e=>e.id===t||void 0===t?(0,K.A)((0,K.A)({},e),{},{open:!1}):e)})}case"REMOVE_TOAST":return void 0===s.toastId?(0,K.A)((0,K.A)({},e),{},{toasts:[]}):(0,K.A)((0,K.A)({},e),{},{toasts:e.toasts.filter(e=>e.id!==s.toastId)})}},en=[];let sn={toasts:[]};function tn(e){sn=Qa(sn,e),en.forEach(e=>{e(sn)})}function an(e){let s=Object.assign({},((0,Ja.A)(e),e));const t=(Za=(Za+1)%Number.MAX_SAFE_INTEGER,Za.toString()),a=()=>tn({type:"DISMISS_TOAST",toastId:t});return tn({type:"ADD_TOAST",toast:(0,K.A)((0,K.A)({},s),{},{id:t,open:!0,onOpenChange:e=>{e||a()}})}),{id:t,dismiss:a,update:e=>tn({type:"UPDATE_TOAST",toast:(0,K.A)((0,K.A)({},e),{},{id:t})})}}function nn(){const[e,s]=H.useState(sn);return H.useEffect(()=>(en.push(s),()=>{const e=en.indexOf(s);e>-1&&en.splice(e,1)}),[e]),(0,K.A)((0,K.A)({},e),{},{toast:an,dismiss:e=>tn({type:"DISMISS_TOAST",toastId:e})})}var rn=t(38554),ln=t(90983),on=t(37524),cn=t(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:s}=e;return(0,re.jsxs)(re.Fragment,{children:[(0,re.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,re.jsx)("div",{className:"relative",children:(0,re.jsx)("div",{className:"expandable-description text-sm",dangerouslySetInnerHTML:{__html:dn(s)}})})]})},un=["className","children"],xn=e=>{let{className:s,children:t}=e,a=(0,as.A)(e,un);return(0,re.jsxs)(ka.Portal,{children:[(0,re.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,re.jsx)(ka.Content,(0,K.A)((0,K.A)({className:is("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]",s)},a),{},{children:t}))]})};const hn=function(e){var s,t,a,n,r,l;let{isOpen:i,onClose:o,selectedItem:c,onItemUpdate:d}=e;const{user:m}=oe(),[u,x]=(0,H.useState)(0),[h,p]=(0,H.useState)(!1);return(0,H.useEffect)(()=>{i&&c&&x(0)},[i,c]),(0,re.jsx)(Pa,{open:i,onOpenChange:o,className:!0,children:(0,re.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,re.jsxs)("div",{className:"h-full flex flex-col",children:[(0,re.jsx)("div",{className:"flex-shrink-0 flex items-center justify-end rounded-t-[16px] px-3 pt-3",children:(0,re.jsx)(Hs,{variant:"ghost",size:"icon",onClick:o,className:"h-8 w-8",children:(0,re.jsx)(zs.A,{className:"h-6 w-6"})})}),(0,re.jsx)("div",{className:"flex-1 p-[18px] md:p-[18px] p-4 overflow-y-auto md:overflow-y-auto overflow-visible",children:(0,re.jsxs)("div",{className:"flex flex-col md:flex-row md:h-full",children:[(0,re.jsxs)("div",{className:"w-full md:w-[65%] flex flex-col mb-6 md:mb-0",children:[(null===(s=c.item.screenshot_urls)||void 0===s?void 0:s.length)>0?(0,re.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,re.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,re.jsx)("div",{className:"absolute inset-0 flex items-center justify-center",children:(0,re.jsx)("img",{src:c.item.screenshot_urls[u],alt:"Screenshot ".concat(u+1),className:"w-full h-full object-contain"})})]}):(0,re.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,re.jsx)(rn.A,{className:"w-16 h-16 text-slate-300"})}),(null===(t=c.item.screenshot_urls)||void 0===t?void 0:t.length)>1&&(0,re.jsxs)("div",{className:"flex items-center gap-4 mt-6 justify-center flex-shrink-0",children:[(0,re.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,re.jsx)(Qt.A,{className:"w-5 h-5 text-slate-600"})}),(0,re.jsx)("div",{className:"flex gap-3",children:c.item.screenshot_urls.map((e,s)=>(0,re.jsx)("button",{onClick:()=>x(s),className:is("w-3 h-3 rounded-full transition-all",u===s?"bg-slate-900":"bg-slate-200 hover:bg-slate-300"),"aria-label":"Go to screenshot ".concat(s+1)},s))}),(0,re.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,re.jsx)(on.A,{className:"w-4 h-4 ml-1"})]})}),(0,re.jsx)("div",{className:"flex gap-3",children:"platform_admin"===(null==m?void 0:m.platform_role)&&("approved"===c.item.status?(0,re.jsx)(Hs,{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,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(Ze.A,{className:"w-4 h-4 mr-2 animate-spin"}),"Declining..."]}):"Decline Listing"}):(0,re.jsx)(Hs,{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,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(Ze.A,{className:"w-4 h-4 mr-2 animate-spin"}),"Approving..."]}):"Approve Listing"}))}),(0,re.jsxs)("div",{className:"flex gap-3",children:[(0,re.jsx)(Hs,{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,re.jsxs)(Hs,{variant:"outline",onClick:async()=>{const e=await ve.getLoginInfoById(c.item.app_id),s="https://".concat(e.slug,".base44.app");window.open(s,"_blank")},className:"h-10 w-[128px] rounded-[12px]",children:["View App ",(0,re.jsx)(on.A,{className:"w-4 h-4 ml-1"})]})]}),(0,re.jsx)("div",{className:"mt-[36px]",children:(0,re.jsx)("div",{className:"flex flex-wrap gap-2",children:c.item.categories&&c.item.categories.length>0?c.item.categories.map((e,s)=>(0,re.jsx)(et,{variant:"outline",className:"px-3 py-1 text-[14px] font-normal bg-slate-100 border border-slate-200 text-slate-700 ",children:e},s)):(0,re.jsx)(et,{variant:"secondary",className:"px-3 py-1 text-sm font-normal bg-slate-50 text-slate-700 border-slate-200",children:"No categories"})})})]}),(0,re.jsx)("div",{className:"space-y-8 mt-[18px]",children:(0,re.jsx)("div",{children:(0,re.jsx)(mn,{content:c.item.description||"

No description available

"})})})]})]})})]})})})};function pn(){return(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)("h1",{className:"text-5xl font-base44 font-medium mb-4 mt-6",children:"Explore templates from the community"}),(0,re.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=H.forwardRef((e,s)=>{let{className:t,type:a}=e,n=(0,as.A)(e,gn);return(0,re.jsx)("input",(0,K.A)({type:a,className:is("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",t),ref:s},n))});fn.displayName="Input";var vn=t(13147),bn=t(29126);const jn=["className","variant"],yn=(0,ns.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:s,variant:t}=e,a=(0,as.A)(e,jn);return(0,re.jsx)("div",(0,K.A)({className:is(yn({variant:t}),s)},a))}const wn=["className","children","advancedDropdown"],_n=["className"],kn=["className"],An=["className","children","position"],Sn=["className"],Cn=["className","children","hideCheckIcon"],En=["className"],In=Et.bL,Tn=(Et.YJ,Et.WT),Pn=H.forwardRef((e,s)=>{let{className:t,children:a,advancedDropdown:n=!1}=e,r=(0,as.A)(e,wn);return(0,re.jsxs)(Et.l9,(0,K.A)((0,K.A)({ref:s,className:is("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"),t)},r),{},{children:[n?(0,re.jsx)("div",{className:"flex-1 min-w-0",children:a}):a,(0,re.jsx)(Et.In,{asChild:!0,children:(0,re.jsx)(It.A,{className:is("h-4 w-4 opacity-50",n?"flex-shrink-0 ml-2":"")})})]}))});Pn.displayName=Et.l9.displayName;const Ln=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,_n);return(0,re.jsx)(Et.PP,(0,K.A)((0,K.A)({ref:s,className:is("flex cursor-default items-center justify-center py-1",t)},a),{},{children:(0,re.jsx)(Tt.A,{className:"h-4 w-4"})}))});Ln.displayName=Et.PP.displayName;const On=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,kn);return(0,re.jsx)(Et.wn,(0,K.A)((0,K.A)({ref:s,className:is("flex cursor-default items-center justify-center py-1",t)},a),{},{children:(0,re.jsx)(It.A,{className:"h-4 w-4"})}))});On.displayName=Et.wn.displayName;const Rn=H.forwardRef((e,s)=>{let{className:t,children:a,position:n="popper"}=e,r=(0,as.A)(e,An);return(0,re.jsx)(Et.ZL,{children:(0,re.jsxs)(Et.UC,(0,K.A)((0,K.A)({ref:s,className:is("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",t),position:n},r),{},{children:[(0,re.jsx)(Ln,{}),(0,re.jsx)(Et.LM,{className:is("p-1","popper"===n&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:a}),(0,re.jsx)(On,{})]}))})});Rn.displayName=Et.UC.displayName;H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,Sn);return(0,re.jsx)(Et.JU,(0,K.A)({ref:s,className:is("py-1.5 pl-8 pr-2 text-sm font-semibold",t)},a))}).displayName=Et.JU.displayName;const Dn=H.forwardRef((e,s)=>{let{className:t,children:a,hideCheckIcon:n=!1}=e,r=(0,as.A)(e,Cn);return(0,re.jsxs)(Et.q7,(0,K.A)((0,K.A)({ref:s,className:is("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",t)},r),{},{children:[!n&&(0,re.jsx)("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:(0,re.jsx)(Et.VF,{children:(0,re.jsx)(Pt.A,{className:"h-4 w-4"})})}),(0,re.jsx)(Et.p4,{children:a})]}))});Dn.displayName=Et.q7.displayName;H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,En);return(0,re.jsx)(Et.wv,(0,K.A)({ref:s,className:is("-mx-1 my-1 h-px bg-muted",t)},a))}).displayName=Et.wv.displayName;const Mn=["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"}],Un="everyone",zn="popular";function qn(e){let{searchTerm:s,onSearchChange:t,selectedCategory:a,onCategoryChange:n,ownership:r,onOwnershipChange:l,sortBy:i,onSortByChange:o,selectedLanguage:c,onLanguageChange:d}=e;return(0,re.jsxs)("div",{className:"mt-[42px] mb-6",children:[(0,re.jsxs)("div",{className:"flex flex-col sm:flex-row sm:items-center gap-3 w-full sm:justify-between",children:[(0,re.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,re.jsx)(vn.A,{className:"w-4 h-4 text-[#000] flex-shrink-0"}),(0,re.jsx)(fn,{placeholder:"Search apps...",value:s,onChange:e=>t(e.target.value),className:"border-0 bg-transparent focus-visible:ring-0 focus-visible:ring-offset-0 placeholder:text-[#B4B4B4] text-black"})]}),(0,re.jsxs)("div",{className:"flex items-center gap-3 justify-start sm:justify-end",children:[(0,re.jsxs)(In,{value:r,onValueChange:l,children:[(0,re.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,re.jsx)(Tn,{placeholder:"Ownership"})}),(0,re.jsx)(Rn,{children:Fn.map(e=>(0,re.jsx)(Dn,{value:e.value,className:"font-base44",children:e.label},e.value))})]}),(0,re.jsxs)(In,{value:c,onValueChange:d,children:[(0,re.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,re.jsxs)("div",{className:"flex items-center gap-2",children:[(0,re.jsx)(bn.A,{className:"w-4 h-4 text-black"}),(0,re.jsx)(Tn,{placeholder:"Language"})]})}),(0,re.jsx)(Rn,{children:Bn.map(e=>(0,re.jsx)(Dn,{value:e.value,className:"font-base44",children:e.label},e.value))})]})]})]}),(0,re.jsx)("div",{className:"w-full overflow-x-auto pb-2 mt-[18px]",children:(0,re.jsxs)("div",{className:"flex items-center space-x-2 min-w-max",children:[(0,re.jsx)(Nn,{variant:"all"===a?"default":"outline",className:is("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,re.jsx)("div",{className:"h-4 w-px bg-slate-200"}),Mn.map(e=>(0,re.jsx)(Nn,{variant:a===e?"default":"outline",className:is("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 Wn=["className","variant","size","asChild"],Vn=(0,ns.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"}}),Yn=H.forwardRef((e,s)=>{let{className:t,variant:a,size:n,asChild:r=!1}=e,l=(0,as.A)(e,Wn);const i=r?Ws.DX:"button";return(0,re.jsx)(i,(0,K.A)({className:is(Vn({variant:a,size:n,className:t})),ref:s},l))});Yn.displayName="Button";const Hn=["className"],Gn=["className"],$n=["className"],Jn=["className"],Zn=["className"],Kn=["className"],Xn=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,Hn);return(0,re.jsx)("div",(0,K.A)({ref:s,className:is("rounded-lg border bg-card text-card-foreground shadow-sm",t)},a))});Xn.displayName="Card";const Qn=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,Gn);return(0,re.jsx)("div",(0,K.A)({ref:s,className:is("flex flex-col space-y-1.5 px-6 py-4",t)},a))});Qn.displayName="CardHeader";const er=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,$n);return(0,re.jsx)("h3",(0,K.A)({ref:s,className:is("font-medium leading-none tracking-tight",t)},a))});er.displayName="CardTitle";const sr=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,Jn);return(0,re.jsx)("p",(0,K.A)({ref:s,className:is("text-sm text-muted-foreground",t)},a))});sr.displayName="CardDescription";const tr=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,Zn);return(0,re.jsx)("div",(0,K.A)({ref:s,className:is("px-6 py-3",t)},a))});tr.displayName="CardContent";const ar=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,Kn);return(0,re.jsx)("div",(0,K.A)({ref:s,className:is("flex items-center px-6 pt-0 pb-3",t)},a))});ar.displayName="CardFooter";const nr=["className"],rr=["className"],lr=["className"],ir=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,nr);return(0,re.jsx)(ia.bL,(0,K.A)({ref:s,className:is("relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",t)},a))});ir.displayName=ia.bL.displayName;const or=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,rr);return(0,re.jsx)(ia._V,(0,K.A)({ref:s,className:is("aspect-square h-full w-full",t)},a))});or.displayName=ia._V.displayName;const cr=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,lr);return(0,re.jsx)(ia.H4,(0,K.A)({ref:s,className:is("flex h-full w-full items-center justify-center rounded-full bg-muted",t)},a))});cr.displayName=ia.H4.displayName;var dr=t(79992);function mr(e){var s,t,a;let{catalogItem:n,onCardClick:r,stripHtml:l,isHomepage:i=!1}=e;const o=n.item,c=null===(s=o.screenshot_urls)||void 0===s?void 0:s[0],d=n.item_creator,m=null===(t=n.categories)||void 0===t?void 0:t[0];return(0,re.jsxs)(Xn,{className:is("border-0 cursor-pointer shadow-none group rounded-[16px] overflow-hidden",i?"bg-white":"bg-[#f4f3f2]"),onClick:()=>r(n),children:[(0,re.jsxs)("div",{className:"relative aspect-video overflow-hidden",children:[c?(0,re.jsx)("img",{src:c,alt:o.name,className:"w-full h-full object-cover rounded-[8px] border border-gray-200",onError:e=>{e.currentTarget.style.display="none";const s=e.currentTarget.nextElementSibling;s&&(s.style.display="flex")}}):null,(0,re.jsx)("div",{className:is("absolute inset-0 flex items-center justify-center",c?"hidden":"flex"),children:(0,re.jsx)(rn.A,{className:"w-12 h-12 text-slate-400"})}),(0,re.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,re.jsx)(Yn,{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,re.jsx)(Yn,{onClick:e=>{e.stopPropagation(),null==r||r(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,re.jsx)("div",{className:"absolute top-3 right-3",children:m&&(0,re.jsx)(Nn,{className:"bg-orange-500/90 backdrop-blur-sm border-orange-600 text-white font-medium",children:m})})]}),(0,re.jsxs)(tr,{className:"py-2 px-0 space-y-2",children:[(0,re.jsx)("div",{children:(0,re.jsxs)("div",{className:"flex items-center gap-2",children:[(0,re.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,re.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,re.jsx)(dr.A,{}),(0,re.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,re.jsx)("div",{className:"flex items-center justify-between mt-1",children:(0,re.jsxs)("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[(0,re.jsxs)(ir,{className:"h-6 w-6 flex-shrink-0 border border-gray-200",children:[(0,re.jsx)(or,{src:null==d?void 0:d.profile_image_url,alt:(null==d?void 0:d.full_name)||"User"}),(0,re.jsx)(cr,{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,re.jsxs)("div",{className:"min-w-0 flex-1 flex items-center gap-2",children:[(0,re.jsx)("p",{className:"text-sm text-slate-600 truncate",children:(null==d?void 0:d.full_name)||"Unknown User"}),(0,re.jsx)("div",{className:"w-1 h-1 rounded-full bg-slate-300"}),(0,re.jsxs)("div",{className:"group/tooltip relative",children:[(0,re.jsxs)("p",{className:"text-sm text-slate-600 flex items-center gap-1",children:[(0,re.jsx)("svg",{width:"24",height:"24",viewBox:"0 0 18 18",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:(0,re.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,re.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 ur(){return(0,re.jsxs)("div",{className:"group relative bg-white rounded-2xl border border-slate-100 overflow-hidden",children:[(0,re.jsx)("div",{className:"aspect-[16/9] bg-slate-100 animate-pulse"}),(0,re.jsxs)("div",{className:"p-5 space-y-4",children:[(0,re.jsx)("div",{className:"h-6 bg-slate-100 rounded-md animate-pulse w-3/4"}),(0,re.jsx)("div",{className:"flex items-center justify-between pt-2",children:(0,re.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,re.jsx)("div",{className:"w-8 h-8 bg-slate-100 rounded-full animate-pulse"}),(0,re.jsx)("div",{className:"h-4 w-24 bg-slate-100 rounded-md animate-pulse"})]})})]})]})}function xr(){return(0,re.jsxs)("div",{className:"space-y-8",children:[(0,re.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,s)=>(0,re.jsx)(ur,{},s))}),(0,re.jsx)("div",{className:"flex items-center justify-center mt-8",children:(0,re.jsxs)("div",{className:"flex items-center gap-2",children:[(0,re.jsx)("div",{className:"w-8 h-8 bg-slate-100 rounded-md animate-pulse"}),(0,re.jsx)("div",{className:"w-8 h-8 bg-slate-100 rounded-md animate-pulse"}),(0,re.jsx)("div",{className:"w-8 h-8 bg-slate-100 rounded-md animate-pulse"})]})})]})}var hr=t(12550);function pr(){return(0,re.jsxs)("div",{className:"text-center py-24",children:[(0,re.jsx)("div",{className:"inline-flex items-center justify-center w-16 h-16 rounded-2xl bg-slate-100 mb-4",children:(0,re.jsx)(hr.A,{className:"w-8 h-8 text-slate-400"})}),(0,re.jsx)("p",{className:"text-lg text-slate-600",children:"No apps found"}),(0,re.jsx)("p",{className:"text-sm text-slate-500 mt-1",children:"Try adjusting your search or filters"})]})}function gr(e){let{isLoading:s,isLoadingMore:t=!1,items:a,onCardClick:n,stripHtml:r,hasMore:l=!1,targetRef:i,showViewAllButton:o=!1}=e;return(0,re.jsx)("div",{className:"",children:s?(0,re.jsx)(xr,{}):0===a.length?(0,re.jsx)(pr,{}):(0,re.jsxs)("div",{className:"space-y-8",children:[(0,re.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,re.jsx)(mr,{catalogItem:e,onCardClick:n,stripHtml:r,isHomepage:o},e.item.id))}),(0,re.jsx)("div",{ref:o?void 0:i,className:"w-full py-4",children:o?(0,re.jsx)("div",{className:"flex justify-center py-8",children:(0,re.jsx)(Yn,{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,re.jsxs)(re.Fragment,{children:[t&&(0,re.jsxs)("div",{className:"flex justify-center items-center py-8",children:[(0,re.jsx)("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-slate-600"}),(0,re.jsx)("span",{className:"ml-2 text-slate-600",children:"Loading more items..."})]}),!l&&a.length>0&&(0,re.jsx)("div",{className:"text-center py-8 text-slate-500",children:"No more apps to load"})]})})]})})}function fr(e){if(!e)return"";const s=document.createElement("div");return s.innerHTML=e,s.textContent||s.innerText||""}const vr=function(){const{user:e}=oe(),[s,t]=(0,H.useState)([]),[a,n]=(0,H.useState)(!0),[r,l]=(0,H.useState)(""),[i,o]=(0,H.useState)("all"),[c,d]=(0,H.useState)(Un),[m,u]=(0,H.useState)(zn),[x,h]=(0,H.useState)("en"),[p,g]=(0,H.useState)(!1),[f,v]=(0,H.useState)(!0),[b,j]=(0,H.useState)(!1),[y,N]=(0,H.useState)(0),[w]=(0,H.useState)(20),[_,k]=(0,H.useState)(0),[A,S]=(0,H.useState)(null),[C,E]=(0,H.useState)(!1);(0,H.useEffect)(()=>{const e=new URLSearchParams(window.location.search).get("category");if(e){const s=Mn.find(s=>s.toLowerCase()===e.toLowerCase());s?o(s):"my-apps"===e.toLowerCase()&&o("my-apps")}},[]),(0,H.useEffect)(()=>{t([]),k(0),v(!0),I(!0)},[r,i,c,m,x]);const I=(0,H.useCallback)(async function(){let s=arguments.length>0&&void 0!==arguments[0]&&arguments[0];try{s?n(!0):j(!0);const a=s?0:_;let l={skip:a,limit:w,sort_by:T(m),categories:"all"!==i&&"my-apps"!==i?[i]:void 0};"me"===c||"my-apps"===i?l.created_by=e.email:"not_me"===c&&(l.created_by={$ne:e.email}),r&&"en"===x?l.$and=[{$or:[{name:{$regex:r,$options:"i"}},{description:{$regex:r,$options:"i"}},{categories:{$regex:r,$options:"i"}},{tags:{$regex:r,$options:"i"}},{created_by:{$regex:r,$options:"i"}}]},{$or:[{language:"en"},{language:{$exists:!1}},{language:null}]}]:r?(l.$or=[{name:{$regex:r,$options:"i"}},{description:{$regex:r,$options:"i"}},{categories:{$regex:r,$options:"i"}},{tags:{$regex:r,$options:"i"}},{created_by:{$regex:r,$options:"i"}}],x&&"en"!==x&&(l.language=x)):x&&("en"===x?l.$or=[{language:"en"},{language:{$exists:!1}},{language:null}]:l.language=x),Object.keys(l).forEach(e=>{void 0===l[e]&&delete l[e]});const o=await $a.listCatalogItems(l),d=o.items||o,u=o.total||d.length;s?(t(d),N(u)):t(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,r,c,m,x,e]),T=e=>{switch(e){case"newest":return"created_at_desc";case"oldest":return"created_at_asc";default:return"usage"}},P=s.length,L=y>0?"Showing ".concat(P," of ").concat(y," items"):"";return(0,re.jsxs)("div",{className:"px-12 max-w-[1600px] mx-auto",children:[(0,re.jsx)(pn,{}),(0,re.jsx)(qn,{searchTerm:r,onSearchChange:e=>{l(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,re.jsx)(gr,{isLoading:a,isLoadingMore:b,items:s,onCardClick:e=>{S(e),E(!0)},stripHtml:fr,hasMore:f,targetRef:null,showViewAllButton:!0}),(0,re.jsx)(hn,{isOpen:C,onClose:()=>{E(!1),S(null)},selectedItem:A,onItemUpdate:e=>{S(e)}})]})};const br=function(){const[e,s]=(0,H.useState)(!1),[t,a]=(0,H.useState)("my-apps"),[n,r]=(0,H.useState)(!1),[l,i]=(0,H.useState)(!0),o=(0,Z.Zp)(),c=(0,Z.zy)(),{user:d}=oe();return(0,re.jsxs)("div",{className:"min-h-screen",children:[(0,re.jsxs)("main",{className:"relative z-10 sm:max-w-screen-2xl mx-auto sm:px-6 lg:px-8 pb-12",children:[(0,re.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,re.jsxs)("div",{className:"max-w-md sm:max-w-4xl mx-auto text-center mb-[32px] md:mb-[32px]",children:[(0,re.jsx)("h1",{className:"text-[26px] sm:text-[48px] font-base44 font-medium text-slate-800 mb-2 ",children:"What would you build today?"}),(0,re.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,re.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,re.jsx)("div",{className:"sm:max-w-4xl mx-auto",children:(0,re.jsx)(na,{onStart:async e=>{let{text:t,files:a,deep_coding_mode:n,integrations:r,secrets:l}=e;if(t.trim()){s(!0);try{const e=new URLSearchParams(c.search).get("app_platform_version"),s={deep_coding_mode:!!n,status:{state:"processing",details:"Starting conversation..."},integrations:r,secrets:l};e&&(s.platform_version=parseInt(e,10));const i=await ve.create(s);He(i.id,{content:t,file_urls:a},null==d?void 0:d.id),o("/apps/".concat(i.id,"/editor/preview"))}catch(i){alert("Failed to create app. Please try again.")}finally{s(!1)}}else alert("Please enter an app description")},loading:e})})]}),(0,re.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,re.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,re.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"===t&&(0,re.jsx)(ja,{}),"trending"===t&&(0,re.jsx)(_a,{})]}),(0,re.jsx)(Ga,{isOpen:n,onClose:()=>r(!1)})]}),(0,re.jsxs)("section",{id:"app-catalog-section",className:"relative bg-white md:py-16",children:[(0,re.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,re.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,re.jsx)("div",{className:"relative z-10 bg-white pt-8",children:(0,re.jsx)(vr,{})})]})]})};var jr=t(2263),yr=t(82407),Nr=t(24990),wr=t(46327),_r=t(39193),kr=t(9072);const Ar=["className"],Sr=["className"],Cr=["className"],Er=["className"],Ir=["className"],Tr=["className"],Pr=["className"],Lr=["className"],Or=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,Ar);return(0,re.jsx)("div",{className:"relative w-full overflow-auto",children:(0,re.jsx)("table",(0,K.A)({ref:s,className:is("w-full caption-bottom text-sm",t)},a))})});Or.displayName="Table";const Rr=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,Sr);return(0,re.jsx)("thead",(0,K.A)({ref:s,className:is("[&_tr]:border-b",t)},a))});Rr.displayName="TableHeader";const Dr=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,Cr);return(0,re.jsx)("tbody",(0,K.A)({ref:s,className:is("[&_tr:last-child]:border-0",t)},a))});Dr.displayName="TableBody";const Mr=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,Er);return(0,re.jsx)("tfoot",(0,K.A)({ref:s,className:is("border-t bg-muted/50 font-medium [&>tr]:last:border-b-0",t)},a))});Mr.displayName="TableFooter";const Fr=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,Ir);return(0,re.jsx)("tr",(0,K.A)({ref:s,className:is("border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",t)},a))});Fr.displayName="TableRow";const Br=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,Tr);return(0,re.jsx)("th",(0,K.A)({ref:s,className:is("h-12 px-4 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0",t)},a))});Br.displayName="TableHead";const Ur=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,Pr);return(0,re.jsx)("td",(0,K.A)({ref:s,className:is("p-4 align-middle [&:has([role=checkbox])]:pr-0",t)},a))});Ur.displayName="TableCell";const zr=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,Lr);return(0,re.jsx)("caption",(0,K.A)({ref:s,className:is("mt-4 text-sm text-muted-foreground",t)},a))});zr.displayName="TableCaption";const qr=function(){const{user:e}=oe(),[s,t]=(0,H.useState)([]),[a,n]=(0,H.useState)(!0),[r,l]=(0,H.useState)(""),[i,o]=(0,H.useState)("desc"),[c,d]=(0,H.useState)(!1),[m,u]=(0,H.useState)(!1),[x,h]=(0,H.useState)(1),[p,g]=(0,H.useState)(!0),[f,v]=(0,H.useState)("grid"),b="grid"===f?24:100,{activeWorkspaceId:j}=((0,Z.Zp)(),ge());(0,H.useEffect)(()=>{y()},[x,i,c,r,f,j]);const y=async()=>{try{const s="desc"===i?"-":"";let a={};c&&(a.created_by=e.email),r&&(a.$or=[{name:{$regex:r,$options:"i"}},{user_description:{$regex:r,$options:"i"}},{created_by:{$regex:r,$options:"i"}}]);const l=await ve.filter(a,"".concat(s,"updated_date"),b,(x-1)*b,["id","name","logo_url","user_description","created_by","created_date","updated_date","is_starred"].join(","));t(e=>1===x?l:[...e,...l]),g(l.length===b),n(!1)}catch(s){n(!1)}},N=s.filter(e=>!m||e.is_starred);return a&&1===x?(0,re.jsx)("div",{className:"flex justify-center items-center h-full",children:(0,re.jsx)("div",{className:"animate-spin h-8 w-8 border-4 border-primary border-t-transparent rounded-full"})}):(0,re.jsx)("div",{className:"p-6 min-h-full",children:(0,re.jsxs)("div",{className:"max-w-7xl mx-auto",children:[(0,re.jsxs)("div",{className:"flex flex-col md:flex-row justify-between items-start md:items-center gap-4 mb-8",children:[(0,re.jsx)("h2",{className:"text-3xl font-bold",children:"Apps"}),(0,re.jsxs)("div",{className:"flex flex-col sm:flex-row gap-4 w-full md:w-auto",children:[(0,re.jsxs)("div",{className:"relative",children:[(0,re.jsx)(vn.A,{className:"absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground h-4 w-4"}),(0,re.jsx)(ft,{type:"text",placeholder:"Search apps...",className:"pl-10 w-full sm:w-80",value:r,onChange:e=>{l(e.target.value),h(1),t([])}})]}),(0,re.jsxs)("div",{className:"flex gap-2",children:[(0,re.jsx)(Hs,{variant:c?"default":"outline",onClick:()=>{d(!c),h(1),t([])},children:c?"My Apps":"All Apps"}),(0,re.jsx)(Hs,{variant:m?"default":"outline",onClick:()=>u(!m),children:(0,re.jsx)(jr.A,{className:"h-4 w-4 ".concat(m?"fill-current":"")})}),(0,re.jsx)(Hs,{variant:"outline",onClick:()=>{o("desc"===i?"asc":"desc"),h(1),t([])},children:"desc"===i?(0,re.jsx)(yr.A,{className:"h-4 w-4"}):(0,re.jsx)(Nr.A,{className:"h-4 w-4"})}),(0,re.jsx)(Hs,{variant:"outline",onClick:()=>{v(e=>"grid"===e?"table":"grid"),h(1),t([])},children:"grid"===f?(0,re.jsx)(wr.A,{className:"h-4 w-4"}):(0,re.jsx)(hr.A,{className:"h-4 w-4"})})]})]})]}),"grid"===f?(0,re.jsx)("div",{className:"grid gap-4 sm:grid-cols-2 lg:grid-cols-3",children:N.map(e=>(0,re.jsx)(J.Link,{to:"/apps/".concat(e.id,"/editor/preview"),className:"block hover:shadow-lg transition-all duration-300",children:(0,re.jsxs)(it,{children:[(0,re.jsx)(ot,{children:(0,re.jsxs)("div",{className:"flex items-center gap-4",children:[(0,re.jsx)(ma,{className:"h-12 w-12 rounded-xl",children:e.logo_url?(0,re.jsx)(ua,{src:e.logo_url,alt:"".concat(e.name," logo")}):(0,re.jsx)(xa,{className:"bg-primary/10",children:(0,re.jsx)(_r.A,{className:"h-6 w-6 text-primary"})})}),(0,re.jsx)("h3",{className:"font-semibold text-lg line-clamp-2",children:e.name})]})}),(0,re.jsxs)(mt,{children:[(0,re.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,re.jsx)(kr.A,{className:"inline ml-1 h-4 w-4"})]}),(0,re.jsxs)("div",{className:"text-xs text-muted-foreground flex flex-wrap gap-2",children:[(0,re.jsxs)("span",{children:["By ",e.created_by]}),(0,re.jsx)(pt,{orientation:"vertical",className:"h-4"}),(0,re.jsxs)("span",{children:["Created ",la().utc(e.created_date).fromNow()]})]})]})]})},e.id))}):(0,re.jsx)(it,{children:(0,re.jsx)(mt,{className:"p-0",children:(0,re.jsxs)(Or,{children:[(0,re.jsx)(Rr,{children:(0,re.jsxs)(Fr,{children:[(0,re.jsx)(Br,{className:"w-16"})," ",(0,re.jsx)(Br,{children:"Name"}),(0,re.jsx)(Br,{children:"Description"}),(0,re.jsx)(Br,{children:"Created By"}),(0,re.jsx)(Br,{children:"Last Updated"}),(0,re.jsx)(Br,{className:"text-right",children:"Actions"})]})}),(0,re.jsx)(Dr,{children:N.map(e=>(0,re.jsxs)(Fr,{children:[(0,re.jsx)(Ur,{className:"p-2",children:(0,re.jsx)(ma,{className:"h-10 w-10 rounded-md",children:e.logo_url?(0,re.jsx)(ua,{src:e.logo_url,alt:"".concat(e.name," logo")}):(0,re.jsx)(xa,{className:"bg-primary/10 rounded-md",children:(0,re.jsx)(_r.A,{className:"h-5 w-5 text-primary"})})})}),(0,re.jsx)(Ur,{className:"font-medium py-2 pr-2",children:(0,re.jsx)(J.Link,{to:"/apps/".concat(e.id,"/editor/preview"),className:"hover:underline line-clamp-2",children:e.name})}),(0,re.jsx)(Ur,{className:"text-muted-foreground py-2 pr-2 line-clamp-2",children:e.user_description||"-"}),(0,re.jsx)(Ur,{className:"text-muted-foreground py-2 pr-2 whitespace-nowrap",children:e.created_by}),(0,re.jsx)(Ur,{className:"text-muted-foreground py-2 pr-2 whitespace-nowrap",children:la().utc(e.updated_date).fromNow()}),(0,re.jsx)(Ur,{className:"py-2 pl-2 text-right",children:(0,re.jsx)(Hs,{variant:"ghost",size:"icon",onClick:s=>{s.stopPropagation(),alert("Actions for ".concat(e.name))},children:(0,re.jsx)(kr.A,{className:"h-4 w-4"})})})]},e.id))})]})})}),0===N.length&&!a&&(0,re.jsx)("div",{className:"text-center py-12 text-muted-foreground",children:"No apps found matching your criteria"}),N.length>0&&(0,re.jsxs)("div",{className:"flex justify-center gap-2 mt-8",children:[(0,re.jsx)(Hs,{variant:"outline",onClick:()=>h(e=>Math.max(1,e-1)),disabled:1===x,children:"Previous"}),(0,re.jsx)(Hs,{variant:"outline",onClick:()=>h(e=>e+1),disabled:!p,children:"Next"})]}),a&&x>1&&(0,re.jsx)("div",{className:"flex justify-center items-center py-4",children:(0,re.jsx)("div",{className:"animate-spin h-8 w-8 border-4 border-primary border-t-transparent rounded-full"})})]})})};var Wr=t(32443),Vr=t(86805),Yr=t(74878),Hr=t(40978),Gr=t(29975),$r=t(78419),Jr=t(65330);function Zr(e){let{children:s}=e;const{app:t,isLoading:a}=_s(),[n,r]=(0,H.useState)(null),[l,i]=(0,H.useState)([]),[o,c]=(0,H.useState)(!0),[d,m]=(0,H.useState)(!0),[u,x]=(0,H.useState)(null),h=(0,H.useMemo)(()=>(null==t?void 0:t.organization_id)||null,[null==t?void 0:t.organization_id]),p=(0,H.useMemo)(()=>{if(!h||!l.length)return null;return l.find(e=>e.id===h)||null},[h,l]);(0,H.useEffect)(()=>((0,ae.r8)(()=>h),()=>{(0,ae.r8)(()=>null)}),[h]),(0,H.useEffect)(()=>{r(p)},[p]);const g=(0,H.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,H.useEffect)(()=>{g()},[g]),(0,H.useEffect)(()=>{c(a||d)},[a,d]);const f=(0,H.useCallback)(e=>{},[]),v=(0,H.useCallback)(()=>{},[]),b={activeWorkspace:n,activeWorkspaceId:h,workspaces:l,isLoading:o,isLoadingWorkspaces:d,error:u,switchActiveWorkspace:f,clearActiveWorkspace:v,refetchWorkspaces:g};return(0,re.jsx)(he.Provider,{value:b,children:s})}var Kr=t(81830),Xr=t(35887),Qr=t(52180),el=t(89796),sl=t(72128),tl=t(10743),al=t(67637),nl=t(70446);function rl(e,s){const t=[];let a=0;const n="<".concat(s," "),r="");for(;-1!==e.indexOf(n,a);){const s=e.indexOf(n,a);let l=e.indexOf(">",s)+1;0===l&&(l=e.length);const i=e.slice(s,l),o=e.indexOf(r,l);if(-1===o){t.push({openingTagIndex:s,closingTagIndex:null,openingTag:i,content:e.slice(l)});break}t.push({openingTagIndex:s,closingTagIndex:o,openingTag:i,content:e.slice(l,o)}),a=o+r.length}return t}function ll(e,s){const t=e.match(new RegExp("".concat(s,'="([^"]*)"'),"i"));return t?t[1]:void 0}class il extends X.H{getBaseURL(){return"/apps"}getCheckpointFileTree(e,s){return this.axios.get("/".concat(e,"/app-checkpoints/").concat(s,"/file-tree"))}listCheckpoints(e){return this.axios.get("/".concat(e,"/app-checkpoints"))}loadCheckpoint(e,s){return this.axios.post("/".concat(e,"/app-checkpoints/").concat(s,"/load"))}}const ol=new il;var cl=t(35023),dl=t(37970);const ml=["className"],ul=["className"],xl=["className"],hl=dl.bL,pl=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,ml);return(0,re.jsx)(dl.B8,(0,K.A)({ref:s,className:is("inline-flex h-10 items-center justify-center rounded-md bg-muted p-1 text-muted-foreground",t)},a))});pl.displayName=dl.B8.displayName;const gl=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,ul);return(0,re.jsx)(dl.l9,(0,K.A)({ref:s,className:is("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",t)},a))});gl.displayName=dl.l9.displayName;const fl=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,xl);return(0,re.jsx)(dl.UC,(0,K.A)({ref:s,className:is("mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",t)},a))});fl.displayName=dl.UC.displayName;const vl=e=>{let{originalCode:s="",modifiedCode:t="",language:a="javascript",title:n="Code Comparison",diffViewStyle:r="default"}=e;const l={readOnly:!0,renderSideBySide:!0,wordWrap:"on",scrollBeyondLastLine:!1,minimap:{enabled:!1},lineNumbers:"on",diffWordWrap:"on"},i="github"===r?"light":"vs";return(0,re.jsxs)(it,{className:"w-full shadow-md",children:[(0,re.jsx)(ot,{className:"pb-2",children:(0,re.jsx)(ct,{className:"text-lg font-medium",children:n})}),(0,re.jsx)(mt,{children:(0,re.jsxs)(hl,{defaultValue:"diff",className:"w-full",children:[(0,re.jsxs)(pl,{className:"mb-2",children:[(0,re.jsx)(gl,{value:"diff",children:"Diff View"}),(0,re.jsx)(gl,{value:"original",children:"Original"}),(0,re.jsx)(gl,{value:"modified",children:"Modified"})]}),(0,re.jsx)(fl,{value:"diff",className:"w-full",children:(0,re.jsx)("div",{className:"h-[500px] border rounded-md overflow-hidden",children:(0,re.jsx)(cl.zC,{height:"100%",language:a,original:s,modified:t,options:l,theme:i})})}),(0,re.jsx)(fl,{value:"original",children:(0,re.jsx)("div",{className:"h-[500px] border rounded-md overflow-hidden",children:(0,re.jsx)(cl.zC,{height:"100%",language:a,original:s,modified:s,options:(0,K.A)((0,K.A)({},l),{},{renderSideBySide:!1}),theme:i})})}),(0,re.jsx)(fl,{value:"modified",children:(0,re.jsx)("div",{className:"h-[500px] border rounded-md overflow-hidden",children:(0,re.jsx)(cl.zC,{height:"100%",language:a,original:t,modified:t,options:(0,K.A)((0,K.A)({},l),{},{renderSideBySide:!1}),theme:i})})})]})})]})};var bl=t(61878),jl=t(31641);function yl(e){let{msgId:s,isOpen:t,onClose:a}=e;const{user:n}=oe(),{app:r}=_s(),[l,i]=(0,H.useState)(null),[o,c]=(0,H.useState)(!0),[d,m]=(0,H.useState)("diff"),[u,x]=(0,H.useState)(!1),h=r.conversation.messages.findIndex(e=>e.id===s),p=r.conversation.messages[h],g=null!=p&&p.content?rl(p.content,"action"):[],f=async e=>{try{return await ol.getCheckpointFileTree(r.id,e)}catch(s){return null}};(0,H.useEffect)(()=>{(async()=>{c(!0);const e=r.conversation.messages.slice(0,h).reverse().find(e=>e.checkpoint_id);if(!p.checkpoint_id)return void c(!1);const s=await f(p.checkpoint_id);let t=null;e&&e.checkpoint_id&&(t=await f(e.checkpoint_id));const a={};s&&t?(Object.entries(s.files).forEach(e=>{let[s,n]=e;const r=t.files[s];r&&JSON.stringify(r)===JSON.stringify(n)||(a[s]={original:r?"string"==typeof r?r:JSON.stringify(r,null,2):"",modified:"string"==typeof n?n:JSON.stringify(n,null,2),type:r?"modified":"added"})}),Object.keys(t.files).forEach(e=>{if(!s.files[e]){const s=t.files[e];a[e]={original:"string"==typeof s?s:JSON.stringify(s,null,2),modified:"",type:"deleted"}}})):s&&Object.entries(s.files).forEach(e=>{let[s,t]=e;a[s]={original:"",modified:"string"==typeof t?t:JSON.stringify(t,null,2),type:"added"}}),i(a),c(!1)})()},[s,r.id,h]);const v=p.metadata.created_date,b=p.metadata.created_by_email,j=la().utc(v),y=j.clone().subtract(5,"minutes").format(),N=j.clone().add(5,"minutes").format(),w=encodeURIComponent("userId;string;;=;".concat(b)),_=encodeURIComponent("timestamp;datetime;;>;".concat(y,",timestamp;datetime;;<;").concat(N)),k="https://cloud.langfuse.com/project/cm23r6fre000rr9hhpjkrzoqx/traces?filter=".concat(w,",").concat(_),A=()=>{null!=p&&p.content&&(navigator.clipboard.writeText(p.content),x(!0),setTimeout(()=>x(!1),2e3))};return(0,re.jsx)(Pa,{open:t,onOpenChange:a,children:(0,re.jsxs)(Ma,{className:"max-w-5xl max-h-[95vh] p-0 overflow-hidden flex flex-col border border-gray-200 rounded-md",children:[(0,re.jsx)(Fa,{className:"px-4 py-3 border-b border-gray-200 bg-gray-50 flex flex-row items-center justify-between",children:(0,re.jsx)(Ua,{className:"text-base font-medium",children:"Message Details"})}),(0,re.jsxs)(hl,{defaultValue:"diff",className:"flex-1 flex flex-col overflow-hidden",onValueChange:m,children:[(0,re.jsxs)(pl,{className:"px-4 pt-2 bg-white border-b border-gray-200",children:[(0,re.jsxs)(gl,{value:"diff",className:"flex items-center",children:[(0,re.jsx)(Yr.A,{className:"h-4 w-4 mr-2"}),"Code Changes"]}),"platform_admin"===n.platform_role&&(0,re.jsxs)(gl,{value:"info",className:"flex items-center",children:[(0,re.jsx)(bl.A,{className:"h-4 w-4 mr-2"}),"Message Info"]})]}),(0,re.jsx)(fl,{value:"diff",className:"flex-1 overflow-auto p-0 m-0",children:o?(0,re.jsxs)("div",{className:"flex justify-center items-center h-64",children:[(0,re.jsx)(Ze.A,{className:"h-6 w-6 animate-spin text-gray-500"}),(0,re.jsx)("span",{className:"ml-2 text-gray-600",children:"Loading changes..."})]}):l&&0!==Object.keys(l).length?(0,re.jsx)("div",{className:"divide-y divide-gray-200",children:Object.entries(l).map((e,s)=>{let[t,a]=e;return(0,re.jsxs)("div",{className:"bg-white",children:[(0,re.jsxs)("div",{className:"flex items-center px-4 py-2 bg-gray-50 border-b border-gray-200",children:[(0,re.jsx)(al.A,{className:"h-4 w-4 mr-2 text-gray-600"}),(0,re.jsx)("span",{className:"font-medium text-sm text-gray-700",children:t}),(0,re.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,re.jsx)("div",{className:"px-0",children:(0,re.jsx)(vl,{originalCode:a.original,modifiedCode:a.modified,language:t.endsWith(".css")?"css":"javascript",title:t,diffViewStyle:"github"})})]},s)})}):(0,re.jsxs)("div",{className:"flex flex-col items-center justify-center h-64 text-gray-500",children:[(0,re.jsx)(Xe.A,{className:"h-10 w-10 mb-3 text-gray-400"}),(0,re.jsx)("p",{children:"No file changes detected for this message."})]})}),"platform_admin"===n.platform_role&&(0,re.jsx)(fl,{value:"info",className:"flex-1 overflow-auto p-0 m-0",children:p?p?(0,re.jsxs)("div",{className:"p-4 space-y-4",children:[(0,re.jsxs)("div",{className:"rounded-lg border border-gray-200 bg-white",children:[(0,re.jsxs)("div",{className:"bg-gray-50 p-3 border-b border-gray-200 flex justify-between items-center",children:[(0,re.jsx)("h3",{className:"text-sm font-medium text-gray-700",children:"Message Attributes"}),(0,re.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,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(Pt.A,{className:"h-3.5 w-3.5 mr-1"}),"Copied!"]}):(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(Kr.A,{className:"h-3.5 w-3.5 mr-1"}),"Copy Content"]})})]}),(0,re.jsx)("div",{className:"p-4 space-y-2",children:Object.entries(p).filter(e=>{let[s]=e;return"content"!==s}).map(e=>{let[s,t]=e;return(0,re.jsxs)("div",{className:"flex",children:[(0,re.jsxs)("span",{className:"font-medium text-gray-700 min-w-[120px]",children:[s,":"]}),(0,re.jsx)("span",{className:"text-gray-600 break-all",children:"object"==typeof t?JSON.stringify(t):String(t)})]},s)})})]}),(0,re.jsxs)("div",{className:"rounded-lg border border-gray-200 bg-white",children:[(0,re.jsx)("div",{className:"bg-gray-50 p-3 border-b border-gray-200",children:(0,re.jsx)("h3",{className:"text-sm font-medium text-gray-700",children:"Langfuse Trace"})}),(0,re.jsx)("div",{className:"p-4",children:(0,re.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,re.jsx)("span",{className:"text-gray-600",children:"View trace in Langfuse:"}),(0,re.jsxs)("a",{href:k,target:"_blank",rel:"noopener noreferrer",className:"text-blue-600 hover:text-blue-800 hover:underline flex items-center",children:[k.substring(0,60),"...",(0,re.jsx)(jl.A,{className:"h-4 w-4 ml-1"})]})]})})]}),(0,re.jsxs)("div",{className:"rounded-lg border border-gray-200 bg-white",children:[(0,re.jsx)("div",{className:"bg-gray-50 p-3 border-b border-gray-200",children:(0,re.jsxs)("h3",{className:"text-sm font-medium text-gray-700",children:["Actions (",g.length,")"]})}),(0,re.jsx)("div",{className:"divide-y divide-gray-200",children:0===g.length?(0,re.jsx)("div",{className:"p-4 text-gray-500 text-center",children:"No actions found in this message"}):g.map((e,s)=>{const t=e.openingTag.match(/action-type="([^"]*)"/)||e.openingTag.match(/type="([^"]*)"/),a=t?t[1]:"Unknown";return(0,re.jsxs)("div",{className:"p-4",children:[(0,re.jsxs)("div",{className:"mb-2",children:[(0,re.jsxs)("span",{className:"font-medium text-gray-700",children:["Action ",s+1,":"]}),(0,re.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,re.jsxs)("div",{className:"mt-2",children:[(0,re.jsx)("div",{className:"font-medium text-sm text-gray-700 mb-1",children:"Content:"}),(0,re.jsx)("pre",{className:"bg-gray-50 p-2 rounded text-xs overflow-x-auto",children:e.content})]})]},s)})})]})]}):null:(0,re.jsxs)("div",{className:"flex justify-center items-center h-64",children:[(0,re.jsx)(Xe.A,{className:"h-10 w-10 mb-3 text-gray-400"}),(0,re.jsx)("span",{className:"ml-2 text-gray-600",children:"Message not found"})]})})]})]})})}var Nl=t(63653);const wl=["className","inset","children"],_l=["className"],kl=["className","sideOffset"],Al=["className","inset"],Sl=["className","children","checked"],Cl=["className","children"],El=["className","inset"],Il=["className"],Tl=["className"],Pl=Nl.bL,Ll=Nl.l9,Ol=Nl.YJ,Rl=Nl.ZL,Dl=Nl.Pb,Ml=Nl.z6,Fl=H.forwardRef((e,s)=>{let{className:t,inset:a,children:n}=e,r=(0,as.A)(e,wl);return(0,re.jsxs)(Nl.ZP,(0,K.A)((0,K.A)({ref:s,className:is("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",t)},r),{},{children:[n,(0,re.jsx)(ln.A,{className:"ml-auto h-4 w-4"})]}))});Fl.displayName=Nl.ZP.displayName;const Bl=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,_l);return(0,re.jsx)(Nl.G5,(0,K.A)({ref:s,className:is("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",t)},a))});Bl.displayName=Nl.G5.displayName;const Ul=H.forwardRef((e,s)=>{let{className:t,sideOffset:a=4}=e,n=(0,as.A)(e,kl);return(0,re.jsx)(Nl.ZL,{children:(0,re.jsx)(Nl.UC,(0,K.A)({ref:s,sideOffset:a,className:is("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",t)},n))})});Ul.displayName=Nl.UC.displayName;const zl=H.forwardRef((e,s)=>{let{className:t,inset:a}=e,n=(0,as.A)(e,Al);return(0,re.jsx)(Nl.q7,(0,K.A)({ref:s,className:is("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",t)},n))});zl.displayName=Nl.q7.displayName;const ql=H.forwardRef((e,s)=>{let{className:t,children:a,checked:n}=e,r=(0,as.A)(e,Sl);return(0,re.jsxs)(Nl.H_,(0,K.A)((0,K.A)({ref:s,className:is("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",t),checked:n},r),{},{children:[(0,re.jsx)("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:(0,re.jsx)(Nl.VF,{children:(0,re.jsx)(Pt.A,{className:"h-4 w-4"})})}),a]}))});ql.displayName=Nl.H_.displayName;const Wl=H.forwardRef((e,s)=>{let{className:t,children:a}=e,n=(0,as.A)(e,Cl);return(0,re.jsxs)(Nl.hN,(0,K.A)((0,K.A)({ref:s,className:is("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",t)},n),{},{children:[(0,re.jsx)("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:(0,re.jsx)(Nl.VF,{children:(0,re.jsx)(_t.A,{className:"h-2 w-2 fill-current"})})}),a]}))});Wl.displayName=Nl.hN.displayName;const Vl=H.forwardRef((e,s)=>{let{className:t,inset:a}=e,n=(0,as.A)(e,El);return(0,re.jsx)(Nl.JU,(0,K.A)({ref:s,className:is("px-2 py-1.5 text-sm font-semibold",a&&"pl-8",t)},n))});Vl.displayName=Nl.JU.displayName;const Yl=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,Il);return(0,re.jsx)(Nl.wv,(0,K.A)({ref:s,className:is("-mx-1 my-1 h-px bg-muted",t)},a))});Yl.displayName=Nl.wv.displayName;const Hl=e=>{let{className:s}=e,t=(0,as.A)(e,Tl);return(0,re.jsx)("span",(0,K.A)({className:is("ml-auto text-xs tracking-widest opacity-60",s)},t))};Hl.displayName="DropdownMenuShortcut";let Gl=0;const $l=new Map,Jl=e=>{if($l.has(e))return;const s=setTimeout(()=>{$l.delete(e),Ql({type:"REMOVE_TOAST",toastId:e})},1e6);$l.set(e,s)},Zl=(e,s)=>{switch(s.type){case"ADD_TOAST":return(0,K.A)((0,K.A)({},e),{},{toasts:[s.toast,...e.toasts].slice(0,1)});case"UPDATE_TOAST":return(0,K.A)((0,K.A)({},e),{},{toasts:e.toasts.map(e=>e.id===s.toast.id?(0,K.A)((0,K.A)({},e),s.toast):e)});case"DISMISS_TOAST":{const{toastId:t}=s;return t?Jl(t):e.toasts.forEach(e=>{Jl(e.id)}),(0,K.A)((0,K.A)({},e),{},{toasts:e.toasts.map(e=>e.id===t||void 0===t?(0,K.A)((0,K.A)({},e),{},{open:!1}):e)})}case"REMOVE_TOAST":return void 0===s.toastId?(0,K.A)((0,K.A)({},e),{},{toasts:[]}):(0,K.A)((0,K.A)({},e),{},{toasts:e.toasts.filter(e=>e.id!==s.toastId)})}},Kl=[];let Xl={toasts:[]};function Ql(e){Xl=Zl(Xl,e),Kl.forEach(e=>{e(Xl)})}function ei(e){let s=Object.assign({},((0,Ja.A)(e),e));const t=(Gl=(Gl+1)%Number.MAX_SAFE_INTEGER,Gl.toString()),a=()=>Ql({type:"DISMISS_TOAST",toastId:t});return Ql({type:"ADD_TOAST",toast:(0,K.A)((0,K.A)({},s),{},{id:t,open:!0,onOpenChange:e=>{e||a()}})}),{id:t,dismiss:a,update:e=>Ql({type:"UPDATE_TOAST",toast:(0,K.A)((0,K.A)({},e),{},{id:t})})}}function si(){const[e,s]=H.useState(Xl);return H.useEffect(()=>(Kl.push(s),()=>{const e=Kl.indexOf(s);e>-1&&Kl.splice(e,1)}),[e]),(0,K.A)((0,K.A)({},e),{},{toast:ei,dismiss:e=>Ql({type:"DISMISS_TOAST",toastId:e})})}var ti=t(22796);const ai=e=>{let{content:s}=e;const{updateSecrets:t,existingSecretNames:a,addChatMessage:n}=_s(),[r,l]=(0,H.useState)(!1),[i,o]=(0,H.useState)({}),[c,d]=(0,H.useState)(!1),{toast:m}=si(),u=Array.isArray(s)?s:[],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{l(e),e||o({})},children:[(0,re.jsx)(La,{asChild:!0,children:(0,re.jsxs)(Hs,{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,re.jsx)(nl.A,{size:16}):(0,re.jsx)(ti.A,{size:16}),g&&(0,re.jsx)(Xe.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,re.jsxs)(Ma,{className:"sm:max-w-md",children:[(0,re.jsxs)(Fa,{children:[(0,re.jsxs)(Ua,{className:"text-teal-700",children:[p?"Update":"Set"," ",x.length>1?"Secrets":"".concat(x[0]," Secret")]}),(0,re.jsx)(za,{children:"Enter the values for the required secrets."})]}),(0,re.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 t(i);const e=Object.keys(i).filter(e=>!a.includes(e));if(e.length>0){const s=e.join(", ");n({role:"user",content:"I've added ".concat(s," secrets")})}l(!1),o({}),m({title:"Secrets updated successfully",description:"The secrets have been set."})}catch(s){m({variant:"destructive",title:"Failed to set secrets",description:s.message||"An error occurred while setting the secrets"})}finally{d(!1)}}},children:[(0,re.jsx)("div",{className:"grid gap-6 py-4",children:u.map((e,s)=>(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsx)(Nt,{htmlFor:"secret-".concat(s),className:"block font-medium text-slate-700",children:e.secretName}),(0,re.jsx)(ft,{id:"secret-".concat(s),type:"password",value:i[e.secretName]||"",onChange:s=>{return t=e.secretName,a=s.target.value,void o(e=>(0,K.A)((0,K.A)({},e),{},{[t]:a}));var t,a},className:"w-full",placeholder:e.description||"Enter ".concat(e.secretName," value"),autoComplete:"off"}),e.description&&(0,re.jsx)("p",{className:"text-xs text-slate-500 mt-1",children:e.description})]},s))}),(0,re.jsxs)(Ba,{className:"gap-2 sm:gap-0",children:[(0,re.jsx)(Hs,{type:"button",variant:"outline",onClick:()=>l(!1),disabled:c,className:"border-slate-300 text-slate-700",children:"Cancel"}),(0,re.jsx)(Hs,{type:"submit",disabled:c,className:"bg-teal-600 hover:bg-teal-700 text-white",children:c?"Saving...":"Save Secrets"})]})]})]})]})},ni=["node"],ri=["node"],li=["node"];function ii(e){let{msgId:s,title:t,children:a}=e;const[n,r]=(0,H.useState)(!1);return(0,re.jsxs)("div",{className:"action-component action-group bg-white rounded-lg p-4 my-4 cursor-pointer","data-title":t,children:[(0,re.jsxs)("div",{className:"flex items-center justify-between gap-2 mb-4 pb-2 border-b border-gray-100",children:[(0,re.jsx)("h3",{className:"font-medium text-gray-800",children:t}),(0,re.jsx)("div",{className:"flex items-center",children:(0,re.jsxs)(Pl,{children:[(0,re.jsx)(Ll,{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,re.jsx)(tl.A,{size:16})}),(0,re.jsx)(Ul,{align:"end",children:(0,re.jsxs)(zl,{onClick:e=>{e.stopPropagation(),r(!0)},className:"flex items-center gap-2 cursor-pointer",children:[(0,re.jsx)(al.A,{size:14,className:"text-gray-400"}),(0,re.jsx)("span",{children:"View Changes"})]})})]})})]}),(0,re.jsx)("div",{className:"space-y-3",children:a}),n&&(0,re.jsx)(yl,{msgId:s,isOpen:n,onClose:e=>r(!1)})]})}function oi(e){let{title:s,details:t,componentName:a}=e;const[n,r]=H.useState(!1),l=null==s?void 0:s.replace(/"/g,'"').replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/'/g,"'").replace(/'/g,"'"),i=null==t?void 0:t.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,re.jsxs)("div",{className:"my-4 rounded-lg border border-red-200 bg-red-50",children:[(0,re.jsxs)("div",{className:"flex items-center gap-3 p-4 cursor-pointer",onClick:()=>r(!n),children:[(0,re.jsx)("div",{className:"text-red-500",children:(0,re.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,re.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,re.jsx)("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),(0,re.jsx)("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]})}),(0,re.jsxs)("div",{className:"flex-1",children:[(0,re.jsx)("h3",{className:"font-medium text-red-700",children:l}),o&&(0,re.jsxs)("p",{className:"text-sm text-red-600",children:["in ",o]})]}),(0,re.jsx)("div",{className:"transition-transform ".concat(n?"rotate-180":""),children:(0,re.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,re.jsx)("polyline",{points:"6 9 12 15 18 9"})})})]}),n&&i&&(0,re.jsx)("div",{className:"px-4 pb-4 pt-0",children:(0,re.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 ci=e=>{const s=e.split("/"),t=s[0];let a=s[s.length-1];return a.includes(".")&&(a=a.split(".").slice(0,-1).join(" ")),{name:a,artifactType:t}};function di(e){let{node:s}=e;const{app:t}=_s(),a=(0,Z.Zp)(),n=s.properties["action-type"]||s.properties.type;if("requestsecrets"===(null==n?void 0:n.toLowerCase())){let e;try{e=JSON.parse(atob(s.properties.dataContent))}catch(m){e=[]}return(0,re.jsx)(ai,{content:e})}let r=(null==n?void 0:n.replace(/(_)/g," ").replace(/\b\w/g,e=>e.toUpperCase()))||"";"file"===n&&s.properties.filepath&&(r=(e=>{const{name:s,artifactType:t}=ci(e);return"components"===t?"".concat(s," component"):"pages"===t?"".concat(s," page"):"entities"===t?"".concat(s," entity"):s.toLowerCase().includes("layout")?"Layout":"".concat(t," - ").concat(s)})(s.properties.filepath)),"insertentityrecords"===(null==n?void 0:n.toLowerCase())&&s.properties.dataInsertRecordsLength&&(r="Insert ".concat(s.properties.dataInsertRecordsLength," ").concat(s.properties.dataEntityName," Records"));const l=!0===s.properties.dataIsComplete||"true"===s.properties.dataIsComplete,i=s.properties.dataContentLength;let o=l?100:0;if(!l&&"file"===n&&s.properties.filepath){var c,d;const e=s.properties.filepath,{name:a,artifactType:n}=ci(e),r=(null===(c=t[n])||void 0===c||null===(d=c[a])||void 0===d?void 0:d.length)||15e3;o=Math.round(i/r*100),o=o>100?100:o}return(0,re.jsxs)("div",{className:"action-component action-step flex flex-col px-3 py-2 rounded-md hover:bg-gray-100 transition-colors","data-type":s.properties.dataActionType,"data-title":s.properties.dataTitle,onClick:()=>{if("file"===n&&s.properties.filepath){const e=s.properties.filepath;if(e.startsWith("agents/")){let s=e.split("/").pop();s.endsWith(".json")&&(s=s.slice(0,-5)),a("/apps/".concat(t.id,"/editor/workspace/agents?agent=").concat(s))}else a("/apps/".concat(t.id,"/editor/workspace/code?filePath=").concat(s.properties.filepath))}},children:[(0,re.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,re.jsxs)("div",{className:"flex items-center gap-2",children:[!0===l||"true"===l?(0,re.jsx)(nl.A,{className:"w-4 h-4 text-green-500"}):(0,re.jsx)("div",{className:"relative w-4 h-4",children:(0,re.jsxs)("svg",{className:"w-4 h-4",viewBox:"0 0 24 24",children:[(0,re.jsx)("circle",{cx:"12",cy:"12",r:"10",fill:"none",stroke:"#e5e7eb",strokeWidth:"2"}),(0,re.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,re.jsx)("span",{className:"text-sm text-gray-700",children:s.properties.title||"Editing "+r})]}),"file"===n&&s.properties.filepath&&s.properties.filepath.startsWith("functions/")&&(0,re.jsx)("div",{className:"text-gray-400",children:(0,re.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,re.jsx)("path",{d:"m9 18 6-6-6-6"})})})]}),(0,re.jsx)("span",{className:"text-xs text-gray-400 ml-6",children:r})]})}function mi(e){let{content:s,msgId:t,role:a}=e;const{user:n}=oe(),{app:r}=_s(),l=function(e){let s=e;const t=rl(e,"action");for(let n=t.length-1;n>=0;n--){const e=t[n];let r=s.slice(0,e.openingTagIndex);if(e.closingTagIndex||e.openingTag.includes(">")){let t={"data-content-length":e.content.length,"data-is-complete":e.closingTagIndex?"true":"false"};const n=ll(e.openingTag,"action-type")||ll(e.openingTag,"type");if((null==n?void 0:n.toLowerCase())==="insertEntityRecords".toLowerCase()){if(t["data-entity-name"]=ll(e.openingTag,"entity-name"),t.title="Insert ".concat(t["data-entity-name"]," Records"),e.closingTagIndex)try{const s=JSON.parse(e.content);t["data-insert-records-length"]=s.length}catch(a){}}else if((null==n?void 0:n.toLowerCase())==="requestsecrets".toLowerCase())try{t["data-content"]=btoa(e.content)}catch(a){}e.openingTag.slice(0,-1).includes(">");const l="".concat(e.openingTag.slice(0,-1)," ").concat(Object.entries(t).map(e=>{let[s,t]=e;return"".concat(s,'="').concat(t,'"')}).join(" "),">");s=r+l+(e.closingTagIndex?s.slice(e.closingTagIndex+9):"")}else s=r}return s=s.replace(//g,""),s=s.replace(//g,""),s}(s),i={div:e=>{var s;let{node:a}=e,n=(0,as.A)(e,ni),r=(null===(s=a.properties)||void 0===s?void 0:s.className)||"";if(Array.isArray(r)&&(r=r.join(" ")),"string"==typeof r&&r.includes("action-component")){if(r.includes("action-group"))return(0,re.jsx)(ii,(0,K.A)({msgId:t,title:a.properties.dataTitle},n));if(r.includes("action-single"))return(0,re.jsx)(di,(0,K.A)({node:a},n))}return r.includes("error-component")?(0,re.jsx)(oi,(0,K.A)({},n)):(0,re.jsx)("div",(0,K.A)({},n))},action:e=>{let{node:s}=e,t=(0,as.A)(e,ri);return(0,re.jsx)(di,(0,K.A)({node:s},t))},diff:e=>{let{node:s}=e,t=(0,as.A)(e,li);return(0,re.jsx)("code",(0,K.A)({},t))}};return(0,re.jsx)("div",{className:"prose dark:prose-invert max-w-none base44-markdown relative",children:(0,re.jsx)(el.oz,{rehypePlugins:"user"!==a||s.includes("n(!a),children:[(0,re.jsx)("span",{className:"font-medium",children:s}),a?(0,re.jsx)(Tt.A,{className:"h-5 w-5 text-gray-500"}):(0,re.jsx)(It.A,{className:"h-5 w-5 text-gray-500"})]}),a&&(0,re.jsx)("div",{className:"mt-2 p-2 rounded-lg transition-all duration-300 ease-in-out overflow-hidden ".concat(a?"opacity-100":"max-h-0 opacity-0"),children:t})]})}var hi=t(40602);function pi(e){let{toolCall:s}=e;return(0,re.jsx)(xi,{title:(0,re.jsxs)("div",{className:"font-small flex items-center",children:[(0,re.jsx)(hi.A,{className:"w-4 h-4 mr-2"}),(0,re.jsxs)("span",{className:"font-semibold",children:["Action: ",s.name]})]}),children:(0,re.jsx)("div",{className:"ml-2 text-gray-700",children:(t=s.arguments,"object"==typeof t&&null!==t?Object.entries(t).map(e=>{let[s,t]=e;const a="object"==typeof t?JSON.stringify(t):t.toString();return(0,re.jsxs)("div",{className:"mb-1 text-sm",children:[(0,re.jsxs)("span",{className:"font-semibold",children:[s,":"]})," ",a.split("\n").map((e,s)=>(0,re.jsxs)("span",{children:[s>0&&(0,re.jsx)("br",{}),e]},s))]},s)}):t)})});var t}function gi(e){let{toolResults:s}=e;const t=s.display_results;if(ts().isObject(t)){const{widget:e,data:s}=t;if("table"===e)return(0,re.jsx)("div",{className:"overflow-x-auto",children:(0,re.jsxs)("table",{className:"table w-full bg-white",children:[(0,re.jsx)("thead",{children:(0,re.jsx)("tr",{children:s.columns.map((e,s)=>(0,re.jsx)("th",{children:e},s))})}),(0,re.jsx)("tbody",{children:s.rows.map((e,t)=>(0,re.jsx)("tr",{children:s.columns.map((s,t)=>(0,re.jsx)("td",{children:e[s]},t))},t))})]})})}return(0,re.jsx)(xi,{title:(0,re.jsx)("div",{className:"font-semibold",children:"Action Results"}),children:(0,re.jsxs)("div",{className:"text-gray-700",children:[(0,re.jsx)("p",{children:s.results}),(0,re.jsx)("div",{className:"text-xs text-gray-500 mt-1",children:"(This is the result of a tool execution, not the AI's response)"})]})})}const fi=function(e){let{message:s}=e;const[t,a]=(0,H.useState)(!1);return(0,re.jsxs)("div",{className:"text-sm p-4 bg-white mx-auto mb-6 rounded-lg mb-6 border border-gray-300",children:[(0,re.jsxs)("div",{className:"text-gray-700",children:["Some errors were detected, base44 will try to fix them automatically."," ",(0,re.jsx)("div",{className:"mt-2",children:(0,re.jsx)("a",{className:"text-teal-900/70 hover:underline cursor-pointer",onClick:()=>a(!t),children:t?"hide errors":"see errors"})})]}),t&&(0,re.jsx)("div",{className:"mt-4",children:(0,re.jsx)(ui,{content:s.content})})]})};var vi=t(50270),bi=t(78968),ji=t(97820),yi=t(26209);const Ni={div:(0,re.jsx)(vi.A,{className:"h-3 w-3"}),button:(0,re.jsx)(bi.A,{className:"h-3 w-3"}),p:(0,re.jsx)(ji.A,{className:"h-3 w-3"}),h1:(0,re.jsx)(yi.A,{className:"h-3 w-3"}),h2:(0,re.jsx)(yi.A,{className:"h-3 w-3"}),h3:(0,re.jsx)(yi.A,{className:"h-3 w-3"}),h4:(0,re.jsx)(yi.A,{className:"h-3 w-3"}),h5:(0,re.jsx)(yi.A,{className:"h-3 w-3"})};var wi=t(21570);const _i=function(e){let{message:s}=e;const{app:t}=_s(),{user:a}=oe(),[n,r]=(0,H.useState)(!1);return(0,re.jsxs)("div",{className:"text-sm p-4 bg-white mx-auto mb-6 rounded-lg mb-6 relative",children:[(0,re.jsxs)("div",{className:"text-gray-700",children:["Files have been manually edited."," ",(0,re.jsx)("div",{className:"mt-2",children:(0,re.jsx)("a",{className:"text-teal-900/70 hover:underline cursor-pointer",onClick:()=>r(!n),children:n?"hide details":"see details"})})]}),n&&(0,re.jsx)("div",{className:"mt-4",children:(0,re.jsx)(ui,{content:s.content})}),(0,re.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,re.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.")&&(Ie("User clicked - revert this",{app_id:null==t?void 0:t.id,message_id:s.id}),We({user_id:null==a?void 0:a.id,app_id:null==t?void 0:t.id,conversation_id:null==t||null===(e=t.conversation)||void 0===e?void 0:e.id},{cta:"revert this",origin:"manual_editing_message",message_id:s.id,target_route:null}),await ve.undoMessage(t.id,s.id))},className:"flex items-center gap-1",children:[(0,re.jsx)(wi.A,{className:"h-3 w-3"}),"Revert this"]})})]})},ki=e=>{let{reasoning:s}=e;const[t,a]=(0,H.useState)(!1);if(!s)return null;const n=null!==s.end_date&&void 0!==s.end_date,r=(()=>{if(!n)return null;const e=la()(s.start_date),t=la()(s.end_date),a=la().duration(t.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,re.jsxs)("div",{className:"mb-3",children:[(0,re.jsx)("div",{className:"inline-flex items-start gap-2",children:(0,re.jsx)("button",{onClick:()=>a(!t),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||!s.content,children:n?(0,re.jsxs)(re.Fragment,{children:[s.content&&(t?(0,re.jsx)(It.A,{className:"h-3 w-3"}):(0,re.jsx)(ln.A,{className:"h-3 w-3"})),(0,re.jsxs)("span",{className:"text-xs font-medium",children:["Thought ",r&&(0,re.jsxs)("span",{className:"text-xs text-slate-500",children:["for ",r]})]})]}):(0,re.jsx)(re.Fragment,{children:(0,re.jsx)("span",{className:"text-xs font-medium animate-pulse",children:"Planning next steps..."})})})}),n&&s.content&&t&&(0,re.jsx)("div",{className:"mt-2 ml-0 animate-in slide-in-from-top-1 duration-200",children:(0,re.jsxs)("div",{className:"relative pl-4 py-2 pr-3 rounded-md bg-gradient-to-r from-slate-50 to-transparent",children:[(0,re.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,re.jsx)("p",{className:"text-xs text-slate-600 leading-relaxed whitespace-pre-wrap",children:s.content})]})})]})},Ai=e=>{let{files:s}=e;const[t,a]=(0,H.useState)(!1);if(!s||0===s.length)return null;const n=s.reduce((e,s)=>(s.startsWith("entities/")?e.entities.push(s):s.startsWith("pages/")||s.startsWith("components/")||s.startsWith("layout")?e.code.push(s):e.other.push(s),e),{entities:[],code:[],other:[]});return(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)("div",{className:"text-xs text-gray-400 cursor-pointer hover:underline",onClick:()=>a(!0),children:(0,re.jsxs)("span",{className:"flex items-center gap-1",children:[(0,re.jsx)(al.A,{className:"h-3 w-3"}),"see context"]})}),t&&(0,re.jsx)("div",{className:"fixed inset-0 bg-black bg-opacity-50 z-50 flex items-center justify-center p-4",children:(0,re.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,re.jsxs)("div",{className:"flex justify-between items-center p-4 border-b dark:border-gray-700",children:[(0,re.jsx)("h3",{className:"font-medium text-lg",children:"Files Selected for Context"}),(0,re.jsx)("button",{onClick:()=>a(!1),className:"text-gray-500 hover:text-gray-700 dark:hover:text-gray-300 transition-colors",children:(0,re.jsx)(zs.A,{className:"h-5 w-5"})})]}),(0,re.jsxs)("div",{className:"p-5 overflow-y-auto flex-1",children:[(0,re.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,re.jsx)("b",{children:"might"})," be relevant for potential changes."]}),(0,re.jsxs)("p",{className:"text-sm text-teal-700 dark:text-teal-400 mb-5 border-l-2 border-teal-600 pl-3",children:[(0,re.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,re.jsxs)("div",{className:"mb-5",children:[(0,re.jsxs)("h4",{className:"text-sm font-semibold mb-2 flex items-center gap-2",children:[(0,re.jsx)(Yr.A,{className:"h-4 w-4"}),"Code Files"]}),(0,re.jsx)("div",{className:"space-y-1 pl-2",children:n.code.map((e,s)=>(0,re.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},s))})]}),n.entities.length>0&&(0,re.jsxs)("div",{className:"mb-5",children:[(0,re.jsxs)("h4",{className:"text-sm font-semibold mb-2 flex items-center gap-2",children:[(0,re.jsx)(jr.A,{className:"h-4 w-4"}),"Entity Files"]}),(0,re.jsx)("div",{className:"space-y-1 pl-2",children:n.entities.map((e,s)=>(0,re.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},s))})]}),n.other.length>0&&(0,re.jsxs)("div",{children:[(0,re.jsxs)("h4",{className:"text-sm font-semibold mb-2 flex items-center gap-2",children:[(0,re.jsx)(al.A,{className:"h-4 w-4"}),"Other Files"]}),(0,re.jsx)("div",{className:"space-y-1 pl-2",children:n.other.map((e,s)=>(0,re.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},s))})]})]}),(0,re.jsx)("div",{className:"p-4 border-t dark:border-gray-700 flex justify-end",children:(0,re.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 Si(e){var s,t,a,n,r;let{item:l,undoMessage:i,itemIndex:o}=e;const{user:c}=oe(),{app:d}=_s();if(null===(s=l.additional_message_params)||void 0===s?void 0:s.automated_fix)return(0,re.jsx)("div",{className:"mb-6 relative",children:(0,re.jsx)(fi,{message:l})});if(null===(t=l.additional_message_params)||void 0===t?void 0:t.diff_message)return(0,re.jsx)("div",{className:"mb-6 relative",children:(0,re.jsx)(_i,{message:l})});const m=null===(a=l.custom_context)||void 0===a?void 0:a.find(e=>{var s;return"files"===e.type&&(null===(s=e.data)||void 0===s?void 0:s.files)}),u=(null==m||null===(n=m.data)||void 0===n?void 0:n.files)||[],x="user"===l.role;return(0,re.jsxs)("div",{className:"mb-6 relative ".concat(x?"flex justify-end":""),children:["assistant"===l.role&&(0,re.jsxs)("div",{className:"flex items-center gap-2 mb-2",children:[(0,re.jsx)("img",{src:"https://base44.app/logo_v3.png",alt:"Base44 AI",className:"w-6 h-6 object-cover rounded-full opacity-75"}),(0,re.jsx)("span",{className:"text-xs text-gray-500",children:"Base44"})]}),(0,re.jsx)(ki,{reasoning:l.reasoning}),(0,re.jsx)("div",{className:"text-sm ps-4 rounded-lg ".concat(x?"pr-4 bg-slate-200 max-w-[85%] py-4":"pl-8"),children:(0,re.jsxs)("div",{children:["tool"===l.role?l.tool_results.map((e,s)=>(0,re.jsx)(gi,{toolResults:e},s)):(0,re.jsxs)(re.Fragment,{children:[l.custom_context&&l.custom_context.map((e,s)=>{var t;if("element"===e.type&&null!==(t=e.data)&&void 0!==t&&t.element_tag_name){const t=e.data.element_tag_name.toLowerCase(),a=Ni[t]||(0,re.jsx)(Yr.A,{className:"h-3 w-3"});return(0,re.jsx)("div",{className:"mb-2 flex items-center gap-2 text-xs",children:(0,re.jsxs)("div",{className:"flex items-center gap-1 px-2 py-1 bg-gray-900 text-white rounded-md",children:[a,(0,re.jsx)("span",{children:t})]})},s)}return null}),l.file_urls&&l.file_urls.length>0&&(0,re.jsx)("div",{className:"mb-4 flex flex-wrap gap-4",children:l.file_urls.map((e,s)=>(0,re.jsx)("div",{className:"relative",children:e.match(/\.(jpg|jpeg|png|gif)$/i)?(0,re.jsx)("img",{src:e,alt:"Attached content",className:"max-w-[300px] max-h-[300px] rounded-lg border border-gray-200 shadow-sm"}):(0,re.jsxs)("div",{className:"flex items-center gap-2 p-2 bg-white rounded-lg border border-gray-200",children:[(0,re.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,re.jsx)("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),(0,re.jsx)("polyline",{points:"14 2 14 8 20 8"})]}),(0,re.jsx)("a",{href:e,target:"_blank",rel:"noopener noreferrer",className:"text-blue-600 hover:underline",children:"Attached file"})]})},s))}),(0,re.jsx)(ui,{content:l.content,msgId:l.id,role:l.role}),l.tool_calls&&l.tool_calls.map((e,s)=>(0,re.jsx)(pi,{toolCall:e},s))]}),(null===(r=l.metadata)||void 0===r?void 0:r.created_date)&&(0,re.jsxs)("div",{className:"text-xs text-gray-400 mt-2 flex items-center",children:[la().utc(l.metadata.created_date,la().ISO_8601).fromNow(),"user"===l.role&&u.length>0&&(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)("span",{className:"mx-2",children:"\u2022"}),(0,re.jsx)(Ai,{files:u})]})]})]})}),"user"===l.role&&o>0&&l.checkpoint_id&&(0,re.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,re.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.")&&(Ie("User clicked - revert this",{app_id:null==d?void 0:d.id,message_id:l.id}),We({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:l.id,target_route:null}),i(l.id))},className:"flex items-center gap-1",children:[(0,re.jsx)(wi.A,{className:"h-3 w-3"}),"Revert this"]})})]})}class Ci extends H.Component{constructor(e){super(e),this.state={hasError:!1,error:null}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,s){}render(){return this.state.hasError?(0,re.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,re.jsx)("p",{className:"text-sm",children:"Could not render this message. It might contain special characters."})}):this.props.children}}const Ei=e=>{let{messages:s,undoMessage:t}=e;const[a,n]=(0,H.useState)(20),[r,l]=(0,H.useState)(!0),[i,o]=(0,H.useState)(!1),c=(0,H.useRef)(null),d=(0,H.useRef)(s.length);(0,H.useEffect)(()=>{0===d.current&&s.length>0?(n(20),l(s.length>20),o(!1)):i?(n(s.length),l(!1)):n(e=>{const t=Math.min(20,s.length);return l(s.length>t),t}),d.current=s.length},[s.length,i]),(0,H.useEffect)(()=>{const e=new URLSearchParams(window.location.search).get("msgId");e&&setTimeout(()=>{const s=document.getElementById("message-".concat(e));s&&(s.scrollIntoView({behavior:"smooth"}),s.classList.add("border-2"),s.classList.add("border-black"),s.classList.add("font-medium"))},1e3)},[]);const m=s.slice(-a);return(0,re.jsxs)("div",{ref:c,className:"relative",children:[r&&(0,re.jsx)("div",{className:"flex justify-center py-2",children:(0,re.jsx)("button",{onClick:()=>{const e=c.current,t=e.scrollHeight-e.scrollTop;n(s.length),l(!1),o(!0),setTimeout(()=>{e.scrollTop=e.scrollHeight-t},0)},className:"text-sm text-blue-500 hover:text-blue-600 hover:underline",children:"Load entire conversation"})}),m.slice(0,m.length).map((e,s)=>(0,re.jsx)("div",{id:"message-".concat(e.id),children:(0,re.jsx)(Ci,{children:(0,re.jsx)(Si,{item:e,itemIndex:s,undoMessage:t})})},e.id||s))]})};var Ii=t(53291),Ti=t(52229);function Pi(e){let{status:s,typingSpeed:t=40,className:a=""}=e;const[n,r]=(0,H.useState)(""),[l,i]=(0,H.useState)(!0),[o,c]=(0,H.useState)(0),d=(0,H.useRef)(s||""),m=(0,H.useRef)(null);return(0,H.useEffect)(()=>{s===d.current&&l||(c(e=>e+1),i(!0),r(""),d.current=s||"")},[s]),(0,H.useEffect)(()=>{if(l&&d.current&&n.length{r(d.current.substring(0,n.length+1))},t),()=>clearTimeout(m.current);l&&d.current&&n.length===d.current.length&&i(!1)},[n,l,t]),(0,re.jsxs)("div",{className:"flex items-center h-[1.5em] sm:h-[2em]",children:[" ",(0,re.jsx)(Ii.N,{mode:"wait",children:(0,re.jsxs)(Ti.P.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:{duration:.2},className:"text-slate-700 tracking-normal ".concat(a),children:[n,l?(0,re.jsx)(Ti.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,re.jsx)(Ti.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 Li=e=>{let{status:s}=e;return(0,re.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,re.jsx)("div",{className:"flex-1",children:s.details})})};function Oi(e){let{status:s,messages:t}=e;const[a,n]=(0,H.useState)(new Date),[r,l]=(0,H.useState)(window.innerWidth<=768);(0,H.useEffect)(()=>{const e=()=>{l(window.innerWidth<=768)};return window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[]),(0,H.useEffect)(()=>{n(s.last_updated_date)},[s.details]);const i=a0,o=r||(null==t?void 0:t.length)>2;return(0,re.jsxs)("div",{children:["error"===s.state&&(0,re.jsx)(Li,{status:s}),"processing"===s.state&&(0,re.jsxs)("div",{className:"",children:[i&&(0,re.jsxs)("div",{className:"text-xs text-gray-500 mt-2",children:["This has been running for a while. It might be stuck.",(0,re.jsxs)("div",{className:"mt-1",children:["If this persists, try to stop the chat, *revert your last message* and try again, or ",(0,re.jsx)("button",{type:"button",onClick:()=>window.open("/support","_blank"),className:"underline text-primary hover:text-orange-500 transition-colors",children:"contact support"}),"."]})]}),o&&(0,re.jsxs)("div",{className:"text-gray-500 mt-3 ml-4 flex items-center gap-2",children:[(0,re.jsx)("img",{src:Ge,alt:"Logo",className:"w-4 h-4 grayscale"}),(0,re.jsx)(Pi,{status:s.details,className:"text-xs"})]})]})]})}function Ri(e){if(!e)return"0";const s=parseInt(e.toString(),10);return s>=1e3?"".concat((s/1e3).toFixed(s%1e3==0?0:1),"k"):s.toString()}function Di(e){return Boolean(e&&e.endsWith("_yearly"))}function Mi(e){return e&&e.endsWith("_yearly")?e.replace("_yearly",""):e||""}function Fi(e){return"".concat(e,"_yearly")}function Bi(e){return e?e.replace(/\s*(yearly|Yearly)\s*/gi,"").replace(/\s*plan\s*/gi,"").replace(/\s*\.\.\.\s*/g,"").replace(/\s+/g," ").trim():""}const Ui=["starter","builder","pro","elite","elite_2","elite_3"];function zi(e){return e&&"free"!==e.toLowerCase()?Di(e)?"yearly":"monthly":"yearly"}function qi(e){if(!e||"free"===e.toLowerCase())return"starter";const s=Mi(e),t=Ui.indexOf(s);return-1===t||t===Ui.length-1?null:Ui[t+1]}function Wi(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 Vi(e){return Ri(e)}function Yi(e){if(!e)return"";return{starter:"Starter",builder:"Builder",pro:"Pro",elite:"Elite",elite_2:"Elite 2",elite_3:"Elite 3"}[e]||e}function Hi(e,s){const t=zi(e),a=qi(e),n=function(e,s){if(null==s||!s.pricing)return null;const t=qi(e);return t&&("yearly"===zi(e)?s.pricing.yearly:s.pricing.monthly)[t]||null}(e,s);return{currentTier:e||"free",nextTier:a,billingPeriod:t,nextPlan:n}}function Gi(e,s){const t=function(e){let{currentUsage:s,stats:t}=e;const[a,n]=(0,H.useState)(!0),[r,l]=(0,H.useState)(null),i=(0,H.useMemo)(()=>{if(!s||!t)return{currentPlan:null,nextPlan:null,billingPeriod:"yearly"};try{var e;const a=Hi(s.tier,t);return{currentPlan:null!==(e=t.stripe_subscription)&&void 0!==e&&e.plan&&Object.values(t.pricing.monthly).concat(Object.values(t.pricing.yearly)).find(e=>{var s,a;return e.id===(null===(s=t.stripe_subscription)||void 0===s||null===(a=s.plan)||void 0===a?void 0:a.id)})||null,nextPlan:a.nextPlan,billingPeriod:a.billingPeriod}}catch(a){return l("Failed to calculate billing information"),{currentPlan:null,nextPlan:null,billingPeriod:"yearly"}}},[s,t]);return(0,H.useEffect)(()=>{null!==s&&null!==t?(n(!1),l(null)):n(!0)},[s,t]),{currentPlan:i.currentPlan,nextPlan:i.nextPlan,billingPeriod:i.billingPeriod,isLoading:a,error:r}}({currentUsage:e,stats:s}),a=(0,H.useMemo)(()=>t.nextPlan?Wi(t.nextPlan):{messageCredits:0,integrationCredits:0},[t.nextPlan]);return(0,K.A)((0,K.A)({},t),{},{nextPlanCredits:a,hasNextPlan:null!==t.nextPlan})}class $i extends X.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,s){return this.axios.post("/create-workspace-checkout-session",{workspace_id:e,pending_changes:s})}getInvoices(){return this.axios.get("/invoices")}}const Ji=new $i,Zi=["className"],Ki=["className","children"],Xi=["className"],Qi=["className"],eo=["className"],so=["className"],to=ka.Root,ao=ka.Trigger,no=ka.Portal,ro=(ka.Close,H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,Zi);return(0,re.jsx)(ka.Overlay,(0,K.A)({ref:s,className:is("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",t)},a))}));ro.displayName=ka.Overlay.displayName;const lo=H.forwardRef((e,s)=>{let{className:t,children:a}=e,n=(0,as.A)(e,Ki);return(0,re.jsxs)(no,{children:[(0,re.jsx)(ro,{}),(0,re.jsxs)(ka.Content,(0,K.A)((0,K.A)({ref:s,className:is("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",t)},n),{},{children:[a,(0,re.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,re.jsx)(zs.A,{className:"h-4 w-4"}),(0,re.jsx)("span",{className:"sr-only",children:"Close"})]})]}))]})});lo.displayName=ka.Content.displayName;const io=e=>{let{className:s}=e,t=(0,as.A)(e,Xi);return(0,re.jsx)("div",(0,K.A)({className:is("flex flex-col space-y-1.5 text-center sm:text-left",s)},t))};io.displayName="DialogHeader";const oo=e=>{let{className:s}=e,t=(0,as.A)(e,Qi);return(0,re.jsx)("div",(0,K.A)({className:is("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",s)},t))};oo.displayName="DialogFooter";const co=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,eo);return(0,re.jsx)(ka.Title,(0,K.A)({ref:s,className:is("text-lg font-semibold leading-none tracking-tight",t)},a))});co.displayName=ka.Title.displayName;const mo=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,so);return(0,re.jsx)(ka.Description,(0,K.A)({ref:s,className:is("text-sm text-muted-foreground",t)},a))});mo.displayName=ka.Description.displayName;const uo=e=>{let{question:s,answer:t}=e;const[a,n]=(0,H.useState)(!1);return(0,re.jsxs)("div",{className:"border-b border-gray-200 py-4",children:[(0,re.jsxs)("button",{className:"flex justify-between items-center w-full text-left",onClick:()=>n(!a),children:[(0,re.jsx)("h3",{className:"text-lg font-medium text-gray-800",children:s}),(0,re.jsx)("span",{className:"text-gray-600 transition-transform duration-300 ".concat(a?"rotate-180":""),children:(0,re.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,re.jsx)("polyline",{points:"6 9 12 15 18 9"})})})]}),(0,re.jsx)(Ii.N,{children:a&&(0,re.jsx)(Ti.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,re.jsx)("div",{className:"pt-4 pb-2 text-gray-600",children:t})})})]})};function xo(){const e=[{question:"What is Base44?",answer:(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.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,re.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,re.jsxs)("div",{className:"space-y-2",children:[(0,re.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,re.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,re.jsxs)("div",{className:"space-y-2",children:[(0,re.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,re.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,re.jsxs)("div",{className:"space-y-2",children:[(0,re.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,re.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,re.jsxs)("div",{className:"space-y-2",children:[(0,re.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,re.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,re.jsxs)("div",{className:"space-y-2",children:[(0,re.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,re.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,re.jsxs)("div",{className:"space-y-2",children:[(0,re.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,re.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,re.jsxs)("div",{className:" rounded-xl p-8 mt-12",children:[(0,re.jsx)("h2",{className:"text-2xl font-semibold mb-6 text-gray-800",children:"Frequently Asked Questions"}),(0,re.jsx)("div",{className:"divide-y divide-gray-200",children:e.map((e,s)=>(0,re.jsx)(uo,{question:e.question,answer:e.answer},s))})]})}const ho=["trackingAction","ctaText","trackingContext","onClick","children"],po=e=>{let{trackingAction:s,ctaText:t,trackingContext:a={},onClick:n,children:r}=e,l=(0,as.A)(e,ho);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,re.jsx)(Yn,(0,K.A)((0,K.A)({},l),{},{onClick:e=>{try{var r,l,i,o,u;const e=(0,K.A)({action:s||"unknown_action",element_type:"button",user_id:(null===(r=c)||void 0===r?void 0:r.id)||null,workspace_id:(null===(l=d)||void 0===l?void 0:l.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{Ie("User - Click",e)}catch(p){}try{var x,h;We({user_id:null!==(x=null===(h=c)||void 0===h?void 0:h.id)&&void 0!==x?x:null},(0,K.A)({cta:t||"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:r}))},go=["billingAction","ctaText","billingContext","children"],fo=e=>{let{billingAction:s,ctaText:t,billingContext:a={},children:n}=e,r=(0,as.A)(e,go),l={};try{l=(0,K.A)({origin:"BillingPage",target_route:"/billing",element_type:"button"},a)}catch(i){l={origin:"BillingPage",element_type:"button"}}return(0,re.jsx)(po,(0,K.A)((0,K.A)({trackingAction:s||"unknown_billing_action",ctaText:t||"Unknown Button",trackingContext:l},r),{},{children:n}))};class vo extends X.H{getBaseURL(){return"/credits"}addBonusCredits(e,s,t){return this.axios.post("/add-bonus-credits",{user_id:e,num_messages:s,reason:t})}createCouponCode(e,s,t,a){return this.axios.post("/create-coupon-code",{code:e,num_messages:s,max_number_of_people:t,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,s){return this.axios.delete("/".concat(e,"/bonus-credits/").concat(s))}}const bo=new vo;var jo=t(16859),yo=t(34799);function No(){const{toast:e}=nn(),{user:s}=oe(),{activeWorkspace:t}=ge(),[a,n]=(0,H.useState)(null),[r,l]=(0,H.useState)(!0),[i,o]=(0,H.useState)(null);if((0,H.useEffect)(()=>{(async()=>{if(null!=t&&t.id)try{l(!0),o(null);const e=await xe.getMySeatInfo(t.id);n(e)}catch(s){o(s),e({variant:"destructive",title:"Error",description:"Failed to load workspace billing information"})}finally{l(!1)}})()},[null==t?void 0:t.id,e]),r)return(0,re.jsx)("div",{className:"flex items-center justify-center py-8",children:(0,re.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,re.jsx)(us,{className:"border-red-200 bg-red-50",children:(0,re.jsx)(hs,{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,re.jsxs)("div",{className:"space-y-6",children:["assigned"===(null==c?void 0:c.status)?(0,re.jsx)(it,{className:"border-slate-200",children:(0,re.jsx)(mt,{className:"pt-6 space-y-4",children:(0,re.jsxs)("div",{children:[(0,re.jsxs)("h2",{className:"text-2xl font-semibold text-slate-900 mb-3",children:[c.seat_type," Plan",(0,re.jsx)(Is,{children:(0,re.jsxs)(Ts,{children:[(0,re.jsx)(Ps,{asChild:!0,children:(0,re.jsx)(jo.A,{className:"h-4 w-4 text-slate-400 hover:text-slate-600 ml-2 inline"})}),(0,re.jsx)(Ls,{children:(0,re.jsxs)("p",{children:["Seat #",c.seat_id]})})]})})]}),(0,re.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,re.jsxs)("div",{className:"space-y-2",children:[u.filter(e=>"owner"===e.role).map((e,s)=>(0,re.jsxs)("p",{className:"text-sm text-slate-600",children:[(0,re.jsx)("span",{className:"font-medium",children:"Workspace owner:"})," ",e.email]},s)),u.filter(e=>"admin"===e.role).map((e,s)=>(0,re.jsxs)("p",{className:"text-sm text-slate-600",children:[(0,re.jsx)("span",{className:"font-medium",children:"Workspace admin:"})," ",e.email]},s))]})]})})}):(0,re.jsx)(it,{className:"border-slate-200",children:(0,re.jsx)(mt,{className:"pt-6 space-y-4",children:(0,re.jsxs)("div",{children:[(0,re.jsx)("h2",{className:"text-2xl font-semibold text-slate-900 mb-3",children:"No Seat Assigned"}),(0,re.jsxs)("p",{className:"text-slate-700 mb-4",children:["You don't currently have a seat plan assigned in this workspace. To get access, please contact your workspace ",u.some(e=>"owner"===e.role)?"owner":"administrator","."]}),(0,re.jsxs)("div",{className:"space-y-2",children:[u.filter(e=>"owner"===e.role).map((e,s)=>(0,re.jsxs)("p",{className:"text-sm text-slate-600",children:[(0,re.jsx)("span",{className:"font-medium",children:"Workspace owner:"})," ",e.email]},s)),u.filter(e=>"admin"===e.role).map((e,s)=>(0,re.jsxs)("p",{className:"text-sm text-slate-600",children:[(0,re.jsx)("span",{className:"font-medium",children:"Workspace admin:"})," ",e.email]},s))]})]})})}),m&&(0,re.jsxs)(us,{className:"bg-teal-50 border-teal-200",children:[(0,re.jsx)(yo.A,{className:"h-4 w-4"}),(0,re.jsxs)(hs,{className:"text-teal-800",children:[(0,re.jsx)("strong",{children:"Administrator Access:"})," Visit the"," ",(0,re.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 wo=t(15255);const _o="GTM-5WLCSX6J",ko=function(e){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};window.dataLayer=window.dataLayer||[],window.dataLayer.push((0,K.A)({event:e,event_id:(0,wo.A)().toString()},s))};function Ao(){const e=(0,Z.zy)();return(0,H.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(_o,"');\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,H.useEffect)(()=>{ko("pageview",{page_path:e.pathname})},[e]),null}var So=t(90386),Co=t.n(So);function Eo(){return(0,re.jsxs)("div",{className:"bg-white rounded-[20px] p-6 flex flex-col h-[480px] border-2 border-[#E9E9E9] animate-pulse",children:[(0,re.jsxs)("div",{className:"mb-5",children:[(0,re.jsxs)("div",{className:"flex items-center justify-between mb-3",children:[(0,re.jsx)("div",{className:"h-5 bg-gray-200 rounded w-16"}),(0,re.jsx)("div",{className:"h-6 bg-gray-200 rounded w-20"})]}),(0,re.jsxs)("div",{className:"flex items-end mb-2",children:[(0,re.jsx)("div",{className:"h-8 bg-gray-200 rounded w-12"}),(0,re.jsx)("div",{className:"h-6 bg-gray-200 rounded w-16 ml-2"})]})]}),(0,re.jsx)("div",{className:"mb-4",children:(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsx)("div",{className:"h-4 bg-gray-200 rounded w-32"}),(0,re.jsx)("div",{className:"h-4 bg-gray-200 rounded w-28"})]})}),(0,re.jsx)("div",{className:"mb-4",children:(0,re.jsx)("div",{className:"h-10 bg-gray-200 rounded-[8px] w-full"})}),(0,re.jsxs)("div",{className:"space-y-2 flex-grow",children:[(0,re.jsx)("div",{className:"h-3 bg-gray-200 rounded w-full"}),(0,re.jsx)("div",{className:"h-3 bg-gray-200 rounded w-4/5"}),(0,re.jsx)("div",{className:"h-3 bg-gray-200 rounded w-3/4"}),(0,re.jsx)("div",{className:"h-3 bg-gray-200 rounded w-full"}),(0,re.jsx)("div",{className:"h-3 bg-gray-200 rounded w-2/3"}),(0,re.jsx)("div",{className:"h-3 bg-gray-200 rounded w-4/5"}),(0,re.jsx)("div",{className:"h-3 bg-gray-200 rounded w-1/2"})]})]})}const Io=e=>{let{text:s,variant:t="default",disabled:a=!1,showX:n=!1,showGift:r=!1}=e;return(0,re.jsxs)("div",{className:"flex items-center text-sm ".concat(a?"text-gray-400":"text-gray-600"),children:[n?(0,re.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,re.jsx)("path",{d:"M18 6 6 18"}),(0,re.jsx)("path",{d:"m6 6 12 12"})]}):r?(0,re.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,re.jsx)("rect",{x:"3",y:"8",width:"18",height:"4",rx:"1"}),(0,re.jsx)("path",{d:"M12 8v13"}),(0,re.jsx)("path",{d:"M19 12v7a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2v-7"}),(0,re.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,re.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,re.jsx)("path",{d:"M20 6L9 17l-5-5"})}),(0,re.jsx)("span",{className:"text-left font-light base44-font ".concat(a?"text-gray-400":"text-black"),children:s})]})};function To(e,s){let t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};try{var a;Ie("Billing - Click",(0,K.A)({action:s},t)),We({user_id:null!==(a=null==e?void 0:e.user_id)&&void 0!==a?a:null},(0,K.A)({cta:s,origin:t.origin||"BillingPage",target_route:"/billing"},t))}catch(n){}}const Po=e=>{var s,t,a,n,r;let{planType:l,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,H.useState)(!1),[j,y]=(0,H.useState)(!1),[N,w]=(0,H.useState)("elite"),[_,k]=(0,H.useState)(!1),[A,S]=(0,H.useState)(!1),C="elite"===l,E=(()=>{if(!C)return i;const e="".concat(N,"_").concat(f),s=o.find(s=>{let[t]=s;return t===e});return s?s[1]:i})(),I=(null==E||null===(s=E.metadata)||void 0===s?void 0:s.monthly_message_limit)||0,T=(null==E||null===(t=E.metadata)||void 0===t?void 0:t.monthly_integration_credits)||0,P=Bi((null==E?void 0:E.nickname)||""),L=C?N:l,O=("active"===(null==d?void 0:d.subscription_status)||"past_due"===(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,s){const t=["free","starter","starter_yearly","builder","builder_yearly","pro","pro_yearly","elite","elite_yearly","elite_2","elite_2_yearly","elite_3","elite_3_yearly"],a=t.indexOf((null==e?void 0:e.toLowerCase())||""),n=t.indexOf((null==s?void 0:s.toLowerCase())||"");return n>a&&-1!==a&&-1!==n}(c,L),D=function(e,s){const t=["free","starter","starter_yearly","builder","builder_yearly","pro","pro_yearly","elite","elite_yearly","elite_2","elite_2_yearly","elite_3","elite_3_yearly"],a=t.indexOf((null==e?void 0:e.toLowerCase())||""),n=t.indexOf((null==s?void 0:s.toLowerCase())||"");return n{var e,s,t;if(!o)return(null==E||null===(e=E.metadata)||void 0===e?void 0:e.features)||"";const a=["starter","builder","pro"];let n=Mi(L);const r=n.startsWith("elite");r&&(n="pro");const l=a.indexOf(n);if(-1===l)return(null==E||null===(s=E.metadata)||void 0===s?void 0:s.features)||"";let i=[];for(let m=0;m<=l;m++){var c,d;const e=a[m],s="".concat(e,"_").concat(f),t=o.find(e=>{let[t,a]=e;return t===s});if(t&&null!==(c=t[1])&&void 0!==c&&null!==(d=c.metadata)&&void 0!==d&&d.features){const e=t[1].metadata.features.split(",").map(e=>e.trim()).filter(e=>e.length>0);i=[...i,...e]}}if(r&&null!=E&&null!==(t=E.metadata)&&void 0!==t&&t.features){const e=E.metadata.features.split(",").map(e=>e.trim()).filter(e=>e.length>0);i=[...i,...e]}return i.filter((e,s,t)=>s===t.findIndex(s=>s.toLowerCase()===e.toLowerCase())).join(",")})(),U=p?"Processing...":g?"Not Available":O?"Manage Payments":D?"Downgrade to ".concat(P):R&&!M?"Upgrade to ".concat(P):"Subscribe to ".concat(P),z=p||g,q=(0,H.useCallback)(()=>{if(!C)return[];return["elite","elite_2","elite_3"].map(e=>({value:e,label:"elite"===e?"Elite":"elite_2"===e?"Elite 2":"Elite 3"}))},[C]),W=(0,H.useCallback)(()=>{const e=q();if(!c||"free"===c.toLowerCase())return e;return c&&!Di(c)?e.filter(e=>function(e,s){if(!e||"free"===e.toLowerCase())return!0;if(Di(e))return!0;const t=["starter","builder","pro","elite","elite_2","elite_3"],a=Mi(e),n=Mi(s),r=t.indexOf(a);return t.indexOf(n)>=r}(c,Fi(e.value))):e},[c,q]);(0,H.useEffect)(()=>{if(C){const e=W();e.length>0&&!e.find(e=>e.value===N)&&w(e[0].value)}},[c,C]);const V=E.unit_amount?"month"===(null===(r=E.recurring)||void 0===r?void 0:r.interval)?(E.unit_amount/100).toFixed(0):(E.unit_amount/100/12).toFixed(0):"0",Y=(()=>{if(!F||!o)return null;const e=Fi(Mi(c)),s=o.find(s=>{let[t]=s;return t===e});return s?s[1]:null})(),G=null!=Y&&Y.unit_amount?(Y.unit_amount/100/12).toFixed(0):"0";return(0,re.jsx)(re.Fragment,{children:(0,re.jsxs)("div",{className:"relative",children:[O&&(0,re.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,re.jsxs)("div",{className:"bg-white rounded-[20px] p-6 flex flex-col transition-all duration-300 hover:shadow-xl h-[480px] ".concat(O?"border-2 border-slate-700":"pro"!==l||g?"border-2 border-[#E9E9E9]":"border-2 border-orange-300 mb-2"),children:[(0,re.jsxs)("div",{className:"".concat(C?"mb-2":"mb-5"),children:[(0,re.jsxs)("div",{className:"flex items-center justify-between mb-3",children:[(0,re.jsx)("div",{className:"flex items-center gap-2",children:(0,re.jsx)("span",{className:"text-[18px] font-[400] ".concat(g?"text-gray-400":"text-gray-900"),children:P})}),"pro"===l&&!g&&(0,re.jsx)("span",{className:"px-2 py-1 text-sm font-medium bg-[#FFE5DA] text-[#F16727] rounded-[6px]",children:"Recommended"})]}),(0,re.jsxs)("div",{className:"flex items-end mb-2",children:[(0,re.jsx)("span",{className:"text-3xl font-medium ".concat(g?"text-gray-400":"text-gray-900"),children:"$"}),(0,re.jsx)("span",{className:"text-3xl font-medium ".concat(g?"text-gray-400":"text-gray-900"),children:V}),(0,re.jsx)("span",{className:"font-thin ml-1 mb-1 text-[#C1C1C1] text-2xl",children:"/"}),(0,re.jsx)("span",{className:"font-normal mb-1 text-[#C1C1C1] text-[14px]",children:"mo"})]})]}),(0,re.jsx)("div",{className:"-mt-1 mb-2",children:C&&!g?(0,re.jsxs)(In,{value:N,onValueChange:e=>{To({user_id:null},"elite_tier_select",{origin:"PlanCard",billing_period:f,current_tier:c,selected_plan_type:l,selected_elite_tier:e,element_type:"dropdown"}),w(e)},children:[(0,re.jsx)(Pn,{advancedDropdown:!0,className:"w-full h-auto p-2 bg-white border border-gray-200",children:(0,re.jsx)("div",{className:"w-full text-left",children:(0,re.jsxs)("div",{className:"w-full flex flex-col gap-1",children:[(0,re.jsxs)("div",{className:"text-sm text-gray-900",children:[(0,re.jsx)("span",{className:"font-[500] inline-block min-w-[30px]",children:Ri(I)}),(0,re.jsx)("span",{className:"font-[400] text-[#5F5F5F]",children:"Monthly credits"})]}),(0,re.jsxs)("div",{className:"text-sm text-gray-900",children:[(0,re.jsx)("span",{className:"font-[500] inline-block min-w-[30px]",children:Ri(T)}),(0,re.jsx)("span",{className:"font-[400] text-[#5F5F5F]",children:"Integration credits"})]})]})})}),(0,re.jsx)(Rn,{className:"w-[calc(100%-1rem)] max-w-[320px] z-50 p-1.5",sideOffset:4,children:W().map(e=>{var s,t;const a="".concat(e.value,"_").concat(f),n=o.find(e=>{let[s]=e;return s===a}),r=n?n[1]:null,l=(null==r||null===(s=r.metadata)||void 0===s?void 0:s.monthly_message_limit)||0,i=(null==r||null===(t=r.metadata)||void 0===t?void 0:t.monthly_integration_credits)||0;return(0,re.jsx)(Dn,{value:e.value,className:"px-4 py-2 border-b border-gray-100 last:border-b-0",hideCheckIcon:!0,children:(0,re.jsxs)("div",{className:"w-full flex flex-col gap-1",children:[(0,re.jsxs)("div",{className:"text-sm leading-[17px] flex items-center gap-1.5 text-gray-900",children:[(0,re.jsx)("span",{className:"font-bold",children:Ri(l)}),(0,re.jsx)("span",{className:"text-gray-500",children:"monthly credits"})]}),(0,re.jsxs)("div",{className:"text-sm leading-[17px] flex items-center gap-1.5 text-gray-900",children:[(0,re.jsx)("span",{className:"font-bold",children:Ri(i)}),(0,re.jsx)("span",{className:"text-gray-500",children:"integration credits"})]})]})},e.value)})})]}):(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsxs)("div",{className:"text-sm ".concat(g?"text-gray-400":"text-gray-900"),children:[(0,re.jsx)("span",{className:"font-[500] inline-block min-w-[30px]",children:Ri(I)}),(0,re.jsx)("span",{className:"font-[400] text-[#5F5F5F]",children:"Monthly credits"})]}),(0,re.jsxs)("div",{className:"text-sm ".concat(g?"text-gray-400":"text-gray-900"),children:[(0,re.jsx)("span",{className:"font-[500] inline-block min-w-[30px]",children:Ri(T)}),(0,re.jsx)("span",{className:"font-[400] text-[#5F5F5F]",children:"Integration credits"})]})]})}),(0,re.jsx)("div",{className:"mb-4",children:(0,re.jsx)(fo,{billingAction:O?"manage_payments_click":D?"downgrade_click":R&&!M?"upgrade_click":"subscribe_click",ctaText:U,billingContext:{origin:"PlanCard",billing_period:f,current_tier:c,selected_plan_type:l,selected_elite_tier:C?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:M,is_current_plan:O,can_upgrade:R,is_downgrade:D,is_elite_plan:C,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:z,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&&!z)if(O)F?k(!0):h();else if(D)y(!0);else if(R&&!M)if(F){x(C?N:l)}else b(!0);else{u(C?N:l)}},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"===l?"bg-[#F97316] hover:bg-[#000000] text-white":"bg-white border border-gray-300 hover:bg-[#F97316] text-black hover:text-white hover:border-white"),disabled:z,children:U})}),(0,re.jsx)("div",{className:"space-y-1 flex-grow",children:null==B?void 0:B.split(",").map((e,s)=>(0,re.jsx)(Io,{text:e.trim(),disabled:g,showGift:!1},s))})]}),(0,re.jsx)(to,{open:v,onOpenChange:b,children:(0,re.jsxs)(lo,{className:"sm:max-w-md",children:[(0,re.jsxs)(io,{children:[(0,re.jsx)(co,{children:"Confirm Subscription Upgrade"}),(0,re.jsxs)(mo,{children:["You are about to upgrade to the ",P," plan for $",V,"/mo. Your subscription will be updated immediately and you'll be charged a prorated amount for the remainder of your billing cycle."]})]}),(0,re.jsxs)(oo,{className:"sm:justify-between",children:[(0,re.jsx)(fo,{billingAction:"dialog_cancel",ctaText:"Cancel",billingContext:{origin:"PlanCard",billing_period:f,current_tier:c,selected_plan_type:l,dialog_type:"upgrade"},onClick:()=>b(!1),variant:"outline",className:"text-sm",children:"Cancel"}),(0,re.jsx)(fo,{billingAction:"dialog_confirm",ctaText:p?"Processing...":"Confirm Upgrade",billingContext:{origin:"PlanCard",billing_period:f,current_tier:c,selected_plan_type:l,selected_elite_tier:C?N:void 0,dialog_type:"upgrade",price_id:E.id,target_route:"/stripe-checkout",is_monthly_user:F,is_free_user:M,can_upgrade:R,is_elite_plan:C,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&&!M){x(C?N:l)}else x(E.id)},disabled:p,className:"text-sm bg-teal-600 hover:bg-teal-700",children:p?"Processing...":"Confirm Upgrade"})]})]})}),(0,re.jsx)(to,{open:j,onOpenChange:y,children:(0,re.jsxs)(lo,{className:"sm:max-w-md",children:[(0,re.jsxs)(io,{children:[(0,re.jsx)(co,{children:"Confirm Subscription Downgrade"}),(0,re.jsxs)(mo,{children:["You are about to downgrade to the ",P," plan for $",V,"/mo. This change will take effect at the end of your current billing cycle."]})]}),(0,re.jsxs)(oo,{className:"sm:justify-between",children:[(0,re.jsx)(fo,{billingAction:"dialog_cancel",ctaText:"Cancel",billingContext:{origin:"PlanCard",billing_period:f,current_tier:c,selected_plan_type:l,dialog_type:"downgrade"},onClick:()=>y(!1),variant:"outline",className:"text-sm",children:"Cancel"}),(0,re.jsx)(fo,{billingAction:"dialog_confirm",ctaText:"Confirm Downgrade",billingContext:{origin:"PlanCard",billing_period:f,current_tier:c,selected_plan_type:l,selected_elite_tier:C?N:void 0,dialog_type:"downgrade",price_id:E.id,target_route:"/stripe-checkout",is_monthly_user:F,is_downgrade:D,is_elite_plan:C,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,re.jsx)(to,{open:_,onOpenChange:k,children:(0,re.jsxs)(lo,{className:"sm:max-w-md",children:[(0,re.jsxs)(io,{children:[(0,re.jsx)(co,{children:"Manage Your Subscription"}),(0,re.jsxs)(mo,{children:["Choose how you'd like to manage your ",P," subscription."]})]}),(0,re.jsxs)("div",{className:"py-4 space-y-3",children:[(0,re.jsx)(fo,{billingAction:"upgrade_to_yearly_click",ctaText:"Upgrade to Yearly & Save",billingContext:{origin:"PlanCard",billing_period:f,current_tier:c,selected_plan_type:l,selected_elite_tier:C?N:void 0,dialog_type:"upgrade_to_yearly",target_route:"/billing-period-selector",is_monthly_user:F,is_current_plan:O,is_elite_plan:C,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),S(!0)},className:"w-full bg-teal-600 hover:bg-teal-700 text-white p-4 h-auto",disabled:!Y,children:(0,re.jsxs)("div",{className:"text-left w-full",children:[(0,re.jsx)("div",{className:"font-medium",children:"Upgrade to Yearly"}),(0,re.jsx)("div",{className:"text-sm opacity-90 mt-1",children:"Save money and get a free domain + 25 credits to share!"})]})}),(0,re.jsx)(fo,{billingAction:"manage_payments_click",ctaText:"Manage Payments",billingContext:{origin:"PlanCard",billing_period:f,current_tier:c,selected_plan_type:l,selected_elite_tier:C?N:void 0,dialog_type:"manage_payments",target_route:"/stripe-portal",is_monthly_user:F,is_current_plan:O,is_elite_plan:C,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,re.jsxs)("div",{className:"text-left w-full",children:[(0,re.jsx)("div",{className:"font-medium",children:"Manage Payments"}),(0,re.jsx)("div",{className:"text-sm text-gray-600 mt-1",children:"Update payment method, view invoices, and more"})]})})]})]})}),(0,re.jsx)(to,{open:A,onOpenChange:S,children:(0,re.jsxs)(lo,{className:"sm:max-w-md",children:[(0,re.jsxs)(io,{children:[(0,re.jsx)(co,{children:"Confirm Subscription Upgrade"}),(0,re.jsxs)(mo,{children:["You are about to upgrade to the ",Bi((null==Y?void 0:Y.nickname)||"")," yearly plan for $",G,"/mo. Your subscription will be updated immediately and you'll be charged a prorated amount for the remainder of your billing cycle."]})]}),(0,re.jsx)("div",{className:"py-4",children:(0,re.jsxs)("div",{className:"bg-green-50 border border-green-200 rounded-lg p-4",children:[(0,re.jsx)("div",{className:"text-green-800 font-medium mb-2",children:"\u{1f381} Yearly Benefits"}),(0,re.jsxs)("ul",{className:"text-sm text-green-700 space-y-1",children:[(0,re.jsx)("li",{children:"\u2022 Get a free domain for a year"}),(0,re.jsx)("li",{children:"\u2022 25 credits to share with friends"}),(0,re.jsx)("li",{children:"\u2022 Better value with yearly pricing"})]})]})}),(0,re.jsxs)(oo,{className:"sm:justify-between",children:[(0,re.jsx)(fo,{billingAction:"dialog_cancel",ctaText:"Cancel",billingContext:{origin:"PlanCard",billing_period:f,current_tier:c,selected_plan_type:l,dialog_type:"upgrade_to_yearly"},onClick:()=>S(!1),variant:"outline",className:"text-sm",children:"Cancel"}),(0,re.jsx)(fo,{billingAction:"dialog_confirm",ctaText:"Confirm Upgrade",billingContext:{origin:"PlanCard",billing_period:f,current_tier:c,selected_plan_type:l,selected_elite_tier:C?N:void 0,dialog_type:"upgrade_to_yearly",price_id:(null==Y?void 0:Y.id)||null,target_route:"/stripe-checkout",is_monthly_user:F,is_current_plan:O,is_elite_plan:C,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==Y?void 0:Y.unit_amount)||0},onClick:()=>{S(!1),Y&&x(Y.id)},disabled:p,className:"text-sm bg-teal-600 hover:bg-teal-700",children:p?"Processing...":"Confirm Upgrade"})]})]})})]})})},Lo=["className"],Oo=["className"],Ro=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,Lo);return(0,re.jsx)(wt.bL,(0,K.A)((0,K.A)({className:is("grid gap-2",t)},a),{},{ref:s}))});Ro.displayName=wt.bL.displayName;const Do=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,Oo);return(0,re.jsx)(wt.q7,(0,K.A)((0,K.A)({ref:s,className:is("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",t)},a),{},{children:(0,re.jsx)(wt.C1,{className:"flex items-center justify-center",children:(0,re.jsx)(_t.A,{className:"h-2.5 w-2.5 fill-current text-current"})})}))});Do.displayName=wt.q7.displayName;var Mo=t(24082);const Fo=Mo.bL,Bo=H.forwardRef((e,s)=>{let t=Object.assign({},((0,Ja.A)(e),e));return(0,re.jsx)(Mo.R6,(0,K.A)({ref:s},t))});Bo.displayName=Mo.R6.displayName;const Uo=H.forwardRef((e,s)=>{let t=Object.assign({},((0,Ja.A)(e),e));return(0,re.jsx)(Mo.Ke,(0,K.A)({ref:s},t))});Uo.displayName=Mo.Ke.displayName;const zo=e=>{var s,t;let{period:a,plan:n,monthlyPlan:r,features:l,isSelected:i,isExpanded:o,onSelect:c,onExpansionToggle:d,onYearlySelect:m,disabled:u=!1,userId:x}=e;const h=(null==n||null===(s=n.metadata)||void 0===s?void 0:s.monthly_message_limit)||0,p=(null==n||null===(t=n.metadata)||void 0===t?void 0:t.monthly_integration_credits)||0,g=(null==n?void 0:n.nickname)||"",f=Bi(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==r||!r.unit_amount||null==n||!n.unit_amount)return 0;const e=12*r.unit_amount-n.unit_amount;return Math.round(e/100)})();return(0,re.jsx)(Fo,{open:o,onOpenChange:()=>{To({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:()=>{To({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,re.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,re.jsxs)("div",{className:"flex items-center justify-between p-4 sm:p-6",children:[(0,re.jsxs)("div",{className:"flex items-center space-x-3 sm:space-x-4 flex-1 cursor-pointer",children:[(0,re.jsx)(Do,{value:a,id:a,className:i?"border-black text-black":""}),(0,re.jsx)("div",{className:"text-left flex-1 min-w-0",children:(0,re.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,re.jsx)("span",{className:"font-bold",children:y}),(0,re.jsx)("span",{className:"hidden sm:block h-px w-4 bg-gray-300"}),(0,re.jsxs)("span",{className:"font-normal text-sm sm:text-base",children:["$",b,j]})]})})]}),(0,re.jsxs)("div",{className:"flex items-center space-x-2 sm:space-x-3 flex-shrink-0",children:["yearly"===a&&N>0&&(0,re.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,re.jsx)(Bo,{asChild:!0,children:(0,re.jsx)("button",{className:"p-1 hover:bg-gray-100 rounded",children:o?(0,re.jsx)(Tt.A,{className:"h-5 w-5 text-gray-400"}):(0,re.jsx)(It.A,{className:"h-5 w-5 text-gray-400"})})})]})]}),(0,re.jsx)(Uo,{children:(0,re.jsxs)("div",{className:"px-4 sm:px-6 pb-4 sm:pb-6",children:[(0,re.jsx)("div",{className:"border-t border-gray-200"}),(0,re.jsx)("div",{className:"mt-4 mb-6",children:(0,re.jsxs)("div",{className:"flex gap-3",children:[(0,re.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,re.jsx)("span",{className:"font-bold",children:Ri(h)}),(0,re.jsx)("span",{className:"text-black",children:"Monthly credits"})]}),(0,re.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,re.jsx)("span",{className:"font-semibold",children:Ri(p)}),(0,re.jsx)("span",{className:"text-black",children:"Integration credits"})]})]})}),!v&&(0,re.jsxs)("div",{className:"mb-4 ".concat("monthly"===a?"bg-slate-50 p-3 sm:p-4 rounded-lg border border-gray-200":""),children:[(0,re.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,re.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,s)=>(0,re.jsx)(Io,{text:e,disabled:u,showX:"monthly"===a,showGift:"yearly"===a},"additional-".concat(s)))}),"monthly"===a&&(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)("div",{className:"border-t border-gray-200 mt-4"}),(0,re.jsxs)("p",{className:"mt-4 text-sm",children:["Choose a ",(0,re.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"]})]})]})]})})]})})},qo=e=>{var s;let{selectedPlanType:t,stats:a,onSubscribe:n,onBack:r,selectedEliteTier:l,isUpgradeFlow:i=!1,onUpgrade:o,userId:c}=e;const[d,m]=(0,H.useState)("yearly"),[u,x]=(0,H.useState)("yearly"),[h,p]=(0,H.useState)(!1),[g,f]=(0,H.useState)(!1),v=l||t,b=a.pricing.monthly[v],j=a.pricing.yearly[v];if(!b||!j)return(0,re.jsxs)("div",{className:"text-center py-8 px-4",children:[(0,re.jsx)("p",{className:"text-gray-500",children:"Plan not found. Please try again."}),(0,re.jsx)(fo,{billingAction:"back_to_plans",ctaText:"Back",billingContext:{origin:"BillingPeriodSelector",selected_plan_type:v},onClick:r,variant:"outline",className:"mt-4",children:"Go Back"})]});const y=e=>{var s;return(null==e||null===(s=e.metadata)||void 0===s?void 0:s.features)||""},N=e=>{m(e),x(e),To({user_id:c},"select_period",{origin:"BillingPeriodSelector",billing_period:e,selected_plan_type:v})},w=e=>{x(u===e?null:e)};return(0,re.jsxs)("div",{className:"max-w-6xl mx-auto px-4 sm:px-6 lg:px-8",children:[(0,re.jsx)("div",{className:"rounded-lg",children:(0,re.jsxs)(Ro,{value:d,onValueChange:N,className:"gap-0",children:[(0,re.jsx)(zo,{period:"yearly",plan:j,monthlyPlan:b,features:y(j),isSelected:"yearly"===d,isExpanded:"yearly"===u,onSelect:()=>N("yearly"),onExpansionToggle:()=>w("yearly"),userId:c}),(0,re.jsx)(zo,{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,re.jsx)("div",{className:"mt-6 flex justify-center sm:justify-end px-4 sm:px-0",children:(0,re.jsx)(fo,{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:l,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,re.jsx)(to,{open:h,onOpenChange:p,children:(0,re.jsxs)(lo,{className:"sm:max-w-md",children:[(0,re.jsxs)(io,{children:[(0,re.jsx)(co,{children:"Confirm Subscription Upgrade"}),(0,re.jsxs)(mo,{children:["You are about to upgrade to the ",Bi((null===(s="yearly"===d?j:b)||void 0===s?void 0:s.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,re.jsxs)(oo,{className:"sm:justify-between",children:[(0,re.jsx)(fo,{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,re.jsx)(fo,{billingAction:"dialog_confirm",ctaText:"Confirm Upgrade",billingContext:{origin:"BillingPeriodSelector",billing_period:d,selected_plan_type:v,selected_elite_tier:l,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},Wo=e=>{let{isOpen:s,onClose:t}=e;const a=(0,H.useRef)(null),n=(0,H.useRef)(null);(0,H.useEffect)(()=>{if(s){if(window.hbspt)r();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=()=>{r()}}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()}}},[s]);const r=()=>{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 s=document.getElementById("hubspot-form-container");s&&(s.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 s?(0,re.jsx)("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 p-4",children:(0,re.jsxs)("div",{ref:a,className:"bg-white rounded-xl shadow-xl max-w-lg w-full max-h-[90vh] overflow-y-auto",children:[(0,re.jsxs)("div",{className:"flex items-center justify-between p-6 border-b border-slate-100",children:[(0,re.jsxs)("div",{children:[(0,re.jsx)("h2",{className:"text-2xl font-bold text-slate-900",children:"Let's talk"}),(0,re.jsx)("p",{className:"text-slate-600 mt-1",children:"Connect with our team to see how Base44 can help your organization."})]}),(0,re.jsx)(Hs,{variant:"ghost",size:"sm",onClick:t,className:"h-8 w-8 p-0 hover:bg-slate-100 rounded-full",children:(0,re.jsx)(zs.A,{className:"h-4 w-4"})})]}),(0,re.jsx)("div",{className:"p-6",children:(0,re.jsx)("div",{id:"hubspot-form-container",ref:n})})]})}):null};var Vo=t(55510),Yo=t(63997),Ho=t(16243);const Go=e=>{let{icon:s,title:t,description:a}=e;return(0,re.jsxs)("div",{className:"flex flex-col items-start gap-2",children:[(0,re.jsx)("div",{className:"w-5 h-5 flex items-center justify-center flex-shrink-0",children:s}),(0,re.jsxs)("div",{children:[(0,re.jsx)("h4",{className:"text-white font-bold mb-1 text-sm",children:t}),(0,re.jsx)("p",{className:"text-white font-normal text-sm",children:a})]})]})},$o=()=>{const[e,s]=(0,H.useState)(!1);return(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)("div",{className:"mt-8 max-w-full mx-auto px-4",children:(0,re.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,re.jsxs)("div",{className:"flex flex-col lg:flex-row items-center gap-14",children:[(0,re.jsxs)("div",{className:"flex-[2] flex flex-col justify-center items-start",children:[(0,re.jsx)("h3",{className:"text-[24px] font-bold mb-2",children:"Base44 Enterprise Capabilities"}),(0,re.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,re.jsx)(fo,{billingAction:"enterprise_contact",ctaText:"Contact Us",billingContext:{origin:"EnterpriseCard"},onClick:()=>s(!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,re.jsx)("div",{className:"flex-[3]",children:(0,re.jsxs)("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-14 w-full",children:[(0,re.jsx)(Go,{icon:(0,re.jsx)($r.A,{className:"w-5 h-5 text-orange-400"}),title:"Tailored onboarding at scale",description:"Custom training designed for your team's skills, roles, and goals so everyone is ready from day one."}),(0,re.jsx)(Go,{icon:(0,re.jsx)(Vo.A,{className:"w-5 h-5 text-orange-400"}),title:"Dedicated account manager",description:"A single point of contact offering guidance and support to help you achieve your objectives faster."}),(0,re.jsx)(Go,{icon:(0,re.jsx)(Yo.A,{className:"w-5 h-5 text-orange-400"}),title:"Priority support, guaranteed",description:"Direct access to a support channel and guaranteed response times for every issue that arises."}),(0,re.jsx)(Go,{icon:(0,re.jsx)(Ho.A,{className:"w-5 h-5 text-orange-400"}),title:"Enterprise security and compliance",description:"Easily manage access, connect with your systems, and meet all necessary regulatory requirements."})]})})]})})}),(0,re.jsx)(Wo,{isOpen:e,onClose:()=>s(!1)})]})};var Jo=t(37358),Zo=t(53270);const Ko=()=>(0,re.jsx)("div",{className:"mt-6 mb-2 flex items-center justify-center",children:(0,re.jsxs)("div",{className:"flex items-center justify-center gap-6 flex-wrap",children:[(0,re.jsx)("span",{style:{color:"#000624"},className:"text-sm font-normal leading-normal",children:"Base44 benefits:"}),(0,re.jsxs)("div",{className:"flex items-center gap-2",children:[(0,re.jsx)(Jo.A,{size:16,style:{color:"#000624"}}),(0,re.jsx)("span",{style:{color:"#000624"},className:"text-sm font-medium leading-normal",children:"Responsive visual editor"})]}),(0,re.jsxs)("div",{className:"flex items-center gap-2",children:[(0,re.jsx)(Zo.A,{size:16,style:{color:"#000624"}}),(0,re.jsx)("span",{style:{color:"#000624"},className:"text-sm font-medium leading-normal",children:"Built-in backend"})]}),(0,re.jsxs)("div",{className:"flex items-center gap-2",children:[(0,re.jsx)(Gr.A,{size:16,style:{color:"#000624"}}),(0,re.jsx)("span",{style:{color:"#000624"},className:"text-sm font-medium leading-normal",children:"User management"})]})]})});var Xo=t(1323);const Qo=e=>{let{type:s,title:t,message:a,subMessage:n,buttonText:r,loadingText:l,onButtonClick:i,handleManageSubscription:o,isLoading:c}=e;const d="cancellation"===s?{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,re.jsx)(us,{className:"mb-3 ".concat(d.container," rounded-xl border p-4"),children:(0,re.jsxs)("div",{className:"flex items-start gap-3",children:[(0,re.jsx)(Xo._TA,{className:"h-4 w-4 ".concat(d.icon," mt-0.5 flex-shrink-0")}),(0,re.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,re.jsx)(xs,{className:"".concat(d.title," text-sm mb-1 leading-tight"),children:t}),(0,re.jsxs)(hs,{className:"".concat(d.description," text-sm leading-relaxed"),children:[(0,re.jsx)("div",{className:"mb-1",children:a}),n&&(0,re.jsx)("div",{className:"text-xs ".concat(d.subText," leading-relaxed"),children:n})]})]}),r&&(0,re.jsx)("div",{className:"flex-shrink-0",children:(0,re.jsx)(fo,{billingAction:"subscription_notice_action",ctaText:r,billingContext:{notice_type:s},variant:"outline",size:"sm",className:"text-xs px-3 py-1.5 h-auto rounded-lg ".concat(d.button),onClick:()=>{"cancellation"===s?null==o||o():null==i||i()},disabled:c,children:c?l:r})})]})})};var ec=t(97202);const sc=()=>(0,re.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,re.jsx)(Eo,{}),(0,re.jsx)(Eo,{}),(0,re.jsx)(Eo,{}),(0,re.jsx)(Eo,{})]}),tc=()=>{var e;const{toast:s}=nn(),{user:t}=oe(),{activeWorkspace:a}=ge(),n=(0,H.useRef)(null),[r,l]=(0,H.useState)("billing"),[i,o]=(0,H.useState)("yearly"),[c,d]=(0,H.useState)(""),[m,u]=(0,H.useState)(!1),[x,h]=(0,H.useState)(null),[p,g]=(0,H.useState)(null),[f,v]=(0,H.useState)(!0),[b,j]=(0,H.useState)(!1),[y,N]=(0,H.useState)(""),[w,_]=(0,H.useState)(""),[k,A]=(0,H.useState)(!1),[S,C]=(0,H.useState)(""),[E,I]=(0,H.useState)(!1),[T,P]=(0,H.useState)(!1),L=a&&!a.is_personal;(0,H.useEffect)(()=>{const e=(null==a?void 0:a.id)||null;null!==n.current&&n.current!==e&&(h(null),g(null),v(!0),l("billing"),o("monthly"),d(""),u(!1),j(!1),N(""),_(""),A(!1)),n.current=e},[null==a?void 0:a.id]),(0,H.useEffect)(()=>{if(L)return;(async()=>{try{v(!0);const[e,s]=await Promise.all([es.default.getCurrentUsage(),es.default.getStats()]);h(e),g(s);const t=e;if(null!=t&&t.tier)if("free"===t.tier.toLowerCase())o("yearly");else{const e=t.tier.toLowerCase().includes("_yearly");o(e?"yearly":"monthly")}}catch(e){}finally{v(!1)}})()},[L]),(0,H.useEffect)(()=>{if(t){"true"===new URLSearchParams(window.location.search).get("success")&&t.email&&(window.rewardful&&window.rewardful("convert",{email:t.email}),Ie("Billing - Purchase",{}),ko("Purchase",{email:(0,So.sha256)(t.email),price:20,user_id:t.id}))}},[t]),(0,H.useEffect)(()=>{t&&!L&&(Ie("Package Picker",{}),ko("package_picker",{user_id:t.id,email:(0,So.sha256)(t.email)}))},[t,L]);const O=async e=>{const a=["starter","builder","pro","elite"].includes(e),n=["elite","elite_2","elite_3"].includes(e);if(a||n)return To({user_id:(null==t?void 0:t.id)||null},"select_plan",{origin:"BillingPage",view:r,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{To({user_id:(null==t?void 0:t.id)||null},"continue_checkout",{origin:"BillingPage",view:r,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}),Ie("Hit Subscribe",{}),ko("checkout_initiated",{email:(0,So.sha256)(t.email),price:20,user_id:t.id});const s=await Ji.createCheckoutSession(e),{sessionId:a}=s,n=null==p?void 0:p.publishable_key;if(!n)throw new Error("Stripe publishable key not available");const l=await(0,ec.loadStripe)(n);await l.redirectToCheckout({sessionId:a})}catch(l){s({variant:"destructive",title:"Error",description:"Failed to create checkout session. Please try again later."})}},R=()=>{To({user_id:(null==t?void 0:t.id)||null},"back_to_plans",{origin:"BillingPage",view:r,is_workspace_context:!!L}),j(!1),N(""),_(""),A(!1)},D=async e=>{try{var a;To({user_id:(null==t?void 0:t.id)||null},"upgrade_click",{origin:"BillingPage",view:r,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 Ji.updateSubscription(e)).subscription)||void 0===a?void 0:a.is_downgrade;s({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(l){var n;s({variant:"destructive",title:"Error",description:(null===(n=l.response)||void 0===n?void 0:n.detail)||"Failed to update subscription. Please try again later."})}},M=async e=>{const s=["elite","elite_2","elite_3"];if((["starter","builder","pro","elite"].includes(e)||s.includes(e))&&"monthly"===i)return To({user_id:(null==t?void 0:t.id)||null},"upgrade_click",{origin:"BillingPage",view:r,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:s.includes(e)?"elite":e,selected_elite_tier:s.includes(e)?e:void 0}),N(s.includes(e)?"elite":e),s.includes(e)?_(e):_(""),A(!0),void j(!0);await D(e)},F=async()=>{try{To({user_id:(null==t?void 0:t.id)||null},"manage_payments_click",{origin:"BillingPage",view:r,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 Ji.createPortalSession();window.open(e.url,"_blank")}catch(e){s({variant:"destructive",title:"Error",description:"Failed to open subscription management. Please try again later."})}},B=null==t?void 0:t.subscription_schedule_id,U=!0===(null==p||null===(e=p.stripe_subscription)||void 0===e?void 0:e.cancel_at_period_end),z=()=>{if(null==p||!p.pricing)return[];const e=[];return Object.entries(p.pricing.monthly).forEach(s=>{let[t,a]=s;e.push(["".concat(t,"_monthly"),a])}),Object.entries(p.pricing.yearly).forEach(s=>{let[t,a]=s;e.push(["".concat(t,"_yearly"),a])}),e};return(0,re.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,re.jsxs)("div",{className:"mb-6 p-4 bg-red-50 border border-red-200 rounded-md text-red-800",children:[(0,re.jsxs)("div",{className:"flex items-center justify-between",children:[(0,re.jsxs)("div",{className:"flex items-center",children:[(0,re.jsx)(Ke.A,{className:"h-5 w-5 mr-2 flex-shrink-0"}),(0,re.jsx)("span",{className:"font-medium",children:"Subscription payment overdue"})]}),(0,re.jsx)(fo,{billingAction:"payment_overdue_update",ctaText:"Update Payment Method",billingContext:{origin:"BillingPage",view:r,is_workspace_context:!!L,notice_type:"overdue",target_route:"/stripe-portal"},onClick:async()=>{try{const e="payment_method_update",s=await Ji.createPortalSession(e);window.location.href=s.url}catch(e){s({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,re.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,re.jsx)("div",{className:"block lg:hidden mb-2",children:(0,re.jsxs)(fo,{billingAction:"back_to_plans",ctaText:"Back to Plans",billingContext:{origin:"BillingPage",view:r,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,re.jsx)(Qt.A,{className:"h-5 w-5"}),(0,re.jsx)("span",{className:"font-base44",children:"Back"})]})}),(0,re.jsx)("div",{className:"flex flex-col items-center text-center mb-6",children:b?(0,re.jsx)(re.Fragment,{children:(0,re.jsxs)("div",{className:"w-full relative",children:[(0,re.jsxs)(fo,{billingAction:"back_to_plans",ctaText:"Back to Plans",billingContext:{origin:"BillingPage",view:r,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,re.jsx)(Qt.A,{className:"h-5 w-5"}),(0,re.jsx)("span",{className:"font-base44",children:"Back"})]}),(0,re.jsxs)("div",{className:"max-w-3xl mx-auto text-center mb-2",children:[(0,re.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,re.jsx)(Ko,{})]})]})}):(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)("h1",{className:"text-3xl md:text-4xl font-normal text-slate-900 base44-font",children:"billing"===r?"Choose the plan that's right for you":"Usage"}),(0,re.jsx)(Ko,{}),"billing"!==r&&(0,re.jsx)("div",{className:"flex justify-center mt-4",children:(0,re.jsxs)(fo,{billingAction:"view_billing_click",ctaText:L?"View Billing":"See Pricing",billingContext:{view:r,is_workspace_context:!!L},onClick:()=>{l("billing")},variant:"ghost",className:"text-sm text-orange-600 hover:text-orange-700 font-medium flex items-center p-0 h-auto",children:[(0,re.jsx)(Ke.A,{size:16}),L?"View Billing":"See Pricing"]})})]})}),L?"billing"===r?(0,re.jsxs)("div",{className:"space-y-6",children:[(0,re.jsx)(No,{}),(0,re.jsx)(xo,{})]}):(0,re.jsx)("div",{className:"space-y-8"}):"billing"===r?(0,re.jsxs)("div",{className:"space-y-8",children:[B&&(0,re.jsx)(Qo,{type:"schedule-change",title:"Pending Subscription Change",message:"You have a subscription change to the ".concat((q=null==t?void 0:t.subscription_schedule_tier,q?q.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 Ji.cancelSchedule(),s({title:"Success",description:"Subscription schedule cancelled successfully"}),I(!1),setTimeout(()=>{window.location.reload()},2e3)}catch(e){s({variant:"destructive",title:"Error",description:"Failed to cancel subscription schedule. Please try again later."}),I(!1)}},handleManageSubscription:F,isLoading:E}),!B&&U&&(0,re.jsx)(Qo,{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==t?void 0:t.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,re.jsx)(sc,{}):b?(0,re.jsx)(re.Fragment,{children:(0,re.jsx)(qo,{selectedPlanType:y,stats:p,onSubscribe:O,onBack:R,selectedEliteTier:w,isUpgradeFlow:k,onUpgrade:D})}):(0,re.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:["starter","builder","pro","elite"].map(e=>{const s=(e=>{if(null==p||!p.pricing)return null;const s=("yearly"===i?p.pricing.yearly:p.pricing.monthly)[e];return s?[e,s]:null})(e);return s?(0,re.jsx)("div",{className:"w-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,re.jsx)(Po,{planType:e,plan:s[1],allPlans:z(),currentTier:(null==x?void 0:x.tier)||"",stats:p,usage:x,onSubscribe:O,onUpgrade:M,onManageSubscription:F,upgrading:!1,billingPeriod:i})},e):null})}),!b&&(0,re.jsx)($o,{}),!f&&!b&&(0,re.jsx)("div",{className:"flex justify-end mt-2",children:(0,re.jsxs)("div",{className:"relative group",children:[(0,re.jsx)(fo,{billingAction:"coupon_open",ctaText:"Have a coupon code?",billingContext:{view:r,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,re.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,re.jsxs)("form",{onSubmit:async e=>{if(e.preventDefault(),c.trim()){u(!0);try{const e=await bo.addCouponCode(c.trim());s({title:"Success",description:"".concat(e.num_messages," credits added to your account!")}),d("")}catch(a){var t;s({variant:"destructive",title:"Error",description:(null===(t=a.response)||void 0===t?void 0:t.detail)||"Failed to apply coupon code. Please try again."})}finally{u(!1)}}},className:"flex gap-2 items-center",children:[(0,re.jsx)(fn,{type:"text",placeholder:"Enter code",value:c,onChange:e=>d(e.target.value),className:"flex-1 text-xs h-7"}),(0,re.jsx)(fo,{billingAction:"coupon_apply",ctaText:"Apply",billingContext:{origin:"BillingPage",view:r,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,re.jsx)(xo,{})]}):(0,re.jsx)("div",{className:"space-y-8"})]});var q},ac=["className","children"],nc=e=>{let{className:s,children:t}=e,a=(0,as.A)(e,ac);return(0,re.jsxs)(ka.Portal,{children:[(0,re.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,re.jsx)(ka.Content,(0,K.A)((0,K.A)({className:is("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",s)},a),{},{children:t}))]})},rc=e=>{let{isOpen:s,onClose:t,onSubscriptionSuccess:a}=e;return(0,re.jsx)(to,{open:s,onOpenChange:t,children:(0,re.jsx)(nc,{className:"bg-white",children:(0,re.jsxs)("div",{className:"h-full flex flex-col",children:[(0,re.jsx)("div",{className:"flex-shrink-0 flex items-center justify-end px-6 pt-4",children:(0,re.jsxs)("button",{onClick:t,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,re.jsx)(zs.A,{className:"h-4 w-4"}),(0,re.jsx)("span",{className:"sr-only",children:"Close"})]})}),(0,re.jsx)("div",{className:"flex-1 overflow-auto",children:(0,re.jsx)(tc,{})})]})})})};function lc(e){let{currentUsage:s,stats:t,className:a=""}=e;const{toast:n}=nn(),[r,l]=(0,H.useState)(!1),[i,o]=(0,H.useState)(!1),[c,d]=(0,H.useState)(!1),[m,u]=(0,H.useState)(!1),{app:x}=_s(),{user:h}=oe(),{nextPlan:p,billingPeriod:g,isLoading:f,error:v}=Gi(s,t),b=(null==s?void 0:s.tier)||null,j=!b||"free"===b.toLowerCase(),y=zi(b),N=qi(b),w=j&&(null==s?void 0:s.daily_usage)>=(null==s?void 0:s.daily_limit),_=(()=>{if(!N||null==t||!t.pricing)return null;return("yearly"===y?t.pricing.yearly:t.pricing.monthly)[N]||null})();(0,H.useEffect)(()=>{try{if(s&&t){var e;const a={user_id:(null==h?void 0:h.id)||null,user_email:s.user_email,organization_id:s.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:s.monthly_usage,daily_usage:s.daily_usage,monthly_limit:s.monthly_limit,daily_limit:s.daily_limit,extra_credits:s.extra_credits,is_over_limit:s.is_over_limit,current_tier:b,is_free_user:j,next_tier:N,billing_period:y,hit_daily_limit:w,hit_monthly_limit:!w&&s.is_over_limit,current_period_start:s.current_credit_period_start_date,current_period_end:s.current_credit_period_end_date,next_period_start:s.next_period_start_date,past_due:s.past_due,has_pricing_data:!(null==t||!t.pricing),next_plan_price:(null==_?void 0:_.unit_amount)||null,next_plan_id:(null==_?void 0:_.id)||null};Ie("User out of credits",a)}}catch(v){}},[]);const k=(e,t)=>{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},r={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:t,daily_usage:(null==s?void 0:s.daily_usage)||null,daily_limit:(null==s?void 0:s.daily_limit)||null,monthly_usage:(null==s?void 0:s.monthly_usage)||null,monthly_limit:(null==s?void 0:s.monthly_limit)||null,is_daily_limit_hit:w};Ie("User clicked upgrade",(0,K.A)((0,K.A)({},n),r)),We(n,r)}catch(v){}},A=()=>{u(!0);const e=j?"billing_dialog":"direct_upgrade",s=S();k(s,e),j?(d(!0),o(!0)):(async()=>{if(null!=_&&_.id){l(!0);try{var e;const s=null===(e=(await Ji.updateSubscription(_.id)).subscription)||void 0===e?void 0:e.is_downgrade;n({title:"Subscription Updated",description:s?"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 s;n({variant:"destructive",title:"Error",description:(null===(s=v.response)||void 0===s?void 0:s.detail)||"Failed to update subscription. Please try again later."})}finally{l(!1),u(!1)}}})()},S=()=>{if(j)return c?"Opening...":"View All Plans";if(!N)return"View All Plans";const e=Yi(N),s=y.charAt(0).toUpperCase()+y.slice(1);return"Upgrade to ".concat(e," ").concat(s)},C=()=>Wi(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,re.jsxs)(re.Fragment,{children:[(0,re.jsx)("div",{className:"py-2 px-2 ".concat(a," align-center w-full"),children:(0,re.jsx)("div",{className:"min-h-[100px] font-base44 rounded-[16px]",children:(0,re.jsxs)("div",{className:"p-2 text-center",children:[(0,re.jsx)("div",{className:"mb-2",children:(0,re.jsx)("div",{className:"font-light text-gray-700 mb-4 leading-relaxed",children:(0,re.jsxs)("div",{className:"animate-pulse",children:[(0,re.jsx)("div",{className:"h-4 bg-gray-200 rounded mb-2 w-3/4 mx-auto"}),(0,re.jsx)("div",{className:"h-3 bg-gray-200 rounded w-1/2 mx-auto"})]})})}),(0,re.jsx)("div",{className:"",children:(0,re.jsx)("div",{className:"animate-pulse",children:(0,re.jsx)("div",{className:"w-full h-[32px] bg-gray-200 rounded-[10px]"})})})]})})}),(0,re.jsx)(rc,{isOpen:i,onClose:()=>{o(!1),d(!1),u(!1)},onSubscriptionSuccess:()=>{o(!1),d(!1),u(!1),setTimeout(()=>{window.location.reload()},1e3)}})]}):v?(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)("div",{className:"py-6 px-6 ".concat(a," font-base44"),children:(0,re.jsxs)("div",{className:"max-w-lg",children:[(0,re.jsx)("div",{className:"mb-2",children:(0,re.jsx)("p",{className:"text-md font-light text-gray-700 mb-6 leading-relaxed",children:w?(0,re.jsxs)(re.Fragment,{children:["Looks like you've reached your daily credit limit. Your credits will reset tomorrow, or"," ",(0,re.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,re.jsxs)(re.Fragment,{children:["Looks like you've used all your credits for this month."," ",(0,re.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,re.jsx)("button",{onClick:A,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:S()}):(0,re.jsx)("button",{onClick:A,disabled:r||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:r?"Upgrading...":S()})]})}),(0,re.jsx)(rc,{isOpen:i,onClose:()=>{o(!1),d(!1),u(!1)},onSubscriptionSuccess:()=>{o(!1),d(!1),u(!1),setTimeout(()=>{window.location.reload()},1e3)}})]}):(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)("div",{className:"py-2 px-2 ".concat(a," align-center w-full"),children:(0,re.jsx)("div",{className:" min-h-[100px] font-base44 rounded-[16px]",children:(0,re.jsxs)("div",{className:"p-2 text-center",children:[(0,re.jsx)("div",{className:"mb-2",children:j?(0,re.jsx)("div",{className:"font-light text-gray-700 mb-4 leading-relaxed",children:w?(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)("div",{className:"text-black text-[16px]",children:"You're out of daily credits on your Free plan"}),(0,re.jsx)("div",{className:"text-[14px]",children:"Upgrade to a Premium plan and unlock instant credits and more power for your app"})]}):(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)("div",{className:"text-black text-[16px]",children:"You're out of monthly credits on your Free plan"}),(0,re.jsx)("div",{className:"text-[14px]",children:"Upgrade to a Premium plan and unlock instant credits and more power for your app"})]})}):N?(0,re.jsxs)("p",{className:"text-md font-light text-gray-700 mb-4 leading-relaxed",children:[(0,re.jsx)("span",{className:"font-bold text-md text-black",children:"You've hit this month's limit"}),(0,re.jsx)("br",{}),(0,re.jsxs)("span",{children:["Out of credits but still full of ideas? Upgrade to unlock more power for your app ",(0,re.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,re.jsxs)("div",{className:"font-light text-gray-700 mb-4 leading-relaxed",children:[(0,re.jsx)("div",{className:"text-black text-[16px]",children:"You've hit the limit on our highest plan"}),(0,re.jsx)("div",{className:"text-[14px]",children:"Let's take it further - contact our sales team to create a custom plan for you"})]})}),j&&(0,re.jsx)("div",{className:"",children:(0,re.jsx)("button",{onClick:A,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:S()})}),!j&&!N&&(0,re.jsx)("div",{className:"",children:(0,re.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,re.jsxs)("div",{className:"bg-white/50 rounded-[12px] p-4 font-base44",children:[(0,re.jsxs)("div",{className:"flex justify-between items-center mb-2",children:[(0,re.jsxs)("h3",{className:"text-lg font-semibold text-slate-900 font-base44",children:[Yi(N)," Plan"]}),(0,re.jsxs)("div",{className:"flex items-center gap-2 bg-white p-0.5 px-4 rounded-full",children:[(0,re.jsxs)("div",{className:"text-lg font-semibold text-slate-900",children:["$",E().price]}),(0,re.jsx)("div",{className:"text-xs text-slate-500 font-base44",children:E().billingText})]})]}),(0,re.jsxs)("div",{className:"space-y-2 mb-4",children:[(0,re.jsxs)("div",{className:"text-sm text-slate-600 flex",children:[(0,re.jsx)("span",{className:"text-orange-500 font-semibold min-w-[40px]",children:Vi(C().messageCredits)})," Monthly credits"]}),(0,re.jsxs)("div",{className:"text-sm text-slate-600 flex",children:[(0,re.jsx)("span",{className:"text-orange-500 font-semibold min-w-[40px]",children:Vi(C().integrationCredits)})," Integration credits"]})]}),(0,re.jsx)("div",{className:"mb-2 cursor-pointer",children:j?(0,re.jsx)("button",{onClick:A,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:S()}):(0,re.jsx)("button",{onClick:A,disabled:r||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:r?"Upgrading...":S()})}),(0,re.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,re.jsx)(rc,{isOpen:i,onClose:()=>{o(!1),d(!1),u(!1)},onSubscriptionSuccess:()=>{o(!1),d(!1),u(!1),setTimeout(()=>{window.location.reload()},1e3)}})]})}function ic(e){let{endDate:s,isDaily:t=!1}=e;const[a,n]=(0,H.useState)("");return(0,H.useEffect)(()=>{const e=()=>{if(t){const e=new Date,s=new Date(e);s.setUTCHours(24,0,0,0);const t=s.getTime()-e.getTime();if(t>0){const e=Math.floor(t/36e5),s=Math.floor(t%36e5/6e4);n(e>0?"".concat(e,"h : ").concat(s,"m"):"".concat(s,"m"))}else n("")}else{if(!s)return;const e=new Date,t=new Date(s+"T00:00:00").getTime()-e.getTime();if(t>0){const e=Math.floor(t/864e5),s=Math.floor(t%864e5/36e5),a=Math.floor(t%36e5/6e4);n(e>0?"".concat(e,"d : ").concat(s,"h"):s>0?"".concat(s,"h : ").concat(a,"m"):"".concat(a,"m"))}else n("Expired")}};e();const a=setInterval(e,6e4);return()=>clearInterval(a)},[s,t]),(0,re.jsx)("span",{className:"flex text-md text-white justify-center",children:a&&"".concat(a," until credits renew")})}const oc=function(e){var s;let{chat:t,addMessage:a,undoMessage:n,status:r,onStop:l,suggestions:i=null,isDisabled:o=!1,isOutOfCredits:c=!1,currentUsage:d=null,billingStats:m=null,customButtomRight:u=null,customButtomLeft:x=null,customMiddleComponent:h=null,placeholder:p="What would you like to change?",isDiscussionMode:g=!1,isVisualEditMode:f=!1}=e;const{user:v}=oe(),[b,j]=(0,H.useState)(""),[y,N]=(0,H.useState)([]),w=(0,H.useRef)(null),_=(0,H.useRef)(null),[k,A]=(0,H.useState)(!1),[S,C]=(0,H.useState)(!0),[E,I]=(0,H.useState)(!1),T=null===(s=v.platform_role)||void 0===s?void 0:s.includes("admin"),P=(!(null!=d&&d.tier)||"free"===(null==d?void 0:d.tier.toLowerCase()))&&(null==d?void 0:d.daily_usage)>=(null==d?void 0:d.daily_limit);(0,H.useEffect)(()=>{const e=sessionStorage.getItem("pendingChatMessage");e&&(j(e),sessionStorage.removeItem("pendingChatMessage"));const s=e=>{e.detail&&e.detail.message&&(j(e.detail.message),setTimeout(()=>{if(_.current&&_.current.focus&&(_.current.focus(),_.current.setSelectionRange)){var e;const s=(null===(e=_.current.value)||void 0===e?void 0:e.length)||0;_.current.setSelectionRange(s,s)}},100))};return window.addEventListener("pendingChatMessage",s),()=>{window.removeEventListener("pendingChatMessage",s)}},[]);const L=()=>{w.current&&S&&(w.current.scrollTop=w.current.scrollHeight)},O=()=>{const e=(()=>{if(!w.current)return!0;const e=w.current;return e.scrollHeight-e.scrollTop-e.clientHeight<=100})();A(!e),C(e),I(!0),clearTimeout(O.timeout),O.timeout=setTimeout(()=>{I(!1)},1500)};(0,H.useEffect)(()=>{new URLSearchParams(window.location.search).get("msgId")||k||L()},[null==t?void 0:t.messages,k]),(0,H.useEffect)(()=>{k||L()},[r,k]),(0,H.useEffect)(()=>{if(!w.current)return;const e=new MutationObserver(()=>{k||L()});e.observe(w.current,{childList:!0,subtree:!0,characterData:!0});const s=w.current;return s.addEventListener("scroll",O),()=>{e.disconnect(),s.removeEventListener("scroll",O)}},[k]);const R=(0,H.useMemo)(()=>(null==t?void 0:t.messages.filter(e=>!0!==e.hidden))||[],[(null==t?void 0:t.messages)||[]]);return t?(0,re.jsxs)("div",{className:"flex flex-col h-full w-full bg-[#F8FAFC] relative p-2",children:[(0,re.jsx)("div",{className:""}),(0,re.jsx)("div",{ref:w,className:"flex-grow overflow-y-auto py-2 space-y-2 pb-4 scrollbar-auto-hide relative z-10 ".concat(E?"scrollbar-visible":""),onMouseEnter:()=>{I(!0)},onMouseLeave:()=>{clearTimeout(O.timeout),setTimeout(()=>{I(!1)},300)},children:(0,re.jsx)(Ei,{messages:R,undoMessage:n?e=>{const s=t.messages.find(s=>s.id===e);"user"===s.role&&(n(e),j(s.content))}:null})}),(0,re.jsxs)("div",{className:"relative z-10",children:[(0,re.jsx)(Oi,{status:r,messages:R}),h||("ready"===r.state&&i?(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)("div",{className:"text-[10px] text-gray-400 text-center mb-1",children:"Suggestions"}),(0,re.jsx)("div",{className:"flex justify-center gap-3 px-4 py-2 border-t border-gray-100",children:[i.suggestion_1,i.suggestion_2,i.suggestion_3].map((e,s)=>(0,re.jsx)("span",{className:"text-xs text-gray-400 hover:text-gray-600 cursor-pointer transition-colors duration-200 hover:underline px-2 py-1 rounded-full hover:bg-gray-50",onClick:()=>(e=>{j(e.prompt)})(e),children:e.title},s))})]}):null)]}),(0,re.jsxs)("div",{className:"rounded-[12px] relative z-10 ".concat(c?"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%)]":""),children:[c&&(0,re.jsx)("div",{className:"flex justify-center",children:(0,re.jsx)(lc,{currentUsage:d,stats:m})}),(0,re.jsxs)("div",{className:"relative flex-shrink-0",children:[c&&(null==d?void 0:d.current_credit_period_end_date)&&(0,re.jsx)("div",{className:"flex justify-center -mb-1",children:(0,re.jsx)("div",{className:"bg-[#C7BECF] rounded-t-[16px] p-2 px-4 w-full text-center",children:(0,re.jsx)(ic,{endDate:d.next_period_start_date,isDaily:P})})}),(0,re.jsx)("div",{className:"w-full ".concat(c?"bg-[#C7BECF] border border-[#C7BECF] rounded-b-[16px]":""),children:(0,re.jsx)("div",{className:"join w-full",children:(0,re.jsx)(qs,{ref:_,value:b,onValueChange:j,files:y,onFilesChange:N,onSend:async()=>{if(b.trim()&&"processing"!==r.state)try{const e={content:b,file_urls:y};j(""),N([]),C(!0),A(!1),await a(e)}catch(e){Xr.toast.error("Failed to send message")}},onStop:l,placeholder:p,disabled:"processing"===r.state||o,customButtomRight:u,customButtomLeft:x,isProcessing:"processing"===r.state,isDiscussionMode:g,isVisualEditMode:f,isOutOfCredits:c})})})]}),T&&(0,re.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,re.jsxs)("a",{onClick:()=>{const e=t.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,re.jsx)(Kr.A,{className:"w-3 h-3"}),"Copy"]})})]})]}):(0,re.jsx)("div",{className:"alert alert-warning m-4 text-sm",children:"No chat found"})};var cc=t(50253);function dc(e){let{isVisualEditMode:s,toggleVisualEditMode:t,isSaving:a}=e;return(0,re.jsxs)("button",{onClick:t,className:"flex items-center gap-1 px-2 py-1 rounded-md text-xs ".concat(s?"bg-blue-50 text-blue-600 hover:bg-blue-100":"text-gray-600 bg-gray-100 hover:bg-gray-200"),disabled:a,children:[(0,re.jsx)(cc.A,{className:"h-4 w-4"}),(0,re.jsx)("span",{children:"Visual Edit"})]})}var mc=t(17119),uc=t.t(mc,2);const xc="palette",hc="custom",pc="bg",gc="text",fc="#000000",vc=[{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"}],bc=[50,100,200,300,400,500,600,700,800,900,950],jc=e=>e<500?"text-gray-900":"text-white",yc=e=>{let{color:s}=e;if(!s)return(0,re.jsx)("span",{className:"text-sm text-gray-500",children:"None"});const t=s.type===hc?{backgroundColor:s.value,border:"1px solid rgba(0,0,0,0.1)"}:null,a=s.type===xc?"bg-".concat(s.name,"-").concat(s.shade," border border-black/10"):"";return(0,re.jsxs)("div",{className:"flex items-center",children:[(0,re.jsx)("div",{className:"h-6 w-6 rounded-sm mr-2 ".concat(a),style:t}),(0,re.jsx)("span",{className:"text-sm text-gray-700",children:s.type===xc?"".concat(s.name.charAt(0).toUpperCase()+s.name.slice(1)," ").concat(s.shade):s.value})]})},Nc=e=>{let{mode:s,onModeChange:t}=e;return(0,re.jsx)("div",{className:"w-full",children:(0,re.jsxs)("div",{className:"flex h-8 items-center rounded-md bg-gray-100 p-0.5",children:[(0,re.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(s===xc?"bg-white text-slate-950 shadow-sm":"text-slate-500 hover:text-slate-900"),onClick:()=>t(xc),children:"Palettes"}),(0,re.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(s===hc?"bg-white text-slate-950 shadow-sm":"text-slate-500 hover:text-slate-900"),onClick:()=>t(hc),children:"Custom"})]})})},wc=e=>{let{color:s,onChange:t}=e;const[a,n]=(0,H.useState)(100),[r,l]=(0,H.useState)(50),[i,o]=(0,H.useState)(0),[c,d]=(0,H.useState)(!1),[m,u]=(0,H.useState)(!1),x=(0,H.useRef)(null),h=(0,H.useRef)(null);(0,H.useEffect)(()=>{if(s&&s.startsWith("#")&&7===s.length){const[e,t,a]=(e=>{if(!e||!e.startsWith("#")||7!==e.length)return[0,100,50];const s=parseInt(e.slice(1,3),16)/255,t=parseInt(e.slice(3,5),16)/255,a=parseInt(e.slice(5,7),16)/255,n=Math.max(s,t,a),r=Math.min(s,t,a);let l,i,o=(n+r)/2;if(n===r)l=i=0;else{const e=n-r;switch(i=o>.5?e/(2-n-r):e/(n+r),n){case s:l=(t-a)/e+(t{e=Math.max(0,Math.min(360,e))/360,s=Math.max(0,Math.min(100,s))/100;const a=(e,s,t)=>(t<0&&(t+=1),t>1&&(t-=1),t<1/6?e+6*(s-e)*t:t<.5?s:t<2/3?e+(s-e)*(2/3-t)*6:e),n=(t=Math.max(0,Math.min(100,t))/100)<.5?t*(1+s):t+s-t*s,r=2*t-n,l=a(r,n,e+1/3),i=a(r,n,e),o=a(r,n,e-1/3),c=e=>{const s=Math.max(0,Math.min(255,Math.round(255*e))).toString(16);return 1===s.length?"0"+s:s};return"#".concat(c(l)).concat(c(i)).concat(c(o))},g=(e,s)=>{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(s-o.top,o.height)),m=Math.round(c/o.width*100),u=Math.round(100-d/o.height*100),[h,g,f]=((e,s,t)=>{const a=(t/=100)*(2-(s/=100))/2,n=0!==a&&1!==a?(t-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-r)>.5){n(g),l(f);const e=p(h,g,f);t(e)}},f=e=>{if(!h.current)return;const s=h.current.getBoundingClientRect(),n=Math.max(0,Math.min(e-s.left,s.width-1)),l=Math.max(0,Math.min(360,n/(s.width-1)*360));if(Math.abs(l-i)>1){o(l);const e=p(l,a,r);t(e)}};(0,H.useEffect)(()=>{const e=e=>{e.preventDefault(),c?g(e.clientX,e.clientY):m&&f(e.clientX)},s=e=>{e.preventDefault(),d(!1),u(!1)};return(c||m)&&(document.addEventListener("mousemove",e,{passive:!1}),document.addEventListener("mouseup",s,{passive:!1}),document.body.style.userSelect="none",document.body.style.cursor=c?"crosshair":"pointer"),()=>{document.removeEventListener("mousemove",e),document.removeEventListener("mouseup",s),document.body.style.userSelect="",document.body.style.cursor=""}},[c,m,i,a,r]);const[v,b,j]=((e,s,t)=>{const a=(t/=100)+(s/=100)*Math.min(t,1-t),n=0===a?0:2*(1-t/a);return[e,Math.round(100*n),Math.round(100*a)]})(i,a,r);return(0,re.jsxs)("div",{className:"p-4 space-y-4",children:[(0,re.jsxs)("div",{className:"flex items-center gap-3",children:[(0,re.jsx)("div",{className:"w-12 h-12 rounded-lg border border-gray-200 shadow-sm",style:{backgroundColor:s||"#000000"}}),(0,re.jsx)("div",{className:"flex-1",children:(0,re.jsx)("input",{type:"text",value:s||"",onChange:e=>t(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,re.jsx)("div",{className:"relative",children:(0,re.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,re.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,re.jsx)("div",{className:"relative",children:(0,re.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,re.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)"}})})})]})},_c=e=>{let{selectedColorInfo:s,onColorSelect:t}=e;return(0,re.jsx)("div",{className:"overflow-y-auto max-h-64 p-2",children:vc.map(e=>(0,re.jsxs)("div",{className:"mb-3",children:[(0,re.jsx)("div",{className:"text-xs font-medium text-gray-900 mb-1",children:e.name}),(0,re.jsx)("div",{className:"flex flex-wrap gap-2",children:bc.map(a=>{const n=(null==s?void 0:s.name)===e.prefix&&(null==s?void 0:s.shade)===a;return(0,re.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(jc(a)," ").concat(n?"ring-2 ring-offset-1 ring-blue-500":"","\n "),onClick:()=>t(e.prefix,a),children:n&&(0,re.jsx)(Pt.A,{className:"h-3 w-3"})},a)})})]},e.prefix))})};const kc=function(e){let{label:s,selectedColor:t,onChange:a}=e;const[n,r]=(0,H.useState)(!1),[l,i]=(0,H.useState)(xc),[o,c]=(0,H.useState)(fc),[d,m]=(0,H.useState)(null),u=(0,H.useRef)(null),x=(0,H.useRef)(null),[h,p]=(0,H.useState)({top:0,left:0,width:0}),g=s.toLowerCase().includes("background")?pc:gc;(0,H.useEffect)(()=>{const e=(e=>{if(!e)return null;const s=e.match(/^(bg|text)-([a-z]+)-(\d+)$/);if(s)return{type:xc,name:s[2],shade:parseInt(s[3])};const t=e.match(/^(bg|text)-\[(.+)\]$/);return t?{type:hc,value:t[2]}:null})(t);if(!e)return m(null),void c(fc);e.type===hc?(i(hc),c(e.value),m(null)):(i(xc),m({name:e.name,shade:e.shade}),c(fc))},[t]),(0,H.useEffect)(()=>{if(n&&x.current){const e=x.current.getBoundingClientRect();p({top:e.bottom+window.scrollY+4,left:e.left+window.scrollX,width:e.width})}},[n]),(0,H.useEffect)(()=>{const e=e=>{const s=document.getElementById("color-dropdown");!u.current||u.current.contains(e.target)||s&&s.contains(e.target)||r(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]);const f=()=>{m(null),c(fc),a(null),r(!1)};return(0,re.jsxs)("div",{ref:u,className:"relative",children:[(0,re.jsx)("div",{className:"flex items-start justify-between gap-4",children:(0,re.jsx)("div",{className:"flex-1",children:(0,re.jsxs)("div",{className:"flex gap-4",children:[(0,re.jsx)("label",{className:"text-sm font-light text-gray-700 min-w-[100px] pt-2",children:s}),(0,re.jsxs)("button",{ref:x,type:"button",onClick:()=>r(!n),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:[yc({color:d?{type:xc,name:d.name,shade:d.shade}:o!==fc?{type:hc,value:o}:null}),n?(0,re.jsx)(Tt.A,{className:"h-4 w-4 text-gray-500"}):(0,re.jsx)(It.A,{className:"h-4 w-4 text-gray-500"})]})]})})}),n&&(0,mc.createPortal)((0,re.jsx)("div",{id:"color-dropdown",className:"fixed z-50 bg-white shadow-lg rounded-[8px] border border-gray-200 max-w-[250px]",style:{top:"".concat(h.top,"px"),left:"".concat(h.left,"px"),width:"".concat(h.width,"px"),maxHeight:"400px"},children:(0,re.jsxs)("div",{className:"flex flex-col h-full",children:[(0,re.jsx)("div",{className:"p-2",children:(0,re.jsx)(Nc,{mode:l,onModeChange:i})}),(0,re.jsx)("div",{className:"flex-1 overflow-auto",children:l===xc?(0,re.jsx)(_c,{selectedColorInfo:d,onColorSelect:(e,s)=>{m({name:e,shade:s}),a("".concat(g,"-").concat(e,"-").concat(s)),r(!1)}}):(0,re.jsx)(wc,{color:o,onChange:e=>{c(e),a("".concat(g,"-[").concat(e,"]"))}})}),(0,re.jsx)("div",{className:"border-t border-gray-200",children:(0,re.jsxs)("div",{className:"flex items-center justify-between p-2 hover:bg-gray-50 cursor-pointer",onClick:f,children:[(0,re.jsx)("span",{className:"text-sm font-light text-gray-700",children:"Clear Color"}),(0,re.jsx)("button",{className:"w-6 h-6 rounded-sm border border-gray-300 relative hover:bg-gray-50",onClick:f,children:(0,re.jsx)("div",{className:"absolute inset-0 flex items-center justify-center",children:(0,re.jsx)("div",{className:"w-[2px] h-[120%] bg-red-500 rotate-45 transform origin-center"})})})]})})]})}),document.body)]})};var Ac=t(72995),Sc=t(14703),Cc=t(45462),Ec=t(56404),Ic=t(25146),Tc=t(80369);const Pc=[0,1,2,3,4,5,6,8,10,12,16,20,24,32,40,48,64];const Lc=function(e){let{label:s,spacing:t,onChange:a}=e;const n=s.toLowerCase().startsWith("m")?"m":"p",[r,l]=(0,H.useState)({all:0,t:0,r:0,b:0,l:0,x:0,y:0}),[i,o]=(0,H.useState)("axes"),[c,d]=(0,H.useState)(!1),m=(0,H.useRef)(null);(0,H.useEffect)(()=>{const e={all:0,t:0,r:0,b:0,l:0,x:0,y:0};let s=!1,a=!1,r=!1,i=!1;const c=t||{},u=e=>{if(!e)return 0;if("mx-auto"===e)return s=!0,0;const t=e.match(new RegExp("^".concat(n,"[ytrlbx]?-(\\d+)$")));if(!t)return 0;const a=parseInt(t[1]),r=Pc.indexOf(a);return-1!==r?r: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?(s=!0,r=!0):(c.x&&(e.x=u(c.x),e.l=e.x,e.r=e.x,r=!0),c.y&&(e.y=u(c.y),e.t=e.y,e.b=e.y,r=!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),l(e),d(s);let x=m.current;x||(x=r?"axes":i?"sides":a?"all":"axes"),o(x)},[t,n]);const u=function(e,s){let t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:c;const r={};"all"===s?r.all="".concat(n,"-").concat(Pc[e.all]):"axes"===s?(t&&"m"===n?r.x="mx-auto":e.x>0&&(r.x="".concat(n,"x-").concat(Pc[e.x])),e.y>0&&(r.y="".concat(n,"y-").concat(Pc[e.y]))):(e.t>0&&(r.t="".concat(n,"t-").concat(Pc[e.t])),e.r>0&&(r.r="".concat(n,"r-").concat(Pc[e.r])),e.b>0&&(r.b="".concat(n,"b-").concat(Pc[e.b])),e.l>0&&(r.l="".concat(n,"l-").concat(Pc[e.l]))),a(r)},x=(e,s)=>{const t=Math.max(0,Math.min(s,Pc.length-1)),a=(0,K.A)({},r);a[e]=t,"all"===i?(a.t=t,a.r=t,a.b=t,a.l=t,a.x=t,a.y=t):"axes"===i&&("x"===e?(a.l=t,a.r=t):"y"===e&&(a.t=t,a.b=t)),t>0&&"x"===e&&c&&d(!1),l(a),u(a,i,"x"!==e&&c)},h=()=>{const e=!c;if(d(e),e){const e=(0,K.A)((0,K.A)({},r),{},{x:0,l:0,r:0});l(e),u(e,"axes",!0)}else u(r,i,!1)},p=(e,s)=>{const t=r[e];x(e,t+(s?1:-1))},g=e=>{let{label:s,icon:t,value:a,onChange:n}=e;return(0,re.jsx)("div",{className:"flex items-center space-x-2",children:(0,re.jsx)("div",{className:"flex-1 flex items-center",children:(0,re.jsx)("div",{className:"relative flex-1 w-full min-w-[90px] max-w-[140px]",children:(0,re.jsxs)("div",{className:"relative w-full",children:[(0,re.jsx)("div",{className:"absolute left-2 top-1/2 -translate-y-1/2",children:(0,re.jsx)("div",{className:"scale-75",children:t})}),(0,re.jsx)("input",{type:"text",value:Pc[a],onChange:e=>{const s=parseInt(e.target.value),t=Pc.indexOf(s);-1!==t&&n(t)},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,re.jsxs)("div",{className:"absolute inset-y-0 right-0 flex flex-col pr-1",children:[(0,re.jsx)("button",{type:"button",onClick:()=>p(s.toLowerCase(),!0),disabled:a>=Pc.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,re.jsx)(Tt.A,{className:"h-3 w-3"})}),(0,re.jsx)("button",{type:"button",onClick:()=>p(s.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,re.jsx)(It.A,{className:"h-3 w-3"})})]})]})})})})};return(0,re.jsx)("div",{className:"space-y-3",children:(0,re.jsxs)("div",{className:"flex items-start justify-between gap-4",children:[(0,re.jsx)("div",{className:"flex-1",children:(0,re.jsxs)("div",{className:"flex gap-4",children:[(0,re.jsx)("label",{className:"text-xs font-light text-gray-700 min-w-[100px] pt-2",children:s}),(0,re.jsxs)("div",{className:"flex-1 space-y-3",children:["axes"===i&&"m"===n&&(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)("div",{className:"flex items-center space-x-2",children:(0,re.jsx)("div",{className:"flex items-center gap-2 w-full",children:c?(0,re.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,re.jsx)(Ac.A,{className:"h-4 w-4 text-indigo-500"}),(0,re.jsx)("span",{className:"text-xs text-indigo-700",children:"mx-auto"})]}):(0,re.jsx)(g,{label:"x",icon:(0,re.jsx)(Ec.A,{className:"h-4 w-4 text-gray-500"}),value:r.x,onChange:e=>x("x",e)})})}),(0,re.jsx)(g,{label:"y",icon:(0,re.jsx)(Ic.A,{className:"h-4 w-4 text-gray-500"}),value:r.y,onChange:e=>x("y",e)})]}),"axes"===i&&"m"!==n&&(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(g,{label:"x",icon:(0,re.jsx)(ha.A,{className:"h-4 w-4 text-gray-500"}),value:r.x,onChange:e=>x("x",e)}),(0,re.jsx)(g,{label:"y",icon:(0,re.jsx)(Sc.A,{className:"h-4 w-4 text-gray-500"}),value:r.y,onChange:e=>x("y",e)})]}),"sides"===i&&(0,re.jsxs)("div",{className:"grid auto-rows-auto gap-3",style:{gridTemplateColumns:"repeat(auto-fit, minmax(90px, 140px))"},children:[(0,re.jsx)(g,{label:"t",icon:(0,re.jsx)(Bs.A,{className:"h-4 w-4 text-gray-500"}),value:r.t,onChange:e=>x("t",e)}),(0,re.jsx)(g,{label:"r",icon:(0,re.jsx)(ha.A,{className:"h-4 w-4 text-gray-500"}),value:r.r,onChange:e=>x("r",e)}),(0,re.jsx)(g,{label:"b",icon:(0,re.jsx)(Sc.A,{className:"h-4 w-4 text-gray-500"}),value:r.b,onChange:e=>x("b",e)}),(0,re.jsx)(g,{label:"l",icon:(0,re.jsx)(Cc.A,{className:"h-4 w-4 text-gray-500"}),value:r.l,onChange:e=>x("l",e)})]})]})]})}),(0,re.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,re.jsx)("div",{className:"rounded-md overflow-hidden",children:(0,re.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:()=>{return o(e="axes"===i?"sides":"axes"),m.current=e,void("axes"!==e&&c?(d(!1),u(r,e,!1)):u(r,e,c));var e},children:(0,re.jsx)(Tc.A,{size:16})})}),"Margin"===s&&"axes"===i&&(0,re.jsx)("div",{children:(0,re.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,re.jsx)(Ac.A,{className:"h-4 w-4"})})})]})]})})};var Oc=t(14666),Rc=t(92530),Dc=t(54413),Mc=t(69367),Fc=t(68215),Bc=t(66291);const Uc=[{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"}],zc=[{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}],qc=[{label:"Left",value:"text-left",icon:(0,re.jsx)(Oc.A,{className:"h-4 w-4"})},{label:"Center",value:"text-center",icon:(0,re.jsx)(Rc.A,{className:"h-4 w-4"})},{label:"Right",value:"text-right",icon:(0,re.jsx)(Dc.A,{className:"h-4 w-4"})},{label:"Justify",value:"text-justify",icon:(0,re.jsx)(Mc.A,{className:"h-4 w-4"})}],Wc=[{label:"None",value:"no-underline",icon:(0,re.jsx)(Fc.A,{className:"h-4 w-4"})},{label:"Underline",value:"underline",icon:(0,re.jsx)(Bc.A,{className:"h-4 w-4"})},{label:"Line Through",value:"line-through",icon:(0,re.jsx)("span",{className:"text-xs line-through",children:"abc"})}],Vc=[{label:"Normal",value:"normal-case",icon:(0,re.jsx)(Fc.A,{className:"h-4 w-4"})},{label:"Uppercase",value:"uppercase",icon:(0,re.jsx)("span",{className:"text-xs",children:"AA"})},{label:"Lowercase",value:"lowercase",icon:(0,re.jsx)("span",{className:"text-xs",children:"aa"})},{label:"Capitalize",value:"capitalize",icon:(0,re.jsx)("span",{className:"text-xs",children:"Aa"})}];function Yc(e){let{value:s,onChange:t}=e;const a=Uc.findIndex(e=>e.value===s),n=-1===a?2:a;return(0,re.jsxs)("div",{className:"flex items-center gap-4",children:[(0,re.jsx)("label",{className:"text-sm font-light text-gray-700 whitespace-nowrap min-w-[100px]",children:"Size"}),(0,re.jsxs)("div",{className:"flex-1 flex items-center gap-2",children:[(0,re.jsxs)(Ut,{value:s,onValueChange:t,children:[(0,re.jsx)(Wt,{className:"w-[80px] h-8 text-sm font-light bg-gray-100 rounded-[6px] border-none",children:(0,re.jsx)(qt,{placeholder:"Select size"})}),(0,re.jsx)(Ht,{children:Uc.map(e=>(0,re.jsx)($t,{value:e.value,className:"text-xs",children:e.label},e.value))})]}),(0,re.jsx)("div",{className:"flex-1",children:(0,re.jsx)("input",{type:"range",min:"0",max:Uc.length-1,value:n,onChange:e=>t(Uc[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(n/(Uc.length-1)*100,"%, #f3f4f6 ").concat(n/(Uc.length-1)*100,"%, #f3f4f6 100%)")}})})]})]})}function Hc(e){let{value:s,onChange:t}=e;zc.findIndex(e=>e.value===s);return(0,re.jsxs)("div",{className:"flex items-center gap-4",children:[(0,re.jsx)("label",{className:"text-sm font-light text-gray-700 whitespace-nowrap min-w-[100px] max-w-[120px]",children:"Weight"}),(0,re.jsxs)(Ut,{value:s,onValueChange:t,children:[(0,re.jsx)(Wt,{className:"h-8 text-sm font-light bg-gray-100 rounded-[6px] border-none",children:(0,re.jsx)(qt,{placeholder:"Select weight"})}),(0,re.jsx)(Ht,{children:zc.map(e=>(0,re.jsx)($t,{value:e.value,className:"text-xs",children:e.label},e.value))})]})]})}const Gc=function(e){let{typography:s,onChange:t}=e;const[a,n]=(0,H.useState)(null),[r,l]=(0,H.useState)(null),[i,o]=(0,H.useState)(null),[c,d]=(0,H.useState)(null),[m,u]=(0,H.useState)(null);return(0,H.useEffect)(()=>{n((null==s?void 0:s.size)||Uc[2].value),l((null==s?void 0:s.weight)||zc[3].value),o((null==s?void 0:s.align)||qc[0].value),d((null==s?void 0:s.decoration)||Wc[0].value),u((null==s?void 0:s.transform)||Vc[0].value)},[s]),(0,re.jsxs)("div",{className:"space-y-4",children:[(0,re.jsx)(Yc,{value:a,onChange:e=>{n(e),t((0,K.A)((0,K.A)({},s),{},{size:e}))}}),(0,re.jsx)(Hc,{value:r,onChange:e=>{l(e),t((0,K.A)((0,K.A)({},s),{},{weight:e}))}}),(0,re.jsxs)("div",{className:"flex items-center gap-3",children:[(0,re.jsx)("label",{className:"text-sm font-light text-gray-700 shrink-0 min-w-[105px]",children:"Decoration"}),(0,re.jsx)("div",{className:"flex border rounded-[6px] divide-x flex-1 overflow-hidden",children:Wc.map((e,a)=>(0,re.jsx)("button",{type:"button",className:"flex-1 flex justify-center py-1.5 ".concat(c===e.value?"bg-gray-200 text-gray-700":"bg-white text-gray-700 hover:bg-gray-50"),onClick:()=>{return a=e.value,d(a),void t((0,K.A)((0,K.A)({},s),{},{decoration:a}));var a},title:e.label,children:e.icon},e.value))})]}),(0,re.jsxs)("div",{className:"flex items-center gap-3",children:[(0,re.jsx)("label",{className:"text-sm font-light text-gray-700 shrink-0 min-w-[105px]",children:"Alignment"}),(0,re.jsx)("div",{className:"flex border rounded-[6px] divide-x flex-1 overflow-hidden",children:qc.map((e,a)=>(0,re.jsx)("button",{type:"button",className:"flex-1 flex justify-center py-1.5 ".concat(i===e.value?"bg-gray-200 text-gray-700":"bg-white text-gray-700 hover:bg-gray-50"),onClick:()=>{return a=e.value,o(a),void t((0,K.A)((0,K.A)({},s),{},{align:a}));var a},title:e.label,children:e.icon},e.value))})]}),(0,re.jsxs)("div",{className:"flex items-center gap-3",children:[(0,re.jsx)("label",{className:"text-sm font-light text-gray-700 shrink-0 min-w-[105px]",children:"Transform"}),(0,re.jsx)("div",{className:"flex border rounded-[6px] divide-x flex-1 overflow-hidden",children:Vc.map((e,a)=>(0,re.jsx)("button",{type:"button",className:"flex-1 flex justify-center py-1.5 ".concat(m===e.value?"bg-gray-200 text-gray-700":"bg-white text-gray-700 hover:bg-gray-50"),onClick:()=>{return a=e.value,u(a),void t((0,K.A)((0,K.A)({},s),{},{transform:a}));var a},title:e.label,children:e.icon},e.value))})]})]})};function $c(e){const 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},other:[]};if(!e)return s;if("string"!=typeof e)return s;return e.trim().split(/\s+/).forEach(e=>{if(!e)return;let t=!1;e.startsWith("bg-")?(s.colors.bg=e,t=!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("m-")?(s.spacing.margin.x=e,s.spacing.margin.y=e,t=!0):e.startsWith("mt-")?(s.spacing.margin.t=e,t=!0):e.startsWith("mr-")?(s.spacing.margin.r=e,t=!0):e.startsWith("mb-")?(s.spacing.margin.b=e,t=!0):e.startsWith("ml-")?(s.spacing.margin.l=e,t=!0):e.startsWith("mx-")?(s.spacing.margin.x=e,t=!0):e.startsWith("my-")?(s.spacing.margin.y=e,t=!0):e.startsWith("p-")?(s.spacing.padding.x=e,s.spacing.padding.y=e,t=!0):e.startsWith("pt-")?(s.spacing.padding.t=e,t=!0):e.startsWith("pr-")?(s.spacing.padding.r=e,t=!0):e.startsWith("pb-")?(s.spacing.padding.b=e,t=!0):e.startsWith("pl-")?(s.spacing.padding.l=e,t=!0):e.startsWith("px-")?(s.spacing.padding.x=e,t=!0):e.startsWith("py-")?(s.spacing.padding.y=e,t=!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")?(s.typography.size=e,t=!0):e.startsWith("font-")?(s.typography.weight=e,t=!0):e.startsWith("text-left")||e.startsWith("text-center")||e.startsWith("text-right")||e.startsWith("text-justify")?(s.typography.align=e,t=!0):e.startsWith("underline")||e.startsWith("line-through")||e.startsWith("no-underline")?(s.typography.decoration=e,t=!0):(e.startsWith("uppercase")||e.startsWith("lowercase")||e.startsWith("capitalize")||e.startsWith("normal-case"))&&(s.typography.transform=e,t=!0):(s.colors.text=e,t=!0),t||s.other.push(e)}),s}function Jc(e){const s=new Set;if(e.colors&&(e.colors.bg&&s.add(e.colors.bg),e.colors.text&&s.add(e.colors.text)),e.spacing&&e.spacing.margin){const t=e.spacing.margin;t.all?s.add(t.all):(t.t&&s.add(t.t),t.r&&s.add(t.r),t.b&&s.add(t.b),t.l&&s.add(t.l),t.x&&s.add(t.x),t.y&&s.add(t.y))}if(e.spacing&&e.spacing.padding){const t=e.spacing.padding;t.all?s.add(t.all):(t.t&&s.add(t.t),t.r&&s.add(t.r),t.b&&s.add(t.b),t.l&&s.add(t.l),t.x&&s.add(t.x),t.y&&s.add(t.y))}if(e.typography){const{size:t,weight:a,align:n,decoration:r,transform:l}=e.typography;t&&s.add(t),a&&s.add(a),n&&s.add(n),r&&s.add(r),l&&s.add(l)}return e.other&&Array.isArray(e.other)&&e.other.forEach(e=>{e&&s.add(e)}),Array.from(s).join(" ")}function Zc(e){let{title:s,children:t,defaultOpen:a=!1}=e;const[n,r]=(0,H.useState)(a);return(0,re.jsx)("div",{className:"px-2 py-1",children:(0,re.jsxs)("div",{className:"border border-gray-200 rounded-md",children:[(0,re.jsxs)("button",{onClick:()=>r(!n),type:"button",className:"w-full rounded-md flex justify-between items-center px-3 py-2 text-sm font-semibold text-gray-800 hover:bg-gray-50 cursor-pointer ".concat(n?"":"bg-gray-100"),children:[s,n?(0,re.jsx)(Tt.A,{className:"h-4 w-4 text-gray-500"}):(0,re.jsx)(It.A,{className:"h-4 w-4 text-gray-500"})]}),n&&(0,re.jsx)("div",{className:"p-3",children:t})]})})}function Kc(e){var s,t;let{element:a,onChange:n,onClose:r,onSave:l,onDiscard:i,isSaving:o,onContentChange:c}=e;const[d,m]=(0,H.useState)({colors:{},spacing:{},typography:{}}),[u,x]=(0,H.useState)(""),[h,p]=(0,H.useState)(!1);(0,H.useEffect)(()=>{if(null!=a&&a.classes){x(a.classes);const e=$c(a.classes);m(e)}},[a]);if("svg"===(null==a||null===(s=a.tagName)||void 0===s?void 0:s.toLowerCase())||(null==a||null===(t=a.tagName)||void 0===t?void 0:t.toLowerCase().startsWith("svg"))||(null==a?void 0:a.tagName)&&["path","circle","rect","line","polygon","polyline","ellipse","g","defs","use","symbol"].includes(a.tagName.toLowerCase()))return(0,re.jsx)("div",{className:"w-full h-[500px] flex flex-col items-center justify-center px-4",children:(0,re.jsxs)("div",{className:"text-center",children:[(0,re.jsx)(vi.A,{className:"h-12 w-12 text-slate-400 mx-auto mb-4"}),(0,re.jsx)("h3",{className:"text-lg font-medium text-slate-700 mb-2",children:"SVG Element Selected"}),(0,re.jsx)("p",{className:"text-slate-500 text-sm leading-relaxed",children:"SVG elements and their properties can only be modified through the chat interface. Use the chat to request changes to this SVG element."})]})});const g=(e,s)=>{const t=(0,K.A)({},d);t.colors[e]=s,m(t);const a=Jc(t);x(a),n(a)},f=(e,s)=>{const t=(0,K.A)({},d);t.spacing[e]=s,m(t);const a=Jc(t);x(a),n(a)};return(0,re.jsxs)("div",{className:"w-full h-[450px] flex flex-col relative",children:[(0,re.jsx)("div",{className:"flex-1 overflow-y-auto",children:(0,re.jsxs)("div",{className:"controls w-full",children:[a.isTextElement&&(0,re.jsx)(Zc,{title:"Content",defaultOpen:!0,children:a.isDynamicContent?(0,re.jsx)("p",{className:"mt-1 text-xs text-slate-500",children:"This content is dynamically generated and cannot be edited directly. You can modify the content via the chat."}):(0,re.jsx)("textarea",{className:"w-full p-2 border border-gray-200 text-sm rounded-[6px] focus:outline-none focus:ring-1 focus:ring-gray-500 overflow-y-auto min-h-[4rem]",style:{height:"auto",resize:"none"},value:a.content,onChange:e=>{var s;e.target.style.height="auto",e.target.style.height=e.target.scrollHeight+"px",s=e.target.value,c(s)}})}),(0,re.jsxs)(Zc,{title:"Colors",defaultOpen:!0,children:[(0,re.jsx)(kc,{label:"Background",selectedColor:d.colors.bg,onChange:e=>g("bg",e)}),(0,re.jsx)("div",{className:"mt-2",children:(0,re.jsx)(kc,{label:"Text Color",selectedColor:d.colors.text,onChange:e=>g("text",e)})})]}),a.isTextElement&&(0,re.jsx)(Zc,{title:"Text & Font",defaultOpen:!0,children:(0,re.jsx)(Gc,{typography:d.typography,onChange:e=>{const s=(0,K.A)({},d);s.typography=(0,K.A)((0,K.A)({},s.typography),e),m(s);const t=Jc(s);x(t),n(t)}})}),(0,re.jsxs)(Zc,{title:"Spacing",defaultOpen:!1,children:[(0,re.jsx)(Lc,{label:"Margin",spacing:d.spacing.margin||{},onChange:e=>f("margin",e)}),(0,re.jsx)("div",{className:"mt-3",children:(0,re.jsx)(Lc,{label:"Padding",spacing:d.spacing.padding||{},onChange:e=>f("padding",e)})})]}),(0,re.jsx)(Zc,{title:"Advanced - Tailwind Classes",defaultOpen:!1,children:(0,re.jsx)("textarea",{className:"w-full p-2 border border-gray-200 text-sm font-mono rounded-[6px] focus:outline-none focus:ring-1 focus:ring-gray-500",rows:"5",value:u,onChange:e=>{const s=e.target.value;x(s);const t=$c(s);m(t),n(s)},placeholder:"Enter Tailwind classes..."})})]})}),(0,re.jsxs)("div",{className:"sticky bottom-0 left-0 right-0 p-3 flex justify-between",children:[(0,re.jsxs)("button",{onClick:()=>{i&&i()},disabled:o,className:"flex items-center gap-1 px-3 py-1 hover:bg-gray-200 text-gray-700 rounded-[6px] text-sm",children:[(0,re.jsx)(wi.A,{className:"h-3 w-3"}),"Discard"]}),(0,re.jsx)("button",{onClick:()=>{l&&l(a,u)},disabled:o,className:"flex items-center gap-1 px-3 py-1 bg-blue-600 hover:bg-blue-700 text-white rounded-[6px] text-sm",children:o?"Saving...":"Save"})]})]})}var Xc=t(20939);const Qc=["className"],ed=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,Qc);return(0,re.jsx)(Xc.bL,(0,K.A)((0,K.A)({ref:s,className:is("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",t)},a),{},{children:(0,re.jsx)(Xc.C1,{className:is("flex items-center justify-center text-current"),children:(0,re.jsx)(Pt.A,{className:"h-4 w-4"})})}))});ed.displayName=Xc.bL.displayName;const sd=["className"],td=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,sd);return(0,re.jsx)("textarea",(0,K.A)({className:is("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",t),ref:s},a))});td.displayName="Textarea";var ad=t(41443);const nd=["className","children"],rd=["className","orientation"],ld=H.forwardRef((e,s)=>{let{className:t,children:a}=e,n=(0,as.A)(e,nd);return(0,re.jsxs)(ad.bL,(0,K.A)((0,K.A)({ref:s,className:is("relative overflow-hidden",t)},n),{},{children:[(0,re.jsx)(ad.LM,{className:"h-full w-full rounded-[inherit]",children:a}),(0,re.jsx)(id,{}),(0,re.jsx)(ad.OK,{})]}))});ld.displayName=ad.bL.displayName;const id=H.forwardRef((e,s)=>{let{className:t,orientation:a="vertical"}=e,n=(0,as.A)(e,rd);return(0,re.jsx)(ad.VM,(0,K.A)((0,K.A)({ref:s,orientation:a,className:is("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]",t)},n),{},{children:(0,re.jsx)(ad.lr,{className:"relative flex-1 rounded-full bg-border"})}))});id.displayName=ad.VM.displayName;var od=t(89318),cd=t(81745);function dd(e){let{isOpen:s,onClose:t}=e;const{app:a,updateApp:n}=_s(),[r,l]=(0,H.useState)(""),[i,o]=(0,H.useState)([]),[c,d]=(0,H.useState)([]),[m,u]=(0,H.useState)(!1);(0,H.useEffect)(()=>{if(a){l(a.custom_instructions||""),o(a.frozen_files||[]);const e=[["pages",a.pages],["functions",a.functions],["components",a.components]].flatMap(e=>{let[s,t]=e;return Object.keys(t||{}).map(e=>"".concat(s,"/").concat(e))});d(e)}},[a,s]);const x=e=>{o(e?[...c]:[])};return(0,re.jsx)(Pa,{open:s,onOpenChange:t,children:(0,re.jsxs)(Ma,{className:"max-w-[90vw] sm:max-w-[500px] p-0 overflow-hidden rounded-lg shadow-lg border-0",children:[(0,re.jsx)(Fa,{className:"px-6 pt-5 pb-3 bg-gradient-to-r from-slate-50 to-gray-50",children:(0,re.jsxs)(Ua,{className:"flex items-center gap-2 text-lg font-medium",children:[(0,re.jsx)(od.A,{className:"h-5 w-5 text-gray-700"}),"AI Controls"]})}),(0,re.jsxs)("div",{className:"p-6 space-y-5 overflow-y-auto max-h-[70vh]",children:[(0,re.jsxs)("div",{className:"space-y-3",children:[(0,re.jsx)(Nt,{htmlFor:"custom-instructions",className:"text-sm font-medium flex items-center",children:"Custom Instructions"}),(0,re.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,re.jsx)(td,{id:"custom-instructions",value:r,onChange:e=>l(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,re.jsx)(pt,{className:"my-5"}),(0,re.jsxs)("div",{className:"space-y-3",children:[(0,re.jsxs)("div",{className:"flex justify-between items-center",children:[(0,re.jsxs)(Nt,{className:"text-sm font-medium flex items-center gap-2",children:[(0,re.jsx)(Fs.A,{className:"h-4 w-4 text-gray-700"}),"Freeze Files",i.length>0&&(0,re.jsxs)(et,{variant:"secondary",className:"ml-1 bg-blue-50 text-blue-700 hover:bg-blue-100",children:[i.length," frozen"]})]}),(0,re.jsxs)("div",{className:"flex gap-2",children:[(0,re.jsx)(Hs,{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,re.jsx)(Hs,{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,re.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,re.jsx)(ld,{className:"h-[200px] border border-gray-200 rounded-lg overflow-hidden",children:(0,re.jsx)("div",{className:"p-1",children:c.map(e=>{const s=i.includes(e);return(0,re.jsxs)("div",{className:"flex items-center p-2 rounded-md transition-colors ".concat(s?"bg-blue-50 text-blue-800":"hover:bg-gray-50"),children:[(0,re.jsx)(ed,{id:"freeze-".concat(e),checked:s,onCheckedChange:()=>(e=>{o(s=>s.includes(e)?s.filter(s=>s!==e):[...s,e])})(e),className:s?"border-blue-500 text-blue-600":""}),(0,re.jsxs)("div",{className:"flex-1 flex items-center ml-3",children:[(0,re.jsx)(Nt,{htmlFor:"freeze-".concat(e),className:"cursor-pointer text-sm font-normal flex-1",children:e}),s?(0,re.jsx)(Fs.A,{className:"h-3.5 w-3.5 text-blue-500 ml-2"}):(0,re.jsx)(cd.A,{className:"h-3.5 w-3.5 text-gray-300 ml-2"})]})]},e)})})})]})]}),(0,re.jsx)(Ba,{className:"px-6 py-4 bg-gray-50 border-t border-gray-100",children:(0,re.jsxs)("div",{className:"flex w-full gap-3 sm:justify-end",children:[(0,re.jsx)(Hs,{type:"button",variant:"outline",onClick:t,disabled:m,className:"flex-1 sm:flex-initial border-gray-200",children:"Cancel"}),(0,re.jsx)(Hs,{type:"button",onClick:async()=>{try{u(!0),await n({custom_instructions:r,frozen_files:i}),t()}catch(e){}finally{u(!1)}},disabled:m,className:"flex-1 sm:flex-initial bg-[#2b3440] hover:bg-[#3a4555] text-white",children:m?(0,re.jsxs)("span",{className:"flex items-center gap-2",children:[(0,re.jsx)("span",{className:"h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent"}),"Saving..."]}):(0,re.jsxs)("span",{className:"flex items-center gap-1",children:[(0,re.jsx)(Pt.A,{className:"h-4 w-4"}),"Save Changes"]})})]})})]})})}var md=t(94119),ud=t(52536),xd=t(83817),hd=t(4940),pd=t(36876);function gd(e){let{app:s,writeCodeToFile:t,setContextSelectedElement:a}=e;const[n,r]=(0,H.useState)(!1),[l,i]=(0,H.useState)(null),[o,c]=(0,H.useState)(!1),[d,m]=(0,H.useState)({left:0,top:0}),[u,x]=(0,H.useState)(!1),[h,p]=(0,H.useState)(!1),g=(0,H.useRef)(null),f=(0,H.useRef)(!1),v=(0,H.useRef)(null),b=()=>!Object.keys(s.pages).length||!window.location.pathname.includes("preview")||window.innerWidth<768;(0,H.useEffect)(()=>{if(b())return;const e=document.getElementById("preview-iframe");if(e){g.current=e;const s=()=>{e.getBoundingClientRect();m({left:0,top:-300})};return s(),window.addEventListener("resize",s),()=>window.removeEventListener("resize",s)}},[window.location.pathname]),(0,H.useEffect)(()=>{b()&&(r(!1),c(!1),i(null),a(null))},[window.location.pathname]),(0,H.useEffect)(()=>{if(b())return;const e=e=>{var s;const t=e.data;switch(t.type){case"visual-edit-agent-ready":f.current=!0;break;case"element-selected":const e={tagName:t.tagName,classes:t.classes,linenumber:t.linenumber,dataSourceLocation:t.dataSourceLocation,filename:t.filename,visualSelectorId:t.visualSelectorId,content:t.content,isDynamicContent:t.isDynamicContent,isTextElement:["p","h1","h2","h3","h4","h5","h6","span","a","label"].includes(null===(s=t.tagName)||void 0===s?void 0:s.toLowerCase())};i(e),v.current=t.visualSelectorId,c(!0),a({tagName:t.tagName,dataset:{filename:t.filename,linenumber:t.linenumber}})}};return window.addEventListener("message",e),()=>{window.removeEventListener("message",e)}},[a,window.location.pathname]),(0,H.useEffect)(()=>{},[o,l]);const j=e=>{v.current&&(i(s=>(0,K.A)((0,K.A)({},s),{},{classes:e})),g.current&&g.current.contentWindow.postMessage({type:"update-classes",data:{classes:e,visualSelectorId:v.current}},"*"))},y=e=>{i(s=>(0,K.A)((0,K.A)({},s),{},{content:e})),p(!0),g.current&&g.current.contentWindow.postMessage({type:"update-content",data:{content:e,visualSelectorId:v.current}},"*")},N=()=>{c(!1),g.current&&g.current.contentWindow.postMessage({type:"unselect-element"},"*"),i(null),v.current=null,a(null)},w=async(e,a)=>{if(e&&e.dataSourceLocation)try{x(!0);const n=e.dataSourceLocation,[i,o,c]=n.split(":");let d=i;d.endsWith(".js")&&(d=d.replace(".js",""));const m=parseInt(o,10),u=parseInt(c,10);if(isNaN(m)||isNaN(u))return;const h=(e=>{if(!e)return null;try{if("layout"===e)return s.layout;if(e.startsWith("pages/")){const t=e.split("pages/")[1];return s.pages[t]}if(e.startsWith("components/")){const t=e.split("components/")[1];return s.components[t]}}catch(t){}return null})(d);if(!h)return;const p={className:a};l.isTextElement&&!l.isDynamicContent&&(p.content=l.content);const f=function(e,s,t,a){try{const n=(0,ud.parse)(e,{sourceType:"module",plugins:["jsx","typescript","decorators-legacy","classProperties","objectRestSpread","functionBind","exportDefaultFrom","exportNamespaceFrom","dynamicImport","nullishCoalescingOperator","optionalChaining","asyncGenerators","bigInt","optionalCatchBinding","throwExpressions"]});let r=!1;return(0,xd.default)(n,{JSXElement(e){const n=e.node.openingElement,{start:l}=n.loc||{};if(l&&l.line===s&&l.column===t){if(void 0!==a.className){const e=n.attributes.findIndex(e=>pd.isJSXAttribute(e)&&pd.isJSXIdentifier(e.name)&&"className"===e.name.name),s=pd.jsxAttribute(pd.jsxIdentifier("className"),pd.stringLiteral(a.className));e>=0?n.attributes[e]=s:n.attributes.push(s)}if(void 0!==a.content&&!n.selfClosing){const s=pd.jsxText(a.content);e.node.children=[s]}r=!0,e.stop()}}}),r?{code:(0,hd.default)(n,{retainLines:!0,compact:!1,concise:!1}).code,success:!0,found:!0}:{code:e,success:!0,found:!1,error:"Element not found at line ".concat(s,", column ").concat(t)}}catch(n){return{code:e,success:!1,found:!1,error:n instanceof Error?n.message:"Unknown error"}}}(h,m,u,p);if(!f.success)return;if(!f.found)return;await t(d,f.code),g.current&&g.current.contentWindow.postMessage({type:"refresh-page"},"*"),N(),r(!1)}catch(n){}finally{x(!1)}},_=()=>{g.current&&(g.current.contentWindow.postMessage({type:"refresh-page"},"*"),N(),r(!1))};return{isVisualEditMode:n,selectedElement:l,isFormVisible:o,formPosition:d,isSaving:u,shouldHideSelectElement:b(),toggleVisualEditMode:()=>{const e=!n;r(e),g.current&&f.current&&g.current.contentWindow.postMessage({type:"toggle-visual-edit-mode",data:{enabled:e}},"*"),e||(i(null),v.current=null,c(!1),a(null),g.current&&g.current.contentWindow.postMessage({type:"unselect-element"},"*"))},handleClassesChange:j,handleCloseForm:N,handleSave:w,handleDiscard:_,renderVisualEditsMiddleComponent:e=>o&&l&&!b()?(0,re.jsx)("div",{className:"w-full p-2",children:(0,re.jsxs)("div",{className:"w-full border border-gray-300 bg-white mb-2 flex flex-col rounded-[12px] overflow-hidden",children:[(0,re.jsxs)("div",{className:"p-2 bg-white text-xs text-gray-500 flex justify-between",children:[(0,re.jsxs)("div",{className:"flex items-center gap-2 px-2 py-1",children:[(0,re.jsx)("div",{className:"flex items-center gap-2",children:(0,re.jsx)(cc.A,{className:"text-black",size:20})}),(0,re.jsx)("div",{className:"text-black text-sm",children:"Visual Edit"}),(0,re.jsx)("div",{className:"bg-blue-100 text-blue-600 text-sm rounded-md p-0.5 px-1.5 flex items-center gap-0.5",children:l.isTextElement?(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(md.A,{className:"w-4 h-4"}),l.tagName.toLowerCase()]}):l.tagName.toLowerCase()})]}),(0,re.jsx)("div",{className:"flex items-center gap-2 py-1 px-2",children:(0,re.jsx)("button",{onClick:N,className:"text-gray-500 hover:text-gray-700",children:(0,re.jsx)(zs.A,{className:"text-black hover:text-gray-700",size:20})})})]}),(0,re.jsx)("div",{className:"w-full flex-1 overflow-y-auto",style:{minHeight:"250px"},children:(0,re.jsx)(e,{element:l,onChange:j,onContentChange:y,onClose:()=>{N(),_()},onSave:w,onDiscard:_,isSaving:u})})]})}):null}}var fd=t(69830),vd=t(51981);function bd(e){let{appId:s,onOpenChatSettings:t,frozenFiles:a}=e;const{app:n,updateApp:r}=_s(),{toast:l}=nn(),[i,o]=(0,H.useState)(!1),[c,d]=(0,H.useState)(!1),[m,u]=(0,H.useState)(!1),[x,h]=(0,H.useState)(!1),p=(0,H.useRef)(null);(0,H.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 r({model:e}),u(!1),o(!1),l({title:"AI model updated",description:"Your app is now using a different AI model"})}catch(s){l({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,re.jsxs)("div",{className:"relative",ref:p,children:[(0,re.jsx)("div",{className:"flex items-center",children:(0,re.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,re.jsx)(od.A,{className:"h-4 w-4 transition-transform duration-300 ease-in-out ".concat(i?"rotate-90":"")})})}),i&&(0,re.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,re.jsxs)("div",{className:"relative border-t border-gray-100",children:[(0,re.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,re.jsxs)("div",{className:"flex items-center justify-between",children:[(0,re.jsxs)("div",{className:"flex items-center gap-2",children:[(0,re.jsx)(fd.A,{className:"w-3.5 h-3.5 text-gray-600"}),(0,re.jsxs)("div",{children:[(0,re.jsx)("span",{className:"font-medium",children:"AI Model"}),(0,re.jsx)("div",{className:"text-xs text-gray-500",children:v})]})]}),(0,re.jsx)(ln.A,{className:"w-3 h-3 text-gray-400 transition-transform duration-200 ".concat(m?"rotate-90":"")})]})}),m&&(0,re.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,re.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,re.jsxs)("div",{className:"flex flex-col items-start",children:[(0,re.jsx)("span",{children:"Default"}),(0,re.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,re.jsx)(Pt.A,{className:"w-3.5 h-3.5 text-blue-600 ml-2 flex-shrink-0"})]}),(0,re.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,re.jsx)("span",{children:"Claude Sonnet 4.5"}),"claude_sonnet_4"===n.model&&(0,re.jsx)(Pt.A,{className:"w-3.5 h-3.5 text-blue-600"})]}),(0,re.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,re.jsx)("span",{children:"Gemini 2.5 Pro"}),"gemini_2_5_pro"===n.model&&(0,re.jsx)(Pt.A,{className:"w-3.5 h-3.5 text-blue-600"})]}),(0,re.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,re.jsx)("span",{children:"GPT-5"}),"gpt_5"===n.model&&(0,re.jsx)(Pt.A,{className:"w-3.5 h-3.5 text-blue-600"})]}),x&&(0,re.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,re.jsx)("div",{className:"animate-spin h-3 w-3 border-2 border-blue-500 border-t-transparent rounded-full mr-2"}),"Updating..."]})]})]}),(0,re.jsxs)("button",{onClick:()=>{o(!1),t()},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,re.jsxs)("div",{className:"flex items-center",children:[(0,re.jsx)(vd.A,{size:13,className:"mr-2 text-gray-600"}),(0,re.jsx)("span",{className:"font-medium",children:"AI Controls"})]}),f>0&&(0,re.jsxs)("span",{className:"text-xs text-blue-600 font-medium bg-blue-50 px-1.5 py-0.5 rounded",children:[f," frozen"]})]})]})]})}var jd=t(33252);function yd(e){let{onDismiss:s,onConnectDomain:t}=e;return(0,re.jsx)("div",{className:"px-4 align-center w-full font-base44",children:(0,re.jsx)("div",{className:"rounded-t-xl border border-gray-200 bg-gray-100 ",children:(0,re.jsx)("div",{className:"px-2.5 py-1",children:(0,re.jsxs)("div",{className:"flex items-center justify-between",children:[(0,re.jsxs)("div",{className:"font-light text-gray-700 text-[12px] sm:text-[14px]",children:["Ready for a custom domain?"," ",(0,re.jsx)("button",{onClick:t,className:"text-orange-600 hover:underline hover:text-orange-700 bg-transparent border-none cursor-pointer",children:"Connect a domain"})]}),(0,re.jsx)("button",{onClick:s,className:"text-black hover:text-slate-600 transition-colors p-1 flex-shrink-0 h-[32px] w-[32px] rounded-[6px] hover:bg-gray-100 flex items-center justify-center",children:(0,re.jsx)(zs.A,{className:"h-4 w-4"})})]})})})})}const Nd=e=>{let{isDiscussionMode:s,setIsDiscussionMode:t}=e;return(0,re.jsxs)(Ts,{children:[(0,re.jsx)(Ps,{asChild:!0,children:(0,re.jsxs)("button",{onClick:()=>t(!s),className:"flex items-center gap-1 px-2 py-1 rounded-md text-xs transition-all duration-200 ".concat(s?"bg-violet-50 text-violet-600 hover:bg-violet-100":"text-gray-600 bg-gray-100 hover:bg-gray-200"),children:[(0,re.jsx)(jd.A,{className:"h-3 w-3"}),(0,re.jsx)("span",{children:"Discuss"})]})}),(0,re.jsx)(Ls,{side:"top",align:"end",className:"max-w-[280px]",children:(0,re.jsxs)("div",{className:"space-y-1",children:[(0,re.jsx)("p",{className:"font-medium",children:"Discuss Mode"}),(0,re.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 wd(){const[e,s]=(0,H.useState)(!1),[t,a]=(0,H.useState)(null),[n,r]=(0,H.useState)(!1),[l,i]=(0,H.useState)([]),{app:o,addChatMessage:c,undoMessage:d,stopChat:m,suggestions:u,currentUsage:x,writeCodeToFile:h,setSelectedElement:p,updateApp:g}=_s(),f=(0,Z.Zp)(),[v,b]=(0,H.useState)(!1),{isVisualEditMode:j,isSaving:y,shouldHideSelectElement:N,toggleVisualEditMode:w,handleDiscard:_,renderVisualEditsMiddleComponent:k}=gd({app:o,writeCodeToFile:h,setContextSelectedElement:p});(0,H.useEffect)(()=>{x&&(async()=>{try{const e=await es.default.getStats();a(e)}catch(e){}})()},[x]);const A=!!x&&(x.daily_usage>=(x.daily_limit||1e6)||null!==x.monthly_limit&&void 0!==x.monthly_limit&&x.monthly_usage>=x.monthly_limit),S=A?"0 credits remaining":e?"What would you like to discuss?":"What would you like to change?";(0,H.useEffect)(()=>{(async()=>{if(null!=o&&o.id)try{const e=await Ha.filter({app_id:o.id});i(e)}catch(e){i([])}})()},[null==o?void 0:o.id]);return(0,re.jsxs)("div",{className:"h-full flex flex-col",children:[(0,re.jsx)(oc,{chat:o.conversation,addMessage:s=>(j&&_(),e&&(s.additional_message_params=s.additional_message_params||{},s.additional_message_params.discussion_mode=!0),c(s)),status:o.status,undoMessage:d,onStop:m,suggestions:u,isDisabled:A,isOutOfCredits:A,currentUsage:x,billingStats:t,placeholder:S,isDiscussionMode:e,isVisualEditMode:j,customButtomRight:null,customButtomLeft:t=>(0,re.jsxs)("div",{className:"flex items-center gap-1",children:[(0,re.jsx)(bd,{appId:o.id,onOpenChatSettings:()=>b(!0),frozenFiles:o.frozen_files}),(0,re.jsx)("div",{className:"h-6 w-px bg-gray-200 mx-2"}),t,!N&&(0,re.jsx)(dc,{isVisualEditMode:j,toggleVisualEditMode:w,isSaving:y}),!A&&(0,re.jsx)(Nd,{isDiscussionMode:e,setIsDiscussionMode:s})]}),customMiddleComponent:(0,re.jsxs)("div",{children:[o.custom_domain_suggestion_count>o.custom_domain_suggestion_last_shown_count&&!n&&0===l.length&&(0,re.jsx)(yd,{onDismiss:async()=>{r(!0);try{await g({custom_domain_suggestion_last_shown_count:o.custom_domain_suggestion_count})}catch(e){}},onConnectDomain:async()=>{try{await g({custom_domain_suggestion_last_shown_count:o.custom_domain_suggestion_count})}catch(e){}f("/apps/".concat(o.id,"/editor/workspace/domains"))}}),k(Kc)]})}),(0,re.jsx)(dd,{isOpen:v,onClose:()=>b(!1)})]})}var _d=t(24276),kd=t(18134);const Ad=Mo.bL,Sd=Mo.R6,Cd=Mo.Ke,Ed={overview:_d.A,data:al.A,users:Gr.A,analytics:kd.A,domains:bn.A,security:Ho.A,code:rn.A,logs:al.A,settings:od.A,payments:Ke.A,secrets:al.A,api:rn.A,agents:fd.A},Id=e=>{if(e.id&&e.id.startsWith("entity-"))return null;const s=Ed[e.id];return!s&&e.icon?(0,re.jsx)("div",{className:"min-w-[20px]",children:e.icon}):s?(0,re.jsx)(s,{className:"w-5 h-5"}):null},Td=(e,s)=>e.id===s||!!e.subitems&&e.subitems.some(e=>Td(e,s)),Pd=e=>{let{item:s,selected:t,onSelect:a,searchTerm:n,level:r=0}=e;const l=t===s.id,i=s.subitems&&s.subitems.some(e=>t===e.id||!!e.subitems&&Td(e,t));return!n||s.label.toLowerCase().includes(n.toLowerCase())||s.subitems&&s.subitems.some(e=>e.label.toLowerCase().includes(n.toLowerCase())||e.subitems&&e.subitems.some(e=>e.label.toLowerCase().includes(n.toLowerCase())))?s.subitems?(0,re.jsxs)(Ad,{defaultOpen:l||i,className:is("group",r>0?"ml-3":""),children:[(0,re.jsx)(Sd,{asChild:!0,children:(0,re.jsxs)(Hs,{variant:"ghost",className:is("w-full justify-start px-3 py-2.5 text-sm rounded-lg transition-colors",l||i?"bg-primary/10 text-primary":"text-foreground hover:bg-gray-100"),children:[(0,re.jsx)("div",{className:is("w-6 h-6 flex items-center justify-center",l?"text-primary":"text-muted-foreground"),children:Id(s)}),(0,re.jsx)("span",{className:"ml-3 truncate",children:s.label}),s.badge&&(0,re.jsx)(et,{variant:"secondary",className:"ml-auto mr-2 px-1.5 py-0 text-xs",children:s.badge}),(0,re.jsx)("div",{className:s.badge?"":"ml-auto",children:(0,re.jsx)(It.A,{className:"h-4 w-4 transition-transform group-data-[state=open]:rotate-180 text-muted-foreground"})})]})}),(0,re.jsxs)(Cd,{className:"mt-1 relative",children:[(0,re.jsx)("div",{className:"absolute left-6 top-0 bottom-0 w-px bg-gray-200"}),s.subitems.map((e,s)=>(0,re.jsx)(Pd,{item:e,selected:t,onSelect:a,searchTerm:n,level:r+1},s))]})]}):(0,re.jsxs)(Hs,{variant:"ghost",className:is("w-full justify-start px-3 py-2.5 text-sm rounded-lg transition-colors",l?"bg-primary/10 text-primary":"text-foreground hover:bg-gray-100"),onClick:()=>a(s.id),children:[(0,re.jsx)("div",{className:is("w-6 h-6 flex items-center justify-center",l?"text-primary":"text-muted-foreground"),children:Id(s)}),(0,re.jsx)("span",{className:"ml-3 truncate",children:s.label}),s.badge&&(0,re.jsx)(et,{variant:"secondary",className:"ml-auto px-1.5 py-0 text-xs",children:s.badge})]}):null},Ld=e=>{let{items:s,selected:t,onSelect:a,isOpen:n,onClose:r,title:l,showBackButton:i,onBack:o,showSearch:c=!1,style:d}=e;const[m,u]=(0,H.useState)(""),[x,h]=(0,H.useState)(!1);return(0,re.jsxs)(re.Fragment,{children:[(0,re.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:r}),(0,re.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,re.jsx)("div",{className:"p-2 flex justify-end lg:hidden",children:(0,re.jsx)(Hs,{variant:"ghost",size:"icon",onClick:r,children:(0,re.jsx)(zs.A,{className:"h-4 w-4"})})}),i&&(0,re.jsxs)(Hs,{variant:"ghost",className:"justify-start mx-3 mb-2 px-4 text-sm",onClick:o,children:[(0,re.jsx)(ln.A,{className:"h-4 w-4 mr-2 rotate-180"}),"Back to Editor"]}),c&&(0,re.jsx)("div",{className:"px-3 pt-2 pb-4",children:(0,re.jsxs)("div",{className:is("relative flex items-center",x?"ring-2 ring-ring":""),children:[(0,re.jsx)(vn.A,{className:"absolute left-3 h-4 w-4 text-muted-foreground"}),(0,re.jsx)("input",{type:"text",placeholder:"Search...",value:m,onChange:e=>u(e.target.value),className:is("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,re.jsx)("nav",{className:"flex-1 overflow-y-auto py-1 px-3 space-y-1 scrollbar-thin scrollbar-thumb-muted",children:s.map((e,s)=>(0,re.jsx)(Pd,{item:e,selected:t,onSelect:a,searchTerm:m},s))})]})]})};var Od=t(58907),Rd=t(27255),Dd=t(98989);var Md=t(34079);const Fd=["className"],Bd=["children"],Ud=["className"],zd=["className"],qd=["className"],Wd=["className"],Vd=["className"],Yd=["className"],Hd=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,Fd);return(0,re.jsx)(Md.uB,(0,K.A)({ref:s,className:is("flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",t)},a))});Hd.displayName=Md.uB.displayName;const Gd=e=>{let{children:s}=e,t=(0,as.A)(e,Bd);return(0,re.jsx)(Pa,(0,K.A)((0,K.A)({},t),{},{children:(0,re.jsx)(Ma,{className:"overflow-hidden p-0 shadow-lg",children:(0,re.jsx)(Hd,{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:s})})}))},$d=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,Ud);return(0,re.jsxs)("div",{className:"flex items-center border-b px-3","cmdk-input-wrapper":"",children:[(0,re.jsx)(vn.A,{className:"mr-2 h-4 w-4 shrink-0 opacity-50"}),(0,re.jsx)(Md.uB.Input,(0,K.A)({ref:s,className:is("flex h-11 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",t)},a))]})});$d.displayName=Md.uB.Input.displayName;const Jd=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,zd);return(0,re.jsx)(Md.uB.List,(0,K.A)({ref:s,className:is("max-h-[300px] overflow-y-auto overflow-x-hidden",t)},a))});Jd.displayName=Md.uB.List.displayName;const Zd=H.forwardRef((e,s)=>(0,re.jsx)(Md.uB.Empty,(0,K.A)({ref:s,className:"py-6 text-center text-sm"},e)));Zd.displayName=Md.uB.Empty.displayName;const Kd=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,qd);return(0,re.jsx)(Md.uB.Group,(0,K.A)({ref:s,className:is("overflow-hidden p-1 text-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",t)},a))});Kd.displayName=Md.uB.Group.displayName;const Xd=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,Wd);return(0,re.jsx)(Md.uB.Separator,(0,K.A)({ref:s,className:is("-mx-1 h-px bg-border",t)},a))});Xd.displayName=Md.uB.Separator.displayName;const Qd=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,Vd);return(0,re.jsx)(Md.uB.Item,(0,K.A)({ref:s,className:is("relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none data-[disabled=true]:pointer-events-none data-[selected='true']:bg-accent data-[selected=true]:text-accent-foreground data-[disabled=true]:opacity-50",t)},a))});Qd.displayName=Md.uB.Item.displayName;const em=e=>{let{className:s}=e,t=(0,as.A)(e,Yd);return(0,re.jsx)("span",(0,K.A)({className:is("ml-auto text-xs tracking-widest text-muted-foreground",s)},t))};em.displayName="CommandShortcut";const sm=e=>{let{value:s,onChange:t,options:a,isMulti:n,placeholder:r,optionsNames:l=null}=e;const i=a.map((e,s)=>null==e?{label:(null==l?void 0:l[s])||"null",value:null}:"object"==typeof e?{label:e.label||l[s],value:e.value}:{label:l?l[s]:e,value:e});let o=[];if(s)if(n)o=s.map(e=>i.find(s=>s.value===e)).filter(Boolean);else{const e=i.find(e=>e.value===s);e&&(o=[e])}const c=e=>{const s=o.filter(s=>s.value!==e.value);t(s.map(e=>e.value))};var d;return n?(0,re.jsxs)(Hd,{className:"border rounded-md",children:[(0,re.jsx)("div",{className:"flex gap-1 flex-wrap p-2",children:null===(d=o)||void 0===d?void 0:d.map(e=>(0,re.jsxs)(et,{variant:"secondary",className:"max-w-[200px]",children:[(0,re.jsx)("span",{className:"truncate",children:e.label}),(0,re.jsx)("button",{className:"ml-1 ring-offset-background rounded-full outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",onKeyDown:s=>{"Enter"===s.key&&c(e)},onMouseDown:e=>{e.preventDefault(),e.stopPropagation()},onClick:()=>c(e),children:(0,re.jsx)(zs.A,{className:"h-3 w-3 text-muted-foreground hover:text-foreground"})})]},e.value))}),(0,re.jsx)($d,{placeholder:r||"Search...",className:"border-none focus:ring-0"}),(0,re.jsx)(Kd,{className:"max-h-[200px] overflow-auto",children:0===(null==i?void 0:i.length)?(0,re.jsx)("div",{className:"py-6 text-center text-sm text-muted-foreground",children:"No options available"}):null==i?void 0:i.map(e=>{var s;return(0,re.jsx)("div",{className:"cursor-pointer px-2 py-1.5 ".concat(null!==(s=o)&&void 0!==s&&s.some(s=>s.value===e.value)?"bg-muted":""),onClick:()=>(e=>{if(n){const s=o.some(s=>s.value===e.value)?o.filter(s=>s.value!==e.value):[...o,e];t(s.map(e=>e.value))}else t(e.value)})(e),children:e.label},e.value)})})]}):(0,re.jsxs)(Ut,{value:null==s?void 0:s.toString(),onValueChange:e=>t(e),children:[(0,re.jsx)(Wt,{children:(0,re.jsx)(qt,{placeholder:r})}),(0,re.jsx)(Ht,{children:(0,re.jsx)(zt,{children:0===i.length?(0,re.jsx)("div",{className:"py-6 text-center text-sm text-muted-foreground",children:"No options available"}):i.map(e=>{var s;return(0,re.jsx)($t,{value:(null===(s=e.value)||void 0===s?void 0:s.toString())||null,children:e.label},e.value||"null")})})})]})};function tm(e){let{value:s,onChange:t,name:a,itemSchema:n,isMulti:r=!1}=e;const{getEntitiesSDK:l}=_s(),[i,o]=(0,H.useState)([]),[c,d]=(0,H.useState)(!1),m=l();return(0,H.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 s=e[2];m[s].list().then(e=>{o(e.map(e=>{const t=m[s].schema();let a="id";for(const s in t.properties)if(s.toLowerCase().includes("name")||s.toLowerCase().includes("title")){a=s;break}return{label:e[a],value:e.id}})),d(!1)})},[n.$ref]),c?(0,re.jsx)("div",{children:"Loading..."}):(0,re.jsx)(sm,{options:i,onChange:t,isMulti:r,value:s})}var am=t(53938);const nm=["className","classNames","showOutsideDays"];function rm(e){let{className:s,classNames:t,showOutsideDays:a=!0}=e,n=(0,as.A)(e,nm);return(0,re.jsx)(am.hv,(0,K.A)({showOutsideDays:a,className:is("p-3",s),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:is(Ys({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:is(Ys({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"},t),components:{IconLeft:e=>{Object.assign({},((0,Ja.A)(e),e));return(0,re.jsx)(Qt.A,{className:"h-4 w-4"})},IconRight:e=>{Object.assign({},((0,Ja.A)(e),e));return(0,re.jsx)(ln.A,{className:"h-4 w-4"})}}},n))}rm.displayName="Calendar";var lm=t(32264),im=t(19201),om=t(48367);const cm=["className","align","sideOffset"],dm=om.bL,mm=om.l9,um=H.forwardRef((e,s)=>{let{className:t,align:a="center",sideOffset:n=4}=e,r=(0,as.A)(e,cm);return(0,re.jsx)(om.ZL,{children:(0,re.jsx)(om.UC,(0,K.A)({ref:s,align:a,sideOffset:n,className:is("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",t)},r))})});function xm(e){let{value:s,onChange:t,format:a="date",className:n}=e;const r=(e,s)=>{if(s){const[t,a]=s.split(":");e.setHours(parseInt(t)),e.setMinutes(parseInt(a))}t(e)};let l=s;return l=null==s||""===s?null:new Date(s),(0,re.jsxs)(dm,{children:[(0,re.jsx)(mm,{asChild:!0,children:(0,re.jsxs)(Hs,{variant:"outline",className:is("w-full justify-start text-left font-normal",!l&&"text-muted-foreground",n),children:[(0,re.jsx)(im.A,{className:"mr-2 h-4 w-4"}),l?"date"===a?(0,lm.GP)(l,"PPP"):"date-time"===a?(0,lm.GP)(l,"PPP HH:mm:ss"):(0,lm.GP)(l,"HH:mm:ss"):(0,re.jsx)("span",{children:"Pick a date"})]})}),(0,re.jsx)(um,{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,re.jsxs)("div",{className:"p-3 bg-popover shadow-lg rounded-md border",style:{pointerEvents:"auto"},children:[(0,re.jsx)(rm,{mode:"single",selected:l,onSelect:e=>r(e),initialFocus:!0,className:"pointer-events-auto"}),("date-time"===a||"time"===a)&&(0,re.jsx)("input",{type:"time",className:"mt-3 w-full px-3 py-2 border rounded pointer-events-auto",value:l?(0,lm.GP)(l,"HH:mm"):"",onChange:e=>r(l||new Date,e.target.value)})]})})]})}um.displayName=om.UC.displayName;var hm=t(77834);function pm(e){let{value:s,onChange:t,isMulti:a}=e;const n=_s(),[r,l]=(0,H.useState)([]),[i,o]=(0,H.useState)(!1);(0,H.useEffect)(()=>{if(s){l((a?s:[s]).map(e=>({name:e.split("/").pop(),url:e})))}},[s,a]);const c=(0,H.useCallback)(async e=>{o(!0);try{const s=await Promise.all(e.map(async e=>{const s=null!=n&&n.app?await As.uploadAppFile(e,n.app.id):await As.uploadFile(e);return{name:e.name,url:s.url}}));l(e=>{const t=a?[...e,...s]:s;return d(t),t})}catch(s){}finally{o(!1)}},[a,t]),d=e=>{t(a?e.map(e=>e.url):e.length>0?e[0].url:null)};return(0,re.jsxs)("div",{className:"w-full",children:[(0,re.jsxs)("div",{className:is("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,re.jsx)("div",{className:"loading loading-spinner"}):(0,re.jsx)(hm.A,{className:"h-5 w-5 text-muted-foreground"}),(0,re.jsx)("input",{id:"fileInput",type:"file",multiple:a,className:"hidden",onChange:e=>c(Array.from(e.target.files||[])),disabled:i})]}),r.length>0&&(0,re.jsx)("div",{className:"mt-2 space-y-1",children:r.map((e,s)=>(0,re.jsxs)("div",{className:"flex items-center justify-between bg-muted/50 p-1 rounded",children:[(0,re.jsx)("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",className:"text-xs hover:underline truncate",children:e.name}),(0,re.jsx)(Hs,{variant:"ghost",size:"icon",onClick:()=>{return s=e,void l(e=>{const t=e.filter(e=>e!==s);return d(t),t});var s},className:"h-4 w-4 p-0",children:(0,re.jsx)(zs.A,{className:"h-3 w-3"})})]},s))})]})}const gm=e=>{let{value:s,onChange:t}=e;return(0,re.jsx)(ed,{checked:s,onCheckedChange:t})},fm=e=>{let{value:s,onChange:t}=e;const[a,n]=(0,H.useState)("");return(0,re.jsxs)("div",{className:"flex flex-wrap items-center border rounded-md p-1",children:[s&&s.map((e,a)=>(0,re.jsxs)("span",{className:"bg-gray-200 rounded-md px-2 py-1 m-1 flex items-center",children:[e,(0,re.jsx)("button",{type:"button",onClick:()=>(e=>{const a=s.filter((s,t)=>t!==e);t(a)})(a),className:"ml-1 text-gray-500 hover:text-gray-700 focus:outline-none",children:"\xd7"})]},a)),(0,re.jsx)("input",{type:"text",value:a,onChange:e=>{n(e.target.value)},onKeyDown:e=>{if("Enter"===e.key&&a.trim()){e.preventDefault();const r=[...s||[],a.trim()];t(r),n("")}else if("Backspace"===e.key&&!a&&s&&s.length>0){const e=s.slice(0,-1);t(e)}},className:"flex-grow outline-none px-2 py-1",placeholder:"enter values..."})]})};function vm(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 bm(e){let{path:s,schema:t,value:a,setValueAt:n,getValueAt:r,uiSchema:l,validationErrors:i}=e;const o=a||[];if("string"===t.items.type&&!t.items.$ref&&!t.items.enum&&!t.items.format)return(0,re.jsx)(fm,{value:o,onChange:e=>n(s,e)});if("string"===t.items.type&&t.items.enum)return(0,re.jsx)(sm,{options:t.items.enum,isMulti:!0,value:o,onChange:e=>n(s,e),optionsNames:t.items.enumNames});if("string"===t.items.type&&"file"===t.items.format)return(0,re.jsx)(pm,{value:o,onChange:e=>n(s,e),isMulti:!0});if(t.items.$ref)return(0,re.jsx)(tm,{value:o,onChange:e=>n(s,e),name:s[s.length-1],itemSchema:t.items,isMulti:!0});const c=t.items.default||"object"===t.items.type?{}:null;if(!t.hasOwnProperty("items"))throw new Error("Error in json schema for array: items is required. path: ".concat(s.join(".")));return(0,re.jsxs)("div",{className:"space-y-4 ps-4 border-s-2 border-gray-200",children:[o.map((e,a)=>(0,re.jsxs)("div",{className:"relative",children:[(0,re.jsx)("button",{className:"absolute top-0 right-0 p-1 text-gray-500 hover:text-gray-700",onClick:()=>(e=>{const t=[...o];t.splice(e,1),n(s,t)})(a),children:(0,re.jsx)(zs.A,{size:16})}),(0,re.jsx)(ym,{path:[...s,a],value:e,schema:t.items,setValueAt:n,getValueAt:r,uiSchema:l,validationErrors:i[a]||{}},a)]},a)),(0,re.jsx)("div",{className:"mt-2",children:(0,re.jsxs)("button",{type:"button",onClick:e=>{e.preventDefault(),n([...s,o.length],c)},className:"btn btn-outline btn-sm",children:[(0,re.jsx)(Ss.A,{size:16})," Add Item"]})})]})}function jm(e){let{path:s,schema:t,value:a,setValueAt:n,getValueAt:r,uiSchema:l,validationErrors:i,suppressLabel:o}=e;const c=a||{},[d,m]=H.useState(""),[u,x]=H.useState(vm(t.additionalProperties));return(0,re.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,re.jsx)("div",{children:(0,re.jsxs)("div",{className:"flex items-center gap-4 mb-1",children:[(0,re.jsx)("div",{className:"flex-1 mt-4",children:(0,re.jsx)(ft,{type:"text",value:a,disabled:!0,className:"bg-gray-50"})}),(0,re.jsx)("div",{className:"flex-1",children:(0,re.jsx)(ym,{path:[...s,a],value:o,schema:t.additionalProperties,setValueAt:n,getValueAt:r,uiSchema:l,validationErrors:i[a]||{},suppressLabel:!0})}),(0,re.jsx)("button",{className:"mt-4 p-1 text-gray-500 hover:text-gray-700",onClick:()=>(e=>{const t=(0,K.A)({},c);delete t[e],n(s,t)})(a),"aria-label":"Remove",children:(0,re.jsx)(zs.A,{size:16})})]})},a)}),(0,re.jsxs)("div",{children:[(0,re.jsxs)("div",{className:"flex items-center gap-4",children:[(0,re.jsx)("div",{className:"flex-1 mt-4",children:(0,re.jsx)(ft,{type:"text",value:d,onChange:e=>m(e.target.value),placeholder:"Key",className:"flex-1"})}),(0,re.jsx)("div",{className:"flex-1",children:(0,re.jsx)(ym,{path:[...s,"new"],value:u,schema:t.additionalProperties,setValueAt:(e,s)=>x(s),getValueAt:()=>u,uiSchema:l,validationErrors:{},suppressLabel:!0})})]}),(0,re.jsx)("div",{className:"mt-2 flex",children:(0,re.jsx)("button",{type:"button",onClick:e=>{if(e.preventDefault(),!d)return;const a=(0,K.A)({},c);a[d]=u,n(s,a),m(""),x(vm(t.additionalProperties))},className:"btn btn-outline btn-sm",children:"+ Add"})})]})]})}function ym(e){let{path:s,getValueAt:t,setValueAt:a,schema:n,uiSchema:r,validationErrors:l,suppressLabel:i}=e;if("hidden"===r["ui:widget"])return(0,re.jsx)(re.Fragment,{});if(!n)throw new Error("Error in json schema: schema for the property is required. property path: ".concat(s.join(".")));const o=void 0===t(s)?n.default||null:t(s);let c;if(!i)if(r["ui:title"])c=r["ui:title"];else if(n.title)c=n.title;else{const e=s[s.length-1];c="number"==typeof e?void 0:e}return(0,re.jsxs)("div",{className:"mt-4",children:[c&&(0,re.jsxs)("div",{className:"mb-2",children:[(0,re.jsx)("label",{htmlFor:s.join("__"),className:"text-sm font-medium text-gray-900",children:c}),n.description&&(0,re.jsx)("p",{className:"text-sm text-gray-500",children:n.description})]}),(()=>{if(ts().isFunction(r["ui:widget"]))return r["ui:widget"]({value:o,onChange:e=>a(s,e),getValueAt:t,setValueAt:a,schema:n,uiSchema:r,path:s});if(n.enum&&"array"!==n.type&&"object"!==n.type)return(0,re.jsx)(sm,{options:n.enum,optionsNames:n.enumNames,value:o,onChange:e=>a(s,e)});if(n.$ref)return(0,re.jsx)(tm,{value:o,onChange:e=>a(s,e),name:s[s.length-1],itemSchema:n});if("string"===n.type)return"date"===n.format||"date-time"===n.format||"time"===n.format?(0,re.jsx)(xm,{format:n.format,value:o,onChange:e=>a(s,e)}):"file"===n.format?(0,re.jsx)(pm,{value:o,onChange:e=>a(s,e)}):"textarea"===r["ui:widget"]?(0,re.jsx)(td,{value:o||"",onChange:e=>a(s,e.target.value)}):(0,re.jsx)(ft,{type:"text",value:o||"",onChange:e=>a(s,e.target.value)});if("number"===n.type||"integer"===n.type)return(0,re.jsx)(ft,{type:"number",value:o||"",onChange:e=>a(s,parseFloat(e.target.value)),min:n.minimum,max:n.maximum,step:"integer"===n.type?1:"any"});if("boolean"===n.type)return(0,re.jsx)(gm,{value:o,onChange:e=>a(s,e)});if("array"===n.type)return(0,re.jsx)(bm,{path:s,schema:n,value:o,setValueAt:a,getValueAt:t,uiSchema:r.hasOwnProperty("items")?r.items:r,validationErrors:l});if("object"===n.type){if(n.additionalProperties)return(0,re.jsx)(jm,{path:s,schema:n,value:o,setValueAt:a,getValueAt:t,uiSchema:r,validationErrors:l,suppressLabel:i});if(!n.properties)throw new Error("Error in json schema: properties is required for object type. property path: ".concat(s.join("."),". if you need the user to insert a flexible object, JsonSchemaFrom might not be the right choice"));return(0,re.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,re.jsx)(ym,{path:[...s,n],getValueAt:t,setValueAt:a,schema:i,uiSchema:r[n]||{},validationErrors:l[n]||{}},n)})})}})(),l&&ts().isString(l)&&(0,re.jsx)("div",{style:{color:"red"},children:l})]})}function Nm(e,s,t){if(0===s.length)return t;const[a,...n]=s,r=ts().isNumber(n[0]),l=ts().isArray(e)?[...e]:(0,K.A)({},e);return 0===n.length?l[a]=t:l[a]=Nm(r?l[a]||[]:l[a]||{},n,t),l}function wm(e,s){if(ts().isNil(e)||0===s.length)return e;const[t,...a]=s;return 0===a.length?e[t]:wm(e[t],a)}const _m=e=>{let{schema:s,onChange:t,onSubmit:a,initialValues:n,uiSchema:r}=e;const[l,i]=(0,H.useState)(n||{}),[o,c]=(0,H.useState)({});if(!s||ts().isEmpty(s)||ts().isEmpty(s.properties))throw new Error("Error In JsonSchemaForm: valid json schema is required, but got: "+JSON.stringify(s));const d=function(e,s){let t=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,r]=e;const l=[...t,n],i=d(r,s,l);ts().isEmpty(i)||(a[n]=i)});const n=function(e){if(!e||(0,ss.isEmpty)(e))throw new Error("JSON Schema error is required, got: "+JSON.stringify(e));if((0,ss.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 l=[...t,n],i=wm(s,l)||e.properties[n].default,o=wm(r,l),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){(wm(s,t)||[]).forEach((n,r)=>{const l=[...t,r],i=d(e.items,s,l);ts().isEmpty(i)||(a[r]=i)})}return a},m=(e,s)=>{const a=Nm(l,e,s);i(a),t&&t(a)};if(ts().isFunction(r)&&(r=r(l)),r&&"object"==typeof r){const e={};Object.entries(r).forEach(s=>{let[t,a]=s;const n=t.split(".");let r=e;for(let e=0;e{let[s,t]=e;return(0,re.jsx)(ym,{path:[s],value:l[s],setValueAt:m,getValueAt:e=>wm(l,e),schema:t,uiSchema:(r||{})[s]||{},validationErrors:o[s]||{}},s)}),a&&(0,re.jsx)("div",{className:"mt-4",children:(0,re.jsx)(Hs,{onClick:e=>{e.preventDefault();(()=>{const e=d(s,l);return c(e),ts().isEmpty(e)})()?a(l):(0,Xr.toast)("some fields are required: "+Object.keys(o).join(", "))},children:"Submit"})})]})},km=_m,Am=e=>{let{isOpen:s,onClose:t,title:a,children:n}=e;return s?(0,re.jsx)("div",{className:"modal modal-open",children:(0,re.jsxs)("div",{className:"modal-box",children:[(0,re.jsx)("h3",{className:"font-bold text-lg",children:a}),(0,re.jsx)("div",{className:"py-4",children:n}),(0,re.jsx)("div",{className:"modal-action",children:(0,re.jsx)("button",{className:"btn",onClick:t,children:"Close"})})]})}):null},Sm={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 Cm(e){let s=ts().cloneDeep(Sm);return"array"===e.type&&(e.items?s.properties.items=Cm(e.items):s.properties.items=ts().cloneDeep(Sm)),"string"===e.type&&(s.properties.format={type:"string",title:"Format",default:null,enum:["date","email","file","uri","date-time","ipv4","ipv6","regex"]},"file"!==e.format&&(s.properties.enum={type:"array",title:"Enum",default:null,items:{type:"string"}})),e.type,s}function Em(e){let{value:s,onSubmit:t}=e;const[a,n]=(0,H.useState)(s),r=Cm(a);return(0,re.jsx)(km,{schema:r,initialValues:a,onChange:e=>{n(e)},onSubmit:t})}var Im=t(388),Tm=t(59807),Pm=t(81807),Lm=t(78541),Om=t(14754);function Rm(e,s){if(s.$ref)return(0,re.jsx)(jl.A,{size:16});switch(e){case"array":return(0,re.jsx)(wr.A,{size:16});case"date-time":case"date":return(0,re.jsx)(im.A,{size:16});case"email":return(0,re.jsx)(Im.A,{size:16});case"uri":case"url":return(0,re.jsx)(Tm.A,{size:16});case"number":return(0,re.jsx)(Pm.A,{size:16});case"boolean":return(0,re.jsx)(Lm.A,{size:16});case"object":return(0,re.jsx)(Om.A,{size:16});default:return(0,re.jsx)(al.A,{size:16})}}function Dm(e){let{name:s,prop:t,schema:a,onEdit:n}=e;const r=Object.entries(t).filter(e=>{let[s]=e;return!["type","description","default","title","format","$ref","enum","items","properties","required"].includes(s)}),l=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 s=e.$ref.split("/");return s[s.length-2]}return"text"}return e.type}(t);return(0,re.jsx)("li",{className:"py-4",children:(0,re.jsxs)("div",{className:"flex flex-col space-y-2",children:[(0,re.jsx)("div",{className:"flex items-center justify-between",children:(0,re.jsxs)("div",{className:"flex items-center",children:[(0,re.jsx)("h5",{className:"font-semibold text-gray-900 me-2",children:t.title||s})," ("," ",Rm(l,t),(0,re.jsx)("span",{className:"ml-1",children:l}),a.required&&a.required.includes(s)&&(0,re.jsx)("span",{className:"ml-2",children:", required"}),")"]})}),t.description&&(0,re.jsx)("p",{className:"text-sm text-gray-700",children:t.description}),void 0!==t.default&&(0,re.jsxs)("div",{className:"text-sm",children:[(0,re.jsx)("span",{className:"font-medium",children:"Default:"})," ",JSON.stringify(t.default)]}),t.enum&&(0,re.jsxs)("div",{className:"text-sm",children:[(0,re.jsx)("span",{className:"font-medium",children:"Options:"})," ",t.enum.join(", ")]}),t.items&&(0,re.jsx)("div",{className:"ps-6 border-s-4 border-gray-300",children:(0,re.jsx)(Mm,{schema:t.items})}),t.properties&&(0,re.jsx)("div",{className:"ps-6 border-s-4 border-gray-300",children:(0,re.jsx)(Mm,{schema:t})}),r.length>0&&(0,re.jsxs)("div",{className:"mt-2",children:[(0,re.jsx)("h4",{className:"text-sm font-medium text-gray-900",children:"Additional Properties:"}),(0,re.jsx)("ul",{className:"mt-1 space-y-1",children:r.map(e=>{let[s,t]=e;return(0,re.jsxs)("li",{className:"text-sm text-gray-600",children:[(0,re.jsxs)("span",{className:"font-medium",children:[s,":"]})," ",JSON.stringify(t)]},s)})})]})]})},s)}function Mm(e){let{schema:s,onEdit:t}=e;const[a,n]=(0,H.useState)(null),r=(e,s)=>{n({name:e,prop:s})};return(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)("ul",{className:"ps-4 border-s-4 border-gray-300",children:Object.entries(s.properties||{}).map(e=>{let[a,n]=e;return(0,re.jsx)(Dm,{name:a,prop:n,schema:s,onEdit:t?r:null},a)})}),a&&(0,re.jsx)(Am,{isOpen:!!a,onClose:()=>{n(null)},title:"Edit ".concat(a.name),children:(0,re.jsx)(Em,{value:a.prop,onSubmit:e=>{t&&t(a.name,e),n(null)}})})]})}const Fm=["className"],Bm=["side","className","children"],Um=["className"],zm=["className"],qm=["className"],Wm=["className"],Vm=ka.Root,Ym=ka.Trigger,Hm=ka.Close,Gm=ka.Portal,$m=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,Fm);return(0,re.jsx)(ka.Overlay,(0,K.A)((0,K.A)({className:is("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",t)},a),{},{ref:s}))});$m.displayName=ka.Overlay.displayName;const Jm=(0,ns.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"}}),Zm=H.forwardRef((e,s)=>{let{side:t="right",className:a,children:n}=e,r=(0,as.A)(e,Bm);return(0,re.jsxs)(Gm,{children:[(0,re.jsx)($m,{}),(0,re.jsxs)(ka.Content,(0,K.A)((0,K.A)({ref:s,className:is(Jm({side:t}),a)},r),{},{children:[n,(0,re.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,re.jsx)(zs.A,{className:"h-4 w-4"}),(0,re.jsx)("span",{className:"sr-only",children:"Close"})]})]}))]})});Zm.displayName=ka.Content.displayName;const Km=e=>{let{className:s}=e,t=(0,as.A)(e,Um);return(0,re.jsx)("div",(0,K.A)({className:is("flex flex-col space-y-2 text-center sm:text-left",s)},t))};Km.displayName="SheetHeader";const Xm=e=>{let{className:s}=e,t=(0,as.A)(e,zm);return(0,re.jsx)("div",(0,K.A)({className:is("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",s)},t))};Xm.displayName="SheetFooter";const Qm=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,qm);return(0,re.jsx)(ka.Title,(0,K.A)({ref:s,className:is("text-lg font-semibold text-foreground",t)},a))});Qm.displayName=ka.Title.displayName;const eu=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,Wm);return(0,re.jsx)(ka.Description,(0,K.A)({ref:s,className:is("text-sm text-muted-foreground",t)},a))});eu.displayName=ka.Description.displayName;const su=e=>{let{children:s,className:t,title:a,prefix:n,subtitle:r,primaryAction:l,actions:i,filters:o,content:c}=e;return(0,re.jsxs)("div",{className:is("flex flex-col p-6 gap-6 h-full font-base44 md:max-w-[1200px] mx-auto",t),children:[(0,re.jsxs)("div",{className:"grid grid-cols-[".concat(n?"min-content_":"","1fr_max-content] gap-6"),children:[n&&(0,re.jsx)("div",{className:"flex mr-2",children:n}),(0,re.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,re.jsx)("h2",{className:"font-semibold text-xl",children:a}),r&&(0,re.jsx)("p",{className:"text-sm text-[#71717A] font-normal",children:r})]}),(i||l)&&(0,re.jsxs)("div",{className:"flex flex-row gap-2 items-center",children:[i,l]})]}),o&&(0,re.jsx)("div",{className:"flex md:flex-row md:items-center flex-wrap gap-2 w-full items-left",children:o}),(0,re.jsxs)("div",{className:"flex flex-col gap-3 pb-6",children:[c,s]})]})};function tu(e){let{entity:s}=e;const{app:t,updateApp:a}=_s();return(0,re.jsx)(Mm,{schema:s,onEdit:(e,n)=>{s.properties[e]=n,t.entities[s.name]=s,a({entities:t.entities})}})}const au=function(e){let{entity:s}=e;const{app:t,getEntitiesSDK:a}=_s(),{toast:n}=nn(),[r,l]=(0,H.useState)([]),[i,o]=(0,H.useState)(!0),[c,d]=(0,H.useState)(!1),[m,u]=(0,H.useState)(!1),[x,h]=(0,H.useState)(null),[p,g]=(0,H.useState)(!1),[f,v]=(0,H.useState)(!1),[b,j]=(0,H.useState)(!1),y=a(),N=async()=>{o(!0);try{const e=await y[s.name].list();l(e)}catch(e){n({title:"Error",description:"Failed to load records",variant:"destructive"})}finally{o(!1)}};return(0,H.useEffect)(()=>{N()},[s]),(0,re.jsxs)(su,{title:s.name,subtitle:s.description,primaryAction:(0,re.jsxs)(Hs,{size:"sm",onClick:()=>{h(null),d(!0)},children:[(0,re.jsx)(Ss.A,{className:"h-4 w-4 mr-2"}),"Add"]}),actions:[(0,re.jsx)(ft,{type:"file",accept:".csv",className:"hidden",id:"csv-upload",onChange:async e=>{const t=e.target.files[0];if(t){g(!0);try{const e=await y[s.name].importEntities(t);"success"===e.status&&(n({title:"Import Successful",description:"Successfully imported ".concat(e.n_entities_created," ").concat(s.name," records")}),N())}catch(l){var a,r;n({title:"Import Failed",description:(null===(a=l.response)||void 0===a||null===(r=a.data)||void 0===r?void 0:r.message)||l.message,variant:"destructive"})}finally{g(!1),e.target.value=""}}},disabled:p}),(0,re.jsxs)(Pl,{children:[(0,re.jsx)(Ll,{asChild:!0,children:(0,re.jsx)(Hs,{size:"sm",variant:"outline",children:(0,re.jsx)(kr.A,{className:"h-4 w-4"})})}),(0,re.jsxs)(Ul,{align:"end",children:[(0,re.jsxs)(zl,{onClick:()=>document.getElementById("csv-upload").click(),disabled:p,children:[p?(0,re.jsx)(Ze.A,{className:"h-4 w-4 animate-spin mr-2"}):(0,re.jsx)(Od.A,{className:"h-4 w-4 mr-2"}),"Import"]}),(0,re.jsxs)(zl,{onClick:async()=>{v(!0);try{const e=await y[s.name].list(),t=Object.keys(e[0]||{}),a=[t.join(","),...Object.values(e).map(e=>t.map(s=>{const t=e[s];let a;a="object"==typeof t&&null!==t?JSON.stringify(t):String(t||"");const n=a.replace(/"/g,'""');return'"'.concat(n,'"')}).join(","))],r=a.join("\n"),l=new Blob([r],{type:"text/csv"}),i=window.URL.createObjectURL(l),o=document.createElement("a");o.href=i,o.download="".concat(s.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(a){var e,t;n({title:"Export Failed",description:(null===(e=a.response)||void 0===e||null===(t=e.data)||void 0===t?void 0:t.message)||a.message,variant:"destructive"})}finally{v(!1)}},disabled:f,children:[f?(0,re.jsx)(Ze.A,{className:"h-4 w-4 animate-spin mr-2"}):(0,re.jsx)(Rd.A,{className:"h-4 w-4 mr-2"}),"Export"]}),(0,re.jsxs)(zl,{onClick:()=>u(!0),children:[(0,re.jsx)(Tc.A,{className:"h-4 w-4 mr-2"}),"Schema"]}),(0,re.jsxs)(zl,{onClick:async()=>{if(window.confirm("Are you sure you want to delete all records? This cannot be undone.")){j(!0);try{await y[s.name].deleteMany({}),l([]),n({title:"Success",description:"All records deleted successfully"})}catch(a){var e,t;n({title:"Error",description:(null===(e=a.response)||void 0===e||null===(t=e.data)||void 0===t?void 0:t.message)||a.message,variant:"destructive"})}finally{j(!1)}}},disabled:b||0===r.length,className:"text-red-500 hover:text-red-600 focus:text-red-600",children:[b?(0,re.jsx)(Ze.A,{className:"h-4 w-4 animate-spin mr-2"}):(0,re.jsx)(Dd.A,{className:"h-4 w-4 mr-2"}),"Delete All"]})]})]})],children:[(0,re.jsx)("div",{className:"border rounded-md",children:(0,re.jsx)("div",{className:"h-[600px] w-full overflow-auto",children:(0,re.jsxs)(Or,{className:"min-w-full",children:[(0,re.jsx)(Rr,{className:"sticky top-0 bg-background z-10",children:(0,re.jsxs)(Fr,{children:[Object.keys(s.properties).map(e=>(0,re.jsx)(Br,{className:"text-xs whitespace-nowrap",children:s.properties[e].title||e},e)),(0,re.jsx)(Br,{className:"text-xs",children:"Actions"})]})}),(0,re.jsx)(Dr,{children:i?(0,re.jsx)(Fr,{children:(0,re.jsxs)(Ur,{colSpan:Object.keys(s.properties).length+1,className:"text-center py-4",children:[(0,re.jsx)(Ze.A,{className:"h-6 w-6 animate-spin mx-auto"}),(0,re.jsx)("p",{className:"text-sm text-muted-foreground mt-2",children:"Loading records..."})]})}):0===r.length?(0,re.jsx)(Fr,{children:(0,re.jsxs)(Ur,{colSpan:Object.keys(s.properties).length+1,className:"text-center py-8",children:[(0,re.jsx)("p",{className:"text-sm text-muted-foreground",children:"No records found"}),(0,re.jsxs)(Hs,{variant:"outline",size:"sm",className:"mt-2",onClick:()=>{h(null),d(!0)},children:[(0,re.jsx)(Ss.A,{className:"h-4 w-4 mr-2"}),"Add your first record"]})]})}):r.map(e=>(0,re.jsxs)(Fr,{className:"cursor-pointer hover:bg-muted/50",onClick:()=>{h(e),d(!0)},children:[Object.keys(s.properties).map(s=>(0,re.jsx)(Ur,{className:"text-xs whitespace-nowrap overflow-hidden text-ellipsis",style:{maxWidth:"200px"},children:"object"==typeof e[s]?JSON.stringify(e[s]):String(e[s]||"")},s)),(0,re.jsx)(Ur,{className:"whitespace-nowrap",children:(0,re.jsx)("div",{className:"flex gap-1",children:(0,re.jsx)(Hs,{size:"xs",variant:"ghost",onClick:t=>{t.stopPropagation(),(async e=>{try{await y[s.name].delete(e.id),l(r.filter(s=>s.id!==e.id)),n({title:"Success",description:"Item deleted successfully"})}catch(i){var t,a;n({title:"Error",description:(null===(t=i.response)||void 0===t||null===(a=t.data)||void 0===a?void 0:a.message)||i.message,variant:"destructive"})}})(e)},className:"text-red-500 hover:text-red-600",children:(0,re.jsx)(Dd.A,{className:"h-3 w-3"})})})})]},e.id))})]})})}),(0,re.jsx)(Vm,{open:c,onOpenChange:d,children:(0,re.jsxs)(Zm,{className:"w-[400px] overflow-y-auto",children:[(0,re.jsx)(Km,{children:(0,re.jsx)(Qm,{children:x?"Edit ".concat(s.name):"Add New ".concat(s.name)})}),(0,re.jsx)("div",{className:"py-4",children:(0,re.jsx)(km,{schema:s,onSubmit:x?async e=>{try{const t=await y[s.name].update(x.id,e);l(r.map(e=>e.id===x.id?t:e)),d(!1),h(null),n({title:"Success",description:"Item updated successfully"})}catch(i){var t,a;n({title:"Error",description:(null===(t=i.response)||void 0===t||null===(a=t.data)||void 0===a?void 0:a.message)||i.message,variant:"destructive"})}}:async e=>{try{const t=await y[s.name].create(e);l([...r,t]),d(!1),n({title:"Success",description:"New item created successfully"})}catch(i){var t,a;n({title:"Error",description:(null===(t=i.response)||void 0===t||null===(a=t.data)||void 0===a?void 0:a.message)||i.message,variant:"destructive"})}},initialValues:x})})]})}),(0,re.jsx)(Vm,{open:m,onOpenChange:u,children:(0,re.jsxs)(Zm,{className:"w-[600px] overflow-y-auto",children:[(0,re.jsx)(Km,{children:(0,re.jsx)(Qm,{children:"Schema Editor"})}),(0,re.jsx)("div",{className:"py-4",children:(0,re.jsx)(tu,{entity:s})})]})})]})};var nu=t(2737);const ru=e=>{let{isVisible:s,onCancel:t,onInviteSuccess:a}=e;const{user:n}=oe(),{app:r}=_s(),{toast:l}=si(),[i,o]=(0,H.useState)(""),[c,d]=(0,H.useState)("user"),[m,u]=(0,H.useState)(""),[x,h]=(0,H.useState)(!1),[p,g]=(0,H.useState)([]),f="free"===(null==n?void 0:n.subscription_tier),v=p.length>0?"https://".concat(p[0].domain):fa(r);(0,H.useEffect)(()=>{(async()=>{if(s)try{const e=await Ha.filter({app_id:r.id});g(e)}catch(m){}})()},[s,r.id]);return(0,re.jsx)(Pa,{open:s,onOpenChange:t,children:(0,re.jsxs)(Ma,{className:"sm:max-w-[520px] p-0 overflow-hidden",children:[(0,re.jsx)("div",{className:"bg-gradient-to-br from-slate-50 to-slate-100/50 px-6 py-8",children:(0,re.jsx)(Fa,{className:"space-y-3",children:(0,re.jsxs)("div",{className:"flex items-center gap-3",children:[(0,re.jsx)("div",{className:"p-2 bg-orange-100 rounded-xl",children:(0,re.jsx)(qa.A,{className:"w-5 h-5 text-orange-600"})}),(0,re.jsxs)("div",{children:[(0,re.jsx)(Ua,{className:"text-2xl font-semibold text-slate-900",children:"Share Your App"}),(0,re.jsxs)(za,{className:"text-slate-600 mt-1",children:["Give others access to ",r.name]})]})]})})}),(0,re.jsxs)("div",{className:"px-6 pb-6 space-y-8",children:[(0,re.jsxs)("div",{className:"space-y-4",children:[(0,re.jsxs)("div",{className:"flex items-center gap-2 mb-3",children:[(0,re.jsx)(bn.A,{className:"w-4 h-4 text-slate-500"}),(0,re.jsx)("h3",{className:"font-medium text-slate-900",children:"Public Access"})]}),(0,re.jsxs)("div",{className:"bg-slate-50 rounded-xl p-4 border border-slate-200",children:[(0,re.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,re.jsx)("p",{className:"text-sm font-medium text-slate-700",children:"Share URL"}),(0,re.jsxs)(Hs,{variant:"ghost",size:"sm",onClick:()=>{navigator.clipboard.writeText(v),l({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,re.jsx)(Kr.A,{className:"h-3 w-3 mr-1.5"}),"Copy"]})]}),(0,re.jsx)(ft,{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,re.jsx)("p",{className:"text-xs text-slate-500 mt-2",children:"Anyone with this link can access your app"})]})]}),(0,re.jsxs)("div",{className:"relative",children:[(0,re.jsx)("div",{className:"absolute inset-0 flex items-center",children:(0,re.jsx)(pt,{className:"w-full"})}),(0,re.jsx)("div",{className:"relative flex justify-center text-xs uppercase",children:(0,re.jsx)("span",{className:"bg-white px-3 text-slate-500 font-medium",children:"or"})})]}),(0,re.jsxs)("form",{onSubmit:async e=>{if(e.preventDefault(),u(""),i){h(!0);try{await ve.inviteUser(r.id,i,c),l({title:"Success",description:"Invitation sent successfully"}),a(),t()}catch(m){var s,n;const t=(null===(s=m.response)||void 0===s||null===(n=s.data)||void 0===n?void 0:n.detail)||m.message||"Failed to send invitation";u(t)}finally{h(!1)}}else u("Please enter an email address")},className:"space-y-6",children:[(0,re.jsxs)("div",{className:"space-y-4",children:[(0,re.jsxs)("div",{className:"flex items-center gap-2 mb-3",children:[(0,re.jsx)(Im.A,{className:"w-4 h-4 text-slate-500"}),(0,re.jsx)("h3",{className:"font-medium text-slate-900",children:"Send Invitation"})]}),(0,re.jsxs)("div",{className:"space-y-4",children:[(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsx)(Nt,{htmlFor:"email",className:"text-sm font-medium text-slate-700",children:"Email address"}),(0,re.jsx)(ft,{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,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsx)(Nt,{htmlFor:"role",className:"text-sm font-medium text-slate-700",children:"Access level"}),(0,re.jsxs)(Ut,{value:c,onValueChange:d,children:[(0,re.jsx)(Wt,{id:"role",className:"h-11 border-slate-200 focus:ring-orange-500 focus:border-orange-500",children:(0,re.jsx)(qt,{placeholder:"Select access level"})}),(0,re.jsxs)(Ht,{children:[(0,re.jsx)($t,{value:"user",className:"py-3",children:(0,re.jsxs)("div",{className:"flex flex-col",children:[(0,re.jsx)("span",{className:"font-medium",children:"User"}),(0,re.jsx)("span",{className:"text-xs text-slate-500",children:"Can use the app"})]})}),(0,re.jsx)($t,{value:"admin",disabled:f,className:"py-3",children:(0,re.jsxs)("div",{className:"flex flex-col",children:[(0,re.jsx)("span",{className:"font-medium",children:"Admin"}),(0,re.jsxs)("span",{className:"text-xs text-slate-500",children:["Can manage users and settings ",f&&"\u2022 Paid plans only"]})]})})]})]}),f&&(0,re.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,re.jsx)("div",{className:"p-1 bg-orange-100 rounded-full",children:(0,re.jsx)(Xe.A,{className:"h-3 w-3 text-orange-600"})}),(0,re.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,re.jsx)("p",{className:"text-sm text-orange-800 font-medium",children:"Admin access requires a paid plan"}),(0,re.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,re.jsxs)("div",{className:"flex items-start gap-3 p-4 bg-red-50 border border-red-200 rounded-xl",children:[(0,re.jsx)("div",{className:"p-1 bg-red-100 rounded-full",children:(0,re.jsx)(Xe.A,{className:"h-3 w-3 text-red-600"})}),(0,re.jsx)("p",{className:"text-sm text-red-800 font-medium",children:m})]})]})]}),(0,re.jsxs)(Ba,{className:"gap-3 pt-2",children:[(0,re.jsx)(Hs,{variant:"outline",type:"button",onClick:t,className:"h-11 px-6 border-slate-200 text-slate-700 hover:bg-slate-50",children:"Cancel"}),(0,re.jsx)(Hs,{type:"submit",disabled:x,className:"h-11 px-6 bg-orange-600 hover:bg-orange-700 text-white font-medium",children:x?(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)("div",{className:"w-4 h-4 border-2 border-white/30 border-t-white rounded-full animate-spin mr-2"}),"Sending..."]}):(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(nu.A,{className:"w-4 h-4 mr-2"}),"Send Invitation"]})})]})]})]})]})})};function lu(e){let{entity:s}=e;const{app:t,updateApp:a}=_s();return(0,re.jsx)(Mm,{schema:s,onEdit:(e,n)=>{s.properties[e]=n,t.user_entity=s,a({user_entity:t.user_entity})}})}function iu(){const{app:e}=_s(),{state:s,updateState:t,loadUsers:a}=(()=>{const[e,s]=(0,H.useState)({users:[],isLoading:!1,isDrawerOpen:!1,isSchemaDrawerOpen:!1,isInviteModalOpen:!1,editingItem:null}),{user:t}=oe(),a=_s().getEntitiesSDK(),{toast:n}=nn(),r=e=>{s(s=>(0,K.A)((0,K.A)({},s),e))};return{state:e,updateState:r,loadUsers:async()=>{r({isLoading:!0});try{let e=await a.User.list();!(null==t||!t.email)&&(t.email.endsWith("@base44.com")||t.email.endsWith("@wix.com"))||(e=e.filter(e=>!e.email.includes("@base44.com")&&!e.email.includes("@wix.com"))),r({users:e})}catch(e){n({title:"Error",description:"Failed to load users",variant:"destructive"})}finally{r({isLoading:!1})}}}})();return(0,H.useEffect)(()=>{a()},[]),(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(su,{title:"Users",subtitle:"Manage users and their roles",primaryAction:(0,re.jsxs)(Hs,{size:"sm",onClick:()=>t({isInviteModalOpen:!0}),children:[(0,re.jsx)(Ss.A,{className:"h-4 w-4"}),"Invite User"]}),actions:(0,re.jsxs)(Hs,{size:"sm",variant:"outline",onClick:()=>t({isSchemaDrawerOpen:!0}),children:[(0,re.jsx)(Tc.A,{className:"h-4 w-4 mr-2"}),"Schema"]}),children:(0,re.jsx)(ou,{state:s,updateState:t})}),(0,re.jsx)(ru,{isVisible:s.isInviteModalOpen,onCancel:()=>t({isInviteModalOpen:!1}),onInviteSuccess:a}),(0,re.jsx)(Vm,{open:s.isSchemaDrawerOpen,onOpenChange:()=>t({isSchemaDrawerOpen:!1}),children:(0,re.jsxs)(Zm,{className:"w-[600px] overflow-y-auto",children:[(0,re.jsx)(Km,{children:(0,re.jsx)(Qm,{children:"User Schema Editor"})}),(0,re.jsx)("div",{className:"py-4",children:(0,re.jsx)(lu,{entity:e.user_entity})})]})})]})}const ou=e=>{let{state:s,updateState:t}=e;const{app:a}=_s(),{navigate:n}=(0,Z.Zp)(),{user:r}=oe(),l=_s().getEntitiesSDK(),{toast:i}=nn(),{isDrawerOpen:o,isLoading:c,editingItem:d,users:m}=s;return(0,re.jsxs)("div",{className:"border rounded-md",children:[(0,re.jsx)("div",{className:"h-[600px] overflow-auto",children:(0,re.jsxs)(Or,{children:[(0,re.jsx)(Rr,{children:(0,re.jsxs)(Fr,{children:[Object.keys(a.user_entity.properties).map(e=>(0,re.jsx)(Br,{className:"text-xs whitespace-nowrap",children:a.user_entity.properties[e].title||e},e)),(0,re.jsx)(Br,{className:"text-xs",children:"Actions"})]})}),(0,re.jsx)(Dr,{children:c?(0,re.jsx)(Fr,{children:(0,re.jsxs)(Ur,{colSpan:Object.keys(a.user_entity.properties).length+1,className:"text-center py-4",children:[(0,re.jsx)(Ze.A,{className:"h-6 w-6 animate-spin mx-auto"}),(0,re.jsx)("p",{className:"text-sm text-muted-foreground mt-2",children:"Loading users..."})]})}):0===m.length?(0,re.jsx)(Fr,{children:(0,re.jsxs)(Ur,{colSpan:Object.keys(a.user_entity.properties).length+1,className:"text-center py-8",children:[(0,re.jsx)("p",{className:"text-sm text-muted-foreground",children:"No users found"}),(0,re.jsxs)(Hs,{variant:"outline",size:"sm",className:"mt-2",onClick:()=>t({isInviteModalOpen:!0}),children:[(0,re.jsx)(Ss.A,{className:"h-4 w-4 mr-2"}),"Invite your first user"]})]})}):m.map(e=>(0,re.jsxs)(Fr,{className:"cursor-pointer hover:bg-muted/50",onClick:()=>{t({editingItem:e,isDrawerOpen:!0})},children:[Object.keys(a.user_entity.properties).map(s=>(0,re.jsx)(Ur,{className:"text-xs whitespace-nowrap overflow-hidden text-ellipsis",style:{maxWidth:"200px"},children:"object"==typeof e[s]?JSON.stringify(e[s]):String(e[s]||"")},s)),(0,re.jsx)(Ur,{className:"whitespace-nowrap",children:(0,re.jsx)("div",{className:"flex gap-1",children:(0,re.jsx)(Hs,{size:"xs",variant:"ghost",onClick:s=>{s.stopPropagation(),(async e=>{try{await l.User.delete(e.id),t({users:m.filter(s=>s.id!==e.id)}),i({title:"Success",description:"User removed successfully"})}catch(n){var s,a;i({title:"Error",description:(null===(s=n.response)||void 0===s||null===(a=s.data)||void 0===a?void 0:a.message)||n.message,variant:"destructive"})}})(e)},className:"text-red-500 hover:text-red-600",children:(0,re.jsx)(Dd.A,{className:"h-3 w-3"})})})})]},e.id))})]})}),(0,re.jsx)(Vm,{open:o,onOpenChange:()=>t({isDrawerOpen:!1}),children:(0,re.jsxs)(Zm,{className:"w-[400px] overflow-y-auto",children:[(0,re.jsx)(Km,{children:(0,re.jsx)(Qm,{children:"Edit User"})}),(0,re.jsx)("div",{className:"py-4",children:(0,re.jsx)(km,{schema:a.user_entity,onSubmit:async e=>{try{if("admin"===e.role&&"admin"!==d.role&&"free"===r.subscription_tier)return void i({title:"Subscription Required",description:(0,re.jsxs)("div",{children:["Only paying users can make other users admins.",(0,re.jsx)(Hs,{variant:"link",className:"p-0 h-auto font-semibold underline",onClick:()=>n("/billing"),children:"Upgrade your subscription"}),"to continue."]}),variant:"destructive"});const s=await l.User.update(d.id,e);t({users:m.map(e=>e.id===d.id?s:e),isDrawerOpen:!1,editingItem:null}),i({title:"Success",description:"User updated successfully"})}catch(o){var s,a;i({title:"Error",description:(null===(s=o.response)||void 0===s||null===(a=s.data)||void 0===a?void 0:a.message)||o.message,variant:"destructive"})}},initialValues:d,uiSchema:{email:{"ui:widget":"hidden"},full_name:{"ui:widget":"hidden"}}})})]})})]})},cu=["className"],du=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,cu);return(0,re.jsx)("textarea",(0,K.A)({className:is("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",t),ref:s},a))});du.displayName="Textarea";const mu=["className"],uu=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,mu);return(0,re.jsx)(bt.b,(0,K.A)({ref:s,className:is("text-regular text-sm leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",t)},a))});uu.displayName=bt.b.displayName;const xu=["className"],hu=["className"],pu=["className"],gu=dl.bL,fu=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,xu);return(0,re.jsx)(dl.B8,(0,K.A)({ref:s,className:is("inline-flex h-10 items-center justify-center rounded-md bg-muted p-1 text-muted-foreground",t)},a))});fu.displayName=dl.B8.displayName;const vu=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,hu);return(0,re.jsx)(dl.l9,(0,K.A)({ref:s,className:is("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",t)},a))});vu.displayName=dl.l9.displayName;const bu=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,pu);return(0,re.jsx)(dl.UC,(0,K.A)({ref:s,className:is("mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",t)},a))});bu.displayName=dl.UC.displayName;const ju=(e,s)=>{var t;const{toast:a}=nn(),[n,r]=(0,H.useState)(!1),[l,i]=(0,H.useState)(null!==(t=null==s?void 0:s.initialResult)&&void 0!==t?t:null),[o,c]=(0,H.useState)(null),d="string"==typeof(null==s?void 0:s.toastSuccess)?{title:"Success",description:s.toastSuccess}:null==s?void 0:s.toastSuccess,m="string"==typeof(null==s?void 0:s.toastError)?{title:"Error",description:s.toastError}:null==s?void 0:s.toastError;return{isLoading:n,update:async function(){r(!0);try{const t=await e(...arguments);return(null==s?void 0:s.toastSuccess)&&a(d),i(t),t}catch(o){(null==s?void 0:s.toastError)&&a((0,K.A)((0,K.A)({},m),{},{variant:"destructive"})),c(o)}finally{r(!1)}},result:l,error:o}};var yu=t(59222);const Nu=["className"],wu=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,Nu);return(0,re.jsx)(yu.bL,(0,K.A)((0,K.A)({className:is("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",t)},a),{},{ref:s,children:(0,re.jsx)(yu.zi,{className:is("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")})}))});wu.displayName=yu.bL.displayName;var _u=t(84814),ku=t(66987),Au=t(35254),Su=t.n(Au);t(17687);const Cu=(0,H.createContext)(),Eu=e=>{let{children:s}=e;const{appId:t}=(0,Z.g)(),[a,n]=(0,H.useState)(null),[r,l]=(0,H.useState)(null),[i,o]=(0,H.useState)(!0),[c,d]=(0,H.useState)(null),m=async()=>{if(t){o(!0);try{const e=await ve.get(t);n(e);try{const e=await $a.getListingIfExists(t);l(e)}catch(s){l(null)}}catch(s){var e;d(s),403===(null==s||null===(e=s.response)||void 0===e?void 0:e.status)&&d(new Error("You do not have access to this app"))}finally{o(!1)}}};(0,H.useEffect)(()=>{m()},[t]);const u={app:a,listing:r,isLoading:i,error:c,hasListing:!(null==r||!r.id||null!=r&&r.archived),createOrUpdateListing:async e=>{if(null!=r&&r.id){const s=await $a.update(r.id,e);return l(s),s}{const s=await $a.create((0,K.A)((0,K.A)({},e),{},{app_id:t}));return l(s),s}},refetch:()=>{m()}};return(0,re.jsx)(Cu.Provider,{value:u,children:s})},Iu=()=>{const e=(0,H.useContext)(Cu);if(!e)throw new Error("useAppListing must be used within an AppListingProvider");return e},Tu=["timestamp"],Pu=["Marketing & Sales","Operations","Data & Analytics","Content Generation","HR & Legal","Finance","Education","Community","Lifestyle & Hobbies","Games & Entertainment"],Lu=e=>e&&Array.isArray(e)?e.filter(e=>Pu.includes(e)):[],Ou=(e,s)=>"app_listing_autosave_".concat(e,"_").concat(s||"new"),Ru=(e,s)=>{try{const t=Ou(e,s),a=localStorage.getItem(t);if(a){const e=JSON.parse(a);if(Date.now()-e.timestamp<6048e5){const{timestamp:s}=e;return(0,as.A)(e,Tu)}}return null}catch(t){return null}};function Du(e){let{listingId:s,listing:t,onSave:a,onRouteChange:n,app:r}=e;const l=(0,H.useRef)(null),[i,o]=(0,H.useState)(t||null),[c,d]=(0,H.useState)(!1),[m,u]=(0,H.useState)(null),[x,h]=(0,H.useState)(!1),[p,g]=(0,H.useState)(!1),[f,v]=(0,H.useState)(!1),[b,j]=(0,H.useState)(null),[y,N]=(0,H.useState)(null),[w,_]=(0,H.useState)(!1),[k,A]=(0,H.useState)(!1),[S,C]=(0,H.useState)(null),[E,I]=(0,H.useState)(!1),T=(0,H.useRef)(null),P=(0,H.useRef)(null),[L,O]=(0,H.useState)({name:"",description:"",screenshot_urls:[],categories:[],is_private:!1}),R=(0,H.useCallback)(e=>{null!=r&&r.id&&(A(!0),((e,s,t)=>{try{const a=Ou(e,s),n=(0,K.A)((0,K.A)({},t),{},{timestamp:Date.now()});localStorage.setItem(a,JSON.stringify(n))}catch(m){}})(r.id,s,e),C(new Date),setTimeout(()=>A(!1),500))},[null==r?void 0:r.id,s]),D=(0,H.useCallback)(e=>{T.current&&clearTimeout(T.current),T.current=setTimeout(()=>{R(e)},1e3)},[R]);(0,H.useEffect)(()=>{if(s&&!t)(async()=>{try{d(!0);const e=await $a.get(s);o(e);const t=null!=r&&r.id?Ru(r.id,s):null;if(t){if(O((0,K.A)((0,K.A)({},t),{},{categories:Lu(t.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:Lu(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(t){const e=null!=r&&r.id?Ru(r.id,s):null;if(e){if(O((0,K.A)((0,K.A)({},e),{},{categories:Lu(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:t.name||"",description:dn(t.description||""),screenshot_urls:t.screenshot_urls||[],categories:Lu(t.categories||[]),is_private:t.is_private||!1,archived:!1})}},[s,t,null==r?void 0:r.id,E]),(0,H.useEffect)(()=>{l.current&&l.current.scrollIntoView({behavior:"smooth",block:"start"})},[]),(0,H.useEffect)(()=>()=>{T.current&&clearTimeout(T.current),P.current&&P.current.dismiss()},[]);const M=(e,s)=>{const t="description"===e?dn(s):s;O(s=>{const a=(0,K.A)((0,K.A)({},s),{},{[e]:t});return D(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||s))throw new Error("No save handler provided for new listing");e=await $a.update((null==i?void 0:i.id)||s,L)}o(e),v(!1),null!=r&&r.id&&((e,s)=>{try{const t=Ou(e,s);localStorage.removeItem(t)}catch(m){}})(r.id,s),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,H.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 s=await As.uploadAppFile(e,r.id),t=s.url||s.file_url||s;O(e=>{const s=(0,K.A)((0,K.A)({},e),{},{screenshot_urls:[...e.screenshot_urls,t]});return D(s),v(!0),s}),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,D]);(0,H.useEffect)(()=>{const e=async e=>{var s;const t=null===(s=e.clipboardData)||void 0===s?void 0:s.items;if(t)for(const a of t)if(-1!==a.type.indexOf("image")){e.preventDefault();const s=a.getAsFile();s&&await B(s)}};return document.addEventListener("paste",e),()=>document.removeEventListener("paste",e)},[B]);const U=()=>{N(null)},z=(e,s)=>{e.preventDefault(),null!==b&&b!==s&&((e,s)=>{const t=[...L.screenshot_urls],[a]=t.splice(e,1);t.splice(s,0,a),M("screenshot_urls",t)})(b,s),j(null),N(null)},q=()=>{j(null),N(null)};if(c)return(0,re.jsx)("div",{className:"flex items-center justify-center min-h-[400px]",children:(0,re.jsx)("div",{className:"text-muted-foreground",children:"Loading listing..."})});if(m)return(0,re.jsx)("div",{className:"flex items-center justify-center min-h-[400px]",children:(0,re.jsxs)("div",{className:"text-red-600",children:["Error: ",m.message]})});const W=!(null!=i&&i.id||s);return(0,re.jsxs)("div",{ref:l,className:"w-full",children:[(0,re.jsxs)("div",{className:"sticky top-0 z-10 bg-slate-50 py-4 mb-4",children:[(0,re.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground mb-4",children:[(0,re.jsx)("button",{onClick:()=>n("main"),className:"hover:text-foreground hover:underline transition-colors cursor-pointer",children:"App Settings"}),(0,re.jsx)("span",{children:"/"}),(0,re.jsx)("span",{className:"transition-colors",children:"App Templates Listing"})]}),(0,re.jsxs)("div",{className:"flex flex-col sm:flex-row sm:justify-between sm:items-start gap-4 w-full",children:[(0,re.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,re.jsx)("h2",{className:"text-xl sm:text-2xl font-semibold text-gray-800 truncate",children:W?"Create Listing":"Manage Listing"}),(0,re.jsx)("div",{className:"flex items-center gap-3 mt-1",children:(0,re.jsx)("p",{className:"text-muted-foreground text-sm sm:text-base",children:W?"Create your app's template listing":"Update your app's template listing"})})]}),(0,re.jsx)("div",{className:"flex-shrink-0",children:(0,re.jsxs)("div",{className:"flex items-center gap-2 sm:gap-3",children:[(0,re.jsx)(Hs,{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,re.jsx)(Hs,{onClick:async()=>{W||"approved"!==(null==i?void 0:i.status)&&"rejected"!==(null==i?void 0:i.status)?await F():_(!0)},disabled:!f&&!W&&!(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...":W?"Create Listing":"Update Listing"})]})})]})]}),(0,re.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,re.jsxs)("div",{className:"space-y-4 w-full max-w-full overflow-hidden",children:[(0,re.jsxs)(it,{className:"border-none rounded-[12px]",children:[(0,re.jsx)(ot,{className:"py-4 px-6",children:(0,re.jsx)(ct,{className:"text-sm font-medium",children:"App Info"})}),(0,re.jsx)(pt,{}),(0,re.jsxs)(mt,{className:"space-y-6 pt-6",children:[(0,re.jsxs)("div",{className:"space-y-1",children:[(0,re.jsxs)(Nt,{htmlFor:"name",className:"text-sm font-medium",children:["App Name",(0,re.jsx)("span",{className:"text-red-500",children:"*"})]}),(0,re.jsx)(ft,{id:"name",value:L.name,onChange:e=>M("name",e.target.value),placeholder:"Enter your app name",className:"max-w-md"})]}),(0,re.jsxs)("div",{className:"space-y-1",children:[(0,re.jsxs)(Nt,{htmlFor:"description",className:"text-sm font-medium",children:["App Description",(0,re.jsx)("span",{className:"text-red-500",children:"*"})]}),(0,re.jsx)("p",{className:"text-sm text-muted-foreground",children:"Tell users what makes your app worth trying."}),(0,re.jsx)("div",{className:"prose-editor w-full max-w-full pt-2",children:(0,re.jsx)(Su(),{theme:"snow",value:L.description,onChange:e=>M("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,re.jsxs)("div",{className:"space-y-1",children:[(0,re.jsxs)("div",{className:"flex items-center gap-2",children:[(0,re.jsxs)(Nt,{children:["Categories",(0,re.jsx)("span",{className:"text-red-500",children:"*"})]}),(0,re.jsxs)("span",{className:"text-sm text-muted-foreground",children:["(",L.categories.length," selected)"]})]}),(0,re.jsx)("p",{className:"text-sm text-muted-foreground",children:"Select categories that best describe your app to help users discover it"}),(0,re.jsx)("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-x-3 gap-y-2 py-3",children:Pu.map(e=>(0,re.jsxs)("div",{className:"flex items-center space-x-2 min-w-0",children:[(0,re.jsx)(ed,{id:"category-".concat(e),checked:L.categories.includes(e),onCheckedChange:()=>(e=>{O(s=>{const t=s.categories.includes(e)?s.categories.filter(s=>s!==e):[...s.categories,e],a=(0,K.A)((0,K.A)({},s),{},{categories:t});return D(a),v(!0),a})})(e),className:"flex-shrink-0 shadow-sm border-slate-200"}),(0,re.jsx)(Nt,{htmlFor:"category-".concat(e),className:"text-sm font-normal cursor-pointer truncate",children:e})]},e))}),0===L.categories.length&&(0,re.jsx)("p",{className:"text-sm text-orange-600",children:"At least one category is required"})]}),(0,re.jsxs)("div",{className:"space-y-4",children:[(0,re.jsxs)("div",{className:"flex items-center justify-between",children:[(0,re.jsxs)("div",{children:[(0,re.jsxs)(Nt,{children:["Screenshots",(0,re.jsx)("span",{className:"text-red-500",children:"*"})]}),(0,re.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==r?void 0:r.slug)&&(0,re.jsxs)(Hs,{variant:"outline",size:"sm",onClick:()=>window.open(null!=r&&r.slug?"localhost"===window.location.hostname?"http://".concat(r.slug,".localhost:3000"):window.location.hostname.includes("base44.io")||window.location.hostname.includes("beta-base44")?"https://".concat(r.slug,".base44.io"):window.location.hostname.includes("ba11.me")?"https://".concat(r.slug,".ba11.me"):window.location.hostname.includes("ba22.me")?"https://".concat(r.slug,".ba22.me"):window.location.hostname.includes("ba33.me")?"https://".concat(r.slug,".ba33.me"):"https://".concat(r.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,re.jsx)("span",{children:"Preview App"}),(0,re.jsx)(jl.A,{className:"w-3 h-3"})]})]}),(0,re.jsxs)("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4",children:[L.screenshot_urls.map((e,s)=>(0,re.jsxs)("div",{className:"relative group cursor-move min-w-0 ".concat(b===s?"opacity-50":""," ").concat(y===s?"ring-2 ring-orange-400 ring-offset-2":""),draggable:!0,onDragStart:e=>((e,s)=>{j(s),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,s),onDragOver:e=>((e,s)=>{e.preventDefault(),e.dataTransfer.dropEffect="move",N(s)})(e,s),onDragLeave:U,onDrop:e=>z(e,s),onDragEnd:q,children:[0===s&&(0,re.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,re.jsx)("img",{src:e,alt:"Screenshot ".concat(s+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,re.jsx)("div",{className:"absolute inset-0 opacity-0 group-hover:opacity-100 transition-opacity rounded-lg",children:(0,re.jsx)(Hs,{size:"sm",variant:"destructive",onClick:()=>(e=>{const s=L.screenshot_urls.filter((s,t)=>t!==e);M("screenshot_urls",s)})(s),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,re.jsx)(_u.A,{className:"h-4 w-4"})})}),(0,re.jsx)("div",{className:"absolute top-2 right-2 opacity-0 group-hover:opacity-90 transition-opacity",children:(0,re.jsx)("div",{className:"text-white text-xs bg-black/70 px-2 py-1 rounded",children:"Drag to reorder"})})]},s)),(0,re.jsxs)("div",{className:"relative",children:[(0,re.jsx)(ft,{type:"file",accept:".jpg,.jpeg,.png,image/jpeg,image/png",multiple:!0,onChange:async e=>{const s=e.target.files;if(s&&0!==s.length)for(const t of s)await B(t)},className:"absolute inset-0 w-full h-full opacity-0 cursor-pointer",disabled:p||L.screenshot_urls.length>=7}),(0,re.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,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(ku.A,{className:"w-6 h-6 text-gray-400 animate-spin mb-2"}),(0,re.jsx)("span",{className:"text-sm text-gray-500",children:"Uploading..."})]}):L.screenshot_urls.length>=7?(0,re.jsx)(re.Fragment,{children:(0,re.jsx)("span",{className:"text-sm text-gray-500",children:"Maximum screenshots reached (7)"})}):(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(Ss.A,{className:"w-6 h-6 text-gray-400 mb-2"}),(0,re.jsx)("span",{className:"text-sm text-gray-500",children:"Add Screenshot"})]})})]})]}),(0,re.jsx)("div",{className:"rounded-lg bg-slate-50 p-3 flex items-center gap-2",children:(0,re.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,re.jsx)("p",{className:"text-sm text-orange-600",children:"At least one screenshot is required for your listing"})]})]})]}),(0,re.jsxs)(it,{className:"border-none rounded-[12px]",children:[(0,re.jsx)(ot,{className:"py-4 px-6",children:(0,re.jsx)(ct,{className:"text-sm font-medium",children:"Settings"})}),(0,re.jsx)(pt,{className:"mb-4"}),(0,re.jsx)(mt,{className:"space-y-6",children:(0,re.jsxs)("div",{className:"flex items-center justify-between",children:[(0,re.jsxs)("div",{className:"space-y-1",children:[(0,re.jsx)(Nt,{htmlFor:"is_private",className:"text-sm font-medium",children:"Visible to Everyone"}),(0,re.jsx)("p",{className:"text-sm text-regular text-muted-foreground",children:"Make your listing public and discoverable by others"})]}),(0,re.jsx)(wu,{id:"is_private",checked:!L.is_private,onCheckedChange:e=>M("is_private",!e)})]})})]})]}),(0,re.jsx)(Pa,{open:w,onOpenChange:_,children:(0,re.jsxs)(Ma,{className:"sm:max-w-md",children:[(0,re.jsxs)(Fa,{children:[(0,re.jsx)(Ua,{children:"Attention"}),(0,re.jsx)(za,{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,re.jsxs)(Ba,{className:"flex gap-2",children:[(0,re.jsx)(Hs,{variant:"outline",onClick:()=>_(!1),disabled:x,children:"Cancel"}),(0,re.jsx)(Hs,{onClick:F,disabled:x,className:"bg-gray-900 hover:bg-gray-500 text-white",children:x?"Saving...":"Continue"})]})]})})]})}function Mu(e){let{onRouteChange:s}=e;const{app:t,listing:a,isLoading:n,error:r,createOrUpdateListing:l}=Iu();return n?(0,re.jsx)("div",{className:"p-6",children:"Loading..."}):r?(0,re.jsxs)("div",{className:"p-6 text-red-600",children:["Error: ",r.message]}):(0,re.jsx)(Du,{listingId:null==a?void 0:a.id,onRouteChange:s,onSave:l,app:t,listing:a||{name:(null==t?void 0:t.name)||"",description:dn((null==t?void 0:t.user_description)||"

"),screenshot_urls:[],categories:Lu((null==t?void 0:t.categories)||[]),is_private:!1}})}var Fu=t(15924),Bu=t(85354);function Uu(){const{app:e}=_s(),{user:s}=oe(),{workspaces:t}=ge(),[a,n]=(0,H.useState)(!1),[r,l]=(0,H.useState)(!0);return(0,H.useEffect)(()=>{(()=>{if(!e.organization_id||!t||!s)return n(!1),void l(!1);const a=t.find(s=>s.id===e.organization_id);if(!a)return n(!1),void l(!1);const r=!a.is_personal&&a.id!==s.personal_organization_id;n(r),l(!1)})()},[e.organization_id,t,s]),{isInSharedWorkspace:a,isLoading:r}}const zu=["className","children"],qu=H.forwardRef((e,s)=>{let{className:t,children:a}=e,n=(0,as.A)(e,zu);return(0,re.jsx)(Et.q7,(0,K.A)((0,K.A)({ref:s,className:is("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",t)},n),{},{children:(0,re.jsx)(Et.p4,{children:a})}))});qu.displayName="SelectItemNoCheck";const Wu=e=>{let{options:s=[],value:t,onValueChange:a,placeholder:n="Select option",disabled:r=!1,className:l}=e;const i=s.find(e=>e.value===t);return(0,re.jsxs)(In,{value:t,onValueChange:a,disabled:r,children:[(0,re.jsx)(Pn,{className:is("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",l),children:(0,re.jsx)(Tn,{children:i?(0,re.jsxs)("div",{className:"flex items-center gap-2",children:[i.icon&&(0,re.jsx)(i.icon,{className:"w-4 h-4 flex-shrink-0 text-slate-500"}),(0,re.jsx)("span",{className:"truncate text-sm font-medium text-slate-900",children:i.label})]}):(0,re.jsx)("span",{className:"text-slate-400 text-sm",children:n})})}),(0,re.jsx)(Rn,{className:"bg-white border border-slate-200 rounded-md shadow-lg",children:s.map(e=>(0,re.jsx)(qu,{value:e.value,className:is("py-2 cursor-pointer","hover:bg-slate-50 focus:bg-slate-50","data-[state=checked]:bg-slate-100"),children:(0,re.jsxs)("div",{className:"flex items-center gap-2",children:[e.icon&&(0,re.jsx)(e.icon,{className:"w-4 h-4 flex-shrink-0 text-slate-500"}),(0,re.jsx)("span",{className:"text-sm font-medium text-slate-900",children:e.label})]})},e.value))})]})},Vu=["className"],Yu=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,Vu);return(0,re.jsx)(Xc.bL,(0,K.A)((0,K.A)({ref:s,className:is("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",t)},a),{},{children:(0,re.jsx)(Xc.C1,{className:is("flex items-center justify-center text-current"),children:(0,re.jsx)(Pt.A,{className:"h-4 w-4"})})}))});Yu.displayName=Xc.bL.displayName;const Hu=e=>{let{checked:s,onCheckedChange:t,label:a,disabled:n=!1,className:r,checkboxClassName:l,labelClassName:i}=e;return(0,re.jsxs)("div",{className:is("flex items-center space-x-2",!n&&"hover:opacity-70 cursor-pointer",n&&"cursor-not-allowed","transition-opacity duration-200",r),onClick:()=>{!n&&t&&t(!s)},children:[(0,re.jsx)(Yu,{checked:s,onCheckedChange:()=>{},disabled:n,className:is("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",l)}),(0,re.jsx)(uu,{className:is("text-sm text-slate-700","font-normal","select-none","peer-disabled:opacity-50","pointer-events-none",i),children:a})]})},Gu=e=>[{value:"private",label:"Private",icon:Fs.A},...e?[{value:"workspace",label:"Workspace",icon:Gr.A}]:[],{value:"public",label:"Public",icon:bn.A}];function $u(e,s){return"private"===e?"private_with_login":"workspace"===e?"workspace_with_login":"public"===e?s?"public_with_login":"public_without_login":"private_with_login"}function Ju(e){let{value:s,onValueChange:t,disabled:a=!1,showWorkspace:n=!0,className:r}=e;const l=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"}}(s),i="public_without_login"!==s;const o=Gu(n),c=a||"public"!==l;return(0,re.jsxs)("div",{className:is("space-y-2",r),children:[(0,re.jsx)(Wu,{options:o,value:l,onValueChange:e=>{const s=$u(e,"public"!==e||i);t(s)},disabled:a,placeholder:"Select visibility"}),(0,re.jsx)(Hu,{checked:i,onCheckedChange:e=>{if("public"===l){const s=$u(l,e);t(s)}},disabled:c,label:"Require login to access"})]})}const Zu=["className","variant"],Ku=["className"],Xu=["className"],Qu=(0,ns.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"}}),ex=H.forwardRef((e,s)=>{let{className:t,variant:a}=e,n=(0,as.A)(e,Zu);return(0,re.jsx)("div",(0,K.A)({ref:s,role:"alert",className:is(Qu({variant:a}),t)},n))});ex.displayName="Alert";const sx=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,Ku);return(0,re.jsx)("h5",(0,K.A)({ref:s,className:is("mb-1 font-medium leading-none tracking-tight",t)},a))});sx.displayName="AlertTitle";const tx=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,Xu);return(0,re.jsx)("div",(0,K.A)({ref:s,className:is("text-sm [&_p]:leading-relaxed",t)},a))});tx.displayName="AlertDescription";class ax extends X.H{getBaseURL(){return"/apps"}activateBackendFunctions(e){return this.axios.post("/".concat(e,"/activate-backend-functions"))}getBackendFunctionsLogs(e,s,t){return this.axios.get("/".concat(e,"/functions/").concat(s,"/logs"),{params:t})}}const nx=new ax,rx=e=>(e=>e&&e.subscription_tier&&!["free","starter"].includes(e.subscription_tier))(e),lx=()=>(0,re.jsxs)(us,{variant:"warning",className:"bg-gray-50 border-gray-200",children:[(0,re.jsx)(Fu.A,{className:"h-4 w-4 text-gray-500"}),(0,re.jsx)(xs,{className:"text-gray-800",children:"Premium Feature"}),(0,re.jsxs)(hs,{className:"text-gray-600",children:["Backend functions are available only for Builder tier and above.",(0,re.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."]})]}),ix=["className"];function ox(e){let{className:s}=e,t=(0,as.A)(e,ix);return(0,re.jsx)("div",(0,K.A)({className:is("animate-pulse rounded-md bg-muted",s)},t))}function cx(e){let{onRouteChange:s}=e;const{hasListing:t,listing:a,isLoading:n,refetch:r}=Iu(),[l,i]=(0,H.useState)(!1);return n?(0,re.jsx)("div",{className:"space-y-4",children:(0,re.jsxs)("div",{className:"flex flex-col sm:flex-row justify-between items-start gap-4",children:[(0,re.jsxs)("div",{className:"flex-grow space-y-2",children:[(0,re.jsx)(ox,{className:"h-4 w-20"}),(0,re.jsx)(ox,{className:"h-3 w-full max-w-md"})]}),(0,re.jsx)(ox,{className:"h-9 w-36"})]})}):(0,re.jsxs)(re.Fragment,{children:[(0,re.jsxs)("div",{className:"flex flex-col sm:flex-row justify-between items-start gap-4",children:[(0,re.jsxs)("div",{children:[(0,re.jsx)("h3",{className:"text-sm font-medium",children:"App Templates"}),(0,re.jsx)("p",{className:"text-sm text-muted-foreground",children:t?"Manage your template listing":"Share your template with the community so others can discover and use it."})]}),(0,re.jsxs)("div",{className:"flex items-center gap-2",children:[(0,re.jsxs)(Hs,{onClick:()=>s("appListing"),variant:"outline",className:"flex items-center border-gray-200 hover:bg-gray-50 hover:text-gray-700 cursor-pointer",children:[(0,re.jsx)(wr.A,{className:"mr-2 h-4 w-4"}),t?"Manage Listing":"Publish to App Templates"]}),t&&(0,re.jsxs)(Pl,{children:[(0,re.jsx)(Ll,{asChild:!0,children:(0,re.jsx)(Hs,{variant:"outline",className:"flex items-center border-gray-200 hover:bg-gray-50 hover:text-gray-700 cursor-pointer p-2",children:(0,re.jsx)(kr.A,{})})}),(0,re.jsxs)(Ul,{align:"end",children:[(0,re.jsx)(zl,{onClick:()=>window.open("/app-templates?category=my-apps","_blank"),children:"See on App Templates"}),(0,re.jsx)(zl,{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 r()}catch(e){an({title:"Error",description:e.message||"Failed to remove listing from catalog",variant:"destructive"})}finally{i(!1)}}},disabled:!t||l,className:"text-red-600 focus:text-red-600",children:l?(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(Ze.A,{className:"w-4 h-4 mr-2 animate-spin"}),"Removing..."]}):"Remove from App Templates"})]})]})]})]}),t&&a&&(0,re.jsxs)("div",{className:"flex flex-col sm:flex-row gap-4",children:[(0,re.jsx)("div",{className:"flex-shrink-0",children:(0,re.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,re.jsx)("img",{src:a.screenshot_urls[0],alt:"".concat(a.name," screenshot"),className:"w-full h-full object-cover"}):(0,re.jsx)("div",{className:"w-full h-full flex items-center justify-center text-slate-400",children:(0,re.jsx)(od.A,{className:"w-6 h-6"})})})}),(0,re.jsx)("div",{className:"flex-grow min-w-0",children:(0,re.jsx)("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-2",children:(0,re.jsxs)("div",{className:"min-w-0",children:[(0,re.jsxs)("div",{className:"flex items-center gap-2",children:[(0,re.jsx)("h4",{className:"font-medium text-slate-900 truncate",children:a.name}),(0,re.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,re.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,re.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 dx=e=>{let{onClose:s,isOpen:t}=e;const{app:a}=_s();return(0,H.useEffect)(()=>{t&&ve.getLoginInfoById(a.id).then(e=>{})},[t]),(0,re.jsx)(to,{open:t,onOpenChange:e=>!e&&s(),children:(0,re.jsxs)(lo,{className:"w-full gap-4 font-base44",children:[(0,re.jsx)(Fa,{className:"space-y-0",children:(0,re.jsx)(co,{children:"Edit App Logo"})}),(0,re.jsx)(mx,{onSubmit:s})]})})},mx=e=>{var s,t;let{onSubmit:a}=e;const{app:n}=_s(),{isLoading:r,logoPrompt:l,defaultPrompt:i,handleRegenerateLogo:o,handleUploadLogo:c,handlePromptChange:d,handleUploadImageFile:m,logoUrl:u,isDirty:x}=(()=>{const{app:e}=_s(),s="A modern, minimalist logo for a business app",[t,a]=(0,H.useState)(e.logo_prompt),[n,r]=(0,H.useState)(e.logo_url);(0,H.useEffect)(()=>()=>{r(void 0)},[]);const l=ju(async()=>{const a=await ve.generateLogoFromPrompt(e.id,{prompt:t||s});return r(a.logo_url),a.logo_url},{toastError:"Failed to regenerate logo"}),i=ju(async s=>{const t=await As.uploadAppFile(s,e.id);return r(t.url),t.url},{toastError:"Failed to upload logo",initialResult:e.logo_url}),o=ju(async s=>{var t;const a=null!==(t=s.url)&&void 0!==t?t:(await As.uploadAppFile(s.file,e.id)).url;return r(a),ve.updateLogo(e.id,{logo_url:a})},{toastSuccess:"Logo uploaded successfully",toastError:"Failed to upload logo"});return{isLoading:l.isLoading||o.isLoading||i.isLoading,logoPrompt:t,defaultPrompt:s,handleRegenerateLogo:l.update,handleUploadLogo:o.update,handleUploadImageFile:i.update,handlePromptChange:e=>a(e.target.value),logoUrl:n,isDirty:n!==e.logo_url}})(),[h,p]=(0,H.useState)(!1),g=r||h;return(0,re.jsxs)(re.Fragment,{children:[(0,re.jsxs)("div",{className:"flex flex-col py-2 gap-3 items-center justify-center",children:[(0,re.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,re.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,re.jsx)("div",{className:"p-1 bg-gray-100 rounded-xl flex items-center justify-center",children:(0,re.jsx)("span",{className:"text-xl font-bold text-gray-400",children:(null===(s=n.name)||void 0===s||null===(t=s[0])||void 0===t?void 0:t.toUpperCase())||"A"})})}),(0,re.jsxs)(gu,{defaultValue:"upload",className:"w-full space-y-6",children:[(0,re.jsxs)(fu,{className:"grid w-full grid-cols-2 bg-normal",children:[(0,re.jsx)(vu,{value:"upload",className:"border-b-2 data-[state=active]:border-primary border-secondary rounded-none font-normal text-foreground",children:"Upload Logo"}),(0,re.jsx)(vu,{value:"generate",className:"border-b-2 data-[state=active]:border-primary border-secondary rounded-none font-normal text-foreground",children:"Generate Logo"})]}),(0,re.jsx)(bu,{value:"upload",className:" h-full rounded-lg",children:(0,re.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,re.jsx)("input",{type:"file",id:"logo-upload",className:"hidden pointer-events-none ",disabled:g,accept:"image/*",onChange:e=>{m(e.target.files[0])}}),(0,re.jsxs)("label",{htmlFor:"logo-upload",className:"pointer-events-none text-center",children:[(0,re.jsx)("p",{className:"text-sm text-foreground ",children:"Drag and drop or click to upload"}),(0,re.jsx)("p",{className:"text-xs text-muted-foreground",children:"PNG, JPG up to 5MB"}),(0,re.jsx)(Yn,{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,re.jsxs)(bu,{value:"generate",className:"space-y-1",children:[(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsx)(uu,{htmlFor:"logo-prompt",className:"text-muted-foreground",children:"What should yout logo look like?"}),(0,re.jsx)(du,{id:"logo-prompt",value:l,onChange:d,className:"min-h-[100px] rounded-lg",placeholder:i})]}),(0,re.jsx)(Yn,{onClick:o,disabled:g,variant:"secondary",size:"tiny",className:"w-full",children:g?"Generating...":"Generate new logo"})]})]})]}),(0,re.jsxs)("div",{className:"flex flex-row gap-2 items-center justify-end w-full",children:[(0,re.jsx)(Yn,{autoFocus:!x,variant:"outline",size:"tiny",onClick:a,children:"Cancel"}),(0,re.jsx)(Yn,{autoFocus:x,size:"tiny",onClick:async()=>{await c({url:u}),null==a||a()},disabled:g||!x,children:"Save"})]})]})};const ux=function(e){var s;let{onRouteChange:t}=e;const{user:a}=oe(),{app:n,updateApp:r}=_s(),{isInSharedWorkspace:l}=Uu(),i=(0,Z.Zp)(),o=(0,Z.zy)(),{toast:c}=nn(),[d,m]=(0,H.useState)(!1),[u,x]=(0,H.useState)(!1),[h,p]=(0,H.useState)(!1),[g,f]=(0,H.useState)(!1),[v,b]=(0,H.useState)(!1),[j,y]=(0,H.useState)(null),N=(0,H.useRef)(null),w=(0,H.useRef)(null),_=(0,H.useRef)(null),k=(0,H.useRef)(null),A=(0,H.useRef)(null),S=(0,H.useRef)(null),C=(0,H.useRef)(null),E=(0,H.useRef)(null),I=(0,H.useRef)(null),T=rx(a);(0,H.useEffect)(()=>{const e=new URLSearchParams(o.search).get("selectedParam");if(e){y(e);let s=null;switch(e){case"main-page":s=N;break;case"visibility":s=w;break;case"branding-badge":s=_;break;case"hide-created-by":s=k;break;case"enable-agents":s=A;break;case"clone-app":s=S;break;case"backend-functions":s=C;break;case"delete-app":s=E;break;case"admin-controls":s=I}s&&s.current&&setTimeout(()=>{s.current.scrollIntoView({behavior:"smooth",block:"center"})},300)}},[o.search]);const P=async()=>{try{await ve.delete(n.id),c({title:"Success",description:"App deleted successfully"}),i("/")}catch(e){c({title:"Error",description:"Failed to delete app",variant:"destructive"})}},L=e=>j===e?"selected-section p-4 rounded-md":"";return(0,re.jsxs)(su,{title:"App Settings",children:[(0,re.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,re.jsx)(xx,{}),(0,re.jsxs)(Xn,{children:[(0,re.jsx)(Qn,{className:"border-b border-gray-100",children:(0,re.jsx)(er,{className:"text-gray-800",children:"General Settings"})}),(0,re.jsxs)(tr,{className:"space-y-6 pt-6",children:[(0,re.jsxs)("div",{ref:N,className:"flex flex-col sm:flex-row justify-between sm:items-center gap-2 ".concat(L("main-page")),children:[(0,re.jsxs)("div",{children:[(0,re.jsx)("h3",{className:"text-sm font-medium",children:"Main Page"}),(0,re.jsx)("p",{className:"text-sm text-muted-foreground",children:"Set the default landing page for your app"})]}),(0,re.jsx)("div",{className:"w-full sm:w-64",children:(0,re.jsxs)(Ut,{value:n.main_page||"",onValueChange:async e=>{try{r({main_page:e}),c({title:"Success",description:"Main page updated successfully"})}catch(s){c({title:"Error",description:"Failed to update main page",variant:"destructive"})}},children:[(0,re.jsx)(Wt,{children:(0,re.jsx)(qt,{placeholder:"Select main page"})}),(0,re.jsx)(Ht,{children:Object.keys(n.pages||{}).map(e=>(0,re.jsx)($t,{value:e,children:e},e))})]})})]}),(0,re.jsx)(pt,{}),(0,re.jsxs)("div",{ref:w,className:"flex flex-col sm:flex-row justify-between sm:items-center gap-2 ".concat(L("visibility")),children:[(0,re.jsxs)("div",{children:[(0,re.jsx)("h3",{className:"text-sm font-medium",children:"App Visibility"}),(0,re.jsx)("p",{className:"text-sm text-muted-foreground",children:"Control who can access your application"})]}),(0,re.jsx)("div",{className:"w-full sm:w-64",children:(0,re.jsx)(Ju,{value:n.public_settings||"private_with_login",onValueChange:async e=>{x(!0);try{await r({public_settings:e}),c({title:"Success",description:"App visibility updated successfully"})}catch(s){c({title:"Error",description:"Failed to update app visibility",variant:"destructive"})}finally{x(!1)}},disabled:u,showWorkspace:l})})]}),(0,re.jsx)(pt,{}),(0,re.jsxs)("div",{ref:_,className:"flex flex-col sm:flex-row justify-between sm:items-center gap-2 ".concat(L("platform-badge")),children:[(0,re.jsxs)("div",{className:"flex-grow space-y-1",children:[(0,re.jsx)("h3",{className:"text-sm font-medium",children:"Platform Badge"}),(0,re.jsx)("p",{className:"text-sm text-muted-foreground",children:'Show or hide the "Edit with Base44" badge on your app.'}),"free"===a.subscription_tier&&(0,re.jsxs)("p",{className:"text-xs text-orange-500 pt-1",children:[(0,re.jsx)(Fs.A,{className:"h-3 w-3 inline-block mr-1 relative -top-px"}),"Available only for paying users.",(0,re.jsx)("a",{href:"/billing",className:"ml-1 underline font-medium hover:text-orange-700",children:"Upgrade now"})]})]}),(0,re.jsxs)("div",{className:"flex items-center space-x-2 flex-shrink-0 mt-2 sm:mt-0",children:[(0,re.jsx)(wu,{id:"platform-badge-switch",checked:!0===n.is_remixable,onCheckedChange:async e=>{p(!0);try{r({is_remixable:e}),c({title:"Success",description:"Platform badge will be ".concat(e?"visible":"hidden",".")})}catch(s){c({title:"Error",description:"Failed to update platform badge visibility.",variant:"destructive"})}finally{p(!1)}},disabled:"free"===a.subscription_tier||h,"aria-label":"Toggle platform badge visibility"}),(0,re.jsx)(Nt,{htmlFor:"platform-badge-switch",className:"text-sm text-muted-foreground",children:!0===n.is_remixable?"Visible":"Hidden"})]})]}),(0,re.jsx)(pt,{}),(0,re.jsxs)("div",{ref:k,className:"flex flex-col sm:flex-row justify-between sm:items-center gap-2 ".concat(L("hide-created-by")),children:[(0,re.jsxs)("div",{children:[(0,re.jsx)("h3",{className:"text-sm font-medium",children:"Hide Entity Creator"}),(0,re.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,re.jsxs)("div",{className:"flex items-center space-x-2 flex-shrink-0 mt-2 sm:mt-0",children:[(0,re.jsx)(wu,{id:"hide-created-by-switch",checked:!0===n.hide_entity_created_by,onCheckedChange:async e=>{f(!0);try{r({hide_entity_created_by:e}),c({title:"Success",description:"Entity creator information will be ".concat(e?"hidden":"visible"," in your app.")})}catch(s){c({title:"Error",description:"Failed to update entity creator visibility.",variant:"destructive"})}finally{f(!1)}},disabled:g,"aria-label":"Toggle hide entity creator"}),(0,re.jsx)(Nt,{htmlFor:"hide-created-by-switch",className:"text-sm text-muted-foreground",children:!0===n.hide_entity_created_by?"Hidden":"Visible"})]})]}),(0,re.jsx)(pt,{}),(0,re.jsxs)("div",{ref:A,className:"flex flex-col sm:flex-row justify-between sm:items-center gap-2 ".concat(L("enable-agents")),children:[(0,re.jsxs)("div",{children:[(0,re.jsxs)("div",{className:"flex items-center gap-2",children:[(0,re.jsx)("h3",{className:"text-sm font-medium",children:"AI Agents"}),(0,re.jsx)("span",{className:"px-2 py-0.5 text-xs font-medium bg-teal-100 text-teal-700 rounded-full",children:"Alpha"})]}),(0,re.jsx)("p",{className:"text-sm text-muted-foreground",children:"Build AI agents into your app using Base44's AI agents infrastructure"})]}),(0,re.jsxs)("div",{className:"flex items-center space-x-2 flex-shrink-0 mt-2 sm:mt-0",children:[(0,re.jsx)(wu,{id:"enable-agents-switch",checked:!0===n.agents_enabled,onCheckedChange:async e=>{b(!0);try{await r({agents_enabled:e}),c({title:"Success",description:"AI agents ".concat(e?"enabled":"disabled"," successfully.")})}catch(s){c({title:"Error",description:"Failed to update AI agents setting.",variant:"destructive"})}finally{b(!1)}},disabled:v,"aria-label":"Toggle AI agents"}),(0,re.jsx)(Nt,{htmlFor:"enable-agents-switch",className:"text-sm text-muted-foreground",children:!0===n.agents_enabled?"Enabled":"Disabled"})]})]}),n.agents_enabled&&(0,re.jsxs)(ex,{className:"bg-teal-50 border-teal-200",children:[(0,re.jsx)(fd.A,{className:"h-4 w-4 text-teal-600"}),(0,re.jsx)(sx,{className:"text-teal-800",children:"AI Agents Enabled"}),(0,re.jsx)(tx,{className:"text-teal-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,re.jsx)(pt,{}),(0,re.jsxs)("div",{ref:S,className:"flex flex-col sm:flex-row justify-between sm:items-center gap-2 ".concat(L("clone-app")),children:[(0,re.jsxs)("div",{children:[(0,re.jsx)("h3",{className:"text-sm font-medium",children:"Clone App"}),(0,re.jsx)("p",{className:"text-sm text-muted-foreground",children:"Create a duplicate of this app"})]}),(0,re.jsxs)(Hs,{onClick:async()=>{window.open("/remix-app/".concat(n.id,"?clone_history=true"),"_blank")},variant:"outline",className:"flex items-center border-gray-200 hover:bg-gray-50 hover:text-gray-700",children:[(0,re.jsx)(Kr.A,{className:"mr-2 h-4 w-4"}),"Create Copy"]})]}),(0,re.jsx)(pt,{}),(0,re.jsx)(cx,{onRouteChange:t}),(0,re.jsx)(pt,{}),(0,re.jsxs)("div",{ref:C,className:"flex flex-col sm:flex-row justify-between sm:items-center gap-2 ".concat(L("backend-functions")),children:[(0,re.jsxs)("div",{children:[(0,re.jsx)("h3",{className:"text-sm font-medium",children:"Backend Functions"}),(0,re.jsx)("p",{className:"text-sm text-muted-foreground",children:"Enable server-side functionality (Alpha)"})]}),T?(0,re.jsxs)(Hs,{onClick:async()=>{try{m(!0),await nx.activateBackendFunctions(n.id),c({title:"Success",description:"Backend functions activated successfully. Prompt the chat to build your backend functions."})}catch(e){c({title:"Error",description:"Failed to activate backend functions",variant:"destructive"})}finally{m(!1)}},disabled:d||!!n.has_backend_functions_enabled,variant:"outline",className:"flex items-center border-gray-200 hover:bg-gray-50 hover:text-gray-700",children:[(0,re.jsx)(Yr.A,{className:"mr-2 h-4 w-4"}),d?"Activating...":n.has_backend_functions_enabled?"Activated":"Activate"]}):(0,re.jsxs)(Hs,{variant:"outline",className:"flex items-center text-gray-500 border-gray-200 hover:bg-gray-50",onClick:()=>i("/billing"),children:[(0,re.jsx)(jl.A,{className:"mr-2 h-4 w-4"}),"Upgrade Plan"]})]}),T?!n.has_backend_functions_enabled&&(0,re.jsxs)(ex,{variant:"warning",className:"bg-gray-50 border-gray-200",children:[(0,re.jsx)(Fu.A,{className:"h-4 w-4 text-gray-500"}),(0,re.jsx)(sx,{className:"text-gray-800 text-lg",children:"Backend Functions - Alpha Feature"}),(0,re.jsx)(tx,{className:"text-gray-600",children:"This feature is currently in alpha and may be unstable. It is recommended only for developers at this time. Use with caution."})]}):(0,re.jsx)(lx,{})]})]}),(0,re.jsxs)(Xn,{className:"border-gray-200",children:[(0,re.jsxs)(Qn,{className:"border-b border-gray-100",children:[(0,re.jsx)(er,{className:"text-gray-800",children:"Danger Zone"}),(0,re.jsx)(sr,{className:"text-gray-600",children:"Irreversible actions that affect your app"})]}),(0,re.jsxs)(tr,{className:"space-y-6",children:[(0,re.jsxs)("div",{ref:E,className:"flex flex-col sm:flex-row justify-between sm:items-center gap-2 ".concat(L("delete-app")),children:[(0,re.jsxs)("div",{children:[(0,re.jsx)("h3",{className:"text-sm font-medium",children:"Delete App"}),(0,re.jsx)("p",{className:"text-sm text-muted-foreground",children:"Permanently remove this app and all its data"})]}),(0,re.jsxs)(Hs,{onClick:()=>{window.confirm("Are you sure you want to delete this app? This action cannot be undone.")&&P()},variant:"destructive",className:"flex items-center bg-red-500/90 hover:bg-red-600 text-white",children:[(0,re.jsx)(_u.A,{className:"mr-2 h-4 w-4"}),"Delete App"]})]}),(null===(s=a.platform_role)||void 0===s?void 0:s.includes("admin"))&&(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(pt,{}),(0,re.jsxs)("div",{ref:I,className:"flex flex-col sm:flex-row justify-between sm:items-center gap-2 ".concat(L("admin-controls")),children:[(0,re.jsxs)("div",{children:[(0,re.jsx)("h3",{className:"text-sm font-medium",children:"Admin Controls"}),(0,re.jsx)("p",{className:"text-sm text-muted-foreground",children:"Manage app availability"})]}),(0,re.jsxs)(Hs,{onClick:async()=>{try{r({is_blocked:!n.is_blocked}),c({title:"Success",description:"App ".concat(n.is_blocked?"unblocked":"blocked"," successfully")})}catch(e){c({title:"Error",description:"Failed to ".concat(n.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,re.jsx)(Bu.A,{className:"mr-2 h-4 w-4"}),n.is_blocked?"Unblock App":"Block App"]})]})]})]})]})]})},xx=()=>{var e,s;const{app:t,updateApp:a}=_s(),[n,r]=(0,H.useState)(!1),[l,i]=(0,H.useState)(t.description),[o,c]=(0,H.useState)(!1),d=ju(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,H.useEffect)(()=>{t.user_description&&i(t.user_description)},[t.user_description]),(0,re.jsxs)(re.Fragment,{children:[(0,re.jsxs)(Xn,{children:[(0,re.jsx)(Qn,{children:(0,re.jsx)(er,{children:"App Info"})}),(0,re.jsxs)(tr,{className:" flex flex-col gap-4",children:[(0,re.jsx)(pt,{}),(0,re.jsxs)("div",{className:"flex justify-between w-full h-full items-center",children:[(0,re.jsxs)("div",{className:"flex flex-row gap-3 items-center",children:[(0,re.jsx)("div",{className:"flex w-12 h-12 rounded-lg bg-white shadow items-center justify-center",children:t.logo_url?(0,re.jsx)("img",{src:t.logo_url,alt:"".concat(t.name," logo"),className:"w-full h-full object-contain rounded-lg"}):(0,re.jsx)("div",{className:"p-1 bg-gray-100 rounded-lg flex items-center justify-center object-contain",children:(0,re.jsx)("span",{className:"text-sm font-bold text-gray-400",children:(null===(e=t.name)||void 0===e||null===(s=e[0])||void 0===s?void 0:s.toUpperCase())||"A"})})}),(0,re.jsx)(Nt,{children:"App Logo"})]}),(0,re.jsx)(Yn,{onClick:()=>r(!0),variant:"outline",size:"tiny",children:"Edit Logo"})]}),(0,re.jsx)(pt,{}),(0,re.jsxs)("div",{className:"flex flex-col justify-between w-full h-full gap-3",children:[(0,re.jsxs)("div",{className:"flex flex-row gap-3 items-center justify-between",children:[(0,re.jsx)(Nt,{children:"App Description"}),(0,re.jsxs)("div",{className:"flex flex-row gap-2 items-center",children:[(0,re.jsx)(Yn,{size:"tiny",variant:"outline",onClick:()=>{c(e=>!e)},children:o?(0,re.jsx)(zs.A,{}):(0,re.jsx)(Hr.A,{})}),o&&(0,re.jsx)(Yn,{disabled:!o,onClick:()=>{d.update(l),c(!1)},size:"tiny",children:"Save Description"})]})]}),(0,re.jsx)("div",{className:"h-20",children:o?(0,re.jsx)(du,{disabled:!o,value:l,initialValue:t.user_description,onChange:e=>i(e.target.value),placeholder:"Describe your app...",className:"h-full resize-none"}):(0,re.jsx)("p",{className:"text-gray-600 text-sm mt-1",children:l})})]})]})]}),(0,re.jsx)(dx,{isOpen:n,onClose:()=>r(!1)})]})};function hx(){const[e,s]=(0,H.useState)(()=>"appListing"===new URLSearchParams(window.location.search).get("tab")?"appListing":"main"),t=e=>{s(e)},a={main:(0,re.jsx)(ux,{onRouteChange:t}),appListing:(0,re.jsx)("div",{className:"max-w-8xl mx-auto p-4",children:(0,re.jsx)(Mu,{onRouteChange:t})})};return(0,re.jsx)(Eu,{children:a[e]||a.main})}function px(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}}const gx=e=>{let{children:s,content:t,side:a="left"}=e;const n="right"===a,r="top"===a,l="bottom"===a,i="left"===a;return(0,re.jsxs)("div",{className:"relative group",children:[s,(0,re.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(l?"top-full mt-2 left-1/2 transform -translate-x-1/2":r?"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:[t,(0,re.jsx)("div",{className:"\n absolute border-4 border-transparent\n ".concat(l?"bottom-full -mb-1 left-1/2 transform -translate-x-1/2 border-b-gray-900":r?"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 ")})]})]})},fx=e=>{let{provider:s,icon:t,iconBg:a,title:n,description:r,checked:l,onToggle:i,disabled:o}=e;const c=a||"bg-white border-gray-200",d=o&&!l;return(0,re.jsx)("div",{className:"bg-white rounded-lg outline outline-1 outline-offset-[-1px] outline-gray-200 overflow-hidden ".concat(d?"opacity-60":""),children:(0,re.jsxs)("div",{className:"p-4 flex justify-start items-center gap-4",children:[(0,re.jsx)("div",{className:"w-10 h-10 rounded-lg border flex items-center justify-center ".concat(c," ").concat(d?"opacity-60":""),children:t}),(0,re.jsxs)("div",{className:"flex-1 flex flex-col justify-start items-start gap-0.5",children:[(0,re.jsx)("div",{className:"flex justify-center items-center gap-2",children:(0,re.jsx)("div",{className:"text-gray-900 text-sm font-medium leading-tight ".concat(d?"text-gray-400":""),children:n})}),(0,re.jsx)("div",{className:"self-stretch flex justify-center items-center gap-2.5",children:(0,re.jsx)("div",{className:"flex-1 text-gray-500 text-sm font-normal leading-tight ".concat(d?"text-gray-400":""),children:r})})]}),(0,re.jsx)(wu,{id:"".concat(s,"-auth-switch"),checked:l,onCheckedChange:e=>i(s,e),disabled:o})]})})};function vx(){const{user:e}=oe(),{app:s,updateApp:t,updateSecrets:a}=_s(),n=e.subscription_tier&&!["free","starter","pro"].includes(e.subscription_tier),r=(0,Z.zy)(),{toast:l}=nn(),[i,o]=(0,H.useState)(!1),[c,d]=(0,H.useState)(!1),[m,u]=(0,H.useState)(new Set),[x,h]=(0,H.useState)(!1),[p,g]=(0,H.useState)({name:"",client_id:"",client_secret:"",discovery_url:"",scope:"openid email profile",auth_endpoint:"",token_endpoint:"",userinfo_endpoint:"",jwks_uri:"",tenant_id:"",okta_domain:""}),[f,v]=(0,H.useState)(""),[b,j]=(0,H.useState)(null),[y,N]=(0,H.useState)({email_password:!1,google:!1,microsoft:!1,facebook:!1}),[w,_]=(0,H.useState)({email_password:!1,google:!1,microsoft:!1,facebook:!1}),k=[{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,re.jsx)("svg",{className:"w-5 h-5 text-white",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,re.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,re.jsxs)("svg",{className:"w-5 h-5",viewBox:"0 0 24 24",children:[(0,re.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,re.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,re.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,re.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,re.jsxs)("svg",{className:"w-5 h-5",viewBox:"0 0 24 24",children:[(0,re.jsx)("path",{fill:"#F25022",d:"M0 0h11.5v11.5H0z"}),(0,re.jsx)("path",{fill:"#00A4EF",d:"M12.5 0H24v11.5H12.5z"}),(0,re.jsx)("path",{fill:"#7FBA00",d:"M0 12.5h11.5V24H0z"}),(0,re.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,re.jsx)("svg",{className:"w-5 h-5 text-white",fill:"currentColor",viewBox:"0 0 24 24",children:(0,re.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"})})}],A={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"}]}},S=(0,H.useRef)(null);(0,H.useEffect)(()=>{const e=new URLSearchParams(r.search).get("selectedParam");if(e){j(e);let s=null;if("sso-settings"===e)s=S,d(!0);s&&s.current&&setTimeout(()=>{s.current.scrollIntoView({behavior:"smooth",block:"center"})},300)}},[r.search]),(0,H.useEffect)(()=>{if(s){const e=px(s),t=e.enable_sso_login;Object.values(w).some(e=>e)||N({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,w]),(0,H.useEffect)(()=>{(async()=>{if(null!=s&&s.id)try{const e=px(s),t=await vs.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=A[e.sso_provider_name]?e.sso_provider_name:"advanced";else if(n.name){const e=Object.entries(A).find(e=>{let[s,t]=e;return t.name===n.name});r=e?e[0]:"advanced"}else x&&!e.sso_provider_name&&(r="google");let l=n;const i=new Set;if(r&&"advanced"===r)l=(0,K.A)((0,K.A)({},n),{},{name:e.sso_provider_name||n.name||""}),e.sso_provider_name&&e.sso_provider_name!==n.name&&i.add("name");else if(r&&A[r]){const e=A[r],s={};if(Object.entries(e.defaults||{}).forEach(e=>{let[t,a]=e;n[t]||(s[t]=a,i.add(t))}),l=(0,K.A)((0,K.A)((0,K.A)({},n),s),{},{name:e.name}),e.name!==n.name&&i.add("name"),e.autoGenerate){const s=l[e.autoGenerate.field];s&&!l[e.autoGenerate.target]&&(l[e.autoGenerate.target]=e.autoGenerate.template(s),i.add(e.autoGenerate.target))}}g(l),v(r),u(i)}catch(e){const t=px(s);g({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:""}),v(""),u(new Set)}})()},[null==s?void 0:s.id,null==s?void 0:s.auth_config,x]);const C=(e,s)=>{g(t=>{const a=(0,K.A)((0,K.A)({},t),{},{[e]:s}),n=A[f];if(null!=n&&n.autoGenerate&&e===n.autoGenerate.field&&s){const e=n.autoGenerate.template(s);a[n.autoGenerate.target]=e,u(e=>new Set(e).add(n.autoGenerate.target))}return a}),u(s=>new Set(s).add(e))},E=e=>e&&A[e]&&A[e].fields||[],I=e=>e&&"string"==typeof e&&(e.match(/^x+$/)||e.match(/^\u2022+$/)),T=(e,s)=>I(s)?"\u2022".repeat(20):s,P=async(e,a)=>{if(w[e])return;const n=px(s);if(a&&n.enable_sso_login&&"email_password"!==e)return void l({title:"Cannot Enable Social Provider",description:"Please disable SSO first before enabling social providers",variant:"destructive"});const r={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(r){N(s=>(0,K.A)((0,K.A)({},s),{},{[e]:a})),_(s=>(0,K.A)((0,K.A)({},s),{},{[e]:!0}));try{s.auth_config[r.field]=a,await t({auth_config:(0,K.A)((0,K.A)({},s.auth_config),{},{[r.field]:a})}),l({title:"".concat(r.name,a?" Authentication Enabled":" Authentication Disabled"),description:"".concat(r.name,a?" authentication is now enabled for your app":" authentication has been disabled")})}catch(i){N(s=>(0,K.A)((0,K.A)({},s),{},{[e]:!a})),l({title:"Error",description:"Failed to update ".concat(r.name," authentication"),variant:"destructive"})}finally{_(s=>(0,K.A)((0,K.A)({},s),{},{[e]:!1}))}}};return(0,re.jsxs)("div",{className:"max-w-4xl mx-auto p-4 space-y-6",children:[(0,re.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,re.jsxs)("div",{className:"space-y-6",children:[(0,re.jsxs)("div",{children:[(0,re.jsx)("h2",{className:"text-2xl font-semibold text-gray-800",children:"Authentication"}),(0,re.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)","."]})]}),(0,re.jsx)("div",{className:"space-y-3",children:k.map(e=>(0,re.jsx)(fx,{provider:e.id,icon:e.icon,iconBg:e.iconBg,title:e.title,description:e.description,checked:y[e.id],onToggle:P,disabled:!!px(s).enable_sso_login&&"email_password"!==e.id},e.id))}),(0,re.jsxs)("div",{className:"flex items-center py-2",children:[(0,re.jsx)("div",{className:"flex-1 border-t border-gray-200"}),(0,re.jsx)("div",{className:"px-3 text-gray-500 text-sm font-medium",children:"or"}),(0,re.jsx)("div",{className:"flex-1 border-t border-gray-200"})]})]}),(0,re.jsxs)("div",{ref:S,className:"bg-white rounded-lg outline outline-1 outline-offset-[-1px] outline-gray-200 ".concat((L="sso-settings",b===L?"selected-section p-4 rounded-md":"")," ").concat(n?"":"opacity-75"),children:[(0,re.jsxs)("div",{className:"p-4 flex justify-start items-center gap-4",children:[(0,re.jsx)("div",{className:"w-10 h-10 bg-slate-900 rounded-lg border border-slate-900 flex items-center justify-center",children:(0,re.jsx)("svg",{className:"w-5 h-5 text-white",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,re.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,re.jsxs)("div",{className:"flex-1 flex flex-col justify-start items-start gap-0.5",children:[(0,re.jsxs)("div",{className:"flex justify-center items-center gap-2",children:[(0,re.jsx)("div",{className:"text-gray-900 text-sm font-medium leading-tight",children:"Single Sign-on (SSO)"}),(0,re.jsx)(gx,{content:"Early-stage feature for feedback. Subject to change or removal.",side:"top",children:(0,re.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,re.jsx)("div",{className:"w-1.5 h-1.5 bg-orange-400 rounded-full animate-pulse"}),(0,re.jsx)("span",{className:"text-xs font-medium text-orange-800",children:"Elite Early Preview"})]})})]}),(0,re.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,re.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,re.jsx)("div",{className:"flex items-center gap-3",children:px(s).sso_provider_name&&!x?(0,re.jsx)(wu,{id:"sso-toggle",checked:!0===px(s).enable_sso_login,onCheckedChange:async e=>{if(i)return;px(s).sso_provider_name;const a=(0,K.A)({},y),n=c;e?(N(e=>(0,K.A)((0,K.A)({},e),{},{google:!1,microsoft:!1,facebook:!1})),d(!0)):d(!1),o(!0);try{e?(await t({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})}),l({title:"SSO Enabled",description:"Single Sign-On has been enabled and social login providers have been disabled. Please configure your SSO settings."})):(await t({auth_config:(0,K.A)((0,K.A)({},s.auth_config),{},{enable_sso_login:!1})}),h(!1),l({title:"SSO Disabled",description:"Single Sign-On has been disabled"}))}catch(r){N(a),d(n),l({title:"Error",description:"Failed to update SSO settings",variant:"destructive"})}finally{o(!1)}},disabled:!1}):x?(0,re.jsx)(wu,{id:"sso-toggle",checked:!1,onCheckedChange:()=>{},disabled:!0}):(0,re.jsx)(gx,{content:n?"Configure Single Sign-On for your app":"SSO is available for Elite tier and above",side:"left",children:(0,re.jsx)("button",{onClick:()=>{n&&(h(!0),d(!0),v("google"))},className:"px-4 py-2 border rounded-md text-xs font-medium leading-4 tracking-normal transition-colors ".concat(n?"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:i||!n,children:i?"Setting up...":"Set Up"})})})]}),(px(s).sso_provider_name||x)&&!c&&(0,re.jsx)("div",{className:"px-4 pb-4",children:(0,re.jsxs)("button",{onClick:()=>{const e=c;if(d(!c),e)v(""),u(new Set);else{const e=px(s);e.sso_provider_name?A[e.sso_provider_name]?v(e.sso_provider_name):v("advanced"):v("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,re.jsx)("div",{className:"text-gray-900 text-sm font-medium",children:x?"Set up SSO Configuration":((e,t,a)=>{const n=px(s);return(null===(e=A[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,re.jsxs)("div",{className:"flex items-center gap-2 text-gray-500",children:[(0,re.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,re.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,re.jsx)("span",{className:"text-sm",children:x?"Set up":"Configure"}),(0,re.jsx)(It.A,{className:"w-4 h-4 transition-transform ".concat(c?"rotate-180":"")})]})]})}),c&&(px(s).sso_provider_name||x)&&(0,re.jsx)("div",{className:"border-t border-gray-100 p-4 bg-white",children:(0,re.jsxs)("div",{className:"space-y-4",children:[(0,re.jsxs)("div",{children:[(0,re.jsx)("div",{className:"text-gray-500 text-sm font-normal leading-tight mb-2",children:"Select SSO Provider"}),(0,re.jsxs)(Ut,{value:f,onValueChange:e=>{v(e);const t=px(s);if("advanced"===e){const e=t.sso_provider_name&&!A[t.sso_provider_name];g(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&&A[e]){const s=A[e];if(t.sso_provider_name===e)g(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}}g(t)}}},children:[(0,re.jsx)(Wt,{className:"w-full px-4 py-3 bg-white rounded-md shadow-sm outline outline-1 outline-offset-[-1px] outline-gray-200",children:(0,re.jsx)(qt,{placeholder:"Select SSO Provider"})}),(0,re.jsx)(Ht,{children:Object.entries(A).map(e=>{let[s,t]=e;return(0,re.jsx)($t,{value:s,children:t.displayName},s)})})]})]}),(e=>{const s=E(e);if(!s.length)return null;const t=s.reduce((e,s)=>{const t=s.row||1;return e[t]||(e[t]=[]),e[t].push(s),e},{});return(0,re.jsx)("div",{className:"space-y-4",children:Object.entries(t).sort((e,s)=>{let[t]=e,[a]=s;return parseInt(t)-parseInt(a)}).map(s=>{let[t,a]=s;return(0,re.jsx)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:a.map((s,t)=>{var n,r,l,i;const o=a.length>1&&1===t,c=p[s.name]||"",d=s.placeholder||"Enter ".concat(s.name.replace("_"," ")),m=T(s.name,c),u="discovery_url"===s.name&&"discovery_url"===(null===(n=A[e])||void 0===n||null===(r=n.autoGenerate)||void 0===r?void 0:r.target)&&c;return(0,re.jsxs)("div",{children:[(0,re.jsxs)(Nt,{className:"text-gray-500 text-sm flex items-center gap-1",children:[s.name.replace("_"," ").replace(/\b\w/g,e=>e.toUpperCase()),s.required&&" *",s.name===(null===(l=A[e])||void 0===l||null===(i=l.autoGenerate)||void 0===i?void 0:i.target)&&c&&" (Auto-generated)",(0,re.jsx)(gx,{content:s.tooltip,side:o?"right":"left",children:(0,re.jsx)(jo.A,{className:"w-3.5 h-3.5 text-gray-400 hover:text-gray-600 cursor-help"})})]}),(0,re.jsx)(ft,{className:"mt-1 w-full h-8 ".concat(u?"bg-gray-50":""),type:"text",placeholder:d,value:m,onChange:e=>{I(e.target.value)||C(s.name,e.target.value)},onFocus:e=>{I(m)&&(e.target.value="",C(s.name,""))},readOnly:u})]},s.name)})},t)})})})(f),(0,re.jsxs)("div",{className:"flex justify-between pt-4",children:[(0,re.jsx)(Hs,{onClick:()=>{d(!1),x&&h(!1),v(""),u(new Set)},variant:"outline",className:"border-gray-300 text-gray-700 hover:bg-gray-50",children:x?"Cancel Setup":"Dismiss"}),(0,re.jsx)(Hs,{onClick:async()=>{o(!0);try{const e={};Object.keys(p).forEach(s=>{const t=p[s];!t||I(t)||!m.has(s)&&""===t||(e["sso_".concat(s)]=t)}),Object.keys(e).length>0&&await a(e);let n=null;f&&"advanced"!==f?n=f:"advanced"===f&&(n=p.name||"advanced");const r={sso_provider_name:n,enable_sso_login:!0};x&&(r.enable_google_login=!1,r.enable_microsoft_login=!1,r.enable_facebook_login=!1),await t({auth_config:(0,K.A)((0,K.A)({},s.auth_config),r)}),u(new Set),x&&(h(!1),N(e=>(0,K.A)((0,K.A)({},e),{},{google:!1,microsoft:!1,facebook:!1}))),d(!1);const i=Object.keys(e).length;l({title:"Success",description:x?"SSO has been enabled and configured successfully":i>0?"SSO settings updated successfully (".concat(i," configuration").concat(1===i?"":"s"," saved)"):"SSO provider updated successfully"})}catch(e){l({title:"Error",description:"Failed to update SSO settings",variant:"destructive"})}finally{o(!1)}},disabled:i||!f||E(f).some(e=>e.required&&!p[e.name]),className:"bg-gray-900 text-white",children:i?"Saving...":x?"Enable SSO":"Save SSO Settings"})]})]})})]})]});var L}const bx=["value","onChange","language","readOnly","height","className","style","isSaving"],jx=e=>{let{value:s,onChange:t,language:a="javascript",readOnly:n=!1,height:r,className:l,style:i,isSaving:o}=e,c=(0,as.A)(e,bx);const d={};return r&&(d.height=r),(0,re.jsxs)("div",{className:"relative h-full",children:[(0,re.jsx)(cl.KE,(0,K.A)((0,K.A)({defaultLanguage:a,value:s,onChange:e=>{t&&!n&&t(e)},options:{minimap:{enabled:!1},scrollBeyondLastLine:!1,fontSize:14,readOnly:n}},d),c)),o&&(0,re.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 yx=function(){var e;const{user:s}=oe(),{app:t}=_s(),[a,n]=(0,H.useState)(!1),[r,l]=(0,H.useState)(Object.keys(t.entities)[0]||"EntityName"),[i,o]=(0,H.useState)("javascript"),c=(null===(e=t.entities[r])||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(r,"Entities() {\n const response = await fetch(`").concat((0,ee.Gt)(),"/apps/").concat(t.id,"/entities/").concat(r,"`, {\n headers: {\n 'api_key': '").concat(s.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(r,"Entity(entityId, updateData) {\n const response = await fetch(`").concat((0,ee.Gt)(),"/apps/").concat(t.id,"/entities/").concat(r,"/${entityId}`, {\n method: 'PUT',\n headers: {\n 'api_key': '").concat(s.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(s.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(t.id,"/entities/").concat(r,"')\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(t.id,"/entities/").concat(r,"/{entity_id}',\n headers={\n 'api_key': '").concat(s.api_key,"',\n 'Content-Type': 'application/json'\n },\n json=update_data\n )\n response.raise_for_status()\n return response.json()");return(0,re.jsx)(su,{title:"API Integration",subtitle:"Get copy-paste examples for API integration.",children:(0,re.jsx)(Xn,{children:(0,re.jsx)(tr,{className:"p-6",children:(0,re.jsx)(su,{className:"gap-4 p-0 text-lg",title:(0,re.jsx)("div",{className:"font-normal",children:"Example: API Operations"}),subtitle:"Select an entity to generate code examples for reading and updating:",filters:[Object.keys(t.entities||{}).length>0?(0,re.jsx)("div",{className:"min-w-[180px]",children:(0,re.jsxs)(In,{value:r,onValueChange:e=>l(e),children:[(0,re.jsx)(Pn,{children:(0,re.jsx)(Tn,{placeholder:"Select main page"})}),(0,re.jsx)(Rn,{children:Object.keys(t.entities).map(e=>(0,re.jsx)(Dn,{value:e,children:e},e))})]})}):null,(0,re.jsxs)("div",{className:"flex flex-row gap-2",children:[(0,re.jsx)(Yn,{variant:"javascript"===i?"secondary":"ghost",onClick:()=>o("javascript"),className:"".concat("javascript"===i?"font-bold":""),children:"JavaScript"}),(0,re.jsx)(Yn,{variant:"python"===i?"secondary":"ghost",onClick:()=>o("python"),className:"".concat("python"===i?"font-bold":""),children:"Python"})]})],children:(0,re.jsxs)("div",{className:"border rounded-md p-2 relative",children:[(0,re.jsx)(jx,{value:"javascript"===i?m:u,language:i,readOnly:!0,height:"600px"}),(0,re.jsx)("div",{className:"absolute top-0 right-0",children:(0,re.jsx)(Yn,{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,re.jsx)(Pt.A,{className:"h-4 w-4"}):(0,re.jsx)(Kr.A,{className:"h-4 w-4"})})})]})})})})})};var Nx=t(51654);const wx=["onClick","saveSize","className"],_x=(0,ns.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 kx(e){let{onClick:s,saveSize:t="default",className:a}=e,n=(0,as.A)(e,wx);const r="sm"===t?"h-3 w-3":"lg"===t?"h-5 w-5":"xl"===t?"h-6 w-6":"h-4 w-4";return(0,re.jsx)(Yn,(0,K.A)((0,K.A)({},n),{},{onMouseDown:e=>{e.preventDefault(),e.stopPropagation(),n.disabled||s()},className:is(_x({saveSize:t}),a),children:(0,re.jsx)(Pt.A,{className:r})}))}function Ax(e){let{initialText:s,onChange:t,className:a="",minWidth:n=60,maxWidth:r=280,validate:l}=e;const[i,o]=(0,H.useState)(!1),[c,d]=(0,H.useState)(s),[m,u]=(0,H.useState)(s),[x,h]=(0,H.useState)(n),[p,g]=(0,H.useState)(!1),f=(0,H.useRef)(null),v=(0,H.useRef)(null),b=(0,H.useRef)(null),j=()=>{if(b.current){const e=b.current.scrollWidth||b.current.offsetWidth,s=Math.min(Math.max(e,n),r),t=r;h(i?t:s),f.current&&(f.current.style.width="".concat(t,"px"))}};(0,H.useEffect)(()=>{i&&f.current&&(f.current.focus(),j())},[i]),(0,H.useEffect)(()=>{j()},[c,i,n,r]),(0,H.useEffect)(()=>{d(s)},[s]);const y=()=>{u(c),o(!0)},N=()=>{g(!0),t(c),o(!1),g(!1)},w=()=>{d(m),o(!1)},_=()=>!l||l(c);return(0,re.jsxs)("div",{className:"inline-flex items-center group relative",children:[(0,re.jsxs)("div",{className:"relative",style:{minWidth:"".concat(n,"px"),maxWidth:"".concat(r,"px")},children:[i?(0,re.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,re.jsx)("span",{ref:v,onClick:y,className:"cursor-pointer whitespace-nowrap overflow-hidden text-ellipsis block ".concat(a),children:c}),(0,re.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,re.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,re.jsx)("div",{className:"ml-2 w-7 h-7 flex items-center justify-center relative",children:i?(0,re.jsx)(kx,{onClick:N,disabled:!_(),saveSize:"lg",variant:"outline"}):(0,re.jsx)(Hr.A,{className:"h-5 w-5 text-slate-400 cursor-pointer",onClick:y})})]})}const Sx=()=>{const{user:e}=oe();return{hasFlag:s=>{var t;return(null==e||null===(t=e.feature_flags)||void 0===t?void 0:t.includes(s))||!1}}};function Cx(e){let{onClosePublish:s}=e;const{app:t}=_s(),a=(0,Z.Zp)(),{hasFlag:n}=Sx(),[r,l]=(0,H.useState)(!1),[i,o]=(0,H.useState)(!1),c=(e=>{if(!e||!e.entities)return!1;const s=Object.values(e.entities),t=s.length>0&&s.some(e=>!e.rls),a="public_without_login"===e.public_settings||"public_with_login"===e.public_settings;return t&&a})(t),d="security-warning-dismissed-".concat(t.id),m=n("show-publish-security-warning");(0,H.useEffect)(()=>{"true"===localStorage.getItem(d)&&l(!0)},[d]);const u=()=>{i||(o(!0),s&&s(),a("/apps/".concat(t.id,"/editor/workspace/security?autoStartScan=1")),o(!1))};return c&&!r&&m?(0,re.jsx)("div",{className:"pt-2",children:(0,re.jsx)(us,{variant:"destructive",className:"border-amber-300 bg-amber-100 text-gray-800 p-3",children:(0,re.jsx)("div",{className:"flex items-start justify-between w-full",children:(0,re.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,re.jsx)("div",{className:"font-semibold text-gray-800 text-sm mb-1",children:(0,re.jsx)("span",{children:"Your app data is publicly accessible"})}),(0,re.jsxs)(hs,{className:"text-gray-800 text-sm ",children:["Run a security scan and follow the recommendations to protect it.",(0,re.jsx)("div",{className:"mt-3",children:(0,re.jsx)(Hs,{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 Ex=t(61165);function Ix(e){let{app:s}=e;const{workspaces:t}=ge(),{user:a}=oe(),{toast:n}=nn(),[r,l]=((0,Z.Zp)(),(0,H.useState)(!1)),[i,o]=(0,H.useState)(""),[c,d]=(0,H.useState)(!1),m=(null==s?void 0:s.organization_id)===(null==a?void 0:a.organization_id),u=(null==s?void 0:s.organization_id)===(null==a?void 0:a.personal_organization_id),x=null==t?void 0:t.find(e=>e.id===(null==s?void 0:s.organization_id)),h=!0===(null==x?void 0:x.is_personal),p=m||u||h,g=(null==t?void 0:t.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,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(it,{className:"mt-4",children:(0,re.jsx)(mt,{className:"p-4",children:(0,re.jsxs)("div",{className:"flex items-center justify-between",children:[(0,re.jsxs)("div",{children:[(0,re.jsx)("h3",{className:"text-base font-semibold",children:"Move to Workspace"}),(0,re.jsx)("p",{className:"text-gray-600 text-xs mt-1",children:"Move this app from your personal workspace to a shared workspace"})]}),(0,re.jsxs)(Hs,{variant:"outline",size:"sm",onClick:()=>l(!0),className:"gap-1.5",children:[(0,re.jsx)(Ex.A,{className:"w-3.5 h-3.5"}),"Move App"]})]})})}),(0,re.jsx)(Pa,{open:r,onOpenChange:l,children:(0,re.jsxs)(Ma,{className:"sm:max-w-md",children:[(0,re.jsxs)(Fa,{children:[(0,re.jsx)(Ua,{children:"Move App to Workspace"}),(0,re.jsx)(za,{children:"Select a workspace to move this app to. This action cannot be undone."})]}),(0,re.jsxs)("div",{className:"py-4 space-y-4",children:[(0,re.jsxs)("div",{children:[(0,re.jsx)("label",{className:"text-sm font-medium mb-2 block",children:"Target Workspace"}),(0,re.jsxs)(Ut,{value:i,onValueChange:o,children:[(0,re.jsx)(Wt,{children:(0,re.jsx)(qt,{placeholder:"Select a workspace"})}),(0,re.jsx)(Ht,{children:g.map(e=>(0,re.jsx)($t,{value:e.id,children:e.name},e.id))})]})]}),(0,re.jsxs)("div",{className:"text-sm text-gray-600 space-y-2",children:[(0,re.jsxs)("p",{children:["\u26a0\ufe0f ",(0,re.jsx)("strong",{children:"Important:"})]}),(0,re.jsxs)("ul",{className:"list-disc list-inside space-y-1 text-xs",children:[(0,re.jsx)("li",{children:"The app will be moved to the selected workspace"}),(0,re.jsx)("li",{children:"Future usage will count against the new workspace's credits"}),(0,re.jsx)("li",{children:"Workspace members with appropriate permissions will gain access"}),(0,re.jsx)("li",{children:"You will retain ownership as the app creator"})]})]})]}),(0,re.jsxs)(Ba,{children:[(0,re.jsx)(Hs,{variant:"outline",onClick:()=>l(!1),children:"Cancel"}),(0,re.jsx)(Hs,{onClick:async()=>{if(i){d(!0);try{await ve.moveToWorkspace(s.id,i),n({title:"Success",description:"App moved to workspace successfully"}),window.location.reload()}catch(a){var e,t;n({title:"Error",description:(null===(e=a.response)||void 0===e||null===(t=e.data)||void 0===t?void 0:t.detail)||"Failed to move app to workspace",variant:"destructive"})}finally{d(!1),l(!1)}}else n({title:"Error",description:"Please select a target workspace",variant:"destructive"})},disabled:!i||c,children:c?"Moving...":"Move App"})]})]})})]}):null}function Tx(){var e,s;const{app:t,updateApp:a}=_s(),{isInSharedWorkspace:n}=Uu(),r=(0,Z.Zp)(),{toast:l}=nn(),[i,o]=(0,H.useState)(!1),[c,d]=(0,H.useState)(!1),[m,u]=(0,H.useState)(!1),[x,h]=(0,H.useState)(!1),[p,g]=(0,H.useState)(!1),[f,v]=(0,H.useState)(""),[b,j]=(0,H.useState)([]),[y,N]=(0,H.useState)(!1);(0,H.useEffect)(()=>{(async()=>{if(null!=t&&t.id)try{const e=await Ha.filter({app_id:t.id});j(e)}catch(e){}})()},[null==t?void 0:t.id]);const w=b.length>0?"https://".concat(b[0].domain):fa(t);(0,H.useEffect)(()=>{t.user_description&&v(t.user_description)},[t.user_description]);return(0,re.jsxs)("div",{className:"h-full bg-gray-50 p-4 sm:p-6",children:[(0,re.jsxs)("div",{className:"max-w-6xl mx-auto",children:[(0,re.jsxs)("div",{className:"space-y-6 mb-8",children:[(0,re.jsxs)("div",{className:"flex flex-col sm:flex-row gap-4 sm:gap-6 items-start sm:items-center",children:[(0,re.jsxs)("div",{className:"relative cursor-pointer",onClick:()=>N(!0),children:[(0,re.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,re.jsx)(Hr.A,{color:"white",className:"h-5 w-5"})}),(0,re.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:t.logo_url?(0,re.jsx)("img",{src:t.logo_url,alt:"".concat(t.name," logo"),className:"w-full h-full object-contain rounded-xl"}):(0,re.jsx)("div",{className:"p-1 bg-gray-100 rounded-xl flex items-center justify-center",children:(0,re.jsx)("span",{className:"text-xl font-bold text-gray-400",children:(null===(e=t.name)||void 0===e||null===(s=e[0])||void 0===s?void 0:s.toUpperCase())||"A"})})})]}),(0,re.jsxs)("div",{className:"flex-grow min-w-0",children:[(0,re.jsxs)("div",{className:"flex items-center justify-between flex-wrap",children:[(0,re.jsx)("h1",{className:"text-2xl font-bold text-gray-900",children:(0,re.jsx)(Ax,{initialText:t.name||"untitled",onChange:async e=>{var s;"ready"===(null===(s=t.status)||void 0===s?void 0:s.state)?0!==e.length?a({name:e}):l({title:"Error",description:"App name cannot be empty",variant:"destructive"}):l({title:"Error",description:"App is still loading... name not updated",variant:"destructive"})},validate:e=>e.trim().length>0})}),(0,re.jsx)(Hs,{variant:"ghost",size:"sm",onClick:()=>{a({is_starred:!t.is_starred}),l({title:t.is_starred?"Removed from favorites":"Added to favorites",description:t.is_starred?"App removed from your starred list":"App added to your starred list"})},className:"hover:bg-yellow-100 transition-colors ".concat(t.is_starred?"text-yellow-500":"text-gray-400"),children:(0,re.jsx)(jr.A,{className:"h-4 w-4 ".concat(t.is_starred?"fill-current":"")})})]}),(0,re.jsxs)("div",{className:"flex items-center gap-2",children:[(0,re.jsx)("p",{className:"text-gray-600 text-sm mt-1",children:t.user_description}),(0,re.jsx)(Hs,{variant:"ghost",size:"sm",onClick:()=>{v(t.user_description||""),g(!0)},className:"mt-1 p-1 pr-3 h-auto",children:(0,re.jsx)(Hr.A,{className:"h-3 w-3 text-gray-400"})})]}),(0,re.jsxs)("p",{className:"text-xs text-muted-foreground mt-1",children:["Created ",la().utc(t.created_date).fromNow()]})]})]}),(0,re.jsxs)("div",{className:"flex flex-wrap gap-3",children:[(0,re.jsxs)(Hs,{variant:"outline",onClick:()=>{r("/apps/".concat(t.id,"/editor/preview/").concat(Object.keys(t.pages)[0]))},className:"gap-1.5 w-36 h-10",children:[(0,re.jsx)(jl.A,{className:"w-4 h-4"}),"Open App"]}),(0,re.jsxs)(Hs,{variant:"outline",onClick:()=>u(!0),className:"gap-1.5 w-36 h-10",children:[(0,re.jsx)(qa.A,{className:"w-4 h-4 ml-[-8px]"}),(0,re.jsxs)("div",{className:"flex flex-col items-start",children:[(0,re.jsx)("span",{className:"mb-[-6px]",children:"Share App"}),(0,re.jsx)("span",{className:"text-[9px] mb-[-3px] text-gray-500",children:"win free credits!"})]})]})]})]}),(0,re.jsxs)("div",{className:"grid sm:grid-cols-2 gap-4",children:[(0,re.jsx)(it,{children:(0,re.jsxs)(mt,{className:"p-4",children:[(0,re.jsx)("div",{className:"flex items-center justify-between mb-6",children:(0,re.jsxs)("div",{children:[(0,re.jsx)("h3",{className:"text-base font-semibold",children:"App Visibility"}),(0,re.jsx)("p",{className:"text-gray-600 text-xs mt-1",children:"Control who can access your application"})]})}),(0,re.jsxs)("div",{children:[(0,re.jsx)(Ju,{value:t.public_settings||"private_with_login",onValueChange:async e=>{o(!0);try{await a({public_settings:e})}finally{o(!1)}},disabled:i,showWorkspace:n}),(0,re.jsx)(Cx,{})]})]})}),(0,re.jsx)(it,{children:(0,re.jsxs)(mt,{className:"p-4",children:[(0,re.jsxs)("div",{className:"flex items-start justify-between mb-6",children:[(0,re.jsxs)("div",{children:[(0,re.jsx)("h3",{className:"text-base font-semibold mb-1",children:"Invite Users"}),(0,re.jsx)("p",{className:"text-gray-600 text-xs",children:"Grow your user base by inviting others"})]}),(0,re.jsx)(Gr.A,{className:"w-4 h-4 text-gray-400"})]}),(0,re.jsxs)("div",{className:"flex gap-2",children:[(0,re.jsxs)(Hs,{variant:"outline",className:"w-full h-10 text-sm",onClick:()=>{return e=w,navigator.clipboard.writeText(e),h(!0),void setTimeout(()=>h(!1),2e3);var e},children:[(0,re.jsx)(Kr.A,{className:"w-3 h-3 mr-1"}),x?"Copied!":"Copy Link"]}),(0,re.jsx)(Hs,{className:"w-full h-10 text-sm bg-blue-600 hover:bg-blue-700",onClick:()=>d(!0),children:"Send Invites"})]})]})})]}),(0,re.jsx)(Ix,{app:t}),!0===t.is_remixable&&(0,re.jsx)(it,{className:"mt-4",children:(0,re.jsx)(mt,{className:"p-4",children:(0,re.jsxs)("div",{className:"flex items-center justify-between",children:[(0,re.jsxs)("div",{children:[(0,re.jsx)("h3",{className:"text-base font-semibold",children:"Platform Badge"}),(0,re.jsx)("p",{className:"text-gray-600 text-xs mt-1",children:'The "Edit with Base44" badge is currently visible on your app.'})]}),(0,re.jsxs)(Hs,{variant:"outline",size:"sm",onClick:()=>{r("/apps/".concat(t.id,"/editor/workspace/app-settings?selectedParam=platform-badge"))},className:"gap-1.5",children:[(0,re.jsx)(Nx.A,{className:"w-3.5 h-3.5"}),"Hide Badge"]})]})})})]}),(0,re.jsx)(dx,{isOpen:y,onClose:()=>N(!1)}),(0,re.jsx)(ru,{isVisible:c,onCancel:()=>d(!1),onInviteSuccess:()=>d(!1)}),(0,re.jsx)(Ga,{app:t,isOpen:m,onClose:()=>u(!1)}),(0,re.jsx)(Pa,{open:p,onOpenChange:g,children:(0,re.jsxs)(Ma,{className:"sm:max-w-md",children:[(0,re.jsxs)(Fa,{children:[(0,re.jsx)(Ua,{children:"Edit App Description"}),(0,re.jsx)(za,{children:"Provide a brief description of your app's purpose and functionality."})]}),(0,re.jsx)("div",{className:"py-4",children:(0,re.jsx)(td,{value:f,onChange:e=>v(e.target.value),placeholder:"Describe your app...",className:"min-h-[100px]"})}),(0,re.jsxs)(Ba,{children:[(0,re.jsx)(Hs,{variant:"outline",onClick:()=>g(!1),children:"Cancel"}),(0,re.jsx)(Hs,{onClick:async()=>{try{await a({user_description:f}),g(!1),l({title:"Description updated",description:"Your app description has been updated successfully"})}catch(e){l({title:"Error",description:"Failed to update app description",variant:"destructive"})}},children:"Save"})]})]})})]})}var Px=t(45833);const Lx=(e,s)=>{let{query:t,enabled:a,initialData:n,throwErrorToBoundary:r,onError:l,logErrorMsg:i,onSuccess:o,onLoading:c}=e;const[d,m]=(0,H.useState)(n),[u,x]=(0,H.useState)(!1),[h,p]=(0,H.useState)(void 0),g=(0,H.useRef)(!1);(0,H.useEffect)(()=>(g.current=!0,()=>{g.current=!1}),[]);const f=(0,H.useCallback)(async()=>{x(!0),null==c||c(!0);try{const e=await t();null==o||o(e),g.current&&m(e)}catch(e){null==l||l(e),g.current&&p(e)}finally{x(!1),null==c||c(!1)}},[t,o,l]);if((0,H.useEffect)(()=>{!1!==a&&f()},s),(0,H.useEffect)(()=>{!1!==a&&!d&&f()},[a]),h&&r)throw h;const v=(0,H.useCallback)(()=>{f()},[f]);return{data:d,isLoading:u,error:h,refetch:v}};const Ox=function(){const{app:e}=_s(),[s,t]=(0,H.useState)(1),[a,n]=(0,H.useState)(null),[r,l]=(0,H.useState)({userEmail:"",showFailuresOnly:!1,logType:"all"}),{data:i,isLoading:o,refetch:c}=Lx({query:async()=>{const{userEmail:t,showFailuresOnly:a,logType:n}=r;let l=(0,K.A)((0,K.A)((0,K.A)({},t&&{user_email:t}),a&&{status:"error"}),"all"!==n&&{log_type:n});return wa.fetchLogs(e.id,{sort:"-created_date",q:l,skip:50*(s-1),limit:50})},initialData:[],enabled:!(null==e||!e.id),logErrorMsg:"Error fetching logs"},[null==e?void 0:e.id,r,s,50]),d=e=>{switch(e){case"error":return(0,re.jsx)(Is,{children:(0,re.jsxs)(Ts,{children:[(0,re.jsx)(Ps,{asChild:!0,children:(0,re.jsx)("div",{children:(0,re.jsx)(Xe.A,{className:"text-destructive",size:16})})}),(0,re.jsx)(Ls,{children:(0,re.jsx)("p",{children:"Error"})})]})});case"success":return(0,re.jsx)(Is,{children:(0,re.jsxs)(Ts,{children:[(0,re.jsx)(Ps,{asChild:!0,children:(0,re.jsx)("div",{children:(0,re.jsx)(Px.A,{className:"text-success",size:16})})}),(0,re.jsx)(Ls,{children:(0,re.jsx)("p",{children:"Success"})})]})});default:return(0,re.jsx)(Is,{children:(0,re.jsxs)(Ts,{children:[(0,re.jsx)(Ps,{asChild:!0,children:(0,re.jsx)("div",{children:(0,re.jsx)(jo.A,{className:"text-primary",size:16})})}),(0,re.jsx)(Ls,{children:(0,re.jsx)("p",{children:"Info"})})]})})}},m=[...new Set(i.map(e=>e.log_type))];return(0,re.jsxs)(su,{title:"Logs Explorer",subtitle:"Monitor system logs across your application.",actions:[(0,re.jsxs)(Yn,{variant:"outline",size:"sm",onClick:()=>{c()},children:[(0,re.jsx)(ku.A,{className:"h-4 w-4 mr-1"}),"Refresh"]}),(0,re.jsx)(Yn,{variant:"outline",size:"sm",disabled:!0,children:"Export Logs"})],filters:[(0,re.jsxs)("div",{className:"flex items-center gap-2",children:[(0,re.jsx)(vn.A,{className:"h-4 w-4 text-muted-foreground"}),(0,re.jsx)(ft,{placeholder:"Filter by email...",className:"h-8 w-44",value:r.userEmail,onChange:e=>l(s=>(0,K.A)((0,K.A)({},s),{},{userEmail:e.target.value}))})]}),(0,re.jsxs)(Ut,{value:r.logType,onValueChange:e=>l(s=>(0,K.A)((0,K.A)({},s),{},{logType:e})),children:[(0,re.jsx)(Wt,{className:"h-8 w-36",children:(0,re.jsx)(qt,{placeholder:"Log type"})}),(0,re.jsxs)(Ht,{children:[(0,re.jsx)($t,{value:"all",children:"All types"}),m.map(e=>(0,re.jsx)($t,{value:e,children:e},e))]})]}),(0,re.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,re.jsx)(ed,{id:"showFailures",checked:r.showFailuresOnly,onCheckedChange:e=>l(s=>(0,K.A)((0,K.A)({},s),{},{showFailuresOnly:!!e}))}),(0,re.jsx)("label",{htmlFor:"showFailures",className:"text-sm cursor-pointer",children:"Errors only"})]}),(0,re.jsxs)(Yn,{className:"w-min",variant:"ghost",size:"sm",onClick:()=>l({userEmail:"",showFailuresOnly:!1,logType:"all"}),children:[(0,re.jsx)(zs.A,{className:"h-3.5 w-3.5 md:mr-1"}),"Clear"]})],children:[o?(0,re.jsx)("div",{className:"flex h-40 items-center justify-center",children:(0,re.jsx)("div",{className:"h-8 w-8 animate-spin rounded-full border-4 border-primary border-t-transparent"})}):(0,re.jsx)("div",{className:"rounded-md border bg-card",children:(0,re.jsxs)(Or,{children:[(0,re.jsx)(Rr,{children:(0,re.jsxs)(Fr,{children:[(0,re.jsx)(Br,{className:"w-12"}),(0,re.jsx)(Br,{children:"Type"}),(0,re.jsx)(Br,{children:"User"}),(0,re.jsx)(Br,{children:"Timestamp"}),(0,re.jsx)(Br,{className:"w-10"})]})}),(0,re.jsx)(Dr,{children:0===i.length?(0,re.jsx)(Fr,{children:(0,re.jsx)(Ur,{colSpan:5,className:"h-32 text-center text-muted-foreground",children:"No logs found"})}):i.map((e,s)=>{return(0,re.jsxs)(H.Fragment,{children:[(0,re.jsxs)(Fr,{className:(null==a?void 0:a.created_date)===e.created_date?"bg-muted/50":"",children:[(0,re.jsx)(Ur,{className:"pr-0",children:d(e.status)}),(0,re.jsx)(Ur,{className:"font-medium",children:e.object_name||e.log_type}),(0,re.jsx)(Ur,{className:"text-sm text-muted-foreground",children:e.user_email}),(0,re.jsx)(Ur,{className:"text-sm text-muted-foreground",children:(t=e.created_date,new Date(t).toLocaleString())}),(0,re.jsx)(Ur,{className:"text-right",children:(0,re.jsx)(Yn,{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,re.jsx)(Tt.A,{size:16}):(0,re.jsx)(It.A,{size:16})})})]}),(null==a?void 0:a.created_date)===e.created_date&&(0,re.jsx)(Fr,{children:(0,re.jsx)(Ur,{colSpan:5,className:"p-0",children:(0,re.jsx)("div",{className:"bg-muted/30 px-6 py-3",children:(0,re.jsxs)("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-2",children:[(0,re.jsxs)("div",{children:[(0,re.jsx)("h4",{className:"mb-2 text-sm font-semibold",children:"Inputs"}),(0,re.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,re.jsxs)("div",{children:[(0,re.jsx)("h4",{className:"mb-2 text-sm font-semibold",children:"Outputs"}),(0,re.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,re.jsxs)("div",{className:e.outputs?"col-span-2":"",children:[(0,re.jsx)("h4",{className:"mb-2 text-sm font-semibold text-destructive",children:"Error"}),(0,re.jsx)("pre",{className:"max-h-60 overflow-auto rounded bg-destructive/10 p-2 text-xs text-destructive-foreground",children:e.error})]})]})})})})]},s);var t})})]})}),(0,re.jsxs)("div",{className:"flex items-center justify-between",children:[(0,re.jsx)(Yn,{variant:"outline",size:"sm",disabled:1===s,onClick:()=>t(e=>Math.max(1,e-1)),children:"Previous"}),(0,re.jsxs)("span",{className:"text-sm text-muted-foreground",children:["Page ",s]}),(0,re.jsx)(Yn,{variant:"outline",size:"sm",disabled:i.length<50,onClick:()=>t(e=>e+1),children:"Next"})]})]})};var Rx=t(45403),Dx=t(81850);const Mx=om.bL,Fx=om.l9,Bx=H.forwardRef((e,s)=>(0,re.jsx)(um,(0,K.A)({ref:s},e)));Bx.displayName=om.UC.displayName;const Ux=["className","classNames","showOutsideDays"];function zx(e){let{className:s,classNames:t,showOutsideDays:a=!0}=e,n=(0,as.A)(e,Ux);return(0,re.jsx)(rm,(0,K.A)({className:s,classNames:t,showOutsideDays:a},n))}zx.displayName="Calendar";const qx=e=>{let{data:s,title:t="Bar Chart",barColor:a="#2A9D90;",maxWidth:n="800px",maxLabelWidth:r="150px",backgroundColor:l="white",textColor:i="#1f2937",className:o,renderLabel:c=e=>e.name,renderValue:d=e=>e.value}=e;const[m,u]=(0,H.useState)(!1),x=Math.max(...s.map(e=>e.value)),h=s.length;(0,H.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,re.jsxs)("div",{className:o,style:{width:"100%",maxWidth:n,backgroundColor:l,overflow:"hidden"},children:[t&&(0,re.jsx)("h2",{style:{fontSize:"24px",fontWeight:"bold",marginBottom:"24px",color:i,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t}),(0,re.jsxs)("div",{className:"text-[".concat(g,"] text-[").concat(i,"]"),style:{display:"grid",gridTemplateColumns:"max-content 1fr",gap:"10px",gridTemplateRows:"repeat(".concat(s.length,", ").concat(p,")")},children:[(0,re.jsx)("div",{className:"align-left max-w-[".concat(r,"]"),children:s.map((e,s)=>{let{name:t}=e;return(0,re.jsx)("div",{className:"align-middle h-[".concat(p,"] flex items-center"),children:t},s)})}),(0,re.jsx)("div",{children:s.map((e,s)=>{let{value:t}=e;return(0,re.jsxs)("div",{className:"p-1 flex row gap-1 align-middle h-[".concat(p,"]"),children:[(0,re.jsx)("div",{className:"bg-[".concat(a,"] w-[").concat((m?t:0)/x*100,"%] rounded-lg"),style:{transition:"width 0.5s ease-in-out"}},s),(0,re.jsx)("div",{className:"align-middle flex items-center ",children:t},s)]})})})]})]})};var Wx=t(81095),Vx=t(68354),Yx=t(93245),Hx=t(60158),Gx=t(44813),$x=t(40992),Jx=t(10734);function Zx(){const{state:e,updateState:s}=(()=>{var e,s;const{app:t}=_s(),a=t.id,[n,r]=(0,H.useState)({appId:a,pageNames:Object.keys(t.pages),date:{from:void 0,to:void 0},selectedPage:"all",selectedUser:null,showAllUsers:!1}),l=e=>{r(s=>(0,K.A)((0,K.A)({},s),e))},{isLoading:i,data:o}=Lx({query:()=>{var e,s;return wa.getStats(a,{date_from:null!==(e=n.date)&&void 0!==e&&e.from?(0,lm.GP)(n.date.from,"yyyy-MM-dd"):void 0,date_to:null!==(s=n.date)&&void 0!==s&&s.to?(0,lm.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){l({isLoading:e})},onSuccess(e){l({stats:e})}},[a,null===(e=n.date)||void 0===e?void 0:e.from,null===(s=n.date)||void 0===s?void 0:s.to,n.selectedPage,n.selectedUser]);return{state:(0,K.A)((0,K.A)({},n),{},{isLoading:i,stats:o}),updateState:l}})(),{appId:t,selectedPage:a,showAllUsers:n,stats:r}=e;return r?(0,re.jsxs)(su,{title:"Analytics",subtitle:"Manage your app\u2019s data",filters:(0,re.jsx)(Kx,{updateState:s,state:e}),children:[(0,re.jsx)(Xx,{stats:r}),(0,re.jsx)(Qx,{updateState:s,stats:r,showAllUsers:n}),(0,re.jsx)(eh,{stats:r,selectedPage:a,appId:t}),(0,re.jsx)(sh,{stats:r}),(0,re.jsx)(th,{stats:r})]}):(0,re.jsx)("div",{className:"h-full w-full flex items-center justify-center",children:(0,re.jsx)(Ze.A,{className:"h-8 w-8 animate-spin text-muted-foreground"})})}const Kx=e=>{let{state:s,updateState:t}=e;const{date:a,selectedPage:n,pageNames:r,selectedUser:l,isLoading:i}=s;return(0,re.jsxs)("div",{className:"flex flex-col sm:flex-row gap-3",children:[(0,re.jsxs)(Mx,{children:[(0,re.jsx)(Fx,{asChild:!0,children:(0,re.jsxs)(Yn,{variant:"outline",className:is("w-full sm:w-[240px] justify-start text-left font-normal",!a&&"text-muted-foreground"),children:[(0,re.jsx)(im.A,{className:"mr-2 h-4 w-4"}),null!=a&&a.from?a.to?(0,re.jsxs)(re.Fragment,{children:[(0,lm.GP)(a.from,"LLL dd, y")," - ",(0,lm.GP)(a.to,"LLL dd, y")]}):(0,lm.GP)(a.from,"LLL dd, y"):(0,re.jsx)("span",{children:"Pick a date range"})]})}),(0,re.jsx)(Bx,{className:"w-auto p-0",align:"start",children:(0,re.jsx)(zx,{initialFocus:!0,mode:"range",defaultMonth:null==a?void 0:a.from,selected:a,onSelect:e=>t({date:{to:null==e?void 0:e.to,from:null==e?void 0:e.from}}),numberOfMonths:1})})]}),(0,re.jsxs)(In,{value:n,onValueChange:e=>t({selectedPage:e}),children:[(0,re.jsx)(Pn,{className:"w-full sm:w-[240px]",children:(0,re.jsx)(Tn,{placeholder:"Filter by page"})}),(0,re.jsxs)(Rn,{children:[(0,re.jsx)(Dn,{value:"all",children:"All Pages"}),null==r?void 0:r.map(e=>(0,re.jsx)(Dn,{value:e,children:e},e))]})]}),l&&(0,re.jsxs)("div",{className:"flex items-center gap-2 bg-muted px-3 py-2 rounded-md",children:[(0,re.jsxs)("span",{className:"text-sm",children:["Filtered by user: ",l]}),(0,re.jsx)("button",{onClick:()=>t({selectedUser:null}),className:"text-muted-foreground hover:text-foreground",children:(0,re.jsx)(Dx.A,{className:"h-4 w-4"})})]}),i&&(0,re.jsxs)("div",{className:"flex items-center gap-2",children:[(0,re.jsx)(Ze.A,{className:"h-4 w-4 animate-spin text-muted-foreground"}),(0,re.jsx)("span",{className:"text-sm text-muted-foreground",children:"Updating..."})]})]})},Xx=e=>{let{stats:s}=e;return(0,re.jsx)(Xn,{children:(0,re.jsxs)(Qn,{className:"py-6",children:[(0,re.jsx)(er,{className:"text-lg",children:(null==s?void 0:s.unique_users_count)||0}),(0,re.jsx)(sr,{children:"Total Unique Users"})]})})},Qx=e=>{var s,t;let{stats:a,updateState:n,showAllUsers:r}=e;const l=null!=a&&a.top_users?r?a.top_users:null===(s=a.top_users)||void 0===s?void 0:s.slice(0,5):[],i=(null==a||null===(t=a.top_users)||void 0===t?void 0:t.length)>5;return 0===l.length?null:(0,re.jsxs)(Xn,{children:[(0,re.jsx)(Qn,{children:(0,re.jsx)(er,{children:"Top Users"})}),(0,re.jsx)(tr,{children:(0,re.jsxs)("div",{className:"space-y-2",children:[null==l?void 0:l.map((e,s)=>(0,re.jsxs)("div",{className:"flex justify-between items-center text-sm cursor-pointer hover:bg-muted rounded-md",onClick:()=>n({selectedUser:e.email}),children:[(0,re.jsx)("span",{className:"truncate max-w-[180px]",children:e.email}),(0,re.jsxs)("span",{className:"font-semibold",children:[e.visits," visits"]})]},s)),i&&(0,re.jsx)(Yn,{variant:"ghost",className:"w-full mt-2 text-sm text-muted-foreground hover:text-foreground",onClick:()=>n({showAllUsers:!r}),children:r?(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(Tt.A,{className:"h-4 w-4 mr-2"})," Show Less"]}):(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(It.A,{className:"h-4 w-4 mr-2"})," Show More Users"]})})]})})]})},eh=e=>{var s,t;let{stats:a,selectedPage:n,appId:r}=e;const l=(null!==(s="all"===n?null==a?void 0:a.top_pages:null===(t=a.top_pages)||void 0===t?void 0:t.filter(e=>e.url===n))&&void 0!==s?s:[]).map(e=>({name:e.page_name,value:e.visits}));return(0,re.jsxs)(Xn,{children:[(0,re.jsxs)(Qn,{children:[(0,re.jsx)(er,{children:"Top Pages"}),(0,re.jsx)(sr,{children:"Shows the most visited pages in your app and their total visit count"})]}),(0,re.jsx)(tr,{children:(0,re.jsx)(qx,{data:l,title:"",maxWidth:"80%",backgroundColor:"transparent",renderLabel:e=>"all"===r?(0,re.jsx)(J.Link,{to:"/apps/".concat(e.name),target:"_blank",className:"hover:underline",children:e.name}):e.name})})]})},sh=e=>{var s;let{stats:t}=e;return(0,re.jsxs)(Xn,{children:[(0,re.jsxs)(Qn,{children:[(0,re.jsx)(er,{children:"Unique Users Over Time"}),(0,re.jsx)(sr,{children:"Tracks the number of distinct users accessing your app each day"})]}),(0,re.jsx)(tr,{children:(null==t||null===(s=t.users_per_date)||void 0===s?void 0:s.length)<=1?(0,re.jsx)("div",{className:"h-[200px] flex items-center justify-center text-muted-foreground",children:"Not enough data to show trends"}):(0,re.jsx)("div",{className:"h-[300px]",children:(0,re.jsx)(Wx.u,{width:"100%",height:"100%",children:(0,re.jsxs)(Vx.Q,{data:t.users_per_date,margin:{top:10,right:10,left:0,bottom:0},children:[(0,re.jsx)(Yx.d,{strokeDasharray:"3 3"}),(0,re.jsx)(Hx.W,{dataKey:"date"}),(0,re.jsx)(Gx.h,{}),(0,re.jsx)($x.m,{}),(0,re.jsx)(Jx.G,{type:"monotone",dataKey:"unique_users",stroke:"#8884d8",fill:"#8884d8",name:"Unique Users"})]})})})})]})},th=e=>{var s;let{stats:t}=e;return(0,re.jsxs)(Xn,{children:[(0,re.jsxs)(Qn,{children:[(0,re.jsx)(er,{children:"Total Usage Over Time"}),(0,re.jsx)(sr,{children:"Shows the total number of visits to your app, including repeat visits from the same users"})]}),(0,re.jsx)(tr,{children:(null==t||null===(s=t.users_per_date)||void 0===s?void 0:s.length)<=1?(0,re.jsx)("div",{className:"h-[200px] flex items-center justify-center text-muted-foreground",children:"Not enough data to show trends"}):(0,re.jsx)("div",{className:"h-[300px]",children:(0,re.jsx)(Wx.u,{width:"100%",height:"100%",children:(0,re.jsxs)(Vx.Q,{data:t.users_per_date,margin:{top:10,right:10,left:0,bottom:0},children:[(0,re.jsx)(Yx.d,{strokeDasharray:"3 3"}),(0,re.jsx)(Hx.W,{dataKey:"date"}),(0,re.jsx)(Gx.h,{}),(0,re.jsx)($x.m,{}),(0,re.jsx)(Jx.G,{type:"monotone",dataKey:"total_visits",stroke:"#82ca9d",fill:"#82ca9d",name:"Total Visits"})]})})})})]})};var ah=t(71742);function nh(e){let{isSaving:s,hasEditorErrors:t,onDiscard:a,onSave:n,onSaveAndRedeploy:r,hasUnsavedChanges:l,isFunction:i,deploymentError:o,onClearError:c}=e;if(!l&&!o)return null;const d=(e=>{if(!e)return null;const s=e.match(/Deployment (.*?) failed with error (.*)/);return s?{deployment:"".concat(s[1]," failed"),error:s[2].replace(/\\n\\n+/g,": ").replace(/\\n+/g," ").trim()}:void 0})(o);return d?(0,re.jsx)("div",{className:"fixed bottom-2 right-6 w-full max-w-2xl z-[100]",children:(0,re.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,re.jsxs)("div",{className:"flex items-start p-3 gap-3 bg-red-50/80",children:[(0,re.jsx)("div",{className:"flex-1 min-w-0",children:(0,re.jsx)("div",{className:"font-medium text-base text-red-800",children:d.deployment})}),(0,re.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,re.jsx)(zs.A,{className:"w-4 h-4"})})]}),d.error&&(0,re.jsx)("div",{className:"p-3 bg-white/50 border-t border-red-100",children:(0,re.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,re.jsxs)("div",{className:"fixed bottom-6 right-6 flex flex-col gap-2 w-56 z-[200]",children:[t&&(0,re.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,re.jsx)(Xe.A,{className:"w-4 h-4 text-red-500"}),(0,re.jsx)("span",{children:"Editor has errors"})]}),(0,re.jsxs)(Hs,{variant:"outline",size:"lg",className:"rounded-full shadow-lg w-full",onClick:a,disabled:s,children:[(0,re.jsx)(wi.A,{className:"w-4 h-4 mr-2"}),"Discard"]}),i?(0,re.jsxs)(Hs,{size:"lg",className:"relative rounded-full shadow-lg bg-gray-900 text-white hover:bg-gray-800 w-full justify-center",onClick:r,disabled:s,children:[s?(0,re.jsx)(ku.A,{className:"w-4 h-4 mr-2 animate-spin"}):(0,re.jsx)(ku.A,{className:"w-4 h-4 mr-2"}),"Save & Redeploy"]}):(0,re.jsxs)(Hs,{size:"lg",className:"rounded-full shadow-lg bg-gray-900 text-white hover:bg-gray-800 w-full",onClick:n,disabled:s,children:[s?(0,re.jsx)(ah.A,{className:"w-4 h-4 mr-2 animate-spin"}):(0,re.jsx)(ah.A,{className:"w-4 h-4 mr-2"}),"Save"]})]})}function rh(e){let{filepath:s,selectedLine:t,onEdit:a,onSaveOrDiscard:n,isFunction:r,onRedeployFunction:l}=e;const{user:i}=oe(),{app:o,writeCodeToFile:c}=_s(),[d,m]=(0,H.useState)(!1),[u,x]=(0,H.useState)(""),[h,p]=(0,H.useState)(!1),[g,f]=(0,H.useState)(!1),[v,b]=(0,H.useState)(null),j=(0,H.useRef)(null),y=(0,H.useRef)(null),N="free"===(null==i?void 0:i.subscription_tier),w=(0,H.useRef)(null),_=(0,H.useRef)(""),k=(0,H.useRef)(s),[A,S]=(0,H.useState)(!0),C=()=>{if(j.current&&y.current){const e=j.current.getModel(),s=y.current;if(e&&s){const t=s.editor.getModelMarkers({resource:e.uri}).some(e=>e.severity===s.MarkerSeverity.Error);S(t)}}};(0,H.useEffect)(()=>{if(!s||!o)return;f(!1);let e="";if("layout"===s)e=o.layout;else if(s.startsWith("pages/")){const t=s.split("pages/")[1];e=o.pages[t]}else if(s.startsWith("components/")){const t=s.split("components/")[1];e=o.components[t]}else if(s.startsWith("functions/")){const t=s.split("functions/")[1];e=o.functions[t]}else if(s.startsWith("entities/")){const t=s.split("entities/")[1];e=JSON.stringify(o.entities[t],null,2)}if(x(e),_.current=e,k.current=s,f(!0),j.current&&(w.current=j.current.saveViewState()),j.current){const e=j.current.getModel();if(e){const s=e.onDidChangeDecorations(()=>{C(),s&&s.dispose&&s.dispose()})}}},[s,o]),(0,H.useEffect)(()=>{j.current&&w.current&&(j.current.restoreViewState(w.current),j.current.focus(),w.current=null)},[u,h]),(0,H.useEffect)(()=>{t&&h&&g&&u&&(()=>{if(!(j.current&&t&&h&&g))return;const e=j.current,s=e.getModel();if(!s)return;const a=parseInt(t,10);if(isNaN(a)||a<=0)return;const n=s.getLineCount(),r=Math.min(a,n);requestAnimationFrame(()=>{try{e.revealLineInCenter(r),e.setPosition({lineNumber:r,column:1}),e.setSelection({startLineNumber:r,startColumn:1,endLineNumber:r,endColumn:s.getLineMaxColumn(r)}),e.focus()}catch(t){}})})()},[t,h,g,u]),(0,H.useEffect)(()=>{if(!j.current||!y.current)return;const e=j.current.getModel(),s=y.current;if(!e||!s)return;const t=s.editor.onDidChangeMarkers(s=>{s.some(s=>s.toString()===e.uri.toString())&&C()});return C(),()=>{t&&t.dispose&&t.dispose()}},[h,u]),(0,H.useEffect)(()=>{b(null)},[s]);const E=u!==_.current;return(0,re.jsxs)("div",{className:"h-full relative",children:[(0,re.jsx)(nh,{isSaving:d,hasEditorErrors:A,onDiscard:()=>{x(_.current),j.current&&w.current&&(j.current.restoreViewState(w.current),j.current.focus()),n&&n()},onSave:async()=>{m(!0),await(async e=>{N||(m(!0),await c(s,e),m(!1))})(u),m(!1),n&&n()},onSaveAndRedeploy:async()=>{if(m(!0),b(null),n&&n(),l)try{await l(u)}catch(e){b(e.message||"Failed to redeploy function")}m(!1)},hasUnsavedChanges:E,isFunction:r,deploymentError:v,onClearError:()=>{b(null)}}),(0,re.jsx)(cl.KE,{defaultLanguage:"javascript",value:u,onChange:e=>{N||(x(e),j.current&&(w.current=j.current.saveViewState()),a&&a())},onMount:(e,s)=>{j.current=e,y.current=s,p(!0);const t=e.getModel();t&&t.onDidChangeContent(()=>{f(!0)})},options:{minimap:{enabled:!1},scrollBeyondLastLine:!1,fontSize:14,readOnly:N||d,padding:{top:N?40:0}},height:"100%"}),N&&(0,re.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,re.jsx)(J.Link,{to:"/billing",className:"ml-2 text-blue-600 hover:underline",children:"Upgrade your plan"})]}),d&&(0,re.jsx)("div",{className:"absolute top-10 right-2 bg-gray-700 text-white text-xs px-2 py-1 rounded opacity-70"})]})}function lh(e,s){let t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};const a=bs(),n=(0,K.A)((0,K.A)({},t),{},{"Base44-Functions-Version":a}),r=(0,ae.Ay)("https://base44.app/api"+"/apps/".concat(e.id,"/functions"),n,!0,!1,!1);s=s||(e=>{}),r.interceptors.response.use(e=>e,e=>{const t="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 r;null!==(r=e.response)&&void 0!==r&&r.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 l="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 s(t,l),Promise.reject(e)});let l={};return(e.function_names||Object.keys(e.functions||{})).forEach(e=>{l[e]=async s=>await r.post("/".concat(e),s||{})}),l}var ih=t(25692),oh=t(7838),ch=t(30621),dh=t(5487);const mh=(0,H.forwardRef)((e,s)=>{let{functionName:t,hasUnsavedChanges:a}=e;const{user:n}=oe(),{app:r,runtimeAuthToken:l}=_s(),[i,o]=(0,H.useState)(null),[c,d]=(0,H.useState)(!1),[m,u]=(0,H.useState)(!1),[x,h]=(0,H.useState)(!1),[p,g]=(0,H.useState)("{\n \n}"),[f,v]=(0,H.useState)(null),[b,j]=(0,H.useState)(!1),[y,N]=(0,H.useState)(null),[w,_]=(0,H.useState)(null),[k,A]=(0,H.useState)(!1),[S,C]=(0,H.useState)(!1),[E,I]=(0,H.useState)(!1),[T,P]=(0,H.useState)([]),[L,O]=(0,H.useState)(!1),[R,D]=(0,H.useState)(null),[M,F]=(0,H.useState)(0),[B]=(0,H.useState)(50),[U,z]=(0,H.useState)(!0);(0,H.useEffect)(()=>{o(lh(r,()=>{},{Authorization:"Bearer ".concat(l)}))},[null==r?void 0:r.id,null==r?void 0:r.functions]);const q=async e=>{if(null!=r&&r.id&&t)try{await ve.redeployFunction(r.id,t,e)}catch(n){var s,a;const e=(null===(s=n.response)||void 0===s||null===(a=s.data)||void 0===a?void 0:a.message)||n.message||"An error occurred while redeploying the function";throw new Error(e)}};(0,H.useImperativeHandle)(s,()=>({handleRedeployFunction:q}));const W=async(e,s)=>{try{await navigator.clipboard.writeText(e),"url"===s?(A(!0),setTimeout(()=>A(!1),2e3)):"headers"===s?(C(!0),setTimeout(()=>C(!1),2e3)):"curl"===s&&(I(!0),setTimeout(()=>I(!1),2e3))}catch(t){}},V=()=>null!=r&&r.slug&&null!=r&&r.id&&t?"".concat(fa(r),"/api/apps/").concat(r.id,"/functions/").concat(t):"",Y=()=>{const e={"Content-Type":"application/json"};return null!=n&&n.api_key&&(e.api_key=n.api_key),e},G=async function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,s=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(null!=r&&r.id&&t){O(!0),D(null);try{const a=await nx.getBackendFunctionsLogs(r.id,t,{limit:B,offset:e});P(s||0===e?a:e=>[...e,...a]),z(a.length===B),F(e)}catch(l){var a,n;D((null===(a=l.response)||void 0===a||null===(n=a.data)||void 0===n?void 0:n.message)||l.message||"Failed to fetch logs")}finally{O(!1)}}},$=e=>{try{return new Date(e).toLocaleString()}catch(s){return e}},J=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,re.jsxs)(re.Fragment,{children:[(0,re.jsx)("div",{className:"fixed bottom-6 right-6",children:!a&&(0,re.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,re.jsxs)(Hs,{variant:"ghost",size:"sm",className:"rounded-xl text-slate-600 hover:text-slate-800 hover:bg-slate-100 transition-all duration-200",onClick:()=>d(!0),children:[(0,re.jsx)(ih.A,{className:"h-4 w-4 mr-2"}),"Test Function"]}),(0,re.jsx)("div",{className:"w-px h-6 bg-slate-300 mx-1"}),(0,re.jsxs)(Hs,{variant:"ghost",size:"sm",className:"rounded-xl text-slate-600 hover:text-slate-800 hover:bg-slate-100 transition-all duration-200",onClick:()=>{h(!0),0===T.length&&G(0,!0)},children:[(0,re.jsx)(oh.A,{className:"h-4 w-4 mr-2"}),"Logs"]}),(0,re.jsx)("div",{className:"w-px h-6 bg-slate-300 mx-1"}),(0,re.jsxs)(Hs,{variant:"ghost",size:"sm",className:"rounded-xl text-slate-600 hover:text-slate-800 hover:bg-slate-100 transition-all duration-200",onClick:()=>u(!0),children:[(0,re.jsx)(Yr.A,{className:"h-4 w-4 mr-2"}),"API"]})]})}),y&&(0,re.jsx)("div",{className:"fixed bottom-24 right-6 max-w-md",children:(0,re.jsxs)(us,{variant:"destructive",className:"bg-white/95 backdrop-blur-sm border-red-200",children:[(0,re.jsx)(dh.A,{className:"h-4 w-4"}),(0,re.jsx)(xs,{children:"Deployment Error"}),(0,re.jsx)(hs,{className:"font-mono text-sm whitespace-pre-wrap break-all",children:y})]})}),(0,re.jsx)(Vm,{open:x&&!a,onOpenChange:h,children:(0,re.jsxs)(Zm,{className:"sm:max-w-3xl md:max-w-5xl w-[96vw]",children:[(0,re.jsx)(Km,{className:"pb-3",children:(0,re.jsxs)("div",{className:"flex items-center justify-between",children:[(0,re.jsxs)("div",{className:"flex items-center gap-3",children:[(0,re.jsxs)("div",{className:"flex items-center gap-2",children:[(0,re.jsx)(oh.A,{className:"h-5 w-5 text-teal-600"}),(0,re.jsx)(Qm,{className:"text-slate-800 text-lg",children:"Logs"})]}),(0,re.jsx)("div",{className:"text-sm text-slate-500 font-mono bg-slate-100 px-2 py-1 rounded",children:t})]}),(0,re.jsxs)(Hs,{variant:"outline",size:"sm",onClick:()=>{G(0,!0)},disabled:L,className:"text-teal-600 hover:text-teal-700 hover:bg-teal-50 border-teal-200",children:[(0,re.jsx)(ku.A,{className:"h-4 w-4 mr-1 ".concat(L?"animate-spin":"")}),"Refresh"]})]})}),(0,re.jsxs)("div",{className:"space-y-3",children:[R&&(0,re.jsxs)(us,{variant:"destructive",className:"mb-4",children:[(0,re.jsx)(dh.A,{className:"h-4 w-4"}),(0,re.jsx)(xs,{children:"Error"}),(0,re.jsx)(hs,{children:R})]}),0===T.length&&!L&&!R&&(0,re.jsxs)("div",{className:"text-center py-8 text-slate-500",children:[(0,re.jsx)(al.A,{className:"h-8 w-8 mx-auto mb-3 text-slate-400"}),(0,re.jsx)("p",{className:"font-medium mb-1",children:"No logs found"}),(0,re.jsx)("p",{className:"text-xs text-slate-400",children:"This function hasn't generated any logs yet."})]}),T.length>0&&(0,re.jsx)("div",{className:"max-h-[70vh] overflow-y-auto border border-slate-200 rounded-lg",children:(0,re.jsx)("div",{className:"divide-y divide-slate-100",children:T.map((e,s)=>{return(0,re.jsxs)("div",{className:"px-3 py-2 hover:bg-slate-50/50 transition-colors ".concat(J(e.level).includes("red")?"bg-red-50/30":J(e.level).includes("amber")?"bg-amber-50/30":J(e.level).includes("blue")?"bg-blue-50/30":J(e.level).includes("purple")?"bg-purple-50/30":""),children:[(0,re.jsx)("div",{className:"flex items-start gap-3 mb-1",children:(0,re.jsxs)("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.level&&(0,re.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,re.jsx)("span",{className:"text-xs text-slate-400 font-mono min-w-0",children:$(e.time).split(", ")[1]}),e.region&&(0,re.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,re.jsx)("div",{className:"font-mono text-xs leading-relaxed text-slate-700 whitespace-pre-wrap break-words pl-1",children:"string"==typeof e.message?(t=e.message.trim(),"string"!=typeof t?t:t.replace(/\u001b\[[0-9;]*m/g,"")):JSON.stringify(e.message,null,2)})]},"".concat(e.time,"-").concat(s));var t})})}),U&&T.length>0&&(0,re.jsx)("div",{className:"flex justify-center pt-2",children:(0,re.jsx)(Hs,{variant:"outline",size:"sm",onClick:()=>{!L&&U&&G(M+B)},disabled:L,className:"text-slate-600 hover:text-slate-800 text-xs",children:L?(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(Ze.A,{className:"mr-1 h-3 w-3 animate-spin"}),"Loading..."]}):(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(ln.A,{className:"mr-1 h-3 w-3"}),"Load More"]})})}),L&&0===T.length&&(0,re.jsx)("div",{className:"flex justify-center py-8",children:(0,re.jsxs)("div",{className:"flex items-center text-slate-500 text-sm",children:[(0,re.jsx)(Ze.A,{className:"mr-2 h-4 w-4 animate-spin"}),"Loading logs..."]})})]})]})}),(0,re.jsx)(Vm,{open:m&&!a,onOpenChange:u,children:(0,re.jsxs)(Zm,{className:"sm:max-w-md md:max-w-lg w-[90vw] flex flex-col",children:[(0,re.jsxs)(Km,{className:"pb-4 flex-shrink-0",children:[(0,re.jsxs)("div",{className:"flex items-center gap-2",children:[(0,re.jsx)(Yr.A,{className:"h-5 w-5 text-teal-600"}),(0,re.jsx)(Qm,{className:"text-slate-800 text-lg",children:"API Information"})]}),(0,re.jsx)("div",{className:"text-sm text-slate-500 font-mono bg-slate-100 px-2 py-1 rounded w-fit",children:t})]}),(0,re.jsxs)("div",{className:"flex-1 overflow-y-auto mt-6 space-y-6 pr-2",children:[(0,re.jsxs)("div",{className:"space-y-3",children:[(0,re.jsxs)("div",{className:"flex items-center justify-between",children:[(0,re.jsx)("h3",{className:"text-sm font-semibold text-slate-700 uppercase tracking-wider",children:"Function URL"}),(0,re.jsx)(Hs,{variant:"ghost",size:"sm",onClick:()=>W(V(),"url"),className:"text-teal-600 hover:text-teal-700 hover:bg-teal-50",children:k?(0,re.jsx)(Pt.A,{className:"h-4 w-4"}):(0,re.jsx)(Kr.A,{className:"h-4 w-4"})})]}),(0,re.jsx)("div",{className:"bg-slate-50 border border-slate-200 rounded-lg p-4",children:(0,re.jsx)("code",{className:"text-sm font-mono text-slate-800 break-all",children:V()})}),(0,re.jsx)("p",{className:"text-xs text-slate-500",children:"Make POST requests to this endpoint with your function payload."})]}),(0,re.jsxs)("div",{className:"space-y-3",children:[(0,re.jsxs)("div",{className:"flex items-center justify-between",children:[(0,re.jsx)("h3",{className:"text-sm font-semibold text-slate-700 uppercase tracking-wider",children:"Headers"}),(0,re.jsx)(Hs,{variant:"ghost",size:"sm",onClick:()=>W(JSON.stringify(Y(),null,2),"headers"),className:"text-teal-600 hover:text-teal-700 hover:bg-teal-50",children:S?(0,re.jsx)(Pt.A,{className:"h-4 w-4"}):(0,re.jsx)(Kr.A,{className:"h-4 w-4"})})]}),(0,re.jsx)("div",{className:"bg-slate-50 border border-slate-200 rounded-lg p-4",children:(0,re.jsx)("pre",{className:"text-sm font-mono text-slate-800 whitespace-pre-wrap",children:JSON.stringify(Y(),null,2)})}),(0,re.jsxs)("div",{className:"text-xs text-slate-500 space-y-1",children:[(0,re.jsxs)("p",{children:[(0,re.jsx)("strong",{children:"Content-Type:"})," Always required for JSON payloads."]}),null!=n&&n.api_key?(0,re.jsxs)("p",{children:[(0,re.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,re.jsxs)("p",{className:"text-amber-600",children:[(0,re.jsx)("strong",{children:"api_key:"})," Not found. Include your personal API key here only if your function requires authentication."]})]})]}),(0,re.jsxs)("div",{className:"space-y-3",children:[(0,re.jsx)("h3",{className:"text-sm font-semibold text-slate-700 uppercase tracking-wider",children:"Request Body"}),(0,re.jsx)("div",{className:"bg-slate-50 border border-slate-200 rounded-lg p-4",children:(0,re.jsx)("pre",{className:"text-sm font-mono text-slate-800 whitespace-pre-wrap",children:'{\n "param1": "value1",\n "param2": "value2"\n}'})}),(0,re.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,re.jsxs)("div",{className:"space-y-3",children:[(0,re.jsxs)("div",{className:"flex items-center justify-between",children:[(0,re.jsx)("h3",{className:"text-sm font-semibold text-slate-700 uppercase tracking-wider",children:"Usage Example (cURL)"}),(0,re.jsx)(Hs,{variant:"ghost",size:"sm",onClick:()=>W('curl -X POST "'.concat(V(),'" \\\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:E?(0,re.jsx)(Pt.A,{className:"h-4 w-4"}):(0,re.jsx)(Kr.A,{className:"h-4 w-4"})})]}),(0,re.jsx)("div",{className:"bg-slate-900 rounded-lg p-4",children:(0,re.jsx)("pre",{className:"text-sm font-mono text-green-400 whitespace-pre-wrap break-all",children:'curl -X POST "'.concat(V(),'" \\\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,re.jsx)(Vm,{open:c&&!a,onOpenChange:d,children:(0,re.jsxs)(Zm,{className:"sm:max-w-md md:max-w-lg w-[90vw]",children:[(0,re.jsxs)(Km,{className:"pb-4",children:[(0,re.jsxs)("div",{className:"flex items-center gap-2",children:[(0,re.jsx)(ih.A,{className:"h-5 w-5 text-orange-600"}),(0,re.jsx)(Qm,{className:"text-slate-800 text-lg",children:"Test Function"})]}),(0,re.jsx)("div",{className:"text-sm text-slate-500 font-mono bg-slate-100 px-2 py-1 rounded w-fit",children:t})]}),(0,re.jsxs)("div",{className:"mt-6 space-y-4",children:[(0,re.jsxs)("div",{children:[(0,re.jsx)("h3",{className:"text-sm font-medium mb-2",children:"Payload"}),(0,re.jsx)(td,{value:p,onChange:e=>g(e.target.value),className:"font-mono h-40",placeholder:"Enter JSON payload"})]}),(0,re.jsx)(Hs,{onClick:async()=>{if(i&&t){j(!0),N(null),v(null);try{const e=JSON.parse(p),s=await i[t](e);v(s)}catch(l){var e,s,a,n,r;N((null===(e=l.response)||void 0===e||null===(s=e.data)||void 0===s?void 0:s.error)||(null===(a=l.response)||void 0===a||null===(n=a.data)||void 0===n?void 0:n.message)||l.message||"An error occurred while executing the function"),_((null===(r=l.response)||void 0===r?void 0:r.data)||"")}finally{j(!1)}}},disabled:b,className:"w-full",children:b?(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(Ze.A,{className:"mr-2 h-4 w-4 animate-spin"}),"Running..."]}):(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(ch.A,{className:"mr-2 h-4 w-4"}),"Run Function"]})}),y&&(0,re.jsxs)(us,{variant:"destructive",children:[(0,re.jsx)(dh.A,{className:"h-4 w-4"}),(0,re.jsx)(xs,{children:"Error"}),(0,re.jsxs)(hs,{className:"font-mono text-sm whitespace-pre-wrap break-all",children:[y,w&&(0,re.jsxs)("div",{className:"mt-2 pt-2 border-t border-red-300 dark:border-red-700",children:[(0,re.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,re.jsx)("div",{className:"bg-red-50 dark:bg-red-900/30 p-2 rounded-md overflow-auto max-h-40",children:(0,re.jsx)("pre",{className:"text-xs font-mono whitespace-pre-wrap break-all",children:"string"==typeof w?w:JSON.stringify(w,null,2)})})]})]})]}),f&&(0,re.jsxs)("div",{className:"mt-4",children:[(0,re.jsx)("h3",{className:"text-sm font-medium mb-2",children:"Result"}),(0,re.jsxs)(hl,{defaultValue:"formatted",children:[(0,re.jsxs)(pl,{className:"mb-2",children:[(0,re.jsx)(gl,{value:"formatted",children:"Formatted"}),(0,re.jsx)(gl,{value:"raw",children:"Raw"})]}),(0,re.jsx)(fl,{value:"formatted",children:(0,re.jsx)("div",{className:"bg-gray-50 p-4 rounded-md overflow-auto max-h-60",children:(0,re.jsx)("pre",{className:"text-sm font-mono whitespace-pre-wrap",children:(e=>{try{return JSON.stringify(e,null,2)}catch(s){return String(e)}})(f)})})}),(0,re.jsx)(fl,{value:"raw",children:(0,re.jsx)("div",{className:"bg-gray-50 p-4 rounded-md overflow-auto max-h-60",children:(0,re.jsx)("pre",{className:"text-sm font-mono whitespace-pre-wrap",children:JSON.stringify(f)})})})]})]})]})]})})]})}),uh=mh;var xh=t(57543),hh=t(15939);const ph=e=>{let{selectedFile:s,onFileSelect:t,onBack:a,app:n,width:r,hasUnsavedChanges:l=!1}=e;const[i,o]=(0,H.useState)(""),[c,d]=(0,H.useState)([]),[m,u]=(0,H.useState)(!1),[x,h]=(0,H.useState)({}),p=e=>{const s={};return Object.keys(e||{}).forEach(e=>{const t=e.split("/");let a=s;for(let s=0;sObject.entries(e).map(e=>{let[a,n]=e;const r=s?"".concat(s,"/").concat(a):"".concat(t,":").concat(a);if(n.isFile){return{id:r,label:a,icon:"entities"===t?(0,re.jsx)(Zo.A,{className:"w-4 h-4"}):(0,re.jsx)(xh.A,{className:"w-4 h-4"})}}{const e=g(n.children,r,t);return{id:r,label:a,icon:(0,re.jsx)(hh.A,{className:"w-4 h-4"}),subitems:e}}});(0,H.useEffect)(()=>{if(i.length<2||!m)return void d([]);const e=[],s=(s,t)=>{t&&Object.entries(t).forEach(t=>{let[a,n]=t;const r=n.toString().split("\n").map((e,s)=>({line:e,idx:s+1})).filter(e=>{let{line:s}=e;return s.toLowerCase().includes(i.toLowerCase())});r.length>0&&e.push({type:s,key:a,matches:r.map(e=>{let{line:s,idx:t}=e;return{lineNumber:t,content:s,preview:s.trim()}})})})};if(s("pages",n.pages),s("components",n.components),s("entities",n.entities),s("functions",n.functions),n.layout){const s=n.layout.toString().split("\n").map((e,s)=>({line:e,idx:s+1})).filter(e=>{let{line:s}=e;return s.toLowerCase().includes(i.toLowerCase())});s.length>0&&e.push({type:"layout",key:"main",matches:s.map(e=>{let{line:s,idx:t}=e;return{lineNumber:t,content:s,preview:s.trim()}})})}d(e)},[i,n,m]);const f=e=>{let{item:s,selected:t,onSelect:a}=e;const n=x[s.id]||!1,r=n?s.matches:s.matches.slice(0,3),i=s.matches.length>3;return(0,re.jsxs)("div",{className:"pl-2 mb-2",children:[(0,re.jsxs)(Hs,{variant:t===s.id?"secondary":"ghost",className:"w-full justify-start text-left ".concat(t===s.id?"bg-primary/10 text-primary hover:bg-primary/20":"hover:bg-gray-100"," ").concat(l?"pointer-events-none opacity-60 cursor-not-allowed":""),onClick:()=>{l||a(s.id)},title:l?"You have unsaved changes. Save or discard to jump to a line.":"",children:[s.icon,(0,re.jsx)("span",{className:"ml-2 truncate max-w-[250px] inline-block",children:s.label})]}),(0,re.jsxs)("div",{className:"pl-4 mt-1 text-xs",children:[r.map((e,t)=>(0,re.jsxs)("div",{className:"text-gray-600 bg-gray-100 rounded p-1 mb-1 overflow-hidden cursor-pointer hover:bg-gray-200 ".concat(l?"pointer-events-none opacity-60 cursor-not-allowed":""),onClick:()=>{return t=e.lineNumber,void(l||a(s.id,t));var t},title:l?"You have unsaved changes. Save or discard to jump to a line.":"",children:[(0,re.jsxs)("span",{className:"text-gray-500",children:[e.lineNumber,": "]}),(0,re.jsx)("span",{className:"whitespace-nowrap overflow-hidden text-ellipsis inline-block max-w-[180px]",children:e.preview})]},t)),i&&(0,re.jsxs)("div",{className:"text-gray-500 italic pl-1 flex items-center cursor-pointer hover:text-gray-700",onClick:e=>{e.stopPropagation(),h(e=>(0,K.A)((0,K.A)({},e),{},{[s.id]:!n}))},children:[(0,re.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(s.matches.length-3," more matches")]})]})]})};return(0,re.jsxs)("div",{className:"flex flex-col h-full bg-gray-100 border-r",style:{width:"100%"},children:[(0,re.jsx)("div",{className:"border-b p-2 bg-gray-50",children:(0,re.jsxs)(Hs,{variant:"ghost",className:"w-full justify-start text-sm",onClick:a,children:[(0,re.jsx)(Qt.A,{className:"h-4 w-4 mr-2"}),"Back to Editor"]})}),(0,re.jsx)("div",{className:"p-3 border-b",children:(0,re.jsxs)("div",{className:"flex items-center gap-2",children:[(0,re.jsx)(ft,{type:"text",placeholder:"Search files...",value:i,onChange:e=>{o(e.target.value),u(e.target.value.length>=2)},className:"text-sm w-full"}),i&&(0,re.jsx)(Hs,{variant:"ghost",size:"icon",onClick:()=>{o(""),u(!1)},children:(0,re.jsx)(Xo.MKb,{className:"h-4 w-4"})})]})}),m&&c.length>0?(0,re.jsxs)("div",{className:"flex-1 overflow-y-auto",children:[(0,re.jsxs)("div",{className:"p-2 text-xs text-gray-500",children:[c.length," result",1!==c.length?"s":""," in ",c.length," file",1!==c.length?"s":""]}),(0,re.jsx)("div",{className:"space-y-1",children:c.map(e=>({id:"".concat(e.type,":").concat(e.key),label:e.key,icon:"entities"===e.type?(0,re.jsx)(Zo.A,{className:"w-4 h-4"}):"layout"===e.type?(0,re.jsx)(vi.A,{className:"w-4 h-4"}):(0,re.jsx)(xh.A,{className:"w-4 h-4"}),matches:e.matches})).map((e,a)=>(0,re.jsx)(f,{item:e,selected:s?"".concat(s.type,":").concat(s.key):null,onSelect:t},a))})]}):(0,re.jsx)("div",{className:"flex-1 overflow-y-auto",children:(0,re.jsx)(Ld,{items:(()=>{const e=[];if(n.pages&&Object.keys(n.pages).length>0){const s=p(n.pages);e.push({id:"pages",label:"Pages",icon:(0,re.jsx)(hh.A,{className:"w-4 h-4"}),subitems:g(s,null,"pages")})}if(n.components&&Object.keys(n.components).length>0){const s=p(n.components);e.push({id:"components",label:"Components",icon:(0,re.jsx)(hh.A,{className:"w-4 h-4"}),subitems:g(s,null,"components")})}if(n.entities&&Object.keys(n.entities).length>0){const s=p(n.entities);e.push({id:"entities",label:"Entities",icon:(0,re.jsx)(hh.A,{className:"w-4 h-4"}),subitems:g(s,null,"entities")})}if(n.layout&&e.push({id:"layout:main",label:"Layout.js",icon:(0,re.jsx)(vi.A,{className:"w-4 h-4"})}),n.has_backend_functions_enabled&&n.functions){const s=p(n.functions);e.push({id:"functions",label:"Functions",icon:(0,re.jsx)(hh.A,{className:"w-4 h-4"}),subitems:g(s,null,"functions")})}return e})(),selected:s?"".concat(s.type,":").concat(s.key):null,onSelect:e=>{if(e.includes("/")){const[s,a]=(e=>{if(-1!==e.indexOf(":"))return e.split(":");const s=e.split("/"),t=s[0];return 1===s.length?[t,""]:[t,s.slice(1).join("/")]})(e);let r=!1;("pages"===s&&n.pages&&n.pages[a]||"components"===s&&n.components&&n.components[a]||"functions"===s&&n.functions&&n.functions[a]||"entities"===s&&n.entities&&n.entities[a])&&(r=!0),r&&t("".concat(s,":").concat(a))}else t(e)},title:"Files",showBackButton:!1,onBack:a,showSearch:!1,style:{width:"100%"}})})]})};var gh=t(81646),fh=t(13129);const vh=["className"],bh=["withHandle","className"],jh=e=>{let{className:s}=e,t=(0,as.A)(e,vh);return(0,re.jsx)(fh.YZ,(0,K.A)({className:is("flex h-full w-full data-[panel-group-direction=vertical]:flex-col",s)},t))},yh=fh.Zk,Nh=e=>{let{withHandle:s,className:t}=e,a=(0,as.A)(e,bh);return(0,re.jsx)(fh.TW,(0,K.A)((0,K.A)({className:is("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",t)},a),{},{children:s&&(0,re.jsx)("div",{className:"z-10 flex h-4 w-3 items-center justify-center rounded-sm border bg-border",children:(0,re.jsx)(gh.A,{className:"h-2.5 w-2.5"})})}))},wh=()=>{const{app:e}=_s(),[s,t]=(0,H.useState)(null),[a,n]=(0,H.useState)(null),[r,l]=(0,H.useState)(!1),i=(0,H.useRef)(null),o=(0,Z.Zp)(),c=(0,Z.zy)(),[d,m]=(0,H.useState)(!1);(0,H.useEffect)(()=>{const s=new URLSearchParams(c.search),a=s.get("filePath"),r=s.get("line");if(n(r?parseInt(r,10):null),a&&e){const s=a.replace(/\.\w+$/,"").split("/");if(s.length>=2){const a=s[0],n=s.slice(1).join("/");let r=!1;("pages"===a&&e.pages&&e.pages[n]||"components"===a&&e.components&&e.components[n]||"functions"===a&&e.functions&&e.functions[n]||"entities"===a&&e.entities&&e.entities[n]||"layout"===a&&e.layout)&&(r=!0),r&&t({type:a,key:n})}}},[e,c.search]);const u=(()=>{if(!s)return null;switch(s.type){case"pages":return"pages/".concat(s.key);case"components":return"components/".concat(s.key);case"functions":return"functions/".concat(s.key);case"entities":return"entities/".concat(s.key);case"layout":return"layout";default:return null}})(),x="functions"===(null==s?void 0:s.type);return(0,re.jsx)("div",{className:"h-full w-full border rounded-lg overflow-hidden bg-white shadow-sm",children:(0,re.jsxs)(jh,{direction:"horizontal",children:[(0,re.jsx)(yh,{defaultSize:33,minSize:20,maxSize:40,className:"h-full overflow-hidden",children:(0,re.jsx)(ph,{selectedFile:s,onFileSelect:function(s){let a,r,l=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;if(s.includes(":"))[a,r]=s.split(":");else{if(!s.includes("/"))return a=s,void(r="");{const t=s.split("/");a=t[0],r=t.slice(1).join("/");let n=!1;if(("pages"===a&&e.pages&&e.pages[r]||"components"===a&&e.components&&e.components[r]||"functions"===a&&e.functions&&e.functions[r]||"entities"===a&&e.entities&&e.entities[r])&&(n=!0),!n)return}}t({type:a,key:r}),n(l);const i="layout"===a?"layout/main":"".concat(a,"/").concat(r),c=new URLSearchParams;c.set("filePath",i),l&&c.set("line",l),o("?".concat(c.toString()),{replace:!0})},onBack:()=>{o("/apps/".concat(e.id,"/editor/workspace/overview"))},app:e})}),(0,re.jsx)(Nh,{withHandle:!0,className:"group transition-opacity opacity-0 hover:opacity-100 focus:opacity-100"}),(0,re.jsx)(yh,{defaultSize:75,className:"flex-1 overflow-x-auto",children:u?(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(rh,{filepath:u,selectedLine:a,onEdit:()=>{if(l(!0),null!==a){n(null);const e=new URLSearchParams(c.search);e.delete("line"),o("?".concat(e.toString()),{replace:!0})}},onSaveOrDiscard:()=>{l(!1)},isFunction:x,onRedeployFunction:async e=>{l(!0),i.current&&(await i.current.handleRedeployFunction(e),l(!1),m(!1))},isSaving:d}),x&&(0,re.jsx)(uh,{ref:i,functionName:s.key,hasUnsavedChanges:r})]}):(0,re.jsx)("div",{className:"h-full flex items-center justify-center text-gray-500",children:"Select a file to view code"})})]})})};var _h=t(36391);function kh(e){let{appId:s,appName:t,disabled:a=!1,disabledReason:n="",onError:r=()=>{}}=e;const[l,i]=(0,H.useState)(!1),[o,c]=(0,H.useState)(!1);(0,H.useEffect)(()=>{(async()=>{if(!window.entri)return new Promise(e=>{const s=document.createElement("script");s.src="https://cdn.goentri.com/entri.js",s.async=!0,s.onload=()=>{c(!0),e()},document.body.appendChild(s)});c(!0)})()},[]);return(0,re.jsx)(Hs,{size:"sm",onClick:async()=>{if(a)r("Cannot purchase domain",n||"Domain purchase is currently disabled");else if(o){i(!0);try{const e=await Ha.getEntriToken({appId:s,appName:t}),a=(0,K.A)({},e.config);await window.entri.purchaseDomain(a),Ie("Domain - Buy",{})}catch(c){var e,l;const s=(null===(e=c.response)||void 0===e||null===(l=e.data)||void 0===l?void 0:l.detail)||c.message||"Failed to get purchase config",t=s.includes("Maximum of")&&s.includes("domains allowed");r(t?"Domain limit reached":"Error purchasing domain",s)}i(!1)}else r("Error","Entri is not ready yet. Please try again in a moment.")},disabled:l||!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:l?"Buy Domain":o?a?(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(Bu.A,{className:"h-3 w-3 mr-2"}),"Domain Limit Reached"]}):"Buy Domain":(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(ku.A,{className:"h-3 w-3 mr-2 animate-spin"}),"Loading Entri..."]})})}var Ah=t(39181);const Sh=["className"],Ch=["className","variant"],Eh=["className"],Ih=["className"],Th=["className"],Ph=["className"],Lh=Ah.Provider,Oh=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,Sh);return(0,re.jsx)(Ah.Viewport,(0,K.A)({ref:s,className:is("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]",t)},a))});Oh.displayName=Ah.Viewport.displayName;const Rh=(0,ns.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"}}),Dh=H.forwardRef((e,s)=>{let{className:t,variant:a}=e,n=(0,as.A)(e,Ch);return(0,re.jsx)(Ah.Root,(0,K.A)({ref:s,className:is(Rh({variant:a}),t)},n))});Dh.displayName=Ah.Root.displayName;const Mh=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,Eh);return(0,re.jsx)(Ah.Action,(0,K.A)({ref:s,className:is("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",t)},a))});Mh.displayName=Ah.Action.displayName;const Fh=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,Ih);return(0,re.jsx)(Ah.Close,(0,K.A)((0,K.A)({ref:s,className:is("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",t),"toast-close":""},a),{},{children:(0,re.jsx)(zs.A,{className:"h-4 w-4"})}))});Fh.displayName=Ah.Close.displayName;const Bh=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,Th);return(0,re.jsx)(Ah.Title,(0,K.A)({ref:s,className:is("text-sm font-semibold",t)},a))});Bh.displayName=Ah.Title.displayName;const Uh=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,Ph);return(0,re.jsx)(Ah.Description,(0,K.A)({ref:s,className:is("text-sm opacity-90",t)},a))});Uh.displayName=Ah.Description.displayName;const zh=["id","title","description","action"];function qh(){const{toasts:e}=nn();return(0,re.jsxs)(Lh,{children:[e.map(function(e){let{id:s,title:t,description:a,action:n}=e,r=(0,as.A)(e,zh);return(0,re.jsxs)(Dh,(0,K.A)((0,K.A)({},r),{},{children:[(0,re.jsxs)("div",{className:"grid gap-1",children:[t&&(0,re.jsx)(Bh,{children:t}),a&&(0,re.jsx)(Uh,{children:a})]}),n,(0,re.jsx)(Fh,{})]}),s)}),(0,re.jsx)(Oh,{})]})}const Wh=["isLoading","loadingText","children"],Vh=150,Yh=e=>{let{isLoading:s,loadingText:t,children:a}=e,n=(0,as.A)(e,Wh);return(0,re.jsx)(Hs,(0,K.A)((0,K.A)({},n),{},{children:s?(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(ku.A,{className:"h-4 w-4 mr-2 animate-spin"}),t]}):a}))},Hh=e=>{let{open:s,onOpenChange:t,title:a,description:n,isLoading:r,loadingText:l,confirmText:i,onConfirm:o,variant:c="destructive"}=e;return(0,re.jsx)(Pa,{open:s,onOpenChange:t,children:(0,re.jsxs)(Ma,{children:[(0,re.jsxs)(Fa,{children:[(0,re.jsx)(Ua,{children:a}),(0,re.jsx)(za,{children:n})]}),(0,re.jsxs)("div",{className:"flex justify-end gap-2 pt-4",children:[(0,re.jsx)(Hs,{variant:"outline",onClick:()=>t(!1),children:"Cancel"}),(0,re.jsx)(Yh,{variant:c,onClick:o,disabled:r,isLoading:r,loadingText:l,children:i})]})]})})},Gh=e=>{var s,t;let{domain:a}=e;const n=void 0!==(null===(s=a.purchase_info)||void 0===s?void 0:s.purchase_time),r=!0===(null===(t=a.purchase_info)||void 0===t?void 0:t.blocked);return!0===a.disabled?(0,re.jsx)("span",{className:"px-2 py-0.5 text-xs bg-red-100 text-red-700 rounded-full",children:"Blocked"}):r?(0,re.jsx)("span",{className:"px-2 py-0.5 text-xs bg-orange-100 text-orange-700 rounded-full",children:"Propagation Blocked"}):n?(0,re.jsx)("span",{className:"px-2 py-0.5 text-xs bg-blue-100 text-blue-700 rounded-full",children:"Base44 Domain"}):null},$h=e=>{let{status:s,lastChecked:t,lastPollingTime:a,isBoughtDomain:n,isActive:r,isUnlinked:l,isDisabled:i}=e;return i?(0,re.jsxs)("div",{className:"space-y-1",children:[(0,re.jsx)("p",{className:"text-sm text-red-600",children:"Domain requires Builder plan or above"}),(0,re.jsx)("a",{href:"/billing",className:"text-xs text-blue-600 hover:text-blue-800 underline",children:"Update billing to restore access"})]}):l?(0,re.jsx)("p",{className:"text-sm text-gray-500",children:s}):(0,re.jsxs)("div",{className:"space-y-1",children:[(0,re.jsx)("p",{className:"text-sm text-gray-500",children:s}),!n&&t&&(0,re.jsx)("div",{className:"flex items-center gap-2 text-xs text-gray-400",children:(0,re.jsxs)("span",{children:["Last checked: ",la().utc(t).fromNow()]})}),n&&!r&&a&&(0,re.jsx)("div",{className:"flex items-center gap-2 text-xs text-gray-400",children:(0,re.jsxs)("span",{children:["Last checked: ",la()(a).format("HH:mm:ss")]})})]})},Jh=e=>{var s,t,a,n;let{domain:r,isChecking:l,isVerifying:i,isUnlinking:o,onCheck:c,onVerify:d,onUnlink:m}=e;const[u,x]=(0,H.useState)(!1),{toast:h}=nn(),p=void 0!==(null===(s=r.purchase_info)||void 0===s?void 0:s.purchase_time),g=!0===(null===(t=r.purchase_info)||void 0===t?void 0:t.unlinked),f=(null===(a=r.purchase_info)||void 0===a?void 0:a.purchase_time)&&(null===(n=r.purchase_info)||void 0===n?void 0:n.propagation_status);if(!0===r.disabled)return null;const v=async()=>{x(!0);try{await Ha.link(r.id),h({title:"Domain linked",description:"Domain has been linked to your project",duration:3e3}),c()}catch(t){var e,s;h({variant:"destructive",title:"Error linking domain",description:(null===(e=t.response)||void 0===e||null===(s=e.data)||void 0===s?void 0:s.detail)||"Something went wrong",duration:3e3})}x(!1)};return g?(0,re.jsx)("div",{className:"flex items-center gap-2 justify-end",children:(0,re.jsx)(Yh,{variant:"outline",size:"sm",onClick:v,disabled:u,isLoading:u,loadingText:"Linking...",children:"Link Domain"})}):(0,re.jsxs)("div",{className:"flex items-center gap-2 justify-end",children:[!f&&(0,re.jsxs)(Yh,{variant:"ghost",size:"sm",onClick:c,className:"text-gray-500",disabled:l,isLoading:l,loadingText:"Checking...",children:[(0,re.jsx)(ku.A,{className:"h-4 w-4 mr-2"}),"Check Status"]}),!p&&(0,re.jsx)(Yh,{variant:"outline",size:"sm",onClick:d,disabled:i,isLoading:i,loadingText:"Verifying...",children:"Verify Domain"}),p&&!g&&(0,re.jsx)(Yh,{variant:"outline",size:"sm",onClick:m,disabled:o,isLoading:o,loadingText:"Unlinking...",children:"Unlink Domain"})]})},Zh=e=>{var s,t,a,n;let{domain:r,onUpdate:l,lastPollingTime:i}=e;const{toast:o}=nn(),[c,d]=(0,H.useState)(!1),[m,u]=(0,H.useState)(!1),[x,h]=(0,H.useState)(!1),[p,g]=(0,H.useState)(!1),[f,v]=(0,H.useState)(!1),[b,j]=(0,H.useState)(!1),y=void 0!==(null===(s=r.purchase_info)||void 0===s?void 0:s.purchase_time),N=!0===(null===(t=r.purchase_info)||void 0===t?void 0:t.unlinked),w=r.disabled?"Blocked":null!==(_=r.purchase_info)&&void 0!==_&&_.unlinked?"Unlinked":null!==(k=r.purchase_info)&&void 0!==k&&k.purchase_time&&null!==(A=r.purchase_info)&&void 0!==A&&A.propagation_status?"Domain Active":null===(S=r.purchase_info)||void 0===S||!S.purchase_time||null!==(C=r.purchase_info)&&void 0!==C&&C.blocked?"verified"===(null===(E=r.last_status_payload)||void 0===E?void 0:E.verificationStatus)?"Verified":"error"===(null===(I=r.last_status_payload)||void 0===I?void 0:I.verificationStatus)?"Error":"Pending":"Waiting for DNS Propagation";var _,k,A,S,C,E,I;const T=!0===r.disabled;return(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(Hh,{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 Ha.delete(r.id),o({title:"Domain deleted",duration:3e3}),l()}catch(t){var e,s;o({variant:"destructive",title:"Error deleting domain",description:(null===(e=t.response)||void 0===e||null===(s=e.data)||void 0===s?void 0:s.detail)||"Something went wrong",duration:3e3})}u(!1),v(!1)}}),(0,re.jsx)(Hh,{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 Ha.unlink(r.id),o({title:"Domain unlinked",description:"Domain has been unlinked from your project",duration:3e3}),l()}catch(t){var e,s;o({variant:"destructive",title:"Error unlinking domain",description:(null===(e=t.response)||void 0===e||null===(s=e.data)||void 0===s?void 0:s.detail)||"Something went wrong",duration:3e3})}g(!1),j(!1)}}),(0,re.jsx)(it,{className:"hover:bg-gray-50 transition-colors ".concat(N||r.disabled?"opacity-60":""),children:(0,re.jsx)(mt,{className:"p-4",children:(0,re.jsxs)("div",{className:"flex flex-col space-y-4",children:[(0,re.jsxs)("div",{className:"flex items-center justify-between",children:[(0,re.jsxs)("div",{className:"flex items-center gap-3",children:["Domain Active"===w||"Verified"===w?(0,re.jsx)(nl.A,{className:"h-5 w-5 text-green-500"}):"Blocked"===w?(0,re.jsx)(Xe.A,{className:"h-5 w-5 text-red-500"}):(0,re.jsx)(Xe.A,{className:"h-5 w-5 text-yellow-500"}),(0,re.jsxs)("div",{children:[(0,re.jsxs)("div",{className:"flex items-center gap-2",children:[(0,re.jsx)("a",{href:"https://".concat(r.domain),target:"_blank",children:(0,re.jsx)("p",{className:"font-medium",children:r.domain})}),(0,re.jsx)(Gh,{domain:r})]}),(0,re.jsx)($h,{status:w,lastChecked:r.last_status_check,lastPollingTime:i,isUnlinked:N,isBoughtDomain:y,isActive:(null===(a=r.purchase_info)||void 0===a?void 0:a.purchase_time)&&(null===(n=r.purchase_info)||void 0===n?void 0:n.propagation_status),isDisabled:T})]})]}),(0,re.jsx)(Hs,{variant:"ghost",size:"sm",onClick:()=>v(!0),className:"text-red-500 hover:text-red-600 hover:bg-red-50",disabled:m||y&&!N&&!r.disabled,children:(0,re.jsx)(_u.A,{className:"h-4 w-4 ".concat(m?"animate-spin":"")})})]}),(0,re.jsx)(Jh,{domain:r,isChecking:x,isVerifying:c,isUnlinking:p,onCheck:async()=>{h(!0);try{var e;const s=void 0!==(null===(e=r.purchase_info)||void 0===e?void 0:e.purchase_time);s||await Ha.refreshStatus(r.id),l(),s&&await new Promise(e=>setTimeout(e,1e3))}catch(a){var s,t;o({variant:"destructive",title:"Error checking status",description:(null===(s=a.response)||void 0===s||null===(t=s.data)||void 0===t?void 0:t.detail)||"Something went wrong",duration:3e3})}h(!1)},onVerify:async()=>{d(!0);try{await Ha.verify(r.id),o({title:"Verification initiated",description:"Please check back in a few minutes",duration:3e3}),l()}catch(t){var e,s;o({variant:"destructive",title:"Error verifying domain",description:(null===(e=t.response)||void 0===e||null===(s=e.data)||void 0===s?void 0:s.detail)||"Something went wrong",duration:3e3})}d(!1)},onUnlink:()=>j(!0)})]})})})]})},Kh=e=>{let{onAdd:s,loading:t,open:a,setOpen:n,disabled:r=!1,disabledReason:l=""}=e;const[i,o]=(0,H.useState)("");return(0,re.jsxs)(Pa,{open:a,onOpenChange:n,children:[(0,re.jsx)(La,{asChild:!0,children:(0,re.jsx)(Hs,{variant:"outline",disabled:r,className:"text-gray-700 hover:text-gray-900 hover:bg-gray-100 ".concat(r?"bg-red-50 border-red-200 text-red-600 cursor-not-allowed hover:bg-red-50 hover:text-red-600":""),children:r?(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(Fu.A,{className:"h-4 w-4 mr-2"}),"Domain Limit Reached"]}):(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(Ss.A,{className:"h-4 w-4 mr-2"}),"Add Domain"]})})}),(0,re.jsxs)(Ma,{children:[(0,re.jsxs)(Fa,{children:[(0,re.jsx)(Ua,{children:"Add New Domain"}),(0,re.jsx)(za,{children:"Enter your domain name below. Make sure it follows the format: app.example.com"})]}),(0,re.jsxs)("div",{className:"space-y-4 pt-4",children:[(0,re.jsx)(ft,{placeholder:"Enter domain (e.g. app.example.com)",value:i,onChange:e=>o(e.target.value)}),(0,re.jsx)("div",{className:"flex justify-end",children:(0,re.jsx)(Yh,{onClick:async()=>{if(r)return;const e=i.toLowerCase().trim();await s(e),o(""),n(!1)},disabled:t||!i,isLoading:t,loadingText:"Adding...",children:"Add Domain"})})]})]})]})},Xh=e=>{let{onUpgrade:s}=e;return(0,re.jsx)("div",{className:"w-full",children:(0,re.jsxs)("div",{className:"w-full rounded-lg p-12 text-center",style:{borderWidth:"2px",borderStyle:"dashed",borderColor:"#e5e7eb",borderRadius:"12px"},children:[(0,re.jsx)("h3",{className:"text-xl font-semibold mb-2",children:"Want to use your domain?"}),(0,re.jsxs)("p",{className:"text-gray-600 mb-6",children:["Custom domains are available on our Builder plan and above.",(0,re.jsx)("br",{}),"Upgrade to connect your domain to this app."]}),(0,re.jsx)(Hs,{onClick:s,className:"bg-black text-white hover:bg-gray-800",children:"View Plans"})]})})},Qh=()=>(0,re.jsx)(it,{children:(0,re.jsx)(mt,{className:"p-4",children:(0,re.jsxs)("div",{className:"flex items-start gap-3",children:[(0,re.jsx)(_h.A,{className:"h-5 w-5 text-blue-500 shrink-0 mt-0.5"}),(0,re.jsxs)("div",{className:"space-y-2 text-sm",children:[(0,re.jsxs)("p",{className:"font-medium",children:[(0,re.jsx)("b",{children:"After adding a domain"}),", connect it via your DNS provider:"]}),(0,re.jsxs)("ol",{className:"list-decimal list-inside space-y-1 text-gray-600",children:[(0,re.jsxs)("li",{children:["Add CNAME record: ",(0,re.jsx)("code",{className:"bg-gray-100 px-1.5 py-0.5 rounded",children:"www \u2192 base44.onrender.com"})]}),(0,re.jsxs)("li",{children:["Add ANAME/ALIAS record: ",(0,re.jsx)("code",{className:"bg-gray-100 px-1.5 py-0.5 rounded",children:"empty or @ \u2192 base44.onrender.com"})]}),(0,re.jsxs)("li",{children:["If your DNS provider doesn't support ANAME/ALIAS, use A record: ",(0,re.jsx)("code",{className:"bg-gray-100 px-1.5 py-0.5 rounded",children:"@ \u2192 216.24.57.1"})]}),(0,re.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,re.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,re.jsxs)("p",{className:"text-xs text-gray-500",children:["Need help? Create a ticket at ",(0,re.jsx)("button",{type:"button",onClick:()=>{window.open("/support","_blank")},className:"underline text-primary hover:text-orange-500 transition-colors",children:"support system"})]})]})]})})}),ep=e=>{let{currentCount:s,maxCount:t}=e;return(0,re.jsx)(it,{className:"border-orange-200 bg-orange-50",children:(0,re.jsx)(mt,{className:"p-4",children:(0,re.jsxs)("div",{className:"flex items-start gap-3",children:[(0,re.jsx)(Fu.A,{className:"h-5 w-5 text-orange-500 shrink-0 mt-0.5"}),(0,re.jsxs)("div",{className:"space-y-2 text-sm",children:[(0,re.jsx)("p",{className:"font-medium text-orange-800",children:"Domain Limit Reached"}),(0,re.jsxs)("p",{className:"text-orange-700",children:["You have reached the maximum of ",t," domains for this app (",s,"/",t,"). Please remove some domains before adding new ones."]})]})]})})})},sp=e=>{let{app:s,onUpdate:t,isPaidTier:a=!0}=e;const[n,r]=(0,H.useState)(!1),{toast:l}=nn(),i=fa(s).replace(/^https?:\/\//,"");return s?(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(tp,{app:s,onUpdate:t,open:n,onOpenChange:r,isPaidTier:a}),(0,re.jsx)(it,{className:"border rounded-lg",children:(0,re.jsx)(mt,{className:"p-4",children:(0,re.jsxs)("div",{className:"flex items-center justify-between",children:[(0,re.jsxs)("div",{className:"flex-1",children:[(0,re.jsx)("div",{className:"text-[16px] font-medium mb-1",children:i}),(0,re.jsx)("div",{className:"text-sm text-gray-500",children:"Never Expires"})]}),(0,re.jsx)(Hs,{variant:"outline",size:"sm",onClick:()=>r(!0),className:"ml-4",children:"Edit URL"})]})})})]}):null},tp=e=>{let{app:s,onUpdate:t,open:a,onOpenChange:n,isPaidTier:r=!0}=e;const[l,i]=(0,H.useState)((null==s?void 0:s.slug)||""),[o,c]=(0,H.useState)(!1),[d,m]=(0,H.useState)(""),{toast:u}=nn(),x=(0,Z.Zp)();(0,H.useEffect)(()=>{i((null==s?void 0:s.slug)||""),m("")},[null==s?void 0:s.slug]);if(!s)return null;return(0,re.jsx)(Pa,{open:a,onOpenChange:n,children:(0,re.jsxs)(Ma,{className:"w-[634px] max-w-[634px] p-6",children:[(0,re.jsx)(Fa,{className:"text-left mb-3",children:(0,re.jsx)(Ua,{className:"text-lg font-semibold",children:"Edit URL"})}),(0,re.jsx)("div",{className:"space-y-6",children:(0,re.jsxs)("div",{children:[(0,re.jsxs)("div",{className:"flex justify-between items-center mb-2",children:[(0,re.jsx)("p",{className:"text-sm font-normal text-gray-500",children:"Base44 Built-in domain"}),l&&(0,re.jsx)("button",{onClick:async()=>{c(!0);try{await t({slug:null});const e=fa(s).replace(/^https?:\/\//,"");u({title:"Slug reset to default",description:"Your app is now available at ".concat(e),duration:3e3}),Ie("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"})]}),r?(0,re.jsxs)(re.Fragment,{children:[(0,re.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,re.jsx)("span",{className:"text-sm text-gray-500 pl-3 select-none",children:"https://"}),(0,re.jsx)("input",{value:l,onChange:e=>{i(e.target.value.toLowerCase()),m("")},className:"flex-1 text-base bg-transparent outline-none"}),(0,re.jsxs)("span",{className:"text-sm text-gray-400 pr-3 select-none",children:[".","base44.app"]})]}),d&&(0,re.jsxs)("div",{className:"flex items-center gap-2 text-sm text-red-600 mt-2",children:[(0,re.jsx)(Xe.A,{className:"h-4 w-4"}),(0,re.jsx)("span",{children:d})]}),(0,re.jsx)("div",{className:"flex justify-end items-center mt-6",children:(0,re.jsx)(Yh,{onClick:async()=>{c(!0);try{if(!l){await t({slug:null});const e=fa(s).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 t({slug:l});const e=fa((0,K.A)((0,K.A)({},s),{},{slug:l})).replace(/^https?:\/\//,"");u({title:"URL updated",description:"Your app is now available at ".concat(e),duration:3e3}),Ie("Custom URL - Updated",{}),n(!1),i(l)}catch(d){var e,a;const t=(null===(e=d.response)||void 0===e||null===(a=e.data)||void 0===a?void 0:a.detail)||d.message||"Something went wrong";t.toLowerCase().includes("is already in use")?m("URL change failed, this URL is already taken. Please try a different one."):t.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||l===(null==s?void 0:s.slug),isLoading:o,loadingText:"Changing...",className:"bg-black text-white hover:bg-gray-800 ml-auto",children:"Change"})})]}):(0,re.jsxs)(re.Fragment,{children:[(0,re.jsxs)("div",{className:"relative flex items-center h-10 rounded-md border border-gray-300 bg-gray-100",children:[(0,re.jsx)("span",{className:"text-sm text-gray-500 pl-3 select-none",children:"https://"}),(0,re.jsx)("input",{value:null==s?void 0:s.slug,disabled:!0,className:"flex-1 text-base bg-transparent outline-none"}),(0,re.jsxs)("span",{className:"text-sm text-gray-400 pr-3 select-none",children:[".","base44.app"]})]}),(0,re.jsx)("div",{className:"bg-blue-50 border border-blue-200 rounded-lg p-4 mt-4",children:(0,re.jsxs)("div",{className:"flex items-start gap-3",children:[(0,re.jsx)(Xe.A,{className:"h-4 w-4 text-blue-500 mt-0.5 shrink-0"}),(0,re.jsxs)("p",{className:"text-sm text-blue-800",children:["URL editing requires a starter plan."," ",(0,re.jsx)("button",{onClick:()=>{n(!1),x("/billing")},className:"underline font-medium hover:text-blue-900",children:"Upgrade to Premium"})]})]})})]})]})})]})})};function ap(e){let{appId:s,appName:t}=e;const{user:a}=oe(),{app:n,updateApp:r}=_s(),[l,i]=(0,H.useState)([]),[o,c]=(0,H.useState)(!1),{toast:d}=nn(),m=(0,Z.Zp)(),u=(0,H.useRef)(null),[x,h]=(0,H.useState)(!1),[p,g]=(0,H.useState)(null),[f,v]=(0,H.useState)(!1),[b,j]=(0,H.useState)(!1),[y,N]=(0,H.useState)(null),w=(null==a?void 0:a.subscription_tier)&&!["free","starter","starter_yearly"].includes(a.subscription_tier),_=l.length>=Vh,k=async()=>{try{const t=await Ha.filter({app_id:s});if(i(t),N(Date.now()),p){const s=t.find(e=>e.domain===p);var e;if(s)g(null),null!==(e=s.purchase_info)&&void 0!==e&&e.propagation_status||x?S():A()}const a=t.some(e=>{var s,t,a;return(null===(s=e.purchase_info)||void 0===s?void 0:s.purchase_time)&&!(null!==(t=e.purchase_info)&&void 0!==t&&t.propagation_status)&&!(null!==(a=e.purchase_info)&&void 0!==a&&a.blocked)&&!e.disabled});a&&!x?A():!a&&x&&S()}catch(n){var t,a;d({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})}},A=()=>{h(!0),u.current&&clearInterval(u.current),u.current=setInterval(k,1e4)},S=()=>{h(!1),u.current&&(clearInterval(u.current),u.current=null)};(0,H.useEffect)(()=>(w&&k(),()=>{S()}),[s,w]),(0,H.useEffect)(()=>{const e=new URLSearchParams(window.location.search),s=e.get("result"),t=e.get("domain");if(s||t||Ie("Domain - Manage",{}),s&&t){"success"===s?(d({title:"Domain Purchased!",description:"Your domain ".concat(t," was purchased successfully. Waiting for it to appear in your domains...")}),g(t),A(),Ie("Domain - Purchased Successfully",{domain:t})):d({variant:"destructive",title:"Domain Purchase Failed",description:"Purchase failed for ".concat(t,".")});const e=new URL(window.location);e.searchParams.delete("result"),e.searchParams.delete("domain"),window.history.replaceState({},document.title,e.pathname)}},[]);const C=async e=>{if(e)if(_)d({variant:"destructive",title:"Domain limit reached",description:"You can only have up to ".concat(Vh," domains per app. Please remove some domains first."),duration:5e3});else{c(!0);try{await Ha.create({domain:e,app_id:s}),await k(),d({title:"Domain added successfully",description:"Please verify your domain to complete setup",duration:3e3})}catch(n){var t,a;d({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})}c(!1)}};return(0,re.jsxs)(su,{title:"Domains",subtitle:(0,re.jsxs)("p",{children:["Buy, connect and manage your domains. ",(0,re.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,re.jsx)(qh,{}),(0,re.jsxs)("div",{children:[(0,re.jsxs)("div",{className:"mb-12",children:[(0,re.jsx)("h3",{className:"text-base font-medium text-black mb-4",children:"Built-in domain"}),(0,re.jsx)(sp,{app:n,onUpdate:r,isPaidTier:!0})]}),(0,re.jsxs)("div",{className:"mb-8",children:[(0,re.jsx)("h3",{className:"text-base font-medium text-black mb-4",children:"Custom domains"}),w?!_&&(0,re.jsxs)("div",{className:"flex items-center gap-2.5 mb-4",children:[(0,re.jsx)(Hs,{variant:"outline",size:"sm",onClick:()=>v(e=>!e),className:"h-8 px-4 rounded-md border text-sm bg-white",children:"Connect your Domain"}),(0,re.jsx)("div",{className:"inline-block",children:(0,re.jsx)(kh,{appId:s,appName:t,disabled:_,disabledReason:_?"Maximum of ".concat(Vh," domains reached for this app"):"",onError:(e,s)=>{const t=e.includes("Domain limit reached")||s.includes("Maximum of");d({variant:"destructive",title:e,description:s,duration:t?5e3:3e3})}})})]}):(0,re.jsx)(Xh,{onUpgrade:()=>m("/billing")})]}),w&&_&&(0,re.jsx)(ep,{currentCount:l.length,maxCount:Vh}),w&&f&&!_&&(0,re.jsxs)("div",{className:"space-y-2 mb-4 w-full max-w-xl",children:[(0,re.jsx)(Kh,{onAdd:C,loading:o,open:b,setOpen:j,disabled:_,disabledReason:_?"Maximum of ".concat(Vh," domains reached"):""}),(0,re.jsx)(Qh,{})]}),w&&_&&f&&(0,re.jsxs)("div",{className:"space-y-2 mb-4 w-full max-w-xl",children:[(0,re.jsx)(Kh,{onAdd:C,loading:o,open:b,setOpen:j,disabled:_,disabledReason:_?"Maximum of ".concat(Vh," domains reached"):""}),(0,re.jsx)("div",{className:"text-sm text-red-600 mt-2 p-3 bg-red-50 border border-red-200 rounded-md",children:(0,re.jsxs)("div",{className:"flex items-center gap-2",children:[(0,re.jsx)(Fu.A,{className:"h-4 w-4"}),(0,re.jsxs)("span",{children:["Cannot add domains: You have reached the maximum limit of ",Vh," domains per app."]})]})})]}),w&&(0,re.jsx)("div",{className:"grid gap-6",children:l.length>0&&(0,re.jsx)("div",{className:"space-y-4",children:l.map(e=>(0,re.jsx)(Zh,{domain:e,onUpdate:k,lastPollingTime:y},e.id))})})]})]})}var np=t(81064),rp=t(81946);function lp(e){let{rule:s}=e;if(!s)return(0,re.jsx)("span",{className:"text-muted-foreground",children:"No restrictions"});if("{{user.email}}"===s.created_by)return(0,re.jsxs)("span",{className:"flex items-center gap-1.5",children:[(0,re.jsx)(np.A,{className:"h-3.5 w-3.5",style:{color:"#64748b"}})," Creator only"]});if(s.user_condition&&"admin"===s.user_condition.role)return(0,re.jsxs)("span",{className:"flex items-center gap-1.5",children:[(0,re.jsx)(rp.A,{className:"h-3.5 w-3.5",style:{color:"#64748b"}})," Admin only"]});if(s.$or)return(0,re.jsxs)("span",{className:"flex items-center gap-1.5",children:[(0,re.jsx)("span",{className:"bg-secondary text-secondary-foreground text-xs rounded-md px-1.5 py-0.5",children:"OR"}),(0,re.jsxs)("span",{children:[s.$or.length," conditions"]})]});if(s.$and)return(0,re.jsxs)("span",{className:"flex items-center gap-1.5",children:[(0,re.jsx)("span",{className:"bg-secondary text-secondary-foreground text-xs rounded-md px-1.5 py-0.5",children:"AND"}),(0,re.jsxs)("span",{children:[s.$and.length," conditions"]})]});const t=Object.keys(s).filter(e=>!e.startsWith("$"));if(t.length){const e=t[0],a=s[e];if("string"==typeof a&&a.startsWith("{{user."))return(0,re.jsxs)("span",{className:"flex items-center gap-1.5",children:[(0,re.jsx)(al.A,{className:"h-3.5 w-3.5",style:{color:"#64748b"}}),(0,re.jsxs)("span",{className:"text-xs font-medium",children:[e.replace("data.","")," = user field"]})]})}if(s.field_condition){const e=Object.entries(s.field_condition).map(e=>{let[s,t]=e;return"".concat(s,": ").concat(JSON.stringify(t))}).join(", ");return(0,re.jsxs)("span",{className:"flex items-center gap-1.5",children:[(0,re.jsx)(al.A,{className:"h-3.5 w-3.5",style:{color:"#64748b"}}),(0,re.jsxs)("span",{className:"text-xs font-medium",children:["Field(s): ",e]})]})}return(0,re.jsxs)("span",{className:"text-xs font-medium flex items-center gap-1.5",children:[(0,re.jsx)(Ho.A,{className:"h-3.5 w-3.5",style:{color:"#64748b"}}),"Custom rule"]})}function ip(e){let{rec:s,onApply:t,onDismiss:a,forceOpen:n,onOpen:r}=e;const[l,i]=(0,H.useState)(!!n),[o,c]=(0,H.useState)(!1),d=(e,s,t)=>(0,re.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,re.jsxs)("div",{className:"flex items-center gap-2 mb-1 text-black font-medium text-sm",children:[s,t]}),o?(0,re.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,re.jsx)("div",{className:"w-full text-xs min-h-[32px] flex flex-col gap-1",children:(()=>{try{const s="string"==typeof e?JSON.parse(e):e;if(s&&(s.$or||s.$and)){return(s.$or||s.$and).map((e,s)=>(0,re.jsx)(lp,{rule:e},s))}return(0,re.jsx)(lp,{rule:s})}catch(s){return(0,re.jsx)("span",{children:e})}})()})]});return s?l?(0,re.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,re.jsxs)("div",{className:"flex items-center gap-2 mb-2",children:[(0,re.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,re.jsx)(Tt.A,{className:"h-4 w-4 text-slate-500"})}),(0,re.jsx)(Fu.A,{className:"h-5 w-5 text-black",strokeWidth:2,fill:"none"}),(0,re.jsx)("span",{className:"font-semibold text-[1.08rem] text-black",children:"RLS Recommendation"})]}),(0,re.jsx)("div",{className:"text-muted-foreground text-sm mb-2",children:s.description}),(0,re.jsxs)("div",{className:"flex items-center gap-1 mb-2",children:[(0,re.jsx)("span",{className:"text-xs text-slate-700",children:"JSON"}),(0,re.jsx)(wu,{checked:o,onCheckedChange:c,onClick:e=>e.stopPropagation(),onFocus:e=>e.stopPropagation(),className:"scale-75"})]}),(0,re.jsxs)("div",{className:o?"flex flex-col gap-3":"flex flex-row gap-3",children:[d(s.read_rule,(0,re.jsx)(oh.A,{className:"h-4 w-4 text-slate-500 opacity-40"}),"Read"),d(s.write_rule,(0,re.jsx)(Hr.A,{className:"h-4 w-4 text-slate-500 opacity-40"}),"Write/Delete")]}),(0,re.jsxs)("div",{className:"flex justify-end gap-2 mt-6",children:[(0,re.jsx)(Hs,{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,re.jsx)(Hs,{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(),t&&t()},children:"Apply Fixes"})]})]}):(0,re.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),r&&r())},children:[(0,re.jsxs)("div",{className:"flex items-center gap-2 whitespace-nowrap flex-1 min-w-0",children:[(0,re.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),r&&r())},"aria-label":"Expand recommendations",children:(0,re.jsx)(It.A,{className:"h-4 w-4 text-slate-500"})}),(0,re.jsx)(Fu.A,{className:"h-5 w-5 text-black",strokeWidth:2,fill:"none"}),(0,re.jsx)("span",{className:"font-semibold text-black text-xs truncate",children:"RLS Recommendation"})]}),(0,re.jsx)("div",{className:"flex-shrink-0 w-full md:w-auto flex justify-end",children:(0,re.jsx)(Hs,{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(),t&&t()},children:"Apply Fixes"})})]}):null}function op(e){let{entity:s,scanResult:t,rlsRecs:a,onSaveRecommendation:n,onClick:r,clickable:l,forceOpenRLS:i,onRLSOpen:o}=e;const c=s.rls&&Object.keys(s.rls).length>0,d=c&&s.rls.read,m=c&&s.rls.write;let u=[];t&&a&&a.length>0&&(u=a.map((e,s)=>(0,K.A)((0,K.A)({},e),{},{_idx:s})).filter(e=>e.entity_name===s.name));return(0,re.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(l?"hover:bg-muted/30":""),onClick:e=>{e.target.closest(".rec-collapsible-trigger")||e.target.closest(".rec-save-btn")||l&&r&&r()},tabIndex:l?0:void 0,role:l?"button":void 0,children:[(0,re.jsxs)("div",{className:"flex items-center gap-2",children:[(0,re.jsx)("span",{className:"text-base font-semibold",children:s.title||s.name}),(0,re.jsxs)(et,{variant:c?"default":"outline",className:"ml-2 ".concat(c?"bg-blue-100 text-blue-800 hover:bg-blue-200":""),children:[c?(0,re.jsx)(Fs.A,{className:"h-3 w-3 mr-1"}):(0,re.jsx)(oh.A,{className:"h-3 w-3 mr-1"}),c?"Restricted":"Public"]})]}),(0,re.jsx)("div",{className:"space-y-3 text-sm mt-2",children:c?(0,re.jsx)(re.Fragment,{children:(0,re.jsxs)("div",{className:"flex flex-row gap-8 w-full items-start",children:[(0,re.jsxs)("div",{className:"flex-1 min-w-[160px] flex flex-col items-start",children:[(0,re.jsxs)("div",{className:"flex items-center gap-2 mb-1 min-h-[24px]",children:[(0,re.jsx)(oh.A,{className:"h-4 w-4 text-slate-500 opacity-40"}),(0,re.jsx)("span",{className:"text-muted-foreground font-medium",children:"Read:"})]}),(0,re.jsx)("div",{className:"flex flex-col gap-0.5 w-full",children:d?Array.isArray(s.rls.read.$or)?s.rls.read.$or.map((e,s)=>(0,re.jsx)("div",{className:"flex items-center py-0.5",children:(0,re.jsx)(lp,{rule:e})},s)):(0,re.jsx)("div",{className:"flex items-center py-0.5",children:(0,re.jsx)(lp,{rule:s.rls.read})}):(0,re.jsx)("span",{className:"text-muted-foreground",children:"No restrictions"})})]}),(0,re.jsxs)("div",{className:"flex-1 min-w-[160px] flex flex-col items-start",children:[(0,re.jsxs)("div",{className:"flex items-center gap-2 mb-1 min-h-[24px]",children:[(0,re.jsx)(Hr.A,{className:"h-4 w-4 text-slate-500 opacity-40"}),(0,re.jsx)("span",{className:"text-muted-foreground font-medium",children:"Write/Delete:"})]}),(0,re.jsx)("div",{className:"flex flex-col gap-0.5 w-full",children:m?Array.isArray(s.rls.write.$or)?s.rls.write.$or.map((e,s)=>(0,re.jsx)("div",{className:"flex items-center py-0.5",children:(0,re.jsx)(lp,{rule:e})},s)):(0,re.jsx)("div",{className:"flex items-center py-0.5",children:(0,re.jsx)(lp,{rule:s.rls.write})}):(0,re.jsx)("span",{className:"text-muted-foreground",children:"Same as read"})})]})]})}):(0,re.jsxs)("div",{className:"flex items-center text-muted-foreground",children:[(0,re.jsx)(Xe.A,{className:"h-4 w-4 mr-2 text-red-500"}),(0,re.jsx)("span",{children:"All users have full access"})]})}),u.length>0&&(0,re.jsx)(ip,{rec:u[0],onApply:()=>n(u[0]._idx),forceOpenRLS:i,onOpen:o})]})}var cp=t(18247);const dp=["className"],mp=["className"],up=["className"],xp=["className"],hp=["className"],pp=["className"],gp=["className"],fp=["className"],vp=cp.bL,bp=cp.l9,jp=cp.ZL,yp=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,dp);return(0,re.jsx)(cp.hJ,(0,K.A)((0,K.A)({className:is("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",t)},a),{},{ref:s}))});yp.displayName=cp.hJ.displayName;const Np=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,mp);return(0,re.jsxs)(jp,{children:[(0,re.jsx)(yp,{}),(0,re.jsx)(cp.UC,(0,K.A)({ref:s,className:is("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",t)},a))]})});Np.displayName=cp.UC.displayName;const wp=e=>{let{className:s}=e,t=(0,as.A)(e,up);return(0,re.jsx)("div",(0,K.A)({className:is("flex flex-col space-y-2 text-center sm:text-left",s)},t))};wp.displayName="AlertDialogHeader";const _p=e=>{let{className:s}=e,t=(0,as.A)(e,xp);return(0,re.jsx)("div",(0,K.A)({className:is("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",s)},t))};_p.displayName="AlertDialogFooter";const kp=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,hp);return(0,re.jsx)(cp.hE,(0,K.A)({ref:s,className:is("text-lg font-semibold",t)},a))});kp.displayName=cp.hE.displayName;const Ap=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,pp);return(0,re.jsx)(cp.VY,(0,K.A)({ref:s,className:is("text-sm text-muted-foreground",t)},a))});Ap.displayName=cp.VY.displayName;const Sp=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,gp);return(0,re.jsx)(cp.rc,(0,K.A)({ref:s,className:is(Ys(),t)},a))});Sp.displayName=cp.rc.displayName;const Cp=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,fp);return(0,re.jsx)(cp.ZD,(0,K.A)({ref:s,className:is(Ys({variant:"outline"}),"mt-2 sm:mt-0",t)},a))});function Ep(e){var s;let{rule:t,onChange:a,onDelete:n,index:r}=e;const{app:l}=_s(),[i,o]=(0,H.useState)(()=>t?"{{user.email}}"===t.created_by?"creatorOnly":t.user_condition?"userProperty":"fieldComparison":"none"),[c,d]=(0,H.useState)(""),[m,u]=(0,H.useState)(""),[x,h]=(0,H.useState)("role"),[p,g]=(0,H.useState)(""),f=(null==l||null===(s=l.user_entity)||void 0===s?void 0:s.properties)||{},v=Object.keys(f).filter(e=>!["role","email","full_name"].includes(e));(0,H.useEffect)(()=>{if(t)if(t.user_condition){const e=Object.keys(t.user_condition)[0];h(e),g(t.user_condition[e])}else{const e=Object.keys(t).filter(e=>!e.startsWith("$"));if(e.length){const s=e[0],a=t[s];"string"==typeof a&&a.startsWith("{{user.")&&(d(s.replace("data.","")),u(a.substring(7,a.length-2)))}}},[t]);(0,H.useEffect)(()=>{if("fieldComparison"===i&&c&&m){let e=c;["id","created_by","updated_date","created_date"].includes(c)||(e="data.".concat(c)),a({[e]:"{{user.".concat(m,"}}")},r)}},[c,m,i,r,a]),(0,H.useEffect)(()=>{"userProperty"===i&&x&&p&&a({user_condition:{[x]:p}},r)},[x,p,i,r,a]);return(0,re.jsxs)("div",{className:"p-5 border rounded-lg relative mb-5 bg-white shadow-sm",children:[r>0&&(0,re.jsx)(Hs,{variant:"ghost",size:"icon",className:"absolute top-3 right-3 h-7 w-7 text-destructive hover:bg-red-50",onClick:()=>n(r),title:"Remove rule",children:(0,re.jsx)(_u.A,{className:"h-4 w-4"})}),(0,re.jsxs)(St,{value:i,onValueChange:e=>{o(e),"none"===e?a(null,r):"creatorOnly"===e?a({created_by:"{{user.email}}"},r):"fieldComparison"===e?(d(""),u("")):"userProperty"===e&&(h("role"),g(""))},className:"space-y-4",children:[(0,re.jsxs)("div",{className:"flex items-start space-x-3 p-3 rounded-lg border hover:bg-muted/30 transition-colors",children:[(0,re.jsx)(Ct,{value:"none",id:"none-".concat(r),className:"mt-1"}),(0,re.jsxs)("div",{className:"space-y-1",children:[(0,re.jsxs)(Nt,{htmlFor:"none-".concat(r),className:"font-medium flex items-center gap-2",children:[(0,re.jsx)(oh.A,{className:"h-4 w-4 text-green-500"}),"No Restrictions"]}),(0,re.jsx)("p",{className:"text-sm text-muted-foreground",children:"All users can access records"})]})]}),(0,re.jsxs)("div",{className:"flex items-start space-x-3 p-3 rounded-lg border hover:bg-muted/30 transition-colors",children:[(0,re.jsx)(Ct,{value:"creatorOnly",id:"creatorOnly-".concat(r),className:"mt-1"}),(0,re.jsxs)("div",{className:"space-y-1",children:[(0,re.jsxs)(Nt,{htmlFor:"creatorOnly-".concat(r),className:"font-medium flex items-center gap-2",children:[(0,re.jsx)(np.A,{className:"h-4 w-4 text-indigo-500"}),"Creator Only"]}),(0,re.jsx)("p",{className:"text-sm text-muted-foreground",children:"Users can only access records they created"})]})]}),(0,re.jsxs)("div",{className:"flex items-start space-x-3 p-3 rounded-lg border hover:bg-muted/30 transition-colors",children:[(0,re.jsx)(Ct,{value:"fieldComparison",id:"fieldComparison-".concat(r),className:"mt-1"}),(0,re.jsxs)("div",{className:"space-y-1 w-full",children:[(0,re.jsxs)(Nt,{htmlFor:"fieldComparison-".concat(r),className:"font-medium flex items-center gap-2",children:[(0,re.jsx)(al.A,{className:"h-4 w-4 text-emerald-500"}),"Entity-User Field Comparison"]}),(0,re.jsx)("p",{className:"text-sm text-muted-foreground mb-2",children:"Compare a field in this entity with a user property"}),"fieldComparison"===i&&(0,re.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4 mt-4 p-3 bg-muted/20 rounded-lg",children:[(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsxs)(Nt,{className:"flex items-center gap-1.5",children:[(0,re.jsx)(Zo.A,{className:"h-3.5 w-3.5 text-primary/70"}),"Entity Field"]}),(0,re.jsx)(ft,{placeholder:"e.g. department",value:c,onChange:e=>d(e.target.value),className:"border-muted-foreground/30 focus:border-primary"}),(0,re.jsx)("p",{className:"text-xs text-muted-foreground",children:"Field in the entity to compare"})]}),(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsxs)(Nt,{className:"flex items-center gap-1.5",children:[(0,re.jsx)(np.A,{className:"h-3.5 w-3.5 text-primary/70"}),"User Field"]}),(0,re.jsxs)(Ut,{value:m,onValueChange:u,children:[(0,re.jsx)(Wt,{className:"border-muted-foreground/30 focus:border-primary",children:(0,re.jsx)(qt,{placeholder:"Select user field"})}),(0,re.jsx)(Ht,{children:(()=>{const e=v.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,re.jsx)($t,{value:e.value,children:e.label},e.value))})]}),(0,re.jsx)("p",{className:"text-xs text-muted-foreground",children:"Field from the user to compare"})]})]})]})]}),(0,re.jsxs)("div",{className:"flex items-start space-x-3 p-3 rounded-lg border hover:bg-muted/30 transition-colors",children:[(0,re.jsx)(Ct,{value:"userProperty",id:"userProperty-".concat(r),className:"mt-1"}),(0,re.jsxs)("div",{className:"space-y-1 w-full",children:[(0,re.jsxs)(Nt,{htmlFor:"userProperty-".concat(r),className:"font-medium flex items-center gap-2",children:[(0,re.jsx)(rp.A,{className:"h-4 w-4 text-amber-500"}),"User Property Check"]}),(0,re.jsx)("p",{className:"text-sm text-muted-foreground mb-2",children:"Check if a user property matches a specific value"}),"userProperty"===i&&(0,re.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4 mt-4 p-3 bg-muted/20 rounded-lg",children:[(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsxs)(Nt,{className:"flex items-center gap-1.5",children:[(0,re.jsx)(np.A,{className:"h-3.5 w-3.5 text-primary/70"}),"User Property"]}),(0,re.jsxs)(Ut,{value:x,onValueChange:h,children:[(0,re.jsx)(Wt,{className:"border-muted-foreground/30 focus:border-primary",children:(0,re.jsx)(qt,{placeholder:"Select user property"})}),(0,re.jsxs)(Ht,{children:[(0,re.jsx)($t,{value:"role",children:"User Role"}),(0,re.jsx)($t,{value:"email",children:"User Email"}),(0,re.jsx)($t,{value:"full_name",children:"Full Name"}),v.map(e=>(0,re.jsx)($t,{value:"data.".concat(e),children:e.charAt(0).toUpperCase()+e.slice(1).replace(/_/g," ")},"data.".concat(e)))]})]})]}),(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsxs)(Nt,{className:"flex items-center gap-1.5",children:[(0,re.jsx)(Px.A,{className:"h-3.5 w-3.5 text-primary/70"}),"Required Value"]}),"role"===x?(0,re.jsxs)(Ut,{value:p,onValueChange:g,children:[(0,re.jsx)(Wt,{className:"border-muted-foreground/30 focus:border-primary",children:(0,re.jsx)(qt,{placeholder:"Select role"})}),(0,re.jsxs)(Ht,{children:[(0,re.jsx)($t,{value:"admin",children:"Admin"}),(0,re.jsx)($t,{value:"user",children:"User"})]})]}):(0,re.jsx)(ft,{placeholder:"email"===x?"e.g. admin@example.com":"e.g. required value",value:p,onChange:e=>g(e.target.value),className:"border-muted-foreground/30 focus:border-primary"}),(0,re.jsx)("p",{className:"text-xs text-muted-foreground",children:"role"===x?"Select the required user role":"Value that the user property must match"})]})]})]})]})]})]})}function Ip(e){let{entity:s,onSave:t,onBack:a}=e;const[n,r]=(0,H.useState)(s.rls||{}),[l,i]=(0,H.useState)("read"),[o,c]=(0,H.useState)(s.rls&&Object.keys(s.rls).length>0?"restricted":"public"),[d,m]=(0,H.useState)(!(!s.rls||!s.rls.write)),[u,x]=(0,H.useState)(!1),[h,p]=(0,H.useState)(()=>s.rls&&s.rls.read?s.rls.read.$or?s.rls.read.$or:[s.rls.read]:[null]),[g,f]=(0,H.useState)(()=>s.rls&&s.rls.write?s.rls.write.$or?s.rls.write.$or:[s.rls.write]:[null]);(0,H.useEffect)(()=>{const e=(0,K.A)({},n),s=h.filter(e=>null!==e),t=g.filter(e=>null!==e);s.length>0?1===s.length?e.read=s[0]:e.read={$or:s}:delete e.read,d&&t.length>0?1===t.length?e.write=t[0]:e.write={$or:t}:d?delete e.write:e.read?e.write=e.read:delete e.write,r(e)},[h,g,d]);const v=(e,s)=>{if("read"===l){const t=[...h];t[s]=e,p(t)}else{const t=[...g];t[s]=e,f(t)}},b=e=>{if("read"===l){const s=[...h];s.splice(e,1),p(s)}else{const s=[...g];s.splice(e,1),f(s)}};return(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(vp,{open:u,onOpenChange:x,children:(0,re.jsxs)(Np,{children:[(0,re.jsxs)(wp,{children:[(0,re.jsxs)(kp,{className:"flex items-center gap-2",children:[(0,re.jsx)(Fu.A,{className:"h-5 w-5 text-amber-500"}),"Remove All Security Rules"]}),(0,re.jsx)(Ap,{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,re.jsxs)(_p,{children:[(0,re.jsx)(Cp,{children:"Cancel"}),(0,re.jsx)(Sp,{onClick:()=>{c("public"),p([null]),f([null]),m(!1),x(!1)},className:"bg-red-600 hover:bg-red-700 text-white",children:"Remove All Rules"})]})]})}),(0,re.jsxs)("div",{className:"flex items-center justify-between mb-6 space-x-4 border-b pb-4",children:[(0,re.jsxs)("div",{className:"flex items-center gap-3",children:[(0,re.jsxs)(Hs,{variant:"outline",size:"sm",onClick:a,className:"hover:bg-muted/50",children:[(0,re.jsx)(Cc.A,{className:"h-4 w-4 mr-2"})," Back"]}),(0,re.jsxs)("div",{children:[(0,re.jsxs)("h2",{className:"text-xl font-semibold flex items-center gap-2",children:[(0,re.jsx)(Ho.A,{className:"h-5 w-5 text-primary"}),"Security Rules: ",s.title||s.name]}),"restricted"===o&&(0,re.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,re.jsx)(Hs,{variant:"outline",size:"sm",onClick:()=>x(!0),className:"border-red-300 text-red-600 hover:bg-red-50 hover:text-red-700",children:"Remove All Rules"})]}),(0,re.jsxs)(it,{className:"w-full border-muted-foreground/20 shadow-sm",children:[(0,re.jsx)(mt,{className:"space-y-6 pt-6",children:"public"===o?(0,re.jsx)("div",{className:"p-6 border rounded-lg bg-muted/5 space-y-4",children:(0,re.jsxs)("div",{className:"flex items-start gap-4",children:[(0,re.jsx)("div",{className:"bg-green-50 p-2 rounded-full",children:(0,re.jsx)(cd.A,{className:"h-5 w-5 text-green-600"})}),(0,re.jsxs)("div",{className:"space-y-2 flex-1",children:[(0,re.jsx)("h3",{className:"text-lg font-medium",children:"Public Access"}),(0,re.jsx)("p",{className:"text-muted-foreground",children:"Currently all users can access all records in this entity. There are no access restrictions."})]}),(0,re.jsxs)(Hs,{onClick:()=>{c("restricted"),p([null]),i("read")},className:"gap-2 whitespace-nowrap",children:[(0,re.jsx)(Fs.A,{className:"h-4 w-4"}),"Create Access Rules"]})]})}):(0,re.jsx)(re.Fragment,{children:(0,re.jsxs)(hl,{value:l,onValueChange:i,className:"w-full",children:[(0,re.jsxs)(pl,{className:"grid grid-cols-2 w-full mb-4",children:[(0,re.jsxs)(gl,{value:"read",className:"flex items-center gap-2",children:[(0,re.jsx)(oh.A,{className:"h-4 w-4"})," Read Access"]}),(0,re.jsxs)(gl,{value:"write",className:"flex items-center gap-2",children:[(0,re.jsx)(Hr.A,{className:"h-4 w-4"})," Write/Delete Access"]})]}),(0,re.jsxs)(fl,{value:l,className:"space-y-6 pt-4",children:[(0,re.jsxs)("div",{className:"space-y-4",children:[(0,re.jsxs)("div",{className:"flex items-center justify-between mb-4",children:[(0,re.jsx)(Nt,{className:"text-base font-medium flex items-center gap-2",children:"read"===l?(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(oh.A,{className:"h-4 w-4 text-blue-500"})," Read Access Rules"]}):(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(Hr.A,{className:"h-4 w-4 text-amber-500"})," Write/Delete Access Rules"]})}),(0,re.jsxs)(Hs,{variant:"outline",size:"sm",onClick:()=>{"read"===l?p([...h,null]):f([...g,null])},className:"flex items-center gap-1.5 border-primary/30 hover:bg-primary/5",children:[(0,re.jsx)(Ss.A,{className:"h-3.5 w-3.5"})," Add Rule"]})]}),"read"===l?h.map((e,t)=>(0,re.jsx)(Ep,{rule:e,onChange:v,onDelete:b,index:t,entity:s},t)):d?g.map((e,t)=>(0,re.jsx)(Ep,{rule:e,onChange:v,onDelete:b,index:t,entity:s},t)):(0,re.jsxs)("div",{className:"p-6 border rounded-lg bg-blue-50 flex flex-col items-center justify-center space-y-4",children:[(0,re.jsxs)("div",{className:"flex items-center gap-2 text-blue-800",children:[(0,re.jsx)(ha.A,{className:"h-5 w-5 text-blue-600"}),(0,re.jsx)("span",{className:"font-medium",children:"Write rules inherit from Read Access rules"})]}),(0,re.jsx)("p",{className:"text-sm text-blue-700 text-center max-w-md",children:"Users who can read records will have the same permissions for writing and deleting records"}),(0,re.jsxs)(Hs,{onClick:()=>{m(!0),h.length>0&&f([...h]),i("write")},variant:"outline",className:"border-blue-300 text-blue-700 hover:bg-blue-100",children:[(0,re.jsx)(Hr.A,{className:"h-4 w-4 mr-2"}),"Create Custom Write Rules"]})]})]}),(0,re.jsxs)("div",{className:"space-y-2 bg-muted/10 p-4 rounded-lg border",children:[(0,re.jsxs)("div",{className:"flex justify-between items-center",children:[(0,re.jsxs)(Nt,{className:"font-medium flex items-center gap-2",children:[(0,re.jsx)(al.A,{className:"h-4 w-4 text-primary/70"}),"Generated Rules (JSON)"]}),(0,re.jsx)(et,{variant:"outline",className:"bg-primary/5 border-primary/20",children:"read"===l?h.filter(e=>null!==e).length:d?g.filter(e=>null!==e).length:"Same as read"})]}),(0,re.jsx)(td,{rows:4,value:"read"===l?n.read?JSON.stringify(n.read,null,2):"":d?n.write?JSON.stringify(n.write,null,2):"":"Using the same rules as Read Access",readOnly:!0,className:"font-mono text-sm bg-muted/30 border-muted-foreground/20"})]})]})]})})}),(0,re.jsx)(ut,{className:"flex justify-end pt-4 border-t bg-muted/5",children:(0,re.jsxs)(Hs,{onClick:()=>{const e=(0,K.A)((0,K.A)({},s),{},{rls:"public"===o?void 0:n});t(e)},size:"lg",className:"gap-2",children:[(0,re.jsx)(Ho.A,{className:"h-4 w-4"}),"Save Security Rules"]})})]})]})}Cp.displayName=cp.ZD.displayName;class Tp extends X.H{getBaseURL(){return"/apps"}runSecurityScan(e){return this.axios.post("/".concat(e,"/security/generate-suggestions")).then(e=>e.result||e)}}const Pp=new Tp;function Lp(e){let{title:s,count:t,subtitle:a,noIssuesSubtitle:n,rightElement:r}=e;const l=t>0,i=l?(0,re.jsx)(Xe.A,{className:"h-4 w-4 mr-2 text-red-600",strokeWidth:2}):(0,re.jsx)(Px.A,{className:"h-4 w-4 text-green-500 mr-2",strokeWidth:2});return(0,re.jsxs)("div",{className:"flex flex-col items-start w-full",children:[(0,re.jsxs)("div",{className:"flex items-center w-full",children:[(0,re.jsxs)("span",{className:"flex items-center font-semibold text-sm text-black flex-1",children:[i,s]}),r&&(0,re.jsx)("span",{children:r})]}),(0,re.jsx)("span",{className:"text-sm leading-5 font-normal mt-1 text-black ml-6",children:l?a:n})]})}function Op(e){let{title:s,issues:t=[],subtitle:a,noIssuesSubtitle:n}=e;const[r,l]=(0,H.useState)(!1),i=t.length>0,o=i?r?(0,re.jsx)(Tt.A,{className:"h-5 w-5 text-slate-500"}):(0,re.jsx)(It.A,{className:"h-5 w-5 text-slate-500"}):null;return(0,re.jsxs)("div",{className:"w-full rounded-lg border border-[#E4E4E7] bg-white shadow-sm",children:[(0,re.jsx)("button",{className:"flex items-center justify-between w-full px-4 py-5 focus:outline-none rounded-lg",onClick:()=>i&&l(e=>!e),"aria-expanded":r,style:{border:"none",background:"transparent",boxShadow:"none"},children:(0,re.jsx)(Lp,{title:s,count:t.length,subtitle:a,noIssuesSubtitle:n,rightElement:o})}),r&&i&&(0,re.jsx)("div",{className:"flex flex-col gap-4 mb-[12px] px-4 pb-4",children:t.map((e,s)=>(0,re.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,re.jsx)("div",{className:"flex items-start",children:(0,re.jsx)(Xe.A,{className:"h-4 w-4 text-red-700 mt-0.5",strokeWidth:2})}),(0,re.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,re.jsx)("div",{className:"text-red-600 text-sm font-medium leading-5 flex items-start gap-2",children:e.description}),(0,re.jsxs)("div",{className:"text-[#71717A] text-sm font-normal leading-5",children:["File: ",e.filePath]})]})]},s))})]})}function Rp(){const{app:e}=_s(),s=(0,Z.zy)(),t=(0,Z.Zp)(),[a,n]=(0,H.useState)(null),[r,l]=(0,H.useState)("list"),[i,o]=(0,H.useState)(null),[c,d]=(0,H.useState)(!1),{toast:m}=nn(),[u,x]=(0,H.useState)(null),h=e.entities||{},p=Object.keys(h);(0,H.useEffect)(()=>{i&&i.rls_recommendations&&x([...i.rls_recommendations])},[i]);const g=(0,H.useCallback)(async()=>{Ie("Security Scan Started",{app_id:e.id,app_name:e.name}),d(!0),o(null);try{const s=await Pp.runSecurityScan(e.id);o(s.result||s),m({title:"Security scan complete",description:"Review the findings below."})}catch(s){m({title:"Security scan failed",description:s.message,variant:"destructive"})}finally{d(!1)}},[e.id,e.name,m]);(0,H.useEffect)(()=>{const e=new URLSearchParams(s.search);if("1"===e.get("autoStartScan")&&!c&&!i){g(),e.delete("autoStartScan");const a=e.toString(),n="".concat(s.pathname).concat(a?"?".concat(a):"");t(n,{replace:!0})}},[s.search,g,c,i,t,s.pathname]);const f=()=>{const e=document.getElementById("data-entities-section");e&&e.scrollIntoView({behavior:"smooth",block:"start"})};return"list"===r?(0,re.jsxs)(su,{title:"App Security",subtitle:"Configure row-level security policies to control who can access your app's data",children:[(0,re.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,re.jsxs)("div",{className:"flex flex-col",children:[(0,re.jsx)("span",{className:"font-semibold text-base text-black",children:"Scan issues"}),(0,re.jsx)("span",{className:"text-sm text-slate-500",children:"Scan typically takes few minutes to complete"})]}),(0,re.jsx)(Hs,{onClick:g,disabled:c,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:c?(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(Ze.A,{className:"animate-spin h-4 w-4"}),(0,re.jsx)("span",{className:"ml-2",children:"Scanning"})]}):(0,re.jsx)("span",{children:"Start Security Check"})})]}),i?(0,re.jsxs)("div",{className:"bg-white border border-slate-200 rounded-lg p-6 mb-8 shadow-sm animate-in fade-in",children:[(0,re.jsx)("div",{className:"font-bold text-2xl text-black mb-6",children:"Scan Results"}),(0,re.jsxs)("div",{className:"space-y-3",children:[(0,re.jsx)("div",{className:"bg-white border border-slate-200 rounded-lg p-6 shadow-sm",children:(0,re.jsx)(Lp,{title:"RLS Recommendations",count:(null==u?void 0:u.length)||0,subtitle:u&&u.length>0?(0,re.jsxs)(re.Fragment,{children:["".concat(u.length," RLS recommendation").concat(u.length>1?"s":""," found, "),(0,re.jsx)("button",{onClick:f,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,re.jsx)(Op,{title:"Secrets",subtitle:"".concat(i.hardcoded_secrets.length," Exposed secrets found"),noIssuesSubtitle:"No exposed secrets found",issues:(i.hardcoded_secrets||[]).map(e=>({description:e.description,filePath:e.file_path}))}),(0,re.jsx)(Op,{title:"Backend Functions",subtitle:"".concat(i.backend_functions.length," Unauthenticated backend functions found"),noIssuesSubtitle:"No unauthenticated backend functions found",issues:(i.backend_functions||[]).map(e=>({description:e.description,filePath:e.file_path}))})]})]}):null,(0,re.jsxs)("div",{className:"flex items-center justify-between",children:[(0,re.jsxs)("h2",{id:"data-entities-section",className:"text-xl font-medium flex items-center gap-2",children:[(0,re.jsx)(Zo.A,{className:"h-5 w-5 text-primary/70"}),"Data Entities"]}),(0,re.jsxs)(et,{variant:"outline",className:"bg-primary/5 border-primary/20 px-3 py-1",children:[(0,re.jsx)(Gr.A,{className:"h-3.5 w-3.5 mr-1.5"}),p.length," entities"]})]}),(0,re.jsx)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6 w-full mx-auto items-stretch",children:p.map(s=>(0,re.jsx)("div",{className:"h-full flex flex-col",children:(0,re.jsx)(op,{entity:h[s],scanResult:i,rlsRecs:u,app:e,onSaveRecommendation:t=>(async(s,t)=>{const a=u.filter((e,a)=>e.entity_name===s&&a===t);if(0===a.length)return;const n=a[0];try{await gs.write(e.id,"entities/".concat(n.entity_name),JSON.stringify((0,K.A)((0,K.A)({},h[n.entity_name]),{},{rls:{read:n.read_rule?JSON.parse(n.read_rule):void 0,write:n.write_rule?JSON.parse(n.write_rule):void 0}}),null,2)),x(e=>e.filter((e,s)=>s!==t)),m({title:"Rule saved for ".concat(n.entity_name),description:"The recommended rule has been saved.",variant:"success"})}catch(r){m({title:"Failed to save rule",description:r.message,variant:"destructive"})}})(s,t),onClick:()=>(e=>{n(e),l("edit")})(s),clickable:!0},s)}))})]}):(0,re.jsx)("div",{className:"max-w-full py-6 p-4",children:(0,re.jsx)(Ip,{entity:h[a],onSave:s=>{gs.write(e.id,"entities/".concat(s.name),JSON.stringify(s,null,2)),l("list")},onBack:()=>{l("list"),n(null)}})})}var Dp=t(81872);const Mp=e=>{let{secretName:s,appId:t,onUpdate:a}=e;const{toast:n}=si(),[r,l]=(0,H.useState)(!1),[i,o]=(0,H.useState)(!1),[c,d]=(0,H.useState)(""),[m,u]=(0,H.useState)(!1),[x,h]=(0,H.useState)(!1),{updateSecrets:p}=_s();return(0,re.jsx)(it,{children:(0,re.jsx)(mt,{className:"p-4",children:(0,re.jsxs)("div",{className:"flex items-center justify-between",children:[(0,re.jsxs)("div",{className:"flex items-center gap-3",children:[(0,re.jsx)(nl.A,{className:"h-5 w-5 text-green-500"}),(0,re.jsxs)("div",{children:[(0,re.jsx)("p",{className:"font-medium",children:s}),i?(0,re.jsx)("div",{className:"mt-2 space-y-2",children:(0,re.jsxs)("div",{className:"flex gap-2",children:[(0,re.jsxs)("div",{className:"relative",children:[(0,re.jsx)(ft,{type:x?"text":"password",placeholder:"New secret value",value:c,onChange:e=>d(e.target.value),className:"h-8 w-48 pr-10"}),(0,re.jsx)(Hs,{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,re.jsx)(Nx.A,{className:"h-3 w-3"}):(0,re.jsx)(oh.A,{className:"h-3 w-3"})})]}),(0,re.jsx)(Hs,{size:"sm",onClick:async()=>{if(c){u(!0);try{await p({[s]:c}),n({title:"Secret updated",duration:3e3}),a(),o(!1),d(""),h(!1)}catch(r){var e,t;n({variant:"destructive",title:"Error updating secret",description:(null===(e=r.response)||void 0===e||null===(t=e.data)||void 0===t?void 0:t.detail)||"Something went wrong",duration:3e3})}u(!1)}},disabled:m||!c,className:"h-8",children:m?(0,re.jsx)(ku.A,{className:"h-4 w-4 animate-spin"}):"Save"}),(0,re.jsx)(Hs,{size:"sm",variant:"outline",onClick:()=>{o(!1),d(""),h(!1)},className:"h-8",children:"Cancel"})]})}):(0,re.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,re.jsxs)("div",{className:"flex gap-2",children:[!i&&(0,re.jsx)(Hs,{variant:"ghost",size:"sm",onClick:()=>{o(!0)},className:"text-blue-500 hover:text-blue-600 hover:bg-blue-50",children:(0,re.jsx)(Dp.A,{className:"h-4 w-4"})}),(0,re.jsx)(Hs,{variant:"ghost",size:"sm",onClick:async()=>{l(!0);try{await vs.deleteSecret(t,s),n({title:"Secret deleted",duration:3e3}),a()}catch(i){var e,r;n({variant:"destructive",title:"Error deleting secret",description:(null===(e=i.response)||void 0===e||null===(r=e.data)||void 0===r?void 0:r.detail)||"Something went wrong",duration:3e3})}l(!1)},className:"text-red-500 hover:text-red-600 hover:bg-red-50",disabled:r,children:(0,re.jsx)(_u.A,{className:"h-4 w-4 ".concat(r?"animate-spin":"")})})]})]})})})},Fp=e=>{let{onAdd:s,loading:t}=e;const[a,n]=(0,H.useState)(""),[r,l]=(0,H.useState)(""),[i,o]=(0,H.useState)(!1),[c,d]=(0,H.useState)(!1),m=a.includes(" "),u=m;return(0,re.jsxs)(Pa,{open:i,onOpenChange:o,children:[(0,re.jsx)(La,{asChild:!0,children:(0,re.jsxs)(Hs,{children:[(0,re.jsx)(Ss.A,{className:"h-4 w-4 mr-2"}),"Add Secret"]})}),(0,re.jsxs)(Ma,{children:[(0,re.jsxs)(Fa,{children:[(0,re.jsx)(Ua,{children:"Add New Secret"}),(0,re.jsx)(za,{children:"Enter your secret name and value below. Secrets are encrypted and securely stored."})]}),(0,re.jsxs)("div",{className:"space-y-4 pt-4",children:[(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsx)("label",{className:"text-sm font-medium",children:"Secret Name"}),(0,re.jsx)(ft,{placeholder:"Enter secret name (e.g. API_KEY)",value:a,onChange:e=>n(e.target.value),className:m?"border-red-500":""}),m&&(0,re.jsx)("p",{className:"text-sm text-red-500",children:"Secret name cannot contain spaces. Use underscores instead (e.g. API_KEY)."})]}),(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsx)("label",{className:"text-sm font-medium",children:"Secret Value"}),(0,re.jsxs)("div",{className:"relative",children:[(0,re.jsx)(ft,{type:c?"text":"password",placeholder:"Enter secret value",value:r,onChange:e=>l(e.target.value),className:"pr-10"}),(0,re.jsx)(Hs,{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,re.jsx)(Nx.A,{className:"h-4 w-4"}):(0,re.jsx)(oh.A,{className:"h-4 w-4"})})]})]}),(0,re.jsx)("div",{className:"flex justify-end",children:(0,re.jsx)(Hs,{onClick:async()=>{u||(await s(a,r),n(""),l(""),d(!1),o(!1))},disabled:t||!a||!r||u,children:t?(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(ku.A,{className:"h-4 w-4 mr-2 animate-spin"}),"Adding..."]}):"Add Secret"})})]})]})]})},Bp=e=>{let{app:s}=e;return(0,re.jsx)(it,{children:(0,re.jsx)(mt,{className:"p-4",children:(0,re.jsxs)("div",{className:"flex items-start gap-3",children:[(0,re.jsx)(rp.A,{className:"h-5 w-5 text-blue-500 shrink-0 mt-0.5"}),(0,re.jsxs)("div",{className:"space-y-2 text-sm",children:[(0,re.jsx)("p",{className:"font-medium",children:(0,re.jsx)("b",{children:"About Secrets Management"})}),(0,re.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,re.jsxs)("ul",{className:"list-disc list-inside space-y-1 text-gray-600",children:[(0,re.jsx)("li",{children:"Secrets are used by your backend functions to access external services"}),(0,re.jsx)("li",{children:"All secrets are encrypted and stored securely"}),(0,re.jsx)("li",{children:"You can add, update, or delete secrets as needed for your application"})]}),(0,re.jsxs)("p",{className:"text-xs text-gray-500",children:["Need help? Create a ticket at ",(0,re.jsx)("button",{type:"button",onClick:()=>{const e=null!=s&&s.id?"/support?appId=".concat(s.id):"/support";window.open(e,"_blank")},className:"underline text-primary hover:text-orange-500 transition-colors",children:"support system"})]})]})]})})})};function Up(){const{app:e,updateSecrets:s,existingSecretNames:t}=_s(),a=null==e?void 0:e.id,[n,r]=(0,H.useState)({}),[l,i]=(0,H.useState)(!1),{toast:o}=si(),c=((0,Z.Zp)(),async()=>{try{const e=await vs.getSecrets(a);r(e)}catch(t){var e,s;o({variant:"destructive",title:"Error fetching secrets",description:(null===(e=t.response)||void 0===e||null===(s=e.data)||void 0===s?void 0:s.detail)||"Something went wrong",duration:3e3})}});(0,H.useEffect)(()=>{c()},[a]);return(0,re.jsx)("div",{className:"space-y-6 p-6",children:(0,re.jsxs)("div",{children:[(0,re.jsxs)("div",{className:"flex items-center justify-between mb-6",children:[(0,re.jsx)("h2",{className:"text-2xl font-bold",children:"Application Secrets"}),(0,re.jsx)(Fp,{onAdd:async(e,t)=>{if(e&&t){i(!0);try{await s({[e]:t}),await c(),o({title:"Secret added successfully",duration:3e3})}catch(r){var a,n;o({variant:"destructive",title:"Error creating secret",description:(null===(a=r.response)||void 0===a||null===(n=a.data)||void 0===n?void 0:n.detail)||"Something went wrong",duration:3e3})}i(!1)}},loading:l})]}),(0,re.jsxs)("div",{className:"grid gap-6",children:[Object.keys(n).length>0?(0,re.jsxs)("div",{className:"space-y-4",children:[(0,re.jsxs)("h3",{className:"text-lg font-semibold text-green-600 flex items-center",children:[(0,re.jsx)(ti.A,{className:"h-5 w-5 mr-2"}),"Configured Secrets"]}),Object.keys(n).map(e=>(0,re.jsx)(Mp,{secretName:e,appId:a,onUpdate:c},e))]}):(0,re.jsx)("div",{className:"text-center py-8 text-gray-500",children:(0,re.jsx)("p",{children:"No secrets configured yet. Add your first secret to get started."})}),(0,re.jsx)(Bp,{app:e})]})]})})}var zp=t(69783);let qp=null;const Wp=function(e,s){class t extends zp.A{getMountPath(){return"/ws-user-apps/socket.io/"}getSocketQuery(){let t=super.getSocketQuery();return s&&(t.token=s),t.app_id=e,t}}return qp||(qp=new t),qp};var Vp=t(76976);let Yp=null;function Hp(e,s,t){class a extends X.y{constructor(){super(),this.socketManager=Wp(e,s),this.axios.interceptors.response.use(e=>e,e=>{var s,a;return t((null===(s=e.response)||void 0===s||null===(a=s.data)||void 0===a?void 0:a.message)||e.message),Promise.reject(e)})}getClient(){return s?(0,ae.Ay)(this.getBaseURL(),{Authorization:"Bearer ".concat(s)}):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,s){let t=null;return Yp&&Yp.id===e.id?t=Yp.messages:(Yp=e,t=e.messages),e.messages=[...t,s],this.socketManager.onUpdateModel({room:"/agent-conversations/".concat(e.id),data:JSON.stringify(e)}),this.axios.post("/conversations/".concat(e.id,"/messages"),s)}getWhatsAppConnectURL(t){const a="".concat("https://base44.app","/api/apps/").concat(e,"/agents/").concat(encodeURIComponent(t),"/whatsapp"),n=null!=s?s:Vp.A.getToken();return n?"".concat(a,"?token=").concat(n):a}subscribeToConversation(e,s){return this.socketManager.addListener("/agent-conversations/".concat(e),e=>{Yp&&Yp.id===e.id&&(Yp=e),s(e)})}}return new a}var Gp=t(32033),$p=t(21449);function Jp(e){var s,t,a,n,r,l;let{agent:i,color:o,onEdit:c,onStartChat:d,isSelected:m=!1,agentsSDK:u,onSaveWhatsAppGreeting:x,onToggleWhatsApp:h}=e;const p=(null===(s=i.tool_configs)||void 0===s||null===(t=s.filter(e=>e.entity_name))||void 0===t?void 0:t.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,re.jsx)("div",{className:is("group relative bg-white transition-all p-4 font-base44","rounded-[12px] border border-gray-100"),children:(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsxs)("div",{className:"flex items-start justify-between",children:[(0,re.jsxs)("div",{className:"flex items-start gap-3",children:[(0,re.jsx)("div",{className:is("h-10 w-10 flex items-center justify-center flex-shrink-0",(null==o?void 0:o.light)||"bg-slate-100"),children:(0,re.jsx)(fd.A,{className:is("h-5 w-5",(null==o?void 0:o.text)||"text-slate-500")})}),(0,re.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,re.jsx)("h3",{className:"font-semibold text-slate-900 text-base font-base44",children:i.name}),p>0&&(0,re.jsxs)("div",{className:"flex items-center gap-2 flex-wrap mt-1",children:[(0,re.jsxs)("div",{className:"flex items-center gap-1.5 text-xs text-slate-600 font-base44",children:[(0,re.jsx)(Zo.A,{className:"h-3 w-3"}),(0,re.jsx)("span",{children:"Entities:"})]}),(0,re.jsxs)("div",{className:"flex flex-wrap gap-1",children:[null===(r=i.tool_configs)||void 0===r?void 0:r.filter(e=>e.entity_name).slice(0,3).map((e,s)=>(0,re.jsx)(et,{variant:"secondary",className:"text-xs px-2 py-0 bg-slate-100 text-slate-600 border-0 font-base44",children:e.entity_name},s)),(null===(l=i.tool_configs)||void 0===l?void 0:l.filter(e=>e.entity_name).length)>3&&(0,re.jsxs)(et,{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,re.jsxs)("div",{className:"flex gap-2 ml-3",children:[(0,re.jsx)(Hs,{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,re.jsx)(Hs,{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,re.jsx)(Hs,{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,re.jsx)(Hs,{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,re.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,re.jsx)(Yr.A,{className:"h-3 w-3"}),(0,re.jsxs)("span",{children:[g," ",1===g?"function":"functions"]})]}),(0,re.jsx)("div",{className:"pl-[52px] sm:pl-[52px] pl-0",children:(0,re.jsx)("p",{className:"text-sm text-slate-600 line-clamp-2 font-base44",children:i.description||"No description provided"})})]})})}function Zp(e){try{const s=new Date(e);if(isNaN(s.getTime()))return"Recently";const t=new Date,a=Math.abs(t-s),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(s){return"Recently"}}function Kp(e){var s,t,a,n,r;let{conversation:l,agentColor:i,onSelect:o,isSelected:c}=e;const d=null===(s=l.messages)||void 0===s?void 0:s.slice(-1)[0],m=(null===(t=l.messages)||void 0===t?void 0:t.length)||0;return(0,re.jsx)("div",{className:is("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(l),children:(0,re.jsxs)("div",{className:"flex items-start gap-3",children:[(0,re.jsx)("div",{className:is("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,re.jsx)(fd.A,{className:is("h-4 w-4",(null==i?void 0:i.text)||"text-slate-500")})}),(0,re.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,re.jsxs)("div",{className:"flex items-center gap-2 mb-1",children:[(0,re.jsx)("span",{className:"text-sm font-medium text-slate-800",children:l.agent_name}),"whatsapp"===(null===(a=l.metadata)||void 0===a?void 0:a.channel)&&(0,re.jsxs)("div",{className:"flex items-center gap-1 px-1.5 py-0.5 bg-green-50 rounded",children:[(0,re.jsx)(bl.A,{className:"h-3 w-3 text-green-600"}),(0,re.jsx)("span",{className:"text-xs text-green-700 font-medium",children:"WhatsApp"})]}),(0,re.jsx)(et,{variant:"outline",className:"text-xs px-1.5 py-0 border-slate-300",children:m})]}),d&&(0,re.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,re.jsxs)("div",{className:"flex items-center gap-2 text-xs text-slate-400 mt-1",children:[(0,re.jsx)("span",{children:Zp(l.created_at)}),(null===(r=l.metadata)||void 0===r?void 0:r.phone_number)&&(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)("span",{children:"\u2022"}),(0,re.jsx)("span",{children:l.metadata.phone_number})]})]})]}),(0,re.jsx)(ln.A,{className:"h-4 w-4 text-slate-400 opacity-0 group-hover:opacity-100 transition-opacity"})]})})}var Xp=t(77737);const Qp=["inline","className","children"],eg=["children"],sg=e=>{let{toolCall:s}=e;const[t,a]=(0,H.useState)(!1),n=(null==s?void 0:s.name)||"Function",r=(null==s?void 0:s.status)||"pending",l=null==s?void 0:s.results,i=(()=>{if(!l)return null;try{return"string"==typeof l?JSON.parse(l):l}catch(e){return l}})(),o=l&&("string"==typeof l&&/error|failed/i.test(l)||!1===(null==i?void 0:i.success)),c={pending:{icon:Xp.A,color:"text-slate-400",text:"Pending"},running:{icon:Ze.A,color:"text-slate-500",text:"Running...",spin:!0},in_progress:{icon:Ze.A,color:"text-slate-500",text:"Running...",spin:!0},completed:o?{icon:Xe.A,color:"text-red-500",text:"Failed"}:{icon:nl.A,color:"text-green-600",text:"Success"},success:{icon:nl.A,color:"text-green-600",text:"Success"},failed:{icon:Xe.A,color:"text-red-500",text:"Failed"},error:{icon:Xe.A,color:"text-red-500",text:"Failed"}}[r]||{icon:ih.A,color:"text-slate-500",text:""},d=c.icon,m=n.split(".").reverse().join(" ").replace(/(?:^|\s)\S/g,e=>e.toUpperCase()).replace(/_/g," ");return(0,re.jsxs)("div",{className:"mt-2 text-xs",children:[(0,re.jsxs)("button",{onClick:()=>a(!t),className:is("flex items-center gap-2 px-3 py-1.5 rounded-lg border transition-all","hover:bg-slate-50",t?"bg-slate-50 border-slate-300":"bg-white border-slate-200"),children:[(0,re.jsx)(d,{className:is("h-3 w-3",c.color,c.spin&&"animate-spin")}),(0,re.jsx)("span",{className:"text-slate-700",children:m}),c.text&&(0,re.jsxs)("span",{className:is("text-slate-500",o&&"text-red-600"),children:["\u2022 ",c.text]}),!c.spin&&(s.arguments_string||l)&&(0,re.jsx)(ln.A,{className:is("h-3 w-3 text-slate-400 transition-transform ml-auto",t&&"rotate-90")})]}),t&&!c.spin&&(0,re.jsxs)("div",{className:"mt-1.5 ml-3 pl-3 border-l-2 border-slate-200 space-y-2",children:[s.arguments_string&&(0,re.jsxs)("div",{children:[(0,re.jsx)("div",{className:"text-xs text-slate-500 mb-1",children:"Parameters:"}),(0,re.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(s.arguments_string),null,2)}catch(e){return s.arguments_string}})()})]}),i&&(0,re.jsxs)("div",{children:[(0,re.jsx)("div",{className:"text-xs text-slate-500 mb-1",children:"Result:"}),(0,re.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 i?JSON.stringify(i,null,2):i})]})]})]})};function tg(e){var s;let{message:t}=e;const a="user"===t.role;return(0,re.jsxs)("div",{className:is("flex gap-3",a?"justify-end":"justify-start"),children:[!a&&(0,re.jsx)("div",{className:"h-7 w-7 rounded-lg bg-slate-100 flex items-center justify-center mt-0.5",children:(0,re.jsx)("div",{className:"h-1.5 w-1.5 rounded-full bg-slate-400"})}),(0,re.jsxs)("div",{className:is("max-w-[85%]",a&&"flex flex-col items-end"),children:[t.content&&(0,re.jsx)("div",{className:is("rounded-2xl px-4 py-2.5",a?"bg-slate-800 text-white":"bg-white border border-slate-200"),children:a?(0,re.jsx)("p",{className:"text-sm leading-relaxed",children:t.content}):(0,re.jsx)(el.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:s,className:t,children:a}=e,n=(0,as.A)(e,Qp);const r=/language-(\w+)/.exec(t||"");return!s&&r?(0,re.jsxs)("div",{className:"relative group/code",children:[(0,re.jsx)("pre",{className:"bg-slate-900 text-slate-100 rounded-lg p-3 overflow-x-auto my-2",children:(0,re.jsx)("code",(0,K.A)((0,K.A)({className:t},n),{},{children:a}))}),(0,re.jsx)(Hs,{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$/,"")),Gp.toast.success("Code copied")},children:(0,re.jsx)(Kr.A,{className:"h-3 w-3 text-slate-400"})})]}):(0,re.jsx)("code",{className:"px-1 py-0.5 rounded bg-slate-100 text-slate-700 text-xs",children:a})},a:e=>{let{children:s}=e,t=(0,as.A)(e,eg);return(0,re.jsx)("a",(0,K.A)((0,K.A)({},t),{},{target:"_blank",rel:"noopener noreferrer",children:s}))},p:e=>{let{children:s}=e;return(0,re.jsx)("p",{className:"my-1 leading-relaxed",children:s})},ul:e=>{let{children:s}=e;return(0,re.jsx)("ul",{className:"my-1 ml-4 list-disc",children:s})},ol:e=>{let{children:s}=e;return(0,re.jsx)("ol",{className:"my-1 ml-4 list-decimal",children:s})},li:e=>{let{children:s}=e;return(0,re.jsx)("li",{className:"my-0.5",children:s})},h1:e=>{let{children:s}=e;return(0,re.jsx)("h1",{className:"text-lg font-semibold my-2",children:s})},h2:e=>{let{children:s}=e;return(0,re.jsx)("h2",{className:"text-base font-semibold my-2",children:s})},h3:e=>{let{children:s}=e;return(0,re.jsx)("h3",{className:"text-sm font-semibold my-2",children:s})},blockquote:e=>{let{children:s}=e;return(0,re.jsx)("blockquote",{className:"border-l-2 border-slate-300 pl-3 my-2 text-slate-600",children:s})}},children:t.content})}),(null===(s=t.tool_calls)||void 0===s?void 0:s.length)>0&&(0,re.jsx)("div",{className:"space-y-1",children:t.tool_calls.map((e,s)=>(0,re.jsx)(sg,{toolCall:e},s))})]})]})}function ag(e){let{conversation:s,agentColor:t,agentsSDK:a,onBack:n}=e;const[r,l]=(0,H.useState)(""),[i,o]=(0,H.useState)(!1),c=(0,H.useRef)(null),d=(0,H.useRef)(null),m=s.messages||[];(0,H.useEffect)(()=>{var e;null===(e=d.current)||void 0===e||e.scrollIntoView({behavior:"smooth"})},[m]);const u=async()=>{if(!r.trim()||i)return;const e={id:Date.now().toString(),role:"user",content:r.trim()};l(""),o(!0);try{await a.addMessage(s,e)}catch(t){Gp.toast.error("Failed to send message")}finally{o(!1)}};return(0,re.jsxs)("div",{className:"flex flex-col h-full w-full bg-white font-base44",children:[(0,re.jsx)("div",{className:"border-b bg-white px-6 py-4",children:(0,re.jsxs)("div",{className:"flex items-center gap-3",children:[(0,re.jsx)(Hs,{variant:"ghost",size:"icon",onClick:n,className:"h-7 w-7",children:(0,re.jsx)(Qt.A,{className:"h-4 w-4"})}),(0,re.jsx)("div",{className:is("h-8 w-8 rounded-lg flex items-center justify-center",(null==t?void 0:t.light)||"bg-slate-100"),children:(0,re.jsx)(fd.A,{className:is("h-4 w-4",(null==t?void 0:t.text)||"text-slate-500")})}),(0,re.jsxs)("div",{className:"flex-1",children:[(0,re.jsx)("h3",{className:"font-semibold text-sm text-slate-900",children:s.agent_name}),(0,re.jsx)("p",{className:"text-xs text-slate-500",children:"Active conversation"})]})]})}),(0,re.jsx)(ld,{className:"flex-1 px-6 py-4",ref:c,children:(0,re.jsxs)("div",{className:"space-y-4",children:[0===m.length?(0,re.jsxs)("div",{className:"text-center py-8",children:[(0,re.jsx)("div",{className:"h-12 w-12 rounded-xl bg-slate-100 flex items-center justify-center mx-auto mb-3",children:(0,re.jsx)(bl.A,{className:"h-6 w-6 text-slate-400"})}),(0,re.jsx)("p",{className:"text-sm text-slate-500",children:"Start your conversation"}),(0,re.jsx)("p",{className:"text-xs text-slate-400 mt-1",children:"Type a message below to begin"})]}):m.map(e=>e?(0,re.jsx)(tg,{message:e},e.id):null),i&&(0,re.jsxs)("div",{className:"flex gap-3",children:[(0,re.jsx)("div",{className:"flex-shrink-0 mt-0.5",children:(0,re.jsx)(ox,{className:"h-7 w-7 rounded-lg"})}),(0,re.jsx)("div",{className:"bg-white border border-slate-200 rounded-2xl px-4 py-2.5",children:(0,re.jsx)(ox,{className:"h-4 w-32"})})]}),(0,re.jsx)("div",{ref:d})]})}),(0,re.jsx)("div",{className:"border-t bg-white px-6 py-4",children:(0,re.jsxs)("div",{className:"flex gap-2",children:[(0,re.jsx)(ft,{value:r,onChange:e=>l(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,re.jsx)(Hs,{onClick:u,disabled:i||!r.trim(),size:"sm",className:"bg-slate-800 hover:bg-slate-900 text-white",children:i?(0,re.jsx)(Ze.A,{className:"h-4 w-4 animate-spin"}):(0,re.jsx)(nu.A,{className:"h-4 w-4"})})]})})]})}const ng=e=>{let{className:s}=e;return(0,re.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 360 362",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:s,children:(0,re.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 rg(e){let{agent:s,agentColor:t,appId:a,onClose:n,onSave:r,agentsSDK:l}=e;const{app:i,addChatMessage:o}=_s(),[c,d]=(0,H.useState)(s.description||""),[m,u]=(0,H.useState)(s.instructions||""),[x,h]=(0,H.useState)(s.tool_configs||[]),[p,g]=(0,H.useState)(s.whatsapp_greeting||""),[f,v]=(0,H.useState)(!1),[b,j]=(0,H.useState)([]),[y,N]=(0,H.useState)([]),[w,_]=(0,H.useState)("guidelines");(0,H.useEffect)(()=>{const e=Object.keys((null==i?void 0:i.entities)||{});j(e);const s=Object.keys((null==i?void 0:i.functions)||{});N(s)},[i]);const k=()=>{const e=x.filter(e=>e.entity_name).map(e=>e.entity_name);return b.filter(s=>!e.includes(s))},A=()=>{const e=x.filter(e=>e.function_name).map(e=>e.function_name);return y.filter(s=>!e.includes(s))},S=()=>x.filter(e=>"entity_name"in e).lengthx.filter(e=>"function_name"in e).length{h(x.filter((s,t)=>t!==e))},I=(e,s)=>{const t=[...x];t[e]=(0,K.A)((0,K.A)({},t[e]),s),h(t)},T=["create","read","update","delete"],P=e=>"entity_name"in e;return(0,re.jsx)("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4 md:p-8",children:(0,re.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,re.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,re.jsx)("div",{className:"mb-4 md:mb-8",children:(0,re.jsxs)("div",{className:"flex items-center gap-3 mb-3",children:[(0,re.jsx)("div",{className:is("h-8 w-8 md:h-10 md:w-10 rounded-lg flex items-center justify-center",(null==t?void 0:t.light)||"bg-slate-100"),children:(0,re.jsx)(fd.A,{className:is("h-4 w-4 md:h-5 md:w-5",(null==t?void 0:t.text)||"text-slate-500")})}),(0,re.jsxs)("div",{children:[(0,re.jsx)("h2",{className:"text-base md:text-lg font-base44 font-semibold text-slate-900 truncate max-w-[150px]",children:s.name}),(0,re.jsx)("p",{className:"text-xs font-base44 text-slate-500",children:"Agent Configuration"})]})]})}),(0,re.jsxs)("nav",{className:"flex md:flex-col space-x-1 md:space-x-0 md:space-y-1",children:[(0,re.jsxs)("button",{onClick:()=>_("guidelines"),className:is("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,re.jsx)(al.A,{className:"inline-block w-4 h-4 mr-0 md:mr-2"}),(0,re.jsx)("span",{className:"block md:inline mt-1 md:mt-0 text-xs md:text-sm",children:"Guidelines"})]}),(0,re.jsxs)("button",{onClick:()=>_("tools"),className:is("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,re.jsx)(Tc.A,{className:"inline-block w-4 h-4 mr-0 md:mr-2"}),(0,re.jsx)("span",{className:"block md:inline mt-1 md:mt-0 text-xs md:text-sm",children:"Tools"})]}),(0,re.jsxs)("button",{onClick:()=>_("whatsapp"),className:is("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,re.jsx)(ng,{className:"inline-block w-4 h-4 mr-0 md:mr-2"}),(0,re.jsx)("span",{className:"block md:inline mt-1 md:mt-0 text-xs md:text-sm",children:"WhatsApp"})]})]})]}),(0,re.jsxs)("div",{className:"flex-1 flex flex-col min-h-0",children:[(0,re.jsxs)("div",{className:"px-4 md:px-8 py-4 border-b border-slate-200 flex items-center justify-between",children:[(0,re.jsx)("h3",{className:"text-base md:text-lg font-semibold text-slate-900 truncate",children:"guidelines"===w?"Guidelines":"Tools and Capabilities"}),(0,re.jsx)(Hs,{variant:"ghost",size:"icon",onClick:n,className:"h-8 w-8 flex-shrink-0",children:(0,re.jsx)(zs.A,{className:"h-4 w-4"})})]}),(0,re.jsx)("div",{className:"flex-1 overflow-y-auto px-4 md:px-8 py-4 md:py-6",children:"guidelines"===w?(0,re.jsxs)("div",{className:"space-y-6 max-w-4xl",children:[(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsx)(Nt,{htmlFor:"description",className:"text-sm font-base44 font-medium text-slate-700",children:"Description"}),(0,re.jsx)("p",{className:"text-xs font-base44 text-slate-500",children:"This is the system prompt that defines the agent's behavior"}),(0,re.jsx)(td,{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,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsx)(Nt,{htmlFor:"instructions",className:"text-sm font-base44 font-medium text-slate-700",children:"Instructions"}),(0,re.jsx)("p",{className:"text-xs font-base44 text-slate-500",children:"Specific guidelines and rules the agent should follow"}),(0,re.jsx)(td,{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,re.jsx)("div",{className:"space-y-6 max-w-4xl",children:(0,re.jsxs)("div",{className:"space-y-4",children:[(0,re.jsxs)("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3",children:[(0,re.jsxs)("div",{children:[(0,re.jsx)("h4",{className:"text-sm font-base44 font-medium text-slate-700",children:"Available Tools"}),(0,re.jsx)("p",{className:"text-xs font-base44 text-slate-500 mt-1",children:"Configure what tools and data this agent can access"})]}),(0,re.jsxs)(Pl,{children:[(0,re.jsx)(Ll,{asChild:!0,children:(0,re.jsxs)(Hs,{size:"sm",variant:"outline",className:"text-xs w-full sm:w-auto",disabled:!S()&&!C(),children:[(0,re.jsx)(Ss.A,{className:"h-3.5 w-3.5 mr-1 sm:hidden"}),"Add",(0,re.jsx)(It.A,{className:"h-3.5 w-3.5 ml-1"})]})}),(0,re.jsxs)(Ul,{align:"end",className:"w-72",children:[(0,re.jsxs)(zl,{onClick:()=>{h([...x,{entity_name:"",allowed_operations:[]}])},disabled:!S(),className:"cursor-pointer",children:[(0,re.jsx)(Zo.A,{className:"h-4 w-4 mr-2"}),(0,re.jsxs)("div",{className:"flex flex-col",children:[(0,re.jsx)("span",{className:"text-sm font-medium",children:S()?"Add Entity Tool":"All Entity Slots Used"}),(0,re.jsx)("span",{className:"text-xs text-slate-500",children:"Database operations and CRUD access"})]})]}),(0,re.jsxs)(zl,{onClick:()=>{h([...x,{function_name:"",description:""}])},disabled:!C(),className:"cursor-pointer",children:[(0,re.jsx)(Yr.A,{className:"h-4 w-4 mr-2"}),(0,re.jsxs)("div",{className:"flex flex-col",children:[(0,re.jsx)("span",{className:"text-sm font-medium",children:C()?"Add Backend Function":"All Function Slots Used"}),(0,re.jsx)("span",{className:"text-xs text-slate-500",children:"Custom backend logic and integrations"})]})]})]})]})]}),(0,re.jsx)("div",{className:"space-y-3",children:0===x.length?(0,re.jsxs)("div",{className:"text-center py-12 bg-slate-50 rounded-lg border border-slate-200 border-dashed",children:[(0,re.jsx)(Zo.A,{className:"h-8 w-8 text-slate-400 mx-auto mb-3"}),(0,re.jsx)("p",{className:"text-sm text-slate-500",children:"No tools configured"}),(0,re.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,s)=>{var t,a,n;return(0,re.jsx)("div",{className:"border rounded-lg p-4 bg-white border-slate-200",children:P(e)?(0,re.jsxs)("div",{className:"space-y-3",children:[(0,re.jsxs)("div",{className:"flex items-start justify-between",children:[(0,re.jsxs)("div",{className:"flex items-center gap-2",children:[(0,re.jsx)(Zo.A,{className:"h-4 w-4 text-teal-600"}),(0,re.jsx)("span",{className:"text-sm font-medium text-slate-700",children:"Entity Tool"})]}),(0,re.jsx)(Hs,{size:"icon",variant:"ghost",onClick:()=>E(s),className:"h-6 w-6 hover:bg-red-50",children:(0,re.jsx)(_u.A,{className:"h-3.5 w-3.5 text-red-500 hover:text-red-600"})})]}),(0,re.jsxs)(Ut,{value:e.entity_name||"",onValueChange:e=>I(s,{entity_name:e}),children:[(0,re.jsx)(Wt,{className:"w-full",children:(0,re.jsx)(qt,{placeholder:"Select entity"})}),(0,re.jsx)(Ht,{children:k().concat(e.entity_name?[e.entity_name]:[]).map(e=>(0,re.jsx)($t,{value:e,children:e},e))})]}),(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsxs)("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-2",children:[(0,re.jsx)("p",{className:"text-sm font-base44 font-thin text-black ",children:"Allowed operations"}),(0,re.jsx)("div",{className:"flex flex-wrap gap-2",children:T.map(t=>{var a,n;const r=(null===(a=e.allowed_operations)||void 0===a?void 0:a.includes("read"))||!1,l=("update"===t||"delete"===t)&&!r;return(0,re.jsxs)("label",{className:is("flex items-center gap-1.5 px-2 py-1 rounded-md",l?"cursor-not-allowed opacity-50":"cursor-pointer hover:bg-slate-50"),children:[(0,re.jsx)(ed,{checked:(null===(n=e.allowed_operations)||void 0===n?void 0:n.includes(t))||!1,onCheckedChange:()=>!l&&((e,s)=>{const t=x[e];if(!t.entity_name)return;const a=t.allowed_operations||[];let n;a.includes(s)?(n=a.filter(e=>e!==s),"read"===s&&(n=n.filter(e=>"update"!==e&&"delete"!==e))):n=[...a,s],I(e,{allowed_operations:n})})(s,t),disabled:l,className:"h-3.5 w-3.5"}),(0,re.jsx)("span",{className:is("text-xs font-base44 capitalize",l?"text-slate-400":"text-slate-600"),children:t})]},t)})})]}),(null===(t=e.allowed_operations)||void 0===t?void 0:t.includes("delete"))&&(0,re.jsxs)("div",{className:"flex items-center justify-end gap-2 mt-2",children:[(0,re.jsx)(Fu.A,{className:"h-3.5 w-3.5 text-amber-500 flex-shrink-0"}),(0,re.jsx)("p",{className:"text-xs font-base44 text-slate-600",children:"Careful, deleted data by the agent can't be restored"})]})]})]}):(0,re.jsxs)("div",{className:"space-y-3",children:[(0,re.jsxs)("div",{className:"flex items-start justify-between",children:[(0,re.jsxs)("div",{className:"flex items-center gap-2",children:[(0,re.jsx)(Yr.A,{className:"h-4 w-4 text-orange-600"}),(0,re.jsx)("span",{className:"text-sm font-medium text-slate-700",children:"Backend Function"})]}),(0,re.jsx)(Hs,{size:"icon",variant:"ghost",onClick:()=>E(s),className:"h-6 w-6 hover:bg-red-50",children:(0,re.jsx)(_u.A,{className:"h-3.5 w-3.5 text-red-500 hover:text-red-600"})})]}),(0,re.jsxs)(Ut,{value:e.function_name||"",onValueChange:t=>{var a;const n=null==i||null===(a=i.functions)||void 0===a?void 0:a[t];I(s,{function_name:t,description:(null==n?void 0:n.description)||e.description||""})},children:[(0,re.jsx)(Wt,{className:"w-full",children:(0,re.jsx)(qt,{placeholder:"Select backend function"})}),(0,re.jsx)(Ht,{children:A().concat(e.function_name?[e.function_name]:[]).map(e=>(0,re.jsx)($t,{value:e,children:e},e))})]}),e.function_name&&(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsx)(Nt,{htmlFor:"func-desc-".concat(s),className:"text-xs font-medium text-slate-600",children:"Function Description"}),(0,re.jsx)(td,{id:"func-desc-".concat(s),value:e.description||"",onChange:e=>I(s,{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,re.jsxs)("p",{className:"text-xs text-slate-400 italic mt-1",children:["Default: ",i.functions[e.function_name].description]})]})]})},s)})})]})}):(0,re.jsxs)("div",{className:"space-y-6 max-w-4xl",children:[(0,re.jsxs)("div",{className:"flex items-center justify-between pb-2",children:[(0,re.jsxs)("div",{className:"flex items-center gap-3",children:[(0,re.jsx)("div",{className:"p-2 bg-green-50 rounded-lg",children:(0,re.jsx)(ng,{className:"w-6 h-6 text-green-600"})}),(0,re.jsxs)("div",{children:[(0,re.jsx)("h3",{className:"text-lg font-semibold text-slate-900",children:"WhatsApp Integration"}),(0,re.jsx)("p",{className:"text-sm text-slate-500",children:"Connect your agent to WhatsApp for seamless communication"})]})]}),(0,re.jsx)(Hs,{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,re.jsxs)("a",{href:l.getWhatsAppConnectURL(s.name),target:"_blank",rel:"noopener noreferrer",children:[(0,re.jsx)(ng,{className:"w-5 h-5"}),(0,re.jsx)("span",{children:"Test Chat"})]})})]}),(0,re.jsx)(it,{className:"border-slate-200 bg-white",children:(0,re.jsx)(mt,{className:"p-5",children:(0,re.jsxs)("div",{className:"space-y-3",children:[(0,re.jsxs)("div",{children:[(0,re.jsx)("h4",{className:"text-sm font-semibold text-slate-900",children:"Add WhatsApp to Your App"}),(0,re.jsx)("p",{className:"text-xs text-slate-600 mt-1",children:"Enable WhatsApp access for your users with a single command"})]}),(0,re.jsx)("div",{className:"flex items-center gap-2",children:(0,re.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,re.jsxs)("code",{className:"text-sm text-slate-700 font-mono flex-1",children:["Add a WhatsApp button for the ",s.name||"agent"]}),(0,re.jsxs)(Hs,{onClick:()=>{const e="Add a WhatsApp button for the ".concat(s.name||"agent");sessionStorage.setItem("pendingChatMessage",e),window.dispatchEvent(new CustomEvent("pendingChatMessage",{detail:{message:e}})),n(),Gp.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,re.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,re.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13 7l5 5m0 0l-5 5m5-5H6"})})]})]})})]})})}),(0,re.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[(0,re.jsx)(it,{className:"border-slate-200 hover:border-slate-300 transition-colors",children:(0,re.jsx)(mt,{className:"p-4",children:(0,re.jsxs)("div",{className:"flex items-start gap-3",children:[(0,re.jsx)("div",{className:"p-1.5 bg-orange-50 rounded-lg flex-shrink-0",children:(0,re.jsx)("svg",{className:"w-5 h-5 text-orange-600",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,re.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,re.jsxs)("div",{children:[(0,re.jsx)("h4",{className:"text-sm font-medium text-slate-900",children:"Full Chat Capabilities"}),(0,re.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,re.jsx)(it,{className:"border-slate-200 hover:border-slate-300 transition-colors",children:(0,re.jsx)(mt,{className:"p-4",children:(0,re.jsxs)("div",{className:"flex items-start gap-3",children:[(0,re.jsx)("div",{className:"p-1.5 bg-teal-50 rounded-lg flex-shrink-0",children:(0,re.jsx)("svg",{className:"w-5 h-5 text-teal-600",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,re.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,re.jsxs)("div",{children:[(0,re.jsx)("h4",{className:"text-sm font-medium text-slate-900",children:"Voice & Media Support"}),(0,re.jsx)("p",{className:"text-xs text-slate-600 mt-1",children:"Users can send voice notes and images for natural interaction"})]})]})})}),(0,re.jsx)(it,{className:"border-slate-200 hover:border-slate-300 transition-colors",children:(0,re.jsx)(mt,{className:"p-4",children:(0,re.jsxs)("div",{className:"flex items-start gap-3",children:[(0,re.jsx)("div",{className:"p-1.5 bg-orange-50 rounded-lg flex-shrink-0",children:(0,re.jsx)("svg",{className:"w-5 h-5 text-orange-600",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,re.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,re.jsxs)("div",{children:[(0,re.jsxs)("h4",{className:"text-sm font-medium text-slate-900",children:["Custom Numbers ",(0,re.jsx)(et,{variant:"outline",className:"ml-2 text-xs",children:"Coming Soon"})]}),(0,re.jsx)("p",{className:"text-xs text-slate-600 mt-1",children:"Connect your own WhatsApp Business numbers"})]})]})})}),(0,re.jsx)(it,{className:"border-slate-200 hover:border-slate-300 transition-colors",children:(0,re.jsx)(mt,{className:"p-4",children:(0,re.jsxs)("div",{className:"flex items-start gap-3",children:[(0,re.jsx)("div",{className:"p-1.5 bg-teal-50 rounded-lg flex-shrink-0",children:(0,re.jsx)("svg",{className:"w-5 h-5 text-teal-600",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,re.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 20l4-16m4 4l4 4-4 4M6 16l-4-4 4-4"})})}),(0,re.jsxs)("div",{children:[(0,re.jsx)("h4",{className:"text-sm font-medium text-slate-900",children:"Easy UI Integration"}),(0,re.jsx)("p",{className:"text-xs text-slate-600 mt-1",children:"Add WhatsApp button to your app with a simple chat command"})]})]})})})]}),(0,re.jsxs)(it,{className:"border-slate-200",children:[(0,re.jsx)(ot,{className:"pb-4",children:(0,re.jsxs)("div",{className:"flex items-center gap-2",children:[(0,re.jsx)("svg",{className:"w-5 h-5 text-slate-600",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,re.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,re.jsx)(ct,{className:"text-base",children:"Welcome Message"})]})}),(0,re.jsxs)(mt,{className:"space-y-3",children:[(0,re.jsx)("p",{className:"text-sm text-slate-600",children:"Craft a warm greeting that introduces your agent and sets expectations"}),(0,re.jsxs)("div",{className:"relative",children:[(0,re.jsx)(td,{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,re.jsxs)("div",{className:"absolute top-2 right-2 text-xs text-slate-400",children:[p.length,"/500"]})]})]})]})]})}),(0,re.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,re.jsx)(Hs,{variant:"outline",onClick:n,className:"px-6 order-2 sm:order-1",children:"Cancel"}),(0,re.jsx)(Hs,{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||""});r&&await r((0,K.A)((0,K.A)({},s),{},{description:c,instructions:m,tool_configs:e,whatsapp_greeting:p})),n()}catch(e){Gp.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 lg=[{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 ig(e){if(!e)return lg[0];let s=0;for(let a=0;a{Gp.toast.error(e||"An error occurred")}),y=Object.entries(e.agents||{}).map(e=>{let[s,t]=e;return(0,K.A)((0,K.A)({},t),{},{key:s,name:s})});(0,H.useEffect)(()=>{const e=new URLSearchParams(r.search),s=e.get("agent"),t=e.get("conversation"),a=e.get("tab");t?(w(t),p("conversations")):s?(b(s),p("agents")):a&&p(a)},[r.search]),(0,H.useEffect)(()=>{N()},[]);const N=async()=>{x(!0);try{const e=await j.getConversations();c(e||[])}catch(e){Gp.toast.error("Failed to load conversations")}finally{x(!1)}},w=async e=>{try{const s=await j.getConversation(e);m(s),p("conversations")}catch(s){Gp.toast.error("Failed to load conversation")}},_=e=>{const s=new URLSearchParams(r.search);s.delete("agent"),s.delete("conversation"),s.delete("tab"),Object.entries(e).forEach(e=>{let[t,a]=e;a&&s.set(t,a)});const t=s.toString(),a=r.pathname+(t?"?".concat(t):"");n(a,{replace:!0})},k=async e=>{f(!0);try{const s=await j.createConversation({agent_name:e.name});c(e=>[s,...e]),m(s),p("conversations"),_({conversation:s.id,tab:"conversations"}),Gp.toast.success("Conversation started")}catch(s){Gp.toast.error("Failed to start conversation")}finally{f(!1)}},A=async e=>{try{const s=await j.getConversation(e.id);m(s),_({conversation:e.id,tab:"conversations"})}catch(s){Gp.toast.error("Failed to load conversation")}},S=e=>{i(e.name),_({agent:e.name,tab:"agents"})};(0,H.useEffect)(()=>{let e=null;if(d)return e=j.subscribeToConversation(d.id,e=>{m(s=>(0,K.A)((0,K.A)({},s),{},{messages:e.messages}))}),()=>{e&&e()}},[null==d?void 0:d.id]);const C=async()=>{try{await a({agents_enabled:!0}),Gp.toast.success("AI agents enabled successfully")}catch(e){Gp.toast.error("Failed to enable AI agents")}};return e.agents_enabled&&0!==y.length?d?(0,re.jsx)("div",{className:"h-full p-4 bg-slate-50",children:(0,re.jsx)(ag,{conversation:d,agentColor:ig(d.agent_name),agentsSDK:j,onBack:()=>{m(null),N(),_({tab:"conversations"})}})}):(0,re.jsxs)(su,{title:"AI Agents",subtitle:"Manage agents and conversations",children:[(0,re.jsx)("div",{className:"flex-1 overflow-hidden",children:0===y.length?(0,re.jsx)("div",{className:"h-full flex items-center pt-16",children:(0,re.jsx)(it,{className:"max-w-md w-full border-dashed mx-auto",children:(0,re.jsxs)(mt,{className:"flex flex-col items-center justify-center py-8",children:[(0,re.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,re.jsx)(fd.A,{className:"h-8 w-8 text-teal-600"})}),(0,re.jsx)("h3",{className:"text-base font-semibold text-slate-700 mb-2",children:"No Agents Yet"}),(0,re.jsx)("p",{className:"text-sm text-slate-500 text-center",children:"Prompt the chat to create your first AI agent"})]})})}):(0,re.jsxs)(hl,{value:h,onValueChange:e=>{p(e),_({tab:e})},className:"h-full flex flex-col",children:[(0,re.jsxs)(pl,{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,re.jsx)(gl,{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,re.jsxs)(gl,{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,re.jsx)(et,{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,re.jsxs)("div",{className:"flex-1 ",children:[(0,re.jsx)(fl,{value:"agents",className:"mt-4 h-full",children:g?(0,re.jsx)("div",{className:"grid grid-cols-1 gap-3 max-w-4xl",children:[...Array(3)].map((e,s)=>(0,re.jsxs)("div",{className:"bg-white border border-gray-100 rounded-[12px] p-4",children:[(0,re.jsxs)("div",{className:"flex items-start justify-between mb-2",children:[(0,re.jsxs)("div",{className:"flex items-start gap-3 flex-1",children:[(0,re.jsx)(ox,{className:"h-10 w-10 rounded-lg"}),(0,re.jsx)(ox,{className:"h-6 w-32"})]}),(0,re.jsxs)("div",{className:"flex gap-2",children:[(0,re.jsx)(ox,{className:"h-8 w-16"}),(0,re.jsx)(ox,{className:"h-8 w-16"})]})]}),(0,re.jsxs)("div",{className:"pl-[52px]",children:[(0,re.jsx)(ox,{className:"h-4 w-24 mb-2"}),(0,re.jsxs)("div",{className:"flex gap-1 mb-2",children:[(0,re.jsx)(ox,{className:"h-5 w-16"}),(0,re.jsx)(ox,{className:"h-5 w-20"})]}),(0,re.jsx)(ox,{className:"h-4 w-full"}),(0,re.jsx)(ox,{className:"h-4 w-3/4 mt-1"})]})]},s))}):(0,re.jsx)("div",{className:"grid grid-cols-1 gap-3 max-w-4xl",children:y.map((s,a)=>(0,re.jsx)("div",{onClick:()=>(e=>{b(e.name),_({agent:e.name,tab:"agents"})})(s),className:"cursor-pointer",children:(0,re.jsx)(Jp,{agent:s,color:ig(s.name),onEdit:S,onStartChat:k,isSelected:v===s.name,agentsSDK:j,onSaveWhatsAppGreeting:a=>(async(s,a)=>{const n=e.agents[s];if(!n)return;const r=(0,K.A)((0,K.A)({},n),{},{whatsapp_greeting:a});await t("agents/"+s,JSON.stringify(r,null,2))})(s.name,a),onToggleWhatsApp:(a,n)=>async function(s,a){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;const r=e.agents[s];if(!r)return;const l=(0,K.A)((0,K.A)({},r),{},{whatsapp_enabled:a});a&&n&&(l.whatsapp_greeting=n),await t("agents/"+s,JSON.stringify(l,null,2))}(s.name,a,n)})},s.key))})}),(0,re.jsx)(fl,{value:"conversations",className:"mt-4 h-full",children:u?(0,re.jsx)("div",{className:"grid grid-cols-1 gap-2 max-w-4xl",children:[...Array(4)].map((e,s)=>(0,re.jsx)("div",{className:"bg-white border border-gray-100 rounded-lg p-4",children:(0,re.jsxs)("div",{className:"flex items-start gap-3",children:[(0,re.jsx)(ox,{className:"h-8 w-8 rounded-lg"}),(0,re.jsxs)("div",{className:"flex-1",children:[(0,re.jsx)(ox,{className:"h-5 w-32 mb-1"}),(0,re.jsx)(ox,{className:"h-4 w-48 mb-2"}),(0,re.jsx)(ox,{className:"h-3 w-20"})]})]})},s))}):0===o.length?(0,re.jsx)(it,{className:"border-dashed max-w-4xl",children:(0,re.jsxs)(mt,{className:"py-8 text-center",children:[(0,re.jsx)($p.A,{className:"h-10 w-10 text-slate-300 mx-auto mb-3"}),(0,re.jsx)("p",{className:"text-sm text-slate-500",children:"No conversations yet"}),(0,re.jsx)("p",{className:"text-xs text-slate-400 mt-1",children:"Go to the Agents tab to start a conversation"})]})}):(0,re.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,re.jsx)(Kp,{conversation:e,agentColor:ig(e.agent_name),onSelect:A,isSelected:(null==d?void 0:d.id)===e.id},e.id))})})]})]})}),l&&(0,re.jsx)(rg,{agent:e.agents[l],agentColor:ig(l),appId:e.id,onClose:()=>{i(null),_({tab:"agents"})},onSave:async e=>{const s={description:e.description,instructions:e.instructions,tool_configs:e.tool_configs,whatsapp_greeting:e.whatsapp_greeting};await t("agents/"+l,JSON.stringify(s,null,2)),i(null),_({agent:l,tab:"agents"})},agentsSDK:j})]}):(0,re.jsx)("div",{className:"h-full bg-slate-50 flex flex-col items-center p-8",children:(0,re.jsxs)("div",{className:"flex-1 flex flex-col items-center pt-16",children:[(0,re.jsx)("div",{className:"text-center mb-8",children:(0,re.jsx)("h1",{className:"text-3xl font-base44 text-slate-700",children:"Set up Agents"})}),(0,re.jsx)("div",{className:"w-full max-w-3xl",children:(0,re.jsx)("div",{className:"relative flex items-center justify-center",children:(0,re.jsx)("div",{className:"w-full max-w-2xl",children:(0,re.jsxs)("div",{className:"space-y-16",children:[(0,re.jsx)("div",{className:"relative ".concat(e.agents_enabled?"opacity-60":""),children:(0,re.jsxs)("div",{className:"flex items-start gap-6",children:[(0,re.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,re.jsxs)("div",{className:"flex-1",children:[(0,re.jsx)("h3",{className:"text-xl font-base44 mb-1 ".concat(e.agents_enabled?"text-slate-600":"text-slate-900"),children:"Enable Agents"}),(0,re.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,re.jsx)("div",{className:"bg-white rounded-[16px] p-6 border border-slate-200 font-base44",children:(0,re.jsxs)("div",{className:"flex items-center justify-between",children:[(0,re.jsxs)("div",{children:[(0,re.jsxs)("div",{className:"flex items-center gap-2",children:[(0,re.jsx)("span",{className:"text-sm font-base44 text-slate-900",children:"AI Agents"}),(0,re.jsx)(et,{variant:"secondary",className:"text-xs bg-blue-100 text-blue-700 border-0 font-base44 font-thin",children:"Beta"})]}),(0,re.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,re.jsxs)("div",{className:"flex items-center gap-2",children:[(0,re.jsx)("span",{className:"text-xs font-base44 text-slate-500",children:"Enabled"}),(0,re.jsx)("button",{onClick:e.agents_enabled?void 0:C,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,re.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,re.jsx)("div",{className:"relative ".concat(e.agents_enabled?"":"opacity-50"),children:(0,re.jsxs)("div",{className:"flex items-start gap-6",children:[(0,re.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,re.jsxs)("div",{className:"flex-1",children:[(0,re.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,re.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 cg(){const{app:e}=_s(),{workspaceView:s}=(0,Z.g)(),t=(0,Z.Zp)(),[a,n]=(0,H.useState)(!1),[r,l]=(0,H.useState)(!1),[i,o]=(0,H.useState)(!1);(0,H.useEffect)(()=>{e&&e.id&&l(!0)},[e]),(0,H.useEffect)(()=>{const e=()=>{o(window.innerWidth<1024)};return e(),window.addEventListener("resize",e),()=>{window.removeEventListener("resize",e)}},[]);const c=s||"overview",d="code"===c,m=()=>{if(!r)return(0,re.jsx)("div",{className:"w-full h-full flex items-center justify-center",children:(0,re.jsxs)("div",{className:"text-center",children:[(0,re.jsx)("div",{className:"animate-spin h-8 w-8 border-4 border-blue-500 rounded-full border-t-transparent mx-auto mb-4"}),(0,re.jsx)("p",{className:"text-gray-500",children:"Loading app data..."})]})});if(d)return(0,re.jsx)(wh,{});let s;if("overview"===c)s=(0,re.jsx)(Tx,{appId:e.id});else if("analytics"===c)s=(0,re.jsx)(Zx,{appId:e.id});else if("domains"===c)s=(0,re.jsx)(ap,{appId:e.id,appName:e.name});else if("secrets"===c)s=(0,re.jsx)(Up,{appId:e.id});else if("security"===c)s=(0,re.jsx)(Rp,{appId:e.id});else if(c.startsWith("entity-")){const t=c.split("entity-")[1],a=e.entities[t];s=a?(0,re.jsx)(au,{entity:a}):null}else if("users"===c)s=(0,re.jsx)(iu,{appId:e.id});else if("app-settings"===c)s=(0,re.jsx)(hx,{});else if("api"===c)s=(0,re.jsx)(yx,{appId:e.id});else if("logs"===c)s=(0,re.jsx)(Ox,{appId:e.id});else if("authentication"===c)s=(0,re.jsx)(vx,{});else{if("agents"!==c)return(0,re.jsx)("div",{className:"p-6",children:"Unknown view"});s=(0,re.jsx)(og,{})}return(0,re.jsx)("div",{className:"h-full w-full overflow-auto",children:s})},u=s=>{t("/apps/".concat(e.id,"/editor/workspace/").concat(s))};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,re.jsx)("div",{className:"h-full w-full relative",children:m()}):i?(0,re.jsxs)("div",{className:"h-full w-full flex flex-col",children:[(0,re.jsxs)("div",{className:"w-full bg-white border-b p-2 flex items-center",children:[(0,re.jsx)("button",{className:"p-2 rounded-md hover:bg-gray-100 transition-colors",onClick:()=>n(!0),children:(0,re.jsx)(Rx.A,{size:20})}),(0,re.jsx)("div",{className:"ml-2 font-medium",children:"App Editor"})]}),(0,re.jsx)(Ld,{items:x,selected:c,onSelect:e=>{u(e),n(!1)},isOpen:a,onClose:()=>n(!1),title:"App Editor",showSearch:!1}),(0,re.jsx)("div",{className:"flex-1 overflow-auto",children:m()})]}):(0,re.jsx)("div",{className:"h-full w-full relative",children:(0,re.jsxs)(jh,{direction:"horizontal",children:[(0,re.jsx)(yh,{defaultSize:25,minSize:15,maxSize:30,className:"h-full overflow-hidden",children:(0,re.jsx)(Ld,{items:x,selected:c,onSelect:e=>{u(e),n(!1)},isOpen:a,onClose:()=>n(!1),title:"App Editor",showSearch:!1})}),(0,re.jsx)(Nh,{withHandle:!0,className:"group transition-opacity opacity-0 hover:opacity-100 focus:opacity-100"}),(0,re.jsx)(yh,{defaultSize:75,className:"flex-1 overflow-auto",children:m()})]})})}var dg=t(53980),mg=t(74874),ug=t(225),xg=t(14664),hg=t(81103),pg=t(72420),gg=t(4084),fg=t(41186);function vg(e){let{isOpen:s,onClose:t}=e;const{user:a}=oe(),{app:n}=_s(),[r,l]=(0,H.useState)(!1),[i,o]=(0,H.useState)(""),[c,d]=(0,H.useState)("update"),[m,u]=(0,H.useState)([]),[x,h]=(0,H.useState)(!1),[p,g]=(0,H.useState)(!1),[f,v]=(0,H.useState)(""),b=(0,H.useRef)(null),j=(0,H.useRef)(null),y=(0,H.useRef)(null),[N,w]=(0,H.useState)(null),[_,k]=(0,H.useState)((null==n?void 0:n.github_repo_url)||null),[A,S]=(0,H.useState)(""),[C,E]=(0,H.useState)(0),[I,T]=(0,H.useState)(!1),P=(null==a?void 0:a.subscription_tier)&&!["free","starter"].includes(a.subscription_tier);(0,H.useEffect)(()=>{"invite"===c&&y.current&&y.current.focus()},[c]),(0,H.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()-C,s=1e3;if(i.trim()===A)return void g(m.length>0);h(!0);const t=e{L(i),S(i.trim()),E(Date.now())},t)}else u([]),g(!1);return()=>{b.current&&clearTimeout(b.current)}},[i,null==n?void 0:n.id,A,C,m.length]);const L=async e=>{try{h(!0);const s=await gs.searchGithubUsers(n.id,e);u(s.users||[]),g(s.users&&s.users.length>0)}catch(s){}finally{h(!1)}};return(0,re.jsx)(Pa,{open:s,onOpenChange:t,children:(0,re.jsxs)(Ma,{className:"sm:max-w-[500px]",children:[(0,re.jsxs)(Fa,{children:[(0,re.jsxs)(Ua,{className:"flex items-center gap-2",children:[(0,re.jsx)(gg.A,{className:"h-5 w-5"}),"GitHub Integration"]}),(0,re.jsx)(za,{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",s="success"===N.type?"text-green-700":"error"===N.type?"text-red-700":"text-blue-700",t="success"===N.type?Px.A:"error"===N.type?Xe.A:null;return(0,re.jsxs)("div",{className:"flex items-center gap-2 p-3 my-3 rounded-md border ".concat(e),children:[t&&(0,re.jsx)(t,{className:"h-5 w-5 ".concat(s)}),(0,re.jsx)("p",{className:"text-sm ".concat(s),children:N.text})]})})(),P?_?(0,re.jsxs)("div",{className:"space-y-4 py-2",children:[(0,re.jsxs)("div",{className:"rounded-lg bg-muted p-3 mb-4",children:[(0,re.jsx)("p",{className:"text-sm font-medium mb-1",children:"Repository URL:"}),(0,re.jsx)("a",{href:_,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-blue-500 hover:underline break-all",children:_})]}),I&&(0,re.jsxs)("div",{className:"rounded-lg bg-blue-50 border border-blue-200 p-4 mb-4",children:[(0,re.jsx)("h3",{className:"text-sm font-medium text-blue-800 mb-1",children:"Important Next Step"}),(0,re.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,re.jsxs)(Hs,{variant:"outline",className:"mt-3 border-blue-300 hover:bg-blue-100 text-blue-800",onClick:()=>{o(a.github_username||""),d("invite")},children:[(0,re.jsx)(np.A,{className:"h-4 w-4 mr-2"}),"Invite Yourself as Collaborator",(0,re.jsx)(ha.A,{className:"h-4 w-4 ml-2"})]})]}),(0,re.jsxs)(hl,{defaultValue:"update",value:c,onValueChange:d,children:[(0,re.jsxs)(pl,{className:"grid w-full grid-cols-2",children:[(0,re.jsx)(gl,{value:"update",children:"Update Repository"}),(0,re.jsx)(gl,{value:"invite",children:"Invite Collaborator"})]}),(0,re.jsxs)(fl,{value:"update",className:"space-y-4 pt-4",children:[(0,re.jsx)("p",{className:"text-sm text-muted-foreground",children:"Push the latest changes from your app to the GitHub repository."}),(0,re.jsx)(Hs,{onClick:async()=>{try{l(!0),w({type:"loading",text:"Updating GitHub repository..."});const e=await gs.updateGithubRepo(n.id);e&&e.repository_url&&k(e.repository_url),w({type:"success",text:"Successfully updated GitHub repository"})}catch(i){var e,s,t,a,r;if(null!==(e=i.response)&&void 0!==e&&null!==(s=e.data)&&void 0!==s&&null!==(t=s.message)&&void 0!==t&&t.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===(r=a.data)||void 0===r?void 0:r.message)||i.message||"Unknown error")})}finally{l(!1)}},className:"w-full",disabled:r,children:r?"Updating...":"Update Repository"})]}),(0,re.jsxs)(fl,{value:"invite",className:"space-y-4 pt-4",children:[(0,re.jsxs)("p",{className:"text-sm text-muted-foreground",children:["Invite a collaborator to work on your GitHub repository.",!I&&(0,re.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,re.jsxs)("div",{className:"relative",children:[(0,re.jsxs)("div",{className:"flex space-x-2",children:[(0,re.jsxs)("div",{className:"relative flex-1",children:[(0,re.jsx)(ft,{ref:y,placeholder:"Enter GitHub username",value:i,onChange:e=>o(e.target.value),disabled:r,onFocus:()=>i.trim().length>=2&&!f&&g(!0)}),x&&(0,re.jsx)("div",{className:"absolute right-3 top-1/2 transform -translate-y-1/2",children:(0,re.jsx)(vn.A,{className:"h-4 w-4 animate-pulse text-muted-foreground"})})]}),(0,re.jsx)(Hs,{onClick:async()=>{if(i.trim())try{l(!0),w({type:"loading",text:"Inviting ".concat(i,"...")}),await gs.inviteCollaborator(n.id,i),w({type:"success",text:"Successfully invited ".concat(i," as a collaborator")}),o(""),T(!1)}catch(t){var e,s;w({type:"error",text:"Failed to invite collaborator: "+((null===(e=t.response)||void 0===e||null===(s=e.data)||void 0===s?void 0:s.message)||t.message||"Unknown error")})}finally{l(!1)}else w({type:"error",text:"Please enter a GitHub username"})},disabled:r||!i.trim()||f,children:r?"Inviting...":"Invite"})]}),f&&(0,re.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,re.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,re.jsx)("div",{className:"p-2 text-sm text-muted-foreground",children:"No users found"}):(0,re.jsx)("ul",{children:m.map(e=>(0,re.jsxs)("li",{className:"flex items-center gap-2 p-2 hover:bg-accent cursor-pointer",onClick:()=>{return s=e.username,o(s),void g(!1);var s},children:[(0,re.jsx)("img",{src:e.avatar_url,alt:e.username,className:"w-8 h-8 rounded-full"}),(0,re.jsxs)("div",{children:[(0,re.jsx)("div",{className:"text-sm font-medium",children:e.username}),e.name&&(0,re.jsx)("div",{className:"text-xs text-muted-foreground",children:e.name})]})]},e.username))})})]})]})]})]}):(0,re.jsxs)("div",{className:"space-y-4 py-4",children:[(0,re.jsxs)("div",{className:"rounded-lg bg-muted p-4",children:[(0,re.jsx)("p",{className:"text-sm text-muted-foreground",children:"Export your app to GitHub to enable version control, collaboration, and easier deployment."}),(0,re.jsxs)("p",{className:"text-sm text-muted-foreground mt-2",children:[(0,re.jsx)("strong",{children:"Important:"})," After exporting, you'll need to invite yourself as a collaborator to access the repository directly."]})]}),(0,re.jsx)(Hs,{onClick:async()=>{try{l(!0),w({type:"loading",text:"Exporting to GitHub..."});const e=await gs.exportToGithub(n.id);k(e.repository_url),w({type:"success",text:"Successfully exported to GitHub"}),T(!0),d("invite")}catch(t){var e,s;w({type:"error",text:"Failed to export to GitHub: "+((null===(e=t.response)||void 0===e||null===(s=e.data)||void 0===s?void 0:s.message)||t.message||"Unknown error")})}finally{l(!1)}},className:"w-full",disabled:r,children:r?"Exporting...":"Export to GitHub"})]}):(0,re.jsx)("div",{className:"space-y-4 py-4",children:(0,re.jsxs)("div",{className:"rounded-lg bg-amber-50 border border-amber-200 p-4",children:[(0,re.jsx)("h3",{className:"text-sm font-medium text-amber-800 mb-1",children:"Upgrade Required"}),(0,re.jsx)("p",{className:"text-sm text-amber-700",children:"GitHub integration is only available on Builder, Pro, Elite and Enterprise plans."}),(0,re.jsx)(J.Link,{to:"/billing",children:(0,re.jsx)(Hs,{variant:"outline",className:"mt-3 border-amber-300 hover:bg-amber-100 text-amber-800",children:"Upgrade Your Plan"})})]})}),(0,re.jsx)(Ba,{children:(0,re.jsx)(Hs,{variant:"outline",onClick:t,children:"Close"})})]})})}function bg(e){let{isOpen:s,onClose:t}=e;const{user:a}=oe(),{app:n}=_s(),[r,l]=(0,H.useState)(!1),[i,o]=(0,H.useState)(null),c=(null==a?void 0:a.subscription_tier)&&!["free","starter","starter_yearly"].includes(a.subscription_tier);return(0,re.jsx)(Pa,{open:s,onOpenChange:t,children:(0,re.jsxs)(Ma,{className:"sm:max-w-[500px]",children:[(0,re.jsxs)(Fa,{children:[(0,re.jsxs)(Ua,{className:"flex items-center gap-2",children:[(0,re.jsx)(fg.A,{className:"h-5 w-5"}),"Export to ZIP"]}),(0,re.jsx)(za,{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",s="success"===i.type?"text-green-700":"error"===i.type?"text-red-700":"text-blue-700",t="success"===i.type?Px.A:"error"===i.type?Xe.A:null;return(0,re.jsxs)("div",{className:"flex items-center gap-2 p-3 my-3 rounded-md border ".concat(e),children:[t&&(0,re.jsx)(t,{className:"h-5 w-5 ".concat(s)}),(0,re.jsx)("p",{className:"text-sm ".concat(s),children:i.text})]})})(),c?(0,re.jsxs)("div",{className:"space-y-4 py-4",children:[(0,re.jsxs)("div",{className:"rounded-lg bg-muted p-4",children:[(0,re.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,re.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,re.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 l(!1)),children:(0,re.jsx)(Hs,{className:"w-full",disabled:r,onClick:()=>{l(!0),o({type:"loading",text:"Initiating download..."}),setTimeout(()=>{l(!1),o({type:"success",text:"Download initiated. Check your downloads folder."})},1e3)},children:r?"Preparing Download...":"Download ZIP"})}):(0,re.jsx)(Hs,{className:"w-full",disabled:!0,children:"Unable to generate download link"})]}):(0,re.jsx)("div",{className:"space-y-4 py-4",children:(0,re.jsxs)("div",{className:"rounded-lg bg-amber-50 border border-amber-200 p-4",children:[(0,re.jsx)("h3",{className:"text-sm font-medium text-amber-800 mb-1",children:"Upgrade Required"}),(0,re.jsx)("p",{className:"text-sm text-amber-700",children:"ZIP file export is only available on Builder, Pro, Elite and Enterprise plans."}),(0,re.jsx)(J.Link,{to:"/billing",children:(0,re.jsx)(Hs,{variant:"outline",className:"mt-3 border-amber-300 hover:bg-amber-100 text-amber-800",children:"Upgrade Your Plan"})})]})}),(0,re.jsx)(Ba,{children:(0,re.jsx)(Hs,{variant:"outline",onClick:t,children:"Close"})})]})})}function jg(e){let{showFiles:s}=e;const{app:t,currentPage:a}=_s(),[n,r]=(0,H.useState)(!1),[l,i]=(0,H.useState)(null),[o,c]=(0,H.useState)(!1),[d,m]=(0,H.useState)(!1);let u=[];if(s&&a){const{name:e,code:s}=a;if(t.layout){u.push("layout");const e=yg(t,t.layout);u=[...u,...e.map(e=>"components/"+e)]}u.push("pages/"+e);const n=yg(t,s);u=[...u,...n.map(e=>"components/"+e)],u=[...new Set(u)]}const x=e=>{r(!1),setTimeout(()=>{i(e),r(!0)},150)};return(0,re.jsxs)(re.Fragment,{children:[(0,re.jsxs)(Pl,{children:[(0,re.jsx)(Ll,{asChild:!0,children:(0,re.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,re.jsx)(dh.A,{size:20,className:"text-gray-600"})})}),(0,re.jsxs)(Ul,{align:"end",className:"w-64 border border-gray-200 shadow-lg rounded-lg animate-in fade-in-80",children:[s&&(0,re.jsxs)(re.Fragment,{children:[(0,re.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,re.jsx)("div",{className:"max-h-[250px] overflow-y-auto",children:u.map((e,s)=>{const t=e.split("/"),a="layout"===e;let n=t[t.length-1],r=t.slice(0,-1).join("/");return a&&(n="layout",r="Application Layout"),(0,re.jsxs)(zl,{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,re.jsxs)("span",{className:"font-medium",children:[n,".jsx"]}),r&&(0,re.jsx)("span",{className:"text-gray-400 text-[10px] mt-0.5",children:r})]},s)})}),(0,re.jsx)(Yl,{className:"my-1 bg-gray-200"})]}),(0,re.jsx)(zl,{asChild:!0,children:(0,re.jsxs)(J.Link,{to:"/apps/".concat(t.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,re.jsx)(pg.A,{className:"mr-2 h-4 w-4 text-gray-600"}),"See all files"]})}),(0,re.jsx)(Yl,{className:"my-1 bg-gray-200"}),(0,re.jsx)("div",{className:"px-3 py-1 text-[10px] text-gray-500 bg-gray-50 rounded mx-1",children:"BETA FEATURES"}),(0,re.jsxs)(zl,{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,re.jsx)(gg.A,{className:"mr-2 h-4 w-4 text-gray-600"}),"Export project to GitHub"]}),(0,re.jsxs)(zl,{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,re.jsx)(fg.A,{className:"mr-2 h-4 w-4 text-gray-600"}),"Export project as ZIP"]})]})]}),n&&(0,re.jsxs)("div",{className:"fixed inset-0 z-50",children:[(0,re.jsx)("div",{className:"absolute inset-0 bg-black/50",onClick:()=>r(!1)}),(0,re.jsxs)("div",{className:"absolute right-0 h-full w-3/4 bg-white dark:bg-gray-900 shadow-xl flex flex-col",children:[(0,re.jsxs)("div",{className:"flex justify-between items-center p-4 border-b flex-shrink-0",children:[(0,re.jsxs)("h3",{className:"text-lg font-semibold",children:["Code Editor - ",l]}),(0,re.jsx)(Hs,{variant:"ghost",size:"sm",onClick:()=>r(!1),children:"\u2715"})]}),(0,re.jsx)("div",{className:"flex-1 min-h-0",children:(0,re.jsx)(rh,{filepath:l,onSaveOrDiscard:()=>x(l)})})]})]}),(0,re.jsx)(vg,{isOpen:o,onClose:()=>c(!1)}),(0,re.jsx)(bg,{isOpen:d,onClose:()=>m(!1)})]})}function yg(e,s){if(!e||!s)return[];const t=Object.keys(e.components||{});if(0===t.length)return[];const a=new Set;const n=function s(n){let r=[];const l=n.split("\n");for(const i of l)if(i.includes("/components/")){const n=i.split("/components/")[1];if(n){const l=n.match(/^([a-zA-Z0-9_/-]+)/);if(l&&l[1]){const n=l[1].trim();if(t.includes(n)&&!a.has(n)){r.push(n),a.add(n);const t=s(e.components[n]);r=[...r,...t]}else{const l=n.split("/").pop();if(t.includes(l)&&!a.has(l)){r.push(l),a.add(l);const t=s(e.components[l]);r=[...r,...t]}}}}}return r}(s);return[...new Set(n)]}var Ng=t(58406);const wg=(0,H.createContext)();function _g(){const e=(0,H.useContext)(wg);if(void 0===e)throw new Error("useActivity must be used within an ActivityProvider");return e}const kg=function(e){let{children:s}=e;const[t,a]=(0,H.useState)({}),[n,r]=(0,H.useState)(0);(0,H.useEffect)(()=>{const e=e=>{const{type:s,requestId:t,logId:n,data:l}=e.data||{};if("api-request-start"===s)a(e=>(0,K.A)((0,K.A)({},e),{},{[t]:{id:t,type:"request",url:l.url,method:l.method,headers:l.headers,body:l.body,startTime:new Date,status:"pending"}})),r(e=>e+1);else if("api-request-end"===s)a(e=>{const s=e[t];return s?(0,K.A)((0,K.A)({},e),{},{[t]:(0,K.A)((0,K.A)({},s),{},{status:"completed",statusCode:l.statusCode,response:l.response,endTime:new Date,duration:s.startTime?new Date-s.startTime:0})}):e}),r(e=>Math.max(0,e-1));else if("console-log"===s){const e=new Date;a(s=>(0,K.A)((0,K.A)({},s),{},{[n]:{id:n,type:"log",message:l.message,severity:l.severity,component:l.component,timestamp:e}}))}};return window.addEventListener("message",e),()=>{window.removeEventListener("message",e)}},[]);const l=Object.values(t);return(0,re.jsx)(wg.Provider,{value:{allActivities:l,activeRequests:n,clearActivities:()=>a({})},children:s})},Ag=_g;var Sg=t(52245);function Cg(e){let{onClose:s}=e;const{allActivities:t,clearActivities:a}=_g(),[n,r]=(0,H.useState)("all"),[l,i]=(0,H.useState)("all"),[o,c]=(0,H.useState)(""),[d,m]=(0,H.useState)(!1),u=(0,H.useRef)(null),x=(0,H.useRef)(null),h=[{value:"all",label:"All",count:t.length},{value:"requests",label:"Requests",count:t.filter(e=>"request"===e.type).length},{value:"logs",label:"Logs",count:t.filter(e=>"log"===e.type).length}].filter(e=>e.count>0),p=t.filter(e=>{if(!((e,s)=>{if(!s.trim())return!0;const t=s.toLowerCase();if("log"===e.type){var a,n;const s=(null===(a=e.message)||void 0===a?void 0:a.toString().toLowerCase())||"",r=(null===(n=e.component)||void 0===n?void 0:n.toLowerCase())||"";return s.includes(t)||r.includes(t)}if("request"===e.type){var r;const s=(null===(r=e.url)||void 0===r?void 0:r.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 s.includes(t)||a.includes(t)||n.includes(t)}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"!==l){const s=parseInt(l);return"request"===e.type&&"completed"===e.status&&e.statusCode===s}return!0}),g=[...p].sort((e,s)=>{const t="request"===e.type?e.startTime:e.timestamp,a="request"===s.type?s.startTime:s.timestamp;return new Date(t)-new Date(a)}),f=(()=>{if("requests"!==n)return[];const e=new Set;t.forEach(s=>{"request"===s.type&&"completed"===s.status&&s.statusCode&&e.add(s.statusCode)});const s=[{value:"all",label:"All",count:t.filter(e=>"request"===e.type).length}];return Array.from(e).sort((e,s)=>e-s).forEach(e=>{const a=t.filter(s=>"request"===s.type&&"completed"===s.status&&s.statusCode===e).length;s.push({value:e.toString(),label:"".concat(e),count:a,statusCode:e})}),s.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,re.jsx)(Px.A,{className:"h-3 w-3"}):e>=300&&e<400?(0,re.jsx)(jo.A,{className:"h-3 w-3"}):e>=400&&e<500?(0,re.jsx)(Fu.A,{className:"h-3 w-3"}):e>=500?(0,re.jsx)(Dx.A,{className:"h-3 w-3"}):(0,re.jsx)(jo.A,{className:"h-3 w-3"}),j=()=>{m(!0),setTimeout(()=>{u.current&&u.current.focus()},100)};(0,H.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,H.useEffect)(()=>{const e=e=>{if(d&&x.current&&!x.current.contains(e.target)){const s=e.target.closest('[role="combobox"]')||e.target.closest("[data-radix-collection-item]")||e.target.closest("button");o.trim()||s||m(!1)}};return d&&document.addEventListener("mousedown",e),()=>{document.removeEventListener("mousedown",e)}},[d,o]);const N=t.filter(e=>"request"===e.type).length,w=t.filter(e=>"log"===e.type).length;return(0,re.jsxs)("div",{className:"flex flex-col h-full bg-white shadow-lg rounded-lg relative",children:[(0,re.jsxs)("div",{className:"flex justify-between items-center py-3 px-4 border-b",children:[(0,re.jsxs)("div",{className:"flex items-center gap-2",children:[(0,re.jsx)("h2",{className:"font-semibold",children:"Activity Monitor"}),(0,re.jsx)("div",{className:"text-xs text-muted-foreground",children:t.length>0&&(0,re.jsxs)(et,{variant:"outline",className:"font-normal bg-slate-50",children:[t.length," entries"]})})]}),(0,re.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,re.jsxs)(Ut,{value:n,onValueChange:e=>{r(e),"requests"!==e&&i("all")},children:[(0,re.jsxs)(Wt,{className:"h-8 w-auto min-w-[90px] bg-white border-slate-200",children:[(0,re.jsx)(Sg.A,{className:"h-3.5 w-3.5 mr-1.5 text-slate-500"}),(0,re.jsx)(qt,{})]}),(0,re.jsx)(Ht,{className:"bg-white border-slate-200",children:h.map(e=>(0,re.jsx)($t,{value:e.value,className:"hover:bg-slate-50",children:(0,re.jsxs)("div",{className:"flex items-center justify-between w-full",children:[(0,re.jsx)("span",{children:e.label}),(0,re.jsx)("span",{className:"text-xs text-slate-400 ml-2",children:e.count})]})},e.value))})]}),"requests"===n&&f.length>1&&(0,re.jsxs)(Ut,{value:l,onValueChange:i,children:[(0,re.jsx)(Wt,{className:"h-8 w-auto min-w-[70px] bg-white border-slate-200",children:(0,re.jsx)(qt,{})}),(0,re.jsx)(Ht,{className:"bg-white border-slate-200",children:f.map(e=>(0,re.jsx)($t,{value:e.value,className:"hover:bg-slate-50",children:(0,re.jsxs)("div",{className:"flex items-center justify-between w-full",children:[(0,re.jsx)("span",{className:"flex items-center gap-1",children:e.statusCode?(0,re.jsxs)(re.Fragment,{children:[b(e.statusCode),(0,re.jsx)(et,{variant:"outline",className:is("text-xs px-1 py-0.5",v(e.statusCode)),children:e.label})]}):e.label}),(0,re.jsx)("span",{className:"text-xs text-slate-400 ml-1.5",children:e.count})]})},e.value))})]}),(0,re.jsx)(Hs,{variant:"outline",size:"sm",onClick:()=>{a(),c(""),r("all"),i("all"),m(!1)},className:"h-8",children:(0,re.jsx)(_u.A,{className:"h-3.5 w-3.5"})}),s&&(0,re.jsx)(Hs,{variant:"ghost",size:"sm",onClick:s,className:"h-8 w-8 p-0",children:(0,re.jsx)(zs.A,{className:"h-4 w-4"})})]})]}),(d||o.trim())&&(0,re.jsx)("div",{ref:x,className:"border-b border-slate-200 px-4 py-2",children:d?(0,re.jsxs)("div",{className:"relative animate-in slide-in-from-top-2 duration-200",children:[(0,re.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,re.jsx)(ft,{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,re.jsx)(Hs,{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,re.jsx)(zs.A,{className:"h-3 w-3"})})]}):(0,re.jsxs)(Hs,{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,re.jsx)(vn.A,{className:"h-3.5 w-3.5"}),(0,re.jsxs)("span",{className:"text-sm",children:['Search: "',o.length>30?o.substring(0,30)+"...":o,'"']})]})}),t.length>0&&(0,re.jsxs)("div",{className:"flex justify-between items-center text-xs border-b px-4 py-1 bg-slate-50",children:[(0,re.jsxs)("div",{className:"flex items-center gap-3",children:[!d&&!o.trim()&&(0,re.jsx)(Hs,{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,re.jsx)(vn.A,{className:"h-3 w-3"})}),(0,re.jsxs)("span",{children:[N," requests"]}),(0,re.jsxs)("span",{children:[w," logs"]})]}),(o.trim()||"all"!==n||"all"!==l)&&(0,re.jsxs)("div",{className:"text-slate-500",children:["Showing ",p.length," of ",t.length]})]}),0===t.length&&!d&&!o.trim()&&(0,re.jsx)("div",{className:"px-4 py-1 border-b border-slate-200",children:(0,re.jsx)(Hs,{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,re.jsx)(vn.A,{className:"h-3 w-3"})})}),(0,re.jsx)(ld,{className:"flex-grow",children:0===g.length?(0,re.jsxs)("div",{className:"flex flex-col items-center justify-center h-full text-muted-foreground p-8",children:[(0,re.jsx)("p",{className:"text-sm",children:0===t.length?"No activities logged":o.trim()?"No ".concat("all"===n?"activities":n,' found matching "').concat(o,'"'):"No matching activities found"}),o.trim()&&(0,re.jsx)("p",{className:"text-xs mt-2 text-slate-400",children:"Try a different search term or clear filters"})]}):(0,re.jsx)("div",{className:"p-2 space-y-1",children:[...g].reverse().map(e=>"request"===e.type?(0,re.jsx)(Ig,{request:e},e.id):(0,re.jsx)(Eg,{log:e},e.id))})})]})}function Eg(e){var s,t,a;let{log:n}=e;const{icon:r,className:l}=(e=>{switch(e){case"error":return{icon:(0,re.jsx)(Dx.A,{className:"h-3.5 w-3.5"}),className:"bg-rose-50 text-rose-700"};case"warn":return{icon:(0,re.jsx)(Fu.A,{className:"h-3.5 w-3.5"}),className:"bg-amber-50 text-amber-700"};default:return{icon:(0,re.jsx)(jo.A,{className:"h-3.5 w-3.5"}),className:"bg-slate-50 text-slate-700"}}})(n.severity),i=e=>e?la()(e).fromNow():"";return(0,re.jsxs)(Ad,{className:"border rounded overflow-hidden hover:shadow-sm transition-all duration-200",children:[(0,re.jsxs)(Sd,{className:"flex w-full p-2 hover:bg-accent/5 text-left",children:[(0,re.jsx)("div",{className:"flex-shrink-0 w-16 flex justify-center",children:(0,re.jsxs)(et,{variant:"outline",className:"bg-purple-50 text-purple-700 font-mono text-xs uppercase",children:[(0,re.jsx)(dh.A,{className:"h-3 w-3 mr-1"})," Log"]})}),(0,re.jsxs)("div",{className:"flex-grow mx-3",children:[n.component&&(0,re.jsx)("div",{className:"text-xs text-muted-foreground mb-0.5 font-medium",children:n.component}),(0,re.jsxs)("div",{className:"text-sm font-normal truncate",children:[null===(s=n.message)||void 0===s?void 0:s.toString().substring(0,60),(null===(t=n.message)||void 0===t?void 0:t.toString().length)>60?"...":""]})]}),(0,re.jsxs)("div",{className:"flex items-center gap-2 shrink-0",children:[(0,re.jsx)("div",{className:"text-xs text-muted-foreground text-right",children:i(n.timestamp)}),(0,re.jsx)(et,{variant:"outline",className:is("flex items-center",l),children:r}),(0,re.jsx)(It.A,{className:"h-3.5 w-3.5 text-muted-foreground"})]})]}),(0,re.jsx)(Cd,{children:(0,re.jsx)("div",{className:"p-4 border-t bg-slate-50/50",children:(0,re.jsxs)("div",{className:"space-y-3",children:[(0,re.jsxs)("div",{children:[(0,re.jsx)("p",{className:"text-sm font-medium",children:"Message"}),(0,re.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,re.jsxs)("div",{className:"grid grid-cols-2 gap-3",children:[(0,re.jsxs)("div",{children:[(0,re.jsx)("p",{className:"text-sm font-medium",children:"Severity"}),(0,re.jsx)("p",{className:"text-sm text-muted-foreground",children:n.severity})]}),n.component&&(0,re.jsxs)("div",{children:[(0,re.jsx)("p",{className:"text-sm font-medium",children:"Component"}),(0,re.jsx)("p",{className:"text-sm text-muted-foreground",children:n.component})]}),(0,re.jsxs)("div",{children:[(0,re.jsx)("p",{className:"text-sm font-medium",children:"Time"}),(0,re.jsx)("p",{className:"text-sm text-muted-foreground",children:i(n.timestamp)})]})]})]})})})]})}function Ig(e){var s;let{request:t}=e;const{app:a}=_s(),n=e=>e?la()(e).fromNow():"";return(0,re.jsxs)(Ad,{className:"border rounded overflow-hidden hover:shadow-sm transition-all duration-200",children:[(0,re.jsxs)(Sd,{className:"flex w-full p-2 hover:bg-accent/5 text-left",children:[(0,re.jsx)("div",{className:"flex-shrink-0 w-16 flex justify-center",children:(0,re.jsx)(et,{variant:"outline",className:is("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"}})(t.method)),children:null===(s=t.method)||void 0===s?void 0:s.toLowerCase()})}),(0,re.jsx)("div",{className:"flex-grow mx-3",children:(0,re.jsx)("div",{className:"text-sm font-normal truncate",children:(e=>{let s=e;return e.startsWith("http")&&(s=new URL(e).pathname),s.startsWith("/api/apps/"+(null==a?void 0:a.id))&&(s=s.replace("/api/apps/"+a.id,"")),null!=a&&a.id&&s.includes(a.id)&&(s=s.replace(a.id,"{app_id}")),s})(t.url)})}),(0,re.jsxs)("div",{className:"flex items-center gap-2 shrink-0",children:[(0,re.jsx)("div",{className:"text-xs text-muted-foreground text-right",children:n(t.startTime)}),(0,re.jsxs)(et,{variant:"outline",className:is("flex items-center",(r=t.status,l=t.statusCode,"pending"===r?"bg-slate-100 text-slate-700":l>=200&&l<300?"bg-emerald-50 text-emerald-700":"bg-rose-50 text-rose-700")),children:[((e,s)=>"pending"===e?(0,re.jsx)(Ze.A,{className:"h-3.5 w-3.5 animate-spin"}):s>=200&&s<300?(0,re.jsx)(Px.A,{className:"h-3.5 w-3.5"}):(0,re.jsx)(Xe.A,{className:"h-3.5 w-3.5"}))(t.status,t.statusCode),"completed"===t.status&&t.statusCode]}),(0,re.jsx)(It.A,{className:"h-3.5 w-3.5 text-muted-foreground"})]})]}),(0,re.jsx)(Cd,{children:(0,re.jsx)("div",{className:"p-4 border-t bg-slate-50/50",children:(0,re.jsxs)(hl,{defaultValue:"general",children:[(0,re.jsxs)(pl,{className:"mb-3",children:[(0,re.jsx)(gl,{value:"general",children:"General"}),(0,re.jsx)(gl,{value:"request",children:"Request"}),"completed"===t.status&&(0,re.jsx)(gl,{value:"response",children:"Response"})]}),(0,re.jsxs)(fl,{value:"general",className:"space-y-3",children:[(0,re.jsxs)("div",{children:[(0,re.jsx)("p",{className:"text-sm font-medium",children:"URL"}),(0,re.jsx)("p",{className:"text-sm text-muted-foreground break-all",children:t.url})]}),(0,re.jsxs)("div",{className:"grid grid-cols-2 gap-3",children:[(0,re.jsxs)("div",{children:[(0,re.jsx)("p",{className:"text-sm font-medium",children:"Method"}),(0,re.jsx)("p",{className:"text-sm text-muted-foreground",children:t.method})]}),(0,re.jsxs)("div",{children:[(0,re.jsx)("p",{className:"text-sm font-medium",children:"Status"}),(0,re.jsx)("p",{className:"text-sm text-muted-foreground",children:"completed"===t.status?"".concat(t.statusCode," (").concat(t.duration,"ms)"):(0,re.jsxs)("span",{className:"flex items-center",children:[(0,re.jsx)(Ze.A,{className:"h-3 w-3 mr-1 animate-spin"}),"Pending"]})})]})]}),(0,re.jsxs)("div",{children:[(0,re.jsx)("p",{className:"text-sm font-medium",children:"Time"}),(0,re.jsxs)("p",{className:"text-sm text-muted-foreground",children:["Started: ",n(t.startTime),t.endTime&&(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)("br",{}),"Completed: ",n(t.endTime)]})]})]})]}),(0,re.jsx)(fl,{value:"request",children:t.body?(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsx)("p",{className:"text-sm font-medium",children:"Request Data"}),(0,re.jsx)("pre",{className:"p-3 rounded bg-white text-xs overflow-auto max-h-60 border",children:"object"==typeof t.body?JSON.stringify(t.body,null,2):t.body})]}):(0,re.jsx)("p",{className:"text-sm text-muted-foreground",children:"No request data"})}),"completed"===t.status&&(0,re.jsx)(fl,{value:"response",children:t.response?(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsx)("p",{className:"text-sm font-medium",children:"Response Data"}),(0,re.jsx)("pre",{className:"p-3 rounded bg-white text-xs overflow-auto max-h-60 border",children:"object"==typeof t.response?JSON.stringify(t.response,null,2):t.response})]}):(0,re.jsx)("p",{className:"text-sm text-muted-foreground",children:"No response data"})})]})})})]});var r,l}function Tg(){const{activeRequests:e}=Ag(),[s,t]=(0,H.useState)(!1);return(0,re.jsxs)(Vm,{open:s,onOpenChange:t,children:[(0,re.jsx)(Ym,{asChild:!0,children:(0,re.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,re.jsx)(Ng.A,{className:is("h-5 w-5",e>0?"text-primary animate-pulse":"text-muted-foreground")}),e>0&&(0,re.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,re.jsx)(Zm,{side:"right",className:"min-w-[600px]",children:(0,re.jsx)(Cg,{onClose:()=>t(!1)})})]})}var Pg=t(99040);const Lg=["className","sideOffset"],Og=Cs.Kq,Rg=Cs.bL,Dg=Cs.l9,Mg=H.forwardRef((e,s)=>{let{className:t,sideOffset:a=4}=e,n=(0,as.A)(e,Lg);return(0,re.jsx)(Cs.UC,(0,K.A)({ref:s,sideOffset:a,className:is("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]",t)},n))});Mg.displayName=Cs.UC.displayName;const Fg={COPY_LINK:"Copy link",COPIED:"Copied"},Bg={TITLE:"Available Domains",MANAGE_BUTTON:"Manage"},Ug={NO_CUSTOM_DOMAINS:"No custom domains configured",MORE_DOMAINS:"more domains"},zg=e=>{let{url:s,displayUrl:t,copiedUrl:a,onCopy:n}=e;const[r,l]=(0,H.useState)(!1),i=(0,H.useRef)(null),o=a===s;(0,H.useEffect)(()=>()=>{i.current&&clearTimeout(i.current)},[]),(0,H.useEffect)(()=>{o?(l(!0),i.current&&clearTimeout(i.current),i.current=setTimeout(()=>{l(!1)},2e3)):l(!1)},[o]);return(0,re.jsxs)("div",{className:"group flex items-center justify-between text-sm bg-slate-100 hover:bg-transparent rounded-md",onMouseOut:()=>{l(!1)},children:[(0,re.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,re.jsx)(bn.A,{className:"h-4 w-4 mr-2 flex-shrink-0 text-gray-400","data-testid":"globe-icon"}),(0,re.jsx)("a",{href:s,target:"_blank",rel:"noopener noreferrer",className:"text-blue-600 hover:underline truncate",children:t})]}),(0,re.jsxs)("div",{className:"relative",children:[(0,re.jsx)(Og,{delayDuration:500,children:(0,re.jsxs)(Rg,{children:[(0,re.jsx)(Dg,{asChild:!0,children:(0,re.jsx)("button",{onClick:e=>{n(s)},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,re.jsx)(Pt.A,{className:"h-4 w-4","data-testid":"check-icon"}):(0,re.jsx)(Kr.A,{className:"h-4 w-4","data-testid":"copy-icon"})})}),(0,re.jsx)(Mg,{side:"top",sideOffset:4,children:(0,re.jsx)("p",{children:Fg.COPY_LINK})})]})}),r&&(0,re.jsx)(Og,{children:(0,re.jsxs)(Rg,{open:!0,children:[(0,re.jsx)(Dg,{asChild:!0,children:(0,re.jsx)("div",{className:"absolute inset-0 pointer-events-none"})}),(0,re.jsx)(Mg,{side:"top",sideOffset:4,children:(0,re.jsx)("p",{children:Fg.COPIED})})]})})]})]})},qg=e=>{let{publishLink:s,domains:t,appId:a,onManageDomainsClick:n}=e;const r=(0,Z.Zp)(),[l,i]=(0,H.useState)("");(0,H.useEffect)(()=>{if(l){const e=setTimeout(()=>{i("")},2e3);return()=>clearTimeout(e)}},[l]);const o=e=>{navigator.clipboard.writeText(e).then(()=>{i(e)}).catch(e=>{})},c=(0,H.useCallback)(()=>{null==n||n(),r("/apps/".concat(a,"/editor/workspace/domains"))},[n,r,a]);return(0,re.jsxs)("div",{className:"py-4",children:[(0,re.jsxs)("div",{className:"flex items-center justify-between mb-1",children:[(0,re.jsx)("h4",{className:"font-medium text-sm leading-5 text-gray-700",children:Bg.TITLE}),(0,re.jsx)(Yn,{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:Bg.MANAGE_BUTTON})]}),(0,re.jsxs)("div",{className:"space-y-1",children:[(0,re.jsx)(zg,{url:s,displayUrl:s.replace(/(https?:\/\/)/,""),copiedUrl:l,onCopy:o},s),t&&t.length>0?t.slice(0,4).map(e=>(0,re.jsx)(zg,{url:"https://".concat(e.domain),displayUrl:e.domain,copiedUrl:l,onCopy:o},e.domain)):(0,re.jsx)("p",{className:"text-sm text-gray-500",children:Ug.NO_CUSTOM_DOMAINS}),t&&t.length>4&&(0,re.jsxs)("p",{className:"text-xs text-gray-500 pl-1",children:["+",t.length-4," ",Ug.MORE_DOMAINS]})]})]})};const Wg=e=>{let{value:s,showWorkspace:t=!0,onNavigation:a}=e;const n=(0,Z.Zp)(),{app:r}=_s(),l=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)"}}(s),i=function(e){switch(e){case"private_with_login":default:return Fs.A;case"workspace_with_login":return Gr.A;case"public_with_login":case"public_without_login":return bn.A}}(s);return(0,re.jsx)("div",{className:"pt-4 pb-1 border-t border-slate-200",children:(0,re.jsxs)("button",{onClick:()=>{null!=r&&r.id&&(null==a||a(),n("/apps/".concat(r.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,re.jsx)("div",{className:"flex-shrink-0 bg-gray-100 rounded-md p-[5px]",children:(0,re.jsx)(i,{size:16})}),(0,re.jsxs)("div",{className:"flex-1 flex items-center gap-1",children:[(0,re.jsx)("span",{children:l}),(0,re.jsx)(Jo.A,{size:14,className:"opacity-0 group-hover:opacity-100 transition-opacity"})]})]})})};function Vg(e){let{isMobile:s=!1,app:t,updateApp:a}=e;const{isInSharedWorkspace:n}=Uu(),{user:r}=oe(),{hasFlag:l}=Sx(),[i,o]=(0,H.useState)(!1),[c,d]=(0,H.useState)(!1),[m,u]=(0,H.useState)(null),[x,h]=(0,H.useState)([]),[p,g]=(0,H.useState)(!1),[f,v]=(0,H.useState)(""),[b,j]=(0,H.useState)(!0),[y,N]=(0,H.useState)(null),[w,_]=(0,H.useState)(!1),k=null!=t&&t.slug?fa(t):"",A=b,S=y;(0,H.useEffect)(()=>{(i||p)&&null!=t&&t.id&&(async()=>{try{const e=await Ha.filter({app_id:t.id});h(e)}catch(e){}})()},[i,p,null==t?void 0:t.id]),(0,H.useEffect)(()=>{(async()=>{if(null==t||!t.id||null==t||!t.organization_id)return j(!0),void N(null);try{const e=await xe.checkSensitiveFeaturePermission("publish_app",t.organization_id);j(e.allowed),N(e.restriction_reason)}catch(e){j(!0),N(null)}})()},[null==t?void 0:t.id,null==t?void 0:t.organization_id]),(0,H.useEffect)(()=>{_(!1)},[b]),(0,H.useEffect)(()=>{if(f){const e=setTimeout(()=>{v("")},2e3);return()=>clearTimeout(e)}},[f]);const C=e=>{let{url:s,displayUrl:t}=e;const a=f===s;return(0,re.jsxs)("div",{className:"flex items-center justify-between text-sm","data-testid":"domain-item",children:[(0,re.jsxs)("div",{className:"flex items-center flex-1 overflow-hidden",children:[(0,re.jsx)(bn.A,{className:"h-4 w-4 mr-2 flex-shrink-0 text-gray-500"}),(0,re.jsx)("a",{href:s,target:"_blank",rel:"noopener noreferrer",className:"text-blue-600 hover:underline truncate",children:t})]}),(0,re.jsx)("button",{onClick:()=>(e=>{navigator.clipboard.writeText(e).then(()=>{v(e)}).catch(e=>{})})(s),className:"ml-2 p-1 text-gray-500 hover:bg-gray-100 rounded-md transition-colors",title:"Copy to clipboard",children:a?(0,re.jsx)(Pt.A,{className:"h-4 w-4 text-green-500"}):(0,re.jsx)(Kr.A,{className:"h-4 w-4"})})]})},E=async()=>{null!=t&&t.id&&(((e,s)=>{try{var a;We({user_id:(null==r?void 0:r.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:"publish",origin:e,target_route:s}),Ie("User Clicked Publish Button",{user_id:(null==r?void 0:r.id)||null,app_id:t.id,origin:e,target_route:s})}catch(n){}})("publish_modal","publish"),await I())},I=async()=>{try{d(!0),u(null),await ve.deployApp(t.id),Ie("App Published",{app_id:t.id,app_name:t.name,has_custom_domains:x.length>0});const e=x.length>0?"https://".concat(x[0].domain):k;window.open(e,"_blank")}catch(e){u(e.message||"Failed to deploy app")}finally{d(!1),s&&g(!1)}};return s?"icon"===s?(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(Hs,{variant:"ghost",size:"icon",className:"h-8 w-8 ".concat(A?"":"opacity-50 cursor-not-allowed"),onClick:()=>A&&g(!0),disabled:c||!A,title:!A&&S?S:void 0,children:(0,re.jsx)(Pg.A,{className:"h-5 w-5"})}),(0,re.jsx)(Pa,{open:p,onOpenChange:g,children:(0,re.jsxs)(Ma,{className:"sm:max-w-md",children:[(0,re.jsx)(Fa,{children:(0,re.jsx)(Ua,{children:"Publish Your App"})}),null!=t&&t.last_deployed_at?(0,re.jsxs)("div",{className:"py-3 text-sm text-gray-600",children:[(0,re.jsx)("p",{className:"mb-2",children:"Publishing will make your current version available at the public link."}),(0,re.jsxs)("p",{className:"mb-2",children:["Last published: ",la().utc(null==t?void 0:t.last_deployed_at).fromNow()]})]}):(0,re.jsxs)("div",{className:"py-3 text-sm text-gray-600",children:[(0,re.jsx)("p",{className:"mb-2",children:"This will be the first public version of your app."}),(0,re.jsx)("p",{children:"Publishing will make your app accessible to users at the public link."})]}),m&&(0,re.jsx)("div",{className:"py-2 text-sm text-red-600 bg-red-50 border-t border-b border-red-100",children:(0,re.jsxs)("div",{className:"flex items-center",children:[(0,re.jsx)(Xe.A,{className:"h-4 w-4 mr-2"}),(0,re.jsx)("p",{children:m})]})}),(0,re.jsxs)("div",{className:"py-3",children:[(0,re.jsx)("h4",{className:"font-medium text-gray-900 mb-2",children:"Available Domains"}),(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsx)(C,{url:k,displayUrl:k.replace(/(https?:\/\/)/,"")}),x.length>0?x.map((e,s)=>(0,re.jsx)("div",{className:"px-1",children:(0,re.jsx)(C,{url:"https://".concat(e.domain),displayUrl:e.domain})},s)):(0,re.jsx)("p",{className:"text-sm text-gray-500",children:"No custom domains configured"})]})]}),(0,re.jsx)(Ba,{children:(0,re.jsx)(Hs,{className:"w-full bg-gray-900 text-white hover:bg-gray-800",onClick:E,disabled:c,children:c?(0,re.jsxs)("span",{className:"flex items-center justify-center",children:[(0,re.jsx)(Ze.A,{className:"mr-2 h-4 w-4 animate-spin"}),"Publishing..."]}):"Publish App"})})]})})]}):(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(zl,{asChild:!0,onClick:e=>{e.preventDefault(),g(!0)},disabled:c,children:(0,re.jsxs)("div",{className:"flex items-center",children:[(0,re.jsx)(Pg.A,{className:"mr-2 h-4 w-4"}),"Publish"]})}),(0,re.jsx)(Pa,{open:p,onOpenChange:g,children:(0,re.jsxs)(Ma,{className:"sm:max-w-md",children:[(0,re.jsx)(Fa,{children:(0,re.jsx)(Ua,{children:"Publish Your App"})}),t.last_deployed_at?(0,re.jsxs)("div",{className:"py-3 text-sm text-gray-600",children:[(0,re.jsx)("p",{className:"mb-2",children:"Publishing will make your current version available at the public link."}),(0,re.jsxs)("p",{className:"mb-2",children:["Last published: ",la().utc(null==t?void 0:t.last_deployed_at).fromNow()]})]}):(0,re.jsxs)("div",{className:"py-3 text-sm text-gray-600",children:[(0,re.jsx)("p",{className:"mb-2",children:"This will be the first public version of your app. "}),(0,re.jsx)("p",{children:"Publishing will make your app accessible to users at the public link."})]}),m&&(0,re.jsx)("div",{className:"py-2 text-sm text-red-600 bg-red-50 border-t border-b border-red-100",children:(0,re.jsxs)("div",{className:"flex items-center",children:[(0,re.jsx)(Xe.A,{className:"h-4 w-4 mr-2"}),(0,re.jsx)("p",{children:m})]})}),(0,re.jsxs)("div",{className:"py-3",children:[(0,re.jsx)("h4",{className:"font-medium text-gray-900 mb-2",children:"Available Domains"}),(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsx)(C,{url:k,displayUrl:k.replace(/(https?:\/\/)/,"")}),x.length>0?x.map((e,s)=>(0,re.jsx)("div",{className:"px-1",children:(0,re.jsx)(C,{url:"https://".concat(e.domain),displayUrl:e.domain})},s)):(0,re.jsx)("p",{className:"text-sm text-gray-500",children:"No custom domains configured"})]})]}),(0,re.jsxs)(Ba,{children:[(0,re.jsx)(Hs,{className:"w-full ".concat(A?"bg-gray-900 text-white hover:bg-gray-800":"bg-gray-300 text-gray-500 cursor-not-allowed"),onClick:E,disabled:c||!A,children:c?(0,re.jsxs)("span",{className:"flex items-center justify-center",children:[(0,re.jsx)(Ze.A,{className:"mr-2 h-4 w-4 animate-spin"}),"Publishing..."]}):"Publish App"}),!A&&S&&(0,re.jsx)("div",{className:"text-sm text-red-600 text-center mt-2",children:S})]})]})})]}):A?(0,re.jsx)(Is,{children:(0,re.jsxs)(Ts,{open:i,children:[(0,re.jsxs)(Pl,{open:i,onOpenChange:o,children:[(0,re.jsx)(Ll,{asChild:!0,children:(0,re.jsx)(Ps,{asChild:!0,children:(0,re.jsx)(Hs,{className:"px-3 py-1 bg-gray-900 text-white text-sm rounded-md hover:bg-gray-800 transition-colors h-8",disabled:c||!(null!=t&&t.id),children:c?(0,re.jsxs)("span",{className:"flex items-center",children:[(0,re.jsx)(Ze.A,{className:"mr-2 h-3.5 w-3.5 animate-spin"}),"Publishing..."]}):(0,re.jsx)("span",{children:"Publish"})})})}),(0,re.jsx)(Ls,{children:(0,re.jsx)("p",{children:"Publish your app"})}),(0,re.jsxs)(Ul,{align:"end",className:"w-80 p-0 rounded-xl","data-hook":"publish-dropdown-menu-content",children:[(0,re.jsxs)("div",{className:"p-4",children:[(0,re.jsxs)("div",{className:"flex items-center justify-between",children:[(0,re.jsx)("h3",{className:"font-semibold text-gray-900",children:"Publish Your App"}),(null==t?void 0:t.logo_url)&&(0,re.jsx)("img",{src:t.logo_url,alt:"".concat((null==t?void 0:t.name)||"App"," logo"),className:"w-8 h-8 ml-3 rounded-md object-cover border border-black/10 bg-gray-300"})]}),null!=t&&t.last_deployed_at?null:(0,re.jsx)("div",{className:"py-3 text-sm text-gray-600 border-b border-slate-100",children:(0,re.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."})}),m&&(0,re.jsx)("div",{className:"py-2 text-sm text-red-600 bg-red-50 border-t border-b border-red-100",children:(0,re.jsxs)("div",{className:"flex items-center",children:[(0,re.jsx)(Xe.A,{className:"h-4 w-4 mr-2"}),(0,re.jsx)("p",{children:m})]})}),(0,re.jsx)(qg,{publishLink:k,domains:x,appId:(null==t?void 0:t.id)||""}),(0,re.jsx)(Wg,{value:(null==t?void 0:t.public_settings)||"private_with_login",showWorkspace:n,onNavigation:()=>o(!1)}),(0,re.jsx)(Cx,{onClosePublish:()=>o(!1)}),(0,re.jsx)("div",{className:"pt-3",children:(0,re.jsx)(Hs,{className:"w-full h-8 bg-gray-900 text-white text-sm rounded-md hover:bg-gray-800 transition-colors py-2",onClick:E,disabled:c,"data-testid":"publish-button",children:c?(0,re.jsxs)("span",{className:"flex items-center justify-center",children:[(0,re.jsx)(Ze.A,{className:"mr-2 h-4 w-4 animate-spin"}),"Publishing..."]}):"Publish App"})})]}),(null==t?void 0:t.last_deployed_at)&&(0,re.jsx)("div",{className:"text-center",children:(0,re.jsxs)("p",{className:"text-xs bg-slate-100 py-[6px] font-normal leading-4 text-center text-[var(--text-muted,#71717A)]",children:["Last published ",la().utc(t.last_deployed_at).fromNow()]})})]})]}),(0,re.jsx)(Ls,{children:(0,re.jsx)("p",{children:"Publish app and open in new tab"})})]})}):(0,re.jsxs)("div",{className:"relative",children:[(0,re.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:()=>_(!0),onMouseLeave:()=>_(!1),title:S||"Publishing is currently disabled",children:(0,re.jsx)("span",{children:"Publish"})}),w&&(0,re.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:[S||"Publishing is currently disabled",(0,re.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 Yg=t(86009),Hg=t(80903),Gg=t(3255),$g=t(15332);const Jg=["className","inset","children"],Zg=["className"],Kg=["className","sideOffset"],Xg=["className","inset"],Qg=["className","children","checked"],ef=["className","children"],sf=["className","inset"],tf=["className"],af=Nl.bL,nf=Nl.l9;Nl.YJ,Nl.ZL,Nl.Pb,Nl.z6;H.forwardRef((e,s)=>{let{className:t,inset:a,children:n}=e,r=(0,as.A)(e,Jg);return(0,re.jsxs)(Nl.ZP,(0,K.A)((0,K.A)({ref:s,className:is("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",t)},r),{},{children:[n,(0,re.jsx)(ln.A,{className:"ml-auto h-4 w-4"})]}))}).displayName=Nl.ZP.displayName;H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,Zg);return(0,re.jsx)(Nl.G5,(0,K.A)({ref:s,className:is("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",t)},a))}).displayName=Nl.G5.displayName;const rf=H.forwardRef((e,s)=>{let{className:t,sideOffset:a=4}=e,n=(0,as.A)(e,Kg);return(0,re.jsx)(Nl.ZL,{children:(0,re.jsx)(Nl.UC,(0,K.A)({ref:s,sideOffset:a,className:is("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",t)},n))})});rf.displayName=Nl.UC.displayName;const lf=H.forwardRef((e,s)=>{let{className:t,inset:a}=e,n=(0,as.A)(e,Xg);return(0,re.jsx)(Nl.q7,(0,K.A)({ref:s,className:is("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",t)},n))});lf.displayName=Nl.q7.displayName;H.forwardRef((e,s)=>{let{className:t,children:a,checked:n}=e,r=(0,as.A)(e,Qg);return(0,re.jsxs)(Nl.H_,(0,K.A)((0,K.A)({ref:s,className:is("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",t),checked:n},r),{},{children:[(0,re.jsx)("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:(0,re.jsx)(Nl.VF,{children:(0,re.jsx)(Pt.A,{className:"h-4 w-4"})})}),a]}))}).displayName=Nl.H_.displayName;H.forwardRef((e,s)=>{let{className:t,children:a}=e,n=(0,as.A)(e,ef);return(0,re.jsxs)(Nl.hN,(0,K.A)((0,K.A)({ref:s,className:is("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",t)},n),{},{children:[(0,re.jsx)("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:(0,re.jsx)(Nl.VF,{children:(0,re.jsx)(_t.A,{className:"h-2 w-2 fill-current"})})}),a]}))}).displayName=Nl.hN.displayName;const of=H.forwardRef((e,s)=>{let{className:t,inset:a}=e,n=(0,as.A)(e,sf);return(0,re.jsx)(Nl.JU,(0,K.A)({ref:s,className:is("px-2 py-1.5 text-sm font-semibold",a&&"pl-8",t)},n))});of.displayName=Nl.JU.displayName;const cf=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,tf);return(0,re.jsx)(Nl.wv,(0,K.A)({ref:s,className:is("-mx-1 my-1 h-px bg-muted",t)},a))});cf.displayName=Nl.wv.displayName;function df(){const[e,s]=H.useState(void 0);return H.useEffect(()=>{const e=window.matchMedia("(max-width: ".concat(767,"px)")),t=()=>{s(window.innerWidth<768)};return e.addEventListener("change",t),s(window.innerWidth<768),()=>e.removeEventListener("change",t)},[]),!!e}function mf(e){let{onDataChange:s,onReset:t}=e;const{activeWorkspace:a}=ge(),n=df(),[r,l]=(0,H.useState)(""),[i,o]=(0,H.useState)(""),[c,d]=(0,H.useState)(""),[m,u]=(0,H.useState)(!1),[x,h]=(0,H.useState)(!1);(0,H.useEffect)(()=>{if(a){const e=a.is_personal||!1;if(h(e),e)l("Personal Workspace"),o(a.description||""),d(""),u(!0);else{l(a.name||""),o(a.description||""),d(a.domain||"");const e=a.user_role||"member";u(["admin","owner"].includes(e))}}},[a]),(0,H.useEffect)(()=>{s&&a&&s({name:r,description:i,domain:c,canEdit:m,isPersonalWorkspace:x,workspaceId:a.id,hasChanges:p()})},[r,i,c,m,x,a,s]),(0,H.useEffect)(()=>{if(t){const e=()=>{a&&(x?(l("Personal Workspace"),d("")):(l(a.name||""),d(a.domain||"")),o(a.description||""))};window.workspaceInfoReset=e}},[a,x,t]);const p=()=>{if(!a)return!1;const e=x?"Personal Workspace":a.name||"",s=a.description||"",t=x?"":a.domain||"";return r!==e||i!==s||c!==t};return a?(0,re.jsxs)("div",{className:"flex flex-col gap-6",children:[!n&&(0,re.jsx)("div",{className:"flex flex-col gap-3",children:(0,re.jsx)("div",{className:"text-black text-base font-semibold",children:"Workspace info"})}),(0,re.jsxs)("div",{className:"flex flex-col gap-3",children:[(0,re.jsx)("div",{className:"flex gap-3",children:(0,re.jsxs)("div",{className:"flex-1 flex flex-col gap-2",children:[(0,re.jsx)("label",{className:"text-gray-700 text-sm font-medium",children:"Workspace name"}),(0,re.jsx)("input",{type:"text",value:r,onChange:e=>{!x&&m&&l(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,re.jsx)("div",{className:"flex gap-3",children:(0,re.jsxs)("div",{className:"flex-1 flex flex-col gap-2",children:[(0,re.jsx)("label",{className:"text-gray-700 text-sm font-medium",children:"Workspace Domain"}),(0,re.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,re.jsx)("p",{className:"text-xs text-gray-500",children:"The domain associated with your workspace (optional)"})]})}),(0,re.jsx)("div",{className:"flex gap-3",children:(0,re.jsxs)("div",{className:"flex-1 flex flex-col gap-2",children:[(0,re.jsx)("label",{className:"text-gray-700 text-sm font-medium",children:"Workspace Description"}),(0,re.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,re.jsxs)("div",{className:"flex flex-col gap-6",children:[(0,re.jsx)("div",{className:"flex flex-col gap-3",children:(0,re.jsx)("div",{className:"text-black text-base font-semibold",children:"Workspace info"})}),(0,re.jsx)("div",{className:"text-gray-500 text-sm",children:"Loading workspace information..."})]})}function uf(e){let{title:s,current:t,total:a,percentage:n,remaining:r}=e;const[l,i]=(0,H.useState)(0);(0,H.useEffect)(()=>{const e=setTimeout(()=>{i(n)},100);return()=>clearTimeout(e)},[n]);return(0,re.jsxs)("div",{className:"flex flex-col gap-2 animate-in fade-in duration-500",children:[(0,re.jsxs)("div",{className:"flex justify-between items-center",children:[(0,re.jsx)("div",{className:"text-gray-700 text-sm font-medium leading-tight",children:s}),(0,re.jsxs)("div",{className:"text-black text-sm font-medium leading-tight",children:[t,"/",a]})]}),(0,re.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,re.jsx)("div",{className:"flex items-center gap-3",children:(0,re.jsx)("div",{className:"flex-1 flex items-center gap-1.5",children:(0,re.jsx)("div",{className:"flex-1 h-2 bg-slate-100 rounded-full flex",children:(0,re.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(l,"%")}})})})}),(0,re.jsxs)("div",{className:"flex justify-between items-center",children:[(0,re.jsxs)("div",{className:"text-gray-500 text-sm font-normal leading-tight",children:[n,"% used"]}),(0,re.jsxs)("div",{className:"text-gray-500 text-sm font-normal leading-tight",children:[r," ",s.toLowerCase().includes("credit")?"credits":"messages"," remaining"]})]})]})]})}var xf=t(80294),hf=t(85706);function pf(e){let{usageByDate:s,height:t}=e;const a=e=>{try{return new Date(e).toLocaleDateString("en-US",{month:"short",day:"numeric"})}catch(s){return e}},n=(e=>{if(!e||!Array.isArray(e))return[];return[...e].sort((e,s)=>new Date(e._id)-new Date(s._id)).slice(-10).map(e=>(0,K.A)((0,K.A)({},e),{},{date:a(e._id),total_messages:e.total_messages||0}))})(s),r=e=>{let{active:s,payload:t,label:a}=e;return s&&t&&t.length?(0,re.jsxs)("div",{className:"bg-white p-3 border border-gray-200 shadow-lg rounded-md text-xs",children:[(0,re.jsx)("p",{className:"font-medium text-gray-900",children:t[0].payload.date}),(0,re.jsxs)("p",{className:"text-slate-700 mt-1",children:[(0,re.jsx)("span",{className:"font-medium",children:t[0].value})," messages"]})]}):null};return n.length?(0,re.jsxs)("div",{className:"flex flex-col gap-6",children:[(0,re.jsx)("div",{className:"text-gray-700 text-sm font-medium leading-tight",children:"Daily Usage (Messages)"}),(0,re.jsx)("div",{className:"".concat(t||"h-40"),children:(0,re.jsx)(Wx.u,{width:"100%",height:"100%",children:(0,re.jsxs)(xf.E,{data:n,margin:{top:0,right:0,left:0,bottom:0},padding:{top:0,right:0,left:0,bottom:0},children:[(0,re.jsx)(Yx.d,{stroke:"#F3F4F6",vertical:!1,strokeWidth:1}),(0,re.jsx)(Hx.W,{dataKey:"date",textAnchor:"middle",height:26,fontSize:12,stroke:"#6b7280",tickMargin:10,axisLine:!1,tickLine:!1}),(0,re.jsx)(Gx.h,{fontSize:12,stroke:"#6b7280",axisLine:!1,tickLine:!1,tickCount:5,tickFormatter:e=>0===e?"0":e,width:38}),(0,re.jsx)($x.m,{content:(0,re.jsx)(r,{}),cursor:{fill:"rgba(71, 85, 105, 0.1)"}}),(0,re.jsx)(hf.y,{dataKey:"total_messages",name:"Messages",fill:"#f1f5f9",stroke:"#d1d5db",strokeWidth:1,radius:[4,4,0,0],maxBarSize:50,animationDuration:2e3})]})})})]}):(0,re.jsxs)("div",{className:"flex flex-col gap-6",children:[(0,re.jsx)("div",{className:"text-gray-700 text-sm font-medium leading-tight",children:"Daily Usage (Messages)"}),(0,re.jsx)("div",{className:"h-40 flex items-center justify-center",children:(0,re.jsx)("div",{className:"text-gray-500 text-sm",children:"No usage data available"})})]})}function gf(){var e,s,t;const[a,n]=(0,H.useState)([]),[r,l]=(0,H.useState)(!0),[i,o]=(0,H.useState)(null),[c,d]=(0,H.useState)(null),[m,u]=(0,H.useState)([]),{user:x}=oe(),h=df(),{toast:p}=nn();(0,H.useEffect)(()=>{g()},[]);const g=async()=>{try{l(!0);const[e,s]=await Promise.all([es.default.getStats(),es.default.getCurrentIntegrationUsage()]),t=e,a=s,r=[{title:"Monthly Messages",current:Math.round((null==t?void 0:t.monthly_usage)||0),total:(null==t?void 0:t.monthly_limit)||0,percentage:null!=t&&t.monthly_limit?Math.round(t.monthly_usage/t.monthly_limit*100):0,remaining:Math.max(0,((null==t?void 0:t.monthly_limit)||0)-Math.round((null==t?void 0:t.monthly_usage)||0))},...null!=t&&t.daily_limit?[{title:"Daily Messages",current:Math.round((null==t?void 0:t.daily_usage)||0),total:(null==t?void 0:t.daily_limit)||0,percentage:null!=t&&t.daily_limit?Math.round(t.daily_usage/t.daily_limit*100):0,remaining:Math.max(0,((null==t?void 0:t.daily_limit)||0)-Math.round((null==t?void 0:t.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(r),u((null==t?void 0:t.usage_by_date)||[]),d({subscription_status:null==t?void 0:t.subscription_status,is_over_limit:null==t?void 0:t.is_over_limit,past_due:null==t?void 0:t.past_due,tier:null==t?void 0:t.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{l(!1)}};return r?(0,re.jsxs)("div",{className:"flex flex-col gap-6 animate-in fade-in duration-300",children:[!h&&(0,re.jsx)("div",{className:"flex flex-col gap-3",children:(0,re.jsx)("div",{className:"text-black text-base font-semibold leading-normal",children:"Credits Usages"})}),(0,re.jsx)("div",{className:"bg-gray-100 rounded-xl border border-gray-200 flex flex-col transition-all duration-300",children:(0,re.jsx)("div",{className:"p-6 flex items-center justify-center",children:(0,re.jsx)("div",{className:"animate-spin rounded-full h-12 w-12 border-t-2 border-b-2 border-slate-700"})})})]}):i?(0,re.jsxs)("div",{className:"flex flex-col gap-6 animate-in fade-in duration-300",children:[!h&&(0,re.jsx)("div",{className:"flex flex-col gap-3",children:(0,re.jsx)("div",{className:"text-black text-base font-semibold leading-normal",children:"Credits Usages"})}),(0,re.jsx)("div",{className:"bg-gray-100 rounded-xl border border-gray-200 flex flex-col transition-all duration-300",children:(0,re.jsx)("div",{className:"p-6 flex items-center justify-center",children:(0,re.jsx)("div",{className:"text-red-500 animate-in fade-in duration-500",children:i})})})]}):(0,re.jsxs)("div",{className:"flex flex-col gap-6 animate-in fade-in duration-500",children:[!h&&(0,re.jsx)("div",{className:"flex flex-col gap-3",children:(0,re.jsx)("div",{className:"text-black text-base font-semibold leading-normal",children:"Credits Usages"})}),(0,re.jsxs)("div",{className:"bg-gray-100 rounded-xl border border-gray-200 flex flex-col transition-all duration-300",children:[(0,re.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,re.jsxs)("div",{className:"flex-1 flex items-center gap-2",children:[(0,re.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,re.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,re.jsx)("button",{onClick:async()=>{if(null!=c&&c.past_due)try{const e="payment_method_update",s=await Ji.createPortalSession(e);window.location.href=s.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,re.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,re.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,re.jsxs)("div",{className:"flex items-start gap-3",children:[(0,re.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,re.jsx)("svg",{className:"w-3 h-3 text-white",fill:"currentColor",viewBox:"0 0 20 20",children:(0,re.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,re.jsxs)("div",{className:"flex-1",children:[(0,re.jsx)("h3",{className:"text-orange-800 font-medium text-sm mb-1",children:"Payment overdue"}),(0,re.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===(s=e.charAt(0))||void 0===s?void 0:s.toUpperCase())+(null==c||null===(t=c.tier)||void 0===t?void 0:t.slice(1)),")."]})]})]})}),(0,re.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,s)=>(0,re.jsx)("div",{style:{animationDelay:"".concat(100*s,"ms")},className:"animate-in fade-in slide-in-from-bottom-1 duration-500",children:(0,re.jsx)(uf,(0,K.A)({},e))},s)),(0,re.jsx)("div",{style:{animationDelay:"".concat(100*a.length,"ms")},className:"animate-in fade-in slide-in-from-bottom-1 duration-500",children:(0,re.jsx)(pf,{usageByDate:m})})]})]})]})}function ff(){const e=df(),[s,t]=(0,H.useState)(!1),[a,n]=(0,H.useState)(null),r=(0,H.useCallback)(e=>{n(e)},[]),l=(null==a?void 0:a.canEdit)&&(null==a?void 0:a.hasChanges);return(0,re.jsxs)("div",{className:"h-full flex flex-col",children:[(0,re.jsx)("div",{className:"flex-1 overflow-y-auto",children:(0,re.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,re.jsx)(mf,{onDataChange:r,onReset:!0}),(0,re.jsx)(gf,{})]})}),l&&(0,re.jsxs)("div",{className:"flex-shrink-0 p-4 bg-white border-t border-gray-200 flex justify-end items-center gap-3",children:[(0,re.jsx)("button",{onClick:()=>{window.workspaceInfoReset&&window.workspaceInfoReset()},disabled:s,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,re.jsx)("button",{onClick:async()=>{if(a&&a.canEdit&&a.hasChanges){t(!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),Xr.default.success("Workspace settings updated successfully!")}catch(n){var e,s;Xr.default.error("Failed to update workspace settings: "+((null===(e=n.response)||void 0===e||null===(s=e.data)||void 0===s?void 0:s.detail)||n.message||"Unknown error"))}finally{t(!1)}}},disabled:s,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:s?"Saving...":"Save Changes"})]})]})}function vf(e){let{userEmail:s,userFullName:t,profileImageUrl:a,size:n="default"}=e;const{activeWorkspace:r}=ge(),l={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=l[n]||l.default;return(0,re.jsxs)("div",{className:i.containerClass,title:"".concat(t||"Unknown"," (").concat(s||"No email",")"),children:[i.showWorkspace&&(0,re.jsx)("span",{className:"text-sm font-base44 font-light text-slate-700",children:r&&!r.is_personal?"".concat(r.name.length>8?r.name.substring(0,8)+"...":r.name):"My Workspace"}),a?(0,re.jsx)("img",{src:a,alt:"".concat(t||"User"," profile"),className:i.imageClass,onError:e=>{e.target.style.display="none";const s=e.target.nextElementSibling;s&&(s.style.display="flex")}}):null,(0,re.jsx)("div",{className:i.initialsClass,style:{display:a?"none":"flex"},children:t?t.charAt(0).toUpperCase():"U"})]})}function bf(e){let{size:s="default"}=e;const{user:t}=oe();return t?(0,re.jsx)(vf,{userEmail:null==t?void 0:t.email,userFullName:null==t?void 0:t.full_name,profileImageUrl:null==t?void 0:t.profile_image_url,size:s}):null}function jf(e){let{value:s,onChange:t,userEmail:a,userFullName:n}=e;const[r,l]=(0,H.useState)(!1),[i,o]=(0,H.useState)(!1),[c,d]=(0,H.useState)(!1),m=(0,H.useRef)(null);return(0,re.jsxs)("div",{className:"flex flex-col lg:flex-row lg:items-start gap-3",children:[(0,re.jsx)("div",{className:"text-gray-700 text-sm font-medium lg:w-48 lg:flex-shrink-0 lg:mt-2",children:"Profile Image"}),(0,re.jsxs)("div",{className:"flex-1",children:[(0,re.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:[s&&!r?(0,re.jsx)("img",{src:s,alt:"Profile",className:"h-12 w-12 rounded-lg object-cover border border-slate-300 group-hover:border-slate-400 transition-colors",onLoad:()=>{l(!1),o(!0)},onError:()=>{l(!0),o(!1)},style:{display:i&&!r?"block":"none"}}):null,(!s||r||!i)&&(0,re.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,re.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,re.jsx)(hm.A,{className:"w-4 h-4 text-white opacity-0 group-hover:opacity-100 transition-opacity"})}),c&&(0,re.jsx)("div",{className:"absolute inset-0 bg-white bg-opacity-75 rounded-lg flex items-center justify-center",children:(0,re.jsx)("div",{className:"animate-spin rounded-full h-6 w-6 border-t-2 border-b-2 border-gray-900"})})]}),(0,re.jsx)("input",{ref:m,type:"file",accept:"image/jpeg,image/jpg,image/png,image/gif,image/webp",onChange:async e=>{const s=e.target.files[0];if(!s)return;if(!["image/jpeg","image/jpg","image/png","image/gif","image/webp"].includes(s.type))return void Xr.default.error("Please upload a valid image file (JPG, PNG, GIF, or WebP)");if(s.size>5242880)Xr.default.error("Image must be less than 5MB");else try{d(!0);const e=(await As.uploadFile(s)).url;t(e),Xr.default.success("Profile image uploaded successfully!")}catch(a){Xr.default.error("Failed to upload image. Please try again.")}finally{d(!1)}},className:"hidden"})]})]})}function yf(){const{user:e,updateUser:s}=oe(),t=df(),[a,n]=(0,H.useState)(!1),r=rx(e),[l,i]=(0,H.useState)(!1),[o,c]=(0,H.useState)(!1),[d,m]=(0,H.useState)({email:"",fullName:"",phoneNumber:"",profileImageUrl:"",notificationPreference:"every_prompt",enableBackendFunctionsByDefault:!1,enableAgentsByDefault:!1});(0,H.useEffect)(()=>{if(e){const s=rx(e);m({email:e.email||"",fullName:e.full_name||"",phoneNumber:e.phone_number||"",profileImageUrl:e.profile_image_url||"",enableBackendFunctionsByDefault:s&&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!==(r&&e.enable_backend_functions_by_default||!1)||d.enableAgentsByDefault!==(e.enable_agents_by_default||!1)||d.notificationPreference!==(e.notification_preference||"every_prompt")),x=(e,s)=>{m(t=>(0,K.A)((0,K.A)({},t),{},{[e]:s}))};return e?(0,re.jsxs)("div",{className:"h-full flex flex-col",children:[(0,re.jsx)("div",{className:"flex-1 overflow-y-auto",children:(0,re.jsx)("div",{className:"".concat(t?"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,re.jsxs)("div",{className:"space-y-6",children:[!t&&(0,re.jsx)("div",{className:"space-y-3",children:(0,re.jsx)("div",{className:"text-black text-base font-semibold",children:"Account"})}),(0,re.jsxs)("div",{className:"space-y-6",children:[(0,re.jsxs)("div",{className:"flex flex-col lg:flex-row lg:items-start gap-3",children:[(0,re.jsx)("div",{className:"text-gray-700 text-sm font-medium lg:w-48 lg:flex-shrink-0 lg:mt-2",children:"Email"}),(0,re.jsx)("div",{className:"flex-1",children:(0,re.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,re.jsxs)("div",{className:"flex flex-col lg:flex-row lg:items-start gap-3",children:[(0,re.jsx)("div",{className:"text-gray-700 text-sm font-medium lg:w-48 lg:flex-shrink-0 lg:mt-2",children:"Full Name"}),(0,re.jsx)("div",{className:"flex-1",children:(0,re.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,re.jsxs)("div",{className:"flex flex-col lg:flex-row lg:items-start gap-3",children:[(0,re.jsx)("div",{className:"text-gray-700 text-sm font-medium lg:w-48 lg:flex-shrink-0 lg:mt-2",children:"Phone Number"}),(0,re.jsxs)("div",{className:"flex-1 space-y-2",children:[(0,re.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,re.jsx)("div",{className:"text-gray-500 text-xs",children:"By entering your phone number, you agree to receive SMS notifications from us."})]})]}),(0,re.jsx)(jf,{value:d.profileImageUrl,onChange:e=>x("profileImageUrl",e),userEmail:d.email,userFullName:d.fullName}),(0,re.jsxs)("div",{className:"flex flex-col lg:flex-row lg:items-start gap-3",children:[(0,re.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,re.jsxs)("div",{className:"flex-1 space-y-2",children:[(0,re.jsxs)(Ut,{value:d.notificationPreference,onValueChange:e=>x("notificationPreference",e),children:[(0,re.jsx)(Wt,{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,re.jsx)("div",{className:"w-full text-left",children:(0,re.jsx)("div",{className:"w-full flex flex-col gap-1",children:(0,re.jsx)("div",{className:"text-sm text-gray-900",children:(0,re.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,re.jsxs)(Ht,{className:"w-[calc(100%-1rem)] max-w-[400px] z-50 p-1.5",sideOffset:4,children:[(0,re.jsx)($t,{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,re.jsx)("div",{className:"w-full flex flex-col gap-1",children:(0,re.jsx)("div",{className:"text-sm leading-[17px] text-gray-900",children:(0,re.jsx)("span",{className:"font-bold",children:"On first prompt only"})})})}),(0,re.jsx)($t,{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,re.jsx)("div",{className:"w-full flex flex-col gap-1",children:(0,re.jsx)("div",{className:"text-sm leading-[17px] text-gray-900",children:(0,re.jsx)("span",{className:"font-bold",children:"On every prompt"})})})}),(0,re.jsx)($t,{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,re.jsx)("div",{className:"w-full flex flex-col gap-1",children:(0,re.jsx)("div",{className:"text-sm leading-[17px] text-gray-900",children:(0,re.jsx)("span",{className:"font-bold",children:"Disable notification sounds"})})})})]})]}),(0,re.jsx)("div",{className:"text-gray-500 text-xs",children:"Choose when to play notification sounds when your app completes prompts."})]})]}),(0,re.jsxs)("div",{className:"flex flex-col lg:flex-row lg:items-start gap-3",children:[(0,re.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,re.jsxs)("div",{className:"flex-1 space-y-2",children:[(0,re.jsxs)("div",{className:"flex items-center gap-3",children:[(0,re.jsx)(wu,{checked:d.enableBackendFunctionsByDefault,onCheckedChange:e=>x("enableBackendFunctionsByDefault",e),disabled:!r,className:"data-[state=checked]:bg-black"}),(0,re.jsx)("div",{className:"text-sm text-gray-700",children:"Enable backend functions for new apps by default"})]}),(0,re.jsx)("div",{className:"text-gray-500 text-xs",children:"When enabled, new apps will automatically have backend functions activated."}),!r&&(0,re.jsx)(lx,{})]})]}),(0,re.jsxs)("div",{className:"flex flex-col lg:flex-row lg:items-start gap-3",children:[(0,re.jsx)("div",{className:"text-gray-700 text-sm font-medium lg:w-48 lg:flex-shrink-0 lg:mt-2",children:"Default Agents"}),(0,re.jsxs)("div",{className:"flex-1 space-y-2",children:[(0,re.jsxs)("div",{className:"flex items-center gap-3",children:[(0,re.jsx)(wu,{checked:d.enableAgentsByDefault,onCheckedChange:e=>x("enableAgentsByDefault",e),className:"data-[state=checked]:bg-black"}),(0,re.jsx)("div",{className:"text-sm text-gray-700",children:"Enable agents for new apps by default"})]}),(0,re.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,re.jsxs)("div",{className:"flex flex-col lg:flex-row lg:items-start gap-3",children:[(0,re.jsx)("div",{className:"text-gray-700 text-sm font-medium lg:w-48 lg:flex-shrink-0 lg:mt-2",children:"API Key"}),(0,re.jsxs)("div",{className:"flex-1 space-y-2",children:[(0,re.jsxs)("div",{className:"flex items-center gap-2",children:[(0,re.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,re.jsx)("div",{className:"text-black text-sm font-mono truncate",children:e.api_key})}),(0,re.jsxs)("button",{onClick:async()=>{try{await navigator.clipboard.writeText(e.api_key),c(!0),Xr.default.success("API key copied to clipboard!"),setTimeout(()=>c(!1),2e3)}catch(s){Xr.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,re.jsx)(Kr.A,{size:16}),o&&(0,re.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,re.jsxs)("button",{onClick:async()=>{i(!0);try{const t=await te.regenerateApiKey(e.id);s(t),Xr.default.success("API key regenerated successfully!")}catch(t){Xr.default.error("Failed to regenerate API key: "+(t.detail||t.message||"Unknown error"))}finally{i(!1)}},disabled:l,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,re.jsx)(ku.A,{size:14,className:l?"animate-spin":""}),(0,re.jsx)("div",{className:"text-black text-xs sm:text-sm font-medium hidden sm:block",children:l?"Regenerating...":"Regenerate"}),(0,re.jsx)("div",{className:"text-black text-xs font-medium sm:hidden",children:l?"Regen...":"Regen"})]})]}),(0,re.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,re.jsxs)("div",{className:"flex-shrink-0 p-4 bg-white border-t border-gray-200 flex justify-end items-center gap-3",children:[(0,re.jsx)("button",{onClick:()=>{if(e){const s=rx(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:s&&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,re.jsx)("button",{onClick:async()=>{n(!0);try{const t=await te.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:!!r&&d.enableBackendFunctionsByDefault,enable_agents_by_default:d.enableAgentsByDefault});s(t);const a=rx(t);m({email:t.email||"",fullName:t.full_name||"",phoneNumber:t.phone_number||"",profileImageUrl:t.profile_image_url||"",notificationPreference:t.notification_preference||"every_prompt",enableBackendFunctionsByDefault:a&&t.enable_backend_functions_by_default||!1,enableAgentsByDefault:t.enable_agents_by_default||!1}),Xr.default.success("Account settings updated successfully!")}catch(t){Xr.default.error("Failed to update account settings: "+(t.detail||t.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,re.jsx)("div",{className:"h-full flex items-center justify-center",children:(0,re.jsx)("div",{className:"animate-spin rounded-full h-8 w-8 border-t-2 border-b-2 border-gray-900"})})}function Nf(){const{user:e}=oe(),s=df(),[t,a]=(0,H.useState)([]),[n,r]=(0,H.useState)(!0),[l,i]=(0,H.useState)(null),o=()=>{window.open("/billing","_blank")},c=e=>{const s=parseInt(e);if(s>=1e3){const e=s/1e3;return"".concat(e%1==0?e:e.toFixed(1),"k")}return s.toString()};(0,H.useEffect)(()=>{(async()=>{try{r(!0);const e=await es.default.getMonthlyPlans();if(e&&e.plans){const s=["starter","builder","pro","elite"],t=e.plans.filter(e=>s.includes(e.tier)),n=t.sort((e,s)=>s.price_data.unit_amount-e.price_data.unit_amount).map(e=>((e,s)=>{var t,a;const n=(null===(t=s.metadata)||void 0===t?void 0:t.monthly_message_limit)||"0",r=(null===(a=s.metadata)||void 0===a?void 0:a.monthly_integration_credits)||"0",l=e.charAt(0).toUpperCase()+e.slice(1),i="pro"===e?"Upgrade to "+l:"Upgrade";return{name:l,monthlyCredits:c(n),integrationCredits:c(r),buttonText:i,isRecommended:"pro"===e,price:"$".concat(Math.round(s.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{r(!1)}})()},[]);return n?(0,re.jsx)("div",{className:"self-stretch px-10 bg-white inline-flex flex-col justify-start items-start gap-10",children:(0,re.jsxs)("div",{className:"self-stretch flex flex-col justify-start items-start gap-3",children:[(0,re.jsx)("div",{className:"text-black text-base font-semibold leading-normal",children:"Plan & Billing"}),(0,re.jsx)("div",{className:"flex items-center justify-center h-32",children:(0,re.jsx)("div",{className:"animate-spin rounded-full h-8 w-8 border-t-2 border-b-2 border-gray-900"})})]})}):l?(0,re.jsx)("div",{className:"self-stretch px-10 bg-white inline-flex flex-col justify-start items-start gap-10",children:(0,re.jsxs)("div",{className:"self-stretch flex flex-col justify-start items-start gap-3",children:[(0,re.jsx)("div",{className:"text-black text-base font-semibold leading-normal",children:"Plan & Billing"}),(0,re.jsx)("div",{className:"text-red-500 text-sm",children:l})]})}):(0,re.jsx)("div",{className:"self-stretch ".concat(s?"px-5 pt-6":"px-10"," bg-white inline-flex flex-col justify-start items-start gap-10"),children:(0,re.jsxs)("div",{className:"self-stretch flex flex-col justify-start items-start gap-3",children:[!s&&(0,re.jsx)("div",{className:"self-stretch flex flex-col justify-center items-start gap-2",children:(0,re.jsx)("div",{className:"justify-start text-black text-base font-semibold leading-normal",children:"Plan & Billing"})}),(0,re.jsxs)("div",{className:"self-stretch inline-flex justify-between items-center",children:[(0,re.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,re.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,re.jsx)("div",{className:"py-1.5 rounded-md flex flex-col justify-center items-center gap-2.5",children:(0,re.jsx)("div",{className:"inline-flex justify-center items-center gap-2.5",children:(0,re.jsx)("div",{className:"justify-start text-text-default text-xs font-medium leading-none",children:"Compare Plans"})})})})]}),(0,re.jsx)("div",{className:"self-stretch flex flex-col justify-start items-start",children:(0,re.jsx)("div",{className:"self-stretch inline-flex justify-start items-end gap-2",children:t.map(e=>{const s=e.isRecommended?"outline-orange-400":"outline-gray-200",t=e.isRecommended?"bg-orange-500":"bg-zinc-100",a=e.isRecommended?"text-white":"text-black";return(0,re.jsxs)("div",{className:"flex-1 rounded-xl outline outline-1 w-[171px] outline-offset-[-0.50px] ".concat(s," inline-flex flex-col justify-end items-start overflow-hidden"),children:[(0,re.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,re.jsxs)("div",{className:"self-stretch h-6 inline-flex justify-start items-start gap-1",children:[(0,re.jsx)("div",{className:"justify-center text-black text-sm font-normal",children:e.name}),e.isRecommended&&(0,re.jsx)("div",{className:"px-2 py-0.5 bg-red-100 rounded flex justify-center items-center gap-2.5",children:(0,re.jsx)("div",{className:"justify-center text-orange-500 text-xs font-medium leading-3",children:"Recommended"})})]}),(0,re.jsx)("div",{className:"self-stretch pt-1.5 inline-flex justify-start items-end gap-[3px]",children:(0,re.jsxs)("div",{className:"flex justify-start items-end gap-0.5",children:[(0,re.jsx)("div",{className:"justify-center text-black text-xl font-semibold",children:e.price}),(0,re.jsx)("div",{className:"w-7 h-6 justify-start text-stone-300 text-sm font-normal",children:"/mo"})]})}),(0,re.jsxs)("div",{className:"self-stretch pt-11 pb-3 flex flex-col justify-start items-start gap-1",children:[(0,re.jsxs)("div",{className:"self-stretch inline-flex justify-start items-start gap-1.5",children:[(0,re.jsx)("div",{className:"w-7 justify-center text-black text-xs font-semibold leading-none",children:e.monthlyCredits}),(0,re.jsx)("div",{className:"flex-1 justify-center text-zinc-600 text-xs font-normal leading-none",children:"monthly credits"})]}),(0,re.jsxs)("div",{className:"self-stretch inline-flex justify-start items-start gap-1.5",children:[(0,re.jsx)("div",{className:"w-7 justify-center text-black text-xs font-semibold leading-none",children:e.integrationCredits}),(0,re.jsx)("div",{className:"flex-1 justify-center text-zinc-600 text-xs font-normal leading-none",children:"integration credits"})]})]})]}),(0,re.jsx)("div",{className:"self-stretch p-2 inline-flex justify-center items-center gap-2.5",children:(0,re.jsx)("div",{className:"flex-1 h-8 ".concat(t," rounded-md inline-flex flex-col justify-center items-center overflow-hidden"),children:(0,re.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,re.jsx)("div",{className:"inline-flex flex-col justify-center items-start",children:(0,re.jsx)("div",{className:"self-stretch justify-start text-sm font-medium leading-normal ".concat(a),children:e.buttonText})})})})})]},e.name)})})})]})})}function wf(e){var s;let{handleModalClose:t}=e;const{user:a}=oe(),n=(0,Z.Zp)(),r=df(),{toast:l}=nn(),[i,o]=(0,H.useState)([]),[c,d]=(0,H.useState)(null),[m,u]=(0,H.useState)(!0),[x,h]=(0,H.useState)(null);(0,H.useEffect)(()=>{(async()=>{try{u(!0);const[e,s]=await Promise.all([Ji.getInvoices(),es.default.getStats()]);o(e.invoices||[]),d(s)}catch(e){h("Failed to load billing data")}finally{u(!1)}})()},[]);const p=async()=>{try{const e="past_due"===a.stripe_subscription_status?"payment_method_update":void 0,s=await Ji.createPortalSession(e);"past_due"===a.stripe_subscription_status?window.location.href=s.url:window.open(s.url,"_blank")}catch(x){l({variant:"destructive",title:"Error",description:"Failed to open payment management. Please try again."})}},g=function(e){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"USD";return new Intl.NumberFormat("en-US",{style:"currency",currency:s}).format(e)},f=e=>e?new Date(e).toLocaleDateString("en-US",{year:"numeric",month:"long",day:"numeric"}):"N/A",v=!0===(null==c||null===(s=c.stripe_subscription)||void 0===s?void 0:s.cancel_at_period_end),b=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,re.jsx)("div",{className:"self-stretch bg-white flex flex-col justify-start items-start h-full overflow-y-auto",style:{scrollbarGutter:"stable"},children:(0,re.jsxs)("div",{className:"w-full ".concat(r?"px-5 pt-6":"px-10 pt-0"," pb-10 flex flex-col justify-start items-start gap-10"),children:[(0,re.jsxs)("div",{className:"self-stretch flex flex-col justify-start items-start gap-3",children:[!r&&(0,re.jsx)("div",{className:"self-stretch flex flex-col justify-center items-start gap-2",children:(0,re.jsx)("div",{className:"justify-start text-black text-base font-semibold leading-normal",children:"Plan & Billing"})}),(0,re.jsxs)("div",{className:"self-stretch flex flex-col justify-start items-start gap-2",children:[(0,re.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,re.jsxs)("div",{className:"self-stretch inline-flex justify-between items-center",children:[(0,re.jsxs)("div",{className:"".concat(r?"text-sm flex-1 pr-2":"text-base"," justify-start text-text-default font-normal leading-normal"),children:["You're currently using the ",a.subscription_tier.charAt(0).toUpperCase()+a.subscription_tier.slice(1)," plan"]}),(0,re.jsxs)("div",{className:"flex justify-start items-center gap-2 flex-shrink-0",children:[!r&&(0,re.jsx)("div",{className:"inline-flex flex-col justify-start items-start",children:(0,re.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:p,children:(0,re.jsx)("div",{className:"inline-flex justify-center items-center gap-2.5",children:(0,re.jsx)("div",{className:"justify-start text-text-default text-sm font-medium leading-tight",children:"Manage Plan"})})})}),(0,re.jsx)("div",{className:"inline-flex flex-col justify-start items-start",children:(0,re.jsx)("div",{className:"".concat(r?"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?p():(n("/billing"),t())},children:(0,re.jsx)("div",{className:"inline-flex justify-center items-center gap-2.5",children:(0,re.jsx)("div",{className:"justify-start text-orange-500 ".concat(r?"text-xs":"text-sm"," font-medium leading-tight"),children:"past_due"===a.stripe_subscription_status?"Update Payment":"Upgrade Plan"})})})})]})]})}),(0,re.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,re.jsx)("div",{className:"justify-start text-gray-600 ".concat(r?"text-xs":"text-sm"," font-normal leading-tight"),children:a.subscription_period_end?v?"Your subscription will end on ".concat(f(a.subscription_period_end)):"Your subscription renews on ".concat(f(a.subscription_period_end)):"No active subscription"}),v&&(0,re.jsxs)("div",{className:"justify-start text-gray-500 ".concat("text-xs"," font-normal leading-tight"),children:["Want to keep your subscription? Click ",(0,re.jsx)("span",{className:"underline text-blue-500 cursor-pointer",onClick:p,children:"Manage Plan"})," and Cancel the change."]})]})]})]}),"past_due"===a.stripe_subscription_status&&(0,re.jsx)("div",{className:"self-stretch mt-0 p-4 bg-orange-50 border border-orange-200 rounded-lg",children:(0,re.jsxs)("div",{className:"flex items-start gap-3",children:[(0,re.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,re.jsx)("svg",{className:"w-3 h-3 text-white",fill:"currentColor",viewBox:"0 0 20 20",children:(0,re.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,re.jsxs)("div",{className:"flex-1",children:[(0,re.jsx)("h3",{className:"text-orange-800 font-medium text-sm mb-1",children:"Payment overdue"}),(0,re.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,re.jsxs)("div",{className:"self-stretch flex flex-col justify-start items-start gap-6",children:[(0,re.jsx)("div",{className:"self-stretch flex flex-col justify-center items-start gap-2",children:(0,re.jsx)("div",{className:"justify-start text-black text-base font-semibold leading-normal",children:"Billing History"})}),(0,re.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,re.jsx)("div",{className:"self-stretch text-center text-gray-500 py-8",children:"Loading billing history..."}),x&&(0,re.jsx)("div",{className:"self-stretch text-center text-red-500 py-8",children:x}),!m&&!x&&0===i.length&&(0,re.jsx)("div",{className:"self-stretch text-center text-gray-500 py-8",children:"No billing history available"}),!m&&!x&&i.map((e,s)=>{return(0,re.jsxs)(H.Fragment,{children:[(0,re.jsxs)("div",{className:"w-full inline-flex justify-start items-center",children:[(0,re.jsx)("div",{className:"w-40 pr-3 flex justify-start items-center gap-2.5",children:(0,re.jsx)("div",{className:"justify-start text-gray-800 text-sm font-normal leading-tight",children:(t=e.date,new Date(1e3*t).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"}))})}),(0,re.jsx)("div",{className:"w-28 px-3 flex justify-start items-center gap-2.5",children:(0,re.jsx)("div",{className:"justify-start text-gray-800 text-sm font-normal leading-tight",children:g(e.amount,e.currency)})}),(0,re.jsx)("div",{className:"w-28 px-3 flex justify-start items-center gap-2.5",children:(0,re.jsx)("div",{className:"px-2 py-0.5 rounded-[100px] outline outline-1 outline-offset-[-1px] ".concat(b(e.status).background," flex justify-center items-center gap-2.5"),children:(0,re.jsx)("div",{className:"justify-start text-xs font-medium leading-none ".concat(b(e.status).text),children:e.status.charAt(0).toUpperCase()+e.status.slice(1)})})}),!r&&(0,re.jsx)("div",{className:"flex-1 px-3 flex justify-start items-center gap-2.5",children:(0,re.jsx)("div",{className:"justify-start text-gray-800 text-sm font-normal leading-tight",children:e.description||"".concat(a.subscription_tier.charAt(0).toUpperCase()+a.subscription_tier.slice(1)," Plan")})}),(0,re.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,re.jsx)("div",{className:"relative cursor-pointer hover:text-blue-600",onClick:()=>{return s=e.invoice_pdf||e.hosted_invoice_url,void window.open(s,"_blank");var s},title:"Download Invoice",children:(0,re.jsxs)("svg",{width:"17",height:"16",viewBox:"0 0 17 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[(0,re.jsx)("path",{d:"M8.5 10V2",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round"}),(0,re.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,re.jsx)("path",{d:"M5.1665 6.6665L8.49984 9.99984L11.8332 6.6665",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round"})]})}):(0,re.jsx)("div",{className:"relative text-gray-400",title:"Invoice not available for download",children:(0,re.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,re.jsx)("path",{d:"M8.5 10V2",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round"}),(0,re.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,re.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);let s=(await xe.getWorkspaceInvoices(e.id)).invoices||[];n(s)}catch(s){o("Failed to load workspace billing history")}finally{l(!1)}})()},[null==e?void 0:e.id]);const c=function(e){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"USD";return new Intl.NumberFormat("en-US",{style:"currency",currency:s}).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,re.jsx)("div",{className:"self-stretch bg-white flex flex-col justify-start items-start h-full overflow-y-auto",style:{scrollbarGutter:"stable"},children:(0,re.jsxs)("div",{className:"w-full ".concat(s?"px-5 pt-6":"px-10 pt-0"," pb-10 flex flex-col justify-start items-start gap-10"),children:[(0,re.jsxs)("div",{className:"self-stretch flex flex-col justify-start items-start gap-3",children:[!s&&(0,re.jsx)("div",{className:"self-stretch flex flex-col justify-center items-start gap-2",children:(0,re.jsx)("div",{className:"justify-start text-black text-base font-semibold leading-normal",children:"Plan & Billing"})}),(0,re.jsxs)("div",{className:"self-stretch flex flex-col justify-start items-start gap-2",children:[(0,re.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,re.jsxs)("div",{className:"self-stretch inline-flex justify-between items-center",children:[(0,re.jsxs)("div",{className:"".concat(s?"text-sm flex-1 pr-2":"text-base"," justify-start text-text-default font-normal leading-normal"),children:["Managing billing for ",(0,re.jsx)("strong",{children:(null==e?void 0:e.name)||"workspace"})]}),(0,re.jsxs)("div",{className:"flex justify-start items-center gap-2 flex-shrink-0",children:[!s&&"owner"===(null==e?void 0:e.user_role)&&(0,re.jsx)("div",{className:"inline-flex flex-col justify-start items-start",children:(0,re.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 s=await xe.createWorkspacePortalSession(e.id);s.url&&window.open(s.url,"_blank")}catch(i){t({variant:"destructive",title:"Error",description:"Failed to open billing portal. Please try again later."})}},children:(0,re.jsx)("div",{className:"inline-flex justify-center items-center gap-2.5",children:(0,re.jsx)("div",{className:"justify-start text-text-default text-sm font-medium leading-tight",children:"Manage"})})})}),(0,re.jsx)("div",{className:"inline-flex flex-col justify-start items-start",children:(0,re.jsx)("div",{className:"".concat(s?"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,re.jsx)("div",{className:"inline-flex justify-center items-center gap-2.5",children:(0,re.jsx)("div",{className:"justify-start text-orange-500 ".concat(s?"text-xs":"text-sm"," font-medium leading-tight"),children:"Add Seats"})})})})]})]})}),(0,re.jsx)("div",{className:"justify-start text-gray-600 ".concat(s?"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,re.jsxs)("div",{className:"self-stretch flex flex-col justify-start items-start gap-6",children:[(0,re.jsx)("div",{className:"self-stretch flex flex-col justify-center items-start gap-2",children:(0,re.jsx)("div",{className:"justify-start text-black text-base font-semibold leading-normal",children:"Billing History"})}),(0,re.jsxs)("div",{className:"self-stretch flex flex-col justify-start items-start gap-4 pb-6 md:pb-8 lg:pb-10",children:[r&&(0,re.jsx)("div",{className:"self-stretch text-center text-gray-500 py-8",children:"Loading billing history..."}),i&&(0,re.jsx)("div",{className:"self-stretch text-center text-red-500 py-8",children:i}),!r&&!i&&0===a.length&&(0,re.jsx)("div",{className:"self-stretch text-center text-gray-500 py-8",children:"No billing history available"}),!r&&!i&&a.map((e,t)=>{return(0,re.jsxs)(H.Fragment,{children:[(0,re.jsxs)("div",{className:"w-full inline-flex justify-start items-center",children:[(0,re.jsx)("div",{className:"w-40 pr-3 flex justify-start items-center gap-2.5",children:(0,re.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,re.jsx)("div",{className:"w-28 px-3 flex justify-start items-center gap-2.5",children:(0,re.jsx)("div",{className:"justify-start text-gray-800 text-sm font-normal leading-tight",children:c(e.amount,e.currency)})}),(0,re.jsx)("div",{className:"w-28 px-3 flex justify-start items-center gap-2.5",children:(0,re.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,re.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)})})}),!s&&(0,re.jsx)("div",{className:"flex-1 px-3 flex justify-start items-center gap-2.5",children:(0,re.jsx)("div",{className:"justify-start text-gray-800 text-sm font-normal leading-tight",children:e.description||"Workspace Seats"})}),(0,re.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,re.jsx)("div",{className:"relative cursor-pointer hover:text-blue-600",onClick:()=>{return s=e.invoice_pdf||e.hosted_invoice_url,void window.open(s,"_blank");var s},title:"Download Invoice",children:(0,re.jsxs)("svg",{width:"17",height:"16",viewBox:"0 0 17 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[(0,re.jsx)("path",{d:"M8.5 10V2",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round"}),(0,re.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,re.jsx)("path",{d:"M5.1665 6.6665L8.49984 9.99984L11.8332 6.6665",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round"})]})}):(0,re.jsx)("div",{className:"relative text-gray-400",title:"Invoice not available for download",children:(0,re.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,re.jsx)("path",{d:"M8.5 10V2",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round"}),(0,re.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,re.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);const s=await xe.getMySeatInfo(e.id);a(s)}catch(s){i("Failed to load seat information")}finally{r(!1)}})()},[null==e?void 0:e.id]);const o=e=>{if(null==e||!e.user_seat)return"No seat assigned";const{user_seat:s}=e;return"assigned"===s.status&&s.seat_type?"".concat(s.seat_type," seat assigned"):"No seat assigned"},c=e=>"assigned"===e?{background:"outline-emerald-700",text:"text-emerald-700"}:{background:"outline-gray-500",text:"text-gray-500"};return(0,re.jsxs)("div",{className:"self-stretch ".concat(s?"px-5 pt-6":"px-10"," bg-white flex flex-col justify-start items-start gap-10"),children:[!s&&(0,re.jsx)("div",{className:"self-stretch flex flex-col justify-start items-start gap-3",children:(0,re.jsx)("div",{className:"self-stretch flex flex-col justify-center items-start gap-2",children:(0,re.jsx)("div",{className:"justify-start text-black text-base font-semibold leading-normal",children:"Plan & Billing"})})}),n?(0,re.jsxs)("div",{className:"self-stretch flex flex-col justify-center items-center py-16",children:[(0,re.jsx)("div",{className:"animate-spin rounded-full h-8 w-8 border-t-2 border-b-2 border-slate-700"}),(0,re.jsx)("div",{className:"mt-4 text-gray-600",children:"Loading seat information..."})]}):l?(0,re.jsx)("div",{className:"self-stretch flex flex-col justify-center items-center py-16",children:(0,re.jsx)("div",{className:"text-red-500 text-center",children:l})}):(0,re.jsxs)(re.Fragment,{children:[(0,re.jsxs)("div",{className:"self-stretch flex flex-col justify-start items-start gap-4",children:[(0,re.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,re.jsxs)("div",{className:"self-stretch inline-flex justify-between items-center",children:[(0,re.jsx)("div",{className:"justify-start text-text-default text-base font-normal leading-normal",children:(0,re.jsx)("strong",{children:(null==e?void 0:e.name)||"Workspace"})}),(0,re.jsx)("div",{className:"text-sm text-gray-600",children:(null==t?void 0:t.user_role)&&(0,re.jsxs)("span",{className:"capitalize",children:[t.user_role," access"]})})]})}),(0,re.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,re.jsxs)("div",{className:"self-stretch inline-flex justify-between items-center",children:[(0,re.jsx)("div",{className:"justify-start text-text-default text-base font-normal leading-normal",children:o(t)}),(0,re.jsx)("div",{className:"px-2 py-0.5 rounded-[100px] outline outline-1 outline-offset-[-1px] ".concat(c(null==t||null===(d=t.user_seat)||void 0===d?void 0:d.status).background," flex justify-center items-center gap-2.5"),children:(0,re.jsx)("div",{className:"justify-start text-xs font-medium leading-none ".concat(c(null==t||null===(m=t.user_seat)||void 0===m?void 0:m.status).text),children:"assigned"===(null==t||null===(u=t.user_seat)||void 0===u?void 0:u.status)?"Active":"No Seat"})})]})}),"assigned"===(null==t||null===(x=t.user_seat)||void 0===x?void 0:x.status)&&(0,re.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,re.jsxs)("div",{className:"self-stretch flex flex-col gap-2",children:[(0,re.jsx)("div",{className:"text-sm font-medium text-gray-700",children:"Seat Details"}),t.user_seat.seat_id&&(0,re.jsxs)("div",{className:"text-sm text-gray-600",children:["Seat ID: ",t.user_seat.seat_id]}),(0,re.jsxs)("div",{className:"text-sm text-gray-600",children:["Plan: ",t.user_seat.seat_type]})]})}),(null==e?void 0:e.subscription_period_end)&&(0,re.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==t?void 0:t.workspace_admins)&&t.workspace_admins.length>0&&(0,re.jsxs)("div",{className:"self-stretch flex flex-col justify-start items-start gap-6",children:[(0,re.jsx)("div",{className:"self-stretch flex flex-col justify-center items-start gap-2",children:(0,re.jsx)("div",{className:"justify-start text-black text-base font-semibold leading-normal",children:"Workspace Administrators"})}),(0,re.jsxs)("div",{className:"self-stretch flex flex-col justify-start items-start gap-4",children:[(0,re.jsx)("div",{className:"justify-start text-gray-600 text-sm font-normal leading-tight",children:"Contact your workspace administrators for seat assignments:"}),(0,re.jsx)("div",{className:"self-stretch flex flex-col justify-start items-start gap-2",children:t.workspace_admins.map((e,s)=>(0,re.jsxs)("div",{className:"self-stretch px-4 py-2 bg-gray-50 rounded-lg flex justify-between items-center",children:[(0,re.jsx)("div",{className:"text-sm text-gray-800",children:e.email}),(0,re.jsx)("div",{className:"text-xs text-gray-600 capitalize",children:e.role})]},e.email))})]})]}),"assigned"!==(null==t||null===(h=t.user_seat)||void 0===h?void 0:h.status)&&(0,re.jsxs)("div",{className:"self-stretch flex flex-col justify-start items-start gap-6",children:[(0,re.jsx)("div",{className:"self-stretch flex flex-col justify-center items-start gap-2",children:(0,re.jsx)("div",{className:"justify-start text-black text-base font-semibold leading-normal",children:"Need a Seat?"})}),(0,re.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,re.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 Af(e){let{handleModalClose:s}=e;const{user:t}=oe(),{activeWorkspace:a}=ge();if(a&&!a.is_personal){return a.user_role&&["admin","owner"].includes(a.user_role)?(0,re.jsx)(_f,{}):(0,re.jsx)(kf,{})}return t.stripe_customer_id||t.stripe_subscription_status?(0,re.jsx)(wf,{handleModalClose:s}):(0,re.jsx)(Nf,{})}const Sf="workspace",Cf="account",Ef="plan-billing",If=[{key:Sf,label:"Workspace"},{key:Ef,label:"Plan & Billing"},{key:Cf,label:"Account"}];function Tf(e){let{isOpen:s,onClose:t}=e;const[a,n]=(0,H.useState)(Sf),[r,l]=(0,H.useState)("sidebar"),[i,o]=(0,H.useState)(0),[c,d]=(0,H.useState)(!1),[m,u]=(0,H.useState)(0),[x,h]=(0,H.useState)(!1),p=(0,H.useRef)(0),g=(0,H.useRef)(0),f=(0,H.useRef)(null),v=df();(0,H.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,H.useEffect)(()=>{if(v&&s){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,s]);const b=e=>{n(e),v&&l("content")},j=()=>{l("sidebar")},y=()=>{v&&(l("sidebar"),o(0),d(!1),u(0),h(!1),f.current=null),t()},N=(0,H.useCallback)(e=>{v&&(e.stopPropagation(),p.current=e.touches[0].clientY,d(!0))},[v]),w=(0,H.useCallback)(e=>{if(!v||!c)return;e.preventDefault(),e.stopPropagation();const s=e.touches[0].clientY-p.current;s>0&&o(s)},[v,c]),_=(0,H.useCallback)(e=>{v&&c&&(e.stopPropagation(),d(!1),i>150?y():o(0))},[v,c,i,y]),k=(0,H.useCallback)(e=>{v&&"content"===r&&(e.stopPropagation(),g.current=e.touches[0].clientX,p.current=e.touches[0].clientY,f.current=null)},[v,r]),A=(0,H.useCallback)(e=>{if(!v||"content"!==r)return;const s=e.touches[0].clientX,t=e.touches[0].clientY,a=s-g.current,n=t-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,r,x]),S=(0,H.useCallback)(e=>{v&&"content"===r&&(e.stopPropagation(),x&&(h(!1),m>100&&j(),u(0)),f.current=null)},[v,r,x,m,j]),C=()=>{switch(a){case Sf:return(0,re.jsx)(ff,{});case Cf:return(0,re.jsx)(yf,{});case Ef:return(0,re.jsx)(Af,{handleModalClose:y});default:return(0,re.jsx)(ff,{})}};var E;return v?(0,re.jsxs)(Pa,{open:s,onOpenChange:y,children:[(0,re.jsx)("div",{className:"fixed inset-0 z-50 bg-black/80 transition-opacity duration-300",style:{opacity:s?.8:0,pointerEvents:s?"auto":"none",touchAction:"none"},onTouchStart:e=>e.preventDefault(),onTouchMove:e=>e.preventDefault(),onTouchEnd:e=>e.preventDefault()}),(0,re.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(s?"".concat(i,"px"):"100%",")"),transition:c?"none":"transform 0.3s ease-out",touchAction:"none"},onTouchStart:N,onTouchMove:w,onTouchEnd:_,children:(0,re.jsxs)("div",{className:"w-full h-full bg-white rounded-t-xl flex flex-col overflow-hidden relative",children:[(0,re.jsx)("div",{className:"w-full flex justify-center pt-2 pb-1",children:(0,re.jsx)("div",{className:"w-10 h-1 bg-gray-300 rounded-full"})}),(0,re.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"===r?(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)("div",{className:"text-black text-lg font-bold",children:"Settings"}),(0,re.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,re.jsx)(zs.A,{size:18})})]}):(0,re.jsxs)(re.Fragment,{children:[(0,re.jsxs)("div",{className:"absolute left-3 flex items-center",children:[(0,re.jsx)("button",{onClick:j,className:"w-8 h-8 flex items-center justify-center hover:bg-gray-100 rounded-full",children:(0,re.jsx)(Qt.A,{size:18})}),(0,re.jsx)("button",{onClick:j,className:"text-gray-600 text-sm font-medium hover:text-gray-800 transition-colors -ml-1.5",children:"Settings"})]}),(0,re.jsx)("div",{className:"text-black text-lg font-bold",children:null===(E=If.find(e=>e.key===a))||void 0===E?void 0:E.label}),(0,re.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,re.jsx)(zs.A,{size:18})})]})}),(0,re.jsxs)("div",{className:"flex-1 overflow-hidden relative",children:[x&&m>0&&(0,re.jsx)("div",{className:"absolute inset-0 bg-black/10 z-10 pointer-events-none",style:{opacity:Math.min(m/100,.3)}}),(0,re.jsxs)("div",{className:"flex w-[200%] h-full transition-transform duration-300 ease-in-out",style:{transform:"sidebar"===r?"translateX(0%)":"translateX(calc(-50% + ".concat(m,"px))"),transition:x?"none":"transform 0.3s ease-in-out"},children:[(0,re.jsx)("div",{className:"w-1/2 h-full overflow-y-auto",children:(0,re.jsx)("div",{className:"flex flex-col space-y-2 px-2 py-4",children:If.map(e=>(0,re.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,re.jsx)("div",{className:"text-base",children:e.label}),(0,re.jsx)(ln.A,{size:20,className:"text-gray-400"})]},e.key))})}),(0,re.jsxs)("div",{className:"w-1/2 h-full relative",onTouchStart:k,onTouchMove:A,onTouchEnd:S,children:["content"===r&&!x&&(0,re.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"}),C()]})]})]})]})})]}):(0,re.jsx)(Pa,{open:s,onOpenChange:y,children:(0,re.jsx)(Ma,{className:"max-w-6xl w-[90vw] max-w-[1000px] h-[90vh] p-0 [&>button]:hidden",children:(0,re.jsxs)("div",{className:"w-full h-full bg-white rounded-xl flex overflow-hidden",children:[(0,re.jsxs)("div",{className:"w-52 flex-shrink-0 bg-gray-50 border-r border-gray-200 flex flex-col",children:[(0,re.jsx)("div",{className:"px-4 py-6 flex items-center",children:(0,re.jsx)("div",{className:"text-black text-lg font-bold",children:"Settings"})}),(0,re.jsx)("div",{className:"flex flex-col space-y-1 px-3",children:If.map(e=>(0,re.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,re.jsx)("div",{className:"text-sm",children:e.label})},e.key))})]}),(0,re.jsxs)("div",{className:"flex-1 flex flex-col min-w-0",children:[(0,re.jsx)("div",{className:"flex-shrink-0 p-3 bg-white flex justify-end items-center",children:(0,re.jsx)("button",{onClick:y,className:"w-6 h-6 flex items-center justify-center hover:bg-gray-100 rounded",children:(0,re.jsx)(zs.A,{size:16})})}),(0,re.jsx)("div",{className:"flex-1 min-h-0",children:C()})]})]})})})}const Pf=e=>{let{app:s,currentUsage:t,onShareModalOpen:a,onLogout:n,user:r}=e;const[l,i]=(0,H.useState)(!1),o="Upgrade Plan",c=e=>{var t,a;Ie("User clicked upgrade",{app_id:(null==s?void 0:s.id)||null,user_id:(null==r?void 0:r.id)||null,conversation_id:(null==s||null===(t=s.conversation)||void 0===t?void 0:t.id)||null,cta:e,origin:"editor account menu",target_route:"/billing"}),We({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:e,origin:"editor account menu",target_route:"/billing"})};return(0,re.jsxs)(re.Fragment,{children:[(0,re.jsxs)(af,{children:[(0,re.jsx)(nf,{asChild:!0,children:(0,re.jsxs)("div",{className:"flex items-center gap-3 cursor-pointer flex-1 p-1 rounded-md hover:bg-gray-200 transition-colors",children:[(0,re.jsx)(ir,{className:"h-6 w-6 rounded-xl",children:(0,re.jsx)(or,{src:Ge,alt:"Base44"})}),(0,re.jsx)("div",{className:"flex-1 min-w-0",children:(0,re.jsx)(It.A,{className:"h-4 w-4 text-muted-foreground"})})]})}),(0,re.jsxs)(rf,{align:"start",className:"w-[240px] p-2 shadow-lg border border-slate-200 rounded-lg",children:[(0,re.jsx)(lf,{asChild:!0,children:(0,re.jsxs)(J.Link,{to:"/",className:"flex items-center gap-2 cursor-pointer",children:[(0,re.jsx)(Qt.A,{className:"h-4 w-4"}),(0,re.jsx)("span",{children:"Back to Workspace"})]})}),(0,re.jsx)(cf,{}),(0,re.jsx)(of,{asChild:!0,children:(0,re.jsx)("div",{className:"px-2 py-1.5 text-gray-500",children:null==r?void 0:r.email})}),t&&(0,re.jsxs)("div",{className:"border border-slate-200 rounded-[10px] p-2 my-2",children:[(0,re.jsx)(of,{children:(0,re.jsxs)("div",{className:"flex justify-between",children:[(0,re.jsx)("span",{children:"Credits"}),(0,re.jsx)("span",{className:"text-xs bg-slate-100 px-2 py-0.5 rounded",children:t.tier.charAt(0).toUpperCase()+t.tier.slice(1).toLowerCase()})]})}),(0,re.jsxs)("div",{className:"px-2 py-1.5",children:[(0,re.jsxs)("div",{className:"flex justify-between text-xs mb-1",children:[(0,re.jsx)("span",{children:"Monthly Credits"}),(0,re.jsxs)("span",{children:[(d=t.monthly_usage,d%1==0?d:d.toFixed(1)),"/",t.monthly_limit,t.extra_credits>0&&" (+".concat(t.extra_credits,")")]})]}),(0,re.jsx)("div",{className:"w-full bg-gray-200 rounded-full h-1.5",children:(0,re.jsx)("div",{className:"h-1.5 rounded-full ".concat(t.is_over_limit?"bg-red-500":"bg-primary"),style:{width:"".concat(Math.min(t.monthly_usage/t.monthly_limit*100,100),"%")}})})]}),t.daily_limit&&(0,re.jsx)("div",{className:"px-2 py-1.5",children:(0,re.jsxs)("div",{className:"flex justify-between text-xs",children:[(0,re.jsx)("span",{children:"Daily Credits"}),(0,re.jsxs)("span",{children:[t.daily_usage,"/",t.daily_limit]})]})}),(0,re.jsxs)("div",{className:"px-2 pb-1 text-xs text-muted-foreground",children:["Credits renew on: ",t.next_period_start_date]})]}),t&&a&&(0,re.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,re.jsx)(Yg.A,{className:"h-4 w-4 mr-2 text-blue-600"}),(0,re.jsx)("span",{className:"text-sm flex-1 text-blue-600",children:"Win Free Credits"}),(0,re.jsx)(ln.A,{className:"h-4 w-4 text-blue-600"})]}),(0,re.jsx)(cf,{}),(0,re.jsx)(lf,{asChild:!0,children:(0,re.jsxs)(J.Link,{to:"https://docs.base44.com",className:"flex items-center gap-2 cursor-pointer",target:"_blank",children:[(0,re.jsx)(Hg.A,{className:"h-4 w-4"}),(0,re.jsx)("span",{children:"Documentation"})]})}),(0,re.jsxs)(lf,{onClick:()=>i(!0),className:"flex items-center gap-2 cursor-pointer",children:[(0,re.jsx)(od.A,{className:"h-4 w-4"}),(0,re.jsx)("span",{children:"Settings"})]}),(0,re.jsx)(lf,{asChild:!0,children:(0,re.jsxs)(J.Link,{target:"_blank",onClick:()=>c("Billing"),to:"/billing",className:"flex items-center gap-2 cursor-pointer",children:[(0,re.jsx)(Ke.A,{className:"h-4 w-4"}),(0,re.jsx)("span",{children:"Billing"})]})}),(0,re.jsx)(lf,{asChild:!0,children:(0,re.jsxs)(J.Link,{target:"_blank",to:"/support?appId=".concat(null==s?void 0:s.id),className:"flex items-center gap-2 cursor-pointer",children:[(0,re.jsx)(jo.A,{className:"h-4 w-4"}),(0,re.jsx)("span",{children:"Help Center"})]})}),(0,re.jsx)(lf,{asChild:!0,children:(0,re.jsxs)(J.Link,{target:"_blank",to:"/billing",className:"flex items-center gap-2 cursor-pointer",onClick:()=>c(o),children:[(0,re.jsx)(Gg.A,{className:"h-4 w-4 text-orange-600 group-hover:text-orange-700"}),(0,re.jsx)("span",{className:"text-orange-600 group-hover:text-orange-700",children:o})]})}),(0,re.jsx)(cf,{}),(0,re.jsxs)(lf,{onClick:n,className:"flex items-center gap-2 cursor-pointer text-gray-800 hover:bg-gray-100",children:[(0,re.jsx)($g.A,{className:"h-4 w-4"}),(0,re.jsx)("span",{children:"Sign Out"})]})]})]}),(0,re.jsx)(Tf,{isOpen:l,onClose:()=>i(!1)})]});var d},Lf={"#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."},Of=e=>{let{children:s,menuControl:t,toggleControl:a,actionControl:n,isMobile:r}=e;return r?(0,re.jsxs)("div",{className:"flex flex-col h-full overflow-hidden",children:[(0,re.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b",children:[(0,re.jsx)("div",{className:"w-[60px] flex justify-start",children:(0,re.jsx)(Rf,{})}),(0,re.jsx)("div",{className:"flex-1 flex justify-center",children:a}),(0,re.jsx)("div",{className:"w-[60px] flex justify-end",children:n})]}),(0,re.jsx)("div",{className:"flex-1 overflow-auto",children:s})]}):(0,re.jsxs)("div",{className:"flex flex-col h-full overflow-hidden pr-2",children:[(0,re.jsxs)("div",{className:"flex items-center justify-between py-1",children:[(0,re.jsx)("div",{className:"flex items-center gap-2",children:t}),(0,re.jsx)("div",{children:n})]}),(0,re.jsx)("div",{className:"flex-1 overflow-auto border border-slate-200 rounded-[10px] mb-2",children:s})]})},Rf=()=>{const{app:e,currentUsage:s}=_s(),{logout:t,user:a}=oe(),n=(0,Z.Zp)();return(0,re.jsx)(Pf,{app:e,currentUsage:s,onShareModalOpen:null,onLogout:()=>{t(),n("/login")},user:a})};function Df(e){var s,t;let{view:a,selectedCheckpoint:n,setSelectedCheckpoint:r,isLeftPanelHidden:l,toggleLeftPanel:i}=e;const{user:o}=oe(),{app:c,updateApp:d,undoMessage:m,appErrors:u,addChatMessage:x,setAppErrors:h,onAppError:p,runtimeAuthToken:g}=_s(),f=(0,H.useRef)(null),[v,b]=(0,H.useState)(!1),[j,y]=(0,H.useState)(!1),[N,w]=(0,H.useState)(!1),_=(0,Z.Zp)(),k=(0,Z.zy)(),A=(0,Qe.Ub)({maxWidth:767}),[S,C]=(0,H.useState)(!1),[E,I]=(0,H.useState)("overview"),T=e=>{if(f.current){const s=e||f.current.src;f.current.src="",setTimeout(()=>{f.current&&(f.current.src=s)},50)}};(0,H.useEffect)(()=>{var e,s;n?"workspace"===a.toLowerCase()?_("/apps/".concat(c.id,"/editor/preview/").concat(c.main_page)):T(L()):(null===(e=c.conversation)||void 0===e||null===(s=e.messages)||void 0===s?void 0:s.length)<=2?setTimeout(()=>{T(L())},1e3):T(L())},[n,a,c.app_code_hash]);const P=async()=>{if(window.confirm("Are you sure you want to restore this checkpoint? This action is irreversible.")){w(!0);try{await ol.loadCheckpoint(c.id,n.id),r(void 0)}catch(e){}finally{w(!1)}}};function L(){const e=window.location.pathname.split("/preview")[1],s=n?function(e,s){return va("checkpoint--".concat(e.id,"--").concat(s.id))}(c,n):function(e){return va("preview--".concat(e.slug))}(c),t=new URLSearchParams({access_token:g,hide_badge:"true"});return"".concat(s).concat(e,"?").concat(t.toString())}(0,H.useEffect)(()=>{if(c.slug&&f.current&&!f.current.src.includes(c.slug)){const e=L();f.current.src=e,setTimeout(()=>{f.current&&(f.current.src=e)},50)}return window.addEventListener("message",R),()=>{window.removeEventListener("message",R)}},[c.slug,null==f?void 0:f.current]),(0,H.useEffect)(()=>{if(k.pathname.includes("/workspace/")){const e=k.pathname.split("/workspace/");if(e.length>1){const s=e[1],t=k.search?"".concat(s).concat(k.search):s;I(t)}}},[k.pathname,k.search]);const O=async()=>{b(!0);const e=e=>{const s=(e=>{if(e.title&&e.title.includes("Minified React error"))for(const[s,t]of Object.entries(Lf))if(e.title.includes("Minified React error ".concat(s)))return(0,K.A)((0,K.A)({},e),{},{details:t});return e})(e),t=ts().escape(s.title),a=ts().escape(s.details||"no details");ts().escape(s.componentName);return'\n\n')+"\n\n"},s=u.map(s=>e(s)).join("\n\n"),t="the following errors happened in the app:\n".concat(s,"\n---\nplease help me fix these errors");(async e=>{try{var s,t;Ie("User clicked resolve with AI",{user_id:(null==o?void 0:o.id)||null,app_id:c.id,app_name:c.name,conversation_id:(null==c||null===(s=c.conversation)||void 0===s?void 0:s.id)||null,error_message:e}),We({user_id:(null==o?void 0:o.id)||null,app_id:(null==c?void 0:c.id)||null,conversation_id:(null==c||null===(t=c.conversation)||void 0===t?void 0:t.id)||null},{cta:"resolve with ai",origin:"editor",target_route:"same_page",error_message:e})}catch(a){}})(t),await x({role:"user",content:t}),b(!1)},R=e=>{var s,t;if("app_error"===(null===(s=e.data)||void 0===s?void 0:s.type)&&e.data.error&&p(e.data.error.title,e.data.error.details,e.data.error.componentName),"app_changed_url"===(null===(t=e.data)||void 0===t?void 0:t.type)&&e.data.url&&window.location.href.includes("/preview")){const s=new URL(e.data.url),t=s.pathname,a=new URLSearchParams(s.search);a.delete("access_token"),a.delete("hide_badge");let n=t;if(t.startsWith("/apps"))return n="/"+t.split("/").pop(),n.includes("".concat(c.slug))?void 0:void _("/apps/".concat(c.id,"/editor/preview").concat(n));"/"===t||t==="/".concat(c.slug)?n="/apps/".concat(c.id,"/editor/preview/").concat(c.main_page):t.startsWith("/apps")||t.includes("".concat(c.slug))||(n="/apps/".concat(c.id,"/editor/preview").concat(t));const r=a.toString();r&&(n+="?".concat(r)),A||_(n)}},D=(0,re.jsxs)("div",{className:"flex items-center gap-2",children:[!A&&(0,re.jsxs)("div",{className:"flex items-center gap-2",children:[(0,re.jsxs)(Ts,{children:[(0,re.jsx)(Ps,{asChild:!0,children:(0,re.jsx)("button",{onClick:i,className:"p-1.5 text-gray-500 hover:bg-gray-200 rounded-md transition-colors",children:l?(0,re.jsx)(dg.A,{size:16}):(0,re.jsx)(mg.A,{size:16})})}),(0,re.jsx)(Ls,{children:(0,re.jsx)("p",{children:l?"Show chat panel":"Hide chat panel"})})]}),(0,re.jsx)("div",{className:"h-6 w-[1px] bg-gray-300"})]}),(0,re.jsx)(hl,{value:"preview"===a?"preview":"workspace",onValueChange:e=>{"workspace"===e.toLowerCase()?_("/apps/".concat(c.id,"/editor/workspace/").concat(E)):_("/apps/".concat(c.id,"/editor/preview/").concat(c.main_page))},children:(0,re.jsxs)(pl,{className:"h-7 rounded-lg",children:[(0,re.jsx)(gl,{value:"workspace",className:"h-6 rounded-md cursor-pointer",children:"Dashboard"}),(0,re.jsx)("div",{className:"h-6 w-[2px] bg-gray-100"}),(0,re.jsx)(gl,{value:"preview",className:"h-6 rounded-md cursor-pointer",children:"Preview"})]})}),!A&&(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)("div",{children:(0,re.jsxs)(Ts,{children:[(0,re.jsx)(Ps,{asChild:!0,children:(0,re.jsx)("button",{onClick:()=>T(),className:"p-1.5 text-gray-500 hover:bg-gray-200 rounded-md transition-colors",children:(0,re.jsx)(ku.A,{size:16})})}),(0,re.jsx)(Ls,{children:(0,re.jsx)("p",{children:"Refresh preview"})})]})}),(0,re.jsx)("div",{children:"preview"===a&&(0,re.jsxs)(Ts,{children:[(0,re.jsx)(Ps,{asChild:!0,children:(0,re.jsx)(hl,{defaultValue:S?"mobile":"desktop",children:(0,re.jsxs)(pl,{className:"h-7 rounded-lg",children:[(0,re.jsx)(gl,{value:"desktop",onClick:()=>C(!1),className:"h-6 rounded-md",children:(0,re.jsx)(ug.A,{size:15})}),(0,re.jsx)("div",{className:"h-6 w-[2px] bg-gray-100"}),(0,re.jsx)(gl,{value:"mobile",onClick:()=>C(!0),className:"h-6 rounded-md",children:(0,re.jsx)(xg.A,{size:15})})]})})}),(0,re.jsx)(Ls,{children:(0,re.jsx)("p",{children:S?"Switch to desktop view":"Switch to mobile view"})})]})})]})]}),M=(0,re.jsx)("div",{className:"flex items-center gap-2",children:(0,re.jsxs)(Is,{children:[(0,re.jsxs)(Ts,{children:[(0,re.jsx)(Ps,{asChild:!0,children:(0,re.jsx)(Tg,{})}),(0,re.jsx)(Ls,{children:(0,re.jsx)("p",{children:"Network requests"})})]}),(0,re.jsxs)(Ts,{children:[(0,re.jsx)(Ps,{asChild:!0,children:(0,re.jsx)(jg,{showFiles:"preview"===a})}),(0,re.jsx)(Ls,{children:(0,re.jsx)("p",{children:"Github & code editing"})})]}),(0,re.jsxs)(Ts,{children:[(0,re.jsx)(Ps,{asChild:!0,children:(0,re.jsx)(Hs,{onClick:()=>y(!0),variant:"outline",size:"sm",className:"gap-2",children:"Share"})}),(0,re.jsx)(Ls,{children:(0,re.jsx)("p",{children:"Share app"})})]}),(0,re.jsx)(Vg,{app:c,updateApp:d})]})}),F=(0,re.jsxs)("div",{className:"flex items-center gap-4 py-2",children:[(0,re.jsx)("p",{className:"text-sm font-medium",children:"Viewing checkpoint version"}),(0,re.jsxs)("div",{className:"flex items-center gap-2",children:[(0,re.jsx)(Hs,{variant:"outline",size:"sm",className:"h-8",onClick:P,disabled:N,children:N?(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(hg.A,{className:"mr-2 h-3 w-3 animate-spin"}),"Restoring..."]}):"Restore this version"}),(0,re.jsx)(Hs,{variant:"secondary",size:"sm",className:"h-8",onClick:()=>r(void 0),disabled:N,children:"Exit"})]})]}),B=(0,re.jsx)("div",{className:"flex items-center",children:(0,re.jsx)(Vg,{app:c,isMobile:"icon"})});return(0,re.jsxs)("div",{className:"flex-grow h-full overflow-y-auto",children:[(0,re.jsx)(Of,{isMobile:A,menuControl:A||n?null:D,toggleControl:A?D:null,actionControl:A?B:n?F:M,children:"preview"===a?(0,re.jsx)("div",{className:"w-full h-full flex justify-center ".concat(S?"items-start pt-4":""),children:(0,re.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:f,id:"preview-iframe",className:"transition-all duration-300 ease-in-out ".concat(S?"w-[375px] h-[667px] border border-gray-300 rounded-xl shadow-md":"w-full h-full"),style:A&&!S?{height:"100vh"}:{}})}):(0,re.jsx)(cg,{})}),(0,re.jsx)(ru,{isVisible:j,onCancel:()=>y(!1),onInviteSuccess:()=>y(!1)}),n&&!A&&(0,re.jsx)("div",{className:"fixed top-0 left-0 right-0 z-50 bg-slate-50",children:(0,re.jsx)("div",{className:"max-w-4xl mx-auto px-4 pt-2",children:(0,re.jsxs)("div",{className:"flex items-center justify-between",children:[(0,re.jsxs)("div",{className:"flex items-center gap-3",children:[(0,re.jsx)("div",{className:"w-2 h-2 bg-orange-400 rounded-full"}),(0,re.jsxs)("div",{children:[(0,re.jsx)("p",{className:"text-sm font-medium text-slate-800",children:"Viewing Version History"}),(0,re.jsx)("p",{className:"text-xs text-slate-500",children:n.title})]})]}),(0,re.jsxs)("div",{className:"flex items-center gap-2",children:[(0,re.jsx)(Hs,{variant:"outline",size:"sm",className:"h-8 text-xs",onClick:P,disabled:N,children:N?(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(hg.A,{className:"mr-2 h-3 w-3 animate-spin"}),"Restoring..."]}):"Restore This Version"}),(0,re.jsx)(Hs,{variant:"ghost",size:"sm",className:"h-8 text-xs text-slate-600",onClick:()=>r(void 0),disabled:N,children:"Exit"})]})]})})}),u.length>0&&(0,re.jsx)("div",{className:"fixed ".concat(A?"bottom-2 right-2 left-2 z-50 max-w-full":"bottom-4 right-4 z-50 max-w-md"," bg-white rounded-lg shadow-xl p-4 border border-gray-100"),children:(0,re.jsxs)("div",{className:"flex flex-col gap-3",children:[(0,re.jsxs)("div",{className:"flex justify-between items-center",children:[(0,re.jsx)("div",{className:"font-medium text-gray-800",children:"Issues Found"}),(0,re.jsx)("button",{onClick:()=>h([]),className:"p-1 hover:bg-gray-100 rounded-md",children:(0,re.jsx)(zs.A,{size:16})})]}),u.map(e=>(0,re.jsxs)("div",{className:"text-sm text-gray-600",children:[e.componentName&&(0,re.jsxs)("div",{className:"text-xs text-gray-500 mb-1",children:["In ",e.componentName," component:"]}),e.title]},e.title)),(0,re.jsx)("button",{onClick:()=>O(),disabled:"processing"===(null===(s=c.status)||void 0===s?void 0:s.state)||v,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=c.status)||void 0===t?void 0:t.state)?"opacity-50 cursor-not-allowed":""),children:"Resolve with AI"}),"free"!==o.subscription_tier&&(0,re.jsx)("div",{className:"text-xs text-gray-500 mt-1 italic",children:"This action won't deduct credits from your account."})]})})]})}var Mf=t(28017);const Ff=e=>{try{const s=rl(e,"action_group");if(s.length>0)for(const e of s){const s=e.openingTag.match(/title=["']([^"']*)["']/i);if(s&&s[1])return s[1]}const t=/# (.*)/,a=e.match(t);if(a)return a[1]}catch(s){}return"Untitled Version"},Bf=e=>{let{onClose:s,selectedCheckpoint:t,onSelectCheckpoint:a}=e;const{app:n}=_s(),[r,l]=(0,H.useState)(!1),[i,o]=(0,H.useState)([]),[c,d]=(0,H.useState)([]),[m,u]=(0,H.useState)(!1),[x,h]=(0,H.useState)(!0);(0,H.useEffect)(()=>{!async function(){try{h(!0);const e=await ol.listCheckpoints(n.id),s=n.conversation.messages.filter(e=>e.checkpoint_id&&e.content.includes("action_group")),t=s.map(e=>e.checkpoint_id);let a={};e.forEach(e=>{a[e.id]=e});const r=s.map(e=>{var s,t;return{id:e.checkpoint_id,timestamp:(null===(s=e.metadata)||void 0===s?void 0:s.created_date)||(new Date).toISOString(),title:(null===(t=a[e.checkpoint_id])||void 0===t?void 0:t.name)||Ff(e.content)}}).reverse();o(r);const l=e.filter(e=>!t.includes(e.id));d(l.map(e=>({id:e.id,timestamp:e.created_date,title:e.name})))}catch(e){}finally{h(!1)}}()},[]);const p=e=>{const s=la().utc(e);return{relative:s.fromNow(),absolute:s.format("MMM D, YYYY [at] h:mm A")}},g=e=>{a(e)};return x?(0,re.jsxs)("div",{className:"flex flex-col h-full p-4",children:[(0,re.jsxs)("div",{className:"flex items-center mb-4",children:[(0,re.jsx)(Hs,{variant:"ghost",size:"icon",onClick:s,children:(0,re.jsx)(Cc.A,{className:"h-4 w-4"})}),(0,re.jsx)("h2",{className:"text-lg font-semibold ml-2",children:"Version History"})]}),(0,re.jsx)("div",{className:"space-y-4",children:[1,2,3].map(e=>(0,re.jsxs)("div",{className:"border border-gray-200 dark:border-gray-700 rounded-lg p-4 animate-pulse",children:[(0,re.jsx)("div",{className:"h-4 bg-gray-200 dark:bg-gray-700 rounded mb-2 w-3/4"}),(0,re.jsx)("div",{className:"h-3 bg-gray-200 dark:bg-gray-700 rounded w-1/2"})]},e))})]}):(0,re.jsxs)("div",{className:"flex flex-col h-full p-4",children:[(0,re.jsxs)("div",{className:"flex items-center mb-4",children:[(0,re.jsx)(Hs,{variant:"ghost",size:"icon",onClick:s,children:(0,re.jsx)(Cc.A,{className:"h-4 w-4"})}),(0,re.jsx)("h2",{className:"text-lg font-semibold ml-2",children:"Version History"})]}),(0,re.jsx)("div",{className:"space-y-4",children:i.map(e=>{const{relative:s,absolute:a}=p(e.timestamp);return(0,re.jsxs)("div",{className:"border border-gray-200 dark:border-gray-700 rounded-lg p-4 relative cursor-pointer transition-all ".concat((null==t?void 0:t.id)===e.id?"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:()=>g(e),children:[(0,re.jsx)("div",{className:"mb-2 font-medium pr-8",children:e.title}),(0,re.jsxs)("div",{className:"text-xs text-gray-400",children:[(0,re.jsx)("div",{className:"font-medium",children:s}),(0,re.jsx)("div",{className:"opacity-75",children:a})]}),(null==t?void 0:t.id)===e.id&&(0,re.jsx)("div",{className:"absolute top-2 right-2",children:(0,re.jsx)(Pt.A,{className:"h-4 w-4 text-blue-500"})})]},e.id)})}),c.length>0&&(0,re.jsxs)("div",{className:"mt-6 pt-4 border-t border-gray-200 dark:border-gray-700",children:[(0,re.jsx)(Hs,{variant:"ghost",className:"w-full justify-start p-3 h-auto text-left hover:bg-gray-50 dark:hover:bg-gray-800/50",onClick:()=>u(!m),children:(0,re.jsxs)("div",{className:"flex items-start justify-between w-full",children:[(0,re.jsxs)("div",{className:"flex-1 min-w-0 mr-3",children:[(0,re.jsx)("div",{className:"font-medium text-sm mb-1",children:"Alternative Versions"}),(0,re.jsxs)("div",{className:"text-xs text-gray-500 leading-relaxed",children:["These versions may be from alternative paths,",(0,re.jsx)("br",{}),"created when reverting to previous checkpoints"]})]}),(0,re.jsx)("div",{className:"flex-shrink-0 ml-2",children:m?(0,re.jsx)(It.A,{className:"h-4 w-4 text-gray-400"}):(0,re.jsx)(ln.A,{className:"h-4 w-4 text-gray-400"})})]})}),m&&(0,re.jsx)("div",{className:"space-y-2 mt-3",children:c.map(e=>{const{relative:s,absolute:a}=p(e.timestamp);return(0,re.jsxs)("div",{className:"border border-gray-200 dark:border-gray-700 rounded-lg p-3 relative cursor-pointer transition-all ".concat((null==t?void 0:t.id)===e.id?"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:()=>g(e),children:[(0,re.jsx)("div",{className:"mb-2 font-medium text-sm pr-8",children:e.title}),(0,re.jsxs)("div",{className:"text-xs text-gray-400",children:[(0,re.jsx)("div",{className:"font-medium",children:s}),(0,re.jsx)("div",{className:"opacity-75",children:a})]}),(null==t?void 0:t.id)===e.id&&(0,re.jsx)("div",{className:"absolute top-2 right-2",children:(0,re.jsx)(Pt.A,{className:"h-4 w-4 text-blue-500"})})]},e.id)})})]}),(0,re.jsx)(vp,{open:r,onOpenChange:l,children:(0,re.jsxs)(Np,{children:[(0,re.jsxs)(wp,{children:[(0,re.jsx)(kp,{children:"Are you sure?"}),(0,re.jsxs)(Ap,{children:['This action is irreversible. Your app will be reverted to "',null==t?void 0:t.title,'".']})]}),(0,re.jsxs)(_p,{children:[(0,re.jsx)(Cp,{children:"Cancel"}),(0,re.jsx)(Sp,{onClick:()=>{alert("Reverted to: ".concat(t.title)),l(!1)},children:"Revert"})]})]})})]})};var Uf=t(319);function zf(){const{app:e}=_s();return(0,re.jsx)(Hs,{variant:"ghost",size:"sm",className:"w-7 h-7 p-0 text-gray-500 hover:text-gray-700 hover:bg-gray-100 ",onClick:()=>{const s=null!=e&&e.id?"/support?appId=".concat(e.id):"/support";window.open(s,"_blank")},title:"Help Center",children:(0,re.jsx)(_h.A,{size:16})})}var qf=t(43558),Wf=t(90770);const Vf=e=>{var s;let{app:t}=e;return(0,re.jsxs)(af,{children:[(0,re.jsx)(nf,{asChild:!0,children:(0,re.jsxs)("div",{className:"flex items-center gap-3 cursor-pointer flex-1 p-1 rounded-md hover:bg-gray-200 transition-colors",children:[(0,re.jsxs)(ir,{className:"h-6 w-6 rounded-xl",children:[(0,re.jsx)(or,{src:null==t?void 0:t.logo_url,alt:(null==t?void 0:t.name)||"App"}),(0,re.jsx)(cr,{children:(null==t||null===(s=t.name)||void 0===s?void 0:s[0])||"A"})]}),(0,re.jsx)("div",{className:"flex-1 min-w-0",children:(0,re.jsxs)("div",{className:"flex items-center gap-1",children:[(0,re.jsx)("div",{className:"max-w-[120px]",title:(null==t?void 0:t.name)||"My App",children:(0,re.jsx)("h3",{className:"text-sm font-medium truncate",children:(null==t?void 0:t.name)||"My App"})}),(0,re.jsx)(It.A,{className:"h-4 w-4 text-muted-foreground"})]})})]})}),(0,re.jsxs)(rf,{align:"start",className:"w-[240px] p-1 shadow-lg border border-slate-200 rounded-lg",children:[(0,re.jsx)(lf,{asChild:!0,children:(0,re.jsxs)(J.Link,{to:"/apps/".concat(null==t?void 0:t.id,"/editor/workspace/overview"),className:"flex items-center gap-2 cursor-pointer",children:[(0,re.jsx)(_d.A,{className:"h-4 w-4"}),(0,re.jsx)("span",{children:"App Overview"})]})}),(0,re.jsx)(lf,{asChild:!0,children:(0,re.jsxs)(J.Link,{to:"/apps/".concat(null==t?void 0:t.id,"/editor/workspace/users"),className:"flex items-center gap-2 cursor-pointer",children:[(0,re.jsx)(qf.A,{className:"h-4 w-4"}),(0,re.jsx)("span",{children:"Users"})]})}),(0,re.jsx)(lf,{asChild:!0,children:(0,re.jsxs)(J.Link,{to:"/apps/".concat(null==t?void 0:t.id,"/editor/workspace/security"),className:"flex items-center gap-2 cursor-pointer",children:[(0,re.jsx)(Ho.A,{className:"h-4 w-4"}),(0,re.jsx)("span",{children:"Security"})]})}),(0,re.jsx)(lf,{asChild:!0,children:(0,re.jsxs)(J.Link,{to:"/apps/".concat(null==t?void 0:t.id,"/editor/workspace/app-settings"),className:"flex items-center gap-2 cursor-pointer",children:[(0,re.jsx)(Wf.A,{className:"h-4 w-4"}),(0,re.jsx)("span",{children:"App Settings"})]})})]})]})};const Yf=e=>{let{onToggleVersions:s,showVersions:t}=e;const{app:a,currentUsage:n}=_s(),{logout:r,user:l}=oe(),i=(0,Z.Zp)(),[o,c]=(0,H.useState)(!1);return(0,re.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,re.jsx)("div",{className:"flex items-center gap-3 flex-1",children:(0,re.jsxs)("div",{className:"flex items-center gap-3",children:[(0,re.jsx)(Pf,{app:a,currentUsage:n,user:l,onShareModalOpen:()=>c(!0),onLogout:()=>{r(),i("/login")}}),(0,re.jsx)("div",{className:"h-5 w-[1px] bg-slate-300 rotate-[25deg]"}),(0,re.jsx)(Vf,{app:a})]})}),(0,re.jsxs)("div",{className:"flex items-center mr-2",children:[(0,re.jsx)(Hs,{variant:t?"secondary":"ghost",size:"sm",className:"transition-colors w-7 h-7 mr-1 p-0 ".concat(t?"text-gray-700 bg-gray-200":"text-gray-500 hover:text-gray-700 hover:bg-gray-100"),onClick:s,title:"Version history",children:(0,re.jsx)(Uf.A,{size:16})}),(0,re.jsx)(zf,{})]}),(0,re.jsx)(Ga,{app:a,isOpen:o,onClose:()=>c(!1)})]})};function Hf(e){let{app:s}=e;return(0,re.jsx)("div",{className:"h-full flex items-center justify-center pt-4",children:(0,re.jsxs)("div",{className:"flex flex-col items-center space-y-8 max-w-md text-center px-4",children:[(0,re.jsxs)("div",{className:"relative",children:[(0,re.jsx)("div",{className:"w-16 h-16 rounded-full bg-orange-500/20 backdrop-blur-sm flex items-center justify-center",children:(0,re.jsx)("div",{className:"w-8 h-8 rounded-full bg-gradient-to-br from-orange-400 to-orange-500"})}),(0,re.jsx)("div",{className:"absolute top-0 left-0 w-16 h-16 rounded-full bg-orange-400/20 animate-ping"}),(0,re.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,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsx)("h2",{className:"text-2xl font-medium tracking-tight text-slate-700",children:"Creating Your App"}),(0,re.jsx)("p",{className:"text-sm font-light text-teal-700/60 tracking-wide",children:"This might take a few minutes..."})]}),(0,re.jsx)("div",{className:"text-base text-teal-600/80 font-light tracking-wide",children:(0,re.jsx)(Pi,{status:s.status.details})})]})})}const Gf=e=>{var s,t;const{user:a}=oe(),n=(0,H.useRef)(null),[r,l]=(0,H.useState)(!1),[i,o]=(0,H.useState)(!0),c=(0,H.useRef)(null),d=(0,H.useRef)(0);(0,H.useEffect)(()=>{const e=()=>{o(!document.hidden)},s=()=>{o(!0)},t=()=>{o(!1)};return o(!document.hidden),document.addEventListener("visibilitychange",e),window.addEventListener("focus",s),window.addEventListener("blur",t),()=>{document.removeEventListener("visibilitychange",e),window.removeEventListener("focus",s),window.removeEventListener("blur",t)}},[]),(0,H.useEffect)(()=>{if(!a||"never"===(null==a?void 0:a.notification_preference))return;if(!n.current){const e=new Audio("/sounds/notification.mp3");let s=!1;e.addEventListener("error",t=>{s||(s=!0),e.src="data:audio/wav;base64,UklGRnoGAABXQVZFZm10IBAAAAABAAEAQB8AAEAfAAABAAgAZGF0YQoGAACBhYqFbF1fdJivrJBhNjVgodDbq2EcBj+a2/LDciUFLIHO8tiJNwgZaLvt559NEAxQp+PwtmMcBjiR1/LMeSwFJHfH8N2QQAoUXrTp66hVFApGn+DyvmwhBSuBzvLZiTYIG2m98OScTgwOUarm7blmGgU7k9n1unEiBC13yO/eizEIHWq+8+OWT"}),n.current=e}const e=()=>{r||(l(!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)}},[r,a,null==a?void 0:a.notification_preference]),(0,H.useEffect)(()=>()=>{n.current&&(n.current.pause(),n.current=null)},[]),(0,H.useEffect)(()=>{var s,t,r,l,o;if(!n.current)return;const m=null===(s=e.status)||void 0===s?void 0:s.state,u=(null===(t=e.conversation)||void 0===t||null===(r=t.messages)||void 0===r?void 0:r.length)||0,x=(null===(l=e.conversation)||void 0===l||null===(o=l.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===(s=e.status)||void 0===s?void 0:s.state,null==e||null===(t=e.conversation)||void 0===t?void 0:t.messages,null==a?void 0:a.notification_preference,i])};function $f(e){var s,t,a;let{view:n}=e;const r=(0,Qe.Ub)({maxWidth:767}),[l,i]=(0,H.useState)(!1),{app:o}=_s(),[c,d]=(0,H.useState)(!1),[m,u]=(0,H.useState)(null),[x,h]=(0,H.useState)(!1),[p,g]=(0,H.useState)(null);Gf(o);const f=e=>{u(e)};(0,H.useEffect)(()=>{if(r){var e,s,t,a,n;const r="processing"===(null===(e=o.status)||void 0===e?void 0:e.state),l=(null===(s=o.conversation)||void 0===s||null===(t=s.messages)||void 0===t?void 0:t.length)<=3;r&&l&&i(!0),"processing"===p&&"processing"!==(null===(a=o.status)||void 0===a?void 0:a.state)&&l&&i(!1),g(null===(n=o.status)||void 0===n?void 0:n.state)}},[null===(s=o.status)||void 0===s?void 0:s.state,null===(t=o.conversation)||void 0===t||null===(a=t.messages)||void 0===a?void 0:a.length,r,p]),(0,H.useEffect)(()=>(null!=o&&o.name?document.title="".concat(o.name," | Base44"):document.title="Base44",()=>{document.title="Base44"}),[null==o?void 0:o.name]);let v=null;var b,j,y;"pending"===o.app_stage?v="processing"===(null===(b=o.status)||void 0===b?void 0:b.state)?(0,re.jsx)(Hf,{app:o}):(0,re.jsx)("div",{className:"h-full flex items-center justify-center pt-4",children:(0,re.jsxs)("div",{className:"flex flex-col items-center space-y-6 max-w-md text-center px-4",children:[(0,re.jsx)("div",{className:"w-12 h-12 rounded-full bg-gray-100 flex items-center justify-center",onClick:()=>i(!0),children:(0,re.jsx)(Mf.A,{className:"w-6 h-6 text-gray-400"})}),(0,re.jsx)("h2",{className:"text-xl font-light text-gray-700",children:"Let's Build Your App"}),(0,re.jsx)("p",{className:"text-sm text-gray-500",children:"Tell me what you'd like to create using the chat"})]})}):v=(0,re.jsx)(Df,{view:n,selectedCheckpoint:m,setSelectedCheckpoint:u,isLeftPanelHidden:x,toggleLeftPanel:()=>h(!x)});return r?(0,re.jsx)("div",{className:"h-full bg-slate-50 rounded-tr-lg rounded-br-lg",children:(0,re.jsxs)("div",{className:"relative",children:[v,(0,re.jsx)(Hs,{className:"fixed bottom-6 right-6 rounded-full shadow-lg z-50 bg-gray-900 hover:bg-gray-800 flex items-center gap-2 px-4",onClick:()=>i(!0),children:"processing"===(null===(j=o.status)||void 0===j?void 0:j.state)?(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)("div",{className:"h-5 w-5 border-2 border-white border-t-transparent rounded-full animate-spin"}),(0,re.jsx)("span",{className:"text-white text-sm",children:"Processing..."})]}):(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(Mf.A,{className:"h-5 w-5 text-white"}),(0,re.jsx)("span",{className:"text-white text-sm",children:"Edit App"})]})}),(0,re.jsx)(Vm,{open:l,onOpenChange:i,children:(0,re.jsxs)(Zm,{side:"left",className:"w-[90%] sm:w-[385px] p-0 flex flex-col rounded-tr-lg rounded-br-lg",children:[(0,re.jsx)(Km,{className:"p-4 flex-shrink-0 bg-slate-50 relative z-10 rounded-tr-lg rounded-br-lg",children:(0,re.jsx)("div",{className:"flex justify-between items-center",children:(0,re.jsxs)("div",{className:"flex items-center gap-3",children:[(0,re.jsx)(J.Link,{to:"/apps/".concat(null==o?void 0:o.id,"/editor/workspace/logo"),children:(0,re.jsxs)(ma,{className:"h-8 w-8 rounded-xl cursor-pointer",children:[(0,re.jsx)(ua,{src:null==o?void 0:o.logo_url,alt:(null==o?void 0:o.name)||"App"}),(0,re.jsx)(xa,{children:(null==o||null===(y=o.name)||void 0===y?void 0:y[0])||"A"})]})}),(0,re.jsx)("div",{children:(0,re.jsx)(Qm,{className:"m-0 text-sm",children:(null==o?void 0:o.name)||"AI App Editor"})})]})})}),(0,re.jsx)("div",{className:"flex-1 overflow-y-auto p-2",children:c?(0,re.jsx)(Bf,{onClose:()=>{u(void 0),d(!1)},selectedCheckpoint:m,onSelectCheckpoint:f}):(0,re.jsx)(wd,{})})]})})]})}):(0,re.jsx)("div",{className:"flex flex-row h-screen bg-slate-50",children:(0,re.jsxs)(jh,{direction:"horizontal",children:[(0,re.jsx)(yh,{defaultSize:x?0:26,minSize:x?0:28,maxSize:x?0:40,className:"h-full overflow-hidden relative ".concat(x?"hidden":""),style:{minWidth:x?"0px":"250px"},children:(0,re.jsxs)("div",{className:"flex flex-col h-full",children:[(0,re.jsx)("div",{className:"flex-shrink-0",children:(0,re.jsx)(Yf,{onToggleVersions:()=>{d(!c)},showVersions:c})}),(0,re.jsx)("div",{className:"flex-1 overflow-y-auto",children:c?(0,re.jsx)(Bf,{onClose:()=>{d(!1),u(void 0)},selectedCheckpoint:m,onSelectCheckpoint:f}):(0,re.jsx)(wd,{})})]})}),(0,re.jsx)(Nh,{withHandle:!0,className:"group transition-opacity ".concat(x?"hidden":"opacity-0 hover:opacity-100 focus:opacity-100")}),(0,re.jsx)(yh,{defaultSize:x?100:67,className:"flex-1 overflow-x-auto ".concat(x?"pl-4":""),children:v})]})})}const Jf=e=>{let{view:s}=e;return(0,re.jsx)(ws,{children:(0,re.jsx)(Zr,{children:(0,re.jsx)(kg,{children:(0,re.jsx)($f,{view:s})})})})};function Zf(){const e=(0,Z.Zp)(),s=(0,Z.zy)(),t=new URLSearchParams(s.search),a=t.get("prompt"),[n,r]=(0,H.useState)(null),{user:l}=oe();return(0,H.useEffect)(()=>{!async function(){if(a)try{const s=t.get("app_platform_version"),n={status:{state:"processing",details:"Starting conversation..."}};s&&(n.platform_version=parseInt(s,10));const r=await ve.create(n);He(r.id,{content:a},null==l?void 0:l.id),e("/apps/".concat(r.id,"/editor/preview"))}catch(s){r(s.message||"Error creating app")}else r("No prompt provided")}()},[a,e,t]),n?(0,re.jsx)("div",{className:"flex items-center justify-center h-screen",children:(0,re.jsx)("div",{className:"bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded",children:(0,re.jsx)("span",{children:n})})}):(0,re.jsx)("div",{className:"flex items-center justify-center h-screen",children:(0,re.jsx)("div",{"data-testid":"loading-spinner",className:"animate-spin rounded-full h-12 w-12 border-4 border-gray-300 border-t-blue-600"})})}var Kf=t(85113),Xf=t(58799),Qf=t(35097),ev=t(73581),sv=t(2847),tv=t(56473);function av(e){let{stats:s}=e;const[t,a]=(0,H.useState)("30days"),[n,r]=(0,H.useState)(!1);return(0,re.jsxs)(re.Fragment,{children:[(0,re.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4 mb-8",children:[(0,re.jsx)(it,{children:(0,re.jsxs)(mt,{className:"flex items-center p-6",children:[(0,re.jsx)(Gr.A,{className:"w-8 h-8 text-blue-500 mr-4"}),(0,re.jsxs)("div",{children:[(0,re.jsx)("p",{className:"text-sm text-gray-600",children:"Total Users"}),(0,re.jsx)("p",{className:"text-2xl font-bold",children:s.total_users})]})]})}),(0,re.jsx)(it,{children:(0,re.jsxs)(mt,{className:"flex items-center p-6",children:[(0,re.jsx)(Qf.A,{className:"w-8 h-8 text-green-500 mr-4"}),(0,re.jsxs)("div",{children:[(0,re.jsx)("p",{className:"text-sm text-gray-600",children:"New Today"}),(0,re.jsx)("p",{className:"text-2xl font-bold",children:s.new_users_today})]})]})}),(0,re.jsx)(it,{children:(0,re.jsxs)(mt,{className:"flex items-center p-6",children:[(0,re.jsx)(ev.A,{className:"w-8 h-8 text-yellow-500 mr-4"}),(0,re.jsxs)("div",{children:[(0,re.jsx)("p",{className:"text-sm text-gray-600",children:"Premium Users"}),(0,re.jsx)("p",{className:"text-2xl font-bold",children:s.paying_users})]})]})})]}),(0,re.jsx)(it,{className:"mb-8",children:(0,re.jsxs)(mt,{className:"p-6",children:[(0,re.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,re.jsx)("h3",{className:"text-lg font-semibold",children:"User Growth"}),(0,re.jsxs)("div",{className:"flex space-x-2",children:[(0,re.jsx)(Hs,{variant:"7days"===t?"default":"outline",size:"sm",onClick:()=>a("7days"),children:"7 Days"}),(0,re.jsx)(Hs,{variant:"30days"===t?"default":"outline",size:"sm",onClick:()=>a("30days"),children:"30 Days"}),(0,re.jsx)(Hs,{variant:"90days"===t?"default":"outline",size:"sm",onClick:()=>a("90days"),children:"90 Days"}),(0,re.jsx)(Hs,{variant:"year"===t?"default":"outline",size:"sm",onClick:()=>a("year"),children:"1 Year"}),(0,re.jsx)(Hs,{variant:"all"===t?"default":"outline",size:"sm",onClick:()=>a("all"),children:"All Time"}),(0,re.jsx)(Hs,{variant:n?"default":"outline",size:"sm",onClick:()=>r(!n),children:n?"Show Today":"Hide Today"})]})]}),(0,re.jsx)("div",{className:"h-[200px] w-full",children:(0,re.jsx)(Wx.u,{width:"100%",height:"100%",children:(0,re.jsxs)(sv.b,{data:(()=>{if(!s.new_users_by_day)return[];la()();let e;switch(t){case"7days":e=la()().subtract(7,"days");break;case"30days":default:e=la()().subtract(30,"days");break;case"90days":e=la()().subtract(90,"days");break;case"year":e=la()().subtract(1,"year");break;case"all":return n?s.new_users_by_day.filter(e=>!la()(e.date).isSame(la()(),"day")):s.new_users_by_day}let a=s.new_users_by_day.filter(s=>la()(s.date).isAfter(e));return n&&(a=a.filter(e=>!la()(e.date).isSame(la()(),"day"))),a})(),children:[(0,re.jsx)(Hx.W,{dataKey:"date",tickFormatter:e=>la()(e).format("MMM DD")}),(0,re.jsx)(Gx.h,{}),(0,re.jsx)($x.m,{labelFormatter:e=>la()(e).format("MMMM DD, YYYY"),formatter:e=>["".concat(e," new users")]}),(0,re.jsx)(tv.N,{type:"monotone",dataKey:"count",stroke:"#2563eb",strokeWidth:2})]})})})]})})]})}function nv(e){let{details:s,selectedUser:t,onUpdateUser:a,loading:n}=e;return s.is_personal?(0,re.jsxs)(re.Fragment,{children:[(0,re.jsxs)("div",{children:[(0,re.jsx)("h3",{className:"mb-2 font-medium",children:"Subscription Tier"}),(0,re.jsxs)(Ut,{value:t.subscription_tier,onValueChange:e=>a(t.id,{subscription_tier:e}),disabled:n,children:[(0,re.jsx)(Wt,{children:(0,re.jsx)(qt,{})}),(0,re.jsxs)(Ht,{children:[(0,re.jsx)($t,{value:"free",children:"Free"}),(0,re.jsx)($t,{value:"starter",children:"Starter"}),(0,re.jsx)($t,{value:"builder",children:"Builder"}),(0,re.jsx)($t,{value:"pro",children:"Pro"}),(0,re.jsx)($t,{value:"elite",children:"Elite"}),(0,re.jsx)($t,{value:"enterprise",children:"Enterprise"})]})]})]}),(0,re.jsxs)("div",{className:"bg-gray-50 p-4 rounded-lg space-y-4",children:[(0,re.jsxs)("div",{children:[(0,re.jsx)("h3",{className:"mb-2 font-medium",children:"Stripe Customer ID"}),(0,re.jsx)("p",{className:"text-sm text-gray-600 font-mono",children:s.stripe_customer_id||"-"})]}),(0,re.jsxs)("div",{children:[(0,re.jsx)("h3",{className:"mb-2 font-medium",children:"Stripe Subscription ID"}),(0,re.jsx)("p",{className:"text-sm text-gray-600 font-mono",children:s.stripe_subscription_id||"-"})]}),(0,re.jsxs)("div",{children:[(0,re.jsx)("h3",{className:"mb-2 font-medium",children:"Stripe Subscription Status"}),(0,re.jsx)("p",{className:"text-sm text-gray-600",children:s.stripe_subscription_status||"-"})]})]})]}):(0,re.jsxs)("div",{className:"bg-gray-50 p-4 rounded-lg space-y-4",children:[(0,re.jsxs)("div",{children:[(0,re.jsx)("h3",{className:"mb-2 font-medium",children:"Workspace Role"}),(0,re.jsx)("span",{className:"px-2 py-1 rounded-full text-xs ".concat("owner"===s.user_role?"bg-purple-100 text-purple-800":"admin"===s.user_role?"bg-blue-100 text-blue-800":"bg-gray-100 text-gray-800"),children:s.user_role})]}),(0,re.jsxs)("div",{children:[(0,re.jsx)("h3",{className:"mb-2 font-medium",children:"Seat Status"}),(0,re.jsx)("span",{className:"px-2 py-1 rounded-full text-xs ".concat("assigned"===s.seat_status?"bg-green-100 text-green-800":"bg-orange-100 text-orange-800"),children:"assigned"===s.seat_status?"Assigned":"No Seat"})]}),"assigned"===s.seat_status&&(0,re.jsxs)(re.Fragment,{children:[(0,re.jsxs)("div",{children:[(0,re.jsx)("h3",{className:"mb-2 font-medium",children:"Seat Plan"}),(0,re.jsx)("p",{className:"text-sm text-gray-600",children:s.seat_type_name})]}),(0,re.jsxs)("div",{children:[(0,re.jsx)("h3",{className:"mb-2 font-medium",children:"Seat Number"}),(0,re.jsxs)("p",{className:"text-sm text-gray-600",children:["#",s.seat_id]})]})]})]})}function rv(e){let{selectedUser:s,workspaceDetails:t,onUpdateUser:a,loading:n,loadingStates:r}=e;return s?(0,re.jsxs)("div",{className:"space-y-4",children:[(0,re.jsxs)("div",{children:[(0,re.jsx)("h3",{className:"mb-2 font-medium",children:"Full Name"}),(0,re.jsx)(ft,{type:"text",value:s.full_name||"",onChange:e=>a(s.id,{full_name:e.target.value}),disabled:n})]}),(0,re.jsxs)("div",{children:[(0,re.jsx)("h3",{className:"mb-2 font-medium",children:"Username"}),(0,re.jsx)("p",{className:"text-gray-600",children:s.username||"-"})]}),(0,re.jsxs)("div",{children:[(0,re.jsx)("h3",{className:"mb-2 font-medium",children:"Phone Number"}),(0,re.jsx)(ft,{type:"text",value:s.phone_number||"",onChange:e=>a(s.id,{phone_number:e.target.value}),disabled:n})]}),(0,re.jsxs)("div",{children:[(0,re.jsx)("h3",{className:"mb-2 font-medium",children:"Platform Role"}),(0,re.jsxs)(Ut,{value:s.platform_role,onValueChange:e=>a(s.id,{platform_role:e}),disabled:n,children:[(0,re.jsx)(Wt,{children:(0,re.jsx)(qt,{})}),(0,re.jsxs)(Ht,{children:[(0,re.jsx)($t,{value:"user",children:"User"}),(0,re.jsx)($t,{value:"platform_admin",children:"Platform Admin"})]})]})]}),r.workspaces?(0,re.jsx)("div",{className:"bg-gray-50 p-4 rounded-lg",children:(0,re.jsxs)("div",{className:"flex items-center gap-2 text-sm text-gray-500",children:[(0,re.jsx)(Ze.A,{className:"h-4 w-4 animate-spin"}),"Loading workspace details..."]})}):t?(0,re.jsx)(nv,{details:t,selectedUser:s,onUpdateUser:a,loading:n}):null,(0,re.jsxs)("div",{children:[(0,re.jsx)("h3",{className:"mb-2 font-medium",children:"API Key"}),(0,re.jsx)("p",{className:"text-sm text-gray-600 font-mono break-all",children:s.api_key||"-"})]}),(0,re.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,re.jsx)(ed,{id:"beta-tester",checked:s.is_beta_tester||!1,onCheckedChange:e=>a(s.id,{is_beta_tester:e}),disabled:n}),(0,re.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,re.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,re.jsx)(ed,{id:"user-disabled",checked:s.disabled||!1,onCheckedChange:e=>a(s.id,{disabled:e}),disabled:n}),(0,re.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,re.jsxs)("div",{children:[(0,re.jsx)("h3",{className:"mb-2 font-medium",children:"Account Status"}),(0,re.jsx)("span",{className:"px-2 py-1 rounded-full text-xs ".concat(s.disabled?"bg-red-100 text-red-800":"bg-green-100 text-green-800"),children:s.disabled?"Disabled":"Active"})]})]}):null}var lv=t(82237);const iv=["className","value"],ov=H.forwardRef((e,s)=>{let{className:t,value:a}=e,n=(0,as.A)(e,iv);return(0,re.jsx)(lv.bL,(0,K.A)((0,K.A)({ref:s,className:is("relative h-4 w-full overflow-hidden rounded-full bg-secondary",t)},n),{},{children:(0,re.jsx)(lv.C1,{className:"h-full w-full flex-1 bg-primary transition-all",style:{transform:"translateX(-".concat(100-(a||0),"%)")}})}))});function cv(e){let{userUsageStats:s,dateRange:t,onDateRangeChange:a,selectedWorkspace:n,onSwitchToCreditsTab:r,isLoading:l}=e;const[i,o]=(0,H.useState)(!1),[c,d]=(0,H.useState)(null),[m,u]=(0,H.useState)(!1),x=(e,s)=>{d({startDate:e,endDate:s})};return l||!s?(0,re.jsx)("div",{className:"flex items-center justify-center py-12",children:(0,re.jsxs)("div",{className:"text-center",children:[(0,re.jsx)(Ze.A,{className:"h-8 w-8 animate-spin mx-auto mb-4 text-gray-400"}),(0,re.jsx)("p",{className:"text-gray-500",children:"Loading usage statistics..."})]})}):(0,re.jsxs)("div",{className:"space-y-8",children:[(0,re.jsxs)("div",{className:"bg-white rounded-lg shadow p-4",children:[(0,re.jsx)("h3",{className:"text-lg font-semibold mb-2",children:"Current Usage"}),(0,re.jsxs)("div",{className:"space-y-4",children:[(0,re.jsxs)("div",{children:[(0,re.jsxs)("div",{className:"flex justify-between mb-1",children:[(0,re.jsxs)("span",{className:"text-sm font-medium",children:["Monthly Usage: ",s.monthly_usage," / ",s.monthly_limit]}),(0,re.jsxs)("span",{className:"text-sm text-gray-500",children:[Math.round(s.monthly_usage/s.monthly_limit*100),"%"]})]}),(0,re.jsx)(ov,{value:s.monthly_usage/s.monthly_limit*100,className:"h-2",indicatorClassName:s.is_over_limit?"bg-red-500":void 0})]}),s.daily_limit&&(0,re.jsxs)("div",{children:[(0,re.jsxs)("div",{className:"flex justify-between mb-1",children:[(0,re.jsxs)("span",{className:"text-sm font-medium",children:["Daily Usage: ",s.daily_usage," / ",s.daily_limit]}),(0,re.jsxs)("span",{className:"text-sm text-gray-500",children:[Math.round(s.daily_usage/s.daily_limit*100),"%"]})]}),(0,re.jsx)(ov,{value:s.daily_usage/s.daily_limit*100,className:"h-2",indicatorClassName:s.is_over_limit?"bg-red-500":void 0})]})]})]}),s.usage_by_date&&(0,re.jsxs)("div",{className:"bg-white rounded-lg shadow p-6",children:[(0,re.jsxs)("div",{className:"flex justify-between items-center mb-6",children:[(0,re.jsx)("h3",{className:"text-lg font-semibold",children:"Usage History"}),(0,re.jsxs)(dm,{open:i,onOpenChange:o,children:[(0,re.jsx)(mm,{asChild:!0,children:(0,re.jsxs)(Hs,{variant:"outline",className:"flex items-center gap-2",disabled:m,children:[(0,re.jsx)(im.A,{className:"h-4 w-4"}),t.startDate&&t.endDate?"".concat(la()(t.startDate).format("MMM D, YYYY")," - ").concat(la()(t.endDate).format("MMM D, YYYY")):"Select Date Range"]})}),(0,re.jsx)(um,{className:"w-auto p-0",align:"end",children:(0,re.jsxs)("div",{className:"p-3 border-b",children:[(0,re.jsx)("h4",{className:"font-medium mb-2",children:"Select Date Range"}),(0,re.jsxs)("div",{className:"grid grid-cols-2 gap-2",children:[(0,re.jsxs)("div",{children:[(0,re.jsx)("label",{className:"text-sm text-gray-600",children:"Start Date"}),(0,re.jsx)(rm,{mode:"single",selected:(null==c?void 0:c.startDate)||t.startDate,onSelect:e=>x(e,(null==c?void 0:c.endDate)||t.endDate),className:"rounded-md border"})]}),(0,re.jsxs)("div",{children:[(0,re.jsx)("label",{className:"text-sm text-gray-600",children:"End Date"}),(0,re.jsx)(rm,{mode:"single",selected:(null==c?void 0:c.endDate)||t.endDate,onSelect:e=>x((null==c?void 0:c.startDate)||t.startDate,e),className:"rounded-md border"})]})]}),(0,re.jsxs)("div",{className:"flex justify-end gap-2 mt-3",children:[(0,re.jsx)(Hs,{variant:"outline",size:"sm",onClick:()=>{if(s){const e=new Date(s.current_credit_period_start_date),t=new Date(s.current_credit_period_end_date);u(!0),a(e,t,n,()=>{u(!1)})}d(null)},children:"Reset"}),(0,re.jsx)(Hs,{size:"sm",onClick:()=>{c&&(u(!0),a(c.startDate,c.endDate,n,()=>{u(!1)})),o(!1)},children:"Apply"})]})]})})]})]}),(0,re.jsx)("div",{className:"h-[300px]",children:(0,re.jsx)(pf,{usageByDate:s.usage_by_date,height:"h-[260px]"})})]}),(0,re.jsx)(it,{children:(0,re.jsxs)(mt,{className:"pt-6 space-y-6",children:[(0,re.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,re.jsxs)("div",{className:"bg-gray-50 p-4 rounded-lg",children:[(0,re.jsx)("h4",{className:"text-sm font-medium text-gray-700 mb-2",children:"Subscription Tier"}),(0,re.jsx)("p",{className:"text-lg font-semibold capitalize",children:s.tier})]}),(0,re.jsxs)("div",{className:"bg-gray-50 p-4 rounded-lg",children:[(0,re.jsx)("h4",{className:"text-sm font-medium text-gray-700 mb-2",children:"Bonus Credits"}),(0,re.jsx)("p",{className:"text-lg font-semibold",children:s.extra_credits})]})]}),(0,re.jsxs)("div",{className:"bg-gray-50 p-4 rounded-lg",children:[(0,re.jsx)("h3",{className:"text-sm font-medium text-gray-700 mb-3",children:"Billing Period"}),(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsxs)("div",{className:"flex justify-between",children:[(0,re.jsx)("span",{className:"font-medium",children:"Start:"}),(0,re.jsx)("span",{children:la()(s.current_credit_period_start_date).format("MMM DD, YYYY")})]}),(0,re.jsxs)("div",{className:"flex justify-between",children:[(0,re.jsx)("span",{className:"font-medium",children:"End:"}),(0,re.jsx)("span",{children:la()(s.current_credit_period_end_date).format("MMM DD, YYYY")})]}),(0,re.jsxs)("div",{className:"flex justify-between",children:[(0,re.jsx)("span",{className:"font-medium",children:"Next Start:"}),(0,re.jsx)("span",{children:la()(s.next_period_start_date).format("MMM DD, YYYY")})]})]})]})]})}),s.is_over_limit&&(0,re.jsxs)("div",{className:"bg-red-50 border border-red-200 text-red-800 px-4 py-3 rounded-lg",children:[(0,re.jsx)("p",{className:"font-medium",children:"User is over their usage limit"}),(0,re.jsx)("p",{className:"text-sm",children:"Consider adding bonus credits or upgrading their subscription tier."})]}),(0,re.jsxs)(Hs,{onClick:r,className:"w-full mt-8",children:[(0,re.jsx)(Yg.A,{className:"h-4 w-4 mr-2"}),"Add Bonus Credits"]})]})}function dv(e){let{userBonusCredits:s,onAddBonusCredits:t,onDeleteBonusCredit:a,loading:n}=e;const[r,l]=(0,H.useState)({numMessages:0,reason:""});return(0,re.jsxs)("div",{className:"space-y-6",children:[(0,re.jsx)("h3",{className:"text-lg font-semibold",children:"Bonus Credits"}),s.length>0?(0,re.jsx)("div",{className:"space-y-3 mb-4",children:s.map((e,s)=>(0,re.jsxs)("div",{className:"bg-blue-50 p-3 rounded-md",children:[(0,re.jsxs)("div",{className:"flex justify-between",children:[(0,re.jsxs)("span",{className:"font-medium",children:[e.num_messages," messages"]}),(0,re.jsx)("span",{className:"text-sm text-gray-600",children:la()(e.created_date).format("MMM DD, YYYY")})]}),(0,re.jsx)("p",{className:"text-sm text-gray-700 mt-1",children:e.reason}),(0,re.jsxs)("div",{className:"flex justify-between items-center mt-1",children:[(0,re.jsxs)("p",{className:"text-xs text-gray-500",children:["Expires: ",la()(e.expires_date).format("MMM DD, YYYY")]}),(0,re.jsx)(Hs,{variant:"ghost",size:"sm",className:"text-red-500 hover:text-red-700 hover:bg-red-50",onClick:()=>a(e.id),disabled:n,children:(0,re.jsx)(_u.A,{className:"h-4 w-4"})})]})]},s))}):(0,re.jsx)("p",{className:"text-gray-500 mb-4",children:"No bonus credits found for this user."}),(0,re.jsxs)("div",{className:"bg-gray-50 p-4 rounded-lg",children:[(0,re.jsx)("h4",{className:"font-medium mb-3",children:"Add Bonus Credits"}),(0,re.jsxs)("div",{className:"space-y-3",children:[(0,re.jsxs)("div",{children:[(0,re.jsx)("label",{className:"text-sm text-gray-600",children:"Number of Messages"}),(0,re.jsx)(ft,{type:"number",min:"1",value:r.numMessages,onChange:e=>l((0,K.A)((0,K.A)({},r),{},{numMessages:e.target.value})),disabled:n})]}),(0,re.jsxs)("div",{children:[(0,re.jsx)("label",{className:"text-sm text-gray-600",children:"Reason"}),(0,re.jsx)(ft,{type:"text",value:r.reason,onChange:e=>l((0,K.A)((0,K.A)({},r),{},{reason:e.target.value})),placeholder:"e.g., Promotional offer, Customer support",disabled:n})]}),(0,re.jsxs)(Hs,{onClick:()=>{r.numMessages&&r.reason&&(t(parseInt(r.numMessages),r.reason),l({numMessages:0,reason:""}))},disabled:n||!r.numMessages||!r.reason,className:"w-full",children:[(0,re.jsx)(Ss.A,{className:"h-4 w-4 mr-2"}),"Add Credits"]})]})]})]})}function mv(e){let{workspaces:s,selectedWorkspace:t,onWorkspaceChange:a,loading:n,disabled:r=!1}=e;return(0,re.jsxs)("div",{className:"w-full relative",children:[(0,re.jsxs)(Ut,{value:t||"",onValueChange:a,disabled:n||r,children:[(0,re.jsx)(Wt,{className:"text-sm",children:(0,re.jsx)(qt,{placeholder:"Select workspace..."})}),(0,re.jsx)(Ht,{children:s.map(e=>(0,re.jsx)($t,{value:e.id,children:(0,re.jsx)("span",{children:e.is_personal?"Personal":e.name})},e.id))})]}),n&&(0,re.jsx)("div",{className:"absolute right-8 top-1/2 transform -translate-y-1/2",children:(0,re.jsx)(Ze.A,{className:"h-4 w-4 animate-spin text-gray-400"})})]})}ov.displayName=lv.bL.displayName;const uv={workspaces:!1,usageStats:!1};function xv(e){let{selectedUser:s,onClose:t,onUpdateUser:a,userBonusCredits:n,onAddBonusCredits:r,onDeleteBonusCredit:l,loading:i,userUsageStats:o,onDateRangeChange:c,dateRange:d}=e;const[m,u]=(0,H.useState)("details"),[x,h]=(0,H.useState)(d),[p,g]=(0,H.useState)([]),[f,v]=(0,H.useState)(null),[b,j]=(0,H.useState)(null),[y,N]=(0,H.useState)(uv);(0,H.useEffect)(()=>{h(d)},[d]),(0,H.useEffect)(()=>{if(o&&(null==d||!d.startDate)&&(null==x||!x.startDate)){const e=new Date(o.current_credit_period_start_date),s=new Date(o.current_credit_period_end_date);h({startDate:e,endDate:s})}},[o,d,x]),(0,H.useEffect)(()=>{if(!s)return g([]),v(null),void j(null);(async()=>{N(e=>(0,K.A)((0,K.A)({},e),{},{workspaces:!0}));try{var e;const t=await es.default.getUserWorkspacesWithDetails(s.id);g(t.workspaces||[]);const a=null===(e=t.workspaces)||void 0===e?void 0:e.find(e=>e.is_personal);a&&(v(a.id),j(a))}catch(t){g([])}finally{N(e=>(0,K.A)((0,K.A)({},e),{},{workspaces:!1}))}})()},[s]);return(0,re.jsx)(Vm,{open:!!s,onOpenChange:t,className:"bg-white",children:(0,re.jsxs)(Zm,{className:"sm:max-w-xl overflow-y-auto",children:[(0,re.jsx)(Km,{children:(0,re.jsx)(Qm,{children:"User Details"})}),s&&(0,re.jsxs)("div",{className:"py-6",children:[(0,re.jsxs)("div",{className:"mb-6",children:[(0,re.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,re.jsx)("h3",{className:"text-lg font-semibold",children:s.full_name||s.email}),p&&p.length>1&&(0,re.jsx)("div",{className:"w-48",children:(0,re.jsx)(mv,{workspaces:p,selectedWorkspace:f,onWorkspaceChange:e=>{v(e);const s=p.find(s=>s.id===e);j(s),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,re.jsx)("p",{className:"text-gray-600",children:s.email}),b&&!b.is_personal&&(0,re.jsxs)("p",{className:"text-sm text-gray-500 mt-1",children:[b.name," (".concat(b.user_role,")")]})]}),(0,re.jsxs)(hl,{defaultValue:"details",className:"w-full",onValueChange:u,value:m,children:[(0,re.jsxs)(pl,{className:"grid grid-cols-3 mb-6",children:[(0,re.jsxs)(gl,{value:"details",className:"flex items-center gap-2",children:[(0,re.jsx)(np.A,{className:"h-4 w-4"}),"Details"]}),(0,re.jsxs)(gl,{value:"usage",className:"flex items-center gap-2",children:[(0,re.jsx)(Jr.A,{className:"h-4 w-4"}),"Usage"]}),(0,re.jsxs)(gl,{value:"credits",className:"flex items-center gap-2",children:[(0,re.jsx)(Yg.A,{className:"h-4 w-4"}),"Credits"]})]}),(0,re.jsx)(fl,{value:"details",children:(0,re.jsx)(rv,{selectedUser:s,workspaceDetails:b,onUpdateUser:a,loading:i,loadingStates:y})}),(0,re.jsx)(fl,{value:"usage",children:(0,re.jsx)(cv,{userUsageStats:o,dateRange:x,onDateRangeChange:c,selectedWorkspace:f,onSwitchToCreditsTab:()=>u("credits"),isLoading:y.usageStats})}),(0,re.jsx)(fl,{value:"credits",children:(0,re.jsx)(dv,{userBonusCredits:n,onAddBonusCredits:(e,t)=>{r(s.id,e,t)},onDeleteBonusCredit:e=>{l(e)},loading:i})})]})]})]})})}class hv extends X.y{getBaseURL(){return"/admin/analytics"}getAdminStats(){return this.axios.get("/overall")}getTopUsers(e,s){let t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:100;return this.axios.get("/top-users",{params:{start_date:e,end_date:s,limit:t}})}getUserAnalytics(){return this.axios.get("/user-analytics")}getOrganizationsWithPlans(){return this.axios.get("/organizations-with-plans")}getOrganizationUsage(e){return this.axios.get("/organization/".concat(e,"/usage"))}}const pv=new hv;function gv(){const[e,s]=(0,H.useState)(!1),[t,a]=(0,H.useState)([]),[n,r]=(0,H.useState)({startDate:la()().subtract(7,"days").format("YYYY-MM-DD"),endDate:la()().format("YYYY-MM-DD")}),[l,i]=(0,H.useState)(!1),[o,c]=(0,H.useState)(!1);(0,H.useEffect)(()=>{d()},[n.startDate,n.endDate]);const d=async()=>{s(!0);try{const e=await pv.getTopUsers(n.startDate,n.endDate);a(e)}catch(e){}finally{s(!1)}},m=e=>{r("ever"===e?{startDate:"2020-01-01",endDate:la()().format("YYYY-MM-DD")}:{startDate:la()().subtract(e,"days").format("YYYY-MM-DD"),endDate:la()().format("YYYY-MM-DD")})};return(0,re.jsxs)(it,{className:"mb-8",children:[(0,re.jsx)(ot,{children:(0,re.jsxs)(ct,{className:"flex justify-between items-center",children:[(0,re.jsx)("span",{children:"Top Users by Message Count"}),(0,re.jsxs)("div",{className:"flex items-center space-x-2 text-sm",children:[(0,re.jsx)(Hs,{variant:"outline",size:"sm",onClick:()=>m(1),className:n.startDate===la()().subtract(1,"days").format("YYYY-MM-DD")?"bg-blue-50":"",children:"1 Day"}),(0,re.jsx)(Hs,{variant:"outline",size:"sm",onClick:()=>m(7),className:n.startDate===la()().subtract(7,"days").format("YYYY-MM-DD")?"bg-blue-50":"",children:"7 Days"}),(0,re.jsx)(Hs,{variant:"outline",size:"sm",onClick:()=>m(15),className:n.startDate===la()().subtract(15,"days").format("YYYY-MM-DD")?"bg-blue-50":"",children:"15 Days"}),(0,re.jsx)(Hs,{variant:"outline",size:"sm",onClick:()=>m(30),className:n.startDate===la()().subtract(30,"days").format("YYYY-MM-DD")?"bg-blue-50":"",children:"30 Days"}),(0,re.jsx)(Hs,{variant:"outline",size:"sm",onClick:()=>m("ever"),className:"2020-01-01"===n.startDate?"bg-blue-50":"",children:"All Time"}),(0,re.jsxs)("div",{className:"flex items-center space-x-2 ml-4",children:[(0,re.jsxs)(dm,{open:l,onOpenChange:i,children:[(0,re.jsx)(mm,{asChild:!0,children:(0,re.jsxs)(Hs,{variant:"outline",size:"sm",className:"flex items-center gap-1",children:[(0,re.jsx)(im.A,{className:"h-3.5 w-3.5"}),(0,re.jsx)("span",{children:n.startDate})]})}),(0,re.jsx)(um,{className:"w-auto p-0",children:(0,re.jsx)(rm,{mode:"single",selected:new Date(n.startDate),onSelect:e=>{const s=la()(e).format("YYYY-MM-DD");r(e=>(0,K.A)((0,K.A)({},e),{},{startDate:s})),i(!1)},initialFocus:!0,disabled:e=>e>new Date(n.endDate)||e>new Date})})]}),(0,re.jsx)("span",{children:"to"}),(0,re.jsxs)(dm,{open:o,onOpenChange:c,children:[(0,re.jsx)(mm,{asChild:!0,children:(0,re.jsxs)(Hs,{variant:"outline",size:"sm",className:"flex items-center gap-1",children:[(0,re.jsx)(im.A,{className:"h-3.5 w-3.5"}),(0,re.jsx)("span",{children:n.endDate})]})}),(0,re.jsx)(um,{className:"w-auto p-0",children:(0,re.jsx)(rm,{mode:"single",selected:new Date(n.endDate),onSelect:e=>{const s=la()(e).format("YYYY-MM-DD");r(e=>(0,K.A)((0,K.A)({},e),{},{endDate:s})),c(!1)},initialFocus:!0,disabled:e=>enew Date})})]})]})]})]})}),(0,re.jsx)(mt,{children:e?(0,re.jsx)("div",{className:"text-center py-8",children:"Loading top users data..."}):0===t.length?(0,re.jsx)("div",{className:"text-center py-8 text-gray-500",children:"No data available for the selected date range"}):(0,re.jsx)("div",{className:"overflow-x-auto",children:(0,re.jsxs)(Or,{children:[(0,re.jsx)(Rr,{children:(0,re.jsxs)(Fr,{children:[(0,re.jsx)(Br,{children:"Email"}),(0,re.jsx)(Br,{children:"Full Name"}),(0,re.jsx)(Br,{children:"Subscription"}),(0,re.jsx)(Br,{children:"Role"}),(0,re.jsx)(Br,{className:"text-right",children:(0,re.jsxs)("div",{className:"flex items-center justify-end",children:[(0,re.jsx)(bl.A,{className:"h-4 w-4 mr-2"}),"Messages"]})})]})}),(0,re.jsx)(Dr,{children:t.map((e,s)=>{var t,a,n,r,l;return(0,re.jsxs)(Fr,{children:[(0,re.jsx)(Ur,{className:"font-medium",children:e.email}),(0,re.jsx)(Ur,{children:e.full_name||"-"}),(0,re.jsx)(Ur,{children:(0,re.jsx)("span",{className:"px-2 py-1 rounded-full text-xs ".concat(null!==(t=e.subscription_tier)&&void 0!==t&&t.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!==(r=e.subscription_tier)&&void 0!==r&&r.toLowerCase().includes("builder")?"bg-indigo-100 text-indigo-800":null!==(l=e.subscription_tier)&&void 0!==l&&l.toLowerCase().includes("starter")?"bg-green-100 text-green-800":"bg-gray-100 text-gray-800"),children:e.subscription_tier||"Free"})}),(0,re.jsx)(Ur,{children:(0,re.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,re.jsx)(Ur,{className:"text-right font-semibold",children:e.message_count.toLocaleString()})]},s)})})]})})})]})}var fv=t(89284);class vv extends X.y{getBaseURL(){return"/workspace"}updateWorkspace(e,s){const t={workspaceId:e};return this.axios.put("/admin/update",s,{params:t})}}const bv=new vv,jv=[{value:"stripe",label:"Stripe Billing"},{value:"no_billing",label:"No Billing (Free)"}];function yv(e){let{workspace:s,isOpen:t,onClose:a,onSave:n}=e;const[r,l]=(0,H.useState)({billing_type:"stripe",is_enterprise:!1,plans:[]}),[i,o]=(0,H.useState)({billing_type:"stripe",is_enterprise:!1,plans:[]}),[c,d]=(0,H.useState)(!1),[m,u]=(0,H.useState)(""),[x,h]=(0,H.useState)([]),[p,g]=(0,H.useState)(!1);(0,H.useEffect)(()=>{t&&f()},[t]),(0,H.useEffect)(()=>{if(s){const e={billing_type:s.billing_type||"stripe",is_enterprise:s.is_enterprise||!1,plans:s.plans?s.plans.map(e=>({name:e.name.toLowerCase(),price_id:e.price_id,total_seats:e.total_seats||0})):[]};l(e),o(JSON.parse(JSON.stringify(e))),u("")}},[s]);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 s=e.plans.map(e=>({name:e.name.toLowerCase(),price_id:e.price_id,displayName:e.name.charAt(0).toUpperCase()+e.name.slice(1)}));h(s)}}catch(e){u("Failed to load available plans")}finally{g(!1)}},v=e=>{const s=r.plans.find(s=>s.name===e);return s?s.total_seats:0},b=()=>{if(r.billing_type!==i.billing_type)return!0;if(r.is_enterprise!==i.is_enterprise)return!0;const e=[...r.plans].sort((e,s)=>e.name.localeCompare(s.name)),s=[...i.plans].sort((e,s)=>e.name.localeCompare(s.name));if(e.length!==s.length)return!0;for(let t=0;t{u(""),a()};return s?(0,re.jsx)(Pa,{open:t,onOpenChange:j,children:(0,re.jsxs)(Ma,{className:"max-w-2xl max-h-[90vh] overflow-y-auto",children:[(0,re.jsx)(Fa,{children:(0,re.jsx)(Ua,{className:"flex items-center gap-2",children:(0,re.jsxs)("span",{children:["Edit Workspace: ",s.name||s.domain||"Unknown"]})})}),(0,re.jsxs)("div",{className:"space-y-6",children:[m&&(0,re.jsxs)(us,{variant:"destructive",children:[(0,re.jsx)(Xe.A,{className:"h-4 w-4"}),(0,re.jsx)(hs,{children:m})]}),(0,re.jsxs)(it,{children:[(0,re.jsx)(ot,{children:(0,re.jsx)(ct,{className:"text-lg",children:"Billing Configuration"})}),(0,re.jsx)(mt,{children:(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsx)(Nt,{htmlFor:"billing-type",children:"Billing Type"}),(0,re.jsxs)(Ut,{value:r.billing_type,onValueChange:e=>{l(s=>(0,K.A)((0,K.A)({},s),{},{billing_type:e}))},children:[(0,re.jsx)(Wt,{children:(0,re.jsx)(qt,{placeholder:"Select billing type"})}),(0,re.jsx)(Ht,{children:jv.map(e=>(0,re.jsx)($t,{value:e.value,children:e.label},e.value))})]})]})})]}),(0,re.jsxs)(it,{children:[(0,re.jsx)(ot,{children:(0,re.jsxs)(ct,{className:"text-lg flex items-center gap-2",children:[(0,re.jsx)(fv.A,{className:"h-5 w-5"}),"Enterprise Features"]})}),(0,re.jsx)(mt,{children:(0,re.jsxs)("div",{className:"flex items-center justify-between",children:[(0,re.jsxs)("div",{className:"space-y-1",children:[(0,re.jsx)(Nt,{htmlFor:"is-enterprise",className:"text-base",children:"Enable Enterprise Features"}),(0,re.jsx)("p",{className:"text-sm text-slate-600",children:"Enables SSO, advanced security features, and enterprise-level support"})]}),(0,re.jsx)(wu,{id:"is-enterprise",checked:r.is_enterprise,onCheckedChange:e=>l(s=>(0,K.A)((0,K.A)({},s),{},{is_enterprise:e}))})]})})]}),(0,re.jsxs)(it,{children:[(0,re.jsxs)(ot,{children:[(0,re.jsx)(ct,{className:"text-lg",children:"Seat Plans"}),(0,re.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,re.jsx)(mt,{children:p?(0,re.jsxs)("div",{className:"flex items-center justify-center py-8",children:[(0,re.jsx)(Ze.A,{className:"h-6 w-6 animate-spin text-slate-600"}),(0,re.jsx)("span",{className:"ml-2 text-slate-600",children:"Loading plans..."})]}):(0,re.jsx)("div",{className:"space-y-4",children:x.map(e=>(0,re.jsxs)("div",{className:"flex items-center justify-between p-3 border rounded-lg",children:[(0,re.jsxs)("div",{className:"flex-1",children:[(0,re.jsx)("div",{className:"font-medium text-slate-900",children:e.displayName}),(0,re.jsxs)("div",{className:"text-sm text-slate-500",children:["Price ID: ",e.price_id]})]}),(0,re.jsxs)("div",{className:"flex items-center gap-2 min-w-[120px]",children:[(0,re.jsx)(Nt,{htmlFor:"".concat(e.name,"-seats"),className:"text-sm whitespace-nowrap",children:"Total Seats:"}),(0,re.jsx)(ft,{id:"".concat(e.name,"-seats"),type:"number",min:"0",value:v(e.name),onChange:s=>((e,s)=>{const t=parseInt(s)||0,a=x.find(s=>s.name===e);l(s=>{const n=[...s.plans],r=n.findIndex(s=>s.name===e);if(t>0){const s={name:e,price_id:a.price_id,total_seats:t};r>=0?n[r]=s:n.push(s)}else r>=0&&n.splice(r,1);return(0,K.A)((0,K.A)({},s),{},{plans:n})})})(e.name,s.target.value),className:"w-20 text-center",placeholder:"0"})]})]},e.name))})})]}),(0,re.jsxs)("div",{className:"flex justify-end gap-3 pt-4 border-t",children:[(0,re.jsxs)(Hs,{variant:"outline",onClick:j,disabled:c,children:[(0,re.jsx)(zs.A,{className:"h-4 w-4 mr-2"}),"Cancel"]}),(0,re.jsxs)(Hs,{onClick:async()=>{if(s)if(b()){d(!0),u("");try{await n(s.id||s.organization_id,r),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,re.jsx)(ah.A,{className:"h-4 w-4 mr-2"}),c?"Saving...":b()?"Save Changes":"No Changes"]})]})]})]})}):null}function Nv(){const[e,s]=(0,H.useState)(null),[t,a]=(0,H.useState)(!0),[n,r]=(0,H.useState)(""),[l,i]=(0,H.useState)(!1),[o,c]=(0,H.useState)(null);(0,H.useEffect)(()=>{d()},[]);const d=async()=>{try{const e=await pv.getOrganizationsWithPlans();if(null==e||!e.success)return void s(null);const t=e.data,a=t.organizations||[],n=t.all_plans||[],r=a.length;let l=0,i=0;a.forEach(e=>{e.plans&&e.plans.forEach(e=>{l+=e.total_seats||0,i+=e.used_seats||0})});const o=l>0?Math.round(i/l*100*100)/100:0,c={};a.forEach(e=>{e.plans&&e.plans.forEach(e=>{if(e.created_date){const s=new Date(e.created_date).toISOString().split("T")[0];c[s]=(c[s]||0)+(e.total_seats||0)}})}),a.forEach(e=>{if(e.plans){const s=e.plans.reduce((e,s)=>e+(s.total_seats||0),0),t=e.plans.reduce((e,s)=>e+(s.used_seats||0),0),a=s>0?Math.round(t/s*100*100)/100:0;e.plan_summary={total_seats:s,used_seats:t,utilization_rate:a}}else e.plan_summary={total_seats:0,used_seats:0,utilization_rate:0}});s({organizations:a,all_plans:n,total_organizations_with_plans:r,total_seats_purchased:l,total_seats_used:i,overall_utilization_rate:o,seats_by_day:c})}catch(e){s(null)}finally{a(!1)}};if(t)return(0,re.jsx)("div",{className:"flex items-center justify-center h-64",children:(0,re.jsxs)("div",{className:"text-center",children:[(0,re.jsx)("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-slate-600 mx-auto mb-4"}),(0,re.jsx)("p",{className:"text-slate-600",children:"Loading organizations..."})]})});if(!e)return(0,re.jsxs)("div",{className:"text-center py-8",children:[(0,re.jsx)("p",{className:"text-slate-600",children:"Failed to load organizations data"}),(0,re.jsx)("p",{className:"text-sm text-slate-500 mt-2",children:"Check console for debugging information"})]});const m=e.organizations||[],u=e.seats_by_day||{},x=m.reduce((e,s)=>{var t;return e+((null===(t=s.plan_summary)||void 0===t?void 0:t.total_seats)||0)},0),h=m.reduce((e,s)=>{var t;return e+((null===(t=s.plan_summary)||void 0===t?void 0:t.used_seats)||0)},0),p=x>0?Math.round(h/x*100*100)/100:0,g=m.reduce((e,s)=>{var t;const a=null===(t=s.plans)||void 0===t?void 0:t.find(e=>{var s;return null===(s=e.name)||void 0===s?void 0:s.toLowerCase().includes("starter")});return e+((null==a?void 0:a.total_seats)||0)},0),f=m.reduce((e,s)=>{var t;const a=null===(t=s.plans)||void 0===t?void 0:t.find(e=>{var s;return null===(s=e.name)||void 0===s?void 0:s.toLowerCase().includes("builder")});return e+((null==a?void 0:a.total_seats)||0)},0),v=m.reduce((e,s)=>{var t;const a=null===(t=s.plans)||void 0===t?void 0:t.find(e=>{var s;return null===(s=e.name)||void 0===s?void 0:s.toLowerCase().includes("pro")});return e+((null==a?void 0:a.total_seats)||0)},0),b=m.reduce((e,s)=>{var t;return e+((null===(t=s.plans)||void 0===t?void 0:t.filter(e=>{var s;return null===(s=e.name)||void 0===s?void 0:s.toLowerCase().includes("elite")}))||[]).reduce((e,s)=>e+(s.total_seats||0),0)},0),j=m.filter(e=>{var s,t;return!n.trim()||(null===(s=e.name)||void 0===s?void 0:s.toLowerCase().includes(n.toLowerCase()))||(null===(t=e.domain)||void 0===t?void 0:t.toLowerCase().includes(n.toLowerCase()))}).sort((e,s)=>{var t,a;const n=(null===(t=e.plan_summary)||void 0===t?void 0:t.total_seats)||0;return((null===(a=s.plan_summary)||void 0===a?void 0:a.total_seats)||0)-n});return(0,re.jsxs)("div",{className:"space-y-6",children:[(0,re.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-4 gap-4",children:[(0,re.jsx)("div",{className:"bg-white p-4 rounded-lg shadow",children:(0,re.jsxs)("div",{className:"flex items-center",children:[(0,re.jsx)(fv.A,{className:"h-8 w-8 text-slate-600"}),(0,re.jsxs)("div",{className:"ml-3",children:[(0,re.jsx)("p",{className:"text-sm font-medium text-slate-600",children:"Orgs with Plans"}),(0,re.jsx)("p",{className:"text-2xl font-bold text-slate-900",children:e.total_organizations_with_plans||0})]})]})}),(0,re.jsx)("div",{className:"bg-white p-4 rounded-lg shadow",children:(0,re.jsxs)("div",{className:"flex items-center",children:[(0,re.jsx)(Je.A,{className:"h-8 w-8 text-slate-600"}),(0,re.jsxs)("div",{className:"ml-3",children:[(0,re.jsx)("p",{className:"text-sm font-medium text-slate-600",children:"Total Seats Purchased"}),(0,re.jsx)("p",{className:"text-2xl font-bold text-slate-900",children:x})]})]})}),(0,re.jsx)("div",{className:"bg-white p-4 rounded-lg shadow",children:(0,re.jsxs)("div",{className:"flex items-center",children:[(0,re.jsx)(Gr.A,{className:"h-8 w-8 text-slate-600"}),(0,re.jsxs)("div",{className:"ml-3",children:[(0,re.jsx)("p",{className:"text-sm font-medium text-slate-600",children:"Total Seats Used"}),(0,re.jsx)("p",{className:"text-2xl font-bold text-slate-900",children:h})]})]})}),(0,re.jsx)("div",{className:"bg-white p-4 rounded-lg shadow",children:(0,re.jsxs)("div",{className:"flex items-center",children:[(0,re.jsx)(ya.A,{className:"h-8 w-8 text-slate-600"}),(0,re.jsxs)("div",{className:"ml-3",children:[(0,re.jsx)("p",{className:"text-sm font-medium text-slate-600",children:"Utilization Rate"}),(0,re.jsxs)("p",{className:"text-2xl font-bold text-slate-900",children:[p,"%"]})]})]})})]}),(0,re.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-4 gap-4",children:[(0,re.jsx)("div",{className:"bg-white p-4 rounded-lg shadow border-l-4 border-green-500",children:(0,re.jsxs)("div",{className:"flex items-center",children:[(0,re.jsx)("div",{className:"h-8 w-8 bg-green-100 rounded-lg flex items-center justify-center",children:(0,re.jsx)("span",{className:"text-green-600 font-bold text-sm",children:"S"})}),(0,re.jsxs)("div",{className:"ml-3",children:[(0,re.jsx)("p",{className:"text-sm font-medium text-slate-600",children:"Starter Seats"}),(0,re.jsx)("p",{className:"text-2xl font-bold text-slate-900",children:g})]})]})}),(0,re.jsx)("div",{className:"bg-white p-4 rounded-lg shadow border-l-4 border-blue-500",children:(0,re.jsxs)("div",{className:"flex items-center",children:[(0,re.jsx)("div",{className:"h-8 w-8 bg-blue-100 rounded-lg flex items-center justify-center",children:(0,re.jsx)("span",{className:"text-blue-600 font-bold text-sm",children:"B"})}),(0,re.jsxs)("div",{className:"ml-3",children:[(0,re.jsx)("p",{className:"text-sm font-medium text-slate-600",children:"Builder Seats"}),(0,re.jsx)("p",{className:"text-2xl font-bold text-slate-900",children:f})]})]})}),(0,re.jsx)("div",{className:"bg-white p-4 rounded-lg shadow border-l-4 border-purple-500",children:(0,re.jsxs)("div",{className:"flex items-center",children:[(0,re.jsx)("div",{className:"h-8 w-8 bg-purple-100 rounded-lg flex items-center justify-center",children:(0,re.jsx)("span",{className:"text-purple-600 font-bold text-sm",children:"P"})}),(0,re.jsxs)("div",{className:"ml-3",children:[(0,re.jsx)("p",{className:"text-sm font-medium text-slate-600",children:"Pro Seats"}),(0,re.jsx)("p",{className:"text-2xl font-bold text-slate-900",children:v})]})]})}),(0,re.jsx)("div",{className:"bg-white p-4 rounded-lg shadow border-l-4 border-orange-500",children:(0,re.jsxs)("div",{className:"flex items-center",children:[(0,re.jsx)("div",{className:"h-8 w-8 bg-orange-100 rounded-lg flex items-center justify-center",children:(0,re.jsx)("span",{className:"text-orange-600 font-bold text-sm",children:"E"})}),(0,re.jsxs)("div",{className:"ml-3",children:[(0,re.jsx)("p",{className:"text-sm font-medium text-slate-600",children:"Elite Seats"}),(0,re.jsx)("p",{className:"text-2xl font-bold text-slate-900",children:b})]})]})})]}),Object.keys(u).length>0&&(0,re.jsxs)("div",{className:"bg-white p-6 rounded-lg shadow",children:[(0,re.jsxs)("h3",{className:"text-lg font-semibold text-slate-900 mb-4 flex items-center",children:[(0,re.jsx)(im.A,{className:"h-5 w-5 mr-2"}),"Seats Purchased by Day"]}),(0,re.jsx)("div",{className:"grid grid-cols-2 md:grid-cols-4 lg:grid-cols-6 gap-3",children:Object.entries(u).sort((e,s)=>{let[t]=e,[a]=s;return new Date(t)-new Date(a)}).map(e=>{let[s,t]=e;return(0,re.jsxs)("div",{className:"text-center p-3 bg-slate-50 rounded-lg",children:[(0,re.jsx)("div",{className:"text-sm font-medium text-slate-600",children:la()(s).format("MMM DD")}),(0,re.jsx)("div",{className:"text-lg font-bold text-slate-900",children:t}),(0,re.jsx)("div",{className:"text-xs text-slate-500",children:"seats"})]},s)})})]}),(0,re.jsxs)("div",{className:"flex justify-between items-center",children:[(0,re.jsxs)("div",{className:"relative w-72",children:[(0,re.jsx)(vn.A,{className:"absolute left-2 top-2.5 h-4 w-4 text-slate-500"}),(0,re.jsx)(ft,{placeholder:"Search organizations...",className:"pl-8",value:n,onChange:e=>r(e.target.value)})]}),(0,re.jsxs)("div",{className:"text-sm text-slate-600",children:[j.length," of ",m.length," organizations"]})]}),(0,re.jsxs)("div",{className:"bg-white rounded-lg shadow",children:[(0,re.jsx)("div",{className:"p-6 border-b",children:(0,re.jsx)("h3",{className:"text-lg font-semibold text-slate-900",children:"Organizations with Plans"})}),(0,re.jsxs)(Or,{children:[(0,re.jsx)(Rr,{children:(0,re.jsxs)(Fr,{children:[(0,re.jsx)(Br,{children:"Organization Name"}),(0,re.jsx)(Br,{children:"Enterprise"}),(0,re.jsx)(Br,{children:"Total Seats"}),(0,re.jsx)(Br,{children:"Used Seats"}),(0,re.jsx)(Br,{children:"Starter"}),(0,re.jsx)(Br,{children:"Builder"}),(0,re.jsx)(Br,{children:"Pro"}),(0,re.jsx)(Br,{children:"Elite"}),(0,re.jsx)(Br,{children:"Utilization Rate"}),(0,re.jsx)(Br,{children:"Created Date"}),(0,re.jsx)(Br,{children:"Actions"})]})}),(0,re.jsx)(Dr,{children:0===j.length?(0,re.jsx)(Fr,{children:(0,re.jsx)(Ur,{colSpan:11,className:"text-center py-8",children:n?"No organizations found matching your search":"No organizations with plans found"})}):j.map(e=>{var s,t,a,n,r,l,o;const d=(null===(s=e.plans)||void 0===s?void 0:s.find(e=>{var s;return null===(s=e.name)||void 0===s?void 0:s.toLowerCase().includes("starter")}))||{total_seats:0,used_seats:0},m=(null===(t=e.plans)||void 0===t?void 0:t.find(e=>{var s;return null===(s=e.name)||void 0===s?void 0:s.toLowerCase().includes("builder")}))||{total_seats:0,used_seats:0},u=(null===(a=e.plans)||void 0===a?void 0:a.find(e=>{var s;return null===(s=e.name)||void 0===s?void 0:s.toLowerCase().includes("pro")}))||{total_seats:0,used_seats:0},x=(null===(n=e.plans)||void 0===n?void 0:n.filter(e=>{var s;return null===(s=e.name)||void 0===s?void 0:s.toLowerCase().includes("elite")}))||[],h=x.reduce((e,s)=>e+(s.total_seats||0),0),p=x.reduce((e,s)=>e+(s.used_seats||0),0);return(0,re.jsxs)(Fr,{className:"hover:bg-slate-50 transition-colors",children:[(0,re.jsx)(Ur,{className:"font-medium",children:e.name||e.domain||"No name"}),(0,re.jsx)(Ur,{children:e.is_enterprise?(0,re.jsx)("div",{className:"flex items-center justify-center",children:(0,re.jsx)(rp.A,{className:"h-5 w-5 text-yellow-600",title:"Enterprise Enabled"})}):(0,re.jsx)("div",{className:"flex items-center justify-center",children:(0,re.jsx)("span",{className:"text-slate-400",children:"-"})})}),(0,re.jsx)(Ur,{children:(0,re.jsx)("span",{className:"px-2 py-1 rounded-full text-xs bg-slate-100 text-slate-800",children:(null===(r=e.plan_summary)||void 0===r?void 0:r.total_seats)||0})}),(0,re.jsx)(Ur,{children:(0,re.jsx)("span",{className:"px-2 py-1 rounded-full text-xs bg-orange-100 text-orange-800",children:(null===(l=e.plan_summary)||void 0===l?void 0:l.used_seats)||0})}),(0,re.jsx)(Ur,{children:(0,re.jsxs)("div",{className:"text-center",children:[(0,re.jsx)("div",{className:"text-sm font-medium text-slate-900",children:d.total_seats}),(0,re.jsxs)("div",{className:"text-xs text-slate-500",children:[d.used_seats," used"]})]})}),(0,re.jsx)(Ur,{children:(0,re.jsxs)("div",{className:"text-center",children:[(0,re.jsx)("div",{className:"text-sm font-medium text-slate-900",children:m.total_seats}),(0,re.jsxs)("div",{className:"text-xs text-slate-500",children:[m.used_seats," used"]})]})}),(0,re.jsx)(Ur,{children:(0,re.jsxs)("div",{className:"text-center",children:[(0,re.jsx)("div",{className:"text-sm font-medium text-slate-900",children:u.total_seats}),(0,re.jsxs)("div",{className:"text-xs text-slate-500",children:[u.used_seats," used"]})]})}),(0,re.jsx)(Ur,{children:(0,re.jsxs)("div",{className:"text-center",children:[(0,re.jsx)("div",{className:"text-sm font-medium text-slate-900",children:h}),(0,re.jsxs)("div",{className:"text-xs text-slate-500",children:[p," used"]})]})}),(0,re.jsx)(Ur,{children:(0,re.jsxs)("span",{className:"px-2 py-1 rounded-full text-xs bg-blue-100 text-blue-800",children:[(null===(o=e.plan_summary)||void 0===o?void 0:o.utilization_rate)||0,"%"]})}),(0,re.jsx)(Ur,{children:(0,re.jsx)("span",{className:"text-sm text-slate-600",children:e.created_date?la().utc(e.created_date).format("YYYY-MM-DD"):"-"})}),(0,re.jsx)(Ur,{children:(0,re.jsxs)("div",{className:"flex items-center gap-2",children:[(e.id||e.organization_id)&&(0,re.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,re.jsx)(jl.A,{className:"h-3 w-3"}),"Manage"]}),(0,re.jsxs)("button",{onClick:()=>(c(e),void i(!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,re.jsx)(Hr.A,{className:"h-3 w-3"}),"Edit"]})]})})]},e.id||e.organization_id)})})]})]}),(0,re.jsx)(yv,{workspace:o,isOpen:l,onClose:()=>{i(!1),c(null)},onSave:async(e,s)=>{try{await bv.updateWorkspace(e,s),await d()}catch(t){throw t}}})]})}var wv=t(9449);const _v=()=>{const[e,s]=(0,H.useState)([]),[t,a]=(0,H.useState)(!0),{register:n,handleSubmit:r,reset:l,formState:{errors:i}}=(0,wv.useForm)({defaultValues:{code:"",numMessages:"",maxNumberOfPeople:"",domain:""}}),o=async()=>{try{a(!0);const e=await bo.getCouponCodes();s(e||[])}catch(e){ei({title:"Error",description:"Failed to fetch coupon codes",variant:"destructive"})}finally{a(!1)}};(0,H.useEffect)(()=>{o()},[]);return(0,re.jsxs)("div",{className:"container mx-auto py-8 space-y-6",children:[(0,re.jsx)("h1",{className:"text-3xl font-bold",children:"Coupon Code Management"}),(0,re.jsxs)(it,{children:[(0,re.jsxs)(ot,{children:[(0,re.jsx)(ct,{children:"Create Coupon Code"}),(0,re.jsx)(dt,{children:"Create a new coupon code for users to redeem"})]}),(0,re.jsx)(mt,{children:(0,re.jsxs)("form",{onSubmit:r(async e=>{try{a(!0),await bo.createCouponCode(e.code,parseInt(e.numMessages),parseInt(e.maxNumberOfPeople),e.domain||null),ei({title:"Success",description:"Coupon code created successfully"}),l(),o()}catch(s){ei({title:"Error",description:"Failed to create coupon code",variant:"destructive"})}finally{a(!1)}}),className:"space-y-4",children:[(0,re.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsx)(Nt,{htmlFor:"code",children:"Code"}),(0,re.jsx)(ft,(0,K.A)({id:"code",placeholder:"SUMMER2023"},n("code",{required:"Code is required"}))),i.code&&(0,re.jsx)("span",{className:"text-sm text-red-500",children:i.code.message})]}),(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsx)(Nt,{htmlFor:"numMessages",children:"Number of Messages"}),(0,re.jsx)(ft,(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,re.jsx)("span",{className:"text-sm text-red-500",children:i.numMessages.message})]}),(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsx)(Nt,{htmlFor:"maxNumberOfPeople",children:"Max Number of People"}),(0,re.jsx)(ft,(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,re.jsx)("span",{className:"text-sm text-red-500",children:i.maxNumberOfPeople.message})]}),(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsx)(Nt,{htmlFor:"domain",children:"Domain (Optional)"}),(0,re.jsx)(ft,(0,K.A)({id:"domain",placeholder:"example.com"},n("domain"))),(0,re.jsx)("p",{className:"text-xs text-gray-500",children:"Limit code to specific email domain"})]})]}),(0,re.jsx)(Hs,{type:"submit",disabled:t,children:"Create Coupon Code"})]})})]}),(0,re.jsxs)(it,{children:[(0,re.jsxs)(ot,{children:[(0,re.jsx)(ct,{children:"Existing Coupon Codes"}),(0,re.jsx)(dt,{children:"View and manage all available coupon codes"})]}),(0,re.jsx)(mt,{children:t?(0,re.jsx)("div",{className:"flex justify-center items-center py-8",children:(0,re.jsx)("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900"})}):0===e.length?(0,re.jsx)("div",{className:"text-center py-8 text-gray-500",children:"No coupon codes found"}):(0,re.jsx)("div",{className:"rounded-md border",children:(0,re.jsxs)(Or,{children:[(0,re.jsx)(Rr,{children:(0,re.jsxs)(Fr,{children:[(0,re.jsx)(Br,{children:"Code"}),(0,re.jsx)(Br,{children:"Messages"}),(0,re.jsx)(Br,{children:"Max Users"}),(0,re.jsx)(Br,{children:"Domain"}),(0,re.jsx)(Br,{children:"Usage"})]})}),(0,re.jsx)(Dr,{children:e.map((e,s)=>(0,re.jsxs)(Fr,{children:[(0,re.jsx)(Ur,{className:"font-medium",children:e.code}),(0,re.jsx)(Ur,{children:e.num_messages}),(0,re.jsx)(Ur,{children:e.max_number_of_people}),(0,re.jsx)(Ur,{children:e.domain||"Any"}),(0,re.jsxs)(Ur,{children:[e.used_credits||0," / ",e.max_number_of_people]})]},s))})]})})})]})]})};class kv extends X.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,s){return await this.axios.put("/changelog/".concat(e),s)}async deleteChangelogItem(e){return await this.axios.delete("/changelog/".concat(e))}async getAllChangelogItems(){return await this.axios.get("/changelog")}}const Av=new kv,Sv=["is_seen"];function Cv(){const[e,s]=(0,H.useState)([]),[t,a]=(0,H.useState)(!1),[n,r]=(0,H.useState)(!1),[l,i]=(0,H.useState)(null),[o,c]=(0,H.useState)(!1),[d,m]=(0,H.useState)({title:"",content:"",image_url:"",link_url:""}),u=(0,H.useRef)(null);(0,H.useRef)(null);(0,H.useEffect)(()=>{x()},[]),(0,H.useEffect)(()=>{if(n)return document.addEventListener("paste",f),()=>{document.removeEventListener("paste",f)}},[n]);const x=async()=>{a(!0);try{const e=(await Av.getAllChangelogItems()).map(e=>{let{is_seen:s}=e;return(0,as.A)(e,Sv)}).sort((e,s)=>new Date(s.created_date)-new Date(e.created_date));s(e)}catch(e){Xr.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:""})),r(!0)},p=()=>{r(!1),i(null),m({title:"",content:"",image_url:"",link_url:""})},g=async e=>{if(e)if(e.type.startsWith("image/"))if(e.size>5242880)Xr.toast.error("Image must be less than 5MB");else{c(!0);try{const s=(await As.uploadFile(e)).url;if(!s)throw new Error("No URL returned from upload");m(e=>(0,K.A)((0,K.A)({},e),{},{image_url:s})),Xr.toast.success("Image uploaded successfully")}catch(s){Xr.toast.error("Failed to upload image")}finally{c(!1)}}else Xr.toast.error("Please upload an image file")},f=async e=>{var s;const t=null===(s=e.clipboardData)||void 0===s?void 0:s.items;if(t)for(const a of t)if(a.type.startsWith("image/")){e.preventDefault();const s=a.getAsFile();s&&await g(s);break}};return(0,re.jsxs)("div",{children:[(0,re.jsxs)("div",{className:"flex justify-between items-center mb-6",children:[(0,re.jsx)("h2",{className:"text-2xl font-bold",children:"What's New Management"}),(0,re.jsxs)(Hs,{onClick:()=>h(),className:"flex items-center gap-2",children:[(0,re.jsx)(Ss.A,{className:"h-4 w-4"}),"Add New Item"]})]}),(0,re.jsx)("div",{className:"bg-white rounded-lg shadow",children:(0,re.jsxs)(Or,{children:[(0,re.jsx)(Rr,{children:(0,re.jsxs)(Fr,{children:[(0,re.jsx)(Br,{className:"w-[50px]",children:"Image"}),(0,re.jsx)(Br,{children:"Title"}),(0,re.jsx)(Br,{children:"Content"}),(0,re.jsx)(Br,{children:"Created Date"}),(0,re.jsx)(Br,{className:"text-right",children:"Actions"})]})}),(0,re.jsx)(Dr,{children:t?(0,re.jsx)(Fr,{children:(0,re.jsx)(Ur,{colSpan:5,className:"text-center py-8",children:"Loading changelog items..."})}):0===e.length?(0,re.jsx)(Fr,{children:(0,re.jsx)(Ur,{colSpan:5,className:"text-center py-8",children:"No changelog items found"})}):e.map(e=>(0,re.jsxs)(Fr,{children:[(0,re.jsx)(Ur,{children:e.image_url&&(0,re.jsx)("img",{src:e.image_url,alt:"",className:"w-12 h-12 rounded object-cover"})}),(0,re.jsx)(Ur,{className:"font-medium",children:(0,re.jsxs)("div",{className:"flex items-center gap-2",children:[e.title,e.link_url&&(0,re.jsx)("a",{href:e.link_url,target:"_blank",rel:"noopener noreferrer",className:"text-blue-500 hover:text-blue-700",children:(0,re.jsx)(jl.A,{className:"h-3 w-3"})})]})}),(0,re.jsx)(Ur,{children:(0,re.jsx)("p",{className:"text-sm text-gray-600 line-clamp-2 max-w-md",children:e.content})}),(0,re.jsx)(Ur,{children:(0,re.jsxs)("div",{className:"flex items-center gap-1 text-sm text-gray-500",children:[(0,re.jsx)(im.A,{className:"h-3 w-3"}),la()(e.created_date).format("MMM DD, YYYY")]})}),(0,re.jsx)(Ur,{className:"text-right",children:(0,re.jsxs)("div",{className:"flex justify-end gap-2",children:[(0,re.jsx)(Hs,{variant:"outline",size:"sm",onClick:()=>h(e),children:(0,re.jsx)(Dp.A,{className:"h-4 w-4"})}),(0,re.jsx)(Hs,{variant:"outline",size:"sm",onClick:()=>(async e=>{if(window.confirm("Are you sure you want to delete this changelog item?"))try{a(!0),await Av.deleteChangelogItem(e),Xr.toast.success("Changelog item deleted successfully"),x()}catch(s){Xr.toast.error("Failed to delete item")}finally{a(!1)}})(e.id),className:"text-red-600 hover:bg-red-50",children:(0,re.jsx)(_u.A,{className:"h-4 w-4"})})]})})]},e.id))})]})}),(0,re.jsx)(Pa,{open:n,onOpenChange:r,children:(0,re.jsxs)(Ma,{className:"sm:max-w-[525px]",children:[(0,re.jsxs)(Fa,{children:[(0,re.jsx)(Ua,{children:l?"Edit Changelog Item":"Create New Changelog Item"}),(0,re.jsx)(za,{children:l?"Update the details of the changelog item below.":"Fill in the details for the new changelog item."})]}),(0,re.jsxs)("div",{className:"grid gap-4 py-4",children:[(0,re.jsxs)("div",{className:"grid gap-2",children:[(0,re.jsx)(Nt,{htmlFor:"title",children:"Title"}),(0,re.jsx)(ft,{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,re.jsxs)("div",{className:"grid gap-2",children:[(0,re.jsx)(Nt,{htmlFor:"content",children:"Content"}),(0,re.jsx)(td,{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,re.jsxs)("div",{className:"grid gap-2",children:[(0,re.jsx)(Nt,{htmlFor:"image_url",children:"Image"}),(0,re.jsxs)("div",{className:"space-y-2",children:[d.image_url&&(0,re.jsxs)("div",{className:"relative",children:[(0,re.jsx)("img",{src:d.image_url,alt:"Preview",className:"w-full h-48 object-cover rounded-lg border"}),(0,re.jsx)(Hs,{variant:"outline",size:"sm",className:"absolute top-2 right-2",onClick:()=>m((0,K.A)((0,K.A)({},d),{},{image_url:""})),children:"Remove"})]}),(0,re.jsxs)("div",{className:"flex gap-2",children:[(0,re.jsx)(ft,{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,re.jsx)("input",{ref:u,type:"file",accept:"image/*",onChange:async e=>{var s;const t=null===(s=e.target.files)||void 0===s?void 0:s[0];t&&await g(t)},className:"hidden"}),(0,re.jsx)(Hs,{type:"button",variant:"outline",onClick:()=>{var e;return null===(e=u.current)||void 0===e?void 0:e.click()},disabled:o,children:o?(0,re.jsx)(Ze.A,{className:"h-4 w-4 animate-spin"}):(0,re.jsx)(hm.A,{className:"h-4 w-4"})})]}),(0,re.jsx)("p",{className:"text-xs text-gray-500",children:"Upload an image or paste from clipboard (Ctrl/Cmd + V)"})]})]}),(0,re.jsxs)("div",{className:"grid gap-2",children:[(0,re.jsx)(Nt,{htmlFor:"link_url",children:"Link URL (Optional)"}),(0,re.jsx)(ft,{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,re.jsxs)(Ba,{children:[(0,re.jsx)(Hs,{variant:"outline",onClick:p,children:"Cancel"}),(0,re.jsx)(Hs,{onClick:async()=>{try{a(!0),l?(await Av.updateChangelogItem(l.id,d),Xr.toast.success("Changelog item updated successfully")):(await Av.createChangelogItem(d),Xr.toast.success("Changelog item created successfully")),p(),x()}catch(e){Xr.toast.error(l?"Failed to update item":"Failed to create item")}finally{a(!1)}},disabled:t||!d.title||!d.content||!d.image_url,children:l?"Update":"Create"})]})]})})]})}function Ev(){const{user:e}=oe(),[s,t]=(0,J.useSearchParams)(),[a,n]=(0,H.useState)([]),[r,l]=(0,H.useState)(null),[i,o]=(0,H.useState)(!1),[c,d]=(0,H.useState)(""),[m,u]=(0,H.useState)({key:"created_date",direction:"desc"}),[x,h]=(0,H.useState)({totalUsers:0,newUsersToday:0,premiumUsers:0}),[p,g]=(0,H.useState)([]),[f,v]=(0,H.useState)(null),[b,j]=(0,H.useState)(null),[y,N]=(0,H.useState)({startDate:null,endDate:null}),w=(0,H.useRef)(0);(0,H.useEffect)(()=>{A()},[]),(0,H.useEffect)(()=>(f&&clearTimeout(f),v(setTimeout(()=>{c.trim()?k(c):_()},500)),()=>{f&&clearTimeout(f)}),[c]),(0,H.useEffect)(()=>{r?(S(r.id),C(r.id),y.startDate||N({startDate:null,endDate:null})):(j(null),N({startDate:null,endDate:null}))},[r]),(0,H.useEffect)(()=>{const e=s.get("userId");if(e&&a.length>0){const s=a.find(s=>s.id===e);s?l(s):E(e)}},[a,s]);const _=async()=>{o(!0);try{const e=await te.listUsers({limit:100});n(e)}catch(e){}finally{o(!1)}},k=async e=>{o(!0);try{const s=await te.listUsers({limit:100,q:JSON.stringify({$or:[{email:{$regex:e,$options:"i"}},{full_name:{$regex:e,$options:"i"}}]})});n(s)}catch(s){}finally{o(!1)}},A=async()=>{const e=await pv.getUserAnalytics();h(e)},S=async e=>{try{const s=await bo.getBonusCredits(e);g(s)}catch(s){g([])}},C=async function(e){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,t=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 r=Date.now();w.current=r,null!==a&&j(null);try{const n=await es.default.getUserStats(e,s,t,a);r>=w.current&&j(n)}catch(l){r>=w.current&&j(null)}finally{n&&n()}},E=async e=>{o(!0);try{const s=await te.get(e);l(s)}catch(a){const e=new URLSearchParams(s);e.delete("userId"),t(e)}finally{o(!1)}},I=e=>{u({key:e,direction:m.key===e&&"asc"===m.direction?"desc":"asc"})},T=a.sort((e,s)=>"created_date"===m.key?"asc"===m.direction?new Date(e[m.key])-new Date(s[m.key]):new Date(s[m.key])-new Date(e[m.key]):"asc"===m.direction?e[m.key]>s[m.key]?1:-1:s[m.key]>e[m.key]?1:-1);return e.platform_role.includes("admin")?(0,re.jsxs)("div",{className:"container mx-auto py-10 px-4",children:[(0,re.jsx)("h1",{className:"text-3xl font-bold mb-6",children:"Admin Portal"}),(0,re.jsxs)(hl,{defaultValue:"users",className:"mb-8",children:[(0,re.jsxs)(pl,{className:"grid grid-cols-5 w-[700px] mb-4",children:[(0,re.jsx)(gl,{value:"users",children:"User Management"}),(0,re.jsx)(gl,{value:"organizations",children:"Organizations"}),(0,re.jsx)(gl,{value:"statistics",children:"Statistics"}),(0,re.jsx)(gl,{value:"coupons",children:"Coupon Codes"}),(0,re.jsx)(gl,{value:"changelog",children:"What's New"})]}),(0,re.jsxs)(fl,{value:"users",children:[(0,re.jsxs)("div",{className:"mb-4",children:[(0,re.jsx)("h2",{className:"text-2xl font-bold mb-4",children:"User Management"}),(0,re.jsx)(av,{stats:x}),(0,re.jsxs)("div",{className:"flex justify-between items-center mb-6 mt-6",children:[(0,re.jsxs)("div",{className:"relative w-72",children:[(0,re.jsx)(vn.A,{className:"absolute left-2 top-2.5 h-4 w-4 text-gray-500"}),(0,re.jsx)(ft,{placeholder:"Search users...",className:"pl-8",value:c,onChange:e=>d(e.target.value)})]}),(0,re.jsxs)(Hs,{onClick:()=>{const e=T.map(e=>[e.email,e.full_name||"",e.platform_role,la().utc(e.created_date).format("YYYY-MM-DD HH:mm:ss"),e.subscription_tier||"Free",e.stripe_customer_id||"",e.api_key||""]),s=[["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"),t=new Blob([s],{type:"text/csv;charset=utf-8;"}),a=document.createElement("a"),n=URL.createObjectURL(t);a.setAttribute("href",n),a.setAttribute("download","users_".concat(la()().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,re.jsx)(Rd.A,{className:"h-4 w-4"}),"Download CSV"]})]})]}),(0,re.jsx)("div",{className:"bg-white rounded-lg shadow",children:(0,re.jsxs)(Or,{children:[(0,re.jsx)(Rr,{children:(0,re.jsxs)(Fr,{children:[(0,re.jsx)(Br,{className:"cursor-pointer",onClick:()=>I("email"),children:(0,re.jsxs)("div",{className:"flex items-center",children:["Email",(0,re.jsx)(Xf.A,{className:"ml-2 h-4 w-4"})]})}),(0,re.jsx)(Br,{className:"cursor-pointer",onClick:()=>I("full_name"),children:(0,re.jsxs)("div",{className:"flex items-center",children:["Full Name",(0,re.jsx)(Xf.A,{className:"ml-2 h-4 w-4"})]})}),(0,re.jsx)(Br,{className:"cursor-pointer",onClick:()=>I("platform_role"),children:(0,re.jsxs)("div",{className:"flex items-center",children:["Platform Role",(0,re.jsx)(Xf.A,{className:"ml-2 h-4 w-4"})]})}),(0,re.jsx)(Br,{className:"cursor-pointer",onClick:()=>I("created_date"),children:(0,re.jsxs)("div",{className:"flex items-center",children:["Created Date",(0,re.jsx)(Xf.A,{className:"ml-2 h-4 w-4"})]})}),(0,re.jsx)(Br,{className:"cursor-pointer",onClick:()=>I("subscription_tier"),children:(0,re.jsxs)("div",{className:"flex items-center",children:["Subscription Plan",(0,re.jsx)(Xf.A,{className:"ml-2 h-4 w-4"})]})}),(0,re.jsx)(Br,{children:"Actions"})]})}),(0,re.jsx)(Dr,{children:i?(0,re.jsx)(Fr,{children:(0,re.jsx)(Ur,{colSpan:6,className:"text-center py-8",children:"Loading users..."})}):0===T.length?(0,re.jsx)(Fr,{children:(0,re.jsx)(Ur,{colSpan:6,className:"text-center py-8",children:"No users found"})}):T.map(e=>{var a,n,r,i,o;return(0,re.jsxs)(Fr,{className:"hover:bg-gray-50 cursor-pointer",onClick:()=>{l(e);const a=new URLSearchParams(s);a.set("userId",e.id),t(a)},children:[(0,re.jsx)(Ur,{className:"font-medium",children:e.email}),(0,re.jsx)(Ur,{children:e.full_name||"-"}),(0,re.jsx)(Ur,{children:(0,re.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,re.jsx)(Ur,{children:la().utc(e.created_date).fromNow()}),(0,re.jsx)(Ur,{children:(0,re.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!==(r=e.subscription_tier)&&void 0!==r&&r.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,re.jsx)(Ur,{children:(0,re.jsx)(Hs,{variant:"outline",size:"sm",onClick:a=>{a.stopPropagation(),l(e);const n=new URLSearchParams(s);n.set("userId",e.id),t(n)},children:"Edit"})})]},e.id)})})]})})]}),(0,re.jsx)(fl,{value:"organizations",children:(0,re.jsx)(Nv,{})}),(0,re.jsx)(fl,{value:"statistics",children:(0,re.jsxs)("div",{children:[(0,re.jsx)("h2",{className:"text-2xl font-bold mb-4",children:"User Statistics"}),(0,re.jsx)(gv,{})]})}),(0,re.jsx)(fl,{value:"coupons",children:(0,re.jsxs)("div",{children:[(0,re.jsx)("h2",{className:"text-2xl font-bold mb-4",children:"Coupon Code Management"}),(0,re.jsx)(_v,{})]})}),(0,re.jsx)(fl,{value:"changelog",children:(0,re.jsx)(Cv,{})})]}),(0,re.jsx)(xv,{selectedUser:r,onClose:()=>{l(null);const e=new URLSearchParams(s);e.delete("userId"),t(e)},onUpdateUser:async(e,s)=>{o(!0);try{const t=await te.updateUser(e,s);n(a.map(s=>s.id===e?t:s)),l(t)}catch(t){}finally{o(!1)}},userBonusCredits:p,onAddBonusCredits:async(e,s,t)=>{o(!0);try{await bo.addBonusCredits(e,s,t),await S(e)}catch(a){}finally{o(!1)}},onDeleteBonusCredit:async e=>{if(r&&e){o(!0);try{await Ji.deleteBonusCredits(r.id,e),await S(r.id)}catch(s){}finally{o(!1)}}},loading:i,userUsageStats:b,onDateRangeChange:(e,s,t,a)=>{N({startDate:e,endDate:s}),r?C(r.id,e,s,t,a):a&&a()},dateRange:y})]}):(0,re.jsx)("div",{className:"flex items-center justify-center h-screen",children:(0,re.jsxs)("div",{className:"text-center",children:[(0,re.jsx)(Kf.A,{className:"w-16 h-16 text-red-500 mx-auto mb-4"}),(0,re.jsx)("h2",{className:"text-2xl font-bold text-gray-800",children:"Access Denied"}),(0,re.jsx)("p",{className:"text-gray-600",children:"You are not authorized to access this page"})]})})}const Iv=e=>{let{data:s,title:t="Bar Chart",barColor:a="#14b8a6",maxWidth:n="800px",maxLabelWidth:r="40%",backgroundColor:l="white",textColor:i="#1f2937",renderLabel:o=e=>e.name,renderValue:c=e=>e.value}=e;const d=Math.max(...s.map(e=>e.value)),m=s.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,re.jsxs)("div",{style:{width:"100%",maxWidth:n,margin:"0 auto",padding:"24px",backgroundColor:l,borderRadius:"8px",overflow:"hidden"},children:[t&&(0,re.jsx)("h2",{style:{fontSize:"24px",fontWeight:"bold",marginBottom:"24px",color:i,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:t}),(0,re.jsx)("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:s.map((e,s)=>{const t=e.value/d*100;return(0,re.jsxs)("div",{style:{position:"relative",height:u,marginBottom:"8px",overflow:"hidden"},children:[(0,re.jsx)("div",{style:{position:"absolute",top:0,left:0,height:"100%",width:"".concat(t,"%"),backgroundColor:a,borderRadius:"4px",transition:"width 0.5s ease-in-out"}}),(0,re.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:r},children:o(e)}),(0,re.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)})]},s)})})]})};function Tv(e){var s;let{appId:t,pageNames:a}=e;const[n,r]=(0,H.useState)(null),[l,i]=(0,H.useState)({from:void 0,to:void 0}),[o,c]=(0,H.useState)("all"),[d,m]=(0,H.useState)(null),[u,x]=(0,H.useState)(!0),[h,p]=(0,H.useState)(!1);(0,H.useEffect)(()=>{(async()=>{x(!0);try{const e={};null!=l&&l.from&&(e.date_from=(0,lm.GP)(l.from,"yyyy-MM-dd")),null!=l&&l.to&&(e.date_to=(0,lm.GP)(l.to,"yyyy-MM-dd")),"all"!==o&&(e.page_name=o),d&&(e.user_email=d);const s=await wa.getStats(t,e);r(s)}catch(e){}finally{x(!1)}})()},[t,l,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===(s=n.top_users)||void 0===s?void 0:s.length)>5;return u&&!n?(0,re.jsx)("div",{className:"h-full w-full flex items-center justify-center",children:(0,re.jsx)(Ze.A,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):(0,re.jsxs)("div",{className:"space-y-4 p-4",children:[(0,re.jsxs)("div",{className:"flex flex-col sm:flex-row gap-3",children:[(0,re.jsxs)(dm,{children:[(0,re.jsx)(mm,{asChild:!0,children:(0,re.jsxs)(Hs,{variant:"outline",className:is("w-full sm:w-[240px] justify-start text-left font-normal",!l&&"text-muted-foreground"),children:[(0,re.jsx)(im.A,{className:"mr-2 h-4 w-4"}),null!=l&&l.from?l.to?(0,re.jsxs)(re.Fragment,{children:[(0,lm.GP)(l.from,"LLL dd, y")," - ",(0,lm.GP)(l.to,"LLL dd, y")]}):(0,lm.GP)(l.from,"LLL dd, y"):(0,re.jsx)("span",{children:"Pick a date range"})]})}),(0,re.jsx)(um,{className:"w-auto p-0",align:"start",children:(0,re.jsx)(rm,{initialFocus:!0,mode:"range",defaultMonth:null==l?void 0:l.from,selected:l,onSelect:i,numberOfMonths:1})})]}),(0,re.jsxs)(Ut,{value:o,onValueChange:c,children:[(0,re.jsx)(Wt,{className:"w-full sm:w-[240px]",children:(0,re.jsx)(qt,{placeholder:"Filter by page"})}),(0,re.jsxs)(Ht,{children:[(0,re.jsx)($t,{value:"all",children:"All Pages"}),null==a?void 0:a.map(e=>(0,re.jsx)($t,{value:e,children:e},e))]})]}),d&&(0,re.jsxs)("div",{className:"flex items-center gap-2 bg-muted px-3 py-2 rounded-md",children:[(0,re.jsxs)("span",{className:"text-sm",children:["Filtered by user: ",d]}),(0,re.jsx)("button",{onClick:()=>m(null),className:"text-muted-foreground hover:text-foreground",children:(0,re.jsx)(Dx.A,{className:"h-4 w-4"})})]}),u&&(0,re.jsxs)("div",{className:"flex items-center gap-2",children:[(0,re.jsx)(Ze.A,{className:"h-4 w-4 animate-spin text-muted-foreground"}),(0,re.jsx)("span",{className:"text-sm text-muted-foreground",children:"Updating..."})]})]}),(0,re.jsxs)("div",{className:"grid gap-4 grid-cols-1 md:grid-cols-2",children:[(0,re.jsxs)(it,{children:[(0,re.jsx)(ot,{className:"pb-2",children:(0,re.jsx)(ct,{className:"text-lg",children:"Total Unique Users"})}),(0,re.jsx)(mt,{children:(0,re.jsx)("div",{className:"text-3xl font-bold",children:(null==n?void 0:n.unique_users_count)||0})})]}),(0,re.jsxs)(it,{children:[(0,re.jsx)(ot,{className:"pb-2",children:(0,re.jsx)(ct,{className:"text-lg",children:"Top Users"})}),(0,re.jsx)(mt,{children:(0,re.jsxs)("div",{className:"space-y-2",children:[f.map((e,s)=>(0,re.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,re.jsx)("span",{className:"truncate max-w-[180px]",children:e.email}),(0,re.jsxs)("span",{className:"font-semibold",children:[e.visits," visits"]})]},s)),v&&(0,re.jsx)(Hs,{variant:"ghost",className:"w-full mt-2 text-sm text-muted-foreground hover:text-foreground",onClick:()=>p(!h),children:h?(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(Tt.A,{className:"h-4 w-4 mr-2"})," Show Less"]}):(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(It.A,{className:"h-4 w-4 mr-2"})," Show More Users"]})})]})})]})]}),(0,re.jsxs)(it,{children:[(0,re.jsx)(ot,{children:(0,re.jsx)(ct,{className:"text-lg",children:"Top Pages"})}),(0,re.jsxs)(mt,{children:[(0,re.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,re.jsx)(Iv,{data:g,title:"",maxWidth:"100%",maxLabelWidth:"60%",backgroundColor:"transparent",renderLabel:e=>"all"===t?(0,re.jsx)(J.Link,{to:"/apps/".concat(e.name),target:"_blank",className:"hover:underline",children:e.name}):e.name})]})]}),(0,re.jsxs)(it,{children:[(0,re.jsx)(ot,{children:(0,re.jsx)(ct,{className:"text-lg",children:"Unique Users Over Time"})}),(0,re.jsxs)(mt,{children:[(0,re.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,re.jsx)("div",{className:"h-[200px] flex items-center justify-center text-muted-foreground",children:"Not enough data to show trends"}):(0,re.jsx)("div",{className:"h-[300px]",children:(0,re.jsx)(Wx.u,{width:"100%",height:"100%",children:(0,re.jsxs)(Vx.Q,{data:n.users_per_date,margin:{top:10,right:10,left:0,bottom:0},children:[(0,re.jsx)(Yx.d,{strokeDasharray:"3 3"}),(0,re.jsx)(Hx.W,{dataKey:"date"}),(0,re.jsx)(Gx.h,{}),(0,re.jsx)($x.m,{}),(0,re.jsx)(Jx.G,{type:"monotone",dataKey:"unique_users",stroke:"#8884d8",fill:"#8884d8",name:"Unique Users"})]})})})]})]}),(0,re.jsxs)(it,{children:[(0,re.jsx)(ot,{children:(0,re.jsx)(ct,{className:"text-lg",children:"Total Usage Over Time"})}),(0,re.jsxs)(mt,{children:[(0,re.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,re.jsx)("div",{className:"h-[200px] flex items-center justify-center text-muted-foreground",children:"Not enough data to show trends"}):(0,re.jsx)("div",{className:"h-[300px]",children:(0,re.jsx)(Wx.u,{width:"100%",height:"100%",children:(0,re.jsxs)(Vx.Q,{data:n.users_per_date,margin:{top:10,right:10,left:0,bottom:0},children:[(0,re.jsx)(Yx.d,{strokeDasharray:"3 3"}),(0,re.jsx)(Hx.W,{dataKey:"date"}),(0,re.jsx)(Gx.h,{}),(0,re.jsx)($x.m,{}),(0,re.jsx)(Jx.G,{type:"monotone",dataKey:"total_visits",stroke:"#82ca9d",fill:"#82ca9d",name:"Total Visits"})]})})})]})]})]})}const Pv=function(){var e,s;const[t,a]=(0,H.useState)(null),[n,r]=(0,H.useState)([]),[l,i]=(0,H.useState)(!0);if((0,H.useEffect)(()=>{(async()=>{try{const[e,s]=await Promise.all([pv.getAdminStats(),wa.getTrendingApps()]);a(e),r(s.trending_apps)}catch(e){}finally{i(!1)}})()},[]),l)return(0,re.jsx)("div",{className:"h-full w-full flex items-center justify-center",children:(0,re.jsx)(Ze.A,{className:"h-8 w-8 animate-spin text-muted-foreground"})});const o=(null==t||null===(e=t.usage_by_date)||void 0===e?void 0:e.map(e=>({date:e._id,messages:e.total_messages})))||[],c=(null==t||null===(s=t.tokens_by_user_7d)||void 0===s?void 0:s.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,re.jsxs)("div",{className:"container mx-auto py-6 space-y-6",children:[(0,re.jsx)("h1",{className:"text-2xl font-bold mb-6",children:"Platform Analytics"}),(0,re.jsxs)(it,{children:[(0,re.jsx)(ot,{children:(0,re.jsx)(ct,{children:"Messages Per Day"})}),(0,re.jsx)(mt,{children:(0,re.jsx)("div",{className:"h-[400px]",children:(0,re.jsx)(Wx.u,{width:"100%",height:"100%",children:(0,re.jsxs)(Vx.Q,{data:o,children:[(0,re.jsx)(Yx.d,{strokeDasharray:"3 3"}),(0,re.jsx)(Hx.W,{dataKey:"date"}),(0,re.jsx)(Gx.h,{}),(0,re.jsx)($x.m,{}),(0,re.jsx)(Jx.G,{type:"monotone",dataKey:"messages",stroke:"#8884d8",fill:"#8884d8",fillOpacity:.3})]})})})})]}),(0,re.jsxs)(it,{children:[(0,re.jsx)(ot,{children:(0,re.jsx)(ct,{children:"Top Users by Token Usage (Last 7 Days)"})}),(0,re.jsx)(mt,{children:(0,re.jsx)("div",{className:"h-[400px]",children:(0,re.jsx)(Wx.u,{width:"100%",height:"100%",children:(0,re.jsxs)(xf.E,{data:c,children:[(0,re.jsx)(Yx.d,{strokeDasharray:"3 3"}),(0,re.jsx)(Hx.W,{dataKey:"user",angle:-45,textAnchor:"end",height:100}),(0,re.jsx)(Gx.h,{}),(0,re.jsx)($x.m,{}),(0,re.jsx)(hf.y,{dataKey:"tokens",fill:"#82ca9d"})]})})})})]}),(0,re.jsxs)(it,{children:[(0,re.jsx)(ot,{children:(0,re.jsx)(ct,{children:"Trending Apps (Last 7 Days)"})}),(0,re.jsx)(mt,{children:(0,re.jsx)("div",{className:"h-[400px]",children:(0,re.jsx)(Wx.u,{width:"100%",height:"100%",children:(0,re.jsxs)(xf.E,{data:d,children:[(0,re.jsx)(Yx.d,{strokeDasharray:"3 3"}),(0,re.jsx)(Hx.W,{dataKey:"name",angle:-45,textAnchor:"end",height:100}),(0,re.jsx)(Gx.h,{}),(0,re.jsx)($x.m,{}),(0,re.jsx)(hf.y,{dataKey:"visits",fill:"#8884d8",name:"Total Visits"}),(0,re.jsx)(hf.y,{dataKey:"users",fill:"#82ca9d",name:"Unique Users"})]})})})})]}),(0,re.jsx)(Tv,{appId:"all"})]})},Lv=["className","variant","size","asChild"],Ov=(0,ns.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"}}),Rv=H.forwardRef((e,s)=>{let{className:t,variant:a,size:n,asChild:r=!1}=e,l=(0,as.A)(e,Lv);const i=r?Ws.DX:"button";return(0,re.jsx)(i,(0,K.A)({className:is(Ov({variant:a,size:n,className:t})),ref:s},l))});Rv.displayName="Button";const Dv=["className","type"],Mv=H.forwardRef((e,s)=>{let{className:t,type:a}=e,n=(0,as.A)(e,Dv);return(0,re.jsx)("input",(0,K.A)({type:a,className:is("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",t),ref:s},n))});function Fv(e){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"/";return function(e){if(!e)return!1;try{const t=decodeURIComponent(e);if(t.match(/^(javascript|data|vbscript|file|about):/i))return!1;if(t.startsWith("/")&&!t.startsWith("//"))return!t.includes(":");let a;try{a=new URL(t)}catch(s){return!1}return!!["http:","https:"].includes(a.protocol)}catch(t){return!1}}(e)?e:s}Mv.displayName="Input";const Bv=e=>{let{buttonText:s={default:"Continue with Google",loading:"Please wait..."},showLastUsed:t=!1}=e;const a=(0,Z.zy)(),n=new URLSearchParams(a.search),[r,l]=(0,H.useState)(!1);return(0,re.jsxs)("div",{className:"relative",children:[(0,re.jsxs)(Rv,{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(t?"border border-[#FF983B]":"border border-[#E4E4E7]"),type:"button",onClick:async()=>{l(!0);try{sessionStorage.setItem("pendingAuthMethod","google"),localStorage.setItem("lastUsedAuthMethod","google");const e=Fv(n.get("from_url"),"/"),s=n.get("ref");let t="".concat((0,ee.Zk)(),"/auth/login?from_url=").concat(encodeURIComponent(e),"&auth_method=google");s&&(t+="&ref=".concat(encodeURIComponent(s))),window.location.href=t}catch(e){l(!1)}},disabled:r,children:[(0,re.jsxs)("svg",{className:"h-4 w-4",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:[(0,re.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,re.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,re.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,re.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"})]}),r?s.loading:s.default]}),t&&!r&&(0,re.jsx)("div",{className:"absolute",style:{top:"-25px",right:"20px"},children:(0,re.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"})})]})},Uv=()=>(0,re.jsxs)("svg",{width:"147",height:"24",viewBox:"0 0 147 36",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[(0,re.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,re.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"}),(0,re.jsx)("path",{d:"M45.675 6.95605H55.3324C59.9211 6.95605 62.1243 9.07361 62.1243 12.4343C62.1243 14.6432 60.9159 16.248 59.2275 17.003C61.3117 17.6071 63 19.2435 63 21.9335C63 25.7753 60.3449 27.9561 55.3324 27.9561H45.675V6.95605ZM54.2465 10.4362H49.9905V15.6405H54.2465C56.5689 15.6405 57.7178 14.9452 57.7178 13.0383C57.7178 11.1315 56.5724 10.4362 54.2465 10.4362ZM54.912 18.938H49.994V24.476H54.912C57.2974 24.476 58.5935 23.7209 58.5935 21.7228C58.5935 19.7246 57.2939 18.938 54.912 18.938Z",fill:"black"}),(0,re.jsx)("path",{d:"M74.486 27.919V25.5781C73.3926 27.3477 71.3255 28.2186 68.9834 28.2186C66.0662 28.2186 63.7875 26.658 63.7875 23.8364C63.7875 21.1959 65.7946 19.6945 68.74 19.1824L74.2109 18.2524V17.8936C74.2109 16.2737 72.994 15.5527 71.262 15.5527C69.4384 15.5527 68.5565 16.3643 68.4366 17.6253H64.3343C64.486 14.4449 67.0398 12.7311 71.2656 12.7311C75.9146 12.7311 78.225 14.6226 78.225 18.5833V27.919H74.486ZM74.2144 21.7358V21.0461L70.1121 21.7672C68.4719 22.0389 67.71 22.5161 67.71 23.6587C67.71 24.648 68.5918 25.2785 70.1121 25.2785C72.0874 25.2785 74.2144 24.0175 74.2144 21.7358Z",fill:"black"}),(0,re.jsx)("path",{d:"M86.4047 12.7311C90.0182 12.7311 93.1215 14.26 93.181 17.5337H89.1445C89.0537 16.4227 88.0612 15.552 86.2824 15.552C84.8355 15.552 83.8116 16.1511 83.8116 17.0531C83.8116 17.9551 84.5036 18.2232 85.8001 18.4636L89.204 19.1253C91.9159 19.6337 93.45 21.0164 93.45 23.4159C93.45 26.3275 91.0701 28.2186 86.6738 28.2186C82.2774 28.2186 79.6878 26.2683 79.5375 23.1164H83.7522C83.871 24.3772 84.8356 25.3976 86.8241 25.3976C88.6623 25.3976 89.5325 24.708 89.5325 23.8373C89.5325 22.9667 88.8405 22.608 87.544 22.3676L84.1401 21.7373C81.4317 21.2288 79.894 19.8183 79.894 17.4153C79.894 14.5351 82.5151 12.7345 86.3977 12.7345L86.4047 12.7311Z",fill:"black"}),(0,re.jsx)("path",{d:"M101.797 12.7311C106.609 12.7311 109.463 15.5834 109.463 20.3825V21.6746H98.099C98.1897 23.5065 99.5713 25.2165 101.766 25.2165C103.36 25.2165 104.683 24.4364 105.042 23.1164H109.25C108.59 26.418 105.611 28.2186 101.762 28.2186C97.314 28.2186 93.975 25.4568 93.975 20.4765C93.975 15.8237 97.0104 12.7345 101.79 12.7345L101.797 12.7311ZM105.342 18.9128C105.251 16.9939 103.748 15.6112 101.885 15.6112C99.84 15.6112 98.3677 17.1401 98.1269 18.9128H105.342Z",fill:"black"}),(0,re.jsx)("path",{d:"M124.283 27.9561V23.598H113.925V20.0863L123.469 6.95605H128.363V27.9561H124.283ZM124.283 11.4651L118.061 20.1811H124.283V11.4651Z",fill:"black"}),(0,re.jsx)("path",{d:"M140.333 23.5952H129.938V20.0841L139.514 6.95605H144.425V20.1789H147V23.5988H144.425V27.9561H140.333V23.5952ZM140.333 11.4643L134.089 20.1789H140.333V11.4643Z",fill:"black"})]}),zv=e=>{let{className:s=""}=e;return(0,re.jsx)("div",{className:"hidden lg:block relative min-h-screen p-4 ".concat(s),children:(0,re.jsx)("div",{className:"h-full w-full bg-white rounded-2xl p-4",children:(0,re.jsxs)("div",{className:"relative h-full w-full",children:[(0,re.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,re.jsx)("div",{className:"absolute inset-0 flex items-center justify-center py-6 px-12 xl:px-16 2xl:px-20",children:(0,re.jsx)("div",{className:"w-full max-w-3xl",children:(0,re.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,re.jsxs)("div",{className:"flex items-center gap-4",children:[(0,re.jsxs)("div",{className:"flex-1 flex items-center gap-3",children:[(0,re.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,re.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,re.jsx)("div",{className:"flex-shrink-0",children:(0,re.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,re.jsx)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",className:"text-white",children:(0,re.jsx)("path",{d:"M12 4L12 20M12 4L18 10M12 4L6 10",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})})})]})})})})]})})})},qv=e=>{let{className:s=""}=e;return(0,re.jsx)("div",{className:"lg:hidden absolute inset-0 ".concat(s),children:(0,re.jsx)("img",{src:"/assets/auth/auth-page-image.jpg",alt:"Creative workspace",className:"absolute inset-0 h-full w-full object-cover"})})},Wv=e=>{let{title:s,subtitle:t,showImageColumn:a=!0,backLink:n,footerContent:r,children:l,className:i=""}=e;return(0,re.jsx)("div",{className:"min-h-screen bg-white",children:(0,re.jsxs)("div",{className:"".concat(a?"grid grid-cols-1 lg:grid-cols-2":""," min-h-screen"),children:[(0,re.jsxs)("div",{className:"relative min-h-screen",children:[(0,re.jsx)(qv,{}),(0,re.jsx)("div",{className:"absolute top-6 lg:top-8 z-10",children:(0,re.jsx)(J.Link,{to:"/",children:(0,re.jsx)(Uv,{})})}),(0,re.jsx)("div",{className:"flex items-center justify-center min-h-screen p-6 lg:p-8 relative z-10",children:(0,re.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,re.jsx)("div",{className:"mb-6",children:(0,re.jsxs)(J.Link,{to:n.href,className:"inline-flex items-center text-sm text-[#71717A] hover:text-[#09090B] font-medium",children:[(0,re.jsx)("svg",{className:"w-4 h-4 mr-2",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,re.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 19l-7-7 7-7"})}),n.text]})}),(0,re.jsxs)("div",{className:"space-y-2 text-center",children:[(0,re.jsx)("h1",{className:"text-[20px] lg:text-[48px] font-semibold text-[#09090B] leading-[61px] tracking-[0%] text-center",children:s}),t&&(0,re.jsx)("p",{className:"text-[#71717A] text-base leading-6",children:t})]}),l]})}),r&&(0,re.jsx)("div",{className:"absolute bottom-6 left-6 right-6 lg:bottom-8 lg:left-8 lg:right-8 z-20",children:r})]}),a&&(0,re.jsx)(zv,{})]})})},Vv=()=>{const[e,s]=(0,H.useState)(!1),[t,a]=(0,H.useState)(null),[n,r]=(0,H.useState)(null),[l,i]=(0,H.useState)(!1),[o,c]=(0,H.useState)(null),[d,m]=(0,H.useState)(!1),[u,x]=(0,H.useState)(!1),[h,p]=(0,H.useState)(null),[g,f]=(0,H.useState)(!1),[v,b]=(0,H.useState)({email:"",password:""}),j=(0,Z.Zp)(),y=(0,Z.zy)();(0,H.useEffect)(()=>{const e=y.state;null!=e&&e.message&&(r(e.message),e.email&&b(s=>(0,K.A)((0,K.A)({},s),{},{email:e.email})));const s=new URLSearchParams(window.location.search),t=s.get("auth_method"),a=sessionStorage.getItem("pendingAuthMethod");"google"!==t&&"google"!==a||(localStorage.setItem("lastUsedAuthMethod","google"),sessionStorage.removeItem("pendingAuthMethod")),"true"===s.get("auth_success")&&a&&(localStorage.setItem("lastUsedAuthMethod",a),sessionStorage.removeItem("pendingAuthMethod"));const n=localStorage.getItem("lastUsedAuthMethod");c(n)},[y]);const N=e=>{const{name:s,value:l}=e.target;b(e=>(0,K.A)((0,K.A)({},e),{},{[s]:l})),t&&a(null),n&&r(null)};return(0,re.jsxs)(Wv,{title:"Welcome to Base44",showImageColumn:!0,children:[(0,re.jsx)(Bv,{buttonText:{default:"Log in with Google",loading:"Logging in..."},showLastUsed:"google"===o}),(0,re.jsxs)("div",{className:"relative",children:[(0,re.jsx)("div",{className:"absolute inset-0 flex items-center",children:(0,re.jsx)(pt,{})}),(0,re.jsx)("div",{className:"relative flex justify-center text-xs uppercase",children:(0,re.jsx)("span",{className:"bg-white px-2 text-slate-500",children:"Or"})})]}),l&&(0,re.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,re.jsx)("div",{className:"mt-2",children:(0,re.jsx)("button",{onClick:async()=>{if(v.email)try{s(!0),await te.resendOtp(v.email),j("/verify-email",{state:{email:v.email,isFromLogin:!0}})}catch(t){a("Failed to resend verification code. Please try again.")}finally{s(!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,re.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")||"/",s="".concat((0,ee.Zk)(),"/workspaces/").concat(h.workspace_id,"/auth/sso/login?from_url=").concat(encodeURIComponent(e));window.location.replace(s)})();else{s(!0),a(null),r(null),i(!1);try{const e=await te.login(v.email,v.password,null);if(e.success&&e.access_token){(0,ne.O5)(e.access_token),localStorage.setItem("lastUsedAuthMethod","email");const s=new URLSearchParams(window.location.search),t=Fv(s.get("from_url"),"/");window.location.href=t}else a("Login failed. Please try again.")}catch(t){var n;if(400===(null===(n=t.response)||void 0===n?void 0:n.status)){var l;const s=(null===(l=t.response.data)||void 0===l?void 0:l.detail)||"Invalid email or password";s.includes("verify your email")?(i(!0),a("Please verify your email before logging in. Check your email for the verification code.")):a(s)}else a("Login failed. Please try again.")}finally{s(!1)}}else await(async()=>{var e;const s=v.email;if(s.includes("@")&&null!==(e=s.split("@")[1])&&void 0!==e&&e.includes(".")){f(!0),a(null);try{const e=await te.checkDomainSSO(s);p(e),x(!0),m(!e.has_sso)}catch(t){x(!0),m(!0),p(null)}finally{f(!1)}}else a("Please enter a valid email address")})()},className:"space-y-6",children:[(0,re.jsxs)("div",{className:"relative",children:[(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsx)("label",{htmlFor:"email",className:"text-sm font-medium leading-5 tracking-normal text-[#09090B]",children:"Email"}),(0,re.jsxs)("div",{className:"relative",children:[(0,re.jsx)(Mv,{name:"email",type:"email",placeholder:"Enter your email address",value:v.email,onChange:e=>{N(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,re.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,re.jsx)("div",{className:"absolute -top-2 right-0",children:(0,re.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,re.jsx)(re.Fragment,{children:null!=h&&h.has_sso?(0,re.jsxs)("div",{className:"p-3 bg-slate-50 border border-slate-200 rounded-md",children:[(0,re.jsxs)("p",{className:"text-sm text-slate-800",children:["SSO is enabled for ",(0,re.jsx)("strong",{children:h.workspace_name})]}),(0,re.jsx)("p",{className:"text-xs text-slate-600 mt-1",children:"Click below to continue with your organization's login"})]}):(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsxs)("div",{className:"flex items-center justify-between",children:[(0,re.jsx)("label",{htmlFor:"password",className:"text-sm font-medium leading-5 tracking-normal text-[#09090B]",children:"Password"}),(0,re.jsx)(J.Link,{to:"/forgot-password",className:"text-sm font-medium leading-5 tracking-normal text-[#71717A]",children:"Forgot password?"})]}),(0,re.jsx)(Mv,{name:"password",type:"password",placeholder:"Enter your password",value:v.password,onChange:N,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(t&&!l&&u?"border border-[#DC2626]":"border border-[#E4E4E7]")})]})}),t&&!l&&(0,re.jsx)("p",{className:"text-[14px] leading-[20px] tracking-[0%] text-[#DC2626] font-normal",children:t}),g&&(0,re.jsxs)("div",{className:"flex items-center justify-center gap-2 text-sm text-gray-500",children:[(0,re.jsx)("div",{className:"animate-spin rounded-full h-4 w-4 border-b-2 border-gray-500"}),"Checking authentication method..."]}),(0,re.jsxs)("div",{className:"space-y-4",children:[(0,re.jsx)(Rv,{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,re.jsx)("div",{className:"p-4 text-sm text-green-600 bg-green-50 border border-green-200 rounded-md",children:n}),(0,re.jsxs)("p",{className:"text-center text-sm text-[#71717A]",children:["Don't have an account?"," ",(0,re.jsx)(J.Link,{to:"/register",className:"font-medium text-black underline",children:"Sign up"})]})]})]})]})},Yv=e=>{let{name:s,value:t,onChange:a,placeholder:n="Enter your email address",required:r=!1,disabled:l=!1,label:i="Email",onValidationChange:o}=e;const[c,d]=H.useState(null);return(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsx)("label",{htmlFor:s,className:"text-sm font-medium leading-5 tracking-normal text-[#09090B]",children:i}),(0,re.jsx)(Mv,{name:s,type:"email",placeholder:n,value:t,onChange:e=>{const{value:s}=e.target;c&&(d(null),null==o||o(!0)),a(e)},onBlur:e=>{const{value:s}=e.target;s&&!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(s)?(d("That's not a valid email. Try a different email address."),null==o||o(!1)):s&&(d(null),null==o||o(!0))},required:r,disabled:l,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,re.jsx)("p",{className:"text-[14px] leading-[20px] tracking-[0%] text-[#DC2626] font-normal mt-1",children:c})]})},Hv=(0,H.forwardRef)((e,s)=>{let{siteKey:t,onSuccess:a,onError:n,onExpired:r,theme:l="light",size:i="normal",className:o=""}=e;const c=(0,H.useRef)(null),[d,m]=(0,H.useState)(null),[u,x]=(0,H.useState)(!1);(0,H.useEffect)(()=>{const e=()=>{window.turnstile?x(!0):setTimeout(e,100)};e()},[]),(0,H.useEffect)(()=>{if(u&&c.current&&!d)try{const e=window.turnstile.render(c.current,{sitekey:t,theme:l,size:i,callback:e=>{null==a||a(e)},"error-callback":e=>{null==n||n(e)},"expired-callback":()=>{null==r||r()}});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,t,l,i,d,a,n,r]);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,H.useImperativeHandle)(s,()=>({reset:h,getResponse:p})),(0,re.jsx)("div",{className:"turnstile-container ".concat(o),children:(0,re.jsx)("div",{ref:c})})});Hv.displayName="Turnstile";const Gv=Hv,$v="0x4AAAAAABkwg1ZNNlkay6SI",Jv="light",Zv="normal",Kv=!0,Xv=e=>e&&e.length>0,Qv=e=>{let{onSuccess:s,onError:t,onExpired:a,isVerified:n=!1,className:r=""}=e;return Kv?n?null:(0,re.jsx)("div",{className:"space-y-2 ".concat(r),children:(0,re.jsx)(Gv,{siteKey:$v,theme:Jv,size:Zv,onSuccess:s,onError:t,onExpired:a,className:"flex justify-center"})}):null};class eb extends X.H{getBaseURL(){return"/referrals"}async generateReferralCode(){try{return(await this.axios.post("/generate-code")).referral_code}catch(t){var e,s;throw new Error((null===(e=t.response)||void 0===e||null===(s=e.data)||void 0===s?void 0:s.detail)||"Failed to generate referral code")}}async validateReferralCode(e){try{return await this.axios.post("/validate",{referral_code:e})}catch(a){var s,t;throw new Error((null===(s=a.response)||void 0===s||null===(t=s.data)||void 0===t?void 0:t.detail)||"Failed to validate referral code")}}async getReferralStats(){try{return await this.axios.get("/stats")}catch(t){var e,s;throw new Error((null===(e=t.response)||void 0===e||null===(s=e.data)||void 0===s?void 0:s.detail)||"Failed to fetch referral statistics")}}}const sb=new eb,tb=e=>{const s=e.length>=8,t=/[a-z]/.test(e)&&/[A-Z]/.test(e),a=/[#$&@!%*?&]/.test(e);let n=0;s&&n++,t&&n++,a&&n++;let r="Weak password";return n>=3?r="Strong password":n>=2&&(r="Average password"),{score:n,label:r,hasMinLength:s,hasUpperLower:t,hasSymbol:a}},ab=e=>e>=3?"bg-green-500":e>=2?"bg-yellow-500":"bg-orange-500",nb=e=>{const s=[];for(let t=0;t<3;t++)s.push((0,re.jsx)("div",{className:"h-1 flex-1 rounded-full ".concat(t{let{password:s,showTooltip:t,onMouseEnter:a,onMouseLeave:n}=e;const r=tb(s);return t&&s?(0,re.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,re.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,re.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,re.jsxs)("div",{className:"space-y-3",children:[(0,re.jsxs)("div",{children:[(0,re.jsx)("div",{className:"flex justify-between items-center mb-2",children:(0,re.jsx)("span",{className:"text-sm font-medium text-[#09090B]",children:r.label})}),(0,re.jsx)("div",{className:"flex space-x-1",children:nb(r.score)})]}),(0,re.jsxs)("div",{children:[(0,re.jsx)("p",{className:"text-sm text-[#71717A] mb-2",children:"Password must include:"}),(0,re.jsxs)("ul",{className:"space-y-1 text-sm",children:[(0,re.jsxs)("li",{className:"flex items-center gap-2",children:[(0,re.jsx)("div",{className:"w-[18px] h-[18px] rounded-full border-2 flex items-center justify-center border-[#71717A]",children:r.hasMinLength&&(0,re.jsx)("svg",{width:"10",height:"8",viewBox:"0 0 10 8",fill:"none",children:(0,re.jsx)("path",{d:"M9 1L3.5 6.5L1 4",stroke:"#71717A",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),(0,re.jsx)("span",{className:"text-[#09090B]",children:"At least 8 characters"})]}),(0,re.jsxs)("li",{className:"flex items-center gap-2",children:[(0,re.jsx)("div",{className:"w-[18px] h-[18px] rounded-full border-2 flex items-center justify-center border-[#71717A]",children:r.hasUpperLower&&(0,re.jsx)("svg",{width:"10",height:"8",viewBox:"0 0 10 8",fill:"none",children:(0,re.jsx)("path",{d:"M9 1L3.5 6.5L1 4",stroke:"#71717A",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),(0,re.jsx)("span",{className:"text-[#09090B]",children:"Upper & lower case letters"})]}),(0,re.jsxs)("li",{className:"flex items-center gap-2",children:[(0,re.jsx)("div",{className:"w-[18px] h-[18px] rounded-full border-2 flex items-center justify-center border-[#71717A]",children:r.hasSymbol&&(0,re.jsx)("svg",{width:"10",height:"8",viewBox:"0 0 10 8",fill:"none",children:(0,re.jsx)("path",{d:"M9 1L3.5 6.5L1 4",stroke:"#71717A",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),(0,re.jsx)("span",{className:"text-[#09090B]",children:"A symbol (#$&)"})]})]})]})]})]}):null},lb=e=>{let{password:s,showTooltip:t}=e;const a=tb(s);return t&&s?(0,re.jsxs)("div",{className:"w-full bg-[#F8F9FA] border border-[#E4E4E7] rounded-xl p-4 space-y-3",children:[(0,re.jsx)("p",{className:"text-sm font-medium text-[#09090B] mb-3",children:"Password must include:"}),(0,re.jsxs)("ul",{className:"space-y-3",children:[(0,re.jsxs)("li",{className:"flex items-center gap-3",children:[(0,re.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,re.jsx)("svg",{width:"12",height:"10",viewBox:"0 0 12 10",fill:"none",children:(0,re.jsx)("path",{d:"M10 2L4.5 7.5L2 5",stroke:"white",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}),(0,re.jsx)("span",{className:"text-sm text-[#09090B]",children:"At least 8 characters"})]}),(0,re.jsxs)("li",{className:"flex items-center gap-3",children:[(0,re.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,re.jsx)("svg",{width:"12",height:"10",viewBox:"0 0 12 10",fill:"none",children:(0,re.jsx)("path",{d:"M10 2L4.5 7.5L2 5",stroke:"white",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}),(0,re.jsx)("span",{className:"text-sm text-[#09090B]",children:"Upper & lower case letters"})]}),(0,re.jsxs)("li",{className:"flex items-center gap-3",children:[(0,re.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,re.jsx)("svg",{width:"12",height:"10",viewBox:"0 0 12 10",fill:"none",children:(0,re.jsx)("path",{d:"M10 2L4.5 7.5L2 5",stroke:"white",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}),(0,re.jsx)("span",{className:"text-sm text-[#09090B]",children:"At least one symbol (#$&)"})]})]})]}):null},ib=e=>{let{email:s,onSuccess:t,successRedirectPath:a="/login",isFromLogin:n=!1}=e;const[r,l]=(0,H.useState)(!1),[i,o]=(0,H.useState)(null),[c,d]=(0,H.useState)(["","","","","",""]),[m,u]=(0,H.useState)([!1,!1,!1,!1,!1,!1]),[x,h]=(0,H.useState)(null),p=(0,Z.Zp)(),g=(0,H.useRef)([]);(0,H.useEffect)(()=>{var e;null===(e=g.current[0])||void 0===e||e.focus()},[]);const f=e=>{e.preventDefault();const s=e.clipboardData.getData("text").slice(0,6),t=[...c];for(let l=0;l!e);var n,r;-1!==a?null===(n=g.current[a])||void 0===n||n.focus():null===(r=g.current[5])||void 0===r||r.focus()};return(0,re.jsxs)(Wv,{title:"Verify your email",subtitle:"We sent a verification code to ".concat(s),showImageColumn:!0,children:[i&&(0,re.jsx)("div",{className:"p-4 text-sm text-red-600 bg-red-50 border border-red-200 rounded-md",children:i}),(0,re.jsxs)("form",{onSubmit:async e=>{e.preventDefault(),l(!0),o(null),h(null);const r=c.map(e=>!e);if(r.some(e=>e))return u(r),h("Please fill out all fields."),void l(!1);const d=c.join("");try{const e=await te.verifyOtp(s,d);e.success?(n||(ko("registration_completed",{email:(0,So.sha256)(s),user_id:e.id,registration_method:"email&password"}),Ae(e.id)),t?t():p(a,{state:{message:n?"Email verified successfully! You can now log in.":"Email verified successfully! Please log in to continue.",email:s}})):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 s=(null===(g=i.response.data)||void 0===g?void 0:g.detail)||"Invalid verification code";o(s)}else o("Verification failed. Please try again.")}finally{l(!1)}},className:"space-y-6",children:[(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsx)("label",{htmlFor:"otpCode",className:"text-sm font-medium leading-5 tracking-normal text-[#09090B]",children:"Verification Code"}),(0,re.jsx)("div",{className:"flex gap-2",children:c.map((e,s)=>(0,re.jsx)(Mv,{name:"otpCode".concat(s),type:"text",inputMode:"numeric",pattern:"\\d{1}",value:e,onChange:e=>((e,s)=>{if(s.length>1)return;const t=[...c];if(t[e]=s,d(t),s){const s=[...m];s[e]=!1,u(s),t.every(e=>e)&&h(null)}var a;s&&e<5&&(null===(a=g.current[e+1])||void 0===a||a.focus())})(s,e.target.value),onKeyDown:e=>((e,s)=>{var t;"Backspace"===s.key&&!c[e]&&e>0&&(null===(t=g.current[e-1])||void 0===t||t.focus())})(s,e),onPaste:0===s?f:void 0,disabled:r,className:"w-11 h-11 text-center text-lg font-semibold bg-white text-[#09090B] rounded-md shadow-xs ".concat(m[s]?"border border-[#DC2626]":"border border-[#E4E4E7] focus:border-slate-400 focus:ring-slate-400"),maxLength:1,ref:e=>g.current[s]=e},s))}),x&&(0,re.jsx)("p",{className:"text-[14px] leading-[20px] tracking-[0%] text-[#DC2626] font-normal mt-1",children:x}),(0,re.jsx)("p",{className:"text-xs text-slate-500 mt-3",children:"Enter the verification code sent to your email"})]}),(0,re.jsxs)("div",{className:"space-y-4",children:[(0,re.jsx)(Rv,{type:"submit",className:"w-full h-[40px] bg-black text-[#FAFAFA] border border-[#E4E4E7] rounded-md shadow-xs px-4 py-2",disabled:r,children:r?"Verifying...":"Verify Email"}),(0,re.jsxs)("p",{className:"text-sm text-slate-600",children:["Didn't receive the code?"," ",(0,re.jsx)("button",{type:"button",onClick:async()=>{try{var e;l(!0),o(null),await te.resendOtp(s),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{l(!1)}},disabled:r,className:"font-medium text-black hover:text-slate-700 underline",children:"Resend email"})]})]})]})]})};var ob=t(29221);const cb=()=>{const[e]=(0,J.useSearchParams)(),s=e.get("ref"),[t,a]=(0,H.useState)(!1),[n,r]=(0,H.useState)(null),[l,i]=(0,H.useState)({isValidating:!1,isValid:null,referrerInfo:null,validationMessage:null}),[o,c]=(0,H.useState)(!1),[d,m]=(0,H.useState)(""),[u,x]=(0,H.useState)(!1),[h,p]=(0,H.useState)(null),[g,f]=(0,H.useState)(!1),[v,b]=(0,H.useState)({score:0,label:"Weak password",hasMinLength:!1,hasUpperLower:!1,hasSymbol:!1}),[j,y]=(0,H.useState)({email:"",password:""}),{user:N,isAuthenticated:w}=oe();(0,H.useEffect)(()=>{const e="sign_up",s={user_id:w&&null!=N&&N.id?N.id:null,app_id:null,conversation_id:null};qe(s,{page_name:e}),Ie("Page View",{page_name:e,page_url:window.location.pathname,user_id:s.user_id})},[]);const{turnstileToken:_,isVerified:k,handleTurnstileSuccess:A,handleTurnstileError:S,handleTurnstileExpired:C,validateTurnstileToken:E}=(e=>{const[s,t]=(0,H.useState)(null),a=Xv(s),n=(0,H.useCallback)(s=>{t(s),e&&e("")},[e]),r=(0,H.useCallback)(s=>{t(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."}})(s))},[e]),l=(0,H.useCallback)(()=>{t(null)},[]),i=(0,H.useCallback)(()=>!(Kv&&!Xv(s)&&(e&&e("Please complete the security verification"),1)),[s,e]),o=(0,H.useCallback)(s=>{e&&e(s)},[e]),c=(0,H.useCallback)(()=>{e&&e("")},[e]);return{turnstileToken:s,isVerified:a,handleTurnstileSuccess:n,handleTurnstileError:r,handleTurnstileExpired:l,validateTurnstileToken:i,setError:o,clearError:c}})(r);(0,H.useEffect)(()=>()=>{h&&clearTimeout(h)},[h]),(0,H.useEffect)(()=>{s&&I()},[s]);const I=async()=>{if(s){i(e=>(0,K.A)((0,K.A)({},e),{},{isValidating:!0}));try{const e=await sb.validateReferralCode(s);i({isValidating:!1,isValid:e.is_valid,referrerInfo:e.referrer,validationMessage:e.message})}catch(n){i({isValidating:!1,isValid:!1,referrerInfo:null,validationMessage:"Failed to validate referral code"})}}},T=e=>{const{name:s,value:t}=e.target;y(e=>(0,K.A)((0,K.A)({},e),{},{[s]:t})),"password"===s&&b(tb(t)),n&&r(null)};return o?(0,re.jsx)(ib,{email:d,isFromLogin:!1}):(0,re.jsxs)(Wv,{title:"Create your account",showImageColumn:!0,footerContent:(0,re.jsxs)("p",{className:"text-center text-xs text-slate-500",children:['By clicking "Sign Up", you agree to our'," ",(0,re.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,re.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:[s&&(0,re.jsx)("div",{className:"mb-6 p-4 rounded-lg text-center border ".concat((l.isValidating||l.isValid,"bg-gray-50 border-gray-200")),children:l.isValidating?(0,re.jsxs)("div",{className:"flex items-center justify-center",children:[(0,re.jsx)("div",{className:"animate-spin rounded-full h-4 w-4 border-b-2 border-gray-600 mr-2"}),(0,re.jsx)("span",{className:"text-sm font-medium text-gray-800",children:"Validating referral code..."})]}):!1===l.isValid?(0,re.jsxs)("div",{children:[(0,re.jsxs)("div",{className:"flex items-center justify-center mb-2",children:[(0,re.jsx)(ob.A,{className:"h-5 w-5 text-gray-600 mr-2"}),(0,re.jsx)("span",{className:"text-sm font-medium text-gray-800",children:"Invalid Referral Code"})]}),(0,re.jsx)("p",{className:"text-sm text-gray-700",children:l.validationMessage})]}):l.isValid&&l.referrerInfo?(0,re.jsxs)("div",{children:[(0,re.jsxs)("div",{className:"flex items-center justify-center mb-2",children:[(0,re.jsx)("svg",{className:"h-5 w-5 text-gray-600 mr-2",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,re.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,re.jsx)("span",{className:"text-sm font-medium text-gray-800",children:"You've been invited!"})]}),(0,re.jsxs)("p",{className:"text-sm text-gray-700 mb-1",children:[(0,re.jsx)("strong",{children:l.referrerInfo.first_name||l.referrerInfo.email})," invited you to join Base44"]}),(0,re.jsx)("p",{className:"text-sm text-gray-600",children:"Sign up to get 10 free credits!"})]}):(0,re.jsxs)("div",{children:[(0,re.jsx)("span",{className:"text-sm font-medium text-gray-800",children:"You've been invited!"}),(0,re.jsx)("p",{className:"text-sm text-gray-700",children:"Let's build something amazing together!"}),(0,re.jsx)("p",{className:"text-sm text-gray-600",children:"Sign up to get 10 free credits!"})]})}),(0,re.jsx)(Bv,{buttonText:{default:"Sign up with Google",loading:"Signing up..."}}),(0,re.jsxs)("div",{className:"relative",children:[(0,re.jsx)("div",{className:"absolute inset-0 flex items-center",children:(0,re.jsx)(pt,{})}),(0,re.jsx)("div",{className:"relative flex justify-center text-xs uppercase",children:(0,re.jsx)("span",{className:"bg-white px-2 text-slate-500",children:"Or"})})]}),n&&(0,re.jsx)("div",{className:"p-4 text-sm text-red-600 bg-red-50 rounded-md",children:n}),(0,re.jsxs)("form",{onSubmit:async e=>{if(e.preventDefault(),a(!0),r(null),E())try{const e=s&&l.isValid?s:null;(await te.register(j.email,j.password,_,e)).id?(m(j.email),c(!0),r(null)):r("Registration failed. Please try again.")}catch(n){var t;if(400===(null===(t=n.response)||void 0===t?void 0:t.status)){var i;const s=(null===(i=n.response.data)||void 0===i?void 0:i.detail)||"Registration failed";r(s)}else r("Registration failed. Please try again.")}finally{a(!1)}else a(!1)},className:"space-y-6",children:[(0,re.jsx)(Yv,{name:"email",value:j.email,onChange:e=>{T(e)},placeholder:"Enter your email address",required:!0,disabled:t,label:"Email"}),(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsx)("label",{htmlFor:"password",className:"text-sm font-medium leading-5 tracking-normal text-[#09090B]",children:"Password"}),(0,re.jsxs)("div",{className:"relative",children:[(0,re.jsx)(Mv,{name:"password",type:g?"text":"password",placeholder:"Enter your password",value:j.password,onChange:T,onFocus:()=>{h&&(clearTimeout(h),p(null)),x(!0)},onBlur:()=>{const e=setTimeout(()=>{x(!1)},150);p(e)},required:!0,disabled:t,className:"bg-white text-[#09090B] h-9 px-3 py-1 pr-20 border border-[#E4E4E7] rounded-md shadow-xs",minLength:8}),j.password&&(0,re.jsx)("div",{className:"absolute right-9 top-1/2 -translate-y-1/2 h-[18px] flex items-center",children:(0,re.jsx)("span",{className:"text-xs text-[#71717A] font-normal leading-none tracking-normal",children:v.label.replace(" password","")})}),j.password&&(0,re.jsx)("button",{type:"button",onClick:()=>f(!g),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:g?(0,re.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,re.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,re.jsx)("line",{x1:"1",y1:"1",x2:"23",y2:"23"})]}):(0,re.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,re.jsx)("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"}),(0,re.jsx)("circle",{cx:"12",cy:"12",r:"3"})]})}),(0,re.jsx)("div",{className:"hidden lg:block",children:(0,re.jsx)(rb,{password:j.password,showTooltip:u,onMouseEnter:()=>{h&&(clearTimeout(h),p(null))},onMouseLeave:()=>{x(!1)}})})]})]}),(0,re.jsx)("div",{className:"lg:hidden",children:(0,re.jsx)(lb,{password:j.password,showTooltip:!!j.password})}),(0,re.jsxs)("div",{className:"space-y-4",children:[(0,re.jsx)(Rv,{type:"submit",className:"w-full h-[40px] bg-black text-[#FAFAFA] border border-[#E4E4E7] rounded-md shadow-xs px-4 py-2",disabled:t||v.score<3,children:t?"Creating account...":"Sign Up"}),(0,re.jsx)(Qv,{onSuccess:A,onError:S,onExpired:C,isVerified:k,className:"flex justify-center"}),(0,re.jsxs)("p",{className:"text-center text-sm text-[#71717A]",children:["Already have a Base44 account?"," ",(0,re.jsx)(J.Link,{to:"/login",className:"font-medium text-black underline",children:"Log in"})]})]})]})]})},db=()=>{var e,s;const t=(0,Z.zy)(),a=(0,Z.g)(),n=(null===(e=t.state)||void 0===e?void 0:e.email)||a.email||new URLSearchParams(t.search).get("email"),r=(null===(s=t.state)||void 0===s?void 0:s.isFromLogin)||!1;return n?(0,re.jsx)(ib,{email:n,isFromLogin:r,successRedirectPath:"/login"}):(0,re.jsx)(Z.C5,{to:"/login",replace:!0})},mb=()=>{const[e,s]=(0,H.useState)(!1),[t,a]=(0,H.useState)(null),[n,r]=(0,H.useState)(""),l=(0,Z.Zp)();return(0,re.jsxs)(Wv,{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:[t&&(0,re.jsx)("div",{className:"p-4 text-sm text-red-600 bg-red-50 border border-red-200 rounded-md",children:t}),(0,re.jsxs)("form",{onSubmit:async e=>{e.preventDefault(),s(!0),a(null);try{await te.resetPasswordRequest(n,null);l("/check-email",{state:{email:n}})}catch(t){var r;if(400===(null===(r=t.response)||void 0===r?void 0:r.status)){var i;const s=(null===(i=t.response.data)||void 0===i?void 0:i.detail)||"Invalid email address";a(s)}else a("Failed to send reset link. Please try again.")}finally{s(!1)}},className:"space-y-6",children:[(0,re.jsx)(Yv,{name:"email",value:n,onChange:e=>{(e=>{r(e.target.value),t&&a(null)})(e)},placeholder:"e.g., name@email.com",required:!0,disabled:e,label:"Login email"}),(0,re.jsx)("div",{className:"space-y-4",children:(0,re.jsx)(Rv,{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"})})]})]})},ub=()=>{const[e,s]=(0,H.useState)(!1),[t,a]=(0,H.useState)(null),[n,r]=(0,H.useState)(""),l=(0,Z.zy)(),i=(0,Z.Zp)();(0,H.useEffect)(()=>{const e=l.state;null!=e&&e.email&&r(e.email)},[l]);return(0,re.jsxs)(Wv,{title:"Check your email",subtitle:(0,re.jsxs)(re.Fragment,{children:["We've sent password reset instructions to"," ",(0,re.jsx)("span",{className:"font-medium text-[#09090B]",children:n}),"."]}),showImageColumn:!0,backLink:{href:"/forgot-password",text:"Back to Reset password"},children:[(0,re.jsx)("div",{className:"py-3 px-4 bg-[#FAFAFA] border border-[#E4E4E7] rounded-lg gap-x-3",children:(0,re.jsxs)("p",{className:"text-sm text-[#71717A] text-center leading-relaxed",children:[(0,re.jsx)("span",{className:"block",children:"Please check your email for the password reset link."}),(0,re.jsx)("span",{className:"block",children:"It may take a few minutes to arrive."})]})}),t&&(0,re.jsx)("div",{className:"p-4 text-sm text-red-600 bg-red-50 border border-red-200 rounded-md",children:t}),(0,re.jsxs)("div",{className:"space-y-4",children:[(0,re.jsx)(Rv,{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,re.jsx)("div",{className:"text-center",children:(0,re.jsxs)("span",{className:"text-sm text-[#71717A]",children:["Didn't get the email?"," ",(0,re.jsx)("button",{onClick:async()=>{if(n){s(!0),a(null);try{await te.resetPasswordRequest(n),a("New password reset email sent. Please check your inbox.")}catch(t){var e;if(400===(null===(e=t.response)||void 0===e?void 0:e.status)){var r;const e=(null===(r=t.response.data)||void 0===r?void 0:r.detail)||"Failed to send email";a(e)}else a("Failed to resend email. Please try again.")}finally{s(!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"})]})})]})]})},xb=()=>{const[e,s]=(0,H.useState)(!1),[t,a]=(0,H.useState)(null),[n,r]=(0,H.useState)(null),[l,i]=(0,H.useState)(""),[o,c]=(0,H.useState)(""),[d,m]=(0,H.useState)(!1),[u,x]=(0,H.useState)(!1),[h,p]=(0,H.useState)(!1),[g,f]=(0,H.useState)(null),[v,b]=(0,H.useState)({score:0,label:"Weak password",hasMinLength:!1,hasUpperLower:!1,hasSymbol:!1}),[j]=(0,J.useSearchParams)(),y=(0,Z.Zp)(),N=j.get("token");H.useEffect(()=>{N||y("/forgot-password")},[N,y]),(0,H.useEffect)(()=>()=>{g&&clearTimeout(g)},[g]);return(0,re.jsxs)(Wv,{title:"Set new password",subtitle:"Enter your new password for Base44",showImageColumn:!1,children:[t&&(0,re.jsx)("div",{className:"p-4 text-sm text-red-600 bg-red-50 border border-red-200 rounded-md",children:t}),(0,re.jsxs)("form",{onSubmit:async e=>{if(e.preventDefault(),N)if(l===o)if(v.score<3)a("Please create a strong password that meets all requirements.");else{s(!0),a(null),r(null);try{const e=await te.resetPassword(N,l,null);e&&e.id?(r("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(t){var n;if(400===(null===(n=t.response)||void 0===n?void 0:n.status)){var i;const s=(null===(i=t.response.data)||void 0===i?void 0:i.detail)||"Invalid or expired reset token";a(s)}else a("Failed to reset password. Please try again.")}finally{s(!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,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsx)("label",{htmlFor:"newPassword",className:"text-sm font-medium leading-5 tracking-normal text-[#09090B]",children:"New password"}),(0,re.jsxs)("div",{className:"relative",children:[(0,re.jsx)(Mv,{name:"newPassword",type:d?"text":"password",placeholder:"Enter your new password",value:l,onChange:e=>{const s=e.target.value;i(s),b(tb(s)),t&&a(null),n&&r(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}),l&&(0,re.jsx)("div",{className:"absolute right-9 top-1/2 -translate-y-1/2 h-[18px] flex items-center",children:(0,re.jsx)("span",{className:"text-xs text-[#71717A] font-normal leading-none tracking-normal",children:v.label.replace(" password","")})}),l&&(0,re.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,re.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,re.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,re.jsx)("line",{x1:"1",y1:"1",x2:"23",y2:"23"})]}):(0,re.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,re.jsx)("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"}),(0,re.jsx)("circle",{cx:"12",cy:"12",r:"3"})]})}),(0,re.jsx)("div",{className:"hidden lg:block",children:(0,re.jsx)(rb,{password:l,showTooltip:h,onMouseEnter:()=>{g&&(clearTimeout(g),f(null))},onMouseLeave:()=>{p(!1)}})})]})]}),(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsx)("label",{htmlFor:"confirmPassword",className:"text-sm font-medium leading-5 tracking-normal text-[#09090B]",children:"Confirm new password"}),(0,re.jsxs)("div",{className:"relative",children:[(0,re.jsx)(Mv,{name:"confirmPassword",type:u?"text":"password",placeholder:"Confirm your new password",value:o,onChange:e=>{c(e.target.value),t&&a(null),n&&r(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,re.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,re.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,re.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,re.jsx)("line",{x1:"1",y1:"1",x2:"23",y2:"23"})]}):(0,re.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,re.jsx)("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"}),(0,re.jsx)("circle",{cx:"12",cy:"12",r:"3"})]})})]})]}),(0,re.jsx)("div",{className:"lg:hidden",children:(0,re.jsx)(lb,{password:l,showTooltip:!!l})}),(0,re.jsxs)("div",{className:"space-y-4",children:[(0,re.jsx)(Rv,{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,re.jsx)("div",{className:"p-4 text-sm text-green-600 bg-green-50 border border-green-200 rounded-md",children:n}),(0,re.jsx)("div",{className:"text-center",children:(0,re.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 hb(e){let{children:s}=e;return(0,re.jsx)(el.oz,{className:"base44-markdown prose",remarkPlugins:[Qr.A],children:s})}const pb=()=>{const e=(0,Z.Zp)();return(0,re.jsx)("div",{className:"flex items-center justify-center min-h-screen bg-slate-50",children:(0,re.jsxs)("div",{className:"max-w-md mx-auto text-center px-6",children:[(0,re.jsxs)("div",{className:"mb-8",children:[(0,re.jsx)("h1",{className:"text-8xl font-light text-slate-300 mb-4",children:"404"}),(0,re.jsx)("h2",{className:"text-2xl font-medium text-slate-900 mb-3",children:"Page not found"}),(0,re.jsx)("p",{className:"text-slate-600 leading-relaxed",children:"The page you're looking for doesn't exist or has been moved."})]}),(0,re.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 gb extends X.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,s){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,s){if(!e)throw new Error("Account ID is required for this operation");return this.axios.get("/".concat(e,"/connect-to-app/").concat(s))}createCheckoutSession(e,s){let t=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:s,quantity:t,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 fb=new gb;function vb(e){let{onAccountCreated:s}=e;const[t,a]=(0,H.useState)(!1),[n,r]=(0,H.useState)("express"),{toast:l}=si();return(0,re.jsxs)(it,{children:[(0,re.jsxs)(ot,{children:[(0,re.jsx)(ct,{children:"Get Started with Stripe"}),(0,re.jsx)(dt,{children:"Create a Stripe account to start accepting payments in your apps"})]}),(0,re.jsxs)(mt,{children:[(0,re.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,re.jsxs)("div",{className:"mt-6",children:[(0,re.jsx)("h3",{className:"text-lg font-medium mb-4",children:"Choose Account Type"}),(0,re.jsxs)(St,{value:n,onValueChange:r,className:"space-y-4",children:[(0,re.jsxs)("div",{className:"flex items-start space-x-2 rounded-md border p-4",children:[(0,re.jsx)(Ct,{value:"express",id:"express",className:"mt-1"}),(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsxs)("div",{className:"flex space-x-2",children:[(0,re.jsx)(Nt,{htmlFor:"express",className:"font-medium",children:"Express Account"}),(0,re.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,re.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,re.jsxs)("div",{className:"flex items-start space-x-2 rounded-md border p-4",children:[(0,re.jsx)(Ct,{value:"standard",id:"standard",className:"mt-1"}),(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsxs)("div",{className:"flex space-x-2",children:[(0,re.jsx)(Nt,{htmlFor:"standard",className:"font-medium",children:"Standard Account"}),(0,re.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,re.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,re.jsx)(ut,{className:"flex justify-end",children:(0,re.jsx)(Hs,{onClick:async()=>{a(!0);try{const e=await fb.getOrCreateAccount(n);s(e),l({title:"Success",description:"Stripe account created successfully",variant:"success"})}catch(e){l({variant:"destructive",title:"Error",description:"Failed to create Stripe account"})}finally{a(!1)}},disabled:t,children:t?(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(Ze.A,{className:"mr-2 h-4 w-4 animate-spin"}),"Creating Account..."]}):(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(jl.A,{className:"mr-2 h-4 w-4"}),"Create Stripe Account"]})})})]})}function bb(e){var s;let{account:t,onAccountVerified:a}=e;const[n,r]=(0,H.useState)(!0),[l,i]=(0,H.useState)(null),[o,c]=(0,H.useState)(!1),{toast:d}=si();(0,H.useEffect)(()=>{t&&m()},[t]);const m=async()=>{r(!0);try{const e=await fb.checkAccountStatus(t.id);i(e),e.is_complete&&a()}catch(e){d({variant:"destructive",title:"Error",description:"Failed to check Stripe account status"})}finally{r(!1)}};if(n)return(0,re.jsxs)(it,{children:[(0,re.jsxs)(ot,{children:[(0,re.jsx)(ct,{children:"Checking Your Stripe Account"}),(0,re.jsx)(dt,{children:"Verifying your Stripe account setup..."})]}),(0,re.jsx)(mt,{className:"flex justify-center items-center p-8",children:(0,re.jsx)(Ze.A,{className:"h-8 w-8 animate-spin text-muted-foreground"})})]});if(null!=l&&l.is_complete)return(0,re.jsxs)(it,{children:[(0,re.jsxs)(ot,{children:[(0,re.jsx)(ct,{children:"Stripe Account Setup Complete"}),(0,re.jsx)(dt,{children:"Your Stripe account is fully set up and ready to use"})]}),(0,re.jsx)(mt,{children:(0,re.jsxs)(us,{className:"bg-green-50 border-green-200",children:[(0,re.jsx)(Px.A,{className:"h-4 w-4 text-green-600"}),(0,re.jsx)(xs,{className:"text-green-600",children:"Ready to accept payments"}),(0,re.jsx)(hs,{children:"Your Stripe account is ready to process payments and receive payouts."})]})}),(0,re.jsx)(ut,{className:"flex justify-end",children:(0,re.jsx)(Hs,{onClick:a,children:"Continue to Next Step"})})]});const u=(null==l||null===(s=l.requirements)||void 0===s?void 0:s.currently_due)||[];return(0,re.jsxs)(it,{children:[(0,re.jsxs)(ot,{children:[(0,re.jsx)(ct,{children:"Complete Your Stripe Account Setup"}),(0,re.jsx)(dt,{children:"Your Stripe account needs additional information to start accepting payments"})]}),(0,re.jsxs)(mt,{className:"space-y-4",children:[(0,re.jsxs)(us,{variant:"warning",className:"bg-yellow-50 border-yellow-200",children:[(0,re.jsx)(Xe.A,{className:"h-4 w-4 text-yellow-600"}),(0,re.jsx)(xs,{className:"text-yellow-600",children:"Account setup incomplete"}),(0,re.jsx)(hs,{children:"Please continue the Stripe onboarding process to complete your account setup."})]}),(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsx)("div",{className:"flex items-center gap-2",children:(0,re.jsxs)("div",{className:null!=l&&l.details_submitted?"text-green-600":"text-muted-foreground",children:[null!=l&&l.details_submitted?(0,re.jsx)(Px.A,{className:"inline h-4 w-4 mr-1"}):(0,re.jsx)(Dx.A,{className:"inline h-4 w-4 mr-1"}),"Account details provided"]})}),(0,re.jsx)("div",{className:"flex items-center gap-2",children:(0,re.jsxs)("div",{className:null!=l&&l.charges_enabled?"text-green-600":"text-muted-foreground",children:[null!=l&&l.charges_enabled?(0,re.jsx)(Px.A,{className:"inline h-4 w-4 mr-1"}):(0,re.jsx)(Dx.A,{className:"inline h-4 w-4 mr-1"}),"Charges enabled"]})}),(0,re.jsx)("div",{className:"flex items-center gap-2",children:(0,re.jsxs)("div",{className:null!=l&&l.payouts_enabled?"text-green-600":"text-muted-foreground",children:[null!=l&&l.payouts_enabled?(0,re.jsx)(Px.A,{className:"inline h-4 w-4 mr-1"}):(0,re.jsx)(Dx.A,{className:"inline h-4 w-4 mr-1"}),"Payouts enabled"]})})]}),u.length>0&&(0,re.jsxs)("div",{className:"mt-4",children:[(0,re.jsx)("h4",{className:"text-sm font-medium mb-2",children:"Required Information:"}),(0,re.jsx)("ul",{className:"text-sm text-muted-foreground space-y-1 list-disc pl-5",children:u.map((e,s)=>(0,re.jsx)("li",{children:e.split(".").join(" ").replace(/_/g," ")},s))})]})]}),(0,re.jsxs)(ut,{className:"flex justify-between items-center",children:[(0,re.jsx)(Hs,{variant:"outline",onClick:m,children:"Refresh Status"}),(0,re.jsx)(Hs,{onClick:async()=>{c(!0);try{const e="".concat(window.location.origin,"/integrations/stripe"),s=await fb.createAccountLink(t.id,e);s.account_link_url&&(window.location.href=s.account_link_url)}catch(e){d({variant:"destructive",title:"Error",description:"Failed to create Stripe account link"}),c(!1)}},disabled:o,children:o?(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(Ze.A,{className:"mr-2 h-4 w-4 animate-spin"}),"Preparing Onboarding..."]}):(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(jl.A,{className:"mr-2 h-4 w-4"}),"Complete Stripe Onboarding"]})})]})]})}var jb=t(37656);function yb(e){let{integrationInstance:s}=e;const[t,a]=(0,H.useState)(null),[n,r]=(0,H.useState)(!1),{toast:l}=si(),i=e=>{if(!e||!e.unit_amount)return"N/A";const s=e.unit_amount/100;return new Intl.NumberFormat("en-US",{style:"currency",currency:e.currency||"USD"}).format(s)},o=async()=>{try{r(!0),await fb.refreshProductCatalog(s.id),l({title:"Success",description:"Product catalog refreshed successfully from Stripe",variant:"success"})}catch(e){l({variant:"destructive",title:"Error",description:"Failed to refresh product catalog from Stripe"})}finally{r(!1)}};return s.product_catalog&&0!==s.product_catalog.length?(0,re.jsxs)("div",{children:[(0,re.jsxs)("div",{className:"flex justify-between items-center mb-4",children:[(0,re.jsx)("h3",{className:"text-lg font-medium",children:"Product Catalog"}),(0,re.jsx)(Hs,{variant:"outline",size:"sm",onClick:o,disabled:n,children:n?(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(Ze.A,{className:"mr-2 h-4 w-4 animate-spin"}),"Refreshing..."]}):(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(ku.A,{className:"mr-2 h-4 w-4"}),"Refresh Catalog"]})})]}),(0,re.jsx)("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:s.product_catalog.map(e=>(0,re.jsx)(it,{className:"overflow-hidden",children:(0,re.jsxs)("div",{className:"p-4",children:[(0,re.jsx)("h4",{className:"font-semibold",children:e.name}),(0,re.jsx)("p",{className:"text-sm text-muted-foreground mt-1",children:e.description||"No description"}),e.images&&e.images.length>0&&(0,re.jsx)("div",{className:"mt-2",children:(0,re.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,re.jsxs)("div",{className:"mt-3",children:[(0,re.jsx)("h5",{className:"text-sm font-medium mb-1",children:"Prices:"}),(0,re.jsx)("div",{className:"space-y-1 max-h-32 overflow-y-auto",children:e.prices.map(e=>(0,re.jsxs)("div",{className:"bg-muted/30 p-2 rounded-md text-xs",children:[(0,re.jsxs)("div",{className:"flex justify-between",children:[(0,re.jsx)("span",{className:"font-medium",children:i(e)}),(0,re.jsx)("span",{className:"text-muted-foreground",children:e.recurring?"".concat(e.recurring.interval_count," ").concat(e.recurring.interval):"One-time"})]}),(0,re.jsxs)("div",{className:"flex justify-between items-center mt-2",children:[(0,re.jsxs)("div",{className:"text-muted-foreground text-xs truncate",title:e.id,children:["ID: ",e.id.substring(0,10),"..."]}),(0,re.jsxs)(Hs,{size:"sm",variant:"secondary",className:"h-6 text-xs px-2",onClick:()=>(async e=>{try{a(e);const t=await fb.createCheckoutSession(s.id,e);t.checkout_url&&window.open(t.checkout_url,"_blank")}catch(t){}finally{a(null)}})(e.id),disabled:t===e.id,children:[t===e.id?(0,re.jsx)(Ze.A,{className:"h-3 w-3 animate-spin mr-1"}):null,"Checkout"]})]})]},e.id))})]}):(0,re.jsx)("div",{className:"mt-2 text-xs text-muted-foreground italic",children:"No prices defined for this product"}),(0,re.jsxs)("div",{className:"mt-2 text-xs text-muted-foreground",children:["ID: ",e.id]})]})},e.id))})]}):(0,re.jsxs)("div",{className:"text-center py-6 bg-muted/30 rounded-lg",children:[(0,re.jsx)("p",{className:"text-muted-foreground mb-4",children:"No products available."}),(0,re.jsx)(Hs,{variant:"outline",size:"sm",onClick:o,disabled:n,children:n?(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(Ze.A,{className:"mr-2 h-4 w-4 animate-spin"}),"Refreshing..."]}):(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(ku.A,{className:"mr-2 h-4 w-4"}),"Refresh Products from Stripe"]})}),(0,re.jsx)("p",{className:"text-xs text-muted-foreground mt-2",children:"This will fetch the latest products and prices from your Stripe account."})]})}function Nb(e){let{account:s,onContinue:t}=e;const[a,n]=(0,H.useState)(!1),{toast:r}=si();return(0,re.jsxs)("div",{className:"space-y-6",children:[(0,re.jsxs)(it,{children:[(0,re.jsxs)(ot,{children:[(0,re.jsx)(ct,{children:"Manage Your Product Catalog"}),(0,re.jsx)(dt,{children:"Set up products and prices in Stripe to offer to your customers"})]}),(0,re.jsxs)(mt,{className:"space-y-4",children:[(0,re.jsxs)(us,{children:[(0,re.jsx)(jb.A,{className:"h-4 w-4"}),(0,re.jsx)(xs,{children:"Optional Step"}),(0,re.jsx)(hs,{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,re.jsxs)("div",{className:"p-4 bg-muted/20 rounded-lg",children:[(0,re.jsx)("h3",{className:"text-sm font-medium mb-3",children:"Instructions"}),(0,re.jsxs)("ol",{className:"space-y-2 text-sm text-muted-foreground list-decimal pl-5",children:[(0,re.jsx)("li",{children:"Go to the Stripe Dashboard by clicking the button below"}),(0,re.jsx)("li",{children:'Navigate to "Products" in the sidebar'}),(0,re.jsx)("li",{children:"Create new products with appropriate pricing"}),(0,re.jsx)("li",{children:"For subscriptions, set up recurring prices with the desired interval"}),(0,re.jsx)("li",{children:"Return here and refresh your product catalog when complete"})]})]})]}),(0,re.jsxs)(ut,{className:"flex justify-between",children:[(0,re.jsxs)(Hs,{variant:"outline",onClick:()=>window.open("https://dashboard.stripe.com/account","_blank"),children:[(0,re.jsx)(jl.A,{className:"mr-2 h-4 w-4"}),"Open Stripe Dashboard"]}),(0,re.jsx)(Hs,{onClick:async()=>{n(!0);try{await fb.refreshProductCatalog(s.id),r({title:"Success",description:"Product catalog refreshed successfully",variant:"success"})}catch(e){r({variant:"destructive",title:"Error",description:"Failed to refresh product catalog"})}finally{n(!1)}},disabled:a,children:a?(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(Ze.A,{className:"mr-2 h-4 w-4 animate-spin"}),"Refreshing..."]}):(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(ku.A,{className:"mr-2 h-4 w-4"}),"Refresh Product Catalog"]})})]})]}),(0,re.jsxs)(it,{children:[(0,re.jsxs)(ot,{children:[(0,re.jsx)(ct,{children:"Current Product Catalog"}),(0,re.jsx)(dt,{children:"Products and prices available for your apps"})]}),(0,re.jsx)(mt,{children:(0,re.jsx)(yb,{integrationInstance:s})}),(0,re.jsx)(ut,{className:"flex justify-end",children:(0,re.jsx)(Hs,{onClick:t,children:"Continue to Next Step"})})]})]})}var wb=t(56150),_b=t(2999);function kb(){const e=(0,Z.Zp)();return(0,re.jsxs)(it,{children:[(0,re.jsx)(ot,{children:(0,re.jsxs)("div",{className:"flex items-start justify-between",children:[(0,re.jsxs)("div",{children:[(0,re.jsx)(ct,{children:"Stripe Integration Complete"}),(0,re.jsx)(dt,{children:"Your Stripe integration is ready to use with your apps"})]}),(0,re.jsx)("div",{className:"p-1.5 rounded-full bg-green-100",children:(0,re.jsx)(wb.A,{className:"h-5 w-5 text-green-600"})})]})}),(0,re.jsx)(mt,{children:(0,re.jsxs)(hl,{defaultValue:"navigation",children:[(0,re.jsxs)(pl,{className:"grid w-full grid-cols-2",children:[(0,re.jsx)(gl,{value:"navigation",children:"Navigation Instructions"}),(0,re.jsx)(gl,{value:"code",children:"Code Integration"})]}),(0,re.jsxs)(fl,{value:"navigation",className:"space-y-4 mt-4",children:[(0,re.jsxs)("div",{className:"p-4 bg-muted/20 rounded-lg space-y-4",children:[(0,re.jsx)("h3",{className:"text-sm font-medium",children:"How to Use Your Stripe Integration"}),(0,re.jsxs)("div",{className:"space-y-1",children:[(0,re.jsx)("h4",{className:"text-sm font-medium",children:"1. Navigate to an App"}),(0,re.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,re.jsxs)("div",{className:"space-y-1",children:[(0,re.jsx)("h4",{className:"text-sm font-medium",children:"2. Go to the Payments Tab"}),(0,re.jsx)("p",{className:"text-sm text-muted-foreground",children:'Open the app editor and click on the "Payments" tab in the sidebar.'})]}),(0,re.jsxs)("div",{className:"space-y-1",children:[(0,re.jsx)("h4",{className:"text-sm font-medium",children:"3. Connect Your Stripe Account"}),(0,re.jsx)("p",{className:"text-sm text-muted-foreground",children:'Click "Connect Payments" to link your Stripe account to the app.'})]}),(0,re.jsxs)("div",{className:"space-y-1",children:[(0,re.jsx)("h4",{className:"text-sm font-medium",children:"4. Use the Product Catalog"}),(0,re.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,re.jsx)("div",{className:"flex justify-end",children:(0,re.jsxs)(Hs,{onClick:()=>e("/apps"),children:["Go to My Apps ",(0,re.jsx)(ln.A,{className:"ml-2 h-4 w-4"})]})})]}),(0,re.jsx)(fl,{value:"code",className:"space-y-4 mt-4",children:(0,re.jsxs)("div",{className:"p-4 bg-muted/20 rounded-lg space-y-4",children:[(0,re.jsx)("h3",{className:"text-sm font-medium",children:"Code Integration"}),(0,re.jsxs)("div",{className:"space-y-1",children:[(0,re.jsx)("h4",{className:"text-sm font-medium",children:"Using the API"}),(0,re.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,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsx)("h4",{className:"text-sm font-medium",children:"Example: Create a Checkout Session"}),(0,re.jsx)("pre",{className:"p-3 bg-muted/40 rounded-md text-xs overflow-x-auto",children:(0,re.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,re.jsxs)(ut,{className:"flex justify-between",children:[(0,re.jsxs)(Hs,{variant:"outline",onClick:()=>window.open("https://stripe.com/docs","_blank"),children:[(0,re.jsx)(_b.A,{className:"mr-2 h-4 w-4"}),"Stripe Documentation"]}),(0,re.jsxs)(Hs,{variant:"outline",onClick:()=>window.open("https://dashboard.stripe.com","_blank"),children:[(0,re.jsx)(Yr.A,{className:"mr-2 h-4 w-4"}),"Stripe Dashboard"]})]})]})}var Ab=t(44153);function Sb(e){let{currentStep:s,totalSteps:t}=e;return(0,re.jsx)("div",{className:"flex items-center justify-center my-6",children:(0,re.jsx)("div",{className:"flex items-center",children:Array.from({length:t}).map((e,a)=>(0,re.jsxs)("div",{className:"flex items-center",children:[(0,re.jsxs)("div",{className:"flex flex-col items-center",children:[(0,re.jsx)("div",{className:"rounded-full flex items-center justify-center h-8 w-8 ".concat(al(!1),disabled:a,children:"Cancel"}),(0,re.jsx)(Hs,{variant:"destructive",onClick:async()=>{n(!0),o(null);try{await fb.deleteAccount(s.id),c({title:"Account Deleted",description:"Your Stripe integration has been successfully deleted.",variant:"success"}),l(!1),t&&t()}catch(i){var e,a;const t=(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(t),c({variant:"destructive",title:"Error",description:"Failed to delete Stripe account"})}finally{n(!1)}},disabled:a,children:a?(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(Ze.A,{className:"mr-2 h-4 w-4 animate-spin"}),"Deleting..."]}):"Delete Integration"})]})]})]})})]})}function Eb(){const{user:e}=oe(),[s,t]=(0,H.useState)(!0),[a,n]=(0,H.useState)(null),[r,l]=(0,H.useState)(0),[i,o]=(0,H.useState)(null),{toast:c}=si(),d=(0,Z.Zp)();(0,H.useEffect)(()=>{(async()=>{try{t(!0);const e=await fb.getAccount();e?(n(e),l(1)):l(0)}catch(i){o("Failed to load Stripe account information"),c({variant:"destructive",title:"Error",description:"Failed to load Stripe account information"})}finally{t(!1)}})()},[c]);const m=e=>{n(e),l(1)},u=()=>{l(2)},x=()=>{l(3)};if("builder"!==e.subscription_tier&&"pro"!==e.subscription_tier&&"elite"!==e.subscription_tier&&"elite_2"!==e.subscription_tier&&"elite_3"!==e.subscription_tier&&"enterprise"!==e.subscription_tier)return(0,re.jsxs)("div",{className:"p-6 max-w-4xl mx-auto",children:[(0,re.jsxs)("div",{className:"mb-6",children:[(0,re.jsx)("h2",{className:"text-3xl font-bold tracking-tight",children:"Stripe Integration"}),(0,re.jsx)("p",{className:"text-muted-foreground mt-2",children:"Set up Stripe to accept payments in your apps"})]}),(0,re.jsxs)(us,{children:[(0,re.jsx)(xs,{children:"Subscription Required"}),(0,re.jsx)(hs,{children:"Stripe integration is currently available only for Pro and Enterprise users. Please upgrade your subscription to access this feature."})]}),(0,re.jsx)("div",{className:"mt-4",children:(0,re.jsx)(Hs,{onClick:()=>d("/billing"),children:"Upgrade Subscription"})})]});return s?(0,re.jsxs)("div",{className:"p-6 max-w-4xl mx-auto",children:[(0,re.jsxs)("div",{className:"mb-6",children:[(0,re.jsx)("h2",{className:"text-3xl font-bold tracking-tight",children:"Stripe Integration"}),(0,re.jsx)("p",{className:"text-muted-foreground mt-2",children:"Set up Stripe to accept payments in your apps"})]}),(0,re.jsx)("div",{className:"flex justify-center items-center p-12",children:(0,re.jsx)(Ze.A,{className:"h-8 w-8 animate-spin text-muted-foreground"})})]}):i?(0,re.jsxs)("div",{className:"p-6 max-w-4xl mx-auto",children:[(0,re.jsxs)("div",{className:"mb-6",children:[(0,re.jsx)("h2",{className:"text-3xl font-bold tracking-tight",children:"Stripe Integration"}),(0,re.jsx)("p",{className:"text-muted-foreground mt-2",children:"Set up Stripe to accept payments in your apps"})]}),(0,re.jsx)("div",{className:"bg-amber-50 border border-amber-200 rounded-md p-4 mb-4",children:(0,re.jsxs)("div",{className:"flex items-start",children:[(0,re.jsx)(Fu.A,{className:"h-5 w-5 text-amber-500 mt-0.5 mr-3"}),(0,re.jsxs)("div",{children:[(0,re.jsx)("h3",{className:"text-sm font-medium text-amber-800",children:"Something went wrong"}),(0,re.jsxs)("p",{className:"text-sm text-amber-700 mt-1",children:[i,". Refreshing the page might help resolve this issue."]})]})]})}),(0,re.jsx)("div",{className:"mt-4",children:(0,re.jsx)(Hs,{onClick:()=>window.location.reload(),children:"Refresh Page"})})]}):(0,re.jsxs)("div",{className:"p-6 max-w-4xl mx-auto",children:[(0,re.jsxs)("div",{className:"mb-6 flex justify-between items-center",children:[(0,re.jsxs)("div",{children:[(0,re.jsx)("h2",{className:"text-3xl font-bold tracking-tight",children:"Stripe Integration"}),(0,re.jsx)("p",{className:"text-muted-foreground mt-2",children:"Set up Stripe to accept payments in your apps"})]}),r>0&&(0,re.jsxs)(Hs,{variant:"outline",onClick:()=>l(Math.max(0,r-1)),children:[(0,re.jsx)(Cc.A,{className:"mr-2 h-4 w-4"}),"Back"]})]}),(0,re.jsx)(Sb,{currentStep:r,totalSteps:4}),(()=>{switch(r){case 0:default:return(0,re.jsx)(vb,{onAccountCreated:m});case 1:return(0,re.jsx)(bb,{account:a,onAccountVerified:u});case 2:return(0,re.jsx)(Nb,{account:a,onContinue:x});case 3:return(0,re.jsx)(kb,{})}})(),a&&(0,re.jsx)("div",{className:"mt-8",children:(0,re.jsx)(Cb,{account:a,onAccountDeleted:()=>{n(null),l(0),c({title:"Account Deleted",description:"Your Stripe integration has been successfully removed.",variant:"success"})}})})]})}function Ib(){return(0,re.jsx)("div",{className:"p-9",children:(0,re.jsx)(hb,{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 Tb(e){let{onLoadMore:s,hasMore:t=!0,isLoading:a=!1,threshold:n=.1}=e;const[r,l]=(0,H.useState)(!1),i=(0,H.useRef)(null),o=(0,H.useRef)(null),c=(0,H.useCallback)(()=>{t&&!a&&s&&s()},[t,a,s]);return(0,H.useEffect)(()=>{const e=i.current;if(e)return o.current=new IntersectionObserver(e=>{const[s]=e;l(s.isIntersecting),s.isIntersecting&&t&&!a&&c()},{threshold:n,rootMargin:"50px"}),o.current.observe(e),()=>{o.current&&o.current.disconnect()}},[c,t,a,n]),{targetRef:i,isIntersecting:r,hasMore:t}}function Pb(e){let{activeTab:s,onTabChange:t}=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,re.jsxs)(re.Fragment,{children:[(0,re.jsx)("h1",{className:"text-3xl sm:text-4xl lg:text-5xl font-base44 font-medium mb-4 mt-6",children:"Integrations"}),(0,re.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,re.jsx)(gu,{value:s,onValueChange:t,className:"mb-8",children:(0,re.jsxs)(fu,{className:"h-auto w-full bg-transparent p-0 border-b border-gray-200 justify-start",children:[(0,re.jsx)(vu,{value:"catalog",className:a,children:"Integrations Catalog"}),(0,re.jsx)(vu,{value:"my-integrations",className:a,children:"My Integrations"})]})})]})}const Lb=[{value:"most-upvoted",label:"Most Popular"},{value:"newest",label:"Newest first"},{value:"oldest",label:"Oldest first"}];function Ob(e){let{searchTerm:s,onSearchChange:t,selectedCategory:a,onCategoryChange:n,sortBy:r,onSortByChange:l,privacyFilter:i,onPrivacyFilterChange:o,statusFilter:c,onStatusFilterChange:d,isAdmin:m}=e;const[u,x]=(0,H.useState)(s),h=(0,H.useCallback)(e=>setTimeout(()=>{t(e)},300),[t]);return(0,H.useEffect)(()=>{const e=h(u);return()=>clearTimeout(e)},[u,h]),(0,H.useEffect)(()=>{x(s)},[s]),(0,re.jsx)("div",{className:"mt-[42px] mb-6 font-base44",children:(0,re.jsxs)("div",{className:"flex flex-col sm:flex-row sm:items-center gap-3 w-full sm:justify-between",children:[(0,re.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,re.jsx)(vn.A,{className:"w-4 h-4 text-[#000] flex-shrink-0"}),(0,re.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,re.jsx)("div",{className:"flex items-center gap-3 justify-end sm:justify-start",children:(0,re.jsxs)(In,{value:r,onValueChange:l,children:[(0,re.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,re.jsx)(Tn,{placeholder:"Sort by"})}),(0,re.jsx)(Rn,{children:Lb.map(e=>(0,re.jsx)(Dn,{value:e.value,className:"font-base44",children:e.label},e.value))})]})})]})})}var Rb=t(95445);const Db=e=>{var s,t;let{item:a,onSelect:n,isAdmin:r,currentUser:l}=e;const{item:i,usage:o}=a,c=(null==l?void 0:l.email)===i.owner_email,d=!("pending"===i.status&&!i.is_private)||r||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,re.jsxs)(Xn,{className:m,onClick:()=>{d&&n(i.id)},children:[(0,re.jsx)(Qn,{className:"pb-1 px-4 pt-4",children:(0,re.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,re.jsxs)(ir,{className:"h-12 w-12 flex-shrink-0 rounded-md",children:[(0,re.jsx)(or,{src:i.image_url,alt:i.name,className:"object-contain"}),(0,re.jsx)(cr,{className:"bg-gradient-to-br from-blue-100 to-teal-100 text-teal-700 text-sm font-medium",children:(null===(s=i.name)||void 0===s||null===(t=s.charAt(0))||void 0===t?void 0:t.toUpperCase())||"I"})]}),(0,re.jsxs)("div",{className:"w-full",children:[(0,re.jsx)(er,{className:"text-[16px] font-regular",children:i.name}),(0,re.jsxs)("div",{className:"flex gap-1.5 flex-wrap",children:[i.official&&(0,re.jsxs)(Nn,{variant:"outline",className:"bg-blue-50 px-1.5 py-0 h-5 font-normal",children:[(0,re.jsx)(Rb.A,{className:"h-3 w-3 mr-0.5"}),(0,re.jsx)("span",{className:"text-xs",children:"Official"})]}),i.is_private&&(0,re.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,re.jsx)(Fs.A,{className:"h-3 w-3 mr-0.5"}),(0,re.jsx)("span",{className:"text-xs",children:"Private"})]}),"pending"===i.status&&!i.is_private&&(0,re.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,re.jsx)(Xp.A,{className:"h-3 w-3 mr-0.5"}),(0,re.jsx)("span",{className:"text-xs",children:"Pending Review"})]})]})]})]})}),(0,re.jsx)(tr,{className:"pb-3 px-4 flex-1",children:(0,re.jsx)("div",{className:" overflow-hidden",children:(0,re.jsx)("p",{className:"text-sm font-light line-clamp-3 text-[#3C444C]",children:i.description||"No description provided."})})}),(0,re.jsx)(ar,{className:"px-4 py-2 flex mt-auto",children:(0,re.jsx)("div",{className:"flex gap-1 text-sm",children:(0,re.jsxs)("span",{className:"font-light font-base44 text-[#3C444C]",children:[o||0," installs"]})})})]})},Mb=()=>{const e=(0,Z.Zp)(),s=()=>{e("/integrations-catalog/editor")};return(0,re.jsxs)(Xn,{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:s,children:[(0,re.jsx)(Qn,{className:"pb-1 px-4 pt-4 relative z-10",children:(0,re.jsx)(er,{className:"text-[16px] font-regular text-white leading-tight text-left",children:"Create Your Integration"})}),(0,re.jsx)(tr,{className:"pb-3 px-4 flex-1 relative z-10",children:(0,re.jsx)("div",{className:"text-left",children:(0,re.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,re.jsx)(ar,{className:"px-4 py-2 flex mt-auto relative z-10",children:(0,re.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(),s()},children:"Create Integration"})})]})},Fb=()=>(0,re.jsxs)(Xn,{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,re.jsx)(Qn,{className:"pb-1 px-4 pt-4",children:(0,re.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,re.jsx)("div",{className:"h-12 w-12 flex-shrink-0 rounded-md bg-slate-200"}),(0,re.jsx)("div",{className:"w-full",children:(0,re.jsx)("div",{className:"h-5 bg-slate-200 rounded w-3/4 mb-2"})})]})}),(0,re.jsx)(tr,{className:"pb-3 px-4 flex-1",children:(0,re.jsx)("div",{className:"overflow-hidden",children:(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsx)("div",{className:"h-4 bg-slate-200 rounded w-full"}),(0,re.jsx)("div",{className:"h-4 bg-slate-200 rounded w-5/6"}),(0,re.jsx)("div",{className:"h-4 bg-slate-200 rounded w-4/6"})]})})}),(0,re.jsx)(ar,{className:"px-4 py-2 flex mt-auto",children:(0,re.jsx)("div",{className:"h-4 bg-slate-200 rounded w-20"})})]}),Bb=e=>{let{count:s=12}=e;return(0,re.jsx)("div",{className:"space-y-6",children:(0,re.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:s}).map((e,s)=>(0,re.jsx)(Fb,{},"skeleton-".concat(s)))})})},Ub=e=>{let{isLoading:s,isLoadingMore:t,items:a,onCardClick:n,hasMore:r,targetRef:l,isAdmin:i,onCreateIntegration:o,activeTab:c,currentUser:d}=e;if(s)return(0,re.jsx)(Bb,{});if(0===a.length)return"my-integrations"===c?(0,re.jsx)("div",{className:"text-center py-16 px-8",children:(0,re.jsxs)("div",{className:"max-w-sm mx-auto",children:[(0,re.jsx)("div",{className:"relative mb-6",children:(0,re.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,re.jsx)($r.A,{className:"h-8 w-8 text-teal-600"})})}),(0,re.jsx)("h3",{className:"text-xl font-base44 font-medium text-slate-900 mb-3",children:"Create your first integration"}),(0,re.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,re.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,re.jsx)(Ss.A,{className:"h-4 w-4 mr-2"}),"Create Integration"]})]})}):(0,re.jsxs)("div",{className:"text-center p-12 border rounded-lg bg-slate-50",children:[(0,re.jsx)("div",{className:"text-slate-400 mb-3",children:(0,re.jsx)(vn.A,{className:"h-12 w-12 mx-auto"})}),(0,re.jsx)("h3",{className:"text-lg font-medium text-slate-700 mb-1",children:"No matching integrations found"}),(0,re.jsx)("p",{className:"text-slate-500 text-sm",children:"Try adjusting your search or filter settings."})]});return(0,re.jsxs)("div",{className:"space-y-6",children:[(0,re.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((s,t)=>{5===t&&e.push((0,re.jsx)(Mb,{},"create-integration-card")),e.push((0,re.jsx)(Db,{item:s,onSelect:n,isAdmin:i,currentUser:d},s.item.id))}),a.length<6&&e.push((0,re.jsx)(Mb,{},"create-integration-card")),e})()}),t&&(0,re.jsxs)("div",{className:"flex justify-center items-center py-8",children:[(0,re.jsx)(Ze.A,{className:"h-6 w-6 text-teal-600 animate-spin mr-2"}),(0,re.jsx)("span",{className:"text-sm text-slate-500",children:"Loading more integrations..."})]}),r&&!t&&(0,re.jsx)("div",{ref:l,className:"h-1"}),!r&&a.length>0&&(0,re.jsx)("div",{className:"text-center py-8 text-sm text-slate-500",children:"You've reached the end of the integrations catalog"})]})};const zb=function(){const{user:e}=oe(),s=(0,H.useRef)(0),[t,a]=(0,H.useState)("catalog"),[n,r]=(0,H.useState)([]),[l,i]=(0,H.useState)(!0),[o,c]=(0,H.useState)(""),[d,m]=(0,H.useState)("all"),[u,x]=(0,H.useState)("most-upvoted"),[h,p]=(0,H.useState)("all"),[g,f]=(0,H.useState)("all"),[v,b]=(0,H.useState)(new Set),j=(0,Z.Zp)(),[y,N]=(0,H.useState)(!0),[w,_]=(0,H.useState)(!1),[k,A]=(0,H.useState)(0),[S]=(0,H.useState)(20),[C,E]=(0,H.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,H.useCallback)(async function(){let a=arguments.length>0&&void 0!==arguments[0]&&arguments[0];const n=++s.current;try{a?_(!0):(i(!0),E(0));const l=(()=>{const s={};return"my-integrations"===t&&null!=e&&e.email&&(s.created_by=e.email),o.trim()&&(s.$or=[{name:{$regex:o.trim(),$options:"i"}},{description:{$regex:o.trim(),$options:"i"}},{created_by:{$regex:o.trim(),$options:"i"}}]),"all"!==d&&(s.categories=d),I&&("private"===h?s.is_private=!0:"public"===h&&(s.is_private=!1),"pending"===g?s.status="pending":"approved"===g&&(s.status="approved")),s})(),c=a?C:0,m=await Ks.listCatalogItems((0,K.A)((0,K.A)({},l),{},{limit:S,skip:c,sort_by:T(u)}));if(n!==s.current)return;const x=m.data||m||[];a?(r(e=>[...e,...x]),E(e=>e+S)):(r(x),E(S)),N(x.length===S),A(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(l){if(n!==s.current)return;an({title:"Error",description:"Failed to load integrations",variant:"destructive"}),a||r([])}finally{n===s.current&&(i(!1),_(!1))}},[t,u,h,g,o,d,I,C,S,null==e?void 0:e.email]);(0,H.useEffect)(()=>{P()},[]),(0,H.useEffect)(()=>{P(!1)},[t,o,d,u,h,g]);const{targetRef:L}=Tb({onLoadMore:()=>{y&&!w&&P(!0)},hasMore:y,isLoading:l||w}),O=n.length,R=k>0?"Showing ".concat(O," of ").concat(k," integrations"):"";return(0,re.jsxs)("div",{className:"px-4 sm:px-6 md:px-8 lg:px-12 max-w-[1600px] mx-auto",children:[(0,re.jsx)(Pb,{activeTab:t,onTabChange:e=>{e!==t&&(r([]),i(!0),a(e),E(0),N(!0),A(0))}}),(0,re.jsx)(Ob,{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:l,isAdmin:I}),(0,re.jsx)(Ub,{isLoading:l,isLoadingMore:w,items:n,onCardClick:e=>{j("/integrations-catalog/item/".concat(e))},hasMore:y,targetRef:L,isAdmin:I,onCreateIntegration:()=>{j("/integrations-catalog/editor")},activeTab:t})]})};var qb=t(68432),Wb=t(32369);const Vb=["className","orientation","decorative"],Yb=H.forwardRef((e,s)=>{let{className:t,orientation:a="horizontal",decorative:n=!0}=e,r=(0,as.A)(e,Vb);return(0,re.jsx)(xt.b,(0,K.A)({ref:s,decorative:n,orientation:a,className:is("shrink-0 bg-border","horizontal"===a?"h-[1px] w-full":"h-full w-[1px]",t)},r))});Yb.displayName=xt.b.displayName;const Hb=()=>(0,re.jsx)("div",{className:"min-h-screen bg-white font-base44 animate-pulse",children:(0,re.jsxs)("div",{className:"mx-auto",children:[(0,re.jsx)("div",{className:"max-w-7xl mx-auto px-4 sm:px-6 py-4",children:(0,re.jsxs)("nav",{className:"flex items-center space-x-2 text-sm",children:[(0,re.jsx)("div",{className:"h-4 w-20 bg-slate-200 rounded"}),(0,re.jsx)("span",{children:"/"}),(0,re.jsx)("div",{className:"h-4 w-32 bg-slate-200 rounded"})]})}),(0,re.jsx)("div",{className:"border-b border-slate-200"}),(0,re.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,re.jsx)("div",{className:"w-full lg:w-80 lg:flex-shrink-0",children:(0,re.jsxs)("div",{className:"mb-8",children:[(0,re.jsx)("div",{className:"flex gap-4 items-start mb-4",children:(0,re.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,re.jsx)("div",{className:"h-16 w-16 rounded-xl bg-slate-200"}),(0,re.jsxs)("div",{className:"text-center",children:[(0,re.jsx)("div",{className:"h-6 w-40 bg-slate-200 rounded mb-2 mx-auto"}),(0,re.jsx)("div",{className:"h-4 w-16 bg-slate-200 rounded mx-auto"})]})]})}),(0,re.jsxs)("div",{className:"space-y-3 mb-6",children:[(0,re.jsxs)("div",{className:"flex items-center gap-2",children:[(0,re.jsx)("div",{className:"h-4 w-4 bg-slate-200 rounded"}),(0,re.jsx)("div",{className:"h-4 w-16 bg-slate-200 rounded"})]}),(0,re.jsxs)("div",{className:"flex items-center gap-2",children:[(0,re.jsx)("div",{className:"h-4 w-4 bg-slate-200 rounded"}),(0,re.jsx)("div",{className:"h-4 w-24 bg-slate-200 rounded"})]})]}),(0,re.jsx)("div",{className:"w-full lg:w-[280px] h-12 bg-slate-200 rounded-[16px] mb-4"}),(0,re.jsxs)("div",{className:"space-y-4",children:[(0,re.jsxs)("div",{children:[(0,re.jsx)("div",{className:"h-4 w-12 bg-slate-200 rounded mb-2"}),(0,re.jsx)("div",{className:"h-4 w-28 bg-slate-200 rounded"})]}),(0,re.jsxs)("div",{children:[(0,re.jsx)("div",{className:"h-4 w-full bg-slate-200 rounded mb-1"}),(0,re.jsx)("div",{className:"h-4 w-3/4 bg-slate-200 rounded"})]})]}),(0,re.jsx)("div",{className:"h-px w-full bg-slate-200 my-6"}),(0,re.jsxs)("div",{className:"mt-6 space-y-3",children:[(0,re.jsxs)("div",{className:"flex items-center justify-between w-full",children:[(0,re.jsx)("div",{className:"h-4 w-36 bg-slate-200 rounded"}),(0,re.jsx)("div",{className:"h-4 w-4 bg-slate-200 rounded"})]}),(0,re.jsxs)("div",{className:"flex items-center justify-between w-full",children:[(0,re.jsx)("div",{className:"h-4 w-32 bg-slate-200 rounded"}),(0,re.jsx)("div",{className:"h-4 w-4 bg-slate-200 rounded"})]})]})]})}),(0,re.jsxs)("div",{className:"flex-1 border border-slate-200 p-6 rounded-[20px] min-w-0",children:[(0,re.jsxs)("div",{className:"mb-8",children:[(0,re.jsx)("div",{className:"h-6 sm:h-8 w-28 bg-slate-200 rounded mb-4"}),(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsx)("div",{className:"h-4 w-full bg-slate-200 rounded"}),(0,re.jsx)("div",{className:"h-4 w-full bg-slate-200 rounded"}),(0,re.jsx)("div",{className:"h-4 w-3/4 bg-slate-200 rounded"})]})]}),(0,re.jsxs)("div",{className:"mb-8",children:[(0,re.jsx)("div",{className:"h-6 w-40 bg-slate-200 rounded mb-4"}),(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsx)("div",{className:"bg-slate-100 rounded-lg px-4 py-3",children:(0,re.jsx)("div",{className:"h-4 w-full bg-slate-200 rounded"})}),(0,re.jsx)("div",{className:"bg-slate-100 rounded-lg px-4 py-3",children:(0,re.jsx)("div",{className:"h-4 w-5/6 bg-slate-200 rounded"})}),(0,re.jsx)("div",{className:"bg-slate-100 rounded-lg px-4 py-3",children:(0,re.jsx)("div",{className:"h-4 w-4/5 bg-slate-200 rounded"})})]})]}),(0,re.jsxs)("div",{className:"mb-8",children:[(0,re.jsxs)("div",{className:"bg-slate-100 p-1 mb-6 rounded-md flex gap-1",children:[(0,re.jsx)("div",{className:"h-8 w-24 bg-slate-200 rounded"}),(0,re.jsx)("div",{className:"h-8 w-32 bg-slate-200 rounded"})]}),(0,re.jsx)("div",{className:"space-y-4",children:(0,re.jsxs)("div",{children:[(0,re.jsxs)("div",{className:"flex items-center justify-between mb-3",children:[(0,re.jsx)("div",{className:"h-5 w-32 bg-slate-200 rounded"}),(0,re.jsx)("div",{className:"h-4 w-24 bg-slate-200 rounded"})]}),(0,re.jsx)("div",{className:"h-4 w-full bg-slate-200 rounded mb-4"}),(0,re.jsxs)("div",{className:"space-y-3",children:[(0,re.jsxs)("div",{className:"bg-slate-100 rounded-lg p-4 border border-slate-200",children:[(0,re.jsx)("div",{className:"h-5 w-24 bg-slate-200 rounded mb-2"}),(0,re.jsx)("div",{className:"h-4 w-full bg-slate-200 rounded"})]}),(0,re.jsxs)("div",{className:"bg-slate-100 rounded-lg p-4 border border-slate-200",children:[(0,re.jsx)("div",{className:"h-5 w-32 bg-slate-200 rounded mb-2"}),(0,re.jsx)("div",{className:"h-4 w-5/6 bg-slate-200 rounded"})]})]})]})})]}),(0,re.jsx)("div",{className:"mb-8 p-4 bg-slate-100 border border-slate-200 rounded-lg",children:(0,re.jsxs)("div",{className:"flex items-start gap-3",children:[(0,re.jsx)("div",{className:"h-8 w-8 rounded-full bg-slate-200 flex-shrink-0"}),(0,re.jsxs)("div",{children:[(0,re.jsx)("div",{className:"h-5 w-28 bg-slate-200 rounded mb-2"}),(0,re.jsx)("div",{className:"h-9 w-36 bg-slate-200 rounded"})]})]})})]})]}),(0,re.jsx)("div",{className:"max-w-7xl mx-auto px-4 sm:px-6 pb-8",children:(0,re.jsxs)("div",{className:"bg-slate-100 rounded-2xl border border-slate-200 p-6",children:[(0,re.jsxs)("div",{className:"mb-4",children:[(0,re.jsx)("div",{className:"h-6 w-48 bg-slate-200 rounded mb-2"}),(0,re.jsxs)("div",{className:"space-y-1",children:[(0,re.jsx)("div",{className:"h-4 w-full bg-slate-200 rounded"}),(0,re.jsx)("div",{className:"h-4 w-2/3 bg-slate-200 rounded"})]})]}),(0,re.jsxs)("div",{className:"flex flex-col sm:flex-row sm:flex-wrap gap-3",children:[(0,re.jsx)("div",{className:"h-10 w-36 bg-slate-200 rounded-xl"}),(0,re.jsx)("div",{className:"h-10 w-28 bg-slate-200 rounded-xl"}),(0,re.jsx)("div",{className:"h-10 w-32 bg-slate-200 rounded-xl"}),(0,re.jsx)("div",{className:"h-10 w-20 bg-slate-200 rounded-xl"})]})]})})]})}),Gb=()=>{var e;const{itemId:s}=(0,Z.g)(),t=(0,Z.Zp)(),{user:a}=oe(),[n,r]=(0,H.useState)(null),[l,i]=(0,H.useState)(!0),[o,c]=(0,H.useState)(null),[d,m]=(0,H.useState)("details"),[u,x]=(0,H.useState)(!1),[h,p]=(0,H.useState)(!1),[g,f]=(0,H.useState)(!1),[v,b]=(0,H.useState)(!1),[j,y]=(0,H.useState)(!1),[N,w]=(0,H.useState)(""),[_,k]=(0,H.useState)(!1),A=a&&"platform_admin"===a.platform_role,S=a&&("free"===a.subscription_tier||"starter"===a.subscription_tier);(0,H.useEffect)(()=>{s&&C()},[s]);const C=async()=>{if(s)try{i(!0);const e=await Ks.getCatalogItem(s);r(e.data||e),i(!1)}catch(e){c("Failed to load item details"),i(!1)}};if(l)return(0,re.jsx)(Hb,{});if(o)return(0,re.jsxs)("div",{className:"flex flex-col items-center justify-center min-h-[500px] text-center p-4",children:[(0,re.jsxs)("div",{className:"text-red-500 text-xl font-semibold mb-2",children:["\u26a0\ufe0f ",o]}),(0,re.jsx)("button",{className:"px-4 py-2 bg-blue-500 text-white rounded-md hover:bg-blue-600 transition-colors",onClick:C,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&&S;return(0,re.jsx)("div",{className:"min-h-screen bg-white font-base44",children:(0,re.jsxs)("div",{className:"mx-auto",children:[(0,re.jsx)("div",{className:"max-w-7xl mx-auto px-4 sm:px-6 py-4",children:(0,re.jsxs)("nav",{className:"flex items-center space-x-2 text-sm text-slate-600",children:[(0,re.jsx)("button",{onClick:()=>{t("/integrations-catalog")},className:"hover:text-slate-900 transition-colors",children:"Integrations"}),(0,re.jsx)("span",{children:"/"}),(0,re.jsx)("span",{className:"text-slate-900 font-medium",children:E.name})]})}),(0,re.jsx)("div",{className:"border-b border-slate-200"}),(0,re.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,re.jsx)("div",{className:"w-full lg:w-80 lg:flex-shrink-0",children:(0,re.jsxs)("div",{className:"mb-8",children:[(0,re.jsx)("div",{className:"flex gap-4 items-start mb-4",children:(0,re.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,re.jsx)("div",{className:"h-16 w-16 rounded-xl overflow-hidden bg-white",children:E.image_url?(0,re.jsx)("img",{src:E.image_url,alt:E.name,className:"h-full w-full object-contain",onError:e=>{const s=e.target;s.src="",s.alt=""}}):(0,re.jsx)("div",{className:"h-full w-full bg-slate-50 flex items-center justify-center",children:(0,re.jsx)("span",{className:"text-slate-600 text-lg font-semibold",children:E.name.charAt(0).toUpperCase()})})}),(0,re.jsx)("div",{className:"text-center",children:(0,re.jsx)("h1",{className:"text-lg sm:text-xl font-semibold break-words",children:E.name})}),E.official&&(0,re.jsxs)("div",{className:"flex items-center gap-1 mt-2",children:[(0,re.jsx)(Rb.A,{className:"h-4 w-4 text-blue-600"}),(0,re.jsx)("span",{className:"text-sm text-blue-600 font-medium",children:"Official"})]})]})}),(0,re.jsxs)("div",{className:"space-y-3 mb-6",children:[(0,re.jsxs)("div",{className:"flex items-center gap-2 text-sm text-slate-600",children:[(0,re.jsx)(bn.A,{className:"h-4 w-4"}),(0,re.jsx)("span",{children:E.is_private?"Private":"Public"})]}),E.created_at&&(0,re.jsxs)("div",{className:"flex items-center gap-2 text-sm text-slate-600",children:[(0,re.jsx)(Xp.A,{className:"h-4 w-4"}),(0,re.jsxs)("span",{children:["Added ",la().utc(E.created_at).fromNow()]})]})]}),L?(0,re.jsx)(Yn,{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,re.jsx)(Yn,{onClick:()=>{t("/?integrations=".concat(s))},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,re.jsx)("div",{className:"bg-amber-50 border border-amber-200 rounded-md p-3 mb-4",children:(0,re.jsxs)("div",{className:"flex gap-2",children:[(0,re.jsx)(Xe.A,{className:"h-4 w-4 text-amber-600 flex-shrink-0 mt-0.5"}),(0,re.jsx)("p",{className:"text-sm text-amber-800",children:"This integration requires backend functions, a feature available only on Builder tier and above."})]})}),(0,re.jsxs)("div",{className:"space-y-4",children:[(0,re.jsxs)("div",{className:"flex justify-between items-center",children:[(0,re.jsx)("span",{className:"text-sm font-medium text-slate-900",children:"Status"}),"approved"===E.status?(0,re.jsxs)(Nn,{className:"bg-green-100 text-green-800 hover:bg-green-200",children:[(0,re.jsx)(Px.A,{className:"h-3 w-3 mr-1"}),"Approved"]}):(0,re.jsx)(Nn,{className:"bg-amber-100 text-amber-800 hover:bg-amber-200",children:"Pending Approval"})]}),(0,re.jsxs)("div",{children:[(0,re.jsx)("h4",{className:"text-sm font-medium text-slate-900 mb-3",children:"Share this integration"}),(0,re.jsxs)("div",{className:"flex items-center gap-1.5 p-1.5 bg-slate-50 rounded-md border border-slate-200",children:[(0,re.jsx)("div",{className:"flex-1 text-xs text-slate-600 truncate font-mono",children:window.location.href}),(0,re.jsx)(Yn,{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,re.jsx)(Pt.A,{className:"h-3.5 w-3.5 text-green-600"}):(0,re.jsx)(Kr.A,{className:"h-3.5 w-3.5 text-slate-500"})})]})]}),E.requires_backend_functions&&(0,re.jsxs)("div",{children:[(0,re.jsx)("p",{className:"text-sm text-slate-600 break-words",children:"Using this integration will automatically activate backend functions."}),(0,re.jsx)("p",{className:"text-sm text-slate-600 mt-1 break-words",children:"Available on the Builder tier and above."})]})]}),(0,re.jsx)(Yb,{className:"my-6 bg-gray-400"}),P&&(0,re.jsxs)("div",{className:"mt-6 space-y-3",children:[(0,re.jsxs)("button",{className:"flex items-center justify-between w-full text-sm text-slate-600 hover:text-slate-900",children:[(0,re.jsx)("span",{children:"How to get your API key"}),(0,re.jsx)("span",{children:"\u2197"})]}),(0,re.jsxs)("button",{className:"flex items-center justify-between w-full text-sm text-slate-600 hover:text-slate-900",onClick:()=>t("/support"),children:[(0,re.jsx)("span",{children:"Base44 support hub"}),(0,re.jsx)("span",{children:"\u2197"})]})]})]})}),(0,re.jsxs)("div",{className:"flex-1 border border-slate-200 p-6 rounded-[20px] min-w-0",children:[(0,re.jsxs)("div",{className:"mb-8",children:[(0,re.jsx)("h1",{className:"text-xl sm:text-2xl font-bold text-slate-900 mb-4",children:"Overview"}),(0,re.jsx)("p",{className:"text-slate-600 text-base leading-relaxed break-words",children:E.description})]}),E.example_asks&&E.example_asks.length>0&&(0,re.jsxs)("div",{className:"mb-8",children:[(0,re.jsx)("h3",{className:"text-lg font-semibold text-slate-900 mb-4",children:"Example prompts"}),(0,re.jsx)("div",{className:"space-y-2",children:E.example_asks.map((e,s)=>(0,re.jsx)("div",{className:"bg-slate-50 rounded-lg px-4 py-3 text-sm text-slate-700 break-words",children:e},s))})]}),(P||E.prompt)&&(0,re.jsx)("div",{className:"mb-8",children:(0,re.jsxs)(gu,{defaultValue:P?"requirements":"instructions",className:"w-full",children:[(0,re.jsxs)(fu,{className:"bg-slate-50 p-1 mb-6",children:[P&&(0,re.jsx)(vu,{value:"requirements",className:"text-sm data-[state=active]:bg-white data-[state=active]:shadow-sm",children:"Requirements"}),E.prompt&&(0,re.jsx)(vu,{value:"instructions",className:"text-sm data-[state=active]:bg-white data-[state=active]:shadow-sm",children:"Instructions Set"})]}),P&&(0,re.jsx)(bu,{value:"requirements",children:(0,re.jsx)("div",{className:"space-y-4",children:(0,re.jsxs)("div",{children:[(0,re.jsxs)("div",{className:"flex items-center justify-between mb-3",children:[(0,re.jsx)("h4",{className:"font-semibold text-slate-900",children:"Required API Keys"}),(0,re.jsxs)("button",{className:"text-sm text-blue-600 hover:text-blue-800 flex items-center gap-1",children:["Documentation ",(0,re.jsx)("span",{children:"\u2197"})]})]}),(0,re.jsx)("p",{className:"text-sm text-slate-600 mb-4",children:"You'll need these credentials to use this integration:"}),(0,re.jsx)("div",{className:"space-y-3",children:null===(e=E.required_secrets)||void 0===e?void 0:e.map((e,s)=>(0,re.jsxs)("div",{className:"bg-slate-50 rounded-lg p-4 border border-slate-200",children:[(0,re.jsx)("h5",{className:"font-medium text-slate-900 mb-2 break-words",children:e.name}),(0,re.jsx)("p",{className:"text-sm text-slate-600 break-words",children:e.description||"Required for this integration to work properly."})]},s))})]})})}),E.prompt&&(0,re.jsx)(bu,{value:"instructions",children:(0,re.jsxs)("div",{className:"space-y-4",children:[(0,re.jsx)("div",{children:(0,re.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,re.jsx)("div",{className:"bg-blue-50 border border-blue-200 rounded-lg p-4",children:(0,re.jsxs)("div",{className:"flex gap-2",children:[(0,re.jsx)(qb.A,{className:"h-4 w-4 text-blue-600 flex-shrink-0 mt-0.5"}),(0,re.jsx)("div",{children:(0,re.jsxs)("p",{className:"text-sm text-blue-800",children:[(0,re.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,re.jsx)("div",{className:"bg-slate-50 p-4 rounded-lg border border-slate-200 overflow-auto max-h-[500px]",children:(0,re.jsx)("pre",{className:"whitespace-pre-wrap text-sm text-slate-700 font-mono break-words overflow-hidden",children:E.prompt})})]})})]})}),A&&T&&(0,re.jsx)("div",{className:"mb-8 p-4 bg-blue-50 border border-blue-200 rounded-lg",children:(0,re.jsxs)("div",{className:"flex items-start gap-3",children:[(0,re.jsx)("div",{className:"h-8 w-8 rounded-full bg-blue-100 flex items-center justify-center flex-shrink-0",children:(0,re.jsx)(Ho.A,{className:"h-4 w-4 text-blue-600"})}),(0,re.jsxs)("div",{children:[(0,re.jsx)("h4",{className:"font-medium text-slate-900",children:"Admin Actions"}),(0,re.jsx)("div",{className:"mt-2",children:(0,re.jsxs)(Yn,{onClick:async()=>{if(s)try{x(!0),await Ks.approveItem(s),an({title:"Success",description:"Integration has been approved"}),C()}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,re.jsx)(Px.A,{className:"h-4 w-4 mr-1.5"}),u?"Approving...":"Approve Integration"]})})]})]})})]})]}),I&&(0,re.jsx)(re.Fragment,{children:(0,re.jsx)("div",{className:"max-w-7xl mx-auto px-4 sm:px-6 pb-8",children:(0,re.jsxs)("div",{className:"bg-slate-50 rounded-2xl border border-slate-200 p-6",children:[(0,re.jsxs)("div",{className:"mb-4",children:[(0,re.jsx)("h3",{className:"text-lg font-semibold text-slate-900 mb-2",children:"Integration Management"}),(0,re.jsx)("p",{className:"text-sm text-slate-600",children:"As the owner of this integration, you can manage its settings and visibility."})]}),(0,re.jsxs)("div",{className:"flex flex-col sm:flex-row sm:flex-wrap gap-3",children:[(0,re.jsxs)(Yn,{variant:"outline",size:"default",onClick:()=>{t("/integrations-catalog/editor/".concat(s))},className:"bg-white text-slate-700 border-slate-300 hover:bg-slate-50 rounded-xl px-6",children:[(0,re.jsx)(Hr.A,{className:"h-4 w-4 mr-2"}),"Edit Integration"]}),(0,re.jsx)(Yn,{variant:"outline",size:"default",onClick:async()=>{if(s&&n)try{y(!0),await Ks.update(s,{is_private:!n.item.is_private}),an({title:"Success",description:n.item.is_private?"Integration is now public":"Integration is now private"}),C()}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,re.jsxs)(re.Fragment,{children:[(0,re.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,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(bn.A,{className:"h-4 w-4 mr-2"}),"Make Public"]}):(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(Fs.A,{className:"h-4 w-4 mr-2"}),"Make Private"]})}),(0,re.jsxs)(to,{open:_,onOpenChange:k,children:[(0,re.jsx)(ao,{asChild:!0,children:(0,re.jsxs)(Yn,{variant:"outline",size:"default",className:"bg-white text-slate-700 border-slate-300 hover:bg-slate-50 rounded-xl px-6",children:[(0,re.jsx)(Qf.A,{className:"h-4 w-4 mr-2"}),"Invite Admin"]})}),(0,re.jsxs)(lo,{className:"sm:max-w-[425px]",children:[(0,re.jsxs)(io,{children:[(0,re.jsx)(co,{children:"Invite User"}),(0,re.jsx)(mo,{children:"Invite a user to edit and administer this catalog item"})]}),(0,re.jsx)("div",{className:"grid gap-4 py-4",children:(0,re.jsxs)("div",{className:"grid grid-cols-4 items-center gap-4",children:[(0,re.jsx)(uu,{htmlFor:"email",className:"text-right",children:"Email"}),(0,re.jsx)(fn,{id:"email",type:"email",placeholder:"user@example.com",className:"col-span-3",value:N,onChange:e=>w(e.target.value)})]})}),(0,re.jsx)(oo,{children:(0,re.jsx)(Yn,{onClick:async()=>{if(s&&N&&N.includes("@"))try{b(!0),await Ks.inviteAdmin(s,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,re.jsxs)(Yn,{variant:"outline",size:"default",onClick:async()=>{if(s)try{p(!0),await Ks.archiveItem(s),an({title:"Success",description:"Integration has been archived"}),t("/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,re.jsx)(Wb.A,{className:"h-4 w-4 mr-2"}),h?"Archiving...":"Archive"]})]})]})})})]})})};var $b=t(27304),Jb=t(23198),Zb=t(13052),Kb=t(11464);const Xb=["className"],Qb=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,Xb);return(0,re.jsx)(yu.bL,(0,K.A)((0,K.A)({className:is("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",t)},a),{},{ref:s,children:(0,re.jsx)(yu.zi,{className:is("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")})}))});Qb.displayName=yu.bL.displayName;const ej=e=>{let{children:s}=e;return(0,re.jsx)(Og,{children:(0,re.jsxs)(Rg,{delayDuration:300,children:[(0,re.jsx)(Dg,{asChild:!0,children:(0,re.jsx)(_h.A,{className:"h-4 w-4 text-slate-400 ml-1.5 cursor-help"})}),(0,re.jsx)(Mg,{className:"max-w-xs p-3 text-xs",children:s})]})})},sj=()=>{const{itemId:e}=(0,Z.g)(),s=(0,Z.Zp)(),{toast:t}=nn(),a=!!e,[n,r]=(0,H.useState)(null),[l,i]=(0,H.useState)(!!e),[o,c]=(0,H.useState)(!1),[d,m]=(0,H.useState)(!1),[u,x]=(0,H.useState)(null),[h,p]=(0,H.useState)({name:"",description:"",prompt:"",image_url:"",example_asks:[],required_secrets:[],requires_backend_functions:!0,is_private:!1}),[g,f]=(0,H.useState)("metadata"),[v,b]=(0,H.useState)(""),[j,y]=(0,H.useState)(""),[N,w]=(0,H.useState)("");(0,H.useEffect)(()=>{e?(async()=>{if(e)try{i(!0);const s=await Ks.getCatalogItem(e),t=s.data||s;r(t);const a=t.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(s){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:s,value:t}=e.target;p(e=>(0,K.A)((0,K.A)({},e),{},{[s]:t}))},k=(e,s)=>{p(t=>(0,K.A)((0,K.A)({},t),{},{[e]:s}))},A=async n=>{if(n&&n.preventDefault(),h.name.trim()?h.description.trim()?!(h.prompt.trim().length<50&&(t({title:"Validation Error",description:"Integration prompt must be at least 50 characters",variant:"destructive"}),f("content"),1)):(t({title:"Validation Error",description:"Integration description is required",variant:"destructive"}),f("metadata"),0):(t({title:"Validation Error",description:"Integration name is required",variant:"destructive"}),f("metadata"),0)){c(!0),x(null);try{let n;if(a&&e)await Ks.update(e,h),n=e;else{var r;const e=await Ks.create(h);n=(null===(r=e.data)||void 0===r?void 0:r.id)||e.id}t({title:"Success",description:a?"Integration updated successfully":"Integration created successfully"}),s("/integrations-catalog/item/".concat(n))}catch(l){x("Failed to save integration. Please try again."),t({title:"Error",description:"Failed to save integration. Please try again.",variant:"destructive"}),c(!1)}}},S=()=>{s("/integrations-catalog")};return l?(0,re.jsxs)("div",{className:"flex items-center justify-center h-[80vh]",children:[(0,re.jsx)(Ze.A,{className:"h-8 w-8 text-teal-600 animate-spin"}),(0,re.jsx)("span",{className:"ml-2 text-lg text-slate-700",children:"Loading integration..."})]}):u&&e&&!h.name?(0,re.jsxs)("div",{className:"flex flex-col items-center justify-center h-[80vh]",children:[(0,re.jsx)("div",{className:"text-red-500 text-lg mb-4",children:u}),(0,re.jsx)(Yn,{onClick:S,className:"px-4 py-2 bg-teal-600 text-white rounded hover:bg-teal-700",children:"Return to Catalog"})]}):(0,re.jsxs)("div",{className:"max-w-screen-xl mx-auto px-4 py-8",children:[(0,re.jsxs)("div",{className:"flex justify-between items-center mb-8",children:[(0,re.jsxs)("div",{className:"flex items-center gap-3",children:[(0,re.jsx)(Yn,{variant:"ghost",size:"icon",onClick:S,className:"h-10 w-10 rounded-full",children:(0,re.jsx)(Cc.A,{className:"h-5 w-5"})}),(0,re.jsx)("h1",{className:"text-2xl font-bold text-slate-900",children:a?"Edit Integration":"Create New Integration"})]}),(0,re.jsxs)("div",{className:"flex items-center gap-3",children:[(0,re.jsx)(Yn,{variant:"outline",onClick:S,className:"px-4",children:"Cancel"}),(0,re.jsxs)(Yn,{onClick:()=>A(),disabled:o,className:"bg-teal-600 hover:bg-teal-700 px-4",children:[o?(0,re.jsx)(Ze.A,{className:"h-4 w-4 mr-2 animate-spin"}):(0,re.jsx)(ah.A,{className:"h-4 w-4 mr-2"}),o?"Saving...":"Save Integration"]})]})]}),(0,re.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,re.jsx)($b.A,{className:"h-5 w-5 text-amber-500 mr-3 flex-shrink-0"}),(0,re.jsxs)("p",{className:"text-amber-800",children:[(0,re.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,re.jsx)(ex,{variant:"destructive",className:"mb-6",children:(0,re.jsx)(tx,{children:u})}),(0,re.jsx)("div",{className:"bg-white rounded-xl border shadow-sm overflow-hidden",children:(0,re.jsxs)(gu,{value:g,onValueChange:f,className:"w-full",children:[(0,re.jsx)("div",{className:"px-6 pt-6 border-b",children:(0,re.jsxs)(fu,{className:"grid w-full grid-cols-2 max-w-md",children:[(0,re.jsxs)(vu,{value:"metadata",className:"flex items-center gap-2",children:[(0,re.jsx)(od.A,{className:"h-4 w-4"}),(0,re.jsx)("span",{children:"Integration Metadata"})]}),(0,re.jsxs)(vu,{value:"content",className:"flex items-center gap-2",children:[(0,re.jsx)(Yr.A,{className:"h-4 w-4"}),(0,re.jsx)("span",{children:"Integration Content"})]})]})}),(0,re.jsx)(bu,{value:"metadata",className:"p-6 space-y-8",children:(0,re.jsxs)("div",{className:"grid gap-8 max-w-3xl mx-auto",children:[(0,re.jsxs)("div",{className:"space-y-4",children:[(0,re.jsxs)("div",{className:"flex items-center",children:[(0,re.jsx)("h2",{className:"text-lg font-semibold text-slate-900",children:"Integration Name"}),(0,re.jsx)(ej,{children:"A descriptive name for your integration that will be displayed in the catalog."})]}),(0,re.jsx)(fn,{id:"name",name:"name",value:h.name,onChange:_,placeholder:"E.g., OpenAI Text-To-Speech",required:!0,className:"text-lg"})]}),(0,re.jsxs)("div",{className:"space-y-4",children:[(0,re.jsxs)("div",{className:"flex items-center",children:[(0,re.jsx)("h2",{className:"text-lg font-semibold text-slate-900",children:"Description"}),(0,re.jsx)(ej,{children:"A brief explanation of what this integration does and how it helps users."})]}),(0,re.jsx)(du,{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,re.jsxs)("div",{className:"space-y-4",children:[(0,re.jsxs)("div",{className:"flex items-center",children:[(0,re.jsx)("h2",{className:"text-lg font-semibold text-slate-900",children:"Integration Logo"}),(0,re.jsx)(ej,{children:"An image that represents your integration. Square images work best."})]}),(0,re.jsxs)("div",{className:"flex items-center gap-8",children:[h.image_url?(0,re.jsx)("div",{className:"w-32 h-32 rounded-lg overflow-hidden border shadow-sm flex-shrink-0",children:(0,re.jsx)("img",{src:h.image_url,alt:"Integration Logo",className:"h-full w-full object-cover",onError:e=>{const s=e.target;s.src="",s.alt=""}})}):(0,re.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,re.jsx)(Jb.A,{className:"h-8 w-8 text-slate-400 mb-2"}),(0,re.jsx)("p",{className:"text-xs text-slate-500 text-center px-2",children:"No logo uploaded"})]}),(0,re.jsxs)("div",{className:"flex-1 max-w-sm",children:[(0,re.jsx)("input",{type:"file",id:"logo-upload",className:"hidden",accept:"image/*",onChange:async e=>{var s;const t=null===(s=e.target.files)||void 0===s?void 0:s[0];if(t)try{m(!0);const e=(await As.uploadFile(t)).url;p(s=>(0,K.A)((0,K.A)({},s),{},{image_url:e}))}catch(a){x("Failed to upload logo. Please try again.")}finally{m(!1)}}}),(0,re.jsxs)(Yn,{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,re.jsx)(hm.A,{className:"h-4 w-4 mr-2"}),d?"Uploading...":h.image_url?"Change Logo":"Upload Logo"]}),(0,re.jsx)("p",{className:"text-xs text-slate-500",children:"Upload a square image in PNG or JPG format (recommended size: 256\xd7256px)"})]})]})]}),(0,re.jsxs)("div",{className:"space-y-4",children:[(0,re.jsxs)("div",{className:"flex items-center",children:[(0,re.jsxs)("h2",{className:"text-lg font-semibold text-slate-900 flex items-center",children:[(0,re.jsx)(bl.A,{className:"h-4 w-4 mr-2 text-teal-600"}),"Example Prompts"]}),(0,re.jsx)(ej,{children:"Add examples of how users can ask for this integration in plain language"})]}),(0,re.jsxs)("div",{className:"grid gap-4",children:[(0,re.jsxs)("div",{className:"flex gap-2",children:[(0,re.jsx)(fn,{placeholder:"E.g., Convert text to speech",value:v,onChange:e=>b(e.target.value)}),(0,re.jsxs)(Yn,{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,re.jsx)(Zb.A,{className:"h-4 w-4 mr-1"})," Add"]})]}),h.example_asks.length>0?(0,re.jsx)("div",{className:"flex flex-wrap gap-2",children:h.example_asks.map((e,s)=>(0,re.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,re.jsx)("button",{type:"button",onClick:()=>(e=>{p(s=>(0,K.A)((0,K.A)({},s),{},{example_asks:s.example_asks.filter((s,t)=>t!==e)}))})(s),className:"ml-1 text-teal-700 hover:text-teal-900",children:(0,re.jsx)(zs.A,{className:"h-3 w-3"})})]},s))}):(0,re.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,re.jsxs)("div",{className:"space-y-4",children:[(0,re.jsxs)("div",{className:"flex items-center",children:[(0,re.jsx)("h2",{className:"text-lg font-semibold text-slate-900",children:"Integration Visibility"}),(0,re.jsx)(ej,{children:"Control whether your integration is private or public"})]}),(0,re.jsxs)("div",{className:"bg-white rounded-lg p-4 border flex items-center gap-4",children:[(0,re.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,re.jsx)(Fs.A,{className:"h-5 w-5 text-slate-700"}):(0,re.jsx)(bn.A,{className:"h-5 w-5 text-teal-600"})}),(0,re.jsxs)("div",{className:"flex-1",children:[(0,re.jsx)("h3",{className:"font-medium text-slate-900",children:h.is_private?"Private Integration":"Public Integration"}),(0,re.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,re.jsx)(Qb,{checked:!h.is_private,onCheckedChange:e=>k("is_private",!e)})]})]}),(0,re.jsx)("div",{className:"flex justify-end",children:(0,re.jsx)(Yn,{onClick:()=>f("content"),className:"bg-teal-600 hover:bg-teal-700",children:"Continue to Integration Content"})})]})}),(0,re.jsx)(bu,{value:"content",className:"p-6",children:(0,re.jsxs)("div",{className:"max-w-6xl mx-auto",children:[(0,re.jsxs)("div",{className:"mb-8 bg-blue-50 rounded-lg p-4 border border-blue-100",children:[(0,re.jsxs)("h3",{className:"text-lg font-medium text-blue-800 mb-2 flex items-center",children:[(0,re.jsx)(jo.A,{className:"h-5 w-5 mr-2"}),"About Integration Content"]}),(0,re.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,re.jsxs)("div",{className:"mb-8",children:[(0,re.jsxs)("div",{className:"flex items-center mb-2",children:[(0,re.jsx)("h2",{className:"text-xl font-semibold text-slate-900",children:"Integration Settings"}),(0,re.jsx)(ej,{children:"Configure how your integration should behave and what capabilities it needs."})]}),(0,re.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,re.jsx)(Xn,{className:"border-slate-200",children:(0,re.jsx)(tr,{className:"pt-6 space-y-6",children:(0,re.jsxs)("div",{className:"flex items-center gap-4",children:[(0,re.jsx)("div",{className:"h-10 w-10 rounded-full bg-slate-100 flex items-center justify-center flex-shrink-0",children:(0,re.jsx)(Kb.A,{className:"h-5 w-5 text-slate-700"})}),(0,re.jsxs)("div",{className:"flex-1",children:[(0,re.jsx)("h3",{className:"font-medium text-slate-900",children:"Backend Functions"}),(0,re.jsx)("p",{className:"text-sm text-slate-600",children:"Most integrations with external APIs require backend functions"})]}),(0,re.jsx)(Qb,{checked:h.requires_backend_functions,onCheckedChange:e=>k("requires_backend_functions",e)})]})})})]}),h.requires_backend_functions&&(0,re.jsxs)("div",{className:"mb-8",children:[(0,re.jsxs)("div",{className:"flex items-center mb-2",children:[(0,re.jsx)("h2",{className:"text-xl font-semibold text-slate-900",children:"Required API Keys"}),(0,re.jsx)(ej,{children:"API keys that users will need to configure to use this integration."})]}),(0,re.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,re.jsxs)(Xn,{className:"border-slate-200 shadow-sm mb-4",children:[(0,re.jsxs)(Qn,{className:"pb-0",children:[(0,re.jsx)(er,{className:"text-base font-medium",children:"Add API Keys"}),(0,re.jsx)(sr,{children:"Specify the API keys users will need to configure to use your integration"})]}),(0,re.jsx)(tr,{className:"pt-4",children:(0,re.jsxs)("div",{className:"grid grid-cols-1 gap-4",children:[(0,re.jsxs)("div",{children:[(0,re.jsx)(uu,{htmlFor:"newSecretName",className:"mb-1 block",children:"Secret Name"}),(0,re.jsx)(fn,{id:"newSecretName",placeholder:"E.g., OPENAI_API_KEY",value:j,onChange:e=>y(e.target.value)}),(0,re.jsx)("p",{className:"text-xs text-slate-500 mt-1",children:"This is the environment variable name used in code"})]}),(0,re.jsxs)("div",{children:[(0,re.jsx)(uu,{htmlFor:"newSecretDescription",className:"mb-1 block",children:"Instructions for obtaining"}),(0,re.jsx)(fn,{id:"newSecretDescription",placeholder:"E.g., Get from platform.openai.com/api-keys",value:N,onChange:e=>w(e.target.value)}),(0,re.jsx)("p",{className:"text-xs text-slate-500 mt-1",children:"Help users understand where to find this key"})]})]})}),(0,re.jsx)(ar,{className:"border-t pt-4 bg-slate-50",children:(0,re.jsxs)(Yn,{type:"button",onClick:()=>{if(j.trim()){const e={name:j.trim(),description:N.trim()};p(s=>(0,K.A)((0,K.A)({},s),{},{required_secrets:[...s.required_secrets,e]})),y(""),w("")}},className:"w-full bg-teal-600 hover:bg-teal-700",children:[(0,re.jsx)(Zb.A,{className:"h-4 w-4 mr-2"})," Add API Key"]})})]}),h.required_secrets.length>0?(0,re.jsx)("div",{className:"space-y-3",children:h.required_secrets.map((e,s)=>(0,re.jsxs)("div",{className:"bg-white rounded-lg p-4 border flex justify-between items-start",children:[(0,re.jsxs)("div",{children:[(0,re.jsxs)("div",{className:"flex items-center",children:[(0,re.jsx)(vt.A,{className:"h-4 w-4 text-slate-600 mr-2"}),(0,re.jsx)("h4",{className:"font-medium text-slate-900",children:e.name})]}),(0,re.jsx)("p",{className:"text-sm text-slate-600 mt-1 ml-6",children:e.description||"Required for this integration"})]}),(0,re.jsx)(Yn,{variant:"ghost",size:"sm",onClick:()=>(e=>{p(s=>(0,K.A)((0,K.A)({},s),{},{required_secrets:s.required_secrets.filter((s,t)=>t!==e)}))})(s),className:"text-red-500 hover:text-red-700 hover:bg-red-50",children:(0,re.jsx)(_u.A,{className:"h-4 w-4"})})]},s))}):(0,re.jsxs)("div",{className:"bg-slate-50 p-5 rounded-lg border text-center",children:[(0,re.jsx)(vt.A,{className:"h-10 w-10 text-slate-400 mx-auto mb-2"}),(0,re.jsx)("p",{className:"text-slate-600 mb-1",children:"No API keys added yet"}),(0,re.jsx)("p",{className:"text-sm text-slate-500",children:"Add keys if your integration requires external API access"})]})]}),(0,re.jsxs)("div",{className:"mb-8",children:[(0,re.jsxs)("div",{className:"flex items-center mb-2",children:[(0,re.jsx)("h2",{className:"text-xl font-semibold text-slate-900",children:"Integration Prompt"}),(0,re.jsx)(ej,{children:"The implementation guide for your integration."})]}),(0,re.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,re.jsxs)("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-6",children:[(0,re.jsx)("div",{className:"lg:col-span-2",children:(0,re.jsxs)(Xn,{className:"h-full",children:[(0,re.jsxs)(Qn,{className:"pb-2",children:[(0,re.jsx)(er,{className:"text-base font-medium",children:"Implementation Guide"}),(0,re.jsx)(sr,{children:"Provide detailed instructions on how to use this integration"})]}),(0,re.jsxs)(tr,{children:[(0,re.jsx)(du,{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,re.jsxs)("div",{className:"flex justify-between items-center mt-2 text-xs",children:[(0,re.jsx)("div",{className:"text-slate-500",children:(0,re.jsx)("span",{children:"Supports Markdown formatting"})}),(0,re.jsx)("div",{children:(0,re.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,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(zs.A,{className:"h-3 w-3 mr-1"}),h.prompt.length,"/50 characters (minimum)"]}):(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(Pt.A,{className:"h-3 w-3 mr-1"}),h.prompt.length," characters"]})})})]})]})]})}),(0,re.jsx)("div",{className:"lg:col-span-1",children:(0,re.jsxs)(Xn,{className:"bg-slate-50 border border-slate-200 h-full",children:[(0,re.jsxs)(Qn,{className:"pb-2",children:[(0,re.jsxs)(er,{className:"text-base font-medium flex items-center text-slate-700",children:[(0,re.jsx)(jo.A,{className:"h-4 w-4 mr-2 text-teal-600"}),"Tips for writing effective prompts"]}),(0,re.jsx)(sr,{children:"Guidelines to help users implement your integration"})]}),(0,re.jsxs)(tr,{className:"space-y-4",children:[(0,re.jsxs)("div",{children:[(0,re.jsx)("h4",{className:"font-medium text-slate-800 mb-1",children:"Structure your guide clearly"}),(0,re.jsxs)("ul",{className:"space-y-2 text-sm text-slate-600 list-disc pl-5",children:[(0,re.jsx)("li",{children:"Start with an introduction explaining what the integration does"}),(0,re.jsx)("li",{children:"Include complete code examples with explanations"}),(0,re.jsx)("li",{children:"Provide configuration and setup instructions"})]})]}),h.requires_backend_functions&&(0,re.jsxs)("div",{children:[(0,re.jsx)("h4",{className:"font-medium text-slate-800 mb-1",children:"Backend Function Tips"}),(0,re.jsxs)("ul",{className:"space-y-2 text-sm text-slate-600 list-disc pl-5",children:[(0,re.jsxs)("li",{children:["Show how to implement with ",(0,re.jsx)("strong",{children:"Deno serve"})," (this is how backend functions run)"]}),(0,re.jsx)("li",{children:"Document the output schema for each function"}),(0,re.jsx)("li",{children:"Include examples of how to call these functions from frontend components"}),(0,re.jsx)("li",{children:"Provide error handling guidance"})]})]}),(0,re.jsxs)("div",{children:[(0,re.jsx)("h4",{className:"font-medium text-slate-800 mb-1",children:"Recommended sections"}),(0,re.jsxs)("ul",{className:"space-y-2 text-sm text-slate-600 list-disc pl-5",children:[(0,re.jsxs)("li",{children:[(0,re.jsx)("strong",{children:"Introduction:"})," What the integration does"]}),(0,re.jsxs)("li",{children:[(0,re.jsx)("strong",{children:"API Reference:"})," Available functions and parameters"]}),(0,re.jsxs)("li",{children:[(0,re.jsx)("strong",{children:"Example Usage:"})," Practical implementation examples"]}),(0,re.jsxs)("li",{children:[(0,re.jsx)("strong",{children:"Troubleshooting:"})," Common issues and solutions"]})]})]}),(0,re.jsxs)("div",{className:"bg-blue-50 p-3 rounded-md text-sm text-blue-700 border border-blue-100",children:[(0,re.jsx)("p",{className:"font-medium mb-1",children:"Pro Tip"}),(0,re.jsx)("p",{children:"The better your documentation, the more likely users will successfully implement your integration!"})]})]})]})})]})]}),(0,re.jsxs)("div",{className:"flex justify-between pt-4 border-t",children:[(0,re.jsxs)(Yn,{onClick:()=>f("metadata"),variant:"outline",children:[(0,re.jsx)(Cc.A,{className:"h-4 w-4 mr-2"}),"Back to Metadata"]}),(0,re.jsx)(Yn,{onClick:()=>A(),disabled:o,className:"bg-teal-600 hover:bg-teal-700",children:o?(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(Ze.A,{className:"h-4 w-4 mr-2 animate-spin"}),"Saving..."]}):(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(ah.A,{className:"h-4 w-4 mr-2"}),"Save Integration"]})})]})]})})]})})]})};function tj(e){let{isHowToModalOpen:s,setIsHowToModalOpen:t}=e;return(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)("h1",{className:"text-5xl font-base44 font-medium mb-4 mt-6",children:"App Templates"}),(0,re.jsxs)(to,{open:s,onOpenChange:t,children:[(0,re.jsxs)("p",{className:"text-lg font-base44 max-w-2xl mb-4",children:["Explore a curated collection of applications built by our community."," ",(0,re.jsx)(ao,{asChild:!0,children:(0,re.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,re.jsxs)(lo,{className:"max-w-2xl",children:[(0,re.jsx)(io,{children:(0,re.jsx)(co,{className:"text-xl font-semibold text-slate-900",children:"How to Share Your App with the Community"})}),(0,re.jsxs)("div",{className:"space-y-6 pt-2",children:[(0,re.jsx)("p",{className:"text-slate-600 leading-relaxed",children:"Follow these simple steps:"}),(0,re.jsxs)("div",{className:"space-y-4",children:[(0,re.jsxs)("div",{className:"flex items-start gap-3 p-4 rounded-xl bg-slate-50 border border-slate-200",children:[(0,re.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,re.jsxs)("div",{className:"space-y-1",children:[(0,re.jsx)("p",{className:"font-medium text-slate-900",children:"Open your app's builder"}),(0,re.jsx)("p",{className:"text-sm text-slate-600",children:"Navigate to an app you created or have admin access to"})]})]}),(0,re.jsx)("div",{className:"flex items-center justify-center",children:(0,re.jsx)(Sc.A,{className:"w-4 h-4 text-slate-400"})}),(0,re.jsxs)("div",{className:"flex items-start gap-3 p-4 rounded-xl bg-slate-50 border border-slate-200",children:[(0,re.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,re.jsxs)("div",{className:"space-y-1",children:[(0,re.jsx)("p",{className:"font-medium text-slate-900",children:"Go to catalog settings"}),(0,re.jsx)("p",{className:"text-sm text-slate-600",children:(0,re.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,re.jsx)("div",{className:"flex items-center justify-center",children:(0,re.jsx)(Sc.A,{className:"w-4 h-4 text-slate-400"})}),(0,re.jsxs)("div",{className:"flex items-start gap-3 p-4 rounded-xl bg-slate-50 border border-slate-200",children:[(0,re.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,re.jsxs)("div",{className:"space-y-1",children:[(0,re.jsx)("p",{className:"font-medium text-slate-900",children:"Publish your listing"}),(0,re.jsx)("p",{className:"text-sm text-slate-600",children:"Add a description, screenshots, and configure your listing visibility"})]})]})]}),(0,re.jsx)("div",{className:"p-4 rounded-xl bg-orange-50 border border-orange-200",children:(0,re.jsxs)("p",{className:"text-sm text-orange-800",children:[(0,re.jsx)("strong",{children:"Tip:"})," Make sure your app is deployed and has an engaging description to attract more users!"]})})]})]})]})]})}function aj(e){if(!e)return"";const s=document.createElement("div");return s.innerHTML=e,s.textContent||s.innerText||""}const nj=function(){const{user:e}=oe(),[s,t]=(0,H.useState)([]),[a,n]=(0,H.useState)(!0),[r,l]=(0,H.useState)(""),[i,o]=(0,H.useState)("all"),[c,d]=(0,H.useState)(Un),[m,u]=(0,H.useState)(zn),[x,h]=(0,H.useState)("en"),[p,g]=(0,H.useState)(new Set),[f,v]=(0,H.useState)(!1),[b,j]=(0,H.useState)(!0),[y,N]=(0,H.useState)(!1),[w,_]=(0,H.useState)(0),[k]=(0,H.useState)(20),[A,S]=(0,H.useState)(0),[C,E]=(0,H.useState)(null),[I,T]=(0,H.useState)(!1);(0,H.useEffect)(()=>{const e=new URLSearchParams(window.location.search).get("category");if(e){const s=Mn.find(s=>s.toLowerCase()===e.toLowerCase());s?o(s):"my-apps"===e.toLowerCase()&&o("my-apps")}},[]),(0,H.useEffect)(()=>{const e=e=>{I&&("ArrowLeft"===e.key?D():"ArrowRight"===e.key&&M())};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[I,C]),(0,H.useEffect)(()=>{t([]),S(0),j(!0),P(!0)},[r,i,c,m,x]);const P=(0,H.useCallback)(async function(){let s=arguments.length>0&&void 0!==arguments[0]&&arguments[0];try{s?n(!0):N(!0);const a=s?0:A;let l={skip:a,limit:k,sort_by:L(m),categories:"all"!==i&&"my-apps"!==i?[i]:void 0};"me"===c||"my-apps"===i?l.created_by=e.email:"not_me"===c&&(l.created_by={$ne:e.email}),r&&"en"===x?l.$and=[{$or:[{name:{$regex:r,$options:"i"}},{description:{$regex:r,$options:"i"}},{categories:{$regex:r,$options:"i"}},{tags:{$regex:r,$options:"i"}},{created_by:{$regex:r,$options:"i"}}]},{$or:[{language:"en"},{language:{$exists:!1}},{language:null}]}]:r?(l.$or=[{name:{$regex:r,$options:"i"}},{description:{$regex:r,$options:"i"}},{categories:{$regex:r,$options:"i"}},{tags:{$regex:r,$options:"i"}},{created_by:{$regex:r,$options:"i"}}],x&&"en"!==x&&(l.language=x)):x&&("en"===x?l.$or=[{language:"en"},{language:{$exists:!1}},{language:null}]:l.language=x),Object.keys(l).forEach(e=>{void 0===l[e]&&delete l[e]});const o=await $a.listCatalogItems(l),d=o.items||o,u=o.total||d.length;s?(t(d),_(u)):t(e=>[...e,...d]),S(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(s?h:e=>new Set([...e,...h]))}catch(a){an({title:"Error",description:"Failed to load catalog items",variant:"destructive"})}finally{n(!1),N(!1)}},[A,k,i,r,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,H.useCallback)(()=>{!b||y||a||P(!1)},[b,y,a,P]),{targetRef:R}=Tb({onLoadMore:O,hasMore:b,isLoading:y||a}),D=()=>{const e=s.findIndex(e=>e.item.id===C.item.id);e>0&&E(s[e-1])},M=()=>{const e=s.findIndex(e=>e.item.id===C.item.id);e0?"Showing ".concat(F," of ").concat(w," items"):"";return(0,re.jsxs)("div",{className:"px-12 max-w-[1600px] mx-auto",children:[(0,re.jsx)(tj,{}),(0,re.jsx)(qn,{searchTerm:r,onSearchChange:e=>{l(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,re.jsx)(gr,{isLoading:a,isLoadingMore:y,items:s,upvotedItems:p,onCardClick:e=>{E(e),T(!0)},onUpvote:async(e,s)=>{e.stopPropagation();try{await $a.upvoteItem(s),g(e=>new Set([...e,s])),t(e=>e.map(e=>e.item.id===s?(0,K.A)((0,K.A)({},e),{},{upvotes:e.upvotes+1,did_current_user_upvote:!0}):e)),C&&C.item.id===s&&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:aj,hasMore:b,targetRef:R}),(0,re.jsx)(hn,{isOpen:I,onClose:()=>{T(!1),E(null)},selectedItem:C,filteredItems:s,onPrevious:D,onNext:M,upvotedItems:p,onUpvote:e=>{g(s=>new Set([...s,e])),t(s=>s.map(s=>s.item.id===e?(0,K.A)((0,K.A)({},s),{},{upvotes:s.upvotes+1,did_current_user_upvote:!0}):s))},onItemUpdate:e=>{E(e)}})]})};function rj(){const{user:e}=oe(),{appId:s}=(0,Z.g)(),t=(0,Z.Zp)(),[a,n]=(0,H.useState)(!0),[r,l]=(0,H.useState)(!1),[i,o]=(0,H.useState)(null),[c,d]=(0,H.useState)(null),[m,u]=(0,H.useState)({}),[x,h]=(0,H.useState)(!1),p=new URLSearchParams(window.location.search).get("clone_history"),g=(0,H.useCallback)(()=>{l(!0),o(null),ve.remixApp(s,{with_chat_history:"true"===p,secret_values:m}).then(e=>{t("/apps/".concat(e.id,"/editor/preview"))}).catch(e=>{o(e.message||"An error occurred while cloning the app"),l(!1)})},[s,m,t]);(0,H.useEffect)(()=>{n(!0),ve.remixAppRequirements(s).then(s=>{d(s);s&&(!s.app_secret_names||0===s.app_secret_names.length)&&!(s.requires_backend_functions&&("free"===e.subscription_tier||"starter"===e.subscription_tier))?g():s&&s.app_secret_names&&s.app_secret_names.length>0&&(!s.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)})},[s,e.subscription_tier]);return a?(0,re.jsx)("div",{className:"fixed inset-0 flex items-center justify-center",children:(0,re.jsx)("div",{className:"flex flex-col items-center space-y-4",children:(0,re.jsx)(Ze.A,{className:"h-8 w-8 animate-spin"})})}):r?(0,re.jsx)("div",{className:"fixed inset-0 flex items-center justify-center",children:(0,re.jsxs)("div",{className:"flex flex-col items-center space-y-4",children:[(0,re.jsx)("div",{className:"w-12 h-12 border-4 border-gray-200 border-t-black rounded-full animate-spin"}),(0,re.jsxs)("p",{className:"text-gray-600",children:["Cloning ",(null==c?void 0:c.name)||"app","..."]})]})}):i?(0,re.jsx)("div",{className:"fixed inset-0 flex items-center justify-center",children:(0,re.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,re.jsx)(Xe.A,{className:"h-12 w-12 text-red-500"}),(0,re.jsx)("div",{className:"text-red-600 text-lg font-medium",children:"Error"}),(0,re.jsx)("p",{className:"text-gray-600 text-center",children:i}),(0,re.jsx)(Hs,{onClick:()=>t(-1),variant:"outline",children:"Go Back"})]})}):c&&c.requires_backend_functions&&("free"===e.subscription_tier||"starter"===e.subscription_tier)?(0,re.jsx)("div",{className:"fixed inset-0 flex items-center justify-center",children:(0,re.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,re.jsx)(Xe.A,{className:"h-12 w-12 text-red-500"}),(0,re.jsx)("div",{className:"text-red-600 text-lg font-medium",children:"Clone Not Allowed"}),(0,re.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,re.jsx)(Hs,{onClick:()=>t(-1),variant:"outline",children:"Go Back"})]})}):(0,re.jsx)("div",{className:"container mx-auto p-4 pt-10 max-w-2xl",children:x?(0,re.jsxs)("div",{className:"mb-6 p-6 border rounded-lg bg-slate-50",children:[(0,re.jsxs)("h1",{className:"text-2xl font-semibold mb-6",children:["Clone ",(null==c?void 0:c.name)||"App"]}),(0,re.jsx)("h2",{className:"text-lg font-medium mb-4 text-slate-700",children:"Configure Secrets"}),(0,re.jsx)(Kt,{secretNames:c.app_secret_names.map(e=>({name:e})),value:m,onChange:e=>{u(e)}}),(0,re.jsx)(Hs,{onClick:g,disabled:r,className:"w-full mt-4",children:r?"Cloning ".concat((null==c?void 0:c.name)||"App","..."):"Clone ".concat((null==c?void 0:c.name)||"App")})]}):(0,re.jsx)("div",{className:"fixed inset-0 flex items-center justify-center",children:(0,re.jsxs)("div",{className:"flex flex-col items-center space-y-4",children:[(0,re.jsx)("div",{className:"w-12 h-12 border-4 border-gray-200 border-t-black rounded-full animate-spin"}),(0,re.jsx)("p",{className:"text-gray-600",children:"Preparing..."})]})})})}var lj=t(35219),ij=t(97104);const oj=e=>{let{className:s}=e;return(0,re.jsx)("svg",{className:s,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:(0,re.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"})})},cj=e=>{let{icon:s,title:t,description:a,action:n,variant:r="default",external:l=!1}=e;return(0,re.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,children:[(0,re.jsx)("div",{className:"absolute inset-0 transition-all duration-500 ".concat("primary"===r?"bg-gradient-to-br from-orange-500 to-orange-600 group-hover:from-orange-600 group-hover:to-orange-700":"secondary"===r?"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,re.jsxs)("div",{className:"relative z-10 p-8 text-white",children:[(0,re.jsxs)("div",{className:"flex items-start justify-between mb-6",children:[(0,re.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,re.jsx)(s,{className:"w-7 h-7"})}),l&&(0,re.jsx)(jl.A,{className:"w-5 h-5 opacity-60 group-hover:opacity-100 transition-opacity"})]}),(0,re.jsxs)("div",{className:"space-y-3",children:[(0,re.jsx)("h3",{className:"text-xl font-bold leading-tight",children:t}),(0,re.jsx)("p",{className:"text-white/80 text-sm leading-relaxed",children:a})]}),(0,re.jsxs)("div",{className:"mt-6 inline-flex items-center text-sm font-semibold group-hover:translate-x-1 transition-transform duration-300",children:[(0,re.jsx)("span",{children:"Get Started"}),(0,re.jsx)(ha.A,{className:"w-4 h-4 ml-2"})]})]})]})},dj=e=>{let{icon:s,title:t,description:a,action:n,count:r}=e;return(0,re.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,re.jsxs)("div",{className:"flex items-start space-x-4",children:[(0,re.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,re.jsx)(s,{className:"w-6 h-6"})}),(0,re.jsxs)("div",{className:"flex-1",children:[(0,re.jsxs)("div",{className:"flex items-center justify-between mb-1",children:[(0,re.jsx)("h4",{className:"font-semibold text-slate-900",children:t}),void 0!==r&&(0,re.jsx)("span",{className:"text-sm font-medium text-slate-500",children:r})]}),(0,re.jsx)("p",{className:"text-sm text-slate-600",children:a})]}),(0,re.jsx)(ha.A,{className:"w-5 h-5 text-slate-400 group-hover:text-slate-600 group-hover:translate-x-1 transition-all"})]})})};function mj(e){let{appId:s}=e;const[t]=(0,J.useSearchParams)(),a=(0,Z.Zp)(),[n,r]=(0,H.useState)(s);(0,H.useEffect)(()=>{const e=t.get("appId");r(e||s)},[t,s]);return(0,re.jsx)(re.Fragment,{children:(0,re.jsxs)("div",{className:"w-full max-w-7xl mx-auto px-6 py-12",children:[(0,re.jsx)("div",{className:"text-center mb-16",children:(0,re.jsxs)("div",{className:"space-y-4",children:[(0,re.jsx)("h1",{className:"text-5xl font-bold text-slate-900 tracking-tight",children:"Help & Support"}),(0,re.jsx)("div",{className:"w-24 h-1 bg-gradient-to-r from-orange-500 to-teal-500 mx-auto rounded-full"}),(0,re.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,re.jsx)("div",{className:"mb-12 p-6 bg-slate-50 border border-slate-200 rounded-xl",children:(0,re.jsxs)("div",{className:"flex items-center space-x-3",children:[(0,re.jsx)("div",{className:"w-10 h-10 bg-slate-100 text-slate-600 rounded-lg flex items-center justify-center",children:(0,re.jsx)(lj.A,{className:"w-5 h-5"})}),(0,re.jsxs)("div",{children:[(0,re.jsx)("h3",{className:"font-semibold text-slate-900",children:"App-Specific Support"}),(0,re.jsxs)("p",{className:"text-sm text-slate-600",children:["Support requests will be associated with app: ",(0,re.jsx)("span",{className:"font-mono bg-slate-100 px-2 py-1 rounded text-slate-800",children:n})]})]})]})}),(0,re.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-8 mb-16",children:[(0,re.jsx)(cj,{icon:Hg.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,re.jsx)(cj,{icon:oj,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,re.jsx)(cj,{icon:ij.A,title:"Open Support Ticket",description:"Submit a detailed support ticket and get personalized assistance.",action:()=>{const e=new URLSearchParams({openNew:"true"});n&&e.set("appId",n),a("/support/conversations?".concat(e.toString()))},variant:"default"})]}),(0,re.jsxs)("div",{className:"bg-slate-50 rounded-2xl p-8",children:[(0,re.jsxs)("div",{className:"mb-6",children:[(0,re.jsx)("h2",{className:"text-2xl font-bold text-slate-900 mb-2",children:"Quick Actions"}),(0,re.jsx)("p",{className:"text-slate-600",children:"Manage your support experience"})]}),(0,re.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[(0,re.jsx)(dj,{icon:bl.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,re.jsx)(dj,{icon:Gr.A,title:"Community Forum",description:"Our brand-new reddit community",action:()=>{window.open("https://www.reddit.com/r/Base44","_blank")}})]})]})]})})}var uj=t(82981),xj=t(83655);class hj extends X.y{getBaseURL(){return"/support/conversations"}async addMessage(e,s){return await this.axios.post("/".concat(e,"/messages"),s)}async updateConversationNotifications(e,s){return await this.axios.put("/".concat(e,"/notifications"),s)}async closeTicket(e){return await this.axios.patch("/".concat(e,"/close"))}}const pj=new hj;class gj extends X.H{getBaseURL(){return"/support/admin"}async getTickets(e){const s=Object.fromEntries(Object.entries(e||{}).filter(e=>{let[s,t]=e;return null!==t}));return await this.axios.get("",{params:s})}async getTicketDetail(e){return await this.axios.get("/".concat(e))}async updateTicketStatus(e,s){return await this.axios.patch("/".concat(e,"/status"),{status:s})}async polishResponse(e,s){return await this.axios.post("/".concat(e,"/messages/polish"),{text:s})}async changeTicketStatus(e,s){return await this.axios.patch("/".concat(e,"/change_ticket_status"),{status:s})}async assignTicket(e,s){return await this.axios.patch("/".concat(e,"/assign"),{user_email:s})}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,s){return await this.axios.patch("/".concat(e,"/internal_categories"),{internal_categories:s})}async updateInternalNotes(e,s){return await this.axios.patch("/".concat(e,"/internal_notes"),{internal_notes:s})}async updateTicketCategory(e,s){return await this.axios.patch("/".concat(e,"/category"),{category:s})}async resolveMany(e){return await this.axios.patch("/resolve-many",{ticket_ids:e})}async deleteMessage(e,s){return await this.axios.delete("/".concat(e,"/messages"),{data:{message_id:s}})}}const fj=new gj;class vj extends X.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,s){return await this.axios.put("/articles/".concat(e),s)}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 bj=new vj;class jj extends X.H{getBaseURL(){return"/support/analytics"}async exportTicketsCSV(e,s){let t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;const a={start_date:e,end_date:s};t&&(a.category=t);const n=await this.axios.get("/export-csv",{params:a,responseType:"blob"}),r=window.URL.createObjectURL(new Blob([n])),l=document.createElement("a");return l.href=r,l.setAttribute("download","support_tickets_".concat(e.split("T")[0],"_").concat(s.split("T")[0],".csv")),document.body.appendChild(l),l.click(),l.remove(),window.URL.revokeObjectURL(r),n}async runTrendAnalysis(e,s){let t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;const a={start_date:e,end_date:s};return t&&(a.category=t),await this.axios.post("/trend-analysis",a)}async getOperationalMetrics(e,s){const t={start_date:e,end_date:s};return await this.axios.get("/operational-metrics",{params:t})}}const yj=new jj;class Nj extends X.H{getBaseURL(){return"/support/bot"}async requestAnswer(e,s,t){let a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:[];return await this.axios.post("/request",{title:e,content:s,category:t,file_urls:a})}async logAnswer(e,s,t){let a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null;return await this.axios.post("/log_answer",{support_ticket_id:e,answer:s,is_useful:t,ticket_body:a})}}const wj=new Nj;class _j extends X.y{getBaseURL(){return"/support/agents"}updateRecord(e,s){return this.axios.post("/realtime/".concat(e,"/").concat(s))}}const kj=new _j;var Aj=t(59027),Sj=t(62702);const Cj=e=>{let{imageUrl:s,isOpen:t,onClose:a}=e;return t?(0,re.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center",children:[(0,re.jsx)("div",{className:"absolute inset-0 bg-black/80 backdrop-blur-sm",onClick:a}),(0,re.jsxs)("div",{className:"relative z-10 max-w-7xl max-h-[90vh] mx-4",children:[(0,re.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,re.jsx)(zs.A,{size:20})}),(0,re.jsx)("img",{src:s,alt:"Full size image",className:"max-w-full max-h-[90vh] object-contain rounded-lg shadow-2xl"})]})]}):null},Ej=e=>{var s,t,a;let{message:n,onImageClick:r,isAdmin:l=!1,conversationId:i,onMessageDeleted:o}=e;const c="user"===n.role,d=null===(s=n.additional_message_params)||void 0===s?void 0:s.is_admin_message,m=null===(t=n.metadata)||void 0===t?void 0:t.created_by_full_name,[u,x]=(0,H.useState)(!1),[h,p]=(0,H.useState)(!1);return(0,re.jsx)("div",{className:"flex ".concat(c?"justify-end":"justify-start"," mb-4"),onMouseEnter:()=>p(!0),onMouseLeave:()=>p(!1),children:(0,re.jsxs)("div",{className:"flex max-w-[80%] ".concat(c?"flex-row-reverse":"flex-row"," items-start space-x-3 relative"),children:[(0,re.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,re.jsx)(np.A,{size:16}):d?(0,re.jsx)(rp.A,{size:16}):(0,re.jsx)(fd.A,{size:16})}),(0,re.jsxs)("div",{className:"flex flex-col ".concat(c?"items-end":"items-start"),children:[d&&m&&(0,re.jsxs)("div",{className:"mb-2 flex items-center space-x-2",children:[(0,re.jsx)("div",{className:"text-xs font-medium text-slate-700",children:m.split(" ")[0]}),(0,re.jsx)("div",{className:"w-1 h-1 bg-slate-300 rounded-full"}),(0,re.jsx)("div",{className:"text-xs text-slate-500",children:"Support Team"})]}),(0,re.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,re.jsx)("div",{className:"mb-3 flex flex-wrap gap-3",children:n.file_urls.map((e,s)=>(0,re.jsx)("div",{className:"relative",children:e.match(/\.(jpg|jpeg|png|gif|webp)$/i)?(0,re.jsxs)("div",{className:"relative group cursor-pointer",onClick:()=>r(e),children:[(0,re.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,re.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,re.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,re.jsx)(Sj.A,{size:16,className:"text-slate-700"})})})]}):(0,re.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,re.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,re.jsx)("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),(0,re.jsx)("polyline",{points:"14 2 14 8 20 8"})]}),(0,re.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"})]})},s))}),(0,re.jsx)("div",{className:"text-sm leading-relaxed prose prose-sm max-w-[550px]",children:(0,re.jsx)(el.oz,{components:{p:e=>{let{children:s}=e;return(0,re.jsx)("p",{className:"mb-2 last:mb-0",children:s})},ul:e=>{let{children:s}=e;return(0,re.jsx)("ul",{className:"list-disc list-inside mb-2 last:mb-0",children:s})},ol:e=>{let{children:s}=e;return(0,re.jsx)("ol",{className:"list-decimal list-inside mb-2 last:mb-0",children:s})},li:e=>{let{children:s}=e;return(0,re.jsx)("li",{className:"mb-1",children:s})},code:e=>{let{children:s,inline:t}=e;return t?(0,re.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:s}):(0,re.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,re.jsx)("code",{children:s})})},blockquote:e=>{let{children:s}=e;return(0,re.jsx)("blockquote",{className:"border-l-4 pl-3 italic ".concat(c?"border-slate-400":"border-slate-300"),children:s})},strong:e=>{let{children:s}=e;return(0,re.jsx)("strong",{className:"font-semibold",children:s})},em:e=>{let{children:s}=e;return(0,re.jsx)("em",{className:"italic",children:s})},h1:e=>{let{children:s}=e;return(0,re.jsx)("h1",{className:"text-lg font-bold mb-2",children:s})},h2:e=>{let{children:s}=e;return(0,re.jsx)("h2",{className:"text-base font-bold mb-2",children:s})},h3:e=>{let{children:s}=e;return(0,re.jsx)("h3",{className:"text-sm font-bold mb-1",children:s})}},children:n.content})})]}),(0,re.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,re.jsx)("div",{className:"text-xs text-slate-500",children:(g=n.metadata.created_date,la().utc(g).fromNow())}),l&&!c&&"assistant"===n.role&&h&&(0,re.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 fj.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,re.jsx)("div",{className:"animate-spin rounded-full h-3 w-3 border-b-2 border-red-400"}):(0,re.jsx)(_u.A,{size:14})})]})]})]})});var g},Ij=()=>(0,re.jsx)("div",{className:"flex justify-start mb-4",children:(0,re.jsxs)("div",{className:"flex items-start space-x-3",children:[(0,re.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,re.jsx)(fd.A,{size:16})}),(0,re.jsx)("div",{className:"bg-white text-slate-900 border border-slate-200 shadow-sm rounded-2xl px-4 py-3",children:(0,re.jsxs)("div",{className:"flex space-x-1",children:[(0,re.jsx)("div",{className:"w-2 h-2 bg-slate-400 rounded-full animate-bounce"}),(0,re.jsx)("div",{className:"w-2 h-2 bg-slate-400 rounded-full animate-bounce",style:{animationDelay:"0.1s"}}),(0,re.jsx)("div",{className:"w-2 h-2 bg-slate-400 rounded-full animate-bounce",style:{animationDelay:"0.2s"}})]})})]})});function Tj(e){let{messages:s,isTyping:t,isAdmin:a=!1,conversationId:n,onMessageDeleted:r}=e;const l=(0,H.useRef)(null),[i,o]=(0,H.useState)(null);(0,H.useEffect)(()=>{var e;null===(e=l.current)||void 0===e||e.scrollIntoView({behavior:"smooth"})},[s,t]);const c=e=>{o(e)};return(0,re.jsxs)("div",{className:"h-full overflow-y-auto px-4 py-4",children:[0===s.length?(0,re.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,re.jsxs)("div",{className:"text-center",children:[(0,re.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,re.jsx)(fd.A,{size:24})}),(0,re.jsx)("h3",{className:"text-lg font-medium text-slate-900 mb-2",children:"Start the conversation"}),(0,re.jsx)("p",{className:"text-slate-600",children:"Send a message to begin your support conversation"})]})}):(0,re.jsxs)("div",{className:"space-y-4",children:[s.map((e,s)=>(0,re.jsx)(Ej,{message:e,onImageClick:c,isAdmin:a,conversationId:n,onMessageDeleted:r},e.id||s)),t&&(0,re.jsx)(Ij,{}),(0,re.jsx)("div",{ref:l})]}),i&&(0,re.jsx)(Cj,{imageUrl:i,isOpen:!!i,onClose:()=>o(null)})]})}const Pj="support_templates",Lj=()=>{try{const e=localStorage.getItem(Pj);return e?JSON.parse(e):[]}catch(e){return[]}},Oj=e=>{let{onTemplateSelect:s,className:t=""}=e;const[a,n]=(0,H.useState)([]),[r,l]=(0,H.useState)(!1),[i,o]=(0,H.useState)(!0);if((0,H.useEffect)(()=>{n(Lj());const e=e=>{e.key===Pj&&n(Lj())};window.addEventListener("storage",e);const s=()=>{n(Lj())};return window.addEventListener("templatesUpdated",s),()=>{window.removeEventListener("storage",e),window.removeEventListener("templatesUpdated",s)}},[]),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=r?a:a.slice(0,10);return(0,re.jsxs)("div",{className:"space-y-2 ".concat(t),children:[(0,re.jsxs)("div",{className:"flex items-center justify-between mb-1",children:[(0,re.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,re.jsx)(al.A,{className:"w-3 h-3 text-slate-500"}),(0,re.jsx)("span",{className:"text-xs font-medium text-slate-700",children:"Quick Templates"}),(0,re.jsxs)("span",{className:"text-xs text-slate-500",children:["(",a.length,")"]})]}),(0,re.jsx)(Hs,{variant:"ghost",size:"sm",onClick:()=>o(!1),className:"h-5 w-5 p-0 text-slate-400 hover:text-slate-600",children:(0,re.jsx)(zs.A,{className:"w-3 h-3"})})]}),(0,re.jsxs)("div",{className:"flex flex-wrap gap-2",children:[m.map((e,t)=>{const a=c[t%c.length];return(0,re.jsx)("button",{onClick:()=>s(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,re.jsxs)("button",{onClick:()=>l(!r),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,re.jsx)(kr.A,{className:"w-3 h-3"}),(0,re.jsx)("span",{children:r?"Less":"+".concat(a.length-10)}),r?(0,re.jsx)(Tt.A,{className:"w-3 h-3"}):(0,re.jsx)(It.A,{className:"w-3 h-3"})]})]})]})};function Rj(e){var s;let{conversationId:t,isAdmin:a=!1,onMessageSent:n}=e;const{user:r}=oe(),[l,i]=(0,H.useState)(null),[o,c]=(0,H.useState)(!1),[d,m]=(0,H.useState)(null),[u,x]=(0,H.useState)(!1),[h,p]=(0,H.useState)(!1),[g,f]=(0,H.useState)(""),[v,b]=(0,H.useState)(!1),[j,y]=(0,H.useState)(""),[N,w]=(0,H.useState)([]),[_,k]=(0,H.useState)(!1),[A,S]=(0,H.useState)(!1),[C,E]=(0,H.useState)(!1),[I,T]=(0,H.useState)(!1),P=a?null:500,L=t?"support-draft-".concat(t):"support-draft-temp";(0,H.useEffect)(()=>{if(t&&O(),a){const e=localStorage.getItem(L);y(e||"")}},[t,L,a]),(0,H.useEffect)(()=>{a&&j&&localStorage.setItem(L,j)},[j,a,L]),(0,H.useEffect)(()=>{a&&null!=l&&l.draft&&!h&&(p(!0),f(l.draft),b(!1))},[null==l?void 0:l.draft,a]),(0,H.useEffect)(()=>{void 0!==(null==l?void 0:l.notify_via_email_on_admin_response)&&S(l.notify_via_email_on_admin_response)},[null==l?void 0:l.notify_via_email_on_admin_response]),(0,H.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 pj.fetchAndSubscribe(t,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 fj.polishResponse(t,j);y(e)}catch(d){}finally{k(!1)}};if(o)return(0,re.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,re.jsxs)("div",{className:"text-center",children:[(0,re.jsx)("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-slate-400 mx-auto mb-4"}),(0,re.jsx)("p",{className:"text-slate-600",children:"Loading conversation..."})]})});if(d)return(0,re.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,re.jsxs)("div",{className:"text-center",children:[(0,re.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,re.jsx)(bl.A,{className:"w-8 h-8"})}),(0,re.jsx)("h3",{className:"text-lg font-medium text-slate-900 mb-2",children:"Error Loading Conversation"}),(0,re.jsx)("p",{className:"text-slate-600 mb-4",children:d}),(0,re.jsx)(Hs,{onClick:O,variant:"outline",size:"sm",children:"Try Again"})]})});if(!l)return(0,re.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,re.jsxs)("div",{className:"text-center",children:[(0,re.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,re.jsx)(bl.A,{className:"w-8 h-8"})}),(0,re.jsx)("h3",{className:"text-lg font-medium text-slate-900 mb-2",children:"No Conversation Found"}),(0,re.jsx)("p",{className:"text-slate-600",children:"This conversation doesn't exist or you don't have access to it."})]})});const D="premium"==(((null==r?void 0:r.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"},M="pending_admin_response"===(null==l?void 0:l.status),F=a?(0,re.jsx)(Hs,{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,re.jsx)("div",{className:"animate-spin rounded-full h-4 w-4 border-b-2 border-slate-400"}):(0,re.jsx)($b.A,{className:"w-4 h-4"})}):null;return(0,re.jsxs)("div",{className:"flex flex-col h-full max-h-full overflow-hidden",children:[!a&&l&&(0,re.jsx)("div",{className:"flex-shrink-0 border-b border-slate-200 px-4 py-3 bg-slate-50",children:(0,re.jsxs)("div",{className:"flex items-center justify-between",children:[(0,re.jsxs)("div",{className:"flex items-center space-x-3",children:[(0,re.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,re.jsxs)("div",{children:[(0,re.jsx)("h3",{className:"text-sm font-medium text-slate-900 line-clamp-1",children:l.title||"Support Ticket"}),(0,re.jsx)("p",{className:"text-xs text-slate-500 capitalize",children:(null===(s=l.category)||void 0===s?void 0:s.replace(/_/g," "))||"General"})]})]}),"closed"!==l.status&&"resolved"!==l.ticket_status&&(0,re.jsx)(Hs,{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 pj.closeTicket(t);const e=window.location.pathname;e.includes("/support")&&!e.includes("/support/conversations/")?window.location.reload():(await O(),n&&n({conversationId:t,action:"ticket_closed",role:a?"admin":"user",conversation:l}))}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,re.jsxs)(re.Fragment,{children:[(0,re.jsx)("div",{className:"animate-spin rounded-full h-3 w-3 border-b-2 border-teal-600 mr-1"}),"Closing..."]}):(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(nl.A,{className:"w-3 h-3 mr-1"}),"Close Ticket"]})})]})}),(0,re.jsx)("div",{className:"flex-1 min-h-0 overflow-hidden",children:(0,re.jsx)(Tj,{messages:l.messages||[],isTyping:l.is_bot_writing,isAdmin:a,conversationId:t,onMessageDeleted:async()=>{await O()}})}),(0,re.jsx)("div",{className:"flex-shrink-0",children:a&&h&&g?(0,re.jsx)("div",{className:"px-4 py-2 border-t border-slate-200 bg-teal-50",children:(0,re.jsx)(it,{className:"border-teal-200 bg-white",children:(0,re.jsxs)(mt,{className:"p-3",children:[(0,re.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,re.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,re.jsx)(qb.A,{className:"w-4 h-4 text-teal-600"}),(0,re.jsx)("span",{className:"text-sm font-medium text-teal-800",children:"AI Suggested Response"})]}),(0,re.jsxs)("div",{className:"flex items-center space-x-1",children:[(0,re.jsx)(Hs,{variant:"ghost",size:"sm",onClick:()=>{b(!v)},className:"h-6 px-2 text-xs text-teal-700 hover:bg-teal-100",children:v?(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(Tt.A,{className:"w-3 h-3 mr-1"}),"Collapse"]}):(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(It.A,{className:"w-3 h-3 mr-1"}),"View All"]})}),(0,re.jsx)(Hs,{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,re.jsx)(zs.A,{className:"w-3 h-3"})})]})]}),(0,re.jsxs)("div",{className:"space-y-3",children:[(0,re.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,re.jsx)("pre",{className:"whitespace-pre-wrap font-sans text-xs leading-relaxed",children:g}),!v&&g.length>150&&(0,re.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,re.jsx)("div",{className:"flex items-center",children:(0,re.jsxs)(Hs,{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,re.jsx)(Aj.A,{className:"w-3 h-3 mr-1"}),"Use"]})})]})]})})}):!a&&(0,re.jsx)("div",{className:"px-4 py-3 border-t border-slate-200 bg-slate-50",children:(0,re.jsxs)("div",{className:"p-3 rounded-lg border ".concat(D.color),children:[(0,re.jsxs)("div",{className:"flex items-center space-x-2 mb-2",children:[(0,re.jsx)("div",{className:"w-2 h-2 rounded-full bg-current"}),(0,re.jsx)("span",{className:"text-sm font-medium",children:D.tier})]}),(0,re.jsx)("p",{className:"text-xs opacity-80",children:D.message}),M&&(0,re.jsx)("div",{className:"flex items-start space-x-2 mt-2 pt-2 border-t border-current/20",children:(0,re.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,re.jsx)(ed,{id:"email-notifications",checked:A,onCheckedChange:async e=>{try{E(!0),await pj.updateConversationNotifications(t,{notify_via_email_on_admin_response:e}),S(e)}catch(d){S(!e)}finally{E(!1)}},disabled:C,className:"h-3 w-3 data-[state=checked]:bg-slate-600 data-[state=checked]:border-slate-600 border-slate-400 rounded-sm"}),(0,re.jsxs)("label",{htmlFor:"email-notifications",className:"text-xs opacity-80 cursor-pointer flex items-center space-x-1",children:[(0,re.jsx)(Im.A,{className:"w-3 h-3 flex-shrink-0"}),(0,re.jsx)("span",{children:"Notify me when a Base44 representative responds"})]})]})})]})})}),(0,re.jsxs)("div",{className:"flex-shrink-0 p-2",children:[a&&(0,re.jsx)("div",{className:"mb-2",children:(0,re.jsx)(Oj,{onTemplateSelect:e=>{const s=P?e.substring(0,P):e;y(s),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"===l.status?(0,re.jsx)("div",{className:"flex items-center justify-center py-4 text-slate-500 bg-slate-50 rounded-lg border",children:(0,re.jsx)("span",{className:"text-sm",children:"This conversation is closed"})}):"resolved"!==l.ticket_status||a?(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsx)(qs,{value:j,files:N,onSend:async e=>{let s,{text:r,files:l}=e;x(!0);try{s={id:"temp-".concat(Date.now()),role:a?"assistant":"user",content:r,file_urls:l||[],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)||[],s]}));const e=await pj.addMessage(t,{role:a?"assistant":"user",content:r,file_urls:l||[],additional_message_params:a?{is_admin_message:!0}:{}});a&&localStorage.removeItem(L),n&&n({conversationId:t,action:"message_sent",role:a?"admin":"user",conversation:e})}catch(d){var o,c,m,u;if(s&&i(e=>(0,K.A)((0,K.A)({},e),{},{messages:((null==e?void 0:e.messages)||[]).filter(e=>e.id!==s.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"===l.ticket_status&&!a,isProcessing:u,onValueChange:e=>{const s=P?e.substring(0,P):e;y(s)},onFilesChange:w,variant:"default",customButtomRight:F,isAdminMode:a}),P&&(0,re.jsxs)("div",{className:"flex justify-between items-center px-3 py-1 text-xs text-slate-500",children:[(0,re.jsx)("span",{}),(0,re.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,re.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,re.jsx)(nl.A,{className:"w-8 h-8 text-teal-500"}),(0,re.jsxs)("div",{className:"text-center",children:[(0,re.jsx)("p",{className:"text-sm font-medium text-slate-700 mb-1",children:"This ticket has been resolved"}),(0,re.jsx)("p",{className:"text-xs text-slate-500",children:"Please create a new ticket for additional support"})]})]})]})]})}const Dj={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 Mj(e){let{conversationId:s,isOpen:t,onClose:a,ticketTitle:n,ticket:r,onTicketUpdated:l}=e;const{user:i}=oe();return t?(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)("div",{className:"fixed inset-0 bg-black/20 backdrop-blur-sm z-40 transition-opacity duration-300",onClick:a}),(0,re.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(t?"translate-x-0":"translate-x-full"),children:[(0,re.jsxs)("div",{className:"flex-shrink-0 p-4 border-b border-slate-200 bg-white",children:[(0,re.jsxs)("div",{className:"flex items-center justify-between mb-3",children:[(0,re.jsxs)("div",{className:"flex items-center space-x-3 flex-1 min-w-0",children:[(0,re.jsx)(Hs,{variant:"ghost",size:"sm",onClick:a,className:"p-1.5 hover:bg-slate-100",children:(0,re.jsx)(Cc.A,{className:"w-4 h-4"})}),(0,re.jsx)("div",{className:"flex-1 min-w-0",children:(0,re.jsx)("h2",{className:"text-base font-semibold text-slate-900 leading-tight truncate",children:n||"Support Conversation"})})]}),(0,re.jsx)(Hs,{variant:"ghost",size:"sm",onClick:a,className:"p-1.5 hover:bg-slate-100",children:(0,re.jsx)(zs.A,{className:"w-4 h-4"})})]}),(0,re.jsxs)("div",{className:"flex items-center justify-between text-xs text-slate-600",children:[(0,re.jsxs)("div",{className:"flex items-center space-x-3",children:[(0,re.jsxs)("span",{className:"font-mono bg-slate-100 px-2 py-1 rounded text-xs",children:["#",null==s?void 0:s.slice(0,8)]}),(null==r?void 0:r.created_date)&&(0,re.jsxs)("span",{className:"flex items-center space-x-1",children:[(0,re.jsx)(im.A,{className:"w-3 h-3"}),(0,re.jsx)("span",{children:la().utc(r.created_date).fromNow()})]})]}),(0,re.jsxs)("div",{className:"flex items-center space-x-2",children:[(null==r?void 0:r.category)&&(0,re.jsxs)("span",{className:"flex items-center space-x-1 text-xs",children:[(0,re.jsx)("span",{children:Dj[r.category]||"\u{1f4cb}"}),(0,re.jsx)("span",{className:"hidden sm:inline",children:r.category.replace(/_/g," ").replace(/\b\w/g,e=>e.toUpperCase())})]}),(null==r?void 0:r.app_id)&&(0,re.jsxs)("a",{href:"/apps/".concat(r.app_id),className:"flex items-center space-x-1 text-blue-600 hover:text-blue-800 hover:underline",children:[(0,re.jsx)(xj.A,{className:"w-3 h-3"}),(0,re.jsx)("span",{className:"hidden sm:inline",children:"App"}),(0,re.jsx)(jl.A,{className:"w-3 h-3"})]})]})]})]}),(0,re.jsx)(Rj,{conversationId:s,isAdmin:!1,onMessageSent:e=>{l&&null!=e&&e.conversation&&l(s,"message_sent","user",e.conversation)}})]})]}):null}const Fj=["node"],Bj=["node","inline"],Uj=["node"],zj=["node"],qj=["node"],Wj=["node"],Vj=["node"],Yj=["node"],Hj=["node"],Gj=["node"],$j=[{value:"authentication",label:"Authentication",icon:Fs.A},{value:"billing",label:"Billing",icon:Ke.A},{value:"bug_report",label:"Bug Report",icon:uj.A},{value:"integrations_and_backend_functions",label:"Integrations & Backend",icon:ih.A},{value:"chat_issues",label:"Chat Issues",icon:$p.A},{value:"security",label:"Security",icon:rp.A},{value:"social_post_bonus_credits",label:"Social Post Bonus Credits",icon:Yg.A},{value:"other",label:"Other",icon:_h.A}],Jj=["billing","security","social_post_bonus_credits","other"],Zj=(e,s)=>!s&&(e&&!Jj.includes(e));function Kj(e){let{value:s,onChange:t}=e;return(0,re.jsxs)(Ut,{value:s,onValueChange:t,children:[(0,re.jsx)(Wt,{className:"w-full",children:(0,re.jsx)(qt,{placeholder:"Select a category"})}),(0,re.jsx)(Ht,{children:$j.map(e=>{const s=e.icon;return(0,re.jsx)($t,{value:e.value,children:(0,re.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,re.jsx)(s,{className:"w-4 h-4"}),(0,re.jsx)("span",{children:e.label})]})},e.value)})})]})}function Xj(e){var s,t,a;let{appId:n,onSubmit:r,onCancel:l}=e;const{user:i}=oe(),[o,c]=(0,H.useState)(""),[d,m]=(0,H.useState)(""),[u,x]=(0,H.useState)([]),[h,p]=(0,H.useState)(""),[g,f]=(0,H.useState)(""),[v,b]=(0,H.useState)(!1),[j,y]=(0,H.useState)({}),[N,w]=(0,H.useState)(null),[_,k]=(0,H.useState)(!1),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||[]},s=await pj.create(e);c(""),m(""),x([]),p(""),f(""),y({}),w(null),null==r||r(s)}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"),Zj(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({});try{const e=await wj.requestAnswer(o.trim(),d.trim(),h,u||[]);e.answer_exists?w(e):await A()}catch(s){await A()}finally{k(!1)}}},C=async()=>{if(N)try{const s=N;w(null),b(!0);const t={title:o.trim(),content:d.trim(),category:h,app_id:n||null,app_link:g.trim()||null,file_urls:u||[]},a=await pj.create(t);try{const e="category: ".concat(h,"\ntitle: ").concat(o.trim(),"\n\ncontent: ").concat(d.trim());await wj.logAnswer(a.id,s,!1,e)}catch(e){}c(""),m(""),x([]),p(""),f(""),y({}),null==r||r(a)}catch(s){s.response&&s.response.data?y({submit:s.response.data.message}):y({submit:"Failed to submit your support ticket. Please try again."})}finally{b(!1)}else await A()},E=async()=>{if(N)try{const e="category: ".concat(h,"\ntitle: ").concat(o.trim(),"\n\ncontent: ").concat(d.trim());await wj.logAnswer(null,N,!0,e)}catch(e){}c(""),m(""),x([]),p(""),f(""),y({}),w(null),null==l||l()};return N&&N.answer_exists?(0,re.jsxs)("div",{className:"w-full p-6",children:[(0,re.jsx)("div",{className:"mb-4",children:(0,re.jsxs)("button",{onClick:()=>w(null),className:"inline-flex items-center text-xs text-slate-500 hover:text-slate-700 transition-colors",children:[(0,re.jsx)(Qt.A,{className:"w-3 h-3 mr-1"}),"Back"]})}),(0,re.jsxs)("div",{className:"mb-6",children:[(0,re.jsx)("h2",{className:"text-base font-medium text-slate-900 mb-1",children:"This might help"}),(0,re.jsx)("p",{className:"text-sm text-slate-500",children:"Here's what we found in our documentation"})]}),(0,re.jsx)("div",{className:"border-t border-b border-slate-200 py-6 mb-6",children:(0,re.jsx)("div",{children:(0,re.jsx)("div",{className:"prose prose-slate prose-sm max-w-none",children:(0,re.jsx)(el.oz,{remarkPlugins:[Qr.A],components:{a:e=>{let{node:s}=e,t=(0,as.A)(e,Fj);return(0,re.jsx)("a",(0,K.A)((0,K.A)({},t),{},{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:s,inline:t}=e,a=(0,as.A)(e,Bj);return t?(0,re.jsx)("code",(0,K.A)({className:"bg-slate-100 px-1 py-0.5 rounded text-xs font-mono text-slate-700"},a)):(0,re.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:s}=e,t=(0,as.A)(e,Uj);return(0,re.jsx)("blockquote",(0,K.A)({className:"border-l-2 border-slate-300 pl-4 text-slate-600"},t))},h1:e=>{let{node:s}=e,t=(0,as.A)(e,zj);return(0,re.jsx)("h1",(0,K.A)({className:"text-lg font-semibold text-slate-900 mt-6 mb-3"},t))},h2:e=>{let{node:s}=e,t=(0,as.A)(e,qj);return(0,re.jsx)("h2",(0,K.A)({className:"text-base font-medium text-slate-900 mt-5 mb-2"},t))},h3:e=>{let{node:s}=e,t=(0,as.A)(e,Wj);return(0,re.jsx)("h3",(0,K.A)({className:"text-sm font-medium text-slate-900 mt-4 mb-2"},t))},ul:e=>{let{node:s}=e,t=(0,as.A)(e,Vj);return(0,re.jsx)("ul",(0,K.A)({className:"list-disc pl-5 space-y-1 text-sm mb-4"},t))},ol:e=>{let{node:s}=e,t=(0,as.A)(e,Yj);return(0,re.jsx)("ol",(0,K.A)({className:"list-decimal pl-5 space-y-1 text-sm mb-4"},t))},li:e=>{let{node:s}=e,t=(0,as.A)(e,Hj);return(0,re.jsx)("li",(0,K.A)({className:"text-slate-600"},t))},p:e=>{var s;let{node:t}=e,a=(0,as.A)(e,Gj);const n=(null===(s=a.children)||void 0===s?void 0:s.toString())||"",r=n.startsWith("Important")||n.startsWith("Source:");return(0,re.jsx)("p",(0,K.A)({className:"text-slate-600 leading-relaxed text-sm ".concat(r?"mt-5 mb-3":"mb-3")},a))}},children:N.answer})})})}),(0,re.jsxs)("div",{className:"flex flex-col sm:flex-row gap-3",children:[(0,re.jsxs)(Hs,{onClick:E,className:"flex-1 bg-slate-900 hover:bg-slate-800 text-white",children:[(0,re.jsx)(nl.A,{className:"w-4 h-4 mr-2"}),"This helps"]}),(0,re.jsx)(Hs,{variant:"outline",onClick:C,disabled:v,className:"flex-1 border-slate-300 text-slate-700 hover:bg-slate-50",children:v?(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)("div",{className:"w-4 h-4 border-2 border-slate-600 border-t-transparent rounded-full animate-spin mr-2"}),"Submitting ticket..."]}):(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)($p.A,{className:"w-4 h-4 mr-2"}),"Still need help"]})})]}),(0,re.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,re.jsx)(re.Fragment,{children:(0,re.jsxs)("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-8 p-6",children:[(0,re.jsx)("div",{className:"lg:col-span-2 space-y-6",children:(0,re.jsxs)("form",{onSubmit:S,className:"space-y-6",children:[(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsx)(Nt,{className:"text-sm font-medium text-gray-700",children:"Category"}),(0,re.jsx)(Kj,{value:h,onChange:p}),j.category&&(0,re.jsx)("p",{className:"text-sm text-red-600",children:j.category}),h&&!n&&Zj(h,n)&&(0,re.jsx)("div",{className:"bg-orange-50 border border-orange-200 rounded-md p-2",children:(0,re.jsxs)("p",{className:"text-xs text-orange-700 flex items-start",children:[(0,re.jsx)(Xe.A,{className:"w-3 h-3 mr-1 mt-0.5 flex-shrink-0"}),(0,re.jsxs)("span",{children:["For ",h.replace(/_/g," ")," issues, you'll need to provide a link to your app."]})]})})]}),(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsx)(Nt,{htmlFor:"title",className:"text-sm font-medium text-gray-700",children:"Subject"}),(0,re.jsx)(ft,{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,re.jsx)("p",{className:"text-sm text-red-600",children:j.title})]}),!n&&(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsxs)(Nt,{htmlFor:"appLink",className:"text-sm font-medium text-gray-700",children:["App Link ",Zj(h,n)?(0,re.jsx)("span",{className:"text-red-500",children:"*"}):(0,re.jsx)("span",{className:"text-gray-400",children:"(optional)"})]}),(0,re.jsx)(ft,{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,re.jsxs)("div",{className:"space-y-1",children:[Zj(h,n)?(0,re.jsxs)("div",{className:"flex items-start space-x-1",children:[(0,re.jsx)(Xe.A,{className:"w-3 h-3 text-orange-500 mt-0.5 flex-shrink-0"}),(0,re.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,re.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&&Jj.includes(h)&&(0,re.jsxs)("p",{className:"text-xs text-gray-400 italic",children:["App link is optional for ",h.replace(/_/g," ")," issues."]})]}),j.appLink&&(0,re.jsx)("p",{className:"text-sm text-red-600",children:j.appLink})]}),(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsx)(Nt,{className:"text-sm font-medium text-gray-700",children:"Steps to Reproduce / Description"}),(0,re.jsx)("div",{className:"".concat(j.content?"border border-red-500 rounded-lg":""),children:(0,re.jsx)(qs,{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,re.jsxs)("div",{className:"flex justify-between items-center",children:[(0,re.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,re.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,re.jsx)("p",{className:"text-sm text-red-600",children:j.content})]}),j.submit&&(0,re.jsx)(us,{variant:"destructive",children:(0,re.jsx)(hs,{children:j.submit})})]})}),(0,re.jsxs)("div",{className:"space-y-6",children:[(0,re.jsxs)("div",{className:"bg-gray-50 rounded-lg p-4 space-y-3",children:[(0,re.jsx)("h3",{className:"text-sm font-semibold text-gray-900",children:"Ticket Information"}),n&&(0,re.jsxs)("div",{className:"space-y-1",children:[(0,re.jsx)("p",{className:"text-xs text-gray-500",children:"App ID"}),(0,re.jsx)("p",{className:"text-sm font-mono text-gray-900 bg-white px-2 py-1 rounded border",children:n})]}),!n&&g&&(0,re.jsxs)("div",{className:"space-y-1",children:[(0,re.jsx)("p",{className:"text-xs text-gray-500",children:"App Link"}),(0,re.jsx)("p",{className:"text-sm text-gray-900 bg-white px-2 py-1 rounded border break-all",children:g})]}),(0,re.jsxs)("div",{className:"space-y-1",children:[(0,re.jsx)("p",{className:"text-xs text-gray-500",children:"Support Tier"}),(0,re.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,re.jsx)("span",{className:"inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium ".concat(null!=i&&null!==(s=i.subscription_tier)&&void 0!==s&&s.toLowerCase().includes("elite")?"bg-purple-100 text-purple-800":null!=i&&null!==(t=i.subscription_tier)&&void 0!==t&&t.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,re.jsx)("span",{className:"text-xs text-purple-600",children:"Priority Support"})]})]})]}),(0,re.jsxs)("div",{className:"space-y-3",children:[(0,re.jsx)(Hs,{onClick:S,disabled:v||_,className:"w-full bg-blue-600 hover:bg-blue-700 text-white",children:_?(0,re.jsxs)(re.Fragment,{children:[(0,re.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,re.jsxs)(re.Fragment,{children:[(0,re.jsx)("div",{className:"w-4 h-4 border-2 border-white border-t-transparent rounded-full animate-spin mr-2"}),"Submitting..."]}):(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(nu.A,{className:"w-4 h-4 mr-2"}),"Submit Ticket"]})}),(0,re.jsxs)(Hs,{variant:"outline",onClick:l,className:"w-full",children:[(0,re.jsx)(zs.A,{className:"w-4 h-4 mr-2"}),"Cancel"]})]}),(0,re.jsx)("div",{className:"text-xs text-gray-500 space-y-2",children:(0,re.jsxs)("p",{children:[(0,re.jsx)("strong",{children:"Need immediate help?"})," Check our"," ",(0,re.jsx)("a",{href:"https://docs.base44.com",target:"_blank",rel:"noopener noreferrer",className:"text-blue-600 hover:underline",children:"documentation"})," ","or join our"," ",(0,re.jsx)("a",{href:"https://discord.gg/ThpYPZpVts",target:"_blank",rel:"noopener noreferrer",className:"text-blue-600 hover:underline",children:"Discord community"}),"."]})})]})]})})}const Qj={authentication:Fs.A,billing:Ke.A,bug_report:uj.A,integrations_and_backend_functions:ih.A,chat_issues:$p.A,security:rp.A,other:_h.A},ey={open:{label:"Open",color:"bg-orange-100 text-orange-800 border-orange-200",icon:Xp.A},resolved:{label:"Resolved",color:"bg-green-100 text-green-800 border-green-200",icon:Px.A}},sy=e=>{var s,t,a,n,r;let{ticket:l,onClick:i,isSelected:o}=e;const c=(null===(s=ey[l.ticket_status])||void 0===s?void 0:s.icon)||Xe.A,d=Qj[l.category]||_h.A;return(0,re.jsxs)(it,{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(l),children:[(0,re.jsx)(ot,{className:"pb-3",children:(0,re.jsxs)("div",{className:"flex items-start justify-between",children:[(0,re.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,re.jsx)(ct,{className:"text-lg font-semibold truncate transition-colors ".concat(o?"text-orange-900":"text-slate-900 group-hover:text-slate-700"),children:l.title}),(0,re.jsxs)("div",{className:"flex items-center space-x-3 mt-2",children:[(0,re.jsxs)(et,{variant:"secondary",className:"".concat(null===(t=ey[l.ticket_status])||void 0===t?void 0:t.color," border text-xs font-medium"),children:[(0,re.jsx)(c,{className:"w-3 h-3 mr-1"}),null===(a=ey[l.ticket_status])||void 0===a?void 0:a.label]}),l.category&&(0,re.jsxs)(et,{variant:"outline",className:"text-xs",children:[(0,re.jsx)(d,{className:"w-3 h-3 mr-1"}),l.category.replace(/_/g," ").replace(/\b\w/g,e=>e.toUpperCase())]})]})]}),(0,re.jsxs)("div",{className:"ml-4 flex items-center",children:[(0,re.jsx)(im.A,{className:"w-3 h-3 mr-2 text-slate-400"}),(e=>{if(!e)return"Not available";const s=la().utc(e);return(0,re.jsxs)("div",{className:"text-right text-xs text-slate-500",children:[(0,re.jsx)("div",{className:"font-medium",children:s.format("MMM DD, YYYY")}),(0,re.jsx)("div",{className:"text-slate-400 mt-0.5",children:s.fromNow()})]})})(l.created_date)]})]})}),(0,re.jsxs)(mt,{className:"pt-0",children:[(0,re.jsx)("p",{className:"text-slate-600 text-sm leading-relaxed line-clamp-2 mb-3",children:l.content}),(0,re.jsxs)("div",{className:"flex items-center justify-between text-xs text-slate-500",children:[(0,re.jsx)("div",{className:"flex items-center space-x-4",children:l.app_id&&(0,re.jsxs)("div",{className:"flex items-center",children:[(0,re.jsx)(xj.A,{className:"w-3 h-3 mr-1"}),(0,re.jsxs)("span",{children:["App: ",l.app_id]})]})}),(0,re.jsx)(et,{variant:"outline",className:"text-xs ".concat(null!==(n=l.user_subscription_tier)&&void 0!==n&&n.toLowerCase().includes("elite")?"border-purple-200 text-purple-700":null!==(r=l.user_subscription_tier)&&void 0!==r&&r.toLowerCase().includes("pro")?"border-blue-200 text-blue-700":"border-gray-200 text-gray-700"),children:l.user_subscription_tier||"free"})]})]})]})},ty=e=>{let{filter:s,onCreateTicket:t}=e;return(0,re.jsxs)("div",{className:"text-center py-16",children:[(0,re.jsx)("div",{className:"mx-auto w-24 h-24 bg-slate-100 rounded-full flex items-center justify-center mb-6",children:(0,re.jsx)(lj.A,{className:"w-12 h-12 text-slate-400"})}),(0,re.jsxs)("h3",{className:"text-xl font-semibold text-slate-900 mb-2",children:["No ","open"===s?"Open":"closed"===s?"Closed":""," Tickets"]}),(0,re.jsx)("p",{className:"text-slate-600 max-w-md mx-auto mb-6",children:"open"===s?"You don't have any open support tickets at the moment.":"closed"===s?"No closed tickets found.":"You haven't submitted any support tickets yet."}),(0,re.jsxs)(Hs,{className:"bg-orange-500 hover:bg-orange-600",onClick:t,children:[(0,re.jsx)(Ss.A,{className:"w-4 h-4 mr-2"}),"Create New Ticket"]})]})};function ay(){const[e,s]=(0,J.useSearchParams)(),t=(0,Z.Zp)(),{toast:a}=nn(),n=e.get("appId"),r="true"===e.get("openNew"),[l,i]=(0,H.useState)([]),[o,c]=(0,H.useState)(!0),[d,m]=(0,H.useState)(null),[u,x]=(0,H.useState)("open"),[h,p]=(0,H.useState)(null),[g,f]=(0,H.useState)(!1),[v,b]=(0,H.useState)(!1);(0,H.useEffect)(()=>{j()},[n]),(0,H.useEffect)(()=>{if(r){b(!0);const t=new URLSearchParams(e);t.delete("openNew"),s(t,{replace:!0})}},[r,e,s]);const j=async()=>{try{c(!0),m(null);const e=await pj.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 s=e||[];n&&(s=s.filter(e=>e.app_id===n)),i(s)}catch(e){m("Failed to load support tickets. Please try again.")}finally{c(!1)}},y=e=>{p(e),f(!0)},N=()=>{b(!0)},w=(()=>{switch(u){case"open":return l.filter(e=>"open"===e.ticket_status);case"closed":return l.filter(e=>"resolved"===e.ticket_status);default:return l}})(),_=l.filter(e=>"open"===e.ticket_status).length,k=l.filter(e=>"resolved"===e.ticket_status).length;return o?(0,re.jsx)("div",{className:"w-full max-w-6xl mx-auto px-6 py-12",children:(0,re.jsxs)("div",{className:"animate-pulse space-y-6",children:[(0,re.jsx)("div",{className:"h-8 bg-slate-200 rounded w-1/3"}),(0,re.jsx)("div",{className:"space-y-4",children:[1,2,3].map(e=>(0,re.jsx)("div",{className:"h-32 bg-slate-200 rounded-lg"},e))})]})}):d?(0,re.jsx)("div",{className:"w-full max-w-6xl mx-auto px-6 py-12",children:(0,re.jsxs)("div",{className:"text-center py-16",children:[(0,re.jsx)("div",{className:"mx-auto w-24 h-24 bg-red-100 rounded-full flex items-center justify-center mb-6",children:(0,re.jsx)(Xe.A,{className:"w-12 h-12 text-red-500"})}),(0,re.jsx)("h3",{className:"text-xl font-semibold text-slate-900 mb-2",children:"Error Loading Tickets"}),(0,re.jsx)("p",{className:"text-slate-600 mb-6",children:d}),(0,re.jsx)(Hs,{onClick:j,variant:"outline",children:"Try Again"})]})}):(0,re.jsxs)(re.Fragment,{children:[(0,re.jsxs)("div",{className:"w-full max-w-6xl mx-auto px-6 py-12",children:[(0,re.jsxs)("div",{className:"mb-8",children:[(0,re.jsxs)("div",{className:"flex items-center justify-between mb-4",children:[(0,re.jsxs)("div",{className:"flex items-center space-x-4",children:[(0,re.jsxs)(Hs,{variant:"ghost",size:"sm",onClick:()=>{t("/support")},className:"text-slate-600 hover:text-slate-900 hover:bg-slate-100",children:[(0,re.jsx)(Cc.A,{className:"w-4 h-4 mr-2"}),"Back to Support"]}),(0,re.jsxs)("div",{children:[(0,re.jsx)("h1",{className:"text-3xl font-bold text-slate-900",children:"My Support Tickets"}),n&&(0,re.jsxs)("p",{className:"text-slate-600 mt-1",children:["Showing tickets for App: ",(0,re.jsx)("span",{className:"font-mono text-sm",children:n})]})]})]}),(0,re.jsxs)("div",{className:"flex items-center space-x-3",children:[(0,re.jsxs)(Hs,{onClick:j,variant:"outline",size:"sm",children:[(0,re.jsx)(Sg.A,{className:"w-4 h-4 mr-2"}),"Refresh"]}),(0,re.jsxs)(Hs,{className:"bg-orange-500 hover:bg-orange-600",size:"sm",onClick:N,children:[(0,re.jsx)(Ss.A,{className:"w-4 h-4 mr-2"}),"New Ticket"]})]})]}),n&&(0,re.jsx)("div",{className:"mb-6",children:(0,re.jsxs)("div",{className:"inline-flex items-center gap-2 bg-blue-50 border border-blue-200 rounded-lg px-4 py-2",children:[(0,re.jsx)(Sg.A,{className:"w-4 h-4 text-blue-600"}),(0,re.jsxs)("span",{className:"text-sm font-medium text-blue-800",children:["Filtered by App: ",(0,re.jsx)("span",{className:"font-mono",children:n})]}),(0,re.jsx)(Hs,{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,re.jsx)(zs.A,{className:"w-4 h-4"})})]})})]}),(0,re.jsxs)(hl,{value:u,onValueChange:x,className:"mb-6",children:[(0,re.jsxs)(pl,{className:"grid w-full grid-cols-3 lg:w-96",children:[(0,re.jsxs)(gl,{value:"open",className:"flex items-center space-x-2",children:[(0,re.jsx)(Xp.A,{className:"w-4 h-4"}),(0,re.jsxs)("span",{children:["Open (",_,")"]})]}),(0,re.jsxs)(gl,{value:"closed",className:"flex items-center space-x-2",children:[(0,re.jsx)(Px.A,{className:"w-4 h-4"}),(0,re.jsxs)("span",{children:["Closed (",k,")"]})]}),(0,re.jsxs)(gl,{value:"all",className:"flex items-center space-x-2",children:[(0,re.jsx)(lj.A,{className:"w-4 h-4"}),(0,re.jsxs)("span",{children:["All (",l.length,")"]})]})]}),(0,re.jsx)(fl,{value:u,className:"mt-6",children:0===w.length?(0,re.jsx)(ty,{filter:u,onCreateTicket:N}):(0,re.jsx)("div",{className:"grid grid-cols-1 gap-4",children:w.map(e=>(0,re.jsx)(sy,{ticket:e,onClick:y,isSelected:(null==h?void 0:h.id)===e.id},e.id))})})]})]}),(0,re.jsx)(Pa,{open:v,onOpenChange:b,children:(0,re.jsxs)(Ma,{className:"max-w-6xl max-h-[90vh] overflow-y-auto",children:[(0,re.jsx)(Fa,{children:(0,re.jsx)(Ua,{className:"text-2xl font-bold",children:"Submit Support Ticket"})}),(0,re.jsx)(Xj,{appId:n,onSubmit:async e=>{b(!1),await j();const s=await pj.list("-updated_date",1e3);s&&1e3===s.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=s||[];n&&(t=t.filter(e=>e.app_id===n));const r=t.find(s=>s.title===e.title&&s.content===e.content);r&&(p(r),f(!0),i(t))},onCancel:()=>{b(!1)}})]})}),(0,re.jsx)(Mj,{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,s,t,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"===s){const e="user"===t;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 s=a.messages[a.messages.length-1];e="user"===s.role?"admin":"user"}p(s=>(0,K.A)((0,K.A)((0,K.A)({},s),a),{},{pending_response_from:e,updated_date:(new Date).toISOString()}))}}})]})}function ny(e){let{error:s,onRetry:t}=e;return(0,re.jsx)("div",{className:"w-full max-w-7xl mx-auto px-6 py-12",children:(0,re.jsxs)("div",{className:"text-center py-16",children:[(0,re.jsx)("div",{className:"mx-auto w-24 h-24 bg-red-100 rounded-full flex items-center justify-center mb-6",children:(0,re.jsx)(Xe.A,{className:"w-12 h-12 text-red-500"})}),(0,re.jsx)("h3",{className:"text-xl font-semibold text-slate-900 mb-2",children:"Error Loading Tickets"}),(0,re.jsx)("p",{className:"text-slate-600 mb-6",children:s}),(0,re.jsx)(Hs,{onClick:t,variant:"outline",children:"Try Again"})]})})}var ry=t(45536),ly=t(91412);const iy={authentication:Fs.A,billing:Ke.A,bug_report:uj.A,integrations_and_backend_functions:ih.A,chat_issues:$p.A,security:rp.A,social_post_bonus_credits:Yg.A,other:_h.A},oy=(Xp.A,Px.A,{starter:{label:"Starter",color:"bg-green-100 text-green-800 border-green-200",icon:Gg.A},starter_yearly:{label:"Starter(Yearly)",color:"bg-green-100 text-green-800 border-green-200",icon:Gg.A},builder:{label:"Builder",color:"bg-blue-100 text-blue-800 border-blue-200",icon:yo.A},builder_yearly:{label:"Builder(Yearly)",color:"bg-blue-100 text-blue-800 border-blue-200",icon:yo.A},pro:{label:"Pro",color:"bg-indigo-100 text-indigo-800 border-indigo-200",icon:jr.A},pro_yearly:{label:"Pro(Yearly)",color:"bg-indigo-100 text-indigo-800 border-indigo-200",icon:jr.A},elite:{label:"Elite",color:"bg-purple-100 text-purple-800 border-purple-200",icon:ry.A},elite_yearly:{label:"Elite(Yearly)",color:"bg-purple-100 text-purple-800 border-purple-200",icon:ry.A},elite_2:{label:"Elite 2",color:"bg-violet-100 text-violet-800 border-violet-200",icon:ly.A},elite_2_yearly:{label:"Elite 2(Yearly)",color:"bg-violet-100 text-violet-800 border-violet-200",icon:ly.A},elite_3:{label:"Elite 3",color:"bg-pink-100 text-pink-800 border-pink-200",icon:$b.A},elite_3_yearly:{label:"Elite 3 (Yearly)",color:"bg-pink-100 text-pink-800 border-pink-200",icon:$b.A},free:{label:"Free",color:"bg-gray-100 text-gray-800 border-gray-200",icon:Gr.A}});function cy(e){let{userEmail:s,currentTicketId:t}=e;const[a,n]=(0,H.useState)([]),[r,l]=(0,H.useState)(!0),[i,o]=(0,H.useState)(null);(0,H.useEffect)(()=>{s&&c()},[s]);const c=async()=>{try{l(!0);const e=(await fj.getTickets({created_by:s,show_resolved:!0})||[]).sort((e,s)=>new Date(s.created_date)-new Date(e.created_date));n(e)}catch(i){o(i)}finally{l(!1)}};return r?(0,re.jsx)("div",{className:"flex items-center justify-center py-4",children:(0,re.jsx)("div",{className:"animate-spin rounded-full h-4 w-4 border-b-2 border-slate-400"})}):i?(0,re.jsx)("div",{className:"text-xs text-red-600 p-2",children:"Failed to load tickets"}):0===a.length?(0,re.jsx)("div",{className:"text-xs text-slate-500 italic p-2",children:"No previous tickets found"}):(0,re.jsxs)("div",{className:"space-y-2 max-h-96 overflow-y-auto",children:[a.slice(0,10).map(e=>{const s=e.id===t;return(0,re.jsxs)(J.Link,{to:"/support/admin/conversations?conversationId=".concat(e.id),className:"block p-2 rounded-lg border transition-colors group ".concat(s?"border-teal-500 bg-teal-50 ring-1 ring-teal-500":"border-slate-200 hover:border-slate-300 hover:bg-slate-50"),children:[(0,re.jsxs)("div",{className:"space-y-1",children:[(0,re.jsx)("h4",{className:"text-xs font-medium text-slate-900 line-clamp-2 group-hover:text-slate-700",children:e.title}),(0,re.jsxs)("div",{className:"flex items-center justify-between",children:[(0,re.jsx)("div",{className:"flex items-center space-x-2",children:"resolved"===e.ticket_status?(0,re.jsxs)(et,{variant:"secondary",className:"text-[10px] bg-green-100 text-green-800 border-green-200 h-auto py-0.5 px-1",children:[(0,re.jsx)(Px.A,{className:"w-2.5 h-2.5 mr-0.5"}),"Resolved"]}):(0,re.jsxs)(et,{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,re.jsx)(Xp.A,{className:"w-2.5 h-2.5 mr-0.5"}),"admin"===e.pending_response_from?"Pending Admin":"Pending User"]})}),(0,re.jsx)("span",{className:"text-[10px] text-slate-500",children:la().utc(e.created_date).fromNow()})]}),e.category&&(0,re.jsxs)("div",{className:"flex items-center text-[10px] text-slate-600",children:[(0,re.jsx)(bl.A,{className:"w-2.5 h-2.5 mr-1"}),(0,re.jsx)("span",{className:"capitalize",children:e.category.replace(/_/g," ")})]})]}),(0,re.jsx)("div",{className:"flex items-center justify-end mt-1",children:s?(0,re.jsx)("span",{className:"text-[10px] text-teal-600 font-medium",children:"Current ticket"}):(0,re.jsx)(jl.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,re.jsxs)("div",{className:"text-[10px] text-slate-500 text-center py-2",children:["Showing 10 of ",a.length," tickets"]})]})}const dy=function(e){let s=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(!e)return"Not available";const t=la().utc(e);return s?"".concat(t.format("MMM DD, YYYY [at] HH:mm [UTC]")," (").concat(t.fromNow(),")"):"".concat(t.format("MMM DD, YYYY")," (").concat(t.fromNow(),")")},my=[{value:"open",label:"Open",icon:Xp.A,color:"text-orange-600"},{value:"resolved",label:"Resolved",icon:Px.A,color:"text-green-600"}],uy=[{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"}],xy=e=>{let{category:s}=e;const t=iy[s]||Xe.A,a=s?s.replace(/_/g," ").replace(/\b\w/g,e=>e.toUpperCase()):"Uncategorized";return(0,re.jsxs)(et,{variant:"outline",className:"text-xs",children:[(0,re.jsx)(t,{className:"w-3 h-3 mr-1"}),a]})},hy=e=>{let{title:s,icon:t,children:a,isCollapsible:n=!1,defaultExpanded:r=!0}=e;const[l,i]=(0,H.useState)(r);return(0,re.jsxs)(it,{className:"border-slate-200",children:[(0,re.jsx)("div",{className:"p-3 ".concat(n?"cursor-pointer":""),onClick:n?()=>i(!l):void 0,children:(0,re.jsxs)("div",{className:"flex items-center justify-between",children:[(0,re.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,re.jsx)(t,{className:"w-4 h-4 text-slate-600"}),(0,re.jsx)("h3",{className:"text-sm font-semibold text-slate-900",children:s})]}),n&&(0,re.jsx)("div",{className:"text-slate-400",children:l?(0,re.jsx)(Tt.A,{className:"w-4 h-4"}):(0,re.jsx)(It.A,{className:"w-4 h-4"})})]})}),l&&(0,re.jsx)(mt,{className:"pt-0 pb-3 px-3",children:a})]})},py=e=>{let{label:s,value:t,className:a=""}=e;return(0,re.jsxs)("div",{className:"flex justify-between items-start py-1.5 ".concat(a),children:[(0,re.jsx)("span",{className:"text-xs text-slate-600 flex-shrink-0 w-20",children:s}),(0,re.jsx)("span",{className:"text-xs text-slate-900 text-right flex-1",children:t})]})};function gy(e){var s,t,a,n,r;let{conversationId:l,onTicketUpdated:i}=e;const{conversationId:o}=(0,Z.g)(),[c]=(0,J.useSearchParams)(),d=c.get("conversationId"),m=l||o||d,[u,x]=(0,H.useState)(null),[h,p]=(0,H.useState)(!0),[g,f]=(0,H.useState)(null),[v,b]=(0,H.useState)(!1),[j,y]=(0,H.useState)([]),[N,w]=(0,H.useState)([]),[_,k]=(0,H.useState)(!1),[A,S]=(0,H.useState)([]),[C,E]=(0,H.useState)(!1),[I,T]=(0,H.useState)(""),[P,L]=(0,H.useState)(""),[O,R]=(0,H.useState)(!1),[D,M]=(0,H.useState)(""),[F,B]=(0,H.useState)(!1),[U,z]=(0,H.useState)(""),[q,W]=(0,H.useState)(!1),[V,Y]=(0,H.useState)(!1),[G,$]=(0,H.useState)(!1);(0,H.useEffect)(()=>{m&&(x(null),p(!0),f(null),K())},[m]);const K=async()=>{try{var e,s;p(!0),f(null);const[t,a]=await Promise.all([fj.getTicketDetail(m),bj.getAgentProperties()]);x(t),y((null==a?void 0:a.internal_category_options)||[]),w((null==t||null===(e=t.ticket)||void 0===e?void 0:e.internal_categories)||[]),M((null==t||null===(s=t.ticket)||void 0===s?void 0:s.internal_notes)||"")}catch(t){f("Failed to load ticket details. Please try again.")}finally{p(!1)}},X=async()=>{const e=(s=I).trim()?/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(s)?s.endsWith("@base44.com")||s.endsWith("@wix.com")?"":"Email must be from @base44.com or @wix.com domain":"Please enter a valid email address":"Email is required";var s;if(e)L(e);else try{R(!0),L(""),await fj.assignTicket(m,I.trim()),await K(),i&&i(m,"assigned",I.trim()),E(!1),T("")}catch(t){L("Failed to assign ticket. Please try again.")}finally{R(!1)}};if(h)return(0,re.jsx)("div",{className:"h-full flex items-center justify-center",children:(0,re.jsxs)("div",{className:"text-center",children:[(0,re.jsx)("div",{className:"animate-spin rounded-full h-6 w-6 border-b-2 border-slate-400 mx-auto mb-3"}),(0,re.jsx)("p",{className:"text-sm text-slate-600",children:"Loading conversation..."})]})});if(g)return(0,re.jsx)("div",{className:"h-full flex items-center justify-center p-6",children:(0,re.jsxs)("div",{className:"text-center",children:[(0,re.jsx)("div",{className:"w-12 h-12 bg-red-100 rounded-full flex items-center justify-center mx-auto mb-3",children:(0,re.jsx)(Xe.A,{className:"w-6 h-6 text-red-500"})}),(0,re.jsx)("h3",{className:"text-sm font-semibold text-slate-900 mb-2",children:"Error Loading Ticket"}),(0,re.jsx)("p",{className:"text-xs text-slate-600 mb-4",children:g}),(0,re.jsx)(Hs,{onClick:K,variant:"outline",size:"sm",children:"Try Again"})]})});const Q=(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:Q.created_by||"unknown@example.com",name:"Unknown User",stripe_customer_id:null,created_date:(new Date).toISOString()},se=(null==u?void 0:u.subscriptions)||[];return(0,re.jsxs)("div",{className:"h-full flex flex-col min-h-0",children:[(0,re.jsx)("div",{className:"border-b border-slate-200 p-4 bg-slate-50 flex-shrink-0 min-h-fit",children:(0,re.jsx)("div",{className:"space-y-4",children:(0,re.jsxs)("div",{className:"flex items-start justify-between gap-4",children:[(0,re.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,re.jsxs)("div",{className:"flex items-start gap-2",children:[(0,re.jsx)("h2",{className:"text-lg font-semibold text-slate-900 leading-snug break-words",children:Q.title}),Q.is_escalated&&(0,re.jsxs)(et,{variant:"destructive",className:"bg-red-100 text-red-800 border-red-200 flex-shrink-0",children:[(0,re.jsx)(Fu.A,{className:"w-3 h-3 mr-1"}),"Escalated"]})]}),(0,re.jsxs)("div",{className:"flex items-start justify-between mt-3 gap-4",children:[(0,re.jsxs)("div",{className:"flex items-center space-x-3 flex-wrap min-w-0",children:[(0,re.jsx)(xy,{category:Q.category}),(0,re.jsx)("div",{className:"text-xs text-slate-600",children:(0,re.jsx)("span",{className:"font-medium capitalize",children:Q.ticket_status})}),Q.assigned_to&&(0,re.jsxs)("div",{className:"text-xs text-slate-600",children:[(0,re.jsx)(ev.A,{className:"w-3 h-3 inline mr-1"}),(0,re.jsx)("span",{className:"font-medium",children:Q.assigned_to})]})]}),(0,re.jsxs)("div",{className:"flex items-center space-x-2 flex-shrink-0 flex-wrap",children:["resolved"!==Q.ticket_status&&(0,re.jsxs)(Hs,{variant:Q.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 fj.unescalateTicket(m):await fj.escalateTicket(m),await K(),i&&i(m,"escalation_updated")}catch(s){f("Failed to change escalation status. Please try again.")}finally{$(!1)}},disabled:G,className:"h-auto py-1 px-2 text-xs ".concat(Q.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,re.jsx)("div",{className:"animate-spin rounded-full h-3 w-3 border-b-2 border-current mr-1"}):(0,re.jsx)(Fu.A,{className:"w-3 h-3 mr-1"}),Q.is_escalated?"Unescalate":"Escalate"]}),"resolved"!==Q.ticket_status&&(0,re.jsxs)(Hs,{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,re.jsx)(Qf.A,{className:"w-3 h-3 mr-1"}),Q.assigned_to?"Reassign":"Assign"]}),(0,re.jsxs)(Ut,{value:Q.category||"other",onValueChange:async e=>{try{Y(!0),await fj.updateTicketCategory(m,e),await K(),i&&i(m,"category_updated")}catch(s){f("Failed to change ticket category. Please try again.")}finally{Y(!1)}},disabled:V,children:[(0,re.jsx)(Wt,{className:"h-auto py-1 w-auto text-xs border-slate-300 hover:border-slate-400",children:(0,re.jsxs)("div",{className:"flex items-center",children:[V?(0,re.jsx)("div",{className:"animate-spin rounded-full h-3 w-3 border-b-2 border-slate-400 mr-1"}):(0,re.jsx)(xj.A,{className:"w-3 h-3 mr-1"}),(0,re.jsx)("span",{className:"mr-1",children:"Category:"}),(0,re.jsx)(qt,{})]})}),(0,re.jsx)(Ht,{children:uy.map(e=>(0,re.jsx)($t,{value:e.value,children:e.label},e.value))})]}),(0,re.jsxs)(Ut,{value:Q.ticket_status,onValueChange:async e=>{try{b(!0),await fj.changeTicketStatus(m,e),await K(),i&&i(m,e)}catch(s){f("Failed to change ticket status. Please try again.")}finally{b(!1)}},disabled:v,children:[(0,re.jsx)(Wt,{className:"h-auto py-1 w-auto text-xs border-slate-300 hover:border-slate-400",children:(0,re.jsxs)("div",{className:"flex items-center",children:[v?(0,re.jsx)("div",{className:"animate-spin rounded-full h-3 w-3 border-b-2 border-slate-400 mr-1"}):(()=>{const e=my.find(e=>e.value===Q.ticket_status),s=(null==e?void 0:e.icon)||Xp.A;return(0,re.jsx)(s,{className:"w-3 h-3 mr-1"})})(),(0,re.jsx)(qt,{})]})}),(0,re.jsx)(Ht,{children:my.map(e=>{const s=e.icon;return(0,re.jsx)($t,{value:e.value,children:(0,re.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,re.jsx)(s,{className:"w-4 h-4 ".concat(e.color)}),(0,re.jsx)("span",{children:e.label})]})},e.value)})})]})]})]})]}),(0,re.jsxs)("div",{className:"flex flex-col items-end space-y-1 text-xs text-slate-600 flex-shrink-0",children:[(0,re.jsxs)("span",{className:"font-mono bg-white px-2 py-1 rounded text-xs whitespace-nowrap",children:["id: ",Q.id]}),(0,re.jsx)("span",{className:"text-right text-xs",children:dy(Q.created_date)})]})]})})}),(0,re.jsxs)(jh,{direction:"horizontal",className:"flex-1 overflow-hidden min-h-0",children:[(0,re.jsx)(yh,{defaultSize:90,minSize:20,children:(0,re.jsx)("div",{className:"h-full flex flex-col min-h-0",children:(0,re.jsx)(Rj,{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,re.jsx)(Nh,{withHandle:!0,className:"hidden lg:flex group transition-opacity opacity-0 hover:opacity-100 focus:opacity-100"}),(0,re.jsx)(yh,{defaultSize:30,minSize:15,maxSize:40,className:"hidden lg:block",children:(0,re.jsx)("div",{className:"w-full border-l border-slate-200 bg-slate-50 h-full flex flex-col",children:(0,re.jsxs)("div",{className:"flex-1 overflow-y-auto p-3 space-y-3",children:[(0,re.jsx)(hy,{title:"User",icon:np.A,isCollapsible:!0,defaultExpanded:!0,children:(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsx)(py,{label:"Email",value:ee.email}),(0,re.jsx)(py,{label:"Name",value:ee.full_name||"Not provided"}),(0,re.jsx)(py,{label:"Subscription Status",value:ee.stripe_subscription_status||"Not provided"}),(0,re.jsx)(py,{label:"Manage",value:(0,re.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,re.jsx)(jl.A,{className:"w-2 h-2 ml-1"})]})}),ee.stripe_customer_id&&(0,re.jsx)(py,{label:"Stripe",value:(0,re.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,re.jsx)(jl.A,{className:"w-2 h-2 ml-1"})]})})]})}),(0,re.jsx)(hy,{title:"Previous Tickets",icon:Uf.A,isCollapsible:!0,defaultExpanded:!0,children:(0,re.jsx)(cy,{userEmail:ee.email,currentTicketId:m})}),(0,re.jsx)(hy,{title:"Subscription",icon:Ke.A,isCollapsible:!0,defaultExpanded:!0,children:se&&se.length>0?(0,re.jsx)("div",{className:"space-y-2",children:se.map((e,s)=>{var t,a,n;return(0,re.jsxs)("div",{className:"space-y-1",children:[(0,re.jsx)(py,{label:"Plan",value:(null===(t=e.plan)||void 0===t?void 0:t.nickname)||"Unknown"}),(0,re.jsx)(py,{label:"Status",value:e.status}),(0,re.jsx)(py,{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)})]},s)})}):(0,re.jsx)("p",{className:"text-xs text-slate-600",children:"No subscriptions found."})}),(0,re.jsx)(hy,{title:"App",icon:bl.A,isCollapsible:!0,defaultExpanded:!0,children:(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsx)(py,{label:"Name",value:(null==u||null===(s=u.app)||void 0===s?void 0:s.name)||"None"}),(0,re.jsx)(py,{label:"Link",value:null!=u&&null!==(t=u.app)&&void 0!==t&&t.id?(0,re.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,re.jsx)(jl.A,{className:"w-2 h-2 ml-1"})]}):"No app linked"}),(0,re.jsx)(py,{label:"App Visiblity",value:(null==u||null===(a=u.app)||void 0===a?void 0:a.visibility)||"Not available"}),(0,re.jsx)(py,{label:"Created",value:null!=u&&null!==(n=u.app)&&void 0!==n&&n.created_date?dy(u.app.created_date):"Not available"}),(0,re.jsx)(py,{label:"Updated",value:null!=u&&null!==(r=u.app)&&void 0!==r&&r.updated_date?dy(u.app.updated_date):"Not available"}),(0,re.jsx)(py,{label:"App ID",value:(null==Q?void 0:Q.app_id)||"None"})]})}),(0,re.jsx)(hy,{title:"Internal Categories",icon:xj.A,isCollapsible:!0,defaultExpanded:!0,children:(0,re.jsxs)("div",{className:"space-y-3",children:[(0,re.jsx)("div",{className:"text-xs text-slate-600 mb-2",children:"Internal categories for admin organization and tracking."}),_?(0,re.jsxs)("div",{className:"space-y-3",children:[(0,re.jsx)("div",{className:"space-y-2",children:j.map(e=>(0,re.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,re.jsx)(ed,{id:"category-".concat(e),checked:A.includes(e),onCheckedChange:()=>(e=>{S(s=>s.includes(e)?s.filter(s=>s!==e):[...s,e])})(e),className:"h-3 w-3"}),(0,re.jsx)("label",{htmlFor:"category-".concat(e),className:"text-xs text-slate-700 cursor-pointer",children:e})]},e))}),(0,re.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,re.jsxs)(Hs,{variant:"default",size:"sm",onClick:async()=>{try{await fj.updateInternalCategories(m,A),w([...A]),k(!1),S([]),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,re.jsx)(ah.A,{className:"w-3 h-3 mr-1"}),"Save"]}),(0,re.jsxs)(Hs,{variant:"outline",size:"sm",onClick:()=>{S([]),k(!1)},className:"h-6 px-2 text-xs",children:[(0,re.jsx)(zs.A,{className:"w-3 h-3 mr-1"}),"Cancel"]})]})]}):(0,re.jsxs)("div",{className:"space-y-2",children:[N.length>0?(0,re.jsx)("div",{className:"flex flex-wrap gap-1",children:N.map(e=>(0,re.jsx)(et,{variant:"secondary",className:"text-xs",children:e},e))}):(0,re.jsx)("p",{className:"text-xs text-slate-500 italic",children:"No internal categories assigned."}),(0,re.jsxs)(Hs,{variant:"outline",size:"sm",onClick:()=>{S([...N]),k(!0)},className:"h-6 px-2 text-xs",children:[(0,re.jsx)(Hr.A,{className:"w-3 h-3 mr-1"}),"Edit Categories"]})]})]})}),(0,re.jsx)(hy,{title:"Internal Notes",icon:al.A,isCollapsible:!0,defaultExpanded:!0,children:(0,re.jsxs)("div",{className:"space-y-3",children:[(0,re.jsx)("div",{className:"text-xs text-slate-600 mb-2",children:"Private notes visible only to admins."}),F?(0,re.jsxs)("div",{className:"space-y-3",children:[(0,re.jsx)(td,{value:U,onChange:e=>z(e.target.value),placeholder:"Add internal notes here...",className:"min-h-[100px] text-xs resize-none",disabled:q}),(0,re.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,re.jsx)(Hs,{variant:"default",size:"sm",onClick:async()=>{try{W(!0),await fj.updateInternalNotes(m,U),M(U),B(!1),z(""),i&&i(m,"notes_updated")}catch(e){f("Failed to update internal notes. Please try again.")}finally{W(!1)}},disabled:q,className:"h-6 px-2 text-xs",children:q?(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)("div",{className:"animate-spin rounded-full h-3 w-3 border-b-2 border-white mr-1"}),"Saving..."]}):(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(ah.A,{className:"w-3 h-3 mr-1"}),"Save"]})}),(0,re.jsxs)(Hs,{variant:"outline",size:"sm",onClick:()=>{z(""),B(!1)},disabled:q,className:"h-6 px-2 text-xs",children:[(0,re.jsx)(zs.A,{className:"w-3 h-3 mr-1"}),"Cancel"]})]})]}):(0,re.jsxs)("div",{className:"space-y-2",children:[D?(0,re.jsx)("div",{className:"p-2 bg-slate-50 rounded-lg border border-slate-200",children:(0,re.jsx)("p",{className:"text-xs text-slate-700 whitespace-pre-wrap",children:D})}):(0,re.jsx)("p",{className:"text-xs text-slate-500 italic",children:"No internal notes added."}),(0,re.jsxs)(Hs,{variant:"outline",size:"sm",onClick:()=>{z(D),B(!0)},className:"h-6 px-2 text-xs",children:[(0,re.jsx)(Hr.A,{className:"w-3 h-3 mr-1"}),D?"Edit Notes":"Add Notes"]})]})]})})]})})})]}),(0,re.jsx)(Pa,{open:C,onOpenChange:E,children:(0,re.jsxs)(Ma,{className:"sm:max-w-md",children:[(0,re.jsx)(Fa,{children:(0,re.jsxs)(Ua,{className:"flex items-center",children:[(0,re.jsx)(Qf.A,{className:"w-5 h-5 mr-2"}),Q.assigned_to?"Reassign Ticket":"Assign Ticket"]})}),(0,re.jsxs)("div",{className:"space-y-4 py-4",children:[(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsx)(Nt,{htmlFor:"assignEmail",children:"Agent Email"}),(0,re.jsx)(ft,{id:"assignEmail",type:"email",value:I,onChange:e=>{T(e.target.value),P&&L("")},onKeyPress:e=>{"Enter"===e.key&&(e.preventDefault(),X())},placeholder:"agent@base44.com",className:"w-full ".concat(P?"border-red-500":""),disabled:O}),P&&(0,re.jsx)("p",{className:"text-sm text-red-600",children:P}),(0,re.jsx)("p",{className:"text-xs text-slate-500",children:"Email must be from @base44.com or @wix.com domain"})]}),Q.assigned_to&&(0,re.jsxs)("div",{className:"p-3 bg-slate-50 rounded-lg",children:[(0,re.jsx)("p",{className:"text-xs text-slate-600 mb-1",children:"Currently assigned to:"}),(0,re.jsx)("p",{className:"text-sm font-medium text-slate-900",children:Q.assigned_to})]})]}),(0,re.jsxs)("div",{className:"flex justify-end space-x-3",children:[(0,re.jsx)(Hs,{variant:"outline",onClick:()=>{T(""),L(""),E(!1)},disabled:O,children:"Cancel"}),(0,re.jsx)(Hs,{onClick:X,disabled:O||!I.trim(),children:O?(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)("div",{className:"w-4 h-4 border-2 border-white border-t-transparent rounded-full animate-spin mr-2"}),"Assigning..."]}):(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(ev.A,{className:"w-4 h-4 mr-2"}),Q.assigned_to?"Reassign":"Assign"," Ticket"]})})]})]})})]})}const fy=e=>{var s,t,a,n,r,l,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===(s=u.category)||void 0===s?void 0:s.authentication)||0},{value:"billing",label:"Billing",count:(null===(t=u.category)||void 0===t?void 0:t.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===(r=u.category)||void 0===r?void 0:r.chat_issues)||0},{value:"security",label:"Security",count:(null===(l=u.category)||void 0===l?void 0:l.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[s]=e;return"unassigned"!==s}).map(e=>{let[s,t]=e;return{value:s,label:s.split("@")[0],count:t}})];return(0,re.jsxs)("div",{className:"w-full h-full bg-white border-r border-slate-200 flex flex-col",children:[(0,re.jsx)("div",{className:"flex-shrink-0 p-3 border-b border-slate-100",children:(0,re.jsxs)("div",{className:"relative",children:[(0,re.jsx)(vn.A,{className:"absolute left-2 top-1/2 transform -translate-y-1/2 text-slate-400 w-3 h-3"}),(0,re.jsx)(ft,{placeholder:"Search...",value:x,onChange:e=>h(e.target.value),className:"pl-7 text-xs h-8"})]})}),(0,re.jsxs)("div",{className:"flex-1 overflow-y-auto p-3 space-y-4 text-xs",children:[(0,re.jsx)("div",{className:"space-y-2",children:(0,re.jsxs)("div",{className:"flex items-center space-x-2 p-2 bg-slate-50 rounded border",children:[(0,re.jsx)(ed,{id:"show-resolved",checked:p,onCheckedChange:g,className:"h-4 w-4"}),(0,re.jsx)("label",{htmlFor:"show-resolved",className:"text-xs font-medium text-slate-700 cursor-pointer flex-1",children:"Include resolved tickets"})]})}),(0,re.jsxs)("div",{className:"space-y-1",children:[(0,re.jsx)("h3",{className:"text-xs font-semibold text-slate-600 uppercase tracking-wide",children:"Pending Response"}),(0,re.jsx)("div",{className:"space-y-0.5",children:f.map(e=>(0,re.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,re.jsxs)("div",{className:"flex items-center justify-between",children:[(0,re.jsx)("span",{className:"truncate",children:e.label}),void 0!==e.count&&(0,re.jsx)(et,{variant:"secondary",className:"text-xs h-4 px-1",children:e.count})]})},e.value))})]}),u.escalated>0&&(0,re.jsxs)("div",{className:"space-y-1",children:[(0,re.jsx)("h3",{className:"text-xs font-semibold text-slate-600 uppercase tracking-wide",children:"Priority"}),(0,re.jsx)("div",{className:"space-y-0.5",children:(0,re.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,re.jsxs)("div",{className:"flex items-center justify-between",children:[(0,re.jsxs)("div",{className:"flex items-center space-x-1",children:[(0,re.jsx)(Fu.A,{className:"w-3 h-3"}),(0,re.jsx)("span",{className:"truncate",children:"Escalated"})]}),(0,re.jsx)(et,{variant:"secondary",className:"text-xs h-4 px-1",children:u.escalated})]})})})]}),(0,re.jsxs)("div",{className:"space-y-1",children:[(0,re.jsx)("h3",{className:"text-xs font-semibold text-slate-600 uppercase tracking-wide",children:"Assigned"}),(0,re.jsx)("div",{className:"space-y-0.5 max-h-32 overflow-y-auto",children:b.map(e=>(0,re.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,re.jsxs)("div",{className:"flex items-center justify-between",children:[(0,re.jsx)("span",{className:"truncate",children:e.label}),void 0!==e.count&&(0,re.jsx)(et,{variant:"secondary",className:"text-xs h-4 px-1",children:e.count})]})},e.value))})]}),(0,re.jsxs)("div",{className:"space-y-1",children:[(0,re.jsx)("h3",{className:"text-xs font-semibold text-slate-600 uppercase tracking-wide",children:"Subscription"}),(0,re.jsxs)("div",{className:"space-y-0.5 max-h-32 overflow-y-auto",children:[(0,re.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,re.jsxs)("div",{className:"flex items-center justify-between",children:[(0,re.jsx)("span",{className:"truncate",children:"All Tiers"}),u.tier&&(0,re.jsx)(et,{variant:"secondary",className:"text-xs h-4 px-1",children:Object.values(u.tier).reduce((e,s)=>e+s,0)})]})}),Object.entries(oy).map(e=>{var s;let[t,a]=e;const n=(null===(s=u.tier)||void 0===s?void 0:s[t])||0;return 0===n?null:(0,re.jsx)("button",{onClick:()=>d("user_subscription_tier",c.user_subscription_tier===t?"":t),className:"w-full text-left px-2 py-1 rounded text-xs transition-colors ".concat(c.user_subscription_tier===t?"bg-purple-100 text-purple-800 font-medium":"text-slate-600 hover:bg-slate-50"),children:(0,re.jsxs)("div",{className:"flex items-center justify-between",children:[(0,re.jsx)("span",{className:"truncate",children:a.label}),(0,re.jsx)(et,{variant:"secondary",className:"text-xs h-4 px-1",children:n})]})},t)})]})]}),(0,re.jsxs)("div",{className:"space-y-1",children:[(0,re.jsx)("h3",{className:"text-xs font-semibold text-slate-600 uppercase tracking-wide",children:"Category"}),(0,re.jsx)("div",{className:"space-y-0.5",children:v.map(e=>(0,re.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,re.jsxs)("div",{className:"flex items-center justify-between",children:[(0,re.jsx)("span",{className:"truncate",children:e.label}),void 0!==e.count&&(0,re.jsx)(et,{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,re.jsxs)("div",{className:"space-y-1",children:[(0,re.jsx)("h3",{className:"text-xs font-semibold text-slate-600 uppercase tracking-wide",children:"Internal Categories"}),(0,re.jsx)("div",{className:"space-y-0.5 max-h-32 overflow-y-auto",children:Object.entries(u.internal_categories).map(e=>{let[s,t]=e;return(0,re.jsx)("button",{onClick:()=>d("internal_category",c.internal_category===s?"":s),className:"w-full text-left px-2 py-1 rounded text-xs transition-colors ".concat(c.internal_category===s?"bg-purple-100 text-purple-800 font-medium":"text-slate-600 hover:bg-slate-50"),children:(0,re.jsxs)("div",{className:"flex items-center justify-between",children:[(0,re.jsx)("span",{className:"truncate",children:s}),(0,re.jsx)(et,{variant:"secondary",className:"text-xs h-4 px-1",children:t})]})},s)})})]}),(c.status||c.category||c.assigned_to||c.internal_category||c.user_subscription_tier||c.is_escalated||x||p)&&(0,re.jsx)(Hs,{variant:"outline",size:"sm",onClick:m,className:"w-full text-xs h-7",children:"Clear Filters"})]})]})},vy=e=>{let{ticket:s,isSelected:t,onClick:a,onCheckboxToggle:n,showCheckbox:r,activeAgents:l,isCurrentUserViewing:i}=e;const o=iy[s.category],c=l||[];return(0,re.jsxs)("div",{className:"flex items-start p-3 border-b border-slate-100 transition-colors ".concat(t?"bg-teal-50 border-l-4 border-l-teal-500":"hover:bg-slate-50"),children:["resolved"!==s.ticket_status&&(0,re.jsx)("div",{className:"mr-3 mt-1",children:(0,re.jsx)(ed,{checked:r,onCheckedChange:e=>{n(s.id,e)},onClick:e=>e.stopPropagation(),className:"h-4 w-4"})}),(0,re.jsxs)("div",{onClick:()=>a(s),className:"flex-1 cursor-pointer space-y-1.5",children:[(0,re.jsxs)("div",{className:"flex items-start gap-1",children:[(0,re.jsx)("h4",{className:"font-medium text-slate-900 text-sm line-clamp-2 leading-tight flex-1",children:s.title}),s.is_escalated&&(0,re.jsx)(Fu.A,{className:"w-3.5 h-3.5 text-red-500 flex-shrink-0 mt-0.5",title:"Escalated"})]}),(0,re.jsxs)("div",{className:"flex items-center justify-between text-xs text-slate-500",children:[(0,re.jsx)("span",{className:"truncate",children:s.created_by}),s.category&&(0,re.jsxs)("div",{className:"flex items-center space-x-1 flex-shrink-0 ml-2",children:[o&&(0,re.jsx)(o,{className:"w-3 h-3 text-slate-500"}),(0,re.jsx)("span",{className:"capitalize",children:"integrations_and_backend_functions"===s.category?"Integrations":s.category.replace("_"," ")})]})]}),(0,re.jsxs)("div",{className:"flex items-center justify-between text-xs text-slate-500",children:[(0,re.jsxs)("span",{children:[(0,re.jsx)("span",{className:"text-slate-400",children:"created:"})," ",la().utc(s.created_date).fromNow()]}),s.last_agent_response_date&&(0,re.jsxs)("span",{children:[(0,re.jsx)("span",{className:"text-slate-400",children:"wait time:"})," ",la().utc(s.last_agent_response_date).fromNow()]})]}),(0,re.jsxs)("div",{className:"flex items-center justify-between",children:[(0,re.jsx)("div",{className:"flex items-center space-x-2",children:s.pending_response_from?(0,re.jsx)(et,{variant:"secondary",className:"text-xs ".concat("admin"===s.pending_response_from?"bg-orange-100 text-orange-800 border-orange-200":"user"===s.pending_response_from?"bg-blue-100 text-blue-800 border-blue-200":"bg-gray-100 text-gray-800 border-gray-200"),children:"admin"===s.pending_response_from?"Pending Admin":"user"===s.pending_response_from?"Pending User":s.pending_response_from}):(0,re.jsx)(et,{variant:"secondary",className:"text-xs bg-green-100 text-green-800 border-green-200",children:"Resolved"})}),(0,re.jsx)("div",{className:"flex items-center space-x-2",children:(0,re.jsx)("span",{className:"text-xs text-slate-500",children:s.assigned_to?(0,re.jsxs)("span",{children:[(0,re.jsx)("span",{className:"text-slate-400",children:"assigned:"})," ",s.assigned_to.split("@")[0]]}):(0,re.jsx)("span",{className:"text-slate-400 italic",children:"Unassigned"})})})]}),(c.length>0||i)&&(0,re.jsxs)("div",{className:"mt-1.5 flex items-center space-x-1.5 bg-teal-50 rounded-md px-2 py-1",children:[(0,re.jsx)(oh.A,{className:"w-3 h-3 text-teal-600"}),(0,re.jsxs)("div",{className:"flex -space-x-2",children:[i&&(0,re.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,s)=>(0,re.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,re.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,re.jsxs)("div",{className:"flex items-center space-x-1",children:[(0,re.jsx)("div",{className:"w-1.5 h-1.5 bg-teal-500 rounded-full animate-pulse"}),(0,re.jsx)("span",{className:"text-xs text-teal-700 font-medium",children:[...i?["You"]:[],...c.map(e=>e.name.split(" ")[0])].join(", ")})]})]})]})]})};function by(){const{user:e}=oe(),s=(0,Z.Zp)(),[t]=(0,J.useSearchParams)(),a=t.get("conversationId"),[n,r]=(0,H.useState)([]),[l,i]=(0,H.useState)(!0),[o,c]=(0,H.useState)(!1),[d,m]=(0,H.useState)(null),[u,x]=(0,H.useState)(""),[h,p]=(0,H.useState)(null),[g,f]=(0,H.useState)(new Set),[v,b]=(0,H.useState)(!1),[j,y]=(0,H.useState)("desc"),[N,w]=(0,H.useState)("last_agent_response_date"),[_,k]=(0,H.useState)(!1),[A,S]=(0,H.useState)({}),[C,E]=(0,H.useState)({status:"",category:"",user_subscription_tier:"",app_id:"",created_by:"",assigned_to:"",internal_category:"",is_escalated:""});(0,H.useEffect)(()=>{I(!0)},[]),(0,H.useEffect)(()=>{n.length>0&&I()},[_,N,j]),(0,H.useEffect)(()=>{p(a||null)},[a]),(0,H.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"),s("?".concat(e.toString()),{replace:!0})}}},[n,h,s]),(0,H.useEffect)(()=>{const e=()=>{const e=new URLSearchParams(window.location.search).get("conversationId");if(e){n.find(s=>s.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 s=await fj.getTickets({show_resolved:_,sort_field:N,sort_direction:j});r(s||[])}catch(s){m("Failed to load support tickets. Please try again.")}finally{i(!1),c(!1)}},T=e=>{p(e.id);const t=new URLSearchParams(window.location.search);t.set("conversationId",e.id),s("?".concat(t.toString()),{replace:!0})};(0,H.useEffect)(()=>{let e=null;return(async()=>{e=await kj.fetchAndSubscribe("realtime",e=>{if(e&&e.records){const s={};e.records.forEach(e=>{s[e.ticket_id]||(s[e.ticket_id]=[]),s[e.ticket_id].push({id:e.agent_user_id,name:e.agent_name,updatedAt:e.updated_date})}),S(s)}})})(),()=>{e&&e()}},[]),(0,H.useEffect)(()=>{e&&e.id&&h?kj.updateRecord(e.id,h):e&&e.id&&!h&&kj.updateRecord(e.id,null)},[e,h]);const P=(e,s)=>{f(t=>{const a=new Set(t);return s?a.add(e):a.delete(e),a})},L=((e,s)=>{if(!s)return e;const t=s.toLowerCase();return e.filter(e=>{var s,a,n,r;return(null===(s=e.title)||void 0===s?void 0:s.toLowerCase().includes(t))||(null===(a=e.content)||void 0===a?void 0:a.toLowerCase().includes(t))||(null===(n=e.app_id)||void 0===n?void 0:n.toLowerCase().includes(t))||(null===(r=e.created_by)||void 0===r?void 0:r.toLowerCase().includes(t))})})((()=>{let e=n;return"resolved"===C.status?e=e.filter(e=>"resolved"===e.ticket_status):"all"===C.status||("admin"===C.status||"user"===C.status?e=e.filter(e=>"resolved"!==e.ticket_status&&e.pending_response_from===C.status):_&&(e=e.filter(e=>"resolved"!==e.ticket_status))),C.category&&(e=e.filter(e=>e.category===C.category)),C.user_subscription_tier&&(e=e.filter(e=>e.user_subscription_tier===C.user_subscription_tier)),C.assigned_to&&(e="unassigned"===C.assigned_to?e.filter(e=>!e.assigned_to):e.filter(e=>e.assigned_to===C.assigned_to)),C.internal_category&&(e=e.filter(e=>e.internal_categories&&e.internal_categories.includes(C.internal_category))),!0===C.is_escalated&&(e=e.filter(e=>!0===e.is_escalated)),e})(),u),O=[...L].sort((e,s)=>{let t=0;if("updated_date"===N||"created_date"===N||"last_agent_response_date"===N){t=new Date(e[N])-new Date(s[N])}else"subject"===N?t=(e.title||"").localeCompare(s.title||""):"category"===N?t=(e.category||"").localeCompare(s.category||""):"assigned_to"===N&&(t=(e.assigned_to||"").localeCompare(s.assigned_to||""));return"desc"===j?-t:t}),R=(e=>{const s={status:{},tier:{},category:{},assigned_to:{},internal_categories:{},escalated:0};return e.forEach(e=>{if("resolved"===e.ticket_status)return void(s.status.resolved=(s.status.resolved||0)+1);const t=e.pending_response_from;t&&(s.status[t]=(s.status[t]||0)+1);const a=e.user_subscription_tier||"free";s.tier[a]=(s.tier[a]||0)+1;const n=e.category;n&&(s.category[n]=(s.category[n]||0)+1);const r=e.assigned_to||"unassigned";s.assigned_to[r]=(s.assigned_to[r]||0)+1,!0===e.is_escalated&&s.escalated++,e.internal_categories&&Array.isArray(e.internal_categories)&&e.internal_categories.forEach(e=>{s.internal_categories[e]=(s.internal_categories[e]||0)+1})}),s.total=e.length,s.pending_admin=s.status.admin||0,s.pending_user=s.status.user||0,s.resolved=s.status.resolved||0,s})(n),D=h?n.find(e=>e.id===h):null;return l?(0,re.jsx)("div",{className:"h-screen flex items-center justify-center",children:(0,re.jsxs)("div",{className:"text-center",children:[(0,re.jsx)("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-slate-400 mx-auto mb-4"}),(0,re.jsx)("p",{className:"text-slate-600",children:"Loading conversations..."})]})}):d&&0===n.length?(0,re.jsx)(ny,{error:d,onRetry:()=>I(!0)}):(0,re.jsxs)("div",{className:"w-full h-screen bg-slate-50",children:[(0,re.jsx)("div",{className:"bg-white border-b border-slate-200 px-4 md:px-6 py-3 relative z-10",children:(0,re.jsxs)("div",{className:"flex items-center justify-between flex-wrap gap-2",children:[(0,re.jsxs)("div",{className:"flex items-center space-x-2 md:space-x-4",children:[(0,re.jsx)("h1",{className:"text-lg md:text-xl font-semibold text-slate-900",children:"Support Admin"}),(0,re.jsxs)("span",{className:"text-xs md:text-sm text-slate-500",children:[O.length," conversations"]}),o&&(0,re.jsxs)("div",{className:"flex items-center space-x-2 text-sm text-slate-500",children:[(0,re.jsx)("div",{className:"animate-spin rounded-full h-3 w-3 border-b-2 border-slate-400"}),(0,re.jsx)("span",{children:"Refreshing..."})]})]}),(0,re.jsxs)("div",{className:"flex items-center space-x-2",children:[g.size>0&&(0,re.jsxs)(Hs,{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),t=await fj.resolveMany(e);if(t.resolved&&t.resolved.length>0){var s;f(new Set),await I();const e=t.resolved.length,a=(null===(s=t.errors)||void 0===s?void 0:s.length)||0;let n="Successfully resolved ".concat(e," ticket").concat(e>1?"s":"");a>0&&(n+=" (".concat(a," failed)")),alert(n)}}catch(t){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,re.jsx)("div",{className:"animate-spin rounded-full h-4 w-4 border-b-2 border-white mr-2"}):(0,re.jsx)(nl.A,{className:"w-4 h-4 mr-2"}),"Resolve ",g.size," ticket",g.size>1?"s":""]}),(0,re.jsxs)(Hs,{onClick:()=>s("/support/admin/agent-backoffice"),variant:"outline",size:"sm",children:[(0,re.jsx)(od.A,{className:"w-4 h-4 mr-2"}),"AI Settings"]}),(0,re.jsxs)(Hs,{onClick:()=>I(),variant:"outline",size:"sm",disabled:o,children:[(0,re.jsx)(ku.A,{className:"w-4 h-4 mr-2 ".concat(o?"animate-spin":"")}),"Refresh"]})]})]})}),(0,re.jsxs)(jh,{direction:"horizontal",style:{height:"calc(100vh - 80px)"},children:[(0,re.jsx)(yh,{defaultSize:8,minSize:5,maxSize:25,className:"hidden md:block",children:(0,re.jsx)(fy,{filters:C,onFilterChange:(e,s)=>{E(t=>(0,K.A)((0,K.A)({},t),{},{[e]:"all"===s?"":s}))},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,re.jsx)(Nh,{withHandle:!0,className:"hidden md:flex group transition-opacity opacity-0 hover:opacity-100 focus:opacity-100"}),(0,re.jsxs)(yh,{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,re.jsxs)("div",{className:"flex-shrink-0 bg-white border-b border-slate-200 p-3 flex items-center justify-between",children:[(0,re.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,re.jsx)(ed,{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,re.jsx)("span",{className:"text-xs text-slate-600",children:"Select all open tickets"})]}),(0,re.jsxs)("div",{className:"flex items-center space-x-1 text-xs text-slate-500",children:[(0,re.jsx)("span",{children:"Sort:"}),(0,re.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,re.jsx)("option",{value:"last_agent_response_date",children:"Wait Time"}),(0,re.jsx)("option",{value:"updated_date",children:"Updated"}),(0,re.jsx)("option",{value:"created_date",children:"Created"}),(0,re.jsx)("option",{value:"subject",children:"Subject"}),(0,re.jsx)("option",{value:"category",children:"Category"}),(0,re.jsx)("option",{value:"assigned_to",children:"Assigned"})]}),(0,re.jsx)(Hs,{onClick:()=>y("desc"===j?"asc":"desc"),variant:"ghost",size:"sm",className:"h-5 w-5 p-0",children:"desc"===j?(0,re.jsx)(Sc.A,{className:"w-3 h-3"}):(0,re.jsx)(Bs.A,{className:"w-3 h-3"})})]})]}),(0,re.jsx)("div",{className:"flex-1 overflow-y-auto",children:0===L.length?(0,re.jsx)("div",{className:"p-8 text-center text-slate-500",children:(0,re.jsx)("p",{children:"No conversations found"})}):(0,re.jsx)("div",{children:O.map(e=>(0,re.jsx)(vy,{ticket:e,isSelected:h===e.id,onClick:T,onCheckboxToggle:P,showCheckbox:g.has(e.id),activeAgents:A[e.id],isCurrentUserViewing:h===e.id},e.id))})})]}),(0,re.jsx)(Nh,{withHandle:!0,className:"group transition-opacity opacity-0 hover:opacity-100 focus:opacity-100"}),(0,re.jsx)(yh,{defaultSize:50,minSize:10,className:"bg-white min-w-0 overflow-hidden",children:D?(0,re.jsx)(gy,{conversationId:h,isEmbedded:!0,onTicketUpdated:(e,s,t,a)=>{r(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"===s)return(0,K.A)((0,K.A)({},n),{},{assigned_to:t,updated_date:(new Date).toISOString()});if("categories_updated"===s)return(0,K.A)((0,K.A)({},n),{},{updated_date:(new Date).toISOString()});if("message_sent"===s){const e="admin"===t;return(0,K.A)((0,K.A)({},n),{},{pending_response_from:e?"user":"admin",updated_date:(new Date).toISOString()})}return"ticket_closed"===s?(0,K.A)((0,K.A)({},n),{},{ticket_status:"resolved",updated_date:(new Date).toISOString()}):(0,K.A)((0,K.A)({},n),{},{ticket_status:s,updated_date:(new Date).toISOString()})}return n}))}}):(0,re.jsx)("div",{className:"h-full flex items-center justify-center text-slate-500 p-4",children:(0,re.jsxs)("div",{className:"text-center max-w-md",children:[(0,re.jsx)("div",{className:"w-16 h-16 bg-slate-100 rounded-full flex items-center justify-center mx-auto mb-4",children:(0,re.jsx)(od.A,{className:"w-8 h-8"})}),(0,re.jsx)("h3",{className:"text-lg font-medium text-slate-900 mb-2",children:"Select a conversation"}),(0,re.jsx)("p",{className:"text-slate-600 text-sm",children:"Choose a support ticket from the list to view details and respond"})]})})})]})]})}const jy=e=>{if(!e)return"Not available";const s=la().utc(e);return"".concat(s.format("MMM DD, YYYY")," (").concat(s.fromNow(),")")},yy=e=>{let{article:s,onEdit:t,onDelete:a}=e;return(0,re.jsxs)(it,{className:"group hover:shadow-lg transition-all duration-300 border-slate-200 hover:border-slate-300",children:[(0,re.jsx)(ot,{className:"pb-3",children:(0,re.jsxs)("div",{className:"flex items-start justify-between",children:[(0,re.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,re.jsx)(ct,{className:"text-lg font-semibold text-slate-900 truncate group-hover:text-slate-700 transition-colors",children:s.title}),(0,re.jsxs)("div",{className:"flex items-center space-x-2 mt-2",children:[(0,re.jsxs)(et,{variant:"outline",className:"text-xs",children:[(0,re.jsx)(al.A,{className:"w-3 h-3 mr-1"}),"Article"]}),s.created_date&&(0,re.jsxs)("span",{className:"text-xs text-slate-500",children:["Created ",jy(s.created_date)]})]})]}),(0,re.jsxs)("div",{className:"flex items-center space-x-2 ml-4",children:[(0,re.jsx)(Hs,{variant:"ghost",size:"sm",onClick:()=>t(s),className:"opacity-0 group-hover:opacity-100 transition-opacity",children:(0,re.jsx)(Hr.A,{className:"w-4 h-4"})}),(0,re.jsx)(Hs,{variant:"ghost",size:"sm",onClick:()=>a(s),className:"opacity-0 group-hover:opacity-100 transition-opacity text-red-600 hover:text-red-800",children:(0,re.jsx)(_u.A,{className:"w-4 h-4"})})]})]})}),(0,re.jsx)(mt,{className:"pt-0",children:(0,re.jsx)("p",{className:"text-slate-600 text-sm leading-relaxed line-clamp-3",children:s.content||"No content available"})})]})},Ny=e=>{let{article:s,isOpen:t,onClose:a,onSave:n,isCreating:r}=e;const[l,i]=(0,H.useState)(""),[o,c]=(0,H.useState)(""),[d,m]=(0,H.useState)(!1);(0,H.useEffect)(()=>{s?(i(s.title||""),c(s.content||"")):(i(""),c(""))},[s,t]);return(0,re.jsx)(Pa,{open:t,onOpenChange:a,children:(0,re.jsxs)(Ma,{className:"max-w-4xl max-h-[80vh] overflow-y-auto",children:[(0,re.jsx)(Fa,{children:(0,re.jsxs)(Ua,{className:"flex items-center",children:[(0,re.jsx)(al.A,{className:"w-5 h-5 mr-2"}),r?"Create New Article":"Edit Article"]})}),(0,re.jsxs)("div",{className:"space-y-6 py-4",children:[(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsx)(Nt,{htmlFor:"title",children:"Title"}),(0,re.jsx)(ft,{id:"title",value:l,onChange:e=>i(e.target.value),placeholder:"Enter article title...",className:"w-full"})]}),(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsx)(Nt,{htmlFor:"content",children:"Content"}),(0,re.jsx)(td,{id:"content",value:o,onChange:e=>c(e.target.value),placeholder:"Enter article content...",className:"min-h-[400px] resize-none"}),(0,re.jsx)("p",{className:"text-xs text-slate-500",children:"You can use markdown formatting for better presentation."})]}),(0,re.jsxs)("div",{className:"flex justify-end space-x-3",children:[(0,re.jsx)(Hs,{variant:"outline",onClick:a,children:"Cancel"}),(0,re.jsx)(Hs,{onClick:async()=>{if(l.trim()&&o.trim()){m(!0);try{await n({id:null==s?void 0:s.id,title:l.trim(),content:o.trim()}),a()}catch(e){}finally{m(!1)}}},disabled:d||!l.trim()||!o.trim(),children:d?(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)("div",{className:"w-4 h-4 border-2 border-white border-t-transparent rounded-full animate-spin mr-2"}),"Saving..."]}):(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(ah.A,{className:"w-4 h-4 mr-2"}),r?"Create Article":"Save Changes"]})})]})]})]})})},wy=e=>{let{categories:s,onSave:t}=e;const[a,n]=(0,H.useState)([]),[r,l]=(0,H.useState)(""),[i,o]=(0,H.useState)(!1),[c,d]=(0,H.useState)(!1);(0,H.useEffect)(()=>{n(s||[])},[s]);const m=()=>{const e=r.trim();e&&!a.includes(e)&&(n([...a,e]),l(""))};return(0,re.jsxs)(it,{children:[(0,re.jsx)(ot,{children:(0,re.jsxs)("div",{className:"flex items-center justify-between",children:[(0,re.jsxs)(ct,{className:"flex items-center",children:[(0,re.jsx)(xj.A,{className:"w-5 h-5 mr-2"}),"Internal Category Options"]}),!i&&(0,re.jsxs)(Hs,{variant:"outline",size:"sm",onClick:()=>o(!0),children:[(0,re.jsx)(Hr.A,{className:"w-4 h-4 mr-2"}),"Edit"]})]})}),(0,re.jsx)(mt,{children:i?(0,re.jsxs)("div",{className:"space-y-4",children:[(0,re.jsxs)("div",{className:"space-y-3",children:[(0,re.jsxs)("div",{className:"flex space-x-2",children:[(0,re.jsx)(ft,{value:r,onChange:e=>l(e.target.value),placeholder:"Add new internal category...",onKeyPress:e=>{"Enter"===e.key&&(e.preventDefault(),m())},className:"flex-1"}),(0,re.jsx)(Hs,{onClick:m,disabled:!r.trim(),children:(0,re.jsx)(Ss.A,{className:"w-4 h-4"})})]}),(0,re.jsxs)("div",{className:"space-y-2 max-h-48 overflow-y-auto",children:[a.map((e,s)=>(0,re.jsxs)("div",{className:"flex items-center justify-between p-2 bg-slate-50 rounded-lg",children:[(0,re.jsx)("span",{className:"text-sm text-slate-700",children:e}),(0,re.jsx)(Hs,{variant:"ghost",size:"sm",onClick:()=>{return s=e,void n(a.filter(e=>e!==s));var s},className:"text-red-600 hover:text-red-800 h-6 w-6 p-0",children:(0,re.jsx)(zs.A,{className:"w-3 h-3"})})]},s)),0===a.length&&(0,re.jsx)("p",{className:"text-sm text-slate-500 text-center py-4",children:"No internal categories defined yet"})]})]}),(0,re.jsxs)("div",{className:"flex justify-end space-x-3",children:[(0,re.jsxs)(Hs,{variant:"outline",onClick:()=>{n(s||[]),l(""),o(!1)},children:[(0,re.jsx)(zs.A,{className:"w-4 h-4 mr-2"}),"Cancel"]}),(0,re.jsx)(Hs,{onClick:async()=>{d(!0);try{await t(a),o(!1)}catch(e){}finally{d(!1)}},disabled:c,children:c?(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)("div",{className:"w-4 h-4 border-2 border-white border-t-transparent rounded-full animate-spin mr-2"}),"Saving..."]}):(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(ah.A,{className:"w-4 h-4 mr-2"}),"Save Categories"]})})]})]}):(0,re.jsxs)("div",{className:"space-y-3",children:[(0,re.jsx)("div",{className:"flex flex-wrap gap-2",children:a.length>0?a.map((e,s)=>(0,re.jsxs)(et,{variant:"outline",className:"text-xs",children:[(0,re.jsx)(xj.A,{className:"w-3 h-3 mr-1"}),e]},s)):(0,re.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,re.jsx)("p",{className:"text-xs text-slate-500",children:"These categories can be assigned to support tickets for internal organization and tracking."})]})})]})},_y=e=>{let{title:s,systemPrompt:t,onSave:a,promptKey:n}=e;const[r,l]=(0,H.useState)(""),[i,o]=(0,H.useState)(!1),[c,d]=(0,H.useState)(!1);(0,H.useEffect)(()=>{l(t||"")},[t]);return(0,re.jsxs)(it,{children:[(0,re.jsx)(ot,{children:(0,re.jsxs)("div",{className:"flex items-center justify-between",children:[(0,re.jsxs)(ct,{className:"flex items-center",children:[(0,re.jsx)(ih.A,{className:"w-5 h-5 mr-2"}),s]}),!i&&(0,re.jsxs)(Hs,{variant:"outline",size:"sm",onClick:()=>o(!0),children:[(0,re.jsx)(Hr.A,{className:"w-4 h-4 mr-2"}),"Edit"]})]})}),(0,re.jsx)(mt,{children:i?(0,re.jsxs)("div",{className:"space-y-4",children:[(0,re.jsx)(td,{value:r,onChange:e=>l(e.target.value),placeholder:"Enter ".concat(s.toLowerCase()," for AI assistance..."),className:"min-h-[200px] resize-none"}),(0,re.jsxs)("div",{className:"flex justify-end space-x-3",children:[(0,re.jsxs)(Hs,{variant:"outline",onClick:()=>{l(t||""),o(!1)},children:[(0,re.jsx)(zs.A,{className:"w-4 h-4 mr-2"}),"Cancel"]}),(0,re.jsx)(Hs,{onClick:async()=>{d(!0);try{await a(n,r),o(!1)}catch(e){}finally{d(!1)}},disabled:c,children:c?(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)("div",{className:"w-4 h-4 border-2 border-white border-t-transparent rounded-full animate-spin mr-2"}),"Saving..."]}):(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(ah.A,{className:"w-4 h-4 mr-2"}),"Save Prompt"]})})]})]}):(0,re.jsxs)("div",{className:"space-y-3",children:[(0,re.jsx)("div",{className:"bg-slate-50 rounded-lg p-4 border",children:(0,re.jsx)("pre",{className:"whitespace-pre-wrap text-sm text-slate-700 font-sans leading-relaxed",children:r||"No ".concat(s.toLowerCase()," configured")})}),(0,re.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."})]})})]})},ky="support_templates",Ay=()=>{try{const e=localStorage.getItem(ky);return e?JSON.parse(e):[]}catch(e){return[]}},Sy=e=>{try{localStorage.setItem(ky,JSON.stringify(e)),window.dispatchEvent(new CustomEvent("templatesUpdated"))}catch(s){}},Cy=e=>{let{onTemplateUpdated:s}=e;const[t,a]=(0,H.useState)([]),[n,r]=(0,H.useState)(null),[l,i]=(0,H.useState)(!1),[o,c]=(0,H.useState)(""),[d,m]=(0,H.useState)(""),[u,x]=(0,H.useState)(!1),[h,p]=(0,H.useState)(null);(0,H.useEffect)(()=>{a(Ay())},[]);const g=()=>{r(null),i(!0),c(""),m("")};return(0,re.jsxs)("div",{className:"space-y-6",children:[(l||n)&&(0,re.jsxs)(it,{children:[(0,re.jsx)(ot,{children:(0,re.jsxs)(ct,{className:"flex items-center",children:[(0,re.jsx)(al.A,{className:"w-5 h-5 mr-2"}),l?"Create New Template":"Edit Template"]})}),(0,re.jsxs)(mt,{className:"space-y-4",children:[(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsx)(Nt,{htmlFor:"templateName",children:"Template Name"}),(0,re.jsx)(ft,{id:"templateName",value:o,onChange:e=>c(e.target.value),placeholder:"Enter template name...",className:"w-full"})]}),(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsx)(Nt,{htmlFor:"templateContent",children:"Template Content"}),(0,re.jsx)(td,{id:"templateContent",value:d,onChange:e=>m(e.target.value),placeholder:"Enter template content...",className:"min-h-[200px] resize-none"})]}),(0,re.jsxs)("div",{className:"flex justify-end space-x-3",children:[(0,re.jsxs)(Hs,{variant:"outline",onClick:()=>{r(null),i(!1),c(""),m("")},children:[(0,re.jsx)(zs.A,{className:"w-4 h-4 mr-2"}),"Cancel"]}),(0,re.jsx)(Hs,{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()},l=n?t.map(s=>s.id===n.id?e:s):[...t,e];a(l),Sy(l),r(null),i(!1),c(""),m(""),s&&s(l)}catch(e){}finally{x(!1)}}},disabled:u||!o.trim()||!d.trim(),children:u?(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)("div",{className:"w-4 h-4 border-2 border-white border-t-transparent rounded-full animate-spin mr-2"}),"Saving..."]}):(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(ah.A,{className:"w-4 h-4 mr-2"}),l?"Create Template":"Save Changes"]})})]})]})]}),(0,re.jsxs)(it,{children:[(0,re.jsx)(ot,{children:(0,re.jsxs)("div",{className:"flex items-center justify-between",children:[(0,re.jsxs)(ct,{className:"flex items-center",children:[(0,re.jsx)(al.A,{className:"w-5 h-5 mr-2"}),"Response Templates (",t.length,")"]}),!l&&!n&&(0,re.jsxs)(Hs,{onClick:g,children:[(0,re.jsx)(Ss.A,{className:"w-4 h-4 mr-2"}),"New Template"]})]})}),(0,re.jsx)(mt,{children:0===t.length?(0,re.jsxs)("div",{className:"text-center py-8",children:[(0,re.jsx)("div",{className:"mx-auto w-16 h-16 bg-slate-100 rounded-full flex items-center justify-center mb-4",children:(0,re.jsx)(al.A,{className:"w-8 h-8 text-slate-400"})}),(0,re.jsx)("h3",{className:"text-lg font-medium text-slate-900 mb-2",children:"No Templates Yet"}),(0,re.jsx)("p",{className:"text-slate-600 mb-4",children:"Create reusable response templates to speed up your workflow."}),(0,re.jsxs)(Hs,{onClick:g,children:[(0,re.jsx)(Ss.A,{className:"w-4 h-4 mr-2"}),"Create First Template"]})]}):(0,re.jsx)("div",{className:"space-y-3",children:t.map(e=>(0,re.jsxs)("div",{className:"border border-slate-200 rounded-lg p-4 hover:bg-slate-50 transition-colors",children:[(0,re.jsxs)("div",{className:"flex items-start justify-between mb-2",children:[(0,re.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,re.jsx)("h4",{className:"text-sm font-medium text-slate-900 truncate",children:e.name}),(0,re.jsxs)("p",{className:"text-xs text-slate-500 mt-1",children:["Created ",jy(e.created_date),e.updated_date!==e.created_date&&(0,re.jsxs)("span",{children:[" \u2022 Updated ",jy(e.updated_date)]})]})]}),(0,re.jsxs)("div",{className:"flex items-center space-x-2 ml-4",children:[(0,re.jsx)(Hs,{variant:"ghost",size:"sm",onClick:()=>(e=>{r(e),i(!1),c(e.name),m(e.content)})(e),className:"h-8 w-8 p-0",children:(0,re.jsx)(Hr.A,{className:"w-4 h-4"})}),(0,re.jsx)(Hs,{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,re.jsx)(_u.A,{className:"w-4 h-4"})})]})]}),(0,re.jsx)("div",{className:"text-sm text-slate-600 bg-slate-50 rounded p-3 border",children:(0,re.jsx)("div",{className:"line-clamp-3",children:e.content})})]},e.id))})})]}),(0,re.jsx)(Pa,{open:!!h,onOpenChange:()=>p(null),children:(0,re.jsxs)(Ma,{children:[(0,re.jsx)(Fa,{children:(0,re.jsxs)(Ua,{className:"flex items-center text-red-600",children:[(0,re.jsx)(Xe.A,{className:"w-5 h-5 mr-2"}),"Delete Template"]})}),(0,re.jsx)("div",{className:"py-4",children:(0,re.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,re.jsxs)("div",{className:"flex justify-end space-x-3",children:[(0,re.jsx)(Hs,{variant:"outline",onClick:()=>p(null),children:"Cancel"}),(0,re.jsxs)(Hs,{variant:"destructive",onClick:()=>{if(h){const e=t.filter(e=>e.id!==h.id);a(e),Sy(e),p(null),s&&s(e)}},children:[(0,re.jsx)(_u.A,{className:"w-4 h-4 mr-2"}),"Delete Template"]})]})]})})]})};function Ey(){const e=(0,Z.Zp)(),[s,t]=(0,H.useState)([]),[a,n]=(0,H.useState)(""),[r,l]=(0,H.useState)(""),[i,o]=(0,H.useState)([]),[c,d]=(0,H.useState)([]),[m,u]=(0,H.useState)(!0),[x,h]=(0,H.useState)(null),[p,g]=(0,H.useState)(""),[f,v]=(0,H.useState)(null),[b,j]=(0,H.useState)(!1),[y,N]=(0,H.useState)(!1),[w,_]=(0,H.useState)(null);(0,H.useEffect)(()=>{k(),d(Ay())},[]);const k=async()=>{try{u(!0),h(null);const[e,s]=await Promise.all([bj.getArticles(),bj.getAgentProperties()]);t((null==e?void 0:e.articles)||e||[]),n((null==s?void 0:s.response_system_prompt)||""),l((null==s?void 0:s.polish_system_prompt)||""),o((null==s?void 0:s.internal_category_options)||[])}catch(e){h("Failed to load documentation data. Please try again.")}finally{u(!1)}},A=()=>{v(null),N(!0),j(!0)},S=e=>{v(e),N(!1),j(!0)},C=e=>{_(e)},E=async(e,s)=>{const t={};t[e]=s,await bj.updateAgentProperties(t),"response_system_prompt"===e?n(s):"polish_system_prompt"===e&&l(s)},I=s.filter(e=>{var s,t;return(null===(s=e.title)||void 0===s?void 0:s.toLowerCase().includes(p.toLowerCase()))||(null===(t=e.content)||void 0===t?void 0:t.toLowerCase().includes(p.toLowerCase()))});return m?(0,re.jsx)("div",{className:"w-full max-w-7xl mx-auto px-6 py-12",children:(0,re.jsxs)("div",{className:"animate-pulse space-y-6",children:[(0,re.jsx)("div",{className:"h-8 bg-slate-200 rounded w-1/3"}),(0,re.jsxs)("div",{className:"grid grid-cols-1 gap-6",children:[(0,re.jsx)("div",{className:"h-48 bg-slate-200 rounded-lg"}),(0,re.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,re.jsx)("div",{className:"h-32 bg-slate-200 rounded-lg"},e))})]})]})}):x?(0,re.jsx)("div",{className:"w-full max-w-7xl mx-auto px-6 py-12",children:(0,re.jsxs)("div",{className:"text-center py-16",children:[(0,re.jsx)("div",{className:"mx-auto w-24 h-24 bg-red-100 rounded-full flex items-center justify-center mb-6",children:(0,re.jsx)(Xe.A,{className:"w-12 h-12 text-red-500"})}),(0,re.jsx)("h3",{className:"text-xl font-semibold text-slate-900 mb-2",children:"Error Loading Documentation"}),(0,re.jsx)("p",{className:"text-slate-600 mb-6",children:x}),(0,re.jsx)(Hs,{onClick:k,variant:"outline",children:"Try Again"})]})}):(0,re.jsxs)("div",{className:"w-full max-w-7xl mx-auto px-6 py-12",children:[(0,re.jsx)("div",{className:"mb-8",children:(0,re.jsxs)("div",{className:"flex items-center justify-between mb-6",children:[(0,re.jsxs)("div",{className:"flex items-center space-x-4",children:[(0,re.jsxs)(Hs,{variant:"ghost",size:"sm",onClick:()=>e("/support/admin/conversations"),className:"text-slate-600 hover:text-slate-900",children:[(0,re.jsx)(Cc.A,{className:"w-4 h-4 mr-2"}),"Back to list"]}),(0,re.jsxs)("div",{children:[(0,re.jsx)("h1",{className:"text-3xl font-bold text-slate-900",children:"AI Settings"}),(0,re.jsx)("p",{className:"text-slate-600 mt-1",children:"Manage support articles and AI system prompts"})]})]}),(0,re.jsxs)("div",{className:"flex items-center space-x-3",children:[(0,re.jsxs)(Hs,{onClick:k,variant:"outline",size:"sm",children:[(0,re.jsx)(ku.A,{className:"w-4 h-4 mr-2"}),"Refresh"]}),(0,re.jsxs)(Hs,{onClick:A,children:[(0,re.jsx)(Ss.A,{className:"w-4 h-4 mr-2"}),"New Article"]})]})]})}),(0,re.jsxs)(hl,{defaultValue:"articles",className:"space-y-6",children:[(0,re.jsxs)(pl,{className:"grid w-full grid-cols-4 lg:w-[800px]",children:[(0,re.jsxs)(gl,{value:"articles",className:"flex items-center space-x-2",children:[(0,re.jsx)(Hg.A,{className:"w-4 h-4"}),(0,re.jsxs)("span",{children:["Articles (",s.length,")"]})]}),(0,re.jsxs)(gl,{value:"system-prompts",className:"flex items-center space-x-2",children:[(0,re.jsx)(od.A,{className:"w-4 h-4"}),(0,re.jsx)("span",{children:"System Prompts"})]}),(0,re.jsxs)(gl,{value:"templates",className:"flex items-center space-x-2",children:[(0,re.jsx)(al.A,{className:"w-4 h-4"}),(0,re.jsx)("span",{children:"Templates"})]}),(0,re.jsxs)(gl,{value:"internal-categories",className:"flex items-center space-x-2",children:[(0,re.jsx)(xj.A,{className:"w-4 h-4"}),(0,re.jsx)("span",{children:"Categories"})]})]}),(0,re.jsxs)(fl,{value:"articles",className:"space-y-6",children:[(0,re.jsx)("div",{className:"flex items-center space-x-4",children:(0,re.jsxs)("div",{className:"relative flex-1 max-w-md",children:[(0,re.jsx)(vn.A,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 text-slate-400 w-4 h-4"}),(0,re.jsx)(ft,{placeholder:"Search articles...",value:p,onChange:e=>g(e.target.value),className:"pl-10"})]})}),0===I.length?(0,re.jsxs)("div",{className:"text-center py-16",children:[(0,re.jsx)("div",{className:"mx-auto w-24 h-24 bg-slate-100 rounded-full flex items-center justify-center mb-6",children:(0,re.jsx)(al.A,{className:"w-12 h-12 text-slate-400"})}),(0,re.jsx)("h3",{className:"text-xl font-semibold text-slate-900 mb-2",children:p?"No Articles Found":"No Articles Yet"}),(0,re.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,re.jsxs)(Hs,{onClick:A,children:[(0,re.jsx)(Ss.A,{className:"w-4 h-4 mr-2"}),"Create First Article"]})]}):(0,re.jsx)("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6",children:I.map(e=>(0,re.jsx)(yy,{article:e,onEdit:S,onDelete:C},e.id))})]}),(0,re.jsxs)(fl,{value:"system-prompts",className:"space-y-6",children:[(0,re.jsx)(_y,{title:"Response System Prompt",systemPrompt:a,onSave:E,promptKey:"response_system_prompt"}),(0,re.jsx)(_y,{title:"Polish System Prompt",systemPrompt:r,onSave:E,promptKey:"polish_system_prompt"})]}),(0,re.jsx)(fl,{value:"templates",className:"space-y-6",children:(0,re.jsx)(Cy,{onTemplateUpdated:e=>{d(e)}})}),(0,re.jsx)(fl,{value:"internal-categories",className:"space-y-6",children:(0,re.jsx)(wy,{categories:i,onSave:async e=>{await bj.updateAgentProperties({internal_category_options:e}),o(e)}})})]}),(0,re.jsx)(Ny,{article:f,isOpen:b,onClose:()=>j(!1),onSave:async e=>{y?await bj.createArticle(e):await bj.updateArticle(e.id,e),await k()},isCreating:y}),(0,re.jsx)(Pa,{open:!!w,onOpenChange:()=>_(null),children:(0,re.jsxs)(Ma,{children:[(0,re.jsx)(Fa,{children:(0,re.jsxs)(Ua,{className:"flex items-center text-red-600",children:[(0,re.jsx)(Xe.A,{className:"w-5 h-5 mr-2"}),"Delete Article"]})}),(0,re.jsx)("div",{className:"py-4",children:(0,re.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,re.jsxs)("div",{className:"flex justify-end space-x-3",children:[(0,re.jsx)(Hs,{variant:"outline",onClick:()=>_(null),children:"Cancel"}),(0,re.jsxs)(Hs,{variant:"destructive",onClick:async()=>{if(w)try{await bj.deleteArticle(w.id),await k(),_(null)}catch(x){}},children:[(0,re.jsx)(_u.A,{className:"w-4 h-4 mr-2"}),"Delete Article"]})]})]})})]})}const Iy=(0,H.createContext)();function Ty(e){var s;let{children:t,workspaceId:a}=e;const[n,r]=(0,H.useState)(null),[l,i]=(0,H.useState)(!0),[o,c]=(0,H.useState)(null),[d,m]=(0,H.useState)([]),[u,x]=(0,H.useState)(!1),[h,p]=(0,H.useState)(!1),[g,f]=(0,H.useState)(null),v=(0,H.useRef)(null),b=(0,H.useCallback)(async()=>{try{i(!0),c(null);const e=await xe.getDashboard(a);r(e),v.current&&v.current(),v.current=xe.subscribeToDashboard(a,e,(s,t)=>{var a,n;const l=(0,K.A)((0,K.A)((0,K.A)({},e),s),{},{workspace:(0,K.A)((0,K.A)((0,K.A)({},e.workspace),s.workspace),{},{is_personal:void 0!==(null===(a=s.workspace)||void 0===a?void 0:a.is_personal)?s.workspace.is_personal:null===(n=e.workspace)||void 0===n?void 0:n.is_personal})});r(l)})}catch(e){c(e)}finally{i(!1)}},[a]),j=(0,H.useCallback)(async()=>{try{const e=await xe.getAvailablePlans();m(e.plans||[])}catch(o){m([])}},[]),y=(0,H.useCallback)(async()=>{await b()},[b]),N=(0,H.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,H.useCallback)(()=>["owner","admin"].includes(null==n?void 0:n.user_role),[n]),_=(0,H.useCallback)(async(e,s)=>{x(!0);try{await xe.inviteUser(e,s,a)}catch(o){throw o}finally{x(!1)}},[a]),k=(0,H.useCallback)(async(e,s)=>{x(!0);try{await xe.updateMemberRole(e,s,a)}catch(o){throw o}finally{x(!1)}},[a]),A=(0,H.useCallback)(async(e,s)=>{x(!0);try{await xe.updateMemberSeat(e,s,a)}catch(o){throw o}finally{x(!1)}},[a]),S=(0,H.useCallback)(e=>{f(e),p(!0)},[]),C=(0,H.useCallback)(()=>{p(!1),f(null)},[]),E=(0,H.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,H.useCallback)(async(e,s,t)=>{x(!0);try{let r;if(r="buy"===t?await xe.buySeats(e,s,a):await xe.removeSeats(e,s,a),!r)throw new Error("Invalid response from server");if("stripe_checkout_required"===r.status)try{const e=await Ji.createWorkspaceCheckoutSession(r.workspace_id,r.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,H.useEffect)(()=>(b(),j(),()=>{v.current&&v.current()}),[b,j]);const T={loading:l,error:o,actionLoading:u,availablePlans:d,currentWorkspace:null==n?void 0:n.workspace,plans:(null==n||null===(s=n.workspace)||void 0===s?void 0:s.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:A,showRemoveMemberDialog:S,hideRemoveMemberDialog:C,confirmRemoveMember:E,manageSeat:I,handleCheckoutSuccess:y,canInviteUsers:N,canManageSeats:w};return(0,re.jsx)(Iy.Provider,{value:T,children:t})}function Py(){const e=(0,H.useContext)(Iy);if(!e)throw new Error("useWorkspaceDashboard must be used within a WorkspaceDashboardProvider");return e}const Ly=e=>{let{users:s,onSelectUser:t,anchorElement:a,onClose:n}=e;const[r,l]=(0,H.useState)({left:0,top:0,width:0}),i=(0,H.useRef)(null);(0,H.useEffect)(()=>{const e=()=>{if(!a)return;const e=a.getBoundingClientRect(),s=window.innerHeight,t=window.innerWidth,n=Math.max(e.width,300),r=s-e.bottom,i=e.top,o=r<192&&i>192;let c=e.left;c+n>t&&(c=t-n-10),c<10&&(c=10),l({left:c,top:o?e.top-192-4:e.bottom+4,width:n})};e();const s=()=>e(),t=()=>e();return window.addEventListener("scroll",s,!0),window.addEventListener("resize",t),()=>{window.removeEventListener("scroll",s,!0),window.removeEventListener("resize",t)}},[a]),(0,H.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,re.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(r.left,"px"),top:"".concat(r.top,"px"),width:"".concat(r.width,"px")},children:s.map(e=>(0,re.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:()=>t(e.email),children:(0,re.jsxs)("div",{className:"flex items-center gap-2",children:[(0,re.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,re.jsx)(np.A,{className:"w-3 h-3 text-orange-600"})}),(0,re.jsxs)("div",{className:"flex flex-col",children:[(0,re.jsx)("span",{className:"text-sm font-medium text-slate-700 truncate max-w-[200px]",children:e.email}),"pending"===e.status&&(0,re.jsx)("span",{className:"text-xs text-orange-500 font-medium",children:"Pending invitation"})]})]})},e.email))});return mc.createPortal(o,document.body)},Oy=e=>{let{anchorElement:s,onClose:t}=e;const[a,n]=(0,H.useState)({left:0,top:0,width:0}),r=(0,H.useRef)(null);(0,H.useEffect)(()=>{const e=()=>{if(!s)return;const e=s.getBoundingClientRect(),t=window.innerWidth,a=Math.max(e.width,300);let r=e.left;r+a>t&&(r=t-a-10),r<10&&(r=10),n({left:r,top:e.bottom+4,width:a})};e();const t=()=>e(),a=()=>e();return window.addEventListener("scroll",t,!0),window.addEventListener("resize",a),()=>{window.removeEventListener("scroll",t,!0),window.removeEventListener("resize",a)}},[s]),(0,H.useEffect)(()=>{const e=e=>{r.current&&!r.current.contains(e.target)&&s&&!s.contains(e.target)&&t()};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[t,s]);const l=(0,re.jsx)("div",{ref:r,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,re.jsx)("div",{className:"px-3 py-2 text-sm text-slate-500 text-center",children:"No users found"})});return mc.createPortal(l,document.body)},Ry=e=>{let{open:s,onOpenChange:t,planName:a}=e;const[n,r]=(0,H.useState)(null),[l,i]=(0,H.useState)(!1),[o,c]=(0,H.useState)(null),[d,m]=(0,H.useState)(new Set),[u,x]=(0,H.useState)(null),[h,p]=(0,H.useState)(""),[g,f]=(0,H.useState)(null),{workspaceId:v,members:b}=Py();(0,H.useEffect)(()=>{s&&a?j():s||(x(null),p(""),f(null))},[s,a]),(0,H.useEffect)(()=>{p(""),f(null)},[u]);const j=async()=>{try{i(!0),c(null),r(null);const e=await xe.getSeatUsage(a,v);r(e.data||e)}catch(t){var e,s;c((null===(e=t.response)||void 0===e||null===(s=e.data)||void 0===s?void 0:s.detail)||"Failed to fetch seat usage data")}finally{i(!1)}},y=async function(e,s){let t=arguments.length>2&&void 0!==arguments[2]&&arguments[2];const l="".concat(a,"_").concat(s);try{if(m(e=>new Set([...e,l])),x(null),p(""),f(null),t)await xe.updateMemberSeat(e,null,v);else{var i;const t=null==n||null===(i=n.plan)||void 0===i?void 0:i.price_id;if(!t)throw new Error("Plan price ID not found");await xe.updateMemberSeat(e,t,v,s)}r(a=>{if(!a)return a;const n=a.seats.map(a=>a.assigned_user===e&&a.seat_number!==s?(0,K.A)((0,K.A)({},a),{},{assigned_user:null,status:"available"}):a.seat_number===s?(0,K.A)((0,K.A)({},a),{},{assigned_user:t?null:e,status:t?"available":"assigned"}):a),r=n.filter(e=>"assigned"===e.status).length,l=a.plan.total_seats-r;return(0,K.A)((0,K.A)({},a),{},{seats:n,summary:(0,K.A)((0,K.A)({},a.summary),{},{total_assigned:r,total_available:l}),plan:(0,K.A)((0,K.A)({},a.plan),{},{used_seats:r,available_seats:l})})})}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 s=new Set(e);return s.delete(l),s})}},N=e=>"assigned"===e?(0,re.jsx)(np.A,{className:"w-3 h-3"}):(0,re.jsx)(Gr.A,{className:"w-3 h-3"});return(0,re.jsx)(Pa,{open:s,onOpenChange:t,children:(0,re.jsxs)(Ma,{className:"max-w-5xl max-h-[90vh] flex flex-col",children:[(0,re.jsxs)(Fa,{className:"pb-3",children:[(0,re.jsxs)(Ua,{className:"flex items-center gap-2 text-lg",children:[(0,re.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,re.jsx)(Gr.A,{className:"w-4 h-4 text-orange-600"})}),(0,re.jsxs)("span",{className:"font-semibold text-slate-800",children:[a," Seats Usage"]})]}),(0,re.jsx)(za,{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."})]}),l&&(0,re.jsx)("div",{className:"flex items-center justify-center p-8",children:(0,re.jsx)("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-orange-500"})}),o&&(0,re.jsx)("div",{className:"p-4 bg-red-50 border border-red-200 rounded-lg",children:(0,re.jsx)("p",{className:"text-red-800 text-sm",children:o})}),n&&(0,re.jsxs)("div",{className:"flex flex-col flex-1 min-h-0",children:[(0,re.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-3 mb-4",children:[(0,re.jsxs)(it,{className:"p-3 bg-gradient-to-br from-orange-50 to-orange-100 border-orange-200",children:[(0,re.jsxs)("div",{className:"flex items-center gap-2 mb-2",children:[(0,re.jsx)("div",{className:"w-6 h-6 bg-orange-500 rounded-full flex items-center justify-center",children:(0,re.jsx)(Gr.A,{className:"w-3 h-3 text-white"})}),(0,re.jsx)("span",{className:"text-xs font-semibold text-slate-700",children:"Total Seats"})]}),(0,re.jsx)("div",{className:"text-xl font-bold text-slate-900",children:n.plan.total_seats})]}),(0,re.jsxs)(it,{className:"p-3 bg-gradient-to-br from-green-50 to-green-100 border-green-200",children:[(0,re.jsxs)("div",{className:"flex items-center gap-2 mb-2",children:[(0,re.jsx)("div",{className:"w-6 h-6 bg-green-500 rounded-full flex items-center justify-center",children:(0,re.jsx)(np.A,{className:"w-3 h-3 text-white"})}),(0,re.jsx)("span",{className:"text-xs font-semibold text-slate-700",children:"Assigned"})]}),(0,re.jsx)("div",{className:"text-xl font-bold text-slate-900",children:n.summary.total_assigned})]}),(0,re.jsxs)(it,{className:"p-3 bg-gradient-to-br from-teal-50 to-teal-100 border-teal-200",children:[(0,re.jsxs)("div",{className:"flex items-center gap-2 mb-2",children:[(0,re.jsx)("div",{className:"w-6 h-6 bg-teal-500 rounded-full flex items-center justify-center",children:(0,re.jsx)(ya.A,{className:"w-3 h-3 text-white"})}),(0,re.jsx)("span",{className:"text-xs font-semibold text-slate-700",children:"Period Usage"})]}),(0,re.jsxs)("div",{className:"text-xl font-bold text-slate-900",children:[n.summary.current_month_usage,"/",n.summary.monthly_limit||0]}),(0,re.jsx)("div",{className:"text-xs text-slate-500 mt-1 font-medium",children:n.summary.period})]})]}),(0,re.jsx)(pt,{className:"mb-4"}),(0,re.jsxs)("div",{children:[(0,re.jsx)("h3",{className:"text-base font-semibold text-slate-900 mb-3",children:"Individual Seats"}),(0,re.jsxs)("div",{className:"border rounded-xl overflow-hidden bg-white shadow-sm",children:[(0,re.jsx)(Or,{children:(0,re.jsx)(Rr,{className:"bg-gradient-to-r from-slate-50 to-slate-100 border-b border-slate-200",children:(0,re.jsxs)(Fr,{children:[(0,re.jsx)(Br,{className:"w-20 font-semibold text-slate-700 py-2",children:"Seat #"}),(0,re.jsx)(Br,{className:"w-24 font-semibold text-slate-700 py-2",children:"Status"}),(0,re.jsx)(Br,{className:"font-semibold text-slate-700 py-2",children:"Assigned User"}),(0,re.jsx)(Br,{className:"w-32 text-right font-semibold text-slate-700 py-2",children:"Period Usage"})]})})}),(0,re.jsx)("div",{className:"max-h-96 overflow-y-auto",children:(0,re.jsx)(Or,{children:(0,re.jsx)(Dr,{children:n.seats.map(e=>{const s=(()=>{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})(),t=d.has("".concat(a,"_").concat(e.seat_number)),n=u===e.seat_number;return(0,re.jsxs)(Fr,{className:"hover:bg-slate-50/50 transition-colors",children:[(0,re.jsxs)(Ur,{className:"font-semibold w-20 text-slate-600 py-2",children:["#",e.seat_number]}),(0,re.jsx)(Ur,{className:"w-24 py-2",children:(0,re.jsxs)(et,{className:"text-xs font-medium ".concat((r=e.status,"assigned"===r?"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,re.jsx)("span",{className:"ml-1 capitalize",children:e.status})]})}),(0,re.jsx)(Ur,{className:"py-2",children:t?(0,re.jsxs)("div",{className:"flex items-center gap-2",children:[(0,re.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,re.jsx)("div",{className:"animate-spin rounded-full h-3 w-3 border border-orange-400 border-t-transparent"})}),(0,re.jsx)("span",{className:"text-sm font-medium text-orange-600 animate-pulse",children:"Updating..."})]}):e.assigned_user?(0,re.jsxs)("div",{className:"flex items-center gap-2 group",children:[(0,re.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,re.jsx)(np.A,{className:"w-3 h-3 text-green-600"})}),(0,re.jsx)("div",{className:"flex-1 min-w-0",children:(0,re.jsx)("span",{className:"text-sm font-medium text-slate-700 truncate block",children:e.assigned_user})}),(0,re.jsx)(Hs,{variant:"ghost",size:"sm",disabled:t,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,re.jsxs)("div",{className:"relative",children:[(0,re.jsxs)("div",{className:"relative",children:[(0,re.jsx)(vn.A,{className:"absolute left-2 top-2.5 h-3 w-3 text-slate-400"}),(0,re.jsx)(ft,{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,re.jsx)(Hs,{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,re.jsx)(zs.A,{className:"h-3 w-3 text-slate-400"})})]}),g&&s.length>0&&(0,re.jsx)(Ly,{users:s,onSelectUser:s=>y(s,e.seat_number),anchorElement:g,onClose:()=>{x(null),p(""),f(null)}}),g&&h&&0===s.length&&(0,re.jsx)(Oy,{anchorElement:g,onClose:()=>{x(null),p(""),f(null)}})]}):(0,re.jsxs)("div",{className:"flex items-center gap-2 group",children:[(0,re.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,re.jsx)(Qf.A,{className:"w-3 h-3 text-slate-500"})}),(0,re.jsx)("span",{className:"text-sm text-slate-500 cursor-pointer hover:text-orange-600 hover:underline transition-colors font-medium",onClick:s=>{x(e.seat_number)},title:"Click to assign user",children:"Available for assignment"})]})}),(0,re.jsx)(Ur,{className:"text-right w-32 py-2",children:(0,re.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 r})})})})]})]})]})]})})},Dy={Starter:(0,re.jsx)(Gg.A,{className:"text-orange-500"}),Builder:(0,re.jsx)(hi.A,{className:"text-teal-500"}),Pro:(0,re.jsx)(ly.A,{className:"text-orange-400"}),Elite:(0,re.jsx)(ih.A,{className:"text-purple-500"})};function My(e){let{onRemoveSeats:s,onBuySeats:t}=e;const{plans:a,canManageSeats:n}=Py(),[r,l]=(0,H.useState)({open:!1,planName:null});return a&&0!==a.length?(0,re.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-4 gap-4 mb-8",children:[a.map(e=>(0,re.jsxs)(it,{className:"bg-white rounded-xl shadow-sm p-6 flex flex-col gap-3",children:[(0,re.jsxs)("div",{className:"flex items-start justify-between",children:[(0,re.jsxs)("div",{className:"flex items-center gap-3",children:[(0,re.jsx)("div",{className:"flex-shrink-0",children:Dy[e.name]}),(0,re.jsxs)("span",{className:"font-semibold text-lg",children:[e.name," Seats"]})]}),n()&&(0,re.jsxs)(Pl,{children:[(0,re.jsx)(Ll,{asChild:!0,children:(0,re.jsx)(Hs,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 text-slate-400 hover:text-slate-600 hover:bg-transparent",children:(0,re.jsx)(tl.A,{className:"h-3 w-3"})})}),(0,re.jsxs)(Ul,{align:"end",className:"w-40",children:[(0,re.jsxs)(zl,{onClick:()=>{return s=e.name,void l({open:!0,planName:s});var s},className:"text-slate-700 hover:bg-slate-50 focus:bg-slate-50",children:[(0,re.jsx)(kd.A,{className:"w-4 h-4 mr-2"}),"Seats Usage"]}),(0,re.jsx)(zl,{onClick:()=>{return s=e.name,void t(s);var s},className:"text-slate-700 hover:bg-slate-50 focus:bg-slate-50",children:"Add Seats"}),e.used_seats{return t=e.name,void s(t);var t},className:"text-slate-700 hover:bg-slate-50 focus:bg-slate-50",children:"Remove Seats"})]})]})]}),(0,re.jsxs)("div",{className:"text-2xl font-bold",children:[e.used_seats," / ",e.total_seats]}),(0,re.jsxs)("div",{className:"text-slate-500 text-sm",children:[e.available_seats," seats available"]})]},e.name)),n()&&(0,re.jsxs)(it,{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:()=>t(),children:[(0,re.jsxs)("div",{className:"flex items-center gap-3 mb-4",children:[(0,re.jsx)("div",{className:"flex-shrink-0",children:(0,re.jsx)(Ss.A,{className:"w-6 h-6 text-orange-500"})}),(0,re.jsx)("span",{className:"font-semibold text-lg text-slate-900",children:"Buy More Seats"})]}),(0,re.jsx)("div",{className:"text-slate-600 text-sm",children:"Expand your workspace size"})]}),(0,re.jsx)(Ry,{open:r.open,onOpenChange:()=>{l({open:!1,planName:null})},planName:r.planName})]}):(0,re.jsx)("div",{className:"mb-8",children:(0,re.jsx)(it,{className:"bg-gradient-to-br from-orange-50 to-teal-50 border-orange-200/50 rounded-xl shadow-sm p-8",children:(0,re.jsxs)("div",{className:"text-center",children:[(0,re.jsx)("div",{className:"mx-auto w-16 h-16 bg-orange-100 rounded-full flex items-center justify-center mb-4",children:(0,re.jsx)(Gr.A,{className:"w-8 h-8 text-orange-600"})}),(0,re.jsx)("h3",{className:"text-xl font-semibold text-slate-900 mb-2",children:"Get Started with Workspace Seats"}),(0,re.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,re.jsxs)(Hs,{onClick:()=>t(),className:"bg-orange-500 hover:bg-orange-600 text-white px-6 py-2 rounded-lg font-medium transition-colors",children:[(0,re.jsx)(Ss.A,{className:"w-4 h-4 mr-2"}),"Buy Your First Seats"]})]})})})}const Fy={Starter:(0,re.jsx)(Gg.A,{className:"text-orange-500"}),Builder:(0,re.jsx)(hi.A,{className:"text-teal-500"}),Pro:(0,re.jsx)(ly.A,{className:"text-orange-400"}),Elite:(0,re.jsx)(ih.A,{className:"text-purple-500"})};function By(e){var s;let{member:t}=e;const{currentUser:a,plans:n,userRole:r,canManageSeats:l,updateMemberRole:i,updateMemberSeat:o,showRemoveMemberDialog:c,actionLoading:d}=Py(),[m,u]=(0,H.useState)(!1),[x,h]=(0,H.useState)(!1),{displayStatus:p,seatPlan:g,seatTypeName:f}=(0,H.useMemo)(()=>{let e=t.status;if("pending"===t.status){t.invitation_expires_at&&new Date(t.invitation_expires_at)e.price_id===t.seat_type):null;return{displayStatus:e,seatPlan:s,seatTypeName:s?s.name:null}},[t,n]),v=["owner","admin"].includes(r),b=v&&t.email!==(null==a?void 0:a.email),j=t.email===(null==a?void 0:a.email),y=v&&!j&&("owner"===r||"admin"===r&&"owner"!==t.role),N=v&&!j&&("owner"===r||"admin"===r&&"owner"!==t.role),w="owner"===r&&!j,_=async e=>{if(t.role!==e&&v){u(!0);try{await i(t.email,e)}finally{u(!1)}}},k=async e=>{if(t.seat_type!==e&&l()){h(!0);try{await o(t.email,e)}finally{h(!1)}}};return(0,re.jsxs)("div",{className:"flex items-center justify-between py-4 border-b border-slate-100 last:border-b-0",children:[(0,re.jsxs)("div",{className:"flex items-center gap-3",children:[(0,re.jsx)(ma,{className:"h-10 w-10",children:(0,re.jsx)(xa,{className:"bg-slate-100 text-slate-700 font-bold text-sm",children:null===(s=t.email[0])||void 0===s?void 0:s.toUpperCase()})}),(0,re.jsx)("div",{children:(0,re.jsxs)("div",{className:"flex items-center gap-2",children:[(0,re.jsx)("span",{className:"font-medium text-slate-900",children:t.email}),"pending"===p&&(0,re.jsx)(et,{variant:"secondary",className:"bg-orange-100 text-orange-700 border-orange-200 text-xs",children:"Pending"}),"expired"===p&&(0,re.jsx)(et,{variant:"destructive",className:"bg-red-100 text-red-700 border-red-200 text-xs",children:"Expired"})]})})]}),(0,re.jsxs)("div",{className:"flex items-center gap-3",children:[(0,re.jsxs)(Pl,{children:[(0,re.jsx)(Ll,{asChild:!0,children:(0,re.jsxs)(Hs,{variant:"outline",size:"sm",className:"min-w-[100px] justify-between",disabled:m||d||!y&&!N&&!w,children:[(0,re.jsxs)("div",{className:"flex items-center gap-1",children:[m?(0,re.jsx)(Ze.A,{className:"h-3 w-3 animate-spin"}):(0,re.jsx)(np.A,{className:"h-3 w-3"}),(0,re.jsx)("span",{className:"capitalize",children:t.role})]}),(0,re.jsx)(It.A,{className:"h-3 w-3"})]})}),(0,re.jsxs)(Ul,{align:"end",className:"w-40",children:[(0,re.jsxs)(zl,{onClick:()=>_("member"),disabled:"member"===t.role||!y||m,children:[(0,re.jsx)(np.A,{className:"mr-2 h-4 w-4"}),"Member"]}),(0,re.jsxs)(zl,{onClick:()=>_("admin"),disabled:"admin"===t.role||!N||m,children:[(0,re.jsx)(np.A,{className:"mr-2 h-4 w-4"}),"Admin"]}),(0,re.jsxs)(zl,{onClick:()=>_("owner"),disabled:"owner"===t.role||!w||m,children:[(0,re.jsx)(np.A,{className:"mr-2 h-4 w-4"}),"Owner"]}),b&&(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)("div",{className:"border-t border-slate-100 my-1"}),(0,re.jsxs)(zl,{onClick:()=>{c(t)},disabled:d||m,className:"text-red-600 hover:text-red-700 focus:text-red-700",children:[d?(0,re.jsx)(Ze.A,{className:"mr-2 h-4 w-4 animate-spin"}):(0,re.jsx)(np.A,{className:"mr-2 h-4 w-4"}),"Remove Member"]})]})]})]}),(0,re.jsxs)(Pl,{children:[(0,re.jsx)(Ll,{asChild:!0,children:(0,re.jsxs)(Hs,{variant:"outline",size:"sm",className:"min-w-[120px] justify-between",disabled:x||d,children:[(0,re.jsx)("div",{className:"flex items-center gap-1",children:x?(0,re.jsx)(Ze.A,{className:"h-3 w-3 animate-spin"}):f?(0,re.jsxs)(re.Fragment,{children:[Fy[f],(0,re.jsx)("span",{children:f})]}):(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(np.A,{className:"h-3 w-3"}),(0,re.jsx)("span",{children:"No Seat"})]})}),(0,re.jsx)(It.A,{className:"h-3 w-3"})]})}),(0,re.jsxs)(Ul,{align:"end",className:"w-50",children:[(0,re.jsxs)(zl,{onClick:()=>k(null),disabled:!t.seat_type||x,children:[(0,re.jsx)(np.A,{className:"mr-2 h-4 w-4"}),"No Seat"]}),n.length>0&&(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)("div",{className:"border-t border-slate-100 my-1"}),n.map(e=>(0,re.jsxs)(zl,{onClick:()=>k(e.price_id),disabled:t.seat_type===e.price_id||!l()||x||0===e.available_seats,className:0===e.available_seats?"opacity-50":"",children:[(0,re.jsx)("div",{className:"flex items-center mr-2 h-4 w-4",children:Fy[e.name]}),(0,re.jsxs)("div",{className:"flex flex-col",children:[(0,re.jsx)("span",{children:e.name}),(0,re.jsxs)("span",{className:"text-xs text-slate-500",children:[e.available_seats," available"]})]})]},e.price_id))]})]})]})]})]})}function Uy(e){let{onInviteUser:s,onBulkInvite:t}=e;const{currentOrganization:a,members:n,canInviteUsers:r}=Py(),l=n&&n.length>0;return(0,re.jsxs)(it,{children:[(0,re.jsxs)(ot,{className:"flex flex-row items-center justify-between",children:[(0,re.jsxs)("div",{className:"flex items-center gap-2",children:[(0,re.jsx)(Gr.A,{className:"text-slate-400"}),(0,re.jsxs)(ct,{children:["Members (",(null==n?void 0:n.length)||0,")"]})]}),r()&&(0,re.jsxs)("div",{className:"flex gap-2",children:[(0,re.jsxs)(Hs,{variant:"outline",onClick:t,className:"text-orange-600 border-orange-200 hover:bg-orange-50",children:[(0,re.jsx)(hm.A,{className:"h-4 w-4 mr-2"}),"Bulk Invite"]}),(0,re.jsxs)(Hs,{onClick:s,children:[(0,re.jsx)(Ss.A,{className:"h-4 w-4"}),"Invite User"]})]})]}),(0,re.jsx)(mt,{children:l?(0,re.jsx)("div",{className:"space-y-0",children:n.map(e=>(0,re.jsx)(By,{member:e},e.id))}):(0,re.jsxs)("div",{className:"flex flex-col items-center justify-center py-12",children:[(0,re.jsx)(Gr.A,{className:"text-slate-200 text-5xl mb-2"}),(0,re.jsx)("div",{className:"font-semibold text-lg",children:"No workspace members yet"}),(0,re.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 zy(e){let{isOpen:s,onClose:t,onInvite:a}=e;const{actionLoading:n}=Py(),[r,l]=(0,H.useState)(""),[i,o]=(0,H.useState)("member"),[c,d]=(0,H.useState)(""),m=()=>{l(""),o("member"),d(""),t()};return(0,re.jsx)(Pa,{open:s,onOpenChange:m,children:(0,re.jsxs)(Ma,{className:"max-w-md",children:[(0,re.jsx)(Fa,{children:(0,re.jsxs)("div",{className:"flex items-center gap-2",children:[(0,re.jsx)("div",{className:"rounded bg-teal-100 p-2",children:(0,re.jsx)(Im.A,{className:"text-teal-600 w-5 h-5"})}),(0,re.jsx)(Ua,{className:"text-2xl font-bold",children:"Invite Workspace Member"})]})}),(0,re.jsxs)("form",{onSubmit:async e=>{if(e.preventDefault(),r.trim())if(r.includes("@"))try{d(""),await a(r.trim(),i),m()}catch(n){var s,t;d((null==n||null===(s=n.response)||void 0===s||null===(t=s.data)||void 0===t?void 0:t.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,re.jsxs)("div",{children:[(0,re.jsx)("label",{className:"block text-sm font-medium text-slate-700 mb-1",children:"Email Address"}),(0,re.jsxs)("div",{className:"relative",children:[(0,re.jsx)(Im.A,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 text-slate-400 w-4 h-4"}),(0,re.jsx)(ft,{type:"email",placeholder:"colleague@company.com",value:r,onChange:e=>l(e.target.value),disabled:n,className:"pl-10 focus:ring-2 focus:ring-teal-500",autoFocus:!0})]})]}),(0,re.jsxs)("div",{children:[(0,re.jsx)("label",{className:"block text-sm font-medium text-slate-700 mb-1",children:"Role"}),(0,re.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,re.jsx)("option",{value:"member",children:"Member"}),(0,re.jsx)("option",{value:"admin",children:"Admin"})]})]}),c&&(0,re.jsx)("div",{className:"bg-red-50 border border-red-200 rounded-lg p-3",children:(0,re.jsx)("p",{className:"text-red-700 text-sm",children:c})}),(0,re.jsxs)(Ba,{children:[(0,re.jsx)(Hs,{type:"button",variant:"outline",onClick:m,disabled:n,children:"Cancel"}),(0,re.jsx)(Hs,{type:"submit",className:"bg-teal-600 hover:bg-teal-700 text-white",disabled:n||!r.trim(),children:n?(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(Ze.A,{className:"mr-2 h-4 w-4 animate-spin"}),"Sending Invite..."]}):"Send Invite"})]})]})]})})}const qy=[{value:"member",label:"Member"},{value:"admin",label:"Admin"}];function Wy(e){let{isOpen:s,onClose:t,onSuccess:a}=e;const{workspaceId:n,plans:r,availablePlans:l}=Py(),[i,o]=(0,H.useState)(null),[c,d]=(0,H.useState)("member"),[m,u]=(0,H.useState)(null),[x,h]=(0,H.useState)(""),[p,g]=(0,H.useState)([]),[f,v]=(0,H.useState)([]),[b,j]=(0,H.useState)(!1),[y,N]=(0,H.useState)(!1),[w,_]=(0,H.useState)(!1),k=(0,H.useRef)(),A=H.useMemo(()=>{const e=[{value:null,label:"No seat"}];return l&&l.length>0&&e.push(...l.map(e=>({value:e.name.toLowerCase(),label:e.name}))),e},[l]),S=e=>"text/csv"===e.type||e.name.endsWith(".csv")?(o(e),h(""),C(e),!0):(h("Please upload a CSV file"),!1),C=e=>{const s=new FileReader;s.onload=e=>{try{const s=e.target.result.split("\n").filter(e=>e.trim());if(0===s.length)return void h("CSV file is empty");const t=s[0].split(",").map(e=>e.trim().toLowerCase());if(!t.includes("email"))return void h('CSV must contain an "email" column');const a=[];for(let e=1;ee.trim()),r={};t.forEach((e,s)=>{r[e]=n[s]||""}),r.email&&a.push({email:r.email,role:r.role||"",seat:r.seat||""})}if(0===a.length)return void h("No valid email addresses found in CSV");v(a),j(!0),h("")}catch(s){const e="string"==typeof s.message?s.message:"Unknown parsing error";h("Error parsing CSV file: "+e)}},s.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 s=e.target.result.split("\n").filter(e=>e.trim()),t=s[0].split(",").map(e=>e.trim().toLowerCase()),r=[];for(let e=1;ee.trim()),n={};t.forEach((e,s)=>{n[e]=a[s]||""}),n.email&&r.push({email:n.email,role:n.role||c,seat:n.seat||m})}I(r),await xe.bulkInviteUsers(r,n),a&&a(),T()}catch(r){var s,t;let e="Failed to send bulk invitations";null!=r&&null!==(s=r.response)&&void 0!==s&&null!==(t=s.data)&&void 0!==t&&t.detail?"string"==typeof r.response.data.detail?e=r.response.data.detail:Array.isArray(r.response.data.detail)?e=r.response.data.detail.map(e=>e.msg||e.message||e).join(", "):"object"==typeof r.response.data.detail&&(e=r.response.data.detail.msg||r.response.data.detail.message||JSON.stringify(r.response.data.detail)):null!=r&&r.message&&(e=r.message),h(e)}finally{N(!1)}},e.readAsText(i)}catch(r){var s,t;let e="Failed to send bulk invitations";null!=r&&null!==(s=r.response)&&void 0!==s&&null!==(t=s.data)&&void 0!==t&&t.detail?"string"==typeof r.response.data.detail?e=r.response.data.detail:Array.isArray(r.response.data.detail)?e=r.response.data.detail.map(e=>e.msg||e.message||e).join(", "):"object"==typeof r.response.data.detail&&(e=r.response.data.detail.msg||r.response.data.detail.message||JSON.stringify(r.response.data.detail)):null!=r&&r.message&&(e=r.message),h(e),N(!1)}}else h("No valid invitations to send");else h("Please upload a CSV file")},I=e=>{const s={};if(e.forEach(e=>{e.seat&&"none"!==e.seat&&(s[e.seat]=(s[e.seat]||0)+1)}),0===Object.keys(s).length)return;const t=[],a=[],n=[];if(Object.entries(s).forEach(e=>{let[s,i]=e;const o=l.find(e=>e.name.toLowerCase()===s.toLowerCase());if(!o)return void n.push("Invalid seat type: ".concat(s,". Available types: ").concat(l.map(e=>e.name.toLowerCase()).join(", ")));const c=r.find(e=>e.name.toLowerCase()===s.toLowerCase());c?c.available_seats0||t.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(s=>{e+="\u25b6 ".concat(s.plan_name," Plan: You need to purchase this plan first (").concat(s.requested," seat").concat(s.requested>1?"s":""," needed)\n")}),e+="\n"),t.length>0&&(e+="\u{1f4ca} Insufficient Seats:\n",t.forEach(s=>{e+="\u25b6 ".concat(s.plan_name," Plan: Need to purchase ").concat(s.needed," more seat").concat(s.needed>1?"s":"","\n"),e+=" (You're trying to assign ".concat(s.requested," seats, but only ").concat(s.available," are available)\n")}),e+="\n"),(a.length>0||t.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=""),t()};return(0,H.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,re.jsx)(Pa,{open:s,onOpenChange:T,children:(0,re.jsxs)(Ma,{className:"max-w-2xl max-h-[90vh] overflow-hidden flex flex-col",children:[(0,re.jsx)(Fa,{children:(0,re.jsxs)("div",{className:"flex items-center gap-2",children:[(0,re.jsx)("div",{className:"rounded bg-orange-100 p-2",children:(0,re.jsx)(Gr.A,{className:"text-orange-600 w-5 h-5"})}),(0,re.jsx)(Ua,{className:"text-2xl font-bold",children:"Bulk Invite Members"})]})}),(0,re.jsx)("div",{className:"flex-1 overflow-y-auto",children:(0,re.jsxs)("form",{onSubmit:E,className:"space-y-6",children:[(0,re.jsxs)("div",{className:"space-y-4",children:[(0,re.jsxs)("div",{className:"flex items-center justify-between",children:[(0,re.jsx)(Nt,{className:"text-sm font-medium text-slate-700",children:"CSV File"}),(0,re.jsxs)(Hs,{type:"button",variant:"outline",size:"sm",onClick:()=>{var e,s;const t=(null===(e=l[0])||void 0===e?void 0:e.name.toLowerCase())||"starter",a=(null===(s=l[1])||void 0===s?void 0:s.name.toLowerCase())||"pro",n="email,role,seat\nexample@company.com,member,".concat(t,"\nuser2@company.com,admin,").concat(a),r=new Blob([n],{type:"text/csv"}),i=window.URL.createObjectURL(r),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,re.jsx)(Rd.A,{className:"h-4 w-4 mr-1.5"}),"Download Template"]})]}),(0,re.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 s=e.currentTarget.getBoundingClientRect(),t=e.clientX,a=e.clientY;(t=s.right||a=s.bottom)&&_(!1)},onDrop:e=>{e.preventDefault(),e.stopPropagation(),_(!1);const s=e.dataTransfer.files;if(s.length>0){const e=s[0];S(e)}},children:[(0,re.jsx)(hm.A,{className:"mx-auto h-8 w-8 mb-2 transition-colors ".concat(w?"text-orange-500":"text-slate-400")}),(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.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,re.jsxs)("p",{className:"text-xs text-slate-500",children:["CSV should contain columns: ",(0,re.jsx)("span",{className:"font-mono text-orange-600",children:"email, role, seat"})]}),(0,re.jsx)(ft,{ref:k,type:"file",accept:".csv",onChange:e=>{const s=e.target.files[0];s&&S(s)},disabled:y,className:"max-w-xs mx-auto"})]}),i&&(0,re.jsxs)("div",{className:"mt-3 flex items-center justify-center gap-2 text-sm text-green-600",children:[(0,re.jsx)(al.A,{className:"h-4 w-4"}),i.name]})]}),(0,re.jsxs)(us,{children:[(0,re.jsx)(Xe.A,{className:"h-4 w-4"}),(0,re.jsx)(hs,{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,re.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsx)(Nt,{htmlFor:"defaultRole",className:"text-sm font-medium text-slate-700",children:"Default Role"}),(0,re.jsxs)(Ut,{value:c,onValueChange:d,children:[(0,re.jsx)(Wt,{id:"defaultRole",className:"h-11 border-slate-200 focus:ring-orange-500 focus:border-orange-500",children:(0,re.jsx)(qt,{placeholder:"Select default role"})}),(0,re.jsx)(Ht,{children:qy.map(e=>(0,re.jsx)($t,{value:e.value,className:"py-3",children:(0,re.jsx)("div",{className:"flex flex-col",children:(0,re.jsx)("span",{className:"font-medium",children:e.label})})},e.value))})]})]}),(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsx)(Nt,{htmlFor:"defaultSeat",className:"text-sm font-medium text-slate-700",children:"Default Seat"}),(0,re.jsxs)(Ut,{value:m||"none",onValueChange:e=>u("none"===e?null:e),children:[(0,re.jsx)(Wt,{id:"defaultSeat",className:"h-11 border-slate-200 focus:ring-orange-500 focus:border-orange-500",children:(0,re.jsx)(qt,{placeholder:"Select default seat"})}),(0,re.jsx)(Ht,{children:A.map(e=>(0,re.jsx)($t,{value:e.value||"none",className:"py-3",children:(0,re.jsx)("div",{className:"flex flex-col",children:(0,re.jsx)("span",{className:"font-medium",children:e.label})})},e.value||"none"))})]})]})]}),b&&p.length>0&&(0,re.jsxs)("div",{className:"space-y-3",children:[(0,re.jsxs)(Nt,{className:"text-sm font-medium text-slate-700",children:["Preview (",p.length," invitation",1!==p.length?"s":"",")"]}),(0,re.jsx)("div",{className:"bg-slate-50 rounded-lg border border-slate-200 max-h-48 overflow-y-auto",children:(0,re.jsxs)("table",{className:"w-full text-sm",children:[(0,re.jsx)("thead",{className:"bg-slate-100 sticky top-0",children:(0,re.jsxs)("tr",{children:[(0,re.jsx)("th",{className:"text-left p-3 font-medium",children:"Email"}),(0,re.jsx)("th",{className:"text-left p-3 font-medium",children:"Role"}),(0,re.jsx)("th",{className:"text-left p-3 font-medium",children:"Seat"})]})}),(0,re.jsx)("tbody",{children:p.map((e,s)=>(0,re.jsxs)("tr",{className:"border-t border-slate-200",children:[(0,re.jsx)("td",{className:"p-3 font-mono text-xs",children:e.email}),(0,re.jsx)("td",{className:"p-3 capitalize",children:e.role}),(0,re.jsx)("td",{className:"p-3 capitalize",children:e.seat||"No seat"})]},s))})]})})]})]})}),x&&(0,re.jsxs)("div",{className:"px-6 pb-4 relative",children:[(0,re.jsxs)(us,{variant:"destructive",children:[(0,re.jsx)(Xe.A,{className:"h-4 w-4"}),(0,re.jsx)(hs,{className:"whitespace-pre-line text-sm pr-8",children:x})]}),(0,re.jsx)(Hs,{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,re.jsx)(zs.A,{className:"h-3 w-3"})})]}),(0,re.jsxs)(Ba,{className:"gap-3 pt-4 border-t",children:[(0,re.jsx)(Hs,{variant:"outline",type:"button",onClick:T,disabled:y,children:"Cancel"}),(0,re.jsx)(Hs,{onClick:E,className:"bg-orange-600 hover:bg-orange-700 text-white",disabled:y||!i||0===p.length,children:y?(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)("div",{className:"w-4 h-4 border-2 border-white/30 border-t-white rounded-full animate-spin mr-2"}),"Sending Invitations..."]}):(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(Gr.A,{className:"w-4 h-4 mr-2"}),"Send ",p.length," Invitation",1!==p.length?"s":""]})})]})]})})}function Vy(e){let{isOpen:s,onClose:t,onAction:a,action:n="buy",selectedPlanName:r=null}=e;const{plans:l,availablePlans:i,currentWorkspace:o,actionLoading:c}=Py(),[d,m]=(0,H.useState)(""),[u,x]=(0,H.useState)(1),[h,p]=(0,H.useState)(""),[g,f]=(0,H.useState)(!1);(0,H.useEffect)(()=>{if(s)if(p(""),f(!1),r)m(r);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&&l.length>0){var e;m((null===(e=l[0])||void 0===e?void 0:e.name)||"")}},[s,n,i,l,r]);const v=()=>{m(""),x(1),p(""),f(!1),t()},b="buy"===n?i:l,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,re.jsx)(Pa,{open:s,onOpenChange:v,children:(0,re.jsxs)(Ma,{className:"max-w-md",children:[(0,re.jsx)(Fa,{children:(0,re.jsxs)("div",{className:"flex items-center gap-2",children:[(0,re.jsx)("div",{className:"buy"===n?"rounded bg-teal-100 p-2":"rounded bg-red-100 p-2",children:(0,re.jsx)(Gr.A,{className:"buy"===n?"text-teal-600 w-5 h-5":"text-red-600 w-5 h-5"})}),(0,re.jsx)(Ua,{className:"text-2xl font-bold",children:"buy"===n?"Purchase Seats":"Remove Seats"})]})}),c&&!g?(0,re.jsx)("div",{className:"flex items-center justify-center py-8",children:(0,re.jsxs)("div",{className:"flex flex-col items-center gap-3",children:[(0,re.jsx)(Ze.A,{className:"h-8 w-8 animate-spin text-teal-600"}),(0,re.jsx)("p",{className:"text-slate-600",children:"Loading plans..."})]})}):(0,re.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=l.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(r){var s,t;const e=(null==r||null===(s=r.response)||void 0===s||null===(t=s.data)||void 0===t?void 0:t.detail)||r.message||"Failed to ".concat(n," seats. Please try again.");p(e)}finally{f(!1)}}},className:"space-y-4",children:[(0,re.jsxs)("div",{className:"flex gap-4",children:[(0,re.jsxs)("div",{className:"flex-1",children:[(0,re.jsx)("label",{className:"block text-sm font-medium text-slate-700 mb-1",children:"Seat Type"}),(0,re.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,re.jsx)("option",{children:"buy"===n?"No plans available":"No seats to remove"}):b.map(e=>(0,re.jsxs)("option",{value:e.name,children:[e.name," ","remove"===n?"(".concat(e.available_seats," available)"):""]},e.name))})]}),(0,re.jsxs)("div",{className:"flex-1",children:[(0,re.jsx)("label",{className:"block text-sm font-medium text-slate-700 mb-1",children:"Quantity"}),(0,re.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,re.jsxs)("div",{className:"bg-slate-50 rounded-xl p-4 border",children:[(0,re.jsxs)("div",{className:"flex justify-between text-slate-600 text-sm mb-1",children:[(0,re.jsx)("span",{children:"Seat Type"}),(0,re.jsx)("span",{className:"font-medium",children:d||"None selected"})]}),"buy"===n&&(null==j?void 0:j.price)&&(0,re.jsxs)("div",{className:"flex justify-between text-slate-600 text-sm mb-1",children:[(0,re.jsx)("span",{children:"Price per seat"}),(0,re.jsxs)("span",{className:"font-medium",children:["$",j.price,"/month"]})]}),(0,re.jsxs)("div",{className:"flex justify-between text-slate-600 text-sm mb-1",children:[(0,re.jsx)("span",{children:"Quantity"}),(0,re.jsxs)("span",{className:"font-medium",children:[u," seat",u>1?"s":""]})]}),"remove"===n&&j&&(0,re.jsxs)("div",{className:"flex justify-between text-slate-600 text-sm mb-1",children:[(0,re.jsx)("span",{children:"Available to remove"}),(0,re.jsxs)("span",{className:"font-medium",children:[j.available_seats," seat",j.available_seats>1?"s":""]})]}),(0,re.jsx)("hr",{className:"my-2"}),(0,re.jsxs)("div",{className:"flex justify-between items-center",children:[(0,re.jsx)("span",{className:"font-bold text-lg",children:"buy"===n?"Total Cost":"Action"}),(0,re.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,re.jsx)("div",{className:"bg-teal-50 border border-teal-200 rounded-lg p-3",children:(0,re.jsxs)("p",{className:"text-teal-800 text-sm",children:[(0,re.jsx)(jl.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,re.jsx)("div",{className:"bg-red-50 border border-red-200 rounded-lg p-3",children:(0,re.jsx)("p",{className:"text-red-700 text-sm",children:h})}),(0,re.jsxs)(Ba,{children:[(0,re.jsx)(Hs,{type:"button",variant:"outline",onClick:v,disabled:y,children:"Cancel"}),(0,re.jsx)(Hs,{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,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(Ze.A,{className:"mr-2 h-4 w-4 animate-spin"}),"buy"===n?"Processing...":"Removing..."]}):"buy"===n?"Purchase Seats":"Remove Seats"})]})]})]})})}class Yy extends X.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,s){let t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;const a=t?{provider_name:t}:{};return this.axios.put("/".concat(e,"/sso/settings"),s,{params:a})}}const Hy=new Yy,Gy=e=>{let{children:s,content:t,side:a="left"}=e;const n="right"===a,r="top"===a,l="bottom"===a,i="left"===a;return(0,re.jsxs)("div",{className:"relative group",children:[s,(0,re.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(l?"top-full mt-2 left-1/2 transform -translate-x-1/2":r?"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:[t,(0,re.jsx)("div",{className:"\n absolute border-4 border-transparent\n ".concat(l?"bottom-full -mb-1 left-1/2 transform -translate-x-1/2 border-b-gray-900":r?"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 $y(e){var s;let{workspace:t,userRole:a}=e;const{toast:n}=nn(),[r,l]=(0,H.useState)(!1),[i,o]=(0,H.useState)(!1),[c,d]=(0,H.useState)(new Set),[m,u]=(0,H.useState)(!1),[x,h]=(0,H.useState)({sso_provider_name:"",sso_enabled:!1,is_enterprise:!1}),[p,g]=(0,H.useState)({name:"",client_id:"",client_secret:"",discovery_url:"",scope:"openid email profile",auth_endpoint:"",token_endpoint:"",userinfo_endpoint:"",jwks_uri:"",tenant_id:"",okta_domain:""}),[f,v]=(0,H.useState)(""),b="owner"===a&&(null==t?void 0:t.is_enterprise),j={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,H.useEffect)(()=>{(async()=>{if(null!=t&&t.id&&b)try{const e=await Hy.getSSOSettings(t.id);h(e.config);const s=(0,K.A)({},e.settings);Object.keys(s).forEach(e=>{s[e]&&s[e].match(/^X+$/)&&(s[e]="\u2022".repeat(20))}),g(s),e.config.sso_provider_name&&(j[e.config.sso_provider_name]?v(e.config.sso_provider_name):v("advanced"))}catch(e){}})()},[null==t?void 0:t.id,b]);const y=(e,s)=>{g(t=>{const a=(0,K.A)((0,K.A)({},t),{},{[e]:s}),n=j[f];if(null!=n&&n.autoGenerate&&e===n.autoGenerate.field&&s){const e=n.autoGenerate.template(s);a[n.autoGenerate.target]=e,d(e=>new Set(e).add(n.autoGenerate.target))}return a}),d(s=>new Set(s).add(e))},N=e=>e&&"string"==typeof e&&(e.match(/^X+$/)||e.match(/^\u2022+$/)),w=e=>e&&j[e]&&j[e].fields||[];return null!=t&&t.is_enterprise?b?(0,re.jsxs)("div",{className:"space-y-6",children:[(0,re.jsxs)("div",{children:[(0,re.jsx)("h2",{className:"text-xl font-semibold text-gray-800",children:"Single Sign-On (SSO)"}),(0,re.jsx)("p",{className:"text-gray-600 mt-1",children:"Configure SSO to allow workspace members to authenticate using your organization's identity provider."})]}),(0,re.jsxs)("div",{className:"bg-white rounded-lg outline outline-1 outline-offset-[-1px] outline-gray-200",children:[(0,re.jsxs)("div",{className:"p-4 flex justify-start items-center gap-4",children:[(0,re.jsx)("div",{className:"w-10 h-10 bg-slate-900 rounded-lg border border-slate-900 flex items-center justify-center",children:(0,re.jsx)("svg",{className:"w-5 h-5 text-white",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,re.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,re.jsxs)("div",{className:"flex-1 flex flex-col justify-start items-start gap-0.5",children:[(0,re.jsxs)("div",{className:"flex justify-center items-center gap-2",children:[(0,re.jsx)("div",{className:"text-gray-900 text-sm font-medium leading-tight",children:"Single Sign-on Configuration"}),(0,re.jsx)(Gy,{content:"Configure SSO for your workspace",side:"top",children:(0,re.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,re.jsx)("span",{className:"text-xs font-medium text-blue-800",children:"Enterprise"})})})]}),(0,re.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,re.jsx)("div",{className:"flex items-center gap-3",children:x.sso_provider_name&&!m?(0,re.jsx)(wu,{id:"sso-toggle",checked:!0===x.sso_enabled,onCheckedChange:async e=>{if(!r){l(!0);try{e?(await Hy.enableSSO(t.id),h(e=>(0,K.A)((0,K.A)({},e),{},{sso_enabled:!0})),o(!0),n({title:"SSO Enabled",description:"Single Sign-On has been enabled for your workspace"})):(await Hy.disableSSO(t.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(s){n({title:"Error",description:s.message||"Failed to update SSO status",variant:"destructive"})}finally{l(!1)}}},disabled:r}):(0,re.jsx)(Hs,{onClick:()=>{u(!0),o(!0),v("google")},variant:"outline",size:"sm",disabled:r,children:r?"Setting up...":"Set Up"})})]}),(x.sso_provider_name||m)&&!i&&(0,re.jsx)("div",{className:"px-4 pb-4",children:(0,re.jsxs)("button",{onClick:()=>o(!i),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,re.jsx)("div",{className:"text-gray-900 text-sm font-medium",children:m?"Set up SSO Configuration":(null===(s=j[x.sso_provider_name])||void 0===s?void 0:s.displayName)||"".concat(x.sso_provider_name," SSO")}),(0,re.jsxs)("div",{className:"flex items-center gap-2 text-gray-500",children:[(0,re.jsx)("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,re.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,re.jsx)("span",{className:"text-sm",children:m?"Set up":"Configure"}),(0,re.jsx)(It.A,{className:"w-4 h-4 transition-transform ".concat(i?"rotate-180":"")})]})]})}),i&&(x.sso_provider_name||m)&&(0,re.jsx)("div",{className:"border-t border-gray-100 p-4 bg-white",children:(0,re.jsxs)("div",{className:"space-y-4",children:[(0,re.jsxs)("div",{children:[(0,re.jsx)("div",{className:"text-gray-500 text-sm font-normal leading-tight mb-2",children:"Select SSO Provider"}),(0,re.jsxs)(Ut,{value:f,onValueChange:e=>{if(v(e),"advanced"===e)g({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&&j[e]){const s=j[e],t={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:""};g((0,K.A)((0,K.A)({},t),s.defaults))}},children:[(0,re.jsx)(Wt,{className:"w-full px-4 py-3 bg-white rounded-md shadow-sm outline outline-1 outline-offset-[-1px] outline-gray-200",children:(0,re.jsx)(qt,{placeholder:"Select SSO Provider"})}),(0,re.jsx)(Ht,{children:Object.entries(j).map(e=>{let[s,t]=e;return(0,re.jsx)($t,{value:s,children:t.displayName},s)})})]})]}),(e=>{const s=w(e);if(!s.length)return null;const t=s.reduce((e,s)=>{const t=s.row||1;return e[t]||(e[t]=[]),e[t].push(s),e},{});return(0,re.jsx)("div",{className:"space-y-4",children:Object.entries(t).sort((e,s)=>{let[t]=e,[a]=s;return parseInt(t)-parseInt(a)}).map(s=>{let[t,a]=s;return(0,re.jsx)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:a.map((s,t)=>{var n,r,l,i;const o=a.length>1&&1===t,c=p[s.name]||"",d=s.placeholder||"Enter ".concat(s.name.replace("_"," ")),m=(s.name,N(u=c)?"\u2022".repeat(20):u);var u;const x="discovery_url"===s.name&&"discovery_url"===(null===(n=j[e])||void 0===n||null===(r=n.autoGenerate)||void 0===r?void 0:r.target)&&c;return(0,re.jsxs)("div",{children:[(0,re.jsxs)(Nt,{className:"text-gray-500 text-sm flex items-center gap-1",children:[s.name.replace("_"," ").replace(/\b\w/g,e=>e.toUpperCase()),s.required&&" *",s.name===(null===(l=j[e])||void 0===l||null===(i=l.autoGenerate)||void 0===i?void 0:i.target)&&c&&" (Auto-generated)",(0,re.jsx)(Gy,{content:s.tooltip,side:o?"right":"left",children:(0,re.jsx)(jo.A,{className:"w-3.5 h-3.5 text-gray-400 hover:text-gray-600 cursor-help"})})]}),(0,re.jsx)(ft,{className:"mt-1 w-full h-8 ".concat(x?"bg-gray-50":""),type:"text",placeholder:d,value:m,onChange:e=>{N(e.target.value)||y(s.name,e.target.value)},onFocus:e=>{N(m)&&(e.target.value="",y(s.name,""))},readOnly:x,disabled:!b})]},s.name)})},t)})})})(f),(0,re.jsxs)("div",{className:"flex justify-between pt-4",children:[(0,re.jsx)(Hs,{onClick:()=>{o(!1),m&&u(!1),v(""),d(new Set)},variant:"outline",className:"border-gray-300 text-gray-700 hover:bg-gray-50",children:m?"Cancel Setup":"Dismiss"}),(0,re.jsx)(Hs,{onClick:async()=>{l(!0);try{const e={};c.forEach(s=>{const t=p[s];!t||t.match(/^\u2022+$/)||t.match(/^X+$/)||(e[s]=t)});let s=f;"advanced"===f&&(s=p.name||"advanced"),await Hy.updateSSOSettings(t.id,e,s),h(e=>(0,K.A)((0,K.A)({},e),{},{sso_provider_name:s,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{l(!1)}},disabled:r||!f||w(f).some(e=>e.required&&!p[e.name]),className:"bg-gray-900 text-white",children:r?"Saving...":m?"Enable SSO":"Save SSO Settings"})]})]})})]})]}):(0,re.jsx)("div",{className:"bg-yellow-50 rounded-lg p-4",children:(0,re.jsxs)("div",{className:"flex items-start gap-3",children:[(0,re.jsx)(Fu.A,{className:"w-5 h-5 text-yellow-600 mt-0.5"}),(0,re.jsxs)("div",{children:[(0,re.jsx)("h3",{className:"text-sm font-medium text-yellow-900",children:"Limited Access"}),(0,re.jsx)("p",{className:"text-sm text-yellow-700 mt-1",children:"Only workspace owners can configure SSO settings."})]})]})}):(0,re.jsxs)("div",{className:"bg-gray-50 rounded-lg p-6 text-center",children:[(0,re.jsx)(Fs.A,{className:"w-12 h-12 text-gray-400 mx-auto mb-4"}),(0,re.jsx)("h3",{className:"text-lg font-semibold text-gray-900 mb-2",children:"Enterprise Feature"}),(0,re.jsx)("p",{className:"text-gray-600",children:"Single Sign-On (SSO) is available for enterprise workspaces only."})]})}function Jy(){const{currentWorkspace:e,userRole:s,loading:t,actionLoading:a,inviteUser:n,manageSeat:r,handleCheckoutSuccess:l,showRemoveDialog:i,memberToRemove:o,hideRemoveMemberDialog:c,confirmRemoveMember:d}=Py(),[m,u]=(0,J.useSearchParams)(),x=(0,Z.Zp)(),[h,p]=(0,H.useState)(!1),[g,f]=(0,H.useState)(!1),[v,b]=(0,H.useState)(!1),[j,y]=(0,H.useState)("buy"),[N,w]=(0,H.useState)(null);(0,H.useEffect)(()=>{const e=m.get("success"),s=m.get("subscription_update");"true"!==e&&"success"!==s||(m.delete("success"),m.delete("subscription_update"),u(m,{replace:!0}),l())},[m,u,l]);const _=function(e){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;y(e),s?(w(s),b(!0)):(w(null),b(!0))};return t?(0,re.jsx)("div",{className:"flex items-center justify-center min-h-screen",children:(0,re.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(s)?(0,re.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,re.jsxs)("div",{className:"mb-8 relative",children:[(0,re.jsxs)("h1",{className:"text-4xl font-bold text-slate-900 mb-1",children:[e.name," Workspace Dashboard"]}),(0,re.jsx)("p",{className:"text-slate-500 text-lg",children:"Manage your workspace and seats"}),(0,re.jsx)("div",{className:"absolute -bottom-2.5 left-0 w-48 h-0.5 bg-orange-500 rounded-full"})]}),(0,re.jsxs)(hl,{defaultValue:"overview",className:"space-y-6",children:[e.is_enterprise&&(0,re.jsxs)(pl,{className:"grid w-full grid-cols-2 max-w-md",children:[(0,re.jsx)(gl,{value:"overview",children:"Overview"}),(0,re.jsxs)(gl,{value:"sso",className:"flex items-center gap-2",children:[(0,re.jsx)(rp.A,{className:"w-4 h-4"}),"SSO"]})]}),(0,re.jsxs)(fl,{value:"overview",className:"space-y-6",children:[(0,re.jsx)(My,{onRemoveSeats:e=>_("remove",e),onBuySeats:e=>_("buy",e)}),(0,re.jsx)(Uy,{onInviteUser:()=>p(!0),onBulkInvite:()=>f(!0)})]}),e.is_enterprise&&(0,re.jsx)(fl,{value:"sso",className:"space-y-6",children:(0,re.jsx)($y,{workspace:e,userRole:s})})]}),(0,re.jsx)(zy,{isOpen:h,onClose:()=>p(!1),onInvite:async(e,s)=>{try{await n(e,s),p(!1)}catch(t){}}}),(0,re.jsx)(Wy,{isOpen:g,onClose:()=>f(!1),onSuccess:()=>{}}),(0,re.jsx)(Vy,{isOpen:v,onClose:()=>{b(!1),w(null)},onAction:async(e,s)=>{try{const t="remove"===j&&N?N:e;await r(t,s,j),b(!1),w(null)}catch(t){}},action:j,selectedPlanName:N}),(0,re.jsx)(vp,{open:i,onOpenChange:c,children:(0,re.jsxs)(Np,{children:[(0,re.jsxs)(wp,{children:[(0,re.jsxs)("div",{className:"flex items-center gap-2",children:[(0,re.jsx)(Fu.A,{className:"h-5 w-5 text-orange-500"}),(0,re.jsx)(kp,{children:"Remove Member"})]}),(0,re.jsxs)(Ap,{className:"space-y-2 pt-2",children:[(0,re.jsxs)("p",{children:["Are you sure you want to remove ",(0,re.jsx)("strong",{children:null==o?void 0:o.email})," from this workspace?"]}),(0,re.jsx)("div",{className:"bg-orange-50 border border-orange-200 rounded-lg p-3",children:(0,re.jsxs)("div",{className:"flex items-start gap-2",children:[(0,re.jsx)(Fu.A,{className:"h-4 w-4 text-orange-600 mt-0.5 flex-shrink-0"}),(0,re.jsxs)("div",{className:"text-sm text-orange-800",children:[(0,re.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,re.jsxs)(_p,{children:[(0,re.jsx)(Cp,{children:"Cancel"}),(0,re.jsx)(Sp,{onClick:d,className:"bg-red-600 hover:bg-red-700 focus:ring-red-600",children:"Remove Member"})]})]})})]}):(0,re.jsx)("div",{className:"flex items-center justify-center min-h-screen",children:(0,re.jsxs)("div",{className:"text-center max-w-md mx-auto p-8",children:[(0,re.jsx)(Fs.A,{className:"mx-auto h-16 w-16 text-slate-400 mb-4"}),(0,re.jsx)("h2",{className:"text-2xl font-bold text-slate-900 mb-2",children:"Access Restricted"}),(0,re.jsxs)("p",{className:"text-slate-500 mb-6",children:["You don't have permission to access the workspace dashboard for ",(0,re.jsx)("strong",{children:e.name}),". Only workspace administrators and owners can manage workspace settings."]}),(0,re.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,re.jsx)("div",{className:"flex items-center justify-center py-12",children:(0,re.jsxs)("div",{className:"text-center",children:[(0,re.jsx)(fv.A,{className:"mx-auto h-12 w-12 text-slate-400 mb-4"}),(0,re.jsx)("h2",{className:"text-xl font-bold text-slate-900 mb-2",children:"Workspace Not Found"}),(0,re.jsx)("p",{className:"text-slate-500",children:"The requested workspace could not be found or you don't have access to it."})]})})}function Zy(){const{workspaceId:e}=(0,Z.g)();return(0,re.jsx)(Ty,{workspaceId:e,children:(0,re.jsx)(Jy,{})})}function Ky(){const e=(0,Z.Zp)(),[s,t]=(0,H.useState)(""),[a,n]=(0,H.useState)(!1),[r,l]=(0,H.useState)("");return(0,re.jsx)("div",{className:"min-h-screen p-8",children:(0,re.jsxs)("div",{className:"max-w-2xl mx-auto",children:[(0,re.jsxs)("div",{className:"mb-8",children:[(0,re.jsxs)(Hs,{variant:"ghost",onClick:()=>e(-1),className:"mb-4 text-slate-600 hover:text-slate-800",children:[(0,re.jsx)(Cc.A,{className:"mr-2 h-4 w-4"}),"Back"]}),(0,re.jsxs)("div",{className:"flex items-center gap-3 mb-2",children:[(0,re.jsx)("div",{className:"rounded-lg bg-orange-100 p-3",children:(0,re.jsx)(Gr.A,{className:"h-6 w-6 text-orange-600"})}),(0,re.jsxs)("div",{children:[(0,re.jsx)("h1",{className:"text-3xl font-bold text-slate-900",children:"Create a Workspace"}),(0,re.jsx)("p",{className:"text-slate-600",children:"Start collaborating with your workspace members"})]})]})]}),(0,re.jsxs)(it,{className:"shadow-sm",children:[(0,re.jsx)(ot,{children:(0,re.jsxs)(ct,{className:"flex items-center gap-2",children:[(0,re.jsx)(Gr.A,{className:"h-5 w-5 text-slate-600"}),"Workspace Information"]})}),(0,re.jsx)(mt,{children:(0,re.jsxs)("form",{onSubmit:async t=>{if(t.preventDefault(),s.trim()){n(!0),l("");try{const t=(await xe.createWorkspace(s.trim())).workspace_id;e("/workspace/".concat(t))}catch(i){var a,r;const e=(null==i||null===(a=i.response)||void 0===a||null===(r=a.data)||void 0===r?void 0:r.detail)||i.message||"Failed to create workspace";e.includes("Workspace limit reached")?l("Workspace limit reached. You can create a maximum of 3 workspaces."):l(e)}finally{n(!1)}}else l("Workspace name is required")},className:"space-y-6",children:[(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsxs)(Nt,{htmlFor:"workspaceName",className:"text-sm font-medium text-slate-700",children:["Workspace Name ",(0,re.jsx)("span",{className:"text-red-500",children:"*"})]}),(0,re.jsx)(ft,{id:"workspaceName",type:"text",placeholder:"Enter your workspace name",value:s,onChange:e=>t(e.target.value),disabled:a,className:"w-full",maxLength:100}),(0,re.jsx)("p",{className:"text-xs text-slate-500",children:"Choose a name that represents your workspace"})]}),r&&(0,re.jsx)("div",{className:"p-3 bg-red-50 border border-red-200 rounded-md",children:(0,re.jsx)("p",{className:"text-sm text-red-600",children:r})}),(0,re.jsxs)("div",{className:"flex gap-3",children:[(0,re.jsx)(Hs,{type:"button",variant:"outline",onClick:()=>e(-1),disabled:a,className:"flex-1",children:"Cancel"}),(0,re.jsx)(Hs,{type:"submit",disabled:a||!s.trim(),className:"flex-1 bg-orange-500 hover:bg-orange-600 text-white",children:a?(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)("div",{className:"animate-spin rounded-full h-4 w-4 border-t-2 border-b-2 border-white mr-2"}),"Creating Workspace..."]}):(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(Gr.A,{className:"mr-2 h-4 w-4"}),"Create Workspace"]})})]})]})})]}),(0,re.jsx)(it,{className:"mt-6 bg-teal-50 border-teal-200",children:(0,re.jsx)(mt,{className:"pt-6",children:(0,re.jsxs)("div",{className:"flex items-start gap-3",children:[(0,re.jsx)("div",{className:"rounded-full bg-teal-100 p-2 mt-0.5",children:(0,re.jsx)(Gr.A,{className:"h-4 w-4 text-teal-600"})}),(0,re.jsxs)("div",{children:[(0,re.jsx)("h3",{className:"font-medium text-teal-900 mb-1",children:"What happens next?"}),(0,re.jsxs)("ul",{className:"text-sm text-teal-800 space-y-1",children:[(0,re.jsx)("li",{children:"\u2022 You'll be the workspace owner with full management permissions"}),(0,re.jsx)("li",{children:"\u2022 You can invite workspace members and manage seats"}),(0,re.jsx)("li",{children:"\u2022 Access your workspace dashboard to get started"})]})]})]})})})]})})}const Xy=()=>{var e,s,t,a;const[n,r]=(0,H.useState)(null),[l,i]=(0,H.useState)(!0),[o,c]=(0,H.useState)(!1),[d,m]=(0,H.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,H.useEffect)(()=>{if(!v)return m("Invalid invitation link"),void i(!1);b()},[v]);const b=async()=>{try{const e=await xe.getInvitationDetails(v);r(e)}catch(t){var e,s;404===(null===(e=t.response)||void 0===e?void 0:e.status)?m("Invitation not found"):410===(null===(s=t.response)||void 0===s?void 0:s.status)?m("This invitation has expired"):m("Failed to load invitation details")}finally{i(!1)}};return l?(0,re.jsx)("div",{className:"min-h-screen bg-slate-50 flex items-center justify-center",children:(0,re.jsxs)("div",{className:"flex items-center gap-3 text-slate-600",children:[(0,re.jsx)(Ze.A,{className:"h-6 w-6 animate-spin"}),(0,re.jsx)("span",{children:"Loading invitation..."})]})}):d?(0,re.jsx)("div",{className:"min-h-screen bg-slate-50 flex items-center justify-center p-4",children:(0,re.jsxs)(it,{className:"w-full max-w-md",children:[(0,re.jsxs)(ot,{className:"text-center",children:[(0,re.jsx)("div",{className:"mx-auto w-12 h-12 bg-red-100 rounded-full flex items-center justify-center mb-4",children:(0,re.jsx)(Xe.A,{className:"h-6 w-6 text-red-600"})}),(0,re.jsx)(ct,{className:"text-red-900",children:"Invitation Error"}),(0,re.jsx)(dt,{className:"text-red-600",children:d})]}),(0,re.jsx)(mt,{children:(0,re.jsx)(Hs,{onClick:()=>x("/"),className:"w-full",variant:"outline",children:"Go to Homepage"})})]})}):(0,re.jsx)("div",{className:"min-h-screen bg-slate-50 flex items-center justify-center p-4",children:(0,re.jsxs)(it,{className:"w-full max-w-lg",children:[(0,re.jsxs)(ot,{className:"text-center",children:[(0,re.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,re.jsx)(Gr.A,{className:"h-8 w-8 text-white"})}),(0,re.jsx)(ct,{className:"text-2xl text-slate-900",children:"You're Invited!"}),(0,re.jsx)(dt,{className:"text-slate-600",children:"Join your workspace and start collaborating"})]}),(0,re.jsxs)(mt,{className:"space-y-6",children:[(0,re.jsxs)("div",{className:"bg-slate-50 rounded-lg p-4 space-y-3",children:[(0,re.jsxs)("div",{className:"flex items-center gap-3",children:[(0,re.jsx)(Gr.A,{className:"h-5 w-5 text-slate-500"}),(0,re.jsxs)("div",{children:[(0,re.jsx)("p",{className:"font-semibold text-slate-900",children:n.workspace.name}),(0,re.jsx)("p",{className:"text-sm text-slate-600",children:n.workspace.domain})]})]}),(0,re.jsxs)("div",{className:"flex items-center gap-3",children:[(0,re.jsx)(Im.A,{className:"h-5 w-5 text-slate-500"}),(0,re.jsxs)("div",{children:[(0,re.jsx)("p",{className:"text-sm text-slate-600",children:"Invited as"}),(0,re.jsxs)("div",{className:"flex items-center gap-2",children:[(0,re.jsx)("span",{className:"font-medium text-slate-900",children:n.email}),(0,re.jsx)(et,{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,re.jsxs)("div",{className:"flex items-center gap-3",children:[(0,re.jsx)(im.A,{className:"h-5 w-5 text-slate-500"}),(0,re.jsxs)("div",{children:[(0,re.jsx)("p",{className:"text-sm text-slate-600",children:"Expires"}),(0,re.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===(s=n.email)||void 0===s?void 0:s.toLowerCase())&&(0,re.jsxs)(us,{className:"border-amber-200 bg-amber-50",children:[(0,re.jsx)(Xe.A,{className:"h-4 w-4 text-amber-600"}),(0,re.jsx)(hs,{className:"text-amber-800",children:(0,re.jsxs)("div",{className:"flex flex-col gap-3",children:[(0,re.jsxs)("div",{children:["This invitation was sent to ",(0,re.jsx)("strong",{children:n.email}),", but you're logged in as ",(0,re.jsx)("strong",{children:h.email}),". Please log in with the correct account to accept this invitation."]}),(0,re.jsx)(Hs,{onClick:async()=>{try{await p(),Xr.toast.success("Logged out successfully. Please log in with the correct email address."),x("/login")}catch(e){Xr.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,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(Ze.A,{className:"mr-2 h-3 w-3 animate-spin"}),"Logging out..."]}):"Logout & Login with Correct Email"})]})})]}),(null==h||null===(t=h.email)||void 0===t?void 0:t.toLowerCase())===(null==n||null===(a=n.email)||void 0===a?void 0:a.toLowerCase())&&(0,re.jsxs)("div",{className:"flex gap-3",children:[(0,re.jsx)(Hs,{onClick:async()=>{var e,s;if((null==h||null===(e=h.email)||void 0===e?void 0:e.toLowerCase())===(null==n||null===(s=n.email)||void 0===s?void 0:s.toLowerCase())){c(!0);try{var t;const e=await xe.acceptInvitation(v);await f(),null!==(t=e.workspace)&&void 0!==t&&t.id&&g(e.workspace.id),Xr.toast.success("Welcome to ".concat(e.workspace.name,"!")),x("/")}catch(l){var a,r;const e=(null===(a=l.response)||void 0===a||null===(r=a.data)||void 0===r?void 0:r.detail)||l.message||"Failed to accept invitation";Xr.toast.error(e)}finally{c(!1)}}else Xr.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,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(Ze.A,{className:"mr-2 h-4 w-4 animate-spin"}),"Accepting..."]}):(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(Px.A,{className:"mr-2 h-4 w-4"}),"Accept Invitation"]})}),(0,re.jsx)(Hs,{onClick:async()=>{c(!0);try{await xe.declineInvitation(v),Xr.toast.success("Invitation declined"),x("/")}catch(t){var e,s;const a=(null===(e=t.response)||void 0===e||null===(s=e.data)||void 0===s?void 0:s.detail)||t.message||"Failed to decline invitation";Xr.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,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(Ze.A,{className:"mr-2 h-4 w-4 animate-spin"}),"Declining..."]}):(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(Dx.A,{className:"mr-2 h-4 w-4"}),"Decline"]})})]}),(0,re.jsx)("div",{className:"text-center",children:(0,re.jsx)("p",{className:"text-xs text-slate-500",children:"If you didn't expect this invitation, you can safely ignore it."})})]})]})})};var Qy=t(12671),eN=t(54203),sN=t(72528);const tN={primary:"#0ea5e9",secondary:"#64748b",success:"#10b981",warning:"#f59e0b",danger:"#ef4444",purple:"#8b5cf6",teal:"#14b8a6",orange:"#f97316"},aN=[tN.primary,tN.teal,tN.purple,tN.warning,tN.orange,tN.danger],nN=e=>{let{title:s,value:t,description:a,icon:n,trend:r,color:l=tN.primary}=e;return(0,re.jsxs)(it,{children:[(0,re.jsxs)(ot,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[(0,re.jsx)(ct,{className:"text-sm font-medium",children:s}),(0,re.jsx)(n,{className:"h-4 w-4",style:{color:l}})]}),(0,re.jsxs)(mt,{children:[(0,re.jsx)("div",{className:"text-2xl font-bold",children:t}),a&&(0,re.jsx)("p",{className:"text-xs text-muted-foreground",children:a}),r&&(0,re.jsxs)("div",{className:"flex items-center text-xs mt-2",children:[(0,re.jsx)(ya.A,{className:"h-3 w-3 mr-1",style:{color:r>0?tN.success:tN.danger}}),(0,re.jsxs)("span",{style:{color:r>0?tN.success:tN.danger},children:[Math.abs(r),"% from last period"]})]})]})]})},rN=e=>{let{ticketClass:s}=e;return(0,re.jsxs)(it,{className:"hover:shadow-lg transition-shadow",children:[(0,re.jsxs)(ot,{children:[(0,re.jsx)(ct,{className:"text-lg",children:s.class_name}),(0,re.jsx)(dt,{children:s.description})]}),(0,re.jsxs)(mt,{className:"space-y-4",children:[(0,re.jsxs)("div",{children:[(0,re.jsx)("h4",{className:"text-sm font-semibold mb-2",children:"Example Tickets:"}),(0,re.jsx)("ul",{className:"text-sm text-muted-foreground space-y-1",children:s.example_titles.slice(0,3).map((e,s)=>(0,re.jsxs)("li",{className:"line-clamp-1",children:["\u2022 ",e]},s))})]}),(0,re.jsxs)("div",{children:[(0,re.jsx)("h4",{className:"text-sm font-semibold mb-2",children:"Common Issues:"}),(0,re.jsx)("div",{className:"flex flex-wrap gap-1",children:s.common_issues.slice(0,3).map((e,s)=>(0,re.jsx)(et,{variant:"secondary",className:"text-xs",children:e},s))})]}),s.suggested_improvements&&(0,re.jsxs)("div",{className:"pt-2 border-t",children:[(0,re.jsx)("h4",{className:"text-sm font-semibold mb-1 text-teal-700",children:"Suggested Improvements:"}),(0,re.jsx)("p",{className:"text-xs text-muted-foreground",children:s.suggested_improvements})]}),(0,re.jsxs)("div",{className:"text-xs text-muted-foreground",children:[s.ticket_ids.length," tickets in this category"]})]})]})};function lN(){const[e,s]=(0,H.useState)(!0),[t,a]=(0,H.useState)(!1),[n,r]=(0,H.useState)(!1),[l,i]=(0,H.useState)(null),[o,c]=(0,H.useState)(null),[d,m]=(0,H.useState)(null),[u,x]=(0,H.useState)({preset:"last7days",startDate:la()().subtract(7,"days").startOf("day").toISOString(),endDate:la()().endOf("day").toISOString()}),[h,p]=(0,H.useState)(null),g=[{value:"today",label:"Today",getDates:()=>({startDate:la()().startOf("day").toISOString(),endDate:la()().endOf("day").toISOString()})},{value:"yesterday",label:"Yesterday",getDates:()=>({startDate:la()().subtract(1,"day").startOf("day").toISOString(),endDate:la()().subtract(1,"day").endOf("day").toISOString()})},{value:"last2days",label:"Last 2 Days",getDates:()=>({startDate:la()().subtract(2,"days").startOf("day").toISOString(),endDate:la()().endOf("day").toISOString()})},{value:"last3days",label:"Last 3 Days",getDates:()=>({startDate:la()().subtract(3,"days").startOf("day").toISOString(),endDate:la()().endOf("day").toISOString()})},{value:"last7days",label:"Last 7 Days",getDates:()=>({startDate:la()().subtract(7,"days").startOf("day").toISOString(),endDate:la()().endOf("day").toISOString()})},{value:"last14days",label:"Last 14 Days",getDates:()=>({startDate:la()().subtract(14,"days").startOf("day").toISOString(),endDate:la()().endOf("day").toISOString()})},{value:"last30days",label:"Last 30 Days",getDates:()=>({startDate:la()().subtract(30,"days").startOf("day").toISOString(),endDate:la()().endOf("day").toISOString()})},{value:"last60days",label:"Last 60 Days",getDates:()=>({startDate:la()().subtract(60,"days").startOf("day").toISOString(),endDate:la()().endOf("day").toISOString()})},{value:"last90days",label:"Last 90 Days",getDates:()=>({startDate:la()().subtract(90,"days").startOf("day").toISOString(),endDate:la()().endOf("day").toISOString()})},{value:"thisWeek",label:"This Week",getDates:()=>({startDate:la()().startOf("week").toISOString(),endDate:la()().endOf("day").toISOString()})},{value:"lastWeek",label:"Last Week",getDates:()=>({startDate:la()().subtract(1,"week").startOf("week").toISOString(),endDate:la()().subtract(1,"week").endOf("week").toISOString()})},{value:"thisMonth",label:"This Month",getDates:()=>({startDate:la()().startOf("month").toISOString(),endDate:la()().endOf("day").toISOString()})},{value:"lastMonth",label:"Last Month",getDates:()=>({startDate:la()().subtract(1,"month").startOf("month").toISOString(),endDate:la()().subtract(1,"month").endOf("month").toISOString()})},{value:"thisQuarter",label:"This Quarter",getDates:()=>({startDate:la()().startOf("quarter").toISOString(),endDate:la()().endOf("day").toISOString()})},{value:"lastQuarter",label:"Last Quarter",getDates:()=>({startDate:la()().subtract(1,"quarter").startOf("quarter").toISOString(),endDate:la()().subtract(1,"quarter").endOf("quarter").toISOString()})},{value:"thisYear",label:"This Year",getDates:()=>({startDate:la()().startOf("year").toISOString(),endDate:la()().endOf("day").toISOString()})},{value:"lastYear",label:"Last Year",getDates:()=>({startDate:la()().subtract(1,"year").startOf("year").toISOString(),endDate:la()().subtract(1,"year").endOf("year").toISOString()})}];(0,H.useEffect)(()=>{f()},[u]);const f=async()=>{try{s(!0),m(null);const e=await yj.getOperationalMetrics(u.startDate,u.endDate);i(e)}catch(e){m("Failed to load analytics data")}finally{s(!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=l?Object.entries(l.tickets_by_category).map(e=>{let[s,t]=e;return{name:"uncategorized"===s?"Uncategorized":s.replace(/_/g," "),value:t}}):[],j=l?Object.entries(l.tickets_by_user_tier).map(e=>{let[s,t]=e;return{name:"unknown"===s?"Unknown":s,value:t}}):[],y=(null==l?void 0:l.busiest_days)||[],N=(null==l?void 0:l.tickets_by_hour)||[];return e?(0,re.jsx)("div",{className:"h-full w-full flex items-center justify-center",children:(0,re.jsx)(Ze.A,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):d?(0,re.jsx)("div",{className:"h-full w-full flex items-center justify-center",children:(0,re.jsxs)(it,{className:"p-6",children:[(0,re.jsxs)("div",{className:"flex items-center space-x-2 text-red-600",children:[(0,re.jsx)(Xe.A,{className:"h-5 w-5"}),(0,re.jsx)("p",{children:d})]}),(0,re.jsx)(Hs,{onClick:f,className:"mt-4",children:"Retry"})]})}):(0,re.jsxs)("div",{className:"container mx-auto py-6 space-y-6",children:[(0,re.jsxs)("div",{className:"flex items-center justify-between",children:[(0,re.jsxs)("div",{children:[(0,re.jsx)("h1",{className:"text-3xl font-bold text-slate-900",children:"Support Analytics"}),(0,re.jsx)("p",{className:"text-muted-foreground mt-1",children:"Analyze support ticket trends and performance metrics"}),(0,re.jsxs)("p",{className:"text-sm text-muted-foreground mt-2 flex items-center gap-1",children:[(0,re.jsx)(im.A,{className:"h-3 w-3"}),la()(u.startDate).format("MMM DD, YYYY")," - ",la()(u.endDate).format("MMM DD, YYYY")]})]}),(0,re.jsxs)("div",{className:"flex items-center gap-3",children:[(0,re.jsxs)(Ut,{value:u.preset,onValueChange:e=>{const s=g.find(s=>s.value===e);if(s){const t=s.getDates();x((0,K.A)({preset:e},t))}},children:[(0,re.jsxs)(Wt,{className:"w-[200px]",children:[(0,re.jsx)(im.A,{className:"h-4 w-4 mr-2"}),(0,re.jsx)(qt,{})]}),(0,re.jsxs)(Ht,{className:"max-h-[400px]",children:[(0,re.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,re.jsx)($t,{value:e.value,children:e.label},e.value)),(0,re.jsx)("div",{className:"my-1 h-px bg-border"}),(0,re.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,re.jsx)($t,{value:e.value,children:e.label},e.value)),(0,re.jsx)("div",{className:"my-1 h-px bg-border"}),(0,re.jsx)("div",{className:"px-2 py-1.5 text-xs font-semibold text-muted-foreground",children:"Quarterly/Yearly"}),g.slice(13).map(e=>(0,re.jsx)($t,{value:e.value,children:e.label},e.value))]})]}),(0,re.jsxs)(Hs,{onClick:async()=>{try{a(!0),await yj.exportTicketsCSV(u.startDate,u.endDate,h)}catch(e){alert("Failed to export tickets")}finally{a(!1)}},disabled:t,variant:"outline",children:[t?(0,re.jsx)(Ze.A,{className:"h-4 w-4 animate-spin mr-2"}):(0,re.jsx)(Rd.A,{className:"h-4 w-4 mr-2"}),"Export CSV"]})]})]}),(0,re.jsxs)("div",{className:"grid gap-4 md:grid-cols-2 lg:grid-cols-4",children:[(0,re.jsx)(nN,{title:"Total Tickets",value:(null==l?void 0:l.total_tickets)||0,description:"".concat((null==l?void 0:l.open_tickets)||0," open, ").concat((null==l?void 0:l.resolved_tickets)||0," resolved"),icon:bl.A,color:tN.primary}),(0,re.jsx)(nN,{title:"Avg Response Time",value:v(null==l?void 0:l.avg_response_time_hours),description:"First admin response",icon:Xp.A,color:tN.teal}),(0,re.jsx)(nN,{title:"Avg Resolution Time",value:v(null==l?void 0:l.avg_resolution_time_hours),description:"Time to resolve tickets",icon:Px.A,color:tN.success}),(0,re.jsx)(nN,{title:"Pending Admin Response",value:(null==l?void 0:l.tickets_pending_admin_response)||0,description:"".concat((null==l?void 0:l.tickets_pending_user_response)||0," pending user response"),icon:Xe.A,color:tN.warning})]}),(0,re.jsxs)(hl,{defaultValue:"overview",className:"space-y-4",children:[(0,re.jsxs)(pl,{children:[(0,re.jsx)(gl,{value:"overview",children:"Overview"}),(0,re.jsx)(gl,{value:"trends",children:"AI Trend Analysis"}),(0,re.jsx)(gl,{value:"performance",children:"Performance"})]}),(0,re.jsxs)(fl,{value:"overview",className:"space-y-4",children:[(0,re.jsxs)("div",{className:"grid gap-4 md:grid-cols-2",children:[(0,re.jsxs)(it,{children:[(0,re.jsxs)(ot,{children:[(0,re.jsx)(ct,{children:"Tickets by Category"}),(0,re.jsx)(dt,{children:"Distribution of support tickets across categories"})]}),(0,re.jsx)(mt,{children:(0,re.jsx)("div",{className:"h-[300px]",children:(0,re.jsx)(Wx.u,{width:"100%",height:"100%",children:(0,re.jsxs)(Qy.r,{children:[(0,re.jsx)(eN.F,{data:b,cx:"50%",cy:"50%",labelLine:!1,outerRadius:80,fill:"#8884d8",dataKey:"value",label:e=>{let{name:s,percent:t}=e;return"".concat(s," ").concat((100*t).toFixed(0),"%")},children:b.map((e,s)=>(0,re.jsx)(sN.f,{fill:aN[s%aN.length]},"cell-".concat(s)))}),(0,re.jsx)($x.m,{})]})})})})]}),(0,re.jsxs)(it,{children:[(0,re.jsxs)(ot,{children:[(0,re.jsx)(ct,{children:"Tickets by User Tier"}),(0,re.jsx)(dt,{children:"Support requests by subscription tier"})]}),(0,re.jsx)(mt,{children:(0,re.jsx)("div",{className:"h-[300px]",children:(0,re.jsx)(Wx.u,{width:"100%",height:"100%",children:(0,re.jsxs)(xf.E,{data:j,children:[(0,re.jsx)(Yx.d,{strokeDasharray:"3 3"}),(0,re.jsx)(Hx.W,{dataKey:"name"}),(0,re.jsx)(Gx.h,{}),(0,re.jsx)($x.m,{}),(0,re.jsx)(hf.y,{dataKey:"value",fill:tN.purple})]})})})})]})]}),(0,re.jsxs)(it,{children:[(0,re.jsxs)(ot,{children:[(0,re.jsx)(ct,{children:"Ticket Volume Over Time"}),(0,re.jsx)(dt,{children:"Daily ticket creation trends"})]}),(0,re.jsx)(mt,{children:(0,re.jsx)("div",{className:"h-[300px]",children:(0,re.jsx)(Wx.u,{width:"100%",height:"100%",children:(0,re.jsxs)(Vx.Q,{data:y,children:[(0,re.jsx)(Yx.d,{strokeDasharray:"3 3"}),(0,re.jsx)(Hx.W,{dataKey:"date",tickFormatter:e=>la()(e).format("MMM DD")}),(0,re.jsx)(Gx.h,{}),(0,re.jsx)($x.m,{labelFormatter:e=>la()(e).format("MMMM DD, YYYY")}),(0,re.jsx)(Jx.G,{type:"monotone",dataKey:"count",stroke:tN.primary,fill:tN.primary,fillOpacity:.3,name:"Tickets"})]})})})})]}),(0,re.jsxs)(it,{children:[(0,re.jsxs)(ot,{children:[(0,re.jsx)(ct,{children:"Tickets by Hour of Day"}),(0,re.jsx)(dt,{children:"When support tickets are typically created"})]}),(0,re.jsx)(mt,{children:(0,re.jsx)("div",{className:"h-[300px]",children:(0,re.jsx)(Wx.u,{width:"100%",height:"100%",children:(0,re.jsxs)(xf.E,{data:N,children:[(0,re.jsx)(Yx.d,{strokeDasharray:"3 3"}),(0,re.jsx)(Hx.W,{dataKey:"label",angle:-45,textAnchor:"end",height:60}),(0,re.jsx)(Gx.h,{}),(0,re.jsx)($x.m,{labelFormatter:e=>"Hour: ".concat(e),formatter:e=>["".concat(e," tickets"),"Count"]}),(0,re.jsx)(hf.y,{dataKey:"count",fill:tN.teal,radius:[4,4,0,0]})]})})})})]})]}),(0,re.jsx)(fl,{value:"trends",className:"space-y-4",children:(0,re.jsxs)(it,{children:[(0,re.jsxs)(ot,{children:[(0,re.jsxs)(ct,{className:"flex items-center gap-2",children:[(0,re.jsx)($b.A,{className:"h-5 w-5 text-purple-500"}),"AI-Powered Trend Analysis"]}),(0,re.jsx)(dt,{children:"Use AI to identify patterns and group similar tickets"})]}),(0,re.jsxs)(mt,{children:[(0,re.jsxs)("div",{className:"flex items-center gap-3 mb-4",children:[(0,re.jsxs)(Ut,{value:h||"all",onValueChange:e=>p("all"===e?null:e),children:[(0,re.jsx)(Wt,{className:"w-[200px]",children:(0,re.jsx)(qt,{placeholder:"Filter by category"})}),(0,re.jsxs)(Ht,{children:[(0,re.jsx)($t,{value:"all",children:"All Categories"}),(0,re.jsx)($t,{value:"authentication",children:"Authentication"}),(0,re.jsx)($t,{value:"billing",children:"Billing"}),(0,re.jsx)($t,{value:"bug_report",children:"Bug Reports"}),(0,re.jsx)($t,{value:"integrations_and_backend_functions",children:"Integrations"}),(0,re.jsx)($t,{value:"chat_issues",children:"Chat Issues"}),(0,re.jsx)($t,{value:"security",children:"Security"}),(0,re.jsx)($t,{value:"other",children:"Other"})]})]}),(0,re.jsx)(Hs,{onClick:async()=>{try{r(!0),c(null);const e=await yj.runTrendAnalysis(u.startDate,u.endDate,h);c(e)}catch(e){alert("Failed to run trend analysis")}finally{r(!1)}},disabled:n,children:n?(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(Ze.A,{className:"h-4 w-4 animate-spin mr-2"}),"Analyzing..."]}):(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(kd.A,{className:"h-4 w-4 mr-2"}),"Run Analysis"]})})]}),o&&(0,re.jsxs)("div",{className:"space-y-4",children:[(0,re.jsxs)("div",{className:"bg-slate-50 p-4 rounded-lg",children:[(0,re.jsx)("h3",{className:"font-semibold mb-2",children:"Analysis Summary"}),(0,re.jsx)("p",{className:"text-sm text-muted-foreground",children:o.analysis_summary}),(0,re.jsxs)("p",{className:"text-xs text-muted-foreground mt-2",children:["Analyzed ",o.total_tickets_analyzed," tickets"]})]}),(0,re.jsxs)("div",{children:[(0,re.jsx)("h3",{className:"font-semibold mb-3",children:"Identified Ticket Classes"}),(0,re.jsx)("div",{className:"grid gap-4 md:grid-cols-2",children:o.ticket_classes.map((e,s)=>(0,re.jsx)(rN,{ticketClass:e},s))})]}),o.recommendations&&o.recommendations.length>0&&(0,re.jsxs)("div",{className:"bg-teal-50 p-4 rounded-lg",children:[(0,re.jsx)("h3",{className:"font-semibold mb-2 text-teal-900",children:"Strategic Recommendations"}),(0,re.jsx)("ul",{className:"space-y-2",children:o.recommendations.map((e,s)=>(0,re.jsxs)("li",{className:"text-sm text-teal-800 flex items-start",children:[(0,re.jsx)("span",{className:"text-teal-600 mr-2",children:"\u2022"}),e]},s))})]})]}),!o&&!n&&(0,re.jsxs)("div",{className:"text-center py-12 text-muted-foreground",children:[(0,re.jsx)(kd.A,{className:"h-12 w-12 mx-auto mb-3 text-slate-300"}),(0,re.jsx)("p",{children:'Click "Run Analysis" to generate AI insights'})]})]})]})}),(0,re.jsx)(fl,{value:"performance",className:"space-y-4",children:(0,re.jsxs)("div",{className:"grid gap-4 md:grid-cols-2",children:[(0,re.jsxs)(it,{children:[(0,re.jsxs)(ot,{children:[(0,re.jsx)(ct,{children:"Tickets by Assignee"}),(0,re.jsx)(dt,{children:"Workload distribution across team members"})]}),(0,re.jsx)(mt,{children:(0,re.jsx)("div",{className:"space-y-3",children:l&&Object.entries(l.tickets_by_assignee).map(e=>{let[s,t]=e;return(0,re.jsxs)("div",{className:"flex items-center justify-between",children:[(0,re.jsxs)("div",{className:"flex items-center gap-2",children:[(0,re.jsx)(Gr.A,{className:"h-4 w-4 text-muted-foreground"}),(0,re.jsx)("span",{className:"text-sm",children:"unassigned"===s?"Unassigned":s})]}),(0,re.jsx)(et,{variant:"unassigned"===s?"secondary":"default",children:t})]},s)})})})]}),(0,re.jsxs)(it,{children:[(0,re.jsxs)(ot,{children:[(0,re.jsx)(ct,{children:"Response Status"}),(0,re.jsx)(dt,{children:"Current pending responses breakdown"})]}),(0,re.jsx)(mt,{children:(0,re.jsxs)("div",{className:"space-y-4",children:[(0,re.jsxs)("div",{className:"flex items-center justify-between p-3 bg-orange-50 rounded-lg",children:[(0,re.jsxs)("div",{className:"flex items-center gap-2",children:[(0,re.jsx)(Xe.A,{className:"h-5 w-5 text-orange-600"}),(0,re.jsx)("span",{className:"font-medium",children:"Pending Admin"})]}),(0,re.jsx)("span",{className:"text-2xl font-bold text-orange-600",children:(null==l?void 0:l.tickets_pending_admin_response)||0})]}),(0,re.jsxs)("div",{className:"flex items-center justify-between p-3 bg-blue-50 rounded-lg",children:[(0,re.jsxs)("div",{className:"flex items-center gap-2",children:[(0,re.jsx)(Xp.A,{className:"h-5 w-5 text-blue-600"}),(0,re.jsx)("span",{className:"font-medium",children:"Pending User"})]}),(0,re.jsx)("span",{className:"text-2xl font-bold text-blue-600",children:(null==l?void 0:l.tickets_pending_user_response)||0})]})]})})]})]})})]})]})}const iN=["className"],oN=["className"],cN=["className"],dN=["className"],mN=["className"],uN=["className"],xN=["className"],hN=["className"],pN=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,iN);return(0,re.jsx)("div",{className:"relative w-full overflow-auto",children:(0,re.jsx)("table",(0,K.A)({ref:s,className:is("w-full caption-bottom text-sm",t)},a))})});pN.displayName="Table";const gN=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,oN);return(0,re.jsx)("thead",(0,K.A)({ref:s,className:is("[&_tr]:border-b",t)},a))});gN.displayName="TableHeader";const fN=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,cN);return(0,re.jsx)("tbody",(0,K.A)({ref:s,className:is("[&_tr:last-child]:border-0",t)},a))});fN.displayName="TableBody";H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,dN);return(0,re.jsx)("tfoot",(0,K.A)({ref:s,className:is("border-t bg-muted/50 font-medium [&>tr]:last:border-b-0",t)},a))}).displayName="TableFooter";const vN=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,mN);return(0,re.jsx)("tr",(0,K.A)({ref:s,className:is("border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",t)},a))});vN.displayName="TableRow";const bN=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,uN);return(0,re.jsx)("th",(0,K.A)({ref:s,className:is("h-12 px-4 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0",t)},a))});bN.displayName="TableHead";const jN=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,xN);return(0,re.jsx)("td",(0,K.A)({ref:s,className:is("p-4 align-middle [&:has([role=checkbox])]:pr-0",t)},a))});jN.displayName="TableCell";H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,hN);return(0,re.jsx)("caption",(0,K.A)({ref:s,className:is("mt-4 text-sm text-muted-foreground",t)},a))}).displayName="TableCaption";const yN=[{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 NN(){var e,s,t,a;const{user:n}=oe(),[r,l]=(0,H.useState)([]),[i,o]=(0,H.useState)(!1),[c,d]=(0,H.useState)(""),[m,u]=(0,H.useState)({key:"created_date",direction:"desc"}),[x,h]=(0,H.useState)(null),[p,g]=(0,H.useState)({}),[f,v]=(0,H.useState)({}),[b,j]=(0,H.useState)(new Set),[y,N]=(0,H.useState)("all"),[w,_]=(0,H.useState)("en"),[k,A]=(0,H.useState)("all"),[S,C]=(0,H.useState)(""),[E,I]=(0,H.useState)(""),[T,P]=(0,H.useState)(1),[L,O]=(0,H.useState)(0),R=100,[D,M]=(0,H.useState)(!1),[F,B]=(0,H.useState)([]),[U,z]=(0,H.useState)(!1),[q,W]=(0,H.useState)({isOpen:!1,action:null,item:null}),[V,Y]=(0,H.useState)(""),[G,$]=(0,H.useState)("en"),[J,Z]=(0,H.useState)({isOpen:!1,imageUrl:"",imageAlt:""});(0,H.useEffect)(()=>{X()},[]),(0,H.useEffect)(()=>{if(x&&clearTimeout(x),1===T)return h(setTimeout(()=>{X()},500)),()=>{x&&clearTimeout(x)};P(1)},[c,y,w,k,S,E,m]),(0,H.useEffect)(()=>{X()},[T]);const X=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 s=la()();let t;switch(k){case"today":t=s.clone().startOf("day"),e.created_at={$gte:t.toISOString()};break;case"week":t=s.clone().subtract(7,"days").startOf("day"),e.created_at={$gte:t.toISOString()};break;case"month":t=s.clone().subtract(30,"days").startOf("day"),e.created_at={$gte:t.toISOString()};break;case"custom":S&&E?e.created_at={$gte:la()(S).startOf("day").toISOString(),$lte:la()(E).endOf("day").toISOString()}:S?e.created_at={$gte:la()(S).startOf("day").toISOString()}:E&&(e.created_at={$lte:la()(E).endOf("day").toISOString()})}}const s=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})),t=s.items||s;l(t),t.length{$(s.item.language||"en"),W({isOpen:!0,action:e,item:s})},ee=()=>{W({isOpen:!1,action:null,item:null}),Y("")},se=e=>{const s=m.key===e&&"asc"===m.direction?"desc":"asc";u({key:e,direction:s}),P(1)},te=()=>"all"!==y||"en"!==w||"all"!==k||""!==c||""!==S||""!==E,ae=e=>{const s=yN.find(s=>s.value===e);return s?s.label:e},ne=e=>{switch(e){case"approved":return(0,re.jsxs)(Nn,{className:"bg-emerald-100 text-emerald-700 border-emerald-200 font-medium px-2.5 py-0.5 text-xs",children:[(0,re.jsx)("div",{className:"w-1.5 h-1.5 bg-emerald-500 rounded-full mr-1.5"}),"Approved"]});case"pending":return(0,re.jsxs)(Nn,{className:"bg-amber-100 text-amber-700 border-amber-200 font-medium px-2.5 py-0.5 text-xs",children:[(0,re.jsx)(Xp.A,{className:"w-3 h-3 mr-1.5"}),"Pending"]});case"rejected":return(0,re.jsxs)(Nn,{className:"bg-red-100 text-red-700 border-red-200 font-medium px-2.5 py-0.5 text-xs",children:[(0,re.jsx)("div",{className:"w-1.5 h-1.5 bg-red-500 rounded-full mr-1.5"}),"Rejected"]});case"archived":return(0,re.jsxs)(Nn,{className:"bg-gray-100 text-gray-700 border-gray-200 font-medium px-2.5 py-0.5 text-xs",children:[(0,re.jsx)(Wb.A,{className:"w-3 h-3 mr-1.5"}),"Archived"]});default:return(0,re.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,re.jsxs)("div",{className:"container mx-auto py-10 px-4",children:[(0,re.jsxs)("div",{className:"flex items-center justify-between mb-6",children:[(0,re.jsx)("h1",{className:"text-3xl font-bold",children:"App Templates Management"}),(0,re.jsxs)(Yn,{onClick:()=>D?M(!1):(async()=>{z(!0);try{const e=await $a.listCatalogItems({limit:1e4,skip:0,sort_by:"-created_date"}),s=e.items||e;B(s),M(!0)}catch(e){an({title:"Error",description:"Failed to fetch analytics data",variant:"destructive"})}finally{z(!1)}})(),disabled:U,className:"flex items-center gap-2",variant:D?"default":"outline",children:[(0,re.jsx)(kd.A,{className:"h-4 w-4"}),U?"Analyzing...":D?"Hide Analytics":"Analyze"]})]}),D&&F.length>0&&(0,re.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,re.jsxs)("div",{className:"flex items-center justify-between mb-8",children:[(0,re.jsxs)("div",{className:"flex items-center gap-3",children:[(0,re.jsx)("div",{className:"p-2 bg-blue-100 rounded-xl",children:(0,re.jsx)(kd.A,{className:"h-6 w-6 text-blue-600"})}),(0,re.jsxs)("div",{children:[(0,re.jsx)("h2",{className:"text-2xl font-bold text-slate-900",children:"Analytics Dashboard"}),(0,re.jsxs)("p",{className:"text-sm text-slate-600 mt-1",children:["Real-time insights across ",F.length," catalog items"]})]})]}),(0,re.jsx)(Yn,{variant:"ghost",size:"sm",onClick:()=>M(!1),className:"h-10 w-10 p-0 hover:bg-slate-100 rounded-xl",children:(0,re.jsx)(zs.A,{className:"h-5 w-5 text-slate-400"})})]}),(()=>{const e=(e=>{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},t=e.reduce((e,s)=>{const t=s.item.language||"en";return e[t]=(e[t]||0)+1,e},{}),a={totalUsage:e.reduce((e,s)=>e+s.usage,0),averageUsage:e.length?e.reduce((e,s)=>e+s.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},r=e.reduce((e,s)=>{var t;const a=(null===(t=s.item_creator)||void 0===t?void 0:t.full_name)||"Unknown";return e[a]=(e[a]||0)+1,e},{}),l=e.reduce((e,s)=>{var t;return null===(t=s.item.categories)||void 0===t||t.forEach(s=>{e[s]=(e[s]||0)+1}),e},{}),i=la()(),o=e.filter(e=>la()(e.item.created_date).isSame(i,"month")).length,c=e.filter(e=>la()(e.item.created_date).isSame(i,"quarter")).length;return{statusStats:s,languageStats:t,usageStats:a,contentStats:n,creatorStats:Object.entries(r).sort((e,s)=>{let[,t]=e,[,a]=s;return a-t}).slice(0,10),categories:Object.entries(l).sort((e,s)=>{let[,t]=e,[,a]=s;return a-t}).slice(0,10),temporalStats:{thisMonth:o,thisQuarter:c,totalCreators:Object.keys(r).length}}})(F);return(0,re.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6",children:[(0,re.jsxs)("div",{className:"bg-white p-6 rounded-xl border border-slate-200 shadow-sm hover:shadow-md transition-shadow",children:[(0,re.jsxs)("div",{className:"flex items-center gap-3 mb-6",children:[(0,re.jsx)("div",{className:"p-2 bg-emerald-100 rounded-lg",children:(0,re.jsx)($b.A,{className:"h-5 w-5 text-emerald-600"})}),(0,re.jsxs)("div",{children:[(0,re.jsx)("h3",{className:"font-semibold text-slate-800",children:"Status Overview"}),(0,re.jsx)("p",{className:"text-xs text-slate-500",children:"Approval pipeline health"})]})]}),(0,re.jsxs)("div",{className:"space-y-4",children:[(0,re.jsxs)("div",{className:"text-center p-4 bg-slate-50 rounded-lg",children:[(0,re.jsx)("div",{className:"text-3xl font-bold text-slate-900",children:e.statusStats.total}),(0,re.jsx)("div",{className:"text-sm text-slate-600 font-medium",children:"Total Apps"})]}),(0,re.jsxs)("div",{className:"space-y-3",children:[(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsxs)("div",{className:"flex justify-between items-center",children:[(0,re.jsx)("span",{className:"text-sm font-medium text-emerald-700",children:"Approved"}),(0,re.jsxs)("span",{className:"text-sm font-bold text-emerald-700",children:[e.statusStats.approved," (",(e.statusStats.approved/e.statusStats.total*100).toFixed(1),"%)"]})]}),(0,re.jsx)("div",{className:"w-full bg-emerald-100 rounded-full h-2",children:(0,re.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,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsxs)("div",{className:"flex justify-between items-center",children:[(0,re.jsx)("span",{className:"text-sm font-medium text-amber-700",children:"Pending"}),(0,re.jsxs)("span",{className:"text-sm font-bold text-amber-700",children:[e.statusStats.pending," (",(e.statusStats.pending/e.statusStats.total*100).toFixed(1),"%)"]})]}),(0,re.jsx)("div",{className:"w-full bg-amber-100 rounded-full h-2",children:(0,re.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,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsxs)("div",{className:"flex justify-between items-center",children:[(0,re.jsx)("span",{className:"text-sm font-medium text-red-700",children:"Rejected"}),(0,re.jsxs)("span",{className:"text-sm font-bold text-red-700",children:[e.statusStats.rejected," (",(e.statusStats.rejected/e.statusStats.total*100).toFixed(1),"%)"]})]}),(0,re.jsx)("div",{className:"w-full bg-red-100 rounded-full h-2",children:(0,re.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,re.jsxs)("div",{className:"bg-white p-6 rounded-xl border border-slate-200 shadow-sm hover:shadow-md transition-shadow",children:[(0,re.jsxs)("div",{className:"flex items-center gap-3 mb-6",children:[(0,re.jsx)("div",{className:"p-2 bg-blue-100 rounded-lg",children:(0,re.jsx)(Kr.A,{className:"h-5 w-5 text-blue-600"})}),(0,re.jsxs)("div",{children:[(0,re.jsx)("h3",{className:"font-semibold text-slate-800",children:"Usage Analytics"}),(0,re.jsx)("p",{className:"text-xs text-slate-500",children:"Clone and adoption metrics"})]})]}),(0,re.jsxs)("div",{className:"space-y-4",children:[(0,re.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,re.jsxs)("div",{className:"text-center p-3 bg-gradient-to-br from-blue-50 to-blue-100 rounded-lg",children:[(0,re.jsx)("div",{className:"text-2xl font-bold text-blue-900",children:e.usageStats.totalUsage.toLocaleString()}),(0,re.jsx)("div",{className:"text-xs text-blue-700 font-medium",children:"Total Clones"})]}),(0,re.jsxs)("div",{className:"text-center p-3 bg-gradient-to-br from-indigo-50 to-indigo-100 rounded-lg",children:[(0,re.jsx)("div",{className:"text-2xl font-bold text-indigo-900",children:e.usageStats.averageUsage.toFixed(1)}),(0,re.jsx)("div",{className:"text-xs text-indigo-700 font-medium",children:"Avg per App"})]})]}),(0,re.jsxs)("div",{className:"p-4 bg-slate-50 rounded-lg border-l-4 border-green-500",children:[(0,re.jsxs)("div",{className:"flex justify-between items-center",children:[(0,re.jsx)("span",{className:"text-sm font-medium text-slate-700",children:"Top Performer"}),(0,re.jsx)("span",{className:"text-lg font-bold text-green-600",children:e.usageStats.topUsage.toLocaleString()})]}),(0,re.jsx)("div",{className:"text-xs text-slate-500 mt-1",children:"Most cloned app"})]}),(0,re.jsxs)("div",{className:"p-4 bg-orange-50 rounded-lg border-l-4 border-orange-500",children:[(0,re.jsxs)("div",{className:"flex justify-between items-center",children:[(0,re.jsx)("span",{className:"text-sm font-medium text-slate-700",children:"Zero Usage"}),(0,re.jsx)("span",{className:"text-lg font-bold text-orange-600",children:e.usageStats.zeroUsage})]}),(0,re.jsxs)("div",{className:"text-xs text-slate-500 mt-1",children:[(e.usageStats.zeroUsage/e.statusStats.total*100).toFixed(1),"% of total apps"]})]})]})]}),(0,re.jsxs)("div",{className:"bg-white p-6 rounded-xl border border-slate-200 shadow-sm hover:shadow-md transition-shadow",children:[(0,re.jsxs)("div",{className:"flex items-center gap-3 mb-6",children:[(0,re.jsx)("div",{className:"p-2 bg-purple-100 rounded-lg",children:(0,re.jsx)(oh.A,{className:"h-5 w-5 text-purple-600"})}),(0,re.jsxs)("div",{children:[(0,re.jsx)("h3",{className:"font-semibold text-slate-800",children:"Content Quality"}),(0,re.jsx)("p",{className:"text-xs text-slate-500",children:"Completeness metrics"})]})]}),(0,re.jsxs)("div",{className:"space-y-4",children:[(0,re.jsxs)("div",{className:"space-y-3",children:[(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsxs)("div",{className:"flex justify-between items-center",children:[(0,re.jsx)("span",{className:"text-sm font-medium text-slate-700",children:"With Descriptions"}),(0,re.jsxs)("span",{className:"text-sm font-bold text-slate-900",children:[(e.contentStats.withDescriptions/e.statusStats.total*100).toFixed(1),"%"]})]}),(0,re.jsx)("div",{className:"w-full bg-gray-200 rounded-full h-2",children:(0,re.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,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsxs)("div",{className:"flex justify-between items-center",children:[(0,re.jsx)("span",{className:"text-sm font-medium text-slate-700",children:"With Screenshots"}),(0,re.jsxs)("span",{className:"text-sm font-bold text-slate-900",children:[(e.contentStats.withScreenshots/e.statusStats.total*100).toFixed(1),"%"]})]}),(0,re.jsx)("div",{className:"w-full bg-gray-200 rounded-full h-2",children:(0,re.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,re.jsxs)("div",{className:"grid grid-cols-2 gap-3 pt-2",children:[(0,re.jsxs)("div",{className:"text-center p-3 bg-green-50 rounded-lg border border-green-200",children:[(0,re.jsx)("div",{className:"text-xl font-bold text-green-700",children:e.contentStats.publicApps}),(0,re.jsx)("div",{className:"text-xs text-green-600 font-medium",children:"Public"})]}),(0,re.jsxs)("div",{className:"text-center p-3 bg-orange-50 rounded-lg border border-orange-200",children:[(0,re.jsx)("div",{className:"text-xl font-bold text-orange-700",children:e.contentStats.privateApps}),(0,re.jsx)("div",{className:"text-xs text-orange-600 font-medium",children:"Private"})]})]})]})]}),(0,re.jsxs)("div",{className:"bg-white p-6 rounded-xl border border-slate-200 shadow-sm hover:shadow-md transition-shadow",children:[(0,re.jsxs)("div",{className:"flex items-center gap-3 mb-6",children:[(0,re.jsx)("div",{className:"p-2 bg-teal-100 rounded-lg",children:(0,re.jsx)(bn.A,{className:"h-5 w-5 text-teal-600"})}),(0,re.jsxs)("div",{children:[(0,re.jsx)("h3",{className:"font-semibold text-slate-800",children:"Language Distribution"}),(0,re.jsx)("p",{className:"text-xs text-slate-500",children:"Global reach insights"})]})]}),(0,re.jsx)("div",{className:"space-y-3",children:Object.entries(e.languageStats).sort((e,s)=>{let[,t]=e,[,a]=s;return a-t}).slice(0,6).map((s,t)=>{let[a,n]=s;const r=n/e.statusStats.total*100;return(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsxs)("div",{className:"flex justify-between items-center",children:[(0,re.jsx)("span",{className:"text-sm font-medium text-slate-700",children:ae(a)}),(0,re.jsxs)("span",{className:"text-sm font-bold text-slate-900",children:[n," (",r.toFixed(1),"%)"]})]}),(0,re.jsx)("div",{className:"w-full bg-gray-200 rounded-full h-2",children:(0,re.jsx)("div",{className:"".concat(["bg-blue-500","bg-green-500","bg-purple-500","bg-orange-500","bg-pink-500","bg-indigo-500"][t]," h-2 rounded-full transition-all duration-500"),style:{width:"".concat(r,"%")}})})]},a)})})]}),(0,re.jsxs)("div",{className:"bg-white p-6 rounded-xl border border-slate-200 shadow-sm hover:shadow-md transition-shadow",children:[(0,re.jsxs)("div",{className:"flex items-center gap-3 mb-6",children:[(0,re.jsx)("div",{className:"p-2 bg-rose-100 rounded-lg",children:(0,re.jsx)(Gr.A,{className:"h-5 w-5 text-rose-600"})}),(0,re.jsxs)("div",{children:[(0,re.jsx)("h3",{className:"font-semibold text-slate-800",children:"Top Creators"}),(0,re.jsx)("p",{className:"text-xs text-slate-500",children:"Most active contributors"})]})]}),(0,re.jsxs)("div",{className:"space-y-4",children:[(0,re.jsxs)("div",{className:"text-center p-3 bg-gradient-to-br from-rose-50 to-rose-100 rounded-lg",children:[(0,re.jsx)("div",{className:"text-2xl font-bold text-rose-900",children:e.temporalStats.totalCreators}),(0,re.jsx)("div",{className:"text-xs text-rose-700 font-medium",children:"Total Creators"})]}),(0,re.jsx)("div",{className:"space-y-3",children:e.creatorStats.slice(0,5).map((e,s)=>{let[t,a]=e;return(0,re.jsxs)("div",{className:"flex items-center justify-between p-3 bg-slate-50 rounded-lg",children:[(0,re.jsxs)("div",{className:"flex items-center gap-3",children:[(0,re.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:s+1}),(0,re.jsx)("span",{className:"text-sm font-medium text-slate-700 truncate max-w-24",children:t})]}),(0,re.jsx)("div",{className:"flex items-center gap-2",children:(0,re.jsxs)("div",{className:"text-right",children:[(0,re.jsx)("div",{className:"text-sm font-bold text-slate-900",children:a}),(0,re.jsx)("div",{className:"text-xs text-slate-500",children:"apps"})]})})]},t)})})]})]}),(0,re.jsxs)("div",{className:"bg-white p-6 rounded-xl border border-slate-200 shadow-sm hover:shadow-md transition-shadow",children:[(0,re.jsxs)("div",{className:"flex items-center gap-3 mb-6",children:[(0,re.jsx)("div",{className:"p-2 bg-cyan-100 rounded-lg",children:(0,re.jsx)(im.A,{className:"h-5 w-5 text-cyan-600"})}),(0,re.jsxs)("div",{children:[(0,re.jsx)("h3",{className:"font-semibold text-slate-800",children:"Recent Activity"}),(0,re.jsx)("p",{className:"text-xs text-slate-500",children:"Growth and trends"})]})]}),(0,re.jsxs)("div",{className:"space-y-4",children:[(0,re.jsxs)("div",{className:"grid grid-cols-1 gap-3",children:[(0,re.jsxs)("div",{className:"p-4 bg-gradient-to-r from-green-50 to-emerald-50 rounded-lg border border-green-200",children:[(0,re.jsxs)("div",{className:"flex justify-between items-center",children:[(0,re.jsx)("span",{className:"text-sm font-medium text-green-700",children:"This Month"}),(0,re.jsx)("span",{className:"text-xl font-bold text-green-900",children:e.temporalStats.thisMonth})]}),(0,re.jsx)("div",{className:"text-xs text-green-600 mt-1",children:"new submissions"})]}),(0,re.jsxs)("div",{className:"p-4 bg-gradient-to-r from-blue-50 to-cyan-50 rounded-lg border border-blue-200",children:[(0,re.jsxs)("div",{className:"flex justify-between items-center",children:[(0,re.jsx)("span",{className:"text-sm font-medium text-blue-700",children:"This Quarter"}),(0,re.jsx)("span",{className:"text-xl font-bold text-blue-900",children:e.temporalStats.thisQuarter})]}),(0,re.jsx)("div",{className:"text-xs text-blue-600 mt-1",children:"total submissions"})]})]}),e.categories.length>0&&(0,re.jsxs)("div",{className:"p-4 bg-gradient-to-br from-purple-50 to-pink-50 rounded-lg border border-purple-200",children:[(0,re.jsx)("div",{className:"text-sm font-medium text-purple-700 mb-2",children:"Most Popular Category"}),(0,re.jsx)("div",{className:"text-lg font-bold text-purple-900",children:e.categories[0][0]}),(0,re.jsxs)("div",{className:"text-xs text-purple-600 mt-1",children:[e.categories[0][1]," apps in this category"]})]})]})]})]})})()]}),(0,re.jsxs)("div",{className:"mb-8 space-y-4",children:[(0,re.jsx)("div",{className:"bg-white p-4 rounded-xl border border-gray-100 shadow-sm",children:(0,re.jsxs)("div",{className:"flex flex-col lg:flex-row gap-3 items-start lg:items-center justify-between",children:[(0,re.jsxs)("div",{className:"flex flex-col sm:flex-row gap-3 items-start sm:items-center flex-1",children:[(0,re.jsxs)("div",{className:"relative w-full sm:w-80",children:[(0,re.jsx)(vn.A,{className:"absolute left-3 top-2.5 h-4 w-4 text-gray-400"}),(0,re.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,re.jsxs)(In,{value:y,onValueChange:N,children:[(0,re.jsx)(Pn,{className:"w-36 h-9 border-gray-200 hover:border-gray-300 transition-colors",children:(0,re.jsxs)("div",{className:"flex items-center gap-2",children:[(0,re.jsx)($b.A,{className:"h-3.5 w-3.5 text-gray-400"}),(0,re.jsx)(Tn,{placeholder:"Status"})]})}),(0,re.jsxs)(Rn,{children:[(0,re.jsx)(Dn,{value:"all",children:"All Status"}),(0,re.jsx)(Dn,{value:"pending",children:"Pending"}),(0,re.jsx)(Dn,{value:"approved",children:"Approved"}),(0,re.jsx)(Dn,{value:"rejected",children:"Rejected"}),(0,re.jsx)(Dn,{value:"archived",children:"Archived"})]})]}),(0,re.jsxs)(In,{value:w,onValueChange:_,children:[(0,re.jsx)(Pn,{className:"w-40 h-9 border-gray-200 hover:border-gray-300 transition-colors",children:(0,re.jsxs)("div",{className:"flex items-center gap-2",children:[(0,re.jsx)(bn.A,{className:"h-3.5 w-3.5 text-gray-400"}),(0,re.jsx)(Tn,{placeholder:"Language"})]})}),(0,re.jsx)(Rn,{children:yN.map(e=>(0,re.jsx)(Dn,{value:e.value,children:e.label},e.value))})]}),te()&&(0,re.jsxs)(Yn,{variant:"outline",size:"sm",onClick:()=>{N("all"),_("en"),A("all"),C(""),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,re.jsx)(zs.A,{className:"h-3.5 w-3.5 mr-1"}),"Clear"]})]}),(0,re.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,re.jsx)(oh.A,{className:"h-3.5 w-3.5"}),L>0?"".concat(L," total apps"):"".concat(r.length," apps")]})]})}),"custom"===k&&(0,re.jsx)("div",{className:"bg-blue-50 p-4 rounded-lg border border-blue-100",children:(0,re.jsxs)("div",{className:"flex gap-4 items-center",children:[(0,re.jsxs)("div",{className:"flex items-center gap-2",children:[(0,re.jsx)("label",{className:"text-sm font-medium text-gray-700",children:"From:"}),(0,re.jsx)(fn,{type:"date",value:S,onChange:e=>C(e.target.value),className:"w-40 h-8 border-gray-200 focus:border-blue-500 focus:ring-blue-500/20"})]}),(0,re.jsxs)("div",{className:"flex items-center gap-2",children:[(0,re.jsx)("label",{className:"text-sm font-medium text-gray-700",children:"To:"}),(0,re.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"})]})]})}),te()&&(0,re.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,re.jsxs)("span",{className:"text-sm font-medium text-gray-700 flex items-center gap-1",children:[(0,re.jsx)(Sg.A,{className:"h-3.5 w-3.5"}),"Active filters:"]}),"all"!==y&&(0,re.jsxs)(Nn,{className:"bg-blue-100 text-blue-800 hover:bg-blue-200 transition-colors",children:["Status: ",y,(0,re.jsx)("button",{onClick:()=>N("all"),className:"ml-1 hover:bg-blue-300 rounded-full p-0.5 transition-colors",children:(0,re.jsx)(zs.A,{className:"h-3 w-3"})})]}),"en"!==w&&(0,re.jsxs)(Nn,{className:"bg-teal-100 text-teal-800 hover:bg-teal-200 transition-colors",children:["Language: ",ae(w),(0,re.jsx)("button",{onClick:()=>_("en"),className:"ml-1 hover:bg-teal-300 rounded-full p-0.5 transition-colors",children:(0,re.jsx)(zs.A,{className:"h-3 w-3"})})]}),"all"!==k&&(0,re.jsxs)(Nn,{className:"bg-purple-100 text-purple-800 hover:bg-purple-200 transition-colors",children:["Date: ","custom"===k?"Custom":k,(0,re.jsx)("button",{onClick:()=>A("all"),className:"ml-1 hover:bg-purple-300 rounded-full p-0.5 transition-colors",children:(0,re.jsx)(zs.A,{className:"h-3 w-3"})})]}),c&&(0,re.jsxs)(Nn,{className:"bg-green-100 text-green-800 hover:bg-green-200 transition-colors",children:['Search: "',c,'"',(0,re.jsx)("button",{onClick:()=>d(""),className:"ml-1 hover:bg-green-300 rounded-full p-0.5 transition-colors",children:(0,re.jsx)(zs.A,{className:"h-3 w-3"})})]})]})]}),(0,re.jsx)("div",{className:"bg-white rounded-xl border border-gray-200 shadow-sm overflow-hidden",children:(0,re.jsxs)(pN,{children:[(0,re.jsx)(gN,{children:(0,re.jsxs)(vN,{children:[(0,re.jsx)(bN,{className:"w-8"}),(0,re.jsx)(bN,{className:"cursor-pointer",onClick:()=>se("name"),children:(0,re.jsxs)("div",{className:"flex items-center",children:["App Name",(0,re.jsx)(Xf.A,{className:"ml-2 h-4 w-4"})]})}),(0,re.jsx)(bN,{className:"cursor-pointer w-24",onClick:()=>se("item_creator"),children:(0,re.jsxs)("div",{className:"flex items-center",children:["Creator",(0,re.jsx)(Xf.A,{className:"ml-2 h-4 w-4"})]})}),(0,re.jsx)(bN,{className:"cursor-pointer",onClick:()=>se("status"),children:(0,re.jsxs)("div",{className:"flex items-center",children:["Status",(0,re.jsx)(Xf.A,{className:"ml-2 h-4 w-4"})]})}),(0,re.jsx)(bN,{className:"cursor-pointer w-40",onClick:()=>se("created_date"),children:(0,re.jsxs)("div",{className:"flex items-center",children:["Created Date",(0,re.jsx)(Xf.A,{className:"ml-2 h-4 w-4"})]})}),(0,re.jsx)(bN,{className:"cursor-pointer",onClick:()=>se("usage"),children:(0,re.jsxs)("div",{className:"flex items-center",children:["#Clones",(0,re.jsx)(Xf.A,{className:"ml-2 h-4 w-4"})]})}),(0,re.jsx)(bN,{className:"cursor-pointer",onClick:()=>se("is_private"),children:(0,re.jsxs)("div",{className:"flex items-center",children:["Privacy",(0,re.jsx)(Xf.A,{className:"ml-2 h-4 w-4"})]})}),(0,re.jsx)(bN,{className:"cursor-pointer",onClick:()=>se("language"),children:(0,re.jsxs)("div",{className:"flex items-center",children:["Language",(0,re.jsx)(Xf.A,{className:"ml-2 h-4 w-4"})]})}),(0,re.jsx)(bN,{children:"Actions"})]})}),(0,re.jsx)(fN,{children:i?(0,re.jsx)(vN,{children:(0,re.jsx)(jN,{colSpan:9,className:"text-center py-8",children:"Loading apps..."})}):0===r.length?(0,re.jsx)(vN,{children:(0,re.jsx)(jN,{colSpan:9,className:"text-center py-8",children:"No apps found"})}):r.map(e=>{var s,t;return(0,re.jsxs)(re.Fragment,{children:[(0,re.jsxs)(vN,{className:"hover:bg-gray-50/80 transition-colors duration-200 group h-12",children:[(0,re.jsx)(jN,{className:"py-2",children:(0,re.jsx)(Yn,{variant:"ghost",size:"sm",onClick:()=>{return s=e.item.id,void j(e=>{const t=new Set(e);return t.has(s)?t.delete(s):t.add(s),t});var s},className:"h-6 w-6 p-0 rounded hover:bg-gray-100 transition-all duration-200 group",children:b.has(e.item.id)?(0,re.jsx)(It.A,{className:"h-3 w-3 text-gray-600 group-hover:text-gray-900 transition-colors"}):(0,re.jsx)(ln.A,{className:"h-3 w-3 text-gray-600 group-hover:text-gray-900 transition-colors"})})}),(0,re.jsx)(jN,{className:"font-medium py-2 text-sm",children:e.item.name}),(0,re.jsx)(jN,{className:"py-2 text-xs w-24 truncate",children:e.item_creator.full_name}),(0,re.jsx)(jN,{className:"py-2",children:ne(e.item.status)}),(0,re.jsx)(jN,{className:"py-2 w-40",children:la().utc(e.item.created_date).fromNow()}),(0,re.jsx)(jN,{className:"py-2",children:(0,re.jsxs)("div",{className:"flex items-center gap-1 text-sm",children:[(0,re.jsx)(Kr.A,{className:"h-3 w-3 text-gray-500"}),e.usage||0]})}),(0,re.jsx)(jN,{className:"py-2",children:(0,re.jsx)("div",{className:"flex items-center gap-1",children:e.item.is_private?(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(Fs.A,{className:"h-3 w-3 text-gray-500"}),(0,re.jsx)("span",{className:"text-xs text-gray-600",children:"Private"})]}):(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(bn.A,{className:"h-3 w-3 text-green-500"}),(0,re.jsx)("span",{className:"text-xs text-green-600",children:"Public"})]})})}),(0,re.jsx)(jN,{className:"py-2",children:(0,re.jsx)("span",{className:"text-xs text-gray-700",children:ae(e.item.language||"en")})}),(0,re.jsx)(jN,{className:"py-2",children:(0,re.jsxs)("div",{className:"flex gap-1",children:[(0,re.jsx)(Yn,{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:s=>{s.stopPropagation(),Q("approve",e)},disabled:p[e.item.id],title:"Approve",children:(0,re.jsx)(Pt.A,{className:"h-3.5 w-3.5 group-hover:scale-110 transition-transform"})}),(0,re.jsx)(Yn,{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:s=>{s.stopPropagation(),Q("decline",e)},disabled:p[e.item.id],title:"Decline",children:(0,re.jsx)(zs.A,{className:"h-3.5 w-3.5 group-hover:scale-110 transition-transform"})}),(0,re.jsx)(Yn,{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:s=>{s.stopPropagation(),Q("archive",e)},disabled:p[e.item.id],title:"Archive",children:(0,re.jsx)(Wb.A,{className:"h-3.5 w-3.5 group-hover:scale-110 transition-transform"})}),(0,re.jsx)(Yn,{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:s=>{s.stopPropagation(),(async e=>{v(s=>(0,K.A)((0,K.A)({},s),{},{[e]:!0}));try{const s=await ve.getLoginInfoById(e),t="https://".concat(s.slug,".base44.app");window.open(t,"_blank")}catch(s){an({title:"Error",description:"Failed to open app",variant:"destructive"})}finally{v(s=>(0,K.A)((0,K.A)({},s),{},{[e]:!1}))}})(e.item.app_id)},disabled:f[e.item.app_id],title:"Open New Tab",children:(0,re.jsx)(jl.A,{className:"h-3.5 w-3.5 group-hover:scale-110 transition-transform"})})]})})]},e.item.id),b.has(e.item.id)&&(0,re.jsx)(vN,{children:(0,re.jsx)(jN,{colSpan:9,className:"bg-gradient-to-br from-gray-50 to-gray-100/50 p-8 border-t border-gray-100",children:(0,re.jsxs)("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-8",children:[(0,re.jsxs)("div",{className:"space-y-6",children:[(0,re.jsxs)("div",{className:"bg-white p-4 rounded-lg border border-gray-200",children:[(0,re.jsxs)("h4",{className:"font-semibold text-gray-900 mb-3 flex items-center gap-2",children:[(0,re.jsx)("div",{className:"w-1 h-5 bg-blue-500 rounded-full"}),"Description"]}),(0,re.jsx)("div",{className:"text-sm text-gray-600 prose prose-sm max-w-none",dangerouslySetInnerHTML:{__html:dn(e.item.description||'

No description available

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

No description available

')}})]}),(0,re.jsxs)("div",{className:"bg-white p-4 rounded-lg border border-gray-200 shadow-sm",children:[(0,re.jsxs)("h4",{className:"font-semibold text-gray-900 mb-3 flex items-center gap-2",children:[(0,re.jsx)("div",{className:"w-1 h-4 bg-orange-500 rounded-full"}),"Technical Details"]}),(0,re.jsxs)("div",{className:"space-y-2 text-sm",children:[(0,re.jsxs)("div",{className:"flex justify-between items-center py-1",children:[(0,re.jsx)("span",{className:"text-gray-600",children:"Integration ID:"}),(0,re.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,re.jsxs)("div",{className:"flex justify-between items-center py-1",children:[(0,re.jsx)("span",{className:"text-gray-600",children:"Organization:"}),(0,re.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,re.jsxs)("div",{className:"flex justify-between items-center py-1",children:[(0,re.jsx)("span",{className:"text-gray-600",children:"Created:"}),(0,re.jsx)("span",{className:"text-gray-900 font-medium",children:la().utc(e.item.created_date).format("MMM DD, YYYY")})]}),(0,re.jsxs)("div",{className:"flex justify-between items-center py-1",children:[(0,re.jsx)("span",{className:"text-gray-600",children:"Updated:"}),(0,re.jsx)("span",{className:"text-gray-900 font-medium",children:la().utc(e.item.updated_date).format("MMM DD, YYYY")})]})]})]}),(null===(a=e.item.categories)||void 0===a?void 0:a.length)>0&&(0,re.jsxs)("div",{className:"bg-white p-4 rounded-lg border border-gray-200",children:[(0,re.jsxs)("h4",{className:"font-semibold text-gray-900 mb-3 flex items-center gap-2",children:[(0,re.jsx)("div",{className:"w-1 h-5 bg-purple-500 rounded-full"}),"Categories"]}),(0,re.jsx)("div",{className:"flex flex-wrap gap-2",children:e.item.categories.map((e,s)=>(0,re.jsx)(Nn,{className:"bg-purple-50 text-purple-700 border-purple-200 hover:bg-purple-100 transition-colors",children:e},s))})]})]}),(0,re.jsxs)("div",{className:"bg-white p-4 rounded-lg border border-gray-200 h-fit",children:[(0,re.jsxs)("h4",{className:"font-semibold text-gray-900 mb-3 flex items-center gap-2",children:[(0,re.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,re.jsxs)("div",{className:"grid grid-cols-1 gap-4",children:[e.item.screenshot_urls.slice(0,3).map((e,s)=>(0,re.jsxs)("div",{className:"relative rounded-lg overflow-hidden border border-gray-200 group",children:[(0,re.jsx)("img",{src:e,alt:"Screenshot ".concat(s+1),className:"w-full h-36 object-cover group-hover:scale-105 transition-all duration-300 cursor-pointer",onClick:()=>window.open(e,"_blank")}),(0,re.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,re.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,re.jsx)(oh.A,{className:"h-4 w-4 text-gray-700"})})})]},s)),e.item.screenshot_urls.length>3&&(0,re.jsx)("div",{className:"text-center py-2 bg-gray-50 rounded-lg border border-gray-200",children:(0,re.jsxs)("p",{className:"text-sm text-gray-600 font-medium",children:["+",e.item.screenshot_urls.length-3," more screenshots"]})})]}):(0,re.jsxs)("div",{className:"text-center py-8 text-gray-400 bg-gray-50 rounded-lg border-2 border-dashed border-gray-200",children:[(0,re.jsx)(oh.A,{className:"h-8 w-8 mx-auto mb-2 opacity-50"}),(0,re.jsx)("p",{className:"text-sm",children:"No screenshots available"})]})]})]})})})]})})})]})}),(0,re.jsxs)("div",{className:"mt-6 flex flex-col sm:flex-row items-center justify-between gap-4",children:[(0,re.jsxs)("div",{className:"flex items-center gap-4 text-sm text-gray-600",children:[(0,re.jsxs)("div",{className:"flex items-center gap-2",children:[(0,re.jsx)("span",{children:"Showing"}),(0,re.jsxs)("span",{className:"font-semibold text-gray-900",children:[Math.min((b-1)*y+1,w),"-",Math.min(b*y,w)]}),(0,re.jsx)("span",{children:"of"}),(0,re.jsx)("span",{className:"font-semibold text-gray-900",children:w}),(0,re.jsx)("span",{children:"integrations"})]}),(0,re.jsxs)(In,{value:y.toString(),onValueChange:e=>{return s=parseInt(e),N(s),void j(1);var s},children:[(0,re.jsx)(Pn,{className:"w-24 h-8 text-sm",children:(0,re.jsx)(Tn,{})}),(0,re.jsxs)(Rn,{children:[(0,re.jsx)(Dn,{value:"10",children:"10"}),(0,re.jsx)(Dn,{value:"20",children:"20"}),(0,re.jsx)(Dn,{value:"50",children:"50"}),(0,re.jsx)(Dn,{value:"100",children:"100"})]})]}),(0,re.jsx)("span",{className:"text-gray-500",children:"per page"})]}),(0,re.jsx)(wN,{currentPage:b,totalPages:k,onPageChange:e=>{j(e)}})]}),(0,re.jsx)(to,{open:R.isOpen,onOpenChange:z,children:(0,re.jsxs)(lo,{children:[(0,re.jsxs)(io,{children:[(0,re.jsxs)(co,{children:["approve"===R.action&&"Approve Integration","decline"===R.action&&"Decline Integration","archive"===R.action&&"Archive Integration"]}),(0,re.jsxs)(mo,{children:["approve"===R.action&&(0,re.jsxs)(re.Fragment,{children:["Are you sure you want to approve ",(0,re.jsx)("strong",{children:null===(s=R.item)||void 0===s?void 0:s.item.name}),"?",(0,re.jsx)("br",{}),"This will make the integration publicly visible in the catalog."]}),"decline"===R.action&&(0,re.jsxs)(re.Fragment,{children:["Are you sure you want to decline ",(0,re.jsx)("strong",{children:null===(t=R.item)||void 0===t?void 0:t.item.name}),"?",(0,re.jsx)("br",{}),"This will remove the integration from public visibility in the catalog.",(0,re.jsxs)("div",{className:"mt-4",children:[(0,re.jsx)("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:"Reason for decline (optional):"}),(0,re.jsx)("textarea",{placeholder:"Enter reason for declining this integration...",value:M,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,re.jsxs)(re.Fragment,{children:["Are you sure you want to archive ",(0,re.jsx)("strong",{children:null===(a=R.item)||void 0===a?void 0:a.item.name}),"?",(0,re.jsx)("br",{}),"This will permanently remove the integration from the catalog."]})]})]}),(0,re.jsxs)(oo,{children:[(0,re.jsx)(Yn,{variant:"outline",onClick:z,children:"Cancel"}),(0,re.jsxs)(Yn,{onClick:async()=>{if(!R.action||!R.item)return;const{action:e,item:s}=R,t=s.item.id;g(e=>(0,K.A)((0,K.A)({},e),{},{[t]:!0})),z();try{switch(e){case"approve":await Ks.approveItem(t);break;case"decline":await Ks.declineItem(t,M||void 0);break;case"archive":await Ks.archiveItem(t)}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),{},{[t]:!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,re.jsx)("div",{className:"flex items-center justify-center h-screen",children:(0,re.jsxs)("div",{className:"text-center",children:[(0,re.jsx)(Kf.A,{className:"w-16 h-16 text-red-500 mx-auto mb-4"}),(0,re.jsx)("h2",{className:"text-2xl font-bold text-gray-800",children:"Access Denied"}),(0,re.jsx)("p",{className:"text-gray-600",children:"You are not authorized to access this page"})]})})}const kN=["steps","currentStep","title","description","children","onNext","onPrevious","onClose","onSubmit","isNextDisabled","isLoading","nextButtonText","submitButtonText","previousButtonText","hideCloseButton","className","banner","footerLeftContent"];function AN(e){let{steps:s,currentStep:t,title:a,description:n,children:r,onNext:l,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,as.A)(e,kN);const j=0===t,y=t===s.length-1,N=(t+1)/s.length*100;return(0,re.jsxs)("div",(0,K.A)((0,K.A)({"data-testid":"stepped-wizard",className:is("bg-theme-card bg-white rounded-[20px] shadow-lg inline-flex flex-col justify-start items-start overflow-hidden",g)},b),{},{children:[(0,re.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,re.jsx)("div",{className:"h-2 bg-slate-200 transition-all duration-300 ease-in-out",style:{width:"".concat(100-N,"%")}})}),(0,re.jsxs)("div",{className:"self-stretch px-6 pt-4 pb-3 border-b border-theme-border inline-flex justify-between items-start",children:[(0,re.jsxs)("div",{className:"w-full inline-flex flex-col justify-start items-start gap-1.5",children:[(0,re.jsx)("div",{"data-testid":"wizard-title",className:"justify-start text-2xl font-semibold font-base44",children:a}),n&&(0,re.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,re.jsx)("div",{className:"w-36 flex justify-end items-center gap-3",children:(0,re.jsx)("button",{"data-testid":"wizard-close-button",onClick:o,className:"flex justify-start items-start","aria-label":"Close",children:(0,re.jsx)("div",{className:"w-6 h-6 relative",children:(0,re.jsx)("div",{className:"w-5 h-5 absolute",children:(0,re.jsx)(zs.A,{className:"w-5 h-5"})})})})})]}),(0,re.jsx)("div",{className:"flex-1 self-stretch overflow-y-auto",children:r}),(0,re.jsx)("div",{className:"self-stretch px-6 py-4 border-t border-gray-200",children:(0,re.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,re.jsx)("div",{className:"flex justify-start items-center order-1 min-[470px]:order-1",children:v}),(0,re.jsxs)("div",{className:"flex justify-end items-center gap-6 order-2 min-[470px]:order-2",children:[(0,re.jsxs)("div",{"data-testid":"step-indicator",className:"justify-center text-gray-500 text-sm font-normal font-base44 leading-tight",children:["Step ",t+1," of ",s.length]}),(0,re.jsxs)("div",{className:"flex justify-start items-center gap-3",children:[!j&&i&&(0,re.jsx)(Yn,{"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,re.jsx)(Qt.A,{className:"w-4 h-4"})}),(y?c:l)&&(0,re.jsxs)(Yn,{"data-testid":y?"wizard-submit-button":"wizard-next-button",onClick:y?c:l,variant:"default",disabled:d||m,className:"h-9 rounded-lg min-w-24",children:[(0,re.jsx)("span",{className:"text-center justify-center text-sm font-medium font-base44 leading-tight",children:m?"Loading...":y?x:u}),!m&&!y&&(0,re.jsx)(ln.A,{className:"w-4 h-4 "})]})]})]})]})}),f&&f]}))}function SN(e){let{label:s,placeholder:t,value:a,onChange:n,error:r,type:l="text",icon:i,className:o="",required:c=!1,helperText:d,rows:m=4,tooltipText:u}=e;const x="".concat("textarea"===l?"h-20":"h-10"," ").concat(r?"border-red-500":"border-slate-200"," ").concat(o),h=e=>{n(e.target.value)};return(0,re.jsxs)("div",{className:s?"space-y-1":"",children:[s&&(0,re.jsxs)("div",{className:"flex items-center gap-1",children:[(0,re.jsxs)(uu,{className:"text-center justify-center text-gray-700 text-sm font-medium font-base44 leading-tight",children:[s,c&&(0,re.jsx)("span",{className:"text-red-500 ml-1",children:"*"})]}),u&&(0,re.jsxs)(Rg,{delayDuration:100,children:[(0,re.jsx)(Dg,{asChild:!0,children:(0,re.jsx)(jo.A,{className:"h-4 w-4 text-gray-600 hover:text-gray-900"})}),(0,re.jsx)(Mg,{className:"max-w-[240px] p-3 text-xs",children:(0,re.jsx)("p",{children:u})})]})]}),"textarea"===l?(0,re.jsx)(du,{placeholder:t,value:a,onChange:h,rows:m,className:x}):(0,re.jsx)(fn,{type:l,placeholder:t,value:a,onChange:h,className:x}),r&&(0,re.jsx)("p",{className:"text-sm text-red-500 mt-2",children:r}),d&&!r&&(0,re.jsx)("p",{className:"text-xs text-slate-400 mt-2",children:d})]})}var CN=t(88434),EN=t(56003);const IN=["Application Development","UI/UX Design","Security Expert","Strategic Consulting","Mobile Development","AI Expert","API & Integrations","QA & Testing","Other"],TN=[{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"}],PN=[{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"}],LN=e=>{const s=PN.find(s=>s.value===e);return s?s.label:e},ON=CN.Yj().url("Please enter a valid URL"),RN=CN.Ik({url:CN.Yj(),allow_public_showcase:CN.zM().default(!0)}),DN=CN.Yj().url("Please enter a valid URL").refine(e=>e.toLowerCase().includes("linkedin.com"),"Please enter a valid LinkedIn URL"),MN=CN.Yj().optional().refine(e=>!e||""===e.trim()||!isNaN(Number(e))&&Number(e)>=0,"Please enter a valid number"),FN=(e,s)=>{const t=e.website_url&&""!==e.website_url.trim(),a=e.linkedin_url&&""!==e.linkedin_url.trim();if(t||a||(s.addIssue({code:EN.eq.custom,message:"Please provide either a website or LinkedIn URL",path:["website_url"]}),s.addIssue({code:EN.eq.custom,message:"Please provide either a website or LinkedIn URL",path:["linkedin_url"]})),t){ON.safeParse(e.website_url).success||s.addIssue({code:EN.eq.custom,message:"Please enter a valid URL",path:["website_url"]})}if(a){const t=DN.safeParse(e.linkedin_url);var n;if(!t.success)s.addIssue({code:EN.eq.custom,message:(null===(n=t.error.errors[0])||void 0===n?void 0:n.message)||"Please enter a valid LinkedIn URL",path:["linkedin_url"]})}},BN=(e,s)=>{const t=e.budget_starting_from_dollars&&""!==e.budget_starting_from_dollars.trim(),a=e.hourly_rate&&""!==e.hourly_rate.trim();t||a||s.addIssue({code:EN.eq.custom,message:"Please provide at least one pricing option",path:["pricing"]})},UN=(e,s)=>{var t;null===(t=e.services)||void 0===t||!t.includes("Other")||e.other_service_description&&""!==e.other_service_description.trim()||s.addIssue({code:EN.eq.custom,message:"Please describe your other service",path:["other_service_description"]})},zN=(e,s)=>{if(e.has_apps_to_share){0===(e.apps||[]).filter(e=>e.url&&e.url.trim()).length&&s.addIssue({code:EN.eq.custom,message:"Please provide at least one app URL",path:["apps"]}),e.apps&&e.apps.length>0&&e.apps.forEach((e,t)=>{e.url&&e.url.trim()&&(CN.Yj().url().safeParse(e.url).success||s.addIssue({code:EN.eq.custom,message:"App ".concat(t+1," must be a valid URL"),path:["apps"]}))})}else(!e.no_apps_explanation||e.no_apps_explanation.trim().length<20)&&s.addIssue({code:EN.eq.custom,message:"Please provide an explanation of at least 20 characters",path:["no_apps_explanation"]})},qN=CN.Ik({name:CN.Yj().min(1,"Company/Personal name is required").max(100,"Name must be less than 100 characters"),description:CN.Yj().min(20,"Please provide at least 20 characters").max(500,"Description must be less than 500 characters"),logo_url:CN.Yj().optional(),country:CN.Yj().min(1,"Country is required"),city:CN.Yj().min(1,"City is required").max(50,"City name must be less than 50 characters"),individual_or_team:CN.k5(["individual","team"],{required_error:"Please select team size"}),website_url:CN.Yj().optional(),linkedin_url:CN.Yj().optional(),languages:CN.YO(CN.Yj()).min(1,"Please select at least one language"),budget_starting_from_dollars:MN,hourly_rate:MN,services:CN.YO(CN.Yj()).min(1,"Please select at least one service"),other_service_description:CN.Yj().max(30,"Service description must be 30 characters or less").optional(),apps:CN.YO(RN).max(5,"Maximum 5 apps allowed").default([]),has_apps_to_share:CN.zM().default(!0),no_apps_explanation:CN.Yj().max(500,"Explanation must be less than 500 characters").optional(),terms_accepted:CN.zM().refine(e=>!0===e,"You must agree to the terms of use to continue")}),WN=qN.superRefine((e,s)=>{FN(e,s),BN(e,s),UN(e,s),zN(e,s)}),VN=qN.pick({name:!0,description:!0,country:!0,city:!0}).extend({logo:CN.zM().refine(e=>!0===e,"Logo upload is required")}),YN=qN.pick({individual_or_team:!0,website_url:!0,linkedin_url:!0,languages:!0,budget_starting_from_dollars:!0,hourly_rate:!0}).superRefine((e,s)=>{FN(e,s),BN(e,s)}),HN=qN.pick({services:!0,other_service_description:!0}).superRefine((e,s)=>{UN(e,s)}),GN=qN.pick({apps:!0,has_apps_to_share:!0,no_apps_explanation:!0}).superRefine((e,s)=>{zN(e,s)}),$N=e=>{const s={};return e.errors.forEach(e=>{const t=e.path.join(".");t&&(s[t]=e.message)}),s},JN=e=>{let{value:s,onValueChange:t,placeholder:a="Select a country",error:n,required:r=!1,disabled:l=!1,className:i=""}=e;PN.find(e=>e.value===s);const o="w-full h-10 ".concat(n?"border-red-500":"border-slate-200"," ").concat(i);return(0,re.jsxs)("div",{className:"w-full",children:[(0,re.jsxs)(In,{value:s,onValueChange:t,disabled:l,children:[(0,re.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:s?"#000000":"#94a3b8"},children:(0,re.jsx)(Tn,{placeholder:a,className:"text-sm font-normal font-base44 leading-tight"})}),(0,re.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:PN.map(e=>(0,re.jsx)(Dn,{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,re.jsx)("div",{className:"flex-1 justify-start text-sm font-normal font-base44 leading-tight",children:e.label})},e.value))})]}),n&&(0,re.jsx)("p",{className:"text-sm text-red-500 mt-2",children:n})]})};function ZN(e){let{label:s,placeholder:t,value:a,onChange:n,error:r,className:l="",required:i=!1,helperText:o,tooltipText:c,disabled:d=!1}=e;return(0,re.jsxs)("div",{className:"w-full space-y-1",children:[s&&(0,re.jsxs)("div",{className:"flex items-center gap-1",children:[(0,re.jsxs)(uu,{className:"text-center justify-center text-gray-700 text-sm font-medium font-base44 leading-tight",children:[s,i&&(0,re.jsx)("span",{className:"text-red-500 ml-1",children:"*"})]}),c&&(0,re.jsxs)(Rg,{delayDuration:100,children:[(0,re.jsx)(Dg,{asChild:!0,children:(0,re.jsx)(jo.A,{className:"h-4 w-4 text-gray-600 hover:text-gray-900"})}),(0,re.jsx)(Mg,{className:"max-w-[240px] p-3 text-xs",children:(0,re.jsx)("p",{children:c})})]})]}),(0,re.jsx)(JN,{value:a,onValueChange:n,placeholder:t,error:r,disabled:d,className:l}),r&&(0,re.jsx)("p",{className:"text-sm text-red-500 mt-2",children:r}),o&&!r&&(0,re.jsx)("p",{className:"text-xs text-slate-400 mt-2",children:o})]})}const KN=e=>{let{formData:s,errors:t,logoPreview:a,onInputChange:n,onLogoUpload:r,onLogoRemove:l}=e;return(0,re.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,re.jsxs)("div",{className:"w-full flex flex-col justify-start items-start",children:[(0,re.jsx)("div",{className:"w-full inline-flex justify-start items-start",children:(0,re.jsx)("div",{className:"flex-1 flex justify-start items-start",children:(0,re.jsx)("div",{className:"flex-1 self-stretch inline-flex flex-col justify-start items-start gap-2",children:(0,re.jsxs)("div",{className:"inline-flex justify-start items-start gap-4",children:[(0,re.jsx)("div",{className:"w-20 h-20 rounded-2xl overflow-hidden bg-gray-100 flex items-center justify-center",children:a?(0,re.jsx)("img",{src:a,alt:"Logo preview",className:"w-20 h-20 rounded-2xl object-cover"}):(0,re.jsx)("div",{className:"w-20 h-20 bg-gray-200 rounded-2xl flex items-center justify-center",children:(0,re.jsx)(hm.A,{"data-testid":"placeholder-upload-icon",className:"h-8 w-8 text-gray-400"})})}),(0,re.jsxs)("div",{className:"inline-flex flex-col justify-start items-start gap-3",children:[(0,re.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,re.jsx)("span",{className:"text-red-500 ml-1",children:"*"})]}),(0,re.jsxs)("div",{className:"self-stretch flex flex-col justify-start items-start gap-1.5",children:[(0,re.jsxs)("div",{className:"inline-flex justify-start items-start gap-3",children:[(0,re.jsx)("input",{"data-testid":"logo-upload-input",type:"file",id:"logo-upload-basic",className:"hidden",accept:"image/*",onChange:r}),(0,re.jsx)(Yn,{variant:"secondary",size:"sm",asChild:!0,className:"h-7 px-3",children:(0,re.jsxs)("label",{"data-testid":"upload-button",htmlFor:"logo-upload-basic",className:"cursor-pointer gap-1.5",children:[(0,re.jsx)(hm.A,{"data-testid":"upload-icon",className:"w-4 h-4"}),"Upload logo"]})}),a&&(0,re.jsx)(Yn,{"data-testid":"remove-logo-button",variant:"outline",size:"sm",onClick:l,className:"h-7 px-3",children:"Remove"})]}),(0,re.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"})]})]})]})})})}),t.logo&&(0,re.jsx)("p",{"data-testid":"logo-error",className:"text-sm text-red-500 mt-2",children:t.logo})]}),(0,re.jsx)("div",{"data-testid":"name-field-container",className:"w-full",children:(0,re.jsx)(SN,{"data-testid":"name-input",label:"Display name (you or your company)",placeholder:"Enter your name or company name",value:s.name,onChange:e=>n("name",e),error:t.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,re.jsx)("div",{"data-testid":"description-field-container",className:"w-full",children:(0,re.jsx)(SN,{"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:s.description,onChange:e=>n("description",e),error:t.description,type:"textarea",helperText:"".concat(s.description.length," characters (minimum 20)"),required:!0,className:"w-full"})}),(0,re.jsxs)("div",{"data-testid":"location-fields-container",className:"w-full grid grid-cols-1 sm:grid-cols-2 gap-3",children:[(0,re.jsx)(ZN,{"data-testid":"country-select",label:"Country",placeholder:"Select your country",value:s.country,onChange:e=>n("country",e),error:t.country,required:!0,className:"w-full",tooltipText:"Providing your location ensures smoother collaboration with people in different places"}),(0,re.jsx)(SN,{"data-testid":"city-input",label:"City",placeholder:"e.g., San Francisco",value:s.city,onChange:e=>n("city",e),error:t.city,required:!0,className:"w-full",tooltipText:"Providing your location ensures smoother collaboration with people in different places"})]})]})},XN=e=>{let{label:s,value:t,onValueChange:a,options:n,className:r="",error:l}=e;return(0,re.jsxs)("div",{className:"w-full flex flex-col justify-start items-start gap-1 ".concat(r),children:[(0,re.jsx)(uu,{className:"text-gray-700 text-sm font-medium font-base44 leading-tight",children:s}),(0,re.jsx)(Ro,{value:t,onValueChange:a,className:"w-full grid grid-cols-1 sm:grid-cols-2 gap-3",children:n.map(e=>(0,re.jsxs)(uu,{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,re.jsx)(Do,{id:"radio-".concat(e.value),value:e.value,className:"w-4 h-4"}),(0,re.jsx)("span",{className:"text-black text-sm font-medium font-base44 leading-tight",children:e.label})]},e.value))}),l&&(0,re.jsx)("p",{className:"text-sm text-red-500 mt-1",children:l})]})},QN=e=>{let{formData:s,errors:t,onInputChange:a,onLanguageToggle:n}=e;return(0,re.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,re.jsx)(XN,{label:"Your team size",value:s.individual_or_team,onValueChange:e=>a("individual_or_team",e),options:[{value:"individual",label:"Individual"},{value:"team",label:"Team/Agency"}],error:t.individual_or_team}),(0,re.jsxs)("div",{className:"w-full flex flex-col justify-start items-start gap-3",children:[(0,re.jsxs)("div",{className:"w-full grid grid-cols-1 sm:grid-cols-2 gap-3",children:[(0,re.jsxs)("div",{className:"flex flex-col justify-start items-start gap-1",children:[(0,re.jsx)(uu,{className:"text-gray-700 text-sm font-medium font-base44 leading-tight",children:"Starting budget (USD)"}),(0,re.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,re.jsx)("span",{className:"text-slate-500 text-sm font-normal font-base44 leading-tight",children:"$"}),(0,re.jsx)("input",{type:"number",min:"0",placeholder:"e.g, 5000",value:s.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"})]}),t.budget_starting_from_dollars&&(0,re.jsx)("p",{className:"text-sm text-red-500 mt-1",children:t.budget_starting_from_dollars})]}),(0,re.jsxs)("div",{className:"flex flex-col justify-start items-start gap-1",children:[(0,re.jsx)(uu,{className:"text-gray-700 text-sm font-medium font-base44 leading-tight",children:"Hourly rate (USD)"}),(0,re.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,re.jsx)("span",{className:"text-slate-500 text-sm font-normal font-base44 leading-tight",children:"$"}),(0,re.jsx)("input",{type:"number",min:"0",placeholder:"e.g, 150",value:s.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"})]}),t.hourly_rate&&(0,re.jsx)("p",{className:"text-sm text-red-500 mt-1",children:t.hourly_rate})]})]}),t.pricing&&(0,re.jsx)("p",{className:"text-sm text-red-500 mt-1",children:t.pricing})]}),(0,re.jsxs)("div",{className:"w-full flex flex-col justify-start items-start gap-2",children:[(0,re.jsxs)("div",{className:"w-full grid grid-cols-1 sm:grid-cols-2 gap-3",children:[(0,re.jsx)(SN,{label:"Add Website link",placeholder:"Paste website URL",value:s.website_url,onChange:e=>a("website_url",e),error:t.website_url,type:"url",className:"w-full"}),(0,re.jsx)(SN,{label:"LinkedIn link",placeholder:"Paste LinkedIn URL",value:s.linkedin_url,onChange:e=>a("linkedin_url",e),error:t.linkedin_url,type:"url",className:"w-full"})]}),(0,re.jsx)("div",{className:"w-full flex flex-col justify-start items-start",children:(0,re.jsx)("p",{className:"text-slate-500 text-sm font-normal font-base44 leading-tight",children:"At least one link is required."})})]}),(0,re.jsxs)("div",{className:"w-full flex flex-col justify-start items-start gap-1",children:[(0,re.jsx)(uu,{className:"text-gray-700 text-sm font-medium font-base44 leading-tight",children:"What is your preferred working language?"}),(0,re.jsx)("div",{className:"w-full h-40 bg-white rounded-lg border border-slate-200 overflow-hidden",children:(0,re.jsx)("div",{className:"h-full overflow-y-auto pl-3 pr-1.5 py-3",children:(0,re.jsx)("div",{className:"grid grid-cols-2 gap-x-3 gap-y-1.5",children:TN.map(e=>(0,re.jsxs)("div",{className:"inline-flex justify-start items-center gap-2",children:[(0,re.jsx)(Yu,{id:"lang-".concat(e.value),checked:s.languages.includes(e.value),onCheckedChange:()=>n(e.value),className:"w-4 h-4"}),(0,re.jsx)(uu,{htmlFor:"lang-".concat(e.value),className:"text-gray-700 text-sm font-normal font-base44 leading-tight cursor-pointer",children:e.label})]},e.value))})})}),t.languages&&(0,re.jsx)("p",{className:"text-sm text-red-500 mt-1",children:t.languages})]})]})},ew=e=>{let{options:s,selectedOptions:t,onToggle:a,getOptionLabel:n=e=>String(e),getOptionKey:r=e=>String(e),className:l,buttonClassName:i,multiple:o=!0,disabled:c=!1}=e;return(0,re.jsx)("div",{className:is("w-full inline-flex justify-start items-start gap-3 flex-wrap content-start",l),children:s.map(e=>{const s=(e=>t.some(s=>r(s)===r(e)))(e);return(0,re.jsx)("button",{type:"button",onClick:()=>(e=>{c||a(e)})(e),disabled:c,className:is("p-3 rounded-lg outline outline-1 outline-offset-[-1px] flex justify-center items-center gap-3 transition-all duration-200",s?"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&&s&&"hover:bg-gray-800 hover:outline-gray-800",i),children:(0,re.jsx)("div",{className:"inline-flex flex-col justify-center items-start gap-0.5",children:(0,re.jsx)("div",{className:"inline-flex justify-start items-center gap-2",children:(0,re.jsx)("span",{className:"text-sm font-normal font-base44 leading-tight",children:n(e)})})})},r(e))})})},sw=e=>{var s,t;let{formData:a,errors:n,onInputChange:r,onServiceToggle:l}=e;return(0,re.jsxs)("div",{className:"w-full p-6 bg-white flex flex-col justify-start items-start gap-6",children:[(0,re.jsxs)("div",{className:"w-full flex flex-col justify-start items-start gap-2",children:[(0,re.jsxs)("div",{className:"flex flex-col justify-start items-start gap-0.5",children:[(0,re.jsx)(uu,{className:"text-gray-700 text-sm font-medium font-base44 leading-tight",children:"Which services do you offer?"}),(0,re.jsx)("p",{className:"text-slate-500 text-sm font-normal font-base44 leading-tight",children:"Please select at least one service"})]}),(0,re.jsx)(ew,{options:IN,selectedOptions:a.services,onToggle:l}),n.services&&(0,re.jsx)("p",{className:"text-sm text-red-500 mt-1",children:n.services})]}),a.services.includes("Other")&&(0,re.jsx)("div",{className:"w-full",children:(0,re.jsx)(SN,{label:"Tell us what service you offer",placeholder:"Describe your service...",value:a.other_service_description||"",onChange:e=>r("other_service_description",e),error:n.other_service_description,helperText:"".concat(null!==(s=null===(t=a.other_service_description)||void 0===t?void 0:t.length)&&void 0!==s?s:0,"/30 characters"),className:"w-full"})})]})},tw=e=>{let{formData:s,errors:t,onInputChange:a,onAppsModeToggle:n}=e;const r=s.apps&&s.apps.length>0?s.apps.length<2?[...s.apps,...Array(2-s.apps.length).fill({url:"",allow_public_showcase:!0})]:s.apps:[{url:"",allow_public_showcase:!0},{url:"",allow_public_showcase:!0}],l=s.has_apps_to_share?"has_apps":"no_apps";return(0,re.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,re.jsx)("div",{className:"flex flex-col justify-start items-start gap-1",children:(0,re.jsx)("div",{className:"flex flex-col justify-start items-start",children:(0,re.jsx)("div",{className:"justify-center text-gray-700 text-base font-semibold font-base44 leading-normal",children:"Show us your work on Base44"})})}),(0,re.jsx)(XN,{label:"",value:l,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"}]}),s.has_apps_to_share?(0,re.jsxs)("div",{className:"w-full pt-3 flex flex-col justify-start items-start gap-2",children:[(0,re.jsxs)("div",{className:"w-full flex gap-4",children:[(0,re.jsx)("div",{className:"flex-[3] min-w-0",children:(0,re.jsxs)("div",{className:"text-left text-gray-700 text-sm font-medium font-base44 leading-tight",children:["App links",t.apps&&(0,re.jsx)("div",{className:"text-red-500 text-xs mt-1 font-normal",children:t.apps})]})}),(0,re.jsx)("div",{className:"flex-[2] min-w-0",children:(0,re.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,re.jsx)(Og,{children:(0,re.jsxs)(Rg,{delayDuration:100,children:[(0,re.jsx)(Dg,{asChild:!0,children:(0,re.jsx)(jo.A,{className:"h-4 w-4 text-gray-600 hover:text-gray-900"})}),(0,re.jsx)(Mg,{className:"max-w-[240px] p-3 text-xs",children:(0,re.jsx)("p",{children:"Public apps will be showcased to other users. Private apps are only shared with us for review."})})]})})]})})]}),(0,re.jsx)("div",{className:"w-full flex flex-col gap-3",children:r.map((e,t)=>(0,re.jsxs)("div",{className:"w-full flex gap-4 items-center",children:[(0,re.jsx)("div",{className:"flex-[3] min-w-0",children:(0,re.jsx)(SN,{label:"",placeholder:"https://base44.com/app/my-app",value:e.url,onChange:e=>((e,t)=>{const n=[...s.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:t}),a("apps",n)})(t,e),error:null,type:"url",className:"w-full"})}),(0,re.jsx)("div",{className:"flex-[2] min-w-0",children:(0,re.jsxs)("div",{className:"flex justify-start items-center gap-2",children:[(0,re.jsx)(Yu,{id:"showcase-".concat(t),checked:e.allow_public_showcase,onCheckedChange:e=>((e,t)=>{const n=[...s.apps||[]];n[e]||(n[e]={url:"",allow_public_showcase:!0}),n[e]=(0,K.A)((0,K.A)({},n[e]),{},{allow_public_showcase:t}),a("apps",n)})(t,e),className:"w-4 h-4"}),(0,re.jsx)(uu,{htmlFor:"showcase-".concat(t),className:"text-gray-950 text-sm font-normal font-base44 leading-tight pointer-events-none",children:"Share publicly"})]})})]},t))}),(0,re.jsxs)(Yn,{type:"button",variant:"secondary",size:"sm",onClick:()=>{const e=[...s.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:r.length>=5,className:"h-7 px-3 gap-1.5",children:[r.length<5?(0,re.jsx)(Ss.A,{className:"w-4 h-4"}):null,r.length>=5?"Maximum 5 apps":"Add link"]})]}):(0,re.jsx)("div",{className:"w-full pt-3",children:(0,re.jsx)(SN,{label:"What makes you a great partner?",placeholder:"Describe your relevant experience",value:s.no_apps_explanation||"",onChange:e=>a("no_apps_explanation",e),error:t.no_apps_explanation,type:"textarea",required:!0,helperText:"".concat((s.no_apps_explanation||"").length," characters (minimum 20)"),rows:4,className:"w-full h-30",tooltipText:"Will be reviewed internally by Base44"})})]})},aw=e=>{var s;let{formData:t,userEmail:a,logoPreview:n}=e;const r=(()=>{const e=[];return t.website_url&&e.push(t.website_url.replace(/^https?:\/\//,"").replace(/^www\./,"")),t.linkedin_url&&e.push(t.linkedin_url.replace(/^https?:\/\//,"").replace(/^www\./,"")),e})(),l=(()=>{let e=[...t.services];return e.includes("Other")&&t.other_service_description&&(e=e.filter(e=>"Other"!==e),e.push(t.other_service_description)),e})(),i=[{label:"Type",value:"individual"===t.individual_or_team?"Individual":"Team/Agency"},{label:"Location",value:"".concat(t.city,", ").concat(t.country)},{label:"Links",value:(0,re.jsx)("div",{className:"flex flex-wrap items-center gap-3",children:r.map((e,s)=>(0,re.jsxs)(H.Fragment,{children:[(0,re.jsx)("div",{className:"text-gray-950 text-sm font-medium font-base44 leading-tight break-words",children:e}),s0},{label:"Languages",value:t.languages.map(e=>{var s;return(null===(s=TN.find(s=>s.value===e))||void 0===s?void 0:s.label)||e}).join(", "),show:t.languages.length>0},{label:"Services",value:(0,re.jsx)("div",{className:"flex flex-col gap-1",children:l.map((e,s)=>(0,re.jsxs)("div",{className:"text-gray-950 text-sm font-medium font-base44 leading-tight break-words",children:["\u2022 ",e]},s))}),show:t.services.length>0},{label:"Pricing",value:(0,re.jsxs)("div",{className:"flex flex-wrap items-center gap-3",children:[t.budget_starting_from_dollars&&(0,re.jsxs)(re.Fragment,{children:[(0,re.jsxs)("div",{className:"text-gray-950 text-sm font-medium font-base44 leading-tight break-words",children:["From $",t.budget_starting_from_dollars]}),t.hourly_rate&&(0,re.jsx)("div",{className:"w-1 h-1 bg-gray-500 rounded-full flex-shrink-0"})]}),t.hourly_rate&&(0,re.jsxs)("div",{className:"text-gray-950 text-sm font-medium font-base44 leading-tight break-words",children:["$",t.hourly_rate,"/hour"]})]}),show:!(!t.budget_starting_from_dollars&&!t.hourly_rate)},{label:"Description",value:(0,re.jsx)("div",{className:"text-gray-950 text-sm font-medium font-base44 leading-tight whitespace-pre-wrap break-words",children:t.description}),show:!!t.description},{label:"Apps",value:(0,re.jsx)("div",{className:"flex flex-col gap-2",children:null===(s=t.apps)||void 0===s?void 0:s.filter(e=>e.url&&e.url.trim()).map((e,s)=>{return(0,re.jsxs)("div",{className:"flex flex-col sm:flex-row sm:items-start gap-1 sm:gap-2",children:[(0,re.jsxs)("div",{className:"flex-1 justify-start text-gray-950 text-sm font-medium font-base44 leading-tight break-words",children:["\u2022 ",(t=e.url,t.replace(/^https?:\/\//,"").replace(/^www\./,""))]}),e.allow_public_showcase&&(0,re.jsx)("span",{className:"text-xs text-slate-900 bg-gray-200 px-2 py-1 max-w-16 rounded flex-shrink-0",children:"Allowed"})]},s);var t})}),show:t.has_apps_to_share&&t.apps&&t.apps.length>0&&t.apps.some(e=>e.url&&e.url.trim())},{label:"Experience",value:(0,re.jsx)("div",{className:"text-gray-950 text-sm font-medium font-base44 leading-tight whitespace-pre-wrap break-words",children:t.no_apps_explanation}),show:!t.has_apps_to_share&&!!t.no_apps_explanation}];return(0,re.jsxs)("div",{className:"w-full p-6 bg-white inline-flex flex-col justify-start items-start gap-3 overflow-hidden",children:[(0,re.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,re.jsx)("span",{className:"font-medium",children:a})," once it has been processed."]}),(0,re.jsx)("p",{className:"w-full text-gray-700 text-sm font-medium font-base44 leading-tight",children:"Review your profile card"}),(0,re.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,re.jsxs)("div",{className:"w-full inline-flex justify-start items-center gap-3",children:[(0,re.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||t.logo_url?(0,re.jsx)("img",{src:n||t.logo_url,alt:"Company logo",className:"w-10 h-10 object-cover"}):(0,re.jsx)("div",{className:"w-10 h-10 bg-gray-200 rounded-md flex items-center justify-center",children:(0,re.jsx)("span",{className:"text-xs text-gray-400 font-base44",children:t.name.charAt(0).toUpperCase()})})}),(0,re.jsx)("div",{className:"flex-1 text-black text-base font-medium font-base44 leading-tight",children:t.name})]}),(0,re.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,s)=>(0,re.jsxs)("div",{className:"w-full py-[3px] flex flex-col sm:flex-row sm:items-start gap-1 sm:gap-0",children:[(0,re.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,re.jsx)("div",{className:"flex-1 justify-start text-gray-950 text-sm font-medium font-base44 leading-tight break-words",children:e.value})]},s))})]})]})};const nw=new class extends Zs{getBaseURL(){return"/partners"}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})}},rw={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},lw=()=>{const[e,s]=(0,H.useState)(rw),[t,a]=(0,H.useState)({}),[n,r]=(0,H.useState)(null),[l,i]=(0,H.useState)(null),[o,c]=(0,H.useState)(!1),d=(e,n)=>{s(s=>(0,K.A)((0,K.A)({},s),{},{[e]:n})),t[e]&&a(s=>(0,K.A)((0,K.A)({},s),{},{[e]:null})),("budget_starting_from_dollars"===e||"hourly_rate"===e)&&t.pricing&&n&&a(e=>(0,K.A)((0,K.A)({},e),{},{pricing:null}))};return{formData:e,errors:t,logoFile:n,logoPreview:l,isSubmitting:o,handleInputChange:d,handleServiceToggle:s=>{const t=e.services.includes(s)?e.services.filter(e=>e!==s):[...e.services,s];d("services",t)},handleLanguageToggle:s=>{const t=e.languages.includes(s)?e.languages.filter(e=>e!==s):[...e.languages,s];d("languages",t)},handleAppsModeToggle:e=>{s(s=>(0,K.A)((0,K.A)({},s),{},{has_apps_to_share:e})),a(e=>(0,K.A)((0,K.A)({},e),{},{apps:null,no_apps_explanation:null}))},handleLogoUpload:e=>{var s;const n=null===(s=e.target.files)||void 0===s?void 0:s[0];if(!n)return;if(!n.type.startsWith("image/"))return void an({title:"Invalid file type",description:"Please upload an image file (PNG, JPG, SVG)",variant:"destructive"});if(n.size>5242880)return void an({title:"File too large",description:"Please upload an image smaller than 5MB",variant:"destructive"});r(n),t.logo&&a(e=>(0,K.A)((0,K.A)({},e),{},{logo:null}));const l=new FileReader;l.onloadend=()=>{i(l.result)},l.readAsDataURL(n)},handleLogoRemove:()=>{r(null),i(null),a(e=>(0,K.A)((0,K.A)({},e),{},{logo:"Logo upload is required"}))},handleTermsToggle:()=>{d("terms_accepted",!e.terms_accepted)},validateStep:s=>{let t;switch(s){case 0:t=((e,s)=>{const t=(0,K.A)((0,K.A)({},e),{},{logo:s}),a=VN.safeParse(t);return a.success?{success:!0,errors:{}}:{success:!1,errors:$N(a.error)}})(e,!(!n&&!e.logo_url));break;case 1:t=(e=>{const s=YN.safeParse(e);return s.success?{success:!0,errors:{}}:{success:!1,errors:$N(s.error)}})(e);break;case 2:t=(e=>{const s=HN.safeParse(e);return s.success?{success:!0,errors:{}}:{success:!1,errors:$N(s.error)}})(e);break;case 3:t=(e=>{const s=GN.safeParse(e);return s.success?{success:!0,errors:{}}:{success:!1,errors:$N(s.error)}})(e);break;default:return!0}return a(t.errors),t.success},handleSubmit:async s=>{const t=(e=>{const s=WN.safeParse(e);return s.success?{success:!0,errors:{}}:{success:!1,errors:$N(s.error)}})(e);if(!t.success)return a(t.errors),!1;if(!s)return an({title:"Authentication Required",description:"Please log in to submit a partner application.",variant:"destructive"}),!1;c(!0);try{let t=e.logo_url;if(n)try{t=(await As.uploadFile(n)).url}catch(i){an({title:"Logo upload failed",description:"Continuing with application without logo",variant:"destructive"})}const a=(0,K.A)((0,K.A)({},e),{},{logo_url:t,budget_starting_from_dollars:e.budget_starting_from_dollars?parseInt(e.budget_starting_from_dollars):null,hourly_rate:e.hourly_rate?parseInt(e.hourly_rate):null,apps:(e.apps||[]).filter(e=>e.url&&e.url.trim())});return await nw.create(a),an({description:(0,re.jsx)("div",{className:"flex items-start gap-2",children:(0,re.jsxs)("div",{children:[(0,re.jsx)("p",{className:"font-medium",children:"Thank you for applying to become a partner!"}),(0,re.jsxs)("p",{className:"text-sm text-slate-600 mt-1",children:["We'll review your application and notify you via email at ",s,"."]})]})}),duration:1e4}),!0}catch(i){var r,l;return an({title:"Submission Failed",description:(null===(r=i.response)||void 0===r||null===(l=r.data)||void 0===l?void 0:l.detail)||"Failed to submit application. Please try again.",variant:"destructive"}),!1}finally{c(!1)}},resetForm:()=>{s(rw),r(null),i(null),a({})}}},iw=e=>{let{isOpen:s,onClose:t}=e;const{user:a}=oe(),[n,r]=(0,H.useState)(0),{formData:l,errors:i,logoPreview:o,isSubmitting:c,handleInputChange:d,handleServiceToggle:m,handleLanguageToggle:u,handleAppsModeToggle:x,handleLogoUpload:h,handleLogoRemove:p,handleTermsToggle:g,validateStep:f,handleSubmit:v,resetForm:b}=lw(),j=[{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 s?(0,re.jsx)(Og,{children:(0,re.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,re.jsx)(AN,{"data-testid":"partner-wizard",steps:j,currentStep:n,title:"Become a Base44 Partner",description:(0,re.jsxs)(re.Fragment,{children:["Information you provide here will be shown on your Partner profile and will be visible to potential clients."," ",(0,re.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:()=>{f(n)&&r(e=>Math.min(e+1,j.length-1))},onPrevious:()=>{r(e=>Math.max(e-1,0))},onSubmit:async()=>{await v(null==a?void 0:a.email)&&(b(),r(0),t())},onClose:t,isLoading:c,submitButtonText:"Submit",className:"w-[640px] h-[600px]",footerLeftContent:n!==j.length-1?null:(0,re.jsxs)("div",{className:"flex justify-start items-center gap-2",children:[(0,re.jsx)("button",{type:"button",onClick:g,className:"w-4 h-4 rounded outline outline-1 outline-offset-[-1px] flex justify-center items-center transition-colors ".concat(i.terms_accepted?"bg-white outline-red-500 hover:outline-red-600":l.terms_accepted?"bg-gray-800 outline-gray-800":"bg-white outline-gray-300 hover:outline-gray-400"),children:l.terms_accepted&&(0,re.jsx)(Pt.A,{className:"w-3 h-3 text-white",strokeWidth:2})}),(0,re.jsxs)("div",{className:"flex justify-start items-center gap-1",children:[(0,re.jsxs)("span",{className:"text-gray-700 text-sm font-normal font-base44 leading-tight",children:["Agree to"," "]}),(0,re.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"}),i.terms_accepted&&(0,re.jsxs)(Rg,{delayDuration:100,children:[(0,re.jsx)(Dg,{asChild:!0,children:(0,re.jsx)(jo.A,{className:"w-4 h-4 text-red-500"})}),(0,re.jsx)(Mg,{children:(0,re.jsx)("p",{children:"You must agree to the terms of service to become a partner."})})]})]})]}),children:(0,re.jsx)("div",{"data-testid":"step-content",children:(()=>{switch(n){case 0:return(0,re.jsx)(KN,{formData:l,errors:i,logoPreview:o,onInputChange:d,onLogoUpload:h,onLogoRemove:p});case 1:return(0,re.jsx)(QN,{formData:l,errors:i,onInputChange:d,onLanguageToggle:u});case 2:return(0,re.jsx)(sw,{formData:l,errors:i,onInputChange:d,onServiceToggle:m});case 3:return(0,re.jsx)(tw,{formData:l,errors:i,onInputChange:d,onAppsModeToggle:x});case 4:return(0,re.jsx)(aw,{formData:l,userEmail:null==a?void 0:a.email,logoPreview:o});default:return null}})()})})})}):null};var ow=t(76274),cw=t(78130),dw=t(41016),mw=t(31855),uw=t(14215);const xw=e=>e&&Array.isArray(e)?e.map(e=>{const s=TN.find(s=>s.value===e);return s?s.label:e}):[];function hw(e){let{showAnalytics:s=!1,setShowAnalytics:t=()=>{}}=e;const[a,n]=(0,H.useState)([]),[r,l]=(0,H.useState)(!0),[i,o]=(0,H.useState)("all"),[c,d]=(0,H.useState)(""),[m,u]=(0,H.useState)(null),[x,h]=(0,H.useState)(!1),[p,g]=(0,H.useState)(""),[f,v]=(0,H.useState)(!1),[b,j]=(0,H.useState)(1),[y,N]=(0,H.useState)(0),[w,_]=(0,H.useState)({key:"created_date",direction:"desc"}),[k,A]=(0,H.useState)(null),[S,C]=(0,H.useState)({}),[E,I]=(0,H.useState)(new Set),[T,P]=(0,H.useState)("all"),[L,O]=(0,H.useState)(""),R=50,[D,M]=(0,H.useState)([]),[F,B]=(0,H.useState)([]),[U,z]=(0,H.useState)(!1);(0,H.useEffect)(()=>{if(k&&clearTimeout(k),1===b)return A(setTimeout(()=>{q()},500)),()=>{k&&clearTimeout(k)};j(1)},[c,i,T,L,w]),(0,H.useEffect)(()=>{q()},[b]);const q=async()=>{try{l(!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"!==T&&(e.individual_or_team=T),L&&(e.$or=e.$or?[...e.$or,{city:{$regex:L,$options:"i"}},{country:{$regex:L,$options:"i"}}]:[{city:{$regex:L,$options:"i"}},{country:{$regex:L,$options:"i"}}]);const s=(0,K.A)((0,K.A)({},e),{},{limit:R,skip:(b-1)*R,sort_by:"desc"===w.direction?"-".concat(w.key):w.key}),t=await nw.listCatalogItems(s),a=t.items||t;n(a),a.length{const s=e.item.id;C(e=>(0,K.A)((0,K.A)({},e),{},{[s]:!0}));try{await nw.approveItem(s),an({title:"Success",description:"".concat(e.item.name," has been approved")}),await q()}catch(t){an({title:"Error",description:"Failed to approve partner",variant:"destructive"})}finally{C(e=>(0,K.A)((0,K.A)({},e),{},{[s]:!1}))}},V=e=>{u(e),g(""),h(!0)},Y=e=>{const s=w.key===e&&"asc"===w.direction?"desc":"asc";_({key:e,direction:s}),j(1)},G=()=>"all"!==i||"all"!==T||""!==L||""!==c,$=e=>{switch(e){case"approved":return(0,re.jsxs)(et,{className:"bg-emerald-100 text-emerald-700 border-emerald-200 font-medium px-2.5 py-0.5 text-xs",children:[(0,re.jsx)("div",{className:"w-1.5 h-1.5 bg-emerald-500 rounded-full mr-1.5"}),"Approved"]});case"rejected":return(0,re.jsxs)(et,{className:"bg-red-100 text-red-700 border-red-200 font-medium px-2.5 py-0.5 text-xs",children:[(0,re.jsx)("div",{className:"w-1.5 h-1.5 bg-red-500 rounded-full mr-1.5"}),"Rejected"]});default:return(0,re.jsxs)(et,{className:"bg-amber-100 text-amber-700 border-amber-200 font-medium px-2.5 py-0.5 text-xs",children:[(0,re.jsx)(Xp.A,{className:"w-3 h-3 mr-1.5"}),"Pending"]})}};return(0,re.jsxs)(re.Fragment,{children:[(0,re.jsxs)("div",{className:"flex items-center justify-between mb-6",children:[(0,re.jsx)("h1",{className:"text-3xl font-bold",children:"Partner Management"}),(0,re.jsxs)(Hs,{onClick:()=>s?t(!1):(async()=>{z(!0);try{const[e,s]=await Promise.all([nw.listCatalogItems({limit:1e4,skip:0,sort_by:"-created_date"}),nw.getAllContactRequests({limit:1e4,skip:0,sort_by:"-created_date"})]),a=e.items||e,n=s.items||s;M(a),B(n),t(!0)}catch(e){an({title:"Error",description:"Failed to fetch analytics data",variant:"destructive"})}finally{z(!1)}})(),disabled:U,className:"flex items-center gap-2",variant:s?"default":"outline",children:[(0,re.jsx)(kd.A,{className:"h-4 w-4"}),U?"Analyzing...":s?"Hide Analytics":"Analyze"]})]}),s&&D.length>0&&(0,re.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,re.jsxs)("div",{className:"flex items-center justify-between mb-8",children:[(0,re.jsxs)("div",{className:"flex items-center gap-3",children:[(0,re.jsx)("div",{className:"p-2 bg-blue-100 rounded-xl",children:(0,re.jsx)(kd.A,{className:"h-6 w-6 text-blue-600"})}),(0,re.jsxs)("div",{children:[(0,re.jsx)("h2",{className:"text-2xl font-bold text-slate-900",children:"Partner Analytics Dashboard"}),(0,re.jsxs)("p",{className:"text-sm text-slate-600 mt-1",children:["Real-time insights across ",D.length," partners"]})]})]}),(0,re.jsx)(Hs,{variant:"ghost",size:"sm",onClick:()=>t(!1),className:"h-10 w-10 p-0 hover:bg-slate-100 rounded-xl",children:(0,re.jsx)(zs.A,{className:"h-5 w-5 text-slate-400"})})]}),(()=>{const e=function(e){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];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},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,s)=>(s.item.languages&&s.item.languages.forEach(s=>{e[s]=(e[s]||0)+1}),e),{}),r=e.reduce((e,s)=>{const t=LN(s.item.country)||s.item.country||"Unknown";return e[t]=(e[t]||0)+1,e},{}),l=e.reduce((e,s)=>(s.item.services&&s.item.services.forEach(s=>{e[s]=(e[s]||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,s)=>e+s.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,s)=>e+s.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,s)=>{var t;const a=(null===(t=s.item_creator)||void 0===t?void 0:t.full_name)||"Unknown";return e[a]=(e[a]||0)+1,e},{}),d=la()(),m=e.filter(e=>la()(e.item.created_date).isSame(d,"month")).length,u=e.filter(e=>la()(e.item.created_date).isSame(d,"quarter")).length,x={total:s.length,thisMonth:s.filter(e=>la()(e.created_date).isSame(d,"month")).length,thisQuarter:s.filter(e=>la()(e.created_date).isSame(d,"quarter")).length},h=s.reduce((e,s)=>{const t=s.partner_name||"Unknown";return e[t]=(e[t]||0)+1,e},{}),p=s.reduce((e,s)=>{const t=s.project_type||"unknown";return e[t]=(e[t]||0)+1,e},{}),g=s.reduce((e,s)=>{const t=s.work_basis||"unknown";return e[t]=(e[t]||0)+1,e},{}),f=s.reduce((e,s)=>{const t=s.start_date||"unknown";return e[t]=(e[t]||0)+1,e},{}),v={uniqueClients:new Set(s.map(e=>e.client_email)).size,averageRequestsPerClient:s.length/new Set(s.map(e=>e.client_email)).size||0,repeatClients:Object.values(s.reduce((e,s)=>(e[s.client_email]=(e[s.client_email]||0)+1,e),{})).filter(e=>e>1).length};return{statusStats:t,typeStats:a,languageStats:n,countryStats:r,serviceStats:l,pricingStats:i,contentStats:o,creatorStats:Object.entries(c).sort((e,s)=>{let[,t]=e,[,a]=s;return a-t}).slice(0,10),topCountries:Object.entries(r).sort((e,s)=>{let[,t]=e,[,a]=s;return a-t}).slice(0,5),topServices:Object.entries(l).sort((e,s)=>{let[,t]=e,[,a]=s;return a-t}).slice(0,5),temporalStats:{thisMonth:m,thisQuarter:u,totalCreators:Object.keys(c).length},contactRequestsStats:x,topPartnersByRequests:Object.entries(h).sort((e,s)=>{let[,t]=e,[,a]=s;return a-t}).slice(0,10),projectTypeStats:p,workBasisStats:g,startDateStats:f,clientEngagementStats:v}}(D,F);return(0,re.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6",children:[(0,re.jsxs)("div",{className:"bg-white p-6 rounded-xl border border-slate-200 shadow-sm hover:shadow-md transition-shadow",children:[(0,re.jsxs)("div",{className:"flex items-center gap-3 mb-6",children:[(0,re.jsx)("div",{className:"p-2 bg-emerald-100 rounded-lg",children:(0,re.jsx)($b.A,{className:"h-5 w-5 text-emerald-600"})}),(0,re.jsxs)("div",{children:[(0,re.jsx)("h3",{className:"font-semibold text-slate-800",children:"Status Overview"}),(0,re.jsx)("p",{className:"text-xs text-slate-500",children:"Approval pipeline health"})]})]}),(0,re.jsxs)("div",{className:"space-y-4",children:[(0,re.jsxs)("div",{className:"text-center p-4 bg-slate-50 rounded-lg",children:[(0,re.jsx)("div",{className:"text-3xl font-bold text-slate-900",children:e.statusStats.total}),(0,re.jsx)("div",{className:"text-sm text-slate-600 font-medium",children:"Total Partners"})]}),(0,re.jsxs)("div",{className:"space-y-3",children:[(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsxs)("div",{className:"flex justify-between items-center",children:[(0,re.jsx)("span",{className:"text-sm font-medium text-emerald-700",children:"Approved"}),(0,re.jsxs)("span",{className:"text-sm font-bold text-emerald-700",children:[e.statusStats.approved," (",(e.statusStats.approved/e.statusStats.total*100).toFixed(1),"%)"]})]}),(0,re.jsx)("div",{className:"w-full bg-emerald-100 rounded-full h-2",children:(0,re.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,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsxs)("div",{className:"flex justify-between items-center",children:[(0,re.jsx)("span",{className:"text-sm font-medium text-amber-700",children:"Pending"}),(0,re.jsxs)("span",{className:"text-sm font-bold text-amber-700",children:[e.statusStats.pending," (",(e.statusStats.pending/e.statusStats.total*100).toFixed(1),"%)"]})]}),(0,re.jsx)("div",{className:"w-full bg-amber-100 rounded-full h-2",children:(0,re.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,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsxs)("div",{className:"flex justify-between items-center",children:[(0,re.jsx)("span",{className:"text-sm font-medium text-red-700",children:"Rejected"}),(0,re.jsxs)("span",{className:"text-sm font-bold text-red-700",children:[e.statusStats.rejected," (",(e.statusStats.rejected/e.statusStats.total*100).toFixed(1),"%)"]})]}),(0,re.jsx)("div",{className:"w-full bg-red-100 rounded-full h-2",children:(0,re.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,re.jsxs)("div",{className:"bg-white p-6 rounded-xl border border-slate-200 shadow-sm hover:shadow-md transition-shadow",children:[(0,re.jsxs)("div",{className:"flex items-center gap-3 mb-6",children:[(0,re.jsx)("div",{className:"p-2 bg-blue-100 rounded-lg",children:(0,re.jsx)(Gr.A,{className:"h-5 w-5 text-blue-600"})}),(0,re.jsxs)("div",{children:[(0,re.jsx)("h3",{className:"font-semibold text-slate-800",children:"Partner Analytics"}),(0,re.jsx)("p",{className:"text-xs text-slate-500",children:"Types and geographic distribution"})]})]}),(0,re.jsxs)("div",{className:"space-y-4",children:[(0,re.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,re.jsxs)("div",{className:"text-center p-3 bg-gradient-to-br from-blue-50 to-blue-100 rounded-lg",children:[(0,re.jsx)("div",{className:"text-2xl font-bold text-blue-900",children:e.typeStats.individual}),(0,re.jsx)("div",{className:"text-xs text-blue-700 font-medium",children:"Individuals"})]}),(0,re.jsxs)("div",{className:"text-center p-3 bg-gradient-to-br from-indigo-50 to-indigo-100 rounded-lg",children:[(0,re.jsx)("div",{className:"text-2xl font-bold text-indigo-900",children:e.typeStats.team}),(0,re.jsx)("div",{className:"text-xs text-indigo-700 font-medium",children:"Teams"})]})]}),(0,re.jsxs)("div",{className:"p-4 bg-slate-50 rounded-lg border-l-4 border-green-500",children:[(0,re.jsx)("div",{className:"text-sm font-medium text-slate-700 mb-2",children:"Top Regions"}),(0,re.jsx)("div",{className:"space-y-2",children:e.topCountries.slice(0,3).map((e,s)=>{let[t,a]=e;return(0,re.jsxs)("div",{className:"flex justify-between items-center",children:[(0,re.jsx)("span",{className:"text-xs text-slate-600",children:t}),(0,re.jsx)("span",{className:"text-xs font-bold text-slate-900",children:a})]},t)})})]})]})]}),(0,re.jsxs)("div",{className:"bg-white p-6 rounded-xl border border-slate-200 shadow-sm hover:shadow-md transition-shadow",children:[(0,re.jsxs)("div",{className:"flex items-center gap-3 mb-6",children:[(0,re.jsx)("div",{className:"p-2 bg-purple-100 rounded-lg",children:(0,re.jsx)(ow.A,{className:"h-5 w-5 text-purple-600"})}),(0,re.jsxs)("div",{children:[(0,re.jsx)("h3",{className:"font-semibold text-slate-800",children:"Profile Quality"}),(0,re.jsx)("p",{className:"text-xs text-slate-500",children:"Completeness metrics"})]})]}),(0,re.jsxs)("div",{className:"space-y-4",children:[(0,re.jsxs)("div",{className:"space-y-3",children:[(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsxs)("div",{className:"flex justify-between items-center",children:[(0,re.jsx)("span",{className:"text-sm font-medium text-slate-700",children:"With Descriptions"}),(0,re.jsxs)("span",{className:"text-sm font-bold text-slate-900",children:[(e.contentStats.withDescriptions/e.statusStats.total*100).toFixed(1),"%"]})]}),(0,re.jsx)("div",{className:"w-full bg-gray-200 rounded-full h-2",children:(0,re.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,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsxs)("div",{className:"flex justify-between items-center",children:[(0,re.jsx)("span",{className:"text-sm font-medium text-slate-700",children:"Terms Accepted"}),(0,re.jsxs)("span",{className:"text-sm font-bold text-slate-900",children:[(e.contentStats.termsAccepted/e.statusStats.total*100).toFixed(1),"%"]})]}),(0,re.jsx)("div",{className:"w-full bg-gray-200 rounded-full h-2",children:(0,re.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,re.jsxs)("div",{className:"grid grid-cols-2 gap-3 pt-2",children:[(0,re.jsxs)("div",{className:"text-center p-3 bg-green-50 rounded-lg border border-green-200",children:[(0,re.jsx)("div",{className:"text-xl font-bold text-green-700",children:e.contentStats.withLogos}),(0,re.jsx)("div",{className:"text-xs text-green-600 font-medium",children:"With Logos"})]}),(0,re.jsxs)("div",{className:"text-center p-3 bg-orange-50 rounded-lg border border-orange-200",children:[(0,re.jsx)("div",{className:"text-xl font-bold text-orange-700",children:e.contentStats.withApps}),(0,re.jsx)("div",{className:"text-xs text-orange-600 font-medium",children:"With Apps"})]})]})]})]}),(0,re.jsxs)("div",{className:"bg-white p-6 rounded-xl border border-slate-200 shadow-sm hover:shadow-md transition-shadow",children:[(0,re.jsxs)("div",{className:"flex items-center gap-3 mb-6",children:[(0,re.jsx)("div",{className:"p-2 bg-teal-100 rounded-lg",children:(0,re.jsx)(bn.A,{className:"h-5 w-5 text-teal-600"})}),(0,re.jsxs)("div",{children:[(0,re.jsx)("h3",{className:"font-semibold text-slate-800",children:"Services & Languages"}),(0,re.jsx)("p",{className:"text-xs text-slate-500",children:"Service portfolio analysis"})]})]}),(0,re.jsx)("div",{className:"space-y-4",children:(0,re.jsxs)("div",{className:"space-y-3",children:[(0,re.jsx)("div",{className:"text-sm font-medium text-slate-700",children:"Top Services"}),e.topServices.slice(0,4).map((s,t)=>{let[a,n]=s;const r=n/e.statusStats.total*100;return(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsxs)("div",{className:"flex justify-between items-center",children:[(0,re.jsx)("span",{className:"text-sm font-medium text-slate-700",children:a}),(0,re.jsxs)("span",{className:"text-sm font-bold text-slate-900",children:[n," (",r.toFixed(1),"%)"]})]}),(0,re.jsx)("div",{className:"w-full bg-gray-200 rounded-full h-2",children:(0,re.jsx)("div",{className:"".concat(["bg-blue-500","bg-green-500","bg-purple-500","bg-orange-500"][t]," h-2 rounded-full transition-all duration-500"),style:{width:"".concat(r,"%")}})})]},a)})]})})]}),(0,re.jsxs)("div",{className:"bg-white p-6 rounded-xl border border-slate-200 shadow-sm hover:shadow-md transition-shadow",children:[(0,re.jsxs)("div",{className:"flex items-center gap-3 mb-6",children:[(0,re.jsx)("div",{className:"p-2 bg-rose-100 rounded-lg",children:(0,re.jsx)(cw.A,{className:"h-5 w-5 text-rose-600"})}),(0,re.jsxs)("div",{children:[(0,re.jsx)("h3",{className:"font-semibold text-slate-800",children:"Top Contributors"}),(0,re.jsx)("p",{className:"text-xs text-slate-500",children:"Most active partner creators"})]})]}),(0,re.jsxs)("div",{className:"space-y-4",children:[(0,re.jsxs)("div",{className:"text-center p-3 bg-gradient-to-br from-rose-50 to-rose-100 rounded-lg",children:[(0,re.jsx)("div",{className:"text-2xl font-bold text-rose-900",children:e.temporalStats.totalCreators}),(0,re.jsx)("div",{className:"text-xs text-rose-700 font-medium",children:"Total Contributors"})]}),(0,re.jsx)("div",{className:"space-y-3",children:e.creatorStats.slice(0,5).map((e,s)=>{let[t,a]=e;return(0,re.jsxs)("div",{className:"flex items-center justify-between p-3 bg-slate-50 rounded-lg",children:[(0,re.jsxs)("div",{className:"flex items-center gap-3",children:[(0,re.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:s+1}),(0,re.jsx)("span",{className:"text-sm font-medium text-slate-700 truncate max-w-24",children:t})]}),(0,re.jsx)("div",{className:"flex items-center gap-2",children:(0,re.jsxs)("div",{className:"text-right",children:[(0,re.jsx)("div",{className:"text-sm font-bold text-slate-900",children:a}),(0,re.jsx)("div",{className:"text-xs text-slate-500",children:"partners"})]})})]},t)})})]})]}),(0,re.jsxs)("div",{className:"bg-white p-6 rounded-xl border border-slate-200 shadow-sm hover:shadow-md transition-shadow",children:[(0,re.jsxs)("div",{className:"flex items-center gap-3 mb-6",children:[(0,re.jsx)("div",{className:"p-2 bg-cyan-100 rounded-lg",children:(0,re.jsx)(ya.A,{className:"h-5 w-5 text-cyan-600"})}),(0,re.jsxs)("div",{children:[(0,re.jsx)("h3",{className:"font-semibold text-slate-800",children:"Recent Activity"}),(0,re.jsx)("p",{className:"text-xs text-slate-500",children:"Growth and trends"})]})]}),(0,re.jsxs)("div",{className:"space-y-4",children:[(0,re.jsxs)("div",{className:"grid grid-cols-1 gap-3",children:[(0,re.jsxs)("div",{className:"p-4 bg-gradient-to-r from-green-50 to-emerald-50 rounded-lg border border-green-200",children:[(0,re.jsxs)("div",{className:"flex justify-between items-center",children:[(0,re.jsx)("span",{className:"text-sm font-medium text-green-700",children:"This Month"}),(0,re.jsx)("span",{className:"text-xl font-bold text-green-900",children:e.temporalStats.thisMonth})]}),(0,re.jsx)("div",{className:"text-xs text-green-600 mt-1",children:"new partners"})]}),(0,re.jsxs)("div",{className:"p-4 bg-gradient-to-r from-blue-50 to-cyan-50 rounded-lg border border-blue-200",children:[(0,re.jsxs)("div",{className:"flex justify-between items-center",children:[(0,re.jsx)("span",{className:"text-sm font-medium text-blue-700",children:"This Quarter"}),(0,re.jsx)("span",{className:"text-xl font-bold text-blue-900",children:e.temporalStats.thisQuarter})]}),(0,re.jsx)("div",{className:"text-xs text-blue-600 mt-1",children:"total registrations"})]})]}),(0,re.jsxs)("div",{className:"grid grid-cols-1 gap-3",children:[e.pricingStats.averageBudget>0&&(0,re.jsxs)("div",{className:"p-4 bg-gradient-to-br from-purple-50 to-pink-50 rounded-lg border border-purple-200",children:[(0,re.jsx)("div",{className:"text-sm font-medium text-purple-700 mb-2",children:"Average Project Budget"}),(0,re.jsxs)("div",{className:"text-lg font-bold text-purple-900",children:["$",e.pricingStats.averageBudget.toLocaleString()]}),(0,re.jsxs)("div",{className:"text-xs text-purple-600 mt-1",children:["starting budget across ",e.pricingStats.withBudget," partners"]})]}),e.pricingStats.averageHourlyRate>0&&(0,re.jsxs)("div",{className:"p-4 bg-gradient-to-br from-emerald-50 to-teal-50 rounded-lg border border-emerald-200",children:[(0,re.jsx)("div",{className:"text-sm font-medium text-emerald-700 mb-2",children:"Average Hourly Rate"}),(0,re.jsxs)("div",{className:"text-lg font-bold text-emerald-900",children:["$",e.pricingStats.averageHourlyRate.toFixed(0),"/hr"]}),(0,re.jsxs)("div",{className:"text-xs text-emerald-600 mt-1",children:["across ",e.pricingStats.withHourlyRate," partners"]})]})]})]})]}),(0,re.jsxs)("div",{className:"bg-white p-6 rounded-xl border border-slate-200 shadow-sm hover:shadow-md transition-shadow",children:[(0,re.jsxs)("div",{className:"flex items-center gap-3 mb-6",children:[(0,re.jsx)("div",{className:"p-2 bg-indigo-100 rounded-lg",children:(0,re.jsx)(bl.A,{className:"h-5 w-5 text-indigo-600"})}),(0,re.jsxs)("div",{children:[(0,re.jsx)("h3",{className:"font-semibold text-slate-800",children:"Contact Requests"}),(0,re.jsx)("p",{className:"text-xs text-slate-500",children:"Client engagement metrics"})]})]}),(0,re.jsxs)("div",{className:"space-y-4",children:[(0,re.jsxs)("div",{className:"text-center p-4 bg-slate-50 rounded-lg",children:[(0,re.jsx)("div",{className:"text-3xl font-bold text-slate-900",children:e.contactRequestsStats.total}),(0,re.jsx)("div",{className:"text-sm text-slate-600 font-medium",children:"Total Requests"})]}),(0,re.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,re.jsxs)("div",{className:"text-center p-3 bg-gradient-to-br from-indigo-50 to-indigo-100 rounded-lg",children:[(0,re.jsx)("div",{className:"text-2xl font-bold text-indigo-900",children:e.clientEngagementStats.uniqueClients}),(0,re.jsx)("div",{className:"text-xs text-indigo-700 font-medium",children:"Unique Clients"})]}),(0,re.jsxs)("div",{className:"text-center p-3 bg-gradient-to-br from-purple-50 to-purple-100 rounded-lg",children:[(0,re.jsx)("div",{className:"text-2xl font-bold text-purple-900",children:e.clientEngagementStats.repeatClients}),(0,re.jsx)("div",{className:"text-xs text-purple-700 font-medium",children:"Repeat Clients"})]})]}),(0,re.jsx)("div",{className:"space-y-2",children:(0,re.jsxs)("div",{className:"p-3 bg-green-50 rounded-lg border-l-4 border-green-500",children:[(0,re.jsxs)("div",{className:"flex justify-between items-center",children:[(0,re.jsx)("span",{className:"text-sm font-medium text-green-700",children:"This Month"}),(0,re.jsx)("span",{className:"text-lg font-bold text-green-900",children:e.contactRequestsStats.thisMonth})]}),(0,re.jsx)("div",{className:"text-xs text-green-600 mt-1",children:"new requests"})]})})]})]}),(0,re.jsxs)("div",{className:"bg-white p-6 rounded-xl border border-slate-200 shadow-sm hover:shadow-md transition-shadow",children:[(0,re.jsxs)("div",{className:"flex items-center gap-3 mb-6",children:[(0,re.jsx)("div",{className:"p-2 bg-emerald-100 rounded-lg",children:(0,re.jsx)(Kr.A,{className:"h-5 w-5 text-emerald-600"})}),(0,re.jsxs)("div",{children:[(0,re.jsx)("h3",{className:"font-semibold text-slate-800",children:"Most Contacted Partners"}),(0,re.jsx)("p",{className:"text-xs text-slate-500",children:"Popular partner rankings"})]})]}),(0,re.jsxs)("div",{className:"space-y-4",children:[(0,re.jsx)("div",{className:"space-y-3",children:e.topPartnersByRequests.slice(0,5).map((e,s)=>{let[t,a]=e;return(0,re.jsxs)("div",{className:"flex items-center justify-between p-3 bg-slate-50 rounded-lg",children:[(0,re.jsxs)("div",{className:"flex items-center gap-3",children:[(0,re.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:s+1}),(0,re.jsx)("span",{className:"text-sm font-medium text-slate-700 truncate max-w-24",children:t})]}),(0,re.jsx)("div",{className:"flex items-center gap-2",children:(0,re.jsxs)("div",{className:"text-right",children:[(0,re.jsx)("div",{className:"text-sm font-bold text-slate-900",children:a}),(0,re.jsx)("div",{className:"text-xs text-slate-500",children:"requests"})]})})]},t)})}),0===e.topPartnersByRequests.length&&(0,re.jsx)("div",{className:"text-center py-4 text-slate-500",children:(0,re.jsx)("div",{className:"text-sm",children:"No contact requests yet"})})]})]}),(0,re.jsxs)("div",{className:"bg-white p-6 rounded-xl border border-slate-200 shadow-sm hover:shadow-md transition-shadow",children:[(0,re.jsxs)("div",{className:"flex items-center gap-3 mb-6",children:[(0,re.jsx)("div",{className:"p-2 bg-orange-100 rounded-lg",children:(0,re.jsx)(dw.A,{className:"h-5 w-5 text-orange-600"})}),(0,re.jsxs)("div",{children:[(0,re.jsx)("h3",{className:"font-semibold text-slate-800",children:"Project Insights"}),(0,re.jsx)("p",{className:"text-xs text-slate-500",children:"Client preferences analysis"})]})]}),(0,re.jsxs)("div",{className:"space-y-4",children:[(0,re.jsxs)("div",{className:"space-y-3",children:[(0,re.jsx)("div",{className:"text-sm font-medium text-slate-700",children:"Project Types"}),Object.entries(e.projectTypeStats).map((s,t)=>{let[a,n]=s;const r=n/e.contactRequestsStats.total*100,l="new_project"===a?"New Project":"Existing Project";return(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsxs)("div",{className:"flex justify-between items-center",children:[(0,re.jsx)("span",{className:"text-sm font-medium text-slate-700",children:l}),(0,re.jsxs)("span",{className:"text-sm font-bold text-slate-900",children:[n," (",r.toFixed(1),"%)"]})]}),(0,re.jsx)("div",{className:"w-full bg-gray-200 rounded-full h-2",children:(0,re.jsx)("div",{className:"".concat(["bg-blue-500","bg-green-500"][t]," h-2 rounded-full transition-all duration-500"),style:{width:"".concat(r,"%")}})})]},a)})]}),(0,re.jsxs)("div",{className:"space-y-3",children:[(0,re.jsx)("div",{className:"text-sm font-medium text-slate-700",children:"Work Basis Preference"}),Object.entries(e.workBasisStats).map((s,t)=>{let[a,n]=s;const r=n/e.contactRequestsStats.total*100,l="hourly"===a?"Hourly Rate":"fixed_price"===a?"Fixed Price":a;return(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsxs)("div",{className:"flex justify-between items-center",children:[(0,re.jsx)("span",{className:"text-sm font-medium text-slate-700",children:l}),(0,re.jsxs)("span",{className:"text-sm font-bold text-slate-900",children:[n," (",r.toFixed(1),"%)"]})]}),(0,re.jsx)("div",{className:"w-full bg-gray-200 rounded-full h-2",children:(0,re.jsx)("div",{className:"".concat(["bg-purple-500","bg-pink-500"][t]," h-2 rounded-full transition-all duration-500"),style:{width:"".concat(r,"%")}})})]},a)})]})]})]})]})})()]}),(0,re.jsxs)("div",{className:"mb-8 space-y-4",children:[(0,re.jsx)("div",{className:"bg-white p-4 rounded-xl border border-gray-100 shadow-sm",children:(0,re.jsxs)("div",{className:"flex flex-col lg:flex-row gap-3 items-start lg:items-center justify-between",children:[(0,re.jsxs)("div",{className:"flex flex-col sm:flex-row gap-3 items-start sm:items-center flex-1",children:[(0,re.jsxs)("div",{className:"relative w-full sm:w-80",children:[(0,re.jsx)(vn.A,{className:"absolute left-3 top-2.5 h-4 w-4 text-gray-400"}),(0,re.jsx)(ft,{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,re.jsxs)(Ut,{value:i,onValueChange:o,children:[(0,re.jsx)(Wt,{className:"w-36 h-9 border-gray-200 hover:border-gray-300 transition-colors",children:(0,re.jsxs)("div",{className:"flex items-center gap-2",children:[(0,re.jsx)(rp.A,{className:"h-3.5 w-3.5 text-gray-400"}),(0,re.jsx)(qt,{placeholder:"Status"})]})}),(0,re.jsxs)(Ht,{children:[(0,re.jsx)($t,{value:"all",children:"All Status"}),(0,re.jsx)($t,{value:"pending",children:"Pending"}),(0,re.jsx)($t,{value:"approved",children:"Approved"}),(0,re.jsx)($t,{value:"rejected",children:"Rejected"})]})]}),(0,re.jsxs)(Ut,{value:T,onValueChange:P,children:[(0,re.jsx)(Wt,{className:"w-36 h-9 border-gray-200 hover:border-gray-300 transition-colors",children:(0,re.jsxs)("div",{className:"flex items-center gap-2",children:[(0,re.jsx)(Gr.A,{className:"h-3.5 w-3.5 text-gray-400"}),(0,re.jsx)(qt,{placeholder:"Type"})]})}),(0,re.jsxs)(Ht,{children:[(0,re.jsx)($t,{value:"all",children:"All Types"}),(0,re.jsx)($t,{value:"individual",children:"Individual"}),(0,re.jsx)($t,{value:"team",children:"Team"})]})]}),(0,re.jsxs)("div",{className:"relative w-full sm:w-40",children:[(0,re.jsx)(mw.A,{className:"absolute left-3 top-2.5 h-4 w-4 text-gray-400"}),(0,re.jsx)(ft,{placeholder:"Location...",className:"pl-10 h-9 border-gray-200 focus:border-blue-500 focus:ring-blue-500/20 transition-all duration-200",value:L,onChange:e=>O(e.target.value)})]}),G()&&(0,re.jsxs)(Hs,{variant:"outline",size:"sm",onClick:()=>{o("all"),P("all"),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,re.jsx)(zs.A,{className:"h-3.5 w-3.5 mr-1"}),"Clear"]})]}),(0,re.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,re.jsx)(oh.A,{className:"h-3.5 w-3.5"}),y>0?"".concat(y," total partners"):"".concat(a.length," partners")]})]})}),G()&&(0,re.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,re.jsxs)("span",{className:"text-sm font-medium text-gray-700 flex items-center gap-1",children:[(0,re.jsx)(Sg.A,{className:"h-3.5 w-3.5"}),"Active filters:"]}),"all"!==i&&(0,re.jsxs)(et,{className:"bg-blue-100 text-blue-800 hover:bg-blue-200 transition-colors",children:["Status: ",i,(0,re.jsx)("button",{onClick:()=>o("all"),className:"ml-1 hover:bg-blue-300 rounded-full p-0.5 transition-colors",children:(0,re.jsx)(zs.A,{className:"h-3 w-3"})})]}),"all"!==T&&(0,re.jsxs)(et,{className:"bg-teal-100 text-teal-800 hover:bg-teal-200 transition-colors",children:["Type: ",T,(0,re.jsx)("button",{onClick:()=>P("all"),className:"ml-1 hover:bg-teal-300 rounded-full p-0.5 transition-colors",children:(0,re.jsx)(zs.A,{className:"h-3 w-3"})})]}),L&&(0,re.jsxs)(et,{className:"bg-purple-100 text-purple-800 hover:bg-purple-200 transition-colors",children:["Location: ",L,(0,re.jsx)("button",{onClick:()=>O(""),className:"ml-1 hover:bg-purple-300 rounded-full p-0.5 transition-colors",children:(0,re.jsx)(zs.A,{className:"h-3 w-3"})})]}),c&&(0,re.jsxs)(et,{className:"bg-green-100 text-green-800 hover:bg-green-200 transition-colors",children:['Search: "',c,'"',(0,re.jsx)("button",{onClick:()=>d(""),className:"ml-1 hover:bg-green-300 rounded-full p-0.5 transition-colors",children:(0,re.jsx)(zs.A,{className:"h-3 w-3"})})]})]})]}),(0,re.jsx)("div",{className:"bg-white rounded-xl border border-gray-200 shadow-sm overflow-hidden",children:(0,re.jsxs)(Or,{children:[(0,re.jsx)(Rr,{children:(0,re.jsxs)(Fr,{children:[(0,re.jsx)(Br,{className:"w-8"}),(0,re.jsx)(Br,{className:"cursor-pointer",onClick:()=>Y("name"),children:(0,re.jsxs)("div",{className:"flex items-center",children:["Partner",(0,re.jsx)(Xf.A,{className:"ml-2 h-4 w-4"})]})}),(0,re.jsx)(Br,{className:"cursor-pointer",onClick:()=>Y("city"),children:(0,re.jsxs)("div",{className:"flex items-center",children:["Location",(0,re.jsx)(Xf.A,{className:"ml-2 h-4 w-4"})]})}),(0,re.jsx)(Br,{className:"cursor-pointer",onClick:()=>Y("individual_or_team"),children:(0,re.jsxs)("div",{className:"flex items-center",children:["Type",(0,re.jsx)(Xf.A,{className:"ml-2 h-4 w-4"})]})}),(0,re.jsx)(Br,{children:"Services"}),(0,re.jsx)(Br,{children:"Languages"}),(0,re.jsx)(Br,{className:"cursor-pointer",onClick:()=>Y("status"),children:(0,re.jsxs)("div",{className:"flex items-center",children:["Status",(0,re.jsx)(Xf.A,{className:"ml-2 h-4 w-4"})]})}),(0,re.jsx)(Br,{className:"cursor-pointer w-40",onClick:()=>Y("created_date"),children:(0,re.jsxs)("div",{className:"flex items-center",children:["Created Date",(0,re.jsx)(Xf.A,{className:"ml-2 h-4 w-4"})]})}),(0,re.jsx)(Br,{children:"Actions"})]})}),(0,re.jsx)(Dr,{children:r?(0,re.jsx)(Fr,{children:(0,re.jsx)(Ur,{colSpan:9,className:"text-center py-8",children:"Loading partners..."})}):0===a.length?(0,re.jsx)(Fr,{children:(0,re.jsx)(Ur,{colSpan:9,className:"text-center py-8",children:"No partners found"})}):a.map(e=>(0,re.jsxs)(re.Fragment,{children:[(0,re.jsxs)(Fr,{className:"hover:bg-gray-50/80 transition-colors duration-200 group h-12",children:[(0,re.jsx)(Ur,{className:"py-2",children:(0,re.jsx)(Hs,{variant:"ghost",size:"sm",onClick:()=>{return s=e.item.id,void I(e=>{const t=new Set(e);return t.has(s)?t.delete(s):t.add(s),t});var s},className:"h-6 w-6 p-0 rounded hover:bg-gray-100 transition-all duration-200 group",children:E.has(e.item.id)?(0,re.jsx)(It.A,{className:"h-3 w-3 text-gray-600 group-hover:text-gray-900 transition-colors"}):(0,re.jsx)(ln.A,{className:"h-3 w-3 text-gray-600 group-hover:text-gray-900 transition-colors"})})}),(0,re.jsx)(Ur,{className:"font-medium py-2 text-sm",children:(0,re.jsxs)("div",{className:"flex items-center gap-3",children:[e.item.logo_url&&""!==e.item.logo_url.trim()?(0,re.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,re.jsx)(fv.A,{className:"h-8 w-8 text-gray-400 p-1 border border-gray-200 rounded-full bg-gray-50"}),(0,re.jsxs)("div",{children:[(0,re.jsx)("div",{className:"font-medium text-gray-900",children:e.item.name}),(0,re.jsxs)("div",{className:"flex items-center gap-2 mt-0.5",children:[e.item.website_url&&(0,re.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,re.jsx)(bn.A,{className:"h-3 w-3"}),"Website"]}),e.item.linkedin_url&&(0,re.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,re.jsx)(Wa.A,{className:"h-3 w-3"}),"LinkedIn"]})]})]})]})}),(0,re.jsx)(Ur,{className:"py-2",children:(0,re.jsxs)("div",{className:"flex items-center gap-1 text-sm text-gray-600",children:[(0,re.jsx)(mw.A,{className:"h-3.5 w-3.5"}),e.item.city,", ",LN(e.item.country)]})}),(0,re.jsx)(Ur,{className:"py-2",children:(0,re.jsx)("div",{className:"flex items-center gap-1 text-sm",children:"individual"===e.item.individual_or_team?(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(np.A,{className:"h-3.5 w-3.5 text-gray-400"}),(0,re.jsx)("span",{className:"text-gray-600",children:"Individual"})]}):(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(Gr.A,{className:"h-3.5 w-3.5 text-gray-400"}),(0,re.jsx)("span",{className:"text-gray-600",children:"Team"})]})})}),(0,re.jsx)(Ur,{className:"py-2",children:(0,re.jsx)("div",{className:"text-sm text-gray-600",children:e.item.services&&e.item.services.length>0?(0,re.jsxs)("div",{className:"flex flex-wrap gap-1",children:[e.item.services.slice(0,2).map((s,t)=>(0,re.jsx)("span",{className:"inline-block px-2 py-1 text-xs bg-gray-100 text-gray-700 rounded-md",children:"Other"===s&&e.item.other_service_description?"Other: ".concat(e.item.other_service_description.substring(0,20),"..."):s},t)),e.item.services.length>2&&(0,re.jsxs)("span",{className:"text-xs text-gray-500",children:["+",e.item.services.length-2]})]}):(0,re.jsx)("span",{className:"text-gray-400 text-xs",children:"No services"})})}),(0,re.jsx)(Ur,{className:"py-2",children:(0,re.jsx)("div",{className:"text-sm text-gray-600",children:e.item.languages&&e.item.languages.length>0?(0,re.jsxs)("div",{className:"flex flex-wrap gap-1",children:[xw(e.item.languages.slice(0,2)).map((e,s)=>(0,re.jsx)("span",{className:"inline-block px-2 py-1 text-xs bg-blue-100 text-blue-700 rounded-md",children:e},s)),e.item.languages.length>2&&(0,re.jsxs)("span",{className:"text-xs text-gray-500",children:["+",e.item.languages.length-2]})]}):(0,re.jsx)("span",{className:"text-gray-400 text-xs",children:"No languages"})})}),(0,re.jsxs)(Ur,{className:"py-2",children:[$(e.item.status),"rejected"===e.item.status&&e.item.rejected_reason&&(0,re.jsx)("div",{className:"mt-1 text-xs text-red-600 max-w-xs truncate",children:e.item.rejected_reason})]}),(0,re.jsx)(Ur,{className:"py-2 w-40",children:la().utc(e.item.created_date).fromNow()}),(0,re.jsx)(Ur,{className:"py-2",children:(0,re.jsxs)("div",{className:"flex items-center gap-2",children:["pending"===e.item.status&&(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(Hs,{size:"sm",variant:"ghost",onClick:s=>{s.stopPropagation(),W(e)},disabled:S[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,re.jsx)(Hs,{size:"sm",variant:"ghost",onClick:s=>{s.stopPropagation(),V(e)},disabled:S[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,re.jsx)(Hs,{size:"sm",variant:"ghost",onClick:s=>{s.stopPropagation(),W(e)},disabled:S[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,re.jsx)(Hs,{size:"sm",variant:"ghost",onClick:s=>{s.stopPropagation(),V(e)},disabled:S[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,re.jsx)(Hs,{size:"sm",variant:"ghost",onClick:s=>{s.stopPropagation(),(async e=>{const s=e.item.id;C(e=>(0,K.A)((0,K.A)({},e),{},{[s]:!0}));try{await nw.archiveItem(s),an({title:"Success",description:"".concat(e.item.name," has been archived")}),await q()}catch(t){an({title:"Error",description:"Failed to archive partner",variant:"destructive"})}finally{C(e=>(0,K.A)((0,K.A)({},e),{},{[s]:!1}))}})(e)},disabled:S[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),E.has(e.item.id)&&(0,re.jsx)(Fr,{children:(0,re.jsx)(Ur,{colSpan:9,className:"bg-gradient-to-br from-gray-50 to-gray-100/50 p-8 border-t border-gray-100",children:(0,re.jsxs)("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-8",children:[(0,re.jsxs)("div",{className:"space-y-6",children:[(0,re.jsxs)("div",{className:"bg-white p-4 rounded-lg border border-gray-200",children:[(0,re.jsxs)("h4",{className:"font-semibold text-gray-900 mb-3 flex items-center gap-2",children:[(0,re.jsx)("div",{className:"w-1 h-5 bg-blue-500 rounded-full"}),"Description"]}),(0,re.jsx)("div",{className:"text-sm text-gray-600",children:e.item.description||(0,re.jsx)("span",{className:"text-gray-400 italic",children:"No description available"})})]}),(0,re.jsxs)("div",{className:"bg-white p-4 rounded-lg border border-gray-200",children:[(0,re.jsxs)("h4",{className:"font-semibold text-gray-900 mb-3 flex items-center gap-2",children:[(0,re.jsx)("div",{className:"w-1 h-5 bg-green-500 rounded-full"}),"Services & Pricing"]}),(0,re.jsxs)("div",{className:"space-y-3",children:[e.item.services&&e.item.services.length>0&&(0,re.jsxs)("div",{children:[(0,re.jsx)("span",{className:"font-medium text-gray-700 text-sm",children:"Services:"}),(0,re.jsx)("div",{className:"flex flex-wrap gap-2 mt-2",children:e.item.services.map((s,t)=>(0,re.jsx)(et,{className:"bg-blue-50 text-blue-700 border-blue-200",children:"Other"===s&&e.item.other_service_description?"Other: ".concat(e.item.other_service_description):s},t))})]}),(e.item.budget_starting_from_dollars||e.item.hourly_rate)&&(0,re.jsxs)("div",{children:[(0,re.jsx)("span",{className:"font-medium text-gray-700 text-sm",children:"Pricing:"}),(0,re.jsxs)("div",{className:"mt-2 space-y-1",children:[e.item.budget_starting_from_dollars&&(0,re.jsxs)("div",{className:"flex items-center gap-1 text-sm text-gray-600",children:[(0,re.jsx)(uw.A,{className:"h-3.5 w-3.5"}),"Starting from $",e.item.budget_starting_from_dollars.toLocaleString()]}),e.item.hourly_rate&&(0,re.jsxs)("div",{className:"flex items-center gap-1 text-sm text-gray-600",children:[(0,re.jsx)(Xp.A,{className:"h-3.5 w-3.5"}),"$",e.item.hourly_rate,"/hour"]})]})]})]})]}),e.item.languages&&e.item.languages.length>0&&(0,re.jsxs)("div",{className:"bg-white p-4 rounded-lg border border-gray-200",children:[(0,re.jsxs)("h4",{className:"font-semibold text-gray-900 mb-3 flex items-center gap-2",children:[(0,re.jsx)("div",{className:"w-1 h-5 bg-purple-500 rounded-full"}),"Languages"]}),(0,re.jsx)("div",{className:"flex flex-wrap gap-2",children:xw(e.item.languages).map((e,s)=>(0,re.jsx)(et,{className:"bg-purple-50 text-purple-700 border-purple-200",children:e},s))})]})]}),(0,re.jsxs)("div",{className:"space-y-6",children:[(0,re.jsxs)("div",{className:"bg-white p-4 rounded-lg border border-gray-200",children:[(0,re.jsxs)("h4",{className:"font-semibold text-gray-900 mb-3 flex items-center gap-2",children:[(0,re.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,re.jsx)("div",{children:e.item.apps&&e.item.apps.length>0?(0,re.jsx)("div",{className:"space-y-3",children:e.item.apps.map((e,s)=>(0,re.jsxs)("div",{className:"flex items-center justify-between p-3 bg-gray-50 rounded-lg",children:[(0,re.jsx)("div",{children:(0,re.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,re.jsx)(jl.A,{className:"h-3.5 w-3.5"}),e.url.replace(/^https?:\/\//,"").split("/")[0]]})}),e.allow_public_showcase&&(0,re.jsx)(et,{className:"bg-green-100 text-green-700 text-xs",children:"Public Showcase"})]},s))}):(0,re.jsx)("p",{className:"text-sm text-gray-600",children:"No apps shared"})}):(0,re.jsx)("div",{className:"text-sm text-gray-600",children:e.item.no_apps_explanation||(0,re.jsx)("span",{className:"text-gray-400 italic",children:"No experience description provided"})})]}),(0,re.jsxs)("div",{className:"bg-white p-4 rounded-lg border border-gray-200",children:[(0,re.jsxs)("h4",{className:"font-semibold text-gray-900 mb-3 flex items-center gap-2",children:[(0,re.jsx)("div",{className:"w-1 h-5 bg-teal-500 rounded-full"}),"Terms & Conditions"]}),(0,re.jsx)("div",{className:"text-sm",children:e.item.terms_accepted?(0,re.jsxs)("div",{className:"flex items-center gap-2 text-green-700",children:[(0,re.jsx)(rp.A,{className:"h-4 w-4"}),(0,re.jsx)("span",{className:"font-medium",children:"Terms Accepted"}),e.item.terms_accepted_at&&(0,re.jsxs)("span",{className:"text-gray-500",children:["on ",new Date(e.item.terms_accepted_at).toLocaleDateString()]})]}):(0,re.jsxs)("div",{className:"flex items-center gap-2 text-red-600",children:[(0,re.jsx)(Xe.A,{className:"h-4 w-4"}),(0,re.jsx)("span",{className:"font-medium",children:"Terms Not Accepted"})]})})]}),"rejected"===e.item.status&&e.item.rejected_reason&&(0,re.jsxs)("div",{className:"bg-red-50 p-4 rounded-lg border border-red-200",children:[(0,re.jsxs)("h4",{className:"font-semibold text-red-900 mb-3 flex items-center gap-2",children:[(0,re.jsx)("div",{className:"w-1 h-5 bg-red-500 rounded-full"}),"Rejection Reason"]}),(0,re.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,re.jsxs)("div",{className:"flex items-center justify-between py-4",children:[(0,re.jsx)("div",{className:"flex items-center gap-2 text-sm text-gray-500",children:(0,re.jsxs)("span",{children:["Showing ",(b-1)*R+1," to ",Math.min(b*R,y)," of ",y," items"]})}),(0,re.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,re.jsx)(Hs,{variant:"outline",size:"sm",onClick:()=>j(e=>Math.max(e-1,1)),disabled:1===b||r,className:"h-8 px-3",children:"Previous"}),(0,re.jsxs)("div",{className:"flex items-center gap-1",children:[b>2&&(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(Hs,{variant:"outline",size:"sm",onClick:()=>j(1),className:"h-8 w-8 p-0",children:"1"}),b>3&&(0,re.jsx)("span",{className:"px-1 text-gray-400",children:"..."})]}),b>1&&(0,re.jsx)(Hs,{variant:"outline",size:"sm",onClick:()=>j(e=>e-1),className:"h-8 w-8 p-0",children:b-1}),(0,re.jsx)(Hs,{variant:"default",size:"sm",className:"h-8 w-8 p-0",children:b}),a.length===R&&(0,re.jsx)(Hs,{variant:"outline",size:"sm",onClick:()=>j(e=>e+1),disabled:r,className:"h-8 w-8 p-0",children:b+1})]}),(0,re.jsx)(Hs,{variant:"outline",size:"sm",onClick:()=>j(e=>e+1),disabled:a.lengthg(e.target.value),className:"mt-2 min-h-[100px]"})]}),(0,re.jsx)("div",{className:"p-3 bg-amber-50 border border-amber-200 rounded-lg",children:(0,re.jsxs)("div",{className:"flex gap-2",children:[(0,re.jsx)(Xe.A,{className:"h-4 w-4 text-amber-600 mt-0.5 flex-shrink-0"}),(0,re.jsx)("p",{className:"text-sm text-amber-800",children:"This action will mark the partner as rejected and they will need to reapply."})]})})]}),(0,re.jsxs)(Ba,{children:[(0,re.jsx)(Hs,{variant:"outline",onClick:()=>h(!1),children:"Cancel"}),(0,re.jsx)(Hs,{variant:"destructive",onClick:async()=>{if(!m)return;const e=m.item.id;C(s=>(0,K.A)((0,K.A)({},s),{},{[e]:!0})),h(!1);try{await nw.declineItem(e,p),an({title:"Partner Rejected",description:"".concat(m.item.name," has been rejected")}),await q()}catch(s){an({title:"Error",description:"Failed to reject partner",variant:"destructive"})}finally{C(s=>(0,K.A)((0,K.A)({},s),{},{[e]:!1}))}},disabled:S[null==m?void 0:m.item.id],children:"Reject Partner"})]})]})})]})}function pw(){const[e,s]=(0,H.useState)([]),[t,a]=(0,H.useState)(!0),[n,r]=(0,H.useState)(""),[l,i]=(0,H.useState)(null),[o,c]=(0,H.useState)(!1),[d,m]=(0,H.useState)(0),[u,x]=(0,H.useState)(1),[h,p]=(0,H.useState)({key:"created_date",direction:"desc"}),[g,f]=(0,H.useState)(null),[v,b]=(0,H.useState)("all"),[j,y]=(0,H.useState)("all"),N=25;(0,H.useEffect)(()=>{if(g&&clearTimeout(g),1===u)return f(setTimeout(()=>{w()},500)),()=>{g&&clearTimeout(g)};x(1)},[n,v,j,h]),(0,H.useEffect)(()=>{w()},[u]);const w=async()=>{try{var e;a(!0);let t={skip:(u-1)*N,limit:N,sort_by:"desc"===h.direction?"-".concat(h.key):h.key};n&&(t.search=n),"all"!==v&&(t.project_type=v),"all"!==j&&(t.work_basis=j);const r=await nw.getAllContactRequests(t);s(r.items||[]),m(r.total||(null===(e=r.items)||void 0===e?void 0:e.length)||0)}catch(t){an({title:"Error",description:"Failed to load contact requests",variant:"destructive"})}finally{a(!1)}},_=e=>{const s=h.key===e&&"asc"===h.direction?"desc":"asc";p({key:e,direction:s}),x(1)},k=()=>"all"!==v||"all"!==j||""!==n,A=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}},S=e=>"hourly"===e?"Hourly Rate":"Fixed Price",C=e=>"new_project"===e?"New Project":"Existing Project";return(0,re.jsxs)(re.Fragment,{children:[(0,re.jsxs)("div",{className:"mb-8 space-y-4",children:[(0,re.jsx)("div",{className:"bg-white p-4 rounded-xl border border-gray-100 shadow-sm",children:(0,re.jsxs)("div",{className:"flex flex-col lg:flex-row gap-3 items-start lg:items-center justify-between",children:[(0,re.jsxs)("div",{className:"flex flex-col sm:flex-row gap-3 items-start sm:items-center flex-1",children:[(0,re.jsxs)("div",{className:"relative w-full sm:w-80",children:[(0,re.jsx)(vn.A,{className:"absolute left-3 top-2.5 h-4 w-4 text-gray-400"}),(0,re.jsx)(ft,{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=>r(e.target.value)})]}),(0,re.jsxs)(Ut,{value:v,onValueChange:b,children:[(0,re.jsx)(Wt,{className:"w-36 h-9 border-gray-200 hover:border-gray-300 transition-colors",children:(0,re.jsxs)("div",{className:"flex items-center gap-2",children:[(0,re.jsx)(dw.A,{className:"h-3.5 w-3.5 text-gray-400"}),(0,re.jsx)(qt,{placeholder:"Project"})]})}),(0,re.jsxs)(Ht,{children:[(0,re.jsx)($t,{value:"all",children:"All Projects"}),(0,re.jsx)($t,{value:"new_project",children:"New Project"}),(0,re.jsx)($t,{value:"existing_project",children:"Existing Project"})]})]}),(0,re.jsxs)(Ut,{value:j,onValueChange:y,children:[(0,re.jsx)(Wt,{className:"w-36 h-9 border-gray-200 hover:border-gray-300 transition-colors",children:(0,re.jsxs)("div",{className:"flex items-center gap-2",children:[(0,re.jsx)(uw.A,{className:"h-3.5 w-3.5 text-gray-400"}),(0,re.jsx)(qt,{placeholder:"Pricing"})]})}),(0,re.jsxs)(Ht,{children:[(0,re.jsx)($t,{value:"all",children:"All Pricing"}),(0,re.jsx)($t,{value:"hourly",children:"Hourly Rate"}),(0,re.jsx)($t,{value:"fixed",children:"Fixed Price"})]})]}),k()&&(0,re.jsxs)(Hs,{variant:"outline",size:"sm",onClick:()=>{b("all"),y("all"),r(""),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,re.jsx)(zs.A,{className:"h-3.5 w-3.5 mr-1"}),"Clear"]})]}),(0,re.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,re.jsx)(oh.A,{className:"h-3.5 w-3.5"}),d>0?"".concat(d," total requests"):"".concat(e.length," requests")]})]})}),k()&&(0,re.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,re.jsxs)("span",{className:"text-sm font-medium text-gray-700 flex items-center gap-1",children:[(0,re.jsx)(Sg.A,{className:"h-3.5 w-3.5"}),"Active filters:"]}),"all"!==v&&(0,re.jsxs)(et,{className:"bg-blue-100 text-blue-800 hover:bg-blue-200 transition-colors",children:["Type: ","new_project"===v?"New Project":"Existing Project",(0,re.jsx)("button",{onClick:()=>b("all"),className:"ml-1 hover:bg-blue-300 rounded-full p-0.5 transition-colors",children:(0,re.jsx)(zs.A,{className:"h-3 w-3"})})]}),"all"!==j&&(0,re.jsxs)(et,{className:"bg-teal-100 text-teal-800 hover:bg-teal-200 transition-colors",children:["Pricing: ","hourly"===j?"Hourly Rate":"Fixed Price",(0,re.jsx)("button",{onClick:()=>y("all"),className:"ml-1 hover:bg-teal-300 rounded-full p-0.5 transition-colors",children:(0,re.jsx)(zs.A,{className:"h-3 w-3"})})]}),n&&(0,re.jsxs)(et,{className:"bg-green-100 text-green-800 hover:bg-green-200 transition-colors",children:['Search: "',n,'"',(0,re.jsx)("button",{onClick:()=>r(""),className:"ml-1 hover:bg-green-300 rounded-full p-0.5 transition-colors",children:(0,re.jsx)(zs.A,{className:"h-3 w-3"})})]})]})]}),(0,re.jsx)("div",{className:"bg-white rounded-xl border border-gray-200 shadow-sm overflow-hidden",children:(0,re.jsxs)(Or,{children:[(0,re.jsx)(Rr,{children:(0,re.jsxs)(Fr,{children:[(0,re.jsx)(Br,{className:"cursor-pointer",onClick:()=>_("client_name"),children:(0,re.jsxs)("div",{className:"flex items-center",children:["Client",(0,re.jsx)(Xf.A,{className:"ml-2 h-4 w-4"})]})}),(0,re.jsx)(Br,{className:"cursor-pointer",onClick:()=>_("partner_name"),children:(0,re.jsxs)("div",{className:"flex items-center",children:["Partner",(0,re.jsx)(Xf.A,{className:"ml-2 h-4 w-4"})]})}),(0,re.jsx)(Br,{children:"Project Description"}),(0,re.jsx)(Br,{className:"cursor-pointer",onClick:()=>_("project_type"),children:(0,re.jsxs)("div",{className:"flex items-center",children:["Type",(0,re.jsx)(Xf.A,{className:"ml-2 h-4 w-4"})]})}),(0,re.jsx)(Br,{className:"cursor-pointer",onClick:()=>_("work_basis"),children:(0,re.jsxs)("div",{className:"flex items-center",children:["Pricing",(0,re.jsx)(Xf.A,{className:"ml-2 h-4 w-4"})]})}),(0,re.jsx)(Br,{className:"cursor-pointer",onClick:()=>_("start_date"),children:(0,re.jsxs)("div",{className:"flex items-center",children:["Start Date",(0,re.jsx)(Xf.A,{className:"ml-2 h-4 w-4"})]})}),(0,re.jsx)(Br,{className:"cursor-pointer w-40",onClick:()=>_("created_date"),children:(0,re.jsxs)("div",{className:"flex items-center",children:["Created",(0,re.jsx)(Xf.A,{className:"ml-2 h-4 w-4"})]})}),(0,re.jsx)(Br,{children:"Actions"})]})}),(0,re.jsx)(Dr,{children:t?(0,re.jsx)(Fr,{children:(0,re.jsx)(Ur,{colSpan:8,className:"text-center py-8",children:"Loading contact requests..."})}):0===e.length?(0,re.jsx)(Fr,{children:(0,re.jsx)(Ur,{colSpan:8,className:"text-center py-8",children:"No contact requests found"})}):e.map(e=>{var s;return(0,re.jsxs)(Fr,{className:"hover:bg-gray-50/80 transition-colors duration-200",children:[(0,re.jsx)(Ur,{className:"font-medium py-2 text-sm",children:(0,re.jsxs)("div",{children:[(0,re.jsx)("div",{className:"font-medium text-gray-900",children:e.client_name}),(0,re.jsxs)("div",{className:"flex items-center gap-1 mt-0.5 text-xs text-gray-500",children:[(0,re.jsx)(Im.A,{className:"h-3 w-3"}),e.client_email]}),(0,re.jsxs)("div",{className:"flex items-center gap-1 mt-0.5 text-xs text-gray-500",children:[(0,re.jsx)(np.A,{className:"h-3 w-3"}),"Account: ",e.requester_email]})]})}),(0,re.jsx)(Ur,{className:"py-2 text-sm",children:(0,re.jsxs)("div",{className:"flex items-center gap-1 text-gray-700",children:[(0,re.jsx)(fv.A,{className:"h-3.5 w-3.5 text-gray-400"}),e.partner_name]})}),(0,re.jsx)(Ur,{className:"py-2 text-sm max-w-xs",children:(0,re.jsx)("div",{className:"truncate text-gray-600",title:e.project_description,children:(null===(s=e.project_description)||void 0===s?void 0:s.length)>100?"".concat(e.project_description.substring(0,100),"..."):e.project_description})}),(0,re.jsx)(Ur,{className:"py-2",children:(0,re.jsx)(et,{variant:"outline",className:"text-xs",children:C(e.project_type)})}),(0,re.jsx)(Ur,{className:"py-2",children:(0,re.jsx)(et,{variant:"outline",className:"text-xs",children:S(e.work_basis)})}),(0,re.jsx)(Ur,{className:"py-2 text-sm text-gray-600",children:(0,re.jsxs)("div",{className:"flex items-center gap-1",children:[(0,re.jsx)(im.A,{className:"h-3 w-3"}),A(e.start_date)]})}),(0,re.jsx)(Ur,{className:"py-2 w-40 text-sm text-gray-500",children:la().utc(e.created_date).fromNow()}),(0,re.jsx)(Ur,{className:"py-2",children:(0,re.jsxs)(Hs,{size:"sm",variant:"outline",onClick:()=>(e=>{i(e),c(!0)})(e),className:"h-7 text-xs",children:["View Details",(0,re.jsx)(ln.A,{className:"h-3 w-3 ml-1"})]})})]},e.id)})})]})}),e.length>0&&(0,re.jsxs)("div",{className:"flex items-center justify-between py-4",children:[(0,re.jsx)("div",{className:"flex items-center gap-2 text-sm text-gray-500",children:(0,re.jsxs)("span",{children:["Showing ",(u-1)*N+1," to ",Math.min(u*N,d)," of ",d," items"]})}),(0,re.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,re.jsx)(Hs,{variant:"outline",size:"sm",onClick:()=>x(e=>Math.max(e-1,1)),disabled:1===u||t,className:"h-8 px-3",children:"Previous"}),(0,re.jsxs)("div",{className:"flex items-center gap-1",children:[u>2&&(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(Hs,{variant:"outline",size:"sm",onClick:()=>x(1),className:"h-8 w-8 p-0",children:"1"}),u>3&&(0,re.jsx)("span",{className:"px-1 text-gray-400",children:"..."})]}),u>1&&(0,re.jsx)(Hs,{variant:"outline",size:"sm",onClick:()=>x(e=>e-1),className:"h-8 w-8 p-0",children:u-1}),(0,re.jsx)(Hs,{variant:"default",size:"sm",className:"h-8 w-8 p-0",children:u}),e.length===N&&(0,re.jsx)(Hs,{variant:"outline",size:"sm",onClick:()=>x(e=>e+1),disabled:t,className:"h-8 w-8 p-0",children:u+1})]}),(0,re.jsx)(Hs,{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},s={cta:"Apply here",origin:"partner_catalog_hero",target_route:null,section:"catalog_header"};Ie("User clicked apply as partner",(0,K.A)((0,K.A)({},e),s)),We(e,s),t()},className:"text-base font-medium text-orange-500 leading-loose hover:text-orange-600 transition-colors whitespace-nowrap",children:"Apply here"})]})]})})]})}function vw(e){let{title:s,onApply:t,onClearAll:a,onClearAndApply:n,children:r,width:l="w-80"}=e;return(0,re.jsxs)("div",{className:"".concat(l," flex flex-col gap-2"),children:[(0,re.jsx)("div",{className:"p-4",children:(0,re.jsx)(uu,{className:"text-xs font-medium text-slate-500 tracking-wide block",children:s})}),(0,re.jsx)("div",{className:"px-4",children:r}),(0,re.jsx)("div",{className:"border-t border-slate-200 px-4 py-4",children:(0,re.jsxs)("div",{className:"flex justify-between items-center",children:[(0,re.jsx)(Yn,{variant:"ghost",size:"sm",onClick:n,className:"text-slate-500 hover:text-slate-700 hover:bg-transparent px-0",children:"Clear All"}),(0,re.jsx)(Yn,{onClick:t,className:"px-6",size:"sm",children:"Apply"})]})})]})}const bw=["Application Development","Mobile Development","UI/UX Design","AI Specialist","Security Specialist","API & Integrations","Strategic consulting","QA & Testing","Other"];function jw(e){let{onApply:s,initialServices:t=[],onClose:a}=e;const[n,r]=(0,H.useState)(t);(0,H.useEffect)(()=>{r(t)},[t]);return(0,re.jsx)(vw,{title:"Services",onApply:()=>{s(n)},onClearAll:()=>{r([])},onClearAndApply:()=>{r([]),s([]),null==a||a()},children:(0,re.jsx)("div",{className:"space-y-3 max-h-64 overflow-y-auto",children:bw.map(e=>(0,re.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,re.jsx)(Yu,{id:e,checked:n.includes(e),onCheckedChange:()=>(e=>{n.includes(e)?r(n.filter(s=>s!==e)):r([...n,e])})(e)}),(0,re.jsx)("label",{htmlFor:e,className:"text-sm text-slate-700 cursor-pointer select-none flex-1",children:e})]},e))})})}function yw(e){let{onApply:s,initialLanguages:t=[],onClose:a}=e;const[n,r]=(0,H.useState)(t);(0,H.useEffect)(()=>{r(t)},[t]);return(0,re.jsx)(vw,{title:"Language",onApply:()=>{s(n)},onClearAll:()=>{r([])},onClearAndApply:()=>{r([]),s([]),null==a||a()},children:(0,re.jsx)("div",{className:"grid grid-cols-2 gap-x-4 gap-y-3 max-h-64 overflow-y-auto",children:TN.map(e=>(0,re.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,re.jsx)(Yu,{id:e.value,checked:n.includes(e.value),onCheckedChange:()=>{return s=e.value,void(n.includes(s)?r(n.filter(e=>e!==s)):r([...n,s]));var s}}),(0,re.jsx)("label",{htmlFor:e.value,className:"text-sm text-slate-700 cursor-pointer select-none flex-1",children:e.label})]},e.value))})})}function Nw(e){let{selectedServices:s,onServicesChange:t,budgetRange:a,onBudgetRangeChange:n,selectedLanguages:r,onLanguagesChange:l,onBudgetApply:i,onServicesApply:o,onLanguagesApply:c}=e;const[d,m]=(0,H.useState)(!1),[u,x]=(0,H.useState)(!1);return(0,re.jsx)("div",{className:"w-full bg-white border-t border-b border-slate-200 font-base44",children:(0,re.jsx)("div",{className:"max-w-7xl mx-auto px-6 lg:px-8 py-6 flex justify-between items-center",children:(0,re.jsx)("div",{className:"flex justify-end items-center gap-6",children:(0,re.jsxs)("div",{className:"flex justify-start items-center gap-10",children:[(0,re.jsxs)(Mx,{open:d,onOpenChange:m,children:[(0,re.jsx)(Fx,{asChild:!0,children:(0,re.jsxs)(Yn,{variant:"ghost",className:"flex justify-end items-center gap-1 p-0 h-auto hover:bg-transparent",children:[(0,re.jsx)("span",{className:"text-black text-sm font-normal",children:"Service"}),(0,re.jsx)(It.A,{className:"w-4 h-4 text-zinc-500"})]})}),(0,re.jsx)(Bx,{className:"w-auto p-0",align:"start",children:(0,re.jsx)(jw,{onApply:e=>{o(e),m(!1)},initialServices:s,onClose:()=>m(!1)})})]}),(0,re.jsxs)(Mx,{open:u,onOpenChange:x,children:[(0,re.jsx)(Fx,{asChild:!0,children:(0,re.jsxs)(Yn,{variant:"ghost",className:"flex justify-end items-center gap-1 p-0 h-auto hover:bg-transparent",children:[(0,re.jsx)("span",{className:"text-black text-sm font-normal",children:"Language"}),(0,re.jsx)(It.A,{className:"w-4 h-4 text-zinc-500"})]})}),(0,re.jsx)(Bx,{className:"w-auto p-0",align:"start",children:(0,re.jsx)(yw,{onApply:e=>{c(e),x(!1)},initialLanguages:r,onClose:()=>x(!1)})})]})]})})})})}function ww(e){if(!e)return null;const s="string"==typeof e?Number(e):e;if(isNaN(s)||s<=0)return null;if(s>=1e3){const e=s/1e3;return"From $".concat(e%1==0?e.toFixed(0):e.toFixed(1),"K")}return"From $".concat(s)}function _w(e){if(!e)return null;const s="string"==typeof e?Number(e):e;if(isNaN(s)||s<=0)return null;if(s>=1e3){const e=s/1e3;return"$".concat(e%1==0?e.toFixed(0):e.toFixed(1),"K/hr")}return"$".concat(s,"/hr")}function kw(e){if(!e)return null;try{return new URL(e).hostname.replace(/^www\./,"")}catch(s){return e}}const Aw=function(e){var s,t;let{partner:a,onContactClick:n}=e;const{item:r}=a,{user:l}=oe(),[i,o]=(0,H.useState)(!1),c=(0,H.useRef)(null),d=Array.isArray(r.services)?r.services.slice(0,4):[],m=Array.isArray(r.services)&&r.services.length>4?r.services.length-4:0;(0,H.useEffect)(()=>{const e=e=>{c.current&&!c.current.contains(e.target)&&o(!1)},s=e=>{c.current&&!c.current.contains(e.relatedTarget)&&o(!1)};return i&&(document.addEventListener("mousedown",e),document.addEventListener("focusout",s)),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("focusout",s)}},[i]);const u=e=>{o(!i)};return(0,re.jsx)("div",{ref:c,className:"group cursor-pointer h-full",onClick:u,children:(0,re.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,re.jsxs)("div",{className:"p-5 flex-1 flex flex-col",children:[(0,re.jsxs)("div",{className:"flex flex-col",children:[(0,re.jsxs)("div",{className:"flex items-start gap-3",children:[(0,re.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:r.logo_url?(0,re.jsx)("img",{src:r.logo_url,alt:r.name||"Partner",className:"w-full h-full object-contain"}):(0,re.jsx)("span",{className:"text-2xl font-light text-slate-400",children:null===(s=r.name)||void 0===s?void 0:s.charAt(0).toUpperCase()})}),(0,re.jsx)("div",{className:"flex-1 min-w-0",children:(0,re.jsxs)("div",{className:"flex flex-col min-w-0 space-y-2",children:[(0,re.jsx)("h3",{className:"text-gray-900 text-base font-semibold font-base44 leading-4 truncate",children:r.name}),(r.city||r.country)&&(0,re.jsx)(Og,{children:(0,re.jsxs)(Rg,{children:[(0,re.jsx)(Dg,{asChild:!0,children:(0,re.jsx)("div",{className:"text-gray-500 text-sm font-normal font-base44 leading-4 truncate",children:[r.city,r.country?LN(r.country):null].filter(Boolean).join(", ")})}),(0,re.jsx)(Mg,{children:(0,re.jsx)("p",{children:[r.city,r.country?LN(r.country):null].filter(Boolean).join(", ")})})]})}),(r.website_url||r.linkedin_url)&&(0,re.jsxs)("div",{className:"flex items-center gap-3 min-w-0",children:[r.website_url&&(0,re.jsx)("a",{href:r.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,re.jsxs)("div",{className:"inline-flex justify-start items-start gap-1",children:[(0,re.jsx)("div",{className:"justify-start text-sm font-normal font-base44 leading-4 truncate max-w-32",children:kw(r.website_url)}),(0,re.jsx)("div",{"data-filled":"False","data-size":"Small",className:"flex justify-start items-start",children:(0,re.jsx)("div",{className:"w-4 h-4 relative",children:(0,re.jsx)(jl.A,{className:"w-4 h-4 absolute "})})})]})}),r.linkedin_url&&(0,re.jsx)("a",{href:r.linkedin_url,target:"_blank",rel:"noopener noreferrer",onClick:e=>e.stopPropagation(),children:(0,re.jsx)("div",{className:"justify-start text-blue-500 text-sm hover:text-blue-400 font-normal leading-4",children:"LinkedIn"})})]})]})})]}),d.length>0&&(0,re.jsxs)("div",{className:"mt-4 flex flex-wrap gap-1.5",children:[null===(t=i?r.services:d)||void 0===t?void 0:t.map(e=>(0,re.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,re.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]})]}),r.description&&(0,re.jsx)("div",{className:"mt-4 cursor-pointer",onClick:e=>{e.stopPropagation(),u()},children:(0,re.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:r.description})}),r.languages&&r.languages.length>0&&(0,re.jsxs)("div",{className:"mt-4 text-[15px] text-slate-500",children:[(0,re.jsx)("span",{className:"text-slate-500",children:"Languages:"})," ",(0,re.jsx)("span",{className:"text-slate-900",children:(x=r.languages,xw(x).join(", "))})]})]}),(0,re.jsx)("div",{className:"flex-1"})]}),(0,re.jsxs)("div",{className:"flex flex-wrap items-center gap-4 border-t border-slate-200 px-5 py-5 flex-shrink-0",children:[(0,re.jsxs)("div",{className:"flex flex-wrap items-center gap-3 text-[15px] flex-1 min-w-0",children:[ww(r.budget_starting_from_dollars)&&(0,re.jsxs)("div",{className:"flex items-center gap-2 text-slate-600 whitespace-nowrap",children:[(0,re.jsx)(uw.A,{className:"h-4 w-4 text-slate-400"}),(0,re.jsx)("span",{children:ww(r.budget_starting_from_dollars)})]}),_w(r.hourly_rate)&&(0,re.jsxs)("div",{className:"flex items-center gap-2 text-slate-600 whitespace-nowrap",children:[(0,re.jsx)(Xp.A,{className:"h-4 w-4 text-slate-400"}),(0,re.jsx)("span",{children:_w(r.hourly_rate)})]})]}),(0,re.jsxs)(Yn,{onClick:e=>{e.stopPropagation();const s={user_id:(null==l?void 0:l.id)||null,app_id:null,conversation_id:null},t={cta:"Contact",origin:"partner_card",target_route:null,partner_id:r.id,partner_name:r.name||null,partner_services:r.services||[],partner_country:r.country||null};Ie("User clicked contact partner",(0,K.A)((0,K.A)({},s),t)),We(s,t),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,re.jsx)(ha.A,{className:"h-3.5 w-3.5 ml-2"})]})]})]})});var x};function Sw(e){let{isLoading:s,isLoadingMore:t,partners:a,onContactClick:n,onBecomePartnerClick:r,hasMore:l,targetRef:i}=e;return s?(0,re.jsx)("div",{className:"flex justify-center items-center py-32",children:(0,re.jsxs)("div",{className:"flex flex-col items-center gap-3",children:[(0,re.jsx)("div",{className:"w-8 h-8 border-2 border-slate-200 border-t-slate-600 rounded-full animate-spin"}),(0,re.jsx)("p",{className:"text-sm text-slate-500",children:"Loading partners..."})]})}):s||0!==a.length?(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)("div",{className:"grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-6",children:a.map(e=>(0,re.jsx)(Aw,{partner:e,onContactClick:()=>n(e)},e.item.id))}),l&&(0,re.jsx)("div",{ref:i,className:"flex justify-center items-center py-12",children:t&&(0,re.jsxs)("div",{className:"flex items-center gap-3",children:[(0,re.jsx)("div",{className:"w-5 h-5 border-2 border-slate-200 border-t-slate-600 rounded-full animate-spin"}),(0,re.jsx)("span",{className:"text-sm text-slate-500",children:"Loading more..."})]})})]}):(0,re.jsx)("div",{className:"text-center py-32",children:(0,re.jsxs)("div",{className:"max-w-sm mx-auto",children:[(0,re.jsx)("div",{className:"w-16 h-16 bg-slate-100 rounded-full flex items-center justify-center mx-auto mb-4",children:(0,re.jsx)("svg",{className:"w-8 h-8 text-slate-400",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,re.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,re.jsx)("h3",{className:"text-lg font-medium text-slate-900 mb-2",children:"No partners found"}),(0,re.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."}),r&&(0,re.jsxs)("div",{className:"pt-6 border-t border-slate-100",children:[(0,re.jsx)("p",{className:"text-sm text-slate-600 mb-3",children:"Are you a developer or agency?"}),(0,re.jsxs)(Yn,{variant:"outline",size:"sm",onClick:r,className:"border-slate-300",children:[(0,re.jsx)(Ss.A,{className:"h-4 w-4 mr-2"}),"Become a Partner"]})]})]})})}const Cw=e=>{let{label:s,options:t,selectedValue:a,onValueChange:n,error:r,className:l=""}=e;return(0,re.jsxs)("div",{className:"w-full flex flex-col justify-start items-start gap-1 ".concat(l),children:[(0,re.jsx)(uu,{className:"text-gray-700 text-sm font-medium font-base44 leading-tight",children:s}),(0,re.jsx)("div",{className:"w-full inline-flex justify-start items-start gap-3 mt-3",children:t.map(e=>(0,re.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,re.jsxs)("div",{className:"inline-flex flex-col justify-center items-center gap-0.5",children:[(0,re.jsx)("div",{className:"inline-flex justify-start items-center gap-2",children:(0,re.jsx)("span",{className:"text-center text-sm font-medium font-base44 leading-tight",children:e.label})}),(0,re.jsx)("div",{className:"text-center text-sm font-normal font-base44 leading-tight",children:e.description})]})},e.value))}),r&&(0,re.jsx)("p",{className:"text-sm text-red-500 mt-2",children:r})]})},Ew=e=>{let{label:s,helperText:t,selectedServices:a,onServiceToggle:n,error:r,className:l=""}=e;return(0,re.jsxs)("div",{className:"w-full flex flex-col justify-start items-start gap-2 ".concat(l),children:[(0,re.jsxs)("div",{className:"flex flex-col justify-start items-start gap-0.5",children:[(0,re.jsx)(uu,{className:"text-gray-700 text-sm font-medium font-base44 leading-tight",children:s}),t&&(0,re.jsx)("p",{className:"text-slate-500 text-sm font-normal font-base44 leading-tight",children:t})]}),(0,re.jsx)(ew,{options:IN,selectedOptions:a,onToggle:n}),r&&(0,re.jsx)("p",{className:"text-sm text-red-500 mt-1",children:r})]})},Iw=[{value:"new_project",label:"New project",description:"Start from scratch"},{value:"existing_project",label:"Existing project",description:"Update or improve current project"}],Tw=[{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"}],Pw=[{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"}],Lw=CN.Ik({project_type:CN.k5(["new_project","existing_project"],{required_error:"Please select a project type"}),project_description:CN.Yj().min(20,"Please provide at least 20 characters").max(1e3,"Description must be less than 1000 characters"),services:CN.YO(CN.Yj()).min(1,"Please select at least one service"),work_basis:CN.k5(["hourly","fixed_price"],{required_error:"Please select a work basis"}),start_date:CN.KC([CN.k5(["as_soon_as_possible","within_a_week","within_a_month","more_than_a_month"]),CN.eu("")]).refine(e=>""!==e,{message:"Please select a timeline"}),estimated_project_duration:CN.KC([CN.k5(["less_than_a_week","about_1_week","about_1_month","more_than_1_month","i_dont_know"]),CN.eu("")]).refine(e=>""!==e,{message:"Please select estimated project duration"}),client_name:CN.Yj().min(1,"Name is required").max(100,"Name must be less than 100 characters"),client_email:CN.Yj().min(1,"Email is required").email("Please enter a valid email address")}),Ow=Lw.pick({project_type:!0,project_description:!0,services:!0}),Rw=Lw.pick({work_basis:!0,start_date:!0,estimated_project_duration:!0}),Dw=Lw.pick({client_name:!0,client_email:!0}),Mw=Lw,Fw=e=>{const s={};return e.errors.forEach(e=>{const t=e.path.join(".");t&&(s[t]=e.message)}),s},Bw=e=>{let{formData:s,errors:t,onInputChange:a,onServiceToggle:n}=e;return(0,re.jsxs)("div",{className:"w-full p-6 bg-white flex flex-col justify-start items-start gap-6 overflow-hidden",children:[(0,re.jsx)(Cw,{label:"Project type",options:Iw,selectedValue:s.project_type,onValueChange:e=>a("project_type",e),error:t.project_type}),(0,re.jsxs)("div",{className:"w-full flex flex-col justify-start items-start gap-1",children:[(0,re.jsx)(uu,{htmlFor:"project_description",className:"text-gray-700 text-sm font-medium font-base44 leading-tight",children:"Project description"}),(0,re.jsx)(du,{id:"project_description",placeholder:"Describe your project goals, requirements, and any specific technologies needed\u2026",value:s.project_description,onChange:e=>a("project_description",e.target.value),className:"min-h-[120px] resize-none mt-3 ".concat(t.project_description?"border-red-500":"border-slate-200")}),t.project_description&&(0,re.jsx)("p",{className:"text-sm text-red-500 mt-2",children:t.project_description}),(0,re.jsxs)("p",{className:"text-sm text-slate-400 mt-1",children:[s.project_description.length," characters (minimum 20)"]})]}),(0,re.jsx)(Ew,{label:"What do you need help with?",selectedServices:s.services,onServiceToggle:n,error:t.services})]})},Uw=e=>{let{label:s,placeholder:t="",value:a,options:n,onValueChange:r,error:l,helperText:i,required:o=!1,tooltipText:c,className:d=""}=e;const m="w-full h-10 ".concat(l?"border-red-500":"border-slate-200"," ").concat(d);return(0,re.jsxs)("div",{className:"w-full space-y-2",children:[(0,re.jsxs)("div",{className:"flex items-center gap-1",children:[(0,re.jsxs)(uu,{className:"text-center justify-center text-gray-700 text-sm font-medium font-base44 leading-tight",children:[s,o&&(0,re.jsx)("span",{className:"text-red-500 ml-1",children:"*"})]}),c&&(0,re.jsxs)(Rg,{delayDuration:100,children:[(0,re.jsx)(Dg,{asChild:!0,children:(0,re.jsx)(jo.A,{className:"h-4 w-4 text-gray-600 hover:text-gray-900"})}),(0,re.jsx)(Mg,{className:"max-w-[240px] p-3 text-xs",children:(0,re.jsx)("p",{children:c})})]})]}),(0,re.jsxs)(In,{value:a,onValueChange:r,children:[(0,re.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,re.jsx)(Tn,{placeholder:t,className:"text-sm font-normal font-base44 leading-tight"})}),(0,re.jsx)(Rn,{className:"bg-white border border-slate-200 rounded-md shadow-lg",position:"popper",sideOffset:0,children:n.map(e=>(0,re.jsx)(Dn,{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,re.jsx)("div",{className:"flex-1 justify-start text-sm font-normal font-base44 leading-tight ",children:e.label})},e.value))})]}),l&&(0,re.jsx)("p",{className:"text-sm text-red-500 mt-2",children:l}),i&&!l&&(0,re.jsx)("p",{className:"text-xs text-slate-400 mt-2",children:i})]})},zw=e=>{let{formData:s,errors:t,onInputChange:a}=e;return(0,re.jsxs)("div",{className:"w-full p-6 bg-white flex flex-col justify-start items-start gap-6 overflow-hidden",children:[(0,re.jsx)(Cw,{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:s.work_basis,onValueChange:e=>a("work_basis",e),error:t.work_basis}),(0,re.jsx)(Uw,{label:"Preferred start time",placeholder:"Select start time",value:s.start_date,options:Tw,onValueChange:e=>a("start_date",e),error:t.start_date}),(0,re.jsx)(Uw,{label:"Estimated project duration",placeholder:"Select project duration",value:s.estimated_project_duration,options:Pw,onValueChange:e=>a("estimated_project_duration",e),error:t.estimated_project_duration})]})},qw=e=>{let{formData:s,errors:t,onInputChange:a}=e;return(0,re.jsxs)("div",{className:"w-full p-6 bg-white flex flex-col justify-start items-start gap-6 overflow-hidden",children:[(0,re.jsxs)("div",{className:"w-full flex flex-col justify-start items-start gap-1",children:[(0,re.jsx)(uu,{htmlFor:"client_name",className:"text-gray-700 text-sm font-medium font-base44 leading-tight",children:"Your Name"}),(0,re.jsx)(fn,{id:"client_name",type:"text",placeholder:"Full name",value:s.client_name,onChange:e=>a("client_name",e.target.value),className:"h-11 mt-3 ".concat(t.client_name?"border-red-500":"border-slate-200")}),t.client_name&&(0,re.jsx)("p",{className:"text-sm text-red-500 mt-2",children:t.client_name})]}),(0,re.jsxs)("div",{className:"w-full flex flex-col justify-start items-start gap-1",children:[(0,re.jsx)(uu,{htmlFor:"client_email",className:"text-gray-700 text-sm font-medium font-base44 leading-tight",children:"Email Address"}),(0,re.jsx)(fn,{id:"client_email",type:"email",placeholder:"your@email.com",value:s.client_email,onChange:e=>a("client_email",e.target.value),className:"h-11 mt-3 ".concat(t.client_email?"border-red-500":"border-slate-200")}),t.client_email&&(0,re.jsx)("p",{className:"text-sm text-red-500 mt-2",children:t.client_email}),(0,re.jsx)("p",{className:"text-xs text-slate-400 mt-2",children:"This email will be shared with the partner for communication"})]})]})},Ww=e=>{let{title:s,items:t,className:a=""}=e;const n=t.filter(e=>!1!==e.show);return(0,re.jsxs)("div",{className:"w-full flex flex-col gap-3 ".concat(a),children:[s&&(0,re.jsx)("div",{className:"w-full justify-center text-gray-700 text-sm font-medium font-base44 leading-tight",children:s}),(0,re.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,re.jsx)("div",{className:"w-full flex flex-col justify-start items-start gap-[3px]",children:n.map((e,s)=>(0,re.jsxs)("div",{className:"w-full py-[3px] flex flex-col sm:flex-row sm:items-start gap-1 sm:gap-0",children:[(0,re.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,re.jsx)("div",{className:"flex-1 justify-start text-gray-950 text-sm font-medium font-base44 leading-tight break-words",children:e.value})]},s))})})]})},Vw=e=>{let{formData:s,partner:t}=e;const a=[{label:"Partner",value:t.item.name||"Partner"},{label:"Project Type",value:(e=>"new_project"===e?"New Project":"Existing Project")(s.project_type)},{label:"Work Basis",value:(n=s.work_basis,"hourly"===n?"Hourly Rate":"Fixed Price")},{label:"Preferred start time",value:(e=>{const s=Tw.find(s=>s.value===e);return s?s.label:e})(s.start_date)},{label:"Estimated duration",value:(e=>{const s=Pw.find(s=>s.value===e);return s?s.label:e})(s.estimated_project_duration)},{label:"Contact",value:s.client_email},{label:"Services",value:s.services.join(", "),show:s.services.length>0},{label:"Description",value:s.project_description}];var n;return(0,re.jsxs)("div",{className:"w-full p-6 bg-white inline-flex flex-col justify-start items-start gap-3 overflow-hidden",children:[(0,re.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 ",t.item.name||"this partner",". After reviewing your project details, they'll get in touch with you by email."]}),(0,re.jsx)(Ww,{title:"Request summary",items:a})]})},Yw={project_type:"existing_project",project_description:"",services:[],work_basis:"hourly",start_date:"",estimated_project_duration:"",client_name:"",client_email:""},Hw=(e,s)=>{const[t,a]=(0,H.useState)((0,K.A)((0,K.A)({},Yw),{},{client_name:e||"",client_email:s||""})),[n,r]=(0,H.useState)({}),[l,i]=(0,H.useState)(!1),o=(e,s)=>{a(t=>(0,K.A)((0,K.A)({},t),{},{[e]:s})),n[e]&&r(s=>(0,K.A)((0,K.A)({},s),{},{[e]:null}))},c=()=>{a((0,K.A)((0,K.A)({},Yw),{},{client_name:e||"",client_email:s||""})),r({}),i(!1)};return{formData:t,errors:n,isSubmitting:l,handleInputChange:o,handleServiceToggle:e=>{const s=t.services.includes(e)?t.services.filter(s=>s!==e):[...t.services,e];o("services",s)},validateStep:e=>{let s;switch(e){case 0:s=(e=>{const s=Ow.safeParse(e);return s.success?{success:!0,errors:{}}:{success:!1,errors:Fw(s.error)}})(t);break;case 1:s=(e=>{const s=Rw.safeParse(e);return s.success?{success:!0,errors:{}}:{success:!1,errors:Fw(s.error)}})(t);break;case 2:s=(e=>{const s=Dw.safeParse(e);return s.success?{success:!0,errors:{}}:{success:!1,errors:Fw(s.error)}})(t);break;default:return!0}return r(s.errors),s.success},resetForm:c,handleSubmit:async e=>{const s=(e=>{const s=Mw.safeParse(e);return s.success?{success:!0,errors:{}}:{success:!1,errors:Fw(s.error)}})(t);if(!s.success)return r(s.errors),!1;i(!0);try{return await e(t),c(),!0}catch(a){return!1}finally{i(!1)}}}},Gw=e=>{let{isOpen:s,onClose:t,partner:a,onSubmit:n}=e;const{user:r}=oe(),[l,i]=(0,H.useState)(0),{formData:o,errors:c,isSubmitting:d,handleInputChange:m,handleServiceToggle:u,validateStep:x,resetForm:h,handleSubmit:p}=Hw(null==r?void 0:r.full_name,null==r?void 0:r.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(!s||!a)return null;const f=(0,re.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,re.jsxs)("div",{className:"text-center flex items-center",children:[(0,re.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,re.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,re.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,re.jsx)(AN,{"data-testid":"contact-request-wizard",steps:g,currentStep:l,title:"Contact ".concat(a.item.name||"Partner"),description:"We will share this information with the partner to enable communication.",onNext:()=>{x(l)&&i(e=>Math.min(e+1,g.length-1))},onPrevious:()=>{i(e=>Math.max(e-1,0))},onClose:()=>{d||(h(),i(0),t())},onSubmit:async()=>{await p(n)&&(i(0),t())},isNextDisabled:!1,isLoading:d,nextButtonText:"Next",submitButtonText:"Submit",className:"w-[640px] h-[600px]",banner:f,children:(0,re.jsx)("div",{"data-testid":"contact-request-step-content",children:(()=>{if(!a)return null;switch(l){case 0:return(0,re.jsx)(Bw,{formData:o,errors:c,onInputChange:m,onServiceToggle:u});case 1:return(0,re.jsx)(zw,{formData:o,errors:c,onInputChange:m});case 2:return(0,re.jsx)(qw,{formData:o,errors:c,onInputChange:m});case 3:return(0,re.jsx)(Vw,{formData:o,partner:a});default:return null}})()})})})};function $w(){oe();const[e,s]=(0,H.useState)([]),[t,a]=(0,H.useState)(!0),[n,r]=(0,H.useState)([]),[l,i]=(0,H.useState)("all"),[o,c]=(0,H.useState)([]),[d]=(0,H.useState)("relevance"),[m,u]=(0,H.useState)(0),[x,h]=(0,H.useState)(1e5),[p,g]=(0,H.useState)(!0),[f,v]=(0,H.useState)(!1),[b,j]=(0,H.useState)(0),[y]=(0,H.useState)(12),[N,w]=(0,H.useState)(0),[_,k]=(0,H.useState)(!1),[A,S]=(0,H.useState)(null),[C,E]=(0,H.useState)(!1),I=(0,H.useCallback)(async function(){let e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];try{e?a(!0):v(!0);const t=e?0:N,r={skip:t,limit:y,sort_by:T(d),status:"approved"};n.length>0&&(r.services={$in:n}),o.length>0&&(r.languages={$in:o}),(m>0||x<1e5)&&(r.budget_starting_from_dollars={},m>0&&(r.budget_starting_from_dollars.$gte=m),x<1e5&&(r.budget_starting_from_dollars.$lte=x)),Object.keys(r).forEach(e=>{void 0===r[e]&&delete r[e]});const l=await nw.listCatalogItems(r),i=Array.isArray(l)?l:l.items,c=Array.isArray(l)?i.length:l.total||i.length;e?(s(i),j(c)):s(e=>[...e,...i]),w(t+i.length),g(i.length===y)}catch(t){an({title:"Error",description:"Failed to load partners. Please try again.",variant:"destructive"})}finally{a(!1),v(!1)}},[N,y,n,o,d,m,x]);(0,H.useEffect)(()=>{s([]),w(0),g(!0),I(!0)},[n,o,d,m,x]);const T=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"}},P=(0,H.useCallback)(()=>{!p||f||t||I(!1)},[p,f,t,I]),{targetRef:L}=Tb({onLoadMore:P,hasMore:p,isLoading:f||t}),O=()=>{k(!1),S(null)};return(0,re.jsxs)("div",{"data-testid":"partners-catalog",className:"min-h-screen bg-white",children:[(0,re.jsx)(fw,{"data-testid":"catalog-header",totalPartners:b,onBecomePartnerClick:()=>E(!0)}),(0,re.jsx)(Nw,{"data-testid":"filter-bar",selectedServices:n,onServicesChange:r,budgetRange:l,onBudgetRangeChange:i,selectedLanguages:o,onLanguagesChange:c,onBudgetApply:(e,s)=>{u(e),h(s)},onServicesApply:e=>{r(e)},onLanguagesApply:e=>{c(e)},currentBudgetMin:m,currentBudgetMax:x}),(0,re.jsxs)("div",{"data-testid":"partners-catalog-content",className:"max-w-7xl mx-auto px-6 lg:px-8 py-12",children:[(0,re.jsx)(Sw,{"data-testid":"partners-grid",isLoading:t,isLoadingMore:f,partners:e,onContactClick:e=>{S(e),k(!0)},onBecomePartnerClick:()=>E(!0),hasMore:p,targetRef:L}),(0,re.jsx)(Gw,{isOpen:_,onClose:O,partner:A,onSubmit:async e=>{try{await nw.contactRequest((0,K.A)((0,K.A)({},e),{},{partner_profile_id:null==A?void 0:A.item.id})),an({title:"Success",description:"Your contact request has been sent successfully!"}),O()}catch(a){var s,t;null!==(s=a.response)&&void 0!==s&&null!==(t=s.data)&&void 0!==t&&t.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,re.jsx)(iw,{isOpen:C,onClose:()=>E(!1)})]})]})}function Jw(){return(0,re.jsx)("div",{className:"min-h-screen bg-gradient-to-br from-slate-50 to-slate-100",children:(0,re.jsx)("div",{className:"max-w-4xl mx-auto px-6 py-12",children:(0,re.jsxs)("div",{className:"bg-white rounded-2xl shadow-xl border border-slate-200 overflow-hidden",children:[(0,re.jsxs)("div",{className:"bg-gradient-to-r from-orange-500 to-orange-600 px-8 py-6",children:[(0,re.jsx)("h1",{className:"text-3xl font-bold text-white",children:"Base44 Partners Terms of Use"}),(0,re.jsx)("p",{className:"text-orange-100 mt-2",children:"Last updated: September 11, 2025"})]}),(0,re.jsx)("div",{className:"px-8 py-8",children:(0,re.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,re.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,re.jsx)("div",{className:"partners-terms",children:(0,re.jsx)(hb,{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,re.jsx)("div",{className:"bg-slate-50 px-8 py-6 border-t border-slate-200",children:(0,re.jsx)("p",{className:"text-sm text-slate-600 text-center",children:"For questions about these terms, please contact us at partners@base44.com."})})]})})})}const Zw=()=>{const[e]=(0,J.useSearchParams)(),s=e.get("appId"),[t,a]=(0,H.useState)(!0);return(0,H.useEffect)(()=>{(async()=>{if(s)try{const e=await ve.getLoginInfoById(s),{slug:t}=e;t?window.location.href="https://".concat(t,".base44.app"):a(!1)}catch(e){a(!1)}else a(!1)})()},[s]),s?t?(0,re.jsx)("div",{className:"flex items-center justify-center min-h-screen bg-slate-50",children:(0,re.jsxs)("div",{className:"text-center",children:[(0,re.jsx)("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-orange-500 mx-auto mb-4"}),(0,re.jsx)("p",{className:"text-slate-600",children:"Redirecting to app..."})]})}):null:(0,re.jsx)("div",{className:"flex items-center justify-center min-h-screen bg-slate-50",children:(0,re.jsx)("div",{className:"text-center",children:(0,re.jsx)("p",{className:"text-slate-500 text-sm",children:"No app found"})})})};function Kw(){const{fileId:e}=(0,Z.g)();window.location.href="".concat((0,ee.wE)(),"/api/files/").concat(e)}function Xw(e){let{url:s}=e;window.location.href=s}function Qw(e){let{urlChangeHandler:s}=e;const t=(0,Z.g)(),a=window.location.pathname,n=s(a,t);return n!==a&&(window.location.href=n),(0,re.jsx)("div",{children:"Loading..."})}const e_=[{name:"Home",url:"/",component:(0,re.jsx)(br,{}),icon:(0,re.jsx)(Wr.A,{})},{name:"Login",url:"/login",component:(0,re.jsx)(Vv,{}),requiresAuth:!1,usesLayout:!1,hide:!0},{name:"Register",url:"/register",component:(0,re.jsx)(cb,{}),requiresAuth:!1,usesLayout:!1,hide:!0},{name:"VerifyEmail",url:"/verify-email",component:(0,re.jsx)(db,{}),requiresAuth:!1,usesLayout:!1,hide:!0},{name:"ForgotPassword",url:"/forgot-password",component:(0,re.jsx)(mb,{}),requiresAuth:!1,usesLayout:!1,hide:!0},{name:"CheckEmail",url:"/check-email",component:(0,re.jsx)(ub,{}),requiresAuth:!1,usesLayout:!1,hide:!0},{name:"ResetPassword",url:"/reset-password",component:(0,re.jsx)(xb,{}),requiresAuth:!1,usesLayout:!1,hide:!0},{name:"PrivacyPolicy",url:"/privacy-policy",component:(0,re.jsx)(Xw,{url:"https://base44.com/privacy-policy"}),requiresAuth:!1,hide:!0},{name:"TermsOfService",url:"/terms-of-service",component:(0,re.jsx)(Xw,{url:"https://base44.com/terms-of-service"}),requiresAuth:!1,hide:!0},{name:"ResponsibleUse",url:"/responsible-use-policy",component:(0,re.jsx)(Ib,{}),requiresAuth:!1,hide:!0},{name:"File",url:"/api/files/:fileId",component:(0,re.jsx)(Kw,{}),requiresAuth:!1,usesLayout:!1,hide:!0},{name:"App Preview",url:"/app_preview",component:(0,re.jsx)(Zw,{}),requiresAuth:!1,usesLayout:!1,hide:!0},{name:"User Apps",url:"/user-apps/:appId/show/:pageName?",component:(0,re.jsx)(Qw,{urlChangeHandler:e=>e.replace("/user-apps/","/apps/")}),icon:(0,re.jsx)(Vr.A,{}),showInMenu:!1,requiresAuth:!1},{name:"User Apps",url:"/apps",component:(0,re.jsx)(qr,{}),icon:(0,re.jsx)(Vr.A,{}),children:[{name:"User App Dashboard",url:"/apps/:appId",component:(0,re.jsx)(Jf,{}),icon:(0,re.jsx)(Vr.A,{}),usesLayout:!1},{name:"App Show",url:"/apps-show/:appSlug/:pageName?",component:(0,re.jsx)(Qw,{urlChangeHandler:(e,s)=>{const t=s.appSlug,a=s.pageName,n=window.location.host;return"https://".concat(t,".").concat(n,"/").concat(a||"")}}),icon:(0,re.jsx)(Yr.A,{}),usesLayout:!1,requiresAuth:!1},{name:"Edit User App",url:"/apps/:appId/editor/preview/:pageName",component:(0,re.jsx)(Jf,{view:"preview"}),icon:(0,re.jsx)(Hr.A,{}),usesLayout:!1},{name:"Remix User App",url:"/remix-app/:appId",component:(0,re.jsx)(rj,{}),icon:(0,re.jsx)(Hr.A,{})},{name:"Edit User App",url:"/apps/:appId/dashboard",component:(0,re.jsx)(Jf,{view:"workspace"}),icon:(0,re.jsx)(Hr.A,{}),usesLayout:!1},{name:"Edit User App",url:"/apps/:appId/editor/preview",component:(0,re.jsx)(Jf,{view:"preview"}),icon:(0,re.jsx)(Hr.A,{}),usesLayout:!1},{name:"Edit User App",url:"/apps/:appId/editor/workspace/:workspaceView",component:(0,re.jsx)(Jf,{view:"workspace"}),icon:(0,re.jsx)(Hr.A,{}),usesLayout:!1},{name:"Create App",url:"/create-app",component:(0,re.jsx)(Zf,{}),icon:(0,re.jsx)(Ss.A,{})}]},{name:"Billing",url:"/billing",component:(0,re.jsx)(tc,{}),icon:(0,re.jsx)(Ke.A,{}),hide:!0},{name:"Support",url:"/support",component:(0,re.jsx)(mj,{})},{name:"My Tickets",url:"/support/conversations",component:(0,re.jsx)(ay,{})},{name:"Admin Support Tickets",url:"/support/admin/conversations",component:(0,re.jsx)(by,{}),usesLayout:!1},{name:"Admin Support Docs",url:"/support/admin/agent-backoffice",component:(0,re.jsx)(Ey,{})},{name:"Admin Analytics",url:"/support/admin/analytics",component:(0,re.jsx)(lN,{})},{name:"User Management",url:"/user-management",component:(0,re.jsx)(Ev,{}),icon:(0,re.jsx)(Gr.A,{}),hide:!0},{name:"App Templates Management",url:"/app-templates-management",component:(0,re.jsx)(NN,{}),icon:(0,re.jsx)(Gr.A,{}),hide:!0},{name:"Integration Management",url:"/integration-management",component:(0,re.jsx)(_N,{}),icon:(0,re.jsx)($r.A,{}),hide:!0},{name:"Integrations Catalog",url:"/integrations-catalog",component:(0,re.jsx)(zb,{}),icon:(0,re.jsx)($r.A,{}),children:[{name:"Integrations Catalog Item",url:"/integrations-catalog/item/:itemId",component:(0,re.jsx)(Gb,{})},{name:"Integration Editor",url:"/integrations-catalog/editor/:itemId?",component:(0,re.jsx)(sj,{})}]},{name:"App Templates",url:"/app-templates",component:(0,re.jsx)(nj,{}),icon:(0,re.jsx)(Vr.A,{}),children:[{name:"Manage Listing",url:"/app-templates/manage-listing/:appId",component:(0,re.jsx)(Mu,{})}]},{name:"Partners Catalog",url:"/partners",component:(0,re.jsx)($w,{}),icon:(0,re.jsx)(Gr.A,{})},{name:"Partners Terms",url:"/partners/terms",component:(0,re.jsx)(Jw,{}),requiresAuth:!1,hide:!0},{name:"Partner Admin",url:"/admin/partners",component:(0,re.jsx)(gw,{}),icon:(0,re.jsx)(Gr.A,{}),hide:!0},{name:"Analytics",url:"/admin/analytics",component:(0,re.jsx)(Pv,{}),icon:(0,re.jsx)(Jr.A,{}),hide:!0},{name:"Stripe",url:"/integrations/stripe",component:(0,re.jsx)(Eb,{}),icon:(0,re.jsx)(Ke.A,{}),hide:!0},{name:"Workspace Dashboard",url:"/workspace/:workspaceId",component:(0,re.jsx)(Zy,{}),hide:!0},{name:"Create Workspace",url:"/create-workspace",component:(0,re.jsx)(Ky,{}),hide:!0},{name:"Accept Invitation",url:"/invite/accept",component:(0,re.jsx)(Xy,{}),hide:!0,usesLayout:!1,requiresAuth:!0},{name:"NotFound",url:"*",component:(0,re.jsx)(pb,{}),hide:!0,usesLayout:!1,requiresAuth:!1}];var s_=t(78602),t_=t(30772);function a_(e){let{isMobile:s=!1,onItemClick:t}=e;const a=(0,Z.Zp)(),{workspaces:n,isLoadingWorkspaces:r,activeWorkspace:l,switchActiveWorkspace:i}=ge(),o=e=>{i(e),t&&t()},c=e=>{a("/workspace/".concat(e.id)),t&&t()},d=e=>{if(e.is_personal)return!1;const s=e.user_role||e.role||"member";return["owner","admin"].includes(s)},m=()=>{a("/create-workspace"),t&&t()};return s?(0,re.jsxs)("div",{className:"p-1",children:[(0,re.jsxs)("div",{className:"flex items-center justify-between px-4 py-2",children:[(0,re.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,re.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,re.jsx)(Ss.A,{className:"h-3 w-3 text-gray-600"})})]}),r?(0,re.jsxs)("div",{className:"px-4 py-3 flex items-center justify-center",children:[(0,re.jsx)(Ze.A,{className:"h-4 w-4 animate-spin text-gray-400"}),(0,re.jsx)("span",{className:"ml-2 text-sm text-gray-500 font-base44",children:"Loading..."})]}):n.length>0?(0,re.jsx)("div",{className:"space-y-1",children:n.map(e=>(0,re.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==l?void 0:l.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,re.jsx)("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:(0,re.jsxs)("div",{className:"min-w-0 flex-1 text-left",children:[(0,re.jsx)("div",{className:"truncate text-base font-light ".concat((null==l?void 0:l.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,re.jsx)("div",{className:"text-xs text-gray-500 truncate mt-0.5",children:e.domain})]})}),(0,re.jsx)("div",{className:"flex items-center gap-1 flex-shrink-0",children:d(e)&&(0,re.jsx)("button",{onClick:s=>{s.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,re.jsx)("div",{className:"px-4 py-3",children:(0,re.jsx)("div",{className:"text-sm text-gray-500 text-center font-base44",children:"No workspaces found"})})]}):(0,re.jsxs)("div",{className:"p-1",children:[(0,re.jsxs)("div",{className:"flex items-center justify-between px-4 py-2",children:[(0,re.jsx)(Vl,{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,re.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,re.jsx)(Ss.A,{className:"h-3 w-3 text-gray-600"})})]}),r?(0,re.jsxs)("div",{className:"px-4 py-3 flex items-center justify-center",children:[(0,re.jsx)(Ze.A,{className:"h-4 w-4 animate-spin text-gray-400"}),(0,re.jsx)("span",{className:"ml-2 text-sm text-gray-500 font-base44",children:"Loading..."})]}):n.length>0?(0,re.jsx)("div",{className:"space-y-1",children:n.map(e=>(0,re.jsxs)(zl,{onClick:()=>o(e),className:"cursor-pointer flex items-center justify-between px-4 py-2 rounded-lg font-base44 group ".concat((null==l?void 0:l.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,re.jsx)("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:(0,re.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,re.jsx)("div",{className:"truncate text-sm font-light ".concat((null==l?void 0:l.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,re.jsx)("div",{className:"text-xs text-gray-500 truncate mt-0.5",children:e.domain})]})}),(0,re.jsx)("div",{className:"flex items-center gap-1 flex-shrink-0",children:d(e)&&(0,re.jsx)("button",{onClick:s=>{s.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,re.jsx)("div",{className:"px-4 py-3",children:(0,re.jsx)("div",{className:"text-sm text-gray-500 text-center font-base44",children:"No workspaces found"})})]})}var n_=t(42309);const r_=e=>{let{referral:s}=e;const t="published"===s.status;return(0,re.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,re.jsx)("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:(0,re.jsx)("div",{className:"min-w-0 flex-1",children:(0,re.jsx)("p",{className:"text-sm font-light text-black truncate font-base44",children:s.email})})}),(0,re.jsx)("div",{className:"flex-shrink-0 ml-2",children:(0,re.jsx)("span",{className:"inline-flex items-center gap-1 px-3 py-1 rounded-full text-xs font-light font-base44 ".concat(t?"text-[#229954] border border-[#229954]":"bg-white text-black border border-slate-200"),style:t?{backgroundColor:"#E9F6EE"}:{},children:t?(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(n_.A,{className:"h-3 w-3"}),"+10"]}):"Registered"})})]})};function l_(e){let{isOpen:s,onClose:t}=e;const{user:a,reloadUser:n}=oe(),[r,l]=(0,H.useState)((null==a?void 0:a.referral_code)||null),[i,o]=(0,H.useState)(!1),[c,d]=(0,H.useState)(!1),[m,u]=(0,H.useState)(null),[x,h]=(0,H.useState)(null),[p,g]=(0,H.useState)(!1),[f,v]=(0,H.useState)(!1),b=(0,H.useRef)(!1),j=(0,H.useRef)(null),y=(0,H.useRef)(null),N=(0,H.useRef)(null),w=(0,H.useRef)(null),_=(e,s)=>{e.current&&(e.current.classList.add("show-scrollbar"),s.current&&clearTimeout(s.current),s.current=setTimeout(()=>{e.current&&e.current.classList.remove("show-scrollbar")},1e3))};(0,H.useEffect)(()=>{const e=j.current,s=y.current,t=()=>_(j,N),a=()=>_(y,w);return e&&e.addEventListener("scroll",t,{passive:!0}),s&&s.addEventListener("scroll",a,{passive:!0}),()=>{e&&e.removeEventListener("scroll",t),s&&s.removeEventListener("scroll",a),[N,w].forEach(e=>{e.current&&clearTimeout(e.current)})}},[f,x]);const k=r?"https://app.base44.com/register?ref=".concat(r):"",A=((null==x?void 0:x.referrals)||[]).slice(0,5),S=((null==x?void 0:x.total_referrals)||0)>=5,C=(0,H.useCallback)(async()=>{if(!p)try{g(!0);const e=await sb.getReferralStats();h(e)}catch(e){h({referrals:[],total_referrals:0,published_referrals:0})}finally{g(!1)}},[]),E=(0,H.useCallback)(async()=>{if(!i)try{o(!0),u(null);const e=await sb.generateReferralCode();l(e),await n(),await C()}catch(e){u(e.message)}finally{o(!1)}},[]);(0,H.useEffect)(()=>{s&&a&&!b.current&&(b.current=!0,r?C():E()),s||(b.current=!1)},[s,a,r]);const I=()=>{d(!1),u(null),v(!1),t()};return(0,re.jsxs)(re.Fragment,{children:[(0,re.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,re.jsx)(Pa,{open:s,onOpenChange:I,children:(0,re.jsxs)(Ma,{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,re.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,re.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,re.jsx)(re.Fragment,{children:(0,re.jsxs)("div",{className:"hidden sm:flex flex-col w-[270px] flex-shrink-0 rounded-tl-[36px] relative overflow-hidden",children:[(0,re.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,re.jsx)("div",{className:"absolute inset-0 bg-gradient-to-br from-orange-400/20 via-transparent to-orange-300/30 rounded-tl-[36px]"}),(0,re.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,re.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,re.jsx)("div",{className:"flex-shrink-0 absolute top-0 left-0 right-0 z-40",children:(0,re.jsxs)("div",{className:"flex items-center justify-between px-4 sm:px-9 pt-4 sm:pt-6",children:[f?(0,re.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,re.jsx)(Cc.A,{className:"h-6 w-6 text-black"}),(0,re.jsx)("span",{className:"text-black font-base44 text-sm",children:"Back"})]}):(0,re.jsx)("div",{}),(0,re.jsx)("button",{onClick:I,className:"p-2 hover:bg-black/10 rounded-lg transition-all duration-200",title:"Close",children:(0,re.jsx)("svg",{className:"h-6 w-6 text-black",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,re.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})}),f?(0,re.jsx)(re.Fragment,{children:(0,re.jsxs)("div",{ref:j,className:"flex-1 overflow-y-auto sm:px-5 pb-5 custom-scrollbar",style:{paddingTop:"60px"},children:[(0,re.jsx)("div",{className:"mb-6",children:(0,re.jsxs)(Fa,{children:[(0,re.jsx)(Ua,{className:"text-left font-base44 text-2xl font-bold text-black mb-2",children:"Terms & Conditions"}),(0,re.jsx)(za,{className:"text-left text-sm text-black font-base44",children:"Referral program terms and conditions"})]})}),(0,re.jsxs)("div",{className:"space-y-6 text-sm",children:[(0,re.jsxs)("div",{children:[(0,re.jsx)("h4",{className:"font-semibold text-slate-800 mb-4 font-base44",children:"Eligibility"}),(0,re.jsxs)("ul",{className:"space-y-3 ml-4",children:[(0,re.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,re.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,re.jsxs)("div",{children:[(0,re.jsx)("h4",{className:"font-semibold text-slate-800 mb-4 font-base44",children:"Referral Credits"}),(0,re.jsxs)("ul",{className:"list-disc list-inside ml-4 space-y-3 text-slate-700",children:[(0,re.jsx)("li",{className:"leading-relaxed font-base44",children:"You earn 10 credits when a referred friend publishes their first app"}),(0,re.jsx)("li",{className:"leading-relaxed font-base44",children:"Referred friends receive 10 bonus credits upon registration"}),(0,re.jsx)("li",{className:"leading-relaxed font-base44",children:"Maximum of 5 successful referrals per account"}),(0,re.jsx)("li",{className:"leading-relaxed font-base44",children:"Credits have no cash value and cannot be transferred"})]})]}),(0,re.jsxs)("div",{children:[(0,re.jsx)("h4",{className:"font-semibold text-slate-800 mb-4 font-base44",children:"Restrictions"}),(0,re.jsxs)("ul",{className:"list-disc list-inside ml-4 space-y-3 text-slate-700",children:[(0,re.jsx)("li",{className:"leading-relaxed font-base44",children:"Base44 reserves the right to void fraudulent referrals"}),(0,re.jsx)("li",{className:"leading-relaxed font-base44",children:"Referral codes are non-transferable"})]})]})]})]})}):(0,re.jsx)(re.Fragment,{children:(0,re.jsxs)("div",{ref:y,className:"flex-1 overflow-y-auto sm:px-9 pb-5 custom-scrollbar",children:[(0,re.jsxs)("div",{className:"relative mb-4 sm:mb-6 pt-4 sm:pt-8 max-w-sm",children:[(0,re.jsxs)(Fa,{children:[(0,re.jsxs)(Ua,{className:"text-left font-base44 font-normal text-black mb-1 text-xl sm:text-5xl leading-tight sm:leading-none",children:[(0,re.jsx)("span",{className:"sm:hidden",children:"Invite & Earn Credits"}),(0,re.jsxs)("span",{className:"hidden sm:inline",children:["Invite Friends &",(0,re.jsx)("br",{}),"Earn Credits"]})]}),(0,re.jsx)(za,{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"})]}),S&&(0,re.jsx)("div",{className:"mt-3 mb-1",children:(0,re.jsxs)("div",{className:"flex items-center gap-2",children:[(0,re.jsx)("div",{className:"text-lg",children:"\u{1f389}"}),(0,re.jsxs)("div",{children:[(0,re.jsx)("p",{className:"text-sm font-semibold text-black font-base44",children:"Amazing! You've reached the maximum referrals"}),(0,re.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,re.jsxs)("div",{className:"relative z-10",children:[(0,re.jsx)("div",{className:"mb-4",children:i||!r?(0,re.jsx)("div",{children:(0,re.jsxs)("div",{className:"flex items-center gap-2",children:[(0,re.jsx)(ox,{className:"flex-1 h-10 rounded"}),(0,re.jsx)(ox,{className:"w-16 h-10 rounded"})]})}):m?(0,re.jsxs)("div",{className:"p-4 rounded-xl bg-red-50 border border-red-200",children:[(0,re.jsx)("p",{className:"text-sm text-red-600 font-medium font-base44",children:m}),(0,re.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,re.jsxs)("div",{className:"relative",children:[(0,re.jsxs)("div",{className:"flex items-center gap-2",children:[(0,re.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,re.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,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(Pt.A,{className:"h-4 w-4"}),"Copied"]}):(0,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(Kr.A,{className:"h-4 w-4"}),"Copy"]})})]}),(0,re.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,re.jsxs)("div",{className:"flex items-center gap-2 p-2 bg-emerald-50 border border-emerald-200/50 rounded-lg text-xs",children:[(0,re.jsx)(Px.A,{className:"w-3 h-3 text-emerald-600 flex-shrink-0"}),(0,re.jsx)("p",{className:"text-emerald-700 font-medium font-base44",children:"Copied to clipboard!"})]})})]})}),(0,re.jsxs)("div",{className:"space-y-1.5",children:[(0,re.jsx)("h3",{className:"text-sm font-light text-gray-700 font-base44",children:"How it Works"}),(0,re.jsx)("div",{className:"flex flex-col",children:[{icon:qa.A,text:"Share your unique referral link with friends"},{icon:Yg.A,text:"They get 10 credits when they sign up"},{icon:Yg.A,text:"You earn 10 credits when they publish their first app"}].map((e,s)=>{const t=e.icon;return(0,re.jsxs)("div",{className:"flex items-center py-0.5 rounded-lg",children:[(0,re.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,re.jsx)(t,{className:"w-5 h-5 text-[#272524]"})}),(0,re.jsx)("p",{className:"text-sm text-black font-base44",dangerouslySetInnerHTML:{__html:e.text}})]},s)})})]})]}),(A.length>0||void 0!==(null==x?void 0:x.total_referrals))&&(0,re.jsxs)("div",{children:[(0,re.jsx)("div",{className:"mb-3 mt-3",children:(0,re.jsxs)("h4",{className:"text-sm font-light text-gray-700 font-base44",children:["Your Referrals (",(null==x?void 0:x.total_referrals)||0,"/",5,")"]})}),A.length>0&&(0,re.jsx)("div",{className:"space-y-1.5",children:A.map((e,s)=>(0,re.jsx)(r_,{referral:e},s))})]})]})}),(0,re.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,re.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,re.jsx)("button",{onClick:()=>{v(!0)},className:"text-sm text-black transition-colors hover:underline font-base44",children:"Terms & Conditions"})})]})," "]})," "]})," "]})})]})}var i_=t(59469),o_=t(33978);function c_(){const[e,s]=(0,H.useState)([]),[t,a]=(0,H.useState)(!0),[n,r]=(0,H.useState)(null),[l,i]=(0,H.useState)(!1),[o,c]=(0,H.useState)(new Set),d=async()=>{try{a(!0);const e=await Av.getChangelog();s(e),r(null)}catch(e){r(e.message)}finally{a(!1)}};(0,H.useEffect)(()=>{d();const e=setInterval(d,12e5);return()=>clearInterval(e)},[]);const m=e.filter(e=>!e.is_seen).length;return(0,re.jsxs)(re.Fragment,{children:[(0,re.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,re.jsxs)(Pl,{open:l,onOpenChange:async t=>{i(t),await Av.markChangelogAsSeen(),s(e.map(e=>(0,K.A)((0,K.A)({},e),{},{is_seen:!0})))},children:[(0,re.jsx)(Ll,{className:"relative p-2 hover:bg-gray-100 rounded-lg transition-colors focus:outline-none",children:(0,re.jsx)("div",{className:"flex items-center justify-center p-2 hover:bg-gray-200 hover:rounded-[10px]",children:(0,re.jsxs)("div",{className:"relative",children:[(0,re.jsx)(i_.A,{size:18,className:"text-gray-800"}),m>0&&(0,re.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,re.jsxs)(Ul,{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,re.jsx)("div",{className:"px-4 pt-3",children:(0,re.jsx)("h3",{className:"text-[22px] font-semibold",children:"What's new"})}),(0,re.jsx)("div",{className:"overflow-y-auto flex-1 hover-scrollbar",children:t?(0,re.jsx)("div",{className:"px-4 py-8 text-center text-gray-500",children:"Loading notifications..."}):n?(0,re.jsx)("div",{className:"px-4 py-8 text-center text-red-500",children:"Failed to load notifications"}):0===e.length?(0,re.jsx)("div",{className:"px-4 py-8 text-center text-gray-500",children:"No notifications yet"}):(0,re.jsx)("div",{className:"space-y-0",children:e.map((e,s)=>(0,re.jsxs)("div",{className:"relative",children:[s>0&&(0,re.jsx)("div",{className:"border-t border-gray-100 mx-2"}),(0,re.jsx)("div",{className:"px-2 py-2",children:(0,re.jsx)("div",{className:"p-0 hover:bg-slate-50 hover:rounded-xl cursor-pointer transition-all duration-200",onClick:()=>((e,s)=>{0===s&&e.link_url&&window.open(e.link_url,"_blank")})(e,s),children:0===s?(0,re.jsxs)("div",{className:"px-2 py-2",children:[e.image_url&&(0,re.jsx)("div",{className:"w-full mb-4",children:(0,re.jsx)("img",{src:e.image_url,alt:"",className:"w-full h-48 object-cover rounded-lg"})}),(0,re.jsxs)("div",{className:"flex items-start justify-between mb-2",children:[(0,re.jsx)("h4",{className:"text-[15px] font-semibold text-gray-900",children:e.title}),!e.is_seen&&(0,re.jsx)("div",{className:"w-2 h-2 bg-orange-500 rounded-full flex-shrink-0 ml-3 mt-1"})]}),(0,re.jsxs)("div",{children:[(0,re.jsx)("p",{className:"text-[14px] text-gray-600 mb-2",children:e.content}),(0,re.jsx)("p",{className:"text-xs text-gray-400",children:(0,o_.m)(new Date(e.created_date),{addSuffix:!0})})]})]}):(0,re.jsxs)("div",{className:"px-2 py-2",children:[e.image_url&&(0,re.jsx)("div",{className:"w-full mb-4",children:(0,re.jsx)("img",{src:e.image_url,alt:"",className:"w-full h-48 object-cover rounded-lg"})}),(0,re.jsxs)("div",{className:"flex items-start justify-between mb-2",children:[(0,re.jsx)("h4",{className:"text-[15px] font-semibold text-gray-900",children:e.title}),!e.is_seen&&(0,re.jsx)("div",{className:"w-2 h-2 bg-orange-500 rounded-full flex-shrink-0 ml-3 mt-1"})]}),(0,re.jsxs)("div",{children:[(0,re.jsx)("p",{className:"text-[14px] text-gray-600 mb-1 ".concat(o.has(e.id||s)?"":"line-clamp-2"),children:e.content}),(0,re.jsx)("div",{className:"mb-2",children:(0,re.jsx)("span",{className:"text-black hover:text-gray-700 text-xs cursor-pointer font-light underline",onClick:t=>((e,s,t)=>{if(e.stopPropagation(),t>0){const e=s.id||t;c(s=>{const t=new Set;return s.has(e)||t.add(e),t})}})(t,e,s),children:o.has(e.id||s)?"Show less":"Read more"})}),(0,re.jsx)("p",{className:"text-xs text-gray-400",children:(0,o_.m)(new Date(e.created_date),{addSuffix:!0})})]})]})})})]},e.id||s))})})]})]})]})}const d_="text-gray-700 hover:text-gray-800",m_="",u_=()=>(0,re.jsx)("img",{src:"/Logo_v5.png",alt:"Base44",width:"114",height:"28"});function x_(){var e,s;const{logout:t,user:a}=oe(),n=(0,Z.Zp)(),r=(0,Z.zy)(),{workspaces:l,isLoadingWorkspaces:i,activeWorkspace:o,switchActiveWorkspace:c}=ge(),{hasFlag:d}=Sx(),[m,u]=(0,H.useState)(!1),[x,h]=(0,H.useState)(!1),[p,g]=(0,H.useState)(!1),[f,v]=(0,H.useState)(!1),b=()=>{u(!1)};(0,H.useEffect)(()=>{!i&&l.length>0&&!o&&c(l[0])},[l,i,o,c]);const j=e=>r.pathname===e,y=[{key:"settings",icon:(0,re.jsx)(od.A,{size:18,className:"mr-2 font-base44 text-gray-800"}),label:"Settings",onClick:()=>g(!0)},{key:"referrals",icon:(0,re.jsx)(Yg.A,{size:18,className:"mr-2 font-base44 text-gray-800"}),label:"Refer Friends",onClick:()=>v(!0)},{key:"billing",icon:(0,re.jsx)(Ke.A,{size:18,className:"mr-2 font-base44 text-gray-800"}),label:"Billing",onClick:()=>{Ie("User Clicked Billing",{source:"top_bar_user_menu",destination:"/billing"}),We({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,re.jsx)(s_.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,re.jsx)($g.A,{size:18,className:"mr-2 font-base44 text-gray-800"}),label:"Sign Out",onClick:()=>{t(),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,re.jsx)("svg",{className:"h-7 w-7",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:(0,re.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,re.jsx)(Va.A,{size:26})},{href:"https://www.linkedin.com/company/106589953",title:"Follow on LinkedIn",icon:(0,re.jsx)(Wa.A,{size:26})}];return(0,re.jsxs)("header",{className:"sticky top-0 z-50",children:[(0,re.jsx)("div",{className:"mx-auto px-4 sm:px-6 lg:px-8",children:(0,re.jsxs)("div",{className:"flex items-center justify-between h-16",children:[(0,re.jsxs)("div",{className:"flex items-center",children:[(0,re.jsx)(J.Link,{to:"/",children:(0,re.jsx)(u_,{})}),(0,re.jsx)("nav",{className:"hidden md:flex items-center ml-6 sm:ml-8 space-x-4 sm:space-x-6",children:w.map((e,s)=>e.external?(0,re.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,re.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"})]},s):(0,re.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,re.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")})]},s))})]}),(0,re.jsxs)("div",{className:"flex items-center",children:[(0,re.jsxs)("div",{className:"hidden md:flex items-center mr-2",children:[(0,re.jsx)(c_,{}),(0,re.jsx)("button",{onClick:()=>v(!0),className:"".concat(d_," ").concat(m_," p-2 hover:bg-gray-200 hover:rounded-[10px]"),title:"Refer Friends",children:(0,re.jsx)(Yg.A,{size:20})})]}),(0,re.jsxs)("div",{className:"flex items-center font-base44",children:[(0,re.jsx)("div",{className:"hidden md:block",children:(0,re.jsxs)(Pl,{children:[(0,re.jsx)(Ll,{className:"outline-none",children:(0,re.jsx)("div",{className:"flex items-center gap-2",children:(0,re.jsxs)("div",{className:"".concat(d_," ").concat(m_," cursor-pointer relative"),children:[(0,re.jsx)(bf,{}),o&&!o.is_personal&&(0,re.jsx)("div",{className:"absolute -bottom-1 -right-1 w-3 h-3 bg-orange-500 border-2 border-white rounded-full"})]})})}),(0,re.jsxs)(Ul,{align:"end",className:"w-64 p-0 shadow-lg border-none rounded-lg min-w-[128px]",children:[a&&(0,re.jsxs)("div",{className:"px-4 py-3 border-b border-slate-100 font-base44",children:[(0,re.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,re.jsx)("div",{className:"text-xs text-muted-foreground truncate mt-0.5",children:a.email})]}),(0,re.jsx)("div",{className:"p-1",children:y.map(e=>(0,re.jsxs)(zl,{onClick:e.onClick,className:"cursor-pointer flex items-center px-4 py-2 hover:bg-slate-50 font-base44",children:[e.icon,(0,re.jsx)("span",{children:e.label})]},e.key))}),(0,re.jsx)(Yl,{}),(0,re.jsx)(a_,{}),(0,re.jsx)(Yl,{}),(0,re.jsx)("div",{className:"p-1",children:N.map(e=>(0,re.jsxs)(zl,{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,re.jsx)($g.A,{size:18,className:"mr-2 font-base44"}):e.icon,(0,re.jsx)("span",{children:e.label})]},e.key))})]})]})}),(0,re.jsxs)("div",{className:"md:hidden",children:[(0,re.jsx)("button",{onClick:()=>h(!0),className:"outline-none",children:(0,re.jsx)("div",{className:"flex items-center gap-2",children:(0,re.jsxs)("div",{className:"".concat(d_," ").concat(m_," cursor-pointer relative"),children:[(0,re.jsx)(bf,{}),o&&!o.is_personal&&(0,re.jsx)("div",{className:"absolute -bottom-1 -right-1 w-3 h-3 bg-orange-500 border-2 border-white rounded-full"})]})})}),(0,re.jsx)(Vm,{open:x,onOpenChange:h,children:(0,re.jsx)(Zm,{side:"bottom",className:"h-[90vh] max-h-[600px] p-0 rounded-t-3xl border-t border-gray-200",children:(0,re.jsxs)("div",{className:"flex flex-col h-full",children:[(0,re.jsx)("div",{className:"flex justify-center pt-3 pb-2",children:(0,re.jsx)("div",{className:"w-12 h-1 bg-gray-300 rounded-full"})}),a&&(0,re.jsx)("div",{className:"px-6 py-6 border-b border-gray-100",children:(0,re.jsxs)("div",{className:"flex items-center space-x-4",children:[(0,re.jsxs)("div",{className:"relative",children:[(0,re.jsx)(bf,{size:"lg"}),o&&!o.is_personal&&(0,re.jsx)("div",{className:"absolute -bottom-1 -right-1 w-4 h-4 bg-orange-500 border-2 border-white rounded-full"})]}),(0,re.jsxs)("div",{children:[(0,re.jsx)("div",{className:"font-semibold text-lg text-gray-900 font-base44",children:null===(s=a.full_name)||void 0===s?void 0:s.split(" ").map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(" ")}),(0,re.jsx)("div",{className:"text-sm text-gray-500 mt-1",children:a.email})]})]})}),(0,re.jsxs)("div",{className:"flex-1 overflow-y-auto scrollbar-auto-hide",children:[(0,re.jsx)("div",{className:"py-2",children:y.map(e=>(0,re.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,re.jsx)("span",{className:"text-gray-600",children:e.icon}),(0,re.jsx)("span",{className:"ml-3 text-base font-medium text-gray-900",children:e.label})]},e.key))}),(0,re.jsx)("div",{className:"border-t border-gray-100 py-2",children:(0,re.jsx)(a_,{isMobile:!0,onItemClick:()=>h(!1)})}),(0,re.jsx)("div",{className:"border-t border-gray-100 py-2",children:N.map(e=>(0,re.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,re.jsx)("span",{className:"logout"===e.key?"text-red-600":"text-gray-600",children:"logout"===e.key?(0,re.jsx)($g.A,{size:18,className:"mr-2 font-base44"}):e.icon}),(0,re.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,re.jsx)("div",{className:"md:hidden ml-4 flex items-center",children:(0,re.jsxs)(Vm,{open:m,onOpenChange:u,children:[(0,re.jsx)(Ym,{asChild:!0,children:(0,re.jsx)("button",{className:"".concat(d_," ").concat(m_," flex items-center justify-center"),children:(0,re.jsx)(t_.A,{size:24})})}),(0,re.jsx)(Zm,{side:"right",className:"w-[80%] sm:w-[350px] p-0",children:(0,re.jsxs)("div",{className:"flex flex-col h-full",children:[(0,re.jsx)("div",{className:"flex-1 px-6 py-8",children:(0,re.jsx)("nav",{className:"space-y-1",children:w.map((e,s)=>e.external?(0,re.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},s):(0,re.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},s))})}),(0,re.jsx)("div",{className:"px-6 py-8 border-t border-gray-100",children:(0,re.jsx)("div",{className:"flex justify-center space-x-8",children:_.map((e,s)=>(0,re.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},s))})})]})})]})})]})]})]})}),(0,re.jsx)(Tf,{isOpen:p,onClose:()=>g(!1)}),(0,re.jsx)(l_,{isOpen:f,onClose:()=>v(!1)})]})}const h_=e=>{let{children:s}=e;return(0,re.jsxs)(Is,{children:[(0,re.jsx)(qh,{}),(0,re.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,re.jsxs)("div",{className:"flex flex-col h-full w-full relative z-10",children:[(0,re.jsx)(x_,{}),(0,re.jsx)("div",{className:"flex-1 overflow-auto",children:(0,re.jsx)("main",{className:"w-full h-full",children:s})})]})})]})};var p_=t(39330),g_=t(15441);const f_=(0,H.createContext)();class v_ extends X.y{getBaseURL(){return"/apps"}getCurrentUser(e){return this.axios.get("/".concat(e,"/entities/User/me"))}}const b_=new v_,j_=e=>{let{children:s,appId:t}=e;const[a,n]=(0,H.useState)(null),[r,l]=(0,H.useState)(!1),[i,o]=(0,H.useState)(!0),[c,d]=(0,H.useState)(null),[m,u]=(0,H.useState)(null);(0,H.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 s=ne.b3.addListener((e,s)=>{if("sso_tokens_updated"===e){const e=s.tokens;d(e);!(0,ne.VO)(!1)&&e&&e.access_token&&u("sso")}else"sso_tokens_cleared"===e&&(d(null),"sso"===m&&(u(null),l(!1),n(null)))});return()=>{s()}},[]);const x=()=>{(0,ne.QF)(),n(null),l(!1),o(!1),d(null),u(null),ne.b3.clearSSOTokens()},h=async()=>{try{o(!0);const e=await b_.getCurrentUser(t);return window.FS&&window.FS("setIdentity",{uid:e.id,properties:{displayName:e.full_name||e.email,email:e.email}}),n(e),l(!0),o(!1),e}catch(e){o(!1),x()}},p=()=>c||ne.b3.getSSOTokens();return(0,re.jsx)(f_.Provider,{value:{user:a,isAuthenticated:r,logout:function(){let e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];if(x(),l(!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 s=window.location.href,a="/api/apps/".concat(t,"/auth/sso/login?from_url=").concat(encodeURIComponent(s),"&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 s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return ne.b3.fetchWithSSO(e,s)},clearSSOTokens:()=>{ne.b3.clearSSOTokens(),d(null)}},children:s})},y_=()=>(0,H.useContext)(f_);async function N_(e,s){const t=(0,ae.Ay)("https://base44.app/api"+"/apps/".concat(e,"/integration-endpoints"),{"X-App-Id":e},!0,!0),a=await t.get("/schema");let n={};return(a.installed_packages||a).forEach(e=>{n[e.package_name]=function(e,s,t){const a={};return s.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 t,r;a instanceof FormData||a&&Object.values(a).some(e=>e instanceof File)?(t=new FormData,Object.keys(a).forEach(e=>{a[e]instanceof File?t.append(e,a[e],a[e].name):"object"==typeof a[e]&&null!==a[e]?t.append(e,JSON.stringify(a[e])):t.append(e,a[e])}),r="multipart/form-data"):(t=a,r="application/json");const l="Core"===s.package_name?"/Core/".concat(n.name):"/".concat(s.package_name,"/").concat(n.name),i=e.post(l,t||a,{headers:{"Content-Type":r}});return await i}catch(i){var r,l;throw t("Error calling integration ".concat(n.name,": ").concat((null===(r=i.response)||void 0===r||null===(l=r.data)||void 0===l?void 0:l.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}(t,e,s)}),n.getMissingPackages=()=>a.missing_packages||[],n}function w_(e,s,t){class a extends X.y{getBaseURL(){return"https://base44.app/api"+"/apps/".concat(e)}inviteUser(e,s){return this.axios.post("/users/invite-user",{user_email:e,role:s})}getMyUserInfo(){return this.axios.get("/entities/User/me")}updateMyUserData(e){return this.axios.put("/entities/User/me",e)}async logout(){t.logout(!1),window.location.reload()}async login(){const s=window.location.href,t="".concat((0,ee.Zk)(),"/apps/auth/login?from_url=").concat(s,"&app_id=").concat(e);window.location.href=t}async loginWithRedirect(e){const s=window.location.href.substring(0,window.location.href.lastIndexOf("/")+1);window.location.href="".concat(s,"login?from_url=").concat(encodeURIComponent(e))}isUserAuthenticated(){return t.isUserAuthenticated()}register(e){return this.axios.post("/auth/register",e)}verifyOtp(e,s){return this.axios.post("/auth/verify-otp",{email:e,otp_code:s})}resendOtp(e){return this.axios.post("/auth/resend-otp",{email:e})}loginViaUsernamePassword(e,s){return this.axios.post("/auth/login",{email:e,password:s})}resetPasswordRequest(e){return this.axios.post("/auth/reset-password-request",{email:e})}resetPassword(e,s){return this.axios.post("/auth/reset-password",{reset_token:e,new_password:s})}changePassword(e,s,t){return this.axios.post("/auth/change-password",{user_id:e,current_password:s,new_password:t})}}return new a(s)}async function __(e){const s=(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 t;t=e.slug?await s.get("/prod/by-slug/".concat(e.slug)):await s.get("/prod/by-id/".concat(e.id));const a=bs(),n={};n["api/base44Client.js"]="import { createClient } from '@base44/sdk';\n\nexport const base44 = createClient({\n appId: \"".concat(t.id,'",\n serverUrl: "').concat("https://base44.app",'",\n functionsVersion: "').concat(a,'"\n});\n');const r=(s,a,n,r)=>{let l=n;if(a&&"string"==typeof a){const e=a.match(/at\s+(\w+)\s+/);if(e&&e[1]){const s=e[1];if(t.components&&t.components[s])l=s;else if(t.pages&&t.pages[s])l=s;else{for(const e in t.components||{})if(t.components[e].includes("function ".concat(s))){l=e;break}for(const e in t.pages||{})if(t.pages[e].includes("function ".concat(s))){l=e;break}}}}e.onError(s,a,l,r)},l=w_(t.id,r,e.authProps),i=ys(t,r,l),o=await N_(t.id,r),c=lh(t,r),d=Hp(t.id,void 0,r);return{appId:t.id,files:(0,K.A)((0,K.A)({},t),{},{coreFiles:n}),entities:i,integrations:o,functions:c,users:l,agents:d,getCurrentPage:()=>function(e){let s=window.location.pathname;s.endsWith("/")&&(s=s.slice(0,-1));let t=s.split("/").pop();return t.includes("?")&&(t=t.split("?")[0]),Object.keys(e.pages).map(e=>e.toLowerCase()).includes(t.toLowerCase())?{name:t,code:e.pages[t]}:t===e.slug||t===e.id||"preview"===t||""===t?{name:e.main_page,code:e.pages[e.main_page]}:null}(t),createPageUrl:(e,s)=>((e,s,t)=>{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--")?t&&"object"==typeof t?"/".concat(s,"?").concat(Object.keys(t).map(e=>"".concat(e,"=").concat(t[e])).join("&")):t&&"string"==typeof t?t.startsWith("?")?"/".concat(s).concat(t):"/".concat(s,"?").concat(t):"/".concat(s):t&&"object"==typeof t?"/apps-show/".concat(e.slug,"/").concat(s,"?").concat(Object.keys(t).map(e=>"".concat(e,"=").concat(t[e])).join("&")):t&&"string"==typeof t?t.startsWith("?")?"/apps-show/".concat(e.slug,"/").concat(s).concat(t):"/apps-show/".concat(e.slug,"/").concat(s,"?").concat(t):"/apps-show/".concat(e.slug,"/").concat(s)})(t,e,s),options:(0,K.A)((0,K.A)({},e),{},{onError:r})}}var k_=t(37906);function A_(e){let s=!1;function t(e){!function(e){if(pd.isJSXExpressionContainer(e)){const s=e.expression;if(pd.isJSXEmptyExpression(s))return!1;if(!pd.isLiteral(s))return!0}if(pd.isTemplateLiteral(e)&&e.expressions.length>0)return!0;if(pd.isMemberExpression(e))return!0;if(pd.isCallExpression(e))return!0;if(pd.isConditionalExpression(e))return!0;if(pd.isIdentifier(e)&&["props","state","data","item","value","text","content"].some(s=>e.name.includes(s)))return!0;return!1}(e)?Object.keys(e).forEach(s=>{const a=e[s];Array.isArray(a)?a.forEach(e=>{e&&"object"==typeof e&&e.type&&t(e)}):a&&"object"==typeof a&&a.type&&t(a)}):s=!0}return e.children.forEach(e=>{s||t(e)}),s}function S_(e,s){const t=function(e,s){e.includes(".")&&(e=e.split(".")[0]);try{const t=(0,ud.parse)(s,{sourceType:"module",plugins:["jsx","typescript","decorators-legacy","classProperties","objectRestSpread","functionBind","exportDefaultFrom","exportNamespaceFrom","dynamicImport","nullishCoalescingOperator","optionalChaining","asyncGenerators","bigInt","optionalCatchBinding","throwExpressions"]});return(0,xd.default)(t,{JSXElement(s){var t;const a=s.node,n=a.openingElement;if(pd.isJSXFragment(a))return;if(n.attributes.some(e=>pd.isJSXAttribute(e)&&pd.isJSXIdentifier(e.name)&&"data-source-location"===e.name.name))return;const{line:r,column:l}=(null===(t=n.loc)||void 0===t?void 0:t.start)||{line:1,column:0},i=pd.jsxAttribute(pd.jsxIdentifier("data-source-location"),pd.stringLiteral("".concat(e,":").concat(r,":").concat(l))),o=A_(a),c=pd.jsxAttribute(pd.jsxIdentifier("data-dynamic-content"),pd.stringLiteral(o?"true":"false"));n.attributes.unshift(i,c)}}),{code:(0,hd.default)(t,{retainLines:!0,compact:!1,concise:!1}).code,success:!0}}catch(t){return{code:s,success:!1,error:t instanceof Error?t.message:"Unknown error"}}}(e,s);return t.code}function C_(){const e="preview_";return{getItem:s=>localStorage.getItem(e+s),setItem:(s,t)=>localStorage.setItem(e+s,t),removeItem:s=>localStorage.removeItem(e+s)}}function E_(e){(e.startsWith("./")||e.startsWith("@/"))&&(e=e.substring(2));const s=e.split("/"),t=[];for(const n of s)".."===n?t.pop():"."!==n&&t.push(n);let a=t.join("/");return/\.\w+$/.test(a)||(a+=".js"),a}function I_(e,s){let t=arguments.length>2&&void 0!==arguments[2]&&arguments[2];const a={get(s,a){if(!s.hasOwnProperty(a)&&"PropTypes"!==a&&"__esModule"!==a&&a.charAt(0)===a.charAt(0).toUpperCase()){if("function"==typeof s&&a.charAt(0)===a.charAt(0).toUpperCase())return s;if(!t&&a===e.split("/").pop().split(".")[0]&&s.default)return s.default;throw new Error("'".concat(a,"' does not exist in module: ").concat(e))}return s[a]}};return new Proxy(s,a)}function T_(e,s,t){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:s,component:t}},"*")}catch(a){}}function P_(e,s){const t="[".concat(e,"]");return{log:function(){for(var s=arguments.length,a=new Array(s),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),r=0;re 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:l,componentName:e};s(o.title,o.details,o.componentName,o.originalError),T_(i,"error",e)},warn:function(){for(var s=arguments.length,a=new Array(s),n=0;n"object"==typeof e?JSON.stringify(e):String(e)).join(" "),"warn",e)}}}var L_=t(84079),O_=t(94048),R_=t(93204),D_=t(86991),M_=t(79476),F_=t(2191),B_=t(59019),U_=t(2527),z_=t(99603),q_=t(65604),W_=(t(55392),t(56687)),V_=t(39040);const Y_=["className"],H_=["className","children"],G_=["className","children"],$_=V_.bL,J_=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,Y_);return(0,re.jsx)(V_.q7,(0,K.A)({ref:s,className:is("border-b",t)},a))});J_.displayName="AccordionItem";const Z_=H.forwardRef((e,s)=>{let{className:t,children:a}=e,n=(0,as.A)(e,H_);return(0,re.jsx)(V_.Y9,{className:"flex",children:(0,re.jsxs)(V_.l9,(0,K.A)((0,K.A)({ref:s,className:is("flex flex-1 items-center justify-between py-4 font-medium transition-all hover:underline [&[data-state=open]>svg]:rotate-180",t)},n),{},{children:[a,(0,re.jsx)(It.A,{className:"h-4 w-4 shrink-0 transition-transform duration-200"})]}))})});Z_.displayName=V_.l9.displayName;const K_=H.forwardRef((e,s)=>{let{className:t,children:a}=e,n=(0,as.A)(e,G_);return(0,re.jsx)(V_.UC,(0,K.A)((0,K.A)({ref:s,className:"overflow-hidden text-sm transition-all data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down"},n),{},{children:(0,re.jsx)("div",{className:is("pb-4 pt-0",t),children:a})}))});K_.displayName=V_.UC.displayName;const X_=t(61980).b;var Q_=t(55421);const ek=["orientation","opts","setApi","plugins","className","children"],sk=["className"],tk=["className"],ak=["className","variant","size"],nk=["className","variant","size"],rk=H.createContext(null);function lk(){const e=H.useContext(rk);if(!e)throw new Error("useCarousel must be used within a ");return e}const ik=H.forwardRef((e,s)=>{let{orientation:t="horizontal",opts:a,setApi:n,plugins:r,className:l,children:i}=e,o=(0,as.A)(e,ek);const[c,d]=(0,Q_.A)((0,K.A)((0,K.A)({},a),{},{axis:"horizontal"===t?"x":"y"}),r),[m,u]=H.useState(!1),[x,h]=H.useState(!1),p=H.useCallback(e=>{e&&(u(e.canScrollPrev()),h(e.canScrollNext()))},[]),g=H.useCallback(()=>{null==d||d.scrollPrev()},[d]),f=H.useCallback(()=>{null==d||d.scrollNext()},[d]),v=H.useCallback(e=>{"ArrowLeft"===e.key?(e.preventDefault(),g()):"ArrowRight"===e.key&&(e.preventDefault(),f())},[g,f]);return H.useEffect(()=>{d&&n&&n(d)},[d,n]),H.useEffect(()=>{if(d)return p(d),d.on("reInit",p),d.on("select",p),()=>{null==d||d.off("select",p)}},[d,p]),(0,re.jsx)(rk.Provider,{value:{carouselRef:c,api:d,opts:a,orientation:t||("y"===(null==a?void 0:a.axis)?"vertical":"horizontal"),scrollPrev:g,scrollNext:f,canScrollPrev:m,canScrollNext:x},children:(0,re.jsx)("div",(0,K.A)((0,K.A)({ref:s,onKeyDownCapture:v,className:is("relative",l),role:"region","aria-roledescription":"carousel"},o),{},{children:i}))})});ik.displayName="Carousel";const ok=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,sk);const{carouselRef:n,orientation:r}=lk();return(0,re.jsx)("div",{ref:n,className:"overflow-hidden",children:(0,re.jsx)("div",(0,K.A)({ref:s,className:is("flex","horizontal"===r?"-ml-4":"-mt-4 flex-col",t)},a))})});ok.displayName="CarouselContent";const ck=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,tk);const{orientation:n}=lk();return(0,re.jsx)("div",(0,K.A)({ref:s,role:"group","aria-roledescription":"slide",className:is("min-w-0 shrink-0 grow-0 basis-full","horizontal"===n?"pl-4":"pt-4",t)},a))});ck.displayName="CarouselItem";const dk=H.forwardRef((e,s)=>{let{className:t,variant:a="outline",size:n="icon"}=e,r=(0,as.A)(e,ak);const{orientation:l,scrollPrev:i,canScrollPrev:o}=lk();return(0,re.jsxs)(Hs,(0,K.A)((0,K.A)({ref:s,variant:a,size:n,className:is("absolute h-8 w-8 rounded-full","horizontal"===l?"-left-12 top-1/2 -translate-y-1/2":"-top-12 left-1/2 -translate-x-1/2 rotate-90",t),disabled:!o,onClick:i},r),{},{children:[(0,re.jsx)(Cc.A,{className:"h-4 w-4"}),(0,re.jsx)("span",{className:"sr-only",children:"Previous slide"})]}))});dk.displayName="CarouselPrevious";const mk=H.forwardRef((e,s)=>{let{className:t,variant:a="outline",size:n="icon"}=e,r=(0,as.A)(e,nk);const{orientation:l,scrollNext:i,canScrollNext:o}=lk();return(0,re.jsxs)(Hs,(0,K.A)((0,K.A)({ref:s,variant:a,size:n,className:is("absolute h-8 w-8 rounded-full","horizontal"===l?"-right-12 top-1/2 -translate-y-1/2":"-bottom-12 left-1/2 -translate-x-1/2 rotate-90",t),disabled:!o,onClick:i},r),{},{children:[(0,re.jsx)(ha.A,{className:"h-4 w-4"}),(0,re.jsx)("span",{className:"sr-only",children:"Next slide"})]}))});mk.displayName="CarouselNext";var uk=t(21984);const xk=["className","inset","children"],hk=["className"],pk=["className"],gk=["className","inset"],fk=["className","children","checked"],vk=["className","children"],bk=["className","inset"],jk=["className"],yk=["className"],Nk=uk.bL,wk=uk.l9,_k=uk.YJ,kk=uk.ZL,Ak=uk.Pb,Sk=uk.z6,Ck=H.forwardRef((e,s)=>{let{className:t,inset:a,children:n}=e,r=(0,as.A)(e,xk);return(0,re.jsxs)(uk.ZP,(0,K.A)((0,K.A)({ref:s,className:is("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",t)},r),{},{children:[n,(0,re.jsx)(ln.A,{className:"ml-auto h-4 w-4"})]}))});Ck.displayName=uk.ZP.displayName;const Ek=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,hk);return(0,re.jsx)(uk.G5,(0,K.A)({ref:s,className:is("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",t)},a))});Ek.displayName=uk.G5.displayName;const Ik=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,pk);return(0,re.jsx)(uk.ZL,{children:(0,re.jsx)(uk.UC,(0,K.A)({ref:s,className:is("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",t)},a))})});Ik.displayName=uk.UC.displayName;const Tk=H.forwardRef((e,s)=>{let{className:t,inset:a}=e,n=(0,as.A)(e,gk);return(0,re.jsx)(uk.q7,(0,K.A)({ref:s,className:is("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",t)},n))});Tk.displayName=uk.q7.displayName;const Pk=H.forwardRef((e,s)=>{let{className:t,children:a,checked:n}=e,r=(0,as.A)(e,fk);return(0,re.jsxs)(uk.H_,(0,K.A)((0,K.A)({ref:s,className:is("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",t),checked:n},r),{},{children:[(0,re.jsx)("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:(0,re.jsx)(uk.VF,{children:(0,re.jsx)(Pt.A,{className:"h-4 w-4"})})}),a]}))});Pk.displayName=uk.H_.displayName;const Lk=H.forwardRef((e,s)=>{let{className:t,children:a}=e,n=(0,as.A)(e,vk);return(0,re.jsxs)(uk.hN,(0,K.A)((0,K.A)({ref:s,className:is("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",t)},n),{},{children:[(0,re.jsx)("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:(0,re.jsx)(uk.VF,{children:(0,re.jsx)(_t.A,{className:"h-2 w-2 fill-current"})})}),a]}))});Lk.displayName=uk.hN.displayName;const Ok=H.forwardRef((e,s)=>{let{className:t,inset:a}=e,n=(0,as.A)(e,bk);return(0,re.jsx)(uk.JU,(0,K.A)({ref:s,className:is("px-2 py-1.5 text-sm font-semibold text-foreground",a&&"pl-8",t)},n))});Ok.displayName=uk.JU.displayName;const Rk=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,jk);return(0,re.jsx)(uk.wv,(0,K.A)({ref:s,className:is("-mx-1 my-1 h-px bg-border",t)},a))});Rk.displayName=uk.wv.displayName;const Dk=e=>{let{className:s}=e,t=(0,as.A)(e,yk);return(0,re.jsx)("span",(0,K.A)({className:is("ml-auto text-xs tracking-widest text-muted-foreground",s)},t))};Dk.displayName="ContextMenuShortcut";const Mk=["className"],Fk=["className"],Bk=["className"],Uk=["className","children"],zk=wv.FormProvider,qk=H.createContext({}),Wk=e=>{let s=Object.assign({},((0,Ja.A)(e),e));return(0,re.jsx)(qk.Provider,{value:{name:s.name},children:(0,re.jsx)(wv.Controller,(0,K.A)({},s))})},Vk=()=>{const e=H.useContext(qk),s=H.useContext(Yk),{getFieldState:t,formState:a}=(0,wv.useFormContext)(),n=t(e.name,a);if(!e)throw new Error("useFormField should be used within ");const{id:r}=s;return(0,K.A)({id:r,name:e.name,formItemId:"".concat(r,"-form-item"),formDescriptionId:"".concat(r,"-form-item-description"),formMessageId:"".concat(r,"-form-item-message")},n)},Yk=H.createContext({}),Hk=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,Mk);const n=H.useId();return(0,re.jsx)(Yk.Provider,{value:{id:n},children:(0,re.jsx)("div",(0,K.A)({ref:s,className:is("space-y-2",t)},a))})});Hk.displayName="FormItem";const Gk=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,Fk);const{error:n,formItemId:r}=Vk();return(0,re.jsx)(Nt,(0,K.A)({ref:s,className:is(n&&"text-destructive",t),htmlFor:r},a))});Gk.displayName="FormLabel";const $k=H.forwardRef((e,s)=>{let t=Object.assign({},((0,Ja.A)(e),e));const{error:a,formItemId:n,formDescriptionId:r,formMessageId:l}=Vk();return(0,re.jsx)(Ws.DX,(0,K.A)({ref:s,id:n,"aria-describedby":a?"".concat(r," ").concat(l):"".concat(r),"aria-invalid":!!a},t))});$k.displayName="FormControl";const Jk=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,Bk);const{formDescriptionId:n}=Vk();return(0,re.jsx)("p",(0,K.A)({ref:s,id:n,className:is("text-sm text-muted-foreground",t)},a))});Jk.displayName="FormDescription";const Zk=H.forwardRef((e,s)=>{let{className:t,children:a}=e,n=(0,as.A)(e,Uk);const{error:r,formMessageId:l}=Vk(),i=r?String(null==r?void 0:r.message):a;return i?(0,re.jsx)("p",(0,K.A)((0,K.A)({ref:s,id:l,className:is("text-sm font-medium text-destructive",t)},n),{},{children:i})):null});Zk.displayName="FormMessage";var Kk=t(29037);const Xk=["className","align","sideOffset"],Qk=Kk.bL,eA=Kk.l9,sA=H.forwardRef((e,s)=>{let{className:t,align:a="center",sideOffset:n=4}=e,r=(0,as.A)(e,Xk);return(0,re.jsx)(Kk.UC,(0,K.A)({ref:s,align:a,sideOffset:n,className:is("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",t)},r))});sA.displayName=Kk.UC.displayName;var tA=t(55102);const aA=["className"],nA=["className"],rA=["className","inset","children"],lA=["className"],iA=["className","align","alignOffset","sideOffset"],oA=["className","inset"],cA=["className","children","checked"],dA=["className","children"],mA=["className","inset"],uA=["className"],xA=["className"],hA=tA.W1,pA=tA.YJ,gA=tA.ZL,fA=tA.Pb,vA=tA.z6,bA=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,aA);return(0,re.jsx)(tA.bL,(0,K.A)({ref:s,className:is("flex h-10 items-center space-x-1 rounded-md border bg-background p-1",t)},a))});bA.displayName=tA.bL.displayName;const jA=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,nA);return(0,re.jsx)(tA.l9,(0,K.A)({ref:s,className:is("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",t)},a))});jA.displayName=tA.l9.displayName;const yA=H.forwardRef((e,s)=>{let{className:t,inset:a,children:n}=e,r=(0,as.A)(e,rA);return(0,re.jsxs)(tA.ZP,(0,K.A)((0,K.A)({ref:s,className:is("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",t)},r),{},{children:[n,(0,re.jsx)(ln.A,{className:"ml-auto h-4 w-4"})]}))});yA.displayName=tA.ZP.displayName;const NA=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,lA);return(0,re.jsx)(tA.G5,(0,K.A)({ref:s,className:is("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",t)},a))});NA.displayName=tA.G5.displayName;const wA=H.forwardRef((e,s)=>{let{className:t,align:a="start",alignOffset:n=-4,sideOffset:r=8}=e,l=(0,as.A)(e,iA);return(0,re.jsx)(tA.ZL,{children:(0,re.jsx)(tA.UC,(0,K.A)({ref:s,align:a,alignOffset:n,sideOffset:r,className:is("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",t)},l))})});wA.displayName=tA.UC.displayName;const _A=H.forwardRef((e,s)=>{let{className:t,inset:a}=e,n=(0,as.A)(e,oA);return(0,re.jsx)(tA.q7,(0,K.A)({ref:s,className:is("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",t)},n))});_A.displayName=tA.q7.displayName;const kA=H.forwardRef((e,s)=>{let{className:t,children:a,checked:n}=e,r=(0,as.A)(e,cA);return(0,re.jsxs)(tA.H_,(0,K.A)((0,K.A)({ref:s,className:is("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",t),checked:n},r),{},{children:[(0,re.jsx)("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:(0,re.jsx)(tA.VF,{children:(0,re.jsx)(Pt.A,{className:"h-4 w-4"})})}),a]}))});kA.displayName=tA.H_.displayName;const AA=H.forwardRef((e,s)=>{let{className:t,children:a}=e,n=(0,as.A)(e,dA);return(0,re.jsxs)(tA.hN,(0,K.A)((0,K.A)({ref:s,className:is("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",t)},n),{},{children:[(0,re.jsx)("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:(0,re.jsx)(tA.VF,{children:(0,re.jsx)(_t.A,{className:"h-2 w-2 fill-current"})})}),a]}))});AA.displayName=tA.hN.displayName;const SA=H.forwardRef((e,s)=>{let{className:t,inset:a}=e,n=(0,as.A)(e,mA);return(0,re.jsx)(tA.JU,(0,K.A)({ref:s,className:is("px-2 py-1.5 text-sm font-semibold",a&&"pl-8",t)},n))});SA.displayName=tA.JU.displayName;const CA=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,uA);return(0,re.jsx)(tA.wv,(0,K.A)({ref:s,className:is("-mx-1 my-1 h-px bg-muted",t)},a))});CA.displayName=tA.wv.displayName;const EA=e=>{let{className:s}=e,t=(0,as.A)(e,xA);return(0,re.jsx)("span",(0,K.A)({className:is("ml-auto text-xs tracking-widest text-muted-foreground",s)},t))};EA.displayname="MenubarShortcut";var IA=t(47624);const TA=["className","children"],PA=["className"],LA=["className","children"],OA=["className"],RA=["className"],DA=["className"],MA=H.forwardRef((e,s)=>{let{className:t,children:a}=e,n=(0,as.A)(e,TA);return(0,re.jsxs)(IA.bL,(0,K.A)((0,K.A)({ref:s,className:is("relative z-10 flex max-w-max flex-1 items-center justify-center",t)},n),{},{children:[a,(0,re.jsx)(VA,{})]}))});MA.displayName=IA.bL.displayName;const FA=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,PA);return(0,re.jsx)(IA.B8,(0,K.A)({ref:s,className:is("group flex flex-1 list-none items-center justify-center space-x-1",t)},a))});FA.displayName=IA.B8.displayName;const BA=IA.q7,UA=(0,ns.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"),zA=H.forwardRef((e,s)=>{let{className:t,children:a}=e,n=(0,as.A)(e,LA);return(0,re.jsxs)(IA.l9,(0,K.A)((0,K.A)({ref:s,className:is(UA(),"group",t)},n),{},{children:[a," ",(0,re.jsx)(It.A,{className:"relative top-[1px] ml-1 h-3 w-3 transition duration-200 group-data-[state=open]:rotate-180","aria-hidden":"true"})]}))});zA.displayName=IA.l9.displayName;const qA=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,OA);return(0,re.jsx)(IA.UC,(0,K.A)({ref:s,className:is("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 ",t)},a))});qA.displayName=IA.UC.displayName;const WA=IA.N_,VA=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,RA);return(0,re.jsx)("div",{className:is("absolute left-0 top-full flex justify-center"),children:(0,re.jsx)(IA.LM,(0,K.A)({className:is("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)]",t),ref:s},a))})});VA.displayName=IA.LM.displayName;const YA=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,DA);return(0,re.jsx)(IA.C1,(0,K.A)((0,K.A)({ref:s,className:is("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",t)},a),{},{children:(0,re.jsx)("div",{className:"relative top-[60%] h-2 w-2 rotate-45 rounded-tl-sm bg-border shadow-md"})}))});YA.displayName=IA.C1.displayName;var HA=t(23379);const GA=["className"],$A=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,GA);return(0,re.jsxs)(HA.bL,(0,K.A)((0,K.A)({ref:s,className:is("relative flex w-full touch-none select-none items-center",t)},a),{},{children:[(0,re.jsx)(HA.CC,{className:"relative h-2 w-full grow overflow-hidden rounded-full bg-secondary",children:(0,re.jsx)(HA.Q6,{className:"absolute h-full bg-primary"})}),(0,re.jsx)(HA.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"})]}))});$A.displayName=HA.bL.displayName;var JA=t(52982);const ZA=["className","variant","size"],KA=(0,ns.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"}}),XA=H.forwardRef((e,s)=>{let{className:t,variant:a,size:n}=e,r=(0,as.A)(e,ZA);return(0,re.jsx)(JA.b,(0,K.A)({ref:s,className:is(KA({variant:a,size:n,className:t}))},r))});XA.displayName=JA.b.displayName;var QA=t(85162);const eS=e=>{let s=Object.assign({},((0,Ja.A)(e),e));const{theme:t="system"}=(0,QA.D)();return(0,re.jsx)(Gp.Toaster,(0,K.A)({theme:t,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"}}},s))};function sS(){for(var e=arguments.length,s=new Array(e),t=0;t{let{defaultOpen:t=!0,open:a,onOpenChange:n,className:r,style:l,children:i}=e,o=(0,as.A)(e,tS);const c=function(){const[e,s]=H.useState(void 0);return H.useEffect(()=>{const e=window.matchMedia("(max-width: ".concat(767,"px)")),t=()=>{s(window.innerWidth<768)};return e.addEventListener("change",t),s(window.innerWidth<768),()=>e.removeEventListener("change",t)},[]),!!e}(),[d,m]=H.useState(!1),[u,x]=H.useState(t),h=null!=a?a:u,p=H.useCallback(e=>{const s="function"==typeof e?e(h):e;n?n(s):x(s),document.cookie="".concat("sidebar_state","=").concat(s,"; path=/; max-age=").concat(604800)},[n,h]),g=H.useCallback(()=>c?m(e=>!e):p(e=>!e),[c,p,m]);H.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=H.useMemo(()=>({state:f,open:h,setOpen:p,isMobile:c,openMobile:d,setOpenMobile:m,toggleSidebar:g}),[f,h,p,c,d,m,g]);return(0,re.jsx)(_S.Provider,{value:v,children:(0,re.jsx)(Is,{delayDuration:0,children:(0,re.jsx)("div",(0,K.A)((0,K.A)({style:(0,K.A)({"--sidebar-width":"16rem","--sidebar-width-icon":"3rem"},l),className:sS("group/sidebar-wrapper flex min-h-svh w-full has-[[data-variant=inset]]:bg-sidebar",r),ref:s},o),{},{children:i}))})})});AS.displayName="SidebarProvider";const SS=H.forwardRef((e,s)=>{let{side:t="left",variant:a="sidebar",collapsible:n="offcanvas",className:r,children:l}=e,i=(0,as.A)(e,aS);const{isMobile:o,state:c,openMobile:d,setOpenMobile:m}=kS();return"none"===n?(0,re.jsx)("div",(0,K.A)((0,K.A)({className:sS("flex h-full w-[--sidebar-width] flex-col bg-sidebar text-sidebar-foreground",r),ref:s},i),{},{children:l})):o?(0,re.jsx)(Vm,(0,K.A)((0,K.A)({open:d,onOpenChange:m},i),{},{children:(0,re.jsxs)(Zm,{"data-sidebar":"sidebar","data-mobile":"true",className:"w-[--sidebar-width] bg-sidebar p-0 text-sidebar-foreground [&>button]:hidden",style:{"--sidebar-width":"18rem"},side:t,children:[(0,re.jsxs)(Km,{className:"sr-only",children:[(0,re.jsx)(Qm,{children:"Sidebar"}),(0,re.jsx)(eu,{children:"Displays the mobile sidebar."})]}),(0,re.jsx)("div",{className:"flex h-full w-full flex-col",children:l})]})})):(0,re.jsxs)("div",{ref:s,className:"group peer hidden text-sidebar-foreground md:block","data-state":c,"data-collapsible":"collapsed"===c?n:"","data-variant":a,"data-side":t,children:[(0,re.jsx)("div",{className:sS("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,re.jsx)("div",(0,K.A)((0,K.A)({className:sS("fixed inset-y-0 z-10 hidden h-svh w-[--sidebar-width] transition-[left,right,width] duration-200 ease-linear md:flex","left"===t?"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",r)},i),{},{children:(0,re.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:l})}))]})});SS.displayName="Sidebar";const CS=H.forwardRef((e,s)=>{let{className:t,onClick:a}=e,n=(0,as.A)(e,nS);const{toggleSidebar:r}=kS();return(0,re.jsxs)(Hs,(0,K.A)((0,K.A)({ref:s,"data-sidebar":"trigger",variant:"ghost",size:"icon",className:sS("h-7 w-7",t),onClick:e=>{null==a||a(e),r()}},n),{},{children:[(0,re.jsx)(Rx.A,{}),(0,re.jsx)("span",{className:"sr-only",children:"Toggle Sidebar"})]}))});CS.displayName="SidebarTrigger";const ES=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,rS);const{toggleSidebar:n}=kS();return(0,re.jsx)("button",(0,K.A)({ref:s,"data-sidebar":"rail","aria-label":"Toggle Sidebar",tabIndex:-1,onClick:n,title:"Toggle Sidebar",className:sS("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",t)},a))});ES.displayName="SidebarRail";const IS=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,lS);return(0,re.jsx)("main",(0,K.A)({ref:s,className:sS("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",t)},a))});IS.displayName="SidebarInset";const TS=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,iS);return(0,re.jsx)(ft,(0,K.A)({ref:s,"data-sidebar":"input",className:sS("h-8 w-full bg-background shadow-none focus-visible:ring-2 focus-visible:ring-sidebar-ring",t)},a))});TS.displayName="SidebarInput";const PS=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,oS);return(0,re.jsx)("div",(0,K.A)({ref:s,"data-sidebar":"header",className:sS("flex flex-col gap-2 p-2",t)},a))});PS.displayName="SidebarHeader";const LS=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,cS);return(0,re.jsx)("div",(0,K.A)({ref:s,"data-sidebar":"footer",className:sS("flex flex-col gap-2 p-2",t)},a))});LS.displayName="SidebarFooter";const OS=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,dS);return(0,re.jsx)(pt,(0,K.A)({ref:s,"data-sidebar":"separator",className:sS("mx-2 w-auto bg-sidebar-border",t)},a))});OS.displayName="SidebarSeparator";const RS=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,mS);return(0,re.jsx)("div",(0,K.A)({ref:s,"data-sidebar":"content",className:sS("flex min-h-0 flex-1 flex-col gap-2 overflow-auto group-data-[collapsible=icon]:overflow-hidden",t)},a))});RS.displayName="SidebarContent";const DS=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,uS);return(0,re.jsx)("div",(0,K.A)({ref:s,"data-sidebar":"group",className:sS("relative flex w-full min-w-0 flex-col p-2",t)},a))});DS.displayName="SidebarGroup";const MS=H.forwardRef((e,s)=>{let{className:t,asChild:a=!1}=e,n=(0,as.A)(e,xS);const r=a?Ws.DX:"div";return(0,re.jsx)(r,(0,K.A)({ref:s,"data-sidebar":"group-label",className:sS("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",t)},n))});MS.displayName="SidebarGroupLabel";const FS=H.forwardRef((e,s)=>{let{className:t,asChild:a=!1}=e,n=(0,as.A)(e,hS);const r=a?Ws.DX:"button";return(0,re.jsx)(r,(0,K.A)({ref:s,"data-sidebar":"group-action",className:sS("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",t)},n))});FS.displayName="SidebarGroupAction";const BS=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,pS);return(0,re.jsx)("div",(0,K.A)({ref:s,"data-sidebar":"group-content",className:sS("w-full text-sm",t)},a))});BS.displayName="SidebarGroupContent";const US=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,gS);return(0,re.jsx)("ul",(0,K.A)({ref:s,"data-sidebar":"menu",className:sS("flex w-full min-w-0 flex-col gap-1",t)},a))});US.displayName="SidebarMenu";const zS=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,fS);return(0,re.jsx)("li",(0,K.A)({ref:s,"data-sidebar":"menu-item",className:sS("group/menu-item relative",t)},a))});zS.displayName="SidebarMenuItem";const qS=(0,ns.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"}}),WS=H.forwardRef((e,s)=>{let{asChild:t=!1,isActive:a=!1,variant:n="default",size:r="default",tooltip:l,className:i}=e,o=(0,as.A)(e,vS);const c=t?Ws.DX:"button",{isMobile:d,state:m}=kS(),u=(0,re.jsx)(c,(0,K.A)({ref:s,"data-sidebar":"menu-button","data-size":r,"data-active":a,className:sS(qS({variant:n,size:r}),i)},o));return l?("string"==typeof l&&(l={children:l}),(0,re.jsxs)(Ts,{children:[(0,re.jsx)(Ps,{asChild:!0,children:u}),(0,re.jsx)(Ls,(0,K.A)({side:"right",align:"center",hidden:"collapsed"!==m||d},l))]})):u});WS.displayName="SidebarMenuButton";const VS=H.forwardRef((e,s)=>{let{className:t,asChild:a=!1,showOnHover:n=!1}=e,r=(0,as.A)(e,bS);const l=a?Ws.DX:"button";return(0,re.jsx)(l,(0,K.A)({ref:s,"data-sidebar":"menu-action",className:sS("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",t)},r))});VS.displayName="SidebarMenuAction";const YS=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,jS);return(0,re.jsx)("div",(0,K.A)({ref:s,"data-sidebar":"menu-badge",className:sS("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",t)},a))});YS.displayName="SidebarMenuBadge";const HS=H.forwardRef((e,s)=>{let{className:t,showIcon:a=!1}=e,n=(0,as.A)(e,yS);const r=H.useMemo(()=>"".concat(Math.floor(40*Math.random())+50,"%"),[]);return(0,re.jsxs)("div",(0,K.A)((0,K.A)({ref:s,"data-sidebar":"menu-skeleton",className:sS("flex h-8 items-center gap-2 rounded-md px-2",t)},n),{},{children:[a&&(0,re.jsx)(ox,{className:"size-4 rounded-md","data-sidebar":"menu-skeleton-icon"}),(0,re.jsx)(ox,{className:"h-4 max-w-[--skeleton-width] flex-1","data-sidebar":"menu-skeleton-text",style:{"--skeleton-width":r}})]}))});HS.displayName="SidebarMenuSkeleton";const GS=H.forwardRef((e,s)=>{let{className:t}=e,a=(0,as.A)(e,NS);return(0,re.jsx)("ul",(0,K.A)({ref:s,"data-sidebar":"menu-sub",className:sS("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",t)},a))});GS.displayName="SidebarMenuSub";const $S=H.forwardRef((e,s)=>{let t=Object.assign({},((0,Ja.A)(e),e));return(0,re.jsx)("li",(0,K.A)({ref:s},t))});$S.displayName="SidebarMenuSubItem";const JS=H.forwardRef((e,s)=>{let{asChild:t=!1,size:a="md",isActive:n,className:r}=e,l=(0,as.A)(e,wS);const i=t?Ws.DX:"a";return(0,re.jsx)(i,(0,K.A)({ref:s,"data-sidebar":"menu-sub-button","data-size":a,"data-active":n,className:sS("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",r)},l))});JS.displayName="SidebarMenuSubButton";var ZS=t(92319),KS=t(22164),XS=t(31815),QS=t(69504),eC=t(13437),sC=t(11728),tC=t(15061),aC=t(14237),nC=t(88141),rC=t(81052),lC=t(18545);la().locale("en-US");class iC{constructor(e){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},t=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:M_,"react-hot-toast":Xr,moment:la(),"moment/locale/he":D_,"moment/locale/ar":L_,"moment/locale/fr":O_,"moment/locale/es":R_,react:H,"lucide-react":F_,"react-quill":Au,"@hello-pangea/dnd":W_,"date-fns":ZS,"date-fns/locale":KS,three:eC,"three/addons/controls/OrbitControls.js":sC,"three/addons/loaders/GLTFLoader.js":tC,sonner:Gp,"@stripe/stripe-js":ec,"@stripe/react-stripe-js":q_,"@radix-ui/react-toast":Ah,"@radix-ui/react-dialog":ka,"class-variance-authority":ns,"@/components/ui/sidebar":Y,"react-dom":uc,"react-dom/client":$,"react-markdown":XS,"@tanstack/react-query":QS,lodash:ss,jspdf:B_,"framer-motion":aC,"react-router-dom":J,"react-hook-form":wv,"react-quill/dist/quill.snow.css":{},"react-leaflet":z_,leaflet:U_,"leaflet/dist/leaflet.css":{},"canvas-confetti":nC,html2canvas:rC,"@/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":l,"@/components/ui/calendar":k,"@/components/ui/card":o,"@/components/ui/checkbox":j,"@/components/ui/collapsible":w,"@/components/ui/carousel":D,"@/components/ui/command":_,"@/components/ui/context-menu":M,"@/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":U,"@/components/ui/navigation-menu":z,"@/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":q,"@/components/ui/switch":C,"@/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":W,"@/components/ui/tooltip":r,"@/components/ui/sonner":V,"@base44/sdk":lC},this.globals=s,this.moduleCache={},this.compilingModules=new Set,this.importFile=this.importFile.bind(this),this.onError=t}_importAppSDK(e){let s=e;if(e.split("/").length>2&&(s=e.split("/").pop()),e.includes("/entities"))return s?(0,K.A)((0,K.A)({},this.appSDK.entities),{},{default:this.appSDK.entities[s]}):this.appSDK.entities;if(e.includes("/functions"))return s?(0,K.A)((0,K.A)({},this.appSDK.functions),{},{default:()=>alert="ok!!!"}):this.appSDK.functions;if(e.includes("/integrations")){if(s)return this.appSDK.integrations[s];let e={};return Object.keys(this.appSDK.integrations).forEach(s=>{e["@/integrations/".concat(s)]=this.appSDK.integrations[s],e["./integrations/".concat(s)]=this.appSDK.integrations[s]}),e}return"./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,s){if(e.endsWith(".css"))return this.handleCSSImport(e);const t=E_(e);if(this.appFiles[t]&&!t.includes("use-toast"))return this.importAppFile(e,s);if(e.includes("components/ui/")||e.includes("@/components/ui/")){let s=e;if(e.startsWith("./")||e.startsWith("../")){const t=e.split("/"),a=t[t.length-1];s="@/components/ui/".concat(a)}return this.importPackage(s)}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?this.importAppSDK(e):this.importAppFile(e,s):this.importPackage(e)}importPackage(e){if(!this.packages.hasOwnProperty(e)){const s=e.split("/");if(this.packages.hasOwnProperty(s[0])){let t=this.packages[s[0]];for(let a=1;a0&&r.pop():e&&r.push(e));let l=r.join("/");if(l.startsWith("./")&&(l=l.substring(2)),l.startsWith("../")&&(l=l.substring(3)),l.startsWith("@/")&&(l=l.substring(2)),t[l])return l;if(t[l+".js"])return l+".js";const i=Object.keys(t).find(s=>s.endsWith(e));if(i)return i}return a}(e,s,this.appFiles);if(this.moduleCache[t])return this.moduleCache[t];if(this.compilingModules.has(t))return{};this.compilingModules.add(t);const a=this.appFiles[t];if(!a)throw new Error("Error in ".concat(s,": can't import file ").concat(e,", it doesn't exist."));const n=function(e,s){e.includes(".")&&(e=e.split(".")[0]);const t=S_(e,s).split("\n"),a=/(<[A-Z][a-zA-Z]*|<[a-z][a-zA-Z0-9]*)(\s|>|\/>)/g;return t.map((s,t)=>{const n=t+1;return a.test(s)?(a.lastIndex=0,s.replace(a,(t,a,r)=>{const l=s.substring(0,s.indexOf(a)).includes('"')?"'":'"';return r.includes(">")?(r.indexOf(">"),"".concat(a," data-filename=").concat(l).concat(e).concat(l," data-linenumber=").concat(l).concat(n).concat(l," data-visual-selector-id=").concat(l).concat(e).concat(n).concat(l).concat(r)):"".concat(a).concat(r,"data-filename=").concat(l).concat(e).concat(l," data-linenumber=").concat(l).concat(n).concat(l," data-visual-selector-id=").concat(l).concat(e).concat(n).concat(l," ")})):s}).join("\n")}(t,a);let r;try{r=this.compileJSXToJavascript(t,n,!1)}catch(i){r=this.compileJSXToJavascript(t,a,!0)}const l=this.evaluateJavascriptCode(t,r);return this.moduleCache[t]=l,this.compilingModules.delete(t),l}compileJSXToJavascript(e,s){let t=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];if(!s||"string"!=typeof s)throw new Error('Invalid code content for "'.concat(e,'"'));const a=s.trim();let n;try{n=(0,k_.pd)(a,{transforms:["jsx","imports"],production:!1,filePath:e})}catch(l){throw t&&this.onError(null==l?void 0:l.message,null==l?void 0:l.toString(),e,l),l}let r=n.code;r.startsWith('"use strict";')&&(r=r.substring(13));return"\n // Initialize module objects\n const module = { exports: {} };\n const exports = module.exports;\n \n ".concat(r,"\n \n // No need for regex transforms - module.exports will naturally capture all exports\n ")}evaluateJavascriptCode(e,s){const t=(0,K.A)({React:H,require:s=>this.importFile(s,e),console:P_(e,this.onError)},this.globals),a=Object.keys(t),n=a.map(e=>t[e]);try{const t=new Function(...a,s+"; return { moduleExports: module.exports, exportsObj: exports };")(...n),r=t.moduleExports&&Object.keys(t.moduleExports).length>0?t.moduleExports:t.exportsObj;return I_(e,r)}catch(r){return this.onError("Error evaluating module ".concat(e,": ").concat(r.message),r.toString(),e,r),I_(e,{})}}render(e){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},t=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 r of Object.keys(a))if("function"==typeof a[r]&&(r.includes("Component")||r.endsWith("Provider")||r.startsWith("App")||"Main"===r||r.charAt(0)===r.charAt(0).toUpperCase())){n=a[r];break}if(!n)throw new Error('No component found in "'.concat(e,'"'));return H.createElement(n,s,...t)}handleCSSImport(e){const s=E_(e);if(this.constructor.injectedCSS||(this.constructor.injectedCSS=new Set),this.constructor.injectedCSS.has(s))return{};let t="";if(!this.appFiles[s])return this.packages[e],{};if(t=this.appFiles[s],t){const e=document.createElement("style");e.textContent=t,e.setAttribute("data-source",s),document.head.appendChild(e),this.constructor.injectedCSS.add(s)}return{}}}function oC(){const[e,s]=(0,H.useState)(!1),t=(0,H.useRef)(!1),[a,n]=(0,H.useState)(null),r=(0,H.useRef)([]),l=(0,H.useRef)([]),i=(0,H.useRef)([]),o=(0,H.useRef)(null),c=function(){let e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];const s=document.createElement("div");return s.style.position="absolute",s.style.pointerEvents="none",s.style.transition="all 0.1s ease-in-out",s.style.zIndex="9999",e?s.style.border="2px solid #2563EB":(s.style.border="2px dotted #2563EB",s.style.backgroundColor="rgba(99, 102, 241, 0.05)"),s},d=function(e,s){let a=arguments.length>2&&void 0!==arguments[2]&&arguments[2];if(!s||!t.current)return;s.offsetWidth;const n=s.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");const r=document.createElement("div");r.textContent=s.tagName.toLowerCase(),r.style.position="absolute",r.style.top="-27px",r.style.left="-2px",r.style.padding="2px 6px",r.style.fontSize="14px",r.style.fontWeight=a?"500":"400",r.style.color=a?"#ffffff":"#2563EB",r.style.backgroundColor=a?"#2563EB":"#DBEAFE",r.style.borderRadius="6px 6px 0px 0px",r.style.boxShadow="none",r.style.minWidth="24px",r.style.textAlign="center",e.appendChild(r)},m=e=>{if(!e)return[];const s=[...document.querySelectorAll('[data-source-location="'.concat(e,'"]'))];return s.length>0?s:[...document.querySelectorAll('[data-visual-selector-id="'.concat(e,'"]'))]},u=()=>{r.current.forEach(e=>{e&&e.parentNode&&e.remove()}),r.current=[],i.current=[]},x=e=>{if(!t.current)return;const s=e.target.closest("[data-source-location], [data-visual-selector-id]");if(!s)return void u();const a=s.dataset.sourceLocation||s.dataset.visualSelectorId;s.dataset.sourceLocation;if(o.current===a)return void u();const n=m(a);u(),n.forEach(e=>{const s=c(!1);document.body.appendChild(s),r.current.push(s),d(s,e)}),i.current=n},h=()=>{u()},p=e=>{var s;if(!t.current)return;e.preventDefault(),e.stopPropagation(),e.stopImmediatePropagation();const a=e.target.closest("[data-source-location], [data-visual-selector-id]");if(!a)return;const r=a.dataset.sourceLocation||a.dataset.visualSelectorId;a.dataset.sourceLocation;l.current.forEach(e=>{e&&e.parentNode&&e.remove()}),l.current=[];m(r).forEach(e=>{const s=c(!0);document.body.appendChild(s),l.current.push(s),d(s,e,!0)}),n(a),o.current=r,u();const i={type:"element-selected",tagName:a.tagName,classes:(null===(s=a.className)||void 0===s?void 0:s.baseVal)||a.className||"",visualSelectorId:r,content:a.innerText,dataSourceLocation:a.dataset.sourceLocation,isDynamicContent:"true"===a.dataset.dynamicContent,linenumber:a.dataset.linenumber,filename:a.dataset.filename};window.parent.postMessage(i,"*")};return(0,H.useEffect)(()=>{document.querySelectorAll("[data-visual-selector-id]");document.querySelectorAll("[data-linenumber]:not([data-visual-selector-id])").forEach((e,s)=>{const t="visual-id-".concat(e.dataset.filename,"-").concat(e.dataset.linenumber,"-").concat(s);e.dataset.visualSelectorId=t});const e=e=>{const a=e.data;switch(a.type){case"toggle-visual-edit-mode":c=a.data.enabled,s(c),t.current=c,c?(document.body.style.cursor="crosshair",document.addEventListener("mouseover",x),document.addEventListener("mouseout",h),document.addEventListener("click",p,!0)):(u(),l.current.forEach(e=>{e&&e.parentNode&&e.remove()}),l.current=[],i.current=[],n(null),o.current=null,document.body.style.cursor="default",document.removeEventListener("mouseover",x),document.removeEventListener("mouseout",h),document.removeEventListener("click",p,!0));break;case"update-classes":a.data&&void 0!==a.data.classes&&((e,s)=>{const t=m(e);0!==t.length&&(t.forEach(e=>{var t;const a=(null===(t=e.className)||void 0===t?void 0:t.baseVal)||e.className||"";e.className=(0,ls.QP)(a,s)}),setTimeout(()=>{var s,a;(o.current===e&&l.current.forEach((e,s)=>{s0)&&((null===(s=i.current[0])||void 0===s||null===(a=s.dataset)||void 0===a?void 0:a.visualSelectorId)===e&&r.current.forEach((e,s)=>{s{e&&e.parentNode&&e.remove()}),l.current=[],n(null),o.current=null;break;case"refresh-page":window.location.reload();break;case"update-content":a.data&&void 0!==a.data.content&&((e,s)=>{const t=m(e);0!==t.length&&(t.forEach(e=>{e.innerText=s}),setTimeout(()=>{o.current===e&&l.current.forEach((e,s)=>{s{window.removeEventListener("message",e),document.removeEventListener("mouseover",x),document.removeEventListener("mouseout",h),document.removeEventListener("click",p,!0),u(),l.current.forEach(e=>{e&&e.parentNode&&e.remove()})}},[]),(0,H.useEffect)(()=>{t.current=e},[e]),(0,H.useEffect)(()=>{const e=()=>{if(o.current){const e=m(o.current);l.current.forEach((s,t)=>{t0&&r.current.forEach((e,s)=>{s{s.some(e=>{const s=e=>{if(e.nodeType===Node.ELEMENT_NODE){if(e.dataset&&e.dataset.visualSelectorId)return!0;for(let t=0;t{window.removeEventListener("resize",e),window.removeEventListener("scroll",e),s.disconnect()}},[]),null}function cC(e){let{appId:s}=e;const[t,a]=(0,H.useState)(!1),[n,r]=(0,H.useState)(!0);(0,H.useEffect)(()=>{"true"===new URLSearchParams(window.location.search).get("hide_badge")&&r(!1)},[]);return n?(0,re.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(s),"_blank"),a(!1)},children:[(0,re.jsx)("img",{src:"https://base44.app/logo_v3.png",alt:"base44",className:"w-5 h-5"}),(0,re.jsx)("span",{className:"whitespace-nowrap text-xs",children:t?(0,re.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,re.jsx)(Ze.A,{className:"w-3 h-3 animate-spin"}),(0,re.jsx)("span",{children:"Cloning..."})]}):(0,re.jsxs)("div",{className:"flex items-center gap-1.5 align-middle justify-center text-sm",children:[(0,re.jsx)("span",{children:"Edit with "}),(0,re.jsx)("span",{className:"mb-0.5",children:(0,re.jsx)("img",{src:"/base44_text.png",alt:"Base44",height:18,width:56})})]})}),(0,re.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(),r(!1)},children:(0,re.jsx)(zs.A,{className:"w-3.5 h-3.5"})})]}):null}function dC(e){let{}=e;const{user:s,isAuthenticated:t}=y_(),{pageName:a}=(0,Z.g)();return(0,re.jsx)("div",{className:"min-h-screen flex items-center justify-center p-6 bg-slate-50",children:(0,re.jsx)("div",{className:"max-w-md w-full",children:(0,re.jsxs)("div",{className:"text-center space-y-6",children:[(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsx)("h1",{className:"text-7xl font-light text-slate-300",children:"404"}),(0,re.jsx)("div",{className:"h-0.5 w-16 bg-slate-200 mx-auto"})]}),(0,re.jsxs)("div",{className:"space-y-3",children:[(0,re.jsx)("h2",{className:"text-2xl font-medium text-slate-800",children:"Page Not Found"}),(0,re.jsxs)("p",{className:"text-slate-600 leading-relaxed",children:["The page ",(0,re.jsxs)("span",{className:"font-medium text-slate-700",children:['"',a,'"']})," could not be found in this application."]})]}),t&&"admin"===(null==s?void 0:s.role)&&(0,re.jsx)("div",{className:"mt-8 p-4 bg-slate-100 rounded-lg border border-slate-200",children:(0,re.jsxs)("div",{className:"flex items-start space-x-3",children:[(0,re.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,re.jsx)("div",{className:"w-2 h-2 rounded-full bg-orange-400"})}),(0,re.jsxs)("div",{className:"text-left space-y-1",children:[(0,re.jsx)("p",{className:"text-sm font-medium text-slate-700",children:"Admin Note"}),(0,re.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,re.jsx)("div",{className:"pt-6",children:(0,re.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,re.jsx)("svg",{className:"w-4 h-4 mr-2",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,re.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 mC=()=>(0,re.jsx)("div",{className:"flex flex-col items-center justify-center min-h-screen bg-gradient-to-b from-white to-gray-50",children:(0,re.jsx)("div",{className:"max-w-md w-full p-8 bg-white rounded-lg shadow-lg border border-gray-100",children:(0,re.jsxs)("div",{className:"text-center",children:[(0,re.jsx)("div",{className:"inline-flex items-center justify-center w-16 h-16 mb-6 rounded-full bg-red-100",children:(0,re.jsx)("svg",{className:"w-8 h-8 text-red-600",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,re.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,re.jsx)("h1",{className:"text-3xl font-bold text-gray-900 mb-4",children:"Access Restricted"}),(0,re.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,re.jsxs)("div",{className:"p-4 bg-gray-50 rounded-md text-sm text-gray-600",children:[(0,re.jsx)("p",{children:"If you believe this is an error, you can:"}),(0,re.jsxs)("ul",{className:"list-disc list-inside mt-2 space-y-1",children:[(0,re.jsx)("li",{children:"Verify you are logged in with the correct account"}),(0,re.jsx)("li",{children:"Contact the app administrator for access"}),(0,re.jsx)("li",{children:"Try logging out and back in again"})]})]})]})})});function uC(e){var s,t,a,n;let{appId:r}=e;const{isAuthenticated:l,isLoadingAuth:i,logout:o}=y_(),c=(0,Z.zy)(),d=(0,Z.Zp)(),{appId:m,pageName:u}=(0,Z.g)(),[x,h]=(0,H.useState)(null),[p,g]=(0,H.useState)(null),[f,v]=(0,H.useState)(!0),b=e=>{const s=new iC(e,{cn:is,localStorage:C_()},(s,t,a,n)=>{e.options.onError(s,t,a,n)}),t=e.getCurrentPage();if(!t)return void g((0,re.jsx)(dC,{}));const a=s.render("pages/"+t.name);if(e.files.layout){const e=s.render("layout",{currentPageName:null==t?void 0:t.name},[a]);g(e)}else g(a)};(0,H.useEffect)(()=>{__({id:r||m,onError:j,authProps:{isLoadingAuth:i,logout:o,isUserAuthenticated:()=>l}}).then(e=>{h(e)}).catch(e=>{var s,t,a,n,r,l,i,o;e.response&&403===e.response.status&&null!==(s=e.response.data)&&void 0!==s&&null!==(t=s.extra_data)&&void 0!==t&&t.reason?"auth_required"===(null===(a=e.response.data)||void 0===a||null===(n=a.extra_data)||void 0===n?void 0:n.reason)?w(null===(i=e.response.data)||void 0===i||null===(o=i.extra_data)||void 0===o?void 0:o.app_id):"user_not_registered"===(null===(r=e.response.data)||void 0===r||null===(l=r.extra_data)||void 0===l?void 0:l.reason)&&v(!1):j("Failed to load app "+e.message,"none","general",e)})},[]);const j=(e,s,t,a)=>{var n,r;402!==(null==a||null===(n=a.response)||void 0===n?void 0:n.status)&&(null===(r=window.parent)||void 0===r||r.postMessage({type:"app_error",error:{title:e.toString(),details:null==s?void 0:s.toString(),componentName:null==t?void 0:t.toString()}},"*"))};(0,H.useEffect)(()=>{window.parent.postMessage({type:"app_changed_url",url:window.location.href},"*"),x&&b(x)},[c,u,x]);const y=e=>{var s;const t=null===(s=e.reason.stack.match(/at\s+(\w+)\s+\(eval/))||void 0===s?void 0:s[1],a=t?"Error in ".concat(t,": ").concat(e.reason.toString()):e.reason.toString();j(a,e.reason.toString(),t,e.reason)},N=e=>{var s,t;let a=null===(t=(null===(s=e.error)||void 0===s?void 0:s.stack).match(/at\s+(\w+)\s+\(eval/))||void 0===t?void 0:t[1];"eval"===a&&(a=null);const n=a?"in ".concat(a,": ").concat(e.error.toString()):e.error.toString();j(n,e.error.toString(),a,e.error)};(0,H.useEffect)(()=>(window.addEventListener("unhandledrejection",y),window.addEventListener("error",N),()=>{window.removeEventListener("unhandledrejection",y),window.removeEventListener("error",N)}),[]);const w=e=>{d("/login?from_url=".concat(window.location.href,"&app_id=").concat(e))};return(0,H.useEffect)(()=>{let e=null==x?void 0:x.getCurrentPage();l&&null!=x&&x.appId&&null!=e&&e.name&&wa.logUserInApp(x.appId,e.name)},[l,null==x?void 0:x.appId,null==x||null===(s=x.getCurrentPage())||void 0===s?void 0:s.name]),f?x?i?(0,re.jsx)("div",{className:"fixed inset-0 flex items-center justify-center",children:(0,re.jsx)("div",{className:"w-8 h-8 border-4 border-gray-200 border-t-black rounded-full animate-spin"})}):(0,re.jsxs)("div",{className:"min-h-screen w-full relative app-preview",children:[(0,re.jsx)(oC,{}),(null==x||null===(t=x.files)||void 0===t?void 0:t.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,re.jsx)(cC,{appId:r}),(0,re.jsx)("div",{className:"flex flex-col w-full h-full",id:"app-demo",children:(0,re.jsx)("div",{className:"bg-white w-full min-h-full overflow-auto",children:(0,re.jsx)("div",{id:"component-preview-container",children:p})})})]}):(0,re.jsx)("div",{className:"fixed inset-0 flex items-center justify-center",children:(0,re.jsx)("div",{className:"flex flex-col items-center space-y-4",children:(0,re.jsx)("div",{className:"w-12 h-12 border-4 border-gray-200 border-t-black rounded-full animate-spin"})})}):(0,re.jsx)(mC,{})}function xC(e){let{appId:s,appPlatformVersion:t,authSDK:a,onSuccess:n,onSwitchToRegister:r,onSwitchToResetPassword:l}=e;const[i,o]=(0,H.useState)(""),[c,d]=(0,H.useState)(""),[m,u]=(0,H.useState)(""),[x,h]=(0,H.useState)(!1);return(0,re.jsxs)("form",{onSubmit:async e=>{e.preventDefault(),u(""),h(!0);try{if(3===t){const e=(0,lC.createClient)({appId:s,serverUrl:(0,ee.wE)()}),t=await e.auth.loginViaEmailPassword(i,c);t&&n(t.user)}else{const e=await a.loginViaUsernamePassword(i,c);e&&((0,ne.O5)(e.access_token),n(e.user))}}catch(o){var r,l;u((null===(r=o.response)||void 0===r||null===(l=r.data)||void 0===l?void 0:l.detail)||"Invalid email or password")}finally{h(!1)}},className:"space-y-4 sm:space-y-5",children:[(0,re.jsxs)("div",{className:"space-y-3 sm:space-y-4",children:[(0,re.jsxs)("div",{className:"space-y-1.5",children:[(0,re.jsx)(Nt,{htmlFor:"email",className:"text-sm font-medium text-slate-700",children:"Email"}),(0,re.jsxs)("div",{className:"relative",children:[(0,re.jsx)(Im.A,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-slate-400"}),(0,re.jsx)(ft,{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,re.jsxs)("div",{className:"space-y-1.5",children:[(0,re.jsx)(Nt,{htmlFor:"password",className:"text-sm font-medium text-slate-700",children:"Password"}),(0,re.jsxs)("div",{className:"relative",children:[(0,re.jsx)(Fs.A,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-slate-400"}),(0,re.jsx)(ft,{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,re.jsx)(us,{className:"bg-red-50/70 border-red-200 rounded-xl",children:(0,re.jsx)(hs,{className:"text-red-700 text-sm",children:m})}),(0,re.jsxs)("div",{className:"space-y-3",children:[(0,re.jsx)(Hs,{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,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(Ze.A,{className:"mr-2 h-4 w-4 animate-spin"}),"Signing in..."]}):"Sign in"}),(0,re.jsxs)("div",{className:"flex flex-col sm:flex-row items-center justify-between gap-2 sm:gap-0",children:[(0,re.jsx)("button",{type:"button",onClick:l,className:"text-sm text-slate-500 hover:text-slate-700 font-medium transition-colors",children:"Forgot password?"}),(0,re.jsxs)("button",{type:"button",onClick:r,className:"text-sm text-slate-500 hover:text-slate-700 transition-colors",children:["Need an account? ",(0,re.jsx)("span",{className:"font-medium text-slate-700",children:"Sign up"})]})]})]})]})}function hC(e){let{authSDK:s,onSuccess:t,onSwitchToLogin:a,onSwitchToOtpVerification:n}=e;const[r,l]=(0,H.useState)({email:"",password:"",confirmPassword:""}),[i,o]=(0,H.useState)(""),[c,d]=(0,H.useState)(!1),m=(e,s)=>{l(t=>(0,K.A)((0,K.A)({},t),{},{[e]:s}))};return(0,re.jsxs)("div",{className:"space-y-4",children:[(0,re.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,re.jsx)(Cc.A,{className:"h-4 w-4"}),"Back to sign in"]}),(0,re.jsx)("h2",{className:"text-xl sm:text-2xl font-bold text-slate-900",children:"Create your account"}),(0,re.jsxs)("form",{onSubmit:async e=>{if(e.preventDefault(),o(""),r.password===r.confirmPassword)if(r.password.length<8)o("Password must be at least 8 characters long");else{d(!0);try{await s.register({email:r.email,password:r.password})&&n(r.email)}catch(l){var t,a;o((null===(t=l.response)||void 0===t||null===(a=t.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,re.jsxs)("div",{className:"space-y-3",children:[(0,re.jsxs)("div",{className:"space-y-1.5",children:[(0,re.jsx)(Nt,{htmlFor:"email",className:"text-sm font-medium text-slate-700",children:"Email"}),(0,re.jsxs)("div",{className:"relative",children:[(0,re.jsx)(Im.A,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-slate-400"}),(0,re.jsx)(ft,{id:"email",type:"email",placeholder:"you@example.com",value:r.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,re.jsxs)("div",{className:"space-y-1.5",children:[(0,re.jsx)(Nt,{htmlFor:"password",className:"text-sm font-medium text-slate-700",children:"Password"}),(0,re.jsxs)("div",{className:"relative",children:[(0,re.jsx)(Fs.A,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-slate-400"}),(0,re.jsx)(ft,{id:"password",type:"password",placeholder:"Min. 8 characters",value:r.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,re.jsxs)("div",{className:"space-y-1.5",children:[(0,re.jsx)(Nt,{htmlFor:"confirmPassword",className:"text-sm font-medium text-slate-700",children:"Confirm Password"}),(0,re.jsxs)("div",{className:"relative",children:[(0,re.jsx)(Fs.A,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-slate-400"}),(0,re.jsx)(ft,{id:"confirmPassword",type:"password",placeholder:"Re-enter password",value:r.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,re.jsx)(us,{className:"bg-red-50/70 border-red-200 rounded-xl",children:(0,re.jsx)(hs,{className:"text-red-700 text-sm",children:i})}),(0,re.jsx)(Hs,{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,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(Ze.A,{className:"mr-2 h-4 w-4 animate-spin"}),"Creating account..."]}):"Create account"})]})]})}function pC(e){let{authSDK:s,email:t,onSuccess:a,onSwitchToLogin:n}=e;const[r,l]=(0,H.useState)(["","","","","",""]),[i,o]=(0,H.useState)(""),[c,d]=(0,H.useState)(""),[m,u]=(0,H.useState)(!1),[x,h]=(0,H.useState)(!1),p=(0,H.useRef)([]);(0,H.useEffect)(()=>{var e;null===(e=p.current[0])||void 0===e||e.focus()},[]);const g=e=>{e.preventDefault();const s=e.clipboardData.getData("text").slice(0,6),t=[...r];for(let r=0;r!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,re.jsxs)("div",{className:"space-y-4 sm:space-y-6",children:[(0,re.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,re.jsx)(Cc.A,{className:"h-4 w-4"}),"Back to sign in"]}),(0,re.jsxs)("div",{className:"text-center space-y-2",children:[(0,re.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,re.jsx)(Ho.A,{className:"h-7 w-7 sm:h-8 sm:w-8 text-slate-700"})}),(0,re.jsx)("h2",{className:"text-xl sm:text-2xl font-bold text-slate-900",children:"Verify your email"}),(0,re.jsxs)("p",{className:"text-slate-600 text-sm sm:text-base",children:["We've sent a 6-digit code to",(0,re.jsx)("br",{}),(0,re.jsx)("span",{className:"font-medium text-slate-900",children:t})]})]}),(0,re.jsxs)("form",{onSubmit:async e=>{e.preventDefault(),o(""),d("");const a=r.join("");if(6===a.length){u(!0);try{await s.verifyOtp(t,a)&&(d("Email verified successfully! Redirecting to login..."),setTimeout(()=>{n()},2e3))}catch(c){var l,i;o((null===(l=c.response)||void 0===l||null===(i=l.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,re.jsxs)("div",{children:[(0,re.jsx)("div",{className:"flex gap-2 justify-center",children:r.map((e,s)=>(0,re.jsx)(ft,{ref:e=>p.current[s]=e,type:"text",inputMode:"numeric",pattern:"\\d{1}",maxLength:1,value:e,onChange:e=>((e,s)=>{if(s.length>1)return;const t=[...r];var a;t[e]=s,l(t),s&&e<5&&(null===(a=p.current[e+1])||void 0===a||a.focus())})(s,e.target.value),onKeyDown:e=>((e,s)=>{var t;"Backspace"===s.key&&!r[e]&&e>0&&(null===(t=p.current[e-1])||void 0===t||t.focus())})(s,e),onPaste:0===s?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"},s))}),(0,re.jsx)("p",{className:"text-xs text-slate-500 text-center mt-3",children:"Enter the verification code sent to your email"})]}),i&&(0,re.jsx)(us,{className:"bg-red-50/70 border-red-200 rounded-xl",children:(0,re.jsx)(hs,{className:"text-red-700 text-sm",children:i})}),c&&(0,re.jsx)(us,{className:"bg-green-50/70 border-green-200 rounded-xl",children:(0,re.jsx)(hs,{className:"text-green-700 text-sm",children:c})}),(0,re.jsxs)("div",{className:"space-y-3",children:[(0,re.jsx)(Hs,{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,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(Ze.A,{className:"mr-2 h-4 w-4 animate-spin"}),"Verifying..."]}):"Verify email"}),(0,re.jsx)("div",{className:"text-center",children:(0,re.jsxs)("p",{className:"text-sm text-slate-600",children:["Didn't receive the code?"," ",(0,re.jsx)("button",{type:"button",onClick:async()=>{o(""),d(""),h(!0);try{var e;await s.resendOtp(t),d("New verification code sent to your email"),l(["","","","","",""]),null===(e=p.current[0])||void 0===e||e.focus()}catch(r){var a,n;o((null===(a=r.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 gC(e){let{authSDK:s,onSwitchToLogin:t}=e;const[a,n]=(0,H.useState)(""),[r,l]=(0,H.useState)(""),[i,o]=(0,H.useState)(!1),[c,d]=(0,H.useState)(!1);return i?(0,re.jsxs)("div",{className:"space-y-4 sm:space-y-6",children:[(0,re.jsxs)("div",{className:"text-center space-y-3 sm:space-y-4",children:[(0,re.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,re.jsx)(Im.A,{className:"h-7 w-7 sm:h-8 sm:w-8 text-slate-700"})}),(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsx)("h2",{className:"text-xl sm:text-2xl font-bold text-slate-900",children:"Check your email"}),(0,re.jsxs)("p",{className:"text-slate-600 text-sm sm:text-base",children:["We've sent password reset instructions to",(0,re.jsx)("br",{}),(0,re.jsx)("span",{className:"font-medium text-slate-900",children:a})]})]})]}),(0,re.jsx)(us,{className:"bg-green-50/70 border-green-200 rounded-xl",children:(0,re.jsx)(hs,{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,re.jsxs)("button",{onClick:t,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,re.jsx)(Cc.A,{className:"h-4 w-4"}),"Back to sign in"]})]}):(0,re.jsxs)("div",{className:"space-y-4 sm:space-y-6",children:[(0,re.jsxs)("button",{type:"button",onClick:t,className:"flex items-center gap-2 text-sm text-slate-500 hover:text-slate-700 font-medium transition-colors -mb-2",children:[(0,re.jsx)(Cc.A,{className:"h-4 w-4"}),"Back to sign in"]}),(0,re.jsxs)("div",{className:"text-center space-y-2",children:[(0,re.jsx)("h2",{className:"text-xl sm:text-2xl font-bold text-slate-900",children:"Reset your password"}),(0,re.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,re.jsxs)("form",{onSubmit:async e=>{e.preventDefault(),l(""),o(!1),d(!0);try{await s.resetPasswordRequest(a),o(!0)}catch(r){var t,n;l((null===(t=r.response)||void 0===t||null===(n=t.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,re.jsxs)("div",{className:"space-y-1.5",children:[(0,re.jsx)(Nt,{htmlFor:"email",className:"text-sm font-medium text-slate-700",children:"Email"}),(0,re.jsxs)("div",{className:"relative",children:[(0,re.jsx)(Im.A,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-slate-400"}),(0,re.jsx)(ft,{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"})]})]}),r&&(0,re.jsx)(us,{className:"bg-red-50/70 border-red-200 rounded-xl",children:(0,re.jsx)(hs,{className:"text-red-700 text-sm",children:r})}),(0,re.jsx)(Hs,{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,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(Ze.A,{className:"mr-2 h-4 w-4 animate-spin"}),"Sending..."]}):"Send reset link"})]})]})}const fC=()=>(0,re.jsxs)("svg",{className:"h-5 w-5",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:[(0,re.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,re.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,re.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,re.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"})]}),vC=()=>(0,re.jsxs)("svg",{className:"h-5 w-5",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:[(0,re.jsx)("path",{fill:"#F25022",d:"M1 1h10v10H1z"}),(0,re.jsx)("path",{fill:"#00A4EF",d:"M13 1h10v10H13z"}),(0,re.jsx)("path",{fill:"#7FBA00",d:"M1 13h10v10H1z"}),(0,re.jsx)("path",{fill:"#FFB900",d:"M13 13h10v10H13z"})]}),bC=()=>(0,re.jsx)("svg",{className:"h-5 w-5",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:(0,re.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"})}),jC={google:{name:"Google",icon:fC},microsoft:{name:"Microsoft",icon:vC},github:{name:"GitHub",icon:()=>(0,re.jsx)("svg",{className:"h-5 w-5",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:(0,re.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,re.jsx)("svg",{className:"h-5 w-5",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:(0,re.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 yC(e){var s;let{appId:t}=e;const a=(0,Z.zy)(),n=w_(t,()=>{},{}),[r,l]=(0,H.useState)(!0),[i,o]=(0,H.useState)(null),[c,d]=(0,H.useState)(null),[m,u]=(0,H.useState)("login"),[x,h]=(0,H.useState)(""),p=new URLSearchParams(a.search),g=e=>{const s=p.get("from_url")||"/",a=p.get("app_id")||t;let n;n="google"===e?"".concat((0,ee.Zk)(),"/apps/auth/login?from_url=").concat(s):"".concat((0,ee.Zk)(),"/apps/auth/").concat(e,"/login?from_url=").concat(s),a&&(n+="&app_id=".concat(a)),window.location.href=n},f=()=>{const e=p.get("from_url")||"/",s=p.get("app_id")||t;let a="".concat((0,ee.Zk)(),"/apps/").concat(s,"/auth/sso/login?from_url=").concat(e);s&&(a+="&app_id=".concat(s)),window.location.href=a},v=e=>{const s=p.get("from_url")||"/";window.location.href=s},b=e=>{h(e),u("otp")},j=px(c),y=[{id:"google",name:"Google",enabled:!1!==j.enable_google_login,handler:()=>g("google"),icon:fC},{id:"microsoft",name:"Microsoft",enabled:j.enable_microsoft_login,handler:()=>g("microsoft"),icon:vC},{id:"facebook",name:"Facebook",enabled:j.enable_facebook_login,handler:()=>g("facebook"),icon:bC}],N=j.enable_sso_login?[]:y.filter(e=>e.enabled),w=e=>{const s=e.icon;return(0,re.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,re.jsx)("div",{className:" transition-transform duration-200 ".concat("google"===e.id?"-ml-4":""),children:(0,re.jsx)(s,{})}),(0,re.jsxs)("span",{children:["Continue with ",e.name]})]},e.id)},_=()=>{if(!j.sso_provider_name||!1===j.enable_sso_login)return null;const e=jC[j.sso_provider_name],s=e?"Continue with ".concat(e.name):"Continue with SSO",t=null==e?void 0:e.icon;return(0,re.jsxs)("button",{onClick:f,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:[t&&(0,re.jsx)("div",{className:"group-hover:scale-110 transition-transform duration-200",children:(0,re.jsx)(t,{})}),(0,re.jsx)("span",{children:s})]})};if((0,H.useEffect)(()=>{(async()=>{try{const e=await ve.getLoginInfoById(t);d(e),l(!1)}catch(i){o(i),l(!1)}})()},[t]),r)return(0,re.jsx)("div",{className:"min-h-screen flex items-center justify-center bg-gradient-to-br from-slate-50 to-slate-100",children:(0,re.jsx)("div",{className:"p-8",children:(0,re.jsx)(Ze.A,{className:"h-10 w-10 animate-spin text-slate-400"})})});if(i)return(0,re.jsx)("div",{className:"min-h-screen flex items-center justify-center bg-gradient-to-br from-slate-50 to-slate-100",children:(0,re.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,re.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,re.jsxs)("div",{className:"w-full max-w-md",children:[(0,re.jsxs)(it,{className:"relative overflow-hidden border-0 shadow-2xl bg-white/95 backdrop-blur-sm rounded-2xl",children:[(0,re.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,re.jsx)(mt,{className:"p-8 sm:p-10 md:pt-12 md:pb-10 md:px-10",children:(0,re.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,re.jsxs)("div",{className:"relative group",children:[(0,re.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,re.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,re.jsx)(ua,{src:c.logo_url,alt:"".concat(c.name," logo"),className:"object-cover"}),(0,re.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===(s=c.name)||void 0===s?void 0:s[0]})]})]}),"login"===m&&(0,re.jsxs)("div",{className:"space-y-2 sm:space-y-3",children:[(0,re.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,re.jsx)("p",{className:"text-slate-500 text-sm sm:text-base font-medium",children:"Sign in to continue"})]}),(0,re.jsx)("div",{className:"w-full",children:(()=>{if(j.enable_username_password)switch(m){case"register":return(0,re.jsx)(hC,{authSDK:n,onSuccess:v,onSwitchToLogin:()=>u("login"),onSwitchToOtpVerification:b});case"otp":return(0,re.jsx)(pC,{authSDK:n,email:x,onSuccess:v,onSwitchToLogin:()=>u("login")});case"reset":return(0,re.jsx)(gC,{authSDK:n,onSwitchToLogin:()=>u("login")});default:return(0,re.jsxs)(re.Fragment,{children:[(0,re.jsxs)("div",{className:"space-y-3",children:[N.map(e=>w(e)),_()]}),(N.length>0||_())&&(0,re.jsxs)("div",{className:"relative my-6",children:[(0,re.jsx)("div",{className:"absolute inset-0 flex items-center",children:(0,re.jsx)(pt,{className:"w-full bg-slate-200"})}),(0,re.jsx)("div",{className:"relative flex justify-center text-xs uppercase",children:(0,re.jsx)("span",{className:"bg-white px-3 text-slate-400 font-medium tracking-wider",children:"or"})})]}),(0,re.jsx)(xC,{appId:t,appPlatformVersion:null==c?void 0:c.platform_version,authSDK:n,onSuccess:v,onSwitchToRegister:()=>u("register"),onSwitchToResetPassword:()=>u("reset")})]})}return(0,re.jsxs)("div",{className:"space-y-3",children:[N.map(e=>w(e)),_()]})})()})]})})]}),(0,re.jsx)("div",{className:"mt-8 text-center text-xs text-slate-400 sm:hidden",children:(0,re.jsx)("p",{children:"\xa0"})})]})})}function NC(e){let{appId:s}=e;const t=(0,Z.zy)(),a=(0,Z.Zp)(),n=w_(s,()=>{},{}),r=new URLSearchParams(t.search).get("token"),[l,i]=(0,H.useState)({password:"",confirmPassword:""}),[o,c]=(0,H.useState)(""),[d,m]=(0,H.useState)(!1),[u,x]=(0,H.useState)(!1),[h,p]=(0,H.useState)(null),[g,f]=(0,H.useState)(!0);(0,H.useEffect)(()=>{(async()=>{try{const e=await ve.getLoginInfoById(s);p(e)}catch(o){}finally{f(!1)}})(),r||c("Invalid reset link. Please request a new password reset.")},[r,s]);const v=(e,s)=>{i(t=>(0,K.A)((0,K.A)({},t),{},{[e]:s}))};return g?(0,re.jsx)("div",{className:"min-h-screen flex items-center justify-center bg-gray-50",children:(0,re.jsx)("div",{className:"p-8",children:(0,re.jsx)(Ze.A,{className:"h-10 w-10 animate-spin text-gray-600"})})}):u?(0,re.jsx)("div",{className:"min-h-screen flex items-center justify-center bg-gray-50 p-4",children:(0,re.jsx)(it,{className:"max-w-md w-full overflow-hidden border-0 shadow-lg bg-white",children:(0,re.jsxs)(mt,{className:"pt-12 pb-10 px-12 text-center space-y-6",children:[(0,re.jsx)("div",{className:"mx-auto w-20 h-20 bg-gray-100 rounded-full flex items-center justify-center",children:(0,re.jsx)(Px.A,{className:"h-10 w-10 text-green-600"})}),(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsx)("h2",{className:"text-2xl font-bold text-gray-900",children:"Password reset successful!"}),(0,re.jsx)("p",{className:"text-gray-600",children:"Your password has been reset. Redirecting to login..."})]}),(null==h?void 0:h.name)&&(0,re.jsxs)("p",{className:"text-sm text-gray-500",children:["You can now sign in to ",h.name," with your new password"]})]})})}):r?(0,re.jsx)("div",{className:"min-h-screen flex items-center justify-center bg-gray-50 p-4",children:(0,re.jsxs)(it,{className:"relative max-w-md w-full overflow-hidden border-0 shadow-lg bg-white",children:[(0,re.jsx)("div",{className:"absolute top-0 left-0 right-0 h-0.5 bg-gray-900"}),(0,re.jsxs)(mt,{className:"pt-12 pb-10 px-12 space-y-8",children:[(0,re.jsxs)("div",{className:"text-center space-y-2",children:[(0,re.jsx)("h2",{className:"text-2xl font-bold text-gray-900",children:"Set new password"}),(0,re.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,re.jsxs)("form",{onSubmit:async e=>{if(e.preventDefault(),c(""),l.password===l.confirmPassword)if(l.password.length<8)c("Password must be at least 8 characters long");else{m(!0);try{await n.resetPassword(r,l.password),x(!0),setTimeout(()=>{a("/login")},3e3)}catch(i){var s,t;c((null===(s=i.response)||void 0===s||null===(t=s.data)||void 0===t?void 0:t.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,re.jsxs)("div",{className:"space-y-5",children:[(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsx)(Nt,{htmlFor:"password",className:"text-sm font-medium text-gray-700",children:"New Password"}),(0,re.jsxs)("div",{className:"relative",children:[(0,re.jsx)(Fs.A,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-gray-400"}),(0,re.jsx)(ft,{id:"password",type:"password",placeholder:"\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022",value:l.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,re.jsx)("p",{className:"text-xs text-gray-500",children:"Must be at least 8 characters"})]}),(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsx)(Nt,{htmlFor:"confirmPassword",className:"text-sm font-medium text-gray-700",children:"Confirm New Password"}),(0,re.jsxs)("div",{className:"relative",children:[(0,re.jsx)(Fs.A,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-gray-400"}),(0,re.jsx)(ft,{id:"confirmPassword",type:"password",placeholder:"\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022",value:l.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,re.jsx)(us,{className:"bg-red-50/50 border-red-200",children:(0,re.jsx)(hs,{className:"text-red-800 text-sm",children:o})}),(0,re.jsxs)("div",{className:"space-y-3",children:[(0,re.jsx)(Hs,{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,re.jsxs)(re.Fragment,{children:[(0,re.jsx)(Ze.A,{className:"mr-2 h-4 w-4 animate-spin"}),"Resetting password..."]}):"Reset password"}),(0,re.jsx)("button",{type:"button",onClick:()=>a("/login"),className:"w-full text-sm text-gray-600 hover:text-gray-700",children:"Back to login"})]})]})]})]})}):(0,re.jsx)("div",{className:"min-h-screen flex items-center justify-center bg-gray-50 p-4",children:(0,re.jsx)(it,{className:"max-w-md w-full overflow-hidden border-0 shadow-lg bg-white",children:(0,re.jsxs)(mt,{className:"pt-12 pb-10 px-12 text-center space-y-6",children:[(0,re.jsx)("div",{className:"mx-auto w-20 h-20 bg-red-100 rounded-full flex items-center justify-center",children:(0,re.jsx)(Xe.A,{className:"h-10 w-10 text-red-600"})}),(0,re.jsxs)("div",{className:"space-y-2",children:[(0,re.jsx)("h2",{className:"text-2xl font-bold text-gray-900",children:"Invalid Reset Link"}),(0,re.jsx)("p",{className:"text-gray-600",children:"This password reset link is invalid or has expired."})]}),(0,re.jsx)(Hs,{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 wC(e){let{}=e;const[s,t]=(0,H.useState)(null),[a,n]=(0,H.useState)(null),[r,l]=(0,H.useState)(!0),i=window.location.host.includes("localhost")?window.location.host:window.location.hostname,[o]=(0,H.useState)(()=>new p_.E);return(0,H.useEffect)(()=>{ve.getDomainAppId(i).then(e=>{t(e),window.appId=e,l(!1)}).catch(e=>{n(!0),l(!1)})},[]),r?(0,re.jsx)("div",{className:"fixed inset-0 flex items-center justify-center",children:(0,re.jsx)("div",{className:"w-12 h-12 border-4 border-gray-200 border-t-black rounded-full animate-spin"})}):a?(0,re.jsx)("div",{className:"flex items-center justify-center min-h-screen p-4",children:(0,re.jsxs)("div",{className:"text-center",children:[(0,re.jsx)("h1",{className:"text-2xl font-bold mb-4",children:"Domain Not Recognized"}),(0,re.jsx)("p",{className:"mb-2",children:"This domain is not associated with any Base44 app."}),(0,re.jsxs)("p",{children:["Please contact support at ",(0,re.jsx)("button",{type:"button",onClick:()=>window.open("/support","_blank"),className:"underline text-primary hover:text-orange-500 transition-colors",children:"support system"})," for assistance."]})]})}):(0,re.jsxs)(J.BrowserRouter,{children:[(0,re.jsx)("div",{children:(0,re.jsx)(Xr.Toaster,{})}),(0,re.jsx)("div",{children:(0,re.jsx)(eS,{})}),(0,re.jsx)("div",{children:(0,re.jsx)(Xr.Toaster,{})}),(0,re.jsx)(j_,{appId:s,children:(0,re.jsx)(g_.Ht,{client:o,children:(0,re.jsxs)(Z.BV,{children:[(0,re.jsx)(Z.qh,{path:"/login",element:(0,re.jsx)(yC,{appId:s})}),(0,re.jsx)(Z.qh,{path:"/reset-password",element:(0,re.jsx)(NC,{appId:s})}),(0,re.jsx)(Z.qh,{path:"/:pageName?",element:(0,re.jsx)(uC,{appId:s})})]})})})]})}var _C=t(12055);let kC=!1;const AC=[],SC=async e=>{var s;if(!kC&&e)for(await(s=e.email,new Promise(e=>{var t,a,n,r,l,i;window.fbq||(t=window,a=document,n="script",t.fbq||(r=t.fbq=function(){r.callMethod?r.callMethod.apply(r,arguments):r.queue.push(arguments)},t._fbq||(t._fbq=r),r.push=r,r.loaded=!0,r.version="2.0",r.queue=[],(l=a.createElement(n)).async=!0,l.src="https://connect.facebook.net/en_US/fbevents.js",(i=a.getElementsByTagName(n)[0]).parentNode.insertBefore(l,i)),window.fbq("init","2102574843552117",s?{em:s}:{})),e()})),kC=!0;AC.length>0;){AC.shift()()}};function CC(){const{user:e,isLoadingAuth:s}=oe(),t=(0,Z.zy)(),a="true"===new URLSearchParams(t.search).get("is_new_user"),n=(0,H.useRef)(!1);return(0,H.useEffect)(()=>{!s&&e&&(SC(e),a&&!n.current&&(n.current=!0,Ie("Registration Completed",{}),ko("registration_completed",{email:Co()(e.email),user_id:e.id,registration_method:"google"}),Ae(e.id),(0,_C.V)("is_new_user")))},[s,e,a]),null}let EC=!1;function IC(){return(0,H.useEffect)(()=>{new Promise(e=>{if(window.turnstile||EC)return void e();const s=document.createElement("script");s.src="https://challenges.cloudflare.com/turnstile/v0/api.js",s.async=!0,s.defer=!0,s.onload=()=>{EC=!0,e()},s.onerror=()=>{e()},document.head.appendChild(s)})},[]),null}function TC(e){let{page:s}=e;const t=!(!1===s.requiresAuth),a=!(!1===s.usesLayout),n=e_.filter(e=>!1!==e.showInMenu);let r=a?(0,re.jsx)(h_,{pages:n,children:s.component}):s.component;return t&&(r=(0,re.jsx)(PC,{children:r})),r}const PC=e=>{let{children:s}=e;const{isAuthenticated:t,isLoadingAuth:a}=oe();if(a)return(0,re.jsx)("div",{className:"flex justify-center items-center h-screen",children:(0,re.jsx)(Ze.A,{className:"h-8 w-8 animate-spin"})});if(!t){const e=encodeURIComponent(window.location.href);return ga(window.location.host)||(window.location.href="https://app.base44.com/login?from_url=".concat(e)),(0,re.jsx)(Z.C5,{to:"/login?from_url=".concat(e),replace:!0})}return s},LC=()=>{(0,H.useEffect)(()=>{(()=>{try{const e=new URLSearchParams(window.location.search),s={};let t=!1;if(Ne.forEach(a=>{const n=e.get(a);n&&(s[a]=n,t||(t=!0))}),t){const e=we();return e.params&&0!==Object.keys(e.params).length?e.params:(localStorage.setItem(je,JSON.stringify(s)),localStorage.setItem(ye,Date.now().toString()),s)}return{}}catch(e){return{}}})()},[]);const e=ts().flatMapDeep(e_,e=>[e,...e.children||[]]);return(0,re.jsx)(J.BrowserRouter,{children:(0,re.jsx)(ie,{children:(0,re.jsxs)(pe,{children:[(0,re.jsx)(Z.BV,{children:e.map(e=>(0,re.jsx)(Z.qh,{path:e.url,element:(0,re.jsx)(TC,{page:e})},e.url))}),(0,re.jsx)(CC,{}),(0,re.jsx)(Te,{}),(0,re.jsx)(Ao,{}),(0,re.jsx)(IC,{})]})})})},OC=()=>{const e=window.location.host;let s=(0,re.jsx)(LC,{});return ga(e)||(s=(0,re.jsx)(wC,{})),(0,re.jsxs)("div",{className:"font-sans",children:[(0,re.jsx)("div",{children:(0,re.jsx)(qh,{})}),(0,re.jsx)("div",{children:(0,re.jsx)(eS,{})}),(0,re.jsx)("div",{children:(0,re.jsx)(Xr.Toaster,{})}),(0,re.jsx)(Is,{children:s})]})},RC=e=>{e&&e instanceof Function&&t.e(96).then(t.bind(t,88206)).then(s=>{let{getCLS:t,getFID:a,getFCP:n,getLCP:r,getTTFB:l}=s;t(e),a(e),n(e),r(e),l(e)})};G.createRoot(document.getElementById("root")).render((0,re.jsx)(OC,{})),RC()},55194:(e,s,t)=>{"use strict";t.d(s,{O5:()=>r,QF:()=>l,VO:()=>n,b3:()=>a.A});t(73215);var a=t(76976);function n(){let e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];return a.A.fetchToken(e)}function r(e){a.A.setToken(e)}function l(){a.A.setToken(null)}},69783:(e,s,t)=>{"use strict";t.d(s,{A:()=>o});var a=t(73422),n=t(41397),r=t.n(n),l=t(23046),i=t(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,l.wE)(),e),this.socket.on("connect",()=>{this.historicalSocketIds=r().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:s}=e;s&&s()})})}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,s,t){this.hasListeners(e)||(this.joinRoom(e),this._roomToListeners[e]={});const a="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var s=16*Math.random()|0;return("x"===e?s:3&s|8).toString(16)});this._roomToListeners[e][a]={callback:s,reconnectCallback:t};const n=this;return()=>{n.removeListener(a)}}getListeners(e){return this._roomToListeners[e]}removeListener(e){Object.keys(this._roomToListeners).forEach(s=>{this._roomToListeners[s][e]&&(delete this._roomToListeners[s][e],0===Object.keys(this._roomToListeners[s]).length&&(this.leaveRoom(s),delete this._roomToListeners[s]))})}onUpdateModel(e){const s=e.room,t=JSON.parse(e.data);this._roomToListeners[s]&&Object.values(this._roomToListeners[s]).forEach(e=>{let{callback:s}=e;s(t)})}cleanup(){this.tokenUnsubscribe&&(this.tokenUnsubscribe(),this.tokenUnsubscribe=null),this.socket&&this.socket.disconnect()}}},73215:(e,s,t)=>{"use strict";t.d(s,{Ay:()=>v,Vp:()=>x,bx:()=>f,r8:()=>p,xL:()=>m,yI:()=>d});var a=t(36642),n=t(41397),r=t.n(n),l=t(23046),i=t(6221),o=t(15255);let c={};function d(e,s){c[e]=s}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 s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},t=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,l.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(s).forEach(e=>{m.defaults.headers.common[e]=s[e]}),m.interceptors.request.use(s=>{s.headers=r().merge(r().cloneDeep(c),s.headers),s.headers["X-Socket-Id"]=i.A.getSocketId(),s.headers["X-Origin-URL"]=window.location.href;const a=h();a&&(s.headers["X-Active-Workspace-Id"]=a);const n=g();n&&(s.headers["X-Active-App-Id"]=n);const l=(0,o.A)();if(s.requestId=l,t)try{window.parent.postMessage({type:"api-request-start",requestId:l,data:{url:e+s.url,method:s.method,body:s.data instanceof FormData?"[FormData object]":s.data}},"*")}catch(d){}return s},e=>Promise.reject(e)),m.interceptors.response.use(e=>{if(t)try{window.parent.postMessage({type:"api-request-end",requestId:e.config.requestId,data:{statusCode:e.status,response:e.data}},"*")}catch(s){}return n?e.data:e},e=>{var s,t,a,n,r;null!==(s=e.config)&&void 0!==s&&s.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===(r=e.response)||void 0===r?void 0:r.data)||{error:e.message}}},"*");if(d)for(const l of u)l(e);if(null!==(t=e.response)&&void 0!==t&&null!==(a=t.data)&&void 0!==a&&a.traceback);return Promise.reject(e)}),m}},75888:(e,s,t)=>{"use strict";t.r(s),t.d(s,{default:()=>r});var a=t(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 s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null;const n={};return s&&t&&(n.start_date=s.toISOString(),n.end_date=t.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 r=new n},76976:(e,s,t)=>{"use strict";t.d(s,{A:()=>l});var a=t(89379),n=t(73215),r=t(12055);const l=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 s=new URLSearchParams(window.location.search),t=s.get("access_token")||localStorage.getItem("token")||localStorage.getItem("base44_access_token");return e&&s.has("access_token")&&(0,r.V)("access_token"),t}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 s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this.listeners.forEach(t=>{try{t(e,s)}catch(a){}})}processSSOTokensFromURL(){const e=new URLSearchParams(window.location.search);if(e.get("sso_access_token")){const s={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(s);["sso_access_token","sso_token_type","sso_expires_at","sso_scope","sso_provider","sso_id_token"].forEach(s=>{e.delete(s)});const t=window.location.pathname+(e.toString()?"?"+e.toString():"");window.history.replaceState({},"",t),this.notifyListeners("sso_tokens_updated",{tokens:this.getSSOTokens()})}}setSSOTokens(e){const s={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()},t=Object.fromEntries(Object.entries(s).filter(e=>{let[s,t]=e;return null!=t}));if(localStorage.setItem("sso_tokens",JSON.stringify(t)),t.access_token)try{(0,n.yI)("SSO_AUTHORIZATION","".concat(t.token_type," ").concat(t.access_token))}catch(a){setTimeout(()=>{try{(0,n.yI)("SSO_AUTHORIZATION","".concat(t.token_type," ").concat(t.access_token))}catch(e){}},100)}}getSSOTokens(){try{const e=localStorage.getItem("sso_tokens");if(!e)return null;const s=JSON.parse(e);return s.expires_at&&new Date(1e3*s.expires_at)<=new Date?(this.clearSSOTokens(),null):s}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 s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const t=this.getSSOAuthHeader();if(!t)throw new Error("No valid SSO tokens available");const n=(0,a.A)((0,a.A)({},t),{},{"Content-Type":"application/json"},s.headers);return fetch(e,(0,a.A)((0,a.A)({},s),{},{headers:n}))}debugSSOTokens(){const e=localStorage.getItem("sso_tokens");if(e)try{const s=JSON.parse(e);if(s.expires_at){new Date(1e3*s.expires_at)}}catch(s){}}}},84125:(e,s,t)=>{"use strict";t.d(s,{H:()=>l,y:()=>i});var a=t(89379),n=t(73215),r=t(6221);class l{constructor(){this.axios=this.getClient()}getBaseURL(){return"/"}getClient(){return(0,n.Ay)(this.getBaseURL())}}class i extends l{parseInstance(e){return e}list(e,s,t,a){let n={};return e&&(n.sort=e),s&&(n.limit=s),t&&(n.skip=t),a&&(n.fields=a),this.axios.get("",{params:n}).then(e=>e.map(this.parseInstance))}filter(e,s,t,a,n){let r={q:JSON.stringify(e)};return s&&(r.sort=s),t&&(r.limit=t),a&&(r.skip=a),n&&(r.fields=n),this.axios.get("",{params:r}).then(e=>e.map(this.parseInstance))}get(e){return this.axios.get("/".concat(e)).then(this.parseInstance)}subscribe(e,s,t){const n=this;t(this.parseInstance(s));const l=this.getBaseURL()+"/"+e;return r.A.addListener(l,e=>{s=(0,a.A)((0,a.A)({},s),e),t(this.parseInstance(s),Object.keys(e))},async()=>{const s=await n.get(e);t(this.parseInstance(s),Object.keys(s))})}async fetchAndSubscribe(e,s){let t=await this.get(e);return this.subscribe(e,t,s)}schema(){return this.axios.get("/schema")}create(e){return this.axios.post("",e).then(this.parseInstance)}update(e,s){return this.axios.put("/".concat(e),s).then(this.parseInstance).then(t=>{const a=r.A.getListeners(this.getBaseURL()+"/"+e)||[];return Object.values(a).forEach(e=>e.callback(t,Object.keys(s))),t})}delete(e){return this.axios.delete("/".concat(e))}deleteMany(e){return this.axios.delete("",{data:e})}}},91903:()=>{}},n={};function r(e){var s=n[e];if(void 0!==s)return s.exports;var t=n[e]={id:e,loaded:!1,exports:{}};return a[e].call(t.exports,t,t.exports,r),t.loaded=!0,t.exports}r.m=a,r.amdO={},e=[],r.O=(s,t,a,n)=>{if(!t){var l=1/0;for(d=0;d=n)&&Object.keys(r.O).every(e=>r.O[e](t[o]))?t.splice(o--,1):(i=!1,n0&&e[d-1][2]>n;d--)e[d]=e[d-1];e[d]=[t,a,n]},r.n=e=>{var s=e&&e.__esModule?()=>e.default:()=>e;return r.d(s,{a:s}),s},t=Object.getPrototypeOf?e=>Object.getPrototypeOf(e):e=>e.__proto__,r.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);r.r(n);var l={};s=s||[null,t({}),t([]),t(t)];for(var i=2&a&&e;("object"==typeof i||"function"==typeof i)&&!~s.indexOf(i);i=t(i))Object.getOwnPropertyNames(i).forEach(s=>l[s]=()=>e[s]);return l.default=()=>e,r.d(n,l),n},r.d=(e,s)=>{for(var t in s)r.o(s,t)&&!r.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:s[t]})},r.e=()=>Promise.resolve(),r.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),r.o=(e,s)=>Object.prototype.hasOwnProperty.call(e,s),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.nmd=e=>(e.paths=[],e.children||(e.children=[]),e),r.p="/",(()=>{var e={792:0};r.O.j=s=>0===e[s];var s=(s,t)=>{var a,n,l=t[0],i=t[1],o=t[2],c=0;if(l.some(s=>0!==e[s])){for(a in i)r.o(i,a)&&(r.m[a]=i[a]);if(o)var d=o(r)}for(s&&s(t);cr(39865));l=r.O(l)})();