module.exports=[661998,a=>{"use strict";var b=a.i(254157),c=a.i(839769),d=a.i(563842),e=a.i(18170),f=a.i(347421),g=a.i(372712),h=a.i(82012),i=a.i(778737),j=a.i(161367),k=a.i(419573),l=a.i(560450),m=a.i(592709),n=a.i(550093),o=a.i(622706),p=a.i(830203),q=a.i(661616),r=a.i(701505),s=a.i(210872),t=a.i(224504),u=a.i(303469),v=a.i(175035),w=a.i(660042),x=a.i(472238),y=a.i(190208),z=a.i(986990),A=a.i(709929),B=a.i(745250);function C(a){if(!a)return"(any)";let b=[];return a.teamKey&&b.push(`team:${a.teamKey}`),a.stateIds&&a.stateIds.length>0&&b.push(`state:${a.stateIds.length} selected`),a.assigned&&b.push(`assigned:${a.assigned}`),a.query&&b.push(`q:"${a.query}"`),0===b.length?"(any)":b.join(" · ")}function D({watch:a,onToggleEnabled:c,onTrigger:d,onDelete:f}){return(0,b.jsxs)("div",{className:"flex items-center justify-end gap-1",children:[(0,b.jsxs)(B.Tooltip,{children:[(0,b.jsx)(B.TooltipTrigger,{asChild:!0,children:(0,b.jsx)(e.Button,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0 cursor-pointer",onClick:b=>{b.stopPropagation(),c(a)},children:a.enabled?(0,b.jsx)(y.IconPlayerPause,{className:"h-3.5 w-3.5"}):(0,b.jsx)(x.IconPlayerPlay,{className:"h-3.5 w-3.5"})})}),(0,b.jsx)(B.TooltipContent,{children:a.enabled?"Pause":"Enable"})]}),(0,b.jsxs)(B.Tooltip,{children:[(0,b.jsx)(B.TooltipTrigger,{asChild:!0,children:(0,b.jsx)(e.Button,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0 cursor-pointer",onClick:b=>{b.stopPropagation(),d(a.id)},children:(0,b.jsx)(w.IconRefresh,{className:"h-3.5 w-3.5"})})}),(0,b.jsx)(B.TooltipContent,{children:"Check now"})]}),(0,b.jsxs)(B.Tooltip,{children:[(0,b.jsx)(B.TooltipTrigger,{asChild:!0,children:(0,b.jsx)(e.Button,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0 text-red-500 hover:text-red-600 cursor-pointer",onClick:b=>{b.stopPropagation(),f(a.id)},children:(0,b.jsx)(v.IconTrash,{className:"h-3.5 w-3.5"})})}),(0,b.jsx)(B.TooltipContent,{children:"Delete"})]})]})}function E({watches:a,showWorkspace:c,onEdit:d,onDelete:e,onTrigger:f,onToggleEnabled:g}){let h=(0,u.useAppStore)(a=>a.workspaces.items);return 0===a.length?(0,b.jsx)("p",{className:"text-sm text-muted-foreground py-4 text-center",children:"No Linear watchers configured. Create one to auto-create tasks from filtered issues."}):(0,b.jsxs)(A.Table,{children:[(0,b.jsx)(A.TableHeader,{children:(0,b.jsxs)(A.TableRow,{children:[c&&(0,b.jsx)(A.TableHead,{children:"Workspace"}),(0,b.jsx)(A.TableHead,{children:"Filter"}),(0,b.jsx)(A.TableHead,{children:"Interval"}),(0,b.jsx)(A.TableHead,{children:"Last Polled"}),(0,b.jsx)(A.TableHead,{children:"Status"}),(0,b.jsx)(A.TableHead,{className:"text-right",children:"Actions"})]})}),(0,b.jsx)(A.TableBody,{children:a.map(a=>{let i;return(0,b.jsxs)(A.TableRow,{className:"cursor-pointer",onClick:()=>d(a),children:[c&&(0,b.jsx)(A.TableCell,{className:"text-xs text-muted-foreground",children:(i=a.workspaceId,h.find(a=>a.id===i)?.name??i)}),(0,b.jsx)(A.TableCell,{className:"font-mono text-xs max-w-md truncate",title:C(a.filter),children:C(a.filter)}),(0,b.jsxs)(A.TableCell,{className:"text-xs text-muted-foreground",children:[Math.round(a.pollIntervalSeconds/60),"m"]}),(0,b.jsx)(A.TableCell,{className:"text-xs text-muted-foreground",children:function(a){if(!a)return"Never";let b=Math.floor((Date.now()-new Date(a).getTime())/6e4);if(b<1)return"Just now";if(b<60)return`${b}m ago`;let c=Math.floor(b/60);return c<24?`${c}h ago`:`${Math.floor(c/24)}d ago`}(a.lastPolledAt)}),(0,b.jsx)(A.TableCell,{children:(0,b.jsx)(z.Badge,{variant:a.enabled?"default":"secondary",className:"text-xs",children:a.enabled?"Active":"Paused"})}),(0,b.jsx)(A.TableCell,{className:"text-right",children:(0,b.jsx)(D,{watch:a,onToggleEnabled:g,onTrigger:f,onDelete:e})})]},a.id)})})]})}var F=a.i(417132),G=a.i(740114),H=a.i(764292),I=a.i(298611),J=a.i(161885),K=a.i(8272);let L=[{key:"issue.url",description:"Linear issue URL",example:"https://linear.app/acme/issue/ENG-7",executor_types:[]},{key:"issue.identifier",description:"Issue identifier",example:"ENG-7",executor_types:[]},{key:"issue.title",description:"Issue title",example:"Login fails on mobile",executor_types:[]},{key:"issue.team",description:"Team key",example:"ENG",executor_types:[]},{key:"issue.state",description:"Workflow state name",example:"In Progress",executor_types:[]},{key:"issue.priority",description:"Priority label",example:"High",executor_types:[]},{key:"issue.assignee",description:"Assignee display name",example:"Alice",executor_types:[]},{key:"issue.creator",description:"Issue creator display name",example:"Bob",executor_types:[]},{key:"issue.description",description:"Issue description body",example:"Tap submit, nothing happens.",executor_types:[]}],M=`You have been assigned a Linear issue to work on.

**Issue:** {{issue.url}}
**Identifier:** {{issue.identifier}}
**Title:** {{issue.title}}
**Team:** {{issue.team}}
**State:** {{issue.state}}
**Priority:** {{issue.priority}}
**Assignee:** {{issue.assignee}}

## Description

{{issue.description}}

## Instructions

1. Read the issue description carefully and understand the requirements.
2. Explore the codebase to understand the relevant code and architecture.
3. Implement the changes described in the issue.
4. Write or update tests to cover the changes.
5. Run the test suite to ensure nothing is broken.
6. Commit your changes with a descriptive commit message referencing {{issue.identifier}}.`,N="__any__";function O(a){return{workspaceId:a,query:"",teamKey:"",stateIds:[],assigned:"",workflowId:"",workflowStepId:"",agentProfileId:"",executorProfileId:"",prompt:M,enabled:!0,pollInterval:300}}function P(a){return(0,b.jsxs)("div",{className:"space-y-1.5",children:[(0,b.jsx)(h.Label,{children:a.label}),a.description&&(0,b.jsx)("p",{className:"text-xs text-muted-foreground",children:a.description}),(0,b.jsxs)(k.Select,{value:a.value||void 0,onValueChange:a.onChange,disabled:a.disabled,children:[(0,b.jsx)(k.SelectTrigger,{className:"cursor-pointer",children:(0,b.jsx)(k.SelectValue,{placeholder:a.placeholder})}),(0,b.jsx)(k.SelectContent,{children:a.items.map(a=>(0,b.jsx)(k.SelectItem,{value:a.id,children:a.label},a.id))})]})]})}function Q({states:a,loading:c,selected:d,onToggle:e,disabled:f}){return f?(0,b.jsx)("p",{className:"text-xs text-muted-foreground",children:"Pick a team to choose specific workflow states."}):c?(0,b.jsx)("p",{className:"text-xs text-muted-foreground",children:"Loading states…"}):0===a.length?(0,b.jsx)("p",{className:"text-xs text-muted-foreground",children:"No workflow states available."}):(0,b.jsx)("div",{className:"flex flex-wrap gap-1.5",children:a.map(a=>{let c=d.includes(a.id);return(0,b.jsx)(z.Badge,{variant:c?"default":"outline",className:"cursor-pointer",onClick:()=>e(a.id),children:a.name},a.id)})})}function R({form:a,setForm:d}){let{teams:e,states:f,loadingStates:i}=function(a){let[b,d]=(0,c.useState)([]),[e,f]=(0,c.useState)({}),g=(0,c.useRef)(new Set);return(0,c.useEffect)(()=>{let a=!1;return(0,r.listLinearTeams)().then(b=>{a||d(b.teams??[])}).catch(()=>{a||d([])}),()=>{a=!0}},[]),(0,c.useEffect)(()=>{if(!a||g.current.has(a))return;g.current.add(a);let b=!1;return(0,r.listLinearStates)(a).then(c=>{b||f(b=>({...b,[a]:c.states??[]}))}).catch(()=>{b||f(b=>({...b,[a]:[]}))}),()=>{b=!0}},[a]),{teams:b,states:a?e[a]??[]:[],loadingStates:!!a&&void 0===e[a]}}(a.teamKey),j=(0,c.useCallback)(a=>d(b=>({...b,stateIds:b.stateIds.includes(a)?b.stateIds.filter(b=>b!==a):[...b.stateIds,a]})),[d]);return(0,b.jsxs)(b.Fragment,{children:[(0,b.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,b.jsx)(P,{label:"Team",description:"Restrict matches to one team.",value:a.teamKey,onChange:a=>d(b=>({...b,teamKey:a,stateIds:[]})),placeholder:"(any team)",items:e.map(a=>({id:a.key,label:`${a.name} (${a.key})`}))}),(0,b.jsx)(P,{label:"Assignee",description:"Filter by who an issue is assigned to.",value:a.assigned||N,onChange:a=>d(b=>({...b,assigned:a===N?"":a})),placeholder:"(any)",items:[{id:N,label:"(any)"},{id:"me",label:"Me"},{id:"unassigned",label:"Unassigned"}]})]}),(0,b.jsxs)("div",{className:"space-y-1.5",children:[(0,b.jsx)(h.Label,{children:"States"}),(0,b.jsx)("p",{className:"text-xs text-muted-foreground",children:"Click states to toggle. Empty matches every state on the team."}),(0,b.jsx)(Q,{states:f,loading:i,selected:a.stateIds,onToggle:j,disabled:!a.teamKey})]}),(0,b.jsxs)("div",{className:"space-y-1.5",children:[(0,b.jsx)(h.Label,{children:"Query"}),(0,b.jsx)("p",{className:"text-xs text-muted-foreground",children:"Free-text match across title and description (optional)."}),(0,b.jsx)(g.Input,{value:a.query,onChange:a=>d(b=>({...b,query:a.target.value})),placeholder:"auth bug"})]})]})}function S(){return(0,b.jsx)(B.TooltipProvider,{children:(0,b.jsxs)(B.Tooltip,{children:[(0,b.jsx)(B.TooltipTrigger,{asChild:!0,children:(0,b.jsx)(G.IconInfoCircle,{className:"h-3.5 w-3.5 text-muted-foreground/50 hover:text-muted-foreground cursor-help shrink-0"})}),(0,b.jsxs)(B.TooltipContent,{className:"max-w-xs",align:"start",children:[(0,b.jsx)("p",{className:"text-xs font-medium mb-1",children:"Available placeholders:"}),(0,b.jsx)("ul",{className:"text-xs space-y-0.5",children:L.map(a=>(0,b.jsxs)("li",{children:[(0,b.jsx)("code",{className:"text-[10px] bg-white/15 px-1 rounded",children:`{{${a.key}}}`})," ",(0,b.jsx)("span",{className:"opacity-70",children:a.description})]},a.key))})]})]})})}function T({value:a,onChange:c}){return(0,b.jsxs)("div",{className:"space-y-1.5",children:[(0,b.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,b.jsx)(h.Label,{children:"Task Prompt"}),(0,b.jsx)(S,{})]}),(0,b.jsxs)("p",{className:"text-xs text-muted-foreground",children:["The prompt sent to the agent for each new issue. Type ","{{"," to insert placeholders."]}),(0,b.jsx)("div",{className:"rounded-md border border-border overflow-hidden",children:(0,b.jsx)(K.ScriptEditor,{value:a,onChange:c,language:"markdown",height:(0,K.computeEditorHeight)(a),lineNumbers:"off",placeholders:L})})]})}function U({value:a,onChange:c,disabled:d}){let e=(0,u.useAppStore)(a=>a.workspaces.items);return(0,b.jsx)(P,{label:"Workspace",description:"Tasks created by this watcher land in the selected workspace.",value:a,onChange:c,placeholder:"Select workspace",items:e.map(a=>({id:a.id,label:a.name})),disabled:d})}function V({form:a,setForm:d}){var e;let f,g,h,i,j,{workflows:k,agentProfiles:l,allExecutorProfiles:m}=(e=a.workspaceId,(0,H.useSettingsData)(!0),(0,I.useWorkflows)(e,!0),f=(0,u.useAppStore)(a=>a.workflows.items),g=(0,c.useMemo)(()=>f.filter(a=>!a.hidden),[f]),h=(0,u.useAppStore)(a=>a.agentProfiles.items),i=(0,u.useAppStore)(a=>a.executors.items),j=(0,c.useMemo)(()=>i.filter(a=>"local"!==a.type).flatMap(a=>a.profiles??[]),[i]),{workflows:g,agentProfiles:(0,c.useMemo)(()=>h.filter(a=>!a.cli_passthrough),[h]),allExecutorProfiles:j}),{steps:n,loading:o}=(0,J.useWorkflowSteps)(a.workflowId);return(0,b.jsxs)(b.Fragment,{children:[(0,b.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,b.jsx)(P,{label:"Workflow",description:"Tasks are created in this workflow.",value:a.workflowId,onChange:a=>d(b=>({...b,workflowId:a,workflowStepId:""})),placeholder:"Select workflow",items:k.map(a=>({id:a.id,label:a.name}))}),(0,b.jsx)(P,{label:"Workflow Step",description:"Initial step for new tasks.",value:a.workflowStepId,onChange:a=>d(b=>({...b,workflowStepId:a})),placeholder:(0,J.stepPlaceholder)(a.workflowId,o,n.length),items:n.map(a=>({id:a.id,label:a.name})),disabled:!a.workflowId||o||0===n.length})]}),(0,b.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,b.jsx)(P,{label:"Agent Profile",description:"Optional — falls back to step default.",value:a.agentProfileId,onChange:a=>d(b=>({...b,agentProfileId:a})),placeholder:"(use step default)",items:l.map(a=>({id:a.id,label:a.label}))}),(0,b.jsx)(P,{label:"Executor Profile",description:"Optional — falls back to step default.",value:a.executorProfileId,onChange:a=>d(b=>({...b,executorProfileId:a})),placeholder:"(use step default)",items:m.map(a=>({id:a.id,label:a.name}))})]})]})}function W({form:a,setForm:c}){return(0,b.jsxs)(b.Fragment,{children:[(0,b.jsxs)("div",{className:"space-y-1.5",children:[(0,b.jsx)(h.Label,{children:"Poll Interval (seconds)"}),(0,b.jsx)("p",{className:"text-xs text-muted-foreground",children:"How often to re-run the search. Minimum 60s, maximum 3600s."}),(0,b.jsx)(g.Input,{type:"number",value:a.pollInterval,onChange:a=>c(b=>({...b,pollInterval:Number(a.target.value)})),min:60,max:3600})]}),(0,b.jsxs)("div",{className:"flex items-center justify-between",children:[(0,b.jsxs)("div",{children:[(0,b.jsx)(h.Label,{children:"Enabled"}),(0,b.jsx)("p",{className:"text-xs text-muted-foreground",children:"Pause or resume polling."})]}),(0,b.jsx)(l.Switch,{checked:a.enabled,onCheckedChange:a=>c(b=>({...b,enabled:a})),className:"cursor-pointer"})]})]})}function X({open:a,onOpenChange:d,watch:f,workspaceId:g,onCreate:h,onUpdate:i}){var j;let k=(0,u.useAppStore)(a=>a.workspaces.activeId),[l,m]=(0,c.useState)(!1),[n,o]=(0,c.useState)(()=>O(g??""));(0,c.useEffect)(()=>{if(f)o({workspaceId:f.workspaceId,query:f.filter?.query??"",teamKey:f.filter?.teamKey??"",stateIds:f.filter?.stateIds??[],assigned:f.filter?.assigned??"",workflowId:f.workflowId,workflowStepId:f.workflowStepId,agentProfileId:f.agentProfileId,executorProfileId:f.executorProfileId,prompt:f.prompt||M,enabled:f.enabled,pollInterval:f.pollIntervalSeconds});else o(O(g??k??""))},[f,a,g,k]);let p=!!f||!!g,q=!!n.workspaceId&&(""!==n.query.trim()||""!==n.teamKey.trim()||""!==n.assigned.trim()||0!==n.stateIds.length)&&!!n.workflowId&&!!n.workflowStepId&&!!n.prompt.trim(),r=(0,c.useCallback)(async()=>{m(!0);try{let a={filter:{query:n.query.trim()||void 0,teamKey:n.teamKey.trim()||void 0,stateIds:n.stateIds.length>0?n.stateIds:void 0,assigned:n.assigned.trim()||void 0},workflowId:n.workflowId,workflowStepId:n.workflowStepId,agentProfileId:n.agentProfileId,executorProfileId:n.executorProfileId,prompt:n.prompt,enabled:n.enabled,pollIntervalSeconds:n.pollInterval};f?await i(f.id,a):await h({...a,workspaceId:n.workspaceId}),d(!1)}catch{}finally{m(!1)}},[n,f,h,i,d]);return(0,b.jsx)(F.Dialog,{open:a,onOpenChange:d,children:(0,b.jsxs)(F.DialogContent,{className:"w-full max-w-full sm:w-[800px] sm:max-w-none max-h-[90vh] overflow-y-auto",children:[(0,b.jsxs)(F.DialogHeader,{children:[(0,b.jsx)(F.DialogTitle,{children:f?"Edit Linear Watcher":"Create Linear Watcher"}),(0,b.jsx)(F.DialogDescription,{children:"Poll Linear with a structured filter and auto-create a Kandev task for each newly-matching issue. Issues are not bound to a repository — the workflow step's defaults decide where the task runs."})]}),(0,b.jsxs)("div",{className:"space-y-5",children:[(0,b.jsx)(U,{value:n.workspaceId,onChange:a=>o(b=>({...b,workspaceId:a,workflowId:"",workflowStepId:""})),disabled:p}),(0,b.jsx)(R,{form:n,setForm:o}),(0,b.jsx)(V,{form:n,setForm:o}),(0,b.jsx)(T,{value:n.prompt,onChange:a=>o(b=>({...b,prompt:a}))}),(0,b.jsx)(W,{form:n,setForm:o})]}),(0,b.jsxs)(F.DialogFooter,{children:[(0,b.jsx)(e.Button,{variant:"outline",onClick:()=>d(!1),className:"cursor-pointer",children:"Cancel"}),(0,b.jsx)(e.Button,{onClick:r,disabled:l||!q,className:"cursor-pointer",children:(j=!!f,l?"Saving…":j?"Update":"Create")})]})]})})}function Y(){let a,d,g,h,i,j,k,l,o,p,q,v,w,{items:x,loading:y,create:z,update:A,remove:B,trigger:C}=(a=(0,u.useAppStore)(a=>a.linearIssueWatches.items),d=(0,u.useAppStore)(a=>a.linearIssueWatches.loaded),g=(0,u.useAppStore)(a=>a.linearIssueWatches.loading),h=(0,u.useAppStore)(a=>a.setLinearIssueWatches),i=(0,u.useAppStore)(a=>a.resetLinearIssueWatches),j=(0,u.useAppStore)(a=>a.setLinearIssueWatchesLoading),k=(0,u.useAppStore)(a=>a.addLinearIssueWatch),l=(0,u.useAppStore)(a=>a.updateLinearIssueWatch),o=(0,u.useAppStore)(a=>a.removeLinearIssueWatch),p=(0,c.useRef)(void 0),q=(void 0)??null,(0,c.useEffect)(()=>{void 0!==p.current&&p.current!==q&&i(),p.current=q},[void 0,q,i]),(0,c.useEffect)(()=>{d||g||(j(!0),(0,r.listLinearIssueWatches)((void 0)??void 0,{cache:"no-store"}).then(a=>h(a??[])).catch(()=>h([])).finally(()=>j(!1)))},[void 0,d,g,h,j]),v=(0,c.useCallback)(async a=>{let b=await (0,r.createLinearIssueWatch)(a);return k(b),b},[k]),w=(0,c.useCallback)(async(a,b,c)=>{let d=c??void 0;if(!d)throw Error("workspaceId required");let e=await (0,r.updateLinearIssueWatch)(d,a,b);return l(e),e},[void 0,l]),{items:a,loaded:d,loading:g,create:v,update:w,remove:(0,c.useCallback)(async(a,b)=>{let c=b??void 0;if(!c)throw Error("workspaceId required");await (0,r.deleteLinearIssueWatch)(c,a),o(a)},[void 0,o]),trigger:(0,c.useCallback)(async(a,b)=>{let c=b??void 0;if(!c)throw Error("workspaceId required");return(0,r.triggerLinearIssueWatch)(c,a)},[void 0])}),D=function({create:a,update:b,remove:d,trigger:e}){let{toast:f}=(0,m.useToast)();return{create:(0,c.useCallback)(async b=>{try{await a(b),f({description:"Watcher created",variant:"success"})}catch(a){throw f({description:`Create failed: ${String(a)}`,variant:"error"}),a}},[a,f]),update:(0,c.useCallback)(async(a,c,d)=>{try{await b(a,c,d),f({description:"Watcher updated",variant:"success"})}catch(a){throw f({description:`Update failed: ${String(a)}`,variant:"error"}),a}},[b,f]),remove:(0,c.useCallback)(async a=>{if(confirm("Delete this Linear watcher?"))try{await d(a.id,a.workspaceId),f({description:"Watcher deleted",variant:"success"})}catch(a){f({description:`Delete failed: ${String(a)}`,variant:"error"})}},[d,f]),trigger:(0,c.useCallback)(async a=>{try{let b=await e(a.id,a.workspaceId),c=b?.newIssues??0,d=c>0?`Found ${c} new issue(s) — tasks will appear shortly.`:"No new issues matched.";f({description:d,variant:"success"})}catch(a){f({description:`Check failed: ${String(a)}`,variant:"error"})}},[e,f]),toggleEnabled:(0,c.useCallback)(async a=>{try{await b(a.id,{enabled:!a.enabled},a.workspaceId)}catch(a){f({description:`Toggle failed: ${String(a)}`,variant:"error"})}},[b,f])}}({create:z,update:A,remove:B,trigger:C}),[F,G]=(0,c.useState)(!1),[H,I]=(0,c.useState)(null),J=(0,c.useCallback)(()=>{I(null),G(!0)},[]),K=(0,c.useCallback)(a=>{I(a),G(!0)},[]),L=(0,c.useCallback)(a=>{let b=x.find(b=>b.id===a);b&&D.remove(b)},[x,D]),M=(0,c.useCallback)(a=>{let b=x.find(b=>b.id===a);b&&D.trigger(b)},[x,D]);return(0,b.jsxs)(n.SettingsSection,{icon:(0,b.jsx)(s.IconBellRinging,{className:"h-5 w-5"}),title:"Linear watchers",description:"Poll a Linear filter and auto-create a Kandev task for each newly-matching issue.",action:(0,b.jsxs)(e.Button,{size:"sm",onClick:J,className:"cursor-pointer",children:[(0,b.jsx)(t.IconPlus,{className:"h-4 w-4 mr-1"}),"New watcher"]}),children:[(0,b.jsx)(f.Card,{children:(0,b.jsx)(f.CardContent,{className:"pt-6",children:y&&0===x.length?(0,b.jsx)("p",{className:"text-sm text-muted-foreground py-4 text-center",children:"Loading…"}):(0,b.jsx)(E,{watches:x,showWorkspace:!0,onEdit:K,onDelete:L,onTrigger:M,onToggleEnabled:D.toggleEnabled})})}),(0,b.jsx)(X,{open:F,onOpenChange:G,watch:H,onCreate:D.create,onUpdate:(a,b)=>{if(!H)throw Error("update without editing watch");return D.update(a,b,H.workspaceId)}})]})}let Z={defaultTeamKey:"",secret:""};function $(a){return a?{defaultTeamKey:a.defaultTeamKey,secret:""}:Z}function _({form:a,loading:c,update:d,hasSavedSecret:e}){return(0,b.jsxs)("div",{className:"space-y-1.5",children:[(0,b.jsxs)(h.Label,{htmlFor:"linear-secret",children:["API key",e&&(0,b.jsx)("span",{className:"text-xs text-muted-foreground ml-2",children:"(saved — leave blank to keep the current value)"})]}),(0,b.jsx)(g.Input,{id:"linear-secret","data-testid":"linear-secret-input",type:"password",placeholder:e?"••••••••":"lin_api_...",value:a.secret,onChange:a=>d("secret",a.target.value),disabled:c}),(0,b.jsxs)("p",{className:"text-xs text-muted-foreground",children:["Create a personal API key at"," ",(0,b.jsx)("a",{className:"underline cursor-pointer",href:"https://linear.app/settings/account/security",target:"_blank",rel:"noreferrer",children:"linear.app/settings/account/security"})]})]})}function aa({form:a,loading:c,update:d,teams:e,loadingTeams:f}){return(0,b.jsxs)("div",{className:"space-y-1.5",children:[(0,b.jsx)(h.Label,{htmlFor:"linear-team",children:"Default team (optional)"}),(0,b.jsxs)(k.Select,{value:a.defaultTeamKey||"__none__",onValueChange:a=>d("defaultTeamKey","__none__"===a?"":a),disabled:c||f,children:[(0,b.jsx)(k.SelectTrigger,{id:"linear-team",className:"w-full",children:(0,b.jsx)(k.SelectValue,{placeholder:f?"Loading teams…":"Choose a team"})}),(0,b.jsxs)(k.SelectContent,{children:[(0,b.jsx)(k.SelectItem,{value:"__none__",children:"No default"}),e.map(a=>(0,b.jsxs)(k.SelectItem,{value:a.key,children:[a.name," (",a.key,")"]},a.id))]})]})]})}function ab({result:a}){return a?(0,b.jsx)(j.Alert,{variant:a.ok?"default":"destructive",children:(0,b.jsx)(j.AlertDescription,{children:a.ok?`Connected as ${a.displayName||a.email||a.userId}${a.orgName?` (${a.orgName})`:""}`:`Failed: ${a.error}`})}):null}function ac({saving:a,testing:c,loading:d,hasConfig:f,disableSave:g,disableTest:h,onTest:i,onSave:j,onDelete:k}){return(0,b.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,b.jsx)(e.Button,{type:"button",variant:"outline",onClick:i,disabled:c||d||h,className:"cursor-pointer",title:h?"Paste an API key to test the connection":void 0,"data-testid":"linear-test-button",children:c?"Testing...":"Test connection"}),(0,b.jsx)(e.Button,{type:"button",onClick:j,disabled:g,className:"cursor-pointer","data-testid":"linear-save-button",children:a?"Saving...":f?"Update":"Save"}),f&&(0,b.jsx)(e.Button,{type:"button",variant:"destructive",onClick:k,className:"ml-auto cursor-pointer","data-testid":"linear-delete-button",children:"Remove configuration"})]})}function ad(){let{enabled:a,setEnabled:c}=(0,o.useLinearEnabled)();return(0,b.jsxs)("div",{className:"flex items-center gap-2 rounded-full border bg-muted/30 px-3 py-1",children:[(0,b.jsx)(l.Switch,{id:"linear-enabled",checked:a,onCheckedChange:c,className:"cursor-pointer"}),(0,b.jsx)(h.Label,{htmlFor:"linear-enabled",className:"text-xs cursor-pointer",children:a?"Enabled":"Disabled"})]})}function ae(){let a=function(){let{toast:a}=(0,m.useToast)(),[b,d]=(0,c.useState)(null),[e,f]=(0,c.useState)(Z),[g,h]=(0,c.useState)(!0),[i,j]=(0,c.useState)(null),k=b?.hasSecret?b.lastCheckedAt?{ok:!!b.lastOk,error:b.lastError??"",checkedAt:new Date(b.lastCheckedAt)}:{ok:!1,error:"",checkedAt:null}:null,{teams:l,loadingTeams:n}=function(a,b){let[d,e]=(0,c.useState)(null);return(0,c.useEffect)(()=>{if(!a)return;let b=!1;return(0,r.listLinearTeams)().then(a=>{b||e(a.teams??[])}).catch(()=>{b||e([])}),()=>{b=!0}},[a,b]),{teams:d??[],loadingTeams:null===d&&!!a}}(b?.hasSecret,b?.lastOk),o=(0,c.useCallback)(async()=>{h(!0);try{let a=await (0,r.getLinearConfig)();d(a),f($(a))}catch(b){a({description:`Failed to load Linear config: ${String(b)}`,variant:"error"})}finally{h(!1)}},[a]);(0,c.useEffect)(()=>{o()},[o]),(0,c.useEffect)(()=>{let a=setInterval(()=>{(0,r.getLinearConfig)().then(a=>d(a)).catch(()=>{})},q.INTEGRATION_STATUS_REFRESH_MS);return()=>clearInterval(a)},[]);let p=(0,c.useCallback)((a,b)=>f(c=>({...c,[a]:b})),[]),{saving:s,testing:t,handleTest:u,handleSave:v,handleDelete:w}=function({form:a,setConfig:b,setForm:d,setTestResult:e}){let{toast:f}=(0,m.useToast)(),[g,h]=(0,c.useState)(!1),[i,j]=(0,c.useState)(!1),k=(0,c.useCallback)(async()=>{j(!0),e(null);try{let b=await (0,r.testLinearConnection)({authMethod:"api_key",secret:a.secret||void 0});e(b)}catch(a){e({ok:!1,error:String(a)})}finally{j(!1)}},[a,e]),l=(0,c.useCallback)(async()=>{h(!0);try{let c=await (0,r.setLinearConfig)({authMethod:"api_key",defaultTeamKey:a.defaultTeamKey,secret:a.secret||void 0});b(c),d($(c)),e(null),f({description:"Linear configuration saved",variant:"success"})}catch(a){f({description:`Save failed: ${String(a)}`,variant:"error"})}finally{h(!1)}},[a,f,b,d,e]),n=(0,c.useCallback)(async()=>{if(confirm("Remove Linear configuration?"))try{await (0,r.deleteLinearConfig)(),b(null),d(Z),e(null),f({description:"Linear configuration removed",variant:"success"})}catch(a){f({description:`Delete failed: ${String(a)}`,variant:"error"})}},[f,b,d,e]);return{saving:g,testing:i,handleTest:k,handleSave:l,handleDelete:n}}({form:e,setConfig:d,setForm:f,setTestResult:j});return{config:b,form:e,loading:g,saving:s,testing:t,testResult:i,health:k,teams:l,loadingTeams:n,update:p,handleTest:u,handleSave:v,handleDelete:w}}(),e=!a.config?.hasSecret&&!a.form.secret,g=a.saving||e;return(0,b.jsx)(n.SettingsSection,{icon:(0,b.jsx)(d.IconHexagon,{className:"h-5 w-5"}),title:"Linear integration",description:"Connect Kandev to Linear with a personal API key. Credentials are stored encrypted server-side and shared across all workspaces.",action:(0,b.jsx)(ad,{}),children:(0,b.jsx)(f.Card,{children:(0,b.jsxs)(f.CardContent,{className:"space-y-4 pt-6",children:[(0,b.jsx)(p.IntegrationAuthStatusBanner,{health:a.health}),(0,b.jsx)(_,{form:a.form,loading:a.loading,update:a.update,hasSavedSecret:!!a.config?.hasSecret}),(0,b.jsx)(aa,{form:a.form,loading:a.loading,update:a.update,hasSavedSecret:!!a.config?.hasSecret,teams:a.teams,loadingTeams:a.loadingTeams}),(0,b.jsx)(ab,{result:a.testResult}),(0,b.jsx)(i.Separator,{}),(0,b.jsx)(ac,{saving:a.saving,testing:a.testing,loading:a.loading,hasConfig:!!a.config,disableSave:g,disableTest:e,onTest:a.handleTest,onSave:a.handleSave,onDelete:a.handleDelete})]})})})}function af(){return(0,b.jsxs)("div",{className:"space-y-8",children:[(0,b.jsx)(ae,{}),(0,b.jsx)(Y,{})]})}a.s(["LinearConnectionSection",()=>ae,"LinearIntegrationPage",()=>af],661998)}];

//# sourceMappingURL=web_components_linear_linear-settings_tsx_3076c645._.js.map