import{_ as L}from"./nxDA0OVn.js";import{B as N,D as V,q as _,r as f,c as k,o as w,b as F,a as t,g as q,s as y,C,k as r,E as R,z as g,m as x}from"./CGJ-iGzd.js";import{C as B}from"./C46f8uP2.js";import{_ as A}from"./DlAUqK2U.js";const E={class:""},H={class:"mt-4"},S={class:"mt-4"},T={key:0,class:"flex flex-col space-y-1 mt-4"},W=["src"],j={class:""},I={__name:"addForm",setup(D){const v=N(),m=V(),h=_({}),i=_({title:"",abstract:""});f(0);async function U(){await g.post(x().public.BaseUrl+"maghale/activities/",i).then(l=>{if(a.value){const e=new FormData;e.append("image",a.value),e.append("activity",l.data.id),g.post(x().public.BaseUrl+"maghale/images/",e)}h.activity=l.data.id,g.post(x().public.BaseUrl+"books/publishers/",h).then(e=>{v.setPublisherId(e.data.id),m.go(-1)})})}const a=f(null),c=f(null);function M(){c.value=null,a.value=null}const P=async l=>{const e=l.target.files[0];if(!e)return;if(e&&e.type.match("image.*")){const s=new FileReader;s.onload=n=>{c.value=n.target.result},s.readAsDataURL(e)}const o=e.name.split(".").pop().toLowerCase();try{const s=await new Promise((u,b)=>{new B(e,{quality:.6,maxWidth:1024,maxHeight:1024,success(d){u(d)},error(d){b(d)}})}),n=new File([s],`compressed.${o}`,{type:s.type,lastModified:Date.now()});if(n.size>3e5){const u=await new Promise((d,$)=>{new B(n,{quality:.4,maxWidth:800,maxHeight:800,success(p){d(p)},error(p){$(p)}})}),b=new File([u],`compressed.${o}`,{type:u.type,lastModified:Date.now()});a.value=b}else a.value=n}catch(s){console.error("Error:",s)}};return(l,e)=>{const z=L;return w(),k("div",E,[F(z,{title:"افزودن ناشر"}),t("form",{onSubmit:R(U,["prevent"]),class:"max-w-sm mx-auto",dir:"rtl"},[t("div",null,[t("div",H,[e[3]||(e[3]=t("label",{for:"title",class:"block mb-2 font-medium text-zinc-900 dark:text-white"},"عنوان",-1)),y(t("input",{"onUpdate:modelValue":e[0]||(e[0]=o=>r(i).title=o),type:"text",id:"title",class:"shadow-sm bg-zinc-50 border border-zinc-300 text-zinc-900 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 dark:shadow-sm-light",required:""},null,512),[[C,r(i).title]])]),t("div",S,[e[4]||(e[4]=t("label",{for:"message",class:"block mb-2 text-sm font-medium text-zinc-900 dark:text-white"}," توضیحات مختصر ",-1)),y(t("textarea",{"onUpdate:modelValue":e[1]||(e[1]=o=>r(i).abstract=o),id:"message",rows:"4",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",placeholder:""},null,512),[[C,r(i).abstract]])]),r(c)?(w(),k("div",T,[t("img",{src:r(c),alt:"Preview",class:"rounded-lg size-20 mx-auto"},null,8,W),t("button",{type:"button",onClick:e[2]||(e[2]=o=>M(r(a).id)),class:"w-20 rounded-lg bg-yellow-300 mx-auto"},e[5]||(e[5]=[t("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"},[t("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)]))])):q("",!0),t("div",j,[e[6]||(e[6]=t("label",{class:"block mb-2 text-sm font-medium text-zinc-900 dark:text-white"},"انتخاب عکس",-1)),t("input",{type:"file",accept:"image/*",onChange:P,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)])]),e[7]||(e[7]=t("div",{class:"flex mt-4"},[t("button",{type:"submit",class:"text-white ml-2 bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg px-3 py-2.5 text-center dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800"},"ثبت ")],-1))],32)])}}},G={},J={class:""};function K(D,v){const m=I;return w(),k("div",null,[t("div",J,[F(m)])])}const Z=A(G,[["render",K]]);export{Z as default};
