diff --git a/backend/app/api/routes/auth.py b/backend/app/api/routes/auth.py
index b942c972a..d3981a320 100644
--- a/backend/app/api/routes/auth.py
+++ b/backend/app/api/routes/auth.py
@@ -41,7 +41,7 @@ from backend.app.services.email_service import (
save_smtp_settings,
send_email,
)
-from backend.app.api.routes.settings import get_setting
+from backend.app.api.routes.settings import get_external_login_url
def _user_to_response(user: User) -> UserResponse:
@@ -525,7 +525,6 @@ async def get_advanced_auth_status(db: AsyncSession = Depends(get_db)):
async def forgot_password(request: ForgotPasswordRequest, db: AsyncSession = Depends(get_db)):
"""Request password reset via email (advanced auth only)."""
import logging
- import os
logger = logging.getLogger(__name__)
@@ -557,13 +556,7 @@ async def forgot_password(request: ForgotPasswordRequest, db: AsyncSession = Dep
user.password_hash = get_password_hash(new_password)
await db.commit()
- # Use external_url from settings if available, otherwise fall back to APP_URL env var
- external_url = await get_setting(db, "external_url")
- if external_url:
- external_url = external_url.rstrip("/")
- else:
- external_url = os.environ.get("APP_URL", "http://localhost:5173")
- login_url = external_url + "/login"
+ login_url = await get_external_login_url(db)
# Send password reset email
subject, text_body, html_body = create_password_reset_email(user.username, new_password, login_url)
@@ -587,7 +580,6 @@ async def reset_user_password(
):
"""Reset a user's password and send them an email (admin only, advanced auth only)."""
import logging
- import os
logger = logging.getLogger(__name__)
@@ -638,13 +630,7 @@ async def reset_user_password(
user.password_hash = get_password_hash(new_password)
await db.commit()
- # Use external_url from settings if available, otherwise fall back to APP_URL env var
- external_url = await get_setting(db, "external_url")
- if external_url:
- external_url = external_url.rstrip("/")
- else:
- external_url = os.environ.get("APP_URL", "http://localhost:5173")
- login_url = external_url + "/login"
+ login_url = await get_external_login_url(db)
# Send password reset email
subject, text_body, html_body = create_password_reset_email(user.username, new_password, login_url)
diff --git a/backend/app/api/routes/settings.py b/backend/app/api/routes/settings.py
index 56cc5a83e..973811c35 100644
--- a/backend/app/api/routes/settings.py
+++ b/backend/app/api/routes/settings.py
@@ -32,6 +32,27 @@ async def get_setting(db: AsyncSession, key: str) -> str | None:
return setting.value if setting else None
+async def get_external_login_url(db: AsyncSession) -> str:
+ """Get the external URL for the login page.
+
+ Uses external_url from settings if available, otherwise falls back to APP_URL env var.
+
+ Args:
+ db: Database session
+
+ Returns:
+ Full URL to the login page
+ """
+ import os
+
+ external_url = await get_setting(db, "external_url")
+ if external_url:
+ external_url = external_url.rstrip("/")
+ else:
+ external_url = os.environ.get("APP_URL", "http://localhost:5173")
+ return external_url + "/login"
+
+
async def set_setting(db: AsyncSession, key: str, value: str) -> None:
"""Set a single setting value."""
from sqlalchemy import func
diff --git a/backend/app/api/routes/users.py b/backend/app/api/routes/users.py
index 376809dd9..8eb8d2ae8 100644
--- a/backend/app/api/routes/users.py
+++ b/backend/app/api/routes/users.py
@@ -24,7 +24,7 @@ from backend.app.services.email_service import (
get_smtp_settings,
send_email,
)
-from backend.app.api.routes.settings import get_setting
+from backend.app.api.routes.settings import get_external_login_url
router = APIRouter(prefix="/users", tags=["users"])
@@ -71,7 +71,6 @@ async def create_user(
- Admin cannot set or see the password
"""
import logging
- import os
logger = logging.getLogger(__name__)
@@ -153,13 +152,7 @@ async def create_user(
try:
smtp_settings = await get_smtp_settings(db)
if smtp_settings:
- # Use external_url from settings if available, otherwise fall back to APP_URL env var
- external_url = await get_setting(db, "external_url")
- if external_url:
- external_url = external_url.rstrip("/")
- else:
- external_url = os.environ.get("APP_URL", "http://localhost:5173")
- login_url = external_url + "/login"
+ login_url = await get_external_login_url(db)
subject, text_body, html_body = create_welcome_email(new_user.username, password, login_url)
send_email(smtp_settings, new_user.email, subject, text_body, html_body)
logger.info(f"Welcome email sent to {new_user.email}")
diff --git a/frontend/src/pages/SettingsPage.tsx b/frontend/src/pages/SettingsPage.tsx
index b21b61e98..afe07ef15 100644
--- a/frontend/src/pages/SettingsPage.tsx
+++ b/frontend/src/pages/SettingsPage.tsx
@@ -3435,9 +3435,9 @@ export function SettingsPage() {
-
{t('settings.email.advancedAuthEnabled') || 'Advanced Authentication is enabled'}
+
{t('settings.email.advancedAuthEnabled')}
- {t('settings.email.advancedAuthEnabledDesc') || 'Email-based user management features are active. New users will receive auto-generated passwords via email, and users can reset their passwords through the forgot password feature.'}
+ {t('settings.email.advancedAuthEnabledDesc')}
diff --git a/static/assets/index-NgO9xbrN.js b/static/assets/index-C4SeuzlU.js
similarity index 98%
rename from static/assets/index-NgO9xbrN.js
rename to static/assets/index-C4SeuzlU.js
index 2459a9135..0331edf4a 100644
--- a/static/assets/index-NgO9xbrN.js
+++ b/static/assets/index-C4SeuzlU.js
@@ -8648,7 +8648,7 @@ Accuracy: ${t.time_accuracy.toFixed(0)}%`:t.actual_time_seconds?`Actual: ${m0(t.
transition-all duration-200 hover:border-bambu-dark-tertiary/80
${k?"opacity-50 scale-[1.02] shadow-xl z-50":""}
${E?"border-blue-500/30 bg-gradient-to-r from-blue-500/5 to-transparent":""}
- `,children:a.jsxs("div",{className:"flex items-center gap-4 p-4",children:[P&&d&&a.jsx("button",{onClick:j=>{j.stopPropagation(),d()},className:`flex items-center justify-center w-6 h-6 rounded border transition-colors ${u?"bg-bambu-green border-bambu-green text-white":"border-white/30 bg-black/30 hover:border-bambu-green/50"}`,children:u&&a.jsx(qi,{className:"w-4 h-4"})}),P?a.jsx("div",{...x,...y,className:"flex items-center justify-center w-10 h-10 md:w-8 md:h-8 rounded-lg bg-bambu-dark cursor-grab active:cursor-grabbing hover:bg-bambu-dark-tertiary transition-colors touch-manipulation",children:a.jsx(eb,{className:"w-6 h-6 md:w-4 md:h-4 text-bambu-gray"})}):e!==void 0?a.jsxs("div",{className:"flex items-center justify-center w-8 h-8 rounded-lg bg-bambu-dark text-bambu-gray text-sm font-medium",children:["#",e]}):a.jsx("div",{className:"w-8"}),a.jsx("div",{className:"w-14 h-14 flex-shrink-0 bg-bambu-dark rounded-lg overflow-hidden",children:t.archive_thumbnail?a.jsx("img",{src:t.plate_id!=null?ce.getArchivePlateThumbnail(t.archive_id,t.plate_id):ce.getArchiveThumbnail(t.archive_id),alt:"",className:"w-full h-full object-cover"}):t.library_file_thumbnail?a.jsx("img",{src:t.plate_id!=null?ce.getLibraryFilePlateThumbnail(t.library_file_id,t.plate_id):ce.getLibraryFileThumbnailUrl(t.library_file_id),alt:"",className:"w-full h-full object-cover"}):a.jsx("div",{className:"w-full h-full flex items-center justify-center text-bambu-gray",children:a.jsx(ys,{className:"w-6 h-6"})})}),a.jsxs("div",{className:"flex-1 min-w-0",children:[a.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[a.jsx("p",{className:"text-white font-medium truncate",children:t.archive_name||t.library_file_name||`File #${t.archive_id||t.library_file_id}`}),t.archive_id?a.jsx(Fs,{to:`/archives?highlight=${t.archive_id}`,className:"text-bambu-gray hover:text-bambu-green transition-colors flex-shrink-0",title:b("queue.viewArchive"),children:a.jsx(Xr,{className:"w-3.5 h-3.5"})}):t.library_file_id?a.jsx(Fs,{to:`/library?highlight=${t.library_file_id}`,className:"text-bambu-gray hover:text-bambu-green transition-colors flex-shrink-0",title:b("queue.viewInFileManager"),children:a.jsx(Xr,{className:"w-3.5 h-3.5"})}):null]}),a.jsxs("div",{className:"flex items-center gap-3 text-sm text-bambu-gray",children:[a.jsxs("span",{className:`flex items-center gap-1.5 ${t.printer_id===null&&!t.target_model?"text-orange-400":""} ${t.target_model?"text-blue-400":""}`,children:[a.jsx(Or,{className:"w-3.5 h-3.5"}),t.target_model?`${b("queue.filter.any")} ${t.target_model}${t.target_location?` @ ${t.target_location}`:""}${t.required_filament_types?.length?` (${t.required_filament_types.join(", ")})`:""}`:t.printer_id===null?b("queue.filter.unassigned"):t.printer_name||`${b("common.printer")} #${t.printer_id}`]}),t.print_time_seconds&&a.jsxs("span",{className:"flex items-center gap-1.5",children:[a.jsx(Su,{className:"w-3.5 h-3.5"}),lae(t.print_time_seconds)]}),t.created_by_username&&a.jsxs("span",{className:"flex items-center gap-1.5",title:b("queue.addedBy",{name:t.created_by_username}),children:[a.jsx(Hu,{className:"w-3.5 h-3.5"}),t.created_by_username]}),P&&!t.manual_start&&a.jsxs("span",{className:"flex items-center gap-1.5",children:[a.jsx(nr,{className:"w-3.5 h-3.5"}),MYe(t.scheduled_time,c,b)]})]}),a.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[t.manual_start&&a.jsxs("span",{className:"text-xs px-2 py-0.5 bg-purple-500/10 text-purple-400 rounded-full border border-purple-500/20 flex items-center gap-1",children:[a.jsx(LK,{className:"w-3 h-3"}),b("queue.badges.staged")]}),t.require_previous_success&&a.jsx("span",{className:"text-xs px-2 py-0.5 bg-orange-500/10 text-orange-400 rounded-full border border-orange-500/20",children:b("queue.badges.requiresPrevious")}),t.auto_off_after&&a.jsxs("span",{className:"text-xs px-2 py-0.5 bg-blue-500/10 text-blue-400 rounded-full border border-blue-500/20 flex items-center gap-1",children:[a.jsx(Zu,{className:"w-3 h-3"}),b("queue.badges.autoPowerOff")]})]}),E&&a.jsxs("div",{className:"mt-3",children:[a.jsx("div",{className:"h-2 bg-bambu-dark rounded-full overflow-hidden",children:a.jsx("div",{className:"h-full bg-gradient-to-r from-blue-500 to-blue-400 animate-pulse w-full opacity-50"})}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:b("queue.printingInProgress")})]}),t.waiting_reason&&t.status==="pending"&&a.jsxs("p",{className:"text-xs text-purple-400 mt-2 flex items-start gap-1",children:[a.jsx(Wi,{className:"w-3 h-3 mt-0.5 flex-shrink-0"}),a.jsx("span",{children:t.waiting_reason})]}),t.error_message&&a.jsxs("p",{className:"text-xs text-red-400 mt-2 flex items-center gap-1",children:[a.jsx(Wi,{className:"w-3 h-3"}),t.error_message]})]}),a.jsx(kYe,{status:t.status,waitingReason:t.waiting_reason,printerState:p,t:b}),a.jsxs("div",{className:"flex items-center gap-1",children:[E&&a.jsx(ke,{variant:"ghost",size:"sm",onClick:s,disabled:!h("printers:control"),title:h("printers:control")?b("queue.actions.stopPrint"):b("queue.permissions.noStopPrint"),className:"text-red-400 hover:text-red-300 hover:bg-red-500/10",children:a.jsx(_de,{className:"w-4 h-4"})}),P&&a.jsxs(a.Fragment,{children:[t.manual_start&&a.jsx(ke,{variant:"ghost",size:"sm",onClick:l,disabled:!h("printers:control"),title:h("printers:control")?b("queue.actions.startPrint"):b("queue.permissions.noStartPrint"),className:"text-bambu-green hover:text-bambu-green-light hover:bg-bambu-green/10",children:a.jsx(vo,{className:"w-4 h-4"})}),a.jsx(ke,{variant:"ghost",size:"sm",onClick:n,disabled:!m("queue","update",t.created_by_id),title:m("queue","update",t.created_by_id)?b("common.edit"):b("queue.permissions.noEdit"),children:a.jsx(na,{className:"w-4 h-4"})}),a.jsx(ke,{variant:"ghost",size:"sm",onClick:r,disabled:!m("queue","delete",t.created_by_id),title:m("queue","delete",t.created_by_id)?b("common.cancel"):b("queue.permissions.noCancel"),className:"text-red-400 hover:text-red-300 hover:bg-red-500/10",children:a.jsx(Lt,{className:"w-4 h-4"})})]}),T&&a.jsxs(a.Fragment,{children:[a.jsx(ke,{variant:"ghost",size:"sm",onClick:o,disabled:!h("queue:create"),title:h("queue:create")?b("queue.actions.requeue"):b("queue.permissions.noRequeue"),className:"text-bambu-green hover:text-bambu-green/80 hover:bg-bambu-green/10",children:a.jsx(Ir,{className:"w-4 h-4"})}),a.jsx(ke,{variant:"ghost",size:"sm",onClick:i,disabled:!m("queue","delete",t.created_by_id),title:m("queue","delete",t.created_by_id)?b("common.remove"):b("queue.permissions.noRemove"),children:a.jsx(cn,{className:"w-4 h-4"})})]})]})]})})}function AYe(){const{t}=Sn(),e=un(),{showToast:n}=Hn(),{hasPermission:r,hasAnyPermission:i,canModify:s}=Di(),[o,l]=_.useState(null),[c,u]=_.useState(""),[d,h]=_.useState(""),[m,p]=_.useState(!1),[b,v]=_.useState(null),[x,y]=_.useState(null),[S,N]=_.useState(null),[A,k]=_.useState([]),[C,E]=_.useState(!1),[P,T]=_.useState(()=>localStorage.getItem("queue.historySortBy")||"date"),[j,z]=_.useState(()=>{const ee=localStorage.getItem("queue.historySortAsc");return ee!==null?ee==="true":!1}),[L,B]=_.useState(()=>localStorage.getItem("queue.pendingSortBy")||"position"),[R,$]=_.useState(()=>{const ee=localStorage.getItem("queue.pendingSortAsc");return ee!==null?ee==="true":!0});_.useEffect(()=>{localStorage.setItem("queue.historySortBy",P)},[P]),_.useEffect(()=>{localStorage.setItem("queue.historySortAsc",String(j))},[j]),_.useEffect(()=>{localStorage.setItem("queue.pendingSortBy",L)},[L]),_.useEffect(()=>{localStorage.setItem("queue.pendingSortAsc",String(R))},[R]);const q=Fie(NM(pk,{activationConstraint:{distance:8}}),NM(mk,{coordinateGetter:sae})),{data:I}=st({queryKey:["settings"],queryFn:ce.getSettings}),G=I?.time_format||"system",{data:Y,isLoading:re}=st({queryKey:["queue",o,c],queryFn:()=>ce.getQueue(o||void 0,c||void 0),refetchInterval:5e3}),{data:H}=st({queryKey:["printers"],queryFn:()=>ce.getPrinters()}),K=pt({mutationFn:ee=>ce.cancelQueueItem(ee),onSuccess:()=>{e.invalidateQueries({queryKey:["queue"]}),n(t("queue.toast.cancelled"))},onError:()=>n(t("queue.toast.cancelFailed"),"error")}),ne=pt({mutationFn:ee=>ce.removeFromQueue(ee),onSuccess:()=>{e.invalidateQueries({queryKey:["queue"]}),n(t("queue.toast.removed"))},onError:()=>n(t("queue.toast.removeFailed"),"error")}),ie=pt({mutationFn:ee=>ce.stopQueueItem(ee),onSuccess:()=>{e.invalidateQueries({queryKey:["queue"]}),n(t("queue.toast.stopped"))},onError:()=>n(t("queue.toast.stopFailed"),"error")}),be=pt({mutationFn:ee=>ce.startQueueItem(ee),onSuccess:()=>{e.invalidateQueries({queryKey:["queue"]}),n(t("queue.toast.released"))},onError:()=>n(t("queue.toast.startFailed"),"error")}),pe=pt({mutationFn:ee=>ce.reorderQueue(ee),onSuccess:()=>{e.invalidateQueries({queryKey:["queue"]})},onError:()=>n(t("queue.toast.reorderFailed"),"error")}),de=pt({mutationFn:async()=>{const ee=Y?.filter(U=>["completed","failed","skipped","cancelled"].includes(U.status))||[];for(const U of ee)await ce.removeFromQueue(U.id);return ee.length},onSuccess:ee=>{e.invalidateQueries({queryKey:["queue"]}),n(t("queue.toast.historyCleared",{count:ee}))},onError:()=>n(t("queue.toast.clearHistoryFailed"),"error")}),Ce=pt({mutationFn:ee=>ce.bulkUpdateQueue(ee),onSuccess:ee=>{e.invalidateQueries({queryKey:["queue"]}),k([]),E(!1),n(ee.message)},onError:()=>n(t("queue.toast.updateFailed"),"error")}),ae=pt({mutationFn:async ee=>{for(const U of ee)await ce.cancelQueueItem(U);return ee.length},onSuccess:ee=>{e.invalidateQueries({queryKey:["queue"]}),k([]),n(t("queue.toast.bulkCancelled",{count:ee}))},onError:()=>n(t("queue.toast.bulkCancelFailed"),"error")}),Ae=ee=>{k(U=>U.includes(ee)?U.filter(O=>O!==ee):[...U,ee])},Le=_.useMemo(()=>{const ee=new Set;return H?.forEach(U=>{U.location&&ee.add(U.location)}),Y?.forEach(U=>{U.target_location&&ee.add(U.target_location)}),Array.from(ee).sort()},[H,Y]),fe=_.useCallback(ee=>d?ee.target_location?ee.target_location===d:ee.printer_id?H?.find(O=>O.id===ee.printer_id)?.location===d:!1:!0,[d,H]),Xe=_.useMemo(()=>{let ee=Y?.filter(O=>O.status==="pending")||[];d&&(ee=ee.filter(fe));const U=O=>{if(!O.scheduled_time)return 0;const Z=new Date(O.scheduled_time).getTime(),le=Date.now()+4320*60*60*1e3;return Z>le?0:Z};return[...ee].sort((O,Z)=>{let le;if(L==="name"){const we=O.archive_name||O.library_file_name||"",ye=Z.archive_name||Z.library_file_name||"";le=we.localeCompare(ye)}else L==="printer"?le=(O.printer_name||"").localeCompare(Z.printer_name||""):L==="time"?le=U(O)-U(Z):le=O.position-Z.position;return R?le:-le})},[Y,L,R,fe,d]),W=()=>{const ee=Xe.map(U=>U.id);A.length===ee.length?k([]):k(ee)},Q=_.useMemo(()=>{let ee=Y?.filter(U=>U.status==="printing")||[];return d&&(ee=ee.filter(fe)),ee},[Y,d,fe]),me=_.useMemo(()=>{const ee=new Set;return Q.forEach(U=>{U.printer_id&&ee.add(U.printer_id)}),Array.from(ee)},[Q]),X=iO({queries:me.map(ee=>({queryKey:["printerStatus",ee],queryFn:()=>ce.getPrinterStatus(ee),refetchInterval:5e3}))}),te=_.useMemo(()=>{const ee={};return me.forEach((U,O)=>{const Z=X[O];Z?.data?.state&&(ee[U]=Z.data.state)}),ee},[me,X]),V=_.useMemo(()=>{let ee=Y?.filter(U=>["completed","failed","skipped","cancelled"].includes(U.status))||[];return d&&(ee=ee.filter(fe)),[...ee].sort((U,O)=>{let Z;if(P==="name"){const le=U.archive_name||U.library_file_name||"",we=O.archive_name||O.library_file_name||"";Z=le.localeCompare(we)}else P==="printer"?Z=(U.printer_name||"").localeCompare(O.printer_name||""):Z=new Date(O.completed_at||O.created_at).getTime()-new Date(U.completed_at||U.created_at).getTime();return j?-Z:Z})},[Y,P,j,fe,d]),ge=_.useMemo(()=>Xe.reduce((ee,U)=>ee+(U.print_time_seconds||0),0),[Xe]),Se=ee=>{const{active:U,over:O}=ee;if(!O||U.id===O.id)return;const Z=Xe.findIndex(we=>we.id===U.id),le=Xe.findIndex(we=>we.id===O.id);if(Z!==-1&&le!==-1){const ye=xk(Xe,Z,le).map((se,Oe)=>({id:se.id,position:Oe+1}));pe.mutate(ye)}};return a.jsxs("div",{className:"p-4 md:p-8",children:[a.jsx("div",{className:"flex items-center justify-between mb-8",children:a.jsxs("div",{children:[a.jsxs("h1",{className:"text-2xl font-bold text-white flex items-center gap-3",children:[a.jsx(FK,{className:"w-7 h-7 text-bambu-green"}),t("queue.title")]}),a.jsx("p",{className:"text-bambu-gray mt-1",children:t("queue.subtitle")})]})}),a.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-4 gap-4 mb-8",children:[a.jsx(_t,{className:"bg-gradient-to-br from-blue-500/10 to-transparent border-blue-500/20",children:a.jsx(Mt,{className:"p-4",children:a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx("div",{className:"w-10 h-10 rounded-lg bg-blue-500/20 flex items-center justify-center",children:a.jsx(vo,{className:"w-5 h-5 text-blue-400"})}),a.jsxs("div",{children:[a.jsx("p",{className:"text-2xl font-bold text-white",children:Q.length}),a.jsx("p",{className:"text-sm text-bambu-gray",children:t("queue.summary.printing")})]})]})})}),a.jsx(_t,{className:"bg-gradient-to-br from-yellow-500/10 to-transparent border-yellow-500/20",children:a.jsx(Mt,{className:"p-4",children:a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx("div",{className:"w-10 h-10 rounded-lg bg-yellow-500/20 flex items-center justify-center",children:a.jsx(nr,{className:"w-5 h-5 text-yellow-400"})}),a.jsxs("div",{children:[a.jsx("p",{className:"text-2xl font-bold text-white",children:Xe.length}),a.jsx("p",{className:"text-sm text-bambu-gray",children:t("queue.summary.queued")})]})]})})}),a.jsx(_t,{className:"bg-gradient-to-br from-bambu-green/10 to-transparent border-bambu-green/20",children:a.jsx(Mt,{className:"p-4",children:a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx("div",{className:"w-10 h-10 rounded-lg bg-bambu-green/20 flex items-center justify-center",children:a.jsx(Su,{className:"w-5 h-5 text-bambu-green"})}),a.jsxs("div",{children:[a.jsx("p",{className:"text-2xl font-bold text-white",children:lae(ge)}),a.jsx("p",{className:"text-sm text-bambu-gray",children:t("queue.summary.totalTime")})]})]})})}),a.jsx(_t,{className:"bg-gradient-to-br from-gray-500/10 to-transparent border-gray-500/20",children:a.jsx(Mt,{className:"p-4",children:a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx("div",{className:"w-10 h-10 rounded-lg bg-gray-500/20 flex items-center justify-center",children:a.jsx(Nr,{className:"w-5 h-5 text-gray-400"})}),a.jsxs("div",{children:[a.jsx("p",{className:"text-2xl font-bold text-white",children:V.length}),a.jsx("p",{className:"text-sm text-bambu-gray",children:t("queue.summary.history")})]})]})})})]}),a.jsxs("div",{className:"flex items-center gap-4 mb-6",children:[a.jsxs("select",{className:"px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:o===-1?"unassigned":o||"",onChange:ee=>{const U=ee.target.value;l(U==="unassigned"?-1:U===""?null:Number(U))},children:[a.jsx("option",{value:"",children:t("queue.filter.allPrinters")}),a.jsx("option",{value:"unassigned",children:t("queue.filter.unassigned")}),H?.map(ee=>a.jsx("option",{value:ee.id,children:ee.name},ee.id))]}),a.jsxs("select",{className:"px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:c,onChange:ee=>u(ee.target.value),children:[a.jsx("option",{value:"",children:t("queue.filter.allStatus")}),a.jsx("option",{value:"pending",children:t("queue.status.pending")}),a.jsx("option",{value:"printing",children:t("queue.status.printing")}),a.jsx("option",{value:"completed",children:t("queue.status.completed")}),a.jsx("option",{value:"failed",children:t("queue.status.failed")}),a.jsx("option",{value:"skipped",children:t("queue.status.skipped")}),a.jsx("option",{value:"cancelled",children:t("queue.status.cancelled")})]}),Le.length>0&&a.jsxs("select",{className:"px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:d,onChange:ee=>h(ee.target.value),children:[a.jsx("option",{value:"",children:t("queue.filter.allLocations")}),Le.map(ee=>a.jsx("option",{value:ee,children:ee},ee))]}),a.jsx("div",{className:"flex-1"}),V.length>0&&a.jsxs(ke,{variant:"secondary",size:"sm",onClick:()=>p(!0),disabled:!r("queue:delete_all"),title:r("queue:delete_all")?void 0:t("queue.permissions.noClearHistory"),children:[a.jsx(cn,{className:"w-4 h-4"}),t("queue.clearHistory")]})]}),re?a.jsx("div",{className:"text-center py-12 text-bambu-gray",children:t("common.loading")}):Y?.length===0?a.jsxs(_t,{className:"p-12 text-center border-dashed",children:[a.jsx(ei,{className:"w-16 h-16 text-bambu-gray mx-auto mb-4 opacity-50"}),a.jsx("h3",{className:"text-xl font-medium text-white mb-2",children:t("queue.empty.title")}),a.jsx("p",{className:"text-bambu-gray max-w-md mx-auto",children:t("queue.empty.description")})]}):a.jsxs("div",{className:"space-y-8",children:[Q.length>0&&a.jsxs("div",{children:[a.jsxs("h2",{className:"text-lg font-semibold text-white mb-4 flex items-center gap-2",children:[a.jsx("div",{className:"w-2 h-2 rounded-full bg-blue-400 animate-pulse"}),t("queue.sections.currentlyPrinting")]}),a.jsx("div",{className:"space-y-3",children:Q.map(ee=>a.jsx(gP,{item:ee,onEdit:()=>{},onCancel:()=>{},onRemove:()=>{},onStop:()=>N({type:"stop",item:ee}),onRequeue:()=>{},onStart:()=>{},timeFormat:G,hasPermission:r,canModify:s,printerState:ee.printer_id?te[ee.printer_id]:null,t},ee.id))})]}),Xe.length>0&&a.jsxs("div",{children:[a.jsxs("div",{className:"flex items-center justify-between mb-4",children:[a.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[a.jsx(nr,{className:"w-5 h-5 text-yellow-400"}),t("queue.sections.queued"),a.jsxs("span",{className:"text-sm font-normal text-bambu-gray",children:["(",t("queue.itemCount",{count:Xe.length}),")"]}),a.jsx("span",{className:"text-xs text-bambu-gray ml-2",title:t("queue.reorderHint"),children:t("queue.dragToReorder")})]}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsxs("select",{className:"px-3 py-1.5 text-sm bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:L,onChange:ee=>B(ee.target.value),children:[a.jsx("option",{value:"position",children:t("queue.sort.byPosition")}),a.jsx("option",{value:"name",children:t("queue.sort.byName")}),a.jsx("option",{value:"printer",children:t("queue.sort.byPrinter")}),a.jsx("option",{value:"time",children:t("queue.sort.bySchedule")})]}),a.jsx(ke,{variant:"ghost",size:"sm",onClick:()=>$(!R),title:t(R?"common.ascending":"common.descending"),className:"px-2",children:R?a.jsx(Zg,{className:"w-4 h-4"}):a.jsx(ay,{className:"w-4 h-4"})})]})]}),a.jsxs("div",{className:"flex items-center gap-3 mb-4 p-3 bg-bambu-dark rounded-lg",children:[a.jsxs(ke,{variant:"ghost",size:"sm",onClick:W,className:"flex items-center gap-2",children:[A.length===Xe.length&&Xe.length>0?a.jsx(qs,{className:"w-4 h-4 text-bambu-green"}):a.jsx(ll,{className:"w-4 h-4"}),A.length===Xe.length&&Xe.length>0?t("queue.bulkEdit.deselectAll"):t("queue.bulkEdit.selectAll")]}),A.length>0&&a.jsxs(a.Fragment,{children:[a.jsx("span",{className:"text-sm text-bambu-gray",children:t("queue.bulkEdit.selected",{count:A.length})}),a.jsx("div",{className:"h-4 w-px bg-bambu-dark-tertiary"}),a.jsxs(ke,{variant:"ghost",size:"sm",onClick:()=>E(!0),className:"flex items-center gap-2 text-bambu-green hover:text-bambu-green-light",disabled:!i("queue:update_own","queue:update_all"),title:i("queue:update_own","queue:update_all")?void 0:t("queue.permissions.noEditItems"),children:[a.jsx(na,{className:"w-4 h-4"}),t("queue.bulkEdit.editSelected")]}),a.jsxs(ke,{variant:"ghost",size:"sm",onClick:()=>ae.mutate(A),className:"flex items-center gap-2 text-red-400 hover:text-red-300",disabled:ae.isPending||!i("queue:delete_own","queue:delete_all"),title:i("queue:delete_own","queue:delete_all")?void 0:t("queue.permissions.noCancelItems"),children:[a.jsx(Lt,{className:"w-4 h-4"}),t("queue.bulkEdit.cancelSelected")]})]})]}),a.jsx(eae,{sensors:q,collisionDetection:Bie,onDragEnd:Se,children:a.jsx(rae,{items:Xe.map(ee=>ee.id),strategy:mYe,children:a.jsx("div",{className:"space-y-3",children:Xe.map((ee,U)=>a.jsx(gP,{item:ee,position:U+1,onEdit:()=>v(ee),onCancel:()=>N({type:"cancel",item:ee}),onRemove:()=>{},onStop:()=>{},onRequeue:()=>{},onStart:()=>be.mutate(ee.id),timeFormat:G,isSelected:A.includes(ee.id),onToggleSelect:()=>Ae(ee.id),hasPermission:r,canModify:s,t},ee.id))})})})]}),V.length>0&&a.jsxs("div",{children:[a.jsxs("div",{className:"flex items-center justify-between mb-4",children:[a.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[a.jsx(Nr,{className:"w-5 h-5 text-bambu-gray"}),t("queue.sections.history"),a.jsxs("span",{className:"text-sm font-normal text-bambu-gray",children:["(",t("queue.itemCount",{count:V.length}),")"]})]}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsxs("select",{className:"px-3 py-1.5 text-sm bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:P,onChange:ee=>T(ee.target.value),children:[a.jsx("option",{value:"date",children:t("queue.sort.byDate")}),a.jsx("option",{value:"name",children:t("queue.sort.byName")}),a.jsx("option",{value:"printer",children:t("queue.sort.byPrinter")})]}),a.jsx(ke,{variant:"ghost",size:"sm",onClick:()=>z(!j),title:t(j?"queue.sort.ascendingOldest":"queue.sort.descendingNewest"),className:"px-2",children:j?a.jsx(Zg,{className:"w-4 h-4"}):a.jsx(ay,{className:"w-4 h-4"})})]})]}),a.jsx("div",{className:"space-y-3",children:V.slice(0,20).map((ee,U)=>a.jsx(gP,{item:ee,position:U+1,onEdit:()=>{},onCancel:()=>{},onRemove:()=>N({type:"remove",item:ee}),onStop:()=>{},onRequeue:()=>y(ee),onStart:()=>{},timeFormat:G,hasPermission:r,canModify:s,t},ee.id))})]})]}),b&&a.jsx(Fu,{mode:"edit-queue-item",archiveId:b.archive_id??void 0,libraryFileId:b.library_file_id??void 0,archiveName:b.archive_name||b.library_file_name||`File #${b.archive_id||b.library_file_id}`,queueItem:b,onClose:()=>v(null)}),x&&a.jsx(Fu,{mode:"add-to-queue",archiveId:x.archive_id??void 0,libraryFileId:x.library_file_id??void 0,archiveName:x.archive_name||x.library_file_name||`File #${x.archive_id||x.library_file_id}`,onClose:()=>y(null)}),S&&a.jsx(er,{title:S.type==="cancel"?t("queue.confirm.cancelTitle"):S.type==="stop"?t("queue.confirm.stopTitle"):t("queue.confirm.removeTitle"),message:S.type==="cancel"?t("queue.confirm.cancelMessage",{name:S.item.archive_name||S.item.library_file_name||t("queue.confirm.thisPrint")}):S.type==="stop"?t("queue.confirm.stopMessage",{name:S.item.archive_name||S.item.library_file_name||t("queue.confirm.thisPrint")}):t("queue.confirm.removeMessage",{name:S.item.archive_name||S.item.library_file_name||t("queue.confirm.thisItem")}),confirmText:S.type==="cancel"?t("queue.confirm.cancelButton"):S.type==="stop"?t("queue.confirm.stopButton"):t("common.remove"),variant:"danger",onConfirm:()=>{S.type==="cancel"?K.mutate(S.item.id):S.type==="stop"?ie.mutate(S.item.id):ne.mutate(S.item.id),N(null)},onCancel:()=>N(null)}),m&&a.jsx(er,{title:t("queue.confirm.clearHistoryTitle"),message:t("queue.confirm.clearHistoryMessage",{count:V.length}),confirmText:t("queue.clearHistory"),variant:"danger",onConfirm:()=>{de.mutate(),p(!1)},onCancel:()=>p(!1)}),C&&a.jsx(EYe,{selectedCount:A.length,printers:H?.map(ee=>({id:ee.id,name:ee.name}))||[],onSave:ee=>{Object.keys(ee).length>0&&Ce.mutate({item_ids:A,...ee})},onClose:()=>E(!1),isSaving:Ce.isPending,t})]})}function TYe({printDates:t,months:e=3}){const n=_.useRef(null),[r,i]=_.useState(0);_.useEffect(()=>{const S=n.current;if(!S)return;const N=new ResizeObserver(A=>{const k=A[0]?.contentRect.width||0;i(k)});return N.observe(S),()=>N.disconnect()},[]);const{weeks:s,monthLabels:o,printCounts:l}=_.useMemo(()=>{const S={};t.forEach(z=>{const L=z.split("T")[0];S[L]=(S[L]||0)+1});const N=new Date,A=new Date(N);A.setMonth(A.getMonth()-e),A.setDate(A.getDate()-A.getDay());const k=[],C=[];let E=[],P=-1;const T=new Date(A);let j=0;for(;T<=N;)T.getDay()===0&&E.length>0&&(k.push(E),E=[],j++),T.getMonth()!==P&&(C.push({month:T.toLocaleDateString("en-US",{month:"short"}),weekIndex:j}),P=T.getMonth()),E.push(new Date(T)),T.setDate(T.getDate()+1);return E.length>0&&k.push(E),{weeks:k,monthLabels:C,printCounts:S}},[t,e]),c=Math.max(1,...Object.values(l)),u=S=>{if(S===0)return"bg-bambu-dark";const N=S/c;return N<=.25?"bg-bambu-green/30":N<=.5?"bg-bambu-green/50":N<=.75?"bg-bambu-green/75":"bg-bambu-green"},d=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],h=s.length,m=32,p=2,b=r-m-16,v=h>0?Math.floor((b-(h-1)*p)/h):12,x=Math.max(8,Math.min(20,v)),y=x<=10?10:12;return a.jsx("div",{ref:n,className:"w-full flex justify-center",children:r>0&&a.jsxs("div",{children:[a.jsx("div",{className:"flex mb-1",style:{marginLeft:m+4},children:o.map(({month:S,weekIndex:N},A)=>a.jsx("div",{className:"text-bambu-gray",style:{fontSize:y,marginLeft:A===0?0:`${(N-(o[A-1]?.weekIndex||0))*(x+p)-24}px`},children:S},A))}),a.jsxs("div",{className:"flex",style:{gap:p},children:[a.jsx("div",{className:"flex flex-col",style:{gap:p,marginRight:4,width:m},children:d.map((S,N)=>a.jsx("div",{className:"text-bambu-gray flex items-center",style:{width:m,height:x,fontSize:y,visibility:N%2===1?"visible":"hidden"},children:S},S))}),s.map((S,N)=>a.jsx("div",{className:"flex flex-col",style:{gap:p},children:[0,1,2,3,4,5,6].map(A=>{const k=S.find(T=>T.getDay()===A);if(!k)return a.jsx("div",{style:{width:x,height:x}},A);const C=k.toISOString().split("T")[0],E=l[C]||0,P=C===new Date().toISOString().split("T")[0];return a.jsx("div",{className:`rounded-sm ${u(E)} ${P?"ring-1 ring-white":""}`,style:{width:x,height:x},title:`${k.toLocaleDateString()}: ${E} print${E!==1?"s":""}`},A)})},N))]}),a.jsxs("div",{className:"flex items-center gap-2 mt-3 text-bambu-gray",style:{fontSize:y},children:[a.jsx("span",{children:"Less"}),a.jsxs("div",{className:"flex",style:{gap:p},children:[a.jsx("div",{className:"rounded-sm bg-bambu-dark",style:{width:x,height:x}}),a.jsx("div",{className:"rounded-sm bg-bambu-green/30",style:{width:x,height:x}}),a.jsx("div",{className:"rounded-sm bg-bambu-green/50",style:{width:x,height:x}}),a.jsx("div",{className:"rounded-sm bg-bambu-green/75",style:{width:x,height:x}}),a.jsx("div",{className:"rounded-sm bg-bambu-green",style:{width:x,height:x}})]}),a.jsx("span",{children:"More"})]})]})})}const E1=["#00ae42","#3b82f6","#f59e0b","#ef4444","#8b5cf6","#ec4899","#14b8a6","#f97316"];function CYe(t){const e=new Date;switch(t){case"7d":return new Date(e.getTime()-10080*60*1e3);case"30d":return new Date(e.getTime()-720*60*60*1e3);case"90d":return new Date(e.getTime()-2160*60*60*1e3);case"365d":return new Date(e.getTime()-365*24*60*60*1e3);case"all":return new Date(0)}}function jYe({archives:t,currency:e="$"}){const[n,r]=_.useState("30d"),i=_.useMemo(()=>{const p=CYe(n);return t.filter(b=>(Hi(b.completed_at||b.created_at)||new Date(0))>=p)},[t,n]),s=_.useMemo(()=>{const p=new Map;return i.forEach(b=>{const v=Hi(b.completed_at||b.created_at)||new Date,x=`${v.getFullYear()}-${String(v.getMonth()+1).padStart(2,"0")}-${String(v.getDate()).padStart(2,"0")}`,y=p.get(x)||{date:x,filament:0,cost:0,prints:0},S=b.quantity||1;y.filament+=(b.filament_used_grams||0)*S,y.cost+=b.cost||0,y.prints+=S,p.set(x,y)}),Array.from(p.values()).sort((b,v)=>b.date.localeCompare(v.date)).map(b=>({...b,dateLabel:new Date(b.date).toLocaleDateString("en-US",{month:"short",day:"numeric"})}))},[i]),o=_.useMemo(()=>{if(n==="7d"||n==="30d")return s;const p=new Map;return i.forEach(b=>{const v=Hi(b.completed_at||b.created_at)||new Date,x=new Date(v);x.setDate(v.getDate()-v.getDay());const y=`${x.getFullYear()}-${String(x.getMonth()+1).padStart(2,"0")}-${String(x.getDate()).padStart(2,"0")}`,S=p.get(y)||{week:y,filament:0,cost:0,prints:0},N=b.quantity||1;S.filament+=(b.filament_used_grams||0)*N,S.cost+=b.cost||0,S.prints+=N,p.set(y,S)}),Array.from(p.values()).sort((b,v)=>b.week.localeCompare(v.week)).map(b=>({date:b.week,dateLabel:`Week of ${new Date(b.week).toLocaleDateString("en-US",{month:"short",day:"numeric"})}`,...b}))},[i,s,n]),l=_.useMemo(()=>{const p=new Map;return i.forEach(b=>{const v=b.filament_type||"Unknown",x=b.quantity||1,y=v.split(", ");y.forEach(S=>{const N=(b.filament_used_grams||0)*x/y.length;p.set(S,(p.get(S)||0)+N)})}),Array.from(p.entries()).map(([b,v])=>({name:b,value:Math.round(v)})).sort((b,v)=>v.value-b.value)},[i]),c=_.useMemo(()=>{const p=new Date,b=[];for(let v=5;v>=0;v--){const x=new Date(p.getFullYear(),p.getMonth()-v,1),y=new Date(p.getFullYear(),p.getMonth()-v+1,0),S=x.toLocaleDateString("en-US",{month:"short",year:"2-digit"}),N=t.filter(A=>{const k=Hi(A.completed_at||A.created_at)||new Date(0);return k>=x&&k<=y});b.push({month:S,filament:Math.round(N.reduce((A,k)=>A+(k.filament_used_grams||0),0)),cost:N.reduce((A,k)=>A+(k.cost||0),0),prints:N.reduce((A,k)=>A+(k.quantity||1),0)})}return b},[t]),u=n==="7d"||n==="30d"?s:o,d=i.reduce((p,b)=>p+(b.filament_used_grams||0),0),h=i.reduce((p,b)=>p+(b.cost||0),0),m=i.reduce((p,b)=>p+(b.quantity||1),0);return a.jsxs("div",{className:"space-y-6",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("h3",{className:"text-lg font-semibold text-white",children:"Filament Usage Trends"}),a.jsx("div",{className:"flex gap-1 bg-bambu-dark rounded-lg p-1",children:["7d","30d","90d","365d","all"].map(p=>a.jsx("button",{onClick:()=>r(p),className:`px-3 py-1 text-sm rounded-md transition-colors ${n===p?"bg-bambu-green text-white":"text-bambu-gray hover:text-white"}`,children:p==="all"?"All":p.replace("d","D")},p))})]}),a.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[a.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[a.jsx("p",{className:"text-sm text-bambu-gray",children:"Period Filament"}),a.jsxs("p",{className:"text-2xl font-bold text-white",children:[(d/1e3).toFixed(2),"kg"]}),a.jsxs("p",{className:"text-xs text-bambu-gray",children:[d.toFixed(0),"g total"]})]}),a.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[a.jsx("p",{className:"text-sm text-bambu-gray",children:"Period Cost"}),a.jsxs("p",{className:"text-2xl font-bold text-white",children:[e,h.toFixed(2)]}),a.jsxs("p",{className:"text-xs text-bambu-gray",children:[m," prints"]})]}),a.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[a.jsx("p",{className:"text-sm text-bambu-gray",children:"Avg per Print"}),a.jsxs("p",{className:"text-2xl font-bold text-white",children:[m>0?(d/m).toFixed(0):0,"g"]}),a.jsxs("p",{className:"text-xs text-bambu-gray",children:[e,m>0?(h/m).toFixed(2):"0.00"," avg"]})]})]}),u.length>0?a.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[a.jsx("h4",{className:"text-sm font-medium text-bambu-gray mb-4",children:"Usage Over Time"}),a.jsx(W1,{width:"100%",height:250,children:a.jsxs(A6e,{data:u,children:[a.jsx("defs",{children:a.jsxs("linearGradient",{id:"colorFilament",x1:"0",y1:"0",x2:"0",y2:"1",children:[a.jsx("stop",{offset:"5%",stopColor:"#00ae42",stopOpacity:.3}),a.jsx("stop",{offset:"95%",stopColor:"#00ae42",stopOpacity:0})]})}),a.jsx(_N,{strokeDasharray:"3 3",stroke:"#3d3d3d"}),a.jsx(kN,{dataKey:"dateLabel",stroke:"#9ca3af",tick:{fontSize:12},interval:"preserveStartEnd"}),a.jsx(EN,{stroke:"#9ca3af",tick:{fontSize:12},tickFormatter:p=>`${p}g`}),a.jsx(X1,{contentStyle:{backgroundColor:"#2d2d2d",border:"1px solid #3d3d3d",borderRadius:"8px"},labelStyle:{color:"#fff"},formatter:p=>[`${Number(p??0).toFixed(0)}g`,"Filament"]}),a.jsx(fte,{type:"monotone",dataKey:"filament",stroke:"#00ae42",strokeWidth:2,fillOpacity:1,fill:"url(#colorFilament)"})]})})]}):a.jsx("div",{className:"bg-bambu-dark rounded-lg p-8 text-center text-bambu-gray",children:"No data for selected time range"}),a.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[a.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[a.jsx("h4",{className:"text-sm font-medium text-bambu-gray mb-4",children:"By Filament Type"}),l.length>0?a.jsxs("div",{className:"flex items-center gap-4",children:[a.jsx(W1,{width:160,height:160,children:a.jsxs(k6e,{children:[a.jsx(Uee,{data:l,cx:"50%",cy:"50%",innerRadius:40,outerRadius:70,paddingAngle:2,dataKey:"value",children:l.map((p,b)=>a.jsx(kv,{fill:E1[b%E1.length]},`cell-${b}`))}),a.jsx(X1,{contentStyle:{backgroundColor:"#2d2d2d",border:"1px solid #3d3d3d",borderRadius:"8px"},formatter:p=>[`${p??0}g`,"Usage"]})]})}),a.jsx("div",{className:"flex-1 space-y-2 overflow-hidden",children:l.map((p,b)=>{const v=l.reduce((y,S)=>y+S.value,0),x=v>0?(p.value/v*100).toFixed(0):0;return a.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[a.jsx("div",{className:"w-3 h-3 rounded-sm flex-shrink-0",style:{backgroundColor:E1[b%E1.length]}}),a.jsx("span",{className:"text-white truncate flex-1",children:p.name}),a.jsxs("span",{className:"text-bambu-gray flex-shrink-0",children:[x,"%"]})]},p.name)})})]}):a.jsx("div",{className:"h-[160px] flex items-center justify-center text-bambu-gray",children:"No filament data"})]}),a.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[a.jsx("h4",{className:"text-sm font-medium text-bambu-gray mb-4",children:"Monthly Comparison"}),a.jsx(W1,{width:"100%",height:200,children:a.jsxs(m6e,{data:c,children:[a.jsx(_N,{strokeDasharray:"3 3",stroke:"#3d3d3d"}),a.jsx(kN,{dataKey:"month",stroke:"#9ca3af",tick:{fontSize:12}}),a.jsx(EN,{stroke:"#9ca3af",tick:{fontSize:12},tickFormatter:p=>`${p}g`}),a.jsx(X1,{contentStyle:{backgroundColor:"#2d2d2d",border:"1px solid #3d3d3d",borderRadius:"8px"},formatter:(p,b)=>[b==="filament"?`${p??0}g`:b==="cost"?`${e}${Number(p??0).toFixed(2)}`:p??0,b==="filament"?"Filament":b==="cost"?"Cost":"Prints"]}),a.jsx(b4,{}),a.jsx(xte,{dataKey:"filament",name:"Filament (g)",fill:"#00ae42",radius:[4,4,0,0]})]})})]})]})]})}function PYe({id:t,title:e,component:n,isHidden:r,size:i,onToggleVisibility:s,onToggleSize:o}){const{attributes:l,listeners:c,setNodeRef:u,transform:d,transition:h,isDragging:m}=aae({id:t}),p={transform:Eb.Transform.toString(d),transition:h,opacity:m?.5:1};return r?null:a.jsxs("div",{ref:u,style:{...p,gridColumn:`span ${i}`},className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary overflow-hidden ${m?"ring-2 ring-bambu-green shadow-lg":""}`,children:[a.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-bambu-dark-tertiary bg-bambu-dark/30",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("button",{...l,...c,className:"cursor-grab active:cursor-grabbing p-1 hover:bg-bambu-dark-tertiary rounded transition-colors",title:"Drag to reorder",children:a.jsx(eb,{className:"w-6 h-6 md:w-4 md:h-4 text-bambu-gray"})}),a.jsx("h3",{className:"text-sm font-medium text-white",children:e})]}),a.jsxs("div",{className:"flex items-center gap-1",children:[a.jsx("button",{onClick:o,className:"p-1 hover:bg-bambu-dark-tertiary rounded transition-colors",title:`Size: ${i===1?"1/4":i===2?"1/2":"Full"} - Click to cycle`,children:i===4?a.jsx(lO,{className:"w-4 h-4 text-bambu-gray hover:text-white"}):a.jsx(oO,{className:"w-4 h-4 text-bambu-gray hover:text-white"})}),a.jsx("button",{onClick:s,className:"p-1 hover:bg-bambu-dark-tertiary rounded transition-colors",title:"Hide widget",children:a.jsx(RM,{className:"w-4 h-4 text-bambu-gray hover:text-white"})})]})]}),a.jsx("div",{className:"p-4",children:typeof n=="function"?n(i):n})]})}function DYe({widgets:t,storageKey:e,columns:n=4,hideControls:r=!1,onResetLayout:i,renderControls:s}){const o=()=>{const A={};return t.forEach(k=>{A[k.id]=k.defaultSize||4}),A},[l,c]=_.useState(()=>{const A=localStorage.getItem(e);if(A)try{const k=JSON.parse(A);return k.sizes||(k.sizes=o()),k}catch{}return{order:t.map(k=>k.id),hidden:t.filter(k=>k.defaultVisible===!1).map(k=>k.id),sizes:o()}}),[u,d]=_.useState(!1);_.useEffect(()=>{const A=()=>d(k=>!k);return window.addEventListener("toggle-hidden-panel",A),()=>window.removeEventListener("toggle-hidden-panel",A)},[]),_.useEffect(()=>{localStorage.setItem(e,JSON.stringify(l))},[l,e]),_.useEffect(()=>{const k=t.map(C=>C.id).filter(C=>!l.order.includes(C));k.length>0&&c(C=>({...C,order:[...C.order,...k]}))},[t,l.order]);const h=Fie(NM(pk,{activationConstraint:{distance:8}}),NM(mk,{coordinateGetter:sae})),m=A=>{const{active:k,over:C}=A;C&&k.id!==C.id&&c(E=>{const P=E.order.indexOf(k.id),T=E.order.indexOf(C.id);return{...E,order:xk(E.order,P,T)}})},p=A=>{c(k=>({...k,hidden:k.hidden.includes(A)?k.hidden.filter(C=>C!==A):[...k.hidden,A]}))},b=A=>{c(k=>{const C=k.sizes[A]||4,E=C===1?2:C===2?4:1;return{...k,sizes:{...k.sizes,[A]:E}}})},v=()=>{const A={order:t.map(k=>k.id),hidden:t.filter(k=>k.defaultVisible===!1).map(k=>k.id),sizes:o()};c(A),i?.()},x=l.order.map(A=>t.find(k=>k.id===A)).filter(Boolean),y=x.filter(A=>!l.hidden.includes(A.id)),S=x.filter(A=>l.hidden.includes(A.id)),N=s?.({hiddenCount:S.length,showHiddenPanel:u,setShowHiddenPanel:d,resetLayout:v});return a.jsxs("div",{className:"space-y-4",children:[N,!r&&!s&&a.jsxs("div",{className:"flex items-center justify-end gap-2",children:[a.jsxs(ke,{variant:"secondary",size:"sm",onClick:v,children:[a.jsx($h,{className:"w-4 h-4"}),"Reset Layout"]}),S.length>0&&a.jsxs(ke,{variant:"secondary",size:"sm",onClick:()=>d(!u),children:[a.jsx(_c,{className:"w-4 h-4"}),S.length," Hidden"]})]}),u&&S.length>0&&a.jsxs("div",{className:"p-4 bg-bambu-dark rounded-xl border border-bambu-dark-tertiary",children:[a.jsx("p",{className:"text-sm text-bambu-gray mb-3",children:"Hidden widgets (click to show):"}),a.jsx("div",{className:"flex flex-wrap gap-2",children:S.map(A=>a.jsxs("button",{onClick:()=>p(A.id),className:"px-3 py-1.5 bg-bambu-dark-tertiary hover:bg-bambu-green/20 rounded-lg text-sm text-white transition-colors flex items-center gap-2",children:[a.jsx(_c,{className:"w-3 h-3"}),A.title]},A.id))})]}),a.jsx(eae,{sensors:h,collisionDetection:Bie,onDragEnd:m,children:a.jsx(rae,{items:y.map(A=>A.id),strategy:BF,children:a.jsx("div",{className:"grid gap-6",style:{gridTemplateColumns:`repeat(${n}, minmax(0, 1fr))`},children:y.map(A=>a.jsx(PYe,{id:A.id,title:A.title,component:A.component,isHidden:l.hidden.includes(A.id),size:l.sizes[A.id]||2,onToggleVisibility:()=>p(A.id),onToggleSize:()=>b(A.id)},A.id))})})}),y.length===0&&a.jsxs("div",{className:"text-center py-12 text-bambu-gray",children:[a.jsx("p",{children:"All widgets are hidden."}),a.jsx(ke,{className:"mt-4",onClick:v,children:"Reset Layout"})]})]})}function RYe({stats:t,currency:e,t:n}){return a.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-4",children:[a.jsxs("div",{className:"flex items-start gap-3",children:[a.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-bambu-green",children:a.jsx(Sc,{className:"w-5 h-5"})}),a.jsxs("div",{children:[a.jsx("p",{className:"text-xs text-bambu-gray",children:n("stats.totalPrints")}),a.jsx("p",{className:"text-xl font-bold text-white",children:t?.total_prints||0})]})]}),a.jsxs("div",{className:"flex items-start gap-3",children:[a.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-blue-400",children:a.jsx(nr,{className:"w-5 h-5"})}),a.jsxs("div",{children:[a.jsx("p",{className:"text-xs text-bambu-gray",children:n("stats.printTime")}),a.jsxs("p",{className:"text-xl font-bold text-white",children:[t?.total_print_time_hours.toFixed(1)||0,"h"]})]})]}),a.jsxs("div",{className:"flex items-start gap-3",children:[a.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-orange-400",children:a.jsx(Sc,{className:"w-5 h-5"})}),a.jsxs("div",{children:[a.jsx("p",{className:"text-xs text-bambu-gray",children:n("stats.filamentUsed")}),a.jsxs("p",{className:"text-xl font-bold text-white",children:[((t?.total_filament_grams||0)/1e3).toFixed(2),"kg"]})]})]}),a.jsxs("div",{className:"flex items-start gap-3",children:[a.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-green-400",children:a.jsx(zP,{className:"w-5 h-5"})}),a.jsxs("div",{children:[a.jsx("p",{className:"text-xs text-bambu-gray",children:n("stats.filamentCost")}),a.jsxs("p",{className:"text-xl font-bold text-white",children:[e," ",t?.total_cost.toFixed(2)||"0.00"]})]})]}),a.jsxs("div",{className:"flex items-start gap-3",children:[a.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-yellow-400",children:a.jsx(Dh,{className:"w-5 h-5"})}),a.jsxs("div",{children:[a.jsx("p",{className:"text-xs text-bambu-gray",children:n("stats.energyUsed")}),a.jsxs("p",{className:"text-xl font-bold text-white",children:[t?.total_energy_kwh.toFixed(2)||"0.00"," kWh"]})]})]}),a.jsxs("div",{className:"flex items-start gap-3",children:[a.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-yellow-500",children:a.jsx(zP,{className:"w-5 h-5"})}),a.jsxs("div",{children:[a.jsx("p",{className:"text-xs text-bambu-gray",children:n("stats.energyCost")}),a.jsxs("p",{className:"text-xl font-bold text-white",children:[e," ",t?.total_energy_cost.toFixed(2)||"0.00"]})]})]})]})}function OYe({stats:t,printerMap:e,size:n=1,t:r}){const i=t?.total_prints?Math.round(t.successful_prints/t.total_prints*100):0,s=n===1?112:n===2?128:144,o=s/2-8,l=o*2*Math.PI;return a.jsxs("div",{className:"flex items-center gap-6",children:[a.jsxs("div",{className:"relative flex-shrink-0",style:{width:s,height:s},children:[a.jsxs("svg",{className:"w-full h-full -rotate-90",children:[a.jsx("circle",{cx:s/2,cy:s/2,r:o,fill:"none",stroke:"#3d3d3d",strokeWidth:"10"}),a.jsx("circle",{cx:s/2,cy:s/2,r:o,fill:"none",stroke:"#00ae42",strokeWidth:"10",strokeLinecap:"round",strokeDasharray:`${i/100*l} ${l}`})]}),a.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:a.jsxs("span",{className:`font-bold text-white ${n>=2?"text-2xl":"text-xl"}`,children:[i,"%"]})})]}),a.jsxs("div",{className:"flex-1 min-w-0",children:[a.jsxs("div",{className:"space-y-2",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(Nr,{className:"w-4 h-4 text-status-ok flex-shrink-0"}),a.jsx("span",{className:"text-sm text-bambu-gray",children:r("stats.successful")}),a.jsx("span",{className:"text-sm text-white font-medium",children:t?.successful_prints||0})]}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(ta,{className:"w-4 h-4 text-status-error flex-shrink-0"}),a.jsx("span",{className:"text-sm text-bambu-gray",children:r("stats.failed")}),a.jsx("span",{className:"text-sm text-white font-medium",children:t?.failed_prints||0})]})]}),n>=2&&t?.prints_by_printer&&Object.keys(t.prints_by_printer).length>0&&a.jsxs("div",{className:"mt-4 pt-4 border-t border-bambu-dark-tertiary",children:[a.jsx("p",{className:"text-xs text-bambu-gray font-medium mb-2",children:r("stats.printsByPrinter")}),a.jsx("div",{className:`grid gap-x-6 gap-y-1 ${n===4?"grid-cols-3":"grid-cols-2"}`,style:{width:"fit-content"},children:Object.entries(t.prints_by_printer).map(([c,u])=>a.jsxs("div",{className:"flex items-center gap-3 text-sm",children:[a.jsx("span",{className:"text-bambu-gray truncate max-w-[120px]",children:e.get(c)||`${r("common.printer")} ${c}`}),a.jsx("span",{className:"text-white font-medium",children:u})]},c))})]})]})]})}function LYe({stats:t,printerMap:e,size:n=1,t:r}){const i=t?.average_time_accuracy;if(i==null)return a.jsx("div",{className:"flex items-center justify-center h-full",children:a.jsx("p",{className:"text-bambu-gray text-center py-4",children:r("stats.noTimeAccuracyData")})});const o=(Math.min(150,Math.max(50,i))-50)/100*100,c=(v=>v>=95&&v<=105?"#00ae42":v>105?"#3b82f6":"#f97316")(i),u=i-100,d=n===1?112:n===2?128:144,h=d/2-8,m=h*2*Math.PI,p=n===1?3:n===2?6:999,b=t?.time_accuracy_by_printer?Object.entries(t.time_accuracy_by_printer).slice(0,p):[];return a.jsxs("div",{className:"flex items-center gap-6",children:[a.jsxs("div",{className:"relative flex-shrink-0",style:{width:d,height:d},children:[a.jsxs("svg",{className:"w-full h-full -rotate-90",children:[a.jsx("circle",{cx:d/2,cy:d/2,r:h,fill:"none",stroke:"#3d3d3d",strokeWidth:"10"}),a.jsx("circle",{cx:d/2,cy:d/2,r:h,fill:"none",stroke:c,strokeWidth:"10",strokeLinecap:"round",strokeDasharray:`${o/100*m} ${m}`})]}),a.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center",children:[a.jsxs("span",{className:`font-bold text-white ${n>=2?"text-2xl":"text-xl"}`,children:[i.toFixed(0),"%"]}),a.jsxs("span",{className:`text-xs ${u>=0?"text-blue-400":"text-orange-400"}`,children:[u>=0?"+":"",u.toFixed(0),"%"]})]})]}),a.jsxs("div",{className:"flex-1 min-w-0",children:[a.jsxs("div",{className:"flex items-center gap-2 text-xs text-bambu-gray",children:[a.jsx($K,{className:"w-3 h-3 flex-shrink-0"}),a.jsx("span",{children:r("stats.perfectEstimate")})]}),b.length>0&&a.jsx("div",{className:`mt-2 ${n===4?"grid grid-cols-3 gap-x-6 gap-y-1":n===2?"grid grid-cols-2 gap-x-6 gap-y-1":"space-y-1"}`,style:{width:"fit-content"},children:b.map(([v,x])=>a.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[a.jsx("span",{className:"text-bambu-gray truncate max-w-[100px]",children:e.get(v)||`${r("common.printer")} ${v}`}),a.jsxs("span",{className:`font-medium ${x>=95&&x<=105?"text-status-ok":x>105?"text-blue-400":"text-status-warning"}`,children:[x.toFixed(0),"%"]})]},v))})]})]})}function FYe({stats:t,size:e=1,t:n}){if(!t?.prints_by_filament_type||Object.keys(t.prints_by_filament_type).length===0)return a.jsx("p",{className:"text-bambu-gray text-center py-4",children:n("stats.noFilamentData")});const r=Object.entries(t.prints_by_filament_type).sort(([,l],[,c])=>c-l),i=e===1?5:e===2?8:999,s=r.slice(0,i),o=r.length>i;return e===4&&s.length>4?a.jsx("div",{className:"grid grid-cols-2 lg:grid-cols-3 gap-4",children:s.map(([l,c])=>{const u=Math.round(c/(t.total_prints||1)*100);return a.jsxs("div",{children:[a.jsxs("div",{className:"flex justify-between text-sm mb-1",children:[a.jsx("span",{className:"text-white truncate max-w-[120px]",children:l}),a.jsx("span",{className:"text-bambu-gray",children:c})]}),a.jsx("div",{className:"h-2 bg-bambu-dark rounded-full",children:a.jsx("div",{className:"h-full bg-bambu-green rounded-full transition-all",style:{width:`${u}%`}})})]},l)})}):a.jsxs("div",{className:"space-y-3",children:[s.map(([l,c])=>{const u=Math.round(c/(t.total_prints||1)*100);return a.jsxs("div",{children:[a.jsxs("div",{className:"flex justify-between text-sm mb-1",children:[a.jsx("span",{className:"text-white",children:l}),a.jsxs("span",{className:"text-bambu-gray",children:[c," ",n("common.prints")]})]}),a.jsx("div",{className:"h-2 bg-bambu-dark rounded-full",children:a.jsx("div",{className:"h-full bg-bambu-green rounded-full transition-all",style:{width:`${u}%`}})})]},l)}),o&&a.jsx("p",{className:"text-xs text-bambu-gray text-center pt-1",children:n("common.more",{count:r.length-i})})]})}function IYe({printDates:t,size:e=2}){const n=e===1?3:e===2?6:12;return a.jsx(TYe,{printDates:t,months:n})}function UYe({stats:t,printerMap:e,t:n}){return!t?.prints_by_printer||Object.keys(t.prints_by_printer).length===0?a.jsx("p",{className:"text-bambu-gray text-center py-4",children:n("stats.noPrinterData")}):a.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:Object.entries(t.prints_by_printer).map(([r,i])=>a.jsxs("div",{className:"flex items-center gap-3 p-3 bg-bambu-dark rounded-lg",children:[a.jsx("div",{className:"p-2 bg-bambu-dark-tertiary rounded-lg",children:a.jsx(Or,{className:"w-4 h-4 text-bambu-green"})}),a.jsxs("div",{children:[a.jsx("p",{className:"text-white font-medium text-sm",children:e.get(r)||`${n("common.printer")} ${r}`}),a.jsxs("p",{className:"text-xs text-bambu-gray",children:[i," ",n("common.prints")]})]})]},r))})}function zYe({archives:t,currency:e,t:n}){return!t||t.length===0?a.jsx("p",{className:"text-bambu-gray text-center py-4",children:n("stats.noPrintData")}):a.jsx(jYe,{archives:t,currency:e})}function BYe({size:t=1,t:e}){const{data:n,isLoading:r}=st({queryKey:["failureAnalysis"],queryFn:()=>ce.getFailureAnalysis({days:30})});if(r)return a.jsx("div",{className:"flex justify-center py-4",children:a.jsx(ut,{className:"w-6 h-6 text-bambu-green animate-spin"})});if(!n||n.total_prints===0)return a.jsx("p",{className:"text-bambu-gray text-center py-4",children:e("stats.noPrintDataLast30Days")});const i=t===1?5:t===2?8:999,s=Object.entries(n.failures_by_reason).sort(([,c],[,u])=>u-c),o=s.slice(0,i),l=s.length>i;return a.jsxs("div",{className:`${t>=2?"flex gap-8":"space-y-4"}`,children:[a.jsxs("div",{className:t>=2?"flex-shrink-0":"",children:[a.jsx("div",{className:"flex items-center gap-4",children:a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(kn,{className:`w-5 h-5 ${n.failure_rate>20?"text-status-error":n.failure_rate>10?"text-status-warning":"text-status-ok"}`}),a.jsxs("span",{className:`font-bold text-white ${t>=2?"text-3xl":"text-2xl"}`,children:[n.failure_rate.toFixed(1),"%"]})]})}),a.jsx("div",{className:"text-sm text-bambu-gray mt-1",children:e("stats.failedPrintsCount",{failed:n.failed_prints,total:n.total_prints})}),n.trend&&n.trend.length>=2&&a.jsx("div",{className:`${t>=2?"mt-4":"mt-2 pt-2 border-t border-bambu-dark-tertiary"}`,children:a.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[a.jsx(GK,{className:`w-4 h-4 ${n.trend[n.trend.length-1].failure_rate0&&a.jsxs("div",{className:`flex-1 ${t>=2?"border-l border-bambu-dark-tertiary pl-8":"pt-2"}`,children:[a.jsx("p",{className:"text-xs text-bambu-gray font-medium mb-2",children:t>=2?e("stats.failureReasons"):e("stats.topFailureReasons")}),a.jsx("div",{className:`${t===4?"grid grid-cols-2 gap-x-6 gap-y-1":"space-y-1"}`,children:o.map(([c,u])=>a.jsxs("div",{className:"flex items-center justify-between text-sm",children:[a.jsx("span",{className:`text-white truncate ${t===4?"max-w-[200px]":"max-w-[160px]"}`,children:c||e("common.unknown")}),a.jsx("span",{className:"text-bambu-gray ml-2",children:u})]},c))}),l&&a.jsx("p",{className:"text-xs text-bambu-gray mt-2",children:e("common.more",{count:s.length-i})})]})]})}function HYe(){const{t}=Sn(),{showToast:e}=Hn(),{hasPermission:n}=Di(),[r,i]=_.useState(!1),[s,o]=_.useState(!1),[l,c]=_.useState(0),[u,d]=_.useState(0),[h,m]=_.useState(!1);_.useEffect(()=>{const T=()=>{try{const z=localStorage.getItem("bambusy-dashboard-layout");if(z){const L=JSON.parse(z);d(L.hidden?.length||0)}}catch{d(0)}};T(),window.addEventListener("storage",T);const j=setInterval(T,500);return()=>{window.removeEventListener("storage",T),clearInterval(j)}},[l]);const{data:p,isLoading:b,refetch:v}=st({queryKey:["archiveStats"],queryFn:ce.getArchiveStats}),{data:x}=st({queryKey:["printers"],queryFn:ce.getPrinters}),{data:y}=st({queryKey:["archives"],queryFn:()=>ce.getArchives(void 0,void 0,1e3,0)}),{data:S}=st({queryKey:["settings"],queryFn:ce.getSettings}),N=async T=>{o(!1),i(!0);try{const{blob:j,filename:z}=await ce.exportStats({format:T,days:90}),L=URL.createObjectURL(j),B=document.createElement("a");B.href=L,B.download=z,B.click(),URL.revokeObjectURL(L),e(t("stats.exportDownloaded"))}catch{e(t("stats.exportFailed"),"error")}finally{i(!1)}},A=async()=>{m(!0);try{const T=await ce.recalculateCosts();await v(),e(t("stats.recalculatedCosts",{count:T.updated}))}catch{e(t("stats.recalculateFailed"),"error")}finally{m(!1)}},k=S?.currency||"$",C=new Map(x?.map(T=>[String(T.id),T.name])||[]),E=y?.map(T=>T.created_at)||[];if(b)return a.jsx("div",{className:"p-4 md:p-8",children:a.jsx("div",{className:"text-center py-12 text-bambu-gray",children:t("stats.loadingStats")})});const P=[{id:"quick-stats",title:t("stats.quickStats"),component:a.jsx(RYe,{stats:p,currency:k,t}),defaultSize:2},{id:"success-rate",title:t("stats.successRate"),component:T=>a.jsx(OYe,{stats:p,printerMap:C,size:T,t}),defaultSize:1},{id:"time-accuracy",title:t("stats.timeAccuracy"),component:T=>a.jsx(LYe,{stats:p,printerMap:C,size:T,t}),defaultSize:1},{id:"filament-types",title:t("stats.filamentTypes"),component:T=>a.jsx(FYe,{stats:p,size:T,t}),defaultSize:1},{id:"failure-analysis",title:t("stats.failureAnalysis"),component:T=>a.jsx(BYe,{size:T,t}),defaultSize:1},{id:"print-activity",title:t("stats.printActivity"),component:T=>a.jsx(IYe,{printDates:E,size:T}),defaultSize:2},{id:"prints-by-printer",title:t("stats.printsByPrinter"),component:a.jsx(UYe,{stats:p,printerMap:C,t}),defaultSize:2},{id:"filament-trends",title:t("stats.filamentTrends"),component:a.jsx(zYe,{archives:y||[],currency:k,t}),defaultSize:4}];return a.jsxs("div",{className:"p-4 md:p-8",children:[a.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4 mb-6",children:[a.jsxs("div",{children:[a.jsx("h1",{className:"text-2xl font-bold text-white",children:t("stats.title")}),a.jsx("p",{className:"text-bambu-gray",children:t("stats.subtitle")})]}),a.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[u>0&&a.jsxs(ke,{variant:"secondary",onClick:()=>{window.dispatchEvent(new CustomEvent("toggle-hidden-panel"))},children:[a.jsx(_c,{className:"w-4 h-4"}),t("stats.hiddenCount",{count:u})]}),a.jsxs(ke,{variant:"secondary",onClick:()=>{localStorage.removeItem("bambusy-dashboard-layout"),c(T=>T+1),e(t("stats.layoutReset"))},disabled:!n("settings:update"),title:n("settings:update")?void 0:t("stats.noPermissionResetLayout"),children:[a.jsx($h,{className:"w-4 h-4"}),t("stats.resetLayout")]}),a.jsxs(ke,{variant:"secondary",onClick:A,disabled:h||!n("archives:update_all"),title:n("archives:update_all")?t("stats.recalculateCostsHint"):t("stats.noPermissionRecalculate"),children:[h?a.jsx(ut,{className:"w-4 h-4 animate-spin"}):a.jsx(rde,{className:"w-4 h-4"}),t("stats.recalculateCosts")]}),a.jsxs("div",{className:"relative",children:[a.jsxs(ke,{variant:"secondary",onClick:()=>o(!s),disabled:r,children:[r?a.jsx(ut,{className:"w-4 h-4 animate-spin"}):a.jsx(dS,{className:"w-4 h-4"}),t("stats.exportStats")]}),s&&a.jsxs("div",{className:"absolute right-0 top-full mt-1 w-48 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-20",children:[a.jsxs("button",{className:"w-full px-4 py-2 text-left text-white hover:bg-bambu-dark-tertiary transition-colors flex items-center gap-2 rounded-t-lg",onClick:()=>N("csv"),children:[a.jsx(ps,{className:"w-4 h-4"}),t("stats.exportAsCsv")]}),a.jsxs("button",{className:"w-full px-4 py-2 text-left text-white hover:bg-bambu-dark-tertiary transition-colors flex items-center gap-2 rounded-b-lg",onClick:()=>N("xlsx"),children:[a.jsx(dS,{className:"w-4 h-4"}),t("stats.exportAsExcel")]})]})]})]})]}),a.jsx(DYe,{widgets:P,storageKey:"bambusy-dashboard-layout",hideControls:!0},l)]})}function $Ye({plug:t,onEdit:e}){const n=un(),{showToast:r}=Hn(),[i,s]=_.useState(!1),[o,l]=_.useState(!1),[c,u]=_.useState(!1),[d,h]=_.useState(!1),{data:m,isLoading:p}=st({queryKey:["smart-plug-status",t.id],queryFn:()=>ce.getSmartPlugStatus(t.id),refetchInterval:3e4}),{data:b}=st({queryKey:["printers"],queryFn:ce.getPrinters}),v=b?.find(T=>T.id===t.printer_id),x=pt({mutationFn:T=>ce.controlSmartPlug(t.id,T),onMutate:async T=>{await n.cancelQueries({queryKey:["smart-plug-status",t.id]});const j=n.getQueryData(["smart-plug-status",t.id]),z=T==="on"?"ON":T==="off"||m?.state==="ON"?"OFF":"ON";return n.setQueryData(["smart-plug-status",t.id],L=>({...L,state:z})),{previousStatus:j}},onError:(T,j,z)=>{z?.previousStatus&&n.setQueryData(["smart-plug-status",t.id],z.previousStatus),r(`Failed to turn ${j} "${t.name}"`,"error")},onSettled:()=>{setTimeout(()=>{n.invalidateQueries({queryKey:["smart-plug-status",t.id]}),n.invalidateQueries({queryKey:["smart-plugs"]})},1e3)}}),y=pt({mutationFn:T=>ce.updateSmartPlug(t.id,T),onSuccess:()=>{n.invalidateQueries({queryKey:["smart-plugs"]}),t.printer_id&&(n.invalidateQueries({queryKey:["smartPlugByPrinter",t.printer_id]}),n.invalidateQueries({queryKey:["scriptPlugsByPrinter",t.printer_id]}))}}),S=pt({mutationFn:()=>ce.deleteSmartPlug(t.id),onSuccess:()=>{n.invalidateQueries({queryKey:["smart-plugs"]}),t.printer_id&&n.invalidateQueries({queryKey:["scriptPlugsByPrinter",t.printer_id]})}}),N=m?.state==="ON",A=t.plug_type==="mqtt"&&m?.energy?.power!==null&&m?.energy?.power!==void 0,k=(m?.reachable??!1)||A,C=x.isPending,P=(()=>{if(t.plug_type!=="tasmota"||!t.ip_address)return null;const T=t.ip_address;return t.username&&t.password?`http://${encodeURIComponent(t.username)}:${encodeURIComponent(t.password)}@${T}/`:`http://${T}/`})();return a.jsxs(a.Fragment,{children:[a.jsx(_t,{className:"relative",children:a.jsxs(Mt,{className:"p-4",children:[a.jsxs("div",{className:"flex items-start justify-between gap-2 mb-3",children:[a.jsxs("div",{className:"flex items-center gap-3 min-w-0 flex-1",children:[a.jsx("div",{className:`p-2 rounded-lg flex-shrink-0 ${t.plug_type==="mqtt"?k?"bg-teal-500/20":"bg-red-500/20":k?N?"bg-bambu-green/20":"bg-bambu-dark":"bg-red-500/20"}`,children:t.plug_type==="mqtt"?a.jsx(cO,{className:`w-5 h-5 ${k?"text-teal-400":"text-red-400"}`}):t.plug_type==="homeassistant"?a.jsx(Jy,{className:`w-5 h-5 ${k?N?"text-bambu-green":"text-bambu-gray":"text-red-400"}`}):a.jsx(rl,{className:`w-5 h-5 ${k?N?"text-bambu-green":"text-bambu-gray":"text-red-400"}`})}),a.jsxs("div",{className:"min-w-0",children:[a.jsx("h3",{className:"font-medium text-white truncate",children:t.name}),a.jsx("p",{className:"text-sm text-bambu-gray truncate",title:t.plug_type==="mqtt"?t.mqtt_topic??void 0:t.plug_type==="homeassistant"?t.ha_entity_id??void 0:t.ip_address??void 0,children:t.plug_type==="mqtt"?t.mqtt_topic:t.plug_type==="homeassistant"?t.ha_entity_id:t.ip_address})]})]}),a.jsxs("div",{className:"flex flex-col items-end gap-1 flex-shrink-0",children:[p?a.jsx(ut,{className:"w-4 h-4 text-bambu-gray animate-spin"}):t.plug_type==="mqtt"?a.jsxs("div",{className:"flex items-center gap-1.5 text-sm whitespace-nowrap",children:[a.jsx("span",{className:"px-1.5 py-0.5 bg-teal-500/20 text-teal-400 text-[10px] font-medium rounded flex-shrink-0",children:"MQTT"}),k&&a.jsx("span",{className:"text-status-ok",children:"✓"})]}):t.plug_type==="homeassistant"?a.jsxs("div",{className:"flex items-center gap-1 text-sm",children:[a.jsx("span",{className:"px-1 py-0.5 bg-blue-500/20 text-blue-400 text-[10px] font-medium rounded",children:"HA"}),a.jsx("span",{className:k?N?"text-status-ok":"text-bambu-gray":"text-status-error",children:k?m?.state||"?":"Offline"})]}):k?a.jsxs("div",{className:"flex items-center gap-1 text-sm",children:[a.jsx(Fg,{className:"w-4 h-4 text-status-ok"}),a.jsx("span",{className:N?"text-status-ok":"text-bambu-gray",children:m?.state||"Unknown"})]}):a.jsxs("div",{className:"flex items-center gap-1 text-sm text-status-error",children:[a.jsx(_m,{className:"w-4 h-4"}),a.jsx("span",{children:"Offline"})]}),P&&a.jsxs("a",{href:P,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1 px-2 py-0.5 bg-bambu-dark hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white text-xs rounded-full transition-colors",title:"Open plug admin page",children:[a.jsx(Xr,{className:"w-3 h-3"}),"Admin"]})]})]}),v&&a.jsxs("div",{className:"mb-3 px-2 py-1.5 bg-bambu-dark rounded-lg",children:[a.jsx("span",{className:"text-xs text-bambu-gray",children:"Linked to: "}),a.jsx("span",{className:"text-sm text-white",children:v.name})]}),(t.power_alert_enabled||t.schedule_enabled||t.plug_type==="mqtt")&&a.jsxs("div",{className:"flex flex-wrap gap-1.5 mb-3",children:[t.plug_type==="mqtt"&&a.jsxs("span",{className:"flex items-center gap-1 px-2 py-0.5 bg-teal-500/20 text-teal-400 text-xs rounded-full",children:[a.jsx(_c,{className:"w-3 h-3"}),"Monitor Only"]}),t.power_alert_enabled&&a.jsxs("span",{className:"flex items-center gap-1 px-2 py-0.5 bg-yellow-500/20 text-yellow-400 text-xs rounded-full",children:[a.jsx(Og,{className:"w-3 h-3"}),"Alerts"]}),t.schedule_enabled&&a.jsxs("span",{className:"flex items-center gap-1 px-2 py-0.5 bg-blue-500/20 text-blue-400 text-xs rounded-full",children:[a.jsx(ei,{className:"w-3 h-3"}),t.schedule_on_time&&t.schedule_off_time?`${t.schedule_on_time} - ${t.schedule_off_time}`:t.schedule_on_time?`On ${t.schedule_on_time}`:`Off ${t.schedule_off_time}`]})]}),t.plug_type!=="mqtt"&&a.jsxs("div",{className:"flex gap-2 mb-3",children:[a.jsxs(ke,{size:"sm",variant:N?"primary":"secondary",disabled:!k||C,onClick:()=>l(!0),className:"flex-1",children:[C?a.jsx(ut,{className:"w-4 h-4 animate-spin"}):a.jsx(Zu,{className:"w-4 h-4"}),"On"]}),a.jsxs(ke,{size:"sm",variant:N?"secondary":"primary",disabled:!k||C,onClick:()=>u(!0),className:"flex-1",children:[C?a.jsx(ut,{className:"w-4 h-4 animate-spin"}):a.jsx(HM,{className:"w-4 h-4"}),"Off"]})]}),t.plug_type==="mqtt"&&m?.energy&&a.jsxs("div",{className:"flex gap-2 mb-3 px-3 py-2 bg-bambu-dark rounded-lg",children:[m.energy.power!==null&&m.energy.power!==void 0&&a.jsxs("div",{className:"flex-1 text-center",children:[a.jsxs("p",{className:"text-lg font-semibold text-white",children:[Math.round(m.energy.power),"W"]}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Power"})]}),m.energy.today!==null&&m.energy.today!==void 0&&a.jsxs("div",{className:"flex-1 text-center border-l border-bambu-dark-tertiary",children:[a.jsx("p",{className:"text-lg font-semibold text-white",children:m.energy.today.toFixed(2)}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"kWh Today"})]})]}),a.jsxs("button",{onClick:()=>h(!d),className:"w-full flex items-center justify-between py-2 text-sm text-bambu-gray hover:text-white transition-colors",children:[a.jsxs("span",{className:"flex items-center gap-2",children:[a.jsx(jh,{className:"w-4 h-4"}),t.plug_type==="mqtt"?"Settings":"Automation Settings"]}),a.jsx("span",{children:d?"-":"+"})]}),d&&a.jsxs("div",{className:"pt-3 border-t border-bambu-dark-tertiary space-y-4",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(UM,{className:"w-4 h-4 text-bambu-green"}),a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"Show in Switchbar"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Quick access from sidebar"})]})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:t.show_in_switchbar,onChange:T=>y.mutate({show_in_switchbar:T.target.checked}),className:"sr-only peer"}),a.jsx("div",{className:"w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green"})]})]}),t.plug_type!=="mqtt"&&a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"Enabled"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Enable automation for this plug"})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:t.enabled,onChange:T=>y.mutate({enabled:T.target.checked}),className:"sr-only peer"}),a.jsx("div",{className:"w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green"})]})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"Auto On"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Turn on when print starts"})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:t.auto_on,onChange:T=>y.mutate({auto_on:T.target.checked}),className:"sr-only peer"}),a.jsx("div",{className:"w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green"})]})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"Auto Off"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Turn off when print completes (one-shot)"})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:t.auto_off,onChange:T=>y.mutate({auto_off:T.target.checked}),className:"sr-only peer"}),a.jsx("div",{className:"w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green"})]})]}),t.auto_off&&a.jsxs("div",{className:"space-y-3 pl-4 border-l-2 border-bambu-dark-tertiary",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white mb-2",children:"Turn Off Delay Mode"}),a.jsxs("div",{className:"flex gap-2",children:[a.jsxs("button",{onClick:()=>y.mutate({off_delay_mode:"time"}),className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg text-sm transition-colors ${t.off_delay_mode==="time"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white"}`,children:[a.jsx(nr,{className:"w-4 h-4"}),"Time"]}),a.jsxs("button",{onClick:()=>y.mutate({off_delay_mode:"temperature"}),className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg text-sm transition-colors ${t.off_delay_mode==="temperature"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white"}`,children:[a.jsx(GM,{className:"w-4 h-4"}),"Temp"]})]})]}),t.off_delay_mode==="time"?a.jsxs("div",{children:[a.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Delay (minutes)"}),a.jsx("input",{type:"number",min:"1",max:"60",value:t.off_delay_minutes,onChange:T=>y.mutate({off_delay_minutes:parseInt(T.target.value)||5}),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none"})]}):a.jsxs("div",{children:[a.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Temperature threshold (C)"}),a.jsx("input",{type:"number",min:"30",max:"100",value:t.off_temp_threshold,onChange:T=>y.mutate({off_temp_threshold:parseInt(T.target.value)||70}),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none"}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Turns off when nozzle cools below this temperature"})]})]})]}),a.jsxs("div",{className:"flex gap-2 pt-2",children:[a.jsxs(ke,{size:"sm",variant:"secondary",onClick:()=>e(t),className:"flex-1",children:[a.jsx(Eg,{className:"w-4 h-4"}),"Edit"]}),a.jsx(ke,{size:"sm",variant:"secondary",onClick:()=>s(!0),className:"text-red-400 hover:text-red-300",children:a.jsx(cn,{className:"w-4 h-4"})})]})]})]})}),i&&a.jsx(er,{title:"Delete Smart Plug",message:`Are you sure you want to delete "${t.name}"? This cannot be undone.`,confirmText:"Delete",variant:"danger",onConfirm:()=>{S.mutate(),s(!1)},onCancel:()=>s(!1)}),o&&a.jsx(er,{title:"Turn On Smart Plug",message:`Are you sure you want to turn on "${t.name}"?`,confirmText:"Turn On",variant:"default",onConfirm:()=>{x.mutate("on"),l(!1)},onCancel:()=>l(!1)}),c&&a.jsx(er,{title:"Turn Off Smart Plug",message:`Are you sure you want to turn off "${t.name}"? This will cut power to the connected device.`,confirmText:"Turn Off",variant:"danger",onConfirm:()=>{x.mutate("off"),u(!1)},onCancel:()=>u(!1)})]})}function VYe({plug:t,onClose:e}){const n=un(),r=!!t,[i,s]=_.useState(t?.plug_type||"tasmota"),[o,l]=_.useState(t?.name||""),[c,u]=_.useState(t?.ip_address||""),[d,h]=_.useState(t?.username||""),[m,p]=_.useState(t?.password||""),[b,v]=_.useState(t?.ha_entity_id||""),[x,y]=_.useState(t?.mqtt_power_topic||t?.mqtt_topic||""),[S,N]=_.useState(t?.mqtt_power_path||""),[A,k]=_.useState((t?.mqtt_power_multiplier??t?.mqtt_multiplier??1).toString()),[C,E]=_.useState(t?.mqtt_energy_topic||""),[P,T]=_.useState(t?.mqtt_energy_path||""),[j,z]=_.useState((t?.mqtt_energy_multiplier??1).toString()),[L,B]=_.useState(t?.mqtt_state_topic||""),[R,$]=_.useState(t?.mqtt_state_path||""),[q,I]=_.useState(t?.mqtt_state_on_value||""),[G,Y]=_.useState(t?.ha_power_entity||""),[re,H]=_.useState(t?.ha_energy_today_entity||""),[K,ne]=_.useState(t?.ha_energy_total_entity||""),[ie,be]=_.useState(""),[pe,de]=_.useState(""),[Ce,ae]=_.useState(!1),Ae=_.useRef(null),[Le,fe]=_.useState(""),[Xe,W]=_.useState(!1),Q=_.useRef(null),[me,X]=_.useState(""),[te,V]=_.useState(!1),ge=_.useRef(null),[Se,ee]=_.useState(""),[U,O]=_.useState(!1),Z=_.useRef(null),[le,we]=_.useState(t?.printer_id||null),[ye,se]=_.useState(null),[Oe,He]=_.useState(null),[tt,Ue]=_.useState(t?.power_alert_enabled||!1),[xe,Te]=_.useState(t?.power_alert_high?.toString()||""),[Ie,Ne]=_.useState(t?.power_alert_low?.toString()||""),[Ge,Me]=_.useState(t?.schedule_enabled||!1),[rt,Ee]=_.useState(t?.schedule_on_time||""),[Ke,Be]=_.useState(t?.schedule_off_time||""),[ue,$e]=_.useState(t?.show_in_switchbar||!1),[at,kt]=_.useState(t?.show_on_printer_card??!0),[gt,Ut]=_.useState(!1),[Ft,Fe]=_.useState({scanned:0,total:0}),[xt,Wt]=_.useState([]),Qt=_.useRef(null),{data:En}=st({queryKey:["printers"],queryFn:ce.getPrinters}),{data:hn}=st({queryKey:["smart-plugs"],queryFn:ce.getSmartPlugs}),{data:or}=st({queryKey:["settings"],queryFn:ce.getSettings}),Kn=!!(or?.ha_enabled&&or?.ha_url&&or?.ha_token);_.useEffect(()=>{const _e=setTimeout(()=>{de(ie)},300);return()=>clearTimeout(_e)},[ie]),_.useEffect(()=>{const _e=Re=>{Ae.current&&!Ae.current.contains(Re.target)&&ae(!1),Q.current&&!Q.current.contains(Re.target)&&W(!1),ge.current&&!ge.current.contains(Re.target)&&V(!1),Z.current&&!Z.current.contains(Re.target)&&O(!1)};return document.addEventListener("mousedown",_e),()=>document.removeEventListener("mousedown",_e)},[]);const{data:Qn,isLoading:Tn,error:di}=st({queryKey:["ha-entities",pe],queryFn:()=>ce.getHAEntities(pe||void 0),enabled:i==="homeassistant"&&Kn,retry:!1,staleTime:0}),{data:ii}=st({queryKey:["ha-sensor-entities"],queryFn:ce.getHASensorEntities,enabled:i==="homeassistant"&&Kn,retry:!1,staleTime:0});_.useEffect(()=>{const _e=Re=>{Re.key==="Escape"&&e()};return window.addEventListener("keydown",_e),()=>{window.removeEventListener("keydown",_e),Qt.current&&clearInterval(Qt.current)}},[e]);const je=async()=>{Ut(!0),Wt([]),Fe({scanned:0,total:0}),He(null);try{await ce.startTasmotaScan();const _e=async()=>{try{const Re=await ce.getTasmotaScanStatus();Fe({scanned:Re.scanned,total:Re.total});const et=await ce.getDiscoveredTasmotaDevices();Wt(et),Re.running||(Ut(!1),Qt.current&&(clearInterval(Qt.current),Qt.current=null))}catch(Re){console.error("Polling error:",Re)}};await _e(),Qt.current=setInterval(_e,500)}catch(_e){Ut(!1);const Re=_e instanceof Error?_e.message:typeof _e=="string"?_e:JSON.stringify(_e);He(Re||"Failed to start scan")}},Je=async()=>{try{await ce.stopTasmotaScan()}catch{}Ut(!1),Qt.current&&(clearInterval(Qt.current),Qt.current=null)},dt=_e=>{u(_e.ip_address),l(_e.name),se(null)},ht=pt({mutationFn:()=>ce.testSmartPlugConnection(c,d||null,m||null),onSuccess:_e=>{se(_e),He(null),!o&&_e.device_name&&l(_e.device_name)},onError:_e=>{se(null),He(_e.message)}}),ct=pt({mutationFn:_e=>ce.createSmartPlug(_e),onSuccess:()=>{n.invalidateQueries({queryKey:["smart-plugs"]}),n.invalidateQueries({queryKey:["scriptPlugsByPrinter"]}),e()},onError:_e=>{He(_e.message)}}),Tt=pt({mutationFn:_e=>ce.updateSmartPlug(t.id,_e),onSuccess:()=>{n.invalidateQueries({queryKey:["smart-plugs"]}),n.invalidateQueries({queryKey:["scriptPlugsByPrinter"]}),e()},onError:_e=>{He(_e.message)}}),he=En?.filter(_e=>i==="tasmota"?!hn?.some(et=>et.printer_id===_e.id&&et.id!==t?.id&&et.plug_type==="tasmota"):!0),De=_e=>{if(_e.preventDefault(),He(null),!o.trim()){He("Name is required");return}if(i==="tasmota"&&!c.trim()){He("IP address is required for Tasmota plugs");return}if(i==="homeassistant"&&!b){He("Entity is required for Home Assistant plugs");return}if(i==="mqtt"){const et=x.trim(),Ye=C.trim(),Ct=L.trim();if(!et&&!Ye&&!Ct){He("At least one MQTT topic must be configured for power, energy, or state monitoring");return}}const Re={name:o.trim(),plug_type:i,ip_address:i==="tasmota"?c.trim():null,ha_entity_id:i==="homeassistant"?b:null,ha_power_entity:i==="homeassistant"&&G||null,ha_energy_today_entity:i==="homeassistant"&&re||null,ha_energy_total_entity:i==="homeassistant"&&K||null,mqtt_power_topic:i==="mqtt"&&x.trim()||null,mqtt_power_path:i==="mqtt"&&S.trim()||null,mqtt_power_multiplier:i==="mqtt"&&parseFloat(A)||1,mqtt_energy_topic:i==="mqtt"&&C.trim()||null,mqtt_energy_path:i==="mqtt"&&P.trim()||null,mqtt_energy_multiplier:i==="mqtt"&&parseFloat(j)||1,mqtt_state_topic:i==="mqtt"&&L.trim()||null,mqtt_state_path:i==="mqtt"&&R.trim()||null,mqtt_state_on_value:i==="mqtt"&&q.trim()||null,username:i==="tasmota"&&d.trim()||null,password:i==="tasmota"&&m.trim()||null,printer_id:le,power_alert_enabled:tt,power_alert_high:xe?parseFloat(xe):null,power_alert_low:Ie?parseFloat(Ie):null,schedule_enabled:Ge,schedule_on_time:rt||null,schedule_off_time:Ke||null,show_in_switchbar:ue,show_on_printer_card:at};r?Tt.mutate(Re):ct.mutate(Re)},Ve=ct.isPending||Tt.isPending;return a.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",onClick:e,children:a.jsxs("div",{className:"bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-md max-h-[90vh] flex flex-col",onClick:_e=>_e.stopPropagation(),children:[a.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary flex-shrink-0",children:[a.jsx("h2",{className:"text-lg font-semibold text-white",children:r?"Edit Smart Plug":"Add Smart Plug"}),a.jsx("button",{onClick:e,className:"text-bambu-gray hover:text-white transition-colors",children:a.jsx(Lt,{className:"w-5 h-5"})})]}),a.jsxs("form",{onSubmit:De,className:"p-6 space-y-4 overflow-y-auto",children:[Oe&&a.jsx("div",{className:"p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400",children:Oe}),!r&&a.jsxs("div",{className:"flex gap-2 mb-2",children:[a.jsxs("button",{type:"button",onClick:()=>{s("tasmota"),se(null),He(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2.5 rounded-lg font-medium transition-colors ${i==="tasmota"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white border border-bambu-dark-tertiary"}`,children:[a.jsx(rl,{className:"w-4 h-4"}),"Tasmota"]}),a.jsxs("button",{type:"button",onClick:()=>{s("homeassistant"),se(null),He(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2.5 rounded-lg font-medium transition-colors ${i==="homeassistant"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white border border-bambu-dark-tertiary"}`,children:[a.jsx(Jy,{className:"w-4 h-4"}),"HA"]}),a.jsxs("button",{type:"button",onClick:()=>{s("mqtt"),se(null),He(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2.5 rounded-lg font-medium transition-colors ${i==="mqtt"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white border border-bambu-dark-tertiary"}`,children:[a.jsx(cO,{className:"w-4 h-4"}),"MQTT"]})]}),!r&&i==="tasmota"&&a.jsxs("div",{className:"space-y-3",children:[gt?a.jsxs(ke,{type:"button",variant:"secondary",onClick:Je,className:"w-full",children:[a.jsx(Lt,{className:"w-4 h-4"}),"Stop Scanning"]}):a.jsxs(ke,{type:"button",variant:"primary",onClick:je,className:"w-full",children:[a.jsx(va,{className:"w-4 h-4"}),"Discover Tasmota Devices"]}),gt&&Ft.total>0&&a.jsxs("div",{className:"space-y-1",children:[a.jsxs("div",{className:"flex justify-between text-xs text-bambu-gray",children:[a.jsx("span",{children:"Scanning network..."}),a.jsxs("span",{children:[Ft.scanned," / ",Ft.total]})]}),a.jsx("div",{className:"w-full bg-bambu-dark-tertiary rounded-full h-2",children:a.jsx("div",{className:"bg-bambu-green h-2 rounded-full transition-all duration-300",style:{width:`${Ft.scanned/Ft.total*100}%`}})})]}),xt.length>0&&a.jsxs("div",{className:"space-y-2",children:[a.jsxs("p",{className:"text-xs text-bambu-gray",children:["Found ",xt.length," device(s) - click to select:"]}),a.jsx("div",{className:"max-h-40 overflow-y-auto space-y-1",children:xt.map(_e=>a.jsxs("button",{type:"button",onClick:()=>dt(_e),className:"w-full flex items-center justify-between p-2 bg-bambu-dark hover:bg-bambu-dark-tertiary rounded-lg transition-colors text-left border border-bambu-dark-tertiary",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(rl,{className:"w-4 h-4 text-bambu-green"}),a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:_e.name}),a.jsx("p",{className:"text-xs text-bambu-gray",children:_e.ip_address})]})]}),_e.state&&a.jsxs("span",{className:`flex items-center gap-1 text-xs ${_e.state==="ON"?"text-bambu-green":"text-bambu-gray"}`,children:[a.jsx(Zu,{className:"w-3 h-3"}),_e.state]})]},_e.ip_address))})]}),!gt&&xt.length===0&&Ft.total>0&&a.jsx("p",{className:"text-xs text-bambu-gray text-center py-2",children:"No Tasmota devices found on your network"})]}),i==="homeassistant"&&a.jsxs("div",{className:"space-y-3",children:[!Kn&&a.jsxs("div",{className:"space-y-3",children:[a.jsxs("div",{className:"p-3 bg-yellow-500/20 border border-yellow-500/50 rounded-lg text-sm text-yellow-400",children:["Home Assistant is not configured. Set it up in"," ",a.jsx("span",{className:"font-medium",children:"Settings → Network → Home Assistant"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1 opacity-50",children:"Select Entity *"}),a.jsx("select",{disabled:!0,className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray cursor-not-allowed opacity-50",children:a.jsx("option",{children:"Choose an entity..."})})]})]}),Kn&&a.jsxs(a.Fragment,{children:[Tn&&a.jsxs("div",{className:"flex items-center justify-center py-4 text-bambu-gray",children:[a.jsx(ut,{className:"w-5 h-5 animate-spin mr-2"}),"Loading entities..."]}),di&&a.jsxs("div",{className:"p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400",children:["Failed to load entities: ",di.message]}),(()=>{const _e=hn?.filter(Ye=>Ye.ha_entity_id&&Ye.id!==t?.id).map(Ye=>Ye.ha_entity_id)||[],Re=(Qn||[]).filter(Ye=>!_e.includes(Ye.entity_id)),et=Qn?.find(Ye=>Ye.entity_id===b);return a.jsxs("div",{ref:Ae,className:"relative",children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Select Entity *"}),a.jsxs("div",{className:"relative",children:[a.jsx(va,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"}),a.jsx("input",{type:"text",value:Ce?ie:et?`${et.friendly_name} (${et.entity_id})`:"",onChange:Ye=>{be(Ye.target.value),Ce||ae(!0)},onFocus:()=>{ae(!0),be("")},placeholder:"Search entities...",className:"w-full pl-9 pr-8 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"}),b&&!Ce&&a.jsx("button",{type:"button",onClick:()=>{v(""),be("")},className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-bambu-dark-tertiary rounded",children:a.jsx(Lt,{className:"w-4 h-4 text-bambu-gray hover:text-white"})}),Tn&&a.jsx(ut,{className:"absolute right-2 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray animate-spin"})]}),Ce&&a.jsxs("div",{className:"absolute z-50 w-full mt-1 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-60 overflow-y-auto",children:[Tn&&a.jsxs("div",{className:"px-3 py-2 text-sm text-bambu-gray flex items-center gap-2",children:[a.jsx(ut,{className:"w-4 h-4 animate-spin"}),"Loading..."]}),!Tn&&Re.length===0&&a.jsx("div",{className:"px-3 py-2 text-sm text-bambu-gray",children:pe?`No entities found matching "${pe}"`:"No entities available"}),!Tn&&Re.map(Ye=>a.jsxs("button",{type:"button",onClick:()=>{v(Ye.entity_id),ae(!1),be(""),o||l(Ye.friendly_name)},className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary transition-colors ${Ye.entity_id===b?"bg-bambu-green/20 text-bambu-green":"text-white"}`,children:[a.jsx("div",{className:"font-medium",children:Ye.friendly_name}),a.jsxs("div",{className:"text-xs text-bambu-gray flex items-center justify-between",children:[a.jsx("span",{children:Ye.entity_id}),a.jsx("span",{className:Ye.state==="on"?"text-bambu-green":"",children:Ye.state})]})]},Ye.entity_id))]}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:pe?`Searching all entities (${Re.length} found)`:`Showing switch, light, input_boolean (${Re.length} available)`})]})})(),b&&ii&&ii.length>0&&a.jsxs("div",{className:"border-t border-bambu-dark-tertiary pt-4 mt-4 space-y-3",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white font-medium mb-1",children:"Energy Monitoring (Optional)"}),a.jsx("p",{className:"text-xs text-bambu-gray mb-3",children:"Search and select sensors that provide power/energy data."})]}),(()=>{const _e=ii.filter(Ye=>Ye.unit_of_measurement==="W"||Ye.unit_of_measurement==="kW"||Ye.unit_of_measurement==="mW"),Re=Le?_e.filter(Ye=>Ye.entity_id.toLowerCase().includes(Le.toLowerCase())||Ye.friendly_name.toLowerCase().includes(Le.toLowerCase())):_e,et=ii.find(Ye=>Ye.entity_id===G);return a.jsxs("div",{ref:Q,className:"relative",children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Power Sensor (W)"}),a.jsxs("div",{className:"relative",children:[a.jsx(va,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"}),a.jsx("input",{type:"text",value:Xe?Le:et?`${et.friendly_name} (${et.state} ${et.unit_of_measurement})`:"",onChange:Ye=>{fe(Ye.target.value),Xe||W(!0)},onFocus:()=>{W(!0),fe("")},placeholder:"Search power sensors...",className:"w-full pl-9 pr-8 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"}),G&&!Xe&&a.jsx("button",{type:"button",onClick:()=>{Y(""),fe("")},className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-bambu-dark-tertiary rounded",children:a.jsx(Lt,{className:"w-4 h-4 text-bambu-gray hover:text-white"})})]}),Xe&&a.jsxs("div",{className:"absolute z-50 w-full mt-1 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-48 overflow-y-auto",children:[a.jsx("button",{type:"button",onClick:()=>{Y(""),W(!1),fe("")},className:"w-full px-3 py-2 text-left text-sm text-bambu-gray hover:bg-bambu-dark-tertiary",children:"None"}),Re.map(Ye=>a.jsxs("button",{type:"button",onClick:()=>{Y(Ye.entity_id),W(!1),fe("")},className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${Ye.entity_id===G?"bg-bambu-green/20 text-bambu-green":"text-white"}`,children:[a.jsx("div",{className:"font-medium",children:Ye.friendly_name}),a.jsxs("div",{className:"text-xs text-bambu-gray",children:[Ye.entity_id," • ",Ye.state," ",Ye.unit_of_measurement]})]},Ye.entity_id)),Re.length===0&&a.jsx("div",{className:"px-3 py-2 text-sm text-bambu-gray",children:"No matching sensors"})]})]})})(),(()=>{const _e=ii.filter(Ye=>Ye.unit_of_measurement==="kWh"||Ye.unit_of_measurement==="Wh"||Ye.unit_of_measurement==="MWh"),Re=me?_e.filter(Ye=>Ye.entity_id.toLowerCase().includes(me.toLowerCase())||Ye.friendly_name.toLowerCase().includes(me.toLowerCase())):_e,et=ii.find(Ye=>Ye.entity_id===re);return a.jsxs("div",{ref:ge,className:"relative",children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Energy Today (kWh)"}),a.jsxs("div",{className:"relative",children:[a.jsx(va,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"}),a.jsx("input",{type:"text",value:te?me:et?`${et.friendly_name} (${et.state} ${et.unit_of_measurement})`:"",onChange:Ye=>{X(Ye.target.value),te||V(!0)},onFocus:()=>{V(!0),X("")},placeholder:"Search energy sensors...",className:"w-full pl-9 pr-8 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"}),re&&!te&&a.jsx("button",{type:"button",onClick:()=>{H(""),X("")},className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-bambu-dark-tertiary rounded",children:a.jsx(Lt,{className:"w-4 h-4 text-bambu-gray hover:text-white"})})]}),te&&a.jsxs("div",{className:"absolute z-50 w-full mt-1 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-48 overflow-y-auto",children:[a.jsx("button",{type:"button",onClick:()=>{H(""),V(!1),X("")},className:"w-full px-3 py-2 text-left text-sm text-bambu-gray hover:bg-bambu-dark-tertiary",children:"None"}),Re.map(Ye=>a.jsxs("button",{type:"button",onClick:()=>{H(Ye.entity_id),V(!1),X("")},className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${Ye.entity_id===re?"bg-bambu-green/20 text-bambu-green":"text-white"}`,children:[a.jsx("div",{className:"font-medium",children:Ye.friendly_name}),a.jsxs("div",{className:"text-xs text-bambu-gray",children:[Ye.entity_id," • ",Ye.state," ",Ye.unit_of_measurement]})]},Ye.entity_id)),Re.length===0&&a.jsx("div",{className:"px-3 py-2 text-sm text-bambu-gray",children:"No matching sensors"})]})]})})(),(()=>{const _e=ii.filter(Ye=>Ye.unit_of_measurement==="kWh"||Ye.unit_of_measurement==="Wh"||Ye.unit_of_measurement==="MWh"),Re=Se?_e.filter(Ye=>Ye.entity_id.toLowerCase().includes(Se.toLowerCase())||Ye.friendly_name.toLowerCase().includes(Se.toLowerCase())):_e,et=ii.find(Ye=>Ye.entity_id===K);return a.jsxs("div",{ref:Z,className:"relative",children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Total Energy (kWh)"}),a.jsxs("div",{className:"relative",children:[a.jsx(va,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"}),a.jsx("input",{type:"text",value:U?Se:et?`${et.friendly_name} (${et.state} ${et.unit_of_measurement})`:"",onChange:Ye=>{ee(Ye.target.value),U||O(!0)},onFocus:()=>{O(!0),ee("")},placeholder:"Search energy sensors...",className:"w-full pl-9 pr-8 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"}),K&&!U&&a.jsx("button",{type:"button",onClick:()=>{ne(""),ee("")},className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-bambu-dark-tertiary rounded",children:a.jsx(Lt,{className:"w-4 h-4 text-bambu-gray hover:text-white"})})]}),U&&a.jsxs("div",{className:"absolute z-50 w-full mt-1 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-48 overflow-y-auto",children:[a.jsx("button",{type:"button",onClick:()=>{ne(""),O(!1),ee("")},className:"w-full px-3 py-2 text-left text-sm text-bambu-gray hover:bg-bambu-dark-tertiary",children:"None"}),Re.map(Ye=>a.jsxs("button",{type:"button",onClick:()=>{ne(Ye.entity_id),O(!1),ee("")},className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${Ye.entity_id===K?"bg-bambu-green/20 text-bambu-green":"text-white"}`,children:[a.jsx("div",{className:"font-medium",children:Ye.friendly_name}),a.jsxs("div",{className:"text-xs text-bambu-gray",children:[Ye.entity_id," • ",Ye.state," ",Ye.unit_of_measurement]})]},Ye.entity_id)),Re.length===0&&a.jsx("div",{className:"px-3 py-2 text-sm text-bambu-gray",children:"No matching sensors"})]})]})})()]})]})]}),i==="mqtt"&&a.jsxs("div",{className:"space-y-3",children:[!or?.mqtt_broker&&a.jsxs("div",{className:"p-3 bg-yellow-500/20 border border-yellow-500/50 rounded-lg text-sm text-yellow-400",children:["MQTT broker not configured. Set broker address in"," ",a.jsx("span",{className:"font-medium",children:"Settings → Network → MQTT Publishing"})," ","(you don't need to enable publishing, just fill in the broker details)."]}),or?.mqtt_broker&&a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"p-3 bg-blue-500/10 border border-blue-500/30 rounded-lg text-sm text-blue-300",children:[a.jsx("p",{className:"font-medium mb-1",children:"Monitor Only"}),a.jsx("p",{className:"text-xs opacity-80",children:"MQTT plugs receive power/energy data via MQTT subscription. On/off control is not available - use your MQTT broker or home automation system."})]}),a.jsxs("div",{className:"space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[a.jsx("p",{className:"text-white font-medium text-sm",children:"Power Monitoring"}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Topic"}),a.jsx("input",{type:"text",value:x,onChange:_e=>y(_e.target.value),placeholder:"zigbee2mqtt/shelly-working-room",className:"w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"})]}),a.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"JSON Path"}),a.jsx("input",{type:"text",value:S,onChange:_e=>N(_e.target.value),placeholder:"power_l1",className:"w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Multiplier"}),a.jsx("input",{type:"text",value:A,onChange:_e=>k(_e.target.value),placeholder:"1",className:"w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"})]})]}),a.jsxs("p",{className:"text-xs text-bambu-gray",children:['JSON path extracts value from JSON payload (e.g., "power_l1"). Leave empty if topic publishes raw numeric values.',a.jsx("br",{}),"Use multiplier 0.001 for mW→W, 1000 for kW→W."]})]}),a.jsxs("div",{className:"space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[a.jsxs("p",{className:"text-white font-medium text-sm",children:["Energy Monitoring ",a.jsx("span",{className:"text-bambu-gray font-normal",children:"(optional)"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Topic"}),a.jsx("input",{type:"text",value:C,onChange:_e=>E(_e.target.value),placeholder:"Same as power topic, or different",className:"w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"})]}),a.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"JSON Path"}),a.jsx("input",{type:"text",value:P,onChange:_e=>T(_e.target.value),placeholder:"energy_l1",className:"w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Multiplier"}),a.jsx("input",{type:"text",value:j,onChange:_e=>z(_e.target.value),placeholder:"1",className:"w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"})]})]}),a.jsxs("p",{className:"text-xs text-bambu-gray",children:["JSON path extracts value from JSON payload. Leave empty for raw values.",a.jsx("br",{}),"Use multiplier 0.001 for Wh→kWh, 1000 for MWh→kWh."]})]}),a.jsxs("div",{className:"space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[a.jsxs("p",{className:"text-white font-medium text-sm",children:["State Monitoring ",a.jsx("span",{className:"text-bambu-gray font-normal",children:"(optional)"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Topic"}),a.jsx("input",{type:"text",value:L,onChange:_e=>B(_e.target.value),placeholder:"Same as power topic, or different",className:"w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"})]}),a.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"JSON Path"}),a.jsx("input",{type:"text",value:R,onChange:_e=>$(_e.target.value),placeholder:"state_l1",className:"w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"ON Value"}),a.jsx("input",{type:"text",value:q,onChange:_e=>I(_e.target.value),placeholder:"ON, true, 1",className:"w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"})]})]}),a.jsxs("p",{className:"text-xs text-bambu-gray",children:["JSON path extracts value from JSON payload. Leave empty for raw values.",a.jsx("br",{}),'ON value: the exact string that means "ON". Leave empty for auto-detect (ON, true, 1).']})]})]})]}),i==="tasmota"&&a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"IP Address *"}),a.jsxs("div",{className:"flex gap-2",children:[a.jsx("input",{type:"text",value:c,onChange:_e=>{u(_e.target.value),se(null)},placeholder:"192.168.1.100",className:"flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"}),a.jsxs(ke,{type:"button",variant:"secondary",onClick:()=>ht.mutate(),disabled:!c.trim()||ht.isPending,children:[ht.isPending?a.jsx(ut,{className:"w-4 h-4 animate-spin"}):a.jsx(Fg,{className:"w-4 h-4"}),"Test"]})]})]}),i==="tasmota"&&ye&&a.jsx("div",{className:`p-3 rounded-lg flex items-center gap-2 ${ye.success?"bg-bambu-green/20 border border-bambu-green/50 text-bambu-green":"bg-red-500/20 border border-red-500/50 text-red-400"}`,children:ye.success?a.jsxs(a.Fragment,{children:[a.jsx(Nr,{className:"w-5 h-5"}),a.jsxs("div",{children:[a.jsx("p",{className:"font-medium",children:"Connected!"}),a.jsxs("p",{className:"text-sm opacity-80",children:[ye.device_name&&`Device: ${ye.device_name} - `,"State: ",ye.state]})]})]}):a.jsxs(a.Fragment,{children:[a.jsx(_m,{className:"w-5 h-5"}),a.jsx("span",{children:"Connection failed"})]})}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Name *"}),a.jsx("input",{type:"text",value:o,onChange:_e=>l(_e.target.value),placeholder:"Living Room Plug",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),i==="tasmota"&&a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Username"}),a.jsx("input",{type:"text",value:d,onChange:_e=>h(_e.target.value),placeholder:"admin",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Password"}),a.jsx("input",{type:"password",value:m,onChange:_e=>p(_e.target.value),placeholder:"********",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]})]}),a.jsx("p",{className:"text-xs text-bambu-gray -mt-2",children:"Leave empty if your Tasmota device doesn't require authentication"})]}),i!=="mqtt"&&a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Link to Printer"}),a.jsxs("select",{value:le??"",onChange:_e=>we(_e.target.value?Number(_e.target.value):null),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[a.jsx("option",{value:"",children:"No printer (manual control only)"}),he?.map(_e=>a.jsx("option",{value:_e.id,children:_e.name},_e.id))]}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Linking enables automatic on/off when prints start/complete"})]}),a.jsxs("div",{className:"border-t border-bambu-dark-tertiary pt-4",children:[a.jsxs("div",{className:"flex items-center justify-between mb-3",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(Og,{className:"w-4 h-4 text-bambu-green"}),a.jsx("span",{className:"text-white font-medium",children:"Power Alerts"})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:tt,onChange:_e=>Ue(_e.target.checked),className:"sr-only peer"}),a.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),tt&&a.jsxs("div",{className:"space-y-3",children:[a.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Alert if above (W)"}),a.jsx("input",{type:"number",value:xe,onChange:_e=>Te(_e.target.value),placeholder:"e.g. 200",min:"0",max:"5000",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Alert if below (W)"}),a.jsx("input",{type:"number",value:Ie,onChange:_e=>Ne(_e.target.value),placeholder:"e.g. 10",min:"0",max:"5000",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]})]}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Get notified when power consumption crosses these thresholds. Leave empty to disable that direction."})]})]}),i!=="mqtt"&&a.jsxs("div",{className:"border-t border-bambu-dark-tertiary pt-4",children:[a.jsxs("div",{className:"flex items-center justify-between mb-3",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(nr,{className:"w-4 h-4 text-bambu-green"}),a.jsx("span",{className:"text-white font-medium",children:"Daily Schedule"})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:Ge,onChange:_e=>Me(_e.target.checked),className:"sr-only peer"}),a.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),Ge&&a.jsxs("div",{className:"space-y-3",children:[a.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Turn On at"}),a.jsx("input",{type:"time",value:rt,onChange:_e=>Ee(_e.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Turn Off at"}),a.jsx("input",{type:"time",value:Ke,onChange:_e=>Be(_e.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]})]}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Automatically turn the plug on/off at these times daily. Leave empty to skip that action."})]})]}),a.jsx("div",{className:"border-t border-bambu-dark-tertiary pt-4",children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(UM,{className:"w-4 h-4 text-bambu-green"}),a.jsxs("div",{children:[a.jsx("span",{className:"text-white font-medium",children:"Show in Switchbar"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Quick access from sidebar"})]})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:ue,onChange:_e=>$e(_e.target.checked),className:"sr-only peer"}),a.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]})}),i==="homeassistant"&&a.jsx("div",{className:"border-t border-bambu-dark-tertiary pt-4",children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(_c,{className:"w-4 h-4 text-bambu-green"}),a.jsxs("div",{children:[a.jsx("span",{className:"text-white font-medium",children:"Show on Printer Card"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Display button on printer card"})]})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:at,onChange:_e=>kt(_e.target.checked),className:"sr-only peer"}),a.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]})}),a.jsxs("div",{className:"flex gap-3 pt-2",children:[a.jsx(ke,{type:"button",variant:"secondary",onClick:e,className:"flex-1",children:"Cancel"}),a.jsxs(ke,{type:"submit",disabled:Ve,className:"flex-1",children:[Ve?a.jsx(ut,{className:"w-4 h-4 animate-spin"}):a.jsx(gs,{className:"w-4 h-4"}),r?"Save":"Add"]})]})]})]})})}function $n({checked:t,onChange:e,disabled:n}){const r=i=>{i.preventDefault(),i.stopPropagation(),n||e(!t)};return a.jsx("button",{type:"button",role:"switch","aria-checked":t,disabled:n,onClick:r,className:`relative inline-flex w-11 h-7 md:w-9 md:h-5 rounded-full transition-colors flex-shrink-0 focus:outline-none focus:ring-2 focus:ring-bambu-green focus:ring-offset-2 focus:ring-offset-bambu-dark ${n?"bg-bambu-dark-tertiary/50 cursor-not-allowed opacity-50":t?"bg-bambu-green cursor-pointer":"bg-bambu-dark-tertiary cursor-pointer hover:bg-bambu-dark-tertiary/80"}`,children:a.jsx("span",{className:`pointer-events-none absolute top-[3px] md:top-[2px] left-[3px] md:left-[2px] w-5 h-5 md:w-4 md:h-4 bg-white rounded-full shadow transition-transform duration-200 ease-in-out ${t?"translate-x-4":"translate-x-0"}`})})}const GYe={callmebot:"CallMeBot/WhatsApp",ntfy:"ntfy",pushover:"Pushover",telegram:"Telegram",email:"Email",discord:"Discord",webhook:"Webhook"};function qYe({provider:t,onEdit:e}){const n=un(),[r,i]=_.useState(!1),[s,o]=_.useState(!1),[l,c]=_.useState(null),{data:u}=st({queryKey:["printers"],queryFn:ce.getPrinters}),d=u?.find(v=>v.id===t.printer_id),h=pt({mutationFn:v=>ce.updateNotificationProvider(t.id,v),onSuccess:()=>{n.invalidateQueries({queryKey:["notification-providers"]})}}),m=pt({mutationFn:()=>ce.deleteNotificationProvider(t.id),onSuccess:()=>{n.invalidateQueries({queryKey:["notification-providers"]})}}),p=pt({mutationFn:()=>ce.testNotificationProvider(t.id),onSuccess:v=>{c(v),n.invalidateQueries({queryKey:["notification-providers"]})},onError:v=>{c({success:!1,message:v.message})}}),b=v=>v||"";return a.jsxs(a.Fragment,{children:[a.jsx(_t,{className:"relative",children:a.jsxs(Mt,{className:"p-4",children:[a.jsxs("div",{className:"flex items-start justify-between mb-3",children:[a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx("div",{className:`p-2 rounded-lg ${t.enabled?"bg-bambu-green/20":"bg-bambu-dark"}`,children:a.jsx(Og,{className:`w-5 h-5 ${t.enabled?"text-bambu-green":"text-bambu-gray"}`})}),a.jsxs("div",{children:[a.jsx("h3",{className:"font-medium text-white",children:t.name}),a.jsx("p",{className:"text-sm text-bambu-gray",children:GYe[t.provider_type]||t.provider_type})]})]}),a.jsxs("div",{className:"flex items-center gap-3",children:[t.last_success&&a.jsxs("span",{className:"text-xs text-status-ok hidden sm:inline",children:["Last: ",tb(t.last_success)]}),t.last_error&&t.last_error_at&&(!t.last_success||(Hi(t.last_error_at)?.getTime()||0)>(Hi(t.last_success)?.getTime()||0))&&a.jsx("span",{className:"text-xs text-status-error",title:t.last_error,children:"Error"}),a.jsx($n,{checked:t.enabled,onChange:v=>h.mutate({enabled:v})})]})]}),d&&a.jsxs("div",{className:"mb-3 px-2 py-1.5 bg-bambu-dark rounded-lg",children:[a.jsx("span",{className:"text-xs text-bambu-gray",children:"Printer: "}),a.jsx("span",{className:"text-sm text-white",children:d.name})]}),!d&&!t.printer_id&&a.jsx("div",{className:"mb-3 px-2 py-1.5 bg-bambu-dark rounded-lg",children:a.jsx("span",{className:"text-xs text-bambu-gray",children:"All printers"})}),a.jsxs("div",{className:"mb-3 flex flex-wrap gap-1",children:[t.on_print_start&&a.jsx("span",{className:"px-2 py-0.5 bg-blue-500/20 text-blue-400 text-xs rounded",children:"Start"}),t.on_plate_not_empty&&a.jsx("span",{className:"px-2 py-0.5 bg-rose-600/20 text-rose-300 text-xs rounded",children:"Plate Check"}),t.on_print_complete&&a.jsx("span",{className:"px-2 py-0.5 bg-bambu-green/20 text-bambu-green text-xs rounded",children:"Complete"}),t.on_print_failed&&a.jsx("span",{className:"px-2 py-0.5 bg-red-500/20 text-red-400 text-xs rounded",children:"Failed"}),t.on_print_stopped&&a.jsx("span",{className:"px-2 py-0.5 bg-orange-500/20 text-orange-400 text-xs rounded",children:"Stopped"}),t.on_print_progress&&a.jsx("span",{className:"px-2 py-0.5 bg-yellow-500/20 text-yellow-400 text-xs rounded",children:"Progress"}),t.on_printer_offline&&a.jsx("span",{className:"px-2 py-0.5 bg-gray-500/20 text-gray-400 text-xs rounded",children:"Offline"}),t.on_printer_error&&a.jsx("span",{className:"px-2 py-0.5 bg-rose-500/20 text-rose-400 text-xs rounded",children:"Error"}),t.on_filament_low&&a.jsx("span",{className:"px-2 py-0.5 bg-cyan-500/20 text-cyan-400 text-xs rounded",children:"Low Filament"}),t.on_maintenance_due&&a.jsx("span",{className:"px-2 py-0.5 bg-purple-500/20 text-purple-400 text-xs rounded",children:"Maintenance"}),t.on_ams_humidity_high&&a.jsx("span",{className:"px-2 py-0.5 bg-blue-600/20 text-blue-300 text-xs rounded",children:"AMS Humidity"}),t.on_ams_temperature_high&&a.jsx("span",{className:"px-2 py-0.5 bg-orange-600/20 text-orange-300 text-xs rounded",children:"AMS Temp"}),t.on_ams_ht_humidity_high&&a.jsx("span",{className:"px-2 py-0.5 bg-cyan-600/20 text-cyan-300 text-xs rounded",children:"AMS-HT Humidity"}),t.on_ams_ht_temperature_high&&a.jsx("span",{className:"px-2 py-0.5 bg-amber-600/20 text-amber-300 text-xs rounded",children:"AMS-HT Temp"}),t.quiet_hours_enabled&&a.jsxs("span",{className:"px-2 py-0.5 bg-indigo-500/20 text-indigo-400 text-xs rounded flex items-center gap-1",children:[a.jsx(hS,{className:"w-3 h-3"}),"Quiet"]}),t.daily_digest_enabled&&a.jsxs("span",{className:"px-2 py-0.5 bg-emerald-500/20 text-emerald-400 text-xs rounded flex items-center gap-1",children:[a.jsx(ei,{className:"w-3 h-3"}),"Digest ",t.daily_digest_time]})]}),a.jsx("div",{className:"mb-3",children:a.jsxs(ke,{size:"sm",variant:"secondary",disabled:p.isPending,onClick:()=>{c(null),p.mutate()},className:"w-full",children:[p.isPending?a.jsx(ut,{className:"w-4 h-4 animate-spin"}):a.jsx($M,{className:"w-4 h-4"}),"Send Test Notification"]})}),l&&a.jsxs("div",{className:`mb-3 p-2 rounded-lg flex items-center gap-2 text-sm ${l.success?"bg-bambu-green/20 text-bambu-green":"bg-red-500/20 text-red-400"}`,children:[l.success?a.jsx(Nr,{className:"w-4 h-4"}):a.jsx(ta,{className:"w-4 h-4"}),a.jsx("span",{children:l.message})]}),a.jsxs("button",{onClick:()=>o(!s),className:"w-full flex items-center justify-between py-2 text-sm text-bambu-gray hover:text-white transition-colors border-t border-bambu-dark-tertiary",children:[a.jsxs("span",{className:"flex items-center gap-2",children:[a.jsx(jh,{className:"w-4 h-4"}),"Event Settings"]}),s?a.jsx(Ch,{className:"w-4 h-4"}):a.jsx(Sr,{className:"w-4 h-4"})]}),s&&a.jsxs("div",{className:"pt-3 border-t border-bambu-dark-tertiary space-y-4",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"Enabled"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Send notifications from this provider"})]}),a.jsx($n,{checked:t.enabled,onChange:v=>h.mutate({enabled:v})})]}),a.jsxs("div",{className:"space-y-2",children:[a.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide",children:"Print Events"}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("p",{className:"text-sm text-white",children:"Print Started"}),a.jsx($n,{checked:t.on_print_start,onChange:v=>h.mutate({on_print_start:v})})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"Plate Not Empty"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Objects detected before print"})]}),a.jsx($n,{checked:t.on_plate_not_empty??!0,onChange:v=>h.mutate({on_plate_not_empty:v})})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("p",{className:"text-sm text-white",children:"Print Completed"}),a.jsx($n,{checked:t.on_print_complete,onChange:v=>h.mutate({on_print_complete:v})})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("p",{className:"text-sm text-white",children:"Print Failed"}),a.jsx($n,{checked:t.on_print_failed,onChange:v=>h.mutate({on_print_failed:v})})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("p",{className:"text-sm text-white",children:"Print Stopped"}),a.jsx($n,{checked:t.on_print_stopped,onChange:v=>h.mutate({on_print_stopped:v})})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"Progress Milestones"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Notify at 25%, 50%, 75%"})]}),a.jsx($n,{checked:t.on_print_progress,onChange:v=>h.mutate({on_print_progress:v})})]})]}),a.jsxs("div",{className:"space-y-2",children:[a.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide",children:"Printer Status"}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("p",{className:"text-sm text-white",children:"Printer Offline"}),a.jsx($n,{checked:t.on_printer_offline,onChange:v=>h.mutate({on_printer_offline:v})})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("p",{className:"text-sm text-white",children:"Printer Error"}),a.jsx($n,{checked:t.on_printer_error,onChange:v=>h.mutate({on_printer_error:v})})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("p",{className:"text-sm text-white",children:"Low Filament"}),a.jsx($n,{checked:t.on_filament_low,onChange:v=>h.mutate({on_filament_low:v})})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"Maintenance Due"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Notify when maintenance is needed"})]}),a.jsx($n,{checked:t.on_maintenance_due??!1,onChange:v=>h.mutate({on_maintenance_due:v})})]})]}),a.jsxs("div",{className:"space-y-2",children:[a.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide",children:"AMS Alarms"}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"AMS Humidity High"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Regular AMS humidity exceeds threshold"})]}),a.jsx($n,{checked:t.on_ams_humidity_high??!1,onChange:v=>h.mutate({on_ams_humidity_high:v})})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"AMS Temperature High"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Regular AMS temperature exceeds threshold"})]}),a.jsx($n,{checked:t.on_ams_temperature_high??!1,onChange:v=>h.mutate({on_ams_temperature_high:v})})]})]}),a.jsxs("div",{className:"space-y-2",children:[a.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide",children:"AMS-HT Alarms"}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"AMS-HT Humidity High"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"AMS-HT humidity exceeds threshold"})]}),a.jsx($n,{checked:t.on_ams_ht_humidity_high??!1,onChange:v=>h.mutate({on_ams_ht_humidity_high:v})})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"AMS-HT Temperature High"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"AMS-HT temperature exceeds threshold"})]}),a.jsx($n,{checked:t.on_ams_ht_temperature_high??!1,onChange:v=>h.mutate({on_ams_ht_temperature_high:v})})]})]}),a.jsxs("div",{className:"space-y-2",children:[a.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide",children:"Print Queue"}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"Job Added"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Job added to queue"})]}),a.jsx($n,{checked:t.on_queue_job_added??!1,onChange:v=>h.mutate({on_queue_job_added:v})})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"Job Assigned"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Model-based job assigned to printer"})]}),a.jsx($n,{checked:t.on_queue_job_assigned??!1,onChange:v=>h.mutate({on_queue_job_assigned:v})})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"Job Started"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Queue job started printing"})]}),a.jsx($n,{checked:t.on_queue_job_started??!1,onChange:v=>h.mutate({on_queue_job_started:v})})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"Job Waiting"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Job waiting for filament"})]}),a.jsx($n,{checked:t.on_queue_job_waiting??!0,onChange:v=>h.mutate({on_queue_job_waiting:v})})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"Job Skipped"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Job skipped (previous failed)"})]}),a.jsx($n,{checked:t.on_queue_job_skipped??!0,onChange:v=>h.mutate({on_queue_job_skipped:v})})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"Job Failed"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Job failed to start"})]}),a.jsx($n,{checked:t.on_queue_job_failed??!0,onChange:v=>h.mutate({on_queue_job_failed:v})})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"Queue Complete"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"All queue jobs finished"})]}),a.jsx($n,{checked:t.on_queue_completed??!1,onChange:v=>h.mutate({on_queue_completed:v})})]})]}),a.jsxs("div",{className:"space-y-2",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(hS,{className:"w-4 h-4 text-purple-400"}),a.jsx("p",{className:"text-sm text-white",children:"Quiet Hours"})]}),a.jsx($n,{checked:t.quiet_hours_enabled,onChange:v=>h.mutate({quiet_hours_enabled:v})})]}),t.quiet_hours_enabled&&a.jsxs("div",{className:"pl-4 border-l-2 border-bambu-dark-tertiary space-y-2",children:[a.jsx("p",{className:"text-xs text-bambu-gray",children:"No notifications during these hours"}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(nr,{className:"w-4 h-4 text-bambu-gray"}),a.jsxs("span",{className:"text-sm text-white",children:[b(t.quiet_hours_start)||"22:00"," - ",b(t.quiet_hours_end)||"07:00"]})]}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Edit provider to change quiet hours"})]})]}),a.jsxs("div",{className:"space-y-2",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(ei,{className:"w-4 h-4 text-emerald-400"}),a.jsx("p",{className:"text-sm text-white",children:"Daily Digest"})]}),a.jsx($n,{checked:t.daily_digest_enabled,onChange:v=>h.mutate({daily_digest_enabled:v})})]}),t.daily_digest_enabled&&a.jsxs("div",{className:"pl-4 border-l-2 border-bambu-dark-tertiary space-y-2",children:[a.jsx("p",{className:"text-xs text-bambu-gray",children:"Batch notifications into a single daily summary"}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(nr,{className:"w-4 h-4 text-bambu-gray"}),a.jsxs("span",{className:"text-sm text-white",children:["Send at ",b(t.daily_digest_time)||"08:00"]})]}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Edit provider to change digest time"})]})]}),a.jsxs("div",{className:"flex gap-2 pt-2",children:[a.jsxs(ke,{size:"sm",variant:"secondary",onClick:()=>e(t),className:"flex-1",children:[a.jsx(Eg,{className:"w-4 h-4"}),"Edit"]}),a.jsx(ke,{size:"sm",variant:"secondary",onClick:()=>i(!0),className:"text-red-400 hover:text-red-300",children:a.jsx(cn,{className:"w-4 h-4"})})]})]})]})}),r&&a.jsx(er,{title:"Delete Notification Provider",message:`Are you sure you want to delete "${t.name}"? This cannot be undone.`,confirmText:"Delete",variant:"danger",onConfirm:()=>{m.mutate(),i(!1)},onCancel:()=>i(!1)})]})}const DW=[{value:"email",label:"Email",description:"SMTP email notifications"},{value:"telegram",label:"Telegram",description:"Notifications via Telegram bot"},{value:"discord",label:"Discord",description:"Send to Discord channel via webhook"},{value:"ntfy",label:"ntfy",description:"Free, self-hostable push notifications"},{value:"pushover",label:"Pushover",description:"Simple, reliable push notifications"},{value:"callmebot",label:"CallMeBot/WhatsApp",description:"Free WhatsApp notifications via CallMeBot"},{value:"webhook",label:"Webhook",description:"Generic HTTP POST to any URL"}];function WYe({provider:t,onClose:e}){const n=un(),r=!!t,[i,s]=_.useState(t?.name||""),[o,l]=_.useState(t?.provider_type||"email"),[c,u]=_.useState(t?.printer_id||null),[d,h]=_.useState(t?.quiet_hours_enabled||!1),[m,p]=_.useState(t?.quiet_hours_start||"22:00"),[b,v]=_.useState(t?.quiet_hours_end||"07:00"),[x,y]=_.useState(t?.daily_digest_enabled||!1),[S,N]=_.useState(t?.daily_digest_time||"08:00"),[A,k]=_.useState(t?.on_print_start??!1),[C,E]=_.useState(t?.on_print_complete??!0),[P,T]=_.useState(t?.on_print_failed??!0),[j,z]=_.useState(t?.on_print_stopped??!0),[L,B]=_.useState(t?.on_print_progress??!1),[R,$]=_.useState(t?.on_printer_offline??!1),[q,I]=_.useState(t?.on_printer_error??!1),[G,Y]=_.useState(t?.on_filament_low??!1),[re,H]=_.useState(t?.on_maintenance_due??!1),[K,ne]=_.useState(t?.config?Object.fromEntries(Object.entries(t.config).map(([X,te])=>[X,String(te)])):{}),[ie,be]=_.useState(null),[pe,de]=_.useState(null),{data:Ce}=st({queryKey:["printers"],queryFn:ce.getPrinters});_.useEffect(()=>{const X=te=>{te.key==="Escape"&&e()};return window.addEventListener("keydown",X),()=>window.removeEventListener("keydown",X)},[e]);const ae=pt({mutationFn:()=>ce.testNotificationConfig({provider_type:o,config:K}),onSuccess:X=>{be(X),de(null)},onError:X=>{be({success:!1,message:X.message})}}),Ae=pt({mutationFn:X=>ce.createNotificationProvider(X),onSuccess:()=>{n.invalidateQueries({queryKey:["notification-providers"]}),e()},onError:X=>{de(X.message)}}),Le=pt({mutationFn:X=>ce.updateNotificationProvider(t.id,X),onSuccess:()=>{n.invalidateQueries({queryKey:["notification-providers"]}),e()},onError:X=>{de(X.message)}}),fe=X=>{if(X.preventDefault(),de(null),!i.trim()){de("Name is required");return}const te=Q(o);for(const ge of te)if(!K[ge.key]?.trim()){de(`${ge.label} is required`);return}const V={name:i.trim(),provider_type:o,config:K,printer_id:c,quiet_hours_enabled:d,quiet_hours_start:d?m:null,quiet_hours_end:d?b:null,daily_digest_enabled:x,daily_digest_time:x?S:null,on_print_start:A,on_print_complete:C,on_print_failed:P,on_print_stopped:j,on_print_progress:L,on_printer_offline:R,on_printer_error:q,on_filament_low:G,on_maintenance_due:re};r?Le.mutate(V):Ae.mutate(V)},Xe=Ae.isPending||Le.isPending,W=X=>{switch(X){case"callmebot":return[{key:"phone",label:"Phone Number",placeholder:"+1234567890",type:"text",required:!0},{key:"apikey",label:"API Key",placeholder:"Your CallMeBot API key",type:"text",required:!0}];case"ntfy":return[{key:"server",label:"Server URL",placeholder:"https://ntfy.sh",type:"text",required:!1},{key:"topic",label:"Topic",placeholder:"my-bambuddy",type:"text",required:!0},{key:"auth_token",label:"Auth Token",placeholder:"Optional authentication",type:"password",required:!1}];case"pushover":return[{key:"user_key",label:"User Key",placeholder:"Your Pushover user key",type:"text",required:!0},{key:"app_token",label:"App Token",placeholder:"Your Pushover app token",type:"text",required:!0},{key:"priority",label:"Priority",placeholder:"0 (normal)",type:"number",required:!1}];case"telegram":return[{key:"bot_token",label:"Bot Token",placeholder:"Bot token from @BotFather",type:"password",required:!0},{key:"chat_id",label:"Chat ID",placeholder:"Your chat or group ID",type:"text",required:!0}];case"email":return[{key:"smtp_server",label:"SMTP Server",placeholder:"smtp.gmail.com",type:"text",required:!0},{key:"smtp_port",label:"SMTP Port",placeholder:"587",type:"number",required:!1},{key:"security",label:"Security",type:"select",required:!1,options:[{value:"starttls",label:"STARTTLS (Port 587)"},{value:"ssl",label:"SSL/TLS (Port 465)"},{value:"none",label:"None (Port 25)"}]},{key:"auth_enabled",label:"Authentication",type:"select",required:!1,options:[{value:"true",label:"Enabled"},{value:"false",label:"Disabled"}]},{key:"username",label:"Username",placeholder:"your@email.com",type:"text",required:!1},{key:"password",label:"Password",placeholder:"App password",type:"password",required:!1},{key:"from_email",label:"From Email",placeholder:"your@email.com",type:"text",required:!0},{key:"to_email",label:"To Email",placeholder:"recipient@email.com",type:"text",required:!0}];case"discord":return[{key:"webhook_url",label:"Webhook URL",placeholder:"https://discord.com/api/webhooks/...",type:"text",required:!0}];case"webhook":return[{key:"webhook_url",label:"Webhook URL",placeholder:"https://example.com/webhook",type:"text",required:!0},{key:"payload_format",label:"Payload Format",type:"select",required:!1,options:[{value:"generic",label:"Generic JSON"},{value:"slack",label:"Slack / Mattermost"}]},{key:"auth_header",label:"Authorization",placeholder:"Bearer token (optional)",type:"password",required:!1},{key:"field_title",label:"Title Field Name",placeholder:"title",type:"text",required:!1,showIf:te=>te.payload_format!=="slack"},{key:"field_message",label:"Message Field Name",placeholder:"message",type:"text",required:!1,showIf:te=>te.payload_format!=="slack"}];default:return[]}},Q=X=>W(X).filter(te=>te.required),me=W(o);return a.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4 overflow-y-auto",onClick:e,children:a.jsxs("div",{className:"bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-lg my-8 max-h-[90vh] overflow-y-auto",onClick:X=>X.stopPropagation(),children:[a.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary",children:[a.jsx("h2",{className:"text-lg font-semibold text-white",children:r?"Edit Notification Provider":"Add Notification Provider"}),a.jsx("button",{onClick:e,className:"text-bambu-gray hover:text-white transition-colors",children:a.jsx(Lt,{className:"w-5 h-5"})})]}),a.jsxs("form",{onSubmit:fe,className:"p-6 space-y-4",children:[pe&&a.jsx("div",{className:"p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400",children:pe}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Name *"}),a.jsx("input",{type:"text",value:i,onChange:X=>s(X.target.value),placeholder:"My Notifications",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Provider Type *"}),a.jsx("select",{value:o,onChange:X=>{l(X.target.value),ne({}),be(null)},disabled:r,className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none disabled:opacity-50",children:DW.map(X=>a.jsx("option",{value:X.value,children:X.label},X.value))}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:DW.find(X=>X.value===o)?.description})]}),a.jsxs("div",{className:"space-y-3",children:[a.jsx("p",{className:"text-sm text-bambu-gray",children:"Configuration"}),me.filter(X=>!("showIf"in X)||X.showIf?.(K)!==!1).map(X=>a.jsxs("div",{children:[a.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[X.label," ",X.required&&"*"]}),X.type==="select"&&"options"in X&&X.options?a.jsx("select",{value:K[X.key]||X.options[0]?.value||"",onChange:te=>{ne({...K,[X.key]:te.target.value}),be(null)},className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:X.options.map(te=>a.jsx("option",{value:te.value,children:te.label},te.value))}):a.jsx("input",{type:X.type,value:K[X.key]||"",onChange:te=>{ne({...K,[X.key]:te.target.value}),be(null)},placeholder:X.placeholder,className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]},X.key))]}),a.jsx("div",{className:"flex gap-2",children:a.jsxs(ke,{type:"button",variant:"secondary",onClick:()=>{be(null),ae.mutate()},disabled:ae.isPending||!K[Q(o)[0]?.key],className:"flex-1",children:[ae.isPending?a.jsx(ut,{className:"w-4 h-4 animate-spin"}):a.jsx($M,{className:"w-4 h-4"}),"Test Configuration"]})}),ie&&a.jsx("div",{className:`p-3 rounded-lg flex items-center gap-2 ${ie.success?"bg-bambu-green/20 border border-bambu-green/50 text-bambu-green":"bg-red-500/20 border border-red-500/50 text-red-400"}`,children:ie.success?a.jsxs(a.Fragment,{children:[a.jsx(Nr,{className:"w-5 h-5"}),a.jsx("span",{children:ie.message})]}):a.jsxs(a.Fragment,{children:[a.jsx(ta,{className:"w-5 h-5"}),a.jsx("span",{children:ie.message})]})}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Printer Filter"}),a.jsxs("select",{value:c??"",onChange:X=>u(X.target.value?Number(X.target.value):null),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[a.jsx("option",{value:"",children:"All printers"}),Ce?.map(X=>a.jsx("option",{value:X.id,children:X.name},X.id))]}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Only send notifications for events from this printer"})]}),a.jsxs("div",{className:"space-y-2",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("label",{className:"text-sm text-white",children:"Quiet Hours (Do Not Disturb)"}),a.jsx($n,{checked:d,onChange:h})]}),d&&a.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Start"}),a.jsx("input",{type:"time",value:m,onChange:X=>p(X.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"End"}),a.jsx("input",{type:"time",value:b,onChange:X=>v(X.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]})]})]}),a.jsxs("div",{className:"space-y-2",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("label",{className:"text-sm text-white",children:"Daily Digest"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Batch notifications into a single daily summary"})]}),a.jsx($n,{checked:x,onChange:y})]}),x&&a.jsxs("div",{children:[a.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Send digest at"}),a.jsx("input",{type:"time",value:S,onChange:X=>N(X.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Events will be collected and sent as a single summary at this time"})]})]}),a.jsxs("div",{className:"space-y-3",children:[a.jsx("p",{className:"text-sm text-bambu-gray",children:"Notification Events"}),a.jsxs("div",{className:"space-y-2 p-3 bg-bambu-dark rounded-lg",children:[a.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide mb-2",children:"Print Events"}),a.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("span",{className:"text-sm text-white",children:"Start"}),a.jsx($n,{checked:A,onChange:k})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("span",{className:"text-sm text-white",children:"Complete"}),a.jsx($n,{checked:C,onChange:E})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("span",{className:"text-sm text-white",children:"Failed"}),a.jsx($n,{checked:P,onChange:T})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("span",{className:"text-sm text-white",children:"Stopped"}),a.jsx($n,{checked:j,onChange:z})]}),a.jsxs("div",{className:"flex items-center justify-between col-span-2",children:[a.jsxs("div",{children:[a.jsx("span",{className:"text-sm text-white",children:"Progress"}),a.jsx("span",{className:"text-xs text-bambu-gray ml-1",children:"(25%, 50%, 75%)"})]}),a.jsx($n,{checked:L,onChange:B})]})]})]}),a.jsxs("div",{className:"space-y-2 p-3 bg-bambu-dark rounded-lg",children:[a.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide mb-2",children:"Printer Status"}),a.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("span",{className:"text-sm text-white",children:"Offline"}),a.jsx($n,{checked:R,onChange:$})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("span",{className:"text-sm text-white",children:"Error"}),a.jsx($n,{checked:q,onChange:I})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("span",{className:"text-sm text-white",children:"Low Filament"}),a.jsx($n,{checked:G,onChange:Y})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("span",{className:"text-sm text-white",children:"Maintenance"}),a.jsx($n,{checked:re,onChange:H})]})]})]})]}),a.jsxs("div",{className:"flex gap-3 pt-2",children:[a.jsx(ke,{type:"button",variant:"secondary",onClick:e,className:"flex-1",children:"Cancel"}),a.jsxs(ke,{type:"submit",disabled:Xe,className:"flex-1",children:[Xe?a.jsx(ut,{className:"w-4 h-4 animate-spin"}):a.jsx(gs,{className:"w-4 h-4"}),r?"Save":"Add"]})]})]})]})})}function KYe({template:t,onClose:e}){const n=un(),r=_.useRef(null),[i,s]=_.useState(t.title_template),[o,l]=_.useState(t.body_template),[c,u]=_.useState(null),[d,h]=_.useState(!0),{data:m}=st({queryKey:["template-variables"],queryFn:ce.getTemplateVariables}),p=m?.find(k=>k.event_type===t.event_type),{data:b,isLoading:v}=st({queryKey:["template-preview",t.event_type,i,o],queryFn:()=>ce.previewTemplate({event_type:t.event_type,title_template:i,body_template:o}),enabled:d&&i.length>0&&o.length>0});_.useEffect(()=>{const k=C=>{C.key==="Escape"&&e()};return window.addEventListener("keydown",k),()=>window.removeEventListener("keydown",k)},[e]);const x=pt({mutationFn:k=>ce.updateNotificationTemplate(t.id,k),onSuccess:()=>{n.invalidateQueries({queryKey:["notification-templates"]}),e()},onError:k=>{u(k.message)}}),y=pt({mutationFn:()=>ce.resetNotificationTemplate(t.id),onSuccess:k=>{s(k.title_template),l(k.body_template),n.invalidateQueries({queryKey:["notification-templates"]})},onError:k=>{u(k.message)}}),S=k=>{if(k.preventDefault(),u(null),!i.trim()){u("Title is required");return}if(!o.trim()){u("Body is required");return}x.mutate({title_template:i,body_template:o})},N=k=>{const C=r.current;if(!C)return;const E=C.selectionStart,P=C.selectionEnd,T=o,j=T.substring(0,E),z=T.substring(P),L=j+`{${k}}`+z;l(L),setTimeout(()=>{C.focus();const B=E+k.length+2;C.setSelectionRange(B,B)},0)},A=i!==t.title_template||o!==t.body_template;return a.jsx("div",{className:"fixed inset-0 bg-black/80 flex items-center justify-center z-50 p-4",children:a.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg w-full max-w-2xl max-h-[90vh] flex flex-col",children:[a.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary shrink-0",children:[a.jsxs("h2",{className:"text-lg font-semibold text-white",children:["Edit Template: ",t.name]}),a.jsx("button",{onClick:e,className:"p-1 hover:bg-bambu-dark-tertiary rounded transition-colors",children:a.jsx(Lt,{className:"w-5 h-5 text-bambu-gray"})})]}),a.jsxs("form",{onSubmit:S,className:"flex-1 overflow-y-auto p-4 space-y-4",children:[c&&a.jsx("div",{className:"p-3 bg-red-500/20 border border-red-500/50 rounded text-red-400 text-sm",children:c}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:"Title"}),a.jsx("input",{type:"text",value:i,onChange:k=>s(k.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white focus:outline-none focus:ring-1 focus:ring-bambu-green",placeholder:"Notification title..."})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:"Body"}),a.jsx("textarea",{ref:r,value:o,onChange:k=>l(k.target.value),rows:4,className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white focus:outline-none focus:ring-1 focus:ring-bambu-green font-mono text-sm resize-none",placeholder:"Notification body..."})]}),p&&a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-2",children:"Available Variables"}),a.jsx("div",{className:"flex flex-wrap gap-2",children:p.variables.map(k=>a.jsxs("button",{type:"button",onClick:()=>N(k),className:"inline-flex items-center gap-1 px-2 py-1 bg-bambu-dark hover:bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-xs text-bambu-gray hover:text-white transition-colors",children:[a.jsx(dr,{className:"w-3 h-3"}),k]},k))}),a.jsx("p",{className:"text-xs text-bambu-gray/60 mt-1",children:"Click to insert at cursor position in body"})]}),a.jsxs("div",{children:[a.jsxs("div",{className:"flex items-center justify-between mb-2",children:[a.jsxs("label",{className:"text-sm font-medium text-bambu-gray flex items-center gap-2",children:[a.jsx(_c,{className:"w-4 h-4"}),"Live Preview"]}),a.jsx("button",{type:"button",onClick:()=>h(!d),className:"text-xs text-bambu-green hover:text-bambu-green-light",children:d?"Hide":"Show"})]}),d&&a.jsx("div",{className:"bg-bambu-dark border border-bambu-dark-tertiary rounded p-3 space-y-2",children:v?a.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-sm",children:[a.jsx(ut,{className:"w-4 h-4 animate-spin"}),"Loading preview..."]}):b?a.jsxs(a.Fragment,{children:[a.jsxs("div",{children:[a.jsx("span",{className:"text-xs text-bambu-gray",children:"Title:"}),a.jsx("div",{className:"text-white font-medium",children:b.title})]}),a.jsxs("div",{children:[a.jsx("span",{className:"text-xs text-bambu-gray",children:"Body:"}),a.jsx("div",{className:"text-white whitespace-pre-wrap text-sm",children:b.body})]})]}):a.jsx("div",{className:"text-bambu-gray text-sm",children:"Enter template content to see preview"})})]})]}),a.jsxs("div",{className:"flex items-center justify-between p-4 border-t border-bambu-dark-tertiary shrink-0",children:[a.jsxs(ke,{type:"button",variant:"ghost",onClick:()=>y.mutate(),disabled:y.isPending,className:"text-orange-400 hover:text-orange-300",children:[y.isPending?a.jsx(ut,{className:"w-4 h-4 animate-spin mr-2"}):a.jsx($h,{className:"w-4 h-4 mr-2"}),"Reset to Default"]}),a.jsxs("div",{className:"flex gap-2",children:[a.jsx(ke,{type:"button",variant:"secondary",onClick:e,children:"Cancel"}),a.jsxs(ke,{onClick:S,disabled:x.isPending||!A,children:[x.isPending?a.jsx(ut,{className:"w-4 h-4 animate-spin mr-2"}):a.jsx(gs,{className:"w-4 h-4 mr-2"}),"Save"]})]})]})]})})}const XYe={print_start:"Print Started",print_complete:"Print Complete",print_failed:"Print Failed",print_stopped:"Print Stopped",print_progress:"Progress",printer_offline:"Printer Offline",printer_error:"Printer Error",filament_low:"Low Filament",maintenance_due:"Maintenance Due",test:"Test"},YYe={print_start:"text-blue-400",print_complete:"text-bambu-green",print_failed:"text-red-400",print_stopped:"text-orange-400",print_progress:"text-yellow-400",printer_offline:"text-gray-400",printer_error:"text-rose-400",filament_low:"text-cyan-400",maintenance_due:"text-purple-400",test:"text-bambu-gray"};function QYe({onClose:t}){const e=un(),{showToast:n}=Hn(),[r,i]=_.useState(7),[s,o]=_.useState(null),[l,c]=_.useState(!1),{data:u}=st({queryKey:["settings"],queryFn:ce.getSettings}),d=u?.time_format||"system",{data:h,isLoading:m,refetch:p,isRefetching:b}=st({queryKey:["notification-logs",r,l],queryFn:()=>ce.getNotificationLogs({days:r,limit:100,success:l?!1:void 0})}),{data:v}=st({queryKey:["notification-log-stats",r],queryFn:()=>ce.getNotificationLogStats(r)}),x=pt({mutationFn:()=>ce.clearNotificationLogs(30),onSuccess:S=>{n(S.message,"success"),e.invalidateQueries({queryKey:["notification-logs"]}),e.invalidateQueries({queryKey:["notification-log-stats"]})},onError:S=>{n(`Failed to clear logs: ${S.message}`,"error")}}),y=S=>{const N=Hi(S);if(!N)return"";const k=new Date().getTime()-N.getTime();return k<6e4?"Just now":k<36e5?`${Math.floor(k/6e4)}m ago`:k<864e5?`${Math.floor(k/36e5)}h ago`:N.toLocaleDateString()+" "+cpe(N,d)};return a.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:a.jsxs("div",{className:"bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg w-full max-w-3xl max-h-[85vh] flex flex-col",children:[a.jsxs("div",{className:"p-4 border-b border-bambu-dark-tertiary flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx(sy,{className:"w-5 h-5 text-bambu-green"}),a.jsx("h2",{className:"text-lg font-semibold text-white",children:"Notification Log"})]}),a.jsx("button",{onClick:t,className:"text-bambu-gray hover:text-white transition-colors",children:"×"})]}),v&&a.jsx("div",{className:"px-4 py-3 border-b border-bambu-dark-tertiary bg-bambu-dark/50",children:a.jsxs("div",{className:"flex items-center gap-6 text-sm",children:[a.jsxs("span",{className:"text-bambu-gray",children:["Last ",r," days: ",a.jsx("span",{className:"text-white font-medium",children:v.total})," notifications"]}),a.jsxs("span",{className:"flex items-center gap-1 text-bambu-green",children:[a.jsx(Nr,{className:"w-4 h-4"}),v.success_count," sent"]}),v.failure_count>0&&a.jsxs("span",{className:"flex items-center gap-1 text-red-400",children:[a.jsx(ta,{className:"w-4 h-4"}),v.failure_count," failed"]})]})}),a.jsxs("div",{className:"px-4 py-3 border-b border-bambu-dark-tertiary flex items-center gap-4",children:[a.jsxs("select",{value:r,onChange:S=>i(Number(S.target.value)),className:"px-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:outline-none focus:ring-1 focus:ring-bambu-green",children:[a.jsx("option",{value:1,children:"Last 24 hours"}),a.jsx("option",{value:7,children:"Last 7 days"}),a.jsx("option",{value:30,children:"Last 30 days"}),a.jsx("option",{value:90,children:"Last 90 days"})]}),a.jsxs("label",{className:"flex items-center gap-2 text-sm text-bambu-gray cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:l,onChange:S=>c(S.target.checked),className:"rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),"Show failed only"]}),a.jsx("div",{className:"flex-1"}),a.jsxs(ke,{size:"sm",variant:"secondary",onClick:()=>p(),disabled:b,children:[b?a.jsx(ut,{className:"w-4 h-4 animate-spin"}):a.jsx(Ir,{className:"w-4 h-4"}),"Refresh"]}),a.jsxs(ke,{size:"sm",variant:"secondary",onClick:()=>x.mutate(),disabled:x.isPending,className:"text-red-400 hover:text-red-300",children:[x.isPending?a.jsx(ut,{className:"w-4 h-4 animate-spin"}):a.jsx(cn,{className:"w-4 h-4"}),"Clear Old"]})]}),a.jsx("div",{className:"flex-1 overflow-y-auto p-4",children:m?a.jsx("div",{className:"flex justify-center py-12",children:a.jsx(ut,{className:"w-6 h-6 text-bambu-green animate-spin"})}):h&&h.length>0?a.jsx("div",{className:"space-y-2",children:h.map(S=>a.jsx(ZYe,{log:S,isExpanded:s===S.id,onToggle:()=>o(s===S.id?null:S.id),formatDate:y,formatFullDate:N=>nb(N,d)},S.id))}):a.jsxs("div",{className:"text-center py-12 text-bambu-gray",children:[a.jsx(sy,{className:"w-12 h-12 mx-auto mb-3 opacity-30"}),a.jsx("p",{className:"text-sm",children:l?"No failed notifications":"No notifications logged"})]})})]})})}function ZYe({log:t,isExpanded:e,onToggle:n,formatDate:r,formatFullDate:i}){return a.jsxs("div",{className:`border rounded-lg overflow-hidden transition-colors ${t.success?"border-bambu-dark-tertiary bg-bambu-dark/30":"border-red-500/30 bg-red-500/5"}`,children:[a.jsxs("button",{className:"w-full px-3 py-2 flex items-center gap-3 text-left hover:bg-bambu-dark/50 transition-colors",onClick:n,children:[t.success?a.jsx(Nr,{className:"w-4 h-4 text-bambu-green shrink-0"}):a.jsx(ta,{className:"w-4 h-4 text-red-400 shrink-0"}),a.jsx("span",{className:`text-xs font-medium ${YYe[t.event_type]||"text-bambu-gray"}`,children:XYe[t.event_type]||t.event_type}),a.jsx("span",{className:"text-sm text-white truncate flex-1",children:t.provider_name||"Unknown Provider"}),t.printer_name&&a.jsx("span",{className:"text-xs text-bambu-gray",children:t.printer_name}),a.jsx("span",{className:"text-xs text-bambu-gray shrink-0",children:r(t.created_at)}),e?a.jsx(Ch,{className:"w-4 h-4 text-bambu-gray shrink-0"}):a.jsx(Sr,{className:"w-4 h-4 text-bambu-gray shrink-0"})]}),e&&a.jsxs("div",{className:"px-3 py-2 border-t border-bambu-dark-tertiary bg-bambu-dark/20 space-y-2",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-xs text-bambu-gray mb-1",children:"Title"}),a.jsx("p",{className:"text-sm text-white",children:t.title})]}),a.jsxs("div",{children:[a.jsx("p",{className:"text-xs text-bambu-gray mb-1",children:"Message"}),a.jsx("p",{className:"text-sm text-white whitespace-pre-wrap",children:t.message})]}),!t.success&&t.error_message&&a.jsxs("div",{children:[a.jsx("p",{className:"text-xs text-red-400 mb-1",children:"Error"}),a.jsx("p",{className:"text-sm text-red-300",children:t.error_message})]}),a.jsxs("div",{className:"flex gap-4 text-xs text-bambu-gray pt-1",children:[a.jsxs("span",{children:["Provider: ",t.provider_type]}),a.jsxs("span",{children:["Time: ",i(t.created_at)]})]})]})]})}function JYe({formData:t,setFormData:e,groups:n,onClose:r,onCreate:i,isCreating:s,isCreateButtonDisabled:o}){const{t:l}=Sn();_.useEffect(()=>{const u=d=>{d.key==="Escape"&&r()};return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[r]);const c=u=>{e({...t,group_ids:t.group_ids.includes(u)?t.group_ids.filter(d=>d!==u):[...t.group_ids,u]})};return a.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",onClick:r,children:a.jsxs(_t,{className:"w-full max-w-md",onClick:u=>u.stopPropagation(),children:[a.jsx(Pn,{children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex flex-col gap-1",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(Kf,{className:"w-5 h-5 text-bambu-green"}),a.jsx("h2",{className:"text-lg font-semibold text-white",children:l("users.modal.createUser")})]}),a.jsx("p",{className:"text-sm text-bambu-gray ml-7",children:l("users.modal.advancedAuthSubtitle")||"with Advanced Authentication"})]}),a.jsx(ke,{variant:"ghost",size:"sm",onClick:r,children:a.jsx(Lt,{className:"w-5 h-5"})})]})}),a.jsxs(Mt,{children:[a.jsxs("div",{className:"space-y-4",children:[a.jsxs("div",{children:[a.jsxs("label",{className:"block text-sm font-medium text-white mb-2",children:[l("users.form.username")," ",a.jsx("span",{className:"text-red-400",children:"*"})]}),a.jsx("input",{type:"text",value:t.username,onChange:u=>e({...t,username:u.target.value}),className:"w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors",placeholder:l("users.form.usernamePlaceholder"),autoComplete:"username",required:!0})]}),a.jsxs("div",{children:[a.jsxs("label",{className:"block text-sm font-medium text-white mb-2",children:[l("users.form.email")||"Email"," ",a.jsx("span",{className:"text-red-400",children:"*"})]}),a.jsx("input",{type:"email",value:t.email,onChange:u=>e({...t,email:u.target.value}),className:"w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors",placeholder:l("users.form.emailPlaceholder")||"user@example.com",required:!0})]}),a.jsx("div",{className:"bg-bambu-dark-secondary/50 border border-bambu-green/20 rounded-lg p-3",children:a.jsx("p",{className:"text-sm text-bambu-gray",children:l("users.form.autoGeneratedPassword")||"A secure password will be automatically generated and emailed to the user."})}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:l("users.form.groups")}),a.jsxs("div",{className:"space-y-2 max-h-40 overflow-y-auto p-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg",children:[n.map(u=>a.jsxs("label",{className:"flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-tertiary cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:t.group_ids.includes(u.id),onChange:()=>c(u.id),className:"w-4 h-4 rounded border-bambu-gray text-bambu-green focus:ring-bambu-green focus:ring-offset-0 bg-bambu-dark"}),a.jsx("span",{className:"text-sm text-white",children:u.name}),u.is_system&&a.jsxs("span",{className:"text-xs text-yellow-400",children:["(",l("users.system"),")"]})]},u.id)),n.length===0&&a.jsx("p",{className:"text-sm text-bambu-gray",children:l("users.noGroupsAvailable")})]})]})]}),a.jsxs("div",{className:"mt-6 flex justify-end gap-3",children:[a.jsx(ke,{variant:"secondary",onClick:r,children:l("users.modal.cancel")}),a.jsx(ke,{onClick:i,disabled:o,children:s?a.jsxs(a.Fragment,{children:[a.jsx(ut,{className:"w-4 h-4 animate-spin"}),l("users.modal.creating")]}):a.jsxs(a.Fragment,{children:[a.jsx(dr,{className:"w-4 h-4"}),l("users.modal.createUser")]})})]})]})]})})}function eQe(){const{t}=Sn(),e=un(),{showToast:n}=Hn(),[r,i]=_.useState(!1),[s,o]=_.useState(""),[l,c]=_.useState("auto"),[u,d]=_.useState(!1),[h,m]=_.useState(!0),[p,b]=_.useState("all"),[v,x]=_.useState(!1),[y,S]=_.useState(!1),{data:N,isLoading:A}=st({queryKey:["spoolman-settings"],queryFn:ce.getSpoolmanSettings}),{data:k,isLoading:C,refetch:E}=st({queryKey:["spoolman-status"],queryFn:ce.getSpoolmanStatus,refetchInterval:3e4}),{data:P}=st({queryKey:["printers"],queryFn:ce.getPrinters});_.useEffect(()=>{N&&(i(N.spoolman_enabled==="true"),o(N.spoolman_url||""),c(N.spoolman_sync_mode||"auto"),d(N.spoolman_disable_weight_sync==="true"),m(N.spoolman_report_partial_usage!=="false"),x(!0))},[N]),_.useEffect(()=>{if(!v||!N)return;if(N.spoolman_enabled==="true"!==r||(N.spoolman_url||"")!==s||(N.spoolman_sync_mode||"auto")!==l||N.spoolman_disable_weight_sync==="true"!==u||N.spoolman_report_partial_usage!=="false"!==h){const Y=setTimeout(()=>{T.mutate()},500);return()=>clearTimeout(Y)}},[r,s,l,u,h,v]);const T=pt({mutationFn:()=>ce.updateSpoolmanSettings({spoolman_enabled:r?"true":"false",spoolman_url:s,spoolman_sync_mode:l,spoolman_disable_weight_sync:u?"true":"false",spoolman_report_partial_usage:h?"true":"false"}),onSuccess:()=>{e.invalidateQueries({queryKey:["spoolman-settings"]}),e.invalidateQueries({queryKey:["spoolman-status"]}),n(t("settings.toast.settingsSaved"))}}),j=pt({mutationFn:ce.connectSpoolman,onSuccess:()=>{E()}}),z=pt({mutationFn:ce.disconnectSpoolman,onSuccess:()=>{E()}}),L=pt({mutationFn:ce.syncAllPrintersAms,onSuccess:G=>{G.success}}),B=pt({mutationFn:G=>ce.syncPrinterAms(G),onSuccess:G=>{G.success}}),R=()=>{p==="all"?L.mutate():B.mutate(p)},$=L.isPending||B.isPending,q=p==="all"?L.data:B.data,I=p==="all"?L.isSuccess:B.isSuccess;return A?a.jsxs(_t,{children:[a.jsx(Pn,{children:a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(ju,{className:"w-5 h-5 text-bambu-green"}),a.jsx("h2",{className:"text-lg font-semibold text-white",children:"Spoolman Integration"})]})}),a.jsx(Mt,{children:a.jsx("div",{className:"flex justify-center py-8",children:a.jsx(ut,{className:"w-6 h-6 text-bambu-green animate-spin"})})})]}):a.jsxs(_t,{children:[a.jsx(Pn,{children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(ju,{className:"w-5 h-5 text-bambu-green"}),a.jsx("h2",{className:"text-lg font-semibold text-white",children:"Spoolman Integration"})]}),T.isPending&&a.jsx(ut,{className:"w-4 h-4 text-bambu-green animate-spin"})]})}),a.jsxs(Mt,{className:"space-y-4",children:[a.jsx("p",{className:"text-sm text-bambu-gray",children:"Connect to Spoolman for filament inventory tracking. AMS data will sync automatically."}),a.jsx("div",{className:"p-3 bg-blue-500/10 border border-blue-500/30 rounded-lg",children:a.jsxs("div",{className:"flex gap-2",children:[a.jsx(ho,{className:"w-4 h-4 text-blue-400 flex-shrink-0 mt-0.5"}),a.jsxs("div",{className:"text-xs text-blue-300",children:[a.jsx("p",{className:"font-medium mb-1",children:"How Sync Works"}),a.jsxs("ul",{className:"list-disc list-inside space-y-0.5 text-blue-300/80",children:[a.jsx("li",{children:"Only official Bambu Lab spools with RFID are synced"}),a.jsx("li",{children:"New spools are auto-created in Spoolman on first sync"}),a.jsx("li",{children:"Non-Bambu Lab spools (third-party, refilled) are skipped"})]}),a.jsx("p",{className:"font-medium mt-2 mb-1",children:"Linking Existing Spools"}),a.jsx("p",{className:"text-blue-300/80",children:'To link existing Spoolman spools to your AMS, hover over an AMS slot and click "Link to Spoolman".'})]})]})}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white",children:"Enable Spoolman"}),a.jsx("p",{className:"text-sm text-bambu-gray",children:"Sync filament data with Spoolman server"})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:r,onChange:G=>i(G.target.checked),className:"sr-only peer"}),a.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Spoolman URL"}),a.jsx("input",{type:"text",placeholder:"http://192.168.1.100:7912",value:s,onChange:G=>o(G.target.value),disabled:!r,className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray/50 focus:border-bambu-green focus:outline-none disabled:opacity-50"}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"URL of your Spoolman server (e.g., http://localhost:7912)"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Sync Mode"}),a.jsxs("select",{value:l,onChange:G=>c(G.target.value),disabled:!r,className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none disabled:opacity-50",children:[a.jsx("option",{value:"auto",children:"Automatic"}),a.jsx("option",{value:"manual",children:"Manual Only"})]}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:l==="auto"?"AMS data syncs automatically when changes are detected":"Only sync when manually triggered"})]}),l==="auto"&&a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white",children:t("spoolman.disableWeightSync")}),a.jsx("p",{className:"text-sm text-bambu-gray",children:t("spoolman.disableWeightSyncDesc")})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:u,onChange:G=>d(G.target.checked),disabled:!r,className:"sr-only peer"}),a.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),u&&a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white",children:t("spoolman.reportPartialUsage")}),a.jsx("p",{className:"text-sm text-bambu-gray",children:t("spoolman.reportPartialUsageDesc")})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:h,onChange:G=>m(G.target.checked),disabled:!r,className:"sr-only peer"}),a.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),r&&a.jsxs("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:[a.jsxs("div",{className:"flex items-center justify-between mb-3",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("span",{className:"text-sm text-bambu-gray",children:"Status:"}),C?a.jsx(ut,{className:"w-4 h-4 text-bambu-gray animate-spin"}):k?.connected?a.jsxs("span",{className:"flex items-center gap-1 text-sm text-green-500",children:[a.jsx(qi,{className:"w-4 h-4"}),"Connected"]}):a.jsxs("span",{className:"flex items-center gap-1 text-sm text-red-500",children:[a.jsx(Lt,{className:"w-4 h-4"}),"Disconnected"]})]}),a.jsx("div",{className:"flex gap-2",children:k?.connected?a.jsxs(ke,{variant:"secondary",size:"sm",onClick:()=>z.mutate(),disabled:z.isPending,children:[z.isPending?a.jsx(ut,{className:"w-4 h-4 animate-spin"}):a.jsx($he,{className:"w-4 h-4"}),"Disconnect"]}):a.jsxs(ke,{size:"sm",onClick:()=>j.mutate(),disabled:j.isPending||!s,children:[j.isPending?a.jsx(ut,{className:"w-4 h-4 animate-spin"}):a.jsx(bc,{className:"w-4 h-4"}),"Connect"]})})]}),j.isError&&a.jsx("div",{className:"mb-3 p-2 bg-red-500/20 border border-red-500/50 rounded text-sm text-red-400",children:j.error.message}),k?.connected&&a.jsxs("div",{className:"space-y-3",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"Sync AMS Data"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Manually sync printer AMS data to Spoolman"})]}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsxs("div",{className:"relative flex-1",children:[a.jsxs("select",{value:p,onChange:G=>b(G.target.value==="all"?"all":Number(G.target.value)),className:"w-full px-3 py-2 pr-8 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none appearance-none cursor-pointer",children:[a.jsx("option",{value:"all",children:"All Printers"}),P?.map(G=>a.jsx("option",{value:G.id,children:G.name},G.id))]}),a.jsx(Sr,{className:"absolute right-2 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),a.jsxs(ke,{variant:"secondary",size:"sm",onClick:R,disabled:$,children:[$?a.jsx(ut,{className:"w-4 h-4 animate-spin"}):a.jsx(Ir,{className:"w-4 h-4"}),"Sync"]})]})]}),I&&q&&a.jsxs("div",{className:"mt-3 space-y-2",children:[a.jsx("div",{className:`p-2 rounded text-sm ${q.success?"bg-green-500/20 border border-green-500/50 text-green-400":"bg-yellow-500/20 border border-yellow-500/50 text-yellow-400"}`,children:q.success?`Synced ${q.synced_count} spool${q.synced_count!==1?"s":""} successfully`:`Synced ${q.synced_count} spool${q.synced_count!==1?"s":""} with ${q.errors.length} error${q.errors.length!==1?"s":""}`}),q.skipped_count>0&&a.jsxs("div",{className:"p-2 bg-amber-500/10 border border-amber-500/30 rounded text-sm",children:[a.jsxs("div",{className:"flex items-center justify-between text-amber-400 mb-1",children:[a.jsxs("div",{className:"flex items-center gap-1.5",children:[a.jsx(kn,{className:"w-3.5 h-3.5"}),a.jsxs("span",{className:"font-medium",children:[q.skipped_count," spool",q.skipped_count!==1?"s":""," skipped"]})]}),q.skipped_count>5&&a.jsx("button",{onClick:()=>S(!y),className:"text-xs text-amber-400 hover:text-amber-300 underline",children:y?"Show less":"Show all"})]}),a.jsxs("ul",{className:"text-xs text-amber-300/80 space-y-0.5",children:[(y?q.skipped:q.skipped.slice(0,5)).map((G,Y)=>a.jsxs("li",{className:"flex items-center gap-2",children:[G.color&&a.jsx("span",{className:"w-3 h-3 rounded-full border border-white/20",style:{backgroundColor:`#${G.color}`}}),a.jsx("span",{children:G.location}),a.jsxs("span",{className:"text-amber-300/60",children:["- ",G.reason]})]},Y)),!y&&q.skipped_count>5&&a.jsxs("li",{className:"text-amber-300/60 italic",children:["...and ",q.skipped_count-5," more"]})]})]}),q.errors.length>0&&a.jsxs("div",{className:"p-2 bg-red-500/10 border border-red-500/30 rounded text-sm",children:[a.jsx("div",{className:"text-red-400 font-medium mb-1",children:"Errors:"}),a.jsx("ul",{className:"text-xs text-red-300/80 space-y-0.5",children:q.errors.map((G,Y)=>a.jsx("li",{children:G},Y))})]})]})]})]})]})}function tQe({link:t,onClose:e}){const n=un(),{mode:r}=Vh(),i=!!t,s=_.useRef(null),[o,l]=_.useState(t?.name||""),[c,u]=_.useState(t?.url||""),[d,h]=_.useState(t?.icon||"link"),[m,p]=_.useState(!!t?.custom_icon),[b,v]=_.useState(t?.custom_icon?ce.getExternalLinkIconUrl(t.id):null),[x,y]=_.useState(null),[S,N]=_.useState(null);_.useEffect(()=>{const z=L=>{L.key==="Escape"&&e()};return window.addEventListener("keydown",z),()=>window.removeEventListener("keydown",z)},[e]);const A=pt({mutationFn:async z=>{const L=await ce.createExternalLink(z);return x?await ce.uploadExternalLinkIcon(L.id,x):L},onSuccess:()=>{n.invalidateQueries({queryKey:["external-links"]}),e()},onError:z=>{N(z.message)}}),k=pt({mutationFn:async z=>{let L=await ce.updateExternalLink(t.id,z);return x?L=await ce.uploadExternalLinkIcon(t.id,x):!m&&t?.custom_icon&&(L=await ce.deleteExternalLinkIcon(t.id)),L},onSuccess:()=>{n.invalidateQueries({queryKey:["external-links"]}),e()},onError:z=>{N(z.message)}}),C=z=>{const L=z.target.files?.[0];if(L){if(!["image/png","image/jpeg","image/gif","image/svg+xml","image/webp","image/x-icon"].includes(L.type)){N("Please select a valid image file (PNG, JPG, GIF, SVG, WebP, or ICO)");return}if(L.size>1024*1024){N("Image file must be less than 1MB");return}y(L),p(!0);const R=new FileReader;R.onload=$=>{v($.target?.result)},R.readAsDataURL(L)}},E=()=>{y(null),v(null),p(!1),s.current&&(s.current.value="")},P=z=>{if(z.preventDefault(),N(null),!o.trim()){N("Name is required");return}if(!c.trim()){N("URL is required");return}if(!c.startsWith("http://")&&!c.startsWith("https://")){N("URL must start with http:// or https://");return}const L={name:o.trim(),url:c.trim(),icon:d};i?k.mutate(L):A.mutate(L)},T=A.isPending||k.isPending,j=qM(d);return a.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",onClick:e,children:a.jsxs("div",{className:"bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-md",onClick:z=>z.stopPropagation(),children:[a.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary",children:[a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx("div",{className:"p-2 rounded-full bg-bambu-green/20 text-bambu-green",children:m&&b?a.jsx("img",{src:b,alt:"",className:`w-5 h-5 rounded ${r==="dark"?"invert opacity-[0.65]":"opacity-60"}`}):a.jsx(j,{className:"w-5 h-5"})}),a.jsx("h2",{className:"text-lg font-semibold text-white",children:i?"Edit Link":"Add External Link"})]}),a.jsx("button",{onClick:e,className:"text-bambu-gray hover:text-white transition-colors",children:a.jsx(Lt,{className:"w-5 h-5"})})]}),a.jsxs("form",{onSubmit:P,className:"p-6 space-y-4",children:[S&&a.jsx("div",{className:"p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400",children:S}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Name *"}),a.jsx("input",{type:"text",value:o,onChange:z=>l(z.target.value),placeholder:"My Link",maxLength:50,className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"URL *"}),a.jsx("input",{type:"text",value:c,onChange:z=>u(z.target.value),placeholder:"https://example.com",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),a.jsxs("div",{className:"space-y-3",children:[a.jsx("label",{className:"block text-sm text-bambu-gray",children:"Icon"}),a.jsxs("div",{className:"p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary",children:[a.jsxs("div",{className:"flex items-center justify-between mb-2",children:[a.jsx("span",{className:"text-sm text-white",children:"Custom Icon"}),a.jsx("input",{ref:s,type:"file",accept:"image/png,image/jpeg,image/gif,image/svg+xml,image/webp,image/x-icon",className:"hidden",onChange:C}),m&&b?a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("img",{src:b,alt:"Custom icon",className:`w-8 h-8 rounded border border-bambu-dark-tertiary ${r==="dark"?"invert opacity-[0.65]":"opacity-60"}`}),a.jsx("button",{type:"button",onClick:E,className:"p-1 text-red-400 hover:text-red-300 transition-colors",title:"Remove custom icon",children:a.jsx(cn,{className:"w-4 h-4"})})]}):a.jsxs(ke,{type:"button",variant:"secondary",size:"sm",onClick:()=>s.current?.click(),children:[a.jsx($a,{className:"w-4 h-4"}),"Upload"]})]}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"PNG, JPG, GIF, SVG, WebP, or ICO. Max 1MB."})]}),!m&&a.jsxs("div",{children:[a.jsx("span",{className:"text-sm text-bambu-gray block mb-2",children:"Or choose a preset icon"}),a.jsx(Yme,{value:d,onChange:h})]})]}),a.jsxs("div",{className:"flex gap-3 pt-2",children:[a.jsx(ke,{type:"button",variant:"secondary",onClick:e,className:"flex-1",children:"Cancel"}),a.jsxs(ke,{type:"submit",disabled:T,className:"flex-1",children:[T?a.jsx(ut,{className:"w-4 h-4 animate-spin"}):a.jsx(gs,{className:"w-4 h-4"}),i?"Save":"Add"]})]})]})]})})}function nQe(){const t=un(),[e,n]=_.useState(!1),[r,i]=_.useState(null),[s,o]=_.useState(null),[l,c]=_.useState(null),{data:u,isLoading:d}=st({queryKey:["external-links"],queryFn:ce.getExternalLinks}),h=pt({mutationFn:S=>ce.deleteExternalLink(S),onSuccess:()=>{t.invalidateQueries({queryKey:["external-links"]})}}),m=pt({mutationFn:S=>ce.reorderExternalLinks(S),onSuccess:()=>{t.invalidateQueries({queryKey:["external-links"]})}}),p=(S,N)=>{c(N),S.dataTransfer.effectAllowed="move"},b=S=>{S.preventDefault(),S.dataTransfer.dropEffect="move"},v=(S,N)=>{if(S.preventDefault(),l===null||l===N||!u)return;const A=u.map(P=>P.id),k=A.indexOf(l),C=A.indexOf(N);if(k===-1||C===-1)return;const E=[...A];E.splice(k,1),E.splice(C,0,l),m.mutate(E),c(null)},x=S=>{o(S)},y=()=>{s&&(h.mutate(s.id),o(null))};return a.jsxs(a.Fragment,{children:[a.jsxs(_t,{children:[a.jsx(Pn,{children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(bc,{className:"w-5 h-5 text-bambu-green"}),a.jsx("h2",{className:"text-lg font-semibold text-white",children:"Sidebar Links"})]}),a.jsxs(ke,{size:"sm",onClick:()=>n(!0),children:[a.jsx(dr,{className:"w-4 h-4"}),"Add Link"]})]})}),a.jsxs(Mt,{children:[a.jsx("p",{className:"text-sm text-bambu-gray mb-4",children:"Add external links to the sidebar navigation. Drag to reorder."}),d?a.jsx("div",{className:"flex justify-center py-8",children:a.jsx(ut,{className:"w-6 h-6 text-bambu-green animate-spin"})}):u&&u.length>0?a.jsx("div",{className:"space-y-2",children:u.map(S=>{const N=qM(S.icon);return a.jsxs("div",{draggable:!0,onDragStart:A=>p(A,S.id),onDragOver:b,onDrop:A=>v(A,S.id),className:`flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary transition-colors ${l===S.id?"opacity-50":""}`,children:[a.jsx(eb,{className:"w-6 h-6 md:w-4 md:h-4 text-bambu-gray cursor-grab flex-shrink-0"}),a.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark-tertiary text-bambu-gray",children:a.jsx(N,{className:"w-4 h-4"})}),a.jsxs("div",{className:"flex-1 min-w-0",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("span",{className:"text-white font-medium truncate",children:S.name}),a.jsx(Xr,{className:"w-3 h-3 text-bambu-gray flex-shrink-0"})]}),a.jsx("span",{className:"text-sm text-bambu-gray truncate block",children:S.url})]}),a.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[a.jsx("button",{onClick:()=>i(S),className:"p-2 rounded-lg hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white transition-colors",title:"Edit",children:a.jsx(na,{className:"w-4 h-4"})}),a.jsx("button",{onClick:()=>x(S),disabled:h.isPending,className:"p-2 rounded-lg hover:bg-red-500/20 text-bambu-gray hover:text-red-400 transition-colors disabled:opacity-50",title:"Delete",children:a.jsx(cn,{className:"w-4 h-4"})})]})]},S.id)})}):a.jsxs("div",{className:"text-center py-8 text-bambu-gray",children:[a.jsx(bc,{className:"w-8 h-8 mx-auto mb-2 opacity-50"}),a.jsx("p",{children:"No external links configured"}),a.jsx("p",{className:"text-sm",children:'Click "Add Link" to add one'})]})]})]}),(e||r)&&a.jsx(tQe,{link:r,onClose:()=>{n(!1),i(null)}}),s&&a.jsx(er,{title:"Delete Link",message:`Are you sure you want to delete "${s.name}"? This action cannot be undone.`,confirmText:"Delete",cancelText:"Cancel",variant:"danger",onConfirm:y,onCancel:()=>o(null)})]})}function rQe(){const{t}=Sn(),e=un(),{showToast:n}=Hn(),[r,i]=_.useState(!1),[s,o]=_.useState(""),[l,c]=_.useState("immediate"),[u,d]=_.useState("3DPrinter-X1-Carbon"),[h,m]=_.useState(null),[p,b]=_.useState(""),[v,x]=_.useState(!1),[y,S]=_.useState(null),{data:N,isLoading:A}=st({queryKey:["virtual-printer-settings"],queryFn:D1.getSettings,refetchInterval:1e4}),{data:k}=st({queryKey:["virtual-printer-models"],queryFn:D1.getModels}),{data:C}=st({queryKey:["printers"],queryFn:ce.getPrinters}),{data:E}=st({queryKey:["network-interfaces"],queryFn:()=>ce.getNetworkInterfaces().then(I=>I.interfaces),enabled:l==="proxy"});_.useEffect(()=>{if(N){i(N.enabled);let I=N.mode==="queue"?"review":N.mode;I!=="immediate"&&I!=="review"&&I!=="print_queue"&&I!=="proxy"&&(I="immediate"),c(I),d(N.model),m(N.target_printer_id),b(N.remote_interface_ip||"")}},[N]);const P=pt({mutationFn:I=>D1.updateSettings(I),onSuccess:()=>{e.invalidateQueries({queryKey:["virtual-printer-settings"]}),n(t("virtualPrinter.toast.updated")),S(null)},onError:I=>{if(n(I.message||t("virtualPrinter.toast.failedToUpdate"),"error"),N){i(N.enabled);const G=N.mode==="queue"?"review":N.mode;c(["immediate","review","print_queue","proxy"].includes(G)?G:"immediate"),d(N.model),m(N.target_printer_id)}S(null)}}),T=()=>{const I=!r;if(I){if(l==="proxy"){if(!h){n(t("virtualPrinter.toast.targetPrinterRequired"),"error");return}}else if(!s&&!N?.access_code_set){n(t("virtualPrinter.toast.accessCodeRequired"),"error");return}}i(I),S("toggle"),P.mutate({enabled:I,access_code:l!=="proxy"&&s||void 0,mode:l,target_printer_id:l==="proxy"?h??void 0:void 0})},j=()=>{if(!s){n(t("virtualPrinter.toast.accessCodeEmpty"),"error");return}if(s.length!==8){n(t("virtualPrinter.toast.accessCodeLength"),"error");return}S("accessCode"),P.mutate({access_code:s}),o("")},z=I=>{c(I),S("mode"),P.mutate({mode:I})},L=I=>{m(I),S("targetPrinter"),P.mutate({target_printer_id:I})},B=I=>{d(I),S("model"),P.mutate({model:I})},R=I=>{b(I),S("remoteInterface"),P.mutate({remote_interface_ip:I})};if(A)return a.jsx(_t,{children:a.jsx(Mt,{className:"py-8 flex justify-center",children:a.jsx(ut,{className:"w-6 h-6 animate-spin text-bambu-green"})})});const $=N?.status,q=$?.running||!1;return a.jsxs("div",{className:"flex flex-col lg:flex-row gap-6 lg:gap-8",children:[a.jsx("div",{className:"space-y-6 lg:w-[480px] lg:flex-shrink-0",children:a.jsxs(_t,{children:[a.jsx(Pn,{children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(Or,{className:"w-5 h-5 text-bambu-green"}),a.jsx("h2",{className:"text-lg font-semibold text-white",children:t("virtualPrinter.title")})]}),$&&a.jsxs("div",{className:`flex items-center gap-2 text-sm ${q?"text-green-400":"text-bambu-gray"}`,children:[a.jsx("span",{className:`w-2 h-2 rounded-full ${q?"bg-green-400 animate-pulse":"bg-gray-500"}`}),t(q?"virtualPrinter.running":"virtualPrinter.stopped")]})]})}),a.jsxs(Mt,{className:"space-y-4",children:[a.jsx("p",{className:"text-sm text-bambu-gray",children:t(l==="proxy"?"virtualPrinter.description.proxy":"virtualPrinter.description.default")}),a.jsxs("div",{className:"flex items-center justify-between py-3 border-t border-bambu-dark-tertiary",children:[a.jsxs("div",{children:[a.jsx("div",{className:"text-white font-medium",children:t("virtualPrinter.enable.title")}),a.jsx("div",{className:"text-sm text-bambu-gray",children:q?l==="proxy"?t("virtualPrinter.enable.proxyingTo",{name:C?.find(I=>I.id===h)?.name||"printer"}):t("virtualPrinter.enable.visibleInSlicer"):t("virtualPrinter.enable.notActive")})]}),a.jsx("button",{onClick:T,disabled:y==="toggle",className:`relative w-12 h-6 rounded-full transition-colors ${r?"bg-bambu-green":"bg-bambu-dark-tertiary"} ${y==="toggle"?"opacity-50":""}`,children:a.jsx("span",{className:`absolute top-1 left-1 w-4 h-4 bg-white rounded-full transition-transform ${r?"translate-x-6":""}`})})]}),l!=="proxy"&&a.jsxs("div",{className:"py-3 border-t border-bambu-dark-tertiary",children:[a.jsx("div",{className:"text-white font-medium mb-2",children:t("virtualPrinter.model.title")}),a.jsx("div",{className:"text-sm text-bambu-gray mb-3",children:t("virtualPrinter.model.description")}),a.jsxs("div",{className:"relative",children:[a.jsx("select",{value:u,onChange:I=>B(I.target.value),disabled:y==="model",className:"w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-2 text-white appearance-none cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed pr-10",children:k?.models&&Object.entries(k.models).sort(([,I],[,G])=>I.localeCompare(G)).map(([I,G])=>a.jsx("option",{value:I,children:G},I))}),a.jsx(Sr,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),r&&q&&a.jsxs("p",{className:"text-xs text-bambu-gray mt-2",children:[a.jsx(ho,{className:"w-3 h-3 inline mr-1"}),t("virtualPrinter.model.restartWarning")]})]}),l!=="proxy"&&a.jsxs("div",{className:"py-3 border-t border-bambu-dark-tertiary",children:[a.jsx("div",{className:"text-white font-medium mb-2",children:t("virtualPrinter.accessCode.title")}),a.jsx("div",{className:"text-sm text-bambu-gray mb-3",children:N?.access_code_set?a.jsxs("span",{className:"flex items-center gap-1 text-green-400",children:[a.jsx(qi,{className:"w-4 h-4"}),t("virtualPrinter.accessCode.isSet")]}):a.jsxs("span",{className:"flex items-center gap-1 text-yellow-400",children:[a.jsx(kn,{className:"w-4 h-4"}),t("virtualPrinter.accessCode.notSet")]})}),a.jsxs("div",{className:"flex gap-2",children:[a.jsxs("div",{className:"relative flex-1",children:[a.jsx("input",{type:v?"text":"password",value:s,onChange:I=>o(I.target.value),placeholder:N?.access_code_set?t("virtualPrinter.accessCode.placeholderChange"):t("virtualPrinter.accessCode.placeholder"),maxLength:8,className:"w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-2 text-white placeholder-bambu-gray pr-10 font-mono"}),a.jsx("button",{onClick:()=>x(!v),className:"absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white",children:v?a.jsx(RM,{className:"w-4 h-4"}):a.jsx(_c,{className:"w-4 h-4"})})]}),a.jsx(ke,{onClick:j,disabled:!s||y==="accessCode",variant:"primary",children:y==="accessCode"?a.jsx(ut,{className:"w-4 h-4 animate-spin"}):t("common.save")})]}),a.jsxs("p",{className:"text-xs text-bambu-gray mt-2",children:[t("virtualPrinter.accessCode.hint"),s&&a.jsxs("span",{className:s.length===8?"text-green-400":"text-yellow-400",children:[" ",t("virtualPrinter.accessCode.charCount",{count:s.length})]})]})]}),l==="proxy"&&a.jsxs("div",{className:"py-3 border-t border-bambu-dark-tertiary",children:[a.jsx("div",{className:"text-white font-medium mb-2",children:t("virtualPrinter.targetPrinter.title")}),a.jsx("div",{className:"text-sm text-bambu-gray mb-3",children:h?a.jsxs("span",{className:"flex items-center gap-1 text-green-400",children:[a.jsx(qi,{className:"w-4 h-4"}),t("virtualPrinter.targetPrinter.configured")]}):a.jsxs("span",{className:"flex items-center gap-1 text-yellow-400",children:[a.jsx(kn,{className:"w-4 h-4"}),t("virtualPrinter.targetPrinter.notConfigured")]})}),a.jsxs("div",{className:"relative",children:[a.jsxs("select",{value:h??"",onChange:I=>{const G=parseInt(I.target.value,10);isNaN(G)||L(G)},disabled:y==="targetPrinter",className:"w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-2 text-white appearance-none cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed pr-10",children:[a.jsx("option",{value:"",children:t("virtualPrinter.targetPrinter.placeholder")}),C?.map(I=>a.jsxs("option",{value:I.id,children:[I.name," (",I.ip_address,")"]},I.id))]}),a.jsx(Sr,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),a.jsx("p",{className:"text-xs text-bambu-gray mt-2",children:t("virtualPrinter.targetPrinter.hint")}),!C?.length&&a.jsxs("p",{className:"text-xs text-yellow-400 mt-2",children:[a.jsx(kn,{className:"w-3 h-3 inline mr-1"}),t("virtualPrinter.targetPrinter.noPrinters")]})]}),l==="proxy"&&a.jsxs("div",{className:"py-3 border-t border-bambu-dark-tertiary",children:[a.jsx("div",{className:"text-white font-medium mb-2",children:t("virtualPrinter.remoteInterface.title")}),a.jsx("div",{className:"text-sm text-bambu-gray mb-3",children:p?a.jsxs("span",{className:"flex items-center gap-1 text-green-400",children:[a.jsx(qi,{className:"w-4 h-4"}),t("virtualPrinter.remoteInterface.configured")]}):a.jsxs("span",{className:"flex items-center gap-1 text-bambu-gray",children:[a.jsx(ho,{className:"w-4 h-4"}),t("virtualPrinter.remoteInterface.optional")]})}),a.jsxs("div",{className:"relative",children:[a.jsxs("select",{value:p,onChange:I=>R(I.target.value),disabled:y==="remoteInterface",className:"w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-2 text-white appearance-none cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed pr-10",children:[a.jsx("option",{value:"",children:t("virtualPrinter.remoteInterface.placeholder")}),E?.map(I=>a.jsxs("option",{value:I.ip,children:[I.name," (",I.ip,") - ",I.subnet]},I.ip))]}),a.jsx(Sr,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),a.jsx("p",{className:"text-xs text-bambu-gray mt-2",children:t("virtualPrinter.remoteInterface.hint")})]}),a.jsxs("div",{className:"py-3 border-t border-bambu-dark-tertiary",children:[a.jsx("div",{className:"text-white font-medium mb-2",children:t("virtualPrinter.mode.title")}),a.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[a.jsxs("button",{onClick:()=>z("immediate"),disabled:y==="mode",className:`p-3 rounded-lg border text-left transition-colors ${l==="immediate"?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary hover:border-bambu-gray"}`,children:[a.jsx("div",{className:"text-white font-medium",children:t("virtualPrinter.mode.archive")}),a.jsx("div",{className:"text-xs text-bambu-gray",children:t("virtualPrinter.mode.archiveDesc")})]}),a.jsxs("button",{onClick:()=>z("review"),disabled:y==="mode",className:`p-3 rounded-lg border text-left transition-colors ${l==="review"?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary hover:border-bambu-gray"}`,children:[a.jsx("div",{className:"text-white font-medium",children:t("virtualPrinter.mode.review")}),a.jsx("div",{className:"text-xs text-bambu-gray",children:t("virtualPrinter.mode.reviewDesc")})]}),a.jsxs("button",{onClick:()=>z("print_queue"),disabled:y==="mode",className:`p-3 rounded-lg border text-left transition-colors ${l==="print_queue"?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary hover:border-bambu-gray"}`,children:[a.jsx("div",{className:"text-white font-medium",children:t("virtualPrinter.mode.queue")}),a.jsx("div",{className:"text-xs text-bambu-gray",children:t("virtualPrinter.mode.queueDesc")})]}),a.jsxs("button",{onClick:()=>z("proxy"),disabled:y==="mode",className:`p-3 rounded-lg border text-left transition-colors ${l==="proxy"?"border-blue-500 bg-blue-500/10":"border-bambu-dark-tertiary hover:border-bambu-gray"}`,children:[a.jsxs("div",{className:"flex items-center gap-1.5 text-white font-medium",children:[a.jsx(hB,{className:"w-4 h-4"}),t("virtualPrinter.mode.proxy")]}),a.jsx("div",{className:"text-xs text-bambu-gray",children:t("virtualPrinter.mode.proxyDesc")})]})]})]})]})]})}),a.jsxs("div",{className:"space-y-6 lg:w-[480px] lg:flex-shrink-0",children:[a.jsx(_t,{className:"border-l-4 border-l-yellow-500",children:a.jsx(Mt,{className:"py-4",children:a.jsxs("div",{className:"flex items-start gap-3",children:[a.jsx(kn,{className:"w-5 h-5 text-yellow-500 flex-shrink-0 mt-0.5"}),a.jsxs("div",{className:"text-sm",children:[a.jsx("p",{className:"text-white font-medium mb-2",children:t("virtualPrinter.setupRequired.title")}),a.jsx("p",{className:"text-bambu-gray mb-3",children:t("virtualPrinter.setupRequired.description")}),a.jsxs("a",{href:"https://wiki.bambuddy.cool/features/virtual-printer/",target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-2 px-4 py-2 bg-yellow-500/20 border border-yellow-500/50 rounded-md text-yellow-400 hover:bg-yellow-500/30 transition-colors",children:[a.jsx(Xr,{className:"w-4 h-4"}),t("virtualPrinter.setupRequired.readGuide")]})]})]})})}),a.jsx(_t,{children:a.jsx(Mt,{className:"py-4",children:a.jsxs("div",{className:"flex items-start gap-3",children:[a.jsx(ho,{className:"w-5 h-5 text-blue-400 flex-shrink-0 mt-0.5"}),a.jsxs("div",{className:"text-sm text-bambu-gray",children:[a.jsx("p",{className:"mb-2",children:a.jsxs("strong",{className:"text-white",children:[t(l==="proxy"?"virtualPrinter.howItWorks.titleProxy":"virtualPrinter.howItWorks.title"),":"]})}),l==="proxy"?a.jsxs("ol",{className:"list-decimal list-inside space-y-1",children:[a.jsx("li",{children:t("virtualPrinter.howItWorks.proxyStep1")}),a.jsx("li",{children:t("virtualPrinter.howItWorks.proxyStep2")}),a.jsx("li",{children:t("virtualPrinter.howItWorks.proxyStep3")}),a.jsx("li",{children:t("virtualPrinter.howItWorks.proxyStep4")}),a.jsx("li",{children:t("virtualPrinter.howItWorks.proxyStep5")})]}):a.jsxs("ol",{className:"list-decimal list-inside space-y-1",children:[a.jsx("li",{children:t("virtualPrinter.howItWorks.step1")}),a.jsx("li",{children:t("virtualPrinter.howItWorks.step2")}),a.jsx("li",{children:t("virtualPrinter.howItWorks.step3")}),a.jsx("li",{children:t("virtualPrinter.howItWorks.step4")}),a.jsx("li",{children:t("virtualPrinter.howItWorks.step5")}),a.jsx("li",{children:t("virtualPrinter.howItWorks.step6")})]})]})]})})}),$&&q&&a.jsxs(_t,{children:[a.jsx(Pn,{children:a.jsx("h3",{className:"text-md font-semibold text-white",children:t("virtualPrinter.status.title")})}),a.jsx(Mt,{children:$.mode==="proxy"&&$.proxy?a.jsxs("div",{className:"grid grid-cols-2 gap-4 text-sm",children:[a.jsxs("div",{children:[a.jsx("div",{className:"text-bambu-gray",children:t("virtualPrinter.status.targetPrinter")}),a.jsx("div",{className:"text-white",children:C?.find(I=>I.id===h)?.name||$.proxy.target_host}),a.jsx("div",{className:"text-xs text-bambu-gray font-mono",children:$.proxy.target_host})]}),a.jsxs("div",{children:[a.jsx("div",{className:"text-bambu-gray",children:t("virtualPrinter.status.mode")}),a.jsxs("div",{className:"text-white flex items-center gap-1.5",children:[a.jsx(hB,{className:"w-4 h-4"}),t("virtualPrinter.mode.proxy")]})]}),a.jsxs("div",{children:[a.jsx("div",{className:"text-bambu-gray",children:t("virtualPrinter.status.ftpPort")}),a.jsx("div",{className:"text-white font-mono",children:$.proxy.ftp_port})]}),a.jsxs("div",{children:[a.jsx("div",{className:"text-bambu-gray",children:t("virtualPrinter.status.mqttPort")}),a.jsx("div",{className:"text-white font-mono",children:$.proxy.mqtt_port})]}),a.jsxs("div",{children:[a.jsx("div",{className:"text-bambu-gray",children:t("virtualPrinter.status.ftpConnections")}),a.jsx("div",{className:"text-white",children:$.proxy.ftp_connections??0})]}),a.jsxs("div",{children:[a.jsx("div",{className:"text-bambu-gray",children:t("virtualPrinter.status.mqttConnections")}),a.jsx("div",{className:"text-white",children:$.proxy.mqtt_connections??0})]})]}):a.jsxs("div",{className:"grid grid-cols-2 gap-4 text-sm",children:[a.jsxs("div",{children:[a.jsx("div",{className:"text-bambu-gray",children:t("virtualPrinter.status.printerName")}),a.jsx("div",{className:"text-white",children:$.name})]}),a.jsxs("div",{children:[a.jsx("div",{className:"text-bambu-gray",children:t("virtualPrinter.status.model")}),a.jsx("div",{className:"text-white",children:$.model_name||$.model})]}),a.jsxs("div",{children:[a.jsx("div",{className:"text-bambu-gray",children:t("virtualPrinter.status.serialNumber")}),a.jsx("div",{className:"text-white font-mono",children:$.serial})]}),a.jsxs("div",{children:[a.jsx("div",{className:"text-bambu-gray",children:t("virtualPrinter.status.mode")}),a.jsx("div",{className:"text-white capitalize",children:$.mode})]}),a.jsxs("div",{children:[a.jsx("div",{className:"text-bambu-gray",children:t("virtualPrinter.status.pendingFiles")}),a.jsx("div",{className:"text-white",children:$.pending_files})]})]})})]})]})]})}function RW({status:t}){if(!t)return null;const e={success:"bg-green-500/20 text-green-400",failed:"bg-red-500/20 text-red-400",skipped:"bg-yellow-500/20 text-yellow-400",running:"bg-blue-500/20 text-blue-400"},n={success:a.jsx(Nr,{className:"w-3 h-3"}),failed:a.jsx(ta,{className:"w-3 h-3"}),skipped:a.jsx(uO,{className:"w-3 h-3"}),running:a.jsx(ut,{className:"w-3 h-3 animate-spin"})};return a.jsxs("span",{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded text-xs font-medium ${e[t]||"bg-gray-500/20 text-gray-400"}`,children:[n[t],t.charAt(0).toUpperCase()+t.slice(1)]})}function iQe(t){return t?new Date(t).toLocaleString():"-"}function OW(t){if(!t)return"-";const e=new Date(t),n=new Date,r=e.getTime()-n.getTime(),i=Math.round(r/6e4);if(i<0){const s=Math.abs(i);if(s<60)return`${s}m ago`;const o=Math.floor(s/60);return o<24?`${o}h ago`:`${Math.floor(o/24)}d ago`}else{if(i<60)return`in ${i}m`;const s=Math.floor(i/60);return s<24?`in ${s}h`:`in ${Math.floor(s/24)}d`}}function aQe(){const t=un(),{showToast:e}=Hn(),{t:n}=Sn(),[r,i]=_.useState(""),[s,o]=_.useState(""),[l,c]=_.useState("main"),[u,d]=_.useState(!1),[h,m]=_.useState("daily"),[p,b]=_.useState(!0),[v,x]=_.useState(!0),[y,S]=_.useState(!1),[N,A]=_.useState(!0),[k,C]=_.useState(!1),[E,P]=_.useState(!1),[T,j]=_.useState(""),[z,L]=_.useState(!1),[B,R]=_.useState(null),[$,q]=_.useState(null),I=_.useRef(null);_.useEffect(()=>{if(k||E){const U=O=>(O.preventDefault(),O.returnValue="A backup operation is in progress. Are you sure you want to leave?",O.returnValue);return window.addEventListener("beforeunload",U),()=>window.removeEventListener("beforeunload",U)}},[k,E]);const[G,Y]=_.useState(!1),[re,H]=_.useState(null),K=_.useRef(null),ne=_.useRef(!1),{data:ie,isLoading:be}=st({queryKey:["github-backup-config"],queryFn:ce.getGitHubBackupConfig}),{data:pe}=st({queryKey:["github-backup-status"],queryFn:ce.getGitHubBackupStatus,refetchInterval:ee=>ee.state.data?.is_running?500:1e4}),{data:de}=st({queryKey:["github-backup-logs"],queryFn:()=>ce.getGitHubBackupLogs(20)}),{data:Ce}=st({queryKey:["cloud-status"],queryFn:ce.getCloudStatus}),{data:ae}=st({queryKey:["printers"],queryFn:ce.getPrinters}),Ae=iO({queries:(ae??[]).map(ee=>({queryKey:["printerStatus",ee.id],queryFn:()=>ce.getPrinterStatus(ee.id),staleTime:1e4,refetchInterval:3e4}))}),Le=(ae??[]).map((ee,U)=>({printer:ee,connected:Ae[U]?.data?.connected??!1})),fe=Le.length,Xe=Le.filter(ee=>ee.connected).length,W=fe>0&&Xe===0,Q=Xe>0&&Xe{ie&&(i(ie.repository_url),c(ie.branch),d(ie.schedule_enabled),m(ie.schedule_type),b(ie.backup_kprofiles),x(ie.backup_cloud_profiles),S(ie.backup_settings),A(ie.enabled),o(""),setTimeout(()=>{ne.current=!0},100))},[ie]);const me=_.useCallback(async(ee=!1)=>{if(ie?.has_token)try{ee&&s?(await ce.saveGitHubBackupConfig({repository_url:r,access_token:s,branch:l,schedule_enabled:u,schedule_type:h,backup_kprofiles:p,backup_cloud_profiles:v,backup_settings:y,enabled:N}),o(""),e("Token updated")):(await ce.updateGitHubBackupConfig({repository_url:r,branch:l,schedule_enabled:u,schedule_type:h,backup_kprofiles:p,backup_cloud_profiles:v,backup_settings:y,enabled:N}),e("Settings saved")),t.invalidateQueries({queryKey:["github-backup-config"]}),t.invalidateQueries({queryKey:["github-backup-status"]})}catch(U){e(`Failed to save: ${U.message}`,"error")}},[ie?.has_token,r,s,l,u,h,p,v,y,N,t,e]);_.useEffect(()=>{if(!(!ne.current||!ie?.has_token))return K.current&&clearTimeout(K.current),K.current=setTimeout(()=>{me(!1)},500),()=>{K.current&&clearTimeout(K.current)}},[r,l,u,h,p,v,y,N,me,ie?.has_token]),_.useEffect(()=>{if(!(!ne.current||!ie?.has_token||!s))return K.current&&clearTimeout(K.current),K.current=setTimeout(()=>{me(!0)},1e3),()=>{K.current&&clearTimeout(K.current)}},[s,me,ie?.has_token]);const X=pt({mutationFn:ee=>ce.saveGitHubBackupConfig(ee),onSuccess:()=>{t.invalidateQueries({queryKey:["github-backup-config"]}),t.invalidateQueries({queryKey:["github-backup-status"]}),e("GitHub backup enabled"),o(""),ne.current=!0},onError:ee=>{e(`Failed to save: ${ee.message}`,"error")}}),te=pt({mutationFn:ce.triggerGitHubBackup,onSuccess:ee=>{t.invalidateQueries({queryKey:["github-backup-status"]}),t.invalidateQueries({queryKey:["github-backup-logs"]}),ee.success?ee.files_changed>0?e(`Backup complete - ${ee.files_changed} files updated`):e("Backup skipped - no changes"):e(`Backup failed: ${ee.message}`,"error")},onError:ee=>{e(`Backup failed: ${ee.message}`,"error")}}),V=pt({mutationFn:()=>ce.clearGitHubBackupLogs(0),onSuccess:ee=>{t.invalidateQueries({queryKey:["github-backup-logs"]}),e(`Cleared ${ee.deleted} logs`)},onError:ee=>{e(`Failed to clear logs: ${ee.message}`,"error")}}),ge=async()=>{Y(!0),H(null);try{let ee;if(s){if(!r){e("Enter repository URL","error"),Y(!1);return}ee=await ce.testGitHubConnection(r,s)}else if(ie?.has_token)ee=await ce.testGitHubStoredConnection();else{e("Enter repository URL and access token","error"),Y(!1);return}H({success:ee.success,message:ee.message})}catch(ee){H({success:!1,message:ee.message})}finally{Y(!1)}},Se=()=>{if(!r){e("Repository URL is required","error");return}if(!s){e("Access token is required","error");return}X.mutate({repository_url:r,access_token:s,branch:l,schedule_enabled:u,schedule_type:h,backup_kprofiles:p,backup_cloud_profiles:v,backup_settings:y,enabled:N})};return be?a.jsx("div",{className:"flex items-center justify-center py-12",children:a.jsx(ut,{className:"w-8 h-8 animate-spin text-bambu-green"})}):a.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[a.jsxs("div",{className:"space-y-6",children:[a.jsxs(_t,{children:[a.jsx(Pn,{children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(BP,{className:"w-5 h-5 text-gray-400"}),a.jsx("h2",{className:"text-lg font-semibold text-white",children:"GitHub Backup"})]}),ie&&Ce?.is_authenticated&&a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("span",{className:"text-sm text-bambu-gray",children:"Enabled"}),a.jsx($n,{checked:N,onChange:A})]})]})}),a.jsx(Mt,{className:"space-y-4",children:Ce?.is_authenticated?a.jsxs(a.Fragment,{children:[a.jsx("p",{className:"text-sm text-bambu-gray",children:"Automatically sync your profiles to a private GitHub repository for backup and version history."}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Repository URL"}),a.jsx("input",{type:"text",value:r,onChange:ee=>{i(ee.target.value),H(null)},placeholder:"https://github.com/username/bambuddy-backup",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),a.jsxs("div",{children:[a.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:["Personal Access Token ",ie?.has_token&&a.jsx("span",{className:"text-green-400",children:"(saved)"})]}),a.jsx("input",{type:"password",value:s,onChange:ee=>{o(ee.target.value),H(null)},placeholder:ie?.has_token?"Enter new token to update":"ghp_xxxxxxxxxxxx",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Fine-grained token with Contents read/write permission"})]}),a.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Branch"}),a.jsx("input",{type:"text",value:l,onChange:ee=>c(ee.target.value),placeholder:"main",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Auto-backup"}),a.jsxs("select",{value:u?h:"disabled",onChange:ee=>{ee.target.value==="disabled"?d(!1):(d(!0),m(ee.target.value))},className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[a.jsx("option",{value:"disabled",children:"Manual only"}),a.jsx("option",{value:"hourly",children:"Hourly"}),a.jsx("option",{value:"daily",children:"Daily"}),a.jsx("option",{value:"weekly",children:"Weekly"})]})]})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-2",children:"Include in backup"}),a.jsxs("div",{className:"space-y-2",children:[a.jsxs("label",{className:`flex items-start gap-2 ${W?"cursor-not-allowed opacity-60":"cursor-pointer"}`,children:[a.jsx("input",{type:"checkbox",checked:p,onChange:ee=>b(ee.target.checked),className:"w-4 h-4 mt-0.5 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green",disabled:W}),a.jsxs("div",{className:"flex-1",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("span",{className:`text-sm ${W?"text-bambu-gray":"text-white"}`,children:"K-Profiles"}),W&&a.jsxs("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-xs bg-yellow-500/20 text-yellow-400",children:[a.jsx(kn,{className:"w-3 h-3"}),"No printers connected"]}),Q&&a.jsxs("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-xs bg-yellow-500/20 text-yellow-400",children:[a.jsx(kn,{className:"w-3 h-3"}),Xe,"/",fe," connected"]})]}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Pressure advance calibration from connected printers"})]})]}),a.jsxs("label",{className:"flex items-start gap-2 cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:v,onChange:ee=>x(ee.target.checked),className:"w-4 h-4 mt-0.5 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green",disabled:!Ce?.is_authenticated}),a.jsxs("div",{children:[a.jsx("span",{className:`text-sm ${Ce?.is_authenticated?"text-white":"text-bambu-gray"}`,children:"Cloud Profiles"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Filament, printer, and process presets from Bambu Cloud"})]})]}),a.jsxs("label",{className:"flex items-start gap-2 cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:y,onChange:ee=>S(ee.target.checked),className:"w-4 h-4 mt-0.5 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),a.jsxs("div",{children:[a.jsx("span",{className:"text-white text-sm",children:"App Settings"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Bambuddy configuration (excludes sensitive data)"})]})]})]})]}),a.jsxs("div",{className:"border-t border-bambu-dark-tertiary pt-4 space-y-3",children:[pe?.configured&&a.jsxs("div",{className:"flex items-center justify-between text-sm",children:[a.jsx("div",{className:"flex items-center gap-2 text-bambu-gray",children:pe.last_backup_at?a.jsxs(a.Fragment,{children:[a.jsxs("span",{children:["Last backup: ",OW(pe.last_backup_at)]}),a.jsx(RW,{status:pe.last_backup_status})]}):a.jsx("span",{children:"No backups yet"})}),pe.next_scheduled_run&&a.jsxs("span",{className:"text-bambu-gray",children:[a.jsx(nr,{className:"w-3 h-3 inline mr-1"}),"Next: ",OW(pe.next_scheduled_run)]})]}),re&&a.jsxs("div",{className:`text-sm flex items-center gap-1 ${re.success?"text-green-400":"text-red-400"}`,children:[re.success?a.jsx(Nr,{className:"w-4 h-4"}):a.jsx(ta,{className:"w-4 h-4"}),re.message]}),a.jsx("div",{className:"flex flex-wrap items-center gap-2",children:pe?.configured?a.jsx(a.Fragment,{children:te.isPending||pe.is_running?a.jsxs("div",{className:"flex items-center gap-2 text-bambu-green",children:[a.jsx(ut,{className:"w-4 h-4 animate-spin"}),a.jsx("span",{className:"text-sm",children:pe.progress||"Starting backup..."})]}):a.jsxs(a.Fragment,{children:[a.jsxs(ke,{variant:"primary",size:"sm",onClick:()=>te.mutate(),disabled:!ie?.enabled,children:[a.jsx(vo,{className:"w-4 h-4"}),"Backup Now"]}),a.jsxs(ke,{variant:"secondary",size:"sm",onClick:ge,disabled:G,children:[G?a.jsx(ut,{className:"w-4 h-4 animate-spin"}):a.jsx(Ir,{className:"w-4 h-4"}),"Test"]})]})}):a.jsxs(a.Fragment,{children:[a.jsxs(ke,{variant:"primary",size:"sm",onClick:Se,disabled:X.isPending||!r||!s,children:[X.isPending?a.jsx(ut,{className:"w-4 h-4 animate-spin"}):a.jsx(Nr,{className:"w-4 h-4"}),"Enable Backup"]}),a.jsxs(ke,{variant:"secondary",size:"sm",onClick:ge,disabled:G||!r||!s,children:[G?a.jsx(ut,{className:"w-4 h-4 animate-spin"}):a.jsx(Ir,{className:"w-4 h-4"}),"Test Connection"]})]})})]})]}):a.jsxs("div",{className:"flex items-start gap-2 p-3 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[a.jsx(kn,{className:"w-4 h-4 text-yellow-400 mt-0.5 flex-shrink-0"}),a.jsx("p",{className:"text-sm text-yellow-400",children:"Bambu Cloud login required. Sign in under Profiles → Cloud Profiles to enable GitHub backup."})]})})]}),de&&de.length>0&&a.jsxs(_t,{children:[a.jsx(Pn,{children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(sy,{className:"w-5 h-5 text-gray-400"}),a.jsx("h2",{className:"text-lg font-semibold text-white",children:"History"})]}),a.jsxs(ke,{variant:"ghost",size:"sm",onClick:()=>V.mutate(),disabled:V.isPending,children:[a.jsx(cn,{className:"w-4 h-4"}),"Clear"]})]})}),a.jsx(Mt,{children:a.jsx("div",{className:"overflow-x-auto",children:a.jsxs("table",{className:"w-full text-sm",children:[a.jsx("thead",{children:a.jsxs("tr",{className:"text-bambu-gray border-b border-bambu-dark-tertiary",children:[a.jsx("th",{className:"text-left py-2 px-2",children:"Date"}),a.jsx("th",{className:"text-left py-2 px-2",children:"Status"}),a.jsx("th",{className:"text-left py-2 px-2",children:"Commit"})]})}),a.jsx("tbody",{children:de.slice(0,10).map(ee=>a.jsxs("tr",{className:"border-b border-bambu-dark-tertiary/50 hover:bg-bambu-dark-secondary",children:[a.jsx("td",{className:"py-2 px-2 text-white",children:iQe(ee.started_at)}),a.jsx("td",{className:"py-2 px-2",children:a.jsx(RW,{status:ee.status})}),a.jsx("td",{className:"py-2 px-2",children:ee.commit_sha?a.jsxs("a",{href:`${ie?.repository_url}/commit/${ee.commit_sha}`,target:"_blank",rel:"noopener noreferrer",className:"text-bambu-green hover:underline inline-flex items-center gap-1",children:[ee.commit_sha.substring(0,7),a.jsx(Xr,{className:"w-3 h-3"})]}):a.jsx("span",{className:"text-bambu-gray",children:"-"})})]},ee.id))})]})})})]})]}),a.jsx("div",{className:"space-y-6",children:a.jsxs(_t,{children:[a.jsx(Pn,{children:a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(ju,{className:"w-5 h-5 text-gray-400"}),a.jsx("h2",{className:"text-lg font-semibold text-white",children:"Local Backup"})]})}),a.jsxs(Mt,{className:"space-y-4",children:[a.jsx("p",{className:"text-sm text-bambu-gray",children:"Create a complete backup of your Bambuddy data including the database, archives, uploads, and all files."}),a.jsxs("div",{className:"flex items-center justify-between py-3 border-b border-bambu-dark-tertiary",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white",children:"Download Backup"}),a.jsx("p",{className:"text-sm text-bambu-gray",children:"Complete backup: database + all files (ZIP)"})]}),a.jsxs(ke,{variant:"secondary",size:"sm",disabled:k||E,onClick:async()=>{C(!0),j("Preparing backup...");try{j("Creating backup archive... This may take a while for large archives.");const{blob:ee,filename:U}=await ce.exportBackup();j("Downloading backup file...");const O=URL.createObjectURL(ee),Z=document.createElement("a");Z.href=O,Z.download=U,Z.click(),URL.revokeObjectURL(O),e("Backup downloaded successfully")}catch(ee){e(`Failed to create backup: ${ee instanceof Error?ee.message:"Unknown error"}`,"error")}finally{C(!1),j("")}},children:[a.jsx(Ni,{className:"w-4 h-4"}),"Download"]})]}),a.jsxs("div",{className:"flex items-center justify-between py-3 border-b border-bambu-dark-tertiary",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white",children:n("backup.restoreBackup")}),a.jsx("p",{className:"text-sm text-bambu-gray",children:n("backup.restoreDescription")}),a.jsx("p",{className:"text-xs text-bambu-gray-light mt-1",children:n("backup.restoreNote")})]}),a.jsx("input",{ref:I,type:"file",accept:".zip",className:"hidden",onChange:ee=>{const U=ee.target.files?.[0];U&&(R(U),L(!0)),ee.target.value=""}}),a.jsxs(ke,{variant:"secondary",size:"sm",disabled:E||k,onClick:()=>I.current?.click(),children:[a.jsx($a,{className:"w-4 h-4"}),"Restore"]})]}),$&&a.jsx("div",{className:`p-3 rounded-lg ${$.success?"bg-green-500/10 border border-green-500/30":"bg-red-500/10 border border-red-500/30"}`,children:a.jsxs("div",{className:"flex items-start gap-2 text-sm",children:[$.success?a.jsx(Nr,{className:"w-4 h-4 text-green-400 mt-0.5 flex-shrink-0"}):a.jsx(ta,{className:"w-4 h-4 text-red-400 mt-0.5 flex-shrink-0"}),a.jsxs("div",{className:$.success?"text-green-200":"text-red-200",children:[$.message,$.success&&a.jsx("div",{className:"mt-2",children:a.jsxs(ke,{size:"sm",onClick:()=>window.location.reload(),children:[a.jsx($h,{className:"w-3 h-3"}),"Reload Now"]})})]})]})}),a.jsx("div",{className:"p-3 rounded-lg bg-yellow-500/10 border border-yellow-500/30",children:a.jsxs("div",{className:"flex items-start gap-2 text-sm",children:[a.jsx(kn,{className:"w-4 h-4 text-yellow-400 mt-0.5 flex-shrink-0"}),a.jsxs("div",{className:"text-yellow-200",children:[a.jsx("span",{className:"font-medium",children:"Restore replaces all data."})," ",a.jsx("span",{className:"text-yellow-200/70",children:"Your current database and files will be completely replaced. A restart is required after restore."})]})]})})]})]})}),z&&B&&a.jsx(er,{title:"Restore Backup",message:`Are you sure you want to restore from "${B.name}"? This will completely replace your current database and all files. The application will need to be restarted after restore.`,confirmText:"Restore Backup",variant:"danger",onConfirm:async()=>{L(!1),P(!0),q(null);try{j("Uploading backup file...");const ee=await ce.importBackup(B);q(ee),ee.success?e("Backup restored. Please restart Bambuddy.","success"):e(ee.message,"error")}catch(ee){const U=ee instanceof Error?ee.message:"Failed to restore backup";q({success:!1,message:U}),e(U,"error")}finally{P(!1),j(""),R(null)}},onCancel:()=>{L(!1),R(null)}}),(k||E)&&a.jsx("div",{className:"fixed inset-0 bg-black/80 flex items-center justify-center z-[100]",children:a.jsxs("div",{className:"bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl p-8 max-w-md w-full mx-4 text-center",children:[a.jsx("div",{className:"flex justify-center mb-4",children:a.jsxs("div",{className:"relative",children:[a.jsx("div",{className:"w-16 h-16 border-4 border-bambu-dark-tertiary rounded-full"}),a.jsx("div",{className:"w-16 h-16 border-4 border-bambu-green border-t-transparent rounded-full absolute inset-0 animate-spin"})]})}),a.jsx("h3",{className:"text-xl font-semibold text-white mb-2",children:k?"Creating Backup":"Restoring Backup"}),a.jsx("p",{className:"text-bambu-gray mb-4",children:T||(k?"Preparing...":"Processing...")}),a.jsx("div",{className:"p-3 rounded-lg bg-yellow-500/10 border border-yellow-500/30",children:a.jsxs("div",{className:"flex items-start gap-2 text-sm",children:[a.jsx(kn,{className:"w-4 h-4 text-yellow-400 mt-0.5 flex-shrink-0"}),a.jsx("p",{className:"text-yellow-200 text-left",children:"Please do not close this page or navigate away. This operation may take several minutes for large backups."})]})})]})})]})}function sQe(){const{t}=Sn(),{showToast:e}=Hn(),n=un(),[r,i]=_.useState({smtp_host:"",smtp_port:587,smtp_username:"",smtp_password:"",smtp_security:"starttls",smtp_auth_enabled:!0,smtp_from_email:"",smtp_from_name:"BamBuddy"}),[s,o]=_.useState(""),{data:l,isLoading:c}=st({queryKey:["smtpSettings"],queryFn:()=>ce.getSMTPSettings()}),{data:u}=st({queryKey:["advancedAuthStatus"],queryFn:()=>ce.getAdvancedAuthStatus()});_.useEffect(()=>{l&&i({...l,smtp_password:""})},[l]);const d=pt({mutationFn:x=>ce.saveSMTPSettings(x),onSuccess:()=>{n.invalidateQueries({queryKey:["smtpSettings"]}),n.invalidateQueries({queryKey:["advancedAuthStatus"]}),e("SMTP settings saved successfully","success")},onError:x=>{e(x.message,"error")}}),h=pt({mutationFn:x=>ce.testSMTP(x),onSuccess:x=>{e(x.message,x.success?"success":"error")},onError:x=>{e(x.message,"error")}}),m=pt({mutationFn:x=>x?ce.enableAdvancedAuth():ce.disableAdvancedAuth(),onSuccess:x=>{n.invalidateQueries({queryKey:["advancedAuthStatus"]}),e(x.message,"success")},onError:x=>{e(x.message,"error")}}),p=()=>{if(!r.smtp_host||!r.smtp_from_email){e("Please fill in all required fields","error");return}if(r.smtp_auth_enabled&&!r.smtp_username){e("Username is required when authentication is enabled","error");return}d.mutate(r)},b=()=>{if(!s){e("Please enter a test email address","error");return}if(!r.smtp_host||!r.smtp_from_email){e("Please fill in SMTP Server and From Email before testing","error");return}if(r.smtp_auth_enabled&&(!r.smtp_username||!r.smtp_password)){e("Username and Password are required when authentication is enabled","error");return}h.mutate({smtp_host:r.smtp_host,smtp_port:r.smtp_port,smtp_username:r.smtp_username,smtp_password:r.smtp_password,smtp_security:r.smtp_security,smtp_auth_enabled:r.smtp_auth_enabled,smtp_from_email:r.smtp_from_email,test_recipient:s})},v=()=>{if(!u?.advanced_auth_enabled&&!u?.smtp_configured){e("Please configure and test SMTP settings first","error");return}m.mutate(!u?.advanced_auth_enabled)};return c?a.jsx("div",{className:"flex items-center justify-center p-12",children:a.jsx(ut,{className:"w-8 h-8 animate-spin text-bambu-green"})}):a.jsxs("div",{className:"space-y-6",children:[a.jsxs(_t,{children:[a.jsx(Pn,{children:a.jsx("h2",{className:"text-lg font-semibold text-white",children:t("settings.email.smtpSettings")||"SMTP Configuration"})}),a.jsx(Mt,{children:a.jsxs("div",{className:"space-y-4",children:[a.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[a.jsxs("div",{children:[a.jsxs("label",{className:"block text-sm font-medium text-white mb-2",children:[t("settings.email.smtpHost")||"SMTP Server"," *"]}),a.jsx("input",{type:"text",value:r.smtp_host,onChange:x=>i({...r,smtp_host:x.target.value}),placeholder:"smtp.gmail.com",className:"w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:t("settings.email.smtpPort")||"SMTP Port"}),a.jsx("input",{type:"number",value:r.smtp_port,onChange:x=>i({...r,smtp_port:parseInt(x.target.value)||587}),placeholder:"587",className:"w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors"})]})]}),a.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:t("settings.email.security")||"Security"}),a.jsxs("select",{value:r.smtp_security,onChange:x=>i({...r,smtp_security:x.target.value}),className:"w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors",children:[a.jsx("option",{value:"starttls",children:"STARTTLS (Port 587)"}),a.jsx("option",{value:"ssl",children:"SSL/TLS (Port 465)"}),a.jsx("option",{value:"none",children:"None (Port 25)"})]})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:t("settings.email.authentication")||"Authentication"}),a.jsxs("select",{value:r.smtp_auth_enabled?"true":"false",onChange:x=>i({...r,smtp_auth_enabled:x.target.value==="true"}),className:"w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors",children:[a.jsx("option",{value:"true",children:"Enabled"}),a.jsx("option",{value:"false",children:"Disabled"})]})]})]}),r.smtp_auth_enabled&&a.jsxs(a.Fragment,{children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:t("settings.email.username")||"Username"}),a.jsx("input",{type:"text",value:r.smtp_username||"",onChange:x=>i({...r,smtp_username:x.target.value}),placeholder:"your.email@gmail.com",className:"w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:t("settings.email.password")||"Password"}),a.jsx("input",{type:"password",value:r.smtp_password||"",onChange:x=>i({...r,smtp_password:x.target.value}),placeholder:l?"••••••••":"App password",className:"w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors"})]})]}),a.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[a.jsxs("div",{children:[a.jsxs("label",{className:"block text-sm font-medium text-white mb-2",children:[t("settings.email.fromEmail")||"From Email"," *"]}),a.jsx("input",{type:"email",value:r.smtp_from_email,onChange:x=>i({...r,smtp_from_email:x.target.value}),placeholder:"your@email.com",className:"w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:t("settings.email.fromName")||"From Name"}),a.jsx("input",{type:"text",value:r.smtp_from_name,onChange:x=>i({...r,smtp_from_name:x.target.value}),placeholder:"BamBuddy",className:"w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors"})]})]}),a.jsx("div",{className:"flex gap-2",children:a.jsx(ke,{onClick:p,disabled:d.isPending,className:"flex-1",children:d.isPending?a.jsxs(a.Fragment,{children:[a.jsx(ut,{className:"w-4 h-4 animate-spin"}),t("settings.email.saving")||"Saving..."]}):t("settings.email.save")||"Save Settings"})})]})})]}),a.jsxs(_t,{children:[a.jsx(Pn,{children:a.jsx("h2",{className:"text-lg font-semibold text-white",children:t("settings.email.testConnection")||"Test SMTP Connection"})}),a.jsx(Mt,{children:a.jsxs("div",{className:"space-y-4",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:t("settings.email.testRecipient")||"Test Recipient Email"}),a.jsx("input",{type:"email",value:s,onChange:x=>o(x.target.value),placeholder:"test@example.com",className:"w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors"})]}),a.jsx(ke,{onClick:b,disabled:h.isPending,variant:"secondary",children:h.isPending?a.jsxs(a.Fragment,{children:[a.jsx(ut,{className:"w-4 h-4 animate-spin"}),t("settings.email.sending")||"Sending..."]}):a.jsxs(a.Fragment,{children:[a.jsx($M,{className:"w-4 h-4"}),t("settings.email.sendTest")||"Send Test Email"]})})]})})]}),u?.smtp_configured&&a.jsxs(_t,{children:[a.jsx(Pn,{children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(oy,{className:"w-5 h-5 text-bambu-green"}),a.jsx("h2",{className:"text-lg font-semibold text-white",children:t("settings.email.advancedAuth")||"Advanced Authentication"})]}),a.jsx(ke,{onClick:v,disabled:m.isPending,variant:u?.advanced_auth_enabled?"danger":"primary",children:u?.advanced_auth_enabled?a.jsxs(a.Fragment,{children:[a.jsx(j1,{className:"w-4 h-4"}),t("settings.email.disable")||"Disable"]}):a.jsxs(a.Fragment,{children:[a.jsx(P1,{className:"w-4 h-4"}),t("settings.email.enable")||"Enable"]})})]})}),a.jsx(Mt,{children:a.jsx("div",{className:"space-y-4",children:u?.advanced_auth_enabled?a.jsx("div",{className:"bg-green-500/10 border border-green-500/30 rounded-lg p-4",children:a.jsxs("div",{className:"flex items-start gap-3",children:[a.jsx(Nr,{className:"w-5 h-5 text-green-400 mt-0.5 flex-shrink-0"}),a.jsxs("div",{className:"space-y-2",children:[a.jsx("p",{className:"text-white font-medium",children:t("settings.email.advancedAuthEnabled")||"Advanced Authentication is enabled"}),a.jsxs("ul",{className:"text-sm text-green-300 space-y-1 list-disc list-inside",children:[a.jsx("li",{children:t("settings.email.feature1")||"Passwords are auto-generated and emailed to new users"}),a.jsx("li",{children:t("settings.email.feature2")||"Users can login with username or email"}),a.jsx("li",{children:t("settings.email.feature3")||"Forgot password feature is available"}),a.jsx("li",{children:t("settings.email.feature4")||"Admins can reset user passwords via email"})]})]})]})}):a.jsx("div",{className:"bg-yellow-500/10 border border-yellow-500/30 rounded-lg p-4",children:a.jsxs("div",{className:"flex items-start gap-3",children:[a.jsx(kn,{className:"w-5 h-5 text-yellow-400 mt-0.5 flex-shrink-0"}),a.jsxs("div",{className:"space-y-2",children:[a.jsx("p",{className:"text-white font-medium",children:t("settings.email.advancedAuthDisabled")||"Advanced Authentication is disabled"}),a.jsx("p",{className:"text-sm text-yellow-300",children:t("settings.email.advancedAuthDisabledDesc")||"Enable advanced authentication to activate email-based features for user management."})]})]})})})})]})]})}const oQe={get:"bg-blue-500/20 text-blue-400 border-blue-500/30",post:"bg-green-500/20 text-green-400 border-green-500/30",put:"bg-yellow-500/20 text-yellow-400 border-yellow-500/30",patch:"bg-orange-500/20 text-orange-400 border-orange-500/30",delete:"bg-red-500/20 text-red-400 border-red-500/30"};function lQe(t,e){const n=e.replace("#/","").split("/");let r=t;for(const i of n)r=r[i];return r}function T0(t,e,n=0){if(n>5)return"...";if(e.$ref)return T0(t,lQe(t,e.$ref),n+1);if(e.allOf){const r={};for(const i of e.allOf){const s=T0(t,i,n+1);typeof s=="object"&&s!==null&&Object.assign(r,s)}return r}if(e.example!==void 0)return e.example;if(e.default!==void 0)return e.default;switch(e.type){case"string":return e.enum?e.enum[0]:"string";case"integer":case"number":return 0;case"boolean":return!1;case"array":return e.items?[T0(t,e.items,n+1)]:[];case"object":if(e.properties){const r={};for(const[i,s]of Object.entries(e.properties))r[i]=T0(t,s,n+1);return r}return{};default:return null}}function cQe({path:t,method:e,spec:n,schema:r,apiKey:i}){const[s,o]=_.useState(!1),[l,c]=_.useState({}),[u,d]=_.useState(""),[h,m]=_.useState(null),[p,b]=_.useState(!1),[v,x]=_.useState(!1);_.useEffect(()=>{if(s&&n.parameters){const P={};for(const T of n.parameters)T.schema?.default!==void 0&&(P[T.name]=String(T.schema.default));c(T=>({...P,...T}))}},[s,n.parameters]),_.useEffect(()=>{if(s&&n.requestBody?.content?.["application/json"]?.schema&&!u){const P=n.requestBody.content["application/json"].schema,T=T0(r,P);d(JSON.stringify(T,null,2))}},[s,n.requestBody,r,u]);const S=(()=>{const P=[];for(const T of n.parameters||[])if(T.in==="path"||T.required){const j=l[T.name];(j===void 0||j==="")&&P.push(T.name)}return P})(),N=async()=>{if(S.length>0){m({status:0,statusText:"Validation Error",headers:{},body:`Missing required parameters: ${S.join(", ")}`,duration:0});return}b(!0),m(null);try{let P=t;const T=new URLSearchParams;for(const re of n.parameters||[]){const H=l[re.name];H!==void 0&&H!==""&&(re.in==="path"?P=P.replace(`{${re.name}}`,encodeURIComponent(H)):re.in==="query"&&T.append(re.name,H))}const j=T.toString(),z=`${P}${j?`?${j}`:""}`,L={"Content-Type":"application/json"};i&&(L["X-API-Key"]=i);const B={method:e.toUpperCase(),headers:L};["post","put","patch"].includes(e)&&u&&(B.body=u);const R=performance.now(),$=await fetch(z,B),q=Math.round(performance.now()-R),I={};$.headers.forEach((re,H)=>{I[H]=re});let G;$.headers.get("content-type")?.includes("application/json")?G=await $.json():G=await $.text(),m({status:$.status,statusText:$.statusText,headers:I,body:G,duration:q})}catch(P){m({status:0,statusText:"Network Error",headers:{},body:P instanceof Error?P.message:"Unknown error",duration:0})}finally{b(!1)}},A=async()=>{if(h){const P=typeof h.body=="string"?h.body:JSON.stringify(h.body,null,2);try{await navigator.clipboard.writeText(P),x(!0),setTimeout(()=>x(!1),2e3)}catch{const T=document.createElement("textarea");T.value=P,T.style.position="fixed",T.style.left="-999999px",document.body.appendChild(T),T.select(),document.execCommand("copy"),document.body.removeChild(T),x(!0),setTimeout(()=>x(!1),2e3)}}},k=(n.parameters||[]).filter(P=>P.in==="path"),C=(n.parameters||[]).filter(P=>P.in==="query"),E=["post","put","patch"].includes(e)&&n.requestBody;return a.jsxs("div",{className:"border border-bambu-dark-tertiary rounded-lg overflow-hidden",children:[a.jsxs("button",{onClick:()=>o(!s),className:"w-full flex items-center gap-3 p-3 hover:bg-bambu-dark-tertiary/50 transition-colors text-left",children:[s?a.jsx(Sr,{className:"w-4 h-4 text-bambu-gray flex-shrink-0"}):a.jsx(_s,{className:"w-4 h-4 text-bambu-gray flex-shrink-0"}),a.jsx("span",{className:`px-2 py-0.5 text-xs font-mono font-semibold uppercase rounded border ${oQe[e]||"bg-gray-500/20 text-gray-400"}`,children:e}),a.jsx("code",{className:"text-sm text-white font-mono flex-1 truncate",children:t}),n.summary&&a.jsx("span",{className:"text-sm text-bambu-gray truncate max-w-[40%]",children:n.summary})]}),s&&a.jsxs("div",{className:"border-t border-bambu-dark-tertiary p-4 space-y-4 bg-bambu-dark/50",children:[n.description&&a.jsx("p",{className:"text-sm text-bambu-gray",children:n.description}),k.length>0&&a.jsxs("div",{className:"space-y-2",children:[a.jsx("h4",{className:"text-sm font-medium text-white",children:"Path Parameters"}),a.jsx("div",{className:"space-y-2",children:k.map(P=>a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsxs("label",{className:"text-sm text-bambu-gray w-32 flex-shrink-0",children:[P.name,P.required&&a.jsx("span",{className:"text-red-400 ml-1",children:"*"})]}),a.jsx("input",{type:"text",value:l[P.name]||"",onChange:T=>c(j=>({...j,[P.name]:T.target.value})),placeholder:P.description||P.schema?.type||"value",className:"flex-1 px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm font-mono focus:border-bambu-green focus:outline-none"})]},P.name))})]}),C.length>0&&a.jsxs("div",{className:"space-y-2",children:[a.jsx("h4",{className:"text-sm font-medium text-white",children:"Query Parameters"}),a.jsx("div",{className:"space-y-2",children:C.map(P=>a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsxs("label",{className:"text-sm text-bambu-gray w-32 flex-shrink-0",children:[P.name,P.required&&a.jsx("span",{className:"text-red-400 ml-1",children:"*"})]}),P.schema?.enum?a.jsxs("select",{value:l[P.name]||"",onChange:T=>c(j=>({...j,[P.name]:T.target.value})),className:"flex-1 px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none",children:[a.jsx("option",{value:"",children:"-- Select --"}),P.schema.enum.map(T=>a.jsx("option",{value:T,children:T},T))]}):a.jsx("input",{type:"text",value:l[P.name]||"",onChange:T=>c(j=>({...j,[P.name]:T.target.value})),placeholder:P.description||P.schema?.type||"value",className:"flex-1 px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm font-mono focus:border-bambu-green focus:outline-none"})]},P.name))})]}),E&&a.jsxs("div",{className:"space-y-2",children:[a.jsx("h4",{className:"text-sm font-medium text-white",children:"Request Body"}),a.jsx("textarea",{value:u,onChange:P=>d(P.target.value),rows:8,className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm font-mono focus:border-bambu-green focus:outline-none resize-y",placeholder:"JSON request body..."})]}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsxs(ke,{onClick:N,disabled:p,children:[p?a.jsx(ut,{className:"w-4 h-4 animate-spin"}):a.jsx(vo,{className:"w-4 h-4"}),"Execute"]}),S.length>0&&a.jsxs("span",{className:"text-xs text-yellow-400 flex items-center gap-1",children:[a.jsx(Wi,{className:"w-3 h-3"}),"Fill in: ",S.join(", ")]})]}),h&&a.jsxs("div",{className:"space-y-2",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("h4",{className:"text-sm font-medium text-white flex items-center gap-2",children:["Response",a.jsxs("span",{className:`px-2 py-0.5 text-xs rounded ${h.status>=200&&h.status<300?"bg-green-500/20 text-green-400":h.status>=400?"bg-red-500/20 text-red-400":"bg-yellow-500/20 text-yellow-400"}`,children:[h.status," ",h.statusText]}),a.jsxs("span",{className:"text-xs text-bambu-gray",children:[h.duration,"ms"]})]}),a.jsx(ke,{variant:"secondary",size:"sm",onClick:A,children:v?a.jsx(Nr,{className:"w-3 h-3 text-green-400"}):a.jsx(Fl,{className:"w-3 h-3"})})]}),a.jsx("pre",{className:"p-3 bg-bambu-dark rounded-lg text-sm font-mono text-white overflow-auto max-h-96 border border-bambu-dark-tertiary",children:typeof h.body=="string"?h.body:JSON.stringify(h.body,null,2)})]})]})]})}function uQe({apiKey:t=""}){const[e,n]=_.useState(null),[r,i]=_.useState(!0),[s,o]=_.useState(null),[l,c]=_.useState(new Set),[u,d]=_.useState("");if(_.useEffect(()=>{async function x(){try{const y=await fetch("/openapi.json");if(!y.ok)throw new Error("Failed to fetch OpenAPI schema");const S=await y.json();n(S)}catch(y){o(y instanceof Error?y.message:"Unknown error")}finally{i(!1)}}x()},[]),r)return a.jsx("div",{className:"flex justify-center py-12",children:a.jsx(ut,{className:"w-8 h-8 text-bambu-green animate-spin"})});if(s||!e)return a.jsx(_t,{children:a.jsx(Mt,{className:"py-8",children:a.jsxs("div",{className:"text-center text-red-400",children:[a.jsx(Wi,{className:"w-12 h-12 mx-auto mb-3 opacity-50"}),a.jsx("p",{children:"Failed to load API schema"}),a.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:s})]})})});const h={};for(const[x,y]of Object.entries(e.paths))for(const[S,N]of Object.entries(y)){if(S==="parameters")continue;const A=N.tags||["Other"];for(const k of A)h[k]||(h[k]=[]),h[k].push({path:x,method:S,spec:N})}const m=Object.entries(h).map(([x,y])=>{if(!u)return{tag:x,endpoints:y};const S=y.filter(({path:N,method:A,spec:k})=>{const C=u.toLowerCase();return N.toLowerCase().includes(C)||A.toLowerCase().includes(C)||(k.summary?.toLowerCase()||"").includes(C)||(k.description?.toLowerCase()||"").includes(C)});return{tag:x,endpoints:S}}).filter(({endpoints:x})=>x.length>0).sort((x,y)=>x.tag.localeCompare(y.tag)),p=x=>{c(y=>{const S=new Set(y);return S.has(x)?S.delete(x):S.add(x),S})},b=()=>{c(new Set(m.map(x=>x.tag)))},v=()=>{c(new Set)};return a.jsxs("div",{className:"space-y-4",children:[a.jsxs("div",{className:"flex items-center justify-between gap-4",children:[a.jsx("div",{className:"flex-1",children:a.jsx("input",{type:"text",value:u,onChange:x=>d(x.target.value),placeholder:"Search endpoints...",className:"w-full max-w-md px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(ke,{variant:"secondary",size:"sm",onClick:b,children:"Expand All"}),a.jsx(ke,{variant:"secondary",size:"sm",onClick:v,children:"Collapse All"}),a.jsxs("a",{href:"/docs",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1 text-sm text-bambu-green hover:underline",children:[a.jsx(Xr,{className:"w-4 h-4"}),"Swagger UI"]})]})]}),a.jsxs("p",{className:"text-sm text-bambu-gray",children:[m.reduce((x,y)=>x+y.endpoints.length,0)," endpoints in ",m.length," categories"]}),a.jsx("div",{className:"space-y-3",children:m.map(({tag:x,endpoints:y})=>a.jsxs(_t,{children:[a.jsx("button",{onClick:()=>p(x),className:"w-full flex items-center justify-between p-4 hover:bg-bambu-dark-tertiary/30 transition-colors text-left",children:a.jsxs("div",{className:"flex items-center gap-2",children:[l.has(x)?a.jsx(Sr,{className:"w-5 h-5 text-bambu-gray"}):a.jsx(_s,{className:"w-5 h-5 text-bambu-gray"}),a.jsx("h3",{className:"text-base font-semibold text-white capitalize",children:x.replace(/-/g," ")}),a.jsx("span",{className:"text-xs bg-bambu-dark-tertiary px-2 py-0.5 rounded-full text-bambu-gray",children:y.length})]})}),l.has(x)&&a.jsx(Mt,{className:"pt-0 space-y-2",children:y.map(({path:S,method:N,spec:A})=>a.jsx(cQe,{path:S,method:N,spec:A,schema:e,apiKey:t},`${N}-${S}`))})]},x))})]})}const dQe=["general","network","plugs","email","notifications","filament","apikeys","virtual-printer","users","backup"];function hQe(){const t=un(),e=Dc(),[n,r]=YR(),{t:i,i18n:s}=Sn(),{showToast:o}=Hn(),{authEnabled:l,user:c,refreshAuth:u}=Di(),{mode:d,darkStyle:h,darkBackground:m,darkAccent:p,lightStyle:b,lightBackground:v,lightAccent:x,setDarkStyle:y,setDarkBackground:S,setDarkAccent:N,setLightStyle:A,setLightBackground:k,setLightAccent:C}=Vh(),[E,P]=_.useState(null),[T,j]=_.useState(!1),[z,L]=_.useState(null),[B,R]=_.useState(!1),[$,q]=_.useState(null),[I,G]=_.useState(null),[Y,re]=_.useState(!1),[H,K]=_.useState(QK()),ne=n.get("tab"),ie=ne&&dQe.includes(ne)?ne:"general",[be,pe]=_.useState(ie),de=oe=>{pe(oe),oe==="general"?n.delete("tab"):n.set("tab",oe),r(n,{replace:!0})},[Ce,ae]=_.useState(!1),[Ae,Le]=_.useState(""),[fe,Xe]=_.useState({can_queue:!0,can_control_printer:!1,can_read_status:!0}),[W,Q]=_.useState(null),[me,X]=_.useState(null),[te,V]=_.useState(""),[ge,Se]=_.useState(!1),[ee,U]=_.useState(!1),[O,Z]=_.useState(null),[le,we]=_.useState(!1),[ye,se]=_.useState(!1),[Oe,He]=_.useState(!1),[tt,Ue]=_.useState({currentPassword:"",newPassword:"",confirmPassword:""}),[xe,Te]=_.useState(!1),[Ie,Ne]=_.useState(!1),[Ge,Me]=_.useState(!1),[rt,Ee]=_.useState(null),[Ke,Be]=_.useState(null),[ue,$e]=_.useState(null),[at,kt]=_.useState(!1),[gt,Ut]=_.useState({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]}),[Ft,Fe]=_.useState(!1),[xt,Wt]=_.useState(null),[Qt,En]=_.useState(null),[hn,or]=_.useState({name:"",description:"",permissions:[]}),[Kn,Qn]=_.useState(new Set),[Tn,di]=_.useState(null),[ii,je]=_.useState(!1),[Je,dt]=_.useState({}),[ht,ct]=_.useState({}),Tt=oe=>{K(oe),rpe(oe),o(i("settings.toast.settingsSaved"),"success")},he=()=>{localStorage.removeItem("sidebarOrder"),window.location.reload()},{data:De,isLoading:Ve}=st({queryKey:["settings"],queryFn:ce.getSettings}),{data:_e,isLoading:Re}=st({queryKey:["smart-plugs"],queryFn:ce.getSmartPlugs}),{data:et,isLoading:Ye}=st({queryKey:["smart-plugs-energy",_e?.map(oe=>oe.id)],queryFn:async()=>{if(!_e||_e.length===0)return null;const oe=await Promise.all(_e.filter(cs=>cs.enabled).map(async cs=>{try{const ka=await ce.getSmartPlugStatus(cs.id);return{plug:cs,status:ka}}catch{return{plug:cs,status:null}}}));let Nt=0,Un=0,sr=0,To=0,cd=0;for(const{plug:cs,status:ka}of oe){const wk=cs.plug_type==="mqtt"&&ka?.energy?.power!=null;(ka?.reachable||wk)&&ka?.energy&&(cd++,ka.energy?.power!=null&&(Nt+=ka.energy.power),ka.energy?.today!=null&&(Un+=ka.energy.today),ka.energy?.yesterday!=null&&(sr+=ka.energy.yesterday),ka.energy?.total!=null&&(To+=ka.energy.total))}return{totalPower:Nt,totalToday:Un,totalYesterday:sr,totalLifetime:To,reachableCount:cd,totalPlugs:_e.filter(cs=>cs.enabled).length}},enabled:be==="plugs"&&!!_e&&_e.length>0,refetchInterval:be==="plugs"?1e4:!1}),{data:Ct,isLoading:jt}=st({queryKey:["notification-providers"],queryFn:ce.getNotificationProviders}),{data:Bt,isLoading:Rt}=st({queryKey:["api-keys"],queryFn:ce.getAPIKeys}),Et=pt({mutationFn:oe=>ce.createAPIKey(oe),onSuccess:oe=>{Q(oe.key||null),ae(!1),Le(""),t.invalidateQueries({queryKey:["api-keys"]}),o(i("settings.toast.apiKeyCreated"))},onError:oe=>{o(`Failed to create API key: ${oe.message}`,"error")}}),an=pt({mutationFn:oe=>ce.deleteAPIKey(oe),onSuccess:()=>{t.invalidateQueries({queryKey:["api-keys"]}),o(i("settings.toast.apiKeyDeleted"))},onError:oe=>{o(`Failed to delete API key: ${oe.message}`,"error")}}),{data:Vt}=st({queryKey:["printers"],queryFn:ce.getPrinters}),{data:pn,isLoading:fn}=st({queryKey:["notification-templates"],queryFn:ce.getNotificationTemplates}),{data:Cn}=st({queryKey:["virtual-printer-settings"],queryFn:D1.getSettings,refetchInterval:1e4}),Xt=Cn?.status?.running??!1,{data:dn}=st({queryKey:["ffmpeg-status"],queryFn:ce.checkFfmpeg}),{data:mn}=st({queryKey:["version"],queryFn:ce.getVersion}),{data:en,refetch:ir,isRefetching:In}=st({queryKey:["updateCheck"],queryFn:ce.checkForUpdates,staleTime:300*1e3}),{data:ai,refetch:ar}=st({queryKey:["updateStatus"],queryFn:ce.getUpdateStatus,refetchInterval:oe=>{const Nt=oe.state.data;return Nt?.status==="downloading"||Nt?.status==="installing"?1e3:!1}}),{data:fr}=st({queryKey:["mqtt-status"],queryFn:ce.getMQTTStatus,refetchInterval:be==="network"?5e3:!1}),{data:nt}=st({queryKey:["github-backup-status"],queryFn:ce.getGitHubBackupStatus}),{data:Dt}=st({queryKey:["cloud-status"],queryFn:ce.getCloudStatus}),{data:Kt={advanced_auth_enabled:!1,smtp_configured:!1}}=st({queryKey:["advancedAuthStatus"],queryFn:()=>ce.getAdvancedAuthStatus()}),{hasPermission:vt}=Di(),{data:Nn=[],isLoading:hi}=st({queryKey:["users"],queryFn:()=>ce.getUsers(),enabled:l&&vt("users:read")}),{data:xr=[],isLoading:Yr}=st({queryKey:["groups"],queryFn:()=>ce.getGroups(),enabled:l&&vt("groups:read")}),{data:No}=st({queryKey:["permissions"],queryFn:()=>ce.getPermissions(),enabled:l&&vt("groups:read")}),nn=pt({mutationFn:oe=>ce.createUser(oe),onSuccess:()=>{t.invalidateQueries({queryKey:["users"]}),t.invalidateQueries({queryKey:["groups"]}),Ne(!1),Ut({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]}),o(i("settings.toast.userCreated"))},onError:oe=>{o(oe.message,"error")}}),Mn=pt({mutationFn:({id:oe,data:Nt})=>ce.updateUser(oe,Nt),onSuccess:()=>{t.invalidateQueries({queryKey:["users"]}),t.invalidateQueries({queryKey:["groups"]}),Me(!1),Ee(null),Ut({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]}),o(i("settings.toast.userUpdated"))},onError:oe=>{o(oe.message,"error")}}),Mr=pt({mutationFn:({id:oe,deleteItems:Nt})=>ce.deleteUser(oe,Nt),onSuccess:()=>{t.invalidateQueries({queryKey:["users"]}),o(i("settings.toast.userDeleted")),Be(null),$e(null)},onError:oe=>{o(oe.message,"error")}}),Mo=async oe=>{Be(oe),kt(!0);try{const Nt=await ce.getUserItemsCount(oe);$e(Nt)}catch{$e({archives:0,queue_items:0,library_files:0})}finally{kt(!1)}},ko=pt({mutationFn:oe=>ce.createGroup(oe),onSuccess:()=>{t.invalidateQueries({queryKey:["groups"]}),Fe(!1),pr(),o(i("settings.toast.groupCreated"))},onError:oe=>{o(oe.message,"error")}}),As=pt({mutationFn:({id:oe,data:Nt})=>ce.updateGroup(oe,Nt),onSuccess:()=>{t.invalidateQueries({queryKey:["groups"]}),Wt(null),pr(),o(i("settings.toast.groupUpdated"))},onError:oe=>{o(oe.message,"error")}}),Eo=pt({mutationFn:oe=>ce.deleteGroup(oe),onSuccess:()=>{t.invalidateQueries({queryKey:["groups"]}),o(i("settings.toast.groupDeleted"))},onError:oe=>{o(oe.message,"error")}}),ls=()=>{const oe=Kt?.advanced_auth_enabled||!1;if(!gt.username){o(i("settings.toast.fillRequiredFields"),"error");return}if(oe&&!gt.email){o("Email is required when advanced authentication is enabled","error");return}if(!oe){if(!gt.password){o(i("settings.toast.fillRequiredFields"),"error");return}if(gt.password!==gt.confirmPassword){o(i("settings.toast.passwordsDoNotMatch"),"error");return}if(gt.password.length<6){o(i("settings.toast.passwordTooShort"),"error");return}}nn.mutate({username:gt.username,password:oe?void 0:gt.password,email:gt.email||void 0,role:gt.role,group_ids:gt.group_ids.length>0?gt.group_ids:void 0})},Ei=oe=>{if(gt.password){if(gt.password!==gt.confirmPassword){o(i("settings.toast.passwordsDoNotMatch"),"error");return}if(gt.password.length<6){o(i("settings.toast.passwordTooShort"),"error");return}}const Nt={username:gt.username||void 0,password:gt.password||void 0,role:gt.role,group_ids:gt.group_ids};Nt.password||delete Nt.password,Mn.mutate({id:oe,data:Nt})},Ao=oe=>{Ee(oe.id),Ut({username:oe.username,password:"",confirmPassword:"",role:oe.role,group_ids:oe.groups?.map(Nt=>Nt.id)||[]}),Me(!0)},Ts=oe=>{Ut(Nt=>({...Nt,group_ids:Nt.group_ids.includes(oe)?Nt.group_ids.filter(Un=>Un!==oe):[...Nt.group_ids,oe]}))},pr=()=>{or({name:"",description:"",permissions:[]}),Qn(new Set)},Zb=()=>{if(!hn.name.trim()){o(i("settings.toast.enterGroupName"),"error");return}ko.mutate({name:hn.name,description:hn.description||void 0,permissions:hn.permissions})},tf=()=>{if(xt){if(!hn.name.trim()){o(i("settings.toast.enterGroupName"),"error");return}As.mutate({id:xt.id,data:{name:hn.name!==xt.name?hn.name:void 0,description:hn.description,permissions:hn.permissions}})}},ql=oe=>{Wt(oe),or({name:oe.name,description:oe.description||"",permissions:oe.permissions});const Nt=new Set;No?.categories.forEach(Un=>{Un.permissions.some(sr=>oe.permissions.includes(sr.value))&&Nt.add(Un.name)}),Qn(Nt)},Jb=oe=>{Qn(Nt=>{const Un=new Set(Nt);return Un.has(oe)?Un.delete(oe):Un.add(oe),Un})},Ym=oe=>{or(Nt=>{const Un=Nt.permissions.includes(oe)?Nt.permissions.filter(sr=>sr!==oe):[...Nt.permissions,oe];return{...Nt,permissions:Un}})},Lv=(oe,Nt)=>{or(Un=>{const sr=oe.permissions.map(cs=>cs.value),To=Un.permissions.filter(cs=>!sr.includes(cs)),cd=Nt?[...To,...sr]:To;return{...Un,permissions:cd}})},ad=oe=>oe.permissions.every(Nt=>hn.permissions.includes(Nt.value)),nf=oe=>{const Nt=oe.permissions.filter(Un=>hn.permissions.includes(Un.value));return Nt.length>0&&Nt.length{oe.is_docker?o(oe.message,"error"):ar()}}),[Ai,gl]=_.useState(null),sd=pt({mutationFn:ce.testAllNotificationProviders,onSuccess:oe=>{gl(oe),t.invalidateQueries({queryKey:["notification-providers"]}),oe.failed===0?o(`All ${oe.tested} providers tested successfully!`,"success"):o(`${oe.success}/${oe.tested} providers succeeded`,oe.failed>0?"error":"success")},onError:oe=>{o(`Failed to test providers: ${oe.message}`,"error")}}),bl=pt({mutationFn:async oe=>{if(!_e)return{success:0,failed:0};const Nt=_e.filter(sr=>sr.enabled),Un=await Promise.all(Nt.map(async sr=>{try{return await ce.controlSmartPlug(sr.id,oe),{success:!0}}catch{return{success:!1}}}));return{success:Un.filter(sr=>sr.success).length,failed:Un.filter(sr=>!sr.success).length}},onSuccess:(oe,Nt)=>{t.invalidateQueries({queryKey:["smart-plugs"]}),t.invalidateQueries({queryKey:["smart-plugs-energy"]}),oe.failed===0?o(`All ${oe.success} plugs turned ${Nt}`,"success"):o(`${oe.success} plugs turned ${Nt}, ${oe.failed} failed`,"error")},onError:oe=>{o(`Failed: ${oe.message}`,"error")}}),rf=_.useRef(null),od=_.useRef(!1),Zm=_.useRef(!0);_.useEffect(()=>{if(De&&!E){const oe={...De,external_url:De.external_url||window.location.origin};P(oe),setTimeout(()=>{Zm.current=!1},100)}},[De,E]);const ld=pt({mutationFn:ce.updateSettings,onSuccess:oe=>{t.setQueryData(["settings"],oe),P(oe),t.invalidateQueries({queryKey:["archiveStats"]}),o(i("settings.toast.settingsSaved"),"success")},onError:oe=>{o(`Failed to save: ${oe.message}`,"error")},onSettled:()=>{od.current=!1}}),af=pt({mutationFn:({id:oe,data:Nt})=>ce.updatePrinter(oe,Nt),onSuccess:()=>{t.invalidateQueries({queryKey:["printers"]}),o(i("settings.toast.cameraSettingsSaved"),"success")},onError:oe=>{o(`Failed to update printer: ${oe.message}`,"error")}});_.useEffect(()=>{if(!(Zm.current||!E||!De||!(De.auto_archive!==E.auto_archive||De.save_thumbnails!==E.save_thumbnails||De.capture_finish_photo!==E.capture_finish_photo||De.default_filament_cost!==E.default_filament_cost||De.currency!==E.currency||De.energy_cost_per_kwh!==E.energy_cost_per_kwh||De.energy_tracking_mode!==E.energy_tracking_mode||De.check_updates!==E.check_updates||(De.check_printer_firmware??!0)!==(E.check_printer_firmware??!0)||De.notification_language!==E.notification_language||De.ams_humidity_good!==E.ams_humidity_good||De.ams_humidity_fair!==E.ams_humidity_fair||De.ams_temp_good!==E.ams_temp_good||De.ams_temp_fair!==E.ams_temp_fair||De.ams_history_retention_days!==E.ams_history_retention_days||De.per_printer_mapping_expanded!==E.per_printer_mapping_expanded||De.date_format!==E.date_format||De.time_format!==E.time_format||De.default_printer_id!==E.default_printer_id||De.ftp_retry_enabled!==E.ftp_retry_enabled||De.ftp_retry_count!==E.ftp_retry_count||De.ftp_retry_delay!==E.ftp_retry_delay||De.ftp_timeout!==E.ftp_timeout||De.mqtt_enabled!==E.mqtt_enabled||De.mqtt_broker!==E.mqtt_broker||De.mqtt_port!==E.mqtt_port||De.mqtt_username!==E.mqtt_username||De.mqtt_password!==E.mqtt_password||De.mqtt_topic_prefix!==E.mqtt_topic_prefix||De.mqtt_use_tls!==E.mqtt_use_tls||De.external_url!==E.external_url||De.ha_enabled!==E.ha_enabled||De.ha_url!==E.ha_url||De.ha_token!==E.ha_token||(De.library_archive_mode??"ask")!==(E.library_archive_mode??"ask")||Number(De.library_disk_warning_gb??5)!==Number(E.library_disk_warning_gb??5)||(De.camera_view_mode??"window")!==(E.camera_view_mode??"window")||De.prometheus_enabled!==E.prometheus_enabled||De.prometheus_token!==E.prometheus_token))&&!od.current)return rf.current&&clearTimeout(rf.current),rf.current=setTimeout(()=>{if(od.current)return;od.current=!0;const Nt={auto_archive:E.auto_archive,save_thumbnails:E.save_thumbnails,capture_finish_photo:E.capture_finish_photo,default_filament_cost:E.default_filament_cost,currency:E.currency,energy_cost_per_kwh:E.energy_cost_per_kwh,energy_tracking_mode:E.energy_tracking_mode,check_updates:E.check_updates,check_printer_firmware:E.check_printer_firmware,notification_language:E.notification_language,ams_humidity_good:E.ams_humidity_good,ams_humidity_fair:E.ams_humidity_fair,ams_temp_good:E.ams_temp_good,ams_temp_fair:E.ams_temp_fair,ams_history_retention_days:E.ams_history_retention_days,per_printer_mapping_expanded:E.per_printer_mapping_expanded,date_format:E.date_format,time_format:E.time_format,default_printer_id:E.default_printer_id,ftp_retry_enabled:E.ftp_retry_enabled,ftp_retry_count:E.ftp_retry_count,ftp_retry_delay:E.ftp_retry_delay,ftp_timeout:E.ftp_timeout,mqtt_enabled:E.mqtt_enabled,mqtt_broker:E.mqtt_broker,mqtt_port:E.mqtt_port,mqtt_username:E.mqtt_username,mqtt_password:E.mqtt_password,mqtt_topic_prefix:E.mqtt_topic_prefix,mqtt_use_tls:E.mqtt_use_tls,external_url:E.external_url,ha_enabled:E.ha_enabled,ha_url:E.ha_url,ha_token:E.ha_token,library_archive_mode:E.library_archive_mode,library_disk_warning_gb:E.library_disk_warning_gb,camera_view_mode:E.camera_view_mode,prometheus_enabled:E.prometheus_enabled,prometheus_token:E.prometheus_token};ld.mutate(Nt)},500),()=>{rf.current&&clearTimeout(rf.current)}},[E,De,ld]);const wn=_.useCallback((oe,Nt)=>{P(Un=>Un?{...Un,[oe]:Nt}:null)},[]),yk=async(oe,Nt,Un)=>{if(!Nt){o(i("settings.toast.enterCameraUrl"),"error");return}ct(sr=>({...sr,[oe]:!0})),dt(sr=>({...sr,[oe]:null}));try{const sr=await ce.testExternalCamera(oe,Nt,Un);dt(To=>({...To,[oe]:sr})),sr.success?o(i("settings.toast.cameraConnected",{resolution:sr.resolution||""}),"success"):o(sr.error||i("settings.toast.connectionFailed"),"error")}catch(sr){const To=sr instanceof Error?sr.message:i("settings.toast.testFailed");dt(cd=>({...cd,[oe]:{success:!1,error:To}})),o(To,"error")}finally{ct(sr=>({...sr,[oe]:!1}))}},[ex,Fv]=_.useState({}),sf=_.useRef({}),Iv=_.useRef(new Set);_.useEffect(()=>{if(Vt){const oe={};Vt.forEach(Nt=>{Nt.external_camera_url&&!Iv.current.has(Nt.id)&&(oe[Nt.id]=Nt.external_camera_url,Iv.current.add(Nt.id))}),Object.keys(oe).length>0&&Fv(Nt=>({...Nt,...oe}))}},[Vt]);const vk=(oe,Nt)=>{Fv(Un=>({...Un,[oe]:Nt})),sf.current[oe]&&clearTimeout(sf.current[oe]),sf.current[oe]=setTimeout(()=>{af.mutate({id:oe,data:{external_camera_url:Nt||null}})},800)},Uv=(oe,Nt)=>{const Un={};Nt.type!==void 0&&(Un.external_camera_type=Nt.type||null),Nt.enabled!==void 0&&(Un.external_camera_enabled=Nt.enabled),af.mutate({id:oe,data:Un})};return Ve||!E?a.jsx("div",{className:"p-4 md:p-8 flex justify-center",children:a.jsx(ut,{className:"w-8 h-8 text-bambu-green animate-spin"})}):a.jsxs("div",{className:"p-4 md:p-8",children:[a.jsxs("div",{className:"mb-8",children:[a.jsx("h1",{className:"text-2xl font-bold text-white",children:i("settings.title")}),a.jsx("p",{className:"text-bambu-gray",children:i("settings.configureBambuddy")})]}),a.jsxs("div",{className:"flex flex-wrap gap-1 mb-6 border-b border-bambu-dark-tertiary overflow-y-auto max-h-32",children:[a.jsx("button",{onClick:()=>de("general"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px ${be==="general"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:i("settings.tabs.general")}),a.jsxs("button",{onClick:()=>de("plugs"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${be==="plugs"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[a.jsx(rl,{className:"w-4 h-4"}),i("settings.tabs.smartPlugs"),_e&&_e.length>0&&a.jsx("span",{className:"text-xs bg-bambu-dark-tertiary px-1.5 py-0.5 rounded-full",children:_e.length})]}),a.jsxs("button",{onClick:()=>de("email"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${be==="email"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[a.jsx(oy,{className:"w-4 h-4"}),i("settings.tabs.globalEmail")||"Global Email"]}),a.jsxs("button",{onClick:()=>de("notifications"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${be==="notifications"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[a.jsx(Og,{className:"w-4 h-4"}),i("settings.tabs.notifications"),Ct&&Ct.length>0&&a.jsx("span",{className:"text-xs bg-bambu-dark-tertiary px-1.5 py-0.5 rounded-full",children:Ct.length})]}),a.jsxs("button",{onClick:()=>de("filament"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${be==="filament"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[a.jsx(Ude,{className:"w-4 h-4"}),i("settings.tabs.filament")]}),a.jsxs("button",{onClick:()=>de("network"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${be==="network"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[a.jsx(Fg,{className:"w-4 h-4"}),i("settings.tabs.network"),a.jsx("span",{className:`w-2 h-2 rounded-full ${fr?.enabled?"bg-green-400":"bg-gray-500"}`})]}),a.jsxs("button",{onClick:()=>de("apikeys"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${be==="apikeys"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[a.jsx(Wo,{className:"w-4 h-4"}),i("settings.tabs.apiKeys"),Bt&&Bt.length>0&&a.jsx("span",{className:"text-xs bg-bambu-dark-tertiary px-1.5 py-0.5 rounded-full",children:Bt.length})]}),a.jsxs("button",{onClick:()=>de("virtual-printer"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${be==="virtual-printer"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[a.jsx(Or,{className:"w-4 h-4"}),i("settings.tabs.virtualPrinter"),a.jsx("span",{className:`w-2 h-2 rounded-full ${Xt?"bg-green-400":"bg-gray-500"}`})]}),a.jsxs("button",{onClick:()=>de("users"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${be==="users"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[a.jsx(Kf,{className:"w-4 h-4"}),i("settings.tabs.users"),l&&a.jsx("span",{className:"w-2 h-2 rounded-full bg-green-400"})]}),a.jsxs("button",{onClick:()=>de("backup"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${be==="backup"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[a.jsx(ju,{className:"w-4 h-4"}),i("settings.tabs.backup"),a.jsx("span",{className:`w-2 h-2 rounded-full ${Dt?.is_authenticated&&nt?.configured&&nt?.enabled?"bg-green-400":"bg-gray-500"}`})]})]}),be==="general"&&a.jsxs("div",{className:"flex flex-col lg:flex-row gap-6 lg:gap-8",children:[a.jsxs("div",{className:"space-y-6 flex-1 lg:max-w-xl",children:[a.jsxs(_t,{children:[a.jsx(Pn,{children:a.jsx("h2",{className:"text-lg font-semibold text-white",children:i("settings.general")})}),a.jsxs(Mt,{className:"space-y-4",children:[a.jsxs("div",{children:[a.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[a.jsx(bh,{className:"w-4 h-4 inline mr-1"}),i("settings.language")]}),a.jsxs("div",{className:"relative",children:[a.jsx("select",{value:s.language,onChange:oe=>{s.changeLanguage(oe.target.value),o(i("settings.toast.settingsSaved"),"success")},className:"w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer",children:Wz.map(oe=>a.jsxs("option",{value:oe.code,children:[oe.nativeName," (",oe.name,")"]},oe.code))}),a.jsx(Sr,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:i("settings.languageDescription")})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:i("settings.defaultView")}),a.jsxs("div",{className:"relative",children:[a.jsx("select",{value:H,onChange:oe=>Tt(oe.target.value),className:"w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer",children:cy.map(oe=>a.jsx("option",{value:oe.to,children:i(oe.labelKey)},oe.id))}),a.jsx(Sr,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:i("settings.defaultViewDescription")})]}),a.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Date Format"}),a.jsxs("div",{className:"relative",children:[a.jsxs("select",{value:E.date_format||"system",onChange:oe=>wn("date_format",oe.target.value),className:"w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer",children:[a.jsx("option",{value:"system",children:i("settings.systemDefault")}),a.jsx("option",{value:"us",children:"US (MM/DD/YYYY)"}),a.jsx("option",{value:"eu",children:"EU (DD/MM/YYYY)"}),a.jsx("option",{value:"iso",children:"ISO (YYYY-MM-DD)"})]}),a.jsx(Sr,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Time Format"}),a.jsxs("div",{className:"relative",children:[a.jsxs("select",{value:E.time_format||"system",onChange:oe=>wn("time_format",oe.target.value),className:"w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer",children:[a.jsx("option",{value:"system",children:i("settings.systemDefault")}),a.jsx("option",{value:"12h",children:"12-hour (3:30 PM)"}),a.jsx("option",{value:"24h",children:"24-hour (15:30)"})]}),a.jsx(Sr,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]})]})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Default Printer"}),a.jsxs("div",{className:"relative",children:[a.jsxs("select",{value:E.default_printer_id??"",onChange:oe=>wn("default_printer_id",oe.target.value?Number(oe.target.value):null),className:"w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer",children:[a.jsx("option",{value:"",children:i("settings.noDefaultPrinter")}),Vt?.map(oe=>a.jsx("option",{value:oe.id,children:oe.name},oe.id))]}),a.jsx(Sr,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Pre-select this printer for uploads, reprints, and other operations."})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white",children:i("settings.sidebarOrder")}),a.jsx("p",{className:"text-sm text-bambu-gray",children:"Drag items in the sidebar to reorder. Reset to default order here."})]}),a.jsxs(ke,{variant:"secondary",size:"sm",onClick:he,children:[a.jsx($h,{className:"w-4 h-4"}),"Reset"]})]})]})]}),a.jsxs(_t,{children:[a.jsx(Pn,{children:a.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[a.jsx(UK,{className:"w-5 h-5"}),"Appearance"]})}),a.jsxs(Mt,{className:"space-y-6",children:[a.jsxs("div",{className:`space-y-3 p-4 rounded-lg border ${d==="dark"?"border-bambu-green bg-bambu-green/5":"border-bambu-dark-tertiary"}`,children:[a.jsxs("h3",{className:"text-sm font-medium text-white flex items-center gap-2",children:["Dark Mode",d==="dark"&&a.jsx("span",{className:"text-xs text-bambu-green",children:"(active)"})]}),a.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Background"}),a.jsxs("select",{value:m,onChange:oe=>{S(oe.target.value),o(i("settings.toast.settingsSaved"),"success")},className:"w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[a.jsx("option",{value:"neutral",children:"Neutral"}),a.jsx("option",{value:"warm",children:"Warm"}),a.jsx("option",{value:"cool",children:"Cool"}),a.jsx("option",{value:"oled",children:"OLED Black"}),a.jsx("option",{value:"slate",children:"Slate Blue"}),a.jsx("option",{value:"forest",children:"Forest Green"})]})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Accent"}),a.jsxs("select",{value:p,onChange:oe=>{N(oe.target.value),o(i("settings.toast.settingsSaved"),"success")},className:"w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[a.jsx("option",{value:"green",children:"Green"}),a.jsx("option",{value:"teal",children:"Teal"}),a.jsx("option",{value:"blue",children:"Blue"}),a.jsx("option",{value:"orange",children:"Orange"}),a.jsx("option",{value:"purple",children:"Purple"}),a.jsx("option",{value:"red",children:"Red"})]})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Style"}),a.jsxs("select",{value:h,onChange:oe=>{y(oe.target.value),o(i("settings.toast.settingsSaved"),"success")},className:"w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[a.jsx("option",{value:"classic",children:"Classic"}),a.jsx("option",{value:"glow",children:"Glow"}),a.jsx("option",{value:"vibrant",children:"Vibrant"})]})]})]})]}),a.jsxs("div",{className:`space-y-3 p-4 rounded-lg border ${d==="light"?"border-bambu-green bg-bambu-green/5":"border-bambu-dark-tertiary"}`,children:[a.jsxs("h3",{className:"text-sm font-medium text-white flex items-center gap-2",children:["Light Mode",d==="light"&&a.jsx("span",{className:"text-xs text-bambu-green",children:"(active)"})]}),a.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Background"}),a.jsxs("select",{value:v,onChange:oe=>{k(oe.target.value),o(i("settings.toast.settingsSaved"),"success")},className:"w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[a.jsx("option",{value:"neutral",children:"Neutral"}),a.jsx("option",{value:"warm",children:"Warm"}),a.jsx("option",{value:"cool",children:"Cool"})]})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Accent"}),a.jsxs("select",{value:x,onChange:oe=>{C(oe.target.value),o(i("settings.toast.settingsSaved"),"success")},className:"w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[a.jsx("option",{value:"green",children:"Green"}),a.jsx("option",{value:"teal",children:"Teal"}),a.jsx("option",{value:"blue",children:"Blue"}),a.jsx("option",{value:"orange",children:"Orange"}),a.jsx("option",{value:"purple",children:"Purple"}),a.jsx("option",{value:"red",children:"Red"})]})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Style"}),a.jsxs("select",{value:b,onChange:oe=>{A(oe.target.value),o(i("settings.toast.settingsSaved"),"success")},className:"w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[a.jsx("option",{value:"classic",children:"Classic"}),a.jsx("option",{value:"glow",children:"Glow"}),a.jsx("option",{value:"vibrant",children:"Vibrant"})]})]})]})]}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Toggle between dark and light mode using the sun/moon icon in the sidebar."})]})]}),a.jsxs(_t,{children:[a.jsx(Pn,{children:a.jsx("h2",{className:"text-lg font-semibold text-white",children:i("settings.archiveSettings")})}),a.jsxs(Mt,{className:"space-y-4",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white",children:"Auto-archive prints"}),a.jsx("p",{className:"text-sm text-bambu-gray",children:"Automatically save 3MF files when prints complete"})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:E.auto_archive,onChange:oe=>wn("auto_archive",oe.target.checked),className:"sr-only peer"}),a.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white",children:i("settings.saveThumbnails")}),a.jsx("p",{className:"text-sm text-bambu-gray",children:"Extract and save preview images from 3MF files"})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:E.save_thumbnails,onChange:oe=>wn("save_thumbnails",oe.target.checked),className:"sr-only peer"}),a.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white",children:i("settings.captureFinishPhoto")}),a.jsx("p",{className:"text-sm text-bambu-gray",children:"Take a photo from printer camera when print completes"})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:E.capture_finish_photo,onChange:oe=>wn("capture_finish_photo",oe.target.checked),className:"sr-only peer"}),a.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),E.capture_finish_photo&&dn&&!dn.installed&&a.jsxs("div",{className:"flex items-start gap-2 p-3 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[a.jsx(kn,{className:"w-5 h-5 text-yellow-500 flex-shrink-0 mt-0.5"}),a.jsxs("div",{className:"text-sm",children:[a.jsx("p",{className:"text-yellow-500 font-medium",children:"ffmpeg not installed"}),a.jsxs("p",{className:"text-bambu-gray mt-1",children:["Camera capture requires ffmpeg. Install it via"," ",a.jsx("code",{className:"bg-bambu-dark-tertiary px-1 rounded",children:"brew install ffmpeg"})," (macOS) or"," ",a.jsx("code",{className:"bg-bambu-dark-tertiary px-1 rounded",children:"apt install ffmpeg"})," (Linux)."]})]})]})]})]})]}),a.jsxs("div",{className:"space-y-6 flex-1 lg:max-w-md",children:[a.jsxs(_t,{children:[a.jsx(Pn,{children:a.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[a.jsx(hO,{className:"w-5 h-5 text-bambu-green"}),"Camera"]})}),a.jsxs(Mt,{className:"space-y-4",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Camera View Mode"}),a.jsxs("select",{value:E.camera_view_mode??"window",onChange:oe=>wn("camera_view_mode",oe.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[a.jsx("option",{value:"window",children:i("settings.newWindow")}),a.jsx("option",{value:"embedded",children:i("settings.embeddedOverlay")})]}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:E.camera_view_mode==="embedded"?"Camera opens in a resizable overlay on the main screen":"Camera opens in a separate browser window"})]}),a.jsxs("div",{className:"border-t border-bambu-dark-tertiary pt-4 mt-4",children:[a.jsx("h3",{className:"text-sm font-medium text-white mb-2",children:i("settings.externalCameras")}),a.jsx("p",{className:"text-xs text-bambu-gray mb-3",children:"Configure external cameras to replace the built-in printer camera. Supports MJPEG streams, RTSP, HTTP snapshots, and USB cameras (V4L2). When enabled, the external camera is used for live view and finish photos."}),Vt&&Vt.length>0?a.jsx("div",{className:"space-y-3",children:Vt.map(oe=>a.jsxs("div",{className:"p-3 bg-bambu-dark rounded-lg",children:[a.jsxs("div",{className:"flex items-center justify-between mb-2",children:[a.jsx("span",{className:"text-white font-medium text-sm",children:oe.name}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:oe.external_camera_enabled,onChange:Nt=>Uv(oe.id,{enabled:Nt.target.checked}),className:"sr-only peer"}),a.jsx("div",{className:"w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green"})]})]}),oe.external_camera_enabled&&a.jsxs("div",{className:"space-y-2 mt-2",children:[a.jsx("input",{type:"text",placeholder:oe.external_camera_type==="usb"?"Device path (/dev/video0)":"Camera URL (rtsp://... or http://...)",value:ex[oe.id]??oe.external_camera_url??"",onChange:Nt=>vk(oe.id,Nt.target.value),className:"w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none"}),a.jsxs("div",{className:"flex gap-2",children:[a.jsxs("select",{value:oe.external_camera_type||"mjpeg",onChange:Nt=>Uv(oe.id,{type:Nt.target.value}),className:"flex-1 px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none",children:[a.jsx("option",{value:"mjpeg",children:"MJPEG Stream"}),a.jsx("option",{value:"rtsp",children:"RTSP Stream"}),a.jsx("option",{value:"snapshot",children:"HTTP Snapshot"}),a.jsx("option",{value:"usb",children:"USB Camera (V4L2)"})]}),a.jsx(ke,{size:"sm",variant:"secondary",onClick:()=>yk(oe.id,ex[oe.id]??oe.external_camera_url??"",oe.external_camera_type||"mjpeg"),disabled:ht[oe.id]||!(ex[oe.id]??oe.external_camera_url),children:ht[oe.id]?a.jsx(ut,{className:"w-4 h-4 animate-spin"}):"Test"})]}),Je[oe.id]&&a.jsx("div",{className:`text-xs flex items-center gap-1 ${Je[oe.id]?.success?"text-green-500":"text-red-500"}`,children:Je[oe.id]?.success?a.jsxs(a.Fragment,{children:[a.jsx(Nr,{className:"w-3 h-3"}),"Connected",Je[oe.id]?.resolution&&` (${Je[oe.id]?.resolution})`]}):a.jsxs(a.Fragment,{children:[a.jsx(ta,{className:"w-3 h-3"}),Je[oe.id]?.error||i("settings.toast.connectionFailed")]})})]})]},oe.id))}):a.jsx("p",{className:"text-xs text-bambu-gray italic",children:i("settings.noPrintersConfigured")})]})]})]}),a.jsxs(_t,{children:[a.jsx(Pn,{children:a.jsx("h2",{className:"text-lg font-semibold text-white",children:i("settings.costTracking")})}),a.jsxs(Mt,{className:"space-y-4",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Default filament cost (per kg)"}),a.jsx("input",{type:"number",step:"0.01",min:"0",value:E.default_filament_cost,onChange:oe=>wn("default_filament_cost",parseFloat(oe.target.value)||0),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Currency"}),a.jsxs("select",{value:E.currency,onChange:oe=>wn("currency",oe.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[a.jsx("option",{value:"USD",children:"USD ($)"}),a.jsx("option",{value:"EUR",children:"EUR (€)"}),a.jsx("option",{value:"GBP",children:"GBP (£)"}),a.jsx("option",{value:"CHF",children:"CHF (Fr.)"}),a.jsx("option",{value:"JPY",children:"JPY (¥)"}),a.jsx("option",{value:"CNY",children:"CNY (¥)"}),a.jsx("option",{value:"CAD",children:"CAD ($)"}),a.jsx("option",{value:"AUD",children:"AUD ($)"})]})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Electricity cost per kWh"}),a.jsx("input",{type:"number",step:"0.01",min:"0",value:E.energy_cost_per_kwh,onChange:oe=>wn("energy_cost_per_kwh",parseFloat(oe.target.value)||0),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Energy display mode"}),a.jsxs("select",{value:E.energy_tracking_mode||"total",onChange:oe=>wn("energy_tracking_mode",oe.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[a.jsx("option",{value:"print",children:i("settings.printsOnly")}),a.jsx("option",{value:"total",children:i("settings.totalConsumption")})]}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:E.energy_tracking_mode==="print"?"Dashboard shows sum of energy used during prints":"Dashboard shows lifetime energy from smart plugs"})]})]})]}),a.jsxs(_t,{children:[a.jsx(Pn,{children:a.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[a.jsx(ps,{className:"w-5 h-5 text-bambu-green"}),"File Manager"]})}),a.jsxs(Mt,{className:"space-y-4",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Create Archive Entry When Printing"}),a.jsxs("select",{value:E.library_archive_mode??"ask",onChange:oe=>wn("library_archive_mode",oe.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[a.jsx("option",{value:"always",children:i("settings.archiveMode.always")}),a.jsx("option",{value:"never",children:i("settings.archiveMode.never")}),a.jsx("option",{value:"ask",children:i("settings.archiveMode.ask")})]}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"When printing from File Manager, optionally create an archive entry"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Low Disk Space Warning"}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("input",{type:"number",min:"0.5",max:"100",step:"0.5",value:E.library_disk_warning_gb??5,onChange:oe=>wn("library_disk_warning_gb",parseFloat(oe.target.value)||5),className:"w-24 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"}),a.jsx("span",{className:"text-bambu-gray",children:"GB"})]}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Show warning when free disk space falls below this threshold"})]})]})]})]}),a.jsxs("div",{className:"space-y-6 flex-1 lg:max-w-sm",children:[a.jsx(nQe,{}),a.jsxs(_t,{children:[a.jsx(Pn,{children:a.jsx("h2",{className:"text-lg font-semibold text-white",children:"Updates"})}),a.jsxs(Mt,{className:"space-y-4",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white",children:i("settings.checkForUpdatesLabel")}),a.jsx("p",{className:"text-sm text-bambu-gray",children:"Automatically check for new versions on startup"})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:E.check_updates,onChange:oe=>wn("check_updates",oe.target.checked),className:"sr-only peer"}),a.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white",children:i("settings.checkPrinterFirmware")}),a.jsx("p",{className:"text-sm text-bambu-gray",children:"Check for printer firmware updates from Bambu Lab"})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:E.check_printer_firmware??!0,onChange:oe=>wn("check_printer_firmware",oe.target.checked),className:"sr-only peer"}),a.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),a.jsxs("div",{className:"border-t border-bambu-dark-tertiary pt-4",children:[a.jsxs("div",{className:"flex items-center justify-between mb-2",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white",children:i("settings.currentVersion")}),a.jsxs("p",{className:"text-sm text-bambu-gray",children:["v",mn?.version||"..."]})]}),a.jsxs(ke,{variant:"secondary",size:"sm",onClick:()=>ir(),disabled:In,children:[In?a.jsx(ut,{className:"w-4 h-4 animate-spin"}):a.jsx(Ir,{className:"w-4 h-4"}),"Check now"]})]}),en?.update_available?a.jsxs("div",{className:"mt-4 p-3 bg-bambu-green/10 border border-bambu-green/30 rounded-lg",children:[a.jsxs("div",{className:"flex items-start justify-between",children:[a.jsxs("div",{children:[a.jsxs("p",{className:"text-bambu-green font-medium",children:["Update available: v",en.latest_version]}),en.release_name&&en.release_name!==en.latest_version&&a.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:en.release_name})]}),a.jsxs("div",{className:"flex items-center gap-2",children:[en.release_notes&&a.jsx("button",{onClick:()=>we(!0),className:"text-bambu-gray hover:text-white transition-colors text-sm underline",children:"Release Notes"}),en.release_url&&a.jsx("a",{href:en.release_url,target:"_blank",rel:"noopener noreferrer",className:"text-bambu-gray hover:text-white transition-colors",title:i("settings.viewReleaseOnGitHub"),children:a.jsx(Xr,{className:"w-4 h-4"})})]})]}),ai?.status==="downloading"||ai?.status==="installing"?a.jsxs("div",{className:"mt-3",children:[a.jsxs("div",{className:"flex items-center gap-2 text-sm text-bambu-gray",children:[a.jsx(ut,{className:"w-4 h-4 animate-spin"}),a.jsx("span",{children:ai.message})]}),a.jsx("div",{className:"mt-2 w-full bg-bambu-dark-tertiary rounded-full h-2",children:a.jsx("div",{className:"bg-bambu-green h-2 rounded-full transition-all duration-300",style:{width:`${ai.progress}%`}})})]}):ai?.status==="complete"?a.jsx("div",{className:"mt-3 p-2 bg-bambu-green/20 rounded text-sm text-bambu-green",children:ai.message}):ai?.status==="error"?a.jsx("div",{className:"mt-3 p-2 bg-red-500/20 rounded text-sm text-red-400",children:ai.error||ai.message}):en?.is_docker?a.jsxs("div",{className:"mt-3 p-3 bg-bambu-dark-tertiary rounded-lg",children:[a.jsx("p",{className:"text-sm text-bambu-gray mb-2",children:"Update via Docker Compose:"}),a.jsx("code",{className:"block text-xs bg-bambu-dark p-2 rounded text-bambu-green font-mono",children:"docker compose pull && docker compose up -d"})]}):a.jsxs(ke,{className:"mt-3",onClick:()=>Qm.mutate(),disabled:Qm.isPending,children:[Qm.isPending?a.jsx(ut,{className:"w-4 h-4 animate-spin"}):a.jsx(Ni,{className:"w-4 h-4"}),"Install Update"]})]}):en?.error?a.jsxs("div",{className:"mt-2 p-2 bg-red-500/10 border border-red-500/30 rounded text-sm text-red-400",children:["Failed to check for updates: ",en.error]}):en&&!en.update_available?a.jsx("p",{className:"mt-2 text-sm text-bambu-gray",children:"You're running the latest version"}):null]})]})]}),a.jsxs(_t,{children:[a.jsx(Pn,{children:a.jsx("h2",{className:"text-lg font-semibold text-white",children:i("settings.dataManagement")})}),a.jsxs(Mt,{className:"space-y-4",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white",children:i("settings.clearNotificationLogs")}),a.jsx("p",{className:"text-sm text-bambu-gray",children:i("settings.clearNotificationLogsDescription")})]}),a.jsxs(ke,{variant:"secondary",size:"sm",onClick:()=>Se(!0),children:[a.jsx(cn,{className:"w-4 h-4"}),i("common.clear")]})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white",children:i("settings.resetUiPreferences")}),a.jsx("p",{className:"text-sm text-bambu-gray",children:i("settings.resetUiPreferencesDescription")})]}),a.jsxs(ke,{variant:"secondary",size:"sm",onClick:()=>U(!0),children:[a.jsx(cn,{className:"w-4 h-4"}),"Reset"]})]}),a.jsxs("div",{className:"flex items-center justify-between pt-4 border-t border-bambu-dark-tertiary",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white",children:"Backup & Restore"}),a.jsx("p",{className:"text-sm text-bambu-gray",children:"Export/import settings and configure GitHub backup"})]}),a.jsxs(ke,{variant:"secondary",size:"sm",onClick:()=>de("backup"),children:[a.jsx(ju,{className:"w-4 h-4"}),"Go to Backup"]})]})]})]})]})]}),be==="network"&&E&&a.jsxs("div",{className:"flex flex-col lg:flex-row gap-6",children:[a.jsxs("div",{className:"flex-1 lg:max-w-xl space-y-4",children:[a.jsxs(_t,{children:[a.jsx(Pn,{children:a.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[a.jsx(bh,{className:"w-5 h-5 text-blue-400"}),"External URL"]})}),a.jsxs(Mt,{className:"space-y-4",children:[a.jsx("p",{className:"text-sm text-bambu-gray",children:"The external URL where Bambuddy is accessible. Used for notification images and external integrations."}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Bambuddy URL"}),a.jsx("input",{type:"text",value:E.external_url??"",onChange:oe=>wn("external_url",oe.target.value),placeholder:"http://192.168.1.100:8000",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Include protocol and port (e.g., http://192.168.1.100:8000)"})]})]})]}),a.jsxs(_t,{children:[a.jsx(Pn,{children:a.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[a.jsx(Ir,{className:"w-5 h-5 text-blue-400"}),"FTP Retry"]})}),a.jsxs(Mt,{className:"space-y-4",children:[a.jsx("p",{className:"text-sm text-bambu-gray",children:"Retry FTP operations when printer WiFi is unreliable. Applies to 3MF downloads, print uploads, timelapse downloads, and firmware updates."}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white",children:i("settings.enableRetry")}),a.jsx("p",{className:"text-sm text-bambu-gray",children:"Automatically retry failed FTP operations"})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:E.ftp_retry_enabled??!0,onChange:oe=>wn("ftp_retry_enabled",oe.target.checked),className:"sr-only peer"}),a.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),E.ftp_retry_enabled&&a.jsxs("div",{className:"space-y-4 pt-2 border-t border-bambu-dark-tertiary",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Retry attempts"}),a.jsxs("div",{className:"relative w-44",children:[a.jsx("select",{value:E.ftp_retry_count??3,onChange:oe=>wn("ftp_retry_count",parseInt(oe.target.value)),className:"w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer",children:[1,2,3,4,5,6,7,8,9,10].map(oe=>a.jsxs("option",{value:oe,children:[oe," ",oe===1?"time":"times"]},oe))}),a.jsx(Sr,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Retry delay"}),a.jsxs("div",{className:"relative w-44",children:[a.jsx("select",{value:E.ftp_retry_delay??2,onChange:oe=>wn("ftp_retry_delay",parseInt(oe.target.value)),className:"w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer",children:[1,2,3,5,10,15,20,30].map(oe=>a.jsxs("option",{value:oe,children:[oe," ",oe===1?"second":"seconds"]},oe))}),a.jsx(Sr,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Connection timeout"}),a.jsxs("div",{className:"relative w-44",children:[a.jsx("select",{value:E.ftp_timeout??30,onChange:oe=>wn("ftp_timeout",parseInt(oe.target.value)),className:"w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer",children:[10,15,20,30,45,60,90,120].map(oe=>a.jsxs("option",{value:oe,children:[oe," seconds"]},oe))}),a.jsx(Sr,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Increase for printers with weak WiFi"})]})]})]})]})]}),a.jsxs("div",{className:"flex-1 lg:max-w-xl space-y-4",children:[a.jsxs(_t,{children:[a.jsx(Pn,{children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[a.jsx(Jy,{className:"w-5 h-5 text-bambu-green"}),"Home Assistant"]}),E.ha_enabled&&Tn&&a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("span",{className:`w-2.5 h-2.5 rounded-full ${Tn.success?"bg-green-400":"bg-red-400"}`}),a.jsx("span",{className:`text-sm ${Tn.success?"text-green-400":"text-red-400"}`,children:Tn.success?"Connected":"Disconnected"})]})]})}),a.jsxs(Mt,{className:"space-y-4",children:[a.jsx("p",{className:"text-sm text-bambu-gray",children:"Connect to Home Assistant to control smart plugs via HA's REST API. Supports switch, light, input_boolean, and script entities."}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white",children:i("settings.enableHomeAssistant")}),a.jsx("p",{className:"text-xs text-bambu-gray",children:i("settings.homeAssistantDescription")})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:E.ha_enabled??!1,onChange:oe=>wn("ha_enabled",oe.target.checked),className:"sr-only peer"}),a.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),E.ha_enabled&&a.jsxs(a.Fragment,{children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Home Assistant URL"}),a.jsx("input",{type:"text",value:E.ha_url??"",onChange:oe=>wn("ha_url",oe.target.value),placeholder:"http://192.168.1.100:8123",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Long-Lived Access Token"}),a.jsx("input",{type:"password",value:E.ha_token??"",onChange:oe=>wn("ha_token",oe.target.value),placeholder:"eyJ0eXAiOiJKV1QiLC...",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Create a token in HA: Profile → Long-Lived Access Tokens → Create Token"})]}),E.ha_url&&E.ha_token&&a.jsx("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:a.jsxs(ke,{variant:"secondary",size:"sm",disabled:ii,onClick:async()=>{je(!0),di(null);try{const oe=await ce.testHAConnection(E.ha_url,E.ha_token);di(oe)}catch(oe){di({success:!1,message:null,error:oe instanceof Error?oe.message:i("common.unknownError")})}finally{je(!1)}},children:[ii?a.jsx(ut,{className:"w-4 h-4 animate-spin"}):a.jsx(Fg,{className:"w-4 h-4"}),i("settings.testConnection")]})})]})]})]}),a.jsxs(_t,{children:[a.jsx(Pn,{children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[a.jsx(Fg,{className:"w-5 h-5 text-blue-400"}),"MQTT Publishing"]}),fr?.enabled&&a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("span",{className:`w-2.5 h-2.5 rounded-full ${fr.connected?"bg-green-400":"bg-red-400"}`}),a.jsx("span",{className:`text-sm ${fr.connected?"text-green-400":"text-red-400"}`,children:fr.connected?"Connected":"Disconnected"})]})]})}),a.jsxs(Mt,{className:"space-y-4",children:[a.jsx("p",{className:"text-sm text-bambu-gray",children:"Publish BamBuddy events to an external MQTT broker for integration with Node-RED, Home Assistant, and other automation systems."}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white",children:i("settings.enableMqtt")}),a.jsx("p",{className:"text-sm text-bambu-gray",children:"Publish events to external MQTT broker"})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:E.mqtt_enabled??!1,onChange:oe=>wn("mqtt_enabled",oe.target.checked),className:"sr-only peer"}),a.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),E.mqtt_enabled&&a.jsxs("div",{className:"space-y-4 pt-2 border-t border-bambu-dark-tertiary",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Broker hostname"}),a.jsx("input",{type:"text",value:E.mqtt_broker??"",onChange:oe=>wn("mqtt_broker",oe.target.value),placeholder:"mqtt.example.com or 192.168.1.100",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),a.jsxs("div",{className:"flex items-end gap-4",children:[a.jsxs("div",{className:"flex-1",children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Port"}),a.jsx("input",{type:"number",min:"1",max:"65535",value:E.mqtt_port??1883,onChange:oe=>wn("mqtt_port",Math.min(65535,Math.max(1,parseInt(oe.target.value)||1883))),className:"w-24 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),a.jsxs("div",{className:"flex items-center gap-3 pb-2",children:[a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:E.mqtt_use_tls??!1,onChange:oe=>{const Nt=oe.target.checked;wn("mqtt_use_tls",Nt);const Un=E.mqtt_port??1883;Nt&&Un===1883?wn("mqtt_port",8883):!Nt&&Un===8883&&wn("mqtt_port",1883)},className:"sr-only peer"}),a.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]}),a.jsx("span",{className:"text-white text-sm",children:i("settings.useTls")})]})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Username (optional)"}),a.jsx("input",{type:"text",value:E.mqtt_username??"",onChange:oe=>wn("mqtt_username",oe.target.value),placeholder:i("settings.leaveEmptyForAnonymous"),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Password (optional)"}),a.jsx("input",{type:"password",value:E.mqtt_password??"",onChange:oe=>wn("mqtt_password",oe.target.value),placeholder:i("settings.leaveEmptyForAnonymous"),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Topic prefix"}),a.jsx("input",{type:"text",value:E.mqtt_topic_prefix??"bambuddy",onChange:oe=>wn("mqtt_topic_prefix",oe.target.value),placeholder:"bambuddy",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"}),a.jsxs("p",{className:"text-xs text-bambu-gray mt-1",children:["Topics will be: ",E.mqtt_topic_prefix||"bambuddy","/printers//status, etc."]})]}),fr&&a.jsx("div",{className:"pt-3 mt-3 border-t border-bambu-dark-tertiary",children:a.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[a.jsx("span",{className:`w-2 h-2 rounded-full ${fr.connected?"bg-green-400":"bg-red-400"}`}),a.jsx("span",{className:"text-bambu-gray",children:fr.connected?a.jsxs(a.Fragment,{children:[i("settings.mqttConnectedTo")," ",a.jsxs("span",{className:"text-white",children:[fr.broker,":",fr.port]})]}):i("settings.spoolmanDisconnected")})]})})]})]})]})]}),a.jsx("div",{className:"flex-1 lg:max-w-md space-y-4",children:a.jsxs(_t,{children:[a.jsx(Pn,{children:a.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[a.jsx(WP,{className:"w-5 h-5 text-orange-400"}),"Prometheus Metrics"]})}),a.jsxs(Mt,{className:"space-y-4",children:[a.jsxs("p",{className:"text-sm text-bambu-gray",children:["Expose printer metrics at ",a.jsx("code",{className:"bg-bambu-dark px-1 rounded",children:"/api/v1/metrics"})," for Prometheus/Grafana monitoring."]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white",children:i("settings.enableMetricsEndpoint")}),a.jsx("p",{className:"text-xs text-bambu-gray",children:i("settings.prometheusDescription")})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:E.prometheus_enabled??!1,onChange:oe=>wn("prometheus_enabled",oe.target.checked),className:"sr-only peer"}),a.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),E.prometheus_enabled&&a.jsxs("div",{className:"space-y-4 pt-2 border-t border-bambu-dark-tertiary",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Bearer Token (optional)"}),a.jsx("input",{type:"password",value:E.prometheus_token??"",onChange:oe=>wn("prometheus_token",oe.target.value),placeholder:i("settings.leaveEmptyForNoAuth"),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"}),a.jsxs("p",{className:"text-xs text-bambu-gray mt-1",children:["If set, requests must include ",a.jsx("code",{className:"bg-bambu-dark px-1 rounded",children:"Authorization: Bearer "})]})]}),a.jsxs("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:[a.jsx("p",{className:"text-sm text-white mb-2",children:i("settings.availableMetrics")}),a.jsxs("div",{className:"text-xs text-bambu-gray space-y-1",children:[a.jsxs("p",{children:[a.jsx("code",{className:"text-orange-400",children:"bambuddy_printer_connected"})," - Connection status"]}),a.jsxs("p",{children:[a.jsx("code",{className:"text-orange-400",children:"bambuddy_printer_state"})," - Printer state (idle/printing/etc)"]}),a.jsxs("p",{children:[a.jsx("code",{className:"text-orange-400",children:"bambuddy_print_progress"})," - Print progress 0-100%"]}),a.jsxs("p",{children:[a.jsx("code",{className:"text-orange-400",children:"bambuddy_bed_temp_celsius"})," - Bed temperature"]}),a.jsxs("p",{children:[a.jsx("code",{className:"text-orange-400",children:"bambuddy_nozzle_temp_celsius"})," - Nozzle temperature"]}),a.jsxs("p",{children:[a.jsx("code",{className:"text-orange-400",children:"bambuddy_prints_total"})," - Total prints by result"]}),a.jsx("p",{className:"text-bambu-gray/70 italic",children:"...and more (layers, fans, queue, filament usage)"})]})]})]})]})]})})]}),Tn&&a.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",children:a.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg p-6 max-w-md w-full mx-4",children:[a.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[Tn.success?a.jsx(Nr,{className:"w-8 h-8 text-green-400"}):a.jsx(ta,{className:"w-8 h-8 text-red-400"}),a.jsx("h3",{className:"text-lg font-medium text-white",children:Tn.success?"Connection Successful":"Connection Failed"})]}),a.jsx("p",{className:"text-bambu-gray mb-6",children:Tn.success?Tn.message||"Successfully connected to Home Assistant.":Tn.error||"Failed to connect to Home Assistant."}),a.jsx("div",{className:"flex justify-end",children:a.jsx(ke,{variant:"primary",onClick:()=>di(null),children:"OK"})})]})}),be==="plugs"&&a.jsxs("div",{className:"max-w-4xl",children:[a.jsxs("div",{className:"flex items-start justify-between mb-6",children:[a.jsxs("div",{children:[a.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[a.jsx(rl,{className:"w-5 h-5 text-bambu-green"}),"Smart Plugs"]}),a.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:"Connect smart plugs (Tasmota or Home Assistant) to automate power control and track energy usage for your printers."})]}),a.jsxs("div",{className:"flex items-center gap-2 pt-1 shrink-0",children:[_e&&_e.filter(oe=>oe.enabled).length>1&&a.jsxs(a.Fragment,{children:[a.jsxs(ke,{variant:"secondary",size:"sm",className:"whitespace-nowrap",onClick:()=>Z("on"),disabled:bl.isPending,title:i("settings.turnAllPlugsOn"),children:[bl.isPending?a.jsx(ut,{className:"w-4 h-4 animate-spin"}):a.jsx(Zu,{className:"w-4 h-4 text-bambu-green"}),"All On"]}),a.jsxs(ke,{variant:"secondary",size:"sm",className:"whitespace-nowrap",onClick:()=>Z("off"),disabled:bl.isPending,title:i("settings.turnAllPlugsOff"),children:[bl.isPending?a.jsx(ut,{className:"w-4 h-4 animate-spin"}):a.jsx(HM,{className:"w-4 h-4 text-red-400"}),"All Off"]})]}),a.jsxs(ke,{className:"whitespace-nowrap",onClick:()=>{L(null),j(!0)},children:[a.jsx(dr,{className:"w-4 h-4"}),"Add Smart Plug"]})]})]}),_e&&_e.length>0&&a.jsxs(_t,{className:"mb-6",children:[a.jsx(Pn,{children:a.jsxs("h3",{className:"text-base font-semibold text-white flex items-center gap-2",children:[a.jsx(Dh,{className:"w-4 h-4 text-yellow-400"}),"Energy Summary",Ye&&a.jsx(ut,{className:"w-4 h-4 animate-spin text-bambu-gray ml-2"})]})}),a.jsx(Mt,{children:et?a.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[a.jsxs("div",{className:"bg-bambu-dark rounded-lg p-3",children:[a.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-xs mb-1",children:[a.jsx(Dh,{className:"w-3 h-3"}),"Current Power"]}),a.jsxs("div",{className:"text-xl font-bold text-white",children:[et.totalPower.toFixed(1),a.jsx("span",{className:"text-sm font-normal text-bambu-gray ml-1",children:"W"})]}),a.jsxs("div",{className:"text-xs text-bambu-gray mt-1",children:[et.reachableCount,"/",et.totalPlugs," plugs online"]})]}),a.jsxs("div",{className:"bg-bambu-dark rounded-lg p-3",children:[a.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-xs mb-1",children:[a.jsx(ei,{className:"w-3 h-3"}),"Today"]}),a.jsxs("div",{className:"text-xl font-bold text-white",children:[et.totalToday.toFixed(2),a.jsx("span",{className:"text-sm font-normal text-bambu-gray ml-1",children:"kWh"})]}),(E?.energy_cost_per_kwh??0)>0&&a.jsxs("div",{className:"text-xs text-bambu-gray mt-1",children:["~",(et.totalToday*(E?.energy_cost_per_kwh??0)).toFixed(2)," ",E?.currency]})]}),a.jsxs("div",{className:"bg-bambu-dark rounded-lg p-3",children:[a.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-xs mb-1",children:[a.jsx(WP,{className:"w-3 h-3"}),"Yesterday"]}),a.jsxs("div",{className:"text-xl font-bold text-white",children:[et.totalYesterday.toFixed(2),a.jsx("span",{className:"text-sm font-normal text-bambu-gray ml-1",children:"kWh"})]}),(E?.energy_cost_per_kwh??0)>0&&a.jsxs("div",{className:"text-xs text-bambu-gray mt-1",children:["~",(et.totalYesterday*(E?.energy_cost_per_kwh??0)).toFixed(2)," ",E?.currency]})]}),a.jsxs("div",{className:"bg-bambu-dark rounded-lg p-3",children:[a.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-xs mb-1",children:[a.jsx(zP,{className:"w-3 h-3"}),"Total"]}),a.jsxs("div",{className:"text-xl font-bold text-white",children:[et.totalLifetime.toFixed(1),a.jsx("span",{className:"text-sm font-normal text-bambu-gray ml-1",children:"kWh"})]}),(E?.energy_cost_per_kwh??0)>0&&a.jsxs("div",{className:"text-xs text-bambu-gray mt-1",children:["~",(et.totalLifetime*(E?.energy_cost_per_kwh??0)).toFixed(2)," ",E?.currency]})]})]}):Ye?null:a.jsx("p",{className:"text-sm text-bambu-gray",children:"Enable plugs to see energy summary"})})]}),Re?a.jsx("div",{className:"flex justify-center py-12",children:a.jsx(ut,{className:"w-8 h-8 text-bambu-green animate-spin"})}):_e&&_e.length>0?a.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:_e.map(oe=>a.jsx($Ye,{plug:oe,onEdit:Nt=>{L(Nt),j(!0)}},oe.id))}):a.jsx(_t,{children:a.jsx(Mt,{className:"py-12",children:a.jsxs("div",{className:"text-center text-bambu-gray",children:[a.jsx(rl,{className:"w-16 h-16 mx-auto mb-4 opacity-30"}),a.jsx("p",{className:"text-lg font-medium text-white mb-2",children:i("settings.noSmartPlugsTitle")}),a.jsx("p",{className:"text-sm mb-4",children:i("settings.noSmartPlugsDescription")}),a.jsxs(ke,{onClick:()=>{L(null),j(!0)},children:[a.jsx(dr,{className:"w-4 h-4"}),i("settings.addFirstSmartPlug")]})]})})})]}),be==="notifications"&&a.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-8",children:[a.jsxs("div",{children:[a.jsxs("div",{className:"flex items-center justify-between mb-4",children:[a.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[a.jsx(Og,{className:"w-5 h-5 text-bambu-green"}),i("settings.providers")]}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsxs(ke,{size:"sm",variant:"secondary",onClick:()=>re(!0),children:[a.jsx(sy,{className:"w-4 h-4"}),i("settings.log")]}),Ct&&Ct.length>0&&a.jsxs(ke,{size:"sm",variant:"secondary",onClick:()=>{gl(null),sd.mutate()},disabled:sd.isPending,children:[sd.isPending?a.jsx(ut,{className:"w-4 h-4 animate-spin"}):a.jsx($M,{className:"w-4 h-4"}),i("settings.testAll")]}),a.jsxs(ke,{size:"sm",onClick:()=>{q(null),R(!0)},children:[a.jsx(dr,{className:"w-4 h-4"}),"Add"]})]})]}),a.jsx(_t,{className:"mb-4",children:a.jsx(Mt,{className:"py-3",children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white text-sm font-medium",children:i("settings.notificationLanguage")}),a.jsx("p",{className:"text-xs text-bambu-gray",children:i("settings.notificationLanguageDescription")})]}),a.jsx("select",{value:E.notification_language||"en",onChange:oe=>wn("notification_language",oe.target.value),className:"px-2 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:outline-none focus:ring-1 focus:ring-bambu-green",children:Wz.map(oe=>a.jsx("option",{value:oe.code,children:oe.nativeName},oe.code))})]})})}),Ai&&a.jsx(_t,{className:"mb-4",children:a.jsxs(Mt,{className:"py-3",children:[a.jsxs("div",{className:"flex items-center justify-between mb-2",children:[a.jsx("span",{className:"text-sm font-medium text-white",children:i("settings.testResults")}),a.jsx("button",{onClick:()=>gl(null),className:"text-bambu-gray hover:text-white text-xs",children:i("common.dismiss")})]}),a.jsxs("div",{className:"flex items-center gap-4 text-sm mb-2",children:[a.jsxs("span",{className:"flex items-center gap-1 text-bambu-green",children:[a.jsx(Nr,{className:"w-4 h-4"}),i("settings.testPassedCount",{count:Ai.success})]}),Ai.failed>0&&a.jsxs("span",{className:"flex items-center gap-1 text-red-400",children:[a.jsx(ta,{className:"w-4 h-4"}),i("settings.testFailedCount",{count:Ai.failed})]})]}),Ai.results.filter(oe=>!oe.success).length>0&&a.jsx("div",{className:"space-y-1 mt-2 pt-2 border-t border-bambu-dark-tertiary",children:Ai.results.filter(oe=>!oe.success).map(oe=>a.jsxs("div",{className:"text-xs text-red-400",children:[a.jsxs("span",{className:"font-medium",children:[oe.provider_name,":"]})," ",oe.message]},oe.provider_id))})]})}),jt?a.jsx("div",{className:"flex justify-center py-12",children:a.jsx(ut,{className:"w-6 h-6 text-bambu-green animate-spin"})}):Ct&&Ct.length>0?a.jsx("div",{className:"space-y-3",children:Ct.map(oe=>a.jsx(qYe,{provider:oe,onEdit:Nt=>{q(Nt),R(!0)}},oe.id))}):a.jsx(_t,{children:a.jsx(Mt,{className:"py-8",children:a.jsxs("div",{className:"text-center text-bambu-gray",children:[a.jsx(Og,{className:"w-12 h-12 mx-auto mb-3 opacity-30"}),a.jsx("p",{className:"text-sm font-medium text-white mb-2",children:i("settings.noProvidersTitle")}),a.jsx("p",{className:"text-xs mb-3",children:i("settings.noProvidersDescription")}),a.jsxs(ke,{size:"sm",onClick:()=>{q(null),R(!0)},children:[a.jsx(dr,{className:"w-4 h-4"}),i("settings.addProvider")]})]})})})]}),a.jsxs("div",{children:[a.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2 mb-4",children:[a.jsx(ps,{className:"w-5 h-5 text-bambu-green"}),i("settings.messageTemplates")]}),a.jsx("p",{className:"text-sm text-bambu-gray mb-4",children:i("settings.messageTemplatesDescription")}),fn?a.jsx("div",{className:"flex justify-center py-8",children:a.jsx(ut,{className:"w-6 h-6 text-bambu-green animate-spin"})}):pn&&pn.length>0?a.jsx("div",{className:"space-y-2",children:pn.map(oe=>a.jsx(_t,{className:"cursor-pointer hover:border-bambu-green/50 transition-colors",onClick:()=>G(oe),children:a.jsx(Mt,{className:"py-2.5 px-3",children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"min-w-0 flex-1",children:[a.jsx("p",{className:"text-white font-medium text-sm truncate",children:oe.name}),a.jsx("p",{className:"text-bambu-gray text-xs truncate mt-0.5",children:oe.title_template})]}),a.jsx("button",{className:"p-1.5 hover:bg-bambu-dark-tertiary rounded transition-colors shrink-0 ml-2",onClick:Nt=>{Nt.stopPropagation(),G(oe)},children:a.jsx(Eg,{className:"w-4 h-4 text-bambu-gray"})})]})})},oe.id))}):a.jsx(_t,{children:a.jsx(Mt,{className:"py-8",children:a.jsxs("div",{className:"text-center text-bambu-gray",children:[a.jsx(ps,{className:"w-12 h-12 mx-auto mb-3 opacity-30"}),a.jsx("p",{className:"text-sm",children:i("settings.noTemplatesAvailable")})]})})})]})]}),be==="apikeys"&&a.jsxs("div",{className:"grid grid-cols-1 xl:grid-cols-2 gap-8",children:[a.jsxs("div",{children:[a.jsxs("div",{className:"flex items-start justify-between gap-4 mb-6",children:[a.jsxs("div",{className:"flex-1",children:[a.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[a.jsx(Wo,{className:"w-5 h-5 text-bambu-green"}),i("settings.apiKeys")]}),a.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:i("settings.apiKeysDescription")})]}),a.jsxs(ke,{size:"sm",onClick:()=>ae(!0),className:"flex-shrink-0",children:[a.jsx(dr,{className:"w-4 h-4"}),i("settings.createKey")]})]}),W&&a.jsx(_t,{className:"mb-6 border-bambu-green",children:a.jsx(Mt,{className:"py-4",children:a.jsxs("div",{className:"flex items-start gap-3",children:[a.jsx(Nr,{className:"w-5 h-5 text-bambu-green flex-shrink-0 mt-0.5"}),a.jsxs("div",{className:"flex-1",children:[a.jsx("p",{className:"text-white font-medium mb-1",children:i("settings.apiKeyCreated")}),a.jsx("p",{className:"text-sm text-bambu-gray mb-2",children:i("settings.apiKeyCopyWarning")}),a.jsxs("div",{className:"flex items-center gap-2 bg-bambu-dark rounded-lg p-2",children:[a.jsx("code",{className:"flex-1 text-sm text-bambu-green font-mono break-all",children:W}),a.jsx(ke,{variant:"secondary",size:"sm",onClick:async()=>{try{if(navigator.clipboard&&navigator.clipboard.writeText)await navigator.clipboard.writeText(W);else{const oe=document.createElement("textarea");oe.value=W,oe.style.position="fixed",oe.style.left="-999999px",document.body.appendChild(oe),oe.select(),document.execCommand("copy"),document.body.removeChild(oe)}o(i("settings.toast.keyCopied"))}catch{o(i("settings.toast.copyFailed"),"error")}},children:a.jsx(Fl,{className:"w-4 h-4"})})]}),a.jsxs("div",{className:"flex gap-2 mt-3",children:[a.jsx(ke,{variant:"secondary",size:"sm",onClick:()=>{V(W),o(i("settings.toast.keyAddedToBrowser"))},children:i("settings.useInApiBrowser")}),a.jsx(ke,{variant:"secondary",size:"sm",onClick:()=>Q(null),children:i("common.dismiss")})]})]})]})})}),Ce&&a.jsxs(_t,{className:"mb-6",children:[a.jsx(Pn,{children:a.jsx("h3",{className:"text-base font-semibold text-white",children:i("settings.createNewApiKey")})}),a.jsxs(Mt,{className:"space-y-4",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:i("settings.keyName")}),a.jsx("input",{type:"text",value:Ae,onChange:oe=>Le(oe.target.value),placeholder:i("settings.keyNamePlaceholder"),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-2",children:i("common.permissions")}),a.jsxs("div",{className:"space-y-2",children:[a.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:fe.can_read_status,onChange:oe=>Xe(Nt=>({...Nt,can_read_status:oe.target.checked})),className:"w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green"}),a.jsxs("div",{children:[a.jsx("span",{className:"text-white",children:i("settings.readStatus")}),a.jsx("p",{className:"text-xs text-bambu-gray",children:i("settings.readStatusDescription")})]})]}),a.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:fe.can_queue,onChange:oe=>Xe(Nt=>({...Nt,can_queue:oe.target.checked})),className:"w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green"}),a.jsxs("div",{children:[a.jsx("span",{className:"text-white",children:i("settings.manageQueue")}),a.jsx("p",{className:"text-xs text-bambu-gray",children:i("settings.manageQueueDescription")})]})]}),a.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:fe.can_control_printer,onChange:oe=>Xe(Nt=>({...Nt,can_control_printer:oe.target.checked})),className:"w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green"}),a.jsxs("div",{children:[a.jsx("span",{className:"text-white",children:i("settings.controlPrinter")}),a.jsx("p",{className:"text-xs text-bambu-gray",children:i("settings.controlPrinterDescription")})]})]})]})]}),a.jsxs("div",{className:"flex items-center gap-2 pt-2",children:[a.jsxs(ke,{onClick:()=>Et.mutate({name:Ae||i("settings.unnamedKey"),...fe}),disabled:Et.isPending,children:[Et.isPending?a.jsx(ut,{className:"w-4 h-4 animate-spin"}):a.jsx(dr,{className:"w-4 h-4"}),i("settings.createKey")]}),a.jsx(ke,{variant:"secondary",onClick:()=>ae(!1),children:i("common.cancel")})]})]})]}),Rt?a.jsx("div",{className:"flex justify-center py-12",children:a.jsx(ut,{className:"w-8 h-8 text-bambu-green animate-spin"})}):Bt&&Bt.length>0?a.jsx("div",{className:"space-y-3",children:Bt.map(oe=>a.jsx(_t,{children:a.jsx(Mt,{className:"py-3",children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx(Wo,{className:`w-5 h-5 ${oe.enabled?"text-bambu-green":"text-bambu-gray"}`}),a.jsxs("div",{children:[a.jsx("p",{className:"text-white font-medium",children:oe.name}),a.jsxs("p",{className:"text-xs text-bambu-gray",children:[oe.key_prefix,"••••••••",oe.last_used&&` · ${i("settings.lastUsed")}: ${tb(oe.last_used)}`]})]})]}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsxs("div",{className:"flex gap-1 text-xs",children:[oe.can_read_status&&a.jsx("span",{className:"px-1.5 py-0.5 bg-blue-500/20 text-blue-400 rounded",children:i("settings.read")}),oe.can_queue&&a.jsx("span",{className:"px-1.5 py-0.5 bg-green-500/20 text-green-400 rounded",children:i("queue.title")}),oe.can_control_printer&&a.jsx("span",{className:"px-1.5 py-0.5 bg-orange-500/20 text-orange-400 rounded",children:i("settings.control")})]}),a.jsx(ke,{variant:"secondary",size:"sm",onClick:()=>X(oe.id),children:a.jsx(cn,{className:"w-4 h-4 text-red-400"})})]})]})})},oe.id))}):a.jsx(_t,{children:a.jsx(Mt,{className:"py-12",children:a.jsxs("div",{className:"text-center text-bambu-gray",children:[a.jsx(Wo,{className:"w-16 h-16 mx-auto mb-4 opacity-30"}),a.jsx("p",{className:"text-lg font-medium text-white mb-2",children:i("settings.apiKeysEmptyTitle")}),a.jsx("p",{className:"text-sm mb-4",children:i("settings.apiKeysEmptyDescription")}),a.jsxs(ke,{onClick:()=>ae(!0),children:[a.jsx(dr,{className:"w-4 h-4"}),i("settings.createFirstKey")]})]})})}),a.jsxs(_t,{className:"mt-6",children:[a.jsx(Pn,{children:a.jsx("h3",{className:"text-base font-semibold text-white",children:i("settings.webhookEndpoints")})}),a.jsxs(Mt,{className:"space-y-3 text-sm",children:[a.jsx("p",{className:"text-bambu-gray",children:i("settings.webhookApiKeyHint")}),a.jsxs("div",{className:"space-y-2 font-mono text-xs",children:[a.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[a.jsx("span",{className:"text-blue-400",children:"GET"})," ",a.jsx("span",{className:"text-white",children:"/api/v1/webhook/status"}),a.jsxs("span",{className:"text-bambu-gray",children:[" - ",i("settings.webhook.getAllStatus")]})]}),a.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[a.jsx("span",{className:"text-blue-400",children:"GET"})," ",a.jsx("span",{className:"text-white",children:"/api/v1/webhook/status/:id"}),a.jsxs("span",{className:"text-bambu-gray",children:[" - ",i("settings.webhook.getSpecificStatus")]})]}),a.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[a.jsx("span",{className:"text-green-400",children:"POST"})," ",a.jsx("span",{className:"text-white",children:"/api/v1/webhook/queue"}),a.jsxs("span",{className:"text-bambu-gray",children:[" - ",i("settings.webhook.addToQueue")]})]}),a.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[a.jsx("span",{className:"text-orange-400",children:"POST"})," ",a.jsx("span",{className:"text-white",children:"/api/v1/webhook/printer/:id/pause"}),a.jsxs("span",{className:"text-bambu-gray",children:[" - ",i("settings.webhook.pausePrint")]})]}),a.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[a.jsx("span",{className:"text-orange-400",children:"POST"})," ",a.jsx("span",{className:"text-white",children:"/api/v1/webhook/printer/:id/resume"}),a.jsxs("span",{className:"text-bambu-gray",children:[" - ",i("settings.webhook.resumePrint")]})]}),a.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[a.jsx("span",{className:"text-red-400",children:"POST"})," ",a.jsx("span",{className:"text-white",children:"/api/v1/webhook/printer/:id/stop"}),a.jsxs("span",{className:"text-bambu-gray",children:[" - ",i("settings.webhook.stopPrint")]})]})]})]})]})]}),a.jsxs("div",{children:[a.jsxs("div",{className:"mb-6",children:[a.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[a.jsx(bh,{className:"w-5 h-5 text-bambu-green"}),i("settings.apiBrowser")]}),a.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:i("settings.apiBrowserDescription")})]}),a.jsx(_t,{className:"mb-4",children:a.jsxs(Mt,{className:"py-3",children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-2",children:i("settings.apiKeyForTesting")}),a.jsx("input",{type:"text",value:te,onChange:oe=>V(oe.target.value),placeholder:i("settings.apiKeyPlaceholder"),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white font-mono text-sm focus:border-bambu-green focus:outline-none"}),a.jsx("p",{className:"text-xs text-bambu-gray mt-2",children:i("settings.apiKeyHint")})]})}),a.jsx(uQe,{apiKey:te})]})]}),be==="virtual-printer"&&a.jsx(rQe,{}),be==="filament"&&E&&a.jsxs("div",{className:"flex flex-col lg:flex-row gap-6 lg:gap-8",children:[a.jsx("div",{className:"flex-1 lg:max-w-xl",children:a.jsxs(_t,{children:[a.jsx(Pn,{children:a.jsx("h2",{className:"text-lg font-semibold text-white",children:i("settings.amsDisplayThresholds")})}),a.jsxs(Mt,{className:"space-y-4",children:[a.jsx("p",{className:"text-sm text-bambu-gray",children:i("settings.amsThresholdsDescription")}),a.jsxs("div",{className:"space-y-3",children:[a.jsxs("div",{className:"flex items-center gap-2 text-white",children:[a.jsx(sO,{className:"w-4 h-4 text-blue-400"}),a.jsx("span",{className:"font-medium",children:i("settings.humidity")})]}),a.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[a.jsxs("div",{children:[a.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[i("settings.goodGreen")," ≤"]}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("input",{type:"number",min:"0",max:"100",value:E.ams_humidity_good??40,onChange:oe=>wn("ams_humidity_good",parseInt(oe.target.value)||40),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"}),a.jsx("span",{className:"text-bambu-gray",children:"%"})]})]}),a.jsxs("div",{children:[a.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[i("settings.fairOrange")," ≤"]}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("input",{type:"number",min:"0",max:"100",value:E.ams_humidity_fair??60,onChange:oe=>wn("ams_humidity_fair",parseInt(oe.target.value)||60),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"}),a.jsx("span",{className:"text-bambu-gray",children:"%"})]})]})]}),a.jsx("p",{className:"text-xs text-bambu-gray",children:i("settings.aboveFairBad")})]}),a.jsxs("div",{className:"space-y-3 pt-2 border-t border-bambu-dark-tertiary",children:[a.jsxs("div",{className:"flex items-center gap-2 text-white",children:[a.jsx(GM,{className:"w-4 h-4 text-orange-400"}),a.jsx("span",{className:"font-medium",children:i("settings.temperature")})]}),a.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[a.jsxs("div",{children:[a.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[i("settings.goodBlue")," ≤"]}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("input",{type:"number",step:"0.5",min:"0",max:"60",value:E.ams_temp_good??28,onChange:oe=>wn("ams_temp_good",parseFloat(oe.target.value)||28),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"}),a.jsx("span",{className:"text-bambu-gray",children:"°C"})]})]}),a.jsxs("div",{children:[a.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[i("settings.fairOrange")," ≤"]}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("input",{type:"number",step:"0.5",min:"0",max:"60",value:E.ams_temp_fair??35,onChange:oe=>wn("ams_temp_fair",parseFloat(oe.target.value)||35),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"}),a.jsx("span",{className:"text-bambu-gray",children:"°C"})]})]})]}),a.jsx("p",{className:"text-xs text-bambu-gray",children:i("settings.aboveFairHot")})]}),a.jsxs("div",{className:"space-y-3 pt-4 border-t border-bambu-dark-tertiary",children:[a.jsxs("div",{className:"flex items-center gap-2 text-white",children:[a.jsx(ju,{className:"w-4 h-4 text-purple-400"}),a.jsx("span",{className:"font-medium",children:i("settings.historyRetention")})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:i("settings.keepSensorHistory")}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("input",{type:"number",min:"1",max:"365",value:E.ams_history_retention_days??30,onChange:oe=>wn("ams_history_retention_days",parseInt(oe.target.value)||30),className:"w-24 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"}),a.jsx("span",{className:"text-bambu-gray",children:i("common.days")})]})]}),a.jsx("p",{className:"text-xs text-bambu-gray",children:i("settings.historyRetentionDescription")})]}),a.jsxs("div",{className:"space-y-3 pt-4 border-t border-bambu-dark-tertiary",children:[a.jsxs("div",{className:"flex items-center gap-2 text-white",children:[a.jsx(Or,{className:"w-4 h-4 text-bambu-green"}),a.jsx("span",{className:"font-medium",children:i("settings.printModal")})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-white",children:i("settings.expandCustomMapping")}),a.jsx("p",{className:"text-xs text-bambu-gray mt-0.5",children:i("settings.expandCustomMappingDescription")})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:E.per_printer_mapping_expanded??!1,onChange:oe=>wn("per_printer_mapping_expanded",oe.target.checked),className:"sr-only peer"}),a.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]})]})]})]})}),a.jsx("div",{className:"flex-1 lg:max-w-xl",children:a.jsx(eQe,{})})]}),me!==null&&a.jsx(er,{title:i("settings.deleteApiKeyTitle"),message:i("settings.deleteApiKeyMessage"),confirmText:i("settings.deleteKey"),variant:"danger",onConfirm:()=>{an.mutate(me),X(null)},onCancel:()=>X(null)}),T&&a.jsx(VYe,{plug:z,onClose:()=>{j(!1),L(null)}}),B&&a.jsx(WYe,{provider:$,onClose:()=>{R(!1),q(null)}}),I&&a.jsx(KYe,{template:I,onClose:()=>G(null)}),Y&&a.jsx(QYe,{onClose:()=>re(!1)}),ge&&a.jsx(er,{title:i("settings.clearNotificationLogs"),message:i("settings.clearLogsMessage"),confirmText:i("settings.clearLogs"),variant:"warning",onConfirm:async()=>{Se(!1);try{const oe=await ce.clearNotificationLogs(30);o(oe.message,"success")}catch{o(i("settings.toast.clearLogsFailed"),"error")}},onCancel:()=>Se(!1)}),ee&&a.jsx(er,{title:i("settings.resetUiPreferences"),message:i("settings.resetUiPreferencesMessage"),confirmText:i("settings.resetPreferences"),variant:"default",onConfirm:()=>{U(!1),localStorage.clear(),o(i("settings.toast.uiPreferencesReset"),"success"),setTimeout(()=>window.location.reload(),1e3)},onCancel:()=>U(!1)}),O&&a.jsx(er,{title:`Turn All Plugs ${O==="on"?"On":"Off"}`,message:`This will turn ${O==="on"?"ON":"OFF"} all ${_e?.filter(oe=>oe.enabled).length||0} enabled smart plugs. ${O==="off"?"Any running printers may be affected!":""}`,confirmText:`Turn All ${O==="on"?"On":"Off"}`,variant:O==="off"?"danger":"warning",onConfirm:()=>{const oe=O;Z(null),bl.mutate(oe)},onCancel:()=>Z(null)}),le&&en?.release_notes&&a.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",onClick:()=>we(!1),children:a.jsxs(_t,{className:"w-full max-w-2xl max-h-[80vh] flex flex-col",onClick:oe=>oe.stopPropagation(),children:[a.jsxs(Pn,{className:"flex flex-row items-center justify-between shrink-0",children:[a.jsxs("div",{children:[a.jsxs("h2",{className:"text-lg font-semibold text-white",children:["Release Notes - v",en.latest_version]}),en.release_name&&en.release_name!==en.latest_version&&a.jsx("p",{className:"text-sm text-bambu-gray",children:en.release_name})]}),a.jsx("button",{onClick:()=>we(!1),className:"p-1 rounded hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white",children:a.jsx(Lt,{className:"w-5 h-5"})})]}),a.jsx(Mt,{className:"overflow-y-auto flex-1",children:a.jsx("pre",{className:"text-sm text-bambu-gray whitespace-pre-wrap font-sans",children:en.release_notes})}),a.jsxs("div",{className:"p-4 border-t border-bambu-dark-tertiary shrink-0 flex gap-2",children:[en.release_url&&a.jsx("a",{href:en.release_url,target:"_blank",rel:"noopener noreferrer",className:"flex-1",children:a.jsxs(ke,{variant:"secondary",className:"w-full",children:[a.jsx(Xr,{className:"w-4 h-4"}),"View on GitHub"]})}),a.jsx(ke,{onClick:()=>we(!1),className:"flex-1",children:"Close"})]})]})}),be==="users"&&a.jsxs("div",{className:"space-y-6",children:[a.jsx(_t,{children:a.jsx(Mt,{className:"py-4",children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx("div",{className:`w-10 h-10 rounded-full flex items-center justify-center ${l?"bg-green-500/20":"bg-gray-500/20"}`,children:l?a.jsx(P1,{className:"w-5 h-5 text-green-400"}):a.jsx(j1,{className:"w-5 h-5 text-gray-400"})}),a.jsxs("div",{children:[a.jsx("h3",{className:"text-white font-medium",children:i("settings.authentication")}),a.jsx("p",{className:"text-sm text-bambu-gray",children:i(l?"settings.authEnabledDescription":"settings.authDisabledDescription")})]})]}),l?c?.is_admin&&a.jsxs(ke,{variant:"secondary",onClick:()=>se(!0),children:[a.jsx(j1,{className:"w-4 h-4"}),i("common.disable")]}):a.jsxs(ke,{onClick:()=>e("/setup"),children:[a.jsx(P1,{className:"w-4 h-4"}),i("common.enable")]})]})})}),Kt?.advanced_auth_enabled&&a.jsx(_t,{className:"border-blue-500/30 bg-blue-500/5",children:a.jsx(Mt,{className:"py-4",children:a.jsxs("div",{className:"flex items-start gap-3",children:[a.jsx("div",{className:"w-10 h-10 rounded-full flex items-center justify-center bg-blue-500/20 flex-shrink-0",children:a.jsx(oy,{className:"w-5 h-5 text-blue-400"})}),a.jsxs("div",{children:[a.jsx("h3",{className:"text-white font-medium",children:i("settings.email.advancedAuthEnabled")||"Advanced Authentication is enabled"}),a.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:i("settings.email.advancedAuthEnabledDesc")||"Email-based user management features are active. New users will receive auto-generated passwords via email, and users can reset their passwords through the forgot password feature."})]})]})})}),l&&a.jsxs("div",{className:"grid grid-cols-1 xl:grid-cols-2 gap-6",children:[a.jsxs("div",{className:"space-y-6",children:[c&&a.jsxs(_t,{children:[a.jsx(Pn,{children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("h3",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[a.jsx(Kf,{className:"w-5 h-5 text-bambu-green"}),i("settings.currentUser")]}),a.jsxs(ke,{size:"sm",variant:"ghost",onClick:()=>He(!0),children:[a.jsx(Wo,{className:"w-4 h-4"}),i("settings.changePassword")]})]})}),a.jsx(Mt,{children:a.jsx("div",{className:"flex items-center justify-between",children:a.jsxs("div",{children:[a.jsx("p",{className:"text-white font-medium text-lg",children:c.username}),a.jsxs("div",{className:"flex flex-wrap gap-1 mt-2",children:[c.is_admin&&a.jsx("span",{className:"px-2 py-0.5 rounded-full text-xs font-medium bg-purple-500/20 text-purple-300",children:i("settings.admin")}),c.groups?.map(oe=>a.jsx("span",{className:`px-2 py-0.5 rounded-full text-xs font-medium ${oe.name==="Administrators"?"bg-purple-500/20 text-purple-300":oe.name==="Operators"?"bg-blue-500/20 text-blue-300":oe.name==="Viewers"?"bg-green-500/20 text-green-300":"bg-gray-500/20 text-gray-300"}`,children:oe.name},oe.id))]})]})})})]}),a.jsxs(_t,{children:[a.jsx(Pn,{children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("h3",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[a.jsx(Kf,{className:"w-5 h-5 text-bambu-green"}),i("settings.users")]}),vt("users:create")&&a.jsxs(ke,{size:"sm",onClick:()=>{Ne(!0),Ut({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]})},children:[a.jsx(dr,{className:"w-4 h-4"}),i("settings.addUser")]})]})}),a.jsx(Mt,{children:hi?a.jsx("div",{className:"flex items-center justify-center py-8",children:a.jsx(ut,{className:"w-6 h-6 text-bambu-green animate-spin"})}):Nn.length===0?a.jsx("p",{className:"text-center text-bambu-gray py-8",children:i("settings.noUsersFound")}):a.jsx("div",{className:"divide-y divide-bambu-dark-tertiary",children:Nn.map(oe=>a.jsxs("div",{className:"py-3 flex items-center justify-between",children:[a.jsxs("div",{className:"flex-1 min-w-0",children:[a.jsx("p",{className:"text-white font-medium truncate",children:oe.username}),a.jsxs("div",{className:"flex flex-wrap gap-1 mt-1",children:[oe.is_admin&&a.jsx("span",{className:"px-2 py-0.5 rounded-full text-xs font-medium bg-purple-500/20 text-purple-300",children:i("settings.admin")}),oe.groups?.map(Nt=>a.jsx("span",{className:`px-2 py-0.5 rounded-full text-xs font-medium ${Nt.name==="Administrators"?"bg-purple-500/20 text-purple-300":Nt.name==="Operators"?"bg-blue-500/20 text-blue-300":Nt.name==="Viewers"?"bg-green-500/20 text-green-300":"bg-gray-500/20 text-gray-300"}`,children:Nt.name},Nt.id))]})]}),a.jsxs("div",{className:"flex items-center gap-1 ml-4",children:[vt("users:update")&&a.jsx(ke,{size:"sm",variant:"ghost",onClick:()=>Ao(oe),children:a.jsx(Eg,{className:"w-4 h-4"})}),vt("users:delete")&&oe.id!==c?.id&&a.jsx(ke,{size:"sm",variant:"ghost",onClick:()=>Mo(oe.id),children:a.jsx(cn,{className:"w-4 h-4"})})]})]},oe.id))})})]})]}),a.jsx("div",{children:a.jsxs(_t,{children:[a.jsx(Pn,{children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("h3",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[a.jsx(PA,{className:"w-5 h-5 text-bambu-green"}),i("settings.groups")]}),vt("groups:create")&&a.jsxs(ke,{size:"sm",onClick:()=>{Fe(!0),pr()},children:[a.jsx(dr,{className:"w-4 h-4"}),i("settings.addGroup")]})]})}),a.jsx(Mt,{children:Yr?a.jsx("div",{className:"flex items-center justify-center py-8",children:a.jsx(ut,{className:"w-6 h-6 text-bambu-green animate-spin"})}):xr.length===0?a.jsx("p",{className:"text-center text-bambu-gray py-8",children:i("settings.noGroupsFound")}):a.jsx("div",{className:"divide-y divide-bambu-dark-tertiary",children:xr.map(oe=>a.jsxs("div",{className:"py-3",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(PA,{className:`w-4 h-4 ${oe.name==="Administrators"?"text-purple-400":oe.name==="Operators"?"text-blue-400":oe.name==="Viewers"?"text-green-400":"text-bambu-gray"}`}),a.jsx("span",{className:"text-white font-medium",children:oe.name}),oe.is_system&&a.jsx("span",{className:"px-2 py-0.5 rounded text-xs bg-yellow-500/20 text-yellow-400",children:i("settings.system")})]}),a.jsxs("div",{className:"flex items-center gap-1",children:[vt("groups:update")&&a.jsx(ke,{size:"sm",variant:"ghost",onClick:()=>ql(oe),children:a.jsx(Eg,{className:"w-4 h-4"})}),vt("groups:delete")&&!oe.is_system&&a.jsx(ke,{size:"sm",variant:"ghost",onClick:()=>En(oe.id),children:a.jsx(cn,{className:"w-4 h-4"})})]})]}),a.jsx("p",{className:"text-sm text-bambu-gray mt-1 ml-6",children:oe.description||i("settings.noDescription")}),a.jsxs("div",{className:"flex items-center gap-4 mt-2 ml-6 text-xs text-bambu-gray",children:[a.jsx("span",{children:i("settings.userCount",{count:oe.user_count})}),a.jsx("span",{children:i("settings.permissionCount",{count:oe.permissions.length})})]})]},oe.id))})})]})})]}),!l&&a.jsx(_t,{children:a.jsx(Mt,{className:"py-6",children:a.jsxs("div",{className:"text-center",children:[a.jsx(j1,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),a.jsx("h3",{className:"text-lg font-medium text-white mb-2",children:i("settings.authDisabledTitle")}),a.jsx("p",{className:"text-sm text-bambu-gray mb-4 max-w-md mx-auto",children:i("settings.authDisabledMessage")}),a.jsxs("ul",{className:"space-y-2 text-sm text-bambu-gray mb-6 text-left max-w-xs mx-auto",children:[a.jsxs("li",{className:"flex items-start gap-2",children:[a.jsx(Nr,{className:"w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0"}),a.jsx("span",{children:i("settings.authDisabledFeature1")})]}),a.jsxs("li",{className:"flex items-start gap-2",children:[a.jsx(Nr,{className:"w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0"}),a.jsx("span",{children:i("settings.authDisabledFeature2")})]}),a.jsxs("li",{className:"flex items-start gap-2",children:[a.jsx(Nr,{className:"w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0"}),a.jsx("span",{children:i("settings.authDisabledFeature3")})]})]}),a.jsxs(ke,{onClick:()=>e("/setup"),children:[a.jsx(P1,{className:"w-4 h-4"}),i("settings.enableAuthentication")]})]})})})]}),Ie&&!Kt?.advanced_auth_enabled&&a.jsx("div",{className:"fixed inset-0 bg-black flex items-center justify-center z-50 p-4",onClick:()=>{Ne(!1),Ut({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]})},children:a.jsxs(_t,{className:"w-full max-w-md",onClick:oe=>oe.stopPropagation(),children:[a.jsx(Pn,{children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(Kf,{className:"w-5 h-5 text-bambu-green"}),a.jsx("h2",{className:"text-lg font-semibold text-white",children:i("settings.createUser")})]}),a.jsx(ke,{variant:"ghost",size:"sm",onClick:()=>{Ne(!1),Ut({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]})},children:a.jsx(Lt,{className:"w-5 h-5"})})]})}),a.jsxs(Mt,{children:[a.jsxs("div",{className:"space-y-4",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:i("settings.username")}),a.jsx("input",{type:"text",value:gt.username,onChange:oe=>Ut({...gt,username:oe.target.value}),className:"w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors",placeholder:i("settings.enterUsername"),autoComplete:"username"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:i("settings.password")}),a.jsx("input",{type:"password",value:gt.password,onChange:oe=>Ut({...gt,password:oe.target.value}),className:"w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors",placeholder:i("settings.enterPassword"),autoComplete:"new-password",minLength:6})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:i("settings.confirmPassword")}),a.jsx("input",{type:"password",value:gt.confirmPassword,onChange:oe=>Ut({...gt,confirmPassword:oe.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors ${gt.confirmPassword&>.password!==gt.confirmPassword?"border-red-500":"border-bambu-dark-tertiary"}`,placeholder:i("settings.confirmPasswordPlaceholder"),autoComplete:"new-password",minLength:6}),gt.confirmPassword&>.password!==gt.confirmPassword&&a.jsx("p",{className:"text-red-400 text-xs mt-1",children:i("settings.passwordsDoNotMatch")})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:"Groups"}),a.jsxs("div",{className:"space-y-2 max-h-40 overflow-y-auto p-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg",children:[xr.map(oe=>a.jsxs("label",{className:"flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-tertiary cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:gt.group_ids.includes(oe.id),onChange:()=>Ts(oe.id),className:"w-4 h-4 rounded border-bambu-gray text-bambu-green focus:ring-bambu-green focus:ring-offset-0 bg-bambu-dark"}),a.jsx("span",{className:"text-sm text-white",children:oe.name}),oe.is_system&&a.jsx("span",{className:"text-xs text-yellow-400",children:"(System)"})]},oe.id)),xr.length===0&&a.jsx("p",{className:"text-sm text-bambu-gray",children:i("settings.noGroupsAvailable")})]})]})]}),a.jsxs("div",{className:"mt-6 flex justify-end gap-3",children:[a.jsx(ke,{variant:"secondary",onClick:()=>{Ne(!1),Ut({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]})},children:"Cancel"}),a.jsx(ke,{onClick:ls,disabled:nn.isPending||!gt.username||!gt.password||gt.password!==gt.confirmPassword||gt.password.length<6,children:nn.isPending?a.jsxs(a.Fragment,{children:[a.jsx(ut,{className:"w-4 h-4 animate-spin"}),"Creating..."]}):a.jsxs(a.Fragment,{children:[a.jsx(dr,{className:"w-4 h-4"}),"Create User"]})})]})]})]})}),Ie&&Kt?.advanced_auth_enabled&&a.jsx(JYe,{formData:gt,setFormData:Ut,groups:xr,onClose:()=>{Ne(!1),Ut({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]})},onCreate:ls,isCreating:nn.isPending,isCreateButtonDisabled:nn.isPending||!gt.username||!gt.email}),Ge&&rt!==null&&a.jsx("div",{className:"fixed inset-0 bg-black flex items-center justify-center z-50 p-4",onClick:()=>{Me(!1),Ee(null),Ut({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]})},children:a.jsxs(_t,{className:"w-full max-w-md",onClick:oe=>oe.stopPropagation(),children:[a.jsx(Pn,{children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(Eg,{className:"w-5 h-5 text-bambu-green"}),a.jsx("h2",{className:"text-lg font-semibold text-white",children:i("settings.editUser")})]}),a.jsx(ke,{variant:"ghost",size:"sm",onClick:()=>{Me(!1),Ee(null),Ut({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]})},children:a.jsx(Lt,{className:"w-5 h-5"})})]})}),a.jsxs(Mt,{children:[a.jsxs("div",{className:"space-y-4",children:[a.jsxs("div",{children:[a.jsxs("label",{className:"block text-sm font-medium text-white mb-2",children:[i("settings.username")," ",Kt?.advanced_auth_enabled&&a.jsx("span",{className:"text-red-400",children:"*"})]}),a.jsx("input",{type:"text",value:gt.username,onChange:oe=>Ut({...gt,username:oe.target.value}),className:"w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors",placeholder:i("settings.enterUsername"),autoComplete:"username"})]}),a.jsxs("div",{children:[a.jsxs("label",{className:"block text-sm font-medium text-white mb-2",children:[i("users.form.email")||"Email"," ",Kt?.advanced_auth_enabled?a.jsx("span",{className:"text-red-400",children:"*"}):a.jsxs("span",{className:"text-bambu-gray font-normal",children:["(",i("users.form.optional")||"optional",")"]})]}),a.jsx("input",{type:"email",value:gt.email,onChange:oe=>Ut({...gt,email:oe.target.value}),className:"w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors",placeholder:i("users.form.emailPlaceholder")||"user@example.com",required:Kt?.advanced_auth_enabled})]}),!Kt?.advanced_auth_enabled&&a.jsxs(a.Fragment,{children:[a.jsxs("div",{children:[a.jsxs("label",{className:"block text-sm font-medium text-white mb-2",children:[i("users.form.password")||"Password"," ",a.jsxs("span",{className:"text-bambu-gray font-normal",children:["(",i("users.form.leaveBlankToKeep")||"leave blank to keep current",")"]})]}),a.jsx("input",{type:"password",value:gt.password,onChange:oe=>Ut({...gt,password:oe.target.value,confirmPassword:""}),className:"w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors",placeholder:i("settings.enterNewPassword"),autoComplete:"new-password",minLength:6})]}),gt.password&&a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:i("settings.confirmPassword")}),a.jsx("input",{type:"password",value:gt.confirmPassword,onChange:oe=>Ut({...gt,confirmPassword:oe.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors ${gt.confirmPassword&>.password!==gt.confirmPassword?"border-red-500":"border-bambu-dark-tertiary"}`,placeholder:i("settings.confirmNewPassword"),autoComplete:"new-password",minLength:6}),gt.confirmPassword&>.password!==gt.confirmPassword&&a.jsx("p",{className:"text-red-400 text-xs mt-1",children:i("settings.passwordsDoNotMatch")})]})]}),Kt?.advanced_auth_enabled&&a.jsx("div",{className:"bg-bambu-dark-secondary/50 border border-bambu-green/20 rounded-lg p-3",children:a.jsx("p",{className:"text-sm text-bambu-gray",children:i("users.form.passwordManagedByAdvancedAuth")||'Password is managed by Advanced Authentication. Use "Reset Password" to send a new password to the user via email.'})}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:i("users.form.groups")||"Groups"}),a.jsx("div",{className:"space-y-2 max-h-40 overflow-y-auto p-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg",children:xr.map(oe=>a.jsxs("label",{className:"flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-tertiary cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:gt.group_ids.includes(oe.id),onChange:()=>Ts(oe.id),className:"w-4 h-4 rounded border-bambu-gray text-bambu-green focus:ring-bambu-green focus:ring-offset-0 bg-bambu-dark"}),a.jsx("span",{className:"text-sm text-white",children:oe.name}),oe.is_system&&a.jsxs("span",{className:"text-xs text-yellow-400",children:["(",i("users.system")||"System",")"]})]},oe.id))})]})]}),a.jsxs("div",{className:"mt-6 flex justify-end gap-3",children:[a.jsx(ke,{variant:"secondary",onClick:()=>{Me(!1),Ee(null),Ut({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]})},children:i("users.modal.cancel")||"Cancel"}),a.jsx(ke,{onClick:()=>Ei(rt),disabled:Mn.isPending||!gt.username||Kt?.advanced_auth_enabled&&!gt.email||!!(!Kt?.advanced_auth_enabled&>.password&&(gt.password!==gt.confirmPassword||gt.password.length<6)),children:Mn.isPending?a.jsxs(a.Fragment,{children:[a.jsx(ut,{className:"w-4 h-4 animate-spin"}),i("users.modal.saving")||"Saving..."]}):a.jsxs(a.Fragment,{children:[a.jsx(gs,{className:"w-4 h-4"}),i("users.modal.saveChanges")||"Save Changes"]})})]})]})]})}),Ke!==null&&a.jsx("div",{className:"fixed inset-0 bg-black/80 flex items-center justify-center z-50 p-4",onClick:()=>{Be(null),$e(null)},children:a.jsxs(_t,{className:"w-full max-w-md",onClick:oe=>oe.stopPropagation(),children:[a.jsx(Pn,{children:a.jsxs("div",{className:"flex items-center gap-2 text-red-400",children:[a.jsx(cn,{className:"w-5 h-5"}),a.jsx("h3",{className:"text-lg font-semibold",children:i("settings.deleteUserTitle")})]})}),a.jsx(Mt,{className:"space-y-4",children:at?a.jsx("div",{className:"flex items-center justify-center py-4",children:a.jsx("div",{className:"animate-spin rounded-full h-6 w-6 border-2 border-bambu-green border-t-transparent"})}):ue&&ue.archives+ue.queue_items+ue.library_files>0?a.jsxs(a.Fragment,{children:[a.jsx("p",{className:"text-white",children:i("settings.userHasCreated")}),a.jsxs("ul",{className:"list-disc list-inside text-bambu-gray space-y-1",children:[ue.archives>0&&a.jsxs("li",{children:[ue.archives," archive",ue.archives!==1?"s":""]}),ue.queue_items>0&&a.jsxs("li",{children:[ue.queue_items," queue item",ue.queue_items!==1?"s":""]}),ue.library_files>0&&a.jsxs("li",{children:[ue.library_files," library file",ue.library_files!==1?"s":""]})]}),a.jsx("p",{className:"text-bambu-gray text-sm",children:i("settings.userItemsQuestion")}),a.jsxs("div",{className:"flex flex-col gap-2",children:[a.jsx(ke,{variant:"danger",onClick:()=>Mr.mutate({id:Ke,deleteItems:!0}),disabled:Mr.isPending,className:"justify-center",children:"Delete user AND their items"}),a.jsx(ke,{variant:"secondary",onClick:()=>Mr.mutate({id:Ke,deleteItems:!1}),disabled:Mr.isPending,className:"justify-center",children:"Delete user, keep items (become ownerless)"}),a.jsx(ke,{variant:"ghost",onClick:()=>{Be(null),$e(null)},disabled:Mr.isPending,className:"justify-center",children:"Cancel"})]})]}):a.jsxs(a.Fragment,{children:[a.jsx("p",{className:"text-white",children:i("settings.deleteUserConfirm")}),a.jsx("p",{className:"text-bambu-gray text-sm",children:i("settings.actionCannotBeUndone")}),a.jsxs("div",{className:"flex gap-2 justify-end",children:[a.jsx(ke,{variant:"ghost",onClick:()=>{Be(null),$e(null)},disabled:Mr.isPending,children:"Cancel"}),a.jsx(ke,{variant:"danger",onClick:()=>Mr.mutate({id:Ke,deleteItems:!1}),disabled:Mr.isPending,children:"Delete User"})]})]})})]})}),(Ft||xt)&&a.jsx("div",{className:"fixed inset-0 bg-black flex items-center justify-center z-50 p-4",onClick:()=>{Fe(!1),Wt(null),pr()},children:a.jsxs(_t,{className:"w-full max-w-2xl max-h-[90vh] overflow-y-auto",onClick:oe=>oe.stopPropagation(),children:[a.jsx(Pn,{children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(PA,{className:"w-5 h-5 text-bambu-green"}),a.jsx("h2",{className:"text-lg font-semibold text-white",children:xt?"Edit Group":"Create Group"})]}),a.jsx(ke,{variant:"ghost",size:"sm",onClick:()=>{Fe(!1),Wt(null),pr()},children:a.jsx(Lt,{className:"w-5 h-5"})})]})}),a.jsxs(Mt,{children:[a.jsxs("div",{className:"space-y-4",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:i("settings.groupName")}),a.jsx("input",{type:"text",value:hn.name,onChange:oe=>or({...hn,name:oe.target.value}),disabled:xt?.is_system,className:"w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors disabled:opacity-50",placeholder:i("settings.enterGroupName")}),xt?.is_system&&a.jsx("p",{className:"text-xs text-yellow-400 mt-1",children:i("settings.systemGroupWarning")})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:"Description"}),a.jsx("textarea",{value:hn.description,onChange:oe=>or({...hn,description:oe.target.value}),rows:2,className:"w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors resize-none",placeholder:i("settings.enterDescriptionOptional")})]}),a.jsxs("div",{children:[a.jsxs("label",{className:"block text-sm font-medium text-white mb-2",children:["Permissions (",hn.permissions.length," selected)"]}),a.jsx("div",{className:"space-y-2 max-h-96 overflow-y-auto",children:No?.categories.map(oe=>a.jsxs("div",{className:"border border-bambu-dark-tertiary rounded-lg overflow-hidden",children:[a.jsxs("div",{className:"flex items-center justify-between px-4 py-2 bg-bambu-dark-secondary cursor-pointer hover:bg-bambu-dark-tertiary transition-colors",onClick:()=>Jb(oe.name),children:[a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx("button",{type:"button",onClick:Nt=>{Nt.stopPropagation(),Lv(oe,!ad(oe))},className:`w-5 h-5 rounded border flex items-center justify-center transition-colors ${ad(oe)?"bg-bambu-green border-bambu-green":nf(oe)?"bg-bambu-green/50 border-bambu-green":"border-bambu-gray hover:border-white"}`,children:(ad(oe)||nf(oe))&&a.jsx(qi,{className:"w-3 h-3 text-white"})}),a.jsx("span",{className:"text-white font-medium",children:oe.name}),a.jsxs("span",{className:"text-xs text-bambu-gray",children:["(",oe.permissions.filter(Nt=>hn.permissions.includes(Nt.value)).length,"/",oe.permissions.length,")"]})]}),Kn.has(oe.name)?a.jsx(Sr,{className:"w-4 h-4 text-bambu-gray"}):a.jsx(_s,{className:"w-4 h-4 text-bambu-gray"})]}),Kn.has(oe.name)&&a.jsx("div",{className:"p-3 bg-bambu-dark space-y-2",children:oe.permissions.map(Nt=>a.jsxs("label",{className:"flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-secondary cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:hn.permissions.includes(Nt.value),onChange:()=>Ym(Nt.value),className:"w-4 h-4 rounded border-bambu-gray text-bambu-green focus:ring-bambu-green focus:ring-offset-0 bg-bambu-dark-secondary"}),a.jsx("span",{className:"text-sm text-bambu-gray",children:Nt.label})]},Nt.value))})]},oe.name))})]})]}),a.jsxs("div",{className:"mt-6 flex justify-end gap-3",children:[a.jsx(ke,{variant:"secondary",onClick:()=>{Fe(!1),Wt(null),pr()},children:"Cancel"}),a.jsx(ke,{onClick:xt?tf:Zb,disabled:ko.isPending||As.isPending||!hn.name.trim(),children:ko.isPending||As.isPending?a.jsxs(a.Fragment,{children:[a.jsx(ut,{className:"w-4 h-4 animate-spin"}),xt?"Saving...":"Creating..."]}):a.jsxs(a.Fragment,{children:[a.jsx(gs,{className:"w-4 h-4"}),xt?"Save Changes":"Create Group"]})})]})]})]})}),Qt!==null&&a.jsx(er,{title:i("settings.deleteGroupTitle"),message:i("settings.deleteGroupMessage"),confirmText:i("settings.deleteGroup"),variant:"danger",onConfirm:()=>{Eo.mutate(Qt),En(null)},onCancel:()=>En(null)}),be==="email"&&a.jsx(sQe,{}),be==="backup"&&a.jsx(aQe,{}),ye&&a.jsx(er,{title:i("settings.disableAuthenticationTitle"),message:i("settings.disableAuthenticationMessage"),confirmText:i("settings.disableAuthentication"),variant:"danger",onConfirm:async()=>{try{await ce.disableAuth(),o(i("settings.toast.authDisabled"),"success"),await u(),se(!1),window.location.href="/"}catch(oe){const Nt=oe instanceof Error?oe.message:i("settings.toast.authDisableFailed");o(Nt,"error")}},onCancel:()=>se(!1)}),Oe&&a.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",onClick:()=>{He(!1),Ue({currentPassword:"",newPassword:"",confirmPassword:""})},children:a.jsxs(_t,{className:"w-full max-w-md",onClick:oe=>oe.stopPropagation(),children:[a.jsx(Pn,{children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(Wo,{className:"w-5 h-5 text-bambu-green"}),a.jsx("h2",{className:"text-lg font-semibold text-white",children:i("settings.changePassword")})]}),a.jsx(ke,{variant:"ghost",size:"sm",onClick:()=>{He(!1),Ue({currentPassword:"",newPassword:"",confirmPassword:""})},children:a.jsx(Lt,{className:"w-5 h-5"})})]})}),a.jsxs(Mt,{children:[a.jsxs("div",{className:"space-y-4",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:"Current Password"}),a.jsx("input",{type:"password",value:tt.currentPassword,onChange:oe=>Ue({...tt,currentPassword:oe.target.value}),className:"w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors",placeholder:i("settings.enterCurrentPassword"),autoComplete:"current-password"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:"New Password"}),a.jsx("input",{type:"password",value:tt.newPassword,onChange:oe=>Ue({...tt,newPassword:oe.target.value}),className:"w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors",placeholder:i("settings.enterNewPasswordMin6"),autoComplete:"new-password",minLength:6})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:"Confirm New Password"}),a.jsx("input",{type:"password",value:tt.confirmPassword,onChange:oe=>Ue({...tt,confirmPassword:oe.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors ${tt.confirmPassword&&tt.newPassword!==tt.confirmPassword?"border-red-500":"border-bambu-dark-tertiary"}`,placeholder:i("settings.confirmNewPassword"),autoComplete:"new-password",minLength:6}),tt.confirmPassword&&tt.newPassword!==tt.confirmPassword&&a.jsx("p",{className:"text-red-400 text-xs mt-1",children:i("settings.passwordsDoNotMatch")})]})]}),a.jsxs("div",{className:"mt-6 flex justify-end gap-3",children:[a.jsx(ke,{variant:"secondary",onClick:()=>{He(!1),Ue({currentPassword:"",newPassword:"",confirmPassword:""})},children:"Cancel"}),a.jsx(ke,{onClick:async()=>{if(tt.newPassword!==tt.confirmPassword){o(i("settings.toast.passwordsDoNotMatch"),"error");return}if(tt.newPassword.length<6){o(i("settings.toast.passwordTooShort"),"error");return}Te(!0);try{await ce.changePassword(tt.currentPassword,tt.newPassword),o(i("settings.toast.passwordChanged"),"success"),He(!1),Ue({currentPassword:"",newPassword:"",confirmPassword:""})}catch(oe){const Nt=oe instanceof Error?oe.message:"Failed to change password";o(Nt,"error")}finally{Te(!1)}},disabled:xe||!tt.currentPassword||!tt.newPassword||tt.newPassword!==tt.confirmPassword||tt.newPassword.length<6,children:xe?a.jsxs(a.Fragment,{children:[a.jsx(ut,{className:"w-4 h-4 animate-spin"}),"Changing..."]}):a.jsxs(a.Fragment,{children:[a.jsx(Wo,{className:"w-4 h-4"}),"Change Password"]})})]})]})]})})]})}const cae=t=>{const e=parseFloat(t);return(Math.trunc(e*1e3)/1e3).toFixed(3)},fQe=t=>t.startsWith("HH")?"HF":"S",mQe=t=>{const e=t.match(/^([A-Z]{2}\d{2})/);return e?e[1]:"HH00"},UR=t=>{const e=["High Flow_","High Flow ","Standard_","Standard ","HF_","HF ","S_","S "];for(const r of e)if(t.startsWith(r))return t.slice(r.length);const n=t.indexOf("_");return n>0?t.slice(n+1):t};function bP({profile:t,onEdit:e,onCopy:n,selectionMode:r,isSelected:i,onToggleSelect:s,note:o}){const l=fQe(t.nozzle_id),c=t.nozzle_diameter,u=()=>{r&&s?s():e()};return a.jsxs("div",{className:"flex items-center gap-2",children:[r&&a.jsx("button",{onClick:s,className:"text-bambu-gray hover:text-white transition-colors p-1",children:i?a.jsx(qs,{className:"w-4 h-4 text-bambu-green"}):a.jsx(ll,{className:"w-4 h-4"})}),a.jsxs("button",{onClick:u,className:`flex-1 text-left px-3 py-2 bg-bambu-dark rounded hover:bg-bambu-dark-tertiary transition-colors ${i?"ring-1 ring-bambu-green":""}`,children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("span",{className:"text-bambu-green font-mono text-sm font-bold whitespace-nowrap",children:cae(t.k_value)}),a.jsx("span",{className:"text-white text-sm truncate flex-1",title:t.name,children:t.name||"Unnamed"}),o&&a.jsx("span",{title:"Has note",children:a.jsx(HK,{className:"w-3 h-3 text-yellow-500"})}),a.jsxs("span",{className:"text-xs text-bambu-gray whitespace-nowrap",children:[l," ",c]})]}),o&&a.jsxs("div",{className:"text-xs mt-0.5 truncate text-yellow-500/70",title:o,children:["Note: ",o.length>50?o.substring(0,50)+"...":o]})]}),!r&&n&&a.jsx("button",{onClick:d=>{d.stopPropagation(),n()},className:"text-bambu-gray hover:text-white transition-colors p-1",title:"Copy profile",children:a.jsx(Fl,{className:"w-4 h-4"})})]})}function xP({profile:t,printerId:e,nozzleDiameter:n,existingProfiles:r=[],isDualNozzle:i=!1,initialNote:s="",initialNoteKey:o=null,onClose:l,onSave:c,onSaveNote:u,hasPermission:d}){const{t:h}=Sn(),{showToast:m}=Hn(),[p,b]=_.useState(t?.name||""),[v,x]=_.useState(t?.k_value?cae(t.k_value):"0.020"),[y,S]=_.useState(t?.filament_id||""),[N,A]=_.useState(t?.nozzle_id?mQe(t.nozzle_id):"HH00"),[k,C]=_.useState(t?.nozzle_diameter||n),[E,P]=_.useState(t?[t.extruder_id]:i?[0,1]:[0]),[T,j]=_.useState(!1),[z,L]=_.useState({current:0,total:0}),[B,R]=_.useState(s),$=Jr.useMemo(()=>{const K=new Map;for(const ne of r)if(ne.filament_id&&!K.has(ne.filament_id)){const ie=UR(ne.name||"");K.set(ne.filament_id,{id:ne.filament_id,name:ie||ne.filament_id})}return Array.from(K.values()).sort((ne,ie)=>ne.name.localeCompare(ie.name))},[r]),q=pt({mutationFn:K=>(console.log("[KProfile] Calling API..."),ce.setKProfile(e,K)),onSuccess:K=>{if(console.log("[KProfile] Save success:",K),m(h("kProfiles.toast.profileSaved")),u&&B!==s){let ne;B===""&&o?ne=o:t&&t.slot_id>0?ne=t.setting_id||`slot_${t.slot_id}_${t.filament_id}_${t.extruder_id}`:ne=`name_${p}_${y}`,u(ne,B)}j(!0),setTimeout(()=>{j(!1),c()},2500)},onError:K=>{console.error("[KProfile] Save error:",K),m(K.message,"error"),j(!1)}}),I=pt({mutationFn:K=>(console.log("[KProfile] Deleting profile..."),ce.deleteKProfile(e,K)),onSuccess:K=>{console.log("[KProfile] Delete success:",K),m(h("kProfiles.toast.profileDeleted")),j(!0),setTimeout(()=>{j(!1),l()},4e3)},onError:K=>{console.error("[KProfile] Delete error:",K),m(K.message,"error"),j(!1)}}),[G,Y]=_.useState(!1),re=()=>{t&&I.mutate({slot_id:t.slot_id,extruder_id:t.extruder_id,nozzle_id:t.nozzle_id,nozzle_diameter:t.nozzle_diameter,filament_id:t.filament_id,setting_id:t.setting_id})},H=async K=>{if(K.preventDefault(),i&&!t&&E.length===0){m(h("kProfiles.toast.selectAtLeastOneExtruder"),"error");return}const ne=parseFloat(v).toFixed(6),ie=`${N}-${k}`;if(t||E.length===1){const pe={name:p,k_value:ne,filament_id:y,nozzle_id:ie,nozzle_diameter:k,extruder_id:t?t.extruder_id:E[0],setting_id:t?.setting_id,slot_id:t?.slot_id??0};console.log("[KProfile] Saving profile:",pe),q.mutate(pe);return}j(!0),L({current:1,total:E.length});const be=E.map(pe=>({name:p,k_value:ne,filament_id:y,nozzle_id:ie,nozzle_diameter:k,extruder_id:pe,setting_id:void 0,slot_id:0}));console.log(`[KProfile] Saving ${be.length} profiles in batch:`,be);try{if(await ce.setKProfilesBatch(e,be),m(h("kProfiles.toast.profilesSaved",{count:E.length})),u&&B){const pe=`name_${p}_${y}`;u(pe,B)}}catch(pe){console.error("[KProfile] Failed to save batch:",pe),m(h("kProfiles.toast.failedToSaveBatch"),"error"),j(!1),L({current:0,total:0});return}L({current:E.length,total:E.length}),setTimeout(()=>{j(!1),L({current:0,total:0}),c()},3e3)};return a.jsxs("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:[a.jsxs(_t,{className:"w-full max-w-md relative",children:[T&&a.jsxs("div",{className:"absolute inset-0 bg-bambu-dark-secondary/90 flex flex-col items-center justify-center z-10 rounded-lg",children:[a.jsx(ut,{className:"w-8 h-8 text-bambu-green animate-spin mb-3"}),a.jsx("p",{className:"text-white font-medium",children:z.total>1?h("kProfiles.modal.savingExtruder",{current:z.current,total:z.total}):h("kProfiles.modal.syncing")}),a.jsx("p",{className:"text-bambu-gray text-sm mt-1",children:h("kProfiles.modal.pleaseWait")})]}),a.jsxs(Mt,{className:"p-0",children:[a.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[a.jsx("h2",{className:"text-xl font-semibold text-white",children:h(t?"kProfiles.modal.editTitle":"kProfiles.modal.addTitle")}),a.jsx("button",{onClick:l,className:"text-bambu-gray hover:text-white transition-colors",disabled:T,children:a.jsx(Lt,{className:"w-5 h-5"})})]}),a.jsxs("form",{onSubmit:H,className:"p-4 space-y-4",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:h("kProfiles.modal.profileName")}),a.jsx("input",{type:"text",value:p,onChange:K=>b(K.target.value),disabled:!!t,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none ${t?"opacity-60 cursor-not-allowed":""}`,placeholder:h("kProfiles.modal.profileNamePlaceholder"),required:!t})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:h("kProfiles.modal.kValue")}),a.jsx("input",{type:"text",inputMode:"decimal",value:v,onChange:K=>{const ne=K.target.value;(ne===""||/^\d*\.?\d*$/.test(ne))&&x(ne)},onBlur:K=>{const ne=parseFloat(K.target.value);isNaN(ne)||x((Math.trunc(ne*1e3)/1e3).toFixed(3))},className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none font-mono",placeholder:h("kProfiles.modal.kValuePlaceholder"),required:!0}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:h("kProfiles.modal.kValueHelp")})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:h("kProfiles.modal.filament")}),a.jsxs("select",{value:y,onChange:K=>{const ne=K.target.value;if(S(ne),!t&&ne&&!p){const ie=$.find(be=>be.id===ne);ie&&b(`${N==="HH00"?"HF":"S"} ${ie.name}`)}},disabled:!!t,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none ${t?"opacity-60 cursor-not-allowed":""}`,required:!t,children:[a.jsx("option",{value:"",children:h("kProfiles.modal.selectFilament")}),t?.filament_id&&a.jsx("option",{value:t.filament_id,children:$.find(K=>K.id===t.filament_id)?.name||t.filament_id},t.filament_id),!t&&$.map(K=>a.jsx("option",{value:K.id,children:K.name},K.id))]}),!t&&$.length===0&&a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:h("kProfiles.modal.noFilamentsHelp")})]}),a.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:h("kProfiles.modal.flowType")}),a.jsxs("select",{value:N,onChange:K=>{const ne=K.target.value;if(A(ne),!t&&y&&!p){const ie=$.find(be=>be.id===y);ie&&b(`${ne==="HS00"?"HF":"S"} ${ie.name}`)}},disabled:!!t,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none ${t?"opacity-60 cursor-not-allowed":""}`,children:[a.jsx("option",{value:"HH00",children:h("kProfiles.modal.highFlow")}),a.jsx("option",{value:"HS00",children:h("kProfiles.modal.standard")})]})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:h("kProfiles.modal.nozzleSize")}),a.jsxs("select",{value:k,onChange:K=>C(K.target.value),disabled:!!t,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none ${t?"opacity-60 cursor-not-allowed":""}`,children:[a.jsx("option",{value:"0.2",children:"0.2mm"}),a.jsx("option",{value:"0.4",children:"0.4mm"}),a.jsx("option",{value:"0.6",children:"0.6mm"}),a.jsx("option",{value:"0.8",children:"0.8mm"})]})]})]}),i&&a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:h(t?"kProfiles.modal.extruder":"kProfiles.modal.extruders")}),t?a.jsx("div",{className:"px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white opacity-60",children:t.extruder_id===1?h("kProfiles.modal.left"):h("kProfiles.modal.right")}):a.jsxs("div",{className:"flex gap-4",children:[a.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:E.includes(1),onChange:K=>{K.target.checked?P([...E,1]):P(E.filter(ne=>ne!==1))},className:"w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green focus:ring-offset-0 accent-bambu-green"}),a.jsx("span",{className:"text-white",children:h("kProfiles.modal.left")})]}),a.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:E.includes(0),onChange:K=>{K.target.checked?P([...E,0]):P(E.filter(ne=>ne!==0))},className:"w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green focus:ring-offset-0 accent-bambu-green"}),a.jsx("span",{className:"text-white",children:h("kProfiles.modal.right")})]})]})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:h("kProfiles.modal.notes")}),a.jsx("textarea",{value:B,onChange:K=>R(K.target.value),placeholder:h("kProfiles.modal.notesPlaceholder"),rows:2,className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none resize-none"}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:h("kProfiles.modal.notesHelp")})]}),a.jsxs("div",{className:"flex gap-2 pt-4",children:[t&&a.jsx(ke,{type:"button",variant:"secondary",onClick:()=>Y(!0),disabled:I.isPending||T||!d("kprofiles:delete"),title:d("kprofiles:delete")?void 0:h("kProfiles.permission.noDelete"),className:"text-red-500 hover:bg-red-500/10",children:I.isPending?a.jsx(ut,{className:"w-4 h-4 animate-spin"}):a.jsx(cn,{className:"w-4 h-4"})}),a.jsx(ke,{type:"button",variant:"secondary",onClick:l,disabled:T,className:"flex-1",children:h("common.cancel")}),a.jsxs(ke,{type:"submit",disabled:q.isPending||T||!d(t?"kprofiles:update":"kprofiles:create"),title:d(t?"kprofiles:update":"kprofiles:create")?void 0:h(t?"kProfiles.permission.noUpdate":"kProfiles.permission.noCreate"),className:"flex-1",children:[q.isPending?a.jsx(ut,{className:"w-4 h-4 animate-spin"}):a.jsx(FM,{className:"w-4 h-4"}),h("common.save")]})]})]})]})]}),G&&a.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-[60]",children:a.jsx(_t,{className:"w-full max-w-sm",children:a.jsxs(Mt,{className:"p-6",children:[a.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[a.jsx("div",{className:"w-10 h-10 rounded-full bg-red-500/20 flex items-center justify-center",children:a.jsx(cn,{className:"w-5 h-5 text-red-500"})}),a.jsxs("div",{children:[a.jsx("h3",{className:"text-lg font-semibold text-white",children:h("kProfiles.deleteConfirm.title")}),a.jsx("p",{className:"text-sm text-bambu-gray",children:h("kProfiles.deleteConfirm.cannotUndo")})]})]}),a.jsx("p",{className:"text-bambu-gray mb-6",children:h("kProfiles.deleteConfirm.message",{name:t?.name})}),a.jsxs("div",{className:"flex gap-3",children:[a.jsx(ke,{variant:"secondary",onClick:()=>Y(!1),className:"flex-1",children:h("common.cancel")}),a.jsxs(ke,{onClick:()=>{Y(!1),re()},disabled:I.isPending,className:"flex-1 bg-red-500 hover:bg-red-600 text-white",children:[I.isPending?a.jsx(ut,{className:"w-4 h-4 animate-spin"}):a.jsx(cn,{className:"w-4 h-4"}),h("common.delete")]})]})]})})})]})}const A1={NOZZLE_DIAMETER:"bambusy_kprofiles_nozzle",SORT_OPTION:"bambusy_kprofiles_sort"};function pQe(){const{t}=Sn(),{showToast:e}=Hn(),{hasPermission:n}=Di(),[r,i]=_.useState(null),[s,o]=_.useState(()=>localStorage.getItem(A1.NOZZLE_DIAMETER)||"0.4"),[l,c]=_.useState(null),[u,d]=_.useState(!1),[h,m]=_.useState(null),[p,b]=_.useState(""),[v,x]=_.useState("all"),[y,S]=_.useState("all"),[N,A]=_.useState(()=>localStorage.getItem(A1.SORT_OPTION)||"name"),[k,C]=_.useState(!1),[E,P]=_.useState(new Set),[T,j]=_.useState(!1),[z,L]=_.useState(!1),B=_.useCallback(V=>`${V.slot_id}_${V.extruder_id}`,[]);_.useEffect(()=>{localStorage.setItem(A1.NOZZLE_DIAMETER,s)},[s]),_.useEffect(()=>{localStorage.setItem(A1.SORT_OPTION,N)},[N]);const{data:R,isLoading:$}=st({queryKey:["printers"],queryFn:ce.getPrinters}),{data:q,isLoading:I,isFetching:G,error:Y,refetch:re}=st({queryKey:["kprofiles",r,s],queryFn:async()=>{console.log("[KProfiles] Fetching profiles for printer",r,"nozzle",s);const V=await ce.getKProfiles(r,s);return console.log("[KProfiles] Received profiles:",V?.profiles?.length||0,"profiles"),V},enabled:!!r,retry:!1,staleTime:0,gcTime:0,refetchOnMount:"always"}),{data:H}=st({queryKey:["kprofiles",r,"0.4"],queryFn:()=>ce.getKProfiles(r,"0.4"),enabled:!!r,staleTime:6e4}),{data:K,refetch:ne}=st({queryKey:["kprofile-notes",r],queryFn:()=>ce.getKProfileNotes(r),enabled:!!r,staleTime:3e4}),ie=Y?.message?.includes("not connected");_.useEffect(()=>{if(!r&&R&&R.length>0){const V=R.find(ge=>ge.is_active);V&&i(V.id)}},[r,R]),_.useEffect(()=>{if(r){const V=setTimeout(()=>{re()},150);return()=>clearTimeout(V)}},[r,s]);const be=R?.filter(V=>V.is_active)||[],pe=Jr.useMemo(()=>q?.profiles?q.profiles.filter(ge=>{const Se=p.toLowerCase(),ee=!Se||ge.name.toLowerCase().includes(Se)||ge.filament_id.toLowerCase().includes(Se),U=v==="all"||v==="left"&&ge.extruder_id===1||v==="right"&&ge.extruder_id===0,O=y==="all"||y==="hf"&&ge.nozzle_id.startsWith("HH")||y==="s"&&ge.nozzle_id.startsWith("HS");return ee&&U&&O}).sort((ge,Se)=>{switch(N){case"k_value":return parseFloat(ge.k_value)-parseFloat(Se.k_value);case"filament":return UR(ge.name).localeCompare(UR(Se.name));default:return ge.name.localeCompare(Se.name)}}):[],[q?.profiles,p,v,y,N]),de=R?.find(V=>V.id===r),Ce=de?.nozzle_count===2;_.useEffect(()=>{const V=ge=>{ge.target instanceof HTMLInputElement||ge.target instanceof HTMLTextAreaElement||ge.target instanceof HTMLSelectElement||l||u||h||(ge.key==="r"||ge.key==="R"?(ge.preventDefault(),re()):ge.key==="n"||ge.key==="N"?(ge.preventDefault(),d(!0)):ge.key==="Escape"&&k&&(ge.preventDefault(),C(!1),P(new Set)))};return window.addEventListener("keydown",V),()=>window.removeEventListener("keydown",V)},[l,u,h,k,re]);const ae=_.useCallback(()=>{if(!q?.profiles||q.profiles.length===0){e(t("kProfiles.toast.noProfilesToExport"),"error");return}const V={version:1,exported_at:new Date().toISOString(),printer:de?.name||"Unknown",nozzle_diameter:s,profiles:q.profiles.map(U=>({name:U.name,k_value:U.k_value,filament_id:U.filament_id,nozzle_id:U.nozzle_id,nozzle_diameter:U.nozzle_diameter,extruder_id:U.extruder_id}))},ge=new Blob([JSON.stringify(V,null,2)],{type:"application/json"}),Se=URL.createObjectURL(ge),ee=document.createElement("a");ee.href=Se,ee.download=`kprofiles_${de?.name||"printer"}_${s}mm_${new Date().toISOString().split("T")[0]}.json`,document.body.appendChild(ee),ee.click(),document.body.removeChild(ee),URL.revokeObjectURL(Se),e(t("kProfiles.toast.exportedProfiles",{count:q.profiles.length}))},[q?.profiles,de,s,e,t]),Ae=_.useCallback(()=>{const V=document.createElement("input");V.type="file",V.accept=".json",V.onchange=async ge=>{const Se=ge.target.files?.[0];if(Se)try{const ee=await Se.text(),U=JSON.parse(ee);if(!U.profiles||!Array.isArray(U.profiles)){e(t("kProfiles.toast.invalidFileFormat"),"error");return}let O=0;for(const Z of U.profiles)if(!(!Z.name||!Z.k_value||!Z.filament_id))try{await ce.setKProfile(r,{name:Z.name,k_value:parseFloat(Z.k_value).toFixed(6),filament_id:Z.filament_id,nozzle_id:Z.nozzle_id||`HH00-${s}`,nozzle_diameter:Z.nozzle_diameter||s,extruder_id:Z.extruder_id??0,slot_id:0}),O++,await new Promise(le=>setTimeout(le,500))}catch(le){console.error("Failed to import profile:",Z.name,le)}e(t("kProfiles.toast.importedProfiles",{count:O,total:U.profiles.length})),re()}catch(ee){console.error("Import error:",ee),e(t("kProfiles.toast.failedToParseImport"),"error")}},V.click()},[r,s,e,re,t]),Le=_.useCallback(V=>{P(ge=>{const Se=new Set(ge);return Se.has(V)?Se.delete(V):Se.add(V),Se})},[]),fe=_.useCallback(()=>{P(new Set(pe.map(V=>B(V))))},[pe,B]),Xe=_.useCallback(()=>{E.size!==0&&j(!0)},[E.size]),W=_.useCallback(async()=>{const V=pe.filter(Se=>E.has(B(Se)));L(!0);let ge=0;for(const Se of V)try{await ce.deleteKProfile(r,{slot_id:Se.slot_id,extruder_id:Se.extruder_id,nozzle_id:Se.nozzle_id,nozzle_diameter:Se.nozzle_diameter,filament_id:Se.filament_id,setting_id:Se.setting_id}),ge++,await new Promise(ee=>setTimeout(ee,300))}catch(ee){console.error("Failed to delete profile:",Se.name,ee)}e(t("kProfiles.toast.profilesDeleted",{count:ge})),L(!1),j(!1),C(!1),P(new Set),re()},[r,E,pe,e,re,B,t]),Q=_.useCallback(V=>{const ge=[];return V.setting_id&&ge.push(V.setting_id),ge.push(`slot_${V.slot_id}_${V.filament_id}_${V.extruder_id}`),ge.push(`name_${V.name}_${V.filament_id}`),ge},[]),me=_.useCallback(async(V,ge)=>{if(r)try{await ce.setKProfileNote(r,V,ge),ne()}catch(Se){console.error("Failed to save note:",Se),e(t("kProfiles.toast.failedToSaveNote"),"error")}},[r,ne,e,t]),X=_.useCallback(V=>{if(!K?.notes)return{note:"",key:null};const ge=Q(V);for(const Se of ge)if(K.notes[Se])return{note:K.notes[Se],key:Se};return{note:"",key:null}},[K,Q]),te=_.useCallback(V=>X(V).note,[X]);return $?a.jsx("div",{className:"flex justify-center py-12",children:a.jsx(ut,{className:"w-8 h-8 text-bambu-green animate-spin"})}):!R||R.length===0?a.jsx(_t,{children:a.jsxs(Mt,{className:"py-12 text-center",children:[a.jsx(Wi,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),a.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:t("kProfiles.noPrintersConfigured")}),a.jsx("p",{className:"text-bambu-gray",children:t("kProfiles.addPrinterInSettings")})]})}):be.length===0?a.jsx(_t,{children:a.jsxs(Mt,{className:"py-12 text-center",children:[a.jsx(Or,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),a.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:t("kProfiles.noActivePrinters")}),a.jsx("p",{className:"text-bambu-gray",children:t("kProfiles.enablePrinterConnection")})]})}):a.jsxs(a.Fragment,{children:[G&&!I&&a.jsxs("div",{className:"fixed inset-0 bg-black/50 flex flex-col items-center justify-center z-40",children:[a.jsx(ut,{className:"w-10 h-10 text-bambu-green animate-spin mb-3"}),a.jsx("p",{className:"text-white font-medium",children:t("kProfiles.loadingProfiles")})]}),a.jsxs("div",{className:"flex flex-wrap gap-4 mb-6",children:[a.jsxs("div",{className:"flex-1 min-w-48",children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:t("kProfiles.printer")}),a.jsx("select",{value:r||"",onChange:V=>i(parseInt(V.target.value)),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:be.map(V=>a.jsx("option",{value:V.id,children:V.name},V.id))})]}),a.jsxs("div",{className:"w-32",children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:t("kProfiles.nozzle")}),a.jsxs("select",{value:s,onChange:V=>o(V.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[a.jsx("option",{value:"0.2",children:"0.2mm"}),a.jsx("option",{value:"0.4",children:"0.4mm"}),a.jsx("option",{value:"0.6",children:"0.6mm"}),a.jsx("option",{value:"0.8",children:"0.8mm"})]})]}),a.jsxs("div",{className:"flex items-end gap-2",children:[a.jsxs(ke,{variant:"secondary",onClick:()=>re(),disabled:G||!n("kprofiles:read"),title:n("kprofiles:read")?void 0:t("kProfiles.permission.noRead"),children:[a.jsx(Ir,{className:`w-4 h-4 ${G?"animate-spin":""}`}),t("kProfiles.refresh")]}),a.jsxs(ke,{onClick:()=>d(!0),disabled:!n("kprofiles:create"),title:n("kprofiles:create")?void 0:t("kProfiles.permission.noCreate"),children:[a.jsx(dr,{className:"w-4 h-4"}),t("kProfiles.addProfile")]})]})]}),a.jsxs("div",{className:"flex flex-wrap gap-4 mb-4",children:[a.jsxs("div",{className:"flex-1 min-w-48 relative",children:[a.jsx(va,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),a.jsx("input",{type:"text",value:p,onChange:V=>b(V.target.value),placeholder:t("kProfiles.searchPlaceholder"),className:"w-full pl-10 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"})]}),Ce&&a.jsx("div",{className:"w-36",children:a.jsxs("select",{value:v,onChange:V=>x(V.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[a.jsx("option",{value:"all",children:t("kProfiles.allExtruders")}),a.jsx("option",{value:"left",children:t("kProfiles.leftOnly")}),a.jsx("option",{value:"right",children:t("kProfiles.rightOnly")})]})}),a.jsx("div",{className:"w-32",children:a.jsxs("select",{value:y,onChange:V=>S(V.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[a.jsx("option",{value:"all",children:t("kProfiles.allFlow")}),a.jsx("option",{value:"hf",children:t("kProfiles.hfOnly")}),a.jsx("option",{value:"s",children:t("kProfiles.sOnly")})]})}),a.jsx("div",{className:"w-32",children:a.jsxs("select",{value:N,onChange:V=>A(V.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[a.jsx("option",{value:"name",children:t("kProfiles.sortName")}),a.jsx("option",{value:"k_value",children:t("kProfiles.sortKValue")}),a.jsx("option",{value:"filament",children:t("kProfiles.sortFilament")})]})})]}),a.jsxs("div",{className:"flex flex-wrap gap-2 mb-6",children:[a.jsxs(ke,{variant:"secondary",onClick:ae,disabled:!q?.profiles?.length||!n("kprofiles:read"),title:n("kprofiles:read")?void 0:t("kProfiles.permission.noExport"),children:[a.jsx(Ni,{className:"w-4 h-4"}),t("kProfiles.export")]}),a.jsxs(ke,{variant:"secondary",onClick:Ae,disabled:!n("kprofiles:create"),title:n("kprofiles:create")?void 0:t("kProfiles.permission.noImport"),children:[a.jsx($a,{className:"w-4 h-4"}),t("kProfiles.import")]}),a.jsx("div",{className:"flex-1"}),k?a.jsxs(a.Fragment,{children:[a.jsxs(ke,{variant:"secondary",onClick:fe,children:[a.jsx(qs,{className:"w-4 h-4"}),t("kProfiles.selectAll")]}),a.jsxs(ke,{variant:"secondary",onClick:Xe,disabled:E.size===0||!n("kprofiles:delete"),className:"text-red-500 hover:bg-red-500/10",title:n("kprofiles:delete")?void 0:t("kProfiles.permission.noDelete"),children:[a.jsx(cn,{className:"w-4 h-4"}),t("kProfiles.delete")," (",E.size,")"]}),a.jsxs(ke,{variant:"secondary",onClick:()=>{C(!1),P(new Set)},children:[a.jsx(Lt,{className:"w-4 h-4"}),t("common.cancel")]})]}):a.jsxs(ke,{variant:"secondary",onClick:()=>C(!0),disabled:!pe.length||!n("kprofiles:delete"),title:n("kprofiles:delete")?void 0:t("kProfiles.permission.noDelete"),children:[a.jsx(qs,{className:"w-4 h-4"}),t("kProfiles.select")]})]}),I?a.jsx("div",{className:"flex justify-center py-12",children:a.jsx(ut,{className:"w-8 h-8 text-bambu-green animate-spin"})}):ie?a.jsx(_t,{children:a.jsxs(Mt,{className:"py-12 text-center",children:[a.jsx(_m,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),a.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:t("kProfiles.printerOffline")}),a.jsx("p",{className:"text-bambu-gray mb-4",children:t("kProfiles.printerOfflineDesc")}),a.jsxs(ke,{variant:"secondary",onClick:()=>re(),children:[a.jsx(Ir,{className:"w-4 h-4"}),t("common.refresh")]})]})}):pe.length>0?Ce?a.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[a.jsxs("div",{children:[a.jsx("h3",{className:"text-sm font-medium text-bambu-gray mb-2 px-1",children:t("kProfiles.leftExtruder")}),a.jsx("div",{className:"space-y-1",children:pe.filter(V=>V.extruder_id===1).map(V=>a.jsx(bP,{profile:V,onEdit:()=>c(V),onCopy:()=>m(V),selectionMode:k,isSelected:E.has(B(V)),onToggleSelect:()=>Le(B(V)),note:te(V)},B(V)))})]}),a.jsxs("div",{children:[a.jsx("h3",{className:"text-sm font-medium text-bambu-gray mb-2 px-1",children:t("kProfiles.rightExtruder")}),a.jsx("div",{className:"space-y-1",children:pe.filter(V=>V.extruder_id===0).map(V=>a.jsx(bP,{profile:V,onEdit:()=>c(V),onCopy:()=>m(V),selectionMode:k,isSelected:E.has(B(V)),onToggleSelect:()=>Le(B(V)),note:te(V)},B(V)))})]})]}):a.jsx("div",{className:"space-y-1",children:pe.map(V=>a.jsx(bP,{profile:V,onEdit:()=>c(V),onCopy:()=>m(V),selectionMode:k,isSelected:E.has(B(V)),onToggleSelect:()=>Le(B(V)),note:te(V)},B(V)))}):p||v!=="all"||y!=="all"?a.jsx(_t,{children:a.jsxs(Mt,{className:"py-12 text-center",children:[a.jsx(va,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),a.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:t("kProfiles.noMatchingProfiles")}),a.jsx("p",{className:"text-bambu-gray",children:t("kProfiles.noMatchingProfilesDesc")})]})}):a.jsx(_t,{children:a.jsxs(Mt,{className:"py-12 text-center",children:[a.jsx(FM,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),a.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:t("kProfiles.noKProfiles")}),a.jsx("p",{className:"text-bambu-gray mb-4",children:t("kProfiles.noKProfilesDesc",{diameter:s})}),a.jsxs(ke,{onClick:()=>d(!0),children:[a.jsx(dr,{className:"w-4 h-4"}),t("kProfiles.createFirstProfile")]})]})}),l&&r&&(()=>{const{note:V,key:ge}=X(l);return a.jsx(xP,{profile:l,printerId:r,nozzleDiameter:s,existingProfiles:H?.profiles||q?.profiles,isDualNozzle:Ce,initialNote:V,initialNoteKey:ge,onSaveNote:me,hasPermission:n,onClose:()=>{console.log("[KProfiles] Edit modal onClose - refetching profiles..."),c(null),re()},onSave:()=>{c(null),re()}})})(),u&&r&&a.jsx(xP,{printerId:r,nozzleDiameter:s,existingProfiles:H?.profiles||q?.profiles,isDualNozzle:Ce,onSaveNote:me,hasPermission:n,onClose:()=>{d(!1),re()},onSave:()=>{d(!1),re()}}),h&&r&&a.jsx(xP,{printerId:r,nozzleDiameter:s,existingProfiles:H?.profiles||q?.profiles,isDualNozzle:Ce,onSaveNote:me,hasPermission:n,profile:{...h,slot_id:0,name:`${h.name} (Copy)`},onClose:()=>{m(null),re()},onSave:()=>{m(null),re()}}),T&&a.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:a.jsx(_t,{className:"w-full max-w-sm",children:a.jsxs(Mt,{className:"p-6",children:[a.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[a.jsx("div",{className:"w-10 h-10 rounded-full bg-red-500/20 flex items-center justify-center",children:a.jsx(cn,{className:"w-5 h-5 text-red-500"})}),a.jsxs("div",{children:[a.jsx("h3",{className:"text-lg font-semibold text-white",children:t("kProfiles.bulkDelete.title")}),a.jsx("p",{className:"text-sm text-bambu-gray",children:t("kProfiles.bulkDelete.cannotUndo")})]})]}),a.jsx("p",{className:"text-bambu-gray mb-6",children:t("kProfiles.bulkDelete.message",{count:E.size})}),a.jsxs("div",{className:"flex gap-3",children:[a.jsx(ke,{variant:"secondary",onClick:()=>j(!1),disabled:z,className:"flex-1",children:t("common.cancel")}),a.jsxs(ke,{onClick:W,disabled:z,className:"flex-1 bg-red-500 hover:bg-red-600 text-white",children:[z?a.jsx(ut,{className:"w-4 h-4 animate-spin"}):a.jsx(cn,{className:"w-4 h-4"}),t("common.delete")]})]})]})})})]})}function HF(t,e){const n=`${t} ${e||""}`,r=n.match(/@?\s*(?:BBL\s+)?(?:Bambu\s+Lab\s+)?([XPAH][1-9][A-Z]?(?:\s*(?:Carbon|mini))?|H2D)/i),i=r?r[1].trim():null,s=n.match(/(\d+\.?\d*)\s*(?:mm\s*)?nozzle|nozzle\s*(\d+\.?\d*)/i),o=s?(s[1]||s[2])+"mm":null,l=n.match(/(\d+\.?\d*)mm\s*(?:Standard|Fine|Extra Fine|Draft|Quality)?/i),c=l?l[1]+"mm":null,u=n.match(/\b(PLA|PETG|ABS|ASA|TPU|PC|PA|PVA|HIPS|PP|PET(?:-?CF)?|PA(?:-?CF)?|PLA(?:-?CF)?)\b/i),d=u?u[1].toUpperCase():null;return{printer:i,nozzle:o,layerHeight:c,filamentType:d}}function Yy(t){return/^(P[FPM]US|PF\d|PP\d)/.test(t)}function gQe(t,e){const n=Hi(t);if(!n)return"";const i=new Date().getTime()-n.getTime(),s=Math.floor(i/6e4),o=Math.floor(i/36e5),l=Math.floor(i/864e5);return s<1?e("profiles.time.justNow"):s<60?e("profiles.time.minsAgo",{count:s}):o<24?e("profiles.time.hoursAgo",{count:o}):l<7?e("profiles.time.daysAgo",{count:l}):n.toLocaleDateString()}function bQe({onSuccess:t,t:e}){const{showToast:n}=Hn(),[r,i]=_.useState("email"),[s,o]=_.useState(""),[l,c]=_.useState(""),[u,d]=_.useState(""),[h,m]=_.useState(""),[p,b]=_.useState("global"),[v,x]=_.useState(null),[y,S]=_.useState(null),N=pt({mutationFn:()=>ce.cloudLogin(s,l,p),onSuccess:P=>{P.success?(n(e("profiles.login.toast.loggedIn")),t()):P.needs_verification?(x(P.verification_type||"email"),S(P.tfa_key||null),P.verification_type==="totp"?n(e("profiles.login.toast.enterTotp")):n(e("profiles.login.toast.codeSent")),i("code")):n(P.message,"error")},onError:P=>n(P.message,"error")}),A=pt({mutationFn:()=>ce.cloudVerify(s,u,y||void 0),onSuccess:P=>{P.success?(n(e("profiles.login.toast.loggedIn")),t()):n(P.message,"error")},onError:P=>n(P.message,"error")}),k=pt({mutationFn:()=>ce.cloudSetToken(h),onSuccess:()=>{n(e("profiles.login.toast.tokenSet")),t()},onError:P=>n(P.message,"error")}),C=P=>{P.preventDefault(),r==="email"?N.mutate():r==="code"?A.mutate():r==="token"&&k.mutate()},E=N.isPending||A.isPending||k.isPending;return a.jsx(_t,{className:"max-w-md mx-auto",children:a.jsxs(Mt,{children:[a.jsxs("div",{className:"text-center mb-6",children:[a.jsx("div",{className:"inline-flex items-center justify-center w-12 h-12 rounded-xl bg-bambu-green/20 mb-3",children:a.jsx(DM,{className:"w-6 h-6 text-bambu-green"})}),a.jsx("h2",{className:"text-xl font-semibold text-white",children:e("profiles.login.title")}),a.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:e("profiles.login.subtitle")})]}),a.jsxs("form",{onSubmit:C,className:"space-y-4",children:[r==="email"&&a.jsxs(a.Fragment,{children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:e("profiles.login.email")}),a.jsx("input",{type:"email",value:s,onChange:P=>o(P.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none",placeholder:"your@email.com",required:!0})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:e("profiles.login.password")}),a.jsx("input",{type:"password",value:l,onChange:P=>c(P.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none",placeholder:"••••••••",required:!0})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:e("profiles.login.region")}),a.jsxs("select",{value:p,onChange:P=>b(P.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[a.jsx("option",{value:"global",children:e("profiles.login.regionGlobal")}),a.jsx("option",{value:"china",children:e("profiles.login.regionChina")})]})]})]}),r==="code"&&a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:e(v==="totp"?"profiles.login.totpCode":"profiles.login.verificationCode")}),a.jsx("p",{className:"text-xs text-bambu-gray mb-2",children:v==="totp"?e("profiles.login.enterTotpHint"):e("profiles.login.checkEmail",{email:s})}),a.jsx("input",{type:"text",value:u,onChange:P=>d(P.target.value.replace(/\D/g,"").slice(0,6)),className:"w-full px-3 py-3 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-center text-2xl tracking-widest font-mono focus:border-bambu-green focus:outline-none",placeholder:"000000",maxLength:6,required:!0})]}),r==="token"&&a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:e("profiles.login.accessToken")}),a.jsx("p",{className:"text-xs text-bambu-gray mb-2",children:e("profiles.login.accessTokenHint")}),a.jsx("textarea",{value:h,onChange:P=>m(P.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-xs font-mono placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none resize-none",placeholder:"eyJ...",rows:4,required:!0})]}),a.jsxs("div",{className:"flex gap-2",children:[r==="code"&&a.jsx(ke,{type:"button",variant:"secondary",onClick:()=>i("email"),className:"flex-1",children:e("profiles.login.back")}),a.jsxs(ke,{type:"submit",disabled:E,className:"flex-1",children:[E?a.jsx(ut,{className:"w-4 h-4 animate-spin"}):a.jsx(fB,{className:"w-4 h-4"}),e(r==="email"?"profiles.login.loginButton":r==="code"?"profiles.login.verifyButton":"profiles.login.setTokenButton")]})]}),r==="email"&&a.jsx("div",{className:"pt-4 border-t border-bambu-dark-tertiary",children:a.jsxs("button",{type:"button",onClick:()=>i("token"),className:"text-sm text-bambu-gray hover:text-white flex items-center gap-2 transition-colors",children:[a.jsx(Wo,{className:"w-4 h-4"}),e("profiles.login.useToken")]})}),r==="token"&&a.jsx("div",{className:"pt-4 border-t border-bambu-dark-tertiary",children:a.jsxs("button",{type:"button",onClick:()=>i("email"),className:"text-sm text-bambu-gray hover:text-white flex items-center gap-2 transition-colors",children:[a.jsx(fB,{className:"w-4 h-4"}),e("profiles.login.useEmail")]})})]})]})})}function xg({label:t,value:e,options:n,onChange:r}){const[i,s]=_.useState(!1),o=n.find(l=>l.value===e);return a.jsxs("div",{className:"relative",children:[a.jsxs("button",{onClick:()=>s(!i),className:"flex items-center gap-2 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-sm text-white hover:border-bambu-gray-dark transition-colors",children:[a.jsxs("span",{className:"text-bambu-gray",children:[t,":"]}),a.jsx("span",{children:o?.label||"All"}),a.jsx(Sr,{className:`w-4 h-4 text-bambu-gray transition-transform ${i?"rotate-180":""}`})]}),i&&a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"fixed inset-0 z-10",onClick:()=>s(!1)}),a.jsx("div",{className:"absolute top-full left-0 mt-1 min-w-[160px] bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-20 py-1 max-h-60 overflow-y-auto",children:n.map(l=>a.jsxs("button",{onClick:()=>{r(l.value),s(!1)},className:`w-full px-3 py-2 text-left text-sm flex items-center justify-between hover:bg-bambu-dark-tertiary transition-colors ${e===l.value?"text-bambu-green":"text-white"}`,children:[a.jsx("span",{children:l.label}),l.count!==void 0&&a.jsx("span",{className:"text-bambu-gray text-xs",children:l.count})]},l.value))})]})]})}function xQe(){const[t,e]=_.useState(!1);_.useEffect(()=>{const r=()=>{e(window.scrollY>300)};return window.addEventListener("scroll",r),()=>window.removeEventListener("scroll",r)},[]);const n=()=>{window.scrollTo({top:0,behavior:"smooth"})};return t?a.jsx("button",{onClick:n,className:"fixed bottom-6 right-6 p-3 bg-bambu-green hover:bg-bambu-green-light text-white rounded-full shadow-lg shadow-bambu-green/25 transition-all z-40","aria-label":"Scroll to top",children:a.jsx(Zg,{className:"w-5 h-5"})}):null}function yP({setting:t,onClick:e,onDuplicate:n,compareMode:r,isCompareSelected:i,compareIndex:s,compareDisabled:o,t:l}){const c=HF(t.name),u=Yy(t.setting_id);return a.jsxs("div",{className:"flex items-center gap-2 group",children:[a.jsx("button",{onClick:e,disabled:o,className:`flex-1 text-left px-3 py-2 rounded transition-colors ${i?"bg-blue-500/20 border border-blue-500/50":o?"bg-bambu-dark/50 opacity-40 cursor-not-allowed":"bg-bambu-dark hover:bg-bambu-dark-tertiary"} ${r&&!o?"cursor-pointer":""}`,children:a.jsxs("div",{className:"flex items-center gap-2",children:[i&&s!==void 0&&a.jsx("span",{className:"flex-shrink-0 w-5 h-5 rounded-full bg-blue-500 text-white text-xs flex items-center justify-center font-medium",children:s+1}),!i&&u&&a.jsx("span",{className:"flex-shrink-0 w-1.5 h-1.5 rounded-full bg-bambu-green",title:l("profiles.presets.myPreset")}),a.jsx("span",{className:"text-white text-sm truncate flex-1",title:t.name,children:t.name}),c.filamentType&&t.type==="filament"&&a.jsx("span",{className:"text-xs text-bambu-gray whitespace-nowrap",children:c.filamentType}),c.layerHeight&&t.type==="process"&&a.jsx("span",{className:"text-xs text-bambu-gray whitespace-nowrap",children:c.layerHeight}),c.printer&&a.jsx("span",{className:"text-xs text-bambu-gray whitespace-nowrap",children:c.printer})]})}),a.jsx("button",{onClick:d=>{d.stopPropagation(),n()},className:"opacity-0 group-hover:opacity-100 text-bambu-gray hover:text-white transition-all p-1",title:l("profiles.presets.duplicate"),children:a.jsx(Fl,{className:"w-4 h-4"})})]})}function zR(t,e=0){const n=" ".repeat(e);if(t===null)return"null";if(t===void 0)return"undefined";if(typeof t=="string"){if(t.includes("\\n")||t.includes(`
+ `,children:a.jsxs("div",{className:"flex items-center gap-4 p-4",children:[P&&d&&a.jsx("button",{onClick:j=>{j.stopPropagation(),d()},className:`flex items-center justify-center w-6 h-6 rounded border transition-colors ${u?"bg-bambu-green border-bambu-green text-white":"border-white/30 bg-black/30 hover:border-bambu-green/50"}`,children:u&&a.jsx(qi,{className:"w-4 h-4"})}),P?a.jsx("div",{...x,...y,className:"flex items-center justify-center w-10 h-10 md:w-8 md:h-8 rounded-lg bg-bambu-dark cursor-grab active:cursor-grabbing hover:bg-bambu-dark-tertiary transition-colors touch-manipulation",children:a.jsx(eb,{className:"w-6 h-6 md:w-4 md:h-4 text-bambu-gray"})}):e!==void 0?a.jsxs("div",{className:"flex items-center justify-center w-8 h-8 rounded-lg bg-bambu-dark text-bambu-gray text-sm font-medium",children:["#",e]}):a.jsx("div",{className:"w-8"}),a.jsx("div",{className:"w-14 h-14 flex-shrink-0 bg-bambu-dark rounded-lg overflow-hidden",children:t.archive_thumbnail?a.jsx("img",{src:t.plate_id!=null?ce.getArchivePlateThumbnail(t.archive_id,t.plate_id):ce.getArchiveThumbnail(t.archive_id),alt:"",className:"w-full h-full object-cover"}):t.library_file_thumbnail?a.jsx("img",{src:t.plate_id!=null?ce.getLibraryFilePlateThumbnail(t.library_file_id,t.plate_id):ce.getLibraryFileThumbnailUrl(t.library_file_id),alt:"",className:"w-full h-full object-cover"}):a.jsx("div",{className:"w-full h-full flex items-center justify-center text-bambu-gray",children:a.jsx(ys,{className:"w-6 h-6"})})}),a.jsxs("div",{className:"flex-1 min-w-0",children:[a.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[a.jsx("p",{className:"text-white font-medium truncate",children:t.archive_name||t.library_file_name||`File #${t.archive_id||t.library_file_id}`}),t.archive_id?a.jsx(Fs,{to:`/archives?highlight=${t.archive_id}`,className:"text-bambu-gray hover:text-bambu-green transition-colors flex-shrink-0",title:b("queue.viewArchive"),children:a.jsx(Xr,{className:"w-3.5 h-3.5"})}):t.library_file_id?a.jsx(Fs,{to:`/library?highlight=${t.library_file_id}`,className:"text-bambu-gray hover:text-bambu-green transition-colors flex-shrink-0",title:b("queue.viewInFileManager"),children:a.jsx(Xr,{className:"w-3.5 h-3.5"})}):null]}),a.jsxs("div",{className:"flex items-center gap-3 text-sm text-bambu-gray",children:[a.jsxs("span",{className:`flex items-center gap-1.5 ${t.printer_id===null&&!t.target_model?"text-orange-400":""} ${t.target_model?"text-blue-400":""}`,children:[a.jsx(Or,{className:"w-3.5 h-3.5"}),t.target_model?`${b("queue.filter.any")} ${t.target_model}${t.target_location?` @ ${t.target_location}`:""}${t.required_filament_types?.length?` (${t.required_filament_types.join(", ")})`:""}`:t.printer_id===null?b("queue.filter.unassigned"):t.printer_name||`${b("common.printer")} #${t.printer_id}`]}),t.print_time_seconds&&a.jsxs("span",{className:"flex items-center gap-1.5",children:[a.jsx(Su,{className:"w-3.5 h-3.5"}),lae(t.print_time_seconds)]}),t.created_by_username&&a.jsxs("span",{className:"flex items-center gap-1.5",title:b("queue.addedBy",{name:t.created_by_username}),children:[a.jsx(Hu,{className:"w-3.5 h-3.5"}),t.created_by_username]}),P&&!t.manual_start&&a.jsxs("span",{className:"flex items-center gap-1.5",children:[a.jsx(nr,{className:"w-3.5 h-3.5"}),MYe(t.scheduled_time,c,b)]})]}),a.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[t.manual_start&&a.jsxs("span",{className:"text-xs px-2 py-0.5 bg-purple-500/10 text-purple-400 rounded-full border border-purple-500/20 flex items-center gap-1",children:[a.jsx(LK,{className:"w-3 h-3"}),b("queue.badges.staged")]}),t.require_previous_success&&a.jsx("span",{className:"text-xs px-2 py-0.5 bg-orange-500/10 text-orange-400 rounded-full border border-orange-500/20",children:b("queue.badges.requiresPrevious")}),t.auto_off_after&&a.jsxs("span",{className:"text-xs px-2 py-0.5 bg-blue-500/10 text-blue-400 rounded-full border border-blue-500/20 flex items-center gap-1",children:[a.jsx(Zu,{className:"w-3 h-3"}),b("queue.badges.autoPowerOff")]})]}),E&&a.jsxs("div",{className:"mt-3",children:[a.jsx("div",{className:"h-2 bg-bambu-dark rounded-full overflow-hidden",children:a.jsx("div",{className:"h-full bg-gradient-to-r from-blue-500 to-blue-400 animate-pulse w-full opacity-50"})}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:b("queue.printingInProgress")})]}),t.waiting_reason&&t.status==="pending"&&a.jsxs("p",{className:"text-xs text-purple-400 mt-2 flex items-start gap-1",children:[a.jsx(Wi,{className:"w-3 h-3 mt-0.5 flex-shrink-0"}),a.jsx("span",{children:t.waiting_reason})]}),t.error_message&&a.jsxs("p",{className:"text-xs text-red-400 mt-2 flex items-center gap-1",children:[a.jsx(Wi,{className:"w-3 h-3"}),t.error_message]})]}),a.jsx(kYe,{status:t.status,waitingReason:t.waiting_reason,printerState:p,t:b}),a.jsxs("div",{className:"flex items-center gap-1",children:[E&&a.jsx(ke,{variant:"ghost",size:"sm",onClick:s,disabled:!h("printers:control"),title:h("printers:control")?b("queue.actions.stopPrint"):b("queue.permissions.noStopPrint"),className:"text-red-400 hover:text-red-300 hover:bg-red-500/10",children:a.jsx(_de,{className:"w-4 h-4"})}),P&&a.jsxs(a.Fragment,{children:[t.manual_start&&a.jsx(ke,{variant:"ghost",size:"sm",onClick:l,disabled:!h("printers:control"),title:h("printers:control")?b("queue.actions.startPrint"):b("queue.permissions.noStartPrint"),className:"text-bambu-green hover:text-bambu-green-light hover:bg-bambu-green/10",children:a.jsx(vo,{className:"w-4 h-4"})}),a.jsx(ke,{variant:"ghost",size:"sm",onClick:n,disabled:!m("queue","update",t.created_by_id),title:m("queue","update",t.created_by_id)?b("common.edit"):b("queue.permissions.noEdit"),children:a.jsx(na,{className:"w-4 h-4"})}),a.jsx(ke,{variant:"ghost",size:"sm",onClick:r,disabled:!m("queue","delete",t.created_by_id),title:m("queue","delete",t.created_by_id)?b("common.cancel"):b("queue.permissions.noCancel"),className:"text-red-400 hover:text-red-300 hover:bg-red-500/10",children:a.jsx(Lt,{className:"w-4 h-4"})})]}),T&&a.jsxs(a.Fragment,{children:[a.jsx(ke,{variant:"ghost",size:"sm",onClick:o,disabled:!h("queue:create"),title:h("queue:create")?b("queue.actions.requeue"):b("queue.permissions.noRequeue"),className:"text-bambu-green hover:text-bambu-green/80 hover:bg-bambu-green/10",children:a.jsx(Ir,{className:"w-4 h-4"})}),a.jsx(ke,{variant:"ghost",size:"sm",onClick:i,disabled:!m("queue","delete",t.created_by_id),title:m("queue","delete",t.created_by_id)?b("common.remove"):b("queue.permissions.noRemove"),children:a.jsx(cn,{className:"w-4 h-4"})})]})]})]})})}function AYe(){const{t}=Sn(),e=un(),{showToast:n}=Hn(),{hasPermission:r,hasAnyPermission:i,canModify:s}=Di(),[o,l]=_.useState(null),[c,u]=_.useState(""),[d,h]=_.useState(""),[m,p]=_.useState(!1),[b,v]=_.useState(null),[x,y]=_.useState(null),[S,N]=_.useState(null),[A,k]=_.useState([]),[C,E]=_.useState(!1),[P,T]=_.useState(()=>localStorage.getItem("queue.historySortBy")||"date"),[j,z]=_.useState(()=>{const ee=localStorage.getItem("queue.historySortAsc");return ee!==null?ee==="true":!1}),[L,B]=_.useState(()=>localStorage.getItem("queue.pendingSortBy")||"position"),[R,$]=_.useState(()=>{const ee=localStorage.getItem("queue.pendingSortAsc");return ee!==null?ee==="true":!0});_.useEffect(()=>{localStorage.setItem("queue.historySortBy",P)},[P]),_.useEffect(()=>{localStorage.setItem("queue.historySortAsc",String(j))},[j]),_.useEffect(()=>{localStorage.setItem("queue.pendingSortBy",L)},[L]),_.useEffect(()=>{localStorage.setItem("queue.pendingSortAsc",String(R))},[R]);const q=Fie(NM(pk,{activationConstraint:{distance:8}}),NM(mk,{coordinateGetter:sae})),{data:I}=st({queryKey:["settings"],queryFn:ce.getSettings}),G=I?.time_format||"system",{data:Y,isLoading:re}=st({queryKey:["queue",o,c],queryFn:()=>ce.getQueue(o||void 0,c||void 0),refetchInterval:5e3}),{data:H}=st({queryKey:["printers"],queryFn:()=>ce.getPrinters()}),K=pt({mutationFn:ee=>ce.cancelQueueItem(ee),onSuccess:()=>{e.invalidateQueries({queryKey:["queue"]}),n(t("queue.toast.cancelled"))},onError:()=>n(t("queue.toast.cancelFailed"),"error")}),ne=pt({mutationFn:ee=>ce.removeFromQueue(ee),onSuccess:()=>{e.invalidateQueries({queryKey:["queue"]}),n(t("queue.toast.removed"))},onError:()=>n(t("queue.toast.removeFailed"),"error")}),ie=pt({mutationFn:ee=>ce.stopQueueItem(ee),onSuccess:()=>{e.invalidateQueries({queryKey:["queue"]}),n(t("queue.toast.stopped"))},onError:()=>n(t("queue.toast.stopFailed"),"error")}),be=pt({mutationFn:ee=>ce.startQueueItem(ee),onSuccess:()=>{e.invalidateQueries({queryKey:["queue"]}),n(t("queue.toast.released"))},onError:()=>n(t("queue.toast.startFailed"),"error")}),pe=pt({mutationFn:ee=>ce.reorderQueue(ee),onSuccess:()=>{e.invalidateQueries({queryKey:["queue"]})},onError:()=>n(t("queue.toast.reorderFailed"),"error")}),de=pt({mutationFn:async()=>{const ee=Y?.filter(U=>["completed","failed","skipped","cancelled"].includes(U.status))||[];for(const U of ee)await ce.removeFromQueue(U.id);return ee.length},onSuccess:ee=>{e.invalidateQueries({queryKey:["queue"]}),n(t("queue.toast.historyCleared",{count:ee}))},onError:()=>n(t("queue.toast.clearHistoryFailed"),"error")}),Ce=pt({mutationFn:ee=>ce.bulkUpdateQueue(ee),onSuccess:ee=>{e.invalidateQueries({queryKey:["queue"]}),k([]),E(!1),n(ee.message)},onError:()=>n(t("queue.toast.updateFailed"),"error")}),ae=pt({mutationFn:async ee=>{for(const U of ee)await ce.cancelQueueItem(U);return ee.length},onSuccess:ee=>{e.invalidateQueries({queryKey:["queue"]}),k([]),n(t("queue.toast.bulkCancelled",{count:ee}))},onError:()=>n(t("queue.toast.bulkCancelFailed"),"error")}),Ae=ee=>{k(U=>U.includes(ee)?U.filter(O=>O!==ee):[...U,ee])},Le=_.useMemo(()=>{const ee=new Set;return H?.forEach(U=>{U.location&&ee.add(U.location)}),Y?.forEach(U=>{U.target_location&&ee.add(U.target_location)}),Array.from(ee).sort()},[H,Y]),fe=_.useCallback(ee=>d?ee.target_location?ee.target_location===d:ee.printer_id?H?.find(O=>O.id===ee.printer_id)?.location===d:!1:!0,[d,H]),Xe=_.useMemo(()=>{let ee=Y?.filter(O=>O.status==="pending")||[];d&&(ee=ee.filter(fe));const U=O=>{if(!O.scheduled_time)return 0;const Z=new Date(O.scheduled_time).getTime(),le=Date.now()+4320*60*60*1e3;return Z>le?0:Z};return[...ee].sort((O,Z)=>{let le;if(L==="name"){const we=O.archive_name||O.library_file_name||"",ye=Z.archive_name||Z.library_file_name||"";le=we.localeCompare(ye)}else L==="printer"?le=(O.printer_name||"").localeCompare(Z.printer_name||""):L==="time"?le=U(O)-U(Z):le=O.position-Z.position;return R?le:-le})},[Y,L,R,fe,d]),W=()=>{const ee=Xe.map(U=>U.id);A.length===ee.length?k([]):k(ee)},Q=_.useMemo(()=>{let ee=Y?.filter(U=>U.status==="printing")||[];return d&&(ee=ee.filter(fe)),ee},[Y,d,fe]),me=_.useMemo(()=>{const ee=new Set;return Q.forEach(U=>{U.printer_id&&ee.add(U.printer_id)}),Array.from(ee)},[Q]),X=iO({queries:me.map(ee=>({queryKey:["printerStatus",ee],queryFn:()=>ce.getPrinterStatus(ee),refetchInterval:5e3}))}),te=_.useMemo(()=>{const ee={};return me.forEach((U,O)=>{const Z=X[O];Z?.data?.state&&(ee[U]=Z.data.state)}),ee},[me,X]),V=_.useMemo(()=>{let ee=Y?.filter(U=>["completed","failed","skipped","cancelled"].includes(U.status))||[];return d&&(ee=ee.filter(fe)),[...ee].sort((U,O)=>{let Z;if(P==="name"){const le=U.archive_name||U.library_file_name||"",we=O.archive_name||O.library_file_name||"";Z=le.localeCompare(we)}else P==="printer"?Z=(U.printer_name||"").localeCompare(O.printer_name||""):Z=new Date(O.completed_at||O.created_at).getTime()-new Date(U.completed_at||U.created_at).getTime();return j?-Z:Z})},[Y,P,j,fe,d]),ge=_.useMemo(()=>Xe.reduce((ee,U)=>ee+(U.print_time_seconds||0),0),[Xe]),Se=ee=>{const{active:U,over:O}=ee;if(!O||U.id===O.id)return;const Z=Xe.findIndex(we=>we.id===U.id),le=Xe.findIndex(we=>we.id===O.id);if(Z!==-1&&le!==-1){const ye=xk(Xe,Z,le).map((se,Oe)=>({id:se.id,position:Oe+1}));pe.mutate(ye)}};return a.jsxs("div",{className:"p-4 md:p-8",children:[a.jsx("div",{className:"flex items-center justify-between mb-8",children:a.jsxs("div",{children:[a.jsxs("h1",{className:"text-2xl font-bold text-white flex items-center gap-3",children:[a.jsx(FK,{className:"w-7 h-7 text-bambu-green"}),t("queue.title")]}),a.jsx("p",{className:"text-bambu-gray mt-1",children:t("queue.subtitle")})]})}),a.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-4 gap-4 mb-8",children:[a.jsx(_t,{className:"bg-gradient-to-br from-blue-500/10 to-transparent border-blue-500/20",children:a.jsx(Mt,{className:"p-4",children:a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx("div",{className:"w-10 h-10 rounded-lg bg-blue-500/20 flex items-center justify-center",children:a.jsx(vo,{className:"w-5 h-5 text-blue-400"})}),a.jsxs("div",{children:[a.jsx("p",{className:"text-2xl font-bold text-white",children:Q.length}),a.jsx("p",{className:"text-sm text-bambu-gray",children:t("queue.summary.printing")})]})]})})}),a.jsx(_t,{className:"bg-gradient-to-br from-yellow-500/10 to-transparent border-yellow-500/20",children:a.jsx(Mt,{className:"p-4",children:a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx("div",{className:"w-10 h-10 rounded-lg bg-yellow-500/20 flex items-center justify-center",children:a.jsx(nr,{className:"w-5 h-5 text-yellow-400"})}),a.jsxs("div",{children:[a.jsx("p",{className:"text-2xl font-bold text-white",children:Xe.length}),a.jsx("p",{className:"text-sm text-bambu-gray",children:t("queue.summary.queued")})]})]})})}),a.jsx(_t,{className:"bg-gradient-to-br from-bambu-green/10 to-transparent border-bambu-green/20",children:a.jsx(Mt,{className:"p-4",children:a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx("div",{className:"w-10 h-10 rounded-lg bg-bambu-green/20 flex items-center justify-center",children:a.jsx(Su,{className:"w-5 h-5 text-bambu-green"})}),a.jsxs("div",{children:[a.jsx("p",{className:"text-2xl font-bold text-white",children:lae(ge)}),a.jsx("p",{className:"text-sm text-bambu-gray",children:t("queue.summary.totalTime")})]})]})})}),a.jsx(_t,{className:"bg-gradient-to-br from-gray-500/10 to-transparent border-gray-500/20",children:a.jsx(Mt,{className:"p-4",children:a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx("div",{className:"w-10 h-10 rounded-lg bg-gray-500/20 flex items-center justify-center",children:a.jsx(Nr,{className:"w-5 h-5 text-gray-400"})}),a.jsxs("div",{children:[a.jsx("p",{className:"text-2xl font-bold text-white",children:V.length}),a.jsx("p",{className:"text-sm text-bambu-gray",children:t("queue.summary.history")})]})]})})})]}),a.jsxs("div",{className:"flex items-center gap-4 mb-6",children:[a.jsxs("select",{className:"px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:o===-1?"unassigned":o||"",onChange:ee=>{const U=ee.target.value;l(U==="unassigned"?-1:U===""?null:Number(U))},children:[a.jsx("option",{value:"",children:t("queue.filter.allPrinters")}),a.jsx("option",{value:"unassigned",children:t("queue.filter.unassigned")}),H?.map(ee=>a.jsx("option",{value:ee.id,children:ee.name},ee.id))]}),a.jsxs("select",{className:"px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:c,onChange:ee=>u(ee.target.value),children:[a.jsx("option",{value:"",children:t("queue.filter.allStatus")}),a.jsx("option",{value:"pending",children:t("queue.status.pending")}),a.jsx("option",{value:"printing",children:t("queue.status.printing")}),a.jsx("option",{value:"completed",children:t("queue.status.completed")}),a.jsx("option",{value:"failed",children:t("queue.status.failed")}),a.jsx("option",{value:"skipped",children:t("queue.status.skipped")}),a.jsx("option",{value:"cancelled",children:t("queue.status.cancelled")})]}),Le.length>0&&a.jsxs("select",{className:"px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:d,onChange:ee=>h(ee.target.value),children:[a.jsx("option",{value:"",children:t("queue.filter.allLocations")}),Le.map(ee=>a.jsx("option",{value:ee,children:ee},ee))]}),a.jsx("div",{className:"flex-1"}),V.length>0&&a.jsxs(ke,{variant:"secondary",size:"sm",onClick:()=>p(!0),disabled:!r("queue:delete_all"),title:r("queue:delete_all")?void 0:t("queue.permissions.noClearHistory"),children:[a.jsx(cn,{className:"w-4 h-4"}),t("queue.clearHistory")]})]}),re?a.jsx("div",{className:"text-center py-12 text-bambu-gray",children:t("common.loading")}):Y?.length===0?a.jsxs(_t,{className:"p-12 text-center border-dashed",children:[a.jsx(ei,{className:"w-16 h-16 text-bambu-gray mx-auto mb-4 opacity-50"}),a.jsx("h3",{className:"text-xl font-medium text-white mb-2",children:t("queue.empty.title")}),a.jsx("p",{className:"text-bambu-gray max-w-md mx-auto",children:t("queue.empty.description")})]}):a.jsxs("div",{className:"space-y-8",children:[Q.length>0&&a.jsxs("div",{children:[a.jsxs("h2",{className:"text-lg font-semibold text-white mb-4 flex items-center gap-2",children:[a.jsx("div",{className:"w-2 h-2 rounded-full bg-blue-400 animate-pulse"}),t("queue.sections.currentlyPrinting")]}),a.jsx("div",{className:"space-y-3",children:Q.map(ee=>a.jsx(gP,{item:ee,onEdit:()=>{},onCancel:()=>{},onRemove:()=>{},onStop:()=>N({type:"stop",item:ee}),onRequeue:()=>{},onStart:()=>{},timeFormat:G,hasPermission:r,canModify:s,printerState:ee.printer_id?te[ee.printer_id]:null,t},ee.id))})]}),Xe.length>0&&a.jsxs("div",{children:[a.jsxs("div",{className:"flex items-center justify-between mb-4",children:[a.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[a.jsx(nr,{className:"w-5 h-5 text-yellow-400"}),t("queue.sections.queued"),a.jsxs("span",{className:"text-sm font-normal text-bambu-gray",children:["(",t("queue.itemCount",{count:Xe.length}),")"]}),a.jsx("span",{className:"text-xs text-bambu-gray ml-2",title:t("queue.reorderHint"),children:t("queue.dragToReorder")})]}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsxs("select",{className:"px-3 py-1.5 text-sm bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:L,onChange:ee=>B(ee.target.value),children:[a.jsx("option",{value:"position",children:t("queue.sort.byPosition")}),a.jsx("option",{value:"name",children:t("queue.sort.byName")}),a.jsx("option",{value:"printer",children:t("queue.sort.byPrinter")}),a.jsx("option",{value:"time",children:t("queue.sort.bySchedule")})]}),a.jsx(ke,{variant:"ghost",size:"sm",onClick:()=>$(!R),title:t(R?"common.ascending":"common.descending"),className:"px-2",children:R?a.jsx(Zg,{className:"w-4 h-4"}):a.jsx(ay,{className:"w-4 h-4"})})]})]}),a.jsxs("div",{className:"flex items-center gap-3 mb-4 p-3 bg-bambu-dark rounded-lg",children:[a.jsxs(ke,{variant:"ghost",size:"sm",onClick:W,className:"flex items-center gap-2",children:[A.length===Xe.length&&Xe.length>0?a.jsx(qs,{className:"w-4 h-4 text-bambu-green"}):a.jsx(ll,{className:"w-4 h-4"}),A.length===Xe.length&&Xe.length>0?t("queue.bulkEdit.deselectAll"):t("queue.bulkEdit.selectAll")]}),A.length>0&&a.jsxs(a.Fragment,{children:[a.jsx("span",{className:"text-sm text-bambu-gray",children:t("queue.bulkEdit.selected",{count:A.length})}),a.jsx("div",{className:"h-4 w-px bg-bambu-dark-tertiary"}),a.jsxs(ke,{variant:"ghost",size:"sm",onClick:()=>E(!0),className:"flex items-center gap-2 text-bambu-green hover:text-bambu-green-light",disabled:!i("queue:update_own","queue:update_all"),title:i("queue:update_own","queue:update_all")?void 0:t("queue.permissions.noEditItems"),children:[a.jsx(na,{className:"w-4 h-4"}),t("queue.bulkEdit.editSelected")]}),a.jsxs(ke,{variant:"ghost",size:"sm",onClick:()=>ae.mutate(A),className:"flex items-center gap-2 text-red-400 hover:text-red-300",disabled:ae.isPending||!i("queue:delete_own","queue:delete_all"),title:i("queue:delete_own","queue:delete_all")?void 0:t("queue.permissions.noCancelItems"),children:[a.jsx(Lt,{className:"w-4 h-4"}),t("queue.bulkEdit.cancelSelected")]})]})]}),a.jsx(eae,{sensors:q,collisionDetection:Bie,onDragEnd:Se,children:a.jsx(rae,{items:Xe.map(ee=>ee.id),strategy:mYe,children:a.jsx("div",{className:"space-y-3",children:Xe.map((ee,U)=>a.jsx(gP,{item:ee,position:U+1,onEdit:()=>v(ee),onCancel:()=>N({type:"cancel",item:ee}),onRemove:()=>{},onStop:()=>{},onRequeue:()=>{},onStart:()=>be.mutate(ee.id),timeFormat:G,isSelected:A.includes(ee.id),onToggleSelect:()=>Ae(ee.id),hasPermission:r,canModify:s,t},ee.id))})})})]}),V.length>0&&a.jsxs("div",{children:[a.jsxs("div",{className:"flex items-center justify-between mb-4",children:[a.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[a.jsx(Nr,{className:"w-5 h-5 text-bambu-gray"}),t("queue.sections.history"),a.jsxs("span",{className:"text-sm font-normal text-bambu-gray",children:["(",t("queue.itemCount",{count:V.length}),")"]})]}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsxs("select",{className:"px-3 py-1.5 text-sm bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",value:P,onChange:ee=>T(ee.target.value),children:[a.jsx("option",{value:"date",children:t("queue.sort.byDate")}),a.jsx("option",{value:"name",children:t("queue.sort.byName")}),a.jsx("option",{value:"printer",children:t("queue.sort.byPrinter")})]}),a.jsx(ke,{variant:"ghost",size:"sm",onClick:()=>z(!j),title:t(j?"queue.sort.ascendingOldest":"queue.sort.descendingNewest"),className:"px-2",children:j?a.jsx(Zg,{className:"w-4 h-4"}):a.jsx(ay,{className:"w-4 h-4"})})]})]}),a.jsx("div",{className:"space-y-3",children:V.slice(0,20).map((ee,U)=>a.jsx(gP,{item:ee,position:U+1,onEdit:()=>{},onCancel:()=>{},onRemove:()=>N({type:"remove",item:ee}),onStop:()=>{},onRequeue:()=>y(ee),onStart:()=>{},timeFormat:G,hasPermission:r,canModify:s,t},ee.id))})]})]}),b&&a.jsx(Fu,{mode:"edit-queue-item",archiveId:b.archive_id??void 0,libraryFileId:b.library_file_id??void 0,archiveName:b.archive_name||b.library_file_name||`File #${b.archive_id||b.library_file_id}`,queueItem:b,onClose:()=>v(null)}),x&&a.jsx(Fu,{mode:"add-to-queue",archiveId:x.archive_id??void 0,libraryFileId:x.library_file_id??void 0,archiveName:x.archive_name||x.library_file_name||`File #${x.archive_id||x.library_file_id}`,onClose:()=>y(null)}),S&&a.jsx(er,{title:S.type==="cancel"?t("queue.confirm.cancelTitle"):S.type==="stop"?t("queue.confirm.stopTitle"):t("queue.confirm.removeTitle"),message:S.type==="cancel"?t("queue.confirm.cancelMessage",{name:S.item.archive_name||S.item.library_file_name||t("queue.confirm.thisPrint")}):S.type==="stop"?t("queue.confirm.stopMessage",{name:S.item.archive_name||S.item.library_file_name||t("queue.confirm.thisPrint")}):t("queue.confirm.removeMessage",{name:S.item.archive_name||S.item.library_file_name||t("queue.confirm.thisItem")}),confirmText:S.type==="cancel"?t("queue.confirm.cancelButton"):S.type==="stop"?t("queue.confirm.stopButton"):t("common.remove"),variant:"danger",onConfirm:()=>{S.type==="cancel"?K.mutate(S.item.id):S.type==="stop"?ie.mutate(S.item.id):ne.mutate(S.item.id),N(null)},onCancel:()=>N(null)}),m&&a.jsx(er,{title:t("queue.confirm.clearHistoryTitle"),message:t("queue.confirm.clearHistoryMessage",{count:V.length}),confirmText:t("queue.clearHistory"),variant:"danger",onConfirm:()=>{de.mutate(),p(!1)},onCancel:()=>p(!1)}),C&&a.jsx(EYe,{selectedCount:A.length,printers:H?.map(ee=>({id:ee.id,name:ee.name}))||[],onSave:ee=>{Object.keys(ee).length>0&&Ce.mutate({item_ids:A,...ee})},onClose:()=>E(!1),isSaving:Ce.isPending,t})]})}function TYe({printDates:t,months:e=3}){const n=_.useRef(null),[r,i]=_.useState(0);_.useEffect(()=>{const S=n.current;if(!S)return;const N=new ResizeObserver(A=>{const k=A[0]?.contentRect.width||0;i(k)});return N.observe(S),()=>N.disconnect()},[]);const{weeks:s,monthLabels:o,printCounts:l}=_.useMemo(()=>{const S={};t.forEach(z=>{const L=z.split("T")[0];S[L]=(S[L]||0)+1});const N=new Date,A=new Date(N);A.setMonth(A.getMonth()-e),A.setDate(A.getDate()-A.getDay());const k=[],C=[];let E=[],P=-1;const T=new Date(A);let j=0;for(;T<=N;)T.getDay()===0&&E.length>0&&(k.push(E),E=[],j++),T.getMonth()!==P&&(C.push({month:T.toLocaleDateString("en-US",{month:"short"}),weekIndex:j}),P=T.getMonth()),E.push(new Date(T)),T.setDate(T.getDate()+1);return E.length>0&&k.push(E),{weeks:k,monthLabels:C,printCounts:S}},[t,e]),c=Math.max(1,...Object.values(l)),u=S=>{if(S===0)return"bg-bambu-dark";const N=S/c;return N<=.25?"bg-bambu-green/30":N<=.5?"bg-bambu-green/50":N<=.75?"bg-bambu-green/75":"bg-bambu-green"},d=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],h=s.length,m=32,p=2,b=r-m-16,v=h>0?Math.floor((b-(h-1)*p)/h):12,x=Math.max(8,Math.min(20,v)),y=x<=10?10:12;return a.jsx("div",{ref:n,className:"w-full flex justify-center",children:r>0&&a.jsxs("div",{children:[a.jsx("div",{className:"flex mb-1",style:{marginLeft:m+4},children:o.map(({month:S,weekIndex:N},A)=>a.jsx("div",{className:"text-bambu-gray",style:{fontSize:y,marginLeft:A===0?0:`${(N-(o[A-1]?.weekIndex||0))*(x+p)-24}px`},children:S},A))}),a.jsxs("div",{className:"flex",style:{gap:p},children:[a.jsx("div",{className:"flex flex-col",style:{gap:p,marginRight:4,width:m},children:d.map((S,N)=>a.jsx("div",{className:"text-bambu-gray flex items-center",style:{width:m,height:x,fontSize:y,visibility:N%2===1?"visible":"hidden"},children:S},S))}),s.map((S,N)=>a.jsx("div",{className:"flex flex-col",style:{gap:p},children:[0,1,2,3,4,5,6].map(A=>{const k=S.find(T=>T.getDay()===A);if(!k)return a.jsx("div",{style:{width:x,height:x}},A);const C=k.toISOString().split("T")[0],E=l[C]||0,P=C===new Date().toISOString().split("T")[0];return a.jsx("div",{className:`rounded-sm ${u(E)} ${P?"ring-1 ring-white":""}`,style:{width:x,height:x},title:`${k.toLocaleDateString()}: ${E} print${E!==1?"s":""}`},A)})},N))]}),a.jsxs("div",{className:"flex items-center gap-2 mt-3 text-bambu-gray",style:{fontSize:y},children:[a.jsx("span",{children:"Less"}),a.jsxs("div",{className:"flex",style:{gap:p},children:[a.jsx("div",{className:"rounded-sm bg-bambu-dark",style:{width:x,height:x}}),a.jsx("div",{className:"rounded-sm bg-bambu-green/30",style:{width:x,height:x}}),a.jsx("div",{className:"rounded-sm bg-bambu-green/50",style:{width:x,height:x}}),a.jsx("div",{className:"rounded-sm bg-bambu-green/75",style:{width:x,height:x}}),a.jsx("div",{className:"rounded-sm bg-bambu-green",style:{width:x,height:x}})]}),a.jsx("span",{children:"More"})]})]})})}const E1=["#00ae42","#3b82f6","#f59e0b","#ef4444","#8b5cf6","#ec4899","#14b8a6","#f97316"];function CYe(t){const e=new Date;switch(t){case"7d":return new Date(e.getTime()-10080*60*1e3);case"30d":return new Date(e.getTime()-720*60*60*1e3);case"90d":return new Date(e.getTime()-2160*60*60*1e3);case"365d":return new Date(e.getTime()-365*24*60*60*1e3);case"all":return new Date(0)}}function jYe({archives:t,currency:e="$"}){const[n,r]=_.useState("30d"),i=_.useMemo(()=>{const p=CYe(n);return t.filter(b=>(Hi(b.completed_at||b.created_at)||new Date(0))>=p)},[t,n]),s=_.useMemo(()=>{const p=new Map;return i.forEach(b=>{const v=Hi(b.completed_at||b.created_at)||new Date,x=`${v.getFullYear()}-${String(v.getMonth()+1).padStart(2,"0")}-${String(v.getDate()).padStart(2,"0")}`,y=p.get(x)||{date:x,filament:0,cost:0,prints:0},S=b.quantity||1;y.filament+=(b.filament_used_grams||0)*S,y.cost+=b.cost||0,y.prints+=S,p.set(x,y)}),Array.from(p.values()).sort((b,v)=>b.date.localeCompare(v.date)).map(b=>({...b,dateLabel:new Date(b.date).toLocaleDateString("en-US",{month:"short",day:"numeric"})}))},[i]),o=_.useMemo(()=>{if(n==="7d"||n==="30d")return s;const p=new Map;return i.forEach(b=>{const v=Hi(b.completed_at||b.created_at)||new Date,x=new Date(v);x.setDate(v.getDate()-v.getDay());const y=`${x.getFullYear()}-${String(x.getMonth()+1).padStart(2,"0")}-${String(x.getDate()).padStart(2,"0")}`,S=p.get(y)||{week:y,filament:0,cost:0,prints:0},N=b.quantity||1;S.filament+=(b.filament_used_grams||0)*N,S.cost+=b.cost||0,S.prints+=N,p.set(y,S)}),Array.from(p.values()).sort((b,v)=>b.week.localeCompare(v.week)).map(b=>({date:b.week,dateLabel:`Week of ${new Date(b.week).toLocaleDateString("en-US",{month:"short",day:"numeric"})}`,...b}))},[i,s,n]),l=_.useMemo(()=>{const p=new Map;return i.forEach(b=>{const v=b.filament_type||"Unknown",x=b.quantity||1,y=v.split(", ");y.forEach(S=>{const N=(b.filament_used_grams||0)*x/y.length;p.set(S,(p.get(S)||0)+N)})}),Array.from(p.entries()).map(([b,v])=>({name:b,value:Math.round(v)})).sort((b,v)=>v.value-b.value)},[i]),c=_.useMemo(()=>{const p=new Date,b=[];for(let v=5;v>=0;v--){const x=new Date(p.getFullYear(),p.getMonth()-v,1),y=new Date(p.getFullYear(),p.getMonth()-v+1,0),S=x.toLocaleDateString("en-US",{month:"short",year:"2-digit"}),N=t.filter(A=>{const k=Hi(A.completed_at||A.created_at)||new Date(0);return k>=x&&k<=y});b.push({month:S,filament:Math.round(N.reduce((A,k)=>A+(k.filament_used_grams||0),0)),cost:N.reduce((A,k)=>A+(k.cost||0),0),prints:N.reduce((A,k)=>A+(k.quantity||1),0)})}return b},[t]),u=n==="7d"||n==="30d"?s:o,d=i.reduce((p,b)=>p+(b.filament_used_grams||0),0),h=i.reduce((p,b)=>p+(b.cost||0),0),m=i.reduce((p,b)=>p+(b.quantity||1),0);return a.jsxs("div",{className:"space-y-6",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("h3",{className:"text-lg font-semibold text-white",children:"Filament Usage Trends"}),a.jsx("div",{className:"flex gap-1 bg-bambu-dark rounded-lg p-1",children:["7d","30d","90d","365d","all"].map(p=>a.jsx("button",{onClick:()=>r(p),className:`px-3 py-1 text-sm rounded-md transition-colors ${n===p?"bg-bambu-green text-white":"text-bambu-gray hover:text-white"}`,children:p==="all"?"All":p.replace("d","D")},p))})]}),a.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[a.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[a.jsx("p",{className:"text-sm text-bambu-gray",children:"Period Filament"}),a.jsxs("p",{className:"text-2xl font-bold text-white",children:[(d/1e3).toFixed(2),"kg"]}),a.jsxs("p",{className:"text-xs text-bambu-gray",children:[d.toFixed(0),"g total"]})]}),a.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[a.jsx("p",{className:"text-sm text-bambu-gray",children:"Period Cost"}),a.jsxs("p",{className:"text-2xl font-bold text-white",children:[e,h.toFixed(2)]}),a.jsxs("p",{className:"text-xs text-bambu-gray",children:[m," prints"]})]}),a.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[a.jsx("p",{className:"text-sm text-bambu-gray",children:"Avg per Print"}),a.jsxs("p",{className:"text-2xl font-bold text-white",children:[m>0?(d/m).toFixed(0):0,"g"]}),a.jsxs("p",{className:"text-xs text-bambu-gray",children:[e,m>0?(h/m).toFixed(2):"0.00"," avg"]})]})]}),u.length>0?a.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[a.jsx("h4",{className:"text-sm font-medium text-bambu-gray mb-4",children:"Usage Over Time"}),a.jsx(W1,{width:"100%",height:250,children:a.jsxs(A6e,{data:u,children:[a.jsx("defs",{children:a.jsxs("linearGradient",{id:"colorFilament",x1:"0",y1:"0",x2:"0",y2:"1",children:[a.jsx("stop",{offset:"5%",stopColor:"#00ae42",stopOpacity:.3}),a.jsx("stop",{offset:"95%",stopColor:"#00ae42",stopOpacity:0})]})}),a.jsx(_N,{strokeDasharray:"3 3",stroke:"#3d3d3d"}),a.jsx(kN,{dataKey:"dateLabel",stroke:"#9ca3af",tick:{fontSize:12},interval:"preserveStartEnd"}),a.jsx(EN,{stroke:"#9ca3af",tick:{fontSize:12},tickFormatter:p=>`${p}g`}),a.jsx(X1,{contentStyle:{backgroundColor:"#2d2d2d",border:"1px solid #3d3d3d",borderRadius:"8px"},labelStyle:{color:"#fff"},formatter:p=>[`${Number(p??0).toFixed(0)}g`,"Filament"]}),a.jsx(fte,{type:"monotone",dataKey:"filament",stroke:"#00ae42",strokeWidth:2,fillOpacity:1,fill:"url(#colorFilament)"})]})})]}):a.jsx("div",{className:"bg-bambu-dark rounded-lg p-8 text-center text-bambu-gray",children:"No data for selected time range"}),a.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[a.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[a.jsx("h4",{className:"text-sm font-medium text-bambu-gray mb-4",children:"By Filament Type"}),l.length>0?a.jsxs("div",{className:"flex items-center gap-4",children:[a.jsx(W1,{width:160,height:160,children:a.jsxs(k6e,{children:[a.jsx(Uee,{data:l,cx:"50%",cy:"50%",innerRadius:40,outerRadius:70,paddingAngle:2,dataKey:"value",children:l.map((p,b)=>a.jsx(kv,{fill:E1[b%E1.length]},`cell-${b}`))}),a.jsx(X1,{contentStyle:{backgroundColor:"#2d2d2d",border:"1px solid #3d3d3d",borderRadius:"8px"},formatter:p=>[`${p??0}g`,"Usage"]})]})}),a.jsx("div",{className:"flex-1 space-y-2 overflow-hidden",children:l.map((p,b)=>{const v=l.reduce((y,S)=>y+S.value,0),x=v>0?(p.value/v*100).toFixed(0):0;return a.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[a.jsx("div",{className:"w-3 h-3 rounded-sm flex-shrink-0",style:{backgroundColor:E1[b%E1.length]}}),a.jsx("span",{className:"text-white truncate flex-1",children:p.name}),a.jsxs("span",{className:"text-bambu-gray flex-shrink-0",children:[x,"%"]})]},p.name)})})]}):a.jsx("div",{className:"h-[160px] flex items-center justify-center text-bambu-gray",children:"No filament data"})]}),a.jsxs("div",{className:"bg-bambu-dark rounded-lg p-4",children:[a.jsx("h4",{className:"text-sm font-medium text-bambu-gray mb-4",children:"Monthly Comparison"}),a.jsx(W1,{width:"100%",height:200,children:a.jsxs(m6e,{data:c,children:[a.jsx(_N,{strokeDasharray:"3 3",stroke:"#3d3d3d"}),a.jsx(kN,{dataKey:"month",stroke:"#9ca3af",tick:{fontSize:12}}),a.jsx(EN,{stroke:"#9ca3af",tick:{fontSize:12},tickFormatter:p=>`${p}g`}),a.jsx(X1,{contentStyle:{backgroundColor:"#2d2d2d",border:"1px solid #3d3d3d",borderRadius:"8px"},formatter:(p,b)=>[b==="filament"?`${p??0}g`:b==="cost"?`${e}${Number(p??0).toFixed(2)}`:p??0,b==="filament"?"Filament":b==="cost"?"Cost":"Prints"]}),a.jsx(b4,{}),a.jsx(xte,{dataKey:"filament",name:"Filament (g)",fill:"#00ae42",radius:[4,4,0,0]})]})})]})]})]})}function PYe({id:t,title:e,component:n,isHidden:r,size:i,onToggleVisibility:s,onToggleSize:o}){const{attributes:l,listeners:c,setNodeRef:u,transform:d,transition:h,isDragging:m}=aae({id:t}),p={transform:Eb.Transform.toString(d),transition:h,opacity:m?.5:1};return r?null:a.jsxs("div",{ref:u,style:{...p,gridColumn:`span ${i}`},className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary overflow-hidden ${m?"ring-2 ring-bambu-green shadow-lg":""}`,children:[a.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-bambu-dark-tertiary bg-bambu-dark/30",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("button",{...l,...c,className:"cursor-grab active:cursor-grabbing p-1 hover:bg-bambu-dark-tertiary rounded transition-colors",title:"Drag to reorder",children:a.jsx(eb,{className:"w-6 h-6 md:w-4 md:h-4 text-bambu-gray"})}),a.jsx("h3",{className:"text-sm font-medium text-white",children:e})]}),a.jsxs("div",{className:"flex items-center gap-1",children:[a.jsx("button",{onClick:o,className:"p-1 hover:bg-bambu-dark-tertiary rounded transition-colors",title:`Size: ${i===1?"1/4":i===2?"1/2":"Full"} - Click to cycle`,children:i===4?a.jsx(lO,{className:"w-4 h-4 text-bambu-gray hover:text-white"}):a.jsx(oO,{className:"w-4 h-4 text-bambu-gray hover:text-white"})}),a.jsx("button",{onClick:s,className:"p-1 hover:bg-bambu-dark-tertiary rounded transition-colors",title:"Hide widget",children:a.jsx(RM,{className:"w-4 h-4 text-bambu-gray hover:text-white"})})]})]}),a.jsx("div",{className:"p-4",children:typeof n=="function"?n(i):n})]})}function DYe({widgets:t,storageKey:e,columns:n=4,hideControls:r=!1,onResetLayout:i,renderControls:s}){const o=()=>{const A={};return t.forEach(k=>{A[k.id]=k.defaultSize||4}),A},[l,c]=_.useState(()=>{const A=localStorage.getItem(e);if(A)try{const k=JSON.parse(A);return k.sizes||(k.sizes=o()),k}catch{}return{order:t.map(k=>k.id),hidden:t.filter(k=>k.defaultVisible===!1).map(k=>k.id),sizes:o()}}),[u,d]=_.useState(!1);_.useEffect(()=>{const A=()=>d(k=>!k);return window.addEventListener("toggle-hidden-panel",A),()=>window.removeEventListener("toggle-hidden-panel",A)},[]),_.useEffect(()=>{localStorage.setItem(e,JSON.stringify(l))},[l,e]),_.useEffect(()=>{const k=t.map(C=>C.id).filter(C=>!l.order.includes(C));k.length>0&&c(C=>({...C,order:[...C.order,...k]}))},[t,l.order]);const h=Fie(NM(pk,{activationConstraint:{distance:8}}),NM(mk,{coordinateGetter:sae})),m=A=>{const{active:k,over:C}=A;C&&k.id!==C.id&&c(E=>{const P=E.order.indexOf(k.id),T=E.order.indexOf(C.id);return{...E,order:xk(E.order,P,T)}})},p=A=>{c(k=>({...k,hidden:k.hidden.includes(A)?k.hidden.filter(C=>C!==A):[...k.hidden,A]}))},b=A=>{c(k=>{const C=k.sizes[A]||4,E=C===1?2:C===2?4:1;return{...k,sizes:{...k.sizes,[A]:E}}})},v=()=>{const A={order:t.map(k=>k.id),hidden:t.filter(k=>k.defaultVisible===!1).map(k=>k.id),sizes:o()};c(A),i?.()},x=l.order.map(A=>t.find(k=>k.id===A)).filter(Boolean),y=x.filter(A=>!l.hidden.includes(A.id)),S=x.filter(A=>l.hidden.includes(A.id)),N=s?.({hiddenCount:S.length,showHiddenPanel:u,setShowHiddenPanel:d,resetLayout:v});return a.jsxs("div",{className:"space-y-4",children:[N,!r&&!s&&a.jsxs("div",{className:"flex items-center justify-end gap-2",children:[a.jsxs(ke,{variant:"secondary",size:"sm",onClick:v,children:[a.jsx($h,{className:"w-4 h-4"}),"Reset Layout"]}),S.length>0&&a.jsxs(ke,{variant:"secondary",size:"sm",onClick:()=>d(!u),children:[a.jsx(_c,{className:"w-4 h-4"}),S.length," Hidden"]})]}),u&&S.length>0&&a.jsxs("div",{className:"p-4 bg-bambu-dark rounded-xl border border-bambu-dark-tertiary",children:[a.jsx("p",{className:"text-sm text-bambu-gray mb-3",children:"Hidden widgets (click to show):"}),a.jsx("div",{className:"flex flex-wrap gap-2",children:S.map(A=>a.jsxs("button",{onClick:()=>p(A.id),className:"px-3 py-1.5 bg-bambu-dark-tertiary hover:bg-bambu-green/20 rounded-lg text-sm text-white transition-colors flex items-center gap-2",children:[a.jsx(_c,{className:"w-3 h-3"}),A.title]},A.id))})]}),a.jsx(eae,{sensors:h,collisionDetection:Bie,onDragEnd:m,children:a.jsx(rae,{items:y.map(A=>A.id),strategy:BF,children:a.jsx("div",{className:"grid gap-6",style:{gridTemplateColumns:`repeat(${n}, minmax(0, 1fr))`},children:y.map(A=>a.jsx(PYe,{id:A.id,title:A.title,component:A.component,isHidden:l.hidden.includes(A.id),size:l.sizes[A.id]||2,onToggleVisibility:()=>p(A.id),onToggleSize:()=>b(A.id)},A.id))})})}),y.length===0&&a.jsxs("div",{className:"text-center py-12 text-bambu-gray",children:[a.jsx("p",{children:"All widgets are hidden."}),a.jsx(ke,{className:"mt-4",onClick:v,children:"Reset Layout"})]})]})}function RYe({stats:t,currency:e,t:n}){return a.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-4",children:[a.jsxs("div",{className:"flex items-start gap-3",children:[a.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-bambu-green",children:a.jsx(Sc,{className:"w-5 h-5"})}),a.jsxs("div",{children:[a.jsx("p",{className:"text-xs text-bambu-gray",children:n("stats.totalPrints")}),a.jsx("p",{className:"text-xl font-bold text-white",children:t?.total_prints||0})]})]}),a.jsxs("div",{className:"flex items-start gap-3",children:[a.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-blue-400",children:a.jsx(nr,{className:"w-5 h-5"})}),a.jsxs("div",{children:[a.jsx("p",{className:"text-xs text-bambu-gray",children:n("stats.printTime")}),a.jsxs("p",{className:"text-xl font-bold text-white",children:[t?.total_print_time_hours.toFixed(1)||0,"h"]})]})]}),a.jsxs("div",{className:"flex items-start gap-3",children:[a.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-orange-400",children:a.jsx(Sc,{className:"w-5 h-5"})}),a.jsxs("div",{children:[a.jsx("p",{className:"text-xs text-bambu-gray",children:n("stats.filamentUsed")}),a.jsxs("p",{className:"text-xl font-bold text-white",children:[((t?.total_filament_grams||0)/1e3).toFixed(2),"kg"]})]})]}),a.jsxs("div",{className:"flex items-start gap-3",children:[a.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-green-400",children:a.jsx(zP,{className:"w-5 h-5"})}),a.jsxs("div",{children:[a.jsx("p",{className:"text-xs text-bambu-gray",children:n("stats.filamentCost")}),a.jsxs("p",{className:"text-xl font-bold text-white",children:[e," ",t?.total_cost.toFixed(2)||"0.00"]})]})]}),a.jsxs("div",{className:"flex items-start gap-3",children:[a.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-yellow-400",children:a.jsx(Dh,{className:"w-5 h-5"})}),a.jsxs("div",{children:[a.jsx("p",{className:"text-xs text-bambu-gray",children:n("stats.energyUsed")}),a.jsxs("p",{className:"text-xl font-bold text-white",children:[t?.total_energy_kwh.toFixed(2)||"0.00"," kWh"]})]})]}),a.jsxs("div",{className:"flex items-start gap-3",children:[a.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark text-yellow-500",children:a.jsx(zP,{className:"w-5 h-5"})}),a.jsxs("div",{children:[a.jsx("p",{className:"text-xs text-bambu-gray",children:n("stats.energyCost")}),a.jsxs("p",{className:"text-xl font-bold text-white",children:[e," ",t?.total_energy_cost.toFixed(2)||"0.00"]})]})]})]})}function OYe({stats:t,printerMap:e,size:n=1,t:r}){const i=t?.total_prints?Math.round(t.successful_prints/t.total_prints*100):0,s=n===1?112:n===2?128:144,o=s/2-8,l=o*2*Math.PI;return a.jsxs("div",{className:"flex items-center gap-6",children:[a.jsxs("div",{className:"relative flex-shrink-0",style:{width:s,height:s},children:[a.jsxs("svg",{className:"w-full h-full -rotate-90",children:[a.jsx("circle",{cx:s/2,cy:s/2,r:o,fill:"none",stroke:"#3d3d3d",strokeWidth:"10"}),a.jsx("circle",{cx:s/2,cy:s/2,r:o,fill:"none",stroke:"#00ae42",strokeWidth:"10",strokeLinecap:"round",strokeDasharray:`${i/100*l} ${l}`})]}),a.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:a.jsxs("span",{className:`font-bold text-white ${n>=2?"text-2xl":"text-xl"}`,children:[i,"%"]})})]}),a.jsxs("div",{className:"flex-1 min-w-0",children:[a.jsxs("div",{className:"space-y-2",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(Nr,{className:"w-4 h-4 text-status-ok flex-shrink-0"}),a.jsx("span",{className:"text-sm text-bambu-gray",children:r("stats.successful")}),a.jsx("span",{className:"text-sm text-white font-medium",children:t?.successful_prints||0})]}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(ta,{className:"w-4 h-4 text-status-error flex-shrink-0"}),a.jsx("span",{className:"text-sm text-bambu-gray",children:r("stats.failed")}),a.jsx("span",{className:"text-sm text-white font-medium",children:t?.failed_prints||0})]})]}),n>=2&&t?.prints_by_printer&&Object.keys(t.prints_by_printer).length>0&&a.jsxs("div",{className:"mt-4 pt-4 border-t border-bambu-dark-tertiary",children:[a.jsx("p",{className:"text-xs text-bambu-gray font-medium mb-2",children:r("stats.printsByPrinter")}),a.jsx("div",{className:`grid gap-x-6 gap-y-1 ${n===4?"grid-cols-3":"grid-cols-2"}`,style:{width:"fit-content"},children:Object.entries(t.prints_by_printer).map(([c,u])=>a.jsxs("div",{className:"flex items-center gap-3 text-sm",children:[a.jsx("span",{className:"text-bambu-gray truncate max-w-[120px]",children:e.get(c)||`${r("common.printer")} ${c}`}),a.jsx("span",{className:"text-white font-medium",children:u})]},c))})]})]})]})}function LYe({stats:t,printerMap:e,size:n=1,t:r}){const i=t?.average_time_accuracy;if(i==null)return a.jsx("div",{className:"flex items-center justify-center h-full",children:a.jsx("p",{className:"text-bambu-gray text-center py-4",children:r("stats.noTimeAccuracyData")})});const o=(Math.min(150,Math.max(50,i))-50)/100*100,c=(v=>v>=95&&v<=105?"#00ae42":v>105?"#3b82f6":"#f97316")(i),u=i-100,d=n===1?112:n===2?128:144,h=d/2-8,m=h*2*Math.PI,p=n===1?3:n===2?6:999,b=t?.time_accuracy_by_printer?Object.entries(t.time_accuracy_by_printer).slice(0,p):[];return a.jsxs("div",{className:"flex items-center gap-6",children:[a.jsxs("div",{className:"relative flex-shrink-0",style:{width:d,height:d},children:[a.jsxs("svg",{className:"w-full h-full -rotate-90",children:[a.jsx("circle",{cx:d/2,cy:d/2,r:h,fill:"none",stroke:"#3d3d3d",strokeWidth:"10"}),a.jsx("circle",{cx:d/2,cy:d/2,r:h,fill:"none",stroke:c,strokeWidth:"10",strokeLinecap:"round",strokeDasharray:`${o/100*m} ${m}`})]}),a.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center",children:[a.jsxs("span",{className:`font-bold text-white ${n>=2?"text-2xl":"text-xl"}`,children:[i.toFixed(0),"%"]}),a.jsxs("span",{className:`text-xs ${u>=0?"text-blue-400":"text-orange-400"}`,children:[u>=0?"+":"",u.toFixed(0),"%"]})]})]}),a.jsxs("div",{className:"flex-1 min-w-0",children:[a.jsxs("div",{className:"flex items-center gap-2 text-xs text-bambu-gray",children:[a.jsx($K,{className:"w-3 h-3 flex-shrink-0"}),a.jsx("span",{children:r("stats.perfectEstimate")})]}),b.length>0&&a.jsx("div",{className:`mt-2 ${n===4?"grid grid-cols-3 gap-x-6 gap-y-1":n===2?"grid grid-cols-2 gap-x-6 gap-y-1":"space-y-1"}`,style:{width:"fit-content"},children:b.map(([v,x])=>a.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[a.jsx("span",{className:"text-bambu-gray truncate max-w-[100px]",children:e.get(v)||`${r("common.printer")} ${v}`}),a.jsxs("span",{className:`font-medium ${x>=95&&x<=105?"text-status-ok":x>105?"text-blue-400":"text-status-warning"}`,children:[x.toFixed(0),"%"]})]},v))})]})]})}function FYe({stats:t,size:e=1,t:n}){if(!t?.prints_by_filament_type||Object.keys(t.prints_by_filament_type).length===0)return a.jsx("p",{className:"text-bambu-gray text-center py-4",children:n("stats.noFilamentData")});const r=Object.entries(t.prints_by_filament_type).sort(([,l],[,c])=>c-l),i=e===1?5:e===2?8:999,s=r.slice(0,i),o=r.length>i;return e===4&&s.length>4?a.jsx("div",{className:"grid grid-cols-2 lg:grid-cols-3 gap-4",children:s.map(([l,c])=>{const u=Math.round(c/(t.total_prints||1)*100);return a.jsxs("div",{children:[a.jsxs("div",{className:"flex justify-between text-sm mb-1",children:[a.jsx("span",{className:"text-white truncate max-w-[120px]",children:l}),a.jsx("span",{className:"text-bambu-gray",children:c})]}),a.jsx("div",{className:"h-2 bg-bambu-dark rounded-full",children:a.jsx("div",{className:"h-full bg-bambu-green rounded-full transition-all",style:{width:`${u}%`}})})]},l)})}):a.jsxs("div",{className:"space-y-3",children:[s.map(([l,c])=>{const u=Math.round(c/(t.total_prints||1)*100);return a.jsxs("div",{children:[a.jsxs("div",{className:"flex justify-between text-sm mb-1",children:[a.jsx("span",{className:"text-white",children:l}),a.jsxs("span",{className:"text-bambu-gray",children:[c," ",n("common.prints")]})]}),a.jsx("div",{className:"h-2 bg-bambu-dark rounded-full",children:a.jsx("div",{className:"h-full bg-bambu-green rounded-full transition-all",style:{width:`${u}%`}})})]},l)}),o&&a.jsx("p",{className:"text-xs text-bambu-gray text-center pt-1",children:n("common.more",{count:r.length-i})})]})}function IYe({printDates:t,size:e=2}){const n=e===1?3:e===2?6:12;return a.jsx(TYe,{printDates:t,months:n})}function UYe({stats:t,printerMap:e,t:n}){return!t?.prints_by_printer||Object.keys(t.prints_by_printer).length===0?a.jsx("p",{className:"text-bambu-gray text-center py-4",children:n("stats.noPrinterData")}):a.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:Object.entries(t.prints_by_printer).map(([r,i])=>a.jsxs("div",{className:"flex items-center gap-3 p-3 bg-bambu-dark rounded-lg",children:[a.jsx("div",{className:"p-2 bg-bambu-dark-tertiary rounded-lg",children:a.jsx(Or,{className:"w-4 h-4 text-bambu-green"})}),a.jsxs("div",{children:[a.jsx("p",{className:"text-white font-medium text-sm",children:e.get(r)||`${n("common.printer")} ${r}`}),a.jsxs("p",{className:"text-xs text-bambu-gray",children:[i," ",n("common.prints")]})]})]},r))})}function zYe({archives:t,currency:e,t:n}){return!t||t.length===0?a.jsx("p",{className:"text-bambu-gray text-center py-4",children:n("stats.noPrintData")}):a.jsx(jYe,{archives:t,currency:e})}function BYe({size:t=1,t:e}){const{data:n,isLoading:r}=st({queryKey:["failureAnalysis"],queryFn:()=>ce.getFailureAnalysis({days:30})});if(r)return a.jsx("div",{className:"flex justify-center py-4",children:a.jsx(ut,{className:"w-6 h-6 text-bambu-green animate-spin"})});if(!n||n.total_prints===0)return a.jsx("p",{className:"text-bambu-gray text-center py-4",children:e("stats.noPrintDataLast30Days")});const i=t===1?5:t===2?8:999,s=Object.entries(n.failures_by_reason).sort(([,c],[,u])=>u-c),o=s.slice(0,i),l=s.length>i;return a.jsxs("div",{className:`${t>=2?"flex gap-8":"space-y-4"}`,children:[a.jsxs("div",{className:t>=2?"flex-shrink-0":"",children:[a.jsx("div",{className:"flex items-center gap-4",children:a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(kn,{className:`w-5 h-5 ${n.failure_rate>20?"text-status-error":n.failure_rate>10?"text-status-warning":"text-status-ok"}`}),a.jsxs("span",{className:`font-bold text-white ${t>=2?"text-3xl":"text-2xl"}`,children:[n.failure_rate.toFixed(1),"%"]})]})}),a.jsx("div",{className:"text-sm text-bambu-gray mt-1",children:e("stats.failedPrintsCount",{failed:n.failed_prints,total:n.total_prints})}),n.trend&&n.trend.length>=2&&a.jsx("div",{className:`${t>=2?"mt-4":"mt-2 pt-2 border-t border-bambu-dark-tertiary"}`,children:a.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[a.jsx(GK,{className:`w-4 h-4 ${n.trend[n.trend.length-1].failure_rate0&&a.jsxs("div",{className:`flex-1 ${t>=2?"border-l border-bambu-dark-tertiary pl-8":"pt-2"}`,children:[a.jsx("p",{className:"text-xs text-bambu-gray font-medium mb-2",children:t>=2?e("stats.failureReasons"):e("stats.topFailureReasons")}),a.jsx("div",{className:`${t===4?"grid grid-cols-2 gap-x-6 gap-y-1":"space-y-1"}`,children:o.map(([c,u])=>a.jsxs("div",{className:"flex items-center justify-between text-sm",children:[a.jsx("span",{className:`text-white truncate ${t===4?"max-w-[200px]":"max-w-[160px]"}`,children:c||e("common.unknown")}),a.jsx("span",{className:"text-bambu-gray ml-2",children:u})]},c))}),l&&a.jsx("p",{className:"text-xs text-bambu-gray mt-2",children:e("common.more",{count:s.length-i})})]})]})}function HYe(){const{t}=Sn(),{showToast:e}=Hn(),{hasPermission:n}=Di(),[r,i]=_.useState(!1),[s,o]=_.useState(!1),[l,c]=_.useState(0),[u,d]=_.useState(0),[h,m]=_.useState(!1);_.useEffect(()=>{const T=()=>{try{const z=localStorage.getItem("bambusy-dashboard-layout");if(z){const L=JSON.parse(z);d(L.hidden?.length||0)}}catch{d(0)}};T(),window.addEventListener("storage",T);const j=setInterval(T,500);return()=>{window.removeEventListener("storage",T),clearInterval(j)}},[l]);const{data:p,isLoading:b,refetch:v}=st({queryKey:["archiveStats"],queryFn:ce.getArchiveStats}),{data:x}=st({queryKey:["printers"],queryFn:ce.getPrinters}),{data:y}=st({queryKey:["archives"],queryFn:()=>ce.getArchives(void 0,void 0,1e3,0)}),{data:S}=st({queryKey:["settings"],queryFn:ce.getSettings}),N=async T=>{o(!1),i(!0);try{const{blob:j,filename:z}=await ce.exportStats({format:T,days:90}),L=URL.createObjectURL(j),B=document.createElement("a");B.href=L,B.download=z,B.click(),URL.revokeObjectURL(L),e(t("stats.exportDownloaded"))}catch{e(t("stats.exportFailed"),"error")}finally{i(!1)}},A=async()=>{m(!0);try{const T=await ce.recalculateCosts();await v(),e(t("stats.recalculatedCosts",{count:T.updated}))}catch{e(t("stats.recalculateFailed"),"error")}finally{m(!1)}},k=S?.currency||"$",C=new Map(x?.map(T=>[String(T.id),T.name])||[]),E=y?.map(T=>T.created_at)||[];if(b)return a.jsx("div",{className:"p-4 md:p-8",children:a.jsx("div",{className:"text-center py-12 text-bambu-gray",children:t("stats.loadingStats")})});const P=[{id:"quick-stats",title:t("stats.quickStats"),component:a.jsx(RYe,{stats:p,currency:k,t}),defaultSize:2},{id:"success-rate",title:t("stats.successRate"),component:T=>a.jsx(OYe,{stats:p,printerMap:C,size:T,t}),defaultSize:1},{id:"time-accuracy",title:t("stats.timeAccuracy"),component:T=>a.jsx(LYe,{stats:p,printerMap:C,size:T,t}),defaultSize:1},{id:"filament-types",title:t("stats.filamentTypes"),component:T=>a.jsx(FYe,{stats:p,size:T,t}),defaultSize:1},{id:"failure-analysis",title:t("stats.failureAnalysis"),component:T=>a.jsx(BYe,{size:T,t}),defaultSize:1},{id:"print-activity",title:t("stats.printActivity"),component:T=>a.jsx(IYe,{printDates:E,size:T}),defaultSize:2},{id:"prints-by-printer",title:t("stats.printsByPrinter"),component:a.jsx(UYe,{stats:p,printerMap:C,t}),defaultSize:2},{id:"filament-trends",title:t("stats.filamentTrends"),component:a.jsx(zYe,{archives:y||[],currency:k,t}),defaultSize:4}];return a.jsxs("div",{className:"p-4 md:p-8",children:[a.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4 mb-6",children:[a.jsxs("div",{children:[a.jsx("h1",{className:"text-2xl font-bold text-white",children:t("stats.title")}),a.jsx("p",{className:"text-bambu-gray",children:t("stats.subtitle")})]}),a.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[u>0&&a.jsxs(ke,{variant:"secondary",onClick:()=>{window.dispatchEvent(new CustomEvent("toggle-hidden-panel"))},children:[a.jsx(_c,{className:"w-4 h-4"}),t("stats.hiddenCount",{count:u})]}),a.jsxs(ke,{variant:"secondary",onClick:()=>{localStorage.removeItem("bambusy-dashboard-layout"),c(T=>T+1),e(t("stats.layoutReset"))},disabled:!n("settings:update"),title:n("settings:update")?void 0:t("stats.noPermissionResetLayout"),children:[a.jsx($h,{className:"w-4 h-4"}),t("stats.resetLayout")]}),a.jsxs(ke,{variant:"secondary",onClick:A,disabled:h||!n("archives:update_all"),title:n("archives:update_all")?t("stats.recalculateCostsHint"):t("stats.noPermissionRecalculate"),children:[h?a.jsx(ut,{className:"w-4 h-4 animate-spin"}):a.jsx(rde,{className:"w-4 h-4"}),t("stats.recalculateCosts")]}),a.jsxs("div",{className:"relative",children:[a.jsxs(ke,{variant:"secondary",onClick:()=>o(!s),disabled:r,children:[r?a.jsx(ut,{className:"w-4 h-4 animate-spin"}):a.jsx(dS,{className:"w-4 h-4"}),t("stats.exportStats")]}),s&&a.jsxs("div",{className:"absolute right-0 top-full mt-1 w-48 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-20",children:[a.jsxs("button",{className:"w-full px-4 py-2 text-left text-white hover:bg-bambu-dark-tertiary transition-colors flex items-center gap-2 rounded-t-lg",onClick:()=>N("csv"),children:[a.jsx(ps,{className:"w-4 h-4"}),t("stats.exportAsCsv")]}),a.jsxs("button",{className:"w-full px-4 py-2 text-left text-white hover:bg-bambu-dark-tertiary transition-colors flex items-center gap-2 rounded-b-lg",onClick:()=>N("xlsx"),children:[a.jsx(dS,{className:"w-4 h-4"}),t("stats.exportAsExcel")]})]})]})]})]}),a.jsx(DYe,{widgets:P,storageKey:"bambusy-dashboard-layout",hideControls:!0},l)]})}function $Ye({plug:t,onEdit:e}){const n=un(),{showToast:r}=Hn(),[i,s]=_.useState(!1),[o,l]=_.useState(!1),[c,u]=_.useState(!1),[d,h]=_.useState(!1),{data:m,isLoading:p}=st({queryKey:["smart-plug-status",t.id],queryFn:()=>ce.getSmartPlugStatus(t.id),refetchInterval:3e4}),{data:b}=st({queryKey:["printers"],queryFn:ce.getPrinters}),v=b?.find(T=>T.id===t.printer_id),x=pt({mutationFn:T=>ce.controlSmartPlug(t.id,T),onMutate:async T=>{await n.cancelQueries({queryKey:["smart-plug-status",t.id]});const j=n.getQueryData(["smart-plug-status",t.id]),z=T==="on"?"ON":T==="off"||m?.state==="ON"?"OFF":"ON";return n.setQueryData(["smart-plug-status",t.id],L=>({...L,state:z})),{previousStatus:j}},onError:(T,j,z)=>{z?.previousStatus&&n.setQueryData(["smart-plug-status",t.id],z.previousStatus),r(`Failed to turn ${j} "${t.name}"`,"error")},onSettled:()=>{setTimeout(()=>{n.invalidateQueries({queryKey:["smart-plug-status",t.id]}),n.invalidateQueries({queryKey:["smart-plugs"]})},1e3)}}),y=pt({mutationFn:T=>ce.updateSmartPlug(t.id,T),onSuccess:()=>{n.invalidateQueries({queryKey:["smart-plugs"]}),t.printer_id&&(n.invalidateQueries({queryKey:["smartPlugByPrinter",t.printer_id]}),n.invalidateQueries({queryKey:["scriptPlugsByPrinter",t.printer_id]}))}}),S=pt({mutationFn:()=>ce.deleteSmartPlug(t.id),onSuccess:()=>{n.invalidateQueries({queryKey:["smart-plugs"]}),t.printer_id&&n.invalidateQueries({queryKey:["scriptPlugsByPrinter",t.printer_id]})}}),N=m?.state==="ON",A=t.plug_type==="mqtt"&&m?.energy?.power!==null&&m?.energy?.power!==void 0,k=(m?.reachable??!1)||A,C=x.isPending,P=(()=>{if(t.plug_type!=="tasmota"||!t.ip_address)return null;const T=t.ip_address;return t.username&&t.password?`http://${encodeURIComponent(t.username)}:${encodeURIComponent(t.password)}@${T}/`:`http://${T}/`})();return a.jsxs(a.Fragment,{children:[a.jsx(_t,{className:"relative",children:a.jsxs(Mt,{className:"p-4",children:[a.jsxs("div",{className:"flex items-start justify-between gap-2 mb-3",children:[a.jsxs("div",{className:"flex items-center gap-3 min-w-0 flex-1",children:[a.jsx("div",{className:`p-2 rounded-lg flex-shrink-0 ${t.plug_type==="mqtt"?k?"bg-teal-500/20":"bg-red-500/20":k?N?"bg-bambu-green/20":"bg-bambu-dark":"bg-red-500/20"}`,children:t.plug_type==="mqtt"?a.jsx(cO,{className:`w-5 h-5 ${k?"text-teal-400":"text-red-400"}`}):t.plug_type==="homeassistant"?a.jsx(Jy,{className:`w-5 h-5 ${k?N?"text-bambu-green":"text-bambu-gray":"text-red-400"}`}):a.jsx(rl,{className:`w-5 h-5 ${k?N?"text-bambu-green":"text-bambu-gray":"text-red-400"}`})}),a.jsxs("div",{className:"min-w-0",children:[a.jsx("h3",{className:"font-medium text-white truncate",children:t.name}),a.jsx("p",{className:"text-sm text-bambu-gray truncate",title:t.plug_type==="mqtt"?t.mqtt_topic??void 0:t.plug_type==="homeassistant"?t.ha_entity_id??void 0:t.ip_address??void 0,children:t.plug_type==="mqtt"?t.mqtt_topic:t.plug_type==="homeassistant"?t.ha_entity_id:t.ip_address})]})]}),a.jsxs("div",{className:"flex flex-col items-end gap-1 flex-shrink-0",children:[p?a.jsx(ut,{className:"w-4 h-4 text-bambu-gray animate-spin"}):t.plug_type==="mqtt"?a.jsxs("div",{className:"flex items-center gap-1.5 text-sm whitespace-nowrap",children:[a.jsx("span",{className:"px-1.5 py-0.5 bg-teal-500/20 text-teal-400 text-[10px] font-medium rounded flex-shrink-0",children:"MQTT"}),k&&a.jsx("span",{className:"text-status-ok",children:"✓"})]}):t.plug_type==="homeassistant"?a.jsxs("div",{className:"flex items-center gap-1 text-sm",children:[a.jsx("span",{className:"px-1 py-0.5 bg-blue-500/20 text-blue-400 text-[10px] font-medium rounded",children:"HA"}),a.jsx("span",{className:k?N?"text-status-ok":"text-bambu-gray":"text-status-error",children:k?m?.state||"?":"Offline"})]}):k?a.jsxs("div",{className:"flex items-center gap-1 text-sm",children:[a.jsx(Fg,{className:"w-4 h-4 text-status-ok"}),a.jsx("span",{className:N?"text-status-ok":"text-bambu-gray",children:m?.state||"Unknown"})]}):a.jsxs("div",{className:"flex items-center gap-1 text-sm text-status-error",children:[a.jsx(_m,{className:"w-4 h-4"}),a.jsx("span",{children:"Offline"})]}),P&&a.jsxs("a",{href:P,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1 px-2 py-0.5 bg-bambu-dark hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white text-xs rounded-full transition-colors",title:"Open plug admin page",children:[a.jsx(Xr,{className:"w-3 h-3"}),"Admin"]})]})]}),v&&a.jsxs("div",{className:"mb-3 px-2 py-1.5 bg-bambu-dark rounded-lg",children:[a.jsx("span",{className:"text-xs text-bambu-gray",children:"Linked to: "}),a.jsx("span",{className:"text-sm text-white",children:v.name})]}),(t.power_alert_enabled||t.schedule_enabled||t.plug_type==="mqtt")&&a.jsxs("div",{className:"flex flex-wrap gap-1.5 mb-3",children:[t.plug_type==="mqtt"&&a.jsxs("span",{className:"flex items-center gap-1 px-2 py-0.5 bg-teal-500/20 text-teal-400 text-xs rounded-full",children:[a.jsx(_c,{className:"w-3 h-3"}),"Monitor Only"]}),t.power_alert_enabled&&a.jsxs("span",{className:"flex items-center gap-1 px-2 py-0.5 bg-yellow-500/20 text-yellow-400 text-xs rounded-full",children:[a.jsx(Og,{className:"w-3 h-3"}),"Alerts"]}),t.schedule_enabled&&a.jsxs("span",{className:"flex items-center gap-1 px-2 py-0.5 bg-blue-500/20 text-blue-400 text-xs rounded-full",children:[a.jsx(ei,{className:"w-3 h-3"}),t.schedule_on_time&&t.schedule_off_time?`${t.schedule_on_time} - ${t.schedule_off_time}`:t.schedule_on_time?`On ${t.schedule_on_time}`:`Off ${t.schedule_off_time}`]})]}),t.plug_type!=="mqtt"&&a.jsxs("div",{className:"flex gap-2 mb-3",children:[a.jsxs(ke,{size:"sm",variant:N?"primary":"secondary",disabled:!k||C,onClick:()=>l(!0),className:"flex-1",children:[C?a.jsx(ut,{className:"w-4 h-4 animate-spin"}):a.jsx(Zu,{className:"w-4 h-4"}),"On"]}),a.jsxs(ke,{size:"sm",variant:N?"secondary":"primary",disabled:!k||C,onClick:()=>u(!0),className:"flex-1",children:[C?a.jsx(ut,{className:"w-4 h-4 animate-spin"}):a.jsx(HM,{className:"w-4 h-4"}),"Off"]})]}),t.plug_type==="mqtt"&&m?.energy&&a.jsxs("div",{className:"flex gap-2 mb-3 px-3 py-2 bg-bambu-dark rounded-lg",children:[m.energy.power!==null&&m.energy.power!==void 0&&a.jsxs("div",{className:"flex-1 text-center",children:[a.jsxs("p",{className:"text-lg font-semibold text-white",children:[Math.round(m.energy.power),"W"]}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Power"})]}),m.energy.today!==null&&m.energy.today!==void 0&&a.jsxs("div",{className:"flex-1 text-center border-l border-bambu-dark-tertiary",children:[a.jsx("p",{className:"text-lg font-semibold text-white",children:m.energy.today.toFixed(2)}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"kWh Today"})]})]}),a.jsxs("button",{onClick:()=>h(!d),className:"w-full flex items-center justify-between py-2 text-sm text-bambu-gray hover:text-white transition-colors",children:[a.jsxs("span",{className:"flex items-center gap-2",children:[a.jsx(jh,{className:"w-4 h-4"}),t.plug_type==="mqtt"?"Settings":"Automation Settings"]}),a.jsx("span",{children:d?"-":"+"})]}),d&&a.jsxs("div",{className:"pt-3 border-t border-bambu-dark-tertiary space-y-4",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(UM,{className:"w-4 h-4 text-bambu-green"}),a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"Show in Switchbar"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Quick access from sidebar"})]})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:t.show_in_switchbar,onChange:T=>y.mutate({show_in_switchbar:T.target.checked}),className:"sr-only peer"}),a.jsx("div",{className:"w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green"})]})]}),t.plug_type!=="mqtt"&&a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"Enabled"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Enable automation for this plug"})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:t.enabled,onChange:T=>y.mutate({enabled:T.target.checked}),className:"sr-only peer"}),a.jsx("div",{className:"w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green"})]})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"Auto On"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Turn on when print starts"})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:t.auto_on,onChange:T=>y.mutate({auto_on:T.target.checked}),className:"sr-only peer"}),a.jsx("div",{className:"w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green"})]})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"Auto Off"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Turn off when print completes (one-shot)"})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:t.auto_off,onChange:T=>y.mutate({auto_off:T.target.checked}),className:"sr-only peer"}),a.jsx("div",{className:"w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green"})]})]}),t.auto_off&&a.jsxs("div",{className:"space-y-3 pl-4 border-l-2 border-bambu-dark-tertiary",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white mb-2",children:"Turn Off Delay Mode"}),a.jsxs("div",{className:"flex gap-2",children:[a.jsxs("button",{onClick:()=>y.mutate({off_delay_mode:"time"}),className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg text-sm transition-colors ${t.off_delay_mode==="time"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white"}`,children:[a.jsx(nr,{className:"w-4 h-4"}),"Time"]}),a.jsxs("button",{onClick:()=>y.mutate({off_delay_mode:"temperature"}),className:`flex-1 flex items-center justify-center gap-2 px-3 py-2 rounded-lg text-sm transition-colors ${t.off_delay_mode==="temperature"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white"}`,children:[a.jsx(GM,{className:"w-4 h-4"}),"Temp"]})]})]}),t.off_delay_mode==="time"?a.jsxs("div",{children:[a.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Delay (minutes)"}),a.jsx("input",{type:"number",min:"1",max:"60",value:t.off_delay_minutes,onChange:T=>y.mutate({off_delay_minutes:parseInt(T.target.value)||5}),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none"})]}):a.jsxs("div",{children:[a.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Temperature threshold (C)"}),a.jsx("input",{type:"number",min:"30",max:"100",value:t.off_temp_threshold,onChange:T=>y.mutate({off_temp_threshold:parseInt(T.target.value)||70}),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none"}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Turns off when nozzle cools below this temperature"})]})]})]}),a.jsxs("div",{className:"flex gap-2 pt-2",children:[a.jsxs(ke,{size:"sm",variant:"secondary",onClick:()=>e(t),className:"flex-1",children:[a.jsx(Eg,{className:"w-4 h-4"}),"Edit"]}),a.jsx(ke,{size:"sm",variant:"secondary",onClick:()=>s(!0),className:"text-red-400 hover:text-red-300",children:a.jsx(cn,{className:"w-4 h-4"})})]})]})]})}),i&&a.jsx(er,{title:"Delete Smart Plug",message:`Are you sure you want to delete "${t.name}"? This cannot be undone.`,confirmText:"Delete",variant:"danger",onConfirm:()=>{S.mutate(),s(!1)},onCancel:()=>s(!1)}),o&&a.jsx(er,{title:"Turn On Smart Plug",message:`Are you sure you want to turn on "${t.name}"?`,confirmText:"Turn On",variant:"default",onConfirm:()=>{x.mutate("on"),l(!1)},onCancel:()=>l(!1)}),c&&a.jsx(er,{title:"Turn Off Smart Plug",message:`Are you sure you want to turn off "${t.name}"? This will cut power to the connected device.`,confirmText:"Turn Off",variant:"danger",onConfirm:()=>{x.mutate("off"),u(!1)},onCancel:()=>u(!1)})]})}function VYe({plug:t,onClose:e}){const n=un(),r=!!t,[i,s]=_.useState(t?.plug_type||"tasmota"),[o,l]=_.useState(t?.name||""),[c,u]=_.useState(t?.ip_address||""),[d,h]=_.useState(t?.username||""),[m,p]=_.useState(t?.password||""),[b,v]=_.useState(t?.ha_entity_id||""),[x,y]=_.useState(t?.mqtt_power_topic||t?.mqtt_topic||""),[S,N]=_.useState(t?.mqtt_power_path||""),[A,k]=_.useState((t?.mqtt_power_multiplier??t?.mqtt_multiplier??1).toString()),[C,E]=_.useState(t?.mqtt_energy_topic||""),[P,T]=_.useState(t?.mqtt_energy_path||""),[j,z]=_.useState((t?.mqtt_energy_multiplier??1).toString()),[L,B]=_.useState(t?.mqtt_state_topic||""),[R,$]=_.useState(t?.mqtt_state_path||""),[q,I]=_.useState(t?.mqtt_state_on_value||""),[G,Y]=_.useState(t?.ha_power_entity||""),[re,H]=_.useState(t?.ha_energy_today_entity||""),[K,ne]=_.useState(t?.ha_energy_total_entity||""),[ie,be]=_.useState(""),[pe,de]=_.useState(""),[Ce,ae]=_.useState(!1),Ae=_.useRef(null),[Le,fe]=_.useState(""),[Xe,W]=_.useState(!1),Q=_.useRef(null),[me,X]=_.useState(""),[te,V]=_.useState(!1),ge=_.useRef(null),[Se,ee]=_.useState(""),[U,O]=_.useState(!1),Z=_.useRef(null),[le,we]=_.useState(t?.printer_id||null),[ye,se]=_.useState(null),[Oe,He]=_.useState(null),[tt,Ue]=_.useState(t?.power_alert_enabled||!1),[xe,Te]=_.useState(t?.power_alert_high?.toString()||""),[Ie,Ne]=_.useState(t?.power_alert_low?.toString()||""),[Ge,Me]=_.useState(t?.schedule_enabled||!1),[rt,Ee]=_.useState(t?.schedule_on_time||""),[Ke,Be]=_.useState(t?.schedule_off_time||""),[ue,$e]=_.useState(t?.show_in_switchbar||!1),[at,kt]=_.useState(t?.show_on_printer_card??!0),[gt,Ut]=_.useState(!1),[Ft,Fe]=_.useState({scanned:0,total:0}),[xt,Wt]=_.useState([]),Qt=_.useRef(null),{data:En}=st({queryKey:["printers"],queryFn:ce.getPrinters}),{data:hn}=st({queryKey:["smart-plugs"],queryFn:ce.getSmartPlugs}),{data:or}=st({queryKey:["settings"],queryFn:ce.getSettings}),Kn=!!(or?.ha_enabled&&or?.ha_url&&or?.ha_token);_.useEffect(()=>{const _e=setTimeout(()=>{de(ie)},300);return()=>clearTimeout(_e)},[ie]),_.useEffect(()=>{const _e=Re=>{Ae.current&&!Ae.current.contains(Re.target)&&ae(!1),Q.current&&!Q.current.contains(Re.target)&&W(!1),ge.current&&!ge.current.contains(Re.target)&&V(!1),Z.current&&!Z.current.contains(Re.target)&&O(!1)};return document.addEventListener("mousedown",_e),()=>document.removeEventListener("mousedown",_e)},[]);const{data:Qn,isLoading:Tn,error:di}=st({queryKey:["ha-entities",pe],queryFn:()=>ce.getHAEntities(pe||void 0),enabled:i==="homeassistant"&&Kn,retry:!1,staleTime:0}),{data:ii}=st({queryKey:["ha-sensor-entities"],queryFn:ce.getHASensorEntities,enabled:i==="homeassistant"&&Kn,retry:!1,staleTime:0});_.useEffect(()=>{const _e=Re=>{Re.key==="Escape"&&e()};return window.addEventListener("keydown",_e),()=>{window.removeEventListener("keydown",_e),Qt.current&&clearInterval(Qt.current)}},[e]);const je=async()=>{Ut(!0),Wt([]),Fe({scanned:0,total:0}),He(null);try{await ce.startTasmotaScan();const _e=async()=>{try{const Re=await ce.getTasmotaScanStatus();Fe({scanned:Re.scanned,total:Re.total});const et=await ce.getDiscoveredTasmotaDevices();Wt(et),Re.running||(Ut(!1),Qt.current&&(clearInterval(Qt.current),Qt.current=null))}catch(Re){console.error("Polling error:",Re)}};await _e(),Qt.current=setInterval(_e,500)}catch(_e){Ut(!1);const Re=_e instanceof Error?_e.message:typeof _e=="string"?_e:JSON.stringify(_e);He(Re||"Failed to start scan")}},Je=async()=>{try{await ce.stopTasmotaScan()}catch{}Ut(!1),Qt.current&&(clearInterval(Qt.current),Qt.current=null)},dt=_e=>{u(_e.ip_address),l(_e.name),se(null)},ht=pt({mutationFn:()=>ce.testSmartPlugConnection(c,d||null,m||null),onSuccess:_e=>{se(_e),He(null),!o&&_e.device_name&&l(_e.device_name)},onError:_e=>{se(null),He(_e.message)}}),ct=pt({mutationFn:_e=>ce.createSmartPlug(_e),onSuccess:()=>{n.invalidateQueries({queryKey:["smart-plugs"]}),n.invalidateQueries({queryKey:["scriptPlugsByPrinter"]}),e()},onError:_e=>{He(_e.message)}}),Tt=pt({mutationFn:_e=>ce.updateSmartPlug(t.id,_e),onSuccess:()=>{n.invalidateQueries({queryKey:["smart-plugs"]}),n.invalidateQueries({queryKey:["scriptPlugsByPrinter"]}),e()},onError:_e=>{He(_e.message)}}),he=En?.filter(_e=>i==="tasmota"?!hn?.some(et=>et.printer_id===_e.id&&et.id!==t?.id&&et.plug_type==="tasmota"):!0),De=_e=>{if(_e.preventDefault(),He(null),!o.trim()){He("Name is required");return}if(i==="tasmota"&&!c.trim()){He("IP address is required for Tasmota plugs");return}if(i==="homeassistant"&&!b){He("Entity is required for Home Assistant plugs");return}if(i==="mqtt"){const et=x.trim(),Ye=C.trim(),Ct=L.trim();if(!et&&!Ye&&!Ct){He("At least one MQTT topic must be configured for power, energy, or state monitoring");return}}const Re={name:o.trim(),plug_type:i,ip_address:i==="tasmota"?c.trim():null,ha_entity_id:i==="homeassistant"?b:null,ha_power_entity:i==="homeassistant"&&G||null,ha_energy_today_entity:i==="homeassistant"&&re||null,ha_energy_total_entity:i==="homeassistant"&&K||null,mqtt_power_topic:i==="mqtt"&&x.trim()||null,mqtt_power_path:i==="mqtt"&&S.trim()||null,mqtt_power_multiplier:i==="mqtt"&&parseFloat(A)||1,mqtt_energy_topic:i==="mqtt"&&C.trim()||null,mqtt_energy_path:i==="mqtt"&&P.trim()||null,mqtt_energy_multiplier:i==="mqtt"&&parseFloat(j)||1,mqtt_state_topic:i==="mqtt"&&L.trim()||null,mqtt_state_path:i==="mqtt"&&R.trim()||null,mqtt_state_on_value:i==="mqtt"&&q.trim()||null,username:i==="tasmota"&&d.trim()||null,password:i==="tasmota"&&m.trim()||null,printer_id:le,power_alert_enabled:tt,power_alert_high:xe?parseFloat(xe):null,power_alert_low:Ie?parseFloat(Ie):null,schedule_enabled:Ge,schedule_on_time:rt||null,schedule_off_time:Ke||null,show_in_switchbar:ue,show_on_printer_card:at};r?Tt.mutate(Re):ct.mutate(Re)},Ve=ct.isPending||Tt.isPending;return a.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",onClick:e,children:a.jsxs("div",{className:"bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-md max-h-[90vh] flex flex-col",onClick:_e=>_e.stopPropagation(),children:[a.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary flex-shrink-0",children:[a.jsx("h2",{className:"text-lg font-semibold text-white",children:r?"Edit Smart Plug":"Add Smart Plug"}),a.jsx("button",{onClick:e,className:"text-bambu-gray hover:text-white transition-colors",children:a.jsx(Lt,{className:"w-5 h-5"})})]}),a.jsxs("form",{onSubmit:De,className:"p-6 space-y-4 overflow-y-auto",children:[Oe&&a.jsx("div",{className:"p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400",children:Oe}),!r&&a.jsxs("div",{className:"flex gap-2 mb-2",children:[a.jsxs("button",{type:"button",onClick:()=>{s("tasmota"),se(null),He(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2.5 rounded-lg font-medium transition-colors ${i==="tasmota"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white border border-bambu-dark-tertiary"}`,children:[a.jsx(rl,{className:"w-4 h-4"}),"Tasmota"]}),a.jsxs("button",{type:"button",onClick:()=>{s("homeassistant"),se(null),He(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2.5 rounded-lg font-medium transition-colors ${i==="homeassistant"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white border border-bambu-dark-tertiary"}`,children:[a.jsx(Jy,{className:"w-4 h-4"}),"HA"]}),a.jsxs("button",{type:"button",onClick:()=>{s("mqtt"),se(null),He(null)},className:`flex-1 flex items-center justify-center gap-2 px-3 py-2.5 rounded-lg font-medium transition-colors ${i==="mqtt"?"bg-bambu-green text-white":"bg-bambu-dark text-bambu-gray hover:text-white border border-bambu-dark-tertiary"}`,children:[a.jsx(cO,{className:"w-4 h-4"}),"MQTT"]})]}),!r&&i==="tasmota"&&a.jsxs("div",{className:"space-y-3",children:[gt?a.jsxs(ke,{type:"button",variant:"secondary",onClick:Je,className:"w-full",children:[a.jsx(Lt,{className:"w-4 h-4"}),"Stop Scanning"]}):a.jsxs(ke,{type:"button",variant:"primary",onClick:je,className:"w-full",children:[a.jsx(va,{className:"w-4 h-4"}),"Discover Tasmota Devices"]}),gt&&Ft.total>0&&a.jsxs("div",{className:"space-y-1",children:[a.jsxs("div",{className:"flex justify-between text-xs text-bambu-gray",children:[a.jsx("span",{children:"Scanning network..."}),a.jsxs("span",{children:[Ft.scanned," / ",Ft.total]})]}),a.jsx("div",{className:"w-full bg-bambu-dark-tertiary rounded-full h-2",children:a.jsx("div",{className:"bg-bambu-green h-2 rounded-full transition-all duration-300",style:{width:`${Ft.scanned/Ft.total*100}%`}})})]}),xt.length>0&&a.jsxs("div",{className:"space-y-2",children:[a.jsxs("p",{className:"text-xs text-bambu-gray",children:["Found ",xt.length," device(s) - click to select:"]}),a.jsx("div",{className:"max-h-40 overflow-y-auto space-y-1",children:xt.map(_e=>a.jsxs("button",{type:"button",onClick:()=>dt(_e),className:"w-full flex items-center justify-between p-2 bg-bambu-dark hover:bg-bambu-dark-tertiary rounded-lg transition-colors text-left border border-bambu-dark-tertiary",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(rl,{className:"w-4 h-4 text-bambu-green"}),a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:_e.name}),a.jsx("p",{className:"text-xs text-bambu-gray",children:_e.ip_address})]})]}),_e.state&&a.jsxs("span",{className:`flex items-center gap-1 text-xs ${_e.state==="ON"?"text-bambu-green":"text-bambu-gray"}`,children:[a.jsx(Zu,{className:"w-3 h-3"}),_e.state]})]},_e.ip_address))})]}),!gt&&xt.length===0&&Ft.total>0&&a.jsx("p",{className:"text-xs text-bambu-gray text-center py-2",children:"No Tasmota devices found on your network"})]}),i==="homeassistant"&&a.jsxs("div",{className:"space-y-3",children:[!Kn&&a.jsxs("div",{className:"space-y-3",children:[a.jsxs("div",{className:"p-3 bg-yellow-500/20 border border-yellow-500/50 rounded-lg text-sm text-yellow-400",children:["Home Assistant is not configured. Set it up in"," ",a.jsx("span",{className:"font-medium",children:"Settings → Network → Home Assistant"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1 opacity-50",children:"Select Entity *"}),a.jsx("select",{disabled:!0,className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray cursor-not-allowed opacity-50",children:a.jsx("option",{children:"Choose an entity..."})})]})]}),Kn&&a.jsxs(a.Fragment,{children:[Tn&&a.jsxs("div",{className:"flex items-center justify-center py-4 text-bambu-gray",children:[a.jsx(ut,{className:"w-5 h-5 animate-spin mr-2"}),"Loading entities..."]}),di&&a.jsxs("div",{className:"p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400",children:["Failed to load entities: ",di.message]}),(()=>{const _e=hn?.filter(Ye=>Ye.ha_entity_id&&Ye.id!==t?.id).map(Ye=>Ye.ha_entity_id)||[],Re=(Qn||[]).filter(Ye=>!_e.includes(Ye.entity_id)),et=Qn?.find(Ye=>Ye.entity_id===b);return a.jsxs("div",{ref:Ae,className:"relative",children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Select Entity *"}),a.jsxs("div",{className:"relative",children:[a.jsx(va,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"}),a.jsx("input",{type:"text",value:Ce?ie:et?`${et.friendly_name} (${et.entity_id})`:"",onChange:Ye=>{be(Ye.target.value),Ce||ae(!0)},onFocus:()=>{ae(!0),be("")},placeholder:"Search entities...",className:"w-full pl-9 pr-8 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"}),b&&!Ce&&a.jsx("button",{type:"button",onClick:()=>{v(""),be("")},className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-bambu-dark-tertiary rounded",children:a.jsx(Lt,{className:"w-4 h-4 text-bambu-gray hover:text-white"})}),Tn&&a.jsx(ut,{className:"absolute right-2 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray animate-spin"})]}),Ce&&a.jsxs("div",{className:"absolute z-50 w-full mt-1 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-60 overflow-y-auto",children:[Tn&&a.jsxs("div",{className:"px-3 py-2 text-sm text-bambu-gray flex items-center gap-2",children:[a.jsx(ut,{className:"w-4 h-4 animate-spin"}),"Loading..."]}),!Tn&&Re.length===0&&a.jsx("div",{className:"px-3 py-2 text-sm text-bambu-gray",children:pe?`No entities found matching "${pe}"`:"No entities available"}),!Tn&&Re.map(Ye=>a.jsxs("button",{type:"button",onClick:()=>{v(Ye.entity_id),ae(!1),be(""),o||l(Ye.friendly_name)},className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary transition-colors ${Ye.entity_id===b?"bg-bambu-green/20 text-bambu-green":"text-white"}`,children:[a.jsx("div",{className:"font-medium",children:Ye.friendly_name}),a.jsxs("div",{className:"text-xs text-bambu-gray flex items-center justify-between",children:[a.jsx("span",{children:Ye.entity_id}),a.jsx("span",{className:Ye.state==="on"?"text-bambu-green":"",children:Ye.state})]})]},Ye.entity_id))]}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:pe?`Searching all entities (${Re.length} found)`:`Showing switch, light, input_boolean (${Re.length} available)`})]})})(),b&&ii&&ii.length>0&&a.jsxs("div",{className:"border-t border-bambu-dark-tertiary pt-4 mt-4 space-y-3",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white font-medium mb-1",children:"Energy Monitoring (Optional)"}),a.jsx("p",{className:"text-xs text-bambu-gray mb-3",children:"Search and select sensors that provide power/energy data."})]}),(()=>{const _e=ii.filter(Ye=>Ye.unit_of_measurement==="W"||Ye.unit_of_measurement==="kW"||Ye.unit_of_measurement==="mW"),Re=Le?_e.filter(Ye=>Ye.entity_id.toLowerCase().includes(Le.toLowerCase())||Ye.friendly_name.toLowerCase().includes(Le.toLowerCase())):_e,et=ii.find(Ye=>Ye.entity_id===G);return a.jsxs("div",{ref:Q,className:"relative",children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Power Sensor (W)"}),a.jsxs("div",{className:"relative",children:[a.jsx(va,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"}),a.jsx("input",{type:"text",value:Xe?Le:et?`${et.friendly_name} (${et.state} ${et.unit_of_measurement})`:"",onChange:Ye=>{fe(Ye.target.value),Xe||W(!0)},onFocus:()=>{W(!0),fe("")},placeholder:"Search power sensors...",className:"w-full pl-9 pr-8 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"}),G&&!Xe&&a.jsx("button",{type:"button",onClick:()=>{Y(""),fe("")},className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-bambu-dark-tertiary rounded",children:a.jsx(Lt,{className:"w-4 h-4 text-bambu-gray hover:text-white"})})]}),Xe&&a.jsxs("div",{className:"absolute z-50 w-full mt-1 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-48 overflow-y-auto",children:[a.jsx("button",{type:"button",onClick:()=>{Y(""),W(!1),fe("")},className:"w-full px-3 py-2 text-left text-sm text-bambu-gray hover:bg-bambu-dark-tertiary",children:"None"}),Re.map(Ye=>a.jsxs("button",{type:"button",onClick:()=>{Y(Ye.entity_id),W(!1),fe("")},className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${Ye.entity_id===G?"bg-bambu-green/20 text-bambu-green":"text-white"}`,children:[a.jsx("div",{className:"font-medium",children:Ye.friendly_name}),a.jsxs("div",{className:"text-xs text-bambu-gray",children:[Ye.entity_id," • ",Ye.state," ",Ye.unit_of_measurement]})]},Ye.entity_id)),Re.length===0&&a.jsx("div",{className:"px-3 py-2 text-sm text-bambu-gray",children:"No matching sensors"})]})]})})(),(()=>{const _e=ii.filter(Ye=>Ye.unit_of_measurement==="kWh"||Ye.unit_of_measurement==="Wh"||Ye.unit_of_measurement==="MWh"),Re=me?_e.filter(Ye=>Ye.entity_id.toLowerCase().includes(me.toLowerCase())||Ye.friendly_name.toLowerCase().includes(me.toLowerCase())):_e,et=ii.find(Ye=>Ye.entity_id===re);return a.jsxs("div",{ref:ge,className:"relative",children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Energy Today (kWh)"}),a.jsxs("div",{className:"relative",children:[a.jsx(va,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"}),a.jsx("input",{type:"text",value:te?me:et?`${et.friendly_name} (${et.state} ${et.unit_of_measurement})`:"",onChange:Ye=>{X(Ye.target.value),te||V(!0)},onFocus:()=>{V(!0),X("")},placeholder:"Search energy sensors...",className:"w-full pl-9 pr-8 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"}),re&&!te&&a.jsx("button",{type:"button",onClick:()=>{H(""),X("")},className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-bambu-dark-tertiary rounded",children:a.jsx(Lt,{className:"w-4 h-4 text-bambu-gray hover:text-white"})})]}),te&&a.jsxs("div",{className:"absolute z-50 w-full mt-1 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-48 overflow-y-auto",children:[a.jsx("button",{type:"button",onClick:()=>{H(""),V(!1),X("")},className:"w-full px-3 py-2 text-left text-sm text-bambu-gray hover:bg-bambu-dark-tertiary",children:"None"}),Re.map(Ye=>a.jsxs("button",{type:"button",onClick:()=>{H(Ye.entity_id),V(!1),X("")},className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${Ye.entity_id===re?"bg-bambu-green/20 text-bambu-green":"text-white"}`,children:[a.jsx("div",{className:"font-medium",children:Ye.friendly_name}),a.jsxs("div",{className:"text-xs text-bambu-gray",children:[Ye.entity_id," • ",Ye.state," ",Ye.unit_of_measurement]})]},Ye.entity_id)),Re.length===0&&a.jsx("div",{className:"px-3 py-2 text-sm text-bambu-gray",children:"No matching sensors"})]})]})})(),(()=>{const _e=ii.filter(Ye=>Ye.unit_of_measurement==="kWh"||Ye.unit_of_measurement==="Wh"||Ye.unit_of_measurement==="MWh"),Re=Se?_e.filter(Ye=>Ye.entity_id.toLowerCase().includes(Se.toLowerCase())||Ye.friendly_name.toLowerCase().includes(Se.toLowerCase())):_e,et=ii.find(Ye=>Ye.entity_id===K);return a.jsxs("div",{ref:Z,className:"relative",children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Total Energy (kWh)"}),a.jsxs("div",{className:"relative",children:[a.jsx(va,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"}),a.jsx("input",{type:"text",value:U?Se:et?`${et.friendly_name} (${et.state} ${et.unit_of_measurement})`:"",onChange:Ye=>{ee(Ye.target.value),U||O(!0)},onFocus:()=>{O(!0),ee("")},placeholder:"Search energy sensors...",className:"w-full pl-9 pr-8 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"}),K&&!U&&a.jsx("button",{type:"button",onClick:()=>{ne(""),ee("")},className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 hover:bg-bambu-dark-tertiary rounded",children:a.jsx(Lt,{className:"w-4 h-4 text-bambu-gray hover:text-white"})})]}),U&&a.jsxs("div",{className:"absolute z-50 w-full mt-1 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg shadow-lg max-h-48 overflow-y-auto",children:[a.jsx("button",{type:"button",onClick:()=>{ne(""),O(!1),ee("")},className:"w-full px-3 py-2 text-left text-sm text-bambu-gray hover:bg-bambu-dark-tertiary",children:"None"}),Re.map(Ye=>a.jsxs("button",{type:"button",onClick:()=>{ne(Ye.entity_id),O(!1),ee("")},className:`w-full px-3 py-2 text-left text-sm hover:bg-bambu-dark-tertiary ${Ye.entity_id===K?"bg-bambu-green/20 text-bambu-green":"text-white"}`,children:[a.jsx("div",{className:"font-medium",children:Ye.friendly_name}),a.jsxs("div",{className:"text-xs text-bambu-gray",children:[Ye.entity_id," • ",Ye.state," ",Ye.unit_of_measurement]})]},Ye.entity_id)),Re.length===0&&a.jsx("div",{className:"px-3 py-2 text-sm text-bambu-gray",children:"No matching sensors"})]})]})})()]})]})]}),i==="mqtt"&&a.jsxs("div",{className:"space-y-3",children:[!or?.mqtt_broker&&a.jsxs("div",{className:"p-3 bg-yellow-500/20 border border-yellow-500/50 rounded-lg text-sm text-yellow-400",children:["MQTT broker not configured. Set broker address in"," ",a.jsx("span",{className:"font-medium",children:"Settings → Network → MQTT Publishing"})," ","(you don't need to enable publishing, just fill in the broker details)."]}),or?.mqtt_broker&&a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"p-3 bg-blue-500/10 border border-blue-500/30 rounded-lg text-sm text-blue-300",children:[a.jsx("p",{className:"font-medium mb-1",children:"Monitor Only"}),a.jsx("p",{className:"text-xs opacity-80",children:"MQTT plugs receive power/energy data via MQTT subscription. On/off control is not available - use your MQTT broker or home automation system."})]}),a.jsxs("div",{className:"space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[a.jsx("p",{className:"text-white font-medium text-sm",children:"Power Monitoring"}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Topic"}),a.jsx("input",{type:"text",value:x,onChange:_e=>y(_e.target.value),placeholder:"zigbee2mqtt/shelly-working-room",className:"w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"})]}),a.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"JSON Path"}),a.jsx("input",{type:"text",value:S,onChange:_e=>N(_e.target.value),placeholder:"power_l1",className:"w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Multiplier"}),a.jsx("input",{type:"text",value:A,onChange:_e=>k(_e.target.value),placeholder:"1",className:"w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"})]})]}),a.jsxs("p",{className:"text-xs text-bambu-gray",children:['JSON path extracts value from JSON payload (e.g., "power_l1"). Leave empty if topic publishes raw numeric values.',a.jsx("br",{}),"Use multiplier 0.001 for mW→W, 1000 for kW→W."]})]}),a.jsxs("div",{className:"space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[a.jsxs("p",{className:"text-white font-medium text-sm",children:["Energy Monitoring ",a.jsx("span",{className:"text-bambu-gray font-normal",children:"(optional)"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Topic"}),a.jsx("input",{type:"text",value:C,onChange:_e=>E(_e.target.value),placeholder:"Same as power topic, or different",className:"w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"})]}),a.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"JSON Path"}),a.jsx("input",{type:"text",value:P,onChange:_e=>T(_e.target.value),placeholder:"energy_l1",className:"w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Multiplier"}),a.jsx("input",{type:"text",value:j,onChange:_e=>z(_e.target.value),placeholder:"1",className:"w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"})]})]}),a.jsxs("p",{className:"text-xs text-bambu-gray",children:["JSON path extracts value from JSON payload. Leave empty for raw values.",a.jsx("br",{}),"Use multiplier 0.001 for Wh→kWh, 1000 for MWh→kWh."]})]}),a.jsxs("div",{className:"space-y-3 p-3 bg-bambu-dark rounded-lg border border-bambu-dark-tertiary",children:[a.jsxs("p",{className:"text-white font-medium text-sm",children:["State Monitoring ",a.jsx("span",{className:"text-bambu-gray font-normal",children:"(optional)"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Topic"}),a.jsx("input",{type:"text",value:L,onChange:_e=>B(_e.target.value),placeholder:"Same as power topic, or different",className:"w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"})]}),a.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"JSON Path"}),a.jsx("input",{type:"text",value:R,onChange:_e=>$(_e.target.value),placeholder:"state_l1",className:"w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"ON Value"}),a.jsx("input",{type:"text",value:q,onChange:_e=>I(_e.target.value),placeholder:"ON, true, 1",className:"w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"})]})]}),a.jsxs("p",{className:"text-xs text-bambu-gray",children:["JSON path extracts value from JSON payload. Leave empty for raw values.",a.jsx("br",{}),'ON value: the exact string that means "ON". Leave empty for auto-detect (ON, true, 1).']})]})]})]}),i==="tasmota"&&a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"IP Address *"}),a.jsxs("div",{className:"flex gap-2",children:[a.jsx("input",{type:"text",value:c,onChange:_e=>{u(_e.target.value),se(null)},placeholder:"192.168.1.100",className:"flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"}),a.jsxs(ke,{type:"button",variant:"secondary",onClick:()=>ht.mutate(),disabled:!c.trim()||ht.isPending,children:[ht.isPending?a.jsx(ut,{className:"w-4 h-4 animate-spin"}):a.jsx(Fg,{className:"w-4 h-4"}),"Test"]})]})]}),i==="tasmota"&&ye&&a.jsx("div",{className:`p-3 rounded-lg flex items-center gap-2 ${ye.success?"bg-bambu-green/20 border border-bambu-green/50 text-bambu-green":"bg-red-500/20 border border-red-500/50 text-red-400"}`,children:ye.success?a.jsxs(a.Fragment,{children:[a.jsx(Nr,{className:"w-5 h-5"}),a.jsxs("div",{children:[a.jsx("p",{className:"font-medium",children:"Connected!"}),a.jsxs("p",{className:"text-sm opacity-80",children:[ye.device_name&&`Device: ${ye.device_name} - `,"State: ",ye.state]})]})]}):a.jsxs(a.Fragment,{children:[a.jsx(_m,{className:"w-5 h-5"}),a.jsx("span",{children:"Connection failed"})]})}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Name *"}),a.jsx("input",{type:"text",value:o,onChange:_e=>l(_e.target.value),placeholder:"Living Room Plug",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),i==="tasmota"&&a.jsxs(a.Fragment,{children:[a.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Username"}),a.jsx("input",{type:"text",value:d,onChange:_e=>h(_e.target.value),placeholder:"admin",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Password"}),a.jsx("input",{type:"password",value:m,onChange:_e=>p(_e.target.value),placeholder:"********",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]})]}),a.jsx("p",{className:"text-xs text-bambu-gray -mt-2",children:"Leave empty if your Tasmota device doesn't require authentication"})]}),i!=="mqtt"&&a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Link to Printer"}),a.jsxs("select",{value:le??"",onChange:_e=>we(_e.target.value?Number(_e.target.value):null),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[a.jsx("option",{value:"",children:"No printer (manual control only)"}),he?.map(_e=>a.jsx("option",{value:_e.id,children:_e.name},_e.id))]}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Linking enables automatic on/off when prints start/complete"})]}),a.jsxs("div",{className:"border-t border-bambu-dark-tertiary pt-4",children:[a.jsxs("div",{className:"flex items-center justify-between mb-3",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(Og,{className:"w-4 h-4 text-bambu-green"}),a.jsx("span",{className:"text-white font-medium",children:"Power Alerts"})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:tt,onChange:_e=>Ue(_e.target.checked),className:"sr-only peer"}),a.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),tt&&a.jsxs("div",{className:"space-y-3",children:[a.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Alert if above (W)"}),a.jsx("input",{type:"number",value:xe,onChange:_e=>Te(_e.target.value),placeholder:"e.g. 200",min:"0",max:"5000",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Alert if below (W)"}),a.jsx("input",{type:"number",value:Ie,onChange:_e=>Ne(_e.target.value),placeholder:"e.g. 10",min:"0",max:"5000",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]})]}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Get notified when power consumption crosses these thresholds. Leave empty to disable that direction."})]})]}),i!=="mqtt"&&a.jsxs("div",{className:"border-t border-bambu-dark-tertiary pt-4",children:[a.jsxs("div",{className:"flex items-center justify-between mb-3",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(nr,{className:"w-4 h-4 text-bambu-green"}),a.jsx("span",{className:"text-white font-medium",children:"Daily Schedule"})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:Ge,onChange:_e=>Me(_e.target.checked),className:"sr-only peer"}),a.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),Ge&&a.jsxs("div",{className:"space-y-3",children:[a.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Turn On at"}),a.jsx("input",{type:"time",value:rt,onChange:_e=>Ee(_e.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Turn Off at"}),a.jsx("input",{type:"time",value:Ke,onChange:_e=>Be(_e.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]})]}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Automatically turn the plug on/off at these times daily. Leave empty to skip that action."})]})]}),a.jsx("div",{className:"border-t border-bambu-dark-tertiary pt-4",children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(UM,{className:"w-4 h-4 text-bambu-green"}),a.jsxs("div",{children:[a.jsx("span",{className:"text-white font-medium",children:"Show in Switchbar"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Quick access from sidebar"})]})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:ue,onChange:_e=>$e(_e.target.checked),className:"sr-only peer"}),a.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]})}),i==="homeassistant"&&a.jsx("div",{className:"border-t border-bambu-dark-tertiary pt-4",children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(_c,{className:"w-4 h-4 text-bambu-green"}),a.jsxs("div",{children:[a.jsx("span",{className:"text-white font-medium",children:"Show on Printer Card"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Display button on printer card"})]})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:at,onChange:_e=>kt(_e.target.checked),className:"sr-only peer"}),a.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]})}),a.jsxs("div",{className:"flex gap-3 pt-2",children:[a.jsx(ke,{type:"button",variant:"secondary",onClick:e,className:"flex-1",children:"Cancel"}),a.jsxs(ke,{type:"submit",disabled:Ve,className:"flex-1",children:[Ve?a.jsx(ut,{className:"w-4 h-4 animate-spin"}):a.jsx(gs,{className:"w-4 h-4"}),r?"Save":"Add"]})]})]})]})})}function $n({checked:t,onChange:e,disabled:n}){const r=i=>{i.preventDefault(),i.stopPropagation(),n||e(!t)};return a.jsx("button",{type:"button",role:"switch","aria-checked":t,disabled:n,onClick:r,className:`relative inline-flex w-11 h-7 md:w-9 md:h-5 rounded-full transition-colors flex-shrink-0 focus:outline-none focus:ring-2 focus:ring-bambu-green focus:ring-offset-2 focus:ring-offset-bambu-dark ${n?"bg-bambu-dark-tertiary/50 cursor-not-allowed opacity-50":t?"bg-bambu-green cursor-pointer":"bg-bambu-dark-tertiary cursor-pointer hover:bg-bambu-dark-tertiary/80"}`,children:a.jsx("span",{className:`pointer-events-none absolute top-[3px] md:top-[2px] left-[3px] md:left-[2px] w-5 h-5 md:w-4 md:h-4 bg-white rounded-full shadow transition-transform duration-200 ease-in-out ${t?"translate-x-4":"translate-x-0"}`})})}const GYe={callmebot:"CallMeBot/WhatsApp",ntfy:"ntfy",pushover:"Pushover",telegram:"Telegram",email:"Email",discord:"Discord",webhook:"Webhook"};function qYe({provider:t,onEdit:e}){const n=un(),[r,i]=_.useState(!1),[s,o]=_.useState(!1),[l,c]=_.useState(null),{data:u}=st({queryKey:["printers"],queryFn:ce.getPrinters}),d=u?.find(v=>v.id===t.printer_id),h=pt({mutationFn:v=>ce.updateNotificationProvider(t.id,v),onSuccess:()=>{n.invalidateQueries({queryKey:["notification-providers"]})}}),m=pt({mutationFn:()=>ce.deleteNotificationProvider(t.id),onSuccess:()=>{n.invalidateQueries({queryKey:["notification-providers"]})}}),p=pt({mutationFn:()=>ce.testNotificationProvider(t.id),onSuccess:v=>{c(v),n.invalidateQueries({queryKey:["notification-providers"]})},onError:v=>{c({success:!1,message:v.message})}}),b=v=>v||"";return a.jsxs(a.Fragment,{children:[a.jsx(_t,{className:"relative",children:a.jsxs(Mt,{className:"p-4",children:[a.jsxs("div",{className:"flex items-start justify-between mb-3",children:[a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx("div",{className:`p-2 rounded-lg ${t.enabled?"bg-bambu-green/20":"bg-bambu-dark"}`,children:a.jsx(Og,{className:`w-5 h-5 ${t.enabled?"text-bambu-green":"text-bambu-gray"}`})}),a.jsxs("div",{children:[a.jsx("h3",{className:"font-medium text-white",children:t.name}),a.jsx("p",{className:"text-sm text-bambu-gray",children:GYe[t.provider_type]||t.provider_type})]})]}),a.jsxs("div",{className:"flex items-center gap-3",children:[t.last_success&&a.jsxs("span",{className:"text-xs text-status-ok hidden sm:inline",children:["Last: ",tb(t.last_success)]}),t.last_error&&t.last_error_at&&(!t.last_success||(Hi(t.last_error_at)?.getTime()||0)>(Hi(t.last_success)?.getTime()||0))&&a.jsx("span",{className:"text-xs text-status-error",title:t.last_error,children:"Error"}),a.jsx($n,{checked:t.enabled,onChange:v=>h.mutate({enabled:v})})]})]}),d&&a.jsxs("div",{className:"mb-3 px-2 py-1.5 bg-bambu-dark rounded-lg",children:[a.jsx("span",{className:"text-xs text-bambu-gray",children:"Printer: "}),a.jsx("span",{className:"text-sm text-white",children:d.name})]}),!d&&!t.printer_id&&a.jsx("div",{className:"mb-3 px-2 py-1.5 bg-bambu-dark rounded-lg",children:a.jsx("span",{className:"text-xs text-bambu-gray",children:"All printers"})}),a.jsxs("div",{className:"mb-3 flex flex-wrap gap-1",children:[t.on_print_start&&a.jsx("span",{className:"px-2 py-0.5 bg-blue-500/20 text-blue-400 text-xs rounded",children:"Start"}),t.on_plate_not_empty&&a.jsx("span",{className:"px-2 py-0.5 bg-rose-600/20 text-rose-300 text-xs rounded",children:"Plate Check"}),t.on_print_complete&&a.jsx("span",{className:"px-2 py-0.5 bg-bambu-green/20 text-bambu-green text-xs rounded",children:"Complete"}),t.on_print_failed&&a.jsx("span",{className:"px-2 py-0.5 bg-red-500/20 text-red-400 text-xs rounded",children:"Failed"}),t.on_print_stopped&&a.jsx("span",{className:"px-2 py-0.5 bg-orange-500/20 text-orange-400 text-xs rounded",children:"Stopped"}),t.on_print_progress&&a.jsx("span",{className:"px-2 py-0.5 bg-yellow-500/20 text-yellow-400 text-xs rounded",children:"Progress"}),t.on_printer_offline&&a.jsx("span",{className:"px-2 py-0.5 bg-gray-500/20 text-gray-400 text-xs rounded",children:"Offline"}),t.on_printer_error&&a.jsx("span",{className:"px-2 py-0.5 bg-rose-500/20 text-rose-400 text-xs rounded",children:"Error"}),t.on_filament_low&&a.jsx("span",{className:"px-2 py-0.5 bg-cyan-500/20 text-cyan-400 text-xs rounded",children:"Low Filament"}),t.on_maintenance_due&&a.jsx("span",{className:"px-2 py-0.5 bg-purple-500/20 text-purple-400 text-xs rounded",children:"Maintenance"}),t.on_ams_humidity_high&&a.jsx("span",{className:"px-2 py-0.5 bg-blue-600/20 text-blue-300 text-xs rounded",children:"AMS Humidity"}),t.on_ams_temperature_high&&a.jsx("span",{className:"px-2 py-0.5 bg-orange-600/20 text-orange-300 text-xs rounded",children:"AMS Temp"}),t.on_ams_ht_humidity_high&&a.jsx("span",{className:"px-2 py-0.5 bg-cyan-600/20 text-cyan-300 text-xs rounded",children:"AMS-HT Humidity"}),t.on_ams_ht_temperature_high&&a.jsx("span",{className:"px-2 py-0.5 bg-amber-600/20 text-amber-300 text-xs rounded",children:"AMS-HT Temp"}),t.quiet_hours_enabled&&a.jsxs("span",{className:"px-2 py-0.5 bg-indigo-500/20 text-indigo-400 text-xs rounded flex items-center gap-1",children:[a.jsx(hS,{className:"w-3 h-3"}),"Quiet"]}),t.daily_digest_enabled&&a.jsxs("span",{className:"px-2 py-0.5 bg-emerald-500/20 text-emerald-400 text-xs rounded flex items-center gap-1",children:[a.jsx(ei,{className:"w-3 h-3"}),"Digest ",t.daily_digest_time]})]}),a.jsx("div",{className:"mb-3",children:a.jsxs(ke,{size:"sm",variant:"secondary",disabled:p.isPending,onClick:()=>{c(null),p.mutate()},className:"w-full",children:[p.isPending?a.jsx(ut,{className:"w-4 h-4 animate-spin"}):a.jsx($M,{className:"w-4 h-4"}),"Send Test Notification"]})}),l&&a.jsxs("div",{className:`mb-3 p-2 rounded-lg flex items-center gap-2 text-sm ${l.success?"bg-bambu-green/20 text-bambu-green":"bg-red-500/20 text-red-400"}`,children:[l.success?a.jsx(Nr,{className:"w-4 h-4"}):a.jsx(ta,{className:"w-4 h-4"}),a.jsx("span",{children:l.message})]}),a.jsxs("button",{onClick:()=>o(!s),className:"w-full flex items-center justify-between py-2 text-sm text-bambu-gray hover:text-white transition-colors border-t border-bambu-dark-tertiary",children:[a.jsxs("span",{className:"flex items-center gap-2",children:[a.jsx(jh,{className:"w-4 h-4"}),"Event Settings"]}),s?a.jsx(Ch,{className:"w-4 h-4"}):a.jsx(Sr,{className:"w-4 h-4"})]}),s&&a.jsxs("div",{className:"pt-3 border-t border-bambu-dark-tertiary space-y-4",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"Enabled"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Send notifications from this provider"})]}),a.jsx($n,{checked:t.enabled,onChange:v=>h.mutate({enabled:v})})]}),a.jsxs("div",{className:"space-y-2",children:[a.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide",children:"Print Events"}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("p",{className:"text-sm text-white",children:"Print Started"}),a.jsx($n,{checked:t.on_print_start,onChange:v=>h.mutate({on_print_start:v})})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"Plate Not Empty"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Objects detected before print"})]}),a.jsx($n,{checked:t.on_plate_not_empty??!0,onChange:v=>h.mutate({on_plate_not_empty:v})})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("p",{className:"text-sm text-white",children:"Print Completed"}),a.jsx($n,{checked:t.on_print_complete,onChange:v=>h.mutate({on_print_complete:v})})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("p",{className:"text-sm text-white",children:"Print Failed"}),a.jsx($n,{checked:t.on_print_failed,onChange:v=>h.mutate({on_print_failed:v})})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("p",{className:"text-sm text-white",children:"Print Stopped"}),a.jsx($n,{checked:t.on_print_stopped,onChange:v=>h.mutate({on_print_stopped:v})})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"Progress Milestones"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Notify at 25%, 50%, 75%"})]}),a.jsx($n,{checked:t.on_print_progress,onChange:v=>h.mutate({on_print_progress:v})})]})]}),a.jsxs("div",{className:"space-y-2",children:[a.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide",children:"Printer Status"}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("p",{className:"text-sm text-white",children:"Printer Offline"}),a.jsx($n,{checked:t.on_printer_offline,onChange:v=>h.mutate({on_printer_offline:v})})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("p",{className:"text-sm text-white",children:"Printer Error"}),a.jsx($n,{checked:t.on_printer_error,onChange:v=>h.mutate({on_printer_error:v})})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("p",{className:"text-sm text-white",children:"Low Filament"}),a.jsx($n,{checked:t.on_filament_low,onChange:v=>h.mutate({on_filament_low:v})})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"Maintenance Due"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Notify when maintenance is needed"})]}),a.jsx($n,{checked:t.on_maintenance_due??!1,onChange:v=>h.mutate({on_maintenance_due:v})})]})]}),a.jsxs("div",{className:"space-y-2",children:[a.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide",children:"AMS Alarms"}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"AMS Humidity High"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Regular AMS humidity exceeds threshold"})]}),a.jsx($n,{checked:t.on_ams_humidity_high??!1,onChange:v=>h.mutate({on_ams_humidity_high:v})})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"AMS Temperature High"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Regular AMS temperature exceeds threshold"})]}),a.jsx($n,{checked:t.on_ams_temperature_high??!1,onChange:v=>h.mutate({on_ams_temperature_high:v})})]})]}),a.jsxs("div",{className:"space-y-2",children:[a.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide",children:"AMS-HT Alarms"}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"AMS-HT Humidity High"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"AMS-HT humidity exceeds threshold"})]}),a.jsx($n,{checked:t.on_ams_ht_humidity_high??!1,onChange:v=>h.mutate({on_ams_ht_humidity_high:v})})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"AMS-HT Temperature High"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"AMS-HT temperature exceeds threshold"})]}),a.jsx($n,{checked:t.on_ams_ht_temperature_high??!1,onChange:v=>h.mutate({on_ams_ht_temperature_high:v})})]})]}),a.jsxs("div",{className:"space-y-2",children:[a.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide",children:"Print Queue"}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"Job Added"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Job added to queue"})]}),a.jsx($n,{checked:t.on_queue_job_added??!1,onChange:v=>h.mutate({on_queue_job_added:v})})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"Job Assigned"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Model-based job assigned to printer"})]}),a.jsx($n,{checked:t.on_queue_job_assigned??!1,onChange:v=>h.mutate({on_queue_job_assigned:v})})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"Job Started"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Queue job started printing"})]}),a.jsx($n,{checked:t.on_queue_job_started??!1,onChange:v=>h.mutate({on_queue_job_started:v})})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"Job Waiting"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Job waiting for filament"})]}),a.jsx($n,{checked:t.on_queue_job_waiting??!0,onChange:v=>h.mutate({on_queue_job_waiting:v})})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"Job Skipped"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Job skipped (previous failed)"})]}),a.jsx($n,{checked:t.on_queue_job_skipped??!0,onChange:v=>h.mutate({on_queue_job_skipped:v})})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"Job Failed"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Job failed to start"})]}),a.jsx($n,{checked:t.on_queue_job_failed??!0,onChange:v=>h.mutate({on_queue_job_failed:v})})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"Queue Complete"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"All queue jobs finished"})]}),a.jsx($n,{checked:t.on_queue_completed??!1,onChange:v=>h.mutate({on_queue_completed:v})})]})]}),a.jsxs("div",{className:"space-y-2",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(hS,{className:"w-4 h-4 text-purple-400"}),a.jsx("p",{className:"text-sm text-white",children:"Quiet Hours"})]}),a.jsx($n,{checked:t.quiet_hours_enabled,onChange:v=>h.mutate({quiet_hours_enabled:v})})]}),t.quiet_hours_enabled&&a.jsxs("div",{className:"pl-4 border-l-2 border-bambu-dark-tertiary space-y-2",children:[a.jsx("p",{className:"text-xs text-bambu-gray",children:"No notifications during these hours"}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(nr,{className:"w-4 h-4 text-bambu-gray"}),a.jsxs("span",{className:"text-sm text-white",children:[b(t.quiet_hours_start)||"22:00"," - ",b(t.quiet_hours_end)||"07:00"]})]}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Edit provider to change quiet hours"})]})]}),a.jsxs("div",{className:"space-y-2",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(ei,{className:"w-4 h-4 text-emerald-400"}),a.jsx("p",{className:"text-sm text-white",children:"Daily Digest"})]}),a.jsx($n,{checked:t.daily_digest_enabled,onChange:v=>h.mutate({daily_digest_enabled:v})})]}),t.daily_digest_enabled&&a.jsxs("div",{className:"pl-4 border-l-2 border-bambu-dark-tertiary space-y-2",children:[a.jsx("p",{className:"text-xs text-bambu-gray",children:"Batch notifications into a single daily summary"}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(nr,{className:"w-4 h-4 text-bambu-gray"}),a.jsxs("span",{className:"text-sm text-white",children:["Send at ",b(t.daily_digest_time)||"08:00"]})]}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Edit provider to change digest time"})]})]}),a.jsxs("div",{className:"flex gap-2 pt-2",children:[a.jsxs(ke,{size:"sm",variant:"secondary",onClick:()=>e(t),className:"flex-1",children:[a.jsx(Eg,{className:"w-4 h-4"}),"Edit"]}),a.jsx(ke,{size:"sm",variant:"secondary",onClick:()=>i(!0),className:"text-red-400 hover:text-red-300",children:a.jsx(cn,{className:"w-4 h-4"})})]})]})]})}),r&&a.jsx(er,{title:"Delete Notification Provider",message:`Are you sure you want to delete "${t.name}"? This cannot be undone.`,confirmText:"Delete",variant:"danger",onConfirm:()=>{m.mutate(),i(!1)},onCancel:()=>i(!1)})]})}const DW=[{value:"email",label:"Email",description:"SMTP email notifications"},{value:"telegram",label:"Telegram",description:"Notifications via Telegram bot"},{value:"discord",label:"Discord",description:"Send to Discord channel via webhook"},{value:"ntfy",label:"ntfy",description:"Free, self-hostable push notifications"},{value:"pushover",label:"Pushover",description:"Simple, reliable push notifications"},{value:"callmebot",label:"CallMeBot/WhatsApp",description:"Free WhatsApp notifications via CallMeBot"},{value:"webhook",label:"Webhook",description:"Generic HTTP POST to any URL"}];function WYe({provider:t,onClose:e}){const n=un(),r=!!t,[i,s]=_.useState(t?.name||""),[o,l]=_.useState(t?.provider_type||"email"),[c,u]=_.useState(t?.printer_id||null),[d,h]=_.useState(t?.quiet_hours_enabled||!1),[m,p]=_.useState(t?.quiet_hours_start||"22:00"),[b,v]=_.useState(t?.quiet_hours_end||"07:00"),[x,y]=_.useState(t?.daily_digest_enabled||!1),[S,N]=_.useState(t?.daily_digest_time||"08:00"),[A,k]=_.useState(t?.on_print_start??!1),[C,E]=_.useState(t?.on_print_complete??!0),[P,T]=_.useState(t?.on_print_failed??!0),[j,z]=_.useState(t?.on_print_stopped??!0),[L,B]=_.useState(t?.on_print_progress??!1),[R,$]=_.useState(t?.on_printer_offline??!1),[q,I]=_.useState(t?.on_printer_error??!1),[G,Y]=_.useState(t?.on_filament_low??!1),[re,H]=_.useState(t?.on_maintenance_due??!1),[K,ne]=_.useState(t?.config?Object.fromEntries(Object.entries(t.config).map(([X,te])=>[X,String(te)])):{}),[ie,be]=_.useState(null),[pe,de]=_.useState(null),{data:Ce}=st({queryKey:["printers"],queryFn:ce.getPrinters});_.useEffect(()=>{const X=te=>{te.key==="Escape"&&e()};return window.addEventListener("keydown",X),()=>window.removeEventListener("keydown",X)},[e]);const ae=pt({mutationFn:()=>ce.testNotificationConfig({provider_type:o,config:K}),onSuccess:X=>{be(X),de(null)},onError:X=>{be({success:!1,message:X.message})}}),Ae=pt({mutationFn:X=>ce.createNotificationProvider(X),onSuccess:()=>{n.invalidateQueries({queryKey:["notification-providers"]}),e()},onError:X=>{de(X.message)}}),Le=pt({mutationFn:X=>ce.updateNotificationProvider(t.id,X),onSuccess:()=>{n.invalidateQueries({queryKey:["notification-providers"]}),e()},onError:X=>{de(X.message)}}),fe=X=>{if(X.preventDefault(),de(null),!i.trim()){de("Name is required");return}const te=Q(o);for(const ge of te)if(!K[ge.key]?.trim()){de(`${ge.label} is required`);return}const V={name:i.trim(),provider_type:o,config:K,printer_id:c,quiet_hours_enabled:d,quiet_hours_start:d?m:null,quiet_hours_end:d?b:null,daily_digest_enabled:x,daily_digest_time:x?S:null,on_print_start:A,on_print_complete:C,on_print_failed:P,on_print_stopped:j,on_print_progress:L,on_printer_offline:R,on_printer_error:q,on_filament_low:G,on_maintenance_due:re};r?Le.mutate(V):Ae.mutate(V)},Xe=Ae.isPending||Le.isPending,W=X=>{switch(X){case"callmebot":return[{key:"phone",label:"Phone Number",placeholder:"+1234567890",type:"text",required:!0},{key:"apikey",label:"API Key",placeholder:"Your CallMeBot API key",type:"text",required:!0}];case"ntfy":return[{key:"server",label:"Server URL",placeholder:"https://ntfy.sh",type:"text",required:!1},{key:"topic",label:"Topic",placeholder:"my-bambuddy",type:"text",required:!0},{key:"auth_token",label:"Auth Token",placeholder:"Optional authentication",type:"password",required:!1}];case"pushover":return[{key:"user_key",label:"User Key",placeholder:"Your Pushover user key",type:"text",required:!0},{key:"app_token",label:"App Token",placeholder:"Your Pushover app token",type:"text",required:!0},{key:"priority",label:"Priority",placeholder:"0 (normal)",type:"number",required:!1}];case"telegram":return[{key:"bot_token",label:"Bot Token",placeholder:"Bot token from @BotFather",type:"password",required:!0},{key:"chat_id",label:"Chat ID",placeholder:"Your chat or group ID",type:"text",required:!0}];case"email":return[{key:"smtp_server",label:"SMTP Server",placeholder:"smtp.gmail.com",type:"text",required:!0},{key:"smtp_port",label:"SMTP Port",placeholder:"587",type:"number",required:!1},{key:"security",label:"Security",type:"select",required:!1,options:[{value:"starttls",label:"STARTTLS (Port 587)"},{value:"ssl",label:"SSL/TLS (Port 465)"},{value:"none",label:"None (Port 25)"}]},{key:"auth_enabled",label:"Authentication",type:"select",required:!1,options:[{value:"true",label:"Enabled"},{value:"false",label:"Disabled"}]},{key:"username",label:"Username",placeholder:"your@email.com",type:"text",required:!1},{key:"password",label:"Password",placeholder:"App password",type:"password",required:!1},{key:"from_email",label:"From Email",placeholder:"your@email.com",type:"text",required:!0},{key:"to_email",label:"To Email",placeholder:"recipient@email.com",type:"text",required:!0}];case"discord":return[{key:"webhook_url",label:"Webhook URL",placeholder:"https://discord.com/api/webhooks/...",type:"text",required:!0}];case"webhook":return[{key:"webhook_url",label:"Webhook URL",placeholder:"https://example.com/webhook",type:"text",required:!0},{key:"payload_format",label:"Payload Format",type:"select",required:!1,options:[{value:"generic",label:"Generic JSON"},{value:"slack",label:"Slack / Mattermost"}]},{key:"auth_header",label:"Authorization",placeholder:"Bearer token (optional)",type:"password",required:!1},{key:"field_title",label:"Title Field Name",placeholder:"title",type:"text",required:!1,showIf:te=>te.payload_format!=="slack"},{key:"field_message",label:"Message Field Name",placeholder:"message",type:"text",required:!1,showIf:te=>te.payload_format!=="slack"}];default:return[]}},Q=X=>W(X).filter(te=>te.required),me=W(o);return a.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4 overflow-y-auto",onClick:e,children:a.jsxs("div",{className:"bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-lg my-8 max-h-[90vh] overflow-y-auto",onClick:X=>X.stopPropagation(),children:[a.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary",children:[a.jsx("h2",{className:"text-lg font-semibold text-white",children:r?"Edit Notification Provider":"Add Notification Provider"}),a.jsx("button",{onClick:e,className:"text-bambu-gray hover:text-white transition-colors",children:a.jsx(Lt,{className:"w-5 h-5"})})]}),a.jsxs("form",{onSubmit:fe,className:"p-6 space-y-4",children:[pe&&a.jsx("div",{className:"p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400",children:pe}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Name *"}),a.jsx("input",{type:"text",value:i,onChange:X=>s(X.target.value),placeholder:"My Notifications",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Provider Type *"}),a.jsx("select",{value:o,onChange:X=>{l(X.target.value),ne({}),be(null)},disabled:r,className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none disabled:opacity-50",children:DW.map(X=>a.jsx("option",{value:X.value,children:X.label},X.value))}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:DW.find(X=>X.value===o)?.description})]}),a.jsxs("div",{className:"space-y-3",children:[a.jsx("p",{className:"text-sm text-bambu-gray",children:"Configuration"}),me.filter(X=>!("showIf"in X)||X.showIf?.(K)!==!1).map(X=>a.jsxs("div",{children:[a.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[X.label," ",X.required&&"*"]}),X.type==="select"&&"options"in X&&X.options?a.jsx("select",{value:K[X.key]||X.options[0]?.value||"",onChange:te=>{ne({...K,[X.key]:te.target.value}),be(null)},className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:X.options.map(te=>a.jsx("option",{value:te.value,children:te.label},te.value))}):a.jsx("input",{type:X.type,value:K[X.key]||"",onChange:te=>{ne({...K,[X.key]:te.target.value}),be(null)},placeholder:X.placeholder,className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]},X.key))]}),a.jsx("div",{className:"flex gap-2",children:a.jsxs(ke,{type:"button",variant:"secondary",onClick:()=>{be(null),ae.mutate()},disabled:ae.isPending||!K[Q(o)[0]?.key],className:"flex-1",children:[ae.isPending?a.jsx(ut,{className:"w-4 h-4 animate-spin"}):a.jsx($M,{className:"w-4 h-4"}),"Test Configuration"]})}),ie&&a.jsx("div",{className:`p-3 rounded-lg flex items-center gap-2 ${ie.success?"bg-bambu-green/20 border border-bambu-green/50 text-bambu-green":"bg-red-500/20 border border-red-500/50 text-red-400"}`,children:ie.success?a.jsxs(a.Fragment,{children:[a.jsx(Nr,{className:"w-5 h-5"}),a.jsx("span",{children:ie.message})]}):a.jsxs(a.Fragment,{children:[a.jsx(ta,{className:"w-5 h-5"}),a.jsx("span",{children:ie.message})]})}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Printer Filter"}),a.jsxs("select",{value:c??"",onChange:X=>u(X.target.value?Number(X.target.value):null),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[a.jsx("option",{value:"",children:"All printers"}),Ce?.map(X=>a.jsx("option",{value:X.id,children:X.name},X.id))]}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Only send notifications for events from this printer"})]}),a.jsxs("div",{className:"space-y-2",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("label",{className:"text-sm text-white",children:"Quiet Hours (Do Not Disturb)"}),a.jsx($n,{checked:d,onChange:h})]}),d&&a.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Start"}),a.jsx("input",{type:"time",value:m,onChange:X=>p(X.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"End"}),a.jsx("input",{type:"time",value:b,onChange:X=>v(X.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]})]})]}),a.jsxs("div",{className:"space-y-2",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("label",{className:"text-sm text-white",children:"Daily Digest"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Batch notifications into a single daily summary"})]}),a.jsx($n,{checked:x,onChange:y})]}),x&&a.jsxs("div",{children:[a.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Send digest at"}),a.jsx("input",{type:"time",value:S,onChange:X=>N(X.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Events will be collected and sent as a single summary at this time"})]})]}),a.jsxs("div",{className:"space-y-3",children:[a.jsx("p",{className:"text-sm text-bambu-gray",children:"Notification Events"}),a.jsxs("div",{className:"space-y-2 p-3 bg-bambu-dark rounded-lg",children:[a.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide mb-2",children:"Print Events"}),a.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("span",{className:"text-sm text-white",children:"Start"}),a.jsx($n,{checked:A,onChange:k})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("span",{className:"text-sm text-white",children:"Complete"}),a.jsx($n,{checked:C,onChange:E})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("span",{className:"text-sm text-white",children:"Failed"}),a.jsx($n,{checked:P,onChange:T})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("span",{className:"text-sm text-white",children:"Stopped"}),a.jsx($n,{checked:j,onChange:z})]}),a.jsxs("div",{className:"flex items-center justify-between col-span-2",children:[a.jsxs("div",{children:[a.jsx("span",{className:"text-sm text-white",children:"Progress"}),a.jsx("span",{className:"text-xs text-bambu-gray ml-1",children:"(25%, 50%, 75%)"})]}),a.jsx($n,{checked:L,onChange:B})]})]})]}),a.jsxs("div",{className:"space-y-2 p-3 bg-bambu-dark rounded-lg",children:[a.jsx("p",{className:"text-xs text-bambu-gray uppercase tracking-wide mb-2",children:"Printer Status"}),a.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("span",{className:"text-sm text-white",children:"Offline"}),a.jsx($n,{checked:R,onChange:$})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("span",{className:"text-sm text-white",children:"Error"}),a.jsx($n,{checked:q,onChange:I})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("span",{className:"text-sm text-white",children:"Low Filament"}),a.jsx($n,{checked:G,onChange:Y})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsx("span",{className:"text-sm text-white",children:"Maintenance"}),a.jsx($n,{checked:re,onChange:H})]})]})]})]}),a.jsxs("div",{className:"flex gap-3 pt-2",children:[a.jsx(ke,{type:"button",variant:"secondary",onClick:e,className:"flex-1",children:"Cancel"}),a.jsxs(ke,{type:"submit",disabled:Xe,className:"flex-1",children:[Xe?a.jsx(ut,{className:"w-4 h-4 animate-spin"}):a.jsx(gs,{className:"w-4 h-4"}),r?"Save":"Add"]})]})]})]})})}function KYe({template:t,onClose:e}){const n=un(),r=_.useRef(null),[i,s]=_.useState(t.title_template),[o,l]=_.useState(t.body_template),[c,u]=_.useState(null),[d,h]=_.useState(!0),{data:m}=st({queryKey:["template-variables"],queryFn:ce.getTemplateVariables}),p=m?.find(k=>k.event_type===t.event_type),{data:b,isLoading:v}=st({queryKey:["template-preview",t.event_type,i,o],queryFn:()=>ce.previewTemplate({event_type:t.event_type,title_template:i,body_template:o}),enabled:d&&i.length>0&&o.length>0});_.useEffect(()=>{const k=C=>{C.key==="Escape"&&e()};return window.addEventListener("keydown",k),()=>window.removeEventListener("keydown",k)},[e]);const x=pt({mutationFn:k=>ce.updateNotificationTemplate(t.id,k),onSuccess:()=>{n.invalidateQueries({queryKey:["notification-templates"]}),e()},onError:k=>{u(k.message)}}),y=pt({mutationFn:()=>ce.resetNotificationTemplate(t.id),onSuccess:k=>{s(k.title_template),l(k.body_template),n.invalidateQueries({queryKey:["notification-templates"]})},onError:k=>{u(k.message)}}),S=k=>{if(k.preventDefault(),u(null),!i.trim()){u("Title is required");return}if(!o.trim()){u("Body is required");return}x.mutate({title_template:i,body_template:o})},N=k=>{const C=r.current;if(!C)return;const E=C.selectionStart,P=C.selectionEnd,T=o,j=T.substring(0,E),z=T.substring(P),L=j+`{${k}}`+z;l(L),setTimeout(()=>{C.focus();const B=E+k.length+2;C.setSelectionRange(B,B)},0)},A=i!==t.title_template||o!==t.body_template;return a.jsx("div",{className:"fixed inset-0 bg-black/80 flex items-center justify-center z-50 p-4",children:a.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg w-full max-w-2xl max-h-[90vh] flex flex-col",children:[a.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary shrink-0",children:[a.jsxs("h2",{className:"text-lg font-semibold text-white",children:["Edit Template: ",t.name]}),a.jsx("button",{onClick:e,className:"p-1 hover:bg-bambu-dark-tertiary rounded transition-colors",children:a.jsx(Lt,{className:"w-5 h-5 text-bambu-gray"})})]}),a.jsxs("form",{onSubmit:S,className:"flex-1 overflow-y-auto p-4 space-y-4",children:[c&&a.jsx("div",{className:"p-3 bg-red-500/20 border border-red-500/50 rounded text-red-400 text-sm",children:c}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:"Title"}),a.jsx("input",{type:"text",value:i,onChange:k=>s(k.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white focus:outline-none focus:ring-1 focus:ring-bambu-green",placeholder:"Notification title..."})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-1",children:"Body"}),a.jsx("textarea",{ref:r,value:o,onChange:k=>l(k.target.value),rows:4,className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white focus:outline-none focus:ring-1 focus:ring-bambu-green font-mono text-sm resize-none",placeholder:"Notification body..."})]}),p&&a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-bambu-gray mb-2",children:"Available Variables"}),a.jsx("div",{className:"flex flex-wrap gap-2",children:p.variables.map(k=>a.jsxs("button",{type:"button",onClick:()=>N(k),className:"inline-flex items-center gap-1 px-2 py-1 bg-bambu-dark hover:bg-bambu-dark-tertiary border border-bambu-dark-tertiary rounded text-xs text-bambu-gray hover:text-white transition-colors",children:[a.jsx(dr,{className:"w-3 h-3"}),k]},k))}),a.jsx("p",{className:"text-xs text-bambu-gray/60 mt-1",children:"Click to insert at cursor position in body"})]}),a.jsxs("div",{children:[a.jsxs("div",{className:"flex items-center justify-between mb-2",children:[a.jsxs("label",{className:"text-sm font-medium text-bambu-gray flex items-center gap-2",children:[a.jsx(_c,{className:"w-4 h-4"}),"Live Preview"]}),a.jsx("button",{type:"button",onClick:()=>h(!d),className:"text-xs text-bambu-green hover:text-bambu-green-light",children:d?"Hide":"Show"})]}),d&&a.jsx("div",{className:"bg-bambu-dark border border-bambu-dark-tertiary rounded p-3 space-y-2",children:v?a.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-sm",children:[a.jsx(ut,{className:"w-4 h-4 animate-spin"}),"Loading preview..."]}):b?a.jsxs(a.Fragment,{children:[a.jsxs("div",{children:[a.jsx("span",{className:"text-xs text-bambu-gray",children:"Title:"}),a.jsx("div",{className:"text-white font-medium",children:b.title})]}),a.jsxs("div",{children:[a.jsx("span",{className:"text-xs text-bambu-gray",children:"Body:"}),a.jsx("div",{className:"text-white whitespace-pre-wrap text-sm",children:b.body})]})]}):a.jsx("div",{className:"text-bambu-gray text-sm",children:"Enter template content to see preview"})})]})]}),a.jsxs("div",{className:"flex items-center justify-between p-4 border-t border-bambu-dark-tertiary shrink-0",children:[a.jsxs(ke,{type:"button",variant:"ghost",onClick:()=>y.mutate(),disabled:y.isPending,className:"text-orange-400 hover:text-orange-300",children:[y.isPending?a.jsx(ut,{className:"w-4 h-4 animate-spin mr-2"}):a.jsx($h,{className:"w-4 h-4 mr-2"}),"Reset to Default"]}),a.jsxs("div",{className:"flex gap-2",children:[a.jsx(ke,{type:"button",variant:"secondary",onClick:e,children:"Cancel"}),a.jsxs(ke,{onClick:S,disabled:x.isPending||!A,children:[x.isPending?a.jsx(ut,{className:"w-4 h-4 animate-spin mr-2"}):a.jsx(gs,{className:"w-4 h-4 mr-2"}),"Save"]})]})]})]})})}const XYe={print_start:"Print Started",print_complete:"Print Complete",print_failed:"Print Failed",print_stopped:"Print Stopped",print_progress:"Progress",printer_offline:"Printer Offline",printer_error:"Printer Error",filament_low:"Low Filament",maintenance_due:"Maintenance Due",test:"Test"},YYe={print_start:"text-blue-400",print_complete:"text-bambu-green",print_failed:"text-red-400",print_stopped:"text-orange-400",print_progress:"text-yellow-400",printer_offline:"text-gray-400",printer_error:"text-rose-400",filament_low:"text-cyan-400",maintenance_due:"text-purple-400",test:"text-bambu-gray"};function QYe({onClose:t}){const e=un(),{showToast:n}=Hn(),[r,i]=_.useState(7),[s,o]=_.useState(null),[l,c]=_.useState(!1),{data:u}=st({queryKey:["settings"],queryFn:ce.getSettings}),d=u?.time_format||"system",{data:h,isLoading:m,refetch:p,isRefetching:b}=st({queryKey:["notification-logs",r,l],queryFn:()=>ce.getNotificationLogs({days:r,limit:100,success:l?!1:void 0})}),{data:v}=st({queryKey:["notification-log-stats",r],queryFn:()=>ce.getNotificationLogStats(r)}),x=pt({mutationFn:()=>ce.clearNotificationLogs(30),onSuccess:S=>{n(S.message,"success"),e.invalidateQueries({queryKey:["notification-logs"]}),e.invalidateQueries({queryKey:["notification-log-stats"]})},onError:S=>{n(`Failed to clear logs: ${S.message}`,"error")}}),y=S=>{const N=Hi(S);if(!N)return"";const k=new Date().getTime()-N.getTime();return k<6e4?"Just now":k<36e5?`${Math.floor(k/6e4)}m ago`:k<864e5?`${Math.floor(k/36e5)}h ago`:N.toLocaleDateString()+" "+cpe(N,d)};return a.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:a.jsxs("div",{className:"bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg w-full max-w-3xl max-h-[85vh] flex flex-col",children:[a.jsxs("div",{className:"p-4 border-b border-bambu-dark-tertiary flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx(sy,{className:"w-5 h-5 text-bambu-green"}),a.jsx("h2",{className:"text-lg font-semibold text-white",children:"Notification Log"})]}),a.jsx("button",{onClick:t,className:"text-bambu-gray hover:text-white transition-colors",children:"×"})]}),v&&a.jsx("div",{className:"px-4 py-3 border-b border-bambu-dark-tertiary bg-bambu-dark/50",children:a.jsxs("div",{className:"flex items-center gap-6 text-sm",children:[a.jsxs("span",{className:"text-bambu-gray",children:["Last ",r," days: ",a.jsx("span",{className:"text-white font-medium",children:v.total})," notifications"]}),a.jsxs("span",{className:"flex items-center gap-1 text-bambu-green",children:[a.jsx(Nr,{className:"w-4 h-4"}),v.success_count," sent"]}),v.failure_count>0&&a.jsxs("span",{className:"flex items-center gap-1 text-red-400",children:[a.jsx(ta,{className:"w-4 h-4"}),v.failure_count," failed"]})]})}),a.jsxs("div",{className:"px-4 py-3 border-b border-bambu-dark-tertiary flex items-center gap-4",children:[a.jsxs("select",{value:r,onChange:S=>i(Number(S.target.value)),className:"px-3 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:outline-none focus:ring-1 focus:ring-bambu-green",children:[a.jsx("option",{value:1,children:"Last 24 hours"}),a.jsx("option",{value:7,children:"Last 7 days"}),a.jsx("option",{value:30,children:"Last 30 days"}),a.jsx("option",{value:90,children:"Last 90 days"})]}),a.jsxs("label",{className:"flex items-center gap-2 text-sm text-bambu-gray cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:l,onChange:S=>c(S.target.checked),className:"rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),"Show failed only"]}),a.jsx("div",{className:"flex-1"}),a.jsxs(ke,{size:"sm",variant:"secondary",onClick:()=>p(),disabled:b,children:[b?a.jsx(ut,{className:"w-4 h-4 animate-spin"}):a.jsx(Ir,{className:"w-4 h-4"}),"Refresh"]}),a.jsxs(ke,{size:"sm",variant:"secondary",onClick:()=>x.mutate(),disabled:x.isPending,className:"text-red-400 hover:text-red-300",children:[x.isPending?a.jsx(ut,{className:"w-4 h-4 animate-spin"}):a.jsx(cn,{className:"w-4 h-4"}),"Clear Old"]})]}),a.jsx("div",{className:"flex-1 overflow-y-auto p-4",children:m?a.jsx("div",{className:"flex justify-center py-12",children:a.jsx(ut,{className:"w-6 h-6 text-bambu-green animate-spin"})}):h&&h.length>0?a.jsx("div",{className:"space-y-2",children:h.map(S=>a.jsx(ZYe,{log:S,isExpanded:s===S.id,onToggle:()=>o(s===S.id?null:S.id),formatDate:y,formatFullDate:N=>nb(N,d)},S.id))}):a.jsxs("div",{className:"text-center py-12 text-bambu-gray",children:[a.jsx(sy,{className:"w-12 h-12 mx-auto mb-3 opacity-30"}),a.jsx("p",{className:"text-sm",children:l?"No failed notifications":"No notifications logged"})]})})]})})}function ZYe({log:t,isExpanded:e,onToggle:n,formatDate:r,formatFullDate:i}){return a.jsxs("div",{className:`border rounded-lg overflow-hidden transition-colors ${t.success?"border-bambu-dark-tertiary bg-bambu-dark/30":"border-red-500/30 bg-red-500/5"}`,children:[a.jsxs("button",{className:"w-full px-3 py-2 flex items-center gap-3 text-left hover:bg-bambu-dark/50 transition-colors",onClick:n,children:[t.success?a.jsx(Nr,{className:"w-4 h-4 text-bambu-green shrink-0"}):a.jsx(ta,{className:"w-4 h-4 text-red-400 shrink-0"}),a.jsx("span",{className:`text-xs font-medium ${YYe[t.event_type]||"text-bambu-gray"}`,children:XYe[t.event_type]||t.event_type}),a.jsx("span",{className:"text-sm text-white truncate flex-1",children:t.provider_name||"Unknown Provider"}),t.printer_name&&a.jsx("span",{className:"text-xs text-bambu-gray",children:t.printer_name}),a.jsx("span",{className:"text-xs text-bambu-gray shrink-0",children:r(t.created_at)}),e?a.jsx(Ch,{className:"w-4 h-4 text-bambu-gray shrink-0"}):a.jsx(Sr,{className:"w-4 h-4 text-bambu-gray shrink-0"})]}),e&&a.jsxs("div",{className:"px-3 py-2 border-t border-bambu-dark-tertiary bg-bambu-dark/20 space-y-2",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-xs text-bambu-gray mb-1",children:"Title"}),a.jsx("p",{className:"text-sm text-white",children:t.title})]}),a.jsxs("div",{children:[a.jsx("p",{className:"text-xs text-bambu-gray mb-1",children:"Message"}),a.jsx("p",{className:"text-sm text-white whitespace-pre-wrap",children:t.message})]}),!t.success&&t.error_message&&a.jsxs("div",{children:[a.jsx("p",{className:"text-xs text-red-400 mb-1",children:"Error"}),a.jsx("p",{className:"text-sm text-red-300",children:t.error_message})]}),a.jsxs("div",{className:"flex gap-4 text-xs text-bambu-gray pt-1",children:[a.jsxs("span",{children:["Provider: ",t.provider_type]}),a.jsxs("span",{children:["Time: ",i(t.created_at)]})]})]})]})}function JYe({formData:t,setFormData:e,groups:n,onClose:r,onCreate:i,isCreating:s,isCreateButtonDisabled:o}){const{t:l}=Sn();_.useEffect(()=>{const u=d=>{d.key==="Escape"&&r()};return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[r]);const c=u=>{e({...t,group_ids:t.group_ids.includes(u)?t.group_ids.filter(d=>d!==u):[...t.group_ids,u]})};return a.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",onClick:r,children:a.jsxs(_t,{className:"w-full max-w-md",onClick:u=>u.stopPropagation(),children:[a.jsx(Pn,{children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex flex-col gap-1",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(Kf,{className:"w-5 h-5 text-bambu-green"}),a.jsx("h2",{className:"text-lg font-semibold text-white",children:l("users.modal.createUser")})]}),a.jsx("p",{className:"text-sm text-bambu-gray ml-7",children:l("users.modal.advancedAuthSubtitle")||"with Advanced Authentication"})]}),a.jsx(ke,{variant:"ghost",size:"sm",onClick:r,children:a.jsx(Lt,{className:"w-5 h-5"})})]})}),a.jsxs(Mt,{children:[a.jsxs("div",{className:"space-y-4",children:[a.jsxs("div",{children:[a.jsxs("label",{className:"block text-sm font-medium text-white mb-2",children:[l("users.form.username")," ",a.jsx("span",{className:"text-red-400",children:"*"})]}),a.jsx("input",{type:"text",value:t.username,onChange:u=>e({...t,username:u.target.value}),className:"w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors",placeholder:l("users.form.usernamePlaceholder"),autoComplete:"username",required:!0})]}),a.jsxs("div",{children:[a.jsxs("label",{className:"block text-sm font-medium text-white mb-2",children:[l("users.form.email")||"Email"," ",a.jsx("span",{className:"text-red-400",children:"*"})]}),a.jsx("input",{type:"email",value:t.email,onChange:u=>e({...t,email:u.target.value}),className:"w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors",placeholder:l("users.form.emailPlaceholder")||"user@example.com",required:!0})]}),a.jsx("div",{className:"bg-bambu-dark-secondary/50 border border-bambu-green/20 rounded-lg p-3",children:a.jsx("p",{className:"text-sm text-bambu-gray",children:l("users.form.autoGeneratedPassword")||"A secure password will be automatically generated and emailed to the user."})}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:l("users.form.groups")}),a.jsxs("div",{className:"space-y-2 max-h-40 overflow-y-auto p-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg",children:[n.map(u=>a.jsxs("label",{className:"flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-tertiary cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:t.group_ids.includes(u.id),onChange:()=>c(u.id),className:"w-4 h-4 rounded border-bambu-gray text-bambu-green focus:ring-bambu-green focus:ring-offset-0 bg-bambu-dark"}),a.jsx("span",{className:"text-sm text-white",children:u.name}),u.is_system&&a.jsxs("span",{className:"text-xs text-yellow-400",children:["(",l("users.system"),")"]})]},u.id)),n.length===0&&a.jsx("p",{className:"text-sm text-bambu-gray",children:l("users.noGroupsAvailable")})]})]})]}),a.jsxs("div",{className:"mt-6 flex justify-end gap-3",children:[a.jsx(ke,{variant:"secondary",onClick:r,children:l("users.modal.cancel")}),a.jsx(ke,{onClick:i,disabled:o,children:s?a.jsxs(a.Fragment,{children:[a.jsx(ut,{className:"w-4 h-4 animate-spin"}),l("users.modal.creating")]}):a.jsxs(a.Fragment,{children:[a.jsx(dr,{className:"w-4 h-4"}),l("users.modal.createUser")]})})]})]})]})})}function eQe(){const{t}=Sn(),e=un(),{showToast:n}=Hn(),[r,i]=_.useState(!1),[s,o]=_.useState(""),[l,c]=_.useState("auto"),[u,d]=_.useState(!1),[h,m]=_.useState(!0),[p,b]=_.useState("all"),[v,x]=_.useState(!1),[y,S]=_.useState(!1),{data:N,isLoading:A}=st({queryKey:["spoolman-settings"],queryFn:ce.getSpoolmanSettings}),{data:k,isLoading:C,refetch:E}=st({queryKey:["spoolman-status"],queryFn:ce.getSpoolmanStatus,refetchInterval:3e4}),{data:P}=st({queryKey:["printers"],queryFn:ce.getPrinters});_.useEffect(()=>{N&&(i(N.spoolman_enabled==="true"),o(N.spoolman_url||""),c(N.spoolman_sync_mode||"auto"),d(N.spoolman_disable_weight_sync==="true"),m(N.spoolman_report_partial_usage!=="false"),x(!0))},[N]),_.useEffect(()=>{if(!v||!N)return;if(N.spoolman_enabled==="true"!==r||(N.spoolman_url||"")!==s||(N.spoolman_sync_mode||"auto")!==l||N.spoolman_disable_weight_sync==="true"!==u||N.spoolman_report_partial_usage!=="false"!==h){const Y=setTimeout(()=>{T.mutate()},500);return()=>clearTimeout(Y)}},[r,s,l,u,h,v]);const T=pt({mutationFn:()=>ce.updateSpoolmanSettings({spoolman_enabled:r?"true":"false",spoolman_url:s,spoolman_sync_mode:l,spoolman_disable_weight_sync:u?"true":"false",spoolman_report_partial_usage:h?"true":"false"}),onSuccess:()=>{e.invalidateQueries({queryKey:["spoolman-settings"]}),e.invalidateQueries({queryKey:["spoolman-status"]}),n(t("settings.toast.settingsSaved"))}}),j=pt({mutationFn:ce.connectSpoolman,onSuccess:()=>{E()}}),z=pt({mutationFn:ce.disconnectSpoolman,onSuccess:()=>{E()}}),L=pt({mutationFn:ce.syncAllPrintersAms,onSuccess:G=>{G.success}}),B=pt({mutationFn:G=>ce.syncPrinterAms(G),onSuccess:G=>{G.success}}),R=()=>{p==="all"?L.mutate():B.mutate(p)},$=L.isPending||B.isPending,q=p==="all"?L.data:B.data,I=p==="all"?L.isSuccess:B.isSuccess;return A?a.jsxs(_t,{children:[a.jsx(Pn,{children:a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(ju,{className:"w-5 h-5 text-bambu-green"}),a.jsx("h2",{className:"text-lg font-semibold text-white",children:"Spoolman Integration"})]})}),a.jsx(Mt,{children:a.jsx("div",{className:"flex justify-center py-8",children:a.jsx(ut,{className:"w-6 h-6 text-bambu-green animate-spin"})})})]}):a.jsxs(_t,{children:[a.jsx(Pn,{children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(ju,{className:"w-5 h-5 text-bambu-green"}),a.jsx("h2",{className:"text-lg font-semibold text-white",children:"Spoolman Integration"})]}),T.isPending&&a.jsx(ut,{className:"w-4 h-4 text-bambu-green animate-spin"})]})}),a.jsxs(Mt,{className:"space-y-4",children:[a.jsx("p",{className:"text-sm text-bambu-gray",children:"Connect to Spoolman for filament inventory tracking. AMS data will sync automatically."}),a.jsx("div",{className:"p-3 bg-blue-500/10 border border-blue-500/30 rounded-lg",children:a.jsxs("div",{className:"flex gap-2",children:[a.jsx(ho,{className:"w-4 h-4 text-blue-400 flex-shrink-0 mt-0.5"}),a.jsxs("div",{className:"text-xs text-blue-300",children:[a.jsx("p",{className:"font-medium mb-1",children:"How Sync Works"}),a.jsxs("ul",{className:"list-disc list-inside space-y-0.5 text-blue-300/80",children:[a.jsx("li",{children:"Only official Bambu Lab spools with RFID are synced"}),a.jsx("li",{children:"New spools are auto-created in Spoolman on first sync"}),a.jsx("li",{children:"Non-Bambu Lab spools (third-party, refilled) are skipped"})]}),a.jsx("p",{className:"font-medium mt-2 mb-1",children:"Linking Existing Spools"}),a.jsx("p",{className:"text-blue-300/80",children:'To link existing Spoolman spools to your AMS, hover over an AMS slot and click "Link to Spoolman".'})]})]})}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white",children:"Enable Spoolman"}),a.jsx("p",{className:"text-sm text-bambu-gray",children:"Sync filament data with Spoolman server"})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:r,onChange:G=>i(G.target.checked),className:"sr-only peer"}),a.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Spoolman URL"}),a.jsx("input",{type:"text",placeholder:"http://192.168.1.100:7912",value:s,onChange:G=>o(G.target.value),disabled:!r,className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray/50 focus:border-bambu-green focus:outline-none disabled:opacity-50"}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"URL of your Spoolman server (e.g., http://localhost:7912)"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Sync Mode"}),a.jsxs("select",{value:l,onChange:G=>c(G.target.value),disabled:!r,className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none disabled:opacity-50",children:[a.jsx("option",{value:"auto",children:"Automatic"}),a.jsx("option",{value:"manual",children:"Manual Only"})]}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:l==="auto"?"AMS data syncs automatically when changes are detected":"Only sync when manually triggered"})]}),l==="auto"&&a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white",children:t("spoolman.disableWeightSync")}),a.jsx("p",{className:"text-sm text-bambu-gray",children:t("spoolman.disableWeightSyncDesc")})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:u,onChange:G=>d(G.target.checked),disabled:!r,className:"sr-only peer"}),a.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),u&&a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white",children:t("spoolman.reportPartialUsage")}),a.jsx("p",{className:"text-sm text-bambu-gray",children:t("spoolman.reportPartialUsageDesc")})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:h,onChange:G=>m(G.target.checked),disabled:!r,className:"sr-only peer"}),a.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),r&&a.jsxs("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:[a.jsxs("div",{className:"flex items-center justify-between mb-3",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("span",{className:"text-sm text-bambu-gray",children:"Status:"}),C?a.jsx(ut,{className:"w-4 h-4 text-bambu-gray animate-spin"}):k?.connected?a.jsxs("span",{className:"flex items-center gap-1 text-sm text-green-500",children:[a.jsx(qi,{className:"w-4 h-4"}),"Connected"]}):a.jsxs("span",{className:"flex items-center gap-1 text-sm text-red-500",children:[a.jsx(Lt,{className:"w-4 h-4"}),"Disconnected"]})]}),a.jsx("div",{className:"flex gap-2",children:k?.connected?a.jsxs(ke,{variant:"secondary",size:"sm",onClick:()=>z.mutate(),disabled:z.isPending,children:[z.isPending?a.jsx(ut,{className:"w-4 h-4 animate-spin"}):a.jsx($he,{className:"w-4 h-4"}),"Disconnect"]}):a.jsxs(ke,{size:"sm",onClick:()=>j.mutate(),disabled:j.isPending||!s,children:[j.isPending?a.jsx(ut,{className:"w-4 h-4 animate-spin"}):a.jsx(bc,{className:"w-4 h-4"}),"Connect"]})})]}),j.isError&&a.jsx("div",{className:"mb-3 p-2 bg-red-500/20 border border-red-500/50 rounded text-sm text-red-400",children:j.error.message}),k?.connected&&a.jsxs("div",{className:"space-y-3",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-sm text-white",children:"Sync AMS Data"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Manually sync printer AMS data to Spoolman"})]}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsxs("div",{className:"relative flex-1",children:[a.jsxs("select",{value:p,onChange:G=>b(G.target.value==="all"?"all":Number(G.target.value)),className:"w-full px-3 py-2 pr-8 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none appearance-none cursor-pointer",children:[a.jsx("option",{value:"all",children:"All Printers"}),P?.map(G=>a.jsx("option",{value:G.id,children:G.name},G.id))]}),a.jsx(Sr,{className:"absolute right-2 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),a.jsxs(ke,{variant:"secondary",size:"sm",onClick:R,disabled:$,children:[$?a.jsx(ut,{className:"w-4 h-4 animate-spin"}):a.jsx(Ir,{className:"w-4 h-4"}),"Sync"]})]})]}),I&&q&&a.jsxs("div",{className:"mt-3 space-y-2",children:[a.jsx("div",{className:`p-2 rounded text-sm ${q.success?"bg-green-500/20 border border-green-500/50 text-green-400":"bg-yellow-500/20 border border-yellow-500/50 text-yellow-400"}`,children:q.success?`Synced ${q.synced_count} spool${q.synced_count!==1?"s":""} successfully`:`Synced ${q.synced_count} spool${q.synced_count!==1?"s":""} with ${q.errors.length} error${q.errors.length!==1?"s":""}`}),q.skipped_count>0&&a.jsxs("div",{className:"p-2 bg-amber-500/10 border border-amber-500/30 rounded text-sm",children:[a.jsxs("div",{className:"flex items-center justify-between text-amber-400 mb-1",children:[a.jsxs("div",{className:"flex items-center gap-1.5",children:[a.jsx(kn,{className:"w-3.5 h-3.5"}),a.jsxs("span",{className:"font-medium",children:[q.skipped_count," spool",q.skipped_count!==1?"s":""," skipped"]})]}),q.skipped_count>5&&a.jsx("button",{onClick:()=>S(!y),className:"text-xs text-amber-400 hover:text-amber-300 underline",children:y?"Show less":"Show all"})]}),a.jsxs("ul",{className:"text-xs text-amber-300/80 space-y-0.5",children:[(y?q.skipped:q.skipped.slice(0,5)).map((G,Y)=>a.jsxs("li",{className:"flex items-center gap-2",children:[G.color&&a.jsx("span",{className:"w-3 h-3 rounded-full border border-white/20",style:{backgroundColor:`#${G.color}`}}),a.jsx("span",{children:G.location}),a.jsxs("span",{className:"text-amber-300/60",children:["- ",G.reason]})]},Y)),!y&&q.skipped_count>5&&a.jsxs("li",{className:"text-amber-300/60 italic",children:["...and ",q.skipped_count-5," more"]})]})]}),q.errors.length>0&&a.jsxs("div",{className:"p-2 bg-red-500/10 border border-red-500/30 rounded text-sm",children:[a.jsx("div",{className:"text-red-400 font-medium mb-1",children:"Errors:"}),a.jsx("ul",{className:"text-xs text-red-300/80 space-y-0.5",children:q.errors.map((G,Y)=>a.jsx("li",{children:G},Y))})]})]})]})]})]})}function tQe({link:t,onClose:e}){const n=un(),{mode:r}=Vh(),i=!!t,s=_.useRef(null),[o,l]=_.useState(t?.name||""),[c,u]=_.useState(t?.url||""),[d,h]=_.useState(t?.icon||"link"),[m,p]=_.useState(!!t?.custom_icon),[b,v]=_.useState(t?.custom_icon?ce.getExternalLinkIconUrl(t.id):null),[x,y]=_.useState(null),[S,N]=_.useState(null);_.useEffect(()=>{const z=L=>{L.key==="Escape"&&e()};return window.addEventListener("keydown",z),()=>window.removeEventListener("keydown",z)},[e]);const A=pt({mutationFn:async z=>{const L=await ce.createExternalLink(z);return x?await ce.uploadExternalLinkIcon(L.id,x):L},onSuccess:()=>{n.invalidateQueries({queryKey:["external-links"]}),e()},onError:z=>{N(z.message)}}),k=pt({mutationFn:async z=>{let L=await ce.updateExternalLink(t.id,z);return x?L=await ce.uploadExternalLinkIcon(t.id,x):!m&&t?.custom_icon&&(L=await ce.deleteExternalLinkIcon(t.id)),L},onSuccess:()=>{n.invalidateQueries({queryKey:["external-links"]}),e()},onError:z=>{N(z.message)}}),C=z=>{const L=z.target.files?.[0];if(L){if(!["image/png","image/jpeg","image/gif","image/svg+xml","image/webp","image/x-icon"].includes(L.type)){N("Please select a valid image file (PNG, JPG, GIF, SVG, WebP, or ICO)");return}if(L.size>1024*1024){N("Image file must be less than 1MB");return}y(L),p(!0);const R=new FileReader;R.onload=$=>{v($.target?.result)},R.readAsDataURL(L)}},E=()=>{y(null),v(null),p(!1),s.current&&(s.current.value="")},P=z=>{if(z.preventDefault(),N(null),!o.trim()){N("Name is required");return}if(!c.trim()){N("URL is required");return}if(!c.startsWith("http://")&&!c.startsWith("https://")){N("URL must start with http:// or https://");return}const L={name:o.trim(),url:c.trim(),icon:d};i?k.mutate(L):A.mutate(L)},T=A.isPending||k.isPending,j=qM(d);return a.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",onClick:e,children:a.jsxs("div",{className:"bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-md",onClick:z=>z.stopPropagation(),children:[a.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary",children:[a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx("div",{className:"p-2 rounded-full bg-bambu-green/20 text-bambu-green",children:m&&b?a.jsx("img",{src:b,alt:"",className:`w-5 h-5 rounded ${r==="dark"?"invert opacity-[0.65]":"opacity-60"}`}):a.jsx(j,{className:"w-5 h-5"})}),a.jsx("h2",{className:"text-lg font-semibold text-white",children:i?"Edit Link":"Add External Link"})]}),a.jsx("button",{onClick:e,className:"text-bambu-gray hover:text-white transition-colors",children:a.jsx(Lt,{className:"w-5 h-5"})})]}),a.jsxs("form",{onSubmit:P,className:"p-6 space-y-4",children:[S&&a.jsx("div",{className:"p-3 bg-red-500/20 border border-red-500/50 rounded-lg text-sm text-red-400",children:S}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Name *"}),a.jsx("input",{type:"text",value:o,onChange:z=>l(z.target.value),placeholder:"My Link",maxLength:50,className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"URL *"}),a.jsx("input",{type:"text",value:c,onChange:z=>u(z.target.value),placeholder:"https://example.com",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),a.jsxs("div",{className:"space-y-3",children:[a.jsx("label",{className:"block text-sm text-bambu-gray",children:"Icon"}),a.jsxs("div",{className:"p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary",children:[a.jsxs("div",{className:"flex items-center justify-between mb-2",children:[a.jsx("span",{className:"text-sm text-white",children:"Custom Icon"}),a.jsx("input",{ref:s,type:"file",accept:"image/png,image/jpeg,image/gif,image/svg+xml,image/webp,image/x-icon",className:"hidden",onChange:C}),m&&b?a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("img",{src:b,alt:"Custom icon",className:`w-8 h-8 rounded border border-bambu-dark-tertiary ${r==="dark"?"invert opacity-[0.65]":"opacity-60"}`}),a.jsx("button",{type:"button",onClick:E,className:"p-1 text-red-400 hover:text-red-300 transition-colors",title:"Remove custom icon",children:a.jsx(cn,{className:"w-4 h-4"})})]}):a.jsxs(ke,{type:"button",variant:"secondary",size:"sm",onClick:()=>s.current?.click(),children:[a.jsx($a,{className:"w-4 h-4"}),"Upload"]})]}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"PNG, JPG, GIF, SVG, WebP, or ICO. Max 1MB."})]}),!m&&a.jsxs("div",{children:[a.jsx("span",{className:"text-sm text-bambu-gray block mb-2",children:"Or choose a preset icon"}),a.jsx(Yme,{value:d,onChange:h})]})]}),a.jsxs("div",{className:"flex gap-3 pt-2",children:[a.jsx(ke,{type:"button",variant:"secondary",onClick:e,className:"flex-1",children:"Cancel"}),a.jsxs(ke,{type:"submit",disabled:T,className:"flex-1",children:[T?a.jsx(ut,{className:"w-4 h-4 animate-spin"}):a.jsx(gs,{className:"w-4 h-4"}),i?"Save":"Add"]})]})]})]})})}function nQe(){const t=un(),[e,n]=_.useState(!1),[r,i]=_.useState(null),[s,o]=_.useState(null),[l,c]=_.useState(null),{data:u,isLoading:d}=st({queryKey:["external-links"],queryFn:ce.getExternalLinks}),h=pt({mutationFn:S=>ce.deleteExternalLink(S),onSuccess:()=>{t.invalidateQueries({queryKey:["external-links"]})}}),m=pt({mutationFn:S=>ce.reorderExternalLinks(S),onSuccess:()=>{t.invalidateQueries({queryKey:["external-links"]})}}),p=(S,N)=>{c(N),S.dataTransfer.effectAllowed="move"},b=S=>{S.preventDefault(),S.dataTransfer.dropEffect="move"},v=(S,N)=>{if(S.preventDefault(),l===null||l===N||!u)return;const A=u.map(P=>P.id),k=A.indexOf(l),C=A.indexOf(N);if(k===-1||C===-1)return;const E=[...A];E.splice(k,1),E.splice(C,0,l),m.mutate(E),c(null)},x=S=>{o(S)},y=()=>{s&&(h.mutate(s.id),o(null))};return a.jsxs(a.Fragment,{children:[a.jsxs(_t,{children:[a.jsx(Pn,{children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(bc,{className:"w-5 h-5 text-bambu-green"}),a.jsx("h2",{className:"text-lg font-semibold text-white",children:"Sidebar Links"})]}),a.jsxs(ke,{size:"sm",onClick:()=>n(!0),children:[a.jsx(dr,{className:"w-4 h-4"}),"Add Link"]})]})}),a.jsxs(Mt,{children:[a.jsx("p",{className:"text-sm text-bambu-gray mb-4",children:"Add external links to the sidebar navigation. Drag to reorder."}),d?a.jsx("div",{className:"flex justify-center py-8",children:a.jsx(ut,{className:"w-6 h-6 text-bambu-green animate-spin"})}):u&&u.length>0?a.jsx("div",{className:"space-y-2",children:u.map(S=>{const N=qM(S.icon);return a.jsxs("div",{draggable:!0,onDragStart:A=>p(A,S.id),onDragOver:b,onDrop:A=>v(A,S.id),className:`flex items-center gap-3 p-3 rounded-lg bg-bambu-dark border border-bambu-dark-tertiary transition-colors ${l===S.id?"opacity-50":""}`,children:[a.jsx(eb,{className:"w-6 h-6 md:w-4 md:h-4 text-bambu-gray cursor-grab flex-shrink-0"}),a.jsx("div",{className:"p-2 rounded-lg bg-bambu-dark-tertiary text-bambu-gray",children:a.jsx(N,{className:"w-4 h-4"})}),a.jsxs("div",{className:"flex-1 min-w-0",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("span",{className:"text-white font-medium truncate",children:S.name}),a.jsx(Xr,{className:"w-3 h-3 text-bambu-gray flex-shrink-0"})]}),a.jsx("span",{className:"text-sm text-bambu-gray truncate block",children:S.url})]}),a.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[a.jsx("button",{onClick:()=>i(S),className:"p-2 rounded-lg hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white transition-colors",title:"Edit",children:a.jsx(na,{className:"w-4 h-4"})}),a.jsx("button",{onClick:()=>x(S),disabled:h.isPending,className:"p-2 rounded-lg hover:bg-red-500/20 text-bambu-gray hover:text-red-400 transition-colors disabled:opacity-50",title:"Delete",children:a.jsx(cn,{className:"w-4 h-4"})})]})]},S.id)})}):a.jsxs("div",{className:"text-center py-8 text-bambu-gray",children:[a.jsx(bc,{className:"w-8 h-8 mx-auto mb-2 opacity-50"}),a.jsx("p",{children:"No external links configured"}),a.jsx("p",{className:"text-sm",children:'Click "Add Link" to add one'})]})]})]}),(e||r)&&a.jsx(tQe,{link:r,onClose:()=>{n(!1),i(null)}}),s&&a.jsx(er,{title:"Delete Link",message:`Are you sure you want to delete "${s.name}"? This action cannot be undone.`,confirmText:"Delete",cancelText:"Cancel",variant:"danger",onConfirm:y,onCancel:()=>o(null)})]})}function rQe(){const{t}=Sn(),e=un(),{showToast:n}=Hn(),[r,i]=_.useState(!1),[s,o]=_.useState(""),[l,c]=_.useState("immediate"),[u,d]=_.useState("3DPrinter-X1-Carbon"),[h,m]=_.useState(null),[p,b]=_.useState(""),[v,x]=_.useState(!1),[y,S]=_.useState(null),{data:N,isLoading:A}=st({queryKey:["virtual-printer-settings"],queryFn:D1.getSettings,refetchInterval:1e4}),{data:k}=st({queryKey:["virtual-printer-models"],queryFn:D1.getModels}),{data:C}=st({queryKey:["printers"],queryFn:ce.getPrinters}),{data:E}=st({queryKey:["network-interfaces"],queryFn:()=>ce.getNetworkInterfaces().then(I=>I.interfaces),enabled:l==="proxy"});_.useEffect(()=>{if(N){i(N.enabled);let I=N.mode==="queue"?"review":N.mode;I!=="immediate"&&I!=="review"&&I!=="print_queue"&&I!=="proxy"&&(I="immediate"),c(I),d(N.model),m(N.target_printer_id),b(N.remote_interface_ip||"")}},[N]);const P=pt({mutationFn:I=>D1.updateSettings(I),onSuccess:()=>{e.invalidateQueries({queryKey:["virtual-printer-settings"]}),n(t("virtualPrinter.toast.updated")),S(null)},onError:I=>{if(n(I.message||t("virtualPrinter.toast.failedToUpdate"),"error"),N){i(N.enabled);const G=N.mode==="queue"?"review":N.mode;c(["immediate","review","print_queue","proxy"].includes(G)?G:"immediate"),d(N.model),m(N.target_printer_id)}S(null)}}),T=()=>{const I=!r;if(I){if(l==="proxy"){if(!h){n(t("virtualPrinter.toast.targetPrinterRequired"),"error");return}}else if(!s&&!N?.access_code_set){n(t("virtualPrinter.toast.accessCodeRequired"),"error");return}}i(I),S("toggle"),P.mutate({enabled:I,access_code:l!=="proxy"&&s||void 0,mode:l,target_printer_id:l==="proxy"?h??void 0:void 0})},j=()=>{if(!s){n(t("virtualPrinter.toast.accessCodeEmpty"),"error");return}if(s.length!==8){n(t("virtualPrinter.toast.accessCodeLength"),"error");return}S("accessCode"),P.mutate({access_code:s}),o("")},z=I=>{c(I),S("mode"),P.mutate({mode:I})},L=I=>{m(I),S("targetPrinter"),P.mutate({target_printer_id:I})},B=I=>{d(I),S("model"),P.mutate({model:I})},R=I=>{b(I),S("remoteInterface"),P.mutate({remote_interface_ip:I})};if(A)return a.jsx(_t,{children:a.jsx(Mt,{className:"py-8 flex justify-center",children:a.jsx(ut,{className:"w-6 h-6 animate-spin text-bambu-green"})})});const $=N?.status,q=$?.running||!1;return a.jsxs("div",{className:"flex flex-col lg:flex-row gap-6 lg:gap-8",children:[a.jsx("div",{className:"space-y-6 lg:w-[480px] lg:flex-shrink-0",children:a.jsxs(_t,{children:[a.jsx(Pn,{children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(Or,{className:"w-5 h-5 text-bambu-green"}),a.jsx("h2",{className:"text-lg font-semibold text-white",children:t("virtualPrinter.title")})]}),$&&a.jsxs("div",{className:`flex items-center gap-2 text-sm ${q?"text-green-400":"text-bambu-gray"}`,children:[a.jsx("span",{className:`w-2 h-2 rounded-full ${q?"bg-green-400 animate-pulse":"bg-gray-500"}`}),t(q?"virtualPrinter.running":"virtualPrinter.stopped")]})]})}),a.jsxs(Mt,{className:"space-y-4",children:[a.jsx("p",{className:"text-sm text-bambu-gray",children:t(l==="proxy"?"virtualPrinter.description.proxy":"virtualPrinter.description.default")}),a.jsxs("div",{className:"flex items-center justify-between py-3 border-t border-bambu-dark-tertiary",children:[a.jsxs("div",{children:[a.jsx("div",{className:"text-white font-medium",children:t("virtualPrinter.enable.title")}),a.jsx("div",{className:"text-sm text-bambu-gray",children:q?l==="proxy"?t("virtualPrinter.enable.proxyingTo",{name:C?.find(I=>I.id===h)?.name||"printer"}):t("virtualPrinter.enable.visibleInSlicer"):t("virtualPrinter.enable.notActive")})]}),a.jsx("button",{onClick:T,disabled:y==="toggle",className:`relative w-12 h-6 rounded-full transition-colors ${r?"bg-bambu-green":"bg-bambu-dark-tertiary"} ${y==="toggle"?"opacity-50":""}`,children:a.jsx("span",{className:`absolute top-1 left-1 w-4 h-4 bg-white rounded-full transition-transform ${r?"translate-x-6":""}`})})]}),l!=="proxy"&&a.jsxs("div",{className:"py-3 border-t border-bambu-dark-tertiary",children:[a.jsx("div",{className:"text-white font-medium mb-2",children:t("virtualPrinter.model.title")}),a.jsx("div",{className:"text-sm text-bambu-gray mb-3",children:t("virtualPrinter.model.description")}),a.jsxs("div",{className:"relative",children:[a.jsx("select",{value:u,onChange:I=>B(I.target.value),disabled:y==="model",className:"w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-2 text-white appearance-none cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed pr-10",children:k?.models&&Object.entries(k.models).sort(([,I],[,G])=>I.localeCompare(G)).map(([I,G])=>a.jsx("option",{value:I,children:G},I))}),a.jsx(Sr,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),r&&q&&a.jsxs("p",{className:"text-xs text-bambu-gray mt-2",children:[a.jsx(ho,{className:"w-3 h-3 inline mr-1"}),t("virtualPrinter.model.restartWarning")]})]}),l!=="proxy"&&a.jsxs("div",{className:"py-3 border-t border-bambu-dark-tertiary",children:[a.jsx("div",{className:"text-white font-medium mb-2",children:t("virtualPrinter.accessCode.title")}),a.jsx("div",{className:"text-sm text-bambu-gray mb-3",children:N?.access_code_set?a.jsxs("span",{className:"flex items-center gap-1 text-green-400",children:[a.jsx(qi,{className:"w-4 h-4"}),t("virtualPrinter.accessCode.isSet")]}):a.jsxs("span",{className:"flex items-center gap-1 text-yellow-400",children:[a.jsx(kn,{className:"w-4 h-4"}),t("virtualPrinter.accessCode.notSet")]})}),a.jsxs("div",{className:"flex gap-2",children:[a.jsxs("div",{className:"relative flex-1",children:[a.jsx("input",{type:v?"text":"password",value:s,onChange:I=>o(I.target.value),placeholder:N?.access_code_set?t("virtualPrinter.accessCode.placeholderChange"):t("virtualPrinter.accessCode.placeholder"),maxLength:8,className:"w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-2 text-white placeholder-bambu-gray pr-10 font-mono"}),a.jsx("button",{onClick:()=>x(!v),className:"absolute right-2 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white",children:v?a.jsx(RM,{className:"w-4 h-4"}):a.jsx(_c,{className:"w-4 h-4"})})]}),a.jsx(ke,{onClick:j,disabled:!s||y==="accessCode",variant:"primary",children:y==="accessCode"?a.jsx(ut,{className:"w-4 h-4 animate-spin"}):t("common.save")})]}),a.jsxs("p",{className:"text-xs text-bambu-gray mt-2",children:[t("virtualPrinter.accessCode.hint"),s&&a.jsxs("span",{className:s.length===8?"text-green-400":"text-yellow-400",children:[" ",t("virtualPrinter.accessCode.charCount",{count:s.length})]})]})]}),l==="proxy"&&a.jsxs("div",{className:"py-3 border-t border-bambu-dark-tertiary",children:[a.jsx("div",{className:"text-white font-medium mb-2",children:t("virtualPrinter.targetPrinter.title")}),a.jsx("div",{className:"text-sm text-bambu-gray mb-3",children:h?a.jsxs("span",{className:"flex items-center gap-1 text-green-400",children:[a.jsx(qi,{className:"w-4 h-4"}),t("virtualPrinter.targetPrinter.configured")]}):a.jsxs("span",{className:"flex items-center gap-1 text-yellow-400",children:[a.jsx(kn,{className:"w-4 h-4"}),t("virtualPrinter.targetPrinter.notConfigured")]})}),a.jsxs("div",{className:"relative",children:[a.jsxs("select",{value:h??"",onChange:I=>{const G=parseInt(I.target.value,10);isNaN(G)||L(G)},disabled:y==="targetPrinter",className:"w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-2 text-white appearance-none cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed pr-10",children:[a.jsx("option",{value:"",children:t("virtualPrinter.targetPrinter.placeholder")}),C?.map(I=>a.jsxs("option",{value:I.id,children:[I.name," (",I.ip_address,")"]},I.id))]}),a.jsx(Sr,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),a.jsx("p",{className:"text-xs text-bambu-gray mt-2",children:t("virtualPrinter.targetPrinter.hint")}),!C?.length&&a.jsxs("p",{className:"text-xs text-yellow-400 mt-2",children:[a.jsx(kn,{className:"w-3 h-3 inline mr-1"}),t("virtualPrinter.targetPrinter.noPrinters")]})]}),l==="proxy"&&a.jsxs("div",{className:"py-3 border-t border-bambu-dark-tertiary",children:[a.jsx("div",{className:"text-white font-medium mb-2",children:t("virtualPrinter.remoteInterface.title")}),a.jsx("div",{className:"text-sm text-bambu-gray mb-3",children:p?a.jsxs("span",{className:"flex items-center gap-1 text-green-400",children:[a.jsx(qi,{className:"w-4 h-4"}),t("virtualPrinter.remoteInterface.configured")]}):a.jsxs("span",{className:"flex items-center gap-1 text-bambu-gray",children:[a.jsx(ho,{className:"w-4 h-4"}),t("virtualPrinter.remoteInterface.optional")]})}),a.jsxs("div",{className:"relative",children:[a.jsxs("select",{value:p,onChange:I=>R(I.target.value),disabled:y==="remoteInterface",className:"w-full bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-md px-3 py-2 text-white appearance-none cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed pr-10",children:[a.jsx("option",{value:"",children:t("virtualPrinter.remoteInterface.placeholder")}),E?.map(I=>a.jsxs("option",{value:I.ip,children:[I.name," (",I.ip,") - ",I.subnet]},I.ip))]}),a.jsx(Sr,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),a.jsx("p",{className:"text-xs text-bambu-gray mt-2",children:t("virtualPrinter.remoteInterface.hint")})]}),a.jsxs("div",{className:"py-3 border-t border-bambu-dark-tertiary",children:[a.jsx("div",{className:"text-white font-medium mb-2",children:t("virtualPrinter.mode.title")}),a.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[a.jsxs("button",{onClick:()=>z("immediate"),disabled:y==="mode",className:`p-3 rounded-lg border text-left transition-colors ${l==="immediate"?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary hover:border-bambu-gray"}`,children:[a.jsx("div",{className:"text-white font-medium",children:t("virtualPrinter.mode.archive")}),a.jsx("div",{className:"text-xs text-bambu-gray",children:t("virtualPrinter.mode.archiveDesc")})]}),a.jsxs("button",{onClick:()=>z("review"),disabled:y==="mode",className:`p-3 rounded-lg border text-left transition-colors ${l==="review"?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary hover:border-bambu-gray"}`,children:[a.jsx("div",{className:"text-white font-medium",children:t("virtualPrinter.mode.review")}),a.jsx("div",{className:"text-xs text-bambu-gray",children:t("virtualPrinter.mode.reviewDesc")})]}),a.jsxs("button",{onClick:()=>z("print_queue"),disabled:y==="mode",className:`p-3 rounded-lg border text-left transition-colors ${l==="print_queue"?"border-bambu-green bg-bambu-green/10":"border-bambu-dark-tertiary hover:border-bambu-gray"}`,children:[a.jsx("div",{className:"text-white font-medium",children:t("virtualPrinter.mode.queue")}),a.jsx("div",{className:"text-xs text-bambu-gray",children:t("virtualPrinter.mode.queueDesc")})]}),a.jsxs("button",{onClick:()=>z("proxy"),disabled:y==="mode",className:`p-3 rounded-lg border text-left transition-colors ${l==="proxy"?"border-blue-500 bg-blue-500/10":"border-bambu-dark-tertiary hover:border-bambu-gray"}`,children:[a.jsxs("div",{className:"flex items-center gap-1.5 text-white font-medium",children:[a.jsx(hB,{className:"w-4 h-4"}),t("virtualPrinter.mode.proxy")]}),a.jsx("div",{className:"text-xs text-bambu-gray",children:t("virtualPrinter.mode.proxyDesc")})]})]})]})]})]})}),a.jsxs("div",{className:"space-y-6 lg:w-[480px] lg:flex-shrink-0",children:[a.jsx(_t,{className:"border-l-4 border-l-yellow-500",children:a.jsx(Mt,{className:"py-4",children:a.jsxs("div",{className:"flex items-start gap-3",children:[a.jsx(kn,{className:"w-5 h-5 text-yellow-500 flex-shrink-0 mt-0.5"}),a.jsxs("div",{className:"text-sm",children:[a.jsx("p",{className:"text-white font-medium mb-2",children:t("virtualPrinter.setupRequired.title")}),a.jsx("p",{className:"text-bambu-gray mb-3",children:t("virtualPrinter.setupRequired.description")}),a.jsxs("a",{href:"https://wiki.bambuddy.cool/features/virtual-printer/",target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-2 px-4 py-2 bg-yellow-500/20 border border-yellow-500/50 rounded-md text-yellow-400 hover:bg-yellow-500/30 transition-colors",children:[a.jsx(Xr,{className:"w-4 h-4"}),t("virtualPrinter.setupRequired.readGuide")]})]})]})})}),a.jsx(_t,{children:a.jsx(Mt,{className:"py-4",children:a.jsxs("div",{className:"flex items-start gap-3",children:[a.jsx(ho,{className:"w-5 h-5 text-blue-400 flex-shrink-0 mt-0.5"}),a.jsxs("div",{className:"text-sm text-bambu-gray",children:[a.jsx("p",{className:"mb-2",children:a.jsxs("strong",{className:"text-white",children:[t(l==="proxy"?"virtualPrinter.howItWorks.titleProxy":"virtualPrinter.howItWorks.title"),":"]})}),l==="proxy"?a.jsxs("ol",{className:"list-decimal list-inside space-y-1",children:[a.jsx("li",{children:t("virtualPrinter.howItWorks.proxyStep1")}),a.jsx("li",{children:t("virtualPrinter.howItWorks.proxyStep2")}),a.jsx("li",{children:t("virtualPrinter.howItWorks.proxyStep3")}),a.jsx("li",{children:t("virtualPrinter.howItWorks.proxyStep4")}),a.jsx("li",{children:t("virtualPrinter.howItWorks.proxyStep5")})]}):a.jsxs("ol",{className:"list-decimal list-inside space-y-1",children:[a.jsx("li",{children:t("virtualPrinter.howItWorks.step1")}),a.jsx("li",{children:t("virtualPrinter.howItWorks.step2")}),a.jsx("li",{children:t("virtualPrinter.howItWorks.step3")}),a.jsx("li",{children:t("virtualPrinter.howItWorks.step4")}),a.jsx("li",{children:t("virtualPrinter.howItWorks.step5")}),a.jsx("li",{children:t("virtualPrinter.howItWorks.step6")})]})]})]})})}),$&&q&&a.jsxs(_t,{children:[a.jsx(Pn,{children:a.jsx("h3",{className:"text-md font-semibold text-white",children:t("virtualPrinter.status.title")})}),a.jsx(Mt,{children:$.mode==="proxy"&&$.proxy?a.jsxs("div",{className:"grid grid-cols-2 gap-4 text-sm",children:[a.jsxs("div",{children:[a.jsx("div",{className:"text-bambu-gray",children:t("virtualPrinter.status.targetPrinter")}),a.jsx("div",{className:"text-white",children:C?.find(I=>I.id===h)?.name||$.proxy.target_host}),a.jsx("div",{className:"text-xs text-bambu-gray font-mono",children:$.proxy.target_host})]}),a.jsxs("div",{children:[a.jsx("div",{className:"text-bambu-gray",children:t("virtualPrinter.status.mode")}),a.jsxs("div",{className:"text-white flex items-center gap-1.5",children:[a.jsx(hB,{className:"w-4 h-4"}),t("virtualPrinter.mode.proxy")]})]}),a.jsxs("div",{children:[a.jsx("div",{className:"text-bambu-gray",children:t("virtualPrinter.status.ftpPort")}),a.jsx("div",{className:"text-white font-mono",children:$.proxy.ftp_port})]}),a.jsxs("div",{children:[a.jsx("div",{className:"text-bambu-gray",children:t("virtualPrinter.status.mqttPort")}),a.jsx("div",{className:"text-white font-mono",children:$.proxy.mqtt_port})]}),a.jsxs("div",{children:[a.jsx("div",{className:"text-bambu-gray",children:t("virtualPrinter.status.ftpConnections")}),a.jsx("div",{className:"text-white",children:$.proxy.ftp_connections??0})]}),a.jsxs("div",{children:[a.jsx("div",{className:"text-bambu-gray",children:t("virtualPrinter.status.mqttConnections")}),a.jsx("div",{className:"text-white",children:$.proxy.mqtt_connections??0})]})]}):a.jsxs("div",{className:"grid grid-cols-2 gap-4 text-sm",children:[a.jsxs("div",{children:[a.jsx("div",{className:"text-bambu-gray",children:t("virtualPrinter.status.printerName")}),a.jsx("div",{className:"text-white",children:$.name})]}),a.jsxs("div",{children:[a.jsx("div",{className:"text-bambu-gray",children:t("virtualPrinter.status.model")}),a.jsx("div",{className:"text-white",children:$.model_name||$.model})]}),a.jsxs("div",{children:[a.jsx("div",{className:"text-bambu-gray",children:t("virtualPrinter.status.serialNumber")}),a.jsx("div",{className:"text-white font-mono",children:$.serial})]}),a.jsxs("div",{children:[a.jsx("div",{className:"text-bambu-gray",children:t("virtualPrinter.status.mode")}),a.jsx("div",{className:"text-white capitalize",children:$.mode})]}),a.jsxs("div",{children:[a.jsx("div",{className:"text-bambu-gray",children:t("virtualPrinter.status.pendingFiles")}),a.jsx("div",{className:"text-white",children:$.pending_files})]})]})})]})]})]})}function RW({status:t}){if(!t)return null;const e={success:"bg-green-500/20 text-green-400",failed:"bg-red-500/20 text-red-400",skipped:"bg-yellow-500/20 text-yellow-400",running:"bg-blue-500/20 text-blue-400"},n={success:a.jsx(Nr,{className:"w-3 h-3"}),failed:a.jsx(ta,{className:"w-3 h-3"}),skipped:a.jsx(uO,{className:"w-3 h-3"}),running:a.jsx(ut,{className:"w-3 h-3 animate-spin"})};return a.jsxs("span",{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded text-xs font-medium ${e[t]||"bg-gray-500/20 text-gray-400"}`,children:[n[t],t.charAt(0).toUpperCase()+t.slice(1)]})}function iQe(t){return t?new Date(t).toLocaleString():"-"}function OW(t){if(!t)return"-";const e=new Date(t),n=new Date,r=e.getTime()-n.getTime(),i=Math.round(r/6e4);if(i<0){const s=Math.abs(i);if(s<60)return`${s}m ago`;const o=Math.floor(s/60);return o<24?`${o}h ago`:`${Math.floor(o/24)}d ago`}else{if(i<60)return`in ${i}m`;const s=Math.floor(i/60);return s<24?`in ${s}h`:`in ${Math.floor(s/24)}d`}}function aQe(){const t=un(),{showToast:e}=Hn(),{t:n}=Sn(),[r,i]=_.useState(""),[s,o]=_.useState(""),[l,c]=_.useState("main"),[u,d]=_.useState(!1),[h,m]=_.useState("daily"),[p,b]=_.useState(!0),[v,x]=_.useState(!0),[y,S]=_.useState(!1),[N,A]=_.useState(!0),[k,C]=_.useState(!1),[E,P]=_.useState(!1),[T,j]=_.useState(""),[z,L]=_.useState(!1),[B,R]=_.useState(null),[$,q]=_.useState(null),I=_.useRef(null);_.useEffect(()=>{if(k||E){const U=O=>(O.preventDefault(),O.returnValue="A backup operation is in progress. Are you sure you want to leave?",O.returnValue);return window.addEventListener("beforeunload",U),()=>window.removeEventListener("beforeunload",U)}},[k,E]);const[G,Y]=_.useState(!1),[re,H]=_.useState(null),K=_.useRef(null),ne=_.useRef(!1),{data:ie,isLoading:be}=st({queryKey:["github-backup-config"],queryFn:ce.getGitHubBackupConfig}),{data:pe}=st({queryKey:["github-backup-status"],queryFn:ce.getGitHubBackupStatus,refetchInterval:ee=>ee.state.data?.is_running?500:1e4}),{data:de}=st({queryKey:["github-backup-logs"],queryFn:()=>ce.getGitHubBackupLogs(20)}),{data:Ce}=st({queryKey:["cloud-status"],queryFn:ce.getCloudStatus}),{data:ae}=st({queryKey:["printers"],queryFn:ce.getPrinters}),Ae=iO({queries:(ae??[]).map(ee=>({queryKey:["printerStatus",ee.id],queryFn:()=>ce.getPrinterStatus(ee.id),staleTime:1e4,refetchInterval:3e4}))}),Le=(ae??[]).map((ee,U)=>({printer:ee,connected:Ae[U]?.data?.connected??!1})),fe=Le.length,Xe=Le.filter(ee=>ee.connected).length,W=fe>0&&Xe===0,Q=Xe>0&&Xe{ie&&(i(ie.repository_url),c(ie.branch),d(ie.schedule_enabled),m(ie.schedule_type),b(ie.backup_kprofiles),x(ie.backup_cloud_profiles),S(ie.backup_settings),A(ie.enabled),o(""),setTimeout(()=>{ne.current=!0},100))},[ie]);const me=_.useCallback(async(ee=!1)=>{if(ie?.has_token)try{ee&&s?(await ce.saveGitHubBackupConfig({repository_url:r,access_token:s,branch:l,schedule_enabled:u,schedule_type:h,backup_kprofiles:p,backup_cloud_profiles:v,backup_settings:y,enabled:N}),o(""),e("Token updated")):(await ce.updateGitHubBackupConfig({repository_url:r,branch:l,schedule_enabled:u,schedule_type:h,backup_kprofiles:p,backup_cloud_profiles:v,backup_settings:y,enabled:N}),e("Settings saved")),t.invalidateQueries({queryKey:["github-backup-config"]}),t.invalidateQueries({queryKey:["github-backup-status"]})}catch(U){e(`Failed to save: ${U.message}`,"error")}},[ie?.has_token,r,s,l,u,h,p,v,y,N,t,e]);_.useEffect(()=>{if(!(!ne.current||!ie?.has_token))return K.current&&clearTimeout(K.current),K.current=setTimeout(()=>{me(!1)},500),()=>{K.current&&clearTimeout(K.current)}},[r,l,u,h,p,v,y,N,me,ie?.has_token]),_.useEffect(()=>{if(!(!ne.current||!ie?.has_token||!s))return K.current&&clearTimeout(K.current),K.current=setTimeout(()=>{me(!0)},1e3),()=>{K.current&&clearTimeout(K.current)}},[s,me,ie?.has_token]);const X=pt({mutationFn:ee=>ce.saveGitHubBackupConfig(ee),onSuccess:()=>{t.invalidateQueries({queryKey:["github-backup-config"]}),t.invalidateQueries({queryKey:["github-backup-status"]}),e("GitHub backup enabled"),o(""),ne.current=!0},onError:ee=>{e(`Failed to save: ${ee.message}`,"error")}}),te=pt({mutationFn:ce.triggerGitHubBackup,onSuccess:ee=>{t.invalidateQueries({queryKey:["github-backup-status"]}),t.invalidateQueries({queryKey:["github-backup-logs"]}),ee.success?ee.files_changed>0?e(`Backup complete - ${ee.files_changed} files updated`):e("Backup skipped - no changes"):e(`Backup failed: ${ee.message}`,"error")},onError:ee=>{e(`Backup failed: ${ee.message}`,"error")}}),V=pt({mutationFn:()=>ce.clearGitHubBackupLogs(0),onSuccess:ee=>{t.invalidateQueries({queryKey:["github-backup-logs"]}),e(`Cleared ${ee.deleted} logs`)},onError:ee=>{e(`Failed to clear logs: ${ee.message}`,"error")}}),ge=async()=>{Y(!0),H(null);try{let ee;if(s){if(!r){e("Enter repository URL","error"),Y(!1);return}ee=await ce.testGitHubConnection(r,s)}else if(ie?.has_token)ee=await ce.testGitHubStoredConnection();else{e("Enter repository URL and access token","error"),Y(!1);return}H({success:ee.success,message:ee.message})}catch(ee){H({success:!1,message:ee.message})}finally{Y(!1)}},Se=()=>{if(!r){e("Repository URL is required","error");return}if(!s){e("Access token is required","error");return}X.mutate({repository_url:r,access_token:s,branch:l,schedule_enabled:u,schedule_type:h,backup_kprofiles:p,backup_cloud_profiles:v,backup_settings:y,enabled:N})};return be?a.jsx("div",{className:"flex items-center justify-center py-12",children:a.jsx(ut,{className:"w-8 h-8 animate-spin text-bambu-green"})}):a.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[a.jsxs("div",{className:"space-y-6",children:[a.jsxs(_t,{children:[a.jsx(Pn,{children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(BP,{className:"w-5 h-5 text-gray-400"}),a.jsx("h2",{className:"text-lg font-semibold text-white",children:"GitHub Backup"})]}),ie&&Ce?.is_authenticated&&a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("span",{className:"text-sm text-bambu-gray",children:"Enabled"}),a.jsx($n,{checked:N,onChange:A})]})]})}),a.jsx(Mt,{className:"space-y-4",children:Ce?.is_authenticated?a.jsxs(a.Fragment,{children:[a.jsx("p",{className:"text-sm text-bambu-gray",children:"Automatically sync your profiles to a private GitHub repository for backup and version history."}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Repository URL"}),a.jsx("input",{type:"text",value:r,onChange:ee=>{i(ee.target.value),H(null)},placeholder:"https://github.com/username/bambuddy-backup",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),a.jsxs("div",{children:[a.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:["Personal Access Token ",ie?.has_token&&a.jsx("span",{className:"text-green-400",children:"(saved)"})]}),a.jsx("input",{type:"password",value:s,onChange:ee=>{o(ee.target.value),H(null)},placeholder:ie?.has_token?"Enter new token to update":"ghp_xxxxxxxxxxxx",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Fine-grained token with Contents read/write permission"})]}),a.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Branch"}),a.jsx("input",{type:"text",value:l,onChange:ee=>c(ee.target.value),placeholder:"main",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Auto-backup"}),a.jsxs("select",{value:u?h:"disabled",onChange:ee=>{ee.target.value==="disabled"?d(!1):(d(!0),m(ee.target.value))},className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[a.jsx("option",{value:"disabled",children:"Manual only"}),a.jsx("option",{value:"hourly",children:"Hourly"}),a.jsx("option",{value:"daily",children:"Daily"}),a.jsx("option",{value:"weekly",children:"Weekly"})]})]})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-2",children:"Include in backup"}),a.jsxs("div",{className:"space-y-2",children:[a.jsxs("label",{className:`flex items-start gap-2 ${W?"cursor-not-allowed opacity-60":"cursor-pointer"}`,children:[a.jsx("input",{type:"checkbox",checked:p,onChange:ee=>b(ee.target.checked),className:"w-4 h-4 mt-0.5 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green",disabled:W}),a.jsxs("div",{className:"flex-1",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("span",{className:`text-sm ${W?"text-bambu-gray":"text-white"}`,children:"K-Profiles"}),W&&a.jsxs("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-xs bg-yellow-500/20 text-yellow-400",children:[a.jsx(kn,{className:"w-3 h-3"}),"No printers connected"]}),Q&&a.jsxs("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-xs bg-yellow-500/20 text-yellow-400",children:[a.jsx(kn,{className:"w-3 h-3"}),Xe,"/",fe," connected"]})]}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Pressure advance calibration from connected printers"})]})]}),a.jsxs("label",{className:"flex items-start gap-2 cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:v,onChange:ee=>x(ee.target.checked),className:"w-4 h-4 mt-0.5 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green",disabled:!Ce?.is_authenticated}),a.jsxs("div",{children:[a.jsx("span",{className:`text-sm ${Ce?.is_authenticated?"text-white":"text-bambu-gray"}`,children:"Cloud Profiles"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Filament, printer, and process presets from Bambu Cloud"})]})]}),a.jsxs("label",{className:"flex items-start gap-2 cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:y,onChange:ee=>S(ee.target.checked),className:"w-4 h-4 mt-0.5 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green"}),a.jsxs("div",{children:[a.jsx("span",{className:"text-white text-sm",children:"App Settings"}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Bambuddy configuration (excludes sensitive data)"})]})]})]})]}),a.jsxs("div",{className:"border-t border-bambu-dark-tertiary pt-4 space-y-3",children:[pe?.configured&&a.jsxs("div",{className:"flex items-center justify-between text-sm",children:[a.jsx("div",{className:"flex items-center gap-2 text-bambu-gray",children:pe.last_backup_at?a.jsxs(a.Fragment,{children:[a.jsxs("span",{children:["Last backup: ",OW(pe.last_backup_at)]}),a.jsx(RW,{status:pe.last_backup_status})]}):a.jsx("span",{children:"No backups yet"})}),pe.next_scheduled_run&&a.jsxs("span",{className:"text-bambu-gray",children:[a.jsx(nr,{className:"w-3 h-3 inline mr-1"}),"Next: ",OW(pe.next_scheduled_run)]})]}),re&&a.jsxs("div",{className:`text-sm flex items-center gap-1 ${re.success?"text-green-400":"text-red-400"}`,children:[re.success?a.jsx(Nr,{className:"w-4 h-4"}):a.jsx(ta,{className:"w-4 h-4"}),re.message]}),a.jsx("div",{className:"flex flex-wrap items-center gap-2",children:pe?.configured?a.jsx(a.Fragment,{children:te.isPending||pe.is_running?a.jsxs("div",{className:"flex items-center gap-2 text-bambu-green",children:[a.jsx(ut,{className:"w-4 h-4 animate-spin"}),a.jsx("span",{className:"text-sm",children:pe.progress||"Starting backup..."})]}):a.jsxs(a.Fragment,{children:[a.jsxs(ke,{variant:"primary",size:"sm",onClick:()=>te.mutate(),disabled:!ie?.enabled,children:[a.jsx(vo,{className:"w-4 h-4"}),"Backup Now"]}),a.jsxs(ke,{variant:"secondary",size:"sm",onClick:ge,disabled:G,children:[G?a.jsx(ut,{className:"w-4 h-4 animate-spin"}):a.jsx(Ir,{className:"w-4 h-4"}),"Test"]})]})}):a.jsxs(a.Fragment,{children:[a.jsxs(ke,{variant:"primary",size:"sm",onClick:Se,disabled:X.isPending||!r||!s,children:[X.isPending?a.jsx(ut,{className:"w-4 h-4 animate-spin"}):a.jsx(Nr,{className:"w-4 h-4"}),"Enable Backup"]}),a.jsxs(ke,{variant:"secondary",size:"sm",onClick:ge,disabled:G||!r||!s,children:[G?a.jsx(ut,{className:"w-4 h-4 animate-spin"}):a.jsx(Ir,{className:"w-4 h-4"}),"Test Connection"]})]})})]})]}):a.jsxs("div",{className:"flex items-start gap-2 p-3 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[a.jsx(kn,{className:"w-4 h-4 text-yellow-400 mt-0.5 flex-shrink-0"}),a.jsx("p",{className:"text-sm text-yellow-400",children:"Bambu Cloud login required. Sign in under Profiles → Cloud Profiles to enable GitHub backup."})]})})]}),de&&de.length>0&&a.jsxs(_t,{children:[a.jsx(Pn,{children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(sy,{className:"w-5 h-5 text-gray-400"}),a.jsx("h2",{className:"text-lg font-semibold text-white",children:"History"})]}),a.jsxs(ke,{variant:"ghost",size:"sm",onClick:()=>V.mutate(),disabled:V.isPending,children:[a.jsx(cn,{className:"w-4 h-4"}),"Clear"]})]})}),a.jsx(Mt,{children:a.jsx("div",{className:"overflow-x-auto",children:a.jsxs("table",{className:"w-full text-sm",children:[a.jsx("thead",{children:a.jsxs("tr",{className:"text-bambu-gray border-b border-bambu-dark-tertiary",children:[a.jsx("th",{className:"text-left py-2 px-2",children:"Date"}),a.jsx("th",{className:"text-left py-2 px-2",children:"Status"}),a.jsx("th",{className:"text-left py-2 px-2",children:"Commit"})]})}),a.jsx("tbody",{children:de.slice(0,10).map(ee=>a.jsxs("tr",{className:"border-b border-bambu-dark-tertiary/50 hover:bg-bambu-dark-secondary",children:[a.jsx("td",{className:"py-2 px-2 text-white",children:iQe(ee.started_at)}),a.jsx("td",{className:"py-2 px-2",children:a.jsx(RW,{status:ee.status})}),a.jsx("td",{className:"py-2 px-2",children:ee.commit_sha?a.jsxs("a",{href:`${ie?.repository_url}/commit/${ee.commit_sha}`,target:"_blank",rel:"noopener noreferrer",className:"text-bambu-green hover:underline inline-flex items-center gap-1",children:[ee.commit_sha.substring(0,7),a.jsx(Xr,{className:"w-3 h-3"})]}):a.jsx("span",{className:"text-bambu-gray",children:"-"})})]},ee.id))})]})})})]})]}),a.jsx("div",{className:"space-y-6",children:a.jsxs(_t,{children:[a.jsx(Pn,{children:a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(ju,{className:"w-5 h-5 text-gray-400"}),a.jsx("h2",{className:"text-lg font-semibold text-white",children:"Local Backup"})]})}),a.jsxs(Mt,{className:"space-y-4",children:[a.jsx("p",{className:"text-sm text-bambu-gray",children:"Create a complete backup of your Bambuddy data including the database, archives, uploads, and all files."}),a.jsxs("div",{className:"flex items-center justify-between py-3 border-b border-bambu-dark-tertiary",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white",children:"Download Backup"}),a.jsx("p",{className:"text-sm text-bambu-gray",children:"Complete backup: database + all files (ZIP)"})]}),a.jsxs(ke,{variant:"secondary",size:"sm",disabled:k||E,onClick:async()=>{C(!0),j("Preparing backup...");try{j("Creating backup archive... This may take a while for large archives.");const{blob:ee,filename:U}=await ce.exportBackup();j("Downloading backup file...");const O=URL.createObjectURL(ee),Z=document.createElement("a");Z.href=O,Z.download=U,Z.click(),URL.revokeObjectURL(O),e("Backup downloaded successfully")}catch(ee){e(`Failed to create backup: ${ee instanceof Error?ee.message:"Unknown error"}`,"error")}finally{C(!1),j("")}},children:[a.jsx(Ni,{className:"w-4 h-4"}),"Download"]})]}),a.jsxs("div",{className:"flex items-center justify-between py-3 border-b border-bambu-dark-tertiary",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white",children:n("backup.restoreBackup")}),a.jsx("p",{className:"text-sm text-bambu-gray",children:n("backup.restoreDescription")}),a.jsx("p",{className:"text-xs text-bambu-gray-light mt-1",children:n("backup.restoreNote")})]}),a.jsx("input",{ref:I,type:"file",accept:".zip",className:"hidden",onChange:ee=>{const U=ee.target.files?.[0];U&&(R(U),L(!0)),ee.target.value=""}}),a.jsxs(ke,{variant:"secondary",size:"sm",disabled:E||k,onClick:()=>I.current?.click(),children:[a.jsx($a,{className:"w-4 h-4"}),"Restore"]})]}),$&&a.jsx("div",{className:`p-3 rounded-lg ${$.success?"bg-green-500/10 border border-green-500/30":"bg-red-500/10 border border-red-500/30"}`,children:a.jsxs("div",{className:"flex items-start gap-2 text-sm",children:[$.success?a.jsx(Nr,{className:"w-4 h-4 text-green-400 mt-0.5 flex-shrink-0"}):a.jsx(ta,{className:"w-4 h-4 text-red-400 mt-0.5 flex-shrink-0"}),a.jsxs("div",{className:$.success?"text-green-200":"text-red-200",children:[$.message,$.success&&a.jsx("div",{className:"mt-2",children:a.jsxs(ke,{size:"sm",onClick:()=>window.location.reload(),children:[a.jsx($h,{className:"w-3 h-3"}),"Reload Now"]})})]})]})}),a.jsx("div",{className:"p-3 rounded-lg bg-yellow-500/10 border border-yellow-500/30",children:a.jsxs("div",{className:"flex items-start gap-2 text-sm",children:[a.jsx(kn,{className:"w-4 h-4 text-yellow-400 mt-0.5 flex-shrink-0"}),a.jsxs("div",{className:"text-yellow-200",children:[a.jsx("span",{className:"font-medium",children:"Restore replaces all data."})," ",a.jsx("span",{className:"text-yellow-200/70",children:"Your current database and files will be completely replaced. A restart is required after restore."})]})]})})]})]})}),z&&B&&a.jsx(er,{title:"Restore Backup",message:`Are you sure you want to restore from "${B.name}"? This will completely replace your current database and all files. The application will need to be restarted after restore.`,confirmText:"Restore Backup",variant:"danger",onConfirm:async()=>{L(!1),P(!0),q(null);try{j("Uploading backup file...");const ee=await ce.importBackup(B);q(ee),ee.success?e("Backup restored. Please restart Bambuddy.","success"):e(ee.message,"error")}catch(ee){const U=ee instanceof Error?ee.message:"Failed to restore backup";q({success:!1,message:U}),e(U,"error")}finally{P(!1),j(""),R(null)}},onCancel:()=>{L(!1),R(null)}}),(k||E)&&a.jsx("div",{className:"fixed inset-0 bg-black/80 flex items-center justify-center z-[100]",children:a.jsxs("div",{className:"bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl p-8 max-w-md w-full mx-4 text-center",children:[a.jsx("div",{className:"flex justify-center mb-4",children:a.jsxs("div",{className:"relative",children:[a.jsx("div",{className:"w-16 h-16 border-4 border-bambu-dark-tertiary rounded-full"}),a.jsx("div",{className:"w-16 h-16 border-4 border-bambu-green border-t-transparent rounded-full absolute inset-0 animate-spin"})]})}),a.jsx("h3",{className:"text-xl font-semibold text-white mb-2",children:k?"Creating Backup":"Restoring Backup"}),a.jsx("p",{className:"text-bambu-gray mb-4",children:T||(k?"Preparing...":"Processing...")}),a.jsx("div",{className:"p-3 rounded-lg bg-yellow-500/10 border border-yellow-500/30",children:a.jsxs("div",{className:"flex items-start gap-2 text-sm",children:[a.jsx(kn,{className:"w-4 h-4 text-yellow-400 mt-0.5 flex-shrink-0"}),a.jsx("p",{className:"text-yellow-200 text-left",children:"Please do not close this page or navigate away. This operation may take several minutes for large backups."})]})})]})})]})}function sQe(){const{t}=Sn(),{showToast:e}=Hn(),n=un(),[r,i]=_.useState({smtp_host:"",smtp_port:587,smtp_username:"",smtp_password:"",smtp_security:"starttls",smtp_auth_enabled:!0,smtp_from_email:"",smtp_from_name:"BamBuddy"}),[s,o]=_.useState(""),{data:l,isLoading:c}=st({queryKey:["smtpSettings"],queryFn:()=>ce.getSMTPSettings()}),{data:u}=st({queryKey:["advancedAuthStatus"],queryFn:()=>ce.getAdvancedAuthStatus()});_.useEffect(()=>{l&&i({...l,smtp_password:""})},[l]);const d=pt({mutationFn:x=>ce.saveSMTPSettings(x),onSuccess:()=>{n.invalidateQueries({queryKey:["smtpSettings"]}),n.invalidateQueries({queryKey:["advancedAuthStatus"]}),e("SMTP settings saved successfully","success")},onError:x=>{e(x.message,"error")}}),h=pt({mutationFn:x=>ce.testSMTP(x),onSuccess:x=>{e(x.message,x.success?"success":"error")},onError:x=>{e(x.message,"error")}}),m=pt({mutationFn:x=>x?ce.enableAdvancedAuth():ce.disableAdvancedAuth(),onSuccess:x=>{n.invalidateQueries({queryKey:["advancedAuthStatus"]}),e(x.message,"success")},onError:x=>{e(x.message,"error")}}),p=()=>{if(!r.smtp_host||!r.smtp_from_email){e("Please fill in all required fields","error");return}if(r.smtp_auth_enabled&&!r.smtp_username){e("Username is required when authentication is enabled","error");return}d.mutate(r)},b=()=>{if(!s){e("Please enter a test email address","error");return}if(!r.smtp_host||!r.smtp_from_email){e("Please fill in SMTP Server and From Email before testing","error");return}if(r.smtp_auth_enabled&&(!r.smtp_username||!r.smtp_password)){e("Username and Password are required when authentication is enabled","error");return}h.mutate({smtp_host:r.smtp_host,smtp_port:r.smtp_port,smtp_username:r.smtp_username,smtp_password:r.smtp_password,smtp_security:r.smtp_security,smtp_auth_enabled:r.smtp_auth_enabled,smtp_from_email:r.smtp_from_email,test_recipient:s})},v=()=>{if(!u?.advanced_auth_enabled&&!u?.smtp_configured){e("Please configure and test SMTP settings first","error");return}m.mutate(!u?.advanced_auth_enabled)};return c?a.jsx("div",{className:"flex items-center justify-center p-12",children:a.jsx(ut,{className:"w-8 h-8 animate-spin text-bambu-green"})}):a.jsxs("div",{className:"space-y-6",children:[a.jsxs(_t,{children:[a.jsx(Pn,{children:a.jsx("h2",{className:"text-lg font-semibold text-white",children:t("settings.email.smtpSettings")||"SMTP Configuration"})}),a.jsx(Mt,{children:a.jsxs("div",{className:"space-y-4",children:[a.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[a.jsxs("div",{children:[a.jsxs("label",{className:"block text-sm font-medium text-white mb-2",children:[t("settings.email.smtpHost")||"SMTP Server"," *"]}),a.jsx("input",{type:"text",value:r.smtp_host,onChange:x=>i({...r,smtp_host:x.target.value}),placeholder:"smtp.gmail.com",className:"w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:t("settings.email.smtpPort")||"SMTP Port"}),a.jsx("input",{type:"number",value:r.smtp_port,onChange:x=>i({...r,smtp_port:parseInt(x.target.value)||587}),placeholder:"587",className:"w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors"})]})]}),a.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:t("settings.email.security")||"Security"}),a.jsxs("select",{value:r.smtp_security,onChange:x=>i({...r,smtp_security:x.target.value}),className:"w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors",children:[a.jsx("option",{value:"starttls",children:"STARTTLS (Port 587)"}),a.jsx("option",{value:"ssl",children:"SSL/TLS (Port 465)"}),a.jsx("option",{value:"none",children:"None (Port 25)"})]})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:t("settings.email.authentication")||"Authentication"}),a.jsxs("select",{value:r.smtp_auth_enabled?"true":"false",onChange:x=>i({...r,smtp_auth_enabled:x.target.value==="true"}),className:"w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors",children:[a.jsx("option",{value:"true",children:"Enabled"}),a.jsx("option",{value:"false",children:"Disabled"})]})]})]}),r.smtp_auth_enabled&&a.jsxs(a.Fragment,{children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:t("settings.email.username")||"Username"}),a.jsx("input",{type:"text",value:r.smtp_username||"",onChange:x=>i({...r,smtp_username:x.target.value}),placeholder:"your.email@gmail.com",className:"w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:t("settings.email.password")||"Password"}),a.jsx("input",{type:"password",value:r.smtp_password||"",onChange:x=>i({...r,smtp_password:x.target.value}),placeholder:l?"••••••••":"App password",className:"w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors"})]})]}),a.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[a.jsxs("div",{children:[a.jsxs("label",{className:"block text-sm font-medium text-white mb-2",children:[t("settings.email.fromEmail")||"From Email"," *"]}),a.jsx("input",{type:"email",value:r.smtp_from_email,onChange:x=>i({...r,smtp_from_email:x.target.value}),placeholder:"your@email.com",className:"w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:t("settings.email.fromName")||"From Name"}),a.jsx("input",{type:"text",value:r.smtp_from_name,onChange:x=>i({...r,smtp_from_name:x.target.value}),placeholder:"BamBuddy",className:"w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors"})]})]}),a.jsx("div",{className:"flex gap-2",children:a.jsx(ke,{onClick:p,disabled:d.isPending,className:"flex-1",children:d.isPending?a.jsxs(a.Fragment,{children:[a.jsx(ut,{className:"w-4 h-4 animate-spin"}),t("settings.email.saving")||"Saving..."]}):t("settings.email.save")||"Save Settings"})})]})})]}),a.jsxs(_t,{children:[a.jsx(Pn,{children:a.jsx("h2",{className:"text-lg font-semibold text-white",children:t("settings.email.testConnection")||"Test SMTP Connection"})}),a.jsx(Mt,{children:a.jsxs("div",{className:"space-y-4",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:t("settings.email.testRecipient")||"Test Recipient Email"}),a.jsx("input",{type:"email",value:s,onChange:x=>o(x.target.value),placeholder:"test@example.com",className:"w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors"})]}),a.jsx(ke,{onClick:b,disabled:h.isPending,variant:"secondary",children:h.isPending?a.jsxs(a.Fragment,{children:[a.jsx(ut,{className:"w-4 h-4 animate-spin"}),t("settings.email.sending")||"Sending..."]}):a.jsxs(a.Fragment,{children:[a.jsx($M,{className:"w-4 h-4"}),t("settings.email.sendTest")||"Send Test Email"]})})]})})]}),u?.smtp_configured&&a.jsxs(_t,{children:[a.jsx(Pn,{children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(oy,{className:"w-5 h-5 text-bambu-green"}),a.jsx("h2",{className:"text-lg font-semibold text-white",children:t("settings.email.advancedAuth")||"Advanced Authentication"})]}),a.jsx(ke,{onClick:v,disabled:m.isPending,variant:u?.advanced_auth_enabled?"danger":"primary",children:u?.advanced_auth_enabled?a.jsxs(a.Fragment,{children:[a.jsx(j1,{className:"w-4 h-4"}),t("settings.email.disable")||"Disable"]}):a.jsxs(a.Fragment,{children:[a.jsx(P1,{className:"w-4 h-4"}),t("settings.email.enable")||"Enable"]})})]})}),a.jsx(Mt,{children:a.jsx("div",{className:"space-y-4",children:u?.advanced_auth_enabled?a.jsx("div",{className:"bg-green-500/10 border border-green-500/30 rounded-lg p-4",children:a.jsxs("div",{className:"flex items-start gap-3",children:[a.jsx(Nr,{className:"w-5 h-5 text-green-400 mt-0.5 flex-shrink-0"}),a.jsxs("div",{className:"space-y-2",children:[a.jsx("p",{className:"text-white font-medium",children:t("settings.email.advancedAuthEnabled")||"Advanced Authentication is enabled"}),a.jsxs("ul",{className:"text-sm text-green-300 space-y-1 list-disc list-inside",children:[a.jsx("li",{children:t("settings.email.feature1")||"Passwords are auto-generated and emailed to new users"}),a.jsx("li",{children:t("settings.email.feature2")||"Users can login with username or email"}),a.jsx("li",{children:t("settings.email.feature3")||"Forgot password feature is available"}),a.jsx("li",{children:t("settings.email.feature4")||"Admins can reset user passwords via email"})]})]})]})}):a.jsx("div",{className:"bg-yellow-500/10 border border-yellow-500/30 rounded-lg p-4",children:a.jsxs("div",{className:"flex items-start gap-3",children:[a.jsx(kn,{className:"w-5 h-5 text-yellow-400 mt-0.5 flex-shrink-0"}),a.jsxs("div",{className:"space-y-2",children:[a.jsx("p",{className:"text-white font-medium",children:t("settings.email.advancedAuthDisabled")||"Advanced Authentication is disabled"}),a.jsx("p",{className:"text-sm text-yellow-300",children:t("settings.email.advancedAuthDisabledDesc")||"Enable advanced authentication to activate email-based features for user management."})]})]})})})})]})]})}const oQe={get:"bg-blue-500/20 text-blue-400 border-blue-500/30",post:"bg-green-500/20 text-green-400 border-green-500/30",put:"bg-yellow-500/20 text-yellow-400 border-yellow-500/30",patch:"bg-orange-500/20 text-orange-400 border-orange-500/30",delete:"bg-red-500/20 text-red-400 border-red-500/30"};function lQe(t,e){const n=e.replace("#/","").split("/");let r=t;for(const i of n)r=r[i];return r}function T0(t,e,n=0){if(n>5)return"...";if(e.$ref)return T0(t,lQe(t,e.$ref),n+1);if(e.allOf){const r={};for(const i of e.allOf){const s=T0(t,i,n+1);typeof s=="object"&&s!==null&&Object.assign(r,s)}return r}if(e.example!==void 0)return e.example;if(e.default!==void 0)return e.default;switch(e.type){case"string":return e.enum?e.enum[0]:"string";case"integer":case"number":return 0;case"boolean":return!1;case"array":return e.items?[T0(t,e.items,n+1)]:[];case"object":if(e.properties){const r={};for(const[i,s]of Object.entries(e.properties))r[i]=T0(t,s,n+1);return r}return{};default:return null}}function cQe({path:t,method:e,spec:n,schema:r,apiKey:i}){const[s,o]=_.useState(!1),[l,c]=_.useState({}),[u,d]=_.useState(""),[h,m]=_.useState(null),[p,b]=_.useState(!1),[v,x]=_.useState(!1);_.useEffect(()=>{if(s&&n.parameters){const P={};for(const T of n.parameters)T.schema?.default!==void 0&&(P[T.name]=String(T.schema.default));c(T=>({...P,...T}))}},[s,n.parameters]),_.useEffect(()=>{if(s&&n.requestBody?.content?.["application/json"]?.schema&&!u){const P=n.requestBody.content["application/json"].schema,T=T0(r,P);d(JSON.stringify(T,null,2))}},[s,n.requestBody,r,u]);const S=(()=>{const P=[];for(const T of n.parameters||[])if(T.in==="path"||T.required){const j=l[T.name];(j===void 0||j==="")&&P.push(T.name)}return P})(),N=async()=>{if(S.length>0){m({status:0,statusText:"Validation Error",headers:{},body:`Missing required parameters: ${S.join(", ")}`,duration:0});return}b(!0),m(null);try{let P=t;const T=new URLSearchParams;for(const re of n.parameters||[]){const H=l[re.name];H!==void 0&&H!==""&&(re.in==="path"?P=P.replace(`{${re.name}}`,encodeURIComponent(H)):re.in==="query"&&T.append(re.name,H))}const j=T.toString(),z=`${P}${j?`?${j}`:""}`,L={"Content-Type":"application/json"};i&&(L["X-API-Key"]=i);const B={method:e.toUpperCase(),headers:L};["post","put","patch"].includes(e)&&u&&(B.body=u);const R=performance.now(),$=await fetch(z,B),q=Math.round(performance.now()-R),I={};$.headers.forEach((re,H)=>{I[H]=re});let G;$.headers.get("content-type")?.includes("application/json")?G=await $.json():G=await $.text(),m({status:$.status,statusText:$.statusText,headers:I,body:G,duration:q})}catch(P){m({status:0,statusText:"Network Error",headers:{},body:P instanceof Error?P.message:"Unknown error",duration:0})}finally{b(!1)}},A=async()=>{if(h){const P=typeof h.body=="string"?h.body:JSON.stringify(h.body,null,2);try{await navigator.clipboard.writeText(P),x(!0),setTimeout(()=>x(!1),2e3)}catch{const T=document.createElement("textarea");T.value=P,T.style.position="fixed",T.style.left="-999999px",document.body.appendChild(T),T.select(),document.execCommand("copy"),document.body.removeChild(T),x(!0),setTimeout(()=>x(!1),2e3)}}},k=(n.parameters||[]).filter(P=>P.in==="path"),C=(n.parameters||[]).filter(P=>P.in==="query"),E=["post","put","patch"].includes(e)&&n.requestBody;return a.jsxs("div",{className:"border border-bambu-dark-tertiary rounded-lg overflow-hidden",children:[a.jsxs("button",{onClick:()=>o(!s),className:"w-full flex items-center gap-3 p-3 hover:bg-bambu-dark-tertiary/50 transition-colors text-left",children:[s?a.jsx(Sr,{className:"w-4 h-4 text-bambu-gray flex-shrink-0"}):a.jsx(_s,{className:"w-4 h-4 text-bambu-gray flex-shrink-0"}),a.jsx("span",{className:`px-2 py-0.5 text-xs font-mono font-semibold uppercase rounded border ${oQe[e]||"bg-gray-500/20 text-gray-400"}`,children:e}),a.jsx("code",{className:"text-sm text-white font-mono flex-1 truncate",children:t}),n.summary&&a.jsx("span",{className:"text-sm text-bambu-gray truncate max-w-[40%]",children:n.summary})]}),s&&a.jsxs("div",{className:"border-t border-bambu-dark-tertiary p-4 space-y-4 bg-bambu-dark/50",children:[n.description&&a.jsx("p",{className:"text-sm text-bambu-gray",children:n.description}),k.length>0&&a.jsxs("div",{className:"space-y-2",children:[a.jsx("h4",{className:"text-sm font-medium text-white",children:"Path Parameters"}),a.jsx("div",{className:"space-y-2",children:k.map(P=>a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsxs("label",{className:"text-sm text-bambu-gray w-32 flex-shrink-0",children:[P.name,P.required&&a.jsx("span",{className:"text-red-400 ml-1",children:"*"})]}),a.jsx("input",{type:"text",value:l[P.name]||"",onChange:T=>c(j=>({...j,[P.name]:T.target.value})),placeholder:P.description||P.schema?.type||"value",className:"flex-1 px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm font-mono focus:border-bambu-green focus:outline-none"})]},P.name))})]}),C.length>0&&a.jsxs("div",{className:"space-y-2",children:[a.jsx("h4",{className:"text-sm font-medium text-white",children:"Query Parameters"}),a.jsx("div",{className:"space-y-2",children:C.map(P=>a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsxs("label",{className:"text-sm text-bambu-gray w-32 flex-shrink-0",children:[P.name,P.required&&a.jsx("span",{className:"text-red-400 ml-1",children:"*"})]}),P.schema?.enum?a.jsxs("select",{value:l[P.name]||"",onChange:T=>c(j=>({...j,[P.name]:T.target.value})),className:"flex-1 px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none",children:[a.jsx("option",{value:"",children:"-- Select --"}),P.schema.enum.map(T=>a.jsx("option",{value:T,children:T},T))]}):a.jsx("input",{type:"text",value:l[P.name]||"",onChange:T=>c(j=>({...j,[P.name]:T.target.value})),placeholder:P.description||P.schema?.type||"value",className:"flex-1 px-2 py-1 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm font-mono focus:border-bambu-green focus:outline-none"})]},P.name))})]}),E&&a.jsxs("div",{className:"space-y-2",children:[a.jsx("h4",{className:"text-sm font-medium text-white",children:"Request Body"}),a.jsx("textarea",{value:u,onChange:P=>d(P.target.value),rows:8,className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm font-mono focus:border-bambu-green focus:outline-none resize-y",placeholder:"JSON request body..."})]}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsxs(ke,{onClick:N,disabled:p,children:[p?a.jsx(ut,{className:"w-4 h-4 animate-spin"}):a.jsx(vo,{className:"w-4 h-4"}),"Execute"]}),S.length>0&&a.jsxs("span",{className:"text-xs text-yellow-400 flex items-center gap-1",children:[a.jsx(Wi,{className:"w-3 h-3"}),"Fill in: ",S.join(", ")]})]}),h&&a.jsxs("div",{className:"space-y-2",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("h4",{className:"text-sm font-medium text-white flex items-center gap-2",children:["Response",a.jsxs("span",{className:`px-2 py-0.5 text-xs rounded ${h.status>=200&&h.status<300?"bg-green-500/20 text-green-400":h.status>=400?"bg-red-500/20 text-red-400":"bg-yellow-500/20 text-yellow-400"}`,children:[h.status," ",h.statusText]}),a.jsxs("span",{className:"text-xs text-bambu-gray",children:[h.duration,"ms"]})]}),a.jsx(ke,{variant:"secondary",size:"sm",onClick:A,children:v?a.jsx(Nr,{className:"w-3 h-3 text-green-400"}):a.jsx(Fl,{className:"w-3 h-3"})})]}),a.jsx("pre",{className:"p-3 bg-bambu-dark rounded-lg text-sm font-mono text-white overflow-auto max-h-96 border border-bambu-dark-tertiary",children:typeof h.body=="string"?h.body:JSON.stringify(h.body,null,2)})]})]})]})}function uQe({apiKey:t=""}){const[e,n]=_.useState(null),[r,i]=_.useState(!0),[s,o]=_.useState(null),[l,c]=_.useState(new Set),[u,d]=_.useState("");if(_.useEffect(()=>{async function x(){try{const y=await fetch("/openapi.json");if(!y.ok)throw new Error("Failed to fetch OpenAPI schema");const S=await y.json();n(S)}catch(y){o(y instanceof Error?y.message:"Unknown error")}finally{i(!1)}}x()},[]),r)return a.jsx("div",{className:"flex justify-center py-12",children:a.jsx(ut,{className:"w-8 h-8 text-bambu-green animate-spin"})});if(s||!e)return a.jsx(_t,{children:a.jsx(Mt,{className:"py-8",children:a.jsxs("div",{className:"text-center text-red-400",children:[a.jsx(Wi,{className:"w-12 h-12 mx-auto mb-3 opacity-50"}),a.jsx("p",{children:"Failed to load API schema"}),a.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:s})]})})});const h={};for(const[x,y]of Object.entries(e.paths))for(const[S,N]of Object.entries(y)){if(S==="parameters")continue;const A=N.tags||["Other"];for(const k of A)h[k]||(h[k]=[]),h[k].push({path:x,method:S,spec:N})}const m=Object.entries(h).map(([x,y])=>{if(!u)return{tag:x,endpoints:y};const S=y.filter(({path:N,method:A,spec:k})=>{const C=u.toLowerCase();return N.toLowerCase().includes(C)||A.toLowerCase().includes(C)||(k.summary?.toLowerCase()||"").includes(C)||(k.description?.toLowerCase()||"").includes(C)});return{tag:x,endpoints:S}}).filter(({endpoints:x})=>x.length>0).sort((x,y)=>x.tag.localeCompare(y.tag)),p=x=>{c(y=>{const S=new Set(y);return S.has(x)?S.delete(x):S.add(x),S})},b=()=>{c(new Set(m.map(x=>x.tag)))},v=()=>{c(new Set)};return a.jsxs("div",{className:"space-y-4",children:[a.jsxs("div",{className:"flex items-center justify-between gap-4",children:[a.jsx("div",{className:"flex-1",children:a.jsx("input",{type:"text",value:u,onChange:x=>d(x.target.value),placeholder:"Search endpoints...",className:"w-full max-w-md px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(ke,{variant:"secondary",size:"sm",onClick:b,children:"Expand All"}),a.jsx(ke,{variant:"secondary",size:"sm",onClick:v,children:"Collapse All"}),a.jsxs("a",{href:"/docs",target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1 text-sm text-bambu-green hover:underline",children:[a.jsx(Xr,{className:"w-4 h-4"}),"Swagger UI"]})]})]}),a.jsxs("p",{className:"text-sm text-bambu-gray",children:[m.reduce((x,y)=>x+y.endpoints.length,0)," endpoints in ",m.length," categories"]}),a.jsx("div",{className:"space-y-3",children:m.map(({tag:x,endpoints:y})=>a.jsxs(_t,{children:[a.jsx("button",{onClick:()=>p(x),className:"w-full flex items-center justify-between p-4 hover:bg-bambu-dark-tertiary/30 transition-colors text-left",children:a.jsxs("div",{className:"flex items-center gap-2",children:[l.has(x)?a.jsx(Sr,{className:"w-5 h-5 text-bambu-gray"}):a.jsx(_s,{className:"w-5 h-5 text-bambu-gray"}),a.jsx("h3",{className:"text-base font-semibold text-white capitalize",children:x.replace(/-/g," ")}),a.jsx("span",{className:"text-xs bg-bambu-dark-tertiary px-2 py-0.5 rounded-full text-bambu-gray",children:y.length})]})}),l.has(x)&&a.jsx(Mt,{className:"pt-0 space-y-2",children:y.map(({path:S,method:N,spec:A})=>a.jsx(cQe,{path:S,method:N,spec:A,schema:e,apiKey:t},`${N}-${S}`))})]},x))})]})}const dQe=["general","network","plugs","email","notifications","filament","apikeys","virtual-printer","users","backup"];function hQe(){const t=un(),e=Dc(),[n,r]=YR(),{t:i,i18n:s}=Sn(),{showToast:o}=Hn(),{authEnabled:l,user:c,refreshAuth:u}=Di(),{mode:d,darkStyle:h,darkBackground:m,darkAccent:p,lightStyle:b,lightBackground:v,lightAccent:x,setDarkStyle:y,setDarkBackground:S,setDarkAccent:N,setLightStyle:A,setLightBackground:k,setLightAccent:C}=Vh(),[E,P]=_.useState(null),[T,j]=_.useState(!1),[z,L]=_.useState(null),[B,R]=_.useState(!1),[$,q]=_.useState(null),[I,G]=_.useState(null),[Y,re]=_.useState(!1),[H,K]=_.useState(QK()),ne=n.get("tab"),ie=ne&&dQe.includes(ne)?ne:"general",[be,pe]=_.useState(ie),de=oe=>{pe(oe),oe==="general"?n.delete("tab"):n.set("tab",oe),r(n,{replace:!0})},[Ce,ae]=_.useState(!1),[Ae,Le]=_.useState(""),[fe,Xe]=_.useState({can_queue:!0,can_control_printer:!1,can_read_status:!0}),[W,Q]=_.useState(null),[me,X]=_.useState(null),[te,V]=_.useState(""),[ge,Se]=_.useState(!1),[ee,U]=_.useState(!1),[O,Z]=_.useState(null),[le,we]=_.useState(!1),[ye,se]=_.useState(!1),[Oe,He]=_.useState(!1),[tt,Ue]=_.useState({currentPassword:"",newPassword:"",confirmPassword:""}),[xe,Te]=_.useState(!1),[Ie,Ne]=_.useState(!1),[Ge,Me]=_.useState(!1),[rt,Ee]=_.useState(null),[Ke,Be]=_.useState(null),[ue,$e]=_.useState(null),[at,kt]=_.useState(!1),[gt,Ut]=_.useState({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]}),[Ft,Fe]=_.useState(!1),[xt,Wt]=_.useState(null),[Qt,En]=_.useState(null),[hn,or]=_.useState({name:"",description:"",permissions:[]}),[Kn,Qn]=_.useState(new Set),[Tn,di]=_.useState(null),[ii,je]=_.useState(!1),[Je,dt]=_.useState({}),[ht,ct]=_.useState({}),Tt=oe=>{K(oe),rpe(oe),o(i("settings.toast.settingsSaved"),"success")},he=()=>{localStorage.removeItem("sidebarOrder"),window.location.reload()},{data:De,isLoading:Ve}=st({queryKey:["settings"],queryFn:ce.getSettings}),{data:_e,isLoading:Re}=st({queryKey:["smart-plugs"],queryFn:ce.getSmartPlugs}),{data:et,isLoading:Ye}=st({queryKey:["smart-plugs-energy",_e?.map(oe=>oe.id)],queryFn:async()=>{if(!_e||_e.length===0)return null;const oe=await Promise.all(_e.filter(cs=>cs.enabled).map(async cs=>{try{const ka=await ce.getSmartPlugStatus(cs.id);return{plug:cs,status:ka}}catch{return{plug:cs,status:null}}}));let Nt=0,Un=0,sr=0,To=0,cd=0;for(const{plug:cs,status:ka}of oe){const wk=cs.plug_type==="mqtt"&&ka?.energy?.power!=null;(ka?.reachable||wk)&&ka?.energy&&(cd++,ka.energy?.power!=null&&(Nt+=ka.energy.power),ka.energy?.today!=null&&(Un+=ka.energy.today),ka.energy?.yesterday!=null&&(sr+=ka.energy.yesterday),ka.energy?.total!=null&&(To+=ka.energy.total))}return{totalPower:Nt,totalToday:Un,totalYesterday:sr,totalLifetime:To,reachableCount:cd,totalPlugs:_e.filter(cs=>cs.enabled).length}},enabled:be==="plugs"&&!!_e&&_e.length>0,refetchInterval:be==="plugs"?1e4:!1}),{data:Ct,isLoading:jt}=st({queryKey:["notification-providers"],queryFn:ce.getNotificationProviders}),{data:Bt,isLoading:Rt}=st({queryKey:["api-keys"],queryFn:ce.getAPIKeys}),Et=pt({mutationFn:oe=>ce.createAPIKey(oe),onSuccess:oe=>{Q(oe.key||null),ae(!1),Le(""),t.invalidateQueries({queryKey:["api-keys"]}),o(i("settings.toast.apiKeyCreated"))},onError:oe=>{o(`Failed to create API key: ${oe.message}`,"error")}}),an=pt({mutationFn:oe=>ce.deleteAPIKey(oe),onSuccess:()=>{t.invalidateQueries({queryKey:["api-keys"]}),o(i("settings.toast.apiKeyDeleted"))},onError:oe=>{o(`Failed to delete API key: ${oe.message}`,"error")}}),{data:Vt}=st({queryKey:["printers"],queryFn:ce.getPrinters}),{data:pn,isLoading:fn}=st({queryKey:["notification-templates"],queryFn:ce.getNotificationTemplates}),{data:Cn}=st({queryKey:["virtual-printer-settings"],queryFn:D1.getSettings,refetchInterval:1e4}),Xt=Cn?.status?.running??!1,{data:dn}=st({queryKey:["ffmpeg-status"],queryFn:ce.checkFfmpeg}),{data:mn}=st({queryKey:["version"],queryFn:ce.getVersion}),{data:en,refetch:ir,isRefetching:In}=st({queryKey:["updateCheck"],queryFn:ce.checkForUpdates,staleTime:300*1e3}),{data:ai,refetch:ar}=st({queryKey:["updateStatus"],queryFn:ce.getUpdateStatus,refetchInterval:oe=>{const Nt=oe.state.data;return Nt?.status==="downloading"||Nt?.status==="installing"?1e3:!1}}),{data:fr}=st({queryKey:["mqtt-status"],queryFn:ce.getMQTTStatus,refetchInterval:be==="network"?5e3:!1}),{data:nt}=st({queryKey:["github-backup-status"],queryFn:ce.getGitHubBackupStatus}),{data:Dt}=st({queryKey:["cloud-status"],queryFn:ce.getCloudStatus}),{data:Kt={advanced_auth_enabled:!1,smtp_configured:!1}}=st({queryKey:["advancedAuthStatus"],queryFn:()=>ce.getAdvancedAuthStatus()}),{hasPermission:vt}=Di(),{data:Nn=[],isLoading:hi}=st({queryKey:["users"],queryFn:()=>ce.getUsers(),enabled:l&&vt("users:read")}),{data:xr=[],isLoading:Yr}=st({queryKey:["groups"],queryFn:()=>ce.getGroups(),enabled:l&&vt("groups:read")}),{data:No}=st({queryKey:["permissions"],queryFn:()=>ce.getPermissions(),enabled:l&&vt("groups:read")}),nn=pt({mutationFn:oe=>ce.createUser(oe),onSuccess:()=>{t.invalidateQueries({queryKey:["users"]}),t.invalidateQueries({queryKey:["groups"]}),Ne(!1),Ut({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]}),o(i("settings.toast.userCreated"))},onError:oe=>{o(oe.message,"error")}}),Mn=pt({mutationFn:({id:oe,data:Nt})=>ce.updateUser(oe,Nt),onSuccess:()=>{t.invalidateQueries({queryKey:["users"]}),t.invalidateQueries({queryKey:["groups"]}),Me(!1),Ee(null),Ut({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]}),o(i("settings.toast.userUpdated"))},onError:oe=>{o(oe.message,"error")}}),Mr=pt({mutationFn:({id:oe,deleteItems:Nt})=>ce.deleteUser(oe,Nt),onSuccess:()=>{t.invalidateQueries({queryKey:["users"]}),o(i("settings.toast.userDeleted")),Be(null),$e(null)},onError:oe=>{o(oe.message,"error")}}),Mo=async oe=>{Be(oe),kt(!0);try{const Nt=await ce.getUserItemsCount(oe);$e(Nt)}catch{$e({archives:0,queue_items:0,library_files:0})}finally{kt(!1)}},ko=pt({mutationFn:oe=>ce.createGroup(oe),onSuccess:()=>{t.invalidateQueries({queryKey:["groups"]}),Fe(!1),pr(),o(i("settings.toast.groupCreated"))},onError:oe=>{o(oe.message,"error")}}),As=pt({mutationFn:({id:oe,data:Nt})=>ce.updateGroup(oe,Nt),onSuccess:()=>{t.invalidateQueries({queryKey:["groups"]}),Wt(null),pr(),o(i("settings.toast.groupUpdated"))},onError:oe=>{o(oe.message,"error")}}),Eo=pt({mutationFn:oe=>ce.deleteGroup(oe),onSuccess:()=>{t.invalidateQueries({queryKey:["groups"]}),o(i("settings.toast.groupDeleted"))},onError:oe=>{o(oe.message,"error")}}),ls=()=>{const oe=Kt?.advanced_auth_enabled||!1;if(!gt.username){o(i("settings.toast.fillRequiredFields"),"error");return}if(oe&&!gt.email){o("Email is required when advanced authentication is enabled","error");return}if(!oe){if(!gt.password){o(i("settings.toast.fillRequiredFields"),"error");return}if(gt.password!==gt.confirmPassword){o(i("settings.toast.passwordsDoNotMatch"),"error");return}if(gt.password.length<6){o(i("settings.toast.passwordTooShort"),"error");return}}nn.mutate({username:gt.username,password:oe?void 0:gt.password,email:gt.email||void 0,role:gt.role,group_ids:gt.group_ids.length>0?gt.group_ids:void 0})},Ei=oe=>{if(gt.password){if(gt.password!==gt.confirmPassword){o(i("settings.toast.passwordsDoNotMatch"),"error");return}if(gt.password.length<6){o(i("settings.toast.passwordTooShort"),"error");return}}const Nt={username:gt.username||void 0,password:gt.password||void 0,role:gt.role,group_ids:gt.group_ids};Nt.password||delete Nt.password,Mn.mutate({id:oe,data:Nt})},Ao=oe=>{Ee(oe.id),Ut({username:oe.username,password:"",confirmPassword:"",role:oe.role,group_ids:oe.groups?.map(Nt=>Nt.id)||[]}),Me(!0)},Ts=oe=>{Ut(Nt=>({...Nt,group_ids:Nt.group_ids.includes(oe)?Nt.group_ids.filter(Un=>Un!==oe):[...Nt.group_ids,oe]}))},pr=()=>{or({name:"",description:"",permissions:[]}),Qn(new Set)},Zb=()=>{if(!hn.name.trim()){o(i("settings.toast.enterGroupName"),"error");return}ko.mutate({name:hn.name,description:hn.description||void 0,permissions:hn.permissions})},tf=()=>{if(xt){if(!hn.name.trim()){o(i("settings.toast.enterGroupName"),"error");return}As.mutate({id:xt.id,data:{name:hn.name!==xt.name?hn.name:void 0,description:hn.description,permissions:hn.permissions}})}},ql=oe=>{Wt(oe),or({name:oe.name,description:oe.description||"",permissions:oe.permissions});const Nt=new Set;No?.categories.forEach(Un=>{Un.permissions.some(sr=>oe.permissions.includes(sr.value))&&Nt.add(Un.name)}),Qn(Nt)},Jb=oe=>{Qn(Nt=>{const Un=new Set(Nt);return Un.has(oe)?Un.delete(oe):Un.add(oe),Un})},Ym=oe=>{or(Nt=>{const Un=Nt.permissions.includes(oe)?Nt.permissions.filter(sr=>sr!==oe):[...Nt.permissions,oe];return{...Nt,permissions:Un}})},Lv=(oe,Nt)=>{or(Un=>{const sr=oe.permissions.map(cs=>cs.value),To=Un.permissions.filter(cs=>!sr.includes(cs)),cd=Nt?[...To,...sr]:To;return{...Un,permissions:cd}})},ad=oe=>oe.permissions.every(Nt=>hn.permissions.includes(Nt.value)),nf=oe=>{const Nt=oe.permissions.filter(Un=>hn.permissions.includes(Un.value));return Nt.length>0&&Nt.length{oe.is_docker?o(oe.message,"error"):ar()}}),[Ai,gl]=_.useState(null),sd=pt({mutationFn:ce.testAllNotificationProviders,onSuccess:oe=>{gl(oe),t.invalidateQueries({queryKey:["notification-providers"]}),oe.failed===0?o(`All ${oe.tested} providers tested successfully!`,"success"):o(`${oe.success}/${oe.tested} providers succeeded`,oe.failed>0?"error":"success")},onError:oe=>{o(`Failed to test providers: ${oe.message}`,"error")}}),bl=pt({mutationFn:async oe=>{if(!_e)return{success:0,failed:0};const Nt=_e.filter(sr=>sr.enabled),Un=await Promise.all(Nt.map(async sr=>{try{return await ce.controlSmartPlug(sr.id,oe),{success:!0}}catch{return{success:!1}}}));return{success:Un.filter(sr=>sr.success).length,failed:Un.filter(sr=>!sr.success).length}},onSuccess:(oe,Nt)=>{t.invalidateQueries({queryKey:["smart-plugs"]}),t.invalidateQueries({queryKey:["smart-plugs-energy"]}),oe.failed===0?o(`All ${oe.success} plugs turned ${Nt}`,"success"):o(`${oe.success} plugs turned ${Nt}, ${oe.failed} failed`,"error")},onError:oe=>{o(`Failed: ${oe.message}`,"error")}}),rf=_.useRef(null),od=_.useRef(!1),Zm=_.useRef(!0);_.useEffect(()=>{if(De&&!E){const oe={...De,external_url:De.external_url||window.location.origin};P(oe),setTimeout(()=>{Zm.current=!1},100)}},[De,E]);const ld=pt({mutationFn:ce.updateSettings,onSuccess:oe=>{t.setQueryData(["settings"],oe),P(oe),t.invalidateQueries({queryKey:["archiveStats"]}),o(i("settings.toast.settingsSaved"),"success")},onError:oe=>{o(`Failed to save: ${oe.message}`,"error")},onSettled:()=>{od.current=!1}}),af=pt({mutationFn:({id:oe,data:Nt})=>ce.updatePrinter(oe,Nt),onSuccess:()=>{t.invalidateQueries({queryKey:["printers"]}),o(i("settings.toast.cameraSettingsSaved"),"success")},onError:oe=>{o(`Failed to update printer: ${oe.message}`,"error")}});_.useEffect(()=>{if(!(Zm.current||!E||!De||!(De.auto_archive!==E.auto_archive||De.save_thumbnails!==E.save_thumbnails||De.capture_finish_photo!==E.capture_finish_photo||De.default_filament_cost!==E.default_filament_cost||De.currency!==E.currency||De.energy_cost_per_kwh!==E.energy_cost_per_kwh||De.energy_tracking_mode!==E.energy_tracking_mode||De.check_updates!==E.check_updates||(De.check_printer_firmware??!0)!==(E.check_printer_firmware??!0)||De.notification_language!==E.notification_language||De.ams_humidity_good!==E.ams_humidity_good||De.ams_humidity_fair!==E.ams_humidity_fair||De.ams_temp_good!==E.ams_temp_good||De.ams_temp_fair!==E.ams_temp_fair||De.ams_history_retention_days!==E.ams_history_retention_days||De.per_printer_mapping_expanded!==E.per_printer_mapping_expanded||De.date_format!==E.date_format||De.time_format!==E.time_format||De.default_printer_id!==E.default_printer_id||De.ftp_retry_enabled!==E.ftp_retry_enabled||De.ftp_retry_count!==E.ftp_retry_count||De.ftp_retry_delay!==E.ftp_retry_delay||De.ftp_timeout!==E.ftp_timeout||De.mqtt_enabled!==E.mqtt_enabled||De.mqtt_broker!==E.mqtt_broker||De.mqtt_port!==E.mqtt_port||De.mqtt_username!==E.mqtt_username||De.mqtt_password!==E.mqtt_password||De.mqtt_topic_prefix!==E.mqtt_topic_prefix||De.mqtt_use_tls!==E.mqtt_use_tls||De.external_url!==E.external_url||De.ha_enabled!==E.ha_enabled||De.ha_url!==E.ha_url||De.ha_token!==E.ha_token||(De.library_archive_mode??"ask")!==(E.library_archive_mode??"ask")||Number(De.library_disk_warning_gb??5)!==Number(E.library_disk_warning_gb??5)||(De.camera_view_mode??"window")!==(E.camera_view_mode??"window")||De.prometheus_enabled!==E.prometheus_enabled||De.prometheus_token!==E.prometheus_token))&&!od.current)return rf.current&&clearTimeout(rf.current),rf.current=setTimeout(()=>{if(od.current)return;od.current=!0;const Nt={auto_archive:E.auto_archive,save_thumbnails:E.save_thumbnails,capture_finish_photo:E.capture_finish_photo,default_filament_cost:E.default_filament_cost,currency:E.currency,energy_cost_per_kwh:E.energy_cost_per_kwh,energy_tracking_mode:E.energy_tracking_mode,check_updates:E.check_updates,check_printer_firmware:E.check_printer_firmware,notification_language:E.notification_language,ams_humidity_good:E.ams_humidity_good,ams_humidity_fair:E.ams_humidity_fair,ams_temp_good:E.ams_temp_good,ams_temp_fair:E.ams_temp_fair,ams_history_retention_days:E.ams_history_retention_days,per_printer_mapping_expanded:E.per_printer_mapping_expanded,date_format:E.date_format,time_format:E.time_format,default_printer_id:E.default_printer_id,ftp_retry_enabled:E.ftp_retry_enabled,ftp_retry_count:E.ftp_retry_count,ftp_retry_delay:E.ftp_retry_delay,ftp_timeout:E.ftp_timeout,mqtt_enabled:E.mqtt_enabled,mqtt_broker:E.mqtt_broker,mqtt_port:E.mqtt_port,mqtt_username:E.mqtt_username,mqtt_password:E.mqtt_password,mqtt_topic_prefix:E.mqtt_topic_prefix,mqtt_use_tls:E.mqtt_use_tls,external_url:E.external_url,ha_enabled:E.ha_enabled,ha_url:E.ha_url,ha_token:E.ha_token,library_archive_mode:E.library_archive_mode,library_disk_warning_gb:E.library_disk_warning_gb,camera_view_mode:E.camera_view_mode,prometheus_enabled:E.prometheus_enabled,prometheus_token:E.prometheus_token};ld.mutate(Nt)},500),()=>{rf.current&&clearTimeout(rf.current)}},[E,De,ld]);const wn=_.useCallback((oe,Nt)=>{P(Un=>Un?{...Un,[oe]:Nt}:null)},[]),yk=async(oe,Nt,Un)=>{if(!Nt){o(i("settings.toast.enterCameraUrl"),"error");return}ct(sr=>({...sr,[oe]:!0})),dt(sr=>({...sr,[oe]:null}));try{const sr=await ce.testExternalCamera(oe,Nt,Un);dt(To=>({...To,[oe]:sr})),sr.success?o(i("settings.toast.cameraConnected",{resolution:sr.resolution||""}),"success"):o(sr.error||i("settings.toast.connectionFailed"),"error")}catch(sr){const To=sr instanceof Error?sr.message:i("settings.toast.testFailed");dt(cd=>({...cd,[oe]:{success:!1,error:To}})),o(To,"error")}finally{ct(sr=>({...sr,[oe]:!1}))}},[ex,Fv]=_.useState({}),sf=_.useRef({}),Iv=_.useRef(new Set);_.useEffect(()=>{if(Vt){const oe={};Vt.forEach(Nt=>{Nt.external_camera_url&&!Iv.current.has(Nt.id)&&(oe[Nt.id]=Nt.external_camera_url,Iv.current.add(Nt.id))}),Object.keys(oe).length>0&&Fv(Nt=>({...Nt,...oe}))}},[Vt]);const vk=(oe,Nt)=>{Fv(Un=>({...Un,[oe]:Nt})),sf.current[oe]&&clearTimeout(sf.current[oe]),sf.current[oe]=setTimeout(()=>{af.mutate({id:oe,data:{external_camera_url:Nt||null}})},800)},Uv=(oe,Nt)=>{const Un={};Nt.type!==void 0&&(Un.external_camera_type=Nt.type||null),Nt.enabled!==void 0&&(Un.external_camera_enabled=Nt.enabled),af.mutate({id:oe,data:Un})};return Ve||!E?a.jsx("div",{className:"p-4 md:p-8 flex justify-center",children:a.jsx(ut,{className:"w-8 h-8 text-bambu-green animate-spin"})}):a.jsxs("div",{className:"p-4 md:p-8",children:[a.jsxs("div",{className:"mb-8",children:[a.jsx("h1",{className:"text-2xl font-bold text-white",children:i("settings.title")}),a.jsx("p",{className:"text-bambu-gray",children:i("settings.configureBambuddy")})]}),a.jsxs("div",{className:"flex flex-wrap gap-1 mb-6 border-b border-bambu-dark-tertiary overflow-y-auto max-h-32",children:[a.jsx("button",{onClick:()=>de("general"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px ${be==="general"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:i("settings.tabs.general")}),a.jsxs("button",{onClick:()=>de("plugs"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${be==="plugs"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[a.jsx(rl,{className:"w-4 h-4"}),i("settings.tabs.smartPlugs"),_e&&_e.length>0&&a.jsx("span",{className:"text-xs bg-bambu-dark-tertiary px-1.5 py-0.5 rounded-full",children:_e.length})]}),a.jsxs("button",{onClick:()=>de("email"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${be==="email"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[a.jsx(oy,{className:"w-4 h-4"}),i("settings.tabs.globalEmail")||"Global Email"]}),a.jsxs("button",{onClick:()=>de("notifications"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${be==="notifications"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[a.jsx(Og,{className:"w-4 h-4"}),i("settings.tabs.notifications"),Ct&&Ct.length>0&&a.jsx("span",{className:"text-xs bg-bambu-dark-tertiary px-1.5 py-0.5 rounded-full",children:Ct.length})]}),a.jsxs("button",{onClick:()=>de("filament"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${be==="filament"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[a.jsx(Ude,{className:"w-4 h-4"}),i("settings.tabs.filament")]}),a.jsxs("button",{onClick:()=>de("network"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${be==="network"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[a.jsx(Fg,{className:"w-4 h-4"}),i("settings.tabs.network"),a.jsx("span",{className:`w-2 h-2 rounded-full ${fr?.enabled?"bg-green-400":"bg-gray-500"}`})]}),a.jsxs("button",{onClick:()=>de("apikeys"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${be==="apikeys"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[a.jsx(Wo,{className:"w-4 h-4"}),i("settings.tabs.apiKeys"),Bt&&Bt.length>0&&a.jsx("span",{className:"text-xs bg-bambu-dark-tertiary px-1.5 py-0.5 rounded-full",children:Bt.length})]}),a.jsxs("button",{onClick:()=>de("virtual-printer"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${be==="virtual-printer"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[a.jsx(Or,{className:"w-4 h-4"}),i("settings.tabs.virtualPrinter"),a.jsx("span",{className:`w-2 h-2 rounded-full ${Xt?"bg-green-400":"bg-gray-500"}`})]}),a.jsxs("button",{onClick:()=>de("users"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${be==="users"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[a.jsx(Kf,{className:"w-4 h-4"}),i("settings.tabs.users"),l&&a.jsx("span",{className:"w-2 h-2 rounded-full bg-green-400"})]}),a.jsxs("button",{onClick:()=>de("backup"),className:`px-4 py-2 text-sm font-medium transition-colors border-b-2 -mb-px flex items-center gap-2 ${be==="backup"?"text-bambu-green border-bambu-green":"text-bambu-gray hover:text-gray-900 dark:hover:text-white border-transparent"}`,children:[a.jsx(ju,{className:"w-4 h-4"}),i("settings.tabs.backup"),a.jsx("span",{className:`w-2 h-2 rounded-full ${Dt?.is_authenticated&&nt?.configured&&nt?.enabled?"bg-green-400":"bg-gray-500"}`})]})]}),be==="general"&&a.jsxs("div",{className:"flex flex-col lg:flex-row gap-6 lg:gap-8",children:[a.jsxs("div",{className:"space-y-6 flex-1 lg:max-w-xl",children:[a.jsxs(_t,{children:[a.jsx(Pn,{children:a.jsx("h2",{className:"text-lg font-semibold text-white",children:i("settings.general")})}),a.jsxs(Mt,{className:"space-y-4",children:[a.jsxs("div",{children:[a.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[a.jsx(bh,{className:"w-4 h-4 inline mr-1"}),i("settings.language")]}),a.jsxs("div",{className:"relative",children:[a.jsx("select",{value:s.language,onChange:oe=>{s.changeLanguage(oe.target.value),o(i("settings.toast.settingsSaved"),"success")},className:"w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer",children:Wz.map(oe=>a.jsxs("option",{value:oe.code,children:[oe.nativeName," (",oe.name,")"]},oe.code))}),a.jsx(Sr,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:i("settings.languageDescription")})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:i("settings.defaultView")}),a.jsxs("div",{className:"relative",children:[a.jsx("select",{value:H,onChange:oe=>Tt(oe.target.value),className:"w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer",children:cy.map(oe=>a.jsx("option",{value:oe.to,children:i(oe.labelKey)},oe.id))}),a.jsx(Sr,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:i("settings.defaultViewDescription")})]}),a.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Date Format"}),a.jsxs("div",{className:"relative",children:[a.jsxs("select",{value:E.date_format||"system",onChange:oe=>wn("date_format",oe.target.value),className:"w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer",children:[a.jsx("option",{value:"system",children:i("settings.systemDefault")}),a.jsx("option",{value:"us",children:"US (MM/DD/YYYY)"}),a.jsx("option",{value:"eu",children:"EU (DD/MM/YYYY)"}),a.jsx("option",{value:"iso",children:"ISO (YYYY-MM-DD)"})]}),a.jsx(Sr,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Time Format"}),a.jsxs("div",{className:"relative",children:[a.jsxs("select",{value:E.time_format||"system",onChange:oe=>wn("time_format",oe.target.value),className:"w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer",children:[a.jsx("option",{value:"system",children:i("settings.systemDefault")}),a.jsx("option",{value:"12h",children:"12-hour (3:30 PM)"}),a.jsx("option",{value:"24h",children:"24-hour (15:30)"})]}),a.jsx(Sr,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]})]})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Default Printer"}),a.jsxs("div",{className:"relative",children:[a.jsxs("select",{value:E.default_printer_id??"",onChange:oe=>wn("default_printer_id",oe.target.value?Number(oe.target.value):null),className:"w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer",children:[a.jsx("option",{value:"",children:i("settings.noDefaultPrinter")}),Vt?.map(oe=>a.jsx("option",{value:oe.id,children:oe.name},oe.id))]}),a.jsx(Sr,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Pre-select this printer for uploads, reprints, and other operations."})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white",children:i("settings.sidebarOrder")}),a.jsx("p",{className:"text-sm text-bambu-gray",children:"Drag items in the sidebar to reorder. Reset to default order here."})]}),a.jsxs(ke,{variant:"secondary",size:"sm",onClick:he,children:[a.jsx($h,{className:"w-4 h-4"}),"Reset"]})]})]})]}),a.jsxs(_t,{children:[a.jsx(Pn,{children:a.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[a.jsx(UK,{className:"w-5 h-5"}),"Appearance"]})}),a.jsxs(Mt,{className:"space-y-6",children:[a.jsxs("div",{className:`space-y-3 p-4 rounded-lg border ${d==="dark"?"border-bambu-green bg-bambu-green/5":"border-bambu-dark-tertiary"}`,children:[a.jsxs("h3",{className:"text-sm font-medium text-white flex items-center gap-2",children:["Dark Mode",d==="dark"&&a.jsx("span",{className:"text-xs text-bambu-green",children:"(active)"})]}),a.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Background"}),a.jsxs("select",{value:m,onChange:oe=>{S(oe.target.value),o(i("settings.toast.settingsSaved"),"success")},className:"w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[a.jsx("option",{value:"neutral",children:"Neutral"}),a.jsx("option",{value:"warm",children:"Warm"}),a.jsx("option",{value:"cool",children:"Cool"}),a.jsx("option",{value:"oled",children:"OLED Black"}),a.jsx("option",{value:"slate",children:"Slate Blue"}),a.jsx("option",{value:"forest",children:"Forest Green"})]})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Accent"}),a.jsxs("select",{value:p,onChange:oe=>{N(oe.target.value),o(i("settings.toast.settingsSaved"),"success")},className:"w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[a.jsx("option",{value:"green",children:"Green"}),a.jsx("option",{value:"teal",children:"Teal"}),a.jsx("option",{value:"blue",children:"Blue"}),a.jsx("option",{value:"orange",children:"Orange"}),a.jsx("option",{value:"purple",children:"Purple"}),a.jsx("option",{value:"red",children:"Red"})]})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Style"}),a.jsxs("select",{value:h,onChange:oe=>{y(oe.target.value),o(i("settings.toast.settingsSaved"),"success")},className:"w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[a.jsx("option",{value:"classic",children:"Classic"}),a.jsx("option",{value:"glow",children:"Glow"}),a.jsx("option",{value:"vibrant",children:"Vibrant"})]})]})]})]}),a.jsxs("div",{className:`space-y-3 p-4 rounded-lg border ${d==="light"?"border-bambu-green bg-bambu-green/5":"border-bambu-dark-tertiary"}`,children:[a.jsxs("h3",{className:"text-sm font-medium text-white flex items-center gap-2",children:["Light Mode",d==="light"&&a.jsx("span",{className:"text-xs text-bambu-green",children:"(active)"})]}),a.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Background"}),a.jsxs("select",{value:v,onChange:oe=>{k(oe.target.value),o(i("settings.toast.settingsSaved"),"success")},className:"w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[a.jsx("option",{value:"neutral",children:"Neutral"}),a.jsx("option",{value:"warm",children:"Warm"}),a.jsx("option",{value:"cool",children:"Cool"})]})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Accent"}),a.jsxs("select",{value:x,onChange:oe=>{C(oe.target.value),o(i("settings.toast.settingsSaved"),"success")},className:"w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[a.jsx("option",{value:"green",children:"Green"}),a.jsx("option",{value:"teal",children:"Teal"}),a.jsx("option",{value:"blue",children:"Blue"}),a.jsx("option",{value:"orange",children:"Orange"}),a.jsx("option",{value:"purple",children:"Purple"}),a.jsx("option",{value:"red",children:"Red"})]})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-xs text-bambu-gray mb-1",children:"Style"}),a.jsxs("select",{value:b,onChange:oe=>{A(oe.target.value),o(i("settings.toast.settingsSaved"),"success")},className:"w-full px-2 py-1.5 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[a.jsx("option",{value:"classic",children:"Classic"}),a.jsx("option",{value:"glow",children:"Glow"}),a.jsx("option",{value:"vibrant",children:"Vibrant"})]})]})]})]}),a.jsx("p",{className:"text-xs text-bambu-gray",children:"Toggle between dark and light mode using the sun/moon icon in the sidebar."})]})]}),a.jsxs(_t,{children:[a.jsx(Pn,{children:a.jsx("h2",{className:"text-lg font-semibold text-white",children:i("settings.archiveSettings")})}),a.jsxs(Mt,{className:"space-y-4",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white",children:"Auto-archive prints"}),a.jsx("p",{className:"text-sm text-bambu-gray",children:"Automatically save 3MF files when prints complete"})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:E.auto_archive,onChange:oe=>wn("auto_archive",oe.target.checked),className:"sr-only peer"}),a.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white",children:i("settings.saveThumbnails")}),a.jsx("p",{className:"text-sm text-bambu-gray",children:"Extract and save preview images from 3MF files"})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:E.save_thumbnails,onChange:oe=>wn("save_thumbnails",oe.target.checked),className:"sr-only peer"}),a.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white",children:i("settings.captureFinishPhoto")}),a.jsx("p",{className:"text-sm text-bambu-gray",children:"Take a photo from printer camera when print completes"})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:E.capture_finish_photo,onChange:oe=>wn("capture_finish_photo",oe.target.checked),className:"sr-only peer"}),a.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),E.capture_finish_photo&&dn&&!dn.installed&&a.jsxs("div",{className:"flex items-start gap-2 p-3 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[a.jsx(kn,{className:"w-5 h-5 text-yellow-500 flex-shrink-0 mt-0.5"}),a.jsxs("div",{className:"text-sm",children:[a.jsx("p",{className:"text-yellow-500 font-medium",children:"ffmpeg not installed"}),a.jsxs("p",{className:"text-bambu-gray mt-1",children:["Camera capture requires ffmpeg. Install it via"," ",a.jsx("code",{className:"bg-bambu-dark-tertiary px-1 rounded",children:"brew install ffmpeg"})," (macOS) or"," ",a.jsx("code",{className:"bg-bambu-dark-tertiary px-1 rounded",children:"apt install ffmpeg"})," (Linux)."]})]})]})]})]})]}),a.jsxs("div",{className:"space-y-6 flex-1 lg:max-w-md",children:[a.jsxs(_t,{children:[a.jsx(Pn,{children:a.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[a.jsx(hO,{className:"w-5 h-5 text-bambu-green"}),"Camera"]})}),a.jsxs(Mt,{className:"space-y-4",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Camera View Mode"}),a.jsxs("select",{value:E.camera_view_mode??"window",onChange:oe=>wn("camera_view_mode",oe.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[a.jsx("option",{value:"window",children:i("settings.newWindow")}),a.jsx("option",{value:"embedded",children:i("settings.embeddedOverlay")})]}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:E.camera_view_mode==="embedded"?"Camera opens in a resizable overlay on the main screen":"Camera opens in a separate browser window"})]}),a.jsxs("div",{className:"border-t border-bambu-dark-tertiary pt-4 mt-4",children:[a.jsx("h3",{className:"text-sm font-medium text-white mb-2",children:i("settings.externalCameras")}),a.jsx("p",{className:"text-xs text-bambu-gray mb-3",children:"Configure external cameras to replace the built-in printer camera. Supports MJPEG streams, RTSP, HTTP snapshots, and USB cameras (V4L2). When enabled, the external camera is used for live view and finish photos."}),Vt&&Vt.length>0?a.jsx("div",{className:"space-y-3",children:Vt.map(oe=>a.jsxs("div",{className:"p-3 bg-bambu-dark rounded-lg",children:[a.jsxs("div",{className:"flex items-center justify-between mb-2",children:[a.jsx("span",{className:"text-white font-medium text-sm",children:oe.name}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:oe.external_camera_enabled,onChange:Nt=>Uv(oe.id,{enabled:Nt.target.checked}),className:"sr-only peer"}),a.jsx("div",{className:"w-9 h-5 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-bambu-green"})]})]}),oe.external_camera_enabled&&a.jsxs("div",{className:"space-y-2 mt-2",children:[a.jsx("input",{type:"text",placeholder:oe.external_camera_type==="usb"?"Device path (/dev/video0)":"Camera URL (rtsp://... or http://...)",value:ex[oe.id]??oe.external_camera_url??"",onChange:Nt=>vk(oe.id,Nt.target.value),className:"w-full px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none"}),a.jsxs("div",{className:"flex gap-2",children:[a.jsxs("select",{value:oe.external_camera_type||"mjpeg",onChange:Nt=>Uv(oe.id,{type:Nt.target.value}),className:"flex-1 px-3 py-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded text-white text-sm focus:border-bambu-green focus:outline-none",children:[a.jsx("option",{value:"mjpeg",children:"MJPEG Stream"}),a.jsx("option",{value:"rtsp",children:"RTSP Stream"}),a.jsx("option",{value:"snapshot",children:"HTTP Snapshot"}),a.jsx("option",{value:"usb",children:"USB Camera (V4L2)"})]}),a.jsx(ke,{size:"sm",variant:"secondary",onClick:()=>yk(oe.id,ex[oe.id]??oe.external_camera_url??"",oe.external_camera_type||"mjpeg"),disabled:ht[oe.id]||!(ex[oe.id]??oe.external_camera_url),children:ht[oe.id]?a.jsx(ut,{className:"w-4 h-4 animate-spin"}):"Test"})]}),Je[oe.id]&&a.jsx("div",{className:`text-xs flex items-center gap-1 ${Je[oe.id]?.success?"text-green-500":"text-red-500"}`,children:Je[oe.id]?.success?a.jsxs(a.Fragment,{children:[a.jsx(Nr,{className:"w-3 h-3"}),"Connected",Je[oe.id]?.resolution&&` (${Je[oe.id]?.resolution})`]}):a.jsxs(a.Fragment,{children:[a.jsx(ta,{className:"w-3 h-3"}),Je[oe.id]?.error||i("settings.toast.connectionFailed")]})})]})]},oe.id))}):a.jsx("p",{className:"text-xs text-bambu-gray italic",children:i("settings.noPrintersConfigured")})]})]})]}),a.jsxs(_t,{children:[a.jsx(Pn,{children:a.jsx("h2",{className:"text-lg font-semibold text-white",children:i("settings.costTracking")})}),a.jsxs(Mt,{className:"space-y-4",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Default filament cost (per kg)"}),a.jsx("input",{type:"number",step:"0.01",min:"0",value:E.default_filament_cost,onChange:oe=>wn("default_filament_cost",parseFloat(oe.target.value)||0),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Currency"}),a.jsxs("select",{value:E.currency,onChange:oe=>wn("currency",oe.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[a.jsx("option",{value:"USD",children:"USD ($)"}),a.jsx("option",{value:"EUR",children:"EUR (€)"}),a.jsx("option",{value:"GBP",children:"GBP (£)"}),a.jsx("option",{value:"CHF",children:"CHF (Fr.)"}),a.jsx("option",{value:"JPY",children:"JPY (¥)"}),a.jsx("option",{value:"CNY",children:"CNY (¥)"}),a.jsx("option",{value:"CAD",children:"CAD ($)"}),a.jsx("option",{value:"AUD",children:"AUD ($)"})]})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Electricity cost per kWh"}),a.jsx("input",{type:"number",step:"0.01",min:"0",value:E.energy_cost_per_kwh,onChange:oe=>wn("energy_cost_per_kwh",parseFloat(oe.target.value)||0),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Energy display mode"}),a.jsxs("select",{value:E.energy_tracking_mode||"total",onChange:oe=>wn("energy_tracking_mode",oe.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[a.jsx("option",{value:"print",children:i("settings.printsOnly")}),a.jsx("option",{value:"total",children:i("settings.totalConsumption")})]}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:E.energy_tracking_mode==="print"?"Dashboard shows sum of energy used during prints":"Dashboard shows lifetime energy from smart plugs"})]})]})]}),a.jsxs(_t,{children:[a.jsx(Pn,{children:a.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[a.jsx(ps,{className:"w-5 h-5 text-bambu-green"}),"File Manager"]})}),a.jsxs(Mt,{className:"space-y-4",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Create Archive Entry When Printing"}),a.jsxs("select",{value:E.library_archive_mode??"ask",onChange:oe=>wn("library_archive_mode",oe.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[a.jsx("option",{value:"always",children:i("settings.archiveMode.always")}),a.jsx("option",{value:"never",children:i("settings.archiveMode.never")}),a.jsx("option",{value:"ask",children:i("settings.archiveMode.ask")})]}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"When printing from File Manager, optionally create an archive entry"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Low Disk Space Warning"}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("input",{type:"number",min:"0.5",max:"100",step:"0.5",value:E.library_disk_warning_gb??5,onChange:oe=>wn("library_disk_warning_gb",parseFloat(oe.target.value)||5),className:"w-24 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"}),a.jsx("span",{className:"text-bambu-gray",children:"GB"})]}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Show warning when free disk space falls below this threshold"})]})]})]})]}),a.jsxs("div",{className:"space-y-6 flex-1 lg:max-w-sm",children:[a.jsx(nQe,{}),a.jsxs(_t,{children:[a.jsx(Pn,{children:a.jsx("h2",{className:"text-lg font-semibold text-white",children:"Updates"})}),a.jsxs(Mt,{className:"space-y-4",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white",children:i("settings.checkForUpdatesLabel")}),a.jsx("p",{className:"text-sm text-bambu-gray",children:"Automatically check for new versions on startup"})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:E.check_updates,onChange:oe=>wn("check_updates",oe.target.checked),className:"sr-only peer"}),a.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white",children:i("settings.checkPrinterFirmware")}),a.jsx("p",{className:"text-sm text-bambu-gray",children:"Check for printer firmware updates from Bambu Lab"})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:E.check_printer_firmware??!0,onChange:oe=>wn("check_printer_firmware",oe.target.checked),className:"sr-only peer"}),a.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),a.jsxs("div",{className:"border-t border-bambu-dark-tertiary pt-4",children:[a.jsxs("div",{className:"flex items-center justify-between mb-2",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white",children:i("settings.currentVersion")}),a.jsxs("p",{className:"text-sm text-bambu-gray",children:["v",mn?.version||"..."]})]}),a.jsxs(ke,{variant:"secondary",size:"sm",onClick:()=>ir(),disabled:In,children:[In?a.jsx(ut,{className:"w-4 h-4 animate-spin"}):a.jsx(Ir,{className:"w-4 h-4"}),"Check now"]})]}),en?.update_available?a.jsxs("div",{className:"mt-4 p-3 bg-bambu-green/10 border border-bambu-green/30 rounded-lg",children:[a.jsxs("div",{className:"flex items-start justify-between",children:[a.jsxs("div",{children:[a.jsxs("p",{className:"text-bambu-green font-medium",children:["Update available: v",en.latest_version]}),en.release_name&&en.release_name!==en.latest_version&&a.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:en.release_name})]}),a.jsxs("div",{className:"flex items-center gap-2",children:[en.release_notes&&a.jsx("button",{onClick:()=>we(!0),className:"text-bambu-gray hover:text-white transition-colors text-sm underline",children:"Release Notes"}),en.release_url&&a.jsx("a",{href:en.release_url,target:"_blank",rel:"noopener noreferrer",className:"text-bambu-gray hover:text-white transition-colors",title:i("settings.viewReleaseOnGitHub"),children:a.jsx(Xr,{className:"w-4 h-4"})})]})]}),ai?.status==="downloading"||ai?.status==="installing"?a.jsxs("div",{className:"mt-3",children:[a.jsxs("div",{className:"flex items-center gap-2 text-sm text-bambu-gray",children:[a.jsx(ut,{className:"w-4 h-4 animate-spin"}),a.jsx("span",{children:ai.message})]}),a.jsx("div",{className:"mt-2 w-full bg-bambu-dark-tertiary rounded-full h-2",children:a.jsx("div",{className:"bg-bambu-green h-2 rounded-full transition-all duration-300",style:{width:`${ai.progress}%`}})})]}):ai?.status==="complete"?a.jsx("div",{className:"mt-3 p-2 bg-bambu-green/20 rounded text-sm text-bambu-green",children:ai.message}):ai?.status==="error"?a.jsx("div",{className:"mt-3 p-2 bg-red-500/20 rounded text-sm text-red-400",children:ai.error||ai.message}):en?.is_docker?a.jsxs("div",{className:"mt-3 p-3 bg-bambu-dark-tertiary rounded-lg",children:[a.jsx("p",{className:"text-sm text-bambu-gray mb-2",children:"Update via Docker Compose:"}),a.jsx("code",{className:"block text-xs bg-bambu-dark p-2 rounded text-bambu-green font-mono",children:"docker compose pull && docker compose up -d"})]}):a.jsxs(ke,{className:"mt-3",onClick:()=>Qm.mutate(),disabled:Qm.isPending,children:[Qm.isPending?a.jsx(ut,{className:"w-4 h-4 animate-spin"}):a.jsx(Ni,{className:"w-4 h-4"}),"Install Update"]})]}):en?.error?a.jsxs("div",{className:"mt-2 p-2 bg-red-500/10 border border-red-500/30 rounded text-sm text-red-400",children:["Failed to check for updates: ",en.error]}):en&&!en.update_available?a.jsx("p",{className:"mt-2 text-sm text-bambu-gray",children:"You're running the latest version"}):null]})]})]}),a.jsxs(_t,{children:[a.jsx(Pn,{children:a.jsx("h2",{className:"text-lg font-semibold text-white",children:i("settings.dataManagement")})}),a.jsxs(Mt,{className:"space-y-4",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white",children:i("settings.clearNotificationLogs")}),a.jsx("p",{className:"text-sm text-bambu-gray",children:i("settings.clearNotificationLogsDescription")})]}),a.jsxs(ke,{variant:"secondary",size:"sm",onClick:()=>Se(!0),children:[a.jsx(cn,{className:"w-4 h-4"}),i("common.clear")]})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white",children:i("settings.resetUiPreferences")}),a.jsx("p",{className:"text-sm text-bambu-gray",children:i("settings.resetUiPreferencesDescription")})]}),a.jsxs(ke,{variant:"secondary",size:"sm",onClick:()=>U(!0),children:[a.jsx(cn,{className:"w-4 h-4"}),"Reset"]})]}),a.jsxs("div",{className:"flex items-center justify-between pt-4 border-t border-bambu-dark-tertiary",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white",children:"Backup & Restore"}),a.jsx("p",{className:"text-sm text-bambu-gray",children:"Export/import settings and configure GitHub backup"})]}),a.jsxs(ke,{variant:"secondary",size:"sm",onClick:()=>de("backup"),children:[a.jsx(ju,{className:"w-4 h-4"}),"Go to Backup"]})]})]})]})]})]}),be==="network"&&E&&a.jsxs("div",{className:"flex flex-col lg:flex-row gap-6",children:[a.jsxs("div",{className:"flex-1 lg:max-w-xl space-y-4",children:[a.jsxs(_t,{children:[a.jsx(Pn,{children:a.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[a.jsx(bh,{className:"w-5 h-5 text-blue-400"}),"External URL"]})}),a.jsxs(Mt,{className:"space-y-4",children:[a.jsx("p",{className:"text-sm text-bambu-gray",children:"The external URL where Bambuddy is accessible. Used for notification images and external integrations."}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Bambuddy URL"}),a.jsx("input",{type:"text",value:E.external_url??"",onChange:oe=>wn("external_url",oe.target.value),placeholder:"http://192.168.1.100:8000",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Include protocol and port (e.g., http://192.168.1.100:8000)"})]})]})]}),a.jsxs(_t,{children:[a.jsx(Pn,{children:a.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[a.jsx(Ir,{className:"w-5 h-5 text-blue-400"}),"FTP Retry"]})}),a.jsxs(Mt,{className:"space-y-4",children:[a.jsx("p",{className:"text-sm text-bambu-gray",children:"Retry FTP operations when printer WiFi is unreliable. Applies to 3MF downloads, print uploads, timelapse downloads, and firmware updates."}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white",children:i("settings.enableRetry")}),a.jsx("p",{className:"text-sm text-bambu-gray",children:"Automatically retry failed FTP operations"})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:E.ftp_retry_enabled??!0,onChange:oe=>wn("ftp_retry_enabled",oe.target.checked),className:"sr-only peer"}),a.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),E.ftp_retry_enabled&&a.jsxs("div",{className:"space-y-4 pt-2 border-t border-bambu-dark-tertiary",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Retry attempts"}),a.jsxs("div",{className:"relative w-44",children:[a.jsx("select",{value:E.ftp_retry_count??3,onChange:oe=>wn("ftp_retry_count",parseInt(oe.target.value)),className:"w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer",children:[1,2,3,4,5,6,7,8,9,10].map(oe=>a.jsxs("option",{value:oe,children:[oe," ",oe===1?"time":"times"]},oe))}),a.jsx(Sr,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Retry delay"}),a.jsxs("div",{className:"relative w-44",children:[a.jsx("select",{value:E.ftp_retry_delay??2,onChange:oe=>wn("ftp_retry_delay",parseInt(oe.target.value)),className:"w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer",children:[1,2,3,5,10,15,20,30].map(oe=>a.jsxs("option",{value:oe,children:[oe," ",oe===1?"second":"seconds"]},oe))}),a.jsx(Sr,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Connection timeout"}),a.jsxs("div",{className:"relative w-44",children:[a.jsx("select",{value:E.ftp_timeout??30,onChange:oe=>wn("ftp_timeout",parseInt(oe.target.value)),className:"w-full px-3 py-2 pr-10 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none appearance-none cursor-pointer",children:[10,15,20,30,45,60,90,120].map(oe=>a.jsxs("option",{value:oe,children:[oe," seconds"]},oe))}),a.jsx(Sr,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none"})]}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Increase for printers with weak WiFi"})]})]})]})]})]}),a.jsxs("div",{className:"flex-1 lg:max-w-xl space-y-4",children:[a.jsxs(_t,{children:[a.jsx(Pn,{children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[a.jsx(Jy,{className:"w-5 h-5 text-bambu-green"}),"Home Assistant"]}),E.ha_enabled&&Tn&&a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("span",{className:`w-2.5 h-2.5 rounded-full ${Tn.success?"bg-green-400":"bg-red-400"}`}),a.jsx("span",{className:`text-sm ${Tn.success?"text-green-400":"text-red-400"}`,children:Tn.success?"Connected":"Disconnected"})]})]})}),a.jsxs(Mt,{className:"space-y-4",children:[a.jsx("p",{className:"text-sm text-bambu-gray",children:"Connect to Home Assistant to control smart plugs via HA's REST API. Supports switch, light, input_boolean, and script entities."}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white",children:i("settings.enableHomeAssistant")}),a.jsx("p",{className:"text-xs text-bambu-gray",children:i("settings.homeAssistantDescription")})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:E.ha_enabled??!1,onChange:oe=>wn("ha_enabled",oe.target.checked),className:"sr-only peer"}),a.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),E.ha_enabled&&a.jsxs(a.Fragment,{children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Home Assistant URL"}),a.jsx("input",{type:"text",value:E.ha_url??"",onChange:oe=>wn("ha_url",oe.target.value),placeholder:"http://192.168.1.100:8123",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Long-Lived Access Token"}),a.jsx("input",{type:"password",value:E.ha_token??"",onChange:oe=>wn("ha_token",oe.target.value),placeholder:"eyJ0eXAiOiJKV1QiLC...",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:"Create a token in HA: Profile → Long-Lived Access Tokens → Create Token"})]}),E.ha_url&&E.ha_token&&a.jsx("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:a.jsxs(ke,{variant:"secondary",size:"sm",disabled:ii,onClick:async()=>{je(!0),di(null);try{const oe=await ce.testHAConnection(E.ha_url,E.ha_token);di(oe)}catch(oe){di({success:!1,message:null,error:oe instanceof Error?oe.message:i("common.unknownError")})}finally{je(!1)}},children:[ii?a.jsx(ut,{className:"w-4 h-4 animate-spin"}):a.jsx(Fg,{className:"w-4 h-4"}),i("settings.testConnection")]})})]})]})]}),a.jsxs(_t,{children:[a.jsx(Pn,{children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[a.jsx(Fg,{className:"w-5 h-5 text-blue-400"}),"MQTT Publishing"]}),fr?.enabled&&a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("span",{className:`w-2.5 h-2.5 rounded-full ${fr.connected?"bg-green-400":"bg-red-400"}`}),a.jsx("span",{className:`text-sm ${fr.connected?"text-green-400":"text-red-400"}`,children:fr.connected?"Connected":"Disconnected"})]})]})}),a.jsxs(Mt,{className:"space-y-4",children:[a.jsx("p",{className:"text-sm text-bambu-gray",children:"Publish BamBuddy events to an external MQTT broker for integration with Node-RED, Home Assistant, and other automation systems."}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white",children:i("settings.enableMqtt")}),a.jsx("p",{className:"text-sm text-bambu-gray",children:"Publish events to external MQTT broker"})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:E.mqtt_enabled??!1,onChange:oe=>wn("mqtt_enabled",oe.target.checked),className:"sr-only peer"}),a.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),E.mqtt_enabled&&a.jsxs("div",{className:"space-y-4 pt-2 border-t border-bambu-dark-tertiary",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Broker hostname"}),a.jsx("input",{type:"text",value:E.mqtt_broker??"",onChange:oe=>wn("mqtt_broker",oe.target.value),placeholder:"mqtt.example.com or 192.168.1.100",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),a.jsxs("div",{className:"flex items-end gap-4",children:[a.jsxs("div",{className:"flex-1",children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Port"}),a.jsx("input",{type:"number",min:"1",max:"65535",value:E.mqtt_port??1883,onChange:oe=>wn("mqtt_port",Math.min(65535,Math.max(1,parseInt(oe.target.value)||1883))),className:"w-24 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),a.jsxs("div",{className:"flex items-center gap-3 pb-2",children:[a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:E.mqtt_use_tls??!1,onChange:oe=>{const Nt=oe.target.checked;wn("mqtt_use_tls",Nt);const Un=E.mqtt_port??1883;Nt&&Un===1883?wn("mqtt_port",8883):!Nt&&Un===8883&&wn("mqtt_port",1883)},className:"sr-only peer"}),a.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]}),a.jsx("span",{className:"text-white text-sm",children:i("settings.useTls")})]})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Username (optional)"}),a.jsx("input",{type:"text",value:E.mqtt_username??"",onChange:oe=>wn("mqtt_username",oe.target.value),placeholder:i("settings.leaveEmptyForAnonymous"),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Password (optional)"}),a.jsx("input",{type:"password",value:E.mqtt_password??"",onChange:oe=>wn("mqtt_password",oe.target.value),placeholder:i("settings.leaveEmptyForAnonymous"),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Topic prefix"}),a.jsx("input",{type:"text",value:E.mqtt_topic_prefix??"bambuddy",onChange:oe=>wn("mqtt_topic_prefix",oe.target.value),placeholder:"bambuddy",className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"}),a.jsxs("p",{className:"text-xs text-bambu-gray mt-1",children:["Topics will be: ",E.mqtt_topic_prefix||"bambuddy","/printers//status, etc."]})]}),fr&&a.jsx("div",{className:"pt-3 mt-3 border-t border-bambu-dark-tertiary",children:a.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[a.jsx("span",{className:`w-2 h-2 rounded-full ${fr.connected?"bg-green-400":"bg-red-400"}`}),a.jsx("span",{className:"text-bambu-gray",children:fr.connected?a.jsxs(a.Fragment,{children:[i("settings.mqttConnectedTo")," ",a.jsxs("span",{className:"text-white",children:[fr.broker,":",fr.port]})]}):i("settings.spoolmanDisconnected")})]})})]})]})]})]}),a.jsx("div",{className:"flex-1 lg:max-w-md space-y-4",children:a.jsxs(_t,{children:[a.jsx(Pn,{children:a.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[a.jsx(WP,{className:"w-5 h-5 text-orange-400"}),"Prometheus Metrics"]})}),a.jsxs(Mt,{className:"space-y-4",children:[a.jsxs("p",{className:"text-sm text-bambu-gray",children:["Expose printer metrics at ",a.jsx("code",{className:"bg-bambu-dark px-1 rounded",children:"/api/v1/metrics"})," for Prometheus/Grafana monitoring."]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white",children:i("settings.enableMetricsEndpoint")}),a.jsx("p",{className:"text-xs text-bambu-gray",children:i("settings.prometheusDescription")})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:E.prometheus_enabled??!1,onChange:oe=>wn("prometheus_enabled",oe.target.checked),className:"sr-only peer"}),a.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]}),E.prometheus_enabled&&a.jsxs("div",{className:"space-y-4 pt-2 border-t border-bambu-dark-tertiary",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:"Bearer Token (optional)"}),a.jsx("input",{type:"password",value:E.prometheus_token??"",onChange:oe=>wn("prometheus_token",oe.target.value),placeholder:i("settings.leaveEmptyForNoAuth"),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"}),a.jsxs("p",{className:"text-xs text-bambu-gray mt-1",children:["If set, requests must include ",a.jsx("code",{className:"bg-bambu-dark px-1 rounded",children:"Authorization: Bearer "})]})]}),a.jsxs("div",{className:"pt-2 border-t border-bambu-dark-tertiary",children:[a.jsx("p",{className:"text-sm text-white mb-2",children:i("settings.availableMetrics")}),a.jsxs("div",{className:"text-xs text-bambu-gray space-y-1",children:[a.jsxs("p",{children:[a.jsx("code",{className:"text-orange-400",children:"bambuddy_printer_connected"})," - Connection status"]}),a.jsxs("p",{children:[a.jsx("code",{className:"text-orange-400",children:"bambuddy_printer_state"})," - Printer state (idle/printing/etc)"]}),a.jsxs("p",{children:[a.jsx("code",{className:"text-orange-400",children:"bambuddy_print_progress"})," - Print progress 0-100%"]}),a.jsxs("p",{children:[a.jsx("code",{className:"text-orange-400",children:"bambuddy_bed_temp_celsius"})," - Bed temperature"]}),a.jsxs("p",{children:[a.jsx("code",{className:"text-orange-400",children:"bambuddy_nozzle_temp_celsius"})," - Nozzle temperature"]}),a.jsxs("p",{children:[a.jsx("code",{className:"text-orange-400",children:"bambuddy_prints_total"})," - Total prints by result"]}),a.jsx("p",{className:"text-bambu-gray/70 italic",children:"...and more (layers, fans, queue, filament usage)"})]})]})]})]})]})})]}),Tn&&a.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",children:a.jsxs("div",{className:"bg-bambu-dark-secondary rounded-lg p-6 max-w-md w-full mx-4",children:[a.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[Tn.success?a.jsx(Nr,{className:"w-8 h-8 text-green-400"}):a.jsx(ta,{className:"w-8 h-8 text-red-400"}),a.jsx("h3",{className:"text-lg font-medium text-white",children:Tn.success?"Connection Successful":"Connection Failed"})]}),a.jsx("p",{className:"text-bambu-gray mb-6",children:Tn.success?Tn.message||"Successfully connected to Home Assistant.":Tn.error||"Failed to connect to Home Assistant."}),a.jsx("div",{className:"flex justify-end",children:a.jsx(ke,{variant:"primary",onClick:()=>di(null),children:"OK"})})]})}),be==="plugs"&&a.jsxs("div",{className:"max-w-4xl",children:[a.jsxs("div",{className:"flex items-start justify-between mb-6",children:[a.jsxs("div",{children:[a.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[a.jsx(rl,{className:"w-5 h-5 text-bambu-green"}),"Smart Plugs"]}),a.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:"Connect smart plugs (Tasmota or Home Assistant) to automate power control and track energy usage for your printers."})]}),a.jsxs("div",{className:"flex items-center gap-2 pt-1 shrink-0",children:[_e&&_e.filter(oe=>oe.enabled).length>1&&a.jsxs(a.Fragment,{children:[a.jsxs(ke,{variant:"secondary",size:"sm",className:"whitespace-nowrap",onClick:()=>Z("on"),disabled:bl.isPending,title:i("settings.turnAllPlugsOn"),children:[bl.isPending?a.jsx(ut,{className:"w-4 h-4 animate-spin"}):a.jsx(Zu,{className:"w-4 h-4 text-bambu-green"}),"All On"]}),a.jsxs(ke,{variant:"secondary",size:"sm",className:"whitespace-nowrap",onClick:()=>Z("off"),disabled:bl.isPending,title:i("settings.turnAllPlugsOff"),children:[bl.isPending?a.jsx(ut,{className:"w-4 h-4 animate-spin"}):a.jsx(HM,{className:"w-4 h-4 text-red-400"}),"All Off"]})]}),a.jsxs(ke,{className:"whitespace-nowrap",onClick:()=>{L(null),j(!0)},children:[a.jsx(dr,{className:"w-4 h-4"}),"Add Smart Plug"]})]})]}),_e&&_e.length>0&&a.jsxs(_t,{className:"mb-6",children:[a.jsx(Pn,{children:a.jsxs("h3",{className:"text-base font-semibold text-white flex items-center gap-2",children:[a.jsx(Dh,{className:"w-4 h-4 text-yellow-400"}),"Energy Summary",Ye&&a.jsx(ut,{className:"w-4 h-4 animate-spin text-bambu-gray ml-2"})]})}),a.jsx(Mt,{children:et?a.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[a.jsxs("div",{className:"bg-bambu-dark rounded-lg p-3",children:[a.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-xs mb-1",children:[a.jsx(Dh,{className:"w-3 h-3"}),"Current Power"]}),a.jsxs("div",{className:"text-xl font-bold text-white",children:[et.totalPower.toFixed(1),a.jsx("span",{className:"text-sm font-normal text-bambu-gray ml-1",children:"W"})]}),a.jsxs("div",{className:"text-xs text-bambu-gray mt-1",children:[et.reachableCount,"/",et.totalPlugs," plugs online"]})]}),a.jsxs("div",{className:"bg-bambu-dark rounded-lg p-3",children:[a.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-xs mb-1",children:[a.jsx(ei,{className:"w-3 h-3"}),"Today"]}),a.jsxs("div",{className:"text-xl font-bold text-white",children:[et.totalToday.toFixed(2),a.jsx("span",{className:"text-sm font-normal text-bambu-gray ml-1",children:"kWh"})]}),(E?.energy_cost_per_kwh??0)>0&&a.jsxs("div",{className:"text-xs text-bambu-gray mt-1",children:["~",(et.totalToday*(E?.energy_cost_per_kwh??0)).toFixed(2)," ",E?.currency]})]}),a.jsxs("div",{className:"bg-bambu-dark rounded-lg p-3",children:[a.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-xs mb-1",children:[a.jsx(WP,{className:"w-3 h-3"}),"Yesterday"]}),a.jsxs("div",{className:"text-xl font-bold text-white",children:[et.totalYesterday.toFixed(2),a.jsx("span",{className:"text-sm font-normal text-bambu-gray ml-1",children:"kWh"})]}),(E?.energy_cost_per_kwh??0)>0&&a.jsxs("div",{className:"text-xs text-bambu-gray mt-1",children:["~",(et.totalYesterday*(E?.energy_cost_per_kwh??0)).toFixed(2)," ",E?.currency]})]}),a.jsxs("div",{className:"bg-bambu-dark rounded-lg p-3",children:[a.jsxs("div",{className:"flex items-center gap-2 text-bambu-gray text-xs mb-1",children:[a.jsx(zP,{className:"w-3 h-3"}),"Total"]}),a.jsxs("div",{className:"text-xl font-bold text-white",children:[et.totalLifetime.toFixed(1),a.jsx("span",{className:"text-sm font-normal text-bambu-gray ml-1",children:"kWh"})]}),(E?.energy_cost_per_kwh??0)>0&&a.jsxs("div",{className:"text-xs text-bambu-gray mt-1",children:["~",(et.totalLifetime*(E?.energy_cost_per_kwh??0)).toFixed(2)," ",E?.currency]})]})]}):Ye?null:a.jsx("p",{className:"text-sm text-bambu-gray",children:"Enable plugs to see energy summary"})})]}),Re?a.jsx("div",{className:"flex justify-center py-12",children:a.jsx(ut,{className:"w-8 h-8 text-bambu-green animate-spin"})}):_e&&_e.length>0?a.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:_e.map(oe=>a.jsx($Ye,{plug:oe,onEdit:Nt=>{L(Nt),j(!0)}},oe.id))}):a.jsx(_t,{children:a.jsx(Mt,{className:"py-12",children:a.jsxs("div",{className:"text-center text-bambu-gray",children:[a.jsx(rl,{className:"w-16 h-16 mx-auto mb-4 opacity-30"}),a.jsx("p",{className:"text-lg font-medium text-white mb-2",children:i("settings.noSmartPlugsTitle")}),a.jsx("p",{className:"text-sm mb-4",children:i("settings.noSmartPlugsDescription")}),a.jsxs(ke,{onClick:()=>{L(null),j(!0)},children:[a.jsx(dr,{className:"w-4 h-4"}),i("settings.addFirstSmartPlug")]})]})})})]}),be==="notifications"&&a.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-8",children:[a.jsxs("div",{children:[a.jsxs("div",{className:"flex items-center justify-between mb-4",children:[a.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[a.jsx(Og,{className:"w-5 h-5 text-bambu-green"}),i("settings.providers")]}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsxs(ke,{size:"sm",variant:"secondary",onClick:()=>re(!0),children:[a.jsx(sy,{className:"w-4 h-4"}),i("settings.log")]}),Ct&&Ct.length>0&&a.jsxs(ke,{size:"sm",variant:"secondary",onClick:()=>{gl(null),sd.mutate()},disabled:sd.isPending,children:[sd.isPending?a.jsx(ut,{className:"w-4 h-4 animate-spin"}):a.jsx($M,{className:"w-4 h-4"}),i("settings.testAll")]}),a.jsxs(ke,{size:"sm",onClick:()=>{q(null),R(!0)},children:[a.jsx(dr,{className:"w-4 h-4"}),"Add"]})]})]}),a.jsx(_t,{className:"mb-4",children:a.jsx(Mt,{className:"py-3",children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("p",{className:"text-white text-sm font-medium",children:i("settings.notificationLanguage")}),a.jsx("p",{className:"text-xs text-bambu-gray",children:i("settings.notificationLanguageDescription")})]}),a.jsx("select",{value:E.notification_language||"en",onChange:oe=>wn("notification_language",oe.target.value),className:"px-2 py-1.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-sm focus:outline-none focus:ring-1 focus:ring-bambu-green",children:Wz.map(oe=>a.jsx("option",{value:oe.code,children:oe.nativeName},oe.code))})]})})}),Ai&&a.jsx(_t,{className:"mb-4",children:a.jsxs(Mt,{className:"py-3",children:[a.jsxs("div",{className:"flex items-center justify-between mb-2",children:[a.jsx("span",{className:"text-sm font-medium text-white",children:i("settings.testResults")}),a.jsx("button",{onClick:()=>gl(null),className:"text-bambu-gray hover:text-white text-xs",children:i("common.dismiss")})]}),a.jsxs("div",{className:"flex items-center gap-4 text-sm mb-2",children:[a.jsxs("span",{className:"flex items-center gap-1 text-bambu-green",children:[a.jsx(Nr,{className:"w-4 h-4"}),i("settings.testPassedCount",{count:Ai.success})]}),Ai.failed>0&&a.jsxs("span",{className:"flex items-center gap-1 text-red-400",children:[a.jsx(ta,{className:"w-4 h-4"}),i("settings.testFailedCount",{count:Ai.failed})]})]}),Ai.results.filter(oe=>!oe.success).length>0&&a.jsx("div",{className:"space-y-1 mt-2 pt-2 border-t border-bambu-dark-tertiary",children:Ai.results.filter(oe=>!oe.success).map(oe=>a.jsxs("div",{className:"text-xs text-red-400",children:[a.jsxs("span",{className:"font-medium",children:[oe.provider_name,":"]})," ",oe.message]},oe.provider_id))})]})}),jt?a.jsx("div",{className:"flex justify-center py-12",children:a.jsx(ut,{className:"w-6 h-6 text-bambu-green animate-spin"})}):Ct&&Ct.length>0?a.jsx("div",{className:"space-y-3",children:Ct.map(oe=>a.jsx(qYe,{provider:oe,onEdit:Nt=>{q(Nt),R(!0)}},oe.id))}):a.jsx(_t,{children:a.jsx(Mt,{className:"py-8",children:a.jsxs("div",{className:"text-center text-bambu-gray",children:[a.jsx(Og,{className:"w-12 h-12 mx-auto mb-3 opacity-30"}),a.jsx("p",{className:"text-sm font-medium text-white mb-2",children:i("settings.noProvidersTitle")}),a.jsx("p",{className:"text-xs mb-3",children:i("settings.noProvidersDescription")}),a.jsxs(ke,{size:"sm",onClick:()=>{q(null),R(!0)},children:[a.jsx(dr,{className:"w-4 h-4"}),i("settings.addProvider")]})]})})})]}),a.jsxs("div",{children:[a.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2 mb-4",children:[a.jsx(ps,{className:"w-5 h-5 text-bambu-green"}),i("settings.messageTemplates")]}),a.jsx("p",{className:"text-sm text-bambu-gray mb-4",children:i("settings.messageTemplatesDescription")}),fn?a.jsx("div",{className:"flex justify-center py-8",children:a.jsx(ut,{className:"w-6 h-6 text-bambu-green animate-spin"})}):pn&&pn.length>0?a.jsx("div",{className:"space-y-2",children:pn.map(oe=>a.jsx(_t,{className:"cursor-pointer hover:border-bambu-green/50 transition-colors",onClick:()=>G(oe),children:a.jsx(Mt,{className:"py-2.5 px-3",children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"min-w-0 flex-1",children:[a.jsx("p",{className:"text-white font-medium text-sm truncate",children:oe.name}),a.jsx("p",{className:"text-bambu-gray text-xs truncate mt-0.5",children:oe.title_template})]}),a.jsx("button",{className:"p-1.5 hover:bg-bambu-dark-tertiary rounded transition-colors shrink-0 ml-2",onClick:Nt=>{Nt.stopPropagation(),G(oe)},children:a.jsx(Eg,{className:"w-4 h-4 text-bambu-gray"})})]})})},oe.id))}):a.jsx(_t,{children:a.jsx(Mt,{className:"py-8",children:a.jsxs("div",{className:"text-center text-bambu-gray",children:[a.jsx(ps,{className:"w-12 h-12 mx-auto mb-3 opacity-30"}),a.jsx("p",{className:"text-sm",children:i("settings.noTemplatesAvailable")})]})})})]})]}),be==="apikeys"&&a.jsxs("div",{className:"grid grid-cols-1 xl:grid-cols-2 gap-8",children:[a.jsxs("div",{children:[a.jsxs("div",{className:"flex items-start justify-between gap-4 mb-6",children:[a.jsxs("div",{className:"flex-1",children:[a.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[a.jsx(Wo,{className:"w-5 h-5 text-bambu-green"}),i("settings.apiKeys")]}),a.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:i("settings.apiKeysDescription")})]}),a.jsxs(ke,{size:"sm",onClick:()=>ae(!0),className:"flex-shrink-0",children:[a.jsx(dr,{className:"w-4 h-4"}),i("settings.createKey")]})]}),W&&a.jsx(_t,{className:"mb-6 border-bambu-green",children:a.jsx(Mt,{className:"py-4",children:a.jsxs("div",{className:"flex items-start gap-3",children:[a.jsx(Nr,{className:"w-5 h-5 text-bambu-green flex-shrink-0 mt-0.5"}),a.jsxs("div",{className:"flex-1",children:[a.jsx("p",{className:"text-white font-medium mb-1",children:i("settings.apiKeyCreated")}),a.jsx("p",{className:"text-sm text-bambu-gray mb-2",children:i("settings.apiKeyCopyWarning")}),a.jsxs("div",{className:"flex items-center gap-2 bg-bambu-dark rounded-lg p-2",children:[a.jsx("code",{className:"flex-1 text-sm text-bambu-green font-mono break-all",children:W}),a.jsx(ke,{variant:"secondary",size:"sm",onClick:async()=>{try{if(navigator.clipboard&&navigator.clipboard.writeText)await navigator.clipboard.writeText(W);else{const oe=document.createElement("textarea");oe.value=W,oe.style.position="fixed",oe.style.left="-999999px",document.body.appendChild(oe),oe.select(),document.execCommand("copy"),document.body.removeChild(oe)}o(i("settings.toast.keyCopied"))}catch{o(i("settings.toast.copyFailed"),"error")}},children:a.jsx(Fl,{className:"w-4 h-4"})})]}),a.jsxs("div",{className:"flex gap-2 mt-3",children:[a.jsx(ke,{variant:"secondary",size:"sm",onClick:()=>{V(W),o(i("settings.toast.keyAddedToBrowser"))},children:i("settings.useInApiBrowser")}),a.jsx(ke,{variant:"secondary",size:"sm",onClick:()=>Q(null),children:i("common.dismiss")})]})]})]})})}),Ce&&a.jsxs(_t,{className:"mb-6",children:[a.jsx(Pn,{children:a.jsx("h3",{className:"text-base font-semibold text-white",children:i("settings.createNewApiKey")})}),a.jsxs(Mt,{className:"space-y-4",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:i("settings.keyName")}),a.jsx("input",{type:"text",value:Ae,onChange:oe=>Le(oe.target.value),placeholder:i("settings.keyNamePlaceholder"),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-2",children:i("common.permissions")}),a.jsxs("div",{className:"space-y-2",children:[a.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:fe.can_read_status,onChange:oe=>Xe(Nt=>({...Nt,can_read_status:oe.target.checked})),className:"w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green"}),a.jsxs("div",{children:[a.jsx("span",{className:"text-white",children:i("settings.readStatus")}),a.jsx("p",{className:"text-xs text-bambu-gray",children:i("settings.readStatusDescription")})]})]}),a.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:fe.can_queue,onChange:oe=>Xe(Nt=>({...Nt,can_queue:oe.target.checked})),className:"w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green"}),a.jsxs("div",{children:[a.jsx("span",{className:"text-white",children:i("settings.manageQueue")}),a.jsx("p",{className:"text-xs text-bambu-gray",children:i("settings.manageQueueDescription")})]})]}),a.jsxs("label",{className:"flex items-center gap-3 cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:fe.can_control_printer,onChange:oe=>Xe(Nt=>({...Nt,can_control_printer:oe.target.checked})),className:"w-4 h-4 text-bambu-green rounded border-bambu-dark-tertiary bg-bambu-dark focus:ring-bambu-green"}),a.jsxs("div",{children:[a.jsx("span",{className:"text-white",children:i("settings.controlPrinter")}),a.jsx("p",{className:"text-xs text-bambu-gray",children:i("settings.controlPrinterDescription")})]})]})]})]}),a.jsxs("div",{className:"flex items-center gap-2 pt-2",children:[a.jsxs(ke,{onClick:()=>Et.mutate({name:Ae||i("settings.unnamedKey"),...fe}),disabled:Et.isPending,children:[Et.isPending?a.jsx(ut,{className:"w-4 h-4 animate-spin"}):a.jsx(dr,{className:"w-4 h-4"}),i("settings.createKey")]}),a.jsx(ke,{variant:"secondary",onClick:()=>ae(!1),children:i("common.cancel")})]})]})]}),Rt?a.jsx("div",{className:"flex justify-center py-12",children:a.jsx(ut,{className:"w-8 h-8 text-bambu-green animate-spin"})}):Bt&&Bt.length>0?a.jsx("div",{className:"space-y-3",children:Bt.map(oe=>a.jsx(_t,{children:a.jsx(Mt,{className:"py-3",children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx(Wo,{className:`w-5 h-5 ${oe.enabled?"text-bambu-green":"text-bambu-gray"}`}),a.jsxs("div",{children:[a.jsx("p",{className:"text-white font-medium",children:oe.name}),a.jsxs("p",{className:"text-xs text-bambu-gray",children:[oe.key_prefix,"••••••••",oe.last_used&&` · ${i("settings.lastUsed")}: ${tb(oe.last_used)}`]})]})]}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsxs("div",{className:"flex gap-1 text-xs",children:[oe.can_read_status&&a.jsx("span",{className:"px-1.5 py-0.5 bg-blue-500/20 text-blue-400 rounded",children:i("settings.read")}),oe.can_queue&&a.jsx("span",{className:"px-1.5 py-0.5 bg-green-500/20 text-green-400 rounded",children:i("queue.title")}),oe.can_control_printer&&a.jsx("span",{className:"px-1.5 py-0.5 bg-orange-500/20 text-orange-400 rounded",children:i("settings.control")})]}),a.jsx(ke,{variant:"secondary",size:"sm",onClick:()=>X(oe.id),children:a.jsx(cn,{className:"w-4 h-4 text-red-400"})})]})]})})},oe.id))}):a.jsx(_t,{children:a.jsx(Mt,{className:"py-12",children:a.jsxs("div",{className:"text-center text-bambu-gray",children:[a.jsx(Wo,{className:"w-16 h-16 mx-auto mb-4 opacity-30"}),a.jsx("p",{className:"text-lg font-medium text-white mb-2",children:i("settings.apiKeysEmptyTitle")}),a.jsx("p",{className:"text-sm mb-4",children:i("settings.apiKeysEmptyDescription")}),a.jsxs(ke,{onClick:()=>ae(!0),children:[a.jsx(dr,{className:"w-4 h-4"}),i("settings.createFirstKey")]})]})})}),a.jsxs(_t,{className:"mt-6",children:[a.jsx(Pn,{children:a.jsx("h3",{className:"text-base font-semibold text-white",children:i("settings.webhookEndpoints")})}),a.jsxs(Mt,{className:"space-y-3 text-sm",children:[a.jsx("p",{className:"text-bambu-gray",children:i("settings.webhookApiKeyHint")}),a.jsxs("div",{className:"space-y-2 font-mono text-xs",children:[a.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[a.jsx("span",{className:"text-blue-400",children:"GET"})," ",a.jsx("span",{className:"text-white",children:"/api/v1/webhook/status"}),a.jsxs("span",{className:"text-bambu-gray",children:[" - ",i("settings.webhook.getAllStatus")]})]}),a.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[a.jsx("span",{className:"text-blue-400",children:"GET"})," ",a.jsx("span",{className:"text-white",children:"/api/v1/webhook/status/:id"}),a.jsxs("span",{className:"text-bambu-gray",children:[" - ",i("settings.webhook.getSpecificStatus")]})]}),a.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[a.jsx("span",{className:"text-green-400",children:"POST"})," ",a.jsx("span",{className:"text-white",children:"/api/v1/webhook/queue"}),a.jsxs("span",{className:"text-bambu-gray",children:[" - ",i("settings.webhook.addToQueue")]})]}),a.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[a.jsx("span",{className:"text-orange-400",children:"POST"})," ",a.jsx("span",{className:"text-white",children:"/api/v1/webhook/printer/:id/pause"}),a.jsxs("span",{className:"text-bambu-gray",children:[" - ",i("settings.webhook.pausePrint")]})]}),a.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[a.jsx("span",{className:"text-orange-400",children:"POST"})," ",a.jsx("span",{className:"text-white",children:"/api/v1/webhook/printer/:id/resume"}),a.jsxs("span",{className:"text-bambu-gray",children:[" - ",i("settings.webhook.resumePrint")]})]}),a.jsxs("div",{className:"p-2 bg-bambu-dark rounded",children:[a.jsx("span",{className:"text-red-400",children:"POST"})," ",a.jsx("span",{className:"text-white",children:"/api/v1/webhook/printer/:id/stop"}),a.jsxs("span",{className:"text-bambu-gray",children:[" - ",i("settings.webhook.stopPrint")]})]})]})]})]})]}),a.jsxs("div",{children:[a.jsxs("div",{className:"mb-6",children:[a.jsxs("h2",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[a.jsx(bh,{className:"w-5 h-5 text-bambu-green"}),i("settings.apiBrowser")]}),a.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:i("settings.apiBrowserDescription")})]}),a.jsx(_t,{className:"mb-4",children:a.jsxs(Mt,{className:"py-3",children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-2",children:i("settings.apiKeyForTesting")}),a.jsx("input",{type:"text",value:te,onChange:oe=>V(oe.target.value),placeholder:i("settings.apiKeyPlaceholder"),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white font-mono text-sm focus:border-bambu-green focus:outline-none"}),a.jsx("p",{className:"text-xs text-bambu-gray mt-2",children:i("settings.apiKeyHint")})]})}),a.jsx(uQe,{apiKey:te})]})]}),be==="virtual-printer"&&a.jsx(rQe,{}),be==="filament"&&E&&a.jsxs("div",{className:"flex flex-col lg:flex-row gap-6 lg:gap-8",children:[a.jsx("div",{className:"flex-1 lg:max-w-xl",children:a.jsxs(_t,{children:[a.jsx(Pn,{children:a.jsx("h2",{className:"text-lg font-semibold text-white",children:i("settings.amsDisplayThresholds")})}),a.jsxs(Mt,{className:"space-y-4",children:[a.jsx("p",{className:"text-sm text-bambu-gray",children:i("settings.amsThresholdsDescription")}),a.jsxs("div",{className:"space-y-3",children:[a.jsxs("div",{className:"flex items-center gap-2 text-white",children:[a.jsx(sO,{className:"w-4 h-4 text-blue-400"}),a.jsx("span",{className:"font-medium",children:i("settings.humidity")})]}),a.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[a.jsxs("div",{children:[a.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[i("settings.goodGreen")," ≤"]}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("input",{type:"number",min:"0",max:"100",value:E.ams_humidity_good??40,onChange:oe=>wn("ams_humidity_good",parseInt(oe.target.value)||40),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"}),a.jsx("span",{className:"text-bambu-gray",children:"%"})]})]}),a.jsxs("div",{children:[a.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[i("settings.fairOrange")," ≤"]}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("input",{type:"number",min:"0",max:"100",value:E.ams_humidity_fair??60,onChange:oe=>wn("ams_humidity_fair",parseInt(oe.target.value)||60),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"}),a.jsx("span",{className:"text-bambu-gray",children:"%"})]})]})]}),a.jsx("p",{className:"text-xs text-bambu-gray",children:i("settings.aboveFairBad")})]}),a.jsxs("div",{className:"space-y-3 pt-2 border-t border-bambu-dark-tertiary",children:[a.jsxs("div",{className:"flex items-center gap-2 text-white",children:[a.jsx(GM,{className:"w-4 h-4 text-orange-400"}),a.jsx("span",{className:"font-medium",children:i("settings.temperature")})]}),a.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[a.jsxs("div",{children:[a.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[i("settings.goodBlue")," ≤"]}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("input",{type:"number",step:"0.5",min:"0",max:"60",value:E.ams_temp_good??28,onChange:oe=>wn("ams_temp_good",parseFloat(oe.target.value)||28),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"}),a.jsx("span",{className:"text-bambu-gray",children:"°C"})]})]}),a.jsxs("div",{children:[a.jsxs("label",{className:"block text-sm text-bambu-gray mb-1",children:[i("settings.fairOrange")," ≤"]}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("input",{type:"number",step:"0.5",min:"0",max:"60",value:E.ams_temp_fair??35,onChange:oe=>wn("ams_temp_fair",parseFloat(oe.target.value)||35),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"}),a.jsx("span",{className:"text-bambu-gray",children:"°C"})]})]})]}),a.jsx("p",{className:"text-xs text-bambu-gray",children:i("settings.aboveFairHot")})]}),a.jsxs("div",{className:"space-y-3 pt-4 border-t border-bambu-dark-tertiary",children:[a.jsxs("div",{className:"flex items-center gap-2 text-white",children:[a.jsx(ju,{className:"w-4 h-4 text-purple-400"}),a.jsx("span",{className:"font-medium",children:i("settings.historyRetention")})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:i("settings.keepSensorHistory")}),a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("input",{type:"number",min:"1",max:"365",value:E.ams_history_retention_days??30,onChange:oe=>wn("ams_history_retention_days",parseInt(oe.target.value)||30),className:"w-24 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none"}),a.jsx("span",{className:"text-bambu-gray",children:i("common.days")})]})]}),a.jsx("p",{className:"text-xs text-bambu-gray",children:i("settings.historyRetentionDescription")})]}),a.jsxs("div",{className:"space-y-3 pt-4 border-t border-bambu-dark-tertiary",children:[a.jsxs("div",{className:"flex items-center gap-2 text-white",children:[a.jsx(Or,{className:"w-4 h-4 text-bambu-green"}),a.jsx("span",{className:"font-medium",children:i("settings.printModal")})]}),a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-white",children:i("settings.expandCustomMapping")}),a.jsx("p",{className:"text-xs text-bambu-gray mt-0.5",children:i("settings.expandCustomMappingDescription")})]}),a.jsxs("label",{className:"relative inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:E.per_printer_mapping_expanded??!1,onChange:oe=>wn("per_printer_mapping_expanded",oe.target.checked),className:"sr-only peer"}),a.jsx("div",{className:"w-11 h-6 bg-bambu-dark-tertiary peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-bambu-green"})]})]})]})]})]})}),a.jsx("div",{className:"flex-1 lg:max-w-xl",children:a.jsx(eQe,{})})]}),me!==null&&a.jsx(er,{title:i("settings.deleteApiKeyTitle"),message:i("settings.deleteApiKeyMessage"),confirmText:i("settings.deleteKey"),variant:"danger",onConfirm:()=>{an.mutate(me),X(null)},onCancel:()=>X(null)}),T&&a.jsx(VYe,{plug:z,onClose:()=>{j(!1),L(null)}}),B&&a.jsx(WYe,{provider:$,onClose:()=>{R(!1),q(null)}}),I&&a.jsx(KYe,{template:I,onClose:()=>G(null)}),Y&&a.jsx(QYe,{onClose:()=>re(!1)}),ge&&a.jsx(er,{title:i("settings.clearNotificationLogs"),message:i("settings.clearLogsMessage"),confirmText:i("settings.clearLogs"),variant:"warning",onConfirm:async()=>{Se(!1);try{const oe=await ce.clearNotificationLogs(30);o(oe.message,"success")}catch{o(i("settings.toast.clearLogsFailed"),"error")}},onCancel:()=>Se(!1)}),ee&&a.jsx(er,{title:i("settings.resetUiPreferences"),message:i("settings.resetUiPreferencesMessage"),confirmText:i("settings.resetPreferences"),variant:"default",onConfirm:()=>{U(!1),localStorage.clear(),o(i("settings.toast.uiPreferencesReset"),"success"),setTimeout(()=>window.location.reload(),1e3)},onCancel:()=>U(!1)}),O&&a.jsx(er,{title:`Turn All Plugs ${O==="on"?"On":"Off"}`,message:`This will turn ${O==="on"?"ON":"OFF"} all ${_e?.filter(oe=>oe.enabled).length||0} enabled smart plugs. ${O==="off"?"Any running printers may be affected!":""}`,confirmText:`Turn All ${O==="on"?"On":"Off"}`,variant:O==="off"?"danger":"warning",onConfirm:()=>{const oe=O;Z(null),bl.mutate(oe)},onCancel:()=>Z(null)}),le&&en?.release_notes&&a.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",onClick:()=>we(!1),children:a.jsxs(_t,{className:"w-full max-w-2xl max-h-[80vh] flex flex-col",onClick:oe=>oe.stopPropagation(),children:[a.jsxs(Pn,{className:"flex flex-row items-center justify-between shrink-0",children:[a.jsxs("div",{children:[a.jsxs("h2",{className:"text-lg font-semibold text-white",children:["Release Notes - v",en.latest_version]}),en.release_name&&en.release_name!==en.latest_version&&a.jsx("p",{className:"text-sm text-bambu-gray",children:en.release_name})]}),a.jsx("button",{onClick:()=>we(!1),className:"p-1 rounded hover:bg-bambu-dark-tertiary text-bambu-gray hover:text-white",children:a.jsx(Lt,{className:"w-5 h-5"})})]}),a.jsx(Mt,{className:"overflow-y-auto flex-1",children:a.jsx("pre",{className:"text-sm text-bambu-gray whitespace-pre-wrap font-sans",children:en.release_notes})}),a.jsxs("div",{className:"p-4 border-t border-bambu-dark-tertiary shrink-0 flex gap-2",children:[en.release_url&&a.jsx("a",{href:en.release_url,target:"_blank",rel:"noopener noreferrer",className:"flex-1",children:a.jsxs(ke,{variant:"secondary",className:"w-full",children:[a.jsx(Xr,{className:"w-4 h-4"}),"View on GitHub"]})}),a.jsx(ke,{onClick:()=>we(!1),className:"flex-1",children:"Close"})]})]})}),be==="users"&&a.jsxs("div",{className:"space-y-6",children:[a.jsx(_t,{children:a.jsx(Mt,{className:"py-4",children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx("div",{className:`w-10 h-10 rounded-full flex items-center justify-center ${l?"bg-green-500/20":"bg-gray-500/20"}`,children:l?a.jsx(P1,{className:"w-5 h-5 text-green-400"}):a.jsx(j1,{className:"w-5 h-5 text-gray-400"})}),a.jsxs("div",{children:[a.jsx("h3",{className:"text-white font-medium",children:i("settings.authentication")}),a.jsx("p",{className:"text-sm text-bambu-gray",children:i(l?"settings.authEnabledDescription":"settings.authDisabledDescription")})]})]}),l?c?.is_admin&&a.jsxs(ke,{variant:"secondary",onClick:()=>se(!0),children:[a.jsx(j1,{className:"w-4 h-4"}),i("common.disable")]}):a.jsxs(ke,{onClick:()=>e("/setup"),children:[a.jsx(P1,{className:"w-4 h-4"}),i("common.enable")]})]})})}),Kt?.advanced_auth_enabled&&a.jsx(_t,{className:"border-blue-500/30 bg-blue-500/5",children:a.jsx(Mt,{className:"py-4",children:a.jsxs("div",{className:"flex items-start gap-3",children:[a.jsx("div",{className:"w-10 h-10 rounded-full flex items-center justify-center bg-blue-500/20 flex-shrink-0",children:a.jsx(oy,{className:"w-5 h-5 text-blue-400"})}),a.jsxs("div",{children:[a.jsx("h3",{className:"text-white font-medium",children:i("settings.email.advancedAuthEnabled")}),a.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:i("settings.email.advancedAuthEnabledDesc")})]})]})})}),l&&a.jsxs("div",{className:"grid grid-cols-1 xl:grid-cols-2 gap-6",children:[a.jsxs("div",{className:"space-y-6",children:[c&&a.jsxs(_t,{children:[a.jsx(Pn,{children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("h3",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[a.jsx(Kf,{className:"w-5 h-5 text-bambu-green"}),i("settings.currentUser")]}),a.jsxs(ke,{size:"sm",variant:"ghost",onClick:()=>He(!0),children:[a.jsx(Wo,{className:"w-4 h-4"}),i("settings.changePassword")]})]})}),a.jsx(Mt,{children:a.jsx("div",{className:"flex items-center justify-between",children:a.jsxs("div",{children:[a.jsx("p",{className:"text-white font-medium text-lg",children:c.username}),a.jsxs("div",{className:"flex flex-wrap gap-1 mt-2",children:[c.is_admin&&a.jsx("span",{className:"px-2 py-0.5 rounded-full text-xs font-medium bg-purple-500/20 text-purple-300",children:i("settings.admin")}),c.groups?.map(oe=>a.jsx("span",{className:`px-2 py-0.5 rounded-full text-xs font-medium ${oe.name==="Administrators"?"bg-purple-500/20 text-purple-300":oe.name==="Operators"?"bg-blue-500/20 text-blue-300":oe.name==="Viewers"?"bg-green-500/20 text-green-300":"bg-gray-500/20 text-gray-300"}`,children:oe.name},oe.id))]})]})})})]}),a.jsxs(_t,{children:[a.jsx(Pn,{children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("h3",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[a.jsx(Kf,{className:"w-5 h-5 text-bambu-green"}),i("settings.users")]}),vt("users:create")&&a.jsxs(ke,{size:"sm",onClick:()=>{Ne(!0),Ut({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]})},children:[a.jsx(dr,{className:"w-4 h-4"}),i("settings.addUser")]})]})}),a.jsx(Mt,{children:hi?a.jsx("div",{className:"flex items-center justify-center py-8",children:a.jsx(ut,{className:"w-6 h-6 text-bambu-green animate-spin"})}):Nn.length===0?a.jsx("p",{className:"text-center text-bambu-gray py-8",children:i("settings.noUsersFound")}):a.jsx("div",{className:"divide-y divide-bambu-dark-tertiary",children:Nn.map(oe=>a.jsxs("div",{className:"py-3 flex items-center justify-between",children:[a.jsxs("div",{className:"flex-1 min-w-0",children:[a.jsx("p",{className:"text-white font-medium truncate",children:oe.username}),a.jsxs("div",{className:"flex flex-wrap gap-1 mt-1",children:[oe.is_admin&&a.jsx("span",{className:"px-2 py-0.5 rounded-full text-xs font-medium bg-purple-500/20 text-purple-300",children:i("settings.admin")}),oe.groups?.map(Nt=>a.jsx("span",{className:`px-2 py-0.5 rounded-full text-xs font-medium ${Nt.name==="Administrators"?"bg-purple-500/20 text-purple-300":Nt.name==="Operators"?"bg-blue-500/20 text-blue-300":Nt.name==="Viewers"?"bg-green-500/20 text-green-300":"bg-gray-500/20 text-gray-300"}`,children:Nt.name},Nt.id))]})]}),a.jsxs("div",{className:"flex items-center gap-1 ml-4",children:[vt("users:update")&&a.jsx(ke,{size:"sm",variant:"ghost",onClick:()=>Ao(oe),children:a.jsx(Eg,{className:"w-4 h-4"})}),vt("users:delete")&&oe.id!==c?.id&&a.jsx(ke,{size:"sm",variant:"ghost",onClick:()=>Mo(oe.id),children:a.jsx(cn,{className:"w-4 h-4"})})]})]},oe.id))})})]})]}),a.jsx("div",{children:a.jsxs(_t,{children:[a.jsx(Pn,{children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("h3",{className:"text-lg font-semibold text-white flex items-center gap-2",children:[a.jsx(PA,{className:"w-5 h-5 text-bambu-green"}),i("settings.groups")]}),vt("groups:create")&&a.jsxs(ke,{size:"sm",onClick:()=>{Fe(!0),pr()},children:[a.jsx(dr,{className:"w-4 h-4"}),i("settings.addGroup")]})]})}),a.jsx(Mt,{children:Yr?a.jsx("div",{className:"flex items-center justify-center py-8",children:a.jsx(ut,{className:"w-6 h-6 text-bambu-green animate-spin"})}):xr.length===0?a.jsx("p",{className:"text-center text-bambu-gray py-8",children:i("settings.noGroupsFound")}):a.jsx("div",{className:"divide-y divide-bambu-dark-tertiary",children:xr.map(oe=>a.jsxs("div",{className:"py-3",children:[a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(PA,{className:`w-4 h-4 ${oe.name==="Administrators"?"text-purple-400":oe.name==="Operators"?"text-blue-400":oe.name==="Viewers"?"text-green-400":"text-bambu-gray"}`}),a.jsx("span",{className:"text-white font-medium",children:oe.name}),oe.is_system&&a.jsx("span",{className:"px-2 py-0.5 rounded text-xs bg-yellow-500/20 text-yellow-400",children:i("settings.system")})]}),a.jsxs("div",{className:"flex items-center gap-1",children:[vt("groups:update")&&a.jsx(ke,{size:"sm",variant:"ghost",onClick:()=>ql(oe),children:a.jsx(Eg,{className:"w-4 h-4"})}),vt("groups:delete")&&!oe.is_system&&a.jsx(ke,{size:"sm",variant:"ghost",onClick:()=>En(oe.id),children:a.jsx(cn,{className:"w-4 h-4"})})]})]}),a.jsx("p",{className:"text-sm text-bambu-gray mt-1 ml-6",children:oe.description||i("settings.noDescription")}),a.jsxs("div",{className:"flex items-center gap-4 mt-2 ml-6 text-xs text-bambu-gray",children:[a.jsx("span",{children:i("settings.userCount",{count:oe.user_count})}),a.jsx("span",{children:i("settings.permissionCount",{count:oe.permissions.length})})]})]},oe.id))})})]})})]}),!l&&a.jsx(_t,{children:a.jsx(Mt,{className:"py-6",children:a.jsxs("div",{className:"text-center",children:[a.jsx(j1,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),a.jsx("h3",{className:"text-lg font-medium text-white mb-2",children:i("settings.authDisabledTitle")}),a.jsx("p",{className:"text-sm text-bambu-gray mb-4 max-w-md mx-auto",children:i("settings.authDisabledMessage")}),a.jsxs("ul",{className:"space-y-2 text-sm text-bambu-gray mb-6 text-left max-w-xs mx-auto",children:[a.jsxs("li",{className:"flex items-start gap-2",children:[a.jsx(Nr,{className:"w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0"}),a.jsx("span",{children:i("settings.authDisabledFeature1")})]}),a.jsxs("li",{className:"flex items-start gap-2",children:[a.jsx(Nr,{className:"w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0"}),a.jsx("span",{children:i("settings.authDisabledFeature2")})]}),a.jsxs("li",{className:"flex items-start gap-2",children:[a.jsx(Nr,{className:"w-4 h-4 text-bambu-green mt-0.5 flex-shrink-0"}),a.jsx("span",{children:i("settings.authDisabledFeature3")})]})]}),a.jsxs(ke,{onClick:()=>e("/setup"),children:[a.jsx(P1,{className:"w-4 h-4"}),i("settings.enableAuthentication")]})]})})})]}),Ie&&!Kt?.advanced_auth_enabled&&a.jsx("div",{className:"fixed inset-0 bg-black flex items-center justify-center z-50 p-4",onClick:()=>{Ne(!1),Ut({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]})},children:a.jsxs(_t,{className:"w-full max-w-md",onClick:oe=>oe.stopPropagation(),children:[a.jsx(Pn,{children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(Kf,{className:"w-5 h-5 text-bambu-green"}),a.jsx("h2",{className:"text-lg font-semibold text-white",children:i("settings.createUser")})]}),a.jsx(ke,{variant:"ghost",size:"sm",onClick:()=>{Ne(!1),Ut({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]})},children:a.jsx(Lt,{className:"w-5 h-5"})})]})}),a.jsxs(Mt,{children:[a.jsxs("div",{className:"space-y-4",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:i("settings.username")}),a.jsx("input",{type:"text",value:gt.username,onChange:oe=>Ut({...gt,username:oe.target.value}),className:"w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors",placeholder:i("settings.enterUsername"),autoComplete:"username"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:i("settings.password")}),a.jsx("input",{type:"password",value:gt.password,onChange:oe=>Ut({...gt,password:oe.target.value}),className:"w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors",placeholder:i("settings.enterPassword"),autoComplete:"new-password",minLength:6})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:i("settings.confirmPassword")}),a.jsx("input",{type:"password",value:gt.confirmPassword,onChange:oe=>Ut({...gt,confirmPassword:oe.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors ${gt.confirmPassword&>.password!==gt.confirmPassword?"border-red-500":"border-bambu-dark-tertiary"}`,placeholder:i("settings.confirmPasswordPlaceholder"),autoComplete:"new-password",minLength:6}),gt.confirmPassword&>.password!==gt.confirmPassword&&a.jsx("p",{className:"text-red-400 text-xs mt-1",children:i("settings.passwordsDoNotMatch")})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:"Groups"}),a.jsxs("div",{className:"space-y-2 max-h-40 overflow-y-auto p-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg",children:[xr.map(oe=>a.jsxs("label",{className:"flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-tertiary cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:gt.group_ids.includes(oe.id),onChange:()=>Ts(oe.id),className:"w-4 h-4 rounded border-bambu-gray text-bambu-green focus:ring-bambu-green focus:ring-offset-0 bg-bambu-dark"}),a.jsx("span",{className:"text-sm text-white",children:oe.name}),oe.is_system&&a.jsx("span",{className:"text-xs text-yellow-400",children:"(System)"})]},oe.id)),xr.length===0&&a.jsx("p",{className:"text-sm text-bambu-gray",children:i("settings.noGroupsAvailable")})]})]})]}),a.jsxs("div",{className:"mt-6 flex justify-end gap-3",children:[a.jsx(ke,{variant:"secondary",onClick:()=>{Ne(!1),Ut({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]})},children:"Cancel"}),a.jsx(ke,{onClick:ls,disabled:nn.isPending||!gt.username||!gt.password||gt.password!==gt.confirmPassword||gt.password.length<6,children:nn.isPending?a.jsxs(a.Fragment,{children:[a.jsx(ut,{className:"w-4 h-4 animate-spin"}),"Creating..."]}):a.jsxs(a.Fragment,{children:[a.jsx(dr,{className:"w-4 h-4"}),"Create User"]})})]})]})]})}),Ie&&Kt?.advanced_auth_enabled&&a.jsx(JYe,{formData:gt,setFormData:Ut,groups:xr,onClose:()=>{Ne(!1),Ut({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]})},onCreate:ls,isCreating:nn.isPending,isCreateButtonDisabled:nn.isPending||!gt.username||!gt.email}),Ge&&rt!==null&&a.jsx("div",{className:"fixed inset-0 bg-black flex items-center justify-center z-50 p-4",onClick:()=>{Me(!1),Ee(null),Ut({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]})},children:a.jsxs(_t,{className:"w-full max-w-md",onClick:oe=>oe.stopPropagation(),children:[a.jsx(Pn,{children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(Eg,{className:"w-5 h-5 text-bambu-green"}),a.jsx("h2",{className:"text-lg font-semibold text-white",children:i("settings.editUser")})]}),a.jsx(ke,{variant:"ghost",size:"sm",onClick:()=>{Me(!1),Ee(null),Ut({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]})},children:a.jsx(Lt,{className:"w-5 h-5"})})]})}),a.jsxs(Mt,{children:[a.jsxs("div",{className:"space-y-4",children:[a.jsxs("div",{children:[a.jsxs("label",{className:"block text-sm font-medium text-white mb-2",children:[i("settings.username")," ",Kt?.advanced_auth_enabled&&a.jsx("span",{className:"text-red-400",children:"*"})]}),a.jsx("input",{type:"text",value:gt.username,onChange:oe=>Ut({...gt,username:oe.target.value}),className:"w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors",placeholder:i("settings.enterUsername"),autoComplete:"username"})]}),a.jsxs("div",{children:[a.jsxs("label",{className:"block text-sm font-medium text-white mb-2",children:[i("users.form.email")||"Email"," ",Kt?.advanced_auth_enabled?a.jsx("span",{className:"text-red-400",children:"*"}):a.jsxs("span",{className:"text-bambu-gray font-normal",children:["(",i("users.form.optional")||"optional",")"]})]}),a.jsx("input",{type:"email",value:gt.email,onChange:oe=>Ut({...gt,email:oe.target.value}),className:"w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors",placeholder:i("users.form.emailPlaceholder")||"user@example.com",required:Kt?.advanced_auth_enabled})]}),!Kt?.advanced_auth_enabled&&a.jsxs(a.Fragment,{children:[a.jsxs("div",{children:[a.jsxs("label",{className:"block text-sm font-medium text-white mb-2",children:[i("users.form.password")||"Password"," ",a.jsxs("span",{className:"text-bambu-gray font-normal",children:["(",i("users.form.leaveBlankToKeep")||"leave blank to keep current",")"]})]}),a.jsx("input",{type:"password",value:gt.password,onChange:oe=>Ut({...gt,password:oe.target.value,confirmPassword:""}),className:"w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors",placeholder:i("settings.enterNewPassword"),autoComplete:"new-password",minLength:6})]}),gt.password&&a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:i("settings.confirmPassword")}),a.jsx("input",{type:"password",value:gt.confirmPassword,onChange:oe=>Ut({...gt,confirmPassword:oe.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors ${gt.confirmPassword&>.password!==gt.confirmPassword?"border-red-500":"border-bambu-dark-tertiary"}`,placeholder:i("settings.confirmNewPassword"),autoComplete:"new-password",minLength:6}),gt.confirmPassword&>.password!==gt.confirmPassword&&a.jsx("p",{className:"text-red-400 text-xs mt-1",children:i("settings.passwordsDoNotMatch")})]})]}),Kt?.advanced_auth_enabled&&a.jsx("div",{className:"bg-bambu-dark-secondary/50 border border-bambu-green/20 rounded-lg p-3",children:a.jsx("p",{className:"text-sm text-bambu-gray",children:i("users.form.passwordManagedByAdvancedAuth")||'Password is managed by Advanced Authentication. Use "Reset Password" to send a new password to the user via email.'})}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:i("users.form.groups")||"Groups"}),a.jsx("div",{className:"space-y-2 max-h-40 overflow-y-auto p-2 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg",children:xr.map(oe=>a.jsxs("label",{className:"flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-tertiary cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:gt.group_ids.includes(oe.id),onChange:()=>Ts(oe.id),className:"w-4 h-4 rounded border-bambu-gray text-bambu-green focus:ring-bambu-green focus:ring-offset-0 bg-bambu-dark"}),a.jsx("span",{className:"text-sm text-white",children:oe.name}),oe.is_system&&a.jsxs("span",{className:"text-xs text-yellow-400",children:["(",i("users.system")||"System",")"]})]},oe.id))})]})]}),a.jsxs("div",{className:"mt-6 flex justify-end gap-3",children:[a.jsx(ke,{variant:"secondary",onClick:()=>{Me(!1),Ee(null),Ut({username:"",password:"",email:"",confirmPassword:"",role:"user",group_ids:[]})},children:i("users.modal.cancel")||"Cancel"}),a.jsx(ke,{onClick:()=>Ei(rt),disabled:Mn.isPending||!gt.username||Kt?.advanced_auth_enabled&&!gt.email||!!(!Kt?.advanced_auth_enabled&>.password&&(gt.password!==gt.confirmPassword||gt.password.length<6)),children:Mn.isPending?a.jsxs(a.Fragment,{children:[a.jsx(ut,{className:"w-4 h-4 animate-spin"}),i("users.modal.saving")||"Saving..."]}):a.jsxs(a.Fragment,{children:[a.jsx(gs,{className:"w-4 h-4"}),i("users.modal.saveChanges")||"Save Changes"]})})]})]})]})}),Ke!==null&&a.jsx("div",{className:"fixed inset-0 bg-black/80 flex items-center justify-center z-50 p-4",onClick:()=>{Be(null),$e(null)},children:a.jsxs(_t,{className:"w-full max-w-md",onClick:oe=>oe.stopPropagation(),children:[a.jsx(Pn,{children:a.jsxs("div",{className:"flex items-center gap-2 text-red-400",children:[a.jsx(cn,{className:"w-5 h-5"}),a.jsx("h3",{className:"text-lg font-semibold",children:i("settings.deleteUserTitle")})]})}),a.jsx(Mt,{className:"space-y-4",children:at?a.jsx("div",{className:"flex items-center justify-center py-4",children:a.jsx("div",{className:"animate-spin rounded-full h-6 w-6 border-2 border-bambu-green border-t-transparent"})}):ue&&ue.archives+ue.queue_items+ue.library_files>0?a.jsxs(a.Fragment,{children:[a.jsx("p",{className:"text-white",children:i("settings.userHasCreated")}),a.jsxs("ul",{className:"list-disc list-inside text-bambu-gray space-y-1",children:[ue.archives>0&&a.jsxs("li",{children:[ue.archives," archive",ue.archives!==1?"s":""]}),ue.queue_items>0&&a.jsxs("li",{children:[ue.queue_items," queue item",ue.queue_items!==1?"s":""]}),ue.library_files>0&&a.jsxs("li",{children:[ue.library_files," library file",ue.library_files!==1?"s":""]})]}),a.jsx("p",{className:"text-bambu-gray text-sm",children:i("settings.userItemsQuestion")}),a.jsxs("div",{className:"flex flex-col gap-2",children:[a.jsx(ke,{variant:"danger",onClick:()=>Mr.mutate({id:Ke,deleteItems:!0}),disabled:Mr.isPending,className:"justify-center",children:"Delete user AND their items"}),a.jsx(ke,{variant:"secondary",onClick:()=>Mr.mutate({id:Ke,deleteItems:!1}),disabled:Mr.isPending,className:"justify-center",children:"Delete user, keep items (become ownerless)"}),a.jsx(ke,{variant:"ghost",onClick:()=>{Be(null),$e(null)},disabled:Mr.isPending,className:"justify-center",children:"Cancel"})]})]}):a.jsxs(a.Fragment,{children:[a.jsx("p",{className:"text-white",children:i("settings.deleteUserConfirm")}),a.jsx("p",{className:"text-bambu-gray text-sm",children:i("settings.actionCannotBeUndone")}),a.jsxs("div",{className:"flex gap-2 justify-end",children:[a.jsx(ke,{variant:"ghost",onClick:()=>{Be(null),$e(null)},disabled:Mr.isPending,children:"Cancel"}),a.jsx(ke,{variant:"danger",onClick:()=>Mr.mutate({id:Ke,deleteItems:!1}),disabled:Mr.isPending,children:"Delete User"})]})]})})]})}),(Ft||xt)&&a.jsx("div",{className:"fixed inset-0 bg-black flex items-center justify-center z-50 p-4",onClick:()=>{Fe(!1),Wt(null),pr()},children:a.jsxs(_t,{className:"w-full max-w-2xl max-h-[90vh] overflow-y-auto",onClick:oe=>oe.stopPropagation(),children:[a.jsx(Pn,{children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(PA,{className:"w-5 h-5 text-bambu-green"}),a.jsx("h2",{className:"text-lg font-semibold text-white",children:xt?"Edit Group":"Create Group"})]}),a.jsx(ke,{variant:"ghost",size:"sm",onClick:()=>{Fe(!1),Wt(null),pr()},children:a.jsx(Lt,{className:"w-5 h-5"})})]})}),a.jsxs(Mt,{children:[a.jsxs("div",{className:"space-y-4",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:i("settings.groupName")}),a.jsx("input",{type:"text",value:hn.name,onChange:oe=>or({...hn,name:oe.target.value}),disabled:xt?.is_system,className:"w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors disabled:opacity-50",placeholder:i("settings.enterGroupName")}),xt?.is_system&&a.jsx("p",{className:"text-xs text-yellow-400 mt-1",children:i("settings.systemGroupWarning")})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:"Description"}),a.jsx("textarea",{value:hn.description,onChange:oe=>or({...hn,description:oe.target.value}),rows:2,className:"w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors resize-none",placeholder:i("settings.enterDescriptionOptional")})]}),a.jsxs("div",{children:[a.jsxs("label",{className:"block text-sm font-medium text-white mb-2",children:["Permissions (",hn.permissions.length," selected)"]}),a.jsx("div",{className:"space-y-2 max-h-96 overflow-y-auto",children:No?.categories.map(oe=>a.jsxs("div",{className:"border border-bambu-dark-tertiary rounded-lg overflow-hidden",children:[a.jsxs("div",{className:"flex items-center justify-between px-4 py-2 bg-bambu-dark-secondary cursor-pointer hover:bg-bambu-dark-tertiary transition-colors",onClick:()=>Jb(oe.name),children:[a.jsxs("div",{className:"flex items-center gap-3",children:[a.jsx("button",{type:"button",onClick:Nt=>{Nt.stopPropagation(),Lv(oe,!ad(oe))},className:`w-5 h-5 rounded border flex items-center justify-center transition-colors ${ad(oe)?"bg-bambu-green border-bambu-green":nf(oe)?"bg-bambu-green/50 border-bambu-green":"border-bambu-gray hover:border-white"}`,children:(ad(oe)||nf(oe))&&a.jsx(qi,{className:"w-3 h-3 text-white"})}),a.jsx("span",{className:"text-white font-medium",children:oe.name}),a.jsxs("span",{className:"text-xs text-bambu-gray",children:["(",oe.permissions.filter(Nt=>hn.permissions.includes(Nt.value)).length,"/",oe.permissions.length,")"]})]}),Kn.has(oe.name)?a.jsx(Sr,{className:"w-4 h-4 text-bambu-gray"}):a.jsx(_s,{className:"w-4 h-4 text-bambu-gray"})]}),Kn.has(oe.name)&&a.jsx("div",{className:"p-3 bg-bambu-dark space-y-2",children:oe.permissions.map(Nt=>a.jsxs("label",{className:"flex items-center gap-3 px-2 py-1.5 rounded hover:bg-bambu-dark-secondary cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:hn.permissions.includes(Nt.value),onChange:()=>Ym(Nt.value),className:"w-4 h-4 rounded border-bambu-gray text-bambu-green focus:ring-bambu-green focus:ring-offset-0 bg-bambu-dark-secondary"}),a.jsx("span",{className:"text-sm text-bambu-gray",children:Nt.label})]},Nt.value))})]},oe.name))})]})]}),a.jsxs("div",{className:"mt-6 flex justify-end gap-3",children:[a.jsx(ke,{variant:"secondary",onClick:()=>{Fe(!1),Wt(null),pr()},children:"Cancel"}),a.jsx(ke,{onClick:xt?tf:Zb,disabled:ko.isPending||As.isPending||!hn.name.trim(),children:ko.isPending||As.isPending?a.jsxs(a.Fragment,{children:[a.jsx(ut,{className:"w-4 h-4 animate-spin"}),xt?"Saving...":"Creating..."]}):a.jsxs(a.Fragment,{children:[a.jsx(gs,{className:"w-4 h-4"}),xt?"Save Changes":"Create Group"]})})]})]})]})}),Qt!==null&&a.jsx(er,{title:i("settings.deleteGroupTitle"),message:i("settings.deleteGroupMessage"),confirmText:i("settings.deleteGroup"),variant:"danger",onConfirm:()=>{Eo.mutate(Qt),En(null)},onCancel:()=>En(null)}),be==="email"&&a.jsx(sQe,{}),be==="backup"&&a.jsx(aQe,{}),ye&&a.jsx(er,{title:i("settings.disableAuthenticationTitle"),message:i("settings.disableAuthenticationMessage"),confirmText:i("settings.disableAuthentication"),variant:"danger",onConfirm:async()=>{try{await ce.disableAuth(),o(i("settings.toast.authDisabled"),"success"),await u(),se(!1),window.location.href="/"}catch(oe){const Nt=oe instanceof Error?oe.message:i("settings.toast.authDisableFailed");o(Nt,"error")}},onCancel:()=>se(!1)}),Oe&&a.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4",onClick:()=>{He(!1),Ue({currentPassword:"",newPassword:"",confirmPassword:""})},children:a.jsxs(_t,{className:"w-full max-w-md",onClick:oe=>oe.stopPropagation(),children:[a.jsx(Pn,{children:a.jsxs("div",{className:"flex items-center justify-between",children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx(Wo,{className:"w-5 h-5 text-bambu-green"}),a.jsx("h2",{className:"text-lg font-semibold text-white",children:i("settings.changePassword")})]}),a.jsx(ke,{variant:"ghost",size:"sm",onClick:()=>{He(!1),Ue({currentPassword:"",newPassword:"",confirmPassword:""})},children:a.jsx(Lt,{className:"w-5 h-5"})})]})}),a.jsxs(Mt,{children:[a.jsxs("div",{className:"space-y-4",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:"Current Password"}),a.jsx("input",{type:"password",value:tt.currentPassword,onChange:oe=>Ue({...tt,currentPassword:oe.target.value}),className:"w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors",placeholder:i("settings.enterCurrentPassword"),autoComplete:"current-password"})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:"New Password"}),a.jsx("input",{type:"password",value:tt.newPassword,onChange:oe=>Ue({...tt,newPassword:oe.target.value}),className:"w-full px-4 py-3 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors",placeholder:i("settings.enterNewPasswordMin6"),autoComplete:"new-password",minLength:6})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm font-medium text-white mb-2",children:"Confirm New Password"}),a.jsx("input",{type:"password",value:tt.confirmPassword,onChange:oe=>Ue({...tt,confirmPassword:oe.target.value}),className:`w-full px-4 py-3 bg-bambu-dark-secondary border rounded-lg text-white placeholder-bambu-gray focus:outline-none focus:ring-2 focus:ring-bambu-green/50 focus:border-bambu-green transition-colors ${tt.confirmPassword&&tt.newPassword!==tt.confirmPassword?"border-red-500":"border-bambu-dark-tertiary"}`,placeholder:i("settings.confirmNewPassword"),autoComplete:"new-password",minLength:6}),tt.confirmPassword&&tt.newPassword!==tt.confirmPassword&&a.jsx("p",{className:"text-red-400 text-xs mt-1",children:i("settings.passwordsDoNotMatch")})]})]}),a.jsxs("div",{className:"mt-6 flex justify-end gap-3",children:[a.jsx(ke,{variant:"secondary",onClick:()=>{He(!1),Ue({currentPassword:"",newPassword:"",confirmPassword:""})},children:"Cancel"}),a.jsx(ke,{onClick:async()=>{if(tt.newPassword!==tt.confirmPassword){o(i("settings.toast.passwordsDoNotMatch"),"error");return}if(tt.newPassword.length<6){o(i("settings.toast.passwordTooShort"),"error");return}Te(!0);try{await ce.changePassword(tt.currentPassword,tt.newPassword),o(i("settings.toast.passwordChanged"),"success"),He(!1),Ue({currentPassword:"",newPassword:"",confirmPassword:""})}catch(oe){const Nt=oe instanceof Error?oe.message:"Failed to change password";o(Nt,"error")}finally{Te(!1)}},disabled:xe||!tt.currentPassword||!tt.newPassword||tt.newPassword!==tt.confirmPassword||tt.newPassword.length<6,children:xe?a.jsxs(a.Fragment,{children:[a.jsx(ut,{className:"w-4 h-4 animate-spin"}),"Changing..."]}):a.jsxs(a.Fragment,{children:[a.jsx(Wo,{className:"w-4 h-4"}),"Change Password"]})})]})]})]})})]})}const cae=t=>{const e=parseFloat(t);return(Math.trunc(e*1e3)/1e3).toFixed(3)},fQe=t=>t.startsWith("HH")?"HF":"S",mQe=t=>{const e=t.match(/^([A-Z]{2}\d{2})/);return e?e[1]:"HH00"},UR=t=>{const e=["High Flow_","High Flow ","Standard_","Standard ","HF_","HF ","S_","S "];for(const r of e)if(t.startsWith(r))return t.slice(r.length);const n=t.indexOf("_");return n>0?t.slice(n+1):t};function bP({profile:t,onEdit:e,onCopy:n,selectionMode:r,isSelected:i,onToggleSelect:s,note:o}){const l=fQe(t.nozzle_id),c=t.nozzle_diameter,u=()=>{r&&s?s():e()};return a.jsxs("div",{className:"flex items-center gap-2",children:[r&&a.jsx("button",{onClick:s,className:"text-bambu-gray hover:text-white transition-colors p-1",children:i?a.jsx(qs,{className:"w-4 h-4 text-bambu-green"}):a.jsx(ll,{className:"w-4 h-4"})}),a.jsxs("button",{onClick:u,className:`flex-1 text-left px-3 py-2 bg-bambu-dark rounded hover:bg-bambu-dark-tertiary transition-colors ${i?"ring-1 ring-bambu-green":""}`,children:[a.jsxs("div",{className:"flex items-center gap-2",children:[a.jsx("span",{className:"text-bambu-green font-mono text-sm font-bold whitespace-nowrap",children:cae(t.k_value)}),a.jsx("span",{className:"text-white text-sm truncate flex-1",title:t.name,children:t.name||"Unnamed"}),o&&a.jsx("span",{title:"Has note",children:a.jsx(HK,{className:"w-3 h-3 text-yellow-500"})}),a.jsxs("span",{className:"text-xs text-bambu-gray whitespace-nowrap",children:[l," ",c]})]}),o&&a.jsxs("div",{className:"text-xs mt-0.5 truncate text-yellow-500/70",title:o,children:["Note: ",o.length>50?o.substring(0,50)+"...":o]})]}),!r&&n&&a.jsx("button",{onClick:d=>{d.stopPropagation(),n()},className:"text-bambu-gray hover:text-white transition-colors p-1",title:"Copy profile",children:a.jsx(Fl,{className:"w-4 h-4"})})]})}function xP({profile:t,printerId:e,nozzleDiameter:n,existingProfiles:r=[],isDualNozzle:i=!1,initialNote:s="",initialNoteKey:o=null,onClose:l,onSave:c,onSaveNote:u,hasPermission:d}){const{t:h}=Sn(),{showToast:m}=Hn(),[p,b]=_.useState(t?.name||""),[v,x]=_.useState(t?.k_value?cae(t.k_value):"0.020"),[y,S]=_.useState(t?.filament_id||""),[N,A]=_.useState(t?.nozzle_id?mQe(t.nozzle_id):"HH00"),[k,C]=_.useState(t?.nozzle_diameter||n),[E,P]=_.useState(t?[t.extruder_id]:i?[0,1]:[0]),[T,j]=_.useState(!1),[z,L]=_.useState({current:0,total:0}),[B,R]=_.useState(s),$=Jr.useMemo(()=>{const K=new Map;for(const ne of r)if(ne.filament_id&&!K.has(ne.filament_id)){const ie=UR(ne.name||"");K.set(ne.filament_id,{id:ne.filament_id,name:ie||ne.filament_id})}return Array.from(K.values()).sort((ne,ie)=>ne.name.localeCompare(ie.name))},[r]),q=pt({mutationFn:K=>(console.log("[KProfile] Calling API..."),ce.setKProfile(e,K)),onSuccess:K=>{if(console.log("[KProfile] Save success:",K),m(h("kProfiles.toast.profileSaved")),u&&B!==s){let ne;B===""&&o?ne=o:t&&t.slot_id>0?ne=t.setting_id||`slot_${t.slot_id}_${t.filament_id}_${t.extruder_id}`:ne=`name_${p}_${y}`,u(ne,B)}j(!0),setTimeout(()=>{j(!1),c()},2500)},onError:K=>{console.error("[KProfile] Save error:",K),m(K.message,"error"),j(!1)}}),I=pt({mutationFn:K=>(console.log("[KProfile] Deleting profile..."),ce.deleteKProfile(e,K)),onSuccess:K=>{console.log("[KProfile] Delete success:",K),m(h("kProfiles.toast.profileDeleted")),j(!0),setTimeout(()=>{j(!1),l()},4e3)},onError:K=>{console.error("[KProfile] Delete error:",K),m(K.message,"error"),j(!1)}}),[G,Y]=_.useState(!1),re=()=>{t&&I.mutate({slot_id:t.slot_id,extruder_id:t.extruder_id,nozzle_id:t.nozzle_id,nozzle_diameter:t.nozzle_diameter,filament_id:t.filament_id,setting_id:t.setting_id})},H=async K=>{if(K.preventDefault(),i&&!t&&E.length===0){m(h("kProfiles.toast.selectAtLeastOneExtruder"),"error");return}const ne=parseFloat(v).toFixed(6),ie=`${N}-${k}`;if(t||E.length===1){const pe={name:p,k_value:ne,filament_id:y,nozzle_id:ie,nozzle_diameter:k,extruder_id:t?t.extruder_id:E[0],setting_id:t?.setting_id,slot_id:t?.slot_id??0};console.log("[KProfile] Saving profile:",pe),q.mutate(pe);return}j(!0),L({current:1,total:E.length});const be=E.map(pe=>({name:p,k_value:ne,filament_id:y,nozzle_id:ie,nozzle_diameter:k,extruder_id:pe,setting_id:void 0,slot_id:0}));console.log(`[KProfile] Saving ${be.length} profiles in batch:`,be);try{if(await ce.setKProfilesBatch(e,be),m(h("kProfiles.toast.profilesSaved",{count:E.length})),u&&B){const pe=`name_${p}_${y}`;u(pe,B)}}catch(pe){console.error("[KProfile] Failed to save batch:",pe),m(h("kProfiles.toast.failedToSaveBatch"),"error"),j(!1),L({current:0,total:0});return}L({current:E.length,total:E.length}),setTimeout(()=>{j(!1),L({current:0,total:0}),c()},3e3)};return a.jsxs("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:[a.jsxs(_t,{className:"w-full max-w-md relative",children:[T&&a.jsxs("div",{className:"absolute inset-0 bg-bambu-dark-secondary/90 flex flex-col items-center justify-center z-10 rounded-lg",children:[a.jsx(ut,{className:"w-8 h-8 text-bambu-green animate-spin mb-3"}),a.jsx("p",{className:"text-white font-medium",children:z.total>1?h("kProfiles.modal.savingExtruder",{current:z.current,total:z.total}):h("kProfiles.modal.syncing")}),a.jsx("p",{className:"text-bambu-gray text-sm mt-1",children:h("kProfiles.modal.pleaseWait")})]}),a.jsxs(Mt,{className:"p-0",children:[a.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-bambu-dark-tertiary",children:[a.jsx("h2",{className:"text-xl font-semibold text-white",children:h(t?"kProfiles.modal.editTitle":"kProfiles.modal.addTitle")}),a.jsx("button",{onClick:l,className:"text-bambu-gray hover:text-white transition-colors",disabled:T,children:a.jsx(Lt,{className:"w-5 h-5"})})]}),a.jsxs("form",{onSubmit:H,className:"p-4 space-y-4",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:h("kProfiles.modal.profileName")}),a.jsx("input",{type:"text",value:p,onChange:K=>b(K.target.value),disabled:!!t,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none ${t?"opacity-60 cursor-not-allowed":""}`,placeholder:h("kProfiles.modal.profileNamePlaceholder"),required:!t})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:h("kProfiles.modal.kValue")}),a.jsx("input",{type:"text",inputMode:"decimal",value:v,onChange:K=>{const ne=K.target.value;(ne===""||/^\d*\.?\d*$/.test(ne))&&x(ne)},onBlur:K=>{const ne=parseFloat(K.target.value);isNaN(ne)||x((Math.trunc(ne*1e3)/1e3).toFixed(3))},className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none font-mono",placeholder:h("kProfiles.modal.kValuePlaceholder"),required:!0}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:h("kProfiles.modal.kValueHelp")})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:h("kProfiles.modal.filament")}),a.jsxs("select",{value:y,onChange:K=>{const ne=K.target.value;if(S(ne),!t&&ne&&!p){const ie=$.find(be=>be.id===ne);ie&&b(`${N==="HH00"?"HF":"S"} ${ie.name}`)}},disabled:!!t,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none ${t?"opacity-60 cursor-not-allowed":""}`,required:!t,children:[a.jsx("option",{value:"",children:h("kProfiles.modal.selectFilament")}),t?.filament_id&&a.jsx("option",{value:t.filament_id,children:$.find(K=>K.id===t.filament_id)?.name||t.filament_id},t.filament_id),!t&&$.map(K=>a.jsx("option",{value:K.id,children:K.name},K.id))]}),!t&&$.length===0&&a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:h("kProfiles.modal.noFilamentsHelp")})]}),a.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:h("kProfiles.modal.flowType")}),a.jsxs("select",{value:N,onChange:K=>{const ne=K.target.value;if(A(ne),!t&&y&&!p){const ie=$.find(be=>be.id===y);ie&&b(`${ne==="HS00"?"HF":"S"} ${ie.name}`)}},disabled:!!t,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none ${t?"opacity-60 cursor-not-allowed":""}`,children:[a.jsx("option",{value:"HH00",children:h("kProfiles.modal.highFlow")}),a.jsx("option",{value:"HS00",children:h("kProfiles.modal.standard")})]})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:h("kProfiles.modal.nozzleSize")}),a.jsxs("select",{value:k,onChange:K=>C(K.target.value),disabled:!!t,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none ${t?"opacity-60 cursor-not-allowed":""}`,children:[a.jsx("option",{value:"0.2",children:"0.2mm"}),a.jsx("option",{value:"0.4",children:"0.4mm"}),a.jsx("option",{value:"0.6",children:"0.6mm"}),a.jsx("option",{value:"0.8",children:"0.8mm"})]})]})]}),i&&a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:h(t?"kProfiles.modal.extruder":"kProfiles.modal.extruders")}),t?a.jsx("div",{className:"px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white opacity-60",children:t.extruder_id===1?h("kProfiles.modal.left"):h("kProfiles.modal.right")}):a.jsxs("div",{className:"flex gap-4",children:[a.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:E.includes(1),onChange:K=>{K.target.checked?P([...E,1]):P(E.filter(ne=>ne!==1))},className:"w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green focus:ring-offset-0 accent-bambu-green"}),a.jsx("span",{className:"text-white",children:h("kProfiles.modal.left")})]}),a.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:E.includes(0),onChange:K=>{K.target.checked?P([...E,0]):P(E.filter(ne=>ne!==0))},className:"w-4 h-4 rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green focus:ring-offset-0 accent-bambu-green"}),a.jsx("span",{className:"text-white",children:h("kProfiles.modal.right")})]})]})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:h("kProfiles.modal.notes")}),a.jsx("textarea",{value:B,onChange:K=>R(K.target.value),placeholder:h("kProfiles.modal.notesPlaceholder"),rows:2,className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none resize-none"}),a.jsx("p",{className:"text-xs text-bambu-gray mt-1",children:h("kProfiles.modal.notesHelp")})]}),a.jsxs("div",{className:"flex gap-2 pt-4",children:[t&&a.jsx(ke,{type:"button",variant:"secondary",onClick:()=>Y(!0),disabled:I.isPending||T||!d("kprofiles:delete"),title:d("kprofiles:delete")?void 0:h("kProfiles.permission.noDelete"),className:"text-red-500 hover:bg-red-500/10",children:I.isPending?a.jsx(ut,{className:"w-4 h-4 animate-spin"}):a.jsx(cn,{className:"w-4 h-4"})}),a.jsx(ke,{type:"button",variant:"secondary",onClick:l,disabled:T,className:"flex-1",children:h("common.cancel")}),a.jsxs(ke,{type:"submit",disabled:q.isPending||T||!d(t?"kprofiles:update":"kprofiles:create"),title:d(t?"kprofiles:update":"kprofiles:create")?void 0:h(t?"kProfiles.permission.noUpdate":"kProfiles.permission.noCreate"),className:"flex-1",children:[q.isPending?a.jsx(ut,{className:"w-4 h-4 animate-spin"}):a.jsx(FM,{className:"w-4 h-4"}),h("common.save")]})]})]})]})]}),G&&a.jsx("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-[60]",children:a.jsx(_t,{className:"w-full max-w-sm",children:a.jsxs(Mt,{className:"p-6",children:[a.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[a.jsx("div",{className:"w-10 h-10 rounded-full bg-red-500/20 flex items-center justify-center",children:a.jsx(cn,{className:"w-5 h-5 text-red-500"})}),a.jsxs("div",{children:[a.jsx("h3",{className:"text-lg font-semibold text-white",children:h("kProfiles.deleteConfirm.title")}),a.jsx("p",{className:"text-sm text-bambu-gray",children:h("kProfiles.deleteConfirm.cannotUndo")})]})]}),a.jsx("p",{className:"text-bambu-gray mb-6",children:h("kProfiles.deleteConfirm.message",{name:t?.name})}),a.jsxs("div",{className:"flex gap-3",children:[a.jsx(ke,{variant:"secondary",onClick:()=>Y(!1),className:"flex-1",children:h("common.cancel")}),a.jsxs(ke,{onClick:()=>{Y(!1),re()},disabled:I.isPending,className:"flex-1 bg-red-500 hover:bg-red-600 text-white",children:[I.isPending?a.jsx(ut,{className:"w-4 h-4 animate-spin"}):a.jsx(cn,{className:"w-4 h-4"}),h("common.delete")]})]})]})})})]})}const A1={NOZZLE_DIAMETER:"bambusy_kprofiles_nozzle",SORT_OPTION:"bambusy_kprofiles_sort"};function pQe(){const{t}=Sn(),{showToast:e}=Hn(),{hasPermission:n}=Di(),[r,i]=_.useState(null),[s,o]=_.useState(()=>localStorage.getItem(A1.NOZZLE_DIAMETER)||"0.4"),[l,c]=_.useState(null),[u,d]=_.useState(!1),[h,m]=_.useState(null),[p,b]=_.useState(""),[v,x]=_.useState("all"),[y,S]=_.useState("all"),[N,A]=_.useState(()=>localStorage.getItem(A1.SORT_OPTION)||"name"),[k,C]=_.useState(!1),[E,P]=_.useState(new Set),[T,j]=_.useState(!1),[z,L]=_.useState(!1),B=_.useCallback(V=>`${V.slot_id}_${V.extruder_id}`,[]);_.useEffect(()=>{localStorage.setItem(A1.NOZZLE_DIAMETER,s)},[s]),_.useEffect(()=>{localStorage.setItem(A1.SORT_OPTION,N)},[N]);const{data:R,isLoading:$}=st({queryKey:["printers"],queryFn:ce.getPrinters}),{data:q,isLoading:I,isFetching:G,error:Y,refetch:re}=st({queryKey:["kprofiles",r,s],queryFn:async()=>{console.log("[KProfiles] Fetching profiles for printer",r,"nozzle",s);const V=await ce.getKProfiles(r,s);return console.log("[KProfiles] Received profiles:",V?.profiles?.length||0,"profiles"),V},enabled:!!r,retry:!1,staleTime:0,gcTime:0,refetchOnMount:"always"}),{data:H}=st({queryKey:["kprofiles",r,"0.4"],queryFn:()=>ce.getKProfiles(r,"0.4"),enabled:!!r,staleTime:6e4}),{data:K,refetch:ne}=st({queryKey:["kprofile-notes",r],queryFn:()=>ce.getKProfileNotes(r),enabled:!!r,staleTime:3e4}),ie=Y?.message?.includes("not connected");_.useEffect(()=>{if(!r&&R&&R.length>0){const V=R.find(ge=>ge.is_active);V&&i(V.id)}},[r,R]),_.useEffect(()=>{if(r){const V=setTimeout(()=>{re()},150);return()=>clearTimeout(V)}},[r,s]);const be=R?.filter(V=>V.is_active)||[],pe=Jr.useMemo(()=>q?.profiles?q.profiles.filter(ge=>{const Se=p.toLowerCase(),ee=!Se||ge.name.toLowerCase().includes(Se)||ge.filament_id.toLowerCase().includes(Se),U=v==="all"||v==="left"&&ge.extruder_id===1||v==="right"&&ge.extruder_id===0,O=y==="all"||y==="hf"&&ge.nozzle_id.startsWith("HH")||y==="s"&&ge.nozzle_id.startsWith("HS");return ee&&U&&O}).sort((ge,Se)=>{switch(N){case"k_value":return parseFloat(ge.k_value)-parseFloat(Se.k_value);case"filament":return UR(ge.name).localeCompare(UR(Se.name));default:return ge.name.localeCompare(Se.name)}}):[],[q?.profiles,p,v,y,N]),de=R?.find(V=>V.id===r),Ce=de?.nozzle_count===2;_.useEffect(()=>{const V=ge=>{ge.target instanceof HTMLInputElement||ge.target instanceof HTMLTextAreaElement||ge.target instanceof HTMLSelectElement||l||u||h||(ge.key==="r"||ge.key==="R"?(ge.preventDefault(),re()):ge.key==="n"||ge.key==="N"?(ge.preventDefault(),d(!0)):ge.key==="Escape"&&k&&(ge.preventDefault(),C(!1),P(new Set)))};return window.addEventListener("keydown",V),()=>window.removeEventListener("keydown",V)},[l,u,h,k,re]);const ae=_.useCallback(()=>{if(!q?.profiles||q.profiles.length===0){e(t("kProfiles.toast.noProfilesToExport"),"error");return}const V={version:1,exported_at:new Date().toISOString(),printer:de?.name||"Unknown",nozzle_diameter:s,profiles:q.profiles.map(U=>({name:U.name,k_value:U.k_value,filament_id:U.filament_id,nozzle_id:U.nozzle_id,nozzle_diameter:U.nozzle_diameter,extruder_id:U.extruder_id}))},ge=new Blob([JSON.stringify(V,null,2)],{type:"application/json"}),Se=URL.createObjectURL(ge),ee=document.createElement("a");ee.href=Se,ee.download=`kprofiles_${de?.name||"printer"}_${s}mm_${new Date().toISOString().split("T")[0]}.json`,document.body.appendChild(ee),ee.click(),document.body.removeChild(ee),URL.revokeObjectURL(Se),e(t("kProfiles.toast.exportedProfiles",{count:q.profiles.length}))},[q?.profiles,de,s,e,t]),Ae=_.useCallback(()=>{const V=document.createElement("input");V.type="file",V.accept=".json",V.onchange=async ge=>{const Se=ge.target.files?.[0];if(Se)try{const ee=await Se.text(),U=JSON.parse(ee);if(!U.profiles||!Array.isArray(U.profiles)){e(t("kProfiles.toast.invalidFileFormat"),"error");return}let O=0;for(const Z of U.profiles)if(!(!Z.name||!Z.k_value||!Z.filament_id))try{await ce.setKProfile(r,{name:Z.name,k_value:parseFloat(Z.k_value).toFixed(6),filament_id:Z.filament_id,nozzle_id:Z.nozzle_id||`HH00-${s}`,nozzle_diameter:Z.nozzle_diameter||s,extruder_id:Z.extruder_id??0,slot_id:0}),O++,await new Promise(le=>setTimeout(le,500))}catch(le){console.error("Failed to import profile:",Z.name,le)}e(t("kProfiles.toast.importedProfiles",{count:O,total:U.profiles.length})),re()}catch(ee){console.error("Import error:",ee),e(t("kProfiles.toast.failedToParseImport"),"error")}},V.click()},[r,s,e,re,t]),Le=_.useCallback(V=>{P(ge=>{const Se=new Set(ge);return Se.has(V)?Se.delete(V):Se.add(V),Se})},[]),fe=_.useCallback(()=>{P(new Set(pe.map(V=>B(V))))},[pe,B]),Xe=_.useCallback(()=>{E.size!==0&&j(!0)},[E.size]),W=_.useCallback(async()=>{const V=pe.filter(Se=>E.has(B(Se)));L(!0);let ge=0;for(const Se of V)try{await ce.deleteKProfile(r,{slot_id:Se.slot_id,extruder_id:Se.extruder_id,nozzle_id:Se.nozzle_id,nozzle_diameter:Se.nozzle_diameter,filament_id:Se.filament_id,setting_id:Se.setting_id}),ge++,await new Promise(ee=>setTimeout(ee,300))}catch(ee){console.error("Failed to delete profile:",Se.name,ee)}e(t("kProfiles.toast.profilesDeleted",{count:ge})),L(!1),j(!1),C(!1),P(new Set),re()},[r,E,pe,e,re,B,t]),Q=_.useCallback(V=>{const ge=[];return V.setting_id&&ge.push(V.setting_id),ge.push(`slot_${V.slot_id}_${V.filament_id}_${V.extruder_id}`),ge.push(`name_${V.name}_${V.filament_id}`),ge},[]),me=_.useCallback(async(V,ge)=>{if(r)try{await ce.setKProfileNote(r,V,ge),ne()}catch(Se){console.error("Failed to save note:",Se),e(t("kProfiles.toast.failedToSaveNote"),"error")}},[r,ne,e,t]),X=_.useCallback(V=>{if(!K?.notes)return{note:"",key:null};const ge=Q(V);for(const Se of ge)if(K.notes[Se])return{note:K.notes[Se],key:Se};return{note:"",key:null}},[K,Q]),te=_.useCallback(V=>X(V).note,[X]);return $?a.jsx("div",{className:"flex justify-center py-12",children:a.jsx(ut,{className:"w-8 h-8 text-bambu-green animate-spin"})}):!R||R.length===0?a.jsx(_t,{children:a.jsxs(Mt,{className:"py-12 text-center",children:[a.jsx(Wi,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),a.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:t("kProfiles.noPrintersConfigured")}),a.jsx("p",{className:"text-bambu-gray",children:t("kProfiles.addPrinterInSettings")})]})}):be.length===0?a.jsx(_t,{children:a.jsxs(Mt,{className:"py-12 text-center",children:[a.jsx(Or,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),a.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:t("kProfiles.noActivePrinters")}),a.jsx("p",{className:"text-bambu-gray",children:t("kProfiles.enablePrinterConnection")})]})}):a.jsxs(a.Fragment,{children:[G&&!I&&a.jsxs("div",{className:"fixed inset-0 bg-black/50 flex flex-col items-center justify-center z-40",children:[a.jsx(ut,{className:"w-10 h-10 text-bambu-green animate-spin mb-3"}),a.jsx("p",{className:"text-white font-medium",children:t("kProfiles.loadingProfiles")})]}),a.jsxs("div",{className:"flex flex-wrap gap-4 mb-6",children:[a.jsxs("div",{className:"flex-1 min-w-48",children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:t("kProfiles.printer")}),a.jsx("select",{value:r||"",onChange:V=>i(parseInt(V.target.value)),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:be.map(V=>a.jsx("option",{value:V.id,children:V.name},V.id))})]}),a.jsxs("div",{className:"w-32",children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:t("kProfiles.nozzle")}),a.jsxs("select",{value:s,onChange:V=>o(V.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[a.jsx("option",{value:"0.2",children:"0.2mm"}),a.jsx("option",{value:"0.4",children:"0.4mm"}),a.jsx("option",{value:"0.6",children:"0.6mm"}),a.jsx("option",{value:"0.8",children:"0.8mm"})]})]}),a.jsxs("div",{className:"flex items-end gap-2",children:[a.jsxs(ke,{variant:"secondary",onClick:()=>re(),disabled:G||!n("kprofiles:read"),title:n("kprofiles:read")?void 0:t("kProfiles.permission.noRead"),children:[a.jsx(Ir,{className:`w-4 h-4 ${G?"animate-spin":""}`}),t("kProfiles.refresh")]}),a.jsxs(ke,{onClick:()=>d(!0),disabled:!n("kprofiles:create"),title:n("kprofiles:create")?void 0:t("kProfiles.permission.noCreate"),children:[a.jsx(dr,{className:"w-4 h-4"}),t("kProfiles.addProfile")]})]})]}),a.jsxs("div",{className:"flex flex-wrap gap-4 mb-4",children:[a.jsxs("div",{className:"flex-1 min-w-48 relative",children:[a.jsx(va,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray"}),a.jsx("input",{type:"text",value:p,onChange:V=>b(V.target.value),placeholder:t("kProfiles.searchPlaceholder"),className:"w-full pl-10 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none"})]}),Ce&&a.jsx("div",{className:"w-36",children:a.jsxs("select",{value:v,onChange:V=>x(V.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[a.jsx("option",{value:"all",children:t("kProfiles.allExtruders")}),a.jsx("option",{value:"left",children:t("kProfiles.leftOnly")}),a.jsx("option",{value:"right",children:t("kProfiles.rightOnly")})]})}),a.jsx("div",{className:"w-32",children:a.jsxs("select",{value:y,onChange:V=>S(V.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[a.jsx("option",{value:"all",children:t("kProfiles.allFlow")}),a.jsx("option",{value:"hf",children:t("kProfiles.hfOnly")}),a.jsx("option",{value:"s",children:t("kProfiles.sOnly")})]})}),a.jsx("div",{className:"w-32",children:a.jsxs("select",{value:N,onChange:V=>A(V.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[a.jsx("option",{value:"name",children:t("kProfiles.sortName")}),a.jsx("option",{value:"k_value",children:t("kProfiles.sortKValue")}),a.jsx("option",{value:"filament",children:t("kProfiles.sortFilament")})]})})]}),a.jsxs("div",{className:"flex flex-wrap gap-2 mb-6",children:[a.jsxs(ke,{variant:"secondary",onClick:ae,disabled:!q?.profiles?.length||!n("kprofiles:read"),title:n("kprofiles:read")?void 0:t("kProfiles.permission.noExport"),children:[a.jsx(Ni,{className:"w-4 h-4"}),t("kProfiles.export")]}),a.jsxs(ke,{variant:"secondary",onClick:Ae,disabled:!n("kprofiles:create"),title:n("kprofiles:create")?void 0:t("kProfiles.permission.noImport"),children:[a.jsx($a,{className:"w-4 h-4"}),t("kProfiles.import")]}),a.jsx("div",{className:"flex-1"}),k?a.jsxs(a.Fragment,{children:[a.jsxs(ke,{variant:"secondary",onClick:fe,children:[a.jsx(qs,{className:"w-4 h-4"}),t("kProfiles.selectAll")]}),a.jsxs(ke,{variant:"secondary",onClick:Xe,disabled:E.size===0||!n("kprofiles:delete"),className:"text-red-500 hover:bg-red-500/10",title:n("kprofiles:delete")?void 0:t("kProfiles.permission.noDelete"),children:[a.jsx(cn,{className:"w-4 h-4"}),t("kProfiles.delete")," (",E.size,")"]}),a.jsxs(ke,{variant:"secondary",onClick:()=>{C(!1),P(new Set)},children:[a.jsx(Lt,{className:"w-4 h-4"}),t("common.cancel")]})]}):a.jsxs(ke,{variant:"secondary",onClick:()=>C(!0),disabled:!pe.length||!n("kprofiles:delete"),title:n("kprofiles:delete")?void 0:t("kProfiles.permission.noDelete"),children:[a.jsx(qs,{className:"w-4 h-4"}),t("kProfiles.select")]})]}),I?a.jsx("div",{className:"flex justify-center py-12",children:a.jsx(ut,{className:"w-8 h-8 text-bambu-green animate-spin"})}):ie?a.jsx(_t,{children:a.jsxs(Mt,{className:"py-12 text-center",children:[a.jsx(_m,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),a.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:t("kProfiles.printerOffline")}),a.jsx("p",{className:"text-bambu-gray mb-4",children:t("kProfiles.printerOfflineDesc")}),a.jsxs(ke,{variant:"secondary",onClick:()=>re(),children:[a.jsx(Ir,{className:"w-4 h-4"}),t("common.refresh")]})]})}):pe.length>0?Ce?a.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[a.jsxs("div",{children:[a.jsx("h3",{className:"text-sm font-medium text-bambu-gray mb-2 px-1",children:t("kProfiles.leftExtruder")}),a.jsx("div",{className:"space-y-1",children:pe.filter(V=>V.extruder_id===1).map(V=>a.jsx(bP,{profile:V,onEdit:()=>c(V),onCopy:()=>m(V),selectionMode:k,isSelected:E.has(B(V)),onToggleSelect:()=>Le(B(V)),note:te(V)},B(V)))})]}),a.jsxs("div",{children:[a.jsx("h3",{className:"text-sm font-medium text-bambu-gray mb-2 px-1",children:t("kProfiles.rightExtruder")}),a.jsx("div",{className:"space-y-1",children:pe.filter(V=>V.extruder_id===0).map(V=>a.jsx(bP,{profile:V,onEdit:()=>c(V),onCopy:()=>m(V),selectionMode:k,isSelected:E.has(B(V)),onToggleSelect:()=>Le(B(V)),note:te(V)},B(V)))})]})]}):a.jsx("div",{className:"space-y-1",children:pe.map(V=>a.jsx(bP,{profile:V,onEdit:()=>c(V),onCopy:()=>m(V),selectionMode:k,isSelected:E.has(B(V)),onToggleSelect:()=>Le(B(V)),note:te(V)},B(V)))}):p||v!=="all"||y!=="all"?a.jsx(_t,{children:a.jsxs(Mt,{className:"py-12 text-center",children:[a.jsx(va,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),a.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:t("kProfiles.noMatchingProfiles")}),a.jsx("p",{className:"text-bambu-gray",children:t("kProfiles.noMatchingProfilesDesc")})]})}):a.jsx(_t,{children:a.jsxs(Mt,{className:"py-12 text-center",children:[a.jsx(FM,{className:"w-12 h-12 text-bambu-gray mx-auto mb-4"}),a.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:t("kProfiles.noKProfiles")}),a.jsx("p",{className:"text-bambu-gray mb-4",children:t("kProfiles.noKProfilesDesc",{diameter:s})}),a.jsxs(ke,{onClick:()=>d(!0),children:[a.jsx(dr,{className:"w-4 h-4"}),t("kProfiles.createFirstProfile")]})]})}),l&&r&&(()=>{const{note:V,key:ge}=X(l);return a.jsx(xP,{profile:l,printerId:r,nozzleDiameter:s,existingProfiles:H?.profiles||q?.profiles,isDualNozzle:Ce,initialNote:V,initialNoteKey:ge,onSaveNote:me,hasPermission:n,onClose:()=>{console.log("[KProfiles] Edit modal onClose - refetching profiles..."),c(null),re()},onSave:()=>{c(null),re()}})})(),u&&r&&a.jsx(xP,{printerId:r,nozzleDiameter:s,existingProfiles:H?.profiles||q?.profiles,isDualNozzle:Ce,onSaveNote:me,hasPermission:n,onClose:()=>{d(!1),re()},onSave:()=>{d(!1),re()}}),h&&r&&a.jsx(xP,{printerId:r,nozzleDiameter:s,existingProfiles:H?.profiles||q?.profiles,isDualNozzle:Ce,onSaveNote:me,hasPermission:n,profile:{...h,slot_id:0,name:`${h.name} (Copy)`},onClose:()=>{m(null),re()},onSave:()=>{m(null),re()}}),T&&a.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:a.jsx(_t,{className:"w-full max-w-sm",children:a.jsxs(Mt,{className:"p-6",children:[a.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[a.jsx("div",{className:"w-10 h-10 rounded-full bg-red-500/20 flex items-center justify-center",children:a.jsx(cn,{className:"w-5 h-5 text-red-500"})}),a.jsxs("div",{children:[a.jsx("h3",{className:"text-lg font-semibold text-white",children:t("kProfiles.bulkDelete.title")}),a.jsx("p",{className:"text-sm text-bambu-gray",children:t("kProfiles.bulkDelete.cannotUndo")})]})]}),a.jsx("p",{className:"text-bambu-gray mb-6",children:t("kProfiles.bulkDelete.message",{count:E.size})}),a.jsxs("div",{className:"flex gap-3",children:[a.jsx(ke,{variant:"secondary",onClick:()=>j(!1),disabled:z,className:"flex-1",children:t("common.cancel")}),a.jsxs(ke,{onClick:W,disabled:z,className:"flex-1 bg-red-500 hover:bg-red-600 text-white",children:[z?a.jsx(ut,{className:"w-4 h-4 animate-spin"}):a.jsx(cn,{className:"w-4 h-4"}),t("common.delete")]})]})]})})})]})}function HF(t,e){const n=`${t} ${e||""}`,r=n.match(/@?\s*(?:BBL\s+)?(?:Bambu\s+Lab\s+)?([XPAH][1-9][A-Z]?(?:\s*(?:Carbon|mini))?|H2D)/i),i=r?r[1].trim():null,s=n.match(/(\d+\.?\d*)\s*(?:mm\s*)?nozzle|nozzle\s*(\d+\.?\d*)/i),o=s?(s[1]||s[2])+"mm":null,l=n.match(/(\d+\.?\d*)mm\s*(?:Standard|Fine|Extra Fine|Draft|Quality)?/i),c=l?l[1]+"mm":null,u=n.match(/\b(PLA|PETG|ABS|ASA|TPU|PC|PA|PVA|HIPS|PP|PET(?:-?CF)?|PA(?:-?CF)?|PLA(?:-?CF)?)\b/i),d=u?u[1].toUpperCase():null;return{printer:i,nozzle:o,layerHeight:c,filamentType:d}}function Yy(t){return/^(P[FPM]US|PF\d|PP\d)/.test(t)}function gQe(t,e){const n=Hi(t);if(!n)return"";const i=new Date().getTime()-n.getTime(),s=Math.floor(i/6e4),o=Math.floor(i/36e5),l=Math.floor(i/864e5);return s<1?e("profiles.time.justNow"):s<60?e("profiles.time.minsAgo",{count:s}):o<24?e("profiles.time.hoursAgo",{count:o}):l<7?e("profiles.time.daysAgo",{count:l}):n.toLocaleDateString()}function bQe({onSuccess:t,t:e}){const{showToast:n}=Hn(),[r,i]=_.useState("email"),[s,o]=_.useState(""),[l,c]=_.useState(""),[u,d]=_.useState(""),[h,m]=_.useState(""),[p,b]=_.useState("global"),[v,x]=_.useState(null),[y,S]=_.useState(null),N=pt({mutationFn:()=>ce.cloudLogin(s,l,p),onSuccess:P=>{P.success?(n(e("profiles.login.toast.loggedIn")),t()):P.needs_verification?(x(P.verification_type||"email"),S(P.tfa_key||null),P.verification_type==="totp"?n(e("profiles.login.toast.enterTotp")):n(e("profiles.login.toast.codeSent")),i("code")):n(P.message,"error")},onError:P=>n(P.message,"error")}),A=pt({mutationFn:()=>ce.cloudVerify(s,u,y||void 0),onSuccess:P=>{P.success?(n(e("profiles.login.toast.loggedIn")),t()):n(P.message,"error")},onError:P=>n(P.message,"error")}),k=pt({mutationFn:()=>ce.cloudSetToken(h),onSuccess:()=>{n(e("profiles.login.toast.tokenSet")),t()},onError:P=>n(P.message,"error")}),C=P=>{P.preventDefault(),r==="email"?N.mutate():r==="code"?A.mutate():r==="token"&&k.mutate()},E=N.isPending||A.isPending||k.isPending;return a.jsx(_t,{className:"max-w-md mx-auto",children:a.jsxs(Mt,{children:[a.jsxs("div",{className:"text-center mb-6",children:[a.jsx("div",{className:"inline-flex items-center justify-center w-12 h-12 rounded-xl bg-bambu-green/20 mb-3",children:a.jsx(DM,{className:"w-6 h-6 text-bambu-green"})}),a.jsx("h2",{className:"text-xl font-semibold text-white",children:e("profiles.login.title")}),a.jsx("p",{className:"text-sm text-bambu-gray mt-1",children:e("profiles.login.subtitle")})]}),a.jsxs("form",{onSubmit:C,className:"space-y-4",children:[r==="email"&&a.jsxs(a.Fragment,{children:[a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:e("profiles.login.email")}),a.jsx("input",{type:"email",value:s,onChange:P=>o(P.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none",placeholder:"your@email.com",required:!0})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:e("profiles.login.password")}),a.jsx("input",{type:"password",value:l,onChange:P=>c(P.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none",placeholder:"••••••••",required:!0})]}),a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:e("profiles.login.region")}),a.jsxs("select",{value:p,onChange:P=>b(P.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none",children:[a.jsx("option",{value:"global",children:e("profiles.login.regionGlobal")}),a.jsx("option",{value:"china",children:e("profiles.login.regionChina")})]})]})]}),r==="code"&&a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:e(v==="totp"?"profiles.login.totpCode":"profiles.login.verificationCode")}),a.jsx("p",{className:"text-xs text-bambu-gray mb-2",children:v==="totp"?e("profiles.login.enterTotpHint"):e("profiles.login.checkEmail",{email:s})}),a.jsx("input",{type:"text",value:u,onChange:P=>d(P.target.value.replace(/\D/g,"").slice(0,6)),className:"w-full px-3 py-3 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-center text-2xl tracking-widest font-mono focus:border-bambu-green focus:outline-none",placeholder:"000000",maxLength:6,required:!0})]}),r==="token"&&a.jsxs("div",{children:[a.jsx("label",{className:"block text-sm text-bambu-gray mb-1",children:e("profiles.login.accessToken")}),a.jsx("p",{className:"text-xs text-bambu-gray mb-2",children:e("profiles.login.accessTokenHint")}),a.jsx("textarea",{value:h,onChange:P=>m(P.target.value),className:"w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-xs font-mono placeholder-bambu-gray-dark focus:border-bambu-green focus:outline-none resize-none",placeholder:"eyJ...",rows:4,required:!0})]}),a.jsxs("div",{className:"flex gap-2",children:[r==="code"&&a.jsx(ke,{type:"button",variant:"secondary",onClick:()=>i("email"),className:"flex-1",children:e("profiles.login.back")}),a.jsxs(ke,{type:"submit",disabled:E,className:"flex-1",children:[E?a.jsx(ut,{className:"w-4 h-4 animate-spin"}):a.jsx(fB,{className:"w-4 h-4"}),e(r==="email"?"profiles.login.loginButton":r==="code"?"profiles.login.verifyButton":"profiles.login.setTokenButton")]})]}),r==="email"&&a.jsx("div",{className:"pt-4 border-t border-bambu-dark-tertiary",children:a.jsxs("button",{type:"button",onClick:()=>i("token"),className:"text-sm text-bambu-gray hover:text-white flex items-center gap-2 transition-colors",children:[a.jsx(Wo,{className:"w-4 h-4"}),e("profiles.login.useToken")]})}),r==="token"&&a.jsx("div",{className:"pt-4 border-t border-bambu-dark-tertiary",children:a.jsxs("button",{type:"button",onClick:()=>i("email"),className:"text-sm text-bambu-gray hover:text-white flex items-center gap-2 transition-colors",children:[a.jsx(fB,{className:"w-4 h-4"}),e("profiles.login.useEmail")]})})]})]})})}function xg({label:t,value:e,options:n,onChange:r}){const[i,s]=_.useState(!1),o=n.find(l=>l.value===e);return a.jsxs("div",{className:"relative",children:[a.jsxs("button",{onClick:()=>s(!i),className:"flex items-center gap-2 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-sm text-white hover:border-bambu-gray-dark transition-colors",children:[a.jsxs("span",{className:"text-bambu-gray",children:[t,":"]}),a.jsx("span",{children:o?.label||"All"}),a.jsx(Sr,{className:`w-4 h-4 text-bambu-gray transition-transform ${i?"rotate-180":""}`})]}),i&&a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"fixed inset-0 z-10",onClick:()=>s(!1)}),a.jsx("div",{className:"absolute top-full left-0 mt-1 min-w-[160px] bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl z-20 py-1 max-h-60 overflow-y-auto",children:n.map(l=>a.jsxs("button",{onClick:()=>{r(l.value),s(!1)},className:`w-full px-3 py-2 text-left text-sm flex items-center justify-between hover:bg-bambu-dark-tertiary transition-colors ${e===l.value?"text-bambu-green":"text-white"}`,children:[a.jsx("span",{children:l.label}),l.count!==void 0&&a.jsx("span",{className:"text-bambu-gray text-xs",children:l.count})]},l.value))})]})]})}function xQe(){const[t,e]=_.useState(!1);_.useEffect(()=>{const r=()=>{e(window.scrollY>300)};return window.addEventListener("scroll",r),()=>window.removeEventListener("scroll",r)},[]);const n=()=>{window.scrollTo({top:0,behavior:"smooth"})};return t?a.jsx("button",{onClick:n,className:"fixed bottom-6 right-6 p-3 bg-bambu-green hover:bg-bambu-green-light text-white rounded-full shadow-lg shadow-bambu-green/25 transition-all z-40","aria-label":"Scroll to top",children:a.jsx(Zg,{className:"w-5 h-5"})}):null}function yP({setting:t,onClick:e,onDuplicate:n,compareMode:r,isCompareSelected:i,compareIndex:s,compareDisabled:o,t:l}){const c=HF(t.name),u=Yy(t.setting_id);return a.jsxs("div",{className:"flex items-center gap-2 group",children:[a.jsx("button",{onClick:e,disabled:o,className:`flex-1 text-left px-3 py-2 rounded transition-colors ${i?"bg-blue-500/20 border border-blue-500/50":o?"bg-bambu-dark/50 opacity-40 cursor-not-allowed":"bg-bambu-dark hover:bg-bambu-dark-tertiary"} ${r&&!o?"cursor-pointer":""}`,children:a.jsxs("div",{className:"flex items-center gap-2",children:[i&&s!==void 0&&a.jsx("span",{className:"flex-shrink-0 w-5 h-5 rounded-full bg-blue-500 text-white text-xs flex items-center justify-center font-medium",children:s+1}),!i&&u&&a.jsx("span",{className:"flex-shrink-0 w-1.5 h-1.5 rounded-full bg-bambu-green",title:l("profiles.presets.myPreset")}),a.jsx("span",{className:"text-white text-sm truncate flex-1",title:t.name,children:t.name}),c.filamentType&&t.type==="filament"&&a.jsx("span",{className:"text-xs text-bambu-gray whitespace-nowrap",children:c.filamentType}),c.layerHeight&&t.type==="process"&&a.jsx("span",{className:"text-xs text-bambu-gray whitespace-nowrap",children:c.layerHeight}),c.printer&&a.jsx("span",{className:"text-xs text-bambu-gray whitespace-nowrap",children:c.printer})]})}),a.jsx("button",{onClick:d=>{d.stopPropagation(),n()},className:"opacity-0 group-hover:opacity-100 text-bambu-gray hover:text-white transition-all p-1",title:l("profiles.presets.duplicate"),children:a.jsx(Fl,{className:"w-4 h-4"})})]})}function zR(t,e=0){const n=" ".repeat(e);if(t===null)return"null";if(t===void 0)return"undefined";if(typeof t=="string"){if(t.includes("\\n")||t.includes(`
`)){const i=t.replace(/\\n/g,`
`).replace(/\\"/g,'"').replace(/\\t/g," ").split(`
`);if(i.length>1)return`"""
diff --git a/static/index.html b/static/index.html
index 333700a1c..273659070 100644
--- a/static/index.html
+++ b/static/index.html
@@ -23,7 +23,7 @@
-
+