2 lines
19 KiB
JavaScript
2 lines
19 KiB
JavaScript
import{a3 as X,a5 as H,d as ye,r as y,i as xe,o as I,c as U,b as m,w as x,a as e,e as ee,a2 as ge,L as A,K as ke,N as R,X as te,O as P,F as we,S as $e,a0 as k,a4 as V}from"./index-f88494bd.js";import{_ as Me}from"./BasicMainCard-60a9e3be.js";import{M as Ce,_ as Se}from"./BasicModal.vue_vue_type_style_index_0_lang-b8f611c9.js";import{_ as Ie}from"./BasicInput.vue_vue_type_style_index_0_lang-125d2adf.js";import{_ as Ue}from"./index-e3363e71.js";import{_ as Be}from"./button.vue_vue_type_style_index_0_lang-4a27af23.js";import{I as q}from"./Icon-521be6d5.js";import{_ as se}from"./BasicSelect.vue_vue_type_style_index_0_lang-7d035bf8.js";import{u as Le}from"./useBaseTable-3aeb2499.js";import{t as ie}from"./useDataTime-af5bdf6a.js";import{getBooks as Te}from"./books-f7337f63.js";import{S as oe}from"./index-b33f7a92.js";import{T as j}from"./styleChecker-82cb676b.js";import{U as ae}from"./index-49fa9b7c.js";import"./_plugin-vue_export-helper-197f9e2b.js";import"./index-7504b32f.js";import"./useState-63c0655b.js";import"./vnode-a7883726.js";import"./Col-222f359d.js";import"./index-cb8a0c0b.js";import"./usePrice-7afab779.js";import"./index-518b6476.js";const Ne=[{title:"ردیف",dataIndex:"id",key:"id",filterable:!1,width:70,align:"center",customRender:c=>c.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:c=>{const r=c.record.book_title,f=c.record.book_id;return r||(f?`کتاب #${f}`:"-")}},{title:"زمان",dataIndex:"time",key:"time",customRender:c=>{const r=c.record.time||{minutes:0,seconds:0},f=Number(r.minutes||0),w=Number(r.seconds||0),g=S=>String(S).padStart(2,"0");return`${g(f)}:${g(w)}`}},{title:"صوت",dataIndex:"src",key:"src",customRender:c=>c.record.src?"دارد":"-"},{title:"زمان ایجاد",dataIndex:"created_at",key:"created_at",customRender:c=>ie(c.record.created_at)},{title:"عملیات",dataIndex:"action",key:"action",slot:"action",filterable:!1,align:"center"}];async function De(c){const{data:r,error:f}=await H.from("storys").insert([{title:c.title,sub_title:c.sub_title,cover:c.cover,src:c.src,time:c.time,book_id:c.book_id||null}]).select();if(f)throw f;return r}async function le(c,r){const{data:f,error:w}=await H.from("storys").update({title:r.title,sub_title:r.sub_title,cover:r.cover,src:r.src,time:r.time,book_id:r.book_id||null}).eq("id",c).select();if(w)throw w;return f}async function Ae(c){const{error:r}=await H.from("storys").delete().eq("id",c);if(r)throw r}async function Pe(c){const{TableEngineRequest:r}=await X(()=>import("./buildSupabaseQuery-aadb09f5.js"),["assets/buildSupabaseQuery-aadb09f5.js","assets/index-f88494bd.js","assets/index-9eba4347.css"]),{getBooks:f}=await X(()=>import("./books-f7337f63.js"),["assets/books-f7337f63.js","assets/index-f88494bd.js","assets/index-9eba4347.css"]),w={...c};!w.sort&&!w.order&&(w.order="-id");const g=await r(w,"storys");try{if(Array.isArray(g==null?void 0:g.rows)){let S=new Map;try{const d=await f();Array.isArray(d)&&d.forEach(i=>{i.id&&i.title&&S.set(i.id,i.title)})}catch(d){console.log("[getStorysTable] Error loading books:",d)}const B=w.page||1,L=w.limit||200,h=(B-1)*L,$=g.rows.map((d,i)=>({id:d.id,title:d.title??"",sub_title:d.sub_title??"",cover:d.cover??null,src:d.src??null,time:d.time??{minutes:0,seconds:0},book_id:d.book_id??null,book_title:d.book_id&&S.get(d.book_id)||null,created_at:d.created_at??"",index:h+i,...d}));return{...g,rows:$}}}catch(S){console.log("[getStorysTable] normalize error:",S)}return g}async function Re(c){try{const{data:r,error:f}=await H.from("user_views").select("*, users!user_id(id, first_name, last_name, phone, name, email, username)").eq("item_id",c).order("viewed_at",{ascending:!1});if(f)throw console.error("[getStoryViews] Error fetching views:",f),f;const w=(r==null?void 0:r.length)||0,S=new Set((r==null?void 0:r.map(h=>h.user_id).filter(Boolean))||[]).size,B=new Map;(r||[]).forEach(h=>{const $=h.user_id;if($&&!B.has($)){const i=(Array.isArray(
|