import{ItemStack as t,system as e}from"@minecraft/server";import{DrawerModifier as s}from"../base/modifier.js";import{ActionFormData as r,ModalFormData as o}from"@minecraft/server-ui";import{UPGRADE_SLOTS as a,getUpgradeInSlot as n,getUpgradeMultiplier as d,setDrawerUpgrade as i}from"../drawers.js";import{EMPTY_UPGRADE as _}from"../upgrades.js";import{Hand as l}from"../render.js";import{addItemOrDrop as f}from"../utils.js";import{getPlayerHeldItem as p,setPlayerHeldItem as b}from"../utils/players.js";class c extends s{constructor(){super(...arguments),this.isItemValid=t=>"ftb_sd:drawer_key"===t?.typeId,this.onUseModifier=(t,e,s,r)=>{e.hasTag("ftb_sd:storage_drawer")&&(r.setDrawerLocked(s,!r.isDrawerLocked(s)),t.playSound("use.chain"))},this.onUseItem=(t,e)=>{}}}class u extends s{constructor(){super(...arguments),this.isItemValid=t=>"ftb_sd:display_key"===t?.typeId,this.onUseModifier=(t,e,s,r)=>{e.hasTag("ftb_sd:storage_drawer")&&this.openTopForm(t,e,s,r)},this.onUseItem=(t,e)=>{}}openTopForm(t,e,s,o){(new r).title({translate:"ftb_sd.display_settings_title"}).button({translate:o.isDisplayEnabled(s)?"ftb_sd.display_toggle_on":"ftb_sd.display_toggle_off"}).button({translate:"ftb_sd.display_settings_color"}).button({translate:"ftb_sd.font_title"}).button({translate:"ftb_sd.refresh_display"}).button({translate:"ftb_sd.close"}).show(t).then((r=>{switch(r.selection){case 0:o.setDisplayKey(s,e,!o.isDisplayEnabled(s)),this.openTopForm(t,e,s,o);break;case 1:this.openTopForm(t,e,s,o),this.openColorForm(t,e,s,o);break;case 2:this.openTopForm(t,e,s,o),this.openFontForm(t,e,s,o);break;case 3:o.refreshDisplay(s)}}))}openFontForm(t,e,s,r){const a=Number(s.getProperty("ftb_sd:font")??0);(new o).title({translate:"ftb_sd.font_title"}).dropdown({translate:"ftb_sd.font_title_newline",with:["\n"]},[{translate:"ftb_sd.font_0"},{translate:"ftb_sd.font_1"}],a).submitButton({translate:"ftb_sd.submit"}).show(t).then((t=>{if(!t.canceled){const e=t.formValues[0];s.setProperty("ftb_sd:font",e)}}))}openColorForm(t,e,s,r){const a=256*Number(s.getProperty("ftb_sd:color_r")??0),n=256*Number(s.getProperty("ftb_sd:color_g")??0),d=256*Number(s.getProperty("ftb_sd:color_b")??0);(new o).title({translate:"ftb_sd.display_settings_color"}).slider({translate:"ftb_sd.color_r"},0,256,1,a).slider({translate:"ftb_sd.color_g"},0,256,1,n).slider({translate:"ftb_sd.color_b"},0,256,1,d).submitButton({translate:"ftb_sd.submit"}).show(t).then((t=>{if(!t.canceled){const e=t.formValues[0]/256,r=t.formValues[1]/256,o=t.formValues[2]/256;s.setProperty("ftb_sd:color_r",e),s.setProperty("ftb_sd:color_g",r),s.setProperty("ftb_sd:color_b",o)}}))}}class m extends s{constructor(){super(...arguments),this.isItemValid=t=>"ftb_sd:upgrade_key"===t?.typeId,this.onUseModifier=(t,e,s,r)=>{e.hasTag("ftb_sd:storage_drawer")&&this.handleSettingsGUI(t,s,r)},this.onUseItem=(t,e)=>{}}handleSettingsGUI(e,s,o){let p=(new r).title({translate:"ftb_sd.drawer_title"}).body(o.getSettingGUIBody(s));const b=new Map;let c=0;for(let t=0;t<a;t++){const e=n(s,t);e!==_&&(p=p.button({translate:"ftb_sd.remove_upgrade",with:[e.displayName]},e.texture),b.set(c++,t))}0===c&&(p=p.button({translate:"ftb_sd.no_upgrades"})),p.show(e).then((r=>{const a=b.get(r.selection);if(void 0!==a){const r=n(s,a);let p=o.getDrawerMaxItemCountWithMuti(s,d(s)-r.upgradeMultiplier);if(o.getDrawerItemCount(s,l.MAIN_HAND)>p)return void e.sendMessage({translate:"ftb_sd.cant_remove"});i(s,a,_),f(e,new t(r.itemId,1),void 0)}}))}}const g=new c,y=new u,h=new m;class w extends s{constructor(){super(...arguments),this.isItemValid=t=>t?.hasTag("ftb_sd:grouped_key"),this.onUseModifier=(t,e,s,r)=>{const o=p(t);if(!t.isSneaking)switch(o?.typeId){case"ftb_sd:grouped_key":y.onUseModifier(t,e,s,r);break;case"ftb_sd:grouped_key_lock":g.onUseModifier(t,e,s,r);break;case"ftb_sd:grouped_key_upgrade":h.onUseModifier(t,e,s,r)}},this.onUseItem=(s,r)=>{if(s.isSneaking){let o=r;switch(r?.typeId){case"ftb_sd:grouped_key":o=new t("ftb_sd:grouped_key_lock");break;case"ftb_sd:grouped_key_lock":o=new t("ftb_sd:grouped_key_upgrade");break;case"ftb_sd:grouped_key_upgrade":o=new t("ftb_sd:grouped_key")}e.run((()=>{b(s,o),s.onScreenDisplay.setActionBar({translate:"ftb_sd.grouped_key_switch."+o.typeId.replace("ftb_sd:","")})}))}}}}const k=[g,y,h,new w];export{k as ALL_MODIFIERS,u as DisplayKey,w as GroupedKey,c as RenderKey,m as UpgradeKey};
