2026-06-08 13:46:58 +03:30
|
|
|
import{_ as ge}from"./BasicMainCard-6a209b66.js";import{_ as ve}from"./BasicModal.vue_vue_type_style_index_0_lang-5906452a.js";import{_ as ye}from"./BasicTextArea.vue_vue_type_style_index_0_lang-59a988dc.js";import{_ as xe,a as we,u as Q}from"./useBaseTable-36a578d2.js";import{_ as be}from"./BasicInput.vue_vue_type_style_index_0_lang-1d8eafa9.js";import{_ as Se}from"./button.vue_vue_type_style_index_0_lang-8d279d3c.js";import{H as T,_ as ke,d as Ce,g as M,z as Ie,o as R,c as B,b as r,w as _,j as b,a as s,e as j,E as Y,t as V,k as W,y as Ue,F as Te,n as Me,C,I as qe,J as Ae,G as $e}from"./index-23e11ebb.js";import{t as J}from"./useDataTime-9d6aa2eb.js";import{I as O}from"./Icon-66e4762f.js";import{e as Z,g as ee}from"./convert-67c23be8.js";import{T as te}from"./index-edb526a6.js";import{M as Le}from"./index-9227ec88.js";import{S as Re}from"./index-1e67613f.js";import{S as se}from"./fa_IR-7046f8f0.js";import{T as H}from"./shallowequal-c0c30dbc.js";import{U as Be}from"./index-46cbdc62.js";import{_ as Pe}from"./_plugin-vue_export-helper-80f83411.js";import"./index-1da12123.js";import"./Col-2dd17677.js";import"./vnode-c21a367b.js";import"./isPlainObject-b53c2fec.js";import"./index-956ab9e6.js";import"./FormItemContext-28dcc8c8.js";import"./useState-9bab46e8.js";import"./lodash-94e4bf0b.js";import"./index-464e86be.js";import"./pickAttrs-deed8a82.js";import"./toArray-b4b91f87.js";import"./usePrice-7afab779.js";import"./useRefs-c7f510f3.js";import"./index-a973200c.js";function ae(e,l){return l.map((n,i)=>({challenge_id:e,step_order:i+1,description:n.description,duration_seconds:Math.max(1,Math.round(Number(n.duration_minutes)*60)),aparat_embed_code:n.aparat_embed_code||null,punishment_description:n.punishment_description,requires_photo_upload:!!n.requires_photo_upload}))}async function De(e){const{data:l,error:n}=await T.from("step_challenges").select("*").eq("id",e).single();if(n)throw n;const{data:i,error:h}=await T.from("step_challenge_steps").select("*").eq("challenge_id",e).order("step_order",{ascending:!0});if(h)throw h;return{...l,steps:(i||[]).map(f=>({...f,duration_minutes:Math.round((f.duration_seconds||60)/60)}))}}async function Ee(e,l){const{data:n,error:i}=await T.from("step_challenges").insert([{title:e.title,character_image_url:e.character_image_url,show:e.show??!1,access_type:e.access_type??"free",sort_order:e.sort_order??0,owner_id:l||null}]).select().single();if(i)throw i;const h=ae(n.id,e.steps),{error:f}=await T.from("step_challenge_steps").insert(h);if(f)throw f;return n}async function ze(e,l){const{error:n}=await T.from("step_challenges").update({title:l.title,character_image_url:l.character_image_url,show:l.show??!1,access_type:l.access_type??"free",sort_order:l.sort_order??0,updated_at:new Date().toISOString()}).eq("id",e);if(n)throw n;const{error:i}=await T.from("step_challenge_steps").delete().eq("challenge_id",e);if(i)throw i;const h=ae(e,l.steps),{error:f}=await T.from("step_challenge_steps").insert(h);if(f)throw f;return{id:e}}async function Oe(e){const{error:l}=await T.from("step_challenges").delete().eq("id",e);if(l)throw l}async function Fe(e,l){const{data:n,error:i}=await T.from("step_challenges").update({...l,updated_at:new Date().toISOString()}).eq("id",e).select();if(i)throw i;return n}async function Ne(e){const{TableEngineRequest:l}=await ke(()=>import("./buildSupabaseQuery-36c151c6.js"),["assets/buildSupabaseQuery-36c151c6.js","assets/index-23e11ebb.js","assets/index-e4e0eb6b.css"]),n={...e};!n.sort&&!n.order&&(n.order="-id");const i=await l(n,"step_challenges");try{if(Array.isArray(i==null?void 0:i.rows)){const h=i.rows,f=h.map(c=>c.id).filter(Boolean);let I={};if(f.length>0){const{data:c}=await T.from("step_challenge_steps").select("id, challenge_id, step_order, duration_seconds").in("challenge_id",f);I=(c||[]).reduce((m,o)=>(m[o.challenge_id]||(m[o.challenge_id]=[]),m[o.challenge_id].push(o),m),{})}const q=n.page||1,S=n.limit||20,A=(q-1)*S,L=h.map((c,m)=>{const o=I[c.id]||[],U=o.reduce((y,P)=>y+Math.round((P.duration_seconds||0)/60),0);return{...c,index:A+m,steps_count:o.length,total_min
|