"use strict";(self["webpackChunkTruckShop"]=self["webpackChunkTruckShop"]||[]).push([[5153],{5153:function(e,t,l){l.r(t),l.d(t,{default:function(){return x}});l(8111),l(7588);var a=l(6768),o=l(4232),n=l(5130),s=l(144),i=l(4084),r=l(7366),u=l.n(r),d=l(281),c=l(1193),p=l(9317),m=l(5404),v=l.n(m);const g={class:"col-sm-12"},f={class:"col-form-label col-sm-3 text-sm-end"},y={class:"col-lg-6 col-sm-7"},k={key:0,class:"form-group"},b=["id"],h=["onUpdate:modelValue"],C=["onUpdate:modelValue"],w={key:4,class:"form-group"},E=["onChange"],L={key:0,class:"mt-2 d-flex justify-content-end"},Y=["src"],X={class:"col-lg-3 col-sm-2 text-start"},_=["onClick","disabled"],R={key:0,class:"spinner-border spinner-border-sm"},H={key:1};var V={__name:"setting",setup(e){const t=(0,s.KR)(!0),l=(0,s.KR)([]),r=(0,s.KR)({}),m=(0,s.KR)({}),V=async()=>{try{const e=await p.A.get("admin/settings");l.value=e.data.data,l.value.forEach((e=>{"image"===e.type&&e.value&&(e.preview=e.value,localStorage.setItem("logo",e.value)),m.value[e.id]=!1})),await(0,a.dY)(),t.value&&(j(),t.value=!1)}catch(e){console.error("Error fetching settings:",e)}},j=()=>{l.value.forEach((e=>{if("longtext"===e.type&&!r.value[e.id]){const t=document.getElementById(`editor-${e.id}`);if(t){const l=new c.Ay(t,{theme:"snow",modules:{toolbar:[[{header:"1"},{header:"2"},{font:[]}],[{list:"ordered"},{list:"bullet"}],[{align:[]}],["bold","italic","underline"],["link"],[{script:"sub"},{script:"super"}],[{direction:"rtl"}]]}});l.root.setAttribute("dir","rtl"),l.format("direction","rtl"),l.root.innerHTML=e.value||"",l.on("text-change",(()=>{e.value=l.root.innerHTML})),r.value[e.id]=l}}}))},x=(e,t)=>{const l=e.target.files[0];l&&(t.preview=URL.createObjectURL(l),t.file=l)},M=async e=>{m.value[e.id]=!0;try{if("image"===e.type&&e.preview){const t=new FormData;t.append("value",e.file),t.append("_method","put"),await p.A.post(`admin/settings/${e.id}`,t,{headers:{"Content-Type":"multipart/form-data"}})}else if("date"===e.type&&e.value){const t=u()(e.value,"jYYYY/jMM/jDD HH:mm:ss").format("YYYY-MM-DD HH:mm:ss");await p.A.put(`admin/settings/${e.id}`,{value:t})}else await p.A.put(`admin/settings/${e.id}`,{value:e.value});V(),i.oR.success("!تنظیمات با موفیت ذخیره شد",{position:"top-right",autoClose:1e3})}catch(t){console.error("Error saving setting:",t),i.oR.error(`${t?.response?.data?.message}`,{position:"top-right",autoClose:1e3})}finally{m.value[e.id]=!1}};return(0,a.sV)((()=>{V()})),(e,t)=>{const i=(0,a.g2)("BCardHeader"),r=(0,a.g2)("BCardBody"),u=(0,a.g2)("BCard"),c=(0,a.g2)("BRow");return(0,a.uX)(),(0,a.Wv)(d.A,null,{default:(0,a.k6)((()=>[(0,a.bF)(c,null,{default:(0,a.k6)((()=>[(0,a.Lk)("div",g,[(0,a.bF)(u,{"no-body":""},{default:(0,a.k6)((()=>[(0,a.bF)(i,null,{default:(0,a.k6)((()=>t[0]||(t[0]=[(0,a.Lk)("h5",null,"تنظیمات سایت",-1)]))),_:1,__:[0]}),(0,a.bF)(r,null,{default:(0,a.k6)((()=>[((0,a.uX)(!0),(0,a.CE)(a.FK,null,(0,a.pI)(l.value,(e=>((0,a.uX)(),(0,a.CE)("div",{key:e.id,class:"mb-3 row align-items-center"},[(0,a.Lk)("label",f,(0,o.v_)(e?.title),1),(0,a.Lk)("div",y,["longtext"===e?.type?((0,a.uX)(),(0,a.CE)("div",k,[(0,a.Lk)("div",{id:"editor-"+e?.id,class:"quill-editor"},null,8,b)])):"string"===e.type?(0,a.bo)(((0,a.uX)(),(0,a.CE)("input",{key:1,type:"text","onUpdate:modelValue":t=>e.value=t,class:"form-control"},null,8,h)),[[n.Jo,e.value]]):"number"===e.type?(0,a.bo)(((0,a.uX)(),(0,a.CE)("input",{key:2,type:"text","onUpdate:modelValue":t=>e.value=t,class:"form-control"},null,8,C)),[[n.Jo,e.value]]):"date"===e.type?((0,a.uX)(),(0,a.Wv)((0,s.R1)(v()),{key:3,modelValue:e.value,"onUpdate:modelValue":t=>e.value=t,type:"datetime",format:"jYYYY/jMM/jDD HH:mm:ss",class:"form-control"},null,8,["modelValue","onUpdate:modelValue"])):"image"===e.type?((0,a.uX)(),(0,a.CE)("div",w,[(0,a.Lk)("input",{type:"file",accept:"image/*",class:"form-control",onChange:t=>x(t,e)},null,40,E),e.preview?((0,a.uX)(),(0,a.CE)("div",L,[(0,a.Lk)("img",{src:e.preview,alt:"Preview",class:"img-thumbnail",width:"150"},null,8,Y)])):(0,a.Q3)("",!0)])):(0,a.Q3)("",!0)]),(0,a.Lk)("div",X,[(0,a.Lk)("button",{class:"btn btn-primary",onClick:t=>M(e),disabled:m.value[e.id]},[m.value[e.id]?((0,a.uX)(),(0,a.CE)("span",R)):((0,a.uX)(),(0,a.CE)("span",H,"ذخیره"))],8,_)])])))),128))])),_:1})])),_:1})])])),_:1})])),_:1})}}};const j=V;var x=j}}]);
//# sourceMappingURL=5153.defe7546.js.map