PageSourceSearch

https://sphub.ai/assets/user-defaults-manager-C4jrS5MO.js

js sphub.ai collected 2026-10-02 01:14:25 UTC 68,208 bytes, 1 lines download raw bytes

1import{r as j,j as e}from"./index-B6Z7dfHe.js";import{t as Me,k as y,v as W,q as R,m as M,H as de,J as ce,b8 as ge,b9 as je,aQ as be,ba as ve,B as S,ay as w,bp as Re,T as Ls,bg as ds,as as Os,ca as Bs,dw as qs,co as De,cn as cs,cm as Ks,ck as Hs,aq as os,cj as us,aF as Qs,ap as zs,aP as Ws,p as _s,b3 as ms,bl as Gs,bw as $e,cb as hs,bv as Ys,aM as xs,d$ as Js,aJ as Xs,aH as Zs,aI as ea,aK as sa,an as ee,bt as x,c8 as aa,h as Ue,e_ as ta,e$ as ia,f0 as na,a5 as _,bQ as Ae,K as ra,bR as Ie,au as fe,f1 as la,f2 as da,aE as ca,aN as oa,az as q,aA as K,aB as H,aC as Q,aD as P,eb as is,aL as ns,at as ua,dF as ma,a1 as rs,dE as ha,a_ as xa,bJ as pa,bK as fa,bL as ga,U as ja,N as ba}from"./respond-action-BpL3big_.js";import{P as ps}from"./plus-DyqNZPQ6.js";import{E as va}from"./eye-BFy3mSFx.js";import{S as ya}from"./square-pen-CnuR6lD9.js";import{F as Na}from"./field-help-CPfFMIQy.js";import{h as wa}from"./helpTexts-cxZMX586.js";import{A as Sa}from"./arrow-up-Cy_BXDJ_.js";import{A as Ca}from"./arrow-down-QfkFG4Il.js";import{S as fs}from"./save-Ns5eNKf0.js";import{H as ka}from"./headphones-CTSPEcvS.js";import{C as Pa}from"./chevrons-up-down-DI9mpwOu.js";function Aa({userId:c}){const{toast:o}=Me(),[h,i]=j.useState({}),[N,n]=j.useState(!1),[A,p]=j.useState(!1),{data:v=[],isLoading:m}=y({queryKey:["/api/topics"]}),{data:f=[],isLoading:T}=y({queryKey:["/api/user/topic-permissions"]}),{data:C}=y({queryKey:["/api/auth/user"]}),E=C?.permissionProfileId,D=E!=null&&String(E).trim()!=="",d=D;j.useEffect(()=>{if(!v.length||T)return;const a={};v.forEach(l=>{const t=f.find(b=>b.topicId===l.id);t?a[l.id]=t:a[l.id]={id:"",userId:c,topicId:l.id,canView:!0,canEdit:!1,canDelete:!1,canViewChat:!0,canViewBingo:!0,canViewQuiz:!0,canViewAlert:!0,canViewNews:!0,canViewPodcasts:!0,canViewVideos:!0,canViewDocuments:!0,canViewCalculator:!0,canViewResearch:!0,canViewSourcing:!0,canViewBlogs:!0,canViewSocial:!0,canViewEVAssets:!0,canViewMaps:!0,canViewIntranet:!0,canViewWaterMeters:!1,canViewChargers:!1,canViewActions:!1,receiveSuggestions:!1,createdAt:new Date,updatedAt:new Date}}),i(a)},[v,f,c,T]),j.useEffect(()=>{C&&C.canCreateTopics!==void 0&&n(C.canCreateTopics)},[C?.canCreateTopics]);const U=W({mutationFn:async({topicId:a,permissions:l})=>await M("PUT",`/api/user/topic-permissions/${a}`,l),onSuccess:()=>{R.invalidateQueries({queryKey:["/api/user/topic-permissions"]}),p(!1)},onError:()=>{o({title:"Error",description:"Failed to update permissions. Please try again.",variant:"destructive"})}}),g=(a,l,t)=>{i(b=>{const O={...b};return l==="canView"&&!t?O[a]={...b[a],canView:!1,canEdit:!1,canDelete:!1,canViewChat:!1,canViewBingo:!1,canViewQuiz:!1,canViewAlert:!1,canViewNews:!1,canViewPodcasts:!1,canViewVideos:!1,canViewDocuments:!1,canViewCalculator:!1,canViewResearch:!1,canViewSourcing:!1,canViewBlogs:!1,canViewSocial:!1,canViewEVAssets:!1,canViewMaps:!1,canViewIntranet:!1,canViewWaterMeters:!1,canViewChargers:!1,canViewActions:!1}:O[a]={...b[a],[l]:t},O}),p(!0)},u=W({mutationFn:async a=>await M("PUT","/api/user/update-create-permission",{canCreateTopics:a}),onSuccess:()=>{R.invalidateQueries({queryKey:["/api/auth/user"]})},onError:()=>{o({title:"Error",description:"Failed to update create permission. Please try again.",variant:"destructive"})}}),V=async()=>{const a=Object.entries(h).map(([l,t])=>U.mutateAsync({topicId:l,permissions:{canView:t.canView,canEdit:t.canEdit,canDelete:t.canDelete,canViewChat:t.canViewChat,canViewBingo:t.canViewBingo,canViewQuiz:t.canViewQuiz,canViewAlert:t.canViewAlert,canViewNews:t.canViewNews,canViewPodcasts:t.canViewPodcasts,canViewVideos:t.canViewVideos,canViewDocuments:t.canViewDocuments,canViewCalculator:t.canViewCalculator,canViewResearch:t.canViewResearch,canViewSourcing:t.canViewSourcing,canViewBlogs:t.canViewBlogs,canViewSocial:t.canViewSocial,canViewEVAssets:t.canViewEVAssets,canViewMaps:t.canViewMaps,canViewIntranet:t.canViewIntranet,canViewWaterMeters:t.canViewWaterMeters,canViewChargers:t.canViewChargers,canViewActions:t.canViewActions,receiveSuggestions:t.receiveSuggestions}}));C&&C.canCreateTopics!==N&&a.push(u.mutateAsync(N));try{await Promise.all(a),o({title:"Permissions Updated",description:"Your permissions have been successfully updated."}),p(!1)}catch(l){console.error("Error saving permissions:",l)}};return m||T?e.jsx(de,{children:e.jsx(ce,{className:"p-6",children:e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-primary"})})})}):e.jsxs(de,{children:[e.jsx(ge,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsxs(je,{className:"flex items-center gap-2",children:[e.jsx(be,{className:"h-5 w-5"}),"Dashboard Permissions"]}),e.jsx(ve,{children:D?e.jsx("span",{className:"text-yellow-600 dark:text-yellow-400",children:"Your permissions are managed by your assigned permission profile and cannot be edited here. Contact an administrator to change your permissions."}):"Manage your access permissions for each dashboard"})]}),A&&!d&&e.jsx(S,{onClick:V,disabled:U.isPending,children:U.isPending?"Saving...":"Save Changes"})]})}),e.jsxs(ce,{children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"rounded-lg border p-4 mb-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs(w,{htmlFor:"create-toggle",className:"text-base font-medium flex items-center gap-2",children:[e.jsx(ps,{className:"h-4 w-4"}),"Create New Dashboards"]}),e.jsx("div",{className:"bg-blue-100 rounded-md p-1.5",children:e.jsx(Re,{id:"create-toggle",checked:N,disabled:d,onCheckedChange:a=>{d||(n(a),p(!0))}})})]}),e.jsx("p",{className:"text-lg text-muted-foreground",children:"Allow this user to create new dashboards in the system"})]}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("div",{className:"min-w-[1840px]",children:[e.jsx(Ls,{delayDuration:200,children:e.jsxs("div",{className:"grid gap-0 pb-2 border-b",style:{gridTemplateColumns:"300px repeat(24, 70px)"},children:[e.jsx("div",{className:"font-medium text-base",children:"Dashboard"}),[[va,"View"],[ya,"Edit"],[ds,"Delete"],[Os,"Chat"],[Bs,"Bingo"],[qs,"Quiz"],[De,"Alerts"],[cs,"
1News"],[Ks,"Podcasts"],[Hs,"Videos"],[os,"Documents"],[us,"Calculator"],[Qs,"Research"],[zs,"Sourcing"],[Ws,"Blog"],[_s,"Social"],[ms,"EV Assets"],[Gs,"Maps"],[$e,"Intranet"],[hs,"Water Meters"],[Ys,"Chargers"],[xs,"AI Data Analyst"],[Js,"Actions"],[Xs,"Suggestions"]].map(([a,l])=>e.jsxs(Zs,{children:[e.jsx(ea,{asChild:!0,children:e.jsx("div",{className:"flex items-center justify-center gap-1 text-sm cursor-help",children:e.jsx(a,{className:"h-3 w-3"})})}),e.jsx(sa,{children:e.jsx("p",{children:l})})]},l))]})}),v.map(a=>{const l=h[a.id];return l?e.jsxs("div",{className:"grid gap-0 items-center py-1 hover:bg-gray-50 rounded-lg",style:{gridTemplateColumns:"300px repeat(24, 70px)"},children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsxs(ee,{variant:"outline",className:`${a.colorClass||""} text-xs shrink-0`,children:[e.jsx("i",{className:`${a.iconClass||""} mr-1`}),a.category]}),e.jsx("span",{className:"text-base font-medium truncate",title:a.title,children:a.title})]}),e.jsx("div",{className:"flex justify-center",children:e.jsx(x,{id:`${a.id}-view`,checked:l.canView||!1,disabled:d,onCheckedChange:t=>!d&&g(a.id,"canView",t===!0)})}),e.jsx("div",{className:"flex justify-center",children:e.jsx(x,{id:`${a.id}-edit`,checked:l.canEdit||!1,disabled:d,onCheckedChange:t=>!d&&g(a.id,"canEdit",t===!0)})}),e.jsx("div",{className:"flex justify-center",children:e.jsx(x,{id:`${a.id}-delete`,checked:l.canDelete||!1,disabled:d,onCheckedChange:t=>!d&&g(a.id,"canDelete",t===!0)})}),e.jsx("div",{className:"flex justify-center",children:e.jsx(x,{id:`${a.id}-chat`,checked:l.canViewChat!==!1,disabled:d,onCheckedChange:t=>!d&&g(a.id,"canViewChat",t===!0)})}),e.jsx("div",{className:"flex justify-center",children:e.jsx(x,{id:`${a.id}-bingo`,checked:l.canViewBingo!==!1,disabled:d,onCheckedChange:t=>!d&&g(a.id,"canViewBingo",t===!0)})}),e.jsx("div",{className:"flex justify-center",children:e.jsx(x,{id:`${a.id}-quiz`,checked:l.canViewQuiz!==!1,disabled:d,onCheckedChange:t=>!d&&g(a.id,"canViewQuiz",t===!0)})}),e.jsx("div",{className:"flex justify-center",children:e.jsx(x,{id:`${a.id}-alerts`,checked:l.canViewAlert!==!1,disabled:d,onCheckedChange:t=>!d&&g(a.id,"canViewAlert",t===!0)})}),e.jsx("div",{className:"flex justify-center",children:e.jsx(x,{id:`${a.id}-news`,checked:l.canViewNews!==!1,disabled:d,onCheckedChange:t=>!d&&g(a.id,"canViewNews",t===!0)})}),e.jsx("div",{className:"flex justify-center",children:e.jsx(x,{id:`${a.id}-podcasts`,checked:l.canViewPodcasts!==!1,disabled:d,onCheckedChange:t=>!d&&g(a.id,"canViewPodcasts",t===!0)})}),e.jsx("div",{className:"flex justify-center",children:e.jsx(x,{id:`${a.id}-videos`,checked:l.canViewVideos!==!1,disabled:d,onCheckedChange:t=>!d&&g(a.id,"canViewVideos",t===!0)})}),e.jsx("div",{className:"flex justify-center",children:e.jsx(x,{id:`${a.id}-documents`,checked:l.canViewDocuments!==!1,disabled:d,onCheckedChange:t=>!d&&g(a.id,"canViewDocuments",t===!0)})}),e.jsx("div",{className:"flex justify-center",children:e.jsx(x,{id:`${a.id}-calculator`,checked:l.canViewCalculator!==!1,disabled:d,onCheckedChange:t=>!d&&g(a.id,"canViewCalculator",t===!0)})}),e.jsx("div",{className:"flex justify-center",children:e.jsx(x,{id:`${a.id}-research`,checked:l.canViewResearch!==!1,disabled:d,onCheckedChange:t=>!d&&g(a.id,"canViewResearch",t===!0)})}),e.jsx("div",{className:"flex justify-center",children:e.jsx(x,{id:`${a.id}-sourcing`,checked:l.canViewSourcing!==!1,disabled:d,onCheckedChange:t=>!d&&g(a.id,"canViewSourcing",t===!0)})}),e.jsx("div",{className:"flex justify-center",children:e.jsx(x,{id:`${a.id}-blog`,checked:l.canViewBlogs!==!1,disabled:d,onCheckedChange:t=>!d&&g(a.id,"canViewBlogs",t===!0)})}),e.jsx("div",{className:"flex justify-center",children:e.jsx(x,{id:`${a.id}-social`,checked:l.canViewSocial!==!1,disabled:d,onCheckedChange:t=>!d&&g(a.id,"canViewSocial",t===!0)})}),e.jsx("div",{className:"flex justify-center",children:e.jsx(x,{id:`${a.id}-evassets`,checked:l.canViewEVAssets!==!1,disabled:d,onCheckedChange:t=>!d&&g(a.id,"canViewEVAssets",t===!0)})}),e.jsx("div",{className:"flex justify-center",children:e.jsx(x,{id:`${a.id}-maps`,checked:l.canViewMaps!==!1,disabled:d,onCheckedChange:t=>!d&&g(a.id,"canViewMaps",t===!0)})}),e.jsx("div",{className:"flex justify-center",children:e.jsx(x,{id:`${a.id}-intranet`,checked:l.canViewIntranet!==!1,disabled:d,onCheckedChange:t=>!d&&g(a.id,"canViewIntranet",t===!0)})}),e.jsx("div",{className:"flex justify-center",children:e.jsx(x,{id:`${a.id}-watermeters`,checked:l.canViewWaterMeters!==!1,disabled:d,onCheckedChange:t=>!d&&g(a.id,"canViewWaterMeters",t===!0)})}),e.jsx("div",{className:"flex justify-center",children:e.jsx(x,{id:`${a.id}-chargers`,checked:l.canViewChargers!==!1,disabled:d,onCheckedChange:t=>!d&&g(a.id,"canViewChargers",t===!0)})}),e.jsx("div",{className:"flex justify-center",children:e.jsx(x,{id:`${a.id}
1-qbsschat`,checked:l.canViewQbSsChat===!0,disabled:d,onCheckedChange:t=>!d&&g(a.id,"canViewQbSsChat",t===!0)})}),e.jsx("div",{className:"flex justify-center",children:e.jsx(x,{id:`${a.id}-actions`,checked:l.canViewActions===!0,disabled:d,onCheckedChange:t=>!d&&g(a.id,"canViewActions",t===!0)})}),e.jsx("div",{className:"flex justify-center",children:e.jsx(x,{id:`${a.id}-suggestions`,checked:l.receiveSuggestions===!0,disabled:d,onCheckedChange:t=>!d&&g(a.id,"receiveSuggestions",t===!0)})})]},a.id):null})]})})]}),v.length===0&&e.jsx("div",{className:"text-center py-8 text-gray-500",children:"No dashboards available to manage permissions."})]})]})}const Ia={footer:"Footer buttons",admin:"General administration","admin-asset-tools":"Asset Tools","admin-billing":"Billing","admin-water-meters":"Water Meters","admin-sp-intranet":"SP Intranet","header-standard":"Standard icons","header-specialized":"Specialized icons","header-local":"Local dashboards","header-dynamic":"Specialty apps and custom groups"};function Ve({title:c,options:o,value:h,onChange:i}){const N=j.useId(),n=new Set(o.map(m=>m.id)),A=h.filter(m=>!n.has(m)),p=[...new Set(o.map(m=>m.group||"Permissions"))],v=(m,f)=>i(f?[...new Set([...h,m])]:h.filter(T=>T!==m));return e.jsxs("fieldset",{className:"min-w-0 space-y-3 rounded-md border p-3",children:[e.jsx("legend",{className:"px-1 text-sm font-semibold",children:c}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(S,{type:"button",size:"sm",variant:"outline",onClick:()=>i([...new Set([...h,...o.map(m=>m.id)])]),children:"Show All"}),e.jsx(S,{type:"button",size:"sm",variant:"outline",onClick:()=>i(A),children:"Show None"}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[h.filter(m=>n.has(m)).length," selected"]})]}),e.jsxs("div",{className:"max-h-96 space-y-4 overflow-y-auto rounded-md border bg-muted/10 p-2 pr-3",tabIndex:0,role:"region","aria-label":`${c} choices`,"data-testid":"permission-options-scroll-region",children:[p.map(m=>e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"text-sm font-medium text-muted-foreground",children:Ia[m]||m}),e.jsx("div",{className:"grid gap-2 lg:grid-cols-2",children:o.filter(f=>(f.group||"Permissions")===m).map(f=>{const T=f.icon,C=`${N}-${f.id}`;return e.jsxs("label",{htmlFor:C,className:"flex min-w-0 cursor-pointer items-start gap-3 rounded-md border p-3 hover:bg-muted/50",children:[e.jsx(x,{id:C,className:"mt-0.5 shrink-0",checked:h.includes(f.id),"aria-label":f.label,onCheckedChange:E=>v(f.id,E===!0),"aria-describedby":f.description?`${C}-description`:void 0}),T&&e.jsx(T,{className:"mt-0.5 h-4 w-4 shrink-0","aria-hidden":"true"}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block break-words text-sm font-medium",children:f.label}),f.description&&e.jsx("span",{id:`${C}-description`,className:"block text-xs text-muted-foreground",children:f.description})]})]},f.id)})})]},m)),A.length>0&&e.jsxs("div",{className:"space-y-2 rounded-md border border-amber-500/50 p-3",children:[e.jsx("h4",{className:"text-sm font-medium",children:"Retained unavailable selections"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"These saved permissions are unavailable in the current catalog. Show All and Show None keep them. Uncheck one only to remove it explicitly."}),A.map(m=>e.jsxs("label",{className:"flex items-start gap-3 text-sm",children:[e.jsx(x,{checked:!0,onCheckedChange:()=>v(m,!1),"aria-label":`Remove retained permission ${m}`}),e.jsx("span",{className:"min-w-0 break-all",children:m})]},m))]})]})]})}function Va({options:c,value:o,onChange:h}){const[i,N]=j.useState(""),[n,A]=j.useState(null),[p,v]=j.useState(null),m=j.useRef(null),f=j.useMemo(()=>new Map(c.map(a=>[a.id,a.label])),[c]),T=c.filter(a=>!o.includes(a.id)),C=(a,l)=>{const t=[...o],b=a+l;[t[a],t[b]]=[t[b],t[a]],h(t)},E=()=>{!i||o.includes(i)||(h([...o,i]),N(""))},D=(a,l)=>{if(a===l)return;const t=o.indexOf(a),b=o.indexOf(l);if(t<0||b<0)return;const O=[...o],[G]=O.splice(t,1);O.splice(b,0,G),h(O)},d=(a,l)=>{A(l),a.dataTransfer.effectAllowed="move",a.dataTransfer.setData("text/plain",l)},U=(a,l)=>{a.preventDefault();const t=n||a.dataTransfer.getData("text/plain");A(null),v(null),t&&D(t,l)},g=(a,l)=>
1{a.pointerType!=="mouse"&&(a.preventDefault(),m.current=l,A(l),a.currentTarget.setPointerCapture?.(a.pointerId))},u=a=>{const l=m.current;if(!l)return;a.preventDefault();const b=document.elementFromPoint(a.clientX,a.clientY)?.closest("[data-header-navigation-id]")?.dataset.headerNavigationId;b&&(v(b),D(l,b))},V=a=>{m.current&&(m.current=null,A(null),v(null),a.currentTarget.releasePointerCapture?.(a.pointerId))};return e.jsxs("section",{className:"space-y-3 border-t pt-4","aria-labelledby":"header-navigation-order-title",children:[e.jsxs("div",{children:[e.jsx("h3",{id:"header-navigation-order-title",className:"text-sm font-semibold",children:"Header navigation order"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Entries appear from top to bottom in their intended header display order."})]}),e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-end",children:[e.jsxs("div",{className:"min-w-0 flex-1 space-y-1",children:[e.jsx(w,{htmlFor:"header-navigation-add",children:"Add navigation entry"}),e.jsxs("select",{id:"header-navigation-add","aria-label":"Add navigation entry",className:"h-10 w-full rounded-md border border-input bg-background px-3 text-sm",value:i,onChange:a=>N(a.target.value),disabled:T.length===0,children:[e.jsx("option",{value:"",children:T.length?"Choose an entry":"All entries selected"}),T.map(a=>e.jsx("option",{value:a.id,children:a.label},a.id))]})]}),e.jsxs(S,{type:"button",variant:"outline",onClick:E,disabled:!i,children:[e.jsx(ps,{className:"mr-2 h-4 w-4"})," Add"]})]}),e.jsx("ol",{className:"space-y-2","aria-label":"Selected header navigation order",children:o.map((a,l)=>{const t=f.get(a);return e.jsxs("li",{"data-header-navigation-id":a,draggable:!0,onDragStart:b=>d(b,a),onDragEnd:()=>{A(null),v(null)},onDragOver:b=>{b.preventDefault(),b.dataTransfer.dropEffect="move",v(a)},onDragLeave:()=>v(b=>b===a?null:b),onDrop:b=>U(b,a),className:`flex items-center gap-2 rounded-md border bg-background p-2 ${p===a&&n!==a?"border-primary":""} ${n===a?"opacity-60":""}`,children:[e.jsx("button",{type:"button",className:"flex h-10 w-8 shrink-0 touch-none items-center justify-center rounded-sm text-muted-foreground cursor-grab active:cursor-grabbing","aria-label":`Drag ${t||a} to reorder`,onPointerDown:b=>g(b,a),onPointerMove:u,onPointerUp:V,onPointerCancel:V,children:e.jsx(aa,{className:"h-4 w-4","aria-hidden":"true"})}),e.jsx("span",{className:"w-6 shrink-0 text-center text-xs text-muted-foreground",children:l+1}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-sm font-medium",children:t||a}),!t&&e.jsx("span",{className:"block text-xs text-amber-700",children:"Unavailable entry retained from the saved policy"})]}),e.jsx(S,{type:"button",size:"icon",variant:"ghost","aria-label":`Move ${t||a} up`,disabled:l===0,onClick:()=>C(l,-1),children:e.jsx(Sa,{className:"h-4 w-4"})}),e.jsx(S,{type:"button",size:"icon",variant:"ghost","aria-label":`Move ${t||a} down`,disabled:l===o.length-1,onClick:()=>C(l,1),children:e.jsx(Ca,{className:"h-4 w-4"})}),e.jsx(S,{type:"button",size:"icon",variant:"ghost",className:"text-destructive","aria-label":`Remove ${t||a} from header navigation`,onClick:()=>h(o.filter(b=>b!==a)),children:e.jsx(ds,{className:"h-4 w-4"})})]},a)})}),o.length===0&&e.jsx("p",{className:"rounded-md border border-dashed p-3 text-sm text-muted-foreground",children:"No preferred order is set. Add entries above to define one."})]})}const Te=["/api/admin/user-access-policy-template"],Ta=new Set(["[email protected]","[email protected]"]),gs=()=>({defaultNativePage:null,canAccessSmartsheet:!1,canAccessRMS:!1,isAdmin:!1,preserveVisibleFooterButtons:!0,visibleFooterButtons:[],visibleAdminIcons:[],enabledHeaderIconKeys:[]});function L(c){const o=new Set,h=[];return String(c||"").split(/[,\n]/).map(i=>i.trim()).filter(Boolean).forEach(i=>{const N=i.toLowerCase();o.has(N)||(o.add(N),h.push(i))}),h}function ls(c){const o=c||{},h=i=>({...gs(),...i||{},defaultNativePage:i?.defaultNativePage?.trim()||null,visibleFooterButtons:Array.isArray(i?.visibleFooterButtons)?L(i.visibleFooterButtons.join(",")):[],visibleAdminIcons:Array.isArray(i?.visibleAdminIcons)?L(i.visibleAdminIcons.join(",")):[],enabledHeaderIconKeys:Array.isArray(i?.enabledHeaderIconKeys)?L(i.enabledHeaderIconKeys.join(",")):[]});return{schemaVersion:1,templateId:1,revision:Number(o.revision||0),updatedAt:o.updatedAt||null,headerNavOrder:Array.isArray(o.headerNavOrder)?L(o.headerNavOrder.join(",")):[],ordinary:h(o.ordinary),limitedAdmin:h(o.limitedAdmin)}}function Ea({onSaved:c}){const{user:o,isLoading:h}=Ue(),{toast:i}=Me(),N=Ta.has(String(o?.email||"").trim().toLowerCase()),[n,A]=j.useState("ordinary"),[p,v]=j.useState(null),m=y({queryKey:Te,enabled:N,staleTime:0,refetchOnMount:"always"}),f=y({queryKey:["/api/admin/user-access-policy-template/header-options"],enabled:N&&!!o?.id,staleTime:0,refetchOnMount:"always"}),T=[...ta,...ia(f.data?.netlifyIcons)],C=[...na,...(f.data?.netlifyIcons||[]).map(u=>({id:u.key.startsWith("netlifyApp:")?`netlify-app-${u.key.slice(11)}`:u.key.startsWith("netlifyGroup:")?`netlify-group-${u.key.slice(13)}`:u.key,label:u.label}))];j.useEffect(()=>{m.data?.template&&v(ls(m.data.template))},[m.data]);const E=W({mutationFn:async u=>M("PUT","/api/admin/user-access-policy-template",{expectedRevision:u.revision,template:{headerNavOrder:L(u.headerNavOrder.join(",")),ordinary:{...u.ordinary,defaultNativePage:u.ordinary.defaultNativePage?.trim()||null,visibleFooterButtons:L(u.ordinary.visibleFooterButtons.join(",")),visibleAdminIcons:L(u.ordinary.visibleAdminIcons.join(",")),enabledHeaderIconKeys:L(u.ordinary.enabledHeaderIconKeys.join(","))},limitedAdmin:{...u.limitedAdmin,defaultNativePage:u.limitedAdmin.defaultNativePage?.trim()||null,visibleFooterButtons:L(u.limitedAdmin.visibleFooterButtons.join(",")),visibleAdminIcons:L(u.limitedAdmin.visibleAdminIcons.join(",")),enabledHeaderIconKeys:L(u.limitedAdmin.enabledHeaderIconKeys.join(","))}}}),onSuccess:async u=>{u?.template&&v(ls(u.template)),await R.invalidateQueries({queryKey:Te}),i({title:"Policy template saved",description:"Organization access policy updated."}),c?.()},onError:async u=>{const V=u?.status===409||/revision|changed|stale|conflict/i.test(String(u?.message||""));V&&await R.invalidateQueries({queryKey:Te}),i({title:V?"Policy template changed":"Save failed",description:V?"Another administrator saved this template. The latest revision has been loaded; review it before saving again.":u?.message||"Could not save the organization access policy.",variant:"destructive"})}}),D=p?.[n]||gs(),d=n==="ordinary"?"Ordinary users":"Limited admins",U=j.useMemo(()=>
1{if(!p?.updatedAt)return"Not recorded";const u=new Date(p.updatedAt);return Number.isNaN(u.getTime())?p.updatedAt:u.toLocaleString()},[p?.updatedAt]),g=(u,V)=>{v(a=>a&&{...a,[n]:{...a[n],[u]:V}})};return h||!o&&!h||!N?null:e.jsxs(de,{"data-testid":"organization-access-policy-template",children:[e.jsxs(ge,{children:[e.jsxs(je,{className:"flex items-center gap-2",children:[e.jsx(be,{className:"h-5 w-5 text-blue-600"}),"Policy Template 1 / Organization Access Policy",e.jsx(ee,{variant:"outline",children:"Owner only"})]}),e.jsx(ve,{children:"Configure the organization-wide access policy used by the baseline preview. Owners and each user's personal desktop/mobile start pages are never changed by this template."})]}),e.jsxs(ce,{className:"space-y-5",children:[m.isLoading&&e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",role:"status",children:[e.jsx(_,{className:"h-4 w-4 animate-spin"})," Loading policy template…"]}),m.isError&&e.jsxs(Ae,{variant:"destructive",children:[e.jsx(ra,{className:"h-4 w-4"}),e.jsxs(Ie,{children:[String(m.error?.message||"Could not load the organization access policy."),e.jsx(S,{className:"ml-3",size:"sm",variant:"outline",onClick:()=>m.refetch(),children:"Retry"})]})]}),E.isError&&!m.isError&&e.jsx(Ae,{variant:"destructive",children:e.jsx(Ie,{children:String(E.error?.message||"The policy could not be saved.")})}),p&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-wrap gap-x-5 gap-y-1 text-sm text-muted-foreground",children:[e.jsxs("span",{children:["Revision ",e.jsx("strong",{className:"text-foreground",children:p.revision})]}),e.jsxs("span",{children:["Last updated ",e.jsx("strong",{className:"text-foreground",children:U})]}),e.jsxs("span",{children:["Schema version ",e.jsx("strong",{className:"text-foreground",children:p.schemaVersion})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(w,{htmlFor:"policy-group",children:"Edit policy group"}),e.jsxs("select",{id:"policy-group",className:"h-10 w-full max-w-sm rounded-md border border-input bg-background px-3 text-sm",value:n,onChange:u=>A(u.target.value),children:[e.jsx("option",{value:"ordinary",children:"Ordinary users"}),e.jsx("option",{value:"limitedAdmin",children:"Limited admins"})]})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(w,{htmlFor:`default-native-page-${n}`,children:["Default native page for ",d.toLowerCase()]}),e.jsx(fe,{id:`default-native-page-${n}`,value:D.defaultNativePage||"",onChange:u=>g("defaultNativePage",u.target.value||null),placeholder:"e.g. /energy-planner (blank for none)"})]}),[["canAccessSmartsheet","Can access Smartsheet"],["canAccessRMS","Can access RMS"],["isAdmin","Is administrator"],["preserveVisibleFooterButtons","Preserve visible footer buttons"]].map(([u,V])=>e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border p-3",children:[e.jsx(w,{htmlFor:`${u}-${n}`,className:"cursor-pointer",children:V}),e.jsx(Re,{id:`${u}-${n}`,checked:!!D[u],onCheckedChange:a=>g(u,a)})]},u))]}),e.jsxs("div",{className:"space-y-5",children:[e.jsx(Ve,{title:`Visible footer buttons for ${d.toLowerCase()}`,options:la,value:D.visibleFooterButtons,onChange:u=>g("visibleFooterButtons",u)}),e.jsx(Ve,{title:`Visible admin icons for ${d.toLowerCase()}`,options:da,value:D.visibleAdminIcons,onChange:u=>g("visibleAdminIcons",u)}),f.isLoading&&e.jsx("p",{role:"status",className:"text-sm text-muted-foreground",children:"Loading specialty app choices…"}),f.isError&&e.jsx(Ae,{variant:"destructive",children:e.jsxs(Ie,{children:["Specialty app choices could not be loaded. Saved selections are retained.",e.jsx(S,{type:"button",size:"sm",variant:"outline",className:"ml-2",onClick:()=>f.refetch(),children:"Retry specialty apps"})]})}),e.jsx(Ve,{title:`Enabled header icons for ${d.toLowerCase()}`,options:T,value:D.enabledHeaderIconKeys,onChange:u=>g("enabledHeaderIconKeys",u)})]}),e.jsx(Va,{options:C,value:p.headerNavOrder,onChange:u=>v(V=>V&&{...V,headerNavOrder:u})}),e.jsx("div",{className:"flex justify-end border-t pt-4",children:e.jsx(S,{onClick:()=>E.mutate(p),disabled:E.isPending,children:E.isPending?e.jsxs(e.Fragment,{children:[e.jsx(_,{className:"mr-2 h-4 w-4 animate-spin"})," Saving…"]}):e.jsxs(e.Fragment,{children:[e.jsx(fs,{className:"mr-2 h-4 w-4"})," Save Policy Template 1"]})})})]})]})]})}function se(c){return typeof c=="string"?c.trim():""}
1function pe(c){return[se(c.firstName),se(c.lastName)].filter(Boolean).join(" ")||se(c.name)||se(c.email).split("@")[0]||`User ${c.id||c.userId}`}function Ee(c){if(!Array.isArray(c))throw new Error("The user list returned invalid data. Please retry.");const o=new Set;for(const h of c){if(!h||typeof h!="object"||typeof h.id!="string"||!h.id.trim()||o.has(h.id)||["email","firstName","lastName"].some(i=>h[i]!=null&&typeof h[i]!="string"))throw new Error("The user list contains an invalid account. Please retry or contact an administrator.");o.add(h.id)}return c}class z extends Error{constructor(o,h,i){const N=o==="request"?i===401?"Your session expired. Sign in again, then retry.":i===403?"You no longer have access to these defaults.":i===404?"This account could not be found. Refresh the account list.":i?`The defaults request failed (HTTP ${i}). Please retry.`:"The defaults request could not finish or did not return JSON. Please retry.":o==="account"?"The response does not match the selected account. Please retry.":`The defaults response is incomplete or invalid (${h||o}). Please retry; if this continues, report this code to an administrator.`;super(N),this.code=o,this.field=h,this.status=i,this.name="DefaultsLoadError"}code;field;status}function Da(c){return c instanceof z?c.message:"The defaults could not be loaded. Please retry."}async function $a(c){try{return await c()}catch(o){const h=Number.isInteger(o?.status)&&o.status>=400&&o.status<=599?o.status:void 0;throw new z("request",void 0,h)}}function Ma(c,o){if(!c||typeof c!="object"||Array.isArray(c)||c.userId!==o)throw new z("account");const h=["defaultNewsSetIds","defaultPodcastSetIds","defaultDocumentSetIds","defaultAlertSetIds","defaultCalculatorSetIds","defaultSmartsheetSetIds","defaultRMSScriptIds","defaultQuickbooksScriptIds","defaultEVScriptIds","defaultWeatherScriptIds"];for(const i of h)if(!Array.isArray(c[i]))throw new z("collection",i);if(!c.defaultPermissions||typeof c.defaultPermissions!="object"||Array.isArray(c.defaultPermissions)||Object.values(c.defaultPermissions).some(i=>!i||typeof i!="object"||Array.isArray(i)||Object.values(i).some(N=>typeof N!="boolean")))throw new z("permissions");for(const i of["defaultPermissionProfileId","defaultHeaderTopicId","defaultChatScriptId","defaultLandingPage","defaultNativePage","kbCompletionEmailPolicy"])if(c[i]!=null&&typeof c[i]!="string")throw new z("setting",i);if(c.defaultMaxEnrichmentRecords!=null&&(typeof c.defaultMaxEnrichmentRecords!="number"||!Number.isFinite(c.defaultMaxEnrichmentRecords)))throw new z("number","defaultMaxEnrichmentRecords");for(const i of["canAccessRMS","canAccessQuickbooks"])if(c[i]!=null&&typeof c[i]!="boolean")throw new z("setting",i);for(const[i,N]of Object.entries(c))if(i.endsWith("Ids")&&N!=null&&(!Array.isArray(N)||N.some(n=>typeof n!="string")))throw new z("selection");return c}function Ra(){const{user:c,isLoading:o}=Ue();return o?e.jsx("div",{role:"status",children:"Loading account…"}):!c?.id||!c.isAdmin?e.jsx("div",{role:"alert",children:"Administrator access required."}):e.jsx(Ua,{viewerId:c.id},c.id)}function Ua({viewerId:c}){const{toast:o}=Me(),{user:h}=Ue(),[i,N]=j.useState(""),[n,A]=j.useState(null),[p,v]=j.useState(null),[m,f]=j.useState([]),[T,C]=j.useState(""),[E,D]=j.useState(""),[d,U]=j.useState(""),u=new Set(["[email protected]","[email protected]"]).has(String(h?.email||"").trim().toLowerCase()),{data:V,isLoading:a,isError:l}=y({queryKey:["/api/admin/user-access-baseline/history"],queryFn:()=>M("GET","/api/admin/user-access-baseline/history"),enabled:u}),t=V?.runs||[],{data:b,isLoading:O}=y({queryKey:["/api/admin/user-access-baseline/sets"],queryFn:()=>M("GET","/api/admin/user-access-baseline/sets"),enabled:u}),G=b?.sets||[],B=G.find(s=>s.id===d),ye=W({mutationFn:async()=>{const s=await M("POST","/api/admin/user-access-baseline/preview",{});return Ee(s?.details?.map(r=>({...r,id:r?.userId}))),s},onMutate:()=>v(null),onSuccess:s=>{v(s),f(s.details.map(r=>r.userId)),C(""),R.invalidateQueries({queryKey:["/api/admin/user-access-baseline/history"]})},onError:s=>o({title:"Preview failed",description:s?.message||"Could not preview the access baseline.",variant:"destructive"})}),Ne=W({mutationFn:async()=>M("POST","/api/admin/user-access-baseline/apply",{confirmationToken:p?.confirmationToken,selectedUserIds:m}),onSuccess:s=>{v(null),R.invalidateQueries({queryKey:["/api/admin/users"]}),R.invalidateQueries({queryKey:["/api/admin/user-access-baseline/history"]}),o({title:"Access baseline applied",description:`${s.changedUsers} users changed; ${s.unchangedUsers} were already current.`})},onError:s=>
1o({title:"Apply failed",description:s?.message||"The baseline was not applied.",variant:"destructive"})}),oe=W({mutationFn:async s=>{const r=G.find(I=>I.id===s);if(!r)throw new Error("Choose a saved set to load");const k=await M("POST","/api/admin/user-access-baseline/preview",{});return Ee(k?.details?.map(I=>({...I,id:I?.userId}))),{set:r,preview:k}},onSuccess:({set:s,preview:r})=>{v(r),U(s.id),D(s.name),f(s.availableUserIds),C(""),R.invalidateQueries({queryKey:["/api/admin/user-access-baseline/history"]})},onError:s=>o({title:"Saved set could not be loaded",description:s?.message||"Create a fresh preview and try again.",variant:"destructive"})}),we=W({mutationFn:async()=>B?M("PUT",`/api/admin/user-access-baseline/sets/${B.id}`,{name:E,userIds:m,expectedVersion:B.version}):M("POST","/api/admin/user-access-baseline/sets",{name:E,userIds:m}),onSuccess:async s=>{U(s.set.id),D(s.set.name),await R.invalidateQueries({queryKey:["/api/admin/user-access-baseline/sets"]}),o({title:B?"Saved set updated":"Baseline set saved",description:`${s.set.userIds.length} users saved in “${s.set.name}”.`})},onError:s=>o({title:"Saved set was not changed",description:s?.message||"Could not save this baseline set.",variant:"destructive"})}),{data:ue=[],isLoading:js,error:me,refetch:bs}=y({queryKey:["/api/admin/users",{viewerId:c}],queryFn:()=>M("GET","/api/admin/users"),select:Ee}),{data:vs=[]}=y({queryKey:["/api/news-sets"]}),{data:ys=[]}=y({queryKey:["/api/podcast-sets"]}),{data:Ns=[]}=y({queryKey:["/api/document-sets"]}),{data:ws=[]}=y({queryKey:["/api/alert-sets"]}),{data:Ss=[]}=y({queryKey:["/api/calculator-sets"]}),{data:Cs=[]}=y({queryKey:["/api/smartsheet-sets"]}),{data:ks=[]}=y({queryKey:["/api/rms-scripts"]}),{data:Ps=[]}=y({queryKey:["/api/quickbooks-scripts"]}),{data:As=[]}=y({queryKey:["/api/ai-query-scripts"]}),{data:Is=[]}=y({queryKey:["/api/vin/views"]}),{data:Vs=[]}=y({queryKey:["/api/integrations/weather/scripts"]}),{data:Fe=[]}=y({queryKey:["/api/water-meters/utilities"]}),{data:Fa=[]}=y({queryKey:["/api/cache-sets"]}),{data:Ts=[]}=y({queryKey:["/api/permission-profiles"]}),{data:Es=[]}=y({queryKey:["/api/topics"]}),{data:Le=[]}=y({queryKey:["/api/netlify-apps"]}),Ds=(Array.isArray(Le)?Le:[]).filter(s=>s.enabled),{data:$s=[]}=y({queryKey:["/api/admin/sp-intranet-catalogs"],select:s=>Array.isArray(s)?s:s?.catalogs||[]}),Oe=vs.filter(s=>s.allowProfileSelection===!0),Be=ys.filter(s=>s.allowProfileSelection===!0),qe=Ns.filter(s=>s.allowProfileSelection===!0),Ke=ws.filter(s=>s.allowProfileSelection===!0),He=Ss.filter(s=>s.allowProfileSelection===!0),Qe=Cs.filter(s=>s.allowProfileSelection===!0),ze=ks.filter(s=>s.allowProfileSelection===!0),We=Ps.filter(s=>s.allowProfileSelection===!0),Ms=As.filter(s=>s.allowProfileSelection===!0),_e=Is.filter(s=>s.allowProfileSelection===!0),Ge=Vs.filter(s=>s.allowProfileSelection===!0),{data:ae,error:Y,isSuccess:Se,isFetchedAfterMount:Ce,isFetching:he,refetch:Ye}=y({queryKey:["/api/admin/users",i,"defaults",{viewerId:c}],queryFn:()=>$a(()=>M("GET",`/api/admin/users/${encodeURIComponent(i)}/defaults`,void 0,{timeoutMs:3e4})),select:s=>Ma(s,i),enabled:!!i,staleTime:0,refetchOnMount:"always",refetchOnWindowFocus:!1,retry:!1}),J=!me&&Se&&Ce&&!he&&!Y&&n?.userId===i&&ue.some(s=>s.id===i),te=j.useRef(!1),ke=j.useRef(i);ke.current=i,te.current=J,j.useEffect(()=>()=>{te.current=!1},[]);const Je=ue.find(s=>s.id===i),Xe=(s,r)=>s?r?.label?`${r.label} (${s})`:s:"Not set",Ze=n?.personalDesktopStartPage||null,es=n?.personalMobileStartPage||null,ss=!!Ze||!!es,Rs=[n?.personalDesktopStartPageTarget,n?.personalMobileStartPageTarget].filter(Boolean).some(s=>s.status==="unavailable"||s.status==="disabled"||s.status==="deleted"),X=W({mutationFn:async s=>{if(!te.current||s.userId!==ke.current)throw new Error("Reload this user's defaults before saving.");if(s.canAccessRMS!==void 0||s.canAccessQuickbooks!==void 0){const r={};s.canAccessRMS!==void 0&&(r.canAccessRMS=s.canAccessRMS),s.canAccessQuickbooks!==void 0&&(r.canAccessQuickbooks=s.canAccessQuickbooks),await M("PATCH",`/api/admin/users/${i}/permissions`,r)}if(!te.current||s.userId!==ke.current)throw new Error("The selected account changed. Reload before saving.");return await M("PUT",`/api/admin/users/${i}/defaults`,s)},onSuccess:()=>{o({title:"Success",description:"User settings have been updated"}),Ye(),R.invalidateQueries({queryKey:["/api/admin/users",{viewerId:c}],exact:!0}),R.invalidateQueries({queryKey:["/api/auth/user"]}),R.invalidateQueries({queryKey:["/api/auth/user-header-topic"]})},onError:s=>{o({title:"Error",description:s.message||"Failed to save user settings",variant:"destructive"})}}),as=W({mutationFn:async s=>{if(!te.current)throw new Error("Reload this user's defaults before saving.");return await M("PUT",`/api/admin/users/${i}/kb-email-policy`,{policy:s})},onSuccess:(s,r)=>{A(k=>k&&{...k,kbCompletionEmailPolicy:r}),R.invalidateQueries({queryKey:["/api/admin/users",i,"defaults"]}),o({title:"Email preference saved"})},onError:s=>{o({title:"Save failed",description:s?.message||"Failed to update email preference",variant:"destructive"})}}),Z=(s,r,k)=>{if(!n)return;const I={...n},F=`default${s}SetIds`,le=I[F]||[];k?I[F]=[...le,r]:I[F]=le.filter(Pe=>Pe!==r),A(I)},xe=(s,r,k)=>{if(!n)return;const I={...n},F=`default${s}ScriptIds`,le=I[F]||[];k?I[F]=[...le,r]:I[F]=le.filter(Pe=>Pe!==r),A(I)},$=j.useRef(null),ie=j.useRef(!1);j.useEffect(()=>()=>{$.current&&clearTimeout($.current)},[]);const ts=j.useCallback(s=>{$.current&&clearTimeout($.current),$.current=setTimeout(()=>{$.current=null,console.log("🔄 Auto-saving user defaults..."),X.mutate(s)},600)},[X]);j.useEffect(()=>{if(!Se||!Ce||he||Y||!ae||ae.userId!==i)return;const s=n?.userId===ae.userId,r=$.current!=null||X.isPending||ie.current;s&&r||A(ae)},[ae,Se,Ce,he,Y,i]),j.useEffect(()=>{$.current&&(clearTimeout($.current),$.current=null),ie.current=!1},[i]);const ne=j.useCallback((s,r)=>{if(!J){console.log("❌ Cannot save - missing userDefaults or selectedUserId");return}const k={...n,[s]:r};if(A(k),s==="allowedWaterUtilityIds"){if(Array.isArray(r)&&r.length===0){ie.current=!0,$.current&&(clearTimeout($.current),$.current=null);return}ie.current=!1}ts(k)},[n,i,ts,J]),re=ne,Us=()=>{J&&($.current&&(clearTimeout($.current),$.current=null),ie.current=!1,X.mutate(n))},Fs=ue.find(s=>
1s.id===i);return e.jsxs("div",{className:"min-h-screen flex flex-col",children:[e.jsx(ca,{}),e.jsxs("div",{className:"flex-1 space-y-6 container mx-auto p-6",children:[e.jsxs(de,{children:[e.jsxs(ge,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(oa,{className:"h-5 w-5 text-blue-600"}),e.jsx(je,{children:"User Default Settings"}),e.jsx(Na,{content:wa.userDefaults?.description||"Configure default permissions and content sets for individual users",detailed:!0})]}),e.jsx(ve,{children:"Configure default permissions and content sets for individual users"})]}),e.jsxs(ce,{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(w,{children:"Select User"}),me&&e.jsxs("div",{role:"alert",children:["Could not load users. ",e.jsx(S,{onClick:()=>bs(),children:"Retry users"})]}),e.jsxs(q,{disabled:js||!!me,value:i,onValueChange:N,children:[e.jsx(K,{children:e.jsx(H,{placeholder:"Choose a user to configure defaults"})}),e.jsx(Q,{children:!me&&ue.map(s=>e.jsx(P,{value:s.id,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{children:pe(s)}),e.jsx("span",{className:"text-muted-foreground text-sm",children:se(s.email)?`(${s.email})`:"No email"}),s.isAuthorized?e.jsx(ee,{className:"ml-2 bg-green-100 text-green-800",children:"Active"}):e.jsx(ee,{className:"ml-2 bg-orange-100 text-orange-800",children:"Pending"})]})},s.id))})]})]}),i&&Y&&e.jsxs("div",{role:"alert",children:["Could not load defaults. Nothing will be saved. ",Da(Y)," ",e.jsx(S,{disabled:he,onClick:()=>Ye(),children:"Retry defaults"})]}),i&&!Y&&!J&&e.jsx("div",{role:"status",children:"Loading defaults…"}),Fs&&J&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-4 border-t pt-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(is,{className:"h-4 w-4 text-purple-600"}),e.jsx("h3",{className:"font-semibold",children:"Default Permission Profile"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Select a permission profile to use as the default for new users. If set, the profile's permissions will be used instead of individual dashboard permissions."}),e.jsxs(q,{value:n?.defaultPermissionProfileId||"none",onValueChange:s=>{re("defaultPermissionProfileId",s==="none"?null:s)},children:[e.jsx(K,{className:"w-full",children:e.jsx(H,{placeholder:"Select a permission profile"})}),e.jsxs(Q,{children:[e.jsx(P,{value:"none",children:"No Profile (Use Individual Permissions)"}),Ts.map(s=>e.jsx(P,{value:s.id,children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{children:s.name}),s.description&&e.jsx("span",{className:"text-xs text-muted-foreground",children:s.description})]})},s.id))]})]}),n?.defaultPermissionProfileId&&e.jsx("div",{className:"bg-amber-50 dark:bg-amber-950 p-3 rounded-lg mt-2",children:e.jsx("p",{className:"text-sm text-amber-700 dark:text-amber-300",children:"When a permission profile is selected, individual dashboard permissions below will be ignored for new users."})})]})]}),e.jsxs("div",{className:"space-y-4 border-t pt-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx($e,{className:"h-4 w-4 text-blue-600"}),e.jsx("h3",{className:"font-semibold",children:"Default SP Intranet Catalog"})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Choose the named catalog assigned by default to this user. Leave inherited to use the role/team or system default."}),e.jsxs(q,{value:n?.defaultSpIntranetCatalogId||"inherited",onValueChange:s=>re("defaultSpIntranetCatalogId",s==="inherited"?null:s),children:[e.jsx(K,{className:"w-full",children:e.jsx(H,{placeholder:"Inherited assignment"})}),e.jsxs(Q,{children:[e.jsx(P,{value:"inherited",children:"Inherited assignment"}),$s.filter(s=>!!s.publishedRevisionId||s.status==="published").map(s=>e.jsxs(P,{value:s.id,children:[s.name," ",e.jsxs("span",{className:"ml-2 text-xs text-muted-foreground",children:["(",s.id,")"]})]},s.id))]})]}),n?.spIntranetCatalogAssignment&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Effective assignment: ",e.jsx("strong",{children:n.spIntranetCatalogAssignment.catalogName||n.spIntranetCatalogAssignment.catalogId||"system default"})," ","(",n.spIntranetCatalogAssignment.source||"inherited",")."]})]}),e.jsx("div",{className:"space-y-4 border-t pt-4",children:e.jsxs("div",{className:"grid gap-4 lg:grid-cols-2 lg:items-start",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ns,{className:"h-4 w-4 text-blue-600"}),e.jsx("h3",{className:"font-semibold",children:"Default Header Dashboard"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Select which dashboard controls the header icons and navigation elements for new users. This determines which header features are visible based on the user's permissions for this dashboard."}),e.jsxs(q,{value:n?.defaultHeaderTopicId||"none",onValueChange:s=>{re("defaultHeaderTopicId",s==="none"?null:s)},children:[e.jsx(K,{className:"w-full",children:e.jsx(H,{placeholder:"Select a dashboard for header control"})}),e.jsxs(Q,{children:[e.jsx(P,{value:"none",children:"No Dashboard (Show All Headers)"}),Es.map(s=>e.jsx(P,{value:s.id,children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{children:s.title}),s.description&&e.jsx("span",{className:"text-xs text-muted-foreground",children:s.description})]})},s.id))]})]}),n?.defaultHeaderTopicId&&e.jsx("div",{className:"bg-blue-50 dark:bg-blue-950 p-3 rounded-lg mt-2",children:e.jsx("p",{className:"text-sm text-blue-700 dark:text-blue-300",children:"The selected dashboard will control which header icons and features are visible to new users based on their permissions for this dashboard."})})]})]}),e.jsxs("div",{className:"rounded-lg border bg-muted/30 p-4","data-testid":"personal-start-page-panel",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(is,{className:"h-4 w-4 text-slate-600"}),e.jsx("h3",{className:"font-semibold",children:"Personal start page"})]}),e.jsx(ee,{variant:"outline",children:ss?Rs?"Saved, unavailable":"Overrides login":"Not set"})]}),e.jsx("p",{className:"mt-2 text-sm text-muted-foreground",children:"A personal page selected from Help or Profile takes precedence over the admin defaults when this user signs in."}),ss?e.jsxs("dl",{className:"mt-3 space-y-2 text-sm",children:[e.jsxs("div",{className:"flex flex-col gap-1 sm:flex-row sm:items-start sm:justify-between",children:[e.jsx("dt",{className:"font-medium text-muted-foreground",children:"Desktop"}),e.jsx("dd",{className:"break-all text-right sm:max-w-[75%]",children:Xe(Ze,n?.personalDesktopStartPageTarget)})]}),e.jsxs("div",{className:"flex flex-col gap-1 sm:flex-row sm:items-start sm:justify-between",children:[e.jsx("dt",{className:"font-medium text-muted-foreground",children:"Mobile"}),e.jsx("dd",{className:"break-all text-right sm:max-w-[75%]",children:Xe(es,n?.personalMobileStartPageTarget)})]})]}):e.jsx("p",{className:"mt-3 text-sm text-muted-foreground",children:"No personal override is set; this user follows the configured default landing behavior."})]})]})}),e.jsxs("div",{className:"space-y-4 border-t pt-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ua,{className:"h-4 w-4 text-blue-600"}),e.jsx("h3",{className:"font-semibold",children:"Default Home Page"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:'Choose where this user lands after signing in. "SPHub" uses the normal home / header-topic behavior; picking a Netlify app opens that app full-page (the user can return to SPHub with the Back button or any header icon).'}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(w,{children:"Default Native SPHub Page"}),e.jsxs(q,{value:n?.defaultNativePage||"none",onValueChange:s=>{re("defaultNativePage",s==="none"?null:s)},"data-testid":"select-default-native-page",children:[e.jsx(K,{className:"w-full",children:e.jsx(H,{placeholder:"Select a native SPHub page"})}),e.jsxs(Q,{children:[e.jsx(P,{value:"none",children:"No Native Page"}),e.jsx(P,{value:"/assets/map",children:"Asset Map"}),e.jsx(P,{value:"/rms-grid",children:"CRM Viewer"}),e.jsx(P,{value:"/energy-planner",children:"Energy Planner"}),e.jsx(P,{value:"/smartsheet-viewer",children:"Smartsheet Viewer"})]})]}),n?.defaultNativePage&&e.jsx("p",{className:"text-sm text-blue-700 dark:text-blue-300 bg-blue-50 dark:bg-blue-950 p-3 rounded-lg",children:"This user will land on the selected native page while they have access to it."})]}),e.jsxs(q,{value:n?.defaultLandingPage||"sphub",onValueChange:s=>{re("defaultLandingPage",s==="sphub"?null:s)},"data-testid":"select-default-landing-page",children:[e.jsx(K,{className:"w-full",children:e.jsx(H,{placeholder:"Select a default home page"})}),e.jsxs(Q,{children:[e.jsx(P,{value:"sphub",children:"SP Intranet (normal home)"}),Ds.map(s=>e.jsx(P,{value:`/netlify-app/${s.id}`,children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{children:s.name}),s.description&&e.jsx("span",{className:"text-xs text-muted-foreground",children:s.description})]})},s.id))]})]}),n?.defaultLandingPage&&e.jsx("div",{className:"bg-blue-50 dark:bg-blue-950 p-3 rounded-lg mt-2",children:e.jsx("p",{className:"text-sm text-blue-700 dark:text-blue-300",children:`This user will land on the selected app after signing in (on both desktop and mobile). The app must be placed on a dashboard the user can access, or they'll see an "isn't available to you yet" notice.`})})]})]}),e.jsxs("div",{className:"space-y-4 border-t pt-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ma,{className:"h-4 w-4 text-blue-600"}),e.jsx("h3",{className:"font-semibold",children:"Default Chat AI Script"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Select the default AI script for chat interactions"}),e.jsxs(q,{value:n?.defaultChatScriptId||"none",onValueChange:s=>{ne("defaultChatScriptId",s==="none"?null:s)},"data-testid":"select-default-chat-script",children:[e.jsx(K,{className:"w-full",children:e.jsx(H,{placeholder:"Select default chat AI script"})}),e.jsxs(Q,{children:[e.jsx(P,{value:"none",children:"No Default Script"}),Ms.map(s=>e.jsx(P,{value:s.id,children:s.name},s.id))]})]})]})]}),e.jsxs("div",{className:"space-y-4 border-t pt-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(De,{className:"h-4 w-4 text-blue-600"}),e.jsx("h3",{className:"font-semibold",children:"KB Sweep Completion Emails"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Controls when this user receives entity knowledge-base sweep completion emails (when they're the run creator and the schedule defers to per-user settings)."}),e.jsxs(q,{value:n?.kbCompletionEmailPolicy||"all",onValueChange:s=>as.mutate(s),disabled:as.isPending,children:[e.jsx(K,{className:"w-full","data-testid":"select-kb-email-policy",children:e.jsx(H,{placeholder:"Select email preference"})}),e.jsxs(Q,{children:[e.jsx(P,{value:"all",children:"All terminal runs"}),e.jsx(P,{value:"errors",children:"Only errors / failures"}),e.jsx(P,{value:"never",children:"Never"})]})]})]})]}),e.jsxs("div",{className:"space-y-4 border-t pt-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(be,{className:"h-4 w-4 text-blue-600"}),e.jsx("h3",{className:"font-semibold",children:"Default Dashboard Permissions"})]}),n?.defaultPermissionProfileId&&e.jsx("div",{className:"bg-blue-50 dark:bg-blue-950 p-3 rounded-lg",children:e.jsx("p",{className:"text-sm text-blue-700 dark:text-blue-300",children:"Individual permissions are currently overridden by the selected permission profile."})}),e.jsx("div",{className:`bg-muted/50 p-4 rounded-lg ${n?.defaultPermissionProfileId?"opacity-50":""}`,children:e.jsx(Aa,{userId:i})})]}),e.jsxs("div",{className:"space-y-4 border-t pt-4",children:[e.jsx("h3",{className:"font-semibold",children:"Default Content Sets"}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(cs,{className:"h-4 w-4"}),e.jsx(w,{children:"News"})]}),e.jsx("div",{className:"grid grid-cols-2 gap-2",children:Oe.length>0?Oe.map(s=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(x,{id:`news-${s.id}
1`,checked:n?.defaultNewsSetIds?.includes(s.id)||!1,onCheckedChange:r=>Z("News",s.id,r)}),e.jsx("label",{htmlFor:`news-${s.id}`,className:"text-sm cursor-pointer",children:s.name})]},s.id)):e.jsx("p",{className:"text-sm text-muted-foreground col-span-2",children:"No news sets available for selection"})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ka,{className:"h-4 w-4"}),e.jsx(w,{children:"Podcasts"})]}),e.jsx("div",{className:"grid grid-cols-2 gap-2",children:Be.length>0?Be.map(s=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(x,{id:`podcast-${s.id}`,checked:n?.defaultPodcastSetIds?.includes(s.id)||!1,onCheckedChange:r=>Z("Podcast",s.id,r)}),e.jsx("label",{htmlFor:`podcast-${s.id}`,className:"text-sm cursor-pointer",children:s.name})]},s.id)):e.jsx("p",{className:"text-sm text-muted-foreground col-span-2",children:"No podcast sets available for selection"})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(os,{className:"h-4 w-4"}),e.jsx(w,{children:"Documents"})]}),e.jsx("div",{className:"grid grid-cols-2 gap-2",children:qe.length>0?qe.map(s=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(x,{id:`document-${s.id}`,checked:n?.defaultDocumentSetIds?.includes(s.id)||!1,onCheckedChange:r=>Z("Document",s.id,r)}),e.jsx("label",{htmlFor:`document-${s.id}`,className:"text-sm cursor-pointer",children:s.name})]},s.id)):e.jsx("p",{className:"text-sm text-muted-foreground col-span-2",children:"No document sets available for selection"})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(De,{className:"h-4 w-4"}),e.jsx(w,{children:"Alerts"})]}),e.jsx("div",{className:"grid grid-cols-2 gap-2",children:Ke.length>0?Ke.map(s=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(x,{id:`alert-${s.id}`,checked:n?.defaultAlertSetIds?.includes(s.id)||!1,onCheckedChange:r=>Z("Alert",s.id,r)}),e.jsx("label",{htmlFor:`alert-${s.id}`,className:"text-sm cursor-pointer",children:s.name})]},s.id)):e.jsx("p",{className:"text-sm text-muted-foreground col-span-2",children:"No alert sets available for selection"})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(us,{className:"h-4 w-4"}),e.jsx(w,{children:"Calculator"})]}),e.jsx("div",{className:"grid grid-cols-2 gap-2",children:He.length>0?He.map(s=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(x,{id:`calculator-${s.id}`,checked:n?.defaultCalculatorSetIds?.includes(s.id)||!1,onCheckedChange:r=>Z("Calculator",s.id,r)}),e.jsx("label",{htmlFor:`calculator-${s.id}`,className:"text-sm cursor-pointer",children:s.name})]},s.id)):e.jsx("p",{className:"text-sm text-muted-foreground col-span-2",children:"No calculator sets available for selection"})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx($e,{className:"h-4 w-4"}),e.jsx(w,{children:"Intranet"})]}),e.jsx("div",{className:"grid grid-cols-2 gap-2",children:Qe.length>0?Qe.map(s=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(x,{id:`smartsheet-${s.id}`,checked:n?.defaultSmartsheetSetIds?.includes(s.id)||!1,onCheckedChange:r=>Z("Smartsheet",s.id,r)}),e.jsx("label",{htmlFor:`smartsheet-${s.id}`,className:"text-sm cursor-pointer",children:s.name})]},s.id)):e.jsx("p",{className:"text-sm text-muted-foreground col-span-2",children:"No Smartsheet sets available for selection"})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ns,{className:"h-4 w-4 text-orange-600"}),e.jsx(w,{children:"CRM Scripts"})]}),!Je?.canAccessRMS&&e.jsxs("div",{className:"flex items-center gap-2 p-2 bg-amber-50 border border-amber-200 rounded-md text-amber-800 text-sm",children:[e.jsx(rs,{className:"h-4 w-4 flex-shrink-0"}),e.jsx("span",{children:"CRM access is not enabled for this user. Enable the CRM toggle in User Authorization for these scripts to be accessible."})]}),e.jsx("div",{className:"grid grid-cols-2 gap-2",children:ze.length>0?ze.map(s=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(x,{id:`hubspot-script-${s.id}
1`,checked:n?.defaultRMSScriptIds?.includes(s.id)||!1,onCheckedChange:r=>xe("RMS",s.id,r)}),e.jsx("label",{htmlFor:`hubspot-script-${s.id}`,className:"text-sm cursor-pointer",children:s.name})]},s.id)):e.jsx("p",{className:"text-sm text-muted-foreground col-span-2",children:"No CRM scripts available for selection"})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(xs,{className:"h-4 w-4 text-green-600"}),e.jsx(w,{children:"QuickBooks Scripts"})]}),!Je?.canAccessQuickbooks&&e.jsxs("div",{className:"flex items-center gap-2 p-2 bg-amber-50 border border-amber-200 rounded-md text-amber-800 text-sm",children:[e.jsx(rs,{className:"h-4 w-4 flex-shrink-0"}),e.jsx("span",{children:"QuickBooks access is not enabled for this user. Enable the QuickBooks toggle in User Authorization for these scripts to be accessible."})]}),e.jsx("div",{className:"grid grid-cols-2 gap-2",children:We.length>0?We.map(s=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(x,{id:`quickbooks-script-${s.id}`,checked:n?.defaultQuickbooksScriptIds?.includes(s.id)||!1,onCheckedChange:r=>xe("Quickbooks",s.id,r)}),e.jsx("label",{htmlFor:`quickbooks-script-${s.id}`,className:"text-sm cursor-pointer",children:s.name})]},s.id)):e.jsx("p",{className:"text-sm text-muted-foreground col-span-2",children:"No QuickBooks scripts available for selection"})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ms,{className:"h-4 w-4 text-blue-600"}),e.jsx(w,{children:"EV Scripts"})]}),e.jsx("div",{className:"grid grid-cols-2 gap-2",children:_e.length>0?_e.map(s=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(x,{id:`ev-script-${s.id}`,checked:n?.defaultEVScriptIds?.includes(s.id)||!1,onCheckedChange:r=>xe("EV",s.id,r)}),e.jsx("label",{htmlFor:`ev-script-${s.id}`,className:"text-sm cursor-pointer",children:s.viewName})]},s.id)):e.jsx("p",{className:"text-sm text-muted-foreground col-span-2",children:"No EV scripts available for selection"})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ha,{className:"h-4 w-4 text-sky-600"}),e.jsx(w,{children:"Weather Scripts"})]}),e.jsx("div",{className:"grid grid-cols-2 gap-2",children:Ge.length>0?Ge.map(s=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(x,{id:`weather-script-${s.id}`,checked:n?.defaultWeatherScriptIds?.includes(s.id)||!1,onCheckedChange:r=>xe("Weather",s.id,r)}),e.jsx("label",{htmlFor:`weather-script-${s.id}`,className:"text-sm cursor-pointer",children:s.name})]},s.id)):e.jsx("p",{className:"text-sm text-muted-foreground col-span-2",children:"No Weather scripts available for selection"})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(hs,{className:"h-4 w-4 text-blue-600"}),e.jsx(w,{children:"Water Utilities Access"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Re,{id:"all-water-utilities",checked:n?.allowedWaterUtilityIds==null,onCheckedChange:s=>{ne("allowedWaterUtilityIds",s?null:[])}}),e.jsx("label",{htmlFor:"all-water-utilities",className:"text-sm cursor-pointer",children:"All utilities (no restriction)"})]}),n?.allowedWaterUtilityIds!=null&&e.jsx("div",{className:"grid grid-cols-2 gap-2 pl-1",children:Fe.length>0?[...Fe].sort((s,r)=>(s.utilityCompanyName||s.scriptName||"").localeCompare(r.utilityCompanyName||r.scriptName||"")).map(s=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(x,{id:`water-utility-${s.id}`,checked:n?.allowedWaterUtilityIds?.includes(s.id)||!1,onCheckedChange:r=>{const k=n?.allowedWaterUtilityIds??[],I=r?[...k,s.id]:k.filter(F=>F!==s.id);ne("allowedWaterUtilityIds",I)}}),e.jsx("label",{htmlFor:`water-utility-${s.id}`,className:"text-sm cursor-pointer",children:s.utilityCompanyName||s.scriptName||s.id})]},s.id)):e.jsx("p",{className:"text-sm text-muted-foreground col-span-2",children:"No water utilities available"})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:`Restricts this user's Water Meters pages (list, map, alerts, setup) to the checked utilities. "All utilities" removes the restriction. If no utilities are checked, the restriction is cleared and the user keeps full access.`})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(xa,{
1className:"h-4 w-4 text-purple-600"}),e.jsx(w,{children:"Max Enrichment Records Per Run"})]}),e.jsx(fe,{type:"number",min:1,max:15e3,value:n?.defaultMaxEnrichmentRecords??50,onChange:s=>{const r=parseInt(s.target.value)||50;ne("defaultMaxEnrichmentRecords",Math.max(1,Math.min(15e3,r)))},className:"w-32"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Caps the maximum records per enrichment run for this user (1–15,000)."})]})]}),e.jsx("div",{className:"flex justify-end pt-4 border-t",children:e.jsx(S,{onClick:Us,disabled:X.isPending||!i,children:X.isPending?e.jsxs(e.Fragment,{children:[e.jsx(_,{className:"h-4 w-4 mr-2 animate-spin"}),"Saving..."]}):e.jsxs(e.Fragment,{children:[e.jsx(fs,{className:"h-4 w-4 mr-2"}),"Save User Defaults"]})})})]})]})]}),u&&e.jsx(Ea,{onSaved:()=>{v(null),f([])}}),u&&e.jsxs(de,{className:"border-amber-300 dark:border-amber-800","data-testid":"user-access-baseline-card",children:[e.jsxs(ge,{children:[e.jsxs(je,{className:"flex items-center gap-2",children:[e.jsx(be,{className:"h-5 w-5"}),"Organization User Access Baseline"]}),e.jsx(ve,{children:"Preview and apply the approved landing, header, footer, and limited-admin policy. Owner accounts and personal desktop/mobile start-page choices are not changed."})]}),e.jsxs(ce,{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2 rounded-md border p-3",children:[e.jsx(w,{htmlFor:"baseline-saved-set",children:"Reusable user set"}),e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row",children:[e.jsxs(q,{value:d,onValueChange:s=>{U(s);const r=G.find(k=>k.id===s);D(r?.name||"")},disabled:O||oe.isPending,children:[e.jsx(K,{id:"baseline-saved-set","data-testid":"select-baseline-saved-set",children:e.jsx(H,{placeholder:O?"Loading saved sets…":"Choose a saved set"})}),e.jsx(Q,{children:G.map(s=>e.jsx(P,{value:s.id,children:s.name},s.id))})]}),e.jsxs(S,{type:"button",variant:"outline",onClick:()=>oe.mutate(d),disabled:!d||oe.isPending,"data-testid":"button-load-baseline-saved-set",children:[oe.isPending&&e.jsx(_,{className:"mr-2 h-4 w-4 animate-spin"}),"Load into fresh preview"]}),d&&e.jsx(S,{type:"button",variant:"ghost",onClick:()=>{U(""),D("")},children:"New set"})]}),B?.unavailableUserIds?.length>0&&e.jsxs("div",{role:"alert",className:"text-sm text-amber-700 dark:text-amber-300","data-testid":"baseline-set-membership-warning",children:[B.unavailableUserIds.length," saved member",B.unavailableUserIds.length===1?" is":"s are"," no longer available and will not be selected or applied."]})]}),p?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid gap-2 text-sm sm:grid-cols-2 lg:grid-cols-4",children:[e.jsxs("div",{children:[e.jsx("strong",{children:m.length})," selected users"]}),e.jsxs("div",{children:[e.jsx("strong",{children:p.details.filter(s=>m.includes(s.userId)&&s.willChange).length})," ","selected users will change"]}),e.jsxs("div",{children:[e.jsx("strong",{children:p.unchangedUsers})," already current"]}),e.jsxs("div",{children:[e.jsx("strong",{children:p.exemptOwners})," exempt owners"]}),e.jsxs("div",{children:[e.jsx("strong",{children:p.ordinaryUsers})," ordinary users"]}),e.jsxs("div",{children:[e.jsx("strong",{children:p.limitedAdminUsers})," limited admins"]}),e.jsxs("div",{children:[e.jsx("strong",{children:p.missingDesignatedAccounts})," designated accounts missing"]}),e.jsxs("div",{children:["Policy ",e.jsx("strong",{children:p.policyVersion})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(w,{children:"Users included in this mass update"}),e.jsxs(pa,{children:[e.jsx(fa,{asChild:!0,children:e.jsxs(S,{variant:"outline",role:"combobox",className:"w-full justify-between","data-testid":"button-select-baseline-users",children:[m.length," of ",p.details.length," users selected",e.jsx(Pa,{className:"ml-2 h-4 w-4 opacity-50"})]})}),e.jsxs(ga,{className:"w-[min(92vw,32rem)] p-0",align:"start",children:[e.jsxs("div",{className:"border-b p-3",children:[e.jsx(fe,{value:T,onChange:s=>C(s.target.value),placeholder:"Search users…","data-testid":"input-search-baseline-users"}),e.jsxs("div",{className:"mt-2 flex gap-2",children:[e.jsx(S,{type:"button",size:"sm",variant:"outline",onClick:()=>f(p.details.map(s=>s.userId)),children:"Select all"}),e.jsx(S,{type:"button",size:"sm",variant:"outline",onClick:()=>f([]),children:"Clear all"})]})]}),e.jsx("div",{className:"max-h-72 overflow-y-auto p-2",children:p.details.filter(s=>{const r=T.trim().toLowerCase();return!r||pe(s).toLowerCase().includes(r)||se(s.email).toLowerCase().includes(r)}).map(s=>{const r=m.includes(s.userId);return e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 rounded-md px-2 py-2 hover:bg-muted",children:[e.jsx(x,{checked:r,onCheckedChange:k=>f(I=>k?[...I,s.userId]:I.filter(F=>F!==s.userId)),"data-testid":`checkbox-baseline-user-${s.userId}`}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block truncate text-sm font-medium",children:pe(s)}),e.jsxs("span",{className:"block truncate text-xs text-muted-foreground",children:[s.email," · ",s.group==="limited-admin"?"Limited admin":"Ordinary user",s.willChange?"":" · Already current"]})]})]},s.userId)})})]})]}),e.jsx("div",{className:"max-h-32 overflow-y-auto rounded-md border bg-muted/30 p-2 text-xs text-muted-foreground",children:p.details.filter(s=>m.includes(s.userId)).map(s=>pe(s)).join(", ")||"No users selected."})]}),e.jsx("div",{className:"rounded-md border border-amber-300 bg-amber-50 p-3 text-sm text-amber-950 dar
1k:border-amber-800 dark:bg-amber-950/30 dark:text-amber-100",children:"This applies changes only to the selected users in one database transaction. If user data changed after this preview, the operation will stop and require a new preview."}),e.jsxs("div",{className:"space-y-2 rounded-md border p-3",children:[e.jsx(w,{htmlFor:"baseline-set-name",children:B?"Update reusable set":"Save selection as a reusable set"}),e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row",children:[e.jsx(fe,{id:"baseline-set-name",value:E,onChange:s=>D(s.target.value),placeholder:"Set name",maxLength:80,"data-testid":"input-baseline-set-name"}),e.jsxs(S,{type:"button",variant:"outline",onClick:()=>we.mutate(),disabled:we.isPending||!E.trim()||m.length===0,"data-testid":"button-save-baseline-set",children:[we.isPending&&e.jsx(_,{className:"mr-2 h-4 w-4 animate-spin"}),B?"Update set":"Save set"]})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(S,{onClick:()=>Ne.mutate(),disabled:Ne.isPending||m.length===0,"data-testid":"button-apply-user-access-baseline",children:[Ne.isPending&&e.jsx(_,{className:"h-4 w-4 mr-2 animate-spin"}),"Confirm and Apply"]}),e.jsx(S,{variant:"outline",onClick:()=>{v(null),f([])},children:"Cancel"})]})]}):e.jsxs(S,{variant:"outline",onClick:()=>ye.mutate(),disabled:ye.isPending,"data-testid":"button-preview-user-access-baseline",children:[ye.isPending&&e.jsx(_,{className:"h-4 w-4 mr-2 animate-spin"}),"Preview Changes"]}),e.jsxs("div",{className:"border-t pt-4","data-testid":"user-access-baseline-history",children:[e.jsxs("div",{className:"mb-3",children:[e.jsx("h3",{className:"text-sm font-semibold",children:"Recent run history"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Aggregate results only; individual user changes are not included."})]}),a?e.jsxs("div",{className:"flex items-center text-sm text-muted-foreground",children:[e.jsx(_,{className:"mr-2 h-4 w-4 animate-spin"}),"Loading history…"]}):l?e.jsx("p",{className:"text-sm text-destructive",children:"Run history could not be loaded."}):t.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"No baseline runs recorded yet."}):e.jsx("div",{className:"space-y-2",children:t.map(s=>{const r=[s.initiator?.firstName,s.initiator?.lastName].filter(Boolean).join(" ");return e.jsxs("div",{className:"rounded-md border p-3 text-sm",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ee,{variant:s.eventType==="apply"?"default":"secondary",children:s.eventType==="apply"?"Applied":"Previewed"}),e.jsxs("span",{className:"font-medium",children:["Policy ",s.policyVersion]})]}),e.jsx("time",{className:"text-xs text-muted-foreground",dateTime:s.createdAt,children:new Date(s.createdAt).toLocaleString()})]}),e.jsxs("div",{className:"mt-2 text-xs text-muted-foreground",children:["By ",r||s.initiator?.email||"Unknown user",r&&s.initiator?.email?` (${s.initiator.email})`:""]}),e.jsxs("div",{className:"mt-2 flex flex-wrap gap-x-4 gap-y-1 text-xs",children:[e.jsxs("span",{children:[s.counts.targetedUsers," targeted"]}),e.jsxs("span",{children:[s.counts.changedUsers," ",s.eventType==="apply"?"changed":"would change"]}),s.counts.unchangedUsers!==null&&e.jsxs("span",{children:[s.counts.unchangedUsers," unchanged"]}),e.jsxs("span",{children:[s.counts.missingDesignatedAccounts," designated missing"]})]})]},s.id)})})]})]})]})]}),e.jsx(ja,{}),e.jsx(ba,{pageId:"user-defaults"})]})}const Xa=Object.freeze(Object.defineProperty({__proto__:null,UserDefaultsManager:Ra},Symbol.toStringTag,{value:"Module"}));export{Ea as O,Ra as U,Xa as u};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.