import{_ as D}from"./1fN7R7tG.js";import{e as M,B as L,I as N,q,r as A,c as g,o as f,b as H,a as e,s as x,C as h,k as o,F as R,x as V,m as l,z as c}from"./CGJ-iGzd.js";import{C as y}from"./C46f8uP2.js";const E={class:""},P={class:"mt-4 grid gap-2 grid-cols-3 text-zinc-800 dark:text-white"},T=["src"],W=["onClick"],j={class:"mt-4"},I={class:""},O={__name:"form",setup(S){const{$CustomAlert:w}=M(),z=L(),C=N().params.id,a=q({data:{handout:0},activity:{}});async function _(){c.defaults.headers.common.Authorization=z.token,await c.get(l().public.BaseUrl+"maghale/get_handout_edit/"+C).then(i=>{a.activity=i.data.activity,a.data=i.data,delete a.data.activity})}_();async function k(){await c.patch(`${l().public.BaseUrl}maghale/activities/${a.activity.id}/`,a.activity).then(()=>{w("تغییرات ثبت شد",4)})}async function B(){const i=new FormData;i.append("image",u.value),i.append("activity",a.activity.id),c.post(l().public.BaseUrl+"maghale/images/",i).then(t=>{t.data.image=t.data.image.split("8010")[1],a.activity.images.push(t.data)})}function $(i){confirm("آیا از حذف عکس اطمینان دارید؟")&&c.delete(`${l().public.BaseUrl}maghale/images/${i}/`).then(()=>{a.activity.images=a.activity.images.filter(t=>t.id!==i)}).catch(t=>{console.log(t)})}const u=A(null),F=async i=>{const t=i.target.files[0];if(!t)return;const s=t.name.split(".").pop().toLowerCase();try{const r=await new Promise((d,p)=>{new y(t,{quality:.6,maxWidth:1024,maxHeight:1024,success(n){d(n)},error(n){p(n)}})}),m=new File([r],`compressed.${s}`,{type:r.type,lastModified:Date.now()});if(m.size>3e5){const d=await new Promise((n,U)=>{new y(m,{quality:.4,maxWidth:800,maxHeight:800,success(b){n(b)},error(b){U(b)}})}),p=new File([d],`compressed.${s}`,{type:d.type,lastModified:Date.now()});u.value=p}else u.value=m;B()}catch(r){console.error("Error:",r)}};return(i,t)=>{const v=D;return f(),g("div",E,[H(v,{title:"ویرایش دست‌نوشته"}),e("div",null,[t[2]||(t[2]=e("label",{for:"title",class:"block mt-6 text-sm font-medium text-zinc-900 dark:text-white"},"عنوان",-1)),x(e("input",{type:"text",id:"title","onUpdate:modelValue":t[0]||(t[0]=s=>o(a).activity.title=s),onChange:k,class:"mt-2 bg-zinc-50 border border-zinc-300 text-zinc-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-zinc-700 dark:border-zinc-600 dark:placeholder-zinc-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500",required:""},null,544),[[h,o(a).activity.title]])]),e("div",null,[t[3]||(t[3]=e("label",{for:"abstract",class:"block mt-4 text-sm font-medium text-zinc-900 dark:text-white"}," خلاصه",-1)),x(e("textarea",{type:"text",id:"abstract","onUpdate:modelValue":t[1]||(t[1]=s=>o(a).activity.abstract=s),onChange:k,class:"mt-2 bg-zinc-50 border border-zinc-300 text-zinc-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-zinc-700 dark:border-zinc-600 dark:placeholder-zinc-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"},null,544),[[h,o(a).activity.abstract]])]),e("div",P,[(f(!0),g(R,null,V(o(a).activity.images,s=>(f(),g("div",{key:s.id,class:"text-center"},[e("img",{src:("useRuntimeConfig"in i?i.useRuntimeConfig:o(l))().public.MediaUrl+s.image,class:"size-20 rounded-lg mx-auto"},null,8,T),e("button",{type:"button",onClick:r=>$(s.id),class:"w-20 mt-1 rounded-lg bg-zinc-300"},t[4]||(t[4]=[e("svg",{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24","stroke-width":"1.5",stroke:"currentColor",class:"size-6 mx-auto p-0.5"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round",d:"m14.74 9-.346 9m-4.788 0L9.26 9m9.968-3.21c.342.052.682.107 1.022.166m-1.022-.165L18.16 19.673a2.25 2.25 0 0 1-2.244 2.077H8.084a2.25 2.25 0 0 1-2.244-2.077L4.772 5.79m14.456 0a48.108 48.108 0 0 0-3.478-.397m-12 .562c.34-.059.68-.114 1.022-.165m0 0a48.11 48.11 0 0 1 3.478-.397m7.5 0v-.916c0-1.18-.91-2.164-2.09-2.201a51.964 51.964 0 0 0-3.32 0c-1.18.037-2.09 1.022-2.09 2.201v.916m7.5 0a48.667 48.667 0 0 0-7.5 0"})],-1)]),8,W)]))),128))]),e("div",j,[e("div",I,[t[5]||(t[5]=e("label",{class:"block mb-2 text-sm font-medium text-zinc-900 dark:text-white"},"افزودن عکس",-1)),e("input",{type:"file",accept:"image/*",onChange:F,class:"block mb-2 p-2.5 w-full text-sm text-zinc-900 bg-zinc-50 rounded-lg border border-zinc-300 focus:ring-blue-500 focus:border-blue-500 dark:bg-zinc-700 dark:border-zinc-600 dark:placeholder-zinc-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"},null,32)])])])}}};export{O as _};
