import{q as u}from"./@tanstack-BUCbhJyH.js";import{l as m,m as p,k as d,n as y,F as g,z as A}from"./index-QQb7wQEC.js";import{o as v}from"./url-D5le3J4q.js";import{f as x}from"./stack-detail-query-xmYxSsUY.js";import{g as E}from"./@radix-DP6vWzyx.js";async function P(e){const n=m(p.stackDeployment.config)+(e?`?${v(e)}`:""),t=await d(n,{method:"GET",headers:{"Content-Type":"application/json"}});if(t.status===404&&y(),!t.ok){const a=await t.json().then(r=>Array.isArray(r.detail)?r.detail[1]:r.detail).catch(()=>"Error while fetching stack deployment config");throw new g({status:t.status,statusText:t.statusText,message:a})}return t.json()}async function O(e){const n=m(p.stackDeployment.info)+(e?`?${v(e)}`:""),t=await d(n,{method:"GET",headers:{"Content-Type":"application/json"}});if(t.status===404&&y(),!t.ok){const a=await t.json().then(r=>Array.isArray(r.detail)?r.detail[1]:r.detail).catch(()=>"Error while fetching stack deployment info");throw new g({status:t.status,statusText:t.statusText,message:a})}return t.json()}async function q(e){const n=m(p.stackDeployment.stack)+(e?`?${v(e)}`:""),t=await d(n,{method:"GET",headers:{"Content-Type":"application/json"}});if(t.status===404&&y(),!t.ok){const a=await t.json().then(r=>Array.isArray(r.detail)?r.detail[1]:r.detail).catch(()=>"Error while fetching the deployed stack");throw new g({status:t.status,statusText:t.statusText,message:a})}return t.json()}async function S(e){const n=m(p.stacks.all)+(e?`?${v(e)}`:""),t=await d(n,{method:"GET",headers:{"Content-Type":"application/json"}});if(t.status===404&&y(),!t.ok){const a=await t.json().then(r=>Array.isArray(r.detail)?r.detail[1]:r.detail).catch(()=>"Error while fetching stacks");throw new g({status:t.status,statusText:t.statusText,message:a})}return t.json()}const l={all:["stacks"],stackDeployment:["stack-deployment"],stackList:e=>u({queryKey:[...l.all,e],queryFn:async()=>S(e)}),stackDetail:e=>u({queryKey:[...l.all,e],queryFn:async()=>x({stackId:e})}),stackDeploymentInfo:e=>u({queryKey:[...l.stackDeployment,"info",e],queryFn:async()=>O(e)}),stackDeploymentStack:e=>u({queryKey:[...l.stackDeployment,"stack",e],queryFn:async()=>q(e)}),stackDeploymentConfig:e=>u({queryKey:[...l.stackDeployment,"config",e],queryFn:async()=>P(e)})};var K=function(n){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,a=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},r=void 0,o=void 0,c=void 0,s=[];return function(){var b=$(t),T=new Date().getTime(),F=!r||T-r>b;r=T;for(var j=arguments.length,f=Array(j),h=0;h<j;h++)f[h]=arguments[h];if(F&&a.leading)return a.accumulate?Promise.resolve(n.call(this,[f])).then(function(D){return D[0]}):Promise.resolve(n.call.apply(n,[this].concat(f)));if(o?clearTimeout(c):o=G(),s.push(f),c=setTimeout(i.bind(this),b),a.accumulate){var C=s.length-1;return o.promise.then(function(D){return D[C]})}return o.promise};function i(){var k=o;clearTimeout(c),Promise.resolve(a.accumulate?n.call(this,s):n.apply(this,s[s.length-1])).then(k.resolve,k.reject),s=[],o=null}};function $(e){return typeof e=="function"?e():e}function G(){var e={};return e.promise=new Promise(function(n,t){e.resolve=n,e.reject=t}),e}const L=E(K);function R(e){var n=null,t=null,a=new Promise(function(r,o){n=r,t=o});return e&&e.then(function(r){n&&n(r)},function(r){t&&t(r)}),{promise:a,resolve:function(r){n&&n(r)},reject:function(r){t&&t(r)},cancel:function(){n=null,t=null}}}function W(e){var n=null,t=function(){for(var a=[],r=0;r<arguments.length;r++)a[r]=arguments[r];n&&n();var o=e.apply(void 0,a),c=R(o),s=c.promise,i=c.cancel;return n=i,s};return t}/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0

THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.

See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */var w=function(){return w=Object.assign||function(n){for(var t,a=1,r=arguments.length;a<r;a++){t=arguments[a];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(n[o]=t[o])}return n},w.apply(this,arguments)},z={key:function(){return null},onlyResolvesLast:!0},I=function(){function e(n){this.config=n,this.debounceSingleton=null,this.debounceCache={}}return e.prototype._createDebouncedFunction=function(){var n=L(this.config.func,this.config.wait,this.config.options);return this.config.options.onlyResolvesLast&&(n=W(n)),{func:n}},e.prototype.getDebouncedFunction=function(n){var t,a=(t=this.config.options).key.apply(t,n);return a===null||typeof a>"u"?(this.debounceSingleton||(this.debounceSingleton=this._createDebouncedFunction()),this.debounceSingleton):(this.debounceCache[a]||(this.debounceCache[a]=this._createDebouncedFunction()),this.debounceCache[a])},e}();function N(e,n,t){var a=w({},z,t),r=new I({func:e,wait:n,options:a}),o=function(){for(var c=[],s=0;s<arguments.length;s++)c[s]=arguments[s];var i=r.getDebouncedFunction(c).func;return i.apply(void 0,c)};return o}const Q=N(async e=>(await S({name:e})).total===0,500),U=A.string().trim().min(1,"Stack name is required").max(32,"Stack name must be less than 32 characters").regex(/^[a-zA-Z0-9-]+$/,"Stack name can only contain alphanumeric characters and hyphens").refine(e=>Q(e),"Stack name is already in use");export{U as a,l as s};
