2026-06-04 15:16:36 +03:30
|
|
|
import{_ as ge}from"./BasicMainCard-870e6a2f.js";import{_ as ve}from"./BasicModal.vue_vue_type_style_index_0_lang-726d71cc.js";import{_ as ye}from"./BasicTextArea.vue_vue_type_style_index_0_lang-65d10079.js";import{_ as xe,a as we,u as Q}from"./useBaseTable-54b44400.js";import{_ as be}from"./BasicInput.vue_vue_type_style_index_0_lang-d9dc6382.js";import{_ as Se}from"./button.vue_vue_type_style_index_0_lang-25794594.js";import{I as T,_ as ke,d as Ie,g as M,A as Ce,o as R,c as B,b as r,w as _,j as b,a as s,e as j,G as Y,t as V,k as W,z as Ue,F as Te,p as Me,D as I,a8 as Ae,a9 as qe,H as $e}from"./index-4139499d.js";import{t as K}from"./useDataTime-6fbd057f.js";import{I as O}from"./Icon-b81ad543.js";import{e as Z,g as ee}from"./convert-67c23be8.js";import{T as te}from"./index-32f1bdce.js";import{M as Le}from"./index-3fee3d89.js";import{S as Re}from"./index-975727f6.js";import{S as se}from"./index-862849ae.js";import{T as H}from"./shallowequal-26ff1c74.js";import{U as Be}from"./index-ef8c1567.js";import{_ as Pe}from"./_plugin-vue_export-helper-c6b863a5.js";import"./index-1f06eb35.js";import"./Col-8e46ddda.js";import"./vnode-b177b857.js";import"./isPlainObject-ae5f6084.js";import"./index-23976fcd.js";import"./FormItemContext-dfbd6afd.js";import"./useState-ec2259f2.js";import"./index-9520c8d4.js";import"./pickAttrs-782832e8.js";import"./toArray-92f12fb1.js";import"./usePrice-7afab779.js";import"./useRefs-5fd4ee0f.js";import"./index-13d6d167.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-db3c9bb7.js"),["assets/buildSupabaseQuery-db3c9bb7.js","assets/index-4139499d.js","assets/index-2e613fc8.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 C={};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);C=(c||[]).reduce((m,o)=>(m[o.challenge_id]||(m[o.challenge_id]=[]),m[o.challenge_id].push(o),m),{})}const A=n.page||1,S=n.limit||20,q=(A-1)*S,L=h.map((c,m)=>{const o=C[c.id]||[],U=o.reduce((y,P)=>y+Math.round((P.duration_seconds||0)/60),0);return{...c,index:q+m,steps_count:o.length,total_minutes:U}});return{...i,
|