2 lines
16 KiB
JavaScript
2 lines
16 KiB
JavaScript
import{_ as ue}from"./BasicMainCard-f5011b39.js";import{_ as _e}from"./BasicModal.vue_vue_type_style_index_0_lang-a547157a.js";import{_ as pe}from"./BasicTextArea.vue_vue_type_style_index_0_lang-5cc0457f.js";import{_ as me,a as he,u as G}from"./useBaseTable-13b436e1.js";import{_ as fe}from"./BasicInput.vue_vue_type_style_index_0_lang-5aefde0f.js";import{_ as ge}from"./button.vue_vue_type_style_index_0_lang-851afdd8.js";import{I as S,_ as ve,d as xe,g as T,A as ye,o as q,c as A,b as l,w as v,j as I,a as s,e as we,G as X,t as j,k as W,z as be,F as ke,p as Se,D as b,H as Q,a8 as Ce,a9 as Ie}from"./index-82b07f49.js";import{t as H}from"./useDataTime-10f46d84.js";import{I as D}from"./Icon-04c02c0b.js";import{a as Y}from"./index-a4d2dbbb.js";import{M as Ue}from"./index-5dc3a2fa.js";import{S as Te}from"./index-1f61ecf5.js";import{T as V}from"./shallowequal-17b27246.js";import{U as Me}from"./index-0f0f5d8d.js";import{_ as $e}from"./_plugin-vue_export-helper-f81f33f1.js";import"./index-ad11eb53.js";import"./Col-5d52aed9.js";import"./vnode-007df887.js";import"./isPlainObject-f3a46277.js";import"./index-c6d6dccd.js";import"./FormItemContext-f4f190fd.js";import"./index-7e5faec0.js";import"./toArray-e3bbd719.js";import"./pickAttrs-b9acd388.js";import"./useState-e0a5bff5.js";import"./index-d634ff29.js";import"./usePrice-7afab779.js";import"./useRefs-e9385981.js";import"./index-2a5d6560.js";function Z(e,i){return i.map((n,c)=>({challenge_id:e,step_order:c+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 qe(e){const{data:i,error:n}=await S.from("step_challenges").select("*").eq("id",e).single();if(n)throw n;const{data:c,error:p}=await S.from("step_challenge_steps").select("*").eq("challenge_id",e).order("step_order",{ascending:!0});if(p)throw p;return{...i,steps:(c||[]).map(m=>({...m,duration_minutes:Math.round((m.duration_seconds||60)/60)}))}}async function Ae(e,i){const{data:n,error:c}=await S.from("step_challenges").insert([{title:e.title,character_image_url:e.character_image_url,show:e.show??!1,sort_order:e.sort_order??0,owner_id:i||null}]).select().single();if(c)throw c;const p=Z(n.id,e.steps),{error:m}=await S.from("step_challenge_steps").insert(p);if(m)throw m;return n}async function Le(e,i){const{error:n}=await S.from("step_challenges").update({title:i.title,character_image_url:i.character_image_url,show:i.show??!1,sort_order:i.sort_order??0,updated_at:new Date().toISOString()}).eq("id",e);if(n)throw n;const{error:c}=await S.from("step_challenge_steps").delete().eq("challenge_id",e);if(c)throw c;const p=Z(e,i.steps),{error:m}=await S.from("step_challenge_steps").insert(p);if(m)throw m;return{id:e}}async function Be(e){const{error:i}=await S.from("step_challenges").delete().eq("id",e);if(i)throw i}async function Re(e,i){const{data:n,error:c}=await S.from("step_challenges").update({...i,updated_at:new Date().toISOString()}).eq("id",e).select();if(c)throw c;return n}async function De(e){const{TableEngineRequest:i}=await ve(()=>import("./buildSupabaseQuery-4056c4b8.js"),["assets/buildSupabaseQuery-4056c4b8.js","assets/index-82b07f49.js","assets/index-f86b861c.css"]),n={...e};!n.sort&&!n.order&&(n.order="-id");const c=await i(n,"step_challenges");try{if(Array.isArray(c==null?void 0:c.rows)){const p=c.rows,m=p.map(r=>r.id).filter(Boolean);let C={};if(m.length>0){const{data:r}=await S.from("step_challenge_steps").select("id, challenge_id, step_order, duration_seconds").in("challenge_id",m);C=(r||[]).reduce((u,a)=>(u[a.challenge_id]||(u[a.challenge_id]=[]),u[a.challenge_id].push(a),u),{})}const P=n.page||1,k=n.limit||20,M=(P-1)*k,E=p.map((r,u)=>{const a=C[r.id]||[],U=a.reduce((d,z)=>d+Math.round((z.duration_seconds||0)/60),0);return{...r,index:M+u,steps_count:a.length,total_minutes:U}});return{...c,rows:E}}}catch(p){console.log("[getStepChallengesTable] normalize error:",p)}return c}async function Pe(e){const{limit:i=20,page:n=1,se
|