document.addEventListener('DOMContentLoaded', function () {
    console.log('osaffron ingredients.js loaded');

    const container = document.querySelector('#osaffron-ingredients');

    if (!container) {
        console.warn('osaffron: container #osaffron-ingredients not found');
        return;
    }

    const tableBody = container.querySelector('tbody');

    if (!tableBody) {
        console.warn('osaffron: tbody not found inside #osaffron-ingredients');
        return;
    }

    if (container.querySelector('#osaffron-add-ingredient-btn')) {
        console.log('osaffron: add button already exists');
        return;
    }

    const addButton = document.createElement('button');

    addButton.id = 'osaffron-add-ingredient-btn';
    addButton.type = 'button';
    addButton.textContent = '＋ افزودن ماده اولیه';
    addButton.style.marginTop = '15px';

    container.appendChild(addButton);

    addButton.addEventListener('click', function () {
        const index = tableBody.querySelectorAll('tr').length;

        const row = document.createElement('tr');

        row.innerHTML = `
            <td style="padding:8px;">
                <input
                    type="text"
                    name="osaffron_ingredients[${index}][name]"
                    placeholder="نام ماده"
                >
            </td>

            <td style="padding:8px;">
                <input
                    type="number"
                    name="osaffron_ingredients[${index}][amount]"
                    min="0"
                    step="0.01"
                    placeholder="مقدار"
                >
            </td>

            <td style="padding:8px;">
                <input
                    type="text"
                    name="osaffron_ingredients[${index}][unit]"
                    placeholder="واحد"
                >
            </td>

            <td style="padding:8px;">
                <input
                    type="number"
                    name="osaffron_ingredients[${index}][calories]"
                    min="0"
                    step="1"
                    placeholder="کالری"
                >
            </td>

            <td style="padding:8px;">
                <button
                    type="button"
                    class="osaffron-remove-ingredient"
                >
                    حذف
                </button>
            </td>
        `;

        tableBody.appendChild(row);

        // انتخاب مطمئن دکمه حذف
        const removeButton = row.querySelector('.osaffron-remove-ingredient');

        if (removeButton) {
            removeButton.addEventListener('click', function () {
                row.remove();
            });
        } else {
            console.warn('osaffron: remove button not found in new row');
        }
    });
});<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="//osaffron.ir/main-sitemap.xsl"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
	<sitemap>
		<loc>https://osaffron.ir/post-sitemap.xml</loc>
		<lastmod>2026-08-03T19:23:49+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://osaffron.ir/page-sitemap.xml</loc>
		<lastmod>2026-08-24T05:55:36+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://osaffron.ir/product-sitemap.xml</loc>
		<lastmod>2026-08-18T18:16:58+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://osaffron.ir/category-sitemap.xml</loc>
		<lastmod>2026-08-03T19:23:49+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://osaffron.ir/product_cat-sitemap.xml</loc>
		<lastmod>2026-08-18T18:16:58+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://osaffron.ir/local-sitemap.xml</loc>
		<lastmod>2026-08-24T13:36:52+00:00</lastmod>
	</sitemap>
</sitemapindex>
<!-- XML Sitemap generated by Rank Math SEO Plugin (c) Rank Math - rankmath.com -->