import{b as n,r as l,j as e,E as T,c as R}from"./index-CUDottTv.js";import{B as k}from"./textarea-DAwdLdON.js";import{T as w}from"./tabs-BoJRkfaU.js";import{F as z}from"./file-text-h8kcLd2l.js";import{S as M}from"./save-BGeL2PJM.js";const U=[{id:"local",label:"Local"},{id:"project",label:"Project"},{id:"global",label:"Global"}],B={global:"~/.claude/CLAUDE.md — Applies to all projects",project:"~/.claude/projects/<key>/CLAUDE.md — Project-specific rules",local:"<project-path>/CLAUDE.md — Local, gitignored rules"};function I({projectId:c}){const t=n(o=>o.rules),j=n(o=>o.rulesLoading),[s,b]=l.useState("local"),[h,r]=l.useState(""),[g,i]=l.useState(""),[C,x]=l.useState(""),[S,d]=l.useState(!1),[y,p]=l.useState(!1),[v,f]=l.useState(!1);l.useEffect(()=>{n.getState().fetchRules(c)},[c]),l.useEffect(()=>{t&&(r(t.global.content),i(t.project.content),x(t.local.content),d(!1),p(!1),f(!1))},[t]);const D={global:h,project:g,local:C},E={global:r,project:i,local:x},N={global:S,project:y,local:v},m={global:d,project:p,local:f},u=D[s],L=N[s],a=t==null?void 0:t[s];function P(o){E[s](o),m[s](!0)}async function A(){await n.getState().saveRule(c,s,u),m[s](!1)}return j&&!t?e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsx("p",{className:"text-sm text-text-muted",children:"Loading rules..."})}):t?e.jsxs("div",{className:"flex-1 flex flex-col min-h-0 overflow-hidden",children:[e.jsx(w,{tabs:U,activeTab:s,onTabChange:o=>b(o)}),e.jsxs("div",{className:"px-4 pt-3 space-y-1 shrink-0",children:[e.jsx("p",{className:"text-xs text-text-muted",children:B[s]}),e.jsx("p",{className:"font-mono text-xs text-text-tertiary",children:a==null?void 0:a.path})]}),e.jsx("textarea",{className:"w-full flex-1 bg-transparent text-text-primary text-sm font-mono p-4 resize-none outline-none border-t border-border-muted mt-3",value:u,onChange:o=>P(o.target.value),spellCheck:!1}),e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-t border-border-muted",children:[e.jsx("span",{className:R("text-xs",a!=null&&a.exists?"text-text-secondary":"text-text-muted"),children:a!=null&&a.exists?"File exists":"File not found"}),e.jsxs(k,{variant:"primary",size:"sm",disabled:!L,onClick:A,children:[e.jsx(M,{size:14}),"Save"]})]})]}):e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsx(T,{icon:e.jsx(z,{size:32}),title:"No rules available",description:"Could not load CLAUDE.md files for this project."})})}export{I as RulesPage};
