import{r as k,j as e}from"./sikshya-admin-sikshya-react-E_TY_un4.js";import{c as P,N as y}from"./sikshya-admin.js";import{B as g}from"./sikshya-admin-buttons-Bym2otdv.js";import{ad as a}from"./sikshya-admin-sikshya-vendor-BVAk_Gwu.js";const v="mt-2 w-full max-w-lg truncate rounded-xl border border-slate-200 bg-slate-50 px-3 py-2 text-xs leading-snug text-slate-600 shadow-sm dark:border-slate-600 dark:bg-slate-900/40 dark:text-slate-400";function E(i){if(!i||i.trim()==="")return v;const d=i.replace(/\bmt-1\.5\b/g,"").replace(/\s+/g," ").trim();return`${v} ${d}`.trim()}const S="group relative flex h-14 w-14 shrink-0 items-center justify-center overflow-hidden rounded-xl border shadow-sm transition focus:outline-none focus-visible:ring-2 focus-visible:ring-brand-500/40";function _(i){const{id:d,value:r,onChange:c,onAttachmentIdChange:t,className:w,placeholder:j,imageOnly:s=!0}=i,u=P(),m=k.useRef(null),o=k.useCallback(()=>{var l;if(typeof((l=window.wp)==null?void 0:l.media)!="function"){u.alert({title:a("Media library unavailable","sikshya"),message:a("WordPress media library is not loaded. Please reload the page.","sikshya")});return}if(!m.current){const x=window.wp.media({library:s?{type:"image"}:{},multiple:!1});x.on("select",()=>{const n=x.state().get("selection").first().toJSON(),b=n.url,h=typeof n.id=="number"?n.id:Number(n.id);Number.isFinite(h)&&h>0&&(t==null||t(h)),typeof b=="string"&&b.length>0&&c(b)}),m.current=x}m.current.open()},[u,s,c,t]),N=s?a("Featured image thumbnail","sikshya"):a("Selected file","sikshya"),f=j||a("Opens the WordPress media library — upload something new or pick an existing file.","sikshya"),p=s?a("Choose image","sikshya"):a("Choose file","sikshya"),R=r?"border-slate-200 bg-white hover:border-brand-300 dark:border-slate-600 dark:bg-slate-900 dark:hover:border-brand-500/60":"border-dashed border-slate-200 bg-slate-50/90 hover:border-brand-300 hover:bg-brand-50/50 dark:border-slate-600 dark:bg-slate-800/70 dark:hover:border-brand-500/50 dark:hover:bg-brand-950/20",C=E(w),F=()=>{t==null||t(0),c("")};return e.jsx("div",{className:"mt-1.5 inline-block w-full max-w-xl align-top",children:e.jsxs("div",{className:"flex flex-wrap items-start gap-3",children:[e.jsx("button",{type:"button",id:d,title:N,"aria-label":r?s?a("Replace featured image","sikshya"):a("Replace file","sikshya"):p,onClick:o,onKeyDown:l=>{(l.key==="Enter"||l.key===" ")&&(l.preventDefault(),o())},className:`${S} ${R}`,children:r?s?e.jsx("img",{src:r,alt:"",className:"h-full w-full object-cover",loading:"lazy"}):e.jsxs("div",{className:"flex h-full w-full flex-col items-center justify-center gap-0.5 bg-slate-50 px-1 dark:bg-slate-800/80",children:[e.jsx(y,{name:"clipboard",className:"h-5 w-5 text-slate-400 dark:text-slate-500"}),e.jsx("span",{className:"max-w-full truncate px-0.5 text-xs font-medium text-slate-500 dark:text-slate-400",children:a("File","sikshya")})]}):e.jsx(y,{name:s?"photoImage":"clipboard",className:"h-6 w-6 text-slate-400 transition group-hover:text-brand-500 dark:text-slate-500 dark:group-hover:text-brand-400"})}),e.jsx("div",{className:"min-w-0 flex-1",children:r?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(g,{type:"button",onClick:o,className:"px-3 py-1.5 text-xs font-semibold shadow-sm","aria-label":s?a("Replace image from media library","sikshya"):a("Replace file from media library","sikshya"),children:s?a("Replace","sikshya"):a("Replace file","sikshya")}),e.jsx("button",{type:"button",className:"text-xs font-semibold text-red-600 underline-offset-2 hover:text-red-800 hover:underline dark:text-red-400 dark:hover:text-red-300",onClick:F,children:s?a("Remove","sikshya"):a("Remove file","sikshya")})]}),e.jsx("input",{type:"text",readOnly:!0,tabIndex:-1,className:C,value:r,title:a("URL","sikshya"),"aria-label":a("File URL","sikshya")})]}):e.jsxs(e.Fragment,{children:[e.jsx(g,{type:"button",onClick:o,className:"px-3 py-1.5 text-xs font-semibold shadow-sm",children:p}),e.jsx("p",{className:"mt-1.5 max-w-lg text-xs leading-relaxed text-slate-500 dark:text-slate-400",children:f}),e.jsx("span",{className:"sr-only",children:f})]})})]})})}export{_ as W};
