2026-06-17 14:16:43 +03:30
|
|
|
import{_ as ge}from"./BasicMainCard-d587bd1b.js";import{_ as ve}from"./BasicModal.vue_vue_type_style_index_0_lang-b6f776a2.js";import{_ as ye}from"./BasicTextArea.vue_vue_type_style_index_0_lang-89f52309.js";import{_ as xe,a as we,u as Q}from"./useBaseTable-b3483437.js";import{_ as be}from"./BasicInput.vue_vue_type_style_index_0_lang-3f67ac52.js";import{_ as ke}from"./button.vue_vue_type_style_index_0_lang-670ebdf7.js";import{I as C,_ as Se,d as Ie,g as A,A as Ce,o as P,c as B,b as o,w as p,j as b,a as s,e as j,G as Y,t as V,k as W,y as Ue,F as $e,n as Te,D as S,J as Me,K as Ae,H as Re}from"./index-ec71f3f7.js";import{d as qe,e as Pe,f as Be}from"./supabaseTableQuery-48420152.js";import{t as H}from"./useDataTime-c77a5d27.js";import{I as z}from"./Icon-7e71129c.js";import{e as Z,g as ee}from"./convert-67c23be8.js";import{T as te}from"./index-1856af53.js";import{M as De}from"./index-8dd0eae2.js";import{S as Ee}from"./index-415c9c8e.js";import{S as se}from"./fa_IR-c2785588.js";import{T as K}from"./shallowequal-d184109e.js";import{U as Le}from"./index-abbfc6d2.js";import{_ as Oe}from"./_plugin-vue_export-helper-93085e13.js";import"./index-6d78e32d.js";import"./index-7e8c40b1.js";import"./Col-137c655a.js";import"./vnode-abb83d2f.js";import"./isPlainObject-fa667e03.js";import"./index-87a6a3b3.js";import"./FormItemContext-343cf89e.js";import"./useState-f67c0555.js";import"./lodash-6639d8f5.js";import"./index-8157723e.js";import"./pickAttrs-0202eba3.js";import"./toArray-eb32ddb8.js";import"./usePrice-bc935b83.js";import"./useRefs-a516dbdb.js";import"./index-055a3fbb.js";function ae(e,r){return r.map((n,l)=>({challenge_id:e,step_order:l+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 ze(e){const{data:r,error:n}=await C.from("step_challenges").select("*").eq("id",e).single();if(n)throw n;const{data:l,error:c}=await C.from("step_challenge_steps").select("*").eq("challenge_id",e).order("step_order",{ascending:!0});if(c)throw c;return{...r,steps:(l||[]).map(h=>({...h,duration_minutes:Math.round((h.duration_seconds||60)/60)}))}}async function Fe(e,r){const{data:n,error:l}=await C.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:r||null}]).select().single();if(l)throw l;const c=ae(n.id,e.steps),{error:h}=await C.from("step_challenge_steps").insert(c);if(h)throw h;return n}async function Ne(e,r){const{error:n}=await C.from("step_challenges").update({title:r.title,character_image_url:r.character_image_url,show:r.show??!1,access_type:r.access_type??"free",sort_order:r.sort_order??0,updated_at:new Date().toISOString()}).eq("id",e);if(n)throw n;const{error:l}=await C.from("step_challenge_steps").delete().eq("challenge_id",e);if(l)throw l;const c=ae(e,r.steps),{error:h}=await C.from("step_challenge_steps").insert(c);if(h)throw h;return{id:e}}async function je(e){const{error:r}=await C.from("step_challenges").delete().eq("id",e);if(r)throw r}async function Ve(e,r){const{data:n,error:l}=await C.from("step_challenges").update({...r,updated_at:new Date().toISOString()}).eq("id",e).select();if(l)throw l;return n}async function We(e){const{TableEngineRequest:r}=await Se(()=>import("./buildSupabaseQuery-d2c8ff03.js"),["assets/buildSupabaseQuery-d2c8ff03.js","assets/index-ec71f3f7.js","assets/index-f5b104f4.css"]),n={...e};!n.sort&&!n.order&&(n.order="-id");const l=await r(n,"step_challenges");try{if(Array.isArray(l==null?void 0:l.rows)){const c=l.rows,h=c.map(y=>y.id).filter(Boolean);let I={};if(h.length>0){const{data:y}=await C.from("step_challenge_steps").select("id, challenge_id, step_order, duration_seconds").in("challenge_id",h);I=(y||[]).reduce((M,v)=>(M[v.challenge_id]||(M[v.challenge_id]=[]),M[v.challenge_id].push(v),M),{})}const T=n.page||1,u=n.limit||20,i=(T-1)*u,U=c.map((y,M)=>{const v=I[y.id]||[],R=v.reduce(
|