﻿using Lovense.UnityKit;
using Lovense.UnityKit.Remote;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class RemoteItemClick : MonoBehaviour
{
    [SerializeField]
    public Toggle toggle;
    public int index { get; set; }

    RemoteAppData remoteData;
    LovenseRemoteToy toyData;


    public void FixedUpdate()
    {
        //GetComponent<RectTransform>().SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, transform.parent.parent.parent.GetComponent<RectTransform>().rect.width);
        //GetComponent<RectTransform>().SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, transform.parent.parent.parent.GetComponent<RectTransform>().rect.height/12);
    }

    public void SetData(RemoteAppData data)
    {
        this.remoteData = data;
        this.GetComponentInChildren<Text>().text = data.domain;
    }

    public void SetToyData(LovenseRemoteToy toy)
    {
        this.toyData = toy;
        this.transform.Find("name").GetComponent<Text>().text = toy.name;
        this.transform.Find("id").GetComponent<Text>().text = toy.id;
        this.transform.Find("type").GetComponent<Text>().text = toy.platform;
        this.transform.Find("nickName").GetComponent<Text>().text = toy.nickName;
        this.transform.Find("connected").GetComponent<Text>().text = toy.status == "1" ? "connect" : "disconnect";
        this.transform.Find("battery").GetComponent<Text>().text = toy.battery + "";
    }

    public void OnThisClick()
    {
        LovenseRemoteController.GetInstance().SetCurrentSearchAppData(this.remoteData);
    } 

    public void OnThisToyClick()
    {
       LovenseRemoteController.GetInstance().SetCurrentToys(this.toyData);
    }

    public LovenseRemoteToy GetToyData()
    {
        return this.toyData;
    }

    public bool IsCheck()
    {
        return toggle.isOn;
    }
}
