import{r as e,c as i,h as t,H as o}from"./p-BIwHMk6j.js";const r=class{constructor(t){e(this,t),this.interact=i(this,"interact"),this.type="checkbox",this.fileTypes=["view","contents","download"],this.handleDocumentItemClick=e=>{if(!this.isUnavailable()){if((null==e?void 0:e.target)instanceof HTMLElement&&(e.target.closest("limel-checkbox")||e.target.closest("limel-radio-button")))return;this.toggleSelection()}},this.handleSelectionControlClick=e=>{var i,t;e.stopPropagation(),this.isUnavailable()||"radio"===this.type&&(null===(i=this.item)||void 0===i?void 0:i.selected)&&(e.preventDefault(),this.forceInputUnchecked(e),this.emitSelectionChange(!(null===(t=this.item)||void 0===t?void 0:t.selected)))},this.handleSelectionControlChange=e=>{var i;if(e.stopPropagation(),this.isUnavailable())return;let t;if("detail"in e&&"boolean"==typeof e.detail)t=e.detail;else{const i=e.target;t=!!(null==i?void 0:i.checked)}"radio"!==this.type||!(null===(i=this.item)||void 0===i?void 0:i.selected)||t?this.emitSelectionChange(t):this.emitSelectionChange(!1)},this.handleKeyDown=e=>{" "!==e.key&&"Enter"!==e.key||(e.preventDefault(),this.isUnavailable()||this.toggleSelection())}}render(){const e=this.isUnavailable(),i=this.getImage();return t(o,{key:"97fe779b6706627e3abb9729b6ea2933d5ccafb4",id:String(this.item.file.id),class:{"has-image":!!i,"has-error":!!this.item.hasError},role:"radio"===this.type?"radio":"checkbox","aria-checked":this.item.selected?"true":"false","aria-disabled":e?"true":"false",tabIndex:e?-1:0},t("limel-card",{key:"c897ca8a474b6b2e2f9e722507dd4b038ece058b",image:i,clickable:!e,onClick:this.handleDocumentItemClick,onKeyDown:this.handleKeyDown},t("div",{key:"cc75606770a2e0edeab4111e6e04608f6d841b6e",slot:"component"},this.renderFileSize(),this.renderBooleanInput())),this.renderHelp())}renderBooleanInput(){const e=this.getControlId();return t("radio"===this.type?"limel-radio-button":"limel-checkbox",{id:e,label:this.item.file.filename,disabled:this.isUnavailable(),checked:this.item.selected,onClick:this.handleSelectionControlClick,onChange:this.handleSelectionControlChange})}renderFileSize(){var e,i;const o=function(e,i=1){if(null==e||Number.isNaN(e))return"";if(e<0)return"";if(0===e)return"0 B";const t=["B","KB","MB","GB","TB","PB","EB","ZB","YB"],o=Math.min(t.length-1,Math.floor(Math.log(e)/Math.log(1024))),r=e/Math.pow(1024,o),l=r<10?Math.max(0,i):0;return`${Number.parseFloat(r.toFixed(l))} ${t[o]}`}(null===(i=null===(e=this.item)||void 0===e?void 0:e.file)||void 0===i?void 0:i.size);if(o)return t("span",{class:"file-size"},o)}renderHelp(){if(this.item.help)return t("limel-help",{value:this.item.help,openDirection:"bottom-end"})}toggleSelection(){var e,i;if("radio"===this.type){const i=!(null===(e=this.item)||void 0===e?void 0:e.selected);return void this.emitSelectionChange(i)}const t=!(null===(i=this.item)||void 0===i?void 0:i.selected);this.emitSelectionChange(t)}emitSelectionChange(e){this.interact.emit(Object.assign(Object.assign({},this.item),{selected:e}))}getControlId(){return`boolean-input-${String(this.item.file.id)}`}isUnavailable(){var e,i;return(null===(e=this.item)||void 0===e?void 0:e.disabled)||(null===(i=this.item)||void 0===i?void 0:i.hasError)}forceInputUnchecked(e){const i=e.target,t=null==i?void 0:i.closest("limel-radio-button"),o=null==t?void 0:t.querySelector('input[type="radio"]');o&&(o.checked=!1)}getImage(){const e=this.hrefForFile();if(e)return{src:e,alt:this.item.file.filename}}hrefForFile(){return["preview",...this.fileTypes].map((e=>this.item.file.getUrl(e))).find(Boolean)}static get delegatesFocus(){return!0}};r.style="*{box-sizing:border-box;min-width:0;min-height:0}:host(limebb-document-item){position:relative}limel-card:not([clickable]):not([clickable=true]){pointer-events:none;opacity:0.75}div[slot=component]{pointer-events:none;display:flex;flex-direction:column;margin-top:-0.25rem;padding:0 0.25rem}limel-checkbox,limel-radio-button{width:100%}.file-size{pointer-events:none;width:fit-content;padding:0 0.375rem;font-size:0.6875rem;color:rgb(var(--color-white));border-radius:1rem;opacity:0.75;background-color:rgb(var(--color-glaucous-darker), 0.8);box-shadow:var(--shadow-brighten-edges-outside);backdrop-filter:blur(0.75rem);margin-top:0.5rem}:host(.has-image) .file-size{margin-top:-1.5rem;margin-bottom:0.5rem}limel-help{position:absolute;top:0;right:0}:host(.has-error) limel-card{box-shadow:0 0 0 1px rgb(var(--color-red-light))}:host(.has-error) limel-help{--color-sky-default:var(       --color-red-default   );--color-sky-lighter:var(--color-red-lighter);--lime-elevated-surface-background-color:rgb(       var(--color-yellow-default)   )}";export{r as limebb_document_item}