1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/Kreis4Map-BzlzrI8Z.js","assets/index-CLTM18rh.js","assets/index-DU6AepMQ.css","assets/TileLayer-DpZblqbA.js","assets/Popup-7uc8Qs2p.js","assets/hooks-DsPkwVqL.js"])))=>i.map(i=>d[i]); 2import{r as a,s as d,j as t,_ as Ce}from"./index-CLTM18rh.js";import{CATEGORY_META as oe,CATEGORY_SUBS as M,SUBCATEGORY_META as Ee}from"./Kreis4Map-BzlzrI8Z.js";import{u as Te}from"./AdminContext-B2hLlcqc.js";import{u as De}from"./useTranslating-CBNKkigt.js";import{T as O}from"./TranslateButton-CwJtN3CI.js";import{b as ce}from"./bestaetige-CpNFuPQa.js";import"./TileLayer-DpZblqbA.js";import"./Popup-7uc8Qs2p.js";import"./hooks-DsPkwVqL.js";import"./callTranslate-CSi3EPWY.js";const Be=a.lazy(()=>Ce(()=>import("./Kreis4Map-BzlzrI8Z.js"),__vite__mapDeps([0,1,2,3,4,5])));function Ae(){return t.jsx("svg",{className:"w-4 h-4",fill:"currentColor",viewBox:"0 0 20 20",children:t.jsx("path",{d:"M7 2a2 2 0 110 4 2 2 0 010-4zm6 0a2 2 0 110 4 2 2 0 010-4zM7 8a2 2 0 110 4 2 2 0 010-4zm6 0a2 2 0 110 4 2 2 0 010-4zm-6 6a2 2 0 110 4 2 2 0 010-4zm6 0a2 2 0 110 4 2 2 0 010-4z"})})}const Fe=Object.keys(oe),K=v=>v.toLowerCase().normalize("NFD").replace(/[Ì-ͯ]/g,"").replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"");function qe({slug:v,onSaved:N,onCancel:de}){const{userId:ue,displayName:xe}=Te(),u=!!v,[me,U]=a.useState(u),[g,f]=a.useState(!1),[R,c]=a.useState(null),[x,ge]=a.useState(null),[o,V]=a.useState(""),[q,D]=a.useState(""),[z,G]=a.useState(""),[j,Y]=a.useState(""),[B,A]=a.useState(""),[S,H]=a.useState(""),[J,F]=a.useState(""),[_,W]=a.useState(""),[Z,I]=a.useState(""),{translating:L,busy:P,error:Q,translate:$}=De(),[h,w]=a.useState(""),[p,C]=a.useState(""),[X,ee]=a.useState(!0),[i,b]=a.useState([]),[y,E]=a.useState(null),[he,T]=a.useState(null);function pe(e){if(y===null||y===e){E(null),T(null);return}const s=[...i],[r]=s.splice(y,1);s.splice(e,0,r),b(s),E(null),T(null)}const[be,fe]=a.useState(!1),[te,je]=a.useState(!1),[se,ye]=a.useState(null),[ae,ve]=a.useState(null);function re(e){V(e.title??""),D(e.title_en??""),Y(e.category??""),A(e.subcategory??""),H(e.body??""),F(e.body_en??""),W(e.summary??""),I(e.summary_en??""),w(e.lat!=null?String(e.lat):""),C(e.lng!=null?String(e.lng):""),ee(!!e.is_published),b(Array.isArray(e.images)?e.images:[])}a.useEffect(()=>{u&&d.from("unterwegs_stations").select("*").eq("slug",v).single().then(({data:e,error:s})=>{if(s||!e){c("Station nicht gefunden."),U(!1);return}ge(e.id),G(e.slug),fe(!!e.is_published),e.draft&&typeof e.draft=="object"?(re({...e,...e.draft}),je(!0),ye(e.draft_updated_at??null),ve(e.draft_updated_by_name??null)):re(e),U(!1)})},[v,u]);async function ze(e){const s=(e.name.split(".").pop()||"jpg").toLowerCase(),r=`unterwegs/${z||K(o)||"neu"}/${Date.now()}-${Math.random().toString(36).slice(2)}.${s}`,{data:n,error:m}=await d.storage.from("images").upload(r,e,{contentType:e.type||void 0});if(m||!n){c(`Bild-Upload fehlgeschlagen: ${m?.message??"?"}`);return}const _e=d.storage.from("images").getPublicUrl(n.path).data.publicUrl;b(we=>[...we,{url:_e,alt:null}])}function ne(e){return{slug:e,title:o.trim(),title_en:q.trim()||null,category:j,subcategory:B||null,body:S.trim()||null,body_en:J.trim()||null,summary:_.trim()||null,summary_en:Z.trim()||null,lat:h.trim()?parseFloat(h):null,lng:p.trim()?parseFloat(p):null,images:i,is_published:X}}function le(){const e=(z||K(o)).trim();return!o.trim()||!e?(c("Titel und Slug sind erforderlich."),null):e}async function ie(){c(null);const e=le();if(!e)return;f(!0);const s={...ne(e),draft:null,draft_updated_at:null,draft_updated_by:null,draft_updated_by_name:null},r=u&&x?await d.from("unterwegs_stations").update(s).eq("id",x):await d.from("unterwegs_stations").insert(s);if(f(!1),r.error){c(r.error.message);return}N(e)}async function ke(){c(null);const e=le();if(!e||!x)return;f(!0);const s=await d.from("unterwegs_stations").update({draft:ne(e),draft_updated_at:new Date().toISOString(),draft_updated_by:ue,draft_updated_by_name:xe||null}).eq("id",x);if(f(!1),s.error){c(s.error.message);return}try{const{data:{session:r}}=await d.auth.getSession();fetch("/api/admin/unterwegs-review",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${r?.access_token??""}`},body:JSON.stringify({slug:e})})}catch{}N(e)}async function Ne(){if(!x||!await ce("Entwurf verwerfen und zur publizierten Fassung zurückkehren?"))return;f(!0);const e=await d.from("unterwegs_stations").update({draft:null,draft_updated_at:null,draft_updated_by:null,draft_updated_by_name:null}).eq("id",x);if(f(!1),e.error){c(e.error.message);return}N(z)}async function Se(){if(!u||!x||!await ce("Station wirklich löschen?"))return;const{error:e}=await d.from("unterwegs_stations").delete().eq("id",x);if(e){c(e.message);return}N()}if(me)return t.jsx("p",{className:"text-sm text-zinc-400",children:"Ladenâ¦"});const k=h.trim()&&p.trim()?{slug:z||"neu",title:o||"Vorschau",lat:parseFloat(h),lng:parseFloat(p),categories:j?[j]:[],image:(i.find(e=>e.hero)??i.find(e=>!e.historical)??i[0])?.url??null}:null,l="w-full px-3 py-2 text-sm rounded-lg border border-zinc-200 dark:border-zinc-700 bg-white dark:bg-zinc-900 text-zinc-900 dark:text-white focus:outline-none focus:ring-2 focus:ring-red-500";return t.jsxs("div",{className:"max-w-3xl space-y-5",children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsx("h1",{className:"text-2xl font-bold text-zinc-900 dark:text-white",children:u?"Station bearbeiten":"Neue Station"}),t.jsx("button",{onClick:de,className:"text-sm text-zinc-500 hover:text-zinc-800 dark:hover:text-zinc-200",children:"Abbrechen"})]}),R&&t.jsx("p",{className:"text-sm text-red-600 bg-red-50 dark:bg-red-950/30 px-3 py-2 rounded-lg",children:R}),Q&&t.jsx("p",{className:"text-sm text-amber-700 bg-amber-50 dark:bg-amber-950/30 px-3 py-2 rounded-lg",children:Q}),te&&t.jsxs("p",{className:"text-sm text-sky-800 dark:text-sky-300 bg-sky-50 dark:bg-sky-950/30 border border-sky-200 dark:border-sky-800/50 px-3 py-2 rounded-lg",children:["Ungeprüfter Entwurf",ae?` von ${ae}
2`:"",se?`, ${new Date(se).toLocaleString("de-CH",{dateStyle:"medium",timeStyle:"short"})}`:""," â ","die Website zeigt weiterhin die publizierte Fassung. Mit «Freigeben & publizieren» geht dieser Stand online."]}),t.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[t.jsxs("label",{className:"block",children:[t.jsx("span",{className:"text-xs text-zinc-500",children:"Titel (DE)"}),t.jsx("input",{className:l,value:o,onChange:e=>V(e.target.value)})]}),t.jsxs("label",{className:"block",children:[t.jsx("span",{className:"text-xs text-zinc-500",children:"Titel (EN)"}),t.jsxs("div",{className:"flex gap-1.5",children:[t.jsx("input",{className:l,value:q,onChange:e=>D(e.target.value)}),t.jsx(O,{source:o,variant:"refresh",loading:L==="title",disabled:P,onClick:()=>$("title",o,D)})]})]}),t.jsxs("label",{className:"block",children:[t.jsx("span",{className:"text-xs text-zinc-500",children:"Slug"}),t.jsx("input",{className:l,value:z,onChange:e=>G(e.target.value),placeholder:K(o)})]}),t.jsxs("label",{className:"block",children:[t.jsx("span",{className:"text-xs text-zinc-500",children:"Kategorie"}),t.jsxs("select",{className:l,value:j,onChange:e=>{Y(e.target.value),(M[e.target.value]??[]).includes(B)||A("")},children:[t.jsx("option",{value:"",children:"â keine â"}),Fe.map(e=>t.jsx("option",{value:e,children:oe[e].label},e))]})]}),t.jsxs("label",{className:"block",children:[t.jsx("span",{className:"text-xs text-zinc-500",children:"Unterkategorie"}),t.jsxs("select",{className:l,value:B,onChange:e=>A(e.target.value),disabled:!(M[j]??[]).length,children:[t.jsx("option",{value:"",children:"â keine â"}),(M[j]??[]).map(e=>t.jsx("option",{value:e,children:Ee[e]??e},e))]})]}),t.jsxs("label",{className:"block",children:[t.jsx("span",{className:"text-xs text-zinc-500",children:"Breitengrad (lat)"}),t.jsx("input",{className:l,value:h,onChange:e=>w(e.target.value),placeholder:"47.3777",inputMode:"decimal"})]}),t.jsxs("label",{className:"block",children:[t.jsx("span",{className:"text-xs text-zinc-500",children:"Längengrad (lng)"}),t.jsx("input",{className:l,value:p,onChange:e=>C(e.target.value),placeholder:"8.5236",inputMode:"decimal"})]})]}),t.jsxs("div",{children:[t.jsxs("span",{className:"text-xs text-zinc-500",children:["Standort â auf die Karte klicken, um den Pin zu setzen",h&&p?"":" (noch kein Pin)"]}),t.jsx("div",{className:"mt-1 h-72 rounded-lg overflow-hidden border border-zinc-200 dark:border-zinc-700",children:t.jsx(a.Suspense,{fallback:t.jsx("div",{className:"h-full bg-zinc-100 dark:bg-zinc-800"}),children:t.jsx(Be,{pois:k?[k]:[],center:k?[k.lat,k.lng]:void 0,onPick:(e,s)=>{w(e.toFixed(6)),C(s.toFixed(6))}})})}),(h||p)&&t.jsx("button",{type:"button",onClick:()=>{w(""),C("")},className:"mt-1 text-xs text-zinc-400 hover:text-red-600",children:"Pin entfernen"})]}),t.jsxs("label",{className:"block",children:[t.jsx("span",{className:"text-xs text-zinc-500",children:"Kurztext für virtuellen Rundgang (DE) â 1 Satz"}),t.jsx("textarea",{className:`${l} min-h-[60px]`,value:_,onChange:e=>W(e.target.value),placeholder:"Kurzer Teaser-Satz für den Tour-Modus (leer = automatischer Auszug)"})]}),t.jsxs("label",{className:"block",children:[t.jsxs("span",{className:"text-xs text-zinc-500 flex items-center justify-between gap-2",children:["Kurztext (EN)",t.jsx(O,{source:_,variant:"refresh",loading:L==="summary",disabled:P,onClick:()=>$("summary",_,I)})]}),t.jsx("textarea",{className:`${l} min-h-[60px]`,value:Z,onChange:e=>I(e.target.value)})]}),t.jsxs("label",{className:"block",children:[t.jsx("span",{className:"text-xs text-zinc-500",children:"Text (DE) â Absätze mit Leerzeile trennen"}),t.jsx("textarea",{className:`${l} min-h-[200px] font-mono`,value:S,onChange:e=>H(e.target.value)})]}),t.jsxs("label",{className:"block",children:[t.jsxs("span",{className:"text-xs text-zinc-500 flex items-center justify-between gap-2",children:["Text (EN) â optional",t.jsx(O,{source:S,variant:"refresh",loading:L==="body",disabled:P,onClick:()=>$("body",S,F)})]}),t.jsx("textarea",{className:`${l} min-h-[120px] font-mono`,value:J,onChange:e=>F(e.target.value)})]}),t.jsxs("div",{children:[t.jsx("span",{className:"text-xs text-zinc-500",children:'Bilder â Legende (z.B. Fotograf), Einstiegsbild + âhistorisch" markieren, Reihenfolge per Ziehen'}),t.jsxs("div",{className:"space-y-2 mt-1",children:[i.map((e,s)=>t.jsxs("div",{draggable:!0,onDragStart:()=>E(s),onDragOver:r=>{r.preventDefault(),T(s)},onDrop:()=>pe(s),onDragEnd:()=>{E(null),T(null)},className:`flex items-start gap-3 rounded-lg border border-zinc-200 dark:border-zinc-700 p-2 transition-colors ${he
2===s&&y!==null&&y!==s?"bg-red-50 dark:bg-red-950/20":y===s?"opacity-40":""}`,children:[t.jsx("span",{className:"self-center text-zinc-300 dark:text-zinc-600 cursor-grab active:cursor-grabbing shrink-0",children:t.jsx(Ae,{})}),t.jsx("img",{src:e.url,alt:"",className:"w-20 h-20 rounded object-cover shrink-0"}),t.jsxs("div",{className:"flex-1 min-w-0 space-y-1.5",children:[t.jsx("input",{className:l,placeholder:"Legende, z.B. «Malerstreik 1953 (Foto: Ernst Köhli)» â erscheint unter dem Bild",value:e.alt??"",onChange:r=>b(i.map((n,m)=>m===s?{...n,alt:r.target.value}:n))}),t.jsxs("div",{className:"flex items-center gap-4",children:[t.jsxs("label",{className:"flex items-center gap-1.5 text-xs text-zinc-600 dark:text-zinc-400",children:[t.jsx("input",{type:"checkbox",checked:!!e.hero,onChange:r=>b(i.map((n,m)=>m===s?{...n,hero:r.target.checked}:{...n,hero:!1}))}),"Einstiegsbild"]}),t.jsxs("label",{className:"flex items-center gap-1.5 text-xs text-zinc-600 dark:text-zinc-400",children:[t.jsx("input",{type:"checkbox",checked:!!e.historical,onChange:r=>b(i.map((n,m)=>m===s?{...n,historical:r.target.checked}:n))}),"Historisches Bild (farblich hervorgehoben)"]})]})]}),t.jsx("button",{onClick:()=>b(i.filter((r,n)=>n!==s)),className:"text-zinc-400 hover:text-red-600 text-lg leading-none shrink-0",children:"Ã"})]},s)),t.jsxs("label",{className:"flex items-center justify-center gap-2 h-12 rounded-lg border-2 border-dashed border-zinc-300 dark:border-zinc-600 text-sm text-zinc-400 cursor-pointer hover:border-red-400",children:["+ Bild hinzufügen",t.jsx("input",{type:"file",accept:"image/*",className:"hidden",onChange:e=>{const s=e.target.files?.[0];s&&ze(s),e.target.value=""}})]})]})]}),t.jsxs("label",{className:"flex items-center gap-2 text-sm text-zinc-700 dark:text-zinc-300",children:[t.jsx("input",{type:"checkbox",checked:X,onChange:e=>ee(e.target.checked)}),"Veröffentlicht (auf der Karte sichtbar)"]}),t.jsxs("div",{className:"flex flex-wrap items-center gap-3 pt-2",children:[u&&be?t.jsxs(t.Fragment,{children:[t.jsx("button",{onClick:ke,disabled:g,className:"text-sm font-medium text-zinc-800 dark:text-zinc-100 bg-zinc-100 dark:bg-zinc-800 border border-zinc-300 dark:border-zinc-600 hover:border-sky-400 px-5 py-2 rounded-lg disabled:opacity-50",children:g?"Speichernâ¦":"Als Entwurf speichern"}),t.jsx("button",{onClick:ie,disabled:g,className:"text-sm font-medium text-white bg-red-600 hover:bg-red-700 px-5 py-2 rounded-lg disabled:opacity-50",children:g?"Speichernâ¦":"Freigeben & publizieren"}),te&&t.jsx("button",{onClick:Ne,disabled:g,className:"text-sm text-zinc-500 hover:text-red-600 hover:underline",children:"Entwurf verwerfen"}),t.jsx("p",{className:"w-full text-xs text-zinc-400 dark:text-zinc-500",children:"Beim Speichern als Entwurf werden die anderen Unterwegs-Verantwortlichen per Mail informiert."})]}):t.jsx("button",{onClick:ie,disabled:g,className:"text-sm font-medium text-white bg-red-600 hover:bg-red-700 px-5 py-2 rounded-lg disabled:opacity-50",children:g?"Speichernâ¦":"Speichern"}),u&&t.jsx("button",{onClick:Se,className:"text-sm text-red-600 hover:underline ml-auto",children:"Löschen"})]})]})}export{qe as AdminUnterwegsForm};
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.