import{r as x,j as e}from"./vendor-react-wBh_31cN.js";import{V as U,J as X,r as c,g as Q,P as Y,R as O}from"./index-BKr2rJhV.js";import{C as R}from"./confirmation-dialog-DFt7ZgUQ.js";import{t as Z}from"./toast-3g7Fh-a0.js";import{N as $}from"./NoData-jkjqmCYT.js";import{P as ee}from"./Panel-epT8eD0X.js";import{u as se}from"./useUserPermissions-BVMFDLlq.js";import{R as te}from"./ResourceNotFound-DwuevSJ8.js";import{c as ae,s as ie,t as ne}from"./index-DJIjy7qt.js";import{u as oe}from"./selectors-CMD4o3wq.js";import{u as re}from"./useProjectNavigate-5znX7Ojg.js";import{M as L}from"./metadata-field-B_vcklh-.js";import{V as G}from"./value-76ihWpF6.js";import{u as ce}from"./useProjectRole-UlQXu1Cp.js";import{c as T}from"./vendor-router-D1GqFWiT.js";const be=({path:o=c.project.featureView.overview,showDelete:P=!1,header:N,children:V,filterToolbar:j,count:u,countContent:d,tools:y,isFetchingContent:F,overrideShowDelete:D,overrideOnClickDelete:S,overrideOnClickRefresh:C,editDisabledReason:f})=>{const{id:l,fsId:a,fvName:n,fvVersion:r}=T(),i=re(),{data:s}=U(),{currentData:m}=oe(),p=(m==null?void 0:m.featurestoreId)===+a,{isObserver:h}=ce(),{data:t,isError:g,isFetching:b,refetch:_,error:I}=ae({pId:+l,fsId:+a,id:n,version:+r,params:{expand:["keywords","tags","features","query_string","tag_schemas"].filter(w=>s?!0:!["keywords","tags","tag_schemas"].includes(w))}}),{currentData:v={items:[]},refetch:B}=ie({pId:+l,fsId:+a,id:n},{refetchOnFocus:!0}),H=()=>{_(),B()},{isDataScientist:W,isFeatureStoreRestricted:q}=se(),{data:k}=X(),E=(W||q)&&(k==null?void 0:k.username)!==(t==null?void 0:t.creator.username),[A,M]=x.useState(!1),J=x.useCallback(w=>{i(o,{fsId:a,fvName:n,fvVersion:w})},[a,n,i,o]),z=()=>{if(M(!1),v.items.length>1){const w=v.items.find(K=>K.version!==+r);i(o,{fsId:a,fvName:n,fvVersion:w.version})}else i(c.project.featureView.list,{fsId:a})};return g&&(I==null?void 0:I.response.status)===400?e.jsx($,{mainText:I.response.data.errorMsg}):g||!b&&!t?e.jsx(te,{resource:"feature view",backHref:Q(c.project.featureView.list,c.project.value,{id:l,fsId:a}),backLabel:"Back to feature views"}):e.jsxs(e.Fragment,{children:[e.jsx(le,{isOpen:A,onClose:()=>M(!1),onDeleteSuccess:z}),e.jsx(ee,{title:String((t==null?void 0:t.name)??n),versions:(v==null?void 0:v.items)??[{version:+r}],version:+r,onVersionChange:J,idColor:"labels.purple",onClickEdit:f?()=>{}:void 0,isEditDisabled:!!f,editRightText:f,onClickRefresh:C??H,onClickDelete:S??(p&&!E?()=>M(!0):void 0),showDelete:D!==void 0?D&&!h:P&&!h,data:t,pathnamePostFix:o.replace(c.project.featureView.overview,""),filterToolbar:j,count:u,countContent:d,tools:y,isFetching:F,children:N}),V({fv:t,isOwnFeatureView:p,isNotOwnedByDataScientist:E})]})},le=({isOpen:o,onClose:P,onDeleteSuccess:N})=>{const{id:V,fsId:j,fvName:u,fvVersion:d}=T(),[y,{isLoading:F}]=ne(),{handleDelete:D}=x.useContext(Y),[S,C]=x.useState(!1),[f,l]=x.useState(""),a=()=>{D(Q(c.project.featureView.overview,c.project.value,{id:V,fsId:j,fvName:u,fvVersion:d})),N()},n=(i=!1)=>{y({pId:+V,fsId:+j,id:u,version:+d,force:i}).unwrap().then(a).catch(s=>{var h,t,g,b;const m=((h=s==null?void 0:s.response)==null?void 0:h.status)||(s==null?void 0:s.status),p=((g=(t=s==null?void 0:s.response)==null?void 0:t.data)==null?void 0:g.usrMsg)||((b=s==null?void 0:s.data)==null?void 0:b.usrMsg);m===409?(l(p||"This feature view is being used by existing models or deployments."),C(!0)):Z.error(p||"Failed to delete feature view")})},r=()=>{C(!1),l(""),P()};return S?e.jsx(R,{open:o,onOpenChange:i=>{i||r()},title:"Warning: Feature view in use",confirmLabel:"Force delete",confirmVariant:"destructive",disabled:F,onConfirm:()=>n(!0),children:e.jsx(O,{className:"whitespace-pre-wrap",children:f})}):e.jsx(R,{open:o,onOpenChange:i=>{i||r()},title:"Delete feature view",confirmLabel:"Delete feature view",confirmVariant:"destructive",disabled:F,onConfirm:()=>n(!1),children:e.jsxs("div",{className:"flex flex-col gap-5",children:[e.jsxs("div",{className:"flex gap-5",children:[e.jsx(L,{label:"Feature View",children:e.jsx(G,{children:u})}),e.jsx(L,{label:"Feature View Version",children:e.jsx(G,{children:d})})]}),e.jsx(O,{className:"w-[350px]",children:"Once you delete a feature view, there is no going back. Please be certain."})]})})};export{be as F};
