import{R as k,j as e,H as p,s as v,S as c,h as x}from"./vendor-ClLR6ncd.js";import{S as b,E as M}from"./Messages-BRmQDxrZ.js";import{M as m,b as A,g as D,n as L,au as $,aw as E,ar as j}from"./index-OtVJl4GC.js";import{B as O}from"./index-BpKmttxq.js";import{f as Q}from"./lodash-ZyeDnt0e.js";import{p as y}from"./pluralize-BF8NJH6e.js";import{D as R,a as T,b as G}from"./DialogContent-DR8Wx7Lo.js";import{D as W}from"./DialogTitle-i0lt2jWQ.js";import{D as q}from"./DialogContentText-5YOBSelz.js";import{L as B}from"./Link-BLwKPJFF.js";const g=s=>{var i;return((i=s.data)==null?void 0:i.total)===void 0?s.data:s.data.total},C=s=>!Number.isInteger(s)||s===0;function F({mutation:s,actionKind:i}){var r;const a=g(s);return Q(`${C(a)?"":a} ${y("statement",a)} ${y("was",a)} ${(r=s.data)!=null&&r.parseOnly?"verified":i} successfully!`.trim())}function I({mutation:s,successMessage:i,actionKind:a,applyButtonLabel:r}){var o;const t=A();return e.jsx(b,{message:s.isSuccess?e.jsxs(e.Fragment,{children:[i||F({mutation:s,actionKind:a})," ",(o=s.data)!=null&&o.parseOnly?`Click "${r.toUpperCase()}" so ${C(g(s))||g(s)>1?"they":"it"} could be ${a}.`:e.jsx(B,{component:v,to:D(t),children:"Write a query"})]}):null,reset:s.reset})}function N({applyButtonLabel:s,applyButtonDisabled:i,applyButtonTooltip:a,mutation:r,spanStyle:t,toConfirmLoadAgain:o}){const[d,l]=k.useState(!1),n=()=>{var f;r.isSuccess&&!((f=r.data)!=null&&f.parseOnly)?l(!0):r.mutate()},u=()=>{l(!1)},h=()=>{l(!1),r.mutate()};return e.jsxs(e.Fragment,{children:[e.jsx(m,{title:a,spanStyle:t,children:e.jsx(p,{fullWidth:!0,variant:"contained",onClick:o?n:r.mutate,disabled:r.isLoading||i,children:r.isLoading?"Processing...":s})}),e.jsxs(R,{open:d,onClose:u,children:[e.jsx(W,{children:"Confirm the loading again"}),e.jsx(T,{children:e.jsx(q,{children:"Are you sure you want to import the data again?"})}),e.jsxs(G,{children:[e.jsx(p,{onClick:u,children:"Cancel"}),e.jsx(p,{onClick:h,children:"Confirm"})]})]})]})}function ee({successMessage:s,action:i,extraInfo:a,options:r,description:t,applyButtonLabel:o,applyButtonDisabled:d,applyButtonTooltip:l,mutation:n,actionTitle:u,actionKind:h="imported",toConfirmLoadAgain:f=!1,toIncludeVerify:w=!1}){const{value:S}=L();return $("The ongoing progress track will be lost and the action will continue in the background. Are you sure?",n.isLoading),e.jsxs(c,{textAlign:"left",spacing:2,flexGrow:1,children:[e.jsxs(c,{direction:"row",justifyContent:"space-between",children:[e.jsx(x,{variant:"h4",children:u}),e.jsx(O,{disabled:n.isLoading})]}),e.jsxs(c,{direction:"row",spacing:4,flexGrow:1,children:[e.jsxs(c,{spacing:S?1:2,sx:{width:.6},children:[i,e.jsxs(c,{direction:"row",spacing:1,children:[w?e.jsx(m,{title:l,spanStyle:{flexGrow:1},children:e.jsx(p,{fullWidth:!0,variant:"outlined",onClick:()=>n.mutate({parseOnly:!0}),disabled:n.isLoading||d,children:n.isLoading?"Verifying...":"only verify"})}):null,e.jsx(N,{spanStyle:{flexGrow:1},toConfirmLoadAgain:f,applyButtonLabel:o,applyButtonDisabled:d,applyButtonTooltip:l,mutation:n})]}),e.jsx(M,{error:n.error,resetError:n.reset}),e.jsx(I,{mutation:n,successMessage:s,actionKind:h,applyButtonLabel:o}),a,r]}),e.jsxs(c,{sx:{width:.4},spacing:2,children:[e.jsx(x,{variant:"h5",children:"Input specification"}),typeof t=="string"?e.jsx(x,{sx:{whiteSpace:"pre-wrap"},children:t}):t]})]})]})}const P=s=>{j.invalidateQueries(s,{refetchType:"all"}),j.removeQueries(s)};function se(s={}){const i=E(),a=(r,...t)=>s[r]&&s[r](...t);return{...s,onMutate:(...r)=>{a("onMutate",...r)},onSuccess:(...r)=>{P(i),a("onSuccess",...r)},onSettled:(...r)=>{a("onSettled",...r)}}}export{ee as A,N as E,I as S,se as u};
