1import{r as l,j as e,b as ee,C as se,F as v,a as T,at as te,ao as _,aq as z,M as a,D as U}from"./react-vendor-CrZSO3tY.js";import{u as ae,A as le,a as re,b as oe,R as ie,c as ne}from"./RevealDropdown-B2KQnLZq.js";import{B as u,b as S}from"./index-DARdAdCa.js";import{S as i}from"./sweetalert2.esm.all-Bj_ZQUAw.js";import{X as ce}from"./x-CDkAAFrI.js";const de=({onClose:F,onSuccess:k,popup:c})=>{const[h,B]=l.useState(null),[j,D]=l.useState((c==null?void 0:c.alt_text)||""),[b,H]=l.useState(!1),[A,w]=l.useState(null),R=o=>{o.target.files&&o.target.files.length>0&&B(o.target.files[0])},M=async o=>{var d,x,C,f;if(o.preventDefault(),!h&&!c){w("Please select an image file");return}H(!0),w(null);try{const n=new FormData;if(h&&n.append("imagefile",h),n.append("alt_text",j),c){const N=await S.post(`/admin/popupform/update/${c.id}`,n,{headers:{"Content-Type":"multipart/form-data"}});i.fire({icon:"success",title:"Success",text:N.data.message||"Popup updated successfully"})}else{const N=await S.post("/admin/popup/create/",n,{headers:{"Content-Type":"multipart/form-data"}});i.fire({icon:"success",title:"Success",text:N.data.message||"Popup created successfully"})}k()}catch(n){console.error("Error submitting popup:",n),w(((x=(d=n.response)==null?void 0:d.data)==null?void 0:x.message)||"Failed to submit popup"),i.fire({icon:"error",title:"Error",text:((f=(C=n.response)==null?void 0:C.data)==null?void 0:f.message)||"Failed to submit popup"})}finally{H(!1)}};return e.jsxs("div",{children:[e.jsx("button",{className:"position-absolute top-0 end-0 m-3 btn btn-link text-dark",onClick:F,"aria-label":"Close",children:e.jsx(ce,{size:24})}),e.jsx("h2",{className:"mb-4 text-start",children:c?"Edit Popup":"Add New Popup"}),e.jsx("hr",{className:"mb-4"}),A&&e.jsx("div",{className:"alert alert-danger",children:A}),e.jsx(ee,{className:"justify-content-center",children:e.jsx(se,{xs:12,xl:9,children:e.jsxs(v,{onSubmit:M,children:[e.jsxs(v.Group,{controlId:"formFile",className:"mb-4",children:[e.jsxs(v.Label,{children:[e.jsx(T,{icon:te,className:"me-2"})," ",c?"Update Image (Optional)":"Image"]}),e.jsx(v.Control,{type:"file",onChange:R,accept:"image/*"})]}),e.jsxs(v.Group,{controlId:"formAltText",className:"mb-4",children:[e.jsx(v.Label,{children:"Image Alt Text"}),e.jsx(v.Control,{type:"text",placeholder:"Describe the image for accessibility/SEO",value:j,onChange:o=>D(o.target.value)})]}),e.jsxs("div",{className:"mt-4 d-flex justify-content-end gap-3",children:[e.jsx(u,{variant:"primary",className:"px-4",onClick:F,disabled:b,children:"Back"}),e.jsx(u,{variant:"warning",className:"px-3 py-2",type:"submit",disabled:b,children:b?"Processing...":"Submit"})]})]})})})]})},ge=()=>{const[F,k]=l.useState([]),[c,h]=l.useState(!1),[B,j]=l.useState(!1),[D,b]=l.useState(!1),[H,A]=l.useState(!0),[w,R]=l.useState(null),[M,o]=l.useState(null),[d,x]=l.useState([]),[C,f]=l.useState([]),[n,N]=l.useState(!1),[m,E]=l.useState({open:!1,id:null,setActive:null}),[$,L]=l.useState(!1),P=async()=>{try{A(!0);const s=await S.get("/admin/popup");k(s.data.data)}catch(s){console.error("Failed to fetch popups:",s),R("Failed to load popups. Please try again later.")}finally{A(!1)}};l.useEffect(()=>{P()},[]);const O=async s=>{if((await i.fire({title:"Are you sure?",text:"You won't be able to revert this!",icon:"warning",showCancelButton:!0,confirmButtonColor:"#3085d6",cancelButtonColor:"#d33",confirmButtonText:"Yes, delete it!"})).isConfirmed)try{await S.get(`/admin/popup/delete/${s}`),i.fire("Deleted!","Popup has been deleted.","success"),P()}catch(r){console.error("Error deleting popup:",r),i.fire("Error!","Failed to delete popup.","error")}},G=s=>{o(s),h(!0)},K=()=>{h(!1),o(null),P()},Y=s=>{const t=s.target.files;if(t){const r=Array.from(t);x(r),f(r.map(()=>""))}},W=s=>{x(t=>t.filter((r,g)=>g!==s)),f(t=>t.filter((r,g)=>g!==s))},q=(s,t)=>{f(r=>r.map((g,I)=>I===s?t:g))},V=async()=>{var s,t,r,g,I;if(d.length===0){i.fire("Error!","Please select at least one file.","error");return}N(!0);try{const p=new FormData;d.forEach((Q,Z)=>{p.append("popup[]",Q),p.append("alt_text[]",C[Z]||"")});const y=await S.post("/admin/popupform/insert",p,{headers:{"Content-Type":"multipart/form-data"}});if(y.data.success)i.fire("Success!",`${y.data.count}
1 popup image(s) uploaded successfully.`,"success"),j(!1),x([]),f([]),P();else throw new Error(y.data.message||"Upload failed")}catch(p){if(console.error("Error uploading files:",p),((s=p.response)==null?void 0:s.status)===422&&((r=(t=p.response)==null?void 0:t.data)!=null&&r.errors)){const y=Object.values(p.response.data.errors).flat();i.fire("Validation Error!",y.join("<br>"),"error")}else{const y=((I=(g=p.response)==null?void 0:g.data)==null?void 0:I.message)||"Failed to upload images.";i.fire("Error!",y,"error")}}finally{N(!1)}},X="/api".replace("/api",""),J=ae({data:F,columns:[{accessorKey:"id",header:"Sr. No.",cell:({row:s})=>s.index+1,meta:{headerProps:{style:{width:"10%"},className:"text-center"},cellProps:{className:"text-center fw-semibold"}}},{accessorKey:"path",header:"Image",cell:({row:s})=>e.jsx("div",{className:"d-flex justify-content-center align-items-center",children:e.jsx("img",{loading:"lazy",src:`${X}/${s.original.path}`,alt:s.original.alt_text||"Popup",style:{width:"80px",height:"80px",objectFit:"cover",borderRadius:"5px"}})}),meta:{headerProps:{style:{width:"15%"},className:"text-center"},cellProps:{className:"d-flex justify-content-center align-items-center"}}},{accessorKey:"isActive",header:"Status",cell:({row:s})=>{const t=s.original;return e.jsx("div",{className:"d-flex justify-content-center align-items-center position-relative",style:{height:"30px",minWidth:"30px"},children:e.jsx("input",{type:"checkbox",checked:t.isActive===1,onChange:()=>{E({open:!0,id:t.id,setActive:t.isActive===0})},style:{width:"22px",height:"22px",accentColor:t.isActive===1?"#2ecc40":void 0,cursor:"pointer"}})})},meta:{headerProps:{style:{width:"10%"},className:"text-center"},cellProps:{className:"text-center"}}},{id:"action",header:"Actions",cell:({row:s})=>e.jsx(ie,{children:e.jsxs(ne,{children:[e.jsx(U.Item,{onClick:()=>G(s.original),children:"Edit"}),e.jsx(U.Item,{className:"text-danger",onClick:()=>O(s.original.id),children:"Delete"})]})}),meta:{headerProps:{style:{width:"15%"},className:"text-center"},cellProps:{className:"text-center"}}}],pageSize:10,pagination:!0,sortable:!0});return e.jsxs("div",{children:[e.jsxs("div",{className:"mb-9",children:[e.jsx("h2",{className:"mb-4 ms-2",children:"Manage Popups"}),e.jsx("hr",{className:"mb-4 ms-2"}),w&&e.jsx("div",{className:"alert alert-danger mx-7",children:w}),e.jsxs(le,{...J,children:[e.jsx("div",{className:"mb-4",children:e.jsxs("div",{className:"d-flex flex-wrap gap-3 ms-2 justify-content-end",children:[e.jsxs(u,{variant:"info",className:"px-3",onClick:()=>b(!0),children:[e.jsx(T,{icon:_,className:"me-2"}),"History"]}),e.jsxs(u,{variant:"warning",className:"px-3",onClick:()=>j(!0),children:[e.jsx(T,{icon:z,className:"me-2"}),"Add Popup Images"]})]})}),e.jsxs("div",{className:"table-container card shadow-sm border rounded-3 bg-white ms-2",children:[e.jsx("div",{className:"table-responsive",children:e.jsx(re,{tableProps:{className:"phoenix-table fs-9 table table-bordered align-middle"}})}),e.jsx(oe,{pagination:!0})]})]})]}),e.jsx(a,{show:c,onHide:()=>{h(!1),o(null)},size:"lg",dialogClassName:"custom-modal",children:e.jsx(a.Body,{children:e.jsx(de,{onClose:()=>{h(!1),o(null)},onSuccess:K,popup:M})})}),e.jsxs(a,{show:B,onHide:()=>{j(!1),x([]),f([])},size:"lg",centered:!0,children:[e.jsx(a.Header,{closeButton:!0,children:e.jsx(a.Title,{children:"Add Popup Images"})}),e.jsxs(a.Body,{children:[e.jsxs("div",{className:"mb-3",children:[e.jsx("label",{className:"form-label fw-bold",children:"Choose Images"}),e.jsx("input",{type:"file",className:"form-control",multiple:!0,accept:"image/*",onChange:Y}),e.jsx("div",{className:"form-text",children:"You can select multiple image files at once."})]}),d.length>0&&e.jsxs("div",{className:"mb-3",children:[e.jsxs("label",{className:"form-label fw-bold",children:["Selected Files (",d.length,")"]}),e.jsx("div",{className:"border rounded p-3 bg-light",children:d.map((s,t)=>e.jsxs("div",{className:"d-flex justify-content-between align-items-start mb-2",children:[e.jsxs("div",{className:"d-flex align-items-start flex-grow-1",children:[e.jsx("img",{loading:"lazy",src:URL.createObjectURL(s),alt:s.name,style:{width:"40px",height:"40px",objectFit:"cover",borderRadius:"4px",marginRight:"10px"}}),e.jsxs("div",{className:"flex-grow-1",children:[e.jsx("span",{className:"text-truncate d-block",style:{maxWidth:"200px"},children:s.name}),e.jsx("input",{type:"text",className:"form-control form-control-sm mt-1",placeholder:"Image alt text",value:C[t]||"",onChange:r=>q(t,r.target.value)})]})]}),e.jsx("button",{type:"button",className:"btn btn-sm btn-outline-danger ms-2",onClick:()=>W(t),children:"Remove"})]},t))})]})]}),e.jsxs(a.Footer,{children:[e.jsx(u,{variant:"secondary",onClick:()=>{j(!1),x([])},children:"Cancel"}),e.jsx(u,{variant:"primary",onClick:V,disabled:n||d.length===0,children:n?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"spinner-border spinner-border-sm me-2"}),"Uploading..."]}):"Submit"})]})]}),e.jsxs(a,{show:D,onHide:()=>b(!1),size:"lg",centered:!0,children:[e.jsx(a.Header,{closeButton:!0,children:e.jsx(a.Title,{children:"Popup History"})}),e.jsx(a.Body,{children:e.jsxs("div",{className:"text-center py-4",children:[e.jsx("p",{className:"text-muted",children:"History functionality will be implemented here."}),e.jsx("p",{className:"text-muted",children:"This will show the history of popup changes, uploads, and deletions."})]})}),e.jsx(a.Footer,{children:e.jsx(u,{variant:"secondary",onClick:()=>b(!1),children:"Close"})})]}),e.jsxs(a,{show:m.open,onHide:()=>
1E({open:!1,id:null,setActive:null}),centered:!0,children:[e.jsx(a.Header,{closeButton:!0,children:e.jsx(a.Title,{children:m.setActive?"Activate Popup":"Deactivate Popup"})}),e.jsx(a.Body,{children:e.jsxs("div",{className:"text-center py-3",children:[e.jsx(T,{icon:m.setActive?z:_,size:"2x",className:"mb-2 text-primary"}),e.jsx("p",{children:m.setActive?"Are you sure you want to make this popup active?":"Are you sure you want to make this popup inactive?"})]})}),e.jsxs(a.Footer,{children:[e.jsx(u,{variant:"secondary",onClick:()=>E({open:!1,id:null,setActive:null}),children:"Cancel"}),e.jsx(u,{variant:"primary",disabled:$,onClick:async()=>{if(!(!m.id||m.setActive===null)){L(!0);try{await S.post(`/admin/popup/update-status/${m.id}`,{isActive:m.setActive?1:0}),i.fire("Success!",`Popup has been ${m.setActive?"activated":"deactivated"}.`,"success"),E({open:!1,id:null,setActive:null}),P()}catch{i.fire("Error!","Failed to update status.","error")}finally{L(!1)}}},children:"Submit"})]})]}),e.jsx("style",{children:` 2 .custom-modal .modal-dialog { 3 max-width: 70vw; 4 width: 100%; 5 } 6 @media (max-width: 768px) { 7 .custom-modal .modal-dialog { 8 max-width: 90vw; 9 } 10 } 11 .table-container { 12 margin-top: 1rem; 13 padding: 1rem; 14 } 15 .table-container .table th { 16 background-color: #f1f1f1; 17 font-weight: 600; 18 color: #333; 19 } 20 .phoenix-table td, .phoenix-table th { 21 vertical-align: middle; 22 text-align: center; 23 } 24 `})]})};export{ge 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.