2 lines
17 KiB
JavaScript
2 lines
17 KiB
JavaScript
import{_ as ge}from"./BasicMainCard-84b6a59f.js";import{_ as ve}from"./BasicModal.vue_vue_type_style_index_0_lang-c3ae10a6.js";import{_ as ye}from"./BasicTextArea.vue_vue_type_style_index_0_lang-0f9eff9d.js";import{_ as xe,a as be,u as Q}from"./useBaseTable-40588527.js";import{_ as we}from"./BasicInput.vue_vue_type_style_index_0_lang-edef22fe.js";import{_ as ke}from"./button.vue_vue_type_style_index_0_lang-ffd7bdde.js";import{H as C,_ as Se,d as Ie,g as A,z as Ce,o as P,c as B,b as o,w as p,j as w,a as s,e as j,E as Y,t as V,k as W,y as Ue,F as $e,n as Te,C as S,I as Me,J as Ae,G as Re}from"./index-4dc7c6f6.js";import{b as qe,c as Pe,f as Be}from"./supabaseTableQuery-8ee1dd3b.js";import{t as J}from"./useDataTime-58f0c0c0.js";import{I as O}from"./Icon-61889149.js";import{e as Z,g as ee}from"./convert-67c23be8.js";import{T as te}from"./index-2fcf178b.js";import{M as De}from"./index-4573c903.js";import{S as Ee}from"./index-286adeb4.js";import{S as se}from"./fa_IR-06db085c.js";import{T as H}from"./shallowequal-c81602d9.js";import{U as Le}from"./index-94e20169.js";import{_ as ze}from"./_plugin-vue_export-helper-a5e52605.js";import"./index-b0faa00c.js";import"./Col-21efcdc2.js";import"./vnode-88405440.js";import"./isPlainObject-8aaa3401.js";import"./index-177aaded.js";import"./FormItemContext-4baae48b.js";import"./useState-4068a96b.js";import"./lodash-746af23f.js";import"./index-ebdb1487.js";import"./pickAttrs-10867317.js";import"./toArray-48ad4c5b.js";import"./usePrice-7afab779.js";import"./useRefs-262e2b68.js";import"./index-99e2bbac.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 Oe(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-0132dd7d.js"),["assets/buildSupabaseQuery-0132dd7d.js","assets/index-4dc7c6f6.js","assets/index-5d811526.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(($,D)=>$+Math.round((D.durat
|