import{html as t}from"lit";import{unsafeHTML as o}from"lit/directives/unsafe-html.js";import{classMap as i}from"lit/directives/class-map.js";import{repeat as e}from"lit/directives/repeat.js";class s{static renderGroupHeader(o){return t`
      <div
        part="group-header"
        class="combobox__group-header"
        role="presentation"
        data-group-id=${o.id}
        style=${`--group-depth:${o.depth}`}
      >
        ${o.prefix?t`<nile-icon
              class="combobox__group-prefix"
              name=${o.prefix}
              size="14"
              method="fill"
            ></nile-icon>`:""}
        <span class="combobox__group-label">${o.label}</span>
      </div>
    `}static renderRowsPlain(o,i,e,r,n,l,a,d,p,c,$,v,b,u,m){return l&&!d&&0===o.length?s.renderNoResults(a,m):t`
      <div
        part="select-options"
        class="combobox__options ${d?"loading":""}"
      >
        <div class="combobox__options-plain" @scroll=${p}>
          ${o.map((t=>"header"===t.kind?s.renderGroupHeader(t):s.renderItem(t.item,i,e,r,n,c,$,v,b,u)))}
        </div>
      </div>
    `}static renderRowsVirtualized(o,i,r,n,l,a,d,p,c,$,v,b,u){return t`
      <div
        part="select-options"
        class="combobox__options ${p?"loading":""}"
      >
        <div style="position:relative;height:${i}px;width:100%;">
          ${e(o,(t=>t.key),(o=>{const i=r[o.index];if(!i)return t``;const e=`position:absolute;top:0;left:0;right:0;transform:translateY(${o.start}px);height:${o.size}px;`;return"header"===i.kind?t`
                  <div style=${e} class="combobox__group-header-slot">
                    ${s.renderGroupHeader(i)}
                  </div>
                `:t`
                <div style=${e}>
                  ${s.renderItem(i.item,n,l,a,d,c,$,v,b,u)}
                </div>
              `}))}
        </div>
      </div>
    `}static renderVirtualizedOptions(o,i,r,n,l,a,d,p,c,$,v,b,u,m){const x=o.length>0?o[0].start:0;return t`
      <div
        part="select-options"
        class="combobox__options ${p?"loading":""}"
      >
        <div style="position:relative;height:${i}px;width:100%;">
          <div style="position:absolute;top:0;left:0;width:100%;transform:translateY(${x}px);">
            ${e(o,(t=>t.key),(t=>{const o=r[t.index];return s.renderMeasuredItem(o,t.index,n,l,a,d,c,v,b,u,m)}))}
          </div>
        </div>
      </div>
    `}static renderPlainOptions(o,i,e,r,n,l,a,d,p,c,$,v,b,u,m){return l&&!d&&0===o.length?s.renderNoResults(a,m):t`
      <div
        part="select-options"
        class="combobox__options ${d?"loading":""}"
      >
        <div class="combobox__options-plain" @scroll=${p}>
          ${o.map((t=>s.renderItem(t,i,e,r,n,c,$,v,b,u)))}
        </div>
      </div>
    `}static renderNoResults(o,i){return t`
      <div part="select-options" class="combobox__options">
        <div part="no-results" class="combobox__no-results">
          <div part="no-results-title" class="combobox__no-results-title">
            ${o||"No result found"}
          </div>
          ${i?t`<div part="no-results-subtitle" class="combobox__no-results-subtitle">${i}</div>`:""}
        </div>
      </div>
    `}static renderNoData(o){return t`
      <div part="select-options" class="combobox__options">
        <div part="no-data" class="combobox__no-results">
          <div part="no-data-title" class="combobox__no-results-title">
            ${o||"No data available"}
          </div>
        </div>
      </div>
    `}static renderMeasuredItem(e,s,r,n,l,a,d,p,c,$,v){if(!e)return t``;const b=a(e),u=l(e),m=e?.disabled||!1,x=e?.className,_=p?p(e):e?.description??"",h=c?c(e):e?.prefix??"",g=$?$(e):e?.suffix??"";let f=!1;return f=n?Array.isArray(r)&&r.some((t=>String(t)===String(b))):String(Array.isArray(r)?r[0]:r)===String(b),t`
      <nile-option
        data-index=${s}
        value=${b}
        .selected=${f}
        .disabled=${m}
        .showCheckbox=${n}
        class=${i({option:v??!1,[x??""]:!!x})}
        .description=${_}
        .isDescriptionEnabled=${v}
      >
        ${o(h)}
        ${d?o(u):u}
        ${o(g)}
      </nile-option>
    `}static renderItem(e,s,r,n,l,a,d,p,c,$){if(!e)return t``;const v=l(e),b=n(e),u=e?.disabled||!1,m=e?.className,x=d?d(e):e?.description??"",_=p?p(e):e?.prefix??"",h=c?c(e):e?.suffix??"";let g=!1;return g=r?Array.isArray(s)&&s.some((t=>String(t)===String(v))):String(Array.isArray(s)?s[0]:s)===String(v),t`
      <nile-option
        value=${v}
        .selected=${g}
        .disabled=${u}
        .showCheckbox=${r}
        class=${i({option:$??!1,[m??""]:!!m})}
        .description=${x}
        .isDescriptionEnabled=${$}
      >
        ${o(_)}
        ${a?o(b):b}
        ${o(h)}
      </nile-option>
    `}static renderVirtualizedGrid(o,i,r,n,l,a,d,p,c,$,v,b,u,m){const x=o.length>0?o[0].start:0,_=m?`repeat(${a}, ${m}px)`:`repeat(${a}, 1fr)`;return t`
      <div
        part="select-options"
        class="combobox__options ${c?"loading":""}"
      >
        <div style="position:relative;height:${i}px;width:${m?"max-content":"100%"};min-width:100%;">
          <div style="position:absolute;top:0;left:0;width:${m?"max-content":"100%"};min-width:100%;transform:translateY(${x}px);">
            ${e(o,(t=>t.key),(o=>{const i=o.index*a,e=r.slice(i,i+a);return t`
                  <div class="combobox__grid-row" style="display:grid;grid-template-columns:${_};gap:4px;">
                    ${e.map((t=>s.renderItem(t,n,l,d,p,$,v,b,u)))}
                  </div>
                `}))}
          </div>
        </div>
      </div>
    `}static renderHorizontalGrid(o,i,r,n,l,a,d,p,c,$,v,b,u,m){const x=o.length>0?o[0].start:0;return t`
      <div
        part="select-options"
        class="combobox__options combobox__options--horizontal ${$?"loading":""}"
      >
        <div style="position:relative;width:${i}px;height:${38*a}px;">
          <div style="position:absolute;top:0;left:0;height:100%;display:flex;transform:translateX(${x}px);">
            ${e(o,(t=>t.key),(o=>{const i=o.index*a,e=r.slice(i,i+a);return t`
                  <div class="combobox__grid-col" style="width:${d}px;flex-shrink:0;display:flex;flex-direction:column;">
                    ${e.map((t=>s.renderItem(t,n,l,p,c,v,b,u,m)))}
                  </div>
                `}))}
          </div>
        </div>
      </div>
    `}static renderAddCustomOption(o,i){return t`
      <nile-option
        value=${o}
        class="combobox__add-option"
        .showCheckbox=${i}
      >
        + Add "${o}"
      </nile-option>
    `}static shouldUseVirtualizer(t,o=1){return o>1||t.length>=5}}export{s as C};
