import{r as i,c as e,h as t,H as o}from"./p-BIwHMk6j.js";const r=class{constructor(t){i(this,t),this.interact=e(this,"interact"),this.type="checkbox",this.fileTypes=["view","contents","download"],this.handleDocumentItemClick=i=>{if(!this.isUnavailable()){if((null==i?void 0:i.target)instanceof HTMLElement&&(i.target.closest("limel-checkbox")||i.target.closest("limel-radio-button")))return;this.toggleSelection()}},this.handleSelectionControlClick=i=>{var e,t;i.stopPropagation(),this.isUnavailable()||"radio"===this.type&&(null===(e=this.item)||void 0===e?void 0:e.selected)&&(i.preventDefault(),this.forceInputUnchecked(i),this.emitSelectionChange(!(null===(t=this.item)||void 0===t?void 0:t.selected)))},this.handleSelectionControlChange=i=>{var e;if(i.stopPropagation(),this.isUnavailable())return;let t;if("detail"in i&&"boolean"==typeof i.detail)t=i.detail;else{const e=i.target;t=!!(null==e?void 0:e.checked)}"radio"!==this.type||!(null===(e=this.item)||void 0===e?void 0:e.selected)||t?this.emitSelectionChange(t):this.emitSelectionChange(!1)},this.handleKeyDown=i=>{" "!==i.key&&"Enter"!==i.key||(i.preventDefault(),this.isUnavailable()||this.toggleSelection())}}render(){const i=this.isUnavailable(),e=this.getImage();return t(o,{key:"4e7f632c97cd078ee44cc262b3531b87409344fb",id:String(this.item.file.id),class:{"has-image":!!e,"has-error":!!this.item.hasError},role:"radio"===this.type?"radio":"checkbox","aria-checked":this.item.selected?"true":"false","aria-disabled":i?"true":"false",tabIndex:i?-1:0},t("limel-card",{key:"b560d107ba3bfee84158b2867fb594eb698072c3",image:e,clickable:!i,onClick:this.handleDocumentItemClick,onKeyDown:this.handleKeyDown},t("div",{key:"798a25ef8ef4ca1470a91afaaf2fc3e975473368",slot:"component"},this.renderFileSize(),this.renderBooleanInput())),this.renderHelp())}renderBooleanInput(){const i=this.getControlId();return t("radio"===this.type?"limel-radio-button":"limel-checkbox",{id:i,label:this.item.file.filename,disabled:this.isUnavailable(),checked:this.item.selected,onClick:this.handleSelectionControlClick,onChange:this.handleSelectionControlChange})}renderFileSize(){var i,e;const o=function(i,e=1){if(null==i||Number.isNaN(i))return"";if(i<0)return"";if(0===i)return"0 B";const t=["B","KB","MB","GB","TB","PB","EB","ZB","YB"],o=Math.min(t.length-1,Math.floor(Math.log(i)/Math.log(1024))),r=i/Math.pow(1024,o),l=r<10?Math.max(0,e):0;return`${Number.parseFloat(r.toFixed(l))} ${t[o]}`}(null===(e=null===(i=this.item)||void 0===i?void 0:i.file)||void 0===e?void 0:e.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 i,e;if("radio"===this.type){const e=!(null===(i=this.item)||void 0===i?void 0:i.selected);return void this.emitSelectionChange(e)}const t=!(null===(e=this.item)||void 0===e?void 0:e.selected);this.emitSelectionChange(t)}emitSelectionChange(i){this.interact.emit(Object.assign(Object.assign({},this.item),{selected:i}))}getControlId(){return`boolean-input-${String(this.item.file.id)}`}isUnavailable(){var i,e;return(null===(i=this.item)||void 0===i?void 0:i.disabled)||(null===(e=this.item)||void 0===e?void 0:e.hasError)}forceInputUnchecked(i){const e=i.target,t=null==e?void 0:e.closest("limel-radio-button"),o=null==t?void 0:t.querySelector('input[type="radio"]');o&&(o.checked=!1)}getImage(){const i=this.hrefForFile();if(i)return{src:i,alt:this.item.file.filename}}hrefForFile(){return["preview",...this.fileTypes].map((i=>this.item.file.getUrl(i))).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}