import{o as e,t}from"./payload-DyKkZIOX.mjs";function n(e){let t=e.createElement(`style`);return t.textContent=`
.bk-form {
  display: grid;
  gap: var(--dt-space-4);
  padding: var(--dt-space-5);
  border: 1px solid var(--dt-border-default);
  border-radius: var(--dt-radius-xl);
  background: linear-gradient(180deg, var(--dt-bg-secondary), var(--dt-bg-primary));
  box-shadow: var(--dt-shadow-sm);
}

.bk-form-group {
  display: grid;
  gap: var(--dt-space-2);
}

.bk-form-label {
  color: var(--dt-text-primary);
  font-size: var(--dt-font-size-sm);
  font-weight: 600;
}

.bk-form-control {
  width: 100%;
  box-sizing: border-box;
  padding: var(--dt-space-3) var(--dt-space-4);
  border: 1px solid var(--dt-border-default);
  border-radius: var(--dt-radius-lg);
  background: var(--dt-bg-primary);
  color: var(--dt-text-primary);
  font: inherit;
}

.bk-form-control:focus {
  outline: 2px solid var(--dt-accent-fg);
  outline-offset: 2px;
}

.bk-form-checkbox {
  display: flex;
  align-items: center;
  gap: var(--dt-space-3);
  color: var(--dt-text-primary);
}

.bk-form-checkbox input {
  width: var(--dt-space-5);
  height: var(--dt-space-5);
  margin: 0;
  accent-color: var(--dt-accent-fg);
}

.bk-form textarea {
  min-height: 8rem;
  resize: vertical;
}

.bk-form-actions {
  display: flex;
  justify-content: flex-end;
}

.bk-form-submit {
  border: 0;
  border-radius: var(--dt-radius-lg);
  padding: var(--dt-space-3) var(--dt-space-5);
  background: var(--dt-accent-fg);
  color: var(--dt-accent-subtle);
  cursor: pointer;
  font: inherit;
  font-weight: 600;
}
`,t}function r(t){return Array.isArray(t)?t.flatMap(t=>typeof t==`string`?[{label:t,value:t}]:e(t)&&typeof t.label==`string`&&typeof t.value==`string`?[{label:t.label,value:t.value}]:[]):[]}function i(t){return!e(t)||!Array.isArray(t.fields)?[]:t.fields.flatMap(t=>!e(t)||typeof t.name!=`string`||typeof t.label!=`string`?[]:[{name:t.name,label:t.label,type:typeof t.type==`string`?t.type:`text`,required:typeof t.required==`boolean`?t.required:!1,placeholder:typeof t.placeholder==`string`?t.placeholder:void 0,default:typeof t.default==`string`?t.default:void 0,options:r(t.options),value:typeof t.value==`string`||typeof t.value==`boolean`?t.value:void 0}])}function a(e){return e.type===`checkbox`?typeof e.value==`boolean`?e.value:!1:typeof e.value==`string`?e.value:typeof e.default==`string`?e.default:``}function o(e,t){let n={};for(let r of t){let t=e.querySelector(`[name="${r.name}"]`);if(t){if(r.type===`checkbox`&&t.tagName===`INPUT`){n[r.name]=t.checked;continue}if(t.tagName===`INPUT`||t.tagName===`TEXTAREA`){n[r.name]=t.value;continue}t.tagName===`SELECT`&&(n[r.name]=t.value)}}return n}function s(e,r={}){let s=i(t(e.ownerDocument));if(s.length===0)return()=>{};let c=e.ownerDocument,l=e.parentElement;if(!l)return()=>{};let u=n(c),d=c.createElement(`form`);d.className=`bk-form`,d.noValidate=!0;for(let e of s){let t=c.createElement(`label`);if(t.className=`bk-form-group`,e.type===`checkbox`){t.className=`bk-form-checkbox`;let n=c.createElement(`input`);n.type=`checkbox`,n.name=e.name,n.checked=!!a(e),e.required&&(n.required=!0);let r=c.createElement(`span`);r.textContent=e.label,t.append(n,r),d.appendChild(t);continue}let n=c.createElement(`span`);if(n.className=`bk-form-label`,n.textContent=e.label,t.appendChild(n),e.type===`select`){let n=c.createElement(`select`);n.className=`bk-form-control`,n.name=e.name,e.required&&(n.required=!0);for(let t of e.options??[]){let r=typeof t==`string`?{label:t,value:t}:t,i=c.createElement(`option`);i.value=r.value,i.textContent=r.label,i.selected=r.value===String(a(e)),n.appendChild(i)}t.appendChild(n),d.appendChild(t);continue}if(e.type===`textarea`){let n=c.createElement(`textarea`);n.className=`bk-form-control`,n.name=e.name,n.value=String(a(e)),e.placeholder&&(n.placeholder=e.placeholder),e.required&&(n.required=!0),t.appendChild(n),d.appendChild(t);continue}let r=c.createElement(`input`);r.className=`bk-form-control`,r.type=e.type||`text`,r.name=e.name,r.value=String(a(e)),e.placeholder&&(r.placeholder=e.placeholder),e.required&&(r.required=!0),t.appendChild(r),d.appendChild(t)}let f=c.createElement(`div`);f.className=`bk-form-actions`;let p=c.createElement(`button`);p.type=`submit`,p.className=`bk-form-submit`,p.textContent=`Submit`,f.appendChild(p),d.appendChild(f);let m=e=>{e.preventDefault(),r.onAction?.(`submit`,JSON.stringify(o(d,s)))};return d.addEventListener(`submit`,m),c.head?.appendChild(u),l.replaceChild(d,e),()=>{d.removeEventListener(`submit`,m),u.remove(),d.parentElement&&d.parentElement.replaceChild(e,d)}}export{s as hydrateForm};