{"mappings":"AACA,cAAc,sBAA2B;AAGzC,SAAS,mBAAmB;;;;;;;AAU5B,cAMM,KAAK,oBAAoB,YAAY;CACzC,AACA;CAEA,IAAI,SAAS;CAIb,0BAA0B;CAE1B,UAAU,UAAU,eAAe;CAInC;CAWA,sBAAsB;CAItB,OAAO,WACL,WAAW,UAAU;EACnB;EACA;EACA;QAED;;AAsBL,eAAe;AACf,SAAS","names":[],"sources":["../../../../src/web-components/form/component.ts"],"sourcesContent":["import { godown, htmlSlot, styles } from \"@godown/element\";\nimport { type TemplateResult, css } from \"lit\";\nimport { property } from \"lit/decorators.js\";\n\nimport { GlobalStyle } from \"../../internal/global-style.js\";\n\nconst protoName = \"form\";\n\n/**\n * {@linkcode Form} Gets child element key-value object,\n * which will be nested if the child element is the same as this element.\n *\n * @category form\n */\n@godown(protoName)\n@styles(css`\n  :host {\n    display: block;\n  }\n`)\nclass Form<T = object> extends GlobalStyle {\n  @property()\n  name = \"\";\n\n  get value(): T {\n    return Form.buildValue(this._slot.assignedElements()) as T;\n  }\n\n  nameValue: () => [string, T] = this.namevalue;\n\n  protected render(): TemplateResult<1> {\n    return htmlSlot();\n  }\n\n  reset(): void {\n    this.deepQuerySelectorAll<HTMLElement & { reset?: () => void }>(\"*\").forEach((el) => {\n      if (el.tagName === this.tagName) {\n        return;\n      }\n      if (el.reset) {\n        el.reset();\n      }\n    });\n  }\n\n  namevalue(): [string, T] {\n    return [this.name, this.value];\n  }\n\n  static buildValue(\n    elements: (Element & {\n      name?: string;\n      value?: unknown;\n      namevalue?: () => [string, unknown];\n    })[],\n  ): Record<string, any> {\n    const result = {};\n    for (const el of elements) {\n      if (el.tagName === \"FORM\") {\n        Object.assign(result, Object.fromEntries(new FormData(el as HTMLFormElement).entries()));\n      } else if (el.namevalue) {\n        const [name, value] = el.namevalue();\n        if (name) {\n          result[name] = value;\n        }\n      } else if (el.name && el.value !== undefined) {\n        result[el.name] = el.value;\n      } else if (el.shadowRoot) {\n        for (const slot of el.shadowRoot.querySelectorAll(\"slot\")) {\n          Object.assign(result, this.buildValue(slot.assignedElements()));\n        }\n      }\n    }\n    return result;\n  }\n}\n\nexport default Form;\nexport { Form };\n"],"version":3,"file":"component.d.ts"}