import{KvKeyEditorHashCtrl as t}from"./kv-key-editor-hash-ctrl.js";import{KvKeyEditorListCtrl as e}from"./kv-key-editor-list-ctrl.js";import{KvKeyEditorSetCtrl as r}from"./kv-key-editor-set-ctrl.js";import{KvKeyEditorStringCtrl as i}from"./kv-key-editor-string-ctrl.js";import{Abortable as a}from"./kv-utils.js";class s{constructor(t,e,r){this._component=t,this._updateDetailState=e,this._kvClient=r,this._abortable=new a,this._currentEditorCtrl=null}abort(){this._abortable.abort()}get editorCtrl(){return this._currentEditorCtrl}hide(){this._currentEditorCtrl=null,this._updateDetailState({type:"hidden"})}get keyName(){return this._currentEditorCtrl?.keyName}async load(t){this._currentEditorCtrl=this._createKeyEditorCtrl(t.name,t.type);try{await this._currentEditorCtrl.load()}catch(t){if(!(t instanceof DOMException&&"AbortError"===t.name))throw t}}async add(t){this._currentEditorCtrl=this._createKeyEditorCtrl(t.name,t.type),this._updateDetailState((t=>{t.formState.type="adding"}));try{await this._currentEditorCtrl.create(t)}catch(t){const e=function(t){return t?.responseBody?.code}(t);if("clever.redis-http.key-already-exists"!==e)throw this._updateDetailState({type:"add",formState:{type:"idle"}}),t;this._updateDetailState({type:"add",formState:{type:"idle",errors:{keyName:"already-used"}}})}}_createKeyEditorCtrl(a,s){switch(s){case"string":return new i(a,this._component,this._updateDetailState,this._kvClient,this._abortable);case"hash":return new t(a,this._component,this._updateDetailState,this._kvClient,this._abortable);case"list":return new e(a,this._component,this._updateDetailState,this._kvClient,this._abortable);case"set":return new r(a,this._component,this._updateDetailState,this._kvClient,this._abortable)}}}export{s as KvDetailsCtrl};
//# sourceMappingURL=kv-details-ctrl.js.map
