import{$ as e,$t as t,Bt as n,En as r,Ht as i,On as a,Pt as o,Rn as s,Vt as ee,X as te,Yn as c,Z as ne,ar as l,cn as u,cr as d,dn as f,et as p,fn as m,ln as h,nt as g,on as _,pn as re,rn as v,rr as y,rt as b,sn as x,sr as ie,tt as ae,un as S,zn as oe,zt as se}from"./game-logic-BBFCPVtv.js";import"./vendor-pinia-L_8CmDWM.js";import"./vendor-crypto-CQM8pryk.js";import"./game-i18n-BC9uiVvf.js";import"./vendor-others-Bce0hM6h.js";import"./vendor-reka-ui-DR3m_AkV.js";import"./vendor-utils-BlvnUqQX.js";import"./vendor-vueuse-Djj-oRw9.js";import{F as C,U as ce}from"./vendor-icons-Ccm2_GPI.js";import{t as le}from"./CardDescription-DduF5EVY.js";import{d as w,v as T}from"./game-config-DRP-gbpS.js";import{$ as ue,A as E,F as D,I as O,J as k,K as de,L as fe,M as A,N as j,P as pe,X as me,d as he,f as ge,j as M,k as N,l as P,m as F,o as I,p as L,s as _e,x as ve}from"./index-B4KMqZ_y.js";import{t as ye}from"./useGameConfig-DLqfPHtW.js";import{t as be}from"./CardUnlockOverlay-CspXlcWR.js";var xe={key:0,class:`container mx-auto p-4 sm:p-6`},Se={class:`text-2xl sm:text-3xl font-bold mb-4 sm:mb-6`},Ce={class:`mb-4 sm:mb-6 p-3 sm:p-4 bg-muted/50 rounded-lg border`},we={class:`flex items-center justify-between`},Te={class:`text-sm sm:text-base font-medium flex items-center gap-2`},Ee={class:`text-sm sm:text-base font-bold`},De={class:`mt-2`},Oe={class:`w-full bg-background rounded-full h-2.5 sm:h-3 overflow-hidden`},ke={class:`grid grid-cols-2 lg:grid-cols-3 gap-3 sm:gap-4`},Ae={class:`mb-2`},je={class:`flex flex-col sm:flex-row sm:justify-between sm:items-start gap-2`},Me={class:`space-y-3`},Ne={class:`text-xs sm:text-sm space-y-1.5 sm:space-y-2`},Pe={class:`text-muted-foreground mb-1 sm:mb-2`},Fe={class:`space-y-1 sm:space-y-1.5`},Ie={class:`text-xs`},Le={class:`text-xs sm:text-sm space-y-0.5 sm:space-y-1`},Re={class:`flex items-center gap-1.5 text-muted-foreground`},ze={class:`flex items-center gap-1.5 text-muted-foreground`},Be={key:1,class:`text-xs text-muted-foreground`},Ve={class:`flex gap-2 flex-wrap`},He={key:0},R=re({__name:`BuildingsView`,setup(re){let R=ue(),Ue=ve(),{t:z}=me(),{BUILDINGS:B,TECHNOLOGIES:We}=ye(),V=_(()=>R.currentPlanet),H=c(!1),U=c(``),W=c(``),G=c(!1),K=c(``),q=c(null),Ge=[{key:`metal`},{key:`crystal`},{key:`deuterium`},{key:`darkMatter`}],Ke=_(()=>V.value?Object.values(w).filter(e=>{let t=B.value[e];return V.value.isMoon?t.moonOnly===!0:t.moonOnly!==!0}):[]),qe=e=>{if(!R.currentPlanet||!p(R.currentPlanet,e,R.player.technologies,R.player.officers).valid)return!1;let t=ne(R.currentPlanet,e,R.player.officers);return R.currentPlanet.buildQueue.push(t),!0},J=e=>i(e),Je=e=>{if(!X(e)){U.value=z(`common.requirementsNotMet`),W.value=Ye(e),H.value=!0;return}qe(e)||(U.value=z(`buildingsView.upgradeFailed`),W.value=z(`buildingsView.upgradeFailedMessage`),H.value=!0)},Y=e=>V.value?.buildings[e]||0,X=e=>{if(!V.value)return!1;let t=B.value[e],n=g(t,Y(e)+1);return!n||Object.keys(n).length===0?!0:ae(V.value,R.player.technologies,n)},Z=e=>{if(!V.value)return z(`buildingsView.upgrade`);let t=B.value[e],n=Y(e);return t.maxLevel!==void 0&&n>=t.maxLevel?z(`buildingsView.maxLevelReached`):V.value.buildQueue.length>0||X(e)?z(`buildingsView.upgrade`):z(`buildingsView.requirementsNotMet`)},Ye=e=>{let t=B.value[e],n=g(t,Y(e)+1);if(!n||!V.value)return``;let r=[];for(let[e,t]of Object.entries(n))if(Object.values(w).includes(e)){let n=e,i=V.value.buildings[n]||0,a=B.value[n]?.name||n,o=i>=t?`✓`:`✗`;r.push(`${o} ${a}: Lv ${t} (${z(`common.current`)}: Lv ${i})`)}else if(Object.values(T).includes(e)){let n=e,i=R.player.technologies[n]||0,a=We.value[n]?.name||n,o=i>=t?`✓`:`✗`;r.push(`${o} ${a}: Lv ${t} (${z(`common.current`)}: Lv ${i})`)}return r.join(`
`)},Xe=e=>{if(!V.value)return!1;let t=B.value[e],n=Y(e);if(t.maxLevel!==void 0&&n>=t.maxLevel)return!1;let r=o(R.player.officers,Date.now()),i=b(V.value,r.additionalBuildQueue);if(V.value.buildQueue.filter(e=>e.type===`building`||e.type===`demolish`).length>=i||!p(V.value,e,R.player.technologies,R.player.officers).valid)return!1;let a=Q(e,n+1);return V.value.resources.metal>=a.metal&&V.value.resources.crystal>=a.crystal&&V.value.resources.deuterium>=a.deuterium&&V.value.resources.darkMatter>=a.darkMatter},Q=(e,t)=>se(e,t),Ze=(e,t)=>{if(!V.value)return 0;let r=o(R.player.officers,Date.now()),i=V.value.buildings[w.RoboticsFactory]||0,a=V.value.buildings[w.NaniteFactory]||0;return n(e,t,r.buildingSpeedBonus,i,a)},Qe=t=>{if(!R.currentPlanet||!e(R.currentPlanet,t,R.player.officers).valid)return!1;let n=te(R.currentPlanet,t,R.player.officers);return R.currentPlanet.buildQueue.push(n),!0},$e=e=>{let t=B.value[e].name,n=$(e);K.value=`${z(`buildingsView.confirmDemolishMessage`)}: ${t}

${z(`buildingsView.demolishRefund`)}:
${z(`resources.metal`)}: ${I(n.metal)}
${z(`resources.crystal`)}: ${I(n.crystal)}
${z(`resources.deuterium`)}: ${I(n.deuterium)}${n.darkMatter>0?`\n${z(`resources.darkMatter`)}: ${I(n.darkMatter)}`:``}`,q.value=e,G.value=!0},et=()=>{q.value&&(Qe(q.value)||(U.value=z(`buildingsView.demolishFailed`),W.value=z(`buildingsView.demolishFailedMessage`),H.value=!0)),G.value=!1,q.value=null},tt=e=>{if(!V.value||Y(e)<=0)return!1;let t=o(R.player.officers,Date.now()),n=b(V.value,t.additionalBuildQueue);return!(V.value.buildQueue.filter(e=>e.type===`building`||e.type===`demolish`).length>=n)},$=e=>ee(e,Y(e));return(e,n)=>V.value?(r(),S(`div`,xe,[x(`h1`,Se,d(y(z)(`buildingsView.title`)),1),x(`div`,Ce,[x(`div`,we,[x(`div`,Te,[m(y(C),{size:16}),f(` `+d(y(z)(`buildingsView.spaceUsage`))+`: `,1)]),x(`div`,Ee,[x(`span`,{class:l(J(V.value)>V.value.maxSpace?`text-destructive`:`text-primary`)},d(y(I)(J(V.value))),3),n[2]||=x(`span`,{class:`text-muted-foreground mx-1`},`/`,-1),x(`span`,null,d(y(I)(V.value.maxSpace)),1)])]),x(`div`,De,[x(`div`,Oe,[x(`div`,{class:l([`h-full transition-all duration-300`,J(V.value)>V.value.maxSpace?`bg-destructive`:`bg-primary`]),style:ie({width:`${Math.min(J(V.value)/V.value.maxSpace*100,100)}%`})},null,6)])])]),x(`div`,ke,[(r(!0),S(v,null,a(Ke.value,e=>(r(),u(y(F),{key:e,class:`relative`},{default:s(()=>[m(be,{requirements:y(B)[e].requirements,currentLevel:Y(e)},null,8,[`requirements`,`currentLevel`]),m(y(ge),null,{default:s(()=>[x(`div`,Ae,[x(`div`,je,[m(y(he),{class:`text-sm sm:text-base lg:text-lg cursor-pointer hover:text-primary transition-colors underline decoration-dotted underline-offset-4 order-2 sm:order-1`,onClick:t=>y(Ue).openBuilding(e,Y(e))},{default:s(()=>[f(d(y(B)[e].name),1)]),_:2},1032,[`onClick`]),m(y(de),{variant:`secondary`,class:`text-xs whitespace-nowrap self-start order-1 sm:order-2`},{default:s(()=>[f(` Lv `+d(Y(e)),1)]),_:2},1024)])]),m(y(le),{class:`text-xs sm:text-sm`},{default:s(()=>[f(d(y(B)[e].description),1)]),_:2},1024)]),_:2},1024),m(y(L),null,{default:s(()=>[x(`div`,Me,[x(`div`,Ne,[x(`p`,Pe,d(y(z)(`buildingsView.upgradeCost`))+`:`,1),x(`div`,Fe,[(r(),S(v,null,a(Ge,n=>oe(x(`div`,{key:n.key,class:`flex items-center gap-1.5 sm:gap-2`},[m(fe,{type:n.key,size:`sm`},null,8,[`type`]),x(`span`,Ie,d(y(z)(`resources.${n.key}`))+`:`,1),x(`span`,{class:l([`font-medium text-xs sm:text-sm`,y(P)(V.value.resources[n.key],Q(e,Y(e)+1)[n.key])])},d(y(I)(Q(e,Y(e)+1)[n.key])),3)]),[[t,n.key!==`darkMatter`||Q(e,Y(e)+1).darkMatter>0]])),64))])]),x(`div`,Le,[x(`div`,Re,[m(y(ce),{size:14,class:`flex-shrink-0`}),x(`span`,null,d(y(_e)(Ze(e,Y(e)+1))),1)]),x(`div`,ze,[m(y(C),{size:14,class:`flex-shrink-0`}),x(`span`,null,d(y(B)[e].spaceUsage),1)])]),m(y(k),{onClick:t=>Je(e),disabled:!Xe(e),class:`w-full`},{default:s(()=>[f(d(Z(e)),1)]),_:2},1032,[`onClick`,`disabled`]),Y(e)>0?(r(),u(y(k),{key:0,onClick:t=>$e(e),disabled:!tt(e),variant:`destructive`,class:`w-full`},{default:s(()=>[f(d(y(z)(`buildingsView.demolish`)),1)]),_:1},8,[`onClick`,`disabled`])):h(``,!0),Y(e)>0?(r(),S(`div`,Be,[x(`p`,null,d(y(z)(`buildingsView.demolishRefund`))+`:`,1),x(`div`,Ve,[x(`span`,null,d(y(I)($(e).metal))+` `+d(y(z)(`resources.metal`)),1),x(`span`,null,d(y(I)($(e).crystal))+` `+d(y(z)(`resources.crystal`)),1),x(`span`,null,d(y(I)($(e).deuterium))+` `+d(y(z)(`resources.deuterium`)),1),$(e).darkMatter>0?(r(),S(`span`,He,d(y(I)($(e).darkMatter))+` `+d(y(z)(`resources.darkMatter`)),1)):h(``,!0)])])):h(``,!0)])]),_:2},1024)]),_:2},1024))),128))]),m(y(O),{open:H.value,"onUpdate:open":n[0]||=e=>H.value=e},{default:s(()=>[m(y(j),null,{default:s(()=>[m(y(E),null,{default:s(()=>[m(y(N),null,{default:s(()=>[f(d(U.value),1)]),_:1}),m(y(A),{class:`whitespace-pre-line`},{default:s(()=>[f(d(W.value),1)]),_:1})]),_:1}),m(y(M),null,{default:s(()=>[m(y(D),null,{default:s(()=>[f(d(y(z)(`common.confirm`)),1)]),_:1})]),_:1})]),_:1})]),_:1},8,[`open`]),m(y(O),{open:G.value,"onUpdate:open":n[1]||=e=>G.value=e},{default:s(()=>[m(y(j),null,{default:s(()=>[m(y(E),null,{default:s(()=>[m(y(N),null,{default:s(()=>[f(d(y(z)(`buildingsView.confirmDemolish`)),1)]),_:1}),m(y(A),{class:`whitespace-pre-line`},{default:s(()=>[f(d(K.value),1)]),_:1})]),_:1}),m(y(M),null,{default:s(()=>[m(y(pe),null,{default:s(()=>[f(d(y(z)(`common.cancel`)),1)]),_:1}),m(y(D),{onClick:et},{default:s(()=>[f(d(y(z)(`common.confirm`)),1)]),_:1})]),_:1})]),_:1})]),_:1},8,[`open`])])):h(``,!0)}});export{R as default};