Files
2026-10-20 16:52:05 +03:30

2 lines
27 KiB
JavaScript

import{bC as $t,aD as Dt,_ as it,O as Ft,P as Mt,Q as Et,d as Wt,i as M,z as ct,x as qt,B as dt,o as j,c as E,e as g,w as C,b as o,f as ot,R as mt,l as A,t as K,k as Zt,n as X,C as vt,H as U,S as ft,bs as Jt}from"./index-1ba0f9ec.js";import{_ as Gt}from"./BasicMainCard-33e38576.js";import{_ as Xt}from"./BasicModal.vue_vue_type_style_index_0_lang-aed8f5e4.js";import{_ as Qt}from"./BasicInput.vue_vue_type_style_index_0_lang-e6a4e582.js";import{u as ht,_ as Kt}from"./useBaseTable-e7a67916.js";import{_ as te}from"./button.vue_vue_type_style_index_0_lang-f90e25b2.js";import{d as Z}from"./updateLocale-a8654270.js";import{I as Q}from"./Icon-29e38d16.js";import{_ as pt}from"./BasicSelect.vue_vue_type_style_index_0_lang-235e6b77.js";import{t as _t}from"./useDataTime-6e234adb.js";import{g as ee,a as se,v as oe}from"./itemViews-9a58c947.js";import{g as st}from"./convert-2ad76038.js";import{g as gt}from"./index-c4537a3b.js";import{M as bt}from"./index-ec322234.js";import{S as yt}from"./index-4bff02a6.js";import{D as ie}from"./dayjs-1cfa00b1.js";import{T as tt}from"./isSymbol-355a1404.js";import{U as xt}from"./index-f4084f09.js";import"./Grid-660f1a55.js";import"./index-f22a4554.js";import"./_plugin-vue_export-helper-31e07528.js";import"./shallowequal-e0d9eafb.js";import"./index-3f6d5caa.js";import"./vnode-c4e67237.js";import"./index-73cafb1e.js";import"./useState-dcd360f8.js";import"./useRefs-5e33302c.js";import"./_flatRest-7877cdf8.js";import"./isMobile-e2e89480.js";import"./omit-f5d28cd3.js";import"./index-c136a321.js";import"./Col-f8806a10.js";import"./styleChecker-19ce40ea.js";import"./isPlainObject-e945bc1f.js";import"./usePrice-bc935b83.js";import"./index-aafc0fe2.js";import"./SearchOutlined-95278fe5.js";import"./FormItemContext-33ef1221.js";import"./index-8f2b7e91.js";import"./useMemo-ee45fb46.js";import"./lodash-27f814e6.js";import"./BaseSwitch.vue_vue_type_script_setup_true_lang-36a1ea6e.js";import"./index-c8127d4e.js";import"./Badge-8a8eeb58.js";import"./isNumeric-3f69e2aa.js";import"./index-a8579634.js";import"./index-e22339b6.js";import"./index-876da578.js";import"./LeftOutlined-93011b30.js";import"./css-aae66f86.js";import"./DialogWrap-394d7eb0.js";import"./pickAttrs-0ddf9a54.js";import"./index-e0664925.js";import"./toArray-41940180.js";import"./index-175b83cf.js";import"./supabaseTableQuery-e0472e9c.js";import"./index-0d716d4e.js";import"./index-83b891e2.js";import"./index-65e13d19.js";var Tt={exports:{}};(function(r,v){(function(p,S){r.exports=S()})(Dt,function(){var p="minute",S=/[+-]\d\d(?::?\d\d)?/g,z=/([+-]|\d\d)/g;return function(W,w,I){var n=w.prototype;I.utc=function(s){var h={date:s,utc:!0,args:arguments};return new w(h)},n.utc=function(s){var h=I(this.toDate(),{locale:this.$L,utc:!0});return s?h.add(this.utcOffset(),p):h},n.local=function(){return I(this.toDate(),{locale:this.$L,utc:!1})};var N=n.parse;n.parse=function(s){s.utc&&(this.$u=!0),this.$utils().u(s.$offset)||(this.$offset=s.$offset),N.call(this,s)};var H=n.init;n.init=function(){if(this.$u){var s=this.$d;this.$y=s.getUTCFullYear(),this.$M=s.getUTCMonth(),this.$D=s.getUTCDate(),this.$W=s.getUTCDay(),this.$H=s.getUTCHours(),this.$m=s.getUTCMinutes(),this.$s=s.getUTCSeconds(),this.$ms=s.getUTCMilliseconds()}else H.call(this)};var O=n.utcOffset;n.utcOffset=function(s,h){var D=this.$utils().u;if(D(s))return this.$u?0:D(this.$offset)?O.call(this):this.$offset;if(typeof s=="string"&&(s=function(R){R===void 0&&(R="");var F=R.match(S);if(!F)return null;var B=(""+F[0]).match(z)||["-",0,0],c=B[0],V=60*+B[1]+ +B[2];return V===0?0:c==="+"?V:-V}(s),s===null))return this;var _=Math.abs(s)<=16?60*s:s,k=this;if(h)return k.$offset=_,k.$u=s===0,k;if(s!==0){var P=this.$u?this.toDate().getTimezoneOffset():-1*this.utcOffset();(k=this.local().add(_+P,p)).$offset=_,k.$x.$localOffset=P}else k=this.utc();return k};var f=n.format;n.format=function(s){var h=s||(this.$u?"YYYY-MM-DDTHH:mm:ss[Z]":"");return f.call(this,h)},n.valueOf=function(){var s=this.$utils().u(this.$offset)?0:this.$offset+(this.$x.$localOffset||this.$d.getTimezoneOffset());return this.$d.valueOf()-6e4*s},n.isUTC=function(){return!!this.$u},n.toISOString=function(){return this.toDate().toISOString()},n.toString=function(){return this.toDate().toUTCString()};var y=n.toDate;n.toDate=function(s){return s==="s"&&this.$offset?I(this.format("YYYY-MM-DD HH:mm:ss:SSS")).toDate():y.call(this)};var x=n.diff;n.diff=function(s,h,D){if(s&&this.$u===s.$u)return x.call(this,s,h,D);var _=this.local(),k=I(s).local();return x.call(_,k,h,D)}}})})(Tt);var ae=Tt.exports;const le=$t(ae);var Ct={exports:{}};(function(r,v){(function(p,S){r.exports=S()})(Dt,function(){var p={year:0,month:1,day:2,hour:3,minute:4,second:5},S={};return function(z,W,w){var I,n=function(f,y,x){x===void 0&&(x={});var s=new Date(f),h=function(D,_){_===void 0&&(_={});var k=_.timeZoneName||"short",P=D+"|"+k,R=S[P];return R||(R=new Intl.DateTimeFormat("en-US",{hour12:!1,timeZone:D,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",timeZoneName:k}),S[P]=R),R}(y,x);return h.formatToParts(s)},N=function(f,y){for(var x=n(f,y),s=[],h=0;h<x.length;h+=1){var D=x[h],_=D.type,k=D.value,P=p[_];P>=0&&(s[P]=parseInt(k,10))}var R=s[3],F=R===24?0:R,B=s[0]+"-"+s[1]+"-"+s[2]+" "+F+":"+s[4]+":"+s[5]+":000",c=+f;return(w.utc(B).valueOf()-(c-=c%1e3))/6e4},H=W.prototype;H.tz=function(f,y){f===void 0&&(f=I);var x=this.utcOffset(),s=this.toDate(),h=s.toLocaleString("en-US",{timeZone:f}),D=Math.round((s-new Date(h))/1e3/60),_=w(h).$set("millisecond",this.$ms).utcOffset(15*-Math.round(s.getTimezoneOffset()/15)-D,!0);if(y){var k=_.utcOffset();_=_.add(x-k,"minute")}return _.$x.$timezone=f,_},H.offsetName=function(f){var y=this.$x.$timezone||w.tz.guess(),x=n(this.valueOf(),y,{timeZoneName:f}).find(function(s){return s.type.toLowerCase()==="timezonename"});return x&&x.value};var O=H.startOf;H.startOf=function(f,y){if(!this.$x||!this.$x.$timezone)return O.call(this,f,y);var x=w(this.format("YYYY-MM-DD HH:mm:ss:SSS"));return O.call(x,f,y).tz(this.$x.$timezone,!0)},w.tz=function(f,y,x){var s=x&&y,h=x||y||I,D=N(+w(),h);if(typeof f!="string")return w(f).tz(h);var _=function(F,B,c){var V=F-60*B*1e3,$=N(V,c);if(B===$)return[V,B];var J=N(V-=60*($-B)*1e3,c);return $===J?[V,$]:[F-60*Math.min($,J)*1e3,Math.max($,J)]}(w.utc(f,s).valueOf(),D,h),k=_[0],P=_[1],R=w(k).utcOffset(P);return R.$x.$timezone=h,R},w.tz.guess=function(){return Intl.DateTimeFormat().resolvedOptions().timeZone},w.tz.setDefault=function(f){I=f}}})})(Ct);var ne=Ct.exports;const re=$t(ne),ue=[{title:"ردیف",dataIndex:"id",key:"id",filterable:!1,width:70,align:"center",customRender:r=>r.record.index+1},{title:"عنوان",dataIndex:"title",key:"title"},{title:"زیرعنوان",dataIndex:"sub_title",key:"sub_title"},{title:"کتاب مرتبط",dataIndex:"book_id",key:"book_id",align:"center",customRender:r=>{const v=r.record.book_title,p=r.record.book_id;return v||(p?`کتاب #${p}`:"-")}},{title:"زمان",dataIndex:"time",key:"time",customRender:r=>{const v=r.record.time||{minutes:0,seconds:0},p=Number(v.minutes||0),S=Number(v.seconds||0),z=W=>String(W).padStart(2,"0");return`${z(p)}:${z(S)}`}},{title:"صوت",dataIndex:"src",key:"src",customRender:r=>r.record.src?"دارد":"-"},{title:"زمان ایجاد",dataIndex:"created_at",key:"created_at",customRender:r=>_t(r.record.created_at)},{title:"زمان انتشار",dataIndex:"time_show",key:"time_show",align:"center",width:180,customRender:r=>{const v=r.record.time_show;return v?_t(v,"jYYYY/jMM/jDD HH:mm:ss"):"-"}},{title:"وضعیت نمایش",dataIndex:"show",key:"show",align:"center",width:120,customRender:r=>r.record.show===!1?"مخفی":"نمایش"},{title:"عملیات",dataIndex:"action",key:"action",slot:"action",filterable:!1,align:"center"}];async function ce(r){const v=await Ft("storys",{title:r.title,sub_title:r.sub_title,cover:r.cover,src:r.src,time:r.time,book_id:r.book_id||null,time_show:r.time_show||null});return Array.isArray(v)?v:[v]}async function wt(r,v){const p=await Mt("storys",r,{title:v.title,sub_title:v.sub_title,cover:v.cover,src:v.src,time:v.time,book_id:v.book_id||null,time_show:v.time_show||null});return Array.isArray(p)?p:[p]}async function de(r,v){const p=await Mt("storys",r,{show:v});return Array.isArray(p)?p:[p]}async function me(r){await Et("storys",r)}async function ve(r){const{TableEngineRequest:v}=await it(()=>import("./buildSupabaseQuery-2323f568.js"),["assets/buildSupabaseQuery-2323f568.js","assets/index-1ba0f9ec.js","assets/index-cb402307.css"]),p={...r};!p.sort&&!p.order&&(p.order="-id"),p.select=["*","books!book_id(id, title, sub_title, cover)"];const S=await v(p,"storys");try{if(Array.isArray(S==null?void 0:S.rows)){const z=p.page||1,W=p.limit||20,w=(z-1)*W,I=S.rows.map((n,N)=>{const O=(Array.isArray(n.books)?n.books[0]:n.books)||{};return{...n,id:n.id,title:n.title??"",sub_title:n.sub_title??"",cover:n.cover??null,src:n.src??null,time:n.time??{minutes:0,seconds:0},book_id:n.book_id??null,book_title:O.title||null,book_sub_title:O.sub_title||null,book_cover:O.cover||null,created_at:n.created_at??"",time_show:n.time_show??null,show:n.show!==void 0?n.show:!0,index:w+N}});return{...S,rows:I}}}catch(z){console.error("[getStorysTable] Error:",z)}return S}async function fe(r){return se(r,"story")}async function kt(r,v){return ee(r,v,"story")}const he={class:"flex justify-between items-center mb-4"},pe=o("h2",null,"قصه ها",-1),_e={class:"gap-2 flex justify-center"},ge=o("span",null,"بازدیدها",-1),be=o("span",null,"حذف",-1),ye=o("span",null,"ویرایش",-1),xe=o("span",null,"مرتبط کردن کتاب",-1),we={class:"space-y-4 relative"},ke={key:0,class:"absolute inset-0 bg-white/60 z-10 flex items-center justify-center"},$e=o("div",{class:"mb-1 text-sm text-gray-600"},"عنوان",-1),De=o("div",{class:"mb-1 text-sm text-gray-600"},"زیرعنوان",-1),Me=o("div",{class:"mb-1 text-sm text-gray-600"},"کتاب مرتبط",-1),Te=o("div",{class:"mb-1 text-sm text-gray-600"},[ot(" زمان انتشار "),o("span",{class:"text-xs text-gray-500"},"(در صورت خالی گذاشتن این فیلد زمان حال ثبت می شود)")],-1),Ce={class:"flex gap-4"},Se={class:"flex-1 flex justify-center gap-4"},Ue=o("div",{class:"mb-1 text-sm text-gray-600"},"آپلود تصویر کاور",-1),Oe={key:0},Ye=o("div",null,"آپلود کاور",-1),Le={key:0,class:"mt-1"},Ie={class:"h-2 rounded bg-gray-200 overflow-hidden"},Re={class:"text-xs text-gray-700 font-semibold text-center mt-1"},ze=o("div",{class:"mb-1 text-sm text-gray-600"},"آپلود صوت (src)",-1),Ne={key:0},He=o("div",null,"آپلود صوت",-1),Pe={key:0,class:"text-xs text-gray-500 mt-1 text-center"},Ve={class:"h-2 rounded bg-gray-200 overflow-hidden"},Be={class:"text-xs text-gray-700 font-semibold text-center mt-1"},Ae={class:"flex-1"},je=o("div",{class:"mb-1 text-sm text-gray-600"},[ot("زمان "),o("span",{class:"text-xs text-gray-500"},"(بعد از آپلود صوت قصه زمان آن به صورت خودکار وارد می شود)")],-1),Fe={class:"space-y-2"},Ee=o("div",{class:"mb-1 text-xs text-gray-500"},"دقیقه",-1),We=o("div",{class:"mb-1 text-xs text-gray-500"},"ثانیه",-1),qe={class:"space-y-4"},Ze=o("div",{class:"mb-1 text-sm text-gray-600"},"کتاب مرتبط",-1),Je={class:"flex justify-end"},Ge={key:0,class:"space-y-4"},Xe={class:"grid grid-cols-2 gap-4"},Qe={class:"bg-blue-50 p-4 rounded-lg"},Ke=o("div",{class:"text-sm text-gray-600 mb-1"},"تعداد بازدید",-1),ts={class:"text-2xl font-bold text-blue-600"},es={class:"bg-purple-50 p-4 rounded-lg"},ss=o("div",{class:"text-sm text-gray-600 mb-1"},"تعداد بازدیدکننده",-1),os={class:"text-2xl font-bold text-purple-600"},is=o("div",{class:"text-sm font-semibold text-gray-700 mb-2"},"لیست بازدیدکننده‌ها",-1),as={key:0},ls={key:1,class:"text-center py-8 text-gray-500"},ns={key:1,class:"flex justify-center items-center py-8"},fo=Wt({__name:"index",setup(r){Z.extend(le),Z.extend(re);const v=ie,p={authorization:`Bearer ${gt()||localStorage.getItem("tamin_token")||""}`},[S,z]=ht(),W=M({columns:ue,api:ve,defaultPageLimit:20}),w=M(!1),I=M(!1),n=M(null),N=M([]),H=M([]),O=M(0),f=M(0),y=M(0),x=M([]),s=M(!1),h=M(null),D=M(!1),_=M(null),k=M(!1),P=M(null),[R,F]=ht(),B=M({columns:oe,api:t=>kt(t,P.value),defaultPageLimit:20}),c=M({title:"",sub_title:"",cover:null,src:null,time:{minutes:0,seconds:0},book_id:null,time_show:null}),V=M({book_id:null}),$=M(null),J=M(!1);let et=!1;ct(()=>c.value.time_show,t=>{if(et){et=!1;return}if(t)try{const e=Z(t);(!$.value||!e.isSame($.value))&&($.value=e)}catch{$.value=null}else $.value&&($.value=null)},{immediate:!0});function St(t,e){t?$.value=t:$.value=null}function Ut(t){if(t){et=!0;const i=t.calendar("gregory").locale("en").subtract(3,"hour").subtract(30,"minute").format("YYYY-MM-DD HH:mm:ss");c.value.time_show=i,$.value=t}else et=!0,c.value.time_show=null,$.value=null;J.value=!1}function Ot(){N.value=[],H.value=[],I.value=!1,n.value=null,c.value={title:"",sub_title:"",cover:null,src:null,time:{minutes:0,seconds:0},book_id:null,time_show:null},$.value=null,w.value=!0}function at(){w.value=!1}function Yt(t){return t.type.startsWith("audio/")?t.size/1024/1024<61?!0:(U.error("حجم فایل باید کمتر از 60MB باشد"),!1):(U.error("فقط فایل‌های صوتی مجاز است"),!1)}function Lt(t){const e=new Audio,l=URL.createObjectURL(t);e.addEventListener("loadedmetadata",()=>{const i=e.duration;if(i&&!isNaN(i)&&isFinite(i)){const b=Math.floor(i/60),L=Math.floor(i%60);c.value.time.minutes=b,c.value.time.seconds=L,U.info(`مدت زمان فایل صوتی: ${b} دقیقه و ${L} ثانیه`)}URL.revokeObjectURL(l)}),e.addEventListener("error",()=>{URL.revokeObjectURL(l),console.warn("Could not determine audio duration from file")}),e.src=l}async function It(t){const{file:e,onSuccess:l,onError:i,onProgress:b}=t;Lt(e);const L=new FormData;L.append("file",e);const q=`${ft}/upload/machartaa-audio`;f.value=0,O.value++,await new Promise((a,T)=>{const u=new XMLHttpRequest;u.open("POST",q),u.setRequestHeader("Authorization",`Bearer ${localStorage.getItem("tamin_token")||""}`),u.timeout=15*60*1e3,u.upload.onprogress=m=>{if(m.lengthComputable){const d=Math.round(m.loaded/m.total*100);f.value=d,b==null||b({percent:d})}},u.onload=()=>{if(f.value=100,u.status>=200&&u.status<300)try{const m=JSON.parse(u.responseText||"{}"),d=m.full_src||m.url||m.src||m.path||m.data&&(m.data.full_src||m.data.url||m.data.src||m.data.path)||"";let Y=d;d!=null&&d.startsWith("http")&&(Y=d.replace(/^https?:\/\/[^\/]+/,""));const G=st(Y);c.value.src=Y,N.value=G?[{uid:`${Date.now()}`,name:"audio.mp3",status:"done",url:G,response:{path:Y}}]:[],l==null||l(m,u),U.success("صوت با موفقیت آپلود شد!"),a()}catch(m){i==null||i(m,u),T(m)}else if(u.status===413){const m=new Error("حجم فایل خیلی بزرگ است. لطفاً فایل کوچکتری انتخاب کنید.");U.error("حجم فایل خیلی بزرگ است. لطفاً فایل کوچکتری انتخاب کنید."),i==null||i(m,u),T(m)}else{let m="خطا در آپلود فایل";try{const Y=JSON.parse(u.responseText||"{}");Y.message?m=Y.message:Y.error&&(m=Y.error)}catch{}const d=new Error(m);U.error(m),i==null||i(d,u),T(d)}},u.onerror=()=>{const m=new Error("خطا در آپلود صوت");i==null||i(m,u),T(m)},u.ontimeout=()=>{const m=new Error("آپلود timeout شد - فایل خیلی بزرگ است");i==null||i(m,u),T(m)},u.onloadend=()=>{O.value=Math.max(0,O.value-1),f.value=0},u.send(L)})}function lt(t){return{width:`${Math.max(0,Math.min(100,t))}%`}}function Rt(t){return t.type.startsWith("image/")?t.size/1024/1024<5?!0:(U.error("حجم تصویر باید کمتر از 5MB باشد"),!1):(U.error("فقط فایل‌های تصویری مجاز است"),!1)}async function zt(t){const{file:e,onSuccess:l,onError:i,onProgress:b}=t,L=new FormData;L.append("file",e);const q=`${ft}/upload/machartaa-img`;y.value=0,O.value++,await new Promise((a,T)=>{const u=new XMLHttpRequest;u.open("POST",q);const m=gt()||localStorage.getItem("tamin_token")||"";u.setRequestHeader("Authorization",`Bearer ${m}`),u.upload.onprogress=d=>{if(d.lengthComputable){const Y=Math.round(d.loaded/d.total*100);y.value=Y,b==null||b({percent:Y})}},u.onload=()=>{if(y.value=100,u.status>=200&&u.status<300)try{const d=JSON.parse(u.responseText||"{}"),Y=d.full_src||d.url||d.src||d.path||d.data&&(d.data.full_src||d.data.url||d.data.src||d.data.path)||"";let G=Y;Y!=null&&Y.startsWith("http")&&(G=Y.replace(/^https?:\/\/[^\/]+/,""));const ut=st(G);c.value.cover=G,H.value=ut?[{uid:`${Date.now()}`,name:"cover.jpg",status:"done",url:ut,response:{path:G}}]:[],l==null||l(d,u),U.success("کاور با موفقیت آپلود شد!"),a()}catch(d){i==null||i(d,u),T(d)}else{const d=new Error("خطا در آپلود تصویر");i==null||i(d,u),T(d)}},u.onerror=()=>{const d=new Error("خطا در آپلود کاور");i==null||i(d,u),T(d)},u.onloadend=()=>{O.value=Math.max(0,O.value-1),y.value=0},u.send(L)})}async function Nt(){var l,i,b,L,q,a;if(!((l=c.value.title)!=null&&l.trim()))return;if(O.value>0){U.warning("لطفاً تا پایان آپلود صبر کنید");return}let t=c.value.time_show;if(!t||t.trim()==="")t=Z().calendar("gregory").locale("en").subtract(3,"hour").subtract(30,"minute").format("YYYY-MM-DD HH:mm:ss");else try{Z(t).isValid()||(t=Z(t).locale("fa").calendar("gregory").locale("en").subtract(3,"hour").subtract(30,"minute").format("YYYY-MM-DD HH:mm:ss"))}catch{t=Z().calendar("gregory").locale("en").subtract(3,"hour").subtract(30,"minute").format("YYYY-MM-DD HH:mm:ss")}const e={title:c.value.title.trim(),sub_title:((i=c.value.sub_title)==null?void 0:i.trim())||"",cover:((b=c.value.cover)==null?void 0:b.trim())||null,src:((L=c.value.src)==null?void 0:L.trim())||null,time:{minutes:Number((q=c.value.time)==null?void 0:q.minutes)||0,seconds:Number((a=c.value.time)==null?void 0:a.seconds)||0},book_id:c.value.book_id||null,time_show:t};try{I.value&&n.value?(await wt(n.value,e),U.success("قصه با موفقیت ویرایش شد")):(await ce(e),U.success("قصه با موفقیت افزوده شد")),at(),await z()}catch(T){console.error("Error saving story:",T),U.error("خطا در ذخیره قصه: "+(T.message||"خطای ناشناخته"))}}function Ht(t){I.value=!0,n.value=t.id;let e=t.cover||null;e&&e.startsWith("http")&&(e=e.replace(/^https?:\/\/[^\/]+/,""));let l=t.src||null;l&&l.startsWith("http")&&(l=l.replace(/^https?:\/\/[^\/]+/,"")),c.value={title:t.title||"",sub_title:t.sub_title||"",cover:e,src:l,time:t.time&&typeof t.time=="object"?{minutes:Number(t.time.minutes)||0,seconds:Number(t.time.seconds)||0}:{minutes:0,seconds:0},book_id:t.book_id||null,time_show:t.time_show||null},t.time_show?$.value=Z(t.time_show):$.value=null;const i=l?st(l):null,b=e?st(e):null;N.value=i?[{uid:"-1",name:"audio.mp3",status:"done",url:i,response:{path:l}}]:[],H.value=b?[{uid:"-2",name:"cover.jpg",status:"done",url:b,response:{path:e}}]:[],w.value=!0}function Pt(t){h.value=t.id,V.value={book_id:t.book_id||null},s.value=!0}function nt(){s.value=!1,h.value=null,V.value={book_id:null}}async function Vt(){if(h.value)try{const{adminResourceGet:t}=await it(()=>import("./index-1ba0f9ec.js").then(L=>L.c0),["assets/index-1ba0f9ec.js","assets/index-cb402307.css"]),e=await t("storys",h.value);if(!e){U.error("قصه یافت نشد");return}let l=e.cover||null;l&&l.startsWith("http")&&(l=l.replace(/^https?:\/\/[^\/]+/,""));let i=e.src||null;i&&i.startsWith("http")&&(i=i.replace(/^https?:\/\/[^\/]+/,""));const b={title:e.title||"",sub_title:e.sub_title||"",cover:l,src:i,time:e.time&&typeof e.time=="object"?{minutes:Number(e.time.minutes)||0,seconds:Number(e.time.seconds)||0}:{minutes:0,seconds:0},book_id:V.value.book_id||null};await wt(h.value,b),U.success("کتاب با موفقیت مرتبط شد"),nt(),await z()}catch(t){console.error("Error linking book:",t),U.error("خطا در مرتبط کردن کتاب: "+(t.message||"خطای ناشناخته"))}}qt(async()=>{try{const{getBooks:t}=await it(()=>import("./books-c52edb11.js"),["assets/books-c52edb11.js","assets/index-1ba0f9ec.js","assets/index-cb402307.css"]),e=await t();x.value=e||[]}catch(t){console.error("Error loading books:",t)}});async function Bt(t){const l=(t==null?void 0:t.show)===!1,i=!!l;bt.confirm({title:l?"نمایش دادن قصه":"مخفی کردن قصه",content:l?`آیا مطمئن هستید که می‌خواهید قصه "${t.title}" را نمایش دهید؟`:`آیا مطمئن هستید که می‌خواهید قصه "${t.title}" را مخفی کنید؟`,okText:l?"بله، نمایش بده":"بله، مخفی کن",cancelText:"انصراف",okType:"default",centered:!0,onOk:async()=>{try{await de(t.id,i),U.success(l?"قصه با موفقیت نمایش داده شد":"قصه با موفقیت مخفی شد"),await z()}catch(b){console.error("Error toggling show:",b),U.error("خطا در تغییر وضعیت قصه: "+(b.message||"خطای ناشناخته"))}}})}function At(t){bt.confirm({title:"حذف قصه",content:`آیا مطمئن هستید که می‌خواهید قصه "${t.title}" را حذف کنید؟`,okText:"بله، حذف کن",cancelText:"انصراف",okType:"danger",centered:!0,onOk:async()=>{await me(t.id),await z()}})}async function jt(t){P.value=t.id,D.value=!0,k.value=!0,_.value=null;try{const e=await fe(t.id);_.value=e,B.value.api=l=>kt(l,t.id)}catch(e){console.error("Error loading views:",e),U.error("خطا در بارگذاری اطلاعات بازدیدها: "+(e.message||"خطای ناشناخته"))}finally{k.value=!1}}ct([D,_],async([t,e])=>{if(t&&e&&e.total_views>0){await dt(),await dt();try{await F()}catch{setTimeout(async()=>{try{await F()}catch(i){console.warn("Could not reload viewers table:",i)}},200)}}},{immediate:!1});function rt(){D.value=!1,_.value=null,P.value=null}return(t,e)=>{const l=te,i=Kt,b=Qt,L=Xt,q=Gt;return j(),E("div",null,[g(q,null,{default:C(()=>[o("div",he,[pe,g(l,{type:"primary",onClick:Ot},{default:C(()=>[ot("افزودن قصه")]),_:1})]),g(i,mt(W.value,{ref:"table",onRegister:A(S)}),{action:C(({record:a})=>[o("div",_e,[g(A(tt),{class:"cursor-pointer"},{title:C(()=>[ge]),default:C(()=>[g(Q,{icon:"vuesax-linear:monitor",color:"#8B5CF6",onClick:T=>jt(a)},null,8,["onClick"])]),_:2},1024),g(A(tt),{class:"cursor-pointer"},{title:C(()=>[o("span",null,K((a==null?void 0:a.show)===!1?"نمایش دادن":"مخفی کردن"),1)]),default:C(()=>[g(Q,{icon:(a==null?void 0:a.show)===!1?"vuesax-linear:eye":"vuesax-linear:eye-slash",color:(a==null?void 0:a.show)===!1?"#10B981":"#F59E0B",onClick:T=>Bt(a)},null,8,["icon","color","onClick"])]),_:2},1024),g(A(tt),{class:"cursor-pointer"},{title:C(()=>[be]),default:C(()=>[g(Q,{icon:"vuesax-linear:trash",color:"#DC2626",onClick:T=>At(a)},null,8,["onClick"])]),_:2},1024),g(A(tt),{class:"cursor-pointer"},{title:C(()=>[ye]),default:C(()=>[g(Q,{icon:"vuesax-linear:edit",color:"#1D4ED8",onClick:T=>Ht(a)},null,8,["onClick"])]),_:2},1024),a!=null&&a.book_id?X("",!0):(j(),Zt(A(tt),{key:0,class:"cursor-pointer"},{title:C(()=>[xe]),default:C(()=>[g(Q,{icon:"vuesax-linear:book",color:"#217346",onClick:T=>Pt(a)},null,8,["onClick"])]),_:2},1024))])]),_:1},16,["onRegister"]),g(L,{visible:w.value,"onUpdate:visible":e[9]||(e[9]=a=>w.value=a),title:I.value?"ویرایش قصه":"افزودن قصه",onOk:Nt,onCancel:at,width:"80%",confirmLoading:O.value>0},{default:C(()=>[o("div",we,[O.value>0?(j(),E("div",ke,[g(A(yt),{size:"large"})])):X("",!0),o("div",null,[$e,g(b,{value:c.value.title,"onUpdate:value":e[0]||(e[0]=a=>c.value.title=a),placeholder:"عنوان"},null,8,["value"])]),o("div",null,[De,g(b,{value:c.value.sub_title,"onUpdate:value":e[1]||(e[1]=a=>c.value.sub_title=a),placeholder:"زیرعنوان"},null,8,["value"])]),o("div",null,[Me,g(pt,{value:c.value.book_id??void 0,"onUpdate:value":e[2]||(e[2]=a=>c.value.book_id=a??null),items:x.value,keyName:"id",valueName:"title",placeholder:"انتخاب کتاب",allowClear:!0},null,8,["value","items"])]),o("div",null,[Te,g(A(v),{value:$.value,"onUpdate:value":e[3]||(e[3]=a=>$.value=a),open:J.value,"onUpdate:open":e[4]||(e[4]=a=>J.value=a),locale:A(Jt),"show-time":{format:"HH:mm:ss"},format:"YYYY-MM-DD HH:mm:ss",placeholder:"انتخاب تاریخ و زمان انتشار",class:"w-full",onChange:St,onOk:Ut},null,8,["value","open","locale"])]),o("div",Ce,[o("div",Se,[o("div",null,[Ue,g(A(xt),{"file-list":H.value,"onUpdate:fileList":e[5]||(e[5]=a=>H.value=a),"before-upload":Rt,"custom-request":zt,headers:p,accept:"image/jpeg,image/png,image/webp,image/gif,image/heic,image/heif,.jpg,.jpeg,.png,.webp,.gif,.heic,.heif","max-count":1,"list-type":"picture-card"},{default:C(()=>[H.value.length<1?(j(),E("div",Oe,[g(Q,{icon:"vuesax-linear:image",class:"text-2xl mb-2"}),Ye])):X("",!0)]),_:1},8,["file-list"]),y.value>0&&y.value<100?(j(),E("div",Le,[o("div",Ie,[o("div",{class:"h-2 bg-blue-500 transition-all",style:vt(lt(y.value))},null,4)]),o("div",Re,K(y.value)+"%",1)])):X("",!0)]),o("div",null,[ze,g(A(xt),{"file-list":N.value,"onUpdate:fileList":e[6]||(e[6]=a=>N.value=a),"before-upload":Yt,"custom-request":It,headers:p,accept:"audio/*","max-count":1,"list-type":"picture-card"},{default:C(()=>[N.value.length<1?(j(),E("div",Ne,[g(Q,{icon:"vuesax-linear:music",class:"text-2xl mb-2"}),He])):X("",!0)]),_:1},8,["file-list"]),f.value>0&&f.value<100?(j(),E("div",Pe,[o("div",Ve,[o("div",{class:"h-2 bg-blue-500 transition-all",style:vt(lt(f.value))},null,4)]),o("div",Be,K(f.value)+"%",1)])):X("",!0)])]),o("div",Ae,[je,o("div",Fe,[o("div",null,[Ee,g(b,{value:c.value.time.minutes,"onUpdate:value":e[7]||(e[7]=a=>c.value.time.minutes=a),type:"number",placeholder:"0",disabled:!0},null,8,["value"])]),o("div",null,[We,g(b,{value:c.value.time.seconds,"onUpdate:value":e[8]||(e[8]=a=>c.value.time.seconds=a),type:"number",placeholder:"0",disabled:!0},null,8,["value"])])])])])])]),_:1},8,["visible","title","confirmLoading"]),g(L,{visible:s.value,"onUpdate:visible":e[11]||(e[11]=a=>s.value=a),title:"مرتبط کردن کتاب",onOk:Vt,onCancel:nt,width:"500px"},{default:C(()=>[o("div",qe,[o("div",null,[Ze,g(pt,{value:V.value.book_id??void 0,"onUpdate:value":e[10]||(e[10]=a=>V.value.book_id=a??null),items:x.value,keyName:"id",valueName:"title",placeholder:"انتخاب کتاب",allowClear:!0},null,8,["value","items"])])])]),_:1},8,["visible"]),g(L,{visible:D.value,"onUpdate:visible":e[12]||(e[12]=a=>D.value=a),title:"اطلاعات بازدیدها",onCancel:rt,width:"800px",customFooter:!0,okText:""},{footer:C(()=>[o("div",Je,[g(l,{onClick:rt},{default:C(()=>[ot("بستن")]),_:1})])]),default:C(()=>[_.value?(j(),E("div",Ge,[o("div",Xe,[o("div",Qe,[Ke,o("div",ts,K(_.value.total_views),1)]),o("div",es,[ss,o("div",os,K(_.value.unique_viewers),1)])]),o("div",null,[is,_.value&&_.value.total_views>0?(j(),E("div",as,[g(i,mt(B.value,{onRegister:A(R)}),null,16,["onRegister"])])):(j(),E("div",ls," هنوز بازدیدی ثبت نشده است "))])])):k.value?(j(),E("div",ns,[g(A(yt),{size:"large"})])):X("",!0)]),_:1},8,["visible"])]),_:1})])}}});export{fo as default};