/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/card-with-select-tool-v1@4.0.2/dist/card-with-select.umd.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
!function(){"use strict";try{if(typeof document<"u"){var e=document.createElement("style");e.appendChild(document.createTextNode('.card-with-select__items{display:flex;flex-direction:row;flex-wrap:nowrap;overflow-x:auto;gap:20px;padding:24px 0 60px;width:100%;box-sizing:border-box;min-height:300px}.card-with-select__items::-webkit-scrollbar{height:8px}.card-with-select__items::-webkit-scrollbar-thumb{background:#ccc;border-radius:4px}.native-select-container{position:relative;width:228px;font-family:TT Hoves,sans-serif;margin-bottom:8px}.native-select-input{width:100%;height:32px;padding:6px 30px 6px 8px;border:1px solid rgba(103,136,243,.3);border-radius:4px;background:transparent;color:#6788f3;font-size:13px;font-family:TT Hoves,sans-serif;outline:none;cursor:pointer;box-sizing:border-box}.native-select-input:focus{border-color:#6788f3}.native-select-input::placeholder{color:#6788f399}.native-select-arrow{position:absolute;right:8px;top:50%;transform:translateY(-50%);color:#6788f3;font-size:10px;pointer-events:none;transition:transform .2s ease}.native-select-open .native-select-arrow{transform:translateY(-50%) rotate(180deg)}.native-select-dropdown{position:absolute;top:100%;left:0;right:0;background:#fff;border:1px solid rgba(103,136,243,.3);border-radius:4px;box-shadow:0 4px 20px #00000026;z-index:1000;max-height:160px;overflow-y:auto;overflow-x:hidden;display:none;margin-top:2px;visibility:hidden;opacity:0;transition:opacity .2s ease,visibility .2s ease}.native-select-open .native-select-dropdown{display:block;visibility:visible;opacity:1}.native-select-options{padding:2px 0;min-height:32px}.native-select-option{padding:6px 12px;color:#6788f3;font-size:12px;cursor:pointer;transition:background-color .2s ease;line-height:1.2;border-bottom:1px solid rgba(103,136,243,.1);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:100%}.native-select-option:hover{background:#6788f31a}.native-select-option:last-child{border-bottom:none}.native-select-option-selected{background:#6788f333;font-weight:500}.native-select-loading,.native-select-error,.native-select-no-results{padding:8px 12px;color:#6788f399;font-size:12px;font-style:italic;text-align:center;line-height:1.2}.native-select-disabled{opacity:.5;pointer-events:none}.native-select-disabled .native-select-input{cursor:not-allowed;background:#6788f30d}.card-with-select__item{position:relative;display:flex;flex-direction:column;align-items:flex-start;padding:20px;gap:12px;width:280px;min-width:280px;max-width:280px;height:auto;min-height:140px;background:#6788f31a;border-radius:8px;flex:none;margin-bottom:30px}.card-with-select__item__title{width:240px;height:auto;font-family:TT Hoves,sans-serif;font-style:normal;font-weight:500;font-size:14px;line-height:20px;display:flex;align-items:flex-end;color:#6788f3;white-space:normal;word-wrap:break-word;overflow-wrap:break-word;flex:none;align-self:stretch;flex-grow:0;margin:0 0 8px}.card-with-select__item__description{width:240px;height:auto;font-family:TT Hoves,sans-serif;font-style:normal;font-weight:400;font-size:14px;line-height:20px;display:flex;align-items:flex-end;color:#6788f3;white-space:normal;word-wrap:break-word;overflow-wrap:break-word;flex:none;align-self:stretch;flex-grow:0;margin-bottom:12px}.card-with-select__item select.card-with-select__item__input{width:228px;height:36px;font-family:TT Hoves,sans-serif;font-style:normal;font-weight:400;font-size:13px;line-height:18px;display:flex;align-items:flex-end;color:#6788f3;flex:none;align-self:stretch;flex-grow:0;background:transparent;border:none;outline:none;margin-bottom:8px}.card-with-select__item__clear-button{position:absolute;right:16px;top:135px;width:20px;height:20px;background:#ff4757;color:#fff;border:none;border-radius:50%;cursor:pointer;font-size:14px;font-weight:700;line-height:1;display:none;align-items:center;justify-content:center;transition:background-color .2s ease;z-index:10}.card-with-select__item__clear-button:hover{background:#ff3742}.card-with-select__item__clear-button:active{background:#ff2938}.card-with-select__item__custom-link{width:228px;height:36px;margin-top:8px;font-family:TT Hoves,sans-serif;font-style:normal;font-weight:400;font-size:13px;line-height:18px;color:#6788f3;background:transparent;border:1px solid rgba(103,136,243,.3);border-radius:4px;padding:10px 12px;outline:none;box-sizing:border-box}.card-with-select__item__custom-link:focus{border-color:#6788f3}.card-with-select__item__file-zone{width:228px;min-height:70px;margin-top:8px;border:2px dashed rgba(103,136,243,.3);border-radius:8px;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:12px;padding:16px;cursor:pointer;transition:border-color .2s ease;box-sizing:border-box}.card-with-select__item__file-zone:hover,.card-with-select__item__file-zone--dragover{border-color:#6788f3;background:#6788f30d}.card-with-select__item__file-zone__text{font-family:TT Hoves,sans-serif;font-size:12px;color:#6788f3;text-align:center}.card-with-select__item__file-zone__button{background:#6788f3;color:#fff;border:none;padding:8px 16px;border-radius:4px;font-size:12px;cursor:pointer;transition:background .2s ease;font-family:TT Hoves,sans-serif}.card-with-select__item__file-zone__button:hover{background:#5a7ae6}.card-with-select__item__file-info{margin-top:8px;font-size:12px;color:#6788f3;word-break:break-all;width:100%;max-width:228px;box-sizing:border-box;line-height:1.4}.card-with-select__item__file-info>div{max-width:100%;box-sizing:border-box}.card-with-select__item__file-info>div:first-child{max-width:228px!important;width:228px!important;box-sizing:border-box!important}.card-with-select__item__file-info div[style*="flex: 1"]{min-width:0!important;flex:1!important;max-width:calc(100% - 80px)!important}.card-with-select__item__file-info div[style*="text-overflow: ellipsis"]{max-width:100%!important;overflow:hidden!important;text-overflow:ellipsis!important;white-space:nowrap!important}.card-with-select__item__remove{position:absolute;top:12px;right:12px;width:20px;height:20px;background:transparent;border:none;color:#6788f3;font-size:16px;line-height:20px;cursor:pointer;padding:0;border-radius:50%;transition:background .2s ease}.card-with-select__item__remove svg{width:20px;height:20px}.card-with-select__item__remove:hover{background:#6788f31a}.card-with-select__item__custom-link:disabled{opacity:.5!important;cursor:not-allowed!important;background:#6788f30d!important}.card-with-select__item__file-zone[style*="pointer-events: none"]{opacity:.5!important;cursor:not-allowed!important;border-color:#6788f333!important}.card-with-select__item__file-zone[style*="pointer-events: none"]:hover{border-color:#6788f333!important;background:#6788f30d!important}.card-with-select-notification{position:fixed;top:20px;right:20px;background:#ff6b6b;color:#fff;padding:12px 16px;border-radius:8px;font-size:14px;z-index:10000;box-shadow:0 4px 12px #00000026;max-width:300px;font-family:TT Hoves,sans-serif;animation:slideInRight .3s ease-out}@keyframes slideInRight{0%{transform:translate(100%);opacity:0}to{transform:translate(0);opacity:1}}.card-with-select__item__change-file{background:transparent!important;border:1px solid #6788F3!important;color:#6788f3!important;padding:4px 8px!important;border-radius:4px!important;font-size:11px!important;cursor:pointer!important;transition:all .2s ease!important;font-family:TT Hoves,sans-serif!important;white-space:nowrap!important}.card-with-select__item__change-file:hover{background:#6788f3!important;color:#fff!important}.card-with-select__item[data-link-type=glossary]{border-left:4px solid #8e44ad}.card-with-select__item[data-link-type=custom]{border-left:4px solid #2ECC71}.card-with-select__item[data-link-type=file]{border-left:4px solid #F39C12}.card-with-select__item[data-link-type=article],.card-with-select__item[data-link-type=blog]{border-left:4px solid #007acc}.card-with-select__item[data-link-type=article]:before,.card-with-select__item[data-link-type=blog]:before,.card-with-select__item[data-link-type=glossary]:before{content:"📄";position:absolute;top:8px;right:8px;font-size:14px;opacity:.7}.card-with-select__item[data-link-type=custom]:before{content:"🔗";position:absolute;top:8px;right:8px;font-size:14px;opacity:.7}.card-with-select__item[data-link-type=file]:before{content:"📁";position:absolute;top:8px;right:8px;font-size:14px;opacity:.7}.card-with-select__item{position:relative;padding-right:40px}.card-with-select__item__remove{right:30px!important}')),document.head.appendChild(e)}}catch(e){console.error("vite-plugin-css-injected-by-js",e)}}(),function(e,t){"object"==typeof exports&&typeof module<"u"?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=typeof globalThis<"u"?globalThis:e||self).CardWithSelectTool=t()}(this,(function(){"use strict";const e='<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24"><path stroke="currentColor" stroke-linecap="round" stroke-width="2" d="M12 7V12M12 17V12M17 12H12M12 12H7"/></svg>';function t(e,t=null,i={}){const n=document.createElement(e);Array.isArray(t)?n.classList.add(...t):null!==t&&n.classList.add(t);for(const e in i)i.hasOwnProperty(e)&&(n[e]=i[e]);return n}class i{constructor(e,t){this.api=e,this.uploadUrl=t.fileUploadEndpoint||"/upload/file",this.renameUrl=t.fileRenameEndpoint||"/upload/file/rename"}async handleFileUpload(e,t,i,n,o){i(t,e);try{n(t,await this.uploadFileToServer(e))}catch{n(t,{url:URL.createObjectURL(e),name:e.name,size:e.size,isBlob:!0})}}async uploadFileToServer(e){const t=new FormData;t.append("file",e);const i=await fetch(this.uploadUrl,{method:"POST",body:t,headers:{"X-Requested-With":"XMLHttpRequest","X-CSRF-Token":this.getCSRFToken()}});if(!i.ok)throw new Error(`Upload failed: ${i.status}`);const n=await i.text(),o=JSON.parse(n);if(o.success&&o.data)return o.data;throw new Error(o.message||"Upload failed")}getCSRFToken(){const e=document.querySelector('meta[name="csrf-token"]');return e?e.content:typeof window.yii<"u"&&window.yii.getCsrfToken?window.yii.getCsrfToken():""}formatFileSize(e){if(0===e)return"0 Bytes";const t=Math.floor(Math.log(e)/Math.log(1024));return parseFloat((e/Math.pow(1024,t)).toFixed(1))+" "+["Bytes","KB","MB","GB"][t]}getFileIcon(e){var t;if(!e)return"📎";return{pdf:"📄",doc:"📝",docx:"📝",xls:"📊",xlsx:"📊",ppt:"📊",pptx:"📊",txt:"📄",rtf:"📄",zip:"📦",rar:"📦","7z":"📦",jpg:"🖼️",jpeg:"🖼️",png:"🖼️",gif:"🖼️",svg:"🖼️"}[(null==(t=e.split(".").pop())?void 0:t.toLowerCase())||""]||"📎"}getFileExtension(e){if(!e)return"";const t=e.split(".");return t.length>1?t[t.length-1]:""}async handleFileRename(e,t){let i=e;if(e.success&&e.data&&(i=e.data),!i.id)return{...i,name:`${t}.${i.extension}`,id:i.id||"",extension:i.extension||this.getFileExtension(i.name),url:i.url||"",size:i.size||0,createdAt:(new Date).toISOString(),updatedAt:(new Date).toISOString()};const n=this.renameUrl,o={id:i.id,name:t,extension:i.extension||this.getFileExtension(i.name),url:i.url,size:i.size},s=await fetch(n,{method:"PUT",headers:{"Content-Type":"application/json","X-CSRF-Token":this.getCSRFToken()},body:JSON.stringify(o)});if(!s.ok)throw await s.text(),new Error(`Rename failed: ${s.status}`);return await s.json()}}class n{constructor(e,t={}){this.options=[],this.isOpen=!1,this.searchTimer=0,this.selectedValue="",this.selectElement=e,this.config={placeholder:"Выберите опцию",searchEnabled:!0,loadingText:"Загрузка...",noResultsText:"Ничего не найдено",searchPlaceholder:"Поиск...",...t},this.init()}init(){this.createStructure(),this.attachEvents(),this.hideOriginalSelect()}createStructure(){var e;this.container=t("div",["native-select-container"]),this.input=t("input",["native-select-input"],{type:"text",placeholder:this.config.placeholder,autocomplete:"off",readonly:!this.config.searchEnabled});const i=t("div",["native-select-arrow"]);i.innerHTML="▼",this.dropdown=t("div",["native-select-dropdown"]),this.optionsList=t("div",["native-select-options"]),this.dropdown.appendChild(this.optionsList),this.container.appendChild(this.input),this.container.appendChild(i),this.container.appendChild(this.dropdown),null==(e=this.selectElement.parentNode)||e.insertBefore(this.container,this.selectElement)}attachEvents(){var e;this.input.addEventListener("click",(()=>this.toggle())),null==(e=this.container.querySelector(".native-select-arrow"))||e.addEventListener("click",(()=>this.toggle())),this.config.searchEnabled&&this.input.addEventListener("input",(e=>{const t=e.target.value;this.handleSearch(t)})),document.addEventListener("click",(e=>{this.container.contains(e.target)||this.close()})),this.input.addEventListener("keydown",(e=>{"ArrowDown"===e.key?(e.preventDefault(),this.open(),this.focusFirstOption()):"Escape"===e.key&&this.close()}))}hideOriginalSelect(){this.selectElement.style.display="none"}toggle(){this.isOpen?this.close():this.open()}open(){this.isOpen||(this.isOpen=!0,this.container.classList.add("native-select-open"),this.config.searchEnabled&&""===this.input.value&&this.showAllOptions())}close(){this.isOpen&&(this.isOpen=!1,this.container.classList.remove("native-select-open"))}handleSearch(e){this.searchTimer&&clearTimeout(this.searchTimer),this.searchTimer=window.setTimeout((()=>{if(e.length<2)this.showAllOptions();else if(this.onSearchCallback)this.showLoading(),this.onSearchCallback(e).then((e=>{this.setOptions(e),this.renderOptions()})).catch((e=>{console.error("Search error:",e),this.showError()}));else{const t=this.options.filter((t=>t.text.toLowerCase().includes(e.toLowerCase())));this.renderOptions(t)}}),300)}showLoading(){this.optionsList.innerHTML=`<div class="native-select-loading">${this.config.loadingText}</div>`}showError(){this.optionsList.innerHTML='<div class="native-select-error">Ошибка загрузки</div>'}showAllOptions(){this.renderOptions()}renderOptions(e){const i=e||this.options;0!==i.length?(this.optionsList.innerHTML="",i.forEach((e=>{const i=t("div",["native-select-option"],{"data-value":e.id});(e.selected||e.id===this.selectedValue)&&i.classList.add("native-select-option-selected"),i.textContent=e.text,i.addEventListener("click",(()=>{this.selectOption(e)})),this.optionsList.appendChild(i)}))):this.optionsList.innerHTML=`<div class="native-select-no-results">${this.config.noResultsText}</div>`}selectOption(e){this.selectedValue=e.id,this.input.value=e.text,this.selectElement.value=e.id,this.optionsList.querySelectorAll(".native-select-option").forEach((e=>{e.classList.remove("native-select-option-selected")}));const t=this.optionsList.querySelector(`[data-value="${e.id}"]`);t&&t.classList.add("native-select-option-selected"),this.close(),this.onChangeCallback&&this.onChangeCallback(e.id),this.selectElement.dispatchEvent(new Event("change",{bubbles:!0}))}focusFirstOption(){const e=this.optionsList.querySelector(".native-select-option");e&&e.focus()}setOptions(e){this.options=e}renderInitialOptions(){this.options.length>0&&this.renderOptions()}getValue(){return this.selectedValue}setValue(e){const t=this.options.find((t=>t.id===e));t&&(this.selectOption(t),this.renderOptions())}clear(){this.selectedValue="",this.input.value="",this.selectElement.value="",this.optionsList.querySelectorAll(".native-select-option").forEach((e=>{e.classList.remove("native-select-option-selected")})),this.onChangeCallback&&this.onChangeCallback("")}disable(){this.input.disabled=!0,this.container.classList.add("native-select-disabled")}enable(){this.input.disabled=!1,this.container.classList.remove("native-select-disabled")}onSearch(e){this.onSearchCallback=e}onChange(e){this.onChangeCallback=e}destroy(){this.container.remove(),this.selectElement.style.display=""}}class o{constructor(e){this.config=e}async initializeSelect(e,t,i){let o=e.linkType;"article"===o&&(o="blog");const s=this.getConfigurableType(o),a=(null==s?void 0:s.endpoint)||this.config.endpoint,r=(null==s?void 0:s.endpointOne)||this.config.endpointOne,l=(null==s?void 0:s.searchPlaceholder)||"Поиск...";e.choices=new n(e.select,{placeholder:"Выберите",searchEnabled:!0,loadingText:"Загрузка...",noResultsText:"Ничего не найдено",searchPlaceholder:l}),e.entity._nativeSelectInstance=e.choices;try{const t=await fetch(`${a}`);if(!t.ok)throw new Error(`HTTP error! status: ${t.status}`);const i=await t.json();if(i.results&&Array.isArray(i.results)){const t=i.results.map((e=>({id:e.id,text:e.text,selected:!1})));e.choices.setOptions(t),e.choices.renderInitialOptions()}}catch(e){console.error("Ошибка при загрузке начального списка:",e)}if(e.choices.onSearch((async e=>{try{const t=await fetch(`${a}?q=${encodeURIComponent(e)}`);if(!t.ok)throw new Error(`HTTP error! status: ${t.status}`);const i=await t.json();return i.results&&Array.isArray(i.results)?i.results.map((e=>({id:e.id,text:e.text,selected:!1}))):[]}catch(e){return console.error("Ошибка при поиске:",e),[]}})),e.choices.onChange(i),null!==t){const i=await(await fetch(`${r}?id=${t}`)).json();if(i.success){let t=!1;if(Array.isArray(e.choices.options)&&(t=e.choices.options.some((e=>e.id===i.data.id))),t||e.choices.setOptions([{id:i.data.id,text:i.data.text,selected:!0}]),e.choices.setValue(i.data.id),e.select){e.select.value=i.data.id;const t=new Event("change",{bubbles:!0});e.select.dispatchEvent(t)}}}}setupClearButton(e,t){e.selectClear.addEventListener("click",(i=>{i.preventDefault(),e.choices.clear(),t(),e.selectClear.style.display="none"}))}getConfigurableType(e){return this.config.configurableTypes?this.config.configurableTypes.find((t=>t.key===e)):null}}class s{constructor(e){this.fileHandler=e}renderFileZone(){const e=t("div",["card-with-select__item__file-zone"],{});return e.innerHTML='\n        <div class="card-with-select__item__file-zone__text">Перетащите файл сюда или</div>\n        <button class="card-with-select__item__file-zone__button" type="button">Выберите файл</button>\n      ',e}showFileUploadProgress(e,t){const i=this.fileHandler.getFileIcon(t.name);e.fileInfo.innerHTML=`\n        <div style="\n          padding: 12px;\n          background: rgba(103, 136, 243, 0.05);\n          border-radius: 6px;\n          border: 1px solid rgba(103, 136, 243, 0.1);\n          width: 240px;\n          max-width: 240px;\n          box-sizing: border-box;\n          margin-bottom: 12px;\n        ">\n          <div style="\n            display: flex; \n            align-items: center; \n            gap: 12px;\n          ">\n            <span style="font-size: 18px; flex-shrink: 0;">${i}</span>\n            <div style="flex: 1; min-width: 0;">\n              <div style="\n                color: #6788F3; \n                font-weight: 500; \n                font-size: 13px;\n                white-space: nowrap;\n                overflow: hidden;\n                text-overflow: ellipsis;\n              ">${t.name}</div>\n              <div style="color: #6788F3; font-size: 11px;">\n                Загружается... ${this.fileHandler.formatFileSize(t.size)}\n              </div>\n            </div>\n          </div>\n        </div>\n      `,e.fileZone.style.display="none"}displayFileInfo(e,t,i){const n=t.size?` (${this.fileHandler.formatFileSize(t.size)})`:"",o=this.fileHandler.getFileIcon(t.name),s=this.fileHandler.getFileExtension(t.name);e.fileInfo.innerHTML=`\n        <div style="\n          padding: 12px;\n          background: rgba(103, 136, 243, 0.05);\n          border-radius: 6px;\n          border: 1px solid rgba(103, 136, 243, 0.1);\n          width: 240px;\n          max-width: 240px;\n          box-sizing: border-box;\n          margin-bottom: 12px;\n        ">\n          <div style="\n            display: flex; \n            align-items: center; \n            gap: 12px; \n            margin-bottom: 12px;\n          ">\n            <span style="font-size: 18px; flex-shrink: 0;">${o}</span>\n            <div style="\n              flex: 1; \n              min-width: 0;\n              max-width: calc(100% - 120px);\n              overflow: hidden;\n            ">\n              <div style="\n                color: #6788F3; \n                font-weight: 500; \n                font-size: 14px;\n                white-space: nowrap;\n                overflow: hidden;\n                text-overflow: ellipsis;\n                max-width: 100%;\n              " title="${t.name}">${t.name}</div>\n              <div style="\n                color: #6788F3; \n                opacity: 0.7; \n                font-size: 12px;\n                white-space: nowrap;\n                overflow: hidden;\n                text-overflow: ellipsis;\n              ">${n}</div>\n            </div>\n            <button class="card-with-select__item__change-file" type="button" style="\n              flex-shrink: 0;\n              background: transparent;\n              border: 1px solid #6788F3;\n              color: #6788F3;\n              padding: 6px 12px;\n              border-radius: 4px;\n              font-size: 12px;\n              cursor: pointer;\n              font-family: 'TT Hoves', sans-serif;\n              white-space: nowrap;\n            ">Заменить</button>\n          </div>\n          \n          \x3c!-- Поле для редактирования названия файла --\x3e\n          <div style="margin-bottom: 12px;">\n            <label style="\n              display: block;\n              color: #6788F3;\n              font-size: 12px;\n              margin-bottom: 6px;\n              font-weight: 500;\n            ">название файла:</label>\n            <input \n              type="text" \n              class="card-with-select__item__file-name-input"\n              value="${(e=>{if(!e)return"";const t=e.split(".");return t.length>1?t.slice(0,-1).join("."):e})(t.name)}"\n              style="\n                width: 100%;\n                padding: 8px 12px;\n                border: 1px solid rgba(103, 136, 243, 0.3);\n                border-radius: 4px;\n                font-size: 13px;\n                color: #6788F3;\n                background: white;\n                box-sizing: border-box;\n                font-family: 'TT Hoves', sans-serif;\n              "\n              placeholder="Введите название для отображения"\n              data-original-extension="${s}"\n            />\n          </div>\n          \n          \x3c!-- Ссылка для скачивания --\x3e\n          <div>\n            ${t.isBlob?'\n                <span style="\n                  color: #999; \n                  font-size: 12px;\n                  display: inline-flex;\n                  align-items: center;\n                  gap: 4px;\n                ">\n                  <span style="flex-shrink: 0;">⚠️</span>\n                  <span>Скачивание недоступно (файл не загружен на сервер)</span>\n                </span>\n              ':`\n                <a href="${t.url}" download="${t.name}" style="\n                  color: #6788F3; \n                  font-size: 12px;\n                  text-decoration: none;\n                  display: inline-flex;\n                  align-items: center;\n                  gap: 4px;\n                  max-width: 100%;\n                  overflow: hidden;\n                  text-overflow: ellipsis;\n                  white-space: nowrap;\n                  cursor: pointer;\n                ">\n                  <span style="flex-shrink: 0;">📥</span>\n                  <span style="overflow: hidden; text-overflow: ellipsis;">Скачать файл</span>\n                </a>\n              `}\n          </div>\n        </div>\n      `,this.setupFileInfoEvents(e,i),e.fileZone.style.display="none"}setupFileInfoEvents(e,t){const i=e.fileInfo,n=i.querySelector(".card-with-select__item__change-file");n&&(n.addEventListener("click",(()=>{t()})),n.addEventListener("mouseenter",(()=>{n.style.background="#6788F3",n.style.color="white"})),n.addEventListener("mouseleave",(()=>{n.style.background="transparent",n.style.color="#6788F3"})));const o=i.querySelector(".card-with-select__item__file-name-input");o&&(o.addEventListener("focus",(()=>{o.style.borderColor="#6788F3",o.style.boxShadow="0 0 0 2px rgba(103, 136, 243, 0.1)"})),o.addEventListener("input",(t=>{const n=t.target,o=n.value.trim(),s=JSON.parse(e.entity.dataset.fileData||"{}"),a=o?`${o}.${s.extension}`:s.name,r=i.querySelector("[title]");r&&(r.textContent=a,r.title=a);const l=i.querySelector("a");l&&(l.download=a),o?(n.style.borderColor="#6788F3",n.style.boxShadow="0 0 0 2px rgba(103, 136, 243, 0.1)"):(n.style.borderColor="#ffa502",n.style.boxShadow="0 0 0 2px rgba(255, 165, 2, 0.1)")})),o.addEventListener("blur",(async t=>{const n=t.target,o=n.value.trim(),s=JSON.parse(e.entity.dataset.fileData||"{}");if(!o){console.error("❌ Имя файла не может быть пустым");const e=s.name.includes(".")?s.name.replace(`.${s.extension}`,""):s.name;return n.value=e,n.style.borderColor="#ff4757",n.style.boxShadow="0 0 0 2px rgba(255, 71, 87, 0.1)",void setTimeout((()=>{n.style.borderColor="rgba(103, 136, 243, 0.3)",n.style.boxShadow="none"}),2e3)}try{const t=await this.fileHandler.handleFileRename(s,o);let a=t;t.success&&t.data&&(a=t.data),e.entity.dataset.fileData=JSON.stringify(a);const r=a.name.includes(".")?a.name:`${a.name}.${a.extension}`;n.value=r.replace(`.${a.extension}`,"");const l=i.querySelector("a");l&&(l.href=a.url,l.download=r)}catch(e){console.error("Переименование файла не удалось:",e)}finally{n.style.borderColor="rgba(103, 136, 243, 0.3)",n.style.boxShadow="none"}})))}}class a{constructor(e,t,i,n,o){this.api=e,this.config=t,this.fileHandler=i,this.selectManager=n,this.domRenderer=o}createEntity(e){const i=this.getCSSClasses();return{title:t("div",[i.textInput,i.input,i.titleInput],{contentEditable:!0}),description:t("div",[i.textInput,i.descriptionInput,i.input],{contentEditable:!0}),select:t("select",[i.textInput,i.input],{}),selectClear:t("button",["card-with-select__item__clear-button"],{type:"button",title:"Очистить выбор",innerHTML:"×"}),customLink:t("input",[i.textInput,i.input,"card-with-select__item__custom-link"],{type:"url",placeholder:"Ссылка"}),fileZone:this.domRenderer.renderFileZone(),fileInput:t("input",[],{type:"file",style:"display: none"}),fileInfo:t("div",["card-with-select__item__file-info"],{}),entity:t("div",["card-with-select__item"],{}),remove:t("div",["card-with-select__item__remove"],{}),choices:null,linkType:e}}setupEntityEvents(e,t){this.setupFileEvents(e),e.remove.addEventListener("click",(()=>{var t;null==(t=e.remove.closest(".card-with-select__item"))||t.remove()})),this.isConfigurableType(e.linkType)&&setTimeout((()=>{const t=e.entityId||e.selectedId||null;this.selectManager.initializeSelect(e,t,(t=>{e.selectClear.style.display=t&&""!==t?"inline-block":"none"}))}),0)}setupFileEvents(e){const t=e.fileZone.querySelector(".card-with-select__item__file-zone__button");null==t||t.addEventListener("click",(t=>{e.fileInput.click()})),e.fileInput.addEventListener("change",(async t=>{var i;const n=null==(i=t.target.files)?void 0:i[0];n&&await this.handleFileUpload(n,e)})),e.fileZone.addEventListener("dragover",(t=>{t.preventDefault(),t.stopPropagation(),e.fileZone.classList.add("card-with-select__item__file-zone--dragover")})),e.fileZone.addEventListener("dragleave",(t=>{t.stopPropagation(),e.fileZone.classList.remove("card-with-select__item__file-zone--dragover")})),e.fileZone.addEventListener("drop",(async t=>{var i;t.preventDefault(),t.stopPropagation(),e.fileZone.classList.remove("card-with-select__item__file-zone--dragover");const n=null==(i=t.dataTransfer)?void 0:i.files;n&&n.length>0&&await this.handleFileUpload(n[0],e)}))}setupDragAndDropPrevention(e){["dragover","drop","dragenter","dragleave"].forEach((t=>{e.entity.addEventListener(t,(e=>{e.stopPropagation()}))}))}async handleFileUpload(e,t){await this.fileHandler.handleFileUpload(e,t,((e,t)=>{this.domRenderer.showFileUploadProgress(e,t)}),((e,t)=>{this.domRenderer.displayFileInfo(e,t,(()=>{e.fileZone.style.display="flex",e.fileInfo.innerHTML="",delete e.entity.dataset.fileData})),e.entity.dataset.fileData=JSON.stringify(t)}),((e,t)=>{console.error("File upload error:",t)}))}getCSSClasses(){return{baseClass:this.api.styles.block,loading:this.api.styles.loader,input:this.api.styles.input,button:this.api.styles.button,header:"ce-header",wrapper:"card-with-select__items",label:"card-with-select__item__label",textInput:"card-with-select__item__input",descriptionInput:"card-with-select__item__description",titleInput:"card-with-select__item__title",entityInput:"card-with-select__item__entity"}}populateEntity(e,t,i,n,o,s){e.entityId=n,e.title.dataset.placeholder=this.config.titlePlaceholder,e.title.innerText=t,e.remove.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M18.1328 7.7234C18.423 7.7634 18.7115 7.80571 19 7.85109M18.1328 7.7234L17.2267 17.4023C17.1897 17.8371 16.973 18.2432 16.62 18.5394C16.267 18.8356 15.8037 19.0001 15.3227 19H8.67733C8.19632 19.0001 7.73299 18.8356 7.37998 18.5394C7.02698 18.2432 6.81032 17.8371 6.77333 17.4023L5.86715 7.7234M18.1328 7.7234C17.1536 7.58919 16.1693 7.48733 15.1818 7.41803M5.86715 7.7234C5.57697 7.76263 5.28848 7.80494 5 7.85032M5.86715 7.7234C6.84642 7.58919 7.83074 7.48733 8.81818 7.41803M15.1818 7.41803C13.0638 7.26963 10.9362 7.26963 8.81818 7.41803M15.1818 7.41803C15.1818 5.30368 13.7266 4.34834 12 4.34834C10.2734 4.34834 8.81818 5.43945 8.81818 7.41803"/><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10.5 15.5L10 11"/><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M14 11L13.5 15.5"/></svg>',e.description.dataset.placeholder=this.config.descriptionPlaceholder,e.description.innerText=i,o&&(e.customLink.value=o),s&&(this.domRenderer.displayFileInfo(e,s,(()=>{e.fileZone.style.display="flex",e.fileInfo.innerHTML="",delete e.entity.dataset.fileData})),e.entity.dataset.fileData=JSON.stringify(s)),e.selectClear.style.display="none"}assembleEntityInDOM(e,t){const i=t.appendChild(e.entity);return e.entity.dataset.linkType=e.linkType,i.appendChild(e.title),i.appendChild(e.remove),i.appendChild(e.description),this.isConfigurableType(e.linkType)?(i.appendChild(e.select),i.appendChild(e.selectClear)):"custom"===e.linkType?i.appendChild(e.customLink):"file"===e.linkType&&(i.appendChild(e.fileZone),i.appendChild(e.fileInfo),i.appendChild(e.fileInput)),i}isConfigurableType(e){return"article"===e||!!this.config.configurableTypes&&this.config.configurableTypes.some((t=>t.key===e))}getConfigurableType(e){return"article"===e&&(e="blog"),this.config.configurableTypes?this.config.configurableTypes.find((t=>t.key===e)):null}}class r{constructor({api:e,config:n}){this.api=e,this.config=n,this.fileHandler=new i(e,n),this.selectManager=new o(n),this.domRenderer=new s(this.fileHandler),this.entityManager=new a(e,n,this.fileHandler,this.selectManager,this.domRenderer),this.nodes={wrapper:t("div",[this.CSS.baseClass,this.CSS.wrapper]),entities:t("div",["card-with-select__items"],{})},this.nodes.wrapper.appendChild(this.nodes.entities)}render(){return this.nodes.wrapper}addNewItem(e,t,i,n,o){this.addNewItemWithType(e,t,i,"blog",n,o)}addNewItemWithType(e,t,i,n,o,s){const a=this.config.maxEntityQuantity??3;if(this.nodes.entities.querySelectorAll(".card-with-select__item").length>=a)return void console.warn("Количество элементов превысило число "+a);const r=this.entityManager.createEntity(n);this.entityManager.assembleEntityInDOM(r,this.nodes.entities),this.entityManager.setupEntityEvents(r,this.nodes.entities),this.entityManager.populateEntity(r,e,t,i,o,s)}get CSS(){return{baseClass:this.api.styles.block,loading:this.api.styles.loader,input:this.api.styles.input,button:this.api.styles.button,header:"ce-header",wrapper:"card-with-select__items",label:"card-with-select__item__label",textInput:"card-with-select__item__input",descriptionInput:"card-with-select__item__description",titleInput:"card-with-select__item__title",entityInput:"card-with-select__item__entity"}}}const l=class t{constructor({data:e,config:i,api:n,block:o}){this.api=n,this.block=o,this.config={endpoint:(null==i?void 0:i.endpoint)??"/blog/ajax-blog-list",endpointOne:(null==i?void 0:i.endpointOne)??"/blog/ajax-blog-by-id?id=1",maxEntityQuantity:(null==i?void 0:i.maxEntityQuantity)??t.DEFAULT_MAX_ENTITY_QUANTITY,additionalRequestData:null==i?void 0:i.additionalRequestData,additionalRequestHeaders:null==i?void 0:i.additionalRequestHeaders,types:null==i?void 0:i.types,titlePlaceholder:this.api.i18n.t((null==i?void 0:i.titlePlaceholder)??"Title"),descriptionPlaceholder:this.api.i18n.t((null==i?void 0:i.descriptionPlaceholder)??"Description"),actions:null==i?void 0:i.actions,fileUploadEndpoint:null==i?void 0:i.fileUploadEndpoint,fileRenameEndpoint:null==i?void 0:i.fileRenameEndpoint,configurableTypes:(null==i?void 0:i.configurableTypes)??[{key:"blog",buttonLabel:"Статья блога",endpoint:"/blog/ajax-blog-list",endpointOne:"/blog/ajax-blog-by-id",searchPlaceholder:"Поиск статей...",color:"#007acc",icon:"📄"}]},this.ui=new r({api:n,config:this.config}),this._data={items:[]},this.data=e??{items:[]}}static get toolbox(){return{icon:'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24"><path stroke="currentColor" stroke-linecap="round" stroke-width="2" d="M8 9V7.2C8 7.08954 8.08954 7 8.2 7L12 7M16 9V7.2C16 7.08954 15.9105 7 15.8 7L12 7M12 7L12 17M12 17H10M12 17H14"/></svg>',title:"Карточка со ссылками"}}render(){return this.ui.render()}validate(e){return!0}save(){return this._data.items=[],this.ui.nodes.entities.querySelectorAll(".card-with-select__item").forEach((e=>{const t=e.querySelector(".card-with-select__item__title"),i=e.querySelector(".card-with-select__item__description"),n=e.querySelector("select"),o=e.querySelector(".card-with-select__item__custom-link"),s=e.dataset.fileData,a=e.dataset.linkType;let r=null;if(s)try{r=JSON.parse(s)}catch(e){console.warn("Ошибка парсинга данных файла:",e),console.warn("Error parsing file data:",e)}if(t&&i){const s=e._nativeSelectInstance;let l="";s?l=s.getValue()||"":n&&(l=n.value||""),this._data.items.push({title:t.innerHTML,description:i.innerHTML,entityId:l,customLink:(null==o?void 0:o.value)||void 0,file:r||void 0,linkType:a||"blog"})}})),this.data}renderSettings(){const t=[];return this.config.configurableTypes&&this.config.configurableTypes.forEach((i=>{t.push({icon:e,label:this.api.i18n.t(i.buttonLabel),onActivate:()=>this.addNewItemWithType(i.key),closeOnActivate:!0,isActive:!1})})),t.push({icon:e,label:"Ссылку",onActivate:()=>this.addNewItemWithType("custom"),closeOnActivate:!0,isActive:!1},{icon:e,label:"Файл",onActivate:()=>this.addNewItemWithType("file"),closeOnActivate:!0,isActive:!1}),t}addNewItemWithType(e){this.ui.addNewItemWithType("","",null,e)}set data(e){e&&e.hasOwnProperty("items")?e.items.forEach((e=>{let t=e.linkType||"blog";"article"===t&&(t="blog");const i={title:e.title||"",description:e.description||"",entityId:e.entityId||"",customLink:e.customLink||void 0,file:e.file||void 0};this.ui.addNewItemWithType(i.title,i.description,String(i.entityId),t,i.customLink,i.file)})):this.ui.addNewItemWithType("","",null,"blog")}get data(){return this._data}};return l.DEFAULT_MAX_ENTITY_QUANTITY=3,l}));
//# sourceMappingURL=/sm/0a5e5d58804cb2acdc9a6b2c80654e2261e33b284de981ecf23374fff01edda6.map