1/*! For license information please see 6351.4076aee5.chunk.js.LICENSE.txt */ 2"use strict";(self.webpackChunkfrontend=self.webpackChunkfrontend||[]).push([[6351],{46351:(e,t,a)=>{a.r(t),a.d(t,{default:()=>Y});var s=a(89379),n=a(65043),i=a(79722),r=a(48970),l=a(56328),d=a(69772),c=a(49954),o=a(43118),p=a(47810),m=a(12967),u=a(8567),x=a(91508),h=a(70492),g=a(56362),v=a(25244),j=a(71360),f=a(55731),b=a(25247),k=a(77784);const y=(0,k.A)("octagon-x",[["path",{d:"m15 9-6 6",key:"1uzhvr"}],["path",{d:"M2.586 16.726A2 2 0 0 1 2 15.312V8.688a2 2 0 0 1 .586-1.414l4.688-4.688A2 2 0 0 1 8.688 2h6.624a2 2 0 0 1 1.414.586l4.688 4.688A2 2 0 0 1 22 8.688v6.624a2 2 0 0 1-.586 1.414l-4.688 4.688a2 2 0 0 1-1.414.586H8.688a2 2 0 0 1-1.414-.586z",key:"2d38gg"}],["path",{d:"m9 9 6 6",key:"z0biqf"}]]);var N=a(7118),_=a(87147),w=a(72313),A=a(35087),C=a(22024),S=a(88306),L=a(94651),K=a(7104),$=a(65505),z=a(9855),O=a(76245);const J=(0,k.A)("image-plus",[["path",{d:"M16 5h6",key:"1vod17"}],["path",{d:"M19 2v6",key:"4bpg5p"}],["path",{d:"M21 11.5V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h7.5",key:"1ue2ih"}],["path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21",key:"1xmnt7"}],["circle",{cx:"9",cy:"9",r:"2",key:"af1f0g"}]]);var E=a(51884),D=a(76833);const P=(0,k.A)("circle-arrow-up",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m16 12-4-4-4 4",key:"177agl"}],["path",{d:"M12 16V8",key:"1sbj14"}]]);var T=a(37475);const B=(0,k.A)("monitor",[["rect",{width:"20",height:"14",x:"2",y:"3",rx:"2",key:"48i651"}],["line",{x1:"8",x2:"16",y1:"21",y2:"21",key:"1svkeh"}],["line",{x1:"12",x2:"12",y1:"17",y2:"21",key:"vw1qmm"}]]);var F=a(46963),M=a(92258),I=a(70579);const U="https://travelease.ai";const R={draft:"bg-slate-200 text-slate-700",published:"bg-emerald-600 text-white",unpublished:"bg-amber-500 text-white",cancelled:"bg-red-600 text-white"},G={confirmed:"bg-emerald-100 text-emerald-700",waitlist:"bg-amber-100 text-amber-700",cancelled:"bg-slate-100 text-slate-500",rejected:"bg-red-100 text-red-700",converted:"bg-blue-100 text-blue-700"},V={web:"Nett",telefon:"Telefon",epost:"E-post",annet:"Annet"},H={person:"Privatperson",gruppe:"Gruppe",selskap:"Selskap"};const Q={title:"",description:"",price_per_seat:0,currency:"NOK",capacity:30,signup_type:"interest",max_seats_per_signup:8,signup_deadline:"",trip_date:"",departure_time:"",from_location:"",to_location:"",trip_number:"",min_signups:"",pricing_mode:"per_person",price_note:""},q=["transport","overnatting","maltider"],W=e=>(Number(e)||0).toLocaleString("nb-NO");function X(e){let{t:t}=e;const a=Number(t.min_signups);if(!t.min_signups||!a||a<=0)return null;const s=Number(t.confirmed_seats||0),n=s>=a;return(0,I.jsx)(u.E,{"data-testid":"open-trip-min-status-".concat(t.id),className:n?"bg-emerald-100 text-emerald-700":"bg-amber-100 text-amber-700",children:n?"Klar (".concat(s,"/").concat(a,")"):"Under minimum (".concat(s,"/").concat(a,")")})}function Y(){const[e,t]=(0,n.useState)(!1),[a,r]=(0,n.useState)(180),[p,m]=(0,n.use
2State)(!1),[h,k]=(0,n.useState)(""),[O,J]=(0,n.useState)([]),[E,D]=(0,n.useState)(!0),[P,T]=(0,n.useState)(null),[B,F]=(0,n.useState)(null),[M,G]=(0,n.useState)(null),[V,H]=(0,n.useState)(null),[q,W]=(0,n.useState)(null),[Y,se]=(0,n.useState)(null),ie=(0,n.useCallback)(async()=>{try{const e=await i.A.get("".concat(U,"/api/admin/open-trips/settings"));t(!!e.data.enabled),r(e.data.retention_days||180),m(!!e.data.catalog_enabled),k(e.data.catalog_url||"")}catch(e){}},[]),re=(0,n.useCallback)(async()=>{D(!0);try{const e=await i.A.get("".concat(U,"/api/admin/open-trips"));J(e.data.open_trips||[])}catch(e){l.toast.error("Kunne ikke laste \xe5pne turer")}D(!1)},[]),le=(0,n.useCallback)(async()=>{try{const e=await i.A.get("".concat(U,"/api/admin/open-trips/stats"));W(e.data)}catch(e){}},[]);(0,n.useEffect)(()=>{ie(),re(),le()},[ie,re,le]);const de=(e,t)=>{navigator.clipboard.writeText(e).then(()=>l.toast.success(t))},ce=h?'<iframe src="'.concat(h,'" width="100%" height="900" style="border:0;max-width:1100px" title="Alle turer"></iframe>'):"",oe=async function(e,t){let a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"a4";try{const s=await i.A.get("".concat(U,"/api/admin/open-trips/").concat(e,"/pdf"),{params:"story"===a?{format:"story"}:{},responseType:"blob"}),n=window.URL.createObjectURL(new Blob([s.data],{type:"application/pdf"})),r=document.createElement("a");r.href=n;const l="story"===a?"_story":"";r.download="plakat".concat(l,"_").concat((t||"tur").slice(0,24).replace(/\s+/g,"_"),".pdf"),r.click(),window.URL.revokeObjectURL(n)}catch(s){l.toast.error("Kunne ikke lage PDF")}};return(0,I.jsxs)("div",{className:"space-y-6","data-testid":"open-trips-manager",children:[(0,I.jsxs)("div",{className:"flex items-center justify-between flex-wrap gap-3",children:[(0,I.jsxs)("div",{children:[(0,I.jsxs)("h1",{className:"text-2xl font-bold text-slate-900 flex items-center gap-2",children:[(0,I.jsx)(v.A,{className:"w-6 h-6 text-emerald-600"})," \xc5pne turer"]}),(0,I.jsx)("p",{className:"text-sm text-muted-foreground",children:"Publiser turer med offentlig p\xe5melding: dagsturer, arrangement og sightseeing. Ingen betaling p\xe5 nett."})]}),e&&(0,I.jsxs)(d.$,{onClick:()=>T((0,s.A)({},Q)),"data-testid":"open-trip-new-btn",children:[(0,I.jsx)(j.A,{className:"w-4 h-4 mr-1"})," Ny \xe5pen tur"]})]}),(0,I.jsxs)("div",{className:"rounded-xl border bg-white p-4 flex flex-wrap items-center gap-4","data-testid":"open-trips-settings",children:[(0,I.jsxs)("label",{className:"flex items-center gap-3",children:[(0,I.jsx)(x.d,{checked:e,onCheckedChange:async e=>{t(e);try{await i.A.put("".concat(U,"/api/admin/open-trips/settings"),{enabled:e}),l.toast.success(e?"\xc5pne turer aktivert":"\xc5pne turer deaktivert"),window.dispatchEvent(new Event("tenant-refresh"))}catch(a){l.toast.error("Kunne ikke oppdatere"),t(!e)}},"data-testid":"open-trips-enabled-switch"}),(0,I.jsxs)("span",{className:"text-sm font-medium",children:[e?"Aktivert":"Deaktivert"," for offentlig p\xe5melding"]})]}),e&&(0,I.jsxs)("div",{className:"flex items-center gap-2 text-sm",children:[(0,I.jsx)("span",{className:"text-muted-foreground",children:"Slett deltakerdata"}),(0,I.jsx)(c.p,{type:"number",className:"w-20 h-8",value:a,onChange:e=>r(Number(e.target.value)||180),"data-testid":"open-trips-retention-input"}),(0,I.jsx)("span",{className:"text-muted-foreground",children:"dager etter turdato"}),(0,I.jsx)(d.$,{size:"sm",variant:"outline",onClick:async()=>{try{await i.A.put("".concat(U,"/api/admin/open-trips/settings"),{retention_days:a}),l.toast.success("Lagringstid oppdatert")}catch(e){l.toast.error("Kunne ikke oppdatere")}},"data-testid":"open-trips-retention-save",children:"Lagre"})]})]}),e&&q&&(0,I.jsx)("div",{className:"grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-5 gap-3","data-testid":"open-trips-stats",children:[{key:"active",label:"Aktive",value:q.active,icon:f.A,cls:"text-emerald-600"},{key:"completed",label:"Gjennomf\xf8rte",value:q.completed,icon:b.A,cls:"text-blue-600"},{key:"cancelled",label:"Avlyste",value:q.cancelled,icon:y,cls:"text-red-600"},{key:"signups",label:"Totalt p\xe5meldte",value:q.total_signups,icon:N.A,cls:"text-slate-700"},{key:"fill",label:"Fyllingsgrad",value:"".concat(q.avg_fill_rate,"%"),icon:_.A,cls:"text-amber-600"}].map(e=>(0,I.jsxs)("div",{className:"rounded-xl border bg-white p-3.5","data-testid":"open-trips-stat-".concat(e.key),children:[(0,I.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[n.createElement(e.icon,{className:"w-3.5 h-3.5 ".concat(e.cls)}),e.label]}),(0,I.jsx)("div",{className:"text-2xl font-bold text-slate-900 mt-1",children:e.value})]},e.key))}),e&&(0,I.jsxs)("div",{className:"rounded-xl border bg-white p-4 space-y-3","data-testid":"open-trips-catalog-settings",children:[(0,I.jsxs)("div",{className:"flex items-center justify-between flex-wrap gap-3",children:[(0,I.jsxs)("div",{children:[(0,I.jsxs)("h2",{className:"text-sm font-semibold flex items-center gap-2",children:[(0,I.jsx)(f.A,{className:"w-4 h-4 text-emerald-600"})," Publiser p\xe5 egen nettside"]}),(0,I.jsx)("p",{className:"text-xs text-muted-foreground",children:"\xc9n s
2amlet \xabAlle turer\xbb-side med alle publiserte turer. Del lenken eller bygg den inn p\xe5 nettsiden din."})]}),(0,I.jsxs)("label",{className:"flex items-center gap-2",children:[(0,I.jsx)(x.d,{checked:p,onCheckedChange:async e=>{try{const t=await i.A.post("".concat(U,"/api/admin/open-trips/catalog/").concat(e?"enable":"disable"));m(e),e&&t.data.catalog_url&&k(t.data.catalog_url),l.toast.success(e?"Katalog aktivert":"Katalog deaktivert")}catch(t){l.toast.error("Kunne ikke oppdatere"),m(!e)}},"data-testid":"open-trips-catalog-switch"}),(0,I.jsx)("span",{className:"text-sm font-medium",children:p?"Aktivert":"Deaktivert"})]})]}),p&&h&&(0,I.jsxs)("div",{className:"space-y-3 pt-1 border-t",children:[(0,I.jsxs)("div",{children:[(0,I.jsx)(o.J,{className:"text-xs",children:"Offentlig katalog-lenke"}),(0,I.jsxs)("div",{className:"flex gap-2 mt-1",children:[(0,I.jsx)(c.p,{readOnly:!0,value:h,className:"font-mono text-xs","data-testid":"open-trips-catalog-url"}),(0,I.jsx)(d.$,{variant:"outline",size:"icon",onClick:()=>de(h,"Lenke kopiert"),"data-testid":"open-trips-catalog-copy-url",children:(0,I.jsx)(w.A,{className:"w-4 h-4"})}),(0,I.jsx)(d.$,{variant:"outline",size:"icon",onClick:()=>window.open(h,"_blank"),"data-testid":"open-trips-catalog-open",children:(0,I.jsx)(A.A,{className:"w-4 h-4"})})]}),(0,I.jsx)("p",{className:"text-[11px] text-muted-foreground mt-1",children:"Slik limer du det inn: del lenken direkte, eller bruk iframe-koden under p\xe5 nettsiden din."})]}),(0,I.jsxs)("div",{children:[(0,I.jsx)(o.J,{className:"text-xs",children:"Bygg inn katalogen (iframe)"}),(0,I.jsxs)("div",{className:"flex gap-2 mt-1",children:[(0,I.jsx)(c.p,{readOnly:!0,value:ce,className:"font-mono text-[10px]","data-testid":"open-trips-catalog-embed"}),(0,I.jsx)(d.$,{variant:"outline",size:"icon",onClick:()=>de(ce,"Embed-kode kopiert"),"data-testid":"open-trips-catalog-copy-embed",children:(0,I.jsx)(w.A,{className:"w-4 h-4"})})]})]})]})]}),e?E?(0,I.jsx)("div",{className:"py-10 flex justify-center",children:(0,I.jsx)(C.A,{className:"w-6 h-6 animate-spin text-muted-foreground"})}):0===O.length?(0,I.jsx)("div",{className:"rounded-xl border border-dashed p-10 text-center text-muted-foreground",children:"Ingen \xe5pne turer enn\xe5. Opprett den f\xf8rste!"}):(0,I.jsx)("div",{className:"grid gap-3",children:O.map(e=>(0,I.jsxs)("div",{className:"rounded-xl border bg-white p-4 flex flex-wrap items-center gap-4","data-testid":"open-trip-card-".concat(e.id),children:[(0,I.jsxs)("div",{className:"flex-1 min-w-[200px]",children:[(0,I.jsxs)("div",{className:"flex items-center gap-2 flex-wrap",children:[(0,I.jsx)("span",{className:"font-semibold text-slate-900",children:e.title}),(0,I.jsx)(u.E,{className:R[e.status],"data-testid":"open-trip-status-".concat(e.id),children:"published"===e.status?"Publisert":"unpublished"===e.status?"Avpublisert":"cancelled"===e.status?"Avlyst":"Utkast"}),(0,I.jsx)(u.E,{variant:"outline",children:"binding"===e.signup_type?"Bindende":"Uforpliktende"}),(0,I.jsx)(X,{t:e})]}),(0,I.jsxs)("p",{className:"text-sm text-muted-foreground mt-1 flex items-center gap-3 flex-wrap",children:[(0,I.jsxs)("span",{className:"flex items-center gap-1",children:[(0,I.jsx)(N.A,{className:"w-3.5 h-3.5"}),e.confirmed_seats,"/",e.capacity," seter"]}),e.waitlist_count>0&&(0,I.jsxs)("span",{className:"text-amber-600",children:[e.waitlist_count," p\xe5 venteliste"]}),e.trip_date&&(0,I.jsx)("span",{children:e.trip_date}),e.price_per_seat>0&&(0,I.jsxs)("span",{children:[e.price_per_seat," ",e.currency]})]}),"cancelled"===e.status&&e.cancel_reason&&(0,I.jsxs)("p",{className:"text-xs text-red-600 mt-1","data-testid":"open-trip-cancel-reason-text-".concat(e.id),children:["Avlyst: ",e.cancel_reason]})]}),(0,I.jsxs)("div",{className:"flex gap-1 flex-wrap",children:[(0,I.jsxs)(d.$,{size:"sm",variant:"outline",onClick:()=>G(e.id),"data-testid":"open-trip-participants-btn-".concat(e.id),children:[(0,I.jsx)(N.A,{className:"w-4 h-4 mr-1"}),"Deltakere (",e.signup_count,")"]}),"published"===e.status&&(0,I.jsxs)(d.$,{size:"sm",variant:"outline",onClick:()=>F({id:e.id}),"data-testid":"open-trip-share-btn-".concat(e.id),children:[(0,I.jsx)(S.A,{className:"w-4 h-4 mr-1"}),"Del"]}),"published"===e.status?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(d.$,{size:"sm",variant:"outline",onClick:()=>(async e=>{try{await i.A.post("".concat(U,"/api/admin/open-trips/").concat(e.id,"/unpublish")),l.toast.success("Avpublisert"),re(),le()}catch(t){l.toast.error("Kunne ikke avpublisere")}})(e),"data-testid":"open-trip-unpublish-btn-".concat(e.id),children:[(0,I.jsx)(L.A,{className:"w-4 h-4 mr-1"}),"Avpubliser"]}),(0,I.jsxs)(d.$,{size:"sm",variant:"outline",onClick:()=>se(e),className:"text-red-600 border-red-200 hover:bg-red-50","data-testid":"open-trip-cancel-btn-".concat(e.id),children:[(0,I.jsx)(y,{className:"w-4 h-4 mr-1"}),"Avlys"]})]}):"cancelled"!==e.status?(0,I.jsxs)(d.$,{size:"sm",variant:"outline",onClick:()=>(async e=>{try{const t=await i.A.post("".concat(U,"/api/admin/open-trips/").concat(e.id,"/publish"));l.toast.success("Publisert"),await re(),le(),F({id:e.id,public_url:t.data.public_url})}catch(t){l.toast.error("Kunne ikke publisere")}})(e),"data-testid":"open-trip-publish-btn-".concat(e.id),children:[(0,I.jsx)(f.A,{className:"w-4 h-4 mr-1"}),"Publiser"]}):null,(0,I.jsxs)(d.$,{size:"sm",variant:"outline",onClick:()=>H(e.id),"data-testid":"open-trip-preview-btn-".concat(e.id),children:[(0,I.jsx)(A.A,{className:"w-4 h-4 mr-1"}),"Forh\xe5ndsvis"]}),(0,I.jsxs)(g.rI,{children:[(0,I.jsx)(g.ty,{asChild:!0,children:(0,I.jsxs)(d.$,{size:"sm",variant:"outline","data-testid":"open-trip-pdf-btn-".concat(e.id),children:[(0,I.jsx)(K.A,{className:"w-4 h-4 mr-1"}),"PDF"]})}),(0,I.jsxs)(g.SQ,{align:"end",children:[(0,I.jsx)(g._2,{onClick:()=>oe(e.id,e.title,"a4"),"data-testid":"open-trip-pdf-a4-".concat(e.id),children:"Flyer (A4)"}),(0,I.jsx)(g._2,{onClick:()=>oe(e.id,e.title,"story"),"data-testid":"open-trip-pdf-story-".concat(e.id),children:"Story (kvadratisk, sosiale medier)"})]})]}),(0,I.jsx)(d.$,{size:"sm",variant:"outline",onClick:()=>T(e),"data-testid":"open-trip-edit-btn-".concat(e.id),children:(0,I.jsx)($.A,{className:"w-4 h-4"})}),(0,I.jsx)(d.$,{size:"sm",variant:"outline",onClick:()=>(async e=>{if(window.confirm("Slette \xab".concat(e.title,"\xbb og alle p\xe5meldinger?")))try{await i.A.delete("".concat(U,"/api/admin/open-trips/").concat(e.id)),l.toast.success("Slettet"),re(),le()}catch(t){l.toast.error("Kunne ikke slette")}})(e),"data-testid":"open-trip-delete-btn-".concat(e.id),children:(0,I.jsx)(z.A,{className:"w-4 h-4 text-red-500"})})]})]},e.id))}):(0,I.jsx)("div",{className:"rounded-xl border border-dashed p-10 text-center text-muted-foreground","data-testid":"open-trips-disabled-hint",children:"Skru p\xe5 \xab\xc5pne turer\xbb for \xe5 opprette og publisere annonser med offentlig p\xe5melding."}),P&&(0,I.jsx)(ee,{trip:P,onClose:()=>T(null),onSaved:()=>{T(null),re(),le()}}),B&&(0,I.jsx)(te,{tripId:B.id,initialUrl:B.public_url,onClose:()=>F(null)}),M&&(0,I.jsx)(ae,{tripId:M,onClose:()=>G(null),onChanged:()=>{re(),le()}}),V&&(0,I.jsx)(ne,{tripId:V,onClose:()=>H(null),onDownloadPdf:oe}),Y&&(0,I.jsx)(Z,{trip:Y,onClose:()=>se(null),onCancelled:()=>{se(null),re(),le()}})]})}function Z(e){let{trip:t,onClose:a,onCancelled:s}=e;
2const[r,c]=(0,n.useState)(""),[m,u]=(0,n.useState)(!1);return(0,I.jsx)(h.lG,{open:!0,onOpenChange:e=>{e||a()},children:(0,I.jsxs)(h.Cf,{className:"max-w-md","data-testid":"open-trip-cancel-dialog",children:[(0,I.jsxs)(h.c7,{children:[(0,I.jsxs)(h.L3,{className:"flex items-center gap-2 text-red-600",children:[(0,I.jsx)(y,{className:"w-5 h-5"})," Avlys tur"]}),(0,I.jsx)(h.rr,{children:"Alle p\xe5meldte (bekreftet + venteliste) varsles med \xe5rsaken. Den offentlige lenken stenges. Dette kan ikke angres."})]}),(0,I.jsxs)("div",{className:"space-y-2",children:[(0,I.jsx)(o.J,{className:"text-xs",children:"\xc5rsak til avlysning *"}),(0,I.jsx)(p.T,{rows:3,value:r,onChange:e=>c(e.target.value),placeholder:"F.eks. for f\xe5 p\xe5meldte, sykdom, v\xe6rforhold \u2026","data-testid":"open-trip-cancel-reason"})]}),(0,I.jsxs)(h.Es,{children:[(0,I.jsx)(d.$,{variant:"outline",onClick:a,children:"Avbryt"}),(0,I.jsx)(d.$,{className:"bg-red-600 hover:bg-red-700 text-white",onClick:async()=>{if(r.trim()){u(!0);try{const e=await i.A.post("".concat(U,"/api/admin/open-trips/").concat(t.id,"/cancel"),{reason:r});l.toast.success("Turen er avlyst. ".concat(e.data.notified||0," av ").concat(e.data.recipients||0," p\xe5meldte varslet.")),s()}catch(n){var e,a;l.toast.error((null===n||void 0===n||null===(e=n.response)||void 0===e||null===(a=e.data)||void 0===a?void 0:a.detail)||"Kunne ikke avlyse")}finally{u(!1)}}else l.toast.error("Oppgi en \xe5rsak for avlysningen")},disabled:m||!r.trim(),"data-testid":"open-trip-cancel-confirm",children:m?(0,I.jsx)(C.A,{className:"w-4 h-4 animate-spin"}):"Avlys og varsle"})]})]})})}function ee(e){var t;let{trip:a,onClose:r,onSaved:u}=e;const x=!a.id,[g,v]=(0,n.useState)((0,s.A)((0,s.A)({},Q),a)),[f,b]=(0,n.useState)(function(e){if(Array.isArray(null===e||void 0===e?void 0:e.price_components)&&e.price_components.length)return e.price_components.map(e=>({key:e.key||null,label:e.label,amount:Number(e.amount)||0,included:!!e.included,fixed:q.includes(e.key)}));const t=[{key:"transport",label:"Transport",amount:0,included:!0,fixed:!0},{key:"overnatting",label:"Overnatting",amount:0,included:!0,fixed:!0},{key:"maltider",label:"M\xe5ltider",amount:0,included:!1,fixed:!0}],a=Number(null===e||void 0===e?void 0:e.price_per_seat)||0;return a>0&&(t[0].amount=a),t}
2(a)),[k,y]=(0,n.useState)(!1),[N,_]=(0,n.useState)(!1),[w,A]=(0,n.useState)(a.image_url||null),S=(e,t)=>v(a=>(0,s.A)((0,s.A)({},a),{},{[e]:t})),L=(e,t,a)=>b(n=>n.map((n,i)=>i===e?(0,s.A)((0,s.A)({},n),{},{[t]:a}):n)),K=f.filter(e=>e.included).reduce((e,t)=>e+(Number(t.amount)||0),0);return(0,I.jsx)(h.lG,{open:!0,onOpenChange:e=>{e||r()},children:(0,I.jsxs)(h.Cf,{className:"max-w-xl max-h-[90vh] overflow-y-auto","data-testid":"open-trip-edit-dialog",children:[(0,I.jsx)(h.c7,{children:(0,I.jsx)(h.L3,{children:x?"Ny \xe5pen tur":"Rediger \xe5pen tur"})}),(0,I.jsxs)("div",{className:"space-y-3",children:[(0,I.jsxs)("div",{children:[(0,I.jsx)(o.J,{className:"text-xs",children:"Tittel *"}),(0,I.jsx)(c.p,{value:g.title,onChange:e=>S("title",e.target.value),"data-testid":"open-trip-field-title"})]}),(0,I.jsxs)("div",{children:[(0,I.jsx)(o.J,{className:"text-xs",children:"Beskrivelse"}),(0,I.jsx)(p.T,{rows:3,value:g.description,onChange:e=>S("description",e.target.value),"data-testid":"open-trip-field-desc"})]}),(0,I.jsxs)("div",{className:"grid grid-cols-2 gap-3",children:[(0,I.jsxs)("div",{children:[(0,I.jsx)(o.J,{className:"text-xs",children:"Turdato"}),(0,I.jsx)(c.p,{type:"date",value:(g.trip_date||"").slice(0,10),onChange:e=>S("trip_date",e.target.value),"data-testid":"open-trip-field-date"})]}),(0,I.jsxs)("div",{children:[(0,I.jsx)(o.J,{className:"text-xs",children:"Avreisetid"}),(0,I.jsx)(c.p,{type:"time",value:g.departure_time||"",onChange:e=>S("departure_time",e.target.value),"data-testid":"open-trip-field-time"})]})]}),(0,I.jsxs)("div",{className:"grid grid-cols-2 gap-3",children:[(0,I.jsxs)("div",{children:[(0,I.jsx)(o.J,{className:"text-xs",children:"Fra"}),(0,I.jsx)(c.p,{value:g.from_location,onChange:e=>S("from_location",e.target.value),"data-testid":"open-trip-field-from"})]}),(0,I.jsxs)("div",{children:[(0,I.jsx)(o.J,{className:"text-xs",children:"Til"}),(0,I.jsx)(c.p,{value:g.to_location,onChange:e=>S("to_location",e.target.value),"data-testid":"open-trip-field-to"})]})]}),(0,I.jsxs)("div",{className:"grid grid-cols-2 gap-3",children:[(0,I.jsxs)("div",{children:[(0,I.jsx)(o.J,{className:"text-xs",children:"Kapasitet"}),(0,I.jsx)(c.p,{type:"number",min:1,value:g.capacity,onChange:e=>S("capacity",e.target.value),"data-testid":"open-trip-field-capacity"})]}),(0,I.jsxs)("div",{children:[(0,I.jsx)(o.J,{className:"text-xs",children:"Maks seter/p\xe5melding"}),(0,I.jsx)(c.p,{type:"number",min:1,value:g.max_seats_per_signup,onChange:e=>S("max_seats_per_signup",e.target.value),"data-testid":"open-trip-field-maxseats"})]})]}),(0,I.jsxs)("div",{children:[(0,I.jsx)(o.J,{className:"text-xs",children:"Minimum antall bekreftede plasser (for at turen kj\xf8res)"}),(0,I.jsx)(c.p,{type:"number",min:0,value:null!==(t=g.min_signups)&&void 0!==t?t:"",onChange:e=>S("min_signups",e.target.value),placeholder:"Valgfritt (la st\xe5 tomt for ingen minimum)","data-testid":"open-trip-field-min-signups"}),(0,I.jsx)("p",{className:"text-[11px] text-muted-foreground mt-1",children:"Kun til info. Turen avlyses aldri automatisk. Viser \xabUnder minimum / Klar\xbb p\xe5 turkortet."})]}),(0,I.jsxs)("div",{className:"grid grid-cols-2 gap-3",children:[(0,I.jsxs)("div",{children:[(0,I.jsx)(o.J,{className:"text-xs",children:"P\xe5meldingstype"}),(0,I.jsx)("div",{className:"flex gap-2 mt-1",children:[["interest","Uforpliktende"],["binding","Bindende"]].map(e=>{let[t,a]=e;return(0,I.jsx)("button",{type:"button",onClick:()=>S("signup_type",t),"data-testid":"open-trip-type-".concat(t),className:"flex-1 text-xs rounded-md border px-2 py-1.5 ".concat(g.signup_type===t?"border-emerald-500 bg-emerald-50 text-emerald-700 font-semibold":"text-muted-foreground"),children:a},t)})})]}),(0,I.jsxs)("div",{children:[(0,I.jsx)(o.J,{className:"text-xs",children:"P\xe5meldingsfrist"}),(0,I.jsx)(c.p,{type:"date",value:(g.signup_deadline||"").slice(0,10),onChange:e=>S("signup_deadline",e.target.value),"data-testid":"open-trip-field-deadline"})]})]}),(0,I.jsxs)("div",{className:"rounded-lg border p-3 space-y-3","data-testid":"open-trip-price-section",children:[(0,I.jsxs)("div",{className:"flex items-center justify-between flex-wrap gap-2",children:[(0,I.jsx)(o.J,{className:"text-sm font-semibold",children:"Pris"}),(0,I.jsx)("div",{className:"flex gap-1",children:[["per_person","Per person"],["per_group","Per gruppe"]].map(e=>
2{let[t,a]=e;return(0,I.jsx)("button",{type:"button",onClick:()=>S("pricing_mode",t),"data-testid":"open-trip-pricing-mode-".concat(t),className:"text-xs rounded-md border px-2 py-1 ".concat((g.pricing_mode||"per_person")===t?"border-emerald-500 bg-emerald-50 text-emerald-700 font-semibold":"text-muted-foreground"),children:a},t)})})]}),(0,I.jsx)("div",{className:"space-y-2",children:f.map((e,t)=>(0,I.jsxs)("div",{className:"flex items-center gap-2","data-testid":"open-trip-price-row-".concat(t),children:[(0,I.jsx)(m.S,{checked:e.included,onCheckedChange:e=>L(t,"included",!!e),"data-testid":"open-trip-price-include-".concat(t)}),e.fixed?(0,I.jsx)("span",{className:"flex-1 text-sm",children:e.label}):(0,I.jsx)(c.p,{value:e.label,onChange:e=>L(t,"label",e.target.value),placeholder:"Navn (f.eks. Inngang)",className:"flex-1 h-8","data-testid":"open-trip-price-label-".concat(t)}),(0,I.jsxs)("div",{className:"relative w-28",children:[(0,I.jsx)(c.p,{type:"number",min:0,value:e.amount,onChange:e=>L(t,"amount",e.target.value),className:"h-8 pr-7","data-testid":"open-trip-price-amount-".concat(t)}),(0,I.jsx)("span",{className:"absolute right-2 top-1.5 text-xs text-muted-foreground",children:"kr"})]}),!e.fixed&&(0,I.jsx)("button",{type:"button",onClick:()=>(e=>b(t=>t.filter((t,a)=>a!==e)))(t),"data-testid":"open-trip-price-remove-".concat(t),className:"text-slate-400 hover:text-red-500",children:(0,I.jsx)(O.A,{className:"w-4 h-4"})})]},t))}),(0,I.jsx)("p",{className:"text-[11px] text-muted-foreground",children:"M\xe5ltider: oppgi bel\xf8p for valgt pensjon (full/halv/frokost), eller la st\xe5 av."}),(0,I.jsxs)(d.$,{type:"button",variant:"outline",size:"sm",onClick:()=>b(e=>[...e,{key:null,label:"",amount:0,included:!0,fixed:!1}]),"data-testid":"open-trip-price-add",children:[(0,I.jsx)(j.A,{className:"w-3.5 h-3.5 mr-1"}),"Legg til priskomponent"]}),(0,I.jsxs)("div",{className:"flex items-center justify-between border-t pt-2",children:[(0,I.jsxs)("span",{className:"text-sm font-semibold",children:["Totalpris ","per_group"===(g.pricing_mode||"per_person")?"per gruppe":"per person"]}),(0,I.jsxs)("span",{className:"text-base font-bold text-emerald-700","data-testid":"open-trip-price-total",children:[W(K)," ",g.currency||"NOK"]})]}),(0,I.jsxs)("div",{children:[(0,I.jsx)(o.J,{className:"text-xs",children:"Prisnotat (valgfritt)"}),(0,I.jsx)(c.p,{value:g.price_note||"",onChange:e=>S("price_note",e.target.value),placeholder:"F.eks. Enkeltromstillegg 400 kr","data-testid":"open-trip-price-note"})]}),(0,I.jsx)("p",{className:"text-[11px] text-muted-foreground",children:"Vises til deltakeren som pris + spesifikasjon. Ingen betaling p\xe5 nett, faktureres etter turen."})]}),(0,I.jsxs)("div",{children:[(0,I.jsx)(o.J,{className:"text-xs",children:"Annonsebilde (valgfritt, maks 2 MB \xb7 JPG/PNG/WebP)"}),(0,I.jsxs)("div",{className:"mt-1 flex items-center gap-3",children:[w&&(0,I.jsx)("img",{src:w,alt:"",className:"h-14 w-24 object-cover rounded-md border"}),(0,I.jsxs)("label",{className:"inline-flex items-center gap-2 text-sm border rounded-md px-3 py-2 cursor-pointer hover:bg-accent","data-testid":"open-trip-image-upload",children:[N?(0,I.jsx)(C.A,{className:"w-4 h-4 animate-spin"}):(0,I.jsx)(J,{className:"w-4 h-4"})," Last opp bilde",(0,I.jsx)("input",{type:"file",accept:"image/png,image/jpeg,image/webp",className:"hidden",onChange:e=>{var t;return(null===(t=e.target.files)||void 0===t?void 0:t[0])&&(async t=>{if(x)l.toast.error("Lagre turen f\xf8rst, deretter last opp bilde");else if(t.size>2097152)l.toast.error("Bildet er for stort (maks 2 MB)");else{_(!0);try{const e=new FormData;e.append("file",t);const s=await i.A.post("".concat(U,"/api/admin/open-trips/").concat(a.id,"/image"),e,{headers:{"Content-Type":"multipart/form-data"}});A(s.data.image_url),l.toast.success("Bilde lastet opp")}catch(e){var s,n;l.toast.error((null===e||void 0===e||null===(s=e.response)||void 0===s||null===(n=s.data)||void 0===n?void 0:n.detail)||"Kunne ikke laste opp bilde")}finally{_(!1)}}})(e.target.files[0])}})]}),x&&(0,I.jsx)("span",{className:"text-xs text-muted-foreground",children:"Lagre f\xf8rst for \xe5 laste opp bilde"})]})]})]}),(0,I.jsxs)(h.Es,{children:[(0,I.jsx)(d.$,{variant:"outline",onClick:r,children:"Avbryt"}),(0,I.jsx)(d.$,{onClick:async()=>
2{if(g.title.trim()){y(!0);try{const e=f.filter(e=>(e.label||"").trim()).map(e=>({key:e.key||void 0,label:e.label,amount:Number(e.amount)||0,included:!!e.included})),t=e.filter(e=>e.included).reduce((e,t)=>e+t.amount,0),s={title:g.title,description:g.description,price_per_seat:t,currency:g.currency||"NOK",capacity:Number(g.capacity)||1,signup_type:g.signup_type,max_seats_per_signup:Number(g.max_seats_per_signup)||8,signup_deadline:g.signup_deadline||null,trip_date:g.trip_date||null,departure_time:g.departure_time||null,from_location:g.from_location,to_location:g.to_location,trip_number:g.trip_number||null,min_signups:""===g.min_signups||null==g.min_signups?null:Number(g.min_signups),price_components:e,pricing_mode:g.pricing_mode||"per_person",price_note:g.price_note||""};x?await i.A.post("".concat(U,"/api/admin/open-trips"),s):await i.A.put("".concat(U,"/api/admin/open-trips/").concat(a.id),s),l.toast.success("Lagret"),u()}catch(e){l.toast.error("Kunne ikke lagre")}finally{y(!1)}}else l.toast.error("Tittel mangler")},disabled:k,"data-testid":"open-trip-save-btn",children:k?(0,I.jsx)(C.A,{className:"w-4 h-4 animate-spin"}):"Lagre"})]})]})})}function te(e){let{tripId:t,initialUrl:a,onClose:s}=e;const[m,u]=(0,n.useState)(a||""),[x,g]=(0,n.useState)(""),[v,j]=(0,n.useState)("");(0,n.useEffect)(()=>{(async()=>{let e=a,s=null;try{var n;s=(await i.A.get("".concat(U,"/api/admin/open-trips/").concat(t))).data.open_trip,e||(e=null===(n=s)||void 0===n?void 0:n.public_url)}catch(l){}
2if(e){u(e);try{g(await r.toDataURL(e,{width:240,margin:1}))}catch(d){}}j(function(e,t){if(!e)return"";let a="";try{a=e.trip_date?new Date(String(e.trip_date).slice(0,10)).toLocaleDateString("nb-NO",{day:"numeric",month:"long",year:"numeric"}):""}catch(d){a=""}const s=[a,e.departure_time?"kl. ".concat(e.departure_time):""].filter(Boolean).join(" \xb7 "),n=[e.from_location,e.to_location].filter(Boolean).join(" \u2192 "),i=(null!=e.price_total?e.price_total:e.price_per_seat)||0,r="per_group"===e.pricing_mode?"per gruppe":"per person",l=i>0?"".concat(Number(i).toLocaleString("nb-NO")," ").concat(e.currency||"NOK"," ").concat(r,", faktureres etter turen"):"Ingen betaling p\xe5 nett";return["\ud83d\ude8c Bli med p\xe5 ".concat(e.title,"!"),s&&"\ud83d\udcc5 ".concat(s),n&&"\ud83d\udccd ".concat(n),"\ud83d\udcba ".concat(l),t&&"\ud83d\udc49 Meld deg p\xe5: ".concat(t)].filter(Boolean).join("\n")}(s,e||""))})()},[t,a]);const f=m?'<iframe src="'.concat(m,'" width="100%" height="720" style="border:0;max-width:560px" title="P\xe5melding"></iframe>'):"",b=(e,t)=>{navigator.clipboard.writeText(e).then(()=>l.toast.success(t))};return(0,I.jsx)(h.lG,{open:!0,onOpenChange:e=>{e||s()},children:(0,I.jsxs)(h.Cf,{className:"max-w-md max-h-[90vh] overflow-y-auto","data-testid":"open-trip-distribute-dialog",children:[(0,I.jsxs)(h.c7,{children:[(0,I.jsxs)(h.L3,{className:"flex items-center gap-2",children:[(0,I.jsx)(S.A,{className:"w-5 h-5 text-emerald-600"})," Del p\xe5meldingslenke"]}),(0,I.jsx)(h.rr,{children:"Kopier lenke, QR-kode, ferdig SoMe-tekst eller iframe-embed for turen."})]}),(0,I.jsxs)("div",{className:"space-y-4",children:[(0,I.jsxs)("div",{children:[(0,I.jsx)(o.J,{className:"text-xs",children:"Offentlig lenke"}),(0,I.jsxs)("div",{className:"flex gap-2 mt-1",children:[(0,I.jsx)(c.p,{readOnly:!0,value:m,className:"font-mono text-xs","data-testid":"open-trip-public-url"}),(0,I.jsx)(d.$,{variant:"outline",size:"icon",onClick:()=>b(m,"Lenke kopiert"),"data-testid":"open-trip-copy-url",children:(0,I.jsx)(w.A,{className:"w-4 h-4"})})]})]}),x&&(0,I.jsxs)("div",{className:"text-center",children:[(0,I.jsx)(o.J,{className:"text-xs block mb-2",children:"QR-kode"}),(0,I.jsx)("img",{src:x,alt:"QR",className:"mx-auto rounded-lg border","data-testid":"open-trip-qr"})]}),(0,I.jsxs)("div",{children:[(0,I.jsx)(o.J,{className:"text-xs",children:"Ferdig tekst for sosiale medier"}),(0,I.jsx)(p.T,{value:v,onChange:e=>j(e.target.value),rows:6,className:"mt-1 text-xs","data-testid":"open-trip-some-text"}),(0,I.jsxs)(d.$,{variant:"outline",size:"sm",className:"mt-2",onClick:()=>b(v,"SoMe-tekst kopiert"),"data-testid":"open-trip-copy-some",children:[(0,I.jsx)(w.A,{className:"w-4 h-4 mr-1"}),"Kopi\xe9r SoMe-tekst"]})]}),(0,I.jsxs)("div",{children:[(0,I.jsx)(o.J,{className:"text-xs",children:"Bygg inn p\xe5 egen nettside (iframe)"}),(0,I.jsxs)("div",{className:"flex gap-2 mt-1",children:[(0,I.jsx)(c.p,{readOnly:!0,value:f,className:"font-mono text-[10px]","data-testid":"open-trip-embed"}),(0,I.jsx)(d.$,{variant:"outline",size:"icon",onClick:()=>b(f,"Embed-kode kopiert"),"data-testid":"open-trip-copy-embed",children:(0,I.jsx)(w.A,{className:"w-4 h-4"})})]})]})]}),(0,I.jsx)(h.Es,{children:(0,I.jsx)(d.$,{variant:"outline",onClick:s,children:"Lukk"})})]})})}function ae(e){let{tripId:t,onClose:a,onChanged:s}=e;const[r,c]=(0,n.useState)(null),[o,p]=(0,n.useState)([]),[m,x]=(0,n.useState)(!0),[g,v]=(0,n.useState)(!1),[j,f]=(0,n.useState)(!1),b=(0,n.useCallback)(async()=>{x(!0);try{const e=await i.A.get("".concat(U,"/api/admin/open-trips/").concat(t));c(e.data.open_trip),p(e.data.signups||[])}catch(e){l.toast.error("Kunne ikke laste deltakere")}x(!1)},[t]);(0,n.useEffect)(()=>{b()},[b]);const k=async(e,a)=>{try{const n=await i.A.post("".concat(U,"/api/admin/open-trips/").concat(t,"/signups/").concat(e.id,"/status"),{action:a});return l.toast.success("Oppdatert"),b(),s(),n.data}catch(d){var n,r;l.toast.error((null===d||void 0===d||null===(n=d.response)||void 0===n||null===(r=n.data)||void 0===r?void 0:r.detail)||"Handlingen feilet")}},y=o.filter(e=>"confirmed"===e.status).length;return(0,I.jsx)(h.lG,{open:!0,onOpenChange:e=>{e||a()},children:(0,I.jsxs)(h.Cf,{className:"max-w-3xl max-h-[90vh] overflow-y-auto","data-testid":"open-trip-participants-dialog",children:[(0,I.jsxs)(h.c7,{children:[(0,I.jsxs)(h.L3,{className:"flex items-center gap-2",children:[(0,I.jsx)(N.A,{className:"w-5 h-5"})," Deltakere ",r?"\xb7 ".concat(r.title):""]}),(0,I.jsx)(h.rr,{children:"Bekreft, avvis, forfrem eller konverter p\xe5meldinger til ekte bookinger."})]}),r&&(0,I.jsxs)("div",{className:"flex items-center gap-3 flex-wrap text-sm text-muted-foreground -mt-2",children:[(0,I.jsxs)("span",{children:[(0,I.jsx)("strong",{children:r.confirmed_seats}),"/",r.capacity," bekreftet"]}),(0,I.jsxs)("span",{children:[r.seats_left," ledig"]}),(0,I.jsx)(X,{t:r}),(0,I.jsxs)("div",{className:"ml-auto flex gap-2 flex-wrap",children:[(0,I.jsxs)(d.$,{size:"sm",variant:"outline",onClick:()=>v(!0),"data-testid":"open-trip-add-participant-btn",children:[(0,I.jsx)(E.A,{className:"w-4 h-4 mr-1"}),"Legg til deltaker"]}
2),y>0&&(0,I.jsxs)(d.$,{size:"sm",variant:"outline",onClick:async()=>{if(window.confirm("Konvertere ".concat(y," bekreftede p\xe5meldinger til bookinger?"))){f(!0);try{var e;const a=await i.A.post("".concat(U,"/api/admin/open-trips/").concat(t,"/convert-all")),n=(null===(e=a.data.errors)||void 0===e?void 0:e.length)||0;l.toast.success("".concat(a.data.converted," konvertert til booking").concat(n?", ".concat(n," feilet"):"")),b(),s()}catch(r){var a,n;l.toast.error((null===r||void 0===r||null===(a=r.response)||void 0===a||null===(n=a.data)||void 0===n?void 0:n.detail)||"Kunne ikke konvertere")}finally{f(!1)}}},disabled:j,className:"text-blue-700 border-blue-200 hover:bg-blue-50","data-testid":"open-trip-convert-all",children:[j?(0,I.jsx)(C.A,{className:"w-4 h-4 mr-1 animate-spin"}):(0,I.jsx)(D.A,{className:"w-4 h-4 mr-1"}),"Konverter alle bekreftede (",y,")"]}),(0,I.jsxs)(d.$,{size:"sm",variant:"outline",onClick:async()=>{try{const e=await i.A.get("".concat(U,"/api/admin/open-trips/").concat(t,"/signups.csv"),{responseType:"blob"}),a=window.URL.createObjectURL(new Blob([e.data])),s=document.createElement("a");s.href=a,s.download="paameldinger.csv",s.click(),window.URL.revokeObjectURL(a)}catch(e){l.toast.error("Kunne ikke eksportere")}},"data-testid":"open-trip-export-csv",children:[(0,I.jsx)(K.A,{className:"w-4 h-4 mr-1"}),"CSV"]})]})]}),g&&r&&(0,I.jsx)(se,{tripId:t,onClose:()=>v(!1),onAdded:()=>{v(!1),b(),s()}}),m?(0,I.jsx)("div",{className:"py-8 flex justify-center",children:(0,I.jsx)(C.A,{className:"w-6 h-6 animate-spin text-muted-foreground"})}):0===o.length?(0,I.jsx)("p",{className:"text-sm text-muted-foreground py-6 text-center",children:"Ingen p\xe5meldinger enn\xe5."}):(0,I.jsx)("div",{className:"mt-3 divide-y border rounded-lg","data-testid":"open-trip-signup-list",children:o.map(e=>{var a,n;return(0,I.jsxs)("div",{className:"p-3 flex items-center gap-3 flex-wrap","data-testid":"open-trip-signup-".concat(e.id),children:[(0,I.jsxs)("div",{className:"flex-1 min-w-[180px]",children:[(0,I.jsxs)("div",{className:"flex items-center gap-2 flex-wrap",children:[(0,I.jsx)("span",{className:"font-medium",children:e.name}),(0,I.jsx)(u.E,{className:G[e.status]||"","data-testid":"open-trip-signup-status-".concat(e.id),children:e.status}),(0,I.jsx)(u.E,{variant:"outline","data-testid":"open-trip-signup-source-".concat(e.id),children:V[e.source]||e.source||"Nett"}),e.party_type&&"person"!==e.party_type&&(0,I.jsx)(u.E,{variant:"outline",className:"bg-slate-100","data-testid":"open-trip-signup-party-".concat(e.id),children:H[e.party_type]||e.party_type}),e.overbooked&&(0,I.jsx)(u.E,{className:"bg-red-100 text-red-700",children:"Overbooket"})]}),(0,I.jsxs)("p",{className:"text-xs text-muted-foreground",children:[e.seats," sete \xb7 ",e.email,e.phone?" \xb7 ".concat(e.phone):""]}),(null===(a=e.invoice_to)||void 0===a?void 0:a.name)&&(0,I.jsxs)("p",{className:"text-xs text-muted-foreground","data-testid":"open-trip-signup-invoice-".concat(e.id),children:["Faktureres til: ",e.invoice_to.name,e.invoice_to.org_number?" (org.nr ".concat(e.invoice_to.org_number,")"):""]}),(null===(n=e.participants)||void 0===n?void 0:n.length)>0&&(0,I.jsxs)("p",{className:"text-xs text-muted-foreground","data-testid":"open-trip-signup-participants-".concat(e.id),children:[e.participants.length," navngitt deltaker",e.participants.length>1?"e":"",": ",e.participants.map(e=>e.name).join(", ")]}),e.booking_id&&(0,I.jsx)("p",{className:"text-xs text-blue-600","data-testid":"open-trip-signup-booking-".concat(e.id),children:"Konvertert til booking"})]}),(0,I.jsxs)("div",{className:"flex gap-1 flex-wrap",children:["waitlist"===e.status&&(0,I.jsxs)(d.$,{size:"sm",variant:"outline",onClick:()=>k(e,"promote"),"data-testid":"open-trip-promote-".concat(e.id),children:[(0,I.jsx)(P,{className:"w-4 h-4 mr-1"}),"Forfrem"]}),("confirmed"===e.status||"waitlist"===e.status)&&(0,I.jsxs)(d.$,{size:"sm",variant:"outline",onClick:()=>k(e,"cancel"),"data-testid":"open-trip-cancel-".concat(e.id),children:[(0,I.jsx)(T.A,{className:"w-4 h-4 mr-1"}),"Avmeld"]}),"rejected"!==e.status&&"converted"!==e.status&&(0,I.jsx)(d.$,{size:"sm",variant:"outline",onClick:()=>k(e,"reject"),"data-testid":"open-trip-reject-".concat(e.id),children:(0,I.jsx)(O.A,{className:"w-4 h-4"})}),"confirmed"===e.status&&(0,I.jsxs)(d.$,{size:"sm",variant:"outline",onClick:()=>(async e=>{try{const a=await i.A.post("".concat(U,"/api/admin/open-trips/").concat(t,"/signups/").concat(e.id,"/convert"));l.toast.success("Booking opprettet (".concat(a.data.booking_number||"",")")),b(),s()}catch(r){var a,n;l.toast.error((null===r||void 0===r||null===(a=r.response)||void 0===a||null===(n=a.data)||void 0===n?void 0:n.detail)||"Kunne ikke konvertere")}})(e),"data-testid":"open-trip-convert-".concat(e.id),children:[(0,I.jsx)(D.A,{className:"w-4 h-4 mr-1"}),"Til booking"]})]})]},e.id)})}),(0,I.jsx)(h.Es,{children:(0,I.jsx)(d.$,{variant:"outline",onClick:a,children:"Lukk"})})]})})}function se(e){let{tripId:t,onClose:a,onAdded:r}=e;
2const[p,u]=(0,n.useState)({name:"",seats:1,phone:"",email:"",message:"",source:"telefon",consent_confirmed:!1,consent_channel:"muntlig",override_capacity:!1,override_reason:"",send_confirmation:!1}),[x,h]=(0,n.useState)(!1),g=(e,t)=>u(a=>(0,s.A)((0,s.A)({},a),{},{[e]:t}));return(0,I.jsxs)("div",{className:"rounded-lg border bg-slate-50 p-4 mt-3 space-y-3","data-testid":"open-trip-manual-add-form",children:[(0,I.jsxs)("div",{className:"grid grid-cols-2 gap-3",children:[(0,I.jsxs)("div",{children:[(0,I.jsx)(o.J,{className:"text-xs",children:"Navn *"}),(0,I.jsx)(c.p,{value:p.name,onChange:e=>g("name",e.target.value),"data-testid":"manual-name"})]}),(0,I.jsxs)("div",{children:[(0,I.jsx)(o.J,{className:"text-xs",children:"Antall seter"}),(0,I.jsx)(c.p,{type:"number",min:1,value:p.seats,onChange:e=>g("seats",e.target.value),"data-testid":"manual-seats"})]}),(0,I.jsxs)("div",{children:[(0,I.jsx)(o.J,{className:"text-xs",children:"Telefon"}),(0,I.jsx)(c.p,{value:p.phone,onChange:e=>g("phone",e.target.value),"data-testid":"manual-phone"})]}),(0,I.jsxs)("div",{children:[(0,I.jsx)(o.J,{className:"text-xs",children:"E-post *"}),(0,I.jsx)(c.p,{value:p.email,onChange:e=>g("email",e.target.value),"data-testid":"manual-email"})]})]}),(0,I.jsxs)("div",{className:"grid grid-cols-2 gap-3",children:[(0,I.jsxs)("div",{children:[(0,I.jsx)(o.J,{className:"text-xs",children:"Kilde"}),(0,I.jsxs)("select",{value:p.source,onChange:e=>g("source",e.target.value),className:"mt-1 w-full h-9 rounded-md border text-sm px-2","data-testid":"manual-source",children:[(0,I.jsx)("option",{value:"telefon",children:"Telefon"}),(0,I.jsx)("option",{value:"epost",children:"E-post"}),(0,I.jsx)("option",{value:"web",children:"Nett"}),(0,I.jsx)("option",{value:"annet",children:"Annet"})]})]}),(0,I.jsxs)("div",{children:[(0,I.jsx)(o.J,{className:"text-xs",children:"Samtykke gitt"}),(0,I.jsxs)("select",{value:p.consent_channel,onChange:e=>g("consent_channel",e.target.value),className:"mt-1 w-full h-9 rounded-md border text-sm px-2","data-testid":"manual-consent-channel",children:[(0,I.jsx)("option",{value:"muntlig",children:"Muntlig"}),(0,I.jsx)("option",{value:"skriftlig",children:"Skriftlig"})]})]})]}),(0,I.jsxs)("label",{className:"flex items-center gap-2 text-sm",children:[(0,I.jsx)(m.S,{checked:p.consent_confirmed,onCheckedChange:e=>g("consent_confirmed",!!e),"data-testid":"manual-consent"})," Kunden har samtykket (dokumenteres med hvem/n\xe5r/kanal)"]}),(0,I.jsxs)("label",{className:"flex items-center gap-2 text-sm",children:[(0,I.jsx)(m.S,{checked:p.override_capacity,onCheckedChange:e=>g("override_capacity",!!e),"data-testid":"manual-overbook"})," Overbook tross full tur (krever begrunnelse)"]}),p.override_capacity&&(0,I.jsx)(c.p,{placeholder:"Begrunnelse for overbooking",value:p.override_reason,onChange:e=>g("override_reason",e.target.value),"data-testid":"manual-overbook-reason"}),(0,I.jsxs)("label",{className:"flex items-center gap-2 text-sm",children:[(0,I.jsx)(m.S,{checked:p.send_confirmation,onCheckedChange:e=>g("send_confirmation",!!e),"data-testid":"manual-send-confirm"})," Send bekreftelse (med avmeldingslenke) hvis leverand\xf8r er satt opp"]}),(0,I.jsxs)("div",{className:"flex gap-2 justify-end",children:[(0,I.jsx)(d.$,{size:"sm",variant:"outline",onClick:a,children:"Avbryt"}),(0,I.jsx)(d.$,{size:"sm",onClick:async()=>{if(p.name.trim()&&p.email.includes("@"))if(p.consent_confirmed)if(!p.override_capacity||p.override_reason.trim()){h(!0);try{const e=await i.A.post("".concat(U,"/api/admin/open-trips/").concat(t,"/signups"),(0,s.A)((0,s.A)({},p),{},{seats:Number(p.seats)||1}));l.toast.success("confirmed"===e.data.status?e.data.overbooked?"Lagt til (overbooket)":"Lagt til og bekreftet":"Lagt til p\xe5 venteliste"),r()}catch(n){var e,a;l.toast.error((null===n||void 0===n||null===(e=n.response)||void 0===e||null===(a=e.data)||void 0===a?void 0:a.detail)||"Kunne ikke legge til")}finally{h(!1)}}else l.toast.error("Overbooking krever begrunnelse");else l.toast.error("Bekreft at kunden har samtykket");else l.toast.error("Fyll inn navn og gyldig e-post")},disabled:x,"data-testid":"manual-submit",children:x?(0,I.jsx)(C.A,{className:"w-4 h-4 animate-spin"}):"Legg til deltaker"})]})]})}function ne(e){let{tripId:t,onClose:a,onDownloadPdf:s}=e;
2const[r,c]=(0,n.useState)(null),[o,p]=(0,n.useState)(""),[m,u]=(0,n.useState)("desktop"),[x,v]=(0,n.useState)(!0);return(0,n.useEffect)(()=>{(async()=>{try{var e;const a=await i.A.get("".concat(U,"/api/admin/open-trips/").concat(t));p((null===(e=a.data.open_trip)||void 0===e?void 0:e.title)||""),c(function(e,t){var a;const s=null!==(a=e.seats_left)&&void 0!==a?a:Math.max(0,(e.capacity||0)-(e.confirmed_seats||0));let n="open";const i=new Date;return i.setHours(0,0,0,0),e.trip_date&&new Date(String(e.trip_date).slice(0,10))<i?n="completed":e.signup_deadline&&new Date(e.signup_deadline)<new Date?n="closed":s<=0&&(n="full"),{state:n,company:t||{},nonce:"preview",trip:{title:e.title,description:e.description,image_url:e.image_url,price_per_seat:e.price_per_seat,currency:e.currency,pricing_mode:e.pricing_mode||"per_person",price_total:e.price_total,price_note:e.price_note||"",price_components:(e.price_components||[]).filter(e=>e.included),seats_left:s,capacity:e.capacity,signup_type:e.signup_type,max_seats_per_signup:e.max_seats_per_signup,signup_deadline:e.signup_deadline,trip_date:e.trip_date,departure_time:e.departure_time,from_location:e.from_location,to_location:e.to_location}}}(a.data.open_trip,a.data.company||{}))}catch(a){l.toast.error("Kunne ikke laste forh\xe5ndsvisning")}v(!1)})()},[t]),(0,I.jsx)(h.lG,{open:!0,onOpenChange:e=>{e||a()},children:(0,I.jsxs)(h.Cf,{className:"sm:max-w-5xl w-[95vw] max-h-[92vh] overflow-hidden p-0 gap-0","data-testid":"open-trip-preview-dialog",children:[(0,I.jsxs)(h.c7,{className:"px-4 py-3 border-b flex-row items-center justify-between space-y-0",children:[(0,I.jsxs)(h.L3,{className:"flex items-center gap-2 text-base",children:[(0,I.jsx)(A.A,{className:"w-5 h-5 text-emerald-600"})," Forh\xe5ndsvisning"]}),(0,I.jsx)(h.rr,{className:"sr-only",children:"Forh\xe5ndsvisning av den offentlige p\xe5meldingssiden. P\xe5melding er deaktivert."}),(0,I.jsxs)("div",{className:"flex items-center gap-2",children:[(0,I.jsxs)("div",{className:"flex rounded-lg border overflow-hidden",children:[(0,I.jsxs)("button",{onClick:()=>u("desktop"),"data-testid":"preview-device-desktop",className:"px-2.5 py-1.5 text-xs flex items-center gap-1 ".concat("desktop"===m?"bg-slate-900 text-white":"text-slate-600"),children:[(0,I.jsx)(B,{className:"w-3.5 h-3.5"}),"Desktop"]}),(0,I.jsxs)("button",{onClick:()=>u("mobile"),"data-testid":"preview-device-mobile",className:"px-2.5 py-1.5 text-xs flex items-center gap-1 ".concat("mobile"===m?"bg-slate-900 text-white":"text-slate-600"),children:[(0,I.jsx)(F.A,{className:"w-3.5 h-3.5"}),"Mobil"]})]}),(0,I.jsxs)(g.rI,{children:[(0,I.jsx)(g.ty,{asChild:!0,children:(0,I.jsxs)(d.$,{size:"sm",variant:"outline","data-testid":"preview-download-pdf",children:[(0,I.jsx)(K.A,{className:"w-4 h-4 mr-1"}),"Last ned PDF"]})}),(0,I.jsxs)(g.SQ,{align:"end",children:[(0,I.jsx)(g._2,{onClick:()=>s(t,o,"a4"),"data-testid":"preview-download-pdf-a4",children:"Flyer (A4)"}),(0,I.jsx)(g._2,{onClick:()=>s(t,o,"story"),"data-testid":"preview-download-pdf-story",children:"Story (kvadratisk, sosiale medier)"})]})]})]})]}),(0,I.jsx)("div",{className:"overflow-y-auto bg-slate-200/60 p-3 sm:p-5",style:{maxHeight:"calc(92vh - 60px)"},children:x||!r?(0,I.jsx)("div",{className:"py-20 flex justify-center",children:(0,I.jsx)(C.A,{className:"w-6 h-6 animate-spin text-muted-foreground"})}):(0,I.jsx)("div",{className:"mx-auto transition-all ".concat("mobile"===m?"w-[400px] max-w-full":"w-full max-w-[1100px]"),children:(0,I.jsx)("div",{className:"rounded-xl overflow-hidden border border-slate-300 shadow-xl bg-white",children:(0,I.jsx)(M.A,{previewData:r,preview:!0})})})})]})})}}}]); 3//# sourceMappingURL=6351.4076aee5.chunk.js.map
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.