import{u as G,ba as _,ed as T,h9 as W,cn as A,ek as B,kO as H,au as J,r as g,x as m,j as e,c5 as z,cE as K,kP as U,gr as X,bI as Y,b4 as O,c as N,q as C,aJ as I,t as Z}from"./index-DHiyXWqE.js";import{P as $}from"./Panel-VWoblIge.js";import{u as ee}from"./useUserPermissions-BpHid_5k.js";import{L as R}from"./LabelValue-BXwn8NCm.js";const oe=({path:o=m.project.featureView.overview,showDelete:P=!1,header:b,children:v})=>{const{id:d,fsId:a,fvName:n,fvVersion:l}=G(),r=_(),{data:y}=T(),{currentData:f}=W(),h=(f==null?void 0:f.featurestoreId)===+a,{isObserver:k}=A(),{data:t,isError:w,isFetching:S,refetch:j,error:i}=B({pId:+d,fsId:+a,id:n,version:+l,params:{expand:["keywords","tags","features","query_string","tag_schemas"].filter(x=>y?!0:!["keywords","tags","tag_schemas"].includes(x))}}),{currentData:c={items:[]},refetch:s}=H({pId:+d,fsId:+a,id:n},{refetchOnFocus:!0}),E=()=>{j(),s()},{isDataScientist:V,isFeatureStoreRestricted:D}=ee(),{data:u}=J(),p=(V||D)&&(u==null?void 0:u.username)!==(t==null?void 0:t.creator.username),[F,M]=g.useState(!1),Q=g.useCallback(x=>{r(o,{fsId:a,fvName:n,fvVersion:x})},[a,n,r,o]),q=()=>{if(M(!1),c.items.length>1){const x=c.items.find(L=>L.version!==+l);r(o,{fsId:a,fvName:n,fvVersion:x.version})}else r(m.project.featureView.list,{fsId:a})};return w&&(i==null?void 0:i.response.status)===400?e.jsx(z,{mainText:i.response.data.errorMsg}):w||!S&&!t?e.jsx(K,{}):e.jsxs(e.Fragment,{children:[e.jsx(se,{isOpen:F,onClose:()=>M(!1),onDeleteSuccess:q}),e.jsx($,{title:String((t==null?void 0:t.name)??n),versions:(c==null?void 0:c.items)??[{version:+l}],version:+l,onVersionChange:Q,idColor:"labels.purple",onClickRefresh:E,onClickDelete:h&&!p?()=>M(!0):void 0,showDelete:P&&!k,data:t,pathnamePostFix:o.replace(m.project.featureView.overview,""),children:b}),v({fv:t,isOwnFeatureView:h,isNotOwnedByDataScientist:p})]})},se=({isOpen:o,onClose:P,onDeleteSuccess:b})=>{const{id:v,fsId:d,fvName:a,fvVersion:n}=G(),[l,{isLoading:r}]=U(),{handleDelete:y}=g.useContext(X),[f,h]=g.useState(!1),[k,t]=g.useState(""),w=Y(),S=()=>{y(Z(m.project.featureView.overview,m.project.value,{id:v,fsId:d,fvName:a,fvVersion:n})),b()},j=(c=!1)=>{l({pId:+v,fsId:+d,id:a,version:+n,force:c}).unwrap().then(S).catch(s=>{var D,u,p,F;const E=((D=s==null?void 0:s.response)==null?void 0:D.status)||(s==null?void 0:s.status),V=((p=(u=s==null?void 0:s.response)==null?void 0:u.data)==null?void 0:p.usrMsg)||((F=s==null?void 0:s.data)==null?void 0:F.usrMsg);E===409?(t(V||"This feature view is being used by existing models or deployments."),h(!0)):w.error({title:"Error",content:V||"Failed to delete feature view"})})},i=()=>{h(!1),t(""),P()};return f?e.jsx(O,{isOpen:o,onClose:i,title:"Warning: Feature view in use",footer:e.jsxs(C,{sx:{gap:"12px"},children:[e.jsx(I,{intent:"secondary",onClick:i,children:"Cancel"}),e.jsx(I,{intent:"alert",isLoading:r,onClick:()=>j(!0),children:"Force delete"})]}),children:e.jsx(N,{width:"100%",style:{whiteSpace:"pre-wrap"},children:k})}):e.jsx(O,{isOpen:o,onClose:i,title:"Delete feature view",footer:e.jsxs(C,{sx:{gap:"12px"},children:[e.jsx(I,{intent:"secondary",onClick:i,children:"Cancel"}),e.jsx(I,{intent:"alert",isLoading:r,onClick:()=>j(!1),children:"Delete feature view"})]}),children:e.jsxs(C,{flexDirection:"column",sx:{gap:"20px"},children:[e.jsxs(C,{sx:{gap:"20px"},children:[e.jsx(R,{label:"Feature View",value:a}),e.jsx(R,{label:"Feature View Version",value:n})]}),e.jsx(N,{width:"350px",children:"Once you delete a file or a folder, there is no going back. Please be certain."})]})})};export{oe as F};
