{"version":3,"file":"BqCheckbox-Bkjo4iIg.cjs","names":[],"sources":["../src/components/checkbox/BqCheckbox.ts"],"sourcesContent":["/**\r\n * Checkbox form control.\r\n * @element bq-checkbox\r\n * @prop {string}  label         - Visible label\r\n * @prop {string}  name          - Input name\r\n * @prop {string}  value         - Input value\r\n * @prop {boolean} checked\r\n * @prop {boolean} indeterminate\r\n * @prop {boolean} disabled\r\n * @prop {boolean} required\r\n * @prop {string}  hint\r\n * @fires bq-change - { value: string, checked: boolean }\r\n */\r\nimport type { ComponentDefinition } from '@bquery/bquery/component';\r\nimport { bool, component, html } from '@bquery/bquery/component';\r\nimport { escapeHtml } from '@bquery/bquery/security';\r\nimport { createFormProxy, type FormProxy } from '../../utils/form.js';\r\nimport { getBaseStyles } from '../../utils/styles.js';\r\n\r\ntype BqCheckboxProps = {\r\n  label: string;\r\n  name: string;\r\n  value: string;\r\n  checked: boolean;\r\n  indeterminate: boolean;\r\n  disabled: boolean;\r\n  required: boolean;\r\n  hint: string;\r\n};\r\n\r\nconst definition: ComponentDefinition<BqCheckboxProps> = {\r\n  props: {\r\n    label: { type: String, default: '' },\r\n    name: { type: String, default: '' },\r\n    value: { type: String, default: '' },\r\n    checked: { type: Boolean, default: false },\r\n    indeterminate: { type: Boolean, default: false },\r\n    disabled: { type: Boolean, default: false },\r\n    required: { type: Boolean, default: false },\r\n    hint: { type: String, default: '' },\r\n  },\r\n  styles: `\r\n    ${getBaseStyles()}\r\n    *, *::before, *::after { box-sizing: border-box; }\r\n    :host { display: block; }\r\n    .wrapper { display: flex; flex-direction: column; gap: 0.25rem; }\r\n    .control { display: flex; align-items: flex-start; gap: 0.625rem; cursor: pointer; }\r\n    :host([disabled]) .control { opacity: 0.5; cursor: not-allowed; pointer-events: none; }\r\n    input[type=\"checkbox\"] {\r\n      width: 1.125rem; height: 1.125rem; flex-shrink: 0;\r\n      border: 2px solid var(--bq-border-emphasis,#cbd5e1);\r\n      border-radius: var(--bq-radius-sm,0.25rem);\r\n      background: var(--bq-bg-base,#fff); cursor: pointer;\r\n      accent-color: var(--bq-color-primary-600,#2563eb);\r\n      margin-top: 0.125rem;\r\n    }\r\n    input[type=\"checkbox\"]:focus-visible { outline: 2px solid transparent; box-shadow: var(--bq-focus-ring); }\r\n    .label-text { font-size: var(--bq-font-size-sm,0.875rem); color: var(--bq-text-base,#0f172a); font-family: var(--bq-font-family-sans); line-height: 1.5; }\r\n    .hint { font-size: var(--bq-font-size-sm,0.875rem); color: var(--bq-text-muted,#475569); font-family: var(--bq-font-family-sans); padding-inline-start: 1.75rem; }\r\n  `,\r\n  connected() {\r\n    const self = this;\r\n\r\n    // Form proxy for native <form> participation\r\n    const name = self.getAttribute('name') ?? '';\r\n    const value = self.hasAttribute('checked')\r\n      ? self.getAttribute('value') || 'on'\r\n      : '';\r\n    const disabled = self.hasAttribute('disabled');\r\n    const proxy = createFormProxy(self, name, value, disabled);\r\n    (self as unknown as Record<string, unknown>)['_formProxy'] = proxy;\r\n\r\n    const handler = (e: Event) => {\r\n      const input = e.target as HTMLInputElement | null;\r\n      if (input?.type !== 'checkbox') return;\r\n      if (input.checked) self.setAttribute('checked', '');\r\n      else self.removeAttribute('checked');\r\n      proxy.setValue(input.checked ? self.getAttribute('value') || 'on' : '');\r\n      self.dispatchEvent(\r\n        new CustomEvent('bq-change', {\r\n          detail: {\r\n            value: self.getAttribute('value') ?? '',\r\n            checked: input.checked,\r\n          },\r\n          bubbles: true,\r\n          composed: true,\r\n        })\r\n      );\r\n    };\r\n    (self as unknown as Record<string, unknown>)['_handler'] = handler;\r\n    self.shadowRoot?.addEventListener('change', handler);\r\n  },\r\n  disconnected() {\r\n    const h = (this as unknown as Record<string, unknown>)['_handler'] as\r\n      | EventListener\r\n      | undefined;\r\n    if (h) this.shadowRoot?.removeEventListener('change', h);\r\n    (\r\n      (this as unknown as Record<string, unknown>)['_formProxy'] as\r\n        | FormProxy\r\n        | undefined\r\n    )?.cleanup();\r\n  },\r\n  updated() {\r\n    const input = this.shadowRoot?.querySelector(\r\n      'input'\r\n    ) as HTMLInputElement | null;\r\n    if (input) input.indeterminate = this.hasAttribute('indeterminate');\r\n    const s = this as unknown as Record<string, unknown>;\r\n    const proxy = s['_formProxy'] as FormProxy | undefined;\r\n    if (proxy) {\r\n      proxy.setName(this.getAttribute('name') ?? '');\r\n      proxy.setValue(\r\n        this.hasAttribute('checked') ? this.getAttribute('value') || 'on' : ''\r\n      );\r\n      proxy.setDisabled(this.hasAttribute('disabled'));\r\n    }\r\n  },\r\n  render({ props }) {\r\n    return html`\r\n      <div class=\"wrapper\" part=\"wrapper\">\r\n        <label class=\"control\" part=\"control\">\r\n          <input\r\n            type=\"checkbox\"\r\n            part=\"input\"\r\n            name=\"${escapeHtml(props.name)}\"\r\n            value=\"${escapeHtml(props.value)}\"\r\n            ${bool('checked', props.checked)}\r\n            ${bool('disabled', props.disabled)}\r\n            ${bool('required', props.required)}\r\n          />\r\n          ${props.label\r\n            ? `<span class=\"label-text\" part=\"label\">${escapeHtml(props.label)}${props.required ? '<span class=\"required-mark\" aria-hidden=\"true\"> *</span>' : ''}</span>`\r\n            : ''}\r\n        </label>\r\n        ${props.hint\r\n          ? `<span class=\"hint\" part=\"hint\">${escapeHtml(props.hint)}</span>`\r\n          : ''}\r\n      </div>\r\n    `;\r\n  },\r\n};\r\n\r\ncomponent<BqCheckboxProps>('bq-checkbox', definition);\r\n"],"mappings":";;;;;;AA+IA,2BAAA,EAA2B,eAAe;CAhHxC,OAAO;EACL,OAAO;GAAE,MAAM;GAAQ,SAAS;GAAI;EACpC,MAAM;GAAE,MAAM;GAAQ,SAAS;GAAI;EACnC,OAAO;GAAE,MAAM;GAAQ,SAAS;GAAI;EACpC,SAAS;GAAE,MAAM;GAAS,SAAS;GAAO;EAC1C,eAAe;GAAE,MAAM;GAAS,SAAS;GAAO;EAChD,UAAU;GAAE,MAAM;GAAS,SAAS;GAAO;EAC3C,UAAU;GAAE,MAAM;GAAS,SAAS;GAAO;EAC3C,MAAM;GAAE,M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