1import{m as L,p as P,r as t,j as e}from"./vendor-react-core-Ba2gwJNM.js";import{B as g,aP as E,C as A,i as Y,v as B,f as T,bx as F,g as _,F as i,a_ as H}from"./index-D-XLV-_s.js";import{W as O}from"./WorkspaceCreateForm-ByHHkgXW.js";import{WorkspaceService as $}from"./workspace.service-dymkAwqF.js";import{u as q}from"./index-B0Ir_8Hh.js";import{g as z}from"./auth-helpers-BgxV-mAQ.js";import{p as V,r as G,s as v,c as y}from"./workspace-onboarding-CmxLHnAg.js";import"./vendor-ui-C6PEtgd7.js";import"./vendor-utils-MSNXLbuZ.js";import"./vendor-supabase-De54M4W1.js";import"./label-C7mpxRQf.js";import"./textarea-BDmvTWAt.js";import"./alert-BRJJGBfn.js";import"./workspace-permissions.service-Ds-SiVVv.js";function le(){const u=L(),d=P(),a=V(new URLSearchParams(d.search).get("repository")),j=t.useMemo(()=>G(a),[a]),[p,m]=t.useState(null),[f,N]=t.useState(!0),[S,k]=t.useState(!0),[C,h]=t.useState(!1),[U,o]=t.useState(null),w=t.useRef(!1),W=t.useRef(Date.now());t.useEffect(()=>{let r=!0;return(async()=>{try{const l=await _(),{data:{user:n}}=await l.auth.getUser();if(!r)return;m(n),!w.current&&n&&(w.current=!0,i("workspace_creation_started",{source:"workspace_new_page",user_id:n.id}))}catch{r&&o("Unable to check your session. Sign in to continue.")}finally{r&&N(!1)}})(),()=>{r=!1}},[]);const D=async r=>{if(k(v(a,r)),!p?.id){o("You must be logged in to create a workspace");return}h(!0),o(null);try{const c=await _(),{data:{user:l}}=await c.auth.getUser();if(!l){m(null),o("Your session expired. Sign in to continue with your workspace draft.");return}const n=await z();if(!n){m(null),o("Unable to resolve your user account. Please try logging in again."),h(!1);return}const s=await $.createWorkspace({appUserId:n,authUserId:l.id},r);if(s.success&&s.data){const b=Date.now()-W.current;i("workspace_created",{workspace_id:s.data.id,workspace_name:r.name,time_to_create_ms:b,is_first_workspace:!0});const{count:R}=await c.from("workspaces").select("*",{count:"exact",head:!0}).eq("owner_id",n);if(R===1&&i("first_workspace_created",{workspace_id:s.data.id,time_to_create_ms:b}),q.success("Workspace created successfully!"),!(s.data.slug||s.data.id)){console.error("No slug or ID returned from workspace creation"),o("Workspace created but navigation failed. Please refresh the page.");return}y(a);const I=a?`?${new URLSearchParams({addRepository:a})}`:"";u(`${H(s.data)}${I}`)}else o(s.error||"Failed to create workspace"),i("workspace_creation_failed",{error:s.error||"Unknown error",workspace_name:r.name})}catch(c){console.error("%s","Error creating workspace:",c),o("An unexpected error occurred. Please try again."),i("workspace_creation_error",{error_type:"exception",workspace_name:r.name})}finally{h(!1)}},x=()=>{y(a),u("/")};return e.jsx("div",{className:"min-h-screen bg-background",children:e.jsxs("div",{className:"container max-w-2xl mx-auto py-8 px-4",children:[e.jsxs("div",{className:"mb-8",children:[e.jsxs(g,{variant:"ghost",size:"sm",onClick:x,className:"mb-4 -ml-2",children:[e.jsx(E,{className:"h-4 w-4 mr-2"}),"Back to Home"]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h1",{className:"text-3xl font-bold tracking-tight",children:"Create New Workspace"}),e.jsx("p",{className:"text-muted-foreground",children:"Organize your favorite repositories and collaborate with your team. You can add repositories and invite members after creating your workspace."})]})]}),e.jsxs(A,{children:[e.jsx(Y,{children:e.jsx(B,{children:"Workspace Details"})}),e.jsxs(T,{children:[f&&e.jsx("p",{role:"status",className:"mb-4 text-sm",children:"Checking your session..."}),!f&&!p&&e.jsxs("div",{className:"mb-4 space-y-2",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Sign in with GitHub before creating your workspace. Your draft will be kept in this tab."}),e.jsx(g,{onClick:()=>u(F(d.pathname+d.search)),children:"Sign in to continue"})]}),!S&&e.jsx("p",{role:"alert",className:"mb-4 text-sm text-destructive",children:"Browser storage is unavailable. Your draft cannot be restored after sign-in or a refresh."}),a&&e.jsxs("p",{className:"mb-4 text-sm",children:["After creation, continue adding ",a,"."]}),e.jsx(O,{onSubmit:D,onCancel:x,loading:C||f,submitDisabled:!p,initialValues:j,onChange:r=>k(v(a,r)),error:U,mode:"create"},a||"new")]})]}),e.jsx("div",{className:"mt-6 text-center",children:e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Need help? Check out our"," ",e.jsx(g,{variant:"link",className:"p-0 h-auto text-sm",asChild:!0,children:e.jsx("a",{href:"https://docs.contributor.info/workspaces
1/overview",target:"_blank",rel:"noopener noreferrer",children:"documentation"})})," ","to learn more about workspaces."]})})]})})}export{le as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.