<?php

namespace Limb_Chatbot\Includes\Widgets\Data;

class Links_Widget_Config extends Abstract_Widget_Config {
	public function sanitize( $data ): array {
		$data = is_array( $data ) ? $data : [];
		$items = [];

		if ( isset( $data['items'] ) && is_array( $data['items'] ) ) {
			foreach ( $data['items'] as $item ) {
				if ( ! is_array( $item ) ) {
					continue;
				}
				$items[] = [
					'url'    => $this->sanitize_url_or_empty( $item['url'] ?? '' ),
					'text'   => $this->sanitize_string( $item['text'] ?? '' ),
					'target' => $this->sanitize_string( $item['target'] ?? '_self', '_self' ),
				];
			}
		}

		return [
			'section_title' => $this->sanitize_string( $data['section_title'] ?? '' ),
			'items'         => $items,
		];
	}

	public function validate( $data ): bool {
		return is_array( $data );
	}
}
