<?php
/** PSI 成品表单（降温服/成衣：款号/颜色/尺码/季节/年份） */
$p = $product;
$isEdit = !empty($p);
$catOpts = ['降温服' => '降温服', '成衣' => '成衣', '配饰' => '配饰', '其他' => '其他'];
$curCat = $p['category'] ?? '降温服';
if ($curCat && !isset($catOpts[$curCat])) { $catOpts[$curCat] = $curCat; }
$seasonOpts = ['春' => '春', '夏' => '夏', '秋' => '秋', '冬' => '冬', '四季' => '四季'];
$curSeason = $p['season'] ?? '';
?>
<div class="page-head"><h1><?php echo $isEdit ? '编辑成品' : '新增成品'; ?></h1></div>
<div class="panel">
    <form method="post" action="<?php echo site_url($isEdit ? 'PSI/products/update/' . $p['id'] : 'PSI/products/store'); ?>">
        <?php echo csrf_field(); ?>
        <div class="form-grid">
            <div class="field"><label>款号 *</label><input name="style_no" value="<?php echo e($p['style_no'] ?? ''); ?>" placeholder="如：KJ-2026-001"></div>
            <div class="field"><label>名称 *</label><input name="name" value="<?php echo e($p['name'] ?? ''); ?>" required></div>
            <div class="field"><label>编码</label><input name="code" value="<?php echo e($p['code'] ?? ''); ?>"></div>
            <div class="field"><label>分类</label>
                <select name="category">
                    <?php foreach ($catOpts as $k => $v): ?>
                        <option value="<?php echo $k; ?>" <?php echo $curCat === $k ? 'selected' : ''; ?>><?php echo $v; ?></option>
                    <?php endforeach; ?>
                </select>
            </div>
            <div class="field"><label>规格</label><input name="spec" value="<?php echo e($p['spec'] ?? ''); ?>"></div>
            <div class="field"><label>单位</label><input name="unit" value="<?php echo e($p['unit'] ?? '件'); ?>"></div>
            <div class="field"><label>颜色</label><input name="color" value="<?php echo e($p['color'] ?? ''); ?>"></div>
            <div class="field"><label>尺码段</label><input name="size_run" value="<?php echo e($p['size_run'] ?? ''); ?>" placeholder="如：S/M/L/XL"></div>
            <div class="field"><label>季节</label>
                <select name="season">
                    <option value="">未设置</option>
                    <?php foreach ($seasonOpts as $k => $v): ?>
                        <option value="<?php echo $k; ?>" <?php echo $curSeason === $k ? 'selected' : ''; ?>><?php echo $v; ?></option>
                    <?php endforeach; ?>
                </select>
            </div>
            <div class="field"><label>年份</label><input name="year" value="<?php echo e($p['year'] ?? ''); ?>" placeholder="如：2026"></div>
            <div class="field"><label>初始库存</label><input name="stock" type="number" step="0.01" value="<?php echo e($p['stock'] ?? '0'); ?>"></div>
            <div class="field"><label>成本</label><input name="cost" type="number" step="0.01" value="<?php echo e($p['cost'] ?? '0'); ?>"></div>
            <div class="field"><label>售价</label><input name="price" type="number" step="0.01" value="<?php echo e($p['price'] ?? '0'); ?>"></div>
        </div>
        <div class="field"><label>备注</label><textarea name="remark" rows="2"><?php echo e($p['remark'] ?? ''); ?></textarea></div>
        <button class="btn-primary" type="submit">保存</button>
        <a class="btn-soft" href="<?php echo site_url('PSI/products'); ?>">取消</a>
    </form>
</div>
