import{r as n,j as e}from"./vendor-react-wBh_31cN.js";import{cg as P,R as c,G as b,a0 as w,D as L,z as R,B as F,C as k,r as H}from"./index-dNe6i2rS.js";import{C as p,a as g,b as u,c as j}from"./card-BeQtvmcJ.js";import{C as O}from"./card-link-4kqDd55h.js";import{V as I}from"./value-7N0Keti9.js";import{S as E}from"./separator-CxqNNMXg.js";import{D as V}from"./data-table-Mt0DWBPO.js";import{C as _}from"./code-input-W_9wcAaJ.js";import{u as z}from"./TagsForm-B-vwjcyr.js";import{L as $}from"./LinkInProject-C8CkeI6P.js";import{u as A}from"./useCurrentProject-CTMLbmkf.js";import{i as v,r as B}from"./file-utils-B4k-DQmp.js";import{T as K}from"./TagsEdit-BoqIfo85.js";const S=/^https?:\/\/\S+$/i,M=/^(?:hdfs:\/\/[^/]*)?\/Projects\/([^/]+)\/(.+)$/,q=s=>typeof s=="string"&&(S.test(s)||M.test(s)),G=(s,t)=>{const r=s.match(M);return!r||!t||r[1]!==t?null:v(B(r[2]))},J=s=>s.flatMap(t=>{const r=typeof t.tags=="string"||!!(t.hasNestedTypes||t.hasAdditionalRules),i=Object.entries(t.tags||{});return i.length===0?[{name:t.name,property:"",value:"",isFirstRow:!0,isComplex:r}]:r?[{name:t.name,property:"",value:t.tags,isFirstRow:!0,isComplex:!0}]:i.map(([o,l],m)=>({name:t.name,property:o,value:l,isFirstRow:m===0,isComplex:!1}))}),f=({value:s})=>{const{project:t}=A();if(typeof s=="string"){if(S.test(s))return e.jsx("a",{href:s,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-quartz-primary underline",children:s});const r=G(s,t==null?void 0:t.projectName);if(r!==null)return e.jsx($,{to:H.project.settings.fileBrowserWithPath,params:{"*":r},className:"text-sm",children:s})}return e.jsx("span",{className:"text-sm",children:String(s)})},U=8,W=({name:s,value:t})=>{const[r,i]=n.useState(!1);if(q(t))return e.jsx(f,{value:t});const o=typeof t=="string"?t:JSON.stringify(t,null,2),l=o.split(`
`).length;return l<=U?e.jsx("pre",{className:"m-0 max-w-[600px] overflow-x-auto rounded-md border border-border bg-muted/30 px-2 py-1.5 font-mono text-xs",children:o}):e.jsxs(e.Fragment,{children:[e.jsxs(b,{variant:"outline",size:"sm",className:"h-7 px-2 text-xs",onClick:()=>i(!0),children:[e.jsx(w,{icon:"expand",size:"sm"}),`JSON · ${l} lines`]}),e.jsx(L,{open:r,onOpenChange:i,children:e.jsxs(R,{className:"max-w-3xl",children:[e.jsx(F,{children:e.jsx(k,{children:s})}),e.jsx(_,{mode:"json",value:o,readOnly:!0,showLineNumbers:!0,height:"auto",maxHeight:"60vh",className:"text-xs"})]})})]})},Q=({value:s})=>Array.isArray(s)?e.jsx("span",{className:"text-sm",children:s.map((t,r)=>e.jsxs("span",{children:[r>0&&", ",e.jsx(f,{value:t})]},`${r}-${String(t)}`))}):e.jsx(f,{value:s}),X=[{accessorKey:"name",header:"Name",cell:({row:s})=>s.original.isFirstRow?e.jsx(I,{children:s.original.name}):null},{accessorKey:"property",header:"Property",cell:({row:s})=>s.original.isComplex?null:e.jsx(c,{gray:!0,children:s.original.property})},{accessorKey:"value",header:"Value",cell:({row:s})=>s.original.isComplex?e.jsx(W,{name:s.original.name,value:s.original.value}):e.jsx(Q,{value:s.original.value})}],T=({tags:s})=>{const t=n.useMemo(()=>J(s),[s]);return e.jsx(V,{columns:X,data:t,emptyMessage:"No tags"})},Y=({data:s=[],isLoading:t,type:r=P.fg,externalEntity:i=!1})=>{const[o,l]=n.useState("view"),{items:m}=z(r),d=n.useMemo(()=>new Set(m.map(a=>a.selected[0])),[m]),y=n.useMemo(()=>s.filter(a=>d.has(a.name)),[s,d]),x=n.useMemo(()=>s.filter(a=>!d.has(a.name)),[s,d]),N=n.useMemo(()=>new Set(s.map(a=>a.name)),[s]),h=n.useMemo(()=>m.map(a=>a.selected[0]).filter(a=>!N.has(a)),[m,N]),C=n.useCallback(()=>{l("edit")},[]),D=n.useCallback(()=>{l("view")},[]);return o==="edit"?e.jsxs(p,{children:[e.jsx(g,{children:e.jsx(u,{children:"Tags"})}),e.jsx(j,{children:e.jsx(K,{type:r,tags:s,onDone:D})})]}):t?e.jsxs(p,{children:[e.jsx(g,{children:e.jsx(u,{children:"Tags"})}),e.jsx(j,{children:e.jsx("div",{className:"flex h-[50px] items-center justify-center mt-[30px]",children:e.jsx(c,{className:"text-lg",gray:!0,children:"Loading..."})})})]}):e.jsxs(p,{children:[e.jsxs(g,{className:"flex flex-row items-center justify-between",children:[e.jsx(u,{children:"Tags"}),!i&&e.jsx(O,{disabled:i,onClick:C,children:"edit tags"})]}),e.jsxs(j,{children:[!s.length&&!h.length&&e.jsxs("div",{className:"my-5 flex flex-col items-center justify-center",children:[e.jsx(c,{className:"text-lg",gray:!0,children:"There are no tags attached"}),!i&&e.jsx(b,{className:"mt-5",onClick:C,children:"Add tags"})]}),(y.length>0||h.length>0)&&e.jsxs(e.Fragment,{children:[e.jsx(c,{bold:!0,className:"mb-2",children:"Mandatory"}),e.jsx(T,{tags:y}),h.map(a=>e.jsxs("div",{className:"mb-1 flex items-center gap-2",children:[e.jsx(w,{icon:"warning",color:"labels.red",size:"sm"}),e.jsx(c,{className:"text-quartz-label-red",children:a})]},a)),(x.length>0||!s.length)&&e.jsx(E,{className:"my-4"})]}),x.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(c,{bold:!0,className:"mb-2",children:"Optional"}),e.jsx(T,{tags:x})]})]})]})},xe=n.memo(Y);export{xe as T};
