1import{r,j as e,f as ha,u as xa,d as pa}from"./vendor-react-GnwsTJfO.js";import{I as U,n as Fe,Y as Je,a6 as Ee,a7 as Ae,a8 as De,B as j,al as $e,a5 as bt,f as I,C as We,g as Ye,aG as br,V as D,r as ue,W as ce,i as kt,j as _t,k as Nt,l as wt,m as Te,O as qt,as as As,ag as fa,G as rt,J as at,aE as ja,aF as qe,a1 as Vr,a9 as lt,aa as nt,ab as it,ac as ot,ad as ws,s as va,ae as ba,af as he,L as Ge,u as ka,N as _a,Z as Na,aH as wa,aI as ya,R as Sa,S as Ca,aD as Ia,F as Ea,aJ as Aa}from"./index-Bk3sb3g_.js";import{u as Da}from"./useAdminAuth-B8BfgGDM.js";import{logActivity as ys}from"./activityLog-D9S9TAPK.js";import{G as Ta,s as Ss}from"./notifications-CLqs6mnN.js";import{r as Cs}from"./auth-CgH0Si-l.js";import{c as kr}from"./articleVersions-5Onrp65e.js";import{L as p}from"./label-CC4lcsSO.js";import{T as ct}from"./textarea-DX8aEp-d.js";import{u as Mr,R as Fa}from"./RichTextEditor-CFLY8lWg.js";import{C as tt}from"./checkbox-CXoLB0wA.js";import{C as _r,a as Nr,b as wr,c as yr,d as Sr,e as Cr}from"./command-B7nLZnCr.js";import{E as Kt,B as Pa,u as Oa,e as La,P as Ir,T as Ra,C as Er,S as Is}from"./AdminNavigation-DVMee0wC.js";import{u as Va,M as Ma}from"./MediaPicker-AY7BSKf3.js";import{u as za,g as $a,r as Ba}from"./mediaLibrary-CxE8eUBE.js";import{M as Ua,R as Ha,a as Es}from"./useProvincialMediaBanks-D1PHzV0C.js";import{I as Ka}from"./type-MjfN6nuh.js";import{U as qa}from"./upload-BsTf4xyL.js";import{C as Ar}from"./circle-alert-C33XTStY.js";import{T as Ga}from"./trash-B9Yv3eXG.js";import{g as Wa,u as Ya,I as Ja}from"./useAssignableEditors-kxr_FLxX.js";import{C as Xa}from"./circle-x-DAuLvfD-.js";import{C as Qa}from"./circle-check-big-CDOLBlXh.js";import{C as Ve,a as Me,b as ze}from"./collapsible-Bjm1WOLF.js";import{S as Za}from"./scroll-area-Do1l-lmj.js";import{A as el}from"./ArticleDiffView-B_6i1x1x.js";import{H as zr}from"./history-gdwIZDAX.js";import{R as Dr}from"./rotate-ccw-CnA-U9Eq.js";import{A as tl}from"./ArticleComments-BIkh35pm.js";import{C as st}from"./calendar-48ynrwFx.js";import{I as Tr}from"./followUpUtils-BjkDY2kf.js";import{U as sl}from"./user-check-BRMa_jUj.js";import{a as rl}from"./addMonths-Drd7G1Kk.js";import"./browser-image-compression-BzWLnoYn.js";import{a as al}from"./vendor-query-Dp4tHR6-.js";import{C as Fr}from"./chevrons-up-down-DD_tIyFg.js";import{I as ll}from"./image-CJtwgLmH.js";import{S as nl}from"./settings-2-BWlldEL-.js";import{M as il}from"./message-square-Dpi2jLvN.js";import{S as Pr}from"./save-DqX4_s7f.js";import"./vendor-cjs-BcELrC9x.js";import"./vendor-supabase-BWPZKnGU.js";import"./vendor-ui-C1xCQL2z.js";import"./vendor-utils-B2rm_Apj.js";import"./vendor-editor-D6dciLIt.js";import"./vendor-charts-nzC1RNlt.js";import"./trash-2-DOLSXo7O.js";import"./useStickyNavOffset-BgVuKoFO.js";import"./image-plus-Cy7-asr8.js";import"./align-left-DWOxStZg.js";import"./MasonicCross-CB_Vslf8.js";import"./users-Cq75-41X.js";import"./tabs-BNB3Udc8.js";import"./alert-1UpWSmue.js";import"./switch-HlfwIZQ_.js";import"./circle-check-HbOHiPuy.js";import"./startOfMonth-3vrP5pyf.js";import"./addDays-beBN0z4I.js";import"./chevron-left-BR0AlWMq.js";import"./differenceInDays-BKUaVyd2.js";function ol(s){return s.some(c=>c.rights_status==="pending")}function Or(s){const{status:c,silent:h,images:k}=s;return h||c!=="published"&&c!=="pending_review"?!1:ol(k)}function cl(s){return s.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Gt(s,c){return`${s.toLowerCase()}â${c.toLowerCase()}`}function $r(s,c){const h=[];if(!s||!c||c.length===0)return h;for(const _ of c){const y=_.case_sensitive?"g":"gi",G=new RegExp(`\\b${cl(_.wrong_term)}\\b`,y);let d;for(;(d=G.exec(s))!==null;)_.case_sensitive&&d[0]===_.correct_term||h.push({start:d.index,end:d.index+d[0].length,wrongTerm:d[0],correctTerm:_.correct_term,description:_.description})}h.sort((_,y)=>_.start-y.start);const k=[];for(const _ of h){const y=k[k.length-1];(!y||_.start>=y.end)&&k.push(_)}return k}const dl=({value:s,onChange:c,placeholder:h,className:k,id:_,maxLength:y})=>{const{data:G=[]}=Mr(),[d,N]=r.useState(null),[H,S]=r.useState({x:0,y:0}),[E,K]=r.useState(new Set),me=r.useRef(null),M=r.useRef(null),q=r.useMemo(()=>$r(s,G).filter(C=>!E.has(Gt(C.wrongTerm,C.correctTerm))),[s,G,E]),J=r.useCallback(()=>{d&&(K(C=>new Set(C).add(Gt(d.wrongTerm,d.correctTerm))),N(null))},[d]),m=r.useCallback(()=>
1{if(!d)return;const C=s.slice(0,d.start)+d.correctTerm+s.slice(d.end);c(C),N(null)},[d,s,c]),v=r.useMemo(()=>{if(q.length===0)return null;const C=[];let f=0;for(const z of q)z.start>f&&C.push({text:s.slice(f,z.start),isError:!1}),C.push({text:s.slice(z.start,z.end),isError:!0,error:z}),f=z.end;return f<s.length&&C.push({text:s.slice(f),isError:!1}),C},[s,q]),o=(C,f)=>{const z=f.target.getBoundingClientRect();S({x:z.left,y:z.bottom+4}),N(C)};return e.jsxs("div",{className:"relative",children:[e.jsx(U,{ref:me,id:_,value:s,onChange:C=>c(C.target.value),placeholder:h,className:k,maxLength:y}),q.length>0&&e.jsx("div",{ref:M,className:"absolute inset-0 pointer-events-none overflow-hidden px-3 py-2 text-sm",style:{color:"transparent",whiteSpace:"nowrap"},children:v==null?void 0:v.map((C,f)=>C.isError?e.jsx("span",{className:"terminology-error pointer-events-auto",onClick:z=>C.error&&o(C.error,z),children:C.text},f):e.jsx("span",{children:C.text},f))}),q.length>0&&e.jsxs(Fe,{variant:"outline",className:"absolute right-2 top-1/2 -translate-y-1/2 text-[hsl(var(--heraldic-gold))] border-[hsl(var(--heraldic-gold)/0.5)] bg-[hsl(var(--heraldic-gold)/0.1)] text-xs cursor-pointer",onClick:()=>q[0]&&N(q[0]),children:[e.jsx(Je,{className:"h-3 w-3 mr-1"}),q.length]}),d&&e.jsxs(Ee,{open:!!d,onOpenChange:C=>!C&&N(null),children:[e.jsx(Ae,{asChild:!0,children:e.jsx("div",{style:{position:"fixed",left:H.x,top:H.y,width:1,height:1,pointerEvents:"none"}})}),e.jsx(De,{className:"w-72",side:"bottom",align:"start",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(Je,{className:"h-5 w-5 text-[hsl(var(--heraldic-gold))] mt-0.5 flex-shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:"Mulig skrivefeil"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:e.jsx("span",{className:"font-mono bg-destructive/10 text-destructive px-1 rounded",children:d.wrongTerm})})]})]}),e.jsxs("div",{className:"border-t pt-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-1",children:"Forslag:"}),e.jsx("p",{className:"font-mono bg-primary/10 text-primary px-2 py-1 rounded text-sm",children:d.correctTerm}),d.description&&e.jsx("p",{className:"text-xs text-muted-foreground mt-2 italic",children:d.description})]}),e.jsxs("div",{className:"flex gap-2 pt-1",children:[e.jsxs(j,{size:"sm",onClick:()=>{m()},className:"flex-1",children:[e.jsx($e,{className:"h-4 w-4 mr-1"}),"Erstatt"]}),e.jsxs(j,{size:"sm",variant:"outline",onClick:J,className:"flex-1",children:[e.jsx(bt,{className:"h-4 w-4 mr-1"}),"Ignorer"]})]})]})})]})]})},ul=({value:s,onChange:c,placeholder:h,className:k,id:_,rows:y=3,maxLength:G})=>{const{data:d=[]}=Mr(),[N,H]=r.useState(null),[S,E]=r.useState({x:0,y:0}),[K,me]=r.useState(new Set),M=r.useMemo(()=>$r(s,d).filter(m=>!K.has(Gt(m.wrongTerm,m.correctTerm))),[s,d,K]),q=r.useCallback(m=>{me(v=>new Set(v).add(Gt(m.wrongTerm,m.correctTerm))),H(null)},[]);r.useCallback(()=>{if(!N)return;const m=s.slice(0,N.start)+N.correctTerm+s.slice(N.end);c(m),H(null)},[N,s,c]);const J=m=>{E({x:100,y:100}),H(m)};return e.jsxs("div",{className:"relative",children:[e.jsx(ct,{id:_,value:s,onChange:m=>c(m.target.value),placeholder:h,className:k,rows:y,maxLength:G}),M.length>0&&e.jsxs(Fe,{variant:"outline",className:"absolute right-2 top-2 text-[hsl(var(--heraldic-gold))] border-[hsl(var(--heraldic-gold)/0.5)] bg-[hsl(var(--heraldic-gold)/0.1)] text-xs cursor-pointer",onClick:()=>{M[0]&&J(M[0])},children:[e.jsx(Je,{className:"h-3 w-3 mr-1"}),M.length," ",(M.length===1,"feil")]}),M.length>0&&e.jsx("div",{className:"mt-2 space-y-1",children:M.map((m,v)=>e.jsxs("div",{className:"text-xs flex items-center gap-2 p-1.5 rounded bg-[hsl(var(--heraldic-gold)/0.1)] border border-[hsl(var(--heraldic-gold)/0.3)] cursor-pointer hover:bg-[hsl(var(--heraldic-gold)/0.15)]",onClick:()=>{const o=s.slice(0,m.start)+m.correctTerm+s.slice(m.end);c(o)},children:[e.jsx(Je,{className:"h-3 w-3 text-[hsl(var(--heraldic-gold))] flex-shrink-0"}),e.jsx("span",{className:"font-mono text-destructive line-through",children:m.wrongTerm}),e.jsx("span",{className:"text-muted-foreground",children:"â"}),e.jsx("span",{className:"font-mono text-primary",children:m.correctTerm}),e.jsx(j,{size:"sm",variant:"ghost",className:"ml-auto h-5 px-2 text-xs",onClick:o=>{o.stopPropagation();const C=s.slice(0,m.start)+m.correctTerm+s.slice(m.end);c(C)},children:e.jsx($e,{className:"h-3 w-3"})}),e.jsx(j,{size:"sm",variant:"ghost",className:"h-5 px-2 text-xs",title:"Ignorer",onClick:o=>{o.stopPropagation(),q(m)},children:e.jsx(bt,{className:"h-3 w-3"})})]},v))})]})};function ml({articleId:s,onChange:c,initialImages:h=[],fallbackImageUrl:k,fallbackAltText:_,imageFocusPoint:y="50% 50%",categoryId:G=null}){const[d,N]=r.useState(h),[H,S]=r.useState(!1),[E,K]=r.useState([]);r.useState(null);const[me,M]=r.useState(!1),[q,J]=r.useState(!1),m=Va(G),v=!!G||m.isSenior;r.useEffect(()=>{s?o():N(h)},[s]),r.useEffect(()=>{s||N(h)},[h,s]);const o=async()=>
1{if(s)try{const{data:i,error:x}=await I.from("article_images").select("*").eq("article_id",s).order("sort_order",{ascending:!0});if(x)throw x;const l=i||[],b=l.map(g=>g.media_id).filter(Boolean);if(b.length>0){const{data:g}=await I.from("media_library").select("id, rights_status").in("id",b),$=new Map((g||[]).map(R=>[R.id,R.rights_status]));l.forEach(R=>{R.media_id&&(R.rights_status=$.get(R.media_id)??null)})}if(l.length===0&&k){M(!0);const g={id:"fallback-image",article_id:s,image_url:k,alt_text:_||null,caption:null,sort_order:0,is_featured:!0};N([g]),c([g])}else M(!1),N(l),c(l)}catch(i){console.error("Error loading images:",i)}},C=async i=>{const x=i.target.files;if(!(!x||x.length===0)){if(!m.canUpload){D.error(m.blockReason||"Opplasting er ikke mulig her"),i.target.value="";return}K(Array.from(x)),i.target.value=""}},f=async i=>{S(!0);const x=[];let l=0;try{const{data:{user:b}}=await I.auth.getUser();if(!b){D.error("Du mÃ¥ være logget inn for Ã¥ laste opp bilder");return}for(let $=0;$<i.length;$++){const R=i[$],Pe=R.file,F=await za(Pe,{scope:m.scope,lodgeId:m.lodgeId,lodgeNumber:m.lodgeNumber,categoryId:G??null,meta:{title:R.title.trim(),alt_text:R.altText.trim()||null,photographer:R.photographer.trim()||null},provenance:R.provenance});if(F.rights_status==="rejected"){l+=1;continue}const dt=$a(F.file_path),P={id:`temp-${Date.now()}-${$}`,article_id:s||"",image_url:dt,alt_text:F.alt_text??null,caption:F.caption??null,sort_order:d.length+$,is_featured:d.length===0&&$===0,media_id:F.id,photographer:F.photographer??null,credit:F.credit??null,copyright:F.copyright??null,source:F.source??null,rights_status:F.rights_status??null};x.push(P)}const g=[...d,...x];N(g),c(g),K([]),x.length>0&&D.success(`${x.length} bilde(r) lastet opp til ${m.bankLabel}`),l>0&&D.warning(`${l} bilde(r) er avvist og kan ikke brukes i artikkelen.`),x.some($=>$.rights_status==="pending")&&D.warning("Ett eller flere bilder venter pÃ¥ rettighetsgodkjenning fra Webredaktør DNFO. Artikkelen kan ikke publiseres før bildene er godkjent.")}catch(b){console.error("Error uploading images:",b),D.error((b==null?void 0:b.message)||"Kunne ikke laste opp bilder")}finally{S(!1)}},z=i=>{const x=d.filter(l=>l.id!==i);x.length>0&&!x.some(l=>l.is_featured)&&(x[0].is_featured=!0),N(x),c(x)},ge=i=>{const x=d.map(l=>({...l,is_featured:l.id===i}));N(x),c(x)},Be=(i,x)=>{const l=d.map(b=>b.id===i?{...b,caption:x}:b);N(l),c(l)},we=(i,x)=>{const l=d.map(b=>b.id===i?{...b,alt_text:x}:b);N(l),c(l)},xe=(i,x,l)=>{const b=d.map(g=>g.id===i?{...g,[x]:l}:g);N(b),c(b)},le=(i,x)=>{if(x<0||x>=d.length)return;const l=[...d],[b]=l.splice(i,1);l.splice(x,0,b),l.forEach((g,$)=>{g.sort_order=$}),N(l),c(l)},Ue=i=>{var b,g,$,R,Pe,F;const x={id:`temp-${Date.now()}`,article_id:s||"",image_url:i.url,alt_text:i.altText,caption:i.caption,sort_order:d.length,is_featured:d.length===0,media_id:((b=i.media)==null?void 0:b.id)??null,photographer:((g=i.media)==null?void 0:g.photographer)??null,credit:(($=i.media)==null?void 0:$.credit)??null,copyright:((R=i.media)==null?void 0:R.copyright)??null,source:((Pe=i.media)==null?void 0:Pe.source)??null,rights_status:((F=i.media)==null?void 0:F.rights_status)??null},l=[...d,x];N(l),c(l),D.success("Bilde lagt til fra bildebanken")};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(p,{children:"Artikkelbilder"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(j,{type:"button",variant:"secondary",onClick:()=>J(!0),disabled:!v,children:[e.jsx(Ka,{className:"h-4 w-4 mr-2"}),"Velg fra bildebank"]}),e.jsx(U,{type:"file",accept:".jpg,.jpeg,.png,.webp,.gif,.avif,.heic,.heif",multiple:!0,onChange:C,disabled:H||!m.canUpload,className:"max-w-xs",id:"image-upload"}),e.jsxs(j,{type:"button",variant:"outline",disabled:H||!m.canUpload,title:m.blockReason??void 0,onClick:()=>{var i;return(i=document.getElementById("image-upload"))==null?void 0:i.click()},children:[e.jsx(qa,{className:"h-4 w-4 mr-2"}),H?"Laster opp...":m.canUpload?`Last opp til ${m.bankLabel}`:"Opplasting ikke mulig"]})]})]}),!m.loading&&m.blockReason&&e.jsxs("div",{className:"flex items-start gap-2 text-amber-700 dark:text-amber-400 bg-amber-50 dark:bg-amber-950/20 p-3 rounded",children:[e.jsx(Ar,{className:"h-5 w-5 shrink-0 mt-0.5"}),e.jsx("span",{className:"text-sm",children:m.blockReason})]}),v&&e.jsx(Ma,{open:q,onOpenChange:J,contextCategoryId:G,onSelect:Ue}),e.jsx(Ua,{open:E.length>0,files:E,lodgeNumber:m.lodgeNumber,bankLabel:m.bankLabel,uploading:H,onCancel:()=>K([]),onConfirm:f}),me&&e.jsxs("div",{className:"flex items-center gap-2 text-amber-600 bg-amber-50 dark:bg-amber-950/20 p-3 rounded mb-4",children:[e.jsx(Ar,{className:"h-5 w-5"}),e.jsx("span",{className:"text-sm",children:"Bildet nedenfor kommer fra artikkeldataene (image_url). Last opp et nytt bilde for Ã¥ erstatte det."})]}),d.length===0?e.jsxs("div",{className:"border-2 border-dashed rounded-lg p-8 text-center text-muted-foreground",children:[e.jsx("p",{children:"Ingen bilder lagt til ennÃ¥"}),e.jsx("p",{className:"text-sm",children:"Last opp bilder for Ã¥ legge dem til artikkelen"})]}):e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:d.map((i,x)=>e.jsx(We,{className:i.is_featured?"ring-2 ring-primary":"",children:e.jsxs(Ye,{className:"p-4",children:[e.jsxs("div",{className:"relative aspect-video mb-3 overflow-hidden rounded bg-muted",children:[e.jsx("img",{loading:"lazy",decoding:"async",src:i.image_url,alt:i.alt_text||"Artikkel bilde",className:"w-full h-full object-cover",style:{objectPosition:y}}),i.is_featured&&e.jsxs("div",{className:"absolute top-2 left-2 bg-primary text-primary-foreground px-2 py-1 rounded text-xs font-medium flex items-center gap-1",children:[e.jsx(br,{className:"h-3 w-3"}),"Hovedbilde"]}),i.rights_status==="pending"&&e.jsx("div",{className:"absolute inset-0 bg-neutral-900/60 flex items-center justify-center",children:e.jsx("span",{className:"px-3 py-1 rounded bg-neutral-900/80 text-neutral-50 text-sm font-medium",children:"Til godkjenning"})})]}),i.rights_status==="pending"&&e.jsx("p",{className:"text-xs text-amber-700 dark:text-amber-400 mb-2",children:"Bildet venter pÃ¥ rettighetsgodkjenning fra Webredaktør DNFO. Artikkelen kan ikke publiseres før bildet er godkjent."}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx(p,{className:"text-xs",children:"Alt-tekst"}),e.jsx(U,{value:i.alt_text||"",onChange:l=>we(i.id,l.target.value),placeholder:"Beskrivelse for tilgjengelighet",className:"h-8 text-sm"})]}),e.jsxs("div",{children:[e.jsx(p,{className:"text-xs",children:"Bildetekst"}),e.jsx(U,{value:i.caption||"",onChange:l=>Be(i.id,l.target.value),placeholder:"Valgfri bildetekst",className:"h-8 text-sm"})]}),e.jsxs("div",{className:"pt-2 border-t space-y-2",children:[e.jsx(p,{className:"text-xs uppercase tracking-wide text-muted-foreground",children:"Fotokreditering"}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{children:[e.jsx(p,{className:"text-[10px] text-muted-foreground",children:"Fotograf"}),e.jsx(U,{value:i.photographer||"",onChange:l=>xe(i.id,"photographer",l.target.value),placeholder:"Navn",className:"h-8 text-sm"})]}),e.jsxs("div",{children:[e.jsx(p,{className:"text-[10px] text-muted-foreground",children:"Kreditt"}),e.jsx(U,{value:i.credit||"",onChange:l=>xe(i.id,"credit",l.target.value),placeholder:"F.eks. byrÃ¥",className:"h-8 text-sm"})]}),e.jsxs("div",{children:[e.jsx(p,{className:"text-[10px] text-muted-foreground",children:"Copyright"}),e.jsx(U,{value:i.copyright||"",onChange:l=>xe(i.id,"copyright",l.target.value),placeholder:"© Eier",className:"h-8 text-sm"})]}),e.jsxs("div",{children:[e.jsx(p,{className:"text-[10px] text-muted-foreground",children:"Kilde"}),e.jsx(U,{value:i.source||"",onChange:l=>xe(i.id,"source",l.target.value),placeholder:"Kilde",className:"h-8 text-sm"})]})]})]}),e.jsxs("div",{className:"flex items-center justify-between pt-2 border-t",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(j,{type:"button",variant:"ghost",size:"sm",onClick:()=>le(x,x-1),disabled:x===0,children:"â"}),e.jsx(j,{type:"button",variant:"ghost",size:"sm",onClick:()=>le(x,x+1),disabled:x===d.length-1,children:"â"}),e.jsxs("span",{className:"text-xs text-muted-foreground ml-2",children:[x+1," av ",d.length]})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[!i.is_featured&&e.jsx(j,{type:"button",variant:"ghost",size:"sm",onClick:()=>ge(i.id),title:"Sett som hovedbilde",children:e.jsx(br,{className:"h-4 w-4"})}),e.jsx(j,{type:"button",variant:"ghost",size:"sm",onClick:()=>z(i.id),className:"text-destructive hover:text-destructive",children:e.jsx(Ga,{className:"h-4 w-4"})})]})]})]})]})},i.id))})]})}const gl=(s,c)=>s==="published"&&c&&new Date(c)<new Date?{status:"expired",isExpired:!0}:{status:s,isExpired:!1},hl=s=>{switch(s){case"draft":return"Utkast";
1case"pending_review":return"Til godkjenning";case"published":return"Publisert";case"rejected":return"Avvist";case"unpublished":return"Avpublisert";case"archived":return"Nyhetsarkiv";case"expired":return"Utløpt";default:return s}},Lr=s=>{switch(s){case"draft":return e.jsx(qt,{className:"h-3 w-3"});case"pending_review":return e.jsx(fa,{className:"h-3 w-3"});case"published":return e.jsx(Qa,{className:"h-3 w-3"});case"rejected":return e.jsx(Xa,{className:"h-3 w-3"});case"unpublished":return e.jsx(Je,{className:"h-3 w-3"});case"archived":return e.jsx(As,{className:"h-3 w-3"});case"expired":return e.jsx(qt,{className:"h-3 w-3"});default:return null}},xl=s=>{switch(s){case"draft":return"bg-muted text-muted-foreground";case"pending_review":return"bg-yellow-100 text-yellow-800 border-yellow-300";case"published":return"bg-green-100 text-green-800 border-green-300";case"rejected":return"bg-destructive text-destructive-foreground";case"unpublished":return"bg-red-100 text-red-800 border-red-300";case"archived":return"bg-blue-100 text-blue-800 border-blue-300";case"expired":return"bg-amber-100 text-amber-800 border-amber-300";default:return""}},pl=({status:s,publishEndAt:c,unpublishReason:h,canChangeStatus:k,canPublish:_,onStatusChange:y,onUnpublishReasonChange:G})=>{const{status:d,isExpired:N}=gl(s,c);if(!k)return e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{children:"Status"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(Fe,{variant:"outline",className:`gap-1 ${xl(d)}`,children:[Lr(d),hl(d)]}),N&&c&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["(utløpt ",ue(c,"d. MMM yyyy",{locale:ce}),")"]})]})]});const S=(()=>{const E=[];return k&&(E.push({value:"draft",label:"Utkast"}),_&&E.push({value:"pending_review",label:"Til godkjenning"}),_&&E.push({value:"published",label:"Publisert"}),E.push({value:"unpublished",label:"Avpublisert"}),s==="archived"&&E.push({value:"archived",label:"Nyhetsarkiv (gammel status)"})),E})();return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{children:"Status"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(kt,{value:s,onValueChange:y,children:[e.jsx(_t,{className:"w-[200px]",children:e.jsx(Nt,{})}),e.jsx(wt,{children:S.map(E=>e.jsx(Te,{value:E.value,children:e.jsxs("div",{className:"flex items-center gap-2",children:[Lr(E.value),E.label]})},E.value))})]}),N&&c&&e.jsxs("span",{className:"text-xs text-amber-600",children:["(utløpt ",ue(c,"d. MMM yyyy",{locale:ce}),")"]})]})]}),s==="unpublished"&&k&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{htmlFor:"unpublish-reason",children:"Ã
rsak til avpublisering (valgfritt)"}),e.jsx(ct,{id:"unpublish-reason",value:h,onChange:E=>G(E.target.value),placeholder:"F.eks. 'Artikkelen er utdatert og trenger revisjon'",rows:3}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Denne meldingen vises for forfatteren når de åpner artikkelen."})]})]})},Rr={draft:{label:"Utkast",variant:"secondary"},submitted:{label:"Innsendt",variant:"outline"},published:{label:"Publisert",variant:"default"},auto_save:{label:"Autolagret",variant:"secondary"},rejected:{label:"Avvist",variant:"destructive"},unpublished:{label:"Avpublisert",variant:"outline"},archived:{label:"Lagt i nyhetsarkiv",variant:"outline"},unarchived:{label:"Hentet ut av nyhetsarkiv",variant:"outline"},imported_baseline:{label:"Importert",variant:"secondary"}},fl=({articleId:s,onRestore:c})=>{const[h,k]=r.useState([]),[_,y]=r.useState([]),[G,d]=r.useState(!0),[N,H]=r.useState(!1),[S,E]=r.useState(null),[K,me]=r.useState(null),[M,q]=r.useState(!1),[J,m]=r.useState(!1),[v,o]=r.useState(!1),[C,f]=r.useState(!1),z=C?h:h.filter(l=>l.change_type!=="auto_save"),ge=h.filter(l=>l.change_type==="auto_save").length;r.useEffect(()=>{N&&s&&(Be(),we())},[N,s]);const Be=async()=>{try{d(!0);const{data:l,error:b}=await I.from("article_versions").select("*").eq("article_id",s).order("version_number",{ascending:!1});if(b)throw b;k(l||[])}catch(l){console.error("Error loading versions:",l),D.error("Kunne ikke laste versjonshistorikk")}finally{d(!1)}},we=async()=>{try{const{data:l,error:b}=await I.from("article_images").select("*").eq("article_id",s).order("sort_order",{ascending:!0});if(b)throw b;y(l||[])}catch(l){console.error("Error loading article images:",l)}},xe=l=>{E(l),q(!0)},le=l=>{me(l);const b=h.findIndex(g=>g.id===l.id);b<h.length-1?E(h[b+1]):E(null),m(!0)},Ue=l=>{E(l),o(!0)},i=()=>{S&&c&&(c(S),o(!1),D.success("Versjon gjenopprettet - husk å lagre artikkelen!"))},x=l=>ue(new Date(l),"d. MMM yyyy 'kl.' HH:mm",{locale:ce});return e.jsxs(e.Fragment,{children:[e.jsx(Ve,{open:N,onOpenChange:H,children:e.jsxs(We,{children:[e.jsx(Me,{asChild:!0,children:e.jsxs(rt,{className:"cursor-pointer hover:bg-muted/50 transition-colors",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(zr,{className:"h-5 w-5"}),e.jsx(at,{className:"text-lg",children:"Versjonshistorikk"}),z.length>0&&e.jsxs(Fe,{variant:"secondary",children:[z.length," versjoner"]})]}),N?e.jsx(ja,{className:"h-5 w-5"}):e.jsx(qe,{className:"h-5 w-5"})]}),e.jsx(Vr,{children:"Se og gjenopprett tidligere versjoner av artikkelen"})]})}),e.jsx(ze,{children:e.jsxs(Ye,{children:[ge>0&&e.jsx("div",{className:"flex items-center justify-end pb-3",children:e.jsx(j,{variant:"ghost",size:"sm",onClick:()=>f(l=>!l),children:C?"Skjul autolagrede versjoner":`Vis autolagrede versjoner (${ge})`})}),G?e.jsx("p",{className:"text-sm text-muted-foreground py-4",children:"Laster versjoner..."}):z.length===0?e.jsx("p",{className:"text-sm text-muted-foreground py-4",children:"Ingen tidligere versjoner funnet. Versjoner opprettes automatisk ved lagring."}):e.jsx(Za,{className:"h-auto max-h-[400px]",children:e.jsx("div",{className:"space-y-2 pr-4",children:z.map((l,b)=>{var g,$;return e.jsxs("div",{className:"flex items-center justify-between p-3 rounded-lg border bg-card hover:bg-muted/30 transition-colors",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsxs("span",{className:"font-medium text-sm",children:["Versjon ",l.version_number]}),e.jsx(Fe,{variant:((g=Rr[l.change_type])==null?void 0:g.variant)||"secondary",children:(($=Rr[l.change_type])==null?void 0:$.label)||l.change_type}),b===0&&e.jsx(Fe,{variant:"outline",className:"text-xs",children:"Siste"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:x(l.created_at)}),l.change_summary&&e.jsx("p",{className:"text-xs text-muted-foreground mt-1 italic",children:l.change_summary})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(j,{variant:"ghost",size:"sm",onClick:()=>xe(l),title:"Forhåndsvis versjon",children:e.jsx(Kt,{className:"h-4 w-4"})}),b<h.length-1&&e.jsx(j,{variant:"ghost",size:"sm",onClick:()=>le(l),title:"Sammenlign med forrige",children:e.jsx(Ta,{className:"h-4 w-4"})}),b>0&&c&&e.jsx(j,{variant:"ghost",size:"sm",onClick:()=>Ue(l),title:"Gjenopprett versjon",children:e.jsx(Dr,{className:"h-4 w-4"})})]})]},l.id)})})})]})})]})}),e.jsx(lt,{open:M,onOpenChange:q,children:e.jsxs(nt,{className:"site-preview max-w-3xl max-h-[80vh] overflow-y-auto",children:[e.jsxs(it,{children:[e.jsxs(ot,{children:["Forhåndsvisning - Versjon ",S==null?void 0:S.version_number]}),e.jsx(ws,{children:S&&x(S.created_at)})]}),S&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-lg",children:S.title}),S.excerpt&&e.jsx("p",{className:"text-muted-foreground mt-2",children:S.excerpt})]}),_.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("p",{className:"text-sm font-medium text-muted-foreground",children:["Bildegalleri (",_.length," bilder)"]}),e.jsx("div",{className:"grid grid-cols-4 gap-2",children:_.map(l=>e.jsxs("div",{className:"relative",children:[e.jsx("img",{loading:"lazy",decoding:"async",src:l.image_url,alt:l.alt_text||"",className:`w-full h-20 object-cover rounded ${l.is_featured?"ring-2 ring-primary":""}`}),l.is_featured&&e.jsx("span",{className:"absolute top-1 left-1 bg-primary text-primary-foreground text-xs px-1 rounded",children:"Hovedbilde"})]},l.id))})]}),_.length===0&&S.image_url&&e.jsx("img",{loading:"lazy",decoding:"async",src:S.image_url,alt:S.image_alt_text||"",className:"w-full max-h-64 object-cover rounded-lg"}),e.jsx("div",{className:"prose prose-sm max-w-none dark:prose-invert",dangerouslySetInnerHTML:{__html:va(S.content)}})]})]})}),e.jsx(lt,{open:J,onOpenChange:m,children:e.jsxs(nt,{className:"max-w-4xl max-h-[80vh] overflow-y-auto",children:[e.jsxs(it,{children:[e.jsx(ot,{children:"Sammenlign versjoner"}),e.jsx(ws,{children:K&&e.jsxs(e.Fragment,{children:["Versjon ",K.version_number," sammenlignet med",S?` versjon ${S.version_number}`:" første versjon"]})})]}),K&&e.jsx(el,{previousVersion:S,currentVersion:K,showFullContent:!0})]})}),e.jsx(lt,{open:v,onOpenChange:o,children:e.jsxs(nt,{children:[e.jsxs(it,{children:[e.jsx(ot,{children:"Gjenopprett versjon"}),e.jsxs(ws,{children:["Er du sikker på at du vil gjenopprette versjon ",S==null?void 0:S.version_number,"? Dette vil erstatte gjeldende innhold i redigeringsskjemaet."]})]}),e.jsxs(ba,{children:[e.jsx(j,{variant:"outline",onClick:()=>o(!1),children:"Avbryt"}),e.jsxs(j,{onClick:i,children:[e.jsx(Dr,{className:"h-4 w-4 mr-2"}),"Gjenopprett"]})]})]})})]})},jl=({followUpType:s,followUpDate:c,followUpIntervalMonths:h,followUpNote:k,updatedAt:_,disabled:y=!1,followUpAssigneeId:G=null,assignableEditors:d=[],canAssign:N=!1,onFollowUpAssigneeChange:H,onFollowUpTypeChange:S,onFollowUpDateChange:E,onFollowUpIntervalChange:K,onFollowUpNoteChange:me})=>{const M=s==="interval"&&h&&_?rl(new Date(_),h):null,q=v=>{v==="custom"?h||K(6):K(parseInt(v))},J=Tr.find(v=>v.value===h),m=h&&!J;return e.jsxs(We,{children:[e.jsx(rt,{className:"pb-3",children:e.jsxs(at,{className:"flex items-center gap-2 text-base",children:[e.jsx(Pa,{className:"h-4 w-4"}),"Oppfølging"]})}),e.jsxs(Ye,{className:"space-y-4",children:[e.jsxs(Ha,{value:s,onValueChange:v=>S(v),disabled:y,children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Es,{value:"none",id:"follow-up-none"}),e.jsx(p,{htmlFor:"follow-up-none",className:"font-normal cursor-pointer",children:"Ingen oppfølging"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Es,{value:"date",id:"follow-up-date"}),e.jsx(p,{htmlFor:"follow-up-date",className:"font-normal cursor-pointer",children:"Oppfølgingsdato"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(Es,{value:"interval",id:"follow-up-interval"}),e.jsx(p,{htmlFor:"follow-up-interval",className:"font-normal cursor-pointer",children:"Oppdateringsintervall"})]})]}),s==="date"&&e.jsxs("div",{className:"space-y-2 pl-6",children:[e.jsx(p,{children:"Dato for oppfølging"}),e.jsxs(Ee,{children:[e.jsx(Ae,{asChild:!0,children:e.jsxs(j,{variant:"outline",className:he("w-full justify-start text-left font-normal",!c&&"text-muted-foreground"),disabled:y,children:[e.jsx(Ge,{className:"mr-2 h-4 w-4"}),c?ue(c,"d. MMMM yyyy",{locale:ce}):e.jsx("span",{children:"Velg dato..."})]})}),e.jsx(De,{className:"w-auto p-0",align:"start",children:e.jsx(st,{mode:"single",selected:c||void 0,onSelect:v=>E(v||null),initialFocus:!0,locale:ce,disabled:v=>v<new Date})})]})]}),s==="interval"&&e.jsxs("div",{className:"space-y-3 pl-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{children:"Oppdater hver"}),e.jsx("div",{className:"flex gap-2",children:e.jsxs(kt,{value:m?"custom"
1:(h==null?void 0:h.toString())||"",onValueChange:q,disabled:y,children:[e.jsx(_t,{className:"w-full",children:e.jsx(Nt,{placeholder:"Velg intervall..."})}),e.jsxs(wt,{children:[Tr.map(v=>e.jsxs(Te,{value:v.value.toString(),children:[v.label," (",v.value," ",v.value===1?"mÃ¥ned":"mÃ¥neder",")"]},v.value)),e.jsx(Te,{value:"custom",children:"Egendefinert..."})]})]})})]}),m&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(U,{type:"number",min:1,max:60,value:h||"",onChange:v=>{const o=parseInt(v.target.value);K(isNaN(o)?null:Math.max(1,Math.min(60,o)))},className:"w-20",disabled:y}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"mÃ¥neder"})]}),M&&e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Neste oppfølging: ",ue(M,"d. MMMM yyyy",{locale:ce})]})]}),s!=="none"&&e.jsxs("div",{className:"space-y-2 pl-6",children:[e.jsx(p,{htmlFor:"follow-up-note",children:"Notat (valgfritt)"}),e.jsx(ct,{id:"follow-up-note",value:k,onChange:v=>me(v.target.value),placeholder:"Hva skal oppdateres?",rows:2,disabled:y})]}),s!=="none"&&N&&e.jsxs("div",{className:"space-y-2 pl-6",children:[e.jsxs(p,{className:"flex items-center gap-2",children:[e.jsx(sl,{className:"h-4 w-4"}),"Ansvarlig for oppfølging"]}),e.jsxs(kt,{value:G??"none",onValueChange:v=>H==null?void 0:H(v==="none"?null:v),disabled:y,children:[e.jsx(_t,{children:e.jsx(Nt,{placeholder:"Ingen ansvarlig"})}),e.jsxs(wt,{children:[e.jsx(Te,{value:"none",children:"Ingen ansvarlig"}),d.map(v=>e.jsxs(Te,{value:v.userId,children:[v.name," â ",Wa(v.role)]},v.userId))]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Oppfølgingen vises pÃ¥ den ansvarliges dashboard."})]})]})]})},Bt=(s,c)=>{if(!s)return null;const h=c??new Date,k=new Date(s);return k.setHours(h.getHours(),h.getMinutes(),0,0),k},Ut=s=>s?`${String(s.getHours()).padStart(2,"0")}:${String(s.getMinutes()).padStart(2,"0")}`:"",Ht=(s,c)=>{if(!c)return s;const[h,k]=c.split(":").map(Number),_=s??new Date,y=new Date(_);return y.setHours(h||0,k||0,0,0),y},Sn=()=>{var dr,ur,mr,gr,hr,xr,pr,fr;const{id:s}=ha(),c=xa(),h=pa(),k=Oa(),{user:_,role:y,userCategoryIds:G,isWebmaster:d,canPublishDirectly:N,canApprove:H,loading:S}=Da(),{getSettingBool:E}=ka(),K=E("region_editor_auto_approve",!0),me=E("region_editor_auto_publish",!1);r.useEffect(()=>{if(h.hash!=="#kommentarer")return;const t=window.setTimeout(()=>{var a;(a=document.getElementById("kommentarer"))==null||a.scrollIntoView({behavior:"smooth",block:"start"})},600);return()=>window.clearTimeout(t)},[h.hash,s]);const M=r.useRef(null);r.useEffect(()=>{var a;const t=(a=h.state)==null?void 0:a.restoreScrollY;typeof t=="number"&&M.current===null&&(M.current=t)},[h.state]);const q=r.useCallback(()=>sessionStorage.getItem("articleList_returnUrl")||"/admin/articles",[]),J=r.useCallback(()=>{const t=q();c(t)},[c,q]),[m,v]=r.useState(!1),[o,C]=r.useState(!1),[f,z]=r.useState(""),[ge,Be]=r.useState(""),[we,xe]=r.useState(null),[le,Ue]=r.useState(""),[i,x]=r.useState(""),[l,b]=r.useState(""),[g,$]=r.useState(""),[R,Pe]=r.useState(""),[F,dt]=r.useState(null),[P,yt]=r.useState(""),[Br,Ur]=r.useState(null),[Oe,Wt]=r.useState(""),[je,Hr]=r.useState([]),[ye,Kr]=r.useState([]),[se,Ds]=r.useState([]),[St,Yt]=r.useState([]),[Ts,qr]=r.useState([]),[Fs,Ps]=r.useState(!1);r.useState(!1);const[Os,Gr]=r.useState(null),[Z,Ct]=r.useState(null),It=r.useRef(null),[V,ut]=r.useState(null),[ee,Jt]=r.useState(null),[O,Et]=r.useState(null),[Xt,Wr]=r.useState(""),[Yr,At]=r.useState(!1),[Dt,Ls]=r.useState(!0),[Tt,Rs]=r.useState(!0),[Ft,Vs]=r.useState(!1),[Pt,Ms]=r.useState(!1),[Jr,Xr]=r.useState(!1),[Qt,zs]=r.useState(!1),pe=S?null:y,Xe=G,[re,Zt]=r.useState(null),[mt,es]=r.useState(""),[gt,ts]=r.useState(""),[ht,ss]=r.useState(""),[xt,rs]=r.useState(""),[Ot,$s]=r.useState(""),[pt,as]=r.useState("right"),[Bs,Lt]=r.useState(null),[Us,Hs]=r.useState(null),[Rt,Ks]=r.useState(""),[W,Qe]=r.useState("draft"),[qs,Gs]=r.useState(null),[Qr,ft]=r.useState(!1),[Zr,jt]=r.useState(!1),[Ws,Ys]=r.useState(""),[ls,Js]=r.useState(""),[ve,Vt]=r.useState(!1),ns=r.useRef(!1),is=r.useRef(!1),os=r.useRef(""),cs=r.useRef(""),ds=!!s&&(W==="published"||W==="unpublished"),Mt=y==="editor_region"?ds?K:me:N,Ze=!!O&&O.getTime()<=Date.now(),[be,Xs]=r.useState("none"),[Le,Qs]=r.useState(null),[us,Zs]=r.useState(null),[ms,er]=r.useState(""),[gs,tr]=r.useState(null),[He,hs]=r.useState("50% 50%"),[ke,xs]=r.useState([]),[ps,ea]=r.useState(null),[sr,ta]=r.useState("national"),[zt,rr]=r.useState({}),[sa,ra]=r.useState(!1),{data:fs=[]}=al({queryKey:["tags"],queryFn:async()=>{const{data:t,error:a}=await I.from("tags").select("id, name, slug, color").order("name");if(a)throw a;return t}}),js=["webmaster","editor_dnfo"].includes(pe||""),ar=["webmaster","editor_dnfo"].includes(pe||""),{editors:aa}=Ya(ar,{categoryId:P||null,authorId:Br});r.useEffect(()=>{if(!s&&f){const t=f.toLowerCase().replace(/[æ]/g,"ae").replace(/[ø]/g,"o").replace(/[Ã¥]/g,"a").replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"");Be(t)}},[f,s]),r.useEffect(()=>{(async()=>{await na(),await la()})()},[]);const la=async()=>{try{const{data:t,error:a}=await I.from("article_templates").select("*").order("name",{ascending:!0});if(a)throw a;Kr(t||[])}catch(t){console.error("Error loading templates:",t)}},vs=()=>
1{if(!P)return null;const t=je.find(a=>a.id===P);return(t==null?void 0:t.default_template_id)||null},_e=()=>Oe||vs(),bs=t=>{if(!t)return null;const a=ye.find(u=>u.id===t);return(a==null?void 0:a.name)||null};r.useEffect(()=>{s&&pe!==null&&je.length>0&&oa()},[s,pe,je,Xe]),r.useEffect(()=>{if(!s&&!Z){const t=new Date;Ct(t),ut(t)}},[s]);const na=async()=>{try{const{data:t,error:a}=await I.from("categories").select("*").order("name",{ascending:!0});if(a)throw a;Hr(t||[]);const{data:n}=await I.from("magazine_issues").select("category_id").not("category_id","is",null);qr((n||[]).map(w=>w.category_id).filter(w=>!!w))}catch(t){console.error("Error loading categories:",t),D.error("Kunne ikke laste kategorier")}};r.useEffect(()=>{if(!pe||je.length===0)return;const t=je.filter(a=>!Ts.includes(a.id)||a.id===P);if(["webmaster","editor_dnfo"].includes(pe)){Yt(t);return}if(["editor_region","editor_lodge"].includes(pe)){const a=t.filter(u=>!!(Xe.includes(u.id)||u.parent_id&&Xe.includes(u.parent_id)));Yt(a);return}Yt(t)},[pe,Xe,je,Ts,P]),r.useEffect(()=>{s||P||St.length===1&&yt(St[0].id)},[s,P,St]);const vt=()=>P?je.find(t=>t.id===P):null,lr=t=>{const a=je.find(u=>u.id===t.parent_id);return a?`${a.name} ⺠${t.name}`:t.name},nr=()=>{var t,a;return JSON.stringify({title:f,slug:ge,subtitle:i,excerpt:le,byline:l,content:g,categoryId:P,templateId:Oe,metaDescription:Ot,imageUrl:((t=se.find(u=>u.is_featured))==null?void 0:t.image_url)||F||null,imageAlt:((a=se.find(u=>u.is_featured))==null?void 0:a.alt_text)||R||null,imageFocusPoint:He,images:se.map(u=>`${u.image_url}|${u.alt_text||""}|${u.caption||""}|${u.is_featured}`),createdAt:(Z==null?void 0:Z.toISOString())||null,publishedAt:(V==null?void 0:V.toISOString())||null,publishEndAt:(ee==null?void 0:ee.toISOString())||null,archiveAt:(O==null?void 0:O.toISOString())||null,showDate:Dt,showCategory:Tt,hideFromListings:Ft,followUpType:be,followUpDate:(Le==null?void 0:Le.toISOString())||null,followUpIntervalMonths:us,followUpNote:ms,followUpAssigneeId:gs,tags:[...ke].sort(),eventDate:(re==null?void 0:re.toISOString())||null,eventTime:mt,eventEndTime:gt,eventLocation:ht,eventAddress:xt,twoColumnImagePosition:pt})};cs.current=nr();const $t=r.useRef(),ir=r.useRef(W);ir.current=W,r.useEffect(()=>{if(!f||!g||!s&&!P)return;const t=setInterval(()=>{var u;if(ns.current||cs.current===os.current)return;const a=ir.current||"draft";ns.current=!0,Promise.resolve((u=$t.current)==null?void 0:u.call($t,a,!0)).finally(()=>{ns.current=!1})},3e4);return()=>clearInterval(t)},[s,f,g,P]),r.useEffect(()=>{const t=a=>{cs.current!==os.current&&(!f&&!g||(a.preventDefault(),a.returnValue=""))};return window.addEventListener("beforeunload",t),()=>window.removeEventListener("beforeunload",t)},[f,i,le,l,g,P]);const ia=async(t,a)=>{try{const{data:u,error:n}=await I.from("article_versions").select("id").eq("article_id",t.id).limit(1);if(n){console.error("Error checking existing versions:",n);return}if(u&&u.length===0&&t.published_at){const{error:w}=await I.from("article_versions").insert([{article_id:t.id,version_number:1,title:t.title,excerpt:t.excerpt,content:t.content,image_url:t.image_url,image_alt_text:t.image_alt_text,image_focus_point:t.image_focus_point,byline:t.byline,layout_data:t.layout_data,template_id:t.template_id,category_id:t.category_id,created_by:a,change_type:"imported_baseline",change_summary:"Automatisk opprettet baseline for importert artikkel"}]);w&&console.error("Error creating baseline version:",w)}}catch(u){console.error("Error in createBaselineVersion:",u)}},oa=async()=>{v(!0);let t=!1;try{const{data:a,error:u}=await I.from("articles").select("*").eq("id",s).single();if(u)throw u;if(!a)throw new Error("Article not found");const n=a,w=(_==null?void 0:_.id)===n.author_id;if(["editor_region","editor_lodge"].includes(pe||"")&&!w){const A=n.category_id;if(A){const oe=Xe.includes(A);let X=!1;if(!oe){const Q=je.find(ie=>ie.id===A);Q!=null&&Q.parent_id&&Xe.includes(Q.parent_id)&&(X=!0)}if(!oe&&!X){D.error("Du har ikke tilgang til å redigere denne artikkelen"),J();return}}else{D.error("Du har ikke tilgang til å redigere denne artikkelen"),J();return}}_&&await ia(n,_.id),z(n.title),Be(n.slug),Ue(n.excerpt||""),x(n.subtitle||""),b(n.byline||""),$(n.content),Pe(n.image_alt_text||""),dt(n.image_url),yt(n.category_id||""),Ur(n.author_id||null),Wt(n.template_id||""),Ct(n.created_at?new Date(n.created_at):null),ut(n.published_at?new Date(n.published_at):null),Jt(n.publish_end_at?new Date(n.publish_end_at):null),Et(n.archive_at?new Date(n.archive_at):null),Wr(n.updated_at),Ls(n.show_date??!0),Rs(n.show_category??!0),Vs(n.hide_from_listings??!1),Ms(n.is_display_slide??!1),Xr(n.display_slide_mandatory??!1),zs(n.exclude_from_attention??!1),Lt(n.rejection_reason||null),Hs(n.approval_feedback||null),Ks(n.unpublish_reason||""),Qe(n.status),Gs(n.submitted_at||null);const B=n.magazine_issue_id;if(ea(B),rr(n.magazine_checklist||{}),B){const{data:A}=await I.from("magazine_issues").select("lodge_id").eq("id",B).maybeSingle();ta(A!=null&&A.lodge_id?"lodge":"national")}if(Xs(n.follow_up_type||"none"),Qs(n.follow_up_date?new Date(n.follow_up_date):null),Zs(n.follow_up_interval_months||null),er(n.follow_up_note||""),tr(n.follow_up_assignee_id||null),It.current={title:n.title,status:n.status,category_id:n.
1category_id||null,template_id:n.template_id||null,published_at:n.published_at||null,publish_end_at:n.publish_end_at||null,archive_at:n.archive_at||null,hide_from_listings:n.hide_from_listings??!1,is_display_slide:n.is_display_slide??!1,exclude_from_attention:n.exclude_from_attention??!1,follow_up_type:n.follow_up_type||"none",follow_up_date:n.follow_up_date||null,image_url:n.image_url||null},$s(n.meta_description||""),hs(n.image_focus_point||"50% 50%"),n.layout_data){const A=n.layout_data;A.eventDate&&Zt(new Date(A.eventDate)),es(A.eventTime||""),ts(A.eventEndTime||""),ss(A.eventLocation||""),rs(A.eventAddress||""),as(A.imagePosition||"right")}const{data:ne,error:ae}=await I.from("article_images").select("*").eq("article_id",s).order("sort_order",{ascending:!0});!ae&&ne&&Ds(ne);const{data:Ce,error:L}=await I.from("article_tags").select("tag_id").eq("article_id",s);!L&&Ce&&xs(Ce.map(A=>A.tag_id)),t=!0}catch(a){console.error("Error loading article:",a),D.error("Kunne ikke laste artikkel")}finally{v(!1);const a=M.current;a!==null&&t&&(M.current=null,window.setTimeout(()=>{window.scrollTo({top:a,left:0,behavior:"auto"}),c(h.pathname,{replace:!0,state:{}})},0))}},or=t=>(t==null?void 0:t.code)==="23505"&&((t==null?void 0:t.message)||"").includes("articles_slug_key"),cr=(t,a)=>{var n;const u=`${t}-${new Date().getFullYear()}`;xe(`URL-en «${t}» er allerede i bruk av en annen artikkel. Velg en annen URL-slug, for eksempel «${u}».`),a||D.error("URL-slug er allerede i bruk",{description:`«${t}» finnes fra før. Endre URL-slug og lagre pÃ¥ nytt.`}),(n=document.getElementById("slug"))==null||n.scrollIntoView({behavior:"smooth",block:"center"})},Se=async(t,a=!1)=>{var u;if(is.current){if(a)return;D.info("En lagring pÃ¥gÃ¥r allerede â prøv igjen om et øyeblikk");return}if(!f||!g){a||D.error("Tittel og innhold er pÃ¥krevd");return}if(!P){a||D.error("Du mÃ¥ velge en kategori før du kan lagre");return}if(ps&&(t==="published"||t==="pending_review")){const n=Aa(zt,sr);if(n.length>0){a||D.error(`Magasinsjekklisten mangler: ${n.join(", ")}`);return}}if(Or({status:t,silent:a,images:se})){D.error("Artikkelen har bilder som venter pÃ¥ rettighetsgodkjenning fra Webredaktør DNFO. Fjern bildene eller vent pÃ¥ godkjenning.");return}is.current=!0,C(!0);try{const n=await Cs(),w=se.find(L=>
1L.is_featured),B=t==="pending_review",ne={title:f,slug:ge,excerpt:le,subtitle:i||null,byline:l,content:g,image_url:(w==null?void 0:w.image_url)||window.__tempImageUrl||F||null,image_alt_text:(w==null?void 0:w.alt_text)||R,image_focus_point:He,category_id:P||null,template_id:Oe||null,status:t,author_id:n,created_at:(Z==null?void 0:Z.toISOString())||new Date().toISOString(),published_at:t==="published"?(V==null?void 0:V.toISOString())||new Date().toISOString():(V==null?void 0:V.toISOString())||null,publish_end_at:(ee==null?void 0:ee.toISOString())||null,archive_at:(O==null?void 0:O.toISOString())||null,show_date:Dt,show_category:Tt,hide_from_listings:Ft,is_display_slide:d||y==="editor_dnfo"?Pt:!1,display_slide_mandatory:(d||y==="editor_dnfo")&&Pt&&Jr,exclude_from_attention:Qt,meta_description:Ot||null,layout_data:{eventDate:(re==null?void 0:re.toISOString())||null,eventTime:mt||null,eventEndTime:gt||null,eventLocation:ht||null,eventAddress:xt||null,imagePosition:pt},follow_up_type:be,follow_up_date:be==="date"&&Le?Le.toISOString().split("T")[0]:null,follow_up_interval_months:be==="interval"?us:null,follow_up_note:be!=="none"&&ms||null,follow_up_assignee_id:be!=="none"?gs:null,...t==="pending_review"&&(!qs||W!=="pending_review")&&{submitted_at:new Date().toISOString()},...B&&{rejection_reason:null},unpublish_reason:t==="unpublished"?Rt:null,...ps?{magazine_checklist:zt}:{}};let ae=s;if(s){const L=await I.from("articles").update(ne).eq("id",s);if(L.error){if(or(L.error)){cr(ne.slug,a);return}throw L.error}xe(null)}else{const L=await I.from("articles").insert([ne]).select().single();if(L.error){if(or(L.error)){cr(ne.slug,a);return}throw L.error}xe(null);const A=L.data;if(A){const oe=A;ae=oe.id;const X=window.scrollY;c(`/admin/articles/edit/${oe.id}`,{replace:!0,state:{restoreScrollY:X}})}}const Ce=!s;if(ae){const L=[],A=async()=>{let te=[];if(!Ce){const{data:T}=await I.from("article_images").select("id, image_url").eq("article_id",ae);te=T||[]}const Ie=(T,Ne)=>({article_id:ae,image_url:T.image_url,alt_text:T.alt_text,caption:T.caption,sort_order:Ne,is_featured:T.is_featured,photographer:T.photographer??null,credit:T.credit??null,copyright:T.copyright??null,source:T.source??null,media_id:T.media_id??null}),de=[...te],fe=T=>{let Ne=de.findIndex(et=>et.id===T.id);if(Ne===-1&&(Ne=de.findIndex(et=>et.image_url===T.image_url)),Ne===-1)return null;const[Ke]=de.splice(Ne,1);return Ke.id},jr=[],Ns=[];se.forEach((T,Ne)=>{const Ke=Ie(T,Ne),et=fe(T);et?jr.push({id:et,row:Ke}):Ns.push(Ke)});const vr=de.map(T=>T.id);vr.length>0&&await I.from("article_images").delete().in("id",vr);for(const{id:T,row:Ne}of jr){const{error:Ke}=await I.from("article_images").update(Ne).eq("id",T);Ke&&console.error("Error updating image:",Ke)}if(Ns.length>0){const{error:T}=await I.from("article_images").insert(Ns);T&&console.error("Error saving images:",T)}const ga=Array.from(new Set(se.map(T=>T.media_id).filter(T=>!!T)));await Promise.all(ga.map(T=>Ba(T,"article",ae)))};L.push(A());const oe=((u=It.current)==null?void 0:u.archive_at)??null,X=(O==null?void 0:O.toISOString())||null,ie=!Ce&&oe!==X?X?"archived":"unarchived":null,Re=ie||(a?"auto_save":t==="draft"||t==="rejected"?"draft":t==="pending_review"?"submitted":"published"),Y=ie==="archived"?`Lagt i nyhetsarkiv (arkiveringsdato ${ue(new Date(X),"dd.MM.yyyy",{locale:ce})})`:ie==="unarchived"?"Hentet ut av nyhetsarkivet (arkiveringsdato fjernet)":null;if(L.push(ua(ae,_.id,Re,Y,!!ie)),js){const te=async()=>{if(Ce||await I.from("article_tags").delete().eq("article_id",ae),ke.length===0)return;const Ie=ke.map(fe=>({article_id:ae,tag_id:fe})),{error:de}=await I.from("article_tags").insert(Ie);de&&console.error("Error saving tags:",de)};L.push(te())}await Promise.all(L)}if(Gr(new Date),os.current=nr(),ae&&!a){const L=!s,A=L?"article_created":t==="pending_review"?"article_submitted":t==="published"?"article_published":t==="unpublished"?"article_unpublished":"article_updated",oe={title:"Tittel",status:"Status",category_id:"Kategori",template_id:"Mal",published_at:"Publiseres",publish_end_at:"Avpubliseres",archive_at:"Nyhetsarkiv",hide_from_listings:"Skjult fra lister",is_display_slide:"Display-slide",exclude_from_attention:"Skjul fra oppmerksomhet",follow_up_type:"Oppfølging",follow_up_date:"Oppfølgingsdato",image_url:"Hovedbilde"},X=(Y,te)=>{var Ie,de;if(te==null||te==="")return"â";if(typeof te=="boolean")return te?"Ja":"Nei";if(Y==="category_id")return((Ie=je.find(fe=>fe.id===te))==null?void 0:Ie.name)||"(kategori)";if(Y==="template_id")return((de=ye.find(fe=>fe.id===te))==null?void 0:de.name)||"(mal)";if(Y==="image_url")return"bilde";if(Y.endsWith("_at")||Y==="follow_up_date")try{return ue(new Date(te),"dd. MMM yyyy",{locale:ce})}catch{return String(te)}return String(te)},Q={title:f,status:t,category_id:P||null,template_id:Oe||null,published_at:(V==null?void 0:V.toISOString())||null,publish_end_at:(ee==null?void 0:ee.toISOString())||null,archive_at:(O==null?void 0:O.toISOString())||null,hide_from_listings:Ft,is_display_slide:Pt,exclude_from_attention:Qt,follow_up_type:be,follow_up_date:Le?Le.toISOString().split("T")[0]:null,image_url:F||null},ie=It.current||{},Re=[];
1if(!L){for(const Y of Object.keys(oe)){const te=ie[Y]??null,Ie=Q[Y]??null,de=fe=>fe instanceof Date?fe.toISOString():fe;de(te)!==de(Ie)&&Re.push({field:Y,label:oe[Y],from:X(Y,te),to:X(Y,Ie)})}It.current=Q}ys(n,A,"article",ae,{title:f,status:t,role:y,auto_approved:y==="editor_region"&&t==="published"&&(ds?K:me),mode:ds?"edit":"new",changes:Re.length>0?Re:void 0}).catch(Y=>console.error("Activity log failed:",Y))}t==="pending_review"?(Qe("pending_review"),Lt(null),(!qs||W!=="pending_review")&&(Gs(new Date().toISOString()),Ss({articleId:ae,eventType:"submitted"}))):t==="draft"&&W!=="rejected"&&Qe("draft"),a||(t==="draft"||t==="rejected"?D.success("Artikkel lagret som utkast"):t==="published"?(Ze?D.success("Artikkel lagt i nyhetsarkiv"):D.success("Artikkel publisert!"),J()):(D.success("Artikkel sendt til godkjenning!"),J()))}catch(n){if(console.error("Error saving article:",n),!a){const w=n==null?void 0:n.message;D.error(w?`Kunne ikke lagre artikkel: ${w}`:"Kunne ikke lagre artikkel")}}finally{is.current=!1,C(!1)}};$t.current=Se;const ks=W==="pending_review",_s=!!s&&H&&ks,ca=async()=>{if(s&&!Or({status:"published",silent:!1,images:se})){Vt(!0);try{await Se("pending_review",!0);const t=await Cs(),a=Ws.trim(),u=new Date().toISOString(),{error:n}=await I.from("articles").update({status:"published",published_at:(V==null?void 0:V.toISOString())||u,reviewed_at:u,rejection_reason:null,approval_feedback:a||null}).eq("id",s);if(n)throw n;const{data:w}=await I.from("articles").select("*").eq("id",s).single();if(w)try{await kr({articleId:s,createdBy:t,changeType:"published",changeSummary:a?`Godkjent og publisert: ${a}`:"Godkjent og publisert",title:w.title,excerpt:w.excerpt,content:w.content,image_url:w.image_url,image_alt_text:w.image_alt_text,image_focus_point:w.image_focus_point,byline:w.byline,layout_data:w.layout_data,template_id:w.template_id,category_id:w.category_id})}catch(B){console.error("Error saving published version:",B)}Ss({articleId:s,eventType:"approved",feedback:a}),await ys(t,"article_published","article",s,{title:f,via:"article_editor",feedback:a||null}),Qe("published"),Lt(null),Hs(a||null),V||ut(new Date),ft(!1),Ys(""),D.success("Artikkel godkjent og publisert!"),J()}catch(t){console.error("Error approving article:",t),D.error("Kunne ikke godkjenne artikkelen")}finally{Vt(!1)}}},da=async()=>{var a;if(!s)return;const t=ls.trim();if(!t){D.error("Du må oppgi en begrunnelse");return}Vt(!0);try{const u=await Cs(),{error:n}=await I.from("articles").update({status:"rejected",rejection_reason:t,reviewed_at:new Date().toISOString()}).eq("id",s);if(n)throw n;try{await kr({articleId:s,createdBy:u,changeType:"rejected",changeSummary:`Avvist: ${t}`,title:f,excerpt:le||null,content:g,image_url:((a=se.find(w=>w.is_featured))==null?void 0:a.image_url)||F,image_alt_text:R||null,byline:l||null,template_id:Oe||null,category_id:P||null})}catch(w){console.error("Error saving rejected version:",w)}Ss({articleId:s,eventType:"rejected",feedback:t}),await ys(u,"article_rejected","article",s,{title:f,reason:t}),Qe("rejected"),Lt(t),jt(!1),Js(""),D.success("Artikkel avvist"),J()}catch(u){console.error("Error rejecting article:",u),D.error("Kunne ikke avvise artikkelen")}finally{Vt(!1)}},ua=async(t,a,u,n=null,w=!1)=>{try{const{data:B}=await I.from("article_versions").select("title, excerpt, content, image_url, image_alt_text, image_focus_point, byline, template_id, category_id, layout_data").eq("article_id",t).order("version_number",{ascending:!1}).limit(1).maybeSingle(),ne=se.find(Q=>Q.is_featured),ae={eventDate:(re==null?void 0:re.toISOString())||null,eventTime:mt||null,eventEndTime:gt||null,eventLocation:ht||null,eventAddress:xt||null,imagePosition:pt};if(B&&!w&&(B.title||"")===(f||"")&&(B.excerpt||"")===(le||"")&&(B.content||"")===(g||"")&&(B.image_url||"")===((ne==null?void 0:ne.image_url)||F||"")&&(B.image_alt_text||"")===((ne==null?void 0:ne.alt_text)||R||"")&&(B.image_focus_point||"")===(He||"")&&(B.byline||"")===(l||"")&&(B.template_id||null)===(Oe||null)&&(B.category_id||null)===(P||null)&&JSON.stringify(B.layout_data||{})===JSON.stringify(ae))return;const Ce=async()=>{var Y;const{data:Q,error:ie}=await I.from("article_versions").select("version_number").eq("article_id",t).order("version_number",{ascending:!1}).limit(1);if(ie)throw ie;return(((Y=Q==null?void 0:Q[0])==null?void 0:Y.version_number)??0)+1};let L=await Ce();const A=ne,oe={article_id:t,version_number:L,title:f,excerpt:le||null,content:g,image_url:(A==null?void 0:A.image_url)||F||null,image_alt_text:(A==null?void 0:A.alt_text)||R||null,image_focus_point:He,byline:l||null,layout_data:ae,template_id:Oe||null,category_id:P||null,created_by:a,change_type:u,change_summary:n};let{error:X}=await I.from("article_versions").insert([oe]);if((X==null?void 0:X.code)==="23505"&&(L=await Ce(),oe.version_number=L,X=(await I.from("article_versions").insert([oe])).error),X)console.error("Error saving version:",X);else{const{data:Q}=await I.from("article_versions").select("id").eq("article_id",t).eq("change_type","auto_save").order("version_number",{ascending:!1}),ie=(Q||[]).slice(5).map(Re=>Re.id);ie.length>0&&await I.from("article_versions").delete().in("id",ie)}}catch(B){console.error("Error saving article version:",B)}},ma=t=>{if(z(t.title),Ue(t.excerpt||""),$(t.content),dt(t.image_url),Pe(t.image_alt_text||""),hs(t.image_focus_point||"50% 50%"),b(t.byline||""),Wt(t.template_id||""),yt(t.category_id||""),t.layout_data){const a=t.layout_data;a.eventDate&&Zt(new Date(a.eventDate)),es(a.eventTime||""),ts(a.eventEndTime||""),ss(a.eventLocation||""),rs(a.eventAddress||""),as(a.imagePosition||"right")}};return m?e.jsx("div",{className:"min-h-screen flex items-center justify-center",children:e.jsx("p",{children:"Laster..."})}):e.jsxs("div",{className:"min-h-screen flex flex-col",children:[e.jsx(_a,{}),e.jsx(La,{}),e.jsx("main",{className:"flex-1 container mx-auto px-4 py-8",children:e.jsxs("div",{className:"max-w-4xl mx-auto",children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsxs(j,{variant:"ghost",onClick:J,children:[e.jsx(Na,{className:"h-4 w-4 mr-2"}),"Tilbake"]}),Os&&e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Sist lagret: ",Os.toLocaleTimeString("nb-NO")]})]}),W==="rejected"&&Bs&&e.jsxs(We,{className:"mb-6 border-destructive bg-destructive/10",children:[e.jsx(rt,{className:"pb-2",children:e.jsxs(at,{className:"text-destructive flex items-center gap-2 text-lg",children:[e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-5 w-5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),e.jsx("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]}),"Artikkelen ble avvist"]})}),e.jsxs(Ye,{children:[e.jsx("p",{className:"text-sm font-medium mb-1",children:"Begrunnelse fra redaktør:"}),e.jsx("p",{className:"text-sm text-muted-foreground whitespace-pre-wrap",children:Bs}),e.jsx("p",{className:"text-sm text-muted-foreground mt-3",children:"Gjør nødvendige endringer og send inn på nytt for godkjenning."})]})]}),Us&&e.jsxs(We,{className:"mb-6 border-green-500 bg-green-50 dark:bg-green-950/20",children:[e.jsx(rt,{className:"pb-2",children:e.jsxs(at,{className:"text-green-700 dark:text-green-400 flex items-center gap-2 text-lg",children:[e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-5 w-5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M22 11.08V12a10 10 0 1 1-5.93-9.14"}),e.jsx("polyline",{points:"22 4 12 14.01 9 11.01"})]}),"Tilbakemelding ved godkjenning"]})}),e.jsx(Ye,{children:e.jsx("p",{className:"text-sm text-green-700 dark:text-green-300 whitespace-pre-wrap",children:Us})})]}),W==="unpublished"&&Rt&&e.jsxs(We,{className:"mb-6 border-amber-500 bg-amber-50 dark:bg-amber-950/20",children:[e.jsx(rt,{className:"pb-2",children:e.jsxs(at,{className:"text-amber-700 dark:text-amber-400 flex items-center gap-2 text-lg",children:[e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-5 w-5",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3"}),e.jsx("path",{d:"M12 9v4"}),e.jsx("path",{d:"M12 17h.01"})]}),"Artikkelen er avpublisert"]})}),e.jsxs(Ye,{children:[e.jsx("p",{className:"text-sm font-medium mb-1",children:"Kommentar fra sentral redaksjon:"}),e.jsx("p",{className:"text-sm text-muted-foreground whitespace-pre-wrap",children:Rt})]})]}),e.jsxs(We,{className:"border-border",children:[e.jsxs(rt,{children:[e.jsx(at,{children:s?"Rediger artikkel":"Ny artikkel"}),e.jsx(Vr,{children:"Fyll ut feltene under for å opprette eller redigere en artikkel"})]}),e.jsxs(Ye,{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{htmlFor:"title",children:"Tittel *"}),e.jsx(dl,{id:"title",value:f,onChange:z,placeholder:"Skriv artikkeltittel...",className:o?"opacity-50 pointer-events-none":""})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{children:"Kategori *"}),e.jsxs(Ee,{open:Fs,onOpenChange:Ps,children:[e.jsx(Ae,{asChild:!0,children:e.jsxs(j,{variant:"outline",role:"combobox","aria-expanded":Fs,className:"w-full justify-between",disabled:o,children:[vt()?lr(vt()):"Velg kategori",e.jsx(Fr,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(De,{className:"w-full p-0",align:"start",children:e.jsxs(_r,{children:[e.jsx(Nr,{placeholder:"Søk etter kategori..."}),e.jsxs(wr,{children:[e.jsx(yr,{children:"Ingen kategorier funnet."}),e.jsx(Sr,{children:St.map(t=>e.jsxs(Cr,{value:`${t.name}`,onSelect:()=>{yt(t.id),Ps(!1)},children:[e.jsx($e,{className:he("mr-2 h-4 w-4",P===t.id?"opacity-100":"opacity-0")}),lr(t)]},t.id))})]})]})})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Kategorien avgjør hvor artikkelen publiseres og hvilken bildebank bildene lagres i. Velg kategori før du legger til bilder."})]}),ps&&e.jsxs("div",{className:"space-y-3 rounded-lg border p-4 bg-muted/40",children:[e.jsxs("div",{children:[e.jsx(p,{children:"Magasinsjekkliste *"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Artikkelen tilhører et magasinnummer. Alle obligatoriske punkter må være huket av før artikkelen kan sendes til godkjenning eller publiseres."})]}),e.jsx("div",{className:"grid gap-2 sm:grid-cols-2",children:wa(sr).map(t=>e.jsxs("label",{className:"flex items-start gap-2 text-sm",children:[e.jsx(tt,{checked:!!zt[t.key],onCheckedChange:a=>rr(u=>({...u,[t.key]:!!a}))}),e.jsxs("span",{className:t.required&&!zt[t.key]?"text-destructive":"",children:[t.label,t.required?" *":""]})]},t.key))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{htmlFor:"slug",children:"URL-slug"}),e.jsx(U,{id:"slug",value:ge,onChange:t=>{Be(t.target.value),we&&xe(null)},placeholder:"artikkel-url",disabled:o,"aria-invalid":!!we,className:we?"border-destructive focus-visible:ring-destructive":""}),we?e.jsx("p",{className:"text-sm font-medium text-destructive",children:we}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"Genereres automatisk fra tittel"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(p,{htmlFor:"subtitle",children:["Undertittel ",e.jsx("span",{className:"text-xs text-muted-foreground font-normal",children:"(valgfritt)"})]}),e.jsx(U,{id:"subtitle",value:i,onChange:t=>x(t.target.value),placeholder:"Kort undertittel som vises under tittelen",disabled:o})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{htmlFor:"excerpt",children:"Sammendrag"}),e.jsx(ul,{id:"excerpt",value:le,onChange:Ue,placeholder:"Kort sammendrag av artikkelen (vises i lister)",rows:4,maxLength:500,className:o?"opacity-50 pointer-events-none":""}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[le.length,"/500 tegn"]}
1),ya(le,g)&&e.jsx("p",{className:"text-sm text-amber-600 dark:text-amber-500",children:"Sammendraget gjentar starten av brødteksten. Det vises derfor ikke pÃ¥ artikkelsiden â bare i lister og søk. Skriv gjerne et eget sammendrag."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{htmlFor:"byline",children:"Byline"}),e.jsx(U,{id:"byline",value:l,onChange:t=>b(t.target.value),placeholder:"F.eks. 'Av forfatternavn'.",disabled:o}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"F.eks. 'Av forfatternavn'. Vises mellom ingress og hovedtekst"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(p,{className:"flex items-center gap-2",children:[e.jsx(Ir,{className:"h-4 w-4"}),"Artikkelmal"]}),e.jsxs(kt,{value:Oe||"inherit",onValueChange:t=>Wt(t==="inherit"?"":t),disabled:o,children:[e.jsx(_t,{children:e.jsx(Nt,{placeholder:"Velg mal..."})}),e.jsxs(wt,{children:[e.jsx(Te,{value:"inherit",children:vs()?`Arv fra kategori (${bs(vs())})`:"Standard mal"}),ye.map(t=>e.jsxs(Te,{value:t.id,className:"group",children:[t.name,t.description&&e.jsxs("span",{className:"text-muted-foreground ml-2 group-focus:text-accent-foreground group-data-[highlighted]:text-accent-foreground",children:["- ",t.description]})]},t.id))]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:_e()?`Bruker mal: ${bs(_e())}`:"Bruker standard mal"}),(f||g)&&e.jsxs(j,{type:"button",size:"sm",onClick:()=>At(!0),className:"h-7 text-xs bg-sky-600 hover:bg-sky-700 text-white",children:[e.jsx(Kt,{className:"h-3 w-3 mr-1"}),"ForhÃ¥ndsvis"]}),ge&&e.jsx(j,{type:"button",size:"sm",variant:"outline",className:"h-7 text-xs ml-2",onClick:async()=>{const t=`https://fxuhdmdgzugofwxmnzsl.supabase.co/functions/v1/share-article/${ge}`;await navigator.clipboard.writeText(t),D.success("Delingslenke kopiert â gir riktig bilde og tittel pÃ¥ Facebook, LinkedIn o.l.")},children:"Kopier delingslenke"})]})]}),(((dr=ye.find(t=>t.id===_e()))==null?void 0:dr.slug)==="two-column"||((ur=ye.find(t=>t.id===_e()))==null?void 0:ur.slug)==="portrait")&&e.jsxs("div",{className:"space-y-4 p-4 bg-primary/5 rounded-lg border border-primary/20",children:[e.jsxs("h3",{className:"font-semibold flex items-center gap-2",children:[e.jsx(Ir,{className:"h-4 w-4"}),((mr=ye.find(t=>t.id===_e()))==null?void 0:mr.slug)==="two-column"?"To-kolonne innstillinger":"Portrett innstillinger"]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{children:"Bildeplassering"}),e.jsxs(kt,{value:pt,onValueChange:t=>as(t),disabled:o,children:[e.jsx(_t,{children:e.jsx(Nt,{})}),e.jsxs(wt,{children:[e.jsx(Te,{value:"right",children:"Høyre side"}),e.jsx(Te,{value:"left",children:"Venstre side"})]})]})]})]}),((gr=ye.find(t=>t.id===_e()))==null?void 0:gr.slug)==="event"&&e.jsxs("div",{className:"space-y-4 p-4 bg-primary/5 rounded-lg border border-primary/20",children:[e.jsxs("h3",{className:"font-semibold flex items-center gap-2",children:[e.jsx(Ge,{className:"h-4 w-4"}),"Arrangementdetaljer"]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{children:"Dato for arrangement"}),e.jsxs(Ee,{children:[e.jsx(Ae,{asChild:!0,children:e.jsxs(j,{variant:"outline",className:he("w-full justify-start text-left font-normal",!re&&"text-muted-foreground"),disabled:o,children:[e.jsx(Ge,{className:"mr-2 h-4 w-4"}),re?ue(re,"PPP",{locale:ce}):e.jsx("span",{children:"Velg dato"})]})}),e.jsx(De,{className:"w-auto p-0",align:"start",children:e.jsx(st,{mode:"single",selected:re||void 0,onSelect:t=>Zt(t||null),initialFocus:!0,className:"pointer-events-auto"})})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(p,{className:"flex items-center gap-1",children:[e.jsx(qt,{className:"h-3 w-3"}),"Starttid"]}),e.jsx(U,{type:"time",value:mt,onChange:t=>es(t.target.value),disabled:o})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(p,{className:"flex items-center gap-1",children:[e.jsx(qt,{className:"h-3 w-3"}),"Sluttid"]}
1),e.jsx(U,{type:"time",value:gt,onChange:t=>ts(t.target.value),disabled:o})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(p,{className:"flex items-center gap-1",children:[e.jsx(Sa,{className:"h-3 w-3"}),"Sted / Lokale"]}),e.jsx(U,{value:ht,onChange:t=>ss(t.target.value),placeholder:"F.eks. Stamhuset, Store sal",disabled:o})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{children:"Adresse (valgfritt)"}),e.jsx(U,{value:xt,onChange:t=>rs(t.target.value),placeholder:"F.eks. Nedre Vollgate 19, Oslo",disabled:o})]})]})]}),e.jsx(Ve,{defaultOpen:!k,children:e.jsxs("div",{className:"pt-4 border-t",children:[e.jsxs(Me,{className:"flex items-center justify-between w-full text-left",children:[e.jsxs("h3",{className:"text-lg font-semibold flex items-center gap-2",children:[e.jsx(ll,{className:"h-4 w-4"}),"Bilder og fokuspunkt"]}),e.jsx(qe,{className:"h-4 w-4 text-muted-foreground transition-transform duration-200 [&[data-state=open]]:rotate-180"})]}),e.jsxs(ze,{className:"space-y-2 pt-4",children:[e.jsx(ml,{articleId:s||null,initialImages:se,onChange:t=>{Ds(t);const a=t.find(u=>u.is_featured)||t[0];dt((a==null?void 0:a.image_url)||""),Pe((a==null?void 0:a.alt_text)||""),a||delete window.__tempImageUrl},fallbackImageUrl:F,fallbackAltText:R,imageFocusPoint:He,categoryId:P||null}),(se.length>0||F)&&e.jsx("div",{className:"mt-4 p-3 bg-muted/50 rounded-lg",children:e.jsx(Ja,{imageUrl:((hr=se.find(t=>t.is_featured))==null?void 0:hr.image_url)||((xr=se[0])==null?void 0:xr.image_url)||F||"",value:He,onChange:hs})})]})]})}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(p,{className:"flex items-center gap-2",children:[e.jsx(Ra,{className:"h-4 w-4"}),"Tagger"]}),js?e.jsxs(e.Fragment,{children:[e.jsxs(Ee,{open:sa,onOpenChange:ra,children:[e.jsx(Ae,{asChild:!0,children:e.jsxs(j,{variant:"outline",role:"combobox",className:"w-full justify-between",disabled:o,children:[ke.length>0?`${ke.length} tagger valgt`:"Velg tagger (valgfritt)",e.jsx(Fr,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(De,{className:"w-full p-0",align:"start",children:e.jsxs(_r,{children:[e.jsx(Nr,{placeholder:"Søk etter tagg..."}),e.jsxs(wr,{children:[e.jsx(yr,{children:"Ingen tagger funnet."}),e.jsx(Sr,{children:fs.map(t=>e.jsxs(Cr,{value:t.name,onSelect:()=>{xs(a=>a.includes(t.id)?a.filter(u=>u!==t.id):[...a,t.id])},children:[e.jsx($e,{className:he("mr-2 h-4 w-4",ke.includes(t.id)?"opacity-100":"opacity-0")}),e.jsx("div",{className:"w-3 h-3 rounded-full mr-2",style:{backgroundColor:t.color}}),t.name]},t.id))})]})]})})]}),ke.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1",children:ke.map(t=>{const a=fs.find(u=>u.id===t);return a?e.jsxs(Fe,{variant:"secondary",className:"gap-1",children:[e.jsx("div",{className:"w-2 h-2 rounded-full",style:{backgroundColor:a.color}}),a.name,e.jsx(bt,{className:"h-3 w-3 cursor-pointer hover:text-destructive",onClick:()=>xs(u=>u.filter(n=>n!==a.id))})]},a.id):null})})]}):e.jsx("div",{className:"flex flex-wrap gap-1",children:ke.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"Ingen tagger"}):ke.map(t=>{const a=fs.find(u=>u.id===t);return a?e.jsxs(Fe,{variant:"secondary",children:[e.jsx("div",{className:"w-2 h-2 rounded-full mr-1",style:{backgroundColor:a.color}}),a.name]},a.id):null})}),e.jsx("p",{className:"text-sm text-muted-foreground",children:js?"Tagger brukes for å fremheve artikler på forsiden og i artikkelblokker":"Kun Webmaster og Webredaktør DNFO kan tilordne tagger"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{children:"Innhold *"}),e.jsx(Fa,{content:g,onChange:$,placeholder:"Skriv artikkelinnhold...",contextCategoryId:P||null})]}),e.jsx("div",{className:"space-y-4 pt-4 border-t",children:e.jsxs(Ve,{children:[e.jsxs(Me,{className:"flex items-center gap-2 text-lg font-semibold hover:text-primary transition-colors",children:[e.jsx(Ca,{className:"h-4 w-4"}),"SEO-innstillinger"]}),e.jsx(ze,{className:"space-y-4 pt-4",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{htmlFor:"meta-description",children:"Meta-beskrivelse"}),e.jsx(ct,{id:"meta-description",value:Ot,onChange:t=>$s(t.target.value),placeholder:"Kort beskrivelse som vises i søkemotorer (anbefalt maks 160 tegn)",rows:3,maxLength:320,disabled:o}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[Ot.length,"/160 tegn (anbefalt)"]})]})})]})}),e.jsx(Ve,{defaultOpen:!k,children:e.jsxs("div",{className:"pt-4 border-t",children:[e.jsxs(Me,{className:"flex items-center justify-between w-full text-left",children:[e.jsxs("h3",{className:"text-lg font-semibold flex items-center gap-2",children:[e.jsx(nl,{className:"h-4 w-4"}),"Visningsinnstillinger"]}),e.jsx(qe,{className:"h-4 w-4 text-muted-foreground transition-transform duration-200"})]}),e.jsxs(ze,{className:"space-y-4 pt-4",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(tt,{id:"show-date",checked:Dt,onCheckedChange:t=>Ls(t),disabled:o}),e.jsx(p,{htmlFor:"show-date",className:"text-sm font-normal cursor-pointer",children:"Vis dato på artikkel"})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(tt,{id:"show-category",checked:Tt,onCheckedChange:t=>Rs(t),disabled:o}),e.jsx(p,{htmlFor:"show-category",className:"text-sm font-normal cursor-pointer",children:"Vis kategori (loge) på artikkel"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(tt,{id:"hide-from-listings",checked:Ft,onCheckedChange:t=>Vs(t),disabled:o}),e.jsx(p,{htmlFor:"hide-from-listings",className:"text-sm font-normal cursor-pointer",children:"Ikke vis i lister"})]}),e.jsx("p",{className:"text-xs text-muted-foreground ml-6",children:"Artikkelen vises kun på logens/kategoriens side, ikke i artikkelmoduler eller andre listevisninger"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(tt,{id:"exclude-from-attention",checked:Qt,onCheckedChange:t=>zs(t),disabled:o}),e.jsx(p,{htmlFor:"exclude-from-attention",className:"text-sm font-normal cursor-pointer",children:"Skjul fra «trenger oppmerksomhet»"})]}),e.jsx("p",{className:"text-xs text-muted-foreground ml-6",children:"Bruk hvis artikkelen bevisst er uten bilde eller andre felter som ellers ville trigget varselet i dashbordet."})]}),(d||y==="editor_dnfo")&&e.jsxs("div",{className:"space-y-1 pt-3 border-t",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(tt,{id:"is-display-slide",checked:Pt,onCheckedChange:t=>Ms(t),disabled:o}),e.jsx(p,{htmlFor:"is-display-slide",className:"text-sm font-normal cursor-pointer",children:"Informasjon fra Ordenen"})]}),e.jsx("p",{className:"text-xs text-muted-foreground ml-6",children:"Artikkelen vises automatisk på alle aktive skjermvisninger i logelokalene (krever at den er publisert)."})]})]})]})}),e.jsx(Ve,{defaultOpen:!k&&be!=="none",children:e.jsxs("div",{className:"pt-4 border-t",children:[e.jsxs(Me,{className:"flex items-center justify-between w-full text-left",children:[e.jsxs("h3",{className:"text-lg font-semibold flex items-center gap-2",children:[e.jsx(Er,{className:"h-4 w-4"}),"Oppfølging",be!=="none"&&e.jsx(Fe,{variant:"secondary",className:"text-xs",children:"Aktiv"})]}),e.jsx(qe,{className:"h-4 w-4 text-muted-foreground transition-transform duration-200"})]}),e.jsx(ze,{className:"pt-4",children:e.jsx(jl,{followUpType:be,followUpDate:Le,followUpIntervalMonths:us,followUpNote:ms,updatedAt:Xt,disabled:o,onFollowUpTypeChange:Xs,onFollowUpDateChange:Qs,onFollowUpIntervalChange:Zs,onFollowUpNoteChange:er,followUpAssigneeId:gs,assignableEditors:aa,canAssign:ar,onFollowUpAssigneeChange:tr})})]})}),e.jsx(Ve,{defaultOpen:!k,children:e.jsxs("div",{className:"pt-4 border-t",children:[e.jsxs(Me,{className:"flex items-center justify-between w-full text-left",children:[e.jsxs("h3",{className:"text-lg font-semibold flex items-center gap-2",children:[e.jsx(Er,{className:"h-4 w-4"}),"Publiseringsinformasjon"]}),e.jsx(qe,{className:"h-4 w-4 text-muted-foreground transition-transform duration-200"})]}),e.jsxs(ze,{className:"space-y-4 pt-4",children:[s&&e.jsx(pl,{status:W,publishEndAt:ee,unpublishReason:Rt,canChangeStatus:["webmaster","editor_dnfo","editor_region","editor_lodge"].includes(pe||""),canPublish:["webmaster","editor_dnfo"].includes(pe||""),onStatusChange:t=>Qe(t),onUnpublishReasonChange:Ks}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{children:"Dato opprettet"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(Ee,{children:[e.jsx(Ae,{asChild:!0,children:e.jsxs(j,{variant:"outline",className:he("flex-1 justify-start text-left font-normal",!Z&&"text-muted-foreground"),disabled:o,children:[e.jsx(Ge,{className:"mr-2 h-4 w-4"}),Z?ue(Z,"PPP 'kl.' HH:mm",{locale:ce}):e.jsx("span",{children:"Velg dato"})]})}),e.jsx(De,{className:"w-auto p-0",align:"start",children:e.jsx(st,{mode:"single",selected:Z||void 0,onSelect:t=>Ct(Bt(t,Z)),initialFocus:!0,className:"pointer-events-auto"})})]}),e.jsx(U,{type:"time",className:"w-32",value:Ut(Z),onChange:t=>Ct(Ht(Z,t.target.value)),disabled:o,"aria-label":"Klokkeslett opprettet"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{children:"Sist endret"}
1),e.jsx(U,{value:Xt?new Date(Xt).toLocaleString("nb-NO"):"Ikke lagret ennå",disabled:!0,className:"bg-muted"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Dette feltet oppdateres automatisk"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{children:"Publiseringsstart"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(Ee,{children:[e.jsx(Ae,{asChild:!0,children:e.jsxs(j,{variant:"outline",className:he("flex-1 justify-start text-left font-normal",!V&&"text-muted-foreground"),disabled:o,children:[e.jsx(Ge,{className:"mr-2 h-4 w-4"}),V?ue(V,"PPP 'kl.' HH:mm",{locale:ce}):e.jsx("span",{children:"Velg dato"})]})}),e.jsx(De,{className:"w-auto p-0",align:"start",children:e.jsx(st,{mode:"single",selected:V||void 0,onSelect:t=>ut(Bt(t,V)),initialFocus:!0,className:"pointer-events-auto"})})]}),e.jsx(U,{type:"time",className:"w-32",value:Ut(V),onChange:t=>ut(Ht(V,t.target.value)),disabled:o,"aria-label":"Klokkeslett publiseringsstart"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Når skal artikkelen publiseres? (dato og klokkeslett)"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{children:"Publiseringsslutt"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(Ee,{children:[e.jsx(Ae,{asChild:!0,children:e.jsxs(j,{variant:"outline",className:he("flex-1 justify-start text-left font-normal",!ee&&"text-muted-foreground"),disabled:o,children:[e.jsx(Ge,{className:"mr-2 h-4 w-4"}),ee?ue(ee,"PPP 'kl.' HH:mm",{locale:ce}):e.jsx("span",{children:"Velg dato (valgfritt)"})]})}),e.jsx(De,{className:"w-auto p-0",align:"start",children:e.jsx(st,{mode:"single",selected:ee||void 0,onSelect:t=>Jt(Bt(t,ee)),initialFocus:!0,className:"pointer-events-auto"})})]}),e.jsx(U,{type:"time",className:"w-32",value:Ut(ee),onChange:t=>Jt(Ht(ee,t.target.value)),disabled:o,"aria-label":"Klokkeslett publiseringsslutt"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Når skal artikkelen skjules? (dato og klokkeslett, valgfritt)"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{children:"Flytt til nyhetsarkiv fra"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(Ee,{children:[e.jsx(Ae,{asChild:!0,children:e.jsxs(j,{variant:"outline",className:he("flex-1 justify-start text-left font-normal",!O&&"text-muted-foreground"),disabled:o,children:[e.jsx(Ge,{className:"mr-2 h-4 w-4"}),O?ue(O,"PPP 'kl.' HH:mm",{locale:ce}):e.jsx("span",{children:"Velg dato (valgfritt)"})]})}),e.jsx(De,{className:"w-auto p-0",align:"start",children:e.jsx(st,{mode:"single",selected:O||void 0,onSelect:t=>Et(Bt(t,O)),initialFocus:!0,className:"pointer-events-auto"})})]}),e.jsx(U,{type:"time",className:"w-32",value:Ut(O),onChange:t=>Et(Ht(O,t.target.value)),disabled:o,"aria-label":"Klokkeslett arkivering"}),O&&e.jsx(j,{type:"button",variant:"ghost",size:"sm",onClick:()=>Et(null),disabled:o,children:"Fjern"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Når denne datoen passerer, fjernes artikkelen fra hovedvisningen og logelistene, men forblir publisert, søkbar og tilgjengelig i nyhetsarkivet."}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Datoen virker kun på publiserte artikler. Velger du «Lagre som utkast», settes artikkelen tilbake til utkast og arkiveringsdatoen får ingen effekt."})]})]})]})]})}),s&&e.jsx(Ve,{defaultOpen:!k||h.hash==="#kommentarer",children:e.jsxs("div",{id:"kommentarer",className:"pt-4 border-t scroll-mt-24",children:[e.jsxs(Me,{className:"flex items-center justify-between w-full text-left",children:[e.jsxs("h3",{className:"text-lg font-semibold flex items-center gap-2",children:[e.jsx(il,{className:"h-4 w-4"}),"Kommentarer"]}),e.jsx(qe,{className:"h-4 w-4 text-muted-foreground transition-transform duration-200"})]}),e.jsx(ze,{className:"pt-4",children:e.jsx(tl,{articleId:s})})]})}),s&&e.jsx(Ve,{defaultOpen:!k,children:e.jsxs("div",{className:"pt-4 border-t",children:[e.jsxs(Me,{className:"flex items-center justify-between w-full text-left",children:[e.jsxs("h3",{className:"text-lg font-semibold flex items-center gap-2",children:[e.jsx(zr,{className:"h-4 w-4"}),"Versjonshistorikk"]}),e.jsx(qe,{className:"h-4 w-4 text-muted-foreground transition-transform duration-200"})]}),e.jsx(ze,{className:"pt-4",children:e.jsx(fl,{articleId:s,onRestore:ma}
1)})]})}),e.jsx("div",{className:he("pt-4",k?"pb-20":"sticky bottom-0 z-30 -mx-6 mt-4 border-t bg-background/95 px-6 py-3 backdrop-blur supports-[backdrop-filter]:bg-background/80"),children:e.jsx("div",{className:he("flex flex-wrap gap-2 w-full items-start",k&&"justify-center"),children:!k&&e.jsxs(e.Fragment,{children:[_s&&e.jsx("div",{className:"w-full rounded-md border border-amber-300 bg-amber-50 px-3 py-2 text-sm text-amber-900 dark:border-amber-700 dark:bg-amber-950/30 dark:text-amber-200",children:"Denne artikkelen venter pÃ¥ godkjenning."}),e.jsxs(j,{onClick:()=>At(!0),disabled:!f||!g,className:"flex-1 bg-sky-600 hover:bg-sky-700 text-white",children:[e.jsx(Kt,{className:"h-4 w-4 mr-2"}),"ForhÃ¥ndsvis"]}),ge&&e.jsx(j,{type:"button",variant:"outline",className:"flex-1",onClick:async()=>{const t=`https://fxuhdmdgzugofwxmnzsl.supabase.co/functions/v1/share-article/${ge}`;await navigator.clipboard.writeText(t),D.success("Delingslenke kopiert â gir riktig bilde og tittel pÃ¥ Facebook, LinkedIn o.l.")},children:"Kopier delingslenke"}),e.jsxs(j,{onClick:()=>Se("draft"),disabled:o||!f||!g,variant:"outline",className:"flex-1",children:[e.jsx(Pr,{className:"h-4 w-4 mr-2"}),o?"Lagrer...":"Lagre som utkast"]}),Mt&&e.jsxs("div",{className:"flex flex-col gap-1 flex-1",children:[e.jsx(j,{onClick:()=>Se(W==="unpublished"?"unpublished":"published"),disabled:o||!f||!g,className:he(W==="unpublished"?"bg-red-600 hover:bg-red-700":Ze?"bg-blue-600 hover:bg-blue-700":"bg-green-600 hover:bg-green-700"),children:W==="unpublished"?e.jsxs(e.Fragment,{children:[e.jsx(Je,{className:"h-4 w-4 mr-2"}),"Avpubliser"]}):Ze?e.jsxs(e.Fragment,{children:[e.jsx(As,{className:"h-4 w-4 mr-2"}),"Lagre i nyhetsarkiv"]}):e.jsxs(e.Fragment,{children:[e.jsx($e,{className:"h-4 w-4 mr-2"}),W==="published"?"Lagre og publiser":"Publiser direkte"]})}),O&&!Ze&&W!=="unpublished"&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["Arkiveres automatisk ",ue(O,"d. MMM yyyy 'kl.' HH:mm",{locale:ce})]})]}),_s&&e.jsxs(e.Fragment,{children:[e.jsxs(j,{onClick:()=>ft(!0),disabled:o||ve||!f||!g,className:"flex-1 bg-green-600 hover:bg-green-700 text-white",children:[e.jsx($e,{className:"h-4 w-4 mr-2"}),"Godkjenn og publiser"]}),e.jsxs(j,{onClick:()=>jt(!0),disabled:o||ve,variant:"outline",className:"flex-1 border-destructive text-destructive hover:bg-destructive/10",children:[e.jsx(bt,{className:"h-4 w-4 mr-2"}),"Avvis"]})]}),!Mt&&!ks&&e.jsxs(j,{onClick:()=>Se("pending_review"),disabled:o||!f||!g,className:"flex-1",children:[e.jsx(Is,{className:"h-4 w-4 mr-2"}),"Send til godkjenning"]}),Mt&&!ks&&e.jsxs(j,{onClick:()=>Se("pending_review"),disabled:o||!f||!g,variant:"outline",className:"flex-1",children:[e.jsx(Is,{className:"h-4 w-4 mr-2"}),"Send til godkjenning"]})]})})})]})]})]})}),k&&e.jsx("div",{className:"fixed bottom-0 left-0 right-0 z-50 border-t bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/80 px-2 py-1.5 safe-area-bottom",children:e.jsxs("div",{className:"grid grid-cols-2 gap-1.5",children:[e.jsx(j,{onClick:()=>At(!0),disabled:!f||!g,variant:"secondary",size:"sm",className:"h-9 w-full px-2.5","aria-label":"ForhÃ¥ndsvis",children:e.jsx(Kt,{className:"h-4 w-4"})}),e.jsxs(j,{onClick:()=>Se("draft"),disabled:o||!f||!g,variant:"outline",size:"sm",className:"h-9 w-full px-2 text-xs",children:[e.jsx(Pr,{className:"h-4 w-4 mr-1"}),o?"Lagrer...":"Utkast"]}),_s?e.jsxs(e.Fragment,{children:[e.jsxs(j,{onClick:()=>ft(!0),disabled:o||ve||!f||!g,size:"sm",className:"h-9 w-full px-2 text-xs bg-green-600 hover:bg-green-700 text-white",children:[e.jsx($e,{className:"h-4 w-4 mr-1"}),"Godkjenn"]}),e.jsxs(j,{onClick:()=>jt(!0),disabled:o||ve,size:"sm",variant:"outline",className:"h-9 w-full px-2 text-xs border-destructive text-destructive",children:[e.jsx(bt,{className:"h-4 w-4 mr-1"}),"Avvis"]})]}):Mt?e.jsx(j,{onClick:()=>Se(W==="unpublished"?"unpublished":"published"),disabled:o||!f||!g,size:"sm",className:he("h-9 w-full px-2 text-xs",W==="unpublished"?"bg-red-600 hover:bg-red-700":Ze?"bg-blue-600 hover:bg-blue-700":"bg-green-600 hover:bg-green-700"),children:W==="unpublished"?e.jsxs(e.Fragment,{children:[e.jsx(Je,{className:"h-4 w-4 mr-1"}),"Avpubliser"]}):Ze?e.jsxs(e.Fragment,{children:[e.jsx(As,{className:"h-4 w-4 mr-1"}),"Arkiver"]}):e.jsxs(e.Fragment,{children:[e.jsx($e,{className:"h-4 w-4 mr-1"}),"Publiser"]})}):e.jsxs(j,{onClick:()=>Se("pending_review"),disabled:o||!f||!g,size:"sm",className:"h-9 w-full px-2 text-xs",children:[e.jsx(Is,{className:"h-4 w-4 mr-1"}),"Godkjenning"]})]})}),e.jsx(lt,{open:Qr,onOpenChange:ft,children:e.jsxs(nt,{children:[e.jsx(it,{children:e.jsx(ot,{children:"Godkjenn og publiser"})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{htmlFor:"approve-feedback",children:"Tilbakemelding til forfatter (valgfritt)"}),e.jsx(ct,{id:"approve-feedback",value:Ws,onChange:t=>Ys(t.target.value),rows:4,placeholder:"F.eks. hva som ble endret eller ros for godt arbeid"})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-4",children:[e.jsx(j,{variant:"outline",onClick:()=>ft(!1),disabled:ve,children:"Avbryt"}),e.jsx(j,{onClick:ca,disabled:ve,className:"bg-green-600 hover:bg-green-700 text-white",children:ve?"Publiserer...":"Godkjenn og publiser"})]})]})}),e.jsx(lt,{open:Zr,onOpenChange:jt,children:e.jsxs(nt,{children:[e.jsx(it,{children:e.jsx(ot,{children:"Avvis artikkel"})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{htmlFor:"reject-reason",children:"Begrunnelse (pÃ¥krevd)"}),e.jsx(ct,{id:"reject-reason",value:ls,onChange:t=>Js(t.target.value),rows:4,placeholder:"Forklar hva som mÃ¥ endres før artikkelen kan godkjennes"})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-4",children:[e.jsx(j,{variant:"outline",onClick:()=>jt(!1),disabled:ve,children:"Avbryt"}),e.jsx(j,{variant:"destructive",onClick:da,disabled:ve||!ls.trim(),children:ve?"Avviser...":"Avvis artikkel"})]})]})}),e.jsx(lt,{open:Yr,onOpenChange:At,children:e.jsxs(nt,{className:"site-preview max-w-6xl max-h-[90vh] overflow-y-auto p-0",children:[e.jsx(it,{className:"p-6 pb-0",children:e.jsxs(ot,{children:["ForhÃ¥ndsvisning",_e(
1)&&e.jsxs("span",{className:"text-sm font-normal text-muted-foreground ml-2",children:["(Mal: ",bs(_e()),")"]})]})}),e.jsx("div",{className:"border-t mt-4",children:e.jsx(Ia,{article:{title:f||"Ingen tittel",subtitle:i||null,content:g,excerpt:le||null,byline:l||null,created_at:(Z==null?void 0:Z.toISOString())||new Date().toISOString(),show_date:Dt,show_category:Tt},images:se.length>0?se:F?[{id:"legacy",image_url:F,alt_text:R||null,caption:null,is_featured:!0}]:[],category:vt()?{name:vt().name,slug:vt().slug}:null,templateSlug:((pr=ye.find(t=>t.id===_e()))==null?void 0:pr.slug)||"standard",layoutConfig:{...((fr=ye.find(t=>t.id===_e()))==null?void 0:fr.layout_config)||{},eventDate:(re==null?void 0:re.toISOString())||null,eventTime:mt||null,eventEndTime:gt||null,eventLocation:ht||null,eventAddress:xt||null,imagePosition:pt},imageFocusPoint:He})})]})}),e.jsx(Ea,{})]})};export{Sn 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.