let S=!1;function _(){S||(S=!0,document.body.addEventListener("click",function(e){if(e.target.classList.contains("clear-row")){const t=e.target.closest("tr");t&&t.querySelectorAll('input[type="number"]').forEach(a=>{a.value=""});return}if(e.target.classList.contains("remove-value-grid")){const t=e.target.closest(".value-grid"),a=t?t.closest("#valuesGridContainer"):null;t&&a&&a.querySelectorAll(".value-grid").length>1&&t.remove()}}))}function c(e,t){const a=e.split(".");let r=window.translations;for(const o of a){if(r==null)return t;r=r[o]}return typeof r=="string"&&r.length?r:t}function x(e){const t=Array.isArray(window.periods)?window.periods:[1,3,6,12,24,36],r=(Array.isArray(window.currencies)?window.currencies:[]).map(s=>{const u=t.map(m=>`<td><input type="number" step="0.01" min="0" class="form-control" name="pricing_grid[${e}][${s.id}][${m}]" /></td>`).join("");return`<tr><td class="text-nowrap">${s.code}</td>${u}<td class="text-nowrap"><button type="button" class="btn btn-sm btn-outline-secondary clear-row">${c("admin.common.clear","Temizle")}</button></td></tr>`}).join(""),o=document.createElement("div");return o.className="card mb-3 value-grid",o.setAttribute("data-index",String(e)),o.innerHTML=`
        <div class="card-header d-flex justify-content-between align-items-center">
            <div class="d-flex align-items-center flex-nowrap" style="gap:.5rem;">
                <label class="mb-0">${c("admin.product_config_options.fields.value","Değer")}</label>
                <input type="text" class="form-control" style="max-width:240px;" name="values_list[${e}][value]" value="" placeholder="Display">
                <div class="d-flex align-items-center flex-nowrap" style="gap:.5rem;">
                    <label class="mb-0 ms-2 small text-muted">${c("admin.product_config_options.field_passthrough_value","Passthrough")}</label>
                    <input type="text" class="form-control form-control-sm" style="max-width:160px;" name="values_list[${e}][passthrough_value]" value="" placeholder="API value (opsiyonel)">
                    <div class="form-check form-check-inline mb-0 ms-1">
                        <input class="form-check-input" type="radio" name="default_value_index" value="${e}" id="default_${e}">
                        <label class="form-check-label small text-nowrap" for="default_${e}">${c("admin.product_config_options.field_is_default","Varsayılan")}</label>
                    </div>
                </div>
            </div>
            <button type="button" class="btn btn-sm btn-outline-danger remove-value-grid">${c("admin.common.delete","Sil")}</button>
        </div>
        <div class="card-body">
            <div class="table-responsive">
                <table class="table table-bordered align-middle mb-0">
                    <thead>
                        <tr>
                            <th>Value</th>
                            ${t.map(s=>`<th>${s} ${c("admin.products.time.month","Ay")}</th>`).join("")}
                            <th>${c("admin.common.actions","İşlemler")}</th>
                        </tr>
                    </thead>
                    <tbody>
                        ${r}
                    </tbody>
                </table>
            </div>
        </div>
    `,o}function q(e){e=e||document;const t=e.querySelector("#editProductConfigOptionForm, #createProductConfigOptionForm");if(!t)return null;if(t.dataset.cfgFormInit==="1")return{form:t,toggleDisabledByVisibility:()=>{}};t.dataset.cfgFormInit="1",_();const a=e.querySelector("#numberFields"),r=e.querySelector("#pricingOptionGrid"),o=e.querySelector("#pricingValuesGrid"),s=e.querySelector("#pricingTextOnly"),u=e.querySelector("#type"),m=e.querySelector("#valuesGridContainer"),b=e.querySelector("#addValueGrid");function g(){[r,o,s].forEach(i=>{if(!i)return;const n=i.style.display!=="none";i.querySelectorAll("input, select, textarea").forEach(l=>{l.disabled=!n})})}function h(i){a&&(a.style.display=i==="number"?"block":"none"),r&&(r.style.display=i==="number"||i==="checkbox"?"block":"none"),o&&(o.style.display=i==="select"||i==="checkboxgroup"?"block":"none"),s&&(s.style.display=i==="text"?"block":"none"),t.querySelectorAll(".ip-address-only").forEach(n=>{n.style.display=i==="ip_address"?"flex":"none"}),g()}u&&(u.addEventListener("change",function(){h(this.value)}),h(u.value)),b&&m&&b.addEventListener("click",function(){let i=-1;m.querySelectorAll(".value-grid").forEach(n=>{const l=parseInt(n.getAttribute("data-index")||"0",10);l>i&&(i=l)}),m.appendChild(x(i+1))});const f=t.querySelector("#adaptiveTermPricingSwitch"),$=[3,6,12,24,36];function v(i){const n=i.getAttribute("name")||"";if(!n.includes("pricing_grid")||!n.endsWith("[1]"))return[];const l=n.slice(0,n.lastIndexOf("["));return $.map(d=>({p:d,el:t.querySelector(`input[name="${l}[${d}]"]`)})).filter(d=>d.el)}function p(){t.querySelectorAll('input[name$="[1]"]').forEach(i=>{const n=v(i);if(!n.length)return;const l=parseFloat(i.value);n.forEach(({p:d,el:y})=>{y.readOnly=!0,y.classList.add("bg-body-secondary"),!isNaN(l)&&l>0&&(y.value=(Math.round(l*d*100)/100).toFixed(2))})})}function w(){t.querySelectorAll('input[name$="[1]"]').forEach(i=>{v(i).forEach(({el:n})=>{n.readOnly=!1,n.classList.remove("bg-body-secondary")})})}return f&&(f.addEventListener("change",function(){this.checked?p():w()}),t.addEventListener("input",function(i){var n,l;f.checked&&((l=(n=i.target)==null?void 0:n.name)!=null&&l.includes("pricing_grid"))&&i.target.name.endsWith("[1]")&&p()}),f.checked&&p()),{form:t,toggleDisabledByVisibility:g}}export{q as i};
