2026-06-03 19:51:45 +03:30
|
|
|
import{_ as ge}from"./BasicMainCard-8123d7a5.js";import{_ as ve}from"./BasicModal.vue_vue_type_style_index_0_lang-078ddd77.js";import{_ as ye}from"./BasicTextArea.vue_vue_type_style_index_0_lang-856c5942.js";import{_ as xe,a as we,u as Q}from"./useBaseTable-e905173e.js";import{_ as be}from"./BasicInput.vue_vue_type_style_index_0_lang-f3e17581.js";import{_ as Se}from"./button.vue_vue_type_style_index_0_lang-147050b5.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-c6a4e685.js";import{t as K}from"./useDataTime-2f3b2841.js";import{I as O}from"./Icon-e19b6c6c.js";import{e as Z,g as ee}from"./convert-67c23be8.js";import{T as te}from"./index-b6b0f56b.js";import{M as Le}from"./index-334d46a3.js";import{S as Re}from"./index-d3f71215.js";import{S as se}from"./index-03a51284.js";import{T as H}from"./shallowequal-ee0267e4.js";import{U as Be}from"./index-cb3f2111.js";import{_ as Pe}from"./_plugin-vue_export-helper-58b6e008.js";import"./index-252f8dad.js";import"./Col-8b3564ce.js";import"./vnode-977fe706.js";import"./isPlainObject-a663ca44.js";import"./index-4608391b.js";import"./FormItemContext-6df15dff.js";import"./useState-08abbf84.js";import"./index-633a27e5.js";import"./pickAttrs-e8130b6d.js";import"./toArray-5f8c3051.js";import"./usePrice-7afab779.js";import"./useRefs-63b38e0f.js";import"./index-e3fdf3f3.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-6e0d527d.js"),["assets/buildSupabaseQuery-6e0d527d.js","assets/index-c6a4e685.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,
|