PageSourceSearch

https://loothing.xyz/assets/FormBuilder-BOEgAUJN.js

js loothing.xyz collected 2026-10-02 02:12:36 UTC 233,866 bytes, 1 lines download raw bytes

1import{r as e,j as t,a,R as l}from"./react-vendor-BR2bEzcq.js";import{c as s,z as i}from"./axios-ClGXtqae.js";import{c as n,D as r,a as o,b as c,d,W as m}from"./WowBossSelection-C7QSHvGU.js";import{D as u,a as p,W as x}from"./wowFormFieldData-CxVN-Yvg.js";import{m as h,F as g,P as f,l as b,r as y}from"./FormAppearanceProvider-CLtIdVSg.js";import{i as v,a as j}from"./displayOnlyFieldTypes-Bu305Jcx.js";import{l as w,a_ as N,A as C,m as S,o as D,B as T,av as k,a0 as I,W as F,g as A,aB as L,X as E,v as P,q as R,F as _,Q as M,R as O,U as $,ay as z,d as U,aw as B,G as H,aH as q,C as W,b as V,a5 as G,S as Y}from"./index-CpSDEIFT.js";import{M as K}from"./Modal-DkjBBQxh.js";import{P as X}from"./plus-CfdF0ep3.js";import{C as Q}from"./copy-8tRFsKvC.js";import{A as Z}from"./arrow-up-C-BppEoN.js";import{A as J}from"./arrow-down-_ivLRj9D.js";import{T as ee}from"./trash-2-CefGdBnP.js";import{G as te}from"./grip-vertical-BoJmq9At.js";import{C as ae}from"./code-CzPeHPNV.js";import{E as le}from"./ellipsis-vertical-CfczfLyA.js";import{S as se}from"./square-pen-C6dErqds.js";import{T as ie}from"./Tooltip-Cx200SpN.js";import{T as ne}from"./Toggle-76_ISnGG.js";import{F as re}from"./funnel-DDgrh7CG.js";import{F as oe,T as ce}from"./FormInput-5aKIUunT.js";import{T as de}from"./type-B7YUSxPR.js";import{T as me,C as ue,F as pe}from"./text-align-start-CwBJWups.js";import{H as xe}from"./hash-IAqmTeC5.js";import{M as he}from"./mail-BrOTJ_YE.js";import{L as ge}from"./link--zs0LcFx.js";import{S as fe}from"./square-check-big-Ci8uWKwf.js";import{C as be}from"./calendar-OSP8Zfeh.js";import{C as ye}from"./clock-7p0Hl2bb.js";import{C as ve}from"./calendar-check-D-K6-1wO.js";import{S as je}from"./sliders-horizontal-CH1eOChq.js";import{C as we}from"./cloud-upload-CiYEjlAw.js";import{I as Ne}from"./image-DZCp_FKW.js";import{M as Ce}from"./minus-CNId-Vu2.js";import{U as Se}from"./user-CGSJLesu.js";import{T as De}from"./trophy-B30ncVk3.js";import{P as Te}from"./package-CwoWoNvZ.js";import{S as ke}from"./sparkles-BkZALuyM.js";import{S as Ie}from"./skull-CVeeYsjz.js";import{C as Fe}from"./chevron-up-fOd_86gI.js";import{E as Ae}from"./eye-tKxUxQQk.js";import{E as Le}from"./eye-off-Dw1kIP7x.js";import{u as Ee}from"./useTierData-CgVIjtrZ.js";import{S as Pe}from"./StandardDropdown-BkSy1FKz.js";import{L as Re}from"./loader-circle-D91B_GSQ.js";import{C as _e}from"./circle-check-REcAsX_P.js";import{R as Me}from"./rotate-ccw-CI66U1aK.js";import{U as Oe}from"./upload-Bfj5LvPA.js";import{S as $e}from"./send-Oz9vOn7S.js";import{L as ze}from"./lock-s08R_Cx5.js";import{A as Ue}from"./arrow-right-DEfVKSSq.js";import{U as Be,R as He}from"./undo-2-BgAwe_jw.js";import{S as qe}from"./save-52hLv5rc.js";import{C as We}from"./chart-column-DlZj1Pa2.js";import{B as Ve}from"./ban-BMpk153J.js";import"./ExclamationCircleIcon-CunFTGPY.js";import"./CheckCircleIcon-Cby2gbWo.js";import"./EyeSlashIcon-5yKjBYTw.js";import"./EyeIcon-D3kwsJLA.js";import"./CheckIcon-911ghGV7.js";const Ge=w("files",[["path",{d:"M15 2h-4a2 2 0 0 0-2 2v11a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2V8",key:"14sh0y"}],["path",{d:"M16.706 2.706A2.4 2.4 0 0 0 15 2v5a1 1 0 0 0 1 1h5a2.4 2.4 0 0 0-.706-1.706z",key:"1970lx"}],["path",{d:"M5 7a2 2 0 0 0-2 2v11a2 2 0 0 0 2 2h8a2 2 0 0 0 1.732-1",key:"l4dndm"}]]),Ye=w("folder-input",[["path",{d:"M2 9V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H20a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2v-1",key:"fm4g5t"}],["path",{d:"M2 13h10",key:"pgb2dq"}],["path",{d:"m9 16 3-3-3-3",key:"6m91ic"}]]),Ke=w("network",[["rect",{x:"16",y:"16",width:"6",height:"6",rx:"1",key:"4q2zg0"}],["rect",{x:"2",y:"16",width:"6",height:"6",rx:"1",key:"8cvhb9"}],["rect",{x:"9",y:"2",width:"6",height:"6",rx:"1",key:"1egb70"}],["path",{d:"M5 16v-3a1 1 0 0 1 1-1h12a1 1 0 0 1 1 1v3",key:"1jsf9p"}],["path",{d:"M12 12V8",key:"2874zd"}]]),Xe=[];for(let gl=0;gl<256;++gl)Xe.push((gl+256).toString(16).slice(1));const Qe=new Uint8Array(16);function Ze(e,t,a){return crypto.randomUUID?crypto.randomUUID():function(e){const t=(e=e||{}).random??e.rng?.()??crypto.getRandomValues(Qe);if(t.length<16)throw new Error("Random bytes length must be >= 16");return t[6]=15&t[6]|64,t[8]=63&t[8]|128,function(e,t=0){return(Xe[e[t+0]]+Xe[e[t+1]]+Xe[e[t+2]]+Xe[e[t+3]]+"-"+Xe[e[t+4]]+Xe[e[t+5]]+"-"+Xe[e[t+6]]+Xe[e[t+7]]+"-"+Xe[e[t+8]]+Xe[e[t+9]]+"-"+Xe[e[t+10]]+Xe[e[t+11]]+Xe[e[t+12]]+Xe[e[t+13]]+Xe[e[t+14]]+Xe[e[t+15]]).toLowerCase()}(t)}(e)}const Je=()=>({title:"Untitled Form",description:"",status:"draft",visibilityLevel:"private",templateData:{version:2,settings:{requireAuth:!1,allowMultipleSubmissions:!1,allowResponseEditing:!1,duplicateSubmissionMessageTitle:"Response Already Submitted",duplicateSubmissionMessageBody:"You have already submitted this form and multiple submissions are disabled.",notifyOnEdit:!1,
1closeAt:null,limitResponses:null,enableCreatorTimezone:!1,creatorTimeZone:null,bannerImage:null},pages:[{id:Ze(),title:"Page 1",description:"",displayOrder:0,transitionType:"slide-horizontal",transitionDuration:300,showProgressBar:!0,allowBack:!0,sections:[{id:Ze(),title:"Section 1",description:"",displayOrder:0,showIf:null,repeatableSection:!1,maxRepetitions:5,fields:[]}],navigationRules:{nextPage:null,conditionalNext:[]}}],conditionalLogic:[],notifications:{discordChannelId:null,notifyOnSubmit:!1,notifyThreshold:null,notifyUsers:[]}}}),et=N((e,t)=>{const a=Je();return{formId:null,formTemplate:a,guildBranding:null,isDirty:!1,isSaving:!1,lastSavedAt:null,activeFieldId:null,activeSectionId:a.templateData.pages[0].sections[0].id,activePageId:a.templateData.pages[0].id,selectedFieldType:null,showPreview:!1,showFormSettings:!1,showConditionalLogic:!1,editingLogicFieldId:null,copiedField:null,copiedFieldSourceSectionId:null,history:[a],historyIndex:0,initializeForm:(t,a)=>{const l=a.templateData?.pages?.[0],s=l?.sections?.[0];n(),e({formId:t,formTemplate:a,isDirty:!1,history:[a],historyIndex:0,lastSavedAt:new Date,activePageId:l?.id||null,activeSectionId:s?.id||null,activeFieldId:null})},createNewForm:()=>{const t=Je();n(),e({formId:null,formTemplate:t,guildBranding:null,isDirty:!1,history:[t],historyIndex:0,activePageId:t.templateData.pages[0].id,activeSectionId:t.templateData.pages[0].sections[0].id,activeFieldId:null})},setGuildBranding:t=>e({guildBranding:t}),resetForm:()=>{const{history:a,historyIndex:l}=t();e({formTemplate:{...a[l]},isDirty:!1})},updateFormTitle:a=>{const{formTemplate:l}=t();e({formTemplate:{...l,title:a},isDirty:!0}),t()._addToHistory()},updateFormDescription:a=>{const{formTemplate:l}=t();e({formTemplate:{...l,description:a},isDirty:!0}),t()._addToHistory()},updateFormSettings:a=>{const{formTemplate:l}=t();e({formTemplate:{...l,templateData:{...l.templateData,settings:{...l.templateData.settings,...a}}},isDirty:!0}),t()._addToHistory()},updateFormAppearanceGlobal:a=>{const{formTemplate:l}=t(),s=l?.templateData?.appearance?.global||{};e({formTemplate:{...l,templateData:{...l.templateData,appearance:{version:1,...l?.templateData?.appearance||{},global:h(s,a)}}},isDirty:!0}),t()._addToHistory()},updateFormAppearanceFlags:a=>{const{formTemplate:l}=t(),s=l?.templateData?.appearance?.flags||{};e({formTemplate:{...l,templateData:{...l.templateData,appearance:{version:1,...l?.templateData?.appearance||{},flags:{...s,...a}}}},isDirty:!0}),t()._addToHistory()},updateFormAppearancePage:(a,l)=>{const{formTemplate:s}=t(),i=s?.templateData?.appearance?.pageOverrides||{},n=i[a]||{};e({formTemplate:{...s,templateData:{...s.templateData,appearance:{version:1,...s?.templateData?.appearance||{},pageOverrides:{...i,[a]:h(n,l)}}}},isDirty:!0}),t()._addToHistory()},resetPageAppearance:a=>{const{formTemplate:l}=t(),s={...l?.templateData?.appearance?.pageOverrides||{}};delete s[a],e({formTemplate:{...l,templateData:{...l.templateData,appearance:{...l?.templateData?.appearance||{},pageOverrides:s}}},isDirty:!0}),t()._addToHistory()},resetFormAppearance:()=>{const{formTemplate:a}=t(),l={...a?.templateData};delete l.appearance,e({formTemplate:{...a,templateData:l},isDirty:!0}),t()._addToHistory()},addSection:()=>{const{formTemplate:a,activePageId:l}=t(),s=2===Number(a.templateData.version);if(!s||l){if(s){const t=a.templateData.pages||[],s=t.find(e=>e.id===l);if(!s)return void console.warn("Active page not found");const i={id:Ze(),title:`Section ${(s.sections?.length||0)+1}`,description:"",displayOrder:s.sections?.length||0,deleted:!1,deletedAt:null,showIf:null,repeatableSection:!1,maxRepetitions:5,fields:[]};e({formTemplate:{...a,templateData:{...a.templateData,pages:t.map(e=>e.id===l?{...e,sections:[...e.sections||[],i]}:e)}},activeSectionId:i.id,isDirty:!0})}else{const t={id:Ze(),title:`Section ${a.templateData.sections.length+1}`,description:"",displayOrder:a.templateData.sections.length,deleted:!1,deletedAt:null,showIf:null,repeatableSection:!1,maxRepetitions:5,fields:[]};e({formTemplate:{...a,templateData:{...a.templateData,sections:[...a.templateData.sections,t]}},activeSectionId:t.id,isDirty:!0})}
1t()._addToHistory()}else console.warn("Cannot add section: no active page in multi-page mode")},removeSection:a=>{const{formTemplate:l,activeSectionId:s,activePageId:i}=t();if(2===Number(l.templateData.version)){const t=l.templateData.pages||[],n=t.find(e=>e.id===i);if(!n)return void console.warn("Active page not found");const r=(n.sections||[]).filter(e=>!e.deleted);if(1===r.length&&r[0].id===a)return void console.warn("Cannot remove the last active section from a page");const o=s===a?r.find(e=>e.id!==a)?.id||null:s;e({formTemplate:{...l,templateData:{...l.templateData,pages:t.map(e=>e.id===i?{...e,sections:e.sections.map(e=>e.id===a?{...e,deleted:!0,deletedAt:(new Date).toISOString(),fields:(e.fields||[]).map(e=>({...e,deleted:!0,deletedAt:(new Date).toISOString()}))}:e)}:e)}},activeSectionId:o,isDirty:!0})}else{const t=l.templateData.sections.filter(e=>!e.deleted);if(1===t.length&&t[0].id===a)return void console.warn("Cannot remove the last active section");const i=s===a?t.find(e=>e.id!==a)?.id||null:s;e({formTemplate:{...l,templateData:{...l.templateData,sections:l.templateData.sections.map(e=>e.id===a?{...e,deleted:!0,deletedAt:(new Date).toISOString(),fields:(e.fields||[]).map(e=>({...e,deleted:!0,deletedAt:(new Date).toISOString()}))}:e)}},activeSectionId:i,isDirty:!0})}
1t()._addToHistory()},updateSectionTitle:(a,l)=>{const{formTemplate:s,activePageId:i}=t(),n=2===Number(s.templateData.version);e(n?{formTemplate:{...s,templateData:{...s.templateData,pages:s.templateData.pages.map(e=>e.id===i?{...e,sections:e.sections.map(e=>e.id===a?{...e,title:l}:e)}:e)}},isDirty:!0}:{formTemplate:{...s,templateData:{...s.templateData,sections:s.templateData.sections.map(e=>e.id===a?{...e,title:l}:e)}},isDirty:!0}),t()._addToHistory()},updateSectionDescription:(a,l)=>{const{formTemplate:s,activePageId:i}=t(),n=2===Number(s.templateData.version);e(n?{formTemplate:{...s,templateData:{...s.templateData,pages:s.templateData.pages.map(e=>e.id===i?{...e,sections:e.sections.map(e=>e.id===a?{...e,description:l}:e)}:e)}},isDirty:!0}:{formTemplate:{...s,templateData:{...s.templateData,sections:s.templateData.sections.map(e=>e.id===a?{...e,description:l}:e)}},isDirty:!0}),t()._addToHistory()},updateSection:(a,l)=>{const{formTemplate:s,activePageId:i}=t(),n=2===Number(s.templateData.version);e(n?{formTemplate:{...s,templateData:{...s.templateData,pages:s.templateData.pages.map(e=>e.id===i?{...e,sections:e.sections.map(e=>e.id===a?{...e,...l}:e)}:e)}},isDirty:!0}:{formTemplate:{...s,templateData:{...s.templateData,sections:s.templateData.sections.map(e=>e.id===a?{...e,...l}:e)}},isDirty:!0}),t()._addToHistory()},moveSectionToPage:(a,l)=>{const{formTemplate:s,activePageId:i}=t();if(2!==Number(s.templateData.version))return;if(i===l)return;const n=s.templateData.pages||[],r=n.find(e=>e.sections?.some(e=>e.id===a));if(!r)return;const o=r.sections.filter(e=>!e.deleted);if(1===o.length&&o[0].id===a)return;const c=r.sections.find(e=>e.id===a);e({formTemplate:{...s,templateData:{...s.templateData,pages:n.map(e=>{if(e.id===r.id)return{...e,sections:e.sections.filter(e=>e.id!==a)};if(e.id===l){const t={...c,displayOrder:e.sections.length};return{...e,sections:[...e.sections,t]}}return e})}},isDirty:!0}),t()._addToHistory()},moveFieldToPage:(e,a,l)=>{const{formTemplate:s}=t(),i=(s.templateData.pages||[]).find(e=>e.id===l);if(!i)return;const n=i.sections.find(e=>!e.deleted);n&&t().moveFieldBetweenSections(a,n.id,e,n.fields.filter(e=>!e.deleted).length)},reorderSections:a=>{const{formTemplate:l,activePageId:s}=t(),i=2===Number(l.templateData.version),n=a.map((e,t)=>({...e,displayOrder:t}));e(i?{formTemplate:{...l,templateData:{...l.templateData,pages:l.templateData.pages.map(e=>e.id===s?{...e,sections:n}:e)}},isDirty:!0}:{formTemplate:{...l,templateData:{...l.templateData,sections:n}},isDirty:!0}),t()._addToHistory()},duplicateSection:a=>{const{formTemplate:l,activePageId:s}=t(),i=2===Number(l.templateData.version),n=i?l.templateData.pages.find(e=>e.id===s)?.sections||[]:l.templateData.sections,r=n.find(e=>e.id===a);if(!r)return;const o={...r,id:Ze(),title:`${r.title} (Copy)`,displayOrder:n.length,fields:r.fields.filter(e=>e.id&&!e.deleted).map(e=>({...e,id:Ze()}))};e(i?{formTemplate:{...l,templateData:{...l.templateData,pages:l.templateData.pages.map(e=>e.id===s?{...e,sections:[...e.sections,o]}:e)}},isDirty:!0}:{formTemplate:{...l,templateData:{...l.templateData,sections:[...l.templateData.sections,o]}},isDirty:!0}),t()._addToHistory()},addField:(a,l,s="end",i=null)=>{const{formTemplate:n,activePageId:r}=t(),o=2===Number(n.templateData.version),c=(e=>{if(v(e)){const t={id:Ze(),type:e,label:"",description:"",hideLabel:!0,hideDescription:!0,displayOrder:0,deleted:!1,deletedAt:null,showIf:null};return"display_text"===e?(t.label="Rich Text",t.content="## Heading\n\nWrite your content here. **Markdown** is supported."):"display_image"===e?(t.label="Image",t.imageUrl="",t.alt="",t.caption="",t.align="center",t.maxWidthPercent=100):"display_video"===e?(t.label="Video Embed",t.videoUrl="",t.caption=""):"display_divider"===e&&(t.label="Divider",t.dividerStyle="solid",t.dividerLabel=""),t}const t=["email","url","text","number","regex"].includes(e)?e:"text",a={id:Ze(),type:e,label:`New ${e} field`,description:"",required:!1,placeholder:"",displayOrder:0,deleted:!1,deletedAt:null,validation:{type:t,minLength:null,maxLength:null,errorMessage:""},showIf:null,defaultValue:["text","textarea","email","url"].includes(e)?"":null};return["select","radio","checkbox","multi-select"].includes(e)&&(a.options=void 0),["number","rating","scale"].includes(e)&&(a.minValue=null,a.maxValue=null),"wow_character_battlenet"!==e&&"wow_character_linked"!==e||(a.label="wow_character_battlenet"===e?"WoW Character (B
1attle.net Search)":"WoW Character (Linked)",a.validation={mustBeGuildMember:!1,minItemLevel:null,maxItemLevel:null,allowedClasses:[],allowedSpecs:[],allowedRoles:[],minMythicPlusScore:null,minRaidProgress:null}),"wow_raiderio_lookup"===e&&(a.label="Raider.io Lookup",a.validation={minMythicPlusScore:null,minDungeonCompletions:null,requiredDungeons:[],minKeyLevel:null}),"wow_item_lookup"===e&&(a.label="WoW Item Lookup",a.validation={}),"wow_spell_lookup"===e&&(a.label="WoW Spell Lookup",a.validation={}),"wow_wcl_encounter"===e&&(a.label="WCL Encounter Selection",a.validation={}),"date"!==e&&"time"!==e&&"datetime"!==e||(a.config={showCreatorTimezonePreview:!0}),"wow_flex_selection"===e&&(a.label="Flex Selection",a.config={...u},a.validation={}),"availability"===e&&(a.label="Availability",a.config={availableDays:[0,1,2,3,4,5,6],timeslotOptions:[{startTime:"20:00",endTime:"22:00",label:""},{startTime:"20:30",endTime:"22:30",label:""},{startTime:"21:00",endTime:"23:00",label:""}],includeAllDay:!1,minSlots:null,maxSlots:null,showCreatorTimezonePreview:!0},a.validation={}),a})(l),d=(e=[])=>{const t=e.filter(e=>e.id&&!e.deleted),a=e.filter(e=>e.id&&e.deleted);if("above"===s&&i){const e=t.findIndex(e=>e.id===i);e>-1?t.splice(e,0,c):t.push(c)}else if("below"===s&&i){const e=t.findIndex(e=>e.id===i);e>-1?t.splice(e+1,0,c):t.push(c)}else t.push(c);return[...t,...a].map((e,t)=>({...e,displayOrder:t}))};if(o){const t=n.templateData.pages||[];let l=!1;const s=t.map(e=>{const t=e.sections?.find(e=>e.id===a);return t?(l=!0,{...e,sections:e.sections.map(e=>e.id===a?{...e,fields:d(e.fields)}:e)}):e});if(!l)return void console.warn("Section not found in any page");e({formTemplate:{...n,templateData:{...n.templateData,pages:s}},activeFieldId:c.id,isDirty:!0})}else{if(!n.templateData.sections.find(e=>e.id===a))return void console.warn("Section not found");e({formTemplate:{...n,templateData:{...n.templateData,sections:n.templateData.sections.map(e=>e.id===a?{...e,fields:d(e.fields)}:e)}},activeFieldId:c.id,isDirty:!0})}
1t()._addToHistory()},_cleanupOrphanedConditionals:(e,t)=>{const a=(e,t)=>{if(!e)return null;if(e.fieldId===t)return null;if("and"===e.type||"or"===e.type){const l=(e.conditions||[]).map(e=>a(e,t)).filter(Boolean);return 0===l.length?null:{...e,conditions:l}}return e};return t.map(t=>({...t,fields:(t.fields||[]).map(t=>{if(!t.showIf)return t;const l=a(t.showIf,e);if(!l){const{showIf:e,...a}=t;return a}return l===t.showIf?t:{...t,showIf:l}}),showIf:t.showIf?a(t.showIf,e):t.showIf}))},removeField:(a,l)=>{const{formTemplate:s}=t(),i=2===Number(s.templateData?.version),n=(new Date).toISOString();let r=!1;const o=(e=[],t=null)=>e.map(e=>({...e,fields:(e.fields||[]).map(a=>t&&e.id!==t?a:(e=>e&&e.id===l?(r=!0,{...e,deleted:!0,deletedAt:n}):e)(a))}));if(i){const i=s.templateData.pages.map(e=>{let s=o(e.sections,a);return r||(s=o(e.sections)),s=t()._cleanupOrphanedConditionals(l,s),{...e,sections:s}});e({formTemplate:{...s,templateData:{...s.templateData,pages:i}},activeFieldId:null,isDirty:!0})}else{let i=o(s.templateData.sections,a);r||(i=o(s.templateData.sections)),i=t()._cleanupOrphanedConditionals(l,i),e({formTemplate:{...s,templateData:{...s.templateData,sections:i}},activeFieldId:null,isDirty:!0})}r||console.warn("removeField: field not found for deletion",{sectionId:a,fieldId:l}),t()._addToHistory()},updateField:(a,l,s)=>{const{formTemplate:i}=t(),n=2===Number(i.templateData?.version);e(n?{formTemplate:{...i,templateData:{...i.templateData,pages:i.templateData.pages.map(e=>({...e,sections:e.sections.map(e=>e.id===a?{...e,fields:e.fields.map(e=>e.id===l?{...e,...s}:e)}:e)}))}},isDirty:!0}:{formTemplate:{...i,templateData:{...i.templateData,sections:i.templateData.sections.map(e=>e.id===a?{...e,fields:e.fields.map(e=>e.id===l?{...e,...s}:e)}:e)}},isDirty:!0}),t()._addToHistory()},reorderFields:(a,l)=>{const{formTemplate:s}=t(),i=2===Number(s.templateData?.version),n=l.filter(e=>e&&e.id).map((e,t)=>({...e,displayOrder:t}));e(i?{formTemplate:{...s,templateData:{...s.templateData,pages:s.templateData.pages.map(e=>({...e,sections:e.sections.map(e=>e.id===a?{...e,fields:n}:e)}))}},isDirty:!0}:{formTemplate:{...s,templateData:{...s.templateData,sections:s.templateData.sections.map(e=>e.id===a?{...e,fields:n}:e)}},isDirty:!0}),t()._addToHistory()},moveFieldBetweenSections:(a,l,s,i)=>{const{formTemplate:n}=t(),r=2===Number(n.templateData?.version),o=(r?n.templateData.pages.flatMap(e=>e.sections):n.templateData.sections).find(e=>e.id===a),c=o?.fields?.find(e=>e.id===s);if(!c)return;const d=e=>e.map(e=>{if(e.id===a)return{...e,fields:e.fields.filter(e=>e.id!==s)};if(e.id===l){const t=e.fields.filter(e=>e.id&&!e.deleted),a=e.fields.filter(e=>e.id&&e.deleted);t.splice(i,0,c);const l=[...t,...a].map((e,t)=>({...e,displayOrder:t}));return{...e,fields:l}}return e});e(r?{formTemplate:{...n,templateData:{...n.templateData,pages:n.templateData.pages.map(e=>({...e,sections:d(e.sections)}))}},isDirty:!0}:{formTemplate:{...n,templateData:{...n.templateData,sections:d(n.templateData.sections)}},isDirty:!0}),t()._addToHistory()},duplicateField:(a,l)=>{const{formTemplate:s}=t(),i=2===Number(s.templateData?.version),n=(i?s.templateData.pages.flatMap(e=>e.sections):s.templateData.sections).find(e=>e.id===a);if(!n)return;const r=n.fields.find(e=>e.id===l);if(!r)return;const o={...r,id:Ze(),label:`${r.label} (Copy)`,displayOrder:n.fields.length};e(i?{formTemplate:{...s,templateData:{...s.templateData,pages:s.templateData.pages.map(e=>({...e,sections:e.sections.map(e=>e.id===a?{...e,fields:[...e.fields,o]}:e)}))}},isDirty:!0}:{formTemplate:{...s,templateData:{...s.templateData,sections:s.templateData.sections.map(e=>e.id===a?{...e,fields:[...e.fields,o]}:e)}},isDirty:!0}),t()._addToHistory()},copyField:(a,l)=>{const{formTemplate:s}=t(),i=(2===Number(s.templateData?.version)?s.templateData.pages.flatMap(e=>e.sections):s.templateData.sections).find(e=>e.id===a);if(!i)return;const n=i.fields.find(e=>e.id===l);n&&e({copiedField:{...n},copiedFieldSourceSectionId:a})},pasteField:(a,l="end",s=null)=>{const{formTemplate:i,copiedField:n}=t();if(!n)return void console.warn("No field in clipboard");const r=2===Number(i.templateData?.version),o={...n,id:Ze(),label:`${n.label} (Copy)`,displayOrder:0};e(r?{formTemplate:{...i,templateData:{...i.templateData,pages:i.templateData.pages.map(e=>({...e,sections:e.sections.map(e=>{if(e.id===a){let t;if("end"===l)t=[...e.fields||[],o];else if("above"===l&&s){const a=e.fields.findIndex(e=>e.id===s);t=a>=0?[...e.fields.slice(0,a),o,...e.fields.slice(a)]:[...e.fields||[],o]}else if("below"===l&&s){const a=e.fields.findIndex(e=>e.id===s);t=a>=0?[...e.fields.slice(0,a+1),o,...e.fields.slice(a+1)]:[...e.fields||[],o]}else t=[...e.fields||[],o];return t=t.map((e,t)=>({...e,displayOrder:t})),{...e,fields:t}}return e})}))}},activeFieldId:o.id,isDirty:!0}:{formTemplate:{...i,templateData:{...i.templateData,sections:i.templateData.sections.map(e=>{if(e.id===a){let t;if("end"===l)t=[...e.fields||[],o];else if("above"===l&&s){const a=e.fields.findIndex(e=>e.id===s);t=a>=0?[...e.fields.slice(0,a),o,...e.fields.slice(a)]:[...e.fields||[],o]}else if("below"===l&&s){const a=e.fields.findIndex(e=>e.id===s);t=a>=0?[...e.fields.slice(0,a+1),o,...e.fields.slice(a+1)]:[...e.fields||[],o]}else t=[...e.fields||[],o];return t=t.map((e,t)=>({...e,displayOrder:t})),{...e,fields:t}}return e})}},activeFieldId:o.id,isDirty:!0}),t()._addToHistory()},clearClipboard:()=>{e({copiedField:null,copiedFieldSourceSectionId:null})},updateFieldConditionalLogic:(a,l,s)=>{const{formTemplate:i}=t(),n=2===Number(i.templateData?.version);e(n?{formTemplate:{...i,templateData:{...i.templateData,pages:i.templateData.pages.map(e=>({...e,sections:e.sections.map(e=>e.id===a?{...e,fields:e.fields.map(e=>e.id===l?{...e,showIf:s}:e)}:e)}))}},isDirty:!0}:{formTemplate:{...i,templateData:{...i.templateData,sections:i.templateData.sections.map(e=>e.id===a?{...e,fields:e.fields.map(e=>e.id===l?{...e,showIf:s}:e)}:e)}},isDirty:!0}),t()._addToHistory()},clearFieldConditionalLogic:(a,l)=>{const{formTemplate:s}=t(),i=2===Number(s.templateData?.version);e(i?{formTemplate:{...s,templateData:{...s.templateData,pages:s.templateData.pages.map(e=>({...e,sections:e.sections.map(e=>e.id===a?{...e,fields:e.fields.map(e=>e.id===l?{...e,showIf:null}:e)}:e)}))}},isDirty:!0}:{formTemplate:{...s,templateData:{...s.templateData,sections:s.templateData.sections.map(e=>e.id===a?{...e,fields:e.fields.map(e=>e.id===l?{...e,showIf:null}:e)}:e)}},isDirty:!0}),t()._addToHistory()},updateSectionConditionalLogic:(a,l)=>{const{formTemplate:s}=t(),i=2===Number(s.templateData?.version);e(i?{formTemplate:{...s,templateData:{...s.templateData,pages:s.templateData.pages.map(e=>({...e,sections:e.sections.map(e=>e.id===a?{...e,showIf:l}:e)}))}},isDirty:!0}:{formTemplate:{...s,templateData:{...s.templateData,sections:s.templateData.sections.map(e=>e.id===a?{...e,showIf:l}:e)}},isDirty:!0}),t()._addToHistory()},clearSectionConditionalLogic:a=>{const{formTemplate:l}=t(),s=2===Number(l.templateData?.version);e(s?{formTemplate:{...l,templateData:{...l.templateData,pages:l.templateData.pages.map(e=>({...e,sections:e.sections.map(e=>e.id===a?{...e,showIf:null}:e)}))}},isDirty:!0}:{formTemplate:{...l,templateData:{...l.templateData,sections:l.templateData.sections.map(e=>e.id===a?{...e,showIf:null}:e)}},isDirty:!0}),t()._addToHistory()},toggleMultiPageMode:a=>{const{formTemplate:l}=t();if(a&&2!==l.templateData.version){const t=l.templateData.sections||[],a=Ze(),{sections:s,...i}=l.templateData;e({formTemplate:{...l,templateData:{...i,version:2,pages:[{id:a,title:"Page 1",description:"",displayOrder:0,transitionType:"slide-horizontal",transitionDuration:300,showProgressBar:!0,allowBack:!0,sections:t,navigationRules:{nextPage:null,conditionalNext:[]}}]}},activePageId:a,isDirty:!0})}else if(!a&&2===Number(l.templateData.version)){const t=(l.templateData.pages||[]).flatMap(e=>e.sections||[]),{pages:a,...s}=l.templateData;e({formTemplate:{...l,templateData:{...s,version:1,sections:t}},activePageId:null,isDirty:!0})}
1t()._addToHistory()},addPage:()=>{const{formTemplate:a}=t();if(2!==a.templateData.version)return void console.warn("addPage called on version 1 form. Convert to multi-page mode first.");const l=a.templateData.pages||[],s=Ze(),i={id:s,title:`Page ${l.length+1}`,description:"",displayOrder:l.length,transitionType:"slide-horizontal",transitionDuration:300,showProgressBar:!0,allowBack:!0,sections:[{id:Ze(),title:"Section 1",description:"",displayOrder:0,showIf:null,repeatableSection:!1,maxRepetitions:5,fields:[]}],navigationRules:{nextPage:null,conditionalNext:[]}};e({formTemplate:{...a,templateData:{...a.templateData,pages:[...l,i]}},activePageId:s,isDirty:!0}),t()._addToHistory()},removePage:a=>{const{formTemplate:l,activePageId:s}=t();if(2!==l.templateData.version)return void console.warn("removePage called on version 1 form");const i=l.templateData.pages||[];if(i.length<=1)return void console.warn("Cannot remove the last page. Convert to single-page mode instead.");const n=i.filter(e=>e.id!==a),r=s===a?n[0].id:s;e({formTemplate:{...l,templateData:{...l.templateData,pages:n}},activePageId:r,isDirty:!0}),t()._addToHistory()},updatePageSettings:(a,l)=>{const{formTemplate:s}=t();2===s.templateData.version?(e({formTemplate:{...s,templateData:{...s.templateData,pages:s.templateData.pages.map(e=>e.id===a?{...e,...l}:e)}},isDirty:!0}),t()._addToHistory()):console.warn("updatePageSettings called on version 1 form")},updatePageNavigation:(a,l)=>{const{formTemplate:s}=t();2===s.templateData.version?(e({formTemplate:{...s,templateData:{...s.templateData,pages:s.templateData.pages.map(e=>e.id===a?{...e,navigationRules:{...e.navigationRules,...l}}:e)}},isDirty:!0}),t()._addToHistory()):console.warn("updatePageNavigation called on version 1 form")},reorderPages:a=>{const{formTemplate:l}=t();if(2!==l.templateData.version)return void console.warn("reorderPages called on version 1 form");const s=a.map((e,t)=>({...e,displayOrder:t}));e({formTemplate:{...l,templateData:{...l.templateData,pages:s}},isDirty:!0}),t()._addToHistory()}
1,setActiveField:a=>{if(!a)return void e({activeFieldId:null});const{formTemplate:l,activePageId:s}=t(),i=2===Number(l.templateData?.version)?l.templateData?.pages?.find(e=>e.id===s)?.sections||[]:l.templateData?.sections||[];let n=null;for(const e of i)if(e.fields?.some(e=>e.id===a)){n=e.id;break}e({activeFieldId:a,activeSectionId:n||t().activeSectionId})},clearActiveField:()=>{e({activeFieldId:null})},setActiveSection:t=>{e({activeSectionId:t})},setActivePage:t=>{e({activePageId:t})},togglePreview:()=>{e(e=>({showPreview:!e.showPreview}))},toggleFormSettings:()=>{e(e=>({showFormSettings:!e.showFormSettings}))},toggleConditionalLogic:t=>{e(e=>({showConditionalLogic:!e.showConditionalLogic,editingLogicFieldId:t||null}))},undo:()=>{const{history:a,historyIndex:l}=t();if(l>0){const t=l-1;e({formTemplate:a[t],historyIndex:t,isDirty:0!==t})}},redo:()=>{const{history:a,historyIndex:l}=t();if(l<a.length-1){const t=l+1;e({formTemplate:a[t],historyIndex:t,isDirty:0!==t})}},clearHistory:()=>{const{formTemplate:a}=t();e({history:[a],historyIndex:0})},markAsSaved:()=>{const{history:a,historyIndex:l}=t();e({isDirty:!1,lastSavedAt:new Date})},setSaving:t=>{e({isSaving:t})},_addToHistory:()=>{const{formTemplate:a,history:l,historyIndex:s}=t(),i=l.slice(0,s+1);i.push({...a}),i.length>50&&i.shift(),e({history:i,historyIndex:i.length-1})}}}),tt={primary:"text-(--theme-primary-color,#bb86fc)",success:"text-green-400",info:"text-cyan-400",danger:"text-red-400"};function at({onClick:e,icon:a,color:l="primary",label:s,secondary:i,danger:n=!1,children:r}){return t.jsx("button",{type:"button",onClick:e,className:"w-full flex items-center gap-2 mx-1 my-0.5 px-2.5 py-2 rounded-md text-sm font-medium text-left transition-colors "+(n?"text-red-300 hover:bg-red-900/20 hover:text-red-200":"text-gray-200 hover:bg-gray-700/60"),style:{width:"calc(100% - 0.5rem)"},children:r??t.jsxs(t.Fragment,{children:[a&&t.jsx(a,{className:`h-4 w-4 shrink-0 ${n?"text-red-300":tt[l]||tt.primary}`}),t.jsx("span",{className:"flex-1",children:s}),i&&t.jsx("span",{className:"text-xs text-gray-400",children:i})]})})}function lt(){return t.jsx("div",{className:"my-1 border-t border-gray-700/50",role:"separator"})}const st=({open:l,position:s,onClose:i,contextType:n,targetId:r,sectionId:o,onAddField:c,onCopyField:d,onPasteField:m,onDeleteField:u})=>{const[p,x]=e.useState(!1),[h,g]=e.useState(null),f=e.useRef(null),{copiedField:b,formTemplate:y,updateField:v,updateSection:j}=et(),w=2===Number(y.templateData?.version)?y.templateData?.pages?.flatMap(e=>e.sections)||[]:y.templateData?.sections||[],N="section"===n?w.find(e=>e.id===r):w.find(e=>e.id===o),k="field"===n?N?.fields?.find(e=>e.id===r):null;e.useEffect(()=>{if(!l)return;const e=e=>{f.current&&!f.current.contains(e.target)&&i()},t=e=>{"Escape"===e.key&&i()},a=setTimeout(()=>{document.addEventListener("mousedown",e),document.addEventListener("keydown",t)},0);return()=>{clearTimeout(a),document.removeEventListener("mousedown",e),document.removeEventListener("keydown",t)}},[l,i]),e.useEffect(()=>{if(!l||!s)return void g(null);const e=requestAnimationFrame(()=>{const e=f.current;if(!e)return void g({top:s.mouseY,left:s.mouseX});const t=e.getBoundingClientRect();let a=s.mouseX,l=s.mouseY;a+t.width+8>window.innerWidth&&(a=Math.max(8,window.innerWidth-t.width-8)),l+t.height+8>window.innerHeight&&(l=Math.max(8,window.innerHeight-t.height-8)),g({top:l,left:a})});return()=>cancelAnimationFrame(e)},[l,s]);const I=Boolean(l&&s),F=I?h||{top:s.mouseY,left:s.mouseX}:null,A=t.jsx(C,{children:I&&t.jsxs(S.div,{ref:f,role:"menu",initial:{opacity:0,scale:.95,y:-4},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:-4},transition:{duration:.12},style:{position:"fixed",top:F.top,left:F.left,visibility:h?"visible":"hidden"},className:"z-50 min-w-[14rem] py-1 rounded-lg border border-gray-700/50 bg-gray-800/95 backdrop-blur-xs shadow-2xl shadow-black/40",children:["field"===n&&t.jsxs(t.Fragment,{children:[k&&t.jsxs(at,{onClick:e=>{e?.stopPropagation?.(),v(o,r,{hideLabel:!k.hideLabel})},children:[t.jsx("input",{type:"checkbox",checked:!!k.hideLabel,readOnly:!0,className:"h-3.5 w-3.5 rounded border-gray-600 bg-gray-800 text-(--theme-primary-color,#bb86fc) pointer-events-none"}),t.jsx("span",{className:"flex-1",children:"Hide Label"})]}),t.jsx(lt,{}),t.jsx(at,{onClick:()=>{"field"===n&&c?.("above",r),i()},icon:X,color:"primary",label:"Add Above"}),t.jsx(at,{onClick:()=>{"field"===n&&c?.("below",r),i()},icon:X,color:"primary",label:"Add Below"}),t.jsx(lt,{}),t.jsx(at,{onClick:()=>{"field"===n&&d?.(o,r),i()},icon:Q,color:"success",label:"Copy"}),b&&t.jsxs(t.Fragment,{children:[t.jsx(at,{onClick:()=>{"field"===n&&m?.(o,"above",r),i()},icon:Z,color:"info",label:"Paste Above",secondary:"Ctrl+V"}),t.jsx(at,{onClick:()=>{"field"===n&&m?.(o,"below",r),i()},icon:J,color:"info",label:"Paste Below",secondary:"Ctrl+V"})]}),t.jsx(lt,{}),t.jsx(at,{onClick:()=>x(!0),icon:ee,danger:!0,label:"Delete",secondary:"Del"})]}),"section"===n&&t.jsxs(t.Fragment,{children:[N&&t.jsxs(t.Fragment,{children:[t.jsxs(at,{onClick:e=>{e?.stopPropagation?.(),j(N.id,{hideTitle:!N.hideTitle})},children:[t.jsx("input",{type:"checkbox",checked:!!N.hideTitle,readOnly:!0,className:"h-3.5 w-3.5 rounded border-gray-600 bg-gray-800 text-(--theme-primary-color,#bb86fc) pointer-events-none"}),t.jsx("span",{className:"flex-1",children:"Hide Title"})]}),N.description&&t.jsxs(at,{onClick:e=>{e?.stopPropagation?.(),j(N.id,{hideDescription:!N.hideDescription})},children:[t.jsx("input",{type:"checkbox",checked:!!N.hideDescription,readOnly:!0,className:"h-3.5 w-3.5 rounded border-gray-600 bg-gray-800 text-(--theme-primary-color,#bb86fc) pointer-events-none"}),t.jsx("span",{className:"flex-1",children:"Hide Description"})]})]}),t.jsx(lt,{}),t.jsx(at,{onClick:()=>{c?.(),i()},icon:X,color:"primary",label:"Add Field"}),b&&t.jsxs(t.Fragment,{children:[t.jsx(lt,{}),t.jsx(at,{onClick:()=>{"section"===n&&m?.(r,"end"),i()}
1,icon:D,color:"info",label:"Paste Field",secondary:"Ctrl+V"})]})]})]})});return t.jsxs(t.Fragment,{children:[a.createPortal(A,document.body),t.jsx(K,{isOpen:p,onClose:()=>x(!1),title:"Delete Field?",size:"sm",footer:t.jsxs(t.Fragment,{children:[t.jsx(T,{variant:"ghost",onClick:()=>x(!1),children:"Cancel"}),t.jsx(T,{variant:"error",leftIcon:t.jsx(ee,{className:"w-4 h-4"}),onClick:()=>{x(!1),"field"===n&&u?.(o,r),i()},children:"Delete"})]}),children:t.jsx("p",{className:"text-gray-300",children:"This will remove the field from the form. This action cannot be undone."})})]})},it=[.4,0,.2,1],nt=.15,rt={hidden:{opacity:0,y:20,scale:.95},visible:{opacity:1,y:0,scale:1,transition:{duration:.2,ease:it}},exit:{opacity:0,scale:.95,transition:{duration:nt,ease:it}}},ot={hidden:{opacity:0},visible:{opacity:1,transition:{staggerChildren:.05,delayChildren:.02}}},ct={hidden:{opacity:0},visible:{opacity:1,transition:{duration:.2,ease:it}},exit:{opacity:0,transition:{duration:nt,ease:it}}},dt={hidden:{opacity:0,scale:0},visible:{opacity:1,scale:1,transition:{type:"spring",stiffness:500,damping:30}},exit:{opacity:0,scale:0,transition:{duration:nt,ease:it}}},mt=e=>{switch(e.type){case"display_text":return t.jsx(d,{field:e});case"display_image":return t.jsx(c,{field:e});case"display_video":return t.jsx(o,{field:e});case"display_divider":return t.jsx(r,{field:e});default:return null}},ut="inline-flex items-center gap-1 px-1.5 py-0.5 rounded-full text-[10px] font-medium border",pt=({field:l,sectionId:s,onDragStart:i,onAddField:n})=>{const[r,o]=e.useState(!1),[c,d]=e.useState(null),[m,u]=e.useState(!1),[p,x]=e.useState(!1),[h,g]=e.useState(null),f=e.useRef(null),b=e.useRef(null),{activeFieldId:y,setActiveField:j,updateField:w,removeField:N,duplicateField:D,copyField:I,pasteField:F}=et(),A=y===l.id;return e.useEffect(()=>{if(!r)return;const e=e=>{b.current&&!b.current.contains(e.target)&&f.current&&!f.current.contains(e.target)&&o(!1)},t=e=>{"Escape"===e.key&&o(!1)};return document.addEventListener("mousedown",e),document.addEventListener("keydown",t),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("keydown",t)}},[r]),t.jsxs(t.Fragment,{children:[t.jsxs(S.div,{draggable:!0,"data-index":l.id,onDragStart:e=>{e.dataTransfer.effectAllowed="move",e.dataTransfer.setData("fieldId",l.id),e.dataTransfer.setData("sourceSectionId",s),e.dataTransfer.setData("dragType","field"),i?.()},onClick:()=>j(l.id),onContextMenu:e=>{e.preventDefault(),e.stopPropagation(),g({mouseX:e.clientX,mouseY:e.clientY}),x(!0)},whileHover:{y:-1},animate:{scale:A?1.005:1},transition:{duration:.15},className:"p-3 rounded-lg cursor-pointer transition-colors active:cursor-grabbing "+(A?"bg-(--theme-primary-color,#bb86fc)/10 border-2 border-(--theme-primary-color,#bb86fc)":"bg-gray-800/40 border border-gray-700/50 hover:bg-gray-800/60"),children:[t.jsxs("div",{className:"flex items-start gap-2",children:[t.jsx("div",{className:"flex items-center pt-0.5 cursor-grab active:cursor-grabbing text-gray-500",children:t.jsx(te,{className:"w-4 h-4"})}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"flex items-center gap-2 mb-0.5 flex-wrap",children:[t.jsx("span",{className:"text-sm font-semibold text-gray-200 truncate",children:l.label}),t.jsxs(C,{children:[l.required&&t.jsxs(S.span,{variants:dt,initial:"hidden",animate:"visible",exit:"exit",className:`${ut} border-gray-600 text-gray-300`,children:[t.jsx(k,{className:"w-3 h-3"}),"Required"]},"required-badge"),l.showIf&&t.jsxs(S.span,{variants:dt,initial:"hidden",animate:"visible",exit:"exit",className:`${ut} border-pink-500/60 text-pink-300`,children:[t.jsx(ae,{className:"w-3 h-3"}),"Conditional"]},"conditional-badge")]})]}),t.jsx("p",{className:"text-xs text-gray-400",children:(L=l.type,{text:"Short Text",textarea:"Long Text",number:"Number",email:"Email",url:"URL",select:"Dropdown",radio:"Radio",checkbox:"Checkboxes",date:"Date",time:"Time",datetime:"Date & Time",rating:"Rating",scale:"Linear Scale",display_text:"Rich Text (display)",display_image:"Image (display)",display_video:"Video Embed (display)",display_divider:"Divider (display)"}[L]||L)})]}),t.jsx("button",{ref:f,type:"button",onClick:e=>{e.stopPropagation();const t=e.currentTarget.getBoundingClientRect();d({top:t.bottom+4,left:t.right-200}),o(!0)},className:"p-1.5 rounded hover:bg-gray-700/50 text-gray-400 hover:text-gray-200 transition-colors","aria-label":"Field actions",children:t.jsx(le,{className:"w-4 h-4"})})]}),l.description&&t.jsx("p",{className:"mt-2 text-xs text-gray-400 italic",children:l.description}),v(l.type)&&t.jsx("div",{className:"mt-2 rounded-md border border-gray-700/40 bg-gray-900/40 p-3 pointer-events-none",children:mt(l)})]}),a.createPortal(t.jsx(C,{children:r&&c&&t.jsxs(S.div,{ref:b,initial:{opacity:0,scale:.95,y:-4}
1,animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:-4},transition:{duration:.12},style:{position:"fixed",top:c.top,left:Math.max(8,c.left),zIndex:9999},className:"min-w-[12rem] py-1 rounded-lg border border-gray-700/50 bg-gray-800/95 backdrop-blur-xs shadow-2xl",children:[t.jsxs("button",{type:"button",onClick:e=>{e.stopPropagation(),w(s,l.id,{hideLabel:!l.hideLabel}),o(!1)},className:"w-full flex items-center gap-2 px-3 py-2 text-sm text-gray-200 hover:bg-gray-700/60 text-left",children:[t.jsx("input",{type:"checkbox",checked:!!l.hideLabel,readOnly:!0,className:"h-3.5 w-3.5 rounded border-gray-600 bg-gray-800 text-(--theme-primary-color,#bb86fc) pointer-events-none"}),"Hide Label"]}),t.jsxs("button",{type:"button",onClick:()=>{j(l.id),o(!1)},className:"w-full flex items-center gap-2 px-3 py-2 text-sm text-gray-200 hover:bg-gray-700/60 text-left",children:[t.jsx(se,{className:"w-4 h-4"})," Edit"]}),t.jsxs("button",{type:"button",onClick:()=>{D(s,l.id),o(!1)},className:"w-full flex items-center gap-2 px-3 py-2 text-sm text-gray-200 hover:bg-gray-700/60 text-left",children:[t.jsx(Q,{className:"w-4 h-4"})," Duplicate"]}),t.jsxs("button",{type:"button",onClick:()=>{u(!0),o(!1)},className:"w-full flex items-center gap-2 px-3 py-2 text-sm text-red-300 hover:bg-red-900/20 text-left",children:[t.jsx(ee,{className:"w-4 h-4"})," Delete"]})]})}),document.body),t.jsx(K,{isOpen:m,onClose:()=>u(!1),title:"Delete Field?",size:"sm",footer:t.jsxs(t.Fragment,{children:[t.jsx(T,{variant:"ghost",onClick:()=>u(!1),children:"Cancel"}),t.jsx(T,{variant:"error",onClick:()=>{N(s,l.id),u(!1)},children:"Delete"})]}),children:t.jsxs("p",{className:"text-gray-300",children:['This will remove the field "',l.label,'" from the form. This action cannot be undone.']})}),t.jsx(st,{open:p,position:h,onClose:()=>{x(!1),g(null)},contextType:"field",targetId:l.id,sectionId:s,onAddField:n,onCopyField:I,onPasteField:F,onDeleteField:N})]});var L},xt={EQUALS:"equals",NOT_EQUALS:"notEquals",GREATER_THAN:"greaterThan",LESS_THAN:"lessThan",GREATER_THAN_OR_EQUAL:"greaterThanOrEqual",LESS_THAN_OR_EQUAL:"lessThanOrEqual",CONTAINS:"contains",NOT_CONTAINS:"notContains",STARTS_WITH:"startsWith",ENDS_WITH:"endsWith",MATCHES:"matches",IN:"in",NOT_IN:"notIn",IS_EMPTY:"isEmpty",IS_NOT_EMPTY:"isNotEmpty",AND:"and",OR:"or",NOT:"not"},ht={[xt.EQUALS]:"Equals",[xt.NOT_EQUALS]:"Does not equal",[xt.GREATER_THAN]:"Greater than",[xt.LESS_THAN]:"Less than",[xt.GREATER_THAN_OR_EQUAL]:"Greater than or equal to",[xt.LESS_THAN_OR_EQUAL]:"Less than or equal to",[xt.CONTAINS]:"Contains",[xt.NOT_CONTAINS]:"Does not contain",[xt.STARTS_WITH]:"Starts with",[xt.ENDS_WITH]:"Ends with",[xt.MATCHES]:"Matches pattern",[xt.IN]:"Is one of",[xt.NOT_IN]:"Is not one of",[xt.IS_EMPTY]:"Is empty",[xt.IS_NOT_EMPTY]:"Is not empty",[xt.AND]:"AND",[xt.OR]:"OR",[xt.NOT]:"NOT"};function gt(e){const{EQUALS:t,NOT_EQUALS:a,CONTAINS:l,NOT_CONTAINS:s,STARTS_WITH:i,ENDS_WITH:n,GREATER_THAN:r,LESS_THAN:o,GREATER_THAN_OR_EQUAL:c,LESS_THAN_OR_EQUAL:d,IN:m,NOT_IN:u,IS_EMPTY:p,IS_NOT_EMPTY:x,MATCHES:h}=xt;switch(e){case"text":case"textarea":case"email":case"url":return[t,a,l,s,i,n,h,p,x];case"number":case"rating":case"linearScale":case"date":case"time":case"datetime":case"scale":return[t,a,r,o,c,d,p,x];case"select":case"radio":return[t,a,m,u,p,x];case"multiSelect":case"checkbox":return[l,s,m,u,p,x];case"wow_role_selection":case"wow_class_selection":return[t,a,l,s,m,u,p,x];case"wow_flex_selection":case"wow_boss_selection":return[p,x];default:return[t,a,l,s,r,o,c,d,m,u,p,x]}}function ft(e){return![xt.IS_EMPTY,xt.IS_NOT_EMPTY].includes(e)}function bt(e){return[xt.IN,xt.NOT_IN].includes(e)}function yt(e,t,a=null){const l={type:t,fieldId:e};return ft(t)&&(l.value=a),l}function vt(e="and",t=[]){return{type:e,conditions:t.length>0?t:[yt("",xt.EQUALS,"")]}}function jt(e){return e?.type&&[xt.AND,xt.OR,xt.NOT].includes(e.type)}function wt(e,t=[]){if(!e||"object"!=typeof e)return"Always show";const{type:a,fieldId:l,value:s,conditions:i}=e;if(a===xt.AND)return Array.isArray(i)&&0!==i.length?i.map(e=>wt(e,t)).join(" AND "):"Invalid AND condition";if(a===xt.OR)return Array.isArray(i)&&0!==i.length?i.map(e=>wt(e,t)).join(" OR "):"Invalid OR condition";if(a===xt.NOT)return Array.isArray(i)&&0!==i.length?`NOT (${wt(i[0],t)})`:"Invalid NOT condition";const n=t.find(e=>e.id===l&&!e.deleted),r=n?.label||l||"Unknown field",o=ht[a]||a;return ft(a)?bt(a)?`${r} ${o} [${Array.isArray(s)?s.join(", "):s}]`:`${r} ${o} "${s}"`:`${r} ${o}`}function Nt(e){return e&&"object"==typeof e?jt(e)?Array.isArray(e.conditions)?e.conditions.reduce((e,t)=>
1e+Nt(t),0):0:1:0}function Ct(e,t=[]){const a=[];if(!e)return{valid:!0,errors:a};const{type:l,fieldId:s,value:i,conditions:n}=e;if(!l)return a.push("Condition type is required"),{valid:!1,errors:a};if(jt(e))return n&&0!==n.length?n.forEach((e,l)=>{const s=Ct(e,t);s.valid||a.push(`Sub-condition ${l+1}: ${s.errors.join(", ")}`)}):a.push(`${l.toUpperCase()} condition must have at least one sub-condition`),{valid:0===a.length,errors:a};if(s){const e=t.find(e=>e.id===s&&!e.deleted);e?gt(e.type).includes(l)||a.push(`Operator "${l}" is not valid for field type "${e.type}"`):a.push(`Field "${s}" not found`)}else a.push("Field ID is required");return ft(l)&&null==i&&a.push("Value is required for this operator"),bt(l)&&!Array.isArray(i)&&a.push("Value must be an array for this operator"),{valid:0===a.length,errors:a}}function St(e=[],t={}){if(!Array.isArray(e))return[];const{includeFromOtherSections:a=!0,currentSectionId:l=null}=t,s=[];return e.forEach(e=>{e&&(!a&&l&&e.id!==l||Array.isArray(e.fields)&&e.fields.forEach(t=>{t&&t.id&&!t.deleted&&(j(t)||s.push({...t,sectionId:e.id,sectionLabel:e.label||e.title}))}))}),s}function Dt(e){if(!e)return[];const t=[];return e.fieldId&&t.push(e.fieldId),e.conditions&&e.conditions.forEach(e=>{t.push(...Dt(e))}),t}const Tt="w-full px-3 py-2 bg-gray-800/50 border border-gray-700/50 rounded-lg text-sm text-gray-200 focus:outline-hidden focus:ring-2 focus:ring-(--theme-primary-color,#bb86fc) disabled:opacity-50 disabled:cursor-not-allowed",kt="w-full px-3 py-2 bg-gray-800/50 border border-gray-700/50 rounded-lg text-sm text-gray-200 placeholder-gray-500 focus:outline-hidden focus:ring-2 focus:ring-(--theme-primary-color,#bb86fc) disabled:opacity-50 disabled:cursor-not-allowed";function It({label:e,children:a,className:l=""}){return t.jsxs("div",{className:`flex flex-col gap-1 ${l}`,children:[t.jsx("label",{className:"text-xs font-medium text-gray-400",children:e}),a]})}function Ft({condition:a,availableFields:l=[],onChange:s,disabled:i=!1}){const n=e.useMemo(()=>l.find(e=>e.id===a?.fieldId),[l,a?.fieldId]),r=e.useMemo(()=>n?gt(n.type):[],[n]),o=e=>{s({...a,value:e.target.value})};return t.jsxs("div",{className:"flex flex-col sm:flex-row gap-3 items-stretch",children:[t.jsx(It,{label:"Field",className:"flex-1 min-w-0",children:t.jsxs("select",{value:a?.fieldId??"",onChange:e=>{const t=e.target.value,i=l.find(e=>e.id===t),n=(i?gt(i.type):[])[0]||xt.EQUALS;s({...a,fieldId:t,type:n,value:ft(n)?"":void 0})},disabled:i,className:Tt,children:[t.jsx("option",{value:"",children:"Select a field"}),l.map(e=>t.jsx("option",{value:e.id,children:e.sectionLabel?`${e.sectionLabel} - ${e.label}`:e.label},e.id))]})}),t.jsx(It,{label:"Condition",className:"flex-1 min-w-0",children:t.jsx("select",{value:a?.type??"",onChange:e=>{const t=e.target.value,l=ft(t),i=bt(t);s({...a,type:t,value:l?i?[]:"":void 0})},disabled:i||!n,className:Tt,children:r.map(e=>t.jsx("option",{value:e,children:ht[e]||e},e))})}),t.jsx("div",{className:"flex-1 min-w-0",children:(()=>{if(!ft(a?.type))return null;const e=bt(a?.type),l=function(e){if(!e)return[];switch(e.type){case"select":case"radio":case"checkbox":case"multiSelect":return Array.isArray(e.options)?e.options.map(e=>"string"==typeof e?{value:e,label:e}:{value:e.value,label:e.label}):[];case"wow_role_selection":return(e.config?.availableRoles||["tank","healer","dps"]).filter(e=>p[e]).map(e=>({value:e,label:p[e].label}));case"wow_class_selection":{const t=Object.keys(x),a=e.config?.allowedClasses;return(a&&a.length>0?a:t).map(e=>({value:e,label:e}))}default:return[]}}(n);if(e){if(l.length>0){const e=Array.isArray(a.value)?a.value:[];return t.jsx(It,{label:"Value",children:t.jsx("div",{className:"flex flex-wrap gap-1.5 p-2 bg-gray-800/50 border border-gray-700/50 rounded-lg min-h-[44px]",children:l.map(l=>{const n=e.includes(l.value);return t.jsx("button",{type:"button",onClick:()=>!i&&(e=>{const t=Array.isArray(a.value)?a.value:[],l=t.includes(e)?t.filter(t=>t!==e):[...t,e];s({...a,value:l})})(l.value),disabled:i,className:"inline-flex items-center px-2 py-1 rounded-full text-xs font-medium border transition-colors disabled:opacity-50 "+(n?"border-(--theme-primary-color,#bb86fc) bg-(--theme-primary-color,#bb86fc)/20 text-(--theme-primary-color,#bb86fc)":"border-gray-700/60 text-gray-300 hover:bg-gray-700/40"),children:l.label},l.value)})})})}return t.jsxs(It,{label:"Values (comma-separated)",children:[t.jsx("input",{type:"text",value:Array.isArray(a.value)?a.value.join(", "):"",onCh
1ange:e=>{const t=e.target.value.split(",").map(e=>e.trim()).filter(Boolean);s({...a,value:t})},disabled:i,className:kt}),t.jsx("p",{className:"text-xs text-gray-500",children:"Enter multiple values separated by commas"})]})}if(l.length>0)return t.jsx(It,{label:"Value",children:t.jsxs("select",{value:a.value??"",onChange:o,disabled:i,className:Tt,children:[t.jsx("option",{value:"",children:"Select..."}),l.map(e=>t.jsx("option",{value:e.value,children:e.label},e.value))]})});const r={number:"number",rating:"number",linearScale:"number",scale:"number",date:"date",time:"time",datetime:"datetime-local"}[n?.type]||"text";return t.jsx(It,{label:"Value",children:t.jsx("input",{type:r,value:a.value??"",onChange:o,disabled:i,className:kt})})})()})]})}const At=["bg-gray-800/30","bg-gray-800/50","bg-gray-800/70"];function Lt({conditionGroup:e,availableFields:a=[],onChange:l,disabled:s=!1,depth:i=0,allowNesting:n=!0,showNotToggle:r=!0}){const o=i>0,c=n&&i<3,d=e?.type===xt.NOT,m=d?e.conditions[0]:e,u=m?.type||xt.AND,p=m?.conditions||[],x=t=>{l(d?{...e,conditions:[t]}:t)},h=(e,t)=>{const a=[...p];a[e]=t,x({...m,conditions:a})},g=At[Math.min(i,At.length-1)];return t.jsxs("div",{className:`rounded-lg p-3 ${g} ${d?"border-2 border-dashed border-red-500/60":"border "+(o?"border-gray-700/60":"border-gray-700/40")}`,children:[t.jsxs("div",{className:"mb-3 flex flex-wrap items-center justify-between gap-2",children:[t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("div",{className:"inline-flex rounded-lg border border-gray-700/50 bg-gray-900/40 p-0.5",children:[xt.AND,xt.OR].map(e=>{const a=u===e;return t.jsx("button",{type:"button",onClick:()=>{var t;(t=e)&&t!==u&&x({...m,type:t})},disabled:s,className:"px-3 py-1 rounded text-xs font-bold transition-colors disabled:opacity-50 "+(a?"bg-(--theme-primary-color,#bb86fc) text-white":"text-gray-300 hover:bg-gray-700/60"),children:e.toUpperCase()},e)})}),r&&t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(ne,{checked:d,onChange:e=>{var t;e&&!d?l((t=m,{type:xt.NOT,conditions:[t]})):!e&&d&&l(m)},disabled:s,size:"sm"}),t.jsx("span",{className:"text-sm font-medium "+(d?"text-red-400":"text-gray-400"),children:"NOT"})]})]}),t.jsxs("div",{className:"flex gap-1",children:[t.jsx(ie,{content:"Add condition",children:t.jsxs("button",{type:"button",onClick:()=>{const e=yt("",xt.EQUALS,"");x({...m,conditions:[...p,e]})},disabled:s,className:"inline-flex items-center gap-1 px-2 py-1 rounded-md text-xs font-medium text-(--theme-primary-color,#bb86fc) hover:bg-(--theme-primary-color,#bb86fc)/10 disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:[t.jsx(X,{className:"w-3.5 h-3.5"}),"Condition"]})}),c&&t.jsx(ie,{content:"Add nested group",children:t.jsxs("button",{type:"button",onClick:()=>{if(!c)return;const e=vt(xt.AND);x({...m,conditions:[...p,e]})},disabled:s,className:"inline-flex items-center gap-1 px-2 py-1 rounded-md text-xs font-medium text-(--theme-primary-color,#bb86fc) hover:bg-(--theme-primary-color,#bb86fc)/10 disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:[t.jsx(Ke,{className:"w-3.5 h-3.5"}),"Group"]})})]})]}),t.jsx("div",{className:"flex flex-col gap-2",children:p.map((e,l)=>t.jsxs("div",{className:"flex gap-2 items-start",children:[l>0&&t.jsx("span",{className:"self-center px-2 py-0.5 rounded bg-gray-900/60 text-xs font-bold text-gray-400 uppercase",children:u.toUpperCase()}),t.jsx("div",{className:"flex-1 min-w-0",children:jt(e)||e?.type===xt.NOT?t.jsx(Lt,{conditionGroup:e,availableFields:a,onChange:e=>h(l,e),disabled:s,depth:i+1,allowNesting:n,showNotToggle:r}):t.jsx(Ft,{condition:e,availableFields:a,onChange:e=>h(l,e),disabled:s})}),t.jsx(ie,{content:"Remove",children:t.jsx("button",{type:"button",onClick:()=>(e=>{p.length<=1||x({...m,conditions:p.filter((t,a)=>a!==e)})})(l),disabled:s||p.length<=1,className:"self-center p-2 rounded hover:bg-gray-700/50 text-gray-400 hover:text-red-400 disabled:opacity-30 disabled:cursor-not-allowed disabled:hover:text-gray-400 transition-colors",children:t.jsx(ee,{className:"w-4 h-4"})})})]},l))}),i>=3&&t.jsx("p",{className:"mt-2 text-xs text-yellow-400",children:"Maximum nesting depth reached"})]})}const Et="inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium border";function Pt({condition:a,fields:l=[],compact:s=!1,expandable:i=!0}){const[n,r]=e.useState(!1);if(!a)return t.jsxs("span",{className:`${Et} border-gray-700/60 text-gray-300`,children:[t.jsx(re,{className:"w-3 h-3"}),"No conditions"]});const o=Nt(a);return s&&!n?t.jsxs("div",{className:"inline-flex items-center gap-1",children:[t.jsxs("button",{type:"button",onClick:i?()=>r(!0):void 0,disabled:!i,className:`${Et} border-(--theme-primary-color,#bb86fc)/60 text-(--theme-primary-color,#bb86fc) ${i?"cursor-pointer hover:bg-(--theme-primary-color,#bb86fc)/10":""}`,children:[t.jsx(re,{className:"w-3 h-3"}),o," condition",1!==o?"s":""]}),i&&t.jsx("button",{type:"button",onClick:()=>r(!0),className:"p-1 rounded hover:bg-gray-700/50 text-gray-400 hover:text-gray-200","aria-label":"Expand",children:t.jsx(I,{className:"w-4 h-4"})})]}):t.jsxs("div",{className:"rounded-lg border border-gray-700/60 bg-gray-800/40 p-3",children:[t.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[t.jsx("span",{className:"text-sm font-semibold text-gray-300",children:"Condition Preview"}),i&&s&&t.jsx("button",{type:"button",onClick:()=>r(!1),className:"p-1 rounded hover:bg-gray-700/50 text-gray-400 hover:text-gray-200","aria-label":"Collapse",children:t.jsx(I,{className:"w-4 h-4 rotate-180"})})]}),t.jsx(Rt,{condition:a,fields:l,depth:0})]})}function Rt({condition:e,fields:a,depth:l=0}){if(!e)return null;const s=e.type===xt.NOT,i=s?e.conditions[0]:e;if(jt(i)){const e=i.type.toUpperCase(),n=i.conditions||[],r="AND"===e?"border-(--theme-primary-color,#bb86fc)/60 text-(--theme-primary-color,#bb86fc) bg-(--theme-primary-color,#bb86fc)/10":"border-pink-500/60 text-pink-300 bg-pink-900/20";return t.jsxs("div",{className:"py-1 "+(l>0?"border-l-2 border-gray-700/50 pl-3":""),style:{paddingLeft:l>0?.75*l+"rem":void 0},children:[s&&t.jsx("span",{className:`${Et} mb-1 mr-1 border-red-500/60 text-red-300 bg-red-900/30 font-bold`,children:"NOT"}),t.jsx("span",{className:`${Et} mb-2 font-bold ${r}`,children:e}),t.jsx("div",{className:"flex flex-col gap-1",children:n.map((s,i)=>t.jsxs("div",{children:[i>0&&t.jsx("div",{className:"text-xs font-bold uppercase text-gray-400 mb-1",style:{paddingLeft:.75*l+.5+"rem"},children:e}),t.jsx(Rt,{condition:s,fields:a,depth:l+1})]},i))})]})}const n=a.find(e=>e.id===i.fieldId),r=n?.label||i.fieldId||"Unknown field",o=wt(i,a).replace(r,"");return t.jsxs("div",{className:"py-1 "+(l>0?"border-l-2 border-gray-700/50 pl-3":""),style:{paddingLeft:l>0?.75*l+"rem":void 0},children:[s&&t.jsx("span",{className:`${Et} mr-1 border-red-500/60 text-red-300 bg-red-900/30 font-bold`,children:"NOT"}),t.jsxs("span",{className:"text-sm text-gray-200",children:[t.jsx("strong",{children:r}),o]})]})}function _t({condition:e,fields:a=[]}){if(!e)return t.jsx("span",{className:"text-sm text-gray-400",children:"Always"});const l=wt(e,a);return t.jsxs("span",{className:"text-sm font-mono text-gray-200",children:["IF ",l]})}function Mt({children:e,variant:a="info",onClose:l}){const s="error"===a?F:"warning"===a?A:L;return t.jsxs("div",{className:`flex items-start gap-2 p-3 rounded-lg border text-sm ${{info:"bg-cyan-900/20 border-cyan-700/40 text-cyan-200",warning:"bg-yellow-900/20 border-yellow-700/40 text-yellow-200",error:"bg-red-900/20 border-red-700/40 text-red-200"}[a]}`,children:[t.jsx(s,{className:"w-4 h-4 shrink-0 mt-0.5"}),t.jsx("div",{className:"flex-1",children:e}),l&&t.jsx("button",{type:"button",onClick:l,className:"p-0.5 rounded hover:bg-black/20 transition-colors","aria-label":"Close",children:t.jsx(E,{className:"w-4 h-4"})})]})}function Ot({open:a,onClose:l,currentCondition:s=null,sections:i=[],currentFieldId:n=null,currentSectionId:r=null,title:o="Conditional Visibility",description:c="Configure when this 
1should be shown",allowCrossSectionReferences:d=!0,onSave:m}){const[u,p]=e.useState(s||vt("and")),[x,h]=e.useState(null),g=e.useMemo(()=>i&&0!==i.length?St(i,{includeFromOtherSections:d,currentSectionId:r}).filter(e=>e.id!==n):[],[i,d,r,n]),f=e.useMemo(()=>Ct(u,g),[u,g]),b=e.useMemo(()=>{if(!n)return!1;try{const e=St(i,{includeFromOtherSections:!0});return!!e.find(e=>e.id===n)&&function(e,t,a){const l=new Map;for(const r of a){if(!r||!r.id||r.deleted)continue;const e=Dt(r.showIf);e.length>0&&l.set(r.id,e)}const s=Dt(t);s.length>0&&l.set(e,s);const i=new Set,n=new Set;return function e(t){if(n.has(t))return!0;if(i.has(t))return!1;i.add(t),n.add(t);for(const a of l.get(t)||[])if(e(a))return!0;return n.delete(t),!1}(e)}(n,u,e)}catch(e){return console.error("Circular dependency check failed:",e),!1}},[n,u,i]);return t.jsx(K,{isOpen:a,onClose:l,title:t.jsxs("span",{children:[o,t.jsx("span",{className:"block text-sm font-normal text-gray-400 mt-0.5",children:c})]}),size:"2xl",footer:t.jsxs("div",{className:"flex flex-col sm:flex-row gap-2 sm:gap-2 w-full sm:justify-end",children:[t.jsx(T,{variant:"ghost",onClick:l,children:"Cancel"}),t.jsx(T,{variant:"warning",onClick:()=>{m(null),l()},disabled:!s,children:"Clear Conditions"}),t.jsx(T,{variant:"primary",onClick:()=>{f.valid?b?h("Circular dependency detected! A field cannot depend on itself (directly or indirectly)."):(h(null),m(u),l()):h(`Validation errors: ${f.errors.join(", ")}`)},disabled:!f.valid||b||0===g.length,children:"Save Condition"})]}),children:t.jsxs("div",{className:"flex flex-col gap-4",children:[t.jsxs(Mt,{variant:"info",children:[t.jsx("strong",{children:"How it works:"})," This content will only be shown when ALL or ANY of the conditions below are met. Use AND/OR groups to create complex logic."]}),t.jsxs("div",{children:[t.jsx("h3",{className:"text-base font-semibold text-gray-200 mb-2",children:"Build Condition"}),t.jsx(Lt,{conditionGroup:u,availableFields:g,onChange:p,allowNesting:!0,showNotToggle:!0})]}),t.jsx("hr",{className:"border-gray-700/50"}),t.jsxs("div",{children:[t.jsx("h3",{className:"text-base font-semibold text-gray-200 mb-2",children:"Preview"}),t.jsx(Pt,{condition:u,fields:g,compact:!1,expandable:!1})]}),!f.valid&&t.jsxs(Mt,{variant:"error",children:[t.jsx("p",{className:"font-semibold mb-1",children:"Validation Errors"}),t.jsx("ul",{className:"list-disc pl-5 space-y-0.5",children:f.errors.map((e,a)=>t.jsx("li",{children:e},a))})]}),b&&t.jsxs(Mt,{variant:"error",children:[t.jsx("p",{className:"font-semibold mb-1",children:"Circular Dependency Detected"}),t.jsx("p",{children:"This field cannot depend on itself (directly or indirectly). Please remove the circular reference."})]}),x&&t.jsx(Mt,{variant:"error",onClose:()=>h(null),children:x}),0===g.length&&t.jsx(Mt,{variant:"warning",children:"No fields available for conditions. Add fields to the form first."}),!d&&r&&t.jsx(Mt,{variant:"info",children:"Only fields from the current section are available for conditions."})]})})}const $t=[{id:"text-input",label:"Text Input",description:"Single and multi-line text fields",fields:[{type:"text",label:"Short Text",Icon:de,description:"Single line text input"},{type:"textarea",label:"Long Text",Icon:me,description:"Multi-line text input"}]},{id:"numeric",label:"Numeric",description:"Number input fields",fields:[{type:"number",label:"Number",Icon:xe,description:"Numeric value input"}]},{id:"email-web",label:"Email & Web",description:"Email and URL fields",fields:[{type:"email",label:"Email",Icon:he,description:"Email address input"},{type:"url",label:"URL",Icon:ge,description:"Website URL input"}]},{id:"selection",label:"Selection",description:"Single and multiple choice fields",fields:[{type:"select",label:"Dropdown",Icon:I,description:"Dropdown selection"},{type:"radio",label:"Radio Buttons",Icon:ue,description:"Radio button group"},{type:"checkbox",label:"Checkboxes",Icon:fe,description:"Checkbox group"}]},{id:"date-time",label:"Date & Time",description:"Date and time selection fields",fields:[{type:"date",label:"Date",Icon:be,description:"Date picker"},{type:"time",label:"Time",Icon:ye,description:"Time picker"},{type:"datetime",label:"Date & Time",Icon:P,description:"Date and time picker"},{type:"availability",label:"Availability",Icon:ve,description:"Weekly availability with time ranges"}]},{id:"rating-scale",label:"Rating & Scale",description:"Rating and scale fields",fields:[{type:"rating",label:"Star Rating",Icon:R,description:"5-star rating"},{type:"scale",label:"Linear Scale",Icon:je,description:"1-10 scale"}]},{id:"file",label:"File & Attachments",description:"File upload field",fields:[{type:"file",label:"File Upload",Icon:we,description:"File upload input"}]}
1,{id:"content-display",label:"Content & Display",description:"Static content shown to respondents — no input collected",fields:[{type:"display_text",label:"Rich Text",Icon:_,description:"Headings, paragraphs, lists (markdown)"},{type:"display_image",label:"Image",Icon:Ne,description:"Show an image or GIF from a URL"},{type:"display_video",label:"Video Embed",Icon:pe,description:"YouTube, Vimeo, or Twitch video"},{type:"display_divider",label:"Divider",Icon:Ce,description:"Visual separator with optional label"}]},{id:"wow-integration",label:"WoW Integration",description:"World of Warcraft data fields",fields:[{type:"wow_role_selection",label:"Role Selection",Icon:M,description:"Tank, Healer, DPS role picker"},{type:"wow_class_selection",label:"Class Selection",Icon:Se,description:"WoW class and spec selector"},{type:"wow_flex_selection",label:"Flex Selection",Icon:O,description:"Let applicants indicate which specs or alts they can flex to"},{type:"wow_character_battlenet",label:"Character (Battle.net)",Icon:Se,description:"Search WoW characters via Battle.net"},{type:"wow_character_linked",label:"Character (Linked)",Icon:$,description:"Select from linked characters"},{type:"wow_raiderio_lookup",label:"Raider.io Lookup",Icon:De,description:"Fetch M+ and raid data"},{type:"wow_item_lookup",label:"Item Lookup",Icon:Te,description:"Search for WoW items"},{type:"wow_spell_lookup",label:"Spell Lookup",Icon:ke,description:"Search for spells"},{type:"wow_wcl_encounter",label:"WCL Encounter",Icon:M,description:"Select Warcraft Logs encounter"},{type:"wow_boss_selection",label:"Boss Selection",Icon:Ie,description:"Pick boss(es) from a configured raid"}]}],zt=({open:a,onClose:l,onSelectField:s,position:i="end",referenceFieldId:n=null})=>{const[r,o]=e.useState(""),[c,d]=e.useState($t.reduce((e,t)=>({...e,[t.id]:!0}),{})),m=e.useMemo(()=>{if(!r.trim())return $t;const e=r.toLowerCase();return $t.map(t=>({...t,fields:t.fields.filter(t=>t.label.toLowerCase().includes(e)||t.description.toLowerCase().includes(e)||t.type.toLowerCase().includes(e))})).filter(e=>e.fields.length>0)},[r]);return t.jsx(K,{isOpen:a,onClose:()=>{o(""),l()},title:"Add Field",size:"default",children:t.jsxs("div",{className:"flex flex-col gap-4",children:[t.jsx(oe,{type:"text",placeholder:"Search field types...",value:r,onChange:e=>o(e.target.value),size:"sm",leftIcon:t.jsx(z,{className:"h-4 w-4 text-gray-400"})}),t.jsx("div",{className:"flex flex-col gap-3",children:0===m.length?t.jsx("div",{className:"py-8 text-center",children:t.jsx("p",{className:"text-sm text-gray-400",children:"No fields match your search"})}):t.jsx(C,{initial:!1,children:m.map((e,a)=>t.jsx(S.div,{initial:{opacity:0,y:-10},animate:{opacity:1,y:0},exit:{opacity:0,y:-10},transition:{delay:.05*a},children:t.jsxs("div",{children:[t.jsxs("button",{type:"button",onClick:()=>{return t=e.id,void d(e=>({...e,[t]:!e[t]}));var t},className:"\n                        w-full flex items-center justify-between\n                        rounded-lg border border-gray-700/50 bg-gray-800/40\n                        px-3 py-2.5 text-left\n                        hover:bg-gray-700/40 transition-colors\n                        focus:outline-hidden focus-visible:ring-2 focus-visible:ring-(--theme-primary-color,#bb86fc)/40\n                      ",children:[t.jsxs("div",{className:"min-w-0",children:[t.jsx("p",{className:"text-sm font-semibold text-gray-100",children:e.label}),t.jsx("p",{className:"text-xs text-gray-400",children:e.description})]}),c[e.id]?t.jsx(Fe,{className:"h-4 w-4 shrink-0 text-gray-400","aria-hidden":"true"}):t.jsx(I,{className:"h-4 w-4 shrink-0 text-gray-400","aria-hidden":"true"})]}),t.jsx(C,{initial:!1,children:c[e.id]&&t.jsx(S.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:.18},className:"overflow-hidden",children:t.jsx("div",{className:"grid grid-cols-2 gap-2 mt-2",children:e.fields.map((e,a)=>{const{Icon:r}=e;return t.jsxs(S.button,{type:"button",initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},transition:{delay:.04*a},onClick:()=>{return t=e.type,s(t,i,n),o(""),void l();var t},whileHover:{y:-2},className:"\n                                    flex flex-col items-center justify-center\n                                    min-h-[6.25rem] p-3\n                                    rounded-lg border border-gray-700/50 bg-gray-800/40\n                                    hover:border-(--theme-primary-color,#bb86fc)/60\n                                    hover:bg-gray-700/40\n                                    transition-colors\n                                    focus:outline-hidden focu
1s-visible:ring-2 focus-visible:ring-(--theme-primary-color,#bb86fc)/40\n                                  ",title:e.description,children:[t.jsx("div",{className:"\n                                    flex items-center justify-center\n                                    w-12 h-12 mb-2 rounded-lg\n                                    bg-(--theme-primary-color,#bb86fc)/15\n                                    text-(--theme-primary-color,#bb86fc)\n                                  ",children:t.jsx(r,{className:"h-5 w-5","aria-hidden":"true"})}),t.jsx("p",{className:"text-sm font-medium text-gray-100 text-center leading-tight",children:e.label})]},e.type)})})})})]})},e.id))})})]})})},Ut="w-full px-3 py-2 bg-gray-800/50 border border-gray-700/50 rounded-lg text-sm text-gray-200 placeholder-gray-500 focus:outline-hidden focus:ring-2 focus:ring-(--theme-primary-color,#bb86fc)",Bt=({section:l,isActive:s,onSelect:i,onDragStart:n,onContextMenu:r})=>{const[o,c]=e.useState(!1),[d,m]=e.useState(!1),[u,p]=e.useState(!0),[x,h]=e.useState(null),[g,f]=e.useState(!1),[b,y]=e.useState(null),[v,j]=e.useState(!1),[w,N]=e.useState("end"),[D,k]=e.useState(null),[F,A]=e.useState(!1),[L,E]=e.useState(null),[P,R]=e.useState(null),[_,M]=e.useState(!1),[O,$]=e.useState(!1),[z,U]=e.useState(l.title),[B,H]=e.useState(l.description),q=e.useRef(null),W=e.useRef(null),{activePageId:V,formTemplate:G,updateSectionTitle:Y,updateSectionDescription:Z,updateSectionConditionalLogic:J,reorderFields:ae,moveFieldBetweenSections:se,removeField:ie,addField:ne,copyField:re,pasteField:oe,removeSection:ce,duplicateSection:de,moveSectionToPage:me,updateSection:ue}=et(),pe=2===Number(G.templateData?.version),xe=pe&&G.templateData?.pages||[],he=pe?G.templateData?.pages?.flatMap(e=>e.sections)||[]:G.templateData?.sections||[],ge=e.useRef(null),fe=e.useRef(null),be=e.useCallback(e=>{U(e),clearTimeout(ge.current),ge.current=setTimeout(()=>{Y(l.id,e)},300)},[l.id,Y]),ye=e.useCallback(e=>{H(e),clearTimeout(fe.current),fe.current=setTimeout(()=>{Z(l.id,e)},300)},[l.id,Z]);e.useEffect(()=>()=>{clearTimeout(ge.current),clearTimeout(fe.current)},[]),e.useEffect(()=>{U(l.title)},[l.title]),e.useEffect(()=>{H(l.description)},[l.description]),e.useEffect(()=>{if(!g)return;const e=e=>{W.current&&!W.current.contains(e.target)&&q.current&&!q.current.contains(e.target)&&f(!1)},t=e=>{"Escape"===e.key&&f(!1)};return document.addEventListener("mousedown",e),document.addEventListener("keydown",t),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("keydown",t)}},[g]);const ve=e=>{e.preventDefault(),h(null)},je=(e,t)=>{e.preventDefault(),e.stopPropagation(),h(null);const a=e.dataTransfer.getData("fieldId"),s=e.dataTransfer.getData("sourceSectionId");if(a)if(s===l.id){const e=l.fields.filter(e=>e.id&&!e.deleted),s=l.fields.filter(e=>e.id&&e.deleted),i=e.findIndex(e=>e.id===a);if(-1===i||i===t)return;const[n]=e.splice(i,1);e.splice(t,0,n),ae(l.id,[...e,...s])}else se(s,l.id,a,t)},we=(e="end",t=null)=>{N(e),k(t),j(!0)},Ne=()=>{j(!1),N("end"),k(null)},Ce=l.fields?l.fields.filter(e=>e.id&&!e.deleted):[];return t.jsxs("div",{onContextMenu:e=>((e,t,a=null)=>{e.preventDefault(),e.stopPropagation(),E({mouseX:e.clientX,mouseY:e.clientY}),R({type:t,id:a||l.id}),A(!0)})(e,"section"),className:"rounded-xl glass-card transition-all "+(s?"border-2 border-(--theme-primary-color,#bb86fc) bg-(--theme-primary-color,#bb86fc)/5":"border border-gray-700/50"),children:[t.jsxs("div",{className:"flex items-start gap-2 p-3 pb-1 cursor-pointer",onClick:i,children:[t.jsx("div",{draggable:!0,onDragStart:e=>{e.dataTransfer.effectAllowed="move",e.dataTransfer.setData("sectionId",l.id),e.dataTransfer.setData("dragType","section"),e.stopPropagation()},className:"flex items-center pt-1 cursor-grab active:cursor-grabbing text-gray-500",children:t.jsx(te,{className:"w-4 h-4"})}),t.jsxs("div",{className:"flex-1 min-w-0",children:[o?t.jsx("input",{type:"text",value:z,onChange:e=>be(e.target.value),onBlur:()=>c(!1),onKeyDown:e=>{"Enter"!==e.key&&"Escape"!==e.key||c(!1)},autoFocus:!0,onClick:e=>e.stopPropagation(),className:Ut}):t.jsx("h3",{onClick:e=>{e.stopPropagation(),c(!0)},className:"text-base font-semibold text-gray-200 cursor-pointer hover:text-white transition-colors",children:l.title}
1),d?t.jsx("textarea",{rows:2,value:B||"",onChange:e=>ye(e.target.value),onBlur:()=>m(!1),autoFocus:!0,onClick:e=>e.stopPropagation(),className:`${Ut} mt-1`}):t.jsx("p",{onClick:e=>{e.stopPropagation(),m(!0)},className:"mt-1 text-sm text-gray-400 cursor-pointer hover:text-gray-200 transition-colors",children:l.description||"Click to add section description"})]}),t.jsxs("div",{className:"flex gap-1 items-center",children:[l.showIf&&t.jsxs("button",{type:"button",onClick:e=>{e.stopPropagation(),M(!0)},className:"relative p-2 rounded text-(--theme-primary-color,#bb86fc) hover:bg-(--theme-primary-color,#bb86fc)/10 transition-colors","aria-label":"Edit visibility conditions",children:[t.jsx(Ae,{className:"w-4 h-4"}),Nt(l.showIf)>0&&t.jsx("span",{className:"absolute top-0 right-0 w-3.5 h-3.5 rounded-full bg-(--theme-primary-color,#bb86fc) text-white text-[9px] font-bold flex items-center justify-center",children:Nt(l.showIf)})]}),t.jsx("button",{type:"button",onClick:e=>{e.stopPropagation(),p(e=>!e)},className:"p-2 rounded hover:bg-gray-700/50 text-gray-400 hover:text-gray-200 transition-colors","aria-label":u?"Collapse":"Expand",children:t.jsx(I,{className:"w-4 h-4 transition-transform "+(u?"":"-rotate-90")})}),t.jsx("button",{ref:q,type:"button",onClick:e=>{e.stopPropagation();const t=e.currentTarget.getBoundingClientRect();y({top:t.bottom+4,left:t.right-220}),f(!0)},className:"p-2 rounded hover:bg-gray-700/50 text-gray-400 hover:text-gray-200 transition-colors","aria-label":"Section actions",children:t.jsx(le,{className:"w-4 h-4"})})]})]}),a.createPortal(t.jsx(C,{children:g&&b&&t.jsxs(S.div,{ref:W,initial:{opacity:0,scale:.95,y:-4},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:-4},transition:{duration:.12},style:{position:"fixed",top:b.top,left:Math.max(8,b.left),zIndex:9999},className:"min-w-[14rem] py-1 rounded-lg border border-gray-700/50 bg-gray-800/95 backdrop-blur-xs shadow-2xl",children:[t.jsxs("button",{type:"button",onClick:()=>{M(!0),f(!1)},className:"w-full flex items-center gap-2 px-3 py-2 text-sm text-gray-200 hover:bg-gray-700/60 text-left",children:[l.showIf?t.jsx(Ae,{className:"w-4 h-4"}):t.jsx(Le,{className:"w-4 h-4"}),l.showIf?"Edit Visibility Conditions":"Set Visibility Conditions"]}),t.jsxs("button",{type:"button",onClick:e=>{e.stopPropagation(),ue(l.id,{hideTitle:!l.hideTitle})},className:"w-full flex items-center gap-2 px-3 py-2 text-sm text-gray-200 hover:bg-gray-700/60 text-left",children:[t.jsx("input",{type:"checkbox",checked:!!l.hideTitle,readOnly:!0,className:"h-3.5 w-3.5 rounded border-gray-600 bg-gray-800 text-(--theme-primary-color,#bb86fc) pointer-events-none"}),"Hide Title"]}),l.description&&t.jsxs("button",{type:"button",onClick:e=>{e.stopPropagation(),ue(l.id,{hideDescription:!l.hideDescription})},className:"w-full flex items-center gap-2 px-3 py-2 text-sm text-gray-200 hover:bg-gray-700/60 text-left",children:[t.jsx("input",{type:"checkbox",checked:!!l.hideDescription,readOnly:!0,className:"h-3.5 w-3.5 rounded border-gray-600 bg-gray-800 text-(--theme-primary-color,#bb86fc) pointer-events-none"}),"Hide Description"]}),t.jsxs("button",{type:"button",onClick:()=>{de(l.id),f(!1)},className:"w-full flex items-center gap-2 px-3 py-2 text-sm text-gray-200 hover:bg-gray-700/60 text-left",children:[t.jsx(Q,{className:"w-4 h-4"})," Duplicate"]}),pe&&xe.length>1&&xe.filter(e=>e.id!==V).map(e=>t.jsxs("button",{type:"button",onClick:()=>{me(l.id,e.id),f(!1)},className:"w-full flex items-center gap-2 px-3 py-2 text-sm text-gray-200 hover:bg-gray-700/60 text-left",children:[t.jsx(Ye,{className:"w-4 h-4"})," Move to ",e.title]},e.id)),t.jsxs("button",{type:"button",onClick:()=>{$(!0),f(!1)},className:"w-full flex items-center gap-2 px-3 py-2 text-sm text-red-300 hover:bg-red-900/20 text-left",children:[t.jsx(ee,{className:"w-4 h-4"})," Delete"]})]})}),document.body),t.jsx(C,{initial:!1,children:u&&t.jsx(S.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:.2},className:"overflow-hidden",children:t.jsxs("div",{className:"px-4 pb-4",children:[t.jsx(C,{mode:"popLayout",children:0===Ce.length?t.jsx(S.div,{variants:ct,initial:"hidden",animate:"visible",exit:"exit",children:t.jsx("div",{className:"text-center py-3 rounded "+(0===x?"outline-dashed outline-2 -outline-offset-2 outline-(--theme-primary-color,#bb86fc)":""),onDragOver:e=>{e.preventDefault(),e.stopPropagation(),h(0)},onDragLeave:ve,onDrop:e=>je(e,0),children:t.jsx("p",{className:"text-sm text-gray-400 mb-2",children:'No fields yet. Drag fields from the left panel or click "Add Field".'})})},"empty-fields"):t.jsx(S.div,{variants:ot,initial:"hidden",animate:"visible",children:t.jsx("div",{className:"flex flex-col gap-2",children:Ce.map((e,a)=>t.jsx(S.div,{layout:!0,variants:rt,custom:a,onDragOver:e=>((e,t)=>{e.preventDefault(),e.stopPropagation(),h(t)})(e,a),onDragLeave:ve,onDrop:e=>je(e,a),className:"rounded "+(x===a?"outline-dashed outline-2 -outline-offset-2 outline-(--theme-primary-color,#bb86fc)":""),children:t.jsx(pt,{field:e,sectionId:l.id,onDragStart:()=>n?.(e.type),onAddField:we})},e.id))})})}),t.jsx("div",{className:"flex justify-center mt-4",children:t.jsxs(S.button,{type:"button",onClick:()=>we(),whileHover:{scale:1.01},whileTap:{scale:.99},className:"w-full inline-flex items-center justify-center gap-2 px-4 py-3 rounded-lg border-2 border-dashed border-gray-600 text-gray-300 hover:border-(--theme-primary-color,#bb86fc) hover:bg-(--theme-primary-color,#bb86fc)/5 hover:text-(--theme-primary-color,#bb86fc) transition-colors",children:[t.jsx(X,{className:"w-4 h-4"}),"Add Field"]})})]})})}),_&&l&&t.jsx(Ot,{open:!0,onClose:()=>M(!1),currentCondition:l.showIf||null,sections:he||[],currentSectionId:l.id,title:"Section Visibility Conditions",description:`Configure when "${l.title}" section should be shown`,allowCrossSectionReferences:!0,onSave:e=>{J(l.id,e)}}),t.jsx(zt,{open:v,onClose:Ne,onSelectField:(e,t="end",a=null)=>{"end"===t?ne(l.id,e):ne(l.id,e,t,a),Ne()},position:w,referenceFieldId:D}),t.jsx(st,{open:F,position:L,onClose:()=>{A(!1),E(null),R(null)},contextType:P?.type,targetId:P?.id,sectionId:l.id,onAddField:we,onCopyField:re,onPasteField:oe,onDeleteField:ie}),t.jsx(K,{isOpen:O,onClose:()=>$(!1),title:"Delete Section?",size:"sm",footer:t.jsxs(t.Fragment,{children:[t.jsx(T,{variant:"ghost",onClick:()=>$(!1),children:"Cancel"}),t.jsx(T,{variant:"error",onClick:()=>{ce(l.id),$(!1)},children:"Delete"})]}),children:t.jsxs("p",{className:"text-gray-300",children:['This will delete the section "',l.title,'" and all fields within it. This action cannot be undone.']})})]})},Ht="w-full px-3 py-2 bg-gray-800/50 border border-gray-700/50 rounded-lg text-sm text-gray-200 placeholder-gray-500 focus:outline-hidden focu
1s:ring-2 focus:ring-(--theme-primary-color,#bb86fc)",qt="inline-flex items-center px-2 py-0.5 rounded-full text-[10px] font-medium border",Wt=()=>{const[l,s]=e.useState(null),[i,n]=e.useState(null),[r,o]=e.useState(!1),[c,d]=e.useState(!1),[m,u]=e.useState(null),[p,x]=e.useState(null),h=e.useRef(null),[f,b]=e.useState(null),{formTemplate:y,guildBranding:v,activeSectionId:j,activePageId:w,setActiveSection:N,setActivePage:D,addSection:k,removeSection:I,duplicateSection:F,updateFormTitle:A,updateFormDescription:L,addField:E,reorderSections:P,moveSectionToPage:R,moveFieldToPage:_}=et(),M=2===Number(y.templateData?.version),O=M&&y.templateData?.pages||[],$=(M?O.find(e=>e.id===w)?.sections||[]:y.templateData?.sections||[]).filter(e=>!e.deleted);e.useEffect(()=>{M&&!w&&O.length>0&&D(O[0].id)},[M,w,O,D]),e.useEffect(()=>{if(!p)return;const e=e=>{h.current&&!h.current.contains(e.target)&&x(null)},t=e=>{"Escape"===e.key&&x(null)},a=setTimeout(()=>{document.addEventListener("mousedown",e),document.addEventListener("keydown",t)},0);return()=>{clearTimeout(a),document.removeEventListener("mousedown",e),document.removeEventListener("keydown",t)}},[p]);const z=e=>{e.preventDefault(),n(null)},U=y.templateData?.settings?.bannerImage,B=M?O.find(e=>e.id===w):null;return t.jsx(g,{guildBranding:v,formAppearance:y?.templateData?.appearance,currentPageId:B?.id||null,viewerContext:"builder",children:t.jsxs("div",{className:"max-w-3xl mx-auto py-4 lg:py-6 px-2 sm:px-4 lg:px-6",children:[t.jsxs("div",{className:"rounded-xl glass-card p-4 lg:p-6 mb-4 lg:mb-6 overflow-hidden",children:[U&&t.jsx("div",{className:"-mx-4 -mt-4 lg:-mx-6 lg:-mt-6 mb-4",children:t.jsx("img",{src:U,alt:"Form banner",className:"w-full max-h-[300px] object-cover"})}),t.jsx("div",{className:"mb-4",children:r?t.jsx("input",{type:"text",value:y.title||"",onChange:e=>A(e.target.value),onBlur:()=>o(!1),onKeyDown:e=>{"Enter"!==e.key&&"Escape"!==e.key||o(!1)},autoFocus:!0,className:`${Ht} text-2xl lg:text-3xl font-semibold`}):t.jsx("h2",{className:"text-2xl lg:text-3xl font-semibold text-gray-100 cursor-pointer p-1 rounded hover:bg-gray-700/30 transition-colors",onClick:()=>o(!0),children:y.title||"Untitled Form"})}),t.jsx("div",{children:c?t.jsx("textarea",{rows:2,value:y.description||"",onChange:e=>L(e.target.value),onBlur:()=>d(!1),onKeyDown:e=>{"Escape"===e.key&&d(!1)},placeholder:"Add a description for your form...",autoFocus:!0,className:Ht}):t.jsx("p",{className:"text-sm text-gray-400 cursor-pointer p-1 rounded hover:bg-gray-700/30 transition-colors min-h-[40px]",onClick:()=>d(!0),children:y.description||"Click to add form description"})})]}),M&&O.length>0&&t.jsxs("div",{className:"rounded-xl glass-card mb-6 overflow-hidden",children:[t.jsx("div",{className:"flex flex-row overflow-x-auto border-b border-gray-700/50",children:O.map((e,a)=>{const l=(w||O[0].id)===e.id,s=f===e.id&&e.id!==w;return t.jsxs("button",{type:"button",onClick:()=>D(e.id),onDragOver:t=>{t.preventDefault(),b(e.id)},onDragLeave:()=>b(null),onDrop:t=>{t.preventDefault(),t.stopPropagation(),b(null);const a=t.dataTransfer.getData("dragType");if("section"===a){const a=t.dataTransfer.getData("sectionId");a&&e.id!==w&&R(a,e.id)}else if("field"===a){const a=t.dataTransfer.getData("fieldId"),l=t.dataTransfer.getData("sourceSectionId");a&&e.id!==w&&_(a,l,e.id)}},className:`shrink-0 px-4 py-3 text-sm font-medium transition-colors flex items-center gap-2 border-b-2 ${l?"border-(--theme-primary-color,#bb86fc) text-(--theme-primary-color,#bb86fc) bg-(--theme-primary-color,#bb86fc)/5":"border-transparent text-gray-400 hover:text-gray-200 hover:bg-gray-700/30"} ${s?"outline-dashed outline-2 -outline-offset-2 outline-(--theme-primary-color,#bb86fc) bg-gray-700/30":""}`,children:[t.jsx(Ge,{className:"w-4 h-4"}),t.jsx("span",{children:e.title||`Page ${a+1}`}),t.jsxs("span",{className:`${qt} border-gray-600 text-gray-400`,children:[e.sections?.filter(e=>!e.deleted).length||0," sections"]})]},e.id)})}),w&&O.find(e=>e.id===w)&&t.jsxs("div",{className:"p-3 bg-gray-900/30",children:[t.jsx("p",{className:"text-sm text-gray-400",children:O.find(e=>e.id===w).description||"No page description"}),t.jsxs("div",{className:"flex gap-1.5 mt-2 flex-wrap",children:[t.jsxs("span",{className:`${qt} border-gray-600 text-gray-300`,children:["Transition: ",O.find(e=>e.id===w).transitionType||"slide-horizontal"]}),t.jsxs("span",{className:`${qt} border-gray-600 text-gray-300`,children:["Duration: ",O.find(e=>e.id===w).transitionDuration||300,"ms"]}),!1!==O.find(e=>e.id===w).showProgressBar&&t.jsx("span",{className:`${qt} border-(--theme-primary-color,#bb86fc) text-(--theme-primary-color,#bb86fc)`,children:"Progress Bar"}),!1!==O.find(e=>e.id===w).allowBack&&t.jsx("span",{className:`${qt} border-(--theme-primary-color,#bb86fc) text-(--theme-primary-color,#bb86fc)`,children:"Allow Back"})]})]})]}),t.jsx("div",{className:"flex flex-col gap-6",children:t.jsx(C,{mode:"popLayout",children:0===$.length?t.jsx(S.div,{variants:ct,initial:"hidden",animate:"visible",exit:"exit",children:t.jsxs("div",{className:"rounded-xl glass-card p-6 text-center",children:[t.jsx("p",{className:"text-gray-400 mb-3",children:'No sections yet. Click "Add Section" to get started.'}),t.jsx(T,{variant:"outline",leftIcon:t.jsx(X,{className:"w-4 h-4"}),onClick:k,children:"Add Section"})]})},"empty-state"):t.jsx(S.div,{variants:ot,initial:"hidden",animate:"visible",className:"flex flex-col gap-6",children:$.map((e,a)=>t.jsx(S.div,{layout:!0,variants:rt,custom:a,onDragOver:t=>((e,t)=>{e.preventDefault(),e.stopPropagation(),n(t)})(t,e.id),onDragLeave:z,onDrop:t=>((e,t)=>{if(e.preventDefault(),e.stopPropagation(),n(null),"section"===e.dataTransfer.getData("dragType")){const a=e.dataTransfer.getData("sectionId");if(a&&a!==t){const e=$.findIndex(e=>e.id===a),l=$.findIndex(e=>e.id===t);if(-1!==e&&-1!==l){const t=[...$],[a]=t.splice(e,1);t.splice(l,0,a),P(t)}}return}const a=e.dataTransfer.getData("fieldType");a&&t&&E(t,a)})(t,e.id),className:"rounded-lg "+(i===e.id?"outline-dashed outline-2 -outline-offset-2 outline-(--theme-primary-color,#bb86fc)":""),children:t.jsx(Bt,{section:e,isActive:j===e.id,onSelect:()=>N(e.id),onDragStart:s,onContextMenu:t=>((e,t)=>{e.preventDefault(),x({sectionId:t,top:e.clientY,left:e.clientX})})(t,e.id)})},e.id))})})}),t.jsx("div",{className:"flex justify-center mt-6",children:t.jsx(S.div,{whileHover:{scale:1.03},whileTap:{scale:.97},children:t.jsx(T,{variant:"outline",leftIcon:t.jsx(X,{className:"w-4 h-4"}),onClick:k,children:"Add Section"})})}),p&&a.createPortal(t.jsx(C,{children:t.jsxs(S.div,{ref:h,role:"menu",initial:{opacity:0,scale:.95,y:-4}
1,animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:-4},transition:{duration:.12},style:{position:"fixed",top:p.top,left:p.left,zIndex:9999},className:"min-w-[12rem] py-1 rounded-lg border border-gray-700/50 bg-gray-800/95 backdrop-blur-xs shadow-2xl",children:[t.jsxs("button",{type:"button",onClick:()=>{F(p.sectionId),x(null)},className:"w-full flex items-center gap-2 px-3 py-2 text-sm text-gray-200 hover:bg-gray-700/60 text-left",children:[t.jsx(Q,{className:"w-4 h-4"})," Duplicate"]}),t.jsxs("button",{type:"button",onClick:()=>{u(p.sectionId),x(null)},className:"w-full flex items-center gap-2 px-3 py-2 text-sm text-red-300 hover:bg-red-900/20 text-left",children:[t.jsx(ee,{className:"w-4 h-4"})," Delete"]})]})}),document.body),t.jsx(K,{isOpen:Boolean(m),onClose:()=>u(null),title:"Delete Section?",size:"sm",footer:t.jsxs(t.Fragment,{children:[t.jsx(T,{variant:"ghost",onClick:()=>u(null),children:"Cancel"}),t.jsx(T,{variant:"error",onClick:()=>{I(m),u(null)},children:"Delete"})]}),children:t.jsx("p",{className:"text-gray-300",children:"This will delete the section and all fields within it. This action cannot be undone."})})]})})},Vt=[{value:"lfr",label:"LFR"},{value:"normal",label:"Normal"},{value:"heroic",label:"Heroic"},{value:"mythic",label:"Mythic"}],Gt=["Death Knight","Demon Hunter","Druid","Evoker","Hunter","Mage","Monk","Paladin","Priest","Rogue","Shaman","Warlock","Warrior"],Yt="w-full px-3 py-2 bg-gray-800/50 border border-gray-700/50 rounded-lg text-sm text-gray-200 placeholder-gray-500 focus:outline-hidden focus:ring-2 focus:ring-(--theme-primary-color,#bb86fc) disabled:opacity-50 disabled:cursor-not-allowed",Kt=Yt;function Xt({label:e,helperText:a,children:l,className:s=""}){return t.jsxs("div",{className:`flex flex-col gap-1 ${s}`,children:[e&&t.jsx("label",{className:"text-xs font-medium text-gray-400",children:e}),l,a&&t.jsx("p",{className:"text-xs text-gray-500",children:a})]})}function Qt({label:e,checked:a,onChange:l,disabled:s=!1}){return t.jsxs("div",{className:"flex items-center justify-between gap-3 "+(s?"cursor-not-allowed opacity-50":"cursor-pointer"),onClick:()=>{s||l(!a)},children:[t.jsx("span",{className:"text-sm text-gray-300 flex-1 select-none",children:e}),t.jsx("span",{onClick:e=>e.stopPropagation(),className:"contents",children:t.jsx(ne,{checked:!!a,onChange:l,disabled:s,size:"sm"})})]})}function Zt({value:e=[],options:a,onToggle:l,disabled:s=!1}){return t.jsx("div",{className:"flex flex-wrap gap-1.5",children:a.map(a=>{const i="object"==typeof a?a.value:a,n="object"==typeof a?a.label:a,r=e.includes(i);return t.jsx("button",{type:"button",onClick:()=>!s&&l(i),disabled:s,className:"inline-flex items-center px-2 py-1 rounded-full text-xs font-medium border transition-colors disabled:opacity-50 "+(r?"border-(--theme-primary-color,#bb86fc) bg-(--theme-primary-color,#bb86fc)/20 text-(--theme-primary-color,#bb86fc)":"border-gray-700/60 text-gray-300 hover:bg-gray-700/40"),children:n},i)})})}function Jt({values:e=[],options:a=[],onChange:l,label:s}){return t.jsx(Xt,{label:s,children:t.jsx("div",{className:"rounded-lg border border-gray-700/50 bg-gray-800/40 p-2 min-h-[44px]",children:t.jsx(Zt,{value:e,options:a,onToggle:t=>{const a=e.includes(t)?e.filter(e=>e!==t):[...e,t];l(a)}})})})}function ea({children:e}){return t.jsx("h4",{className:"text-sm font-semibold text-gray-200",children:e})}function ta({field:a,onUpdate:l}){const{allTiers:i}=Ee(),n=a.config||{},r=n.raidId||"",o=Array.isArray(n.allowedEncounterIds)?n.allowedEncounterIds:[],c="multi"===n.selectionMode?"multi":"single",[d,m]=e.useState([]),[u,p]=e.useState(!1),[x,h]=e.useState(null);e.useEffect(()=>{if(!r)return void m([]);let e=!1;return p(!0),h(null),s.get(`/api/game-data/raids/${r}/bosses`).then(t=>{e||m(t.data?.bosses||[])}).catch(t=>{e||(h(t.response?.data?.error||t.message),m([]))}).finally(()=>{e||p(!1)}),()=>{e=!0}},[r]);const g=e=>{const t=e?d.map(e=>Number(e.encounterId)):[];l({config:{...n,allowedEncounterIds:t}})};return t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"text-xs text-gray-400",children:"Pick a raid and choose which bosses respondents can select."}),t.jsx(Xt,{label:"Raid",children:t.jsxs("select",{value:r,onChange:e=>l({config:{...n,raidId:e.target.value,allowedEncounterIds:[]}}),className:Kt,children:[t.jsx("option",{value:"",children:"— Choose a raid —"}),i.map(e=>t.jsxs("option",{value:e.id,children:[e.name,e.season?` — ${e.expansion} ${e.season}`:""]},e.id))]})}),r&&t.jsxs(Xt,{label:"Allowed Bosses",helperText:u?"Loading bosses…":x?`Error: ${x}`:`${o.length} of ${d.length} selected`,children:[d.length>0&&t.jsxs("div",{className:"flex gap-2 mb-2",children:[t.jsx("button",{type:"button",onClick:()=>g(!0),className:"text-xs text-(--theme-primary-color,#bb86fc) hover:underline",children:"Select all"}),t.jsx("span",{className:"text-gray-600",children:"·"}),t.jsx("button",{type:"button",onClick:()=>g(!1),className:"text-xs text-gray-400 hover:underline",children:"Clear"})]}),t.jsxs("div",{className:"rounded-lg border border-gray-700/50 bg-gray-800/40 p-2 max-h-72 overflow-y-auto flex flex-col gap-1",children:[u&&t.jsx(t.Fragment,{children:[0,1,2,3].map(e=>t.jsxs("div",{className:"flex items-center gap-3 p-2 animate-pulse",children:[t.jsx("span",{className:"w-4 h-4 rounded border border-gray-700/60"}),t.jsx("div",{className:"w-10 h-10 rounded bg-gray-700/40"}),t.jsx("div",{className:"h-3 flex-1 rounded bg-gray-700/40"})]},e))}),!u&&d.map(e=>{const a=Number(e.encounterId),s=o.includes(a);return t.jsxs("button",{type:"button",onClick:()=>(e=>{const t=Number(e),a=o.includes(t)?o.filter(e=>e!==t):[...o,t];l({config:{...n,allowedEncounterIds:a}})})(a),"aria-pressed":s,className:"flex items-center gap-3 p-2 rounded-md text-left transition-colors "+(s?"bg-(--theme-primary-color,#bb86fc)/10 ring-1 ring-(--theme-primary-color,#bb86fc)/40":"hover:bg-gray-700/30"),children:[t.jsx("span",{className:"w-4 h-4 rounded border flex items-center justify-center "+(s?"bg-(--theme-primary-color,#bb86fc) border-(--theme-primary-color,#bb86fc)":"border-gray-600"),children:s&&t.jsx("span",{className:"text-white text-xs leading-none",children:"✓"})}),e.iconUrl||e.portraitUrl?t.jsx("img",{src:e.iconUrl||e.portraitUrl,alt:"",className:"w-10 h-10 rounded object-cover bg-gray-900",loading:"lazy",onError:e=>{e.currentTarget.style.display="none"}}):t.jsxs("div",{className:"w-10 h-10 rounded bg-gray-900 border border-gray-700/50 flex items-center justify-center text-[10px] text-gray-500",children:["#",a]}),t.jsx("span",{className:"flex-1 text-sm text-gray-200 truncate",children:e.name})]},a)}),!u&&0===d.length&&t.jsx("p",{className:"text-xs text-gray-500 px-2 py-3 text-center",children:"No bosses available for this raid."})]})]}),t.jsx("hr",{className:"border-gray-700/50"}),t.jsx(Xt,{label:"Selection Mode",children:t.jsxs("select",{value:c,onChange:e=>l({config:{...n,selectionMode:e.target.value}}),className:Kt,children:[t.jsx("option",{value:"single",children:"Single (pick one boss)"}),t.jsx("option",{value:"multi",children:"Multiple (pick several bosses)"})]})}),"multi"===c&&t.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[t.jsx(Xt,{label:"Min Selections",children:t.jsx("input",{type:"number",min:1,value:n.minSelections??1,onChange:e=>l({config:{...n,minSelections:Math.max(1,parseInt(e.target.value,10)||1)}}),className:Yt})}),t.jsx(Xt,{label:"Max Selections",helperText:"Leave blank for no cap",children:t.jsx("input",{type:"number",min:1,value:n.maxSelections??"",onChange:e=>l({config:{...n,maxSelections:e.target.value?Math.max(1,parseInt(e.target.value,10)):null}}),className:Yt})})]}),t.jsx("hr",{className:"border-gray-700/50"}),t.jsx(Qt,{label:"Capture Difficulty",checked:!!n.captureDifficulty,onChange:e=>l({config:{...n,captureDifficulty:e,difficulties:!e||n.difficulties&&0!==n.difficulties.length?n.difficulties:["normal","heroic","mythic"]}})}),n.captureDifficulty&&t.jsx(Jt,{label:"Allowed Difficulties",values:n.difficulties||[],options:Vt,onChange:e=>l({config:{...n,difficulties:e}})})]})}const aa=()=>{const{formTemplate:a,activeFieldId:l,activeSectionId:s,updateField:i,clearActiveField:n,updateFieldConditionalLogic:r,clearFieldConditionalLogic:o}=et(),[c,d]=e.useState(!1),[m,u]=e.useState(null),[p,x]=e.useState(""),[h,g]=e.useState(""),[f,b]=e.useState(!1),y=2===Number(a.templateData?.version)?a.templateData?.pages?.flatMap(e=>e.sections)||[]:a.templateData?.sections||[],j=y.find(e=>e.id===s),w=j?.fields.find(e=>e.id===l),N=y;if(!w)return t.jsx("div",{className:"p-4 text-center",children:t.jsx("p",{className:"text-gray-400",children:"No field selected"})});const C=e=>{i(s,l,e)},S=["select","radio","checkbox"].includes(w.type),D=v(w.type);return t.jsxs("div",{className:"flex flex-col h-full p-3",children:[t.jsxs("div",{className:"mb-3 flex justify-between items-center",children:[t.jsx("h3",{className:"text-base font-semibold text-gray-200",children:"Field Settings"}),t.jsx("button",{type:"button",onClick:n,className:"p-1.5 rounded hover:bg-gray-700/50 text-gray-400 hover:text-gray-200 transition-colors","aria-label":"Close",children:t.jsx(E,{className:"w-4 h-4"})})]}),t.jsx("hr",{className:"border-gray-700/50 mb-3"}),t.jsx("div",{className:"overflow-y-auto flex-1",children:t.jsxs("div",{className:"flex flex-col gap-5",children:[t.jsxs("div",{children:[t.jsx(ea,{children:"Basic Settings"}),t.jsxs("div",{className:"mt-2 flex flex-col gap-3",children:[t.jsx(Xt,{label:"Field Label",children:t.jsx("input",{type:"text",value:w.label||"",onChange:e=>C({label:e.target.value}),className:Yt})}),t.jsx(Qt,{label:"Hide Label",checked:!!w.hideLabel,onChange:()=>C({hideLabel:!w.hideLabel})}),t.jsx(Xt,{label:"Description",helperText:"Optional text shown below the field",children:t.jsx("textarea",{rows:2,value:w.description||"",onChange:e=>C({description:e.target.value}),className:Yt})}),w.description&&t.jsx(Qt,{label:"Hide Description",checked:!!w.hideDescription,onChange:()=>C({hideDescription:!w.hideDescription})}),!D&&t.jsxs(t.Fragment,{children:[t.jsx(Xt,{label:"Placeholder",helperText:"Example text shown before user input",children:t.jsx("input",{type:"text",value:w.placeholder||"",onChange:e=>C({placeholder:e.target.value}),className:Yt})}),t.jsx(Qt,{label:"Required Field",checked:!!w.required,onChange:e=>C({required:e})})]})]})]}),t.jsx("hr",{className:"border-gray-700/50"}),t.jsxs("div",{children:[t.jsx(ea,{children:"Field Options"}),t.jsxs("div",{className:"mt-2 flex flex-col gap-3",children:["text"===w.type&&t.jsxs(t.Fragment,{children:[t.jsx(Xt,{label:"Min Length",children:t.jsx("input",{type:"number",min:0,value:w.validation?.minLength||"",onChange:e=>{const t=e.target.value?Math.max(0,parseInt(e.target.value)):null,a=w.validation?.maxLength;null!==t&&null!=a&&t>a||C({validation:{...w.validation,minLength:t}})},className:Yt})}),t.jsx(Xt,{label:"Max Length",children:t.jsx("input",{type:"number",min:0,value:w.validation?.maxLength||"",onChange:e=>{const t=e.target.value?Math.max(0,parseInt(e.target.value)):null,a=w.validation?.minLength;null!==t&&null!=a&&t<a||C({validation:{...w.validation,maxLength:t}})},className:Yt})})]}),"number"===w.type&&t.jsxs(t.Fragment,{children:[t.jsx(Xt,{label:"Minimum Value",children:t.jsx("input",{type:"number",value:w.minValue||"",onChange:e=>{const t=e.target.value?parseFloat(e.target.value):null,a=w.maxValue;null!==t&&null!=a&&t>a||C({minValue:t})},className:Yt})}),t.jsx(Xt,{label:"Maximum Value",children:t.jsx("input",{type:"number",value:w.maxValue||"",onChange:e=>{const t=e.target.value?parseFloat(e.target.value):null,a=w.minValue;null!==t&&null!=a&&t<a||C({maxValue:t})},className:Yt})})]}),"rating"===w.type&&t.jsx(Xt,{label:"Max Rating",children:t.jsx("input",{type:"number",min:1,max:10,value:w.maxValue||5,onChange:e=>C({maxValue:parseInt(e.target.value)||5}),className:Yt})}),"scale"===w.type&&t.jsxs(t.Fragment,{children:[t.jsx(Xt,{label:"Min Value",children:t.jsx("input",{type:"number",value:w.minValue||1,onChange:e=>C({minValue:parseInt(e.target.value)||1}),className:Yt})}),t.jsx(Xt,{label:"Max Value",children:t.jsx("input",{type:"number",value:w.maxValue||10,onChange:e=>C({maxValue:parseInt(e.target.value)||10}),className:Yt})})]}),"file"===w.type&&t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"text-xs text-gray-400",children:"Configure file upload restrictions"}),t.jsx(Xt,{label:"Max File Size (MB)",helperText:"Maximum size per file (1-500 MB)",children:t.jsx("input",{type:"number",min:1,max:500,step:1,value:(w.maxFileSize||524288e3)/1048576,onChange:e=>C({maxFileSize:1024*(parseInt(e.target.value)||500)*1024}),className:Yt})}),t.jsx(Xt,{label:"Max Number of Files",helperText:"Maximum files that can be uploaded",children:t.jsx("input",{type:"number",min:1,max:10,step:1,value:w.maxFiles||1,onChange:e=>C({maxFiles:parseInt(e.target.value)||1}),className:Yt})}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-xs font-medium text-gray-400 mb-1",children:"Accepted File Types"}),t.jsx("div",{className:"flex flex-wrap gap-1.5 mb-2",children:[{key:"image/*",label:"Images",match:["image/*"]},{key:"application/pdf",label:"PDF",match:["application/pdf"]},{key:"doc",label:"Documents",match:["application/msword","application/vnd.openxmlformats-officedocument.wordprocessingml.document"]}].map(e=>{const a=w.acceptedFileTypes||[],l=e.match.every(e=>a.includes(e));return t.jsx(T,{variant:l?"primary":"outline",size:"sm",onClick:()=>
1{const t=new Set(a);l?e.match.forEach(e=>t.delete(e)):e.match.forEach(e=>t.add(e)),C({acceptedFileTypes:Array.from(t)})},children:e.label},e.key)})}),t.jsx(Xt,{label:"Custom MIME types (comma-separated)",helperText:"e.g., image/*, application/pdf, video/mp4",children:t.jsx("input",{type:"text",value:(w.acceptedFileTypes||["image/*"]).join(", "),onChange:e=>C({acceptedFileTypes:e.target.value.split(",").map(e=>e.trim()).filter(Boolean)}),className:Yt})})]})]}),("wow_character_battlenet"===w.type||"wow_character_linked"===w.type)&&t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"text-xs text-gray-400",children:"Configure character validation requirements"}),t.jsx(Qt,{label:"Must be guild member",checked:w.validation?.mustBeGuildMember||!1,onChange:e=>C({validation:{...w.validation,mustBeGuildMember:e}})}),t.jsx(Xt,{label:"Minimum Item Level",helperText:"Leave empty for no minimum",children:t.jsx("input",{type:"number",min:1,max:1e3,value:w.validation?.minItemLevel||"",onChange:e=>C({validation:{...w.validation,minItemLevel:e.target.value?parseInt(e.target.value):null}}),className:Yt})}),t.jsx(Xt,{label:"Maximum Item Level",helperText:"Leave empty for no maximum",children:t.jsx("input",{type:"number",min:1,max:1e3,value:w.validation?.maxItemLevel||"",onChange:e=>C({validation:{...w.validation,maxItemLevel:e.target.value?parseInt(e.target.value):null}}),className:Yt})}),t.jsx(Jt,{label:"Allowed Classes",values:w.validation?.allowedClasses||[],options:Gt,onChange:e=>C({validation:{...w.validation,allowedClasses:e}})}),t.jsx(Jt,{label:"Allowed Specializations",values:w.validation?.allowedSpecs||[],options:[{value:"Tank",label:"Tank Spec (any)"},{value:"Healer",label:"Healer Spec (any)"},{value:"DPS",label:"DPS Spec (any)"},{value:"Melee",label:"Melee DPS (any)"},{value:"Ranged",label:"Ranged DPS (any)"}],onChange:e=>C({validation:{...w.validation,allowedSpecs:e}})}),t.jsx(Jt,{label:"Allowed Roles",values:w.validation?.allowedRoles||[],options:[{value:"Tank",label:"Tank"},{value:"Healer",label:"Healer"},{value:"DPS",label:"DPS"}],onChange:e=>C({validation:{...w.validation,allowedRoles:e}})}),t.jsx(Xt,{label:"Minimum Mythic+ Score (Raider.io)",helperText:"Leave empty for no requirement",children:t.jsx("input",{type:"number",min:0,max:5e3,value:w.validation?.minMythicPlusScore||"",onChange:e=>C({validation:{...w.validation,minMythicPlusScore:e.target.value?parseInt(e.target.value):null}}),className:Yt})}),t.jsx(Xt,{label:"Minimum Raid Progress (e.g., '8/8 Mythic')",helperText:"Format: 'X/Y Difficulty' (e.g., '8/8 Mythic')",children:t.jsx("input",{type:"text",value:w.validation?.minRaidProgress||"",onChange:e=>C({validation:{...w.validation,minRaidProgress:e.target.value||null}}),className:Yt})})]}),"wow_raiderio_lookup"===w.type&&t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"text-xs text-gray-400",children:"Configure Raider.io validation requirements"}),t.jsx(Xt,{label:"Minimum Mythic+ Score",helperText:"Leave empty for no minimum",children:t.jsx("input",{type:"number",min:0,max:5e3,value:w.validation?.minMythicPlusScore||"",onChange:e=>C({validation:{...w.validation,minMythicPlusScore:e.target.value?parseInt(e.target.value):null}}),className:Yt})}),t.jsx(Xt,{label:"Minimum Dungeon Completions",helperText:"Total M+ runs completed this season",children:t.jsx("input",{type:"number",min:0,max:500,value:w.validation?.minDungeonCompletions||"",onChange:e=>C({validation:{...w.validation,minDungeonCompletions:e.target.value?parseInt(e.target.value):null}}),className:Yt})}),t.jsx(Jt,{label:"Required Dungeons",values:w.validation?.requiredDungeons||[],options:["Ara-Kara, City of Echoes","City of Threads","The Stonevault","The Dawnbreaker","Mists of Tirna Scithe","The Necrotic Wake","Siege of Boralus","Grim Batol"],onChange:e=>C({validation:{...w.validation,requiredDungeons:e}})}),t.jsx(Xt,{label:"Minimum Key Level",helperText:"Highest key level completed this season",children:t.jsx("input",{type:"number",min:0,max:50,value:w.validation?.minKeyLevel||"",onChange:e=>C({validation:{...w.validation,minKeyLevel:e.target.value?parseInt(e.target.value):null}}),className:Yt})})]}),["wow_item_lookup","wow_spell_lookup","wow_wcl_encounter"].includes(w.type)&&t.jsx("p",{className:"text-xs text-gray-400",children:"No additional validation options for this field type."}),"wow_boss_selection"===w.type&&t.jsx(ta,{field:w,onUpdate:C}
1),"wow_class_selection"===w.type&&t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"text-xs text-gray-400",children:"Configure class and spec selection"}),t.jsx(Xt,{label:"Display Style",children:t.jsxs("select",{value:w.config?.displayStyle||"dropdown",onChange:e=>C({config:{...w.config,displayStyle:e.target.value}}),className:Kt,children:[t.jsx("option",{value:"dropdown",children:"Dropdown"}),t.jsx("option",{value:"grid",children:"Icon Grid"}),t.jsx("option",{value:"cards",children:"Large Cards"})]})}),t.jsx(Qt,{label:"Require Specialization Selection",checked:!1!==w.config?.includeSpec,onChange:e=>C({config:{...w.config,includeSpec:e}})}),t.jsx(Jt,{label:"Allowed Classes (leave empty for all)",values:w.config?.allowedClasses||[],options:Gt,onChange:e=>C({config:{...w.config,allowedClasses:e}})}),t.jsx(Jt,{label:"Filter by Roles (optional)",values:w.config?.allowedRoles||[],options:[{value:"tank",label:"Tank"},{value:"healer",label:"Healer"},{value:"dps",label:"DPS"}],onChange:e=>C({config:{...w.config,allowedRoles:e}})}),t.jsx("hr",{className:"border-gray-700/50"}),t.jsx("p",{className:"text-xs font-semibold text-gray-300",children:"First-Come-First-Serve (FCFS) Settings"}),t.jsx(Qt,{label:"Enable FCFS Slot Limits",checked:w.config?.fcfsEnabled||!1,onChange:e=>C({config:{...w.config,fcfsEnabled:e}})}),w.config?.fcfsEnabled&&t.jsxs(t.Fragment,{children:[t.jsx(Xt,{label:"Full Slot Behavior",children:t.jsxs("select",{value:w.config?.fcfsBehavior||"hard_lock",onChange:e=>C({config:{...w.config,fcfsBehavior:e.target.value}}),className:Kt,children:[t.jsx("option",{value:"hard_lock",children:"Hard Lock (disable option)"}),t.jsx("option",{value:"waitlist",children:"Waitlist (allow with warning)"}),t.jsx("option",{value:"warning",children:"Warning Only"})]})}),t.jsx(Qt,{label:"Show Remaining Slots",checked:!1!==w.config?.showSlotCounts,onChange:e=>C({config:{...w.config,showSlotCounts:e}})}),t.jsx(Xt,{label:"Default Limit Per Class",helperText:"Leave empty for no default limit",children:t.jsx("input",{type:"number",min:1,max:100,value:w.config?.fcfsLimitPerClass||"",onChange:e=>C({config:{...w.config,fcfsLimitPerClass:e.target.value?parseInt(e.target.value):null}}),className:Yt})}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-xs font-medium text-gray-400 mb-1",children:"Custom Limits Per Class (overrides default)"}),t.jsx(T,{variant:"outline",size:"sm",onClick:()=>{const e=w.config?.fcfsLimits||{},t=w.config?.allowedClasses?.length>0?w.config.allowedClasses:Gt,a={};t.forEach(t=>{a[t]=e[t]||w.config?.fcfsLimitPerClass||2}),C({config:{...w.config,fcfsLimits:a}})},children:"Configure Per-Class Limits"}),w.config?.fcfsLimits&&Object.keys(w.config.fcfsLimits).length>0&&t.jsx("div",{className:"mt-2 flex flex-col gap-1.5",children:Object.entries(w.config.fcfsLimits).map(([e,a])=>t.jsxs("div",{className:"flex gap-2 items-center",children:[t.jsx("span",{className:"inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium border border-gray-600 text-gray-300 min-w-[120px] justify-center",children:e}),t.jsx("input",{type:"number",min:1,max:100,value:a,onChange:t=>C({config:{...w.config,fcfsLimits:{...w.config.fcfsLimits,[e]:Math.max(1,Math.min(999,parseInt(t.target.value)||1))}}}),className:`${Yt} w-20`}),t.jsx("button",{type:"button",onClick:()=>{const t={...w.config.fcfsLimits};delete t[e],C({config:{...w.config,fcfsLimits:t}})},className:"p-1.5 rounded text-red-400 hover:bg-red-900/20 transition-colors","aria-label":`Remove ${e} limit`,children:t.jsx(ee,{className:"w-4 h-4"})})]},e))})]})]}),t.jsx("hr",{className:"border-gray-700/50"}),t.jsx(la,{field:w,allSections:N,onUpdate:C,description:"Link to a character lookup field. The class will be auto-locked to the linked character."})]}),"wow_role_selection"===w.type&&t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"text-xs text-gray-400",children:"Configure role selection options"}),t.jsx(Xt,{label:"Selection Mode",children:t.jsxs("select",{value:w.config?.selectionMode||"single",onChange:e=>C({config:{...w.config,selectionMode:e.target.value}}),className:Kt,children:[t.jsx("option",{value:"single",children:"Single (pick one role)"}),t.jsx("option",{value:"multi",children:"Multiple (pick any number)"}),t.jsx("option",{value:"ranked",children:"Ranked Choice (order preferences)"})]})}),("multi"===w.config?.selectionMode||"ranked"===w.config?.selectionMode)&&t.jsx(Xt,{label:"Max Selections",helperText:"Maximum number of roles that can be selected",children:t.jsx("input",{type:"number",min:1,max:3,value:w.config?.maxSelections||3,onChange:e=>C({config:{...w.config,maxSelections:parseInt(e.target.value)||3}}),className:Yt})}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-xs font-medium text-gray-400 mb-1",children:"Available Roles"}),t.jsx(Zt,{value:w.config?.availableRoles||["tank","healer","dps"],options:[{value:"tank",label:"🛡️ Tank"},{value:"healer",label:"💚 Healer"},{value:"dps",label:"⚔️ DPS"}],onToggle:e=>{const t=w.config?.availableRoles||["tank","healer","dps"],a=t.includes(e)?t.filter(t=>t!==e):[...t,e];a.length>0&&C({config:{...w.config,availableRoles:a}})}})]}),t.jsx(Xt,{label:"Icon Style",children:t.jsxs("select",{value:w.config?.iconStyle||"default",onChange:e=>C({config:{...w.config,iconStyle:e.target.value}}),className:Kt,children:[t.jsx("option",{value:"default",children:"Default (WoW Icons)"}),t.jsx("option",{value:"custom",children:"Custom Images"})]})}),"custom"===w.config?.iconStyle&&t.jsxs("div",{children:[t.jsx("label",{className:"block text-xs font-medium text-gray-400 mb-1",children:"Custom Icon URLs (Image URLs)"}),t.jsx("div",{className:"flex flex-col gap-1.5",children:(w.config?.availableRoles||["tank","healer","dps"]).map(e=>t.jsx(Xt,{label:`${{tank:"Tank",healer:"Healer",dps:"DPS"}[e]} Icon URL`,children:t.jsx("input",{type:"text",value:w.config?.customIcons?.[e]||"",onChange:t=>C({config:{...w.config,customIcons:{...w.config?.customIcons,[e]:t.target.value}}}),placeholder:`https://example.com/${e}-icon.png`,className:Yt})},e))})]}),t.jsx("hr",{className:"border-gray-700/50"}),t.jsx(la,{field:w,allSections:N,onUpdate:C,description:"Link to a character lookup field. Available roles will be filtered to roles the linked character's class can fulfill."})]}),"wow_flex_selection"===w.type&&t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"text-xs text-gray-400",children:"Configure flex spec/alt selection options"}),t.jsx(Xt,{label:"Max Flex Options",helperText:"How many flex specs the applicant may declare (1–5)",children:t.jsx("input",{type:"number",min:1,max:5,value:w.config?.maxFlexOptions??2,onCh
1ange:e=>C({config:{...w.config,maxFlexOptions:Math.min(5,Math.max(1,parseInt(e.target.value)||1))}}),className:Yt})}),t.jsx(Qt,{label:"Require Character Proof",checked:w.config?.requireCharacter||!1,onChange:e=>C({config:{...w.config,requireCharacter:e}})}),t.jsx(Qt,{label:"Spec agnostic role flex",checked:w.config?.specAgnosticFlex||!1,onChange:e=>C({config:{...w.config,specAgnosticFlex:e}})}),t.jsx("p",{className:"text-xs text-gray-500",children:"Applicants declare a class + role only, not a specific spec."}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-xs font-medium text-gray-400 mb-1",children:"Allowed Roles (empty = all roles)"}),t.jsx(Zt,{value:w.config?.allowedRoles||[],options:[{value:"tank",label:"🛡️ Tank"},{value:"healer",label:"💚 Healer"},{value:"dps",label:"⚔️ DPS"}],onToggle:e=>{const t=w.config?.allowedRoles||[],a=t.includes(e)?t.filter(t=>t!==e):[...t,e];C({config:{...w.config,allowedRoles:a}})}})]}),t.jsx(Jt,{label:"Allowed Classes (leave empty for all)",values:w.config?.allowedClasses||[],options:Gt,onChange:e=>C({config:{...w.config,allowedClasses:e}})}),t.jsx(Xt,{label:"Min Item Level (optional)",helperText:"Minimum ilvl for attached characters. Leave blank for no minimum.",children:t.jsx("input",{type:"number",min:1,value:w.config?.minItemLevel??"",onChange:e=>C({config:{...w.config,minItemLevel:e.target.value?parseInt(e.target.value):null}}),className:Yt})}),t.jsx("hr",{className:"border-gray-700/50"}),t.jsx(la,{field:w,allSections:N,onUpdate:C,description:"Link to a character lookup field on this form. The flex picker will exclude that character's main spec and can optionally restrict to same-class specs only."}),w.config?.characterSourceFieldId&&t.jsxs("div",{className:"flex flex-col gap-2",children:[t.jsx(Qt,{label:"Exclude linked character's main spec",checked:!1!==w.config?.excludeLinkedSpec,onChange:e=>C({config:{...w.config,excludeLinkedSpec:e}})}),t.jsx(Qt,{label:"Allow flex to same role",checked:!1!==w.config?.allowFlexSameRole,onChange:e=>C({config:{...w.config,allowFlexSameRole:e}})}),t.jsx(Qt,{label:"Allow flex to different role",checked:!1!==w.config?.allowFlexDifferentRole,onChange:e=>C({config:{...w.config,allowFlexDifferentRole:e}})}),t.jsx(Qt,{label:"Allow flex to other classes",checked:w.config?.allowOutsideClassScope||!1,onChange:e=>C({config:{...w.config,allowOutsideClassScope:e}})}),t.jsx("p",{className:"text-xs text-gray-500",children:"If off, applicants can only flex within the linked character's class."}),w.config?.allowOutsideClassScope&&t.jsx(Qt,{label:"Require character proof for out-of-class flex picks",checked:w.config?.forceProofOutsideClassScope||!1,onChange:e=>C({config:{...w.config,forceProofOutsideClassScope:e}})})]})]}),"availability"===w.type&&t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"text-xs text-gray-400",children:"Configure availability selection options"}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-xs font-medium text-gray-400 mb-1",children:"Available Days"}),t.jsx(Zt,{value:w.config?.availableDays||[0,1,2,3,4,5,6],options:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"].map((e,t)=>({value:t,label:e})),onToggle:e=>{const t=w.config?.availableDays||[0,1,2,3,4,5,6],a=t.includes(e)?t.filter(t=>t!==e):[...t,e].sort((e,t)=>e-t);C({config:{...w.config,availableDays:a}})}})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-xs font-medium text-gray-400 mb-1",children:"Timeslot Options"}),t.jsxs("div",{className:"flex flex-col gap-2",children:[(w.config?.timeslotOptions||[]).map((e,a)=>{const l=e.startTime&&e.endTime?(()=>{const t=e=>{if(!e)return"";const[t,a]=e.split(":").map(Number);return isNaN(t)||isNaN(a)?"":`${t%12||12}:${a.toString().padStart(2,"0")} ${t<12?"AM":"PM"}`};return`${t(e.startTime)} - ${t(e.endTime)}`})():"";return t.jsxs("div",{className:"rounded-lg bg-gray-800/40 border border-gray-700/40 p-2 flex flex-col gap-2",children:[t.jsxs("div",{className:"flex gap-2 items-center",children:[t.jsx(Xt,{label:"Start Time",className:"flex-1",children:t.jsx("input",{type:"time",value:e.startTime||"",onChange:e=>{const t=w.config.timeslotOptions.map((t,l)=>l===a?{...t,startTime:e.target.value}:t);C({config:{...w.config,timeslotOptions:t}})},className:Yt})}),t.jsx(Xt,{label:"End Time",className:"flex-1",children:t.jsx("input",{type:"time",value:e.endTime||"",onChange:e=>{const t=w.config.timeslotOptions.map((t,l)=>l===a?{...t,endTime:e.target.value}:t);C({config:{...w.config,timeslotOptions:t}})},className:Yt})}),t.jsx("button",{type:"button",onClick:()=>{const e=w.config.timeslotOptions.filter((e,t)=>
1t!==a);C({config:{...w.config,timeslotOptions:e}})},className:"p-2 rounded text-red-400 hover:bg-red-900/20 transition-colors mt-5","aria-label":"Remove timeslot",children:t.jsx(ee,{className:"w-4 h-4"})})]}),t.jsx(Xt,{label:"Label (optional)",children:t.jsx("input",{type:"text",value:e.label||"",placeholder:l||"e.g. Evening Raid",onChange:e=>{const t=w.config.timeslotOptions.map((t,l)=>l===a?{...t,label:e.target.value}:t);C({config:{...w.config,timeslotOptions:t}})},className:Yt})})]},a)}),t.jsx(T,{variant:"outline",size:"sm",leftIcon:t.jsx(X,{className:"w-3.5 h-3.5"}),onClick:()=>{const e=w.config?.timeslotOptions||[];C({config:{...w.config,timeslotOptions:[...e,{startTime:"20:00",endTime:"22:00",label:""}]}})},children:"Add Timeslot"})]})]}),t.jsx(Qt,{label:"Include 'All Day' option",checked:!!w.config?.includeAllDay,onChange:e=>C({config:{...w.config,includeAllDay:e}})}),t.jsxs("div",{className:"flex gap-2",children:[t.jsx(Xt,{label:"Min Selections",helperText:"Minimum time slots required",className:"flex-1",children:t.jsx("input",{type:"number",min:0,max:50,value:w.config?.minSlots||"",onChange:e=>C({config:{...w.config,minSlots:e.target.value?parseInt(e.target.value):null}}),className:Yt})}),t.jsx(Xt,{label:"Max Selections",helperText:"Leave empty for unlimited",className:"flex-1",children:t.jsx("input",{type:"number",min:1,max:100,value:w.config?.maxSlots||"",onChange:e=>C({config:{...w.config,maxSlots:e.target.value?parseInt(e.target.value):null}}),className:Yt})})]}),t.jsx(Qt,{label:"Show creator timezone conversion",checked:!1!==w.config?.showCreatorTimezonePreview,onChange:e=>C({config:{...w.config,showCreatorTimezonePreview:e}})}),t.jsx("p",{className:"text-xs text-gray-500",children:"Only applies when form-level creator timezone mode is enabled."})]}),["date","time","datetime"].includes(w.type)&&t.jsxs(t.Fragment,{children:[t.jsx("p",{className:"text-xs text-gray-400",children:"Timezone display options"}),t.jsx(Qt,{label:"Show creator timezone conversion",checked:!1!==w.config?.showCreatorTimezonePreview,onChange:e=>C({config:{...w.config,showCreatorTimezonePreview:e}})}),t.jsx("p",{className:"text-xs text-gray-500",children:"Only applies when form-level creator timezone mode is enabled."})]}),"display_text"===w.type&&t.jsx(Xt,{label:"Markdown Content",helperText:"Headings (##), lists, links, **bold**, *italic*, tables, code blocks. Raw HTML is ignored.",children:t.jsx("textarea",{rows:10,value:w.content||"",onChange:e=>C({content:e.target.value}),className:Yt,placeholder:"## Heading\n\nWrite your content here."})}),"display_image"===w.type&&t.jsxs(t.Fragment,{children:[t.jsx(Xt,{label:"Image URL",helperText:"Direct link to an image or GIF (https://...)",children:t.jsx("input",{type:"url",value:w.imageUrl||"",onChange:e=>C({imageUrl:e.target.value}),className:Yt,placeholder:"https://example.com/image.png"})}),t.jsx(Xt,{label:"Alt Text",helperText:"Describes the image for screen readers",children:t.jsx("input",{type:"text",value:w.alt||"",onChange:e=>C({alt:e.target.value}),className:Yt})}),t.jsx(Xt,{label:"Caption",helperText:"Optional text shown below the image",children:t.jsx("input",{type:"text",value:w.caption||"",onChange:e=>C({caption:e.target.value}),className:Yt})}),t.jsx(Xt,{label:"Alignment",children:t.jsxs("select",{value:w.align||"center",onChange:e=>C({align:e.target.value}),className:Kt,children:[t.jsx("option",{value:"left",children:"Left"}),t.jsx("option",{value:"center",children:"Center"}),t.jsx("option",{value:"right",children:"Right"})]})}),t.jsx(Xt,{label:"Max Width (%)",helperText:"Constrain image width relative to the form",children:t.jsx("input",{type:"number",min:20,max:100,step:5,value:w.maxWidthPercent??100,onChange:e=>C({maxWidthPercent:Math.max(20,Math.min(100,parseInt(e.target.value)||100))}),className:Yt})})]}),"display_video"===w.type&&t.jsxs(t.Fragment,{children:[t.jsx(Xt,{label:"Video URL",helperText:"YouTube, Vimeo, or Twitch link. Other providers are not embedded.",children:t.jsx("input",{type:"url",value:w.videoUrl||"",onChange:e=>C({videoUrl:e.target.value}),className:Yt,placeholder:"https://www.youtube.com/watch?v=..."})}),t.jsx(Xt,{label:"Caption",helperText:"Optional text shown below the video",children:t.jsx("input",{type:"text",value:w.caption||"",onChange:e=>C({caption:e.target.value}),className:Yt})})]}),"display_divider"===w.type&&t.jsxs(t.Fragment,{children:[t.jsx(Xt,{label:"Style",children:t.jsxs("select",{value:w.dividerStyle||"solid",onChange:e=>C({dividerStyle:e.target.value}),className:Kt,children:[t.jsx("option",{value:"solid",children:"Solid line"}),t.jsx("option",{value:"dashed",children:"Dashed line"}),t.jsx("option",{value:"dotted",children:"Dotted line"}),t.jsx("option",{value:"thick",children:"Thick line"})]})}),t.jsx(Xt,{label:"Center Label",helperText:"Optional label shown in the middle of the line",children:t.jsx("input",{type:"text",value:w.dividerLabel||"",onChange:e=>C({dividerLabel:e.target.value}),className:Yt,placeholder:"e.g., Section break"})})]})]})]}),t.jsx("hr",{className:"border-gray-700/50"}),S&&t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-center justify-between mb-2",children:[t.jsx(ea,{children:"Options"}),t.jsx(T,{variant:"ghost",size:"sm",leftIcon:t.jsx(X,{className:"w-3.5 h-3.5"}),onClick:()=>{u(null),x(""),g(""),d(!0)},children:"Add"})]}),w.options&&w.options.length>0?t.jsx("div",{className:"flex flex-col gap-1.5",children:w.options.map((e,a)=>t.jsxs("div",{className:"p-2 rounded-lg bg-gray-800/40 border border-gray-700/40 flex justify-between items-center",children:[t.jsxs("div",{className:"min-w-0",children:[t.jsx("p",{className:"text-sm font-medium text-gray-200 truncate",children:e.label}),e.value!==e.label&&t.jsx("p",{className:"text-xs text-gray-400 truncate",children:e.value})]}),t.jsxs("div",{className:"flex gap-1 shrink-0",children:[t.jsx("button",{type:"button",onClick:()=>(e=>{u(e),x(w.options[e].label),g(w.options[e].value),d(!0)})(a),className:"p-1.5 rounded hover:bg-gray-700/50 text-gray-400 hover:text-gray-200 transition-colors","aria-label":"Edit option",children:t.jsx(se,{className:"w-4 h-4"})}),t.jsx("button",{type:"button",onClick:()=>(e=>{C({options:w.options.filter((t,a)=>a!==e)})})(a),className:"p-1.5 rounded text-red-400 hover:bg-red-900/20 transition-colors","aria-label":"Delete option",children:t.jsx(ee,{className:"w-4 h-4"})})]})]},a))}):t.jsx("p",{className:"text-xs text-gray-400",children:'No options yet. Click "Add" to create some.'})]}),t.jsx("hr",{className:"border-gray-700/50"}),t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[w.showIf?t.jsx(Ae,{className:"w-4 h-4 text-(--theme-primary-color,#bb86fc)"}):t.jsx(Le,{className:"w-4 h-4 text-gray-500"}),t.jsx(ea,{children:"Conditional Visibility"})]}),w.showIf?t.jsxs("div",{children:[t.jsx(Pt,{condition:w.showIf,fields:N.flatMap(e=>(e.fields?.filter(e=>e.id&&!e.deleted)||[]).map(t=>({...t,sectionLabel:e.title}))),compact:!0,expandable:!0}),t.jsxs("div",{className:"flex gap-2 mt-2",children:[t.jsx(T,{variant:"outline",size:"sm",leftIcon:t.jsx(se,{className:"w-3.5 h-3.5"}),onClick:()=>b(!0),className:"flex-1",children:"Edit Conditions"}),t.jsx(T,{variant:"error",size:"sm",leftIcon:t.jsx(ee,{className:"w-3.5 h-3.5"}),onClick:()=>o(s,l),children:"Clear"})]})]}):t.jsx(T,{variant:"outline",leftIcon:t.jsx(Le,{className:"w-4 h-4"}),onClick:()=>b(!0),className:"w-full",children:"Set Visibility Conditions"})]}),!D&&t.jsxs(t.Fragment,{children:[t.jsx("hr",{className:"border-gray-700/50"}),t.jsxs("div",{children:[t.jsx(ea,{children:"Validation"}),t.jsx("div",{className:"mt-2",children:t.jsx(Xt,{label:"Error Message",helperText:"Custom message shown when validation fails",children:t.jsx("textarea",{rows:2,value:w.validation?.errorMessage||"",onChange:e=>C({validation:{...w.validation,errorMessage:e.target.value}}),className:Yt})})})]})]})]})}),t.jsx(K,{isOpen:c,onClose:()=>{d(!1),u(null),x(""),g("")},title:null!==m?"Edit Option":"Add Option",size:"default",footer:t.jsxs(t.Fragment,{children:[t.jsx(T,{variant:"ghost",onClick:()=>{d(!1),u(null),x(""),g("")},children:"Cancel"}),t.jsx(T,{variant:"primary",onClick:()=>
1{if(p.trim()){if(null!==m){const e=[...w.options||[]];e[m]={label:p,value:h||p},C({options:e})}else C({options:[...w.options||[],{label:p,value:h||p}]});d(!1),x(""),g(""),u(null)}},disabled:!p.trim(),children:null!==m?"Update":"Add"})]}),children:t.jsxs("div",{className:"flex flex-col gap-3",children:[t.jsx(Xt,{label:"Option Label",children:t.jsx("input",{type:"text",autoFocus:!0,value:p,onChange:e=>x(e.target.value),placeholder:"What users see",className:Yt})}),t.jsx(Xt,{label:"Option Value (optional)",children:t.jsx("input",{type:"text",value:h,onChange:e=>g(e.target.value),placeholder:"Internal value (defaults to label)",className:Yt})})]})}),f&&w&&j&&t.jsx(Ot,{open:!0,onClose:()=>b(!1),currentCondition:w.showIf||null,sections:N||[],currentFieldId:w.id,currentSectionId:j.id,title:"Field Visibility Conditions",description:`Configure when "${w.label}" field should be shown`,allowCrossSectionReferences:!0,onSave:e=>{r(s,l,e)}})]})};function la({field:e,allSections:a,onUpdate:l,description:s}){return t.jsxs("div",{children:[t.jsx("label",{className:"block text-xs font-medium text-gray-400 mb-1",children:"Linked Character Field (optional)"}),t.jsx("p",{className:"text-xs text-gray-500 italic mb-2",children:s}),t.jsxs("select",{value:e.config?.characterSourceFieldId||"",onChange:t=>l({config:{...e.config,characterSourceFieldId:t.target.value||null}}),className:Kt,children:[t.jsx("option",{value:"",children:"None"}),a.flatMap(e=>e.fields||[]).filter(t=>t.id!==e.id&&!t.deleted&&["wow_character_battlenet","wow_character_linked","wow_raiderio_lookup"].includes(t.type)).map(e=>t.jsxs("option",{value:e.id,children:[e.label||e.type," (",e.type,")"]},e.id))]})]})}const sa=({value:a="",onChange:l,label:s="Discord Channel",helperText:i="",disabled:n=!1,required:r=!1,size:o="small",fullWidth:c=!0,error:d=null})=>{const{selectedGuild:m}=U(),u=m?.id,[p,x]=e.useState([]),[h,g]=e.useState(!1),[f,b]=e.useState(null);e.useEffect(()=>{u&&y()},[u]);const y=async()=>{if(g(!0),b(null),!u)return b("No guild selected"),void g(!1);try{const e=await fetch(`/api/discord/channels/${u}`,{credentials:"include"});if(!e.ok){const t=await e.json().catch(()=>({}));throw new Error(t.error||"Failed to load Discord channels")}const t=await e.json(),a=t.success?t.channels:t;if(!Array.isArray(a))throw new Error("Invalid response format from server");const l=a.filter(e=>0===e.type||"GUILD_TEXT"===e.type);x(l)}catch(e){console.error("Error loading Discord channels:",e),b(e.message||"Failed to load Discord channels")}finally{g(!1)}},v=d||f||i,j=Boolean(d||f),w=p.map(e=>({value:e.id,label:`# ${e.name}`})),N=h?"Loading channels...":f?"Failed to load channels":"No channels available",C=h?"Loading channels...":0===p.length?N:s||"Select channel...",S="medium"===o?"default":"sm";return t.jsxs("div",{className:c?"w-full":"inline-block",children:[s&&t.jsxs("label",{className:"mb-1 block text-sm font-medium text-gray-300",children:[s,r&&t.jsx("span",{className:"ml-0.5 text-red-400",children:"*"})]}),t.jsxs("div",{className:"relative",children:[t.jsx(Pe,{options:w,value:a,onChange:e=>{l&&l(e)},placeholder:C,disabled:n||h||0===p.length,loading:h,size:S,error:j,emptyMessage:N}),h&&t.jsx("div",{className:"pointer-events-none absolute inset-y-0 right-9 flex items-center",children:t.jsx(Re,{className:"h-4 w-4 animate-spin text-gray-400"})})]}),v&&t.jsx("p",{className:"mt-1 text-xs "+(j?"text-red-400":"text-gray-500"),children:v})]})},ia=/^[a-z0-9]+(-[a-z0-9]+)*$/,na=({formId:a,guildSlug:l})=>{const[n,r]=e.useState([]),[o,c]=e.useState(!0),[d,m]=e.useState(null),[u,p]=e.useState(!1),[x,h]=e.useState(""),[g,f]=e.useState(""),[b,y]=e.useState(!1),[v,j]=e.useState(null),[w,N]=e.useState(null),[C,S]=e.useState(""),[D,k]=e.useState(""),[I,A]=e.useState(!1),[L,P]=e.useState(null),_=e.useCallback(async()=>{try{c(!0);const e=await s.get(`/api/forms/${a}/slugs`);r(e.data.slugs||[]),m(null)}catch(e){console.error("Error loading form slugs:",e),m("Failed to load form slugs")}finally{c(!1)}},[a]);e.useEffect(()=>{_()},[_]);const M=e.useCallback(async(e,t=null)=>{if(e&&ia.test(e)){A(!0);try{if(n.some(a=>a.slug===e&&a.id!==t))return void P(!1);P(!0)}catch(a){console.error("Error checking slug availability:",a),P(null)}finally{A(!1)}}else P(null)},[n]);e.useEffect(()=>{const e=setTimeout(()=>{x?M(x):P(null)},500);return()=>clearTimeout(e)},[x,M]),e.useEffect(()=>{const e=setTimeout(()=>{C&&v&&M(C,v)},500);return()=>clearTimeout(e)},[C,v,M]);const O=(e,t)=>{j(e),S(t)},$=()=>{j(null),S(""),P(null)},z=()=>{N(null),k("")},U=e=>{const t=`${window.location.origin}/forms/${l}/${e}`;navigator.clipboard.writeText(t),i.success("URL copied to clipboard")},H=e=>`${window.location.origin}/forms/${l}/${e}`,q=n.find(e=>e.isPrimary);return o?t.jsx("div",{className:"flex items-center justify-center p-6",children:t.jsx(Re,{className:"h-5 w-5 animate-spin text-gray-400"})}):d?t.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-red-700/50 bg-red-900/30 px-3 py-2 text-sm text-red-100",children:[t.jsx(F,{className:"h-4 w-4 shrink-0 mt-0.5","aria-hidden":"true"}),t.jsx("span",{className:"flex-1",children:d})]}):t.jsxs("div",{className:"flex flex-col gap-4",children:[q&&t.jsxs("div",{className:"flex items-start gap-3 rounded-lg border border-cyan-700/40 bg-cyan-900/20 p-3 text-sm text-cyan-100",children:[t.jsx(ge,{className:"h-4 w-4 shrink-0 mt-0.5","aria-hidden":"true"}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("p",{className:"font-semibold",children:"Primary Public URL"}),t.jsx("a",{href:H(q.slug),target:"_blank",rel:"noopener noreferrer",className:"font-mono text-xs text-cyan-200 hover:underline break-all",children:H(q.slug)}),t.jsxs("div",{className:"flex gap-2 mt-2",children:[t.jsx(T,{size:"sm",variant:"ghost",leftIcon:t.jsx(Q,{className:"h-3.5 w-3.5"}),onClick:()=>U(q.slug),children:"Copy URL"}),t.jsx(T,{size:"sm",variant:"ghost",leftIcon:t.jsx(se,{className:"h-3.5 w-3.5"}),onClick:()=>O(q.id,q.slug),children:"Edit Slug"})]})]})]}),t.jsxs("div",{className:"flex items-center justify-between gap-3",children:[t.jsx("p",{className:"text-sm text-gray-400",children:"Manage multiple slugs to track different distribution channels"}),t.jsx(T,{size:"sm",variant:"primary",leftIcon:t.jsx(X,{className:"h-4 w-4"}),onClick:()=>p(!0),children:"Add Slug"})]}),0===n.length?t.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-cyan-700/40 bg-cyan-900/20 px-3 py-2 text-sm text-cyan-100",children:[t.jsx(F,{className:"h-4 w-4 shrink-0 mt-0.5","aria-hidden":"true"}),t.jsx("span",{children:'No slugs found. Click "Add Slug" to create one.'})]}):t.jsx("div",{className:"rounded-lg border border-gray-700/50 bg-gray-800/40 overflow-hidden",children:t.jsx("div",{className:"overflow-x-auto",children:t.jsxs("table",{className:"w-full text-sm",children:[t.jsx("thead",{className:"bg-gray-900/40",children:t.jsxs("tr",{children:[t.jsx("th",{className:"px-3 py-2 text-left font-semibold text-gray-300 w-10"}),t.jsx("th",{className:"px-3 py-2 text-left font-semibold text-gray-300",children:"Slug"}),t.jsx("th",{className:"px-3 py-2 text-left font-semibold text-gray-300",children:"Label"}),t.jsx("th",{className:"px-3 py-2 text-left font-semibold text-gray-300",children:"Public URL"}),t.jsx("th",{className:"px-3 py-2 text-center font-semibold text-gray-300",children:"Views"}),t.jsx("th",{className:"px-3 py-2 text-center font-semibold text-gray-300",children:"Submissions"}),t.jsx("th",{className:"px-3 py-2 text-right font-semibold text-gray-300",children:"Actions"})]})}),t.jsx("tbody",{children:n.map(e=>t.jsxs("tr",{className:"border-t border-gray-700/30 hover:bg-gray-700/20",children:[t.jsx("td",{className:"px-3 py-2",children:t.jsx("button",{type:"button",onClick:()=>!e.isPrimary&&(async e=>{try{await s.patch(`/api/forms/${a}/slugs/${e}`,{isPrimary:!0}),r(n.map(t=>({...t,isPrimary:t.id===e}))),i.success("Primary slug updated")}catch(t){console.error("Error setting primary slug:",t),i.error(t.response?.data?.error||"Failed to set primary slug")}})(e.id),className:"p-1 rounded transition-colors "+(e.isPrimary?"text-yellow-400 cursor-default":"text-gray-500 hover:text-yellow-400 hover:bg-gray-700/50"),title:e.isPrimary?"Primary slug":"Set as primary","aria-label":e.isPrimary?"Primary slug":"Set as primary",children:t.jsx(R,{className:"h-4 w-4 "+(e.isPrimary?"fill-current":"")})})}),t.jsx("td",{className:"px-3 py-2",children:v===e.id?t.jsxs("div",{className:"flex items-center gap-1",children:[t.jsxs("div",{className:"relative min-w-[12rem]",children:[t.jsx("input",{type:"text",value:C,onChange:e=>S(e.target.value.toLowerCase()),placeholder:"my-custom-slug",className:"\n                                w-full rounded-md border border-gray-700 bg-gray-900/50\n                                px-2.5 py-1.5 pr-8 text-sm text-gray-200\n                                focus:outline-hidden focu
1s:ring-2 focus:ring-(--theme-primary-color,#bb86fc)\n                              "}),t.jsx("div",{className:"absolute right-2 top-1/2 -translate-y-1/2 pointer-events-none",children:I?t.jsx(Re,{className:"h-4 w-4 animate-spin text-gray-400"}):!0===L?t.jsx(_e,{className:"h-4 w-4 text-green-400"}):!1===L?t.jsx(F,{className:"h-4 w-4 text-red-400"}):null})]}),t.jsx("button",{type:"button",onClick:()=>(async e=>{if(C.trim())if(ia.test(C))if(!1!==L)try{await s.patch(`/api/forms/${a}/slugs/${e}`,{slug:C.trim().toLowerCase()}),r(n.map(t=>t.id===e?{...t,slug:C.trim().toLowerCase()}:t)),j(null),S(""),P(null),i.success("Slug updated successfully")}catch(t){console.error("Error updating slug:",t),i.error(t.response?.data?.error||"Failed to update slug")}else i.error("This slug is already in use");else i.error("Slug must be lowercase alphanumeric with hyphens only");else i.error("Slug cannot be empty")})(e.id),disabled:!L,className:"p-1 rounded text-(--theme-primary-color,#bb86fc) hover:bg-gray-700/50 disabled:opacity-30 disabled:cursor-not-allowed","aria-label":"Save slug",children:t.jsx(B,{className:"h-4 w-4"})}),t.jsx("button",{type:"button",onClick:$,className:"p-1 rounded text-gray-400 hover:text-gray-200 hover:bg-gray-700/50","aria-label":"Cancel",children:t.jsx(E,{className:"h-4 w-4"})})]}):t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"font-mono text-gray-200",children:e.slug}),e.isPrimary&&t.jsx("span",{className:"inline-flex items-center rounded-full bg-(--theme-primary-color,#bb86fc)/20 text-(--theme-primary-color,#bb86fc) px-2 py-0.5 text-xs font-medium",children:"Primary"}),t.jsx("button",{type:"button",onClick:()=>O(e.id,e.slug),className:"p-1 rounded text-gray-400 hover:text-gray-200 hover:bg-gray-700/50","aria-label":"Edit slug",children:t.jsx(se,{className:"h-3.5 w-3.5"})})]})}),t.jsx("td",{className:"px-3 py-2",children:w===e.id?t.jsxs("div",{className:"flex items-center gap-1",children:[t.jsx("input",{type:"text",value:D,onChange:e=>k(e.target.value),placeholder:"Label (e.g., Discord)",className:"\n                              min-w-[9rem] rounded-md border border-gray-700 bg-gray-900/50\n                              px-2.5 py-1.5 text-sm text-gray-200\n                              focus:outline-hidden focus:ring-2 focus:ring-(--theme-primary-color,#bb86fc)\n                            "}),t.jsx("button",{type:"button",onClick:()=>(async e=>{try{await s.patch(`/api/forms/${a}/slugs/${e}`,{label:D.trim()||null}),r(n.map(t=>t.id===e?{...t,label:D.trim()||null}:t)),N(null),k(""),i.success("Label updated")}catch(t){console.error("Error updating label:",t),i.error(t.response?.data?.error||"Failed to update label")}})(e.id),className:"p-1 rounded text-(--theme-primary-color,#bb86fc) hover:bg-gray-700/50","aria-label":"Save label",children:t.jsx(B,{className:"h-4 w-4"})}),t.jsx("button",{type:"button",onClick:z,className:"p-1 rounded text-gray-400 hover:text-gray-200 hover:bg-gray-700/50","aria-label":"Cancel",children:t.jsx(E,{className:"h-4 w-4"})})]}):t.jsxs("div",{className:"flex items-center gap-2",children:[e.label?t.jsx("span",{className:"text-gray-200",children:e.label}):t.jsx("span",{className:"italic text-gray-500",children:"No label"}),t.jsx("button",{type:"button",onClick:()=>{return t=e.id,a=e.label,N(t),void k(a||"");var t,a},className:"p-1 rounded text-gray-400 hover:text-gray-200 hover:bg-gray-700/50","aria-label":"Edit label",children:t.jsx(se,{className:"h-3.5 w-3.5"})})]})}),t.jsx("td",{className:"px-3 py-2",children:t.jsxs("a",{href:H(e.slug),target:"_blank",rel:"noopener noreferrer",className:"font-mono text-xs text-gray-400 hover:text-gray-200 hover:underline",children:["/forms/",l,"/",e.slug]})}),t.jsx("td",{className:"px-3 py-2 text-center",children:t.jsx("span",{className:"inline-flex items-center rounded-full border border-gray-600 px-2 py-0.5 text-xs text-gray-300",children:e.viewCount})}),t.jsx("td",{className:"px-3 py-2 text-center",children:t.jsx("span",{className:"inline-flex items-center rounded-full border border-(--theme-primary-color,#bb86fc)/40 text-(--theme-primary-color,#bb86fc) px-2 py-0.5 text-xs font-medium",children:e.submissionCount})}),t.jsx("td",{className:"px-3 py-2",children:t.jsxs("div",{className:"flex items-center justify-end gap-1",children:[t.jsx("button",{type:"button",onClick:()=>U(e.slug),className:"p-1 rounded text-gray-400 hover:text-gray-200 hover:bg-gray-700/50",title:"Copy full URL","aria-label":"Copy full URL",children:t.jsx(Q,{className:"h-3.5 w-3.5"})}),t.jsx("button",{type:"button",onClick:()=>(async e=>{if(window.confirm("Are you sure you want to delete this slug? This cannot be undone."))try{await s.delete(`/api/forms/${a}/slugs/${e}`),r(n.filter(t=>t.id!==e)),i.success("Slug deleted successfully")}catch(t){console.error("Error deleting slug:",t),i.error(t.response?.data?.error||"Failed to delete slug")}})(e.id),disabled:1===n.length,className:"p-1 rounded text-gray-400 hover:text-red-300 hover:bg-red-900/20 disabled:opacity-30 disabled:cursor-not-allowed",title:1===n.length?"Cannot delete last slug":"Delete slug","aria-label":"Delete slug",children:t.jsx(ee,{className:"h-3.5 w-3.5"})})]})})]},e.id))})]})})}),t.jsx(K,{isOpen:u,onClose:()=>{p(!1),h(""),f(""),P(null)},title:"Create New Slug",size:"default",footer:t.jsxs(t.Fragment,{children:[t.jsx(T,{variant:"ghost",onClick:()=>{p(!1),h(""),f(""),P(null)},disabled:b,children:"Cancel"}),t.jsx(T,{variant:"primary",onClick:async()=>
1{if(x.trim())if(ia.test(x))if(!1!==L)try{y(!0);const e=await s.post(`/api/forms/${a}/slugs`,{slug:x.trim().toLowerCase(),label:g.trim()||null});r([...n,e.data.slug]),p(!1),h(""),f(""),P(null),i.success("Slug created successfully")}catch(e){console.error("Error creating slug:",e),i.error(e.response?.data?.error||"Failed to create slug")}finally{y(!1)}else i.error("This slug is already in use");else i.error("Slug must be lowercase alphanumeric with hyphens only");else i.error("Slug cannot be empty")},disabled:b||!x.trim()||!1===L,loading:b,children:"Create"})]}),children:t.jsxs("div",{className:"flex flex-col gap-4",children:[t.jsx("div",{children:t.jsx(oe,{label:"Slug",required:!0,value:x,onChange:e=>h(e.target.value.toLowerCase()),placeholder:"my-custom-slug",helperText:"Lowercase letters, numbers, and hyphens only",autoFocus:!0,rightIcon:I?t.jsx(Re,{className:"h-4 w-4 animate-spin text-gray-400"}):!0===L?t.jsx(_e,{className:"h-4 w-4 text-green-400"}):!1===L?t.jsx(F,{className:"h-4 w-4 text-red-400"}):null})}),t.jsx(oe,{label:"Label (Optional)",value:g,onChange:e=>f(e.target.value),placeholder:"e.g., Discord, Twitter, Reddit",helperText:"Use labels to track which channel this slug is shared on"}),x&&t.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-cyan-700/40 bg-cyan-900/20 p-3 text-sm text-cyan-100",children:[t.jsx(ge,{className:"h-4 w-4 shrink-0 mt-0.5","aria-hidden":"true"}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("p",{className:"text-xs",children:"Public URL will be:"}),t.jsx("p",{className:"font-mono text-xs mt-1 break-all",children:H(x)})]})]})]})})]})};function ra(){return(ra=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var a=arguments[t];for(var l in a)Object.prototype.hasOwnProperty.call(a,l)&&(e[l]=a[l])}return e}).apply(this,arguments)}function oa(e,t){if(null==e)return{};var a,l,s={},i=Object.keys(e);for(l=0;l<i.length;l++)t.indexOf(a=i[l])>=0||(s[a]=e[a]);return s}function ca(t){var a=e.useRef(t),l=e.useRef(function(e){a.current&&a.current(e)});return a.current=t,l.current}var da=function(e,t,a){return void 0===t&&(t=0),void 0===a&&(a=1),e>a?a:e<t?t:e},ma=function(e){return"touches"in e},ua=function(e){return e&&e.ownerDocument.defaultView||self},pa=function(e,t,a){var l=e.getBoundingClientRect(),s=ma(t)?function(e,t){for(var a=0;a<e.length;a++)if(e[a].identifier===t)return e[a];return e[0]}(t.touches,a):t;return{left:da((s.pageX-(l.left+ua(e).pageXOffset))/l.width),top:da((s.pageY-(l.top+ua(e).pageYOffset))/l.height)}},xa=function(e){!ma(e)&&e.preventDefault()},ha=l.memo(function(t){var a=t.onMove,s=t.onKey,i=oa(t,["onMove","onKey"]),n=e.useRef(null),r=ca(a),o=ca(s),c=e.useRef(null),d=e.useRef(!1),m=e.useMemo(function(){var e=function(e){xa(e),(ma(e)?e.touches.length>0:e.buttons>0)&&n.current?r(pa(n.current,e,c.current)):a(!1)},t=function(){return a(!1)};function a(a){var l=d.current,s=ua(n.current),i=a?s.addEventListener:s.removeEventListener;i(l?"touchmove":"mousemove",e),i(l?"touchend":"mouseup",t)}return[function(e){var t,l=e.nativeEvent,s=n.current;if(s&&(xa(l),t=l,(!d.current||ma(t))&&s)){if(ma(l)){d.current=!0;var i=l.changedTouches||[];i.length&&(c.current=i[0].identifier)}s.focus(),r(pa(s,l,c.current)),a(!0)}},function(e){var t=e.which||e.keyCode;t<37||t>40||(e.preventDefault(),o({left:39===t?.05:37===t?-.05:0,top:40===t?.05:38===t?-.05:0}))},a]},[o,r]),u=m[0],p=m[1],x=m[2];return e.useEffect(function(){return x},[x]),l.createElement("div",ra({},i,{onTouchStart:u,onMouseDown:u,className:"react-colorful__interactive",ref:n,onKeyDown:p,tabIndex:0,role:"slider"}))}),ga=function(e){return e.filter(Boolean).join(" ")},fa=function(e){var t=e.color,a=e.left,s=e.top,i=void 0===s?.5:s,n=ga(["react-colorful__pointer",e.className]);return l.createElement("div",{className:n,style:{top:100*i+"%",left:100*a+"%"}},l.createElement("div",{className:"react-colorful__pointer-fill",style:{backgroundColor:t}}))},ba=function(e,t,a){return void 0===t&&(t=0),void 0===a&&(a=Math.pow(10,t)),Math.round(a*e)/a},ya=function(e){return"#"===e[0]&&(e=e.substring(1)),e.length<6?{r:parseInt(e[0]+e[0],16),g:parseInt(e[1]+e[1],16),b:parseInt(e[2]+e[2],16),a:4===e.length?ba(parseInt(e[3]+e[3],16)/255,2):1}:{r:parseInt(e.substring(0,2),16),g:parseInt(e.substring(2,4),16),b:parseInt(e.substring(4,6),16),a:8===e.length?ba(parseInt(e.substring(6,8),16)/255,2):1}},va=function(e){var t=function(e){var t=e.s,a=e.v,l=e.a,s=(200-t)*a/100;return{h:ba(e.h),s:ba(s>0&&s<200?t*a/100/(s<=100?s:200-s)*100:0),l:ba(s/2),a:ba(l,2)}}(e);return"hsl("+t.h+", "+t.s+"%, "+t.l+"%)"},ja=function(e){var t=e.toString(16);return t.length<2?"0"+t:t},wa=l.memo(function(e){var t=e.hue,a=e.onChange,s=ga(["react-colorful__hue",e.className]);return l.createElement("div",{className:s},l.createElement(ha,{onMove:function(e){a({h:360*e.left})},onKey:function(e){a({h:da(t+360*e.left,0,360)})},"aria-label":"Hue","aria-valuenow":ba(t),"aria-valuemax":"360","aria-valuemin":"
10"},l.createElement(fa,{className:"react-colorful__hue-pointer",left:t/360,color:va({h:t,s:100,v:100,a:1})})))}),Na=l.memo(function(e){var t=e.hsva,a=e.onChange,s={backgroundColor:va({h:t.h,s:100,v:100,a:1})};return l.createElement("div",{className:"react-colorful__saturation",style:s},l.createElement(ha,{onMove:function(e){a({s:100*e.left,v:100-100*e.top})},onKey:function(e){a({s:da(t.s+100*e.left,0,100),v:da(t.v-100*e.top,0,100)})},"aria-label":"Color","aria-valuetext":"Saturation "+ba(t.s)+"%, Brightness "+ba(t.v)+"%"},l.createElement(fa,{className:"react-colorful__saturation-pointer",top:1-t.v/100,left:t.s/100,color:va(t)})))}),Ca=function(e,t){if(e===t)return!0;for(var a in e)if(e[a]!==t[a])return!1;return!0},Sa="undefined"!=typeof window?e.useLayoutEffect:e.useEffect,Da=new Map,Ta=function(t){var a,s=t.className,i=t.colorModel,n=t.color,r=void 0===n?i.defaultColor:n,o=t.onChange,c=oa(t,["className","colorModel","color","onChange"]),d=e.useRef(null);a=d,Sa(function(){var e=a.current?a.current.ownerDocument:document;if(void 0!==e&&!Da.has(e)){var t=e.createElement("style");t.innerHTML='.react-colorful{position:relative;display:flex;flex-direction:column;width:200px;height:200px;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;cursor:default}.react-colorful__saturation{position:relative;flex-grow:1;border-color:transparent;border-bottom:12px solid #000;border-radius:8px 8px 0 0;background-image:linear-gradient(0deg,#000,transparent),linear-gradient(90deg,#fff,hsla(0,0%,100%,0))}.react-colorful__alpha-gradient,.react-colorful__pointer-fill{content:"";position:absolute;left:0;top:0;right:0;bottom:0;pointer-events:none;border-radius:inherit}.react-colorful__alpha-gradient,.react-colorful__saturation{box-shadow:inset 0 0 0 1px rgba(0,0,0,.05)}.react-colorful__alpha,.react-colorful__hue{position:relative;height:24px}.react-colorful__hue{background:linear-gradient(90deg,red 0,#ff0 17%,#0f0 33%,#0ff 50%,#00f 67%,#f0f 83%,red)}.react-colorful__last-control{border-radius:0 0 8px 8px}.react-colorful__interactive{position:absolute;left:0;top:0;right:0;bottom:0;border-radius:inherit;outline:none;touch-action:none}.react-colorful__pointer{position:absolute;z-index:1;box-sizing:border-box;width:28px;height:28px;transform:translate(-50%,-50%);background-color:#fff;border:2px solid #fff;border-radius:50%;box-shadow:0 2px 4px rgba(0,0,0,.2)}.react-colorful__interactive:focus .react-colorful__pointer{transform:translate(-50%,-50%) scale(1.1)}.react-colorful__alpha,.react-colorful__alpha-pointer{background-color:#fff;background-image:url(\'data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill-opacity=".05"><path d="M8 0h8v8H8zM0 8h8v8H0z"/></svg>\')}.react-colorful__saturation-pointer{z-index:3}.react-colorful__hue-pointer{z-index:2}',Da.set(e,t);var l="undefined"!=typeof __webpack_nonce__?__webpack_nonce__:void 0;l&&t.setAttribute("nonce",l),e.head.appendChild(t)}},[]);var m=function(t,a,l){var s=ca(l),i=e.useState(function(){return t.toHsva(a)}),n=i[0],r=i[1],o=e.useRef({color:a,hsva:n});e.useEffect(function(){if(!t.equal(a,o.current.color)){var e=t.toHsva(a);o.current={hsva:e,color:a},r(e)}},[a,t]),e.useEffect(function(){var e;Ca(n,o.current.hsva)||t.equal(e=t.fromHsva(n),o.current.color)||(o.current={hsva:n,color:e},s(e))},[n,t,s]);var c=e.useCallback(function(e){r(function(t){return Object.assign({},t,e)})},[]);return[n,c]}(i,r,o),u=m[0],p=m[1],x=ga(["react-colorful",s]);return l.createElement("div",ra({},c,{ref:d,className:x}),l.createElement(Na,{hsva:u,onChange:p}),l.createElement(wa,{hue:u.h,onChange:p,className:"react-colorful__last-control"}))},ka={defaultColor:"000",toHsva:function(e){return function(e){var t=e.r,a=e.g,l=e.b,s=e.a,i=Math.max(t,a,l),n=i-Math.min(t,a,l),r=n?i===t?(a-l)/n:i===a?2+(l-t)/n:4+(t-a)/n:0;return{h:ba(60*(r<0?r+6:r)),s:ba(i?n/i*100:0),v:ba(i/255*100),a:s}}(ya(e))},fromHsva:function(e){return function(e){return function(e){var t=e.r,a=e.g,l=e.b,s=e.a,i=s<1?ja(ba(255*s)):"";return"#"+ja(t)+ja(a)+ja(l)+i}(function(e){var t=e.h,a=e.s,l=e.v,s=e.a;t=t/360*6,a/=100,l/=100;var i=Math.floor(t),n=l*(1-a),r=l*(1-(t-i)*a),o=l*(1-(1-t+i)*a),c=i%6;return{r:ba(255*[l,r,n,n,o,l][c]),g:ba(255*[o,l,l,r,n,n][c]),b:ba(255*[n,n,o,l,l,r][c]),a:ba(s,2)}}(e))}({h:e.h,s:e.s,v:e.v,a:1})},equal:function(e,t){return e.toLowerCase()===t.toLowerCase()||Ca(ya(e),ya(t))}},Ia=function(e){return l.createElement(Ta,ra({},e,{colorModel:ka}))};const Fa=({label:l,value:s,onChange:i,onReset:n,disabled:r=!1})=>{const[o,c]=e.useState(!1),[d,m]=e.useState(null),[u,p]=e.useState(s||""),x=e.useRef(null),h=e.useRef(null);return e.useEffect(()=>{p(s||"")},[s]),e.useEffect(()=>{if(!o)return;if(x.current){const e=x.current.getBoundingClientRect();m({top:e.bottom+6,left:e.left})}const e=e=>{h.current&&!h.current.contains(e.target)&&x.current&&!x.current.contains(e.target)&&c(!1)},t=e=>{"Escape"===e.key&&c(!1)};return document.addEventListener("mousedown",e),document.addEventListener("keydown",t),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("keydown",t)}},[o]),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(ie,{c
1ontent:s||"Auto (theme default)",children:t.jsx("button",{ref:x,type:"button",onClick:()=>{r||c(e=>!e)},disabled:r,className:"w-8 h-8 rounded border-2 border-gray-700/50 shrink-0 "+(r?"opacity-50 cursor-not-allowed":"cursor-pointer"),style:s?{backgroundColor:s}:{background:"repeating-conic-gradient(#808080 0% 25%, #c0c0c0 0% 50%) 50% / 12px 12px"},"aria-label":"Pick color"})}),t.jsx("span",{className:"flex-1 min-w-0 text-sm text-gray-300 truncate",children:l}),s&&n&&t.jsx(ie,{content:"Reset to default",children:t.jsx("button",{type:"button",onClick:n,disabled:r,className:"p-2 rounded hover:bg-gray-700/50 text-gray-400 hover:text-gray-200 disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:t.jsx(Me,{className:"w-4 h-4"})})}),a.createPortal(t.jsx(C,{children:o&&d&&t.jsxs(S.div,{ref:h,initial:{opacity:0,scale:.95,y:-4},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:-4},transition:{duration:.12},style:{position:"fixed",top:d.top,left:d.left,zIndex:9999},className:"rounded-lg border border-gray-700/50 bg-gray-800/95 backdrop-blur-xs shadow-2xl p-3 w-56",children:[t.jsx(Ia,{color:u||"#000000",onChange:e=>{p(e),i(e)},style:{width:"100%"}}),t.jsx("input",{type:"text",value:u,onChange:e=>{const t=e.target.value;p(t),/^#[0-9a-fA-F]{6}$/.test(t)&&i(t)},placeholder:"#000000",maxLength:7,className:"mt-3 w-full px-2 py-1.5 bg-gray-900/50 border border-gray-700/50 rounded text-sm text-gray-200 placeholder-gray-500 focus:outline-hidden focus:ring-2 focus:ring-(--theme-primary-color,#bb86fc)"})]})}),document.body)]})},Aa=({label:e,value:a,min:l,max:s,step:i=1,unit:n="px",onChange:r,onReset:o,disabled:c=!1})=>{const d=a??l,m=null!=a;return t.jsxs("div",{children:[t.jsxs("div",{className:"mb-1 flex items-center justify-between",children:[t.jsx("span",{className:"text-sm text-gray-400",children:e}),t.jsxs("div",{className:"flex items-center gap-1",children:[t.jsxs("span",{className:"text-xs text-gray-400",children:[d,n]}),m&&o&&t.jsx(ie,{content:"Reset to default",children:t.jsx("button",{type:"button",onClick:o,disabled:c,className:"p-0.5 rounded hover:bg-gray-700/50 text-gray-400 hover:text-gray-200 disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:t.jsx(Me,{className:"w-3.5 h-3.5"})})})]})]}),t.jsx("input",{type:"range",value:d,min:l,max:s,step:i,onChange:e=>r(Number(e.target.value)),disabled:c,className:"w-full accent-(--theme-primary-color,#bb86fc) disabled:opacity-50 disabled:cursor-not-allowed"})]})},La=[{value:"none",label:"None"},{value:"solid",label:"Solid"},{value:"gradient",label:"Gradient"},{value:"image",label:"Image"}],Ea=[{value:"cover",label:"Cover"},{value:"contain",label:"Contain"},{value:"fill",label:"Fill"}],Pa=({value:e={},onChange:a,disabled:l=!1})=>{const s=e.type||"none",i=t=>a({...e,...t});return t.jsxs("div",{className:"flex flex-col gap-3",children:[t.jsx("div",{className:"grid grid-cols-4 gap-1 rounded-lg border border-gray-700/50 bg-gray-800/40 p-1",children:La.map(e=>{const a=s===e.value;return t.jsx("button",{type:"button",onClick:()=>!l&&i({type:e.value}),disabled:l,className:"px-2 py-1.5 rounded text-xs font-medium transition-colors disabled:opacity-50 disabled:cursor-not-allowed "+(a?"bg-(--theme-primary-color,#bb86fc) text-white":"text-gray-300 hover:bg-gray-700/60"),children:e.label},e.value)})}),"solid"===s&&t.jsx(Fa,{label:"Background Color",value:e.color||null,onChange:e=>i({color:e}),onReset:()=>i({color:null}),disabled:l}),"gradient"===s&&t.jsxs(t.Fragment,{children:[t.jsx(Fa,{label:"Gradient Start",value:e.gradientStart||null,onChange:e=>i({gradientStart:e}),onReset:()=>i({gradientStart:null}),disabled:l}),t.jsx(Fa,{label:"Gradient End",value:e.gradientEnd||null,onChange:e=>i({gradientEnd:e}),onReset:()=>i({gradientEnd:null}),disabled:l}),t.jsxs("div",{children:[t.jsxs("div",{className:"mb-1 text-sm text-gray-400",children:["Angle: ",e.gradientAngle??135,"°"]}),t.jsx("input",{type:"range",value:e.gradientAngle??135,min:0,max:360,step:5,onChange:e=>i({gradientAngle:Number(e.target.value)}),disabled:l,className:"w-full accent-(--theme-primary-color,#bb86fc) disabled:opacity-50"})]})]}),"image"===s&&t.jsxs(t.Fragment,{children:[t.jsxs("div",{children:[t.jsx("label",{className:"block text-xs font-medium text-gray-400 mb-1",children:"Image URL"}),t.jsx("input",{type:"text",value:e.imageUrl||"",onChange:e=>i({imageUrl:e.target.value}),placeholder:"https://example.com/bg.jpg",disabled:l,className:"w-full px-3 py-2 bg-gray-800/50 border border-gray-700/50 rounded-lg text-sm text-gray-200 placeholder-gray-500 focus:outline-hidden focu
1s:ring-2 focus:ring-(--theme-primary-color,#bb86fc) disabled:opacity-50"})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-xs font-medium text-gray-400 mb-1",children:"Image Size"}),t.jsx("select",{value:e.imageSize||"cover",onChange:e=>i({imageSize:e.target.value}),disabled:l,className:"w-full px-3 py-2 bg-gray-800/50 border border-gray-700/50 rounded-lg text-sm text-gray-200 focus:outline-hidden focus:ring-2 focus:ring-(--theme-primary-color,#bb86fc) disabled:opacity-50",children:Ea.map(e=>t.jsx("option",{value:e.value,children:e.label},e.value))})]}),t.jsx(Fa,{label:"Overlay Color",value:e.overlayColor||null,onChange:e=>i({overlayColor:e}),onReset:()=>i({overlayColor:null}),disabled:l})]}),"none"!==s&&t.jsxs("div",{children:[t.jsxs("div",{className:"mb-1 text-sm text-gray-400",children:["Opacity: ",(100*(e.opacity??1)).toFixed(0),"%"]}),t.jsx("input",{type:"range",value:e.opacity??1,min:.1,max:1,step:.05,onChange:e=>i({opacity:Number(e.target.value)}),disabled:l,className:"w-full accent-(--theme-primary-color,#bb86fc) disabled:opacity-50"})]})]})},Ra=({label:a,value:l,onChange:s,onReset:i,disabled:n=!1})=>{const[r,o]=e.useState(!1),[c,d]=e.useState(l||""),m=e.useRef(null);e.useEffect(()=>{d(l||"")},[l]),e.useEffect(()=>{if(!r)return;f.forEach(b);const e=e=>{m.current&&!m.current.contains(e.target)&&o(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[r]);const u=c?f.filter(e=>e.toLowerCase().includes(c.toLowerCase())):f;return t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs("div",{className:"relative flex-1",ref:m,children:[a&&t.jsx("label",{className:"block text-xs font-medium text-gray-400 mb-1",children:a}),t.jsxs("div",{className:"relative",children:[t.jsx("input",{type:"text",value:c,onChange:e=>{const t=e.target.value;d(t),t&&b(t),s(t||null)},onFocus:()=>o(!0),placeholder:"Select or type a font...",disabled:n,className:"w-full px-3 py-2 pr-9 bg-gray-800/50 border border-gray-700/50 rounded-lg text-sm text-gray-200 placeholder-gray-500 focus:outline-hidden focus:ring-2 focus:ring-(--theme-primary-color,#bb86fc) disabled:opacity-50 disabled:cursor-not-allowed"}),t.jsx("button",{type:"button",onClick:()=>!n&&o(e=>!e),disabled:n,className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 text-gray-400 hover:text-gray-200","aria-label":"Toggle font list",children:t.jsx(I,{className:"w-4 h-4 transition-transform "+(r?"rotate-180":"")})})]}),t.jsx(C,{children:r&&t.jsx(S.div,{initial:{opacity:0,y:-4},animate:{opacity:1,y:0},exit:{opacity:0,y:-4},transition:{duration:.12},className:"absolute z-50 mt-1 w-full max-h-60 overflow-y-auto rounded-lg border border-gray-700/50 bg-gray-800/95 backdrop-blur-xs shadow-2xl",children:0===u.length?t.jsx("div",{className:"px-3 py-2 text-sm text-gray-400",children:"No matches"}):u.map(e=>t.jsx("button",{type:"button",onClick:()=>(e=>{b(e),s(e),d(e),o(!1)})(e),className:"w-full text-left px-3 py-2 text-sm text-gray-200 hover:bg-gray-700/60",style:{fontFamily:`"${e}", sans-serif`},children:e},e))})})]}),l&&i&&t.jsx(ie,{content:"Reset to default",children:t.jsx("button",{type:"button",onClick:i,disabled:n,className:"p-2 rounded hover:bg-gray-700/50 text-gray-400 hover:text-gray-200 disabled:opacity-50 disabled:cursor-not-allowed transition-colors",children:t.jsx(Me,{className:"w-4 h-4"})})}),l&&t.jsx("div",{className:"px-2 py-1 rounded bg-gray-700/40 text-xs text-gray-200 whitespace-nowrap",style:{fontFamily:l},children:"Aa"})]})},_a="w-full px-3 py-2 bg-gray-800/50 border border-gray-700/50 rounded-lg text-sm text-gray-200 placeholder-gray-500 focus:outline-hidden focus:ring-2 focus:ring-(--theme-primary-color,#bb86fc) disabled:opacity-50 disabled:cursor-not-allowed",Ma=_a;function Oa({label:e,helperText:a,children:l,className:s="",error:i=!1}){return t.jsxs("div",{className:`flex flex-col gap-1 ${s}`,children:[e&&t.jsx("label",{className:"text-xs font-medium text-gray-400",children:e}),l,a&&t.jsx("p",{className:"text-xs "+(i?"text-red-400":"text-gray-500"),children:a})]})}function $a({label:e,checked:a,onChange:l,disabled:s=!1}){return t.jsxs("div",{className:"flex items-center justify-between gap-3 "+(s?"cursor-not-allowed opacity-50":"cursor-pointer"),onClick:()=>{s||l(!a)},children:[t.jsx("span",{className:"text-sm text-gray-300 flex-1 select-none",children:e}),t.jsx("span",{onClick:e=>e.stopPropagation(),className:"contents",children:t.jsx(ne,{checked:!!a,onChange:l,disabled:s,size:"sm"})})]})}function za({children:e,variant:a="info",onClose:l,className:s=""}){const i="error"===a?F:"warning"===a?A:"success"===a?B:L;return t.jsxs("div",{className:`flex items-start gap-2 p-3 rounded-lg border text-sm ${{info:"bg-cyan-900/20 border-cyan-700/40 text-cyan-200",warning:"bg-yellow-900/20 border-yellow-700/40 text-yellow-200",error:"bg-red-900/20 border-red-700/40 text-red-200",success:"bg-green-900/20 border-green-700/40 text-green-200"}[a]} ${s}`,children:[t.jsx(i,{className:"w-4 h-4 shrink-0 mt-0.5"}),t.jsx("div",{className:"flex-1",children:e}),l&&t.jsx("button",{type:"button",onClick:l,className:"p-0.5 rounded hover:bg-black/20","aria-label":"Close",children:t.jsx(E,{className:"w-4 h-4"})})]})}function Ua({title:a,defaultOpen:l=!1,children:s}){const[i,n]=e.useState(l);return t.jsxs("div",{className:"rounded-lg border border-gray-700/50 bg-gray-800/30 overflow-hidden",children:[t.jsxs("button",{type:"button",onClick:()=>n(e=>!e),className:"w-full flex items-center justify-between px-3 py-2.5 text-sm font-semibold text-gray-200 hover:bg-gray-700/30 transition-colors",children:[t.jsx("span",{children:a}),t.jsx(I,{className:"w-4 h-4 text-gray-400 transition-transform "+(i?"rotate-180":"")})]}),t.jsx(C,{initial:!1,children:i&&t.jsx(S.div,{initial:{height:0,opacity:0}
1,animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:.2},className:"overflow-hidden",children:t.jsx("div",{className:"p-3 border-t border-gray-700/40 flex flex-col gap-3",children:s})})})]})}const Ba=({initialTab:a=0})=>{const{formTemplate:l,showFormSettings:i,toggleFormSettings:n,updateFormTitle:r,updateFormDescription:o,updateFormSettings:c,updateFormAppearanceGlobal:d,updateFormAppearanceFlags:m,resetFormAppearance:u,isDirty:p}=et(),{selectedGuild:x}=U(),h=x?.id,[g,f]=e.useState(a),[b,y]=e.useState(null),[v,j]=e.useState(!1),[w,N]=e.useState(""),[D,k]=e.useState(!1),L=e.useRef(null),[E,P]=e.useState(!1),[R,_]=e.useState(null),[z,q]=e.useState(null),[W,V]=e.useState(!1),[G,Y]=e.useState(!1),[X,Z]=e.useState([]),[J,te]=e.useState([]),[ae,le]=e.useState({isUnique:!0,existingForms:[],suggestions:[]}),[ne,re]=e.useState(!1),oe=e.useRef(null),[ce,de]=e.useState(!1),[me,ue]=e.useState(l.formSlug||""),[pe,xe]=e.useState({valid:!0,error:null}),[he,ge]=e.useState(!1),[fe,be]=e.useState(!1),ye=e.useRef(null),ve=l.templateData?.settings||{},je=Intl.DateTimeFormat().resolvedOptions().timeZone||"UTC",we=e.useMemo(()=>"function"==typeof Intl.supportedValuesOf?Intl.supportedValuesOf("timeZone"):["UTC","America/New_York","America/Chicago","America/Denver","America/Los_Angeles","Europe/London","Europe/Paris","Asia/Tokyo","Australia/Sydney"],[]),Ne=(e,t)=>{c({[e]:t})},Ce=(e,t)=>{const{formTemplate:a}=et.getState();et.setState({formTemplate:{...a,templateData:{...a.templateData,notifications:{...a.templateData.notifications,[e]:t}}},isDirty:!0})},Se=e.useCallback(async e=>{if(e&&h){re(!0);try{const t=await s.get("/api/forms/check-title",{params:{title:e,excludeFormId:l.id}});t.data.success&&le({isUnique:t.data.isUnique,existingForms:t.data.existingForms||[],suggestions:t.data.suggestions||[]})}catch(t){console.error("Error checking title uniqueness:",t)}finally{re(!1)}}},[h,l.id]),De=e=>{r(e),oe.current&&clearTimeout(oe.current),oe.current=setTimeout(()=>{Se(e)},500)},Te=e.useCallback(async e=>{if(e&&h){ge(!0);try{const t=await s.get("/api/forms/check-slug",{params:{slug:e,formId:l.id}});t.data.success&&xe({valid:t.data.valid,error:t.data.error,normalizedSlug:t.data.normalizedSlug})}catch(t){console.error("Error validating slug:",t),xe({valid:!1,error:"Failed to validate slug"})}finally{ge(!1)}}},[h,l.id]);e.useEffect(()=>()=>{oe.current&&clearTimeout(oe.current),ye.current&&clearTimeout(ye.current)},[]),e.useEffect(()=>{ue(l.formSlug||"")},[l.formSlug]),e.useEffect(()=>{f(a)},[a]);const ke=async()=>{if(w.trim()){try{new URL(w)}catch(e){return void y("Please enter a valid URL")}j(!0),y(null);try{const e=await fetch("/api/forms/upload-banner-from-url",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({url:w})});if(!e.ok){const t=await e.json().catch(()=>({}));throw new Error(t.error||"Failed to upload banner from URL")}const t=await e.json();t.success&&(Ne("bannerImage",t.url),N(""),k(!1))}catch(t){console.error("Error uploading banner from URL:",t),y(t.message||"Failed to upload image from URL. Please try again.")}finally{j(!1)}}else y("Please enter a valid URL")};e.useEffect(()=>{3===g&&h&&0===X.length&&(async()=>{if(h){Y(!0);try{const e=await fetch(`/api/discord/guilds/${h}/members`,{credentials:"include"});if(!e.ok)throw new Error("Failed to load Discord members");const t=await e.json();Z(t.members||[]),te(t.roles||[])}catch(e){console.error("Error loading Discord members:",e)}finally{Y(!1)}}})()},[g,h]);const Ie=l.templateData?.notifications||{},Fe=Ie.notificationFormat||"embed",Ae=l.visibilityLevel||"private",Le=l.templateData?.settings?.responseVisibility,Ee=!!l.templateData?.settings?.requireAuth,Pe="private"===Ae?"editors":"guild"===Ae?"guild":"public"===Ae&&Ee?"discord":"public",_e="editors"===Pe?ze:"guild"===Pe?$:"discord"===Pe?M:H;return t.jsxs(K,{isOpen:!!i,onClose:n,title:"Form Settings",size:"lg",footer:t.jsx(T,{variant:"ghost",onClick:n,children:"Close"}),children:[t.jsx("div",{className:"flex flex-row overflow-x-auto border-b border-gray-700/50 mb-4 -mx-4 sm:-mx-6 px-4 sm:px-6",children:["General","Appearance","Responses","Notifications","Visibility & Sharing"].map((e,a)=>{const l=g===a;return t.jsx("button",{type:"button",onClick:()=>f(a),className:"shrink-0 px-3 py-2 text-sm font-medium transition-colors border-b-2 "+(l?"border-(--theme-primary-color,#bb86fc) text-(--theme-primary-color,#bb86fc)":"border-transparent text-gray-400 hover:text-gray-200"),children:e},e)})}),0===g&&t.jsxs("div",{className:"flex flex-col gap-4",children:[t.jsxs(Oa,{label:"Form Title",children:[t.jsxs("div",{className:"relative",children:[t.jsx("input",{type:"text",value:l.title||"",onChange:e=>De(e.target.value),className:`${_a} pr-10`}),t.jsx("div",{className:"absolute right-3 top-1/2 -translate-y-1/2 pointer-events-none",children:ne?t.jsx(Re,{className:"w-5 h-5 text-gray-400 animate-spin"}
1):ae.isUnique?t.jsx(ie,{content:"Title is unique",children:t.jsx("span",{children:t.jsx(B,{className:"w-5 h-5 text-green-400"})})}):t.jsx(ie,{content:"Duplicate title detected",children:t.jsx("span",{children:t.jsx(A,{className:"w-5 h-5 text-yellow-400"})})})})]}),!ae.isUnique&&ae.suggestions.length>0&&t.jsxs(za,{variant:"warning",className:"mt-1",children:[t.jsx("p",{className:"mb-1",children:"A form with this title already exists. Suggestions:"}),t.jsx("div",{className:"flex flex-wrap gap-1",children:ae.suggestions.map((e,a)=>t.jsx("button",{type:"button",onClick:()=>De(e),className:"inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium border border-gray-600 text-gray-200 bg-gray-800/50 hover:bg-gray-700/60 transition-colors",children:e},a))})]})]}),t.jsx(Oa,{label:"Form Description",helperText:"Shown at the top of the form",children:t.jsx("textarea",{rows:3,value:l.description||"",onChange:e=>o(e.target.value),className:_a})}),l.id&&l.formSlug&&t.jsxs("div",{className:"rounded-lg border border-gray-700/50 bg-gray-800/40 p-3",children:[t.jsx("p",{className:"text-sm font-semibold text-gray-200",children:"Form URL Slug"}),t.jsx("p",{className:"text-xs text-gray-400 mb-3",children:"The slug is used in the public URL for your form"}),R&&t.jsx(za,{variant:"success",className:"mb-2",children:R}),b&&t.jsx(za,{variant:"error",className:"mb-2",children:b}),ce?t.jsxs("div",{children:[t.jsx(Oa,{label:"Custom Slug",error:!pe.valid,helperText:pe.error||"Use only lowercase letters, numbers, and hyphens",children:t.jsxs("div",{className:"relative",children:[t.jsx("input",{type:"text",value:me,onChange:e=>{return t=e.target.value,ue(t),ye.current&&clearTimeout(ye.current),void(ye.current=setTimeout(()=>{Te(t)},500));var t},className:`${_a} pr-10 ${pe.valid?"":"border-red-500 focus:ring-red-500"}`}),t.jsx("div",{className:"absolute right-3 top-1/2 -translate-y-1/2 pointer-events-none",children:he?t.jsx(Re,{className:"w-5 h-5 text-gray-400 animate-spin"}):pe.valid?t.jsx(B,{className:"w-5 h-5 text-green-400"}):t.jsx(F,{className:"w-5 h-5 text-red-400"})})]})}),pe.normalizedSlug&&pe.normalizedSlug!==me&&t.jsxs(za,{variant:"info",className:"my-2",children:["Will be normalized to: ",t.jsx("strong",{children:pe.normalizedSlug})]}),t.jsxs("div",{className:"flex gap-2 mt-2",children:[t.jsx(T,{variant:"primary",size:"sm",onClick:async()=>{if(l.id&&h&&pe.valid)try{const e=await s.patch(`/api/forms/${l.id}/slug`,{slug:me});if(e.data.success){const{formTemplate:t}=et.getState();et.setState({formTemplate:{...t,formSlug:e.data.slug},isDirty:!0}),de(!1),_("Custom slug saved successfully"),setTimeout(()=>_(null),3e3)}}catch(e){console.error("Error saving custom slug:",e),xe({valid:!1,error:e.response?.data?.error||"Failed to save custom slug"})}},disabled:!pe.valid||he,children:"Save Slug"}),t.jsx(T,{variant:"outline",size:"sm",onClick:()=>{de(!1),ue(l.formSlug),xe({valid:!0,error:null})},children:"Cancel"})]})]}):t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-center gap-2 p-2 bg-gray-900/50 rounded border border-gray-700/40 mb-2",children:[t.jsx("span",{className:"font-mono text-sm text-gray-200 flex-1 truncate",children:l.formSlug}),t.jsx(ie,{content:"Copy public URL",children:t.jsx("button",{type:"button",onClick:()=>{if(!l.formSlug||!x?.slug)return;const e=`${window.location.origin}/forms/${x.slug}/${l.formSlug}`;navigator.clipboard.writeText(e),_("URL copied to clipboard"),setTimeout(()=>_(null),2e3)},className:"p-1.5 rounded hover:bg-gray-700/50 text-gray-400 hover:text-gray-200 transition-colors","aria-label":"Copy URL",children:t.jsx(Q,{className:"w-4 h-4"})})})]}),x?.slug&&t.jsxs("p",{className:"text-xs text-gray-400 mb-2",children:["Public URL:"," ",t.jsxs("a",{href:`/forms/${x.slug}/${l.formSlug}`,target:"_blank",rel:"noopener noreferrer",className:"text-(--theme-primary-color,#bb86fc) hover:underline",children:["/forms/",x.slug,"/",l.formSlug]})]}),t.jsxs("div",{className:"flex flex-wrap gap-2",children:[t.jsx(T,{variant:"outline",size:"sm",leftIcon:t.jsx(O,{className:"w-3.5 h-3.5 "+(fe?"animate-spin":"")}),onClick:async()=>
1{if(l.id&&h){be(!0);try{const e=await s.post(`/api/forms/${l.id}/regenerate-slug`);if(e.data.success){const{formTemplate:t}=et.getState();et.setState({formTemplate:{...t,formSlug:e.data.slug},isDirty:!0}),ue(e.data.slug),y(null),_("Slug regenerated successfully"),setTimeout(()=>_(null),3e3)}}catch(e){console.error("Error regenerating slug:",e),y(e.response?.data?.error||"Failed to regenerate slug")}finally{be(!1)}}},disabled:fe,children:fe?"Regenerating...":"Regenerate from Title"}),t.jsx(T,{variant:"outline",size:"sm",leftIcon:t.jsx(se,{className:"w-3.5 h-3.5"}),onClick:()=>de(!0),children:"Custom Slug"})]})]})]})]}),1===g&&t.jsxs("div",{className:"flex flex-col gap-3",children:[t.jsxs(Ua,{title:"Banner Image",defaultOpen:!0,children:[t.jsx("p",{className:"text-xs text-gray-400",children:"Add a custom banner image that appears at the top of your form"}),b&&t.jsx(za,{variant:"error",onClose:()=>y(null),children:b}),ve.bannerImage?t.jsxs("div",{children:[t.jsxs("div",{className:"rounded-lg p-2 mb-3 border border-gray-700/40 bg-gray-900/30",children:[t.jsx("img",{src:ve.bannerImage,alt:"Form banner",className:"w-full max-h-[200px] object-cover rounded mb-2"}),t.jsx(T,{variant:"error",leftIcon:t.jsx(ee,{className:"w-4 h-4"}),onClick:()=>{Ne("bannerImage",null)},className:"w-full",children:"Remove Banner"})]}),t.jsx(Oa,{label:"Banner Alt Text",helperText:"Screen readers will announce this text for visually impaired users",children:t.jsx("input",{type:"text",value:ve.bannerAltText||"",onChange:e=>Ne("bannerAltText",e.target.value),placeholder:"Describe the banner image for accessibility",className:_a})})]}):t.jsxs("div",{children:[t.jsx("input",{ref:L,type:"file",accept:"image/*",onChange:async e=>{const t=e.target.files?.[0];if(t)if(t.type.startsWith("image/"))if(t.size>5242880)y("Image must be smaller than 5MB");else{j(!0),y(null);try{const e=new FormData;e.append("banner",t);const a=await fetch("/api/forms/upload-banner",{method:"POST",body:e});if(!a.ok)throw new Error("Failed to upload banner image");const l=await a.json();l.success&&Ne("bannerImage",l.url)}catch(a){console.error("Error uploading banner:",a),y("Failed to upload image. Please try again.")}finally{j(!1),L.current&&(L.current.value="")}}else y("Please select an image file")},className:"hidden"}),t.jsxs("div",{className:"flex flex-col gap-2",children:[t.jsx(T,{variant:"outline",leftIcon:t.jsx(Oe,{className:"w-4 h-4"}),onClick:()=>{k(!1),L.current?.click()},disabled:v,className:"w-full",children:v&&!D?"Uploading...":"Upload from Computer"}),D?t.jsxs("div",{children:[t.jsxs("div",{className:"flex gap-2",children:[t.jsx("input",{type:"text",value:w,onChange:e=>N(e.target.value),placeholder:"https://example.com/image.jpg",disabled:v,onKeyDown:e=>{"Enter"===e.key&&ke()},className:`${_a} flex-1`}),t.jsx(T,{variant:"primary",onClick:ke,disabled:v||!w.trim(),children:v?"Loading...":"Upload"})]}),t.jsx(T,{variant:"ghost",size:"sm",onClick:()=>{k(!1),N(""),y(null)},disabled:v,className:"mt-1",children:"Cancel"})]}):t.jsx(T,{variant:"ghost",size:"sm",onClick:()=>k(!0),disabled:v,children:"Or upload from URL"}),t.jsx("p",{className:"text-xs text-gray-400",children:"Recommended: 1200x300px, max 5MB (JPG, PNG, GIF, WebP)"})]})]})]}),t.jsxs(Ua,{title:"Color Scheme",defaultOpen:!0,children:[t.jsx(Fa,{label:"Primary Color",value:l?.templateData?.appearance?.global?.accents?.primaryColor||null,onChange:e=>d({accents:{primaryColor:e}}),onReset:()=>d({accents:{primaryColor:null}})}),t.jsx(Fa,{label:"Secondary Color",value:l?.templateData?.appearance?.global?.accents?.secondaryColor||null,onChange:e=>d({accents:{secondaryColor:e}}),onReset:()=>d({accents:{secondaryColor:null}})}),t.jsx($a,{label:"Use Guild Branding",checked:!1!==l?.templateData?.appearance?.flags?.useGuildBranding,onChange:e=>m({useGuildBranding:e})}),t.jsx("p",{className:"text-xs text-gray-400",children:"Applies your guild's brand colors as defaults when no custom colors are set"})]}),t.jsxs(Ua,{title:"Typography",children:[t.jsx(Ra,{label:"Body Font",value:l?.templateData?.appearance?.global?.typography?.fontFamily||null,onChange:e=>d({typography:{fontFamily:e}}),onReset:()=>d({typography:{fontFamily:null}})}),t.jsx(Ra,{label:"Heading Font",value:l?.templateData?.appearance?.global?.typography?.headingFontFamily||null,onChange:e=>d({typography:{headingFontFamily:e}}),onReset:()=>d({typography:{headingFontFamily:null}})}),t.jsx(Aa,{label:"Base Font Size",value:(()=>{const e=l?.templateData?.appearance?.global?.typography?.bodySize;return e?"string"==typeof e?parseInt(e)||16:e:16})(),min:12,max:24,unit:"px",onChange:e=>d({typography:{bodySize:`${e}px`}}),onReset:()=>d({typography:{bodySize:null}})}),t.jsx(Oa,{label:"Title Weight",children:t.jsxs("select",{value:l?.templateData?.appearance?.global?.typography?.formTitleWeight||600,onChange:e=>d({typography:{formTitleWeight:parseInt(e.target.value)}}),className:Ma,children:[t.jsx("option",{value:400,children:"Regular (400)"}),t.jsx("option",{value:500,children:"Medium (500)"}),t.jsx("option",{value:600,children:"Semi-Bold (600)"}),t.jsx("option",{value:700,children:"Bold (700)"}),t.jsx("option",{value:800,children:"Extra-Bold (800)"})]})}),[["Title Color","formTitleColor"],["Section Title Color","sectionTitleColor"],["Field Label Color","fieldLabelColor"],["Body Text Color","bodyColor"],["Description Color","descriptionColor"],["Helper Text Color","helperColor"]].map(([e,a])=>t.jsx(Fa,{label:e,value:l?.templateData?.appearance?.global?.typography?.[a]||null,onChange:e=>d({typography:{[a]:e}}),onReset:()=>d({typography:{[a]:null}})},a))]}),t.jsxs(Ua,{title:"Layout & Spacing",children:[t.jsx(Aa,{label:"Form Max Width",value:l?.templateData?.appearance?.global?.formSurface?.maxWidth??800,min:600,max:1200,unit:"px",onChange:e=>d({formSurface:{maxWidth:e}}),onReset:()=>d({formSurface:{maxWidth:null}})}),t.jsx(Aa,{label:"Form Border Radius",value:l?.templateData?.appearance?.global?.formSurface?.borderRadius??12,min:0,max:24,unit:"px",onChange:e=>d({formSurface:{borderRadius:e}}),onReset:()=>d({formSurface:{borderRadius:null}})}),t.jsx(Aa,{label:"Field Gap",value:l?.templateData?.appearance?.global?.fieldSurface?.gap??16,min:8,max:48,unit:"px",onChange:e=>d({fieldSurface:{gap:e}}),onReset:()=>d({fieldSurface:{gap:null}})}),t.jsx(Aa,{label:"Section Gap",value:l?.templateData?.appearance?.global?.sectionSurface?.gap??32,min:16,max:64,unit:"px",onChange:e=>d({sectionSurface:{gap:e}}),onReset:()=>d({sectionSurface:{gap:null}})}),t.jsx(Aa,{label:"Form Padding",value:l?.templateData?.appearance?.global?.formSurface?.paddingX??32,min:16,max:64,unit:"px",onChange:e=>d({formSurface:{paddingX:e}}),onReset:()=>d({formSurface:{paddingX:null}})})]}
1),t.jsx(Ua,{title:"Page Background",children:t.jsx(Pa,{value:l?.templateData?.appearance?.global?.pageBackground||{},onChange:e=>d({pageBackground:e})})}),t.jsxs(Ua,{title:"Buttons & Progress",children:[t.jsx(Aa,{label:"Button Border Radius",value:l?.templateData?.appearance?.global?.controls?.buttonBorderRadius??8,min:0,max:24,unit:"px",onChange:e=>d({controls:{buttonBorderRadius:e}}),onReset:()=>d({controls:{buttonBorderRadius:null}})}),t.jsx(Aa,{label:"Progress Bar Height",value:l?.templateData?.appearance?.global?.controls?.progressBarHeight??8,min:2,max:20,unit:"px",onChange:e=>d({controls:{progressBarHeight:e}}),onReset:()=>d({controls:{progressBarHeight:null}})})]}),t.jsxs(Ua,{title:"Motion",children:[t.jsx($a,{label:"Enable animations",checked:!1!==l?.templateData?.appearance?.global?.motion?.enabled,onChange:e=>d({motion:{enabled:e}})}),!1!==l?.templateData?.appearance?.global?.motion?.enabled&&t.jsx(Aa,{label:"Motion Intensity",value:l?.templateData?.appearance?.global?.motion?.intensity??1,min:.1,max:2,step:.1,unit:"x",onChange:e=>d({motion:{intensity:e}}),onReset:()=>d({motion:{intensity:null}})})]}),t.jsx("div",{className:"pt-1",children:t.jsx(T,{variant:"error",size:"sm",onClick:u,className:"w-full",children:"Reset All Appearance to Defaults"})})]}),2===g&&t.jsxs("div",{className:"flex flex-col gap-3",children:[t.jsx($a,{label:"Allow Multiple Submissions",checked:ve.allowMultipleSubmissions||!1,onChange:e=>{const t=e;Ne("allowMultipleSubmissions",t),t&&ve.allowResponseEditing&&Ne("allowResponseEditing",!1)}}),t.jsx("p",{className:"text-xs text-gray-400 -mt-2",children:"If enabled, users can submit the form multiple times"}),t.jsx($a,{label:"Allow Response Editing",checked:ve.allowResponseEditing||!1,disabled:ve.allowMultipleSubmissions||!1,onChange:e=>Ne("allowResponseEditing",e)}),t.jsx("p",{className:"text-xs text-gray-400 -mt-2",children:ve.allowMultipleSubmissions?"Disable multiple submissions to enable response editing.":"If enabled, users with an existing response can edit it instead of submitting again."}),t.jsx(Oa,{label:"Duplicate Submission Message Title",helperText:"Shown when users cannot submit another response.",children:t.jsx("input",{type:"text",value:ve.duplicateSubmissionMessageTitle||"",onChange:e=>Ne("duplicateSubmissionMessageTitle",e.target.value),placeholder:"Response Already Submitted",className:_a})}),t.jsx(Oa,{label:"Duplicate Submission Message Body",helperText:"Creator-customizable message shown instead of technical errors.",children:t.jsx("textarea",{rows:3,value:ve.duplicateSubmissionMessageBody||"",onChange:e=>Ne("duplicateSubmissionMessageBody",e.target.value),placeholder:"You have already submitted this form and multiple submissions are disabled.",className:_a})}),t.jsx($a,{label:"Notify on Response Edit",checked:ve.notifyOnEdit||!1,onChange:e=>Ne("notifyOnEdit",e)}),t.jsx("p",{className:"text-xs text-gray-400 -mt-2",children:"If enabled, submission notifications are sent when a user edits an existing response."}),t.jsx("hr",{className:"border-gray-700/50"}),t.jsx(Oa,{label:"Response Limit",helperText:"Stop accepting responses after this many",children:t.jsx("input",{type:"number",min:1,value:ve.limitResponses||"",onChange:e=>Ne("limitResponses",e.target.value?parseInt(e.target.value):null),placeholder:"Leave empty for unlimited",className:_a})}),t.jsx(Oa,{label:"Close Form At",helperText:"Form will automatically close at this date/time",children:t.jsx("input",{type:"datetime-local",value:ve.closeAt?new Date(ve.closeAt).toISOString().slice(0,16):"",onChange:e=>Ne("closeAt",e.target.value?new Date(e.target.value).toISOString():null),className:_a})}),t.jsx("hr",{className:"border-gray-700/50"}),t.jsx($a,{label:"Enable Creator Timezone for Time Fields",checked:ve.enableCreatorTimezone||!1,onChange:e=>{const t=e;Ne("enableCreatorTimezone",t),t&&!ve.creatorTimeZone&&Ne("creatorTimeZone",je)}}),t.jsx("p",{className:"text-xs text-gray-400 -mt-2",children:"Optional: respondents see local-time previews plus creator timezone conversions for time/date/datetime/availability fields."}),t.jsx(Oa,{label:"Creator Timezone",helperText:"Responses and detail views will show converted values in this timezone when enabled.",children:t.jsx("select",{value:ve.creatorTimeZone||je,disabled:!ve.enableCreatorTimezone,onChange:e=>Ne("creatorTimeZone",e.target.value),className:Ma,children:we.map(e=>t.jsx("option",{value:e,children:e},e))})})]}),3===g&&t.jsxs("div",{className:"flex flex-col gap-4",children:[t.jsx("h4",{className:"text-sm font-semibold text-gray-200",children:"Discord Notifications"}),t.jsx($a,{label:"Notify on New Submission",checked:Ie.notifyOnSubmit||!1,onChange:e=>Ce("notifyOnSubmit",e)}),t.jsx("p",{className:"text-xs text-gray-400 -mt-3",children:"Send a Discord message when someone submits the form"}),Ie.notifyOnSubmit&&t.jsxs("div",{className:"flex flex-col gap-3",children:[t.jsx(sa,{value:
1Ie.discordChannelId||"",onChange:e=>Ce("discordChannelId",e),label:"Notification Channel",helperText:"Channel where notifications will be sent",required:!0}),Ie.discordChannelId&&t.jsxs("div",{children:[t.jsx(T,{variant:"outline",size:"sm",leftIcon:E?t.jsx(Re,{className:"w-3.5 h-3.5 animate-spin"}):t.jsx($e,{className:"w-3.5 h-3.5"}),onClick:async()=>{if(l.id)if(ve.discordChannelId||l.templateData?.notifications?.discordChannelId){P(!0),q(null),_(null);try{const e=await fetch(`/api/forms/${l.id}/test-notification`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include"});if(!e.ok){const t=await e.json();throw new Error(t.error||t.message||"Failed to send test notification")}await e.json(),_("Test notification sent successfully!"),setTimeout(()=>_(null),5e3)}catch(e){console.error("Error sending test notification:",e),q(e.message||"Failed to send test notification")}finally{P(!1)}}else q("Please select a Discord channel first");else q("Form must be saved before sending test notification")},disabled:E||!l.id,className:"w-full",children:E?"Sending...":"Send Test Notification"}),R&&t.jsx(za,{variant:"success",className:"mt-2",children:R}),z&&t.jsx(za,{variant:"error",className:"mt-2",children:z})]}),t.jsx("hr",{className:"border-gray-700/50"}),t.jsx(Oa,{label:"Notification Format",helperText:"embed"===Fe?"Structured Discord embed with fields":"ai"===Fe?"Natural language message composed by AI":"Simple text message with markdown formatting",children:t.jsxs("select",{value:Fe,onChange:e=>Ce("notificationFormat",e.target.value),className:Ma,children:[t.jsx("option",{value:"embed",children:"Rich Embed (Default)"}),t.jsx("option",{value:"ai",children:"AI Composed Message"}),t.jsx("option",{value:"markdown",children:"Plain Markdown"})]})}),t.jsx($a,{label:"Include Share Link in Notification",checked:Ie.includeShareLink||!1,onChange:e=>Ce("includeShareLink",e)}),t.jsx("p",{className:"text-xs text-gray-400 -mt-2",children:"Automatically generates a public share link and includes it in the Discord notification"}),t.jsx(C,{initial:!1,children:"ai"===Fe&&t.jsx(S.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:.2},className:"overflow-hidden",children:t.jsxs("div",{className:"flex flex-col gap-3",children:[t.jsx($a,{label:"Enable AI research mode",checked:Ie.researchFormData||!1,onChange:e=>Ce("researchFormData",e)}),t.jsx("p",{className:"text-xs text-gray-400 -mt-2",children:"Agent will use its tools to research form data (character lookups, web searches) before composing the notification"}),t.jsx(Oa,{label:"Custom AI Instructions (Optional)",helperText:`Custom instructions for the AI agent (${(Ie.customAgentInstructions||"").length}/1000 characters). Leave blank to use default instructions.`,children:t.jsx("textarea",{rows:4,maxLength:1e3,value:Ie.customAgentInstructions||"",onChange:e=>Ce("customAgentInstructions",e.target.value),placeholder:"Add specific instructions for how the AI should format and present this form submission...\n\nExample:\n- Focus on character name and item level\n- Use a friendly, casual tone\n- Include raid role in the summary",className:_a})})]})})}),t.jsx(Oa,{label:"Mention Users/Roles",helperText:"Users or roles to mention in notifications",children:t.jsx(Ha,{members:X,roles:J,value:Ie.notificationMentions||[],loading:G,onChange:e=>Ce("notificationMentions",e)})}),t.jsxs("div",{children:[t.jsxs(T,{variant:"ghost",size:"sm",rightIcon:t.jsx(I,{className:"w-3.5 h-3.5 transition-transform "+(W?"rotate-180":"")}),onClick:()=>V(e=>!e),children:[W?"Hide":"Show"," Custom Message Template"]}),t.jsx(C,{initial:!1,children:W&&t.jsx(S.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:.2},className:"overflow-hidden",children:t.jsxs("div",{className:"mt-2",children:[t.jsx(Oa,{label:"Custom Message Template",helperText:"Available variables: {formName}, {submitterName}, {responseCount}, {submissionTime}",children:t.jsx("textarea",{rows:4,value:Ie.notificationTemplate||"",onChange:e=>Ce("notificationTemplate",e.target.value),placeholder:"New form submission from {submitterName}!\n\nForm: {formName}\nTotal Responses: {responseCount}",className:_a})}),t.jsx("p",{className:"text-xs text-gray-400 mt-1",children:"Leave empty to use default format. This template is used for plain markdown format."})]})})})]}),t.jsx("hr",{className:"border-gray-700/50"}),t.jsx(Oa,{label:"Response Threshold Alert",helperText:"Send an alert when response count reaches this milestone 
1(optional)",children:t.jsx("input",{type:"number",min:1,value:Ie.notifyThreshold||"",onChange:e=>Ce("notifyThreshold",e.target.value?parseInt(e.target.value):null),placeholder:"e.g., 50",className:_a})})]}),t.jsxs(za,{variant:"info",children:[t.jsx("strong",{children:"Tip:"})," Notifications require the Loothing bot to be in your Discord guild and have permission to send messages in the specified channel."]})]}),4===g&&t.jsxs("div",{className:"flex flex-col gap-4",children:[t.jsx("h4",{className:"text-sm font-semibold text-gray-200",children:"Who Can Submit"}),t.jsx(Oa,{label:"Submission Access",helperText:{editors:"Only form editors can view or submit. Use this for drafts and testing.",guild:"Authenticated members of this guild only.",discord:"Anyone with a Discord account can submit. Their Discord identity is captured automatically — no need to ask for it as a form field. Useful for guild applications and external surveys.",public:"Anyone with the link, no login required. Submissions are unattributed unless your form explicitly asks for identity."}[Pe],children:t.jsxs("select",{value:Pe,onChange:e=>(e=>{const t={editors:{visibilityLevel:"private",requireAuth:!1},guild:{visibilityLevel:"guild",requireAuth:!1},discord:{visibilityLevel:"public",requireAuth:!0},public:{visibilityLevel:"public",requireAuth:!1}}[e],{formTemplate:a}=et.getState();et.setState({formTemplate:{...a,visibilityLevel:t.visibilityLevel,templateData:{...a.templateData,settings:{...a.templateData?.settings,requireAuth:t.requireAuth}}},isDirty:!0})})(e.target.value),className:Ma,children:[t.jsx("option",{value:"editors",children:"Editors only — drafts and testing"}),t.jsx("option",{value:"guild",children:"Guild members — must be a member of this guild"}),t.jsx("option",{value:"discord",children:"Discord users — login required, no guild membership"}),t.jsx("option",{value:"public",children:"Anyone — no login required"})]})}),t.jsxs("div",{className:"flex gap-2 text-xs text-gray-400 items-center",children:[t.jsx(_e,{className:"w-3.5 h-3.5"}),t.jsxs("span",{children:["Selected: ",{editors:"Editors only",guild:"Guild members",discord:"Discord users (no guild required)",public:"Anyone (no login)"}[Pe]]})]}),t.jsx("hr",{className:"border-gray-700/50"}),t.jsx("h4",{className:"text-sm font-semibold text-gray-200",children:"Sharing"}),t.jsx(Oa,{label:"Response Visibility",helperText:Le&&"private"!==Le?"guild"===Le?"Responses can be shared with any logged-in guild member.":"Responses can be shared publicly without requiring login.":"Responses can only be viewed by users with the appropriate permission.",children:t.jsxs("select",{value:Le||"private",onChange:e=>{const{formTemplate:t}=et.getState();et.setState({formTemplate:{...t,templateData:{...t.templateData,settings:{...t.templateData?.settings,responseVisibility:e.target.value}}},isDirty:!0})},className:Ma,children:[t.jsx("option",{value:"private",children:"Private — Only users with forms.view_responses permission"}),t.jsx("option",{value:"guild",children:"Guild — Any authenticated guild member with share link"}),t.jsx("option",{value:"public",children:"Public — Anyone with share link (no login required)"})]})}),t.jsx(Oa,{label:"Form URL Slug",helperText:`Form URL: /forms/${x?.name||"guild"}/${l.formSlug||"form-slug"}`,children:t.jsx("input",{type:"text",value:l.formSlug||"",onChange:e=>{const{formTemplate:t}=et.getState();et.setState({formTemplate:{...t,formSlug:e.target.value},isDirty:!0})},placeholder:"my-form-slug",className:_a})}),l.id&&t.jsxs(t.Fragment,{children:[t.jsx("hr",{className:"border-gray-700/50"}),t.jsx("h4",{className:"text-sm font-semibold text-gray-200",children:"Form Slugs"}),p&&t.jsxs(za,{variant:"warning",children:[t.jsx("strong",{children:"Important:"}),' You must save the form (using the "Save Form" button in the main editor) before creating additional slugs. Any visibility changes will not take effect until saved.']}),t.jsx(na,{formId:l.id,guildSlug:x?.slug})]}),t.jsxs(za,{variant:"info",children:[t.jsx("strong",{children:"Tip:"})," Create multiple slugs to track different distribution channels (e.g., Discord, Twitter, Reddit). Each slug shows separate view and submission counts."]})]})]})};function Ha({members:a=[],roles:l=[],value:s=[],onChange:i,loading:n}){const[r,o]=e.useState(""),[c,d]=e.useState(!1),m=e.useRef(null);e.useEffect(()=>{if(!c)return;const e=e=>{m.current&&!m.current.contains(e.target)&&d(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[c]);const u=e.useMemo(()=>[...a.map(e=>({...e,_kind:"Members"})),...l.map(e=>({...e,_kind:"Roles"}))],[a,l]),p=e.useMemo(()=>{const e=r.toLowerCase().trim();return e?u.filter(t=>
1[t.name,t.displayName,t.username].filter(Boolean).join(" ").toLowerCase().includes(e)):u},[u,r]),x=e=>s.some(t=>t.id===e.id);return t.jsxs("div",{className:"relative",ref:m,children:[t.jsxs("div",{className:"flex flex-wrap gap-1.5 min-h-[44px] p-2 bg-gray-800/50 border border-gray-700/50 rounded-lg cursor-text",onClick:()=>d(!0),children:[s.map(e=>t.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium border "+("role"===e.type?"border-pink-500/60 bg-pink-900/20 text-pink-200":"border-gray-600 bg-gray-700/40 text-gray-200"),children:[e.name,t.jsx("button",{type:"button",onClick:t=>{var a;t.stopPropagation(),a=e.id,i(s.filter(e=>e.id!==a))},className:"hover:text-white","aria-label":`Remove ${e.name}`,children:t.jsx(E,{className:"w-3 h-3"})})]},e.id)),t.jsx("input",{type:"text",value:r,onChange:e=>{o(e.target.value),d(!0)},onFocus:()=>d(!0),placeholder:0===s.length?"Search users or roles...":"",className:"flex-1 min-w-[120px] bg-transparent text-sm text-gray-200 placeholder-gray-500 focus:outline-hidden"}),n&&t.jsx(Re,{className:"w-4 h-4 animate-spin text-gray-400 self-center"})]}),c&&p.length>0&&t.jsx("div",{className:"absolute z-50 mt-1 w-full max-h-64 overflow-y-auto rounded-lg border border-gray-700/50 bg-gray-800/95 backdrop-blur-xs shadow-2xl",children:["Members","Roles"].map(e=>{const a=p.filter(t=>t._kind===e);return 0===a.length?null:t.jsxs("div",{children:[t.jsx("div",{className:"px-3 py-1 text-xs font-semibold text-gray-400 bg-gray-900/50 sticky top-0",children:e}),a.map(e=>{const a=x(e);return t.jsxs("button",{type:"button",onClick:()=>(e=>{x(e)?i(s.filter(t=>t.id!==e.id)):i([...s,{type:e.type,id:e.id,name:e.name||e.displayName||e.username||"Unknown"}])})(e),className:"w-full text-left px-3 py-2 text-sm flex items-center justify-between transition-colors "+(a?"bg-(--theme-primary-color,#bb86fc)/20 text-(--theme-primary-color,#bb86fc)":"text-gray-200 hover:bg-gray-700/60"),children:[t.jsx("span",{children:e.name||e.displayName||e.username}),a&&t.jsx(B,{className:"w-4 h-4"})]},e.id)})]},e)})})]})}const qa=(e=[])=>(e||[]).filter(e=>e&&e.id&&!e.deleted),Wa=(e=[])=>(e||[]).filter(e=>e&&e.id&&!e.deleted).map(e=>({...e,fields:qa(e.fields)}));function Va(e){if(!e||"object"!=typeof e)return e;const t={...e};return Array.isArray(t.sections)&&(t.sections=Wa(t.sections)),Array.isArray(t.pages)&&(t.pages=t.pages.filter(e=>e&&e.id&&!e.deleted).map(e=>({...e,sections:Wa(e.sections)}))),t}function Ga(e){return e&&"object"==typeof e?{...e,templateData:Va(e.templateData)}:e}function Ya(){return t.jsx("span",{className:"ml-0.5 text-red-400",children:"*"})}function Ka({label:e,required:a,description:l}){return t.jsxs("div",{className:"mb-1.5",children:[t.jsxs("p",{className:"text-sm font-medium text-gray-200",children:[e,a&&t.jsx(Ya,{})]}),l&&t.jsx("p",{className:"text-xs text-gray-400 mt-0.5",children:l})]})}function Xa({field:e,hint:a}){return t.jsxs("div",{children:[t.jsx(Ka,{label:e.label,required:e.required,description:e.description||a}),t.jsx("input",{type:"text",placeholder:e.placeholder||a,disabled:!0,className:"\n          w-full rounded-lg border border-gray-700 bg-gray-800/50\n          px-4 py-3 text-sm text-gray-200 placeholder-gray-500\n          opacity-60 cursor-not-allowed\n        "})]})}function Qa({value:e,onChange:a,max:l=5}){return t.jsx("div",{className:"flex items-center gap-1",children:Array.from({length:l},(l,s)=>{const i=s+1,n=i<=(e||0);return t.jsx("button",{type:"button",onClick:()=>a(i),className:"p-0.5 text-yellow-400 hover:scale-110 transition-transform","aria-label":`Rate ${i}`,children:t.jsx(R,{className:"h-6 w-6 "+(n?"fill-current":"fill-none stroke-current opacity-50")})},i)})})}function Za({value:e,onChange:a,min:l=1,max:s=10}){const i=e??l;return t.jsxs("div",{children:[t.jsx("input",{type:"range",min:l,max:s,step:1,value:i,onChange:e=>a(parseInt(e.target.value,10)),className:"w-full accent-(--theme-primary-color,#bb86fc)"}),t.jsxs("div",{className:"mt-1 flex justify-between text-xs text-gray-500",children:[t.jsx("span",{children:l}),t.jsx("span",{className:"text-gray-200 font-medium",children:i}),t.jsx("span",{children:s})]})]})}const Ja=({field:e,value:a,onChange:l,isVisible:s})=>{if(!s)return null;switch(e.type){case"text":return t.jsx(oe,{label:e.label,required:e.required,placeholder:e.placeholder,value:a||"",onChange:t=>l(e.id,t.target.value),helperText:e.description});case"textarea":return t.jsx(ce,{label:e.label,required:e.required,placeholder:e.placeholder,value:a||"",onChange:t=>l(e.id,t.target.value),helperText:e.description,rows:4});case"number":return t.jsx(oe,{type:"number",label:e.label,required:e.required,value:a||"",onChange:t=>l(e.id,t.target.value),helperText:e.description});case"email":return t.jsx(oe,{type:"email",label:e.label,required:e.required,value:a||"",onChange:t=>l(e.id,t.target.value),helperText:e.description});case"url":return t.jsx(oe,{type:"url",label:e.label,required:e.required,value:a||"",onChange:t=>l(e.id,t.target.value),helperText:e.description});case"date":return t.jsx(oe,{type:"date",label:e.label,required:e.required,value:a||"",onChange:t=>l(e.id,t.target.value),helperText:e.description});case"time":return t.jsx(oe,{type:"time",label:e.label,required:e.required,value:a||"",onChange:t=>l(e.id,t.target.value),helperText:e.description});case"datetime":return t.jsx(oe,{type:"datetime-local",label:e.label,required:e.required,value:a||"",onChange:t=>l(e.id,t.target.value),helperText:e.description});case"select":{const s=(e.options||[]).map(e=>({value:e.value,label:e.label}));return t.jsxs("div",{children:[t.jsx(Ka,{label:e.label,required:e.required,description:e.description}),t.jsx(Pe,{options:s,value:a||"",onChange:t=>l(e.id,t),placeholder:"Select an option..."})]})}case"radio":return t.jsxs("div",{children:[t.jsx(Ka,{label:e.label,required:e.required,description:e.description}),t.jsx("div",{className:"flex flex-col gap-2",children:(e.options||[]).map(s=>t.jsxs("label",{className:"flex items-center gap-2 cursor-pointer text-sm text-gray-200",children:[t.jsx("input",{type:"radio",name:e.id,value:s.value,checked:a===s.value,onChange:()=>
1l(e.id,s.value),className:"h-4 w-4 accent-(--theme-primary-color,#bb86fc)"}),t.jsx("span",{children:s.label})]},s.value))})]});case"checkbox":return t.jsxs("div",{children:[t.jsx(Ka,{label:e.label,required:e.required,description:e.description}),t.jsx("div",{className:"flex flex-col gap-2",children:(e.options||[]).map(s=>{const i=Array.isArray(a)?a:[],n=i.includes(s.value);return t.jsxs("label",{className:"flex items-center gap-2 cursor-pointer text-sm text-gray-200",children:[t.jsx("input",{type:"checkbox",checked:n,onChange:t=>{const a=i.slice();t.target.checked?a.push(s.value):a.splice(a.indexOf(s.value),1),l(e.id,a)},className:"h-4 w-4 rounded accent-(--theme-primary-color,#bb86fc)"}),t.jsx("span",{children:s.label})]},s.value)})})]});case"rating":return t.jsxs("div",{children:[t.jsx(Ka,{label:e.label,required:e.required,description:e.description}),t.jsx(Qa,{value:a||0,onChange:t=>l(e.id,t),max:e.maxValue||5})]});case"scale":return t.jsxs("div",{children:[t.jsx(Ka,{label:e.label,required:e.required,description:e.description}),t.jsx(Za,{value:a,onChange:t=>l(e.id,t),min:e.minValue||1,max:e.maxValue||10})]});case"wow_character_battlenet":return t.jsx(Xa,{field:e,hint:"WoW Character search (Battle.net API) — preview only"});case"wow_character_linked":return t.jsx(Xa,{field:e,hint:"User's linked WoW characters — preview only"});case"wow_raiderio_lookup":return t.jsx(Xa,{field:e,hint:"Raider.io M+ score and raid progress lookup — preview only"});case"wow_item_lookup":return t.jsx(Xa,{field:e,hint:"WoW item search — preview only"});case"wow_spell_lookup":return t.jsx(Xa,{field:e,hint:"WoW spell/talent/ability search — preview only"});case"wow_wcl_encounter":return t.jsx(Xa,{field:e,hint:"Warcraft Logs encounter selection — preview only"});case"wow_boss_selection":return t.jsx(m,{field:e,value:a,onChange:l||(()=>{})});case"display_text":return t.jsx(d,{field:e});case"display_image":return t.jsx(c,{field:e});case"display_video":return t.jsx(o,{field:e});case"display_divider":return t.jsx(r,{field:e});default:return null}},el=()=>{const{formTemplate:a,showPreview:l,togglePreview:s,guildBranding:i}=et(),n=e.useMemo(()=>Ga(a),[a]),r=e.useMemo(()=>{const{global:e}=y({guildBranding:i,formAppearance:n?.templateData?.appearance,currentPageId:null,viewerContext:"preview"});return e.accents?.primaryColor||null},[i,n]),[o,c]=e.useState({}),[d,m]=e.useState(0),u=2===Number(n?.templateData?.version),p=n?.templateData?.pages||[],x=n?.templateData?.sections||[],h=u?p[d]:null,f=u&&h?h.sections:x,b=u?p.length:1,v=d>0,j=d<b-1;e.useEffect(()=>{l&&(c({}),m(0))},[l]);const w=(e,t)=>{c(a=>({...a,[e]:t}))},N=()=>u&&h?h.description:n?.description,D=u?(d+1)/b*100:100,k=t.jsxs("div",{className:"flex flex-col min-w-0",children:[t.jsx("span",{className:"truncate",children:"Form Preview"}),u&&t.jsxs("span",{className:"text-xs font-normal text-gray-400",children:["Page ",d+1," of ",b]})]}),I=t.jsxs("div",{className:"flex w-full items-center gap-2",children:[u&&t.jsxs(t.Fragment,{children:[t.jsx(T,{variant:"ghost",onClick:()=>{v&&(m(e=>e-1),window.scrollTo(0,0))},disabled:!v,leftIcon:t.jsx(q,{className:"h-4 w-4"}),children:"Previous"}),t.jsx("div",{className:"flex-1"}),t.jsx(T,{variant:"ghost",onClick:()=>{j&&(m(e=>e+1),window.scrollTo(0,0))},disabled:!j,rightIcon:t.jsx(W,{className:"h-4 w-4"}),children:j?"Next":"Submit"})]}),t.jsx(T,{variant:"outline",onClick:s,className:u?"":"ml-auto",children:u&&d===b-1?"Close":"Close Preview"})]});return t.jsxs(K,{isOpen:l,onClose:s,title:k,size:"lg",footer:I,children:[u&&t.jsx("div",{className:"mb-4 -mx-4 sm:-mx-6 -mt-4 sm:-mt-6 h-2 bg-gray-700/50",children:t.jsx("div",{className:"h-full transition-all duration-300",style:{width:`${D}%`,backgroundColor:r||"var(--theme-primary-color, #bb86fc)"}})}),t.jsx(g,{guildBranding:i,formAppearance:n?.templateData?.appearance,currentPageId:h?.id||null,viewerContext:"preview",children:t.jsxs("div",{className:"mx-auto max-w-2xl flex flex-col gap-4",children:[0===d&&t.jsxs("div",{className:"rounded-xl border border-gray-700/50 bg-gray-800/40 overflow-hidden",style:{padding:"var(--form-surface-padding-y, 24px)",background:"var(--form-surface-bg)"},children:[n?.templateData?.settings?.bannerImage&&t.jsx("div",{className:"-m-6 mb-6",children:t.jsx("img",{src:n.templateData.settings.bannerImage,alt:"Form banner",className:"w-full max-h-[300px] object-cover"})}),t.jsx("h1",{className:"text-xl font-semibold mb-1",style:{color:"var(--form-title-color, inherit)"},children:n?.title}),n?.description&&t.jsx("p",{className:"text-sm",style:{color:"var(--form-description-color, inherit)"},children:n.description})]}),t.jsx(C,{mode:"wait",children:t.jsxs(S.div,{initial:{opacity:0,x:20}
1,animate:{opacity:1,x:0},exit:{opacity:0,x:-20},transition:{duration:.2},className:"flex flex-col gap-4",children:[u&&d>0&&t.jsxs("div",{className:"rounded-xl border border-gray-700/50 bg-gray-800/40 p-4",children:[t.jsx("h2",{className:"text-base font-semibold mb-1",style:{color:"var(--form-title-color, inherit)"},children:u&&h?h.title:n?.title}),N()&&t.jsx("p",{className:"text-sm",style:{color:"var(--form-description-color, inherit)"},children:N()})]}),t.jsx("div",{className:"flex flex-col gap-4",children:f?.filter(e=>e.id&&!e.deleted).map(e=>t.jsxs("div",{className:"rounded-xl border border-gray-700/50 bg-gray-800/40 p-4",children:[t.jsx("h3",{className:"mb-2",style:{fontWeight:"var(--form-section-title-weight, 600)",fontSize:"var(--form-section-title-size, 1.125rem)",color:"var(--form-section-title-color, inherit)"},children:e.title}),e.description&&t.jsx("p",{className:"text-sm mb-3",style:{color:"var(--form-description-color, inherit)"},children:e.description}),t.jsx("div",{className:"flex flex-col gap-3",children:e.fields?.filter(e=>e.id&&!e.deleted).map(e=>t.jsx(Ja,{field:e,value:o[e.id],onChange:w,isVisible:!0},e.id))})]},e.id))})]},`page-${d}`)}),t.jsx("div",{className:"rounded-lg border border-cyan-700/40 bg-cyan-900/20 p-3 text-center",children:t.jsx("p",{className:"text-xs text-cyan-200",children:"This is a preview. Responses submitted here will not be saved."})})]})})]})},tl="w-full px-3 py-2 bg-gray-800/50 border border-gray-700/50 rounded-lg text-sm text-gray-200 focus:outline-hidden focus:ring-2 focus:ring-(--theme-primary-color,#bb86fc)",al=({open:a,onClose:l})=>{const{formTemplate:s,activeSectionId:i,activePageId:n,editingLogicFieldId:r,updateFieldConditionalLogic:o}=et(),[c,d]=e.useState(null),[m,u]=e.useState("and"),p=(()=>{if(!s?.templateData)return null;if(2===Number(s.templateData.version)){const e=s.templateData.pages?.find(e=>e.id===n);return e?.sections?.find(e=>e.id===i)}return s.templateData.sections?.find(e=>e.id===i)})(),x=p?.fields?.find(e=>e.id===r);if(e.useEffect(()=>{a&&x&&x.showIf?d(x.showIf):a&&d({type:"equals",fieldId:"",value:""})},[a,x]),!x)return null;const h=p?p.fields.filter(e=>e.id&&!e.deleted&&!j(e)).filter(e=>{const t=p.fields.findIndex(e=>e.id===r);return p.fields.findIndex(t=>t.id===e.id)<t}).map(e=>({id:e.id,label:e.label,type:e.type})):[],g=c&&c.fieldId&&("isEmpty"===c.type||c.value);return t.jsx(K,{isOpen:a,onClose:l,title:`Show "${x.label}" if...`,size:"default",footer:t.jsxs(t.Fragment,{children:[t.jsx(T,{variant:"ghost",onClick:l,children:"Cancel"}),t.jsx(T,{variant:"primary",onClick:()=>{c&&c.fieldId&&""!==c.value&&(o(i,r,c),l())},disabled:!g,children:"Apply Logic"})]}),children:0===h.length?t.jsxs("div",{className:"flex items-start gap-2 p-3 rounded-lg bg-cyan-900/20 border border-cyan-700/40 text-cyan-200 text-sm",children:[t.jsx(L,{className:"w-4 h-4 shrink-0 mt-0.5"}),t.jsx("p",{children:"No previous fields available. Add other fields before this one to set up conditional logic."})]}):t.jsxs("div",{className:"flex flex-col gap-4",children:[t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm font-medium text-gray-300 mb-1",children:"Condition"}),t.jsxs("select",{value:c?.type||"equals",onChange:e=>d({...c,type:e.target.value}),className:tl,children:[t.jsx("option",{value:"equals",children:"Equals"}),t.jsx("option",{value:"notEquals",children:"Does not equal"}),t.jsx("option",{value:"contains",children:"Contains"}),t.jsx("option",{value:"greaterThan",children:"Greater than"}),t.jsx("option",{value:"lessThan",children:"Less than"}),t.jsx("option",{value:"in",children:"Is one of"}),t.jsx("option",{value:"isEmpty",children:"Is empty"})]})]}),t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm font-medium text-gray-300 mb-1",children:"Which field?"}),t.jsxs("select",{value:c?.fieldId||"",onChange:e=>d({...c,fieldId:e.target.value}),className:tl,children:[t.jsx("option",{value:"",children:"Select a field..."}),h.map(e=>t.jsxs("option",{value:e.id,children:[e.label," (",e.type,")"]},e.id))]})]}),"isEmpty"!==c?.type&&t.jsxs("div",{children:[t.jsx("label",{className:"block text-sm font-medium text-gray-300 mb-1",children:"Value"}),t.jsx("input",{type:"text",value:c?.value||"",onChange:e=>d({...c,value:e.target.value}),placeholder:"What value should match?",className:"w-full px-3 py-2 bg-gray-800/50 border border-gray-700/50 rounded-lg text-sm text-gray-200 placeholder-gray-500 focus:outline-hidden focu
1s:ring-2 focus:ring-(--theme-primary-color,#bb86fc)"})]}),t.jsxs("div",{children:[t.jsx("p",{className:"text-sm font-semibold text-gray-200 mb-2",children:"Logic Operator"}),t.jsx("div",{className:"flex flex-col gap-2",children:[{v:"and",label:"AND - All conditions must be true"},{v:"or",label:"OR - Any condition can be true"}].map(e=>t.jsxs("label",{className:"flex items-center gap-2 text-sm text-gray-300 cursor-pointer",children:[t.jsx("input",{type:"radio",name:"combinator",value:e.v,checked:m===e.v,onChange:()=>u(e.v),className:"h-4 w-4 border-gray-600 bg-gray-800 text-(--theme-primary-color,#bb86fc) focus:ring-(--theme-primary-color,#bb86fc)"}),e.label]},e.v))})]}),c&&c.fieldId&&t.jsxs("div",{className:"p-3 rounded-lg bg-gray-800/50 border border-gray-700/40",children:[t.jsxs("p",{className:"text-xs text-gray-400",children:["This field will be ",t.jsx("strong",{children:"shown"})," when:"]}),t.jsxs("p",{className:"mt-1 text-sm text-gray-200",children:[h.find(e=>e.id===c.fieldId)?.label||"?"," ",c.type," ","isEmpty"!==c.type&&`"${c.value}"`]})]})]})})},ll="inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium border";function sl({children:e,variant:a="info",icon:l}){const s=l||("warning"===a?A:L);return t.jsxs("div",{className:`flex items-start gap-2 p-3 rounded-lg border text-sm ${{info:"bg-cyan-900/20 border-cyan-700/40 text-cyan-200",warning:"bg-yellow-900/20 border-yellow-700/40 text-yellow-200"}[a]}`,children:[t.jsx(s,{className:"w-4 h-4 shrink-0 mt-0.5"}),t.jsx("div",{className:"flex-1",children:e})]})}function il({open:a,onClose:l,currentPage:s,allPages:n=[],sections:r=[],onSave:o}){const[c,d]=e.useState(s?.navigationRules?.conditionalNext||[]),[m,u]=e.useState(null),[p,x]=e.useState(null),[h,g]=e.useState(""),f=e.useMemo(()=>r&&0!==r.length?St(r,{includeFromOtherSections:!0}):[],[r]),b=e.useMemo(()=>n&&0!==n.length?n.filter(e=>e.id!==s?.id):[],[n,s]),y=e.useMemo(()=>{const e=new Set;s?.navigationRules?.nextPage&&e.add(s.navigationRules.nextPage),c.forEach(t=>e.add(t.targetPage));const t=n.findIndex(e=>e.id===s?.id);return n.slice(t+1).filter(t=>!e.has(t.id)).map(e=>e.title||`Page ${n.indexOf(e)+1}`)},[s,n,c]);return t.jsx(K,{isOpen:a,onClose:l,size:"xl",title:t.jsxs("span",{children:["Conditional Page Navigation",t.jsxs("span",{className:"block text-sm font-normal text-gray-400 mt-0.5",children:["Page: ",s?.title||"Untitled Page"]})]}),footer:t.jsxs(t.Fragment,{children:[t.jsx(T,{variant:"ghost",onClick:l,children:"Cancel"}),t.jsx(T,{variant:"primary",onClick:()=>{const e=[];c.forEach((t,a)=>{const l=Ct(t.condition,f);l.valid||e.push(`Rule ${a+1}: ${l.errors.join(", ")}`)}),e.length>0?i.error(`Validation errors: ${e.join(" | ")}`):(o({...s?.navigationRules||{},conditionalNext:c}),l())},children:"Save Navigation Rules"})]}),children:t.jsxs("div",{className:"flex flex-col gap-4",children:[null!==p&&t.jsxs("div",{className:"rounded-lg border-2 border-(--theme-primary-color,#bb86fc) bg-(--theme-primary-color,#bb86fc)/10 p-3",children:[t.jsx("h4",{className:"text-base font-semibold text-gray-200 mb-3",children:null!==m?"Edit Rule":"Add New Rule"}),t.jsxs("div",{className:"mb-3",children:[t.jsx("p",{className:"text-sm font-semibold text-gray-300 mb-2",children:"IF:"}),t.jsx(Lt,{conditionGroup:p,availableFields:f,onChange:x,allowNesting:!0,showNotToggle:!0})]}),t.jsxs("div",{className:"mb-3",children:[t.jsx("p",{className:"text-sm font-semibold text-gray-300 mb-2",children:"THEN navigate to:"}),t.jsxs("select",{value:h,onChange:e=>g(e.target.value),className:"w-full px-3 py-2 bg-gray-800/50 border border-gray-700/50 rounded-lg text-sm text-gray-200 focus:outline-hidden focus:ring-2 focus:ring-(--theme-primary-color,#bb86fc)",children:[t.jsx("option",{value:"",children:"Select target page..."}),b.map(e=>t.jsx("option",{value:e.id,children:e.title||`Page ${n.indexOf(e)+1}`},e.id))]})]}),t.jsxs("div",{className:"flex gap-2 justify-end",children:[t.jsx(T,{variant:"outline",size:"sm",onClick:()=>{x(null),g(""),u(null)},children:"Cancel"}),t.jsx(T,{variant:"primary",size:"sm",onClick:()=>{if(!p||!h)return;const e={condition:p,targetPage:h};if(null!==m){const t=[...c];t[m]=e,d(t)}else d([...c,e]);x(null),g(""),u(null)},disabled:!h,children:null!==m?"Update Rule":"Add Rule"})]})]}),t.jsxs("div",{children:[t.jsxs("div",{className:"mb-3 flex items-center justify-between",children:[t.jsxs("h4",{className:"text-base font-semibold text-gray-200",children:["Navigation Rules (",c.length,")"]}),t.jsx(T,{variant:"primary",size:"sm",leftIcon:t.jsx(X,{className:"w-3.5 h-3.5"}),onClick:()=>{x(vt("and")),g(""),u(null)},disabled:null!==p,children:"Add Rule"})]}),0===c.length?t.jsx(sl,{children:"No conditional navigation rules. Page will navigate sequentially to the next page."}):t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"mb-2",children:t.jsx(sl,{children:"Rules are evaluated in order. First matching rule determines the next page."})}),t.jsx("ul",{className:"flex flex-col gap-2",children:c.map((e,a)=>{const l=n.find(t=>
1t.id===e.targetPage),s=l?.title||`Page ${n.indexOf(l)+1}`;return t.jsxs("li",{className:"flex items-center gap-3 p-3 rounded-lg border border-gray-700/50 bg-gray-800/40",children:[t.jsxs("div",{className:"flex flex-col items-center gap-1",children:[t.jsx("span",{className:`${ll} border-(--theme-primary-color,#bb86fc) bg-(--theme-primary-color,#bb86fc)/20 text-(--theme-primary-color,#bb86fc) font-bold`,children:a+1}),t.jsxs("div",{className:"flex flex-col",children:[t.jsx("button",{type:"button",onClick:()=>(e=>{if(0===e)return;const t=[...c];[t[e-1],t[e]]=[t[e],t[e-1]],d(t)})(a),disabled:0===a,className:"p-0.5 rounded hover:bg-gray-700/50 text-gray-400 hover:text-gray-200 disabled:opacity-30 disabled:cursor-not-allowed","aria-label":"Move up",children:t.jsx(Z,{className:"w-3.5 h-3.5"})}),t.jsx("button",{type:"button",onClick:()=>(e=>{if(e===c.length-1)return;const t=[...c];[t[e],t[e+1]]=[t[e+1],t[e]],d(t)})(a),disabled:a===c.length-1,className:"p-0.5 rounded hover:bg-gray-700/50 text-gray-400 hover:text-gray-200 disabled:opacity-30 disabled:cursor-not-allowed","aria-label":"Move down",children:t.jsx(J,{className:"w-3.5 h-3.5"})})]})]}),t.jsxs("div",{className:"flex-1 min-w-0 flex items-center gap-2 flex-wrap",children:[t.jsx(_t,{condition:e.condition,fields:f}),t.jsx(Ue,{className:"w-4 h-4 text-gray-400 shrink-0"}),t.jsx("span",{className:`${ll} border-pink-500/60 bg-pink-900/20 text-pink-200`,children:s})]}),t.jsxs("div",{className:"flex gap-1",children:[t.jsx("button",{type:"button",onClick:()=>(e=>{const t=c[e];x(t.condition),g(t.targetPage),u(e)})(a),className:"p-2 rounded hover:bg-gray-700/50 text-gray-400 hover:text-gray-200 transition-colors","aria-label":"Edit rule",children:t.jsx(se,{className:"w-4 h-4"})}),t.jsx("button",{type:"button",onClick:()=>(e=>{d(c.filter((t,a)=>a!==e))})(a),className:"p-2 rounded text-red-400 hover:bg-red-900/20 transition-colors","aria-label":"Delete rule",children:t.jsx(ee,{className:"w-4 h-4"})})]})]},a)})})]})]}),y.length>0&&t.jsxs(sl,{variant:"warning",children:[t.jsx("p",{className:"font-semibold mb-1",children:"Unreachable Pages Detected"}),t.jsxs("p",{children:["The following pages may be unreachable: ",y.join(", ")]})]})]})})}const nl="w-full px-3 py-2 bg-gray-800/50 border border-gray-700/50 rounded-lg text-sm text-gray-200 focus:outline-hidden focus:ring-2 focus:ring-(--theme-primary-color,#bb86fc)",rl="w-full px-3 py-2 bg-gray-800/50 border border-gray-700/50 rounded-lg text-sm text-gray-200 placeholder-gray-500 focus:outline-hidden focus:ring-2 focus:ring-(--theme-primary-color,#bb86fc)",ol="inline-flex items-center px-2 py-0.5 rounded-full text-[10px] font-medium border";function cl({children:e}){return t.jsx("label",{className:"block text-xs font-medium text-gray-400 mb-1",children:e})}function dl({label:e,checked:a,onChange:l}){return t.jsxs("div",{className:"flex items-center justify-between gap-3 cursor-pointer",onClick:()=>l(!a),children:[t.jsx("span",{className:"text-sm text-gray-300 select-none",children:e}),t.jsx("span",{onClick:e=>e.stopPropagation(),className:"contents",children:t.jsx(ne,{checked:a,onChange:l,size:"sm"})})]})}const ml=()=>{const{formTemplate:a,activePageId:l,setActivePage:s,addPage:i,removePage:n,updatePageSettings:r,updatePageNavigation:o,updateFormAppearancePage:c,resetPageAppearance:d}=et(),[m,u]=e.useState(null),[p,x]=e.useState(null),[h,g]=e.useState(null),f=2===Number(a.templateData?.version),b=f&&a.templateData?.pages||[],y=a.templateData?.sections||[],v=[{value:"slide-horizontal",label:"Slide Horizontal"},{value:"slide-vertical",label:"Slide Vertical"},{value:"fade",label:"Fade"}];return f?t.jsxs("div",{className:"rounded-xl glass-card p-4",children:[t.jsx("div",{className:"mb-3 flex items-center justify-between",children:t.jsxs("h3",{className:"text-base font-semibold text-gray-200",children:["Pages (",b.length,")"]})}),t.jsx("div",{className:"flex flex-col gap-2",children:b.map((e,i)=>{const n=p===e.id,m=l===e.id;return t.jsxs("div",{className:"rounded-lg overflow-hidden "+(m?"border-2 border-(--theme-primary-color,#bb86fc) bg-(--theme-primary-color,#bb86fc)/5":"border border-gray-700/50 bg-gray-800/30"),children:[t.jsxs("button",{type:"button",onClick:()=>x(n?null:e.id),className:"w-full flex items-center gap-2 px-3 py-2 text-left hover:bg-gray-700/30 transition-colors",children:[t.jsx(te,{className:"w-4 h-4 text-gray-500 cursor-grab"}),t.jsxs("span",{className:`${ol} ${m?"border-(--theme-primary-color,#bb86fc) text-(--theme-primary-color,#bb86fc)":"border-gray-700/60 text-gray-400"}`,children:["Page ",i+1]}),t.jsx("span",{className:"flex-1 truncate text-sm "+(m?"font-semibold text-gray-100":"text-gray-300"),children:e.title||`Page ${i+1}`}),m&&t.jsx("span",{className:`${ol} border-(--theme-primary-color,#bb86fc) bg-(--theme-primary-color,#bb86fc)/20 text-(--theme-primary-color,#bb86fc)`,children:"Active"}),t.jsx(I,{className:"w-4 h-4 text-gray-400 transition-transform "+(n?"rotate-180":"")})]}),t.jsx(C,{initial:!1,children:n&&t.jsx(S.div,{initial:{height:0,opacity:0}
1,animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:.2},className:"overflow-hidden",children:t.jsxs("div",{className:"px-3 pb-3 pt-1 flex flex-col gap-3 border-t border-gray-700/40",children:[t.jsxs("div",{children:[t.jsx(cl,{children:"Page Title"}),t.jsx("input",{type:"text",value:e.title||"",onChange:t=>r(e.id,{title:t.target.value}),onClick:e=>e.stopPropagation(),className:rl})]}),t.jsx(dl,{label:"Hide Title",checked:!!e.hideTitle,onChange:()=>r(e.id,{hideTitle:!e.hideTitle})}),t.jsxs("div",{children:[t.jsx(cl,{children:"Page Description"}),t.jsx("textarea",{rows:2,value:e.description||"",onChange:t=>r(e.id,{description:t.target.value}),onClick:e=>e.stopPropagation(),className:rl})]}),e.description&&t.jsx(dl,{label:"Hide Description",checked:!!e.hideDescription,onChange:()=>r(e.id,{hideDescription:!e.hideDescription})}),t.jsx("hr",{className:"border-gray-700/50"}),t.jsx("p",{className:"text-sm font-semibold text-gray-300",children:"Page Transition"}),t.jsxs("div",{children:[t.jsx(cl,{children:"Transition Type"}),t.jsx("select",{value:e.transitionType||"slide-horizontal",onChange:t=>r(e.id,{transitionType:t.target.value}),className:nl,children:v.map(e=>t.jsx("option",{value:e.value,children:e.label},e.value))})]}),t.jsxs("div",{children:[t.jsx(cl,{children:"Transition Duration (ms)"}),t.jsx("input",{type:"number",min:100,max:2e3,step:50,value:e.transitionDuration||300,onChange:t=>{const a=Math.min(Math.max(parseInt(t.target.value)||300,100),2e3);r(e.id,{transitionDuration:a})},onClick:e=>e.stopPropagation(),className:rl}),t.jsx("p",{className:"mt-1 text-xs text-gray-500",children:"Between 100-2000ms"})]}),t.jsx("hr",{className:"border-gray-700/50"}),t.jsx("p",{className:"text-sm font-semibold text-gray-300",children:"Navigation Options"}),t.jsx(dl,{label:"Show Progress Bar",checked:!1!==e.showProgressBar,onChange:t=>r(e.id,{showProgressBar:t})}),t.jsx(dl,{label:"Allow Back Navigation",checked:!1!==e.allowBack,onChange:t=>r(e.id,{allowBack:t})}),i<b.length-1&&t.jsxs("div",{children:[t.jsx(cl,{children:"Next Page"}),t.jsxs("select",{value:e.navigationRules?.nextPage||"sequential",onChange:t=>{const a="sequential"===t.target.value?null:t.target.value;o(e.id,{nextPage:a})},className:nl,children:[t.jsxs("option",{value:"sequential",children:["Sequential (Page ",i+2,")"]}),b.filter((e,t)=>t>i).map((e,a)=>t.jsxs("option",{value:e.id,children:["Jump to Page ",i+a+2,": ",e.title||"Untitled"]},e.id))]})]}),i<b.length-1&&t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-center justify-between mb-1",children:[t.jsx("span",{className:"text-sm text-gray-400",children:"Conditional Navigation"}),t.jsx(T,{variant:e.navigationRules?.conditionalNext?.length>0?"primary":"outline",size:"sm",leftIcon:t.jsx(Ke,{className:"w-3.5 h-3.5"}),onClick:()=>g(e.id),children:e.navigationRules?.conditionalNext?.length>0?`${e.navigationRules.conditionalNext.length} Rules`:"Add Rules"})]}),e.navigationRules?.conditionalNext?.length>0&&t.jsxs("div",{className:"flex items-start gap-2 p-2 rounded-lg bg-cyan-900/20 border border-cyan-700/40 text-cyan-200 text-xs",children:[t.jsx(L,{className:"w-3.5 h-3.5 shrink-0 mt-0.5"}),t.jsxs("span",{children:["This page has ",e.navigationRules.conditionalNext.length," conditional navigation"," ",1===e.navigationRules.conditionalNext.length?"rule":"rules"]})]})]}),t.jsx("hr",{className:"border-gray-700/50"}),t.jsx("p",{className:"text-sm font-semibold text-gray-300",children:"Page Appearance"}),t.jsx(dl,{label:"Override global appearance for this page",checked:Boolean(a?.templateData?.appearance?.pageOverrides?.[e.id]),onChange:t=>
1{t?c(e.id,{pageBackground:{type:"none"}}):d(e.id)}}),Boolean(a?.templateData?.appearance?.pageOverrides?.[e.id])&&t.jsxs("div",{className:"flex flex-col gap-2 pl-2",children:[t.jsx(Pa,{value:a?.templateData?.appearance?.pageOverrides?.[e.id]?.pageBackground||{},onChange:t=>c(e.id,{pageBackground:t})}),(()=>{const l=a?.templateData?.appearance?.pageOverrides?.[e.id];return[["Title Color","formTitleColor"],["Body Text Color","bodyColor"],["Description Color","descriptionColor"],["Section Title Color","sectionTitleColor"],["Field Label Color","fieldLabelColor"],["Helper Text Color","helperColor"]].map(([a,s])=>t.jsx(Fa,{label:a,value:l?.typography?.[s]||null,onChange:t=>c(e.id,{typography:{[s]:t}}),onReset:()=>c(e.id,{typography:{[s]:null}})},s))})()]}),t.jsx("hr",{className:"border-gray-700/50"}),t.jsxs("div",{className:"flex gap-2",children:[t.jsx(T,{variant:"outline",size:"sm",onClick:()=>s(e.id),className:"flex-1",children:"Edit Page Content"}),b.length>1&&t.jsx(ie,{content:"Delete Page",children:t.jsx("button",{type:"button",onClick:()=>u(e.id),className:"p-2 rounded-md text-red-400 hover:bg-red-900/20 transition-colors","aria-label":"Delete page",children:t.jsx(ee,{className:"w-4 h-4"})})})]})]})})})]},e.id)})}),t.jsx(T,{variant:"outline",leftIcon:t.jsx(X,{className:"w-4 h-4"}),onClick:i,className:"w-full mt-3",children:"Add Page"}),t.jsx(K,{isOpen:Boolean(m),onClose:()=>u(null),title:"Delete Page?",size:"sm",footer:t.jsxs(t.Fragment,{children:[t.jsx(T,{variant:"ghost",onClick:()=>u(null),children:"Cancel"}),t.jsx(T,{variant:"error",onClick:()=>{n(m),u(null),x(null)},children:"Delete"})]}),children:t.jsx("p",{className:"text-gray-300",children:"This will delete the page and all sections and fields within it. This action cannot be undone."})}),h&&b.length>0&&t.jsx(il,{open:Boolean(h),onClose:()=>g(null),currentPage:b.find(e=>e.id===h)||null,allPages:b,sections:(y||[]).filter(e=>e.pageId===h),onSave:e=>{o(h,e),g(null)}})]}):t.jsxs("div",{className:"rounded-xl glass-card p-4",children:[t.jsx("h3",{className:"text-base font-semibold text-gray-200 mb-2",children:"Page Management"}),t.jsxs("div",{className:"flex items-start gap-2 p-3 rounded-lg bg-yellow-900/20 border border-yellow-700/40 text-yellow-200 text-sm mb-3",children:[t.jsx(A,{className:"w-4 h-4 shrink-0 mt-0.5"}),t.jsx("p",{children:"This form uses the legacy single-page format (V1). All sections appear on one page. New forms now default to the multi-page format (V2) which offers more flexibility."})]}),t.jsx("p",{className:"text-xs text-gray-400",children:"Note: To create a single-page experience with the new format, simply use one page with multiple sections."})]})},ul={draft:"border-gray-500/40 bg-gray-700/60 text-gray-200",active:"border-green-700/50 bg-green-900/40 text-green-200",closed:"border-red-700/50 bg-red-900/40 text-red-200"},pl={draft:"DRAFT",active:"LIVE",closed:"CLOSED"};function xl({open:a,onClose:l,anchorRect:s,items:i}){const n=e.useRef(null);if(e.useEffect(()=>{if(!a)return;const e=e=>{n.current&&!n.current.contains(e.target)&&l()},t=e=>{"Escape"===e.key&&l()};return document.addEventListener("mousedown",e),document.addEventListener("keydown",t),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("keydown",t)}},[a,l]),!a||!s)return null;const r={position:"fixed",top:s.bottom+4,right:Math.max(8,window.innerWidth-s.right)};return t.jsx("div",{ref:n,role:"menu",style:r,className:"z-50 min-w-[14rem] rounded-lg border border-gray-700/50 bg-gray-800/95 backdrop-blur-xs supports-backdrop-filter:bg-gray-800/85 shadow-2xl py-1",children:i.map(({key:e,label:a,Icon:s,danger:i,disabled:n,onClick:r})=>t.jsxs("button",{type:"button",role:"menuitem",disabled:n,onClick:()=>{n||(r?.(),l())},className:`\n            w-full flex items-center gap-2 px-3 py-2 text-sm transition-colors text-left\n            ${n?"opacity-40 cursor-not-allowed":"hover:bg-gray-700/50"}\n            ${i?"text-red-300 hover:bg-red-900/20":"text-gray-200"}\n          `,children:[s&&t.jsx(s,{className:"h-4 w-4 flex-shrink-0"}),t.jsx("span",{children:a})]},e))})}const hl=()=>{const a=V(),{formId:l}
1=G(),{formId:i,formTemplate:n,isDirty:r,isSaving:o,activeFieldId:c,showPreview:d,showFormSettings:m,showConditionalLogic:u,history:p,historyIndex:x,initializeForm:h,createNewForm:g,markAsSaved:f,setSaving:b,setGuildBranding:y,togglePreview:v,toggleFormSettings:j,undo:w,redo:N}=et(),[D,k]=e.useState(!1),[I,F]=e.useState(!1),[A,L]=e.useState(null),[P,R]=e.useState(null),[M,O]=e.useState(null),[$,z]=e.useState("pages"),[U,B]=e.useState(0),[q,W]=e.useState(null),[X,Q]=e.useState(null),Z=x>0,J=x<p.length-1,te=function(){const[t,a]=e.useState(()=>!("undefined"==typeof window||!window.matchMedia)&&window.matchMedia("(max-width: 1023.98px)").matches);return e.useEffect(()=>{if("undefined"==typeof window||!window.matchMedia)return;const e=window.matchMedia("(max-width: 1023.98px)"),t=e=>a(e.matches);return e.addEventListener?(e.addEventListener("change",t),()=>e.removeEventListener("change",t)):(e.addListener(t),()=>e.removeListener(t))},[]),t}(),[ae,se]=e.useState(!1);e.useEffect(()=>{const e=new AbortController;return(async()=>{if(l)try{const t=await s.get(`/api/forms/${l}`,{signal:e.signal});t.data.success&&(h(l,t.data.form),y(t.data.guild?.branding||null),t.data.form.primarySlug&&W({slug:t.data.form.primarySlug,isPrimary:!0}),t.data.form.guildSlug&&Q(t.data.form.guildSlug))}catch(t){if("AbortError"===t.name||"CanceledError"===t.name)return void console.log("Form load request cancelled");const e=t.response?.data?.error,a=("object"==typeof e?e?.message:e)||t.message||"Failed to load form";L(a),console.error("Error loading form:",t)}else g()})(),()=>{e.abort()}},[l,h,g,y]);const ie=e.useCallback((e=n)=>{const t=[],a=Va(e?.templateData||{});return(2===Number(a.version)?(a.pages||[]).flatMap((e,t)=>(e.sections||[]).map((a,l)=>({...a,displayName:`Page ${t+1} "${e.title||`Page ${t+1}`}", Section "${a.title||`Section ${l+1}`}"`}))):(a.sections||[]).map((e,t)=>({...e,displayName:`Section "${e.title||`Section ${t+1}`}"`}))).forEach(e=>{e.fields?.filter(e=>e.id).forEach(a=>{if(["select","radio","checkbox","multi-select"].includes(a.type)&&(a.options&&Array.isArray(a.options)&&0!==a.options.length||t.push(`${e.displayName}, Field "${a.label}": ${a.type} fields must have at least one option. Please add options before saving.`)),a.validation&&a.validation.type){const l=["email","url","number","text","regex"];l.includes(a.validation.type)||t.push(`${e.displayName}, Field "${a.label}": Invalid validation type "${a.validation.type}". Must be one of: ${l.join(", ")}`)}})}),t},[n]),ne=e.useCallback(async()=>{try{const e=Ga(n);console.log("[SaveForm] Starting save operation",{storeFormId:i,isDirty:r,formTemplateVersion:n?.templateData?.version,hasPages:Array.isArray(n?.templateData?.pages),pagesCount:n?.templateData?.pages?.length,hasSections:Array.isArray(n?.templateData?.sections),sectionsCount:n?.templateData?.sections?.length}),b(!0),L(null),l&&i&&l!==i&&console.warn("[SaveForm] State mismatch detected!",{urlFormId:l,storeFormId:i,message:"URL and store have different form IDs - using URL as source of truth"});const o=ie(e);if(o.length>0)return console.error("[SaveForm] Validation errors:",o),L(t.jsxs("div",{children:[t.jsx("div",{className:"font-bold mb-2",children:"Please fix the following errors before saving:"}),t.jsx("ul",{className:"m-0 pl-5 list-disc",children:o.map((e,a)=>t.jsx("li",{className:"mb-1",children:e},a))})]})),b(!1),!1;const c=i||l;console.log("[SaveForm] Sending request",{method:c?"PUT":"POST",url:c?`/api/forms/${c}`:"/api/forms",dataSize:JSON.stringify(e).length,storeFormId:i,urlFormId:l,effectiveFormId:c});const d=c?await s.put(`/api/forms/${c}`,e):await s.post("/api/forms",e);if(console.log("[SaveForm] Response received",{success:d.data.success,formId:d.data.form?.id}),d.data.success){if(c)!i&&l&&(console.log("[SaveForm] Syncing store with URL formId",l),h(l,d.data.form));else{const e=d.data.form.id;h(e,d.data.form),a(`/forms/edit/${e}`,{replace:!0})}return f(),R("Form saved successfully"),setTimeout(()=>R(null),3e3),!0}return!1}catch(e){const t=e.response?.data?.error,a=("object"==typeof t?t?.message:t)||e.message||"Failed to save form";return console.error("[SaveForm] Error details:",{status:e.response?.status,statusText:e.response?.statusText,error:a,url:e.config?.url,method:e.config?.method,data:e.config?.data?.substring?.(0,200)}
1),L(a),console.error("Error saving form:",e),!1}finally{b(!1)}},[i,r,n,l,ie,a,h,f,b]);e.useEffect(()=>{if(!r)return;const e=setTimeout(()=>{ne()},3e4);return()=>{clearTimeout(e)}},[r,ne]),e.useEffect(()=>{if(!A)return;const e=setTimeout(()=>L(null),6e3);return()=>clearTimeout(e)},[A]),e.useEffect(()=>{if(!P)return;const e=setTimeout(()=>R(null),3e3);return()=>clearTimeout(e)},[P]),e.useEffect(()=>{const e=e=>{r&&(e.preventDefault(),e.returnValue="")};return window.addEventListener("beforeunload",e),()=>window.removeEventListener("beforeunload",e)},[r]),e.useEffect(()=>{const e=e=>{!e.ctrlKey&&!e.metaKey||"z"!==e.key||e.shiftKey?((e.ctrlKey||e.metaKey)&&"y"===e.key||(e.ctrlKey||e.metaKey)&&e.shiftKey&&"z"===e.key)&&(e.preventDefault(),J&&N()):(e.preventDefault(),Z&&w())};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[Z,J,w,N]),e.useEffect(()=>{c&&(z("field-settings"),te&&se(!0))},[c,te]);const re=e=>{m?(j(),setTimeout(()=>{B(e),j()},10)):(B(e),j())},oe=[];te&&"draft"===n.status&&oe.push({key:"publish",label:"Publish",Icon:$e,disabled:o||!i,onClick:()=>F(!0)}),te&&(oe.push({key:"visibility",label:"Visibility & Sharing",Icon:H,onClick:()=>re(5)}),oe.push({key:"pages-mobile",label:"Pages & Field Settings",Icon:_,onClick:()=>se(!0)})),"active"!==n.status&&"closed"!==n.status||oe.push({key:"view-responses",label:"View Responses",Icon:We,onClick:()=>a(`/forms/${i}/responses`)}),"active"===n.status&&oe.push({key:"close-form",label:"Close Form",Icon:Ve,onClick:async()=>{if(confirm("Close this form? It will stop accepting new responses."))try{await s.post(`/api/forms/${i}/close`),R("Form closed successfully"),window.location.reload()}catch(e){L("string"==typeof e.response?.data?.error?e.response.data.error:"Failed to close form")}}}),"closed"===n.status&&oe.push({key:"reopen-form",label:"Reopen Form",Icon:Me,onClick:async()=>{if(confirm("Reopen this form? It will start accepting responses again."))try{await s.post(`/api/forms/${i}/reopen`),R("Form reopened successfully"),window.location.reload()}catch(e){L("string"==typeof e.response?.data?.error?e.response.data.error:"Failed to reopen form")}}}),"draft"===n.status&&oe.push({key:"delete-draft",label:"Delete Draft",Icon:ee,danger:!0,onClick:async()=>{if(confirm("Delete this draft? This cannot be undone."))try{await s.delete(`/api/forms/${i}`),R("Draft deleted successfully"),a("/tools/forms")}catch(e){L("Failed to delete draft")}}}),oe.push({key:"close-editor",label:"Close Editor",Icon:E,onClick:()=>a("/tools/forms")});const ce=()=>t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"flex border-b border-gray-700/50 bg-gray-900/40",children:[{value:"pages",label:"Pages",Icon:_},{value:"field-settings",label:"Field Settings",Icon:Y}].map(({value:e,label:a,Icon:l})=>{const s=$===e;return t.jsxs("button",{type:"button",onClick:()=>z(e),className:`\n                flex-1 inline-flex items-center justify-center gap-2 px-3 py-3 text-sm font-medium\n                border-b-2 transition-colors\n                ${s?"border-(--theme-primary-color,#bb86fc) text-(--theme-primary-color,#bb86fc) bg-gray-800/40":"border-transparent text-gray-300 hover:text-gray-100 hover:bg-gray-800/30"}\n              `,children:[t.jsx(l,{className:"h-4 w-4"}),a]},e)})}),t.jsxs("div",{className:"flex-1 overflow-y-auto",children:["pages"===$&&t.jsx(ml,{}),"field-settings"===$&&(c?t.jsx(aa,{}):t.jsx("div",{className:"flex items-center justify-center h-full min-h-[200px] p-6",children:t.jsx("p",{className:"text-sm text-gray-400 text-center",children:"Select a field to edit"})}))]})]});return t.jsxs("div",{className:"flex flex-col h-screen bg-gray-900",children:[t.jsxs("div",{className:"sticky top-0 z-30 bg-gray-900/85 backdrop-blur-xs border-b border-gray-700/50",children:[t.jsxs("div",{className:"flex items-center gap-1 lg:gap-2 px-2 lg:px-4 min-h-[56px] lg:min-h-[64px]",children:[t.jsxs("div",{className:"flex-1 flex items-center gap-2 min-w-0 overflow-hidden",children:[t.jsxs("h1",{className:"font-semibold text-gray-100 truncate text-[0.95rem] lg:text-xl",title:n.title||"Untitled Form",children:[n.title||"Untitled Form",r&&t.jsx("span",{className:"text-[0.8em] ml-2 opacity-70","aria-label":"Unsaved changes",children:"*"})]}),t.jsx("span",{className:`\n                inline-flex items-center px-2 py-0.5 rounded-full text-[0.7rem] font-semibold border flex-shrink-0\n                ${ul[n.status]||ul.draft}
1\n              `,children:pl[n.status]||"DRAFT"}),!te&&("active"===n.status||"closed"===n.status)&&n.responseCount>0&&t.jsxs("button",{type:"button",onClick:()=>a(`/forms/${i}/responses`),className:"inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium border border-gray-600/50 text-gray-200 hover:bg-gray-700/50 hover:border-gray-500 transition-colors flex-shrink-0",children:[n.responseCount," response",1!==n.responseCount?"s":""]}),!te&&q&&X&&"public"===n.visibilityLevel&&t.jsxs("button",{type:"button",title:`Public URL: ${window.location.origin}/forms/${X}/${q.slug}`,onClick:()=>{const e=`${window.location.origin}/forms/${encodeURIComponent(X)}/${encodeURIComponent(q.slug)}`;navigator.clipboard.writeText(e),R("Public URL copied to clipboard")},className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-mono border border-gray-600/50 text-gray-200 hover:bg-gray-700/50 hover:border-gray-500 transition-colors flex-shrink-0",children:[t.jsx(ge,{className:"h-3 w-3"}),q.slug]})]}),t.jsx("button",{type:"button",onClick:w,disabled:!Z,title:"Undo (Ctrl+Z)","aria-label":"Undo",className:"p-2 rounded-md text-gray-300 hover:text-gray-100 hover:bg-gray-800 disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-transparent transition-colors",children:t.jsx(Be,{className:"h-4 w-4"})}),t.jsx("button",{type:"button",onClick:N,disabled:!J,title:"Redo (Ctrl+Y)","aria-label":"Redo",className:"p-2 rounded-md text-gray-300 hover:text-gray-100 hover:bg-gray-800 disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-transparent transition-colors",children:t.jsx(He,{className:"h-4 w-4"})}),!te&&t.jsxs(t.Fragment,{children:[t.jsx(T,{variant:"outline",size:"sm",leftIcon:t.jsx(H,{className:"h-4 w-4"}),onClick:async()=>{if("active"===n.status&&"public"===n.visibilityLevel)try{const e=(await s.get(`/api/guilds/${n.guildId}`)).data.slug,t=(await s.get(`/api/forms/${n.id}/slugs`)).data.slugs.find(e=>e.isPrimary);if(!e)return void L("Guild slug not found.");if(!t)return void L("No primary slug found.");window.open(`/forms/${encodeURIComponent(e)}/${encodeURIComponent(t.slug)}`,"_blank")}catch(e){const t=e.response?.data?.error;L(("object"==typeof t?t?.message:t)||"Failed to get form information")}else v()},className:"ml-1",children:"active"===n.status&&"public"===n.visibilityLevel?"Open Public Link":"Preview"}),t.jsx(T,{variant:"outline",size:"sm",leftIcon:t.jsx(Y,{className:"h-4 w-4"}),onClick:()=>re(0),className:"ml-1",children:"Settings"}),t.jsx(T,{variant:"outline",size:"sm",leftIcon:t.jsx(H,{className:"h-4 w-4"}),onClick:()=>re(5),className:"ml-1",children:"Visibility & Sharing"})]}),te&&t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",onClick:()=>v(),title:"Preview","aria-label":"Preview",className:"p-2 rounded-md text-gray-300 hover:text-gray-100 hover:bg-gray-800 transition-colors",children:t.jsx(Ae,{className:"h-4 w-4"})}),t.jsx("button",{type:"button",onClick:()=>re(0),title:"Settings","aria-label":"Settings",className:"p-2 rounded-md text-gray-300 hover:text-gray-100 hover:bg-gray-800 transition-colors",children:t.jsx(Y,{className:"h-4 w-4"})})]}),t.jsx(T,{variant:"success",size:te?"sm":"md",leftIcon:te?void 0:t.jsx(qe,{className:"h-4 w-4"}),onClick:ne,disabled:!r||o,className:"ml-1",children:te?t.jsx(qe,{className:"h-4 w-4"}):o?"Saving...":"Save"}),"draft"===n.status&&!te&&t.jsx(T,{variant:"primary",size:"md",leftIcon:t.jsx($e,{className:"h-4 w-4"}),onClick:()=>F(!0),disabled:o||!i,className:"ml-1",children:"Publish"}),t.jsx("button",{type:"button",onClick:e=>{O(M?null:e.currentTarget.getBoundingClientRect())},title:"More actions","aria-label":"More actions",className:"p-2 rounded-md text-gray-300 hover:text-gray-100 hover:bg-gray-800 transition-colors ml-0.5",children:t.jsx(le,{className:"h-4 w-4"})})]}),o&&t.jsx("div",{className:"h-0.5 w-full bg-gray-800 overflow-hidden",children:t.jsx(S.div,{className:"h-full bg-(--theme-primary-color,#bb86fc)",initial:{x:"-100%"},animate:{x:"100%"},transition:{duration:1.2,ease:"easeInOut",repeat:1/0},style:{width:"40%"}})})]}),t.jsx(xl,{open:Boolean(M),onClose:()=>O(null),anchorRect:M,items:oe}),t.jsxs("div",{className:"flex flex-1 overflow-hidden",children:[t.jsx("div",{className:"flex-1 overflow-y-auto flex flex-col bg-gray-900",children:t.jsx(Wt,{})}),!te&&t.jsx("aside",{className:"w-[350px] flex flex-col border-l border-gray-700/50 bg-gray-800/60",children:ce()}),t.jsx(C,{children:te&&ae&&t.jsxs(t.Fragment,{children:[t.jsx(S.div,{initial:{opacity:0}
1,animate:{opacity:1},exit:{opacity:0},className:"fixed inset-0 bg-black/40 backdrop-blur-xs z-40",onClick:()=>se(!1)}),t.jsxs(S.aside,{initial:{x:"100%"},animate:{x:0},exit:{x:"100%"},transition:{type:"spring",damping:30,stiffness:300},className:"fixed top-0 right-0 bottom-0 w-[85vw] max-w-[380px] bg-gray-800/95 backdrop-blur-xs border-l border-gray-700/50 z-50 flex flex-col",children:[t.jsx("div",{className:"flex items-center justify-end p-2 border-b border-gray-700/50",children:t.jsx("button",{type:"button",onClick:()=>se(!1),className:"p-2 rounded-md text-gray-300 hover:text-gray-100 hover:bg-gray-700/50 transition-colors","aria-label":"Close panel",children:t.jsx(E,{className:"h-4 w-4"})})}),ce()]})]})})]}),t.jsx(C,{children:A&&t.jsx(S.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},exit:{opacity:0,y:20},className:"fixed bottom-4 left-4 z-[60] max-w-md rounded-lg border border-red-700/60 bg-red-900/90 backdrop-blur-xs text-red-100 shadow-2xl",role:"alert",children:t.jsxs("div",{className:"flex items-start gap-3 p-4",children:[t.jsx("div",{className:"flex-1 text-sm",children:A}),t.jsx("button",{type:"button",onClick:()=>L(null),className:"p-1 rounded text-red-200 hover:text-white hover:bg-red-800/50 transition-colors","aria-label":"Dismiss",children:t.jsx(E,{className:"h-4 w-4"})})]})})}),t.jsx(C,{children:P&&t.jsx(S.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},exit:{opacity:0,y:20},className:"fixed bottom-4 left-4 z-[60] max-w-md rounded-lg border border-green-700/60 bg-green-900/90 backdrop-blur-xs text-green-100 shadow-2xl",role:"status",children:t.jsxs("div",{className:"flex items-start gap-3 p-4",children:[t.jsx("div",{className:"flex-1 text-sm",children:P}),t.jsx("button",{type:"button",onClick:()=>R(null),className:"p-1 rounded text-green-200 hover:text-white hover:bg-green-800/50 transition-colors","aria-label":"Dismiss",children:t.jsx(E,{className:"h-4 w-4"})})]})})}),t.jsx(K,{isOpen:D,onClose:()=>k(!1),title:"Discard Changes?",size:"default",footer:t.jsxs("div",{className:"flex justify-end gap-2",children:[t.jsx(T,{variant:"ghost",onClick:()=>k(!1),children:"Keep Changes"}),t.jsx(T,{variant:"error",onClick:()=>{k(!1),a("/tools/forms")},children:"Discard"})]}),children:t.jsx("p",{className:"text-sm text-gray-200",children:"You have unsaved changes. Are you sure you want to discard them?"})}),t.jsx(K,{isOpen:I,onClose:()=>!o&&F(!1),title:"Publish Form?",size:"default",footer:t.jsxs("div",{className:"flex justify-end gap-2",children:[t.jsx(T,{variant:"ghost",onClick:()=>F(!1),disabled:o,children:"Cancel"}),t.jsx(T,{variant:"primary",onClick:async()=>{if(!r||await ne())try{b(!0),L(null),(await s.post(`/api/forms/${i}/publish`)).data.success&&(f(),R("Form published successfully"),F(!1),setTimeout(()=>{a(`/forms/${i}/responses`)},1500))}catch(e){const t=e.response?.data?.error,a=("object"==typeof t?t?.message:t)||e.message||"Failed to publish form";L(a),console.error("Error publishing form:",e)}finally{b(!1)}else F(!1)},disabled:o,children:o?"Publishing...":"Publish"})]}),children:t.jsx("p",{className:"text-sm text-gray-200",children:"Once published, users will be able to submit responses to this form. You can still edit the form after publishing."})}),m&&t.jsx(Ba,{initialTab:U}),d&&t.jsx(el,{}),u&&t.jsx(al,{})]})};export{hl as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.