1import{c as z,r as f,h as P,b as y,j as e,I as V,B as r,g as O,i as L,H as q,L as w,f as W}from"./index-3i4vAcIn.js";import{u as M}from"./useMutation-Dw1tDgZ2.js";import{F as E}from"./Footer-BCNYpYir.js";import{B as S}from"./badge-ClNjmgRE.js";import{C as m,a as x}from"./card-DvP66V-u.js";import{D as U,a as K,b as B,c as H,d as Q,e as I}from"./dialog-DKQx9gdu.js";import{S as G}from"./StationLogo-BKptkBXo.js";import{T as X}from"./textarea-CjzaujgE.js";import{L as Y}from"./label-DSjkcGsz.js";import{z as h}from"./index-BNcG5vPl.js";import{W as J}from"./wifi-C7jft_Se.js";import{L as Z}from"./loader-circle-jc_7kDnb.js";import{a as $,C as A}from"./circle-x-D_-CmuZa.js";import{C as ee}from"./clock-DWcbD98e.js";import{T as se}from"./triangle-alert-B2nWx7_o.js";/** 2 * @license lucide-react v0.475.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const ae=[["path",{d:"M15 3h6v6",key:"1q9fwt"}],["path",{d:"M10 14 21 3",key:"gplh6r"}],["path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6",key:"a6xqqp"}]],te=z("ExternalLink",ae);/** 7 * @license lucide-react v0.475.0 - ISC 8 * 9 * This source code is licensed under the ISC license. 10 * See the LICENSE file in the root directory of this source tree. 11 */const le=[["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}],["path",{d:"m15 5 4 4",key:"1mk7zo"}]],F=z("Pencil",le);/** 12 * @license lucide-react v0.475.0 - ISC 13 * 14 * This source code is licensed under the ISC license. 15 * See the LICENSE file in the root directory of this source tree. 16 */const ie=[["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6",key:"4alrt4"}],["path",{d:"M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2",key:"v07s0e"}],["line",{x1:"10",x2:"10",y1:"11",y2:"17",key:"1uufr5"}],["line",{x1:"14",x2:"14",y1:"11",y2:"17",key:"xtxkd"}]],D=z("Trash2",ie),T=[{key:"name",label:"Station Name",required:!0},{key:"slogan",label:"Slogan"},{key:"description",label:"Description",textarea:!0,rows:4},{key:"stream_url",label:"Stream URL",required:!0,type:"url"},{key:"logo_url",label:"Logo URL",type:"url"},{key:"homepage_url",label:"Homepage URL",type:"url"},{key:"country_code",label:"Country Code"},{key:"city",label:"City"},{key:"region",label:"Region / State"},{key:"language_code",label:"Language"},{key:"genres",label:"Genres",helper:"Semicolon-separated, e.g. jazz; blues"},{key:"frequency",label:"Frequency"},{key:"email",label:"Email",type:"email"},{key:"phone",label:"Phone",type:"tel"},{key:"facebook_url",label:"Facebook URL",type:"url"},{key:"twitter_url",label:"Twitter URL",type:"url"}];function ne({station:o,open:g,onOpenChange:p,onSaved:n}){var v;const[l,i]=f.useState({}),[u,d]=f.useState({status:"idle",result:null}),j=P();f.useEffect(()=>{if(o&&g){const a={};T.forEach(t=>{a[t.key]=o[t.key]??""}),i(a),d({status:"idle",result:null})}},[o,g]);const b=M({mutationFn:({id:a,data:t})=>y.entities.Station.update(a,t),onSuccess:()=>{h.success("Station updated"),j.invalidateQueries({queryKey:["myStations"]}),j.invalidateQueries({queryKey:["stations"]}),n==null||n(),p(!1)},onError:()=>h.error("Failed to update station")}),N=a=>{i({...l,[a.target.name]:a.target.value}),a.target.name==="stream_url"&&d({status:"idle",result:null})},_=async()=>{if(!l.stream_url){h.error("Enter a stream URL first");return}d({status:"testing",result:null});try{const a=await O.validateStream({streamUrl:l.stream_url}),t=(a==null?void 0:a.data)??a;if(t!=null&&t.error)throw new Error(t.error);d({status:t.valid?"pass":"fail",result:t})}catch(a){d({status:"fail",result:{message:a.message||"Stream validation failed"}})}},k=a=>{if(a.preventDefault(),!l.name||!l.stream_url){h.error("Station name and stream URL are required");return}const t={...l};t.bitrate_kbps!==void 0&&(t.bitrate_kbps=Number(t.bitrate_kbps)||void 0),b.mutate({id:o.id,data:t})};return o?e.jsx(U,{open:g,onOpenChange:p,children:e.jsxs(K,{className:"max-w-2xl max-h-[90vh] overflow-y-auto",children:[e.jsxs(B,{children:[e.jsx(H,{children:"Edit Station"}),e.jsx(Q,{children:"Update your live station details. Changes go live immediately."})]}),e.jsxs("form",{onSubmit:k,className:"space-y-4",children:[e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:T.map(a=>e.jsxs("div",{className:a.textarea||a.key==="description"?"md:col-span-2":"",children:[e.jsxs(Y,{htmlFor:a.key,className:"text-sm font-medium text-gray-700",children:[a.label,a.required&&e.jsx("span",{className:"text-red-500",children:" *"})]}
16),a.textarea?e.jsx(X,{id:a.key,name:a.key,value:l[a.key]||"",onChange:N,rows:a.rows||3,className:"mt-1.5"}):e.jsx(V,{id:a.key,name:a.key,type:a.type||"text",value:l[a.key]||"",onChange:N,className:"mt-1.5"}),a.helper&&e.jsx("p",{className:"text-xs text-gray-400 mt-1",children:a.helper})]},a.key))}),e.jsxs("div",{className:"rounded-lg border border-gray-200 bg-gray-50/50 p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(J,{className:"w-4 h-4 text-purple-600"}),e.jsx("span",{className:"text-sm font-medium text-gray-700",children:"Stream check"})]}),e.jsx(r,{type:"button",variant:"outline",size:"sm",onClick:_,disabled:u.status==="testing",children:u.status==="testing"?e.jsxs(e.Fragment,{children:[e.jsx(Z,{className:"w-4 h-4 mr-2 animate-spin"})," Testingâ¦"]}):"Test stream"}),u.status==="pass"&&e.jsxs("p",{className:"text-sm text-green-600 flex items-center gap-1.5 mt-2",children:[e.jsx($,{className:"w-4 h-4"})," Stream is reachable and playable."]}),u.status==="fail"&&e.jsxs("p",{className:"text-sm text-red-600 flex items-center gap-1.5 mt-2",children:[e.jsx(A,{className:"w-4 h-4"})," ",((v=u.result)==null?void 0:v.message)||"Stream check failed"]})]}),e.jsxs(I,{children:[e.jsx(r,{type:"button",variant:"outline",onClick:()=>p(!1),children:"Cancel"}),e.jsx(r,{type:"submit",className:"bg-purple-600 hover:bg-purple-700",disabled:b.isPending,children:b.isPending?"Savingâ¦":"Save Changes"})]})]})]})}):null}const C={pending:{label:"Pending Review",className:"bg-yellow-100 text-yellow-700",icon:ee},approved:{label:"Approved",className:"bg-green-100 text-green-700",icon:$},rejected:{label:"Rejected",className:"bg-red-100 text-red-700",icon:A}},re={healthy:{label:"Healthy",className:"bg-green-100 text-green-700"},broken_stream:{label:"Broken stream",className:"bg-red-100 text-red-700"},insecure_stream:{label:"Insecure stream",className:"bg-orange-100 text-orange-700"},missing_location:{label:"Missing location",className:"bg-yellow-100 text-yellow-700"},bad_logo:{label:"Bad logo",className:"bg-yellow-100 text-yellow-700"},incomplete:{label:"Incomplete",className:"bg-yellow-100 text-yellow-700"},no_metadata:{label:"No metadata",className:"bg-gray-100 text-gray-700"}};function ke(){const o=P(),[g,p]=f.useState(null),[n,l]=f.useState(null),{data:i,isLoading:u}=L({queryKey:["currentUser"],queryFn:()=>y.auth.me()}),d=(i==null?void 0:i.role)==="station_owner"||(i==null?void 0:i.role)==="admin",{data:j=[],isLoading:b}=L({queryKey:["myStations",i==null?void 0:i.id],queryFn:()=>y.entities.Station.filter({owner_id:i.id},"-created_date"),enabled:!!(i!=null&&i.id)&&d}),{data:N=[],isLoading:_}=L({queryKey:["mySubmissions"],queryFn:()=>y.entities.StationSubmission.filter({},"-created_date"),enabled:d}),k=M({mutationFn:s=>y.entities.Station.delete(s),onSuccess:()=>{h.success("Station removed"),o.invalidateQueries({queryKey:["myStations"]}),o.invalidateQueries({queryKey:["stations"]}),l(null)},onError:()=>h.error("Failed to delete station")}),v=M({mutationFn:s=>y.entities.StationSubmission.delete(s),onSuccess:()=>{h.success("Submission deleted"),o.invalidateQueries({queryKey:["mySubmissions"]}),l(null)},onError:()=>h.error("Failed to delete submission")});if(u)return e.jsxs("div",{className:"min-h-screen bg-gray-50",children:[e.jsx(q,{}),e.jsx("div",{className:"pt-24 pb-20 px-4 text-center",children:e.jsx("p",{className:"text-xl text-gray-600",children:"Loadingâ¦"})}),e.jsx(E,{})]});if(!d)return e.jsxs("div",{className:"min-h-screen bg-gray-50",children:[e.jsx(q,{}),e.jsxs("div",{className:"pt-24 pb-20 px-4 text-center max-w-2xl mx-auto",children:[e.jsx("h1",{className:"text-4xl font-bold text-gray-900 mb-4",children:"Access Restricted"}),e.jsx("p",{className:"text-xl text-gray-600",children:"Only station owners can manage stations."})]}),e.jsx(E,{})]});const a=N.filter(s=>s.status==="pending"),t=N.filter(s=>s.status!=="pending"),R=j.length;return e.jsxs("div",{className:"min-h-screen bg-gray-50",children:[e.jsx(q,{}),e.jsx("div",{className:"pt-24 pb-20 px-4",children:e.jsxs("div",{className:"container mx-auto max-w-5xl",children:[e.jsxs("div",{className:"flex items-center justify-between mb-8 flex-wrap gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-4xl font-bold text-gray-900 mb-2",children:"My Stations"}),e.jsx("p",{className:"text-lg text-gray-600",children:"Manage your live stations and submissions in one place"})]}),e.jsx(r,{asChild:!0,className:"bg-purple-600 hover:bg-purple-700",children:e.jsx(w,{to:W("SubmitStation"),children:"Submit New Station"})})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-4 mb-8",children:[e.jsx(m,{children:e.jsxs(x,{className:"p-5",children:[e.jsx("p",{className:"text-sm text-gray-500",children:"Live stations"}),e.jsx("p",{className:"text-3xl font-bold text-gray-900",children:R})]})}),e.jsx(m,{children:e.jsxs(x,{className:"p-5",children:[e.jsx("p",{className:"text-sm text-gray-500",children:"Pending review"}),e.jsx("p",{className:"text-3xl font-bold text-yellow-600",children:a.length})]})}),e.jsx(m,{children:e.jsxs(x,{className:"p-5",children:[e.jsx("p",{className:"text-sm text-gray-500",children:"Past submissions"}),e.jsx("p",{className:"text-3xl font-bold text-gray-900",children:t.length})]})})]}),e.jsxs("section",{className:"mb-10",children:[e.jsx("h2",{className:"text-2xl font-bold text-gray-900 mb-4",children:"Live Stations"}),b?e.jsx("p",{className:"text-gray-500",children:"Loadingâ¦"}):R===0?e.jsx(m,{children:e.jsx(x,{className:"p-8 text-center text-gray-500",children:"You don't have any live stations yet. Once a submission is approved, it will appear here."})}):e.jsx("div",{className:"space-y-4",children:j.map(s=>{const c=s.health_status?re[s.health_status]:null;return e.jsx(m,{children:e.jsx(x,{className:"p-5",children:e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:"w-16 h-16 rounded-lg overflow-hidden flex-shrink-0",children:e.jsx(G,{station:s})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-3 flex-wrap mb-1",children:[e.jsx("h3",{className:"text-lg font-bold text-gray-900 truncate",children:s.name}),c&&e.jsx(S,{className:c.className,children:c.label}),s.web_playable===!1&&e.jsx(S,{className:"bg-orange-100 text-orange-700",children:"Not web-playable"})]}),s.slogan&&e.jsx("p",{className:"text-sm text-gray-500 mb-1",children:s.slogan}),e.jsxs("div",{className:"flex flex-wrap gap-x-4 gap-y-1 text-sm text-gray-500",children:[s.city&&e.jsxs("span",{children:[s.city,s.region?`, ${s.region}`:""]}),s.country_code&&e.jsx("span",{children:s.country_code}),s.genres&&e.jsx("span",{children:s.genres}),s.frequency&&e.jsx("span",{children:s.frequency})]})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsx(r,{asChild:!0,variant:"outline",size:"sm",children:e.jsx(w,{to:`/StationDetail
16s?id=${s.id}`,target:"_blank",children:e.jsx(te,{className:"w-4 h-4"})})}),e.jsxs(r,{variant:"outline",size:"sm",onClick:()=>p(s),children:[e.jsx(F,{className:"w-4 h-4 mr-1"})," Edit"]}),e.jsx(r,{variant:"outline",size:"sm",className:"text-red-600 border-red-200 hover:bg-red-50",onClick:()=>l({type:"station",id:s.id,name:s.name}),children:e.jsx(D,{className:"w-4 h-4"})})]})]})})},s.id)})})]}),e.jsxs("section",{className:"mb-10",children:[e.jsx("h2",{className:"text-2xl font-bold text-gray-900 mb-4",children:"Pending Submissions"}),_?e.jsx("p",{className:"text-gray-500",children:"Loadingâ¦"}):a.length===0?e.jsx(m,{children:e.jsx(x,{className:"p-8 text-center text-gray-500",children:"No submissions awaiting review."})}):e.jsx("div",{className:"space-y-4",children:a.map(s=>{const c=C[s.status]||C.pending;return e.jsx(m,{children:e.jsx(x,{className:"p-5",children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-1",children:[e.jsx("h3",{className:"text-lg font-bold text-gray-900",children:s.name}),e.jsxs(S,{className:c.className,children:[e.jsx(c.icon,{className:"w-3 h-3 mr-1"}),c.label]})]}),e.jsx("p",{className:"text-sm text-gray-500 line-clamp-2",children:s.description||"No description"}),e.jsxs("div",{className:"flex flex-wrap gap-x-4 text-sm text-gray-500 mt-1",children:[e.jsxs("span",{children:["Country: ",s.country]}),s.location&&e.jsxs("span",{children:["Location: ",s.location]}),e.jsxs("span",{children:["Submitted: ",new Date(s.created_date).toLocaleDateString()]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsx(r,{asChild:!0,variant:"outline",size:"sm",children:e.jsxs(w,{to:`/SubmitStation?edit=${s.id}`,children:[e.jsx(F,{className:"w-4 h-4 mr-1"})," Edit"]})}),e.jsx(r,{variant:"outline",size:"sm",className:"text-red-600 border-red-200 hover:bg-red-50",onClick:()=>l({type:"submission",id:s.id,name:s.name}),children:e.jsx(D,{className:"w-4 h-4"})})]})]})})},s.id)})})]}),t.length>0&&e.jsxs("section",{children:[e.jsx("h2",{className:"text-2xl font-bold text-gray-900 mb-4",children:"Past Submissions"}),e.jsx("div",{className:"space-y-4",children:t.map(s=>{const c=C[s.status]||C.pending;return e.jsx(m,{children:e.jsx(x,{className:"p-5",children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-1",children:[e.jsx("h3",{className:"text-lg font-bold text-gray-900",children:s.name}),e.jsxs(S,{className:c.className,children:[e.jsx(c.icon,{className:"w-3 h-3 mr-1"}),c.label]})]}),e.jsxs("div",{className:"flex flex-wrap gap-x-4 text-sm text-gray-500",children:[e.jsxs("span",{children:["Country: ",s.country]}),e.jsxs("span",{children:["Reviewed: ",new Date(s.updated_date).toLocaleDateString()]})]}),s.status==="rejected"&&s.adminNote&&e.jsxs("div",{className:"mt-2 p-3 bg-red-50 rounded-lg flex items-start gap-2",children:[e.jsx(se,{className:"w-4 h-4 text-red-500 flex-shrink-0 mt-0.5"}),e.jsx("p",{className:"text-sm text-red-700",children:s.adminNote})]})]}),s.status==="rejected"&&e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsx(r,{asChild:!0,variant:"outline",size:"sm",children:e.jsxs(w,{to:`/SubmitStation?edit=${s.id}`,children:[e.jsx(F,{className:"w-4 h-4 mr-1"})," Edit & Resubmit"]})}),e.jsx(r,{variant:"outline",size:"sm",className:"text-red-600 border-red-200 hover:bg-red-50",onClick:()=>l({type:"submission",id:s.id,name:s.name}),children:e.jsx(D,{className:"w-4 h-4"})})]})]})})},s.id)})})]})]})}),e.jsx(E,{}),e.jsx(ne,{station:g,open:!!g,onOpenChange:s=>!s&&p(null)}),e.jsx(U,{open:!!n,onOpenChange:s=>!s&&l(null),children:e.jsxs(K,{className:"max-w-sm",children:[e.jsxs(B,{children:[e.jsxs(H,{
16children:["Delete ",(n==null?void 0:n.type)==="station"?"station":"submission","?"]}),e.jsxs(Q,{children:["This will permanently remove â",n==null?void 0:n.name,"â. This action cannot be undone."]})]}),e.jsxs(I,{children:[e.jsx(r,{variant:"outline",onClick:()=>l(null),children:"Cancel"}),e.jsx(r,{variant:"destructive",disabled:k.isPending||v.isPending,onClick:()=>{n&&(n.type==="station"?k.mutate(n.id):v.mutate(n.id))},children:"Delete"})]})]})})]})}export{ke 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.