//
// TableViewCellWrapper.m
// Project
//
// Created by haibara on 9/13/16.
//
//

#import "TableViewCellWrapper.h"
#import <PureLayout/PureLayout.h>

@interface TableViewCellWrapper ()
@end

@implementation TableViewCellWrapper

- (id)initWithFrame:(CGRect)frame {
	self = [super initWithFrame:frame];
	if (self) {
		[self loadView];
	}
	return self;
}

- (id)initWithCoder:(NSCoder *)decoder {
	self = [super initWithCoder:decoder];
	if (self) {
		[self loadView];
	}
	return self;
}

#pragma mark - Property

- (void)setStyle:(UITableViewCellStyle)style {
	if (_style != style) {
		_style = style;
		[self loadView];
	}
}

#pragma mark - Public

- (UITableViewCell *)get {
	return [self viewWithTag:NSStringFromClass([UITableViewCell class]).hash];
}

#pragma mark - Private

- (void)loadView {
	[[self get] removeFromSuperview];
	UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:self.style reuseIdentifier:NSStringFromClass([UITableViewCell class])];
	cell.tag = NSStringFromClass([UITableViewCell class]).hash;
	[self addSubview:cell];
	[cell autoPinEdgesToSuperviewEdges];
}

@end
