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-89ffa310.js";import{_ as Me}from"./BasicMainCard-6d707328.js";import{M as Ce,_ as Se}from"./BasicModal.vue_vue_type_style_index_0_lang-a11eae64.js";import{_ as Ie}from"./BasicInput.vue_vue_type_style_index_0_lang-392b5b97.js";import{_ as Ue}from"./index-ccdd9f59.js";import{_ as Be}from"./button.vue_vue_type_style_index_0_lang-ad1ddd30.js";import{I as q}from"./Icon-71136976.js";import{_ as se}from"./BasicSelect.vue_vue_type_style_index_0_lang-83b33a8f.js";import{u as Le}from"./useBaseTable-3aeb2499.js";import{t as ie}from"./useDataTime-8307199e.js";import{getBooks as Te}from"./books-a083f4eb.js";import{S as oe}from"./index-d95ef8ac.js";import{T as j}from"./styleChecker-47862663.js";import{U as ae}from"./index-816ff657.js";import"./_plugin-vue_export-helper-0eb14515.js";import"./index-956b313f.js";import"./useState-33268b88.js";import"./vnode-75acd593.js";import"./Col-fc0de6a1.js";import"./index-7d158bfa.js";import"./usePrice-7afab779.js";import"./index-a33d0202.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-64b2d9ac.js"),["assets/buildSupabaseQuery-64b2d9ac.js","assets/index-89ffa310.js","assets/index-c73797be.css"]),{getBooks:f}=await X(()=>import("./books-a083f4eb.js"),["assets/books-a083f4eb.js","assets/index-89ffa310.js","assets/index-c73797be.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(
|