import { _decorator, assetManager, Component, ImageAsset, instantiate, Layout, Node, Prefab, Sprite, SpriteFrame, Texture2D } from 'cc';
import { diff_child_item } from './diff_child_item';
const { ccclass, property } = _decorator;

@ccclass('diff_item')
export class diff_item extends Component {
    @property(Prefab) prefab_item;
    public initView(is_offset:boolean,children_count:number,call,origin_list:[]=null){

        let item = this.prefab_item;
        if(is_offset){
            this.node.getComponent(Layout).paddingLeft = 40;
        }else{
            this.node.getComponent(Layout).paddingLeft = 0;
        }
        if(origin_list!=null){
            for (let index = 0; index < origin_list.length; index++) {
                const element:Node = instantiate(item);
                let data:any = origin_list[index];
                // console.log("item_list,",data)
                element.parent = this.node;
                element.name = data.id + ""
                element.getComponent(diff_child_item).initView(call,element.name)
            }
        }else{
            for (let index = 0; index < children_count; index++) {
                const element:Node = instantiate(item);
                element.parent = this.node;
                element.name = "1"
                element.getComponent(diff_child_item).initView(call,element.name)
            }
        }

    }

}


