import{b8 as _,u as M,gr as $,e as p,b2 as g,r as f,b7 as C,aX as w,aY as K,b0 as U,aR as z,g as y,ff as H,j as a,a_ as L,K as Q,a as X,O as j,b3 as q,bd as W,aT as Z,ct as V,cO as ee,a3 as te,a4 as oe}from"./index-d6499a22.js";import{u as ae}from"./useDownload-7167ff3b.js";import{P as re}from"./Panel-b19e8cc0.js";import{N as se}from"./NoData-789df290.js";import{u as ie}from"./useUserPermissions-3851a25d.js";import{u as ne}from"./useFeatureGroupVersions-ae275115.js";import"./Deprecated-ec8916ed.js";import"./CardActionButton-ccf1bc35.js";import"./index-da50fbe6.js";import"./file-utils-b5704e1c.js";import"./useCurrentProject-b23444be.js";import"./useProject-0d0fdeb3.js";import"./project-e798ae71.js";const Ie=()=>{const{DATE_TIME_FULL:m}=_.DATE_TIME,{id:r,fsId:i,fgId:n,commitTime:c}=M(),{canEdit:k,isLoading:v,isDataScientist:T}=ie(),{currentData:o,isFetching:E}=$({pId:+r,fsId:+i,fgId:+n}),{currentData:P=[o],isFetching:S,handleVersionChange:N}=ne(o==null?void 0:o.name,p.featureGroup.code),I=g(t=>t.loading.effects.featureGroupCode.getList),s=g(t=>t.featureGroupCode),R=g(t=>t.loading.effects.featureGroupCodeDetails.get),e=g(t=>t.featureGroupCodeDetails),B=f.useMemo(()=>{let t=c;return s&&(!t||t===s[0].commitTime?t=`${C(+s[0].commitTime,m)} (latest)`:Number.isInteger(+t)&&(t=C(+t,m))),t},[c,s,m]);w(`${K.fgCode} ${o!=null&&o.name?o.name:""}`);const u=U(),x=z();f.useEffect(()=>(u.featureGroupCode.getList({projectId:+r,featureGroupId:+n,featureStoreId:+i}),u.featureGroupCodeDetails.get({projectId:+r,featureStoreId:+i,featureGroupId:+n,commitTime:c}),()=>{u.featureGroupCode.clear(),u.featureGroupCodeDetails.clear()}),[u,r,i,n,c]);const J=f.useCallback(()=>{u.featureGroupCode.getList({projectId:+r,featureGroupId:+n,featureStoreId:+i}),u.featureGroupCodeDetails.get({projectId:+r,featureGroupId:+n,featureStoreId:+i,commitTime:c})},[u,r,i,n,c]),A=f.useCallback(t=>{var G;const[h]=t;let b=h;h.includes("(latest)")&&(b=h.slice(0,h.indexOf(" (latest)")));const O=(G=s==null?void 0:s.find(Y=>C(+Y.commitTime,m)===b))==null?void 0:G.commitTime;x(y(p.featureGroup.codeViewCommit,p.project.value,{id:r,fsId:i,fgId:n,commitTime:O??""}))},[s,x,r,i,n,m]),D=ae(),F=f.useCallback(()=>{e&&D(+r,e.path,H.FEATURESTORE)},[e,D,r]);let d="",l="";return e&&(e.contentFormat==="IPYNB"?(d="Jupyter notebook",l="Jupyter"):e.contentFormat==="PY"?(d="Python file",l="Python"):e.contentFormat==="JAR"?(d="Jar file",l="Jar"):e.contentFormat==="DBC"&&(d="Databricks notebook",l="Databricks")),E?a.jsx(L,{}):a.jsxs(a.Fragment,{children:[a.jsx(re,{title:o==null?void 0:o.name,data:o,idColor:(o==null?void 0:o.type)==="onDemandFeaturegroupDTO"?"labels.blue":"labels.orange",version:o==null?void 0:o.version,versions:P,isVersionsLoading:S,onVersionChange:N,hasCommits:!0,commits:(s==null?void 0:s.map(t=>t.commitTime))||[],commit:B,handleCommitChange:A,onClickRefresh:J,isEditDisabled:!k||T||v,onClickEdit:()=>{x(y(p.featureGroup.edit,p.project.value,{id:r,fsId:i,fgId:n}))},pathnamePostFix:"/code",editRightText:T?"Your role is not allowed to perform this action":void 0}),!s&&!I?a.jsx(se,{mainText:"No code commit available for this feature group"}):a.jsxs(Q,{children:[a.jsxs(X,{flexDirection:"column",children:[(!!I||!!R)&&a.jsx(L,{}),a.jsxs(j,{children:[a.jsxs(q,{children:["The following ",d," has been used to generate this feature group commit"]}),a.jsx(W,{mt:"5px",width:"90px",value:l,variant:"light"})]}),e&&e.contentFormat==="JAR"&&a.jsx(j,{mt:"5px",alignItems:"right",children:a.jsx(Z,{sx:{marginLeft:"auto"},onClick:F,intent:"secondary",children:"Download"})})]}),a.jsx(V,{}),e&&(e.contentFormat==="IPYNB"||e.contentFormat==="DBC")&&a.jsx("div",{dangerouslySetInnerHTML:{__html:e.content||""}}),e&&e.contentFormat==="PY"&&a.jsx(j,{children:a.jsx(ee,{title:"Python code",language:"python",copyButton:!0,downloadButton:!0,downloadCallback:F,showLineNumbers:!0,content:e.content})}),e&&e.contentFormat==="JAR"&&a.jsx(te,{content:"The file used to generate this Feature Group was packaged (jar), you can not visualize the code here.",type:oe.neutral})]})]})};export{Ie as default};
