<?php
require_once __DIR__ . '/../../includes/bootstrap.php';
require_login();

$type = strtolower(trim($_GET['type'] ?? 'food'));

if ($type === 'cocktail') {

    $filename = 'cocktail_recipe_template.csv';

    $rows = [
        [
            'Recipe Name',
            'Menu Item',
            'Category',
            'Ingredient',
            'Qty Required',
            'Unit',
            'Waste %',
            'Store',
            'Notes'
        ],
        [
            'Margarita',
            'Margarita',
            'Cocktails',
            'Tequila Tot',
            '2',
            'TOT',
            '0',
            'Bar',
            ''
        ],
        [
            'Margarita',
            'Margarita',
            'Cocktails',
            'Triple Sec Tot',
            '1',
            'TOT',
            '0',
            'Bar',
            ''
        ],
        [
            'Margarita',
            'Margarita',
            'Cocktails',
            'Lime Juice',
            '25',
            'ML',
            '0',
            'Bar',
            ''
        ]
    ];

} else {

    $filename = 'food_recipe_template.csv';

    $rows = [
        [
            'Recipe Name',
            'Menu Item',
            'Category',
            'Ingredient',
            'Qty Required',
            'Unit',
            'Waste %',
            'Store',
            'Notes'
        ],
        [
            'Beef Burger',
            'Beef Burger',
            'Burgers',
            'Beef Patty',
            '1',
            'EACH',
            '0',
            'Kitchen',
            ''
        ],
        [
            'Beef Burger',
            'Beef Burger',
            'Burgers',
            'Burger Bun',
            '1',
            'EACH',
            '0',
            'Kitchen',
            ''
        ],
        [
            'Beef Burger',
            'Beef Burger',
            'Burgers',
            'Lettuce',
            '0.03',
            'KG',
            '5',
            'Kitchen',
            ''
        ],
        [
            'Beef Burger',
            'Beef Burger',
            'Burgers',
            'Tomato',
            '0.02',
            'KG',
            '5',
            'Kitchen',
            ''
        ]
    ];
}

header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename="' . $filename . '"');
header('Pragma: no-cache');
header('Expires: 0');

$output = fopen('php://output', 'w');

foreach ($rows as $row) {
    fputcsv($output, $row);
}

fclose($output);
exit;