1import{u as A,r as i,j as e,L as E}from"./vendor-react-GnwsTJfO.js";import{f as d,U as o,N as T,b8 as v,B as t,R as k,C as N,g as w,E as B,G as K,n as O,aB as z,F as P,a8 as R,a9 as U,aa as $,ab as I,I as q,ad as G}from"./index-Bj2Y77AF.js";import{u as H}from"./useAdminAuth-BXhWp9H6.js";import{e as V}from"./AdminNavigation-DYLQ05kD.js";import{L as M}from"./label-9b9pu6HH.js";import{D as W}from"./displayBoards-DQVuIMIZ.js";import{S as J}from"./square-pen-mOKYrOsG.js";import{E as Q}from"./external-link-Bga9tRS3.js";import{P as X,a as Y}from"./power-B6EBc_9_.js";import{T as Z}from"./trash-2-D673yTlG.js";import"./vendor-cjs-BcELrC9x.js";import"./vendor-supabase-BWPZKnGU.js";import"./vendor-ui-C1xCQL2z.js";import"./vendor-utils-B2rm_Apj.js";import"./vendor-query-Dp4tHR6-.js";import"./MasonicCross-CB_Vslf8.js";import"./users-CHiFHZvy.js";import"./image-l440pP5V.js";const fe=()=>{const y=A(),{user:l,loading:p}=H(),[u,m]=i.useState([]),[_,g]=i.useState(!0),[C,n]=i.useState(!1),[c,h]=i.useState(""),[j,f]=i.useState(!1);i.useEffect(()=>{!p&&l&&D()},[p,l]);const D=async()=>{g(!0);const{data:s,error:a}=await d.from("display_boards").select("id, name, access_token, is_active, updated_at, owner_id").order("updated_at",{ascending:!1});a?o.error("Kunne ikke hente skjermvisninger",{description:a.message}):m(s||[]),g(!1)},S=async()=>{if(!c.trim()||!l)return;f(!0);const{data:s,error:a}=await d.from("display_boards").insert({owner_id:l.id,name:c.trim(),layout_config:{widgets:W}}).select("id").single();if(f(!1),a||!s){o.error("Kunne ikke opprette",{description:a==null?void 0:a.message});return}n(!1),h(""),y(`/admin/displays/${s.id}`)},L=async s=>{const{error:a}=await d.from("display_boards").update({is_active:!s.is_active}).eq("id",s.id);if(a){o.error("Kunne ikke endre status",{description:a.message});return}m(x=>x.map(r=>r.id===s.id?{...r,is_active:!r.is_active}:r))},b=async s=>{if(!confirm("Slette denne skjermvisningen?"))return;const{error:a}=await d.from("display_boards").delete().eq("id",s);if(a){o.error("Kunne ikke slette",{description:a.message});return}m(x=>x.filter(r=>r.id!==s))},F=s=>{const a=`${window.location.origin}/skjerm/${s}`;navigator.clipboard.writeText(a),o("Kopiert",{description:"URL er kopiert til utklippstavlen."})};return e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsx(T,{}),e.jsx(V,{}),e.jsxs("div",{className:"container mx-auto px-4 py-8 max-w-6xl",children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-3xl font-serif flex items-center gap-2",children:[e.jsx(v,{className:"h-7 w-7"})," Skjermvisninger"]}),e.jsx("p",{className:"text-muted-foreground mt-1",children:"Sett opp informasjonsskjermer for vestibyle, garderobe eller andre fellesarealer."})]}),e.jsxs(t,{onClick:()=>n(!0),children:[e.jsx(k,{className:"h-4 w-4 mr-2"})," Ny skjermvisning"]})]}),_?e.jsx("p",{className:"text-muted-foreground",children:"Laster..."}):u.length===0?e.jsx(N,{children:e.jsxs(w,{className:"py-12 text-center",children:[e.jsx(v,{className:"h-12 w-12 mx-auto text-muted-foreground mb-3"}),e.jsx("p",{className:"text-lg font-medium",children:"Ingen skjermvisninger ennÃ¥"}),e.jsx("p",{className:"text-muted-foreground mb-4",children:"Opprett din første visning for Ã¥ vise nyheter, møter og informasjonsmøter pÃ¥ en TV i logelokalet."}),e.jsxs(t,{onClick:()=>n(!0),children:[e.jsx(k,{className:"h-4 w-4 mr-2"})," Kom i gang"]})]})}):e.jsx("div",{className:"grid gap-4",children:u.map(s=>e.jsxs(N,{children:[e.jsx(B,{className:"flex flex-row items-start justify-between gap-4 pb-3",children:e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs(K,{className:"text-xl flex items-center gap-2",children:[s.name,e.jsx(O,{variant:s.is_active?"default":"secondary",children:s.is_active?"Aktiv":"Deaktivert"})]}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1 truncate",children:["/skjerm/",s.access_token]})]})}),e.jsxs(w,{className:"flex flex-wrap gap-2",children:[e.jsx(t,{variant:"outline",size:"sm",asChild:!0,children:e.jsxs(E,{to:`/admin/displays/${s.id}`,children:[e.jsx(J,{className:"h-4 w-4 mr-1"})," Rediger"]})}),e.jsx(t,{variant:"outline",size:"sm",asChild:!0,children:e.jsxs("a",{href:`/skjerm/${s.access_token}`,target:"_blank",rel:"noreferrer",children:[e.jsx(Q,{className:"h-4 w-4 mr-1"})," Ã
pne"]})}),e.jsxs(t,{variant:"outline",size:"sm",onClick:()=>F(s.access_token),children:[e.jsx(z,{className:"h-4 w-4 mr-1"})," Kopier URL"]}),e.jsx(t,{variant:"outline",size:"sm",onClick:()=>L(s),children:s.is_active?e.jsxs(e.Fragment,{children:[e.jsx(X,{className:"h-4 w-4 mr-1"})," Deaktiver"]}):e.jsxs(e.Fragment,{children:[e.jsx(Y,{className:"h-4 w-4 mr-1"})," Aktiver"]})}),e.jsxs(t,{variant:"outline",size:"sm",onClick:()=>b(s.id),className:"text-destructive",children:[e.jsx(Z,{className:"h-4 w-4 mr-1"})," Slett"]})]})]},s.id))})]}),e.jsx(P,{}),e.jsx(R,{open:C,onOpenChange:n,children:e.jsxs(U,{children:[e.jsx($,{children:e.jsx(I,{children:"Ny skjermvisning"})}),e.jsxs("div",{className:"space-y-3 py-2",children:[e.jsx(M,{htmlFor:"board-name",children:"Navn"}),e.jsx(q,{id:"board-name",value:c,onChange:s=>h(s.target.value),placeholder:"F.eks. Vestibyle Stamhuset",autoFocus:!0}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Du kan velge loger, kategorier og widgets etter at du har opprettet visningen."})]}),e.jsxs(G,{children:[e.jsx(t,{variant:"outline",onClick:()=>n(!1),children:"Avbryt"}),e.jsx(t,{onClick:S,disabled:!c.trim()||j,children:j?"Oppretter...":"Opprett"})]})]})})]})};export{fe as default};
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.